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.

252354 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 1
  131. #endif
  132. #ifndef JUCE_LOG_ASSERTIONS
  133. // #define JUCE_LOG_ASSERTIONS 1
  134. #endif
  135. #ifndef JUCE_ASIO
  136. #define JUCE_ASIO 0
  137. #endif
  138. #ifndef JUCE_WASAPI
  139. // #define JUCE_WASAPI 1
  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 1
  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 1
  170. #endif
  171. #if (JUCE_QUICKTIME || JUCE_WINDOWS) && ! defined (JUCE_USE_CAMERA)
  172. // #define JUCE_USE_CAMERA 1
  173. #endif
  174. #ifndef JUCE_ENABLE_REPAINT_DEBUGGING
  175. // #define JUCE_ENABLE_REPAINT_DEBUGGING 1
  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 1
  185. #endif
  186. #ifndef JUCE_PLUGINHOST_VST
  187. // #define JUCE_PLUGINHOST_VST 1
  188. #endif
  189. #ifndef JUCE_PLUGINHOST_AU
  190. // #define JUCE_PLUGINHOST_AU 1
  191. #endif
  192. #ifndef JUCE_ONLY_BUILD_CORE_LIBRARY
  193. //#define JUCE_ONLY_BUILD_CORE_LIBRARY 1
  194. #endif
  195. #ifndef JUCE_WEB_BROWSER
  196. #define JUCE_WEB_BROWSER 0
  197. #endif
  198. #ifndef JUCE_SUPPORT_CARBON
  199. #define JUCE_SUPPORT_CARBON 1
  200. #endif
  201. #ifndef JUCE_INCLUDE_ZLIB_CODE
  202. #define JUCE_INCLUDE_ZLIB_CODE 1
  203. #endif
  204. #ifndef JUCE_INCLUDE_FLAC_CODE
  205. #define JUCE_INCLUDE_FLAC_CODE 1
  206. #endif
  207. #ifndef JUCE_INCLUDE_OGGVORBIS_CODE
  208. #define JUCE_INCLUDE_OGGVORBIS_CODE 1
  209. #endif
  210. #ifndef JUCE_INCLUDE_PNGLIB_CODE
  211. #define JUCE_INCLUDE_PNGLIB_CODE 1
  212. #endif
  213. #ifndef JUCE_INCLUDE_JPEGLIB_CODE
  214. #define JUCE_INCLUDE_JPEGLIB_CODE 1
  215. #endif
  216. #ifndef JUCE_CHECK_MEMORY_LEAKS
  217. #define JUCE_CHECK_MEMORY_LEAKS 1
  218. #endif
  219. #ifndef JUCE_CATCH_UNHANDLED_EXCEPTIONS
  220. #define JUCE_CATCH_UNHANDLED_EXCEPTIONS 1
  221. #endif
  222. // If only building the core classes, we can explicitly turn off some features to avoid including them:
  223. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  224. #undef JUCE_QUICKTIME
  225. #define JUCE_QUICKTIME 0
  226. #undef JUCE_OPENGL
  227. #define JUCE_OPENGL 0
  228. #undef JUCE_USE_CDBURNER
  229. #define JUCE_USE_CDBURNER 0
  230. #undef JUCE_USE_CDREADER
  231. #define JUCE_USE_CDREADER 0
  232. #undef JUCE_WEB_BROWSER
  233. #define JUCE_WEB_BROWSER 0
  234. #undef JUCE_PLUGINHOST_AU
  235. #define JUCE_PLUGINHOST_AU 0
  236. #undef JUCE_PLUGINHOST_VST
  237. #define JUCE_PLUGINHOST_VST 0
  238. #endif
  239. #endif
  240. /*** End of inlined file: juce_Config.h ***/
  241. // FORCE_AMALGAMATOR_INCLUDE
  242. #ifndef JUCE_BUILD_CORE
  243. #define JUCE_BUILD_CORE 1
  244. #endif
  245. #ifndef JUCE_BUILD_MISC
  246. #define JUCE_BUILD_MISC 1
  247. #endif
  248. #ifndef JUCE_BUILD_GUI
  249. #define JUCE_BUILD_GUI 1
  250. #endif
  251. #ifndef JUCE_BUILD_NATIVE
  252. #define JUCE_BUILD_NATIVE 1
  253. #endif
  254. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  255. #undef JUCE_BUILD_MISC
  256. #undef JUCE_BUILD_GUI
  257. #endif
  258. //==============================================================================
  259. #if JUCE_BUILD_NATIVE || JUCE_BUILD_CORE || (JUCE_BUILD_MISC && (JUCE_PLUGINHOST_VST || JUCE_PLUGINHOST_AU))
  260. #if JUCE_WINDOWS
  261. /*** Start of inlined file: juce_win32_NativeIncludes.h ***/
  262. #ifndef __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  263. #define __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  264. #ifndef STRICT
  265. #define STRICT 1
  266. #endif
  267. #undef WIN32_LEAN_AND_MEAN
  268. #define WIN32_LEAN_AND_MEAN 1
  269. #ifdef _MSC_VER
  270. #pragma warning (push)
  271. #pragma warning (disable : 4100 4201 4514 4312 4995)
  272. #endif
  273. #define _WIN32_WINNT 0x0500
  274. #define _UNICODE 1
  275. #define UNICODE 1
  276. #ifndef _WIN32_IE
  277. #define _WIN32_IE 0x0400
  278. #endif
  279. #include <windows.h>
  280. #include <windowsx.h>
  281. #include <commdlg.h>
  282. #include <shellapi.h>
  283. #include <mmsystem.h>
  284. #include <vfw.h>
  285. #include <tchar.h>
  286. #include <stddef.h>
  287. #include <ctime>
  288. #include <wininet.h>
  289. #include <nb30.h>
  290. #include <iphlpapi.h>
  291. #include <mapi.h>
  292. #include <float.h>
  293. #include <process.h>
  294. #include <Exdisp.h>
  295. #include <exdispid.h>
  296. #include <shlobj.h>
  297. #if ! JUCE_MINGW
  298. #include <crtdbg.h>
  299. #include <comutil.h>
  300. #endif
  301. #if JUCE_OPENGL
  302. #include <gl/gl.h>
  303. #endif
  304. #undef PACKED
  305. #if JUCE_ASIO
  306. #include "iasiodrv.h"
  307. #endif
  308. #if JUCE_USE_CDBURNER
  309. #include <imapi.h>
  310. #include <imapierror.h>
  311. #endif
  312. #if JUCE_USE_CAMERA
  313. #include <dshow.h>
  314. #include <qedit.h>
  315. #include <dshowasf.h>
  316. #endif
  317. #if JUCE_WASAPI
  318. #include <MMReg.h>
  319. #include <mmdeviceapi.h>
  320. #include <Audioclient.h>
  321. #include <Avrt.h>
  322. #include <functiondiscoverykeys.h>
  323. #endif
  324. #if JUCE_QUICKTIME
  325. #include <Movies.h>
  326. #include <QTML.h>
  327. #include <QuickTimeComponents.h>
  328. #include <MediaHandlers.h>
  329. #include <ImageCodec.h>
  330. #import <QTOLibrary.dll>
  331. #import <QTOControl.dll>
  332. #endif
  333. #ifdef _MSC_VER
  334. #pragma warning (pop)
  335. #endif
  336. template <class T>
  337. class ComSmartPtr
  338. {
  339. public:
  340. ComSmartPtr() throw() : p (0) {}
  341. ComSmartPtr (T* const p_) : p (p_) { if (p_ != 0) p_->AddRef(); }
  342. ComSmartPtr (const ComSmartPtr<T>& p_) : p (p_.p) { if (p != 0) p->AddRef(); }
  343. ~ComSmartPtr() { if (p != 0) p->Release(); }
  344. operator T*() const throw() { return p; }
  345. T& operator*() const throw() { return *p; }
  346. T** operator&() throw() { return &p; }
  347. T* operator->() const throw() { return p; }
  348. T* operator= (T* const newP)
  349. {
  350. if (newP != 0)
  351. newP->AddRef();
  352. if (p != 0)
  353. p->Release();
  354. p = newP;
  355. return newP;
  356. }
  357. T* operator= (const ComSmartPtr<T>& newP) { return operator= (newP.p); }
  358. HRESULT CoCreateInstance (REFCLSID rclsid, DWORD dwClsContext)
  359. {
  360. #ifndef __MINGW32__
  361. operator= (0);
  362. return ::CoCreateInstance (rclsid, 0, dwClsContext, __uuidof(T), (void**) &p);
  363. #else
  364. return S_FALSE;
  365. #endif
  366. }
  367. T* p;
  368. };
  369. #endif // __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  370. /*** End of inlined file: juce_win32_NativeIncludes.h ***/
  371. #elif JUCE_LINUX
  372. /*** Start of inlined file: juce_linux_NativeIncludes.h ***/
  373. #ifndef __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  374. #define __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  375. #include <sched.h>
  376. #include <pthread.h>
  377. #include <sys/time.h>
  378. #include <errno.h>
  379. #include <sys/stat.h>
  380. #include <sys/dir.h>
  381. #include <sys/ptrace.h>
  382. #include <sys/vfs.h>
  383. #include <sys/wait.h>
  384. #include <fnmatch.h>
  385. #include <utime.h>
  386. #include <pwd.h>
  387. #include <fcntl.h>
  388. #include <dlfcn.h>
  389. #include <netdb.h>
  390. #include <arpa/inet.h>
  391. #include <netinet/in.h>
  392. #include <sys/types.h>
  393. #include <sys/ioctl.h>
  394. #include <sys/socket.h>
  395. #include <linux/if.h>
  396. #include <sys/sysinfo.h>
  397. #include <sys/file.h>
  398. #include <signal.h>
  399. #include <ft2build.h>
  400. #include FT_FREETYPE_H
  401. #include <X11/Xlib.h>
  402. #include <X11/Xatom.h>
  403. #include <X11/Xresource.h>
  404. #include <X11/Xutil.h>
  405. #include <X11/Xmd.h>
  406. #include <X11/keysym.h>
  407. #include <X11/cursorfont.h>
  408. #if JUCE_USE_XINERAMA
  409. #include <X11/extensions/Xinerama.h>
  410. #endif
  411. #if JUCE_USE_XSHM
  412. #include <X11/extensions/XShm.h>
  413. #include <sys/shm.h>
  414. #include <sys/ipc.h>
  415. #endif
  416. #if JUCE_USE_XRENDER
  417. // If you're missing these headers, try installing the libxrender-dev and libxcomposite-dev
  418. #include <X11/extensions/Xrender.h>
  419. #include <X11/extensions/Xcomposite.h>
  420. #endif
  421. #if JUCE_OPENGL
  422. #include <GL/glx.h>
  423. #endif
  424. #undef KeyPress
  425. #if JUCE_ALSA
  426. #include <alsa/asoundlib.h>
  427. #endif
  428. #if JUCE_JACK
  429. #include <jack/jack.h>
  430. //#include <jack/transport.h>
  431. #endif
  432. #undef SIZEOF
  433. #endif // __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  434. /*** End of inlined file: juce_linux_NativeIncludes.h ***/
  435. #elif JUCE_MAC || JUCE_IPHONE
  436. /*** Start of inlined file: juce_mac_NativeIncludes.h ***/
  437. #ifndef __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  438. #define __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  439. #define USE_COREGRAPHICS_RENDERING 1
  440. #if JUCE_IPHONE
  441. #import <Foundation/Foundation.h>
  442. #import <UIKit/UIKit.h>
  443. #import <AudioToolbox/AudioToolbox.h>
  444. #import <AVFoundation/AVFoundation.h>
  445. #import <CoreData/CoreData.h>
  446. #import <MobileCoreServices/MobileCoreServices.h>
  447. #import <QuartzCore/QuartzCore.h>
  448. #include <sys/fcntl.h>
  449. #if JUCE_OPENGL
  450. #include <OpenGLES/ES1/gl.h>
  451. #include <OpenGLES/ES1/glext.h>
  452. #endif
  453. #else
  454. #import <Cocoa/Cocoa.h>
  455. #import <CoreAudio/HostTime.h>
  456. #import <CoreAudio/AudioHardware.h>
  457. #import <CoreMIDI/MIDIServices.h>
  458. #import <QTKit/QTKit.h>
  459. #import <WebKit/WebKit.h>
  460. #import <DiscRecording/DiscRecording.h>
  461. #import <IOKit/IOKitLib.h>
  462. #import <IOKit/IOCFPlugIn.h>
  463. #import <IOKit/hid/IOHIDLib.h>
  464. #import <IOKit/hid/IOHIDKeys.h>
  465. #import <IOKit/pwr_mgt/IOPMLib.h>
  466. #include <Carbon/Carbon.h>
  467. #include <sys/dir.h>
  468. #include <sys/socket.h>
  469. #endif
  470. #include <sys/sysctl.h>
  471. #include <sys/stat.h>
  472. #include <sys/param.h>
  473. #include <sys/mount.h>
  474. #include <fnmatch.h>
  475. #include <utime.h>
  476. #include <dlfcn.h>
  477. #include <ifaddrs.h>
  478. #include <net/if_dl.h>
  479. #include <mach/mach_time.h>
  480. #if MACOS_10_4_OR_EARLIER
  481. #include <GLUT/glut.h>
  482. #endif
  483. #if ! CGFLOAT_DEFINED
  484. #define CGFloat float
  485. #endif
  486. #endif // __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  487. /*** End of inlined file: juce_mac_NativeIncludes.h ***/
  488. #else
  489. #error "Unknown platform!"
  490. #endif
  491. #endif
  492. //==============================================================================
  493. #define DONT_SET_USING_JUCE_NAMESPACE 1
  494. #undef max
  495. #undef min
  496. #define NO_DUMMY_DECL
  497. #if JUCE_BUILD_NATIVE
  498. #include "juce_amalgamated.h" // FORCE_AMALGAMATOR_INCLUDE
  499. #endif
  500. #if (defined(_MSC_VER) && (_MSC_VER <= 1200))
  501. #pragma warning (disable: 4309 4305)
  502. #endif
  503. #if JUCE_MAC && JUCE_32BIT && JUCE_SUPPORT_CARBON && JUCE_BUILD_NATIVE && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  504. BEGIN_JUCE_NAMESPACE
  505. /*** Start of inlined file: juce_mac_CarbonViewWrapperComponent.h ***/
  506. #ifndef __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  507. #define __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  508. class CarbonViewWrapperComponent : public Component,
  509. public ComponentMovementWatcher,
  510. public Timer
  511. {
  512. public:
  513. CarbonViewWrapperComponent()
  514. : ComponentMovementWatcher (this),
  515. wrapperWindow (0),
  516. embeddedView (0),
  517. recursiveResize (false)
  518. {
  519. }
  520. virtual ~CarbonViewWrapperComponent()
  521. {
  522. jassert (embeddedView == 0); // must call deleteWindow() in the subclass's destructor!
  523. }
  524. virtual HIViewRef attachView (WindowRef windowRef, HIViewRef rootView) = 0;
  525. virtual void removeView (HIViewRef embeddedView) = 0;
  526. virtual void mouseDown (int x, int y) {}
  527. virtual void paint() {}
  528. virtual bool getEmbeddedViewSize (int& w, int& h)
  529. {
  530. if (embeddedView == 0)
  531. return false;
  532. HIRect bounds;
  533. HIViewGetBounds (embeddedView, &bounds);
  534. w = jmax (1, roundToInt (bounds.size.width));
  535. h = jmax (1, roundToInt (bounds.size.height));
  536. return true;
  537. }
  538. void createWindow()
  539. {
  540. if (wrapperWindow == 0)
  541. {
  542. Rect r;
  543. r.left = getScreenX();
  544. r.top = getScreenY();
  545. r.right = r.left + getWidth();
  546. r.bottom = r.top + getHeight();
  547. CreateNewWindow (kDocumentWindowClass,
  548. (WindowAttributes) (kWindowStandardHandlerAttribute | kWindowCompositingAttribute
  549. | kWindowNoShadowAttribute | kWindowNoTitleBarAttribute),
  550. &r, &wrapperWindow);
  551. jassert (wrapperWindow != 0);
  552. if (wrapperWindow == 0)
  553. return;
  554. NSWindow* carbonWindow = [[NSWindow alloc] initWithWindowRef: wrapperWindow];
  555. NSWindow* ownerWindow = [((NSView*) getWindowHandle()) window];
  556. [ownerWindow addChildWindow: carbonWindow
  557. ordered: NSWindowAbove];
  558. embeddedView = attachView (wrapperWindow, HIViewGetRoot (wrapperWindow));
  559. EventTypeSpec windowEventTypes[] = { { kEventClassWindow, kEventWindowGetClickActivation },
  560. { kEventClassWindow, kEventWindowHandleDeactivate } };
  561. EventHandlerUPP upp = NewEventHandlerUPP (carbonEventCallback);
  562. InstallWindowEventHandler (wrapperWindow, upp,
  563. sizeof (windowEventTypes) / sizeof (EventTypeSpec),
  564. windowEventTypes, this, &eventHandlerRef);
  565. setOurSizeToEmbeddedViewSize();
  566. setEmbeddedWindowToOurSize();
  567. creationTime = Time::getCurrentTime();
  568. }
  569. }
  570. void deleteWindow()
  571. {
  572. removeView (embeddedView);
  573. embeddedView = 0;
  574. if (wrapperWindow != 0)
  575. {
  576. RemoveEventHandler (eventHandlerRef);
  577. DisposeWindow (wrapperWindow);
  578. wrapperWindow = 0;
  579. }
  580. }
  581. void setOurSizeToEmbeddedViewSize()
  582. {
  583. int w, h;
  584. if (getEmbeddedViewSize (w, h))
  585. {
  586. if (w != getWidth() || h != getHeight())
  587. {
  588. startTimer (50);
  589. setSize (w, h);
  590. if (getParentComponent() != 0)
  591. getParentComponent()->setSize (w, h);
  592. }
  593. else
  594. {
  595. startTimer (jlimit (50, 500, getTimerInterval() + 20));
  596. }
  597. }
  598. else
  599. {
  600. stopTimer();
  601. }
  602. }
  603. void setEmbeddedWindowToOurSize()
  604. {
  605. if (! recursiveResize)
  606. {
  607. recursiveResize = true;
  608. if (embeddedView != 0)
  609. {
  610. HIRect r;
  611. r.origin.x = 0;
  612. r.origin.y = 0;
  613. r.size.width = (float) getWidth();
  614. r.size.height = (float) getHeight();
  615. HIViewSetFrame (embeddedView, &r);
  616. }
  617. if (wrapperWindow != 0)
  618. {
  619. Rect wr;
  620. wr.left = getScreenX();
  621. wr.top = getScreenY();
  622. wr.right = wr.left + getWidth();
  623. wr.bottom = wr.top + getHeight();
  624. SetWindowBounds (wrapperWindow, kWindowContentRgn, &wr);
  625. ShowWindow (wrapperWindow);
  626. }
  627. recursiveResize = false;
  628. }
  629. }
  630. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  631. {
  632. setEmbeddedWindowToOurSize();
  633. }
  634. void componentPeerChanged()
  635. {
  636. deleteWindow();
  637. createWindow();
  638. }
  639. void componentVisibilityChanged (Component&)
  640. {
  641. if (isShowing())
  642. createWindow();
  643. else
  644. deleteWindow();
  645. setEmbeddedWindowToOurSize();
  646. }
  647. static void recursiveHIViewRepaint (HIViewRef view)
  648. {
  649. HIViewSetNeedsDisplay (view, true);
  650. HIViewRef child = HIViewGetFirstSubview (view);
  651. while (child != 0)
  652. {
  653. recursiveHIViewRepaint (child);
  654. child = HIViewGetNextView (child);
  655. }
  656. }
  657. void timerCallback()
  658. {
  659. setOurSizeToEmbeddedViewSize();
  660. // To avoid strange overpainting problems when the UI is first opened, we'll
  661. // repaint it a few times during the first second that it's on-screen..
  662. if ((Time::getCurrentTime() - creationTime).inMilliseconds() < 1000)
  663. recursiveHIViewRepaint (HIViewGetRoot (wrapperWindow));
  664. }
  665. OSStatus carbonEventHandler (EventHandlerCallRef nextHandlerRef,
  666. EventRef event)
  667. {
  668. switch (GetEventKind (event))
  669. {
  670. case kEventWindowHandleDeactivate:
  671. ActivateWindow (wrapperWindow, TRUE);
  672. break;
  673. case kEventWindowGetClickActivation:
  674. {
  675. getTopLevelComponent()->toFront (false);
  676. ClickActivationResult howToHandleClick = kActivateAndHandleClick;
  677. SetEventParameter (event, kEventParamClickActivation, typeClickActivationResult,
  678. sizeof (ClickActivationResult), &howToHandleClick);
  679. HIViewSetNeedsDisplay (embeddedView, true);
  680. }
  681. break;
  682. }
  683. return noErr;
  684. }
  685. static pascal OSStatus carbonEventCallback (EventHandlerCallRef nextHandlerRef,
  686. EventRef event, void* userData)
  687. {
  688. return ((CarbonViewWrapperComponent*) userData)->carbonEventHandler (nextHandlerRef, event);
  689. }
  690. protected:
  691. WindowRef wrapperWindow;
  692. HIViewRef embeddedView;
  693. bool recursiveResize;
  694. Time creationTime;
  695. EventHandlerRef eventHandlerRef;
  696. };
  697. #endif // __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  698. /*** End of inlined file: juce_mac_CarbonViewWrapperComponent.h ***/
  699. END_JUCE_NAMESPACE
  700. #endif
  701. #define JUCE_AMALGAMATED_TEMPLATE 1
  702. //==============================================================================
  703. #if JUCE_BUILD_CORE
  704. /*** Start of inlined file: juce_FileLogger.cpp ***/
  705. BEGIN_JUCE_NAMESPACE
  706. FileLogger::FileLogger (const File& logFile_,
  707. const String& welcomeMessage,
  708. const int maxInitialFileSizeBytes)
  709. : logFile (logFile_)
  710. {
  711. if (maxInitialFileSizeBytes >= 0)
  712. trimFileSize (maxInitialFileSizeBytes);
  713. if (! logFile_.exists())
  714. {
  715. // do this so that the parent directories get created..
  716. logFile_.create();
  717. }
  718. logStream = logFile_.createOutputStream (256);
  719. jassert (logStream != 0);
  720. String welcome;
  721. welcome << "\r\n**********************************************************\r\n"
  722. << welcomeMessage
  723. << "\r\nLog started: " << Time::getCurrentTime().toString (true, true)
  724. << "\r\n";
  725. logMessage (welcome);
  726. }
  727. FileLogger::~FileLogger()
  728. {
  729. }
  730. void FileLogger::logMessage (const String& message)
  731. {
  732. if (logStream != 0)
  733. {
  734. DBG (message);
  735. const ScopedLock sl (logLock);
  736. (*logStream) << message << "\r\n";
  737. logStream->flush();
  738. }
  739. }
  740. void FileLogger::trimFileSize (int maxFileSizeBytes) const
  741. {
  742. if (maxFileSizeBytes <= 0)
  743. {
  744. logFile.deleteFile();
  745. }
  746. else
  747. {
  748. const int64 fileSize = logFile.getSize();
  749. if (fileSize > maxFileSizeBytes)
  750. {
  751. ScopedPointer <FileInputStream> in (logFile.createInputStream());
  752. jassert (in != 0);
  753. if (in != 0)
  754. {
  755. in->setPosition (fileSize - maxFileSizeBytes);
  756. String content;
  757. {
  758. MemoryBlock contentToSave;
  759. contentToSave.setSize (maxFileSizeBytes + 4);
  760. contentToSave.fillWith (0);
  761. in->read (contentToSave.getData(), maxFileSizeBytes);
  762. in = 0;
  763. content = contentToSave.toString();
  764. }
  765. int newStart = 0;
  766. while (newStart < fileSize
  767. && content[newStart] != '\n'
  768. && content[newStart] != '\r')
  769. ++newStart;
  770. logFile.deleteFile();
  771. logFile.appendText (content.substring (newStart), false, false);
  772. }
  773. }
  774. }
  775. }
  776. FileLogger* FileLogger::createDefaultAppLogger (const String& logFileSubDirectoryName,
  777. const String& logFileName,
  778. const String& welcomeMessage,
  779. const int maxInitialFileSizeBytes)
  780. {
  781. #if JUCE_MAC
  782. File logFile ("~/Library/Logs");
  783. logFile = logFile.getChildFile (logFileSubDirectoryName)
  784. .getChildFile (logFileName);
  785. #else
  786. File logFile (File::getSpecialLocation (File::userApplicationDataDirectory));
  787. if (logFile.isDirectory())
  788. {
  789. logFile = logFile.getChildFile (logFileSubDirectoryName)
  790. .getChildFile (logFileName);
  791. }
  792. #endif
  793. return new FileLogger (logFile, welcomeMessage, maxInitialFileSizeBytes);
  794. }
  795. END_JUCE_NAMESPACE
  796. /*** End of inlined file: juce_FileLogger.cpp ***/
  797. /*** Start of inlined file: juce_Logger.cpp ***/
  798. BEGIN_JUCE_NAMESPACE
  799. Logger::Logger()
  800. {
  801. }
  802. Logger::~Logger()
  803. {
  804. }
  805. static Logger* currentLogger = 0;
  806. void Logger::setCurrentLogger (Logger* const newLogger,
  807. const bool deleteOldLogger)
  808. {
  809. Logger* const oldLogger = currentLogger;
  810. currentLogger = newLogger;
  811. if (deleteOldLogger)
  812. delete oldLogger;
  813. }
  814. void Logger::writeToLog (const String& message)
  815. {
  816. if (currentLogger != 0)
  817. currentLogger->logMessage (message);
  818. else
  819. outputDebugString (message);
  820. }
  821. #if JUCE_LOG_ASSERTIONS
  822. void JUCE_API juce_LogAssertion (const char* filename, const int lineNum) throw()
  823. {
  824. String m ("JUCE Assertion failure in ");
  825. m << filename << ", line " << lineNum;
  826. Logger::writeToLog (m);
  827. }
  828. #endif
  829. END_JUCE_NAMESPACE
  830. /*** End of inlined file: juce_Logger.cpp ***/
  831. /*** Start of inlined file: juce_Random.cpp ***/
  832. BEGIN_JUCE_NAMESPACE
  833. Random::Random (const int64 seedValue) throw()
  834. : seed (seedValue)
  835. {
  836. }
  837. Random::~Random() throw()
  838. {
  839. }
  840. void Random::setSeed (const int64 newSeed) throw()
  841. {
  842. seed = newSeed;
  843. }
  844. void Random::combineSeed (const int64 seedValue) throw()
  845. {
  846. seed ^= nextInt64() ^ seedValue;
  847. }
  848. void Random::setSeedRandomly()
  849. {
  850. combineSeed ((int64) (pointer_sized_int) this);
  851. combineSeed (Time::getMillisecondCounter());
  852. combineSeed (Time::getHighResolutionTicks());
  853. combineSeed (Time::getHighResolutionTicksPerSecond());
  854. combineSeed (Time::currentTimeMillis());
  855. }
  856. int Random::nextInt() throw()
  857. {
  858. seed = (seed * literal64bit (0x5deece66d) + 11) & literal64bit (0xffffffffffff);
  859. return (int) (seed >> 16);
  860. }
  861. int Random::nextInt (const int maxValue) throw()
  862. {
  863. jassert (maxValue > 0);
  864. return (nextInt() & 0x7fffffff) % maxValue;
  865. }
  866. int64 Random::nextInt64() throw()
  867. {
  868. return (((int64) nextInt()) << 32) | (int64) (uint64) (uint32) nextInt();
  869. }
  870. bool Random::nextBool() throw()
  871. {
  872. return (nextInt() & 0x80000000) != 0;
  873. }
  874. float Random::nextFloat() throw()
  875. {
  876. return static_cast <uint32> (nextInt()) / (float) 0xffffffff;
  877. }
  878. double Random::nextDouble() throw()
  879. {
  880. return static_cast <uint32> (nextInt()) / (double) 0xffffffff;
  881. }
  882. const BigInteger Random::nextLargeNumber (const BigInteger& maximumValue)
  883. {
  884. BigInteger n;
  885. do
  886. {
  887. fillBitsRandomly (n, 0, maximumValue.getHighestBit() + 1);
  888. }
  889. while (n >= maximumValue);
  890. return n;
  891. }
  892. void Random::fillBitsRandomly (BigInteger& arrayToChange, int startBit, int numBits)
  893. {
  894. arrayToChange.setBit (startBit + numBits - 1, true); // to force the array to pre-allocate space
  895. while ((startBit & 31) != 0 && numBits > 0)
  896. {
  897. arrayToChange.setBit (startBit++, nextBool());
  898. --numBits;
  899. }
  900. while (numBits >= 32)
  901. {
  902. arrayToChange.setBitRangeAsInt (startBit, 32, (unsigned int) nextInt());
  903. startBit += 32;
  904. numBits -= 32;
  905. }
  906. while (--numBits >= 0)
  907. arrayToChange.setBit (startBit + numBits, nextBool());
  908. }
  909. Random& Random::getSystemRandom() throw()
  910. {
  911. static Random sysRand (1);
  912. return sysRand;
  913. }
  914. END_JUCE_NAMESPACE
  915. /*** End of inlined file: juce_Random.cpp ***/
  916. /*** Start of inlined file: juce_RelativeTime.cpp ***/
  917. BEGIN_JUCE_NAMESPACE
  918. RelativeTime::RelativeTime (const double seconds_) throw()
  919. : seconds (seconds_)
  920. {
  921. }
  922. RelativeTime::RelativeTime (const RelativeTime& other) throw()
  923. : seconds (other.seconds)
  924. {
  925. }
  926. RelativeTime::~RelativeTime() throw()
  927. {
  928. }
  929. const RelativeTime RelativeTime::milliseconds (const int milliseconds) throw()
  930. {
  931. return RelativeTime (milliseconds * 0.001);
  932. }
  933. const RelativeTime RelativeTime::milliseconds (const int64 milliseconds) throw()
  934. {
  935. return RelativeTime (milliseconds * 0.001);
  936. }
  937. const RelativeTime RelativeTime::minutes (const double numberOfMinutes) throw()
  938. {
  939. return RelativeTime (numberOfMinutes * 60.0);
  940. }
  941. const RelativeTime RelativeTime::hours (const double numberOfHours) throw()
  942. {
  943. return RelativeTime (numberOfHours * (60.0 * 60.0));
  944. }
  945. const RelativeTime RelativeTime::days (const double numberOfDays) throw()
  946. {
  947. return RelativeTime (numberOfDays * (60.0 * 60.0 * 24.0));
  948. }
  949. const RelativeTime RelativeTime::weeks (const double numberOfWeeks) throw()
  950. {
  951. return RelativeTime (numberOfWeeks * (60.0 * 60.0 * 24.0 * 7.0));
  952. }
  953. int64 RelativeTime::inMilliseconds() const throw()
  954. {
  955. return (int64)(seconds * 1000.0);
  956. }
  957. double RelativeTime::inMinutes() const throw()
  958. {
  959. return seconds / 60.0;
  960. }
  961. double RelativeTime::inHours() const throw()
  962. {
  963. return seconds / (60.0 * 60.0);
  964. }
  965. double RelativeTime::inDays() const throw()
  966. {
  967. return seconds / (60.0 * 60.0 * 24.0);
  968. }
  969. double RelativeTime::inWeeks() const throw()
  970. {
  971. return seconds / (60.0 * 60.0 * 24.0 * 7.0);
  972. }
  973. const String RelativeTime::getDescription (const String& returnValueForZeroTime) const throw()
  974. {
  975. if (seconds < 0.001 && seconds > -0.001)
  976. return returnValueForZeroTime;
  977. String result;
  978. if (seconds < 0)
  979. result = "-";
  980. int fieldsShown = 0;
  981. int n = abs ((int) inWeeks());
  982. if (n > 0)
  983. {
  984. result << n << ((n == 1) ? TRANS(" week ")
  985. : TRANS(" weeks "));
  986. ++fieldsShown;
  987. }
  988. n = abs ((int) inDays()) % 7;
  989. if (n > 0)
  990. {
  991. result << n << ((n == 1) ? TRANS(" day ")
  992. : TRANS(" days "));
  993. ++fieldsShown;
  994. }
  995. if (fieldsShown < 2)
  996. {
  997. n = abs ((int) inHours()) % 24;
  998. if (n > 0)
  999. {
  1000. result << n << ((n == 1) ? TRANS(" hr ")
  1001. : TRANS(" hrs "));
  1002. ++fieldsShown;
  1003. }
  1004. if (fieldsShown < 2)
  1005. {
  1006. n = abs ((int) inMinutes()) % 60;
  1007. if (n > 0)
  1008. {
  1009. result << n << ((n == 1) ? TRANS(" min ")
  1010. : TRANS(" mins "));
  1011. ++fieldsShown;
  1012. }
  1013. if (fieldsShown < 2)
  1014. {
  1015. n = abs ((int) inSeconds()) % 60;
  1016. if (n > 0)
  1017. {
  1018. result << n << ((n == 1) ? TRANS(" sec ")
  1019. : TRANS(" secs "));
  1020. ++fieldsShown;
  1021. }
  1022. if (fieldsShown < 1)
  1023. {
  1024. n = abs ((int) inMilliseconds()) % 1000;
  1025. if (n > 0)
  1026. {
  1027. result << n << TRANS(" ms");
  1028. ++fieldsShown;
  1029. }
  1030. }
  1031. }
  1032. }
  1033. }
  1034. return result.trimEnd();
  1035. }
  1036. RelativeTime& RelativeTime::operator= (const RelativeTime& other) throw()
  1037. {
  1038. seconds = other.seconds;
  1039. return *this;
  1040. }
  1041. bool RelativeTime::operator== (const RelativeTime& other) const throw()
  1042. {
  1043. return seconds == other.seconds;
  1044. }
  1045. bool RelativeTime::operator!= (const RelativeTime& other) const throw()
  1046. {
  1047. return seconds != other.seconds;
  1048. }
  1049. bool RelativeTime::operator> (const RelativeTime& other) const throw()
  1050. {
  1051. return seconds > other.seconds;
  1052. }
  1053. bool RelativeTime::operator< (const RelativeTime& other) const throw()
  1054. {
  1055. return seconds < other.seconds;
  1056. }
  1057. bool RelativeTime::operator>= (const RelativeTime& other) const throw()
  1058. {
  1059. return seconds >= other.seconds;
  1060. }
  1061. bool RelativeTime::operator<= (const RelativeTime& other) const throw()
  1062. {
  1063. return seconds <= other.seconds;
  1064. }
  1065. const RelativeTime RelativeTime::operator+ (const RelativeTime& timeToAdd) const throw()
  1066. {
  1067. return RelativeTime (seconds + timeToAdd.seconds);
  1068. }
  1069. const RelativeTime RelativeTime::operator- (const RelativeTime& timeToSubtract) const throw()
  1070. {
  1071. return RelativeTime (seconds - timeToSubtract.seconds);
  1072. }
  1073. const RelativeTime RelativeTime::operator+ (const double secondsToAdd) const throw()
  1074. {
  1075. return RelativeTime (seconds + secondsToAdd);
  1076. }
  1077. const RelativeTime RelativeTime::operator- (const double secondsToSubtract) const throw()
  1078. {
  1079. return RelativeTime (seconds - secondsToSubtract);
  1080. }
  1081. const RelativeTime& RelativeTime::operator+= (const RelativeTime& timeToAdd) throw()
  1082. {
  1083. seconds += timeToAdd.seconds;
  1084. return *this;
  1085. }
  1086. const RelativeTime& RelativeTime::operator-= (const RelativeTime& timeToSubtract) throw()
  1087. {
  1088. seconds -= timeToSubtract.seconds;
  1089. return *this;
  1090. }
  1091. const RelativeTime& RelativeTime::operator+= (const double secondsToAdd) throw()
  1092. {
  1093. seconds += secondsToAdd;
  1094. return *this;
  1095. }
  1096. const RelativeTime& RelativeTime::operator-= (const double secondsToSubtract) throw()
  1097. {
  1098. seconds -= secondsToSubtract;
  1099. return *this;
  1100. }
  1101. END_JUCE_NAMESPACE
  1102. /*** End of inlined file: juce_RelativeTime.cpp ***/
  1103. /*** Start of inlined file: juce_SystemStats.cpp ***/
  1104. BEGIN_JUCE_NAMESPACE
  1105. const String SystemStats::getJUCEVersion() throw()
  1106. {
  1107. return "JUCE v" + String (JUCE_MAJOR_VERSION)
  1108. + "." + String (JUCE_MINOR_VERSION)
  1109. + "." + String (JUCE_BUILDNUMBER);
  1110. }
  1111. const StringArray SystemStats::getMACAddressStrings()
  1112. {
  1113. int64 macAddresses [16];
  1114. const int numAddresses = getMACAddresses (macAddresses, numElementsInArray (macAddresses), false);
  1115. StringArray s;
  1116. for (int i = 0; i < numAddresses; ++i)
  1117. {
  1118. s.add (String::toHexString (0xff & (int) (macAddresses [i] >> 40)).paddedLeft ('0', 2)
  1119. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 32)).paddedLeft ('0', 2)
  1120. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 24)).paddedLeft ('0', 2)
  1121. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 16)).paddedLeft ('0', 2)
  1122. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 8)).paddedLeft ('0', 2)
  1123. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 0)).paddedLeft ('0', 2));
  1124. }
  1125. return s;
  1126. }
  1127. static bool juceInitialisedNonGUI = false;
  1128. void JUCE_PUBLIC_FUNCTION initialiseJuce_NonGUI()
  1129. {
  1130. if (! juceInitialisedNonGUI)
  1131. {
  1132. #if JUCE_MAC || JUCE_IPHONE
  1133. const ScopedAutoReleasePool pool;
  1134. #endif
  1135. #ifdef JUCE_DEBUG
  1136. {
  1137. // Some simple test code to keep an eye on things and make sure these functions
  1138. // work ok on all platforms. Let me know if any of these assertions fail!
  1139. static_jassert (sizeof (pointer_sized_int) == sizeof (void*));
  1140. char a1[7];
  1141. jassert (numElementsInArray(a1) == 7);
  1142. int a2[3];
  1143. jassert (numElementsInArray(a2) == 3);
  1144. int n = 1;
  1145. Atomic::increment (n);
  1146. jassert (Atomic::incrementAndReturn (n) == 3);
  1147. Atomic::decrement (n);
  1148. jassert (Atomic::decrementAndReturn (n) == 1);
  1149. jassert (ByteOrder::swap ((uint16) 0x1122) == 0x2211);
  1150. jassert (ByteOrder::swap ((uint32) 0x11223344) == 0x44332211);
  1151. // Some quick stream tests..
  1152. int randomInt = Random::getSystemRandom().nextInt();
  1153. int64 randomInt64 = Random::getSystemRandom().nextInt64();
  1154. double randomDouble = Random::getSystemRandom().nextDouble();
  1155. String randomString;
  1156. for (int i = 50; --i >= 0;)
  1157. randomString << (juce_wchar) (Random::getSystemRandom().nextInt() & 0xffff);
  1158. MemoryOutputStream mo;
  1159. mo.writeInt (randomInt);
  1160. mo.writeIntBigEndian (randomInt);
  1161. mo.writeCompressedInt (randomInt);
  1162. mo.writeString (randomString);
  1163. mo.writeInt64 (randomInt64);
  1164. mo.writeInt64BigEndian (randomInt64);
  1165. mo.writeDouble (randomDouble);
  1166. mo.writeDoubleBigEndian (randomDouble);
  1167. MemoryInputStream mi (mo.getData(), mo.getDataSize(), false);
  1168. jassert (mi.readInt() == randomInt);
  1169. jassert (mi.readIntBigEndian() == randomInt);
  1170. jassert (mi.readCompressedInt() == randomInt);
  1171. jassert (mi.readString() == randomString);
  1172. jassert (mi.readInt64() == randomInt64);
  1173. jassert (mi.readInt64BigEndian() == randomInt64);
  1174. jassert (mi.readDouble() == randomDouble);
  1175. jassert (mi.readDoubleBigEndian() == randomDouble);
  1176. }
  1177. #endif
  1178. // Now the real initialisation..
  1179. juceInitialisedNonGUI = true;
  1180. DBG (SystemStats::getJUCEVersion());
  1181. SystemStats::initialiseStats();
  1182. Random::getSystemRandom().setSeedRandomly(); // (mustn't call this before initialiseStats() because it relies on the time being set up)
  1183. }
  1184. }
  1185. #if JUCE_WINDOWS
  1186. // This is imported from the sockets code..
  1187. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  1188. extern juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib;
  1189. #endif
  1190. #if JUCE_DEBUG
  1191. extern void juce_CheckForDanglingStreams();
  1192. #endif
  1193. void JUCE_PUBLIC_FUNCTION shutdownJuce_NonGUI()
  1194. {
  1195. if (juceInitialisedNonGUI)
  1196. {
  1197. #if JUCE_MAC || JUCE_IPHONE
  1198. const ScopedAutoReleasePool pool;
  1199. #endif
  1200. #if JUCE_WINDOWS
  1201. // need to shut down sockets if they were used..
  1202. if (juce_CloseWin32SocketLib != 0)
  1203. (*juce_CloseWin32SocketLib)();
  1204. #endif
  1205. LocalisedStrings::setCurrentMappings (0);
  1206. Thread::stopAllThreads (3000);
  1207. #if JUCE_DEBUG
  1208. juce_CheckForDanglingStreams();
  1209. #endif
  1210. juceInitialisedNonGUI = false;
  1211. }
  1212. }
  1213. #ifdef JUCE_DLL
  1214. void* juce_Malloc (const int size)
  1215. {
  1216. return malloc (size);
  1217. }
  1218. void* juce_Calloc (const int size)
  1219. {
  1220. return calloc (1, size);
  1221. }
  1222. void* juce_Realloc (void* const block, const int size)
  1223. {
  1224. return realloc (block, size);
  1225. }
  1226. void juce_Free (void* const block)
  1227. {
  1228. free (block);
  1229. }
  1230. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  1231. void* juce_DebugMalloc (const int size, const char* file, const int line)
  1232. {
  1233. return _malloc_dbg (size, _NORMAL_BLOCK, file, line);
  1234. }
  1235. void* juce_DebugCalloc (const int size, const char* file, const int line)
  1236. {
  1237. return _calloc_dbg (1, size, _NORMAL_BLOCK, file, line);
  1238. }
  1239. void* juce_DebugRealloc (void* const block, const int size, const char* file, const int line)
  1240. {
  1241. return _realloc_dbg (block, size, _NORMAL_BLOCK, file, line);
  1242. }
  1243. void juce_DebugFree (void* const block)
  1244. {
  1245. _free_dbg (block, _NORMAL_BLOCK);
  1246. }
  1247. #endif
  1248. #endif
  1249. END_JUCE_NAMESPACE
  1250. /*** End of inlined file: juce_SystemStats.cpp ***/
  1251. /*** Start of inlined file: juce_Time.cpp ***/
  1252. #ifdef _MSC_VER
  1253. #pragma warning (disable: 4514)
  1254. #pragma warning (push)
  1255. #endif
  1256. #ifndef JUCE_WINDOWS
  1257. #include <sys/time.h>
  1258. #else
  1259. #include <ctime>
  1260. #endif
  1261. #include <sys/timeb.h>
  1262. BEGIN_JUCE_NAMESPACE
  1263. #ifdef _MSC_VER
  1264. #pragma warning (pop)
  1265. #ifdef _INC_TIME_INL
  1266. #define USE_NEW_SECURE_TIME_FNS
  1267. #endif
  1268. #endif
  1269. namespace TimeHelpers
  1270. {
  1271. static struct tm millisToLocal (const int64 millis) throw()
  1272. {
  1273. struct tm result;
  1274. const int64 seconds = millis / 1000;
  1275. if (seconds < literal64bit (86400) || seconds >= literal64bit (2145916800))
  1276. {
  1277. // use extended maths for dates beyond 1970 to 2037..
  1278. const int timeZoneAdjustment = 31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000);
  1279. const int64 jdm = seconds + timeZoneAdjustment + literal64bit (210866803200);
  1280. const int days = (int) (jdm / literal64bit (86400));
  1281. const int a = 32044 + days;
  1282. const int b = (4 * a + 3) / 146097;
  1283. const int c = a - (b * 146097) / 4;
  1284. const int d = (4 * c + 3) / 1461;
  1285. const int e = c - (d * 1461) / 4;
  1286. const int m = (5 * e + 2) / 153;
  1287. result.tm_mday = e - (153 * m + 2) / 5 + 1;
  1288. result.tm_mon = m + 2 - 12 * (m / 10);
  1289. result.tm_year = b * 100 + d - 6700 + (m / 10);
  1290. result.tm_wday = (days + 1) % 7;
  1291. result.tm_yday = -1;
  1292. int t = (int) (jdm % literal64bit (86400));
  1293. result.tm_hour = t / 3600;
  1294. t %= 3600;
  1295. result.tm_min = t / 60;
  1296. result.tm_sec = t % 60;
  1297. result.tm_isdst = -1;
  1298. }
  1299. else
  1300. {
  1301. time_t now = static_cast <time_t> (seconds);
  1302. #if JUCE_WINDOWS
  1303. #ifdef USE_NEW_SECURE_TIME_FNS
  1304. if (now >= 0 && now <= 0x793406fff)
  1305. localtime_s (&result, &now);
  1306. else
  1307. zeromem (&result, sizeof (result));
  1308. #else
  1309. result = *localtime (&now);
  1310. #endif
  1311. #else
  1312. // more thread-safe
  1313. localtime_r (&now, &result);
  1314. #endif
  1315. }
  1316. return result;
  1317. }
  1318. static int extendedModulo (const int64 value, const int modulo) throw()
  1319. {
  1320. return (int) (value >= 0 ? (value % modulo)
  1321. : (value - ((value / modulo) + 1) * modulo));
  1322. }
  1323. static uint32 lastMSCounterValue = 0;
  1324. }
  1325. Time::Time() throw()
  1326. : millisSinceEpoch (0)
  1327. {
  1328. }
  1329. Time::Time (const Time& other) throw()
  1330. : millisSinceEpoch (other.millisSinceEpoch)
  1331. {
  1332. }
  1333. Time::Time (const int64 ms) throw()
  1334. : millisSinceEpoch (ms)
  1335. {
  1336. }
  1337. Time::Time (const int year,
  1338. const int month,
  1339. const int day,
  1340. const int hours,
  1341. const int minutes,
  1342. const int seconds,
  1343. const int milliseconds,
  1344. const bool useLocalTime) throw()
  1345. {
  1346. jassert (year > 100); // year must be a 4-digit version
  1347. if (year < 1971 || year >= 2038 || ! useLocalTime)
  1348. {
  1349. // use extended maths for dates beyond 1970 to 2037..
  1350. const int timeZoneAdjustment = useLocalTime ? (31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000))
  1351. : 0;
  1352. const int a = (13 - month) / 12;
  1353. const int y = year + 4800 - a;
  1354. const int jd = day + (153 * (month + 12 * a - 2) + 2) / 5
  1355. + (y * 365) + (y / 4) - (y / 100) + (y / 400)
  1356. - 32045;
  1357. const int64 s = ((int64) jd) * literal64bit (86400) - literal64bit (210866803200);
  1358. millisSinceEpoch = 1000 * (s + (hours * 3600 + minutes * 60 + seconds - timeZoneAdjustment))
  1359. + milliseconds;
  1360. }
  1361. else
  1362. {
  1363. struct tm t;
  1364. t.tm_year = year - 1900;
  1365. t.tm_mon = month;
  1366. t.tm_mday = day;
  1367. t.tm_hour = hours;
  1368. t.tm_min = minutes;
  1369. t.tm_sec = seconds;
  1370. t.tm_isdst = -1;
  1371. millisSinceEpoch = 1000 * (int64) mktime (&t);
  1372. if (millisSinceEpoch < 0)
  1373. millisSinceEpoch = 0;
  1374. else
  1375. millisSinceEpoch += milliseconds;
  1376. }
  1377. }
  1378. Time::~Time() throw()
  1379. {
  1380. }
  1381. Time& Time::operator= (const Time& other) throw()
  1382. {
  1383. millisSinceEpoch = other.millisSinceEpoch;
  1384. return *this;
  1385. }
  1386. int64 Time::currentTimeMillis() throw()
  1387. {
  1388. static uint32 lastCounterResult = 0xffffffff;
  1389. static int64 correction = 0;
  1390. const uint32 now = getMillisecondCounter();
  1391. // check the counter hasn't wrapped (also triggered the first time this function is called)
  1392. if (now < lastCounterResult)
  1393. {
  1394. // double-check it's actually wrapped, in case multi-cpu machines have timers that drift a bit.
  1395. if (lastCounterResult == 0xffffffff || now < lastCounterResult - 10)
  1396. {
  1397. // get the time once using normal library calls, and store the difference needed to
  1398. // turn the millisecond counter into a real time.
  1399. #if JUCE_WINDOWS
  1400. struct _timeb t;
  1401. #ifdef USE_NEW_SECURE_TIME_FNS
  1402. _ftime_s (&t);
  1403. #else
  1404. _ftime (&t);
  1405. #endif
  1406. correction = (((int64) t.time) * 1000 + t.millitm) - now;
  1407. #else
  1408. struct timeval tv;
  1409. struct timezone tz;
  1410. gettimeofday (&tv, &tz);
  1411. correction = (((int64) tv.tv_sec) * 1000 + tv.tv_usec / 1000) - now;
  1412. #endif
  1413. }
  1414. }
  1415. lastCounterResult = now;
  1416. return correction + now;
  1417. }
  1418. uint32 juce_millisecondsSinceStartup() throw();
  1419. uint32 Time::getMillisecondCounter() throw()
  1420. {
  1421. const uint32 now = juce_millisecondsSinceStartup();
  1422. if (now < TimeHelpers::lastMSCounterValue)
  1423. {
  1424. // in multi-threaded apps this might be called concurrently, so
  1425. // make sure that our last counter value only increases and doesn't
  1426. // go backwards..
  1427. if (now < TimeHelpers::lastMSCounterValue - 1000)
  1428. TimeHelpers::lastMSCounterValue = now;
  1429. }
  1430. else
  1431. {
  1432. TimeHelpers::lastMSCounterValue = now;
  1433. }
  1434. return now;
  1435. }
  1436. uint32 Time::getApproximateMillisecondCounter() throw()
  1437. {
  1438. jassert (TimeHelpers::lastMSCounterValue != 0);
  1439. return TimeHelpers::lastMSCounterValue;
  1440. }
  1441. void Time::waitForMillisecondCounter (const uint32 targetTime) throw()
  1442. {
  1443. for (;;)
  1444. {
  1445. const uint32 now = getMillisecondCounter();
  1446. if (now >= targetTime)
  1447. break;
  1448. const int toWait = targetTime - now;
  1449. if (toWait > 2)
  1450. {
  1451. Thread::sleep (jmin (20, toWait >> 1));
  1452. }
  1453. else
  1454. {
  1455. // xxx should consider using mutex_pause on the mac as it apparently
  1456. // makes it seem less like a spinlock and avoids lowering the thread pri.
  1457. for (int i = 10; --i >= 0;)
  1458. Thread::yield();
  1459. }
  1460. }
  1461. }
  1462. double Time::highResolutionTicksToSeconds (const int64 ticks) throw()
  1463. {
  1464. return ticks / (double) getHighResolutionTicksPerSecond();
  1465. }
  1466. int64 Time::secondsToHighResolutionTicks (const double seconds) throw()
  1467. {
  1468. return (int64) (seconds * (double) getHighResolutionTicksPerSecond());
  1469. }
  1470. const Time JUCE_CALLTYPE Time::getCurrentTime() throw()
  1471. {
  1472. return Time (currentTimeMillis());
  1473. }
  1474. const String Time::toString (const bool includeDate,
  1475. const bool includeTime,
  1476. const bool includeSeconds,
  1477. const bool use24HourClock) const throw()
  1478. {
  1479. String result;
  1480. if (includeDate)
  1481. {
  1482. result << getDayOfMonth() << ' '
  1483. << getMonthName (true) << ' '
  1484. << getYear();
  1485. if (includeTime)
  1486. result << ' ';
  1487. }
  1488. if (includeTime)
  1489. {
  1490. const int mins = getMinutes();
  1491. result << (use24HourClock ? getHours() : getHoursInAmPmFormat())
  1492. << (mins < 10 ? ":0" : ":") << mins;
  1493. if (includeSeconds)
  1494. {
  1495. const int secs = getSeconds();
  1496. result << (secs < 10 ? ":0" : ":") << secs;
  1497. }
  1498. if (! use24HourClock)
  1499. result << (isAfternoon() ? "pm" : "am");
  1500. }
  1501. return result.trimEnd();
  1502. }
  1503. const String Time::formatted (const juce_wchar* const format) const throw()
  1504. {
  1505. String buffer;
  1506. int bufferSize = 128;
  1507. buffer.preallocateStorage (bufferSize);
  1508. struct tm t (TimeHelpers::millisToLocal (millisSinceEpoch));
  1509. while (CharacterFunctions::ftime (static_cast <juce_wchar*> (buffer), bufferSize, format, &t) <= 0)
  1510. {
  1511. bufferSize += 128;
  1512. buffer.preallocateStorage (bufferSize);
  1513. }
  1514. return buffer;
  1515. }
  1516. int Time::getYear() const throw()
  1517. {
  1518. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_year + 1900;
  1519. }
  1520. int Time::getMonth() const throw()
  1521. {
  1522. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_mon;
  1523. }
  1524. int Time::getDayOfMonth() const throw()
  1525. {
  1526. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_mday;
  1527. }
  1528. int Time::getDayOfWeek() const throw()
  1529. {
  1530. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_wday;
  1531. }
  1532. int Time::getHours() const throw()
  1533. {
  1534. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_hour;
  1535. }
  1536. int Time::getHoursInAmPmFormat() const throw()
  1537. {
  1538. const int hours = getHours();
  1539. if (hours == 0)
  1540. return 12;
  1541. else if (hours <= 12)
  1542. return hours;
  1543. else
  1544. return hours - 12;
  1545. }
  1546. bool Time::isAfternoon() const throw()
  1547. {
  1548. return getHours() >= 12;
  1549. }
  1550. int Time::getMinutes() const throw()
  1551. {
  1552. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_min;
  1553. }
  1554. int Time::getSeconds() const throw()
  1555. {
  1556. return TimeHelpers::extendedModulo (millisSinceEpoch / 1000, 60);
  1557. }
  1558. int Time::getMilliseconds() const throw()
  1559. {
  1560. return TimeHelpers::extendedModulo (millisSinceEpoch, 1000);
  1561. }
  1562. bool Time::isDaylightSavingTime() const throw()
  1563. {
  1564. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_isdst != 0;
  1565. }
  1566. const String Time::getTimeZone() const throw()
  1567. {
  1568. String zone[2];
  1569. #if JUCE_WINDOWS
  1570. _tzset();
  1571. #ifdef USE_NEW_SECURE_TIME_FNS
  1572. {
  1573. char name [128];
  1574. size_t length;
  1575. for (int i = 0; i < 2; ++i)
  1576. {
  1577. zeromem (name, sizeof (name));
  1578. _get_tzname (&length, name, 127, i);
  1579. zone[i] = name;
  1580. }
  1581. }
  1582. #else
  1583. const char** const zonePtr = (const char**) _tzname;
  1584. zone[0] = zonePtr[0];
  1585. zone[1] = zonePtr[1];
  1586. #endif
  1587. #else
  1588. tzset();
  1589. const char** const zonePtr = (const char**) tzname;
  1590. zone[0] = zonePtr[0];
  1591. zone[1] = zonePtr[1];
  1592. #endif
  1593. if (isDaylightSavingTime())
  1594. {
  1595. zone[0] = zone[1];
  1596. if (zone[0].length() > 3
  1597. && zone[0].containsIgnoreCase (T("daylight"))
  1598. && zone[0].contains (T("GMT")))
  1599. zone[0] = "BST";
  1600. }
  1601. return zone[0].substring (0, 3);
  1602. }
  1603. const String Time::getMonthName (const bool threeLetterVersion) const throw()
  1604. {
  1605. return getMonthName (getMonth(), threeLetterVersion);
  1606. }
  1607. const String Time::getWeekdayName (const bool threeLetterVersion) const throw()
  1608. {
  1609. return getWeekdayName (getDayOfWeek(), threeLetterVersion);
  1610. }
  1611. const String Time::getMonthName (int monthNumber, const bool threeLetterVersion) throw()
  1612. {
  1613. const char* const shortMonthNames[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
  1614. const char* const longMonthNames[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
  1615. monthNumber %= 12;
  1616. return TRANS (threeLetterVersion ? shortMonthNames [monthNumber]
  1617. : longMonthNames [monthNumber]);
  1618. }
  1619. const String Time::getWeekdayName (int day, const bool threeLetterVersion) throw()
  1620. {
  1621. const char* const shortDayNames[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
  1622. const char* const longDayNames[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
  1623. day %= 7;
  1624. return TRANS (threeLetterVersion ? shortDayNames [day]
  1625. : longDayNames [day]);
  1626. }
  1627. END_JUCE_NAMESPACE
  1628. /*** End of inlined file: juce_Time.cpp ***/
  1629. /*** Start of inlined file: juce_BitArray.cpp ***/
  1630. BEGIN_JUCE_NAMESPACE
  1631. BigInteger::BigInteger()
  1632. : numValues (4),
  1633. highestBit (-1),
  1634. negative (false)
  1635. {
  1636. values.calloc (numValues + 1);
  1637. }
  1638. BigInteger::BigInteger (const int value)
  1639. : numValues (4),
  1640. highestBit (31),
  1641. negative (value < 0)
  1642. {
  1643. values.calloc (numValues + 1);
  1644. values[0] = abs (value);
  1645. highestBit = getHighestBit();
  1646. }
  1647. BigInteger::BigInteger (int64 value)
  1648. : numValues (4),
  1649. highestBit (63),
  1650. negative (value < 0)
  1651. {
  1652. values.calloc (numValues + 1);
  1653. if (value < 0)
  1654. value = -value;
  1655. values[0] = (unsigned int) value;
  1656. values[1] = (unsigned int) (value >> 32);
  1657. highestBit = getHighestBit();
  1658. }
  1659. BigInteger::BigInteger (const unsigned int value)
  1660. : numValues (4),
  1661. highestBit (31),
  1662. negative (false)
  1663. {
  1664. values.calloc (numValues + 1);
  1665. values[0] = value;
  1666. highestBit = getHighestBit();
  1667. }
  1668. BigInteger::BigInteger (const BigInteger& other)
  1669. : numValues (jmax (4, (other.highestBit >> 5) + 1)),
  1670. highestBit (other.getHighestBit()),
  1671. negative (other.negative)
  1672. {
  1673. values.malloc (numValues + 1);
  1674. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1675. }
  1676. BigInteger::~BigInteger()
  1677. {
  1678. }
  1679. void BigInteger::swapWith (BigInteger& other) throw()
  1680. {
  1681. values.swapWith (other.values);
  1682. swapVariables (numValues, other.numValues);
  1683. swapVariables (highestBit, other.highestBit);
  1684. swapVariables (negative, other.negative);
  1685. }
  1686. BigInteger& BigInteger::operator= (const BigInteger& other)
  1687. {
  1688. if (this != &other)
  1689. {
  1690. highestBit = other.getHighestBit();
  1691. numValues = jmax (4, (highestBit >> 5) + 1);
  1692. negative = other.negative;
  1693. values.malloc (numValues + 1);
  1694. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1695. }
  1696. return *this;
  1697. }
  1698. void BigInteger::ensureSize (const int numVals)
  1699. {
  1700. if (numVals + 2 >= numValues)
  1701. {
  1702. int oldSize = numValues;
  1703. numValues = ((numVals + 2) * 3) / 2;
  1704. values.realloc (numValues + 1);
  1705. while (oldSize < numValues)
  1706. values [oldSize++] = 0;
  1707. }
  1708. }
  1709. bool BigInteger::operator[] (const int bit) const throw()
  1710. {
  1711. return bit <= highestBit && bit >= 0
  1712. && ((values [bit >> 5] & (1 << (bit & 31))) != 0);
  1713. }
  1714. int BigInteger::toInteger() const throw()
  1715. {
  1716. const int n = (int) (values[0] & 0x7fffffff);
  1717. return negative ? -n : n;
  1718. }
  1719. const BigInteger BigInteger::getBitRange (int startBit, int numBits) const
  1720. {
  1721. BigInteger r;
  1722. numBits = jmin (numBits, getHighestBit() + 1 - startBit);
  1723. r.ensureSize (numBits >> 5);
  1724. r.highestBit = numBits;
  1725. int i = 0;
  1726. while (numBits > 0)
  1727. {
  1728. r.values[i++] = getBitRangeAsInt (startBit, jmin (32, numBits));
  1729. numBits -= 32;
  1730. startBit += 32;
  1731. }
  1732. r.highestBit = r.getHighestBit();
  1733. return r;
  1734. }
  1735. int BigInteger::getBitRangeAsInt (const int startBit, int numBits) const throw()
  1736. {
  1737. if (numBits > 32)
  1738. {
  1739. jassertfalse // use getBitRange() if you need more than 32 bits..
  1740. numBits = 32;
  1741. }
  1742. numBits = jmin (numBits, highestBit + 1 - startBit);
  1743. if (numBits <= 0)
  1744. return 0;
  1745. const int pos = startBit >> 5;
  1746. const int offset = startBit & 31;
  1747. const int endSpace = 32 - numBits;
  1748. uint32 n = ((uint32) values [pos]) >> offset;
  1749. if (offset > endSpace)
  1750. n |= ((uint32) values [pos + 1]) << (32 - offset);
  1751. return (int) (n & (((uint32) 0xffffffff) >> endSpace));
  1752. }
  1753. void BigInteger::setBitRangeAsInt (const int startBit, int numBits, unsigned int valueToSet)
  1754. {
  1755. if (numBits > 32)
  1756. {
  1757. jassertfalse
  1758. numBits = 32;
  1759. }
  1760. for (int i = 0; i < numBits; ++i)
  1761. {
  1762. setBit (startBit + i, (valueToSet & 1) != 0);
  1763. valueToSet >>= 1;
  1764. }
  1765. }
  1766. void BigInteger::clear()
  1767. {
  1768. if (numValues > 16)
  1769. {
  1770. numValues = 4;
  1771. values.calloc (numValues + 1);
  1772. }
  1773. else
  1774. {
  1775. zeromem (values, sizeof (unsigned int) * (numValues + 1));
  1776. }
  1777. highestBit = -1;
  1778. negative = false;
  1779. }
  1780. void BigInteger::setBit (const int bit)
  1781. {
  1782. if (bit >= 0)
  1783. {
  1784. if (bit > highestBit)
  1785. {
  1786. ensureSize (bit >> 5);
  1787. highestBit = bit;
  1788. }
  1789. values [bit >> 5] |= (1 << (bit & 31));
  1790. }
  1791. }
  1792. void BigInteger::setBit (const int bit, const bool shouldBeSet)
  1793. {
  1794. if (shouldBeSet)
  1795. setBit (bit);
  1796. else
  1797. clearBit (bit);
  1798. }
  1799. void BigInteger::clearBit (const int bit) throw()
  1800. {
  1801. if (bit >= 0 && bit <= highestBit)
  1802. values [bit >> 5] &= ~(1 << (bit & 31));
  1803. }
  1804. void BigInteger::setRange (int startBit, int numBits, const bool shouldBeSet)
  1805. {
  1806. while (--numBits >= 0)
  1807. setBit (startBit++, shouldBeSet);
  1808. }
  1809. void BigInteger::insertBit (const int bit, const bool shouldBeSet)
  1810. {
  1811. if (bit >= 0)
  1812. shiftBits (1, bit);
  1813. setBit (bit, shouldBeSet);
  1814. }
  1815. bool BigInteger::isZero() const throw()
  1816. {
  1817. return getHighestBit() < 0;
  1818. }
  1819. bool BigInteger::isOne() const throw()
  1820. {
  1821. return getHighestBit() == 0 && ! negative;
  1822. }
  1823. bool BigInteger::isNegative() const throw()
  1824. {
  1825. return negative && ! isZero();
  1826. }
  1827. void BigInteger::setNegative (const bool neg) throw()
  1828. {
  1829. negative = neg;
  1830. }
  1831. void BigInteger::negate() throw()
  1832. {
  1833. negative = (! negative) && ! isZero();
  1834. }
  1835. int BigInteger::countNumberOfSetBits() const throw()
  1836. {
  1837. int total = 0;
  1838. for (int i = (highestBit >> 5) + 1; --i >= 0;)
  1839. {
  1840. unsigned int n = values[i];
  1841. if (n == 0xffffffff)
  1842. {
  1843. total += 32;
  1844. }
  1845. else
  1846. {
  1847. while (n != 0)
  1848. {
  1849. total += (n & 1);
  1850. n >>= 1;
  1851. }
  1852. }
  1853. }
  1854. return total;
  1855. }
  1856. int BigInteger::getHighestBit() const throw()
  1857. {
  1858. for (int i = highestBit + 1; --i >= 0;)
  1859. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  1860. return i;
  1861. return -1;
  1862. }
  1863. int BigInteger::findNextSetBit (int i) const throw()
  1864. {
  1865. for (; i <= highestBit; ++i)
  1866. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  1867. return i;
  1868. return -1;
  1869. }
  1870. int BigInteger::findNextClearBit (int i) const throw()
  1871. {
  1872. for (; i <= highestBit; ++i)
  1873. if ((values [i >> 5] & (1 << (i & 31))) == 0)
  1874. break;
  1875. return i;
  1876. }
  1877. BigInteger& BigInteger::operator+= (const BigInteger& other)
  1878. {
  1879. if (other.isNegative())
  1880. return operator-= (-other);
  1881. if (isNegative())
  1882. {
  1883. if (compareAbsolute (other) < 0)
  1884. {
  1885. BigInteger temp (*this);
  1886. temp.negate();
  1887. *this = other;
  1888. operator-= (temp);
  1889. }
  1890. else
  1891. {
  1892. negate();
  1893. operator-= (other);
  1894. negate();
  1895. }
  1896. }
  1897. else
  1898. {
  1899. if (other.highestBit > highestBit)
  1900. highestBit = other.highestBit;
  1901. ++highestBit;
  1902. const int numInts = (highestBit >> 5) + 1;
  1903. ensureSize (numInts);
  1904. int64 remainder = 0;
  1905. for (int i = 0; i <= numInts; ++i)
  1906. {
  1907. if (i < numValues)
  1908. remainder += values[i];
  1909. if (i < other.numValues)
  1910. remainder += other.values[i];
  1911. values[i] = (unsigned int) remainder;
  1912. remainder >>= 32;
  1913. }
  1914. jassert (remainder == 0);
  1915. highestBit = getHighestBit();
  1916. }
  1917. return *this;
  1918. }
  1919. BigInteger& BigInteger::operator-= (const BigInteger& other)
  1920. {
  1921. if (other.isNegative())
  1922. return operator+= (-other);
  1923. if (! isNegative())
  1924. {
  1925. if (compareAbsolute (other) < 0)
  1926. {
  1927. BigInteger temp (other);
  1928. swapWith (temp);
  1929. operator-= (temp);
  1930. negate();
  1931. return *this;
  1932. }
  1933. }
  1934. else
  1935. {
  1936. negate();
  1937. operator+= (other);
  1938. negate();
  1939. return *this;
  1940. }
  1941. const int numInts = (highestBit >> 5) + 1;
  1942. const int maxOtherInts = (other.highestBit >> 5) + 1;
  1943. int64 amountToSubtract = 0;
  1944. for (int i = 0; i <= numInts; ++i)
  1945. {
  1946. if (i <= maxOtherInts)
  1947. amountToSubtract += (int64) other.values[i];
  1948. if (values[i] >= amountToSubtract)
  1949. {
  1950. values[i] = (unsigned int) (values[i] - amountToSubtract);
  1951. amountToSubtract = 0;
  1952. }
  1953. else
  1954. {
  1955. const int64 n = ((int64) values[i] + (((int64) 1) << 32)) - amountToSubtract;
  1956. values[i] = (unsigned int) n;
  1957. amountToSubtract = 1;
  1958. }
  1959. }
  1960. return *this;
  1961. }
  1962. BigInteger& BigInteger::operator*= (const BigInteger& other)
  1963. {
  1964. BigInteger total;
  1965. highestBit = getHighestBit();
  1966. const bool wasNegative = isNegative();
  1967. setNegative (false);
  1968. for (int i = 0; i <= highestBit; ++i)
  1969. {
  1970. if (operator[](i))
  1971. {
  1972. BigInteger n (other);
  1973. n.setNegative (false);
  1974. n <<= i;
  1975. total += n;
  1976. }
  1977. }
  1978. total.setNegative (wasNegative ^ other.isNegative());
  1979. swapWith (total);
  1980. return *this;
  1981. }
  1982. void BigInteger::divideBy (const BigInteger& divisor, BigInteger& remainder)
  1983. {
  1984. jassert (this != &remainder); // (can't handle passing itself in to get the remainder)
  1985. const int divHB = divisor.getHighestBit();
  1986. const int ourHB = getHighestBit();
  1987. if (divHB < 0 || ourHB < 0)
  1988. {
  1989. // division by zero
  1990. remainder.clear();
  1991. clear();
  1992. }
  1993. else
  1994. {
  1995. const bool wasNegative = isNegative();
  1996. swapWith (remainder);
  1997. remainder.setNegative (false);
  1998. clear();
  1999. BigInteger temp (divisor);
  2000. temp.setNegative (false);
  2001. int leftShift = ourHB - divHB;
  2002. temp <<= leftShift;
  2003. while (leftShift >= 0)
  2004. {
  2005. if (remainder.compareAbsolute (temp) >= 0)
  2006. {
  2007. remainder -= temp;
  2008. setBit (leftShift);
  2009. }
  2010. if (--leftShift >= 0)
  2011. temp >>= 1;
  2012. }
  2013. negative = wasNegative ^ divisor.isNegative();
  2014. remainder.setNegative (wasNegative);
  2015. }
  2016. }
  2017. BigInteger& BigInteger::operator/= (const BigInteger& other)
  2018. {
  2019. BigInteger remainder;
  2020. divideBy (other, remainder);
  2021. return *this;
  2022. }
  2023. BigInteger& BigInteger::operator|= (const BigInteger& other)
  2024. {
  2025. // this operation doesn't take into account negative values..
  2026. jassert (isNegative() == other.isNegative());
  2027. if (other.highestBit >= 0)
  2028. {
  2029. ensureSize (other.highestBit >> 5);
  2030. int n = (other.highestBit >> 5) + 1;
  2031. while (--n >= 0)
  2032. values[n] |= other.values[n];
  2033. if (other.highestBit > highestBit)
  2034. highestBit = other.highestBit;
  2035. highestBit = getHighestBit();
  2036. }
  2037. return *this;
  2038. }
  2039. BigInteger& BigInteger::operator&= (const BigInteger& other)
  2040. {
  2041. // this operation doesn't take into account negative values..
  2042. jassert (isNegative() == other.isNegative());
  2043. int n = numValues;
  2044. while (n > other.numValues)
  2045. values[--n] = 0;
  2046. while (--n >= 0)
  2047. values[n] &= other.values[n];
  2048. if (other.highestBit < highestBit)
  2049. highestBit = other.highestBit;
  2050. highestBit = getHighestBit();
  2051. return *this;
  2052. }
  2053. BigInteger& BigInteger::operator^= (const BigInteger& other)
  2054. {
  2055. // this operation will only work with the absolute values
  2056. jassert (isNegative() == other.isNegative());
  2057. if (other.highestBit >= 0)
  2058. {
  2059. ensureSize (other.highestBit >> 5);
  2060. int n = (other.highestBit >> 5) + 1;
  2061. while (--n >= 0)
  2062. values[n] ^= other.values[n];
  2063. if (other.highestBit > highestBit)
  2064. highestBit = other.highestBit;
  2065. highestBit = getHighestBit();
  2066. }
  2067. return *this;
  2068. }
  2069. BigInteger& BigInteger::operator%= (const BigInteger& divisor)
  2070. {
  2071. BigInteger remainder;
  2072. divideBy (divisor, remainder);
  2073. swapWith (remainder);
  2074. return *this;
  2075. }
  2076. BigInteger& BigInteger::operator<<= (int numBitsToShift)
  2077. {
  2078. shiftBits (numBitsToShift, 0);
  2079. return *this;
  2080. }
  2081. BigInteger& BigInteger::operator>>= (int numBitsToShift)
  2082. {
  2083. return operator<<= (-numBitsToShift);
  2084. }
  2085. BigInteger& BigInteger::operator++() { return operator+= (1); }
  2086. BigInteger& BigInteger::operator--() { return operator-= (1); }
  2087. const BigInteger BigInteger::operator++ (int) { const BigInteger old (*this); operator+= (1); return old; }
  2088. const BigInteger BigInteger::operator-- (int) { const BigInteger old (*this); operator-= (1); return old; }
  2089. const BigInteger BigInteger::operator+ (const BigInteger& other) const { BigInteger b (*this); return b += other; }
  2090. const BigInteger BigInteger::operator- (const BigInteger& other) const { BigInteger b (*this); return b -= other; }
  2091. const BigInteger BigInteger::operator* (const BigInteger& other) const { BigInteger b (*this); return b *= other; }
  2092. const BigInteger BigInteger::operator/ (const BigInteger& other) const { BigInteger b (*this); return b /= other; }
  2093. const BigInteger BigInteger::operator| (const BigInteger& other) const { BigInteger b (*this); return b |= other; }
  2094. const BigInteger BigInteger::operator& (const BigInteger& other) const { BigInteger b (*this); return b &= other; }
  2095. const BigInteger BigInteger::operator^ (const BigInteger& other) const { BigInteger b (*this); return b ^= other; }
  2096. const BigInteger BigInteger::operator% (const BigInteger& other) const { BigInteger b (*this); return b %= other; }
  2097. const BigInteger BigInteger::operator<< (const int numBits) const { BigInteger b (*this); return b <<= numBits; }
  2098. const BigInteger BigInteger::operator>> (const int numBits) const { BigInteger b (*this); return b >>= numBits; }
  2099. const BigInteger BigInteger::operator-() const { BigInteger b (*this); b.negate(); return b; }
  2100. int BigInteger::compare (const BigInteger& other) const throw()
  2101. {
  2102. if (isNegative() == other.isNegative())
  2103. {
  2104. const int absComp = compareAbsolute (other);
  2105. return isNegative() ? -absComp : absComp;
  2106. }
  2107. else
  2108. {
  2109. return isNegative() ? -1 : 1;
  2110. }
  2111. }
  2112. int BigInteger::compareAbsolute (const BigInteger& other) const throw()
  2113. {
  2114. const int h1 = getHighestBit();
  2115. const int h2 = other.getHighestBit();
  2116. if (h1 > h2)
  2117. return 1;
  2118. else if (h1 < h2)
  2119. return -1;
  2120. for (int i = (h1 >> 5) + 1; --i >= 0;)
  2121. if (values[i] != other.values[i])
  2122. return (values[i] > other.values[i]) ? 1 : -1;
  2123. return 0;
  2124. }
  2125. bool BigInteger::operator== (const BigInteger& other) const throw() { return compare (other) == 0; }
  2126. bool BigInteger::operator!= (const BigInteger& other) const throw() { return compare (other) != 0; }
  2127. bool BigInteger::operator< (const BigInteger& other) const throw() { return compare (other) < 0; }
  2128. bool BigInteger::operator<= (const BigInteger& other) const throw() { return compare (other) <= 0; }
  2129. bool BigInteger::operator> (const BigInteger& other) const throw() { return compare (other) > 0; }
  2130. bool BigInteger::operator>= (const BigInteger& other) const throw() { return compare (other) >= 0; }
  2131. void BigInteger::shiftBits (int bits, const int startBit)
  2132. {
  2133. if (highestBit < 0)
  2134. return;
  2135. if (startBit > 0)
  2136. {
  2137. if (bits < 0)
  2138. {
  2139. // right shift
  2140. for (int i = startBit; i <= highestBit; ++i)
  2141. setBit (i, operator[] (i - bits));
  2142. highestBit = getHighestBit();
  2143. }
  2144. else if (bits > 0)
  2145. {
  2146. // left shift
  2147. for (int i = highestBit + 1; --i >= startBit;)
  2148. setBit (i + bits, operator[] (i));
  2149. while (--bits >= 0)
  2150. clearBit (bits + startBit);
  2151. }
  2152. }
  2153. else
  2154. {
  2155. if (bits < 0)
  2156. {
  2157. // right shift
  2158. bits = -bits;
  2159. if (bits > highestBit)
  2160. {
  2161. clear();
  2162. }
  2163. else
  2164. {
  2165. const int wordsToMove = bits >> 5;
  2166. int top = 1 + (highestBit >> 5) - wordsToMove;
  2167. highestBit -= bits;
  2168. if (wordsToMove > 0)
  2169. {
  2170. int i;
  2171. for (i = 0; i < top; ++i)
  2172. values [i] = values [i + wordsToMove];
  2173. for (i = 0; i < wordsToMove; ++i)
  2174. values [top + i] = 0;
  2175. bits &= 31;
  2176. }
  2177. if (bits != 0)
  2178. {
  2179. const int invBits = 32 - bits;
  2180. --top;
  2181. for (int i = 0; i < top; ++i)
  2182. values[i] = (values[i] >> bits) | (values [i + 1] << invBits);
  2183. values[top] = (values[top] >> bits);
  2184. }
  2185. highestBit = getHighestBit();
  2186. }
  2187. }
  2188. else if (bits > 0)
  2189. {
  2190. // left shift
  2191. ensureSize (((highestBit + bits) >> 5) + 1);
  2192. const int wordsToMove = bits >> 5;
  2193. int top = 1 + (highestBit >> 5);
  2194. highestBit += bits;
  2195. if (wordsToMove > 0)
  2196. {
  2197. int i;
  2198. for (i = top; --i >= 0;)
  2199. values [i + wordsToMove] = values [i];
  2200. for (i = 0; i < wordsToMove; ++i)
  2201. values [i] = 0;
  2202. bits &= 31;
  2203. }
  2204. if (bits != 0)
  2205. {
  2206. const int invBits = 32 - bits;
  2207. for (int i = top + 1 + wordsToMove; --i > wordsToMove;)
  2208. values[i] = (values[i] << bits) | (values [i - 1] >> invBits);
  2209. values [wordsToMove] = values [wordsToMove] << bits;
  2210. }
  2211. highestBit = getHighestBit();
  2212. }
  2213. }
  2214. }
  2215. const BigInteger BigInteger::simpleGCD (BigInteger* m, BigInteger* n)
  2216. {
  2217. while (! m->isZero())
  2218. {
  2219. if (n->compareAbsolute (*m) > 0)
  2220. swapVariables (m, n);
  2221. *m -= *n;
  2222. }
  2223. return *n;
  2224. }
  2225. const BigInteger BigInteger::findGreatestCommonDivisor (BigInteger n) const
  2226. {
  2227. BigInteger m (*this);
  2228. while (! n.isZero())
  2229. {
  2230. if (abs (m.getHighestBit() - n.getHighestBit()) <= 16)
  2231. return simpleGCD (&m, &n);
  2232. BigInteger temp1 (m), temp2;
  2233. temp1.divideBy (n, temp2);
  2234. m = n;
  2235. n = temp2;
  2236. }
  2237. return m;
  2238. }
  2239. void BigInteger::exponentModulo (const BigInteger& exponent, const BigInteger& modulus)
  2240. {
  2241. BigInteger exp (exponent);
  2242. exp %= modulus;
  2243. BigInteger value (1);
  2244. swapWith (value);
  2245. value %= modulus;
  2246. while (! exp.isZero())
  2247. {
  2248. if (exp [0])
  2249. {
  2250. operator*= (value);
  2251. operator%= (modulus);
  2252. }
  2253. value *= value;
  2254. value %= modulus;
  2255. exp >>= 1;
  2256. }
  2257. }
  2258. void BigInteger::inverseModulo (const BigInteger& modulus)
  2259. {
  2260. if (modulus.isOne() || modulus.isNegative())
  2261. {
  2262. clear();
  2263. return;
  2264. }
  2265. if (isNegative() || compareAbsolute (modulus) >= 0)
  2266. operator%= (modulus);
  2267. if (isOne())
  2268. return;
  2269. if (! (*this)[0])
  2270. {
  2271. // not invertible
  2272. clear();
  2273. return;
  2274. }
  2275. BigInteger a1 (modulus);
  2276. BigInteger a2 (*this);
  2277. BigInteger b1 (modulus);
  2278. BigInteger b2 (1);
  2279. while (! a2.isOne())
  2280. {
  2281. BigInteger temp1, temp2, multiplier (a1);
  2282. multiplier.divideBy (a2, temp1);
  2283. temp1 = a2;
  2284. temp1 *= multiplier;
  2285. temp2 = a1;
  2286. temp2 -= temp1;
  2287. a1 = a2;
  2288. a2 = temp2;
  2289. temp1 = b2;
  2290. temp1 *= multiplier;
  2291. temp2 = b1;
  2292. temp2 -= temp1;
  2293. b1 = b2;
  2294. b2 = temp2;
  2295. }
  2296. while (b2.isNegative())
  2297. b2 += modulus;
  2298. b2 %= modulus;
  2299. swapWith (b2);
  2300. }
  2301. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const BigInteger& value)
  2302. {
  2303. return stream << value.toString (10);
  2304. }
  2305. const String BigInteger::toString (const int base, const int minimumNumCharacters) const
  2306. {
  2307. String s;
  2308. BigInteger v (*this);
  2309. if (base == 2 || base == 8 || base == 16)
  2310. {
  2311. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2312. static const char* const hexDigits = "0123456789abcdef";
  2313. for (;;)
  2314. {
  2315. const int remainder = v.getBitRangeAsInt (0, bits);
  2316. v >>= bits;
  2317. if (remainder == 0 && v.isZero())
  2318. break;
  2319. s = String::charToString (hexDigits [remainder]) + s;
  2320. }
  2321. }
  2322. else if (base == 10)
  2323. {
  2324. const BigInteger ten (10);
  2325. BigInteger remainder;
  2326. for (;;)
  2327. {
  2328. v.divideBy (ten, remainder);
  2329. if (remainder.isZero() && v.isZero())
  2330. break;
  2331. s = String (remainder.getBitRangeAsInt (0, 8)) + s;
  2332. }
  2333. }
  2334. else
  2335. {
  2336. jassertfalse // can't do the specified base!
  2337. return String::empty;
  2338. }
  2339. s = s.paddedLeft ('0', minimumNumCharacters);
  2340. return isNegative() ? "-" + s : s;
  2341. }
  2342. void BigInteger::parseString (const String& text, const int base)
  2343. {
  2344. clear();
  2345. const juce_wchar* t = (const juce_wchar*) text;
  2346. if (base == 2 || base == 8 || base == 16)
  2347. {
  2348. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2349. for (;;)
  2350. {
  2351. const juce_wchar c = *t++;
  2352. const int digit = CharacterFunctions::getHexDigitValue (c);
  2353. if (((unsigned int) digit) < (unsigned int) base)
  2354. {
  2355. operator<<= (bits);
  2356. operator+= (digit);
  2357. }
  2358. else if (c == 0)
  2359. {
  2360. break;
  2361. }
  2362. }
  2363. }
  2364. else if (base == 10)
  2365. {
  2366. const BigInteger ten ((unsigned int) 10);
  2367. for (;;)
  2368. {
  2369. const juce_wchar c = *t++;
  2370. if (c >= '0' && c <= '9')
  2371. {
  2372. operator*= (ten);
  2373. operator+= ((int) (c - '0'));
  2374. }
  2375. else if (c == 0)
  2376. {
  2377. break;
  2378. }
  2379. }
  2380. }
  2381. setNegative (text.trimStart().startsWithChar ('-'));
  2382. }
  2383. const MemoryBlock BigInteger::toMemoryBlock() const
  2384. {
  2385. const int numBytes = (getHighestBit() + 8) >> 3;
  2386. MemoryBlock mb ((size_t) numBytes);
  2387. for (int i = 0; i < numBytes; ++i)
  2388. mb[i] = (uint8) getBitRangeAsInt (i << 3, 8);
  2389. return mb;
  2390. }
  2391. void BigInteger::loadFromMemoryBlock (const MemoryBlock& data)
  2392. {
  2393. clear();
  2394. for (int i = (int) data.getSize(); --i >= 0;)
  2395. this->setBitRangeAsInt ((int) (i << 3), 8, data [i]);
  2396. }
  2397. END_JUCE_NAMESPACE
  2398. /*** End of inlined file: juce_BitArray.cpp ***/
  2399. /*** Start of inlined file: juce_MemoryBlock.cpp ***/
  2400. BEGIN_JUCE_NAMESPACE
  2401. MemoryBlock::MemoryBlock() throw()
  2402. : size (0)
  2403. {
  2404. }
  2405. MemoryBlock::MemoryBlock (const size_t initialSize,
  2406. const bool initialiseToZero) throw()
  2407. {
  2408. if (initialSize > 0)
  2409. {
  2410. size = initialSize;
  2411. data.allocate (initialSize, initialiseToZero);
  2412. }
  2413. else
  2414. {
  2415. size = 0;
  2416. }
  2417. }
  2418. MemoryBlock::MemoryBlock (const MemoryBlock& other) throw()
  2419. : size (other.size)
  2420. {
  2421. if (size > 0)
  2422. {
  2423. jassert (other.data != 0);
  2424. data.malloc (size);
  2425. memcpy (data, other.data, size);
  2426. }
  2427. }
  2428. MemoryBlock::MemoryBlock (const void* const dataToInitialiseFrom,
  2429. const size_t sizeInBytes) throw()
  2430. : size (jmax ((size_t) 0, sizeInBytes))
  2431. {
  2432. jassert (sizeInBytes >= 0);
  2433. if (size > 0)
  2434. {
  2435. jassert (dataToInitialiseFrom != 0); // non-zero size, but a zero pointer passed-in?
  2436. data.malloc (size);
  2437. if (dataToInitialiseFrom != 0)
  2438. memcpy (data, dataToInitialiseFrom, size);
  2439. }
  2440. }
  2441. MemoryBlock::~MemoryBlock() throw()
  2442. {
  2443. jassert (size >= 0); // should never happen
  2444. jassert (size == 0 || data != 0); // non-zero size but no data allocated?
  2445. }
  2446. MemoryBlock& MemoryBlock::operator= (const MemoryBlock& other) throw()
  2447. {
  2448. if (this != &other)
  2449. {
  2450. setSize (other.size, false);
  2451. memcpy (data, other.data, size);
  2452. }
  2453. return *this;
  2454. }
  2455. bool MemoryBlock::operator== (const MemoryBlock& other) const throw()
  2456. {
  2457. return matches (other.data, other.size);
  2458. }
  2459. bool MemoryBlock::operator!= (const MemoryBlock& other) const throw()
  2460. {
  2461. return ! operator== (other);
  2462. }
  2463. bool MemoryBlock::matches (const void* dataToCompare, size_t dataSize) const throw()
  2464. {
  2465. return size == dataSize
  2466. && memcmp (data, dataToCompare, size) == 0;
  2467. }
  2468. // this will resize the block to this size
  2469. void MemoryBlock::setSize (const size_t newSize,
  2470. const bool initialiseToZero) throw()
  2471. {
  2472. if (size != newSize)
  2473. {
  2474. if (newSize <= 0)
  2475. {
  2476. data.free();
  2477. size = 0;
  2478. }
  2479. else
  2480. {
  2481. if (data != 0)
  2482. {
  2483. data.realloc (newSize);
  2484. if (initialiseToZero && (newSize > size))
  2485. zeromem (data + size, newSize - size);
  2486. }
  2487. else
  2488. {
  2489. data.allocate (newSize, initialiseToZero);
  2490. }
  2491. size = newSize;
  2492. }
  2493. }
  2494. }
  2495. void MemoryBlock::ensureSize (const size_t minimumSize,
  2496. const bool initialiseToZero) throw()
  2497. {
  2498. if (size < minimumSize)
  2499. setSize (minimumSize, initialiseToZero);
  2500. }
  2501. void MemoryBlock::swapWith (MemoryBlock& other) throw()
  2502. {
  2503. swapVariables (size, other.size);
  2504. data.swapWith (other.data);
  2505. }
  2506. void MemoryBlock::fillWith (const uint8 value) throw()
  2507. {
  2508. memset (data, (int) value, size);
  2509. }
  2510. void MemoryBlock::append (const void* const srcData,
  2511. const size_t numBytes) throw()
  2512. {
  2513. if (numBytes > 0)
  2514. {
  2515. const size_t oldSize = size;
  2516. setSize (size + numBytes);
  2517. memcpy (data + oldSize, srcData, numBytes);
  2518. }
  2519. }
  2520. void MemoryBlock::copyFrom (const void* const src, int offset, size_t num) throw()
  2521. {
  2522. const char* d = static_cast<const char*> (src);
  2523. if (offset < 0)
  2524. {
  2525. d -= offset;
  2526. num -= offset;
  2527. offset = 0;
  2528. }
  2529. if (offset + num > size)
  2530. num = size - offset;
  2531. if (num > 0)
  2532. memcpy (data + offset, d, num);
  2533. }
  2534. void MemoryBlock::copyTo (void* const dst, int offset, size_t num) const throw()
  2535. {
  2536. char* d = static_cast<char*> (dst);
  2537. if (offset < 0)
  2538. {
  2539. zeromem (d, -offset);
  2540. d -= offset;
  2541. num += offset;
  2542. offset = 0;
  2543. }
  2544. if (offset + num > size)
  2545. {
  2546. const size_t newNum = size - offset;
  2547. zeromem (d + newNum, num - newNum);
  2548. num = newNum;
  2549. }
  2550. if (num > 0)
  2551. memcpy (d, data + offset, num);
  2552. }
  2553. void MemoryBlock::removeSection (size_t startByte, size_t numBytesToRemove) throw()
  2554. {
  2555. if (startByte < 0)
  2556. {
  2557. numBytesToRemove += startByte;
  2558. startByte = 0;
  2559. }
  2560. if (startByte + numBytesToRemove >= size)
  2561. {
  2562. setSize (startByte);
  2563. }
  2564. else if (numBytesToRemove > 0)
  2565. {
  2566. memmove (data + startByte,
  2567. data + startByte + numBytesToRemove,
  2568. size - (startByte + numBytesToRemove));
  2569. setSize (size - numBytesToRemove);
  2570. }
  2571. }
  2572. const String MemoryBlock::toString() const throw()
  2573. {
  2574. return String ((const char*) data, size);
  2575. }
  2576. int MemoryBlock::getBitRange (const size_t bitRangeStart, size_t numBits) const throw()
  2577. {
  2578. int res = 0;
  2579. size_t byte = bitRangeStart >> 3;
  2580. int offsetInByte = (int) bitRangeStart & 7;
  2581. size_t bitsSoFar = 0;
  2582. while (numBits > 0 && (size_t) byte < size)
  2583. {
  2584. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2585. const int mask = (0xff >> (8 - bitsThisTime)) << offsetInByte;
  2586. res |= (((data[byte] & mask) >> offsetInByte) << bitsSoFar);
  2587. bitsSoFar += bitsThisTime;
  2588. numBits -= bitsThisTime;
  2589. ++byte;
  2590. offsetInByte = 0;
  2591. }
  2592. return res;
  2593. }
  2594. void MemoryBlock::setBitRange (const size_t bitRangeStart, size_t numBits, int bitsToSet) throw()
  2595. {
  2596. size_t byte = bitRangeStart >> 3;
  2597. int offsetInByte = (int) bitRangeStart & 7;
  2598. unsigned int mask = ~((((unsigned int) 0xffffffff) << (32 - numBits)) >> (32 - numBits));
  2599. while (numBits > 0 && (size_t) byte < size)
  2600. {
  2601. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2602. const unsigned int tempMask = (mask << offsetInByte) | ~((((unsigned int) 0xffffffff) >> offsetInByte) << offsetInByte);
  2603. const unsigned int tempBits = bitsToSet << offsetInByte;
  2604. data[byte] = (char) ((data[byte] & tempMask) | tempBits);
  2605. ++byte;
  2606. numBits -= bitsThisTime;
  2607. bitsToSet >>= bitsThisTime;
  2608. mask >>= bitsThisTime;
  2609. offsetInByte = 0;
  2610. }
  2611. }
  2612. void MemoryBlock::loadFromHexString (const String& hex) throw()
  2613. {
  2614. ensureSize (hex.length() >> 1);
  2615. char* dest = data;
  2616. int i = 0;
  2617. for (;;)
  2618. {
  2619. int byte = 0;
  2620. for (int loop = 2; --loop >= 0;)
  2621. {
  2622. byte <<= 4;
  2623. for (;;)
  2624. {
  2625. const juce_wchar c = hex [i++];
  2626. if (c >= '0' && c <= '9')
  2627. {
  2628. byte |= c - '0';
  2629. break;
  2630. }
  2631. else if (c >= 'a' && c <= 'z')
  2632. {
  2633. byte |= c - ('a' - 10);
  2634. break;
  2635. }
  2636. else if (c >= 'A' && c <= 'Z')
  2637. {
  2638. byte |= c - ('A' - 10);
  2639. break;
  2640. }
  2641. else if (c == 0)
  2642. {
  2643. setSize (static_cast <size_t> (dest - data));
  2644. return;
  2645. }
  2646. }
  2647. }
  2648. *dest++ = (char) byte;
  2649. }
  2650. }
  2651. static const char* const encodingTable
  2652. = ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+";
  2653. const String MemoryBlock::toBase64Encoding() const throw()
  2654. {
  2655. const size_t numChars = ((size << 3) + 5) / 6;
  2656. String destString ((unsigned int) size); // store the length, followed by a '.', and then the data.
  2657. const int initialLen = destString.length();
  2658. destString.preallocateStorage (initialLen + 2 + numChars);
  2659. tchar* d = const_cast <tchar*> (((const tchar*) destString) + initialLen);
  2660. *d++ = '.';
  2661. for (size_t i = 0; i < numChars; ++i)
  2662. *d++ = encodingTable [getBitRange (i * 6, 6)];
  2663. *d++ = 0;
  2664. return destString;
  2665. }
  2666. bool MemoryBlock::fromBase64Encoding (const String& s) throw()
  2667. {
  2668. const int startPos = s.indexOfChar ('.') + 1;
  2669. if (startPos <= 0)
  2670. return false;
  2671. const int numBytesNeeded = s.substring (0, startPos - 1).getIntValue();
  2672. setSize (numBytesNeeded, true);
  2673. const int numChars = s.length() - startPos;
  2674. const tchar* const srcChars = ((const tchar*) s) + startPos;
  2675. int pos = 0;
  2676. for (int i = 0; i < numChars; ++i)
  2677. {
  2678. const char c = (char) srcChars[i];
  2679. for (int j = 0; j < 64; ++j)
  2680. {
  2681. if (encodingTable[j] == c)
  2682. {
  2683. setBitRange (pos, 6, j);
  2684. pos += 6;
  2685. break;
  2686. }
  2687. }
  2688. }
  2689. return true;
  2690. }
  2691. END_JUCE_NAMESPACE
  2692. /*** End of inlined file: juce_MemoryBlock.cpp ***/
  2693. /*** Start of inlined file: juce_PropertySet.cpp ***/
  2694. BEGIN_JUCE_NAMESPACE
  2695. PropertySet::PropertySet (const bool ignoreCaseOfKeyNames) throw()
  2696. : properties (ignoreCaseOfKeyNames),
  2697. fallbackProperties (0),
  2698. ignoreCaseOfKeys (ignoreCaseOfKeyNames)
  2699. {
  2700. }
  2701. PropertySet::PropertySet (const PropertySet& other) throw()
  2702. : properties (other.properties),
  2703. fallbackProperties (other.fallbackProperties),
  2704. ignoreCaseOfKeys (other.ignoreCaseOfKeys)
  2705. {
  2706. }
  2707. PropertySet& PropertySet::operator= (const PropertySet& other) throw()
  2708. {
  2709. properties = other.properties;
  2710. fallbackProperties = other.fallbackProperties;
  2711. ignoreCaseOfKeys = other.ignoreCaseOfKeys;
  2712. propertyChanged();
  2713. return *this;
  2714. }
  2715. PropertySet::~PropertySet()
  2716. {
  2717. }
  2718. void PropertySet::clear()
  2719. {
  2720. const ScopedLock sl (lock);
  2721. if (properties.size() > 0)
  2722. {
  2723. properties.clear();
  2724. propertyChanged();
  2725. }
  2726. }
  2727. const String PropertySet::getValue (const String& keyName,
  2728. const String& defaultValue) const throw()
  2729. {
  2730. const ScopedLock sl (lock);
  2731. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2732. if (index >= 0)
  2733. return properties.getAllValues() [index];
  2734. return fallbackProperties != 0 ? fallbackProperties->getValue (keyName, defaultValue)
  2735. : defaultValue;
  2736. }
  2737. int PropertySet::getIntValue (const String& keyName,
  2738. const int defaultValue) const throw()
  2739. {
  2740. const ScopedLock sl (lock);
  2741. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2742. if (index >= 0)
  2743. return properties.getAllValues() [index].getIntValue();
  2744. return fallbackProperties != 0 ? fallbackProperties->getIntValue (keyName, defaultValue)
  2745. : defaultValue;
  2746. }
  2747. double PropertySet::getDoubleValue (const String& keyName,
  2748. const double defaultValue) const throw()
  2749. {
  2750. const ScopedLock sl (lock);
  2751. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2752. if (index >= 0)
  2753. return properties.getAllValues()[index].getDoubleValue();
  2754. return fallbackProperties != 0 ? fallbackProperties->getDoubleValue (keyName, defaultValue)
  2755. : defaultValue;
  2756. }
  2757. bool PropertySet::getBoolValue (const String& keyName,
  2758. const bool defaultValue) const throw()
  2759. {
  2760. const ScopedLock sl (lock);
  2761. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2762. if (index >= 0)
  2763. return properties.getAllValues() [index].getIntValue() != 0;
  2764. return fallbackProperties != 0 ? fallbackProperties->getBoolValue (keyName, defaultValue)
  2765. : defaultValue;
  2766. }
  2767. XmlElement* PropertySet::getXmlValue (const String& keyName) const
  2768. {
  2769. XmlDocument doc (getValue (keyName));
  2770. return doc.getDocumentElement();
  2771. }
  2772. void PropertySet::setValue (const String& keyName,
  2773. const String& value) throw()
  2774. {
  2775. jassert (keyName.isNotEmpty()); // shouldn't use an empty key name!
  2776. if (keyName.isNotEmpty())
  2777. {
  2778. const ScopedLock sl (lock);
  2779. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2780. if (index < 0 || properties.getAllValues() [index] != value)
  2781. {
  2782. properties.set (keyName, value);
  2783. propertyChanged();
  2784. }
  2785. }
  2786. }
  2787. void PropertySet::removeValue (const String& keyName) throw()
  2788. {
  2789. if (keyName.isNotEmpty())
  2790. {
  2791. const ScopedLock sl (lock);
  2792. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2793. if (index >= 0)
  2794. {
  2795. properties.remove (keyName);
  2796. propertyChanged();
  2797. }
  2798. }
  2799. }
  2800. void PropertySet::setValue (const String& keyName, const tchar* const value) throw()
  2801. {
  2802. setValue (keyName, String (value));
  2803. }
  2804. void PropertySet::setValue (const String& keyName, const int value) throw()
  2805. {
  2806. setValue (keyName, String (value));
  2807. }
  2808. void PropertySet::setValue (const String& keyName, const double value) throw()
  2809. {
  2810. setValue (keyName, String (value));
  2811. }
  2812. void PropertySet::setValue (const String& keyName, const bool value) throw()
  2813. {
  2814. setValue (keyName, String (value ? "1" : "0"));
  2815. }
  2816. void PropertySet::setValue (const String& keyName, const XmlElement* const xml)
  2817. {
  2818. setValue (keyName, (xml == 0) ? String::empty
  2819. : xml->createDocument (String::empty, true));
  2820. }
  2821. bool PropertySet::containsKey (const String& keyName) const throw()
  2822. {
  2823. const ScopedLock sl (lock);
  2824. return properties.getAllKeys().contains (keyName, ignoreCaseOfKeys);
  2825. }
  2826. void PropertySet::setFallbackPropertySet (PropertySet* fallbackProperties_) throw()
  2827. {
  2828. const ScopedLock sl (lock);
  2829. fallbackProperties = fallbackProperties_;
  2830. }
  2831. XmlElement* PropertySet::createXml (const String& nodeName) const throw()
  2832. {
  2833. const ScopedLock sl (lock);
  2834. XmlElement* const xml = new XmlElement (nodeName);
  2835. for (int i = 0; i < properties.getAllKeys().size(); ++i)
  2836. {
  2837. XmlElement* const e = xml->createNewChildElement ("VALUE");
  2838. e->setAttribute ("name", properties.getAllKeys()[i]);
  2839. e->setAttribute ("val", properties.getAllValues()[i]);
  2840. }
  2841. return xml;
  2842. }
  2843. void PropertySet::restoreFromXml (const XmlElement& xml) throw()
  2844. {
  2845. const ScopedLock sl (lock);
  2846. clear();
  2847. forEachXmlChildElementWithTagName (xml, e, "VALUE")
  2848. {
  2849. if (e->hasAttribute ("name")
  2850. && e->hasAttribute ("val"))
  2851. {
  2852. properties.set (e->getStringAttribute ("name"),
  2853. e->getStringAttribute ("val"));
  2854. }
  2855. }
  2856. if (properties.size() > 0)
  2857. propertyChanged();
  2858. }
  2859. void PropertySet::propertyChanged()
  2860. {
  2861. }
  2862. END_JUCE_NAMESPACE
  2863. /*** End of inlined file: juce_PropertySet.cpp ***/
  2864. /*** Start of inlined file: juce_Variant.cpp ***/
  2865. BEGIN_JUCE_NAMESPACE
  2866. var::var() throw()
  2867. : type (voidType)
  2868. {
  2869. value.doubleValue = 0;
  2870. }
  2871. var::~var() throw()
  2872. {
  2873. if (type == stringType)
  2874. delete value.stringValue;
  2875. else if (type == objectType && value.objectValue != 0)
  2876. value.objectValue->decReferenceCount();
  2877. }
  2878. const var var::null;
  2879. var::var (const var& valueToCopy)
  2880. : type (valueToCopy.type),
  2881. value (valueToCopy.value)
  2882. {
  2883. if (type == stringType)
  2884. value.stringValue = new String (*(value.stringValue));
  2885. else if (type == objectType && value.objectValue != 0)
  2886. value.objectValue->incReferenceCount();
  2887. }
  2888. var::var (const int value_) throw()
  2889. : type (intType)
  2890. {
  2891. value.intValue = value_;
  2892. }
  2893. var::var (const bool value_) throw()
  2894. : type (boolType)
  2895. {
  2896. value.boolValue = value_;
  2897. }
  2898. var::var (const double value_) throw()
  2899. : type (doubleType)
  2900. {
  2901. value.doubleValue = value_;
  2902. }
  2903. var::var (const String& value_)
  2904. : type (stringType)
  2905. {
  2906. value.stringValue = new String (value_);
  2907. }
  2908. var::var (const char* const value_)
  2909. : type (stringType)
  2910. {
  2911. value.stringValue = new String (value_);
  2912. }
  2913. var::var (const juce_wchar* const value_)
  2914. : type (stringType)
  2915. {
  2916. value.stringValue = new String (value_);
  2917. }
  2918. var::var (DynamicObject* const object)
  2919. : type (objectType)
  2920. {
  2921. value.objectValue = object;
  2922. if (object != 0)
  2923. object->incReferenceCount();
  2924. }
  2925. var::var (MethodFunction method_) throw()
  2926. : type (methodType)
  2927. {
  2928. value.methodValue = method_;
  2929. }
  2930. void var::swapWith (var& other) throw()
  2931. {
  2932. swapVariables (type, other.type);
  2933. swapVariables (value, other.value);
  2934. }
  2935. var& var::operator= (const var& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2936. var& var::operator= (int value_) { var newValue (value_); swapWith (newValue); return *this; }
  2937. var& var::operator= (bool value_) { var newValue (value_); swapWith (newValue); return *this; }
  2938. var& var::operator= (double value_) { var newValue (value_); swapWith (newValue); return *this; }
  2939. var& var::operator= (const char* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2940. var& var::operator= (const juce_wchar* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2941. var& var::operator= (const String& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2942. var& var::operator= (DynamicObject* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2943. var& var::operator= (MethodFunction value_) { var newValue (value_); swapWith (newValue); return *this; }
  2944. var::operator int() const
  2945. {
  2946. switch (type)
  2947. {
  2948. case voidType: break;
  2949. case intType: return value.intValue;
  2950. case boolType: return value.boolValue ? 1 : 0;
  2951. case doubleType: return static_cast <int> (value.doubleValue);
  2952. case stringType: return value.stringValue->getIntValue();
  2953. case objectType: break;
  2954. default: jassertfalse; break;
  2955. }
  2956. return 0;
  2957. }
  2958. var::operator bool() const
  2959. {
  2960. switch (type)
  2961. {
  2962. case voidType: break;
  2963. case intType: return value.intValue != 0;
  2964. case boolType: return value.boolValue;
  2965. case doubleType: return value.doubleValue != 0;
  2966. case stringType: return value.stringValue->getIntValue() != 0
  2967. || value.stringValue->trim().equalsIgnoreCase (T("true"))
  2968. || value.stringValue->trim().equalsIgnoreCase (T("yes"));
  2969. case objectType: return value.objectValue != 0;
  2970. default: jassertfalse; break;
  2971. }
  2972. return false;
  2973. }
  2974. var::operator float() const
  2975. {
  2976. return (float) operator double();
  2977. }
  2978. var::operator double() const
  2979. {
  2980. switch (type)
  2981. {
  2982. case voidType: break;
  2983. case intType: return value.intValue;
  2984. case boolType: return value.boolValue ? 1.0 : 0.0;
  2985. case doubleType: return value.doubleValue;
  2986. case stringType: return value.stringValue->getDoubleValue();
  2987. case objectType: break;
  2988. default: jassertfalse; break;
  2989. }
  2990. return 0.0;
  2991. }
  2992. const String var::toString() const
  2993. {
  2994. switch (type)
  2995. {
  2996. case voidType: return String::empty;
  2997. case intType: return String (value.intValue);
  2998. case boolType: return String::charToString (value.boolValue ? '1' : '0');
  2999. case doubleType: return String (value.doubleValue);
  3000. case stringType: return *(value.stringValue);
  3001. case objectType: return "Object 0x" + String::toHexString ((int) (pointer_sized_int) value.objectValue);
  3002. case methodType: return "Method";
  3003. default: jassertfalse; break;
  3004. }
  3005. return String::empty;
  3006. }
  3007. var::operator const String() const
  3008. {
  3009. return toString();
  3010. }
  3011. DynamicObject* var::getObject() const
  3012. {
  3013. return type == objectType ? value.objectValue : 0;
  3014. }
  3015. bool var::equals (const var& other) const throw()
  3016. {
  3017. switch (type)
  3018. {
  3019. case voidType: return other.isVoid();
  3020. case intType: return value.intValue == static_cast <int> (other);
  3021. case boolType: return value.boolValue == static_cast <bool> (other);
  3022. case doubleType: return value.doubleValue == static_cast <double> (other);
  3023. case stringType: return (*(value.stringValue)) == other.toString();
  3024. case objectType: return value.objectValue == other.getObject();
  3025. case methodType: return value.methodValue == other.value.methodValue && other.isMethod();
  3026. default: jassertfalse; break;
  3027. }
  3028. return false;
  3029. }
  3030. bool operator== (const var& v1, const var& v2) throw() { return v1.equals (v2); }
  3031. bool operator!= (const var& v1, const var& v2) throw() { return ! v1.equals (v2); }
  3032. bool operator== (const var& v1, const String& v2) throw() { return v1.toString() == v2; }
  3033. bool operator!= (const var& v1, const String& v2) throw() { return v1.toString() != v2; }
  3034. void var::writeToStream (OutputStream& output) const
  3035. {
  3036. switch (type)
  3037. {
  3038. case voidType: output.writeCompressedInt (0); break;
  3039. case intType: output.writeCompressedInt (5); output.writeByte (1); output.writeInt (value.intValue); break;
  3040. case boolType: output.writeCompressedInt (1); output.writeByte (value.boolValue ? 2 : 3); break;
  3041. case doubleType: output.writeCompressedInt (9); output.writeByte (4); output.writeDouble (value.doubleValue); break;
  3042. case stringType:
  3043. {
  3044. const int len = value.stringValue->getNumBytesAsUTF8() + 1;
  3045. output.writeCompressedInt (len + 1);
  3046. output.writeByte (5);
  3047. HeapBlock<char> temp (len);
  3048. value.stringValue->copyToUTF8 (temp, len);
  3049. output.write (temp, len);
  3050. break;
  3051. }
  3052. case objectType:
  3053. case methodType: output.writeCompressedInt (0); jassertfalse; break; // Can't write an object to a stream!
  3054. default: jassertfalse; break; // Is this a corrupted object?
  3055. }
  3056. }
  3057. const var var::readFromStream (InputStream& input)
  3058. {
  3059. const int numBytes = input.readCompressedInt();
  3060. if (numBytes > 0)
  3061. {
  3062. switch (input.readByte())
  3063. {
  3064. case 1: return var (input.readInt());
  3065. case 2: return var (true);
  3066. case 3: return var (false);
  3067. case 4: return var (input.readDouble());
  3068. case 5:
  3069. {
  3070. MemoryBlock mb;
  3071. input.readIntoMemoryBlock (mb, numBytes - 1);
  3072. return var (String::fromUTF8 ((const char*) mb.getData(), (int) mb.getSize()));
  3073. }
  3074. default: input.skipNextBytes (numBytes - 1); break;
  3075. }
  3076. }
  3077. return var::null;
  3078. }
  3079. const var var::operator[] (const var::identifier& propertyName) const
  3080. {
  3081. if (type == objectType && value.objectValue != 0)
  3082. return value.objectValue->getProperty (propertyName);
  3083. return var::null;
  3084. }
  3085. const var var::invoke (const var::identifier& method, const var* arguments, int numArguments) const
  3086. {
  3087. if (type == objectType && value.objectValue != 0)
  3088. return value.objectValue->invokeMethod (method, arguments, numArguments);
  3089. return var::null;
  3090. }
  3091. const var var::invoke (const var& targetObject, const var* arguments, int numArguments) const
  3092. {
  3093. if (isMethod())
  3094. {
  3095. DynamicObject* const target = targetObject.getObject();
  3096. if (target != 0)
  3097. return (target->*(value.methodValue)) (arguments, numArguments);
  3098. }
  3099. return var::null;
  3100. }
  3101. const var var::call (const var::identifier& method) const
  3102. {
  3103. return invoke (method, 0, 0);
  3104. }
  3105. const var var::call (const var::identifier& method, const var& arg1) const
  3106. {
  3107. return invoke (method, &arg1, 1);
  3108. }
  3109. const var var::call (const var::identifier& method, const var& arg1, const var& arg2) const
  3110. {
  3111. var args[] = { arg1, arg2 };
  3112. return invoke (method, args, 2);
  3113. }
  3114. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3)
  3115. {
  3116. var args[] = { arg1, arg2, arg3 };
  3117. return invoke (method, args, 3);
  3118. }
  3119. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4) const
  3120. {
  3121. var args[] = { arg1, arg2, arg3, arg4 };
  3122. return invoke (method, args, 4);
  3123. }
  3124. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4, const var& arg5) const
  3125. {
  3126. var args[] = { arg1, arg2, arg3, arg4, arg5 };
  3127. return invoke (method, args, 5);
  3128. }
  3129. var::identifier::identifier() throw()
  3130. : hashCode (0)
  3131. {
  3132. }
  3133. var::identifier::identifier (const String& name_)
  3134. : name (name_),
  3135. hashCode (name_.hashCode())
  3136. {
  3137. /* An identifier string must be suitable for use as a script variable or XML
  3138. attribute, so it can only contain this limited set of characters.. */
  3139. jassert (name.containsOnly (T("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_")) && name.isNotEmpty());
  3140. }
  3141. var::identifier::identifier (const char* const name_)
  3142. : name (name_),
  3143. hashCode (name.hashCode())
  3144. {
  3145. /* An identifier string must be suitable for use as a script variable or XML
  3146. attribute, so it can only contain this limited set of characters.. */
  3147. jassert (name.containsOnly (T("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_")) && name.isNotEmpty());
  3148. }
  3149. var::identifier::~identifier()
  3150. {
  3151. }
  3152. END_JUCE_NAMESPACE
  3153. /*** End of inlined file: juce_Variant.cpp ***/
  3154. /*** Start of inlined file: juce_NamedValueSet.cpp ***/
  3155. BEGIN_JUCE_NAMESPACE
  3156. NamedValueSet::NamedValue::NamedValue() throw()
  3157. {
  3158. }
  3159. inline NamedValueSet::NamedValue::NamedValue (const var::identifier& name_, const var& value_)
  3160. : name (name_), value (value_)
  3161. {
  3162. }
  3163. NamedValueSet::NamedValueSet() throw()
  3164. {
  3165. }
  3166. NamedValueSet::NamedValueSet (const NamedValueSet& other)
  3167. : values (other.values)
  3168. {
  3169. }
  3170. NamedValueSet& NamedValueSet::operator= (const NamedValueSet& other)
  3171. {
  3172. values = other.values;
  3173. return *this;
  3174. }
  3175. NamedValueSet::~NamedValueSet()
  3176. {
  3177. }
  3178. int NamedValueSet::size() const throw()
  3179. {
  3180. return values.size();
  3181. }
  3182. const var& NamedValueSet::operator[] (const var::identifier& name) const
  3183. {
  3184. for (int i = values.size(); --i >= 0;)
  3185. {
  3186. const NamedValue& v = values.getReference(i);
  3187. if (v.name == name)
  3188. return v.value;
  3189. }
  3190. return var::null;
  3191. }
  3192. const var NamedValueSet::getWithDefault (const var::identifier& name, const var& defaultReturnValue) const
  3193. {
  3194. const var* v = getItem (name);
  3195. return v != 0 ? *v : defaultReturnValue;
  3196. }
  3197. var* NamedValueSet::getItem (const var::identifier& name) const
  3198. {
  3199. for (int i = values.size(); --i >= 0;)
  3200. {
  3201. NamedValue& v = values.getReference(i);
  3202. if (v.name == name)
  3203. return &(v.value);
  3204. }
  3205. return 0;
  3206. }
  3207. bool NamedValueSet::set (const var::identifier& name, const var& newValue)
  3208. {
  3209. for (int i = values.size(); --i >= 0;)
  3210. {
  3211. NamedValue& v = values.getReference(i);
  3212. if (v.name == name)
  3213. {
  3214. if (v.value == newValue)
  3215. return false;
  3216. v.value = newValue;
  3217. return true;
  3218. }
  3219. }
  3220. values.add (NamedValue (name, newValue));
  3221. return true;
  3222. }
  3223. bool NamedValueSet::contains (const var::identifier& name) const
  3224. {
  3225. return getItem (name) != 0;
  3226. }
  3227. bool NamedValueSet::remove (const var::identifier& name)
  3228. {
  3229. for (int i = values.size(); --i >= 0;)
  3230. {
  3231. if (values.getReference(i).name == name)
  3232. {
  3233. values.remove (i);
  3234. return true;
  3235. }
  3236. }
  3237. return false;
  3238. }
  3239. const var::identifier NamedValueSet::getName (int index) const
  3240. {
  3241. jassert (((unsigned int) index) < (unsigned int) values.size());
  3242. return values [index].name;
  3243. }
  3244. void NamedValueSet::clear()
  3245. {
  3246. values.clear();
  3247. }
  3248. END_JUCE_NAMESPACE
  3249. /*** End of inlined file: juce_NamedValueSet.cpp ***/
  3250. /*** Start of inlined file: juce_DynamicObject.cpp ***/
  3251. BEGIN_JUCE_NAMESPACE
  3252. DynamicObject::DynamicObject()
  3253. {
  3254. }
  3255. DynamicObject::~DynamicObject()
  3256. {
  3257. }
  3258. bool DynamicObject::hasProperty (const var::identifier& propertyName) const
  3259. {
  3260. var* const v = properties.getItem (propertyName);
  3261. return v != 0 && ! v->isMethod();
  3262. }
  3263. const var DynamicObject::getProperty (const var::identifier& propertyName) const
  3264. {
  3265. return properties [propertyName];
  3266. }
  3267. void DynamicObject::setProperty (const var::identifier& propertyName, const var& newValue)
  3268. {
  3269. properties.set (propertyName, newValue);
  3270. }
  3271. void DynamicObject::removeProperty (const var::identifier& propertyName)
  3272. {
  3273. properties.remove (propertyName);
  3274. }
  3275. bool DynamicObject::hasMethod (const var::identifier& methodName) const
  3276. {
  3277. return getProperty (methodName).isMethod();
  3278. }
  3279. const var DynamicObject::invokeMethod (const var::identifier& methodName,
  3280. const var* parameters,
  3281. int numParameters)
  3282. {
  3283. return properties [methodName].invoke (var (this), parameters, numParameters);
  3284. }
  3285. void DynamicObject::setMethod (const var::identifier& name,
  3286. var::MethodFunction methodFunction)
  3287. {
  3288. properties.set (name, var (methodFunction));
  3289. }
  3290. void DynamicObject::clear()
  3291. {
  3292. properties.clear();
  3293. }
  3294. END_JUCE_NAMESPACE
  3295. /*** End of inlined file: juce_DynamicObject.cpp ***/
  3296. /*** Start of inlined file: juce_BlowFish.cpp ***/
  3297. BEGIN_JUCE_NAMESPACE
  3298. BlowFish::BlowFish (const void* const keyData, const int keyBytes)
  3299. {
  3300. jassert (keyData != 0);
  3301. jassert (keyBytes > 0);
  3302. static const uint32 initialPValues [18] =
  3303. {
  3304. 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
  3305. 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
  3306. 0x9216d5d9, 0x8979fb1b
  3307. };
  3308. static const uint32 initialSValues [4 * 256] =
  3309. {
  3310. 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
  3311. 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
  3312. 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
  3313. 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
  3314. 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
  3315. 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
  3316. 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
  3317. 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
  3318. 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
  3319. 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
  3320. 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
  3321. 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
  3322. 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
  3323. 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
  3324. 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
  3325. 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
  3326. 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
  3327. 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
  3328. 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
  3329. 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
  3330. 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
  3331. 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
  3332. 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
  3333. 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
  3334. 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
  3335. 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
  3336. 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
  3337. 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
  3338. 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
  3339. 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
  3340. 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
  3341. 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a,
  3342. 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
  3343. 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
  3344. 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
  3345. 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
  3346. 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
  3347. 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
  3348. 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
  3349. 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
  3350. 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
  3351. 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
  3352. 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
  3353. 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
  3354. 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
  3355. 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
  3356. 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
  3357. 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
  3358. 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
  3359. 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
  3360. 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
  3361. 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
  3362. 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
  3363. 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
  3364. 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
  3365. 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
  3366. 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
  3367. 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
  3368. 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
  3369. 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
  3370. 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
  3371. 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
  3372. 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
  3373. 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7,
  3374. 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
  3375. 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
  3376. 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
  3377. 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
  3378. 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
  3379. 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
  3380. 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
  3381. 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
  3382. 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
  3383. 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
  3384. 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
  3385. 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
  3386. 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
  3387. 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
  3388. 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
  3389. 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
  3390. 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
  3391. 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
  3392. 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
  3393. 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
  3394. 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
  3395. 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
  3396. 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
  3397. 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
  3398. 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
  3399. 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
  3400. 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
  3401. 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
  3402. 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
  3403. 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
  3404. 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
  3405. 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0,
  3406. 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
  3407. 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
  3408. 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
  3409. 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
  3410. 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
  3411. 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
  3412. 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
  3413. 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
  3414. 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
  3415. 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
  3416. 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
  3417. 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
  3418. 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
  3419. 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
  3420. 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
  3421. 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
  3422. 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
  3423. 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
  3424. 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
  3425. 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
  3426. 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
  3427. 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
  3428. 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
  3429. 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
  3430. 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
  3431. 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
  3432. 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
  3433. 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
  3434. 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
  3435. 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
  3436. 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
  3437. 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
  3438. };
  3439. memcpy (p, initialPValues, sizeof (p));
  3440. int i, j = 0;
  3441. for (i = 4; --i >= 0;)
  3442. {
  3443. s[i].malloc (256);
  3444. memcpy (s[i], initialSValues + i * 256, 256 * sizeof (uint32));
  3445. }
  3446. for (i = 0; i < 18; ++i)
  3447. {
  3448. uint32 d = 0;
  3449. for (int k = 0; k < 4; ++k)
  3450. {
  3451. d = (d << 8) | static_cast <const uint8*> (keyData)[j];
  3452. if (++j >= keyBytes)
  3453. j = 0;
  3454. }
  3455. p[i] = initialPValues[i] ^ d;
  3456. }
  3457. uint32 l = 0, r = 0;
  3458. for (i = 0; i < 18; i += 2)
  3459. {
  3460. encrypt (l, r);
  3461. p[i] = l;
  3462. p[i + 1] = r;
  3463. }
  3464. for (i = 0; i < 4; ++i)
  3465. {
  3466. for (j = 0; j < 256; j += 2)
  3467. {
  3468. encrypt (l, r);
  3469. s[i][j] = l;
  3470. s[i][j + 1] = r;
  3471. }
  3472. }
  3473. }
  3474. BlowFish::BlowFish (const BlowFish& other)
  3475. {
  3476. for (int i = 4; --i >= 0;)
  3477. s[i].malloc (256);
  3478. operator= (other);
  3479. }
  3480. BlowFish& BlowFish::operator= (const BlowFish& other)
  3481. {
  3482. memcpy (p, other.p, sizeof (p));
  3483. for (int i = 4; --i >= 0;)
  3484. memcpy (s[i], other.s[i], 256 * sizeof (uint32));
  3485. return *this;
  3486. }
  3487. BlowFish::~BlowFish()
  3488. {
  3489. }
  3490. uint32 BlowFish::F (const uint32 x) const throw()
  3491. {
  3492. return ((s[0][(x >> 24) & 0xff] + s[1][(x >> 16) & 0xff])
  3493. ^ s[2][(x >> 8) & 0xff]) + s[3][x & 0xff];
  3494. }
  3495. void BlowFish::encrypt (uint32& data1, uint32& data2) const throw()
  3496. {
  3497. uint32 l = data1;
  3498. uint32 r = data2;
  3499. for (int i = 0; i < 16; ++i)
  3500. {
  3501. l ^= p[i];
  3502. r ^= F(l);
  3503. swapVariables (l, r);
  3504. }
  3505. data1 = r ^ p[17];
  3506. data2 = l ^ p[16];
  3507. }
  3508. void BlowFish::decrypt (uint32& data1, uint32& data2) const throw()
  3509. {
  3510. uint32 l = data1;
  3511. uint32 r = data2;
  3512. for (int i = 17; i > 1; --i)
  3513. {
  3514. l ^= p[i];
  3515. r ^= F(l);
  3516. swapVariables (l, r);
  3517. }
  3518. data1 = r ^ p[0];
  3519. data2 = l ^ p[1];
  3520. }
  3521. END_JUCE_NAMESPACE
  3522. /*** End of inlined file: juce_BlowFish.cpp ***/
  3523. /*** Start of inlined file: juce_MD5.cpp ***/
  3524. BEGIN_JUCE_NAMESPACE
  3525. MD5::MD5()
  3526. {
  3527. zerostruct (result);
  3528. }
  3529. MD5::MD5 (const MD5& other)
  3530. {
  3531. memcpy (result, other.result, sizeof (result));
  3532. }
  3533. MD5& MD5::operator= (const MD5& other)
  3534. {
  3535. memcpy (result, other.result, sizeof (result));
  3536. return *this;
  3537. }
  3538. MD5::MD5 (const MemoryBlock& data)
  3539. {
  3540. ProcessContext context;
  3541. context.processBlock ((const uint8*) data.getData(), data.getSize());
  3542. context.finish (result);
  3543. }
  3544. MD5::MD5 (const char* data, const size_t numBytes)
  3545. {
  3546. ProcessContext context;
  3547. context.processBlock ((const uint8*) data, numBytes);
  3548. context.finish (result);
  3549. }
  3550. MD5::MD5 (const String& text)
  3551. {
  3552. ProcessContext context;
  3553. const int len = text.length();
  3554. const juce_wchar* const t = text;
  3555. for (int i = 0; i < len; ++i)
  3556. {
  3557. // force the string into integer-sized unicode characters, to try to make it
  3558. // get the same results on all platforms + compilers.
  3559. uint32 unicodeChar = (uint32) t[i];
  3560. ByteOrder::swapIfBigEndian (unicodeChar);
  3561. context.processBlock ((const uint8*) &unicodeChar,
  3562. sizeof (unicodeChar));
  3563. }
  3564. context.finish (result);
  3565. }
  3566. void MD5::processStream (InputStream& input, int64 numBytesToRead)
  3567. {
  3568. ProcessContext context;
  3569. if (numBytesToRead < 0)
  3570. numBytesToRead = std::numeric_limits<int64>::max();
  3571. while (numBytesToRead > 0)
  3572. {
  3573. char tempBuffer [512];
  3574. const int bytesRead = input.read (tempBuffer, (int) jmin (numBytesToRead, (int64) sizeof (tempBuffer)));
  3575. if (bytesRead <= 0)
  3576. break;
  3577. numBytesToRead -= bytesRead;
  3578. context.processBlock ((const uint8*) tempBuffer, bytesRead);
  3579. }
  3580. context.finish (result);
  3581. }
  3582. MD5::MD5 (InputStream& input, int64 numBytesToRead)
  3583. {
  3584. processStream (input, numBytesToRead);
  3585. }
  3586. MD5::MD5 (const File& file)
  3587. {
  3588. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  3589. if (fin != 0)
  3590. processStream (*fin, -1);
  3591. else
  3592. zerostruct (result);
  3593. }
  3594. MD5::~MD5()
  3595. {
  3596. }
  3597. namespace MD5Functions
  3598. {
  3599. static void encode (uint8* const output, const uint32* const input, const int numBytes) throw()
  3600. {
  3601. uint32* const o = (uint32*) output;
  3602. for (int i = 0; i < (numBytes >> 2); ++i)
  3603. o[i] = ByteOrder::swapIfBigEndian (input [i]);
  3604. }
  3605. static void decode (uint32* const output, const uint8* const input, const int numBytes) throw()
  3606. {
  3607. for (int i = 0; i < (numBytes >> 2); ++i)
  3608. output[i] = ByteOrder::littleEndianInt ((const char*) input + (i << 2));
  3609. }
  3610. static inline uint32 F (const uint32 x, const uint32 y, const uint32 z) throw() { return (x & y) | (~x & z); }
  3611. static inline uint32 G (const uint32 x, const uint32 y, const uint32 z) throw() { return (x & z) | (y & ~z); }
  3612. static inline uint32 H (const uint32 x, const uint32 y, const uint32 z) throw() { return x ^ y ^ z; }
  3613. static inline uint32 I (const uint32 x, const uint32 y, const uint32 z) throw() { return y ^ (x | ~z); }
  3614. static inline uint32 rotateLeft (const uint32 x, const uint32 n) throw() { return (x << n) | (x >> (32 - n)); }
  3615. static void FF (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3616. {
  3617. a += F (b, c, d) + x + ac;
  3618. a = rotateLeft (a, s) + b;
  3619. }
  3620. static void GG (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3621. {
  3622. a += G (b, c, d) + x + ac;
  3623. a = rotateLeft (a, s) + b;
  3624. }
  3625. static void HH (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3626. {
  3627. a += H (b, c, d) + x + ac;
  3628. a = rotateLeft (a, s) + b;
  3629. }
  3630. static void II (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3631. {
  3632. a += I (b, c, d) + x + ac;
  3633. a = rotateLeft (a, s) + b;
  3634. }
  3635. }
  3636. MD5::ProcessContext::ProcessContext()
  3637. {
  3638. state[0] = 0x67452301;
  3639. state[1] = 0xefcdab89;
  3640. state[2] = 0x98badcfe;
  3641. state[3] = 0x10325476;
  3642. count[0] = 0;
  3643. count[1] = 0;
  3644. }
  3645. void MD5::ProcessContext::processBlock (const uint8* const data, size_t dataSize)
  3646. {
  3647. int bufferPos = ((count[0] >> 3) & 0x3F);
  3648. count[0] += (uint32) (dataSize << 3);
  3649. if (count[0] < ((uint32) dataSize << 3))
  3650. count[1]++;
  3651. count[1] += (uint32) (dataSize >> 29);
  3652. const size_t spaceLeft = 64 - bufferPos;
  3653. size_t i = 0;
  3654. if (dataSize >= spaceLeft)
  3655. {
  3656. memcpy (buffer + bufferPos, data, spaceLeft);
  3657. transform (buffer);
  3658. i = spaceLeft;
  3659. while (i + 64 <= dataSize)
  3660. {
  3661. transform (data + i);
  3662. i += 64;
  3663. }
  3664. bufferPos = 0;
  3665. }
  3666. memcpy (buffer + bufferPos, data + i, dataSize - i);
  3667. }
  3668. void MD5::ProcessContext::finish (uint8* const result)
  3669. {
  3670. unsigned char encodedLength[8];
  3671. MD5Functions::encode (encodedLength, count, 8);
  3672. // Pad out to 56 mod 64.
  3673. const int index = (uint32) ((count[0] >> 3) & 0x3f);
  3674. const int paddingLength = (index < 56) ? (56 - index)
  3675. : (120 - index);
  3676. uint8 paddingBuffer [64];
  3677. zeromem (paddingBuffer, paddingLength);
  3678. paddingBuffer [0] = 0x80;
  3679. processBlock (paddingBuffer, paddingLength);
  3680. processBlock (encodedLength, 8);
  3681. MD5Functions::encode (result, state, 16);
  3682. zerostruct (buffer);
  3683. }
  3684. void MD5::ProcessContext::transform (const uint8* const bufferToTransform)
  3685. {
  3686. using namespace MD5Functions;
  3687. uint32 a = state[0];
  3688. uint32 b = state[1];
  3689. uint32 c = state[2];
  3690. uint32 d = state[3];
  3691. uint32 x[16];
  3692. decode (x, bufferToTransform, 64);
  3693. enum Constants
  3694. {
  3695. S11 = 7, S12 = 12, S13 = 17, S14 = 22, S21 = 5, S22 = 9, S23 = 14, S24 = 20,
  3696. S31 = 4, S32 = 11, S33 = 16, S34 = 23, S41 = 6, S42 = 10, S43 = 15, S44 = 21
  3697. };
  3698. FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
  3699. FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
  3700. FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
  3701. FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
  3702. FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
  3703. FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
  3704. FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
  3705. FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
  3706. FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
  3707. FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
  3708. FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
  3709. FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
  3710. FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
  3711. FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
  3712. FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
  3713. FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
  3714. GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
  3715. GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
  3716. GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
  3717. GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
  3718. GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
  3719. GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
  3720. GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
  3721. GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
  3722. GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
  3723. GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
  3724. GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
  3725. GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
  3726. GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
  3727. GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
  3728. GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
  3729. GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
  3730. HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
  3731. HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
  3732. HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
  3733. HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
  3734. HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
  3735. HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
  3736. HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
  3737. HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
  3738. HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
  3739. HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
  3740. HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
  3741. HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
  3742. HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
  3743. HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
  3744. HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
  3745. HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
  3746. II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
  3747. II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
  3748. II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
  3749. II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
  3750. II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
  3751. II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
  3752. II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
  3753. II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
  3754. II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
  3755. II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
  3756. II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
  3757. II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
  3758. II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
  3759. II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
  3760. II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
  3761. II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
  3762. state[0] += a;
  3763. state[1] += b;
  3764. state[2] += c;
  3765. state[3] += d;
  3766. zerostruct (x);
  3767. }
  3768. const MemoryBlock MD5::getRawChecksumData() const
  3769. {
  3770. return MemoryBlock (result, sizeof (result));
  3771. }
  3772. const String MD5::toHexString() const
  3773. {
  3774. return String::toHexString (result, sizeof (result), 0);
  3775. }
  3776. bool MD5::operator== (const MD5& other) const
  3777. {
  3778. return memcmp (result, other.result, sizeof (result)) == 0;
  3779. }
  3780. bool MD5::operator!= (const MD5& other) const
  3781. {
  3782. return ! operator== (other);
  3783. }
  3784. END_JUCE_NAMESPACE
  3785. /*** End of inlined file: juce_MD5.cpp ***/
  3786. /*** Start of inlined file: juce_Primes.cpp ***/
  3787. BEGIN_JUCE_NAMESPACE
  3788. namespace PrimesHelpers
  3789. {
  3790. static void createSmallSieve (const int numBits, BigInteger& result)
  3791. {
  3792. result.setBit (numBits);
  3793. result.clearBit (numBits); // to enlarge the array
  3794. result.setBit (0);
  3795. int n = 2;
  3796. do
  3797. {
  3798. for (int i = n + n; i < numBits; i += n)
  3799. result.setBit (i);
  3800. n = result.findNextClearBit (n + 1);
  3801. }
  3802. while (n <= (numBits >> 1));
  3803. }
  3804. static void bigSieve (const BigInteger& base, const int numBits, BigInteger& result,
  3805. const BigInteger& smallSieve, const int smallSieveSize)
  3806. {
  3807. jassert (! base[0]); // must be even!
  3808. result.setBit (numBits);
  3809. result.clearBit (numBits); // to enlarge the array
  3810. int index = smallSieve.findNextClearBit (0);
  3811. do
  3812. {
  3813. const int prime = (index << 1) + 1;
  3814. BigInteger r (base), remainder;
  3815. r.divideBy (prime, remainder);
  3816. int i = prime - remainder.getBitRangeAsInt (0, 32);
  3817. if (r.isZero())
  3818. i += prime;
  3819. if ((i & 1) == 0)
  3820. i += prime;
  3821. i = (i - 1) >> 1;
  3822. while (i < numBits)
  3823. {
  3824. result.setBit (i);
  3825. i += prime;
  3826. }
  3827. index = smallSieve.findNextClearBit (index + 1);
  3828. }
  3829. while (index < smallSieveSize);
  3830. }
  3831. static bool findCandidate (const BigInteger& base, const BigInteger& sieve,
  3832. const int numBits, BigInteger& result, const int certainty)
  3833. {
  3834. for (int i = 0; i < numBits; ++i)
  3835. {
  3836. if (! sieve[i])
  3837. {
  3838. result = base + (unsigned int) ((i << 1) + 1);
  3839. if (Primes::isProbablyPrime (result, certainty))
  3840. return true;
  3841. }
  3842. }
  3843. return false;
  3844. }
  3845. static bool passesMillerRabin (const BigInteger& n, int iterations)
  3846. {
  3847. const BigInteger one (1), two (2);
  3848. const BigInteger nMinusOne (n - one);
  3849. BigInteger d (nMinusOne);
  3850. const int s = d.findNextSetBit (0);
  3851. d >>= s;
  3852. BigInteger smallPrimes;
  3853. int numBitsInSmallPrimes = 0;
  3854. for (;;)
  3855. {
  3856. numBitsInSmallPrimes += 256;
  3857. createSmallSieve (numBitsInSmallPrimes, smallPrimes);
  3858. const int numPrimesFound = numBitsInSmallPrimes - smallPrimes.countNumberOfSetBits();
  3859. if (numPrimesFound > iterations + 1)
  3860. break;
  3861. }
  3862. int smallPrime = 2;
  3863. while (--iterations >= 0)
  3864. {
  3865. smallPrime = smallPrimes.findNextClearBit (smallPrime + 1);
  3866. BigInteger r (smallPrime);
  3867. r.exponentModulo (d, n);
  3868. if (r != one && r != nMinusOne)
  3869. {
  3870. for (int j = 0; j < s; ++j)
  3871. {
  3872. r.exponentModulo (two, n);
  3873. if (r == nMinusOne)
  3874. break;
  3875. }
  3876. if (r != nMinusOne)
  3877. return false;
  3878. }
  3879. }
  3880. return true;
  3881. }
  3882. }
  3883. const BigInteger Primes::createProbablePrime (const int bitLength,
  3884. const int certainty,
  3885. const int* randomSeeds,
  3886. int numRandomSeeds)
  3887. {
  3888. using namespace PrimesHelpers;
  3889. int defaultSeeds [16];
  3890. if (numRandomSeeds <= 0)
  3891. {
  3892. randomSeeds = defaultSeeds;
  3893. numRandomSeeds = numElementsInArray (defaultSeeds);
  3894. Random r (0);
  3895. for (int j = 10; --j >= 0;)
  3896. {
  3897. r.setSeedRandomly();
  3898. for (int i = numRandomSeeds; --i >= 0;)
  3899. defaultSeeds[i] ^= r.nextInt() ^ Random::getSystemRandom().nextInt();
  3900. }
  3901. }
  3902. BigInteger smallSieve;
  3903. const int smallSieveSize = 15000;
  3904. createSmallSieve (smallSieveSize, smallSieve);
  3905. BigInteger p;
  3906. for (int i = numRandomSeeds; --i >= 0;)
  3907. {
  3908. BigInteger p2;
  3909. Random r (randomSeeds[i]);
  3910. r.fillBitsRandomly (p2, 0, bitLength);
  3911. p ^= p2;
  3912. }
  3913. p.setBit (bitLength - 1);
  3914. p.clearBit (0);
  3915. const int searchLen = jmax (1024, (bitLength / 20) * 64);
  3916. while (p.getHighestBit() < bitLength)
  3917. {
  3918. p += 2 * searchLen;
  3919. BigInteger sieve;
  3920. bigSieve (p, searchLen, sieve,
  3921. smallSieve, smallSieveSize);
  3922. BigInteger candidate;
  3923. if (findCandidate (p, sieve, searchLen, candidate, certainty))
  3924. return candidate;
  3925. }
  3926. jassertfalse
  3927. return BigInteger();
  3928. }
  3929. bool Primes::isProbablyPrime (const BigInteger& number, const int certainty)
  3930. {
  3931. using namespace PrimesHelpers;
  3932. if (! number[0])
  3933. return false;
  3934. if (number.getHighestBit() <= 10)
  3935. {
  3936. const int num = number.getBitRangeAsInt (0, 10);
  3937. for (int i = num / 2; --i > 1;)
  3938. if (num % i == 0)
  3939. return false;
  3940. return true;
  3941. }
  3942. else
  3943. {
  3944. if (number.findGreatestCommonDivisor (2 * 3 * 5 * 7 * 11 * 13 * 17 * 19 * 23) != 1)
  3945. return false;
  3946. return passesMillerRabin (number, certainty);
  3947. }
  3948. }
  3949. END_JUCE_NAMESPACE
  3950. /*** End of inlined file: juce_Primes.cpp ***/
  3951. /*** Start of inlined file: juce_RSAKey.cpp ***/
  3952. BEGIN_JUCE_NAMESPACE
  3953. RSAKey::RSAKey()
  3954. {
  3955. }
  3956. RSAKey::RSAKey (const String& s)
  3957. {
  3958. if (s.containsChar (','))
  3959. {
  3960. part1.parseString (s.upToFirstOccurrenceOf (T(","), false, false), 16);
  3961. part2.parseString (s.fromFirstOccurrenceOf (T(","), false, false), 16);
  3962. }
  3963. else
  3964. {
  3965. // the string needs to be two hex numbers, comma-separated..
  3966. jassertfalse;
  3967. }
  3968. }
  3969. RSAKey::~RSAKey()
  3970. {
  3971. }
  3972. const String RSAKey::toString() const
  3973. {
  3974. return part1.toString (16) + "," + part2.toString (16);
  3975. }
  3976. bool RSAKey::applyToValue (BigInteger& value) const
  3977. {
  3978. if (part1.isZero() || part2.isZero() || value <= 0)
  3979. {
  3980. jassertfalse // using an uninitialised key
  3981. value.clear();
  3982. return false;
  3983. }
  3984. BigInteger result;
  3985. while (! value.isZero())
  3986. {
  3987. result *= part2;
  3988. BigInteger remainder;
  3989. value.divideBy (part2, remainder);
  3990. remainder.exponentModulo (part1, part2);
  3991. result += remainder;
  3992. }
  3993. value.swapWith (result);
  3994. return true;
  3995. }
  3996. static const BigInteger findBestCommonDivisor (const BigInteger& p, const BigInteger& q)
  3997. {
  3998. // try 3, 5, 9, 17, etc first because these only contain 2 bits and so
  3999. // are fast to divide + multiply
  4000. for (int i = 2; i <= 65536; i *= 2)
  4001. {
  4002. const BigInteger e (1 + i);
  4003. if (e.findGreatestCommonDivisor (p).isOne() && e.findGreatestCommonDivisor (q).isOne())
  4004. return e;
  4005. }
  4006. BigInteger e (4);
  4007. while (! (e.findGreatestCommonDivisor (p).isOne() && e.findGreatestCommonDivisor (q).isOne()))
  4008. ++e;
  4009. return e;
  4010. }
  4011. void RSAKey::createKeyPair (RSAKey& publicKey, RSAKey& privateKey,
  4012. const int numBits, const int* randomSeeds, const int numRandomSeeds)
  4013. {
  4014. jassert (numBits > 16); // not much point using less than this..
  4015. BigInteger p (Primes::createProbablePrime (numBits / 2, 30, randomSeeds, numRandomSeeds));
  4016. BigInteger q (Primes::createProbablePrime (numBits - numBits / 2, 30, randomSeeds, numRandomSeeds));
  4017. const BigInteger n (p * q);
  4018. const BigInteger m (--p * --q);
  4019. const BigInteger e (findBestCommonDivisor (p, q));
  4020. BigInteger d (e);
  4021. d.inverseModulo (m);
  4022. publicKey.part1 = e;
  4023. publicKey.part2 = n;
  4024. privateKey.part1 = d;
  4025. privateKey.part2 = n;
  4026. }
  4027. END_JUCE_NAMESPACE
  4028. /*** End of inlined file: juce_RSAKey.cpp ***/
  4029. /*** Start of inlined file: juce_InputStream.cpp ***/
  4030. BEGIN_JUCE_NAMESPACE
  4031. char InputStream::readByte()
  4032. {
  4033. char temp = 0;
  4034. read (&temp, 1);
  4035. return temp;
  4036. }
  4037. bool InputStream::readBool()
  4038. {
  4039. return readByte() != 0;
  4040. }
  4041. short InputStream::readShort()
  4042. {
  4043. char temp[2];
  4044. if (read (temp, 2) == 2)
  4045. return (short) ByteOrder::littleEndianShort (temp);
  4046. return 0;
  4047. }
  4048. short InputStream::readShortBigEndian()
  4049. {
  4050. char temp[2];
  4051. if (read (temp, 2) == 2)
  4052. return (short) ByteOrder::bigEndianShort (temp);
  4053. return 0;
  4054. }
  4055. int InputStream::readInt()
  4056. {
  4057. char temp[4];
  4058. if (read (temp, 4) == 4)
  4059. return (int) ByteOrder::littleEndianInt (temp);
  4060. return 0;
  4061. }
  4062. int InputStream::readIntBigEndian()
  4063. {
  4064. char temp[4];
  4065. if (read (temp, 4) == 4)
  4066. return (int) ByteOrder::bigEndianInt (temp);
  4067. return 0;
  4068. }
  4069. int InputStream::readCompressedInt()
  4070. {
  4071. const unsigned char sizeByte = readByte();
  4072. if (sizeByte == 0)
  4073. return 0;
  4074. const int numBytes = (sizeByte & 0x7f);
  4075. if (numBytes > 4)
  4076. {
  4077. jassertfalse // trying to read corrupt data - this method must only be used
  4078. // to read data that was written by OutputStream::writeCompressedInt()
  4079. return 0;
  4080. }
  4081. char bytes[4] = { 0, 0, 0, 0 };
  4082. if (read (bytes, numBytes) != numBytes)
  4083. return 0;
  4084. const int num = (int) ByteOrder::littleEndianInt (bytes);
  4085. return (sizeByte >> 7) ? -num : num;
  4086. }
  4087. int64 InputStream::readInt64()
  4088. {
  4089. char temp[8];
  4090. if (read (temp, 8) == 8)
  4091. return (int64) ByteOrder::swapIfBigEndian (*reinterpret_cast <uint64*> (temp));
  4092. return 0;
  4093. }
  4094. int64 InputStream::readInt64BigEndian()
  4095. {
  4096. char temp[8];
  4097. if (read (temp, 8) == 8)
  4098. return (int64) ByteOrder::swapIfLittleEndian (*reinterpret_cast <uint64*> (temp));
  4099. return 0;
  4100. }
  4101. float InputStream::readFloat()
  4102. {
  4103. union { int asInt; float asFloat; } n;
  4104. n.asInt = readInt();
  4105. return n.asFloat;
  4106. }
  4107. float InputStream::readFloatBigEndian()
  4108. {
  4109. union { int asInt; float asFloat; } n;
  4110. n.asInt = readIntBigEndian();
  4111. return n.asFloat;
  4112. }
  4113. double InputStream::readDouble()
  4114. {
  4115. union { int64 asInt; double asDouble; } n;
  4116. n.asInt = readInt64();
  4117. return n.asDouble;
  4118. }
  4119. double InputStream::readDoubleBigEndian()
  4120. {
  4121. union { int64 asInt; double asDouble; } n;
  4122. n.asInt = readInt64BigEndian();
  4123. return n.asDouble;
  4124. }
  4125. const String InputStream::readString()
  4126. {
  4127. MemoryBlock buffer (256);
  4128. char* data = static_cast<char*> (buffer.getData());
  4129. size_t i = 0;
  4130. while ((data[i] = readByte()) != 0)
  4131. {
  4132. if (++i >= buffer.getSize())
  4133. {
  4134. buffer.setSize (buffer.getSize() + 512);
  4135. data = static_cast<char*> (buffer.getData());
  4136. }
  4137. }
  4138. return String::fromUTF8 (data, (int) i);
  4139. }
  4140. const String InputStream::readNextLine()
  4141. {
  4142. MemoryBlock buffer (256);
  4143. char* data = static_cast<char*> (buffer.getData());
  4144. size_t i = 0;
  4145. while ((data[i] = readByte()) != 0)
  4146. {
  4147. if (data[i] == '\n')
  4148. break;
  4149. if (data[i] == '\r')
  4150. {
  4151. const int64 lastPos = getPosition();
  4152. if (readByte() != '\n')
  4153. setPosition (lastPos);
  4154. break;
  4155. }
  4156. if (++i >= buffer.getSize())
  4157. {
  4158. buffer.setSize (buffer.getSize() + 512);
  4159. data = static_cast<char*> (buffer.getData());
  4160. }
  4161. }
  4162. return String::fromUTF8 (data, (int) i);
  4163. }
  4164. int InputStream::readIntoMemoryBlock (MemoryBlock& block, int numBytes)
  4165. {
  4166. const int64 totalLength = getTotalLength();
  4167. if (totalLength >= 0)
  4168. {
  4169. const int totalBytesRemaining = (int) jmin ((int64) 0x7fffffff,
  4170. totalLength - getPosition());
  4171. if (numBytes < 0)
  4172. numBytes = totalBytesRemaining;
  4173. else if (numBytes > 0)
  4174. numBytes = jmin (numBytes, totalBytesRemaining);
  4175. else
  4176. return 0;
  4177. }
  4178. const size_t originalBlockSize = block.getSize();
  4179. int totalBytesRead = 0;
  4180. if (numBytes > 0)
  4181. {
  4182. // know how many bytes we want, so we can resize the block first..
  4183. block.setSize (originalBlockSize + numBytes, false);
  4184. totalBytesRead = read (static_cast<char*> (block.getData()) + originalBlockSize, numBytes);
  4185. }
  4186. else
  4187. {
  4188. // read until end of stram..
  4189. const int chunkSize = 32768;
  4190. for (;;)
  4191. {
  4192. block.ensureSize (originalBlockSize + totalBytesRead + chunkSize, false);
  4193. const int bytesJustIn = read (static_cast<char*> (block.getData())
  4194. + originalBlockSize
  4195. + totalBytesRead,
  4196. chunkSize);
  4197. if (bytesJustIn == 0)
  4198. break;
  4199. totalBytesRead += bytesJustIn;
  4200. }
  4201. }
  4202. // trim off any excess left at the end
  4203. block.setSize (originalBlockSize + totalBytesRead, false);
  4204. return totalBytesRead;
  4205. }
  4206. const String InputStream::readEntireStreamAsString()
  4207. {
  4208. MemoryBlock mb;
  4209. const int size = readIntoMemoryBlock (mb);
  4210. return String::createStringFromData (static_cast<const char*> (mb.getData()), size);
  4211. }
  4212. void InputStream::skipNextBytes (int64 numBytesToSkip)
  4213. {
  4214. if (numBytesToSkip > 0)
  4215. {
  4216. const int skipBufferSize = (int) jmin (numBytesToSkip, (int64) 16384);
  4217. HeapBlock<char> temp (skipBufferSize);
  4218. while (numBytesToSkip > 0 && ! isExhausted())
  4219. numBytesToSkip -= read (temp, (int) jmin (numBytesToSkip, (int64) skipBufferSize));
  4220. }
  4221. }
  4222. END_JUCE_NAMESPACE
  4223. /*** End of inlined file: juce_InputStream.cpp ***/
  4224. /*** Start of inlined file: juce_OutputStream.cpp ***/
  4225. BEGIN_JUCE_NAMESPACE
  4226. #if JUCE_DEBUG
  4227. static CriticalSection activeStreamLock;
  4228. static VoidArray activeStreams;
  4229. void juce_CheckForDanglingStreams()
  4230. {
  4231. /*
  4232. It's always a bad idea to leak any object, but if you're leaking output
  4233. streams, then there's a good chance that you're failing to flush a file
  4234. to disk properly, which could result in corrupted data and other similar
  4235. nastiness..
  4236. */
  4237. jassert (activeStreams.size() == 0);
  4238. };
  4239. #endif
  4240. OutputStream::OutputStream()
  4241. {
  4242. #if JUCE_DEBUG
  4243. const ScopedLock sl (activeStreamLock);
  4244. activeStreams.add (this);
  4245. #endif
  4246. }
  4247. OutputStream::~OutputStream()
  4248. {
  4249. #if JUCE_DEBUG
  4250. const ScopedLock sl (activeStreamLock);
  4251. activeStreams.removeValue (this);
  4252. #endif
  4253. }
  4254. void OutputStream::writeBool (const bool b)
  4255. {
  4256. writeByte (b ? (char) 1
  4257. : (char) 0);
  4258. }
  4259. void OutputStream::writeByte (char byte)
  4260. {
  4261. write (&byte, 1);
  4262. }
  4263. void OutputStream::writeShort (short value)
  4264. {
  4265. const unsigned short v = ByteOrder::swapIfBigEndian ((unsigned short) value);
  4266. write (&v, 2);
  4267. }
  4268. void OutputStream::writeShortBigEndian (short value)
  4269. {
  4270. const unsigned short v = ByteOrder::swapIfLittleEndian ((unsigned short) value);
  4271. write (&v, 2);
  4272. }
  4273. void OutputStream::writeInt (int value)
  4274. {
  4275. const unsigned int v = ByteOrder::swapIfBigEndian ((unsigned int) value);
  4276. write (&v, 4);
  4277. }
  4278. void OutputStream::writeIntBigEndian (int value)
  4279. {
  4280. const unsigned int v = ByteOrder::swapIfLittleEndian ((unsigned int) value);
  4281. write (&v, 4);
  4282. }
  4283. void OutputStream::writeCompressedInt (int value)
  4284. {
  4285. unsigned int un = (value < 0) ? (unsigned int) -value
  4286. : (unsigned int) value;
  4287. uint8 data[5];
  4288. int num = 0;
  4289. while (un > 0)
  4290. {
  4291. data[++num] = (uint8) un;
  4292. un >>= 8;
  4293. }
  4294. data[0] = (uint8) num;
  4295. if (value < 0)
  4296. data[0] |= 0x80;
  4297. write (data, num + 1);
  4298. }
  4299. void OutputStream::writeInt64 (int64 value)
  4300. {
  4301. const uint64 v = ByteOrder::swapIfBigEndian ((uint64) value);
  4302. write (&v, 8);
  4303. }
  4304. void OutputStream::writeInt64BigEndian (int64 value)
  4305. {
  4306. const uint64 v = ByteOrder::swapIfLittleEndian ((uint64) value);
  4307. write (&v, 8);
  4308. }
  4309. void OutputStream::writeFloat (float value)
  4310. {
  4311. union { int asInt; float asFloat; } n;
  4312. n.asFloat = value;
  4313. writeInt (n.asInt);
  4314. }
  4315. void OutputStream::writeFloatBigEndian (float value)
  4316. {
  4317. union { int asInt; float asFloat; } n;
  4318. n.asFloat = value;
  4319. writeIntBigEndian (n.asInt);
  4320. }
  4321. void OutputStream::writeDouble (double value)
  4322. {
  4323. union { int64 asInt; double asDouble; } n;
  4324. n.asDouble = value;
  4325. writeInt64 (n.asInt);
  4326. }
  4327. void OutputStream::writeDoubleBigEndian (double value)
  4328. {
  4329. union { int64 asInt; double asDouble; } n;
  4330. n.asDouble = value;
  4331. writeInt64BigEndian (n.asInt);
  4332. }
  4333. void OutputStream::writeString (const String& text)
  4334. {
  4335. // (This avoids using toUTF8() to prevent the memory bloat that it would leave behind
  4336. // if lots of large, persistent strings were to be written to streams).
  4337. const int numBytes = text.getNumBytesAsUTF8() + 1;
  4338. HeapBlock<char> temp (numBytes);
  4339. text.copyToUTF8 (temp, numBytes);
  4340. write (temp, numBytes);
  4341. }
  4342. void OutputStream::writeText (const String& text, const bool asUnicode,
  4343. const bool writeUnicodeHeaderBytes)
  4344. {
  4345. if (asUnicode)
  4346. {
  4347. if (writeUnicodeHeaderBytes)
  4348. write ("\x0ff\x0fe", 2);
  4349. const juce_wchar* src = (const juce_wchar*) text;
  4350. bool lastCharWasReturn = false;
  4351. while (*src != 0)
  4352. {
  4353. if (*src == L'\n' && ! lastCharWasReturn)
  4354. writeShort ((short) L'\r');
  4355. lastCharWasReturn = (*src == L'\r');
  4356. writeShort ((short) *src++);
  4357. }
  4358. }
  4359. else
  4360. {
  4361. const char* src = text.toUTF8();
  4362. const char* t = src;
  4363. for (;;)
  4364. {
  4365. if (*t == '\n')
  4366. {
  4367. if (t > src)
  4368. write (src, (int) (t - src));
  4369. write ("\r\n", 2);
  4370. src = t + 1;
  4371. }
  4372. else if (*t == '\r')
  4373. {
  4374. if (t[1] == '\n')
  4375. ++t;
  4376. }
  4377. else if (*t == 0)
  4378. {
  4379. if (t > src)
  4380. write (src, (int) (t - src));
  4381. break;
  4382. }
  4383. ++t;
  4384. }
  4385. }
  4386. }
  4387. int OutputStream::writeFromInputStream (InputStream& source, int numBytesToWrite)
  4388. {
  4389. if (numBytesToWrite < 0)
  4390. numBytesToWrite = 0x7fffffff;
  4391. int numWritten = 0;
  4392. while (numBytesToWrite > 0 && ! source.isExhausted())
  4393. {
  4394. char buffer [8192];
  4395. const int num = (int) source.read (buffer, (int) jmin ((size_t) numBytesToWrite, sizeof (buffer)));
  4396. if (num == 0)
  4397. break;
  4398. write (buffer, num);
  4399. numBytesToWrite -= num;
  4400. numWritten += num;
  4401. }
  4402. return numWritten;
  4403. }
  4404. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const int number)
  4405. {
  4406. return stream << String (number);
  4407. }
  4408. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const double number)
  4409. {
  4410. return stream << String (number);
  4411. }
  4412. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const char character)
  4413. {
  4414. stream.writeByte (character);
  4415. return stream;
  4416. }
  4417. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const char* const text)
  4418. {
  4419. stream.write (text, (int) strlen (text));
  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. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4427. bool* isDirectory, bool* isHidden, int64* fileSize,
  4428. Time* modTime, Time* creationTime, bool* isReadOnly);
  4429. bool juce_findFileNext (void* handle, String& resultFile,
  4430. bool* isDirectory, bool* isHidden, int64* fileSize,
  4431. Time* modTime, Time* creationTime, bool* isReadOnly);
  4432. void juce_findFileClose (void* handle);
  4433. DirectoryIterator::DirectoryIterator (const File& directory,
  4434. bool isRecursive,
  4435. const String& wc,
  4436. const int whatToLookFor_)
  4437. : wildCard (wc),
  4438. index (-1),
  4439. whatToLookFor (whatToLookFor_)
  4440. {
  4441. // you have to specify the type of files you're looking for!
  4442. jassert ((whatToLookFor_ & (File::findFiles | File::findDirectories)) != 0);
  4443. jassert (whatToLookFor_ > 0 && whatToLookFor_ <= 7);
  4444. String path (directory.getFullPathName());
  4445. if (! path.endsWithChar (File::separator))
  4446. path += File::separator;
  4447. String filename;
  4448. bool isDirectory, isHidden;
  4449. void* const handle = juce_findFileStart (path,
  4450. isRecursive ? "*" : wc,
  4451. filename, &isDirectory, &isHidden, 0, 0, 0, 0);
  4452. if (handle != 0)
  4453. {
  4454. do
  4455. {
  4456. if (! filename.containsOnly (T(".")))
  4457. {
  4458. bool addToList = false;
  4459. if (isDirectory)
  4460. {
  4461. if (isRecursive
  4462. && ((whatToLookFor_ & File::ignoreHiddenFiles) == 0
  4463. || ! isHidden))
  4464. {
  4465. dirsFound.add (File (path + filename, 0));
  4466. }
  4467. addToList = (whatToLookFor_ & File::findDirectories) != 0;
  4468. }
  4469. else
  4470. {
  4471. addToList = (whatToLookFor_ & File::findFiles) != 0;
  4472. }
  4473. // if it's recursive, we're not relying on the OS iterator
  4474. // to do the wildcard match, so do it now..
  4475. if (isRecursive && addToList)
  4476. addToList = filename.matchesWildcard (wc, true);
  4477. if (addToList && (whatToLookFor_ & File::ignoreHiddenFiles) != 0)
  4478. addToList = ! isHidden;
  4479. if (addToList)
  4480. filesFound.add (File (path + filename, 0));
  4481. }
  4482. } while (juce_findFileNext (handle, filename, &isDirectory, &isHidden, 0, 0, 0, 0));
  4483. juce_findFileClose (handle);
  4484. }
  4485. }
  4486. DirectoryIterator::~DirectoryIterator()
  4487. {
  4488. }
  4489. bool DirectoryIterator::next()
  4490. {
  4491. if (subIterator != 0)
  4492. {
  4493. if (subIterator->next())
  4494. return true;
  4495. subIterator = 0;
  4496. }
  4497. if (index >= filesFound.size() + dirsFound.size() - 1)
  4498. return false;
  4499. ++index;
  4500. if (index >= filesFound.size())
  4501. {
  4502. subIterator = new DirectoryIterator (dirsFound.getReference (index - filesFound.size()),
  4503. true, wildCard, whatToLookFor);
  4504. return next();
  4505. }
  4506. return true;
  4507. }
  4508. const File DirectoryIterator::getFile() const
  4509. {
  4510. if (subIterator != 0)
  4511. return subIterator->getFile();
  4512. return filesFound [index];
  4513. }
  4514. float DirectoryIterator::getEstimatedProgress() const
  4515. {
  4516. if (filesFound.size() + dirsFound.size() == 0)
  4517. {
  4518. return 0.0f;
  4519. }
  4520. else
  4521. {
  4522. const float detailedIndex = (subIterator != 0) ? index + subIterator->getEstimatedProgress()
  4523. : (float) index;
  4524. return detailedIndex / (filesFound.size() + dirsFound.size());
  4525. }
  4526. }
  4527. END_JUCE_NAMESPACE
  4528. /*** End of inlined file: juce_DirectoryIterator.cpp ***/
  4529. /*** Start of inlined file: juce_File.cpp ***/
  4530. #ifdef _MSC_VER
  4531. #pragma warning (disable: 4514)
  4532. #pragma warning (push)
  4533. #endif
  4534. #if ! JUCE_WINDOWS
  4535. #include <pwd.h>
  4536. #endif
  4537. BEGIN_JUCE_NAMESPACE
  4538. #ifdef _MSC_VER
  4539. #pragma warning (pop)
  4540. #endif
  4541. void* juce_fileOpen (const String& path, bool forWriting);
  4542. void juce_fileClose (void* handle);
  4543. int juce_fileWrite (void* handle, const void* buffer, int size);
  4544. int64 juce_fileGetPosition (void* handle);
  4545. int64 juce_fileSetPosition (void* handle, int64 pos);
  4546. void juce_fileFlush (void* handle);
  4547. bool juce_fileExists (const String& fileName, const bool dontCountDirectories);
  4548. bool juce_isDirectory (const String& fileName);
  4549. int64 juce_getFileSize (const String& fileName);
  4550. bool juce_canWriteToFile (const String& fileName);
  4551. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly);
  4552. void juce_getFileTimes (const String& fileName, int64& modificationTime, int64& accessTime, int64& creationTime);
  4553. bool juce_setFileTimes (const String& fileName, int64 modificationTime, int64 accessTime, int64 creationTime);
  4554. bool juce_deleteFile (const String& fileName);
  4555. bool juce_copyFile (const String& source, const String& dest);
  4556. bool juce_moveFile (const String& source, const String& dest);
  4557. // this must also create all paths involved in the directory.
  4558. void juce_createDirectory (const String& fileName);
  4559. bool juce_launchFile (const String& fileName, const String& parameters);
  4560. const StringArray juce_getFileSystemRoots();
  4561. const String juce_getVolumeLabel (const String& filenameOnVolume, int& volumeSerialNumber);
  4562. // starts a directory search operation with a wildcard, returning a handle for
  4563. // use in calls to juce_findFileNext.
  4564. // juce_firstResultFile gets the name of the file (not the whole pathname) and
  4565. // the other pointers, if non-null, are set based on the properties of the file.
  4566. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4567. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  4568. Time* creationTime, bool* isReadOnly);
  4569. // returns false when no more files are found
  4570. bool juce_findFileNext (void* handle, String& resultFile,
  4571. bool* isDirectory, bool* isHidden, int64* fileSize,
  4572. Time* modTime, Time* creationTime, bool* isReadOnly);
  4573. void juce_findFileClose (void* handle);
  4574. static const String juce_addTrailingSeparator (const String& path)
  4575. {
  4576. return path.endsWithChar (File::separator) ? path
  4577. : path + File::separator;
  4578. }
  4579. static const String parseAbsolutePath (String path)
  4580. {
  4581. if (path.isEmpty())
  4582. return String::empty;
  4583. #if JUCE_WINDOWS
  4584. // Windows..
  4585. path = path.replaceCharacter ('/', '\\');
  4586. if (path.startsWithChar (File::separator))
  4587. {
  4588. if (path[1] != File::separator)
  4589. {
  4590. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4591. If you're trying to parse a string that may be either a relative path or an absolute path,
  4592. you MUST provide a context against which the partial path can be evaluated - you can do
  4593. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4594. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4595. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4596. */
  4597. jassertfalse
  4598. path = File::getCurrentWorkingDirectory().getFullPathName().substring (0, 2) + path;
  4599. }
  4600. }
  4601. else if (path.indexOfChar (':') < 0)
  4602. {
  4603. if (path.isEmpty())
  4604. return String::empty;
  4605. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4606. If you're trying to parse a string that may be either a relative path or an absolute path,
  4607. you MUST provide a context against which the partial path can be evaluated - you can do
  4608. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4609. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4610. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4611. */
  4612. jassertfalse
  4613. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4614. }
  4615. #else
  4616. // Mac or Linux..
  4617. path = path.replaceCharacter ('\\', '/');
  4618. if (path.startsWithChar ('~'))
  4619. {
  4620. const char* homeDir = 0;
  4621. if (path[1] == File::separator || path[1] == 0)
  4622. {
  4623. // expand a name of the form "~/abc"
  4624. path = File::getSpecialLocation (File::userHomeDirectory).getFullPathName()
  4625. + path.substring (1);
  4626. }
  4627. else
  4628. {
  4629. // expand a name of type "~dave/abc"
  4630. const String userName (path.substring (1).upToFirstOccurrenceOf (T("/"), false, false));
  4631. struct passwd* const pw = getpwnam (userName.toUTF8());
  4632. if (pw != 0)
  4633. {
  4634. String home (homeDir);
  4635. if (home.endsWithChar (File::separator))
  4636. home [home.length() - 1] = 0;
  4637. path = String (pw->pw_dir)
  4638. + path.substring (userName.length());
  4639. }
  4640. }
  4641. }
  4642. else if (! path.startsWithChar (File::separator))
  4643. {
  4644. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4645. If you're trying to parse a string that may be either a relative path or an absolute path,
  4646. you MUST provide a context against which the partial path can be evaluated - you can do
  4647. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4648. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4649. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4650. */
  4651. jassert (path.startsWith (T("./"))); // (assume that a path "./xyz" is deliberately intended to be relative to the CWD)
  4652. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4653. }
  4654. #endif
  4655. int len = path.length();
  4656. while (--len > 0 && path [len] == File::separator)
  4657. path [len] = 0;
  4658. return path;
  4659. }
  4660. const File File::nonexistent;
  4661. File::File (const String& fullPathName)
  4662. : fullPath (parseAbsolutePath (fullPathName))
  4663. {
  4664. }
  4665. File::File (const String& path, int)
  4666. : fullPath (path)
  4667. {
  4668. }
  4669. const File File::createFileWithoutCheckingPath (const String& path)
  4670. {
  4671. return File (path, 0);
  4672. }
  4673. File::File (const File& other)
  4674. : fullPath (other.fullPath)
  4675. {
  4676. }
  4677. File& File::operator= (const String& newPath)
  4678. {
  4679. fullPath = parseAbsolutePath (newPath);
  4680. return *this;
  4681. }
  4682. File& File::operator= (const File& other)
  4683. {
  4684. fullPath = other.fullPath;
  4685. return *this;
  4686. }
  4687. #if JUCE_LINUX
  4688. #define NAMES_ARE_CASE_SENSITIVE 1
  4689. #endif
  4690. bool File::areFileNamesCaseSensitive()
  4691. {
  4692. #if NAMES_ARE_CASE_SENSITIVE
  4693. return true;
  4694. #else
  4695. return false;
  4696. #endif
  4697. }
  4698. bool File::operator== (const File& other) const
  4699. {
  4700. // case-insensitive on Windows, but not on linux.
  4701. #if NAMES_ARE_CASE_SENSITIVE
  4702. return fullPath == other.fullPath;
  4703. #else
  4704. return fullPath.equalsIgnoreCase (other.fullPath);
  4705. #endif
  4706. }
  4707. bool File::operator!= (const File& other) const
  4708. {
  4709. return ! operator== (other);
  4710. }
  4711. bool File::exists() const
  4712. {
  4713. return juce_fileExists (fullPath, false);
  4714. }
  4715. bool File::existsAsFile() const
  4716. {
  4717. return juce_fileExists (fullPath, true);
  4718. }
  4719. bool File::isDirectory() const
  4720. {
  4721. return juce_isDirectory (fullPath);
  4722. }
  4723. bool File::hasWriteAccess() const
  4724. {
  4725. if (exists())
  4726. return juce_canWriteToFile (fullPath);
  4727. #if ! JUCE_WINDOWS
  4728. else if ((! isDirectory()) && fullPath.containsChar (separator))
  4729. return getParentDirectory().hasWriteAccess();
  4730. else
  4731. return false;
  4732. #else
  4733. // on windows, it seems that even read-only directories can still be written into,
  4734. // so checking the parent directory's permissions would return the wrong result..
  4735. else
  4736. return true;
  4737. #endif
  4738. }
  4739. bool File::setReadOnly (const bool shouldBeReadOnly,
  4740. const bool applyRecursively) const
  4741. {
  4742. bool worked = true;
  4743. if (applyRecursively && isDirectory())
  4744. {
  4745. Array <File> subFiles;
  4746. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4747. for (int i = subFiles.size(); --i >= 0;)
  4748. worked = subFiles.getReference(i).setReadOnly (shouldBeReadOnly, true) && worked;
  4749. }
  4750. return juce_setFileReadOnly (fullPath, shouldBeReadOnly) && worked;
  4751. }
  4752. bool File::deleteFile() const
  4753. {
  4754. return (! exists())
  4755. || juce_deleteFile (fullPath);
  4756. }
  4757. bool File::deleteRecursively() const
  4758. {
  4759. bool worked = true;
  4760. if (isDirectory())
  4761. {
  4762. Array<File> subFiles;
  4763. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4764. for (int i = subFiles.size(); --i >= 0;)
  4765. worked = subFiles.getReference(i).deleteRecursively() && worked;
  4766. }
  4767. return deleteFile() && worked;
  4768. }
  4769. bool File::moveFileTo (const File& newFile) const
  4770. {
  4771. if (newFile.fullPath == fullPath)
  4772. return true;
  4773. #if ! NAMES_ARE_CASE_SENSITIVE
  4774. if (*this != newFile)
  4775. #endif
  4776. if (! newFile.deleteFile())
  4777. return false;
  4778. return juce_moveFile (fullPath, newFile.fullPath);
  4779. }
  4780. bool File::copyFileTo (const File& newFile) const
  4781. {
  4782. if (*this == newFile)
  4783. return true;
  4784. if (! newFile.deleteFile())
  4785. return false;
  4786. return juce_copyFile (fullPath, newFile.fullPath);
  4787. }
  4788. bool File::copyDirectoryTo (const File& newDirectory) const
  4789. {
  4790. if (isDirectory() && newDirectory.createDirectory())
  4791. {
  4792. Array<File> subFiles;
  4793. findChildFiles (subFiles, File::findFiles, false);
  4794. int i;
  4795. for (i = 0; i < subFiles.size(); ++i)
  4796. if (! subFiles.getReference(i).copyFileTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4797. return false;
  4798. subFiles.clear();
  4799. findChildFiles (subFiles, File::findDirectories, false);
  4800. for (i = 0; i < subFiles.size(); ++i)
  4801. if (! subFiles.getReference(i).copyDirectoryTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4802. return false;
  4803. return true;
  4804. }
  4805. return false;
  4806. }
  4807. const String File::getPathUpToLastSlash() const
  4808. {
  4809. const int lastSlash = fullPath.lastIndexOfChar (separator);
  4810. if (lastSlash > 0)
  4811. return fullPath.substring (0, lastSlash);
  4812. else if (lastSlash == 0)
  4813. return separatorString;
  4814. else
  4815. return fullPath;
  4816. }
  4817. const File File::getParentDirectory() const
  4818. {
  4819. return File (getPathUpToLastSlash());
  4820. }
  4821. const String File::getFileName() const
  4822. {
  4823. return fullPath.substring (fullPath.lastIndexOfChar (separator) + 1);
  4824. }
  4825. int File::hashCode() const
  4826. {
  4827. return fullPath.hashCode();
  4828. }
  4829. int64 File::hashCode64() const
  4830. {
  4831. return fullPath.hashCode64();
  4832. }
  4833. const String File::getFileNameWithoutExtension() const
  4834. {
  4835. const int lastSlash = fullPath.lastIndexOfChar (separator) + 1;
  4836. const int lastDot = fullPath.lastIndexOfChar ('.');
  4837. if (lastDot > lastSlash)
  4838. return fullPath.substring (lastSlash, lastDot);
  4839. else
  4840. return fullPath.substring (lastSlash);
  4841. }
  4842. bool File::isAChildOf (const File& potentialParent) const
  4843. {
  4844. if (potentialParent == File::nonexistent)
  4845. return false;
  4846. const String ourPath (getPathUpToLastSlash());
  4847. #if NAMES_ARE_CASE_SENSITIVE
  4848. if (potentialParent.fullPath == ourPath)
  4849. #else
  4850. if (potentialParent.fullPath.equalsIgnoreCase (ourPath))
  4851. #endif
  4852. {
  4853. return true;
  4854. }
  4855. else if (potentialParent.fullPath.length() >= ourPath.length())
  4856. {
  4857. return false;
  4858. }
  4859. else
  4860. {
  4861. return getParentDirectory().isAChildOf (potentialParent);
  4862. }
  4863. }
  4864. bool File::isAbsolutePath (const String& path)
  4865. {
  4866. return path.startsWithChar ('/') || path.startsWithChar ('\\')
  4867. #if JUCE_WINDOWS
  4868. || (path.isNotEmpty() && path[1] == ':');
  4869. #else
  4870. || path.startsWithChar ('~');
  4871. #endif
  4872. }
  4873. const File File::getChildFile (String relativePath) const
  4874. {
  4875. if (isAbsolutePath (relativePath))
  4876. {
  4877. // the path is really absolute..
  4878. return File (relativePath);
  4879. }
  4880. else
  4881. {
  4882. // it's relative, so remove any ../ or ./ bits at the start.
  4883. String path (fullPath);
  4884. if (relativePath[0] == '.')
  4885. {
  4886. #if JUCE_WINDOWS
  4887. relativePath = relativePath.replaceCharacter ('/', '\\').trimStart();
  4888. #else
  4889. relativePath = relativePath.replaceCharacter ('\\', '/').trimStart();
  4890. #endif
  4891. while (relativePath[0] == '.')
  4892. {
  4893. if (relativePath[1] == '.')
  4894. {
  4895. if (relativePath [2] == 0 || relativePath[2] == separator)
  4896. {
  4897. const int lastSlash = path.lastIndexOfChar (separator);
  4898. if (lastSlash >= 0)
  4899. path = path.substring (0, lastSlash);
  4900. relativePath = relativePath.substring (3);
  4901. }
  4902. else
  4903. {
  4904. break;
  4905. }
  4906. }
  4907. else if (relativePath[1] == separator)
  4908. {
  4909. relativePath = relativePath.substring (2);
  4910. }
  4911. else
  4912. {
  4913. break;
  4914. }
  4915. }
  4916. }
  4917. return File (juce_addTrailingSeparator (path) + relativePath);
  4918. }
  4919. }
  4920. const File File::getSiblingFile (const String& fileName) const
  4921. {
  4922. return getParentDirectory().getChildFile (fileName);
  4923. }
  4924. int64 File::getSize() const
  4925. {
  4926. return juce_getFileSize (fullPath);
  4927. }
  4928. const String File::descriptionOfSizeInBytes (const int64 bytes)
  4929. {
  4930. if (bytes == 1)
  4931. {
  4932. return "1 byte";
  4933. }
  4934. else if (bytes < 1024)
  4935. {
  4936. return String ((int) bytes) + " bytes";
  4937. }
  4938. else if (bytes < 1024 * 1024)
  4939. {
  4940. return String (bytes / 1024.0, 1) + " KB";
  4941. }
  4942. else if (bytes < 1024 * 1024 * 1024)
  4943. {
  4944. return String (bytes / (1024.0 * 1024.0), 1) + " MB";
  4945. }
  4946. else
  4947. {
  4948. return String (bytes / (1024.0 * 1024.0 * 1024.0), 1) + " GB";
  4949. }
  4950. }
  4951. bool File::create() const
  4952. {
  4953. if (! exists())
  4954. {
  4955. const File parentDir (getParentDirectory());
  4956. if (parentDir == *this || ! parentDir.createDirectory())
  4957. return false;
  4958. void* const fh = juce_fileOpen (fullPath, true);
  4959. if (fh == 0)
  4960. return false;
  4961. juce_fileClose (fh);
  4962. }
  4963. return true;
  4964. }
  4965. bool File::createDirectory() const
  4966. {
  4967. if (! isDirectory())
  4968. {
  4969. const File parentDir (getParentDirectory());
  4970. if (parentDir == *this || ! parentDir.createDirectory())
  4971. return false;
  4972. String dir (fullPath);
  4973. while (dir.endsWithChar (separator))
  4974. dir [dir.length() - 1] = 0;
  4975. juce_createDirectory (dir);
  4976. return isDirectory();
  4977. }
  4978. return true;
  4979. }
  4980. const Time File::getCreationTime() const
  4981. {
  4982. int64 m, a, c;
  4983. juce_getFileTimes (fullPath, m, a, c);
  4984. return Time (c);
  4985. }
  4986. bool File::setCreationTime (const Time& t) const
  4987. {
  4988. return juce_setFileTimes (fullPath, 0, 0, t.toMilliseconds());
  4989. }
  4990. const Time File::getLastModificationTime() const
  4991. {
  4992. int64 m, a, c;
  4993. juce_getFileTimes (fullPath, m, a, c);
  4994. return Time (m);
  4995. }
  4996. bool File::setLastModificationTime (const Time& t) const
  4997. {
  4998. return juce_setFileTimes (fullPath, t.toMilliseconds(), 0, 0);
  4999. }
  5000. const Time File::getLastAccessTime() const
  5001. {
  5002. int64 m, a, c;
  5003. juce_getFileTimes (fullPath, m, a, c);
  5004. return Time (a);
  5005. }
  5006. bool File::setLastAccessTime (const Time& t) const
  5007. {
  5008. return juce_setFileTimes (fullPath, 0, t.toMilliseconds(), 0);
  5009. }
  5010. bool File::loadFileAsData (MemoryBlock& destBlock) const
  5011. {
  5012. if (! existsAsFile())
  5013. return false;
  5014. FileInputStream in (*this);
  5015. return getSize() == in.readIntoMemoryBlock (destBlock);
  5016. }
  5017. const String File::loadFileAsString() const
  5018. {
  5019. if (! existsAsFile())
  5020. return String::empty;
  5021. FileInputStream in (*this);
  5022. return in.readEntireStreamAsString();
  5023. }
  5024. static inline bool fileTypeMatches (const int whatToLookFor,
  5025. const bool isDir,
  5026. const bool isHidden)
  5027. {
  5028. return (whatToLookFor & (isDir ? File::findDirectories
  5029. : File::findFiles)) != 0
  5030. && ((! isHidden)
  5031. || (whatToLookFor & File::ignoreHiddenFiles) == 0);
  5032. }
  5033. int File::findChildFiles (Array<File>& results,
  5034. const int whatToLookFor,
  5035. const bool searchRecursively,
  5036. const String& wildCardPattern) const
  5037. {
  5038. // you have to specify the type of files you're looking for!
  5039. jassert ((whatToLookFor & (findFiles | findDirectories)) != 0);
  5040. int total = 0;
  5041. // find child files or directories in this directory first..
  5042. if (isDirectory())
  5043. {
  5044. const String path (juce_addTrailingSeparator (fullPath));
  5045. String filename;
  5046. bool itemIsDirectory, itemIsHidden;
  5047. void* const handle = juce_findFileStart (path, wildCardPattern, filename,
  5048. &itemIsDirectory, &itemIsHidden,
  5049. 0, 0, 0, 0);
  5050. if (handle != 0)
  5051. {
  5052. do
  5053. {
  5054. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5055. && ! filename.containsOnly (T(".")))
  5056. {
  5057. results.add (File (path + filename, 0));
  5058. ++total;
  5059. }
  5060. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5061. juce_findFileClose (handle);
  5062. }
  5063. }
  5064. else
  5065. {
  5066. // trying to search for files inside a non-directory?
  5067. //jassertfalse
  5068. }
  5069. // and recurse down if required.
  5070. if (searchRecursively)
  5071. {
  5072. Array<File> subDirectories;
  5073. findChildFiles (subDirectories, File::findDirectories, false);
  5074. for (int i = 0; i < subDirectories.size(); ++i)
  5075. {
  5076. total += subDirectories.getReference(i).findChildFiles (results, whatToLookFor,
  5077. true, wildCardPattern);
  5078. }
  5079. }
  5080. return total;
  5081. }
  5082. int File::getNumberOfChildFiles (const int whatToLookFor,
  5083. const String& wildCardPattern) const
  5084. {
  5085. // you have to specify the type of files you're looking for!
  5086. jassert (whatToLookFor > 0 && whatToLookFor <= 3);
  5087. int count = 0;
  5088. if (isDirectory())
  5089. {
  5090. String filename;
  5091. bool itemIsDirectory, itemIsHidden;
  5092. void* const handle = juce_findFileStart (fullPath, wildCardPattern, filename,
  5093. &itemIsDirectory, &itemIsHidden,
  5094. 0, 0, 0, 0);
  5095. if (handle != 0)
  5096. {
  5097. do
  5098. {
  5099. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5100. && ! filename.containsOnly (T(".")))
  5101. {
  5102. ++count;
  5103. }
  5104. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5105. juce_findFileClose (handle);
  5106. }
  5107. }
  5108. else
  5109. {
  5110. // trying to search for files inside a non-directory?
  5111. jassertfalse
  5112. }
  5113. return count;
  5114. }
  5115. bool File::containsSubDirectories() const
  5116. {
  5117. bool result = false;
  5118. if (isDirectory())
  5119. {
  5120. String filename;
  5121. bool itemIsDirectory, itemIsHidden;
  5122. void* const handle = juce_findFileStart (juce_addTrailingSeparator (fullPath),
  5123. "*", filename,
  5124. &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0);
  5125. if (handle != 0)
  5126. {
  5127. do
  5128. {
  5129. if (itemIsDirectory)
  5130. {
  5131. result = true;
  5132. break;
  5133. }
  5134. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5135. juce_findFileClose (handle);
  5136. }
  5137. }
  5138. return result;
  5139. }
  5140. const File File::getNonexistentChildFile (const String& prefix_,
  5141. const String& suffix,
  5142. bool putNumbersInBrackets) const
  5143. {
  5144. File f (getChildFile (prefix_ + suffix));
  5145. if (f.exists())
  5146. {
  5147. int num = 2;
  5148. String prefix (prefix_);
  5149. // remove any bracketed numbers that may already be on the end..
  5150. if (prefix.trim().endsWithChar (')'))
  5151. {
  5152. putNumbersInBrackets = true;
  5153. const int openBracks = prefix.lastIndexOfChar ('(');
  5154. const int closeBracks = prefix.lastIndexOfChar (')');
  5155. if (openBracks > 0
  5156. && closeBracks > openBracks
  5157. && prefix.substring (openBracks + 1, closeBracks).containsOnly (T("0123456789")))
  5158. {
  5159. num = prefix.substring (openBracks + 1, closeBracks).getIntValue() + 1;
  5160. prefix = prefix.substring (0, openBracks);
  5161. }
  5162. }
  5163. // also use brackets if it ends in a digit.
  5164. putNumbersInBrackets = putNumbersInBrackets
  5165. || CharacterFunctions::isDigit (prefix.getLastCharacter());
  5166. do
  5167. {
  5168. if (putNumbersInBrackets)
  5169. f = getChildFile (prefix + '(' + String (num++) + ')' + suffix);
  5170. else
  5171. f = getChildFile (prefix + String (num++) + suffix);
  5172. } while (f.exists());
  5173. }
  5174. return f;
  5175. }
  5176. const File File::getNonexistentSibling (const bool putNumbersInBrackets) const
  5177. {
  5178. if (exists())
  5179. {
  5180. return getParentDirectory()
  5181. .getNonexistentChildFile (getFileNameWithoutExtension(),
  5182. getFileExtension(),
  5183. putNumbersInBrackets);
  5184. }
  5185. else
  5186. {
  5187. return *this;
  5188. }
  5189. }
  5190. const String File::getFileExtension() const
  5191. {
  5192. String ext;
  5193. if (! isDirectory())
  5194. {
  5195. const int indexOfDot = fullPath.lastIndexOfChar ('.');
  5196. if (indexOfDot > fullPath.lastIndexOfChar (separator))
  5197. ext = fullPath.substring (indexOfDot);
  5198. }
  5199. return ext;
  5200. }
  5201. bool File::hasFileExtension (const String& possibleSuffix) const
  5202. {
  5203. if (possibleSuffix.isEmpty())
  5204. return fullPath.lastIndexOfChar ('.') <= fullPath.lastIndexOfChar (separator);
  5205. const int semicolon = possibleSuffix.indexOfChar (0, ';');
  5206. if (semicolon >= 0)
  5207. {
  5208. return hasFileExtension (possibleSuffix.substring (0, semicolon).trimEnd())
  5209. || hasFileExtension (possibleSuffix.substring (semicolon + 1).trimStart());
  5210. }
  5211. else
  5212. {
  5213. if (fullPath.endsWithIgnoreCase (possibleSuffix))
  5214. {
  5215. if (possibleSuffix.startsWithChar ('.'))
  5216. return true;
  5217. const int dotPos = fullPath.length() - possibleSuffix.length() - 1;
  5218. if (dotPos >= 0)
  5219. return fullPath [dotPos] == '.';
  5220. }
  5221. }
  5222. return false;
  5223. }
  5224. const File File::withFileExtension (const String& newExtension) const
  5225. {
  5226. if (fullPath.isEmpty())
  5227. return File::nonexistent;
  5228. String filePart (getFileName());
  5229. int i = filePart.lastIndexOfChar ('.');
  5230. if (i >= 0)
  5231. filePart = filePart.substring (0, i);
  5232. if (newExtension.isNotEmpty() && ! newExtension.startsWithChar ('.'))
  5233. filePart << '.';
  5234. return getSiblingFile (filePart + newExtension);
  5235. }
  5236. bool File::startAsProcess (const String& parameters) const
  5237. {
  5238. return exists() && juce_launchFile (fullPath, parameters);
  5239. }
  5240. FileInputStream* File::createInputStream() const
  5241. {
  5242. if (existsAsFile())
  5243. return new FileInputStream (*this);
  5244. return 0;
  5245. }
  5246. FileOutputStream* File::createOutputStream (const int bufferSize) const
  5247. {
  5248. ScopedPointer <FileOutputStream> out (new FileOutputStream (*this, bufferSize));
  5249. if (out->failedToOpen())
  5250. return 0;
  5251. return out.release();
  5252. }
  5253. bool File::appendData (const void* const dataToAppend,
  5254. const int numberOfBytes) const
  5255. {
  5256. if (numberOfBytes > 0)
  5257. {
  5258. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5259. if (out == 0)
  5260. return false;
  5261. out->write (dataToAppend, numberOfBytes);
  5262. }
  5263. return true;
  5264. }
  5265. bool File::replaceWithData (const void* const dataToWrite,
  5266. const int numberOfBytes) const
  5267. {
  5268. jassert (numberOfBytes >= 0); // a negative number of bytes??
  5269. if (numberOfBytes <= 0)
  5270. return deleteFile();
  5271. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5272. tempFile.getFile().appendData (dataToWrite, numberOfBytes);
  5273. return tempFile.overwriteTargetFileWithTemporary();
  5274. }
  5275. bool File::appendText (const String& text,
  5276. const bool asUnicode,
  5277. const bool writeUnicodeHeaderBytes) const
  5278. {
  5279. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5280. if (out != 0)
  5281. {
  5282. out->writeText (text, asUnicode, writeUnicodeHeaderBytes);
  5283. return true;
  5284. }
  5285. return false;
  5286. }
  5287. bool File::replaceWithText (const String& textToWrite,
  5288. const bool asUnicode,
  5289. const bool writeUnicodeHeaderBytes) const
  5290. {
  5291. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5292. tempFile.getFile().appendText (textToWrite, asUnicode, writeUnicodeHeaderBytes);
  5293. return tempFile.overwriteTargetFileWithTemporary();
  5294. }
  5295. const String File::createLegalPathName (const String& original)
  5296. {
  5297. String s (original);
  5298. String start;
  5299. if (s[1] == ':')
  5300. {
  5301. start = s.substring (0, 2);
  5302. s = s.substring (2);
  5303. }
  5304. return start + s.removeCharacters (T("\"#@,;:<>*^|?"))
  5305. .substring (0, 1024);
  5306. }
  5307. const String File::createLegalFileName (const String& original)
  5308. {
  5309. String s (original.removeCharacters (T("\"#@,;:<>*^|?\\/")));
  5310. const int maxLength = 128; // only the length of the filename, not the whole path
  5311. const int len = s.length();
  5312. if (len > maxLength)
  5313. {
  5314. const int lastDot = s.lastIndexOfChar ('.');
  5315. if (lastDot > jmax (0, len - 12))
  5316. {
  5317. s = s.substring (0, maxLength - (len - lastDot))
  5318. + s.substring (lastDot);
  5319. }
  5320. else
  5321. {
  5322. s = s.substring (0, maxLength);
  5323. }
  5324. }
  5325. return s;
  5326. }
  5327. const String File::getRelativePathFrom (const File& dir) const
  5328. {
  5329. String thisPath (fullPath);
  5330. {
  5331. int len = thisPath.length();
  5332. while (--len >= 0 && thisPath [len] == File::separator)
  5333. thisPath [len] = 0;
  5334. }
  5335. String dirPath (juce_addTrailingSeparator ((dir.existsAsFile()) ? dir.getParentDirectory().getFullPathName()
  5336. : dir.fullPath));
  5337. const int len = jmin (thisPath.length(), dirPath.length());
  5338. int commonBitLength = 0;
  5339. for (int i = 0; i < len; ++i)
  5340. {
  5341. #if NAMES_ARE_CASE_SENSITIVE
  5342. if (thisPath[i] != dirPath[i])
  5343. #else
  5344. if (CharacterFunctions::toLowerCase (thisPath[i])
  5345. != CharacterFunctions::toLowerCase (dirPath[i]))
  5346. #endif
  5347. {
  5348. break;
  5349. }
  5350. ++commonBitLength;
  5351. }
  5352. while (commonBitLength > 0 && thisPath [commonBitLength - 1] != File::separator)
  5353. --commonBitLength;
  5354. // if the only common bit is the root, then just return the full path..
  5355. if (commonBitLength <= 0
  5356. || (commonBitLength == 1 && thisPath [1] == File::separator))
  5357. return fullPath;
  5358. thisPath = thisPath.substring (commonBitLength);
  5359. dirPath = dirPath.substring (commonBitLength);
  5360. while (dirPath.isNotEmpty())
  5361. {
  5362. #if JUCE_WINDOWS
  5363. thisPath = "..\\" + thisPath;
  5364. #else
  5365. thisPath = "../" + thisPath;
  5366. #endif
  5367. const int sep = dirPath.indexOfChar (separator);
  5368. if (sep >= 0)
  5369. dirPath = dirPath.substring (sep + 1);
  5370. else
  5371. dirPath = String::empty;
  5372. }
  5373. return thisPath;
  5374. }
  5375. void File::findFileSystemRoots (Array<File>& destArray)
  5376. {
  5377. const StringArray roots (juce_getFileSystemRoots());
  5378. for (int i = 0; i < roots.size(); ++i)
  5379. destArray.add (File (roots[i]));
  5380. }
  5381. const String File::getVolumeLabel() const
  5382. {
  5383. int serialNum;
  5384. return juce_getVolumeLabel (fullPath, serialNum);
  5385. }
  5386. int File::getVolumeSerialNumber() const
  5387. {
  5388. int serialNum;
  5389. juce_getVolumeLabel (fullPath, serialNum);
  5390. return serialNum;
  5391. }
  5392. const File File::createTempFile (const String& fileNameEnding)
  5393. {
  5394. const File tempFile (getSpecialLocation (tempDirectory)
  5395. .getChildFile ("temp_" + String (Random::getSystemRandom().nextInt()))
  5396. .withFileExtension (fileNameEnding));
  5397. if (tempFile.exists())
  5398. return createTempFile (fileNameEnding);
  5399. else
  5400. return tempFile;
  5401. }
  5402. END_JUCE_NAMESPACE
  5403. /*** End of inlined file: juce_File.cpp ***/
  5404. /*** Start of inlined file: juce_FileInputStream.cpp ***/
  5405. BEGIN_JUCE_NAMESPACE
  5406. void* juce_fileOpen (const String& path, bool forWriting);
  5407. void juce_fileClose (void* handle);
  5408. int juce_fileRead (void* handle, void* buffer, int size);
  5409. int64 juce_fileSetPosition (void* handle, int64 pos);
  5410. FileInputStream::FileInputStream (const File& f)
  5411. : file (f),
  5412. currentPosition (0),
  5413. needToSeek (true)
  5414. {
  5415. totalSize = f.getSize();
  5416. fileHandle = juce_fileOpen (f.getFullPathName(), false);
  5417. }
  5418. FileInputStream::~FileInputStream()
  5419. {
  5420. juce_fileClose (fileHandle);
  5421. }
  5422. int64 FileInputStream::getTotalLength()
  5423. {
  5424. return totalSize;
  5425. }
  5426. int FileInputStream::read (void* buffer, int bytesToRead)
  5427. {
  5428. int num = 0;
  5429. if (needToSeek)
  5430. {
  5431. if (juce_fileSetPosition (fileHandle, currentPosition) < 0)
  5432. return 0;
  5433. needToSeek = false;
  5434. }
  5435. num = juce_fileRead (fileHandle, buffer, bytesToRead);
  5436. currentPosition += num;
  5437. return num;
  5438. }
  5439. bool FileInputStream::isExhausted()
  5440. {
  5441. return currentPosition >= totalSize;
  5442. }
  5443. int64 FileInputStream::getPosition()
  5444. {
  5445. return currentPosition;
  5446. }
  5447. bool FileInputStream::setPosition (int64 pos)
  5448. {
  5449. pos = jlimit ((int64) 0, totalSize, pos);
  5450. needToSeek |= (currentPosition != pos);
  5451. currentPosition = pos;
  5452. return true;
  5453. }
  5454. END_JUCE_NAMESPACE
  5455. /*** End of inlined file: juce_FileInputStream.cpp ***/
  5456. /*** Start of inlined file: juce_FileOutputStream.cpp ***/
  5457. BEGIN_JUCE_NAMESPACE
  5458. void* juce_fileOpen (const String& path, bool forWriting);
  5459. void juce_fileClose (void* handle);
  5460. int juce_fileWrite (void* handle, const void* buffer, int size);
  5461. void juce_fileFlush (void* handle);
  5462. int64 juce_fileGetPosition (void* handle);
  5463. int64 juce_fileSetPosition (void* handle, int64 pos);
  5464. FileOutputStream::FileOutputStream (const File& f,
  5465. const int bufferSize_)
  5466. : file (f),
  5467. bufferSize (bufferSize_),
  5468. bytesInBuffer (0)
  5469. {
  5470. fileHandle = juce_fileOpen (f.getFullPathName(), true);
  5471. if (fileHandle != 0)
  5472. {
  5473. currentPosition = juce_fileGetPosition (fileHandle);
  5474. if (currentPosition < 0)
  5475. {
  5476. jassertfalse
  5477. juce_fileClose (fileHandle);
  5478. fileHandle = 0;
  5479. }
  5480. }
  5481. buffer.malloc (jmax (bufferSize_, 16));
  5482. }
  5483. FileOutputStream::~FileOutputStream()
  5484. {
  5485. flush();
  5486. juce_fileClose (fileHandle);
  5487. }
  5488. int64 FileOutputStream::getPosition()
  5489. {
  5490. return currentPosition;
  5491. }
  5492. bool FileOutputStream::setPosition (int64 newPosition)
  5493. {
  5494. if (newPosition != currentPosition)
  5495. {
  5496. flush();
  5497. currentPosition = juce_fileSetPosition (fileHandle, newPosition);
  5498. }
  5499. return newPosition == currentPosition;
  5500. }
  5501. void FileOutputStream::flush()
  5502. {
  5503. if (bytesInBuffer > 0)
  5504. {
  5505. juce_fileWrite (fileHandle, buffer, bytesInBuffer);
  5506. bytesInBuffer = 0;
  5507. }
  5508. juce_fileFlush (fileHandle);
  5509. }
  5510. bool FileOutputStream::write (const void* const src, const int numBytes)
  5511. {
  5512. if (bytesInBuffer + numBytes < bufferSize)
  5513. {
  5514. memcpy (buffer + bytesInBuffer, src, numBytes);
  5515. bytesInBuffer += numBytes;
  5516. currentPosition += numBytes;
  5517. }
  5518. else
  5519. {
  5520. if (bytesInBuffer > 0)
  5521. {
  5522. // flush the reservoir
  5523. const bool wroteOk = (juce_fileWrite (fileHandle, buffer, bytesInBuffer) == bytesInBuffer);
  5524. bytesInBuffer = 0;
  5525. if (! wroteOk)
  5526. return false;
  5527. }
  5528. if (numBytes < bufferSize)
  5529. {
  5530. memcpy (buffer + bytesInBuffer, src, numBytes);
  5531. bytesInBuffer += numBytes;
  5532. currentPosition += numBytes;
  5533. }
  5534. else
  5535. {
  5536. const int bytesWritten = juce_fileWrite (fileHandle, src, numBytes);
  5537. currentPosition += bytesWritten;
  5538. return bytesWritten == numBytes;
  5539. }
  5540. }
  5541. return true;
  5542. }
  5543. END_JUCE_NAMESPACE
  5544. /*** End of inlined file: juce_FileOutputStream.cpp ***/
  5545. /*** Start of inlined file: juce_FileSearchPath.cpp ***/
  5546. BEGIN_JUCE_NAMESPACE
  5547. FileSearchPath::FileSearchPath()
  5548. {
  5549. }
  5550. FileSearchPath::FileSearchPath (const String& path)
  5551. {
  5552. init (path);
  5553. }
  5554. FileSearchPath::FileSearchPath (const FileSearchPath& other)
  5555. : directories (other.directories)
  5556. {
  5557. }
  5558. FileSearchPath::~FileSearchPath()
  5559. {
  5560. }
  5561. FileSearchPath& FileSearchPath::operator= (const String& path)
  5562. {
  5563. init (path);
  5564. return *this;
  5565. }
  5566. void FileSearchPath::init (const String& path)
  5567. {
  5568. directories.clear();
  5569. directories.addTokens (path, ";", "\"");
  5570. directories.trim();
  5571. directories.removeEmptyStrings();
  5572. for (int i = directories.size(); --i >= 0;)
  5573. directories.set (i, directories[i].unquoted());
  5574. }
  5575. int FileSearchPath::getNumPaths() const
  5576. {
  5577. return directories.size();
  5578. }
  5579. const File FileSearchPath::operator[] (const int index) const
  5580. {
  5581. return File (directories [index]);
  5582. }
  5583. const String FileSearchPath::toString() const
  5584. {
  5585. StringArray directories2 (directories);
  5586. for (int i = directories2.size(); --i >= 0;)
  5587. if (directories2[i].containsChar (';'))
  5588. directories2.set (i, directories2[i].quoted());
  5589. return directories2.joinIntoString (";");
  5590. }
  5591. void FileSearchPath::add (const File& dir, const int insertIndex)
  5592. {
  5593. directories.insert (insertIndex, dir.getFullPathName());
  5594. }
  5595. void FileSearchPath::addIfNotAlreadyThere (const File& dir)
  5596. {
  5597. for (int i = 0; i < directories.size(); ++i)
  5598. if (File (directories[i]) == dir)
  5599. return;
  5600. add (dir);
  5601. }
  5602. void FileSearchPath::remove (const int index)
  5603. {
  5604. directories.remove (index);
  5605. }
  5606. void FileSearchPath::addPath (const FileSearchPath& other)
  5607. {
  5608. for (int i = 0; i < other.getNumPaths(); ++i)
  5609. addIfNotAlreadyThere (other[i]);
  5610. }
  5611. void FileSearchPath::removeRedundantPaths()
  5612. {
  5613. for (int i = directories.size(); --i >= 0;)
  5614. {
  5615. const File d1 (directories[i]);
  5616. for (int j = directories.size(); --j >= 0;)
  5617. {
  5618. const File d2 (directories[j]);
  5619. if ((i != j) && (d1.isAChildOf (d2) || d1 == d2))
  5620. {
  5621. directories.remove (i);
  5622. break;
  5623. }
  5624. }
  5625. }
  5626. }
  5627. void FileSearchPath::removeNonExistentPaths()
  5628. {
  5629. for (int i = directories.size(); --i >= 0;)
  5630. if (! File (directories[i]).isDirectory())
  5631. directories.remove (i);
  5632. }
  5633. int FileSearchPath::findChildFiles (Array<File>& results,
  5634. const int whatToLookFor,
  5635. const bool searchRecursively,
  5636. const String& wildCardPattern) const
  5637. {
  5638. int total = 0;
  5639. for (int i = 0; i < directories.size(); ++i)
  5640. total += operator[] (i).findChildFiles (results,
  5641. whatToLookFor,
  5642. searchRecursively,
  5643. wildCardPattern);
  5644. return total;
  5645. }
  5646. bool FileSearchPath::isFileInPath (const File& fileToCheck,
  5647. const bool checkRecursively) const
  5648. {
  5649. for (int i = directories.size(); --i >= 0;)
  5650. {
  5651. const File d (directories[i]);
  5652. if (checkRecursively)
  5653. {
  5654. if (fileToCheck.isAChildOf (d))
  5655. return true;
  5656. }
  5657. else
  5658. {
  5659. if (fileToCheck.getParentDirectory() == d)
  5660. return true;
  5661. }
  5662. }
  5663. return false;
  5664. }
  5665. END_JUCE_NAMESPACE
  5666. /*** End of inlined file: juce_FileSearchPath.cpp ***/
  5667. /*** Start of inlined file: juce_NamedPipe.cpp ***/
  5668. BEGIN_JUCE_NAMESPACE
  5669. NamedPipe::NamedPipe()
  5670. : internal (0)
  5671. {
  5672. }
  5673. NamedPipe::~NamedPipe()
  5674. {
  5675. close();
  5676. }
  5677. bool NamedPipe::openExisting (const String& pipeName)
  5678. {
  5679. currentPipeName = pipeName;
  5680. return openInternal (pipeName, false);
  5681. }
  5682. bool NamedPipe::createNewPipe (const String& pipeName)
  5683. {
  5684. currentPipeName = pipeName;
  5685. return openInternal (pipeName, true);
  5686. }
  5687. bool NamedPipe::isOpen() const
  5688. {
  5689. return internal != 0;
  5690. }
  5691. const String NamedPipe::getName() const
  5692. {
  5693. return currentPipeName;
  5694. }
  5695. // other methods for this class are implemented in the platform-specific files
  5696. END_JUCE_NAMESPACE
  5697. /*** End of inlined file: juce_NamedPipe.cpp ***/
  5698. /*** Start of inlined file: juce_TemporaryFile.cpp ***/
  5699. BEGIN_JUCE_NAMESPACE
  5700. TemporaryFile::TemporaryFile (const String& suffix, const int optionFlags)
  5701. {
  5702. createTempFile (File::getSpecialLocation (File::tempDirectory),
  5703. "temp_" + String (Random::getSystemRandom().nextInt()),
  5704. suffix,
  5705. optionFlags);
  5706. }
  5707. TemporaryFile::TemporaryFile (const File& targetFile_, const int optionFlags)
  5708. : targetFile (targetFile_)
  5709. {
  5710. // If you use this constructor, you need to give it a valid target file!
  5711. jassert (targetFile != File::nonexistent);
  5712. createTempFile (targetFile.getParentDirectory(),
  5713. targetFile.getFileNameWithoutExtension() + "_temp" + String (Random::getSystemRandom().nextInt()),
  5714. targetFile.getFileExtension(),
  5715. optionFlags);
  5716. }
  5717. void TemporaryFile::createTempFile (const File& parentDirectory, String name,
  5718. const String& suffix, const int optionFlags)
  5719. {
  5720. if ((optionFlags & useHiddenFile) != 0)
  5721. name = "." + name;
  5722. temporaryFile = parentDirectory.getNonexistentChildFile (name, suffix, (optionFlags & putNumbersInBrackets) != 0);
  5723. }
  5724. TemporaryFile::~TemporaryFile()
  5725. {
  5726. // Have a few attempts at deleting the file before giving up..
  5727. for (int i = 5; --i >= 0;)
  5728. {
  5729. if (temporaryFile.deleteFile())
  5730. return;
  5731. Thread::sleep (50);
  5732. }
  5733. // Failed to delete our temporary file! Check that you've deleted all the
  5734. // file output streams that were using it!
  5735. jassertfalse;
  5736. }
  5737. bool TemporaryFile::overwriteTargetFileWithTemporary() const
  5738. {
  5739. // This method only works if you created this object with the constructor
  5740. // that takes a target file!
  5741. jassert (targetFile != File::nonexistent);
  5742. if (temporaryFile.exists())
  5743. {
  5744. // Have a few attempts at overwriting the file before giving up..
  5745. for (int i = 5; --i >= 0;)
  5746. {
  5747. if (temporaryFile.moveFileTo (targetFile))
  5748. return true;
  5749. Thread::sleep (100);
  5750. }
  5751. }
  5752. else
  5753. {
  5754. // There's no temporary file to use. If your write failed, you should
  5755. // probably check, and not bother calling this method.
  5756. jassertfalse
  5757. }
  5758. return false;
  5759. }
  5760. END_JUCE_NAMESPACE
  5761. /*** End of inlined file: juce_TemporaryFile.cpp ***/
  5762. /*** Start of inlined file: juce_Socket.cpp ***/
  5763. #if JUCE_WINDOWS
  5764. #include <winsock2.h>
  5765. #ifdef _MSC_VER
  5766. #pragma warning (disable : 4127 4389 4018)
  5767. #endif
  5768. #else
  5769. #if JUCE_LINUX
  5770. #include <sys/types.h>
  5771. #include <sys/socket.h>
  5772. #include <sys/errno.h>
  5773. #include <unistd.h>
  5774. #include <netinet/in.h>
  5775. #elif (MACOSX_DEPLOYMENT_TARGET <= MAC_OS_X_VERSION_10_4) && ! JUCE_IPHONE
  5776. #include <CoreServices/CoreServices.h>
  5777. #endif
  5778. #include <fcntl.h>
  5779. #include <netdb.h>
  5780. #include <arpa/inet.h>
  5781. #include <netinet/tcp.h>
  5782. #endif
  5783. BEGIN_JUCE_NAMESPACE
  5784. #if defined (JUCE_LINUX) || defined (JUCE_MAC) || defined (JUCE_IPHONE)
  5785. typedef socklen_t juce_socklen_t;
  5786. #else
  5787. typedef int juce_socklen_t;
  5788. #endif
  5789. #if JUCE_WINDOWS
  5790. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  5791. juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib = 0;
  5792. static void initWin32Sockets()
  5793. {
  5794. static CriticalSection lock;
  5795. const ScopedLock sl (lock);
  5796. if (juce_CloseWin32SocketLib == 0)
  5797. {
  5798. WSADATA wsaData;
  5799. const WORD wVersionRequested = MAKEWORD (1, 1);
  5800. WSAStartup (wVersionRequested, &wsaData);
  5801. juce_CloseWin32SocketLib = &WSACleanup;
  5802. }
  5803. }
  5804. #endif
  5805. static bool resetSocketOptions (const int handle, const bool isDatagram, const bool allowBroadcast) throw()
  5806. {
  5807. const int sndBufSize = 65536;
  5808. const int rcvBufSize = 65536;
  5809. const int one = 1;
  5810. return handle > 0
  5811. && setsockopt (handle, SOL_SOCKET, SO_RCVBUF, (const char*) &rcvBufSize, sizeof (rcvBufSize)) == 0
  5812. && setsockopt (handle, SOL_SOCKET, SO_SNDBUF, (const char*) &sndBufSize, sizeof (sndBufSize)) == 0
  5813. && (isDatagram ? ((! allowBroadcast) || setsockopt (handle, SOL_SOCKET, SO_BROADCAST, (const char*) &one, sizeof (one)) == 0)
  5814. : (setsockopt (handle, IPPROTO_TCP, TCP_NODELAY, (const char*) &one, sizeof (one)) == 0));
  5815. }
  5816. static bool bindSocketToPort (const int handle, const int port) throw()
  5817. {
  5818. if (handle <= 0 || port <= 0)
  5819. return false;
  5820. struct sockaddr_in servTmpAddr;
  5821. zerostruct (servTmpAddr);
  5822. servTmpAddr.sin_family = PF_INET;
  5823. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  5824. servTmpAddr.sin_port = htons ((uint16) port);
  5825. return bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) >= 0;
  5826. }
  5827. static int readSocket (const int handle,
  5828. void* const destBuffer, const int maxBytesToRead,
  5829. bool volatile& connected,
  5830. const bool blockUntilSpecifiedAmountHasArrived) throw()
  5831. {
  5832. int bytesRead = 0;
  5833. while (bytesRead < maxBytesToRead)
  5834. {
  5835. int bytesThisTime;
  5836. #if JUCE_WINDOWS
  5837. bytesThisTime = recv (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead, 0);
  5838. #else
  5839. while ((bytesThisTime = (int) ::read (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead)) < 0
  5840. && errno == EINTR
  5841. && connected)
  5842. {
  5843. }
  5844. #endif
  5845. if (bytesThisTime <= 0 || ! connected)
  5846. {
  5847. if (bytesRead == 0)
  5848. bytesRead = -1;
  5849. break;
  5850. }
  5851. bytesRead += bytesThisTime;
  5852. if (! blockUntilSpecifiedAmountHasArrived)
  5853. break;
  5854. }
  5855. return bytesRead;
  5856. }
  5857. static int waitForReadiness (const int handle, const bool forReading,
  5858. const int timeoutMsecs) throw()
  5859. {
  5860. struct timeval timeout;
  5861. struct timeval* timeoutp;
  5862. if (timeoutMsecs >= 0)
  5863. {
  5864. timeout.tv_sec = timeoutMsecs / 1000;
  5865. timeout.tv_usec = (timeoutMsecs % 1000) * 1000;
  5866. timeoutp = &timeout;
  5867. }
  5868. else
  5869. {
  5870. timeoutp = 0;
  5871. }
  5872. fd_set rset, wset;
  5873. FD_ZERO (&rset);
  5874. FD_SET (handle, &rset);
  5875. FD_ZERO (&wset);
  5876. FD_SET (handle, &wset);
  5877. fd_set* const prset = forReading ? &rset : 0;
  5878. fd_set* const pwset = forReading ? 0 : &wset;
  5879. #if JUCE_WINDOWS
  5880. if (select (handle + 1, prset, pwset, 0, timeoutp) < 0)
  5881. return -1;
  5882. #else
  5883. {
  5884. int result;
  5885. while ((result = select (handle + 1, prset, pwset, 0, timeoutp)) < 0
  5886. && errno == EINTR)
  5887. {
  5888. }
  5889. if (result < 0)
  5890. return -1;
  5891. }
  5892. #endif
  5893. {
  5894. int opt;
  5895. juce_socklen_t len = sizeof (opt);
  5896. if (getsockopt (handle, SOL_SOCKET, SO_ERROR, (char*) &opt, &len) < 0
  5897. || opt != 0)
  5898. return -1;
  5899. }
  5900. if ((forReading && FD_ISSET (handle, &rset))
  5901. || ((! forReading) && FD_ISSET (handle, &wset)))
  5902. return 1;
  5903. return 0;
  5904. }
  5905. static bool setSocketBlockingState (const int handle, const bool shouldBlock) throw()
  5906. {
  5907. #if JUCE_WINDOWS
  5908. u_long nonBlocking = shouldBlock ? 0 : 1;
  5909. if (ioctlsocket (handle, FIONBIO, &nonBlocking) != 0)
  5910. return false;
  5911. #else
  5912. int socketFlags = fcntl (handle, F_GETFL, 0);
  5913. if (socketFlags == -1)
  5914. return false;
  5915. if (shouldBlock)
  5916. socketFlags &= ~O_NONBLOCK;
  5917. else
  5918. socketFlags |= O_NONBLOCK;
  5919. if (fcntl (handle, F_SETFL, socketFlags) != 0)
  5920. return false;
  5921. #endif
  5922. return true;
  5923. }
  5924. static bool connectSocket (int volatile& handle,
  5925. const bool isDatagram,
  5926. void** serverAddress,
  5927. const String& hostName,
  5928. const int portNumber,
  5929. const int timeOutMillisecs) throw()
  5930. {
  5931. struct hostent* const hostEnt = gethostbyname (hostName.toUTF8());
  5932. if (hostEnt == 0)
  5933. return false;
  5934. struct in_addr targetAddress;
  5935. memcpy (&targetAddress.s_addr,
  5936. *(hostEnt->h_addr_list),
  5937. sizeof (targetAddress.s_addr));
  5938. struct sockaddr_in servTmpAddr;
  5939. zerostruct (servTmpAddr);
  5940. servTmpAddr.sin_family = PF_INET;
  5941. servTmpAddr.sin_addr = targetAddress;
  5942. servTmpAddr.sin_port = htons ((uint16) portNumber);
  5943. if (handle < 0)
  5944. handle = (int) socket (AF_INET, isDatagram ? SOCK_DGRAM : SOCK_STREAM, 0);
  5945. if (handle < 0)
  5946. return false;
  5947. if (isDatagram)
  5948. {
  5949. *serverAddress = new struct sockaddr_in();
  5950. *((struct sockaddr_in*) *serverAddress) = servTmpAddr;
  5951. return true;
  5952. }
  5953. setSocketBlockingState (handle, false);
  5954. const int result = ::connect (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in));
  5955. if (result < 0)
  5956. {
  5957. #if JUCE_WINDOWS
  5958. if (result == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK)
  5959. #else
  5960. if (errno == EINPROGRESS)
  5961. #endif
  5962. {
  5963. if (waitForReadiness (handle, false, timeOutMillisecs) != 1)
  5964. {
  5965. setSocketBlockingState (handle, true);
  5966. return false;
  5967. }
  5968. }
  5969. }
  5970. setSocketBlockingState (handle, true);
  5971. resetSocketOptions (handle, false, false);
  5972. return true;
  5973. }
  5974. StreamingSocket::StreamingSocket()
  5975. : portNumber (0),
  5976. handle (-1),
  5977. connected (false),
  5978. isListener (false)
  5979. {
  5980. #if JUCE_WINDOWS
  5981. initWin32Sockets();
  5982. #endif
  5983. }
  5984. StreamingSocket::StreamingSocket (const String& hostName_,
  5985. const int portNumber_,
  5986. const int handle_)
  5987. : hostName (hostName_),
  5988. portNumber (portNumber_),
  5989. handle (handle_),
  5990. connected (true),
  5991. isListener (false)
  5992. {
  5993. #if JUCE_WINDOWS
  5994. initWin32Sockets();
  5995. #endif
  5996. resetSocketOptions (handle_, false, false);
  5997. }
  5998. StreamingSocket::~StreamingSocket()
  5999. {
  6000. close();
  6001. }
  6002. int StreamingSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  6003. {
  6004. return (connected && ! isListener) ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  6005. : -1;
  6006. }
  6007. int StreamingSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  6008. {
  6009. if (isListener || ! connected)
  6010. return -1;
  6011. #if JUCE_WINDOWS
  6012. return send (handle, (const char*) sourceBuffer, numBytesToWrite, 0);
  6013. #else
  6014. int result;
  6015. while ((result = (int) ::write (handle, sourceBuffer, numBytesToWrite)) < 0
  6016. && errno == EINTR)
  6017. {
  6018. }
  6019. return result;
  6020. #endif
  6021. }
  6022. int StreamingSocket::waitUntilReady (const bool readyForReading,
  6023. const int timeoutMsecs) const
  6024. {
  6025. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  6026. : -1;
  6027. }
  6028. bool StreamingSocket::bindToPort (const int port)
  6029. {
  6030. return bindSocketToPort (handle, port);
  6031. }
  6032. bool StreamingSocket::connect (const String& remoteHostName,
  6033. const int remotePortNumber,
  6034. const int timeOutMillisecs)
  6035. {
  6036. if (isListener)
  6037. {
  6038. jassertfalse // a listener socket can't connect to another one!
  6039. return false;
  6040. }
  6041. if (connected)
  6042. close();
  6043. hostName = remoteHostName;
  6044. portNumber = remotePortNumber;
  6045. isListener = false;
  6046. connected = connectSocket (handle, false, 0, remoteHostName,
  6047. remotePortNumber, timeOutMillisecs);
  6048. if (! (connected && resetSocketOptions (handle, false, false)))
  6049. {
  6050. close();
  6051. return false;
  6052. }
  6053. return true;
  6054. }
  6055. void StreamingSocket::close()
  6056. {
  6057. #if JUCE_WINDOWS
  6058. closesocket (handle);
  6059. connected = false;
  6060. #else
  6061. if (connected)
  6062. {
  6063. connected = false;
  6064. if (isListener)
  6065. {
  6066. // need to do this to interrupt the accept() function..
  6067. StreamingSocket temp;
  6068. temp.connect ("localhost", portNumber, 1000);
  6069. }
  6070. }
  6071. ::close (handle);
  6072. #endif
  6073. hostName = String::empty;
  6074. portNumber = 0;
  6075. handle = -1;
  6076. isListener = false;
  6077. }
  6078. bool StreamingSocket::createListener (const int newPortNumber, const String& localHostName)
  6079. {
  6080. if (connected)
  6081. close();
  6082. hostName = "listener";
  6083. portNumber = newPortNumber;
  6084. isListener = true;
  6085. struct sockaddr_in servTmpAddr;
  6086. zerostruct (servTmpAddr);
  6087. servTmpAddr.sin_family = PF_INET;
  6088. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  6089. if (localHostName.isNotEmpty())
  6090. servTmpAddr.sin_addr.s_addr = ::inet_addr (localHostName.toUTF8());
  6091. servTmpAddr.sin_port = htons ((uint16) portNumber);
  6092. handle = (int) socket (AF_INET, SOCK_STREAM, 0);
  6093. if (handle < 0)
  6094. return false;
  6095. const int reuse = 1;
  6096. setsockopt (handle, SOL_SOCKET, SO_REUSEADDR, (const char*) &reuse, sizeof (reuse));
  6097. if (bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) < 0
  6098. || listen (handle, SOMAXCONN) < 0)
  6099. {
  6100. close();
  6101. return false;
  6102. }
  6103. connected = true;
  6104. return true;
  6105. }
  6106. StreamingSocket* StreamingSocket::waitForNextConnection() const
  6107. {
  6108. jassert (isListener || ! connected); // to call this method, you first have to use createListener() to
  6109. // prepare this socket as a listener.
  6110. if (connected && isListener)
  6111. {
  6112. struct sockaddr address;
  6113. juce_socklen_t len = sizeof (sockaddr);
  6114. const int newSocket = (int) accept (handle, &address, &len);
  6115. if (newSocket >= 0 && connected)
  6116. return new StreamingSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6117. portNumber, newSocket);
  6118. }
  6119. return 0;
  6120. }
  6121. bool StreamingSocket::isLocal() const throw()
  6122. {
  6123. return hostName == "127.0.0.1";
  6124. }
  6125. DatagramSocket::DatagramSocket (const int localPortNumber, const bool allowBroadcast_)
  6126. : portNumber (0),
  6127. handle (-1),
  6128. connected (true),
  6129. allowBroadcast (allowBroadcast_),
  6130. serverAddress (0)
  6131. {
  6132. #if JUCE_WINDOWS
  6133. initWin32Sockets();
  6134. #endif
  6135. handle = (int) socket (AF_INET, SOCK_DGRAM, 0);
  6136. bindToPort (localPortNumber);
  6137. }
  6138. DatagramSocket::DatagramSocket (const String& hostName_, const int portNumber_,
  6139. const int handle_, const int localPortNumber)
  6140. : hostName (hostName_),
  6141. portNumber (portNumber_),
  6142. handle (handle_),
  6143. connected (true),
  6144. allowBroadcast (false),
  6145. serverAddress (0)
  6146. {
  6147. #if JUCE_WINDOWS
  6148. initWin32Sockets();
  6149. #endif
  6150. resetSocketOptions (handle_, true, allowBroadcast);
  6151. bindToPort (localPortNumber);
  6152. }
  6153. DatagramSocket::~DatagramSocket()
  6154. {
  6155. close();
  6156. delete ((struct sockaddr_in*) serverAddress);
  6157. serverAddress = 0;
  6158. }
  6159. void DatagramSocket::close()
  6160. {
  6161. #if JUCE_WINDOWS
  6162. closesocket (handle);
  6163. connected = false;
  6164. #else
  6165. connected = false;
  6166. ::close (handle);
  6167. #endif
  6168. hostName = String::empty;
  6169. portNumber = 0;
  6170. handle = -1;
  6171. }
  6172. bool DatagramSocket::bindToPort (const int port)
  6173. {
  6174. return bindSocketToPort (handle, port);
  6175. }
  6176. bool DatagramSocket::connect (const String& remoteHostName,
  6177. const int remotePortNumber,
  6178. const int timeOutMillisecs)
  6179. {
  6180. if (connected)
  6181. close();
  6182. hostName = remoteHostName;
  6183. portNumber = remotePortNumber;
  6184. connected = connectSocket (handle, true, &serverAddress,
  6185. remoteHostName, remotePortNumber,
  6186. timeOutMillisecs);
  6187. if (! (connected && resetSocketOptions (handle, true, allowBroadcast)))
  6188. {
  6189. close();
  6190. return false;
  6191. }
  6192. return true;
  6193. }
  6194. DatagramSocket* DatagramSocket::waitForNextConnection() const
  6195. {
  6196. struct sockaddr address;
  6197. juce_socklen_t len = sizeof (sockaddr);
  6198. while (waitUntilReady (true, -1) == 1)
  6199. {
  6200. char buf[1];
  6201. if (recvfrom (handle, buf, 0, 0, &address, &len) > 0)
  6202. {
  6203. return new DatagramSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6204. ntohs (((struct sockaddr_in*) &address)->sin_port),
  6205. -1, -1);
  6206. }
  6207. }
  6208. return 0;
  6209. }
  6210. int DatagramSocket::waitUntilReady (const bool readyForReading,
  6211. const int timeoutMsecs) const
  6212. {
  6213. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  6214. : -1;
  6215. }
  6216. int DatagramSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  6217. {
  6218. return connected ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  6219. : -1;
  6220. }
  6221. int DatagramSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  6222. {
  6223. // You need to call connect() first to set the server address..
  6224. jassert (serverAddress != 0 && connected);
  6225. return connected ? (int) sendto (handle, (const char*) sourceBuffer,
  6226. numBytesToWrite, 0,
  6227. (const struct sockaddr*) serverAddress,
  6228. sizeof (struct sockaddr_in))
  6229. : -1;
  6230. }
  6231. bool DatagramSocket::isLocal() const throw()
  6232. {
  6233. return hostName == "127.0.0.1";
  6234. }
  6235. END_JUCE_NAMESPACE
  6236. /*** End of inlined file: juce_Socket.cpp ***/
  6237. /*** Start of inlined file: juce_URL.cpp ***/
  6238. BEGIN_JUCE_NAMESPACE
  6239. URL::URL()
  6240. {
  6241. }
  6242. URL::URL (const String& url_)
  6243. : url (url_)
  6244. {
  6245. int i = url.indexOfChar ('?');
  6246. if (i >= 0)
  6247. {
  6248. do
  6249. {
  6250. const int nextAmp = url.indexOfChar (i + 1, '&');
  6251. const int equalsPos = url.indexOfChar (i + 1, '=');
  6252. if (equalsPos > i + 1)
  6253. {
  6254. if (nextAmp < 0)
  6255. {
  6256. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6257. removeEscapeChars (url.substring (equalsPos + 1)));
  6258. }
  6259. else if (nextAmp > 0 && equalsPos < nextAmp)
  6260. {
  6261. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6262. removeEscapeChars (url.substring (equalsPos + 1, nextAmp)));
  6263. }
  6264. }
  6265. i = nextAmp;
  6266. }
  6267. while (i >= 0);
  6268. url = url.upToFirstOccurrenceOf (T("?"), false, false);
  6269. }
  6270. }
  6271. URL::URL (const URL& other)
  6272. : url (other.url),
  6273. postData (other.postData),
  6274. parameters (other.parameters),
  6275. filesToUpload (other.filesToUpload),
  6276. mimeTypes (other.mimeTypes)
  6277. {
  6278. }
  6279. URL& URL::operator= (const URL& other)
  6280. {
  6281. url = other.url;
  6282. postData = other.postData;
  6283. parameters = other.parameters;
  6284. filesToUpload = other.filesToUpload;
  6285. mimeTypes = other.mimeTypes;
  6286. return *this;
  6287. }
  6288. URL::~URL()
  6289. {
  6290. }
  6291. static const String getMangledParameters (const StringPairArray& parameters)
  6292. {
  6293. String p;
  6294. for (int i = 0; i < parameters.size(); ++i)
  6295. {
  6296. if (i > 0)
  6297. p += '&';
  6298. p << URL::addEscapeChars (parameters.getAllKeys() [i], true)
  6299. << '='
  6300. << URL::addEscapeChars (parameters.getAllValues() [i], true);
  6301. }
  6302. return p;
  6303. }
  6304. const String URL::toString (const bool includeGetParameters) const
  6305. {
  6306. if (includeGetParameters && parameters.size() > 0)
  6307. return url + "?" + getMangledParameters (parameters);
  6308. else
  6309. return url;
  6310. }
  6311. bool URL::isWellFormed() const
  6312. {
  6313. //xxx TODO
  6314. return url.isNotEmpty();
  6315. }
  6316. static int findStartOfDomain (const String& url)
  6317. {
  6318. int i = 0;
  6319. while (CharacterFunctions::isLetterOrDigit (url[i])
  6320. || CharacterFunctions::indexOfChar (T("+-."), url[i], false) >= 0)
  6321. ++i;
  6322. return url[i] == ':' ? i + 1 : 0;
  6323. }
  6324. const String URL::getDomain() const
  6325. {
  6326. int start = findStartOfDomain (url);
  6327. while (url[start] == '/')
  6328. ++start;
  6329. const int end1 = url.indexOfChar (start, '/');
  6330. const int end2 = url.indexOfChar (start, ':');
  6331. const int end = (end1 < 0 || end2 < 0) ? jmax (end1, end2)
  6332. : jmin (end1, end2);
  6333. return url.substring (start, end);
  6334. }
  6335. const String URL::getSubPath() const
  6336. {
  6337. int start = findStartOfDomain (url);
  6338. while (url[start] == '/')
  6339. ++start;
  6340. const int startOfPath = url.indexOfChar (start, '/') + 1;
  6341. return startOfPath <= 0 ? String::empty
  6342. : url.substring (startOfPath);
  6343. }
  6344. const String URL::getScheme() const
  6345. {
  6346. return url.substring (0, findStartOfDomain (url) - 1);
  6347. }
  6348. const URL URL::withNewSubPath (const String& newPath) const
  6349. {
  6350. int start = findStartOfDomain (url);
  6351. while (url[start] == '/')
  6352. ++start;
  6353. const int startOfPath = url.indexOfChar (start, '/') + 1;
  6354. URL u (*this);
  6355. if (startOfPath > 0)
  6356. u.url = url.substring (0, startOfPath);
  6357. if (! u.url.endsWithChar ('/'))
  6358. u.url << '/';
  6359. if (newPath.startsWithChar ('/'))
  6360. u.url << newPath.substring (1);
  6361. else
  6362. u.url << newPath;
  6363. return u;
  6364. }
  6365. bool URL::isProbablyAWebsiteURL (const String& possibleURL)
  6366. {
  6367. if (possibleURL.startsWithIgnoreCase (T("http:"))
  6368. || possibleURL.startsWithIgnoreCase (T("ftp:")))
  6369. return true;
  6370. if (possibleURL.startsWithIgnoreCase (T("file:"))
  6371. || possibleURL.containsChar ('@')
  6372. || possibleURL.endsWithChar ('.')
  6373. || (! possibleURL.containsChar ('.')))
  6374. return false;
  6375. if (possibleURL.startsWithIgnoreCase (T("www."))
  6376. && possibleURL.substring (5).containsChar ('.'))
  6377. return true;
  6378. const char* commonTLDs[] = { "com", "net", "org", "uk", "de", "fr", "jp" };
  6379. for (int i = 0; i < numElementsInArray (commonTLDs); ++i)
  6380. if ((possibleURL + "/").containsIgnoreCase ("." + String (commonTLDs[i]) + "/"))
  6381. return true;
  6382. return false;
  6383. }
  6384. bool URL::isProbablyAnEmailAddress (const String& possibleEmailAddress)
  6385. {
  6386. const int atSign = possibleEmailAddress.indexOfChar ('@');
  6387. return atSign > 0
  6388. && possibleEmailAddress.lastIndexOfChar ('.') > (atSign + 1)
  6389. && (! possibleEmailAddress.endsWithChar ('.'));
  6390. }
  6391. void* juce_openInternetFile (const String& url,
  6392. const String& headers,
  6393. const MemoryBlock& optionalPostData,
  6394. const bool isPost,
  6395. URL::OpenStreamProgressCallback* callback,
  6396. void* callbackContext,
  6397. int timeOutMs);
  6398. void juce_closeInternetFile (void* handle);
  6399. int juce_readFromInternetFile (void* handle, void* dest, int bytesToRead);
  6400. int juce_seekInInternetFile (void* handle, int newPosition);
  6401. int64 juce_getInternetFileContentLength (void* handle);
  6402. class WebInputStream : public InputStream
  6403. {
  6404. public:
  6405. WebInputStream (const URL& url,
  6406. const bool isPost_,
  6407. URL::OpenStreamProgressCallback* const progressCallback_,
  6408. void* const progressCallbackContext_,
  6409. const String& extraHeaders,
  6410. int timeOutMs_)
  6411. : position (0),
  6412. finished (false),
  6413. isPost (isPost_),
  6414. progressCallback (progressCallback_),
  6415. progressCallbackContext (progressCallbackContext_),
  6416. timeOutMs (timeOutMs_)
  6417. {
  6418. server = url.toString (! isPost);
  6419. if (isPost_)
  6420. createHeadersAndPostData (url);
  6421. headers += extraHeaders;
  6422. if (! headers.endsWithChar ('\n'))
  6423. headers << "\r\n";
  6424. handle = juce_openInternetFile (server, headers, postData, isPost,
  6425. progressCallback_, progressCallbackContext_,
  6426. timeOutMs);
  6427. }
  6428. ~WebInputStream()
  6429. {
  6430. juce_closeInternetFile (handle);
  6431. }
  6432. bool isError() const
  6433. {
  6434. return handle == 0;
  6435. }
  6436. int64 getTotalLength()
  6437. {
  6438. return juce_getInternetFileContentLength (handle);
  6439. }
  6440. bool isExhausted()
  6441. {
  6442. return finished;
  6443. }
  6444. int read (void* dest, int bytes)
  6445. {
  6446. if (finished || isError())
  6447. {
  6448. return 0;
  6449. }
  6450. else
  6451. {
  6452. const int bytesRead = juce_readFromInternetFile (handle, dest, bytes);
  6453. position += bytesRead;
  6454. if (bytesRead == 0)
  6455. finished = true;
  6456. return bytesRead;
  6457. }
  6458. }
  6459. int64 getPosition()
  6460. {
  6461. return position;
  6462. }
  6463. bool setPosition (int64 wantedPos)
  6464. {
  6465. if (wantedPos != position)
  6466. {
  6467. finished = false;
  6468. const int actualPos = juce_seekInInternetFile (handle, (int) wantedPos);
  6469. if (actualPos == wantedPos)
  6470. {
  6471. position = wantedPos;
  6472. }
  6473. else
  6474. {
  6475. if (wantedPos < position)
  6476. {
  6477. juce_closeInternetFile (handle);
  6478. position = 0;
  6479. finished = false;
  6480. handle = juce_openInternetFile (server, headers, postData, isPost,
  6481. progressCallback, progressCallbackContext,
  6482. timeOutMs);
  6483. }
  6484. skipNextBytes (wantedPos - position);
  6485. }
  6486. }
  6487. return true;
  6488. }
  6489. juce_UseDebuggingNewOperator
  6490. private:
  6491. String server, headers;
  6492. MemoryBlock postData;
  6493. int64 position;
  6494. bool finished;
  6495. const bool isPost;
  6496. void* handle;
  6497. URL::OpenStreamProgressCallback* const progressCallback;
  6498. void* const progressCallbackContext;
  6499. const int timeOutMs;
  6500. void createHeadersAndPostData (const URL& url)
  6501. {
  6502. if (url.getFilesToUpload().size() > 0)
  6503. {
  6504. // need to upload some files, so do it as multi-part...
  6505. String boundary (String::toHexString (Random::getSystemRandom().nextInt64()));
  6506. headers << "Content-Type: multipart/form-data; boundary=" << boundary << "\r\n";
  6507. appendUTF8ToPostData ("--" + boundary);
  6508. int i;
  6509. for (i = 0; i < url.getParameters().size(); ++i)
  6510. {
  6511. String s;
  6512. s << "\r\nContent-Disposition: form-data; name=\""
  6513. << url.getParameters().getAllKeys() [i]
  6514. << "\"\r\n\r\n"
  6515. << url.getParameters().getAllValues() [i]
  6516. << "\r\n--"
  6517. << boundary;
  6518. appendUTF8ToPostData (s);
  6519. }
  6520. for (i = 0; i < url.getFilesToUpload().size(); ++i)
  6521. {
  6522. const File f (url.getFilesToUpload().getAllValues() [i]);
  6523. const String paramName (url.getFilesToUpload().getAllKeys() [i]);
  6524. String s;
  6525. s << "\r\nContent-Disposition: form-data; name=\""
  6526. << paramName
  6527. << "\"; filename=\""
  6528. << f.getFileName()
  6529. << "\"\r\n";
  6530. const String mimeType (url.getMimeTypesOfUploadFiles()
  6531. .getValue (paramName, String::empty));
  6532. if (mimeType.isNotEmpty())
  6533. s << "Content-Type: " << mimeType << "\r\n";
  6534. s << "Content-Transfer-Encoding: binary\r\n\r\n";
  6535. appendUTF8ToPostData (s);
  6536. f.loadFileAsData (postData);
  6537. s = "\r\n--" + boundary;
  6538. appendUTF8ToPostData (s);
  6539. }
  6540. appendUTF8ToPostData ("--\r\n");
  6541. }
  6542. else
  6543. {
  6544. appendUTF8ToPostData (getMangledParameters (url.getParameters()));
  6545. appendUTF8ToPostData (url.getPostData());
  6546. // just a short text attachment, so use simple url encoding..
  6547. headers = "Content-Type: application/x-www-form-urlencoded\r\nContent-length: "
  6548. + String ((unsigned int) postData.getSize())
  6549. + "\r\n";
  6550. }
  6551. }
  6552. void appendUTF8ToPostData (const String& text)
  6553. {
  6554. postData.append (text.toUTF8(),
  6555. (int) strlen (text.toUTF8()));
  6556. }
  6557. WebInputStream (const WebInputStream&);
  6558. WebInputStream& operator= (const WebInputStream&);
  6559. };
  6560. InputStream* URL::createInputStream (const bool usePostCommand,
  6561. OpenStreamProgressCallback* const progressCallback,
  6562. void* const progressCallbackContext,
  6563. const String& extraHeaders,
  6564. const int timeOutMs) const
  6565. {
  6566. ScopedPointer <WebInputStream> wi (new WebInputStream (*this, usePostCommand,
  6567. progressCallback, progressCallbackContext,
  6568. extraHeaders,
  6569. timeOutMs));
  6570. return wi->isError() ? 0 : wi.release();
  6571. }
  6572. bool URL::readEntireBinaryStream (MemoryBlock& destData,
  6573. const bool usePostCommand) const
  6574. {
  6575. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6576. if (in != 0)
  6577. {
  6578. in->readIntoMemoryBlock (destData, -1);
  6579. return true;
  6580. }
  6581. return false;
  6582. }
  6583. const String URL::readEntireTextStream (const bool usePostCommand) const
  6584. {
  6585. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6586. if (in != 0)
  6587. return in->readEntireStreamAsString();
  6588. return String::empty;
  6589. }
  6590. XmlElement* URL::readEntireXmlStream (const bool usePostCommand) const
  6591. {
  6592. XmlDocument doc (readEntireTextStream (usePostCommand));
  6593. return doc.getDocumentElement();
  6594. }
  6595. const URL URL::withParameter (const String& parameterName,
  6596. const String& parameterValue) const
  6597. {
  6598. URL u (*this);
  6599. u.parameters.set (parameterName, parameterValue);
  6600. return u;
  6601. }
  6602. const URL URL::withFileToUpload (const String& parameterName,
  6603. const File& fileToUpload,
  6604. const String& mimeType) const
  6605. {
  6606. jassert (mimeType.isNotEmpty()); // You need to supply a mime type!
  6607. URL u (*this);
  6608. u.filesToUpload.set (parameterName, fileToUpload.getFullPathName());
  6609. u.mimeTypes.set (parameterName, mimeType);
  6610. return u;
  6611. }
  6612. const URL URL::withPOSTData (const String& postData_) const
  6613. {
  6614. URL u (*this);
  6615. u.postData = postData_;
  6616. return u;
  6617. }
  6618. const StringPairArray& URL::getParameters() const
  6619. {
  6620. return parameters;
  6621. }
  6622. const StringPairArray& URL::getFilesToUpload() const
  6623. {
  6624. return filesToUpload;
  6625. }
  6626. const StringPairArray& URL::getMimeTypesOfUploadFiles() const
  6627. {
  6628. return mimeTypes;
  6629. }
  6630. const String URL::removeEscapeChars (const String& s)
  6631. {
  6632. const int len = s.length();
  6633. HeapBlock <char> resultUTF8 (len * 4);
  6634. char* r = resultUTF8;
  6635. for (int i = 0; i < len; ++i)
  6636. {
  6637. char c = (char) s[i];
  6638. if (c == 0)
  6639. break;
  6640. if (c == '+')
  6641. {
  6642. c = ' ';
  6643. }
  6644. else if (c == '%')
  6645. {
  6646. c = (char) s.substring (i + 1, i + 3).getHexValue32();
  6647. i += 2;
  6648. }
  6649. *r++ = c;
  6650. }
  6651. return String::fromUTF8 (resultUTF8);
  6652. }
  6653. const String URL::addEscapeChars (const String& s, const bool isParameter)
  6654. {
  6655. String result;
  6656. result.preallocateStorage (s.length() + 8);
  6657. const char* utf8 = s.toUTF8();
  6658. const char* legalChars = isParameter ? "_-.*!'()"
  6659. : "_-$.*!'(),";
  6660. while (*utf8 != 0)
  6661. {
  6662. const char c = *utf8++;
  6663. if (CharacterFunctions::isLetterOrDigit (c)
  6664. || CharacterFunctions::indexOfChar (legalChars, c, false) >= 0)
  6665. {
  6666. result << c;
  6667. }
  6668. else
  6669. {
  6670. const int v = (int) (uint8) c;
  6671. result << (v < 0x10 ? "%0" : "%") << String::toHexString (v);
  6672. }
  6673. }
  6674. return result;
  6675. }
  6676. extern bool juce_launchFile (const String& fileName, const String& parameters);
  6677. bool URL::launchInDefaultBrowser() const
  6678. {
  6679. String u (toString (true));
  6680. if (u.contains (T("@")) && ! u.contains (T(":")))
  6681. u = "mailto:" + u;
  6682. return juce_launchFile (u, String::empty);
  6683. }
  6684. END_JUCE_NAMESPACE
  6685. /*** End of inlined file: juce_URL.cpp ***/
  6686. /*** Start of inlined file: juce_BufferedInputStream.cpp ***/
  6687. BEGIN_JUCE_NAMESPACE
  6688. BufferedInputStream::BufferedInputStream (InputStream* const source_,
  6689. const int bufferSize_,
  6690. const bool deleteSourceWhenDestroyed)
  6691. : source (source_),
  6692. sourceToDelete (deleteSourceWhenDestroyed ? source_ : 0),
  6693. bufferSize (jmax (256, bufferSize_)),
  6694. position (source_->getPosition()),
  6695. lastReadPos (0),
  6696. bufferOverlap (128)
  6697. {
  6698. const int sourceSize = (int) source_->getTotalLength();
  6699. if (sourceSize >= 0)
  6700. bufferSize = jmin (jmax (32, sourceSize), bufferSize);
  6701. bufferStart = position;
  6702. buffer.malloc (bufferSize);
  6703. }
  6704. BufferedInputStream::~BufferedInputStream()
  6705. {
  6706. }
  6707. int64 BufferedInputStream::getTotalLength()
  6708. {
  6709. return source->getTotalLength();
  6710. }
  6711. int64 BufferedInputStream::getPosition()
  6712. {
  6713. return position;
  6714. }
  6715. bool BufferedInputStream::setPosition (int64 newPosition)
  6716. {
  6717. position = jmax ((int64) 0, newPosition);
  6718. return true;
  6719. }
  6720. bool BufferedInputStream::isExhausted()
  6721. {
  6722. return (position >= lastReadPos)
  6723. && source->isExhausted();
  6724. }
  6725. void BufferedInputStream::ensureBuffered()
  6726. {
  6727. const int64 bufferEndOverlap = lastReadPos - bufferOverlap;
  6728. if (position < bufferStart || position >= bufferEndOverlap)
  6729. {
  6730. int bytesRead;
  6731. if (position < lastReadPos
  6732. && position >= bufferEndOverlap
  6733. && position >= bufferStart)
  6734. {
  6735. const int bytesToKeep = (int) (lastReadPos - position);
  6736. memmove (buffer, buffer + (int) (position - bufferStart), bytesToKeep);
  6737. bufferStart = position;
  6738. bytesRead = source->read (buffer + bytesToKeep,
  6739. bufferSize - bytesToKeep);
  6740. lastReadPos += bytesRead;
  6741. bytesRead += bytesToKeep;
  6742. }
  6743. else
  6744. {
  6745. bufferStart = position;
  6746. source->setPosition (bufferStart);
  6747. bytesRead = source->read (buffer, bufferSize);
  6748. lastReadPos = bufferStart + bytesRead;
  6749. }
  6750. while (bytesRead < bufferSize)
  6751. buffer [bytesRead++] = 0;
  6752. }
  6753. }
  6754. int BufferedInputStream::read (void* destBuffer, int maxBytesToRead)
  6755. {
  6756. if (position >= bufferStart
  6757. && position + maxBytesToRead <= lastReadPos)
  6758. {
  6759. memcpy (destBuffer, buffer + (int) (position - bufferStart), maxBytesToRead);
  6760. position += maxBytesToRead;
  6761. return maxBytesToRead;
  6762. }
  6763. else
  6764. {
  6765. if (position < bufferStart || position >= lastReadPos)
  6766. ensureBuffered();
  6767. int bytesRead = 0;
  6768. while (maxBytesToRead > 0)
  6769. {
  6770. const int bytesAvailable = jmin (maxBytesToRead, (int) (lastReadPos - position));
  6771. if (bytesAvailable > 0)
  6772. {
  6773. memcpy (destBuffer, buffer + (int) (position - bufferStart), bytesAvailable);
  6774. maxBytesToRead -= bytesAvailable;
  6775. bytesRead += bytesAvailable;
  6776. position += bytesAvailable;
  6777. destBuffer = (void*) (((char*) destBuffer) + bytesAvailable);
  6778. }
  6779. const int64 oldLastReadPos = lastReadPos;
  6780. ensureBuffered();
  6781. if (oldLastReadPos == lastReadPos)
  6782. break; // if ensureBuffered() failed to read any more data, bail out
  6783. if (isExhausted())
  6784. break;
  6785. }
  6786. return bytesRead;
  6787. }
  6788. }
  6789. const String BufferedInputStream::readString()
  6790. {
  6791. if (position >= bufferStart
  6792. && position < lastReadPos)
  6793. {
  6794. const int maxChars = (int) (lastReadPos - position);
  6795. const char* const src = buffer + (int) (position - bufferStart);
  6796. for (int i = 0; i < maxChars; ++i)
  6797. {
  6798. if (src[i] == 0)
  6799. {
  6800. position += i + 1;
  6801. return String::fromUTF8 (src, i);
  6802. }
  6803. }
  6804. }
  6805. return InputStream::readString();
  6806. }
  6807. END_JUCE_NAMESPACE
  6808. /*** End of inlined file: juce_BufferedInputStream.cpp ***/
  6809. /*** Start of inlined file: juce_FileInputSource.cpp ***/
  6810. BEGIN_JUCE_NAMESPACE
  6811. FileInputSource::FileInputSource (const File& file_)
  6812. : file (file_)
  6813. {
  6814. }
  6815. FileInputSource::~FileInputSource()
  6816. {
  6817. }
  6818. InputStream* FileInputSource::createInputStream()
  6819. {
  6820. return file.createInputStream();
  6821. }
  6822. InputStream* FileInputSource::createInputStreamFor (const String& relatedItemPath)
  6823. {
  6824. return file.getSiblingFile (relatedItemPath).createInputStream();
  6825. }
  6826. int64 FileInputSource::hashCode() const
  6827. {
  6828. return file.hashCode();
  6829. }
  6830. END_JUCE_NAMESPACE
  6831. /*** End of inlined file: juce_FileInputSource.cpp ***/
  6832. /*** Start of inlined file: juce_MemoryInputStream.cpp ***/
  6833. BEGIN_JUCE_NAMESPACE
  6834. MemoryInputStream::MemoryInputStream (const void* const sourceData,
  6835. const size_t sourceDataSize,
  6836. const bool keepInternalCopy)
  6837. : data (static_cast <const char*> (sourceData)),
  6838. dataSize (sourceDataSize),
  6839. position (0)
  6840. {
  6841. if (keepInternalCopy)
  6842. {
  6843. internalCopy.append (data, sourceDataSize);
  6844. data = static_cast <const char*> (internalCopy.getData());
  6845. }
  6846. }
  6847. MemoryInputStream::MemoryInputStream (const MemoryBlock& sourceData,
  6848. const bool keepInternalCopy)
  6849. : data (static_cast <const char*> (sourceData.getData())),
  6850. dataSize (sourceData.getSize()),
  6851. position (0)
  6852. {
  6853. if (keepInternalCopy)
  6854. {
  6855. internalCopy = sourceData;
  6856. data = static_cast <const char*> (internalCopy.getData());
  6857. }
  6858. }
  6859. MemoryInputStream::~MemoryInputStream()
  6860. {
  6861. }
  6862. int64 MemoryInputStream::getTotalLength()
  6863. {
  6864. return dataSize;
  6865. }
  6866. int MemoryInputStream::read (void* const buffer, const int howMany)
  6867. {
  6868. jassert (howMany >= 0);
  6869. const int num = jmin (howMany, (int) (dataSize - position));
  6870. memcpy (buffer, data + position, num);
  6871. position += num;
  6872. return (int) num;
  6873. }
  6874. bool MemoryInputStream::isExhausted()
  6875. {
  6876. return (position >= dataSize);
  6877. }
  6878. bool MemoryInputStream::setPosition (const int64 pos)
  6879. {
  6880. position = (int) jlimit ((int64) 0, (int64) dataSize, pos);
  6881. return true;
  6882. }
  6883. int64 MemoryInputStream::getPosition()
  6884. {
  6885. return position;
  6886. }
  6887. END_JUCE_NAMESPACE
  6888. /*** End of inlined file: juce_MemoryInputStream.cpp ***/
  6889. /*** Start of inlined file: juce_MemoryOutputStream.cpp ***/
  6890. BEGIN_JUCE_NAMESPACE
  6891. MemoryOutputStream::MemoryOutputStream (const size_t initialSize,
  6892. const size_t blockSizeToIncreaseBy,
  6893. MemoryBlock* const memoryBlockToWriteTo)
  6894. : data (memoryBlockToWriteTo),
  6895. position (0),
  6896. size (0),
  6897. blockSize (jmax ((size_t) 16, blockSizeToIncreaseBy))
  6898. {
  6899. if (data == 0)
  6900. dataToDelete = data = new MemoryBlock (initialSize);
  6901. else
  6902. data->setSize (initialSize, false);
  6903. }
  6904. MemoryOutputStream::~MemoryOutputStream()
  6905. {
  6906. flush();
  6907. }
  6908. void MemoryOutputStream::flush()
  6909. {
  6910. if (dataToDelete == 0)
  6911. data->setSize (size, false);
  6912. }
  6913. void MemoryOutputStream::reset() throw()
  6914. {
  6915. position = 0;
  6916. size = 0;
  6917. }
  6918. bool MemoryOutputStream::write (const void* const buffer, int howMany)
  6919. {
  6920. if (howMany > 0)
  6921. {
  6922. size_t storageNeeded = position + howMany;
  6923. if (storageNeeded >= data->getSize())
  6924. {
  6925. // if we need more space, increase the block by at least 10%..
  6926. storageNeeded += jmax (blockSize, storageNeeded / 10);
  6927. storageNeeded = storageNeeded - (storageNeeded % blockSize) + blockSize;
  6928. data->ensureSize (storageNeeded);
  6929. }
  6930. data->copyFrom (buffer, (int) position, howMany);
  6931. position += howMany;
  6932. size = jmax (size, position);
  6933. }
  6934. return true;
  6935. }
  6936. const char* MemoryOutputStream::getData() const throw()
  6937. {
  6938. char* const d = static_cast <char*> (data->getData());
  6939. if (data->getSize() > size)
  6940. d [size] = 0;
  6941. return d;
  6942. }
  6943. size_t MemoryOutputStream::getDataSize() const throw()
  6944. {
  6945. return size;
  6946. }
  6947. int64 MemoryOutputStream::getPosition()
  6948. {
  6949. return position;
  6950. }
  6951. bool MemoryOutputStream::setPosition (int64 newPosition)
  6952. {
  6953. if (newPosition <= (int64) size)
  6954. {
  6955. // ok to seek backwards
  6956. position = jlimit ((size_t) 0, size, (size_t) newPosition);
  6957. return true;
  6958. }
  6959. else
  6960. {
  6961. // trying to make it bigger isn't a good thing to do..
  6962. return false;
  6963. }
  6964. }
  6965. END_JUCE_NAMESPACE
  6966. /*** End of inlined file: juce_MemoryOutputStream.cpp ***/
  6967. /*** Start of inlined file: juce_SubregionStream.cpp ***/
  6968. BEGIN_JUCE_NAMESPACE
  6969. SubregionStream::SubregionStream (InputStream* const sourceStream,
  6970. const int64 startPositionInSourceStream_,
  6971. const int64 lengthOfSourceStream_,
  6972. const bool deleteSourceWhenDestroyed) throw()
  6973. : source (sourceStream),
  6974. startPositionInSourceStream (startPositionInSourceStream_),
  6975. lengthOfSourceStream (lengthOfSourceStream_)
  6976. {
  6977. if (deleteSourceWhenDestroyed)
  6978. sourceToDelete = source;
  6979. setPosition (0);
  6980. }
  6981. SubregionStream::~SubregionStream() throw()
  6982. {
  6983. }
  6984. int64 SubregionStream::getTotalLength()
  6985. {
  6986. const int64 srcLen = source->getTotalLength() - startPositionInSourceStream;
  6987. return (lengthOfSourceStream >= 0) ? jmin (lengthOfSourceStream, srcLen)
  6988. : srcLen;
  6989. }
  6990. int64 SubregionStream::getPosition()
  6991. {
  6992. return source->getPosition() - startPositionInSourceStream;
  6993. }
  6994. bool SubregionStream::setPosition (int64 newPosition)
  6995. {
  6996. return source->setPosition (jmax ((int64) 0, newPosition + startPositionInSourceStream));
  6997. }
  6998. int SubregionStream::read (void* destBuffer, int maxBytesToRead)
  6999. {
  7000. if (lengthOfSourceStream < 0)
  7001. {
  7002. return source->read (destBuffer, maxBytesToRead);
  7003. }
  7004. else
  7005. {
  7006. maxBytesToRead = (int) jmin ((int64) maxBytesToRead, lengthOfSourceStream - getPosition());
  7007. if (maxBytesToRead <= 0)
  7008. return 0;
  7009. return source->read (destBuffer, maxBytesToRead);
  7010. }
  7011. }
  7012. bool SubregionStream::isExhausted()
  7013. {
  7014. if (lengthOfSourceStream >= 0)
  7015. return (getPosition() >= lengthOfSourceStream) || source->isExhausted();
  7016. else
  7017. return source->isExhausted();
  7018. }
  7019. END_JUCE_NAMESPACE
  7020. /*** End of inlined file: juce_SubregionStream.cpp ***/
  7021. /*** Start of inlined file: juce_PerformanceCounter.cpp ***/
  7022. BEGIN_JUCE_NAMESPACE
  7023. PerformanceCounter::PerformanceCounter (const String& name_,
  7024. int runsPerPrintout,
  7025. const File& loggingFile)
  7026. : name (name_),
  7027. numRuns (0),
  7028. runsPerPrint (runsPerPrintout),
  7029. totalTime (0),
  7030. outputFile (loggingFile)
  7031. {
  7032. if (outputFile != File::nonexistent)
  7033. {
  7034. String s ("**** Counter for \"");
  7035. s << name_ << "\" started at: "
  7036. << Time::getCurrentTime().toString (true, true)
  7037. << "\r\n";
  7038. outputFile.appendText (s, false, false);
  7039. }
  7040. }
  7041. PerformanceCounter::~PerformanceCounter()
  7042. {
  7043. printStatistics();
  7044. }
  7045. void PerformanceCounter::start()
  7046. {
  7047. started = Time::getHighResolutionTicks();
  7048. }
  7049. void PerformanceCounter::stop()
  7050. {
  7051. const int64 now = Time::getHighResolutionTicks();
  7052. totalTime += 1000.0 * Time::highResolutionTicksToSeconds (now - started);
  7053. if (++numRuns == runsPerPrint)
  7054. printStatistics();
  7055. }
  7056. void PerformanceCounter::printStatistics()
  7057. {
  7058. if (numRuns > 0)
  7059. {
  7060. String s ("Performance count for \"");
  7061. s << name << "\" - average over " << numRuns << " run(s) = ";
  7062. const int micros = (int) (totalTime * (1000.0 / numRuns));
  7063. if (micros > 10000)
  7064. s << (micros/1000) << " millisecs";
  7065. else
  7066. s << micros << " microsecs";
  7067. s << ", total = " << String (totalTime / 1000, 5) << " seconds";
  7068. Logger::outputDebugString (s);
  7069. s << "\r\n";
  7070. if (outputFile != File::nonexistent)
  7071. outputFile.appendText (s, false, false);
  7072. numRuns = 0;
  7073. totalTime = 0;
  7074. }
  7075. }
  7076. END_JUCE_NAMESPACE
  7077. /*** End of inlined file: juce_PerformanceCounter.cpp ***/
  7078. /*** Start of inlined file: juce_Uuid.cpp ***/
  7079. BEGIN_JUCE_NAMESPACE
  7080. Uuid::Uuid()
  7081. {
  7082. // Mix up any available MAC addresses with some time-based pseudo-random numbers
  7083. // to make it very very unlikely that two UUIDs will ever be the same..
  7084. static int64 macAddresses[2];
  7085. static bool hasCheckedMacAddresses = false;
  7086. if (! hasCheckedMacAddresses)
  7087. {
  7088. hasCheckedMacAddresses = true;
  7089. SystemStats::getMACAddresses (macAddresses, 2);
  7090. }
  7091. value.asInt64[0] = macAddresses[0];
  7092. value.asInt64[1] = macAddresses[1];
  7093. // We'll use both a local RNG that is re-seeded, plus the shared RNG,
  7094. // whose seed will carry over between calls to this method.
  7095. Random r (macAddresses[0] ^ macAddresses[1]
  7096. ^ Random::getSystemRandom().nextInt64());
  7097. for (int i = 4; --i >= 0;)
  7098. {
  7099. r.setSeedRandomly(); // calling this repeatedly improves randomness
  7100. value.asInt[i] ^= r.nextInt();
  7101. value.asInt[i] ^= Random::getSystemRandom().nextInt();
  7102. }
  7103. }
  7104. Uuid::~Uuid() throw()
  7105. {
  7106. }
  7107. Uuid::Uuid (const Uuid& other)
  7108. : value (other.value)
  7109. {
  7110. }
  7111. Uuid& Uuid::operator= (const Uuid& other)
  7112. {
  7113. value = other.value;
  7114. return *this;
  7115. }
  7116. bool Uuid::operator== (const Uuid& other) const
  7117. {
  7118. return memcmp (value.asBytes, other.value.asBytes, 16) == 0;
  7119. }
  7120. bool Uuid::operator!= (const Uuid& other) const
  7121. {
  7122. return ! operator== (other);
  7123. }
  7124. bool Uuid::isNull() const throw()
  7125. {
  7126. return (value.asInt64 [0] == 0) && (value.asInt64 [1] == 0);
  7127. }
  7128. const String Uuid::toString() const
  7129. {
  7130. return String::toHexString (value.asBytes, 16, 0);
  7131. }
  7132. Uuid::Uuid (const String& uuidString)
  7133. {
  7134. operator= (uuidString);
  7135. }
  7136. Uuid& Uuid::operator= (const String& uuidString)
  7137. {
  7138. int destIndex = 0;
  7139. int i = 0;
  7140. for (;;)
  7141. {
  7142. int byte = 0;
  7143. for (int loop = 2; --loop >= 0;)
  7144. {
  7145. byte <<= 4;
  7146. for (;;)
  7147. {
  7148. const tchar c = uuidString [i++];
  7149. if (c >= '0' && c <= '9')
  7150. {
  7151. byte |= c - '0';
  7152. break;
  7153. }
  7154. else if (c >= 'a' && c <= 'z')
  7155. {
  7156. byte |= c - ('a' - 10);
  7157. break;
  7158. }
  7159. else if (c >= 'A' && c <= 'Z')
  7160. {
  7161. byte |= c - ('A' - 10);
  7162. break;
  7163. }
  7164. else if (c == 0)
  7165. {
  7166. while (destIndex < 16)
  7167. value.asBytes [destIndex++] = 0;
  7168. return *this;
  7169. }
  7170. }
  7171. }
  7172. value.asBytes [destIndex++] = (uint8) byte;
  7173. }
  7174. }
  7175. Uuid::Uuid (const uint8* const rawData)
  7176. {
  7177. operator= (rawData);
  7178. }
  7179. Uuid& Uuid::operator= (const uint8* const rawData)
  7180. {
  7181. if (rawData != 0)
  7182. memcpy (value.asBytes, rawData, 16);
  7183. else
  7184. zeromem (value.asBytes, 16);
  7185. return *this;
  7186. }
  7187. END_JUCE_NAMESPACE
  7188. /*** End of inlined file: juce_Uuid.cpp ***/
  7189. /*** Start of inlined file: juce_ZipFile.cpp ***/
  7190. BEGIN_JUCE_NAMESPACE
  7191. class ZipFile::ZipEntryInfo
  7192. {
  7193. public:
  7194. ZipFile::ZipEntry entry;
  7195. int streamOffset;
  7196. int compressedSize;
  7197. bool compressed;
  7198. };
  7199. class ZipFile::ZipInputStream : public InputStream
  7200. {
  7201. public:
  7202. ZipInputStream (ZipFile& file_, ZipFile::ZipEntryInfo& zei)
  7203. : file (file_),
  7204. zipEntryInfo (zei),
  7205. pos (0),
  7206. headerSize (0),
  7207. inputStream (0)
  7208. {
  7209. inputStream = file_.inputStream;
  7210. if (file_.inputSource != 0)
  7211. {
  7212. inputStream = file.inputSource->createInputStream();
  7213. }
  7214. else
  7215. {
  7216. #ifdef JUCE_DEBUG
  7217. file_.numOpenStreams++;
  7218. #endif
  7219. }
  7220. char buffer [30];
  7221. if (inputStream != 0
  7222. && inputStream->setPosition (zei.streamOffset)
  7223. && inputStream->read (buffer, 30) == 30
  7224. && ByteOrder::littleEndianInt (buffer) == 0x04034b50)
  7225. {
  7226. headerSize = 30 + ByteOrder::littleEndianShort (buffer + 26)
  7227. + ByteOrder::littleEndianShort (buffer + 28);
  7228. }
  7229. }
  7230. ~ZipInputStream() throw()
  7231. {
  7232. #ifdef JUCE_DEBUG
  7233. if (inputStream != 0 && inputStream == file.inputStream)
  7234. file.numOpenStreams--;
  7235. #endif
  7236. if (inputStream != file.inputStream)
  7237. delete inputStream;
  7238. }
  7239. int64 getTotalLength() throw()
  7240. {
  7241. return zipEntryInfo.compressedSize;
  7242. }
  7243. int read (void* buffer, int howMany) throw()
  7244. {
  7245. if (headerSize <= 0)
  7246. return 0;
  7247. howMany = (int) jmin ((int64) howMany, zipEntryInfo.compressedSize - pos);
  7248. if (inputStream == 0)
  7249. return 0;
  7250. int num;
  7251. if (inputStream == file.inputStream)
  7252. {
  7253. const ScopedLock sl (file.lock);
  7254. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7255. num = inputStream->read (buffer, howMany);
  7256. }
  7257. else
  7258. {
  7259. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7260. num = inputStream->read (buffer, howMany);
  7261. }
  7262. pos += num;
  7263. return num;
  7264. }
  7265. bool isExhausted() throw()
  7266. {
  7267. return headerSize <= 0 || pos >= zipEntryInfo.compressedSize;
  7268. }
  7269. int64 getPosition() throw()
  7270. {
  7271. return pos;
  7272. }
  7273. bool setPosition (int64 newPos) throw()
  7274. {
  7275. pos = jlimit ((int64) 0, (int64) zipEntryInfo.compressedSize, newPos);
  7276. return true;
  7277. }
  7278. private:
  7279. ZipFile& file;
  7280. ZipEntryInfo zipEntryInfo;
  7281. int64 pos;
  7282. int headerSize;
  7283. InputStream* inputStream;
  7284. ZipInputStream (const ZipInputStream&);
  7285. ZipInputStream& operator= (const ZipInputStream&);
  7286. };
  7287. ZipFile::ZipFile (InputStream* const source_,
  7288. const bool deleteStreamWhenDestroyed) throw()
  7289. : inputStream (source_)
  7290. #ifdef JUCE_DEBUG
  7291. , numOpenStreams (0)
  7292. #endif
  7293. {
  7294. if (deleteStreamWhenDestroyed)
  7295. streamToDelete = inputStream;
  7296. init();
  7297. }
  7298. ZipFile::ZipFile (const File& file)
  7299. : inputStream (0)
  7300. #ifdef JUCE_DEBUG
  7301. , numOpenStreams (0)
  7302. #endif
  7303. {
  7304. inputSource = new FileInputSource (file);
  7305. init();
  7306. }
  7307. ZipFile::ZipFile (InputSource* const inputSource_)
  7308. : inputStream (0),
  7309. inputSource (inputSource_)
  7310. #ifdef JUCE_DEBUG
  7311. , numOpenStreams (0)
  7312. #endif
  7313. {
  7314. init();
  7315. }
  7316. ZipFile::~ZipFile() throw()
  7317. {
  7318. #ifdef JUCE_DEBUG
  7319. entries.clear();
  7320. // If you hit this assertion, it means you've created a stream to read
  7321. // one of the items in the zipfile, but you've forgotten to delete that
  7322. // stream object before deleting the file.. Streams can't be kept open
  7323. // after the file is deleted because they need to share the input
  7324. // stream that the file uses to read itself.
  7325. jassert (numOpenStreams == 0);
  7326. #endif
  7327. }
  7328. int ZipFile::getNumEntries() const throw()
  7329. {
  7330. return entries.size();
  7331. }
  7332. const ZipFile::ZipEntry* ZipFile::getEntry (const int index) const throw()
  7333. {
  7334. ZipEntryInfo* const zei = (ZipEntryInfo*) entries [index];
  7335. return (zei != 0) ? &(zei->entry)
  7336. : 0;
  7337. }
  7338. int ZipFile::getIndexOfFileName (const String& fileName) const throw()
  7339. {
  7340. for (int i = 0; i < entries.size(); ++i)
  7341. if (entries.getUnchecked (i)->entry.filename == fileName)
  7342. return i;
  7343. return -1;
  7344. }
  7345. const ZipFile::ZipEntry* ZipFile::getEntry (const String& fileName) const throw()
  7346. {
  7347. return getEntry (getIndexOfFileName (fileName));
  7348. }
  7349. InputStream* ZipFile::createStreamForEntry (const int index)
  7350. {
  7351. ZipEntryInfo* const zei = entries[index];
  7352. InputStream* stream = 0;
  7353. if (zei != 0)
  7354. {
  7355. stream = new ZipInputStream (*this, *zei);
  7356. if (zei->compressed)
  7357. {
  7358. stream = new GZIPDecompressorInputStream (stream, true, true,
  7359. zei->entry.uncompressedSize);
  7360. // (much faster to unzip in big blocks using a buffer..)
  7361. stream = new BufferedInputStream (stream, 32768, true);
  7362. }
  7363. }
  7364. return stream;
  7365. }
  7366. class ZipFile::ZipFilenameComparator
  7367. {
  7368. public:
  7369. int compareElements (const ZipFile::ZipEntryInfo* first, const ZipFile::ZipEntryInfo* second)
  7370. {
  7371. return first->entry.filename.compare (second->entry.filename);
  7372. }
  7373. };
  7374. void ZipFile::sortEntriesByFilename()
  7375. {
  7376. ZipFilenameComparator sorter;
  7377. entries.sort (sorter);
  7378. }
  7379. void ZipFile::init()
  7380. {
  7381. ScopedPointer <InputStream> toDelete;
  7382. InputStream* in = inputStream;
  7383. if (inputSource != 0)
  7384. {
  7385. in = inputSource->createInputStream();
  7386. toDelete = in;
  7387. }
  7388. if (in != 0)
  7389. {
  7390. int numEntries = 0;
  7391. int pos = findEndOfZipEntryTable (in, numEntries);
  7392. if (pos >= 0 && pos < in->getTotalLength())
  7393. {
  7394. const int size = (int) (in->getTotalLength() - pos);
  7395. in->setPosition (pos);
  7396. MemoryBlock headerData;
  7397. if (in->readIntoMemoryBlock (headerData, size) == size)
  7398. {
  7399. pos = 0;
  7400. for (int i = 0; i < numEntries; ++i)
  7401. {
  7402. if (pos + 46 > size)
  7403. break;
  7404. const char* const buffer = ((const char*) headerData.getData()) + pos;
  7405. const int fileNameLen = ByteOrder::littleEndianShort (buffer + 28);
  7406. if (pos + 46 + fileNameLen > size)
  7407. break;
  7408. ZipEntryInfo* const zei = new ZipEntryInfo();
  7409. zei->entry.filename = String::fromUTF8 (buffer + 46, fileNameLen);
  7410. const int time = ByteOrder::littleEndianShort (buffer + 12);
  7411. const int date = ByteOrder::littleEndianShort (buffer + 14);
  7412. const int year = 1980 + (date >> 9);
  7413. const int month = ((date >> 5) & 15) - 1;
  7414. const int day = date & 31;
  7415. const int hours = time >> 11;
  7416. const int minutes = (time >> 5) & 63;
  7417. const int seconds = (time & 31) << 1;
  7418. zei->entry.fileTime = Time (year, month, day, hours, minutes, seconds);
  7419. zei->compressed = ByteOrder::littleEndianShort (buffer + 10) != 0;
  7420. zei->compressedSize = ByteOrder::littleEndianInt (buffer + 20);
  7421. zei->entry.uncompressedSize = ByteOrder::littleEndianInt (buffer + 24);
  7422. zei->streamOffset = ByteOrder::littleEndianInt (buffer + 42);
  7423. entries.add (zei);
  7424. pos += 46 + fileNameLen
  7425. + ByteOrder::littleEndianShort (buffer + 30)
  7426. + ByteOrder::littleEndianShort (buffer + 32);
  7427. }
  7428. }
  7429. }
  7430. }
  7431. }
  7432. int ZipFile::findEndOfZipEntryTable (InputStream* input, int& numEntries)
  7433. {
  7434. BufferedInputStream in (input, 8192, false);
  7435. in.setPosition (in.getTotalLength());
  7436. int64 pos = in.getPosition();
  7437. const int64 lowestPos = jmax ((int64) 0, pos - 1024);
  7438. char buffer [32];
  7439. zeromem (buffer, sizeof (buffer));
  7440. while (pos > lowestPos)
  7441. {
  7442. in.setPosition (pos - 22);
  7443. pos = in.getPosition();
  7444. memcpy (buffer + 22, buffer, 4);
  7445. if (in.read (buffer, 22) != 22)
  7446. return 0;
  7447. for (int i = 0; i < 22; ++i)
  7448. {
  7449. if (ByteOrder::littleEndianInt (buffer + i) == 0x06054b50)
  7450. {
  7451. in.setPosition (pos + i);
  7452. in.read (buffer, 22);
  7453. numEntries = ByteOrder::littleEndianShort (buffer + 10);
  7454. return ByteOrder::littleEndianInt (buffer + 16);
  7455. }
  7456. }
  7457. }
  7458. return 0;
  7459. }
  7460. void ZipFile::uncompressTo (const File& targetDirectory,
  7461. const bool shouldOverwriteFiles)
  7462. {
  7463. for (int i = 0; i < entries.size(); ++i)
  7464. {
  7465. const ZipEntry& zei = entries.getUnchecked(i)->entry;
  7466. const File targetFile (targetDirectory.getChildFile (zei.filename));
  7467. if (zei.filename.endsWithChar ('/'))
  7468. {
  7469. targetFile.createDirectory(); // (entry is a directory, not a file)
  7470. }
  7471. else
  7472. {
  7473. ScopedPointer <InputStream> in (createStreamForEntry (i));
  7474. if (in != 0)
  7475. {
  7476. if (shouldOverwriteFiles)
  7477. targetFile.deleteFile();
  7478. if ((! targetFile.exists())
  7479. && targetFile.getParentDirectory().createDirectory())
  7480. {
  7481. ScopedPointer <FileOutputStream> out (targetFile.createOutputStream());
  7482. if (out != 0)
  7483. {
  7484. out->writeFromInputStream (*in, -1);
  7485. out = 0;
  7486. targetFile.setCreationTime (zei.fileTime);
  7487. targetFile.setLastModificationTime (zei.fileTime);
  7488. targetFile.setLastAccessTime (zei.fileTime);
  7489. }
  7490. }
  7491. }
  7492. }
  7493. }
  7494. }
  7495. END_JUCE_NAMESPACE
  7496. /*** End of inlined file: juce_ZipFile.cpp ***/
  7497. /*** Start of inlined file: juce_CharacterFunctions.cpp ***/
  7498. #ifdef _MSC_VER
  7499. #pragma warning (disable: 4514 4996)
  7500. #pragma warning (push)
  7501. #endif
  7502. #include <cwctype>
  7503. #include <cctype>
  7504. #include <ctime>
  7505. #ifdef _MSC_VER
  7506. #pragma warning (pop)
  7507. #endif
  7508. BEGIN_JUCE_NAMESPACE
  7509. int CharacterFunctions::length (const char* const s) throw()
  7510. {
  7511. return (int) strlen (s);
  7512. }
  7513. int CharacterFunctions::length (const juce_wchar* const s) throw()
  7514. {
  7515. return (int) wcslen (s);
  7516. }
  7517. void CharacterFunctions::copy (char* dest, const char* src, const int maxChars) throw()
  7518. {
  7519. strncpy (dest, src, maxChars);
  7520. }
  7521. void CharacterFunctions::copy (juce_wchar* dest, const juce_wchar* src, int maxChars) throw()
  7522. {
  7523. wcsncpy (dest, src, maxChars);
  7524. }
  7525. void CharacterFunctions::copy (juce_wchar* dest, const char* src, const int maxChars) throw()
  7526. {
  7527. mbstowcs (dest, src, maxChars);
  7528. }
  7529. void CharacterFunctions::copy (char* dest, const juce_wchar* src, const int maxChars) throw()
  7530. {
  7531. wcstombs (dest, src, maxChars);
  7532. }
  7533. int CharacterFunctions::bytesRequiredForCopy (const juce_wchar* src) throw()
  7534. {
  7535. return (int) wcstombs (0, src, 0);
  7536. }
  7537. void CharacterFunctions::append (char* dest, const char* src) throw()
  7538. {
  7539. strcat (dest, src);
  7540. }
  7541. void CharacterFunctions::append (juce_wchar* dest, const juce_wchar* src) throw()
  7542. {
  7543. wcscat (dest, src);
  7544. }
  7545. int CharacterFunctions::compare (const char* const s1, const char* const s2) throw()
  7546. {
  7547. return strcmp (s1, s2);
  7548. }
  7549. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2) throw()
  7550. {
  7551. jassert (s1 != 0 && s2 != 0);
  7552. return wcscmp (s1, s2);
  7553. }
  7554. int CharacterFunctions::compare (const char* const s1, const char* const s2, const int maxChars) throw()
  7555. {
  7556. jassert (s1 != 0 && s2 != 0);
  7557. return strncmp (s1, s2, maxChars);
  7558. }
  7559. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7560. {
  7561. jassert (s1 != 0 && s2 != 0);
  7562. return wcsncmp (s1, s2, maxChars);
  7563. }
  7564. int CharacterFunctions::compare (const juce_wchar* s1, const char* s2) throw()
  7565. {
  7566. jassert (s1 != 0 && s2 != 0);
  7567. for (;;)
  7568. {
  7569. const int diff = (int) (*s1 - (juce_wchar) (unsigned char) *s2);
  7570. if (diff != 0)
  7571. return diff;
  7572. else if (*s1 == 0)
  7573. break;
  7574. ++s1;
  7575. ++s2;
  7576. }
  7577. return 0;
  7578. }
  7579. int CharacterFunctions::compare (const char* s1, const juce_wchar* s2) throw()
  7580. {
  7581. return -compare (s2, s1);
  7582. }
  7583. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2) throw()
  7584. {
  7585. jassert (s1 != 0 && s2 != 0);
  7586. #if JUCE_WIN32
  7587. return stricmp (s1, s2);
  7588. #else
  7589. return strcasecmp (s1, s2);
  7590. #endif
  7591. }
  7592. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2) throw()
  7593. {
  7594. jassert (s1 != 0 && s2 != 0);
  7595. #if JUCE_WIN32
  7596. return _wcsicmp (s1, s2);
  7597. #else
  7598. for (;;)
  7599. {
  7600. if (*s1 != *s2)
  7601. {
  7602. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7603. if (diff != 0)
  7604. return diff < 0 ? -1 : 1;
  7605. }
  7606. else if (*s1 == 0)
  7607. break;
  7608. ++s1;
  7609. ++s2;
  7610. }
  7611. return 0;
  7612. #endif
  7613. }
  7614. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2, const int maxChars) throw()
  7615. {
  7616. jassert (s1 != 0 && s2 != 0);
  7617. #if JUCE_WIN32
  7618. return strnicmp (s1, s2, maxChars);
  7619. #else
  7620. return strncasecmp (s1, s2, maxChars);
  7621. #endif
  7622. }
  7623. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7624. {
  7625. jassert (s1 != 0 && s2 != 0);
  7626. #if JUCE_WIN32
  7627. return _wcsnicmp (s1, s2, maxChars);
  7628. #else
  7629. while (--maxChars >= 0)
  7630. {
  7631. if (*s1 != *s2)
  7632. {
  7633. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7634. if (diff != 0)
  7635. return diff < 0 ? -1 : 1;
  7636. }
  7637. else if (*s1 == 0)
  7638. break;
  7639. ++s1;
  7640. ++s2;
  7641. }
  7642. return 0;
  7643. #endif
  7644. }
  7645. const char* CharacterFunctions::find (const char* const haystack, const char* const needle) throw()
  7646. {
  7647. return strstr (haystack, needle);
  7648. }
  7649. const juce_wchar* CharacterFunctions::find (const juce_wchar* haystack, const juce_wchar* const needle) throw()
  7650. {
  7651. return wcsstr (haystack, needle);
  7652. }
  7653. int CharacterFunctions::indexOfChar (const char* const haystack, const char needle, const bool ignoreCase) throw()
  7654. {
  7655. if (haystack != 0)
  7656. {
  7657. int i = 0;
  7658. if (ignoreCase)
  7659. {
  7660. const char n1 = toLowerCase (needle);
  7661. const char n2 = toUpperCase (needle);
  7662. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7663. {
  7664. while (haystack[i] != 0)
  7665. {
  7666. if (haystack[i] == n1 || haystack[i] == n2)
  7667. return i;
  7668. ++i;
  7669. }
  7670. return -1;
  7671. }
  7672. jassert (n1 == needle);
  7673. }
  7674. while (haystack[i] != 0)
  7675. {
  7676. if (haystack[i] == needle)
  7677. return i;
  7678. ++i;
  7679. }
  7680. }
  7681. return -1;
  7682. }
  7683. int CharacterFunctions::indexOfChar (const juce_wchar* const haystack, const juce_wchar needle, const bool ignoreCase) throw()
  7684. {
  7685. if (haystack != 0)
  7686. {
  7687. int i = 0;
  7688. if (ignoreCase)
  7689. {
  7690. const juce_wchar n1 = toLowerCase (needle);
  7691. const juce_wchar n2 = toUpperCase (needle);
  7692. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7693. {
  7694. while (haystack[i] != 0)
  7695. {
  7696. if (haystack[i] == n1 || haystack[i] == n2)
  7697. return i;
  7698. ++i;
  7699. }
  7700. return -1;
  7701. }
  7702. jassert (n1 == needle);
  7703. }
  7704. while (haystack[i] != 0)
  7705. {
  7706. if (haystack[i] == needle)
  7707. return i;
  7708. ++i;
  7709. }
  7710. }
  7711. return -1;
  7712. }
  7713. int CharacterFunctions::indexOfCharFast (const char* const haystack, const char needle) throw()
  7714. {
  7715. jassert (haystack != 0);
  7716. int i = 0;
  7717. while (haystack[i] != 0)
  7718. {
  7719. if (haystack[i] == needle)
  7720. return i;
  7721. ++i;
  7722. }
  7723. return -1;
  7724. }
  7725. int CharacterFunctions::indexOfCharFast (const juce_wchar* const haystack, const juce_wchar needle) throw()
  7726. {
  7727. jassert (haystack != 0);
  7728. int i = 0;
  7729. while (haystack[i] != 0)
  7730. {
  7731. if (haystack[i] == needle)
  7732. return i;
  7733. ++i;
  7734. }
  7735. return -1;
  7736. }
  7737. int CharacterFunctions::getIntialSectionContainingOnly (const char* const text, const char* const allowedChars) throw()
  7738. {
  7739. return allowedChars == 0 ? 0 : (int) strspn (text, allowedChars);
  7740. }
  7741. int CharacterFunctions::getIntialSectionContainingOnly (const juce_wchar* const text, const juce_wchar* const allowedChars) throw()
  7742. {
  7743. if (allowedChars == 0)
  7744. return 0;
  7745. int i = 0;
  7746. for (;;)
  7747. {
  7748. if (indexOfCharFast (allowedChars, text[i]) < 0)
  7749. break;
  7750. ++i;
  7751. }
  7752. return i;
  7753. }
  7754. int CharacterFunctions::ftime (char* const dest, const int maxChars, const char* const format, const struct tm* const tm) throw()
  7755. {
  7756. return (int) strftime (dest, maxChars, format, tm);
  7757. }
  7758. int CharacterFunctions::ftime (juce_wchar* const dest, const int maxChars, const juce_wchar* const format, const struct tm* const tm) throw()
  7759. {
  7760. return (int) wcsftime (dest, maxChars, format, tm);
  7761. }
  7762. int CharacterFunctions::getIntValue (const char* const s) throw()
  7763. {
  7764. return atoi (s);
  7765. }
  7766. int CharacterFunctions::getIntValue (const juce_wchar* s) throw()
  7767. {
  7768. #if JUCE_WIN32
  7769. return _wtoi (s);
  7770. #else
  7771. int v = 0;
  7772. while (isWhitespace (*s))
  7773. ++s;
  7774. const bool isNeg = *s == '-';
  7775. if (isNeg)
  7776. ++s;
  7777. for (;;)
  7778. {
  7779. const wchar_t c = *s++;
  7780. if (c >= '0' && c <= '9')
  7781. v = v * 10 + (int) (c - '0');
  7782. else
  7783. break;
  7784. }
  7785. return isNeg ? -v : v;
  7786. #endif
  7787. }
  7788. int64 CharacterFunctions::getInt64Value (const char* s) throw()
  7789. {
  7790. #if JUCE_LINUX
  7791. return atoll (s);
  7792. #elif defined (JUCE_WIN32)
  7793. return _atoi64 (s);
  7794. #else
  7795. int64 v = 0;
  7796. while (isWhitespace (*s))
  7797. ++s;
  7798. const bool isNeg = *s == '-';
  7799. if (isNeg)
  7800. ++s;
  7801. for (;;)
  7802. {
  7803. const char c = *s++;
  7804. if (c >= '0' && c <= '9')
  7805. v = v * 10 + (int64) (c - '0');
  7806. else
  7807. break;
  7808. }
  7809. return isNeg ? -v : v;
  7810. #endif
  7811. }
  7812. int64 CharacterFunctions::getInt64Value (const juce_wchar* s) throw()
  7813. {
  7814. #if JUCE_WIN32
  7815. return _wtoi64 (s);
  7816. #else
  7817. int64 v = 0;
  7818. while (isWhitespace (*s))
  7819. ++s;
  7820. const bool isNeg = *s == '-';
  7821. if (isNeg)
  7822. ++s;
  7823. for (;;)
  7824. {
  7825. const juce_wchar c = *s++;
  7826. if (c >= '0' && c <= '9')
  7827. v = v * 10 + (int64) (c - '0');
  7828. else
  7829. break;
  7830. }
  7831. return isNeg ? -v : v;
  7832. #endif
  7833. }
  7834. static double juce_mulexp10 (const double value, int exponent) throw()
  7835. {
  7836. if (exponent == 0)
  7837. return value;
  7838. if (value == 0)
  7839. return 0;
  7840. const bool negative = (exponent < 0);
  7841. if (negative)
  7842. exponent = -exponent;
  7843. double result = 1.0, power = 10.0;
  7844. for (int bit = 1; exponent != 0; bit <<= 1)
  7845. {
  7846. if ((exponent & bit) != 0)
  7847. {
  7848. exponent ^= bit;
  7849. result *= power;
  7850. if (exponent == 0)
  7851. break;
  7852. }
  7853. power *= power;
  7854. }
  7855. return negative ? (value / result) : (value * result);
  7856. }
  7857. template <class CharType>
  7858. double juce_atof (const CharType* const original) throw()
  7859. {
  7860. double result[3] = { 0, 0, 0 }, accumulator[2] = { 0, 0 };
  7861. int exponentAdjustment[2] = { 0, 0 }, exponentAccumulator[2] = { -1, -1 };
  7862. int exponent = 0, decPointIndex = 0, digit = 0;
  7863. int lastDigit = 0, numSignificantDigits = 0;
  7864. bool isNegative = false, digitsFound = false;
  7865. const int maxSignificantDigits = 15 + 2;
  7866. const CharType* s = original;
  7867. while (CharacterFunctions::isWhitespace (*s))
  7868. ++s;
  7869. switch (*s)
  7870. {
  7871. case '-': isNegative = true; // fall-through..
  7872. case '+': ++s;
  7873. }
  7874. if (*s == 'n' || *s == 'N' || *s == 'i' || *s == 'I')
  7875. return atof (String (original).toUTF8()); // Let the c library deal with NAN and INF
  7876. for (;;)
  7877. {
  7878. if (CharacterFunctions::isDigit (*s))
  7879. {
  7880. lastDigit = digit;
  7881. digit = *s++ - '0';
  7882. digitsFound = true;
  7883. if (decPointIndex != 0)
  7884. exponentAdjustment[1]++;
  7885. if (numSignificantDigits == 0 && digit == 0)
  7886. continue;
  7887. if (++numSignificantDigits > maxSignificantDigits)
  7888. {
  7889. if (digit > 5)
  7890. ++accumulator [decPointIndex];
  7891. else if (digit == 5 && (lastDigit & 1) != 0)
  7892. ++accumulator [decPointIndex];
  7893. if (decPointIndex > 0)
  7894. exponentAdjustment[1]--;
  7895. else
  7896. exponentAdjustment[0]++;
  7897. while (CharacterFunctions::isDigit (*s))
  7898. {
  7899. ++s;
  7900. if (decPointIndex == 0)
  7901. exponentAdjustment[0]++;
  7902. }
  7903. }
  7904. else
  7905. {
  7906. const double maxAccumulatorValue = (double) ((std::numeric_limits<unsigned int>::max() - 9) / 10);
  7907. if (accumulator [decPointIndex] > maxAccumulatorValue)
  7908. {
  7909. result [decPointIndex] = juce_mulexp10 (result [decPointIndex], exponentAccumulator [decPointIndex])
  7910. + accumulator [decPointIndex];
  7911. accumulator [decPointIndex] = 0;
  7912. exponentAccumulator [decPointIndex] = 0;
  7913. }
  7914. accumulator [decPointIndex] = accumulator[decPointIndex] * 10 + digit;
  7915. exponentAccumulator [decPointIndex]++;
  7916. }
  7917. }
  7918. else if (decPointIndex == 0 && *s == '.')
  7919. {
  7920. ++s;
  7921. decPointIndex = 1;
  7922. if (numSignificantDigits > maxSignificantDigits)
  7923. {
  7924. while (CharacterFunctions::isDigit (*s))
  7925. ++s;
  7926. break;
  7927. }
  7928. }
  7929. else
  7930. {
  7931. break;
  7932. }
  7933. }
  7934. result[0] = juce_mulexp10 (result[0], exponentAccumulator[0]) + accumulator[0];
  7935. if (decPointIndex != 0)
  7936. result[1] = juce_mulexp10 (result[1], exponentAccumulator[1]) + accumulator[1];
  7937. if ((*s == 'e' || *s == 'E') && digitsFound)
  7938. {
  7939. bool negativeExponent = false;
  7940. switch (*++s)
  7941. {
  7942. case '-': negativeExponent = true; // fall-through..
  7943. case '+': ++s;
  7944. }
  7945. while (CharacterFunctions::isDigit (*s))
  7946. exponent = (exponent * 10) + (*s++ - '0');
  7947. if (negativeExponent)
  7948. exponent = -exponent;
  7949. }
  7950. double r = juce_mulexp10 (result[0], exponent + exponentAdjustment[0]);
  7951. if (decPointIndex != 0)
  7952. r += juce_mulexp10 (result[1], exponent - exponentAdjustment[1]);
  7953. return isNegative ? -r : r;
  7954. }
  7955. double CharacterFunctions::getDoubleValue (const char* const s) throw()
  7956. {
  7957. return juce_atof <char> (s);
  7958. }
  7959. double CharacterFunctions::getDoubleValue (const juce_wchar* const s) throw()
  7960. {
  7961. return juce_atof <juce_wchar> (s);
  7962. }
  7963. char CharacterFunctions::toUpperCase (const char character) throw()
  7964. {
  7965. return (char) toupper (character);
  7966. }
  7967. juce_wchar CharacterFunctions::toUpperCase (const juce_wchar character) throw()
  7968. {
  7969. return towupper (character);
  7970. }
  7971. void CharacterFunctions::toUpperCase (char* s) throw()
  7972. {
  7973. #if JUCE_WIN32
  7974. strupr (s);
  7975. #else
  7976. while (*s != 0)
  7977. {
  7978. *s = toUpperCase (*s);
  7979. ++s;
  7980. }
  7981. #endif
  7982. }
  7983. void CharacterFunctions::toUpperCase (juce_wchar* s) throw()
  7984. {
  7985. #if JUCE_WIN32
  7986. _wcsupr (s);
  7987. #else
  7988. while (*s != 0)
  7989. {
  7990. *s = toUpperCase (*s);
  7991. ++s;
  7992. }
  7993. #endif
  7994. }
  7995. bool CharacterFunctions::isUpperCase (const char character) throw()
  7996. {
  7997. return isupper (character) != 0;
  7998. }
  7999. bool CharacterFunctions::isUpperCase (const juce_wchar character) throw()
  8000. {
  8001. #if JUCE_WIN32
  8002. return iswupper (character) != 0;
  8003. #else
  8004. return toLowerCase (character) != character;
  8005. #endif
  8006. }
  8007. char CharacterFunctions::toLowerCase (const char character) throw()
  8008. {
  8009. return (char) tolower (character);
  8010. }
  8011. juce_wchar CharacterFunctions::toLowerCase (const juce_wchar character) throw()
  8012. {
  8013. return towlower (character);
  8014. }
  8015. void CharacterFunctions::toLowerCase (char* s) throw()
  8016. {
  8017. #if JUCE_WIN32
  8018. strlwr (s);
  8019. #else
  8020. while (*s != 0)
  8021. {
  8022. *s = toLowerCase (*s);
  8023. ++s;
  8024. }
  8025. #endif
  8026. }
  8027. void CharacterFunctions::toLowerCase (juce_wchar* s) throw()
  8028. {
  8029. #if JUCE_WIN32
  8030. _wcslwr (s);
  8031. #else
  8032. while (*s != 0)
  8033. {
  8034. *s = toLowerCase (*s);
  8035. ++s;
  8036. }
  8037. #endif
  8038. }
  8039. bool CharacterFunctions::isLowerCase (const char character) throw()
  8040. {
  8041. return islower (character) != 0;
  8042. }
  8043. bool CharacterFunctions::isLowerCase (const juce_wchar character) throw()
  8044. {
  8045. #if JUCE_WIN32
  8046. return iswlower (character) != 0;
  8047. #else
  8048. return toUpperCase (character) != character;
  8049. #endif
  8050. }
  8051. bool CharacterFunctions::isWhitespace (const char character) throw()
  8052. {
  8053. return character == ' ' || (character <= 13 && character >= 9);
  8054. }
  8055. bool CharacterFunctions::isWhitespace (const juce_wchar character) throw()
  8056. {
  8057. return iswspace (character) != 0;
  8058. }
  8059. bool CharacterFunctions::isDigit (const char character) throw()
  8060. {
  8061. return (character >= '0' && character <= '9');
  8062. }
  8063. bool CharacterFunctions::isDigit (const juce_wchar character) throw()
  8064. {
  8065. return iswdigit (character) != 0;
  8066. }
  8067. bool CharacterFunctions::isLetter (const char character) throw()
  8068. {
  8069. return (character >= 'a' && character <= 'z')
  8070. || (character >= 'A' && character <= 'Z');
  8071. }
  8072. bool CharacterFunctions::isLetter (const juce_wchar character) throw()
  8073. {
  8074. return iswalpha (character) != 0;
  8075. }
  8076. bool CharacterFunctions::isLetterOrDigit (const char character) throw()
  8077. {
  8078. return (character >= 'a' && character <= 'z')
  8079. || (character >= 'A' && character <= 'Z')
  8080. || (character >= '0' && character <= '9');
  8081. }
  8082. bool CharacterFunctions::isLetterOrDigit (const juce_wchar character) throw()
  8083. {
  8084. return iswalnum (character) != 0;
  8085. }
  8086. int CharacterFunctions::getHexDigitValue (const juce_wchar digit) throw()
  8087. {
  8088. if (digit >= '0' && digit <= '9')
  8089. return digit - '0';
  8090. else if (digit >= 'a' && digit <= 'f')
  8091. return digit - ('a' - 10);
  8092. else if (digit >= 'A' && digit <= 'F')
  8093. return digit - ('A' - 10);
  8094. return -1;
  8095. }
  8096. END_JUCE_NAMESPACE
  8097. /*** End of inlined file: juce_CharacterFunctions.cpp ***/
  8098. /*** Start of inlined file: juce_LocalisedStrings.cpp ***/
  8099. BEGIN_JUCE_NAMESPACE
  8100. LocalisedStrings::LocalisedStrings (const String& fileContents)
  8101. {
  8102. loadFromText (fileContents);
  8103. }
  8104. LocalisedStrings::LocalisedStrings (const File& fileToLoad)
  8105. {
  8106. loadFromText (fileToLoad.loadFileAsString());
  8107. }
  8108. LocalisedStrings::~LocalisedStrings()
  8109. {
  8110. }
  8111. const String LocalisedStrings::translate (const String& text) const
  8112. {
  8113. return translations.getValue (text, text);
  8114. }
  8115. static int findCloseQuote (const String& text, int startPos)
  8116. {
  8117. tchar lastChar = 0;
  8118. for (;;)
  8119. {
  8120. const tchar c = text [startPos];
  8121. if (c == 0 || (c == '"' && lastChar != '\\'))
  8122. break;
  8123. lastChar = c;
  8124. ++startPos;
  8125. }
  8126. return startPos;
  8127. }
  8128. static const String unescapeString (const String& s)
  8129. {
  8130. return s.replace (T("\\\""), T("\""))
  8131. .replace (T("\\\'"), T("\'"))
  8132. .replace (T("\\t"), T("\t"))
  8133. .replace (T("\\r"), T("\r"))
  8134. .replace (T("\\n"), T("\n"));
  8135. }
  8136. void LocalisedStrings::loadFromText (const String& fileContents)
  8137. {
  8138. StringArray lines;
  8139. lines.addLines (fileContents);
  8140. for (int i = 0; i < lines.size(); ++i)
  8141. {
  8142. String line (lines[i].trim());
  8143. if (line.startsWithChar ('"'))
  8144. {
  8145. int closeQuote = findCloseQuote (line, 1);
  8146. const String originalText (unescapeString (line.substring (1, closeQuote)));
  8147. if (originalText.isNotEmpty())
  8148. {
  8149. const int openingQuote = findCloseQuote (line, closeQuote + 1);
  8150. closeQuote = findCloseQuote (line, openingQuote + 1);
  8151. const String newText (unescapeString (line.substring (openingQuote + 1, closeQuote)));
  8152. if (newText.isNotEmpty())
  8153. translations.set (originalText, newText);
  8154. }
  8155. }
  8156. else if (line.startsWithIgnoreCase (T("language:")))
  8157. {
  8158. languageName = line.substring (9).trim();
  8159. }
  8160. else if (line.startsWithIgnoreCase (T("countries:")))
  8161. {
  8162. countryCodes.addTokens (line.substring (10).trim(), true);
  8163. countryCodes.trim();
  8164. countryCodes.removeEmptyStrings();
  8165. }
  8166. }
  8167. }
  8168. void LocalisedStrings::setIgnoresCase (const bool shouldIgnoreCase)
  8169. {
  8170. translations.setIgnoresCase (shouldIgnoreCase);
  8171. }
  8172. static CriticalSection currentMappingsLock;
  8173. static LocalisedStrings* currentMappings = 0;
  8174. void LocalisedStrings::setCurrentMappings (LocalisedStrings* newTranslations)
  8175. {
  8176. const ScopedLock sl (currentMappingsLock);
  8177. delete currentMappings;
  8178. currentMappings = newTranslations;
  8179. }
  8180. LocalisedStrings* LocalisedStrings::getCurrentMappings()
  8181. {
  8182. return currentMappings;
  8183. }
  8184. const String LocalisedStrings::translateWithCurrentMappings (const String& text)
  8185. {
  8186. const ScopedLock sl (currentMappingsLock);
  8187. if (currentMappings != 0)
  8188. return currentMappings->translate (text);
  8189. return text;
  8190. }
  8191. const String LocalisedStrings::translateWithCurrentMappings (const char* text)
  8192. {
  8193. return translateWithCurrentMappings (String (text));
  8194. }
  8195. END_JUCE_NAMESPACE
  8196. /*** End of inlined file: juce_LocalisedStrings.cpp ***/
  8197. /*** Start of inlined file: juce_String.cpp ***/
  8198. #ifdef _MSC_VER
  8199. #pragma warning (push)
  8200. #pragma warning (disable: 4514)
  8201. #endif
  8202. #include <locale>
  8203. #if JUCE_MSVC
  8204. #include <float.h>
  8205. #endif
  8206. BEGIN_JUCE_NAMESPACE
  8207. #ifdef _MSC_VER
  8208. #pragma warning (pop)
  8209. #endif
  8210. #if defined (JUCE_STRINGS_ARE_UNICODE) && ! JUCE_STRINGS_ARE_UNICODE
  8211. #error "JUCE_STRINGS_ARE_UNICODE is deprecated! All strings are now unicode by default."
  8212. #endif
  8213. class StringHolder
  8214. {
  8215. public:
  8216. StringHolder()
  8217. : refCount (0x3fffffff), allocatedNumChars (0)
  8218. {
  8219. text[0] = 0;
  8220. }
  8221. static juce_wchar* create (const size_t numChars)
  8222. {
  8223. StringHolder* const s = reinterpret_cast <StringHolder*> (new char [sizeof (StringHolder) + numChars * sizeof (juce_wchar)]);
  8224. s->refCount = 0;
  8225. s->allocatedNumChars = numChars;
  8226. return &(s->text[0]);
  8227. }
  8228. static inline juce_wchar* getEmpty() throw()
  8229. {
  8230. return &(empty.text[0]);
  8231. }
  8232. static void retain (juce_wchar* const text) throw()
  8233. {
  8234. Atomic::increment (bufferFromText (text)->refCount);
  8235. }
  8236. static inline void release (StringHolder* const b) throw()
  8237. {
  8238. if (Atomic::decrementAndReturn (b->refCount) == -1 && b != &empty)
  8239. delete[] reinterpret_cast <char*> (b);
  8240. }
  8241. static void release (juce_wchar* const text) throw()
  8242. {
  8243. release (bufferFromText (text));
  8244. }
  8245. static juce_wchar* makeUnique (juce_wchar* const text)
  8246. {
  8247. StringHolder* const b = bufferFromText (text);
  8248. if (b->refCount <= 0)
  8249. return text;
  8250. juce_wchar* const newText = create (b->allocatedNumChars);
  8251. copyChars (newText, text, b->allocatedNumChars);
  8252. release (b);
  8253. return newText;
  8254. }
  8255. static juce_wchar* makeUniqueWithSize (juce_wchar* const text, size_t numChars)
  8256. {
  8257. StringHolder* const b = bufferFromText (text);
  8258. if (b->refCount <= 0 && b->allocatedNumChars >= numChars)
  8259. return text;
  8260. juce_wchar* const newText = create (jmax (b->allocatedNumChars, numChars));
  8261. copyChars (newText, text, b->allocatedNumChars);
  8262. release (b);
  8263. return newText;
  8264. }
  8265. static size_t getAllocatedNumChars (juce_wchar* const text) throw()
  8266. {
  8267. return bufferFromText (text)->allocatedNumChars;
  8268. }
  8269. static void copyChars (juce_wchar* const dest, const juce_wchar* const src, const size_t numChars) throw()
  8270. {
  8271. memcpy (dest, src, numChars * sizeof (juce_wchar));
  8272. dest [numChars] = 0;
  8273. }
  8274. int refCount;
  8275. size_t allocatedNumChars;
  8276. juce_wchar text[1];
  8277. static StringHolder empty;
  8278. private:
  8279. static inline StringHolder* bufferFromText (juce_wchar* const text) throw()
  8280. {
  8281. // (Can't use offsetof() here because of warnings about this not being a POD)
  8282. return reinterpret_cast <StringHolder*> (reinterpret_cast <char*> (text)
  8283. - (reinterpret_cast <size_t> (reinterpret_cast <StringHolder*> (1)->text) - 1));
  8284. }
  8285. };
  8286. StringHolder StringHolder::empty;
  8287. const String String::empty;
  8288. void String::createInternal (const juce_wchar* const t, const size_t numChars)
  8289. {
  8290. jassert (t[numChars] == 0); // must have a null terminator
  8291. text = StringHolder::create (numChars);
  8292. StringHolder::copyChars (text, t, numChars);
  8293. }
  8294. void String::appendInternal (const juce_wchar* const newText, const int numExtraChars)
  8295. {
  8296. if (numExtraChars > 0)
  8297. {
  8298. const int oldLen = length();
  8299. const int newTotalLen = oldLen + numExtraChars;
  8300. text = StringHolder::makeUniqueWithSize (text, newTotalLen);
  8301. StringHolder::copyChars (text + oldLen, newText, numExtraChars);
  8302. }
  8303. }
  8304. void String::preallocateStorage (const size_t numChars)
  8305. {
  8306. text = StringHolder::makeUniqueWithSize (text, numChars);
  8307. }
  8308. String::String() throw()
  8309. : text (StringHolder::getEmpty())
  8310. {
  8311. }
  8312. String::~String() throw()
  8313. {
  8314. StringHolder::release (text);
  8315. }
  8316. String::String (const String& other) throw()
  8317. : text (other.text)
  8318. {
  8319. StringHolder::retain (text);
  8320. }
  8321. void String::swapWith (String& other) throw()
  8322. {
  8323. swapVariables (text, other.text);
  8324. }
  8325. String& String::operator= (const String& other) throw()
  8326. {
  8327. juce_wchar* const newText = other.text;
  8328. StringHolder::retain (newText);
  8329. StringHolder::release (static_cast <juce_wchar*> (Atomic::swapPointers ((void* volatile*) &text, newText)));
  8330. return *this;
  8331. }
  8332. String::String (const size_t numChars, const int /*dummyVariable*/)
  8333. : text (StringHolder::create (numChars))
  8334. {
  8335. }
  8336. String::String (const String& stringToCopy, const size_t charsToAllocate)
  8337. {
  8338. const size_t otherSize = StringHolder::getAllocatedNumChars (stringToCopy.text);
  8339. text = StringHolder::create (jmax (charsToAllocate, otherSize));
  8340. StringHolder::copyChars (text, stringToCopy.text, otherSize);
  8341. }
  8342. String::String (const char* const t)
  8343. {
  8344. if (t != 0 && *t != 0)
  8345. {
  8346. const int len = CharacterFunctions::length (t);
  8347. text = StringHolder::create (len);
  8348. CharacterFunctions::copy (text, t, len + 1);
  8349. }
  8350. else
  8351. {
  8352. text = StringHolder::getEmpty();
  8353. }
  8354. }
  8355. String::String (const juce_wchar* const t)
  8356. {
  8357. if (t != 0 && *t != 0)
  8358. {
  8359. const int len = CharacterFunctions::length (t);
  8360. text = StringHolder::create (len);
  8361. StringHolder::copyChars (text, t, len);
  8362. }
  8363. else
  8364. {
  8365. text = StringHolder::getEmpty();
  8366. }
  8367. }
  8368. String::String (const char* const t, const size_t maxChars)
  8369. {
  8370. int i;
  8371. for (i = 0; (size_t) i < maxChars; ++i)
  8372. if (t[i] == 0)
  8373. break;
  8374. if (i > 0)
  8375. {
  8376. text = StringHolder::create (i);
  8377. CharacterFunctions::copy (text, t, i);
  8378. text[i] = 0;
  8379. }
  8380. else
  8381. {
  8382. text = StringHolder::getEmpty();
  8383. }
  8384. }
  8385. String::String (const juce_wchar* const t, const size_t maxChars)
  8386. {
  8387. int i;
  8388. for (i = 0; (size_t) i < maxChars; ++i)
  8389. if (t[i] == 0)
  8390. break;
  8391. if (i > 0)
  8392. {
  8393. text = StringHolder::create (i);
  8394. StringHolder::copyChars (text, t, i);
  8395. }
  8396. else
  8397. {
  8398. text = StringHolder::getEmpty();
  8399. }
  8400. }
  8401. const String String::charToString (const juce_wchar character)
  8402. {
  8403. String result ((size_t) 1, (int) 0);
  8404. result.text[0] = character;
  8405. result.text[1] = 0;
  8406. return result;
  8407. }
  8408. namespace NumberToStringConverters
  8409. {
  8410. // pass in a pointer to the END of a buffer..
  8411. static juce_wchar* int64ToString (juce_wchar* t, const int64 n) throw()
  8412. {
  8413. *--t = 0;
  8414. int64 v = (n >= 0) ? n : -n;
  8415. do
  8416. {
  8417. *--t = (juce_wchar) ('0' + (int) (v % 10));
  8418. v /= 10;
  8419. } while (v > 0);
  8420. if (n < 0)
  8421. *--t = '-';
  8422. return t;
  8423. }
  8424. static juce_wchar* uint64ToString (juce_wchar* t, int64 v) throw()
  8425. {
  8426. *--t = 0;
  8427. do
  8428. {
  8429. *--t = (juce_wchar) ('0' + (int) (v % 10));
  8430. v /= 10;
  8431. } while (v > 0);
  8432. return t;
  8433. }
  8434. static juce_wchar* intToString (juce_wchar* t, const int n) throw()
  8435. {
  8436. if (n == (int) 0x80000000) // (would cause an overflow)
  8437. return int64ToString (t, n);
  8438. *--t = 0;
  8439. int v = abs (n);
  8440. do
  8441. {
  8442. *--t = (juce_wchar) ('0' + (v % 10));
  8443. v /= 10;
  8444. } while (v > 0);
  8445. if (n < 0)
  8446. *--t = '-';
  8447. return t;
  8448. }
  8449. static juce_wchar* uintToString (juce_wchar* t, unsigned int v) throw()
  8450. {
  8451. *--t = 0;
  8452. do
  8453. {
  8454. *--t = (juce_wchar) ('0' + (v % 10));
  8455. v /= 10;
  8456. } while (v > 0);
  8457. return t;
  8458. }
  8459. static juce_wchar getDecimalPoint()
  8460. {
  8461. #if JUCE_WINDOWS && _MSC_VER < 1400
  8462. static juce_wchar dp = std::_USE (std::locale(), std::numpunct <wchar_t>).decimal_point();
  8463. #else
  8464. static juce_wchar dp = std::use_facet <std::numpunct <wchar_t> > (std::locale()).decimal_point();
  8465. #endif
  8466. return dp;
  8467. }
  8468. static juce_wchar* doubleToString (juce_wchar* buffer, int numChars, double n, int numDecPlaces, size_t& len) throw()
  8469. {
  8470. if (numDecPlaces > 0 && n > -1.0e20 && n < 1.0e20)
  8471. {
  8472. juce_wchar* const end = buffer + numChars;
  8473. juce_wchar* t = end;
  8474. int64 v = (int64) (pow (10.0, numDecPlaces) * fabs (n) + 0.5);
  8475. *--t = (juce_wchar) 0;
  8476. while (numDecPlaces >= 0 || v > 0)
  8477. {
  8478. if (numDecPlaces == 0)
  8479. *--t = getDecimalPoint();
  8480. *--t = (juce_wchar) ('0' + (v % 10));
  8481. v /= 10;
  8482. --numDecPlaces;
  8483. }
  8484. if (n < 0)
  8485. *--t = '-';
  8486. len = end - t - 1;
  8487. return t;
  8488. }
  8489. else
  8490. {
  8491. #if JUCE_WIN32
  8492. #if _MSC_VER <= 1200
  8493. len = _snwprintf (buffer, numChars, L"%.9g", n);
  8494. #else
  8495. len = _snwprintf_s (buffer, numChars, _TRUNCATE, L"%.9g", n);
  8496. #endif
  8497. #else
  8498. len = swprintf (buffer, numChars, L"%.9g", n);
  8499. #endif
  8500. return buffer;
  8501. }
  8502. }
  8503. }
  8504. String::String (const int number)
  8505. {
  8506. juce_wchar buffer [16];
  8507. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8508. juce_wchar* const start = NumberToStringConverters::intToString (end, number);
  8509. createInternal (start, end - start - 1);
  8510. }
  8511. String::String (const unsigned int number)
  8512. {
  8513. juce_wchar buffer [16];
  8514. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8515. juce_wchar* const start = NumberToStringConverters::uintToString (end, number);
  8516. createInternal (start, end - start - 1);
  8517. }
  8518. String::String (const short number)
  8519. {
  8520. juce_wchar buffer [16];
  8521. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8522. juce_wchar* const start = NumberToStringConverters::intToString (end, (int) number);
  8523. createInternal (start, end - start - 1);
  8524. }
  8525. String::String (const unsigned short number)
  8526. {
  8527. juce_wchar buffer [16];
  8528. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8529. juce_wchar* const start = NumberToStringConverters::uintToString (end, (unsigned int) number);
  8530. createInternal (start, end - start - 1);
  8531. }
  8532. String::String (const int64 number)
  8533. {
  8534. juce_wchar buffer [32];
  8535. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8536. juce_wchar* const start = NumberToStringConverters::int64ToString (end, number);
  8537. createInternal (start, end - start - 1);
  8538. }
  8539. String::String (const uint64 number)
  8540. {
  8541. juce_wchar buffer [32];
  8542. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8543. juce_wchar* const start = NumberToStringConverters::uint64ToString (end, number);
  8544. createInternal (start, end - start - 1);
  8545. }
  8546. String::String (const float number, const int numberOfDecimalPlaces)
  8547. {
  8548. juce_wchar buffer [48];
  8549. size_t len;
  8550. juce_wchar* start = NumberToStringConverters::doubleToString (buffer, numElementsInArray (buffer), (double) number, numberOfDecimalPlaces, len);
  8551. createInternal (start, len);
  8552. }
  8553. String::String (const double number, const int numberOfDecimalPlaces)
  8554. {
  8555. juce_wchar buffer [48];
  8556. size_t len;
  8557. juce_wchar* start = NumberToStringConverters::doubleToString (buffer, numElementsInArray (buffer), number, numberOfDecimalPlaces, len);
  8558. createInternal (start, len);
  8559. }
  8560. int String::length() const throw()
  8561. {
  8562. return CharacterFunctions::length (text);
  8563. }
  8564. int String::hashCode() const throw()
  8565. {
  8566. const juce_wchar* t = text;
  8567. int result = 0;
  8568. while (*t != (juce_wchar) 0)
  8569. result = 31 * result + *t++;
  8570. return result;
  8571. }
  8572. int64 String::hashCode64() const throw()
  8573. {
  8574. const juce_wchar* t = text;
  8575. int64 result = 0;
  8576. while (*t != (juce_wchar) 0)
  8577. result = 101 * result + *t++;
  8578. return result;
  8579. }
  8580. bool JUCE_CALLTYPE operator== (const String& string1, const String& string2) throw()
  8581. {
  8582. return string1.compare (string2) == 0;
  8583. }
  8584. bool JUCE_CALLTYPE operator== (const String& string1, const char* string2) throw()
  8585. {
  8586. return string1.compare (string2) == 0;
  8587. }
  8588. bool JUCE_CALLTYPE operator== (const String& string1, const juce_wchar* string2) throw()
  8589. {
  8590. return string1.compare (string2) == 0;
  8591. }
  8592. bool JUCE_CALLTYPE operator!= (const String& string1, const String& string2) throw()
  8593. {
  8594. return string1.compare (string2) != 0;
  8595. }
  8596. bool JUCE_CALLTYPE operator!= (const String& string1, const char* string2) throw()
  8597. {
  8598. return string1.compare (string2) != 0;
  8599. }
  8600. bool JUCE_CALLTYPE operator!= (const String& string1, const juce_wchar* string2) throw()
  8601. {
  8602. return string1.compare (string2) != 0;
  8603. }
  8604. bool JUCE_CALLTYPE operator> (const String& string1, const String& string2) throw()
  8605. {
  8606. return string1.compare (string2) > 0;
  8607. }
  8608. bool JUCE_CALLTYPE operator< (const String& string1, const String& string2) throw()
  8609. {
  8610. return string1.compare (string2) < 0;
  8611. }
  8612. bool JUCE_CALLTYPE operator>= (const String& string1, const String& string2) throw()
  8613. {
  8614. return string1.compare (string2) >= 0;
  8615. }
  8616. bool JUCE_CALLTYPE operator<= (const String& string1, const String& string2) throw()
  8617. {
  8618. return string1.compare (string2) <= 0;
  8619. }
  8620. bool String::equalsIgnoreCase (const juce_wchar* t) const throw()
  8621. {
  8622. return t != 0 ? CharacterFunctions::compareIgnoreCase (text, t) == 0
  8623. : isEmpty();
  8624. }
  8625. bool String::equalsIgnoreCase (const String& other) const throw()
  8626. {
  8627. return text == other.text
  8628. || CharacterFunctions::compareIgnoreCase (text, other.text) == 0;
  8629. }
  8630. int String::compare (const String& other) const throw()
  8631. {
  8632. return (text == other.text) ? 0 : CharacterFunctions::compare (text, other.text);
  8633. }
  8634. int String::compare (const char* other) const throw()
  8635. {
  8636. return other == 0 ? isEmpty() : CharacterFunctions::compare (text, other);
  8637. }
  8638. int String::compare (const juce_wchar* other) const throw()
  8639. {
  8640. return other == 0 ? isEmpty() : CharacterFunctions::compare (text, other);
  8641. }
  8642. int String::compareIgnoreCase (const String& other) const throw()
  8643. {
  8644. return (text == other.text) ? 0 : CharacterFunctions::compareIgnoreCase (text, other.text);
  8645. }
  8646. int String::compareLexicographically (const String& other) const throw()
  8647. {
  8648. const juce_wchar* s1 = text;
  8649. while (*s1 != 0 && ! CharacterFunctions::isLetterOrDigit (*s1))
  8650. ++s1;
  8651. const juce_wchar* s2 = other.text;
  8652. while (*s2 != 0 && ! CharacterFunctions::isLetterOrDigit (*s2))
  8653. ++s2;
  8654. return CharacterFunctions::compareIgnoreCase (s1, s2);
  8655. }
  8656. String& String::operator+= (const juce_wchar* const t)
  8657. {
  8658. if (t != 0)
  8659. appendInternal (t, CharacterFunctions::length (t));
  8660. return *this;
  8661. }
  8662. String& String::operator+= (const String& other)
  8663. {
  8664. if (isEmpty())
  8665. operator= (other);
  8666. else
  8667. appendInternal (other.text, other.length());
  8668. return *this;
  8669. }
  8670. String& String::operator+= (const char ch)
  8671. {
  8672. const juce_wchar asString[] = { (juce_wchar) ch, 0 };
  8673. return operator+= ((const juce_wchar*) asString);
  8674. }
  8675. String& String::operator+= (const juce_wchar ch)
  8676. {
  8677. const juce_wchar asString[] = { (juce_wchar) ch, 0 };
  8678. return operator+= ((const juce_wchar*) asString);
  8679. }
  8680. String& String::operator+= (const int number)
  8681. {
  8682. juce_wchar buffer [16];
  8683. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8684. juce_wchar* const start = NumberToStringConverters::intToString (end, number);
  8685. appendInternal (start, (int) (end - start));
  8686. return *this;
  8687. }
  8688. String& String::operator+= (const unsigned int number)
  8689. {
  8690. juce_wchar buffer [16];
  8691. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8692. juce_wchar* const start = NumberToStringConverters::uintToString (end, number);
  8693. appendInternal (start, (int) (end - start));
  8694. return *this;
  8695. }
  8696. void String::append (const juce_wchar* const other, const int howMany)
  8697. {
  8698. if (howMany > 0)
  8699. {
  8700. int i;
  8701. for (i = 0; i < howMany; ++i)
  8702. if (other[i] == 0)
  8703. break;
  8704. appendInternal (other, i);
  8705. }
  8706. }
  8707. const String JUCE_CALLTYPE operator+ (const char* const string1, const String& string2)
  8708. {
  8709. String s (string1);
  8710. return s += string2;
  8711. }
  8712. const String JUCE_CALLTYPE operator+ (const juce_wchar* const string1, const String& string2)
  8713. {
  8714. String s (string1);
  8715. return s += string2;
  8716. }
  8717. const String JUCE_CALLTYPE operator+ (const char string1, const String& string2)
  8718. {
  8719. return String::charToString (string1) + string2;
  8720. }
  8721. const String JUCE_CALLTYPE operator+ (const juce_wchar string1, const String& string2)
  8722. {
  8723. return String::charToString (string1) + string2;
  8724. }
  8725. const String JUCE_CALLTYPE operator+ (String string1, const String& string2)
  8726. {
  8727. return string1 += string2;
  8728. }
  8729. const String JUCE_CALLTYPE operator+ (String string1, const char* const string2)
  8730. {
  8731. return string1 += string2;
  8732. }
  8733. const String JUCE_CALLTYPE operator+ (String string1, const juce_wchar* const string2)
  8734. {
  8735. return string1 += string2;
  8736. }
  8737. const String JUCE_CALLTYPE operator+ (String string1, const char string2)
  8738. {
  8739. return string1 += string2;
  8740. }
  8741. const String JUCE_CALLTYPE operator+ (String string1, const juce_wchar string2)
  8742. {
  8743. return string1 += string2;
  8744. }
  8745. String& JUCE_CALLTYPE operator<< (String& string1, const char characterToAppend)
  8746. {
  8747. return string1 += characterToAppend;
  8748. }
  8749. String& JUCE_CALLTYPE operator<< (String& string1, const juce_wchar characterToAppend)
  8750. {
  8751. return string1 += characterToAppend;
  8752. }
  8753. String& JUCE_CALLTYPE operator<< (String& string1, const char* const string2)
  8754. {
  8755. return string1 += string2;
  8756. }
  8757. String& JUCE_CALLTYPE operator<< (String& string1, const juce_wchar* const string2)
  8758. {
  8759. return string1 += string2;
  8760. }
  8761. String& JUCE_CALLTYPE operator<< (String& string1, const String& string2)
  8762. {
  8763. return string1 += string2;
  8764. }
  8765. String& JUCE_CALLTYPE operator<< (String& string1, const short number)
  8766. {
  8767. return string1 += (int) number;
  8768. }
  8769. String& JUCE_CALLTYPE operator<< (String& string1, const int number)
  8770. {
  8771. return string1 += number;
  8772. }
  8773. String& JUCE_CALLTYPE operator<< (String& string1, const unsigned int number)
  8774. {
  8775. return string1 += number;
  8776. }
  8777. String& JUCE_CALLTYPE operator<< (String& string1, const long number)
  8778. {
  8779. return string1 += (int) number;
  8780. }
  8781. String& JUCE_CALLTYPE operator<< (String& string1, const unsigned long number)
  8782. {
  8783. return string1 += (unsigned int) number;
  8784. }
  8785. String& JUCE_CALLTYPE operator<< (String& string1, const float number)
  8786. {
  8787. return string1 += String (number);
  8788. }
  8789. String& JUCE_CALLTYPE operator<< (String& string1, const double number)
  8790. {
  8791. return string1 += String (number);
  8792. }
  8793. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const String& text)
  8794. {
  8795. // (This avoids using toUTF8() to prevent the memory bloat that it would leave behind
  8796. // if lots of large, persistent strings were to be written to streams).
  8797. const int numBytes = text.getNumBytesAsUTF8();
  8798. HeapBlock<char> temp (numBytes + 1);
  8799. text.copyToUTF8 (temp, numBytes + 1);
  8800. stream.write (temp, numBytes);
  8801. return stream;
  8802. }
  8803. int String::indexOfChar (const juce_wchar character) const throw()
  8804. {
  8805. const juce_wchar* t = text;
  8806. for (;;)
  8807. {
  8808. if (*t == character)
  8809. return (int) (t - text);
  8810. if (*t++ == 0)
  8811. return -1;
  8812. }
  8813. }
  8814. int String::lastIndexOfChar (const juce_wchar character) const throw()
  8815. {
  8816. for (int i = length(); --i >= 0;)
  8817. if (text[i] == character)
  8818. return i;
  8819. return -1;
  8820. }
  8821. int String::indexOf (const juce_wchar* const t) const throw()
  8822. {
  8823. const juce_wchar* const r = CharacterFunctions::find (text, t);
  8824. return (r == 0) ? -1
  8825. : (int) (r - text);
  8826. }
  8827. int String::indexOfChar (const int startIndex,
  8828. const juce_wchar character) const throw()
  8829. {
  8830. if (startIndex >= 0 && startIndex >= length())
  8831. return -1;
  8832. const juce_wchar* t = text + jmax (0, startIndex);
  8833. for (;;)
  8834. {
  8835. if (*t == character)
  8836. return (int) (t - text);
  8837. if (*t == 0)
  8838. return -1;
  8839. ++t;
  8840. }
  8841. }
  8842. int String::indexOfAnyOf (const juce_wchar* const charactersToLookFor,
  8843. const int startIndex,
  8844. const bool ignoreCase) const throw()
  8845. {
  8846. if (charactersToLookFor == 0
  8847. || (startIndex >= 0 && startIndex >= length()))
  8848. return -1;
  8849. const juce_wchar* t = text + jmax (0, startIndex);
  8850. while (*t != 0)
  8851. {
  8852. if (CharacterFunctions::indexOfChar (charactersToLookFor, *t, ignoreCase) >= 0)
  8853. return (int) (t - text);
  8854. ++t;
  8855. }
  8856. return -1;
  8857. }
  8858. int String::indexOf (const int startIndex,
  8859. const juce_wchar* const other) const throw()
  8860. {
  8861. if (other == 0 || startIndex >= length())
  8862. return -1;
  8863. const juce_wchar* const found = CharacterFunctions::find (text + jmax (0, startIndex), other);
  8864. return (found == 0) ? -1
  8865. : (int) (found - text);
  8866. }
  8867. int String::indexOfIgnoreCase (const juce_wchar* const other) const throw()
  8868. {
  8869. if (other != 0 && *other != 0)
  8870. {
  8871. const int len = CharacterFunctions::length (other);
  8872. const int end = length() - len;
  8873. for (int i = 0; i <= end; ++i)
  8874. if (CharacterFunctions::compareIgnoreCase (text + i, other, len) == 0)
  8875. return i;
  8876. }
  8877. return -1;
  8878. }
  8879. int String::indexOfIgnoreCase (const int startIndex,
  8880. const juce_wchar* const other) const throw()
  8881. {
  8882. if (other != 0 && *other != 0)
  8883. {
  8884. const int len = CharacterFunctions::length (other);
  8885. const int end = length() - len;
  8886. for (int i = jmax (0, startIndex); i <= end; ++i)
  8887. if (CharacterFunctions::compareIgnoreCase (text + i, other, len) == 0)
  8888. return i;
  8889. }
  8890. return -1;
  8891. }
  8892. int String::lastIndexOf (const juce_wchar* const other) const throw()
  8893. {
  8894. if (other != 0 && *other != 0)
  8895. {
  8896. const int len = CharacterFunctions::length (other);
  8897. int i = length() - len;
  8898. if (i >= 0)
  8899. {
  8900. const juce_wchar* n = text + i;
  8901. while (i >= 0)
  8902. {
  8903. if (CharacterFunctions::compare (n--, other, len) == 0)
  8904. return i;
  8905. --i;
  8906. }
  8907. }
  8908. }
  8909. return -1;
  8910. }
  8911. int String::lastIndexOfIgnoreCase (const juce_wchar* const other) const throw()
  8912. {
  8913. if (other != 0 && *other != 0)
  8914. {
  8915. const int len = CharacterFunctions::length (other);
  8916. int i = length() - len;
  8917. if (i >= 0)
  8918. {
  8919. const juce_wchar* n = text + i;
  8920. while (i >= 0)
  8921. {
  8922. if (CharacterFunctions::compareIgnoreCase (n--, other, len) == 0)
  8923. return i;
  8924. --i;
  8925. }
  8926. }
  8927. }
  8928. return -1;
  8929. }
  8930. int String::lastIndexOfAnyOf (const juce_wchar* const charactersToLookFor,
  8931. const bool ignoreCase) const throw()
  8932. {
  8933. for (int i = length(); --i >= 0;)
  8934. if (CharacterFunctions::indexOfChar (charactersToLookFor, text[i], ignoreCase) >= 0)
  8935. return i;
  8936. return -1;
  8937. }
  8938. bool String::contains (const juce_wchar* const other) const throw()
  8939. {
  8940. return indexOf (other) >= 0;
  8941. }
  8942. bool String::containsChar (const juce_wchar character) const throw()
  8943. {
  8944. const juce_wchar* t = text;
  8945. for (;;)
  8946. {
  8947. if (*t == character)
  8948. return true;
  8949. if (*t == 0)
  8950. return false;
  8951. ++t;
  8952. }
  8953. }
  8954. bool String::containsIgnoreCase (const juce_wchar* const t) const throw()
  8955. {
  8956. return indexOfIgnoreCase (t) >= 0;
  8957. }
  8958. int String::indexOfWholeWord (const juce_wchar* const word) const throw()
  8959. {
  8960. if (word != 0 && *word != 0)
  8961. {
  8962. const int wordLen = CharacterFunctions::length (word);
  8963. const int end = length() - wordLen;
  8964. const juce_wchar* t = text;
  8965. for (int i = 0; i <= end; ++i)
  8966. {
  8967. if (CharacterFunctions::compare (t, word, wordLen) == 0
  8968. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  8969. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  8970. {
  8971. return i;
  8972. }
  8973. ++t;
  8974. }
  8975. }
  8976. return -1;
  8977. }
  8978. int String::indexOfWholeWordIgnoreCase (const juce_wchar* const word) const throw()
  8979. {
  8980. if (word != 0 && *word != 0)
  8981. {
  8982. const int wordLen = CharacterFunctions::length (word);
  8983. const int end = length() - wordLen;
  8984. const juce_wchar* t = text;
  8985. for (int i = 0; i <= end; ++i)
  8986. {
  8987. if (CharacterFunctions::compareIgnoreCase (t, word, wordLen) == 0
  8988. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  8989. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  8990. {
  8991. return i;
  8992. }
  8993. ++t;
  8994. }
  8995. }
  8996. return -1;
  8997. }
  8998. bool String::containsWholeWord (const juce_wchar* const wordToLookFor) const throw()
  8999. {
  9000. return indexOfWholeWord (wordToLookFor) >= 0;
  9001. }
  9002. bool String::containsWholeWordIgnoreCase (const juce_wchar* const wordToLookFor) const throw()
  9003. {
  9004. return indexOfWholeWordIgnoreCase (wordToLookFor) >= 0;
  9005. }
  9006. static int indexOfMatch (const juce_wchar* const wildcard,
  9007. const juce_wchar* const test,
  9008. const bool ignoreCase) throw()
  9009. {
  9010. int start = 0;
  9011. while (test [start] != 0)
  9012. {
  9013. int i = 0;
  9014. for (;;)
  9015. {
  9016. const juce_wchar wc = wildcard [i];
  9017. const juce_wchar c = test [i + start];
  9018. if (wc == c
  9019. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  9020. || (wc == '?' && c != 0))
  9021. {
  9022. if (wc == 0)
  9023. return start;
  9024. ++i;
  9025. }
  9026. else
  9027. {
  9028. if (wc == '*' && (wildcard [i + 1] == 0
  9029. || indexOfMatch (wildcard + i + 1,
  9030. test + start + i,
  9031. ignoreCase) >= 0))
  9032. {
  9033. return start;
  9034. }
  9035. break;
  9036. }
  9037. }
  9038. ++start;
  9039. }
  9040. return -1;
  9041. }
  9042. bool String::matchesWildcard (const juce_wchar* wildcard, const bool ignoreCase) const throw()
  9043. {
  9044. int i = 0;
  9045. for (;;)
  9046. {
  9047. const juce_wchar wc = wildcard [i];
  9048. const juce_wchar c = text [i];
  9049. if (wc == c
  9050. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  9051. || (wc == '?' && c != 0))
  9052. {
  9053. if (wc == 0)
  9054. return true;
  9055. ++i;
  9056. }
  9057. else
  9058. {
  9059. return wc == '*' && (wildcard [i + 1] == 0
  9060. || indexOfMatch (wildcard + i + 1,
  9061. text + i,
  9062. ignoreCase) >= 0);
  9063. }
  9064. }
  9065. }
  9066. const String String::repeatedString (const juce_wchar* const stringToRepeat, int numberOfTimesToRepeat)
  9067. {
  9068. const int len = CharacterFunctions::length (stringToRepeat);
  9069. String result ((size_t) (len * numberOfTimesToRepeat + 1), (int) 0);
  9070. juce_wchar* n = result.text;
  9071. *n = 0;
  9072. while (--numberOfTimesToRepeat >= 0)
  9073. {
  9074. StringHolder::copyChars (n, stringToRepeat, len);
  9075. n += len;
  9076. }
  9077. return result;
  9078. }
  9079. const String String::paddedLeft (const juce_wchar padCharacter, int minimumLength) const
  9080. {
  9081. jassert (padCharacter != 0);
  9082. const int len = length();
  9083. if (len >= minimumLength || padCharacter == 0)
  9084. return *this;
  9085. String result ((size_t) minimumLength + 1, (int) 0);
  9086. juce_wchar* n = result.text;
  9087. minimumLength -= len;
  9088. while (--minimumLength >= 0)
  9089. *n++ = padCharacter;
  9090. StringHolder::copyChars (n, text, len);
  9091. return result;
  9092. }
  9093. const String String::paddedRight (const juce_wchar padCharacter, int minimumLength) const
  9094. {
  9095. jassert (padCharacter != 0);
  9096. const int len = length();
  9097. if (len >= minimumLength || padCharacter == 0)
  9098. return *this;
  9099. String result (*this, (size_t) minimumLength);
  9100. juce_wchar* n = result.text + len;
  9101. minimumLength -= len;
  9102. while (--minimumLength >= 0)
  9103. *n++ = padCharacter;
  9104. *n = 0;
  9105. return result;
  9106. }
  9107. const String String::replaceSection (int index, int numCharsToReplace,
  9108. const juce_wchar* const stringToInsert) const
  9109. {
  9110. if (index < 0)
  9111. {
  9112. // a negative index to replace from?
  9113. jassertfalse
  9114. index = 0;
  9115. }
  9116. if (numCharsToReplace < 0)
  9117. {
  9118. // replacing a negative number of characters?
  9119. numCharsToReplace = 0;
  9120. jassertfalse;
  9121. }
  9122. const int len = length();
  9123. if (index + numCharsToReplace > len)
  9124. {
  9125. if (index > len)
  9126. {
  9127. // replacing beyond the end of the string?
  9128. index = len;
  9129. jassertfalse
  9130. }
  9131. numCharsToReplace = len - index;
  9132. }
  9133. const int newStringLen = (stringToInsert != 0) ? CharacterFunctions::length (stringToInsert) : 0;
  9134. const int newTotalLen = len + newStringLen - numCharsToReplace;
  9135. if (newTotalLen <= 0)
  9136. return String::empty;
  9137. String result ((size_t) newTotalLen, (int) 0);
  9138. StringHolder::copyChars (result.text, text, index);
  9139. if (newStringLen > 0)
  9140. StringHolder::copyChars (result.text + index, stringToInsert, newStringLen);
  9141. const int endStringLen = newTotalLen - (index + newStringLen);
  9142. if (endStringLen > 0)
  9143. StringHolder::copyChars (result.text + (index + newStringLen),
  9144. text + (index + numCharsToReplace),
  9145. endStringLen);
  9146. return result;
  9147. }
  9148. const String String::replace (const juce_wchar* const stringToReplace,
  9149. const juce_wchar* const stringToInsert,
  9150. const bool ignoreCase) const
  9151. {
  9152. const int stringToReplaceLen = CharacterFunctions::length (stringToReplace);
  9153. const int stringToInsertLen = CharacterFunctions::length (stringToInsert);
  9154. int i = 0;
  9155. String result (*this);
  9156. while ((i = (ignoreCase ? result.indexOfIgnoreCase (i, stringToReplace)
  9157. : result.indexOf (i, stringToReplace))) >= 0)
  9158. {
  9159. result = result.replaceSection (i, stringToReplaceLen, stringToInsert);
  9160. i += stringToInsertLen;
  9161. }
  9162. return result;
  9163. }
  9164. const String String::replaceCharacter (const juce_wchar charToReplace, const juce_wchar charToInsert) const
  9165. {
  9166. const int index = indexOfChar (charToReplace);
  9167. if (index < 0)
  9168. return *this;
  9169. String result (*this, size_t());
  9170. juce_wchar* t = result.text + index;
  9171. while (*t != 0)
  9172. {
  9173. if (*t == charToReplace)
  9174. *t = charToInsert;
  9175. ++t;
  9176. }
  9177. return result;
  9178. }
  9179. const String String::replaceCharacters (const String& charactersToReplace,
  9180. const juce_wchar* const charactersToInsertInstead) const
  9181. {
  9182. String result (*this, size_t());
  9183. juce_wchar* t = result.text;
  9184. const int len2 = CharacterFunctions::length (charactersToInsertInstead);
  9185. // the two strings passed in are supposed to be the same length!
  9186. jassert (len2 == charactersToReplace.length());
  9187. while (*t != 0)
  9188. {
  9189. const int index = charactersToReplace.indexOfChar (*t);
  9190. if (((unsigned int) index) < (unsigned int) len2)
  9191. *t = charactersToInsertInstead [index];
  9192. ++t;
  9193. }
  9194. return result;
  9195. }
  9196. bool String::startsWith (const juce_wchar* const other) const throw()
  9197. {
  9198. return other != 0
  9199. && CharacterFunctions::compare (text, other, CharacterFunctions::length (other)) == 0;
  9200. }
  9201. bool String::startsWithIgnoreCase (const juce_wchar* const other) const throw()
  9202. {
  9203. return other != 0
  9204. && CharacterFunctions::compareIgnoreCase (text, other, CharacterFunctions::length (other)) == 0;
  9205. }
  9206. bool String::startsWithChar (const juce_wchar character) const throw()
  9207. {
  9208. jassert (character != 0); // strings can't contain a null character!
  9209. return text[0] == character;
  9210. }
  9211. bool String::endsWithChar (const juce_wchar character) const throw()
  9212. {
  9213. jassert (character != 0); // strings can't contain a null character!
  9214. return text[0] != 0
  9215. && text [length() - 1] == character;
  9216. }
  9217. bool String::endsWith (const juce_wchar* const other) const throw()
  9218. {
  9219. if (other == 0)
  9220. return false;
  9221. const int thisLen = length();
  9222. const int otherLen = CharacterFunctions::length (other);
  9223. return thisLen >= otherLen
  9224. && CharacterFunctions::compare (text + thisLen - otherLen, other) == 0;
  9225. }
  9226. bool String::endsWithIgnoreCase (const juce_wchar* const other) const throw()
  9227. {
  9228. if (other == 0)
  9229. return false;
  9230. const int thisLen = length();
  9231. const int otherLen = CharacterFunctions::length (other);
  9232. return thisLen >= otherLen
  9233. && CharacterFunctions::compareIgnoreCase (text + thisLen - otherLen, other) == 0;
  9234. }
  9235. const String String::toUpperCase() const
  9236. {
  9237. String result (*this, size_t());
  9238. CharacterFunctions::toUpperCase (result.text);
  9239. return result;
  9240. }
  9241. const String String::toLowerCase() const
  9242. {
  9243. String result (*this, size_t());
  9244. CharacterFunctions::toLowerCase (result.text);
  9245. return result;
  9246. }
  9247. juce_wchar& String::operator[] (const int index)
  9248. {
  9249. jassert (((unsigned int) index) <= (unsigned int) length());
  9250. text = StringHolder::makeUnique (text);
  9251. return text [index];
  9252. }
  9253. juce_wchar String::getLastCharacter() const throw()
  9254. {
  9255. return isEmpty() ? juce_wchar() : text [length() - 1];
  9256. }
  9257. const String String::substring (int start, int end) const
  9258. {
  9259. if (start < 0)
  9260. start = 0;
  9261. else if (end <= start)
  9262. return empty;
  9263. int len = 0;
  9264. const juce_wchar* const t = text;
  9265. while (len <= end && t [len] != 0)
  9266. ++len;
  9267. if (end >= len)
  9268. {
  9269. if (start == 0)
  9270. return *this;
  9271. end = len;
  9272. }
  9273. return String (text + start, end - start);
  9274. }
  9275. const String String::substring (const int start) const
  9276. {
  9277. if (start <= 0)
  9278. return *this;
  9279. const int len = length();
  9280. if (start >= len)
  9281. return empty;
  9282. else
  9283. return String (text + start, len - start);
  9284. }
  9285. const String String::dropLastCharacters (const int numberToDrop) const
  9286. {
  9287. return String (text, jmax (0, length() - numberToDrop));
  9288. }
  9289. const String String::getLastCharacters (const int numCharacters) const
  9290. {
  9291. return String (text + jmax (0, length() - jmax (0, numCharacters)));
  9292. }
  9293. const String String::fromFirstOccurrenceOf (const juce_wchar* const sub,
  9294. const bool includeSubString,
  9295. const bool ignoreCase) const
  9296. {
  9297. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9298. : indexOf (sub);
  9299. if (i < 0)
  9300. return empty;
  9301. else
  9302. return substring (includeSubString ? i : i + CharacterFunctions::length (sub));
  9303. }
  9304. const String String::fromLastOccurrenceOf (const juce_wchar* const sub,
  9305. const bool includeSubString,
  9306. const bool ignoreCase) const
  9307. {
  9308. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9309. : lastIndexOf (sub);
  9310. if (i < 0)
  9311. return *this;
  9312. else
  9313. return substring (includeSubString ? i : i + CharacterFunctions::length (sub));
  9314. }
  9315. const String String::upToFirstOccurrenceOf (const juce_wchar* const sub,
  9316. const bool includeSubString,
  9317. const bool ignoreCase) const
  9318. {
  9319. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9320. : indexOf (sub);
  9321. if (i < 0)
  9322. return *this;
  9323. else
  9324. return substring (0, includeSubString ? i + CharacterFunctions::length (sub) : i);
  9325. }
  9326. const String String::upToLastOccurrenceOf (const juce_wchar* const sub,
  9327. const bool includeSubString,
  9328. const bool ignoreCase) const
  9329. {
  9330. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9331. : lastIndexOf (sub);
  9332. if (i < 0)
  9333. return *this;
  9334. return substring (0, includeSubString ? i + CharacterFunctions::length (sub) : i);
  9335. }
  9336. bool String::isQuotedString() const
  9337. {
  9338. const String trimmed (trimStart());
  9339. return trimmed[0] == '"'
  9340. || trimmed[0] == '\'';
  9341. }
  9342. const String String::unquoted() const
  9343. {
  9344. String s (*this);
  9345. if (s.text[0] == '"' || s.text[0] == '\'')
  9346. s = s.substring (1);
  9347. const int lastCharIndex = s.length() - 1;
  9348. if (lastCharIndex >= 0
  9349. && (s [lastCharIndex] == '"' || s[lastCharIndex] == '\''))
  9350. s [lastCharIndex] = 0;
  9351. return s;
  9352. }
  9353. const String String::quoted (const juce_wchar quoteCharacter) const
  9354. {
  9355. if (isEmpty())
  9356. return charToString (quoteCharacter) + quoteCharacter;
  9357. String t (*this);
  9358. if (! t.startsWithChar (quoteCharacter))
  9359. t = charToString (quoteCharacter) + t;
  9360. if (! t.endsWithChar (quoteCharacter))
  9361. t += quoteCharacter;
  9362. return t;
  9363. }
  9364. const String String::trim() const
  9365. {
  9366. if (isEmpty())
  9367. return empty;
  9368. int start = 0;
  9369. while (CharacterFunctions::isWhitespace (text [start]))
  9370. ++start;
  9371. const int len = length();
  9372. int end = len - 1;
  9373. while ((end >= start) && CharacterFunctions::isWhitespace (text [end]))
  9374. --end;
  9375. ++end;
  9376. if (end <= start)
  9377. return empty;
  9378. else if (start > 0 || end < len)
  9379. return String (text + start, end - start);
  9380. else
  9381. return *this;
  9382. }
  9383. const String String::trimStart() const
  9384. {
  9385. if (isEmpty())
  9386. return empty;
  9387. const juce_wchar* t = text;
  9388. while (CharacterFunctions::isWhitespace (*t))
  9389. ++t;
  9390. if (t == text)
  9391. return *this;
  9392. else
  9393. return String (t);
  9394. }
  9395. const String String::trimEnd() const
  9396. {
  9397. if (isEmpty())
  9398. return empty;
  9399. const juce_wchar* endT = text + (length() - 1);
  9400. while ((endT >= text) && CharacterFunctions::isWhitespace (*endT))
  9401. --endT;
  9402. return String (text, (int) (++endT - text));
  9403. }
  9404. const String String::trimCharactersAtStart (const juce_wchar* charactersToTrim) const
  9405. {
  9406. jassert (charactersToTrim != 0);
  9407. if (isEmpty())
  9408. return empty;
  9409. const juce_wchar* t = text;
  9410. while (CharacterFunctions::indexOfCharFast (charactersToTrim, *t) >= 0)
  9411. ++t;
  9412. if (t == text)
  9413. return *this;
  9414. else
  9415. return String (t);
  9416. }
  9417. const String String::trimCharactersAtEnd (const juce_wchar* charactersToTrim) const
  9418. {
  9419. jassert (charactersToTrim != 0);
  9420. if (isEmpty())
  9421. return empty;
  9422. const juce_wchar* endT = text + (length() - 1);
  9423. while ((endT >= text) && CharacterFunctions::indexOfCharFast (charactersToTrim, *endT) >= 0)
  9424. --endT;
  9425. return String (text, (int) (++endT - text));
  9426. }
  9427. const String String::retainCharacters (const juce_wchar* const charactersToRetain) const
  9428. {
  9429. jassert (charactersToRetain != 0);
  9430. if (isEmpty())
  9431. return empty;
  9432. String result (StringHolder::getAllocatedNumChars (text), (int) 0);
  9433. juce_wchar* dst = result.text;
  9434. const juce_wchar* src = text;
  9435. while (*src != 0)
  9436. {
  9437. if (CharacterFunctions::indexOfCharFast (charactersToRetain, *src) >= 0)
  9438. *dst++ = *src;
  9439. ++src;
  9440. }
  9441. *dst = 0;
  9442. return result;
  9443. }
  9444. const String String::removeCharacters (const juce_wchar* const charactersToRemove) const
  9445. {
  9446. jassert (charactersToRemove != 0);
  9447. if (isEmpty())
  9448. return empty;
  9449. String result (StringHolder::getAllocatedNumChars (text), (int) 0);
  9450. juce_wchar* dst = result.text;
  9451. const juce_wchar* src = text;
  9452. while (*src != 0)
  9453. {
  9454. if (CharacterFunctions::indexOfCharFast (charactersToRemove, *src) < 0)
  9455. *dst++ = *src;
  9456. ++src;
  9457. }
  9458. *dst = 0;
  9459. return result;
  9460. }
  9461. const String String::initialSectionContainingOnly (const juce_wchar* const permittedCharacters) const
  9462. {
  9463. return substring (0, CharacterFunctions::getIntialSectionContainingOnly (text, permittedCharacters));
  9464. }
  9465. const String String::initialSectionNotContaining (const juce_wchar* const charactersToStopAt) const
  9466. {
  9467. jassert (charactersToStopAt != 0);
  9468. const juce_wchar* const t = text;
  9469. int i = 0;
  9470. while (t[i] != 0)
  9471. {
  9472. if (CharacterFunctions::indexOfCharFast (charactersToStopAt, t[i]) >= 0)
  9473. return String (text, i);
  9474. ++i;
  9475. }
  9476. return empty;
  9477. }
  9478. bool String::containsOnly (const juce_wchar* const chars) const throw()
  9479. {
  9480. jassert (chars != 0);
  9481. const juce_wchar* t = text;
  9482. while (*t != 0)
  9483. if (CharacterFunctions::indexOfCharFast (chars, *t++) < 0)
  9484. return false;
  9485. return true;
  9486. }
  9487. bool String::containsAnyOf (const juce_wchar* const chars) const throw()
  9488. {
  9489. jassert (chars != 0);
  9490. const juce_wchar* t = text;
  9491. while (*t != 0)
  9492. if (CharacterFunctions::indexOfCharFast (chars, *t++) >= 0)
  9493. return true;
  9494. return false;
  9495. }
  9496. bool String::containsNonWhitespaceChars() const throw()
  9497. {
  9498. const juce_wchar* t = text;
  9499. while (*t != 0)
  9500. if (! CharacterFunctions::isWhitespace (*t++))
  9501. return true;
  9502. return false;
  9503. }
  9504. const String String::formatted (const juce_wchar* const pf, ... )
  9505. {
  9506. jassert (pf != 0);
  9507. va_list args;
  9508. va_start (args, pf);
  9509. size_t bufferSize = 256;
  9510. String result (bufferSize, (int) 0);
  9511. result.text[0] = 0;
  9512. for (;;)
  9513. {
  9514. #if JUCE_LINUX && JUCE_64BIT
  9515. va_list tempArgs;
  9516. va_copy (tempArgs, args);
  9517. const int num = (int) vswprintf (result.text, bufferSize - 1, pf, tempArgs);
  9518. va_end (tempArgs);
  9519. #elif JUCE_WINDOWS
  9520. #ifdef _MSC_VER
  9521. #pragma warning (push)
  9522. #pragma warning (disable: 4996)
  9523. #endif
  9524. const int num = (int) _vsnwprintf (result.text, bufferSize - 1, pf, args);
  9525. #ifdef _MSC_VER
  9526. #pragma warning (pop)
  9527. #endif
  9528. #else
  9529. const int num = (int) vswprintf (result.text, bufferSize - 1, pf, args);
  9530. #endif
  9531. if (num > 0)
  9532. return result;
  9533. bufferSize += 256;
  9534. if (num == 0 || bufferSize > 65536) // the upper limit is a sanity check to avoid situations where vprintf repeatedly
  9535. break; // returns -1 because of an error rather than because it needs more space.
  9536. result.preallocateStorage (bufferSize);
  9537. }
  9538. return empty;
  9539. }
  9540. int String::getIntValue() const throw()
  9541. {
  9542. return CharacterFunctions::getIntValue (text);
  9543. }
  9544. int String::getTrailingIntValue() const throw()
  9545. {
  9546. int n = 0;
  9547. int mult = 1;
  9548. const juce_wchar* t = text + length();
  9549. while (--t >= text)
  9550. {
  9551. const juce_wchar c = *t;
  9552. if (! CharacterFunctions::isDigit (c))
  9553. {
  9554. if (c == '-')
  9555. n = -n;
  9556. break;
  9557. }
  9558. n += mult * (c - '0');
  9559. mult *= 10;
  9560. }
  9561. return n;
  9562. }
  9563. int64 String::getLargeIntValue() const throw()
  9564. {
  9565. return CharacterFunctions::getInt64Value (text);
  9566. }
  9567. float String::getFloatValue() const throw()
  9568. {
  9569. return (float) CharacterFunctions::getDoubleValue (text);
  9570. }
  9571. double String::getDoubleValue() const throw()
  9572. {
  9573. return CharacterFunctions::getDoubleValue (text);
  9574. }
  9575. static const juce_wchar* const hexDigits = T("0123456789abcdef");
  9576. const String String::toHexString (const int number)
  9577. {
  9578. juce_wchar buffer[32];
  9579. juce_wchar* const end = buffer + 32;
  9580. juce_wchar* t = end;
  9581. *--t = 0;
  9582. unsigned int v = (unsigned int) number;
  9583. do
  9584. {
  9585. *--t = hexDigits [v & 15];
  9586. v >>= 4;
  9587. } while (v != 0);
  9588. return String (t, (int) (((char*) end) - (char*) t) - 1);
  9589. }
  9590. const String String::toHexString (const int64 number)
  9591. {
  9592. juce_wchar buffer[32];
  9593. juce_wchar* const end = buffer + 32;
  9594. juce_wchar* t = end;
  9595. *--t = 0;
  9596. uint64 v = (uint64) number;
  9597. do
  9598. {
  9599. *--t = hexDigits [(int) (v & 15)];
  9600. v >>= 4;
  9601. } while (v != 0);
  9602. return String (t, (int) (((char*) end) - (char*) t));
  9603. }
  9604. const String String::toHexString (const short number)
  9605. {
  9606. return toHexString ((int) (unsigned short) number);
  9607. }
  9608. const String String::toHexString (const unsigned char* data,
  9609. const int size,
  9610. const int groupSize)
  9611. {
  9612. if (size <= 0)
  9613. return empty;
  9614. int numChars = (size * 2) + 2;
  9615. if (groupSize > 0)
  9616. numChars += size / groupSize;
  9617. String s ((size_t) numChars, (int) 0);
  9618. juce_wchar* d = s.text;
  9619. for (int i = 0; i < size; ++i)
  9620. {
  9621. *d++ = hexDigits [(*data) >> 4];
  9622. *d++ = hexDigits [(*data) & 0xf];
  9623. ++data;
  9624. if (groupSize > 0 && (i % groupSize) == (groupSize - 1) && i < (size - 1))
  9625. *d++ = ' ';
  9626. }
  9627. *d = 0;
  9628. return s;
  9629. }
  9630. int String::getHexValue32() const throw()
  9631. {
  9632. int result = 0;
  9633. const juce_wchar* c = text;
  9634. for (;;)
  9635. {
  9636. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9637. if (hexValue >= 0)
  9638. result = (result << 4) | hexValue;
  9639. else if (*c == 0)
  9640. break;
  9641. ++c;
  9642. }
  9643. return result;
  9644. }
  9645. int64 String::getHexValue64() const throw()
  9646. {
  9647. int64 result = 0;
  9648. const juce_wchar* c = text;
  9649. for (;;)
  9650. {
  9651. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9652. if (hexValue >= 0)
  9653. result = (result << 4) | hexValue;
  9654. else if (*c == 0)
  9655. break;
  9656. ++c;
  9657. }
  9658. return result;
  9659. }
  9660. const String String::createStringFromData (const void* const data_, const int size)
  9661. {
  9662. const char* const data = (const char*) data_;
  9663. if (size <= 0 || data == 0)
  9664. {
  9665. return empty;
  9666. }
  9667. else if (size < 2)
  9668. {
  9669. return charToString (data[0]);
  9670. }
  9671. else if ((data[0] == (char)-2 && data[1] == (char)-1)
  9672. || (data[0] == (char)-1 && data[1] == (char)-2))
  9673. {
  9674. // assume it's 16-bit unicode
  9675. const bool bigEndian = (data[0] == (char)-2);
  9676. const int numChars = size / 2 - 1;
  9677. String result;
  9678. result.preallocateStorage (numChars + 2);
  9679. const uint16* const src = (const uint16*) (data + 2);
  9680. juce_wchar* const dst = const_cast <juce_wchar*> ((const juce_wchar*) result);
  9681. if (bigEndian)
  9682. {
  9683. for (int i = 0; i < numChars; ++i)
  9684. dst[i] = (juce_wchar) ByteOrder::swapIfLittleEndian (src[i]);
  9685. }
  9686. else
  9687. {
  9688. for (int i = 0; i < numChars; ++i)
  9689. dst[i] = (juce_wchar) ByteOrder::swapIfBigEndian (src[i]);
  9690. }
  9691. dst [numChars] = 0;
  9692. return result;
  9693. }
  9694. else
  9695. {
  9696. return String::fromUTF8 (data, size);
  9697. }
  9698. }
  9699. const char* String::toUTF8() const
  9700. {
  9701. if (isEmpty())
  9702. {
  9703. return reinterpret_cast <const char*> (text);
  9704. }
  9705. else
  9706. {
  9707. const int currentLen = length() + 1;
  9708. const int utf8BytesNeeded = getNumBytesAsUTF8();
  9709. String* const mutableThis = const_cast <String*> (this);
  9710. mutableThis->text = StringHolder::makeUniqueWithSize (mutableThis->text, currentLen + 1 + utf8BytesNeeded / sizeof (juce_wchar));
  9711. char* const otherCopy = (char*) (text + currentLen);
  9712. copyToUTF8 (otherCopy, std::numeric_limits<int>::max());
  9713. return otherCopy;
  9714. }
  9715. }
  9716. int String::copyToUTF8 (char* const buffer, const int maxBufferSizeBytes) const throw()
  9717. {
  9718. jassert (maxBufferSizeBytes >= 0); // keep this value positive, or no characters will be copied!
  9719. int num = 0, index = 0;
  9720. for (;;)
  9721. {
  9722. const uint32 c = (uint32) text [index++];
  9723. if (c >= 0x80)
  9724. {
  9725. int numExtraBytes = 1;
  9726. if (c >= 0x800)
  9727. {
  9728. ++numExtraBytes;
  9729. if (c >= 0x10000)
  9730. {
  9731. ++numExtraBytes;
  9732. if (c >= 0x200000)
  9733. {
  9734. ++numExtraBytes;
  9735. if (c >= 0x4000000)
  9736. ++numExtraBytes;
  9737. }
  9738. }
  9739. }
  9740. if (buffer != 0)
  9741. {
  9742. if (num + numExtraBytes >= maxBufferSizeBytes)
  9743. {
  9744. buffer [num++] = 0;
  9745. break;
  9746. }
  9747. else
  9748. {
  9749. buffer [num++] = (uint8) ((0xff << (7 - numExtraBytes)) | (c >> (numExtraBytes * 6)));
  9750. while (--numExtraBytes >= 0)
  9751. buffer [num++] = (uint8) (0x80 | (0x3f & (c >> (numExtraBytes * 6))));
  9752. }
  9753. }
  9754. else
  9755. {
  9756. num += numExtraBytes + 1;
  9757. }
  9758. }
  9759. else
  9760. {
  9761. if (buffer != 0)
  9762. {
  9763. if (num + 1 >= maxBufferSizeBytes)
  9764. {
  9765. buffer [num++] = 0;
  9766. break;
  9767. }
  9768. buffer [num] = (uint8) c;
  9769. }
  9770. ++num;
  9771. }
  9772. if (c == 0)
  9773. break;
  9774. }
  9775. return num;
  9776. }
  9777. int String::getNumBytesAsUTF8() const throw()
  9778. {
  9779. int num = 0;
  9780. const juce_wchar* t = text;
  9781. for (;;)
  9782. {
  9783. const uint32 c = (uint32) *t;
  9784. if (c >= 0x80)
  9785. {
  9786. ++num;
  9787. if (c >= 0x800)
  9788. {
  9789. ++num;
  9790. if (c >= 0x10000)
  9791. {
  9792. ++num;
  9793. if (c >= 0x200000)
  9794. {
  9795. ++num;
  9796. if (c >= 0x4000000)
  9797. ++num;
  9798. }
  9799. }
  9800. }
  9801. }
  9802. else if (c == 0)
  9803. break;
  9804. ++num;
  9805. ++t;
  9806. }
  9807. return num;
  9808. }
  9809. const String String::fromUTF8 (const char* const buffer, int bufferSizeBytes)
  9810. {
  9811. if (buffer == 0)
  9812. return empty;
  9813. if (bufferSizeBytes < 0)
  9814. bufferSizeBytes = std::numeric_limits<int>::max();
  9815. size_t numBytes;
  9816. for (numBytes = 0; numBytes < (size_t) bufferSizeBytes; ++numBytes)
  9817. if (buffer [numBytes] == 0)
  9818. break;
  9819. String result ((size_t) numBytes + 1, (int) 0);
  9820. juce_wchar* dest = result.text;
  9821. size_t i = 0;
  9822. while (i < numBytes)
  9823. {
  9824. const char c = buffer [i++];
  9825. if (c < 0)
  9826. {
  9827. unsigned int mask = 0x7f;
  9828. int bit = 0x40;
  9829. int numExtraValues = 0;
  9830. while (bit != 0 && (c & bit) != 0)
  9831. {
  9832. bit >>= 1;
  9833. mask >>= 1;
  9834. ++numExtraValues;
  9835. }
  9836. int n = (mask & (unsigned char) c);
  9837. while (--numExtraValues >= 0 && i < (size_t) bufferSizeBytes)
  9838. {
  9839. const char nextByte = buffer[i];
  9840. if ((nextByte & 0xc0) != 0x80)
  9841. break;
  9842. n <<= 6;
  9843. n |= (nextByte & 0x3f);
  9844. ++i;
  9845. }
  9846. *dest++ = (juce_wchar) n;
  9847. }
  9848. else
  9849. {
  9850. *dest++ = (juce_wchar) c;
  9851. }
  9852. }
  9853. *dest = 0;
  9854. return result;
  9855. }
  9856. const char* String::toCString() const
  9857. {
  9858. if (isEmpty())
  9859. {
  9860. return reinterpret_cast <const char*> (text);
  9861. }
  9862. else
  9863. {
  9864. int len = length();
  9865. String* const mutableThis = const_cast <String*> (this);
  9866. mutableThis->text = StringHolder::makeUniqueWithSize (mutableThis->text, (len + 1) * 2);
  9867. char* otherCopy = (char*) (text + len + 1);
  9868. CharacterFunctions::copy (otherCopy, text, len);
  9869. otherCopy [len] = 0;
  9870. return otherCopy;
  9871. }
  9872. }
  9873. #ifdef _MSC_VER
  9874. #pragma warning (disable: 4514 4996)
  9875. #pragma warning (push)
  9876. #endif
  9877. int String::getNumBytesAsCString() const throw()
  9878. {
  9879. return (int) wcstombs (0, text, 0);
  9880. }
  9881. int String::copyToCString (char* destBuffer, const int maxBufferSizeBytes) const throw()
  9882. {
  9883. const int numBytes = (int) wcstombs (destBuffer, text, maxBufferSizeBytes);
  9884. if (destBuffer != 0 && numBytes >= 0)
  9885. destBuffer [numBytes] = 0;
  9886. return numBytes;
  9887. }
  9888. #ifdef _MSC_VER
  9889. #pragma warning (pop)
  9890. #endif
  9891. void String::copyToUnicode (juce_wchar* const destBuffer, const int maxCharsToCopy) const throw()
  9892. {
  9893. StringHolder::copyChars (destBuffer, text, jmin (maxCharsToCopy, length()));
  9894. }
  9895. String::Concatenator::Concatenator (String& stringToAppendTo)
  9896. : result (stringToAppendTo),
  9897. nextIndex (stringToAppendTo.length())
  9898. {
  9899. }
  9900. String::Concatenator::~Concatenator()
  9901. {
  9902. }
  9903. void String::Concatenator::append (const String& s)
  9904. {
  9905. const int len = s.length();
  9906. if (len > 0)
  9907. {
  9908. result.preallocateStorage (nextIndex + len);
  9909. s.copyToUnicode (((juce_wchar*) result) + nextIndex, len);
  9910. nextIndex += len;
  9911. }
  9912. }
  9913. END_JUCE_NAMESPACE
  9914. /*** End of inlined file: juce_String.cpp ***/
  9915. /*** Start of inlined file: juce_StringArray.cpp ***/
  9916. BEGIN_JUCE_NAMESPACE
  9917. StringArray::StringArray() throw()
  9918. {
  9919. }
  9920. StringArray::StringArray (const StringArray& other)
  9921. : strings (other.strings)
  9922. {
  9923. }
  9924. StringArray::StringArray (const String& firstValue)
  9925. {
  9926. strings.add (firstValue);
  9927. }
  9928. StringArray::StringArray (const juce_wchar** const initialStrings,
  9929. const int numberOfStrings)
  9930. {
  9931. for (int i = 0; i < numberOfStrings; ++i)
  9932. strings.add (initialStrings [i]);
  9933. }
  9934. StringArray::StringArray (const char** const initialStrings,
  9935. const int numberOfStrings)
  9936. {
  9937. for (int i = 0; i < numberOfStrings; ++i)
  9938. strings.add (initialStrings [i]);
  9939. }
  9940. StringArray::StringArray (const juce_wchar** const initialStrings)
  9941. {
  9942. int i = 0;
  9943. while (initialStrings[i] != 0)
  9944. strings.add (initialStrings [i++]);
  9945. }
  9946. StringArray::StringArray (const char** const initialStrings)
  9947. {
  9948. int i = 0;
  9949. while (initialStrings[i] != 0)
  9950. strings.add (initialStrings [i++]);
  9951. }
  9952. StringArray& StringArray::operator= (const StringArray& other)
  9953. {
  9954. strings = other.strings;
  9955. return *this;
  9956. }
  9957. StringArray::~StringArray()
  9958. {
  9959. }
  9960. bool StringArray::operator== (const StringArray& other) const throw()
  9961. {
  9962. if (other.size() != size())
  9963. return false;
  9964. for (int i = size(); --i >= 0;)
  9965. if (other.strings.getReference(i) != strings.getReference(i))
  9966. return false;
  9967. return true;
  9968. }
  9969. bool StringArray::operator!= (const StringArray& other) const throw()
  9970. {
  9971. return ! operator== (other);
  9972. }
  9973. void StringArray::clear()
  9974. {
  9975. strings.clear();
  9976. }
  9977. const String& StringArray::operator[] (const int index) const throw()
  9978. {
  9979. if (((unsigned int) index) < (unsigned int) strings.size())
  9980. return strings.getReference (index);
  9981. return String::empty;
  9982. }
  9983. void StringArray::add (const String& newString)
  9984. {
  9985. strings.add (newString);
  9986. }
  9987. void StringArray::insert (const int index, const String& newString)
  9988. {
  9989. strings.insert (index, newString);
  9990. }
  9991. void StringArray::addIfNotAlreadyThere (const String& newString, const bool ignoreCase)
  9992. {
  9993. if (! contains (newString, ignoreCase))
  9994. add (newString);
  9995. }
  9996. void StringArray::addArray (const StringArray& otherArray, int startIndex, int numElementsToAdd)
  9997. {
  9998. if (startIndex < 0)
  9999. {
  10000. jassertfalse
  10001. startIndex = 0;
  10002. }
  10003. if (numElementsToAdd < 0 || startIndex + numElementsToAdd > otherArray.size())
  10004. numElementsToAdd = otherArray.size() - startIndex;
  10005. while (--numElementsToAdd >= 0)
  10006. strings.add (otherArray.strings.getReference (startIndex++));
  10007. }
  10008. void StringArray::set (const int index, const String& newString)
  10009. {
  10010. strings.set (index, newString);
  10011. }
  10012. bool StringArray::contains (const String& stringToLookFor, const bool ignoreCase) const
  10013. {
  10014. if (ignoreCase)
  10015. {
  10016. for (int i = size(); --i >= 0;)
  10017. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  10018. return true;
  10019. }
  10020. else
  10021. {
  10022. for (int i = size(); --i >= 0;)
  10023. if (stringToLookFor == strings.getReference(i))
  10024. return true;
  10025. }
  10026. return false;
  10027. }
  10028. int StringArray::indexOf (const String& stringToLookFor, const bool ignoreCase, int i) const
  10029. {
  10030. if (i < 0)
  10031. i = 0;
  10032. const int numElements = size();
  10033. if (ignoreCase)
  10034. {
  10035. while (i < numElements)
  10036. {
  10037. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  10038. return i;
  10039. ++i;
  10040. }
  10041. }
  10042. else
  10043. {
  10044. while (i < numElements)
  10045. {
  10046. if (stringToLookFor == strings.getReference (i))
  10047. return i;
  10048. ++i;
  10049. }
  10050. }
  10051. return -1;
  10052. }
  10053. void StringArray::remove (const int index)
  10054. {
  10055. strings.remove (index);
  10056. }
  10057. void StringArray::removeString (const String& stringToRemove,
  10058. const bool ignoreCase)
  10059. {
  10060. if (ignoreCase)
  10061. {
  10062. for (int i = size(); --i >= 0;)
  10063. if (strings.getReference(i).equalsIgnoreCase (stringToRemove))
  10064. strings.remove (i);
  10065. }
  10066. else
  10067. {
  10068. for (int i = size(); --i >= 0;)
  10069. if (stringToRemove == strings.getReference (i))
  10070. strings.remove (i);
  10071. }
  10072. }
  10073. void StringArray::removeEmptyStrings (const bool removeWhitespaceStrings)
  10074. {
  10075. if (removeWhitespaceStrings)
  10076. {
  10077. for (int i = size(); --i >= 0;)
  10078. if (! strings.getReference(i).containsNonWhitespaceChars())
  10079. strings.remove (i);
  10080. }
  10081. else
  10082. {
  10083. for (int i = size(); --i >= 0;)
  10084. if (strings.getReference(i).isEmpty())
  10085. strings.remove (i);
  10086. }
  10087. }
  10088. void StringArray::trim()
  10089. {
  10090. for (int i = size(); --i >= 0;)
  10091. {
  10092. String& s = strings.getReference(i);
  10093. s = s.trim();
  10094. }
  10095. }
  10096. class InternalStringArrayComparator_CaseSensitive
  10097. {
  10098. public:
  10099. static int compareElements (String& first, String& second) { return first.compare (second); }
  10100. };
  10101. class InternalStringArrayComparator_CaseInsensitive
  10102. {
  10103. public:
  10104. static int compareElements (String& first, String& second) { return first.compareIgnoreCase (second); }
  10105. };
  10106. void StringArray::sort (const bool ignoreCase)
  10107. {
  10108. if (ignoreCase)
  10109. {
  10110. InternalStringArrayComparator_CaseInsensitive comp;
  10111. strings.sort (comp);
  10112. }
  10113. else
  10114. {
  10115. InternalStringArrayComparator_CaseSensitive comp;
  10116. strings.sort (comp);
  10117. }
  10118. }
  10119. void StringArray::move (const int currentIndex, int newIndex) throw()
  10120. {
  10121. strings.move (currentIndex, newIndex);
  10122. }
  10123. const String StringArray::joinIntoString (const String& separator, int start, int numberToJoin) const
  10124. {
  10125. const int last = (numberToJoin < 0) ? size()
  10126. : jmin (size(), start + numberToJoin);
  10127. if (start < 0)
  10128. start = 0;
  10129. if (start >= last)
  10130. return String::empty;
  10131. if (start == last - 1)
  10132. return strings.getReference (start);
  10133. const int separatorLen = separator.length();
  10134. int charsNeeded = separatorLen * (last - start - 1);
  10135. for (int i = start; i < last; ++i)
  10136. charsNeeded += strings.getReference(i).length();
  10137. String result;
  10138. result.preallocateStorage (charsNeeded);
  10139. juce_wchar* dest = (juce_wchar*) result;
  10140. while (start < last)
  10141. {
  10142. const String& s = strings.getReference (start);
  10143. const int len = s.length();
  10144. if (len > 0)
  10145. {
  10146. s.copyToUnicode (dest, len);
  10147. dest += len;
  10148. }
  10149. if (++start < last && separatorLen > 0)
  10150. {
  10151. separator.copyToUnicode (dest, separatorLen);
  10152. dest += separatorLen;
  10153. }
  10154. }
  10155. *dest = 0;
  10156. return result;
  10157. }
  10158. int StringArray::addTokens (const String& text, const bool preserveQuotedStrings)
  10159. {
  10160. return addTokens (text, T(" \n\r\t"), preserveQuotedStrings ? T("\"") : T(""));
  10161. }
  10162. int StringArray::addTokens (const String& text, const String& breakCharacters, const String& quoteCharacters)
  10163. {
  10164. int num = 0;
  10165. if (text.isNotEmpty())
  10166. {
  10167. bool insideQuotes = false;
  10168. juce_wchar currentQuoteChar = 0;
  10169. int i = 0;
  10170. int tokenStart = 0;
  10171. for (;;)
  10172. {
  10173. const juce_wchar c = text[i];
  10174. const bool isBreak = (c == 0) || ((! insideQuotes) && breakCharacters.containsChar (c));
  10175. if (! isBreak)
  10176. {
  10177. if (quoteCharacters.containsChar (c))
  10178. {
  10179. if (insideQuotes)
  10180. {
  10181. // only break out of quotes-mode if we find a matching quote to the
  10182. // one that we opened with..
  10183. if (currentQuoteChar == c)
  10184. insideQuotes = false;
  10185. }
  10186. else
  10187. {
  10188. insideQuotes = true;
  10189. currentQuoteChar = c;
  10190. }
  10191. }
  10192. }
  10193. else
  10194. {
  10195. add (String (static_cast <const juce_wchar*> (text) + tokenStart, i - tokenStart));
  10196. ++num;
  10197. tokenStart = i + 1;
  10198. }
  10199. if (c == 0)
  10200. break;
  10201. ++i;
  10202. }
  10203. }
  10204. return num;
  10205. }
  10206. int StringArray::addLines (const String& sourceText)
  10207. {
  10208. int numLines = 0;
  10209. const juce_wchar* text = sourceText;
  10210. while (*text != 0)
  10211. {
  10212. const juce_wchar* const startOfLine = text;
  10213. while (*text != 0)
  10214. {
  10215. if (*text == '\r')
  10216. {
  10217. ++text;
  10218. if (*text == '\n')
  10219. ++text;
  10220. break;
  10221. }
  10222. if (*text == '\n')
  10223. {
  10224. ++text;
  10225. break;
  10226. }
  10227. ++text;
  10228. }
  10229. const juce_wchar* endOfLine = text;
  10230. if (endOfLine > startOfLine && (*(endOfLine - 1) == '\r' || *(endOfLine - 1) == '\n'))
  10231. --endOfLine;
  10232. if (endOfLine > startOfLine && (*(endOfLine - 1) == '\r' || *(endOfLine - 1) == '\n'))
  10233. --endOfLine;
  10234. add (String (startOfLine, jmax (0, (int) (endOfLine - startOfLine))));
  10235. ++numLines;
  10236. }
  10237. return numLines;
  10238. }
  10239. void StringArray::removeDuplicates (const bool ignoreCase)
  10240. {
  10241. for (int i = 0; i < size() - 1; ++i)
  10242. {
  10243. const String s (strings.getReference(i));
  10244. int nextIndex = i + 1;
  10245. for (;;)
  10246. {
  10247. nextIndex = indexOf (s, ignoreCase, nextIndex);
  10248. if (nextIndex < 0)
  10249. break;
  10250. strings.remove (nextIndex);
  10251. }
  10252. }
  10253. }
  10254. void StringArray::appendNumbersToDuplicates (const bool ignoreCase,
  10255. const bool appendNumberToFirstInstance,
  10256. const juce_wchar* preNumberString,
  10257. const juce_wchar* postNumberString)
  10258. {
  10259. if (preNumberString == 0)
  10260. preNumberString = T(" (");
  10261. if (postNumberString == 0)
  10262. postNumberString = T(")");
  10263. for (int i = 0; i < size() - 1; ++i)
  10264. {
  10265. String& s = strings.getReference(i);
  10266. int nextIndex = indexOf (s, ignoreCase, i + 1);
  10267. if (nextIndex >= 0)
  10268. {
  10269. const String original (s);
  10270. int number = 0;
  10271. if (appendNumberToFirstInstance)
  10272. s = original + preNumberString + String (++number) + postNumberString;
  10273. else
  10274. ++number;
  10275. while (nextIndex >= 0)
  10276. {
  10277. set (nextIndex, (*this)[nextIndex] + preNumberString + String (++number) + postNumberString);
  10278. nextIndex = indexOf (original, ignoreCase, nextIndex + 1);
  10279. }
  10280. }
  10281. }
  10282. }
  10283. void StringArray::minimiseStorageOverheads()
  10284. {
  10285. strings.minimiseStorageOverheads();
  10286. }
  10287. END_JUCE_NAMESPACE
  10288. /*** End of inlined file: juce_StringArray.cpp ***/
  10289. /*** Start of inlined file: juce_StringPairArray.cpp ***/
  10290. BEGIN_JUCE_NAMESPACE
  10291. StringPairArray::StringPairArray (const bool ignoreCase_)
  10292. : ignoreCase (ignoreCase_)
  10293. {
  10294. }
  10295. StringPairArray::StringPairArray (const StringPairArray& other)
  10296. : keys (other.keys),
  10297. values (other.values),
  10298. ignoreCase (other.ignoreCase)
  10299. {
  10300. }
  10301. StringPairArray::~StringPairArray()
  10302. {
  10303. }
  10304. StringPairArray& StringPairArray::operator= (const StringPairArray& other)
  10305. {
  10306. keys = other.keys;
  10307. values = other.values;
  10308. return *this;
  10309. }
  10310. bool StringPairArray::operator== (const StringPairArray& other) const
  10311. {
  10312. for (int i = keys.size(); --i >= 0;)
  10313. if (other [keys[i]] != values[i])
  10314. return false;
  10315. return true;
  10316. }
  10317. bool StringPairArray::operator!= (const StringPairArray& other) const
  10318. {
  10319. return ! operator== (other);
  10320. }
  10321. const String& StringPairArray::operator[] (const String& key) const
  10322. {
  10323. return values [keys.indexOf (key, ignoreCase)];
  10324. }
  10325. const String StringPairArray::getValue (const String& key, const String& defaultReturnValue) const
  10326. {
  10327. const int i = keys.indexOf (key, ignoreCase);
  10328. if (i >= 0)
  10329. return values[i];
  10330. return defaultReturnValue;
  10331. }
  10332. void StringPairArray::set (const String& key, const String& value)
  10333. {
  10334. const int i = keys.indexOf (key, ignoreCase);
  10335. if (i >= 0)
  10336. {
  10337. values.set (i, value);
  10338. }
  10339. else
  10340. {
  10341. keys.add (key);
  10342. values.add (value);
  10343. }
  10344. }
  10345. void StringPairArray::addArray (const StringPairArray& other)
  10346. {
  10347. for (int i = 0; i < other.size(); ++i)
  10348. set (other.keys[i], other.values[i]);
  10349. }
  10350. void StringPairArray::clear()
  10351. {
  10352. keys.clear();
  10353. values.clear();
  10354. }
  10355. void StringPairArray::remove (const String& key)
  10356. {
  10357. remove (keys.indexOf (key, ignoreCase));
  10358. }
  10359. void StringPairArray::remove (const int index)
  10360. {
  10361. keys.remove (index);
  10362. values.remove (index);
  10363. }
  10364. void StringPairArray::setIgnoresCase (const bool shouldIgnoreCase)
  10365. {
  10366. ignoreCase = shouldIgnoreCase;
  10367. }
  10368. const String StringPairArray::getDescription() const
  10369. {
  10370. String s;
  10371. for (int i = 0; i < keys.size(); ++i)
  10372. {
  10373. s << keys[i] << " = " << values[i];
  10374. if (i < keys.size())
  10375. s << ", ";
  10376. }
  10377. return s;
  10378. }
  10379. void StringPairArray::minimiseStorageOverheads()
  10380. {
  10381. keys.minimiseStorageOverheads();
  10382. values.minimiseStorageOverheads();
  10383. }
  10384. END_JUCE_NAMESPACE
  10385. /*** End of inlined file: juce_StringPairArray.cpp ***/
  10386. /*** Start of inlined file: juce_XmlDocument.cpp ***/
  10387. BEGIN_JUCE_NAMESPACE
  10388. XmlDocument::XmlDocument (const String& documentText)
  10389. : originalText (documentText),
  10390. ignoreEmptyTextElements (true)
  10391. {
  10392. }
  10393. XmlDocument::XmlDocument (const File& file)
  10394. {
  10395. inputSource = new FileInputSource (file);
  10396. }
  10397. XmlDocument::~XmlDocument()
  10398. {
  10399. }
  10400. void XmlDocument::setInputSource (InputSource* const newSource) throw()
  10401. {
  10402. inputSource = newSource;
  10403. }
  10404. void XmlDocument::setEmptyTextElementsIgnored (const bool shouldBeIgnored) throw()
  10405. {
  10406. ignoreEmptyTextElements = shouldBeIgnored;
  10407. }
  10408. bool XmlDocument::isXmlIdentifierCharSlow (const juce_wchar c) throw()
  10409. {
  10410. return CharacterFunctions::isLetterOrDigit (c)
  10411. || c == '_' || c == '-' || c == ':' || c == '.';
  10412. }
  10413. inline bool XmlDocument::isXmlIdentifierChar (const juce_wchar c) const throw()
  10414. {
  10415. return (c > 0 && c <= 127) ? identifierLookupTable [(int) c]
  10416. : isXmlIdentifierCharSlow (c);
  10417. }
  10418. XmlElement* XmlDocument::getDocumentElement (const bool onlyReadOuterDocumentElement)
  10419. {
  10420. String textToParse (originalText);
  10421. if (textToParse.isEmpty() && inputSource != 0)
  10422. {
  10423. ScopedPointer <InputStream> in (inputSource->createInputStream());
  10424. if (in != 0)
  10425. {
  10426. MemoryBlock data;
  10427. in->readIntoMemoryBlock (data, onlyReadOuterDocumentElement ? 8192 : -1);
  10428. if (data.getSize() >= 2
  10429. && ((data[0] == (char)-2 && data[1] == (char)-1)
  10430. || (data[0] == (char)-1 && data[1] == (char)-2)))
  10431. {
  10432. textToParse = String::createStringFromData ((const char*) data.getData(), (int) data.getSize());
  10433. }
  10434. else
  10435. {
  10436. textToParse = String::fromUTF8 ((const char*) data.getData(), (int) data.getSize());
  10437. }
  10438. if (! onlyReadOuterDocumentElement)
  10439. originalText = textToParse;
  10440. }
  10441. }
  10442. input = textToParse;
  10443. lastError = String::empty;
  10444. errorOccurred = false;
  10445. outOfData = false;
  10446. needToLoadDTD = true;
  10447. for (int i = 0; i < 128; ++i)
  10448. identifierLookupTable[i] = isXmlIdentifierCharSlow ((juce_wchar) i);
  10449. if (textToParse.isEmpty())
  10450. {
  10451. lastError = "not enough input";
  10452. }
  10453. else
  10454. {
  10455. skipHeader();
  10456. if (input != 0)
  10457. {
  10458. ScopedPointer <XmlElement> result (readNextElement (! onlyReadOuterDocumentElement));
  10459. if (! errorOccurred)
  10460. return result.release();
  10461. }
  10462. else
  10463. {
  10464. lastError = "incorrect xml header";
  10465. }
  10466. }
  10467. return 0;
  10468. }
  10469. const String& XmlDocument::getLastParseError() const throw()
  10470. {
  10471. return lastError;
  10472. }
  10473. void XmlDocument::setLastError (const String& desc, const bool carryOn)
  10474. {
  10475. lastError = desc;
  10476. errorOccurred = ! carryOn;
  10477. }
  10478. const String XmlDocument::getFileContents (const String& filename) const
  10479. {
  10480. if (inputSource != 0)
  10481. {
  10482. const ScopedPointer <InputStream> in (inputSource->createInputStreamFor (filename.trim().unquoted()));
  10483. if (in != 0)
  10484. return in->readEntireStreamAsString();
  10485. }
  10486. return String::empty;
  10487. }
  10488. juce_wchar XmlDocument::readNextChar() throw()
  10489. {
  10490. if (*input != 0)
  10491. {
  10492. return *input++;
  10493. }
  10494. else
  10495. {
  10496. outOfData = true;
  10497. return 0;
  10498. }
  10499. }
  10500. int XmlDocument::findNextTokenLength() throw()
  10501. {
  10502. int len = 0;
  10503. juce_wchar c = *input;
  10504. while (isXmlIdentifierChar (c))
  10505. c = input [++len];
  10506. return len;
  10507. }
  10508. void XmlDocument::skipHeader()
  10509. {
  10510. const juce_wchar* const found = CharacterFunctions::find (input, T("<?xml"));
  10511. if (found != 0)
  10512. {
  10513. input = found;
  10514. input = CharacterFunctions::find (input, T("?>"));
  10515. if (input == 0)
  10516. return;
  10517. input += 2;
  10518. }
  10519. skipNextWhiteSpace();
  10520. const juce_wchar* docType = CharacterFunctions::find (input, T("<!DOCTYPE"));
  10521. if (docType == 0)
  10522. return;
  10523. input = docType + 9;
  10524. int n = 1;
  10525. while (n > 0)
  10526. {
  10527. const juce_wchar c = readNextChar();
  10528. if (outOfData)
  10529. return;
  10530. if (c == '<')
  10531. ++n;
  10532. else if (c == '>')
  10533. --n;
  10534. }
  10535. docType += 9;
  10536. dtdText = String (docType, (int) (input - (docType + 1))).trim();
  10537. }
  10538. void XmlDocument::skipNextWhiteSpace()
  10539. {
  10540. for (;;)
  10541. {
  10542. juce_wchar c = *input;
  10543. while (CharacterFunctions::isWhitespace (c))
  10544. c = *++input;
  10545. if (c == 0)
  10546. {
  10547. outOfData = true;
  10548. break;
  10549. }
  10550. else if (c == '<')
  10551. {
  10552. if (input[1] == '!'
  10553. && input[2] == '-'
  10554. && input[3] == '-')
  10555. {
  10556. const juce_wchar* const closeComment = CharacterFunctions::find (input, T("-->"));
  10557. if (closeComment == 0)
  10558. {
  10559. outOfData = true;
  10560. break;
  10561. }
  10562. input = closeComment + 3;
  10563. continue;
  10564. }
  10565. else if (input[1] == '?')
  10566. {
  10567. const juce_wchar* const closeBracket = CharacterFunctions::find (input, T("?>"));
  10568. if (closeBracket == 0)
  10569. {
  10570. outOfData = true;
  10571. break;
  10572. }
  10573. input = closeBracket + 2;
  10574. continue;
  10575. }
  10576. }
  10577. break;
  10578. }
  10579. }
  10580. void XmlDocument::readQuotedString (String& result)
  10581. {
  10582. const juce_wchar quote = readNextChar();
  10583. while (! outOfData)
  10584. {
  10585. const juce_wchar c = readNextChar();
  10586. if (c == quote)
  10587. break;
  10588. if (c == '&')
  10589. {
  10590. --input;
  10591. readEntity (result);
  10592. }
  10593. else
  10594. {
  10595. --input;
  10596. const juce_wchar* const start = input;
  10597. for (;;)
  10598. {
  10599. const juce_wchar character = *input;
  10600. if (character == quote)
  10601. {
  10602. result.append (start, (int) (input - start));
  10603. ++input;
  10604. return;
  10605. }
  10606. else if (character == '&')
  10607. {
  10608. result.append (start, (int) (input - start));
  10609. break;
  10610. }
  10611. else if (character == 0)
  10612. {
  10613. outOfData = true;
  10614. setLastError ("unmatched quotes", false);
  10615. break;
  10616. }
  10617. ++input;
  10618. }
  10619. }
  10620. }
  10621. }
  10622. XmlElement* XmlDocument::readNextElement (const bool alsoParseSubElements)
  10623. {
  10624. XmlElement* node = 0;
  10625. skipNextWhiteSpace();
  10626. if (outOfData)
  10627. return 0;
  10628. input = CharacterFunctions::find (input, T("<"));
  10629. if (input != 0)
  10630. {
  10631. ++input;
  10632. int tagLen = findNextTokenLength();
  10633. if (tagLen == 0)
  10634. {
  10635. // no tag name - but allow for a gap after the '<' before giving an error
  10636. skipNextWhiteSpace();
  10637. tagLen = findNextTokenLength();
  10638. if (tagLen == 0)
  10639. {
  10640. setLastError ("tag name missing", false);
  10641. return node;
  10642. }
  10643. }
  10644. node = new XmlElement (String (input, tagLen));
  10645. input += tagLen;
  10646. XmlElement::XmlAttributeNode* lastAttribute = 0;
  10647. // look for attributes
  10648. for (;;)
  10649. {
  10650. skipNextWhiteSpace();
  10651. const juce_wchar c = *input;
  10652. // empty tag..
  10653. if (c == '/' && input[1] == '>')
  10654. {
  10655. input += 2;
  10656. break;
  10657. }
  10658. // parse the guts of the element..
  10659. if (c == '>')
  10660. {
  10661. ++input;
  10662. skipNextWhiteSpace();
  10663. if (alsoParseSubElements)
  10664. readChildElements (node);
  10665. break;
  10666. }
  10667. // get an attribute..
  10668. if (isXmlIdentifierChar (c))
  10669. {
  10670. const int attNameLen = findNextTokenLength();
  10671. if (attNameLen > 0)
  10672. {
  10673. const juce_wchar* attNameStart = input;
  10674. input += attNameLen;
  10675. skipNextWhiteSpace();
  10676. if (readNextChar() == '=')
  10677. {
  10678. skipNextWhiteSpace();
  10679. const juce_wchar nextChar = *input;
  10680. if (nextChar == '"' || nextChar == '\'')
  10681. {
  10682. XmlElement::XmlAttributeNode* const newAtt
  10683. = new XmlElement::XmlAttributeNode (String (attNameStart, attNameLen),
  10684. String::empty);
  10685. readQuotedString (newAtt->value);
  10686. if (lastAttribute == 0)
  10687. node->attributes = newAtt;
  10688. else
  10689. lastAttribute->next = newAtt;
  10690. lastAttribute = newAtt;
  10691. continue;
  10692. }
  10693. }
  10694. }
  10695. }
  10696. else
  10697. {
  10698. if (! outOfData)
  10699. setLastError ("illegal character found in " + node->getTagName() + ": '" + c + "'", false);
  10700. }
  10701. break;
  10702. }
  10703. }
  10704. return node;
  10705. }
  10706. void XmlDocument::readChildElements (XmlElement* parent)
  10707. {
  10708. XmlElement* lastChildNode = 0;
  10709. for (;;)
  10710. {
  10711. skipNextWhiteSpace();
  10712. if (outOfData)
  10713. {
  10714. setLastError ("unmatched tags", false);
  10715. break;
  10716. }
  10717. if (*input == '<')
  10718. {
  10719. if (input[1] == '/')
  10720. {
  10721. // our close tag..
  10722. input = CharacterFunctions::find (input, T(">"));
  10723. ++input;
  10724. break;
  10725. }
  10726. else if (input[1] == '!'
  10727. && input[2] == '['
  10728. && input[3] == 'C'
  10729. && input[4] == 'D'
  10730. && input[5] == 'A'
  10731. && input[6] == 'T'
  10732. && input[7] == 'A'
  10733. && input[8] == '[')
  10734. {
  10735. input += 9;
  10736. const juce_wchar* const inputStart = input;
  10737. int len = 0;
  10738. for (;;)
  10739. {
  10740. if (*input == 0)
  10741. {
  10742. setLastError ("unterminated CDATA section", false);
  10743. outOfData = true;
  10744. break;
  10745. }
  10746. else if (input[0] == ']'
  10747. && input[1] == ']'
  10748. && input[2] == '>')
  10749. {
  10750. input += 3;
  10751. break;
  10752. }
  10753. ++input;
  10754. ++len;
  10755. }
  10756. XmlElement* const e = new XmlElement ((int) 0);
  10757. e->setText (String (inputStart, len));
  10758. if (lastChildNode != 0)
  10759. lastChildNode->nextElement = e;
  10760. else
  10761. parent->addChildElement (e);
  10762. lastChildNode = e;
  10763. }
  10764. else
  10765. {
  10766. // this is some other element, so parse and add it..
  10767. XmlElement* const n = readNextElement (true);
  10768. if (n != 0)
  10769. {
  10770. if (lastChildNode == 0)
  10771. parent->addChildElement (n);
  10772. else
  10773. lastChildNode->nextElement = n;
  10774. lastChildNode = n;
  10775. }
  10776. else
  10777. {
  10778. return;
  10779. }
  10780. }
  10781. }
  10782. else
  10783. {
  10784. // read character block..
  10785. XmlElement* const e = new XmlElement ((int)0);
  10786. if (lastChildNode != 0)
  10787. lastChildNode->nextElement = e;
  10788. else
  10789. parent->addChildElement (e);
  10790. lastChildNode = e;
  10791. String textElementContent;
  10792. for (;;)
  10793. {
  10794. const juce_wchar c = *input;
  10795. if (c == '<')
  10796. break;
  10797. if (c == 0)
  10798. {
  10799. setLastError ("unmatched tags", false);
  10800. outOfData = true;
  10801. return;
  10802. }
  10803. if (c == '&')
  10804. {
  10805. String entity;
  10806. readEntity (entity);
  10807. if (entity.startsWithChar ('<') && entity [1] != 0)
  10808. {
  10809. const juce_wchar* const oldInput = input;
  10810. const bool oldOutOfData = outOfData;
  10811. input = entity;
  10812. outOfData = false;
  10813. for (;;)
  10814. {
  10815. XmlElement* const n = readNextElement (true);
  10816. if (n == 0)
  10817. break;
  10818. if (lastChildNode == 0)
  10819. parent->addChildElement (n);
  10820. else
  10821. lastChildNode->nextElement = n;
  10822. lastChildNode = n;
  10823. }
  10824. input = oldInput;
  10825. outOfData = oldOutOfData;
  10826. }
  10827. else
  10828. {
  10829. textElementContent += entity;
  10830. }
  10831. }
  10832. else
  10833. {
  10834. const juce_wchar* start = input;
  10835. int len = 0;
  10836. for (;;)
  10837. {
  10838. const juce_wchar nextChar = *input;
  10839. if (nextChar == '<' || nextChar == '&')
  10840. {
  10841. break;
  10842. }
  10843. else if (nextChar == 0)
  10844. {
  10845. setLastError ("unmatched tags", false);
  10846. outOfData = true;
  10847. return;
  10848. }
  10849. ++input;
  10850. ++len;
  10851. }
  10852. textElementContent.append (start, len);
  10853. }
  10854. }
  10855. if (ignoreEmptyTextElements ? textElementContent.containsNonWhitespaceChars()
  10856. : textElementContent.isNotEmpty())
  10857. e->setText (textElementContent);
  10858. }
  10859. }
  10860. }
  10861. void XmlDocument::readEntity (String& result)
  10862. {
  10863. // skip over the ampersand
  10864. ++input;
  10865. if (CharacterFunctions::compareIgnoreCase (input, T("amp;"), 4) == 0)
  10866. {
  10867. input += 4;
  10868. result += '&';
  10869. }
  10870. else if (CharacterFunctions::compareIgnoreCase (input, T("quot;"), 5) == 0)
  10871. {
  10872. input += 5;
  10873. result += '"';
  10874. }
  10875. else if (CharacterFunctions::compareIgnoreCase (input, T("apos;"), 5) == 0)
  10876. {
  10877. input += 5;
  10878. result += '\'';
  10879. }
  10880. else if (CharacterFunctions::compareIgnoreCase (input, T("lt;"), 3) == 0)
  10881. {
  10882. input += 3;
  10883. result += '<';
  10884. }
  10885. else if (CharacterFunctions::compareIgnoreCase (input, T("gt;"), 3) == 0)
  10886. {
  10887. input += 3;
  10888. result += '>';
  10889. }
  10890. else if (*input == '#')
  10891. {
  10892. int charCode = 0;
  10893. ++input;
  10894. if (*input == 'x' || *input == 'X')
  10895. {
  10896. ++input;
  10897. int numChars = 0;
  10898. while (input[0] != ';')
  10899. {
  10900. const int hexValue = CharacterFunctions::getHexDigitValue (input[0]);
  10901. if (hexValue < 0 || ++numChars > 8)
  10902. {
  10903. setLastError ("illegal escape sequence", true);
  10904. break;
  10905. }
  10906. charCode = (charCode << 4) | hexValue;
  10907. ++input;
  10908. }
  10909. ++input;
  10910. }
  10911. else if (input[0] >= '0' && input[0] <= '9')
  10912. {
  10913. int numChars = 0;
  10914. while (input[0] != ';')
  10915. {
  10916. if (++numChars > 12)
  10917. {
  10918. setLastError ("illegal escape sequence", true);
  10919. break;
  10920. }
  10921. charCode = charCode * 10 + (input[0] - '0');
  10922. ++input;
  10923. }
  10924. ++input;
  10925. }
  10926. else
  10927. {
  10928. setLastError ("illegal escape sequence", true);
  10929. result += '&';
  10930. return;
  10931. }
  10932. result << (juce_wchar) charCode;
  10933. }
  10934. else
  10935. {
  10936. const juce_wchar* const entityNameStart = input;
  10937. const juce_wchar* const closingSemiColon = CharacterFunctions::find (input, T(";"));
  10938. if (closingSemiColon == 0)
  10939. {
  10940. outOfData = true;
  10941. result += '&';
  10942. }
  10943. else
  10944. {
  10945. input = closingSemiColon + 1;
  10946. result += expandExternalEntity (String (entityNameStart,
  10947. (int) (closingSemiColon - entityNameStart)));
  10948. }
  10949. }
  10950. }
  10951. const String XmlDocument::expandEntity (const String& ent)
  10952. {
  10953. if (ent.equalsIgnoreCase (T("amp")))
  10954. return String::charToString ('&');
  10955. if (ent.equalsIgnoreCase (T("quot")))
  10956. return String::charToString ('"');
  10957. if (ent.equalsIgnoreCase (T("apos")))
  10958. return String::charToString ('\'');
  10959. if (ent.equalsIgnoreCase (T("lt")))
  10960. return String::charToString ('<');
  10961. if (ent.equalsIgnoreCase (T("gt")))
  10962. return String::charToString ('>');
  10963. if (ent[0] == '#')
  10964. {
  10965. if (ent[1] == 'x' || ent[1] == 'X')
  10966. return String::charToString (static_cast <juce_wchar> (ent.substring (2).getHexValue32()));
  10967. if (ent[1] >= '0' && ent[1] <= '9')
  10968. return String::charToString (static_cast <juce_wchar> (ent.substring (1).getIntValue()));
  10969. setLastError ("illegal escape sequence", false);
  10970. return String::charToString ('&');
  10971. }
  10972. return expandExternalEntity (ent);
  10973. }
  10974. const String XmlDocument::expandExternalEntity (const String& entity)
  10975. {
  10976. if (needToLoadDTD)
  10977. {
  10978. if (dtdText.isNotEmpty())
  10979. {
  10980. while (dtdText.endsWithChar ('>'))
  10981. dtdText = dtdText.dropLastCharacters (1);
  10982. tokenisedDTD.addTokens (dtdText, true);
  10983. if (tokenisedDTD [tokenisedDTD.size() - 2].equalsIgnoreCase (T("system"))
  10984. && tokenisedDTD [tokenisedDTD.size() - 1].isQuotedString())
  10985. {
  10986. const String fn (tokenisedDTD [tokenisedDTD.size() - 1]);
  10987. tokenisedDTD.clear();
  10988. tokenisedDTD.addTokens (getFileContents (fn), true);
  10989. }
  10990. else
  10991. {
  10992. tokenisedDTD.clear();
  10993. const int openBracket = dtdText.indexOfChar ('[');
  10994. if (openBracket > 0)
  10995. {
  10996. const int closeBracket = dtdText.lastIndexOfChar (']');
  10997. if (closeBracket > openBracket)
  10998. tokenisedDTD.addTokens (dtdText.substring (openBracket + 1,
  10999. closeBracket), true);
  11000. }
  11001. }
  11002. for (int i = tokenisedDTD.size(); --i >= 0;)
  11003. {
  11004. if (tokenisedDTD[i].startsWithChar ('%')
  11005. && tokenisedDTD[i].endsWithChar (';'))
  11006. {
  11007. const String parsed (getParameterEntity (tokenisedDTD[i].substring (1, tokenisedDTD[i].length() - 1)));
  11008. StringArray newToks;
  11009. newToks.addTokens (parsed, true);
  11010. tokenisedDTD.remove (i);
  11011. for (int j = newToks.size(); --j >= 0;)
  11012. tokenisedDTD.insert (i, newToks[j]);
  11013. }
  11014. }
  11015. }
  11016. needToLoadDTD = false;
  11017. }
  11018. for (int i = 0; i < tokenisedDTD.size(); ++i)
  11019. {
  11020. if (tokenisedDTD[i] == entity)
  11021. {
  11022. if (tokenisedDTD[i - 1].equalsIgnoreCase (T("<!entity")))
  11023. {
  11024. String ent (tokenisedDTD [i + 1]);
  11025. while (ent.endsWithChar ('>'))
  11026. ent = ent.dropLastCharacters (1);
  11027. ent = ent.trim().unquoted();
  11028. // check for sub-entities..
  11029. int ampersand = ent.indexOfChar ('&');
  11030. while (ampersand >= 0)
  11031. {
  11032. const int semiColon = ent.indexOf (i + 1, T(";"));
  11033. if (semiColon < 0)
  11034. {
  11035. setLastError ("entity without terminating semi-colon", false);
  11036. break;
  11037. }
  11038. const String resolved (expandEntity (ent.substring (i + 1, semiColon)));
  11039. ent = ent.substring (0, ampersand)
  11040. + resolved
  11041. + ent.substring (semiColon + 1);
  11042. ampersand = ent.indexOfChar (semiColon + 1, '&');
  11043. }
  11044. return ent;
  11045. }
  11046. }
  11047. }
  11048. setLastError ("unknown entity", true);
  11049. return entity;
  11050. }
  11051. const String XmlDocument::getParameterEntity (const String& entity)
  11052. {
  11053. for (int i = 0; i < tokenisedDTD.size(); ++i)
  11054. {
  11055. if (tokenisedDTD[i] == entity)
  11056. {
  11057. if (tokenisedDTD [i - 1] == "%"
  11058. && tokenisedDTD [i - 2].equalsIgnoreCase (T("<!entity")))
  11059. {
  11060. String ent (tokenisedDTD [i + 1]);
  11061. while (ent.endsWithChar ('>'))
  11062. ent = ent.dropLastCharacters (1);
  11063. if (ent.equalsIgnoreCase (T("system")))
  11064. {
  11065. String filename (tokenisedDTD [i + 2]);
  11066. while (filename.endsWithChar ('>'))
  11067. filename = filename.dropLastCharacters (1);
  11068. return getFileContents (filename);
  11069. }
  11070. else
  11071. {
  11072. return ent.trim().unquoted();
  11073. }
  11074. }
  11075. }
  11076. }
  11077. return entity;
  11078. }
  11079. END_JUCE_NAMESPACE
  11080. /*** End of inlined file: juce_XmlDocument.cpp ***/
  11081. /*** Start of inlined file: juce_XmlElement.cpp ***/
  11082. BEGIN_JUCE_NAMESPACE
  11083. XmlElement::XmlAttributeNode::XmlAttributeNode (const XmlAttributeNode& other) throw()
  11084. : name (other.name),
  11085. value (other.value),
  11086. next (0)
  11087. {
  11088. }
  11089. XmlElement::XmlAttributeNode::XmlAttributeNode (const String& name_, const String& value_) throw()
  11090. : name (name_),
  11091. value (value_),
  11092. next (0)
  11093. {
  11094. }
  11095. XmlElement::XmlElement (const String& tagName_) throw()
  11096. : tagName (tagName_),
  11097. firstChildElement (0),
  11098. nextElement (0),
  11099. attributes (0)
  11100. {
  11101. // the tag name mustn't be empty, or it'll look like a text element!
  11102. jassert (tagName_.containsNonWhitespaceChars())
  11103. // The tag can't contain spaces or other characters that would create invalid XML!
  11104. jassert (! tagName_.containsAnyOf (T(" <>/&")));
  11105. }
  11106. XmlElement::XmlElement (int /*dummy*/) throw()
  11107. : firstChildElement (0),
  11108. nextElement (0),
  11109. attributes (0)
  11110. {
  11111. }
  11112. XmlElement::XmlElement (const XmlElement& other) throw()
  11113. : tagName (other.tagName),
  11114. firstChildElement (0),
  11115. nextElement (0),
  11116. attributes (0)
  11117. {
  11118. copyChildrenAndAttributesFrom (other);
  11119. }
  11120. XmlElement& XmlElement::operator= (const XmlElement& other) throw()
  11121. {
  11122. if (this != &other)
  11123. {
  11124. removeAllAttributes();
  11125. deleteAllChildElements();
  11126. tagName = other.tagName;
  11127. copyChildrenAndAttributesFrom (other);
  11128. }
  11129. return *this;
  11130. }
  11131. void XmlElement::copyChildrenAndAttributesFrom (const XmlElement& other) throw()
  11132. {
  11133. XmlElement* child = other.firstChildElement;
  11134. XmlElement* lastChild = 0;
  11135. while (child != 0)
  11136. {
  11137. XmlElement* const copiedChild = new XmlElement (*child);
  11138. if (lastChild != 0)
  11139. lastChild->nextElement = copiedChild;
  11140. else
  11141. firstChildElement = copiedChild;
  11142. lastChild = copiedChild;
  11143. child = child->nextElement;
  11144. }
  11145. const XmlAttributeNode* att = other.attributes;
  11146. XmlAttributeNode* lastAtt = 0;
  11147. while (att != 0)
  11148. {
  11149. XmlAttributeNode* const newAtt = new XmlAttributeNode (*att);
  11150. if (lastAtt != 0)
  11151. lastAtt->next = newAtt;
  11152. else
  11153. attributes = newAtt;
  11154. lastAtt = newAtt;
  11155. att = att->next;
  11156. }
  11157. }
  11158. XmlElement::~XmlElement() throw()
  11159. {
  11160. XmlElement* child = firstChildElement;
  11161. while (child != 0)
  11162. {
  11163. XmlElement* const nextChild = child->nextElement;
  11164. delete child;
  11165. child = nextChild;
  11166. }
  11167. XmlAttributeNode* att = attributes;
  11168. while (att != 0)
  11169. {
  11170. XmlAttributeNode* const nextAtt = att->next;
  11171. delete att;
  11172. att = nextAtt;
  11173. }
  11174. }
  11175. namespace XmlOutputFunctions
  11176. {
  11177. static bool isLegalXmlChar (const uint32 c) throw()
  11178. {
  11179. static const unsigned char legalChars[] = { 0, 0, 0, 0, 171, 255, 255, 175, 255, 255, 255, 191, 254, 255, 255, 111 };
  11180. return c < sizeof (legalChars) * 8
  11181. && (legalChars [c >> 3] & (1 << (c & 7))) != 0;
  11182. }
  11183. static void escapeIllegalXmlChars (OutputStream& outputStream, const String& text, const bool changeNewLines)
  11184. {
  11185. const juce_wchar* t = (const juce_wchar*) text;
  11186. for (;;)
  11187. {
  11188. const juce_wchar character = *t++;
  11189. if (character == 0)
  11190. {
  11191. break;
  11192. }
  11193. else if (isLegalXmlChar ((uint32) character))
  11194. {
  11195. outputStream << (char) character;
  11196. }
  11197. else
  11198. {
  11199. switch (character)
  11200. {
  11201. case '&': outputStream << "&amp;"; break;
  11202. case '"': outputStream << "&quot;"; break;
  11203. case '>': outputStream << "&gt;"; break;
  11204. case '<': outputStream << "&lt;"; break;
  11205. case '\n':
  11206. if (changeNewLines)
  11207. outputStream << "&#10;";
  11208. else
  11209. outputStream << (char) character;
  11210. break;
  11211. case '\r':
  11212. if (changeNewLines)
  11213. outputStream << "&#13;";
  11214. else
  11215. outputStream << (char) character;
  11216. break;
  11217. default:
  11218. outputStream << "&#" << ((int) (unsigned int) character) << ';';
  11219. break;
  11220. }
  11221. }
  11222. }
  11223. }
  11224. static void writeSpaces (OutputStream& out, int numSpaces)
  11225. {
  11226. if (numSpaces > 0)
  11227. {
  11228. const char* const blanks = " ";
  11229. const int blankSize = (int) sizeof (blanks) - 1;
  11230. while (numSpaces > blankSize)
  11231. {
  11232. out.write (blanks, blankSize);
  11233. numSpaces -= blankSize;
  11234. }
  11235. out.write (blanks, numSpaces);
  11236. }
  11237. }
  11238. }
  11239. void XmlElement::writeElementAsText (OutputStream& outputStream,
  11240. const int indentationLevel,
  11241. const int lineWrapLength) const
  11242. {
  11243. using namespace XmlOutputFunctions;
  11244. writeSpaces (outputStream, indentationLevel);
  11245. if (! isTextElement())
  11246. {
  11247. outputStream.writeByte ('<');
  11248. outputStream << tagName;
  11249. const int attIndent = indentationLevel + tagName.length() + 1;
  11250. int lineLen = 0;
  11251. const XmlAttributeNode* att = attributes;
  11252. while (att != 0)
  11253. {
  11254. if (lineLen > lineWrapLength && indentationLevel >= 0)
  11255. {
  11256. outputStream.write ("\r\n", 2);
  11257. writeSpaces (outputStream, attIndent);
  11258. lineLen = 0;
  11259. }
  11260. const int64 startPos = outputStream.getPosition();
  11261. outputStream.writeByte (' ');
  11262. outputStream << att->name;
  11263. outputStream.write ("=\"", 2);
  11264. escapeIllegalXmlChars (outputStream, att->value, true);
  11265. outputStream.writeByte ('"');
  11266. lineLen += (int) (outputStream.getPosition() - startPos);
  11267. att = att->next;
  11268. }
  11269. if (firstChildElement != 0)
  11270. {
  11271. XmlElement* child = firstChildElement;
  11272. if (child->nextElement == 0 && child->isTextElement())
  11273. {
  11274. outputStream.writeByte ('>');
  11275. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11276. }
  11277. else
  11278. {
  11279. if (indentationLevel >= 0)
  11280. outputStream.write (">\r\n", 3);
  11281. else
  11282. outputStream.writeByte ('>');
  11283. bool lastWasTextNode = false;
  11284. while (child != 0)
  11285. {
  11286. if (child->isTextElement())
  11287. {
  11288. if ((! lastWasTextNode) && (indentationLevel >= 0))
  11289. writeSpaces (outputStream, indentationLevel + 2);
  11290. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11291. lastWasTextNode = true;
  11292. }
  11293. else
  11294. {
  11295. if (indentationLevel >= 0)
  11296. {
  11297. if (lastWasTextNode)
  11298. outputStream.write ("\r\n", 2);
  11299. child->writeElementAsText (outputStream, indentationLevel + 2, lineWrapLength);
  11300. }
  11301. else
  11302. {
  11303. child->writeElementAsText (outputStream, indentationLevel, lineWrapLength);
  11304. }
  11305. lastWasTextNode = false;
  11306. }
  11307. child = child->nextElement;
  11308. }
  11309. if (indentationLevel >= 0)
  11310. {
  11311. if (lastWasTextNode)
  11312. outputStream.write ("\r\n", 2);
  11313. writeSpaces (outputStream, indentationLevel);
  11314. }
  11315. }
  11316. outputStream.write ("</", 2);
  11317. outputStream << tagName;
  11318. if (indentationLevel >= 0)
  11319. outputStream.write (">\r\n", 3);
  11320. else
  11321. outputStream.writeByte ('>');
  11322. }
  11323. else
  11324. {
  11325. if (indentationLevel >= 0)
  11326. outputStream.write ("/>\r\n", 4);
  11327. else
  11328. outputStream.write ("/>", 2);
  11329. }
  11330. }
  11331. else
  11332. {
  11333. if (indentationLevel >= 0)
  11334. writeSpaces (outputStream, indentationLevel + 2);
  11335. escapeIllegalXmlChars (outputStream, getText(), false);
  11336. }
  11337. }
  11338. const String XmlElement::createDocument (const String& dtdToUse,
  11339. const bool allOnOneLine,
  11340. const bool includeXmlHeader,
  11341. const String& encodingType,
  11342. const int lineWrapLength) const
  11343. {
  11344. MemoryOutputStream mem (2048, 4096);
  11345. writeToStream (mem, dtdToUse, allOnOneLine, includeXmlHeader, encodingType, lineWrapLength);
  11346. return String (mem.getData(), mem.getDataSize());
  11347. }
  11348. void XmlElement::writeToStream (OutputStream& output,
  11349. const String& dtdToUse,
  11350. const bool allOnOneLine,
  11351. const bool includeXmlHeader,
  11352. const String& encodingType,
  11353. const int lineWrapLength) const
  11354. {
  11355. if (includeXmlHeader)
  11356. output << "<?xml version=\"1.0\" encoding=\"" << encodingType
  11357. << (allOnOneLine ? "\"?> " : "\"?>\r\n\r\n");
  11358. if (dtdToUse.isNotEmpty())
  11359. output << dtdToUse << (allOnOneLine ? " " : "\r\n");
  11360. writeElementAsText (output, allOnOneLine ? -1 : 0, lineWrapLength);
  11361. }
  11362. bool XmlElement::writeToFile (const File& file,
  11363. const String& dtdToUse,
  11364. const String& encodingType,
  11365. const int lineWrapLength) const
  11366. {
  11367. if (file.hasWriteAccess())
  11368. {
  11369. TemporaryFile tempFile (file);
  11370. ScopedPointer <FileOutputStream> out (tempFile.getFile().createOutputStream());
  11371. if (out != 0)
  11372. {
  11373. writeToStream (*out, dtdToUse, false, true, encodingType, lineWrapLength);
  11374. out = 0;
  11375. return tempFile.overwriteTargetFileWithTemporary();
  11376. }
  11377. }
  11378. return false;
  11379. }
  11380. bool XmlElement::hasTagName (const String& tagNameWanted) const throw()
  11381. {
  11382. #ifdef JUCE_DEBUG
  11383. // if debugging, check that the case is actually the same, because
  11384. // valid xml is case-sensitive, and although this lets it pass, it's
  11385. // better not to..
  11386. if (tagName.equalsIgnoreCase (tagNameWanted))
  11387. {
  11388. jassert (tagName == tagNameWanted);
  11389. return true;
  11390. }
  11391. else
  11392. {
  11393. return false;
  11394. }
  11395. #else
  11396. return tagName.equalsIgnoreCase (tagNameWanted);
  11397. #endif
  11398. }
  11399. XmlElement* XmlElement::getNextElementWithTagName (const String& requiredTagName) const
  11400. {
  11401. XmlElement* e = nextElement;
  11402. while (e != 0 && ! e->hasTagName (requiredTagName))
  11403. e = e->nextElement;
  11404. return e;
  11405. }
  11406. int XmlElement::getNumAttributes() const throw()
  11407. {
  11408. const XmlAttributeNode* att = attributes;
  11409. int count = 0;
  11410. while (att != 0)
  11411. {
  11412. att = att->next;
  11413. ++count;
  11414. }
  11415. return count;
  11416. }
  11417. const String& XmlElement::getAttributeName (const int index) const throw()
  11418. {
  11419. const XmlAttributeNode* att = attributes;
  11420. int count = 0;
  11421. while (att != 0)
  11422. {
  11423. if (count == index)
  11424. return att->name;
  11425. att = att->next;
  11426. ++count;
  11427. }
  11428. return String::empty;
  11429. }
  11430. const String& XmlElement::getAttributeValue (const int index) const throw()
  11431. {
  11432. const XmlAttributeNode* att = attributes;
  11433. int count = 0;
  11434. while (att != 0)
  11435. {
  11436. if (count == index)
  11437. return att->value;
  11438. att = att->next;
  11439. ++count;
  11440. }
  11441. return String::empty;
  11442. }
  11443. bool XmlElement::hasAttribute (const String& attributeName) const throw()
  11444. {
  11445. const XmlAttributeNode* att = attributes;
  11446. while (att != 0)
  11447. {
  11448. if (att->name.equalsIgnoreCase (attributeName))
  11449. return true;
  11450. att = att->next;
  11451. }
  11452. return false;
  11453. }
  11454. const String& XmlElement::getStringAttribute (const String& attributeName) const throw()
  11455. {
  11456. const XmlAttributeNode* att = attributes;
  11457. while (att != 0)
  11458. {
  11459. if (att->name.equalsIgnoreCase (attributeName))
  11460. return att->value;
  11461. att = att->next;
  11462. }
  11463. return String::empty;
  11464. }
  11465. const String XmlElement::getStringAttribute (const String& attributeName, const String& defaultReturnValue) const
  11466. {
  11467. const XmlAttributeNode* att = attributes;
  11468. while (att != 0)
  11469. {
  11470. if (att->name.equalsIgnoreCase (attributeName))
  11471. return att->value;
  11472. att = att->next;
  11473. }
  11474. return defaultReturnValue;
  11475. }
  11476. int XmlElement::getIntAttribute (const String& attributeName, const int defaultReturnValue) const
  11477. {
  11478. const XmlAttributeNode* att = attributes;
  11479. while (att != 0)
  11480. {
  11481. if (att->name.equalsIgnoreCase (attributeName))
  11482. return att->value.getIntValue();
  11483. att = att->next;
  11484. }
  11485. return defaultReturnValue;
  11486. }
  11487. double XmlElement::getDoubleAttribute (const String& attributeName, const double defaultReturnValue) const
  11488. {
  11489. const XmlAttributeNode* att = attributes;
  11490. while (att != 0)
  11491. {
  11492. if (att->name.equalsIgnoreCase (attributeName))
  11493. return att->value.getDoubleValue();
  11494. att = att->next;
  11495. }
  11496. return defaultReturnValue;
  11497. }
  11498. bool XmlElement::getBoolAttribute (const String& attributeName, const bool defaultReturnValue) const
  11499. {
  11500. const XmlAttributeNode* att = attributes;
  11501. while (att != 0)
  11502. {
  11503. if (att->name.equalsIgnoreCase (attributeName))
  11504. {
  11505. juce_wchar firstChar = att->value[0];
  11506. if (CharacterFunctions::isWhitespace (firstChar))
  11507. firstChar = att->value.trimStart() [0];
  11508. return firstChar == '1'
  11509. || firstChar == 't'
  11510. || firstChar == 'y'
  11511. || firstChar == 'T'
  11512. || firstChar == 'Y';
  11513. }
  11514. att = att->next;
  11515. }
  11516. return defaultReturnValue;
  11517. }
  11518. bool XmlElement::compareAttribute (const String& attributeName,
  11519. const String& stringToCompareAgainst,
  11520. const bool ignoreCase) const throw()
  11521. {
  11522. const XmlAttributeNode* att = attributes;
  11523. while (att != 0)
  11524. {
  11525. if (att->name.equalsIgnoreCase (attributeName))
  11526. {
  11527. if (ignoreCase)
  11528. return att->value.equalsIgnoreCase (stringToCompareAgainst);
  11529. else
  11530. return att->value == stringToCompareAgainst;
  11531. }
  11532. att = att->next;
  11533. }
  11534. return false;
  11535. }
  11536. void XmlElement::setAttribute (const String& attributeName, const String& value)
  11537. {
  11538. #ifdef JUCE_DEBUG
  11539. // check the identifier being passed in is legal..
  11540. const juce_wchar* t = attributeName;
  11541. while (*t != 0)
  11542. {
  11543. jassert (CharacterFunctions::isLetterOrDigit (*t)
  11544. || *t == '_'
  11545. || *t == '-'
  11546. || *t == ':');
  11547. ++t;
  11548. }
  11549. #endif
  11550. if (attributes == 0)
  11551. {
  11552. attributes = new XmlAttributeNode (attributeName, value);
  11553. }
  11554. else
  11555. {
  11556. XmlAttributeNode* att = attributes;
  11557. for (;;)
  11558. {
  11559. if (att->name.equalsIgnoreCase (attributeName))
  11560. {
  11561. att->value = value;
  11562. break;
  11563. }
  11564. else if (att->next == 0)
  11565. {
  11566. att->next = new XmlAttributeNode (attributeName, value);
  11567. break;
  11568. }
  11569. att = att->next;
  11570. }
  11571. }
  11572. }
  11573. void XmlElement::setAttribute (const String& attributeName, const int number)
  11574. {
  11575. setAttribute (attributeName, String (number));
  11576. }
  11577. void XmlElement::setAttribute (const String& attributeName, const double number)
  11578. {
  11579. setAttribute (attributeName, String (number));
  11580. }
  11581. void XmlElement::removeAttribute (const String& attributeName) throw()
  11582. {
  11583. XmlAttributeNode* att = attributes;
  11584. XmlAttributeNode* lastAtt = 0;
  11585. while (att != 0)
  11586. {
  11587. if (att->name.equalsIgnoreCase (attributeName))
  11588. {
  11589. if (lastAtt == 0)
  11590. attributes = att->next;
  11591. else
  11592. lastAtt->next = att->next;
  11593. delete att;
  11594. break;
  11595. }
  11596. lastAtt = att;
  11597. att = att->next;
  11598. }
  11599. }
  11600. void XmlElement::removeAllAttributes() throw()
  11601. {
  11602. while (attributes != 0)
  11603. {
  11604. XmlAttributeNode* const nextAtt = attributes->next;
  11605. delete attributes;
  11606. attributes = nextAtt;
  11607. }
  11608. }
  11609. int XmlElement::getNumChildElements() const throw()
  11610. {
  11611. int count = 0;
  11612. const XmlElement* child = firstChildElement;
  11613. while (child != 0)
  11614. {
  11615. ++count;
  11616. child = child->nextElement;
  11617. }
  11618. return count;
  11619. }
  11620. XmlElement* XmlElement::getChildElement (const int index) const throw()
  11621. {
  11622. int count = 0;
  11623. XmlElement* child = firstChildElement;
  11624. while (child != 0 && count < index)
  11625. {
  11626. child = child->nextElement;
  11627. ++count;
  11628. }
  11629. return child;
  11630. }
  11631. XmlElement* XmlElement::getChildByName (const String& childName) const throw()
  11632. {
  11633. XmlElement* child = firstChildElement;
  11634. while (child != 0)
  11635. {
  11636. if (child->hasTagName (childName))
  11637. break;
  11638. child = child->nextElement;
  11639. }
  11640. return child;
  11641. }
  11642. void XmlElement::addChildElement (XmlElement* const newNode) throw()
  11643. {
  11644. if (newNode != 0)
  11645. {
  11646. if (firstChildElement == 0)
  11647. {
  11648. firstChildElement = newNode;
  11649. }
  11650. else
  11651. {
  11652. XmlElement* child = firstChildElement;
  11653. while (child->nextElement != 0)
  11654. child = child->nextElement;
  11655. child->nextElement = newNode;
  11656. // if this is non-zero, then something's probably
  11657. // gone wrong..
  11658. jassert (newNode->nextElement == 0);
  11659. }
  11660. }
  11661. }
  11662. void XmlElement::insertChildElement (XmlElement* const newNode,
  11663. int indexToInsertAt) throw()
  11664. {
  11665. if (newNode != 0)
  11666. {
  11667. removeChildElement (newNode, false);
  11668. if (indexToInsertAt == 0)
  11669. {
  11670. newNode->nextElement = firstChildElement;
  11671. firstChildElement = newNode;
  11672. }
  11673. else
  11674. {
  11675. if (firstChildElement == 0)
  11676. {
  11677. firstChildElement = newNode;
  11678. }
  11679. else
  11680. {
  11681. if (indexToInsertAt < 0)
  11682. indexToInsertAt = std::numeric_limits<int>::max();
  11683. XmlElement* child = firstChildElement;
  11684. while (child->nextElement != 0 && --indexToInsertAt > 0)
  11685. child = child->nextElement;
  11686. newNode->nextElement = child->nextElement;
  11687. child->nextElement = newNode;
  11688. }
  11689. }
  11690. }
  11691. }
  11692. XmlElement* XmlElement::createNewChildElement (const String& tagName)
  11693. {
  11694. XmlElement* const newElement = new XmlElement (tagName);
  11695. addChildElement (newElement);
  11696. return newElement;
  11697. }
  11698. bool XmlElement::replaceChildElement (XmlElement* const currentChildElement,
  11699. XmlElement* const newNode) throw()
  11700. {
  11701. if (newNode != 0)
  11702. {
  11703. XmlElement* child = firstChildElement;
  11704. XmlElement* previousNode = 0;
  11705. while (child != 0)
  11706. {
  11707. if (child == currentChildElement)
  11708. {
  11709. if (child != newNode)
  11710. {
  11711. if (previousNode == 0)
  11712. firstChildElement = newNode;
  11713. else
  11714. previousNode->nextElement = newNode;
  11715. newNode->nextElement = child->nextElement;
  11716. delete child;
  11717. }
  11718. return true;
  11719. }
  11720. previousNode = child;
  11721. child = child->nextElement;
  11722. }
  11723. }
  11724. return false;
  11725. }
  11726. void XmlElement::removeChildElement (XmlElement* const childToRemove,
  11727. const bool shouldDeleteTheChild) throw()
  11728. {
  11729. if (childToRemove != 0)
  11730. {
  11731. if (firstChildElement == childToRemove)
  11732. {
  11733. firstChildElement = childToRemove->nextElement;
  11734. childToRemove->nextElement = 0;
  11735. }
  11736. else
  11737. {
  11738. XmlElement* child = firstChildElement;
  11739. XmlElement* last = 0;
  11740. while (child != 0)
  11741. {
  11742. if (child == childToRemove)
  11743. {
  11744. if (last == 0)
  11745. firstChildElement = child->nextElement;
  11746. else
  11747. last->nextElement = child->nextElement;
  11748. childToRemove->nextElement = 0;
  11749. break;
  11750. }
  11751. last = child;
  11752. child = child->nextElement;
  11753. }
  11754. }
  11755. if (shouldDeleteTheChild)
  11756. delete childToRemove;
  11757. }
  11758. }
  11759. bool XmlElement::isEquivalentTo (const XmlElement* const other,
  11760. const bool ignoreOrderOfAttributes) const throw()
  11761. {
  11762. if (this != other)
  11763. {
  11764. if (other == 0 || tagName != other->tagName)
  11765. {
  11766. return false;
  11767. }
  11768. if (ignoreOrderOfAttributes)
  11769. {
  11770. int totalAtts = 0;
  11771. const XmlAttributeNode* att = attributes;
  11772. while (att != 0)
  11773. {
  11774. if (! other->compareAttribute (att->name, att->value))
  11775. return false;
  11776. att = att->next;
  11777. ++totalAtts;
  11778. }
  11779. if (totalAtts != other->getNumAttributes())
  11780. return false;
  11781. }
  11782. else
  11783. {
  11784. const XmlAttributeNode* thisAtt = attributes;
  11785. const XmlAttributeNode* otherAtt = other->attributes;
  11786. for (;;)
  11787. {
  11788. if (thisAtt == 0 || otherAtt == 0)
  11789. {
  11790. if (thisAtt == otherAtt) // both 0, so it's a match
  11791. break;
  11792. return false;
  11793. }
  11794. if (thisAtt->name != otherAtt->name
  11795. || thisAtt->value != otherAtt->value)
  11796. {
  11797. return false;
  11798. }
  11799. thisAtt = thisAtt->next;
  11800. otherAtt = otherAtt->next;
  11801. }
  11802. }
  11803. const XmlElement* thisChild = firstChildElement;
  11804. const XmlElement* otherChild = other->firstChildElement;
  11805. for (;;)
  11806. {
  11807. if (thisChild == 0 || otherChild == 0)
  11808. {
  11809. if (thisChild == otherChild) // both 0, so it's a match
  11810. break;
  11811. return false;
  11812. }
  11813. if (! thisChild->isEquivalentTo (otherChild, ignoreOrderOfAttributes))
  11814. return false;
  11815. thisChild = thisChild->nextElement;
  11816. otherChild = otherChild->nextElement;
  11817. }
  11818. }
  11819. return true;
  11820. }
  11821. void XmlElement::deleteAllChildElements() throw()
  11822. {
  11823. while (firstChildElement != 0)
  11824. {
  11825. XmlElement* const nextChild = firstChildElement->nextElement;
  11826. delete firstChildElement;
  11827. firstChildElement = nextChild;
  11828. }
  11829. }
  11830. void XmlElement::deleteAllChildElementsWithTagName (const String& name) throw()
  11831. {
  11832. XmlElement* child = firstChildElement;
  11833. while (child != 0)
  11834. {
  11835. if (child->hasTagName (name))
  11836. {
  11837. XmlElement* const nextChild = child->nextElement;
  11838. removeChildElement (child, true);
  11839. child = nextChild;
  11840. }
  11841. else
  11842. {
  11843. child = child->nextElement;
  11844. }
  11845. }
  11846. }
  11847. bool XmlElement::containsChildElement (const XmlElement* const possibleChild) const throw()
  11848. {
  11849. const XmlElement* child = firstChildElement;
  11850. while (child != 0)
  11851. {
  11852. if (child == possibleChild)
  11853. return true;
  11854. child = child->nextElement;
  11855. }
  11856. return false;
  11857. }
  11858. XmlElement* XmlElement::findParentElementOf (const XmlElement* const elementToLookFor) throw()
  11859. {
  11860. if (this == elementToLookFor || elementToLookFor == 0)
  11861. return 0;
  11862. XmlElement* child = firstChildElement;
  11863. while (child != 0)
  11864. {
  11865. if (elementToLookFor == child)
  11866. return this;
  11867. XmlElement* const found = child->findParentElementOf (elementToLookFor);
  11868. if (found != 0)
  11869. return found;
  11870. child = child->nextElement;
  11871. }
  11872. return 0;
  11873. }
  11874. void XmlElement::getChildElementsAsArray (XmlElement** elems) const throw()
  11875. {
  11876. XmlElement* e = firstChildElement;
  11877. while (e != 0)
  11878. {
  11879. *elems++ = e;
  11880. e = e->nextElement;
  11881. }
  11882. }
  11883. void XmlElement::reorderChildElements (XmlElement** const elems, const int num) throw()
  11884. {
  11885. XmlElement* e = firstChildElement = elems[0];
  11886. for (int i = 1; i < num; ++i)
  11887. {
  11888. e->nextElement = elems[i];
  11889. e = e->nextElement;
  11890. }
  11891. e->nextElement = 0;
  11892. }
  11893. bool XmlElement::isTextElement() const throw()
  11894. {
  11895. return tagName.isEmpty();
  11896. }
  11897. static const juce_wchar* const juce_xmltextContentAttributeName = T("text");
  11898. const String XmlElement::getText() const throw()
  11899. {
  11900. jassert (isTextElement()); // you're trying to get the text from an element that
  11901. // isn't actually a text element.. If this contains text sub-nodes, you
  11902. // probably want to use getAllSubText instead.
  11903. return getStringAttribute (juce_xmltextContentAttributeName);
  11904. }
  11905. void XmlElement::setText (const String& newText) throw()
  11906. {
  11907. if (isTextElement())
  11908. {
  11909. setAttribute (juce_xmltextContentAttributeName, newText);
  11910. }
  11911. else
  11912. {
  11913. jassertfalse // you can only change the text in a text element, not a normal one.
  11914. }
  11915. }
  11916. const String XmlElement::getAllSubText() const throw()
  11917. {
  11918. String result;
  11919. String::Concatenator concatenator (result);
  11920. const XmlElement* child = firstChildElement;
  11921. while (child != 0)
  11922. {
  11923. if (child->isTextElement())
  11924. concatenator.append (child->getText());
  11925. child = child->nextElement;
  11926. }
  11927. return result;
  11928. }
  11929. const String XmlElement::getChildElementAllSubText (const String& childTagName,
  11930. const String& defaultReturnValue) const throw()
  11931. {
  11932. const XmlElement* const child = getChildByName (childTagName);
  11933. if (child != 0)
  11934. return child->getAllSubText();
  11935. return defaultReturnValue;
  11936. }
  11937. XmlElement* XmlElement::createTextElement (const String& text) throw()
  11938. {
  11939. XmlElement* const e = new XmlElement ((int) 0);
  11940. e->setAttribute (juce_xmltextContentAttributeName, text);
  11941. return e;
  11942. }
  11943. void XmlElement::addTextElement (const String& text) throw()
  11944. {
  11945. addChildElement (createTextElement (text));
  11946. }
  11947. void XmlElement::deleteAllTextElements() throw()
  11948. {
  11949. XmlElement* child = firstChildElement;
  11950. while (child != 0)
  11951. {
  11952. XmlElement* const next = child->nextElement;
  11953. if (child->isTextElement())
  11954. removeChildElement (child, true);
  11955. child = next;
  11956. }
  11957. }
  11958. END_JUCE_NAMESPACE
  11959. /*** End of inlined file: juce_XmlElement.cpp ***/
  11960. /*** Start of inlined file: juce_ReadWriteLock.cpp ***/
  11961. BEGIN_JUCE_NAMESPACE
  11962. ReadWriteLock::ReadWriteLock() throw()
  11963. : numWaitingWriters (0),
  11964. numWriters (0),
  11965. writerThreadId (0)
  11966. {
  11967. }
  11968. ReadWriteLock::~ReadWriteLock() throw()
  11969. {
  11970. jassert (readerThreads.size() == 0);
  11971. jassert (numWriters == 0);
  11972. }
  11973. void ReadWriteLock::enterRead() const throw()
  11974. {
  11975. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  11976. const ScopedLock sl (accessLock);
  11977. for (;;)
  11978. {
  11979. jassert (readerThreads.size() % 2 == 0);
  11980. int i;
  11981. for (i = 0; i < readerThreads.size(); i += 2)
  11982. if (readerThreads.getUnchecked(i) == threadId)
  11983. break;
  11984. if (i < readerThreads.size()
  11985. || numWriters + numWaitingWriters == 0
  11986. || (threadId == writerThreadId && numWriters > 0))
  11987. {
  11988. if (i < readerThreads.size())
  11989. {
  11990. readerThreads.set (i + 1, (Thread::ThreadID) (1 + (pointer_sized_int) readerThreads.getUnchecked (i + 1)));
  11991. }
  11992. else
  11993. {
  11994. readerThreads.add (threadId);
  11995. readerThreads.add ((Thread::ThreadID) 1);
  11996. }
  11997. return;
  11998. }
  11999. const ScopedUnlock ul (accessLock);
  12000. waitEvent.wait (100);
  12001. }
  12002. }
  12003. void ReadWriteLock::exitRead() const throw()
  12004. {
  12005. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12006. const ScopedLock sl (accessLock);
  12007. for (int i = 0; i < readerThreads.size(); i += 2)
  12008. {
  12009. if (readerThreads.getUnchecked(i) == threadId)
  12010. {
  12011. const pointer_sized_int newCount = ((pointer_sized_int) readerThreads.getUnchecked (i + 1)) - 1;
  12012. if (newCount == 0)
  12013. {
  12014. readerThreads.removeRange (i, 2);
  12015. waitEvent.signal();
  12016. }
  12017. else
  12018. {
  12019. readerThreads.set (i + 1, (Thread::ThreadID) newCount);
  12020. }
  12021. return;
  12022. }
  12023. }
  12024. jassertfalse // unlocking a lock that wasn't locked..
  12025. }
  12026. void ReadWriteLock::enterWrite() const throw()
  12027. {
  12028. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12029. const ScopedLock sl (accessLock);
  12030. for (;;)
  12031. {
  12032. if (readerThreads.size() + numWriters == 0
  12033. || threadId == writerThreadId
  12034. || (readerThreads.size() == 2
  12035. && readerThreads.getUnchecked(0) == threadId))
  12036. {
  12037. writerThreadId = threadId;
  12038. ++numWriters;
  12039. break;
  12040. }
  12041. ++numWaitingWriters;
  12042. accessLock.exit();
  12043. waitEvent.wait (100);
  12044. accessLock.enter();
  12045. --numWaitingWriters;
  12046. }
  12047. }
  12048. bool ReadWriteLock::tryEnterWrite() const throw()
  12049. {
  12050. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12051. const ScopedLock sl (accessLock);
  12052. if (readerThreads.size() + numWriters == 0
  12053. || threadId == writerThreadId
  12054. || (readerThreads.size() == 2
  12055. && readerThreads.getUnchecked(0) == threadId))
  12056. {
  12057. writerThreadId = threadId;
  12058. ++numWriters;
  12059. return true;
  12060. }
  12061. return false;
  12062. }
  12063. void ReadWriteLock::exitWrite() const throw()
  12064. {
  12065. const ScopedLock sl (accessLock);
  12066. // check this thread actually had the lock..
  12067. jassert (numWriters > 0 && writerThreadId == Thread::getCurrentThreadId());
  12068. if (--numWriters == 0)
  12069. {
  12070. writerThreadId = 0;
  12071. waitEvent.signal();
  12072. }
  12073. }
  12074. END_JUCE_NAMESPACE
  12075. /*** End of inlined file: juce_ReadWriteLock.cpp ***/
  12076. /*** Start of inlined file: juce_Thread.cpp ***/
  12077. BEGIN_JUCE_NAMESPACE
  12078. // these functions are implemented in the platform-specific code.
  12079. void* juce_createThread (void* userData);
  12080. void juce_killThread (void* handle);
  12081. bool juce_setThreadPriority (void* handle, int priority);
  12082. void juce_setCurrentThreadName (const String& name);
  12083. #if JUCE_WIN32
  12084. void juce_CloseThreadHandle (void* handle);
  12085. #endif
  12086. void Thread::threadEntryPoint (Thread* const thread)
  12087. {
  12088. {
  12089. const ScopedLock sl (runningThreadsLock);
  12090. runningThreads.add (thread);
  12091. }
  12092. JUCE_TRY
  12093. {
  12094. thread->threadId_ = Thread::getCurrentThreadId();
  12095. if (thread->threadName_.isNotEmpty())
  12096. juce_setCurrentThreadName (thread->threadName_);
  12097. if (thread->startSuspensionEvent_.wait (10000))
  12098. {
  12099. if (thread->affinityMask_ != 0)
  12100. setCurrentThreadAffinityMask (thread->affinityMask_);
  12101. thread->run();
  12102. }
  12103. }
  12104. JUCE_CATCH_ALL_ASSERT
  12105. {
  12106. const ScopedLock sl (runningThreadsLock);
  12107. jassert (runningThreads.contains (thread));
  12108. runningThreads.removeValue (thread);
  12109. }
  12110. #if JUCE_WIN32
  12111. juce_CloseThreadHandle (thread->threadHandle_);
  12112. #endif
  12113. thread->threadHandle_ = 0;
  12114. thread->threadId_ = 0;
  12115. }
  12116. // used to wrap the incoming call from the platform-specific code
  12117. void JUCE_API juce_threadEntryPoint (void* userData)
  12118. {
  12119. Thread::threadEntryPoint ((Thread*) userData);
  12120. }
  12121. Thread::Thread (const String& threadName)
  12122. : threadName_ (threadName),
  12123. threadHandle_ (0),
  12124. threadPriority_ (5),
  12125. threadId_ (0),
  12126. affinityMask_ (0),
  12127. threadShouldExit_ (false)
  12128. {
  12129. }
  12130. Thread::~Thread()
  12131. {
  12132. stopThread (100);
  12133. }
  12134. void Thread::startThread()
  12135. {
  12136. const ScopedLock sl (startStopLock);
  12137. threadShouldExit_ = false;
  12138. if (threadHandle_ == 0)
  12139. {
  12140. threadHandle_ = juce_createThread ((void*) this);
  12141. juce_setThreadPriority (threadHandle_, threadPriority_);
  12142. startSuspensionEvent_.signal();
  12143. }
  12144. }
  12145. void Thread::startThread (const int priority)
  12146. {
  12147. const ScopedLock sl (startStopLock);
  12148. if (threadHandle_ == 0)
  12149. {
  12150. threadPriority_ = priority;
  12151. startThread();
  12152. }
  12153. else
  12154. {
  12155. setPriority (priority);
  12156. }
  12157. }
  12158. bool Thread::isThreadRunning() const
  12159. {
  12160. return threadHandle_ != 0;
  12161. }
  12162. void Thread::signalThreadShouldExit()
  12163. {
  12164. threadShouldExit_ = true;
  12165. }
  12166. bool Thread::waitForThreadToExit (const int timeOutMilliseconds) const
  12167. {
  12168. // Doh! So how exactly do you expect this thread to wait for itself to stop??
  12169. jassert (getThreadId() != getCurrentThreadId());
  12170. const int sleepMsPerIteration = 5;
  12171. int count = timeOutMilliseconds / sleepMsPerIteration;
  12172. while (isThreadRunning())
  12173. {
  12174. if (timeOutMilliseconds > 0 && --count < 0)
  12175. return false;
  12176. sleep (sleepMsPerIteration);
  12177. }
  12178. return true;
  12179. }
  12180. void Thread::stopThread (const int timeOutMilliseconds)
  12181. {
  12182. // agh! You can't stop the thread that's calling this method! How on earth
  12183. // would that work??
  12184. jassert (getCurrentThreadId() != getThreadId());
  12185. const ScopedLock sl (startStopLock);
  12186. if (isThreadRunning())
  12187. {
  12188. signalThreadShouldExit();
  12189. notify();
  12190. if (timeOutMilliseconds != 0)
  12191. waitForThreadToExit (timeOutMilliseconds);
  12192. if (isThreadRunning())
  12193. {
  12194. // very bad karma if this point is reached, as
  12195. // there are bound to be locks and events left in
  12196. // silly states when a thread is killed by force..
  12197. jassertfalse
  12198. Logger::writeToLog ("!! killing thread by force !!");
  12199. juce_killThread (threadHandle_);
  12200. threadHandle_ = 0;
  12201. threadId_ = 0;
  12202. const ScopedLock sl2 (runningThreadsLock);
  12203. runningThreads.removeValue (this);
  12204. }
  12205. }
  12206. }
  12207. bool Thread::setPriority (const int priority)
  12208. {
  12209. const ScopedLock sl (startStopLock);
  12210. const bool worked = juce_setThreadPriority (threadHandle_, priority);
  12211. if (worked)
  12212. threadPriority_ = priority;
  12213. return worked;
  12214. }
  12215. bool Thread::setCurrentThreadPriority (const int priority)
  12216. {
  12217. return juce_setThreadPriority (0, priority);
  12218. }
  12219. void Thread::setAffinityMask (const uint32 affinityMask)
  12220. {
  12221. affinityMask_ = affinityMask;
  12222. }
  12223. bool Thread::wait (const int timeOutMilliseconds) const
  12224. {
  12225. return defaultEvent_.wait (timeOutMilliseconds);
  12226. }
  12227. void Thread::notify() const
  12228. {
  12229. defaultEvent_.signal();
  12230. }
  12231. int Thread::getNumRunningThreads()
  12232. {
  12233. return runningThreads.size();
  12234. }
  12235. Thread* Thread::getCurrentThread()
  12236. {
  12237. const ThreadID thisId = getCurrentThreadId();
  12238. const ScopedLock sl (runningThreadsLock);
  12239. for (int i = runningThreads.size(); --i >= 0;)
  12240. {
  12241. Thread* const t = runningThreads.getUnchecked(i);
  12242. if (t->threadId_ == thisId)
  12243. return t;
  12244. }
  12245. return 0;
  12246. }
  12247. void Thread::stopAllThreads (const int timeOutMilliseconds)
  12248. {
  12249. {
  12250. const ScopedLock sl (runningThreadsLock);
  12251. for (int i = runningThreads.size(); --i >= 0;)
  12252. runningThreads.getUnchecked(i)->signalThreadShouldExit();
  12253. }
  12254. for (;;)
  12255. {
  12256. Thread* firstThread;
  12257. {
  12258. const ScopedLock sl (runningThreadsLock);
  12259. firstThread = runningThreads.getFirst();
  12260. }
  12261. if (firstThread == 0)
  12262. break;
  12263. firstThread->stopThread (timeOutMilliseconds);
  12264. }
  12265. }
  12266. Array<Thread*> Thread::runningThreads;
  12267. CriticalSection Thread::runningThreadsLock;
  12268. END_JUCE_NAMESPACE
  12269. /*** End of inlined file: juce_Thread.cpp ***/
  12270. /*** Start of inlined file: juce_ThreadPool.cpp ***/
  12271. BEGIN_JUCE_NAMESPACE
  12272. ThreadPoolJob::ThreadPoolJob (const String& name)
  12273. : jobName (name),
  12274. pool (0),
  12275. shouldStop (false),
  12276. isActive (false),
  12277. shouldBeDeleted (false)
  12278. {
  12279. }
  12280. ThreadPoolJob::~ThreadPoolJob()
  12281. {
  12282. // you mustn't delete a job while it's still in a pool! Use ThreadPool::removeJob()
  12283. // to remove it first!
  12284. jassert (pool == 0 || ! pool->contains (this));
  12285. }
  12286. const String ThreadPoolJob::getJobName() const
  12287. {
  12288. return jobName;
  12289. }
  12290. void ThreadPoolJob::setJobName (const String& newName)
  12291. {
  12292. jobName = newName;
  12293. }
  12294. void ThreadPoolJob::signalJobShouldExit()
  12295. {
  12296. shouldStop = true;
  12297. }
  12298. class ThreadPool::ThreadPoolThread : public Thread
  12299. {
  12300. public:
  12301. ThreadPoolThread (ThreadPool& pool_)
  12302. : Thread ("Pool"),
  12303. pool (pool_),
  12304. busy (false)
  12305. {
  12306. }
  12307. ~ThreadPoolThread()
  12308. {
  12309. }
  12310. void run()
  12311. {
  12312. while (! threadShouldExit())
  12313. {
  12314. if (! pool.runNextJob())
  12315. wait (500);
  12316. }
  12317. }
  12318. private:
  12319. ThreadPool& pool;
  12320. bool volatile busy;
  12321. ThreadPoolThread (const ThreadPoolThread&);
  12322. ThreadPoolThread& operator= (const ThreadPoolThread&);
  12323. };
  12324. ThreadPool::ThreadPool (const int numThreads,
  12325. const bool startThreadsOnlyWhenNeeded,
  12326. const int stopThreadsWhenNotUsedTimeoutMs)
  12327. : threadStopTimeout (stopThreadsWhenNotUsedTimeoutMs),
  12328. priority (5)
  12329. {
  12330. jassert (numThreads > 0); // not much point having one of these with no threads in it.
  12331. for (int i = jmax (1, numThreads); --i >= 0;)
  12332. threads.add (new ThreadPoolThread (*this));
  12333. if (! startThreadsOnlyWhenNeeded)
  12334. for (int i = threads.size(); --i >= 0;)
  12335. threads.getUnchecked(i)->startThread (priority);
  12336. }
  12337. ThreadPool::~ThreadPool()
  12338. {
  12339. removeAllJobs (true, 4000);
  12340. int i;
  12341. for (i = threads.size(); --i >= 0;)
  12342. threads.getUnchecked(i)->signalThreadShouldExit();
  12343. for (i = threads.size(); --i >= 0;)
  12344. threads.getUnchecked(i)->stopThread (500);
  12345. }
  12346. void ThreadPool::addJob (ThreadPoolJob* const job)
  12347. {
  12348. jassert (job != 0);
  12349. jassert (job->pool == 0);
  12350. if (job->pool == 0)
  12351. {
  12352. job->pool = this;
  12353. job->shouldStop = false;
  12354. job->isActive = false;
  12355. {
  12356. const ScopedLock sl (lock);
  12357. jobs.add (job);
  12358. int numRunning = 0;
  12359. for (int i = threads.size(); --i >= 0;)
  12360. if (threads.getUnchecked(i)->isThreadRunning() && ! threads.getUnchecked(i)->threadShouldExit())
  12361. ++numRunning;
  12362. if (numRunning < threads.size())
  12363. {
  12364. bool startedOne = false;
  12365. int n = 1000;
  12366. while (--n >= 0 && ! startedOne)
  12367. {
  12368. for (int i = threads.size(); --i >= 0;)
  12369. {
  12370. if (! threads.getUnchecked(i)->isThreadRunning())
  12371. {
  12372. threads.getUnchecked(i)->startThread (priority);
  12373. startedOne = true;
  12374. break;
  12375. }
  12376. }
  12377. if (! startedOne)
  12378. Thread::sleep (2);
  12379. }
  12380. }
  12381. }
  12382. for (int i = threads.size(); --i >= 0;)
  12383. threads.getUnchecked(i)->notify();
  12384. }
  12385. }
  12386. int ThreadPool::getNumJobs() const
  12387. {
  12388. return jobs.size();
  12389. }
  12390. ThreadPoolJob* ThreadPool::getJob (const int index) const
  12391. {
  12392. const ScopedLock sl (lock);
  12393. return (ThreadPoolJob*) jobs [index];
  12394. }
  12395. bool ThreadPool::contains (const ThreadPoolJob* const job) const
  12396. {
  12397. const ScopedLock sl (lock);
  12398. return jobs.contains (const_cast <ThreadPoolJob*> (job));
  12399. }
  12400. bool ThreadPool::isJobRunning (const ThreadPoolJob* const job) const
  12401. {
  12402. const ScopedLock sl (lock);
  12403. return jobs.contains (const_cast <ThreadPoolJob*> (job)) && job->isActive;
  12404. }
  12405. bool ThreadPool::waitForJobToFinish (const ThreadPoolJob* const job,
  12406. const int timeOutMs) const
  12407. {
  12408. if (job != 0)
  12409. {
  12410. const uint32 start = Time::getMillisecondCounter();
  12411. while (contains (job))
  12412. {
  12413. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12414. return false;
  12415. jobFinishedSignal.wait (2);
  12416. }
  12417. }
  12418. return true;
  12419. }
  12420. bool ThreadPool::removeJob (ThreadPoolJob* const job,
  12421. const bool interruptIfRunning,
  12422. const int timeOutMs)
  12423. {
  12424. bool dontWait = true;
  12425. if (job != 0)
  12426. {
  12427. const ScopedLock sl (lock);
  12428. if (jobs.contains (job))
  12429. {
  12430. if (job->isActive)
  12431. {
  12432. if (interruptIfRunning)
  12433. job->signalJobShouldExit();
  12434. dontWait = false;
  12435. }
  12436. else
  12437. {
  12438. jobs.removeValue (job);
  12439. }
  12440. }
  12441. }
  12442. return dontWait || waitForJobToFinish (job, timeOutMs);
  12443. }
  12444. bool ThreadPool::removeAllJobs (const bool interruptRunningJobs,
  12445. const int timeOutMs,
  12446. const bool deleteInactiveJobs,
  12447. ThreadPool::JobSelector* selectedJobsToRemove)
  12448. {
  12449. Array <ThreadPoolJob*> jobsToWaitFor;
  12450. {
  12451. const ScopedLock sl (lock);
  12452. for (int i = jobs.size(); --i >= 0;)
  12453. {
  12454. ThreadPoolJob* const job = jobs.getUnchecked(i);
  12455. if (selectedJobsToRemove == 0 || selectedJobsToRemove->isJobSuitable (job))
  12456. {
  12457. if (job->isActive)
  12458. {
  12459. jobsToWaitFor.add (job);
  12460. if (interruptRunningJobs)
  12461. job->signalJobShouldExit();
  12462. }
  12463. else
  12464. {
  12465. jobs.remove (i);
  12466. if (deleteInactiveJobs)
  12467. delete job;
  12468. }
  12469. }
  12470. }
  12471. }
  12472. const uint32 start = Time::getMillisecondCounter();
  12473. for (;;)
  12474. {
  12475. for (int i = jobsToWaitFor.size(); --i >= 0;)
  12476. if (! isJobRunning (jobsToWaitFor.getUnchecked (i)))
  12477. jobsToWaitFor.remove (i);
  12478. if (jobsToWaitFor.size() == 0)
  12479. break;
  12480. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12481. return false;
  12482. jobFinishedSignal.wait (20);
  12483. }
  12484. return true;
  12485. }
  12486. const StringArray ThreadPool::getNamesOfAllJobs (const bool onlyReturnActiveJobs) const
  12487. {
  12488. StringArray s;
  12489. const ScopedLock sl (lock);
  12490. for (int i = 0; i < jobs.size(); ++i)
  12491. {
  12492. const ThreadPoolJob* const job = jobs.getUnchecked(i);
  12493. if (job->isActive || ! onlyReturnActiveJobs)
  12494. s.add (job->getJobName());
  12495. }
  12496. return s;
  12497. }
  12498. bool ThreadPool::setThreadPriorities (const int newPriority)
  12499. {
  12500. bool ok = true;
  12501. if (priority != newPriority)
  12502. {
  12503. priority = newPriority;
  12504. for (int i = threads.size(); --i >= 0;)
  12505. if (! threads.getUnchecked(i)->setPriority (newPriority))
  12506. ok = false;
  12507. }
  12508. return ok;
  12509. }
  12510. bool ThreadPool::runNextJob()
  12511. {
  12512. ThreadPoolJob* job = 0;
  12513. {
  12514. const ScopedLock sl (lock);
  12515. for (int i = 0; i < jobs.size(); ++i)
  12516. {
  12517. job = jobs[i];
  12518. if (job != 0 && ! (job->isActive || job->shouldStop))
  12519. break;
  12520. job = 0;
  12521. }
  12522. if (job != 0)
  12523. job->isActive = true;
  12524. }
  12525. if (job != 0)
  12526. {
  12527. JUCE_TRY
  12528. {
  12529. ThreadPoolJob::JobStatus result = job->runJob();
  12530. lastJobEndTime = Time::getApproximateMillisecondCounter();
  12531. const ScopedLock sl (lock);
  12532. if (jobs.contains (job))
  12533. {
  12534. job->isActive = false;
  12535. if (result != ThreadPoolJob::jobNeedsRunningAgain || job->shouldStop)
  12536. {
  12537. job->pool = 0;
  12538. job->shouldStop = true;
  12539. jobs.removeValue (job);
  12540. if (result == ThreadPoolJob::jobHasFinishedAndShouldBeDeleted)
  12541. delete job;
  12542. jobFinishedSignal.signal();
  12543. }
  12544. else
  12545. {
  12546. // move the job to the end of the queue if it wants another go
  12547. jobs.move (jobs.indexOf (job), -1);
  12548. }
  12549. }
  12550. }
  12551. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  12552. catch (...)
  12553. {
  12554. const ScopedLock sl (lock);
  12555. jobs.removeValue (job);
  12556. }
  12557. #endif
  12558. }
  12559. else
  12560. {
  12561. if (threadStopTimeout > 0
  12562. && Time::getApproximateMillisecondCounter() > lastJobEndTime + threadStopTimeout)
  12563. {
  12564. const ScopedLock sl (lock);
  12565. if (jobs.size() == 0)
  12566. for (int i = threads.size(); --i >= 0;)
  12567. threads.getUnchecked(i)->signalThreadShouldExit();
  12568. }
  12569. else
  12570. {
  12571. return false;
  12572. }
  12573. }
  12574. return true;
  12575. }
  12576. END_JUCE_NAMESPACE
  12577. /*** End of inlined file: juce_ThreadPool.cpp ***/
  12578. /*** Start of inlined file: juce_TimeSliceThread.cpp ***/
  12579. BEGIN_JUCE_NAMESPACE
  12580. TimeSliceThread::TimeSliceThread (const String& threadName)
  12581. : Thread (threadName),
  12582. index (0),
  12583. clientBeingCalled (0),
  12584. clientsChanged (false)
  12585. {
  12586. }
  12587. TimeSliceThread::~TimeSliceThread()
  12588. {
  12589. stopThread (2000);
  12590. }
  12591. void TimeSliceThread::addTimeSliceClient (TimeSliceClient* const client)
  12592. {
  12593. const ScopedLock sl (listLock);
  12594. clients.addIfNotAlreadyThere (client);
  12595. clientsChanged = true;
  12596. notify();
  12597. }
  12598. void TimeSliceThread::removeTimeSliceClient (TimeSliceClient* const client)
  12599. {
  12600. const ScopedLock sl1 (listLock);
  12601. clientsChanged = true;
  12602. // if there's a chance we're in the middle of calling this client, we need to
  12603. // also lock the outer lock..
  12604. if (clientBeingCalled == client)
  12605. {
  12606. const ScopedUnlock ul (listLock); // unlock first to get the order right..
  12607. const ScopedLock sl2 (callbackLock);
  12608. const ScopedLock sl3 (listLock);
  12609. clients.removeValue (client);
  12610. }
  12611. else
  12612. {
  12613. clients.removeValue (client);
  12614. }
  12615. }
  12616. int TimeSliceThread::getNumClients() const
  12617. {
  12618. return clients.size();
  12619. }
  12620. TimeSliceClient* TimeSliceThread::getClient (const int i) const
  12621. {
  12622. const ScopedLock sl (listLock);
  12623. return clients [i];
  12624. }
  12625. void TimeSliceThread::run()
  12626. {
  12627. int numCallsSinceBusy = 0;
  12628. while (! threadShouldExit())
  12629. {
  12630. int timeToWait = 500;
  12631. {
  12632. const ScopedLock sl (callbackLock);
  12633. {
  12634. const ScopedLock sl2 (listLock);
  12635. if (clients.size() > 0)
  12636. {
  12637. index = (index + 1) % clients.size();
  12638. clientBeingCalled = clients [index];
  12639. }
  12640. else
  12641. {
  12642. index = 0;
  12643. clientBeingCalled = 0;
  12644. }
  12645. if (clientsChanged)
  12646. {
  12647. clientsChanged = false;
  12648. numCallsSinceBusy = 0;
  12649. }
  12650. }
  12651. if (clientBeingCalled != 0)
  12652. {
  12653. if (clientBeingCalled->useTimeSlice())
  12654. numCallsSinceBusy = 0;
  12655. else
  12656. ++numCallsSinceBusy;
  12657. if (numCallsSinceBusy >= clients.size())
  12658. timeToWait = 500;
  12659. else if (index == 0)
  12660. timeToWait = 1; // throw in an occasional pause, to stop everything locking up
  12661. else
  12662. timeToWait = 0;
  12663. }
  12664. }
  12665. if (timeToWait > 0)
  12666. wait (timeToWait);
  12667. }
  12668. }
  12669. END_JUCE_NAMESPACE
  12670. /*** End of inlined file: juce_TimeSliceThread.cpp ***/
  12671. #endif
  12672. #if JUCE_BUILD_MISC
  12673. /*** Start of inlined file: juce_ValueTree.cpp ***/
  12674. BEGIN_JUCE_NAMESPACE
  12675. class ValueTreeSetPropertyAction : public UndoableAction
  12676. {
  12677. public:
  12678. ValueTreeSetPropertyAction (const ValueTree::SharedObjectPtr& target_, const var::identifier& name_,
  12679. const var& newValue_, const bool isAddingNewProperty_, const bool isDeletingProperty_)
  12680. : target (target_), name (name_), newValue (newValue_),
  12681. isAddingNewProperty (isAddingNewProperty_),
  12682. isDeletingProperty (isDeletingProperty_)
  12683. {
  12684. if (! isAddingNewProperty)
  12685. oldValue = target_->getProperty (name_);
  12686. }
  12687. ~ValueTreeSetPropertyAction() {}
  12688. bool perform()
  12689. {
  12690. jassert (! (isAddingNewProperty && target->hasProperty (name)));
  12691. if (isDeletingProperty)
  12692. target->removeProperty (name, 0);
  12693. else
  12694. target->setProperty (name, newValue, 0);
  12695. return true;
  12696. }
  12697. bool undo()
  12698. {
  12699. if (isAddingNewProperty)
  12700. target->removeProperty (name, 0);
  12701. else
  12702. target->setProperty (name, oldValue, 0);
  12703. return true;
  12704. }
  12705. int getSizeInUnits()
  12706. {
  12707. return (int) sizeof (*this); //xxx should be more accurate
  12708. }
  12709. private:
  12710. const ValueTree::SharedObjectPtr target;
  12711. const var::identifier name;
  12712. const var newValue;
  12713. var oldValue;
  12714. const bool isAddingNewProperty, isDeletingProperty;
  12715. ValueTreeSetPropertyAction (const ValueTreeSetPropertyAction&);
  12716. ValueTreeSetPropertyAction& operator= (const ValueTreeSetPropertyAction&);
  12717. };
  12718. class ValueTreeChildChangeAction : public UndoableAction
  12719. {
  12720. public:
  12721. ValueTreeChildChangeAction (const ValueTree::SharedObjectPtr& target_, const int childIndex_,
  12722. const ValueTree::SharedObjectPtr& newChild_)
  12723. : target (target_),
  12724. child (newChild_ != 0 ? newChild_ : target_->children [childIndex_]),
  12725. childIndex (childIndex_),
  12726. isDeleting (newChild_ == 0)
  12727. {
  12728. jassert (child != 0);
  12729. }
  12730. ~ValueTreeChildChangeAction() {}
  12731. bool perform()
  12732. {
  12733. if (isDeleting)
  12734. target->removeChild (childIndex, 0);
  12735. else
  12736. target->addChild (child, childIndex, 0);
  12737. return true;
  12738. }
  12739. bool undo()
  12740. {
  12741. if (isDeleting)
  12742. target->addChild (child, childIndex, 0);
  12743. else
  12744. target->removeChild (childIndex, 0);
  12745. return true;
  12746. }
  12747. int getSizeInUnits()
  12748. {
  12749. return (int) sizeof (*this); //xxx should be more accurate
  12750. }
  12751. private:
  12752. const ValueTree::SharedObjectPtr target, child;
  12753. const int childIndex;
  12754. const bool isDeleting;
  12755. ValueTreeChildChangeAction (const ValueTreeChildChangeAction&);
  12756. ValueTreeChildChangeAction& operator= (const ValueTreeChildChangeAction&);
  12757. };
  12758. ValueTree::SharedObject::SharedObject (const String& type_)
  12759. : type (type_), parent (0)
  12760. {
  12761. }
  12762. ValueTree::SharedObject::SharedObject (const SharedObject& other)
  12763. : type (other.type), properties (other.properties), parent (0)
  12764. {
  12765. for (int i = 0; i < other.children.size(); ++i)
  12766. children.add (new SharedObject (*other.children.getUnchecked(i)));
  12767. }
  12768. ValueTree::SharedObject::~SharedObject()
  12769. {
  12770. jassert (parent == 0); // this should never happen unless something isn't obeying the ref-counting!
  12771. for (int i = children.size(); --i >= 0;)
  12772. {
  12773. const SharedObjectPtr c (children.getUnchecked(i));
  12774. c->parent = 0;
  12775. children.remove (i);
  12776. c->sendParentChangeMessage();
  12777. }
  12778. }
  12779. void ValueTree::SharedObject::sendPropertyChangeMessage (ValueTree& tree, const var::identifier& property)
  12780. {
  12781. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  12782. {
  12783. ValueTree* const v = valueTreesWithListeners[i];
  12784. if (v != 0)
  12785. v->listeners.call (&ValueTree::Listener::valueTreePropertyChanged, tree, property);
  12786. }
  12787. }
  12788. void ValueTree::SharedObject::sendPropertyChangeMessage (const var::identifier& property)
  12789. {
  12790. ValueTree tree (this);
  12791. ValueTree::SharedObject* t = this;
  12792. while (t != 0)
  12793. {
  12794. t->sendPropertyChangeMessage (tree, property);
  12795. t = t->parent;
  12796. }
  12797. }
  12798. void ValueTree::SharedObject::sendChildChangeMessage (ValueTree& tree)
  12799. {
  12800. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  12801. {
  12802. ValueTree* const v = valueTreesWithListeners[i];
  12803. if (v != 0)
  12804. v->listeners.call (&ValueTree::Listener::valueTreeChildrenChanged, tree);
  12805. }
  12806. }
  12807. void ValueTree::SharedObject::sendChildChangeMessage()
  12808. {
  12809. ValueTree tree (this);
  12810. ValueTree::SharedObject* t = this;
  12811. while (t != 0)
  12812. {
  12813. t->sendChildChangeMessage (tree);
  12814. t = t->parent;
  12815. }
  12816. }
  12817. void ValueTree::SharedObject::sendParentChangeMessage()
  12818. {
  12819. ValueTree tree (this);
  12820. int i;
  12821. for (i = children.size(); --i >= 0;)
  12822. {
  12823. SharedObject* const t = children[i];
  12824. if (t != 0)
  12825. t->sendParentChangeMessage();
  12826. }
  12827. for (i = valueTreesWithListeners.size(); --i >= 0;)
  12828. {
  12829. ValueTree* const v = valueTreesWithListeners[i];
  12830. if (v != 0)
  12831. v->listeners.call (&ValueTree::Listener::valueTreeParentChanged, tree);
  12832. }
  12833. }
  12834. const var& ValueTree::SharedObject::getProperty (const var::identifier& name) const
  12835. {
  12836. return properties [name];
  12837. }
  12838. void ValueTree::SharedObject::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  12839. {
  12840. if (undoManager == 0)
  12841. {
  12842. if (properties.set (name, newValue))
  12843. sendPropertyChangeMessage (name);
  12844. }
  12845. else
  12846. {
  12847. var* const existingValue = properties.getItem (name);
  12848. if (existingValue != 0)
  12849. {
  12850. if (*existingValue != newValue)
  12851. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, false, false));
  12852. }
  12853. else
  12854. {
  12855. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, true, false));
  12856. }
  12857. }
  12858. }
  12859. bool ValueTree::SharedObject::hasProperty (const var::identifier& name) const
  12860. {
  12861. return properties.contains (name);
  12862. }
  12863. void ValueTree::SharedObject::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  12864. {
  12865. if (undoManager == 0)
  12866. {
  12867. if (properties.remove (name))
  12868. sendPropertyChangeMessage (name);
  12869. }
  12870. else
  12871. {
  12872. if (properties.contains (name))
  12873. undoManager->perform (new ValueTreeSetPropertyAction (this, name, var::null, false, true));
  12874. }
  12875. }
  12876. void ValueTree::SharedObject::removeAllProperties (UndoManager* const undoManager)
  12877. {
  12878. if (undoManager == 0)
  12879. {
  12880. while (properties.size() > 0)
  12881. {
  12882. const var::identifier name (properties.getName (properties.size() - 1));
  12883. properties.remove (name);
  12884. sendPropertyChangeMessage (name);
  12885. }
  12886. }
  12887. else
  12888. {
  12889. for (int i = properties.size(); --i >= 0;)
  12890. undoManager->perform (new ValueTreeSetPropertyAction (this, properties.getName(i), var::null, false, true));
  12891. }
  12892. }
  12893. ValueTree ValueTree::SharedObject::getChildWithName (const String& typeToMatch) const
  12894. {
  12895. for (int i = 0; i < children.size(); ++i)
  12896. if (children.getUnchecked(i)->type == typeToMatch)
  12897. return (SharedObject*) children.getUnchecked(i);
  12898. return (SharedObject*) 0;
  12899. }
  12900. ValueTree ValueTree::SharedObject::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  12901. {
  12902. for (int i = 0; i < children.size(); ++i)
  12903. if (children.getUnchecked(i)->getProperty (propertyName) == propertyValue)
  12904. return (SharedObject*) children.getUnchecked(i);
  12905. return (SharedObject*) 0;
  12906. }
  12907. bool ValueTree::SharedObject::isAChildOf (const SharedObject* const possibleParent) const
  12908. {
  12909. const SharedObject* p = parent;
  12910. while (p != 0)
  12911. {
  12912. if (p == possibleParent)
  12913. return true;
  12914. p = p->parent;
  12915. }
  12916. return false;
  12917. }
  12918. void ValueTree::SharedObject::addChild (SharedObject* child, int index, UndoManager* const undoManager)
  12919. {
  12920. if (child != 0 && child->parent != this)
  12921. {
  12922. if (child != this && ! isAChildOf (child))
  12923. {
  12924. // You should always make sure that a child is removed from its previous parent before
  12925. // adding it somewhere else - otherwise, it's ambiguous as to whether a different
  12926. // undomanager should be used when removing it from its current parent..
  12927. jassert (child->parent == 0);
  12928. if (child->parent != 0)
  12929. {
  12930. jassert (child->parent->children.indexOf (child) >= 0);
  12931. child->parent->removeChild (child->parent->children.indexOf (child), undoManager);
  12932. }
  12933. if (undoManager == 0)
  12934. {
  12935. children.insert (index, child);
  12936. child->parent = this;
  12937. sendChildChangeMessage();
  12938. child->sendParentChangeMessage();
  12939. }
  12940. else
  12941. {
  12942. undoManager->perform (new ValueTreeChildChangeAction (this, index, child));
  12943. }
  12944. }
  12945. else
  12946. {
  12947. // You're attempting to create a recursive loop! A node
  12948. // can't be a child of one of its own children!
  12949. jassertfalse
  12950. }
  12951. }
  12952. }
  12953. void ValueTree::SharedObject::removeChild (const int childIndex, UndoManager* const undoManager)
  12954. {
  12955. const SharedObjectPtr child (children [childIndex]);
  12956. if (child != 0)
  12957. {
  12958. if (undoManager == 0)
  12959. {
  12960. children.remove (childIndex);
  12961. child->parent = 0;
  12962. sendChildChangeMessage();
  12963. child->sendParentChangeMessage();
  12964. }
  12965. else
  12966. {
  12967. undoManager->perform (new ValueTreeChildChangeAction (this, childIndex, 0));
  12968. }
  12969. }
  12970. }
  12971. void ValueTree::SharedObject::removeAllChildren (UndoManager* const undoManager)
  12972. {
  12973. while (children.size() > 0)
  12974. removeChild (children.size() - 1, undoManager);
  12975. }
  12976. ValueTree::ValueTree (const String& type_)
  12977. : object (new ValueTree::SharedObject (type_))
  12978. {
  12979. jassert (type_.isNotEmpty()); // All objects should be given a sensible type name!
  12980. }
  12981. ValueTree::ValueTree (SharedObject* const object_)
  12982. : object (object_)
  12983. {
  12984. }
  12985. ValueTree::ValueTree (const ValueTree& other)
  12986. : object (other.object)
  12987. {
  12988. }
  12989. ValueTree& ValueTree::operator= (const ValueTree& other)
  12990. {
  12991. if (listeners.size() > 0)
  12992. {
  12993. if (object != 0)
  12994. object->valueTreesWithListeners.removeValue (this);
  12995. if (other.object != 0)
  12996. other.object->valueTreesWithListeners.add (this);
  12997. }
  12998. object = other.object;
  12999. return *this;
  13000. }
  13001. ValueTree::~ValueTree()
  13002. {
  13003. if (listeners.size() > 0 && object != 0)
  13004. object->valueTreesWithListeners.removeValue (this);
  13005. }
  13006. bool ValueTree::operator== (const ValueTree& other) const
  13007. {
  13008. return object == other.object;
  13009. }
  13010. bool ValueTree::operator!= (const ValueTree& other) const
  13011. {
  13012. return object != other.object;
  13013. }
  13014. ValueTree ValueTree::createCopy() const
  13015. {
  13016. return ValueTree (object != 0 ? new SharedObject (*object) : 0);
  13017. }
  13018. bool ValueTree::hasType (const String& typeName) const
  13019. {
  13020. return object != 0 && object->type == typeName;
  13021. }
  13022. const String ValueTree::getType() const
  13023. {
  13024. return object != 0 ? object->type : String::empty;
  13025. }
  13026. ValueTree ValueTree::getParent() const
  13027. {
  13028. return object != 0 ? ValueTree (object->parent) : ValueTree ((SharedObject*) 0);
  13029. }
  13030. const var& ValueTree::operator[] (const var::identifier& name) const
  13031. {
  13032. return object == 0 ? var::null : object->getProperty (name);
  13033. }
  13034. const var& ValueTree::getProperty (const var::identifier& name) const
  13035. {
  13036. return object == 0 ? var::null : object->getProperty (name);
  13037. }
  13038. void ValueTree::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  13039. {
  13040. jassert (name.name.isNotEmpty());
  13041. if (object != 0 && name.name.isNotEmpty())
  13042. object->setProperty (name, newValue, undoManager);
  13043. }
  13044. bool ValueTree::hasProperty (const var::identifier& name) const
  13045. {
  13046. return object != 0 && object->hasProperty (name);
  13047. }
  13048. void ValueTree::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  13049. {
  13050. if (object != 0)
  13051. object->removeProperty (name, undoManager);
  13052. }
  13053. void ValueTree::removeAllProperties (UndoManager* const undoManager)
  13054. {
  13055. if (object != 0)
  13056. object->removeAllProperties (undoManager);
  13057. }
  13058. int ValueTree::getNumProperties() const
  13059. {
  13060. return object == 0 ? 0 : object->properties.size();
  13061. }
  13062. const var::identifier ValueTree::getPropertyName (int index) const
  13063. {
  13064. return (object == 0) ? var::identifier()
  13065. : object->properties.getName (index);
  13066. }
  13067. class ValueTreePropertyValueSource : public Value::ValueSource,
  13068. public ValueTree::Listener
  13069. {
  13070. public:
  13071. ValueTreePropertyValueSource (const ValueTree& tree_,
  13072. const var::identifier& property_,
  13073. UndoManager* const undoManager_)
  13074. : tree (tree_),
  13075. property (property_),
  13076. undoManager (undoManager_)
  13077. {
  13078. tree.addListener (this);
  13079. }
  13080. ~ValueTreePropertyValueSource()
  13081. {
  13082. tree.removeListener (this);
  13083. }
  13084. const var getValue() const
  13085. {
  13086. return tree [property];
  13087. }
  13088. void setValue (const var& newValue)
  13089. {
  13090. tree.setProperty (property, newValue, undoManager);
  13091. }
  13092. void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged, const var::identifier& changedProperty)
  13093. {
  13094. if (tree == treeWhosePropertyHasChanged && property == changedProperty)
  13095. sendChangeMessage (false);
  13096. }
  13097. void valueTreeChildrenChanged (ValueTree&) {}
  13098. void valueTreeParentChanged (ValueTree&) {}
  13099. private:
  13100. ValueTree tree;
  13101. const var::identifier property;
  13102. UndoManager* const undoManager;
  13103. ValueTreePropertyValueSource& operator= (const ValueTreePropertyValueSource&);
  13104. };
  13105. Value ValueTree::getPropertyAsValue (const var::identifier& name, UndoManager* const undoManager) const
  13106. {
  13107. return Value (new ValueTreePropertyValueSource (*this, name, undoManager));
  13108. }
  13109. int ValueTree::getNumChildren() const
  13110. {
  13111. return object == 0 ? 0 : object->children.size();
  13112. }
  13113. ValueTree ValueTree::getChild (int index) const
  13114. {
  13115. return object != 0 ? (SharedObject*) object->children [index] : ValueTree ((SharedObject*) 0);
  13116. }
  13117. ValueTree ValueTree::getChildWithName (const String& type) const
  13118. {
  13119. return object != 0 ? object->getChildWithName (type) : ValueTree ((SharedObject*) 0);
  13120. }
  13121. ValueTree ValueTree::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  13122. {
  13123. return object != 0 ? object->getChildWithProperty (propertyName, propertyValue) : ValueTree ((SharedObject*) 0);
  13124. }
  13125. bool ValueTree::isAChildOf (const ValueTree& possibleParent) const
  13126. {
  13127. return object != 0 && object->isAChildOf (possibleParent.object);
  13128. }
  13129. void ValueTree::addChild (ValueTree child, int index, UndoManager* const undoManager)
  13130. {
  13131. if (object != 0)
  13132. object->addChild (child.object, index, undoManager);
  13133. }
  13134. void ValueTree::removeChild (const int childIndex, UndoManager* const undoManager)
  13135. {
  13136. if (object != 0)
  13137. object->removeChild (childIndex, undoManager);
  13138. }
  13139. void ValueTree::removeChild (ValueTree& child, UndoManager* const undoManager)
  13140. {
  13141. if (object != 0)
  13142. object->removeChild (object->children.indexOf (child.object), undoManager);
  13143. }
  13144. void ValueTree::removeAllChildren (UndoManager* const undoManager)
  13145. {
  13146. if (object != 0)
  13147. object->removeAllChildren (undoManager);
  13148. }
  13149. void ValueTree::addListener (Listener* listener)
  13150. {
  13151. if (listener != 0)
  13152. {
  13153. if (listeners.size() == 0 && object != 0)
  13154. object->valueTreesWithListeners.add (this);
  13155. listeners.add (listener);
  13156. }
  13157. }
  13158. void ValueTree::removeListener (Listener* listener)
  13159. {
  13160. listeners.remove (listener);
  13161. if (listeners.size() == 0 && object != 0)
  13162. object->valueTreesWithListeners.removeValue (this);
  13163. }
  13164. XmlElement* ValueTree::SharedObject::createXml() const
  13165. {
  13166. XmlElement* xml = new XmlElement (type);
  13167. int i;
  13168. for (i = 0; i < properties.size(); ++i)
  13169. {
  13170. var::identifier name (properties.getName(i));
  13171. const var& v = properties [name];
  13172. jassert (! v.isObject()); // DynamicObjects can't be stored as XML!
  13173. xml->setAttribute (name.name, v.toString());
  13174. }
  13175. for (i = 0; i < children.size(); ++i)
  13176. xml->addChildElement (children.getUnchecked(i)->createXml());
  13177. return xml;
  13178. }
  13179. XmlElement* ValueTree::createXml() const
  13180. {
  13181. return object != 0 ? object->createXml() : 0;
  13182. }
  13183. ValueTree ValueTree::fromXml (const XmlElement& xml)
  13184. {
  13185. ValueTree v (xml.getTagName());
  13186. const int numAtts = xml.getNumAttributes(); // xxx inefficient - should write an att iterator..
  13187. for (int i = 0; i < numAtts; ++i)
  13188. v.setProperty (xml.getAttributeName (i), var (xml.getAttributeValue (i)), 0);
  13189. forEachXmlChildElement (xml, e)
  13190. {
  13191. v.addChild (fromXml (*e), -1, 0);
  13192. }
  13193. return v;
  13194. }
  13195. void ValueTree::writeToStream (OutputStream& output)
  13196. {
  13197. output.writeString (getType());
  13198. const int numProps = getNumProperties();
  13199. output.writeCompressedInt (numProps);
  13200. int i;
  13201. for (i = 0; i < numProps; ++i)
  13202. {
  13203. const var::identifier name (getPropertyName(i));
  13204. output.writeString (name.name);
  13205. getProperty(name).writeToStream (output);
  13206. }
  13207. const int numChildren = getNumChildren();
  13208. output.writeCompressedInt (numChildren);
  13209. for (i = 0; i < numChildren; ++i)
  13210. getChild (i).writeToStream (output);
  13211. }
  13212. ValueTree ValueTree::readFromStream (InputStream& input)
  13213. {
  13214. String type (input.readString());
  13215. if (type.isEmpty())
  13216. return ValueTree ((SharedObject*) 0);
  13217. ValueTree v (type);
  13218. const int numProps = input.readCompressedInt();
  13219. if (numProps < 0)
  13220. {
  13221. jassertfalse // trying to read corrupted data!
  13222. return v;
  13223. }
  13224. int i;
  13225. for (i = 0; i < numProps; ++i)
  13226. {
  13227. const String name (input.readString());
  13228. jassert (name.isNotEmpty());
  13229. const var value (var::readFromStream (input));
  13230. v.setProperty (name, value, 0);
  13231. }
  13232. const int numChildren = input.readCompressedInt();
  13233. for (i = 0; i < numChildren; ++i)
  13234. v.addChild (readFromStream (input), -1, 0);
  13235. return v;
  13236. }
  13237. END_JUCE_NAMESPACE
  13238. /*** End of inlined file: juce_ValueTree.cpp ***/
  13239. /*** Start of inlined file: juce_Value.cpp ***/
  13240. BEGIN_JUCE_NAMESPACE
  13241. Value::ValueSource::ValueSource()
  13242. {
  13243. }
  13244. Value::ValueSource::~ValueSource()
  13245. {
  13246. }
  13247. void Value::ValueSource::sendChangeMessage (const bool synchronous)
  13248. {
  13249. if (synchronous)
  13250. {
  13251. for (int i = valuesWithListeners.size(); --i >= 0;)
  13252. {
  13253. Value* const v = valuesWithListeners[i];
  13254. if (v != 0)
  13255. v->callListeners();
  13256. }
  13257. }
  13258. else
  13259. {
  13260. triggerAsyncUpdate();
  13261. }
  13262. }
  13263. void Value::ValueSource::handleAsyncUpdate()
  13264. {
  13265. sendChangeMessage (true);
  13266. }
  13267. class SimpleValueSource : public Value::ValueSource
  13268. {
  13269. public:
  13270. SimpleValueSource()
  13271. {
  13272. }
  13273. SimpleValueSource (const var& initialValue)
  13274. : value (initialValue)
  13275. {
  13276. }
  13277. ~SimpleValueSource()
  13278. {
  13279. }
  13280. const var getValue() const
  13281. {
  13282. return value;
  13283. }
  13284. void setValue (const var& newValue)
  13285. {
  13286. if (newValue != value)
  13287. {
  13288. value = newValue;
  13289. sendChangeMessage (false);
  13290. }
  13291. }
  13292. private:
  13293. var value;
  13294. SimpleValueSource (const SimpleValueSource&);
  13295. SimpleValueSource& operator= (const SimpleValueSource&);
  13296. };
  13297. Value::Value()
  13298. : value (new SimpleValueSource())
  13299. {
  13300. }
  13301. Value::Value (ValueSource* const value_)
  13302. : value (value_)
  13303. {
  13304. jassert (value_ != 0);
  13305. }
  13306. Value::Value (const var& initialValue)
  13307. : value (new SimpleValueSource (initialValue))
  13308. {
  13309. }
  13310. Value::Value (const Value& other)
  13311. : value (other.value)
  13312. {
  13313. }
  13314. Value& Value::operator= (const Value& other)
  13315. {
  13316. value = other.value;
  13317. return *this;
  13318. }
  13319. Value::~Value()
  13320. {
  13321. if (listeners.size() > 0)
  13322. value->valuesWithListeners.removeValue (this);
  13323. }
  13324. const var Value::getValue() const
  13325. {
  13326. return value->getValue();
  13327. }
  13328. Value::operator const var() const
  13329. {
  13330. return getValue();
  13331. }
  13332. void Value::setValue (const var& newValue)
  13333. {
  13334. value->setValue (newValue);
  13335. }
  13336. const String Value::toString() const
  13337. {
  13338. return value->getValue().toString();
  13339. }
  13340. Value& Value::operator= (const var& newValue)
  13341. {
  13342. value->setValue (newValue);
  13343. return *this;
  13344. }
  13345. void Value::referTo (const Value& valueToReferTo)
  13346. {
  13347. if (valueToReferTo.value != value)
  13348. {
  13349. if (listeners.size() > 0)
  13350. {
  13351. value->valuesWithListeners.removeValue (this);
  13352. valueToReferTo.value->valuesWithListeners.add (this);
  13353. }
  13354. value = valueToReferTo.value;
  13355. callListeners();
  13356. }
  13357. }
  13358. bool Value::refersToSameSourceAs (const Value& other) const
  13359. {
  13360. return value == other.value;
  13361. }
  13362. bool Value::operator== (const Value& other) const
  13363. {
  13364. return value == other.value || value->getValue() == other.getValue();
  13365. }
  13366. bool Value::operator!= (const Value& other) const
  13367. {
  13368. return value != other.value && value->getValue() != other.getValue();
  13369. }
  13370. void Value::addListener (Listener* const listener)
  13371. {
  13372. if (listener != 0)
  13373. {
  13374. if (listeners.size() == 0)
  13375. value->valuesWithListeners.add (this);
  13376. listeners.add (listener);
  13377. }
  13378. }
  13379. void Value::removeListener (Listener* const listener)
  13380. {
  13381. listeners.remove (listener);
  13382. if (listeners.size() == 0)
  13383. value->valuesWithListeners.removeValue (this);
  13384. }
  13385. void Value::callListeners()
  13386. {
  13387. Value v (*this); // (create a copy in case this gets deleted by a callback)
  13388. listeners.call (&Listener::valueChanged, v);
  13389. }
  13390. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const Value& value)
  13391. {
  13392. return stream << value.toString();
  13393. }
  13394. END_JUCE_NAMESPACE
  13395. /*** End of inlined file: juce_Value.cpp ***/
  13396. /*** Start of inlined file: juce_Application.cpp ***/
  13397. #if JUCE_MSVC
  13398. #pragma warning (push)
  13399. #pragma warning (disable: 4245 4514 4100)
  13400. #include <crtdbg.h>
  13401. #pragma warning (pop)
  13402. #endif
  13403. BEGIN_JUCE_NAMESPACE
  13404. void juce_setCurrentThreadName (const String& name);
  13405. static JUCEApplication* appInstance = 0;
  13406. JUCEApplication::JUCEApplication()
  13407. : appReturnValue (0),
  13408. stillInitialising (true)
  13409. {
  13410. }
  13411. JUCEApplication::~JUCEApplication()
  13412. {
  13413. if (appLock != 0)
  13414. {
  13415. appLock->exit();
  13416. appLock = 0;
  13417. }
  13418. }
  13419. JUCEApplication* JUCEApplication::getInstance() throw()
  13420. {
  13421. return appInstance;
  13422. }
  13423. bool JUCEApplication::isInitialising() const throw()
  13424. {
  13425. return stillInitialising;
  13426. }
  13427. const String JUCEApplication::getApplicationVersion()
  13428. {
  13429. return String::empty;
  13430. }
  13431. bool JUCEApplication::moreThanOneInstanceAllowed()
  13432. {
  13433. return true;
  13434. }
  13435. void JUCEApplication::anotherInstanceStarted (const String&)
  13436. {
  13437. }
  13438. void JUCEApplication::systemRequestedQuit()
  13439. {
  13440. quit();
  13441. }
  13442. void JUCEApplication::quit()
  13443. {
  13444. MessageManager::getInstance()->stopDispatchLoop();
  13445. }
  13446. void JUCEApplication::setApplicationReturnValue (const int newReturnValue) throw()
  13447. {
  13448. appReturnValue = newReturnValue;
  13449. }
  13450. void JUCEApplication::unhandledException (const std::exception*,
  13451. const String&,
  13452. const int)
  13453. {
  13454. jassertfalse
  13455. }
  13456. void JUCEApplication::sendUnhandledException (const std::exception* const e,
  13457. const char* const sourceFile,
  13458. const int lineNumber)
  13459. {
  13460. if (appInstance != 0)
  13461. appInstance->unhandledException (e, sourceFile, lineNumber);
  13462. }
  13463. ApplicationCommandTarget* JUCEApplication::getNextCommandTarget()
  13464. {
  13465. return 0;
  13466. }
  13467. void JUCEApplication::getAllCommands (Array <CommandID>& commands)
  13468. {
  13469. commands.add (StandardApplicationCommandIDs::quit);
  13470. }
  13471. void JUCEApplication::getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result)
  13472. {
  13473. if (commandID == StandardApplicationCommandIDs::quit)
  13474. {
  13475. result.setInfo (TRANS("Quit"),
  13476. TRANS("Quits the application"),
  13477. "Application",
  13478. 0);
  13479. result.defaultKeypresses.add (KeyPress ('q', ModifierKeys::commandModifier, 0));
  13480. }
  13481. }
  13482. bool JUCEApplication::perform (const InvocationInfo& info)
  13483. {
  13484. if (info.commandID == StandardApplicationCommandIDs::quit)
  13485. {
  13486. systemRequestedQuit();
  13487. return true;
  13488. }
  13489. return false;
  13490. }
  13491. int JUCEApplication::main (String& commandLine, JUCEApplication* const app)
  13492. {
  13493. if (! app->initialiseApp (commandLine))
  13494. return 0;
  13495. // now loop until a quit message is received..
  13496. JUCE_TRY
  13497. {
  13498. MessageManager::getInstance()->runDispatchLoop();
  13499. }
  13500. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13501. catch (const std::exception& e)
  13502. {
  13503. app->unhandledException (&e, __FILE__, __LINE__);
  13504. }
  13505. catch (...)
  13506. {
  13507. app->unhandledException (0, __FILE__, __LINE__);
  13508. }
  13509. #endif
  13510. return shutdownAppAndClearUp();
  13511. }
  13512. bool JUCEApplication::initialiseApp (String& commandLine)
  13513. {
  13514. jassert (appInstance == 0);
  13515. appInstance = this;
  13516. commandLineParameters = commandLine.trim();
  13517. commandLine = String::empty;
  13518. initialiseJuce_GUI();
  13519. #if ! JUCE_IPHONE
  13520. jassert (appLock == 0); // initialiseApp must only be called once!
  13521. if (! moreThanOneInstanceAllowed())
  13522. {
  13523. appLock = new InterProcessLock ("juceAppLock_" + getApplicationName());
  13524. if (! appLock->enter(0))
  13525. {
  13526. MessageManager::broadcastMessage (getApplicationName() + "/" + commandLineParameters);
  13527. delete appInstance;
  13528. appInstance = 0;
  13529. DBG ("Another instance is running - quitting...");
  13530. return false;
  13531. }
  13532. }
  13533. #endif
  13534. // let the app do its setting-up..
  13535. initialise (commandLineParameters);
  13536. // register for broadcast new app messages
  13537. MessageManager::getInstance()->registerBroadcastListener (this);
  13538. stillInitialising = false;
  13539. return true;
  13540. }
  13541. int JUCEApplication::shutdownAppAndClearUp()
  13542. {
  13543. jassert (appInstance != 0);
  13544. ScopedPointer<JUCEApplication> app (appInstance);
  13545. int returnValue = 0;
  13546. MessageManager::getInstance()->deregisterBroadcastListener ((JUCEApplication*) app);
  13547. static bool reentrancyCheck = false;
  13548. if (! reentrancyCheck)
  13549. {
  13550. reentrancyCheck = true;
  13551. JUCE_TRY
  13552. {
  13553. // give the app a chance to clean up..
  13554. app->shutdown();
  13555. }
  13556. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13557. catch (const std::exception& e)
  13558. {
  13559. app->unhandledException (&e, __FILE__, __LINE__);
  13560. }
  13561. catch (...)
  13562. {
  13563. app->unhandledException (0, __FILE__, __LINE__);
  13564. }
  13565. #endif
  13566. JUCE_TRY
  13567. {
  13568. shutdownJuce_GUI();
  13569. returnValue = app->getApplicationReturnValue();
  13570. appInstance = 0;
  13571. app = 0;
  13572. }
  13573. JUCE_CATCH_ALL_ASSERT
  13574. reentrancyCheck = false;
  13575. }
  13576. return returnValue;
  13577. }
  13578. #if JUCE_IPHONE
  13579. extern int juce_IPhoneMain (int argc, const char* argv[], JUCEApplication* app);
  13580. #endif
  13581. #if ! JUCE_WINDOWS
  13582. extern const char* juce_Argv0;
  13583. #endif
  13584. int JUCEApplication::main (int argc, const char* argv[], JUCEApplication* const newApp)
  13585. {
  13586. #if ! JUCE_WINDOWS
  13587. juce_Argv0 = argv[0];
  13588. #endif
  13589. #if JUCE_IPHONE
  13590. const ScopedAutoReleasePool pool;
  13591. return juce_IPhoneMain (argc, argv, newApp);
  13592. #else
  13593. #if JUCE_MAC
  13594. const ScopedAutoReleasePool pool;
  13595. #endif
  13596. String cmd;
  13597. for (int i = 1; i < argc; ++i)
  13598. cmd << argv[i] << ' ';
  13599. return JUCEApplication::main (cmd, newApp);
  13600. #endif
  13601. }
  13602. void JUCEApplication::actionListenerCallback (const String& message)
  13603. {
  13604. if (message.startsWith (getApplicationName() + "/"))
  13605. anotherInstanceStarted (message.substring (getApplicationName().length() + 1));
  13606. }
  13607. static bool juceInitialisedGUI = false;
  13608. void JUCE_PUBLIC_FUNCTION initialiseJuce_GUI()
  13609. {
  13610. if (! juceInitialisedGUI)
  13611. {
  13612. #if JUCE_MAC || JUCE_IPHONE
  13613. const ScopedAutoReleasePool pool;
  13614. #endif
  13615. juceInitialisedGUI = true;
  13616. initialiseJuce_NonGUI();
  13617. MessageManager::getInstance();
  13618. LookAndFeel::setDefaultLookAndFeel (0);
  13619. juce_setCurrentThreadName ("Juce Message Thread");
  13620. #if JUCE_WINDOWS && JUCE_DEBUG
  13621. // This section is just for catching people who mess up their project settings and
  13622. // turn RTTI off..
  13623. try
  13624. {
  13625. TextButton tb (String::empty);
  13626. Component* c = &tb;
  13627. // Got an exception here? Then TURN ON RTTI in your compiler settings!!
  13628. c = dynamic_cast <Button*> (c);
  13629. }
  13630. catch (...)
  13631. {
  13632. // Ended up here? If so, TURN ON RTTI in your compiler settings!! And if you
  13633. // got as far as this catch statement, then why haven't you got exception catching
  13634. // turned on in the debugger???
  13635. jassertfalse
  13636. }
  13637. #endif
  13638. }
  13639. }
  13640. void JUCE_PUBLIC_FUNCTION shutdownJuce_GUI()
  13641. {
  13642. if (juceInitialisedGUI)
  13643. {
  13644. #if JUCE_MAC
  13645. const ScopedAutoReleasePool pool;
  13646. #endif
  13647. {
  13648. DeletedAtShutdown::deleteAll();
  13649. LookAndFeel::clearDefaultLookAndFeel();
  13650. }
  13651. delete MessageManager::getInstance();
  13652. shutdownJuce_NonGUI();
  13653. juceInitialisedGUI = false;
  13654. }
  13655. }
  13656. END_JUCE_NAMESPACE
  13657. /*** End of inlined file: juce_Application.cpp ***/
  13658. /*** Start of inlined file: juce_ApplicationCommandInfo.cpp ***/
  13659. BEGIN_JUCE_NAMESPACE
  13660. ApplicationCommandInfo::ApplicationCommandInfo (const CommandID commandID_) throw()
  13661. : commandID (commandID_),
  13662. flags (0)
  13663. {
  13664. }
  13665. void ApplicationCommandInfo::setInfo (const String& shortName_,
  13666. const String& description_,
  13667. const String& categoryName_,
  13668. const int flags_) throw()
  13669. {
  13670. shortName = shortName_;
  13671. description = description_;
  13672. categoryName = categoryName_;
  13673. flags = flags_;
  13674. }
  13675. void ApplicationCommandInfo::setActive (const bool b) throw()
  13676. {
  13677. if (b)
  13678. flags &= ~isDisabled;
  13679. else
  13680. flags |= isDisabled;
  13681. }
  13682. void ApplicationCommandInfo::setTicked (const bool b) throw()
  13683. {
  13684. if (b)
  13685. flags |= isTicked;
  13686. else
  13687. flags &= ~isTicked;
  13688. }
  13689. void ApplicationCommandInfo::addDefaultKeypress (const int keyCode, const ModifierKeys& modifiers) throw()
  13690. {
  13691. defaultKeypresses.add (KeyPress (keyCode, modifiers, 0));
  13692. }
  13693. END_JUCE_NAMESPACE
  13694. /*** End of inlined file: juce_ApplicationCommandInfo.cpp ***/
  13695. /*** Start of inlined file: juce_ApplicationCommandManager.cpp ***/
  13696. BEGIN_JUCE_NAMESPACE
  13697. ApplicationCommandManager::ApplicationCommandManager()
  13698. : firstTarget (0)
  13699. {
  13700. keyMappings = new KeyPressMappingSet (this);
  13701. Desktop::getInstance().addFocusChangeListener (this);
  13702. }
  13703. ApplicationCommandManager::~ApplicationCommandManager()
  13704. {
  13705. Desktop::getInstance().removeFocusChangeListener (this);
  13706. keyMappings = 0;
  13707. }
  13708. void ApplicationCommandManager::clearCommands()
  13709. {
  13710. commands.clear();
  13711. keyMappings->clearAllKeyPresses();
  13712. triggerAsyncUpdate();
  13713. }
  13714. void ApplicationCommandManager::registerCommand (const ApplicationCommandInfo& newCommand)
  13715. {
  13716. // zero isn't a valid command ID!
  13717. jassert (newCommand.commandID != 0);
  13718. // the name isn't optional!
  13719. jassert (newCommand.shortName.isNotEmpty());
  13720. if (getCommandForID (newCommand.commandID) == 0)
  13721. {
  13722. ApplicationCommandInfo* const newInfo = new ApplicationCommandInfo (newCommand);
  13723. newInfo->flags &= ~ApplicationCommandInfo::isTicked;
  13724. commands.add (newInfo);
  13725. keyMappings->resetToDefaultMapping (newCommand.commandID);
  13726. triggerAsyncUpdate();
  13727. }
  13728. else
  13729. {
  13730. // trying to re-register the same command with different parameters?
  13731. jassert (newCommand.shortName == getCommandForID (newCommand.commandID)->shortName
  13732. && (newCommand.description == getCommandForID (newCommand.commandID)->description || newCommand.description.isEmpty())
  13733. && newCommand.categoryName == getCommandForID (newCommand.commandID)->categoryName
  13734. && newCommand.defaultKeypresses == getCommandForID (newCommand.commandID)->defaultKeypresses
  13735. && (newCommand.flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor))
  13736. == (getCommandForID (newCommand.commandID)->flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor)));
  13737. }
  13738. }
  13739. void ApplicationCommandManager::registerAllCommandsForTarget (ApplicationCommandTarget* target)
  13740. {
  13741. if (target != 0)
  13742. {
  13743. Array <CommandID> commandIDs;
  13744. target->getAllCommands (commandIDs);
  13745. for (int i = 0; i < commandIDs.size(); ++i)
  13746. {
  13747. ApplicationCommandInfo info (commandIDs.getUnchecked(i));
  13748. target->getCommandInfo (info.commandID, info);
  13749. registerCommand (info);
  13750. }
  13751. }
  13752. }
  13753. void ApplicationCommandManager::removeCommand (const CommandID commandID)
  13754. {
  13755. for (int i = commands.size(); --i >= 0;)
  13756. {
  13757. if (commands.getUnchecked (i)->commandID == commandID)
  13758. {
  13759. commands.remove (i);
  13760. triggerAsyncUpdate();
  13761. const Array <KeyPress> keys (keyMappings->getKeyPressesAssignedToCommand (commandID));
  13762. for (int j = keys.size(); --j >= 0;)
  13763. keyMappings->removeKeyPress (keys.getReference (j));
  13764. }
  13765. }
  13766. }
  13767. void ApplicationCommandManager::commandStatusChanged()
  13768. {
  13769. triggerAsyncUpdate();
  13770. }
  13771. const ApplicationCommandInfo* ApplicationCommandManager::getCommandForID (const CommandID commandID) const throw()
  13772. {
  13773. for (int i = commands.size(); --i >= 0;)
  13774. if (commands.getUnchecked(i)->commandID == commandID)
  13775. return commands.getUnchecked(i);
  13776. return 0;
  13777. }
  13778. const String ApplicationCommandManager::getNameOfCommand (const CommandID commandID) const throw()
  13779. {
  13780. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  13781. return (ci != 0) ? ci->shortName : String::empty;
  13782. }
  13783. const String ApplicationCommandManager::getDescriptionOfCommand (const CommandID commandID) const throw()
  13784. {
  13785. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  13786. return (ci != 0) ? (ci->description.isNotEmpty() ? ci->description : ci->shortName)
  13787. : String::empty;
  13788. }
  13789. const StringArray ApplicationCommandManager::getCommandCategories() const throw()
  13790. {
  13791. StringArray s;
  13792. for (int i = 0; i < commands.size(); ++i)
  13793. s.addIfNotAlreadyThere (commands.getUnchecked(i)->categoryName, false);
  13794. return s;
  13795. }
  13796. const Array <CommandID> ApplicationCommandManager::getCommandsInCategory (const String& categoryName) const throw()
  13797. {
  13798. Array <CommandID> results;
  13799. for (int i = 0; i < commands.size(); ++i)
  13800. if (commands.getUnchecked(i)->categoryName == categoryName)
  13801. results.add (commands.getUnchecked(i)->commandID);
  13802. return results;
  13803. }
  13804. bool ApplicationCommandManager::invokeDirectly (const CommandID commandID, const bool asynchronously)
  13805. {
  13806. ApplicationCommandTarget::InvocationInfo info (commandID);
  13807. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  13808. return invoke (info, asynchronously);
  13809. }
  13810. bool ApplicationCommandManager::invoke (const ApplicationCommandTarget::InvocationInfo& info_, const bool asynchronously)
  13811. {
  13812. // This call isn't thread-safe for use from a non-UI thread without locking the message
  13813. // manager first..
  13814. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  13815. ApplicationCommandTarget* const target = getFirstCommandTarget (info_.commandID);
  13816. if (target == 0)
  13817. return false;
  13818. ApplicationCommandInfo commandInfo (0);
  13819. target->getCommandInfo (info_.commandID, commandInfo);
  13820. ApplicationCommandTarget::InvocationInfo info (info_);
  13821. info.commandFlags = commandInfo.flags;
  13822. sendListenerInvokeCallback (info);
  13823. const bool ok = target->invoke (info, asynchronously);
  13824. commandStatusChanged();
  13825. return ok;
  13826. }
  13827. ApplicationCommandTarget* ApplicationCommandManager::getFirstCommandTarget (const CommandID)
  13828. {
  13829. return firstTarget != 0 ? firstTarget
  13830. : findDefaultComponentTarget();
  13831. }
  13832. void ApplicationCommandManager::setFirstCommandTarget (ApplicationCommandTarget* const newTarget) throw()
  13833. {
  13834. firstTarget = newTarget;
  13835. }
  13836. ApplicationCommandTarget* ApplicationCommandManager::getTargetForCommand (const CommandID commandID,
  13837. ApplicationCommandInfo& upToDateInfo)
  13838. {
  13839. ApplicationCommandTarget* target = getFirstCommandTarget (commandID);
  13840. if (target == 0)
  13841. target = JUCEApplication::getInstance();
  13842. if (target != 0)
  13843. target = target->getTargetForCommand (commandID);
  13844. if (target != 0)
  13845. target->getCommandInfo (commandID, upToDateInfo);
  13846. return target;
  13847. }
  13848. ApplicationCommandTarget* ApplicationCommandManager::findTargetForComponent (Component* c)
  13849. {
  13850. ApplicationCommandTarget* target = dynamic_cast <ApplicationCommandTarget*> (c);
  13851. if (target == 0 && c != 0)
  13852. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  13853. target = c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  13854. return target;
  13855. }
  13856. ApplicationCommandTarget* ApplicationCommandManager::findDefaultComponentTarget()
  13857. {
  13858. Component* c = Component::getCurrentlyFocusedComponent();
  13859. if (c == 0)
  13860. {
  13861. TopLevelWindow* const activeWindow = TopLevelWindow::getActiveTopLevelWindow();
  13862. if (activeWindow != 0)
  13863. {
  13864. c = activeWindow->getPeer()->getLastFocusedSubcomponent();
  13865. if (c == 0)
  13866. c = activeWindow;
  13867. }
  13868. }
  13869. if (c == 0 && Process::isForegroundProcess())
  13870. {
  13871. // getting a bit desperate now - try all desktop comps..
  13872. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  13873. {
  13874. ApplicationCommandTarget* const target
  13875. = findTargetForComponent (Desktop::getInstance().getComponent (i)
  13876. ->getPeer()->getLastFocusedSubcomponent());
  13877. if (target != 0)
  13878. return target;
  13879. }
  13880. }
  13881. if (c != 0)
  13882. {
  13883. ResizableWindow* const resizableWindow = dynamic_cast <ResizableWindow*> (c);
  13884. // if we're focused on a ResizableWindow, chances are that it's the content
  13885. // component that really should get the event. And if not, the event will
  13886. // still be passed up to the top level window anyway, so let's send it to the
  13887. // content comp.
  13888. if (resizableWindow != 0 && resizableWindow->getContentComponent() != 0)
  13889. c = resizableWindow->getContentComponent();
  13890. ApplicationCommandTarget* const target = findTargetForComponent (c);
  13891. if (target != 0)
  13892. return target;
  13893. }
  13894. return JUCEApplication::getInstance();
  13895. }
  13896. void ApplicationCommandManager::addListener (ApplicationCommandManagerListener* const listener) throw()
  13897. {
  13898. listeners.add (listener);
  13899. }
  13900. void ApplicationCommandManager::removeListener (ApplicationCommandManagerListener* const listener) throw()
  13901. {
  13902. listeners.remove (listener);
  13903. }
  13904. void ApplicationCommandManager::sendListenerInvokeCallback (const ApplicationCommandTarget::InvocationInfo& info)
  13905. {
  13906. listeners.call (&ApplicationCommandManagerListener::applicationCommandInvoked, info);
  13907. }
  13908. void ApplicationCommandManager::handleAsyncUpdate()
  13909. {
  13910. listeners.call (&ApplicationCommandManagerListener::applicationCommandListChanged);
  13911. }
  13912. void ApplicationCommandManager::globalFocusChanged (Component*)
  13913. {
  13914. commandStatusChanged();
  13915. }
  13916. END_JUCE_NAMESPACE
  13917. /*** End of inlined file: juce_ApplicationCommandManager.cpp ***/
  13918. /*** Start of inlined file: juce_ApplicationCommandTarget.cpp ***/
  13919. BEGIN_JUCE_NAMESPACE
  13920. ApplicationCommandTarget::ApplicationCommandTarget()
  13921. {
  13922. }
  13923. ApplicationCommandTarget::~ApplicationCommandTarget()
  13924. {
  13925. messageInvoker = 0;
  13926. }
  13927. bool ApplicationCommandTarget::tryToInvoke (const InvocationInfo& info, const bool async)
  13928. {
  13929. if (isCommandActive (info.commandID))
  13930. {
  13931. if (async)
  13932. {
  13933. if (messageInvoker == 0)
  13934. messageInvoker = new CommandTargetMessageInvoker (this);
  13935. messageInvoker->postMessage (new Message (0, 0, 0, new ApplicationCommandTarget::InvocationInfo (info)));
  13936. return true;
  13937. }
  13938. else
  13939. {
  13940. const bool success = perform (info);
  13941. jassert (success); // hmm - your target should have been able to perform this command. If it can't
  13942. // do it at the moment for some reason, it should clear the 'isActive' flag when it
  13943. // returns the command's info.
  13944. return success;
  13945. }
  13946. }
  13947. return false;
  13948. }
  13949. ApplicationCommandTarget* ApplicationCommandTarget::findFirstTargetParentComponent()
  13950. {
  13951. Component* c = dynamic_cast <Component*> (this);
  13952. if (c != 0)
  13953. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  13954. return c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  13955. return 0;
  13956. }
  13957. ApplicationCommandTarget* ApplicationCommandTarget::getTargetForCommand (const CommandID commandID)
  13958. {
  13959. ApplicationCommandTarget* target = this;
  13960. int depth = 0;
  13961. while (target != 0)
  13962. {
  13963. Array <CommandID> commandIDs;
  13964. target->getAllCommands (commandIDs);
  13965. if (commandIDs.contains (commandID))
  13966. return target;
  13967. target = target->getNextCommandTarget();
  13968. ++depth;
  13969. jassert (depth < 100); // could be a recursive command chain??
  13970. jassert (target != this); // definitely a recursive command chain!
  13971. if (depth > 100 || target == this)
  13972. break;
  13973. }
  13974. if (target == 0)
  13975. {
  13976. target = JUCEApplication::getInstance();
  13977. if (target != 0)
  13978. {
  13979. Array <CommandID> commandIDs;
  13980. target->getAllCommands (commandIDs);
  13981. if (commandIDs.contains (commandID))
  13982. return target;
  13983. }
  13984. }
  13985. return 0;
  13986. }
  13987. bool ApplicationCommandTarget::isCommandActive (const CommandID commandID)
  13988. {
  13989. ApplicationCommandInfo info (commandID);
  13990. info.flags = ApplicationCommandInfo::isDisabled;
  13991. getCommandInfo (commandID, info);
  13992. return (info.flags & ApplicationCommandInfo::isDisabled) == 0;
  13993. }
  13994. bool ApplicationCommandTarget::invoke (const InvocationInfo& info, const bool async)
  13995. {
  13996. ApplicationCommandTarget* target = this;
  13997. int depth = 0;
  13998. while (target != 0)
  13999. {
  14000. if (target->tryToInvoke (info, async))
  14001. return true;
  14002. target = target->getNextCommandTarget();
  14003. ++depth;
  14004. jassert (depth < 100); // could be a recursive command chain??
  14005. jassert (target != this); // definitely a recursive command chain!
  14006. if (depth > 100 || target == this)
  14007. break;
  14008. }
  14009. if (target == 0)
  14010. {
  14011. target = JUCEApplication::getInstance();
  14012. if (target != 0)
  14013. return target->tryToInvoke (info, async);
  14014. }
  14015. return false;
  14016. }
  14017. bool ApplicationCommandTarget::invokeDirectly (const CommandID commandID, const bool asynchronously)
  14018. {
  14019. ApplicationCommandTarget::InvocationInfo info (commandID);
  14020. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  14021. return invoke (info, asynchronously);
  14022. }
  14023. ApplicationCommandTarget::InvocationInfo::InvocationInfo (const CommandID commandID_) throw()
  14024. : commandID (commandID_),
  14025. commandFlags (0),
  14026. invocationMethod (direct),
  14027. originatingComponent (0),
  14028. isKeyDown (false),
  14029. millisecsSinceKeyPressed (0)
  14030. {
  14031. }
  14032. ApplicationCommandTarget::CommandTargetMessageInvoker::CommandTargetMessageInvoker (ApplicationCommandTarget* const owner_)
  14033. : owner (owner_)
  14034. {
  14035. }
  14036. ApplicationCommandTarget::CommandTargetMessageInvoker::~CommandTargetMessageInvoker()
  14037. {
  14038. }
  14039. void ApplicationCommandTarget::CommandTargetMessageInvoker::handleMessage (const Message& message)
  14040. {
  14041. const ScopedPointer <InvocationInfo> info ((InvocationInfo*) message.pointerParameter);
  14042. owner->tryToInvoke (*info, false);
  14043. }
  14044. END_JUCE_NAMESPACE
  14045. /*** End of inlined file: juce_ApplicationCommandTarget.cpp ***/
  14046. /*** Start of inlined file: juce_ApplicationProperties.cpp ***/
  14047. BEGIN_JUCE_NAMESPACE
  14048. juce_ImplementSingleton (ApplicationProperties)
  14049. ApplicationProperties::ApplicationProperties() throw()
  14050. : msBeforeSaving (3000),
  14051. options (PropertiesFile::storeAsBinary),
  14052. commonSettingsAreReadOnly (0)
  14053. {
  14054. }
  14055. ApplicationProperties::~ApplicationProperties()
  14056. {
  14057. closeFiles();
  14058. clearSingletonInstance();
  14059. }
  14060. void ApplicationProperties::setStorageParameters (const String& applicationName,
  14061. const String& fileNameSuffix,
  14062. const String& folderName_,
  14063. const int millisecondsBeforeSaving,
  14064. const int propertiesFileOptions) throw()
  14065. {
  14066. appName = applicationName;
  14067. fileSuffix = fileNameSuffix;
  14068. folderName = folderName_;
  14069. msBeforeSaving = millisecondsBeforeSaving;
  14070. options = propertiesFileOptions;
  14071. }
  14072. bool ApplicationProperties::testWriteAccess (const bool testUserSettings,
  14073. const bool testCommonSettings,
  14074. const bool showWarningDialogOnFailure)
  14075. {
  14076. const bool userOk = (! testUserSettings) || getUserSettings()->save();
  14077. const bool commonOk = (! testCommonSettings) || getCommonSettings (false)->save();
  14078. if (! (userOk && commonOk))
  14079. {
  14080. if (showWarningDialogOnFailure)
  14081. {
  14082. String filenames;
  14083. if (userProps != 0 && ! userOk)
  14084. filenames << '\n' << userProps->getFile().getFullPathName();
  14085. if (commonProps != 0 && ! commonOk)
  14086. filenames << '\n' << commonProps->getFile().getFullPathName();
  14087. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14088. appName + TRANS(" - Unable to save settings"),
  14089. TRANS("An error occurred when trying to save the application's settings file...\n\nIn order to save and restore its settings, ")
  14090. + appName + TRANS(" needs to be able to write to the following files:\n")
  14091. + filenames
  14092. + TRANS("\n\nMake sure that these files aren't read-only, and that the disk isn't full."));
  14093. }
  14094. return false;
  14095. }
  14096. return true;
  14097. }
  14098. void ApplicationProperties::openFiles() throw()
  14099. {
  14100. // You need to call setStorageParameters() before trying to get hold of the
  14101. // properties!
  14102. jassert (appName.isNotEmpty());
  14103. if (appName.isNotEmpty())
  14104. {
  14105. if (userProps == 0)
  14106. userProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14107. false, msBeforeSaving, options);
  14108. if (commonProps == 0)
  14109. commonProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14110. true, msBeforeSaving, options);
  14111. userProps->setFallbackPropertySet (commonProps);
  14112. }
  14113. }
  14114. PropertiesFile* ApplicationProperties::getUserSettings() throw()
  14115. {
  14116. if (userProps == 0)
  14117. openFiles();
  14118. return userProps;
  14119. }
  14120. PropertiesFile* ApplicationProperties::getCommonSettings (const bool returnUserPropsIfReadOnly) throw()
  14121. {
  14122. if (commonProps == 0)
  14123. openFiles();
  14124. if (returnUserPropsIfReadOnly)
  14125. {
  14126. if (commonSettingsAreReadOnly == 0)
  14127. commonSettingsAreReadOnly = commonProps->save() ? -1 : 1;
  14128. if (commonSettingsAreReadOnly > 0)
  14129. return userProps;
  14130. }
  14131. return commonProps;
  14132. }
  14133. bool ApplicationProperties::saveIfNeeded()
  14134. {
  14135. return (userProps == 0 || userProps->saveIfNeeded())
  14136. && (commonProps == 0 || commonProps->saveIfNeeded());
  14137. }
  14138. void ApplicationProperties::closeFiles()
  14139. {
  14140. userProps = 0;
  14141. commonProps = 0;
  14142. }
  14143. END_JUCE_NAMESPACE
  14144. /*** End of inlined file: juce_ApplicationProperties.cpp ***/
  14145. /*** Start of inlined file: juce_DeletedAtShutdown.cpp ***/
  14146. BEGIN_JUCE_NAMESPACE
  14147. static VoidArray objectsToDelete;
  14148. static CriticalSection lock;
  14149. DeletedAtShutdown::DeletedAtShutdown()
  14150. {
  14151. const ScopedLock sl (lock);
  14152. objectsToDelete.add (this);
  14153. }
  14154. DeletedAtShutdown::~DeletedAtShutdown()
  14155. {
  14156. const ScopedLock sl (lock);
  14157. objectsToDelete.removeValue (this);
  14158. }
  14159. void DeletedAtShutdown::deleteAll()
  14160. {
  14161. // make a local copy of the array, so it can't get into a loop if something
  14162. // creates another DeletedAtShutdown object during its destructor.
  14163. VoidArray localCopy;
  14164. {
  14165. const ScopedLock sl (lock);
  14166. localCopy = objectsToDelete;
  14167. }
  14168. for (int i = localCopy.size(); --i >= 0;)
  14169. {
  14170. JUCE_TRY
  14171. {
  14172. DeletedAtShutdown* deletee = (DeletedAtShutdown*) localCopy.getUnchecked(i);
  14173. // double-check that it's not already been deleted during another object's destructor.
  14174. {
  14175. const ScopedLock sl (lock);
  14176. if (! objectsToDelete.contains (deletee))
  14177. deletee = 0;
  14178. }
  14179. delete deletee;
  14180. }
  14181. JUCE_CATCH_EXCEPTION
  14182. }
  14183. // if no objects got re-created during shutdown, this should have been emptied by their
  14184. // destructors
  14185. jassert (objectsToDelete.size() == 0);
  14186. objectsToDelete.clear(); // just to make sure the array doesn't have any memory still allocated
  14187. }
  14188. END_JUCE_NAMESPACE
  14189. /*** End of inlined file: juce_DeletedAtShutdown.cpp ***/
  14190. /*** Start of inlined file: juce_PropertiesFile.cpp ***/
  14191. BEGIN_JUCE_NAMESPACE
  14192. namespace PropertyFileConstants
  14193. {
  14194. static const int magicNumber = (int) ByteOrder::littleEndianInt ("PROP");
  14195. static const int magicNumberCompressed = (int) ByteOrder::littleEndianInt ("CPRP");
  14196. static const char* const fileTag = "PROPERTIES";
  14197. static const char* const valueTag = "VALUE";
  14198. static const char* const nameAttribute = "name";
  14199. static const char* const valueAttribute = "val";
  14200. }
  14201. PropertiesFile::PropertiesFile (const File& f, const int millisecondsBeforeSaving, const int options_)
  14202. : PropertySet (ignoreCaseOfKeyNames),
  14203. file (f),
  14204. timerInterval (millisecondsBeforeSaving),
  14205. options (options_),
  14206. loadedOk (false),
  14207. needsWriting (false)
  14208. {
  14209. // You need to correctly specify just one storage format for the file
  14210. jassert ((options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsBinary
  14211. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsCompressedBinary
  14212. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsXML);
  14213. ScopedPointer<InputStream> fileStream (f.createInputStream());
  14214. if (fileStream != 0)
  14215. {
  14216. int magicNumber = fileStream->readInt();
  14217. if (magicNumber == PropertyFileConstants::magicNumberCompressed)
  14218. {
  14219. fileStream = new GZIPDecompressorInputStream (new SubregionStream (fileStream.release(), 4, -1, true), true);
  14220. magicNumber = PropertyFileConstants::magicNumber;
  14221. }
  14222. if (magicNumber == PropertyFileConstants::magicNumber)
  14223. {
  14224. loadedOk = true;
  14225. BufferedInputStream in (fileStream.release(), 2048, true);
  14226. int numValues = in.readInt();
  14227. while (--numValues >= 0 && ! in.isExhausted())
  14228. {
  14229. const String key (in.readString());
  14230. const String value (in.readString());
  14231. jassert (key.isNotEmpty());
  14232. if (key.isNotEmpty())
  14233. getAllProperties().set (key, value);
  14234. }
  14235. }
  14236. else
  14237. {
  14238. // Not a binary props file - let's see if it's XML..
  14239. fileStream = 0;
  14240. XmlDocument parser (f);
  14241. ScopedPointer<XmlElement> doc (parser.getDocumentElement (true));
  14242. if (doc != 0 && doc->hasTagName (PropertyFileConstants::fileTag))
  14243. {
  14244. doc = parser.getDocumentElement();
  14245. if (doc != 0)
  14246. {
  14247. loadedOk = true;
  14248. forEachXmlChildElementWithTagName (*doc, e, PropertyFileConstants::valueTag)
  14249. {
  14250. const String name (e->getStringAttribute (PropertyFileConstants::nameAttribute));
  14251. if (name.isNotEmpty())
  14252. {
  14253. getAllProperties().set (name,
  14254. e->getFirstChildElement() != 0
  14255. ? e->getFirstChildElement()->createDocument (String::empty, true)
  14256. : e->getStringAttribute (PropertyFileConstants::valueAttribute));
  14257. }
  14258. }
  14259. }
  14260. else
  14261. {
  14262. // must be a pretty broken XML file we're trying to parse here!
  14263. jassertfalse
  14264. }
  14265. }
  14266. }
  14267. }
  14268. else
  14269. {
  14270. loadedOk = ! f.exists();
  14271. }
  14272. }
  14273. PropertiesFile::~PropertiesFile()
  14274. {
  14275. if (! saveIfNeeded())
  14276. jassertfalse;
  14277. }
  14278. bool PropertiesFile::saveIfNeeded()
  14279. {
  14280. const ScopedLock sl (getLock());
  14281. return (! needsWriting) || save();
  14282. }
  14283. bool PropertiesFile::needsToBeSaved() const
  14284. {
  14285. const ScopedLock sl (getLock());
  14286. return needsWriting;
  14287. }
  14288. void PropertiesFile::setNeedsToBeSaved (const bool needsToBeSaved)
  14289. {
  14290. const ScopedLock sl (getLock());
  14291. needsWriting = needsToBeSaved;
  14292. }
  14293. bool PropertiesFile::save()
  14294. {
  14295. const ScopedLock sl (getLock());
  14296. stopTimer();
  14297. if (file == File::nonexistent
  14298. || file.isDirectory()
  14299. || ! file.getParentDirectory().createDirectory())
  14300. return false;
  14301. if ((options & storeAsXML) != 0)
  14302. {
  14303. XmlElement doc (PropertyFileConstants::fileTag);
  14304. for (int i = 0; i < getAllProperties().size(); ++i)
  14305. {
  14306. XmlElement* const e = doc.createNewChildElement (PropertyFileConstants::valueTag);
  14307. e->setAttribute (PropertyFileConstants::nameAttribute, getAllProperties().getAllKeys() [i]);
  14308. // if the value seems to contain xml, store it as such..
  14309. XmlDocument xmlContent (getAllProperties().getAllValues() [i]);
  14310. XmlElement* const childElement = xmlContent.getDocumentElement();
  14311. if (childElement != 0)
  14312. e->addChildElement (childElement);
  14313. else
  14314. e->setAttribute (PropertyFileConstants::valueAttribute,
  14315. getAllProperties().getAllValues() [i]);
  14316. }
  14317. if (doc.writeToFile (file, String::empty))
  14318. {
  14319. needsWriting = false;
  14320. return true;
  14321. }
  14322. }
  14323. else
  14324. {
  14325. TemporaryFile tempFile (file);
  14326. ScopedPointer <OutputStream> out (tempFile.getFile().createOutputStream());
  14327. if (out != 0)
  14328. {
  14329. if ((options & storeAsCompressedBinary) != 0)
  14330. {
  14331. out->writeInt (PropertyFileConstants::magicNumberCompressed);
  14332. out->flush();
  14333. out = new GZIPCompressorOutputStream (out.release(), 9, true);
  14334. }
  14335. else
  14336. {
  14337. // have you set up the storage option flags correctly?
  14338. jassert ((options & storeAsBinary) != 0);
  14339. out->writeInt (PropertyFileConstants::magicNumber);
  14340. }
  14341. const int numProperties = getAllProperties().size();
  14342. out->writeInt (numProperties);
  14343. for (int i = 0; i < numProperties; ++i)
  14344. {
  14345. out->writeString (getAllProperties().getAllKeys() [i]);
  14346. out->writeString (getAllProperties().getAllValues() [i]);
  14347. }
  14348. out = 0;
  14349. if (tempFile.overwriteTargetFileWithTemporary())
  14350. {
  14351. needsWriting = false;
  14352. return true;
  14353. }
  14354. }
  14355. }
  14356. return false;
  14357. }
  14358. void PropertiesFile::timerCallback()
  14359. {
  14360. saveIfNeeded();
  14361. }
  14362. void PropertiesFile::propertyChanged()
  14363. {
  14364. sendChangeMessage (this);
  14365. needsWriting = true;
  14366. if (timerInterval > 0)
  14367. startTimer (timerInterval);
  14368. else if (timerInterval == 0)
  14369. saveIfNeeded();
  14370. }
  14371. const File PropertiesFile::getDefaultAppSettingsFile (const String& applicationName,
  14372. const String& fileNameSuffix,
  14373. const String& folderName,
  14374. const bool commonToAllUsers)
  14375. {
  14376. // mustn't have illegal characters in this name..
  14377. jassert (applicationName == File::createLegalFileName (applicationName));
  14378. #if JUCE_MAC || JUCE_IPHONE
  14379. File dir (commonToAllUsers ? "/Library/Preferences"
  14380. : "~/Library/Preferences");
  14381. if (folderName.isNotEmpty())
  14382. dir = dir.getChildFile (folderName);
  14383. #endif
  14384. #ifdef JUCE_LINUX
  14385. const File dir ((commonToAllUsers ? "/var/" : "~/")
  14386. + (folderName.isNotEmpty() ? folderName
  14387. : ("." + applicationName)));
  14388. #endif
  14389. #if JUCE_WIN32
  14390. File dir (File::getSpecialLocation (commonToAllUsers ? File::commonApplicationDataDirectory
  14391. : File::userApplicationDataDirectory));
  14392. if (dir == File::nonexistent)
  14393. return File::nonexistent;
  14394. dir = dir.getChildFile (folderName.isNotEmpty() ? folderName
  14395. : applicationName);
  14396. #endif
  14397. return dir.getChildFile (applicationName)
  14398. .withFileExtension (fileNameSuffix);
  14399. }
  14400. PropertiesFile* PropertiesFile::createDefaultAppPropertiesFile (const String& applicationName,
  14401. const String& fileNameSuffix,
  14402. const String& folderName,
  14403. const bool commonToAllUsers,
  14404. const int millisecondsBeforeSaving,
  14405. const int propertiesFileOptions)
  14406. {
  14407. const File file (getDefaultAppSettingsFile (applicationName,
  14408. fileNameSuffix,
  14409. folderName,
  14410. commonToAllUsers));
  14411. jassert (file != File::nonexistent);
  14412. if (file == File::nonexistent)
  14413. return 0;
  14414. return new PropertiesFile (file, millisecondsBeforeSaving, propertiesFileOptions);
  14415. }
  14416. END_JUCE_NAMESPACE
  14417. /*** End of inlined file: juce_PropertiesFile.cpp ***/
  14418. /*** Start of inlined file: juce_FileBasedDocument.cpp ***/
  14419. BEGIN_JUCE_NAMESPACE
  14420. FileBasedDocument::FileBasedDocument (const String& fileExtension_,
  14421. const String& fileWildcard_,
  14422. const String& openFileDialogTitle_,
  14423. const String& saveFileDialogTitle_)
  14424. : changedSinceSave (false),
  14425. fileExtension (fileExtension_),
  14426. fileWildcard (fileWildcard_),
  14427. openFileDialogTitle (openFileDialogTitle_),
  14428. saveFileDialogTitle (saveFileDialogTitle_)
  14429. {
  14430. }
  14431. FileBasedDocument::~FileBasedDocument()
  14432. {
  14433. }
  14434. void FileBasedDocument::setChangedFlag (const bool hasChanged)
  14435. {
  14436. changedSinceSave = hasChanged;
  14437. }
  14438. void FileBasedDocument::changed()
  14439. {
  14440. changedSinceSave = true;
  14441. sendChangeMessage (this);
  14442. }
  14443. void FileBasedDocument::setFile (const File& newFile)
  14444. {
  14445. if (documentFile != newFile)
  14446. {
  14447. documentFile = newFile;
  14448. changedSinceSave = true;
  14449. }
  14450. }
  14451. bool FileBasedDocument::loadFrom (const File& newFile,
  14452. const bool showMessageOnFailure)
  14453. {
  14454. MouseCursor::showWaitCursor();
  14455. const File oldFile (documentFile);
  14456. documentFile = newFile;
  14457. String error;
  14458. if (newFile.existsAsFile())
  14459. {
  14460. error = loadDocument (newFile);
  14461. if (error.isEmpty())
  14462. {
  14463. setChangedFlag (false);
  14464. MouseCursor::hideWaitCursor();
  14465. setLastDocumentOpened (newFile);
  14466. return true;
  14467. }
  14468. }
  14469. else
  14470. {
  14471. error = "The file doesn't exist";
  14472. }
  14473. documentFile = oldFile;
  14474. MouseCursor::hideWaitCursor();
  14475. if (showMessageOnFailure)
  14476. {
  14477. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14478. TRANS("Failed to open file..."),
  14479. TRANS("There was an error while trying to load the file:\n\n")
  14480. + newFile.getFullPathName()
  14481. + "\n\n"
  14482. + error);
  14483. }
  14484. return false;
  14485. }
  14486. bool FileBasedDocument::loadFromUserSpecifiedFile (const bool showMessageOnFailure)
  14487. {
  14488. FileChooser fc (openFileDialogTitle,
  14489. getLastDocumentOpened(),
  14490. fileWildcard);
  14491. if (fc.browseForFileToOpen())
  14492. return loadFrom (fc.getResult(), showMessageOnFailure);
  14493. return false;
  14494. }
  14495. FileBasedDocument::SaveResult FileBasedDocument::save (const bool askUserForFileIfNotSpecified,
  14496. const bool showMessageOnFailure)
  14497. {
  14498. return saveAs (documentFile,
  14499. false,
  14500. askUserForFileIfNotSpecified,
  14501. showMessageOnFailure);
  14502. }
  14503. FileBasedDocument::SaveResult FileBasedDocument::saveAs (const File& newFile,
  14504. const bool warnAboutOverwritingExistingFiles,
  14505. const bool askUserForFileIfNotSpecified,
  14506. const bool showMessageOnFailure)
  14507. {
  14508. if (newFile == File::nonexistent)
  14509. {
  14510. if (askUserForFileIfNotSpecified)
  14511. {
  14512. return saveAsInteractive (true);
  14513. }
  14514. else
  14515. {
  14516. // can't save to an unspecified file
  14517. jassertfalse
  14518. return failedToWriteToFile;
  14519. }
  14520. }
  14521. if (warnAboutOverwritingExistingFiles && newFile.exists())
  14522. {
  14523. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14524. TRANS("File already exists"),
  14525. TRANS("There's already a file called:\n\n")
  14526. + newFile.getFullPathName()
  14527. + TRANS("\n\nAre you sure you want to overwrite it?"),
  14528. TRANS("overwrite"),
  14529. TRANS("cancel")))
  14530. {
  14531. return userCancelledSave;
  14532. }
  14533. }
  14534. MouseCursor::showWaitCursor();
  14535. const File oldFile (documentFile);
  14536. documentFile = newFile;
  14537. String error (saveDocument (newFile));
  14538. if (error.isEmpty())
  14539. {
  14540. setChangedFlag (false);
  14541. MouseCursor::hideWaitCursor();
  14542. return savedOk;
  14543. }
  14544. documentFile = oldFile;
  14545. MouseCursor::hideWaitCursor();
  14546. if (showMessageOnFailure)
  14547. {
  14548. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14549. TRANS("Error writing to file..."),
  14550. TRANS("An error occurred while trying to save \"")
  14551. + getDocumentTitle()
  14552. + TRANS("\" to the file:\n\n")
  14553. + newFile.getFullPathName()
  14554. + "\n\n"
  14555. + error);
  14556. }
  14557. return failedToWriteToFile;
  14558. }
  14559. FileBasedDocument::SaveResult FileBasedDocument::saveIfNeededAndUserAgrees()
  14560. {
  14561. if (! hasChangedSinceSaved())
  14562. return savedOk;
  14563. const int r = AlertWindow::showYesNoCancelBox (AlertWindow::QuestionIcon,
  14564. TRANS("Closing document..."),
  14565. TRANS("Do you want to save the changes to \"")
  14566. + getDocumentTitle() + "\"?",
  14567. TRANS("save"),
  14568. TRANS("discard changes"),
  14569. TRANS("cancel"));
  14570. if (r == 1)
  14571. {
  14572. // save changes
  14573. return save (true, true);
  14574. }
  14575. else if (r == 2)
  14576. {
  14577. // discard changes
  14578. return savedOk;
  14579. }
  14580. return userCancelledSave;
  14581. }
  14582. FileBasedDocument::SaveResult FileBasedDocument::saveAsInteractive (const bool warnAboutOverwritingExistingFiles)
  14583. {
  14584. File f;
  14585. if (documentFile.existsAsFile())
  14586. f = documentFile;
  14587. else
  14588. f = getLastDocumentOpened();
  14589. String legalFilename (File::createLegalFileName (getDocumentTitle()));
  14590. if (legalFilename.isEmpty())
  14591. legalFilename = "unnamed";
  14592. if (f.existsAsFile() || f.getParentDirectory().isDirectory())
  14593. f = f.getSiblingFile (legalFilename);
  14594. else
  14595. f = File::getSpecialLocation (File::userDocumentsDirectory).getChildFile (legalFilename);
  14596. f = f.withFileExtension (fileExtension)
  14597. .getNonexistentSibling (true);
  14598. FileChooser fc (saveFileDialogTitle, f, fileWildcard);
  14599. if (fc.browseForFileToSave (warnAboutOverwritingExistingFiles))
  14600. {
  14601. setLastDocumentOpened (fc.getResult());
  14602. File chosen (fc.getResult());
  14603. if (chosen.getFileExtension().isEmpty())
  14604. {
  14605. chosen = chosen.withFileExtension (fileExtension);
  14606. if (chosen.exists())
  14607. {
  14608. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14609. TRANS("File already exists"),
  14610. TRANS("There's already a file called:")
  14611. + "\n\n" + chosen.getFullPathName()
  14612. + "\n\n" + TRANS("Are you sure you want to overwrite it?"),
  14613. TRANS("overwrite"),
  14614. TRANS("cancel")))
  14615. {
  14616. return userCancelledSave;
  14617. }
  14618. }
  14619. }
  14620. return saveAs (chosen, false, false, true);
  14621. }
  14622. return userCancelledSave;
  14623. }
  14624. END_JUCE_NAMESPACE
  14625. /*** End of inlined file: juce_FileBasedDocument.cpp ***/
  14626. /*** Start of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  14627. BEGIN_JUCE_NAMESPACE
  14628. RecentlyOpenedFilesList::RecentlyOpenedFilesList()
  14629. : maxNumberOfItems (10)
  14630. {
  14631. }
  14632. RecentlyOpenedFilesList::~RecentlyOpenedFilesList()
  14633. {
  14634. }
  14635. void RecentlyOpenedFilesList::setMaxNumberOfItems (const int newMaxNumber)
  14636. {
  14637. maxNumberOfItems = jmax (1, newMaxNumber);
  14638. while (getNumFiles() > maxNumberOfItems)
  14639. files.remove (getNumFiles() - 1);
  14640. }
  14641. int RecentlyOpenedFilesList::getNumFiles() const
  14642. {
  14643. return files.size();
  14644. }
  14645. const File RecentlyOpenedFilesList::getFile (const int index) const
  14646. {
  14647. return File (files [index]);
  14648. }
  14649. void RecentlyOpenedFilesList::clear()
  14650. {
  14651. files.clear();
  14652. }
  14653. void RecentlyOpenedFilesList::addFile (const File& file)
  14654. {
  14655. const String path (file.getFullPathName());
  14656. files.removeString (path, true);
  14657. files.insert (0, path);
  14658. setMaxNumberOfItems (maxNumberOfItems);
  14659. }
  14660. void RecentlyOpenedFilesList::removeNonExistentFiles()
  14661. {
  14662. for (int i = getNumFiles(); --i >= 0;)
  14663. if (! getFile(i).exists())
  14664. files.remove (i);
  14665. }
  14666. int RecentlyOpenedFilesList::createPopupMenuItems (PopupMenu& menuToAddTo,
  14667. const int baseItemId,
  14668. const bool showFullPaths,
  14669. const bool dontAddNonExistentFiles,
  14670. const File** filesToAvoid)
  14671. {
  14672. int num = 0;
  14673. for (int i = 0; i < getNumFiles(); ++i)
  14674. {
  14675. const File f (getFile(i));
  14676. if ((! dontAddNonExistentFiles) || f.exists())
  14677. {
  14678. bool needsAvoiding = false;
  14679. if (filesToAvoid != 0)
  14680. {
  14681. const File** avoid = filesToAvoid;
  14682. while (*avoid != 0)
  14683. {
  14684. if (f == **avoid)
  14685. {
  14686. needsAvoiding = true;
  14687. break;
  14688. }
  14689. ++avoid;
  14690. }
  14691. }
  14692. if (! needsAvoiding)
  14693. {
  14694. menuToAddTo.addItem (baseItemId + i,
  14695. showFullPaths ? f.getFullPathName()
  14696. : f.getFileName());
  14697. ++num;
  14698. }
  14699. }
  14700. }
  14701. return num;
  14702. }
  14703. const String RecentlyOpenedFilesList::toString() const
  14704. {
  14705. return files.joinIntoString ("\n");
  14706. }
  14707. void RecentlyOpenedFilesList::restoreFromString (const String& stringifiedVersion)
  14708. {
  14709. clear();
  14710. files.addLines (stringifiedVersion);
  14711. setMaxNumberOfItems (maxNumberOfItems);
  14712. }
  14713. END_JUCE_NAMESPACE
  14714. /*** End of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  14715. /*** Start of inlined file: juce_UndoManager.cpp ***/
  14716. BEGIN_JUCE_NAMESPACE
  14717. UndoManager::UndoManager (const int maxNumberOfUnitsToKeep,
  14718. const int minimumTransactions)
  14719. : totalUnitsStored (0),
  14720. nextIndex (0),
  14721. newTransaction (true),
  14722. reentrancyCheck (false)
  14723. {
  14724. setMaxNumberOfStoredUnits (maxNumberOfUnitsToKeep,
  14725. minimumTransactions);
  14726. }
  14727. UndoManager::~UndoManager()
  14728. {
  14729. clearUndoHistory();
  14730. }
  14731. void UndoManager::clearUndoHistory()
  14732. {
  14733. transactions.clear();
  14734. transactionNames.clear();
  14735. totalUnitsStored = 0;
  14736. nextIndex = 0;
  14737. sendChangeMessage (this);
  14738. }
  14739. int UndoManager::getNumberOfUnitsTakenUpByStoredCommands() const
  14740. {
  14741. return totalUnitsStored;
  14742. }
  14743. void UndoManager::setMaxNumberOfStoredUnits (const int maxNumberOfUnitsToKeep,
  14744. const int minimumTransactions)
  14745. {
  14746. maxNumUnitsToKeep = jmax (1, maxNumberOfUnitsToKeep);
  14747. minimumTransactionsToKeep = jmax (1, minimumTransactions);
  14748. }
  14749. bool UndoManager::perform (UndoableAction* const command, const String& actionName)
  14750. {
  14751. if (command != 0)
  14752. {
  14753. if (actionName.isNotEmpty())
  14754. currentTransactionName = actionName;
  14755. if (reentrancyCheck)
  14756. {
  14757. jassertfalse // don't call perform() recursively from the UndoableAction::perform() or
  14758. // undo() methods, or else these actions won't actually get done.
  14759. return false;
  14760. }
  14761. else
  14762. {
  14763. bool success = false;
  14764. JUCE_TRY
  14765. {
  14766. success = command->perform();
  14767. }
  14768. JUCE_CATCH_EXCEPTION
  14769. jassert (success);
  14770. if (success)
  14771. {
  14772. if (nextIndex > 0 && ! newTransaction)
  14773. {
  14774. OwnedArray<UndoableAction>* commandSet = transactions [nextIndex - 1];
  14775. jassert (commandSet != 0);
  14776. if (commandSet == 0)
  14777. return false;
  14778. commandSet->add (command);
  14779. }
  14780. else
  14781. {
  14782. OwnedArray<UndoableAction>* commandSet = new OwnedArray<UndoableAction>();
  14783. commandSet->add (command);
  14784. transactions.insert (nextIndex, commandSet);
  14785. transactionNames.insert (nextIndex, currentTransactionName);
  14786. ++nextIndex;
  14787. }
  14788. totalUnitsStored += command->getSizeInUnits();
  14789. newTransaction = false;
  14790. }
  14791. while (nextIndex < transactions.size())
  14792. {
  14793. const OwnedArray <UndoableAction>* const lastSet = transactions.getLast();
  14794. for (int i = lastSet->size(); --i >= 0;)
  14795. totalUnitsStored -= lastSet->getUnchecked (i)->getSizeInUnits();
  14796. transactions.removeLast();
  14797. transactionNames.remove (transactionNames.size() - 1);
  14798. }
  14799. while (nextIndex > 0
  14800. && totalUnitsStored > maxNumUnitsToKeep
  14801. && transactions.size() > minimumTransactionsToKeep)
  14802. {
  14803. const OwnedArray <UndoableAction>* const firstSet = transactions.getFirst();
  14804. for (int i = firstSet->size(); --i >= 0;)
  14805. totalUnitsStored -= firstSet->getUnchecked (i)->getSizeInUnits();
  14806. jassert (totalUnitsStored >= 0); // something fishy going on if this fails!
  14807. transactions.remove (0);
  14808. transactionNames.remove (0);
  14809. --nextIndex;
  14810. }
  14811. sendChangeMessage (this);
  14812. return success;
  14813. }
  14814. }
  14815. return false;
  14816. }
  14817. void UndoManager::beginNewTransaction (const String& actionName)
  14818. {
  14819. newTransaction = true;
  14820. currentTransactionName = actionName;
  14821. }
  14822. void UndoManager::setCurrentTransactionName (const String& newName)
  14823. {
  14824. currentTransactionName = newName;
  14825. }
  14826. bool UndoManager::canUndo() const
  14827. {
  14828. return nextIndex > 0;
  14829. }
  14830. bool UndoManager::canRedo() const
  14831. {
  14832. return nextIndex < transactions.size();
  14833. }
  14834. const String UndoManager::getUndoDescription() const
  14835. {
  14836. return transactionNames [nextIndex - 1];
  14837. }
  14838. const String UndoManager::getRedoDescription() const
  14839. {
  14840. return transactionNames [nextIndex];
  14841. }
  14842. bool UndoManager::undo()
  14843. {
  14844. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex - 1];
  14845. if (commandSet == 0)
  14846. return false;
  14847. reentrancyCheck = true;
  14848. bool failed = false;
  14849. for (int i = commandSet->size(); --i >= 0;)
  14850. {
  14851. if (! commandSet->getUnchecked(i)->undo())
  14852. {
  14853. jassertfalse
  14854. failed = true;
  14855. break;
  14856. }
  14857. }
  14858. reentrancyCheck = false;
  14859. if (failed)
  14860. {
  14861. clearUndoHistory();
  14862. }
  14863. else
  14864. {
  14865. --nextIndex;
  14866. }
  14867. beginNewTransaction();
  14868. sendChangeMessage (this);
  14869. return true;
  14870. }
  14871. bool UndoManager::redo()
  14872. {
  14873. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex];
  14874. if (commandSet == 0)
  14875. return false;
  14876. reentrancyCheck = true;
  14877. bool failed = false;
  14878. for (int i = 0; i < commandSet->size(); ++i)
  14879. {
  14880. if (! commandSet->getUnchecked(i)->perform())
  14881. {
  14882. jassertfalse
  14883. failed = true;
  14884. break;
  14885. }
  14886. }
  14887. reentrancyCheck = false;
  14888. if (failed)
  14889. {
  14890. clearUndoHistory();
  14891. }
  14892. else
  14893. {
  14894. ++nextIndex;
  14895. }
  14896. beginNewTransaction();
  14897. sendChangeMessage (this);
  14898. return true;
  14899. }
  14900. bool UndoManager::undoCurrentTransactionOnly()
  14901. {
  14902. return newTransaction ? false
  14903. : undo();
  14904. }
  14905. void UndoManager::getActionsInCurrentTransaction (Array <const UndoableAction*>& actionsFound) const
  14906. {
  14907. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  14908. if (commandSet != 0 && ! newTransaction)
  14909. {
  14910. for (int i = 0; i < commandSet->size(); ++i)
  14911. actionsFound.add (commandSet->getUnchecked(i));
  14912. }
  14913. }
  14914. int UndoManager::getNumActionsInCurrentTransaction() const
  14915. {
  14916. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  14917. if (commandSet != 0 && ! newTransaction)
  14918. return commandSet->size();
  14919. return 0;
  14920. }
  14921. END_JUCE_NAMESPACE
  14922. /*** End of inlined file: juce_UndoManager.cpp ***/
  14923. /*** Start of inlined file: juce_AiffAudioFormat.cpp ***/
  14924. BEGIN_JUCE_NAMESPACE
  14925. static const char* const aiffFormatName = "AIFF file";
  14926. static const tchar* const aiffExtensions[] = { T(".aiff"), T(".aif"), 0 };
  14927. class AiffAudioFormatReader : public AudioFormatReader
  14928. {
  14929. public:
  14930. int bytesPerFrame;
  14931. int64 dataChunkStart;
  14932. bool littleEndian;
  14933. AiffAudioFormatReader (InputStream* in)
  14934. : AudioFormatReader (in, TRANS (aiffFormatName))
  14935. {
  14936. if (input->readInt() == chunkName ("FORM"))
  14937. {
  14938. const int len = input->readIntBigEndian();
  14939. const int64 end = input->getPosition() + len;
  14940. const int nextType = input->readInt();
  14941. if (nextType == chunkName ("AIFF") || nextType == chunkName ("AIFC"))
  14942. {
  14943. bool hasGotVer = false;
  14944. bool hasGotData = false;
  14945. bool hasGotType = false;
  14946. while (input->getPosition() < end)
  14947. {
  14948. const int type = input->readInt();
  14949. const uint32 length = (uint32) input->readIntBigEndian();
  14950. const int64 chunkEnd = input->getPosition() + length;
  14951. if (type == chunkName ("FVER"))
  14952. {
  14953. hasGotVer = true;
  14954. const int ver = input->readIntBigEndian();
  14955. if (ver != 0 && ver != (int)0xa2805140)
  14956. break;
  14957. }
  14958. else if (type == chunkName ("COMM"))
  14959. {
  14960. hasGotType = true;
  14961. numChannels = (unsigned int)input->readShortBigEndian();
  14962. lengthInSamples = input->readIntBigEndian();
  14963. bitsPerSample = input->readShortBigEndian();
  14964. bytesPerFrame = (numChannels * bitsPerSample) >> 3;
  14965. unsigned char sampleRateBytes[10];
  14966. input->read (sampleRateBytes, 10);
  14967. const int byte0 = sampleRateBytes[0];
  14968. if ((byte0 & 0x80) != 0
  14969. || byte0 <= 0x3F || byte0 > 0x40
  14970. || (byte0 == 0x40 && sampleRateBytes[1] > 0x1C))
  14971. break;
  14972. unsigned int sampRate = ByteOrder::bigEndianInt ((char*) sampleRateBytes + 2);
  14973. sampRate >>= (16414 - ByteOrder::bigEndianShort ((char*) sampleRateBytes));
  14974. sampleRate = (int) sampRate;
  14975. if (length <= 18)
  14976. {
  14977. // some types don't have a chunk large enough to include a compression
  14978. // type, so assume it's just big-endian pcm
  14979. littleEndian = false;
  14980. }
  14981. else
  14982. {
  14983. const int compType = input->readInt();
  14984. if (compType == chunkName ("NONE") || compType == chunkName ("twos"))
  14985. {
  14986. littleEndian = false;
  14987. }
  14988. else if (compType == chunkName ("sowt"))
  14989. {
  14990. littleEndian = true;
  14991. }
  14992. else
  14993. {
  14994. sampleRate = 0;
  14995. break;
  14996. }
  14997. }
  14998. }
  14999. else if (type == chunkName ("SSND"))
  15000. {
  15001. hasGotData = true;
  15002. const int offset = input->readIntBigEndian();
  15003. dataChunkStart = input->getPosition() + 4 + offset;
  15004. lengthInSamples = (bytesPerFrame > 0) ? jmin (lengthInSamples, (int64) (length / bytesPerFrame)) : 0;
  15005. }
  15006. else if ((hasGotVer && hasGotData && hasGotType)
  15007. || chunkEnd < input->getPosition()
  15008. || input->isExhausted())
  15009. {
  15010. break;
  15011. }
  15012. input->setPosition (chunkEnd);
  15013. }
  15014. }
  15015. }
  15016. }
  15017. ~AiffAudioFormatReader()
  15018. {
  15019. }
  15020. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  15021. int64 startSampleInFile, int numSamples)
  15022. {
  15023. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  15024. if (samplesAvailable < numSamples)
  15025. {
  15026. for (int i = numDestChannels; --i >= 0;)
  15027. if (destSamples[i] != 0)
  15028. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  15029. numSamples = (int) samplesAvailable;
  15030. }
  15031. if (numSamples <= 0)
  15032. return true;
  15033. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  15034. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  15035. char tempBuffer [tempBufSize];
  15036. while (numSamples > 0)
  15037. {
  15038. int* left = destSamples[0];
  15039. if (left != 0)
  15040. left += startOffsetInDestBuffer;
  15041. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  15042. if (right != 0)
  15043. right += startOffsetInDestBuffer;
  15044. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  15045. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  15046. if (bytesRead < numThisTime * bytesPerFrame)
  15047. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  15048. if (bitsPerSample == 16)
  15049. {
  15050. if (littleEndian)
  15051. {
  15052. const short* src = (const short*) tempBuffer;
  15053. if (numChannels > 1)
  15054. {
  15055. if (left == 0)
  15056. {
  15057. for (int i = numThisTime; --i >= 0;)
  15058. {
  15059. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15060. ++src;
  15061. }
  15062. }
  15063. else if (right == 0)
  15064. {
  15065. for (int i = numThisTime; --i >= 0;)
  15066. {
  15067. ++src;
  15068. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15069. }
  15070. }
  15071. else
  15072. {
  15073. for (int i = numThisTime; --i >= 0;)
  15074. {
  15075. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15076. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15077. }
  15078. }
  15079. }
  15080. else
  15081. {
  15082. for (int i = numThisTime; --i >= 0;)
  15083. {
  15084. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15085. }
  15086. }
  15087. }
  15088. else
  15089. {
  15090. const char* src = (const char*) tempBuffer;
  15091. if (numChannels > 1)
  15092. {
  15093. if (left == 0)
  15094. {
  15095. for (int i = numThisTime; --i >= 0;)
  15096. {
  15097. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15098. src += 4;
  15099. }
  15100. }
  15101. else if (right == 0)
  15102. {
  15103. for (int i = numThisTime; --i >= 0;)
  15104. {
  15105. src += 2;
  15106. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15107. src += 2;
  15108. }
  15109. }
  15110. else
  15111. {
  15112. for (int i = numThisTime; --i >= 0;)
  15113. {
  15114. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15115. src += 2;
  15116. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15117. src += 2;
  15118. }
  15119. }
  15120. }
  15121. else
  15122. {
  15123. for (int i = numThisTime; --i >= 0;)
  15124. {
  15125. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15126. src += 2;
  15127. }
  15128. }
  15129. }
  15130. }
  15131. else if (bitsPerSample == 24)
  15132. {
  15133. const char* src = (const char*)tempBuffer;
  15134. if (littleEndian)
  15135. {
  15136. if (numChannels > 1)
  15137. {
  15138. if (left == 0)
  15139. {
  15140. for (int i = numThisTime; --i >= 0;)
  15141. {
  15142. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15143. src += 6;
  15144. }
  15145. }
  15146. else if (right == 0)
  15147. {
  15148. for (int i = numThisTime; --i >= 0;)
  15149. {
  15150. src += 3;
  15151. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15152. src += 3;
  15153. }
  15154. }
  15155. else
  15156. {
  15157. for (int i = numThisTime; --i >= 0;)
  15158. {
  15159. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15160. src += 3;
  15161. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15162. src += 3;
  15163. }
  15164. }
  15165. }
  15166. else
  15167. {
  15168. for (int i = numThisTime; --i >= 0;)
  15169. {
  15170. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15171. src += 3;
  15172. }
  15173. }
  15174. }
  15175. else
  15176. {
  15177. if (numChannels > 1)
  15178. {
  15179. if (left == 0)
  15180. {
  15181. for (int i = numThisTime; --i >= 0;)
  15182. {
  15183. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15184. src += 6;
  15185. }
  15186. }
  15187. else if (right == 0)
  15188. {
  15189. for (int i = numThisTime; --i >= 0;)
  15190. {
  15191. src += 3;
  15192. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15193. src += 3;
  15194. }
  15195. }
  15196. else
  15197. {
  15198. for (int i = numThisTime; --i >= 0;)
  15199. {
  15200. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15201. src += 3;
  15202. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15203. src += 3;
  15204. }
  15205. }
  15206. }
  15207. else
  15208. {
  15209. for (int i = numThisTime; --i >= 0;)
  15210. {
  15211. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15212. src += 3;
  15213. }
  15214. }
  15215. }
  15216. }
  15217. else if (bitsPerSample == 32)
  15218. {
  15219. const unsigned int* src = (const unsigned int*) tempBuffer;
  15220. unsigned int* l = (unsigned int*) left;
  15221. unsigned int* r = (unsigned int*) right;
  15222. if (littleEndian)
  15223. {
  15224. if (numChannels > 1)
  15225. {
  15226. if (l == 0)
  15227. {
  15228. for (int i = numThisTime; --i >= 0;)
  15229. {
  15230. ++src;
  15231. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15232. }
  15233. }
  15234. else if (r == 0)
  15235. {
  15236. for (int i = numThisTime; --i >= 0;)
  15237. {
  15238. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15239. ++src;
  15240. }
  15241. }
  15242. else
  15243. {
  15244. for (int i = numThisTime; --i >= 0;)
  15245. {
  15246. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15247. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15248. }
  15249. }
  15250. }
  15251. else
  15252. {
  15253. for (int i = numThisTime; --i >= 0;)
  15254. {
  15255. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15256. }
  15257. }
  15258. }
  15259. else
  15260. {
  15261. if (numChannels > 1)
  15262. {
  15263. if (l == 0)
  15264. {
  15265. for (int i = numThisTime; --i >= 0;)
  15266. {
  15267. ++src;
  15268. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15269. }
  15270. }
  15271. else if (r == 0)
  15272. {
  15273. for (int i = numThisTime; --i >= 0;)
  15274. {
  15275. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15276. ++src;
  15277. }
  15278. }
  15279. else
  15280. {
  15281. for (int i = numThisTime; --i >= 0;)
  15282. {
  15283. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15284. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15285. }
  15286. }
  15287. }
  15288. else
  15289. {
  15290. for (int i = numThisTime; --i >= 0;)
  15291. {
  15292. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15293. }
  15294. }
  15295. }
  15296. left = (int*) l;
  15297. right = (int*) r;
  15298. }
  15299. else if (bitsPerSample == 8)
  15300. {
  15301. const char* src = (const char*) tempBuffer;
  15302. if (numChannels > 1)
  15303. {
  15304. if (left == 0)
  15305. {
  15306. for (int i = numThisTime; --i >= 0;)
  15307. {
  15308. *right++ = ((int) *src++) << 24;
  15309. ++src;
  15310. }
  15311. }
  15312. else if (right == 0)
  15313. {
  15314. for (int i = numThisTime; --i >= 0;)
  15315. {
  15316. ++src;
  15317. *left++ = ((int) *src++) << 24;
  15318. }
  15319. }
  15320. else
  15321. {
  15322. for (int i = numThisTime; --i >= 0;)
  15323. {
  15324. *left++ = ((int) *src++) << 24;
  15325. *right++ = ((int) *src++) << 24;
  15326. }
  15327. }
  15328. }
  15329. else
  15330. {
  15331. for (int i = numThisTime; --i >= 0;)
  15332. {
  15333. *left++ = ((int) *src++) << 24;
  15334. }
  15335. }
  15336. }
  15337. startOffsetInDestBuffer += numThisTime;
  15338. numSamples -= numThisTime;
  15339. }
  15340. if (numSamples > 0)
  15341. {
  15342. for (int i = numDestChannels; --i >= 0;)
  15343. if (destSamples[i] != 0)
  15344. zeromem (destSamples[i] + startOffsetInDestBuffer,
  15345. sizeof (int) * numSamples);
  15346. }
  15347. return true;
  15348. }
  15349. juce_UseDebuggingNewOperator
  15350. private:
  15351. AiffAudioFormatReader (const AiffAudioFormatReader&);
  15352. AiffAudioFormatReader& operator= (const AiffAudioFormatReader&);
  15353. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15354. };
  15355. class AiffAudioFormatWriter : public AudioFormatWriter
  15356. {
  15357. MemoryBlock tempBlock;
  15358. uint32 lengthInSamples, bytesWritten;
  15359. int64 headerPosition;
  15360. bool writeFailed;
  15361. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15362. AiffAudioFormatWriter (const AiffAudioFormatWriter&);
  15363. AiffAudioFormatWriter& operator= (const AiffAudioFormatWriter&);
  15364. void writeHeader()
  15365. {
  15366. const bool couldSeekOk = output->setPosition (headerPosition);
  15367. (void) couldSeekOk;
  15368. // if this fails, you've given it an output stream that can't seek! It needs
  15369. // to be able to seek back to write the header
  15370. jassert (couldSeekOk);
  15371. const int headerLen = 54;
  15372. int audioBytes = lengthInSamples * ((bitsPerSample * numChannels) / 8);
  15373. audioBytes += (audioBytes & 1);
  15374. output->writeInt (chunkName ("FORM"));
  15375. output->writeIntBigEndian (headerLen + audioBytes - 8);
  15376. output->writeInt (chunkName ("AIFF"));
  15377. output->writeInt (chunkName ("COMM"));
  15378. output->writeIntBigEndian (18);
  15379. output->writeShortBigEndian ((short) numChannels);
  15380. output->writeIntBigEndian (lengthInSamples);
  15381. output->writeShortBigEndian ((short) bitsPerSample);
  15382. uint8 sampleRateBytes[10];
  15383. zeromem (sampleRateBytes, 10);
  15384. if (sampleRate <= 1)
  15385. {
  15386. sampleRateBytes[0] = 0x3f;
  15387. sampleRateBytes[1] = 0xff;
  15388. sampleRateBytes[2] = 0x80;
  15389. }
  15390. else
  15391. {
  15392. int mask = 0x40000000;
  15393. sampleRateBytes[0] = 0x40;
  15394. if (sampleRate >= mask)
  15395. {
  15396. jassertfalse
  15397. sampleRateBytes[1] = 0x1d;
  15398. }
  15399. else
  15400. {
  15401. int n = (int) sampleRate;
  15402. int i;
  15403. for (i = 0; i <= 32 ; ++i)
  15404. {
  15405. if ((n & mask) != 0)
  15406. break;
  15407. mask >>= 1;
  15408. }
  15409. n = n << (i + 1);
  15410. sampleRateBytes[1] = (uint8) (29 - i);
  15411. sampleRateBytes[2] = (uint8) ((n >> 24) & 0xff);
  15412. sampleRateBytes[3] = (uint8) ((n >> 16) & 0xff);
  15413. sampleRateBytes[4] = (uint8) ((n >> 8) & 0xff);
  15414. sampleRateBytes[5] = (uint8) (n & 0xff);
  15415. }
  15416. }
  15417. output->write (sampleRateBytes, 10);
  15418. output->writeInt (chunkName ("SSND"));
  15419. output->writeIntBigEndian (audioBytes + 8);
  15420. output->writeInt (0);
  15421. output->writeInt (0);
  15422. jassert (output->getPosition() == headerLen);
  15423. }
  15424. public:
  15425. AiffAudioFormatWriter (OutputStream* out,
  15426. const double sampleRate_,
  15427. const unsigned int chans,
  15428. const int bits)
  15429. : AudioFormatWriter (out,
  15430. TRANS (aiffFormatName),
  15431. sampleRate_,
  15432. chans,
  15433. bits),
  15434. lengthInSamples (0),
  15435. bytesWritten (0),
  15436. writeFailed (false)
  15437. {
  15438. headerPosition = out->getPosition();
  15439. writeHeader();
  15440. }
  15441. ~AiffAudioFormatWriter()
  15442. {
  15443. if ((bytesWritten & 1) != 0)
  15444. output->writeByte (0);
  15445. writeHeader();
  15446. }
  15447. bool write (const int** data, int numSamples)
  15448. {
  15449. if (writeFailed)
  15450. return false;
  15451. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  15452. tempBlock.ensureSize (bytes, false);
  15453. char* buffer = (char*) tempBlock.getData();
  15454. const int* left = data[0];
  15455. const int* right = data[1];
  15456. if (right == 0)
  15457. right = left;
  15458. if (bitsPerSample == 16)
  15459. {
  15460. short* b = (short*) buffer;
  15461. if (numChannels > 1)
  15462. {
  15463. for (int i = numSamples; --i >= 0;)
  15464. {
  15465. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15466. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*right++ >> 16));
  15467. }
  15468. }
  15469. else
  15470. {
  15471. for (int i = numSamples; --i >= 0;)
  15472. {
  15473. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15474. }
  15475. }
  15476. }
  15477. else if (bitsPerSample == 24)
  15478. {
  15479. char* b = (char*) buffer;
  15480. if (numChannels > 1)
  15481. {
  15482. for (int i = numSamples; --i >= 0;)
  15483. {
  15484. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15485. b += 3;
  15486. ByteOrder::bigEndian24BitToChars (*right++ >> 8, b);
  15487. b += 3;
  15488. }
  15489. }
  15490. else
  15491. {
  15492. for (int i = numSamples; --i >= 0;)
  15493. {
  15494. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15495. b += 3;
  15496. }
  15497. }
  15498. }
  15499. else if (bitsPerSample == 32)
  15500. {
  15501. uint32* b = (uint32*) buffer;
  15502. if (numChannels > 1)
  15503. {
  15504. for (int i = numSamples; --i >= 0;)
  15505. {
  15506. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15507. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *right++);
  15508. }
  15509. }
  15510. else
  15511. {
  15512. for (int i = numSamples; --i >= 0;)
  15513. {
  15514. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15515. }
  15516. }
  15517. }
  15518. else if (bitsPerSample == 8)
  15519. {
  15520. char* b = (char*) buffer;
  15521. if (numChannels > 1)
  15522. {
  15523. for (int i = numSamples; --i >= 0;)
  15524. {
  15525. *b++ = (char) (*left++ >> 24);
  15526. *b++ = (char) (*right++ >> 24);
  15527. }
  15528. }
  15529. else
  15530. {
  15531. for (int i = numSamples; --i >= 0;)
  15532. {
  15533. *b++ = (char) (*left++ >> 24);
  15534. }
  15535. }
  15536. }
  15537. if (bytesWritten + bytes >= (uint32) 0xfff00000
  15538. || ! output->write (buffer, bytes))
  15539. {
  15540. // failed to write to disk, so let's try writing the header.
  15541. // If it's just run out of disk space, then if it does manage
  15542. // to write the header, we'll still have a useable file..
  15543. writeHeader();
  15544. writeFailed = true;
  15545. return false;
  15546. }
  15547. else
  15548. {
  15549. bytesWritten += bytes;
  15550. lengthInSamples += numSamples;
  15551. return true;
  15552. }
  15553. }
  15554. juce_UseDebuggingNewOperator
  15555. };
  15556. AiffAudioFormat::AiffAudioFormat()
  15557. : AudioFormat (TRANS (aiffFormatName), (const tchar**) aiffExtensions)
  15558. {
  15559. }
  15560. AiffAudioFormat::~AiffAudioFormat()
  15561. {
  15562. }
  15563. const Array <int> AiffAudioFormat::getPossibleSampleRates()
  15564. {
  15565. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  15566. return Array <int> (rates);
  15567. }
  15568. const Array <int> AiffAudioFormat::getPossibleBitDepths()
  15569. {
  15570. const int depths[] = { 8, 16, 24, 0 };
  15571. return Array <int> (depths);
  15572. }
  15573. bool AiffAudioFormat::canDoStereo()
  15574. {
  15575. return true;
  15576. }
  15577. bool AiffAudioFormat::canDoMono()
  15578. {
  15579. return true;
  15580. }
  15581. #if JUCE_MAC
  15582. bool AiffAudioFormat::canHandleFile (const File& f)
  15583. {
  15584. if (AudioFormat::canHandleFile (f))
  15585. return true;
  15586. const OSType type = PlatformUtilities::getTypeOfFile (f.getFullPathName());
  15587. return type == 'AIFF' || type == 'AIFC'
  15588. || type == 'aiff' || type == 'aifc';
  15589. }
  15590. #endif
  15591. AudioFormatReader* AiffAudioFormat::createReaderFor (InputStream* sourceStream,
  15592. const bool deleteStreamIfOpeningFails)
  15593. {
  15594. ScopedPointer <AiffAudioFormatReader> w (new AiffAudioFormatReader (sourceStream));
  15595. if (w->sampleRate != 0)
  15596. return w.release();
  15597. if (! deleteStreamIfOpeningFails)
  15598. w->input = 0;
  15599. return 0;
  15600. }
  15601. AudioFormatWriter* AiffAudioFormat::createWriterFor (OutputStream* out,
  15602. double sampleRate,
  15603. unsigned int chans,
  15604. int bitsPerSample,
  15605. const StringPairArray& /*metadataValues*/,
  15606. int /*qualityOptionIndex*/)
  15607. {
  15608. if (getPossibleBitDepths().contains (bitsPerSample))
  15609. {
  15610. return new AiffAudioFormatWriter (out,
  15611. sampleRate,
  15612. chans,
  15613. bitsPerSample);
  15614. }
  15615. return 0;
  15616. }
  15617. END_JUCE_NAMESPACE
  15618. /*** End of inlined file: juce_AiffAudioFormat.cpp ***/
  15619. /*** Start of inlined file: juce_AudioCDReader.cpp ***/
  15620. BEGIN_JUCE_NAMESPACE
  15621. #if JUCE_MAC && JUCE_USE_CDREADER
  15622. // Mac version doesn't need any native code because it's all done with files..
  15623. // Windows + Linux versions are in the platform-dependent code sections.
  15624. static void findCDs (Array<File>& cds)
  15625. {
  15626. File volumes ("/Volumes");
  15627. volumes.findChildFiles (cds, File::findDirectories, false);
  15628. for (int i = cds.size(); --i >= 0;)
  15629. if (! cds.getReference(i).getChildFile (".TOC.plist").exists())
  15630. cds.remove (i);
  15631. }
  15632. const StringArray AudioCDReader::getAvailableCDNames()
  15633. {
  15634. Array<File> cds;
  15635. findCDs (cds);
  15636. StringArray names;
  15637. for (int i = 0; i < cds.size(); ++i)
  15638. names.add (cds.getReference(i).getFileName());
  15639. return names;
  15640. }
  15641. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  15642. {
  15643. Array<File> cds;
  15644. findCDs (cds);
  15645. if (cds[index] != File::nonexistent)
  15646. return new AudioCDReader (cds[index]);
  15647. else
  15648. return 0;
  15649. }
  15650. AudioCDReader::AudioCDReader (const File& volume)
  15651. : AudioFormatReader (0, "CD Audio"),
  15652. volumeDir (volume),
  15653. currentReaderTrack (-1),
  15654. reader (0)
  15655. {
  15656. sampleRate = 44100.0;
  15657. bitsPerSample = 16;
  15658. numChannels = 2;
  15659. usesFloatingPointData = false;
  15660. refreshTrackLengths();
  15661. }
  15662. AudioCDReader::~AudioCDReader()
  15663. {
  15664. }
  15665. static int getTrackNumber (const File& file)
  15666. {
  15667. return file.getFileName()
  15668. .initialSectionContainingOnly (T("0123456789"))
  15669. .getIntValue();
  15670. }
  15671. int AudioCDReader::compareElements (const File& first, const File& second)
  15672. {
  15673. const int firstTrack = getTrackNumber (first);
  15674. const int secondTrack = getTrackNumber (second);
  15675. jassert (firstTrack > 0 && secondTrack > 0);
  15676. return firstTrack - secondTrack;
  15677. }
  15678. void AudioCDReader::refreshTrackLengths()
  15679. {
  15680. tracks.clear();
  15681. trackStartSamples.clear();
  15682. volumeDir.findChildFiles (tracks, File::findFiles | File::ignoreHiddenFiles, false, "*.aiff");
  15683. tracks.sort (*this);
  15684. AiffAudioFormat format;
  15685. int sample = 0;
  15686. for (int i = 0; i < tracks.size(); ++i)
  15687. {
  15688. trackStartSamples.add (sample);
  15689. FileInputStream* const in = tracks.getReference(i).createInputStream();
  15690. if (in != 0)
  15691. {
  15692. ScopedPointer <AudioFormatReader> r (format.createReaderFor (in, true));
  15693. if (r != 0)
  15694. sample += (int) r->lengthInSamples;
  15695. }
  15696. }
  15697. trackStartSamples.add (sample);
  15698. lengthInSamples = sample;
  15699. }
  15700. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  15701. int64 startSampleInFile, int numSamples)
  15702. {
  15703. while (numSamples > 0)
  15704. {
  15705. int track = -1;
  15706. for (int i = 0; i < trackStartSamples.size() - 1; ++i)
  15707. {
  15708. if (startSampleInFile < trackStartSamples.getUnchecked (i + 1))
  15709. {
  15710. track = i;
  15711. break;
  15712. }
  15713. }
  15714. if (track < 0)
  15715. return false;
  15716. if (track != currentReaderTrack)
  15717. {
  15718. reader = 0;
  15719. FileInputStream* const in = tracks [track].createInputStream();
  15720. if (in != 0)
  15721. {
  15722. BufferedInputStream* const bin = new BufferedInputStream (in, 65536, true);
  15723. AiffAudioFormat format;
  15724. reader = format.createReaderFor (bin, true);
  15725. if (reader == 0)
  15726. currentReaderTrack = -1;
  15727. else
  15728. currentReaderTrack = track;
  15729. }
  15730. }
  15731. if (reader == 0)
  15732. return false;
  15733. const int startPos = (int) (startSampleInFile - trackStartSamples.getUnchecked (track));
  15734. const int numAvailable = (int) jmin ((int64) numSamples, reader->lengthInSamples - startPos);
  15735. reader->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer, startPos, numAvailable);
  15736. numSamples -= numAvailable;
  15737. startSampleInFile += numAvailable;
  15738. }
  15739. return true;
  15740. }
  15741. bool AudioCDReader::isCDStillPresent() const
  15742. {
  15743. return volumeDir.exists();
  15744. }
  15745. int AudioCDReader::getNumTracks() const
  15746. {
  15747. return tracks.size();
  15748. }
  15749. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  15750. {
  15751. return trackStartSamples [trackNum];
  15752. }
  15753. bool AudioCDReader::isTrackAudio (int trackNum) const
  15754. {
  15755. return tracks [trackNum] != File::nonexistent;
  15756. }
  15757. void AudioCDReader::enableIndexScanning (bool b)
  15758. {
  15759. // any way to do this on a Mac??
  15760. }
  15761. int AudioCDReader::getLastIndex() const
  15762. {
  15763. return 0;
  15764. }
  15765. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  15766. {
  15767. return Array <int>();
  15768. }
  15769. int AudioCDReader::getCDDBId()
  15770. {
  15771. return 0; //xxx
  15772. }
  15773. #endif
  15774. END_JUCE_NAMESPACE
  15775. /*** End of inlined file: juce_AudioCDReader.cpp ***/
  15776. /*** Start of inlined file: juce_AudioFormat.cpp ***/
  15777. BEGIN_JUCE_NAMESPACE
  15778. AudioFormatReader::AudioFormatReader (InputStream* const in,
  15779. const String& formatName_)
  15780. : sampleRate (0),
  15781. bitsPerSample (0),
  15782. lengthInSamples (0),
  15783. numChannels (0),
  15784. usesFloatingPointData (false),
  15785. input (in),
  15786. formatName (formatName_)
  15787. {
  15788. }
  15789. AudioFormatReader::~AudioFormatReader()
  15790. {
  15791. delete input;
  15792. }
  15793. bool AudioFormatReader::read (int** destSamples,
  15794. int numDestChannels,
  15795. int64 startSampleInSource,
  15796. int numSamplesToRead,
  15797. const bool fillLeftoverChannelsWithCopies)
  15798. {
  15799. jassert (numDestChannels > 0); // you have to actually give this some channels to work with!
  15800. int startOffsetInDestBuffer = 0;
  15801. if (startSampleInSource < 0)
  15802. {
  15803. const int silence = (int) jmin (-startSampleInSource, (int64) numSamplesToRead);
  15804. for (int i = numDestChannels; --i >= 0;)
  15805. if (destSamples[i] != 0)
  15806. zeromem (destSamples[i], sizeof (int) * silence);
  15807. startOffsetInDestBuffer += silence;
  15808. numSamplesToRead -= silence;
  15809. startSampleInSource = 0;
  15810. }
  15811. if (numSamplesToRead <= 0)
  15812. return true;
  15813. if (! readSamples (destSamples, jmin ((int) numChannels, numDestChannels), startOffsetInDestBuffer,
  15814. startSampleInSource, numSamplesToRead))
  15815. return false;
  15816. if (numDestChannels > (int) numChannels)
  15817. {
  15818. if (fillLeftoverChannelsWithCopies)
  15819. {
  15820. int* lastFullChannel = destSamples[0];
  15821. for (int i = numDestChannels; --i > 0;)
  15822. {
  15823. if (destSamples[i] != 0)
  15824. {
  15825. lastFullChannel = destSamples[i];
  15826. break;
  15827. }
  15828. }
  15829. if (lastFullChannel != 0)
  15830. for (int i = numChannels; i < numDestChannels; ++i)
  15831. if (destSamples[i] != 0)
  15832. memcpy (destSamples[i], lastFullChannel, sizeof (int) * numSamplesToRead);
  15833. }
  15834. else
  15835. {
  15836. for (int i = numChannels; i < numDestChannels; ++i)
  15837. if (destSamples[i] != 0)
  15838. zeromem (destSamples[i], sizeof (int) * numSamplesToRead);
  15839. }
  15840. }
  15841. return true;
  15842. }
  15843. static void findAudioBufferMaxMin (const float* const buffer, const int num, float& maxVal, float& minVal) throw()
  15844. {
  15845. float mn = buffer[0];
  15846. float mx = mn;
  15847. for (int i = 1; i < num; ++i)
  15848. {
  15849. const float s = buffer[i];
  15850. if (s > mx) mx = s;
  15851. if (s < mn) mn = s;
  15852. }
  15853. maxVal = mx;
  15854. minVal = mn;
  15855. }
  15856. void AudioFormatReader::readMaxLevels (int64 startSampleInFile,
  15857. int64 numSamples,
  15858. float& lowestLeft, float& highestLeft,
  15859. float& lowestRight, float& highestRight)
  15860. {
  15861. if (numSamples <= 0)
  15862. {
  15863. lowestLeft = 0;
  15864. lowestRight = 0;
  15865. highestLeft = 0;
  15866. highestRight = 0;
  15867. return;
  15868. }
  15869. const int bufferSize = (int) jmin (numSamples, (int64) 4096);
  15870. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  15871. int* tempBuffer[3];
  15872. tempBuffer[0] = (int*) tempSpace.getData();
  15873. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  15874. tempBuffer[2] = 0;
  15875. if (usesFloatingPointData)
  15876. {
  15877. float lmin = 1.0e6f;
  15878. float lmax = -lmin;
  15879. float rmin = lmin;
  15880. float rmax = lmax;
  15881. while (numSamples > 0)
  15882. {
  15883. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  15884. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  15885. numSamples -= numToDo;
  15886. startSampleInFile += numToDo;
  15887. float bufmin, bufmax;
  15888. findAudioBufferMaxMin ((float*) tempBuffer[0], numToDo, bufmax, bufmin);
  15889. lmin = jmin (lmin, bufmin);
  15890. lmax = jmax (lmax, bufmax);
  15891. if (numChannels > 1)
  15892. {
  15893. findAudioBufferMaxMin ((float*) tempBuffer[1], numToDo, bufmax, bufmin);
  15894. rmin = jmin (rmin, bufmin);
  15895. rmax = jmax (rmax, bufmax);
  15896. }
  15897. }
  15898. if (numChannels <= 1)
  15899. {
  15900. rmax = lmax;
  15901. rmin = lmin;
  15902. }
  15903. lowestLeft = lmin;
  15904. highestLeft = lmax;
  15905. lowestRight = rmin;
  15906. highestRight = rmax;
  15907. }
  15908. else
  15909. {
  15910. int lmax = std::numeric_limits<int>::min();
  15911. int lmin = std::numeric_limits<int>::max();
  15912. int rmax = std::numeric_limits<int>::min();
  15913. int rmin = std::numeric_limits<int>::max();
  15914. while (numSamples > 0)
  15915. {
  15916. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  15917. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  15918. numSamples -= numToDo;
  15919. startSampleInFile += numToDo;
  15920. for (int j = numChannels; --j >= 0;)
  15921. {
  15922. int bufMax = std::numeric_limits<int>::min();
  15923. int bufMin = std::numeric_limits<int>::max();
  15924. const int* const b = tempBuffer[j];
  15925. for (int i = 0; i < numToDo; ++i)
  15926. {
  15927. const int samp = b[i];
  15928. if (samp < bufMin)
  15929. bufMin = samp;
  15930. if (samp > bufMax)
  15931. bufMax = samp;
  15932. }
  15933. if (j == 0)
  15934. {
  15935. lmax = jmax (lmax, bufMax);
  15936. lmin = jmin (lmin, bufMin);
  15937. }
  15938. else
  15939. {
  15940. rmax = jmax (rmax, bufMax);
  15941. rmin = jmin (rmin, bufMin);
  15942. }
  15943. }
  15944. }
  15945. if (numChannels <= 1)
  15946. {
  15947. rmax = lmax;
  15948. rmin = lmin;
  15949. }
  15950. lowestLeft = lmin / (float) std::numeric_limits<int>::max();
  15951. highestLeft = lmax / (float) std::numeric_limits<int>::max();
  15952. lowestRight = rmin / (float) std::numeric_limits<int>::max();
  15953. highestRight = rmax / (float) std::numeric_limits<int>::max();
  15954. }
  15955. }
  15956. int64 AudioFormatReader::searchForLevel (int64 startSample,
  15957. int64 numSamplesToSearch,
  15958. const double magnitudeRangeMinimum,
  15959. const double magnitudeRangeMaximum,
  15960. const int minimumConsecutiveSamples)
  15961. {
  15962. if (numSamplesToSearch == 0)
  15963. return -1;
  15964. const int bufferSize = 4096;
  15965. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  15966. int* tempBuffer[3];
  15967. tempBuffer[0] = (int*) tempSpace.getData();
  15968. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  15969. tempBuffer[2] = 0;
  15970. int consecutive = 0;
  15971. int64 firstMatchPos = -1;
  15972. jassert (magnitudeRangeMaximum > magnitudeRangeMinimum);
  15973. const double doubleMin = jlimit (0.0, (double) std::numeric_limits<int>::max(), magnitudeRangeMinimum * std::numeric_limits<int>::max());
  15974. const double doubleMax = jlimit (doubleMin, (double) std::numeric_limits<int>::max(), magnitudeRangeMaximum * std::numeric_limits<int>::max());
  15975. const int intMagnitudeRangeMinimum = roundToInt (doubleMin);
  15976. const int intMagnitudeRangeMaximum = roundToInt (doubleMax);
  15977. while (numSamplesToSearch != 0)
  15978. {
  15979. const int numThisTime = (int) jmin (abs64 (numSamplesToSearch), (int64) bufferSize);
  15980. int64 bufferStart = startSample;
  15981. if (numSamplesToSearch < 0)
  15982. bufferStart -= numThisTime;
  15983. if (bufferStart >= (int) lengthInSamples)
  15984. break;
  15985. read ((int**) tempBuffer, 2, bufferStart, numThisTime, false);
  15986. int num = numThisTime;
  15987. while (--num >= 0)
  15988. {
  15989. if (numSamplesToSearch < 0)
  15990. --startSample;
  15991. bool matches = false;
  15992. const int index = (int) (startSample - bufferStart);
  15993. if (usesFloatingPointData)
  15994. {
  15995. const float sample1 = fabsf (((float*) tempBuffer[0]) [index]);
  15996. if (sample1 >= magnitudeRangeMinimum
  15997. && sample1 <= magnitudeRangeMaximum)
  15998. {
  15999. matches = true;
  16000. }
  16001. else if (numChannels > 1)
  16002. {
  16003. const float sample2 = fabsf (((float*) tempBuffer[1]) [index]);
  16004. matches = (sample2 >= magnitudeRangeMinimum
  16005. && sample2 <= magnitudeRangeMaximum);
  16006. }
  16007. }
  16008. else
  16009. {
  16010. const int sample1 = abs (tempBuffer[0] [index]);
  16011. if (sample1 >= intMagnitudeRangeMinimum
  16012. && sample1 <= intMagnitudeRangeMaximum)
  16013. {
  16014. matches = true;
  16015. }
  16016. else if (numChannels > 1)
  16017. {
  16018. const int sample2 = abs (tempBuffer[1][index]);
  16019. matches = (sample2 >= intMagnitudeRangeMinimum
  16020. && sample2 <= intMagnitudeRangeMaximum);
  16021. }
  16022. }
  16023. if (matches)
  16024. {
  16025. if (firstMatchPos < 0)
  16026. firstMatchPos = startSample;
  16027. if (++consecutive >= minimumConsecutiveSamples)
  16028. {
  16029. if (firstMatchPos < 0 || firstMatchPos >= lengthInSamples)
  16030. return -1;
  16031. return firstMatchPos;
  16032. }
  16033. }
  16034. else
  16035. {
  16036. consecutive = 0;
  16037. firstMatchPos = -1;
  16038. }
  16039. if (numSamplesToSearch > 0)
  16040. ++startSample;
  16041. }
  16042. if (numSamplesToSearch > 0)
  16043. numSamplesToSearch -= numThisTime;
  16044. else
  16045. numSamplesToSearch += numThisTime;
  16046. }
  16047. return -1;
  16048. }
  16049. AudioFormatWriter::AudioFormatWriter (OutputStream* const out,
  16050. const String& formatName_,
  16051. const double rate,
  16052. const unsigned int numChannels_,
  16053. const unsigned int bitsPerSample_)
  16054. : sampleRate (rate),
  16055. numChannels (numChannels_),
  16056. bitsPerSample (bitsPerSample_),
  16057. usesFloatingPointData (false),
  16058. output (out),
  16059. formatName (formatName_)
  16060. {
  16061. }
  16062. AudioFormatWriter::~AudioFormatWriter()
  16063. {
  16064. delete output;
  16065. }
  16066. bool AudioFormatWriter::writeFromAudioReader (AudioFormatReader& reader,
  16067. int64 startSample,
  16068. int64 numSamplesToRead)
  16069. {
  16070. const int bufferSize = 16384;
  16071. const int maxChans = 128;
  16072. AudioSampleBuffer tempBuffer (reader.numChannels, bufferSize);
  16073. int* buffers [maxChans];
  16074. for (int i = maxChans; --i >= 0;)
  16075. buffers[i] = 0;
  16076. if (numSamplesToRead < 0)
  16077. numSamplesToRead = reader.lengthInSamples;
  16078. while (numSamplesToRead > 0)
  16079. {
  16080. const int numToDo = (int) jmin (numSamplesToRead, (int64) bufferSize);
  16081. for (int i = tempBuffer.getNumChannels(); --i >= 0;)
  16082. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16083. if (! reader.read (buffers, maxChans, startSample, numToDo, false))
  16084. return false;
  16085. if (reader.usesFloatingPointData != isFloatingPoint())
  16086. {
  16087. int** bufferChan = buffers;
  16088. while (*bufferChan != 0)
  16089. {
  16090. int* b = *bufferChan++;
  16091. if (isFloatingPoint())
  16092. {
  16093. // int -> float
  16094. const double factor = 1.0 / std::numeric_limits<int>::max();
  16095. for (int i = 0; i < numToDo; ++i)
  16096. ((float*) b)[i] = (float) (factor * b[i]);
  16097. }
  16098. else
  16099. {
  16100. // float -> int
  16101. for (int i = 0; i < numToDo; ++i)
  16102. {
  16103. const double samp = *(const float*) b;
  16104. if (samp <= -1.0)
  16105. *b++ = std::numeric_limits<int>::min();
  16106. else if (samp >= 1.0)
  16107. *b++ = std::numeric_limits<int>::max();
  16108. else
  16109. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  16110. }
  16111. }
  16112. }
  16113. }
  16114. if (! write ((const int**) buffers, numToDo))
  16115. return false;
  16116. numSamplesToRead -= numToDo;
  16117. startSample += numToDo;
  16118. }
  16119. return true;
  16120. }
  16121. bool AudioFormatWriter::writeFromAudioSource (AudioSource& source,
  16122. int numSamplesToRead,
  16123. const int samplesPerBlock)
  16124. {
  16125. const int maxChans = 128;
  16126. AudioSampleBuffer tempBuffer (getNumChannels(), samplesPerBlock);
  16127. int* buffers [maxChans];
  16128. while (numSamplesToRead > 0)
  16129. {
  16130. const int numToDo = jmin (numSamplesToRead, samplesPerBlock);
  16131. AudioSourceChannelInfo info;
  16132. info.buffer = &tempBuffer;
  16133. info.startSample = 0;
  16134. info.numSamples = numToDo;
  16135. info.clearActiveBufferRegion();
  16136. source.getNextAudioBlock (info);
  16137. int i;
  16138. for (i = maxChans; --i >= 0;)
  16139. buffers[i] = 0;
  16140. for (i = tempBuffer.getNumChannels(); --i >= 0;)
  16141. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16142. if (! isFloatingPoint())
  16143. {
  16144. int** bufferChan = buffers;
  16145. while (*bufferChan != 0)
  16146. {
  16147. int* b = *bufferChan++;
  16148. // float -> int
  16149. for (int j = numToDo; --j >= 0;)
  16150. {
  16151. const double samp = *(const float*) b;
  16152. if (samp <= -1.0)
  16153. *b++ = std::numeric_limits<int>::min();
  16154. else if (samp >= 1.0)
  16155. *b++ = std::numeric_limits<int>::max();
  16156. else
  16157. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  16158. }
  16159. }
  16160. }
  16161. if (! write ((const int**) buffers, numToDo))
  16162. return false;
  16163. numSamplesToRead -= numToDo;
  16164. }
  16165. return true;
  16166. }
  16167. AudioFormat::AudioFormat (const String& name,
  16168. const tchar** const extensions)
  16169. : formatName (name),
  16170. fileExtensions (extensions)
  16171. {
  16172. }
  16173. AudioFormat::~AudioFormat()
  16174. {
  16175. }
  16176. const String& AudioFormat::getFormatName() const
  16177. {
  16178. return formatName;
  16179. }
  16180. const StringArray& AudioFormat::getFileExtensions() const
  16181. {
  16182. return fileExtensions;
  16183. }
  16184. bool AudioFormat::canHandleFile (const File& f)
  16185. {
  16186. for (int i = 0; i < fileExtensions.size(); ++i)
  16187. if (f.hasFileExtension (fileExtensions[i]))
  16188. return true;
  16189. return false;
  16190. }
  16191. bool AudioFormat::isCompressed()
  16192. {
  16193. return false;
  16194. }
  16195. const StringArray AudioFormat::getQualityOptions()
  16196. {
  16197. return StringArray();
  16198. }
  16199. END_JUCE_NAMESPACE
  16200. /*** End of inlined file: juce_AudioFormat.cpp ***/
  16201. /*** Start of inlined file: juce_AudioFormatManager.cpp ***/
  16202. BEGIN_JUCE_NAMESPACE
  16203. AudioFormatManager::AudioFormatManager()
  16204. : defaultFormatIndex (0)
  16205. {
  16206. }
  16207. AudioFormatManager::~AudioFormatManager()
  16208. {
  16209. clearFormats();
  16210. clearSingletonInstance();
  16211. }
  16212. juce_ImplementSingleton (AudioFormatManager);
  16213. void AudioFormatManager::registerFormat (AudioFormat* newFormat,
  16214. const bool makeThisTheDefaultFormat)
  16215. {
  16216. jassert (newFormat != 0);
  16217. if (newFormat != 0)
  16218. {
  16219. #ifdef JUCE_DEBUG
  16220. for (int i = getNumKnownFormats(); --i >= 0;)
  16221. {
  16222. if (getKnownFormat (i)->getFormatName() == newFormat->getFormatName())
  16223. {
  16224. jassertfalse // trying to add the same format twice!
  16225. }
  16226. }
  16227. #endif
  16228. if (makeThisTheDefaultFormat)
  16229. defaultFormatIndex = knownFormats.size();
  16230. knownFormats.add (newFormat);
  16231. }
  16232. }
  16233. void AudioFormatManager::registerBasicFormats()
  16234. {
  16235. #if JUCE_MAC
  16236. registerFormat (new AiffAudioFormat(), true);
  16237. registerFormat (new WavAudioFormat(), false);
  16238. #else
  16239. registerFormat (new WavAudioFormat(), true);
  16240. registerFormat (new AiffAudioFormat(), false);
  16241. #endif
  16242. #if JUCE_USE_FLAC
  16243. registerFormat (new FlacAudioFormat(), false);
  16244. #endif
  16245. #if JUCE_USE_OGGVORBIS
  16246. registerFormat (new OggVorbisAudioFormat(), false);
  16247. #endif
  16248. }
  16249. void AudioFormatManager::clearFormats()
  16250. {
  16251. for (int i = getNumKnownFormats(); --i >= 0;)
  16252. delete getKnownFormat(i);
  16253. knownFormats.clear();
  16254. defaultFormatIndex = 0;
  16255. }
  16256. int AudioFormatManager::getNumKnownFormats() const
  16257. {
  16258. return knownFormats.size();
  16259. }
  16260. AudioFormat* AudioFormatManager::getKnownFormat (const int index) const
  16261. {
  16262. return (AudioFormat*) knownFormats [index];
  16263. }
  16264. AudioFormat* AudioFormatManager::getDefaultFormat() const
  16265. {
  16266. return getKnownFormat (defaultFormatIndex);
  16267. }
  16268. AudioFormat* AudioFormatManager::findFormatForFileExtension (const String& fileExtension) const
  16269. {
  16270. String e (fileExtension);
  16271. if (! e.startsWithChar ('.'))
  16272. e = "." + e;
  16273. for (int i = 0; i < getNumKnownFormats(); ++i)
  16274. if (getKnownFormat(i)->getFileExtensions().contains (e, true))
  16275. return getKnownFormat(i);
  16276. return 0;
  16277. }
  16278. const String AudioFormatManager::getWildcardForAllFormats() const
  16279. {
  16280. StringArray allExtensions;
  16281. int i;
  16282. for (i = 0; i < getNumKnownFormats(); ++i)
  16283. allExtensions.addArray (getKnownFormat (i)->getFileExtensions());
  16284. allExtensions.trim();
  16285. allExtensions.removeEmptyStrings();
  16286. String s;
  16287. for (i = 0; i < allExtensions.size(); ++i)
  16288. {
  16289. s << '*';
  16290. if (! allExtensions[i].startsWithChar ('.'))
  16291. s << '.';
  16292. s << allExtensions[i];
  16293. if (i < allExtensions.size() - 1)
  16294. s << ';';
  16295. }
  16296. return s;
  16297. }
  16298. AudioFormatReader* AudioFormatManager::createReaderFor (const File& file)
  16299. {
  16300. // you need to actually register some formats before the manager can
  16301. // use them to open a file!
  16302. jassert (knownFormats.size() > 0);
  16303. for (int i = 0; i < getNumKnownFormats(); ++i)
  16304. {
  16305. AudioFormat* const af = getKnownFormat(i);
  16306. if (af->canHandleFile (file))
  16307. {
  16308. InputStream* const in = file.createInputStream();
  16309. if (in != 0)
  16310. {
  16311. AudioFormatReader* const r = af->createReaderFor (in, true);
  16312. if (r != 0)
  16313. return r;
  16314. }
  16315. }
  16316. }
  16317. return 0;
  16318. }
  16319. AudioFormatReader* AudioFormatManager::createReaderFor (InputStream* audioFileStream)
  16320. {
  16321. // you need to actually register some formats before the manager can
  16322. // use them to open a file!
  16323. jassert (knownFormats.size() > 0);
  16324. ScopedPointer <InputStream> in (audioFileStream);
  16325. if (in != 0)
  16326. {
  16327. const int64 originalStreamPos = in->getPosition();
  16328. for (int i = 0; i < getNumKnownFormats(); ++i)
  16329. {
  16330. AudioFormatReader* const r = getKnownFormat(i)->createReaderFor (in, false);
  16331. if (r != 0)
  16332. {
  16333. in.release();
  16334. return r;
  16335. }
  16336. in->setPosition (originalStreamPos);
  16337. // the stream that is passed-in must be capable of being repositioned so
  16338. // that all the formats can have a go at opening it.
  16339. jassert (in->getPosition() == originalStreamPos);
  16340. }
  16341. }
  16342. return 0;
  16343. }
  16344. END_JUCE_NAMESPACE
  16345. /*** End of inlined file: juce_AudioFormatManager.cpp ***/
  16346. /*** Start of inlined file: juce_AudioSubsectionReader.cpp ***/
  16347. BEGIN_JUCE_NAMESPACE
  16348. AudioSubsectionReader::AudioSubsectionReader (AudioFormatReader* const source_,
  16349. const int64 startSample_,
  16350. const int64 length_,
  16351. const bool deleteSourceWhenDeleted_)
  16352. : AudioFormatReader (0, source_->getFormatName()),
  16353. source (source_),
  16354. startSample (startSample_),
  16355. deleteSourceWhenDeleted (deleteSourceWhenDeleted_)
  16356. {
  16357. length = jmin (jmax ((int64) 0, source->lengthInSamples - startSample), length_);
  16358. sampleRate = source->sampleRate;
  16359. bitsPerSample = source->bitsPerSample;
  16360. lengthInSamples = length;
  16361. numChannels = source->numChannels;
  16362. usesFloatingPointData = source->usesFloatingPointData;
  16363. }
  16364. AudioSubsectionReader::~AudioSubsectionReader()
  16365. {
  16366. if (deleteSourceWhenDeleted)
  16367. delete source;
  16368. }
  16369. bool AudioSubsectionReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  16370. int64 startSampleInFile, int numSamples)
  16371. {
  16372. if (startSampleInFile + numSamples > length)
  16373. {
  16374. for (int i = numDestChannels; --i >= 0;)
  16375. if (destSamples[i] != 0)
  16376. zeromem (destSamples[i], sizeof (int) * numSamples);
  16377. numSamples = jmin (numSamples, (int) (length - startSampleInFile));
  16378. if (numSamples <= 0)
  16379. return true;
  16380. }
  16381. return source->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer,
  16382. startSampleInFile + startSample, numSamples);
  16383. }
  16384. void AudioSubsectionReader::readMaxLevels (int64 startSampleInFile,
  16385. int64 numSamples,
  16386. float& lowestLeft,
  16387. float& highestLeft,
  16388. float& lowestRight,
  16389. float& highestRight)
  16390. {
  16391. startSampleInFile = jmax ((int64) 0, startSampleInFile);
  16392. numSamples = jmax ((int64) 0, jmin (numSamples, length - startSampleInFile));
  16393. source->readMaxLevels (startSampleInFile + startSample,
  16394. numSamples,
  16395. lowestLeft,
  16396. highestLeft,
  16397. lowestRight,
  16398. highestRight);
  16399. }
  16400. END_JUCE_NAMESPACE
  16401. /*** End of inlined file: juce_AudioSubsectionReader.cpp ***/
  16402. /*** Start of inlined file: juce_AudioThumbnail.cpp ***/
  16403. BEGIN_JUCE_NAMESPACE
  16404. const int timeBeforeDeletingReader = 2000;
  16405. struct AudioThumbnailDataFormat
  16406. {
  16407. char thumbnailMagic[4];
  16408. int samplesPerThumbSample;
  16409. int64 totalSamples; // source samples
  16410. int64 numFinishedSamples; // source samples
  16411. int numThumbnailSamples;
  16412. int numChannels;
  16413. int sampleRate;
  16414. char future[16];
  16415. char data[1];
  16416. void swapEndiannessIfNeeded() throw()
  16417. {
  16418. #if JUCE_BIG_ENDIAN
  16419. flip (samplesPerThumbSample);
  16420. flip (totalSamples);
  16421. flip (numFinishedSamples);
  16422. flip (numThumbnailSamples);
  16423. flip (numChannels);
  16424. flip (sampleRate);
  16425. #endif
  16426. }
  16427. private:
  16428. #if JUCE_BIG_ENDIAN
  16429. static void flip (int& n) { n = (int) ByteOrder::swap ((uint32) n); }
  16430. static void flip (int64& n) { n = (int64) ByteOrder::swap ((uint64) n); }
  16431. #endif
  16432. };
  16433. AudioThumbnail::AudioThumbnail (const int orginalSamplesPerThumbnailSample_,
  16434. AudioFormatManager& formatManagerToUse_,
  16435. AudioThumbnailCache& cacheToUse)
  16436. : formatManagerToUse (formatManagerToUse_),
  16437. cache (cacheToUse),
  16438. orginalSamplesPerThumbnailSample (orginalSamplesPerThumbnailSample_)
  16439. {
  16440. clear();
  16441. }
  16442. AudioThumbnail::~AudioThumbnail()
  16443. {
  16444. cache.removeThumbnail (this);
  16445. const ScopedLock sl (readerLock);
  16446. reader = 0;
  16447. }
  16448. void AudioThumbnail::setSource (InputSource* const newSource)
  16449. {
  16450. cache.removeThumbnail (this);
  16451. timerCallback(); // stops the timer and deletes the reader
  16452. source = newSource;
  16453. clear();
  16454. if (newSource != 0
  16455. && ! (cache.loadThumb (*this, newSource->hashCode())
  16456. && isFullyLoaded()))
  16457. {
  16458. {
  16459. const ScopedLock sl (readerLock);
  16460. reader = createReader();
  16461. }
  16462. if (reader != 0)
  16463. {
  16464. initialiseFromAudioFile (*reader);
  16465. cache.addThumbnail (this);
  16466. }
  16467. }
  16468. sendChangeMessage (this);
  16469. }
  16470. bool AudioThumbnail::useTimeSlice()
  16471. {
  16472. const ScopedLock sl (readerLock);
  16473. if (isFullyLoaded())
  16474. {
  16475. if (reader != 0)
  16476. startTimer (timeBeforeDeletingReader);
  16477. cache.removeThumbnail (this);
  16478. return false;
  16479. }
  16480. if (reader == 0)
  16481. reader = createReader();
  16482. if (reader != 0)
  16483. {
  16484. readNextBlockFromAudioFile (*reader);
  16485. stopTimer();
  16486. sendChangeMessage (this);
  16487. const bool justFinished = isFullyLoaded();
  16488. if (justFinished)
  16489. cache.storeThumb (*this, source->hashCode());
  16490. return ! justFinished;
  16491. }
  16492. return false;
  16493. }
  16494. AudioFormatReader* AudioThumbnail::createReader() const
  16495. {
  16496. if (source != 0)
  16497. {
  16498. InputStream* const audioFileStream = source->createInputStream();
  16499. if (audioFileStream != 0)
  16500. return formatManagerToUse.createReaderFor (audioFileStream);
  16501. }
  16502. return 0;
  16503. }
  16504. void AudioThumbnail::timerCallback()
  16505. {
  16506. stopTimer();
  16507. const ScopedLock sl (readerLock);
  16508. reader = 0;
  16509. }
  16510. void AudioThumbnail::clear()
  16511. {
  16512. data.setSize (sizeof (AudioThumbnailDataFormat) + 3);
  16513. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16514. d->thumbnailMagic[0] = 'j';
  16515. d->thumbnailMagic[1] = 'a';
  16516. d->thumbnailMagic[2] = 't';
  16517. d->thumbnailMagic[3] = 'm';
  16518. d->samplesPerThumbSample = orginalSamplesPerThumbnailSample;
  16519. d->totalSamples = 0;
  16520. d->numFinishedSamples = 0;
  16521. d->numThumbnailSamples = 0;
  16522. d->numChannels = 0;
  16523. d->sampleRate = 0;
  16524. numSamplesCached = 0;
  16525. cacheNeedsRefilling = true;
  16526. }
  16527. void AudioThumbnail::loadFrom (InputStream& input)
  16528. {
  16529. const ScopedLock sl (readerLock);
  16530. data.setSize (0);
  16531. input.readIntoMemoryBlock (data);
  16532. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16533. d->swapEndiannessIfNeeded();
  16534. if (! (d->thumbnailMagic[0] == 'j'
  16535. && d->thumbnailMagic[1] == 'a'
  16536. && d->thumbnailMagic[2] == 't'
  16537. && d->thumbnailMagic[3] == 'm'))
  16538. {
  16539. clear();
  16540. }
  16541. numSamplesCached = 0;
  16542. cacheNeedsRefilling = true;
  16543. }
  16544. void AudioThumbnail::saveTo (OutputStream& output) const
  16545. {
  16546. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16547. d->swapEndiannessIfNeeded();
  16548. output.write (data.getData(), (int) data.getSize());
  16549. d->swapEndiannessIfNeeded();
  16550. }
  16551. bool AudioThumbnail::initialiseFromAudioFile (AudioFormatReader& fileReader)
  16552. {
  16553. AudioThumbnailDataFormat* d = (AudioThumbnailDataFormat*) data.getData();
  16554. d->totalSamples = fileReader.lengthInSamples;
  16555. d->numChannels = jmin ((uint32) 2, fileReader.numChannels);
  16556. d->numFinishedSamples = 0;
  16557. d->sampleRate = roundToInt (fileReader.sampleRate);
  16558. d->numThumbnailSamples = (int) (d->totalSamples / d->samplesPerThumbSample) + 1;
  16559. data.setSize (sizeof (AudioThumbnailDataFormat) + 3 + d->numThumbnailSamples * d->numChannels * 2);
  16560. d = (AudioThumbnailDataFormat*) data.getData();
  16561. zeromem (&(d->data[0]), d->numThumbnailSamples * d->numChannels * 2);
  16562. return d->totalSamples > 0;
  16563. }
  16564. bool AudioThumbnail::readNextBlockFromAudioFile (AudioFormatReader& fileReader)
  16565. {
  16566. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16567. if (d->numFinishedSamples < d->totalSamples)
  16568. {
  16569. const int numToDo = (int) jmin ((int64) 65536, d->totalSamples - d->numFinishedSamples);
  16570. generateSection (fileReader,
  16571. d->numFinishedSamples,
  16572. numToDo);
  16573. d->numFinishedSamples += numToDo;
  16574. }
  16575. cacheNeedsRefilling = true;
  16576. return (d->numFinishedSamples < d->totalSamples);
  16577. }
  16578. int AudioThumbnail::getNumChannels() const throw()
  16579. {
  16580. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16581. jassert (d != 0);
  16582. return d->numChannels;
  16583. }
  16584. double AudioThumbnail::getTotalLength() const throw()
  16585. {
  16586. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16587. jassert (d != 0);
  16588. if (d->sampleRate > 0)
  16589. return d->totalSamples / (double)d->sampleRate;
  16590. else
  16591. return 0.0;
  16592. }
  16593. void AudioThumbnail::generateSection (AudioFormatReader& fileReader,
  16594. int64 startSample,
  16595. int numSamples)
  16596. {
  16597. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16598. jassert (d != 0);
  16599. int firstDataPos = (int) (startSample / d->samplesPerThumbSample);
  16600. int lastDataPos = (int) ((startSample + numSamples) / d->samplesPerThumbSample);
  16601. char* l = getChannelData (0);
  16602. char* r = getChannelData (1);
  16603. for (int i = firstDataPos; i < lastDataPos; ++i)
  16604. {
  16605. const int sourceStart = i * d->samplesPerThumbSample;
  16606. const int sourceEnd = sourceStart + d->samplesPerThumbSample;
  16607. float lowestLeft, highestLeft, lowestRight, highestRight;
  16608. fileReader.readMaxLevels (sourceStart,
  16609. sourceEnd - sourceStart,
  16610. lowestLeft,
  16611. highestLeft,
  16612. lowestRight,
  16613. highestRight);
  16614. int n = i * 2;
  16615. if (r != 0)
  16616. {
  16617. l [n] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16618. r [n++] = (char) jlimit (-128.0f, 127.0f, lowestRight * 127.0f);
  16619. l [n] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16620. r [n++] = (char) jlimit (-128.0f, 127.0f, highestRight * 127.0f);
  16621. }
  16622. else
  16623. {
  16624. l [n++] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16625. l [n++] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16626. }
  16627. }
  16628. }
  16629. char* AudioThumbnail::getChannelData (int channel) const
  16630. {
  16631. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16632. jassert (d != 0);
  16633. if (channel >= 0 && channel < d->numChannels)
  16634. return d->data + (channel * 2 * d->numThumbnailSamples);
  16635. return 0;
  16636. }
  16637. bool AudioThumbnail::isFullyLoaded() const throw()
  16638. {
  16639. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16640. jassert (d != 0);
  16641. return d->numFinishedSamples >= d->totalSamples;
  16642. }
  16643. void AudioThumbnail::refillCache (const int numSamples,
  16644. double startTime,
  16645. const double timePerPixel)
  16646. {
  16647. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16648. jassert (d != 0);
  16649. if (numSamples <= 0
  16650. || timePerPixel <= 0.0
  16651. || d->sampleRate <= 0)
  16652. {
  16653. numSamplesCached = 0;
  16654. cacheNeedsRefilling = true;
  16655. return;
  16656. }
  16657. if (numSamples == numSamplesCached
  16658. && numChannelsCached == d->numChannels
  16659. && startTime == cachedStart
  16660. && timePerPixel == cachedTimePerPixel
  16661. && ! cacheNeedsRefilling)
  16662. {
  16663. return;
  16664. }
  16665. numSamplesCached = numSamples;
  16666. numChannelsCached = d->numChannels;
  16667. cachedStart = startTime;
  16668. cachedTimePerPixel = timePerPixel;
  16669. cachedLevels.ensureSize (2 * numChannelsCached * numSamples);
  16670. const bool needExtraDetail = (timePerPixel * d->sampleRate <= d->samplesPerThumbSample);
  16671. const ScopedLock sl (readerLock);
  16672. cacheNeedsRefilling = false;
  16673. if (needExtraDetail && reader == 0)
  16674. reader = createReader();
  16675. if (reader != 0 && timePerPixel * d->sampleRate <= d->samplesPerThumbSample)
  16676. {
  16677. startTimer (timeBeforeDeletingReader);
  16678. char* cacheData = (char*) cachedLevels.getData();
  16679. int sample = roundToInt (startTime * d->sampleRate);
  16680. for (int i = numSamples; --i >= 0;)
  16681. {
  16682. const int nextSample = roundToInt ((startTime + timePerPixel) * d->sampleRate);
  16683. if (sample >= 0)
  16684. {
  16685. if (sample >= reader->lengthInSamples)
  16686. break;
  16687. float lmin, lmax, rmin, rmax;
  16688. reader->readMaxLevels (sample,
  16689. jmax (1, nextSample - sample),
  16690. lmin, lmax, rmin, rmax);
  16691. cacheData[0] = (char) jlimit (-128, 127, roundFloatToInt (lmin * 127.0f));
  16692. cacheData[1] = (char) jlimit (-128, 127, roundFloatToInt (lmax * 127.0f));
  16693. if (numChannelsCached > 1)
  16694. {
  16695. cacheData[2] = (char) jlimit (-128, 127, roundFloatToInt (rmin * 127.0f));
  16696. cacheData[3] = (char) jlimit (-128, 127, roundFloatToInt (rmax * 127.0f));
  16697. }
  16698. cacheData += 2 * numChannelsCached;
  16699. }
  16700. startTime += timePerPixel;
  16701. sample = nextSample;
  16702. }
  16703. }
  16704. else
  16705. {
  16706. for (int channelNum = 0; channelNum < numChannelsCached; ++channelNum)
  16707. {
  16708. char* const channelData = getChannelData (channelNum);
  16709. char* cacheData = ((char*) cachedLevels.getData()) + channelNum * 2;
  16710. const double timeToThumbSampleFactor = d->sampleRate / (double) d->samplesPerThumbSample;
  16711. startTime = cachedStart;
  16712. int sample = roundToInt (startTime * timeToThumbSampleFactor);
  16713. const int numFinished = (int) (d->numFinishedSamples / d->samplesPerThumbSample);
  16714. for (int i = numSamples; --i >= 0;)
  16715. {
  16716. const int nextSample = roundToInt ((startTime + timePerPixel) * timeToThumbSampleFactor);
  16717. if (sample >= 0 && channelData != 0)
  16718. {
  16719. char mx = -128;
  16720. char mn = 127;
  16721. while (sample <= nextSample)
  16722. {
  16723. if (sample >= numFinished)
  16724. break;
  16725. const int n = sample << 1;
  16726. const char sampMin = channelData [n];
  16727. const char sampMax = channelData [n + 1];
  16728. if (sampMin < mn)
  16729. mn = sampMin;
  16730. if (sampMax > mx)
  16731. mx = sampMax;
  16732. ++sample;
  16733. }
  16734. if (mn <= mx)
  16735. {
  16736. cacheData[0] = mn;
  16737. cacheData[1] = mx;
  16738. }
  16739. else
  16740. {
  16741. cacheData[0] = 1;
  16742. cacheData[1] = 0;
  16743. }
  16744. }
  16745. else
  16746. {
  16747. cacheData[0] = 1;
  16748. cacheData[1] = 0;
  16749. }
  16750. cacheData += numChannelsCached * 2;
  16751. startTime += timePerPixel;
  16752. sample = nextSample;
  16753. }
  16754. }
  16755. }
  16756. }
  16757. void AudioThumbnail::drawChannel (Graphics& g,
  16758. int x, int y, int w, int h,
  16759. double startTime,
  16760. double endTime,
  16761. int channelNum,
  16762. const float verticalZoomFactor)
  16763. {
  16764. refillCache (w, startTime, (endTime - startTime) / w);
  16765. if (numSamplesCached >= w
  16766. && channelNum >= 0
  16767. && channelNum < numChannelsCached)
  16768. {
  16769. const float topY = (float) y;
  16770. const float bottomY = topY + h;
  16771. const float midY = topY + h * 0.5f;
  16772. const float vscale = verticalZoomFactor * h / 256.0f;
  16773. const Rectangle<int> clip (g.getClipBounds());
  16774. const int skipLeft = jlimit (0, w, clip.getX() - x);
  16775. w -= skipLeft;
  16776. x += skipLeft;
  16777. const char* cacheData = ((const char*) cachedLevels.getData())
  16778. + (channelNum << 1)
  16779. + skipLeft * (numChannelsCached << 1);
  16780. while (--w >= 0)
  16781. {
  16782. const char mn = cacheData[0];
  16783. const char mx = cacheData[1];
  16784. cacheData += numChannelsCached << 1;
  16785. if (mn <= mx) // if the wrong way round, signifies that the sample's not yet known
  16786. g.drawLine ((float) x, jmax (midY - mx * vscale - 0.3f, topY),
  16787. (float) x, jmin (midY - mn * vscale + 0.3f, bottomY));
  16788. ++x;
  16789. if (x >= clip.getRight())
  16790. break;
  16791. }
  16792. }
  16793. }
  16794. END_JUCE_NAMESPACE
  16795. /*** End of inlined file: juce_AudioThumbnail.cpp ***/
  16796. /*** Start of inlined file: juce_AudioThumbnailCache.cpp ***/
  16797. BEGIN_JUCE_NAMESPACE
  16798. struct ThumbnailCacheEntry
  16799. {
  16800. int64 hash;
  16801. uint32 lastUsed;
  16802. MemoryBlock data;
  16803. juce_UseDebuggingNewOperator
  16804. };
  16805. AudioThumbnailCache::AudioThumbnailCache (const int maxNumThumbsToStore_)
  16806. : TimeSliceThread ("thumb cache"),
  16807. maxNumThumbsToStore (maxNumThumbsToStore_)
  16808. {
  16809. startThread (2);
  16810. }
  16811. AudioThumbnailCache::~AudioThumbnailCache()
  16812. {
  16813. }
  16814. bool AudioThumbnailCache::loadThumb (AudioThumbnail& thumb, const int64 hashCode)
  16815. {
  16816. for (int i = thumbs.size(); --i >= 0;)
  16817. {
  16818. if (thumbs[i]->hash == hashCode)
  16819. {
  16820. MemoryInputStream in ((const char*) thumbs[i]->data.getData(),
  16821. thumbs[i]->data.getSize(),
  16822. false);
  16823. thumb.loadFrom (in);
  16824. thumbs[i]->lastUsed = Time::getMillisecondCounter();
  16825. return true;
  16826. }
  16827. }
  16828. return false;
  16829. }
  16830. void AudioThumbnailCache::storeThumb (const AudioThumbnail& thumb,
  16831. const int64 hashCode)
  16832. {
  16833. MemoryOutputStream out;
  16834. thumb.saveTo (out);
  16835. ThumbnailCacheEntry* te = 0;
  16836. for (int i = thumbs.size(); --i >= 0;)
  16837. {
  16838. if (thumbs[i]->hash == hashCode)
  16839. {
  16840. te = thumbs[i];
  16841. break;
  16842. }
  16843. }
  16844. if (te == 0)
  16845. {
  16846. te = new ThumbnailCacheEntry();
  16847. te->hash = hashCode;
  16848. if (thumbs.size() < maxNumThumbsToStore)
  16849. {
  16850. thumbs.add (te);
  16851. }
  16852. else
  16853. {
  16854. int oldest = 0;
  16855. unsigned int oldestTime = Time::getMillisecondCounter() + 1;
  16856. int i;
  16857. for (i = thumbs.size(); --i >= 0;)
  16858. if (thumbs[i]->lastUsed < oldestTime)
  16859. oldest = i;
  16860. thumbs.set (i, te);
  16861. }
  16862. }
  16863. te->lastUsed = Time::getMillisecondCounter();
  16864. te->data.setSize (0);
  16865. te->data.append (out.getData(), out.getDataSize());
  16866. }
  16867. void AudioThumbnailCache::clear()
  16868. {
  16869. thumbs.clear();
  16870. }
  16871. void AudioThumbnailCache::addThumbnail (AudioThumbnail* const thumb)
  16872. {
  16873. addTimeSliceClient (thumb);
  16874. }
  16875. void AudioThumbnailCache::removeThumbnail (AudioThumbnail* const thumb)
  16876. {
  16877. removeTimeSliceClient (thumb);
  16878. }
  16879. END_JUCE_NAMESPACE
  16880. /*** End of inlined file: juce_AudioThumbnailCache.cpp ***/
  16881. /*** Start of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  16882. #if JUCE_QUICKTIME && ! (JUCE_64BIT || JUCE_IPHONE)
  16883. #if ! JUCE_WINDOWS
  16884. #include <QuickTime/Movies.h>
  16885. #include <QuickTime/QTML.h>
  16886. #include <QuickTime/QuickTimeComponents.h>
  16887. #include <QuickTime/MediaHandlers.h>
  16888. #include <QuickTime/ImageCodec.h>
  16889. #else
  16890. #if JUCE_MSVC
  16891. #pragma warning (push)
  16892. #pragma warning (disable : 4100)
  16893. #endif
  16894. #include <Movies.h>
  16895. #include <QTML.h>
  16896. #include <QuickTimeComponents.h>
  16897. #include <MediaHandlers.h>
  16898. #include <ImageCodec.h>
  16899. #if JUCE_MSVC
  16900. #pragma warning (pop)
  16901. #endif
  16902. #endif
  16903. BEGIN_JUCE_NAMESPACE
  16904. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  16905. static const char* const quickTimeFormatName = "QuickTime file";
  16906. static const tchar* const quickTimeExtensions[] = { T(".mov"), T(".mp3"), T(".mp4"), 0 };
  16907. class QTAudioReader : public AudioFormatReader
  16908. {
  16909. public:
  16910. QTAudioReader (InputStream* const input_, const int trackNum_)
  16911. : AudioFormatReader (input_, TRANS (quickTimeFormatName)),
  16912. ok (false),
  16913. movie (0),
  16914. trackNum (trackNum_),
  16915. lastSampleRead (0),
  16916. lastThreadId (0),
  16917. extractor (0),
  16918. dataHandle (0)
  16919. {
  16920. bufferList.calloc (256, 1);
  16921. #ifdef WIN32
  16922. if (InitializeQTML (0) != noErr)
  16923. return;
  16924. #endif
  16925. if (EnterMovies() != noErr)
  16926. return;
  16927. bool opened = juce_OpenQuickTimeMovieFromStream (input_, movie, dataHandle);
  16928. if (! opened)
  16929. return;
  16930. {
  16931. const int numTracks = GetMovieTrackCount (movie);
  16932. int trackCount = 0;
  16933. for (int i = 1; i <= numTracks; ++i)
  16934. {
  16935. track = GetMovieIndTrack (movie, i);
  16936. media = GetTrackMedia (track);
  16937. OSType mediaType;
  16938. GetMediaHandlerDescription (media, &mediaType, 0, 0);
  16939. if (mediaType == SoundMediaType
  16940. && trackCount++ == trackNum_)
  16941. {
  16942. ok = true;
  16943. break;
  16944. }
  16945. }
  16946. }
  16947. if (! ok)
  16948. return;
  16949. ok = false;
  16950. lengthInSamples = GetMediaDecodeDuration (media);
  16951. usesFloatingPointData = false;
  16952. samplesPerFrame = (int) (GetMediaDecodeDuration (media) / GetMediaSampleCount (media));
  16953. trackUnitsPerFrame = GetMovieTimeScale (movie) * samplesPerFrame
  16954. / GetMediaTimeScale (media);
  16955. OSStatus err = MovieAudioExtractionBegin (movie, 0, &extractor);
  16956. unsigned long output_layout_size;
  16957. err = MovieAudioExtractionGetPropertyInfo (extractor,
  16958. kQTPropertyClass_MovieAudioExtraction_Audio,
  16959. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  16960. 0, &output_layout_size, 0);
  16961. if (err != noErr)
  16962. return;
  16963. HeapBlock <AudioChannelLayout> qt_audio_channel_layout;
  16964. qt_audio_channel_layout.calloc (output_layout_size, 1);
  16965. err = MovieAudioExtractionGetProperty (extractor,
  16966. kQTPropertyClass_MovieAudioExtraction_Audio,
  16967. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  16968. output_layout_size, qt_audio_channel_layout, 0);
  16969. qt_audio_channel_layout[0].mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  16970. err = MovieAudioExtractionSetProperty (extractor,
  16971. kQTPropertyClass_MovieAudioExtraction_Audio,
  16972. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  16973. output_layout_size,
  16974. qt_audio_channel_layout);
  16975. err = MovieAudioExtractionGetProperty (extractor,
  16976. kQTPropertyClass_MovieAudioExtraction_Audio,
  16977. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  16978. sizeof (inputStreamDesc),
  16979. &inputStreamDesc, 0);
  16980. if (err != noErr)
  16981. return;
  16982. inputStreamDesc.mFormatFlags = kAudioFormatFlagIsSignedInteger
  16983. | kAudioFormatFlagIsPacked
  16984. | kAudioFormatFlagsNativeEndian;
  16985. inputStreamDesc.mBitsPerChannel = sizeof (SInt16) * 8;
  16986. inputStreamDesc.mChannelsPerFrame = jmin ((UInt32) 2, inputStreamDesc.mChannelsPerFrame);
  16987. inputStreamDesc.mBytesPerFrame = sizeof (SInt16) * inputStreamDesc.mChannelsPerFrame;
  16988. inputStreamDesc.mBytesPerPacket = inputStreamDesc.mBytesPerFrame;
  16989. err = MovieAudioExtractionSetProperty (extractor,
  16990. kQTPropertyClass_MovieAudioExtraction_Audio,
  16991. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  16992. sizeof (inputStreamDesc),
  16993. &inputStreamDesc);
  16994. if (err != noErr)
  16995. return;
  16996. Boolean allChannelsDiscrete = false;
  16997. err = MovieAudioExtractionSetProperty (extractor,
  16998. kQTPropertyClass_MovieAudioExtraction_Movie,
  16999. kQTMovieAudioExtractionMoviePropertyID_AllChannelsDiscrete,
  17000. sizeof (allChannelsDiscrete),
  17001. &allChannelsDiscrete);
  17002. if (err != noErr)
  17003. return;
  17004. bufferList->mNumberBuffers = 1;
  17005. bufferList->mBuffers[0].mNumberChannels = inputStreamDesc.mChannelsPerFrame;
  17006. bufferList->mBuffers[0].mDataByteSize = (UInt32) (samplesPerFrame * inputStreamDesc.mBytesPerFrame) + 16;
  17007. bufferList->mBuffers[0].mData = malloc (bufferList->mBuffers[0].mDataByteSize);
  17008. sampleRate = inputStreamDesc.mSampleRate;
  17009. bitsPerSample = 16;
  17010. numChannels = inputStreamDesc.mChannelsPerFrame;
  17011. detachThread();
  17012. ok = true;
  17013. }
  17014. ~QTAudioReader()
  17015. {
  17016. if (dataHandle != 0)
  17017. DisposeHandle (dataHandle);
  17018. if (extractor != 0)
  17019. {
  17020. MovieAudioExtractionEnd (extractor);
  17021. extractor = 0;
  17022. }
  17023. checkThreadIsAttached();
  17024. DisposeMovie (movie);
  17025. juce_free (bufferList->mBuffers[0].mData);
  17026. #if JUCE_MAC
  17027. ExitMoviesOnThread ();
  17028. #endif
  17029. }
  17030. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17031. int64 startSampleInFile, int numSamples)
  17032. {
  17033. checkThreadIsAttached();
  17034. while (numSamples > 0)
  17035. {
  17036. if (! loadFrame ((int) startSampleInFile))
  17037. return false;
  17038. const int numToDo = jmin (numSamples, samplesPerFrame);
  17039. for (int j = numDestChannels; --j >= 0;)
  17040. {
  17041. if (destSamples[j] != 0)
  17042. {
  17043. const short* const src = ((const short*) bufferList->mBuffers[0].mData) + j;
  17044. for (int i = 0; i < numToDo; ++i)
  17045. destSamples[j][startOffsetInDestBuffer + i] = src [i << 1] << 16;
  17046. }
  17047. }
  17048. startOffsetInDestBuffer += numToDo;
  17049. startSampleInFile += numToDo;
  17050. numSamples -= numToDo;
  17051. }
  17052. detachThread();
  17053. return true;
  17054. }
  17055. bool loadFrame (const int sampleNum)
  17056. {
  17057. if (lastSampleRead != sampleNum)
  17058. {
  17059. TimeRecord time;
  17060. time.scale = (TimeScale) inputStreamDesc.mSampleRate;
  17061. time.base = 0;
  17062. time.value.hi = 0;
  17063. time.value.lo = (UInt32) sampleNum;
  17064. OSStatus err = MovieAudioExtractionSetProperty (extractor,
  17065. kQTPropertyClass_MovieAudioExtraction_Movie,
  17066. kQTMovieAudioExtractionMoviePropertyID_CurrentTime,
  17067. sizeof (time), &time);
  17068. if (err != noErr)
  17069. return false;
  17070. }
  17071. bufferList->mBuffers[0].mDataByteSize = inputStreamDesc.mBytesPerFrame * samplesPerFrame;
  17072. UInt32 outFlags = 0;
  17073. UInt32 actualNumSamples = samplesPerFrame;
  17074. OSStatus err = MovieAudioExtractionFillBuffer (extractor, &actualNumSamples,
  17075. bufferList, &outFlags);
  17076. lastSampleRead = sampleNum + samplesPerFrame;
  17077. return err == noErr;
  17078. }
  17079. juce_UseDebuggingNewOperator
  17080. bool ok;
  17081. private:
  17082. Movie movie;
  17083. Media media;
  17084. Track track;
  17085. const int trackNum;
  17086. double trackUnitsPerFrame;
  17087. int samplesPerFrame;
  17088. int lastSampleRead;
  17089. Thread::ThreadID lastThreadId;
  17090. MovieAudioExtractionRef extractor;
  17091. AudioStreamBasicDescription inputStreamDesc;
  17092. HeapBlock <AudioBufferList> bufferList;
  17093. Handle dataHandle;
  17094. void checkThreadIsAttached()
  17095. {
  17096. #if JUCE_MAC
  17097. if (Thread::getCurrentThreadId() != lastThreadId)
  17098. EnterMoviesOnThread (0);
  17099. AttachMovieToCurrentThread (movie);
  17100. #endif
  17101. }
  17102. void detachThread()
  17103. {
  17104. #if JUCE_MAC
  17105. DetachMovieFromCurrentThread (movie);
  17106. #endif
  17107. }
  17108. QTAudioReader (const QTAudioReader&);
  17109. QTAudioReader& operator= (const QTAudioReader&);
  17110. };
  17111. QuickTimeAudioFormat::QuickTimeAudioFormat()
  17112. : AudioFormat (TRANS (quickTimeFormatName), (const tchar**) quickTimeExtensions)
  17113. {
  17114. }
  17115. QuickTimeAudioFormat::~QuickTimeAudioFormat()
  17116. {
  17117. }
  17118. const Array <int> QuickTimeAudioFormat::getPossibleSampleRates()
  17119. {
  17120. return Array<int>();
  17121. }
  17122. const Array <int> QuickTimeAudioFormat::getPossibleBitDepths()
  17123. {
  17124. return Array<int>();
  17125. }
  17126. bool QuickTimeAudioFormat::canDoStereo()
  17127. {
  17128. return true;
  17129. }
  17130. bool QuickTimeAudioFormat::canDoMono()
  17131. {
  17132. return true;
  17133. }
  17134. AudioFormatReader* QuickTimeAudioFormat::createReaderFor (InputStream* sourceStream,
  17135. const bool deleteStreamIfOpeningFails)
  17136. {
  17137. ScopedPointer <QTAudioReader> r (new QTAudioReader (sourceStream, 0));
  17138. if (r->ok)
  17139. return r.release();
  17140. if (! deleteStreamIfOpeningFails)
  17141. r->input = 0;
  17142. return 0;
  17143. }
  17144. AudioFormatWriter* QuickTimeAudioFormat::createWriterFor (OutputStream* /*streamToWriteTo*/,
  17145. double /*sampleRateToUse*/,
  17146. unsigned int /*numberOfChannels*/,
  17147. int /*bitsPerSample*/,
  17148. const StringPairArray& /*metadataValues*/,
  17149. int /*qualityOptionIndex*/)
  17150. {
  17151. jassertfalse // not yet implemented!
  17152. return 0;
  17153. }
  17154. END_JUCE_NAMESPACE
  17155. #endif
  17156. /*** End of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  17157. /*** Start of inlined file: juce_WavAudioFormat.cpp ***/
  17158. BEGIN_JUCE_NAMESPACE
  17159. static const char* const wavFormatName = "WAV file";
  17160. static const tchar* const wavExtensions[] = { T(".wav"), T(".bwf"), 0 };
  17161. const tchar* const WavAudioFormat::bwavDescription = T("bwav description");
  17162. const tchar* const WavAudioFormat::bwavOriginator = T("bwav originator");
  17163. const tchar* const WavAudioFormat::bwavOriginatorRef = T("bwav originator ref");
  17164. const tchar* const WavAudioFormat::bwavOriginationDate = T("bwav origination date");
  17165. const tchar* const WavAudioFormat::bwavOriginationTime = T("bwav origination time");
  17166. const tchar* const WavAudioFormat::bwavTimeReference = T("bwav time reference");
  17167. const tchar* const WavAudioFormat::bwavCodingHistory = T("bwav coding history");
  17168. const StringPairArray WavAudioFormat::createBWAVMetadata (const String& description,
  17169. const String& originator,
  17170. const String& originatorRef,
  17171. const Time& date,
  17172. const int64 timeReferenceSamples,
  17173. const String& codingHistory)
  17174. {
  17175. StringPairArray m;
  17176. m.set (bwavDescription, description);
  17177. m.set (bwavOriginator, originator);
  17178. m.set (bwavOriginatorRef, originatorRef);
  17179. m.set (bwavOriginationDate, date.formatted (T("%Y-%m-%d")));
  17180. m.set (bwavOriginationTime, date.formatted (T("%H:%M:%S")));
  17181. m.set (bwavTimeReference, String (timeReferenceSamples));
  17182. m.set (bwavCodingHistory, codingHistory);
  17183. return m;
  17184. }
  17185. #if JUCE_MSVC
  17186. #pragma pack (push, 1)
  17187. #define PACKED
  17188. #elif JUCE_GCC
  17189. #define PACKED __attribute__((packed))
  17190. #else
  17191. #define PACKED
  17192. #endif
  17193. struct BWAVChunk
  17194. {
  17195. char description [256];
  17196. char originator [32];
  17197. char originatorRef [32];
  17198. char originationDate [10];
  17199. char originationTime [8];
  17200. uint32 timeRefLow;
  17201. uint32 timeRefHigh;
  17202. uint16 version;
  17203. uint8 umid[64];
  17204. uint8 reserved[190];
  17205. char codingHistory[1];
  17206. void copyTo (StringPairArray& values) const
  17207. {
  17208. values.set (WavAudioFormat::bwavDescription, String::fromUTF8 (description, 256));
  17209. values.set (WavAudioFormat::bwavOriginator, String::fromUTF8 (originator, 32));
  17210. values.set (WavAudioFormat::bwavOriginatorRef, String::fromUTF8 (originatorRef, 32));
  17211. values.set (WavAudioFormat::bwavOriginationDate, String::fromUTF8 (originationDate, 10));
  17212. values.set (WavAudioFormat::bwavOriginationTime, String::fromUTF8 (originationTime, 8));
  17213. const uint32 timeLow = ByteOrder::swapIfBigEndian (timeRefLow);
  17214. const uint32 timeHigh = ByteOrder::swapIfBigEndian (timeRefHigh);
  17215. const int64 time = (((int64)timeHigh) << 32) + timeLow;
  17216. values.set (WavAudioFormat::bwavTimeReference, String (time));
  17217. values.set (WavAudioFormat::bwavCodingHistory, String::fromUTF8 (codingHistory));
  17218. }
  17219. static MemoryBlock createFrom (const StringPairArray& values)
  17220. {
  17221. const size_t sizeNeeded = sizeof (BWAVChunk) + values [WavAudioFormat::bwavCodingHistory].getNumBytesAsUTF8();
  17222. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17223. data.fillWith (0);
  17224. BWAVChunk* b = (BWAVChunk*) data.getData();
  17225. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17226. // as they get called in the right order..
  17227. values [WavAudioFormat::bwavDescription].copyToUTF8 (b->description, 257);
  17228. values [WavAudioFormat::bwavOriginator].copyToUTF8 (b->originator, 33);
  17229. values [WavAudioFormat::bwavOriginatorRef].copyToUTF8 (b->originatorRef, 33);
  17230. values [WavAudioFormat::bwavOriginationDate].copyToUTF8 (b->originationDate, 11);
  17231. values [WavAudioFormat::bwavOriginationTime].copyToUTF8 (b->originationTime, 9);
  17232. const int64 time = values [WavAudioFormat::bwavTimeReference].getLargeIntValue();
  17233. b->timeRefLow = ByteOrder::swapIfBigEndian ((uint32) (time & 0xffffffff));
  17234. b->timeRefHigh = ByteOrder::swapIfBigEndian ((uint32) (time >> 32));
  17235. values [WavAudioFormat::bwavCodingHistory].copyToUTF8 (b->codingHistory, 0x7fffffff);
  17236. if (b->description[0] != 0
  17237. || b->originator[0] != 0
  17238. || b->originationDate[0] != 0
  17239. || b->originationTime[0] != 0
  17240. || b->codingHistory[0] != 0
  17241. || time != 0)
  17242. {
  17243. return data;
  17244. }
  17245. return MemoryBlock();
  17246. }
  17247. } PACKED;
  17248. struct SMPLChunk
  17249. {
  17250. struct SampleLoop
  17251. {
  17252. uint32 identifier;
  17253. uint32 type;
  17254. uint32 start;
  17255. uint32 end;
  17256. uint32 fraction;
  17257. uint32 playCount;
  17258. } PACKED;
  17259. uint32 manufacturer;
  17260. uint32 product;
  17261. uint32 samplePeriod;
  17262. uint32 midiUnityNote;
  17263. uint32 midiPitchFraction;
  17264. uint32 smpteFormat;
  17265. uint32 smpteOffset;
  17266. uint32 numSampleLoops;
  17267. uint32 samplerData;
  17268. SampleLoop loops[1];
  17269. void copyTo (StringPairArray& values, const int totalSize) const
  17270. {
  17271. values.set ("Manufacturer", String (ByteOrder::swapIfBigEndian (manufacturer)));
  17272. values.set ("Product", String (ByteOrder::swapIfBigEndian (product)));
  17273. values.set ("SamplePeriod", String (ByteOrder::swapIfBigEndian (samplePeriod)));
  17274. values.set ("MidiUnityNote", String (ByteOrder::swapIfBigEndian (midiUnityNote)));
  17275. values.set ("MidiPitchFraction", String (ByteOrder::swapIfBigEndian (midiPitchFraction)));
  17276. values.set ("SmpteFormat", String (ByteOrder::swapIfBigEndian (smpteFormat)));
  17277. values.set ("SmpteOffset", String (ByteOrder::swapIfBigEndian (smpteOffset)));
  17278. values.set ("NumSampleLoops", String (ByteOrder::swapIfBigEndian (numSampleLoops)));
  17279. values.set ("SamplerData", String (ByteOrder::swapIfBigEndian (samplerData)));
  17280. for (uint32 i = 0; i < numSampleLoops; ++i)
  17281. {
  17282. if ((uint8*) (loops + (i + 1)) > ((uint8*) this) + totalSize)
  17283. break;
  17284. const String prefix ("Loop" + String(i));
  17285. values.set (prefix + "Identifier", String (ByteOrder::swapIfBigEndian (loops[i].identifier)));
  17286. values.set (prefix + "Type", String (ByteOrder::swapIfBigEndian (loops[i].type)));
  17287. values.set (prefix + "Start", String (ByteOrder::swapIfBigEndian (loops[i].start)));
  17288. values.set (prefix + "End", String (ByteOrder::swapIfBigEndian (loops[i].end)));
  17289. values.set (prefix + "Fraction", String (ByteOrder::swapIfBigEndian (loops[i].fraction)));
  17290. values.set (prefix + "PlayCount", String (ByteOrder::swapIfBigEndian (loops[i].playCount)));
  17291. }
  17292. }
  17293. static MemoryBlock createFrom (const StringPairArray& values)
  17294. {
  17295. const int numLoops = jmin (64, values.getValue ("NumSampleLoops", "0").getIntValue());
  17296. if (numLoops <= 0)
  17297. return MemoryBlock();
  17298. const size_t sizeNeeded = sizeof (SMPLChunk) + (numLoops - 1) * sizeof (SampleLoop);
  17299. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17300. data.fillWith (0);
  17301. SMPLChunk* s = (SMPLChunk*) data.getData();
  17302. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17303. // as they get called in the right order..
  17304. s->manufacturer = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Manufacturer", "0").getIntValue());
  17305. s->product = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Product", "0").getIntValue());
  17306. s->samplePeriod = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplePeriod", "0").getIntValue());
  17307. s->midiUnityNote = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiUnityNote", "60").getIntValue());
  17308. s->midiPitchFraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiPitchFraction", "0").getIntValue());
  17309. s->smpteFormat = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteFormat", "0").getIntValue());
  17310. s->smpteOffset = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteOffset", "0").getIntValue());
  17311. s->numSampleLoops = ByteOrder::swapIfBigEndian ((uint32) numLoops);
  17312. s->samplerData = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplerData", "0").getIntValue());
  17313. for (int i = 0; i < numLoops; ++i)
  17314. {
  17315. const String prefix ("Loop" + String(i));
  17316. s->loops[i].identifier = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Identifier", "0").getIntValue());
  17317. s->loops[i].type = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Type", "0").getIntValue());
  17318. s->loops[i].start = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Start", "0").getIntValue());
  17319. s->loops[i].end = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "End", "0").getIntValue());
  17320. s->loops[i].fraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Fraction", "0").getIntValue());
  17321. s->loops[i].playCount = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "PlayCount", "0").getIntValue());
  17322. }
  17323. return data;
  17324. }
  17325. } PACKED;
  17326. struct ExtensibleWavSubFormat
  17327. {
  17328. uint32 data1;
  17329. uint16 data2;
  17330. uint16 data3;
  17331. uint8 data4[8];
  17332. } PACKED;
  17333. #if JUCE_MSVC
  17334. #pragma pack (pop)
  17335. #endif
  17336. #undef PACKED
  17337. class WavAudioFormatReader : public AudioFormatReader
  17338. {
  17339. int bytesPerFrame;
  17340. int64 dataChunkStart, dataLength;
  17341. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17342. WavAudioFormatReader (const WavAudioFormatReader&);
  17343. WavAudioFormatReader& operator= (const WavAudioFormatReader&);
  17344. public:
  17345. int64 bwavChunkStart, bwavSize;
  17346. WavAudioFormatReader (InputStream* const in)
  17347. : AudioFormatReader (in, TRANS (wavFormatName)),
  17348. dataLength (0),
  17349. bwavChunkStart (0),
  17350. bwavSize (0)
  17351. {
  17352. if (input->readInt() == chunkName ("RIFF"))
  17353. {
  17354. const uint32 len = (uint32) input->readInt();
  17355. const int64 end = input->getPosition() + len;
  17356. bool hasGotType = false;
  17357. bool hasGotData = false;
  17358. if (input->readInt() == chunkName ("WAVE"))
  17359. {
  17360. while (input->getPosition() < end
  17361. && ! input->isExhausted())
  17362. {
  17363. const int chunkType = input->readInt();
  17364. uint32 length = (uint32) input->readInt();
  17365. const int64 chunkEnd = input->getPosition() + length + (length & 1);
  17366. if (chunkType == chunkName ("fmt "))
  17367. {
  17368. // read the format chunk
  17369. const unsigned short format = input->readShort();
  17370. const short numChans = input->readShort();
  17371. sampleRate = input->readInt();
  17372. const int bytesPerSec = input->readInt();
  17373. numChannels = numChans;
  17374. bytesPerFrame = bytesPerSec / (int)sampleRate;
  17375. bitsPerSample = 8 * bytesPerFrame / numChans;
  17376. if (format == 3)
  17377. {
  17378. usesFloatingPointData = true;
  17379. }
  17380. else if (format == 0xfffe /*WAVE_FORMAT_EXTENSIBLE*/)
  17381. {
  17382. if (length < 40) // too short
  17383. {
  17384. bytesPerFrame = 0;
  17385. }
  17386. else
  17387. {
  17388. input->skipNextBytes (12); // skip over blockAlign, bitsPerSample and speakerPosition mask
  17389. ExtensibleWavSubFormat subFormat;
  17390. subFormat.data1 = input->readInt();
  17391. subFormat.data2 = input->readShort();
  17392. subFormat.data3 = input->readShort();
  17393. input->read (subFormat.data4, sizeof (subFormat.data4));
  17394. const ExtensibleWavSubFormat pcmFormat
  17395. = { 0x00000001, 0x0000, 0x0010, { 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } };
  17396. if (memcmp (&subFormat, &pcmFormat, sizeof (subFormat)) != 0)
  17397. {
  17398. const ExtensibleWavSubFormat ambisonicFormat
  17399. = { 0x00000001, 0x0721, 0x11d3, { 0x86, 0x44, 0xC8, 0xC1, 0xCA, 0x00, 0x00, 0x00 } };
  17400. if (memcmp (&subFormat, &ambisonicFormat, sizeof (subFormat)) != 0)
  17401. bytesPerFrame = 0;
  17402. }
  17403. }
  17404. }
  17405. else if (format != 1)
  17406. {
  17407. bytesPerFrame = 0;
  17408. }
  17409. hasGotType = true;
  17410. }
  17411. else if (chunkType == chunkName ("data"))
  17412. {
  17413. // get the data chunk's position
  17414. dataLength = length;
  17415. dataChunkStart = input->getPosition();
  17416. lengthInSamples = (bytesPerFrame > 0) ? (dataLength / bytesPerFrame) : 0;
  17417. hasGotData = true;
  17418. }
  17419. else if (chunkType == chunkName ("bext"))
  17420. {
  17421. bwavChunkStart = input->getPosition();
  17422. bwavSize = length;
  17423. // Broadcast-wav extension chunk..
  17424. HeapBlock <BWAVChunk> bwav;
  17425. bwav.calloc (jmax ((size_t) length + 1, sizeof (BWAVChunk)), 1);
  17426. input->read (bwav, length);
  17427. bwav->copyTo (metadataValues);
  17428. }
  17429. else if (chunkType == chunkName ("smpl"))
  17430. {
  17431. HeapBlock <SMPLChunk> smpl;
  17432. smpl.calloc (jmax ((size_t) length + 1, sizeof (SMPLChunk)), 1);
  17433. input->read (smpl, length);
  17434. smpl->copyTo (metadataValues, length);
  17435. }
  17436. else if (chunkEnd <= input->getPosition())
  17437. {
  17438. break;
  17439. }
  17440. input->setPosition (chunkEnd);
  17441. }
  17442. }
  17443. }
  17444. }
  17445. ~WavAudioFormatReader()
  17446. {
  17447. }
  17448. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17449. int64 startSampleInFile, int numSamples)
  17450. {
  17451. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  17452. if (samplesAvailable < numSamples)
  17453. {
  17454. for (int i = numDestChannels; --i >= 0;)
  17455. if (destSamples[i] != 0)
  17456. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  17457. numSamples = (int) samplesAvailable;
  17458. }
  17459. if (numSamples <= 0)
  17460. return true;
  17461. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  17462. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  17463. char tempBuffer [tempBufSize];
  17464. while (numSamples > 0)
  17465. {
  17466. int* left = destSamples[0];
  17467. if (left != 0)
  17468. left += startOffsetInDestBuffer;
  17469. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  17470. if (right != 0)
  17471. right += startOffsetInDestBuffer;
  17472. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  17473. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  17474. if (bytesRead < numThisTime * bytesPerFrame)
  17475. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  17476. if (bitsPerSample == 16)
  17477. {
  17478. const short* src = (const short*) tempBuffer;
  17479. if (numChannels > 1)
  17480. {
  17481. if (left == 0)
  17482. {
  17483. for (int i = numThisTime; --i >= 0;)
  17484. {
  17485. ++src;
  17486. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17487. }
  17488. }
  17489. else if (right == 0)
  17490. {
  17491. for (int i = numThisTime; --i >= 0;)
  17492. {
  17493. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17494. ++src;
  17495. }
  17496. }
  17497. else
  17498. {
  17499. for (int i = numThisTime; --i >= 0;)
  17500. {
  17501. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17502. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17503. }
  17504. }
  17505. }
  17506. else
  17507. {
  17508. for (int i = numThisTime; --i >= 0;)
  17509. {
  17510. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17511. }
  17512. }
  17513. }
  17514. else if (bitsPerSample == 24)
  17515. {
  17516. const char* src = (const char*) tempBuffer;
  17517. if (numChannels > 1)
  17518. {
  17519. if (left == 0)
  17520. {
  17521. for (int i = numThisTime; --i >= 0;)
  17522. {
  17523. src += 3;
  17524. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17525. src += 3;
  17526. }
  17527. }
  17528. else if (right == 0)
  17529. {
  17530. for (int i = numThisTime; --i >= 0;)
  17531. {
  17532. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17533. src += 6;
  17534. }
  17535. }
  17536. else
  17537. {
  17538. for (int i = 0; i < numThisTime; ++i)
  17539. {
  17540. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17541. src += 3;
  17542. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17543. src += 3;
  17544. }
  17545. }
  17546. }
  17547. else
  17548. {
  17549. for (int i = 0; i < numThisTime; ++i)
  17550. {
  17551. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17552. src += 3;
  17553. }
  17554. }
  17555. }
  17556. else if (bitsPerSample == 32)
  17557. {
  17558. const unsigned int* src = (const unsigned int*) tempBuffer;
  17559. unsigned int* l = (unsigned int*) left;
  17560. unsigned int* r = (unsigned int*) right;
  17561. if (numChannels > 1)
  17562. {
  17563. if (l == 0)
  17564. {
  17565. for (int i = numThisTime; --i >= 0;)
  17566. {
  17567. ++src;
  17568. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17569. }
  17570. }
  17571. else if (r == 0)
  17572. {
  17573. for (int i = numThisTime; --i >= 0;)
  17574. {
  17575. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17576. ++src;
  17577. }
  17578. }
  17579. else
  17580. {
  17581. for (int i = numThisTime; --i >= 0;)
  17582. {
  17583. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17584. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17585. }
  17586. }
  17587. }
  17588. else
  17589. {
  17590. for (int i = numThisTime; --i >= 0;)
  17591. {
  17592. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17593. }
  17594. }
  17595. left = (int*)l;
  17596. right = (int*)r;
  17597. }
  17598. else if (bitsPerSample == 8)
  17599. {
  17600. const unsigned char* src = (const unsigned char*) tempBuffer;
  17601. if (numChannels > 1)
  17602. {
  17603. if (left == 0)
  17604. {
  17605. for (int i = numThisTime; --i >= 0;)
  17606. {
  17607. ++src;
  17608. *right++ = ((int) *src++ - 128) << 24;
  17609. }
  17610. }
  17611. else if (right == 0)
  17612. {
  17613. for (int i = numThisTime; --i >= 0;)
  17614. {
  17615. *left++ = ((int) *src++ - 128) << 24;
  17616. ++src;
  17617. }
  17618. }
  17619. else
  17620. {
  17621. for (int i = numThisTime; --i >= 0;)
  17622. {
  17623. *left++ = ((int) *src++ - 128) << 24;
  17624. *right++ = ((int) *src++ - 128) << 24;
  17625. }
  17626. }
  17627. }
  17628. else
  17629. {
  17630. for (int i = numThisTime; --i >= 0;)
  17631. {
  17632. *left++ = ((int)*src++ - 128) << 24;
  17633. }
  17634. }
  17635. }
  17636. startOffsetInDestBuffer += numThisTime;
  17637. numSamples -= numThisTime;
  17638. }
  17639. if (numSamples > 0)
  17640. {
  17641. for (int i = numDestChannels; --i >= 0;)
  17642. if (destSamples[i] != 0)
  17643. zeromem (destSamples[i] + startOffsetInDestBuffer,
  17644. sizeof (int) * numSamples);
  17645. }
  17646. return true;
  17647. }
  17648. juce_UseDebuggingNewOperator
  17649. };
  17650. class WavAudioFormatWriter : public AudioFormatWriter
  17651. {
  17652. MemoryBlock tempBlock, bwavChunk, smplChunk;
  17653. uint32 lengthInSamples, bytesWritten;
  17654. int64 headerPosition;
  17655. bool writeFailed;
  17656. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17657. WavAudioFormatWriter (const WavAudioFormatWriter&);
  17658. WavAudioFormatWriter& operator= (const WavAudioFormatWriter&);
  17659. void writeHeader()
  17660. {
  17661. const bool seekedOk = output->setPosition (headerPosition);
  17662. (void) seekedOk;
  17663. // if this fails, you've given it an output stream that can't seek! It needs
  17664. // to be able to seek back to write the header
  17665. jassert (seekedOk);
  17666. const int bytesPerFrame = numChannels * bitsPerSample / 8;
  17667. output->writeInt (chunkName ("RIFF"));
  17668. output->writeInt ((int) (lengthInSamples * bytesPerFrame
  17669. + ((bwavChunk.getSize() > 0) ? (44 + bwavChunk.getSize()) : 36)));
  17670. output->writeInt (chunkName ("WAVE"));
  17671. output->writeInt (chunkName ("fmt "));
  17672. output->writeInt (16);
  17673. output->writeShort ((bitsPerSample < 32) ? (short) 1 /*WAVE_FORMAT_PCM*/
  17674. : (short) 3 /*WAVE_FORMAT_IEEE_FLOAT*/);
  17675. output->writeShort ((short) numChannels);
  17676. output->writeInt ((int) sampleRate);
  17677. output->writeInt (bytesPerFrame * (int) sampleRate);
  17678. output->writeShort ((short) bytesPerFrame);
  17679. output->writeShort ((short) bitsPerSample);
  17680. if (bwavChunk.getSize() > 0)
  17681. {
  17682. output->writeInt (chunkName ("bext"));
  17683. output->writeInt ((int) bwavChunk.getSize());
  17684. output->write (bwavChunk.getData(), (int) bwavChunk.getSize());
  17685. }
  17686. if (smplChunk.getSize() > 0)
  17687. {
  17688. output->writeInt (chunkName ("smpl"));
  17689. output->writeInt ((int) smplChunk.getSize());
  17690. output->write (smplChunk.getData(), (int) smplChunk.getSize());
  17691. }
  17692. output->writeInt (chunkName ("data"));
  17693. output->writeInt (lengthInSamples * bytesPerFrame);
  17694. usesFloatingPointData = (bitsPerSample == 32);
  17695. }
  17696. public:
  17697. WavAudioFormatWriter (OutputStream* const out,
  17698. const double sampleRate_,
  17699. const unsigned int numChannels_,
  17700. const int bits,
  17701. const StringPairArray& metadataValues)
  17702. : AudioFormatWriter (out,
  17703. TRANS (wavFormatName),
  17704. sampleRate_,
  17705. numChannels_,
  17706. bits),
  17707. lengthInSamples (0),
  17708. bytesWritten (0),
  17709. writeFailed (false)
  17710. {
  17711. if (metadataValues.size() > 0)
  17712. {
  17713. bwavChunk = BWAVChunk::createFrom (metadataValues);
  17714. smplChunk = SMPLChunk::createFrom (metadataValues);
  17715. }
  17716. headerPosition = out->getPosition();
  17717. writeHeader();
  17718. }
  17719. ~WavAudioFormatWriter()
  17720. {
  17721. writeHeader();
  17722. }
  17723. bool write (const int** data, int numSamples)
  17724. {
  17725. if (writeFailed)
  17726. return false;
  17727. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  17728. tempBlock.ensureSize (bytes, false);
  17729. char* buffer = (char*) tempBlock.getData();
  17730. const int* left = data[0];
  17731. const int* right = data[1];
  17732. if (right == 0)
  17733. right = left;
  17734. if (bitsPerSample == 16)
  17735. {
  17736. short* b = (short*) buffer;
  17737. if (numChannels > 1)
  17738. {
  17739. for (int i = numSamples; --i >= 0;)
  17740. {
  17741. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17742. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*right++ >> 16));
  17743. }
  17744. }
  17745. else
  17746. {
  17747. for (int i = numSamples; --i >= 0;)
  17748. {
  17749. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17750. }
  17751. }
  17752. }
  17753. else if (bitsPerSample == 24)
  17754. {
  17755. char* b = (char*) buffer;
  17756. if (numChannels > 1)
  17757. {
  17758. for (int i = numSamples; --i >= 0;)
  17759. {
  17760. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17761. b += 3;
  17762. ByteOrder::littleEndian24BitToChars ((*right++) >> 8, b);
  17763. b += 3;
  17764. }
  17765. }
  17766. else
  17767. {
  17768. for (int i = numSamples; --i >= 0;)
  17769. {
  17770. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17771. b += 3;
  17772. }
  17773. }
  17774. }
  17775. else if (bitsPerSample == 32)
  17776. {
  17777. unsigned int* b = (unsigned int*) buffer;
  17778. if (numChannels > 1)
  17779. {
  17780. for (int i = numSamples; --i >= 0;)
  17781. {
  17782. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  17783. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *right++);
  17784. }
  17785. }
  17786. else
  17787. {
  17788. for (int i = numSamples; --i >= 0;)
  17789. {
  17790. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  17791. }
  17792. }
  17793. }
  17794. else if (bitsPerSample == 8)
  17795. {
  17796. unsigned char* b = (unsigned char*) buffer;
  17797. if (numChannels > 1)
  17798. {
  17799. for (int i = numSamples; --i >= 0;)
  17800. {
  17801. *b++ = (unsigned char) (128 + (*left++ >> 24));
  17802. *b++ = (unsigned char) (128 + (*right++ >> 24));
  17803. }
  17804. }
  17805. else
  17806. {
  17807. for (int i = numSamples; --i >= 0;)
  17808. {
  17809. *b++ = (unsigned char) (128 + (*left++ >> 24));
  17810. }
  17811. }
  17812. }
  17813. if (bytesWritten + bytes >= (uint32) 0xfff00000
  17814. || ! output->write (buffer, bytes))
  17815. {
  17816. // failed to write to disk, so let's try writing the header.
  17817. // If it's just run out of disk space, then if it does manage
  17818. // to write the header, we'll still have a useable file..
  17819. writeHeader();
  17820. writeFailed = true;
  17821. return false;
  17822. }
  17823. else
  17824. {
  17825. bytesWritten += bytes;
  17826. lengthInSamples += numSamples;
  17827. return true;
  17828. }
  17829. }
  17830. juce_UseDebuggingNewOperator
  17831. };
  17832. WavAudioFormat::WavAudioFormat()
  17833. : AudioFormat (TRANS (wavFormatName), (const tchar**) wavExtensions)
  17834. {
  17835. }
  17836. WavAudioFormat::~WavAudioFormat()
  17837. {
  17838. }
  17839. const Array <int> WavAudioFormat::getPossibleSampleRates()
  17840. {
  17841. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  17842. return Array <int> (rates);
  17843. }
  17844. const Array <int> WavAudioFormat::getPossibleBitDepths()
  17845. {
  17846. const int depths[] = { 8, 16, 24, 32, 0 };
  17847. return Array <int> (depths);
  17848. }
  17849. bool WavAudioFormat::canDoStereo()
  17850. {
  17851. return true;
  17852. }
  17853. bool WavAudioFormat::canDoMono()
  17854. {
  17855. return true;
  17856. }
  17857. AudioFormatReader* WavAudioFormat::createReaderFor (InputStream* sourceStream,
  17858. const bool deleteStreamIfOpeningFails)
  17859. {
  17860. ScopedPointer <WavAudioFormatReader> r (new WavAudioFormatReader (sourceStream));
  17861. if (r->sampleRate != 0)
  17862. return r.release();
  17863. if (! deleteStreamIfOpeningFails)
  17864. r->input = 0;
  17865. return 0;
  17866. }
  17867. AudioFormatWriter* WavAudioFormat::createWriterFor (OutputStream* out,
  17868. double sampleRate,
  17869. unsigned int numChannels,
  17870. int bitsPerSample,
  17871. const StringPairArray& metadataValues,
  17872. int /*qualityOptionIndex*/)
  17873. {
  17874. if (getPossibleBitDepths().contains (bitsPerSample))
  17875. {
  17876. return new WavAudioFormatWriter (out,
  17877. sampleRate,
  17878. numChannels,
  17879. bitsPerSample,
  17880. metadataValues);
  17881. }
  17882. return 0;
  17883. }
  17884. static bool juce_slowCopyOfWavFileWithNewMetadata (const File& file, const StringPairArray& metadata)
  17885. {
  17886. TemporaryFile tempFile (file);
  17887. WavAudioFormat wav;
  17888. ScopedPointer <AudioFormatReader> reader (wav.createReaderFor (file.createInputStream(), true));
  17889. if (reader != 0)
  17890. {
  17891. ScopedPointer <OutputStream> outStream (tempFile.getFile().createOutputStream());
  17892. if (outStream != 0)
  17893. {
  17894. ScopedPointer <AudioFormatWriter> writer (wav.createWriterFor (outStream, reader->sampleRate,
  17895. reader->numChannels, reader->bitsPerSample,
  17896. metadata, 0));
  17897. if (writer != 0)
  17898. {
  17899. outStream.release();
  17900. bool ok = writer->writeFromAudioReader (*reader, 0, -1);
  17901. writer = 0;
  17902. reader = 0;
  17903. return ok && tempFile.overwriteTargetFileWithTemporary();
  17904. }
  17905. }
  17906. }
  17907. return false;
  17908. }
  17909. bool WavAudioFormat::replaceMetadataInFile (const File& wavFile, const StringPairArray& newMetadata)
  17910. {
  17911. ScopedPointer <WavAudioFormatReader> reader ((WavAudioFormatReader*) createReaderFor (wavFile.createInputStream(), true));
  17912. if (reader != 0)
  17913. {
  17914. const int64 bwavPos = reader->bwavChunkStart;
  17915. const int64 bwavSize = reader->bwavSize;
  17916. reader = 0;
  17917. if (bwavSize > 0)
  17918. {
  17919. MemoryBlock chunk = BWAVChunk::createFrom (newMetadata);
  17920. if (chunk.getSize() <= (size_t) bwavSize)
  17921. {
  17922. // the new one will fit in the space available, so write it directly..
  17923. const int64 oldSize = wavFile.getSize();
  17924. {
  17925. ScopedPointer <FileOutputStream> out (wavFile.createOutputStream());
  17926. out->setPosition (bwavPos);
  17927. out->write (chunk.getData(), (int) chunk.getSize());
  17928. out->setPosition (oldSize);
  17929. }
  17930. jassert (wavFile.getSize() == oldSize);
  17931. return true;
  17932. }
  17933. }
  17934. }
  17935. return juce_slowCopyOfWavFileWithNewMetadata (wavFile, newMetadata);
  17936. }
  17937. END_JUCE_NAMESPACE
  17938. /*** End of inlined file: juce_WavAudioFormat.cpp ***/
  17939. /*** Start of inlined file: juce_AudioFormatReaderSource.cpp ***/
  17940. BEGIN_JUCE_NAMESPACE
  17941. AudioFormatReaderSource::AudioFormatReaderSource (AudioFormatReader* const reader_,
  17942. const bool deleteReaderWhenThisIsDeleted)
  17943. : reader (reader_),
  17944. deleteReader (deleteReaderWhenThisIsDeleted),
  17945. nextPlayPos (0),
  17946. looping (false)
  17947. {
  17948. jassert (reader != 0);
  17949. }
  17950. AudioFormatReaderSource::~AudioFormatReaderSource()
  17951. {
  17952. releaseResources();
  17953. if (deleteReader)
  17954. delete reader;
  17955. }
  17956. void AudioFormatReaderSource::setNextReadPosition (int newPosition)
  17957. {
  17958. nextPlayPos = newPosition;
  17959. }
  17960. void AudioFormatReaderSource::setLooping (const bool shouldLoop) throw()
  17961. {
  17962. looping = shouldLoop;
  17963. }
  17964. int AudioFormatReaderSource::getNextReadPosition() const
  17965. {
  17966. return (looping) ? (nextPlayPos % (int) reader->lengthInSamples)
  17967. : nextPlayPos;
  17968. }
  17969. int AudioFormatReaderSource::getTotalLength() const
  17970. {
  17971. return (int) reader->lengthInSamples;
  17972. }
  17973. void AudioFormatReaderSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  17974. double /*sampleRate*/)
  17975. {
  17976. }
  17977. void AudioFormatReaderSource::releaseResources()
  17978. {
  17979. }
  17980. void AudioFormatReaderSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  17981. {
  17982. if (info.numSamples > 0)
  17983. {
  17984. const int start = nextPlayPos;
  17985. if (looping)
  17986. {
  17987. const int newStart = start % (int) reader->lengthInSamples;
  17988. const int newEnd = (start + info.numSamples) % (int) reader->lengthInSamples;
  17989. if (newEnd > newStart)
  17990. {
  17991. info.buffer->readFromAudioReader (reader,
  17992. info.startSample,
  17993. newEnd - newStart,
  17994. newStart,
  17995. true, true);
  17996. }
  17997. else
  17998. {
  17999. const int endSamps = (int) reader->lengthInSamples - newStart;
  18000. info.buffer->readFromAudioReader (reader,
  18001. info.startSample,
  18002. endSamps,
  18003. newStart,
  18004. true, true);
  18005. info.buffer->readFromAudioReader (reader,
  18006. info.startSample + endSamps,
  18007. newEnd,
  18008. 0,
  18009. true, true);
  18010. }
  18011. nextPlayPos = newEnd;
  18012. }
  18013. else
  18014. {
  18015. info.buffer->readFromAudioReader (reader,
  18016. info.startSample,
  18017. info.numSamples,
  18018. start,
  18019. true, true);
  18020. nextPlayPos += info.numSamples;
  18021. }
  18022. }
  18023. }
  18024. END_JUCE_NAMESPACE
  18025. /*** End of inlined file: juce_AudioFormatReaderSource.cpp ***/
  18026. /*** Start of inlined file: juce_AudioSourcePlayer.cpp ***/
  18027. BEGIN_JUCE_NAMESPACE
  18028. AudioSourcePlayer::AudioSourcePlayer()
  18029. : source (0),
  18030. sampleRate (0),
  18031. bufferSize (0),
  18032. tempBuffer (2, 8),
  18033. lastGain (1.0f),
  18034. gain (1.0f)
  18035. {
  18036. }
  18037. AudioSourcePlayer::~AudioSourcePlayer()
  18038. {
  18039. setSource (0);
  18040. }
  18041. void AudioSourcePlayer::setSource (AudioSource* newSource)
  18042. {
  18043. if (source != newSource)
  18044. {
  18045. AudioSource* const oldSource = source;
  18046. if (newSource != 0 && bufferSize > 0 && sampleRate > 0)
  18047. newSource->prepareToPlay (bufferSize, sampleRate);
  18048. {
  18049. const ScopedLock sl (readLock);
  18050. source = newSource;
  18051. }
  18052. if (oldSource != 0)
  18053. oldSource->releaseResources();
  18054. }
  18055. }
  18056. void AudioSourcePlayer::setGain (const float newGain) throw()
  18057. {
  18058. gain = newGain;
  18059. }
  18060. void AudioSourcePlayer::audioDeviceIOCallback (const float** inputChannelData,
  18061. int totalNumInputChannels,
  18062. float** outputChannelData,
  18063. int totalNumOutputChannels,
  18064. int numSamples)
  18065. {
  18066. // these should have been prepared by audioDeviceAboutToStart()...
  18067. jassert (sampleRate > 0 && bufferSize > 0);
  18068. const ScopedLock sl (readLock);
  18069. if (source != 0)
  18070. {
  18071. AudioSourceChannelInfo info;
  18072. int i, numActiveChans = 0, numInputs = 0, numOutputs = 0;
  18073. // messy stuff needed to compact the channels down into an array
  18074. // of non-zero pointers..
  18075. for (i = 0; i < totalNumInputChannels; ++i)
  18076. {
  18077. if (inputChannelData[i] != 0)
  18078. {
  18079. inputChans [numInputs++] = inputChannelData[i];
  18080. if (numInputs >= numElementsInArray (inputChans))
  18081. break;
  18082. }
  18083. }
  18084. for (i = 0; i < totalNumOutputChannels; ++i)
  18085. {
  18086. if (outputChannelData[i] != 0)
  18087. {
  18088. outputChans [numOutputs++] = outputChannelData[i];
  18089. if (numOutputs >= numElementsInArray (outputChans))
  18090. break;
  18091. }
  18092. }
  18093. if (numInputs > numOutputs)
  18094. {
  18095. // if there aren't enough output channels for the number of
  18096. // inputs, we need to create some temporary extra ones (can't
  18097. // use the input data in case it gets written to)
  18098. tempBuffer.setSize (numInputs - numOutputs, numSamples,
  18099. false, false, true);
  18100. for (i = 0; i < numOutputs; ++i)
  18101. {
  18102. channels[numActiveChans] = outputChans[i];
  18103. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18104. ++numActiveChans;
  18105. }
  18106. for (i = numOutputs; i < numInputs; ++i)
  18107. {
  18108. channels[numActiveChans] = tempBuffer.getSampleData (i - numOutputs, 0);
  18109. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18110. ++numActiveChans;
  18111. }
  18112. }
  18113. else
  18114. {
  18115. for (i = 0; i < numInputs; ++i)
  18116. {
  18117. channels[numActiveChans] = outputChans[i];
  18118. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18119. ++numActiveChans;
  18120. }
  18121. for (i = numInputs; i < numOutputs; ++i)
  18122. {
  18123. channels[numActiveChans] = outputChans[i];
  18124. zeromem (channels[numActiveChans], sizeof (float) * numSamples);
  18125. ++numActiveChans;
  18126. }
  18127. }
  18128. AudioSampleBuffer buffer (channels, numActiveChans, numSamples);
  18129. info.buffer = &buffer;
  18130. info.startSample = 0;
  18131. info.numSamples = numSamples;
  18132. source->getNextAudioBlock (info);
  18133. for (i = info.buffer->getNumChannels(); --i >= 0;)
  18134. info.buffer->applyGainRamp (i, info.startSample, info.numSamples, lastGain, gain);
  18135. lastGain = gain;
  18136. }
  18137. else
  18138. {
  18139. for (int i = 0; i < totalNumOutputChannels; ++i)
  18140. if (outputChannelData[i] != 0)
  18141. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  18142. }
  18143. }
  18144. void AudioSourcePlayer::audioDeviceAboutToStart (AudioIODevice* device)
  18145. {
  18146. sampleRate = device->getCurrentSampleRate();
  18147. bufferSize = device->getCurrentBufferSizeSamples();
  18148. zeromem (channels, sizeof (channels));
  18149. if (source != 0)
  18150. source->prepareToPlay (bufferSize, sampleRate);
  18151. }
  18152. void AudioSourcePlayer::audioDeviceStopped()
  18153. {
  18154. if (source != 0)
  18155. source->releaseResources();
  18156. sampleRate = 0.0;
  18157. bufferSize = 0;
  18158. tempBuffer.setSize (2, 8);
  18159. }
  18160. END_JUCE_NAMESPACE
  18161. /*** End of inlined file: juce_AudioSourcePlayer.cpp ***/
  18162. /*** Start of inlined file: juce_AudioTransportSource.cpp ***/
  18163. BEGIN_JUCE_NAMESPACE
  18164. AudioTransportSource::AudioTransportSource()
  18165. : source (0),
  18166. resamplerSource (0),
  18167. bufferingSource (0),
  18168. positionableSource (0),
  18169. masterSource (0),
  18170. gain (1.0f),
  18171. lastGain (1.0f),
  18172. playing (false),
  18173. stopped (true),
  18174. sampleRate (44100.0),
  18175. sourceSampleRate (0.0),
  18176. blockSize (128),
  18177. readAheadBufferSize (0),
  18178. isPrepared (false),
  18179. inputStreamEOF (false)
  18180. {
  18181. }
  18182. AudioTransportSource::~AudioTransportSource()
  18183. {
  18184. setSource (0);
  18185. releaseResources();
  18186. }
  18187. void AudioTransportSource::setSource (PositionableAudioSource* const newSource,
  18188. int readAheadBufferSize_,
  18189. double sourceSampleRateToCorrectFor)
  18190. {
  18191. if (source == newSource)
  18192. {
  18193. if (source == 0)
  18194. return;
  18195. setSource (0, 0, 0); // deselect and reselect to avoid releasing resources wrongly
  18196. }
  18197. readAheadBufferSize = readAheadBufferSize_;
  18198. sourceSampleRate = sourceSampleRateToCorrectFor;
  18199. ResamplingAudioSource* newResamplerSource = 0;
  18200. BufferingAudioSource* newBufferingSource = 0;
  18201. PositionableAudioSource* newPositionableSource = 0;
  18202. AudioSource* newMasterSource = 0;
  18203. ScopedPointer <ResamplingAudioSource> oldResamplerSource (resamplerSource);
  18204. ScopedPointer <BufferingAudioSource> oldBufferingSource (bufferingSource);
  18205. AudioSource* oldMasterSource = masterSource;
  18206. if (newSource != 0)
  18207. {
  18208. newPositionableSource = newSource;
  18209. if (readAheadBufferSize_ > 0)
  18210. newPositionableSource = newBufferingSource
  18211. = new BufferingAudioSource (newPositionableSource, false, readAheadBufferSize_);
  18212. newPositionableSource->setNextReadPosition (0);
  18213. if (sourceSampleRateToCorrectFor != 0)
  18214. newMasterSource = newResamplerSource
  18215. = new ResamplingAudioSource (newPositionableSource, false);
  18216. else
  18217. newMasterSource = newPositionableSource;
  18218. if (isPrepared)
  18219. {
  18220. if (newResamplerSource != 0 && sourceSampleRate > 0 && sampleRate > 0)
  18221. newResamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18222. newMasterSource->prepareToPlay (blockSize, sampleRate);
  18223. }
  18224. }
  18225. {
  18226. const ScopedLock sl (callbackLock);
  18227. source = newSource;
  18228. resamplerSource = newResamplerSource;
  18229. bufferingSource = newBufferingSource;
  18230. masterSource = newMasterSource;
  18231. positionableSource = newPositionableSource;
  18232. playing = false;
  18233. }
  18234. if (oldMasterSource != 0)
  18235. oldMasterSource->releaseResources();
  18236. }
  18237. void AudioTransportSource::start()
  18238. {
  18239. if ((! playing) && masterSource != 0)
  18240. {
  18241. {
  18242. const ScopedLock sl (callbackLock);
  18243. playing = true;
  18244. stopped = false;
  18245. inputStreamEOF = false;
  18246. }
  18247. sendChangeMessage (this);
  18248. }
  18249. }
  18250. void AudioTransportSource::stop()
  18251. {
  18252. if (playing)
  18253. {
  18254. {
  18255. const ScopedLock sl (callbackLock);
  18256. playing = false;
  18257. }
  18258. int n = 500;
  18259. while (--n >= 0 && ! stopped)
  18260. Thread::sleep (2);
  18261. sendChangeMessage (this);
  18262. }
  18263. }
  18264. void AudioTransportSource::setPosition (double newPosition)
  18265. {
  18266. if (sampleRate > 0.0)
  18267. setNextReadPosition (roundToInt (newPosition * sampleRate));
  18268. }
  18269. double AudioTransportSource::getCurrentPosition() const
  18270. {
  18271. if (sampleRate > 0.0)
  18272. return getNextReadPosition() / sampleRate;
  18273. else
  18274. return 0.0;
  18275. }
  18276. void AudioTransportSource::setNextReadPosition (int newPosition)
  18277. {
  18278. if (positionableSource != 0)
  18279. {
  18280. if (sampleRate > 0 && sourceSampleRate > 0)
  18281. newPosition = roundToInt (newPosition * sourceSampleRate / sampleRate);
  18282. positionableSource->setNextReadPosition (newPosition);
  18283. }
  18284. }
  18285. int AudioTransportSource::getNextReadPosition() const
  18286. {
  18287. if (positionableSource != 0)
  18288. {
  18289. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18290. return roundToInt (positionableSource->getNextReadPosition() * ratio);
  18291. }
  18292. return 0;
  18293. }
  18294. int AudioTransportSource::getTotalLength() const
  18295. {
  18296. const ScopedLock sl (callbackLock);
  18297. if (positionableSource != 0)
  18298. {
  18299. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18300. return roundToInt (positionableSource->getTotalLength() * ratio);
  18301. }
  18302. return 0;
  18303. }
  18304. bool AudioTransportSource::isLooping() const
  18305. {
  18306. const ScopedLock sl (callbackLock);
  18307. return positionableSource != 0
  18308. && positionableSource->isLooping();
  18309. }
  18310. void AudioTransportSource::setGain (const float newGain) throw()
  18311. {
  18312. gain = newGain;
  18313. }
  18314. void AudioTransportSource::prepareToPlay (int samplesPerBlockExpected,
  18315. double sampleRate_)
  18316. {
  18317. const ScopedLock sl (callbackLock);
  18318. sampleRate = sampleRate_;
  18319. blockSize = samplesPerBlockExpected;
  18320. if (masterSource != 0)
  18321. masterSource->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18322. if (resamplerSource != 0 && sourceSampleRate != 0)
  18323. resamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18324. isPrepared = true;
  18325. }
  18326. void AudioTransportSource::releaseResources()
  18327. {
  18328. const ScopedLock sl (callbackLock);
  18329. if (masterSource != 0)
  18330. masterSource->releaseResources();
  18331. isPrepared = false;
  18332. }
  18333. void AudioTransportSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18334. {
  18335. const ScopedLock sl (callbackLock);
  18336. inputStreamEOF = false;
  18337. if (masterSource != 0 && ! stopped)
  18338. {
  18339. masterSource->getNextAudioBlock (info);
  18340. if (! playing)
  18341. {
  18342. // just stopped playing, so fade out the last block..
  18343. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18344. info.buffer->applyGainRamp (i, info.startSample, jmin (256, info.numSamples), 1.0f, 0.0f);
  18345. if (info.numSamples > 256)
  18346. info.buffer->clear (info.startSample + 256, info.numSamples - 256);
  18347. }
  18348. if (positionableSource->getNextReadPosition() > positionableSource->getTotalLength() + 1
  18349. && ! positionableSource->isLooping())
  18350. {
  18351. playing = false;
  18352. inputStreamEOF = true;
  18353. sendChangeMessage (this);
  18354. }
  18355. stopped = ! playing;
  18356. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18357. {
  18358. info.buffer->applyGainRamp (i, info.startSample, info.numSamples,
  18359. lastGain, gain);
  18360. }
  18361. }
  18362. else
  18363. {
  18364. info.clearActiveBufferRegion();
  18365. stopped = true;
  18366. }
  18367. lastGain = gain;
  18368. }
  18369. END_JUCE_NAMESPACE
  18370. /*** End of inlined file: juce_AudioTransportSource.cpp ***/
  18371. /*** Start of inlined file: juce_BufferingAudioSource.cpp ***/
  18372. BEGIN_JUCE_NAMESPACE
  18373. class SharedBufferingAudioSourceThread : public DeletedAtShutdown,
  18374. public Thread,
  18375. private Timer
  18376. {
  18377. public:
  18378. SharedBufferingAudioSourceThread()
  18379. : Thread ("Audio Buffer")
  18380. {
  18381. }
  18382. ~SharedBufferingAudioSourceThread()
  18383. {
  18384. stopThread (10000);
  18385. clearSingletonInstance();
  18386. }
  18387. juce_DeclareSingleton (SharedBufferingAudioSourceThread, false)
  18388. void addSource (BufferingAudioSource* source)
  18389. {
  18390. const ScopedLock sl (lock);
  18391. if (! sources.contains ((void*) source))
  18392. {
  18393. sources.add ((void*) source);
  18394. startThread();
  18395. stopTimer();
  18396. }
  18397. notify();
  18398. }
  18399. void removeSource (BufferingAudioSource* source)
  18400. {
  18401. const ScopedLock sl (lock);
  18402. sources.removeValue ((void*) source);
  18403. if (sources.size() == 0)
  18404. startTimer (5000);
  18405. }
  18406. private:
  18407. VoidArray sources;
  18408. CriticalSection lock;
  18409. void run()
  18410. {
  18411. while (! threadShouldExit())
  18412. {
  18413. bool busy = false;
  18414. for (int i = sources.size(); --i >= 0;)
  18415. {
  18416. if (threadShouldExit())
  18417. return;
  18418. const ScopedLock sl (lock);
  18419. BufferingAudioSource* const b = (BufferingAudioSource*) sources[i];
  18420. if (b != 0 && b->readNextBufferChunk())
  18421. busy = true;
  18422. }
  18423. if (! busy)
  18424. wait (500);
  18425. }
  18426. }
  18427. void timerCallback()
  18428. {
  18429. stopTimer();
  18430. if (sources.size() == 0)
  18431. deleteInstance();
  18432. }
  18433. SharedBufferingAudioSourceThread (const SharedBufferingAudioSourceThread&);
  18434. SharedBufferingAudioSourceThread& operator= (const SharedBufferingAudioSourceThread&);
  18435. };
  18436. juce_ImplementSingleton (SharedBufferingAudioSourceThread)
  18437. BufferingAudioSource::BufferingAudioSource (PositionableAudioSource* source_,
  18438. const bool deleteSourceWhenDeleted_,
  18439. int numberOfSamplesToBuffer_)
  18440. : source (source_),
  18441. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18442. numberOfSamplesToBuffer (jmax (1024, numberOfSamplesToBuffer_)),
  18443. buffer (2, 0),
  18444. bufferValidStart (0),
  18445. bufferValidEnd (0),
  18446. nextPlayPos (0),
  18447. wasSourceLooping (false)
  18448. {
  18449. jassert (source_ != 0);
  18450. jassert (numberOfSamplesToBuffer_ > 1024); // not much point using this class if you're
  18451. // not using a larger buffer..
  18452. }
  18453. BufferingAudioSource::~BufferingAudioSource()
  18454. {
  18455. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18456. if (thread != 0)
  18457. thread->removeSource (this);
  18458. if (deleteSourceWhenDeleted)
  18459. delete source;
  18460. }
  18461. void BufferingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate_)
  18462. {
  18463. source->prepareToPlay (samplesPerBlockExpected, sampleRate_);
  18464. sampleRate = sampleRate_;
  18465. buffer.setSize (2, jmax (samplesPerBlockExpected * 2, numberOfSamplesToBuffer));
  18466. buffer.clear();
  18467. bufferValidStart = 0;
  18468. bufferValidEnd = 0;
  18469. SharedBufferingAudioSourceThread::getInstance()->addSource (this);
  18470. while (bufferValidEnd - bufferValidStart < jmin (((int) sampleRate_) / 4,
  18471. buffer.getNumSamples() / 2))
  18472. {
  18473. SharedBufferingAudioSourceThread::getInstance()->notify();
  18474. Thread::sleep (5);
  18475. }
  18476. }
  18477. void BufferingAudioSource::releaseResources()
  18478. {
  18479. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18480. if (thread != 0)
  18481. thread->removeSource (this);
  18482. buffer.setSize (2, 0);
  18483. source->releaseResources();
  18484. }
  18485. void BufferingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18486. {
  18487. const ScopedLock sl (bufferStartPosLock);
  18488. const int validStart = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos) - nextPlayPos;
  18489. const int validEnd = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos + info.numSamples) - nextPlayPos;
  18490. if (validStart == validEnd)
  18491. {
  18492. // total cache miss
  18493. info.clearActiveBufferRegion();
  18494. }
  18495. else
  18496. {
  18497. if (validStart > 0)
  18498. info.buffer->clear (info.startSample, validStart); // partial cache miss at start
  18499. if (validEnd < info.numSamples)
  18500. info.buffer->clear (info.startSample + validEnd,
  18501. info.numSamples - validEnd); // partial cache miss at end
  18502. if (validStart < validEnd)
  18503. {
  18504. for (int chan = jmin (2, info.buffer->getNumChannels()); --chan >= 0;)
  18505. {
  18506. const int startBufferIndex = (validStart + nextPlayPos) % buffer.getNumSamples();
  18507. const int endBufferIndex = (validEnd + nextPlayPos) % buffer.getNumSamples();
  18508. if (startBufferIndex < endBufferIndex)
  18509. {
  18510. info.buffer->copyFrom (chan, info.startSample + validStart,
  18511. buffer,
  18512. chan, startBufferIndex,
  18513. validEnd - validStart);
  18514. }
  18515. else
  18516. {
  18517. const int initialSize = buffer.getNumSamples() - startBufferIndex;
  18518. info.buffer->copyFrom (chan, info.startSample + validStart,
  18519. buffer,
  18520. chan, startBufferIndex,
  18521. initialSize);
  18522. info.buffer->copyFrom (chan, info.startSample + validStart + initialSize,
  18523. buffer,
  18524. chan, 0,
  18525. (validEnd - validStart) - initialSize);
  18526. }
  18527. }
  18528. }
  18529. nextPlayPos += info.numSamples;
  18530. if (source->isLooping() && nextPlayPos > 0)
  18531. nextPlayPos %= source->getTotalLength();
  18532. }
  18533. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18534. if (thread != 0)
  18535. thread->notify();
  18536. }
  18537. int BufferingAudioSource::getNextReadPosition() const
  18538. {
  18539. return (source->isLooping() && nextPlayPos > 0)
  18540. ? nextPlayPos % source->getTotalLength()
  18541. : nextPlayPos;
  18542. }
  18543. void BufferingAudioSource::setNextReadPosition (int newPosition)
  18544. {
  18545. const ScopedLock sl (bufferStartPosLock);
  18546. nextPlayPos = newPosition;
  18547. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18548. if (thread != 0)
  18549. thread->notify();
  18550. }
  18551. bool BufferingAudioSource::readNextBufferChunk()
  18552. {
  18553. int newBVS, newBVE, sectionToReadStart, sectionToReadEnd;
  18554. {
  18555. const ScopedLock sl (bufferStartPosLock);
  18556. if (wasSourceLooping != isLooping())
  18557. {
  18558. wasSourceLooping = isLooping();
  18559. bufferValidStart = 0;
  18560. bufferValidEnd = 0;
  18561. }
  18562. newBVS = jmax (0, nextPlayPos);
  18563. newBVE = newBVS + buffer.getNumSamples() - 4;
  18564. sectionToReadStart = 0;
  18565. sectionToReadEnd = 0;
  18566. const int maxChunkSize = 2048;
  18567. if (newBVS < bufferValidStart || newBVS >= bufferValidEnd)
  18568. {
  18569. newBVE = jmin (newBVE, newBVS + maxChunkSize);
  18570. sectionToReadStart = newBVS;
  18571. sectionToReadEnd = newBVE;
  18572. bufferValidStart = 0;
  18573. bufferValidEnd = 0;
  18574. }
  18575. else if (abs (newBVS - bufferValidStart) > 512
  18576. || abs (newBVE - bufferValidEnd) > 512)
  18577. {
  18578. newBVE = jmin (newBVE, bufferValidEnd + maxChunkSize);
  18579. sectionToReadStart = bufferValidEnd;
  18580. sectionToReadEnd = newBVE;
  18581. bufferValidStart = newBVS;
  18582. bufferValidEnd = jmin (bufferValidEnd, newBVE);
  18583. }
  18584. }
  18585. if (sectionToReadStart != sectionToReadEnd)
  18586. {
  18587. const int bufferIndexStart = sectionToReadStart % buffer.getNumSamples();
  18588. const int bufferIndexEnd = sectionToReadEnd % buffer.getNumSamples();
  18589. if (bufferIndexStart < bufferIndexEnd)
  18590. {
  18591. readBufferSection (sectionToReadStart,
  18592. sectionToReadEnd - sectionToReadStart,
  18593. bufferIndexStart);
  18594. }
  18595. else
  18596. {
  18597. const int initialSize = buffer.getNumSamples() - bufferIndexStart;
  18598. readBufferSection (sectionToReadStart,
  18599. initialSize,
  18600. bufferIndexStart);
  18601. readBufferSection (sectionToReadStart + initialSize,
  18602. (sectionToReadEnd - sectionToReadStart) - initialSize,
  18603. 0);
  18604. }
  18605. const ScopedLock sl2 (bufferStartPosLock);
  18606. bufferValidStart = newBVS;
  18607. bufferValidEnd = newBVE;
  18608. return true;
  18609. }
  18610. else
  18611. {
  18612. return false;
  18613. }
  18614. }
  18615. void BufferingAudioSource::readBufferSection (int start, int length, int bufferOffset)
  18616. {
  18617. if (source->getNextReadPosition() != start)
  18618. source->setNextReadPosition (start);
  18619. AudioSourceChannelInfo info;
  18620. info.buffer = &buffer;
  18621. info.startSample = bufferOffset;
  18622. info.numSamples = length;
  18623. source->getNextAudioBlock (info);
  18624. }
  18625. END_JUCE_NAMESPACE
  18626. /*** End of inlined file: juce_BufferingAudioSource.cpp ***/
  18627. /*** Start of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  18628. BEGIN_JUCE_NAMESPACE
  18629. ChannelRemappingAudioSource::ChannelRemappingAudioSource (AudioSource* const source_,
  18630. const bool deleteSourceWhenDeleted_)
  18631. : requiredNumberOfChannels (2),
  18632. source (source_),
  18633. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18634. buffer (2, 16)
  18635. {
  18636. remappedInfo.buffer = &buffer;
  18637. remappedInfo.startSample = 0;
  18638. }
  18639. ChannelRemappingAudioSource::~ChannelRemappingAudioSource()
  18640. {
  18641. if (deleteSourceWhenDeleted)
  18642. delete source;
  18643. }
  18644. void ChannelRemappingAudioSource::setNumberOfChannelsToProduce (const int requiredNumberOfChannels_) throw()
  18645. {
  18646. const ScopedLock sl (lock);
  18647. requiredNumberOfChannels = requiredNumberOfChannels_;
  18648. }
  18649. void ChannelRemappingAudioSource::clearAllMappings() throw()
  18650. {
  18651. const ScopedLock sl (lock);
  18652. remappedInputs.clear();
  18653. remappedOutputs.clear();
  18654. }
  18655. void ChannelRemappingAudioSource::setInputChannelMapping (const int destIndex, const int sourceIndex) throw()
  18656. {
  18657. const ScopedLock sl (lock);
  18658. while (remappedInputs.size() < destIndex)
  18659. remappedInputs.add (-1);
  18660. remappedInputs.set (destIndex, sourceIndex);
  18661. }
  18662. void ChannelRemappingAudioSource::setOutputChannelMapping (const int sourceIndex, const int destIndex) throw()
  18663. {
  18664. const ScopedLock sl (lock);
  18665. while (remappedOutputs.size() < sourceIndex)
  18666. remappedOutputs.add (-1);
  18667. remappedOutputs.set (sourceIndex, destIndex);
  18668. }
  18669. int ChannelRemappingAudioSource::getRemappedInputChannel (const int inputChannelIndex) const throw()
  18670. {
  18671. const ScopedLock sl (lock);
  18672. if (inputChannelIndex >= 0 && inputChannelIndex < remappedInputs.size())
  18673. return remappedInputs.getUnchecked (inputChannelIndex);
  18674. return -1;
  18675. }
  18676. int ChannelRemappingAudioSource::getRemappedOutputChannel (const int outputChannelIndex) const throw()
  18677. {
  18678. const ScopedLock sl (lock);
  18679. if (outputChannelIndex >= 0 && outputChannelIndex < remappedOutputs.size())
  18680. return remappedOutputs .getUnchecked (outputChannelIndex);
  18681. return -1;
  18682. }
  18683. void ChannelRemappingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18684. {
  18685. source->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18686. }
  18687. void ChannelRemappingAudioSource::releaseResources()
  18688. {
  18689. source->releaseResources();
  18690. }
  18691. void ChannelRemappingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18692. {
  18693. const ScopedLock sl (lock);
  18694. buffer.setSize (requiredNumberOfChannels, bufferToFill.numSamples, false, false, true);
  18695. const int numChans = bufferToFill.buffer->getNumChannels();
  18696. int i;
  18697. for (i = 0; i < buffer.getNumChannels(); ++i)
  18698. {
  18699. const int remappedChan = getRemappedInputChannel (i);
  18700. if (remappedChan >= 0 && remappedChan < numChans)
  18701. {
  18702. buffer.copyFrom (i, 0, *bufferToFill.buffer,
  18703. remappedChan,
  18704. bufferToFill.startSample,
  18705. bufferToFill.numSamples);
  18706. }
  18707. else
  18708. {
  18709. buffer.clear (i, 0, bufferToFill.numSamples);
  18710. }
  18711. }
  18712. remappedInfo.numSamples = bufferToFill.numSamples;
  18713. source->getNextAudioBlock (remappedInfo);
  18714. bufferToFill.clearActiveBufferRegion();
  18715. for (i = 0; i < requiredNumberOfChannels; ++i)
  18716. {
  18717. const int remappedChan = getRemappedOutputChannel (i);
  18718. if (remappedChan >= 0 && remappedChan < numChans)
  18719. {
  18720. bufferToFill.buffer->addFrom (remappedChan, bufferToFill.startSample,
  18721. buffer, i, 0, bufferToFill.numSamples);
  18722. }
  18723. }
  18724. }
  18725. XmlElement* ChannelRemappingAudioSource::createXml() const throw()
  18726. {
  18727. XmlElement* e = new XmlElement ("MAPPINGS");
  18728. String ins, outs;
  18729. int i;
  18730. const ScopedLock sl (lock);
  18731. for (i = 0; i < remappedInputs.size(); ++i)
  18732. ins << remappedInputs.getUnchecked(i) << ' ';
  18733. for (i = 0; i < remappedOutputs.size(); ++i)
  18734. outs << remappedOutputs.getUnchecked(i) << ' ';
  18735. e->setAttribute ("inputs", ins.trimEnd());
  18736. e->setAttribute ("outputs", outs.trimEnd());
  18737. return e;
  18738. }
  18739. void ChannelRemappingAudioSource::restoreFromXml (const XmlElement& e) throw()
  18740. {
  18741. if (e.hasTagName ("MAPPINGS"))
  18742. {
  18743. const ScopedLock sl (lock);
  18744. clearAllMappings();
  18745. StringArray ins, outs;
  18746. ins.addTokens (e.getStringAttribute ("inputs"), false);
  18747. outs.addTokens (e.getStringAttribute ("outputs"), false);
  18748. int i;
  18749. for (i = 0; i < ins.size(); ++i)
  18750. remappedInputs.add (ins[i].getIntValue());
  18751. for (i = 0; i < outs.size(); ++i)
  18752. remappedOutputs.add (outs[i].getIntValue());
  18753. }
  18754. }
  18755. END_JUCE_NAMESPACE
  18756. /*** End of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  18757. /*** Start of inlined file: juce_IIRFilterAudioSource.cpp ***/
  18758. BEGIN_JUCE_NAMESPACE
  18759. IIRFilterAudioSource::IIRFilterAudioSource (AudioSource* const inputSource,
  18760. const bool deleteInputWhenDeleted_)
  18761. : input (inputSource),
  18762. deleteInputWhenDeleted (deleteInputWhenDeleted_)
  18763. {
  18764. jassert (inputSource != 0);
  18765. for (int i = 2; --i >= 0;)
  18766. iirFilters.add (new IIRFilter());
  18767. }
  18768. IIRFilterAudioSource::~IIRFilterAudioSource()
  18769. {
  18770. if (deleteInputWhenDeleted)
  18771. delete input;
  18772. }
  18773. void IIRFilterAudioSource::setFilterParameters (const IIRFilter& newSettings)
  18774. {
  18775. for (int i = iirFilters.size(); --i >= 0;)
  18776. iirFilters.getUnchecked(i)->copyCoefficientsFrom (newSettings);
  18777. }
  18778. void IIRFilterAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18779. {
  18780. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18781. for (int i = iirFilters.size(); --i >= 0;)
  18782. iirFilters.getUnchecked(i)->reset();
  18783. }
  18784. void IIRFilterAudioSource::releaseResources()
  18785. {
  18786. input->releaseResources();
  18787. }
  18788. void IIRFilterAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18789. {
  18790. input->getNextAudioBlock (bufferToFill);
  18791. const int numChannels = bufferToFill.buffer->getNumChannels();
  18792. while (numChannels > iirFilters.size())
  18793. iirFilters.add (new IIRFilter (*iirFilters.getUnchecked (0)));
  18794. for (int i = 0; i < numChannels; ++i)
  18795. iirFilters.getUnchecked(i)
  18796. ->processSamples (bufferToFill.buffer->getSampleData (i, bufferToFill.startSample),
  18797. bufferToFill.numSamples);
  18798. }
  18799. END_JUCE_NAMESPACE
  18800. /*** End of inlined file: juce_IIRFilterAudioSource.cpp ***/
  18801. /*** Start of inlined file: juce_MixerAudioSource.cpp ***/
  18802. BEGIN_JUCE_NAMESPACE
  18803. MixerAudioSource::MixerAudioSource()
  18804. : tempBuffer (2, 0),
  18805. currentSampleRate (0.0),
  18806. bufferSizeExpected (0)
  18807. {
  18808. }
  18809. MixerAudioSource::~MixerAudioSource()
  18810. {
  18811. removeAllInputs();
  18812. }
  18813. void MixerAudioSource::addInputSource (AudioSource* input, const bool deleteWhenRemoved)
  18814. {
  18815. if (input != 0 && ! inputs.contains (input))
  18816. {
  18817. double localRate;
  18818. int localBufferSize;
  18819. {
  18820. const ScopedLock sl (lock);
  18821. localRate = currentSampleRate;
  18822. localBufferSize = bufferSizeExpected;
  18823. }
  18824. if (localRate != 0.0)
  18825. input->prepareToPlay (localBufferSize, localRate);
  18826. const ScopedLock sl (lock);
  18827. inputsToDelete.setBit (inputs.size(), deleteWhenRemoved);
  18828. inputs.add (input);
  18829. }
  18830. }
  18831. void MixerAudioSource::removeInputSource (AudioSource* input, const bool deleteInput)
  18832. {
  18833. if (input != 0)
  18834. {
  18835. int index;
  18836. {
  18837. const ScopedLock sl (lock);
  18838. index = inputs.indexOf ((void*) input);
  18839. if (index >= 0)
  18840. {
  18841. inputsToDelete.shiftBits (index, 1);
  18842. inputs.remove (index);
  18843. }
  18844. }
  18845. if (index >= 0)
  18846. {
  18847. input->releaseResources();
  18848. if (deleteInput)
  18849. delete input;
  18850. }
  18851. }
  18852. }
  18853. void MixerAudioSource::removeAllInputs()
  18854. {
  18855. VoidArray inputsCopy;
  18856. BigInteger inputsToDeleteCopy;
  18857. {
  18858. const ScopedLock sl (lock);
  18859. inputsCopy = inputs;
  18860. inputsToDeleteCopy = inputsToDelete;
  18861. }
  18862. for (int i = inputsCopy.size(); --i >= 0;)
  18863. if (inputsToDeleteCopy[i])
  18864. delete (AudioSource*) inputsCopy[i];
  18865. }
  18866. void MixerAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18867. {
  18868. tempBuffer.setSize (2, samplesPerBlockExpected);
  18869. const ScopedLock sl (lock);
  18870. currentSampleRate = sampleRate;
  18871. bufferSizeExpected = samplesPerBlockExpected;
  18872. for (int i = inputs.size(); --i >= 0;)
  18873. ((AudioSource*) inputs.getUnchecked(i))->prepareToPlay (samplesPerBlockExpected,
  18874. sampleRate);
  18875. }
  18876. void MixerAudioSource::releaseResources()
  18877. {
  18878. const ScopedLock sl (lock);
  18879. for (int i = inputs.size(); --i >= 0;)
  18880. ((AudioSource*) inputs.getUnchecked(i))->releaseResources();
  18881. tempBuffer.setSize (2, 0);
  18882. currentSampleRate = 0;
  18883. bufferSizeExpected = 0;
  18884. }
  18885. void MixerAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18886. {
  18887. const ScopedLock sl (lock);
  18888. if (inputs.size() > 0)
  18889. {
  18890. ((AudioSource*) inputs.getUnchecked(0))->getNextAudioBlock (info);
  18891. if (inputs.size() > 1)
  18892. {
  18893. tempBuffer.setSize (jmax (1, info.buffer->getNumChannels()),
  18894. info.buffer->getNumSamples());
  18895. AudioSourceChannelInfo info2;
  18896. info2.buffer = &tempBuffer;
  18897. info2.numSamples = info.numSamples;
  18898. info2.startSample = 0;
  18899. for (int i = 1; i < inputs.size(); ++i)
  18900. {
  18901. ((AudioSource*) inputs.getUnchecked(i))->getNextAudioBlock (info2);
  18902. for (int chan = 0; chan < info.buffer->getNumChannels(); ++chan)
  18903. info.buffer->addFrom (chan, info.startSample, tempBuffer, chan, 0, info.numSamples);
  18904. }
  18905. }
  18906. }
  18907. else
  18908. {
  18909. info.clearActiveBufferRegion();
  18910. }
  18911. }
  18912. END_JUCE_NAMESPACE
  18913. /*** End of inlined file: juce_MixerAudioSource.cpp ***/
  18914. /*** Start of inlined file: juce_ResamplingAudioSource.cpp ***/
  18915. BEGIN_JUCE_NAMESPACE
  18916. ResamplingAudioSource::ResamplingAudioSource (AudioSource* const inputSource,
  18917. const bool deleteInputWhenDeleted_)
  18918. : input (inputSource),
  18919. deleteInputWhenDeleted (deleteInputWhenDeleted_),
  18920. ratio (1.0),
  18921. lastRatio (1.0),
  18922. buffer (2, 0),
  18923. sampsInBuffer (0)
  18924. {
  18925. jassert (input != 0);
  18926. }
  18927. ResamplingAudioSource::~ResamplingAudioSource()
  18928. {
  18929. if (deleteInputWhenDeleted)
  18930. delete input;
  18931. }
  18932. void ResamplingAudioSource::setResamplingRatio (const double samplesInPerOutputSample)
  18933. {
  18934. jassert (samplesInPerOutputSample > 0);
  18935. const ScopedLock sl (ratioLock);
  18936. ratio = jmax (0.0, samplesInPerOutputSample);
  18937. }
  18938. void ResamplingAudioSource::prepareToPlay (int samplesPerBlockExpected,
  18939. double sampleRate)
  18940. {
  18941. const ScopedLock sl (ratioLock);
  18942. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18943. buffer.setSize (2, roundToInt (samplesPerBlockExpected * ratio) + 32);
  18944. buffer.clear();
  18945. sampsInBuffer = 0;
  18946. bufferPos = 0;
  18947. subSampleOffset = 0.0;
  18948. createLowPass (ratio);
  18949. resetFilters();
  18950. }
  18951. void ResamplingAudioSource::releaseResources()
  18952. {
  18953. input->releaseResources();
  18954. buffer.setSize (2, 0);
  18955. }
  18956. void ResamplingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18957. {
  18958. const ScopedLock sl (ratioLock);
  18959. if (lastRatio != ratio)
  18960. {
  18961. createLowPass (ratio);
  18962. lastRatio = ratio;
  18963. }
  18964. const int sampsNeeded = roundToInt (info.numSamples * ratio) + 2;
  18965. int bufferSize = buffer.getNumSamples();
  18966. if (bufferSize < sampsNeeded + 8)
  18967. {
  18968. bufferPos %= bufferSize;
  18969. bufferSize = sampsNeeded + 32;
  18970. buffer.setSize (buffer.getNumChannels(), bufferSize, true, true);
  18971. }
  18972. bufferPos %= bufferSize;
  18973. int endOfBufferPos = bufferPos + sampsInBuffer;
  18974. while (sampsNeeded > sampsInBuffer)
  18975. {
  18976. endOfBufferPos %= bufferSize;
  18977. int numToDo = jmin (sampsNeeded - sampsInBuffer,
  18978. bufferSize - endOfBufferPos);
  18979. AudioSourceChannelInfo readInfo;
  18980. readInfo.buffer = &buffer;
  18981. readInfo.numSamples = numToDo;
  18982. readInfo.startSample = endOfBufferPos;
  18983. input->getNextAudioBlock (readInfo);
  18984. if (ratio > 1.0001)
  18985. {
  18986. // for down-sampling, pre-apply the filter..
  18987. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  18988. applyFilter (buffer.getSampleData (i, endOfBufferPos), numToDo, filterStates[i]);
  18989. }
  18990. sampsInBuffer += numToDo;
  18991. endOfBufferPos += numToDo;
  18992. }
  18993. float* dl = info.buffer->getSampleData (0, info.startSample);
  18994. float* dr = (info.buffer->getNumChannels() > 1) ? info.buffer->getSampleData (1, info.startSample) : 0;
  18995. const float* const bl = buffer.getSampleData (0, 0);
  18996. const float* const br = buffer.getSampleData (1, 0);
  18997. int nextPos = (bufferPos + 1) % bufferSize;
  18998. for (int m = info.numSamples; --m >= 0;)
  18999. {
  19000. const float alpha = (float) subSampleOffset;
  19001. const float invAlpha = 1.0f - alpha;
  19002. *dl++ = bl [bufferPos] * invAlpha + bl [nextPos] * alpha;
  19003. if (dr != 0)
  19004. *dr++ = br [bufferPos] * invAlpha + br [nextPos] * alpha;
  19005. subSampleOffset += ratio;
  19006. jassert (sampsInBuffer > 0);
  19007. while (subSampleOffset >= 1.0)
  19008. {
  19009. if (++bufferPos >= bufferSize)
  19010. bufferPos = 0;
  19011. --sampsInBuffer;
  19012. nextPos = (bufferPos + 1) % bufferSize;
  19013. subSampleOffset -= 1.0;
  19014. }
  19015. }
  19016. if (ratio < 0.9999)
  19017. {
  19018. // for up-sampling, apply the filter after transposing..
  19019. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19020. applyFilter (info.buffer->getSampleData (i, info.startSample), info.numSamples, filterStates[i]);
  19021. }
  19022. else if (ratio <= 1.0001)
  19023. {
  19024. // if the filter's not currently being applied, keep it stoked with the last couple of samples to avoid discontinuities
  19025. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19026. {
  19027. const float* const endOfBuffer = info.buffer->getSampleData (i, info.startSample + info.numSamples - 1);
  19028. FilterState& fs = filterStates[i];
  19029. if (info.numSamples > 1)
  19030. {
  19031. fs.y2 = fs.x2 = *(endOfBuffer - 1);
  19032. }
  19033. else
  19034. {
  19035. fs.y2 = fs.y1;
  19036. fs.x2 = fs.x1;
  19037. }
  19038. fs.y1 = fs.x1 = *endOfBuffer;
  19039. }
  19040. }
  19041. jassert (sampsInBuffer >= 0);
  19042. }
  19043. void ResamplingAudioSource::createLowPass (const double frequencyRatio)
  19044. {
  19045. const double proportionalRate = (frequencyRatio > 1.0) ? 0.5 / frequencyRatio
  19046. : 0.5 * frequencyRatio;
  19047. const double n = 1.0 / tan (double_Pi * jmax (0.001, proportionalRate));
  19048. const double nSquared = n * n;
  19049. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  19050. setFilterCoefficients (c1,
  19051. c1 * 2.0f,
  19052. c1,
  19053. 1.0,
  19054. c1 * 2.0 * (1.0 - nSquared),
  19055. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  19056. }
  19057. void ResamplingAudioSource::setFilterCoefficients (double c1, double c2, double c3, double c4, double c5, double c6)
  19058. {
  19059. const double a = 1.0 / c4;
  19060. c1 *= a;
  19061. c2 *= a;
  19062. c3 *= a;
  19063. c5 *= a;
  19064. c6 *= a;
  19065. coefficients[0] = c1;
  19066. coefficients[1] = c2;
  19067. coefficients[2] = c3;
  19068. coefficients[3] = c4;
  19069. coefficients[4] = c5;
  19070. coefficients[5] = c6;
  19071. }
  19072. void ResamplingAudioSource::resetFilters()
  19073. {
  19074. zeromem (filterStates, sizeof (filterStates));
  19075. }
  19076. void ResamplingAudioSource::applyFilter (float* samples, int num, FilterState& fs)
  19077. {
  19078. while (--num >= 0)
  19079. {
  19080. const double in = *samples;
  19081. double out = coefficients[0] * in
  19082. + coefficients[1] * fs.x1
  19083. + coefficients[2] * fs.x2
  19084. - coefficients[4] * fs.y1
  19085. - coefficients[5] * fs.y2;
  19086. #if JUCE_INTEL
  19087. if (! (out < -1.0e-8 || out > 1.0e-8))
  19088. out = 0;
  19089. #endif
  19090. fs.x2 = fs.x1;
  19091. fs.x1 = in;
  19092. fs.y2 = fs.y1;
  19093. fs.y1 = out;
  19094. *samples++ = (float) out;
  19095. }
  19096. }
  19097. END_JUCE_NAMESPACE
  19098. /*** End of inlined file: juce_ResamplingAudioSource.cpp ***/
  19099. /*** Start of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19100. BEGIN_JUCE_NAMESPACE
  19101. ToneGeneratorAudioSource::ToneGeneratorAudioSource()
  19102. : frequency (1000.0),
  19103. sampleRate (44100.0),
  19104. currentPhase (0.0),
  19105. phasePerSample (0.0),
  19106. amplitude (0.5f)
  19107. {
  19108. }
  19109. ToneGeneratorAudioSource::~ToneGeneratorAudioSource()
  19110. {
  19111. }
  19112. void ToneGeneratorAudioSource::setAmplitude (const float newAmplitude)
  19113. {
  19114. amplitude = newAmplitude;
  19115. }
  19116. void ToneGeneratorAudioSource::setFrequency (const double newFrequencyHz)
  19117. {
  19118. frequency = newFrequencyHz;
  19119. phasePerSample = 0.0;
  19120. }
  19121. void ToneGeneratorAudioSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  19122. double sampleRate_)
  19123. {
  19124. currentPhase = 0.0;
  19125. phasePerSample = 0.0;
  19126. sampleRate = sampleRate_;
  19127. }
  19128. void ToneGeneratorAudioSource::releaseResources()
  19129. {
  19130. }
  19131. void ToneGeneratorAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19132. {
  19133. if (phasePerSample == 0.0)
  19134. phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  19135. for (int i = 0; i < info.numSamples; ++i)
  19136. {
  19137. const float sample = amplitude * (float) sin (currentPhase);
  19138. currentPhase += phasePerSample;
  19139. for (int j = info.buffer->getNumChannels(); --j >= 0;)
  19140. *info.buffer->getSampleData (j, info.startSample + i) = sample;
  19141. }
  19142. }
  19143. END_JUCE_NAMESPACE
  19144. /*** End of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19145. /*** Start of inlined file: juce_AudioDeviceManager.cpp ***/
  19146. BEGIN_JUCE_NAMESPACE
  19147. AudioDeviceManager::AudioDeviceSetup::AudioDeviceSetup()
  19148. : sampleRate (0),
  19149. bufferSize (0),
  19150. useDefaultInputChannels (true),
  19151. useDefaultOutputChannels (true)
  19152. {
  19153. }
  19154. bool AudioDeviceManager::AudioDeviceSetup::operator== (const AudioDeviceManager::AudioDeviceSetup& other) const
  19155. {
  19156. return outputDeviceName == other.outputDeviceName
  19157. && inputDeviceName == other.inputDeviceName
  19158. && sampleRate == other.sampleRate
  19159. && bufferSize == other.bufferSize
  19160. && inputChannels == other.inputChannels
  19161. && useDefaultInputChannels == other.useDefaultInputChannels
  19162. && outputChannels == other.outputChannels
  19163. && useDefaultOutputChannels == other.useDefaultOutputChannels;
  19164. }
  19165. AudioDeviceManager::AudioDeviceManager()
  19166. : currentAudioDevice (0),
  19167. numInputChansNeeded (0),
  19168. numOutputChansNeeded (2),
  19169. listNeedsScanning (true),
  19170. useInputNames (false),
  19171. inputLevelMeasurementEnabledCount (0),
  19172. inputLevel (0),
  19173. tempBuffer (2, 2),
  19174. defaultMidiOutput (0),
  19175. cpuUsageMs (0),
  19176. timeToCpuScale (0)
  19177. {
  19178. callbackHandler.owner = this;
  19179. }
  19180. AudioDeviceManager::~AudioDeviceManager()
  19181. {
  19182. currentAudioDevice = 0;
  19183. defaultMidiOutput = 0;
  19184. }
  19185. void AudioDeviceManager::createDeviceTypesIfNeeded()
  19186. {
  19187. if (availableDeviceTypes.size() == 0)
  19188. {
  19189. createAudioDeviceTypes (availableDeviceTypes);
  19190. while (lastDeviceTypeConfigs.size() < availableDeviceTypes.size())
  19191. lastDeviceTypeConfigs.add (new AudioDeviceSetup());
  19192. if (availableDeviceTypes.size() > 0)
  19193. currentDeviceType = availableDeviceTypes.getUnchecked(0)->getTypeName();
  19194. }
  19195. }
  19196. const OwnedArray <AudioIODeviceType>& AudioDeviceManager::getAvailableDeviceTypes()
  19197. {
  19198. scanDevicesIfNeeded();
  19199. return availableDeviceTypes;
  19200. }
  19201. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio();
  19202. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio();
  19203. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI();
  19204. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound();
  19205. AudioIODeviceType* juce_createAudioIODeviceType_ASIO();
  19206. AudioIODeviceType* juce_createAudioIODeviceType_ALSA();
  19207. AudioIODeviceType* juce_createAudioIODeviceType_JACK();
  19208. void AudioDeviceManager::createAudioDeviceTypes (OwnedArray <AudioIODeviceType>& list)
  19209. {
  19210. #if JUCE_WINDOWS
  19211. #if JUCE_WASAPI
  19212. if (SystemStats::getOperatingSystemType() >= SystemStats::WinVista)
  19213. list.add (juce_createAudioIODeviceType_WASAPI());
  19214. #endif
  19215. #if JUCE_DIRECTSOUND
  19216. list.add (juce_createAudioIODeviceType_DirectSound());
  19217. #endif
  19218. #if JUCE_ASIO
  19219. list.add (juce_createAudioIODeviceType_ASIO());
  19220. #endif
  19221. #endif
  19222. #if JUCE_MAC
  19223. list.add (juce_createAudioIODeviceType_CoreAudio());
  19224. #endif
  19225. #if JUCE_IPHONE
  19226. list.add (juce_createAudioIODeviceType_iPhoneAudio());
  19227. #endif
  19228. #if JUCE_LINUX && JUCE_ALSA
  19229. list.add (juce_createAudioIODeviceType_ALSA());
  19230. #endif
  19231. #if JUCE_LINUX && JUCE_JACK
  19232. list.add (juce_createAudioIODeviceType_JACK());
  19233. #endif
  19234. }
  19235. const String AudioDeviceManager::initialise (const int numInputChannelsNeeded,
  19236. const int numOutputChannelsNeeded,
  19237. const XmlElement* const e,
  19238. const bool selectDefaultDeviceOnFailure,
  19239. const String& preferredDefaultDeviceName,
  19240. const AudioDeviceSetup* preferredSetupOptions)
  19241. {
  19242. scanDevicesIfNeeded();
  19243. numInputChansNeeded = numInputChannelsNeeded;
  19244. numOutputChansNeeded = numOutputChannelsNeeded;
  19245. if (e != 0 && e->hasTagName ("DEVICESETUP"))
  19246. {
  19247. lastExplicitSettings = new XmlElement (*e);
  19248. String error;
  19249. AudioDeviceSetup setup;
  19250. if (preferredSetupOptions != 0)
  19251. setup = *preferredSetupOptions;
  19252. if (e->getStringAttribute ("audioDeviceName").isNotEmpty())
  19253. {
  19254. setup.inputDeviceName = setup.outputDeviceName
  19255. = e->getStringAttribute ("audioDeviceName");
  19256. }
  19257. else
  19258. {
  19259. setup.inputDeviceName = e->getStringAttribute ("audioInputDeviceName");
  19260. setup.outputDeviceName = e->getStringAttribute ("audioOutputDeviceName");
  19261. }
  19262. currentDeviceType = e->getStringAttribute ("deviceType");
  19263. if (currentDeviceType.isEmpty())
  19264. {
  19265. AudioIODeviceType* const type = findType (setup.inputDeviceName, setup.outputDeviceName);
  19266. if (type != 0)
  19267. currentDeviceType = type->getTypeName();
  19268. else if (availableDeviceTypes.size() > 0)
  19269. currentDeviceType = availableDeviceTypes[0]->getTypeName();
  19270. }
  19271. setup.bufferSize = e->getIntAttribute ("audioDeviceBufferSize");
  19272. setup.sampleRate = e->getDoubleAttribute ("audioDeviceRate");
  19273. setup.inputChannels.parseString (e->getStringAttribute ("audioDeviceInChans", "11"), 2);
  19274. setup.outputChannels.parseString (e->getStringAttribute ("audioDeviceOutChans", "11"), 2);
  19275. setup.useDefaultInputChannels = ! e->hasAttribute ("audioDeviceInChans");
  19276. setup.useDefaultOutputChannels = ! e->hasAttribute ("audioDeviceOutChans");
  19277. error = setAudioDeviceSetup (setup, true);
  19278. midiInsFromXml.clear();
  19279. forEachXmlChildElementWithTagName (*e, c, "MIDIINPUT")
  19280. midiInsFromXml.add (c->getStringAttribute ("name"));
  19281. const StringArray allMidiIns (MidiInput::getDevices());
  19282. for (int i = allMidiIns.size(); --i >= 0;)
  19283. setMidiInputEnabled (allMidiIns[i], midiInsFromXml.contains (allMidiIns[i]));
  19284. if (error.isNotEmpty() && selectDefaultDeviceOnFailure)
  19285. error = initialise (numInputChannelsNeeded, numOutputChannelsNeeded, 0,
  19286. false, preferredDefaultDeviceName);
  19287. setDefaultMidiOutput (e->getStringAttribute ("defaultMidiOutput"));
  19288. return error;
  19289. }
  19290. else
  19291. {
  19292. AudioDeviceSetup setup;
  19293. if (preferredSetupOptions != 0)
  19294. {
  19295. setup = *preferredSetupOptions;
  19296. }
  19297. else if (preferredDefaultDeviceName.isNotEmpty())
  19298. {
  19299. for (int j = availableDeviceTypes.size(); --j >= 0;)
  19300. {
  19301. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(j);
  19302. StringArray outs (type->getDeviceNames (false));
  19303. int i;
  19304. for (i = 0; i < outs.size(); ++i)
  19305. {
  19306. if (outs[i].matchesWildcard (preferredDefaultDeviceName, true))
  19307. {
  19308. setup.outputDeviceName = outs[i];
  19309. break;
  19310. }
  19311. }
  19312. StringArray ins (type->getDeviceNames (true));
  19313. for (i = 0; i < ins.size(); ++i)
  19314. {
  19315. if (ins[i].matchesWildcard (preferredDefaultDeviceName, true))
  19316. {
  19317. setup.inputDeviceName = ins[i];
  19318. break;
  19319. }
  19320. }
  19321. }
  19322. }
  19323. insertDefaultDeviceNames (setup);
  19324. return setAudioDeviceSetup (setup, false);
  19325. }
  19326. }
  19327. void AudioDeviceManager::insertDefaultDeviceNames (AudioDeviceSetup& setup) const
  19328. {
  19329. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19330. if (type != 0)
  19331. {
  19332. if (setup.outputDeviceName.isEmpty())
  19333. setup.outputDeviceName = type->getDeviceNames (false) [type->getDefaultDeviceIndex (false)];
  19334. if (setup.inputDeviceName.isEmpty())
  19335. setup.inputDeviceName = type->getDeviceNames (true) [type->getDefaultDeviceIndex (true)];
  19336. }
  19337. }
  19338. XmlElement* AudioDeviceManager::createStateXml() const
  19339. {
  19340. return lastExplicitSettings != 0 ? new XmlElement (*lastExplicitSettings) : 0;
  19341. }
  19342. void AudioDeviceManager::scanDevicesIfNeeded()
  19343. {
  19344. if (listNeedsScanning)
  19345. {
  19346. listNeedsScanning = false;
  19347. createDeviceTypesIfNeeded();
  19348. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19349. availableDeviceTypes.getUnchecked(i)->scanForDevices();
  19350. }
  19351. }
  19352. AudioIODeviceType* AudioDeviceManager::findType (const String& inputName, const String& outputName)
  19353. {
  19354. scanDevicesIfNeeded();
  19355. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19356. {
  19357. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(i);
  19358. if ((inputName.isNotEmpty() && type->getDeviceNames (true).contains (inputName, true))
  19359. || (outputName.isNotEmpty() && type->getDeviceNames (false).contains (outputName, true)))
  19360. {
  19361. return type;
  19362. }
  19363. }
  19364. return 0;
  19365. }
  19366. void AudioDeviceManager::getAudioDeviceSetup (AudioDeviceSetup& setup)
  19367. {
  19368. setup = currentSetup;
  19369. }
  19370. void AudioDeviceManager::deleteCurrentDevice()
  19371. {
  19372. currentAudioDevice = 0;
  19373. currentSetup.inputDeviceName = String::empty;
  19374. currentSetup.outputDeviceName = String::empty;
  19375. }
  19376. void AudioDeviceManager::setCurrentAudioDeviceType (const String& type,
  19377. const bool treatAsChosenDevice)
  19378. {
  19379. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19380. {
  19381. if (availableDeviceTypes.getUnchecked(i)->getTypeName() == type
  19382. && currentDeviceType != type)
  19383. {
  19384. currentDeviceType = type;
  19385. AudioDeviceSetup s (*lastDeviceTypeConfigs.getUnchecked(i));
  19386. insertDefaultDeviceNames (s);
  19387. setAudioDeviceSetup (s, treatAsChosenDevice);
  19388. sendChangeMessage (this);
  19389. break;
  19390. }
  19391. }
  19392. }
  19393. AudioIODeviceType* AudioDeviceManager::getCurrentDeviceTypeObject() const
  19394. {
  19395. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19396. if (availableDeviceTypes[i]->getTypeName() == currentDeviceType)
  19397. return availableDeviceTypes[i];
  19398. return availableDeviceTypes[0];
  19399. }
  19400. const String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup,
  19401. const bool treatAsChosenDevice)
  19402. {
  19403. jassert (&newSetup != &currentSetup); // this will have no effect
  19404. if (newSetup == currentSetup && currentAudioDevice != 0)
  19405. return String::empty;
  19406. if (! (newSetup == currentSetup))
  19407. sendChangeMessage (this);
  19408. stopDevice();
  19409. const String newInputDeviceName (numInputChansNeeded == 0 ? String::empty : newSetup.inputDeviceName);
  19410. const String newOutputDeviceName (numOutputChansNeeded == 0 ? String::empty : newSetup.outputDeviceName);
  19411. String error;
  19412. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19413. if (type == 0 || (newInputDeviceName.isEmpty() && newOutputDeviceName.isEmpty()))
  19414. {
  19415. deleteCurrentDevice();
  19416. if (treatAsChosenDevice)
  19417. updateXml();
  19418. return String::empty;
  19419. }
  19420. if (currentSetup.inputDeviceName != newInputDeviceName
  19421. || currentSetup.outputDeviceName != newOutputDeviceName
  19422. || currentAudioDevice == 0)
  19423. {
  19424. deleteCurrentDevice();
  19425. scanDevicesIfNeeded();
  19426. if (newOutputDeviceName.isNotEmpty()
  19427. && ! type->getDeviceNames (false).contains (newOutputDeviceName))
  19428. {
  19429. return "No such device: " + newOutputDeviceName;
  19430. }
  19431. if (newInputDeviceName.isNotEmpty()
  19432. && ! type->getDeviceNames (true).contains (newInputDeviceName))
  19433. {
  19434. return "No such device: " + newInputDeviceName;
  19435. }
  19436. currentAudioDevice = type->createDevice (newOutputDeviceName, newInputDeviceName);
  19437. if (currentAudioDevice == 0)
  19438. 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!";
  19439. else
  19440. error = currentAudioDevice->getLastError();
  19441. if (error.isNotEmpty())
  19442. {
  19443. deleteCurrentDevice();
  19444. return error;
  19445. }
  19446. if (newSetup.useDefaultInputChannels)
  19447. {
  19448. inputChannels.clear();
  19449. inputChannels.setRange (0, numInputChansNeeded, true);
  19450. }
  19451. if (newSetup.useDefaultOutputChannels)
  19452. {
  19453. outputChannels.clear();
  19454. outputChannels.setRange (0, numOutputChansNeeded, true);
  19455. }
  19456. if (newInputDeviceName.isEmpty())
  19457. inputChannels.clear();
  19458. if (newOutputDeviceName.isEmpty())
  19459. outputChannels.clear();
  19460. }
  19461. if (! newSetup.useDefaultInputChannels)
  19462. inputChannels = newSetup.inputChannels;
  19463. if (! newSetup.useDefaultOutputChannels)
  19464. outputChannels = newSetup.outputChannels;
  19465. currentSetup = newSetup;
  19466. currentSetup.sampleRate = chooseBestSampleRate (newSetup.sampleRate);
  19467. error = currentAudioDevice->open (inputChannels,
  19468. outputChannels,
  19469. currentSetup.sampleRate,
  19470. currentSetup.bufferSize);
  19471. if (error.isEmpty())
  19472. {
  19473. currentDeviceType = currentAudioDevice->getTypeName();
  19474. currentAudioDevice->start (&callbackHandler);
  19475. currentSetup.sampleRate = currentAudioDevice->getCurrentSampleRate();
  19476. currentSetup.bufferSize = currentAudioDevice->getCurrentBufferSizeSamples();
  19477. currentSetup.inputChannels = currentAudioDevice->getActiveInputChannels();
  19478. currentSetup.outputChannels = currentAudioDevice->getActiveOutputChannels();
  19479. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19480. if (availableDeviceTypes.getUnchecked (i)->getTypeName() == currentDeviceType)
  19481. *(lastDeviceTypeConfigs.getUnchecked (i)) = currentSetup;
  19482. if (treatAsChosenDevice)
  19483. updateXml();
  19484. }
  19485. else
  19486. {
  19487. deleteCurrentDevice();
  19488. }
  19489. return error;
  19490. }
  19491. double AudioDeviceManager::chooseBestSampleRate (double rate) const
  19492. {
  19493. jassert (currentAudioDevice != 0);
  19494. if (rate > 0)
  19495. {
  19496. bool ok = false;
  19497. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19498. {
  19499. const double sr = currentAudioDevice->getSampleRate (i);
  19500. if (sr == rate)
  19501. ok = true;
  19502. }
  19503. if (! ok)
  19504. rate = 0;
  19505. }
  19506. if (rate == 0)
  19507. {
  19508. double lowestAbove44 = 0.0;
  19509. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19510. {
  19511. const double sr = currentAudioDevice->getSampleRate (i);
  19512. if (sr >= 44100.0 && (lowestAbove44 == 0 || sr < lowestAbove44))
  19513. lowestAbove44 = sr;
  19514. }
  19515. if (lowestAbove44 == 0.0)
  19516. rate = currentAudioDevice->getSampleRate (0);
  19517. else
  19518. rate = lowestAbove44;
  19519. }
  19520. return rate;
  19521. }
  19522. void AudioDeviceManager::stopDevice()
  19523. {
  19524. if (currentAudioDevice != 0)
  19525. currentAudioDevice->stop();
  19526. testSound = 0;
  19527. }
  19528. void AudioDeviceManager::closeAudioDevice()
  19529. {
  19530. stopDevice();
  19531. currentAudioDevice = 0;
  19532. }
  19533. void AudioDeviceManager::restartLastAudioDevice()
  19534. {
  19535. if (currentAudioDevice == 0)
  19536. {
  19537. if (currentSetup.inputDeviceName.isEmpty()
  19538. && currentSetup.outputDeviceName.isEmpty())
  19539. {
  19540. // This method will only reload the last device that was running
  19541. // before closeAudioDevice() was called - you need to actually open
  19542. // one first, with setAudioDevice().
  19543. jassertfalse
  19544. return;
  19545. }
  19546. AudioDeviceSetup s (currentSetup);
  19547. setAudioDeviceSetup (s, false);
  19548. }
  19549. }
  19550. void AudioDeviceManager::updateXml()
  19551. {
  19552. lastExplicitSettings = new XmlElement ("DEVICESETUP");
  19553. lastExplicitSettings->setAttribute ("deviceType", currentDeviceType);
  19554. lastExplicitSettings->setAttribute ("audioOutputDeviceName", currentSetup.outputDeviceName);
  19555. lastExplicitSettings->setAttribute ("audioInputDeviceName", currentSetup.inputDeviceName);
  19556. if (currentAudioDevice != 0)
  19557. {
  19558. lastExplicitSettings->setAttribute ("audioDeviceRate", currentAudioDevice->getCurrentSampleRate());
  19559. if (currentAudioDevice->getDefaultBufferSize() != currentAudioDevice->getCurrentBufferSizeSamples())
  19560. lastExplicitSettings->setAttribute ("audioDeviceBufferSize", currentAudioDevice->getCurrentBufferSizeSamples());
  19561. if (! currentSetup.useDefaultInputChannels)
  19562. lastExplicitSettings->setAttribute ("audioDeviceInChans", currentSetup.inputChannels.toString (2));
  19563. if (! currentSetup.useDefaultOutputChannels)
  19564. lastExplicitSettings->setAttribute ("audioDeviceOutChans", currentSetup.outputChannels.toString (2));
  19565. }
  19566. for (int i = 0; i < enabledMidiInputs.size(); ++i)
  19567. {
  19568. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19569. m->setAttribute ("name", enabledMidiInputs[i]->getName());
  19570. }
  19571. if (midiInsFromXml.size() > 0)
  19572. {
  19573. // Add any midi devices that have been enabled before, but which aren't currently
  19574. // open because the device has been disconnected.
  19575. const StringArray availableMidiDevices (MidiInput::getDevices());
  19576. for (int i = 0; i < midiInsFromXml.size(); ++i)
  19577. {
  19578. if (! availableMidiDevices.contains (midiInsFromXml[i], true))
  19579. {
  19580. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19581. m->setAttribute ("name", midiInsFromXml[i]);
  19582. }
  19583. }
  19584. }
  19585. if (defaultMidiOutputName.isNotEmpty())
  19586. lastExplicitSettings->setAttribute ("defaultMidiOutput", defaultMidiOutputName);
  19587. }
  19588. void AudioDeviceManager::addAudioCallback (AudioIODeviceCallback* newCallback)
  19589. {
  19590. {
  19591. const ScopedLock sl (audioCallbackLock);
  19592. if (callbacks.contains (newCallback))
  19593. return;
  19594. }
  19595. if (currentAudioDevice != 0 && newCallback != 0)
  19596. newCallback->audioDeviceAboutToStart (currentAudioDevice);
  19597. const ScopedLock sl (audioCallbackLock);
  19598. callbacks.add (newCallback);
  19599. }
  19600. void AudioDeviceManager::removeAudioCallback (AudioIODeviceCallback* callback)
  19601. {
  19602. if (callback != 0)
  19603. {
  19604. bool needsDeinitialising = currentAudioDevice != 0;
  19605. {
  19606. const ScopedLock sl (audioCallbackLock);
  19607. needsDeinitialising = needsDeinitialising && callbacks.contains (callback);
  19608. callbacks.removeValue (callback);
  19609. }
  19610. if (needsDeinitialising)
  19611. callback->audioDeviceStopped();
  19612. }
  19613. }
  19614. void AudioDeviceManager::audioDeviceIOCallbackInt (const float** inputChannelData,
  19615. int numInputChannels,
  19616. float** outputChannelData,
  19617. int numOutputChannels,
  19618. int numSamples)
  19619. {
  19620. const ScopedLock sl (audioCallbackLock);
  19621. if (inputLevelMeasurementEnabledCount > 0)
  19622. {
  19623. for (int j = 0; j < numSamples; ++j)
  19624. {
  19625. float s = 0;
  19626. for (int i = 0; i < numInputChannels; ++i)
  19627. s += fabsf (inputChannelData[i][j]);
  19628. s /= numInputChannels;
  19629. const double decayFactor = 0.99992;
  19630. if (s > inputLevel)
  19631. inputLevel = s;
  19632. else if (inputLevel > 0.001f)
  19633. inputLevel *= decayFactor;
  19634. else
  19635. inputLevel = 0;
  19636. }
  19637. }
  19638. if (callbacks.size() > 0)
  19639. {
  19640. const double callbackStartTime = Time::getMillisecondCounterHiRes();
  19641. tempBuffer.setSize (jmax (1, numOutputChannels), jmax (1, numSamples), false, false, true);
  19642. callbacks.getUnchecked(0)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19643. outputChannelData, numOutputChannels, numSamples);
  19644. float** const tempChans = tempBuffer.getArrayOfChannels();
  19645. for (int i = callbacks.size(); --i > 0;)
  19646. {
  19647. callbacks.getUnchecked(i)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19648. tempChans, numOutputChannels, numSamples);
  19649. for (int chan = 0; chan < numOutputChannels; ++chan)
  19650. {
  19651. const float* const src = tempChans [chan];
  19652. float* const dst = outputChannelData [chan];
  19653. if (src != 0 && dst != 0)
  19654. for (int j = 0; j < numSamples; ++j)
  19655. dst[j] += src[j];
  19656. }
  19657. }
  19658. const double msTaken = Time::getMillisecondCounterHiRes() - callbackStartTime;
  19659. const double filterAmount = 0.2;
  19660. cpuUsageMs += filterAmount * (msTaken - cpuUsageMs);
  19661. }
  19662. else
  19663. {
  19664. for (int i = 0; i < numOutputChannels; ++i)
  19665. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  19666. }
  19667. if (testSound != 0)
  19668. {
  19669. const int numSamps = jmin (numSamples, testSound->getNumSamples() - testSoundPosition);
  19670. const float* const src = testSound->getSampleData (0, testSoundPosition);
  19671. for (int i = 0; i < numOutputChannels; ++i)
  19672. for (int j = 0; j < numSamps; ++j)
  19673. outputChannelData [i][j] += src[j];
  19674. testSoundPosition += numSamps;
  19675. if (testSoundPosition >= testSound->getNumSamples())
  19676. testSound = 0;
  19677. }
  19678. }
  19679. void AudioDeviceManager::audioDeviceAboutToStartInt (AudioIODevice* const device)
  19680. {
  19681. cpuUsageMs = 0;
  19682. const double sampleRate = device->getCurrentSampleRate();
  19683. const int blockSize = device->getCurrentBufferSizeSamples();
  19684. if (sampleRate > 0.0 && blockSize > 0)
  19685. {
  19686. const double msPerBlock = 1000.0 * blockSize / sampleRate;
  19687. timeToCpuScale = (msPerBlock > 0.0) ? (1.0 / msPerBlock) : 0.0;
  19688. }
  19689. {
  19690. const ScopedLock sl (audioCallbackLock);
  19691. for (int i = callbacks.size(); --i >= 0;)
  19692. callbacks.getUnchecked(i)->audioDeviceAboutToStart (device);
  19693. }
  19694. sendChangeMessage (this);
  19695. }
  19696. void AudioDeviceManager::audioDeviceStoppedInt()
  19697. {
  19698. cpuUsageMs = 0;
  19699. timeToCpuScale = 0;
  19700. sendChangeMessage (this);
  19701. const ScopedLock sl (audioCallbackLock);
  19702. for (int i = callbacks.size(); --i >= 0;)
  19703. callbacks.getUnchecked(i)->audioDeviceStopped();
  19704. }
  19705. double AudioDeviceManager::getCpuUsage() const
  19706. {
  19707. return jlimit (0.0, 1.0, timeToCpuScale * cpuUsageMs);
  19708. }
  19709. void AudioDeviceManager::setMidiInputEnabled (const String& name,
  19710. const bool enabled)
  19711. {
  19712. if (enabled != isMidiInputEnabled (name))
  19713. {
  19714. if (enabled)
  19715. {
  19716. const int index = MidiInput::getDevices().indexOf (name);
  19717. if (index >= 0)
  19718. {
  19719. MidiInput* const min = MidiInput::openDevice (index, &callbackHandler);
  19720. if (min != 0)
  19721. {
  19722. enabledMidiInputs.add (min);
  19723. min->start();
  19724. }
  19725. }
  19726. }
  19727. else
  19728. {
  19729. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19730. if (enabledMidiInputs[i]->getName() == name)
  19731. enabledMidiInputs.remove (i);
  19732. }
  19733. updateXml();
  19734. sendChangeMessage (this);
  19735. }
  19736. }
  19737. bool AudioDeviceManager::isMidiInputEnabled (const String& name) const
  19738. {
  19739. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19740. if (enabledMidiInputs[i]->getName() == name)
  19741. return true;
  19742. return false;
  19743. }
  19744. void AudioDeviceManager::addMidiInputCallback (const String& name,
  19745. MidiInputCallback* callback)
  19746. {
  19747. removeMidiInputCallback (name, callback);
  19748. if (name.isEmpty())
  19749. {
  19750. midiCallbacks.add (callback);
  19751. midiCallbackDevices.add (0);
  19752. }
  19753. else
  19754. {
  19755. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19756. {
  19757. if (enabledMidiInputs[i]->getName() == name)
  19758. {
  19759. const ScopedLock sl (midiCallbackLock);
  19760. midiCallbacks.add (callback);
  19761. midiCallbackDevices.add (enabledMidiInputs[i]);
  19762. break;
  19763. }
  19764. }
  19765. }
  19766. }
  19767. void AudioDeviceManager::removeMidiInputCallback (const String& name,
  19768. MidiInputCallback* /*callback*/)
  19769. {
  19770. const ScopedLock sl (midiCallbackLock);
  19771. for (int i = midiCallbacks.size(); --i >= 0;)
  19772. {
  19773. String devName;
  19774. if (midiCallbackDevices.getUnchecked(i) != 0)
  19775. devName = midiCallbackDevices.getUnchecked(i)->getName();
  19776. if (devName == name)
  19777. {
  19778. midiCallbacks.remove (i);
  19779. midiCallbackDevices.remove (i);
  19780. }
  19781. }
  19782. }
  19783. void AudioDeviceManager::handleIncomingMidiMessageInt (MidiInput* source,
  19784. const MidiMessage& message)
  19785. {
  19786. if (! message.isActiveSense())
  19787. {
  19788. const bool isDefaultSource = (source == 0 || source == enabledMidiInputs.getFirst());
  19789. const ScopedLock sl (midiCallbackLock);
  19790. for (int i = midiCallbackDevices.size(); --i >= 0;)
  19791. {
  19792. MidiInput* const md = midiCallbackDevices.getUnchecked(i);
  19793. if (md == source || (md == 0 && isDefaultSource))
  19794. midiCallbacks.getUnchecked(i)->handleIncomingMidiMessage (source, message);
  19795. }
  19796. }
  19797. }
  19798. void AudioDeviceManager::setDefaultMidiOutput (const String& deviceName)
  19799. {
  19800. if (defaultMidiOutputName != deviceName)
  19801. {
  19802. SortedSet <AudioIODeviceCallback*> oldCallbacks;
  19803. {
  19804. const ScopedLock sl (audioCallbackLock);
  19805. oldCallbacks = callbacks;
  19806. callbacks.clear();
  19807. }
  19808. if (currentAudioDevice != 0)
  19809. for (int i = oldCallbacks.size(); --i >= 0;)
  19810. oldCallbacks.getUnchecked(i)->audioDeviceStopped();
  19811. defaultMidiOutput = 0;
  19812. defaultMidiOutputName = deviceName;
  19813. if (deviceName.isNotEmpty())
  19814. defaultMidiOutput = MidiOutput::openDevice (MidiOutput::getDevices().indexOf (deviceName));
  19815. if (currentAudioDevice != 0)
  19816. for (int i = oldCallbacks.size(); --i >= 0;)
  19817. oldCallbacks.getUnchecked(i)->audioDeviceAboutToStart (currentAudioDevice);
  19818. {
  19819. const ScopedLock sl (audioCallbackLock);
  19820. callbacks = oldCallbacks;
  19821. }
  19822. updateXml();
  19823. sendChangeMessage (this);
  19824. }
  19825. }
  19826. void AudioDeviceManager::CallbackHandler::audioDeviceIOCallback (const float** inputChannelData,
  19827. int numInputChannels,
  19828. float** outputChannelData,
  19829. int numOutputChannels,
  19830. int numSamples)
  19831. {
  19832. owner->audioDeviceIOCallbackInt (inputChannelData, numInputChannels, outputChannelData, numOutputChannels, numSamples);
  19833. }
  19834. void AudioDeviceManager::CallbackHandler::audioDeviceAboutToStart (AudioIODevice* device)
  19835. {
  19836. owner->audioDeviceAboutToStartInt (device);
  19837. }
  19838. void AudioDeviceManager::CallbackHandler::audioDeviceStopped()
  19839. {
  19840. owner->audioDeviceStoppedInt();
  19841. }
  19842. void AudioDeviceManager::CallbackHandler::handleIncomingMidiMessage (MidiInput* source, const MidiMessage& message)
  19843. {
  19844. owner->handleIncomingMidiMessageInt (source, message);
  19845. }
  19846. void AudioDeviceManager::playTestSound()
  19847. {
  19848. { // cunningly nested to swap, unlock and delete in that order.
  19849. ScopedPointer <AudioSampleBuffer> oldSound;
  19850. {
  19851. const ScopedLock sl (audioCallbackLock);
  19852. oldSound = testSound;
  19853. }
  19854. }
  19855. testSoundPosition = 0;
  19856. if (currentAudioDevice != 0)
  19857. {
  19858. const double sampleRate = currentAudioDevice->getCurrentSampleRate();
  19859. const int soundLength = (int) sampleRate;
  19860. AudioSampleBuffer* const newSound = new AudioSampleBuffer (1, soundLength);
  19861. float* samples = newSound->getSampleData (0);
  19862. const double frequency = MidiMessage::getMidiNoteInHertz (80);
  19863. const float amplitude = 0.5f;
  19864. const double phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  19865. for (int i = 0; i < soundLength; ++i)
  19866. samples[i] = amplitude * (float) sin (i * phasePerSample);
  19867. newSound->applyGainRamp (0, 0, soundLength / 10, 0.0f, 1.0f);
  19868. newSound->applyGainRamp (0, soundLength - soundLength / 4, soundLength / 4, 1.0f, 0.0f);
  19869. const ScopedLock sl (audioCallbackLock);
  19870. testSound = newSound;
  19871. }
  19872. }
  19873. void AudioDeviceManager::enableInputLevelMeasurement (const bool enableMeasurement)
  19874. {
  19875. const ScopedLock sl (audioCallbackLock);
  19876. if (enableMeasurement)
  19877. ++inputLevelMeasurementEnabledCount;
  19878. else
  19879. --inputLevelMeasurementEnabledCount;
  19880. inputLevel = 0;
  19881. }
  19882. double AudioDeviceManager::getCurrentInputLevel() const
  19883. {
  19884. jassert (inputLevelMeasurementEnabledCount > 0); // you need to call enableInputLevelMeasurement() before using this!
  19885. return inputLevel;
  19886. }
  19887. END_JUCE_NAMESPACE
  19888. /*** End of inlined file: juce_AudioDeviceManager.cpp ***/
  19889. /*** Start of inlined file: juce_AudioIODevice.cpp ***/
  19890. BEGIN_JUCE_NAMESPACE
  19891. AudioIODevice::AudioIODevice (const String& deviceName, const String& typeName_)
  19892. : name (deviceName),
  19893. typeName (typeName_)
  19894. {
  19895. }
  19896. AudioIODevice::~AudioIODevice()
  19897. {
  19898. }
  19899. bool AudioIODevice::hasControlPanel() const
  19900. {
  19901. return false;
  19902. }
  19903. bool AudioIODevice::showControlPanel()
  19904. {
  19905. jassertfalse // this should only be called for devices which return true from
  19906. // their hasControlPanel() method.
  19907. return false;
  19908. }
  19909. END_JUCE_NAMESPACE
  19910. /*** End of inlined file: juce_AudioIODevice.cpp ***/
  19911. /*** Start of inlined file: juce_AudioIODeviceType.cpp ***/
  19912. BEGIN_JUCE_NAMESPACE
  19913. AudioIODeviceType::AudioIODeviceType (const String& name)
  19914. : typeName (name)
  19915. {
  19916. }
  19917. AudioIODeviceType::~AudioIODeviceType()
  19918. {
  19919. }
  19920. END_JUCE_NAMESPACE
  19921. /*** End of inlined file: juce_AudioIODeviceType.cpp ***/
  19922. /*** Start of inlined file: juce_MidiOutput.cpp ***/
  19923. BEGIN_JUCE_NAMESPACE
  19924. MidiOutput::MidiOutput()
  19925. : Thread ("midi out"),
  19926. internal (0),
  19927. firstMessage (0)
  19928. {
  19929. }
  19930. MidiOutput::PendingMessage::PendingMessage (const uint8* const data, const int len,
  19931. const double sampleNumber)
  19932. : message (data, len, sampleNumber)
  19933. {
  19934. }
  19935. void MidiOutput::sendBlockOfMessages (const MidiBuffer& buffer,
  19936. const double millisecondCounterToStartAt,
  19937. double samplesPerSecondForBuffer)
  19938. {
  19939. // You've got to call startBackgroundThread() for this to actually work..
  19940. jassert (isThreadRunning());
  19941. // this needs to be a value in the future - RTFM for this method!
  19942. jassert (millisecondCounterToStartAt > 0);
  19943. const double timeScaleFactor = 1000.0 / samplesPerSecondForBuffer;
  19944. MidiBuffer::Iterator i (buffer);
  19945. const uint8* data;
  19946. int len, time;
  19947. while (i.getNextEvent (data, len, time))
  19948. {
  19949. const double eventTime = millisecondCounterToStartAt + timeScaleFactor * time;
  19950. PendingMessage* const m
  19951. = new PendingMessage (data, len, eventTime);
  19952. const ScopedLock sl (lock);
  19953. if (firstMessage == 0 || firstMessage->message.getTimeStamp() > eventTime)
  19954. {
  19955. m->next = firstMessage;
  19956. firstMessage = m;
  19957. }
  19958. else
  19959. {
  19960. PendingMessage* mm = firstMessage;
  19961. while (mm->next != 0 && mm->next->message.getTimeStamp() <= eventTime)
  19962. mm = mm->next;
  19963. m->next = mm->next;
  19964. mm->next = m;
  19965. }
  19966. }
  19967. notify();
  19968. }
  19969. void MidiOutput::clearAllPendingMessages()
  19970. {
  19971. const ScopedLock sl (lock);
  19972. while (firstMessage != 0)
  19973. {
  19974. PendingMessage* const m = firstMessage;
  19975. firstMessage = firstMessage->next;
  19976. delete m;
  19977. }
  19978. }
  19979. void MidiOutput::startBackgroundThread()
  19980. {
  19981. startThread (9);
  19982. }
  19983. void MidiOutput::stopBackgroundThread()
  19984. {
  19985. stopThread (5000);
  19986. }
  19987. void MidiOutput::run()
  19988. {
  19989. while (! threadShouldExit())
  19990. {
  19991. uint32 now = Time::getMillisecondCounter();
  19992. uint32 eventTime = 0;
  19993. uint32 timeToWait = 500;
  19994. PendingMessage* message;
  19995. {
  19996. const ScopedLock sl (lock);
  19997. message = firstMessage;
  19998. if (message != 0)
  19999. {
  20000. eventTime = roundToInt (message->message.getTimeStamp());
  20001. if (eventTime > now + 20)
  20002. {
  20003. timeToWait = eventTime - (now + 20);
  20004. message = 0;
  20005. }
  20006. else
  20007. {
  20008. firstMessage = message->next;
  20009. }
  20010. }
  20011. }
  20012. if (message != 0)
  20013. {
  20014. if (eventTime > now)
  20015. {
  20016. Time::waitForMillisecondCounter (eventTime);
  20017. if (threadShouldExit())
  20018. break;
  20019. }
  20020. if (eventTime > now - 200)
  20021. sendMessageNow (message->message);
  20022. delete message;
  20023. }
  20024. else
  20025. {
  20026. jassert (timeToWait < 1000 * 30);
  20027. wait (timeToWait);
  20028. }
  20029. }
  20030. clearAllPendingMessages();
  20031. }
  20032. END_JUCE_NAMESPACE
  20033. /*** End of inlined file: juce_MidiOutput.cpp ***/
  20034. /*** Start of inlined file: juce_AudioDataConverters.cpp ***/
  20035. BEGIN_JUCE_NAMESPACE
  20036. void AudioDataConverters::convertFloatToInt16LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20037. {
  20038. const double maxVal = (double) 0x7fff;
  20039. char* intData = (char*) dest;
  20040. if (dest != (void*) source || destBytesPerSample <= 4)
  20041. {
  20042. for (int i = 0; i < numSamples; ++i)
  20043. {
  20044. *(uint16*)intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20045. intData += destBytesPerSample;
  20046. }
  20047. }
  20048. else
  20049. {
  20050. intData += destBytesPerSample * numSamples;
  20051. for (int i = numSamples; --i >= 0;)
  20052. {
  20053. intData -= destBytesPerSample;
  20054. *(uint16*)intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20055. }
  20056. }
  20057. }
  20058. void AudioDataConverters::convertFloatToInt16BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20059. {
  20060. const double maxVal = (double) 0x7fff;
  20061. char* intData = (char*) dest;
  20062. if (dest != (void*) source || destBytesPerSample <= 4)
  20063. {
  20064. for (int i = 0; i < numSamples; ++i)
  20065. {
  20066. *(uint16*) intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20067. intData += destBytesPerSample;
  20068. }
  20069. }
  20070. else
  20071. {
  20072. intData += destBytesPerSample * numSamples;
  20073. for (int i = numSamples; --i >= 0;)
  20074. {
  20075. intData -= destBytesPerSample;
  20076. *(uint16*)intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20077. }
  20078. }
  20079. }
  20080. void AudioDataConverters::convertFloatToInt24LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20081. {
  20082. const double maxVal = (double) 0x7fffff;
  20083. char* intData = (char*) dest;
  20084. if (dest != (void*) source || destBytesPerSample <= 4)
  20085. {
  20086. for (int i = 0; i < numSamples; ++i)
  20087. {
  20088. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20089. intData += destBytesPerSample;
  20090. }
  20091. }
  20092. else
  20093. {
  20094. intData += destBytesPerSample * numSamples;
  20095. for (int i = numSamples; --i >= 0;)
  20096. {
  20097. intData -= destBytesPerSample;
  20098. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20099. }
  20100. }
  20101. }
  20102. void AudioDataConverters::convertFloatToInt24BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20103. {
  20104. const double maxVal = (double) 0x7fffff;
  20105. char* intData = (char*) dest;
  20106. if (dest != (void*) source || destBytesPerSample <= 4)
  20107. {
  20108. for (int i = 0; i < numSamples; ++i)
  20109. {
  20110. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20111. intData += destBytesPerSample;
  20112. }
  20113. }
  20114. else
  20115. {
  20116. intData += destBytesPerSample * numSamples;
  20117. for (int i = numSamples; --i >= 0;)
  20118. {
  20119. intData -= destBytesPerSample;
  20120. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20121. }
  20122. }
  20123. }
  20124. void AudioDataConverters::convertFloatToInt32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20125. {
  20126. const double maxVal = (double) 0x7fffffff;
  20127. char* intData = (char*) dest;
  20128. if (dest != (void*) source || destBytesPerSample <= 4)
  20129. {
  20130. for (int i = 0; i < numSamples; ++i)
  20131. {
  20132. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20133. intData += destBytesPerSample;
  20134. }
  20135. }
  20136. else
  20137. {
  20138. intData += destBytesPerSample * numSamples;
  20139. for (int i = numSamples; --i >= 0;)
  20140. {
  20141. intData -= destBytesPerSample;
  20142. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20143. }
  20144. }
  20145. }
  20146. void AudioDataConverters::convertFloatToInt32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20147. {
  20148. const double maxVal = (double) 0x7fffffff;
  20149. char* intData = (char*) dest;
  20150. if (dest != (void*) source || destBytesPerSample <= 4)
  20151. {
  20152. for (int i = 0; i < numSamples; ++i)
  20153. {
  20154. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20155. intData += destBytesPerSample;
  20156. }
  20157. }
  20158. else
  20159. {
  20160. intData += destBytesPerSample * numSamples;
  20161. for (int i = numSamples; --i >= 0;)
  20162. {
  20163. intData -= destBytesPerSample;
  20164. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20165. }
  20166. }
  20167. }
  20168. void AudioDataConverters::convertFloatToFloat32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20169. {
  20170. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20171. char* d = (char*) dest;
  20172. for (int i = 0; i < numSamples; ++i)
  20173. {
  20174. *(float*) d = source[i];
  20175. #if JUCE_BIG_ENDIAN
  20176. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20177. #endif
  20178. d += destBytesPerSample;
  20179. }
  20180. }
  20181. void AudioDataConverters::convertFloatToFloat32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20182. {
  20183. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20184. char* d = (char*) dest;
  20185. for (int i = 0; i < numSamples; ++i)
  20186. {
  20187. *(float*) d = source[i];
  20188. #if JUCE_LITTLE_ENDIAN
  20189. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20190. #endif
  20191. d += destBytesPerSample;
  20192. }
  20193. }
  20194. void AudioDataConverters::convertInt16LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20195. {
  20196. const float scale = 1.0f / 0x7fff;
  20197. const char* intData = (const char*) source;
  20198. if (source != (void*) dest || srcBytesPerSample >= 4)
  20199. {
  20200. for (int i = 0; i < numSamples; ++i)
  20201. {
  20202. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20203. intData += srcBytesPerSample;
  20204. }
  20205. }
  20206. else
  20207. {
  20208. intData += srcBytesPerSample * numSamples;
  20209. for (int i = numSamples; --i >= 0;)
  20210. {
  20211. intData -= srcBytesPerSample;
  20212. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20213. }
  20214. }
  20215. }
  20216. void AudioDataConverters::convertInt16BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20217. {
  20218. const float scale = 1.0f / 0x7fff;
  20219. const char* intData = (const char*) source;
  20220. if (source != (void*) dest || srcBytesPerSample >= 4)
  20221. {
  20222. for (int i = 0; i < numSamples; ++i)
  20223. {
  20224. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20225. intData += srcBytesPerSample;
  20226. }
  20227. }
  20228. else
  20229. {
  20230. intData += srcBytesPerSample * numSamples;
  20231. for (int i = numSamples; --i >= 0;)
  20232. {
  20233. intData -= srcBytesPerSample;
  20234. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20235. }
  20236. }
  20237. }
  20238. void AudioDataConverters::convertInt24LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20239. {
  20240. const float scale = 1.0f / 0x7fffff;
  20241. const char* intData = (const char*) source;
  20242. if (source != (void*) dest || srcBytesPerSample >= 4)
  20243. {
  20244. for (int i = 0; i < numSamples; ++i)
  20245. {
  20246. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20247. intData += srcBytesPerSample;
  20248. }
  20249. }
  20250. else
  20251. {
  20252. intData += srcBytesPerSample * numSamples;
  20253. for (int i = numSamples; --i >= 0;)
  20254. {
  20255. intData -= srcBytesPerSample;
  20256. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20257. }
  20258. }
  20259. }
  20260. void AudioDataConverters::convertInt24BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20261. {
  20262. const float scale = 1.0f / 0x7fffff;
  20263. const char* intData = (const char*) source;
  20264. if (source != (void*) dest || srcBytesPerSample >= 4)
  20265. {
  20266. for (int i = 0; i < numSamples; ++i)
  20267. {
  20268. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20269. intData += srcBytesPerSample;
  20270. }
  20271. }
  20272. else
  20273. {
  20274. intData += srcBytesPerSample * numSamples;
  20275. for (int i = numSamples; --i >= 0;)
  20276. {
  20277. intData -= srcBytesPerSample;
  20278. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20279. }
  20280. }
  20281. }
  20282. void AudioDataConverters::convertInt32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20283. {
  20284. const float scale = 1.0f / 0x7fffffff;
  20285. const char* intData = (const char*) source;
  20286. if (source != (void*) dest || srcBytesPerSample >= 4)
  20287. {
  20288. for (int i = 0; i < numSamples; ++i)
  20289. {
  20290. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20291. intData += srcBytesPerSample;
  20292. }
  20293. }
  20294. else
  20295. {
  20296. intData += srcBytesPerSample * numSamples;
  20297. for (int i = numSamples; --i >= 0;)
  20298. {
  20299. intData -= srcBytesPerSample;
  20300. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20301. }
  20302. }
  20303. }
  20304. void AudioDataConverters::convertInt32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20305. {
  20306. const float scale = 1.0f / 0x7fffffff;
  20307. const char* intData = (const char*) source;
  20308. if (source != (void*) dest || srcBytesPerSample >= 4)
  20309. {
  20310. for (int i = 0; i < numSamples; ++i)
  20311. {
  20312. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20313. intData += srcBytesPerSample;
  20314. }
  20315. }
  20316. else
  20317. {
  20318. intData += srcBytesPerSample * numSamples;
  20319. for (int i = numSamples; --i >= 0;)
  20320. {
  20321. intData -= srcBytesPerSample;
  20322. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20323. }
  20324. }
  20325. }
  20326. void AudioDataConverters::convertFloat32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20327. {
  20328. const char* s = (const char*) source;
  20329. for (int i = 0; i < numSamples; ++i)
  20330. {
  20331. dest[i] = *(float*)s;
  20332. #if JUCE_BIG_ENDIAN
  20333. uint32* const d = (uint32*) (dest + i);
  20334. *d = ByteOrder::swap (*d);
  20335. #endif
  20336. s += srcBytesPerSample;
  20337. }
  20338. }
  20339. void AudioDataConverters::convertFloat32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20340. {
  20341. const char* s = (const char*) source;
  20342. for (int i = 0; i < numSamples; ++i)
  20343. {
  20344. dest[i] = *(float*)s;
  20345. #if JUCE_LITTLE_ENDIAN
  20346. uint32* const d = (uint32*) (dest + i);
  20347. *d = ByteOrder::swap (*d);
  20348. #endif
  20349. s += srcBytesPerSample;
  20350. }
  20351. }
  20352. void AudioDataConverters::convertFloatToFormat (const DataFormat destFormat,
  20353. const float* const source,
  20354. void* const dest,
  20355. const int numSamples)
  20356. {
  20357. switch (destFormat)
  20358. {
  20359. case int16LE:
  20360. convertFloatToInt16LE (source, dest, numSamples);
  20361. break;
  20362. case int16BE:
  20363. convertFloatToInt16BE (source, dest, numSamples);
  20364. break;
  20365. case int24LE:
  20366. convertFloatToInt24LE (source, dest, numSamples);
  20367. break;
  20368. case int24BE:
  20369. convertFloatToInt24BE (source, dest, numSamples);
  20370. break;
  20371. case int32LE:
  20372. convertFloatToInt32LE (source, dest, numSamples);
  20373. break;
  20374. case int32BE:
  20375. convertFloatToInt32BE (source, dest, numSamples);
  20376. break;
  20377. case float32LE:
  20378. convertFloatToFloat32LE (source, dest, numSamples);
  20379. break;
  20380. case float32BE:
  20381. convertFloatToFloat32BE (source, dest, numSamples);
  20382. break;
  20383. default:
  20384. jassertfalse
  20385. break;
  20386. }
  20387. }
  20388. void AudioDataConverters::convertFormatToFloat (const DataFormat sourceFormat,
  20389. const void* const source,
  20390. float* const dest,
  20391. const int numSamples)
  20392. {
  20393. switch (sourceFormat)
  20394. {
  20395. case int16LE:
  20396. convertInt16LEToFloat (source, dest, numSamples);
  20397. break;
  20398. case int16BE:
  20399. convertInt16BEToFloat (source, dest, numSamples);
  20400. break;
  20401. case int24LE:
  20402. convertInt24LEToFloat (source, dest, numSamples);
  20403. break;
  20404. case int24BE:
  20405. convertInt24BEToFloat (source, dest, numSamples);
  20406. break;
  20407. case int32LE:
  20408. convertInt32LEToFloat (source, dest, numSamples);
  20409. break;
  20410. case int32BE:
  20411. convertInt32BEToFloat (source, dest, numSamples);
  20412. break;
  20413. case float32LE:
  20414. convertFloat32LEToFloat (source, dest, numSamples);
  20415. break;
  20416. case float32BE:
  20417. convertFloat32BEToFloat (source, dest, numSamples);
  20418. break;
  20419. default:
  20420. jassertfalse
  20421. break;
  20422. }
  20423. }
  20424. void AudioDataConverters::interleaveSamples (const float** const source,
  20425. float* const dest,
  20426. const int numSamples,
  20427. const int numChannels)
  20428. {
  20429. for (int chan = 0; chan < numChannels; ++chan)
  20430. {
  20431. int i = chan;
  20432. const float* src = source [chan];
  20433. for (int j = 0; j < numSamples; ++j)
  20434. {
  20435. dest [i] = src [j];
  20436. i += numChannels;
  20437. }
  20438. }
  20439. }
  20440. void AudioDataConverters::deinterleaveSamples (const float* const source,
  20441. float** const dest,
  20442. const int numSamples,
  20443. const int numChannels)
  20444. {
  20445. for (int chan = 0; chan < numChannels; ++chan)
  20446. {
  20447. int i = chan;
  20448. float* dst = dest [chan];
  20449. for (int j = 0; j < numSamples; ++j)
  20450. {
  20451. dst [j] = source [i];
  20452. i += numChannels;
  20453. }
  20454. }
  20455. }
  20456. END_JUCE_NAMESPACE
  20457. /*** End of inlined file: juce_AudioDataConverters.cpp ***/
  20458. /*** Start of inlined file: juce_AudioSampleBuffer.cpp ***/
  20459. BEGIN_JUCE_NAMESPACE
  20460. AudioSampleBuffer::AudioSampleBuffer (const int numChannels_,
  20461. const int numSamples) throw()
  20462. : numChannels (numChannels_),
  20463. size (numSamples)
  20464. {
  20465. jassert (numSamples >= 0);
  20466. jassert (numChannels_ > 0);
  20467. allocateData();
  20468. }
  20469. AudioSampleBuffer::AudioSampleBuffer (const AudioSampleBuffer& other) throw()
  20470. : numChannels (other.numChannels),
  20471. size (other.size)
  20472. {
  20473. allocateData();
  20474. const size_t numBytes = size * sizeof (float);
  20475. for (int i = 0; i < numChannels; ++i)
  20476. memcpy (channels[i], other.channels[i], numBytes);
  20477. }
  20478. void AudioSampleBuffer::allocateData()
  20479. {
  20480. const size_t channelListSize = (numChannels + 1) * sizeof (float*);
  20481. allocatedBytes = (int) (numChannels * size * sizeof (float) + channelListSize + 32);
  20482. allocatedData.malloc (allocatedBytes);
  20483. channels = reinterpret_cast <float**> (allocatedData.getData());
  20484. float* chan = (float*) (allocatedData + channelListSize);
  20485. for (int i = 0; i < numChannels; ++i)
  20486. {
  20487. channels[i] = chan;
  20488. chan += size;
  20489. }
  20490. channels [numChannels] = 0;
  20491. }
  20492. AudioSampleBuffer::AudioSampleBuffer (float** dataToReferTo,
  20493. const int numChannels_,
  20494. const int numSamples) throw()
  20495. : numChannels (numChannels_),
  20496. size (numSamples),
  20497. allocatedBytes (0)
  20498. {
  20499. jassert (numChannels_ > 0);
  20500. allocateChannels (dataToReferTo);
  20501. }
  20502. void AudioSampleBuffer::setDataToReferTo (float** dataToReferTo,
  20503. const int newNumChannels,
  20504. const int newNumSamples) throw()
  20505. {
  20506. jassert (newNumChannels > 0);
  20507. allocatedBytes = 0;
  20508. allocatedData.free();
  20509. numChannels = newNumChannels;
  20510. size = newNumSamples;
  20511. allocateChannels (dataToReferTo);
  20512. }
  20513. void AudioSampleBuffer::allocateChannels (float** const dataToReferTo)
  20514. {
  20515. // (try to avoid doing a malloc here, as that'll blow up things like Pro-Tools)
  20516. if (numChannels < numElementsInArray (preallocatedChannelSpace))
  20517. {
  20518. channels = static_cast <float**> (preallocatedChannelSpace);
  20519. }
  20520. else
  20521. {
  20522. allocatedData.malloc (numChannels + 1, sizeof (float*));
  20523. channels = reinterpret_cast <float**> (allocatedData.getData());
  20524. }
  20525. for (int i = 0; i < numChannels; ++i)
  20526. {
  20527. // you have to pass in the same number of valid pointers as numChannels
  20528. jassert (dataToReferTo[i] != 0);
  20529. channels[i] = dataToReferTo[i];
  20530. }
  20531. channels [numChannels] = 0;
  20532. }
  20533. AudioSampleBuffer& AudioSampleBuffer::operator= (const AudioSampleBuffer& other) throw()
  20534. {
  20535. if (this != &other)
  20536. {
  20537. setSize (other.getNumChannels(), other.getNumSamples(), false, false, false);
  20538. const size_t numBytes = size * sizeof (float);
  20539. for (int i = 0; i < numChannels; ++i)
  20540. memcpy (channels[i], other.channels[i], numBytes);
  20541. }
  20542. return *this;
  20543. }
  20544. AudioSampleBuffer::~AudioSampleBuffer() throw()
  20545. {
  20546. }
  20547. void AudioSampleBuffer::setSize (const int newNumChannels,
  20548. const int newNumSamples,
  20549. const bool keepExistingContent,
  20550. const bool clearExtraSpace,
  20551. const bool avoidReallocating) throw()
  20552. {
  20553. jassert (newNumChannels > 0);
  20554. if (newNumSamples != size || newNumChannels != numChannels)
  20555. {
  20556. const size_t channelListSize = (newNumChannels + 1) * sizeof (float*);
  20557. const size_t newTotalBytes = (newNumChannels * newNumSamples * sizeof (float)) + channelListSize + 32;
  20558. if (keepExistingContent)
  20559. {
  20560. HeapBlock <char> newData;
  20561. newData.allocate (newTotalBytes, clearExtraSpace);
  20562. const int numChansToCopy = jmin (numChannels, newNumChannels);
  20563. const size_t numBytesToCopy = sizeof (float) * jmin (newNumSamples, size);
  20564. float** const newChannels = reinterpret_cast <float**> (newData.getData());
  20565. float* newChan = reinterpret_cast <float*> (newData + channelListSize);
  20566. for (int i = 0; i < numChansToCopy; ++i)
  20567. {
  20568. memcpy (newChan, channels[i], numBytesToCopy);
  20569. newChannels[i] = newChan;
  20570. newChan += newNumSamples;
  20571. }
  20572. allocatedData.swapWith (newData);
  20573. allocatedBytes = (int) newTotalBytes;
  20574. channels = newChannels;
  20575. }
  20576. else
  20577. {
  20578. if (avoidReallocating && allocatedBytes >= newTotalBytes)
  20579. {
  20580. if (clearExtraSpace)
  20581. zeromem (allocatedData, newTotalBytes);
  20582. }
  20583. else
  20584. {
  20585. allocatedBytes = newTotalBytes;
  20586. allocatedData.allocate (newTotalBytes, clearExtraSpace);
  20587. channels = reinterpret_cast <float**> (allocatedData.getData());
  20588. }
  20589. float* chan = reinterpret_cast <float*> (allocatedData + channelListSize);
  20590. for (int i = 0; i < newNumChannels; ++i)
  20591. {
  20592. channels[i] = chan;
  20593. chan += newNumSamples;
  20594. }
  20595. }
  20596. channels [newNumChannels] = 0;
  20597. size = newNumSamples;
  20598. numChannels = newNumChannels;
  20599. }
  20600. }
  20601. void AudioSampleBuffer::clear() throw()
  20602. {
  20603. for (int i = 0; i < numChannels; ++i)
  20604. zeromem (channels[i], size * sizeof (float));
  20605. }
  20606. void AudioSampleBuffer::clear (const int startSample,
  20607. const int numSamples) throw()
  20608. {
  20609. jassert (startSample >= 0 && startSample + numSamples <= size);
  20610. for (int i = 0; i < numChannels; ++i)
  20611. zeromem (channels [i] + startSample, numSamples * sizeof (float));
  20612. }
  20613. void AudioSampleBuffer::clear (const int channel,
  20614. const int startSample,
  20615. const int numSamples) throw()
  20616. {
  20617. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20618. jassert (startSample >= 0 && startSample + numSamples <= size);
  20619. zeromem (channels [channel] + startSample, numSamples * sizeof (float));
  20620. }
  20621. void AudioSampleBuffer::applyGain (const int channel,
  20622. const int startSample,
  20623. int numSamples,
  20624. const float gain) throw()
  20625. {
  20626. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20627. jassert (startSample >= 0 && startSample + numSamples <= size);
  20628. if (gain != 1.0f)
  20629. {
  20630. float* d = channels [channel] + startSample;
  20631. if (gain == 0.0f)
  20632. {
  20633. zeromem (d, sizeof (float) * numSamples);
  20634. }
  20635. else
  20636. {
  20637. while (--numSamples >= 0)
  20638. *d++ *= gain;
  20639. }
  20640. }
  20641. }
  20642. void AudioSampleBuffer::applyGainRamp (const int channel,
  20643. const int startSample,
  20644. int numSamples,
  20645. float startGain,
  20646. float endGain) throw()
  20647. {
  20648. if (startGain == endGain)
  20649. {
  20650. applyGain (channel, startSample, numSamples, startGain);
  20651. }
  20652. else
  20653. {
  20654. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20655. jassert (startSample >= 0 && startSample + numSamples <= size);
  20656. const float increment = (endGain - startGain) / numSamples;
  20657. float* d = channels [channel] + startSample;
  20658. while (--numSamples >= 0)
  20659. {
  20660. *d++ *= startGain;
  20661. startGain += increment;
  20662. }
  20663. }
  20664. }
  20665. void AudioSampleBuffer::applyGain (const int startSample,
  20666. const int numSamples,
  20667. const float gain) throw()
  20668. {
  20669. for (int i = 0; i < numChannels; ++i)
  20670. applyGain (i, startSample, numSamples, gain);
  20671. }
  20672. void AudioSampleBuffer::addFrom (const int destChannel,
  20673. const int destStartSample,
  20674. const AudioSampleBuffer& source,
  20675. const int sourceChannel,
  20676. const int sourceStartSample,
  20677. int numSamples,
  20678. const float gain) throw()
  20679. {
  20680. jassert (&source != this || sourceChannel != destChannel);
  20681. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20682. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20683. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20684. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20685. if (gain != 0.0f && numSamples > 0)
  20686. {
  20687. float* d = channels [destChannel] + destStartSample;
  20688. const float* s = source.channels [sourceChannel] + sourceStartSample;
  20689. if (gain != 1.0f)
  20690. {
  20691. while (--numSamples >= 0)
  20692. *d++ += gain * *s++;
  20693. }
  20694. else
  20695. {
  20696. while (--numSamples >= 0)
  20697. *d++ += *s++;
  20698. }
  20699. }
  20700. }
  20701. void AudioSampleBuffer::addFrom (const int destChannel,
  20702. const int destStartSample,
  20703. const float* source,
  20704. int numSamples,
  20705. const float gain) throw()
  20706. {
  20707. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20708. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20709. jassert (source != 0);
  20710. if (gain != 0.0f && numSamples > 0)
  20711. {
  20712. float* d = channels [destChannel] + destStartSample;
  20713. if (gain != 1.0f)
  20714. {
  20715. while (--numSamples >= 0)
  20716. *d++ += gain * *source++;
  20717. }
  20718. else
  20719. {
  20720. while (--numSamples >= 0)
  20721. *d++ += *source++;
  20722. }
  20723. }
  20724. }
  20725. void AudioSampleBuffer::addFromWithRamp (const int destChannel,
  20726. const int destStartSample,
  20727. const float* source,
  20728. int numSamples,
  20729. float startGain,
  20730. const float endGain) throw()
  20731. {
  20732. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20733. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20734. jassert (source != 0);
  20735. if (startGain == endGain)
  20736. {
  20737. addFrom (destChannel,
  20738. destStartSample,
  20739. source,
  20740. numSamples,
  20741. startGain);
  20742. }
  20743. else
  20744. {
  20745. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  20746. {
  20747. const float increment = (endGain - startGain) / numSamples;
  20748. float* d = channels [destChannel] + destStartSample;
  20749. while (--numSamples >= 0)
  20750. {
  20751. *d++ += startGain * *source++;
  20752. startGain += increment;
  20753. }
  20754. }
  20755. }
  20756. }
  20757. void AudioSampleBuffer::copyFrom (const int destChannel,
  20758. const int destStartSample,
  20759. const AudioSampleBuffer& source,
  20760. const int sourceChannel,
  20761. const int sourceStartSample,
  20762. int numSamples) throw()
  20763. {
  20764. jassert (&source != this || sourceChannel != destChannel);
  20765. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20766. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20767. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20768. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20769. if (numSamples > 0)
  20770. {
  20771. memcpy (channels [destChannel] + destStartSample,
  20772. source.channels [sourceChannel] + sourceStartSample,
  20773. sizeof (float) * numSamples);
  20774. }
  20775. }
  20776. void AudioSampleBuffer::copyFrom (const int destChannel,
  20777. const int destStartSample,
  20778. const float* source,
  20779. int numSamples) throw()
  20780. {
  20781. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20782. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20783. jassert (source != 0);
  20784. if (numSamples > 0)
  20785. {
  20786. memcpy (channels [destChannel] + destStartSample,
  20787. source,
  20788. sizeof (float) * numSamples);
  20789. }
  20790. }
  20791. void AudioSampleBuffer::copyFrom (const int destChannel,
  20792. const int destStartSample,
  20793. const float* source,
  20794. int numSamples,
  20795. const float gain) throw()
  20796. {
  20797. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20798. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20799. jassert (source != 0);
  20800. if (numSamples > 0)
  20801. {
  20802. float* d = channels [destChannel] + destStartSample;
  20803. if (gain != 1.0f)
  20804. {
  20805. if (gain == 0)
  20806. {
  20807. zeromem (d, sizeof (float) * numSamples);
  20808. }
  20809. else
  20810. {
  20811. while (--numSamples >= 0)
  20812. *d++ = gain * *source++;
  20813. }
  20814. }
  20815. else
  20816. {
  20817. memcpy (d, source, sizeof (float) * numSamples);
  20818. }
  20819. }
  20820. }
  20821. void AudioSampleBuffer::copyFromWithRamp (const int destChannel,
  20822. const int destStartSample,
  20823. const float* source,
  20824. int numSamples,
  20825. float startGain,
  20826. float endGain) throw()
  20827. {
  20828. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20829. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20830. jassert (source != 0);
  20831. if (startGain == endGain)
  20832. {
  20833. copyFrom (destChannel,
  20834. destStartSample,
  20835. source,
  20836. numSamples,
  20837. startGain);
  20838. }
  20839. else
  20840. {
  20841. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  20842. {
  20843. const float increment = (endGain - startGain) / numSamples;
  20844. float* d = channels [destChannel] + destStartSample;
  20845. while (--numSamples >= 0)
  20846. {
  20847. *d++ = startGain * *source++;
  20848. startGain += increment;
  20849. }
  20850. }
  20851. }
  20852. }
  20853. void AudioSampleBuffer::findMinMax (const int channel,
  20854. const int startSample,
  20855. int numSamples,
  20856. float& minVal,
  20857. float& maxVal) const throw()
  20858. {
  20859. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20860. jassert (startSample >= 0 && startSample + numSamples <= size);
  20861. if (numSamples <= 0)
  20862. {
  20863. minVal = 0.0f;
  20864. maxVal = 0.0f;
  20865. }
  20866. else
  20867. {
  20868. const float* d = channels [channel] + startSample;
  20869. float mn = *d++;
  20870. float mx = mn;
  20871. while (--numSamples > 0) // (> 0 rather than >= 0 because we've already taken the first sample)
  20872. {
  20873. const float samp = *d++;
  20874. if (samp > mx)
  20875. mx = samp;
  20876. if (samp < mn)
  20877. mn = samp;
  20878. }
  20879. maxVal = mx;
  20880. minVal = mn;
  20881. }
  20882. }
  20883. float AudioSampleBuffer::getMagnitude (const int channel,
  20884. const int startSample,
  20885. const int numSamples) const throw()
  20886. {
  20887. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20888. jassert (startSample >= 0 && startSample + numSamples <= size);
  20889. float mn, mx;
  20890. findMinMax (channel, startSample, numSamples, mn, mx);
  20891. return jmax (mn, -mn, mx, -mx);
  20892. }
  20893. float AudioSampleBuffer::getMagnitude (const int startSample,
  20894. const int numSamples) const throw()
  20895. {
  20896. float mag = 0.0f;
  20897. for (int i = 0; i < numChannels; ++i)
  20898. mag = jmax (mag, getMagnitude (i, startSample, numSamples));
  20899. return mag;
  20900. }
  20901. float AudioSampleBuffer::getRMSLevel (const int channel,
  20902. const int startSample,
  20903. const int numSamples) const throw()
  20904. {
  20905. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20906. jassert (startSample >= 0 && startSample + numSamples <= size);
  20907. if (numSamples <= 0 || channel < 0 || channel >= numChannels)
  20908. return 0.0f;
  20909. const float* const data = channels [channel] + startSample;
  20910. double sum = 0.0;
  20911. for (int i = 0; i < numSamples; ++i)
  20912. {
  20913. const float sample = data [i];
  20914. sum += sample * sample;
  20915. }
  20916. return (float) sqrt (sum / numSamples);
  20917. }
  20918. void AudioSampleBuffer::readFromAudioReader (AudioFormatReader* reader,
  20919. const int startSample,
  20920. const int numSamples,
  20921. const int readerStartSample,
  20922. const bool useLeftChan,
  20923. const bool useRightChan) throw()
  20924. {
  20925. jassert (reader != 0);
  20926. jassert (startSample >= 0 && startSample + numSamples <= size);
  20927. if (numSamples > 0)
  20928. {
  20929. int* chans[3];
  20930. if (useLeftChan == useRightChan)
  20931. {
  20932. chans[0] = (int*) getSampleData (0, startSample);
  20933. chans[1] = (reader->numChannels > 1 && getNumChannels() > 1) ? (int*) getSampleData (1, startSample) : 0;
  20934. }
  20935. else if (useLeftChan || (reader->numChannels == 1))
  20936. {
  20937. chans[0] = (int*) getSampleData (0, startSample);
  20938. chans[1] = 0;
  20939. }
  20940. else if (useRightChan)
  20941. {
  20942. chans[0] = 0;
  20943. chans[1] = (int*) getSampleData (0, startSample);
  20944. }
  20945. chans[2] = 0;
  20946. reader->read (chans, 2, readerStartSample, numSamples, true);
  20947. if (! reader->usesFloatingPointData)
  20948. {
  20949. for (int j = 0; j < 2; ++j)
  20950. {
  20951. float* const d = (float*) (chans[j]);
  20952. if (d != 0)
  20953. {
  20954. const float multiplier = 1.0f / 0x7fffffff;
  20955. for (int i = 0; i < numSamples; ++i)
  20956. d[i] = *(int*)(d + i) * multiplier;
  20957. }
  20958. }
  20959. }
  20960. if (numChannels > 1 && (chans[0] == 0 || chans[1] == 0))
  20961. {
  20962. // if this is a stereo buffer and the source was mono, dupe the first channel..
  20963. memcpy (getSampleData (1, startSample),
  20964. getSampleData (0, startSample),
  20965. sizeof (float) * numSamples);
  20966. }
  20967. }
  20968. }
  20969. void AudioSampleBuffer::writeToAudioWriter (AudioFormatWriter* writer,
  20970. const int startSample,
  20971. const int numSamples) const throw()
  20972. {
  20973. jassert (startSample >= 0 && startSample + numSamples <= size);
  20974. if (numSamples > 0)
  20975. {
  20976. int* chans [3];
  20977. if (writer->isFloatingPoint())
  20978. {
  20979. chans[0] = (int*) getSampleData (0, startSample);
  20980. if (numChannels > 1)
  20981. chans[1] = (int*) getSampleData (1, startSample);
  20982. else
  20983. chans[1] = 0;
  20984. chans[2] = 0;
  20985. writer->write ((const int**) chans, numSamples);
  20986. }
  20987. else
  20988. {
  20989. HeapBlock <int> tempBuffer (numSamples * 2);
  20990. chans[0] = tempBuffer;
  20991. if (numChannels > 1)
  20992. chans[1] = chans[0] + numSamples;
  20993. else
  20994. chans[1] = 0;
  20995. chans[2] = 0;
  20996. for (int j = 0; j < 2; ++j)
  20997. {
  20998. int* const dest = chans[j];
  20999. if (dest != 0)
  21000. {
  21001. const float* const src = channels [j] + startSample;
  21002. for (int i = 0; i < numSamples; ++i)
  21003. {
  21004. const double samp = src[i];
  21005. if (samp <= -1.0)
  21006. dest[i] = std::numeric_limits<int>::min();
  21007. else if (samp >= 1.0)
  21008. dest[i] = std::numeric_limits<int>::max();
  21009. else
  21010. dest[i] = roundToInt (std::numeric_limits<int>::max() * samp);
  21011. }
  21012. }
  21013. }
  21014. writer->write ((const int**) chans, numSamples);
  21015. }
  21016. }
  21017. }
  21018. END_JUCE_NAMESPACE
  21019. /*** End of inlined file: juce_AudioSampleBuffer.cpp ***/
  21020. /*** Start of inlined file: juce_IIRFilter.cpp ***/
  21021. BEGIN_JUCE_NAMESPACE
  21022. IIRFilter::IIRFilter()
  21023. : active (false)
  21024. {
  21025. reset();
  21026. }
  21027. IIRFilter::IIRFilter (const IIRFilter& other)
  21028. : active (other.active)
  21029. {
  21030. const ScopedLock sl (other.processLock);
  21031. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21032. reset();
  21033. }
  21034. IIRFilter::~IIRFilter()
  21035. {
  21036. }
  21037. void IIRFilter::reset() throw()
  21038. {
  21039. const ScopedLock sl (processLock);
  21040. x1 = 0;
  21041. x2 = 0;
  21042. y1 = 0;
  21043. y2 = 0;
  21044. }
  21045. float IIRFilter::processSingleSampleRaw (const float in) throw()
  21046. {
  21047. float out = coefficients[0] * in
  21048. + coefficients[1] * x1
  21049. + coefficients[2] * x2
  21050. - coefficients[4] * y1
  21051. - coefficients[5] * y2;
  21052. #if JUCE_INTEL
  21053. if (! (out < -1.0e-8 || out > 1.0e-8))
  21054. out = 0;
  21055. #endif
  21056. x2 = x1;
  21057. x1 = in;
  21058. y2 = y1;
  21059. y1 = out;
  21060. return out;
  21061. }
  21062. void IIRFilter::processSamples (float* const samples,
  21063. const int numSamples) throw()
  21064. {
  21065. const ScopedLock sl (processLock);
  21066. if (active)
  21067. {
  21068. for (int i = 0; i < numSamples; ++i)
  21069. {
  21070. const float in = samples[i];
  21071. float out = coefficients[0] * in
  21072. + coefficients[1] * x1
  21073. + coefficients[2] * x2
  21074. - coefficients[4] * y1
  21075. - coefficients[5] * y2;
  21076. #if JUCE_INTEL
  21077. if (! (out < -1.0e-8 || out > 1.0e-8))
  21078. out = 0;
  21079. #endif
  21080. x2 = x1;
  21081. x1 = in;
  21082. y2 = y1;
  21083. y1 = out;
  21084. samples[i] = out;
  21085. }
  21086. }
  21087. }
  21088. void IIRFilter::makeLowPass (const double sampleRate,
  21089. const double frequency) throw()
  21090. {
  21091. jassert (sampleRate > 0);
  21092. const double n = 1.0 / tan (double_Pi * frequency / sampleRate);
  21093. const double nSquared = n * n;
  21094. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21095. setCoefficients (c1,
  21096. c1 * 2.0f,
  21097. c1,
  21098. 1.0,
  21099. c1 * 2.0 * (1.0 - nSquared),
  21100. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21101. }
  21102. void IIRFilter::makeHighPass (const double sampleRate,
  21103. const double frequency) throw()
  21104. {
  21105. const double n = tan (double_Pi * frequency / sampleRate);
  21106. const double nSquared = n * n;
  21107. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21108. setCoefficients (c1,
  21109. c1 * -2.0f,
  21110. c1,
  21111. 1.0,
  21112. c1 * 2.0 * (nSquared - 1.0),
  21113. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21114. }
  21115. void IIRFilter::makeLowShelf (const double sampleRate,
  21116. const double cutOffFrequency,
  21117. const double Q,
  21118. const float gainFactor) throw()
  21119. {
  21120. jassert (sampleRate > 0);
  21121. jassert (Q > 0);
  21122. const double A = jmax (0.0f, gainFactor);
  21123. const double aminus1 = A - 1.0;
  21124. const double aplus1 = A + 1.0;
  21125. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21126. const double coso = cos (omega);
  21127. const double beta = sin (omega) * sqrt (A) / Q;
  21128. const double aminus1TimesCoso = aminus1 * coso;
  21129. setCoefficients (A * (aplus1 - aminus1TimesCoso + beta),
  21130. A * 2.0 * (aminus1 - aplus1 * coso),
  21131. A * (aplus1 - aminus1TimesCoso - beta),
  21132. aplus1 + aminus1TimesCoso + beta,
  21133. -2.0 * (aminus1 + aplus1 * coso),
  21134. aplus1 + aminus1TimesCoso - beta);
  21135. }
  21136. void IIRFilter::makeHighShelf (const double sampleRate,
  21137. const double cutOffFrequency,
  21138. const double Q,
  21139. const float gainFactor) throw()
  21140. {
  21141. jassert (sampleRate > 0);
  21142. jassert (Q > 0);
  21143. const double A = jmax (0.0f, gainFactor);
  21144. const double aminus1 = A - 1.0;
  21145. const double aplus1 = A + 1.0;
  21146. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21147. const double coso = cos (omega);
  21148. const double beta = sin (omega) * sqrt (A) / Q;
  21149. const double aminus1TimesCoso = aminus1 * coso;
  21150. setCoefficients (A * (aplus1 + aminus1TimesCoso + beta),
  21151. A * -2.0 * (aminus1 + aplus1 * coso),
  21152. A * (aplus1 + aminus1TimesCoso - beta),
  21153. aplus1 - aminus1TimesCoso + beta,
  21154. 2.0 * (aminus1 - aplus1 * coso),
  21155. aplus1 - aminus1TimesCoso - beta);
  21156. }
  21157. void IIRFilter::makeBandPass (const double sampleRate,
  21158. const double centreFrequency,
  21159. const double Q,
  21160. const float gainFactor) throw()
  21161. {
  21162. jassert (sampleRate > 0);
  21163. jassert (Q > 0);
  21164. const double A = jmax (0.0f, gainFactor);
  21165. const double omega = (double_Pi * 2.0 * jmax (centreFrequency, 2.0)) / sampleRate;
  21166. const double alpha = 0.5 * sin (omega) / Q;
  21167. const double c2 = -2.0 * cos (omega);
  21168. const double alphaTimesA = alpha * A;
  21169. const double alphaOverA = alpha / A;
  21170. setCoefficients (1.0 + alphaTimesA,
  21171. c2,
  21172. 1.0 - alphaTimesA,
  21173. 1.0 + alphaOverA,
  21174. c2,
  21175. 1.0 - alphaOverA);
  21176. }
  21177. void IIRFilter::makeInactive() throw()
  21178. {
  21179. const ScopedLock sl (processLock);
  21180. active = false;
  21181. }
  21182. void IIRFilter::copyCoefficientsFrom (const IIRFilter& other) throw()
  21183. {
  21184. const ScopedLock sl (processLock);
  21185. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21186. active = other.active;
  21187. }
  21188. void IIRFilter::setCoefficients (double c1,
  21189. double c2,
  21190. double c3,
  21191. double c4,
  21192. double c5,
  21193. double c6) throw()
  21194. {
  21195. const double a = 1.0 / c4;
  21196. c1 *= a;
  21197. c2 *= a;
  21198. c3 *= a;
  21199. c5 *= a;
  21200. c6 *= a;
  21201. const ScopedLock sl (processLock);
  21202. coefficients[0] = (float) c1;
  21203. coefficients[1] = (float) c2;
  21204. coefficients[2] = (float) c3;
  21205. coefficients[3] = (float) c4;
  21206. coefficients[4] = (float) c5;
  21207. coefficients[5] = (float) c6;
  21208. active = true;
  21209. }
  21210. END_JUCE_NAMESPACE
  21211. /*** End of inlined file: juce_IIRFilter.cpp ***/
  21212. /*** Start of inlined file: juce_MidiBuffer.cpp ***/
  21213. BEGIN_JUCE_NAMESPACE
  21214. MidiBuffer::MidiBuffer() throw()
  21215. : bytesUsed (0)
  21216. {
  21217. }
  21218. MidiBuffer::MidiBuffer (const MidiMessage& message) throw()
  21219. : bytesUsed (0)
  21220. {
  21221. addEvent (message, 0);
  21222. }
  21223. MidiBuffer::MidiBuffer (const MidiBuffer& other) throw()
  21224. : data (other.data),
  21225. bytesUsed (other.bytesUsed)
  21226. {
  21227. }
  21228. MidiBuffer& MidiBuffer::operator= (const MidiBuffer& other) throw()
  21229. {
  21230. bytesUsed = other.bytesUsed;
  21231. data = other.data;
  21232. return *this;
  21233. }
  21234. void MidiBuffer::swap (MidiBuffer& other)
  21235. {
  21236. data.swapWith (other.data);
  21237. swapVariables <int> (bytesUsed, other.bytesUsed);
  21238. }
  21239. MidiBuffer::~MidiBuffer() throw()
  21240. {
  21241. }
  21242. void MidiBuffer::clear() throw()
  21243. {
  21244. bytesUsed = 0;
  21245. }
  21246. void MidiBuffer::clear (const int startSample,
  21247. const int numSamples) throw()
  21248. {
  21249. uint8* const start = findEventAfter (getData(), startSample - 1);
  21250. uint8* const end = findEventAfter (start, startSample + numSamples - 1);
  21251. if (end > start)
  21252. {
  21253. const int bytesToMove = bytesUsed - (int) (end - getData());
  21254. if (bytesToMove > 0)
  21255. memmove (start, end, bytesToMove);
  21256. bytesUsed -= (int) (end - start);
  21257. }
  21258. }
  21259. void MidiBuffer::addEvent (const MidiMessage& m,
  21260. const int sampleNumber) throw()
  21261. {
  21262. addEvent (m.getRawData(), m.getRawDataSize(), sampleNumber);
  21263. }
  21264. static int findActualEventLength (const uint8* const data,
  21265. const int maxBytes) throw()
  21266. {
  21267. unsigned int byte = (unsigned int) *data;
  21268. int size = 0;
  21269. if (byte == 0xf0 || byte == 0xf7)
  21270. {
  21271. const uint8* d = data + 1;
  21272. while (d < data + maxBytes)
  21273. if (*d++ == 0xf7)
  21274. break;
  21275. size = (int) (d - data);
  21276. }
  21277. else if (byte == 0xff)
  21278. {
  21279. int n;
  21280. const int bytesLeft = MidiMessage::readVariableLengthVal (data + 1, n);
  21281. size = jmin (maxBytes, n + 2 + bytesLeft);
  21282. }
  21283. else if (byte >= 0x80)
  21284. {
  21285. size = jmin (maxBytes, MidiMessage::getMessageLengthFromFirstByte ((uint8) byte));
  21286. }
  21287. return size;
  21288. }
  21289. void MidiBuffer::addEvent (const uint8* const newData,
  21290. const int maxBytes,
  21291. const int sampleNumber) throw()
  21292. {
  21293. const int numBytes = findActualEventLength (newData, maxBytes);
  21294. if (numBytes > 0)
  21295. {
  21296. int spaceNeeded = bytesUsed + numBytes + 6;
  21297. data.ensureSize ((spaceNeeded + spaceNeeded / 2 + 8) & ~7);
  21298. uint8* d = findEventAfter (getData(), sampleNumber);
  21299. const int bytesToMove = bytesUsed - (int) (d - getData());
  21300. if (bytesToMove > 0)
  21301. memmove (d + numBytes + 6,
  21302. d,
  21303. bytesToMove);
  21304. *(int*) d = sampleNumber;
  21305. d += 4;
  21306. *(uint16*) d = (uint16) numBytes;
  21307. d += 2;
  21308. memcpy (d, newData, numBytes);
  21309. bytesUsed += numBytes + 6;
  21310. }
  21311. }
  21312. void MidiBuffer::addEvents (const MidiBuffer& otherBuffer,
  21313. const int startSample,
  21314. const int numSamples,
  21315. const int sampleDeltaToAdd) throw()
  21316. {
  21317. Iterator i (otherBuffer);
  21318. i.setNextSamplePosition (startSample);
  21319. const uint8* eventData;
  21320. int eventSize, position;
  21321. while (i.getNextEvent (eventData, eventSize, position)
  21322. && (position < startSample + numSamples || numSamples < 0))
  21323. {
  21324. addEvent (eventData, eventSize, position + sampleDeltaToAdd);
  21325. }
  21326. }
  21327. bool MidiBuffer::isEmpty() const throw()
  21328. {
  21329. return bytesUsed == 0;
  21330. }
  21331. int MidiBuffer::getNumEvents() const throw()
  21332. {
  21333. int n = 0;
  21334. const uint8* d = getData();
  21335. const uint8* const end = d + bytesUsed;
  21336. while (d < end)
  21337. {
  21338. d += 4;
  21339. d += 2 + *(const uint16*) d;
  21340. ++n;
  21341. }
  21342. return n;
  21343. }
  21344. int MidiBuffer::getFirstEventTime() const throw()
  21345. {
  21346. return (bytesUsed > 0) ? *reinterpret_cast <const int*> (data.getData()) : 0;
  21347. }
  21348. int MidiBuffer::getLastEventTime() const throw()
  21349. {
  21350. if (bytesUsed == 0)
  21351. return 0;
  21352. const uint8* d = getData();
  21353. const uint8* const endData = d + bytesUsed;
  21354. for (;;)
  21355. {
  21356. const uint8* nextOne = d + 6 + * (const uint16*) (d + 4);
  21357. if (nextOne >= endData)
  21358. return *(const int*) d;
  21359. d = nextOne;
  21360. }
  21361. }
  21362. uint8* MidiBuffer::findEventAfter (uint8* d, const int samplePosition) const throw()
  21363. {
  21364. const uint8* const endData = getData() + bytesUsed;
  21365. while (d < endData && *(int*) d <= samplePosition)
  21366. {
  21367. d += 4;
  21368. d += 2 + *(uint16*) d;
  21369. }
  21370. return d;
  21371. }
  21372. MidiBuffer::Iterator::Iterator (const MidiBuffer& buffer_) throw()
  21373. : buffer (buffer_),
  21374. data (buffer_.getData())
  21375. {
  21376. }
  21377. MidiBuffer::Iterator::~Iterator() throw()
  21378. {
  21379. }
  21380. void MidiBuffer::Iterator::setNextSamplePosition (const int samplePosition) throw()
  21381. {
  21382. data = buffer.getData();
  21383. const uint8* dataEnd = data + buffer.bytesUsed;
  21384. while (data < dataEnd && *reinterpret_cast<const int*> (data) < samplePosition)
  21385. {
  21386. data += 4;
  21387. data += 2 + *(uint16*) data;
  21388. }
  21389. }
  21390. bool MidiBuffer::Iterator::getNextEvent (const uint8* &midiData,
  21391. int& numBytes,
  21392. int& samplePosition) throw()
  21393. {
  21394. if (data >= buffer.getData() + buffer.bytesUsed)
  21395. return false;
  21396. samplePosition = *(int*) data;
  21397. data += 4;
  21398. numBytes = *(uint16*) data;
  21399. data += 2;
  21400. midiData = data;
  21401. data += numBytes;
  21402. return true;
  21403. }
  21404. bool MidiBuffer::Iterator::getNextEvent (MidiMessage& result,
  21405. int& samplePosition) throw()
  21406. {
  21407. if (data >= buffer.getData() + buffer.bytesUsed)
  21408. return false;
  21409. samplePosition = *reinterpret_cast <const int*> (data);
  21410. data += 4;
  21411. const int numBytes = *reinterpret_cast <const uint16*> (data);
  21412. data += 2;
  21413. result = MidiMessage (data, numBytes, samplePosition);
  21414. data += numBytes;
  21415. return true;
  21416. }
  21417. END_JUCE_NAMESPACE
  21418. /*** End of inlined file: juce_MidiBuffer.cpp ***/
  21419. /*** Start of inlined file: juce_MidiFile.cpp ***/
  21420. BEGIN_JUCE_NAMESPACE
  21421. namespace MidiFileHelpers
  21422. {
  21423. static void writeVariableLengthInt (OutputStream& out, unsigned int v)
  21424. {
  21425. unsigned int buffer = v & 0x7F;
  21426. while ((v >>= 7) != 0)
  21427. {
  21428. buffer <<= 8;
  21429. buffer |= ((v & 0x7F) | 0x80);
  21430. }
  21431. for (;;)
  21432. {
  21433. out.writeByte ((char) buffer);
  21434. if (buffer & 0x80)
  21435. buffer >>= 8;
  21436. else
  21437. break;
  21438. }
  21439. }
  21440. static bool parseMidiHeader (const char* &data, short& timeFormat, short& fileType, short& numberOfTracks) throw()
  21441. {
  21442. unsigned int ch = (int) ByteOrder::bigEndianInt (data);
  21443. data += 4;
  21444. if (ch != ByteOrder::bigEndianInt ("MThd"))
  21445. {
  21446. bool ok = false;
  21447. if (ch == ByteOrder::bigEndianInt ("RIFF"))
  21448. {
  21449. for (int i = 0; i < 8; ++i)
  21450. {
  21451. ch = ByteOrder::bigEndianInt (data);
  21452. data += 4;
  21453. if (ch == ByteOrder::bigEndianInt ("MThd"))
  21454. {
  21455. ok = true;
  21456. break;
  21457. }
  21458. }
  21459. }
  21460. if (! ok)
  21461. return false;
  21462. }
  21463. unsigned int bytesRemaining = ByteOrder::bigEndianInt (data);
  21464. data += 4;
  21465. fileType = (short) ByteOrder::bigEndianShort (data);
  21466. data += 2;
  21467. numberOfTracks = (short) ByteOrder::bigEndianShort (data);
  21468. data += 2;
  21469. timeFormat = (short) ByteOrder::bigEndianShort (data);
  21470. data += 2;
  21471. bytesRemaining -= 6;
  21472. data += bytesRemaining;
  21473. return true;
  21474. }
  21475. static double convertTicksToSeconds (const double time,
  21476. const MidiMessageSequence& tempoEvents,
  21477. const int timeFormat)
  21478. {
  21479. if (timeFormat > 0)
  21480. {
  21481. int numer = 4, denom = 4;
  21482. double tempoTime = 0.0, correctedTempoTime = 0.0;
  21483. const double tickLen = 1.0 / (timeFormat & 0x7fff);
  21484. double secsPerTick = 0.5 * tickLen;
  21485. const int numEvents = tempoEvents.getNumEvents();
  21486. for (int i = 0; i < numEvents; ++i)
  21487. {
  21488. const MidiMessage& m = tempoEvents.getEventPointer(i)->message;
  21489. if (time <= m.getTimeStamp())
  21490. break;
  21491. if (timeFormat > 0)
  21492. {
  21493. correctedTempoTime = correctedTempoTime
  21494. + (m.getTimeStamp() - tempoTime) * secsPerTick;
  21495. }
  21496. else
  21497. {
  21498. correctedTempoTime = tickLen * m.getTimeStamp() / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21499. }
  21500. tempoTime = m.getTimeStamp();
  21501. if (m.isTempoMetaEvent())
  21502. secsPerTick = tickLen * m.getTempoSecondsPerQuarterNote();
  21503. else if (m.isTimeSignatureMetaEvent())
  21504. m.getTimeSignatureInfo (numer, denom);
  21505. while (i + 1 < numEvents)
  21506. {
  21507. const MidiMessage& m2 = tempoEvents.getEventPointer(i + 1)->message;
  21508. if (m2.getTimeStamp() == tempoTime)
  21509. {
  21510. ++i;
  21511. if (m2.isTempoMetaEvent())
  21512. secsPerTick = tickLen * m2.getTempoSecondsPerQuarterNote();
  21513. else if (m2.isTimeSignatureMetaEvent())
  21514. m2.getTimeSignatureInfo (numer, denom);
  21515. }
  21516. else
  21517. {
  21518. break;
  21519. }
  21520. }
  21521. }
  21522. return correctedTempoTime + (time - tempoTime) * secsPerTick;
  21523. }
  21524. else
  21525. {
  21526. return time / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21527. }
  21528. }
  21529. }
  21530. MidiFile::MidiFile() throw()
  21531. : timeFormat ((short) (unsigned short) 0xe728)
  21532. {
  21533. }
  21534. MidiFile::~MidiFile() throw()
  21535. {
  21536. clear();
  21537. }
  21538. void MidiFile::clear() throw()
  21539. {
  21540. tracks.clear();
  21541. }
  21542. int MidiFile::getNumTracks() const throw()
  21543. {
  21544. return tracks.size();
  21545. }
  21546. const MidiMessageSequence* MidiFile::getTrack (const int index) const throw()
  21547. {
  21548. return tracks [index];
  21549. }
  21550. void MidiFile::addTrack (const MidiMessageSequence& trackSequence) throw()
  21551. {
  21552. tracks.add (new MidiMessageSequence (trackSequence));
  21553. }
  21554. short MidiFile::getTimeFormat() const throw()
  21555. {
  21556. return timeFormat;
  21557. }
  21558. void MidiFile::setTicksPerQuarterNote (const int ticks) throw()
  21559. {
  21560. timeFormat = (short)ticks;
  21561. }
  21562. void MidiFile::setSmpteTimeFormat (const int framesPerSecond,
  21563. const int subframeResolution) throw()
  21564. {
  21565. timeFormat = (short) (((-framesPerSecond) << 8) | subframeResolution);
  21566. }
  21567. void MidiFile::findAllTempoEvents (MidiMessageSequence& tempoChangeEvents) const
  21568. {
  21569. for (int i = tracks.size(); --i >= 0;)
  21570. {
  21571. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21572. for (int j = 0; j < numEvents; ++j)
  21573. {
  21574. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21575. if (m.isTempoMetaEvent())
  21576. tempoChangeEvents.addEvent (m);
  21577. }
  21578. }
  21579. }
  21580. void MidiFile::findAllTimeSigEvents (MidiMessageSequence& timeSigEvents) const
  21581. {
  21582. for (int i = tracks.size(); --i >= 0;)
  21583. {
  21584. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21585. for (int j = 0; j < numEvents; ++j)
  21586. {
  21587. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21588. if (m.isTimeSignatureMetaEvent())
  21589. timeSigEvents.addEvent (m);
  21590. }
  21591. }
  21592. }
  21593. double MidiFile::getLastTimestamp() const
  21594. {
  21595. double t = 0.0;
  21596. for (int i = tracks.size(); --i >= 0;)
  21597. t = jmax (t, tracks.getUnchecked(i)->getEndTime());
  21598. return t;
  21599. }
  21600. bool MidiFile::readFrom (InputStream& sourceStream)
  21601. {
  21602. clear();
  21603. MemoryBlock data;
  21604. const int maxSensibleMidiFileSize = 2 * 1024 * 1024;
  21605. // (put a sanity-check on the file size, as midi files are generally small)
  21606. if (sourceStream.readIntoMemoryBlock (data, maxSensibleMidiFileSize))
  21607. {
  21608. size_t size = data.getSize();
  21609. const char* d = (char*) data.getData();
  21610. short fileType, expectedTracks;
  21611. if (size > 16 && MidiFileHelpers::parseMidiHeader (d, timeFormat, fileType, expectedTracks))
  21612. {
  21613. size -= (int) (d - (char*) data.getData());
  21614. int track = 0;
  21615. while (size > 0 && track < expectedTracks)
  21616. {
  21617. const int chunkType = (int) ByteOrder::bigEndianInt (d);
  21618. d += 4;
  21619. const int chunkSize = (int) ByteOrder::bigEndianInt (d);
  21620. d += 4;
  21621. if (chunkSize <= 0)
  21622. break;
  21623. if (size < 0)
  21624. return false;
  21625. if (chunkType == (int) ByteOrder::bigEndianInt ("MTrk"))
  21626. {
  21627. readNextTrack (d, chunkSize);
  21628. }
  21629. size -= chunkSize + 8;
  21630. d += chunkSize;
  21631. ++track;
  21632. }
  21633. return true;
  21634. }
  21635. }
  21636. return false;
  21637. }
  21638. // a comparator that puts all the note-offs before note-ons that have the same time
  21639. int MidiFile::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  21640. const MidiMessageSequence::MidiEventHolder* const second) throw()
  21641. {
  21642. const double diff = (first->message.getTimeStamp() - second->message.getTimeStamp());
  21643. if (diff == 0)
  21644. {
  21645. if (first->message.isNoteOff() && second->message.isNoteOn())
  21646. return -1;
  21647. else if (first->message.isNoteOn() && second->message.isNoteOff())
  21648. return 1;
  21649. else
  21650. return 0;
  21651. }
  21652. else
  21653. {
  21654. return (diff > 0) ? 1 : -1;
  21655. }
  21656. }
  21657. void MidiFile::readNextTrack (const char* data, int size)
  21658. {
  21659. double time = 0;
  21660. char lastStatusByte = 0;
  21661. MidiMessageSequence result;
  21662. while (size > 0)
  21663. {
  21664. int bytesUsed;
  21665. const int delay = MidiMessage::readVariableLengthVal ((const uint8*) data, bytesUsed);
  21666. data += bytesUsed;
  21667. size -= bytesUsed;
  21668. time += delay;
  21669. int messSize = 0;
  21670. const MidiMessage mm ((const uint8*) data, size, messSize, lastStatusByte, time);
  21671. if (messSize <= 0)
  21672. break;
  21673. size -= messSize;
  21674. data += messSize;
  21675. result.addEvent (mm);
  21676. const char firstByte = *(mm.getRawData());
  21677. if ((firstByte & 0xf0) != 0xf0)
  21678. lastStatusByte = firstByte;
  21679. }
  21680. // use a sort that puts all the note-offs before note-ons that have the same time
  21681. result.list.sort (*this, true);
  21682. result.updateMatchedPairs();
  21683. addTrack (result);
  21684. }
  21685. void MidiFile::convertTimestampTicksToSeconds()
  21686. {
  21687. MidiMessageSequence tempoEvents;
  21688. findAllTempoEvents (tempoEvents);
  21689. findAllTimeSigEvents (tempoEvents);
  21690. for (int i = 0; i < tracks.size(); ++i)
  21691. {
  21692. MidiMessageSequence& ms = *tracks.getUnchecked(i);
  21693. for (int j = ms.getNumEvents(); --j >= 0;)
  21694. {
  21695. MidiMessage& m = ms.getEventPointer(j)->message;
  21696. m.setTimeStamp (MidiFileHelpers::convertTicksToSeconds (m.getTimeStamp(),
  21697. tempoEvents,
  21698. timeFormat));
  21699. }
  21700. }
  21701. }
  21702. bool MidiFile::writeTo (OutputStream& out)
  21703. {
  21704. out.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MThd"));
  21705. out.writeIntBigEndian (6);
  21706. out.writeShortBigEndian (1); // type
  21707. out.writeShortBigEndian ((short) tracks.size());
  21708. out.writeShortBigEndian (timeFormat);
  21709. for (int i = 0; i < tracks.size(); ++i)
  21710. writeTrack (out, i);
  21711. out.flush();
  21712. return true;
  21713. }
  21714. void MidiFile::writeTrack (OutputStream& mainOut,
  21715. const int trackNum)
  21716. {
  21717. MemoryOutputStream out;
  21718. const MidiMessageSequence& ms = *tracks[trackNum];
  21719. int lastTick = 0;
  21720. char lastStatusByte = 0;
  21721. for (int i = 0; i < ms.getNumEvents(); ++i)
  21722. {
  21723. const MidiMessage& mm = ms.getEventPointer(i)->message;
  21724. const int tick = roundToInt (mm.getTimeStamp());
  21725. const int delta = jmax (0, tick - lastTick);
  21726. MidiFileHelpers::writeVariableLengthInt (out, delta);
  21727. lastTick = tick;
  21728. const char statusByte = *(mm.getRawData());
  21729. if ((statusByte == lastStatusByte)
  21730. && ((statusByte & 0xf0) != 0xf0)
  21731. && i > 0
  21732. && mm.getRawDataSize() > 1)
  21733. {
  21734. out.write (mm.getRawData() + 1, mm.getRawDataSize() - 1);
  21735. }
  21736. else
  21737. {
  21738. out.write (mm.getRawData(), mm.getRawDataSize());
  21739. }
  21740. lastStatusByte = statusByte;
  21741. }
  21742. out.writeByte (0);
  21743. const MidiMessage m (MidiMessage::endOfTrack());
  21744. out.write (m.getRawData(),
  21745. m.getRawDataSize());
  21746. mainOut.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MTrk"));
  21747. mainOut.writeIntBigEndian ((int) out.getDataSize());
  21748. mainOut.write (out.getData(), (int) out.getDataSize());
  21749. }
  21750. END_JUCE_NAMESPACE
  21751. /*** End of inlined file: juce_MidiFile.cpp ***/
  21752. /*** Start of inlined file: juce_MidiKeyboardState.cpp ***/
  21753. BEGIN_JUCE_NAMESPACE
  21754. MidiKeyboardState::MidiKeyboardState()
  21755. {
  21756. zeromem (noteStates, sizeof (noteStates));
  21757. }
  21758. MidiKeyboardState::~MidiKeyboardState()
  21759. {
  21760. }
  21761. void MidiKeyboardState::reset()
  21762. {
  21763. const ScopedLock sl (lock);
  21764. zeromem (noteStates, sizeof (noteStates));
  21765. eventsToAdd.clear();
  21766. }
  21767. bool MidiKeyboardState::isNoteOn (const int midiChannel, const int n) const throw()
  21768. {
  21769. jassert (midiChannel >= 0 && midiChannel <= 16);
  21770. return ((unsigned int) n) < 128
  21771. && (noteStates[n] & (1 << (midiChannel - 1))) != 0;
  21772. }
  21773. bool MidiKeyboardState::isNoteOnForChannels (const int midiChannelMask, const int n) const throw()
  21774. {
  21775. return ((unsigned int) n) < 128
  21776. && (noteStates[n] & midiChannelMask) != 0;
  21777. }
  21778. void MidiKeyboardState::noteOn (const int midiChannel, const int midiNoteNumber, const float velocity)
  21779. {
  21780. jassert (midiChannel >= 0 && midiChannel <= 16);
  21781. jassert (((unsigned int) midiNoteNumber) < 128);
  21782. const ScopedLock sl (lock);
  21783. if (((unsigned int) midiNoteNumber) < 128)
  21784. {
  21785. const int timeNow = (int) Time::getMillisecondCounter();
  21786. eventsToAdd.addEvent (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity), timeNow);
  21787. eventsToAdd.clear (0, timeNow - 500);
  21788. noteOnInternal (midiChannel, midiNoteNumber, velocity);
  21789. }
  21790. }
  21791. void MidiKeyboardState::noteOnInternal (const int midiChannel, const int midiNoteNumber, const float velocity)
  21792. {
  21793. if (((unsigned int) midiNoteNumber) < 128)
  21794. {
  21795. noteStates [midiNoteNumber] |= (1 << (midiChannel - 1));
  21796. for (int i = listeners.size(); --i >= 0;)
  21797. ((MidiKeyboardStateListener*) listeners.getUnchecked(i))
  21798. ->handleNoteOn (this, midiChannel, midiNoteNumber, velocity);
  21799. }
  21800. }
  21801. void MidiKeyboardState::noteOff (const int midiChannel, const int midiNoteNumber)
  21802. {
  21803. const ScopedLock sl (lock);
  21804. if (isNoteOn (midiChannel, midiNoteNumber))
  21805. {
  21806. const int timeNow = (int) Time::getMillisecondCounter();
  21807. eventsToAdd.addEvent (MidiMessage::noteOff (midiChannel, midiNoteNumber), timeNow);
  21808. eventsToAdd.clear (0, timeNow - 500);
  21809. noteOffInternal (midiChannel, midiNoteNumber);
  21810. }
  21811. }
  21812. void MidiKeyboardState::noteOffInternal (const int midiChannel, const int midiNoteNumber)
  21813. {
  21814. if (isNoteOn (midiChannel, midiNoteNumber))
  21815. {
  21816. noteStates [midiNoteNumber] &= ~(1 << (midiChannel - 1));
  21817. for (int i = listeners.size(); --i >= 0;)
  21818. ((MidiKeyboardStateListener*) listeners.getUnchecked(i))
  21819. ->handleNoteOff (this, midiChannel, midiNoteNumber);
  21820. }
  21821. }
  21822. void MidiKeyboardState::allNotesOff (const int midiChannel)
  21823. {
  21824. const ScopedLock sl (lock);
  21825. if (midiChannel <= 0)
  21826. {
  21827. for (int i = 1; i <= 16; ++i)
  21828. allNotesOff (i);
  21829. }
  21830. else
  21831. {
  21832. for (int i = 0; i < 128; ++i)
  21833. noteOff (midiChannel, i);
  21834. }
  21835. }
  21836. void MidiKeyboardState::processNextMidiEvent (const MidiMessage& message)
  21837. {
  21838. if (message.isNoteOn())
  21839. {
  21840. noteOnInternal (message.getChannel(), message.getNoteNumber(), message.getFloatVelocity());
  21841. }
  21842. else if (message.isNoteOff())
  21843. {
  21844. noteOffInternal (message.getChannel(), message.getNoteNumber());
  21845. }
  21846. else if (message.isAllNotesOff())
  21847. {
  21848. for (int i = 0; i < 128; ++i)
  21849. noteOffInternal (message.getChannel(), i);
  21850. }
  21851. }
  21852. void MidiKeyboardState::processNextMidiBuffer (MidiBuffer& buffer,
  21853. const int startSample,
  21854. const int numSamples,
  21855. const bool injectIndirectEvents)
  21856. {
  21857. MidiBuffer::Iterator i (buffer);
  21858. MidiMessage message (0xf4, 0.0);
  21859. int time;
  21860. const ScopedLock sl (lock);
  21861. while (i.getNextEvent (message, time))
  21862. processNextMidiEvent (message);
  21863. if (injectIndirectEvents)
  21864. {
  21865. MidiBuffer::Iterator i2 (eventsToAdd);
  21866. const int firstEventToAdd = eventsToAdd.getFirstEventTime();
  21867. const double scaleFactor = numSamples / (double) (eventsToAdd.getLastEventTime() + 1 - firstEventToAdd);
  21868. while (i2.getNextEvent (message, time))
  21869. {
  21870. const int pos = jlimit (0, numSamples - 1, roundToInt ((time - firstEventToAdd) * scaleFactor));
  21871. buffer.addEvent (message, startSample + pos);
  21872. }
  21873. }
  21874. eventsToAdd.clear();
  21875. }
  21876. void MidiKeyboardState::addListener (MidiKeyboardStateListener* const listener) throw()
  21877. {
  21878. const ScopedLock sl (lock);
  21879. listeners.addIfNotAlreadyThere (listener);
  21880. }
  21881. void MidiKeyboardState::removeListener (MidiKeyboardStateListener* const listener) throw()
  21882. {
  21883. const ScopedLock sl (lock);
  21884. listeners.removeValue (listener);
  21885. }
  21886. END_JUCE_NAMESPACE
  21887. /*** End of inlined file: juce_MidiKeyboardState.cpp ***/
  21888. /*** Start of inlined file: juce_MidiMessage.cpp ***/
  21889. BEGIN_JUCE_NAMESPACE
  21890. int MidiMessage::readVariableLengthVal (const uint8* data,
  21891. int& numBytesUsed) throw()
  21892. {
  21893. numBytesUsed = 0;
  21894. int v = 0;
  21895. int i;
  21896. do
  21897. {
  21898. i = (int) *data++;
  21899. if (++numBytesUsed > 6)
  21900. break;
  21901. v = (v << 7) + (i & 0x7f);
  21902. } while (i & 0x80);
  21903. return v;
  21904. }
  21905. int MidiMessage::getMessageLengthFromFirstByte (const uint8 firstByte) throw()
  21906. {
  21907. // this method only works for valid starting bytes of a short midi message
  21908. jassert (firstByte >= 0x80
  21909. && firstByte != 0xf0
  21910. && firstByte != 0xf7);
  21911. static const char messageLengths[] =
  21912. {
  21913. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21914. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21915. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21916. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21917. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  21918. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  21919. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21920. 1, 2, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
  21921. };
  21922. return messageLengths [firstByte & 0x7f];
  21923. }
  21924. MidiMessage::MidiMessage (const uint8* const d,
  21925. const int dataSize,
  21926. const double t) throw()
  21927. : timeStamp (t),
  21928. message (0),
  21929. size (dataSize)
  21930. {
  21931. jassert (dataSize > 0);
  21932. if (dataSize <= 4)
  21933. data = (uint8*) &message;
  21934. else
  21935. data = (uint8*) juce_malloc (dataSize);
  21936. memcpy (data, d, dataSize);
  21937. // check that the length matches the data..
  21938. jassert (size > 3 || *d >= 0xf0 || getMessageLengthFromFirstByte (*d) == size);
  21939. }
  21940. MidiMessage::MidiMessage (const int byte1,
  21941. const double t) throw()
  21942. : timeStamp (t),
  21943. data ((uint8*) &message),
  21944. size (1)
  21945. {
  21946. data[0] = (uint8) byte1;
  21947. // check that the length matches the data..
  21948. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 1);
  21949. }
  21950. MidiMessage::MidiMessage (const int byte1,
  21951. const int byte2,
  21952. const double t) throw()
  21953. : timeStamp (t),
  21954. data ((uint8*) &message),
  21955. size (2)
  21956. {
  21957. data[0] = (uint8) byte1;
  21958. data[1] = (uint8) byte2;
  21959. // check that the length matches the data..
  21960. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 2);
  21961. }
  21962. MidiMessage::MidiMessage (const int byte1,
  21963. const int byte2,
  21964. const int byte3,
  21965. const double t) throw()
  21966. : timeStamp (t),
  21967. data ((uint8*) &message),
  21968. size (3)
  21969. {
  21970. data[0] = (uint8) byte1;
  21971. data[1] = (uint8) byte2;
  21972. data[2] = (uint8) byte3;
  21973. // check that the length matches the data..
  21974. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 3);
  21975. }
  21976. MidiMessage::MidiMessage (const MidiMessage& other) throw()
  21977. : timeStamp (other.timeStamp),
  21978. message (other.message),
  21979. size (other.size)
  21980. {
  21981. if (other.data != (uint8*) &other.message)
  21982. {
  21983. data = (uint8*) juce_malloc (size);
  21984. memcpy (data, other.data, size);
  21985. }
  21986. else
  21987. {
  21988. data = (uint8*) &message;
  21989. }
  21990. }
  21991. MidiMessage::MidiMessage (const MidiMessage& other,
  21992. const double newTimeStamp) throw()
  21993. : timeStamp (newTimeStamp),
  21994. message (other.message),
  21995. size (other.size)
  21996. {
  21997. if (other.data != (uint8*) &other.message)
  21998. {
  21999. data = (uint8*) juce_malloc (size);
  22000. memcpy (data, other.data, size);
  22001. }
  22002. else
  22003. {
  22004. data = (uint8*) &message;
  22005. }
  22006. }
  22007. MidiMessage::MidiMessage (const uint8* src,
  22008. int sz,
  22009. int& numBytesUsed,
  22010. const uint8 lastStatusByte,
  22011. double t) throw()
  22012. : timeStamp (t),
  22013. data ((uint8*) &message),
  22014. message (0)
  22015. {
  22016. unsigned int byte = (unsigned int) *src;
  22017. if (byte < 0x80)
  22018. {
  22019. byte = (unsigned int) (uint8) lastStatusByte;
  22020. numBytesUsed = -1;
  22021. }
  22022. else
  22023. {
  22024. numBytesUsed = 0;
  22025. --sz;
  22026. ++src;
  22027. }
  22028. if (byte >= 0x80)
  22029. {
  22030. if (byte == 0xf0)
  22031. {
  22032. const uint8* d = (const uint8*) src;
  22033. while (d < src + sz)
  22034. {
  22035. if (*d >= 0x80) // stop if we hit a status byte, and don't include it in this message
  22036. {
  22037. if (*d == 0xf7) // include an 0xf7 if we hit one
  22038. ++d;
  22039. break;
  22040. }
  22041. ++d;
  22042. }
  22043. size = 1 + (int) (d - src);
  22044. data = (uint8*) juce_malloc (size);
  22045. *data = (uint8) byte;
  22046. memcpy (data + 1, src, size - 1);
  22047. }
  22048. else if (byte == 0xff)
  22049. {
  22050. int n;
  22051. const int bytesLeft = readVariableLengthVal (src + 1, n);
  22052. size = jmin (sz + 1, n + 2 + bytesLeft);
  22053. data = (uint8*) juce_malloc (size);
  22054. *data = (uint8) byte;
  22055. memcpy (data + 1, src, size - 1);
  22056. }
  22057. else
  22058. {
  22059. size = getMessageLengthFromFirstByte ((uint8) byte);
  22060. *data = (uint8) byte;
  22061. if (size > 1)
  22062. {
  22063. data[1] = src[0];
  22064. if (size > 2)
  22065. data[2] = src[1];
  22066. }
  22067. }
  22068. numBytesUsed += size;
  22069. }
  22070. else
  22071. {
  22072. message = 0;
  22073. size = 0;
  22074. }
  22075. }
  22076. MidiMessage& MidiMessage::operator= (const MidiMessage& other) throw()
  22077. {
  22078. if (this != &other)
  22079. {
  22080. timeStamp = other.timeStamp;
  22081. size = other.size;
  22082. message = other.message;
  22083. if (data != (uint8*) &message)
  22084. juce_free (data);
  22085. if (other.data != (uint8*) &other.message)
  22086. {
  22087. data = (uint8*) juce_malloc (size);
  22088. memcpy (data, other.data, size);
  22089. }
  22090. else
  22091. {
  22092. data = (uint8*) &message;
  22093. }
  22094. }
  22095. return *this;
  22096. }
  22097. MidiMessage::~MidiMessage() throw()
  22098. {
  22099. if (data != (uint8*) &message)
  22100. juce_free (data);
  22101. }
  22102. int MidiMessage::getChannel() const throw()
  22103. {
  22104. if ((data[0] & 0xf0) != 0xf0)
  22105. return (data[0] & 0xf) + 1;
  22106. else
  22107. return 0;
  22108. }
  22109. bool MidiMessage::isForChannel (const int channel) const throw()
  22110. {
  22111. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22112. return ((data[0] & 0xf) == channel - 1)
  22113. && ((data[0] & 0xf0) != 0xf0);
  22114. }
  22115. void MidiMessage::setChannel (const int channel) throw()
  22116. {
  22117. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22118. if ((data[0] & 0xf0) != (uint8) 0xf0)
  22119. data[0] = (uint8) ((data[0] & (uint8)0xf0)
  22120. | (uint8)(channel - 1));
  22121. }
  22122. bool MidiMessage::isNoteOn (const bool returnTrueForVelocity0) const throw()
  22123. {
  22124. return ((data[0] & 0xf0) == 0x90)
  22125. && (returnTrueForVelocity0 || data[2] != 0);
  22126. }
  22127. bool MidiMessage::isNoteOff (const bool returnTrueForNoteOnVelocity0) const throw()
  22128. {
  22129. return ((data[0] & 0xf0) == 0x80)
  22130. || (returnTrueForNoteOnVelocity0 && (data[2] == 0) && ((data[0] & 0xf0) == 0x90));
  22131. }
  22132. bool MidiMessage::isNoteOnOrOff() const throw()
  22133. {
  22134. const int d = data[0] & 0xf0;
  22135. return (d == 0x90) || (d == 0x80);
  22136. }
  22137. int MidiMessage::getNoteNumber() const throw()
  22138. {
  22139. return data[1];
  22140. }
  22141. void MidiMessage::setNoteNumber (const int newNoteNumber) throw()
  22142. {
  22143. if (isNoteOnOrOff())
  22144. data[1] = (uint8) jlimit (0, 127, newNoteNumber);
  22145. }
  22146. uint8 MidiMessage::getVelocity() const throw()
  22147. {
  22148. if (isNoteOnOrOff())
  22149. return data[2];
  22150. else
  22151. return 0;
  22152. }
  22153. float MidiMessage::getFloatVelocity() const throw()
  22154. {
  22155. return getVelocity() * (1.0f / 127.0f);
  22156. }
  22157. void MidiMessage::setVelocity (const float newVelocity) throw()
  22158. {
  22159. if (isNoteOnOrOff())
  22160. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (newVelocity * 127.0f));
  22161. }
  22162. void MidiMessage::multiplyVelocity (const float scaleFactor) throw()
  22163. {
  22164. if (isNoteOnOrOff())
  22165. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (scaleFactor * data[2]));
  22166. }
  22167. bool MidiMessage::isAftertouch() const throw()
  22168. {
  22169. return (data[0] & 0xf0) == 0xa0;
  22170. }
  22171. int MidiMessage::getAfterTouchValue() const throw()
  22172. {
  22173. return data[2];
  22174. }
  22175. const MidiMessage MidiMessage::aftertouchChange (const int channel,
  22176. const int noteNum,
  22177. const int aftertouchValue) throw()
  22178. {
  22179. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22180. jassert (((unsigned int) noteNum) <= 127);
  22181. jassert (((unsigned int) aftertouchValue) <= 127);
  22182. return MidiMessage (0xa0 | jlimit (0, 15, channel - 1),
  22183. noteNum & 0x7f,
  22184. aftertouchValue & 0x7f);
  22185. }
  22186. bool MidiMessage::isChannelPressure() const throw()
  22187. {
  22188. return (data[0] & 0xf0) == 0xd0;
  22189. }
  22190. int MidiMessage::getChannelPressureValue() const throw()
  22191. {
  22192. jassert (isChannelPressure());
  22193. return data[1];
  22194. }
  22195. const MidiMessage MidiMessage::channelPressureChange (const int channel,
  22196. const int pressure) throw()
  22197. {
  22198. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22199. jassert (((unsigned int) pressure) <= 127);
  22200. return MidiMessage (0xd0 | jlimit (0, 15, channel - 1),
  22201. pressure & 0x7f);
  22202. }
  22203. bool MidiMessage::isProgramChange() const throw()
  22204. {
  22205. return (data[0] & 0xf0) == 0xc0;
  22206. }
  22207. int MidiMessage::getProgramChangeNumber() const throw()
  22208. {
  22209. return data[1];
  22210. }
  22211. const MidiMessage MidiMessage::programChange (const int channel,
  22212. const int programNumber) throw()
  22213. {
  22214. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22215. return MidiMessage (0xc0 | jlimit (0, 15, channel - 1),
  22216. programNumber & 0x7f);
  22217. }
  22218. bool MidiMessage::isPitchWheel() const throw()
  22219. {
  22220. return (data[0] & 0xf0) == 0xe0;
  22221. }
  22222. int MidiMessage::getPitchWheelValue() const throw()
  22223. {
  22224. return data[1] | (data[2] << 7);
  22225. }
  22226. const MidiMessage MidiMessage::pitchWheel (const int channel,
  22227. const int position) throw()
  22228. {
  22229. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22230. jassert (((unsigned int) position) <= 0x3fff);
  22231. return MidiMessage (0xe0 | jlimit (0, 15, channel - 1),
  22232. position & 127,
  22233. (position >> 7) & 127);
  22234. }
  22235. bool MidiMessage::isController() const throw()
  22236. {
  22237. return (data[0] & 0xf0) == 0xb0;
  22238. }
  22239. int MidiMessage::getControllerNumber() const throw()
  22240. {
  22241. jassert (isController());
  22242. return data[1];
  22243. }
  22244. int MidiMessage::getControllerValue() const throw()
  22245. {
  22246. jassert (isController());
  22247. return data[2];
  22248. }
  22249. const MidiMessage MidiMessage::controllerEvent (const int channel,
  22250. const int controllerType,
  22251. const int value) throw()
  22252. {
  22253. // the channel must be between 1 and 16 inclusive
  22254. jassert (channel > 0 && channel <= 16);
  22255. return MidiMessage (0xb0 | jlimit (0, 15, channel - 1),
  22256. controllerType & 127,
  22257. value & 127);
  22258. }
  22259. const MidiMessage MidiMessage::noteOn (const int channel,
  22260. const int noteNumber,
  22261. const float velocity) throw()
  22262. {
  22263. return noteOn (channel, noteNumber, (uint8)(velocity * 127.0f));
  22264. }
  22265. const MidiMessage MidiMessage::noteOn (const int channel,
  22266. const int noteNumber,
  22267. const uint8 velocity) throw()
  22268. {
  22269. jassert (channel > 0 && channel <= 16);
  22270. jassert (((unsigned int) noteNumber) <= 127);
  22271. return MidiMessage (0x90 | jlimit (0, 15, channel - 1),
  22272. noteNumber & 127,
  22273. jlimit (0, 127, roundToInt (velocity)));
  22274. }
  22275. const MidiMessage MidiMessage::noteOff (const int channel,
  22276. const int noteNumber) throw()
  22277. {
  22278. jassert (channel > 0 && channel <= 16);
  22279. jassert (((unsigned int) noteNumber) <= 127);
  22280. return MidiMessage (0x80 | jlimit (0, 15, channel - 1), noteNumber & 127, 0);
  22281. }
  22282. const MidiMessage MidiMessage::allNotesOff (const int channel) throw()
  22283. {
  22284. jassert (channel > 0 && channel <= 16);
  22285. return controllerEvent (channel, 123, 0);
  22286. }
  22287. bool MidiMessage::isAllNotesOff() const throw()
  22288. {
  22289. return (data[0] & 0xf0) == 0xb0
  22290. && data[1] == 123;
  22291. }
  22292. const MidiMessage MidiMessage::allSoundOff (const int channel) throw()
  22293. {
  22294. return controllerEvent (channel, 120, 0);
  22295. }
  22296. bool MidiMessage::isAllSoundOff() const throw()
  22297. {
  22298. return (data[0] & 0xf0) == 0xb0
  22299. && data[1] == 120;
  22300. }
  22301. const MidiMessage MidiMessage::allControllersOff (const int channel) throw()
  22302. {
  22303. return controllerEvent (channel, 121, 0);
  22304. }
  22305. const MidiMessage MidiMessage::masterVolume (const float volume) throw()
  22306. {
  22307. const int vol = jlimit (0, 0x3fff, roundToInt (volume * 0x4000));
  22308. uint8 buf[8];
  22309. buf[0] = 0xf0;
  22310. buf[1] = 0x7f;
  22311. buf[2] = 0x7f;
  22312. buf[3] = 0x04;
  22313. buf[4] = 0x01;
  22314. buf[5] = (uint8) (vol & 0x7f);
  22315. buf[6] = (uint8) (vol >> 7);
  22316. buf[7] = 0xf7;
  22317. return MidiMessage (buf, 8);
  22318. }
  22319. bool MidiMessage::isSysEx() const throw()
  22320. {
  22321. return *data == 0xf0;
  22322. }
  22323. const MidiMessage MidiMessage::createSysExMessage (const uint8* sysexData,
  22324. const int dataSize) throw()
  22325. {
  22326. MemoryBlock mm (dataSize + 2);
  22327. uint8* const m = (uint8*) mm.getData();
  22328. m[0] = 0xf0;
  22329. memcpy (m + 1, sysexData, dataSize);
  22330. m[dataSize + 1] = 0xf7;
  22331. return MidiMessage (m, dataSize + 2);
  22332. }
  22333. const uint8* MidiMessage::getSysExData() const throw()
  22334. {
  22335. return (isSysEx()) ? getRawData() + 1
  22336. : 0;
  22337. }
  22338. int MidiMessage::getSysExDataSize() const throw()
  22339. {
  22340. return (isSysEx()) ? size - 2
  22341. : 0;
  22342. }
  22343. bool MidiMessage::isMetaEvent() const throw()
  22344. {
  22345. return *data == 0xff;
  22346. }
  22347. bool MidiMessage::isActiveSense() const throw()
  22348. {
  22349. return *data == 0xfe;
  22350. }
  22351. int MidiMessage::getMetaEventType() const throw()
  22352. {
  22353. if (*data != 0xff)
  22354. return -1;
  22355. else
  22356. return data[1];
  22357. }
  22358. int MidiMessage::getMetaEventLength() const throw()
  22359. {
  22360. if (*data == 0xff)
  22361. {
  22362. int n;
  22363. return jmin (size - 2, readVariableLengthVal (data + 2, n));
  22364. }
  22365. return 0;
  22366. }
  22367. const uint8* MidiMessage::getMetaEventData() const throw()
  22368. {
  22369. int n;
  22370. const uint8* d = data + 2;
  22371. readVariableLengthVal (d, n);
  22372. return d + n;
  22373. }
  22374. bool MidiMessage::isTrackMetaEvent() const throw()
  22375. {
  22376. return getMetaEventType() == 0;
  22377. }
  22378. bool MidiMessage::isEndOfTrackMetaEvent() const throw()
  22379. {
  22380. return getMetaEventType() == 47;
  22381. }
  22382. bool MidiMessage::isTextMetaEvent() const throw()
  22383. {
  22384. const int t = getMetaEventType();
  22385. return t > 0 && t < 16;
  22386. }
  22387. const String MidiMessage::getTextFromTextMetaEvent() const throw()
  22388. {
  22389. return String ((const char*) getMetaEventData(),
  22390. getMetaEventLength());
  22391. }
  22392. bool MidiMessage::isTrackNameEvent() const throw()
  22393. {
  22394. return (data[1] == 3)
  22395. && (*data == 0xff);
  22396. }
  22397. bool MidiMessage::isTempoMetaEvent() const throw()
  22398. {
  22399. return (data[1] == 81)
  22400. && (*data == 0xff);
  22401. }
  22402. bool MidiMessage::isMidiChannelMetaEvent() const throw()
  22403. {
  22404. return (data[1] == 0x20)
  22405. && (*data == 0xff)
  22406. && (data[2] == 1);
  22407. }
  22408. int MidiMessage::getMidiChannelMetaEventChannel() const throw()
  22409. {
  22410. return data[3] + 1;
  22411. }
  22412. double MidiMessage::getTempoSecondsPerQuarterNote() const throw()
  22413. {
  22414. if (! isTempoMetaEvent())
  22415. return 0.0;
  22416. const uint8* const d = getMetaEventData();
  22417. return (((unsigned int) d[0] << 16)
  22418. | ((unsigned int) d[1] << 8)
  22419. | d[2])
  22420. / 1000000.0;
  22421. }
  22422. double MidiMessage::getTempoMetaEventTickLength (const short timeFormat) const throw()
  22423. {
  22424. if (timeFormat > 0)
  22425. {
  22426. if (! isTempoMetaEvent())
  22427. return 0.5 / timeFormat;
  22428. return getTempoSecondsPerQuarterNote() / timeFormat;
  22429. }
  22430. else
  22431. {
  22432. const int frameCode = (-timeFormat) >> 8;
  22433. double framesPerSecond;
  22434. switch (frameCode)
  22435. {
  22436. case 24: framesPerSecond = 24.0; break;
  22437. case 25: framesPerSecond = 25.0; break;
  22438. case 29: framesPerSecond = 29.97; break;
  22439. case 30: framesPerSecond = 30.0; break;
  22440. default: framesPerSecond = 30.0; break;
  22441. }
  22442. return (1.0 / framesPerSecond) / (timeFormat & 0xff);
  22443. }
  22444. }
  22445. const MidiMessage MidiMessage::tempoMetaEvent (int microsecondsPerQuarterNote) throw()
  22446. {
  22447. uint8 d[8];
  22448. d[0] = 0xff;
  22449. d[1] = 81;
  22450. d[2] = 3;
  22451. d[3] = (uint8) (microsecondsPerQuarterNote >> 16);
  22452. d[4] = (uint8) ((microsecondsPerQuarterNote >> 8) & 0xff);
  22453. d[5] = (uint8) (microsecondsPerQuarterNote & 0xff);
  22454. return MidiMessage (d, 6, 0.0);
  22455. }
  22456. bool MidiMessage::isTimeSignatureMetaEvent() const throw()
  22457. {
  22458. return (data[1] == 0x58)
  22459. && (*data == (uint8) 0xff);
  22460. }
  22461. void MidiMessage::getTimeSignatureInfo (int& numerator,
  22462. int& denominator) const throw()
  22463. {
  22464. if (isTimeSignatureMetaEvent())
  22465. {
  22466. const uint8* const d = getMetaEventData();
  22467. numerator = d[0];
  22468. denominator = 1 << d[1];
  22469. }
  22470. else
  22471. {
  22472. numerator = 4;
  22473. denominator = 4;
  22474. }
  22475. }
  22476. const MidiMessage MidiMessage::timeSignatureMetaEvent (const int numerator,
  22477. const int denominator) throw()
  22478. {
  22479. uint8 d[8];
  22480. d[0] = 0xff;
  22481. d[1] = 0x58;
  22482. d[2] = 0x04;
  22483. d[3] = (uint8) numerator;
  22484. int n = 1;
  22485. int powerOfTwo = 0;
  22486. while (n < denominator)
  22487. {
  22488. n <<= 1;
  22489. ++powerOfTwo;
  22490. }
  22491. d[4] = (uint8) powerOfTwo;
  22492. d[5] = 0x01;
  22493. d[6] = 96;
  22494. return MidiMessage (d, 7, 0.0);
  22495. }
  22496. const MidiMessage MidiMessage::midiChannelMetaEvent (const int channel) throw()
  22497. {
  22498. uint8 d[8];
  22499. d[0] = 0xff;
  22500. d[1] = 0x20;
  22501. d[2] = 0x01;
  22502. d[3] = (uint8) jlimit (0, 0xff, channel - 1);
  22503. return MidiMessage (d, 4, 0.0);
  22504. }
  22505. bool MidiMessage::isKeySignatureMetaEvent() const throw()
  22506. {
  22507. return getMetaEventType() == 89;
  22508. }
  22509. int MidiMessage::getKeySignatureNumberOfSharpsOrFlats() const throw()
  22510. {
  22511. return (int) *getMetaEventData();
  22512. }
  22513. const MidiMessage MidiMessage::endOfTrack() throw()
  22514. {
  22515. return MidiMessage (0xff, 0x2f, 0, 0.0);
  22516. }
  22517. bool MidiMessage::isSongPositionPointer() const throw()
  22518. {
  22519. return *data == 0xf2;
  22520. }
  22521. int MidiMessage::getSongPositionPointerMidiBeat() const throw()
  22522. {
  22523. return data[1] | (data[2] << 7);
  22524. }
  22525. const MidiMessage MidiMessage::songPositionPointer (const int positionInMidiBeats) throw()
  22526. {
  22527. return MidiMessage (0xf2,
  22528. positionInMidiBeats & 127,
  22529. (positionInMidiBeats >> 7) & 127);
  22530. }
  22531. bool MidiMessage::isMidiStart() const throw()
  22532. {
  22533. return *data == 0xfa;
  22534. }
  22535. const MidiMessage MidiMessage::midiStart() throw()
  22536. {
  22537. return MidiMessage (0xfa);
  22538. }
  22539. bool MidiMessage::isMidiContinue() const throw()
  22540. {
  22541. return *data == 0xfb;
  22542. }
  22543. const MidiMessage MidiMessage::midiContinue() throw()
  22544. {
  22545. return MidiMessage (0xfb);
  22546. }
  22547. bool MidiMessage::isMidiStop() const throw()
  22548. {
  22549. return *data == 0xfc;
  22550. }
  22551. const MidiMessage MidiMessage::midiStop() throw()
  22552. {
  22553. return MidiMessage (0xfc);
  22554. }
  22555. bool MidiMessage::isMidiClock() const throw()
  22556. {
  22557. return *data == 0xf8;
  22558. }
  22559. const MidiMessage MidiMessage::midiClock() throw()
  22560. {
  22561. return MidiMessage (0xf8);
  22562. }
  22563. bool MidiMessage::isQuarterFrame() const throw()
  22564. {
  22565. return *data == 0xf1;
  22566. }
  22567. int MidiMessage::getQuarterFrameSequenceNumber() const throw()
  22568. {
  22569. return ((int) data[1]) >> 4;
  22570. }
  22571. int MidiMessage::getQuarterFrameValue() const throw()
  22572. {
  22573. return ((int) data[1]) & 0x0f;
  22574. }
  22575. const MidiMessage MidiMessage::quarterFrame (const int sequenceNumber,
  22576. const int value) throw()
  22577. {
  22578. return MidiMessage (0xf1, (sequenceNumber << 4) | value);
  22579. }
  22580. bool MidiMessage::isFullFrame() const throw()
  22581. {
  22582. return data[0] == 0xf0
  22583. && data[1] == 0x7f
  22584. && size >= 10
  22585. && data[3] == 0x01
  22586. && data[4] == 0x01;
  22587. }
  22588. void MidiMessage::getFullFrameParameters (int& hours,
  22589. int& minutes,
  22590. int& seconds,
  22591. int& frames,
  22592. MidiMessage::SmpteTimecodeType& timecodeType) const throw()
  22593. {
  22594. jassert (isFullFrame());
  22595. timecodeType = (SmpteTimecodeType) (data[5] >> 5);
  22596. hours = data[5] & 0x1f;
  22597. minutes = data[6];
  22598. seconds = data[7];
  22599. frames = data[8];
  22600. }
  22601. const MidiMessage MidiMessage::fullFrame (const int hours,
  22602. const int minutes,
  22603. const int seconds,
  22604. const int frames,
  22605. MidiMessage::SmpteTimecodeType timecodeType)
  22606. {
  22607. uint8 d[10];
  22608. d[0] = 0xf0;
  22609. d[1] = 0x7f;
  22610. d[2] = 0x7f;
  22611. d[3] = 0x01;
  22612. d[4] = 0x01;
  22613. d[5] = (uint8) ((hours & 0x01f) | (timecodeType << 5));
  22614. d[6] = (uint8) minutes;
  22615. d[7] = (uint8) seconds;
  22616. d[8] = (uint8) frames;
  22617. d[9] = 0xf7;
  22618. return MidiMessage (d, 10, 0.0);
  22619. }
  22620. bool MidiMessage::isMidiMachineControlMessage() const throw()
  22621. {
  22622. return data[0] == 0xf0
  22623. && data[1] == 0x7f
  22624. && data[3] == 0x06
  22625. && size > 5;
  22626. }
  22627. MidiMessage::MidiMachineControlCommand MidiMessage::getMidiMachineControlCommand() const throw()
  22628. {
  22629. jassert (isMidiMachineControlMessage());
  22630. return (MidiMachineControlCommand) data[4];
  22631. }
  22632. const MidiMessage MidiMessage::midiMachineControlCommand (MidiMessage::MidiMachineControlCommand command)
  22633. {
  22634. uint8 d[6];
  22635. d[0] = 0xf0;
  22636. d[1] = 0x7f;
  22637. d[2] = 0x00;
  22638. d[3] = 0x06;
  22639. d[4] = (uint8) command;
  22640. d[5] = 0xf7;
  22641. return MidiMessage (d, 6, 0.0);
  22642. }
  22643. bool MidiMessage::isMidiMachineControlGoto (int& hours,
  22644. int& minutes,
  22645. int& seconds,
  22646. int& frames) const throw()
  22647. {
  22648. if (size >= 12
  22649. && data[0] == 0xf0
  22650. && data[1] == 0x7f
  22651. && data[3] == 0x06
  22652. && data[4] == 0x44
  22653. && data[5] == 0x06
  22654. && data[6] == 0x01)
  22655. {
  22656. hours = data[7] % 24; // (that some machines send out hours > 24)
  22657. minutes = data[8];
  22658. seconds = data[9];
  22659. frames = data[10];
  22660. return true;
  22661. }
  22662. return false;
  22663. }
  22664. const MidiMessage MidiMessage::midiMachineControlGoto (int hours,
  22665. int minutes,
  22666. int seconds,
  22667. int frames)
  22668. {
  22669. uint8 d[12];
  22670. d[0] = 0xf0;
  22671. d[1] = 0x7f;
  22672. d[2] = 0x00;
  22673. d[3] = 0x06;
  22674. d[4] = 0x44;
  22675. d[5] = 0x06;
  22676. d[6] = 0x01;
  22677. d[7] = (uint8) hours;
  22678. d[8] = (uint8) minutes;
  22679. d[9] = (uint8) seconds;
  22680. d[10] = (uint8) frames;
  22681. d[11] = 0xf7;
  22682. return MidiMessage (d, 12, 0.0);
  22683. }
  22684. const String MidiMessage::getMidiNoteName (int note,
  22685. bool useSharps,
  22686. bool includeOctaveNumber,
  22687. int octaveNumForMiddleC) throw()
  22688. {
  22689. static const char* const sharpNoteNames[] = { "C", "C#", "D", "D#", "E",
  22690. "F", "F#", "G", "G#", "A",
  22691. "A#", "B" };
  22692. static const char* const flatNoteNames[] = { "C", "Db", "D", "Eb", "E",
  22693. "F", "Gb", "G", "Ab", "A",
  22694. "Bb", "B" };
  22695. if (((unsigned int) note) < 128)
  22696. {
  22697. const String s ((useSharps) ? sharpNoteNames [note % 12]
  22698. : flatNoteNames [note % 12]);
  22699. if (includeOctaveNumber)
  22700. return s + String (note / 12 + (octaveNumForMiddleC - 5));
  22701. else
  22702. return s;
  22703. }
  22704. return String::empty;
  22705. }
  22706. const double MidiMessage::getMidiNoteInHertz (int noteNumber) throw()
  22707. {
  22708. noteNumber -= 12 * 6 + 9; // now 0 = A440
  22709. return 440.0 * pow (2.0, noteNumber / 12.0);
  22710. }
  22711. const String MidiMessage::getGMInstrumentName (int n) throw()
  22712. {
  22713. const char *names[] =
  22714. {
  22715. "Acoustic Grand Piano", "Bright Acoustic Piano", "Electric Grand Piano", "Honky-tonk Piano",
  22716. "Electric Piano 1", "Electric Piano 2", "Harpsichord", "Clavinet", "Celesta", "Glockenspiel",
  22717. "Music Box", "Vibraphone", "Marimba", "Xylophone", "Tubular Bells", "Dulcimer", "Drawbar Organ",
  22718. "Percussive Organ", "Rock Organ", "Church Organ", "Reed Organ", "Accordion", "Harmonica",
  22719. "Tango Accordion", "Acoustic Guitar (nylon)", "Acoustic Guitar (steel)", "Electric Guitar (jazz)",
  22720. "Electric Guitar (clean)", "Electric Guitar (mute)", "Overdriven Guitar", "Distortion Guitar",
  22721. "Guitar Harmonics", "Acoustic Bass", "Electric Bass (finger)", "Electric Bass (pick)",
  22722. "Fretless Bass", "Slap Bass 1", "Slap Bass 2", "Synth Bass 1", "Synth Bass 2", "Violin",
  22723. "Viola", "Cello", "Contrabass", "Tremolo Strings", "Pizzicato Strings", "Orchestral Harp",
  22724. "Timpani", "String Ensemble 1", "String Ensemble 2", "SynthStrings 1", "SynthStrings 2",
  22725. "Choir Aahs", "Voice Oohs", "Synth Voice", "Orchestra Hit", "Trumpet", "Trombone", "Tuba",
  22726. "Muted Trumpet", "French Horn", "Brass Section", "SynthBrass 1", "SynthBrass 2", "Soprano Sax",
  22727. "Alto Sax", "Tenor Sax", "Baritone Sax", "Oboe", "English Horn", "Bassoon", "Clarinet",
  22728. "Piccolo", "Flute", "Recorder", "Pan Flute", "Blown Bottle", "Shakuhachi", "Whistle",
  22729. "Ocarina", "Lead 1 (square)", "Lead 2 (sawtooth)", "Lead 3 (calliope)", "Lead 4 (chiff)",
  22730. "Lead 5 (charang)", "Lead 6 (voice)", "Lead 7 (fifths)", "Lead 8 (bass+lead)", "Pad 1 (new age)",
  22731. "Pad 2 (warm)", "Pad 3 (polysynth)", "Pad 4 (choir)", "Pad 5 (bowed)", "Pad 6 (metallic)",
  22732. "Pad 7 (halo)", "Pad 8 (sweep)", "FX 1 (rain)", "FX 2 (soundtrack)", "FX 3 (crystal)",
  22733. "FX 4 (atmosphere)", "FX 5 (brightness)", "FX 6 (goblins)", "FX 7 (echoes)", "FX 8 (sci-fi)",
  22734. "Sitar", "Banjo", "Shamisen", "Koto", "Kalimba", "Bag pipe", "Fiddle", "Shanai", "Tinkle Bell",
  22735. "Agogo", "Steel Drums", "Woodblock", "Taiko Drum", "Melodic Tom", "Synth Drum", "Reverse Cymbal",
  22736. "Guitar Fret Noise", "Breath Noise", "Seashore", "Bird Tweet", "Telephone Ring", "Helicopter",
  22737. "Applause", "Gunshot"
  22738. };
  22739. return (((unsigned int) n) < 128) ? names[n]
  22740. : (const char*)0;
  22741. }
  22742. const String MidiMessage::getGMInstrumentBankName (int n) throw()
  22743. {
  22744. const char* names[] =
  22745. {
  22746. "Piano", "Chromatic Percussion", "Organ", "Guitar",
  22747. "Bass", "Strings", "Ensemble", "Brass",
  22748. "Reed", "Pipe", "Synth Lead", "Synth Pad",
  22749. "Synth Effects", "Ethnic", "Percussive", "Sound Effects"
  22750. };
  22751. return (((unsigned int) n) <= 15) ? names[n]
  22752. : (const char*)0;
  22753. }
  22754. const String MidiMessage::getRhythmInstrumentName (int n) throw()
  22755. {
  22756. const char* names[] =
  22757. {
  22758. "Acoustic Bass Drum", "Bass Drum 1", "Side Stick", "Acoustic Snare",
  22759. "Hand Clap", "Electric Snare", "Low Floor Tom", "Closed Hi-Hat", "High Floor Tom",
  22760. "Pedal Hi-Hat", "Low Tom", "Open Hi-Hat", "Low-Mid Tom", "Hi-Mid Tom", "Crash Cymbal 1",
  22761. "High Tom", "Ride Cymbal 1", "Chinese Cymbal", "Ride Bell", "Tambourine", "Splash Cymbal",
  22762. "Cowbell", "Crash Cymbal 2", "Vibraslap", "Ride Cymbal 2", "Hi Bongo", "Low Bongo",
  22763. "Mute Hi Conga", "Open Hi Conga", "Low Conga", "High Timbale", "Low Timbale", "High Agogo",
  22764. "Low Agogo", "Cabasa", "Maracas", "Short Whistle", "Long Whistle", "Short Guiro",
  22765. "Long Guiro", "Claves", "Hi Wood Block", "Low Wood Block", "Mute Cuica", "Open Cuica",
  22766. "Mute Triangle", "Open Triangle"
  22767. };
  22768. return (n >= 35 && n <= 81) ? names [n - 35]
  22769. : (const char*)0;
  22770. }
  22771. const String MidiMessage::getControllerName (int n) throw()
  22772. {
  22773. const char* names[] =
  22774. {
  22775. "Bank Select", "Modulation Wheel (coarse)", "Breath controller (coarse)",
  22776. 0, "Foot Pedal (coarse)", "Portamento Time (coarse)",
  22777. "Data Entry (coarse)", "Volume (coarse)", "Balance (coarse)",
  22778. 0, "Pan position (coarse)", "Expression (coarse)", "Effect Control 1 (coarse)",
  22779. "Effect Control 2 (coarse)", 0, 0, "General Purpose Slider 1", "General Purpose Slider 2",
  22780. "General Purpose Slider 3", "General Purpose Slider 4", 0, 0, 0, 0, 0, 0, 0, 0,
  22781. 0, 0, 0, 0, "Bank Select (fine)", "Modulation Wheel (fine)", "Breath controller (fine)",
  22782. 0, "Foot Pedal (fine)", "Portamento Time (fine)", "Data Entry (fine)", "Volume (fine)",
  22783. "Balance (fine)", 0, "Pan position (fine)", "Expression (fine)", "Effect Control 1 (fine)",
  22784. "Effect Control 2 (fine)", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  22785. "Hold Pedal (on/off)", "Portamento (on/off)", "Sustenuto Pedal (on/off)", "Soft Pedal (on/off)",
  22786. "Legato Pedal (on/off)", "Hold 2 Pedal (on/off)", "Sound Variation", "Sound Timbre",
  22787. "Sound Release Time", "Sound Attack Time", "Sound Brightness", "Sound Control 6",
  22788. "Sound Control 7", "Sound Control 8", "Sound Control 9", "Sound Control 10",
  22789. "General Purpose Button 1 (on/off)", "General Purpose Button 2 (on/off)",
  22790. "General Purpose Button 3 (on/off)", "General Purpose Button 4 (on/off)",
  22791. 0, 0, 0, 0, 0, 0, 0, "Reverb Level", "Tremolo Level", "Chorus Level", "Celeste Level",
  22792. "Phaser Level", "Data Button increment", "Data Button decrement", "Non-registered Parameter (fine)",
  22793. "Non-registered Parameter (coarse)", "Registered Parameter (fine)", "Registered Parameter (coarse)",
  22794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "All Sound Off", "All Controllers Off",
  22795. "Local Keyboard (on/off)", "All Notes Off", "Omni Mode Off", "Omni Mode On", "Mono Operation",
  22796. "Poly Operation"
  22797. };
  22798. return (((unsigned int) n) < 128) ? names[n]
  22799. : (const char*)0;
  22800. }
  22801. END_JUCE_NAMESPACE
  22802. /*** End of inlined file: juce_MidiMessage.cpp ***/
  22803. /*** Start of inlined file: juce_MidiMessageCollector.cpp ***/
  22804. BEGIN_JUCE_NAMESPACE
  22805. MidiMessageCollector::MidiMessageCollector()
  22806. : lastCallbackTime (0),
  22807. sampleRate (44100.0001)
  22808. {
  22809. }
  22810. MidiMessageCollector::~MidiMessageCollector()
  22811. {
  22812. }
  22813. void MidiMessageCollector::reset (const double sampleRate_)
  22814. {
  22815. jassert (sampleRate_ > 0);
  22816. const ScopedLock sl (midiCallbackLock);
  22817. sampleRate = sampleRate_;
  22818. incomingMessages.clear();
  22819. lastCallbackTime = Time::getMillisecondCounterHiRes();
  22820. }
  22821. void MidiMessageCollector::addMessageToQueue (const MidiMessage& message)
  22822. {
  22823. // you need to call reset() to set the correct sample rate before using this object
  22824. jassert (sampleRate != 44100.0001);
  22825. // the messages that come in here need to be time-stamped correctly - see MidiInput
  22826. // for details of what the number should be.
  22827. jassert (message.getTimeStamp() != 0);
  22828. const ScopedLock sl (midiCallbackLock);
  22829. const int sampleNumber
  22830. = (int) ((message.getTimeStamp() - 0.001 * lastCallbackTime) * sampleRate);
  22831. incomingMessages.addEvent (message, sampleNumber);
  22832. // if the messages don't get used for over a second, we'd better
  22833. // get rid of any old ones to avoid the queue getting too big
  22834. if (sampleNumber > sampleRate)
  22835. incomingMessages.clear (0, sampleNumber - (int) sampleRate);
  22836. }
  22837. void MidiMessageCollector::removeNextBlockOfMessages (MidiBuffer& destBuffer,
  22838. const int numSamples)
  22839. {
  22840. // you need to call reset() to set the correct sample rate before using this object
  22841. jassert (sampleRate != 44100.0001);
  22842. const double timeNow = Time::getMillisecondCounterHiRes();
  22843. const double msElapsed = timeNow - lastCallbackTime;
  22844. const ScopedLock sl (midiCallbackLock);
  22845. lastCallbackTime = timeNow;
  22846. if (! incomingMessages.isEmpty())
  22847. {
  22848. int numSourceSamples = jmax (1, roundToInt (msElapsed * 0.001 * sampleRate));
  22849. int startSample = 0;
  22850. int scale = 1 << 16;
  22851. const uint8* midiData;
  22852. int numBytes, samplePosition;
  22853. MidiBuffer::Iterator iter (incomingMessages);
  22854. if (numSourceSamples > numSamples)
  22855. {
  22856. // if our list of events is longer than the buffer we're being
  22857. // asked for, scale them down to squeeze them all in..
  22858. const int maxBlockLengthToUse = numSamples << 5;
  22859. if (numSourceSamples > maxBlockLengthToUse)
  22860. {
  22861. startSample = numSourceSamples - maxBlockLengthToUse;
  22862. numSourceSamples = maxBlockLengthToUse;
  22863. iter.setNextSamplePosition (startSample);
  22864. }
  22865. scale = (numSamples << 10) / numSourceSamples;
  22866. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  22867. {
  22868. samplePosition = ((samplePosition - startSample) * scale) >> 10;
  22869. destBuffer.addEvent (midiData, numBytes,
  22870. jlimit (0, numSamples - 1, samplePosition));
  22871. }
  22872. }
  22873. else
  22874. {
  22875. // if our event list is shorter than the number we need, put them
  22876. // towards the end of the buffer
  22877. startSample = numSamples - numSourceSamples;
  22878. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  22879. {
  22880. destBuffer.addEvent (midiData, numBytes,
  22881. jlimit (0, numSamples - 1, samplePosition + startSample));
  22882. }
  22883. }
  22884. incomingMessages.clear();
  22885. }
  22886. }
  22887. void MidiMessageCollector::handleNoteOn (MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity)
  22888. {
  22889. MidiMessage m (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity));
  22890. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  22891. addMessageToQueue (m);
  22892. }
  22893. void MidiMessageCollector::handleNoteOff (MidiKeyboardState*, int midiChannel, int midiNoteNumber)
  22894. {
  22895. MidiMessage m (MidiMessage::noteOff (midiChannel, midiNoteNumber));
  22896. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  22897. addMessageToQueue (m);
  22898. }
  22899. void MidiMessageCollector::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  22900. {
  22901. addMessageToQueue (message);
  22902. }
  22903. END_JUCE_NAMESPACE
  22904. /*** End of inlined file: juce_MidiMessageCollector.cpp ***/
  22905. /*** Start of inlined file: juce_MidiMessageSequence.cpp ***/
  22906. BEGIN_JUCE_NAMESPACE
  22907. MidiMessageSequence::MidiMessageSequence()
  22908. {
  22909. }
  22910. MidiMessageSequence::MidiMessageSequence (const MidiMessageSequence& other)
  22911. {
  22912. list.ensureStorageAllocated (other.list.size());
  22913. for (int i = 0; i < other.list.size(); ++i)
  22914. list.add (new MidiEventHolder (other.list.getUnchecked(i)->message));
  22915. }
  22916. MidiMessageSequence& MidiMessageSequence::operator= (const MidiMessageSequence& other)
  22917. {
  22918. MidiMessageSequence otherCopy (other);
  22919. swapWith (otherCopy);
  22920. return *this;
  22921. }
  22922. void MidiMessageSequence::swapWith (MidiMessageSequence& other) throw()
  22923. {
  22924. list.swapWithArray (other.list);
  22925. }
  22926. MidiMessageSequence::~MidiMessageSequence()
  22927. {
  22928. }
  22929. void MidiMessageSequence::clear()
  22930. {
  22931. list.clear();
  22932. }
  22933. int MidiMessageSequence::getNumEvents() const
  22934. {
  22935. return list.size();
  22936. }
  22937. MidiMessageSequence::MidiEventHolder* MidiMessageSequence::getEventPointer (const int index) const
  22938. {
  22939. return list [index];
  22940. }
  22941. double MidiMessageSequence::getTimeOfMatchingKeyUp (const int index) const
  22942. {
  22943. const MidiEventHolder* const meh = list [index];
  22944. if (meh != 0 && meh->noteOffObject != 0)
  22945. return meh->noteOffObject->message.getTimeStamp();
  22946. else
  22947. return 0.0;
  22948. }
  22949. int MidiMessageSequence::getIndexOfMatchingKeyUp (const int index) const
  22950. {
  22951. const MidiEventHolder* const meh = list [index];
  22952. return (meh != 0) ? list.indexOf (meh->noteOffObject) : -1;
  22953. }
  22954. int MidiMessageSequence::getIndexOf (MidiEventHolder* const event) const
  22955. {
  22956. return list.indexOf (event);
  22957. }
  22958. int MidiMessageSequence::getNextIndexAtTime (const double timeStamp) const
  22959. {
  22960. const int numEvents = list.size();
  22961. int i;
  22962. for (i = 0; i < numEvents; ++i)
  22963. if (list.getUnchecked(i)->message.getTimeStamp() >= timeStamp)
  22964. break;
  22965. return i;
  22966. }
  22967. double MidiMessageSequence::getStartTime() const
  22968. {
  22969. if (list.size() > 0)
  22970. return list.getUnchecked(0)->message.getTimeStamp();
  22971. else
  22972. return 0;
  22973. }
  22974. double MidiMessageSequence::getEndTime() const
  22975. {
  22976. if (list.size() > 0)
  22977. return list.getLast()->message.getTimeStamp();
  22978. else
  22979. return 0;
  22980. }
  22981. double MidiMessageSequence::getEventTime (const int index) const
  22982. {
  22983. if (((unsigned int) index) < (unsigned int) list.size())
  22984. return list.getUnchecked (index)->message.getTimeStamp();
  22985. return 0.0;
  22986. }
  22987. void MidiMessageSequence::addEvent (const MidiMessage& newMessage,
  22988. double timeAdjustment)
  22989. {
  22990. MidiEventHolder* const newOne = new MidiEventHolder (newMessage);
  22991. timeAdjustment += newMessage.getTimeStamp();
  22992. newOne->message.setTimeStamp (timeAdjustment);
  22993. int i;
  22994. for (i = list.size(); --i >= 0;)
  22995. if (list.getUnchecked(i)->message.getTimeStamp() <= timeAdjustment)
  22996. break;
  22997. list.insert (i + 1, newOne);
  22998. }
  22999. void MidiMessageSequence::deleteEvent (const int index,
  23000. const bool deleteMatchingNoteUp)
  23001. {
  23002. if (((unsigned int) index) < (unsigned int) list.size())
  23003. {
  23004. if (deleteMatchingNoteUp)
  23005. deleteEvent (getIndexOfMatchingKeyUp (index), false);
  23006. list.remove (index);
  23007. }
  23008. }
  23009. void MidiMessageSequence::addSequence (const MidiMessageSequence& other,
  23010. double timeAdjustment,
  23011. double firstAllowableTime,
  23012. double endOfAllowableDestTimes)
  23013. {
  23014. firstAllowableTime -= timeAdjustment;
  23015. endOfAllowableDestTimes -= timeAdjustment;
  23016. for (int i = 0; i < other.list.size(); ++i)
  23017. {
  23018. const MidiMessage& m = other.list.getUnchecked(i)->message;
  23019. const double t = m.getTimeStamp();
  23020. if (t >= firstAllowableTime && t < endOfAllowableDestTimes)
  23021. {
  23022. MidiEventHolder* const newOne = new MidiEventHolder (m);
  23023. newOne->message.setTimeStamp (timeAdjustment + t);
  23024. list.add (newOne);
  23025. }
  23026. }
  23027. sort();
  23028. }
  23029. int MidiMessageSequence::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  23030. const MidiMessageSequence::MidiEventHolder* const second) throw()
  23031. {
  23032. const double diff = first->message.getTimeStamp()
  23033. - second->message.getTimeStamp();
  23034. return (diff > 0) - (diff < 0);
  23035. }
  23036. void MidiMessageSequence::sort()
  23037. {
  23038. list.sort (*this, true);
  23039. }
  23040. void MidiMessageSequence::updateMatchedPairs()
  23041. {
  23042. for (int i = 0; i < list.size(); ++i)
  23043. {
  23044. const MidiMessage& m1 = list.getUnchecked(i)->message;
  23045. if (m1.isNoteOn())
  23046. {
  23047. list.getUnchecked(i)->noteOffObject = 0;
  23048. const int note = m1.getNoteNumber();
  23049. const int chan = m1.getChannel();
  23050. const int len = list.size();
  23051. for (int j = i + 1; j < len; ++j)
  23052. {
  23053. const MidiMessage& m = list.getUnchecked(j)->message;
  23054. if (m.getNoteNumber() == note && m.getChannel() == chan)
  23055. {
  23056. if (m.isNoteOff())
  23057. {
  23058. list.getUnchecked(i)->noteOffObject = list[j];
  23059. break;
  23060. }
  23061. else if (m.isNoteOn())
  23062. {
  23063. list.insert (j, new MidiEventHolder (MidiMessage::noteOff (chan, note)));
  23064. list.getUnchecked(j)->message.setTimeStamp (m.getTimeStamp());
  23065. list.getUnchecked(i)->noteOffObject = list[j];
  23066. break;
  23067. }
  23068. }
  23069. }
  23070. }
  23071. }
  23072. }
  23073. void MidiMessageSequence::addTimeToMessages (const double delta)
  23074. {
  23075. for (int i = list.size(); --i >= 0;)
  23076. list.getUnchecked (i)->message.setTimeStamp (list.getUnchecked (i)->message.getTimeStamp()
  23077. + delta);
  23078. }
  23079. void MidiMessageSequence::extractMidiChannelMessages (const int channelNumberToExtract,
  23080. MidiMessageSequence& destSequence,
  23081. const bool alsoIncludeMetaEvents) const
  23082. {
  23083. for (int i = 0; i < list.size(); ++i)
  23084. {
  23085. const MidiMessage& mm = list.getUnchecked(i)->message;
  23086. if (mm.isForChannel (channelNumberToExtract)
  23087. || (alsoIncludeMetaEvents && mm.isMetaEvent()))
  23088. {
  23089. destSequence.addEvent (mm);
  23090. }
  23091. }
  23092. }
  23093. void MidiMessageSequence::extractSysExMessages (MidiMessageSequence& destSequence) const
  23094. {
  23095. for (int i = 0; i < list.size(); ++i)
  23096. {
  23097. const MidiMessage& mm = list.getUnchecked(i)->message;
  23098. if (mm.isSysEx())
  23099. destSequence.addEvent (mm);
  23100. }
  23101. }
  23102. void MidiMessageSequence::deleteMidiChannelMessages (const int channelNumberToRemove)
  23103. {
  23104. for (int i = list.size(); --i >= 0;)
  23105. if (list.getUnchecked(i)->message.isForChannel (channelNumberToRemove))
  23106. list.remove(i);
  23107. }
  23108. void MidiMessageSequence::deleteSysExMessages()
  23109. {
  23110. for (int i = list.size(); --i >= 0;)
  23111. if (list.getUnchecked(i)->message.isSysEx())
  23112. list.remove(i);
  23113. }
  23114. void MidiMessageSequence::createControllerUpdatesForTime (const int channelNumber,
  23115. const double time,
  23116. OwnedArray<MidiMessage>& dest)
  23117. {
  23118. bool doneProg = false;
  23119. bool donePitchWheel = false;
  23120. Array <int> doneControllers;
  23121. doneControllers.ensureStorageAllocated (32);
  23122. for (int i = list.size(); --i >= 0;)
  23123. {
  23124. const MidiMessage& mm = list.getUnchecked(i)->message;
  23125. if (mm.isForChannel (channelNumber)
  23126. && mm.getTimeStamp() <= time)
  23127. {
  23128. if (mm.isProgramChange())
  23129. {
  23130. if (! doneProg)
  23131. {
  23132. dest.add (new MidiMessage (mm, 0.0));
  23133. doneProg = true;
  23134. }
  23135. }
  23136. else if (mm.isController())
  23137. {
  23138. if (! doneControllers.contains (mm.getControllerNumber()))
  23139. {
  23140. dest.add (new MidiMessage (mm, 0.0));
  23141. doneControllers.add (mm.getControllerNumber());
  23142. }
  23143. }
  23144. else if (mm.isPitchWheel())
  23145. {
  23146. if (! donePitchWheel)
  23147. {
  23148. dest.add (new MidiMessage (mm, 0.0));
  23149. donePitchWheel = true;
  23150. }
  23151. }
  23152. }
  23153. }
  23154. }
  23155. MidiMessageSequence::MidiEventHolder::MidiEventHolder (const MidiMessage& message_)
  23156. : message (message_),
  23157. noteOffObject (0)
  23158. {
  23159. }
  23160. MidiMessageSequence::MidiEventHolder::~MidiEventHolder()
  23161. {
  23162. }
  23163. END_JUCE_NAMESPACE
  23164. /*** End of inlined file: juce_MidiMessageSequence.cpp ***/
  23165. /*** Start of inlined file: juce_AudioPluginFormat.cpp ***/
  23166. BEGIN_JUCE_NAMESPACE
  23167. AudioPluginFormat::AudioPluginFormat() throw()
  23168. {
  23169. }
  23170. AudioPluginFormat::~AudioPluginFormat()
  23171. {
  23172. }
  23173. END_JUCE_NAMESPACE
  23174. /*** End of inlined file: juce_AudioPluginFormat.cpp ***/
  23175. /*** Start of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23176. BEGIN_JUCE_NAMESPACE
  23177. AudioPluginFormatManager::AudioPluginFormatManager() throw()
  23178. {
  23179. }
  23180. AudioPluginFormatManager::~AudioPluginFormatManager() throw()
  23181. {
  23182. clearSingletonInstance();
  23183. }
  23184. juce_ImplementSingleton_SingleThreaded (AudioPluginFormatManager);
  23185. void AudioPluginFormatManager::addDefaultFormats()
  23186. {
  23187. #ifdef JUCE_DEBUG
  23188. // you should only call this method once!
  23189. for (int i = formats.size(); --i >= 0;)
  23190. {
  23191. #if JUCE_PLUGINHOST_VST && ! (JUCE_MAC && JUCE_64BIT)
  23192. jassert (dynamic_cast <VSTPluginFormat*> (formats[i]) == 0);
  23193. #endif
  23194. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23195. jassert (dynamic_cast <AudioUnitPluginFormat*> (formats[i]) == 0);
  23196. #endif
  23197. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23198. jassert (dynamic_cast <DirectXPluginFormat*> (formats[i]) == 0);
  23199. #endif
  23200. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23201. jassert (dynamic_cast <LADSPAPluginFormat*> (formats[i]) == 0);
  23202. #endif
  23203. }
  23204. #endif
  23205. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23206. formats.add (new AudioUnitPluginFormat());
  23207. #endif
  23208. #if JUCE_PLUGINHOST_VST && ! (JUCE_MAC && JUCE_64BIT)
  23209. formats.add (new VSTPluginFormat());
  23210. #endif
  23211. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23212. formats.add (new DirectXPluginFormat());
  23213. #endif
  23214. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23215. formats.add (new LADSPAPluginFormat());
  23216. #endif
  23217. }
  23218. int AudioPluginFormatManager::getNumFormats() throw()
  23219. {
  23220. return formats.size();
  23221. }
  23222. AudioPluginFormat* AudioPluginFormatManager::getFormat (const int index) throw()
  23223. {
  23224. return formats [index];
  23225. }
  23226. void AudioPluginFormatManager::addFormat (AudioPluginFormat* const format) throw()
  23227. {
  23228. formats.add (format);
  23229. }
  23230. AudioPluginInstance* AudioPluginFormatManager::createPluginInstance (const PluginDescription& description,
  23231. String& errorMessage) const
  23232. {
  23233. AudioPluginInstance* result = 0;
  23234. for (int i = 0; i < formats.size(); ++i)
  23235. {
  23236. result = formats.getUnchecked(i)->createInstanceFromDescription (description);
  23237. if (result != 0)
  23238. break;
  23239. }
  23240. if (result == 0)
  23241. {
  23242. if (! doesPluginStillExist (description))
  23243. errorMessage = TRANS ("This plug-in file no longer exists");
  23244. else
  23245. errorMessage = TRANS ("This plug-in failed to load correctly");
  23246. }
  23247. return result;
  23248. }
  23249. bool AudioPluginFormatManager::doesPluginStillExist (const PluginDescription& description) const
  23250. {
  23251. for (int i = 0; i < formats.size(); ++i)
  23252. if (formats.getUnchecked(i)->getName() == description.pluginFormatName)
  23253. return formats.getUnchecked(i)->doesPluginStillExist (description);
  23254. return false;
  23255. }
  23256. END_JUCE_NAMESPACE
  23257. /*** End of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23258. /*** Start of inlined file: juce_AudioPluginInstance.cpp ***/
  23259. #define JUCE_PLUGIN_HOST 1
  23260. BEGIN_JUCE_NAMESPACE
  23261. AudioPluginInstance::AudioPluginInstance()
  23262. {
  23263. }
  23264. AudioPluginInstance::~AudioPluginInstance()
  23265. {
  23266. }
  23267. END_JUCE_NAMESPACE
  23268. /*** End of inlined file: juce_AudioPluginInstance.cpp ***/
  23269. /*** Start of inlined file: juce_KnownPluginList.cpp ***/
  23270. BEGIN_JUCE_NAMESPACE
  23271. KnownPluginList::KnownPluginList()
  23272. {
  23273. }
  23274. KnownPluginList::~KnownPluginList()
  23275. {
  23276. }
  23277. void KnownPluginList::clear()
  23278. {
  23279. if (types.size() > 0)
  23280. {
  23281. types.clear();
  23282. sendChangeMessage (this);
  23283. }
  23284. }
  23285. PluginDescription* KnownPluginList::getTypeForFile (const String& fileOrIdentifier) const throw()
  23286. {
  23287. for (int i = 0; i < types.size(); ++i)
  23288. if (types.getUnchecked(i)->fileOrIdentifier == fileOrIdentifier)
  23289. return types.getUnchecked(i);
  23290. return 0;
  23291. }
  23292. PluginDescription* KnownPluginList::getTypeForIdentifierString (const String& identifierString) const throw()
  23293. {
  23294. for (int i = 0; i < types.size(); ++i)
  23295. if (types.getUnchecked(i)->createIdentifierString() == identifierString)
  23296. return types.getUnchecked(i);
  23297. return 0;
  23298. }
  23299. bool KnownPluginList::addType (const PluginDescription& type)
  23300. {
  23301. for (int i = types.size(); --i >= 0;)
  23302. {
  23303. if (types.getUnchecked(i)->isDuplicateOf (type))
  23304. {
  23305. // strange - found a duplicate plugin with different info..
  23306. jassert (types.getUnchecked(i)->name == type.name);
  23307. jassert (types.getUnchecked(i)->isInstrument == type.isInstrument);
  23308. *types.getUnchecked(i) = type;
  23309. return false;
  23310. }
  23311. }
  23312. types.add (new PluginDescription (type));
  23313. sendChangeMessage (this);
  23314. return true;
  23315. }
  23316. void KnownPluginList::removeType (const int index) throw()
  23317. {
  23318. types.remove (index);
  23319. sendChangeMessage (this);
  23320. }
  23321. static Time getFileModTime (const String& fileOrIdentifier) throw()
  23322. {
  23323. if (fileOrIdentifier.startsWithChar ('/')
  23324. || fileOrIdentifier[1] == ':')
  23325. {
  23326. return File (fileOrIdentifier).getLastModificationTime();
  23327. }
  23328. return Time (0);
  23329. }
  23330. static bool timesAreDifferent (const Time& t1, const Time& t2) throw()
  23331. {
  23332. return t1 != t2 || t1 == Time (0);
  23333. }
  23334. bool KnownPluginList::isListingUpToDate (const String& fileOrIdentifier) const throw()
  23335. {
  23336. if (getTypeForFile (fileOrIdentifier) == 0)
  23337. return false;
  23338. for (int i = types.size(); --i >= 0;)
  23339. {
  23340. const PluginDescription* const d = types.getUnchecked(i);
  23341. if (d->fileOrIdentifier == fileOrIdentifier
  23342. && timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23343. {
  23344. return false;
  23345. }
  23346. }
  23347. return true;
  23348. }
  23349. bool KnownPluginList::scanAndAddFile (const String& fileOrIdentifier,
  23350. const bool dontRescanIfAlreadyInList,
  23351. OwnedArray <PluginDescription>& typesFound,
  23352. AudioPluginFormat& format)
  23353. {
  23354. bool addedOne = false;
  23355. if (dontRescanIfAlreadyInList
  23356. && getTypeForFile (fileOrIdentifier) != 0)
  23357. {
  23358. bool needsRescanning = false;
  23359. for (int i = types.size(); --i >= 0;)
  23360. {
  23361. const PluginDescription* const d = types.getUnchecked(i);
  23362. if (d->fileOrIdentifier == fileOrIdentifier)
  23363. {
  23364. if (timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23365. needsRescanning = true;
  23366. else
  23367. typesFound.add (new PluginDescription (*d));
  23368. }
  23369. }
  23370. if (! needsRescanning)
  23371. return false;
  23372. }
  23373. OwnedArray <PluginDescription> found;
  23374. format.findAllTypesForFile (found, fileOrIdentifier);
  23375. for (int i = 0; i < found.size(); ++i)
  23376. {
  23377. PluginDescription* const desc = found.getUnchecked(i);
  23378. jassert (desc != 0);
  23379. if (addType (*desc))
  23380. addedOne = true;
  23381. typesFound.add (new PluginDescription (*desc));
  23382. }
  23383. return addedOne;
  23384. }
  23385. void KnownPluginList::scanAndAddDragAndDroppedFiles (const StringArray& files,
  23386. OwnedArray <PluginDescription>& typesFound)
  23387. {
  23388. for (int i = 0; i < files.size(); ++i)
  23389. {
  23390. bool loaded = false;
  23391. for (int j = 0; j < AudioPluginFormatManager::getInstance()->getNumFormats(); ++j)
  23392. {
  23393. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (j);
  23394. if (scanAndAddFile (files[i], true, typesFound, *format))
  23395. loaded = true;
  23396. }
  23397. if (! loaded)
  23398. {
  23399. const File f (files[i]);
  23400. if (f.isDirectory())
  23401. {
  23402. StringArray s;
  23403. {
  23404. Array<File> subFiles;
  23405. f.findChildFiles (subFiles, File::findFilesAndDirectories, false);
  23406. for (int j = 0; j < subFiles.size(); ++j)
  23407. s.add (subFiles.getReference(j).getFullPathName());
  23408. }
  23409. scanAndAddDragAndDroppedFiles (s, typesFound);
  23410. }
  23411. }
  23412. }
  23413. }
  23414. class PluginSorter
  23415. {
  23416. public:
  23417. KnownPluginList::SortMethod method;
  23418. PluginSorter() throw() {}
  23419. int compareElements (const PluginDescription* const first,
  23420. const PluginDescription* const second) const throw()
  23421. {
  23422. int diff = 0;
  23423. if (method == KnownPluginList::sortByCategory)
  23424. diff = first->category.compareLexicographically (second->category);
  23425. else if (method == KnownPluginList::sortByManufacturer)
  23426. diff = first->manufacturerName.compareLexicographically (second->manufacturerName);
  23427. else if (method == KnownPluginList::sortByFileSystemLocation)
  23428. diff = first->fileOrIdentifier.replaceCharacter ('\\', '/')
  23429. .upToLastOccurrenceOf (T("/"), false, false)
  23430. .compare (second->fileOrIdentifier.replaceCharacter ('\\', '/')
  23431. .upToLastOccurrenceOf (T("/"), false, false));
  23432. if (diff == 0)
  23433. diff = first->name.compareLexicographically (second->name);
  23434. return diff;
  23435. }
  23436. };
  23437. void KnownPluginList::sort (const SortMethod method)
  23438. {
  23439. if (method != defaultOrder)
  23440. {
  23441. PluginSorter sorter;
  23442. sorter.method = method;
  23443. types.sort (sorter, true);
  23444. sendChangeMessage (this);
  23445. }
  23446. }
  23447. XmlElement* KnownPluginList::createXml() const
  23448. {
  23449. XmlElement* const e = new XmlElement ("KNOWNPLUGINS");
  23450. for (int i = 0; i < types.size(); ++i)
  23451. e->addChildElement (types.getUnchecked(i)->createXml());
  23452. return e;
  23453. }
  23454. void KnownPluginList::recreateFromXml (const XmlElement& xml)
  23455. {
  23456. clear();
  23457. if (xml.hasTagName ("KNOWNPLUGINS"))
  23458. {
  23459. forEachXmlChildElement (xml, e)
  23460. {
  23461. PluginDescription info;
  23462. if (info.loadFromXml (*e))
  23463. addType (info);
  23464. }
  23465. }
  23466. }
  23467. const int menuIdBase = 0x324503f4;
  23468. // This is used to turn a bunch of paths into a nested menu structure.
  23469. struct PluginFilesystemTree
  23470. {
  23471. private:
  23472. String folder;
  23473. OwnedArray <PluginFilesystemTree> subFolders;
  23474. Array <PluginDescription*> plugins;
  23475. void addPlugin (PluginDescription* const pd, const String& path)
  23476. {
  23477. if (path.isEmpty())
  23478. {
  23479. plugins.add (pd);
  23480. }
  23481. else
  23482. {
  23483. const String firstSubFolder (path.upToFirstOccurrenceOf (T("/"), false, false));
  23484. const String remainingPath (path.fromFirstOccurrenceOf (T("/"), false, false));
  23485. for (int i = subFolders.size(); --i >= 0;)
  23486. {
  23487. if (subFolders.getUnchecked(i)->folder.equalsIgnoreCase (firstSubFolder))
  23488. {
  23489. subFolders.getUnchecked(i)->addPlugin (pd, remainingPath);
  23490. return;
  23491. }
  23492. }
  23493. PluginFilesystemTree* const newFolder = new PluginFilesystemTree();
  23494. newFolder->folder = firstSubFolder;
  23495. subFolders.add (newFolder);
  23496. newFolder->addPlugin (pd, remainingPath);
  23497. }
  23498. }
  23499. // removes any deeply nested folders that don't contain any actual plugins
  23500. void optimise()
  23501. {
  23502. for (int i = subFolders.size(); --i >= 0;)
  23503. {
  23504. PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23505. sub->optimise();
  23506. if (sub->plugins.size() == 0)
  23507. {
  23508. for (int j = 0; j < sub->subFolders.size(); ++j)
  23509. subFolders.add (sub->subFolders.getUnchecked(j));
  23510. sub->subFolders.clear (false);
  23511. subFolders.remove (i);
  23512. }
  23513. }
  23514. }
  23515. public:
  23516. void buildTree (const Array <PluginDescription*>& allPlugins)
  23517. {
  23518. for (int i = 0; i < allPlugins.size(); ++i)
  23519. {
  23520. String path (allPlugins.getUnchecked(i)
  23521. ->fileOrIdentifier.replaceCharacter ('\\', '/')
  23522. .upToLastOccurrenceOf (T("/"), false, false));
  23523. if (path.substring (1, 2) == ":")
  23524. path = path.substring (2);
  23525. addPlugin (allPlugins.getUnchecked(i), path);
  23526. }
  23527. optimise();
  23528. }
  23529. void addToMenu (PopupMenu& m, const OwnedArray <PluginDescription>& allPlugins) const
  23530. {
  23531. int i;
  23532. for (i = 0; i < subFolders.size(); ++i)
  23533. {
  23534. const PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23535. PopupMenu subMenu;
  23536. sub->addToMenu (subMenu, allPlugins);
  23537. #if JUCE_MAC
  23538. // avoid the special AU formatting nonsense on Mac..
  23539. m.addSubMenu (sub->folder.fromFirstOccurrenceOf (T(":"), false, false), subMenu);
  23540. #else
  23541. m.addSubMenu (sub->folder, subMenu);
  23542. #endif
  23543. }
  23544. for (i = 0; i < plugins.size(); ++i)
  23545. {
  23546. PluginDescription* const plugin = plugins.getUnchecked(i);
  23547. m.addItem (allPlugins.indexOf (plugin) + menuIdBase,
  23548. plugin->name, true, false);
  23549. }
  23550. }
  23551. };
  23552. void KnownPluginList::addToMenu (PopupMenu& menu, const SortMethod sortMethod) const
  23553. {
  23554. Array <PluginDescription*> sorted;
  23555. {
  23556. PluginSorter sorter;
  23557. sorter.method = sortMethod;
  23558. for (int i = 0; i < types.size(); ++i)
  23559. sorted.addSorted (sorter, types.getUnchecked(i));
  23560. }
  23561. if (sortMethod == sortByCategory
  23562. || sortMethod == sortByManufacturer)
  23563. {
  23564. String lastSubMenuName;
  23565. PopupMenu sub;
  23566. for (int i = 0; i < sorted.size(); ++i)
  23567. {
  23568. const PluginDescription* const pd = sorted.getUnchecked(i);
  23569. String thisSubMenuName (sortMethod == sortByCategory ? pd->category
  23570. : pd->manufacturerName);
  23571. if (! thisSubMenuName.containsNonWhitespaceChars())
  23572. thisSubMenuName = "Other";
  23573. if (thisSubMenuName != lastSubMenuName)
  23574. {
  23575. if (sub.getNumItems() > 0)
  23576. {
  23577. menu.addSubMenu (lastSubMenuName, sub);
  23578. sub.clear();
  23579. }
  23580. lastSubMenuName = thisSubMenuName;
  23581. }
  23582. sub.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23583. }
  23584. if (sub.getNumItems() > 0)
  23585. menu.addSubMenu (lastSubMenuName, sub);
  23586. }
  23587. else if (sortMethod == sortByFileSystemLocation)
  23588. {
  23589. PluginFilesystemTree root;
  23590. root.buildTree (sorted);
  23591. root.addToMenu (menu, types);
  23592. }
  23593. else
  23594. {
  23595. for (int i = 0; i < sorted.size(); ++i)
  23596. {
  23597. const PluginDescription* const pd = sorted.getUnchecked(i);
  23598. menu.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23599. }
  23600. }
  23601. }
  23602. int KnownPluginList::getIndexChosenByMenu (const int menuResultCode) const
  23603. {
  23604. const int i = menuResultCode - menuIdBase;
  23605. return (((unsigned int) i) < (unsigned int) types.size()) ? i : -1;
  23606. }
  23607. END_JUCE_NAMESPACE
  23608. /*** End of inlined file: juce_KnownPluginList.cpp ***/
  23609. /*** Start of inlined file: juce_PluginDescription.cpp ***/
  23610. BEGIN_JUCE_NAMESPACE
  23611. PluginDescription::PluginDescription() throw()
  23612. : uid (0),
  23613. isInstrument (false),
  23614. numInputChannels (0),
  23615. numOutputChannels (0)
  23616. {
  23617. }
  23618. PluginDescription::~PluginDescription() throw()
  23619. {
  23620. }
  23621. PluginDescription::PluginDescription (const PluginDescription& other) throw()
  23622. : name (other.name),
  23623. pluginFormatName (other.pluginFormatName),
  23624. category (other.category),
  23625. manufacturerName (other.manufacturerName),
  23626. version (other.version),
  23627. fileOrIdentifier (other.fileOrIdentifier),
  23628. lastFileModTime (other.lastFileModTime),
  23629. uid (other.uid),
  23630. isInstrument (other.isInstrument),
  23631. numInputChannels (other.numInputChannels),
  23632. numOutputChannels (other.numOutputChannels)
  23633. {
  23634. }
  23635. PluginDescription& PluginDescription::operator= (const PluginDescription& other) throw()
  23636. {
  23637. name = other.name;
  23638. pluginFormatName = other.pluginFormatName;
  23639. category = other.category;
  23640. manufacturerName = other.manufacturerName;
  23641. version = other.version;
  23642. fileOrIdentifier = other.fileOrIdentifier;
  23643. uid = other.uid;
  23644. isInstrument = other.isInstrument;
  23645. lastFileModTime = other.lastFileModTime;
  23646. numInputChannels = other.numInputChannels;
  23647. numOutputChannels = other.numOutputChannels;
  23648. return *this;
  23649. }
  23650. bool PluginDescription::isDuplicateOf (const PluginDescription& other) const
  23651. {
  23652. return fileOrIdentifier == other.fileOrIdentifier
  23653. && uid == other.uid;
  23654. }
  23655. const String PluginDescription::createIdentifierString() const throw()
  23656. {
  23657. return pluginFormatName
  23658. + "-" + name
  23659. + "-" + String::toHexString (fileOrIdentifier.hashCode())
  23660. + "-" + String::toHexString (uid);
  23661. }
  23662. XmlElement* PluginDescription::createXml() const
  23663. {
  23664. XmlElement* const e = new XmlElement ("PLUGIN");
  23665. e->setAttribute ("name", name);
  23666. e->setAttribute ("format", pluginFormatName);
  23667. e->setAttribute ("category", category);
  23668. e->setAttribute ("manufacturer", manufacturerName);
  23669. e->setAttribute ("version", version);
  23670. e->setAttribute ("file", fileOrIdentifier);
  23671. e->setAttribute ("uid", String::toHexString (uid));
  23672. e->setAttribute ("isInstrument", isInstrument);
  23673. e->setAttribute ("fileTime", String::toHexString (lastFileModTime.toMilliseconds()));
  23674. e->setAttribute ("numInputs", numInputChannels);
  23675. e->setAttribute ("numOutputs", numOutputChannels);
  23676. return e;
  23677. }
  23678. bool PluginDescription::loadFromXml (const XmlElement& xml)
  23679. {
  23680. if (xml.hasTagName ("PLUGIN"))
  23681. {
  23682. name = xml.getStringAttribute ("name");
  23683. pluginFormatName = xml.getStringAttribute ("format");
  23684. category = xml.getStringAttribute ("category");
  23685. manufacturerName = xml.getStringAttribute ("manufacturer");
  23686. version = xml.getStringAttribute ("version");
  23687. fileOrIdentifier = xml.getStringAttribute ("file");
  23688. uid = xml.getStringAttribute ("uid").getHexValue32();
  23689. isInstrument = xml.getBoolAttribute ("isInstrument", false);
  23690. lastFileModTime = Time (xml.getStringAttribute ("fileTime").getHexValue64());
  23691. numInputChannels = xml.getIntAttribute ("numInputs");
  23692. numOutputChannels = xml.getIntAttribute ("numOutputs");
  23693. return true;
  23694. }
  23695. return false;
  23696. }
  23697. END_JUCE_NAMESPACE
  23698. /*** End of inlined file: juce_PluginDescription.cpp ***/
  23699. /*** Start of inlined file: juce_PluginDirectoryScanner.cpp ***/
  23700. BEGIN_JUCE_NAMESPACE
  23701. PluginDirectoryScanner::PluginDirectoryScanner (KnownPluginList& listToAddTo,
  23702. AudioPluginFormat& formatToLookFor,
  23703. FileSearchPath directoriesToSearch,
  23704. const bool recursive,
  23705. const File& deadMansPedalFile_)
  23706. : list (listToAddTo),
  23707. format (formatToLookFor),
  23708. deadMansPedalFile (deadMansPedalFile_),
  23709. nextIndex (0),
  23710. progress (0)
  23711. {
  23712. directoriesToSearch.removeRedundantPaths();
  23713. filesOrIdentifiersToScan = format.searchPathsForPlugins (directoriesToSearch, recursive);
  23714. // If any plugins have crashed recently when being loaded, move them to the
  23715. // end of the list to give the others a chance to load correctly..
  23716. const StringArray crashedPlugins (getDeadMansPedalFile());
  23717. for (int i = 0; i < crashedPlugins.size(); ++i)
  23718. {
  23719. const String f = crashedPlugins[i];
  23720. for (int j = filesOrIdentifiersToScan.size(); --j >= 0;)
  23721. if (f == filesOrIdentifiersToScan[j])
  23722. filesOrIdentifiersToScan.move (j, -1);
  23723. }
  23724. }
  23725. PluginDirectoryScanner::~PluginDirectoryScanner()
  23726. {
  23727. }
  23728. const String PluginDirectoryScanner::getNextPluginFileThatWillBeScanned() const throw()
  23729. {
  23730. return format.getNameOfPluginFromIdentifier (filesOrIdentifiersToScan [nextIndex]);
  23731. }
  23732. bool PluginDirectoryScanner::scanNextFile (const bool dontRescanIfAlreadyInList)
  23733. {
  23734. String file (filesOrIdentifiersToScan [nextIndex]);
  23735. if (file.isNotEmpty())
  23736. {
  23737. if (! list.isListingUpToDate (file))
  23738. {
  23739. OwnedArray <PluginDescription> typesFound;
  23740. // Add this plugin to the end of the dead-man's pedal list in case it crashes...
  23741. StringArray crashedPlugins (getDeadMansPedalFile());
  23742. crashedPlugins.removeString (file);
  23743. crashedPlugins.add (file);
  23744. setDeadMansPedalFile (crashedPlugins);
  23745. list.scanAndAddFile (file,
  23746. dontRescanIfAlreadyInList,
  23747. typesFound,
  23748. format);
  23749. // Managed to load without crashing, so remove it from the dead-man's-pedal..
  23750. crashedPlugins.removeString (file);
  23751. setDeadMansPedalFile (crashedPlugins);
  23752. if (typesFound.size() == 0)
  23753. failedFiles.add (file);
  23754. }
  23755. ++nextIndex;
  23756. progress = nextIndex / (float) filesOrIdentifiersToScan.size();
  23757. }
  23758. return nextIndex < filesOrIdentifiersToScan.size();
  23759. }
  23760. const StringArray PluginDirectoryScanner::getDeadMansPedalFile() throw()
  23761. {
  23762. StringArray lines;
  23763. if (deadMansPedalFile != File::nonexistent)
  23764. {
  23765. lines.addLines (deadMansPedalFile.loadFileAsString());
  23766. lines.removeEmptyStrings();
  23767. }
  23768. return lines;
  23769. }
  23770. void PluginDirectoryScanner::setDeadMansPedalFile (const StringArray& newContents) throw()
  23771. {
  23772. if (deadMansPedalFile != File::nonexistent)
  23773. deadMansPedalFile.replaceWithText (newContents.joinIntoString ("\n"), true, true);
  23774. }
  23775. END_JUCE_NAMESPACE
  23776. /*** End of inlined file: juce_PluginDirectoryScanner.cpp ***/
  23777. /*** Start of inlined file: juce_PluginListComponent.cpp ***/
  23778. BEGIN_JUCE_NAMESPACE
  23779. PluginListComponent::PluginListComponent (KnownPluginList& listToEdit,
  23780. const File& deadMansPedalFile_,
  23781. PropertiesFile* const propertiesToUse_)
  23782. : list (listToEdit),
  23783. deadMansPedalFile (deadMansPedalFile_),
  23784. propertiesToUse (propertiesToUse_)
  23785. {
  23786. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  23787. addAndMakeVisible (optionsButton = new TextButton ("Options..."));
  23788. optionsButton->addButtonListener (this);
  23789. optionsButton->setTriggeredOnMouseDown (true);
  23790. setSize (400, 600);
  23791. list.addChangeListener (this);
  23792. }
  23793. PluginListComponent::~PluginListComponent()
  23794. {
  23795. list.removeChangeListener (this);
  23796. deleteAllChildren();
  23797. }
  23798. void PluginListComponent::resized()
  23799. {
  23800. listBox->setBounds (0, 0, getWidth(), getHeight() - 30);
  23801. optionsButton->changeWidthToFitText (24);
  23802. optionsButton->setTopLeftPosition (8, getHeight() - 28);
  23803. }
  23804. void PluginListComponent::changeListenerCallback (void*)
  23805. {
  23806. listBox->updateContent();
  23807. listBox->repaint();
  23808. }
  23809. int PluginListComponent::getNumRows()
  23810. {
  23811. return list.getNumTypes();
  23812. }
  23813. void PluginListComponent::paintListBoxItem (int row,
  23814. Graphics& g,
  23815. int width, int height,
  23816. bool rowIsSelected)
  23817. {
  23818. if (rowIsSelected)
  23819. g.fillAll (findColour (TextEditor::highlightColourId));
  23820. const PluginDescription* const pd = list.getType (row);
  23821. if (pd != 0)
  23822. {
  23823. GlyphArrangement ga;
  23824. ga.addCurtailedLineOfText (Font (height * 0.7f, Font::bold), pd->name, 8.0f, height * 0.8f, width - 10.0f, true);
  23825. g.setColour (Colours::black);
  23826. ga.draw (g);
  23827. float x, y, r, b;
  23828. ga.getBoundingBox (0, -1, x, y, r, b, false);
  23829. String desc;
  23830. desc << pd->pluginFormatName
  23831. << (pd->isInstrument ? " instrument" : " effect")
  23832. << " - "
  23833. << pd->numInputChannels << (pd->numInputChannels == 1 ? " in" : " ins")
  23834. << " / "
  23835. << pd->numOutputChannels << (pd->numOutputChannels == 1 ? " out" : " outs");
  23836. if (pd->manufacturerName.isNotEmpty())
  23837. desc << " - " << pd->manufacturerName;
  23838. if (pd->version.isNotEmpty())
  23839. desc << " - " << pd->version;
  23840. if (pd->category.isNotEmpty())
  23841. desc << " - category: '" << pd->category << '\'';
  23842. g.setColour (Colours::grey);
  23843. ga.clear();
  23844. ga.addCurtailedLineOfText (Font (height * 0.6f), desc, r + 10.0f, height * 0.8f, width - r - 12.0f, true);
  23845. ga.draw (g);
  23846. }
  23847. }
  23848. void PluginListComponent::deleteKeyPressed (int lastRowSelected)
  23849. {
  23850. list.removeType (lastRowSelected);
  23851. }
  23852. void PluginListComponent::buttonClicked (Button* b)
  23853. {
  23854. if (optionsButton == b)
  23855. {
  23856. PopupMenu menu;
  23857. menu.addItem (1, TRANS("Clear list"));
  23858. menu.addItem (5, TRANS("Remove selected plugin from list"), listBox->getNumSelectedRows() > 0);
  23859. menu.addItem (6, TRANS("Show folder containing selected plugin"), listBox->getNumSelectedRows() > 0);
  23860. menu.addItem (7, TRANS("Remove any plugins whose files no longer exist"));
  23861. menu.addSeparator();
  23862. menu.addItem (2, TRANS("Sort alphabetically"));
  23863. menu.addItem (3, TRANS("Sort by category"));
  23864. menu.addItem (4, TRANS("Sort by manufacturer"));
  23865. menu.addSeparator();
  23866. for (int i = 0; i < AudioPluginFormatManager::getInstance()->getNumFormats(); ++i)
  23867. {
  23868. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (i);
  23869. if (format->getDefaultLocationsToSearch().getNumPaths() > 0)
  23870. menu.addItem (10 + i, "Scan for new or updated " + format->getName() + " plugins...");
  23871. }
  23872. const int r = menu.showAt (optionsButton);
  23873. if (r == 1)
  23874. {
  23875. list.clear();
  23876. }
  23877. else if (r == 2)
  23878. {
  23879. list.sort (KnownPluginList::sortAlphabetically);
  23880. }
  23881. else if (r == 3)
  23882. {
  23883. list.sort (KnownPluginList::sortByCategory);
  23884. }
  23885. else if (r == 4)
  23886. {
  23887. list.sort (KnownPluginList::sortByManufacturer);
  23888. }
  23889. else if (r == 5)
  23890. {
  23891. const SparseSet <int> selected (listBox->getSelectedRows());
  23892. for (int i = list.getNumTypes(); --i >= 0;)
  23893. if (selected.contains (i))
  23894. list.removeType (i);
  23895. }
  23896. else if (r == 6)
  23897. {
  23898. const PluginDescription* const desc = list.getType (listBox->getSelectedRow());
  23899. if (desc != 0)
  23900. {
  23901. if (File (desc->fileOrIdentifier).existsAsFile())
  23902. File (desc->fileOrIdentifier).getParentDirectory().startAsProcess();
  23903. }
  23904. }
  23905. else if (r == 7)
  23906. {
  23907. for (int i = list.getNumTypes(); --i >= 0;)
  23908. {
  23909. if (! AudioPluginFormatManager::getInstance()->doesPluginStillExist (*list.getType (i)))
  23910. {
  23911. list.removeType (i);
  23912. }
  23913. }
  23914. }
  23915. else if (r != 0)
  23916. {
  23917. typeToScan = r - 10;
  23918. startTimer (1);
  23919. }
  23920. }
  23921. }
  23922. void PluginListComponent::timerCallback()
  23923. {
  23924. stopTimer();
  23925. scanFor (AudioPluginFormatManager::getInstance()->getFormat (typeToScan));
  23926. }
  23927. bool PluginListComponent::isInterestedInFileDrag (const StringArray& /*files*/)
  23928. {
  23929. return true;
  23930. }
  23931. void PluginListComponent::filesDropped (const StringArray& files, int, int)
  23932. {
  23933. OwnedArray <PluginDescription> typesFound;
  23934. list.scanAndAddDragAndDroppedFiles (files, typesFound);
  23935. }
  23936. void PluginListComponent::scanFor (AudioPluginFormat* format)
  23937. {
  23938. if (format == 0)
  23939. return;
  23940. FileSearchPath path (format->getDefaultLocationsToSearch());
  23941. if (propertiesToUse != 0)
  23942. path = propertiesToUse->getValue ("lastPluginScanPath_" + format->getName(), path.toString());
  23943. {
  23944. AlertWindow aw (TRANS("Select folders to scan..."), String::empty, AlertWindow::NoIcon);
  23945. FileSearchPathListComponent pathList;
  23946. pathList.setSize (500, 300);
  23947. pathList.setPath (path);
  23948. aw.addCustomComponent (&pathList);
  23949. aw.addButton (TRANS("Scan"), 1, KeyPress::returnKey);
  23950. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  23951. if (aw.runModalLoop() == 0)
  23952. return;
  23953. path = pathList.getPath();
  23954. }
  23955. if (propertiesToUse != 0)
  23956. {
  23957. propertiesToUse->setValue ("lastPluginScanPath_" + format->getName(), path.toString());
  23958. propertiesToUse->saveIfNeeded();
  23959. }
  23960. double progress = 0.0;
  23961. AlertWindow aw (TRANS("Scanning for plugins..."),
  23962. TRANS("Searching for all possible plugin files..."), AlertWindow::NoIcon);
  23963. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  23964. aw.addProgressBarComponent (progress);
  23965. aw.enterModalState();
  23966. MessageManager::getInstance()->runDispatchLoopUntil (300);
  23967. PluginDirectoryScanner scanner (list, *format, path, true, deadMansPedalFile);
  23968. for (;;)
  23969. {
  23970. aw.setMessage (TRANS("Testing:\n\n")
  23971. + scanner.getNextPluginFileThatWillBeScanned());
  23972. MessageManager::getInstance()->runDispatchLoopUntil (20);
  23973. if (! scanner.scanNextFile (true))
  23974. break;
  23975. if (! aw.isCurrentlyModal())
  23976. break;
  23977. progress = scanner.getProgress();
  23978. }
  23979. if (scanner.getFailedFiles().size() > 0)
  23980. {
  23981. StringArray shortNames;
  23982. for (int i = 0; i < scanner.getFailedFiles().size(); ++i)
  23983. shortNames.add (File (scanner.getFailedFiles()[i]).getFileName());
  23984. AlertWindow::showMessageBox (AlertWindow::InfoIcon,
  23985. TRANS("Scan complete"),
  23986. TRANS("Note that the following files appeared to be plugin files, but failed to load correctly:\n\n")
  23987. + shortNames.joinIntoString (", "));
  23988. }
  23989. }
  23990. END_JUCE_NAMESPACE
  23991. /*** End of inlined file: juce_PluginListComponent.cpp ***/
  23992. /*** Start of inlined file: juce_AudioUnitPluginFormat.mm ***/
  23993. #if JUCE_PLUGINHOST_AU && (! (defined (LINUX) || defined (_WIN32)))
  23994. #include <AudioUnit/AudioUnit.h>
  23995. #include <AudioUnit/AUCocoaUIView.h>
  23996. #include <CoreAudioKit/AUGenericView.h>
  23997. #if JUCE_SUPPORT_CARBON
  23998. #include <AudioToolbox/AudioUnitUtilities.h>
  23999. #include <AudioUnit/AudioUnitCarbonView.h>
  24000. #endif
  24001. BEGIN_JUCE_NAMESPACE
  24002. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  24003. #endif
  24004. #if JUCE_MAC
  24005. // Change this to disable logging of various activities
  24006. #ifndef AU_LOGGING
  24007. #define AU_LOGGING 1
  24008. #endif
  24009. #if AU_LOGGING
  24010. #define log(a) Logger::writeToLog(a);
  24011. #else
  24012. #define log(a)
  24013. #endif
  24014. static int insideCallback = 0;
  24015. static const String osTypeToString (OSType type)
  24016. {
  24017. char s[4];
  24018. s[0] = (char) (((uint32) type) >> 24);
  24019. s[1] = (char) (((uint32) type) >> 16);
  24020. s[2] = (char) (((uint32) type) >> 8);
  24021. s[3] = (char) ((uint32) type);
  24022. return String (s, 4);
  24023. }
  24024. static OSType stringToOSType (const String& s1)
  24025. {
  24026. const String s (s1 + " ");
  24027. return (((OSType) (unsigned char) s[0]) << 24)
  24028. | (((OSType) (unsigned char) s[1]) << 16)
  24029. | (((OSType) (unsigned char) s[2]) << 8)
  24030. | ((OSType) (unsigned char) s[3]);
  24031. }
  24032. static const tchar* auIdentifierPrefix = T("AudioUnit:");
  24033. static const String createAUPluginIdentifier (const ComponentDescription& desc)
  24034. {
  24035. jassert (osTypeToString ('abcd') == "abcd"); // agh, must have got the endianness wrong..
  24036. jassert (stringToOSType ("abcd") == (OSType) 'abcd'); // ditto
  24037. String s (auIdentifierPrefix);
  24038. if (desc.componentType == kAudioUnitType_MusicDevice)
  24039. s << "Synths/";
  24040. else if (desc.componentType == kAudioUnitType_MusicEffect
  24041. || desc.componentType == kAudioUnitType_Effect)
  24042. s << "Effects/";
  24043. else if (desc.componentType == kAudioUnitType_Generator)
  24044. s << "Generators/";
  24045. else if (desc.componentType == kAudioUnitType_Panner)
  24046. s << "Panners/";
  24047. s << osTypeToString (desc.componentType) << ","
  24048. << osTypeToString (desc.componentSubType) << ","
  24049. << osTypeToString (desc.componentManufacturer);
  24050. return s;
  24051. }
  24052. static void getAUDetails (ComponentRecord* comp, String& name, String& manufacturer)
  24053. {
  24054. Handle componentNameHandle = NewHandle (sizeof (void*));
  24055. Handle componentInfoHandle = NewHandle (sizeof (void*));
  24056. if (componentNameHandle != 0 && componentInfoHandle != 0)
  24057. {
  24058. ComponentDescription desc;
  24059. if (GetComponentInfo (comp, &desc, componentNameHandle, componentInfoHandle, 0) == noErr)
  24060. {
  24061. ConstStr255Param nameString = (ConstStr255Param) (*componentNameHandle);
  24062. ConstStr255Param infoString = (ConstStr255Param) (*componentInfoHandle);
  24063. if (nameString != 0 && nameString[0] != 0)
  24064. {
  24065. const String all ((const char*) nameString + 1, nameString[0]);
  24066. DBG ("name: "+ all);
  24067. manufacturer = all.upToFirstOccurrenceOf (T(":"), false, false).trim();
  24068. name = all.fromFirstOccurrenceOf (T(":"), false, false).trim();
  24069. }
  24070. if (infoString != 0 && infoString[0] != 0)
  24071. {
  24072. DBG ("info: " + String ((const char*) infoString + 1, infoString[0]));
  24073. }
  24074. if (name.isEmpty())
  24075. name = "<Unknown>";
  24076. }
  24077. DisposeHandle (componentNameHandle);
  24078. DisposeHandle (componentInfoHandle);
  24079. }
  24080. }
  24081. static bool getComponentDescFromIdentifier (const String& fileOrIdentifier, ComponentDescription& desc,
  24082. String& name, String& version, String& manufacturer)
  24083. {
  24084. zerostruct (desc);
  24085. if (fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  24086. {
  24087. String s (fileOrIdentifier.substring (jmax (fileOrIdentifier.lastIndexOfChar (':'),
  24088. fileOrIdentifier.lastIndexOfChar ('/')) + 1));
  24089. StringArray tokens;
  24090. tokens.addTokens (s, ",", String::empty);
  24091. tokens.trim();
  24092. tokens.removeEmptyStrings();
  24093. if (tokens.size() == 3)
  24094. {
  24095. desc.componentType = stringToOSType (tokens[0]);
  24096. desc.componentSubType = stringToOSType (tokens[1]);
  24097. desc.componentManufacturer = stringToOSType (tokens[2]);
  24098. ComponentRecord* comp = FindNextComponent (0, &desc);
  24099. if (comp != 0)
  24100. {
  24101. getAUDetails (comp, name, manufacturer);
  24102. return true;
  24103. }
  24104. }
  24105. }
  24106. return false;
  24107. }
  24108. class AudioUnitPluginWindowCarbon;
  24109. class AudioUnitPluginWindowCocoa;
  24110. class AudioUnitPluginInstance : public AudioPluginInstance
  24111. {
  24112. public:
  24113. ~AudioUnitPluginInstance();
  24114. // AudioPluginInstance methods:
  24115. void fillInPluginDescription (PluginDescription& desc) const
  24116. {
  24117. desc.name = pluginName;
  24118. desc.fileOrIdentifier = createAUPluginIdentifier (componentDesc);
  24119. desc.uid = ((int) componentDesc.componentType)
  24120. ^ ((int) componentDesc.componentSubType)
  24121. ^ ((int) componentDesc.componentManufacturer);
  24122. desc.lastFileModTime = 0;
  24123. desc.pluginFormatName = "AudioUnit";
  24124. desc.category = getCategory();
  24125. desc.manufacturerName = manufacturer;
  24126. desc.version = version;
  24127. desc.numInputChannels = getNumInputChannels();
  24128. desc.numOutputChannels = getNumOutputChannels();
  24129. desc.isInstrument = (componentDesc.componentType == kAudioUnitType_MusicDevice);
  24130. }
  24131. const String getName() const { return pluginName; }
  24132. bool acceptsMidi() const { return wantsMidiMessages; }
  24133. bool producesMidi() const { return false; }
  24134. // AudioProcessor methods:
  24135. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  24136. void releaseResources();
  24137. void processBlock (AudioSampleBuffer& buffer,
  24138. MidiBuffer& midiMessages);
  24139. AudioProcessorEditor* createEditor();
  24140. const String getInputChannelName (const int index) const;
  24141. bool isInputChannelStereoPair (int index) const;
  24142. const String getOutputChannelName (const int index) const;
  24143. bool isOutputChannelStereoPair (int index) const;
  24144. int getNumParameters();
  24145. float getParameter (int index);
  24146. void setParameter (int index, float newValue);
  24147. const String getParameterName (int index);
  24148. const String getParameterText (int index);
  24149. bool isParameterAutomatable (int index) const;
  24150. int getNumPrograms();
  24151. int getCurrentProgram();
  24152. void setCurrentProgram (int index);
  24153. const String getProgramName (int index);
  24154. void changeProgramName (int index, const String& newName);
  24155. void getStateInformation (MemoryBlock& destData);
  24156. void getCurrentProgramStateInformation (MemoryBlock& destData);
  24157. void setStateInformation (const void* data, int sizeInBytes);
  24158. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  24159. juce_UseDebuggingNewOperator
  24160. private:
  24161. friend class AudioUnitPluginWindowCarbon;
  24162. friend class AudioUnitPluginWindowCocoa;
  24163. friend class AudioUnitPluginFormat;
  24164. ComponentDescription componentDesc;
  24165. String pluginName, manufacturer, version;
  24166. String fileOrIdentifier;
  24167. CriticalSection lock;
  24168. bool initialised, wantsMidiMessages, wasPlaying;
  24169. HeapBlock <AudioBufferList> outputBufferList;
  24170. AudioTimeStamp timeStamp;
  24171. AudioSampleBuffer* currentBuffer;
  24172. AudioUnit audioUnit;
  24173. Array <int> parameterIds;
  24174. bool getComponentDescFromFile (const String& fileOrIdentifier);
  24175. void initialise();
  24176. OSStatus renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24177. const AudioTimeStamp* inTimeStamp,
  24178. UInt32 inBusNumber,
  24179. UInt32 inNumberFrames,
  24180. AudioBufferList* ioData) const;
  24181. static OSStatus renderGetInputCallback (void* inRefCon,
  24182. AudioUnitRenderActionFlags* ioActionFlags,
  24183. const AudioTimeStamp* inTimeStamp,
  24184. UInt32 inBusNumber,
  24185. UInt32 inNumberFrames,
  24186. AudioBufferList* ioData)
  24187. {
  24188. return ((AudioUnitPluginInstance*) inRefCon)
  24189. ->renderGetInput (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  24190. }
  24191. OSStatus getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const;
  24192. OSStatus getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat, Float32* outTimeSig_Numerator,
  24193. UInt32* outTimeSig_Denominator, Float64* outCurrentMeasureDownBeat) const;
  24194. OSStatus getTransportState (Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24195. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24196. Float64* outCycleStartBeat, Float64* outCycleEndBeat);
  24197. static OSStatus getBeatAndTempoCallback (void* inHostUserData, Float64* outCurrentBeat, Float64* outCurrentTempo)
  24198. {
  24199. return ((AudioUnitPluginInstance*) inHostUserData)->getBeatAndTempo (outCurrentBeat, outCurrentTempo);
  24200. }
  24201. static OSStatus getMusicalTimeLocationCallback (void* inHostUserData, UInt32* outDeltaSampleOffsetToNextBeat,
  24202. Float32* outTimeSig_Numerator, UInt32* outTimeSig_Denominator,
  24203. Float64* outCurrentMeasureDownBeat)
  24204. {
  24205. return ((AudioUnitPluginInstance*) inHostUserData)
  24206. ->getMusicalTimeLocation (outDeltaSampleOffsetToNextBeat, outTimeSig_Numerator,
  24207. outTimeSig_Denominator, outCurrentMeasureDownBeat);
  24208. }
  24209. static OSStatus getTransportStateCallback (void* inHostUserData, Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24210. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24211. Float64* outCycleStartBeat, Float64* outCycleEndBeat)
  24212. {
  24213. return ((AudioUnitPluginInstance*) inHostUserData)
  24214. ->getTransportState (outIsPlaying, outTransportStateChanged,
  24215. outCurrentSampleInTimeLine, outIsCycling,
  24216. outCycleStartBeat, outCycleEndBeat);
  24217. }
  24218. void getNumChannels (int& numIns, int& numOuts)
  24219. {
  24220. numIns = 0;
  24221. numOuts = 0;
  24222. AUChannelInfo supportedChannels [128];
  24223. UInt32 supportedChannelsSize = sizeof (supportedChannels);
  24224. if (AudioUnitGetProperty (audioUnit, kAudioUnitProperty_SupportedNumChannels, kAudioUnitScope_Global,
  24225. 0, supportedChannels, &supportedChannelsSize) == noErr
  24226. && supportedChannelsSize > 0)
  24227. {
  24228. for (int i = 0; i < supportedChannelsSize / sizeof (AUChannelInfo); ++i)
  24229. {
  24230. numIns = jmax (numIns, (int) supportedChannels[i].inChannels);
  24231. numOuts = jmax (numOuts, (int) supportedChannels[i].outChannels);
  24232. }
  24233. }
  24234. else
  24235. {
  24236. // (this really means the plugin will take any number of ins/outs as long
  24237. // as they are the same)
  24238. numIns = numOuts = 2;
  24239. }
  24240. }
  24241. const String getCategory() const;
  24242. AudioUnitPluginInstance (const String& fileOrIdentifier);
  24243. };
  24244. AudioUnitPluginInstance::AudioUnitPluginInstance (const String& fileOrIdentifier)
  24245. : fileOrIdentifier (fileOrIdentifier),
  24246. initialised (false),
  24247. wantsMidiMessages (false),
  24248. audioUnit (0),
  24249. currentBuffer (0)
  24250. {
  24251. try
  24252. {
  24253. ++insideCallback;
  24254. log ("Opening AU: " + fileOrIdentifier);
  24255. if (getComponentDescFromFile (fileOrIdentifier))
  24256. {
  24257. ComponentRecord* const comp = FindNextComponent (0, &componentDesc);
  24258. if (comp != 0)
  24259. {
  24260. audioUnit = (AudioUnit) OpenComponent (comp);
  24261. wantsMidiMessages = componentDesc.componentType == kAudioUnitType_MusicDevice
  24262. || componentDesc.componentType == kAudioUnitType_MusicEffect;
  24263. }
  24264. }
  24265. --insideCallback;
  24266. }
  24267. catch (...)
  24268. {
  24269. --insideCallback;
  24270. }
  24271. }
  24272. AudioUnitPluginInstance::~AudioUnitPluginInstance()
  24273. {
  24274. const ScopedLock sl (lock);
  24275. jassert (insideCallback == 0);
  24276. if (audioUnit != 0)
  24277. {
  24278. AudioUnitUninitialize (audioUnit);
  24279. CloseComponent (audioUnit);
  24280. audioUnit = 0;
  24281. }
  24282. }
  24283. bool AudioUnitPluginInstance::getComponentDescFromFile (const String& fileOrIdentifier)
  24284. {
  24285. zerostruct (componentDesc);
  24286. if (getComponentDescFromIdentifier (fileOrIdentifier, componentDesc, pluginName, version, manufacturer))
  24287. return true;
  24288. const File file (fileOrIdentifier);
  24289. if (! file.hasFileExtension (".component"))
  24290. return false;
  24291. const char* const utf8 = fileOrIdentifier.toUTF8();
  24292. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  24293. strlen (utf8), file.isDirectory());
  24294. if (url != 0)
  24295. {
  24296. CFBundleRef bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  24297. CFRelease (url);
  24298. if (bundleRef != 0)
  24299. {
  24300. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  24301. if (name != 0 && CFGetTypeID (name) == CFStringGetTypeID())
  24302. pluginName = PlatformUtilities::cfStringToJuceString ((CFStringRef) name);
  24303. if (pluginName.isEmpty())
  24304. pluginName = file.getFileNameWithoutExtension();
  24305. CFTypeRef versionString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleVersion"));
  24306. if (versionString != 0 && CFGetTypeID (versionString) == CFStringGetTypeID())
  24307. version = PlatformUtilities::cfStringToJuceString ((CFStringRef) versionString);
  24308. CFTypeRef manuString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleGetInfoString"));
  24309. if (manuString != 0 && CFGetTypeID (manuString) == CFStringGetTypeID())
  24310. manufacturer = PlatformUtilities::cfStringToJuceString ((CFStringRef) manuString);
  24311. short resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  24312. UseResFile (resFileId);
  24313. for (int i = 1; i <= Count1Resources ('thng'); ++i)
  24314. {
  24315. Handle h = Get1IndResource ('thng', i);
  24316. if (h != 0)
  24317. {
  24318. HLock (h);
  24319. const uint32* const types = (const uint32*) *h;
  24320. if (types[0] == kAudioUnitType_MusicDevice
  24321. || types[0] == kAudioUnitType_MusicEffect
  24322. || types[0] == kAudioUnitType_Effect
  24323. || types[0] == kAudioUnitType_Generator
  24324. || types[0] == kAudioUnitType_Panner)
  24325. {
  24326. componentDesc.componentType = types[0];
  24327. componentDesc.componentSubType = types[1];
  24328. componentDesc.componentManufacturer = types[2];
  24329. break;
  24330. }
  24331. HUnlock (h);
  24332. ReleaseResource (h);
  24333. }
  24334. }
  24335. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  24336. CFRelease (bundleRef);
  24337. }
  24338. }
  24339. return componentDesc.componentType != 0 && componentDesc.componentSubType != 0;
  24340. }
  24341. void AudioUnitPluginInstance::initialise()
  24342. {
  24343. if (initialised || audioUnit == 0)
  24344. return;
  24345. log ("Initialising AU: " + pluginName);
  24346. parameterIds.clear();
  24347. {
  24348. UInt32 paramListSize = 0;
  24349. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24350. 0, 0, &paramListSize);
  24351. if (paramListSize > 0)
  24352. {
  24353. parameterIds.insertMultiple (0, 0, paramListSize / sizeof (int));
  24354. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24355. 0, &parameterIds.getReference(0), &paramListSize);
  24356. }
  24357. }
  24358. {
  24359. AURenderCallbackStruct info;
  24360. zerostruct (info);
  24361. info.inputProcRefCon = this;
  24362. info.inputProc = renderGetInputCallback;
  24363. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input,
  24364. 0, &info, sizeof (info));
  24365. }
  24366. {
  24367. HostCallbackInfo info;
  24368. zerostruct (info);
  24369. info.hostUserData = this;
  24370. info.beatAndTempoProc = getBeatAndTempoCallback;
  24371. info.musicalTimeLocationProc = getMusicalTimeLocationCallback;
  24372. info.transportStateProc = getTransportStateCallback;
  24373. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_HostCallbacks, kAudioUnitScope_Global,
  24374. 0, &info, sizeof (info));
  24375. }
  24376. int numIns, numOuts;
  24377. getNumChannels (numIns, numOuts);
  24378. setPlayConfigDetails (numIns, numOuts, 0, 0);
  24379. initialised = AudioUnitInitialize (audioUnit) == noErr;
  24380. setLatencySamples (0);
  24381. }
  24382. void AudioUnitPluginInstance::prepareToPlay (double sampleRate_,
  24383. int samplesPerBlockExpected)
  24384. {
  24385. initialise();
  24386. if (initialised)
  24387. {
  24388. int numIns, numOuts;
  24389. getNumChannels (numIns, numOuts);
  24390. setPlayConfigDetails (numIns, numOuts, sampleRate_, samplesPerBlockExpected);
  24391. Float64 latencySecs = 0.0;
  24392. UInt32 latencySize = sizeof (latencySecs);
  24393. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_Latency, kAudioUnitScope_Global,
  24394. 0, &latencySecs, &latencySize);
  24395. setLatencySamples (roundToInt (latencySecs * sampleRate_));
  24396. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24397. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24398. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24399. AudioStreamBasicDescription stream;
  24400. zerostruct (stream);
  24401. stream.mSampleRate = sampleRate_;
  24402. stream.mFormatID = kAudioFormatLinearPCM;
  24403. stream.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved;
  24404. stream.mFramesPerPacket = 1;
  24405. stream.mBytesPerPacket = 4;
  24406. stream.mBytesPerFrame = 4;
  24407. stream.mBitsPerChannel = 32;
  24408. stream.mChannelsPerFrame = numIns;
  24409. OSStatus err = AudioUnitSetProperty (audioUnit,
  24410. kAudioUnitProperty_StreamFormat,
  24411. kAudioUnitScope_Input,
  24412. 0, &stream, sizeof (stream));
  24413. stream.mChannelsPerFrame = numOuts;
  24414. err = AudioUnitSetProperty (audioUnit,
  24415. kAudioUnitProperty_StreamFormat,
  24416. kAudioUnitScope_Output,
  24417. 0, &stream, sizeof (stream));
  24418. outputBufferList.calloc (sizeof (AudioBufferList) + sizeof (AudioBuffer) * (numOuts + 1), 1);
  24419. outputBufferList->mNumberBuffers = numOuts;
  24420. for (int i = numOuts; --i >= 0;)
  24421. outputBufferList->mBuffers[i].mNumberChannels = 1;
  24422. zerostruct (timeStamp);
  24423. timeStamp.mSampleTime = 0;
  24424. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24425. timeStamp.mFlags = kAudioTimeStampSampleTimeValid | kAudioTimeStampHostTimeValid;
  24426. currentBuffer = 0;
  24427. wasPlaying = false;
  24428. }
  24429. }
  24430. void AudioUnitPluginInstance::releaseResources()
  24431. {
  24432. if (initialised)
  24433. {
  24434. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24435. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24436. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24437. outputBufferList.free();
  24438. currentBuffer = 0;
  24439. }
  24440. }
  24441. OSStatus AudioUnitPluginInstance::renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24442. const AudioTimeStamp* inTimeStamp,
  24443. UInt32 inBusNumber,
  24444. UInt32 inNumberFrames,
  24445. AudioBufferList* ioData) const
  24446. {
  24447. if (inBusNumber == 0
  24448. && currentBuffer != 0)
  24449. {
  24450. jassert (inNumberFrames == currentBuffer->getNumSamples()); // if this ever happens, might need to add extra handling
  24451. for (int i = 0; i < ioData->mNumberBuffers; ++i)
  24452. {
  24453. if (i < currentBuffer->getNumChannels())
  24454. {
  24455. memcpy (ioData->mBuffers[i].mData,
  24456. currentBuffer->getSampleData (i, 0),
  24457. sizeof (float) * inNumberFrames);
  24458. }
  24459. else
  24460. {
  24461. zeromem (ioData->mBuffers[i].mData, sizeof (float) * inNumberFrames);
  24462. }
  24463. }
  24464. }
  24465. return noErr;
  24466. }
  24467. void AudioUnitPluginInstance::processBlock (AudioSampleBuffer& buffer,
  24468. MidiBuffer& midiMessages)
  24469. {
  24470. const int numSamples = buffer.getNumSamples();
  24471. if (initialised)
  24472. {
  24473. AudioUnitRenderActionFlags flags = 0;
  24474. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24475. for (int i = getNumOutputChannels(); --i >= 0;)
  24476. {
  24477. outputBufferList->mBuffers[i].mDataByteSize = sizeof (float) * numSamples;
  24478. outputBufferList->mBuffers[i].mData = buffer.getSampleData (i, 0);
  24479. }
  24480. currentBuffer = &buffer;
  24481. if (wantsMidiMessages)
  24482. {
  24483. const uint8* midiEventData;
  24484. int midiEventSize, midiEventPosition;
  24485. MidiBuffer::Iterator i (midiMessages);
  24486. while (i.getNextEvent (midiEventData, midiEventSize, midiEventPosition))
  24487. {
  24488. if (midiEventSize <= 3)
  24489. MusicDeviceMIDIEvent (audioUnit,
  24490. midiEventData[0], midiEventData[1], midiEventData[2],
  24491. midiEventPosition);
  24492. else
  24493. MusicDeviceSysEx (audioUnit, midiEventData, midiEventSize);
  24494. }
  24495. midiMessages.clear();
  24496. }
  24497. AudioUnitRender (audioUnit, &flags, &timeStamp,
  24498. 0, numSamples, outputBufferList);
  24499. timeStamp.mSampleTime += numSamples;
  24500. }
  24501. else
  24502. {
  24503. // Not initialised, so just bypass..
  24504. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  24505. buffer.clear (i, 0, buffer.getNumSamples());
  24506. }
  24507. }
  24508. OSStatus AudioUnitPluginInstance::getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const
  24509. {
  24510. AudioPlayHead* const ph = getPlayHead();
  24511. AudioPlayHead::CurrentPositionInfo result;
  24512. if (ph != 0 && ph->getCurrentPosition (result))
  24513. {
  24514. if (outCurrentBeat != 0)
  24515. *outCurrentBeat = result.ppqPosition;
  24516. if (outCurrentTempo != 0)
  24517. *outCurrentTempo = result.bpm;
  24518. }
  24519. else
  24520. {
  24521. if (outCurrentBeat != 0)
  24522. *outCurrentBeat = 0;
  24523. if (outCurrentTempo != 0)
  24524. *outCurrentTempo = 120.0;
  24525. }
  24526. return noErr;
  24527. }
  24528. OSStatus AudioUnitPluginInstance::getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat,
  24529. Float32* outTimeSig_Numerator,
  24530. UInt32* outTimeSig_Denominator,
  24531. Float64* outCurrentMeasureDownBeat) const
  24532. {
  24533. AudioPlayHead* const ph = getPlayHead();
  24534. AudioPlayHead::CurrentPositionInfo result;
  24535. if (ph != 0 && ph->getCurrentPosition (result))
  24536. {
  24537. if (outTimeSig_Numerator != 0)
  24538. *outTimeSig_Numerator = result.timeSigNumerator;
  24539. if (outTimeSig_Denominator != 0)
  24540. *outTimeSig_Denominator = result.timeSigDenominator;
  24541. if (outDeltaSampleOffsetToNextBeat != 0)
  24542. *outDeltaSampleOffsetToNextBeat = 0; //xxx
  24543. if (outCurrentMeasureDownBeat != 0)
  24544. *outCurrentMeasureDownBeat = result.ppqPositionOfLastBarStart; //xxx wrong
  24545. }
  24546. else
  24547. {
  24548. if (outDeltaSampleOffsetToNextBeat != 0)
  24549. *outDeltaSampleOffsetToNextBeat = 0;
  24550. if (outTimeSig_Numerator != 0)
  24551. *outTimeSig_Numerator = 4;
  24552. if (outTimeSig_Denominator != 0)
  24553. *outTimeSig_Denominator = 4;
  24554. if (outCurrentMeasureDownBeat != 0)
  24555. *outCurrentMeasureDownBeat = 0;
  24556. }
  24557. return noErr;
  24558. }
  24559. OSStatus AudioUnitPluginInstance::getTransportState (Boolean* outIsPlaying,
  24560. Boolean* outTransportStateChanged,
  24561. Float64* outCurrentSampleInTimeLine,
  24562. Boolean* outIsCycling,
  24563. Float64* outCycleStartBeat,
  24564. Float64* outCycleEndBeat)
  24565. {
  24566. AudioPlayHead* const ph = getPlayHead();
  24567. AudioPlayHead::CurrentPositionInfo result;
  24568. if (ph != 0 && ph->getCurrentPosition (result))
  24569. {
  24570. if (outIsPlaying != 0)
  24571. *outIsPlaying = result.isPlaying;
  24572. if (outTransportStateChanged != 0)
  24573. {
  24574. *outTransportStateChanged = result.isPlaying != wasPlaying;
  24575. wasPlaying = result.isPlaying;
  24576. }
  24577. if (outCurrentSampleInTimeLine != 0)
  24578. *outCurrentSampleInTimeLine = roundToInt (result.timeInSeconds * getSampleRate());
  24579. if (outIsCycling != 0)
  24580. *outIsCycling = false;
  24581. if (outCycleStartBeat != 0)
  24582. *outCycleStartBeat = 0;
  24583. if (outCycleEndBeat != 0)
  24584. *outCycleEndBeat = 0;
  24585. }
  24586. else
  24587. {
  24588. if (outIsPlaying != 0)
  24589. *outIsPlaying = false;
  24590. if (outTransportStateChanged != 0)
  24591. *outTransportStateChanged = false;
  24592. if (outCurrentSampleInTimeLine != 0)
  24593. *outCurrentSampleInTimeLine = 0;
  24594. if (outIsCycling != 0)
  24595. *outIsCycling = false;
  24596. if (outCycleStartBeat != 0)
  24597. *outCycleStartBeat = 0;
  24598. if (outCycleEndBeat != 0)
  24599. *outCycleEndBeat = 0;
  24600. }
  24601. return noErr;
  24602. }
  24603. static VoidArray activeWindows;
  24604. class AudioUnitPluginWindowCocoa : public AudioProcessorEditor
  24605. {
  24606. public:
  24607. AudioUnitPluginWindowCocoa (AudioUnitPluginInstance& plugin_, const bool createGenericViewIfNeeded)
  24608. : AudioProcessorEditor (&plugin_),
  24609. plugin (plugin_),
  24610. wrapper (0)
  24611. {
  24612. addAndMakeVisible (wrapper = new NSViewComponent());
  24613. activeWindows.add (this);
  24614. setOpaque (true);
  24615. setVisible (true);
  24616. setSize (100, 100);
  24617. createView (createGenericViewIfNeeded);
  24618. }
  24619. ~AudioUnitPluginWindowCocoa()
  24620. {
  24621. const bool wasValid = isValid();
  24622. wrapper->setView (0);
  24623. activeWindows.removeValue (this);
  24624. if (wasValid)
  24625. plugin.editorBeingDeleted (this);
  24626. delete wrapper;
  24627. }
  24628. bool isValid() const { return wrapper->getView() != 0; }
  24629. void paint (Graphics& g)
  24630. {
  24631. g.fillAll (Colours::white);
  24632. }
  24633. void resized()
  24634. {
  24635. wrapper->setSize (getWidth(), getHeight());
  24636. }
  24637. private:
  24638. AudioUnitPluginInstance& plugin;
  24639. NSViewComponent* wrapper;
  24640. bool createView (const bool createGenericViewIfNeeded)
  24641. {
  24642. NSView* pluginView = 0;
  24643. UInt32 dataSize = 0;
  24644. Boolean isWritable = false;
  24645. if (AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24646. 0, &dataSize, &isWritable) == noErr
  24647. && dataSize != 0
  24648. && AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24649. 0, &dataSize, &isWritable) == noErr)
  24650. {
  24651. HeapBlock <AudioUnitCocoaViewInfo> info;
  24652. info.calloc (dataSize, 1);
  24653. if (AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24654. 0, info, &dataSize) == noErr)
  24655. {
  24656. NSString* viewClassName = (NSString*) (info->mCocoaAUViewClass[0]);
  24657. NSString* path = (NSString*) CFURLCopyPath (info->mCocoaAUViewBundleLocation);
  24658. NSBundle* viewBundle = [NSBundle bundleWithPath: [path autorelease]];
  24659. Class viewClass = [viewBundle classNamed: viewClassName];
  24660. if ([viewClass conformsToProtocol: @protocol (AUCocoaUIBase)]
  24661. && [viewClass instancesRespondToSelector: @selector (interfaceVersion)]
  24662. && [viewClass instancesRespondToSelector: @selector (uiViewForAudioUnit: withSize:)])
  24663. {
  24664. id factory = [[[viewClass alloc] init] autorelease];
  24665. pluginView = [factory uiViewForAudioUnit: plugin.audioUnit
  24666. withSize: NSMakeSize (getWidth(), getHeight())];
  24667. }
  24668. for (int i = (dataSize - sizeof (CFURLRef)) / sizeof (CFStringRef); --i >= 0;)
  24669. {
  24670. CFRelease (info->mCocoaAUViewClass[i]);
  24671. CFRelease (info->mCocoaAUViewBundleLocation);
  24672. }
  24673. }
  24674. }
  24675. if (createGenericViewIfNeeded && (pluginView == 0))
  24676. pluginView = [[AUGenericView alloc] initWithAudioUnit: plugin.audioUnit];
  24677. wrapper->setView (pluginView);
  24678. if (pluginView != 0)
  24679. setSize ([pluginView frame].size.width,
  24680. [pluginView frame].size.height);
  24681. return pluginView != 0;
  24682. }
  24683. };
  24684. #if JUCE_SUPPORT_CARBON
  24685. class AudioUnitPluginWindowCarbon : public AudioProcessorEditor
  24686. {
  24687. public:
  24688. AudioUnitPluginWindowCarbon (AudioUnitPluginInstance& plugin_)
  24689. : AudioProcessorEditor (&plugin_),
  24690. plugin (plugin_),
  24691. viewComponent (0)
  24692. {
  24693. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  24694. activeWindows.add (this);
  24695. setOpaque (true);
  24696. setVisible (true);
  24697. setSize (400, 300);
  24698. ComponentDescription viewList [16];
  24699. UInt32 viewListSize = sizeof (viewList);
  24700. AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_GetUIComponentList, kAudioUnitScope_Global,
  24701. 0, &viewList, &viewListSize);
  24702. componentRecord = FindNextComponent (0, &viewList[0]);
  24703. }
  24704. ~AudioUnitPluginWindowCarbon()
  24705. {
  24706. innerWrapper = 0;
  24707. activeWindows.removeValue (this);
  24708. if (isValid())
  24709. plugin.editorBeingDeleted (this);
  24710. }
  24711. bool isValid() const throw() { return componentRecord != 0; }
  24712. void paint (Graphics& g)
  24713. {
  24714. g.fillAll (Colours::black);
  24715. }
  24716. void resized()
  24717. {
  24718. innerWrapper->setSize (getWidth(), getHeight());
  24719. }
  24720. bool keyStateChanged (bool)
  24721. {
  24722. return false;
  24723. }
  24724. bool keyPressed (const KeyPress&)
  24725. {
  24726. return false;
  24727. }
  24728. void broughtToFront()
  24729. {
  24730. activeWindows.removeValue (this);
  24731. activeWindows.add (this);
  24732. }
  24733. AudioUnit getAudioUnit() const { return plugin.audioUnit; }
  24734. AudioUnitCarbonView getViewComponent()
  24735. {
  24736. if (viewComponent == 0 && componentRecord != 0)
  24737. viewComponent = (AudioUnitCarbonView) OpenComponent (componentRecord);
  24738. return viewComponent;
  24739. }
  24740. void closeViewComponent()
  24741. {
  24742. if (viewComponent != 0)
  24743. {
  24744. CloseComponent (viewComponent);
  24745. viewComponent = 0;
  24746. }
  24747. }
  24748. juce_UseDebuggingNewOperator
  24749. private:
  24750. AudioUnitPluginInstance& plugin;
  24751. ComponentRecord* componentRecord;
  24752. AudioUnitCarbonView viewComponent;
  24753. class InnerWrapperComponent : public CarbonViewWrapperComponent
  24754. {
  24755. public:
  24756. InnerWrapperComponent (AudioUnitPluginWindowCarbon* const owner_)
  24757. : owner (owner_)
  24758. {
  24759. }
  24760. ~InnerWrapperComponent()
  24761. {
  24762. deleteWindow();
  24763. }
  24764. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  24765. {
  24766. log ("Opening AU GUI: " + owner->plugin.getName());
  24767. AudioUnitCarbonView viewComponent = owner->getViewComponent();
  24768. if (viewComponent == 0)
  24769. return 0;
  24770. Float32Point pos = { 0, 0 };
  24771. Float32Point size = { 250, 200 };
  24772. HIViewRef pluginView = 0;
  24773. AudioUnitCarbonViewCreate (viewComponent,
  24774. owner->getAudioUnit(),
  24775. windowRef,
  24776. rootView,
  24777. &pos,
  24778. &size,
  24779. (ControlRef*) &pluginView);
  24780. return pluginView;
  24781. }
  24782. void removeView (HIViewRef)
  24783. {
  24784. log ("Closing AU GUI: " + owner->plugin.getName());
  24785. owner->closeViewComponent();
  24786. }
  24787. private:
  24788. AudioUnitPluginWindowCarbon* const owner;
  24789. };
  24790. friend class InnerWrapperComponent;
  24791. ScopedPointer<InnerWrapperComponent> innerWrapper;
  24792. };
  24793. #endif
  24794. AudioProcessorEditor* AudioUnitPluginInstance::createEditor()
  24795. {
  24796. ScopedPointer<AudioProcessorEditor> w (new AudioUnitPluginWindowCocoa (*this, false));
  24797. if (! static_cast <AudioUnitPluginWindowCocoa*> (static_cast <AudioProcessorEditor*> (w))->isValid())
  24798. w = 0;
  24799. #if JUCE_SUPPORT_CARBON
  24800. if (w == 0)
  24801. {
  24802. w = new AudioUnitPluginWindowCarbon (*this);
  24803. if (! static_cast <AudioUnitPluginWindowCarbon*> (static_cast <AudioProcessorEditor*> (w))->isValid())
  24804. w = 0;
  24805. }
  24806. #endif
  24807. if (w == 0)
  24808. w = new AudioUnitPluginWindowCocoa (*this, true); // use AUGenericView as a fallback
  24809. return w.release();
  24810. }
  24811. const String AudioUnitPluginInstance::getCategory() const
  24812. {
  24813. const char* result = 0;
  24814. switch (componentDesc.componentType)
  24815. {
  24816. case kAudioUnitType_Effect:
  24817. case kAudioUnitType_MusicEffect:
  24818. result = "Effect";
  24819. break;
  24820. case kAudioUnitType_MusicDevice:
  24821. result = "Synth";
  24822. break;
  24823. case kAudioUnitType_Generator:
  24824. result = "Generator";
  24825. break;
  24826. case kAudioUnitType_Panner:
  24827. result = "Panner";
  24828. break;
  24829. default:
  24830. break;
  24831. }
  24832. return result;
  24833. }
  24834. int AudioUnitPluginInstance::getNumParameters()
  24835. {
  24836. return parameterIds.size();
  24837. }
  24838. float AudioUnitPluginInstance::getParameter (int index)
  24839. {
  24840. const ScopedLock sl (lock);
  24841. Float32 value = 0.0f;
  24842. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  24843. {
  24844. AudioUnitGetParameter (audioUnit,
  24845. (UInt32) parameterIds.getUnchecked (index),
  24846. kAudioUnitScope_Global, 0,
  24847. &value);
  24848. }
  24849. return value;
  24850. }
  24851. void AudioUnitPluginInstance::setParameter (int index, float newValue)
  24852. {
  24853. const ScopedLock sl (lock);
  24854. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  24855. {
  24856. AudioUnitSetParameter (audioUnit,
  24857. (UInt32) parameterIds.getUnchecked (index),
  24858. kAudioUnitScope_Global, 0,
  24859. newValue, 0);
  24860. }
  24861. }
  24862. const String AudioUnitPluginInstance::getParameterName (int index)
  24863. {
  24864. AudioUnitParameterInfo info;
  24865. zerostruct (info);
  24866. UInt32 sz = sizeof (info);
  24867. String name;
  24868. if (AudioUnitGetProperty (audioUnit,
  24869. kAudioUnitProperty_ParameterInfo,
  24870. kAudioUnitScope_Global,
  24871. parameterIds [index], &info, &sz) == noErr)
  24872. {
  24873. if ((info.flags & kAudioUnitParameterFlag_HasCFNameString) != 0)
  24874. name = PlatformUtilities::cfStringToJuceString (info.cfNameString);
  24875. else
  24876. name = String (info.name, sizeof (info.name));
  24877. }
  24878. return name;
  24879. }
  24880. const String AudioUnitPluginInstance::getParameterText (int index)
  24881. {
  24882. return String (getParameter (index));
  24883. }
  24884. bool AudioUnitPluginInstance::isParameterAutomatable (int index) const
  24885. {
  24886. AudioUnitParameterInfo info;
  24887. UInt32 sz = sizeof (info);
  24888. if (AudioUnitGetProperty (audioUnit,
  24889. kAudioUnitProperty_ParameterInfo,
  24890. kAudioUnitScope_Global,
  24891. parameterIds [index], &info, &sz) == noErr)
  24892. {
  24893. return (info.flags & kAudioUnitParameterFlag_NonRealTime) == 0;
  24894. }
  24895. return true;
  24896. }
  24897. int AudioUnitPluginInstance::getNumPrograms()
  24898. {
  24899. CFArrayRef presets;
  24900. UInt32 sz = sizeof (CFArrayRef);
  24901. int num = 0;
  24902. if (AudioUnitGetProperty (audioUnit,
  24903. kAudioUnitProperty_FactoryPresets,
  24904. kAudioUnitScope_Global,
  24905. 0, &presets, &sz) == noErr)
  24906. {
  24907. num = (int) CFArrayGetCount (presets);
  24908. CFRelease (presets);
  24909. }
  24910. return num;
  24911. }
  24912. int AudioUnitPluginInstance::getCurrentProgram()
  24913. {
  24914. AUPreset current;
  24915. current.presetNumber = 0;
  24916. UInt32 sz = sizeof (AUPreset);
  24917. AudioUnitGetProperty (audioUnit,
  24918. kAudioUnitProperty_FactoryPresets,
  24919. kAudioUnitScope_Global,
  24920. 0, &current, &sz);
  24921. return current.presetNumber;
  24922. }
  24923. void AudioUnitPluginInstance::setCurrentProgram (int newIndex)
  24924. {
  24925. AUPreset current;
  24926. current.presetNumber = newIndex;
  24927. current.presetName = 0;
  24928. AudioUnitSetProperty (audioUnit,
  24929. kAudioUnitProperty_FactoryPresets,
  24930. kAudioUnitScope_Global,
  24931. 0, &current, sizeof (AUPreset));
  24932. }
  24933. const String AudioUnitPluginInstance::getProgramName (int index)
  24934. {
  24935. String s;
  24936. CFArrayRef presets;
  24937. UInt32 sz = sizeof (CFArrayRef);
  24938. if (AudioUnitGetProperty (audioUnit,
  24939. kAudioUnitProperty_FactoryPresets,
  24940. kAudioUnitScope_Global,
  24941. 0, &presets, &sz) == noErr)
  24942. {
  24943. for (CFIndex i = 0; i < CFArrayGetCount (presets); ++i)
  24944. {
  24945. const AUPreset* p = (const AUPreset*) CFArrayGetValueAtIndex (presets, i);
  24946. if (p != 0 && p->presetNumber == index)
  24947. {
  24948. s = PlatformUtilities::cfStringToJuceString (p->presetName);
  24949. break;
  24950. }
  24951. }
  24952. CFRelease (presets);
  24953. }
  24954. return s;
  24955. }
  24956. void AudioUnitPluginInstance::changeProgramName (int index, const String& newName)
  24957. {
  24958. jassertfalse // xxx not implemented!
  24959. }
  24960. const String AudioUnitPluginInstance::getInputChannelName (const int index) const
  24961. {
  24962. if (((unsigned int) index) < (unsigned int) getNumInputChannels())
  24963. return "Input " + String (index + 1);
  24964. return String::empty;
  24965. }
  24966. bool AudioUnitPluginInstance::isInputChannelStereoPair (int index) const
  24967. {
  24968. if (((unsigned int) index) >= (unsigned int) getNumInputChannels())
  24969. return false;
  24970. return true;
  24971. }
  24972. const String AudioUnitPluginInstance::getOutputChannelName (const int index) const
  24973. {
  24974. if (((unsigned int) index) < (unsigned int) getNumOutputChannels())
  24975. return "Output " + String (index + 1);
  24976. return String::empty;
  24977. }
  24978. bool AudioUnitPluginInstance::isOutputChannelStereoPair (int index) const
  24979. {
  24980. if (((unsigned int) index) >= (unsigned int) getNumOutputChannels())
  24981. return false;
  24982. return true;
  24983. }
  24984. void AudioUnitPluginInstance::getStateInformation (MemoryBlock& destData)
  24985. {
  24986. getCurrentProgramStateInformation (destData);
  24987. }
  24988. void AudioUnitPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  24989. {
  24990. CFPropertyListRef propertyList = 0;
  24991. UInt32 sz = sizeof (CFPropertyListRef);
  24992. if (AudioUnitGetProperty (audioUnit,
  24993. kAudioUnitProperty_ClassInfo,
  24994. kAudioUnitScope_Global,
  24995. 0, &propertyList, &sz) == noErr)
  24996. {
  24997. CFWriteStreamRef stream = CFWriteStreamCreateWithAllocatedBuffers (kCFAllocatorDefault, kCFAllocatorDefault);
  24998. CFWriteStreamOpen (stream);
  24999. CFIndex bytesWritten = CFPropertyListWriteToStream (propertyList, stream, kCFPropertyListBinaryFormat_v1_0, 0);
  25000. CFWriteStreamClose (stream);
  25001. CFDataRef data = (CFDataRef) CFWriteStreamCopyProperty (stream, kCFStreamPropertyDataWritten);
  25002. destData.setSize (bytesWritten);
  25003. destData.copyFrom (CFDataGetBytePtr (data), 0, destData.getSize());
  25004. CFRelease (data);
  25005. CFRelease (stream);
  25006. CFRelease (propertyList);
  25007. }
  25008. }
  25009. void AudioUnitPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  25010. {
  25011. setCurrentProgramStateInformation (data, sizeInBytes);
  25012. }
  25013. void AudioUnitPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  25014. {
  25015. CFReadStreamRef stream = CFReadStreamCreateWithBytesNoCopy (kCFAllocatorDefault,
  25016. (const UInt8*) data,
  25017. sizeInBytes,
  25018. kCFAllocatorNull);
  25019. CFReadStreamOpen (stream);
  25020. CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0;
  25021. CFPropertyListRef propertyList = CFPropertyListCreateFromStream (kCFAllocatorDefault,
  25022. stream,
  25023. 0,
  25024. kCFPropertyListImmutable,
  25025. &format,
  25026. 0);
  25027. CFRelease (stream);
  25028. if (propertyList != 0)
  25029. AudioUnitSetProperty (audioUnit,
  25030. kAudioUnitProperty_ClassInfo,
  25031. kAudioUnitScope_Global,
  25032. 0, &propertyList, sizeof (propertyList));
  25033. }
  25034. AudioUnitPluginFormat::AudioUnitPluginFormat()
  25035. {
  25036. }
  25037. AudioUnitPluginFormat::~AudioUnitPluginFormat()
  25038. {
  25039. }
  25040. void AudioUnitPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  25041. const String& fileOrIdentifier)
  25042. {
  25043. if (! fileMightContainThisPluginType (fileOrIdentifier))
  25044. return;
  25045. PluginDescription desc;
  25046. desc.fileOrIdentifier = fileOrIdentifier;
  25047. desc.uid = 0;
  25048. try
  25049. {
  25050. ScopedPointer <AudioPluginInstance> createdInstance (createInstanceFromDescription (desc));
  25051. AudioUnitPluginInstance* const auInstance = dynamic_cast <AudioUnitPluginInstance*> ((AudioPluginInstance*) createdInstance);
  25052. if (auInstance != 0)
  25053. {
  25054. auInstance->fillInPluginDescription (desc);
  25055. results.add (new PluginDescription (desc));
  25056. }
  25057. }
  25058. catch (...)
  25059. {
  25060. // crashed while loading...
  25061. }
  25062. }
  25063. AudioPluginInstance* AudioUnitPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  25064. {
  25065. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  25066. {
  25067. ScopedPointer <AudioUnitPluginInstance> result (new AudioUnitPluginInstance (desc.fileOrIdentifier));
  25068. if (result->audioUnit != 0)
  25069. {
  25070. result->initialise();
  25071. return result.release();
  25072. }
  25073. }
  25074. return 0;
  25075. }
  25076. const StringArray AudioUnitPluginFormat::searchPathsForPlugins (const FileSearchPath& /*directoriesToSearch*/,
  25077. const bool /*recursive*/)
  25078. {
  25079. StringArray result;
  25080. ComponentRecord* comp = 0;
  25081. ComponentDescription desc;
  25082. zerostruct (desc);
  25083. for (;;)
  25084. {
  25085. zerostruct (desc);
  25086. comp = FindNextComponent (comp, &desc);
  25087. if (comp == 0)
  25088. break;
  25089. GetComponentInfo (comp, &desc, 0, 0, 0);
  25090. if (desc.componentType == kAudioUnitType_MusicDevice
  25091. || desc.componentType == kAudioUnitType_MusicEffect
  25092. || desc.componentType == kAudioUnitType_Effect
  25093. || desc.componentType == kAudioUnitType_Generator
  25094. || desc.componentType == kAudioUnitType_Panner)
  25095. {
  25096. const String s (createAUPluginIdentifier (desc));
  25097. DBG (s);
  25098. result.add (s);
  25099. }
  25100. }
  25101. return result;
  25102. }
  25103. bool AudioUnitPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  25104. {
  25105. ComponentDescription desc;
  25106. String name, version, manufacturer;
  25107. if (getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer))
  25108. return FindNextComponent (0, &desc) != 0;
  25109. const File f (fileOrIdentifier);
  25110. return f.hasFileExtension (".component")
  25111. && f.isDirectory();
  25112. }
  25113. const String AudioUnitPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  25114. {
  25115. ComponentDescription desc;
  25116. String name, version, manufacturer;
  25117. getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer);
  25118. if (name.isEmpty())
  25119. name = fileOrIdentifier;
  25120. return name;
  25121. }
  25122. bool AudioUnitPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  25123. {
  25124. if (desc.fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  25125. return fileMightContainThisPluginType (desc.fileOrIdentifier);
  25126. else
  25127. return File (desc.fileOrIdentifier).exists();
  25128. }
  25129. const FileSearchPath AudioUnitPluginFormat::getDefaultLocationsToSearch()
  25130. {
  25131. return FileSearchPath ("/(Default AudioUnit locations)");
  25132. }
  25133. #endif
  25134. END_JUCE_NAMESPACE
  25135. #undef log
  25136. #endif
  25137. /*** End of inlined file: juce_AudioUnitPluginFormat.mm ***/
  25138. /*** Start of inlined file: juce_VSTPluginFormat.mm ***/
  25139. // This file just wraps juce_VSTPluginFormat.cpp in an objective-C wrapper
  25140. #define JUCE_MAC_VST_INCLUDED 1
  25141. /*** Start of inlined file: juce_VSTPluginFormat.cpp ***/
  25142. #if JUCE_PLUGINHOST_VST
  25143. #if (defined (_WIN32) || defined (_WIN64))
  25144. #undef _WIN32_WINNT
  25145. #define _WIN32_WINNT 0x500
  25146. #undef STRICT
  25147. #define STRICT
  25148. #include <windows.h>
  25149. #include <float.h>
  25150. #pragma warning (disable : 4312 4355)
  25151. #elif defined (LINUX) || defined (__linux__)
  25152. #include <float.h>
  25153. #include <sys/time.h>
  25154. #include <X11/Xlib.h>
  25155. #include <X11/Xutil.h>
  25156. #include <X11/Xatom.h>
  25157. #undef Font
  25158. #undef KeyPress
  25159. #undef Drawable
  25160. #undef Time
  25161. #else
  25162. #ifndef JUCE_MAC_VST_INCLUDED
  25163. // On the mac, this file needs to be compiled indirectly, by using
  25164. // juce_VSTPluginFormat.mm instead - that wraps it as an objective-C file for cocoa
  25165. #error
  25166. #endif
  25167. #include <Cocoa/Cocoa.h>
  25168. #include <Carbon/Carbon.h>
  25169. #endif
  25170. #if ! (JUCE_MAC && JUCE_64BIT)
  25171. BEGIN_JUCE_NAMESPACE
  25172. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  25173. #endif
  25174. #undef PRAGMA_ALIGN_SUPPORTED
  25175. #define VST_FORCE_DEPRECATED 0
  25176. #ifdef _MSC_VER
  25177. #pragma warning (push)
  25178. #pragma warning (disable: 4996)
  25179. #endif
  25180. #include "pluginterfaces/vst2.x/aeffectx.h"
  25181. #ifdef _MSC_VER
  25182. #pragma warning (pop)
  25183. #endif
  25184. #if JUCE_LINUX
  25185. #define Font JUCE_NAMESPACE::Font
  25186. #define KeyPress JUCE_NAMESPACE::KeyPress
  25187. #define Drawable JUCE_NAMESPACE::Drawable
  25188. #define Time JUCE_NAMESPACE::Time
  25189. #endif
  25190. /*** Start of inlined file: juce_VSTMidiEventList.h ***/
  25191. #ifdef __aeffect__
  25192. #ifndef __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25193. #define __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25194. class VSTMidiEventList
  25195. {
  25196. public:
  25197. VSTMidiEventList()
  25198. : numEventsUsed (0), numEventsAllocated (0)
  25199. {
  25200. }
  25201. ~VSTMidiEventList()
  25202. {
  25203. freeEvents();
  25204. }
  25205. void clear()
  25206. {
  25207. numEventsUsed = 0;
  25208. if (events != 0)
  25209. events->numEvents = 0;
  25210. }
  25211. void addEvent (const void* const midiData, const int numBytes, const int frameOffset)
  25212. {
  25213. ensureSize (numEventsUsed + 1);
  25214. VstMidiEvent* const e = (VstMidiEvent*) (events->events [numEventsUsed]);
  25215. events->numEvents = ++numEventsUsed;
  25216. if (numBytes <= 4)
  25217. {
  25218. if (e->type == kVstSysExType)
  25219. {
  25220. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25221. e->type = kVstMidiType;
  25222. e->byteSize = sizeof (VstMidiEvent);
  25223. e->noteLength = 0;
  25224. e->noteOffset = 0;
  25225. e->detune = 0;
  25226. e->noteOffVelocity = 0;
  25227. }
  25228. e->deltaFrames = frameOffset;
  25229. memcpy (e->midiData, midiData, numBytes);
  25230. }
  25231. else
  25232. {
  25233. VstMidiSysexEvent* const se = (VstMidiSysexEvent*) e;
  25234. if (se->type == kVstSysExType)
  25235. se->sysexDump = (char*) juce_realloc (se->sysexDump, numBytes);
  25236. else
  25237. se->sysexDump = (char*) juce_malloc (numBytes);
  25238. memcpy (se->sysexDump, midiData, numBytes);
  25239. se->type = kVstSysExType;
  25240. se->byteSize = sizeof (VstMidiSysexEvent);
  25241. se->deltaFrames = frameOffset;
  25242. se->flags = 0;
  25243. se->dumpBytes = numBytes;
  25244. se->resvd1 = 0;
  25245. se->resvd2 = 0;
  25246. }
  25247. }
  25248. // Handy method to pull the events out of an event buffer supplied by the host
  25249. // or plugin.
  25250. static void addEventsToMidiBuffer (const VstEvents* events, MidiBuffer& dest)
  25251. {
  25252. for (int i = 0; i < events->numEvents; ++i)
  25253. {
  25254. const VstEvent* const e = events->events[i];
  25255. if (e != 0)
  25256. {
  25257. if (e->type == kVstMidiType)
  25258. {
  25259. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiEvent*) e)->midiData,
  25260. 4, e->deltaFrames);
  25261. }
  25262. else if (e->type == kVstSysExType)
  25263. {
  25264. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiSysexEvent*) e)->sysexDump,
  25265. (int) ((const VstMidiSysexEvent*) e)->dumpBytes,
  25266. e->deltaFrames);
  25267. }
  25268. }
  25269. }
  25270. }
  25271. void ensureSize (int numEventsNeeded)
  25272. {
  25273. if (numEventsNeeded > numEventsAllocated)
  25274. {
  25275. numEventsNeeded = (numEventsNeeded + 32) & ~31;
  25276. const int size = 20 + sizeof (VstEvent*) * numEventsNeeded;
  25277. if (events == 0)
  25278. events.calloc (size, 1);
  25279. else
  25280. events.realloc (size, 1);
  25281. for (int i = numEventsAllocated; i < numEventsNeeded; ++i)
  25282. {
  25283. VstMidiEvent* const e = (VstMidiEvent*) juce_calloc (jmax ((int) sizeof (VstMidiEvent),
  25284. (int) sizeof (VstMidiSysexEvent)));
  25285. e->type = kVstMidiType;
  25286. e->byteSize = sizeof (VstMidiEvent);
  25287. events->events[i] = (VstEvent*) e;
  25288. }
  25289. numEventsAllocated = numEventsNeeded;
  25290. }
  25291. }
  25292. void freeEvents()
  25293. {
  25294. if (events != 0)
  25295. {
  25296. for (int i = numEventsAllocated; --i >= 0;)
  25297. {
  25298. VstMidiEvent* const e = (VstMidiEvent*) (events->events[i]);
  25299. if (e->type == kVstSysExType)
  25300. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25301. juce_free (e);
  25302. }
  25303. events.free();
  25304. numEventsUsed = 0;
  25305. numEventsAllocated = 0;
  25306. }
  25307. }
  25308. HeapBlock <VstEvents> events;
  25309. private:
  25310. int numEventsUsed, numEventsAllocated;
  25311. };
  25312. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25313. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25314. /*** End of inlined file: juce_VSTMidiEventList.h ***/
  25315. #if ! JUCE_WIN32
  25316. static void _fpreset() {}
  25317. static void _clearfp() {}
  25318. #endif
  25319. extern void juce_callAnyTimersSynchronously();
  25320. const int fxbVersionNum = 1;
  25321. struct fxProgram
  25322. {
  25323. long chunkMagic; // 'CcnK'
  25324. long byteSize; // of this chunk, excl. magic + byteSize
  25325. long fxMagic; // 'FxCk'
  25326. long version;
  25327. long fxID; // fx unique id
  25328. long fxVersion;
  25329. long numParams;
  25330. char prgName[28];
  25331. float params[1]; // variable no. of parameters
  25332. };
  25333. struct fxSet
  25334. {
  25335. long chunkMagic; // 'CcnK'
  25336. long byteSize; // of this chunk, excl. magic + byteSize
  25337. long fxMagic; // 'FxBk'
  25338. long version;
  25339. long fxID; // fx unique id
  25340. long fxVersion;
  25341. long numPrograms;
  25342. char future[128];
  25343. fxProgram programs[1]; // variable no. of programs
  25344. };
  25345. struct fxChunkSet
  25346. {
  25347. long chunkMagic; // 'CcnK'
  25348. long byteSize; // of this chunk, excl. magic + byteSize
  25349. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25350. long version;
  25351. long fxID; // fx unique id
  25352. long fxVersion;
  25353. long numPrograms;
  25354. char future[128];
  25355. long chunkSize;
  25356. char chunk[8]; // variable
  25357. };
  25358. struct fxProgramSet
  25359. {
  25360. long chunkMagic; // 'CcnK'
  25361. long byteSize; // of this chunk, excl. magic + byteSize
  25362. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25363. long version;
  25364. long fxID; // fx unique id
  25365. long fxVersion;
  25366. long numPrograms;
  25367. char name[28];
  25368. long chunkSize;
  25369. char chunk[8]; // variable
  25370. };
  25371. static long vst_swap (const long x) throw()
  25372. {
  25373. #ifdef JUCE_LITTLE_ENDIAN
  25374. return (long) ByteOrder::swap ((uint32) x);
  25375. #else
  25376. return x;
  25377. #endif
  25378. }
  25379. static float vst_swapFloat (const float x) throw()
  25380. {
  25381. #ifdef JUCE_LITTLE_ENDIAN
  25382. union { uint32 asInt; float asFloat; } n;
  25383. n.asFloat = x;
  25384. n.asInt = ByteOrder::swap (n.asInt);
  25385. return n.asFloat;
  25386. #else
  25387. return x;
  25388. #endif
  25389. }
  25390. typedef AEffect* (*MainCall) (audioMasterCallback);
  25391. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt);
  25392. static int shellUIDToCreate = 0;
  25393. static int insideVSTCallback = 0;
  25394. class VSTPluginWindow;
  25395. // Change this to disable logging of various VST activities
  25396. #ifndef VST_LOGGING
  25397. #define VST_LOGGING 1
  25398. #endif
  25399. #if VST_LOGGING
  25400. #define log(a) Logger::writeToLog(a);
  25401. #else
  25402. #define log(a)
  25403. #endif
  25404. #if JUCE_MAC && JUCE_PPC
  25405. static void* NewCFMFromMachO (void* const machofp) throw()
  25406. {
  25407. void* result = juce_malloc (8);
  25408. ((void**) result)[0] = machofp;
  25409. ((void**) result)[1] = result;
  25410. return result;
  25411. }
  25412. #endif
  25413. #if JUCE_LINUX
  25414. extern Display* display;
  25415. extern XContext improbableNumber;
  25416. typedef void (*EventProcPtr) (XEvent* ev);
  25417. static bool xErrorTriggered;
  25418. static int temporaryErrorHandler (Display*, XErrorEvent*)
  25419. {
  25420. xErrorTriggered = true;
  25421. return 0;
  25422. }
  25423. static int getPropertyFromXWindow (Window handle, Atom atom)
  25424. {
  25425. XErrorHandler oldErrorHandler = XSetErrorHandler (temporaryErrorHandler);
  25426. xErrorTriggered = false;
  25427. int userSize;
  25428. unsigned long bytes, userCount;
  25429. unsigned char* data;
  25430. Atom userType;
  25431. XGetWindowProperty (display, handle, atom, 0, 1, false, AnyPropertyType,
  25432. &userType, &userSize, &userCount, &bytes, &data);
  25433. XSetErrorHandler (oldErrorHandler);
  25434. return (userCount == 1 && ! xErrorTriggered) ? *(int*) data
  25435. : 0;
  25436. }
  25437. static Window getChildWindow (Window windowToCheck)
  25438. {
  25439. Window rootWindow, parentWindow;
  25440. Window* childWindows;
  25441. unsigned int numChildren;
  25442. XQueryTree (display,
  25443. windowToCheck,
  25444. &rootWindow,
  25445. &parentWindow,
  25446. &childWindows,
  25447. &numChildren);
  25448. if (numChildren > 0)
  25449. return childWindows [0];
  25450. return 0;
  25451. }
  25452. static void translateJuceToXButtonModifiers (const MouseEvent& e, XEvent& ev) throw()
  25453. {
  25454. if (e.mods.isLeftButtonDown())
  25455. {
  25456. ev.xbutton.button = Button1;
  25457. ev.xbutton.state |= Button1Mask;
  25458. }
  25459. else if (e.mods.isRightButtonDown())
  25460. {
  25461. ev.xbutton.button = Button3;
  25462. ev.xbutton.state |= Button3Mask;
  25463. }
  25464. else if (e.mods.isMiddleButtonDown())
  25465. {
  25466. ev.xbutton.button = Button2;
  25467. ev.xbutton.state |= Button2Mask;
  25468. }
  25469. }
  25470. static void translateJuceToXMotionModifiers (const MouseEvent& e, XEvent& ev) throw()
  25471. {
  25472. if (e.mods.isLeftButtonDown())
  25473. ev.xmotion.state |= Button1Mask;
  25474. else if (e.mods.isRightButtonDown())
  25475. ev.xmotion.state |= Button3Mask;
  25476. else if (e.mods.isMiddleButtonDown())
  25477. ev.xmotion.state |= Button2Mask;
  25478. }
  25479. static void translateJuceToXCrossingModifiers (const MouseEvent& e, XEvent& ev) throw()
  25480. {
  25481. if (e.mods.isLeftButtonDown())
  25482. ev.xcrossing.state |= Button1Mask;
  25483. else if (e.mods.isRightButtonDown())
  25484. ev.xcrossing.state |= Button3Mask;
  25485. else if (e.mods.isMiddleButtonDown())
  25486. ev.xcrossing.state |= Button2Mask;
  25487. }
  25488. static void translateJuceToXMouseWheelModifiers (const MouseEvent& e, const float increment, XEvent& ev) throw()
  25489. {
  25490. if (increment < 0)
  25491. {
  25492. ev.xbutton.button = Button5;
  25493. ev.xbutton.state |= Button5Mask;
  25494. }
  25495. else if (increment > 0)
  25496. {
  25497. ev.xbutton.button = Button4;
  25498. ev.xbutton.state |= Button4Mask;
  25499. }
  25500. }
  25501. #endif
  25502. static VoidArray activeModules;
  25503. class ModuleHandle : public ReferenceCountedObject
  25504. {
  25505. public:
  25506. File file;
  25507. MainCall moduleMain;
  25508. String pluginName;
  25509. static ModuleHandle* findOrCreateModule (const File& file)
  25510. {
  25511. for (int i = activeModules.size(); --i >= 0;)
  25512. {
  25513. ModuleHandle* const module = (ModuleHandle*) activeModules.getUnchecked(i);
  25514. if (module->file == file)
  25515. return module;
  25516. }
  25517. _fpreset(); // (doesn't do any harm)
  25518. ++insideVSTCallback;
  25519. shellUIDToCreate = 0;
  25520. log ("Attempting to load VST: " + file.getFullPathName());
  25521. ScopedPointer <ModuleHandle> m (new ModuleHandle (file));
  25522. if (! m->open())
  25523. m = 0;
  25524. --insideVSTCallback;
  25525. _fpreset(); // (doesn't do any harm)
  25526. return m.release();
  25527. }
  25528. ModuleHandle (const File& file_)
  25529. : file (file_),
  25530. moduleMain (0),
  25531. #if JUCE_WIN32 || JUCE_LINUX
  25532. hModule (0)
  25533. #elif JUCE_MAC
  25534. fragId (0),
  25535. resHandle (0),
  25536. bundleRef (0),
  25537. resFileId (0)
  25538. #endif
  25539. {
  25540. activeModules.add (this);
  25541. #if JUCE_WIN32 || JUCE_LINUX
  25542. fullParentDirectoryPathName = file_.getParentDirectory().getFullPathName();
  25543. #elif JUCE_MAC
  25544. FSRef ref;
  25545. PlatformUtilities::makeFSRefFromPath (&ref, file_.getParentDirectory().getFullPathName());
  25546. FSGetCatalogInfo (&ref, kFSCatInfoNone, 0, 0, &parentDirFSSpec, 0);
  25547. #endif
  25548. }
  25549. ~ModuleHandle()
  25550. {
  25551. activeModules.removeValue (this);
  25552. close();
  25553. }
  25554. juce_UseDebuggingNewOperator
  25555. #if JUCE_WIN32 || JUCE_LINUX
  25556. void* hModule;
  25557. String fullParentDirectoryPathName;
  25558. bool open()
  25559. {
  25560. #if JUCE_WIN32
  25561. static bool timePeriodSet = false;
  25562. if (! timePeriodSet)
  25563. {
  25564. timePeriodSet = true;
  25565. timeBeginPeriod (2);
  25566. }
  25567. #endif
  25568. pluginName = file.getFileNameWithoutExtension();
  25569. hModule = PlatformUtilities::loadDynamicLibrary (file.getFullPathName());
  25570. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "VSTPluginMain");
  25571. if (moduleMain == 0)
  25572. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "main");
  25573. return moduleMain != 0;
  25574. }
  25575. void close()
  25576. {
  25577. _fpreset(); // (doesn't do any harm)
  25578. PlatformUtilities::freeDynamicLibrary (hModule);
  25579. }
  25580. void closeEffect (AEffect* eff)
  25581. {
  25582. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25583. }
  25584. #else
  25585. CFragConnectionID fragId;
  25586. Handle resHandle;
  25587. CFBundleRef bundleRef;
  25588. FSSpec parentDirFSSpec;
  25589. short resFileId;
  25590. bool open()
  25591. {
  25592. bool ok = false;
  25593. const String filename (file.getFullPathName());
  25594. if (file.hasFileExtension (".vst"))
  25595. {
  25596. const char* const utf8 = filename.toUTF8();
  25597. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  25598. strlen (utf8), file.isDirectory());
  25599. if (url != 0)
  25600. {
  25601. bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  25602. CFRelease (url);
  25603. if (bundleRef != 0)
  25604. {
  25605. if (CFBundleLoadExecutable (bundleRef))
  25606. {
  25607. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("main_macho"));
  25608. if (moduleMain == 0)
  25609. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("VSTPluginMain"));
  25610. if (moduleMain != 0)
  25611. {
  25612. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  25613. if (name != 0)
  25614. {
  25615. if (CFGetTypeID (name) == CFStringGetTypeID())
  25616. {
  25617. char buffer[1024];
  25618. if (CFStringGetCString ((CFStringRef) name, buffer, sizeof (buffer), CFStringGetSystemEncoding()))
  25619. pluginName = buffer;
  25620. }
  25621. }
  25622. if (pluginName.isEmpty())
  25623. pluginName = file.getFileNameWithoutExtension();
  25624. resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  25625. ok = true;
  25626. }
  25627. }
  25628. if (! ok)
  25629. {
  25630. CFBundleUnloadExecutable (bundleRef);
  25631. CFRelease (bundleRef);
  25632. bundleRef = 0;
  25633. }
  25634. }
  25635. }
  25636. }
  25637. #if JUCE_PPC
  25638. else
  25639. {
  25640. FSRef fn;
  25641. if (FSPathMakeRef ((UInt8*) filename.toUTF8(), &fn, 0) == noErr)
  25642. {
  25643. resFileId = FSOpenResFile (&fn, fsRdPerm);
  25644. if (resFileId != -1)
  25645. {
  25646. const int numEffs = Count1Resources ('aEff');
  25647. for (int i = 0; i < numEffs; ++i)
  25648. {
  25649. resHandle = Get1IndResource ('aEff', i + 1);
  25650. if (resHandle != 0)
  25651. {
  25652. OSType type;
  25653. Str255 name;
  25654. SInt16 id;
  25655. GetResInfo (resHandle, &id, &type, name);
  25656. pluginName = String ((const char*) name + 1, name[0]);
  25657. DetachResource (resHandle);
  25658. HLock (resHandle);
  25659. Ptr ptr;
  25660. Str255 errorText;
  25661. OSErr err = GetMemFragment (*resHandle, GetHandleSize (resHandle),
  25662. name, kPrivateCFragCopy,
  25663. &fragId, &ptr, errorText);
  25664. if (err == noErr)
  25665. {
  25666. moduleMain = (MainCall) newMachOFromCFM (ptr);
  25667. ok = true;
  25668. }
  25669. else
  25670. {
  25671. HUnlock (resHandle);
  25672. }
  25673. break;
  25674. }
  25675. }
  25676. if (! ok)
  25677. CloseResFile (resFileId);
  25678. }
  25679. }
  25680. }
  25681. #endif
  25682. return ok;
  25683. }
  25684. void close()
  25685. {
  25686. #if JUCE_PPC
  25687. if (fragId != 0)
  25688. {
  25689. if (moduleMain != 0)
  25690. disposeMachOFromCFM ((void*) moduleMain);
  25691. CloseConnection (&fragId);
  25692. HUnlock (resHandle);
  25693. if (resFileId != 0)
  25694. CloseResFile (resFileId);
  25695. }
  25696. else
  25697. #endif
  25698. if (bundleRef != 0)
  25699. {
  25700. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  25701. if (CFGetRetainCount (bundleRef) == 1)
  25702. CFBundleUnloadExecutable (bundleRef);
  25703. if (CFGetRetainCount (bundleRef) > 0)
  25704. CFRelease (bundleRef);
  25705. }
  25706. }
  25707. void closeEffect (AEffect* eff)
  25708. {
  25709. #if JUCE_PPC
  25710. if (fragId != 0)
  25711. {
  25712. VoidArray thingsToDelete;
  25713. thingsToDelete.add ((void*) eff->dispatcher);
  25714. thingsToDelete.add ((void*) eff->process);
  25715. thingsToDelete.add ((void*) eff->setParameter);
  25716. thingsToDelete.add ((void*) eff->getParameter);
  25717. thingsToDelete.add ((void*) eff->processReplacing);
  25718. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25719. for (int i = thingsToDelete.size(); --i >= 0;)
  25720. disposeMachOFromCFM (thingsToDelete[i]);
  25721. }
  25722. else
  25723. #endif
  25724. {
  25725. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25726. }
  25727. }
  25728. #if JUCE_PPC
  25729. static void* newMachOFromCFM (void* cfmfp)
  25730. {
  25731. if (cfmfp == 0)
  25732. return 0;
  25733. UInt32* const mfp = (UInt32*) juce_malloc (sizeof (UInt32) * 6);
  25734. mfp[0] = 0x3d800000 | ((UInt32) cfmfp >> 16);
  25735. mfp[1] = 0x618c0000 | ((UInt32) cfmfp & 0xffff);
  25736. mfp[2] = 0x800c0000;
  25737. mfp[3] = 0x804c0004;
  25738. mfp[4] = 0x7c0903a6;
  25739. mfp[5] = 0x4e800420;
  25740. MakeDataExecutable (mfp, sizeof (UInt32) * 6);
  25741. return mfp;
  25742. }
  25743. static void disposeMachOFromCFM (void* ptr)
  25744. {
  25745. juce_free (ptr);
  25746. }
  25747. void coerceAEffectFunctionCalls (AEffect* eff)
  25748. {
  25749. if (fragId != 0)
  25750. {
  25751. eff->dispatcher = (AEffectDispatcherProc) newMachOFromCFM ((void*) eff->dispatcher);
  25752. eff->process = (AEffectProcessProc) newMachOFromCFM ((void*) eff->process);
  25753. eff->setParameter = (AEffectSetParameterProc) newMachOFromCFM ((void*) eff->setParameter);
  25754. eff->getParameter = (AEffectGetParameterProc) newMachOFromCFM ((void*) eff->getParameter);
  25755. eff->processReplacing = (AEffectProcessProc) newMachOFromCFM ((void*) eff->processReplacing);
  25756. }
  25757. }
  25758. #endif
  25759. #endif
  25760. };
  25761. class VSTPluginInstance : public AudioPluginInstance,
  25762. private Timer,
  25763. private AsyncUpdater
  25764. {
  25765. public:
  25766. ~VSTPluginInstance();
  25767. // AudioPluginInstance methods:
  25768. void fillInPluginDescription (PluginDescription& desc) const
  25769. {
  25770. desc.name = name;
  25771. desc.fileOrIdentifier = module->file.getFullPathName();
  25772. desc.uid = getUID();
  25773. desc.lastFileModTime = module->file.getLastModificationTime();
  25774. desc.pluginFormatName = "VST";
  25775. desc.category = getCategory();
  25776. {
  25777. char buffer [kVstMaxVendorStrLen + 8];
  25778. zerostruct (buffer);
  25779. dispatch (effGetVendorString, 0, 0, buffer, 0);
  25780. desc.manufacturerName = buffer;
  25781. }
  25782. desc.version = getVersion();
  25783. desc.numInputChannels = getNumInputChannels();
  25784. desc.numOutputChannels = getNumOutputChannels();
  25785. desc.isInstrument = (effect != 0 && (effect->flags & effFlagsIsSynth) != 0);
  25786. }
  25787. const String getName() const { return name; }
  25788. int getUID() const throw();
  25789. bool acceptsMidi() const { return wantsMidiMessages; }
  25790. bool producesMidi() const { return dispatch (effCanDo, 0, 0, (void*) "sendVstMidiEvent", 0) > 0; }
  25791. // AudioProcessor methods:
  25792. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  25793. void releaseResources();
  25794. void processBlock (AudioSampleBuffer& buffer,
  25795. MidiBuffer& midiMessages);
  25796. AudioProcessorEditor* createEditor();
  25797. const String getInputChannelName (const int index) const;
  25798. bool isInputChannelStereoPair (int index) const;
  25799. const String getOutputChannelName (const int index) const;
  25800. bool isOutputChannelStereoPair (int index) const;
  25801. int getNumParameters() { return effect != 0 ? effect->numParams : 0; }
  25802. float getParameter (int index);
  25803. void setParameter (int index, float newValue);
  25804. const String getParameterName (int index);
  25805. const String getParameterText (int index);
  25806. bool isParameterAutomatable (int index) const;
  25807. int getNumPrograms() { return effect != 0 ? effect->numPrograms : 0; }
  25808. int getCurrentProgram() { return dispatch (effGetProgram, 0, 0, 0, 0); }
  25809. void setCurrentProgram (int index);
  25810. const String getProgramName (int index);
  25811. void changeProgramName (int index, const String& newName);
  25812. void getStateInformation (MemoryBlock& destData);
  25813. void getCurrentProgramStateInformation (MemoryBlock& destData);
  25814. void setStateInformation (const void* data, int sizeInBytes);
  25815. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  25816. void timerCallback();
  25817. void handleAsyncUpdate();
  25818. VstIntPtr handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt);
  25819. juce_UseDebuggingNewOperator
  25820. private:
  25821. friend class VSTPluginWindow;
  25822. friend class VSTPluginFormat;
  25823. AEffect* effect;
  25824. String name;
  25825. CriticalSection lock;
  25826. bool wantsMidiMessages, initialised, isPowerOn;
  25827. mutable StringArray programNames;
  25828. AudioSampleBuffer tempBuffer;
  25829. CriticalSection midiInLock;
  25830. MidiBuffer incomingMidi;
  25831. VSTMidiEventList midiEventsToSend;
  25832. VstTimeInfo vstHostTime;
  25833. HeapBlock <float*> channels;
  25834. ReferenceCountedObjectPtr <ModuleHandle> module;
  25835. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const;
  25836. bool restoreProgramSettings (const fxProgram* const prog);
  25837. const String getCurrentProgramName();
  25838. void setParamsInProgramBlock (fxProgram* const prog) throw();
  25839. void updateStoredProgramNames();
  25840. void initialise();
  25841. void handleMidiFromPlugin (const VstEvents* const events);
  25842. void createTempParameterStore (MemoryBlock& dest);
  25843. void restoreFromTempParameterStore (const MemoryBlock& mb);
  25844. const String getParameterLabel (int index) const;
  25845. bool usesChunks() const throw() { return effect != 0 && (effect->flags & effFlagsProgramChunks) != 0; }
  25846. void getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const;
  25847. void setChunkData (const char* data, int size, bool isPreset);
  25848. bool loadFromFXBFile (const void* data, int numBytes);
  25849. bool saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB);
  25850. int getVersionNumber() const throw() { return effect != 0 ? effect->version : 0; }
  25851. const String getVersion() const throw();
  25852. const String getCategory() const throw();
  25853. bool hasEditor() const throw() { return effect != 0 && (effect->flags & effFlagsHasEditor) != 0; }
  25854. void setPower (const bool on);
  25855. VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module);
  25856. };
  25857. VSTPluginInstance::VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module_)
  25858. : effect (0),
  25859. wantsMidiMessages (false),
  25860. initialised (false),
  25861. isPowerOn (false),
  25862. tempBuffer (1, 1),
  25863. module (module_)
  25864. {
  25865. try
  25866. {
  25867. _fpreset();
  25868. ++insideVSTCallback;
  25869. name = module->pluginName;
  25870. log ("Creating VST instance: " + name);
  25871. #if JUCE_MAC
  25872. if (module->resFileId != 0)
  25873. UseResFile (module->resFileId);
  25874. #if JUCE_PPC
  25875. if (module->fragId != 0)
  25876. {
  25877. static void* audioMasterCoerced = 0;
  25878. if (audioMasterCoerced == 0)
  25879. audioMasterCoerced = NewCFMFromMachO ((void*) &audioMaster);
  25880. effect = module->moduleMain ((audioMasterCallback) audioMasterCoerced);
  25881. }
  25882. else
  25883. #endif
  25884. #endif
  25885. {
  25886. effect = module->moduleMain (&audioMaster);
  25887. }
  25888. --insideVSTCallback;
  25889. if (effect != 0 && effect->magic == kEffectMagic)
  25890. {
  25891. #if JUCE_PPC
  25892. module->coerceAEffectFunctionCalls (effect);
  25893. #endif
  25894. jassert (effect->resvd2 == 0);
  25895. jassert (effect->object != 0);
  25896. _fpreset(); // some dodgy plugs fuck around with this
  25897. }
  25898. else
  25899. {
  25900. effect = 0;
  25901. }
  25902. }
  25903. catch (...)
  25904. {
  25905. --insideVSTCallback;
  25906. }
  25907. }
  25908. VSTPluginInstance::~VSTPluginInstance()
  25909. {
  25910. {
  25911. const ScopedLock sl (lock);
  25912. jassert (insideVSTCallback == 0);
  25913. if (effect != 0 && effect->magic == kEffectMagic)
  25914. {
  25915. try
  25916. {
  25917. #if JUCE_MAC
  25918. if (module->resFileId != 0)
  25919. UseResFile (module->resFileId);
  25920. #endif
  25921. // Must delete any editors before deleting the plugin instance!
  25922. jassert (getActiveEditor() == 0);
  25923. _fpreset(); // some dodgy plugs fuck around with this
  25924. module->closeEffect (effect);
  25925. }
  25926. catch (...)
  25927. {}
  25928. }
  25929. module = 0;
  25930. effect = 0;
  25931. }
  25932. }
  25933. void VSTPluginInstance::initialise()
  25934. {
  25935. if (initialised || effect == 0)
  25936. return;
  25937. log ("Initialising VST: " + module->pluginName);
  25938. initialised = true;
  25939. dispatch (effIdentify, 0, 0, 0, 0);
  25940. // this code would ask the plugin for its name, but so few plugins
  25941. // actually bother implementing this correctly, that it's better to
  25942. // just ignore it and use the file name instead.
  25943. if (getSampleRate() > 0)
  25944. dispatch (effSetSampleRate, 0, 0, 0, (float) getSampleRate());
  25945. if (getBlockSize() > 0)
  25946. dispatch (effSetBlockSize, 0, jmax (32, getBlockSize()), 0, 0);
  25947. dispatch (effOpen, 0, 0, 0, 0);
  25948. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  25949. getSampleRate(), getBlockSize());
  25950. if (getNumPrograms() > 1)
  25951. setCurrentProgram (0);
  25952. else
  25953. dispatch (effSetProgram, 0, 0, 0, 0);
  25954. int i;
  25955. for (i = effect->numInputs; --i >= 0;)
  25956. dispatch (effConnectInput, i, 1, 0, 0);
  25957. for (i = effect->numOutputs; --i >= 0;)
  25958. dispatch (effConnectOutput, i, 1, 0, 0);
  25959. updateStoredProgramNames();
  25960. wantsMidiMessages = dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0;
  25961. setLatencySamples (effect->initialDelay);
  25962. }
  25963. void VSTPluginInstance::prepareToPlay (double sampleRate_,
  25964. int samplesPerBlockExpected)
  25965. {
  25966. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  25967. sampleRate_, samplesPerBlockExpected);
  25968. setLatencySamples (effect->initialDelay);
  25969. channels.calloc (jmax (16, getNumOutputChannels(), getNumInputChannels()) + 2);
  25970. vstHostTime.tempo = 120.0;
  25971. vstHostTime.timeSigNumerator = 4;
  25972. vstHostTime.timeSigDenominator = 4;
  25973. vstHostTime.sampleRate = sampleRate_;
  25974. vstHostTime.samplePos = 0;
  25975. vstHostTime.flags = kVstNanosValid; /*| kVstTransportPlaying | kVstTempoValid | kVstTimeSigValid*/;
  25976. initialise();
  25977. if (initialised)
  25978. {
  25979. wantsMidiMessages = wantsMidiMessages
  25980. || (dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0);
  25981. if (wantsMidiMessages)
  25982. midiEventsToSend.ensureSize (256);
  25983. else
  25984. midiEventsToSend.freeEvents();
  25985. incomingMidi.clear();
  25986. dispatch (effSetSampleRate, 0, 0, 0, (float) sampleRate_);
  25987. dispatch (effSetBlockSize, 0, jmax (16, samplesPerBlockExpected), 0, 0);
  25988. tempBuffer.setSize (jmax (1, effect->numOutputs), samplesPerBlockExpected);
  25989. if (! isPowerOn)
  25990. setPower (true);
  25991. // dodgy hack to force some plugins to initialise the sample rate..
  25992. if ((! hasEditor()) && getNumParameters() > 0)
  25993. {
  25994. const float old = getParameter (0);
  25995. setParameter (0, (old < 0.5f) ? 1.0f : 0.0f);
  25996. setParameter (0, old);
  25997. }
  25998. dispatch (effStartProcess, 0, 0, 0, 0);
  25999. }
  26000. }
  26001. void VSTPluginInstance::releaseResources()
  26002. {
  26003. if (initialised)
  26004. {
  26005. dispatch (effStopProcess, 0, 0, 0, 0);
  26006. setPower (false);
  26007. }
  26008. tempBuffer.setSize (1, 1);
  26009. incomingMidi.clear();
  26010. midiEventsToSend.freeEvents();
  26011. channels.free();
  26012. }
  26013. void VSTPluginInstance::processBlock (AudioSampleBuffer& buffer,
  26014. MidiBuffer& midiMessages)
  26015. {
  26016. const int numSamples = buffer.getNumSamples();
  26017. if (initialised)
  26018. {
  26019. AudioPlayHead* playHead = getPlayHead();
  26020. if (playHead != 0)
  26021. {
  26022. AudioPlayHead::CurrentPositionInfo position;
  26023. playHead->getCurrentPosition (position);
  26024. vstHostTime.tempo = position.bpm;
  26025. vstHostTime.timeSigNumerator = position.timeSigNumerator;
  26026. vstHostTime.timeSigDenominator = position.timeSigDenominator;
  26027. vstHostTime.ppqPos = position.ppqPosition;
  26028. vstHostTime.barStartPos = position.ppqPositionOfLastBarStart;
  26029. vstHostTime.flags |= kVstTempoValid | kVstTimeSigValid | kVstPpqPosValid | kVstBarsValid;
  26030. if (position.isPlaying)
  26031. vstHostTime.flags |= kVstTransportPlaying;
  26032. else
  26033. vstHostTime.flags &= ~kVstTransportPlaying;
  26034. }
  26035. #if JUCE_WIN32
  26036. vstHostTime.nanoSeconds = timeGetTime() * 1000000.0;
  26037. #elif JUCE_LINUX
  26038. timeval micro;
  26039. gettimeofday (&micro, 0);
  26040. vstHostTime.nanoSeconds = micro.tv_usec * 1000.0;
  26041. #elif JUCE_MAC
  26042. UnsignedWide micro;
  26043. Microseconds (&micro);
  26044. vstHostTime.nanoSeconds = micro.lo * 1000.0;
  26045. #endif
  26046. if (wantsMidiMessages)
  26047. {
  26048. midiEventsToSend.clear();
  26049. midiEventsToSend.ensureSize (1);
  26050. MidiBuffer::Iterator iter (midiMessages);
  26051. const uint8* midiData;
  26052. int numBytesOfMidiData, samplePosition;
  26053. while (iter.getNextEvent (midiData, numBytesOfMidiData, samplePosition))
  26054. {
  26055. midiEventsToSend.addEvent (midiData, numBytesOfMidiData,
  26056. jlimit (0, numSamples - 1, samplePosition));
  26057. }
  26058. try
  26059. {
  26060. effect->dispatcher (effect, effProcessEvents, 0, 0, midiEventsToSend.events, 0);
  26061. }
  26062. catch (...)
  26063. {}
  26064. }
  26065. int i;
  26066. const int maxChans = jmax (effect->numInputs, effect->numOutputs);
  26067. for (i = 0; i < maxChans; ++i)
  26068. channels[i] = buffer.getSampleData (i);
  26069. channels [maxChans] = 0;
  26070. _clearfp();
  26071. if ((effect->flags & effFlagsCanReplacing) != 0)
  26072. {
  26073. try
  26074. {
  26075. effect->processReplacing (effect, channels, channels, numSamples);
  26076. }
  26077. catch (...)
  26078. {}
  26079. }
  26080. else
  26081. {
  26082. tempBuffer.setSize (effect->numOutputs, numSamples);
  26083. tempBuffer.clear();
  26084. float* outs [64];
  26085. for (i = effect->numOutputs; --i >= 0;)
  26086. outs[i] = tempBuffer.getSampleData (i);
  26087. outs [effect->numOutputs] = 0;
  26088. try
  26089. {
  26090. effect->process (effect, channels, outs, numSamples);
  26091. }
  26092. catch (...)
  26093. {}
  26094. for (i = effect->numOutputs; --i >= 0;)
  26095. buffer.copyFrom (i, 0, outs[i], numSamples);
  26096. }
  26097. }
  26098. else
  26099. {
  26100. // Not initialised, so just bypass..
  26101. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  26102. buffer.clear (i, 0, buffer.getNumSamples());
  26103. }
  26104. {
  26105. // copy any incoming midi..
  26106. const ScopedLock sl (midiInLock);
  26107. midiMessages = incomingMidi;
  26108. incomingMidi.clear();
  26109. }
  26110. }
  26111. void VSTPluginInstance::handleMidiFromPlugin (const VstEvents* const events)
  26112. {
  26113. if (events != 0)
  26114. {
  26115. const ScopedLock sl (midiInLock);
  26116. VSTMidiEventList::addEventsToMidiBuffer (events, incomingMidi);
  26117. }
  26118. }
  26119. static Array <VSTPluginWindow*> activeVSTWindows;
  26120. class VSTPluginWindow : public AudioProcessorEditor,
  26121. #if ! JUCE_MAC
  26122. public ComponentMovementWatcher,
  26123. #endif
  26124. public Timer
  26125. {
  26126. public:
  26127. VSTPluginWindow (VSTPluginInstance& plugin_)
  26128. : AudioProcessorEditor (&plugin_),
  26129. #if ! JUCE_MAC
  26130. ComponentMovementWatcher (this),
  26131. #endif
  26132. plugin (plugin_),
  26133. isOpen (false),
  26134. wasShowing (false),
  26135. pluginRefusesToResize (false),
  26136. pluginWantsKeys (false),
  26137. alreadyInside (false),
  26138. recursiveResize (false)
  26139. {
  26140. #if JUCE_WIN32
  26141. sizeCheckCount = 0;
  26142. pluginHWND = 0;
  26143. #elif JUCE_LINUX
  26144. pluginWindow = None;
  26145. pluginProc = None;
  26146. #else
  26147. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  26148. #endif
  26149. activeVSTWindows.add (this);
  26150. setSize (1, 1);
  26151. setOpaque (true);
  26152. setVisible (true);
  26153. }
  26154. ~VSTPluginWindow()
  26155. {
  26156. #if JUCE_MAC
  26157. innerWrapper = 0;
  26158. #else
  26159. closePluginWindow();
  26160. #endif
  26161. activeVSTWindows.removeValue (this);
  26162. plugin.editorBeingDeleted (this);
  26163. }
  26164. #if ! JUCE_MAC
  26165. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  26166. {
  26167. if (recursiveResize)
  26168. return;
  26169. Component* const topComp = getTopLevelComponent();
  26170. if (topComp->getPeer() != 0)
  26171. {
  26172. const Point<int> pos (relativePositionToOtherComponent (topComp, Point<int>()));
  26173. recursiveResize = true;
  26174. #if JUCE_WIN32
  26175. if (pluginHWND != 0)
  26176. MoveWindow (pluginHWND, pos.getX(), pos.getY(), getWidth(), getHeight(), TRUE);
  26177. #elif JUCE_LINUX
  26178. if (pluginWindow != 0)
  26179. {
  26180. XResizeWindow (display, pluginWindow, getWidth(), getHeight());
  26181. XMoveWindow (display, pluginWindow, pos.getX(), pos.getY());
  26182. XMapRaised (display, pluginWindow);
  26183. }
  26184. #endif
  26185. recursiveResize = false;
  26186. }
  26187. }
  26188. void componentVisibilityChanged (Component&)
  26189. {
  26190. const bool isShowingNow = isShowing();
  26191. if (wasShowing != isShowingNow)
  26192. {
  26193. wasShowing = isShowingNow;
  26194. if (isShowingNow)
  26195. openPluginWindow();
  26196. else
  26197. closePluginWindow();
  26198. }
  26199. componentMovedOrResized (true, true);
  26200. }
  26201. void componentPeerChanged()
  26202. {
  26203. closePluginWindow();
  26204. openPluginWindow();
  26205. }
  26206. #endif
  26207. bool keyStateChanged (bool)
  26208. {
  26209. return pluginWantsKeys;
  26210. }
  26211. bool keyPressed (const KeyPress&)
  26212. {
  26213. return pluginWantsKeys;
  26214. }
  26215. #if JUCE_MAC
  26216. void paint (Graphics& g)
  26217. {
  26218. g.fillAll (Colours::black);
  26219. }
  26220. #else
  26221. void paint (Graphics& g)
  26222. {
  26223. if (isOpen)
  26224. {
  26225. ComponentPeer* const peer = getPeer();
  26226. if (peer != 0)
  26227. {
  26228. const Point<int> pos (getScreenPosition() - peer->getScreenPosition());
  26229. peer->addMaskedRegion (pos.getX(), pos.getY(), getWidth(), getHeight());
  26230. #if JUCE_LINUX
  26231. if (pluginWindow != 0)
  26232. {
  26233. const Rectangle<int> clip (g.getClipBounds());
  26234. XEvent ev;
  26235. zerostruct (ev);
  26236. ev.xexpose.type = Expose;
  26237. ev.xexpose.display = display;
  26238. ev.xexpose.window = pluginWindow;
  26239. ev.xexpose.x = clip.getX();
  26240. ev.xexpose.y = clip.getY();
  26241. ev.xexpose.width = clip.getWidth();
  26242. ev.xexpose.height = clip.getHeight();
  26243. sendEventToChild (&ev);
  26244. }
  26245. #endif
  26246. }
  26247. }
  26248. else
  26249. {
  26250. g.fillAll (Colours::black);
  26251. }
  26252. }
  26253. #endif
  26254. void timerCallback()
  26255. {
  26256. #if JUCE_WIN32
  26257. if (--sizeCheckCount <= 0)
  26258. {
  26259. sizeCheckCount = 10;
  26260. checkPluginWindowSize();
  26261. }
  26262. #endif
  26263. try
  26264. {
  26265. static bool reentrant = false;
  26266. if (! reentrant)
  26267. {
  26268. reentrant = true;
  26269. plugin.dispatch (effEditIdle, 0, 0, 0, 0);
  26270. reentrant = false;
  26271. }
  26272. }
  26273. catch (...)
  26274. {}
  26275. }
  26276. void mouseDown (const MouseEvent& e)
  26277. {
  26278. #if JUCE_LINUX
  26279. if (pluginWindow == 0)
  26280. return;
  26281. toFront (true);
  26282. XEvent ev;
  26283. zerostruct (ev);
  26284. ev.xbutton.display = display;
  26285. ev.xbutton.type = ButtonPress;
  26286. ev.xbutton.window = pluginWindow;
  26287. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26288. ev.xbutton.time = CurrentTime;
  26289. ev.xbutton.x = e.x;
  26290. ev.xbutton.y = e.y;
  26291. ev.xbutton.x_root = e.getScreenX();
  26292. ev.xbutton.y_root = e.getScreenY();
  26293. translateJuceToXButtonModifiers (e, ev);
  26294. sendEventToChild (&ev);
  26295. #elif JUCE_WIN32
  26296. (void) e;
  26297. toFront (true);
  26298. #endif
  26299. }
  26300. void broughtToFront()
  26301. {
  26302. activeVSTWindows.removeValue (this);
  26303. activeVSTWindows.add (this);
  26304. #if JUCE_MAC
  26305. dispatch (effEditTop, 0, 0, 0, 0);
  26306. #endif
  26307. }
  26308. juce_UseDebuggingNewOperator
  26309. private:
  26310. VSTPluginInstance& plugin;
  26311. bool isOpen, wasShowing, recursiveResize;
  26312. bool pluginWantsKeys, pluginRefusesToResize, alreadyInside;
  26313. #if JUCE_WIN32
  26314. HWND pluginHWND;
  26315. void* originalWndProc;
  26316. int sizeCheckCount;
  26317. #elif JUCE_LINUX
  26318. Window pluginWindow;
  26319. EventProcPtr pluginProc;
  26320. #endif
  26321. #if JUCE_MAC
  26322. void openPluginWindow (WindowRef parentWindow)
  26323. {
  26324. if (isOpen || parentWindow == 0)
  26325. return;
  26326. isOpen = true;
  26327. ERect* rect = 0;
  26328. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26329. dispatch (effEditOpen, 0, 0, parentWindow, 0);
  26330. // do this before and after like in the steinberg example
  26331. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26332. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26333. // Install keyboard hooks
  26334. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26335. // double-check it's not too tiny
  26336. int w = 250, h = 150;
  26337. if (rect != 0)
  26338. {
  26339. w = rect->right - rect->left;
  26340. h = rect->bottom - rect->top;
  26341. if (w == 0 || h == 0)
  26342. {
  26343. w = 250;
  26344. h = 150;
  26345. }
  26346. }
  26347. w = jmax (w, 32);
  26348. h = jmax (h, 32);
  26349. setSize (w, h);
  26350. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26351. repaint();
  26352. }
  26353. #else
  26354. void openPluginWindow()
  26355. {
  26356. if (isOpen || getWindowHandle() == 0)
  26357. return;
  26358. log ("Opening VST UI: " + plugin.name);
  26359. isOpen = true;
  26360. ERect* rect = 0;
  26361. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26362. dispatch (effEditOpen, 0, 0, getWindowHandle(), 0);
  26363. // do this before and after like in the steinberg example
  26364. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26365. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26366. // Install keyboard hooks
  26367. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26368. #if JUCE_WIN32
  26369. originalWndProc = 0;
  26370. pluginHWND = GetWindow ((HWND) getWindowHandle(), GW_CHILD);
  26371. if (pluginHWND == 0)
  26372. {
  26373. isOpen = false;
  26374. setSize (300, 150);
  26375. return;
  26376. }
  26377. #pragma warning (push)
  26378. #pragma warning (disable: 4244)
  26379. originalWndProc = (void*) GetWindowLongPtr (pluginHWND, GWL_WNDPROC);
  26380. if (! pluginWantsKeys)
  26381. SetWindowLongPtr (pluginHWND, GWL_WNDPROC, (LONG_PTR) vstHookWndProc);
  26382. #pragma warning (pop)
  26383. int w, h;
  26384. RECT r;
  26385. GetWindowRect (pluginHWND, &r);
  26386. w = r.right - r.left;
  26387. h = r.bottom - r.top;
  26388. if (rect != 0)
  26389. {
  26390. const int rw = rect->right - rect->left;
  26391. const int rh = rect->bottom - rect->top;
  26392. if ((rw > 50 && rh > 50 && rw < 2000 && rh < 2000 && rw != w && rh != h)
  26393. || ((w == 0 && rw > 0) || (h == 0 && rh > 0)))
  26394. {
  26395. // very dodgy logic to decide which size is right.
  26396. if (abs (rw - w) > 350 || abs (rh - h) > 350)
  26397. {
  26398. SetWindowPos (pluginHWND, 0,
  26399. 0, 0, rw, rh,
  26400. SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  26401. GetWindowRect (pluginHWND, &r);
  26402. w = r.right - r.left;
  26403. h = r.bottom - r.top;
  26404. pluginRefusesToResize = (w != rw) || (h != rh);
  26405. w = rw;
  26406. h = rh;
  26407. }
  26408. }
  26409. }
  26410. #elif JUCE_LINUX
  26411. pluginWindow = getChildWindow ((Window) getWindowHandle());
  26412. if (pluginWindow != 0)
  26413. pluginProc = (EventProcPtr) getPropertyFromXWindow (pluginWindow,
  26414. XInternAtom (display, "_XEventProc", False));
  26415. int w = 250, h = 150;
  26416. if (rect != 0)
  26417. {
  26418. w = rect->right - rect->left;
  26419. h = rect->bottom - rect->top;
  26420. if (w == 0 || h == 0)
  26421. {
  26422. w = 250;
  26423. h = 150;
  26424. }
  26425. }
  26426. if (pluginWindow != 0)
  26427. XMapRaised (display, pluginWindow);
  26428. #endif
  26429. // double-check it's not too tiny
  26430. w = jmax (w, 32);
  26431. h = jmax (h, 32);
  26432. setSize (w, h);
  26433. #if JUCE_WIN32
  26434. checkPluginWindowSize();
  26435. #endif
  26436. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26437. repaint();
  26438. }
  26439. #endif
  26440. #if ! JUCE_MAC
  26441. void closePluginWindow()
  26442. {
  26443. if (isOpen)
  26444. {
  26445. log ("Closing VST UI: " + plugin.getName());
  26446. isOpen = false;
  26447. dispatch (effEditClose, 0, 0, 0, 0);
  26448. #if JUCE_WIN32
  26449. #pragma warning (push)
  26450. #pragma warning (disable: 4244)
  26451. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26452. SetWindowLongPtr (pluginHWND, GWL_WNDPROC, (LONG_PTR) originalWndProc);
  26453. #pragma warning (pop)
  26454. stopTimer();
  26455. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26456. DestroyWindow (pluginHWND);
  26457. pluginHWND = 0;
  26458. #elif JUCE_LINUX
  26459. stopTimer();
  26460. pluginWindow = 0;
  26461. pluginProc = 0;
  26462. #endif
  26463. }
  26464. }
  26465. #endif
  26466. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt)
  26467. {
  26468. return plugin.dispatch (opcode, index, value, ptr, opt);
  26469. }
  26470. #if JUCE_WIN32
  26471. void checkPluginWindowSize() throw()
  26472. {
  26473. RECT r;
  26474. GetWindowRect (pluginHWND, &r);
  26475. const int w = r.right - r.left;
  26476. const int h = r.bottom - r.top;
  26477. if (isShowing() && w > 0 && h > 0
  26478. && (w != getWidth() || h != getHeight())
  26479. && ! pluginRefusesToResize)
  26480. {
  26481. setSize (w, h);
  26482. sizeCheckCount = 0;
  26483. }
  26484. }
  26485. // hooks to get keyboard events from VST windows..
  26486. static LRESULT CALLBACK vstHookWndProc (HWND hW, UINT message, WPARAM wParam, LPARAM lParam)
  26487. {
  26488. for (int i = activeVSTWindows.size(); --i >= 0;)
  26489. {
  26490. const VSTPluginWindow* const w = (const VSTPluginWindow*) activeVSTWindows.getUnchecked (i);
  26491. if (w->pluginHWND == hW)
  26492. {
  26493. if (message == WM_CHAR
  26494. || message == WM_KEYDOWN
  26495. || message == WM_SYSKEYDOWN
  26496. || message == WM_KEYUP
  26497. || message == WM_SYSKEYUP
  26498. || message == WM_APPCOMMAND)
  26499. {
  26500. SendMessage ((HWND) w->getTopLevelComponent()->getWindowHandle(),
  26501. message, wParam, lParam);
  26502. }
  26503. return CallWindowProc ((WNDPROC) (w->originalWndProc),
  26504. (HWND) w->pluginHWND,
  26505. message,
  26506. wParam,
  26507. lParam);
  26508. }
  26509. }
  26510. return DefWindowProc (hW, message, wParam, lParam);
  26511. }
  26512. #endif
  26513. #if JUCE_LINUX
  26514. // overload mouse/keyboard events to forward them to the plugin's inner window..
  26515. void sendEventToChild (XEvent* event)
  26516. {
  26517. if (pluginProc != 0)
  26518. {
  26519. // if the plugin publishes an event procedure, pass the event directly..
  26520. pluginProc (event);
  26521. }
  26522. else if (pluginWindow != 0)
  26523. {
  26524. // if the plugin has a window, then send the event to the window so that
  26525. // its message thread will pick it up..
  26526. XSendEvent (display, pluginWindow, False, 0L, event);
  26527. XFlush (display);
  26528. }
  26529. }
  26530. void mouseEnter (const MouseEvent& e)
  26531. {
  26532. if (pluginWindow != 0)
  26533. {
  26534. XEvent ev;
  26535. zerostruct (ev);
  26536. ev.xcrossing.display = display;
  26537. ev.xcrossing.type = EnterNotify;
  26538. ev.xcrossing.window = pluginWindow;
  26539. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26540. ev.xcrossing.time = CurrentTime;
  26541. ev.xcrossing.x = e.x;
  26542. ev.xcrossing.y = e.y;
  26543. ev.xcrossing.x_root = e.getScreenX();
  26544. ev.xcrossing.y_root = e.getScreenY();
  26545. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26546. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26547. translateJuceToXCrossingModifiers (e, ev);
  26548. sendEventToChild (&ev);
  26549. }
  26550. }
  26551. void mouseExit (const MouseEvent& e)
  26552. {
  26553. if (pluginWindow != 0)
  26554. {
  26555. XEvent ev;
  26556. zerostruct (ev);
  26557. ev.xcrossing.display = display;
  26558. ev.xcrossing.type = LeaveNotify;
  26559. ev.xcrossing.window = pluginWindow;
  26560. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26561. ev.xcrossing.time = CurrentTime;
  26562. ev.xcrossing.x = e.x;
  26563. ev.xcrossing.y = e.y;
  26564. ev.xcrossing.x_root = e.getScreenX();
  26565. ev.xcrossing.y_root = e.getScreenY();
  26566. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26567. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26568. ev.xcrossing.focus = hasKeyboardFocus (true); // TODO - yes ?
  26569. translateJuceToXCrossingModifiers (e, ev);
  26570. sendEventToChild (&ev);
  26571. }
  26572. }
  26573. void mouseMove (const MouseEvent& e)
  26574. {
  26575. if (pluginWindow != 0)
  26576. {
  26577. XEvent ev;
  26578. zerostruct (ev);
  26579. ev.xmotion.display = display;
  26580. ev.xmotion.type = MotionNotify;
  26581. ev.xmotion.window = pluginWindow;
  26582. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26583. ev.xmotion.time = CurrentTime;
  26584. ev.xmotion.is_hint = NotifyNormal;
  26585. ev.xmotion.x = e.x;
  26586. ev.xmotion.y = e.y;
  26587. ev.xmotion.x_root = e.getScreenX();
  26588. ev.xmotion.y_root = e.getScreenY();
  26589. sendEventToChild (&ev);
  26590. }
  26591. }
  26592. void mouseDrag (const MouseEvent& e)
  26593. {
  26594. if (pluginWindow != 0)
  26595. {
  26596. XEvent ev;
  26597. zerostruct (ev);
  26598. ev.xmotion.display = display;
  26599. ev.xmotion.type = MotionNotify;
  26600. ev.xmotion.window = pluginWindow;
  26601. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26602. ev.xmotion.time = CurrentTime;
  26603. ev.xmotion.x = e.x ;
  26604. ev.xmotion.y = e.y;
  26605. ev.xmotion.x_root = e.getScreenX();
  26606. ev.xmotion.y_root = e.getScreenY();
  26607. ev.xmotion.is_hint = NotifyNormal;
  26608. translateJuceToXMotionModifiers (e, ev);
  26609. sendEventToChild (&ev);
  26610. }
  26611. }
  26612. void mouseUp (const MouseEvent& e)
  26613. {
  26614. if (pluginWindow != 0)
  26615. {
  26616. XEvent ev;
  26617. zerostruct (ev);
  26618. ev.xbutton.display = display;
  26619. ev.xbutton.type = ButtonRelease;
  26620. ev.xbutton.window = pluginWindow;
  26621. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26622. ev.xbutton.time = CurrentTime;
  26623. ev.xbutton.x = e.x;
  26624. ev.xbutton.y = e.y;
  26625. ev.xbutton.x_root = e.getScreenX();
  26626. ev.xbutton.y_root = e.getScreenY();
  26627. translateJuceToXButtonModifiers (e, ev);
  26628. sendEventToChild (&ev);
  26629. }
  26630. }
  26631. void mouseWheelMove (const MouseEvent& e,
  26632. float incrementX,
  26633. float incrementY)
  26634. {
  26635. if (pluginWindow != 0)
  26636. {
  26637. XEvent ev;
  26638. zerostruct (ev);
  26639. ev.xbutton.display = display;
  26640. ev.xbutton.type = ButtonPress;
  26641. ev.xbutton.window = pluginWindow;
  26642. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26643. ev.xbutton.time = CurrentTime;
  26644. ev.xbutton.x = e.x;
  26645. ev.xbutton.y = e.y;
  26646. ev.xbutton.x_root = e.getScreenX();
  26647. ev.xbutton.y_root = e.getScreenY();
  26648. translateJuceToXMouseWheelModifiers (e, incrementY, ev);
  26649. sendEventToChild (&ev);
  26650. // TODO - put a usleep here ?
  26651. ev.xbutton.type = ButtonRelease;
  26652. sendEventToChild (&ev);
  26653. }
  26654. }
  26655. #endif
  26656. #if JUCE_MAC
  26657. #if ! JUCE_SUPPORT_CARBON
  26658. #error "To build VSTs, you need to enable the JUCE_SUPPORT_CARBON flag in your config!"
  26659. #endif
  26660. class InnerWrapperComponent : public CarbonViewWrapperComponent
  26661. {
  26662. public:
  26663. InnerWrapperComponent (VSTPluginWindow* const owner_)
  26664. : owner (owner_),
  26665. alreadyInside (false)
  26666. {
  26667. }
  26668. ~InnerWrapperComponent()
  26669. {
  26670. deleteWindow();
  26671. }
  26672. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  26673. {
  26674. owner->openPluginWindow (windowRef);
  26675. return 0;
  26676. }
  26677. void removeView (HIViewRef)
  26678. {
  26679. owner->dispatch (effEditClose, 0, 0, 0, 0);
  26680. owner->dispatch (effEditSleep, 0, 0, 0, 0);
  26681. }
  26682. bool getEmbeddedViewSize (int& w, int& h)
  26683. {
  26684. ERect* rect = 0;
  26685. owner->dispatch (effEditGetRect, 0, 0, &rect, 0);
  26686. w = rect->right - rect->left;
  26687. h = rect->bottom - rect->top;
  26688. return true;
  26689. }
  26690. void mouseDown (int x, int y)
  26691. {
  26692. if (! alreadyInside)
  26693. {
  26694. alreadyInside = true;
  26695. getTopLevelComponent()->toFront (true);
  26696. owner->dispatch (effEditMouse, x, y, 0, 0);
  26697. alreadyInside = false;
  26698. }
  26699. else
  26700. {
  26701. PostEvent (::mouseDown, 0);
  26702. }
  26703. }
  26704. void paint()
  26705. {
  26706. ComponentPeer* const peer = getPeer();
  26707. if (peer != 0)
  26708. {
  26709. const Point<int> pos (getScreenPosition() - peer->getScreenPosition());
  26710. ERect r;
  26711. r.left = pos.getX();
  26712. r.right = r.left + getWidth();
  26713. r.top = pos.getY();
  26714. r.bottom = r.top + getHeight();
  26715. owner->dispatch (effEditDraw, 0, 0, &r, 0);
  26716. }
  26717. }
  26718. private:
  26719. VSTPluginWindow* const owner;
  26720. bool alreadyInside;
  26721. };
  26722. friend class InnerWrapperComponent;
  26723. ScopedPointer <InnerWrapperComponent> innerWrapper;
  26724. void resized()
  26725. {
  26726. innerWrapper->setSize (getWidth(), getHeight());
  26727. }
  26728. #endif
  26729. };
  26730. AudioProcessorEditor* VSTPluginInstance::createEditor()
  26731. {
  26732. if (hasEditor())
  26733. return new VSTPluginWindow (*this);
  26734. return 0;
  26735. }
  26736. void VSTPluginInstance::handleAsyncUpdate()
  26737. {
  26738. // indicates that something about the plugin has changed..
  26739. updateHostDisplay();
  26740. }
  26741. bool VSTPluginInstance::restoreProgramSettings (const fxProgram* const prog)
  26742. {
  26743. if (vst_swap (prog->chunkMagic) == 'CcnK' && vst_swap (prog->fxMagic) == 'FxCk')
  26744. {
  26745. changeProgramName (getCurrentProgram(), prog->prgName);
  26746. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  26747. setParameter (i, vst_swapFloat (prog->params[i]));
  26748. return true;
  26749. }
  26750. return false;
  26751. }
  26752. bool VSTPluginInstance::loadFromFXBFile (const void* const data,
  26753. const int dataSize)
  26754. {
  26755. if (dataSize < 28)
  26756. return false;
  26757. const fxSet* const set = (const fxSet*) data;
  26758. if ((vst_swap (set->chunkMagic) != 'CcnK' && vst_swap (set->chunkMagic) != 'KncC')
  26759. || vst_swap (set->version) > fxbVersionNum)
  26760. return false;
  26761. if (vst_swap (set->fxMagic) == 'FxBk')
  26762. {
  26763. // bank of programs
  26764. if (vst_swap (set->numPrograms) >= 0)
  26765. {
  26766. const int oldProg = getCurrentProgram();
  26767. const int numParams = vst_swap (((const fxProgram*) (set->programs))->numParams);
  26768. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26769. for (int i = 0; i < vst_swap (set->numPrograms); ++i)
  26770. {
  26771. if (i != oldProg)
  26772. {
  26773. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + i * progLen);
  26774. if (((const char*) prog) - ((const char*) set) >= dataSize)
  26775. return false;
  26776. if (vst_swap (set->numPrograms) > 0)
  26777. setCurrentProgram (i);
  26778. if (! restoreProgramSettings (prog))
  26779. return false;
  26780. }
  26781. }
  26782. if (vst_swap (set->numPrograms) > 0)
  26783. setCurrentProgram (oldProg);
  26784. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + oldProg * progLen);
  26785. if (((const char*) prog) - ((const char*) set) >= dataSize)
  26786. return false;
  26787. if (! restoreProgramSettings (prog))
  26788. return false;
  26789. }
  26790. }
  26791. else if (vst_swap (set->fxMagic) == 'FxCk')
  26792. {
  26793. // single program
  26794. const fxProgram* const prog = (const fxProgram*) data;
  26795. if (vst_swap (prog->chunkMagic) != 'CcnK')
  26796. return false;
  26797. changeProgramName (getCurrentProgram(), prog->prgName);
  26798. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  26799. setParameter (i, vst_swapFloat (prog->params[i]));
  26800. }
  26801. else if (vst_swap (set->fxMagic) == 'FBCh' || vst_swap (set->fxMagic) == 'hCBF')
  26802. {
  26803. // non-preset chunk
  26804. const fxChunkSet* const cset = (const fxChunkSet*) data;
  26805. if (vst_swap (cset->chunkSize) + sizeof (fxChunkSet) - 8 > (unsigned int) dataSize)
  26806. return false;
  26807. setChunkData (cset->chunk, vst_swap (cset->chunkSize), false);
  26808. }
  26809. else if (vst_swap (set->fxMagic) == 'FPCh' || vst_swap (set->fxMagic) == 'hCPF')
  26810. {
  26811. // preset chunk
  26812. const fxProgramSet* const cset = (const fxProgramSet*) data;
  26813. if (vst_swap (cset->chunkSize) + sizeof (fxProgramSet) - 8 > (unsigned int) dataSize)
  26814. return false;
  26815. setChunkData (cset->chunk, vst_swap (cset->chunkSize), true);
  26816. changeProgramName (getCurrentProgram(), cset->name);
  26817. }
  26818. else
  26819. {
  26820. return false;
  26821. }
  26822. return true;
  26823. }
  26824. void VSTPluginInstance::setParamsInProgramBlock (fxProgram* const prog) throw()
  26825. {
  26826. const int numParams = getNumParameters();
  26827. prog->chunkMagic = vst_swap ('CcnK');
  26828. prog->byteSize = 0;
  26829. prog->fxMagic = vst_swap ('FxCk');
  26830. prog->version = vst_swap (fxbVersionNum);
  26831. prog->fxID = vst_swap (getUID());
  26832. prog->fxVersion = vst_swap (getVersionNumber());
  26833. prog->numParams = vst_swap (numParams);
  26834. getCurrentProgramName().copyToCString (prog->prgName, sizeof (prog->prgName) - 1);
  26835. for (int i = 0; i < numParams; ++i)
  26836. prog->params[i] = vst_swapFloat (getParameter (i));
  26837. }
  26838. bool VSTPluginInstance::saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB)
  26839. {
  26840. const int numPrograms = getNumPrograms();
  26841. const int numParams = getNumParameters();
  26842. if (usesChunks())
  26843. {
  26844. if (isFXB)
  26845. {
  26846. MemoryBlock chunk;
  26847. getChunkData (chunk, false, maxSizeMB);
  26848. const size_t totalLen = sizeof (fxChunkSet) + chunk.getSize() - 8;
  26849. dest.setSize (totalLen, true);
  26850. fxChunkSet* const set = (fxChunkSet*) dest.getData();
  26851. set->chunkMagic = vst_swap ('CcnK');
  26852. set->byteSize = 0;
  26853. set->fxMagic = vst_swap ('FBCh');
  26854. set->version = vst_swap (fxbVersionNum);
  26855. set->fxID = vst_swap (getUID());
  26856. set->fxVersion = vst_swap (getVersionNumber());
  26857. set->numPrograms = vst_swap (numPrograms);
  26858. set->chunkSize = vst_swap ((long) chunk.getSize());
  26859. chunk.copyTo (set->chunk, 0, chunk.getSize());
  26860. }
  26861. else
  26862. {
  26863. MemoryBlock chunk;
  26864. getChunkData (chunk, true, maxSizeMB);
  26865. const size_t totalLen = sizeof (fxProgramSet) + chunk.getSize() - 8;
  26866. dest.setSize (totalLen, true);
  26867. fxProgramSet* const set = (fxProgramSet*) dest.getData();
  26868. set->chunkMagic = vst_swap ('CcnK');
  26869. set->byteSize = 0;
  26870. set->fxMagic = vst_swap ('FPCh');
  26871. set->version = vst_swap (fxbVersionNum);
  26872. set->fxID = vst_swap (getUID());
  26873. set->fxVersion = vst_swap (getVersionNumber());
  26874. set->numPrograms = vst_swap (numPrograms);
  26875. set->chunkSize = vst_swap ((long) chunk.getSize());
  26876. getCurrentProgramName().copyToCString (set->name, sizeof (set->name) - 1);
  26877. chunk.copyTo (set->chunk, 0, chunk.getSize());
  26878. }
  26879. }
  26880. else
  26881. {
  26882. if (isFXB)
  26883. {
  26884. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26885. const int len = (sizeof (fxSet) - sizeof (fxProgram)) + progLen * jmax (1, numPrograms);
  26886. dest.setSize (len, true);
  26887. fxSet* const set = (fxSet*) dest.getData();
  26888. set->chunkMagic = vst_swap ('CcnK');
  26889. set->byteSize = 0;
  26890. set->fxMagic = vst_swap ('FxBk');
  26891. set->version = vst_swap (fxbVersionNum);
  26892. set->fxID = vst_swap (getUID());
  26893. set->fxVersion = vst_swap (getVersionNumber());
  26894. set->numPrograms = vst_swap (numPrograms);
  26895. const int oldProgram = getCurrentProgram();
  26896. MemoryBlock oldSettings;
  26897. createTempParameterStore (oldSettings);
  26898. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + oldProgram * progLen));
  26899. for (int i = 0; i < numPrograms; ++i)
  26900. {
  26901. if (i != oldProgram)
  26902. {
  26903. setCurrentProgram (i);
  26904. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + i * progLen));
  26905. }
  26906. }
  26907. setCurrentProgram (oldProgram);
  26908. restoreFromTempParameterStore (oldSettings);
  26909. }
  26910. else
  26911. {
  26912. const int totalLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26913. dest.setSize (totalLen, true);
  26914. setParamsInProgramBlock ((fxProgram*) dest.getData());
  26915. }
  26916. }
  26917. return true;
  26918. }
  26919. void VSTPluginInstance::getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const
  26920. {
  26921. if (usesChunks())
  26922. {
  26923. void* data = 0;
  26924. const int bytes = dispatch (effGetChunk, isPreset ? 1 : 0, 0, &data, 0.0f);
  26925. if (data != 0 && bytes <= maxSizeMB * 1024 * 1024)
  26926. {
  26927. mb.setSize (bytes);
  26928. mb.copyFrom (data, 0, bytes);
  26929. }
  26930. }
  26931. }
  26932. void VSTPluginInstance::setChunkData (const char* data, int size, bool isPreset)
  26933. {
  26934. if (size > 0 && usesChunks())
  26935. {
  26936. dispatch (effSetChunk, isPreset ? 1 : 0, size, (void*) data, 0.0f);
  26937. if (! isPreset)
  26938. updateStoredProgramNames();
  26939. }
  26940. }
  26941. void VSTPluginInstance::timerCallback()
  26942. {
  26943. if (dispatch (effIdle, 0, 0, 0, 0) == 0)
  26944. stopTimer();
  26945. }
  26946. int VSTPluginInstance::dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const
  26947. {
  26948. const ScopedLock sl (lock);
  26949. ++insideVSTCallback;
  26950. int result = 0;
  26951. try
  26952. {
  26953. if (effect != 0)
  26954. {
  26955. #if JUCE_MAC
  26956. if (module->resFileId != 0)
  26957. UseResFile (module->resFileId);
  26958. CGrafPtr oldPort;
  26959. if (getActiveEditor() != 0)
  26960. {
  26961. const Point<int> pos (getActiveEditor()->relativePositionToOtherComponent (getActiveEditor()->getTopLevelComponent(), Point<int>()));
  26962. GetPort (&oldPort);
  26963. SetPortWindowPort ((WindowRef) getActiveEditor()->getWindowHandle());
  26964. SetOrigin (-pos.getX(), -pos.getY());
  26965. }
  26966. #endif
  26967. result = effect->dispatcher (effect, opcode, index, value, ptr, opt);
  26968. #if JUCE_MAC
  26969. if (getActiveEditor() != 0)
  26970. SetPort (oldPort);
  26971. module->resFileId = CurResFile();
  26972. #endif
  26973. --insideVSTCallback;
  26974. return result;
  26975. }
  26976. }
  26977. catch (...)
  26978. {
  26979. }
  26980. --insideVSTCallback;
  26981. return result;
  26982. }
  26983. // handles non plugin-specific callbacks..
  26984. static const int defaultVSTSampleRateValue = 16384;
  26985. static const int defaultVSTBlockSizeValue = 512;
  26986. static VstIntPtr handleGeneralCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  26987. {
  26988. (void) index;
  26989. (void) value;
  26990. (void) opt;
  26991. switch (opcode)
  26992. {
  26993. case audioMasterCanDo:
  26994. {
  26995. static const char* canDos[] = { "supplyIdle",
  26996. "sendVstEvents",
  26997. "sendVstMidiEvent",
  26998. "sendVstTimeInfo",
  26999. "receiveVstEvents",
  27000. "receiveVstMidiEvent",
  27001. "supportShell",
  27002. "shellCategory" };
  27003. for (int i = 0; i < numElementsInArray (canDos); ++i)
  27004. if (strcmp (canDos[i], (const char*) ptr) == 0)
  27005. return 1;
  27006. return 0;
  27007. }
  27008. case audioMasterVersion:
  27009. return 0x2400;
  27010. case audioMasterCurrentId:
  27011. return shellUIDToCreate;
  27012. case audioMasterGetNumAutomatableParameters:
  27013. return 0;
  27014. case audioMasterGetAutomationState:
  27015. return 1;
  27016. case audioMasterGetVendorVersion:
  27017. return 0x0101;
  27018. case audioMasterGetVendorString:
  27019. case audioMasterGetProductString:
  27020. {
  27021. String hostName ("Juce VST Host");
  27022. if (JUCEApplication::getInstance() != 0)
  27023. hostName = JUCEApplication::getInstance()->getApplicationName();
  27024. hostName.copyToCString ((char*) ptr, jmin (kVstMaxVendorStrLen, kVstMaxProductStrLen) - 1);
  27025. }
  27026. break;
  27027. case audioMasterGetSampleRate:
  27028. return (VstIntPtr) defaultVSTSampleRateValue;
  27029. case audioMasterGetBlockSize:
  27030. return (VstIntPtr) defaultVSTBlockSizeValue;
  27031. case audioMasterSetOutputSampleRate:
  27032. return 0;
  27033. default:
  27034. DBG ("*** Unhandled VST Callback: " + String ((int) opcode));
  27035. break;
  27036. }
  27037. return 0;
  27038. }
  27039. // handles callbacks for a specific plugin
  27040. VstIntPtr VSTPluginInstance::handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  27041. {
  27042. switch (opcode)
  27043. {
  27044. case audioMasterAutomate:
  27045. sendParamChangeMessageToListeners (index, opt);
  27046. break;
  27047. case audioMasterProcessEvents:
  27048. handleMidiFromPlugin ((const VstEvents*) ptr);
  27049. break;
  27050. case audioMasterGetTime:
  27051. #ifdef _MSC_VER
  27052. #pragma warning (push)
  27053. #pragma warning (disable: 4311)
  27054. #endif
  27055. return (VstIntPtr) &vstHostTime;
  27056. #ifdef _MSC_VER
  27057. #pragma warning (pop)
  27058. #endif
  27059. break;
  27060. case audioMasterIdle:
  27061. if (insideVSTCallback == 0 && MessageManager::getInstance()->isThisTheMessageThread())
  27062. {
  27063. ++insideVSTCallback;
  27064. #if JUCE_MAC
  27065. if (getActiveEditor() != 0)
  27066. dispatch (effEditIdle, 0, 0, 0, 0);
  27067. #endif
  27068. juce_callAnyTimersSynchronously();
  27069. handleUpdateNowIfNeeded();
  27070. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  27071. ComponentPeer::getPeer (i)->performAnyPendingRepaintsNow();
  27072. --insideVSTCallback;
  27073. }
  27074. break;
  27075. case audioMasterUpdateDisplay:
  27076. triggerAsyncUpdate();
  27077. break;
  27078. case audioMasterTempoAt:
  27079. // returns (10000 * bpm)
  27080. break;
  27081. case audioMasterNeedIdle:
  27082. startTimer (50);
  27083. break;
  27084. case audioMasterSizeWindow:
  27085. if (getActiveEditor() != 0)
  27086. getActiveEditor()->setSize (index, value);
  27087. return 1;
  27088. case audioMasterGetSampleRate:
  27089. return (VstIntPtr) (getSampleRate() > 0 ? getSampleRate() : defaultVSTSampleRateValue);
  27090. case audioMasterGetBlockSize:
  27091. return (VstIntPtr) (getBlockSize() > 0 ? getBlockSize() : defaultVSTBlockSizeValue);
  27092. case audioMasterWantMidi:
  27093. wantsMidiMessages = true;
  27094. break;
  27095. case audioMasterGetDirectory:
  27096. #if JUCE_MAC
  27097. return (VstIntPtr) (void*) &module->parentDirFSSpec;
  27098. #else
  27099. return (VstIntPtr) (pointer_sized_uint) module->fullParentDirectoryPathName.toUTF8();
  27100. #endif
  27101. case audioMasterGetAutomationState:
  27102. // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
  27103. break;
  27104. // none of these are handled (yet)..
  27105. case audioMasterBeginEdit:
  27106. case audioMasterEndEdit:
  27107. case audioMasterSetTime:
  27108. case audioMasterPinConnected:
  27109. case audioMasterGetParameterQuantization:
  27110. case audioMasterIOChanged:
  27111. case audioMasterGetInputLatency:
  27112. case audioMasterGetOutputLatency:
  27113. case audioMasterGetPreviousPlug:
  27114. case audioMasterGetNextPlug:
  27115. case audioMasterWillReplaceOrAccumulate:
  27116. case audioMasterGetCurrentProcessLevel:
  27117. case audioMasterOfflineStart:
  27118. case audioMasterOfflineRead:
  27119. case audioMasterOfflineWrite:
  27120. case audioMasterOfflineGetCurrentPass:
  27121. case audioMasterOfflineGetCurrentMetaPass:
  27122. case audioMasterVendorSpecific:
  27123. case audioMasterSetIcon:
  27124. case audioMasterGetLanguage:
  27125. case audioMasterOpenWindow:
  27126. case audioMasterCloseWindow:
  27127. break;
  27128. default:
  27129. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27130. }
  27131. return 0;
  27132. }
  27133. // entry point for all callbacks from the plugin
  27134. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt)
  27135. {
  27136. try
  27137. {
  27138. if (effect != 0 && effect->resvd2 != 0)
  27139. {
  27140. return ((VSTPluginInstance*)(effect->resvd2))
  27141. ->handleCallback (opcode, index, value, ptr, opt);
  27142. }
  27143. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27144. }
  27145. catch (...)
  27146. {
  27147. return 0;
  27148. }
  27149. }
  27150. const String VSTPluginInstance::getVersion() const throw()
  27151. {
  27152. unsigned int v = dispatch (effGetVendorVersion, 0, 0, 0, 0);
  27153. String s;
  27154. if (v == 0 || v == -1)
  27155. v = getVersionNumber();
  27156. if (v != 0)
  27157. {
  27158. int versionBits[4];
  27159. int n = 0;
  27160. while (v != 0)
  27161. {
  27162. versionBits [n++] = (v & 0xff);
  27163. v >>= 8;
  27164. }
  27165. s << 'V';
  27166. while (n > 0)
  27167. {
  27168. s << versionBits [--n];
  27169. if (n > 0)
  27170. s << '.';
  27171. }
  27172. }
  27173. return s;
  27174. }
  27175. int VSTPluginInstance::getUID() const throw()
  27176. {
  27177. int uid = effect != 0 ? effect->uniqueID : 0;
  27178. if (uid == 0)
  27179. uid = module->file.hashCode();
  27180. return uid;
  27181. }
  27182. const String VSTPluginInstance::getCategory() const throw()
  27183. {
  27184. const char* result = 0;
  27185. switch (dispatch (effGetPlugCategory, 0, 0, 0, 0))
  27186. {
  27187. case kPlugCategEffect:
  27188. result = "Effect";
  27189. break;
  27190. case kPlugCategSynth:
  27191. result = "Synth";
  27192. break;
  27193. case kPlugCategAnalysis:
  27194. result = "Anaylsis";
  27195. break;
  27196. case kPlugCategMastering:
  27197. result = "Mastering";
  27198. break;
  27199. case kPlugCategSpacializer:
  27200. result = "Spacial";
  27201. break;
  27202. case kPlugCategRoomFx:
  27203. result = "Reverb";
  27204. break;
  27205. case kPlugSurroundFx:
  27206. result = "Surround";
  27207. break;
  27208. case kPlugCategRestoration:
  27209. result = "Restoration";
  27210. break;
  27211. case kPlugCategGenerator:
  27212. result = "Tone generation";
  27213. break;
  27214. default:
  27215. break;
  27216. }
  27217. return result;
  27218. }
  27219. float VSTPluginInstance::getParameter (int index)
  27220. {
  27221. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27222. {
  27223. try
  27224. {
  27225. const ScopedLock sl (lock);
  27226. return effect->getParameter (effect, index);
  27227. }
  27228. catch (...)
  27229. {
  27230. }
  27231. }
  27232. return 0.0f;
  27233. }
  27234. void VSTPluginInstance::setParameter (int index, float newValue)
  27235. {
  27236. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27237. {
  27238. try
  27239. {
  27240. const ScopedLock sl (lock);
  27241. if (effect->getParameter (effect, index) != newValue)
  27242. effect->setParameter (effect, index, newValue);
  27243. }
  27244. catch (...)
  27245. {
  27246. }
  27247. }
  27248. }
  27249. const String VSTPluginInstance::getParameterName (int index)
  27250. {
  27251. if (effect != 0)
  27252. {
  27253. jassert (index >= 0 && index < effect->numParams);
  27254. char nm [256];
  27255. zerostruct (nm);
  27256. dispatch (effGetParamName, index, 0, nm, 0);
  27257. return String (nm).trim();
  27258. }
  27259. return String::empty;
  27260. }
  27261. const String VSTPluginInstance::getParameterLabel (int index) const
  27262. {
  27263. if (effect != 0)
  27264. {
  27265. jassert (index >= 0 && index < effect->numParams);
  27266. char nm [256];
  27267. zerostruct (nm);
  27268. dispatch (effGetParamLabel, index, 0, nm, 0);
  27269. return String (nm).trim();
  27270. }
  27271. return String::empty;
  27272. }
  27273. const String VSTPluginInstance::getParameterText (int index)
  27274. {
  27275. if (effect != 0)
  27276. {
  27277. jassert (index >= 0 && index < effect->numParams);
  27278. char nm [256];
  27279. zerostruct (nm);
  27280. dispatch (effGetParamDisplay, index, 0, nm, 0);
  27281. return String (nm).trim();
  27282. }
  27283. return String::empty;
  27284. }
  27285. bool VSTPluginInstance::isParameterAutomatable (int index) const
  27286. {
  27287. if (effect != 0)
  27288. {
  27289. jassert (index >= 0 && index < effect->numParams);
  27290. return dispatch (effCanBeAutomated, index, 0, 0, 0) != 0;
  27291. }
  27292. return false;
  27293. }
  27294. void VSTPluginInstance::createTempParameterStore (MemoryBlock& dest)
  27295. {
  27296. dest.setSize (64 + 4 * getNumParameters());
  27297. dest.fillWith (0);
  27298. getCurrentProgramName().copyToCString ((char*) dest.getData(), 63);
  27299. float* const p = (float*) (((char*) dest.getData()) + 64);
  27300. for (int i = 0; i < getNumParameters(); ++i)
  27301. p[i] = getParameter(i);
  27302. }
  27303. void VSTPluginInstance::restoreFromTempParameterStore (const MemoryBlock& m)
  27304. {
  27305. changeProgramName (getCurrentProgram(), (const char*) m.getData());
  27306. float* p = (float*) (((char*) m.getData()) + 64);
  27307. for (int i = 0; i < getNumParameters(); ++i)
  27308. setParameter (i, p[i]);
  27309. }
  27310. void VSTPluginInstance::setCurrentProgram (int newIndex)
  27311. {
  27312. if (getNumPrograms() > 0 && newIndex != getCurrentProgram())
  27313. dispatch (effSetProgram, 0, jlimit (0, getNumPrograms() - 1, newIndex), 0, 0);
  27314. }
  27315. const String VSTPluginInstance::getProgramName (int index)
  27316. {
  27317. if (index == getCurrentProgram())
  27318. {
  27319. return getCurrentProgramName();
  27320. }
  27321. else if (effect != 0)
  27322. {
  27323. char nm [256];
  27324. zerostruct (nm);
  27325. if (dispatch (effGetProgramNameIndexed,
  27326. jlimit (0, getNumPrograms(), index),
  27327. -1, nm, 0) != 0)
  27328. {
  27329. return String (nm).trim();
  27330. }
  27331. }
  27332. return programNames [index];
  27333. }
  27334. void VSTPluginInstance::changeProgramName (int index, const String& newName)
  27335. {
  27336. if (index == getCurrentProgram())
  27337. {
  27338. if (getNumPrograms() > 0 && newName != getCurrentProgramName())
  27339. dispatch (effSetProgramName, 0, 0, (void*) newName.substring (0, 24).toCString(), 0.0f);
  27340. }
  27341. else
  27342. {
  27343. jassertfalse // xxx not implemented!
  27344. }
  27345. }
  27346. void VSTPluginInstance::updateStoredProgramNames()
  27347. {
  27348. if (effect != 0 && getNumPrograms() > 0)
  27349. {
  27350. char nm [256];
  27351. zerostruct (nm);
  27352. // only do this if the plugin can't use indexed names..
  27353. if (dispatch (effGetProgramNameIndexed, 0, -1, nm, 0) == 0)
  27354. {
  27355. const int oldProgram = getCurrentProgram();
  27356. MemoryBlock oldSettings;
  27357. createTempParameterStore (oldSettings);
  27358. for (int i = 0; i < getNumPrograms(); ++i)
  27359. {
  27360. setCurrentProgram (i);
  27361. getCurrentProgramName(); // (this updates the list)
  27362. }
  27363. setCurrentProgram (oldProgram);
  27364. restoreFromTempParameterStore (oldSettings);
  27365. }
  27366. }
  27367. }
  27368. const String VSTPluginInstance::getCurrentProgramName()
  27369. {
  27370. if (effect != 0)
  27371. {
  27372. char nm [256];
  27373. zerostruct (nm);
  27374. dispatch (effGetProgramName, 0, 0, nm, 0);
  27375. const int index = getCurrentProgram();
  27376. if (programNames[index].isEmpty())
  27377. {
  27378. while (programNames.size() < index)
  27379. programNames.add (String::empty);
  27380. programNames.set (index, String (nm).trim());
  27381. }
  27382. return String (nm).trim();
  27383. }
  27384. return String::empty;
  27385. }
  27386. const String VSTPluginInstance::getInputChannelName (const int index) const
  27387. {
  27388. if (index >= 0 && index < getNumInputChannels())
  27389. {
  27390. VstPinProperties pinProps;
  27391. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27392. return String (pinProps.label, sizeof (pinProps.label));
  27393. }
  27394. return String::empty;
  27395. }
  27396. bool VSTPluginInstance::isInputChannelStereoPair (int index) const
  27397. {
  27398. if (index < 0 || index >= getNumInputChannels())
  27399. return false;
  27400. VstPinProperties pinProps;
  27401. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27402. return (pinProps.flags & kVstPinIsStereo) != 0;
  27403. return true;
  27404. }
  27405. const String VSTPluginInstance::getOutputChannelName (const int index) const
  27406. {
  27407. if (index >= 0 && index < getNumOutputChannels())
  27408. {
  27409. VstPinProperties pinProps;
  27410. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27411. return String (pinProps.label, sizeof (pinProps.label));
  27412. }
  27413. return String::empty;
  27414. }
  27415. bool VSTPluginInstance::isOutputChannelStereoPair (int index) const
  27416. {
  27417. if (index < 0 || index >= getNumOutputChannels())
  27418. return false;
  27419. VstPinProperties pinProps;
  27420. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27421. return (pinProps.flags & kVstPinIsStereo) != 0;
  27422. return true;
  27423. }
  27424. void VSTPluginInstance::setPower (const bool on)
  27425. {
  27426. dispatch (effMainsChanged, 0, on ? 1 : 0, 0, 0);
  27427. isPowerOn = on;
  27428. }
  27429. const int defaultMaxSizeMB = 64;
  27430. void VSTPluginInstance::getStateInformation (MemoryBlock& destData)
  27431. {
  27432. saveToFXBFile (destData, true, defaultMaxSizeMB);
  27433. }
  27434. void VSTPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  27435. {
  27436. saveToFXBFile (destData, false, defaultMaxSizeMB);
  27437. }
  27438. void VSTPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  27439. {
  27440. loadFromFXBFile (data, sizeInBytes);
  27441. }
  27442. void VSTPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  27443. {
  27444. loadFromFXBFile (data, sizeInBytes);
  27445. }
  27446. VSTPluginFormat::VSTPluginFormat()
  27447. {
  27448. }
  27449. VSTPluginFormat::~VSTPluginFormat()
  27450. {
  27451. }
  27452. void VSTPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  27453. const String& fileOrIdentifier)
  27454. {
  27455. if (! fileMightContainThisPluginType (fileOrIdentifier))
  27456. return;
  27457. PluginDescription desc;
  27458. desc.fileOrIdentifier = fileOrIdentifier;
  27459. desc.uid = 0;
  27460. ScopedPointer <VSTPluginInstance> instance (dynamic_cast <VSTPluginInstance*> (createInstanceFromDescription (desc)));
  27461. if (instance == 0)
  27462. return;
  27463. try
  27464. {
  27465. #if JUCE_MAC
  27466. if (instance->module->resFileId != 0)
  27467. UseResFile (instance->module->resFileId);
  27468. #endif
  27469. instance->fillInPluginDescription (desc);
  27470. VstPlugCategory category = (VstPlugCategory) instance->dispatch (effGetPlugCategory, 0, 0, 0, 0);
  27471. if (category != kPlugCategShell)
  27472. {
  27473. // Normal plugin...
  27474. results.add (new PluginDescription (desc));
  27475. ++insideVSTCallback;
  27476. instance->dispatch (effOpen, 0, 0, 0, 0);
  27477. --insideVSTCallback;
  27478. }
  27479. else
  27480. {
  27481. // It's a shell plugin, so iterate all the subtypes...
  27482. char shellEffectName [64];
  27483. for (;;)
  27484. {
  27485. zerostruct (shellEffectName);
  27486. const int uid = instance->dispatch (effShellGetNextPlugin, 0, 0, shellEffectName, 0);
  27487. if (uid == 0)
  27488. {
  27489. break;
  27490. }
  27491. else
  27492. {
  27493. desc.uid = uid;
  27494. desc.name = shellEffectName;
  27495. bool alreadyThere = false;
  27496. for (int i = results.size(); --i >= 0;)
  27497. {
  27498. PluginDescription* const d = results.getUnchecked(i);
  27499. if (d->isDuplicateOf (desc))
  27500. {
  27501. alreadyThere = true;
  27502. break;
  27503. }
  27504. }
  27505. if (! alreadyThere)
  27506. results.add (new PluginDescription (desc));
  27507. }
  27508. }
  27509. }
  27510. }
  27511. catch (...)
  27512. {
  27513. // crashed while loading...
  27514. }
  27515. }
  27516. AudioPluginInstance* VSTPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  27517. {
  27518. ScopedPointer <VSTPluginInstance> result;
  27519. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  27520. {
  27521. File file (desc.fileOrIdentifier);
  27522. const File previousWorkingDirectory (File::getCurrentWorkingDirectory());
  27523. file.getParentDirectory().setAsCurrentWorkingDirectory();
  27524. const ReferenceCountedObjectPtr <ModuleHandle> module (ModuleHandle::findOrCreateModule (file));
  27525. if (module != 0)
  27526. {
  27527. shellUIDToCreate = desc.uid;
  27528. result = new VSTPluginInstance (module);
  27529. if (result->effect != 0)
  27530. {
  27531. result->effect->resvd2 = (VstIntPtr) (pointer_sized_int) (VSTPluginInstance*) result;
  27532. result->initialise();
  27533. }
  27534. else
  27535. {
  27536. result = 0;
  27537. }
  27538. }
  27539. previousWorkingDirectory.setAsCurrentWorkingDirectory();
  27540. }
  27541. return result.release();
  27542. }
  27543. bool VSTPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  27544. {
  27545. const File f (fileOrIdentifier);
  27546. #if JUCE_MAC
  27547. if (f.isDirectory() && f.hasFileExtension (".vst"))
  27548. return true;
  27549. #if JUCE_PPC
  27550. FSRef fileRef;
  27551. if (PlatformUtilities::makeFSRefFromPath (&fileRef, f.getFullPathName()))
  27552. {
  27553. const short resFileId = FSOpenResFile (&fileRef, fsRdPerm);
  27554. if (resFileId != -1)
  27555. {
  27556. const int numEffects = Count1Resources ('aEff');
  27557. CloseResFile (resFileId);
  27558. if (numEffects > 0)
  27559. return true;
  27560. }
  27561. }
  27562. #endif
  27563. return false;
  27564. #elif JUCE_WIN32
  27565. return f.existsAsFile()
  27566. && f.hasFileExtension (".dll");
  27567. #elif JUCE_LINUX
  27568. return f.existsAsFile()
  27569. && f.hasFileExtension (".so");
  27570. #endif
  27571. }
  27572. const String VSTPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  27573. {
  27574. return fileOrIdentifier;
  27575. }
  27576. bool VSTPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  27577. {
  27578. return File (desc.fileOrIdentifier).exists();
  27579. }
  27580. const StringArray VSTPluginFormat::searchPathsForPlugins (const FileSearchPath& directoriesToSearch, const bool recursive)
  27581. {
  27582. StringArray results;
  27583. for (int j = 0; j < directoriesToSearch.getNumPaths(); ++j)
  27584. recursiveFileSearch (results, directoriesToSearch [j], recursive);
  27585. return results;
  27586. }
  27587. void VSTPluginFormat::recursiveFileSearch (StringArray& results, const File& dir, const bool recursive)
  27588. {
  27589. // avoid allowing the dir iterator to be recursive, because we want to avoid letting it delve inside
  27590. // .component or .vst directories.
  27591. DirectoryIterator iter (dir, false, "*", File::findFilesAndDirectories);
  27592. while (iter.next())
  27593. {
  27594. const File f (iter.getFile());
  27595. bool isPlugin = false;
  27596. if (fileMightContainThisPluginType (f.getFullPathName()))
  27597. {
  27598. isPlugin = true;
  27599. results.add (f.getFullPathName());
  27600. }
  27601. if (recursive && (! isPlugin) && f.isDirectory())
  27602. recursiveFileSearch (results, f, true);
  27603. }
  27604. }
  27605. const FileSearchPath VSTPluginFormat::getDefaultLocationsToSearch()
  27606. {
  27607. #if JUCE_MAC
  27608. return FileSearchPath ("~/Library/Audio/Plug-Ins/VST;/Library/Audio/Plug-Ins/VST");
  27609. #elif JUCE_WIN32
  27610. const String programFiles (File::getSpecialLocation (File::globalApplicationsDirectory).getFullPathName());
  27611. return FileSearchPath (programFiles + "\\Steinberg\\VstPlugins");
  27612. #elif JUCE_LINUX
  27613. return FileSearchPath ("/usr/lib/vst");
  27614. #endif
  27615. }
  27616. END_JUCE_NAMESPACE
  27617. #endif
  27618. #undef log
  27619. #endif
  27620. /*** End of inlined file: juce_VSTPluginFormat.cpp ***/
  27621. /*** End of inlined file: juce_VSTPluginFormat.mm ***/
  27622. /*** Start of inlined file: juce_AudioProcessor.cpp ***/
  27623. BEGIN_JUCE_NAMESPACE
  27624. AudioProcessor::AudioProcessor()
  27625. : playHead (0),
  27626. activeEditor (0),
  27627. sampleRate (0),
  27628. blockSize (0),
  27629. numInputChannels (0),
  27630. numOutputChannels (0),
  27631. latencySamples (0),
  27632. suspended (false),
  27633. nonRealtime (false)
  27634. {
  27635. }
  27636. AudioProcessor::~AudioProcessor()
  27637. {
  27638. // ooh, nasty - the editor should have been deleted before the filter
  27639. // that it refers to is deleted..
  27640. jassert (activeEditor == 0);
  27641. #ifdef JUCE_DEBUG
  27642. // This will fail if you've called beginParameterChangeGesture() for one
  27643. // or more parameters without having made a corresponding call to endParameterChangeGesture...
  27644. jassert (changingParams.countNumberOfSetBits() == 0);
  27645. #endif
  27646. }
  27647. void AudioProcessor::setPlayHead (AudioPlayHead* const newPlayHead) throw()
  27648. {
  27649. playHead = newPlayHead;
  27650. }
  27651. void AudioProcessor::addListener (AudioProcessorListener* const newListener) throw()
  27652. {
  27653. const ScopedLock sl (listenerLock);
  27654. listeners.addIfNotAlreadyThere (newListener);
  27655. }
  27656. void AudioProcessor::removeListener (AudioProcessorListener* const listenerToRemove) throw()
  27657. {
  27658. const ScopedLock sl (listenerLock);
  27659. listeners.removeValue (listenerToRemove);
  27660. }
  27661. void AudioProcessor::setPlayConfigDetails (const int numIns,
  27662. const int numOuts,
  27663. const double sampleRate_,
  27664. const int blockSize_) throw()
  27665. {
  27666. numInputChannels = numIns;
  27667. numOutputChannels = numOuts;
  27668. sampleRate = sampleRate_;
  27669. blockSize = blockSize_;
  27670. }
  27671. void AudioProcessor::setNonRealtime (const bool nonRealtime_) throw()
  27672. {
  27673. nonRealtime = nonRealtime_;
  27674. }
  27675. void AudioProcessor::setLatencySamples (const int newLatency)
  27676. {
  27677. if (latencySamples != newLatency)
  27678. {
  27679. latencySamples = newLatency;
  27680. updateHostDisplay();
  27681. }
  27682. }
  27683. void AudioProcessor::setParameterNotifyingHost (const int parameterIndex,
  27684. const float newValue)
  27685. {
  27686. setParameter (parameterIndex, newValue);
  27687. sendParamChangeMessageToListeners (parameterIndex, newValue);
  27688. }
  27689. void AudioProcessor::sendParamChangeMessageToListeners (const int parameterIndex, const float newValue)
  27690. {
  27691. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27692. for (int i = listeners.size(); --i >= 0;)
  27693. {
  27694. AudioProcessorListener* l;
  27695. {
  27696. const ScopedLock sl (listenerLock);
  27697. l = (AudioProcessorListener*) listeners [i];
  27698. }
  27699. if (l != 0)
  27700. l->audioProcessorParameterChanged (this, parameterIndex, newValue);
  27701. }
  27702. }
  27703. void AudioProcessor::beginParameterChangeGesture (int parameterIndex)
  27704. {
  27705. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27706. #ifdef JUCE_DEBUG
  27707. // This means you've called beginParameterChangeGesture twice in succession without a matching
  27708. // call to endParameterChangeGesture. That might be fine in most hosts, but better to avoid doing it.
  27709. jassert (! changingParams [parameterIndex]);
  27710. changingParams.setBit (parameterIndex);
  27711. #endif
  27712. for (int i = listeners.size(); --i >= 0;)
  27713. {
  27714. AudioProcessorListener* l;
  27715. {
  27716. const ScopedLock sl (listenerLock);
  27717. l = (AudioProcessorListener*) listeners [i];
  27718. }
  27719. if (l != 0)
  27720. l->audioProcessorParameterChangeGestureBegin (this, parameterIndex);
  27721. }
  27722. }
  27723. void AudioProcessor::endParameterChangeGesture (int parameterIndex)
  27724. {
  27725. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27726. #ifdef JUCE_DEBUG
  27727. // This means you've called endParameterChangeGesture without having previously called
  27728. // endParameterChangeGesture. That might be fine in most hosts, but better to keep the
  27729. // calls matched correctly.
  27730. jassert (changingParams [parameterIndex]);
  27731. changingParams.clearBit (parameterIndex);
  27732. #endif
  27733. for (int i = listeners.size(); --i >= 0;)
  27734. {
  27735. AudioProcessorListener* l;
  27736. {
  27737. const ScopedLock sl (listenerLock);
  27738. l = (AudioProcessorListener*) listeners [i];
  27739. }
  27740. if (l != 0)
  27741. l->audioProcessorParameterChangeGestureEnd (this, parameterIndex);
  27742. }
  27743. }
  27744. void AudioProcessor::updateHostDisplay()
  27745. {
  27746. for (int i = listeners.size(); --i >= 0;)
  27747. {
  27748. AudioProcessorListener* l;
  27749. {
  27750. const ScopedLock sl (listenerLock);
  27751. l = (AudioProcessorListener*) listeners [i];
  27752. }
  27753. if (l != 0)
  27754. l->audioProcessorChanged (this);
  27755. }
  27756. }
  27757. bool AudioProcessor::isParameterAutomatable (int /*parameterIndex*/) const
  27758. {
  27759. return true;
  27760. }
  27761. bool AudioProcessor::isMetaParameter (int /*parameterIndex*/) const
  27762. {
  27763. return false;
  27764. }
  27765. void AudioProcessor::suspendProcessing (const bool shouldBeSuspended)
  27766. {
  27767. const ScopedLock sl (callbackLock);
  27768. suspended = shouldBeSuspended;
  27769. }
  27770. void AudioProcessor::reset()
  27771. {
  27772. }
  27773. void AudioProcessor::editorBeingDeleted (AudioProcessorEditor* const editor) throw()
  27774. {
  27775. const ScopedLock sl (callbackLock);
  27776. jassert (activeEditor == editor);
  27777. if (activeEditor == editor)
  27778. activeEditor = 0;
  27779. }
  27780. AudioProcessorEditor* AudioProcessor::createEditorIfNeeded()
  27781. {
  27782. if (activeEditor != 0)
  27783. return activeEditor;
  27784. AudioProcessorEditor* const ed = createEditor();
  27785. if (ed != 0)
  27786. {
  27787. // you must give your editor comp a size before returning it..
  27788. jassert (ed->getWidth() > 0 && ed->getHeight() > 0);
  27789. const ScopedLock sl (callbackLock);
  27790. activeEditor = ed;
  27791. }
  27792. return ed;
  27793. }
  27794. void AudioProcessor::getCurrentProgramStateInformation (JUCE_NAMESPACE::MemoryBlock& destData)
  27795. {
  27796. getStateInformation (destData);
  27797. }
  27798. void AudioProcessor::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  27799. {
  27800. setStateInformation (data, sizeInBytes);
  27801. }
  27802. // magic number to identify memory blocks that we've stored as XML
  27803. const uint32 magicXmlNumber = 0x21324356;
  27804. void AudioProcessor::copyXmlToBinary (const XmlElement& xml,
  27805. JUCE_NAMESPACE::MemoryBlock& destData)
  27806. {
  27807. const String xmlString (xml.createDocument (String::empty, true, false));
  27808. const int stringLength = xmlString.getNumBytesAsUTF8();
  27809. destData.setSize (stringLength + 10);
  27810. char* const d = (char*) destData.getData();
  27811. *(uint32*) d = ByteOrder::swapIfBigEndian ((const uint32) magicXmlNumber);
  27812. *(uint32*) (d + 4) = ByteOrder::swapIfBigEndian ((const uint32) stringLength);
  27813. xmlString.copyToUTF8 (d + 8, stringLength + 1);
  27814. }
  27815. XmlElement* AudioProcessor::getXmlFromBinary (const void* data,
  27816. const int sizeInBytes)
  27817. {
  27818. if (sizeInBytes > 8
  27819. && ByteOrder::littleEndianInt ((const char*) data) == magicXmlNumber)
  27820. {
  27821. const int stringLength = (int) ByteOrder::littleEndianInt (((const char*) data) + 4);
  27822. if (stringLength > 0)
  27823. {
  27824. XmlDocument doc (String::fromUTF8 (((const char*) data) + 8,
  27825. jmin ((sizeInBytes - 8), stringLength)));
  27826. return doc.getDocumentElement();
  27827. }
  27828. }
  27829. return 0;
  27830. }
  27831. void AudioProcessorListener::audioProcessorParameterChangeGestureBegin (AudioProcessor*, int)
  27832. {
  27833. }
  27834. void AudioProcessorListener::audioProcessorParameterChangeGestureEnd (AudioProcessor*, int)
  27835. {
  27836. }
  27837. END_JUCE_NAMESPACE
  27838. /*** End of inlined file: juce_AudioProcessor.cpp ***/
  27839. /*** Start of inlined file: juce_AudioProcessorEditor.cpp ***/
  27840. BEGIN_JUCE_NAMESPACE
  27841. AudioProcessorEditor::AudioProcessorEditor (AudioProcessor* const owner_)
  27842. : owner (owner_)
  27843. {
  27844. // the filter must be valid..
  27845. jassert (owner != 0);
  27846. }
  27847. AudioProcessorEditor::~AudioProcessorEditor()
  27848. {
  27849. // if this fails, then the wrapper hasn't called editorBeingDeleted() on the
  27850. // filter for some reason..
  27851. jassert (owner->getActiveEditor() != this);
  27852. }
  27853. END_JUCE_NAMESPACE
  27854. /*** End of inlined file: juce_AudioProcessorEditor.cpp ***/
  27855. /*** Start of inlined file: juce_AudioProcessorGraph.cpp ***/
  27856. BEGIN_JUCE_NAMESPACE
  27857. const int AudioProcessorGraph::midiChannelIndex = 0x1000;
  27858. AudioProcessorGraph::Node::Node (const uint32 id_, AudioProcessor* const processor_)
  27859. : id (id_),
  27860. processor (processor_),
  27861. isPrepared (false)
  27862. {
  27863. jassert (processor_ != 0);
  27864. }
  27865. AudioProcessorGraph::Node::~Node()
  27866. {
  27867. delete processor;
  27868. }
  27869. void AudioProcessorGraph::Node::prepare (const double sampleRate, const int blockSize,
  27870. AudioProcessorGraph* const graph)
  27871. {
  27872. if (! isPrepared)
  27873. {
  27874. isPrepared = true;
  27875. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  27876. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (processor);
  27877. if (ioProc != 0)
  27878. ioProc->setParentGraph (graph);
  27879. processor->setPlayConfigDetails (processor->getNumInputChannels(),
  27880. processor->getNumOutputChannels(),
  27881. sampleRate, blockSize);
  27882. processor->prepareToPlay (sampleRate, blockSize);
  27883. }
  27884. }
  27885. void AudioProcessorGraph::Node::unprepare()
  27886. {
  27887. if (isPrepared)
  27888. {
  27889. isPrepared = false;
  27890. processor->releaseResources();
  27891. }
  27892. }
  27893. AudioProcessorGraph::AudioProcessorGraph()
  27894. : lastNodeId (0),
  27895. renderingBuffers (1, 1),
  27896. currentAudioOutputBuffer (1, 1)
  27897. {
  27898. }
  27899. AudioProcessorGraph::~AudioProcessorGraph()
  27900. {
  27901. clearRenderingSequence();
  27902. clear();
  27903. }
  27904. const String AudioProcessorGraph::getName() const
  27905. {
  27906. return "Audio Graph";
  27907. }
  27908. void AudioProcessorGraph::clear()
  27909. {
  27910. nodes.clear();
  27911. connections.clear();
  27912. triggerAsyncUpdate();
  27913. }
  27914. AudioProcessorGraph::Node* AudioProcessorGraph::getNodeForId (const uint32 nodeId) const
  27915. {
  27916. for (int i = nodes.size(); --i >= 0;)
  27917. if (nodes.getUnchecked(i)->id == nodeId)
  27918. return nodes.getUnchecked(i);
  27919. return 0;
  27920. }
  27921. AudioProcessorGraph::Node* AudioProcessorGraph::addNode (AudioProcessor* const newProcessor,
  27922. uint32 nodeId)
  27923. {
  27924. if (newProcessor == 0)
  27925. {
  27926. jassertfalse
  27927. return 0;
  27928. }
  27929. if (nodeId == 0)
  27930. {
  27931. nodeId = ++lastNodeId;
  27932. }
  27933. else
  27934. {
  27935. // you can't add a node with an id that already exists in the graph..
  27936. jassert (getNodeForId (nodeId) == 0);
  27937. removeNode (nodeId);
  27938. }
  27939. lastNodeId = nodeId;
  27940. Node* const n = new Node (nodeId, newProcessor);
  27941. nodes.add (n);
  27942. triggerAsyncUpdate();
  27943. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  27944. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (n->processor);
  27945. if (ioProc != 0)
  27946. ioProc->setParentGraph (this);
  27947. return n;
  27948. }
  27949. bool AudioProcessorGraph::removeNode (const uint32 nodeId)
  27950. {
  27951. disconnectNode (nodeId);
  27952. for (int i = nodes.size(); --i >= 0;)
  27953. {
  27954. if (nodes.getUnchecked(i)->id == nodeId)
  27955. {
  27956. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  27957. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (nodes.getUnchecked(i)->processor);
  27958. if (ioProc != 0)
  27959. ioProc->setParentGraph (0);
  27960. nodes.remove (i);
  27961. triggerAsyncUpdate();
  27962. return true;
  27963. }
  27964. }
  27965. return false;
  27966. }
  27967. const AudioProcessorGraph::Connection* AudioProcessorGraph::getConnectionBetween (const uint32 sourceNodeId,
  27968. const int sourceChannelIndex,
  27969. const uint32 destNodeId,
  27970. const int destChannelIndex) const
  27971. {
  27972. for (int i = connections.size(); --i >= 0;)
  27973. {
  27974. const Connection* const c = connections.getUnchecked(i);
  27975. if (c->sourceNodeId == sourceNodeId
  27976. && c->destNodeId == destNodeId
  27977. && c->sourceChannelIndex == sourceChannelIndex
  27978. && c->destChannelIndex == destChannelIndex)
  27979. {
  27980. return c;
  27981. }
  27982. }
  27983. return 0;
  27984. }
  27985. bool AudioProcessorGraph::isConnected (const uint32 possibleSourceNodeId,
  27986. const uint32 possibleDestNodeId) const
  27987. {
  27988. for (int i = connections.size(); --i >= 0;)
  27989. {
  27990. const Connection* const c = connections.getUnchecked(i);
  27991. if (c->sourceNodeId == possibleSourceNodeId
  27992. && c->destNodeId == possibleDestNodeId)
  27993. {
  27994. return true;
  27995. }
  27996. }
  27997. return false;
  27998. }
  27999. bool AudioProcessorGraph::canConnect (const uint32 sourceNodeId,
  28000. const int sourceChannelIndex,
  28001. const uint32 destNodeId,
  28002. const int destChannelIndex) const
  28003. {
  28004. if (sourceChannelIndex < 0
  28005. || destChannelIndex < 0
  28006. || sourceNodeId == destNodeId
  28007. || (destChannelIndex == midiChannelIndex) != (sourceChannelIndex == midiChannelIndex))
  28008. return false;
  28009. const Node* const source = getNodeForId (sourceNodeId);
  28010. if (source == 0
  28011. || (sourceChannelIndex != midiChannelIndex && sourceChannelIndex >= source->processor->getNumOutputChannels())
  28012. || (sourceChannelIndex == midiChannelIndex && ! source->processor->producesMidi()))
  28013. return false;
  28014. const Node* const dest = getNodeForId (destNodeId);
  28015. if (dest == 0
  28016. || (destChannelIndex != midiChannelIndex && destChannelIndex >= dest->processor->getNumInputChannels())
  28017. || (destChannelIndex == midiChannelIndex && ! dest->processor->acceptsMidi()))
  28018. return false;
  28019. return getConnectionBetween (sourceNodeId, sourceChannelIndex,
  28020. destNodeId, destChannelIndex) == 0;
  28021. }
  28022. bool AudioProcessorGraph::addConnection (const uint32 sourceNodeId,
  28023. const int sourceChannelIndex,
  28024. const uint32 destNodeId,
  28025. const int destChannelIndex)
  28026. {
  28027. if (! canConnect (sourceNodeId, sourceChannelIndex, destNodeId, destChannelIndex))
  28028. return false;
  28029. Connection* const c = new Connection();
  28030. c->sourceNodeId = sourceNodeId;
  28031. c->sourceChannelIndex = sourceChannelIndex;
  28032. c->destNodeId = destNodeId;
  28033. c->destChannelIndex = destChannelIndex;
  28034. connections.add (c);
  28035. triggerAsyncUpdate();
  28036. return true;
  28037. }
  28038. void AudioProcessorGraph::removeConnection (const int index)
  28039. {
  28040. connections.remove (index);
  28041. triggerAsyncUpdate();
  28042. }
  28043. bool AudioProcessorGraph::removeConnection (const uint32 sourceNodeId, const int sourceChannelIndex,
  28044. const uint32 destNodeId, const int destChannelIndex)
  28045. {
  28046. bool doneAnything = false;
  28047. for (int i = connections.size(); --i >= 0;)
  28048. {
  28049. const Connection* const c = connections.getUnchecked(i);
  28050. if (c->sourceNodeId == sourceNodeId
  28051. && c->destNodeId == destNodeId
  28052. && c->sourceChannelIndex == sourceChannelIndex
  28053. && c->destChannelIndex == destChannelIndex)
  28054. {
  28055. removeConnection (i);
  28056. doneAnything = true;
  28057. triggerAsyncUpdate();
  28058. }
  28059. }
  28060. return doneAnything;
  28061. }
  28062. bool AudioProcessorGraph::disconnectNode (const uint32 nodeId)
  28063. {
  28064. bool doneAnything = false;
  28065. for (int i = connections.size(); --i >= 0;)
  28066. {
  28067. const Connection* const c = connections.getUnchecked(i);
  28068. if (c->sourceNodeId == nodeId || c->destNodeId == nodeId)
  28069. {
  28070. removeConnection (i);
  28071. doneAnything = true;
  28072. triggerAsyncUpdate();
  28073. }
  28074. }
  28075. return doneAnything;
  28076. }
  28077. bool AudioProcessorGraph::removeIllegalConnections()
  28078. {
  28079. bool doneAnything = false;
  28080. for (int i = connections.size(); --i >= 0;)
  28081. {
  28082. const Connection* const c = connections.getUnchecked(i);
  28083. const Node* const source = getNodeForId (c->sourceNodeId);
  28084. const Node* const dest = getNodeForId (c->destNodeId);
  28085. if (source == 0 || dest == 0
  28086. || (c->sourceChannelIndex != midiChannelIndex
  28087. && (((unsigned int) c->sourceChannelIndex) >= (unsigned int) source->processor->getNumOutputChannels()))
  28088. || (c->sourceChannelIndex == midiChannelIndex
  28089. && ! source->processor->producesMidi())
  28090. || (c->destChannelIndex != midiChannelIndex
  28091. && (((unsigned int) c->destChannelIndex) >= (unsigned int) dest->processor->getNumInputChannels()))
  28092. || (c->destChannelIndex == midiChannelIndex
  28093. && ! dest->processor->acceptsMidi()))
  28094. {
  28095. removeConnection (i);
  28096. doneAnything = true;
  28097. triggerAsyncUpdate();
  28098. }
  28099. }
  28100. return doneAnything;
  28101. }
  28102. namespace GraphRenderingOps
  28103. {
  28104. class AudioGraphRenderingOp
  28105. {
  28106. public:
  28107. AudioGraphRenderingOp() {}
  28108. virtual ~AudioGraphRenderingOp() {}
  28109. virtual void perform (AudioSampleBuffer& sharedBufferChans,
  28110. const OwnedArray <MidiBuffer>& sharedMidiBuffers,
  28111. const int numSamples) = 0;
  28112. juce_UseDebuggingNewOperator
  28113. };
  28114. class ClearChannelOp : public AudioGraphRenderingOp
  28115. {
  28116. public:
  28117. ClearChannelOp (const int channelNum_)
  28118. : channelNum (channelNum_)
  28119. {}
  28120. ~ClearChannelOp() {}
  28121. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28122. {
  28123. sharedBufferChans.clear (channelNum, 0, numSamples);
  28124. }
  28125. private:
  28126. const int channelNum;
  28127. ClearChannelOp (const ClearChannelOp&);
  28128. ClearChannelOp& operator= (const ClearChannelOp&);
  28129. };
  28130. class CopyChannelOp : public AudioGraphRenderingOp
  28131. {
  28132. public:
  28133. CopyChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28134. : srcChannelNum (srcChannelNum_),
  28135. dstChannelNum (dstChannelNum_)
  28136. {}
  28137. ~CopyChannelOp() {}
  28138. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28139. {
  28140. sharedBufferChans.copyFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28141. }
  28142. private:
  28143. const int srcChannelNum, dstChannelNum;
  28144. CopyChannelOp (const CopyChannelOp&);
  28145. CopyChannelOp& operator= (const CopyChannelOp&);
  28146. };
  28147. class AddChannelOp : public AudioGraphRenderingOp
  28148. {
  28149. public:
  28150. AddChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28151. : srcChannelNum (srcChannelNum_),
  28152. dstChannelNum (dstChannelNum_)
  28153. {}
  28154. ~AddChannelOp() {}
  28155. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28156. {
  28157. sharedBufferChans.addFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28158. }
  28159. private:
  28160. const int srcChannelNum, dstChannelNum;
  28161. AddChannelOp (const AddChannelOp&);
  28162. AddChannelOp& operator= (const AddChannelOp&);
  28163. };
  28164. class ClearMidiBufferOp : public AudioGraphRenderingOp
  28165. {
  28166. public:
  28167. ClearMidiBufferOp (const int bufferNum_)
  28168. : bufferNum (bufferNum_)
  28169. {}
  28170. ~ClearMidiBufferOp() {}
  28171. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28172. {
  28173. sharedMidiBuffers.getUnchecked (bufferNum)->clear();
  28174. }
  28175. private:
  28176. const int bufferNum;
  28177. ClearMidiBufferOp (const ClearMidiBufferOp&);
  28178. ClearMidiBufferOp& operator= (const ClearMidiBufferOp&);
  28179. };
  28180. class CopyMidiBufferOp : public AudioGraphRenderingOp
  28181. {
  28182. public:
  28183. CopyMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28184. : srcBufferNum (srcBufferNum_),
  28185. dstBufferNum (dstBufferNum_)
  28186. {}
  28187. ~CopyMidiBufferOp() {}
  28188. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28189. {
  28190. *sharedMidiBuffers.getUnchecked (dstBufferNum) = *sharedMidiBuffers.getUnchecked (srcBufferNum);
  28191. }
  28192. private:
  28193. const int srcBufferNum, dstBufferNum;
  28194. CopyMidiBufferOp (const CopyMidiBufferOp&);
  28195. CopyMidiBufferOp& operator= (const CopyMidiBufferOp&);
  28196. };
  28197. class AddMidiBufferOp : public AudioGraphRenderingOp
  28198. {
  28199. public:
  28200. AddMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28201. : srcBufferNum (srcBufferNum_),
  28202. dstBufferNum (dstBufferNum_)
  28203. {}
  28204. ~AddMidiBufferOp() {}
  28205. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28206. {
  28207. sharedMidiBuffers.getUnchecked (dstBufferNum)
  28208. ->addEvents (*sharedMidiBuffers.getUnchecked (srcBufferNum), 0, numSamples, 0);
  28209. }
  28210. private:
  28211. const int srcBufferNum, dstBufferNum;
  28212. AddMidiBufferOp (const AddMidiBufferOp&);
  28213. AddMidiBufferOp& operator= (const AddMidiBufferOp&);
  28214. };
  28215. class ProcessBufferOp : public AudioGraphRenderingOp
  28216. {
  28217. public:
  28218. ProcessBufferOp (const AudioProcessorGraph::Node::Ptr& node_,
  28219. const Array <int>& audioChannelsToUse_,
  28220. const int totalChans_,
  28221. const int midiBufferToUse_)
  28222. : node (node_),
  28223. processor (node_->processor),
  28224. audioChannelsToUse (audioChannelsToUse_),
  28225. totalChans (jmax (1, totalChans_)),
  28226. midiBufferToUse (midiBufferToUse_)
  28227. {
  28228. channels.calloc (totalChans);
  28229. while (audioChannelsToUse.size() < totalChans)
  28230. audioChannelsToUse.add (0);
  28231. }
  28232. ~ProcessBufferOp()
  28233. {
  28234. }
  28235. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28236. {
  28237. for (int i = totalChans; --i >= 0;)
  28238. channels[i] = sharedBufferChans.getSampleData (audioChannelsToUse.getUnchecked (i), 0);
  28239. AudioSampleBuffer buffer (channels, totalChans, numSamples);
  28240. processor->processBlock (buffer, *sharedMidiBuffers.getUnchecked (midiBufferToUse));
  28241. }
  28242. const AudioProcessorGraph::Node::Ptr node;
  28243. AudioProcessor* const processor;
  28244. private:
  28245. Array <int> audioChannelsToUse;
  28246. HeapBlock <float*> channels;
  28247. int totalChans;
  28248. int midiBufferToUse;
  28249. ProcessBufferOp (const ProcessBufferOp&);
  28250. ProcessBufferOp& operator= (const ProcessBufferOp&);
  28251. };
  28252. class RenderingOpSequenceCalculator
  28253. {
  28254. public:
  28255. RenderingOpSequenceCalculator (AudioProcessorGraph& graph_,
  28256. const VoidArray& orderedNodes_,
  28257. VoidArray& renderingOps)
  28258. : graph (graph_),
  28259. orderedNodes (orderedNodes_)
  28260. {
  28261. nodeIds.add (-2); // first buffer is read-only zeros
  28262. channels.add (0);
  28263. midiNodeIds.add (-2);
  28264. for (int i = 0; i < orderedNodes.size(); ++i)
  28265. {
  28266. createRenderingOpsForNode ((AudioProcessorGraph::Node*) orderedNodes.getUnchecked(i),
  28267. renderingOps, i);
  28268. markAnyUnusedBuffersAsFree (i);
  28269. }
  28270. }
  28271. int getNumBuffersNeeded() const { return nodeIds.size(); }
  28272. int getNumMidiBuffersNeeded() const { return midiNodeIds.size(); }
  28273. juce_UseDebuggingNewOperator
  28274. private:
  28275. AudioProcessorGraph& graph;
  28276. const VoidArray& orderedNodes;
  28277. Array <int> nodeIds, channels, midiNodeIds;
  28278. void createRenderingOpsForNode (AudioProcessorGraph::Node* const node,
  28279. VoidArray& renderingOps,
  28280. const int ourRenderingIndex)
  28281. {
  28282. const int numIns = node->processor->getNumInputChannels();
  28283. const int numOuts = node->processor->getNumOutputChannels();
  28284. const int totalChans = jmax (numIns, numOuts);
  28285. Array <int> audioChannelsToUse;
  28286. int midiBufferToUse = -1;
  28287. for (int inputChan = 0; inputChan < numIns; ++inputChan)
  28288. {
  28289. // get a list of all the inputs to this node
  28290. Array <int> sourceNodes, sourceOutputChans;
  28291. for (int i = graph.getNumConnections(); --i >= 0;)
  28292. {
  28293. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28294. if (c->destNodeId == node->id && c->destChannelIndex == inputChan)
  28295. {
  28296. sourceNodes.add (c->sourceNodeId);
  28297. sourceOutputChans.add (c->sourceChannelIndex);
  28298. }
  28299. }
  28300. int bufIndex = -1;
  28301. if (sourceNodes.size() == 0)
  28302. {
  28303. // unconnected input channel
  28304. if (inputChan >= numOuts)
  28305. {
  28306. bufIndex = getReadOnlyEmptyBuffer();
  28307. jassert (bufIndex >= 0);
  28308. }
  28309. else
  28310. {
  28311. bufIndex = getFreeBuffer (false);
  28312. renderingOps.add (new ClearChannelOp (bufIndex));
  28313. }
  28314. }
  28315. else if (sourceNodes.size() == 1)
  28316. {
  28317. // channel with a straightforward single input..
  28318. const int srcNode = sourceNodes.getUnchecked(0);
  28319. const int srcChan = sourceOutputChans.getUnchecked(0);
  28320. bufIndex = getBufferContaining (srcNode, srcChan);
  28321. if (bufIndex < 0)
  28322. {
  28323. // if not found, this is probably a feedback loop
  28324. bufIndex = getReadOnlyEmptyBuffer();
  28325. jassert (bufIndex >= 0);
  28326. }
  28327. if (inputChan < numOuts
  28328. && isBufferNeededLater (ourRenderingIndex,
  28329. inputChan,
  28330. srcNode, srcChan))
  28331. {
  28332. // can't mess up this channel because it's needed later by another node, so we
  28333. // need to use a copy of it..
  28334. const int newFreeBuffer = getFreeBuffer (false);
  28335. renderingOps.add (new CopyChannelOp (bufIndex, newFreeBuffer));
  28336. bufIndex = newFreeBuffer;
  28337. }
  28338. }
  28339. else
  28340. {
  28341. // channel with a mix of several inputs..
  28342. // try to find a re-usable channel from our inputs..
  28343. int reusableInputIndex = -1;
  28344. for (int i = 0; i < sourceNodes.size(); ++i)
  28345. {
  28346. const int sourceBufIndex = getBufferContaining (sourceNodes.getUnchecked(i),
  28347. sourceOutputChans.getUnchecked(i));
  28348. if (sourceBufIndex >= 0
  28349. && ! isBufferNeededLater (ourRenderingIndex,
  28350. inputChan,
  28351. sourceNodes.getUnchecked(i),
  28352. sourceOutputChans.getUnchecked(i)))
  28353. {
  28354. // we've found one of our input chans that can be re-used..
  28355. reusableInputIndex = i;
  28356. bufIndex = sourceBufIndex;
  28357. break;
  28358. }
  28359. }
  28360. if (reusableInputIndex < 0)
  28361. {
  28362. // can't re-use any of our input chans, so get a new one and copy everything into it..
  28363. bufIndex = getFreeBuffer (false);
  28364. jassert (bufIndex != 0);
  28365. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked (0),
  28366. sourceOutputChans.getUnchecked (0));
  28367. if (srcIndex < 0)
  28368. {
  28369. // if not found, this is probably a feedback loop
  28370. renderingOps.add (new ClearChannelOp (bufIndex));
  28371. }
  28372. else
  28373. {
  28374. renderingOps.add (new CopyChannelOp (srcIndex, bufIndex));
  28375. }
  28376. reusableInputIndex = 0;
  28377. }
  28378. for (int j = 0; j < sourceNodes.size(); ++j)
  28379. {
  28380. if (j != reusableInputIndex)
  28381. {
  28382. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked(j),
  28383. sourceOutputChans.getUnchecked(j));
  28384. if (srcIndex >= 0)
  28385. renderingOps.add (new AddChannelOp (srcIndex, bufIndex));
  28386. }
  28387. }
  28388. }
  28389. jassert (bufIndex >= 0);
  28390. audioChannelsToUse.add (bufIndex);
  28391. if (inputChan < numOuts)
  28392. markBufferAsContaining (bufIndex, node->id, inputChan);
  28393. }
  28394. for (int outputChan = numIns; outputChan < numOuts; ++outputChan)
  28395. {
  28396. const int bufIndex = getFreeBuffer (false);
  28397. jassert (bufIndex != 0);
  28398. audioChannelsToUse.add (bufIndex);
  28399. markBufferAsContaining (bufIndex, node->id, outputChan);
  28400. }
  28401. // Now the same thing for midi..
  28402. Array <int> midiSourceNodes;
  28403. for (int i = graph.getNumConnections(); --i >= 0;)
  28404. {
  28405. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28406. if (c->destNodeId == node->id && c->destChannelIndex == AudioProcessorGraph::midiChannelIndex)
  28407. midiSourceNodes.add (c->sourceNodeId);
  28408. }
  28409. if (midiSourceNodes.size() == 0)
  28410. {
  28411. // No midi inputs..
  28412. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28413. if (node->processor->acceptsMidi() || node->processor->producesMidi())
  28414. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28415. }
  28416. else if (midiSourceNodes.size() == 1)
  28417. {
  28418. // One midi input..
  28419. midiBufferToUse = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28420. AudioProcessorGraph::midiChannelIndex);
  28421. if (midiBufferToUse >= 0)
  28422. {
  28423. if (isBufferNeededLater (ourRenderingIndex,
  28424. AudioProcessorGraph::midiChannelIndex,
  28425. midiSourceNodes.getUnchecked(0),
  28426. AudioProcessorGraph::midiChannelIndex))
  28427. {
  28428. // can't mess up this channel because it's needed later by another node, so we
  28429. // need to use a copy of it..
  28430. const int newFreeBuffer = getFreeBuffer (true);
  28431. renderingOps.add (new CopyMidiBufferOp (midiBufferToUse, newFreeBuffer));
  28432. midiBufferToUse = newFreeBuffer;
  28433. }
  28434. }
  28435. else
  28436. {
  28437. // probably a feedback loop, so just use an empty one..
  28438. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28439. }
  28440. }
  28441. else
  28442. {
  28443. // More than one midi input being mixed..
  28444. int reusableInputIndex = -1;
  28445. for (int i = 0; i < midiSourceNodes.size(); ++i)
  28446. {
  28447. const int sourceBufIndex = getBufferContaining (midiSourceNodes.getUnchecked(i),
  28448. AudioProcessorGraph::midiChannelIndex);
  28449. if (sourceBufIndex >= 0
  28450. && ! isBufferNeededLater (ourRenderingIndex,
  28451. AudioProcessorGraph::midiChannelIndex,
  28452. midiSourceNodes.getUnchecked(i),
  28453. AudioProcessorGraph::midiChannelIndex))
  28454. {
  28455. // we've found one of our input buffers that can be re-used..
  28456. reusableInputIndex = i;
  28457. midiBufferToUse = sourceBufIndex;
  28458. break;
  28459. }
  28460. }
  28461. if (reusableInputIndex < 0)
  28462. {
  28463. // can't re-use any of our input buffers, so get a new one and copy everything into it..
  28464. midiBufferToUse = getFreeBuffer (true);
  28465. jassert (midiBufferToUse >= 0);
  28466. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28467. AudioProcessorGraph::midiChannelIndex);
  28468. if (srcIndex >= 0)
  28469. renderingOps.add (new CopyMidiBufferOp (srcIndex, midiBufferToUse));
  28470. else
  28471. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28472. reusableInputIndex = 0;
  28473. }
  28474. for (int j = 0; j < midiSourceNodes.size(); ++j)
  28475. {
  28476. if (j != reusableInputIndex)
  28477. {
  28478. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(j),
  28479. AudioProcessorGraph::midiChannelIndex);
  28480. if (srcIndex >= 0)
  28481. renderingOps.add (new AddMidiBufferOp (srcIndex, midiBufferToUse));
  28482. }
  28483. }
  28484. }
  28485. if (node->processor->producesMidi())
  28486. markBufferAsContaining (midiBufferToUse, node->id,
  28487. AudioProcessorGraph::midiChannelIndex);
  28488. renderingOps.add (new ProcessBufferOp (node, audioChannelsToUse,
  28489. totalChans, midiBufferToUse));
  28490. }
  28491. int getFreeBuffer (const bool forMidi)
  28492. {
  28493. if (forMidi)
  28494. {
  28495. for (int i = 1; i < midiNodeIds.size(); ++i)
  28496. if (midiNodeIds.getUnchecked(i) < 0)
  28497. return i;
  28498. midiNodeIds.add (-1);
  28499. return midiNodeIds.size() - 1;
  28500. }
  28501. else
  28502. {
  28503. for (int i = 1; i < nodeIds.size(); ++i)
  28504. if (nodeIds.getUnchecked(i) < 0)
  28505. return i;
  28506. nodeIds.add (-1);
  28507. channels.add (0);
  28508. return nodeIds.size() - 1;
  28509. }
  28510. }
  28511. int getReadOnlyEmptyBuffer() const
  28512. {
  28513. return 0;
  28514. }
  28515. int getBufferContaining (const int nodeId, const int outputChannel) const
  28516. {
  28517. if (outputChannel == AudioProcessorGraph::midiChannelIndex)
  28518. {
  28519. for (int i = midiNodeIds.size(); --i >= 0;)
  28520. if (midiNodeIds.getUnchecked(i) == nodeId)
  28521. return i;
  28522. }
  28523. else
  28524. {
  28525. for (int i = nodeIds.size(); --i >= 0;)
  28526. if (nodeIds.getUnchecked(i) == nodeId
  28527. && channels.getUnchecked(i) == outputChannel)
  28528. return i;
  28529. }
  28530. return -1;
  28531. }
  28532. void markAnyUnusedBuffersAsFree (const int stepIndex)
  28533. {
  28534. int i;
  28535. for (i = 0; i < nodeIds.size(); ++i)
  28536. {
  28537. if (nodeIds.getUnchecked(i) >= 0
  28538. && ! isBufferNeededLater (stepIndex, -1,
  28539. nodeIds.getUnchecked(i),
  28540. channels.getUnchecked(i)))
  28541. {
  28542. nodeIds.set (i, -1);
  28543. }
  28544. }
  28545. for (i = 0; i < midiNodeIds.size(); ++i)
  28546. {
  28547. if (midiNodeIds.getUnchecked(i) >= 0
  28548. && ! isBufferNeededLater (stepIndex, -1,
  28549. midiNodeIds.getUnchecked(i),
  28550. AudioProcessorGraph::midiChannelIndex))
  28551. {
  28552. midiNodeIds.set (i, -1);
  28553. }
  28554. }
  28555. }
  28556. bool isBufferNeededLater (int stepIndexToSearchFrom,
  28557. int inputChannelOfIndexToIgnore,
  28558. const int nodeId,
  28559. const int outputChanIndex) const
  28560. {
  28561. while (stepIndexToSearchFrom < orderedNodes.size())
  28562. {
  28563. const AudioProcessorGraph::Node* const node = (const AudioProcessorGraph::Node*) orderedNodes.getUnchecked (stepIndexToSearchFrom);
  28564. if (outputChanIndex == AudioProcessorGraph::midiChannelIndex)
  28565. {
  28566. if (inputChannelOfIndexToIgnore != AudioProcessorGraph::midiChannelIndex
  28567. && graph.getConnectionBetween (nodeId, AudioProcessorGraph::midiChannelIndex,
  28568. node->id, AudioProcessorGraph::midiChannelIndex) != 0)
  28569. return true;
  28570. }
  28571. else
  28572. {
  28573. for (int i = 0; i < node->processor->getNumInputChannels(); ++i)
  28574. if (i != inputChannelOfIndexToIgnore
  28575. && graph.getConnectionBetween (nodeId, outputChanIndex,
  28576. node->id, i) != 0)
  28577. return true;
  28578. }
  28579. inputChannelOfIndexToIgnore = -1;
  28580. ++stepIndexToSearchFrom;
  28581. }
  28582. return false;
  28583. }
  28584. void markBufferAsContaining (int bufferNum, int nodeId, int outputIndex)
  28585. {
  28586. if (outputIndex == AudioProcessorGraph::midiChannelIndex)
  28587. {
  28588. jassert (bufferNum > 0 && bufferNum < midiNodeIds.size());
  28589. midiNodeIds.set (bufferNum, nodeId);
  28590. }
  28591. else
  28592. {
  28593. jassert (bufferNum >= 0 && bufferNum < nodeIds.size());
  28594. nodeIds.set (bufferNum, nodeId);
  28595. channels.set (bufferNum, outputIndex);
  28596. }
  28597. }
  28598. RenderingOpSequenceCalculator (const RenderingOpSequenceCalculator&);
  28599. RenderingOpSequenceCalculator& operator= (const RenderingOpSequenceCalculator&);
  28600. };
  28601. }
  28602. void AudioProcessorGraph::clearRenderingSequence()
  28603. {
  28604. const ScopedLock sl (renderLock);
  28605. for (int i = renderingOps.size(); --i >= 0;)
  28606. {
  28607. GraphRenderingOps::AudioGraphRenderingOp* const r
  28608. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28609. renderingOps.remove (i);
  28610. delete r;
  28611. }
  28612. }
  28613. bool AudioProcessorGraph::isAnInputTo (const uint32 possibleInputId,
  28614. const uint32 possibleDestinationId,
  28615. const int recursionCheck) const
  28616. {
  28617. if (recursionCheck > 0)
  28618. {
  28619. for (int i = connections.size(); --i >= 0;)
  28620. {
  28621. const AudioProcessorGraph::Connection* const c = connections.getUnchecked (i);
  28622. if (c->destNodeId == possibleDestinationId
  28623. && (c->sourceNodeId == possibleInputId
  28624. || isAnInputTo (possibleInputId, c->sourceNodeId, recursionCheck - 1)))
  28625. return true;
  28626. }
  28627. }
  28628. return false;
  28629. }
  28630. void AudioProcessorGraph::buildRenderingSequence()
  28631. {
  28632. VoidArray newRenderingOps;
  28633. int numRenderingBuffersNeeded = 2;
  28634. int numMidiBuffersNeeded = 1;
  28635. {
  28636. MessageManagerLock mml;
  28637. VoidArray orderedNodes;
  28638. int i;
  28639. for (i = 0; i < nodes.size(); ++i)
  28640. {
  28641. Node* const node = nodes.getUnchecked(i);
  28642. node->prepare (getSampleRate(), getBlockSize(), this);
  28643. int j = 0;
  28644. for (; j < orderedNodes.size(); ++j)
  28645. if (isAnInputTo (node->id,
  28646. ((Node*) orderedNodes.getUnchecked (j))->id,
  28647. nodes.size() + 1))
  28648. break;
  28649. orderedNodes.insert (j, node);
  28650. }
  28651. GraphRenderingOps::RenderingOpSequenceCalculator calculator (*this, orderedNodes, newRenderingOps);
  28652. numRenderingBuffersNeeded = calculator.getNumBuffersNeeded();
  28653. numMidiBuffersNeeded = calculator.getNumMidiBuffersNeeded();
  28654. }
  28655. VoidArray oldRenderingOps (renderingOps);
  28656. {
  28657. // swap over to the new rendering sequence..
  28658. const ScopedLock sl (renderLock);
  28659. renderingBuffers.setSize (numRenderingBuffersNeeded, getBlockSize());
  28660. renderingBuffers.clear();
  28661. for (int i = midiBuffers.size(); --i >= 0;)
  28662. midiBuffers.getUnchecked(i)->clear();
  28663. while (midiBuffers.size() < numMidiBuffersNeeded)
  28664. midiBuffers.add (new MidiBuffer());
  28665. renderingOps = newRenderingOps;
  28666. }
  28667. for (int i = oldRenderingOps.size(); --i >= 0;)
  28668. delete (GraphRenderingOps::AudioGraphRenderingOp*) oldRenderingOps.getUnchecked(i);
  28669. }
  28670. void AudioProcessorGraph::handleAsyncUpdate()
  28671. {
  28672. buildRenderingSequence();
  28673. }
  28674. void AudioProcessorGraph::prepareToPlay (double /*sampleRate*/, int estimatedSamplesPerBlock)
  28675. {
  28676. currentAudioInputBuffer = 0;
  28677. currentAudioOutputBuffer.setSize (jmax (1, getNumOutputChannels()), estimatedSamplesPerBlock);
  28678. currentMidiInputBuffer = 0;
  28679. currentMidiOutputBuffer.clear();
  28680. clearRenderingSequence();
  28681. buildRenderingSequence();
  28682. }
  28683. void AudioProcessorGraph::releaseResources()
  28684. {
  28685. for (int i = 0; i < nodes.size(); ++i)
  28686. nodes.getUnchecked(i)->unprepare();
  28687. renderingBuffers.setSize (1, 1);
  28688. midiBuffers.clear();
  28689. currentAudioInputBuffer = 0;
  28690. currentAudioOutputBuffer.setSize (1, 1);
  28691. currentMidiInputBuffer = 0;
  28692. currentMidiOutputBuffer.clear();
  28693. }
  28694. void AudioProcessorGraph::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
  28695. {
  28696. const int numSamples = buffer.getNumSamples();
  28697. const ScopedLock sl (renderLock);
  28698. currentAudioInputBuffer = &buffer;
  28699. currentAudioOutputBuffer.setSize (jmax (1, buffer.getNumChannels()), numSamples);
  28700. currentAudioOutputBuffer.clear();
  28701. currentMidiInputBuffer = &midiMessages;
  28702. currentMidiOutputBuffer.clear();
  28703. int i;
  28704. for (i = 0; i < renderingOps.size(); ++i)
  28705. {
  28706. GraphRenderingOps::AudioGraphRenderingOp* const op
  28707. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28708. op->perform (renderingBuffers, midiBuffers, numSamples);
  28709. }
  28710. for (i = 0; i < buffer.getNumChannels(); ++i)
  28711. buffer.copyFrom (i, 0, currentAudioOutputBuffer, i, 0, numSamples);
  28712. midiMessages.clear();
  28713. midiMessages.addEvents (currentMidiOutputBuffer, 0, buffer.getNumSamples(), 0);
  28714. }
  28715. const String AudioProcessorGraph::getInputChannelName (const int channelIndex) const
  28716. {
  28717. return "Input " + String (channelIndex + 1);
  28718. }
  28719. const String AudioProcessorGraph::getOutputChannelName (const int channelIndex) const
  28720. {
  28721. return "Output " + String (channelIndex + 1);
  28722. }
  28723. bool AudioProcessorGraph::isInputChannelStereoPair (int /*index*/) const
  28724. {
  28725. return true;
  28726. }
  28727. bool AudioProcessorGraph::isOutputChannelStereoPair (int /*index*/) const
  28728. {
  28729. return true;
  28730. }
  28731. bool AudioProcessorGraph::acceptsMidi() const
  28732. {
  28733. return true;
  28734. }
  28735. bool AudioProcessorGraph::producesMidi() const
  28736. {
  28737. return true;
  28738. }
  28739. void AudioProcessorGraph::getStateInformation (JUCE_NAMESPACE::MemoryBlock& /*destData*/)
  28740. {
  28741. }
  28742. void AudioProcessorGraph::setStateInformation (const void* /*data*/, int /*sizeInBytes*/)
  28743. {
  28744. }
  28745. AudioProcessorGraph::AudioGraphIOProcessor::AudioGraphIOProcessor (const IODeviceType type_)
  28746. : type (type_),
  28747. graph (0)
  28748. {
  28749. }
  28750. AudioProcessorGraph::AudioGraphIOProcessor::~AudioGraphIOProcessor()
  28751. {
  28752. }
  28753. const String AudioProcessorGraph::AudioGraphIOProcessor::getName() const
  28754. {
  28755. switch (type)
  28756. {
  28757. case audioOutputNode:
  28758. return "Audio Output";
  28759. case audioInputNode:
  28760. return "Audio Input";
  28761. case midiOutputNode:
  28762. return "Midi Output";
  28763. case midiInputNode:
  28764. return "Midi Input";
  28765. default:
  28766. break;
  28767. }
  28768. return String::empty;
  28769. }
  28770. void AudioProcessorGraph::AudioGraphIOProcessor::fillInPluginDescription (PluginDescription& d) const
  28771. {
  28772. d.name = getName();
  28773. d.uid = d.name.hashCode();
  28774. d.category = "I/O devices";
  28775. d.pluginFormatName = "Internal";
  28776. d.manufacturerName = "Raw Material Software";
  28777. d.version = "1.0";
  28778. d.isInstrument = false;
  28779. d.numInputChannels = getNumInputChannels();
  28780. if (type == audioOutputNode && graph != 0)
  28781. d.numInputChannels = graph->getNumInputChannels();
  28782. d.numOutputChannels = getNumOutputChannels();
  28783. if (type == audioInputNode && graph != 0)
  28784. d.numOutputChannels = graph->getNumOutputChannels();
  28785. }
  28786. void AudioProcessorGraph::AudioGraphIOProcessor::prepareToPlay (double, int)
  28787. {
  28788. jassert (graph != 0);
  28789. }
  28790. void AudioProcessorGraph::AudioGraphIOProcessor::releaseResources()
  28791. {
  28792. }
  28793. void AudioProcessorGraph::AudioGraphIOProcessor::processBlock (AudioSampleBuffer& buffer,
  28794. MidiBuffer& midiMessages)
  28795. {
  28796. jassert (graph != 0);
  28797. switch (type)
  28798. {
  28799. case audioOutputNode:
  28800. {
  28801. for (int i = jmin (graph->currentAudioOutputBuffer.getNumChannels(),
  28802. buffer.getNumChannels()); --i >= 0;)
  28803. {
  28804. graph->currentAudioOutputBuffer.addFrom (i, 0, buffer, i, 0, buffer.getNumSamples());
  28805. }
  28806. break;
  28807. }
  28808. case audioInputNode:
  28809. {
  28810. for (int i = jmin (graph->currentAudioInputBuffer->getNumChannels(),
  28811. buffer.getNumChannels()); --i >= 0;)
  28812. {
  28813. buffer.copyFrom (i, 0, *graph->currentAudioInputBuffer, i, 0, buffer.getNumSamples());
  28814. }
  28815. break;
  28816. }
  28817. case midiOutputNode:
  28818. graph->currentMidiOutputBuffer.addEvents (midiMessages, 0, buffer.getNumSamples(), 0);
  28819. break;
  28820. case midiInputNode:
  28821. midiMessages.addEvents (*graph->currentMidiInputBuffer, 0, buffer.getNumSamples(), 0);
  28822. break;
  28823. default:
  28824. break;
  28825. }
  28826. }
  28827. bool AudioProcessorGraph::AudioGraphIOProcessor::acceptsMidi() const
  28828. {
  28829. return type == midiOutputNode;
  28830. }
  28831. bool AudioProcessorGraph::AudioGraphIOProcessor::producesMidi() const
  28832. {
  28833. return type == midiInputNode;
  28834. }
  28835. const String AudioProcessorGraph::AudioGraphIOProcessor::getInputChannelName (const int channelIndex) const
  28836. {
  28837. switch (type)
  28838. {
  28839. case audioOutputNode:
  28840. return "Output " + String (channelIndex + 1);
  28841. case midiOutputNode:
  28842. return "Midi Output";
  28843. default:
  28844. break;
  28845. }
  28846. return String::empty;
  28847. }
  28848. const String AudioProcessorGraph::AudioGraphIOProcessor::getOutputChannelName (const int channelIndex) const
  28849. {
  28850. switch (type)
  28851. {
  28852. case audioInputNode:
  28853. return "Input " + String (channelIndex + 1);
  28854. case midiInputNode:
  28855. return "Midi Input";
  28856. default:
  28857. break;
  28858. }
  28859. return String::empty;
  28860. }
  28861. bool AudioProcessorGraph::AudioGraphIOProcessor::isInputChannelStereoPair (int /*index*/) const
  28862. {
  28863. return type == audioInputNode || type == audioOutputNode;
  28864. }
  28865. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutputChannelStereoPair (int index) const
  28866. {
  28867. return isInputChannelStereoPair (index);
  28868. }
  28869. bool AudioProcessorGraph::AudioGraphIOProcessor::isInput() const
  28870. {
  28871. return type == audioInputNode || type == midiInputNode;
  28872. }
  28873. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutput() const
  28874. {
  28875. return type == audioOutputNode || type == midiOutputNode;
  28876. }
  28877. AudioProcessorEditor* AudioProcessorGraph::AudioGraphIOProcessor::createEditor()
  28878. {
  28879. return 0;
  28880. }
  28881. int AudioProcessorGraph::AudioGraphIOProcessor::getNumParameters() { return 0; }
  28882. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterName (int) { return String::empty; }
  28883. float AudioProcessorGraph::AudioGraphIOProcessor::getParameter (int) { return 0.0f; }
  28884. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterText (int) { return String::empty; }
  28885. void AudioProcessorGraph::AudioGraphIOProcessor::setParameter (int, float) { }
  28886. int AudioProcessorGraph::AudioGraphIOProcessor::getNumPrograms() { return 0; }
  28887. int AudioProcessorGraph::AudioGraphIOProcessor::getCurrentProgram() { return 0; }
  28888. void AudioProcessorGraph::AudioGraphIOProcessor::setCurrentProgram (int) { }
  28889. const String AudioProcessorGraph::AudioGraphIOProcessor::getProgramName (int) { return String::empty; }
  28890. void AudioProcessorGraph::AudioGraphIOProcessor::changeProgramName (int, const String&) { }
  28891. void AudioProcessorGraph::AudioGraphIOProcessor::getStateInformation (JUCE_NAMESPACE::MemoryBlock&)
  28892. {
  28893. }
  28894. void AudioProcessorGraph::AudioGraphIOProcessor::setStateInformation (const void*, int)
  28895. {
  28896. }
  28897. void AudioProcessorGraph::AudioGraphIOProcessor::setParentGraph (AudioProcessorGraph* const newGraph)
  28898. {
  28899. graph = newGraph;
  28900. if (graph != 0)
  28901. {
  28902. setPlayConfigDetails (type == audioOutputNode ? graph->getNumOutputChannels() : 0,
  28903. type == audioInputNode ? graph->getNumInputChannels() : 0,
  28904. getSampleRate(),
  28905. getBlockSize());
  28906. updateHostDisplay();
  28907. }
  28908. }
  28909. END_JUCE_NAMESPACE
  28910. /*** End of inlined file: juce_AudioProcessorGraph.cpp ***/
  28911. /*** Start of inlined file: juce_AudioProcessorPlayer.cpp ***/
  28912. BEGIN_JUCE_NAMESPACE
  28913. AudioProcessorPlayer::AudioProcessorPlayer()
  28914. : processor (0),
  28915. sampleRate (0),
  28916. blockSize (0),
  28917. isPrepared (false),
  28918. numInputChans (0),
  28919. numOutputChans (0),
  28920. tempBuffer (1, 1)
  28921. {
  28922. }
  28923. AudioProcessorPlayer::~AudioProcessorPlayer()
  28924. {
  28925. setProcessor (0);
  28926. }
  28927. void AudioProcessorPlayer::setProcessor (AudioProcessor* const processorToPlay)
  28928. {
  28929. if (processor != processorToPlay)
  28930. {
  28931. if (processorToPlay != 0 && sampleRate > 0 && blockSize > 0)
  28932. {
  28933. processorToPlay->setPlayConfigDetails (numInputChans, numOutputChans,
  28934. sampleRate, blockSize);
  28935. processorToPlay->prepareToPlay (sampleRate, blockSize);
  28936. }
  28937. AudioProcessor* oldOne;
  28938. {
  28939. const ScopedLock sl (lock);
  28940. oldOne = isPrepared ? processor : 0;
  28941. processor = processorToPlay;
  28942. isPrepared = true;
  28943. }
  28944. if (oldOne != 0)
  28945. oldOne->releaseResources();
  28946. }
  28947. }
  28948. void AudioProcessorPlayer::audioDeviceIOCallback (const float** inputChannelData,
  28949. int numInputChannels,
  28950. float** outputChannelData,
  28951. int numOutputChannels,
  28952. int numSamples)
  28953. {
  28954. // these should have been prepared by audioDeviceAboutToStart()...
  28955. jassert (sampleRate > 0 && blockSize > 0);
  28956. incomingMidi.clear();
  28957. messageCollector.removeNextBlockOfMessages (incomingMidi, numSamples);
  28958. int i, totalNumChans = 0;
  28959. if (numInputChannels > numOutputChannels)
  28960. {
  28961. // if there aren't enough output channels for the number of
  28962. // inputs, we need to create some temporary extra ones (can't
  28963. // use the input data in case it gets written to)
  28964. tempBuffer.setSize (numInputChannels - numOutputChannels, numSamples,
  28965. false, false, true);
  28966. for (i = 0; i < numOutputChannels; ++i)
  28967. {
  28968. channels[totalNumChans] = outputChannelData[i];
  28969. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  28970. ++totalNumChans;
  28971. }
  28972. for (i = numOutputChannels; i < numInputChannels; ++i)
  28973. {
  28974. channels[totalNumChans] = tempBuffer.getSampleData (i - numOutputChannels, 0);
  28975. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  28976. ++totalNumChans;
  28977. }
  28978. }
  28979. else
  28980. {
  28981. for (i = 0; i < numInputChannels; ++i)
  28982. {
  28983. channels[totalNumChans] = outputChannelData[i];
  28984. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  28985. ++totalNumChans;
  28986. }
  28987. for (i = numInputChannels; i < numOutputChannels; ++i)
  28988. {
  28989. channels[totalNumChans] = outputChannelData[i];
  28990. zeromem (channels[totalNumChans], sizeof (float) * numSamples);
  28991. ++totalNumChans;
  28992. }
  28993. }
  28994. AudioSampleBuffer buffer (channels, totalNumChans, numSamples);
  28995. const ScopedLock sl (lock);
  28996. if (processor != 0)
  28997. processor->processBlock (buffer, incomingMidi);
  28998. }
  28999. void AudioProcessorPlayer::audioDeviceAboutToStart (AudioIODevice* device)
  29000. {
  29001. const ScopedLock sl (lock);
  29002. sampleRate = device->getCurrentSampleRate();
  29003. blockSize = device->getCurrentBufferSizeSamples();
  29004. numInputChans = device->getActiveInputChannels().countNumberOfSetBits();
  29005. numOutputChans = device->getActiveOutputChannels().countNumberOfSetBits();
  29006. messageCollector.reset (sampleRate);
  29007. zeromem (channels, sizeof (channels));
  29008. if (processor != 0)
  29009. {
  29010. if (isPrepared)
  29011. processor->releaseResources();
  29012. AudioProcessor* const oldProcessor = processor;
  29013. setProcessor (0);
  29014. setProcessor (oldProcessor);
  29015. }
  29016. }
  29017. void AudioProcessorPlayer::audioDeviceStopped()
  29018. {
  29019. const ScopedLock sl (lock);
  29020. if (processor != 0 && isPrepared)
  29021. processor->releaseResources();
  29022. sampleRate = 0.0;
  29023. blockSize = 0;
  29024. isPrepared = false;
  29025. tempBuffer.setSize (1, 1);
  29026. }
  29027. void AudioProcessorPlayer::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  29028. {
  29029. messageCollector.addMessageToQueue (message);
  29030. }
  29031. END_JUCE_NAMESPACE
  29032. /*** End of inlined file: juce_AudioProcessorPlayer.cpp ***/
  29033. /*** Start of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  29034. BEGIN_JUCE_NAMESPACE
  29035. class ProcessorParameterPropertyComp : public PropertyComponent,
  29036. public AudioProcessorListener,
  29037. public AsyncUpdater
  29038. {
  29039. public:
  29040. ProcessorParameterPropertyComp (const String& name,
  29041. AudioProcessor* const owner_,
  29042. const int index_)
  29043. : PropertyComponent (name),
  29044. owner (owner_),
  29045. index (index_)
  29046. {
  29047. addAndMakeVisible (slider = new ParamSlider (owner_, index_));
  29048. owner_->addListener (this);
  29049. }
  29050. ~ProcessorParameterPropertyComp()
  29051. {
  29052. owner->removeListener (this);
  29053. deleteAllChildren();
  29054. }
  29055. void refresh()
  29056. {
  29057. slider->setValue (owner->getParameter (index), false);
  29058. }
  29059. void audioProcessorChanged (AudioProcessor*) {}
  29060. void audioProcessorParameterChanged (AudioProcessor*, int parameterIndex, float)
  29061. {
  29062. if (parameterIndex == index)
  29063. triggerAsyncUpdate();
  29064. }
  29065. void handleAsyncUpdate()
  29066. {
  29067. refresh();
  29068. }
  29069. juce_UseDebuggingNewOperator
  29070. private:
  29071. AudioProcessor* const owner;
  29072. const int index;
  29073. Slider* slider;
  29074. class ParamSlider : public Slider
  29075. {
  29076. public:
  29077. ParamSlider (AudioProcessor* const owner_, const int index_)
  29078. : Slider (String::empty),
  29079. owner (owner_),
  29080. index (index_)
  29081. {
  29082. setRange (0.0, 1.0, 0.0);
  29083. setSliderStyle (Slider::LinearBar);
  29084. setTextBoxIsEditable (false);
  29085. setScrollWheelEnabled (false);
  29086. }
  29087. ~ParamSlider()
  29088. {
  29089. }
  29090. void valueChanged()
  29091. {
  29092. const float newVal = (float) getValue();
  29093. if (owner->getParameter (index) != newVal)
  29094. owner->setParameter (index, newVal);
  29095. }
  29096. const String getTextFromValue (double /*value*/)
  29097. {
  29098. return owner->getParameterText (index);
  29099. }
  29100. juce_UseDebuggingNewOperator
  29101. private:
  29102. AudioProcessor* const owner;
  29103. const int index;
  29104. ParamSlider (const ParamSlider&);
  29105. ParamSlider& operator= (const ParamSlider&);
  29106. };
  29107. ProcessorParameterPropertyComp (const ProcessorParameterPropertyComp&);
  29108. ProcessorParameterPropertyComp& operator= (const ProcessorParameterPropertyComp&);
  29109. };
  29110. GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor* const owner_)
  29111. : AudioProcessorEditor (owner_)
  29112. {
  29113. setOpaque (true);
  29114. addAndMakeVisible (panel = new PropertyPanel());
  29115. Array <PropertyComponent*> params;
  29116. const int numParams = owner_->getNumParameters();
  29117. int totalHeight = 0;
  29118. for (int i = 0; i < numParams; ++i)
  29119. {
  29120. String name (owner_->getParameterName (i));
  29121. if (name.trim().isEmpty())
  29122. name = "Unnamed";
  29123. ProcessorParameterPropertyComp* const pc = new ProcessorParameterPropertyComp (name, owner_, i);
  29124. params.add (pc);
  29125. totalHeight += pc->getPreferredHeight();
  29126. }
  29127. panel->addProperties (params);
  29128. setSize (400, jlimit (25, 400, totalHeight));
  29129. }
  29130. GenericAudioProcessorEditor::~GenericAudioProcessorEditor()
  29131. {
  29132. deleteAllChildren();
  29133. }
  29134. void GenericAudioProcessorEditor::paint (Graphics& g)
  29135. {
  29136. g.fillAll (Colours::white);
  29137. }
  29138. void GenericAudioProcessorEditor::resized()
  29139. {
  29140. panel->setSize (getWidth(), getHeight());
  29141. }
  29142. END_JUCE_NAMESPACE
  29143. /*** End of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  29144. /*** Start of inlined file: juce_Sampler.cpp ***/
  29145. BEGIN_JUCE_NAMESPACE
  29146. SamplerSound::SamplerSound (const String& name_,
  29147. AudioFormatReader& source,
  29148. const BigInteger& midiNotes_,
  29149. const int midiNoteForNormalPitch,
  29150. const double attackTimeSecs,
  29151. const double releaseTimeSecs,
  29152. const double maxSampleLengthSeconds)
  29153. : name (name_),
  29154. midiNotes (midiNotes_),
  29155. midiRootNote (midiNoteForNormalPitch)
  29156. {
  29157. sourceSampleRate = source.sampleRate;
  29158. if (sourceSampleRate <= 0 || source.lengthInSamples <= 0)
  29159. {
  29160. length = 0;
  29161. attackSamples = 0;
  29162. releaseSamples = 0;
  29163. }
  29164. else
  29165. {
  29166. length = jmin ((int) source.lengthInSamples,
  29167. (int) (maxSampleLengthSeconds * sourceSampleRate));
  29168. data = new AudioSampleBuffer (jmin (2, (int) source.numChannels), length + 4);
  29169. data->readFromAudioReader (&source, 0, length + 4, 0, true, true);
  29170. attackSamples = roundToInt (attackTimeSecs * sourceSampleRate);
  29171. releaseSamples = roundToInt (releaseTimeSecs * sourceSampleRate);
  29172. }
  29173. }
  29174. SamplerSound::~SamplerSound()
  29175. {
  29176. }
  29177. bool SamplerSound::appliesToNote (const int midiNoteNumber)
  29178. {
  29179. return midiNotes [midiNoteNumber];
  29180. }
  29181. bool SamplerSound::appliesToChannel (const int /*midiChannel*/)
  29182. {
  29183. return true;
  29184. }
  29185. SamplerVoice::SamplerVoice()
  29186. : pitchRatio (0.0),
  29187. sourceSamplePosition (0.0),
  29188. lgain (0.0f),
  29189. rgain (0.0f),
  29190. isInAttack (false),
  29191. isInRelease (false)
  29192. {
  29193. }
  29194. SamplerVoice::~SamplerVoice()
  29195. {
  29196. }
  29197. bool SamplerVoice::canPlaySound (SynthesiserSound* sound)
  29198. {
  29199. return dynamic_cast <const SamplerSound*> (sound) != 0;
  29200. }
  29201. void SamplerVoice::startNote (const int midiNoteNumber,
  29202. const float velocity,
  29203. SynthesiserSound* s,
  29204. const int /*currentPitchWheelPosition*/)
  29205. {
  29206. const SamplerSound* const sound = dynamic_cast <const SamplerSound*> (s);
  29207. jassert (sound != 0); // this object can only play SamplerSounds!
  29208. if (sound != 0)
  29209. {
  29210. const double targetFreq = MidiMessage::getMidiNoteInHertz (midiNoteNumber);
  29211. const double naturalFreq = MidiMessage::getMidiNoteInHertz (sound->midiRootNote);
  29212. pitchRatio = (targetFreq * sound->sourceSampleRate) / (naturalFreq * getSampleRate());
  29213. sourceSamplePosition = 0.0;
  29214. lgain = velocity;
  29215. rgain = velocity;
  29216. isInAttack = (sound->attackSamples > 0);
  29217. isInRelease = false;
  29218. if (isInAttack)
  29219. {
  29220. attackReleaseLevel = 0.0f;
  29221. attackDelta = (float) (pitchRatio / sound->attackSamples);
  29222. }
  29223. else
  29224. {
  29225. attackReleaseLevel = 1.0f;
  29226. attackDelta = 0.0f;
  29227. }
  29228. if (sound->releaseSamples > 0)
  29229. {
  29230. releaseDelta = (float) (-pitchRatio / sound->releaseSamples);
  29231. }
  29232. else
  29233. {
  29234. releaseDelta = 0.0f;
  29235. }
  29236. }
  29237. }
  29238. void SamplerVoice::stopNote (const bool allowTailOff)
  29239. {
  29240. if (allowTailOff)
  29241. {
  29242. isInAttack = false;
  29243. isInRelease = true;
  29244. }
  29245. else
  29246. {
  29247. clearCurrentNote();
  29248. }
  29249. }
  29250. void SamplerVoice::pitchWheelMoved (const int /*newValue*/)
  29251. {
  29252. }
  29253. void SamplerVoice::controllerMoved (const int /*controllerNumber*/,
  29254. const int /*newValue*/)
  29255. {
  29256. }
  29257. void SamplerVoice::renderNextBlock (AudioSampleBuffer& outputBuffer, int startSample, int numSamples)
  29258. {
  29259. const SamplerSound* const playingSound = (SamplerSound*) (SynthesiserSound*) getCurrentlyPlayingSound();
  29260. if (playingSound != 0)
  29261. {
  29262. const float* const inL = playingSound->data->getSampleData (0, 0);
  29263. const float* const inR = playingSound->data->getNumChannels() > 1
  29264. ? playingSound->data->getSampleData (1, 0) : 0;
  29265. float* outL = outputBuffer.getSampleData (0, startSample);
  29266. float* outR = outputBuffer.getNumChannels() > 1 ? outputBuffer.getSampleData (1, startSample) : 0;
  29267. while (--numSamples >= 0)
  29268. {
  29269. const int pos = (int) sourceSamplePosition;
  29270. const float alpha = (float) (sourceSamplePosition - pos);
  29271. const float invAlpha = 1.0f - alpha;
  29272. // just using a very simple linear interpolation here..
  29273. float l = (inL [pos] * invAlpha + inL [pos + 1] * alpha);
  29274. float r = (inR != 0) ? (inR [pos] * invAlpha + inR [pos + 1] * alpha)
  29275. : l;
  29276. l *= lgain;
  29277. r *= rgain;
  29278. if (isInAttack)
  29279. {
  29280. l *= attackReleaseLevel;
  29281. r *= attackReleaseLevel;
  29282. attackReleaseLevel += attackDelta;
  29283. if (attackReleaseLevel >= 1.0f)
  29284. {
  29285. attackReleaseLevel = 1.0f;
  29286. isInAttack = false;
  29287. }
  29288. }
  29289. else if (isInRelease)
  29290. {
  29291. l *= attackReleaseLevel;
  29292. r *= attackReleaseLevel;
  29293. attackReleaseLevel += releaseDelta;
  29294. if (attackReleaseLevel <= 0.0f)
  29295. {
  29296. stopNote (false);
  29297. break;
  29298. }
  29299. }
  29300. if (outR != 0)
  29301. {
  29302. *outL++ += l;
  29303. *outR++ += r;
  29304. }
  29305. else
  29306. {
  29307. *outL++ += (l + r) * 0.5f;
  29308. }
  29309. sourceSamplePosition += pitchRatio;
  29310. if (sourceSamplePosition > playingSound->length)
  29311. {
  29312. stopNote (false);
  29313. break;
  29314. }
  29315. }
  29316. }
  29317. }
  29318. END_JUCE_NAMESPACE
  29319. /*** End of inlined file: juce_Sampler.cpp ***/
  29320. /*** Start of inlined file: juce_Synthesiser.cpp ***/
  29321. BEGIN_JUCE_NAMESPACE
  29322. SynthesiserSound::SynthesiserSound()
  29323. {
  29324. }
  29325. SynthesiserSound::~SynthesiserSound()
  29326. {
  29327. }
  29328. SynthesiserVoice::SynthesiserVoice()
  29329. : currentSampleRate (44100.0),
  29330. currentlyPlayingNote (-1),
  29331. noteOnTime (0),
  29332. currentlyPlayingSound (0)
  29333. {
  29334. }
  29335. SynthesiserVoice::~SynthesiserVoice()
  29336. {
  29337. }
  29338. bool SynthesiserVoice::isPlayingChannel (const int midiChannel) const
  29339. {
  29340. return currentlyPlayingSound != 0
  29341. && currentlyPlayingSound->appliesToChannel (midiChannel);
  29342. }
  29343. void SynthesiserVoice::setCurrentPlaybackSampleRate (const double newRate)
  29344. {
  29345. currentSampleRate = newRate;
  29346. }
  29347. void SynthesiserVoice::clearCurrentNote()
  29348. {
  29349. currentlyPlayingNote = -1;
  29350. currentlyPlayingSound = 0;
  29351. }
  29352. Synthesiser::Synthesiser()
  29353. : sampleRate (0),
  29354. lastNoteOnCounter (0),
  29355. shouldStealNotes (true)
  29356. {
  29357. for (int i = 0; i < numElementsInArray (lastPitchWheelValues); ++i)
  29358. lastPitchWheelValues[i] = 0x2000;
  29359. }
  29360. Synthesiser::~Synthesiser()
  29361. {
  29362. }
  29363. SynthesiserVoice* Synthesiser::getVoice (const int index) const
  29364. {
  29365. const ScopedLock sl (lock);
  29366. return voices [index];
  29367. }
  29368. void Synthesiser::clearVoices()
  29369. {
  29370. const ScopedLock sl (lock);
  29371. voices.clear();
  29372. }
  29373. void Synthesiser::addVoice (SynthesiserVoice* const newVoice)
  29374. {
  29375. const ScopedLock sl (lock);
  29376. voices.add (newVoice);
  29377. }
  29378. void Synthesiser::removeVoice (const int index)
  29379. {
  29380. const ScopedLock sl (lock);
  29381. voices.remove (index);
  29382. }
  29383. void Synthesiser::clearSounds()
  29384. {
  29385. const ScopedLock sl (lock);
  29386. sounds.clear();
  29387. }
  29388. void Synthesiser::addSound (const SynthesiserSound::Ptr& newSound)
  29389. {
  29390. const ScopedLock sl (lock);
  29391. sounds.add (newSound);
  29392. }
  29393. void Synthesiser::removeSound (const int index)
  29394. {
  29395. const ScopedLock sl (lock);
  29396. sounds.remove (index);
  29397. }
  29398. void Synthesiser::setNoteStealingEnabled (const bool shouldStealNotes_)
  29399. {
  29400. shouldStealNotes = shouldStealNotes_;
  29401. }
  29402. void Synthesiser::setCurrentPlaybackSampleRate (const double newRate)
  29403. {
  29404. if (sampleRate != newRate)
  29405. {
  29406. const ScopedLock sl (lock);
  29407. allNotesOff (0, false);
  29408. sampleRate = newRate;
  29409. for (int i = voices.size(); --i >= 0;)
  29410. voices.getUnchecked (i)->setCurrentPlaybackSampleRate (newRate);
  29411. }
  29412. }
  29413. void Synthesiser::renderNextBlock (AudioSampleBuffer& outputBuffer,
  29414. const MidiBuffer& midiData,
  29415. int startSample,
  29416. int numSamples)
  29417. {
  29418. // must set the sample rate before using this!
  29419. jassert (sampleRate != 0);
  29420. const ScopedLock sl (lock);
  29421. MidiBuffer::Iterator midiIterator (midiData);
  29422. midiIterator.setNextSamplePosition (startSample);
  29423. MidiMessage m (0xf4, 0.0);
  29424. while (numSamples > 0)
  29425. {
  29426. int midiEventPos;
  29427. const bool useEvent = midiIterator.getNextEvent (m, midiEventPos)
  29428. && midiEventPos < startSample + numSamples;
  29429. const int numThisTime = useEvent ? midiEventPos - startSample
  29430. : numSamples;
  29431. if (numThisTime > 0)
  29432. {
  29433. for (int i = voices.size(); --i >= 0;)
  29434. voices.getUnchecked (i)->renderNextBlock (outputBuffer, startSample, numThisTime);
  29435. }
  29436. if (useEvent)
  29437. {
  29438. if (m.isNoteOn())
  29439. {
  29440. const int channel = m.getChannel();
  29441. noteOn (channel,
  29442. m.getNoteNumber(),
  29443. m.getFloatVelocity());
  29444. }
  29445. else if (m.isNoteOff())
  29446. {
  29447. noteOff (m.getChannel(),
  29448. m.getNoteNumber(),
  29449. true);
  29450. }
  29451. else if (m.isAllNotesOff() || m.isAllSoundOff())
  29452. {
  29453. allNotesOff (m.getChannel(), true);
  29454. }
  29455. else if (m.isPitchWheel())
  29456. {
  29457. const int channel = m.getChannel();
  29458. const int wheelPos = m.getPitchWheelValue();
  29459. lastPitchWheelValues [channel - 1] = wheelPos;
  29460. handlePitchWheel (channel, wheelPos);
  29461. }
  29462. else if (m.isController())
  29463. {
  29464. handleController (m.getChannel(),
  29465. m.getControllerNumber(),
  29466. m.getControllerValue());
  29467. }
  29468. }
  29469. startSample += numThisTime;
  29470. numSamples -= numThisTime;
  29471. }
  29472. }
  29473. void Synthesiser::noteOn (const int midiChannel,
  29474. const int midiNoteNumber,
  29475. const float velocity)
  29476. {
  29477. const ScopedLock sl (lock);
  29478. for (int i = sounds.size(); --i >= 0;)
  29479. {
  29480. SynthesiserSound* const sound = sounds.getUnchecked(i);
  29481. if (sound->appliesToNote (midiNoteNumber)
  29482. && sound->appliesToChannel (midiChannel))
  29483. {
  29484. startVoice (findFreeVoice (sound, shouldStealNotes),
  29485. sound, midiChannel, midiNoteNumber, velocity);
  29486. }
  29487. }
  29488. }
  29489. void Synthesiser::startVoice (SynthesiserVoice* const voice,
  29490. SynthesiserSound* const sound,
  29491. const int midiChannel,
  29492. const int midiNoteNumber,
  29493. const float velocity)
  29494. {
  29495. if (voice != 0 && sound != 0)
  29496. {
  29497. if (voice->currentlyPlayingSound != 0)
  29498. voice->stopNote (false);
  29499. voice->startNote (midiNoteNumber,
  29500. velocity,
  29501. sound,
  29502. lastPitchWheelValues [midiChannel - 1]);
  29503. voice->currentlyPlayingNote = midiNoteNumber;
  29504. voice->noteOnTime = ++lastNoteOnCounter;
  29505. voice->currentlyPlayingSound = sound;
  29506. }
  29507. }
  29508. void Synthesiser::noteOff (const int midiChannel,
  29509. const int midiNoteNumber,
  29510. const bool allowTailOff)
  29511. {
  29512. const ScopedLock sl (lock);
  29513. for (int i = voices.size(); --i >= 0;)
  29514. {
  29515. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29516. if (voice->getCurrentlyPlayingNote() == midiNoteNumber)
  29517. {
  29518. SynthesiserSound* const sound = voice->getCurrentlyPlayingSound();
  29519. if (sound != 0
  29520. && sound->appliesToNote (midiNoteNumber)
  29521. && sound->appliesToChannel (midiChannel))
  29522. {
  29523. voice->stopNote (allowTailOff);
  29524. // the subclass MUST call clearCurrentNote() if it's not tailing off! RTFM for stopNote()!
  29525. jassert (allowTailOff || (voice->getCurrentlyPlayingNote() < 0 && voice->getCurrentlyPlayingSound() == 0));
  29526. }
  29527. }
  29528. }
  29529. }
  29530. void Synthesiser::allNotesOff (const int midiChannel,
  29531. const bool allowTailOff)
  29532. {
  29533. const ScopedLock sl (lock);
  29534. for (int i = voices.size(); --i >= 0;)
  29535. {
  29536. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29537. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29538. voice->stopNote (allowTailOff);
  29539. }
  29540. }
  29541. void Synthesiser::handlePitchWheel (const int midiChannel,
  29542. const int wheelValue)
  29543. {
  29544. const ScopedLock sl (lock);
  29545. for (int i = voices.size(); --i >= 0;)
  29546. {
  29547. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29548. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29549. {
  29550. voice->pitchWheelMoved (wheelValue);
  29551. }
  29552. }
  29553. }
  29554. void Synthesiser::handleController (const int midiChannel,
  29555. const int controllerNumber,
  29556. const int controllerValue)
  29557. {
  29558. const ScopedLock sl (lock);
  29559. for (int i = voices.size(); --i >= 0;)
  29560. {
  29561. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29562. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29563. voice->controllerMoved (controllerNumber, controllerValue);
  29564. }
  29565. }
  29566. SynthesiserVoice* Synthesiser::findFreeVoice (SynthesiserSound* soundToPlay,
  29567. const bool stealIfNoneAvailable) const
  29568. {
  29569. const ScopedLock sl (lock);
  29570. for (int i = voices.size(); --i >= 0;)
  29571. if (voices.getUnchecked (i)->getCurrentlyPlayingNote() < 0
  29572. && voices.getUnchecked (i)->canPlaySound (soundToPlay))
  29573. return voices.getUnchecked (i);
  29574. if (stealIfNoneAvailable)
  29575. {
  29576. // currently this just steals the one that's been playing the longest, but could be made a bit smarter..
  29577. SynthesiserVoice* oldest = 0;
  29578. for (int i = voices.size(); --i >= 0;)
  29579. {
  29580. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29581. if (voice->canPlaySound (soundToPlay)
  29582. && (oldest == 0 || oldest->noteOnTime > voice->noteOnTime))
  29583. oldest = voice;
  29584. }
  29585. jassert (oldest != 0);
  29586. return oldest;
  29587. }
  29588. return 0;
  29589. }
  29590. END_JUCE_NAMESPACE
  29591. /*** End of inlined file: juce_Synthesiser.cpp ***/
  29592. /*** Start of inlined file: juce_ActionBroadcaster.cpp ***/
  29593. BEGIN_JUCE_NAMESPACE
  29594. ActionBroadcaster::ActionBroadcaster() throw()
  29595. {
  29596. // are you trying to create this object before or after juce has been intialised??
  29597. jassert (MessageManager::instance != 0);
  29598. }
  29599. ActionBroadcaster::~ActionBroadcaster()
  29600. {
  29601. // all event-based objects must be deleted BEFORE juce is shut down!
  29602. jassert (MessageManager::instance != 0);
  29603. }
  29604. void ActionBroadcaster::addActionListener (ActionListener* const listener)
  29605. {
  29606. actionListenerList.addActionListener (listener);
  29607. }
  29608. void ActionBroadcaster::removeActionListener (ActionListener* const listener)
  29609. {
  29610. jassert (actionListenerList.isValidMessageListener());
  29611. if (actionListenerList.isValidMessageListener())
  29612. actionListenerList.removeActionListener (listener);
  29613. }
  29614. void ActionBroadcaster::removeAllActionListeners()
  29615. {
  29616. actionListenerList.removeAllActionListeners();
  29617. }
  29618. void ActionBroadcaster::sendActionMessage (const String& message) const
  29619. {
  29620. actionListenerList.sendActionMessage (message);
  29621. }
  29622. END_JUCE_NAMESPACE
  29623. /*** End of inlined file: juce_ActionBroadcaster.cpp ***/
  29624. /*** Start of inlined file: juce_ActionListenerList.cpp ***/
  29625. BEGIN_JUCE_NAMESPACE
  29626. // special message of our own with a string in it
  29627. class ActionMessage : public Message
  29628. {
  29629. public:
  29630. const String message;
  29631. ActionMessage (const String& messageText,
  29632. void* const listener_) throw()
  29633. : message (messageText)
  29634. {
  29635. pointerParameter = listener_;
  29636. }
  29637. ~ActionMessage() throw()
  29638. {
  29639. }
  29640. private:
  29641. ActionMessage (const ActionMessage&);
  29642. ActionMessage& operator= (const ActionMessage&);
  29643. };
  29644. ActionListenerList::ActionListenerList() throw()
  29645. {
  29646. }
  29647. ActionListenerList::~ActionListenerList() throw()
  29648. {
  29649. }
  29650. void ActionListenerList::addActionListener (ActionListener* const listener) throw()
  29651. {
  29652. const ScopedLock sl (actionListenerLock_);
  29653. jassert (listener != 0);
  29654. jassert (! actionListeners_.contains (listener)); // trying to add a listener to the list twice!
  29655. if (listener != 0)
  29656. actionListeners_.add (listener);
  29657. }
  29658. void ActionListenerList::removeActionListener (ActionListener* const listener) throw()
  29659. {
  29660. const ScopedLock sl (actionListenerLock_);
  29661. jassert (actionListeners_.contains (listener)); // trying to remove a listener that isn't on the list!
  29662. actionListeners_.removeValue (listener);
  29663. }
  29664. void ActionListenerList::removeAllActionListeners() throw()
  29665. {
  29666. const ScopedLock sl (actionListenerLock_);
  29667. actionListeners_.clear();
  29668. }
  29669. void ActionListenerList::sendActionMessage (const String& message) const
  29670. {
  29671. const ScopedLock sl (actionListenerLock_);
  29672. for (int i = actionListeners_.size(); --i >= 0;)
  29673. {
  29674. postMessage (new ActionMessage (message,
  29675. (ActionListener*) actionListeners_.getUnchecked(i)));
  29676. }
  29677. }
  29678. void ActionListenerList::handleMessage (const Message& message)
  29679. {
  29680. const ActionMessage& am = (const ActionMessage&) message;
  29681. if (actionListeners_.contains (am.pointerParameter))
  29682. ((ActionListener*) am.pointerParameter)->actionListenerCallback (am.message);
  29683. }
  29684. END_JUCE_NAMESPACE
  29685. /*** End of inlined file: juce_ActionListenerList.cpp ***/
  29686. /*** Start of inlined file: juce_AsyncUpdater.cpp ***/
  29687. BEGIN_JUCE_NAMESPACE
  29688. AsyncUpdater::AsyncUpdater() throw()
  29689. : asyncMessagePending (false)
  29690. {
  29691. internalAsyncHandler.owner = this;
  29692. }
  29693. AsyncUpdater::~AsyncUpdater()
  29694. {
  29695. }
  29696. void AsyncUpdater::triggerAsyncUpdate() throw()
  29697. {
  29698. if (! asyncMessagePending)
  29699. {
  29700. asyncMessagePending = true;
  29701. internalAsyncHandler.postMessage (new Message());
  29702. }
  29703. }
  29704. void AsyncUpdater::cancelPendingUpdate() throw()
  29705. {
  29706. asyncMessagePending = false;
  29707. }
  29708. void AsyncUpdater::handleUpdateNowIfNeeded()
  29709. {
  29710. if (asyncMessagePending)
  29711. {
  29712. asyncMessagePending = false;
  29713. handleAsyncUpdate();
  29714. }
  29715. }
  29716. void AsyncUpdater::AsyncUpdaterInternal::handleMessage (const Message&)
  29717. {
  29718. owner->handleUpdateNowIfNeeded();
  29719. }
  29720. END_JUCE_NAMESPACE
  29721. /*** End of inlined file: juce_AsyncUpdater.cpp ***/
  29722. /*** Start of inlined file: juce_ChangeBroadcaster.cpp ***/
  29723. BEGIN_JUCE_NAMESPACE
  29724. ChangeBroadcaster::ChangeBroadcaster() throw()
  29725. {
  29726. // are you trying to create this object before or after juce has been intialised??
  29727. jassert (MessageManager::instance != 0);
  29728. }
  29729. ChangeBroadcaster::~ChangeBroadcaster()
  29730. {
  29731. // all event-based objects must be deleted BEFORE juce is shut down!
  29732. jassert (MessageManager::instance != 0);
  29733. }
  29734. void ChangeBroadcaster::addChangeListener (ChangeListener* const listener) throw()
  29735. {
  29736. changeListenerList.addChangeListener (listener);
  29737. }
  29738. void ChangeBroadcaster::removeChangeListener (ChangeListener* const listener) throw()
  29739. {
  29740. jassert (changeListenerList.isValidMessageListener());
  29741. if (changeListenerList.isValidMessageListener())
  29742. changeListenerList.removeChangeListener (listener);
  29743. }
  29744. void ChangeBroadcaster::removeAllChangeListeners() throw()
  29745. {
  29746. changeListenerList.removeAllChangeListeners();
  29747. }
  29748. void ChangeBroadcaster::sendChangeMessage (void* objectThatHasChanged) throw()
  29749. {
  29750. changeListenerList.sendChangeMessage (objectThatHasChanged);
  29751. }
  29752. void ChangeBroadcaster::sendSynchronousChangeMessage (void* objectThatHasChanged)
  29753. {
  29754. changeListenerList.sendSynchronousChangeMessage (objectThatHasChanged);
  29755. }
  29756. void ChangeBroadcaster::dispatchPendingMessages()
  29757. {
  29758. changeListenerList.dispatchPendingMessages();
  29759. }
  29760. END_JUCE_NAMESPACE
  29761. /*** End of inlined file: juce_ChangeBroadcaster.cpp ***/
  29762. /*** Start of inlined file: juce_ChangeListenerList.cpp ***/
  29763. BEGIN_JUCE_NAMESPACE
  29764. ChangeListenerList::ChangeListenerList() throw()
  29765. : lastChangedObject (0),
  29766. messagePending (false)
  29767. {
  29768. }
  29769. ChangeListenerList::~ChangeListenerList() throw()
  29770. {
  29771. }
  29772. void ChangeListenerList::addChangeListener (ChangeListener* const listener) throw()
  29773. {
  29774. const ScopedLock sl (lock);
  29775. jassert (listener != 0);
  29776. if (listener != 0)
  29777. listeners.add (listener);
  29778. }
  29779. void ChangeListenerList::removeChangeListener (ChangeListener* const listener) throw()
  29780. {
  29781. const ScopedLock sl (lock);
  29782. listeners.removeValue (listener);
  29783. }
  29784. void ChangeListenerList::removeAllChangeListeners() throw()
  29785. {
  29786. const ScopedLock sl (lock);
  29787. listeners.clear();
  29788. }
  29789. void ChangeListenerList::sendChangeMessage (void* const objectThatHasChanged) throw()
  29790. {
  29791. const ScopedLock sl (lock);
  29792. if ((! messagePending) && (listeners.size() > 0))
  29793. {
  29794. lastChangedObject = objectThatHasChanged;
  29795. postMessage (new Message (0, 0, 0, objectThatHasChanged));
  29796. messagePending = true;
  29797. }
  29798. }
  29799. void ChangeListenerList::handleMessage (const Message& message)
  29800. {
  29801. sendSynchronousChangeMessage (message.pointerParameter);
  29802. }
  29803. void ChangeListenerList::sendSynchronousChangeMessage (void* const objectThatHasChanged)
  29804. {
  29805. const ScopedLock sl (lock);
  29806. messagePending = false;
  29807. for (int i = listeners.size(); --i >= 0;)
  29808. {
  29809. ChangeListener* const l = (ChangeListener*) listeners.getUnchecked (i);
  29810. {
  29811. const ScopedUnlock tempUnlocker (lock);
  29812. l->changeListenerCallback (objectThatHasChanged);
  29813. }
  29814. i = jmin (i, listeners.size());
  29815. }
  29816. }
  29817. void ChangeListenerList::dispatchPendingMessages()
  29818. {
  29819. if (messagePending)
  29820. sendSynchronousChangeMessage (lastChangedObject);
  29821. }
  29822. END_JUCE_NAMESPACE
  29823. /*** End of inlined file: juce_ChangeListenerList.cpp ***/
  29824. /*** Start of inlined file: juce_InterprocessConnection.cpp ***/
  29825. BEGIN_JUCE_NAMESPACE
  29826. InterprocessConnection::InterprocessConnection (const bool callbacksOnMessageThread,
  29827. const uint32 magicMessageHeaderNumber)
  29828. : Thread ("Juce IPC connection"),
  29829. callbackConnectionState (false),
  29830. useMessageThread (callbacksOnMessageThread),
  29831. magicMessageHeader (magicMessageHeaderNumber),
  29832. pipeReceiveMessageTimeout (-1)
  29833. {
  29834. }
  29835. InterprocessConnection::~InterprocessConnection()
  29836. {
  29837. callbackConnectionState = false;
  29838. disconnect();
  29839. }
  29840. bool InterprocessConnection::connectToSocket (const String& hostName,
  29841. const int portNumber,
  29842. const int timeOutMillisecs)
  29843. {
  29844. disconnect();
  29845. const ScopedLock sl (pipeAndSocketLock);
  29846. socket = new StreamingSocket();
  29847. if (socket->connect (hostName, portNumber, timeOutMillisecs))
  29848. {
  29849. connectionMadeInt();
  29850. startThread();
  29851. return true;
  29852. }
  29853. else
  29854. {
  29855. socket = 0;
  29856. return false;
  29857. }
  29858. }
  29859. bool InterprocessConnection::connectToPipe (const String& pipeName,
  29860. const int pipeReceiveMessageTimeoutMs)
  29861. {
  29862. disconnect();
  29863. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  29864. if (newPipe->openExisting (pipeName))
  29865. {
  29866. const ScopedLock sl (pipeAndSocketLock);
  29867. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  29868. initialiseWithPipe (newPipe.release());
  29869. return true;
  29870. }
  29871. return false;
  29872. }
  29873. bool InterprocessConnection::createPipe (const String& pipeName,
  29874. const int pipeReceiveMessageTimeoutMs)
  29875. {
  29876. disconnect();
  29877. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  29878. if (newPipe->createNewPipe (pipeName))
  29879. {
  29880. const ScopedLock sl (pipeAndSocketLock);
  29881. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  29882. initialiseWithPipe (newPipe.release());
  29883. return true;
  29884. }
  29885. return false;
  29886. }
  29887. void InterprocessConnection::disconnect()
  29888. {
  29889. if (socket != 0)
  29890. socket->close();
  29891. if (pipe != 0)
  29892. {
  29893. pipe->cancelPendingReads();
  29894. pipe->close();
  29895. }
  29896. stopThread (4000);
  29897. {
  29898. const ScopedLock sl (pipeAndSocketLock);
  29899. socket = 0;
  29900. pipe = 0;
  29901. }
  29902. connectionLostInt();
  29903. }
  29904. bool InterprocessConnection::isConnected() const
  29905. {
  29906. const ScopedLock sl (pipeAndSocketLock);
  29907. return ((socket != 0 && socket->isConnected())
  29908. || (pipe != 0 && pipe->isOpen()))
  29909. && isThreadRunning();
  29910. }
  29911. const String InterprocessConnection::getConnectedHostName() const
  29912. {
  29913. if (pipe != 0)
  29914. {
  29915. return "localhost";
  29916. }
  29917. else if (socket != 0)
  29918. {
  29919. if (! socket->isLocal())
  29920. return socket->getHostName();
  29921. return "localhost";
  29922. }
  29923. return String::empty;
  29924. }
  29925. bool InterprocessConnection::sendMessage (const MemoryBlock& message)
  29926. {
  29927. uint32 messageHeader[2];
  29928. messageHeader [0] = ByteOrder::swapIfBigEndian (magicMessageHeader);
  29929. messageHeader [1] = ByteOrder::swapIfBigEndian ((uint32) message.getSize());
  29930. MemoryBlock messageData (sizeof (messageHeader) + message.getSize());
  29931. messageData.copyFrom (messageHeader, 0, sizeof (messageHeader));
  29932. messageData.copyFrom (message.getData(), sizeof (messageHeader), message.getSize());
  29933. size_t bytesWritten = 0;
  29934. const ScopedLock sl (pipeAndSocketLock);
  29935. if (socket != 0)
  29936. {
  29937. bytesWritten = socket->write (messageData.getData(), (int) messageData.getSize());
  29938. }
  29939. else if (pipe != 0)
  29940. {
  29941. bytesWritten = pipe->write (messageData.getData(), (int) messageData.getSize());
  29942. }
  29943. if (bytesWritten < 0)
  29944. {
  29945. // error..
  29946. return false;
  29947. }
  29948. return (bytesWritten == messageData.getSize());
  29949. }
  29950. void InterprocessConnection::initialiseWithSocket (StreamingSocket* const socket_)
  29951. {
  29952. jassert (socket == 0);
  29953. socket = socket_;
  29954. connectionMadeInt();
  29955. startThread();
  29956. }
  29957. void InterprocessConnection::initialiseWithPipe (NamedPipe* const pipe_)
  29958. {
  29959. jassert (pipe == 0);
  29960. pipe = pipe_;
  29961. connectionMadeInt();
  29962. startThread();
  29963. }
  29964. const int messageMagicNumber = 0xb734128b;
  29965. void InterprocessConnection::handleMessage (const Message& message)
  29966. {
  29967. if (message.intParameter1 == messageMagicNumber)
  29968. {
  29969. switch (message.intParameter2)
  29970. {
  29971. case 0:
  29972. {
  29973. ScopedPointer <MemoryBlock> data ((MemoryBlock*) message.pointerParameter);
  29974. messageReceived (*data);
  29975. break;
  29976. }
  29977. case 1:
  29978. connectionMade();
  29979. break;
  29980. case 2:
  29981. connectionLost();
  29982. break;
  29983. }
  29984. }
  29985. }
  29986. void InterprocessConnection::connectionMadeInt()
  29987. {
  29988. if (! callbackConnectionState)
  29989. {
  29990. callbackConnectionState = true;
  29991. if (useMessageThread)
  29992. postMessage (new Message (messageMagicNumber, 1, 0, 0));
  29993. else
  29994. connectionMade();
  29995. }
  29996. }
  29997. void InterprocessConnection::connectionLostInt()
  29998. {
  29999. if (callbackConnectionState)
  30000. {
  30001. callbackConnectionState = false;
  30002. if (useMessageThread)
  30003. postMessage (new Message (messageMagicNumber, 2, 0, 0));
  30004. else
  30005. connectionLost();
  30006. }
  30007. }
  30008. void InterprocessConnection::deliverDataInt (const MemoryBlock& data)
  30009. {
  30010. jassert (callbackConnectionState);
  30011. if (useMessageThread)
  30012. postMessage (new Message (messageMagicNumber, 0, 0, new MemoryBlock (data)));
  30013. else
  30014. messageReceived (data);
  30015. }
  30016. bool InterprocessConnection::readNextMessageInt()
  30017. {
  30018. const int maximumMessageSize = 1024 * 1024 * 10; // sanity check
  30019. uint32 messageHeader[2];
  30020. const int bytes = (socket != 0) ? socket->read (messageHeader, sizeof (messageHeader), true)
  30021. : pipe->read (messageHeader, sizeof (messageHeader), pipeReceiveMessageTimeout);
  30022. if (bytes == sizeof (messageHeader)
  30023. && ByteOrder::swapIfBigEndian (messageHeader[0]) == magicMessageHeader)
  30024. {
  30025. int bytesInMessage = (int) ByteOrder::swapIfBigEndian (messageHeader[1]);
  30026. if (bytesInMessage > 0 && bytesInMessage < maximumMessageSize)
  30027. {
  30028. MemoryBlock messageData (bytesInMessage, true);
  30029. int bytesRead = 0;
  30030. while (bytesInMessage > 0)
  30031. {
  30032. if (threadShouldExit())
  30033. return false;
  30034. const int numThisTime = jmin (bytesInMessage, 65536);
  30035. const int bytesIn = (socket != 0) ? socket->read (static_cast <char*> (messageData.getData()) + bytesRead, numThisTime, true)
  30036. : pipe->read (static_cast <char*> (messageData.getData()) + bytesRead, numThisTime, pipeReceiveMessageTimeout);
  30037. if (bytesIn <= 0)
  30038. break;
  30039. bytesRead += bytesIn;
  30040. bytesInMessage -= bytesIn;
  30041. }
  30042. if (bytesRead >= 0)
  30043. deliverDataInt (messageData);
  30044. }
  30045. }
  30046. else if (bytes < 0)
  30047. {
  30048. {
  30049. const ScopedLock sl (pipeAndSocketLock);
  30050. socket = 0;
  30051. }
  30052. connectionLostInt();
  30053. return false;
  30054. }
  30055. return true;
  30056. }
  30057. void InterprocessConnection::run()
  30058. {
  30059. while (! threadShouldExit())
  30060. {
  30061. if (socket != 0)
  30062. {
  30063. const int ready = socket->waitUntilReady (true, 0);
  30064. if (ready < 0)
  30065. {
  30066. {
  30067. const ScopedLock sl (pipeAndSocketLock);
  30068. socket = 0;
  30069. }
  30070. connectionLostInt();
  30071. break;
  30072. }
  30073. else if (ready > 0)
  30074. {
  30075. if (! readNextMessageInt())
  30076. break;
  30077. }
  30078. else
  30079. {
  30080. Thread::sleep (2);
  30081. }
  30082. }
  30083. else if (pipe != 0)
  30084. {
  30085. if (! pipe->isOpen())
  30086. {
  30087. {
  30088. const ScopedLock sl (pipeAndSocketLock);
  30089. pipe = 0;
  30090. }
  30091. connectionLostInt();
  30092. break;
  30093. }
  30094. else
  30095. {
  30096. if (! readNextMessageInt())
  30097. break;
  30098. }
  30099. }
  30100. else
  30101. {
  30102. break;
  30103. }
  30104. }
  30105. }
  30106. END_JUCE_NAMESPACE
  30107. /*** End of inlined file: juce_InterprocessConnection.cpp ***/
  30108. /*** Start of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30109. BEGIN_JUCE_NAMESPACE
  30110. InterprocessConnectionServer::InterprocessConnectionServer()
  30111. : Thread ("Juce IPC server")
  30112. {
  30113. }
  30114. InterprocessConnectionServer::~InterprocessConnectionServer()
  30115. {
  30116. stop();
  30117. }
  30118. bool InterprocessConnectionServer::beginWaitingForSocket (const int portNumber)
  30119. {
  30120. stop();
  30121. socket = new StreamingSocket();
  30122. if (socket->createListener (portNumber))
  30123. {
  30124. startThread();
  30125. return true;
  30126. }
  30127. socket = 0;
  30128. return false;
  30129. }
  30130. void InterprocessConnectionServer::stop()
  30131. {
  30132. signalThreadShouldExit();
  30133. if (socket != 0)
  30134. socket->close();
  30135. stopThread (4000);
  30136. socket = 0;
  30137. }
  30138. void InterprocessConnectionServer::run()
  30139. {
  30140. while ((! threadShouldExit()) && socket != 0)
  30141. {
  30142. ScopedPointer <StreamingSocket> clientSocket (socket->waitForNextConnection());
  30143. if (clientSocket != 0)
  30144. {
  30145. InterprocessConnection* newConnection = createConnectionObject();
  30146. if (newConnection != 0)
  30147. newConnection->initialiseWithSocket (clientSocket.release());
  30148. }
  30149. }
  30150. }
  30151. END_JUCE_NAMESPACE
  30152. /*** End of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30153. /*** Start of inlined file: juce_Message.cpp ***/
  30154. BEGIN_JUCE_NAMESPACE
  30155. Message::Message() throw()
  30156. {
  30157. }
  30158. Message::~Message() throw()
  30159. {
  30160. }
  30161. Message::Message (const int intParameter1_,
  30162. const int intParameter2_,
  30163. const int intParameter3_,
  30164. void* const pointerParameter_) throw()
  30165. : intParameter1 (intParameter1_),
  30166. intParameter2 (intParameter2_),
  30167. intParameter3 (intParameter3_),
  30168. pointerParameter (pointerParameter_)
  30169. {
  30170. }
  30171. END_JUCE_NAMESPACE
  30172. /*** End of inlined file: juce_Message.cpp ***/
  30173. /*** Start of inlined file: juce_MessageListener.cpp ***/
  30174. BEGIN_JUCE_NAMESPACE
  30175. MessageListener::MessageListener() throw()
  30176. {
  30177. // are you trying to create a messagelistener before or after juce has been intialised??
  30178. jassert (MessageManager::instance != 0);
  30179. if (MessageManager::instance != 0)
  30180. MessageManager::instance->messageListeners.add (this);
  30181. }
  30182. MessageListener::~MessageListener()
  30183. {
  30184. if (MessageManager::instance != 0)
  30185. MessageManager::instance->messageListeners.removeValue (this);
  30186. }
  30187. void MessageListener::postMessage (Message* const message) const throw()
  30188. {
  30189. message->messageRecipient = const_cast <MessageListener*> (this);
  30190. if (MessageManager::instance == 0)
  30191. MessageManager::getInstance();
  30192. MessageManager::instance->postMessageToQueue (message);
  30193. }
  30194. bool MessageListener::isValidMessageListener() const throw()
  30195. {
  30196. return (MessageManager::instance != 0)
  30197. && MessageManager::instance->messageListeners.contains (this);
  30198. }
  30199. END_JUCE_NAMESPACE
  30200. /*** End of inlined file: juce_MessageListener.cpp ***/
  30201. /*** Start of inlined file: juce_MessageManager.cpp ***/
  30202. BEGIN_JUCE_NAMESPACE
  30203. // platform-specific functions..
  30204. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages);
  30205. bool juce_postMessageToSystemQueue (void* message);
  30206. MessageManager* MessageManager::instance = 0;
  30207. static const int quitMessageId = 0xfffff321;
  30208. MessageManager::MessageManager() throw()
  30209. : quitMessagePosted (false),
  30210. quitMessageReceived (false),
  30211. threadWithLock (0)
  30212. {
  30213. messageThreadId = Thread::getCurrentThreadId();
  30214. }
  30215. MessageManager::~MessageManager() throw()
  30216. {
  30217. broadcastListeners = 0;
  30218. doPlatformSpecificShutdown();
  30219. jassert (instance == this);
  30220. instance = 0; // do this last in case this instance is still needed by doPlatformSpecificShutdown()
  30221. }
  30222. MessageManager* MessageManager::getInstance() throw()
  30223. {
  30224. if (instance == 0)
  30225. {
  30226. instance = new MessageManager();
  30227. doPlatformSpecificInitialisation();
  30228. }
  30229. return instance;
  30230. }
  30231. void MessageManager::postMessageToQueue (Message* const message)
  30232. {
  30233. if (quitMessagePosted || ! juce_postMessageToSystemQueue (message))
  30234. delete message;
  30235. }
  30236. CallbackMessage::CallbackMessage() throw() {}
  30237. CallbackMessage::~CallbackMessage() throw() {}
  30238. void CallbackMessage::post()
  30239. {
  30240. if (MessageManager::instance != 0)
  30241. MessageManager::instance->postCallbackMessage (this);
  30242. }
  30243. void MessageManager::postCallbackMessage (Message* const message)
  30244. {
  30245. message->messageRecipient = 0;
  30246. postMessageToQueue (message);
  30247. }
  30248. // not for public use..
  30249. void MessageManager::deliverMessage (void* message)
  30250. {
  30251. const ScopedPointer <Message> m ((Message*) message);
  30252. MessageListener* const recipient = m->messageRecipient;
  30253. JUCE_TRY
  30254. {
  30255. if (messageListeners.contains (recipient))
  30256. {
  30257. recipient->handleMessage (*m);
  30258. }
  30259. else if (recipient == 0)
  30260. {
  30261. if (m->intParameter1 == quitMessageId)
  30262. {
  30263. quitMessageReceived = true;
  30264. }
  30265. else
  30266. {
  30267. CallbackMessage* const cm = dynamic_cast <CallbackMessage*> ((Message*) m);
  30268. if (cm != 0)
  30269. cm->messageCallback();
  30270. }
  30271. }
  30272. }
  30273. JUCE_CATCH_EXCEPTION
  30274. }
  30275. #if ! (JUCE_MAC || JUCE_IPHONE)
  30276. void MessageManager::runDispatchLoop()
  30277. {
  30278. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30279. runDispatchLoopUntil (-1);
  30280. }
  30281. void MessageManager::stopDispatchLoop()
  30282. {
  30283. Message* const m = new Message (quitMessageId, 0, 0, 0);
  30284. m->messageRecipient = 0;
  30285. postMessageToQueue (m);
  30286. quitMessagePosted = true;
  30287. }
  30288. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  30289. {
  30290. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30291. const int64 endTime = Time::currentTimeMillis() + millisecondsToRunFor;
  30292. while ((millisecondsToRunFor < 0 || endTime > Time::currentTimeMillis())
  30293. && ! quitMessageReceived)
  30294. {
  30295. JUCE_TRY
  30296. {
  30297. if (! juce_dispatchNextMessageOnSystemQueue (millisecondsToRunFor >= 0))
  30298. {
  30299. const int msToWait = (int) (endTime - Time::currentTimeMillis());
  30300. if (msToWait > 0)
  30301. Thread::sleep (jmin (5, msToWait));
  30302. }
  30303. }
  30304. JUCE_CATCH_EXCEPTION
  30305. }
  30306. return ! quitMessageReceived;
  30307. }
  30308. #endif
  30309. void MessageManager::deliverBroadcastMessage (const String& value)
  30310. {
  30311. if (broadcastListeners != 0)
  30312. broadcastListeners->sendActionMessage (value);
  30313. }
  30314. void MessageManager::registerBroadcastListener (ActionListener* const listener) throw()
  30315. {
  30316. if (broadcastListeners == 0)
  30317. broadcastListeners = new ActionListenerList();
  30318. broadcastListeners->addActionListener (listener);
  30319. }
  30320. void MessageManager::deregisterBroadcastListener (ActionListener* const listener) throw()
  30321. {
  30322. if (broadcastListeners != 0)
  30323. broadcastListeners->removeActionListener (listener);
  30324. }
  30325. bool MessageManager::isThisTheMessageThread() const throw()
  30326. {
  30327. return Thread::getCurrentThreadId() == messageThreadId;
  30328. }
  30329. void MessageManager::setCurrentThreadAsMessageThread()
  30330. {
  30331. if (messageThreadId != Thread::getCurrentThreadId())
  30332. {
  30333. messageThreadId = Thread::getCurrentThreadId();
  30334. // This is needed on windows to make sure the message window is created by this thread
  30335. doPlatformSpecificShutdown();
  30336. doPlatformSpecificInitialisation();
  30337. }
  30338. }
  30339. bool MessageManager::currentThreadHasLockedMessageManager() const throw()
  30340. {
  30341. const Thread::ThreadID thisThread = Thread::getCurrentThreadId();
  30342. return thisThread == messageThreadId || thisThread == threadWithLock;
  30343. }
  30344. class MessageManagerLock::SharedEvents : public ReferenceCountedObject
  30345. {
  30346. public:
  30347. SharedEvents() {}
  30348. ~SharedEvents() {}
  30349. WaitableEvent lockedEvent, releaseEvent;
  30350. private:
  30351. SharedEvents (const SharedEvents&);
  30352. SharedEvents& operator= (const SharedEvents&);
  30353. };
  30354. class MessageManagerLock::BlockingMessage : public CallbackMessage
  30355. {
  30356. public:
  30357. BlockingMessage (MessageManagerLock::SharedEvents* const events_) : events (events_) {}
  30358. ~BlockingMessage() throw() {}
  30359. void messageCallback()
  30360. {
  30361. events->lockedEvent.signal();
  30362. events->releaseEvent.wait();
  30363. }
  30364. juce_UseDebuggingNewOperator
  30365. private:
  30366. ReferenceCountedObjectPtr <MessageManagerLock::SharedEvents> events;
  30367. BlockingMessage (const BlockingMessage&);
  30368. BlockingMessage& operator= (const BlockingMessage&);
  30369. };
  30370. MessageManagerLock::MessageManagerLock (Thread* const threadToCheck) throw()
  30371. : sharedEvents (0),
  30372. locked (false)
  30373. {
  30374. init (threadToCheck, 0);
  30375. }
  30376. MessageManagerLock::MessageManagerLock (ThreadPoolJob* const jobToCheckForExitSignal) throw()
  30377. : sharedEvents (0),
  30378. locked (false)
  30379. {
  30380. init (0, jobToCheckForExitSignal);
  30381. }
  30382. void MessageManagerLock::init (Thread* const threadToCheck, ThreadPoolJob* const job) throw()
  30383. {
  30384. if (MessageManager::instance != 0)
  30385. {
  30386. if (MessageManager::instance->currentThreadHasLockedMessageManager())
  30387. {
  30388. locked = true; // either we're on the message thread, or this is a re-entrant call.
  30389. }
  30390. else
  30391. {
  30392. if (threadToCheck == 0 && job == 0)
  30393. {
  30394. MessageManager::instance->lockingLock.enter();
  30395. }
  30396. else
  30397. {
  30398. while (! MessageManager::instance->lockingLock.tryEnter())
  30399. {
  30400. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30401. || (job != 0 && job->shouldExit()))
  30402. return;
  30403. Thread::sleep (1);
  30404. }
  30405. }
  30406. sharedEvents = new SharedEvents();
  30407. sharedEvents->incReferenceCount();
  30408. (new BlockingMessage (sharedEvents))->post();
  30409. while (! sharedEvents->lockedEvent.wait (50))
  30410. {
  30411. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30412. || (job != 0 && job->shouldExit()))
  30413. {
  30414. sharedEvents->releaseEvent.signal();
  30415. sharedEvents->decReferenceCount();
  30416. sharedEvents = 0;
  30417. MessageManager::instance->lockingLock.exit();
  30418. return;
  30419. }
  30420. }
  30421. jassert (MessageManager::instance->threadWithLock == 0);
  30422. MessageManager::instance->threadWithLock = Thread::getCurrentThreadId();
  30423. locked = true;
  30424. }
  30425. }
  30426. }
  30427. MessageManagerLock::~MessageManagerLock() throw()
  30428. {
  30429. if (sharedEvents != 0)
  30430. {
  30431. jassert (MessageManager::instance == 0 || MessageManager::instance->currentThreadHasLockedMessageManager());
  30432. sharedEvents->releaseEvent.signal();
  30433. sharedEvents->decReferenceCount();
  30434. if (MessageManager::instance != 0)
  30435. {
  30436. MessageManager::instance->threadWithLock = 0;
  30437. MessageManager::instance->lockingLock.exit();
  30438. }
  30439. }
  30440. }
  30441. END_JUCE_NAMESPACE
  30442. /*** End of inlined file: juce_MessageManager.cpp ***/
  30443. /*** Start of inlined file: juce_MultiTimer.cpp ***/
  30444. BEGIN_JUCE_NAMESPACE
  30445. class MultiTimer::MultiTimerCallback : public Timer
  30446. {
  30447. public:
  30448. MultiTimerCallback (const int timerId_, MultiTimer& owner_)
  30449. : timerId (timerId_),
  30450. owner (owner_)
  30451. {
  30452. }
  30453. ~MultiTimerCallback()
  30454. {
  30455. }
  30456. void timerCallback()
  30457. {
  30458. owner.timerCallback (timerId);
  30459. }
  30460. const int timerId;
  30461. private:
  30462. MultiTimer& owner;
  30463. };
  30464. MultiTimer::MultiTimer() throw()
  30465. {
  30466. }
  30467. MultiTimer::MultiTimer (const MultiTimer&) throw()
  30468. {
  30469. }
  30470. MultiTimer::~MultiTimer()
  30471. {
  30472. const ScopedLock sl (timerListLock);
  30473. timers.clear();
  30474. }
  30475. void MultiTimer::startTimer (const int timerId, const int intervalInMilliseconds) throw()
  30476. {
  30477. const ScopedLock sl (timerListLock);
  30478. for (int i = timers.size(); --i >= 0;)
  30479. {
  30480. MultiTimerCallback* const t = timers.getUnchecked(i);
  30481. if (t->timerId == timerId)
  30482. {
  30483. t->startTimer (intervalInMilliseconds);
  30484. return;
  30485. }
  30486. }
  30487. MultiTimerCallback* const newTimer = new MultiTimerCallback (timerId, *this);
  30488. timers.add (newTimer);
  30489. newTimer->startTimer (intervalInMilliseconds);
  30490. }
  30491. void MultiTimer::stopTimer (const int timerId) throw()
  30492. {
  30493. const ScopedLock sl (timerListLock);
  30494. for (int i = timers.size(); --i >= 0;)
  30495. {
  30496. MultiTimerCallback* const t = timers.getUnchecked(i);
  30497. if (t->timerId == timerId)
  30498. t->stopTimer();
  30499. }
  30500. }
  30501. bool MultiTimer::isTimerRunning (const int timerId) const throw()
  30502. {
  30503. const ScopedLock sl (timerListLock);
  30504. for (int i = timers.size(); --i >= 0;)
  30505. {
  30506. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30507. if (t->timerId == timerId)
  30508. return t->isTimerRunning();
  30509. }
  30510. return false;
  30511. }
  30512. int MultiTimer::getTimerInterval (const int timerId) const throw()
  30513. {
  30514. const ScopedLock sl (timerListLock);
  30515. for (int i = timers.size(); --i >= 0;)
  30516. {
  30517. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30518. if (t->timerId == timerId)
  30519. return t->getTimerInterval();
  30520. }
  30521. return 0;
  30522. }
  30523. END_JUCE_NAMESPACE
  30524. /*** End of inlined file: juce_MultiTimer.cpp ***/
  30525. /*** Start of inlined file: juce_Timer.cpp ***/
  30526. BEGIN_JUCE_NAMESPACE
  30527. class InternalTimerThread : private Thread,
  30528. private MessageListener,
  30529. private DeletedAtShutdown,
  30530. private AsyncUpdater
  30531. {
  30532. public:
  30533. InternalTimerThread()
  30534. : Thread ("Juce Timer"),
  30535. firstTimer (0),
  30536. callbackNeeded (false)
  30537. {
  30538. triggerAsyncUpdate();
  30539. }
  30540. ~InternalTimerThread() throw()
  30541. {
  30542. stopThread (4000);
  30543. jassert (instance == this || instance == 0);
  30544. if (instance == this)
  30545. instance = 0;
  30546. }
  30547. void run()
  30548. {
  30549. uint32 lastTime = Time::getMillisecondCounter();
  30550. while (! threadShouldExit())
  30551. {
  30552. const uint32 now = Time::getMillisecondCounter();
  30553. if (now <= lastTime)
  30554. {
  30555. wait (2);
  30556. continue;
  30557. }
  30558. const int elapsed = now - lastTime;
  30559. lastTime = now;
  30560. int timeUntilFirstTimer = 1000;
  30561. {
  30562. const ScopedLock sl (lock);
  30563. decrementAllCounters (elapsed);
  30564. if (firstTimer != 0)
  30565. timeUntilFirstTimer = firstTimer->countdownMs;
  30566. }
  30567. if (timeUntilFirstTimer <= 0)
  30568. {
  30569. if (callbackNeeded.set (true))
  30570. {
  30571. postMessage (new Message());
  30572. const uint32 messageDeliveryTimeout = now + 2000;
  30573. while (callbackNeeded.get())
  30574. {
  30575. wait (4);
  30576. if (threadShouldExit())
  30577. return;
  30578. if (Time::getMillisecondCounter() > messageDeliveryTimeout)
  30579. break;
  30580. }
  30581. }
  30582. }
  30583. else
  30584. {
  30585. // don't wait for too long because running this loop also helps keep the
  30586. // Time::getApproximateMillisecondTimer value stay up-to-date
  30587. wait (jlimit (1, 50, timeUntilFirstTimer));
  30588. }
  30589. }
  30590. }
  30591. void callTimers()
  30592. {
  30593. const ScopedLock sl (lock);
  30594. while (firstTimer != 0 && firstTimer->countdownMs <= 0)
  30595. {
  30596. Timer* const t = firstTimer;
  30597. t->countdownMs = t->periodMs;
  30598. removeTimer (t);
  30599. addTimer (t);
  30600. const ScopedUnlock ul (lock);
  30601. JUCE_TRY
  30602. {
  30603. t->timerCallback();
  30604. }
  30605. JUCE_CATCH_EXCEPTION
  30606. }
  30607. callbackNeeded.set (false);
  30608. }
  30609. void handleMessage (const Message&)
  30610. {
  30611. callTimers();
  30612. }
  30613. void callTimersSynchronously()
  30614. {
  30615. if (! isThreadRunning())
  30616. {
  30617. // (This is relied on by some plugins in cases where the MM has
  30618. // had to restart and the async callback never started)
  30619. cancelPendingUpdate();
  30620. triggerAsyncUpdate();
  30621. }
  30622. callTimers();
  30623. }
  30624. static void callAnyTimersSynchronously()
  30625. {
  30626. if (InternalTimerThread::instance != 0)
  30627. InternalTimerThread::instance->callTimersSynchronously();
  30628. }
  30629. static inline void add (Timer* const tim) throw()
  30630. {
  30631. if (instance == 0)
  30632. instance = new InternalTimerThread();
  30633. const ScopedLock sl (instance->lock);
  30634. instance->addTimer (tim);
  30635. }
  30636. static inline void remove (Timer* const tim) throw()
  30637. {
  30638. if (instance != 0)
  30639. {
  30640. const ScopedLock sl (instance->lock);
  30641. instance->removeTimer (tim);
  30642. }
  30643. }
  30644. static inline void resetCounter (Timer* const tim,
  30645. const int newCounter) throw()
  30646. {
  30647. if (instance != 0)
  30648. {
  30649. tim->countdownMs = newCounter;
  30650. tim->periodMs = newCounter;
  30651. if ((tim->next != 0 && tim->next->countdownMs < tim->countdownMs)
  30652. || (tim->previous != 0 && tim->previous->countdownMs > tim->countdownMs))
  30653. {
  30654. const ScopedLock sl (instance->lock);
  30655. instance->removeTimer (tim);
  30656. instance->addTimer (tim);
  30657. }
  30658. }
  30659. }
  30660. private:
  30661. friend class Timer;
  30662. static InternalTimerThread* instance;
  30663. static CriticalSection lock;
  30664. Timer* volatile firstTimer;
  30665. class AtomicBool
  30666. {
  30667. public:
  30668. AtomicBool (const bool value) throw() : value (static_cast<int32> (value)) {}
  30669. ~AtomicBool() throw() {}
  30670. bool get() const throw() { return value != 0; }
  30671. bool set (const bool newValue) { return Atomic::compareAndExchange (value, newValue ? 1 : 0, value) != 0; }
  30672. private:
  30673. int32 value;
  30674. AtomicBool (const AtomicBool&);
  30675. AtomicBool& operator= (const AtomicBool&);
  30676. };
  30677. AtomicBool callbackNeeded;
  30678. void addTimer (Timer* const t) throw()
  30679. {
  30680. #ifdef JUCE_DEBUG
  30681. Timer* tt = firstTimer;
  30682. while (tt != 0)
  30683. {
  30684. // trying to add a timer that's already here - shouldn't get to this point,
  30685. // so if you get this assertion, let me know!
  30686. jassert (tt != t);
  30687. tt = tt->next;
  30688. }
  30689. jassert (t->previous == 0 && t->next == 0);
  30690. #endif
  30691. Timer* i = firstTimer;
  30692. if (i == 0 || i->countdownMs > t->countdownMs)
  30693. {
  30694. t->next = firstTimer;
  30695. firstTimer = t;
  30696. }
  30697. else
  30698. {
  30699. while (i->next != 0 && i->next->countdownMs <= t->countdownMs)
  30700. i = i->next;
  30701. jassert (i != 0);
  30702. t->next = i->next;
  30703. t->previous = i;
  30704. i->next = t;
  30705. }
  30706. if (t->next != 0)
  30707. t->next->previous = t;
  30708. jassert ((t->next == 0 || t->next->countdownMs >= t->countdownMs)
  30709. && (t->previous == 0 || t->previous->countdownMs <= t->countdownMs));
  30710. notify();
  30711. }
  30712. void removeTimer (Timer* const t) throw()
  30713. {
  30714. #ifdef JUCE_DEBUG
  30715. Timer* tt = firstTimer;
  30716. bool found = false;
  30717. while (tt != 0)
  30718. {
  30719. if (tt == t)
  30720. {
  30721. found = true;
  30722. break;
  30723. }
  30724. tt = tt->next;
  30725. }
  30726. // trying to remove a timer that's not here - shouldn't get to this point,
  30727. // so if you get this assertion, let me know!
  30728. jassert (found);
  30729. #endif
  30730. if (t->previous != 0)
  30731. {
  30732. jassert (firstTimer != t);
  30733. t->previous->next = t->next;
  30734. }
  30735. else
  30736. {
  30737. jassert (firstTimer == t);
  30738. firstTimer = t->next;
  30739. }
  30740. if (t->next != 0)
  30741. t->next->previous = t->previous;
  30742. t->next = 0;
  30743. t->previous = 0;
  30744. }
  30745. void decrementAllCounters (const int numMillisecs) const
  30746. {
  30747. Timer* t = firstTimer;
  30748. while (t != 0)
  30749. {
  30750. t->countdownMs -= numMillisecs;
  30751. t = t->next;
  30752. }
  30753. }
  30754. void handleAsyncUpdate()
  30755. {
  30756. startThread (7);
  30757. }
  30758. InternalTimerThread (const InternalTimerThread&);
  30759. InternalTimerThread& operator= (const InternalTimerThread&);
  30760. };
  30761. InternalTimerThread* InternalTimerThread::instance = 0;
  30762. CriticalSection InternalTimerThread::lock;
  30763. void juce_callAnyTimersSynchronously()
  30764. {
  30765. InternalTimerThread::callAnyTimersSynchronously();
  30766. }
  30767. #ifdef JUCE_DEBUG
  30768. static SortedSet <Timer*> activeTimers;
  30769. #endif
  30770. Timer::Timer() throw()
  30771. : countdownMs (0),
  30772. periodMs (0),
  30773. previous (0),
  30774. next (0)
  30775. {
  30776. #ifdef JUCE_DEBUG
  30777. activeTimers.add (this);
  30778. #endif
  30779. }
  30780. Timer::Timer (const Timer&) throw()
  30781. : countdownMs (0),
  30782. periodMs (0),
  30783. previous (0),
  30784. next (0)
  30785. {
  30786. #ifdef JUCE_DEBUG
  30787. activeTimers.add (this);
  30788. #endif
  30789. }
  30790. Timer::~Timer()
  30791. {
  30792. stopTimer();
  30793. #ifdef JUCE_DEBUG
  30794. activeTimers.removeValue (this);
  30795. #endif
  30796. }
  30797. void Timer::startTimer (const int interval) throw()
  30798. {
  30799. const ScopedLock sl (InternalTimerThread::lock);
  30800. #ifdef JUCE_DEBUG
  30801. // this isn't a valid object! Your timer might be a dangling pointer or something..
  30802. jassert (activeTimers.contains (this));
  30803. #endif
  30804. if (periodMs == 0)
  30805. {
  30806. countdownMs = interval;
  30807. periodMs = jmax (1, interval);
  30808. InternalTimerThread::add (this);
  30809. }
  30810. else
  30811. {
  30812. InternalTimerThread::resetCounter (this, interval);
  30813. }
  30814. }
  30815. void Timer::stopTimer() throw()
  30816. {
  30817. const ScopedLock sl (InternalTimerThread::lock);
  30818. #ifdef JUCE_DEBUG
  30819. // this isn't a valid object! Your timer might be a dangling pointer or something..
  30820. jassert (activeTimers.contains (this));
  30821. #endif
  30822. if (periodMs > 0)
  30823. {
  30824. InternalTimerThread::remove (this);
  30825. periodMs = 0;
  30826. }
  30827. }
  30828. END_JUCE_NAMESPACE
  30829. /*** End of inlined file: juce_Timer.cpp ***/
  30830. #endif
  30831. #if JUCE_BUILD_GUI
  30832. /*** Start of inlined file: juce_Component.cpp ***/
  30833. BEGIN_JUCE_NAMESPACE
  30834. Component* Component::currentlyFocusedComponent = 0;
  30835. static Array <Component*> modalComponentStack, modalComponentReturnValueKeys;
  30836. static Array <int> modalReturnValues;
  30837. enum ComponentMessageNumbers
  30838. {
  30839. customCommandMessage = 0x7fff0001,
  30840. exitModalStateMessage = 0x7fff0002
  30841. };
  30842. #define checkMessageManagerIsLocked jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  30843. static uint32 nextComponentUID = 0;
  30844. Component::Component()
  30845. : parentComponent_ (0),
  30846. componentUID (++nextComponentUID),
  30847. numDeepMouseListeners (0),
  30848. lookAndFeel_ (0),
  30849. effect_ (0),
  30850. bufferedImage_ (0),
  30851. mouseListeners_ (0),
  30852. keyListeners_ (0),
  30853. componentFlags_ (0)
  30854. {
  30855. }
  30856. Component::Component (const String& name)
  30857. : componentName_ (name),
  30858. parentComponent_ (0),
  30859. componentUID (++nextComponentUID),
  30860. numDeepMouseListeners (0),
  30861. lookAndFeel_ (0),
  30862. effect_ (0),
  30863. bufferedImage_ (0),
  30864. mouseListeners_ (0),
  30865. keyListeners_ (0),
  30866. componentFlags_ (0)
  30867. {
  30868. }
  30869. Component::~Component()
  30870. {
  30871. componentListeners.call (&ComponentListener::componentBeingDeleted, *this);
  30872. if (parentComponent_ != 0)
  30873. {
  30874. parentComponent_->removeChildComponent (this);
  30875. }
  30876. else if ((currentlyFocusedComponent == this)
  30877. || isParentOf (currentlyFocusedComponent))
  30878. {
  30879. giveAwayFocus();
  30880. }
  30881. if (flags.hasHeavyweightPeerFlag)
  30882. removeFromDesktop();
  30883. modalComponentStack.removeValue (this);
  30884. for (int i = childComponentList_.size(); --i >= 0;)
  30885. childComponentList_.getUnchecked(i)->parentComponent_ = 0;
  30886. delete bufferedImage_;
  30887. delete mouseListeners_;
  30888. delete keyListeners_;
  30889. }
  30890. void Component::setName (const String& name)
  30891. {
  30892. // if component methods are being called from threads other than the message
  30893. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  30894. checkMessageManagerIsLocked
  30895. if (componentName_ != name)
  30896. {
  30897. componentName_ = name;
  30898. if (flags.hasHeavyweightPeerFlag)
  30899. {
  30900. ComponentPeer* const peer = getPeer();
  30901. jassert (peer != 0);
  30902. if (peer != 0)
  30903. peer->setTitle (name);
  30904. }
  30905. BailOutChecker checker (this);
  30906. componentListeners.callChecked (checker, &ComponentListener::componentNameChanged, *this);
  30907. }
  30908. }
  30909. void Component::setVisible (bool shouldBeVisible)
  30910. {
  30911. if (flags.visibleFlag != shouldBeVisible)
  30912. {
  30913. // if component methods are being called from threads other than the message
  30914. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  30915. checkMessageManagerIsLocked
  30916. SafePointer<Component> safePointer (this);
  30917. flags.visibleFlag = shouldBeVisible;
  30918. internalRepaint (0, 0, getWidth(), getHeight());
  30919. sendFakeMouseMove();
  30920. if (! shouldBeVisible)
  30921. {
  30922. if (currentlyFocusedComponent == this
  30923. || isParentOf (currentlyFocusedComponent))
  30924. {
  30925. if (parentComponent_ != 0)
  30926. parentComponent_->grabKeyboardFocus();
  30927. else
  30928. giveAwayFocus();
  30929. }
  30930. }
  30931. if (safePointer != 0)
  30932. {
  30933. sendVisibilityChangeMessage();
  30934. if (safePointer != 0 && flags.hasHeavyweightPeerFlag)
  30935. {
  30936. ComponentPeer* const peer = getPeer();
  30937. jassert (peer != 0);
  30938. if (peer != 0)
  30939. {
  30940. peer->setVisible (shouldBeVisible);
  30941. internalHierarchyChanged();
  30942. }
  30943. }
  30944. }
  30945. }
  30946. }
  30947. void Component::visibilityChanged()
  30948. {
  30949. }
  30950. void Component::sendVisibilityChangeMessage()
  30951. {
  30952. BailOutChecker checker (this);
  30953. visibilityChanged();
  30954. if (! checker.shouldBailOut())
  30955. componentListeners.callChecked (checker, &ComponentListener::componentVisibilityChanged, *this);
  30956. }
  30957. bool Component::isShowing() const
  30958. {
  30959. if (flags.visibleFlag)
  30960. {
  30961. if (parentComponent_ != 0)
  30962. {
  30963. return parentComponent_->isShowing();
  30964. }
  30965. else
  30966. {
  30967. const ComponentPeer* const peer = getPeer();
  30968. return peer != 0 && ! peer->isMinimised();
  30969. }
  30970. }
  30971. return false;
  30972. }
  30973. class FadeOutProxyComponent : public Component,
  30974. public Timer
  30975. {
  30976. public:
  30977. FadeOutProxyComponent (Component* comp,
  30978. const int fadeLengthMs,
  30979. const int deltaXToMove,
  30980. const int deltaYToMove,
  30981. const float scaleFactorAtEnd)
  30982. : lastTime (0),
  30983. alpha (1.0f),
  30984. scale (1.0f)
  30985. {
  30986. image = comp->createComponentSnapshot (Rectangle<int> (0, 0, comp->getWidth(), comp->getHeight()));
  30987. setBounds (comp->getBounds());
  30988. comp->getParentComponent()->addAndMakeVisible (this);
  30989. toBehind (comp);
  30990. alphaChangePerMs = -1.0f / (float)fadeLengthMs;
  30991. centreX = comp->getX() + comp->getWidth() * 0.5f;
  30992. xChangePerMs = deltaXToMove / (float)fadeLengthMs;
  30993. centreY = comp->getY() + comp->getHeight() * 0.5f;
  30994. yChangePerMs = deltaYToMove / (float)fadeLengthMs;
  30995. scaleChangePerMs = (scaleFactorAtEnd - 1.0f) / (float)fadeLengthMs;
  30996. setInterceptsMouseClicks (false, false);
  30997. // 30 fps is enough for a fade, but we need a higher rate if it's moving as well..
  30998. startTimer (1000 / ((deltaXToMove == 0 && deltaYToMove == 0) ? 30 : 50));
  30999. }
  31000. ~FadeOutProxyComponent()
  31001. {
  31002. delete image;
  31003. }
  31004. void paint (Graphics& g)
  31005. {
  31006. g.setOpacity (alpha);
  31007. g.drawImage (image,
  31008. 0, 0, getWidth(), getHeight(),
  31009. 0, 0, image->getWidth(), image->getHeight());
  31010. }
  31011. void timerCallback()
  31012. {
  31013. const uint32 now = Time::getMillisecondCounter();
  31014. if (lastTime == 0)
  31015. lastTime = now;
  31016. const int msPassed = (now > lastTime) ? now - lastTime : 0;
  31017. lastTime = now;
  31018. alpha += alphaChangePerMs * msPassed;
  31019. if (alpha > 0)
  31020. {
  31021. if (xChangePerMs != 0.0f || yChangePerMs != 0.0f || scaleChangePerMs != 0.0f)
  31022. {
  31023. centreX += xChangePerMs * msPassed;
  31024. centreY += yChangePerMs * msPassed;
  31025. scale += scaleChangePerMs * msPassed;
  31026. const int w = roundToInt (image->getWidth() * scale);
  31027. const int h = roundToInt (image->getHeight() * scale);
  31028. setBounds (roundToInt (centreX) - w / 2,
  31029. roundToInt (centreY) - h / 2,
  31030. w, h);
  31031. }
  31032. repaint();
  31033. }
  31034. else
  31035. {
  31036. delete this;
  31037. }
  31038. }
  31039. juce_UseDebuggingNewOperator
  31040. private:
  31041. Image* image;
  31042. uint32 lastTime;
  31043. float alpha, alphaChangePerMs;
  31044. float centreX, xChangePerMs;
  31045. float centreY, yChangePerMs;
  31046. float scale, scaleChangePerMs;
  31047. FadeOutProxyComponent (const FadeOutProxyComponent&);
  31048. FadeOutProxyComponent& operator= (const FadeOutProxyComponent&);
  31049. };
  31050. void Component::fadeOutComponent (const int millisecondsToFade,
  31051. const int deltaXToMove,
  31052. const int deltaYToMove,
  31053. const float scaleFactorAtEnd)
  31054. {
  31055. //xxx won't work for comps without parents
  31056. if (isShowing() && millisecondsToFade > 0)
  31057. new FadeOutProxyComponent (this, millisecondsToFade,
  31058. deltaXToMove, deltaYToMove, scaleFactorAtEnd);
  31059. setVisible (false);
  31060. }
  31061. bool Component::isValidComponent() const
  31062. {
  31063. return (this != 0) && isValidMessageListener();
  31064. }
  31065. void* Component::getWindowHandle() const
  31066. {
  31067. const ComponentPeer* const peer = getPeer();
  31068. if (peer != 0)
  31069. return peer->getNativeHandle();
  31070. return 0;
  31071. }
  31072. void Component::addToDesktop (int styleWanted, void* nativeWindowToAttachTo)
  31073. {
  31074. // if component methods are being called from threads other than the message
  31075. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31076. checkMessageManagerIsLocked
  31077. if (isOpaque())
  31078. styleWanted &= ~ComponentPeer::windowIsSemiTransparent;
  31079. else
  31080. styleWanted |= ComponentPeer::windowIsSemiTransparent;
  31081. int currentStyleFlags = 0;
  31082. // don't use getPeer(), so that we only get the peer that's specifically
  31083. // for this comp, and not for one of its parents.
  31084. ComponentPeer* peer = ComponentPeer::getPeerFor (this);
  31085. if (peer != 0)
  31086. currentStyleFlags = peer->getStyleFlags();
  31087. if (styleWanted != currentStyleFlags || ! flags.hasHeavyweightPeerFlag)
  31088. {
  31089. SafePointer<Component> safePointer (this);
  31090. #if JUCE_LINUX
  31091. // it's wise to give the component a non-zero size before
  31092. // putting it on the desktop, as X windows get confused by this, and
  31093. // a (1, 1) minimum size is enforced here.
  31094. setSize (jmax (1, getWidth()),
  31095. jmax (1, getHeight()));
  31096. #endif
  31097. const Point<int> topLeft (relativePositionToGlobal (Point<int> (0, 0)));
  31098. bool wasFullscreen = false;
  31099. bool wasMinimised = false;
  31100. ComponentBoundsConstrainer* currentConstainer = 0;
  31101. Rectangle<int> oldNonFullScreenBounds;
  31102. if (peer != 0)
  31103. {
  31104. wasFullscreen = peer->isFullScreen();
  31105. wasMinimised = peer->isMinimised();
  31106. currentConstainer = peer->getConstrainer();
  31107. oldNonFullScreenBounds = peer->getNonFullScreenBounds();
  31108. removeFromDesktop();
  31109. setTopLeftPosition (topLeft.getX(), topLeft.getY());
  31110. }
  31111. if (parentComponent_ != 0)
  31112. parentComponent_->removeChildComponent (this);
  31113. if (safePointer != 0)
  31114. {
  31115. flags.hasHeavyweightPeerFlag = true;
  31116. peer = createNewPeer (styleWanted, nativeWindowToAttachTo);
  31117. Desktop::getInstance().addDesktopComponent (this);
  31118. bounds_.setPosition (topLeft);
  31119. peer->setBounds (topLeft.getX(), topLeft.getY(), getWidth(), getHeight(), false);
  31120. peer->setVisible (isVisible());
  31121. if (wasFullscreen)
  31122. {
  31123. peer->setFullScreen (true);
  31124. peer->setNonFullScreenBounds (oldNonFullScreenBounds);
  31125. }
  31126. if (wasMinimised)
  31127. peer->setMinimised (true);
  31128. if (isAlwaysOnTop())
  31129. peer->setAlwaysOnTop (true);
  31130. peer->setConstrainer (currentConstainer);
  31131. repaint();
  31132. }
  31133. internalHierarchyChanged();
  31134. }
  31135. }
  31136. void Component::removeFromDesktop()
  31137. {
  31138. // if component methods are being called from threads other than the message
  31139. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31140. checkMessageManagerIsLocked
  31141. if (flags.hasHeavyweightPeerFlag)
  31142. {
  31143. ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31144. flags.hasHeavyweightPeerFlag = false;
  31145. jassert (peer != 0);
  31146. delete peer;
  31147. Desktop::getInstance().removeDesktopComponent (this);
  31148. }
  31149. }
  31150. bool Component::isOnDesktop() const throw()
  31151. {
  31152. return flags.hasHeavyweightPeerFlag;
  31153. }
  31154. void Component::userTriedToCloseWindow()
  31155. {
  31156. /* This means that the user's trying to get rid of your window with the 'close window' system
  31157. menu option (on windows) or possibly the task manager - you should really handle this
  31158. and delete or hide your component in an appropriate way.
  31159. If you want to ignore the event and don't want to trigger this assertion, just override
  31160. this method and do nothing.
  31161. */
  31162. jassertfalse
  31163. }
  31164. void Component::minimisationStateChanged (bool)
  31165. {
  31166. }
  31167. void Component::setOpaque (const bool shouldBeOpaque)
  31168. {
  31169. if (shouldBeOpaque != flags.opaqueFlag)
  31170. {
  31171. flags.opaqueFlag = shouldBeOpaque;
  31172. if (flags.hasHeavyweightPeerFlag)
  31173. {
  31174. const ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31175. if (peer != 0)
  31176. {
  31177. // to make it recreate the heavyweight window
  31178. addToDesktop (peer->getStyleFlags());
  31179. }
  31180. }
  31181. repaint();
  31182. }
  31183. }
  31184. bool Component::isOpaque() const throw()
  31185. {
  31186. return flags.opaqueFlag;
  31187. }
  31188. void Component::setBufferedToImage (const bool shouldBeBuffered)
  31189. {
  31190. if (shouldBeBuffered != flags.bufferToImageFlag)
  31191. {
  31192. deleteAndZero (bufferedImage_);
  31193. flags.bufferToImageFlag = shouldBeBuffered;
  31194. }
  31195. }
  31196. void Component::toFront (const bool setAsForeground)
  31197. {
  31198. // if component methods are being called from threads other than the message
  31199. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31200. checkMessageManagerIsLocked
  31201. if (flags.hasHeavyweightPeerFlag)
  31202. {
  31203. ComponentPeer* const peer = getPeer();
  31204. if (peer != 0)
  31205. {
  31206. peer->toFront (setAsForeground);
  31207. if (setAsForeground && ! hasKeyboardFocus (true))
  31208. grabKeyboardFocus();
  31209. }
  31210. }
  31211. else if (parentComponent_ != 0)
  31212. {
  31213. if (parentComponent_->childComponentList_.getLast() != this)
  31214. {
  31215. const int index = parentComponent_->childComponentList_.indexOf (this);
  31216. if (index >= 0)
  31217. {
  31218. int insertIndex = -1;
  31219. if (! flags.alwaysOnTopFlag)
  31220. {
  31221. insertIndex = parentComponent_->childComponentList_.size() - 1;
  31222. while (insertIndex > 0
  31223. && parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31224. {
  31225. --insertIndex;
  31226. }
  31227. }
  31228. if (index != insertIndex)
  31229. {
  31230. parentComponent_->childComponentList_.move (index, insertIndex);
  31231. sendFakeMouseMove();
  31232. repaintParent();
  31233. }
  31234. }
  31235. }
  31236. if (setAsForeground)
  31237. {
  31238. internalBroughtToFront();
  31239. grabKeyboardFocus();
  31240. }
  31241. }
  31242. }
  31243. void Component::toBehind (Component* const other)
  31244. {
  31245. if (other != 0)
  31246. {
  31247. // the two components must belong to the same parent..
  31248. jassert (parentComponent_ == other->parentComponent_);
  31249. if (parentComponent_ != 0)
  31250. {
  31251. const int index = parentComponent_->childComponentList_.indexOf (this);
  31252. int otherIndex = parentComponent_->childComponentList_.indexOf (other);
  31253. if (index >= 0
  31254. && otherIndex >= 0
  31255. && index != otherIndex - 1
  31256. && other != this)
  31257. {
  31258. if (index < otherIndex)
  31259. --otherIndex;
  31260. parentComponent_->childComponentList_.move (index, otherIndex);
  31261. sendFakeMouseMove();
  31262. repaintParent();
  31263. }
  31264. }
  31265. else if (isOnDesktop())
  31266. {
  31267. jassert (other->isOnDesktop());
  31268. if (other->isOnDesktop())
  31269. {
  31270. ComponentPeer* const us = getPeer();
  31271. ComponentPeer* const them = other->getPeer();
  31272. jassert (us != 0 && them != 0);
  31273. if (us != 0 && them != 0)
  31274. us->toBehind (them);
  31275. }
  31276. }
  31277. }
  31278. }
  31279. void Component::toBack()
  31280. {
  31281. if (isOnDesktop())
  31282. {
  31283. jassertfalse //xxx need to add this to native window
  31284. }
  31285. else if (parentComponent_ != 0
  31286. && parentComponent_->childComponentList_.getFirst() != this)
  31287. {
  31288. const int index = parentComponent_->childComponentList_.indexOf (this);
  31289. if (index > 0)
  31290. {
  31291. int insertIndex = 0;
  31292. if (flags.alwaysOnTopFlag)
  31293. {
  31294. while (insertIndex < parentComponent_->childComponentList_.size()
  31295. && ! parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31296. {
  31297. ++insertIndex;
  31298. }
  31299. }
  31300. if (index != insertIndex)
  31301. {
  31302. parentComponent_->childComponentList_.move (index, insertIndex);
  31303. sendFakeMouseMove();
  31304. repaintParent();
  31305. }
  31306. }
  31307. }
  31308. }
  31309. void Component::setAlwaysOnTop (const bool shouldStayOnTop)
  31310. {
  31311. if (shouldStayOnTop != flags.alwaysOnTopFlag)
  31312. {
  31313. flags.alwaysOnTopFlag = shouldStayOnTop;
  31314. if (isOnDesktop())
  31315. {
  31316. ComponentPeer* const peer = getPeer();
  31317. jassert (peer != 0);
  31318. if (peer != 0)
  31319. {
  31320. if (! peer->setAlwaysOnTop (shouldStayOnTop))
  31321. {
  31322. // some kinds of peer can't change their always-on-top status, so
  31323. // for these, we'll need to create a new window
  31324. const int oldFlags = peer->getStyleFlags();
  31325. removeFromDesktop();
  31326. addToDesktop (oldFlags);
  31327. }
  31328. }
  31329. }
  31330. if (shouldStayOnTop)
  31331. toFront (false);
  31332. internalHierarchyChanged();
  31333. }
  31334. }
  31335. bool Component::isAlwaysOnTop() const throw()
  31336. {
  31337. return flags.alwaysOnTopFlag;
  31338. }
  31339. int Component::proportionOfWidth (const float proportion) const throw()
  31340. {
  31341. return roundToInt (proportion * bounds_.getWidth());
  31342. }
  31343. int Component::proportionOfHeight (const float proportion) const throw()
  31344. {
  31345. return roundToInt (proportion * bounds_.getHeight());
  31346. }
  31347. int Component::getParentWidth() const throw()
  31348. {
  31349. return (parentComponent_ != 0) ? parentComponent_->getWidth()
  31350. : getParentMonitorArea().getWidth();
  31351. }
  31352. int Component::getParentHeight() const throw()
  31353. {
  31354. return (parentComponent_ != 0) ? parentComponent_->getHeight()
  31355. : getParentMonitorArea().getHeight();
  31356. }
  31357. int Component::getScreenX() const
  31358. {
  31359. return getScreenPosition().getX();
  31360. }
  31361. int Component::getScreenY() const
  31362. {
  31363. return getScreenPosition().getY();
  31364. }
  31365. const Point<int> Component::getScreenPosition() const
  31366. {
  31367. return (parentComponent_ != 0) ? parentComponent_->getScreenPosition() + getPosition()
  31368. : (flags.hasHeavyweightPeerFlag ? getPeer()->getScreenPosition()
  31369. : getPosition());
  31370. }
  31371. const Rectangle<int> Component::getScreenBounds() const
  31372. {
  31373. return bounds_.withPosition (getScreenPosition());
  31374. }
  31375. const Point<int> Component::relativePositionToGlobal (const Point<int>& relativePosition) const
  31376. {
  31377. const Component* c = this;
  31378. Point<int> p (relativePosition);
  31379. do
  31380. {
  31381. if (c->flags.hasHeavyweightPeerFlag)
  31382. return c->getPeer()->relativePositionToGlobal (p);
  31383. p += c->getPosition();
  31384. c = c->parentComponent_;
  31385. }
  31386. while (c != 0);
  31387. return p;
  31388. }
  31389. const Point<int> Component::globalPositionToRelative (const Point<int>& screenPosition) const
  31390. {
  31391. if (flags.hasHeavyweightPeerFlag)
  31392. {
  31393. return getPeer()->globalPositionToRelative (screenPosition);
  31394. }
  31395. else
  31396. {
  31397. if (parentComponent_ != 0)
  31398. return parentComponent_->globalPositionToRelative (screenPosition) - getPosition();
  31399. return screenPosition - getPosition();
  31400. }
  31401. }
  31402. const Point<int> Component::relativePositionToOtherComponent (const Component* const targetComponent, const Point<int>& positionRelativeToThis) const
  31403. {
  31404. Point<int> p (positionRelativeToThis);
  31405. if (targetComponent != 0)
  31406. {
  31407. const Component* c = this;
  31408. do
  31409. {
  31410. if (c == targetComponent)
  31411. return p;
  31412. if (c->flags.hasHeavyweightPeerFlag)
  31413. {
  31414. p = c->getPeer()->relativePositionToGlobal (p);
  31415. break;
  31416. }
  31417. p += c->getPosition();
  31418. c = c->parentComponent_;
  31419. }
  31420. while (c != 0);
  31421. p = targetComponent->globalPositionToRelative (p);
  31422. }
  31423. return p;
  31424. }
  31425. void Component::setBounds (int x, int y, int w, int h)
  31426. {
  31427. // if component methods are being called from threads other than the message
  31428. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31429. checkMessageManagerIsLocked
  31430. if (w < 0) w = 0;
  31431. if (h < 0) h = 0;
  31432. const bool wasResized = (getWidth() != w || getHeight() != h);
  31433. const bool wasMoved = (getX() != x || getY() != y);
  31434. #ifdef JUCE_DEBUG
  31435. // It's a very bad idea to try to resize a window during its paint() method!
  31436. jassert (! (flags.isInsidePaintCall && wasResized && isOnDesktop()));
  31437. #endif
  31438. if (wasMoved || wasResized)
  31439. {
  31440. if (flags.visibleFlag)
  31441. {
  31442. // send a fake mouse move to trigger enter/exit messages if needed..
  31443. sendFakeMouseMove();
  31444. if (! flags.hasHeavyweightPeerFlag)
  31445. repaintParent();
  31446. }
  31447. bounds_.setBounds (x, y, w, h);
  31448. if (wasResized)
  31449. repaint();
  31450. else if (! flags.hasHeavyweightPeerFlag)
  31451. repaintParent();
  31452. if (flags.hasHeavyweightPeerFlag)
  31453. {
  31454. ComponentPeer* const peer = getPeer();
  31455. if (peer != 0)
  31456. {
  31457. if (wasMoved && wasResized)
  31458. peer->setBounds (getX(), getY(), getWidth(), getHeight(), false);
  31459. else if (wasMoved)
  31460. peer->setPosition (getX(), getY());
  31461. else if (wasResized)
  31462. peer->setSize (getWidth(), getHeight());
  31463. }
  31464. }
  31465. sendMovedResizedMessages (wasMoved, wasResized);
  31466. }
  31467. }
  31468. void Component::sendMovedResizedMessages (const bool wasMoved, const bool wasResized)
  31469. {
  31470. JUCE_TRY
  31471. {
  31472. if (wasMoved)
  31473. moved();
  31474. if (wasResized)
  31475. {
  31476. resized();
  31477. for (int i = childComponentList_.size(); --i >= 0;)
  31478. {
  31479. childComponentList_.getUnchecked(i)->parentSizeChanged();
  31480. i = jmin (i, childComponentList_.size());
  31481. }
  31482. }
  31483. BailOutChecker checker (this);
  31484. if (parentComponent_ != 0)
  31485. parentComponent_->childBoundsChanged (this);
  31486. if (! checker.shouldBailOut())
  31487. componentListeners.callChecked (checker, &ComponentListener::componentMovedOrResized,
  31488. *this, wasMoved, wasResized);
  31489. }
  31490. JUCE_CATCH_EXCEPTION
  31491. }
  31492. void Component::setSize (const int w, const int h)
  31493. {
  31494. setBounds (getX(), getY(), w, h);
  31495. }
  31496. void Component::setTopLeftPosition (const int x, const int y)
  31497. {
  31498. setBounds (x, y, getWidth(), getHeight());
  31499. }
  31500. void Component::setTopRightPosition (const int x, const int y)
  31501. {
  31502. setTopLeftPosition (x - getWidth(), y);
  31503. }
  31504. void Component::setBounds (const Rectangle<int>& r)
  31505. {
  31506. setBounds (r.getX(),
  31507. r.getY(),
  31508. r.getWidth(),
  31509. r.getHeight());
  31510. }
  31511. void Component::setBoundsRelative (const float x, const float y,
  31512. const float w, const float h)
  31513. {
  31514. const int pw = getParentWidth();
  31515. const int ph = getParentHeight();
  31516. setBounds (roundToInt (x * pw),
  31517. roundToInt (y * ph),
  31518. roundToInt (w * pw),
  31519. roundToInt (h * ph));
  31520. }
  31521. void Component::setCentrePosition (const int x, const int y)
  31522. {
  31523. setTopLeftPosition (x - getWidth() / 2,
  31524. y - getHeight() / 2);
  31525. }
  31526. void Component::setCentreRelative (const float x, const float y)
  31527. {
  31528. setCentrePosition (roundToInt (getParentWidth() * x),
  31529. roundToInt (getParentHeight() * y));
  31530. }
  31531. void Component::centreWithSize (const int width, const int height)
  31532. {
  31533. setBounds ((getParentWidth() - width) / 2,
  31534. (getParentHeight() - height) / 2,
  31535. width,
  31536. height);
  31537. }
  31538. void Component::setBoundsInset (const BorderSize& borders)
  31539. {
  31540. setBounds (borders.getLeft(),
  31541. borders.getTop(),
  31542. getParentWidth() - (borders.getLeftAndRight()),
  31543. getParentHeight() - (borders.getTopAndBottom()));
  31544. }
  31545. void Component::setBoundsToFit (int x, int y, int width, int height,
  31546. const Justification& justification,
  31547. const bool onlyReduceInSize)
  31548. {
  31549. // it's no good calling this method unless both the component and
  31550. // target rectangle have a finite size.
  31551. jassert (getWidth() > 0 && getHeight() > 0 && width > 0 && height > 0);
  31552. if (getWidth() > 0 && getHeight() > 0
  31553. && width > 0 && height > 0)
  31554. {
  31555. int newW, newH;
  31556. if (onlyReduceInSize && getWidth() <= width && getHeight() <= height)
  31557. {
  31558. newW = getWidth();
  31559. newH = getHeight();
  31560. }
  31561. else
  31562. {
  31563. const double imageRatio = getHeight() / (double) getWidth();
  31564. const double targetRatio = height / (double) width;
  31565. if (imageRatio <= targetRatio)
  31566. {
  31567. newW = width;
  31568. newH = jmin (height, roundToInt (newW * imageRatio));
  31569. }
  31570. else
  31571. {
  31572. newH = height;
  31573. newW = jmin (width, roundToInt (newH / imageRatio));
  31574. }
  31575. }
  31576. if (newW > 0 && newH > 0)
  31577. {
  31578. int newX, newY;
  31579. justification.applyToRectangle (newX, newY, newW, newH,
  31580. x, y, width, height);
  31581. setBounds (newX, newY, newW, newH);
  31582. }
  31583. }
  31584. }
  31585. bool Component::hitTest (int x, int y)
  31586. {
  31587. if (! flags.ignoresMouseClicksFlag)
  31588. return true;
  31589. if (flags.allowChildMouseClicksFlag)
  31590. {
  31591. for (int i = getNumChildComponents(); --i >= 0;)
  31592. {
  31593. Component* const c = getChildComponent (i);
  31594. if (c->isVisible()
  31595. && c->bounds_.contains (x, y)
  31596. && c->hitTest (x - c->getX(),
  31597. y - c->getY()))
  31598. {
  31599. return true;
  31600. }
  31601. }
  31602. }
  31603. return false;
  31604. }
  31605. void Component::setInterceptsMouseClicks (const bool allowClicks,
  31606. const bool allowClicksOnChildComponents) throw()
  31607. {
  31608. flags.ignoresMouseClicksFlag = ! allowClicks;
  31609. flags.allowChildMouseClicksFlag = allowClicksOnChildComponents;
  31610. }
  31611. void Component::getInterceptsMouseClicks (bool& allowsClicksOnThisComponent,
  31612. bool& allowsClicksOnChildComponents) const throw()
  31613. {
  31614. allowsClicksOnThisComponent = ! flags.ignoresMouseClicksFlag;
  31615. allowsClicksOnChildComponents = flags.allowChildMouseClicksFlag;
  31616. }
  31617. bool Component::contains (const int x, const int y)
  31618. {
  31619. if (((unsigned int) x) < (unsigned int) getWidth()
  31620. && ((unsigned int) y) < (unsigned int) getHeight()
  31621. && hitTest (x, y))
  31622. {
  31623. if (parentComponent_ != 0)
  31624. {
  31625. return parentComponent_->contains (x + getX(),
  31626. y + getY());
  31627. }
  31628. else if (flags.hasHeavyweightPeerFlag)
  31629. {
  31630. const ComponentPeer* const peer = getPeer();
  31631. if (peer != 0)
  31632. return peer->contains (Point<int> (x, y), true);
  31633. }
  31634. }
  31635. return false;
  31636. }
  31637. bool Component::reallyContains (int x, int y, const bool returnTrueIfWithinAChild)
  31638. {
  31639. if (! contains (x, y))
  31640. return false;
  31641. Component* p = this;
  31642. while (p->parentComponent_ != 0)
  31643. {
  31644. x += p->getX();
  31645. y += p->getY();
  31646. p = p->parentComponent_;
  31647. }
  31648. const Component* const c = p->getComponentAt (x, y);
  31649. return (c == this) || (returnTrueIfWithinAChild && isParentOf (c));
  31650. }
  31651. Component* Component::getComponentAt (const Point<int>& position)
  31652. {
  31653. return getComponentAt (position.getX(), position.getY());
  31654. }
  31655. Component* Component::getComponentAt (const int x, const int y)
  31656. {
  31657. if (flags.visibleFlag
  31658. && ((unsigned int) x) < (unsigned int) getWidth()
  31659. && ((unsigned int) y) < (unsigned int) getHeight()
  31660. && hitTest (x, y))
  31661. {
  31662. for (int i = childComponentList_.size(); --i >= 0;)
  31663. {
  31664. Component* const child = childComponentList_.getUnchecked(i);
  31665. Component* const c = child->getComponentAt (x - child->getX(),
  31666. y - child->getY());
  31667. if (c != 0)
  31668. return c;
  31669. }
  31670. return this;
  31671. }
  31672. return 0;
  31673. }
  31674. void Component::addChildComponent (Component* const child, int zOrder)
  31675. {
  31676. // if component methods are being called from threads other than the message
  31677. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31678. checkMessageManagerIsLocked
  31679. if (child != 0 && child->parentComponent_ != this)
  31680. {
  31681. if (child->parentComponent_ != 0)
  31682. child->parentComponent_->removeChildComponent (child);
  31683. else
  31684. child->removeFromDesktop();
  31685. child->parentComponent_ = this;
  31686. if (child->isVisible())
  31687. child->repaintParent();
  31688. if (! child->isAlwaysOnTop())
  31689. {
  31690. if (zOrder < 0 || zOrder > childComponentList_.size())
  31691. zOrder = childComponentList_.size();
  31692. while (zOrder > 0)
  31693. {
  31694. if (! childComponentList_.getUnchecked (zOrder - 1)->isAlwaysOnTop())
  31695. break;
  31696. --zOrder;
  31697. }
  31698. }
  31699. childComponentList_.insert (zOrder, child);
  31700. child->internalHierarchyChanged();
  31701. internalChildrenChanged();
  31702. }
  31703. }
  31704. void Component::addAndMakeVisible (Component* const child, int zOrder)
  31705. {
  31706. if (child != 0)
  31707. {
  31708. child->setVisible (true);
  31709. addChildComponent (child, zOrder);
  31710. }
  31711. }
  31712. void Component::removeChildComponent (Component* const child)
  31713. {
  31714. removeChildComponent (childComponentList_.indexOf (child));
  31715. }
  31716. Component* Component::removeChildComponent (const int index)
  31717. {
  31718. // if component methods are being called from threads other than the message
  31719. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31720. checkMessageManagerIsLocked
  31721. Component* const child = childComponentList_ [index];
  31722. if (child != 0)
  31723. {
  31724. sendFakeMouseMove();
  31725. child->repaintParent();
  31726. childComponentList_.remove (index);
  31727. child->parentComponent_ = 0;
  31728. JUCE_TRY
  31729. {
  31730. if ((currentlyFocusedComponent == child)
  31731. || child->isParentOf (currentlyFocusedComponent))
  31732. {
  31733. // get rid first to force the grabKeyboardFocus to change to us.
  31734. giveAwayFocus();
  31735. grabKeyboardFocus();
  31736. }
  31737. }
  31738. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  31739. catch (const std::exception& e)
  31740. {
  31741. currentlyFocusedComponent = 0;
  31742. Desktop::getInstance().triggerFocusCallback();
  31743. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  31744. }
  31745. catch (...)
  31746. {
  31747. currentlyFocusedComponent = 0;
  31748. Desktop::getInstance().triggerFocusCallback();
  31749. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  31750. }
  31751. #endif
  31752. child->internalHierarchyChanged();
  31753. internalChildrenChanged();
  31754. }
  31755. return child;
  31756. }
  31757. void Component::removeAllChildren()
  31758. {
  31759. for (int i = childComponentList_.size(); --i >= 0;)
  31760. removeChildComponent (i);
  31761. }
  31762. void Component::deleteAllChildren()
  31763. {
  31764. for (int i = childComponentList_.size(); --i >= 0;)
  31765. delete (removeChildComponent (i));
  31766. }
  31767. int Component::getNumChildComponents() const throw()
  31768. {
  31769. return childComponentList_.size();
  31770. }
  31771. Component* Component::getChildComponent (const int index) const throw()
  31772. {
  31773. return childComponentList_ [index];
  31774. }
  31775. int Component::getIndexOfChildComponent (const Component* const child) const throw()
  31776. {
  31777. return childComponentList_.indexOf (const_cast <Component*> (child));
  31778. }
  31779. Component* Component::getTopLevelComponent() const throw()
  31780. {
  31781. const Component* comp = this;
  31782. while (comp->parentComponent_ != 0)
  31783. comp = comp->parentComponent_;
  31784. return const_cast <Component*> (comp);
  31785. }
  31786. bool Component::isParentOf (const Component* possibleChild) const throw()
  31787. {
  31788. if (! possibleChild->isValidComponent())
  31789. {
  31790. jassert (possibleChild == 0);
  31791. return false;
  31792. }
  31793. while (possibleChild != 0)
  31794. {
  31795. possibleChild = possibleChild->parentComponent_;
  31796. if (possibleChild == this)
  31797. return true;
  31798. }
  31799. return false;
  31800. }
  31801. void Component::parentHierarchyChanged()
  31802. {
  31803. }
  31804. void Component::childrenChanged()
  31805. {
  31806. }
  31807. void Component::internalChildrenChanged()
  31808. {
  31809. if (componentListeners.isEmpty())
  31810. {
  31811. childrenChanged();
  31812. }
  31813. else
  31814. {
  31815. BailOutChecker checker (this);
  31816. childrenChanged();
  31817. if (! checker.shouldBailOut())
  31818. componentListeners.callChecked (checker, &ComponentListener::componentChildrenChanged, *this);
  31819. }
  31820. }
  31821. void Component::internalHierarchyChanged()
  31822. {
  31823. BailOutChecker checker (this);
  31824. parentHierarchyChanged();
  31825. if (checker.shouldBailOut())
  31826. return;
  31827. componentListeners.callChecked (checker, &ComponentListener::componentParentHierarchyChanged, *this);
  31828. if (checker.shouldBailOut())
  31829. return;
  31830. for (int i = childComponentList_.size(); --i >= 0;)
  31831. {
  31832. childComponentList_.getUnchecked (i)->internalHierarchyChanged();
  31833. if (checker.shouldBailOut())
  31834. {
  31835. // you really shouldn't delete the parent component during a callback telling you
  31836. // that it's changed..
  31837. jassertfalse;
  31838. return;
  31839. }
  31840. i = jmin (i, childComponentList_.size());
  31841. }
  31842. }
  31843. void* Component::runModalLoopCallback (void* userData)
  31844. {
  31845. return (void*) (pointer_sized_int) ((Component*) userData)->runModalLoop();
  31846. }
  31847. int Component::runModalLoop()
  31848. {
  31849. if (! MessageManager::getInstance()->isThisTheMessageThread())
  31850. {
  31851. // use a callback so this can be called from non-gui threads
  31852. return (int) (pointer_sized_int)
  31853. MessageManager::getInstance()
  31854. ->callFunctionOnMessageThread (&runModalLoopCallback, (void*) this);
  31855. }
  31856. SafePointer<Component> prevFocused (getCurrentlyFocusedComponent());
  31857. if (! isCurrentlyModal())
  31858. enterModalState();
  31859. JUCE_TRY
  31860. {
  31861. while (flags.currentlyModalFlag && flags.visibleFlag)
  31862. {
  31863. if (! MessageManager::getInstance()->runDispatchLoopUntil (20))
  31864. break;
  31865. // check whether this component was deleted during the last message
  31866. if (! isValidMessageListener())
  31867. break;
  31868. }
  31869. }
  31870. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  31871. catch (const std::exception& e)
  31872. {
  31873. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  31874. return 0;
  31875. }
  31876. catch (...)
  31877. {
  31878. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  31879. return 0;
  31880. }
  31881. #endif
  31882. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  31883. int returnValue = 0;
  31884. if (modalIndex >= 0)
  31885. {
  31886. modalComponentReturnValueKeys.remove (modalIndex);
  31887. returnValue = modalReturnValues.remove (modalIndex);
  31888. }
  31889. modalComponentStack.removeValue (this);
  31890. if (prevFocused != 0)
  31891. prevFocused->grabKeyboardFocus();
  31892. return returnValue;
  31893. }
  31894. void Component::enterModalState (const bool takeKeyboardFocus_)
  31895. {
  31896. // if component methods are being called from threads other than the message
  31897. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31898. checkMessageManagerIsLocked
  31899. // Check for an attempt to make a component modal when it already is!
  31900. // This can cause nasty problems..
  31901. jassert (! flags.currentlyModalFlag);
  31902. if (! isCurrentlyModal())
  31903. {
  31904. modalComponentStack.add (this);
  31905. modalComponentReturnValueKeys.add (this);
  31906. modalReturnValues.add (0);
  31907. flags.currentlyModalFlag = true;
  31908. setVisible (true);
  31909. if (takeKeyboardFocus_)
  31910. grabKeyboardFocus();
  31911. }
  31912. }
  31913. void Component::exitModalState (const int returnValue)
  31914. {
  31915. if (isCurrentlyModal())
  31916. {
  31917. if (MessageManager::getInstance()->isThisTheMessageThread())
  31918. {
  31919. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  31920. if (modalIndex >= 0)
  31921. {
  31922. modalReturnValues.set (modalIndex, returnValue);
  31923. }
  31924. else
  31925. {
  31926. modalComponentReturnValueKeys.add (this);
  31927. modalReturnValues.add (returnValue);
  31928. }
  31929. modalComponentStack.removeValue (this);
  31930. flags.currentlyModalFlag = false;
  31931. bringModalComponentToFront();
  31932. }
  31933. else
  31934. {
  31935. postMessage (new Message (exitModalStateMessage, returnValue, 0, 0));
  31936. }
  31937. }
  31938. }
  31939. bool Component::isCurrentlyModal() const throw()
  31940. {
  31941. return flags.currentlyModalFlag
  31942. && getCurrentlyModalComponent() == this;
  31943. }
  31944. bool Component::isCurrentlyBlockedByAnotherModalComponent() const
  31945. {
  31946. Component* const mc = getCurrentlyModalComponent();
  31947. return mc != 0
  31948. && mc != this
  31949. && (! mc->isParentOf (this))
  31950. && ! mc->canModalEventBeSentToComponent (this);
  31951. }
  31952. int JUCE_CALLTYPE Component::getNumCurrentlyModalComponents() throw()
  31953. {
  31954. return modalComponentStack.size();
  31955. }
  31956. Component* JUCE_CALLTYPE Component::getCurrentlyModalComponent (int index) throw()
  31957. {
  31958. Component* const c = static_cast <Component*> (modalComponentStack [modalComponentStack.size() - index - 1]);
  31959. return c->isValidComponent() ? c : 0;
  31960. }
  31961. void Component::bringModalComponentToFront()
  31962. {
  31963. ComponentPeer* lastOne = 0;
  31964. for (int i = 0; i < getNumCurrentlyModalComponents(); ++i)
  31965. {
  31966. Component* const c = getCurrentlyModalComponent (i);
  31967. if (c == 0)
  31968. break;
  31969. ComponentPeer* peer = c->getPeer();
  31970. if (peer != 0 && peer != lastOne)
  31971. {
  31972. if (lastOne == 0)
  31973. {
  31974. peer->toFront (true);
  31975. peer->grabFocus();
  31976. }
  31977. else
  31978. peer->toBehind (lastOne);
  31979. lastOne = peer;
  31980. }
  31981. }
  31982. }
  31983. void Component::setBroughtToFrontOnMouseClick (const bool shouldBeBroughtToFront) throw()
  31984. {
  31985. flags.bringToFrontOnClickFlag = shouldBeBroughtToFront;
  31986. }
  31987. bool Component::isBroughtToFrontOnMouseClick() const throw()
  31988. {
  31989. return flags.bringToFrontOnClickFlag;
  31990. }
  31991. void Component::setMouseCursor (const MouseCursor& cursor)
  31992. {
  31993. if (cursor_ != cursor)
  31994. {
  31995. cursor_ = cursor;
  31996. if (flags.visibleFlag)
  31997. updateMouseCursor();
  31998. }
  31999. }
  32000. const MouseCursor Component::getMouseCursor()
  32001. {
  32002. return cursor_;
  32003. }
  32004. void Component::updateMouseCursor() const
  32005. {
  32006. sendFakeMouseMove();
  32007. }
  32008. void Component::setRepaintsOnMouseActivity (const bool shouldRepaint) throw()
  32009. {
  32010. flags.repaintOnMouseActivityFlag = shouldRepaint;
  32011. }
  32012. void Component::repaintParent()
  32013. {
  32014. if (flags.visibleFlag)
  32015. internalRepaint (0, 0, getWidth(), getHeight());
  32016. }
  32017. void Component::repaint()
  32018. {
  32019. repaint (0, 0, getWidth(), getHeight());
  32020. }
  32021. void Component::repaint (const int x, const int y,
  32022. const int w, const int h)
  32023. {
  32024. deleteAndZero (bufferedImage_);
  32025. if (flags.visibleFlag)
  32026. internalRepaint (x, y, w, h);
  32027. }
  32028. void Component::internalRepaint (int x, int y, int w, int h)
  32029. {
  32030. // if component methods are being called from threads other than the message
  32031. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32032. checkMessageManagerIsLocked
  32033. if (x < 0)
  32034. {
  32035. w += x;
  32036. x = 0;
  32037. }
  32038. if (x + w > getWidth())
  32039. w = getWidth() - x;
  32040. if (w > 0)
  32041. {
  32042. if (y < 0)
  32043. {
  32044. h += y;
  32045. y = 0;
  32046. }
  32047. if (y + h > getHeight())
  32048. h = getHeight() - y;
  32049. if (h > 0)
  32050. {
  32051. if (parentComponent_ != 0)
  32052. {
  32053. x += getX();
  32054. y += getY();
  32055. if (parentComponent_->flags.visibleFlag)
  32056. parentComponent_->internalRepaint (x, y, w, h);
  32057. }
  32058. else if (flags.hasHeavyweightPeerFlag)
  32059. {
  32060. ComponentPeer* const peer = getPeer();
  32061. if (peer != 0)
  32062. peer->repaint (x, y, w, h);
  32063. }
  32064. }
  32065. }
  32066. }
  32067. void Component::renderComponent (Graphics& g)
  32068. {
  32069. const Rectangle<int> clipBounds (g.getClipBounds());
  32070. g.saveState();
  32071. clipObscuredRegions (g, clipBounds, 0, 0);
  32072. if (! g.isClipEmpty())
  32073. {
  32074. if (flags.bufferToImageFlag)
  32075. {
  32076. if (bufferedImage_ == 0)
  32077. {
  32078. bufferedImage_ = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32079. getWidth(), getHeight(), ! flags.opaqueFlag);
  32080. Graphics imG (*bufferedImage_);
  32081. paint (imG);
  32082. }
  32083. g.setColour (Colours::black);
  32084. g.drawImageAt (bufferedImage_, 0, 0);
  32085. }
  32086. else
  32087. {
  32088. paint (g);
  32089. }
  32090. }
  32091. g.restoreState();
  32092. for (int i = 0; i < childComponentList_.size(); ++i)
  32093. {
  32094. Component* const child = childComponentList_.getUnchecked (i);
  32095. if (child->isVisible() && clipBounds.intersects (child->getBounds()))
  32096. {
  32097. g.saveState();
  32098. if (g.reduceClipRegion (child->getX(), child->getY(),
  32099. child->getWidth(), child->getHeight()))
  32100. {
  32101. for (int j = i + 1; j < childComponentList_.size(); ++j)
  32102. {
  32103. const Component* const sibling = childComponentList_.getUnchecked (j);
  32104. if (sibling->flags.opaqueFlag && sibling->isVisible())
  32105. g.excludeClipRegion (sibling->getBounds());
  32106. }
  32107. if (! g.isClipEmpty())
  32108. {
  32109. g.setOrigin (child->getX(), child->getY());
  32110. child->paintEntireComponent (g);
  32111. }
  32112. }
  32113. g.restoreState();
  32114. }
  32115. }
  32116. g.saveState();
  32117. paintOverChildren (g);
  32118. g.restoreState();
  32119. }
  32120. void Component::paintEntireComponent (Graphics& g)
  32121. {
  32122. jassert (! g.isClipEmpty());
  32123. #ifdef JUCE_DEBUG
  32124. flags.isInsidePaintCall = true;
  32125. #endif
  32126. if (effect_ != 0)
  32127. {
  32128. ScopedPointer<Image> effectImage (Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32129. getWidth(), getHeight(),
  32130. ! flags.opaqueFlag));
  32131. {
  32132. Graphics g2 (*effectImage);
  32133. renderComponent (g2);
  32134. }
  32135. effect_->applyEffect (*effectImage, g);
  32136. }
  32137. else
  32138. {
  32139. renderComponent (g);
  32140. }
  32141. #ifdef JUCE_DEBUG
  32142. flags.isInsidePaintCall = false;
  32143. #endif
  32144. }
  32145. Image* Component::createComponentSnapshot (const Rectangle<int>& areaToGrab,
  32146. const bool clipImageToComponentBounds)
  32147. {
  32148. Rectangle<int> r (areaToGrab);
  32149. if (clipImageToComponentBounds)
  32150. r = r.getIntersection (Rectangle<int> (0, 0, getWidth(), getHeight()));
  32151. ScopedPointer<Image> componentImage (Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32152. jmax (1, r.getWidth()),
  32153. jmax (1, r.getHeight()),
  32154. true));
  32155. Graphics imageContext (*componentImage);
  32156. imageContext.setOrigin (-r.getX(), -r.getY());
  32157. paintEntireComponent (imageContext);
  32158. return componentImage.release();
  32159. }
  32160. void Component::setComponentEffect (ImageEffectFilter* const effect)
  32161. {
  32162. if (effect_ != effect)
  32163. {
  32164. effect_ = effect;
  32165. repaint();
  32166. }
  32167. }
  32168. LookAndFeel& Component::getLookAndFeel() const throw()
  32169. {
  32170. const Component* c = this;
  32171. do
  32172. {
  32173. if (c->lookAndFeel_ != 0)
  32174. return *(c->lookAndFeel_);
  32175. c = c->parentComponent_;
  32176. }
  32177. while (c != 0);
  32178. return LookAndFeel::getDefaultLookAndFeel();
  32179. }
  32180. void Component::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  32181. {
  32182. if (lookAndFeel_ != newLookAndFeel)
  32183. {
  32184. lookAndFeel_ = newLookAndFeel;
  32185. sendLookAndFeelChange();
  32186. }
  32187. }
  32188. void Component::lookAndFeelChanged()
  32189. {
  32190. }
  32191. void Component::sendLookAndFeelChange()
  32192. {
  32193. repaint();
  32194. lookAndFeelChanged();
  32195. // (it's not a great idea to do anything that would delete this component
  32196. // during the lookAndFeelChanged() callback)
  32197. jassert (isValidComponent());
  32198. SafePointer<Component> safePointer (this);
  32199. for (int i = childComponentList_.size(); --i >= 0;)
  32200. {
  32201. childComponentList_.getUnchecked (i)->sendLookAndFeelChange();
  32202. if (safePointer == 0)
  32203. return;
  32204. i = jmin (i, childComponentList_.size());
  32205. }
  32206. }
  32207. static const var::identifier getColourPropertyId (const int colourId)
  32208. {
  32209. String s;
  32210. s.preallocateStorage (18);
  32211. s << "jcclr_" << String::toHexString (colourId);
  32212. return s;
  32213. }
  32214. const Colour Component::findColour (const int colourId, const bool inheritFromParent) const
  32215. {
  32216. var* v = properties.getItem (getColourPropertyId (colourId));
  32217. if (v != 0)
  32218. return Colour ((int) *v);
  32219. if (inheritFromParent && parentComponent_ != 0)
  32220. return parentComponent_->findColour (colourId, true);
  32221. return getLookAndFeel().findColour (colourId);
  32222. }
  32223. bool Component::isColourSpecified (const int colourId) const
  32224. {
  32225. return properties.contains (getColourPropertyId (colourId));
  32226. }
  32227. void Component::removeColour (const int colourId)
  32228. {
  32229. if (properties.remove (getColourPropertyId (colourId)))
  32230. colourChanged();
  32231. }
  32232. void Component::setColour (const int colourId, const Colour& colour)
  32233. {
  32234. if (properties.set (getColourPropertyId (colourId), (int) colour.getARGB()))
  32235. colourChanged();
  32236. }
  32237. void Component::copyAllExplicitColoursTo (Component& target) const
  32238. {
  32239. bool changed = false;
  32240. for (int i = properties.size(); --i >= 0;)
  32241. {
  32242. const var::identifier name (properties.getName(i));
  32243. if (name.name.startsWith (T("jcclr_")))
  32244. if (target.properties.set (name, properties [name]))
  32245. changed = true;
  32246. }
  32247. if (changed)
  32248. target.colourChanged();
  32249. }
  32250. void Component::colourChanged()
  32251. {
  32252. }
  32253. const Rectangle<int> Component::getUnclippedArea() const
  32254. {
  32255. int x = 0, y = 0, w = getWidth(), h = getHeight();
  32256. Component* p = parentComponent_;
  32257. int px = getX();
  32258. int py = getY();
  32259. while (p != 0)
  32260. {
  32261. if (! Rectangle<int>::intersectRectangles (x, y, w, h, -px, -py, p->getWidth(), p->getHeight()))
  32262. return Rectangle<int>();
  32263. px += p->getX();
  32264. py += p->getY();
  32265. p = p->parentComponent_;
  32266. }
  32267. return Rectangle<int> (x, y, w, h);
  32268. }
  32269. void Component::clipObscuredRegions (Graphics& g, const Rectangle<int>& clipRect,
  32270. const int deltaX, const int deltaY) const
  32271. {
  32272. for (int i = childComponentList_.size(); --i >= 0;)
  32273. {
  32274. const Component* const c = childComponentList_.getUnchecked(i);
  32275. if (c->isVisible())
  32276. {
  32277. const Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32278. if (! newClip.isEmpty())
  32279. {
  32280. if (c->isOpaque())
  32281. {
  32282. g.excludeClipRegion (newClip.translated (deltaX, deltaY));
  32283. }
  32284. else
  32285. {
  32286. c->clipObscuredRegions (g, newClip.translated (-c->getX(), -c->getY()),
  32287. c->getX() + deltaX,
  32288. c->getY() + deltaY);
  32289. }
  32290. }
  32291. }
  32292. }
  32293. }
  32294. void Component::getVisibleArea (RectangleList& result,
  32295. const bool includeSiblings) const
  32296. {
  32297. result.clear();
  32298. const Rectangle<int> unclipped (getUnclippedArea());
  32299. if (! unclipped.isEmpty())
  32300. {
  32301. result.add (unclipped);
  32302. if (includeSiblings)
  32303. {
  32304. const Component* const c = getTopLevelComponent();
  32305. c->subtractObscuredRegions (result, c->relativePositionToOtherComponent (this, Point<int>()),
  32306. Rectangle<int> (0, 0, c->getWidth(), c->getHeight()),
  32307. this);
  32308. }
  32309. subtractObscuredRegions (result, Point<int>(), unclipped, 0);
  32310. result.consolidate();
  32311. }
  32312. }
  32313. void Component::subtractObscuredRegions (RectangleList& result,
  32314. const Point<int>& delta,
  32315. const Rectangle<int>& clipRect,
  32316. const Component* const compToAvoid) const
  32317. {
  32318. for (int i = childComponentList_.size(); --i >= 0;)
  32319. {
  32320. const Component* const c = childComponentList_.getUnchecked(i);
  32321. if (c != compToAvoid && c->isVisible())
  32322. {
  32323. if (c->isOpaque())
  32324. {
  32325. Rectangle<int> childBounds (c->bounds_.getIntersection (clipRect));
  32326. childBounds.translate (delta.getX(), delta.getY());
  32327. result.subtract (childBounds);
  32328. }
  32329. else
  32330. {
  32331. Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32332. newClip.translate (-c->getX(), -c->getY());
  32333. c->subtractObscuredRegions (result, c->getPosition() + delta,
  32334. newClip, compToAvoid);
  32335. }
  32336. }
  32337. }
  32338. }
  32339. void Component::mouseEnter (const MouseEvent&)
  32340. {
  32341. // base class does nothing
  32342. }
  32343. void Component::mouseExit (const MouseEvent&)
  32344. {
  32345. // base class does nothing
  32346. }
  32347. void Component::mouseDown (const MouseEvent&)
  32348. {
  32349. // base class does nothing
  32350. }
  32351. void Component::mouseUp (const MouseEvent&)
  32352. {
  32353. // base class does nothing
  32354. }
  32355. void Component::mouseDrag (const MouseEvent&)
  32356. {
  32357. // base class does nothing
  32358. }
  32359. void Component::mouseMove (const MouseEvent&)
  32360. {
  32361. // base class does nothing
  32362. }
  32363. void Component::mouseDoubleClick (const MouseEvent&)
  32364. {
  32365. // base class does nothing
  32366. }
  32367. void Component::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  32368. {
  32369. // the base class just passes this event up to its parent..
  32370. if (parentComponent_ != 0)
  32371. parentComponent_->mouseWheelMove (e.getEventRelativeTo (parentComponent_),
  32372. wheelIncrementX, wheelIncrementY);
  32373. }
  32374. void Component::resized()
  32375. {
  32376. // base class does nothing
  32377. }
  32378. void Component::moved()
  32379. {
  32380. // base class does nothing
  32381. }
  32382. void Component::childBoundsChanged (Component*)
  32383. {
  32384. // base class does nothing
  32385. }
  32386. void Component::parentSizeChanged()
  32387. {
  32388. // base class does nothing
  32389. }
  32390. void Component::addComponentListener (ComponentListener* const newListener)
  32391. {
  32392. jassert (isValidComponent());
  32393. componentListeners.add (newListener);
  32394. }
  32395. void Component::removeComponentListener (ComponentListener* const listenerToRemove)
  32396. {
  32397. jassert (isValidComponent());
  32398. componentListeners.remove (listenerToRemove);
  32399. }
  32400. void Component::inputAttemptWhenModal()
  32401. {
  32402. bringModalComponentToFront();
  32403. getLookAndFeel().playAlertSound();
  32404. }
  32405. bool Component::canModalEventBeSentToComponent (const Component*)
  32406. {
  32407. return false;
  32408. }
  32409. void Component::internalModalInputAttempt()
  32410. {
  32411. Component* const current = getCurrentlyModalComponent();
  32412. if (current != 0)
  32413. current->inputAttemptWhenModal();
  32414. }
  32415. void Component::paint (Graphics&)
  32416. {
  32417. // all painting is done in the subclasses
  32418. jassert (! isOpaque()); // if your component's opaque, you've gotta paint it!
  32419. }
  32420. void Component::paintOverChildren (Graphics&)
  32421. {
  32422. // all painting is done in the subclasses
  32423. }
  32424. void Component::handleMessage (const Message& message)
  32425. {
  32426. if (message.intParameter1 == exitModalStateMessage)
  32427. {
  32428. exitModalState (message.intParameter2);
  32429. }
  32430. else if (message.intParameter1 == customCommandMessage)
  32431. {
  32432. handleCommandMessage (message.intParameter2);
  32433. }
  32434. }
  32435. void Component::postCommandMessage (const int commandId)
  32436. {
  32437. postMessage (new Message (customCommandMessage, commandId, 0, 0));
  32438. }
  32439. void Component::handleCommandMessage (int)
  32440. {
  32441. // used by subclasses
  32442. }
  32443. void Component::addMouseListener (MouseListener* const newListener,
  32444. const bool wantsEventsForAllNestedChildComponents)
  32445. {
  32446. // if component methods are being called from threads other than the message
  32447. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32448. checkMessageManagerIsLocked
  32449. if (mouseListeners_ == 0)
  32450. mouseListeners_ = new VoidArray();
  32451. if (! mouseListeners_->contains (newListener))
  32452. {
  32453. if (wantsEventsForAllNestedChildComponents)
  32454. {
  32455. mouseListeners_->insert (0, newListener);
  32456. ++numDeepMouseListeners;
  32457. }
  32458. else
  32459. {
  32460. mouseListeners_->add (newListener);
  32461. }
  32462. }
  32463. }
  32464. void Component::removeMouseListener (MouseListener* const listenerToRemove)
  32465. {
  32466. // if component methods are being called from threads other than the message
  32467. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32468. checkMessageManagerIsLocked
  32469. if (mouseListeners_ != 0)
  32470. {
  32471. const int index = mouseListeners_->indexOf (listenerToRemove);
  32472. if (index >= 0)
  32473. {
  32474. if (index < numDeepMouseListeners)
  32475. --numDeepMouseListeners;
  32476. mouseListeners_->remove (index);
  32477. }
  32478. }
  32479. }
  32480. void Component::internalMouseEnter (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32481. {
  32482. if (isCurrentlyBlockedByAnotherModalComponent())
  32483. {
  32484. // if something else is modal, always just show a normal mouse cursor
  32485. source.showMouseCursor (MouseCursor::NormalCursor);
  32486. return;
  32487. }
  32488. if (! flags.mouseInsideFlag)
  32489. {
  32490. flags.mouseInsideFlag = true;
  32491. flags.mouseOverFlag = true;
  32492. flags.draggingFlag = false;
  32493. BailOutChecker checker (this);
  32494. if (flags.repaintOnMouseActivityFlag)
  32495. repaint();
  32496. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32497. this, time, relativePos,
  32498. time, 0, false);
  32499. mouseEnter (me);
  32500. if (checker.shouldBailOut())
  32501. return;
  32502. Desktop::getInstance().resetTimer();
  32503. Desktop::getInstance().mouseListeners.callChecked (checker, &MouseListener::mouseEnter, me);
  32504. if (checker.shouldBailOut())
  32505. return;
  32506. if (mouseListeners_ != 0)
  32507. {
  32508. for (int i = mouseListeners_->size(); --i >= 0;)
  32509. {
  32510. ((MouseListener*) mouseListeners_->getUnchecked(i))->mouseEnter (me);
  32511. if (checker.shouldBailOut())
  32512. return;
  32513. i = jmin (i, mouseListeners_->size());
  32514. }
  32515. }
  32516. Component* p = parentComponent_;
  32517. while (p != 0)
  32518. {
  32519. if (p->numDeepMouseListeners > 0)
  32520. {
  32521. BailOutChecker checker (this, p);
  32522. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32523. {
  32524. ((MouseListener*) (p->mouseListeners_->getUnchecked(i)))->mouseEnter (me);
  32525. if (checker.shouldBailOut())
  32526. return;
  32527. i = jmin (i, p->numDeepMouseListeners);
  32528. }
  32529. }
  32530. p = p->parentComponent_;
  32531. }
  32532. }
  32533. }
  32534. void Component::internalMouseExit (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32535. {
  32536. BailOutChecker checker (this);
  32537. if (flags.draggingFlag)
  32538. {
  32539. internalMouseUp (source, relativePos, time, source.getCurrentModifiers().getRawFlags());
  32540. if (checker.shouldBailOut())
  32541. return;
  32542. }
  32543. if (flags.mouseInsideFlag || flags.mouseOverFlag)
  32544. {
  32545. flags.mouseInsideFlag = false;
  32546. flags.mouseOverFlag = false;
  32547. flags.draggingFlag = false;
  32548. if (flags.repaintOnMouseActivityFlag)
  32549. repaint();
  32550. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32551. this, time, relativePos,
  32552. time, 0, false);
  32553. mouseExit (me);
  32554. if (checker.shouldBailOut())
  32555. return;
  32556. Desktop::getInstance().resetTimer();
  32557. Desktop::getInstance().mouseListeners.callChecked (checker, &MouseListener::mouseExit, me);
  32558. if (checker.shouldBailOut())
  32559. return;
  32560. if (mouseListeners_ != 0)
  32561. {
  32562. for (int i = mouseListeners_->size(); --i >= 0;)
  32563. {
  32564. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseExit (me);
  32565. if (checker.shouldBailOut())
  32566. return;
  32567. i = jmin (i, mouseListeners_->size());
  32568. }
  32569. }
  32570. Component* p = parentComponent_;
  32571. while (p != 0)
  32572. {
  32573. if (p->numDeepMouseListeners > 0)
  32574. {
  32575. BailOutChecker checker (this, p);
  32576. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32577. {
  32578. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseExit (me);
  32579. if (checker.shouldBailOut())
  32580. return;
  32581. i = jmin (i, p->numDeepMouseListeners);
  32582. }
  32583. }
  32584. p = p->parentComponent_;
  32585. }
  32586. }
  32587. }
  32588. class InternalDragRepeater : public Timer
  32589. {
  32590. public:
  32591. InternalDragRepeater()
  32592. {}
  32593. ~InternalDragRepeater()
  32594. {
  32595. clearSingletonInstance();
  32596. }
  32597. juce_DeclareSingleton_SingleThreaded_Minimal (InternalDragRepeater)
  32598. void timerCallback()
  32599. {
  32600. Desktop& desktop = Desktop::getInstance();
  32601. int numMiceDown = 0;
  32602. for (int i = desktop.getNumMouseSources(); --i >= 0;)
  32603. {
  32604. MouseInputSource* const source = desktop.getMouseSource(i);
  32605. if (source->isDragging())
  32606. {
  32607. source->triggerFakeMove();
  32608. ++numMiceDown;
  32609. }
  32610. }
  32611. if (numMiceDown == 0)
  32612. deleteInstance();
  32613. }
  32614. juce_UseDebuggingNewOperator
  32615. private:
  32616. InternalDragRepeater (const InternalDragRepeater&);
  32617. InternalDragRepeater& operator= (const InternalDragRepeater&);
  32618. };
  32619. juce_ImplementSingleton_SingleThreaded (InternalDragRepeater)
  32620. void Component::beginDragAutoRepeat (const int interval)
  32621. {
  32622. if (interval > 0)
  32623. {
  32624. if (InternalDragRepeater::getInstance()->getTimerInterval() != interval)
  32625. InternalDragRepeater::getInstance()->startTimer (interval);
  32626. }
  32627. else
  32628. {
  32629. InternalDragRepeater::deleteInstance();
  32630. }
  32631. }
  32632. void Component::internalMouseDown (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32633. {
  32634. Desktop& desktop = Desktop::getInstance();
  32635. BailOutChecker checker (this);
  32636. if (isCurrentlyBlockedByAnotherModalComponent())
  32637. {
  32638. internalModalInputAttempt();
  32639. if (checker.shouldBailOut())
  32640. return;
  32641. // If processing the input attempt has exited the modal loop, we'll allow the event
  32642. // to be delivered..
  32643. if (isCurrentlyBlockedByAnotherModalComponent())
  32644. {
  32645. // allow blocked mouse-events to go to global listeners..
  32646. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32647. this, time, relativePos, time,
  32648. source.getNumberOfMultipleClicks(), false);
  32649. desktop.resetTimer();
  32650. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDown, me);
  32651. return;
  32652. }
  32653. }
  32654. {
  32655. Component* c = this;
  32656. while (c != 0)
  32657. {
  32658. if (c->isBroughtToFrontOnMouseClick())
  32659. {
  32660. c->toFront (true);
  32661. if (checker.shouldBailOut())
  32662. return;
  32663. }
  32664. c = c->parentComponent_;
  32665. }
  32666. }
  32667. if (! flags.dontFocusOnMouseClickFlag)
  32668. {
  32669. grabFocusInternal (focusChangedByMouseClick);
  32670. if (checker.shouldBailOut())
  32671. return;
  32672. }
  32673. flags.draggingFlag = true;
  32674. flags.mouseOverFlag = true;
  32675. if (flags.repaintOnMouseActivityFlag)
  32676. repaint();
  32677. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32678. this, time, relativePos, time,
  32679. source.getNumberOfMultipleClicks(), false);
  32680. mouseDown (me);
  32681. if (checker.shouldBailOut())
  32682. return;
  32683. desktop.resetTimer();
  32684. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDown, me);
  32685. if (checker.shouldBailOut())
  32686. return;
  32687. if (mouseListeners_ != 0)
  32688. {
  32689. for (int i = mouseListeners_->size(); --i >= 0;)
  32690. {
  32691. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDown (me);
  32692. if (checker.shouldBailOut())
  32693. return;
  32694. i = jmin (i, mouseListeners_->size());
  32695. }
  32696. }
  32697. Component* p = parentComponent_;
  32698. while (p != 0)
  32699. {
  32700. if (p->numDeepMouseListeners > 0)
  32701. {
  32702. BailOutChecker checker (this, p);
  32703. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32704. {
  32705. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDown (me);
  32706. if (checker.shouldBailOut())
  32707. return;
  32708. i = jmin (i, p->numDeepMouseListeners);
  32709. }
  32710. }
  32711. p = p->parentComponent_;
  32712. }
  32713. }
  32714. void Component::internalMouseUp (MouseInputSource& source, const Point<int>& relativePos, const Time& time, const ModifierKeys& oldModifiers)
  32715. {
  32716. if (flags.draggingFlag)
  32717. {
  32718. Desktop& desktop = Desktop::getInstance();
  32719. flags.draggingFlag = false;
  32720. BailOutChecker checker (this);
  32721. if (flags.repaintOnMouseActivityFlag)
  32722. repaint();
  32723. const MouseEvent me (source, relativePos,
  32724. oldModifiers, this, time,
  32725. globalPositionToRelative (source.getLastMouseDownPosition()),
  32726. source.getLastMouseDownTime(),
  32727. source.getNumberOfMultipleClicks(),
  32728. source.hasMouseMovedSignificantlySincePressed());
  32729. mouseUp (me);
  32730. if (checker.shouldBailOut())
  32731. return;
  32732. desktop.resetTimer();
  32733. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseUp, me);
  32734. if (checker.shouldBailOut())
  32735. return;
  32736. if (mouseListeners_ != 0)
  32737. {
  32738. for (int i = mouseListeners_->size(); --i >= 0;)
  32739. {
  32740. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseUp (me);
  32741. if (checker.shouldBailOut())
  32742. return;
  32743. i = jmin (i, mouseListeners_->size());
  32744. }
  32745. }
  32746. {
  32747. Component* p = parentComponent_;
  32748. while (p != 0)
  32749. {
  32750. if (p->numDeepMouseListeners > 0)
  32751. {
  32752. BailOutChecker checker (this, p);
  32753. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32754. {
  32755. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseUp (me);
  32756. if (checker.shouldBailOut())
  32757. return;
  32758. i = jmin (i, p->numDeepMouseListeners);
  32759. }
  32760. }
  32761. p = p->parentComponent_;
  32762. }
  32763. }
  32764. // check for double-click
  32765. if (me.getNumberOfClicks() >= 2)
  32766. {
  32767. const int numListeners = (mouseListeners_ != 0) ? mouseListeners_->size() : 0;
  32768. mouseDoubleClick (me);
  32769. if (checker.shouldBailOut())
  32770. return;
  32771. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDoubleClick, me);
  32772. if (checker.shouldBailOut())
  32773. return;
  32774. for (int i = numListeners; --i >= 0;)
  32775. {
  32776. if (checker.shouldBailOut())
  32777. return;
  32778. MouseListener* const ml = (MouseListener*)((*mouseListeners_)[i]);
  32779. if (ml != 0)
  32780. ml->mouseDoubleClick (me);
  32781. }
  32782. if (checker.shouldBailOut())
  32783. return;
  32784. Component* p = parentComponent_;
  32785. while (p != 0)
  32786. {
  32787. if (p->numDeepMouseListeners > 0)
  32788. {
  32789. BailOutChecker checker (this, p);
  32790. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32791. {
  32792. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDoubleClick (me);
  32793. if (checker.shouldBailOut())
  32794. return;
  32795. i = jmin (i, p->numDeepMouseListeners);
  32796. }
  32797. }
  32798. p = p->parentComponent_;
  32799. }
  32800. }
  32801. }
  32802. }
  32803. void Component::internalMouseDrag (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32804. {
  32805. if (flags.draggingFlag)
  32806. {
  32807. Desktop& desktop = Desktop::getInstance();
  32808. flags.mouseOverFlag = reallyContains (relativePos.getX(), relativePos.getY(), false);
  32809. BailOutChecker checker (this);
  32810. const MouseEvent me (source, relativePos,
  32811. source.getCurrentModifiers(), this, time,
  32812. globalPositionToRelative (source.getLastMouseDownPosition()),
  32813. source.getLastMouseDownTime(),
  32814. source.getNumberOfMultipleClicks(),
  32815. source.hasMouseMovedSignificantlySincePressed());
  32816. mouseDrag (me);
  32817. if (checker.shouldBailOut())
  32818. return;
  32819. desktop.resetTimer();
  32820. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDrag, me);
  32821. if (checker.shouldBailOut())
  32822. return;
  32823. if (mouseListeners_ != 0)
  32824. {
  32825. for (int i = mouseListeners_->size(); --i >= 0;)
  32826. {
  32827. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDrag (me);
  32828. if (checker.shouldBailOut())
  32829. return;
  32830. i = jmin (i, mouseListeners_->size());
  32831. }
  32832. }
  32833. Component* p = parentComponent_;
  32834. while (p != 0)
  32835. {
  32836. if (p->numDeepMouseListeners > 0)
  32837. {
  32838. BailOutChecker checker (this, p);
  32839. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32840. {
  32841. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDrag (me);
  32842. if (checker.shouldBailOut())
  32843. return;
  32844. i = jmin (i, p->numDeepMouseListeners);
  32845. }
  32846. }
  32847. p = p->parentComponent_;
  32848. }
  32849. }
  32850. }
  32851. void Component::internalMouseMove (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32852. {
  32853. Desktop& desktop = Desktop::getInstance();
  32854. BailOutChecker checker (this);
  32855. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32856. this, time, relativePos,
  32857. time, 0, false);
  32858. if (isCurrentlyBlockedByAnotherModalComponent())
  32859. {
  32860. // allow blocked mouse-events to go to global listeners..
  32861. desktop.sendMouseMove();
  32862. }
  32863. else
  32864. {
  32865. flags.mouseOverFlag = true;
  32866. mouseMove (me);
  32867. if (checker.shouldBailOut())
  32868. return;
  32869. desktop.resetTimer();
  32870. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseMove, me);
  32871. if (checker.shouldBailOut())
  32872. return;
  32873. if (mouseListeners_ != 0)
  32874. {
  32875. for (int i = mouseListeners_->size(); --i >= 0;)
  32876. {
  32877. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseMove (me);
  32878. if (checker.shouldBailOut())
  32879. return;
  32880. i = jmin (i, mouseListeners_->size());
  32881. }
  32882. }
  32883. Component* p = parentComponent_;
  32884. while (p != 0)
  32885. {
  32886. if (p->numDeepMouseListeners > 0)
  32887. {
  32888. BailOutChecker checker (this, p);
  32889. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32890. {
  32891. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseMove (me);
  32892. if (checker.shouldBailOut())
  32893. return;
  32894. i = jmin (i, p->numDeepMouseListeners);
  32895. }
  32896. }
  32897. p = p->parentComponent_;
  32898. }
  32899. }
  32900. }
  32901. void Component::internalMouseWheel (MouseInputSource& source, const Point<int>& relativePos,
  32902. const Time& time, const float amountX, const float amountY)
  32903. {
  32904. Desktop& desktop = Desktop::getInstance();
  32905. BailOutChecker checker (this);
  32906. const float wheelIncrementX = amountX * (1.0f / 256.0f);
  32907. const float wheelIncrementY = amountY * (1.0f / 256.0f);
  32908. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32909. this, time, relativePos, time, 0, false);
  32910. if (isCurrentlyBlockedByAnotherModalComponent())
  32911. {
  32912. // allow blocked mouse-events to go to global listeners..
  32913. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseWheelMove, me, wheelIncrementX, wheelIncrementY);
  32914. }
  32915. else
  32916. {
  32917. mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  32918. if (checker.shouldBailOut())
  32919. return;
  32920. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseWheelMove, me, wheelIncrementX, wheelIncrementY);
  32921. if (checker.shouldBailOut())
  32922. return;
  32923. if (mouseListeners_ != 0)
  32924. {
  32925. for (int i = mouseListeners_->size(); --i >= 0;)
  32926. {
  32927. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  32928. if (checker.shouldBailOut())
  32929. return;
  32930. i = jmin (i, mouseListeners_->size());
  32931. }
  32932. }
  32933. Component* p = parentComponent_;
  32934. while (p != 0)
  32935. {
  32936. if (p->numDeepMouseListeners > 0)
  32937. {
  32938. BailOutChecker checker (this, p);
  32939. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32940. {
  32941. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  32942. if (checker.shouldBailOut())
  32943. return;
  32944. i = jmin (i, p->numDeepMouseListeners);
  32945. }
  32946. }
  32947. p = p->parentComponent_;
  32948. }
  32949. }
  32950. }
  32951. void Component::sendFakeMouseMove() const
  32952. {
  32953. Desktop::getInstance().getMainMouseSource().triggerFakeMove();
  32954. }
  32955. void Component::broughtToFront()
  32956. {
  32957. }
  32958. void Component::internalBroughtToFront()
  32959. {
  32960. if (! isValidComponent())
  32961. return;
  32962. if (flags.hasHeavyweightPeerFlag)
  32963. Desktop::getInstance().componentBroughtToFront (this);
  32964. BailOutChecker checker (this);
  32965. broughtToFront();
  32966. if (checker.shouldBailOut())
  32967. return;
  32968. componentListeners.callChecked (checker, &ComponentListener::componentBroughtToFront, *this);
  32969. if (checker.shouldBailOut())
  32970. return;
  32971. // When brought to the front and there's a modal component blocking this one,
  32972. // we need to bring the modal one to the front instead..
  32973. Component* const cm = getCurrentlyModalComponent();
  32974. if (cm != 0 && cm->getTopLevelComponent() != getTopLevelComponent())
  32975. bringModalComponentToFront();
  32976. }
  32977. void Component::focusGained (FocusChangeType)
  32978. {
  32979. // base class does nothing
  32980. }
  32981. void Component::internalFocusGain (const FocusChangeType cause)
  32982. {
  32983. SafePointer<Component> safePointer (this);
  32984. focusGained (cause);
  32985. if (safePointer != 0)
  32986. internalChildFocusChange (cause);
  32987. }
  32988. void Component::focusLost (FocusChangeType)
  32989. {
  32990. // base class does nothing
  32991. }
  32992. void Component::internalFocusLoss (const FocusChangeType cause)
  32993. {
  32994. SafePointer<Component> safePointer (this);
  32995. focusLost (focusChangedDirectly);
  32996. if (safePointer != 0)
  32997. internalChildFocusChange (cause);
  32998. }
  32999. void Component::focusOfChildComponentChanged (FocusChangeType /*cause*/)
  33000. {
  33001. // base class does nothing
  33002. }
  33003. void Component::internalChildFocusChange (FocusChangeType cause)
  33004. {
  33005. const bool childIsNowFocused = hasKeyboardFocus (true);
  33006. if (flags.childCompFocusedFlag != childIsNowFocused)
  33007. {
  33008. flags.childCompFocusedFlag = childIsNowFocused;
  33009. SafePointer<Component> safePointer (this);
  33010. focusOfChildComponentChanged (cause);
  33011. if (safePointer == 0)
  33012. return;
  33013. }
  33014. if (parentComponent_ != 0)
  33015. parentComponent_->internalChildFocusChange (cause);
  33016. }
  33017. bool Component::isEnabled() const throw()
  33018. {
  33019. return (! flags.isDisabledFlag)
  33020. && (parentComponent_ == 0 || parentComponent_->isEnabled());
  33021. }
  33022. void Component::setEnabled (const bool shouldBeEnabled)
  33023. {
  33024. if (flags.isDisabledFlag == shouldBeEnabled)
  33025. {
  33026. flags.isDisabledFlag = ! shouldBeEnabled;
  33027. // if any parent components are disabled, setting our flag won't make a difference,
  33028. // so no need to send a change message
  33029. if (parentComponent_ == 0 || parentComponent_->isEnabled())
  33030. sendEnablementChangeMessage();
  33031. }
  33032. }
  33033. void Component::sendEnablementChangeMessage()
  33034. {
  33035. SafePointer<Component> safePointer (this);
  33036. enablementChanged();
  33037. if (safePointer == 0)
  33038. return;
  33039. for (int i = getNumChildComponents(); --i >= 0;)
  33040. {
  33041. Component* const c = getChildComponent (i);
  33042. if (c != 0)
  33043. {
  33044. c->sendEnablementChangeMessage();
  33045. if (safePointer == 0)
  33046. return;
  33047. }
  33048. }
  33049. }
  33050. void Component::enablementChanged()
  33051. {
  33052. }
  33053. void Component::setWantsKeyboardFocus (const bool wantsFocus) throw()
  33054. {
  33055. flags.wantsFocusFlag = wantsFocus;
  33056. }
  33057. void Component::setMouseClickGrabsKeyboardFocus (const bool shouldGrabFocus)
  33058. {
  33059. flags.dontFocusOnMouseClickFlag = ! shouldGrabFocus;
  33060. }
  33061. bool Component::getMouseClickGrabsKeyboardFocus() const throw()
  33062. {
  33063. return ! flags.dontFocusOnMouseClickFlag;
  33064. }
  33065. bool Component::getWantsKeyboardFocus() const throw()
  33066. {
  33067. return flags.wantsFocusFlag && ! flags.isDisabledFlag;
  33068. }
  33069. void Component::setFocusContainer (const bool shouldBeFocusContainer) throw()
  33070. {
  33071. flags.isFocusContainerFlag = shouldBeFocusContainer;
  33072. }
  33073. bool Component::isFocusContainer() const throw()
  33074. {
  33075. return flags.isFocusContainerFlag;
  33076. }
  33077. int Component::getExplicitFocusOrder() const
  33078. {
  33079. return properties ["_jexfo"];
  33080. }
  33081. void Component::setExplicitFocusOrder (const int newFocusOrderIndex)
  33082. {
  33083. properties.set ("_jexfo", newFocusOrderIndex);
  33084. }
  33085. KeyboardFocusTraverser* Component::createFocusTraverser()
  33086. {
  33087. if (flags.isFocusContainerFlag || parentComponent_ == 0)
  33088. return new KeyboardFocusTraverser();
  33089. return parentComponent_->createFocusTraverser();
  33090. }
  33091. void Component::takeKeyboardFocus (const FocusChangeType cause)
  33092. {
  33093. // give the focus to this component
  33094. if (currentlyFocusedComponent != this)
  33095. {
  33096. JUCE_TRY
  33097. {
  33098. // get the focus onto our desktop window
  33099. ComponentPeer* const peer = getPeer();
  33100. if (peer != 0)
  33101. {
  33102. SafePointer<Component> safePointer (this);
  33103. peer->grabFocus();
  33104. if (peer->isFocused() && currentlyFocusedComponent != this)
  33105. {
  33106. Component* const componentLosingFocus = currentlyFocusedComponent;
  33107. currentlyFocusedComponent = this;
  33108. Desktop::getInstance().triggerFocusCallback();
  33109. // call this after setting currentlyFocusedComponent so that the one that's
  33110. // losing it has a chance to see where focus is going
  33111. if (componentLosingFocus->isValidComponent())
  33112. componentLosingFocus->internalFocusLoss (cause);
  33113. if (currentlyFocusedComponent == this)
  33114. {
  33115. focusGained (cause);
  33116. if (safePointer != 0)
  33117. internalChildFocusChange (cause);
  33118. }
  33119. }
  33120. }
  33121. }
  33122. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  33123. catch (const std::exception& e)
  33124. {
  33125. currentlyFocusedComponent = 0;
  33126. Desktop::getInstance().triggerFocusCallback();
  33127. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  33128. }
  33129. catch (...)
  33130. {
  33131. currentlyFocusedComponent = 0;
  33132. Desktop::getInstance().triggerFocusCallback();
  33133. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  33134. }
  33135. #endif
  33136. }
  33137. }
  33138. void Component::grabFocusInternal (const FocusChangeType cause, const bool canTryParent)
  33139. {
  33140. if (isShowing())
  33141. {
  33142. if (flags.wantsFocusFlag && (isEnabled() || parentComponent_ == 0))
  33143. {
  33144. takeKeyboardFocus (cause);
  33145. }
  33146. else
  33147. {
  33148. if (isParentOf (currentlyFocusedComponent)
  33149. && currentlyFocusedComponent->isShowing())
  33150. {
  33151. // do nothing if the focused component is actually a child of ours..
  33152. }
  33153. else
  33154. {
  33155. // find the default child component..
  33156. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33157. if (traverser != 0)
  33158. {
  33159. Component* const defaultComp = traverser->getDefaultComponent (this);
  33160. traverser = 0;
  33161. if (defaultComp != 0)
  33162. {
  33163. defaultComp->grabFocusInternal (cause, false);
  33164. return;
  33165. }
  33166. }
  33167. if (canTryParent && parentComponent_ != 0)
  33168. {
  33169. // if no children want it and we're allowed to try our parent comp,
  33170. // then pass up to parent, which will try our siblings.
  33171. parentComponent_->grabFocusInternal (cause, true);
  33172. }
  33173. }
  33174. }
  33175. }
  33176. }
  33177. void Component::grabKeyboardFocus()
  33178. {
  33179. // if component methods are being called from threads other than the message
  33180. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33181. checkMessageManagerIsLocked
  33182. grabFocusInternal (focusChangedDirectly);
  33183. }
  33184. void Component::moveKeyboardFocusToSibling (const bool moveToNext)
  33185. {
  33186. // if component methods are being called from threads other than the message
  33187. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33188. checkMessageManagerIsLocked
  33189. if (parentComponent_ != 0)
  33190. {
  33191. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33192. if (traverser != 0)
  33193. {
  33194. Component* const nextComp = moveToNext ? traverser->getNextComponent (this)
  33195. : traverser->getPreviousComponent (this);
  33196. traverser = 0;
  33197. if (nextComp != 0)
  33198. {
  33199. if (nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33200. {
  33201. SafePointer<Component> safePointer (this);
  33202. internalModalInputAttempt();
  33203. if (safePointer == 0 || nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33204. return;
  33205. }
  33206. nextComp->grabFocusInternal (focusChangedByTabKey);
  33207. return;
  33208. }
  33209. }
  33210. parentComponent_->moveKeyboardFocusToSibling (moveToNext);
  33211. }
  33212. }
  33213. bool Component::hasKeyboardFocus (const bool trueIfChildIsFocused) const
  33214. {
  33215. return (currentlyFocusedComponent == this)
  33216. || (trueIfChildIsFocused && isParentOf (currentlyFocusedComponent));
  33217. }
  33218. Component* JUCE_CALLTYPE Component::getCurrentlyFocusedComponent() throw()
  33219. {
  33220. return currentlyFocusedComponent;
  33221. }
  33222. void Component::giveAwayFocus()
  33223. {
  33224. // use a copy so we can clear the value before the call
  33225. Component* const componentLosingFocus = currentlyFocusedComponent;
  33226. currentlyFocusedComponent = 0;
  33227. Desktop::getInstance().triggerFocusCallback();
  33228. if (componentLosingFocus->isValidComponent())
  33229. componentLosingFocus->internalFocusLoss (focusChangedDirectly);
  33230. }
  33231. bool Component::isMouseOver() const throw()
  33232. {
  33233. return flags.mouseOverFlag;
  33234. }
  33235. bool Component::isMouseButtonDown() const throw()
  33236. {
  33237. return flags.draggingFlag;
  33238. }
  33239. bool Component::isMouseOverOrDragging() const throw()
  33240. {
  33241. return flags.mouseOverFlag || flags.draggingFlag;
  33242. }
  33243. bool JUCE_CALLTYPE Component::isMouseButtonDownAnywhere() throw()
  33244. {
  33245. return ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown();
  33246. }
  33247. const Point<int> Component::getMouseXYRelative() const
  33248. {
  33249. return globalPositionToRelative (Desktop::getMousePosition());
  33250. }
  33251. const Rectangle<int> Component::getParentMonitorArea() const
  33252. {
  33253. return Desktop::getInstance()
  33254. .getMonitorAreaContaining (relativePositionToGlobal (Point<int> (getWidth() / 2,
  33255. getHeight() / 2)));
  33256. }
  33257. void Component::addKeyListener (KeyListener* const newListener)
  33258. {
  33259. if (keyListeners_ == 0)
  33260. keyListeners_ = new VoidArray();
  33261. keyListeners_->addIfNotAlreadyThere (newListener);
  33262. }
  33263. void Component::removeKeyListener (KeyListener* const listenerToRemove)
  33264. {
  33265. if (keyListeners_ != 0)
  33266. keyListeners_->removeValue (listenerToRemove);
  33267. }
  33268. bool Component::keyPressed (const KeyPress&)
  33269. {
  33270. return false;
  33271. }
  33272. bool Component::keyStateChanged (const bool /*isKeyDown*/)
  33273. {
  33274. return false;
  33275. }
  33276. void Component::modifierKeysChanged (const ModifierKeys& modifiers)
  33277. {
  33278. if (parentComponent_ != 0)
  33279. parentComponent_->modifierKeysChanged (modifiers);
  33280. }
  33281. void Component::internalModifierKeysChanged()
  33282. {
  33283. sendFakeMouseMove();
  33284. modifierKeysChanged (ModifierKeys::getCurrentModifiers());
  33285. }
  33286. ComponentPeer* Component::getPeer() const
  33287. {
  33288. if (flags.hasHeavyweightPeerFlag)
  33289. return ComponentPeer::getPeerFor (this);
  33290. else if (parentComponent_ != 0)
  33291. return parentComponent_->getPeer();
  33292. else
  33293. return 0;
  33294. }
  33295. Component::BailOutChecker::BailOutChecker (Component* const component1, Component* const component2_)
  33296. : safePointer1 (component1), safePointer2 (component2_), component2 (component2_)
  33297. {
  33298. jassert (component1 != 0);
  33299. }
  33300. bool Component::BailOutChecker::shouldBailOut() const throw()
  33301. {
  33302. return safePointer1 == 0 || safePointer2.getComponent() != component2;
  33303. }
  33304. END_JUCE_NAMESPACE
  33305. /*** End of inlined file: juce_Component.cpp ***/
  33306. /*** Start of inlined file: juce_ComponentListener.cpp ***/
  33307. BEGIN_JUCE_NAMESPACE
  33308. void ComponentListener::componentMovedOrResized (Component&, bool, bool) {}
  33309. void ComponentListener::componentBroughtToFront (Component&) {}
  33310. void ComponentListener::componentVisibilityChanged (Component&) {}
  33311. void ComponentListener::componentChildrenChanged (Component&) {}
  33312. void ComponentListener::componentParentHierarchyChanged (Component&) {}
  33313. void ComponentListener::componentNameChanged (Component&) {}
  33314. void ComponentListener::componentBeingDeleted (Component&) {}
  33315. END_JUCE_NAMESPACE
  33316. /*** End of inlined file: juce_ComponentListener.cpp ***/
  33317. /*** Start of inlined file: juce_Desktop.cpp ***/
  33318. BEGIN_JUCE_NAMESPACE
  33319. Desktop::Desktop()
  33320. : mouseClickCounter (0),
  33321. kioskModeComponent (0)
  33322. {
  33323. createMouseInputSources();
  33324. refreshMonitorSizes();
  33325. }
  33326. Desktop::~Desktop()
  33327. {
  33328. jassert (instance == this);
  33329. instance = 0;
  33330. // doh! If you don't delete all your windows before exiting, you're going to
  33331. // be leaking memory!
  33332. jassert (desktopComponents.size() == 0);
  33333. }
  33334. Desktop& JUCE_CALLTYPE Desktop::getInstance()
  33335. {
  33336. if (instance == 0)
  33337. instance = new Desktop();
  33338. return *instance;
  33339. }
  33340. Desktop* Desktop::instance = 0;
  33341. extern void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords,
  33342. const bool clipToWorkArea);
  33343. void Desktop::refreshMonitorSizes()
  33344. {
  33345. const Array <Rectangle<int> > oldClipped (monitorCoordsClipped);
  33346. const Array <Rectangle<int> > oldUnclipped (monitorCoordsUnclipped);
  33347. monitorCoordsClipped.clear();
  33348. monitorCoordsUnclipped.clear();
  33349. juce_updateMultiMonitorInfo (monitorCoordsClipped, true);
  33350. juce_updateMultiMonitorInfo (monitorCoordsUnclipped, false);
  33351. jassert (monitorCoordsClipped.size() > 0
  33352. && monitorCoordsClipped.size() == monitorCoordsUnclipped.size());
  33353. if (oldClipped != monitorCoordsClipped
  33354. || oldUnclipped != monitorCoordsUnclipped)
  33355. {
  33356. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  33357. {
  33358. ComponentPeer* const p = ComponentPeer::getPeer (i);
  33359. if (p != 0)
  33360. p->handleScreenSizeChange();
  33361. }
  33362. }
  33363. }
  33364. int Desktop::getNumDisplayMonitors() const throw()
  33365. {
  33366. return monitorCoordsClipped.size();
  33367. }
  33368. const Rectangle<int> Desktop::getDisplayMonitorCoordinates (const int index, const bool clippedToWorkArea) const throw()
  33369. {
  33370. return clippedToWorkArea ? monitorCoordsClipped [index]
  33371. : monitorCoordsUnclipped [index];
  33372. }
  33373. const RectangleList Desktop::getAllMonitorDisplayAreas (const bool clippedToWorkArea) const throw()
  33374. {
  33375. RectangleList rl;
  33376. for (int i = 0; i < getNumDisplayMonitors(); ++i)
  33377. rl.addWithoutMerging (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33378. return rl;
  33379. }
  33380. const Rectangle<int> Desktop::getMainMonitorArea (const bool clippedToWorkArea) const throw()
  33381. {
  33382. return getDisplayMonitorCoordinates (0, clippedToWorkArea);
  33383. }
  33384. const Rectangle<int> Desktop::getMonitorAreaContaining (const Point<int>& position, const bool clippedToWorkArea) const
  33385. {
  33386. Rectangle<int> best (getMainMonitorArea (clippedToWorkArea));
  33387. double bestDistance = 1.0e10;
  33388. for (int i = getNumDisplayMonitors(); --i >= 0;)
  33389. {
  33390. const Rectangle<int> rect (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33391. if (rect.contains (position))
  33392. return rect;
  33393. const double distance = rect.getCentre().getDistanceFrom (position);
  33394. if (distance < bestDistance)
  33395. {
  33396. bestDistance = distance;
  33397. best = rect;
  33398. }
  33399. }
  33400. return best;
  33401. }
  33402. int Desktop::getNumComponents() const throw()
  33403. {
  33404. return desktopComponents.size();
  33405. }
  33406. Component* Desktop::getComponent (const int index) const throw()
  33407. {
  33408. return desktopComponents [index];
  33409. }
  33410. Component* Desktop::findComponentAt (const Point<int>& screenPosition) const
  33411. {
  33412. for (int i = desktopComponents.size(); --i >= 0;)
  33413. {
  33414. Component* const c = desktopComponents.getUnchecked(i);
  33415. const Point<int> relative (c->globalPositionToRelative (screenPosition));
  33416. if (c->contains (relative.getX(), relative.getY()))
  33417. return c->getComponentAt (relative.getX(), relative.getY());
  33418. }
  33419. return 0;
  33420. }
  33421. void Desktop::addDesktopComponent (Component* const c)
  33422. {
  33423. jassert (c != 0);
  33424. jassert (! desktopComponents.contains (c));
  33425. desktopComponents.addIfNotAlreadyThere (c);
  33426. }
  33427. void Desktop::removeDesktopComponent (Component* const c)
  33428. {
  33429. desktopComponents.removeValue (c);
  33430. }
  33431. void Desktop::componentBroughtToFront (Component* const c)
  33432. {
  33433. const int index = desktopComponents.indexOf (c);
  33434. jassert (index >= 0);
  33435. if (index >= 0)
  33436. {
  33437. int newIndex = -1;
  33438. if (! c->isAlwaysOnTop())
  33439. {
  33440. newIndex = desktopComponents.size();
  33441. while (newIndex > 0 && desktopComponents.getUnchecked (newIndex - 1)->isAlwaysOnTop())
  33442. --newIndex;
  33443. --newIndex;
  33444. }
  33445. desktopComponents.move (index, newIndex);
  33446. }
  33447. }
  33448. const Point<int> Desktop::getLastMouseDownPosition() throw()
  33449. {
  33450. return getInstance().getMainMouseSource().getLastMouseDownPosition();
  33451. }
  33452. int Desktop::getMouseButtonClickCounter() throw()
  33453. {
  33454. return getInstance().mouseClickCounter;
  33455. }
  33456. void Desktop::incrementMouseClickCounter() throw()
  33457. {
  33458. ++mouseClickCounter;
  33459. }
  33460. int Desktop::getNumDraggingMouseSources() const throw()
  33461. {
  33462. int num = 0;
  33463. for (int i = mouseSources.size(); --i >= 0;)
  33464. if (mouseSources.getUnchecked(i)->isDragging())
  33465. ++num;
  33466. return num;
  33467. }
  33468. MouseInputSource* Desktop::getDraggingMouseSource (int index) const throw()
  33469. {
  33470. int num = 0;
  33471. for (int i = mouseSources.size(); --i >= 0;)
  33472. {
  33473. MouseInputSource* const mi = mouseSources.getUnchecked(i);
  33474. if (mi->isDragging())
  33475. {
  33476. if (index == num)
  33477. return mi;
  33478. ++num;
  33479. }
  33480. }
  33481. return 0;
  33482. }
  33483. void Desktop::addFocusChangeListener (FocusChangeListener* const listener)
  33484. {
  33485. focusListeners.add (listener);
  33486. }
  33487. void Desktop::removeFocusChangeListener (FocusChangeListener* const listener)
  33488. {
  33489. focusListeners.remove (listener);
  33490. }
  33491. void Desktop::triggerFocusCallback()
  33492. {
  33493. triggerAsyncUpdate();
  33494. }
  33495. void Desktop::handleAsyncUpdate()
  33496. {
  33497. Component* currentFocus = Component::getCurrentlyFocusedComponent();
  33498. focusListeners.call (&FocusChangeListener::globalFocusChanged, currentFocus);
  33499. }
  33500. void Desktop::addGlobalMouseListener (MouseListener* const listener)
  33501. {
  33502. mouseListeners.add (listener);
  33503. resetTimer();
  33504. }
  33505. void Desktop::removeGlobalMouseListener (MouseListener* const listener)
  33506. {
  33507. mouseListeners.remove (listener);
  33508. resetTimer();
  33509. }
  33510. void Desktop::timerCallback()
  33511. {
  33512. if (lastFakeMouseMove != getMousePosition())
  33513. sendMouseMove();
  33514. }
  33515. void Desktop::sendMouseMove()
  33516. {
  33517. if (! mouseListeners.isEmpty())
  33518. {
  33519. startTimer (20);
  33520. lastFakeMouseMove = getMousePosition();
  33521. Component* const target = findComponentAt (lastFakeMouseMove);
  33522. if (target != 0)
  33523. {
  33524. Component::BailOutChecker checker (target);
  33525. const Point<int> pos (target->globalPositionToRelative (lastFakeMouseMove));
  33526. const Time now (Time::getCurrentTime());
  33527. const MouseEvent me (getMainMouseSource(), pos, ModifierKeys::getCurrentModifiers(),
  33528. target, now, pos, now, 0, false);
  33529. if (me.mods.isAnyMouseButtonDown())
  33530. mouseListeners.callChecked (checker, &MouseListener::mouseDrag, me);
  33531. else
  33532. mouseListeners.callChecked (checker, &MouseListener::mouseMove, me);
  33533. }
  33534. }
  33535. }
  33536. void Desktop::resetTimer()
  33537. {
  33538. if (mouseListeners.size() == 0)
  33539. stopTimer();
  33540. else
  33541. startTimer (100);
  33542. lastFakeMouseMove = getMousePosition();
  33543. }
  33544. extern void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars);
  33545. void Desktop::setKioskModeComponent (Component* componentToUse, const bool allowMenusAndBars)
  33546. {
  33547. if (kioskModeComponent != componentToUse)
  33548. {
  33549. // agh! Don't delete a component without first stopping it being the kiosk comp
  33550. jassert (kioskModeComponent == 0 || kioskModeComponent->isValidComponent());
  33551. // agh! Don't remove a component from the desktop if it's the kiosk comp!
  33552. jassert (kioskModeComponent == 0 || kioskModeComponent->isOnDesktop());
  33553. if (kioskModeComponent->isValidComponent())
  33554. {
  33555. juce_setKioskComponent (kioskModeComponent, false, allowMenusAndBars);
  33556. kioskModeComponent->setBounds (kioskComponentOriginalBounds);
  33557. }
  33558. kioskModeComponent = componentToUse;
  33559. if (kioskModeComponent != 0)
  33560. {
  33561. jassert (kioskModeComponent->isValidComponent());
  33562. // Only components that are already on the desktop can be put into kiosk mode!
  33563. jassert (kioskModeComponent->isOnDesktop());
  33564. kioskComponentOriginalBounds = kioskModeComponent->getBounds();
  33565. juce_setKioskComponent (kioskModeComponent, true, allowMenusAndBars);
  33566. }
  33567. }
  33568. }
  33569. END_JUCE_NAMESPACE
  33570. /*** End of inlined file: juce_Desktop.cpp ***/
  33571. /*** Start of inlined file: juce_ArrowButton.cpp ***/
  33572. BEGIN_JUCE_NAMESPACE
  33573. ArrowButton::ArrowButton (const String& name,
  33574. float arrowDirectionInRadians,
  33575. const Colour& arrowColour)
  33576. : Button (name),
  33577. colour (arrowColour)
  33578. {
  33579. path.lineTo (0.0f, 1.0f);
  33580. path.lineTo (1.0f, 0.5f);
  33581. path.closeSubPath();
  33582. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * arrowDirectionInRadians,
  33583. 0.5f, 0.5f));
  33584. setComponentEffect (&shadow);
  33585. buttonStateChanged();
  33586. }
  33587. ArrowButton::~ArrowButton()
  33588. {
  33589. }
  33590. void ArrowButton::paintButton (Graphics& g,
  33591. bool /*isMouseOverButton*/,
  33592. bool /*isButtonDown*/)
  33593. {
  33594. g.setColour (colour);
  33595. g.fillPath (path, path.getTransformToScaleToFit ((float) offset,
  33596. (float) offset,
  33597. (float) (getWidth() - 3),
  33598. (float) (getHeight() - 3),
  33599. false));
  33600. }
  33601. void ArrowButton::buttonStateChanged()
  33602. {
  33603. offset = (isDown()) ? 1 : 0;
  33604. shadow.setShadowProperties ((isDown()) ? 1.2f : 3.0f,
  33605. 0.3f, -1, 0);
  33606. }
  33607. END_JUCE_NAMESPACE
  33608. /*** End of inlined file: juce_ArrowButton.cpp ***/
  33609. /*** Start of inlined file: juce_Button.cpp ***/
  33610. BEGIN_JUCE_NAMESPACE
  33611. class Button::RepeatTimer : public Timer
  33612. {
  33613. public:
  33614. RepeatTimer (Button& owner_) : owner (owner_) {}
  33615. void timerCallback() { owner.repeatTimerCallback(); }
  33616. juce_UseDebuggingNewOperator
  33617. private:
  33618. Button& owner;
  33619. RepeatTimer (const RepeatTimer&);
  33620. RepeatTimer& operator= (const RepeatTimer&);
  33621. };
  33622. Button::Button (const String& name)
  33623. : Component (name),
  33624. text (name),
  33625. buttonPressTime (0),
  33626. lastTimeCallbackTime (0),
  33627. commandManagerToUse (0),
  33628. autoRepeatDelay (-1),
  33629. autoRepeatSpeed (0),
  33630. autoRepeatMinimumDelay (-1),
  33631. radioGroupId (0),
  33632. commandID (0),
  33633. connectedEdgeFlags (0),
  33634. buttonState (buttonNormal),
  33635. lastToggleState (false),
  33636. clickTogglesState (false),
  33637. needsToRelease (false),
  33638. needsRepainting (false),
  33639. isKeyDown (false),
  33640. triggerOnMouseDown (false),
  33641. generateTooltip (false)
  33642. {
  33643. setWantsKeyboardFocus (true);
  33644. isOn.addListener (this);
  33645. }
  33646. Button::~Button()
  33647. {
  33648. isOn.removeListener (this);
  33649. if (commandManagerToUse != 0)
  33650. commandManagerToUse->removeListener (this);
  33651. repeatTimer = 0;
  33652. clearShortcuts();
  33653. }
  33654. void Button::setButtonText (const String& newText)
  33655. {
  33656. if (text != newText)
  33657. {
  33658. text = newText;
  33659. repaint();
  33660. }
  33661. }
  33662. void Button::setTooltip (const String& newTooltip)
  33663. {
  33664. SettableTooltipClient::setTooltip (newTooltip);
  33665. generateTooltip = false;
  33666. }
  33667. const String Button::getTooltip()
  33668. {
  33669. if (generateTooltip && commandManagerToUse != 0 && commandID != 0)
  33670. {
  33671. String tt (commandManagerToUse->getDescriptionOfCommand (commandID));
  33672. Array <KeyPress> keyPresses (commandManagerToUse->getKeyMappings()->getKeyPressesAssignedToCommand (commandID));
  33673. for (int i = 0; i < keyPresses.size(); ++i)
  33674. {
  33675. const String key (keyPresses.getReference(i).getTextDescription());
  33676. tt << " [";
  33677. if (key.length() == 1)
  33678. tt << TRANS("shortcut") << ": '" << key << "']";
  33679. else
  33680. tt << key << ']';
  33681. }
  33682. return tt;
  33683. }
  33684. return SettableTooltipClient::getTooltip();
  33685. }
  33686. void Button::setConnectedEdges (const int connectedEdgeFlags_)
  33687. {
  33688. if (connectedEdgeFlags != connectedEdgeFlags_)
  33689. {
  33690. connectedEdgeFlags = connectedEdgeFlags_;
  33691. repaint();
  33692. }
  33693. }
  33694. void Button::setToggleState (const bool shouldBeOn,
  33695. const bool sendChangeNotification)
  33696. {
  33697. if (shouldBeOn != lastToggleState)
  33698. {
  33699. isOn = shouldBeOn;
  33700. lastToggleState = shouldBeOn;
  33701. repaint();
  33702. if (sendChangeNotification)
  33703. {
  33704. Component::SafePointer<Component> deletionWatcher (this);
  33705. sendClickMessage (ModifierKeys());
  33706. if (deletionWatcher == 0)
  33707. return;
  33708. }
  33709. if (lastToggleState)
  33710. turnOffOtherButtonsInGroup (sendChangeNotification);
  33711. }
  33712. }
  33713. void Button::setClickingTogglesState (const bool shouldToggle) throw()
  33714. {
  33715. clickTogglesState = shouldToggle;
  33716. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  33717. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  33718. // it is that this button represents, and the button will update its state to reflect this
  33719. // in the applicationCommandListChanged() method.
  33720. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  33721. }
  33722. bool Button::getClickingTogglesState() const throw()
  33723. {
  33724. return clickTogglesState;
  33725. }
  33726. void Button::valueChanged (Value& value)
  33727. {
  33728. if (value.refersToSameSourceAs (isOn))
  33729. setToggleState (isOn.getValue(), true);
  33730. }
  33731. void Button::setRadioGroupId (const int newGroupId)
  33732. {
  33733. if (radioGroupId != newGroupId)
  33734. {
  33735. radioGroupId = newGroupId;
  33736. if (lastToggleState)
  33737. turnOffOtherButtonsInGroup (true);
  33738. }
  33739. }
  33740. void Button::turnOffOtherButtonsInGroup (const bool sendChangeNotification)
  33741. {
  33742. Component* const p = getParentComponent();
  33743. if (p != 0 && radioGroupId != 0)
  33744. {
  33745. Component::SafePointer<Component> deletionWatcher (this);
  33746. for (int i = p->getNumChildComponents(); --i >= 0;)
  33747. {
  33748. Component* const c = p->getChildComponent (i);
  33749. if (c != this)
  33750. {
  33751. Button* const b = dynamic_cast <Button*> (c);
  33752. if (b != 0 && b->getRadioGroupId() == radioGroupId)
  33753. {
  33754. b->setToggleState (false, sendChangeNotification);
  33755. if (deletionWatcher == 0)
  33756. return;
  33757. }
  33758. }
  33759. }
  33760. }
  33761. }
  33762. void Button::enablementChanged()
  33763. {
  33764. updateState (0);
  33765. repaint();
  33766. }
  33767. Button::ButtonState Button::updateState (const MouseEvent* const e)
  33768. {
  33769. ButtonState state = buttonNormal;
  33770. if (isEnabled() && isVisible() && ! isCurrentlyBlockedByAnotherModalComponent())
  33771. {
  33772. Point<int> mousePos;
  33773. if (e == 0)
  33774. mousePos = getMouseXYRelative();
  33775. else
  33776. mousePos = e->getEventRelativeTo (this).getPosition();
  33777. const bool over = reallyContains (mousePos.getX(), mousePos.getY(), true);
  33778. const bool down = isMouseButtonDown();
  33779. if ((down && (over || (triggerOnMouseDown && buttonState == buttonDown))) || isKeyDown)
  33780. state = buttonDown;
  33781. else if (over)
  33782. state = buttonOver;
  33783. }
  33784. setState (state);
  33785. return state;
  33786. }
  33787. void Button::setState (const ButtonState newState)
  33788. {
  33789. if (buttonState != newState)
  33790. {
  33791. buttonState = newState;
  33792. repaint();
  33793. if (buttonState == buttonDown)
  33794. {
  33795. buttonPressTime = Time::getApproximateMillisecondCounter();
  33796. lastTimeCallbackTime = buttonPressTime;
  33797. }
  33798. sendStateMessage();
  33799. }
  33800. }
  33801. bool Button::isDown() const throw()
  33802. {
  33803. return buttonState == buttonDown;
  33804. }
  33805. bool Button::isOver() const throw()
  33806. {
  33807. return buttonState != buttonNormal;
  33808. }
  33809. void Button::buttonStateChanged()
  33810. {
  33811. }
  33812. uint32 Button::getMillisecondsSinceButtonDown() const throw()
  33813. {
  33814. const uint32 now = Time::getApproximateMillisecondCounter();
  33815. return now > buttonPressTime ? now - buttonPressTime : 0;
  33816. }
  33817. void Button::setTriggeredOnMouseDown (const bool isTriggeredOnMouseDown) throw()
  33818. {
  33819. triggerOnMouseDown = isTriggeredOnMouseDown;
  33820. }
  33821. void Button::clicked()
  33822. {
  33823. }
  33824. void Button::clicked (const ModifierKeys& /*modifiers*/)
  33825. {
  33826. clicked();
  33827. }
  33828. static const int clickMessageId = 0x2f3f4f99;
  33829. void Button::triggerClick()
  33830. {
  33831. postCommandMessage (clickMessageId);
  33832. }
  33833. void Button::internalClickCallback (const ModifierKeys& modifiers)
  33834. {
  33835. if (clickTogglesState)
  33836. setToggleState ((radioGroupId != 0) || ! lastToggleState, false);
  33837. sendClickMessage (modifiers);
  33838. }
  33839. void Button::flashButtonState()
  33840. {
  33841. if (isEnabled())
  33842. {
  33843. needsToRelease = true;
  33844. setState (buttonDown);
  33845. getRepeatTimer().startTimer (100);
  33846. }
  33847. }
  33848. void Button::handleCommandMessage (int commandId)
  33849. {
  33850. if (commandId == clickMessageId)
  33851. {
  33852. if (isEnabled())
  33853. {
  33854. flashButtonState();
  33855. internalClickCallback (ModifierKeys::getCurrentModifiers());
  33856. }
  33857. }
  33858. else
  33859. {
  33860. Component::handleCommandMessage (commandId);
  33861. }
  33862. }
  33863. void Button::addButtonListener (ButtonListener* const newListener)
  33864. {
  33865. buttonListeners.add (newListener);
  33866. }
  33867. void Button::removeButtonListener (ButtonListener* const listener)
  33868. {
  33869. buttonListeners.remove (listener);
  33870. }
  33871. void Button::sendClickMessage (const ModifierKeys& modifiers)
  33872. {
  33873. Component::BailOutChecker checker (this);
  33874. if (commandManagerToUse != 0 && commandID != 0)
  33875. {
  33876. ApplicationCommandTarget::InvocationInfo info (commandID);
  33877. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromButton;
  33878. info.originatingComponent = this;
  33879. commandManagerToUse->invoke (info, true);
  33880. }
  33881. clicked (modifiers);
  33882. if (! checker.shouldBailOut())
  33883. buttonListeners.callChecked (checker, &ButtonListener::buttonClicked, this);
  33884. }
  33885. void Button::sendStateMessage()
  33886. {
  33887. Component::BailOutChecker checker (this);
  33888. buttonStateChanged();
  33889. if (! checker.shouldBailOut())
  33890. buttonListeners.callChecked (checker, &ButtonListener::buttonStateChanged, this);
  33891. }
  33892. void Button::paint (Graphics& g)
  33893. {
  33894. if (needsToRelease && isEnabled())
  33895. {
  33896. needsToRelease = false;
  33897. needsRepainting = true;
  33898. }
  33899. paintButton (g, isOver(), isDown());
  33900. }
  33901. void Button::mouseEnter (const MouseEvent& e)
  33902. {
  33903. updateState (&e);
  33904. }
  33905. void Button::mouseExit (const MouseEvent& e)
  33906. {
  33907. updateState (&e);
  33908. }
  33909. void Button::mouseDown (const MouseEvent& e)
  33910. {
  33911. updateState (&e);
  33912. if (isDown())
  33913. {
  33914. if (autoRepeatDelay >= 0)
  33915. getRepeatTimer().startTimer (autoRepeatDelay);
  33916. if (triggerOnMouseDown)
  33917. internalClickCallback (e.mods);
  33918. }
  33919. }
  33920. void Button::mouseUp (const MouseEvent& e)
  33921. {
  33922. const bool wasDown = isDown();
  33923. updateState (&e);
  33924. if (wasDown && isOver() && ! triggerOnMouseDown)
  33925. internalClickCallback (e.mods);
  33926. }
  33927. void Button::mouseDrag (const MouseEvent& e)
  33928. {
  33929. const ButtonState oldState = buttonState;
  33930. updateState (&e);
  33931. if (autoRepeatDelay >= 0 && buttonState != oldState && isDown())
  33932. getRepeatTimer().startTimer (autoRepeatSpeed);
  33933. }
  33934. void Button::focusGained (FocusChangeType)
  33935. {
  33936. updateState (0);
  33937. repaint();
  33938. }
  33939. void Button::focusLost (FocusChangeType)
  33940. {
  33941. updateState (0);
  33942. repaint();
  33943. }
  33944. void Button::setVisible (bool shouldBeVisible)
  33945. {
  33946. if (shouldBeVisible != isVisible())
  33947. {
  33948. Component::setVisible (shouldBeVisible);
  33949. if (! shouldBeVisible)
  33950. needsToRelease = false;
  33951. updateState (0);
  33952. }
  33953. else
  33954. {
  33955. Component::setVisible (shouldBeVisible);
  33956. }
  33957. }
  33958. void Button::parentHierarchyChanged()
  33959. {
  33960. Component* const newKeySource = (shortcuts.size() == 0) ? 0 : getTopLevelComponent();
  33961. if (newKeySource != keySource.getComponent())
  33962. {
  33963. if (keySource != 0)
  33964. keySource->removeKeyListener (this);
  33965. keySource = newKeySource;
  33966. if (keySource != 0)
  33967. keySource->addKeyListener (this);
  33968. }
  33969. }
  33970. void Button::setCommandToTrigger (ApplicationCommandManager* const commandManagerToUse_,
  33971. const int commandID_,
  33972. const bool generateTooltip_)
  33973. {
  33974. commandID = commandID_;
  33975. generateTooltip = generateTooltip_;
  33976. if (commandManagerToUse != commandManagerToUse_)
  33977. {
  33978. if (commandManagerToUse != 0)
  33979. commandManagerToUse->removeListener (this);
  33980. commandManagerToUse = commandManagerToUse_;
  33981. if (commandManagerToUse != 0)
  33982. commandManagerToUse->addListener (this);
  33983. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  33984. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  33985. // it is that this button represents, and the button will update its state to reflect this
  33986. // in the applicationCommandListChanged() method.
  33987. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  33988. }
  33989. if (commandManagerToUse != 0)
  33990. applicationCommandListChanged();
  33991. else
  33992. setEnabled (true);
  33993. }
  33994. void Button::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  33995. {
  33996. if (info.commandID == commandID
  33997. && (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) == 0)
  33998. {
  33999. flashButtonState();
  34000. }
  34001. }
  34002. void Button::applicationCommandListChanged()
  34003. {
  34004. if (commandManagerToUse != 0)
  34005. {
  34006. ApplicationCommandInfo info (0);
  34007. ApplicationCommandTarget* const target = commandManagerToUse->getTargetForCommand (commandID, info);
  34008. setEnabled (target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0);
  34009. if (target != 0)
  34010. setToggleState ((info.flags & ApplicationCommandInfo::isTicked) != 0, false);
  34011. }
  34012. }
  34013. void Button::addShortcut (const KeyPress& key)
  34014. {
  34015. if (key.isValid())
  34016. {
  34017. jassert (! isRegisteredForShortcut (key)); // already registered!
  34018. shortcuts.add (key);
  34019. parentHierarchyChanged();
  34020. }
  34021. }
  34022. void Button::clearShortcuts()
  34023. {
  34024. shortcuts.clear();
  34025. parentHierarchyChanged();
  34026. }
  34027. bool Button::isShortcutPressed() const
  34028. {
  34029. if (! isCurrentlyBlockedByAnotherModalComponent())
  34030. {
  34031. for (int i = shortcuts.size(); --i >= 0;)
  34032. if (shortcuts.getReference(i).isCurrentlyDown())
  34033. return true;
  34034. }
  34035. return false;
  34036. }
  34037. bool Button::isRegisteredForShortcut (const KeyPress& key) const
  34038. {
  34039. for (int i = shortcuts.size(); --i >= 0;)
  34040. if (key == shortcuts.getReference(i))
  34041. return true;
  34042. return false;
  34043. }
  34044. bool Button::keyStateChanged (const bool, Component*)
  34045. {
  34046. if (! isEnabled())
  34047. return false;
  34048. const bool wasDown = isKeyDown;
  34049. isKeyDown = isShortcutPressed();
  34050. if (autoRepeatDelay >= 0 && (isKeyDown && ! wasDown))
  34051. getRepeatTimer().startTimer (autoRepeatDelay);
  34052. updateState (0);
  34053. if (isEnabled() && wasDown && ! isKeyDown)
  34054. {
  34055. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34056. // (return immediately - this button may now have been deleted)
  34057. return true;
  34058. }
  34059. return wasDown || isKeyDown;
  34060. }
  34061. bool Button::keyPressed (const KeyPress&, Component*)
  34062. {
  34063. // returning true will avoid forwarding events for keys that we're using as shortcuts
  34064. return isShortcutPressed();
  34065. }
  34066. bool Button::keyPressed (const KeyPress& key)
  34067. {
  34068. if (isEnabled() && key.isKeyCode (KeyPress::returnKey))
  34069. {
  34070. triggerClick();
  34071. return true;
  34072. }
  34073. return false;
  34074. }
  34075. void Button::setRepeatSpeed (const int initialDelayMillisecs,
  34076. const int repeatMillisecs,
  34077. const int minimumDelayInMillisecs) throw()
  34078. {
  34079. autoRepeatDelay = initialDelayMillisecs;
  34080. autoRepeatSpeed = repeatMillisecs;
  34081. autoRepeatMinimumDelay = jmin (autoRepeatSpeed, minimumDelayInMillisecs);
  34082. }
  34083. void Button::repeatTimerCallback()
  34084. {
  34085. if (needsRepainting)
  34086. {
  34087. getRepeatTimer().stopTimer();
  34088. updateState (0);
  34089. needsRepainting = false;
  34090. }
  34091. else if (autoRepeatSpeed > 0 && (isKeyDown || (updateState (0) == buttonDown)))
  34092. {
  34093. int repeatSpeed = autoRepeatSpeed;
  34094. if (autoRepeatMinimumDelay >= 0)
  34095. {
  34096. double timeHeldDown = jmin (1.0, getMillisecondsSinceButtonDown() / 4000.0);
  34097. timeHeldDown *= timeHeldDown;
  34098. repeatSpeed = repeatSpeed + (int) (timeHeldDown * (autoRepeatMinimumDelay - repeatSpeed));
  34099. }
  34100. repeatSpeed = jmax (1, repeatSpeed);
  34101. getRepeatTimer().startTimer (repeatSpeed);
  34102. const uint32 now = Time::getApproximateMillisecondCounter();
  34103. const int numTimesToCallback = (now > lastTimeCallbackTime) ? jmax (1, (int) (now - lastTimeCallbackTime) / repeatSpeed) : 1;
  34104. lastTimeCallbackTime = now;
  34105. Component::SafePointer<Component> deletionWatcher (this);
  34106. for (int i = numTimesToCallback; --i >= 0;)
  34107. {
  34108. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34109. if (deletionWatcher == 0 || ! isDown())
  34110. return;
  34111. }
  34112. }
  34113. else if (! needsToRelease)
  34114. {
  34115. getRepeatTimer().stopTimer();
  34116. }
  34117. }
  34118. Button::RepeatTimer& Button::getRepeatTimer()
  34119. {
  34120. if (repeatTimer == 0)
  34121. repeatTimer = new RepeatTimer (*this);
  34122. return *repeatTimer;
  34123. }
  34124. END_JUCE_NAMESPACE
  34125. /*** End of inlined file: juce_Button.cpp ***/
  34126. /*** Start of inlined file: juce_DrawableButton.cpp ***/
  34127. BEGIN_JUCE_NAMESPACE
  34128. DrawableButton::DrawableButton (const String& name,
  34129. const DrawableButton::ButtonStyle buttonStyle)
  34130. : Button (name),
  34131. style (buttonStyle),
  34132. edgeIndent (3)
  34133. {
  34134. if (buttonStyle == ImageOnButtonBackground)
  34135. {
  34136. backgroundOff = Colour (0xffbbbbff);
  34137. backgroundOn = Colour (0xff3333ff);
  34138. }
  34139. else
  34140. {
  34141. backgroundOff = Colours::transparentBlack;
  34142. backgroundOn = Colour (0xaabbbbff);
  34143. }
  34144. }
  34145. DrawableButton::~DrawableButton()
  34146. {
  34147. deleteImages();
  34148. }
  34149. void DrawableButton::deleteImages()
  34150. {
  34151. }
  34152. void DrawableButton::setImages (const Drawable* normal,
  34153. const Drawable* over,
  34154. const Drawable* down,
  34155. const Drawable* disabled,
  34156. const Drawable* normalOn,
  34157. const Drawable* overOn,
  34158. const Drawable* downOn,
  34159. const Drawable* disabledOn)
  34160. {
  34161. deleteImages();
  34162. jassert (normal != 0); // you really need to give it at least a normal image..
  34163. if (normal != 0)
  34164. normalImage = normal->createCopy();
  34165. if (over != 0)
  34166. overImage = over->createCopy();
  34167. if (down != 0)
  34168. downImage = down->createCopy();
  34169. if (disabled != 0)
  34170. disabledImage = disabled->createCopy();
  34171. if (normalOn != 0)
  34172. normalImageOn = normalOn->createCopy();
  34173. if (overOn != 0)
  34174. overImageOn = overOn->createCopy();
  34175. if (downOn != 0)
  34176. downImageOn = downOn->createCopy();
  34177. if (disabledOn != 0)
  34178. disabledImageOn = disabledOn->createCopy();
  34179. repaint();
  34180. }
  34181. void DrawableButton::setButtonStyle (const DrawableButton::ButtonStyle newStyle)
  34182. {
  34183. if (style != newStyle)
  34184. {
  34185. style = newStyle;
  34186. repaint();
  34187. }
  34188. }
  34189. void DrawableButton::setBackgroundColours (const Colour& toggledOffColour,
  34190. const Colour& toggledOnColour)
  34191. {
  34192. if (backgroundOff != toggledOffColour
  34193. || backgroundOn != toggledOnColour)
  34194. {
  34195. backgroundOff = toggledOffColour;
  34196. backgroundOn = toggledOnColour;
  34197. repaint();
  34198. }
  34199. }
  34200. const Colour& DrawableButton::getBackgroundColour() const throw()
  34201. {
  34202. return getToggleState() ? backgroundOn
  34203. : backgroundOff;
  34204. }
  34205. void DrawableButton::setEdgeIndent (const int numPixelsIndent)
  34206. {
  34207. edgeIndent = numPixelsIndent;
  34208. repaint();
  34209. }
  34210. void DrawableButton::paintButton (Graphics& g,
  34211. bool isMouseOverButton,
  34212. bool isButtonDown)
  34213. {
  34214. Rectangle<int> imageSpace;
  34215. if (style == ImageOnButtonBackground)
  34216. {
  34217. const int insetX = getWidth() / 4;
  34218. const int insetY = getHeight() / 4;
  34219. imageSpace.setBounds (insetX, insetY, getWidth() - insetX * 2, getHeight() - insetY * 2);
  34220. getLookAndFeel().drawButtonBackground (g, *this,
  34221. getBackgroundColour(),
  34222. isMouseOverButton,
  34223. isButtonDown);
  34224. }
  34225. else
  34226. {
  34227. g.fillAll (getBackgroundColour());
  34228. const int textH = (style == ImageAboveTextLabel)
  34229. ? jmin (16, proportionOfHeight (0.25f))
  34230. : 0;
  34231. const int indentX = jmin (edgeIndent, proportionOfWidth (0.3f));
  34232. const int indentY = jmin (edgeIndent, proportionOfHeight (0.3f));
  34233. imageSpace.setBounds (indentX, indentY,
  34234. getWidth() - indentX * 2,
  34235. getHeight() - indentY * 2 - textH);
  34236. if (textH > 0)
  34237. {
  34238. g.setFont ((float) textH);
  34239. g.setColour (Colours::black.withAlpha (isEnabled() ? 1.0f : 0.4f));
  34240. g.drawFittedText (getButtonText(),
  34241. 2, getHeight() - textH - 1,
  34242. getWidth() - 4, textH,
  34243. Justification::centred, 1);
  34244. }
  34245. }
  34246. g.setImageResamplingQuality (Graphics::mediumResamplingQuality);
  34247. g.setOpacity (1.0f);
  34248. const Drawable* imageToDraw = 0;
  34249. if (isEnabled())
  34250. {
  34251. imageToDraw = getCurrentImage();
  34252. }
  34253. else
  34254. {
  34255. imageToDraw = getToggleState() ? disabledImageOn
  34256. : disabledImage;
  34257. if (imageToDraw == 0)
  34258. {
  34259. g.setOpacity (0.4f);
  34260. imageToDraw = getNormalImage();
  34261. }
  34262. }
  34263. if (imageToDraw != 0)
  34264. {
  34265. if (style == ImageRaw)
  34266. {
  34267. imageToDraw->draw (g, 1.0f);
  34268. }
  34269. else
  34270. {
  34271. imageToDraw->drawWithin (g,
  34272. imageSpace.getX(),
  34273. imageSpace.getY(),
  34274. imageSpace.getWidth(),
  34275. imageSpace.getHeight(),
  34276. RectanglePlacement::centred,
  34277. 1.0f);
  34278. }
  34279. }
  34280. }
  34281. const Drawable* DrawableButton::getCurrentImage() const throw()
  34282. {
  34283. if (isDown())
  34284. return getDownImage();
  34285. if (isOver())
  34286. return getOverImage();
  34287. return getNormalImage();
  34288. }
  34289. const Drawable* DrawableButton::getNormalImage() const throw()
  34290. {
  34291. return (getToggleState() && normalImageOn != 0) ? normalImageOn
  34292. : normalImage;
  34293. }
  34294. const Drawable* DrawableButton::getOverImage() const throw()
  34295. {
  34296. const Drawable* d = normalImage;
  34297. if (getToggleState())
  34298. {
  34299. if (overImageOn != 0)
  34300. d = overImageOn;
  34301. else if (normalImageOn != 0)
  34302. d = normalImageOn;
  34303. else if (overImage != 0)
  34304. d = overImage;
  34305. }
  34306. else
  34307. {
  34308. if (overImage != 0)
  34309. d = overImage;
  34310. }
  34311. return d;
  34312. }
  34313. const Drawable* DrawableButton::getDownImage() const throw()
  34314. {
  34315. const Drawable* d = normalImage;
  34316. if (getToggleState())
  34317. {
  34318. if (downImageOn != 0)
  34319. d = downImageOn;
  34320. else if (overImageOn != 0)
  34321. d = overImageOn;
  34322. else if (normalImageOn != 0)
  34323. d = normalImageOn;
  34324. else if (downImage != 0)
  34325. d = downImage;
  34326. else
  34327. d = getOverImage();
  34328. }
  34329. else
  34330. {
  34331. if (downImage != 0)
  34332. d = downImage;
  34333. else
  34334. d = getOverImage();
  34335. }
  34336. return d;
  34337. }
  34338. END_JUCE_NAMESPACE
  34339. /*** End of inlined file: juce_DrawableButton.cpp ***/
  34340. /*** Start of inlined file: juce_HyperlinkButton.cpp ***/
  34341. BEGIN_JUCE_NAMESPACE
  34342. HyperlinkButton::HyperlinkButton (const String& linkText,
  34343. const URL& linkURL)
  34344. : Button (linkText),
  34345. url (linkURL),
  34346. font (14.0f, Font::underlined),
  34347. resizeFont (true),
  34348. justification (Justification::centred)
  34349. {
  34350. setMouseCursor (MouseCursor::PointingHandCursor);
  34351. setTooltip (linkURL.toString (false));
  34352. }
  34353. HyperlinkButton::~HyperlinkButton()
  34354. {
  34355. }
  34356. void HyperlinkButton::setFont (const Font& newFont,
  34357. const bool resizeToMatchComponentHeight,
  34358. const Justification& justificationType)
  34359. {
  34360. font = newFont;
  34361. resizeFont = resizeToMatchComponentHeight;
  34362. justification = justificationType;
  34363. repaint();
  34364. }
  34365. void HyperlinkButton::setURL (const URL& newURL) throw()
  34366. {
  34367. url = newURL;
  34368. setTooltip (newURL.toString (false));
  34369. }
  34370. const Font HyperlinkButton::getFontToUse() const
  34371. {
  34372. Font f (font);
  34373. if (resizeFont)
  34374. f.setHeight (getHeight() * 0.7f);
  34375. return f;
  34376. }
  34377. void HyperlinkButton::changeWidthToFitText()
  34378. {
  34379. setSize (getFontToUse().getStringWidth (getName()) + 6, getHeight());
  34380. }
  34381. void HyperlinkButton::colourChanged()
  34382. {
  34383. repaint();
  34384. }
  34385. void HyperlinkButton::clicked()
  34386. {
  34387. if (url.isWellFormed())
  34388. url.launchInDefaultBrowser();
  34389. }
  34390. void HyperlinkButton::paintButton (Graphics& g,
  34391. bool isMouseOverButton,
  34392. bool isButtonDown)
  34393. {
  34394. const Colour textColour (findColour (textColourId));
  34395. if (isEnabled())
  34396. g.setColour ((isMouseOverButton) ? textColour.darker ((isButtonDown) ? 1.3f : 0.4f)
  34397. : textColour);
  34398. else
  34399. g.setColour (textColour.withMultipliedAlpha (0.4f));
  34400. g.setFont (getFontToUse());
  34401. g.drawText (getButtonText(),
  34402. 2, 0, getWidth() - 2, getHeight(),
  34403. justification.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  34404. true);
  34405. }
  34406. END_JUCE_NAMESPACE
  34407. /*** End of inlined file: juce_HyperlinkButton.cpp ***/
  34408. /*** Start of inlined file: juce_ImageButton.cpp ***/
  34409. BEGIN_JUCE_NAMESPACE
  34410. ImageButton::ImageButton (const String& text_)
  34411. : Button (text_),
  34412. scaleImageToFit (true),
  34413. preserveProportions (true),
  34414. alphaThreshold (0),
  34415. imageX (0),
  34416. imageY (0),
  34417. imageW (0),
  34418. imageH (0),
  34419. normalImage (0),
  34420. overImage (0),
  34421. downImage (0)
  34422. {
  34423. }
  34424. ImageButton::~ImageButton()
  34425. {
  34426. deleteImages();
  34427. }
  34428. void ImageButton::deleteImages()
  34429. {
  34430. ImageCache::releaseOrDelete (normalImage);
  34431. ImageCache::releaseOrDelete (overImage);
  34432. ImageCache::releaseOrDelete (downImage);
  34433. }
  34434. void ImageButton::setImages (const bool resizeButtonNowToFitThisImage,
  34435. const bool rescaleImagesWhenButtonSizeChanges,
  34436. const bool preserveImageProportions,
  34437. Image* const normalImage_,
  34438. const float imageOpacityWhenNormal,
  34439. const Colour& overlayColourWhenNormal,
  34440. Image* const overImage_,
  34441. const float imageOpacityWhenOver,
  34442. const Colour& overlayColourWhenOver,
  34443. Image* const downImage_,
  34444. const float imageOpacityWhenDown,
  34445. const Colour& overlayColourWhenDown,
  34446. const float hitTestAlphaThreshold)
  34447. {
  34448. deleteImages();
  34449. normalImage = normalImage_;
  34450. overImage = overImage_;
  34451. downImage = downImage_;
  34452. if (resizeButtonNowToFitThisImage && normalImage != 0)
  34453. {
  34454. imageW = normalImage->getWidth();
  34455. imageH = normalImage->getHeight();
  34456. setSize (imageW, imageH);
  34457. }
  34458. scaleImageToFit = rescaleImagesWhenButtonSizeChanges;
  34459. preserveProportions = preserveImageProportions;
  34460. normalOpacity = imageOpacityWhenNormal;
  34461. normalOverlay = overlayColourWhenNormal;
  34462. overOpacity = imageOpacityWhenOver;
  34463. overOverlay = overlayColourWhenOver;
  34464. downOpacity = imageOpacityWhenDown;
  34465. downOverlay = overlayColourWhenDown;
  34466. alphaThreshold = (unsigned char) jlimit (0, 0xff, roundToInt (255.0f * hitTestAlphaThreshold));
  34467. repaint();
  34468. }
  34469. Image* ImageButton::getCurrentImage() const
  34470. {
  34471. if (isDown() || getToggleState())
  34472. return getDownImage();
  34473. if (isOver())
  34474. return getOverImage();
  34475. return getNormalImage();
  34476. }
  34477. Image* ImageButton::getNormalImage() const throw()
  34478. {
  34479. return normalImage;
  34480. }
  34481. Image* ImageButton::getOverImage() const throw()
  34482. {
  34483. return (overImage != 0) ? overImage
  34484. : normalImage;
  34485. }
  34486. Image* ImageButton::getDownImage() const throw()
  34487. {
  34488. return (downImage != 0) ? downImage
  34489. : getOverImage();
  34490. }
  34491. void ImageButton::paintButton (Graphics& g,
  34492. bool isMouseOverButton,
  34493. bool isButtonDown)
  34494. {
  34495. if (! isEnabled())
  34496. {
  34497. isMouseOverButton = false;
  34498. isButtonDown = false;
  34499. }
  34500. Image* const im = getCurrentImage();
  34501. if (im != 0)
  34502. {
  34503. const int iw = im->getWidth();
  34504. const int ih = im->getHeight();
  34505. imageW = getWidth();
  34506. imageH = getHeight();
  34507. imageX = (imageW - iw) >> 1;
  34508. imageY = (imageH - ih) >> 1;
  34509. if (scaleImageToFit)
  34510. {
  34511. if (preserveProportions)
  34512. {
  34513. int newW, newH;
  34514. const float imRatio = ih / (float)iw;
  34515. const float destRatio = imageH / (float)imageW;
  34516. if (imRatio > destRatio)
  34517. {
  34518. newW = roundToInt (imageH / imRatio);
  34519. newH = imageH;
  34520. }
  34521. else
  34522. {
  34523. newW = imageW;
  34524. newH = roundToInt (imageW * imRatio);
  34525. }
  34526. imageX = (imageW - newW) / 2;
  34527. imageY = (imageH - newH) / 2;
  34528. imageW = newW;
  34529. imageH = newH;
  34530. }
  34531. else
  34532. {
  34533. imageX = 0;
  34534. imageY = 0;
  34535. }
  34536. }
  34537. if (! scaleImageToFit)
  34538. {
  34539. imageW = iw;
  34540. imageH = ih;
  34541. }
  34542. getLookAndFeel().drawImageButton (g, im, imageX, imageY, imageW, imageH,
  34543. isButtonDown ? downOverlay
  34544. : (isMouseOverButton ? overOverlay
  34545. : normalOverlay),
  34546. isButtonDown ? downOpacity
  34547. : (isMouseOverButton ? overOpacity
  34548. : normalOpacity),
  34549. *this);
  34550. }
  34551. }
  34552. bool ImageButton::hitTest (int x, int y)
  34553. {
  34554. if (alphaThreshold == 0)
  34555. return true;
  34556. Image* const im = getCurrentImage();
  34557. return im == 0
  34558. || (imageW > 0 && imageH > 0
  34559. && alphaThreshold < im->getPixelAt (((x - imageX) * im->getWidth()) / imageW,
  34560. ((y - imageY) * im->getHeight()) / imageH).getAlpha());
  34561. }
  34562. END_JUCE_NAMESPACE
  34563. /*** End of inlined file: juce_ImageButton.cpp ***/
  34564. /*** Start of inlined file: juce_ShapeButton.cpp ***/
  34565. BEGIN_JUCE_NAMESPACE
  34566. ShapeButton::ShapeButton (const String& text_,
  34567. const Colour& normalColour_,
  34568. const Colour& overColour_,
  34569. const Colour& downColour_)
  34570. : Button (text_),
  34571. normalColour (normalColour_),
  34572. overColour (overColour_),
  34573. downColour (downColour_),
  34574. maintainShapeProportions (false),
  34575. outlineWidth (0.0f)
  34576. {
  34577. }
  34578. ShapeButton::~ShapeButton()
  34579. {
  34580. }
  34581. void ShapeButton::setColours (const Colour& newNormalColour,
  34582. const Colour& newOverColour,
  34583. const Colour& newDownColour)
  34584. {
  34585. normalColour = newNormalColour;
  34586. overColour = newOverColour;
  34587. downColour = newDownColour;
  34588. }
  34589. void ShapeButton::setOutline (const Colour& newOutlineColour,
  34590. const float newOutlineWidth)
  34591. {
  34592. outlineColour = newOutlineColour;
  34593. outlineWidth = newOutlineWidth;
  34594. }
  34595. void ShapeButton::setShape (const Path& newShape,
  34596. const bool resizeNowToFitThisShape,
  34597. const bool maintainShapeProportions_,
  34598. const bool hasShadow)
  34599. {
  34600. shape = newShape;
  34601. maintainShapeProportions = maintainShapeProportions_;
  34602. shadow.setShadowProperties (3.0f, 0.5f, 0, 0);
  34603. setComponentEffect ((hasShadow) ? &shadow : 0);
  34604. if (resizeNowToFitThisShape)
  34605. {
  34606. Rectangle<float> bounds (shape.getBounds());
  34607. if (hasShadow)
  34608. bounds.expand (4.0f, 4.0f);
  34609. shape.applyTransform (AffineTransform::translation (-bounds.getX(), -bounds.getY()));
  34610. setSize (1 + (int) (bounds.getWidth() + outlineWidth),
  34611. 1 + (int) (bounds.getHeight() + outlineWidth));
  34612. }
  34613. }
  34614. void ShapeButton::paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  34615. {
  34616. if (! isEnabled())
  34617. {
  34618. isMouseOverButton = false;
  34619. isButtonDown = false;
  34620. }
  34621. g.setColour ((isButtonDown) ? downColour
  34622. : (isMouseOverButton) ? overColour
  34623. : normalColour);
  34624. int w = getWidth();
  34625. int h = getHeight();
  34626. if (getComponentEffect() != 0)
  34627. {
  34628. w -= 4;
  34629. h -= 4;
  34630. }
  34631. const float offset = (outlineWidth * 0.5f) + (isButtonDown ? 1.5f : 0.0f);
  34632. const AffineTransform trans (shape.getTransformToScaleToFit (offset, offset,
  34633. w - offset - outlineWidth,
  34634. h - offset - outlineWidth,
  34635. maintainShapeProportions));
  34636. g.fillPath (shape, trans);
  34637. if (outlineWidth > 0.0f)
  34638. {
  34639. g.setColour (outlineColour);
  34640. g.strokePath (shape, PathStrokeType (outlineWidth), trans);
  34641. }
  34642. }
  34643. END_JUCE_NAMESPACE
  34644. /*** End of inlined file: juce_ShapeButton.cpp ***/
  34645. /*** Start of inlined file: juce_TextButton.cpp ***/
  34646. BEGIN_JUCE_NAMESPACE
  34647. TextButton::TextButton (const String& name,
  34648. const String& toolTip)
  34649. : Button (name)
  34650. {
  34651. setTooltip (toolTip);
  34652. }
  34653. TextButton::~TextButton()
  34654. {
  34655. }
  34656. void TextButton::paintButton (Graphics& g,
  34657. bool isMouseOverButton,
  34658. bool isButtonDown)
  34659. {
  34660. getLookAndFeel().drawButtonBackground (g, *this,
  34661. findColour (getToggleState() ? buttonOnColourId
  34662. : buttonColourId),
  34663. isMouseOverButton,
  34664. isButtonDown);
  34665. getLookAndFeel().drawButtonText (g, *this,
  34666. isMouseOverButton,
  34667. isButtonDown);
  34668. }
  34669. void TextButton::colourChanged()
  34670. {
  34671. repaint();
  34672. }
  34673. const Font TextButton::getFont()
  34674. {
  34675. return Font (jmin (15.0f, getHeight() * 0.6f));
  34676. }
  34677. void TextButton::changeWidthToFitText (const int newHeight)
  34678. {
  34679. if (newHeight >= 0)
  34680. setSize (jmax (1, getWidth()), newHeight);
  34681. setSize (getFont().getStringWidth (getButtonText()) + getHeight(),
  34682. getHeight());
  34683. }
  34684. END_JUCE_NAMESPACE
  34685. /*** End of inlined file: juce_TextButton.cpp ***/
  34686. /*** Start of inlined file: juce_ToggleButton.cpp ***/
  34687. BEGIN_JUCE_NAMESPACE
  34688. ToggleButton::ToggleButton (const String& buttonText)
  34689. : Button (buttonText)
  34690. {
  34691. setClickingTogglesState (true);
  34692. }
  34693. ToggleButton::~ToggleButton()
  34694. {
  34695. }
  34696. void ToggleButton::paintButton (Graphics& g,
  34697. bool isMouseOverButton,
  34698. bool isButtonDown)
  34699. {
  34700. getLookAndFeel().drawToggleButton (g, *this,
  34701. isMouseOverButton,
  34702. isButtonDown);
  34703. }
  34704. void ToggleButton::changeWidthToFitText()
  34705. {
  34706. getLookAndFeel().changeToggleButtonWidthToFitText (*this);
  34707. }
  34708. void ToggleButton::colourChanged()
  34709. {
  34710. repaint();
  34711. }
  34712. END_JUCE_NAMESPACE
  34713. /*** End of inlined file: juce_ToggleButton.cpp ***/
  34714. /*** Start of inlined file: juce_ToolbarButton.cpp ***/
  34715. BEGIN_JUCE_NAMESPACE
  34716. ToolbarButton::ToolbarButton (const int itemId_,
  34717. const String& buttonText,
  34718. Drawable* const normalImage_,
  34719. Drawable* const toggledOnImage_)
  34720. : ToolbarItemComponent (itemId_, buttonText, true),
  34721. normalImage (normalImage_),
  34722. toggledOnImage (toggledOnImage_)
  34723. {
  34724. }
  34725. ToolbarButton::~ToolbarButton()
  34726. {
  34727. }
  34728. bool ToolbarButton::getToolbarItemSizes (int toolbarDepth,
  34729. bool /*isToolbarVertical*/,
  34730. int& preferredSize,
  34731. int& minSize, int& maxSize)
  34732. {
  34733. preferredSize = minSize = maxSize = toolbarDepth;
  34734. return true;
  34735. }
  34736. void ToolbarButton::paintButtonArea (Graphics& g,
  34737. int width, int height,
  34738. bool /*isMouseOver*/,
  34739. bool /*isMouseDown*/)
  34740. {
  34741. Drawable* d = normalImage;
  34742. if (getToggleState() && toggledOnImage != 0)
  34743. d = toggledOnImage;
  34744. if (! isEnabled())
  34745. {
  34746. Image im (Image::ARGB, width, height, true);
  34747. Graphics g2 (im);
  34748. d->drawWithin (g2, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  34749. im.desaturate();
  34750. g.drawImageAt (&im, 0, 0);
  34751. }
  34752. else
  34753. {
  34754. d->drawWithin (g, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  34755. }
  34756. }
  34757. void ToolbarButton::contentAreaChanged (const Rectangle<int>&)
  34758. {
  34759. }
  34760. END_JUCE_NAMESPACE
  34761. /*** End of inlined file: juce_ToolbarButton.cpp ***/
  34762. /*** Start of inlined file: juce_CodeDocument.cpp ***/
  34763. BEGIN_JUCE_NAMESPACE
  34764. class CodeDocumentLine
  34765. {
  34766. public:
  34767. CodeDocumentLine (const tchar* const line_,
  34768. const int lineLength_,
  34769. const int numNewLineChars,
  34770. const int lineStartInFile_)
  34771. : line (line_, lineLength_),
  34772. lineStartInFile (lineStartInFile_),
  34773. lineLength (lineLength_),
  34774. lineLengthWithoutNewLines (lineLength_ - numNewLineChars)
  34775. {
  34776. }
  34777. ~CodeDocumentLine()
  34778. {
  34779. }
  34780. static void createLines (Array <CodeDocumentLine*>& newLines, const String& text)
  34781. {
  34782. const tchar* const t = (const tchar*) text;
  34783. int pos = 0;
  34784. while (t [pos] != 0)
  34785. {
  34786. const int startOfLine = pos;
  34787. int numNewLineChars = 0;
  34788. while (t[pos] != 0)
  34789. {
  34790. if (t[pos] == '\r')
  34791. {
  34792. ++numNewLineChars;
  34793. ++pos;
  34794. if (t[pos] == '\n')
  34795. {
  34796. ++numNewLineChars;
  34797. ++pos;
  34798. }
  34799. break;
  34800. }
  34801. if (t[pos] == '\n')
  34802. {
  34803. ++numNewLineChars;
  34804. ++pos;
  34805. break;
  34806. }
  34807. ++pos;
  34808. }
  34809. newLines.add (new CodeDocumentLine (t + startOfLine, pos - startOfLine,
  34810. numNewLineChars, startOfLine));
  34811. }
  34812. jassert (pos == text.length());
  34813. }
  34814. bool endsWithLineBreak() const throw()
  34815. {
  34816. return lineLengthWithoutNewLines != lineLength;
  34817. }
  34818. void updateLength() throw()
  34819. {
  34820. lineLengthWithoutNewLines = lineLength = line.length();
  34821. while (lineLengthWithoutNewLines > 0
  34822. && (line [lineLengthWithoutNewLines - 1] == '\n'
  34823. || line [lineLengthWithoutNewLines - 1] == '\r'))
  34824. {
  34825. --lineLengthWithoutNewLines;
  34826. }
  34827. }
  34828. String line;
  34829. int lineStartInFile, lineLength, lineLengthWithoutNewLines;
  34830. };
  34831. CodeDocument::Iterator::Iterator (CodeDocument* const document_)
  34832. : document (document_),
  34833. currentLine (document_->lines[0]),
  34834. line (0),
  34835. position (0)
  34836. {
  34837. }
  34838. CodeDocument::Iterator::Iterator (const CodeDocument::Iterator& other)
  34839. : document (other.document),
  34840. currentLine (other.currentLine),
  34841. line (other.line),
  34842. position (other.position)
  34843. {
  34844. }
  34845. CodeDocument::Iterator& CodeDocument::Iterator::operator= (const CodeDocument::Iterator& other) throw()
  34846. {
  34847. document = other.document;
  34848. currentLine = other.currentLine;
  34849. line = other.line;
  34850. position = other.position;
  34851. return *this;
  34852. }
  34853. CodeDocument::Iterator::~Iterator() throw()
  34854. {
  34855. }
  34856. juce_wchar CodeDocument::Iterator::nextChar()
  34857. {
  34858. if (currentLine == 0)
  34859. return 0;
  34860. jassert (currentLine == document->lines.getUnchecked (line));
  34861. const juce_wchar result = currentLine->line [position - currentLine->lineStartInFile];
  34862. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  34863. {
  34864. ++line;
  34865. currentLine = document->lines [line];
  34866. }
  34867. return result;
  34868. }
  34869. void CodeDocument::Iterator::skip()
  34870. {
  34871. if (currentLine != 0)
  34872. {
  34873. jassert (currentLine == document->lines.getUnchecked (line));
  34874. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  34875. {
  34876. ++line;
  34877. currentLine = document->lines [line];
  34878. }
  34879. }
  34880. }
  34881. void CodeDocument::Iterator::skipToEndOfLine()
  34882. {
  34883. if (currentLine != 0)
  34884. {
  34885. jassert (currentLine == document->lines.getUnchecked (line));
  34886. ++line;
  34887. currentLine = document->lines [line];
  34888. if (currentLine != 0)
  34889. position = currentLine->lineStartInFile;
  34890. else
  34891. position = document->getNumCharacters();
  34892. }
  34893. }
  34894. juce_wchar CodeDocument::Iterator::peekNextChar() const
  34895. {
  34896. if (currentLine == 0)
  34897. return 0;
  34898. jassert (currentLine == document->lines.getUnchecked (line));
  34899. return const_cast <const String&> (currentLine->line) [position - currentLine->lineStartInFile];
  34900. }
  34901. void CodeDocument::Iterator::skipWhitespace()
  34902. {
  34903. while (CharacterFunctions::isWhitespace (peekNextChar()))
  34904. skip();
  34905. }
  34906. bool CodeDocument::Iterator::isEOF() const throw()
  34907. {
  34908. return currentLine == 0;
  34909. }
  34910. CodeDocument::Position::Position() throw()
  34911. : owner (0), characterPos (0), line (0),
  34912. indexInLine (0), positionMaintained (false)
  34913. {
  34914. }
  34915. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  34916. const int line_, const int indexInLine_) throw()
  34917. : owner (const_cast <CodeDocument*> (ownerDocument)),
  34918. characterPos (0), line (line_),
  34919. indexInLine (indexInLine_), positionMaintained (false)
  34920. {
  34921. setLineAndIndex (line_, indexInLine_);
  34922. }
  34923. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  34924. const int characterPos_) throw()
  34925. : owner (const_cast <CodeDocument*> (ownerDocument)),
  34926. positionMaintained (false)
  34927. {
  34928. setPosition (characterPos_);
  34929. }
  34930. CodeDocument::Position::Position (const Position& other) throw()
  34931. : owner (other.owner), characterPos (other.characterPos), line (other.line),
  34932. indexInLine (other.indexInLine), positionMaintained (false)
  34933. {
  34934. jassert (*this == other);
  34935. }
  34936. CodeDocument::Position::~Position() throw()
  34937. {
  34938. setPositionMaintained (false);
  34939. }
  34940. CodeDocument::Position& CodeDocument::Position::operator= (const Position& other) throw()
  34941. {
  34942. if (this != &other)
  34943. {
  34944. const bool wasPositionMaintained = positionMaintained;
  34945. if (owner != other.owner)
  34946. setPositionMaintained (false);
  34947. owner = other.owner;
  34948. line = other.line;
  34949. indexInLine = other.indexInLine;
  34950. characterPos = other.characterPos;
  34951. setPositionMaintained (wasPositionMaintained);
  34952. jassert (*this == other);
  34953. }
  34954. return *this;
  34955. }
  34956. bool CodeDocument::Position::operator== (const Position& other) const throw()
  34957. {
  34958. jassert ((characterPos == other.characterPos)
  34959. == (line == other.line && indexInLine == other.indexInLine));
  34960. return characterPos == other.characterPos
  34961. && line == other.line
  34962. && indexInLine == other.indexInLine
  34963. && owner == other.owner;
  34964. }
  34965. bool CodeDocument::Position::operator!= (const Position& other) const throw()
  34966. {
  34967. return ! operator== (other);
  34968. }
  34969. void CodeDocument::Position::setLineAndIndex (const int newLine, const int newIndexInLine) throw()
  34970. {
  34971. jassert (owner != 0);
  34972. if (owner->lines.size() == 0)
  34973. {
  34974. line = 0;
  34975. indexInLine = 0;
  34976. characterPos = 0;
  34977. }
  34978. else
  34979. {
  34980. if (newLine >= owner->lines.size())
  34981. {
  34982. line = owner->lines.size() - 1;
  34983. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  34984. jassert (l != 0);
  34985. indexInLine = l->lineLengthWithoutNewLines;
  34986. characterPos = l->lineStartInFile + indexInLine;
  34987. }
  34988. else
  34989. {
  34990. line = jmax (0, newLine);
  34991. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  34992. jassert (l != 0);
  34993. if (l->lineLengthWithoutNewLines > 0)
  34994. indexInLine = jlimit (0, l->lineLengthWithoutNewLines, newIndexInLine);
  34995. else
  34996. indexInLine = 0;
  34997. characterPos = l->lineStartInFile + indexInLine;
  34998. }
  34999. }
  35000. }
  35001. void CodeDocument::Position::setPosition (const int newPosition) throw()
  35002. {
  35003. jassert (owner != 0);
  35004. line = 0;
  35005. indexInLine = 0;
  35006. characterPos = 0;
  35007. if (newPosition > 0)
  35008. {
  35009. int lineStart = 0;
  35010. int lineEnd = owner->lines.size();
  35011. for (;;)
  35012. {
  35013. if (lineEnd - lineStart < 4)
  35014. {
  35015. for (int i = lineStart; i < lineEnd; ++i)
  35016. {
  35017. CodeDocumentLine* const l = owner->lines.getUnchecked (i);
  35018. int index = newPosition - l->lineStartInFile;
  35019. if (index >= 0 && (index < l->lineLength || i == lineEnd - 1))
  35020. {
  35021. line = i;
  35022. indexInLine = jmin (l->lineLengthWithoutNewLines, index);
  35023. characterPos = l->lineStartInFile + indexInLine;
  35024. }
  35025. }
  35026. break;
  35027. }
  35028. else
  35029. {
  35030. const int midIndex = (lineStart + lineEnd + 1) / 2;
  35031. CodeDocumentLine* const mid = owner->lines.getUnchecked (midIndex);
  35032. if (newPosition >= mid->lineStartInFile)
  35033. lineStart = midIndex;
  35034. else
  35035. lineEnd = midIndex;
  35036. }
  35037. }
  35038. }
  35039. }
  35040. void CodeDocument::Position::moveBy (int characterDelta) throw()
  35041. {
  35042. jassert (owner != 0);
  35043. if (characterDelta == 1)
  35044. {
  35045. setPosition (getPosition());
  35046. // If moving right, make sure we don't get stuck between the \r and \n characters..
  35047. if (line < owner->lines.size())
  35048. {
  35049. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35050. if (indexInLine + characterDelta < l->lineLength
  35051. && indexInLine + characterDelta >= l->lineLengthWithoutNewLines + 1)
  35052. ++characterDelta;
  35053. }
  35054. }
  35055. setPosition (characterPos + characterDelta);
  35056. }
  35057. const CodeDocument::Position CodeDocument::Position::movedBy (const int characterDelta) const throw()
  35058. {
  35059. CodeDocument::Position p (*this);
  35060. p.moveBy (characterDelta);
  35061. return p;
  35062. }
  35063. const CodeDocument::Position CodeDocument::Position::movedByLines (const int deltaLines) const throw()
  35064. {
  35065. CodeDocument::Position p (*this);
  35066. p.setLineAndIndex (getLineNumber() + deltaLines, getIndexInLine());
  35067. return p;
  35068. }
  35069. const tchar CodeDocument::Position::getCharacter() const throw()
  35070. {
  35071. const CodeDocumentLine* const l = owner->lines [line];
  35072. return l == 0 ? 0 : l->line [getIndexInLine()];
  35073. }
  35074. const String CodeDocument::Position::getLineText() const throw()
  35075. {
  35076. const CodeDocumentLine* const l = owner->lines [line];
  35077. return l == 0 ? String::empty : l->line;
  35078. }
  35079. void CodeDocument::Position::setPositionMaintained (const bool isMaintained) throw()
  35080. {
  35081. if (isMaintained != positionMaintained)
  35082. {
  35083. positionMaintained = isMaintained;
  35084. if (owner != 0)
  35085. {
  35086. if (isMaintained)
  35087. {
  35088. jassert (! owner->positionsToMaintain.contains (this));
  35089. owner->positionsToMaintain.add (this);
  35090. }
  35091. else
  35092. {
  35093. jassert (owner->positionsToMaintain.contains (this));
  35094. owner->positionsToMaintain.removeValue (this);
  35095. }
  35096. }
  35097. }
  35098. }
  35099. CodeDocument::CodeDocument()
  35100. : undoManager (std::numeric_limits<int>::max(), 10000),
  35101. currentActionIndex (0),
  35102. indexOfSavedState (-1),
  35103. maximumLineLength (-1),
  35104. newLineChars ("\r\n")
  35105. {
  35106. }
  35107. CodeDocument::~CodeDocument()
  35108. {
  35109. }
  35110. const String CodeDocument::getAllContent() const throw()
  35111. {
  35112. return getTextBetween (Position (this, 0),
  35113. Position (this, lines.size(), 0));
  35114. }
  35115. const String CodeDocument::getTextBetween (const Position& start, const Position& end) const throw()
  35116. {
  35117. if (end.getPosition() <= start.getPosition())
  35118. return String::empty;
  35119. const int startLine = start.getLineNumber();
  35120. const int endLine = end.getLineNumber();
  35121. if (startLine == endLine)
  35122. {
  35123. CodeDocumentLine* const line = lines [startLine];
  35124. return (line == 0) ? String::empty : line->line.substring (start.getIndexInLine(), end.getIndexInLine());
  35125. }
  35126. String result;
  35127. result.preallocateStorage (end.getPosition() - start.getPosition() + 4);
  35128. String::Concatenator concatenator (result);
  35129. const int maxLine = jmin (lines.size() - 1, endLine);
  35130. for (int i = jmax (0, startLine); i <= maxLine; ++i)
  35131. {
  35132. const CodeDocumentLine* line = lines.getUnchecked(i);
  35133. int len = line->lineLength;
  35134. if (i == startLine)
  35135. {
  35136. const int index = start.getIndexInLine();
  35137. concatenator.append (line->line.substring (index, len));
  35138. }
  35139. else if (i == endLine)
  35140. {
  35141. len = end.getIndexInLine();
  35142. concatenator.append (line->line.substring (0, len));
  35143. }
  35144. else
  35145. {
  35146. concatenator.append (line->line);
  35147. }
  35148. }
  35149. return result;
  35150. }
  35151. int CodeDocument::getNumCharacters() const throw()
  35152. {
  35153. const CodeDocumentLine* const lastLine = lines.getLast();
  35154. return (lastLine == 0) ? 0 : lastLine->lineStartInFile + lastLine->lineLength;
  35155. }
  35156. const String CodeDocument::getLine (const int lineIndex) const throw()
  35157. {
  35158. const CodeDocumentLine* const line = lines [lineIndex];
  35159. return (line == 0) ? String::empty : line->line;
  35160. }
  35161. int CodeDocument::getMaximumLineLength() throw()
  35162. {
  35163. if (maximumLineLength < 0)
  35164. {
  35165. maximumLineLength = 0;
  35166. for (int i = lines.size(); --i >= 0;)
  35167. maximumLineLength = jmax (maximumLineLength, lines.getUnchecked(i)->lineLength);
  35168. }
  35169. return maximumLineLength;
  35170. }
  35171. void CodeDocument::deleteSection (const Position& startPosition, const Position& endPosition)
  35172. {
  35173. remove (startPosition.getPosition(), endPosition.getPosition(), true);
  35174. }
  35175. void CodeDocument::insertText (const Position& position, const String& text)
  35176. {
  35177. insert (text, position.getPosition(), true);
  35178. }
  35179. void CodeDocument::replaceAllContent (const String& newContent)
  35180. {
  35181. remove (0, getNumCharacters(), true);
  35182. insert (newContent, 0, true);
  35183. }
  35184. bool CodeDocument::loadFromStream (InputStream& stream)
  35185. {
  35186. replaceAllContent (stream.readEntireStreamAsString());
  35187. setSavePoint();
  35188. clearUndoHistory();
  35189. return true;
  35190. }
  35191. bool CodeDocument::writeToStream (OutputStream& stream)
  35192. {
  35193. for (int i = 0; i < lines.size(); ++i)
  35194. {
  35195. String temp (lines.getUnchecked(i)->line); // use a copy to avoid bloating the memory footprint of the stored string.
  35196. const char* utf8 = temp.toUTF8();
  35197. if (! stream.write (utf8, (int) strlen (utf8)))
  35198. return false;
  35199. }
  35200. return true;
  35201. }
  35202. void CodeDocument::setNewLineCharacters (const String& newLine) throw()
  35203. {
  35204. jassert (newLine == "\r\n" || newLine == "\n" || newLine == "\r");
  35205. newLineChars = newLine;
  35206. }
  35207. void CodeDocument::newTransaction()
  35208. {
  35209. undoManager.beginNewTransaction (String::empty);
  35210. }
  35211. void CodeDocument::undo()
  35212. {
  35213. newTransaction();
  35214. undoManager.undo();
  35215. }
  35216. void CodeDocument::redo()
  35217. {
  35218. undoManager.redo();
  35219. }
  35220. void CodeDocument::clearUndoHistory()
  35221. {
  35222. undoManager.clearUndoHistory();
  35223. }
  35224. void CodeDocument::setSavePoint() throw()
  35225. {
  35226. indexOfSavedState = currentActionIndex;
  35227. }
  35228. bool CodeDocument::hasChangedSinceSavePoint() const throw()
  35229. {
  35230. return currentActionIndex != indexOfSavedState;
  35231. }
  35232. static int getCodeCharacterCategory (const tchar character) throw()
  35233. {
  35234. return (CharacterFunctions::isLetterOrDigit (character) || character == '_')
  35235. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  35236. }
  35237. const CodeDocument::Position CodeDocument::findWordBreakAfter (const Position& position) const throw()
  35238. {
  35239. Position p (position);
  35240. const int maxDistance = 256;
  35241. int i = 0;
  35242. while (i < maxDistance
  35243. && CharacterFunctions::isWhitespace (p.getCharacter())
  35244. && (i == 0 || (p.getCharacter() != '\n'
  35245. && p.getCharacter() != '\r')))
  35246. {
  35247. ++i;
  35248. p.moveBy (1);
  35249. }
  35250. if (i == 0)
  35251. {
  35252. const int type = getCodeCharacterCategory (p.getCharacter());
  35253. while (i < maxDistance && type == getCodeCharacterCategory (p.getCharacter()))
  35254. {
  35255. ++i;
  35256. p.moveBy (1);
  35257. }
  35258. while (i < maxDistance
  35259. && CharacterFunctions::isWhitespace (p.getCharacter())
  35260. && (i == 0 || (p.getCharacter() != '\n'
  35261. && p.getCharacter() != '\r')))
  35262. {
  35263. ++i;
  35264. p.moveBy (1);
  35265. }
  35266. }
  35267. return p;
  35268. }
  35269. const CodeDocument::Position CodeDocument::findWordBreakBefore (const Position& position) const throw()
  35270. {
  35271. Position p (position);
  35272. const int maxDistance = 256;
  35273. int i = 0;
  35274. bool stoppedAtLineStart = false;
  35275. while (i < maxDistance)
  35276. {
  35277. const tchar c = p.movedBy (-1).getCharacter();
  35278. if (c == '\r' || c == '\n')
  35279. {
  35280. stoppedAtLineStart = true;
  35281. if (i > 0)
  35282. break;
  35283. }
  35284. if (! CharacterFunctions::isWhitespace (c))
  35285. break;
  35286. p.moveBy (-1);
  35287. ++i;
  35288. }
  35289. if (i < maxDistance && ! stoppedAtLineStart)
  35290. {
  35291. const int type = getCodeCharacterCategory (p.movedBy (-1).getCharacter());
  35292. while (i < maxDistance && type == getCodeCharacterCategory (p.movedBy (-1).getCharacter()))
  35293. {
  35294. p.moveBy (-1);
  35295. ++i;
  35296. }
  35297. }
  35298. return p;
  35299. }
  35300. void CodeDocument::checkLastLineStatus()
  35301. {
  35302. while (lines.size() > 0
  35303. && lines.getLast()->lineLength == 0
  35304. && (lines.size() == 1 || ! lines.getUnchecked (lines.size() - 2)->endsWithLineBreak()))
  35305. {
  35306. // remove any empty lines at the end if the preceding line doesn't end in a newline.
  35307. lines.removeLast();
  35308. }
  35309. const CodeDocumentLine* const lastLine = lines.getLast();
  35310. if (lastLine != 0 && lastLine->endsWithLineBreak())
  35311. {
  35312. // check that there's an empty line at the end if the preceding one ends in a newline..
  35313. lines.add (new CodeDocumentLine (String::empty, 0, 0, lastLine->lineStartInFile + lastLine->lineLength));
  35314. }
  35315. }
  35316. void CodeDocument::addListener (CodeDocument::Listener* const listener) throw()
  35317. {
  35318. listeners.addIfNotAlreadyThere (listener);
  35319. }
  35320. void CodeDocument::removeListener (CodeDocument::Listener* const listener) throw()
  35321. {
  35322. listeners.removeValue (listener);
  35323. }
  35324. void CodeDocument::sendListenerChangeMessage (const int startLine, const int endLine)
  35325. {
  35326. const Position startPos (this, startLine, 0);
  35327. const Position endPos (this, endLine, 0);
  35328. for (int i = listeners.size(); --i >= 0;)
  35329. {
  35330. Listener* const l = (Listener*) listeners[i];
  35331. if (l != 0)
  35332. l->codeDocumentChanged (startPos, endPos);
  35333. }
  35334. }
  35335. class CodeDocumentInsertAction : public UndoableAction
  35336. {
  35337. CodeDocument& owner;
  35338. const String text;
  35339. int insertPos;
  35340. CodeDocumentInsertAction (const CodeDocumentInsertAction&);
  35341. CodeDocumentInsertAction& operator= (const CodeDocumentInsertAction&);
  35342. public:
  35343. CodeDocumentInsertAction (CodeDocument& owner_, const String& text_, const int insertPos_) throw()
  35344. : owner (owner_),
  35345. text (text_),
  35346. insertPos (insertPos_)
  35347. {
  35348. }
  35349. ~CodeDocumentInsertAction() {}
  35350. bool perform()
  35351. {
  35352. owner.currentActionIndex++;
  35353. owner.insert (text, insertPos, false);
  35354. return true;
  35355. }
  35356. bool undo()
  35357. {
  35358. owner.currentActionIndex--;
  35359. owner.remove (insertPos, insertPos + text.length(), false);
  35360. return true;
  35361. }
  35362. int getSizeInUnits() { return text.length() + 32; }
  35363. };
  35364. void CodeDocument::insert (const String& text, const int insertPos, const bool undoable)
  35365. {
  35366. if (text.isEmpty())
  35367. return;
  35368. if (undoable)
  35369. {
  35370. undoManager.perform (new CodeDocumentInsertAction (*this, text, insertPos));
  35371. }
  35372. else
  35373. {
  35374. Position pos (this, insertPos);
  35375. const int firstAffectedLine = pos.getLineNumber();
  35376. int lastAffectedLine = firstAffectedLine + 1;
  35377. CodeDocumentLine* const firstLine = lines [firstAffectedLine];
  35378. String textInsideOriginalLine (text);
  35379. if (firstLine != 0)
  35380. {
  35381. const int index = pos.getIndexInLine();
  35382. textInsideOriginalLine = firstLine->line.substring (0, index)
  35383. + textInsideOriginalLine
  35384. + firstLine->line.substring (index);
  35385. }
  35386. maximumLineLength = -1;
  35387. Array <CodeDocumentLine*> newLines;
  35388. CodeDocumentLine::createLines (newLines, textInsideOriginalLine);
  35389. jassert (newLines.size() > 0);
  35390. CodeDocumentLine* const newFirstLine = newLines.getUnchecked (0);
  35391. newFirstLine->lineStartInFile = firstLine != 0 ? firstLine->lineStartInFile : 0;
  35392. lines.set (firstAffectedLine, newFirstLine);
  35393. if (newLines.size() > 1)
  35394. {
  35395. for (int i = 1; i < newLines.size(); ++i)
  35396. {
  35397. CodeDocumentLine* const l = newLines.getUnchecked (i);
  35398. lines.insert (firstAffectedLine + i, l);
  35399. }
  35400. lastAffectedLine = lines.size();
  35401. }
  35402. int i, lineStart = newFirstLine->lineStartInFile;
  35403. for (i = firstAffectedLine; i < lines.size(); ++i)
  35404. {
  35405. CodeDocumentLine* const l = lines.getUnchecked (i);
  35406. l->lineStartInFile = lineStart;
  35407. lineStart += l->lineLength;
  35408. }
  35409. checkLastLineStatus();
  35410. const int newTextLength = text.length();
  35411. for (i = 0; i < positionsToMaintain.size(); ++i)
  35412. {
  35413. CodeDocument::Position* const p = positionsToMaintain.getUnchecked(i);
  35414. if (p->getPosition() >= insertPos)
  35415. p->setPosition (p->getPosition() + newTextLength);
  35416. }
  35417. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35418. }
  35419. }
  35420. class CodeDocumentDeleteAction : public UndoableAction
  35421. {
  35422. CodeDocument& owner;
  35423. int startPos, endPos;
  35424. String removedText;
  35425. CodeDocumentDeleteAction (const CodeDocumentDeleteAction&);
  35426. CodeDocumentDeleteAction& operator= (const CodeDocumentDeleteAction&);
  35427. public:
  35428. CodeDocumentDeleteAction (CodeDocument& owner_, const int startPos_, const int endPos_) throw()
  35429. : owner (owner_),
  35430. startPos (startPos_),
  35431. endPos (endPos_)
  35432. {
  35433. removedText = owner.getTextBetween (CodeDocument::Position (&owner, startPos),
  35434. CodeDocument::Position (&owner, endPos));
  35435. }
  35436. ~CodeDocumentDeleteAction() {}
  35437. bool perform()
  35438. {
  35439. owner.currentActionIndex++;
  35440. owner.remove (startPos, endPos, false);
  35441. return true;
  35442. }
  35443. bool undo()
  35444. {
  35445. owner.currentActionIndex--;
  35446. owner.insert (removedText, startPos, false);
  35447. return true;
  35448. }
  35449. int getSizeInUnits() { return removedText.length() + 32; }
  35450. };
  35451. void CodeDocument::remove (const int startPos, const int endPos, const bool undoable)
  35452. {
  35453. if (endPos <= startPos)
  35454. return;
  35455. if (undoable)
  35456. {
  35457. undoManager.perform (new CodeDocumentDeleteAction (*this, startPos, endPos));
  35458. }
  35459. else
  35460. {
  35461. Position startPosition (this, startPos);
  35462. Position endPosition (this, endPos);
  35463. maximumLineLength = -1;
  35464. const int firstAffectedLine = startPosition.getLineNumber();
  35465. const int endLine = endPosition.getLineNumber();
  35466. int lastAffectedLine = firstAffectedLine + 1;
  35467. CodeDocumentLine* const firstLine = lines.getUnchecked (firstAffectedLine);
  35468. if (firstAffectedLine == endLine)
  35469. {
  35470. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35471. + firstLine->line.substring (endPosition.getIndexInLine());
  35472. firstLine->updateLength();
  35473. }
  35474. else
  35475. {
  35476. lastAffectedLine = lines.size();
  35477. CodeDocumentLine* const lastLine = lines.getUnchecked (endLine);
  35478. jassert (lastLine != 0);
  35479. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35480. + lastLine->line.substring (endPosition.getIndexInLine());
  35481. firstLine->updateLength();
  35482. int numLinesToRemove = endLine - firstAffectedLine;
  35483. lines.removeRange (firstAffectedLine + 1, numLinesToRemove);
  35484. }
  35485. int i;
  35486. for (i = firstAffectedLine + 1; i < lines.size(); ++i)
  35487. {
  35488. CodeDocumentLine* const l = lines.getUnchecked (i);
  35489. const CodeDocumentLine* const previousLine = lines.getUnchecked (i - 1);
  35490. l->lineStartInFile = previousLine->lineStartInFile + previousLine->lineLength;
  35491. }
  35492. checkLastLineStatus();
  35493. const int totalChars = getNumCharacters();
  35494. for (i = 0; i < positionsToMaintain.size(); ++i)
  35495. {
  35496. CodeDocument::Position* p = positionsToMaintain.getUnchecked(i);
  35497. if (p->getPosition() > startPosition.getPosition())
  35498. p->setPosition (jmax (startPos, p->getPosition() + startPos - endPos));
  35499. if (p->getPosition() > totalChars)
  35500. p->setPosition (totalChars);
  35501. }
  35502. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35503. }
  35504. }
  35505. END_JUCE_NAMESPACE
  35506. /*** End of inlined file: juce_CodeDocument.cpp ***/
  35507. /*** Start of inlined file: juce_CodeEditorComponent.cpp ***/
  35508. BEGIN_JUCE_NAMESPACE
  35509. class CaretComponent : public Component,
  35510. public Timer
  35511. {
  35512. public:
  35513. CaretComponent()
  35514. {
  35515. setAlwaysOnTop (true);
  35516. setInterceptsMouseClicks (false, false);
  35517. }
  35518. ~CaretComponent()
  35519. {
  35520. }
  35521. void paint (Graphics& g)
  35522. {
  35523. if (getParentComponent()->hasKeyboardFocus (true))
  35524. g.fillAll (findColour (CodeEditorComponent::caretColourId));
  35525. }
  35526. void timerCallback()
  35527. {
  35528. setVisible (! isVisible());
  35529. }
  35530. void updatePosition (CodeEditorComponent& owner)
  35531. {
  35532. startTimer (400);
  35533. setVisible (true);
  35534. const Rectangle<int> pos (owner.getCharacterBounds (owner.getCaretPos()));
  35535. setBounds (pos.getX(), pos.getY(), 2, pos.getHeight());
  35536. }
  35537. };
  35538. class CodeEditorComponent::CodeEditorLine
  35539. {
  35540. public:
  35541. CodeEditorLine() throw()
  35542. {
  35543. }
  35544. ~CodeEditorLine() throw()
  35545. {
  35546. }
  35547. bool update (CodeDocument& document, int lineNum,
  35548. CodeDocument::Iterator& source,
  35549. CodeTokeniser* analyser, const int spacesPerTab,
  35550. const CodeDocument::Position& selectionStart,
  35551. const CodeDocument::Position& selectionEnd)
  35552. {
  35553. Array <SyntaxToken> newTokens;
  35554. newTokens.ensureStorageAllocated (8);
  35555. if (analyser == 0)
  35556. {
  35557. newTokens.add (SyntaxToken (document.getLine (lineNum), -1));
  35558. }
  35559. else if (lineNum < document.getNumLines())
  35560. {
  35561. const CodeDocument::Position pos (&document, lineNum, 0);
  35562. createTokens (pos.getPosition(), pos.getLineText(),
  35563. source, analyser, newTokens);
  35564. }
  35565. replaceTabsWithSpaces (newTokens, spacesPerTab);
  35566. int newHighlightStart = 0;
  35567. int newHighlightEnd = 0;
  35568. if (selectionStart.getLineNumber() <= lineNum && selectionEnd.getLineNumber() >= lineNum)
  35569. {
  35570. const String line (document.getLine (lineNum));
  35571. CodeDocument::Position lineStart (&document, lineNum, 0), lineEnd (&document, lineNum + 1, 0);
  35572. newHighlightStart = indexToColumn (jmax (0, selectionStart.getPosition() - lineStart.getPosition()),
  35573. line, spacesPerTab);
  35574. newHighlightEnd = indexToColumn (jmin (lineEnd.getPosition() - lineStart.getPosition(), selectionEnd.getPosition() - lineStart.getPosition()),
  35575. line, spacesPerTab);
  35576. }
  35577. if (newHighlightStart != highlightColumnStart || newHighlightEnd != highlightColumnEnd)
  35578. {
  35579. highlightColumnStart = newHighlightStart;
  35580. highlightColumnEnd = newHighlightEnd;
  35581. }
  35582. else
  35583. {
  35584. if (tokens.size() == newTokens.size())
  35585. {
  35586. bool allTheSame = true;
  35587. for (int i = newTokens.size(); --i >= 0;)
  35588. {
  35589. if (tokens.getReference(i) != newTokens.getReference(i))
  35590. {
  35591. allTheSame = false;
  35592. break;
  35593. }
  35594. }
  35595. if (allTheSame)
  35596. return false;
  35597. }
  35598. }
  35599. tokens.swapWithArray (newTokens);
  35600. return true;
  35601. }
  35602. void draw (CodeEditorComponent& owner, Graphics& g, const Font& font,
  35603. float x, const int y, const int baselineOffset, const int lineHeight,
  35604. const Colour& highlightColour) const throw()
  35605. {
  35606. if (highlightColumnStart < highlightColumnEnd)
  35607. {
  35608. g.setColour (highlightColour);
  35609. g.fillRect (roundToInt (x + highlightColumnStart * owner.getCharWidth()), y,
  35610. roundToInt ((highlightColumnEnd - highlightColumnStart) * owner.getCharWidth()), lineHeight);
  35611. }
  35612. int lastType = std::numeric_limits<int>::min();
  35613. for (int i = 0; i < tokens.size(); ++i)
  35614. {
  35615. SyntaxToken& token = tokens.getReference(i);
  35616. if (lastType != token.tokenType)
  35617. {
  35618. lastType = token.tokenType;
  35619. g.setColour (owner.getColourForTokenType (lastType));
  35620. }
  35621. g.drawSingleLineText (token.text, roundToInt (x), y + baselineOffset);
  35622. if (i < tokens.size() - 1)
  35623. {
  35624. if (token.width < 0)
  35625. token.width = font.getStringWidthFloat (token.text);
  35626. x += token.width;
  35627. }
  35628. }
  35629. }
  35630. private:
  35631. struct SyntaxToken
  35632. {
  35633. String text;
  35634. int tokenType;
  35635. float width;
  35636. SyntaxToken (const String& text_, const int type) throw()
  35637. : text (text_), tokenType (type), width (-1.0f)
  35638. {
  35639. }
  35640. bool operator!= (const SyntaxToken& other) const throw()
  35641. {
  35642. return text != other.text || tokenType != other.tokenType;
  35643. }
  35644. };
  35645. Array <SyntaxToken> tokens;
  35646. int highlightColumnStart, highlightColumnEnd;
  35647. static void createTokens (int startPosition, const String& lineText,
  35648. CodeDocument::Iterator& source,
  35649. CodeTokeniser* analyser,
  35650. Array <SyntaxToken>& newTokens)
  35651. {
  35652. CodeDocument::Iterator lastIterator (source);
  35653. const int lineLength = lineText.length();
  35654. for (;;)
  35655. {
  35656. int tokenType = analyser->readNextToken (source);
  35657. int tokenStart = lastIterator.getPosition();
  35658. int tokenEnd = source.getPosition();
  35659. if (tokenEnd <= tokenStart)
  35660. break;
  35661. tokenEnd -= startPosition;
  35662. if (tokenEnd > 0)
  35663. {
  35664. tokenStart -= startPosition;
  35665. newTokens.add (SyntaxToken (lineText.substring (jmax (0, tokenStart), tokenEnd),
  35666. tokenType));
  35667. if (tokenEnd >= lineLength)
  35668. break;
  35669. }
  35670. lastIterator = source;
  35671. }
  35672. source = lastIterator;
  35673. }
  35674. static void replaceTabsWithSpaces (Array <SyntaxToken>& tokens, const int spacesPerTab) throw()
  35675. {
  35676. int x = 0;
  35677. for (int i = 0; i < tokens.size(); ++i)
  35678. {
  35679. SyntaxToken& t = tokens.getReference(i);
  35680. for (;;)
  35681. {
  35682. int tabPos = t.text.indexOfChar ('\t');
  35683. if (tabPos < 0)
  35684. break;
  35685. const int spacesNeeded = spacesPerTab - ((tabPos + x) % spacesPerTab);
  35686. t.text = t.text.replaceSection (tabPos, 1, String::repeatedString (T(" "), spacesNeeded));
  35687. }
  35688. x += t.text.length();
  35689. }
  35690. }
  35691. int indexToColumn (int index, const String& line, int spacesPerTab) const throw()
  35692. {
  35693. jassert (index <= line.length());
  35694. int col = 0;
  35695. for (int i = 0; i < index; ++i)
  35696. {
  35697. if (line[i] != '\t')
  35698. ++col;
  35699. else
  35700. col += spacesPerTab - (col % spacesPerTab);
  35701. }
  35702. return col;
  35703. }
  35704. };
  35705. CodeEditorComponent::CodeEditorComponent (CodeDocument& document_,
  35706. CodeTokeniser* const codeTokeniser_)
  35707. : document (document_),
  35708. firstLineOnScreen (0),
  35709. gutter (5),
  35710. spacesPerTab (4),
  35711. lineHeight (0),
  35712. linesOnScreen (0),
  35713. columnsOnScreen (0),
  35714. scrollbarThickness (16),
  35715. columnToTryToMaintain (-1),
  35716. useSpacesForTabs (false),
  35717. xOffset (0),
  35718. codeTokeniser (codeTokeniser_)
  35719. {
  35720. caretPos = CodeDocument::Position (&document_, 0, 0);
  35721. caretPos.setPositionMaintained (true);
  35722. selectionStart = CodeDocument::Position (&document_, 0, 0);
  35723. selectionStart.setPositionMaintained (true);
  35724. selectionEnd = CodeDocument::Position (&document_, 0, 0);
  35725. selectionEnd.setPositionMaintained (true);
  35726. setOpaque (true);
  35727. setMouseCursor (MouseCursor (MouseCursor::IBeamCursor));
  35728. setWantsKeyboardFocus (true);
  35729. addAndMakeVisible (verticalScrollBar = new ScrollBar (true));
  35730. verticalScrollBar->setSingleStepSize (1.0);
  35731. addAndMakeVisible (horizontalScrollBar = new ScrollBar (false));
  35732. horizontalScrollBar->setSingleStepSize (1.0);
  35733. addAndMakeVisible (caret = new CaretComponent());
  35734. Font f (12.0f);
  35735. f.setTypefaceName (Font::getDefaultMonospacedFontName());
  35736. setFont (f);
  35737. resetToDefaultColours();
  35738. verticalScrollBar->addListener (this);
  35739. horizontalScrollBar->addListener (this);
  35740. document.addListener (this);
  35741. }
  35742. CodeEditorComponent::~CodeEditorComponent()
  35743. {
  35744. document.removeListener (this);
  35745. deleteAllChildren();
  35746. }
  35747. void CodeEditorComponent::loadContent (const String& newContent)
  35748. {
  35749. clearCachedIterators (0);
  35750. document.replaceAllContent (newContent);
  35751. document.clearUndoHistory();
  35752. document.setSavePoint();
  35753. caretPos.setPosition (0);
  35754. selectionStart.setPosition (0);
  35755. selectionEnd.setPosition (0);
  35756. scrollToLine (0);
  35757. }
  35758. void CodeEditorComponent::codeDocumentChanged (const CodeDocument::Position& affectedTextStart,
  35759. const CodeDocument::Position& affectedTextEnd)
  35760. {
  35761. clearCachedIterators (affectedTextStart.getLineNumber());
  35762. triggerAsyncUpdate();
  35763. ((CaretComponent*) caret)->updatePosition (*this);
  35764. columnToTryToMaintain = -1;
  35765. if (affectedTextEnd.getPosition() >= selectionStart.getPosition()
  35766. && affectedTextStart.getPosition() <= selectionEnd.getPosition())
  35767. deselectAll();
  35768. if (caretPos.getPosition() > affectedTextEnd.getPosition()
  35769. || caretPos.getPosition() < affectedTextStart.getPosition())
  35770. moveCaretTo (affectedTextStart, false);
  35771. updateScrollBars();
  35772. }
  35773. void CodeEditorComponent::resized()
  35774. {
  35775. linesOnScreen = (getHeight() - scrollbarThickness) / lineHeight;
  35776. columnsOnScreen = (int) ((getWidth() - scrollbarThickness) / charWidth);
  35777. lines.clear();
  35778. rebuildLineTokens();
  35779. ((CaretComponent*) caret)->updatePosition (*this);
  35780. verticalScrollBar->setBounds (getWidth() - scrollbarThickness, 0, scrollbarThickness, getHeight() - scrollbarThickness);
  35781. horizontalScrollBar->setBounds (gutter, getHeight() - scrollbarThickness, getWidth() - scrollbarThickness - gutter, scrollbarThickness);
  35782. updateScrollBars();
  35783. }
  35784. void CodeEditorComponent::paint (Graphics& g)
  35785. {
  35786. handleUpdateNowIfNeeded();
  35787. g.fillAll (findColour (CodeEditorComponent::backgroundColourId));
  35788. g.reduceClipRegion (gutter, 0, verticalScrollBar->getX() - gutter, horizontalScrollBar->getY());
  35789. g.setFont (font);
  35790. const int baselineOffset = (int) font.getAscent();
  35791. const Colour defaultColour (findColour (CodeEditorComponent::defaultTextColourId));
  35792. const Colour highlightColour (findColour (CodeEditorComponent::highlightColourId));
  35793. const Rectangle<int> clip (g.getClipBounds());
  35794. const int firstLineToDraw = jmax (0, clip.getY() / lineHeight);
  35795. const int lastLineToDraw = jmin (lines.size(), clip.getBottom() / lineHeight + 1);
  35796. for (int j = firstLineToDraw; j < lastLineToDraw; ++j)
  35797. {
  35798. lines.getUnchecked(j)->draw (*this, g, font,
  35799. (float) (gutter - xOffset * charWidth),
  35800. lineHeight * j, baselineOffset, lineHeight,
  35801. highlightColour);
  35802. }
  35803. }
  35804. void CodeEditorComponent::setScrollbarThickness (const int thickness) throw()
  35805. {
  35806. if (scrollbarThickness != thickness)
  35807. {
  35808. scrollbarThickness = thickness;
  35809. resized();
  35810. }
  35811. }
  35812. void CodeEditorComponent::handleAsyncUpdate()
  35813. {
  35814. rebuildLineTokens();
  35815. }
  35816. void CodeEditorComponent::rebuildLineTokens()
  35817. {
  35818. cancelPendingUpdate();
  35819. const int numNeeded = linesOnScreen + 1;
  35820. int minLineToRepaint = numNeeded;
  35821. int maxLineToRepaint = 0;
  35822. if (numNeeded != lines.size())
  35823. {
  35824. lines.clear();
  35825. for (int i = numNeeded; --i >= 0;)
  35826. lines.add (new CodeEditorLine());
  35827. minLineToRepaint = 0;
  35828. maxLineToRepaint = numNeeded;
  35829. }
  35830. jassert (numNeeded == lines.size());
  35831. CodeDocument::Iterator source (&document);
  35832. getIteratorForPosition (CodeDocument::Position (&document, firstLineOnScreen, 0).getPosition(), source);
  35833. for (int i = 0; i < numNeeded; ++i)
  35834. {
  35835. CodeEditorLine* const line = lines.getUnchecked(i);
  35836. if (line->update (document, firstLineOnScreen + i, source, codeTokeniser, spacesPerTab,
  35837. selectionStart, selectionEnd))
  35838. {
  35839. minLineToRepaint = jmin (minLineToRepaint, i);
  35840. maxLineToRepaint = jmax (maxLineToRepaint, i);
  35841. }
  35842. }
  35843. if (minLineToRepaint <= maxLineToRepaint)
  35844. {
  35845. repaint (gutter, lineHeight * minLineToRepaint - 1,
  35846. verticalScrollBar->getX() - gutter,
  35847. lineHeight * (1 + maxLineToRepaint - minLineToRepaint) + 2);
  35848. }
  35849. }
  35850. void CodeEditorComponent::moveCaretTo (const CodeDocument::Position& newPos, const bool highlighting)
  35851. {
  35852. caretPos = newPos;
  35853. columnToTryToMaintain = -1;
  35854. if (highlighting)
  35855. {
  35856. if (dragType == notDragging)
  35857. {
  35858. if (abs (caretPos.getPosition() - selectionStart.getPosition())
  35859. < abs (caretPos.getPosition() - selectionEnd.getPosition()))
  35860. dragType = draggingSelectionStart;
  35861. else
  35862. dragType = draggingSelectionEnd;
  35863. }
  35864. if (dragType == draggingSelectionStart)
  35865. {
  35866. selectionStart = caretPos;
  35867. if (selectionEnd.getPosition() < selectionStart.getPosition())
  35868. {
  35869. const CodeDocument::Position temp (selectionStart);
  35870. selectionStart = selectionEnd;
  35871. selectionEnd = temp;
  35872. dragType = draggingSelectionEnd;
  35873. }
  35874. }
  35875. else
  35876. {
  35877. selectionEnd = caretPos;
  35878. if (selectionEnd.getPosition() < selectionStart.getPosition())
  35879. {
  35880. const CodeDocument::Position temp (selectionStart);
  35881. selectionStart = selectionEnd;
  35882. selectionEnd = temp;
  35883. dragType = draggingSelectionStart;
  35884. }
  35885. }
  35886. triggerAsyncUpdate();
  35887. }
  35888. else
  35889. {
  35890. deselectAll();
  35891. }
  35892. ((CaretComponent*) caret)->updatePosition (*this);
  35893. scrollToKeepCaretOnScreen();
  35894. updateScrollBars();
  35895. }
  35896. void CodeEditorComponent::deselectAll()
  35897. {
  35898. if (selectionStart != selectionEnd)
  35899. triggerAsyncUpdate();
  35900. selectionStart = caretPos;
  35901. selectionEnd = caretPos;
  35902. }
  35903. void CodeEditorComponent::updateScrollBars()
  35904. {
  35905. verticalScrollBar->setRangeLimits (0, jmax (document.getNumLines(), firstLineOnScreen + linesOnScreen));
  35906. verticalScrollBar->setCurrentRange (firstLineOnScreen, linesOnScreen);
  35907. horizontalScrollBar->setRangeLimits (0, jmax ((double) document.getMaximumLineLength(), xOffset + columnsOnScreen));
  35908. horizontalScrollBar->setCurrentRange (xOffset, columnsOnScreen);
  35909. }
  35910. void CodeEditorComponent::scrollToLineInternal (int newFirstLineOnScreen)
  35911. {
  35912. newFirstLineOnScreen = jlimit (0, jmax (0, document.getNumLines() - 1),
  35913. newFirstLineOnScreen);
  35914. if (newFirstLineOnScreen != firstLineOnScreen)
  35915. {
  35916. firstLineOnScreen = newFirstLineOnScreen;
  35917. ((CaretComponent*) caret)->updatePosition (*this);
  35918. updateCachedIterators (firstLineOnScreen);
  35919. triggerAsyncUpdate();
  35920. }
  35921. }
  35922. void CodeEditorComponent::scrollToColumnInternal (double column)
  35923. {
  35924. const double newOffset = jlimit (0.0, document.getMaximumLineLength() + 3.0, column);
  35925. if (xOffset != newOffset)
  35926. {
  35927. xOffset = newOffset;
  35928. ((CaretComponent*) caret)->updatePosition (*this);
  35929. repaint();
  35930. }
  35931. }
  35932. void CodeEditorComponent::scrollToLine (int newFirstLineOnScreen)
  35933. {
  35934. scrollToLineInternal (newFirstLineOnScreen);
  35935. updateScrollBars();
  35936. }
  35937. void CodeEditorComponent::scrollToColumn (int newFirstColumnOnScreen)
  35938. {
  35939. scrollToColumnInternal (newFirstColumnOnScreen);
  35940. updateScrollBars();
  35941. }
  35942. void CodeEditorComponent::scrollBy (int deltaLines)
  35943. {
  35944. scrollToLine (firstLineOnScreen + deltaLines);
  35945. }
  35946. void CodeEditorComponent::scrollToKeepCaretOnScreen()
  35947. {
  35948. if (caretPos.getLineNumber() < firstLineOnScreen)
  35949. scrollBy (caretPos.getLineNumber() - firstLineOnScreen);
  35950. else if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  35951. scrollBy (caretPos.getLineNumber() - (firstLineOnScreen + linesOnScreen - 1));
  35952. const int column = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  35953. if (column >= xOffset + columnsOnScreen - 1)
  35954. scrollToColumn (column + 1 - columnsOnScreen);
  35955. else if (column < xOffset)
  35956. scrollToColumn (column);
  35957. }
  35958. const Rectangle<int> CodeEditorComponent::getCharacterBounds (const CodeDocument::Position& pos) const throw()
  35959. {
  35960. return Rectangle<int> (roundToInt ((gutter - xOffset * charWidth) + indexToColumn (pos.getLineNumber(), pos.getIndexInLine()) * charWidth),
  35961. (pos.getLineNumber() - firstLineOnScreen) * lineHeight,
  35962. roundToInt (charWidth),
  35963. lineHeight);
  35964. }
  35965. const CodeDocument::Position CodeEditorComponent::getPositionAt (int x, int y)
  35966. {
  35967. const int line = y / lineHeight + firstLineOnScreen;
  35968. const int column = roundToInt ((x - (gutter - xOffset * charWidth)) / charWidth);
  35969. const int index = columnToIndex (line, column);
  35970. return CodeDocument::Position (&document, line, index);
  35971. }
  35972. void CodeEditorComponent::insertTextAtCaret (const String& newText)
  35973. {
  35974. document.deleteSection (selectionStart, selectionEnd);
  35975. if (newText.isNotEmpty())
  35976. document.insertText (caretPos, newText);
  35977. scrollToKeepCaretOnScreen();
  35978. }
  35979. void CodeEditorComponent::insertTabAtCaret()
  35980. {
  35981. if (CharacterFunctions::isWhitespace (caretPos.getCharacter())
  35982. && caretPos.getLineNumber() == caretPos.movedBy (1).getLineNumber())
  35983. {
  35984. moveCaretTo (document.findWordBreakAfter (caretPos), false);
  35985. }
  35986. if (useSpacesForTabs)
  35987. {
  35988. const int caretCol = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  35989. const int spacesNeeded = spacesPerTab - (caretCol % spacesPerTab);
  35990. insertTextAtCaret (String::repeatedString (T(" "), spacesNeeded));
  35991. }
  35992. else
  35993. {
  35994. insertTextAtCaret ("\t");
  35995. }
  35996. }
  35997. void CodeEditorComponent::cut()
  35998. {
  35999. insertTextAtCaret (String::empty);
  36000. }
  36001. void CodeEditorComponent::copy()
  36002. {
  36003. newTransaction();
  36004. const String selection (document.getTextBetween (selectionStart, selectionEnd));
  36005. if (selection.isNotEmpty())
  36006. SystemClipboard::copyTextToClipboard (selection);
  36007. }
  36008. void CodeEditorComponent::copyThenCut()
  36009. {
  36010. copy();
  36011. cut();
  36012. newTransaction();
  36013. }
  36014. void CodeEditorComponent::paste()
  36015. {
  36016. newTransaction();
  36017. const String clip (SystemClipboard::getTextFromClipboard());
  36018. if (clip.isNotEmpty())
  36019. insertTextAtCaret (clip);
  36020. newTransaction();
  36021. }
  36022. void CodeEditorComponent::cursorLeft (const bool moveInWholeWordSteps, const bool selecting)
  36023. {
  36024. newTransaction();
  36025. if (moveInWholeWordSteps)
  36026. moveCaretTo (document.findWordBreakBefore (caretPos), selecting);
  36027. else
  36028. moveCaretTo (caretPos.movedBy (-1), selecting);
  36029. }
  36030. void CodeEditorComponent::cursorRight (const bool moveInWholeWordSteps, const bool selecting)
  36031. {
  36032. newTransaction();
  36033. if (moveInWholeWordSteps)
  36034. moveCaretTo (document.findWordBreakAfter (caretPos), selecting);
  36035. else
  36036. moveCaretTo (caretPos.movedBy (1), selecting);
  36037. }
  36038. void CodeEditorComponent::moveLineDelta (const int delta, const bool selecting)
  36039. {
  36040. CodeDocument::Position pos (caretPos);
  36041. const int newLineNum = pos.getLineNumber() + delta;
  36042. if (columnToTryToMaintain < 0)
  36043. columnToTryToMaintain = indexToColumn (pos.getLineNumber(), pos.getIndexInLine());
  36044. pos.setLineAndIndex (newLineNum, columnToIndex (newLineNum, columnToTryToMaintain));
  36045. const int colToMaintain = columnToTryToMaintain;
  36046. moveCaretTo (pos, selecting);
  36047. columnToTryToMaintain = colToMaintain;
  36048. }
  36049. void CodeEditorComponent::cursorDown (const bool selecting)
  36050. {
  36051. newTransaction();
  36052. if (caretPos.getLineNumber() == document.getNumLines() - 1)
  36053. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36054. else
  36055. moveLineDelta (1, selecting);
  36056. }
  36057. void CodeEditorComponent::cursorUp (const bool selecting)
  36058. {
  36059. newTransaction();
  36060. if (caretPos.getLineNumber() == 0)
  36061. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36062. else
  36063. moveLineDelta (-1, selecting);
  36064. }
  36065. void CodeEditorComponent::pageDown (const bool selecting)
  36066. {
  36067. newTransaction();
  36068. scrollBy (jlimit (0, linesOnScreen, 1 + document.getNumLines() - firstLineOnScreen - linesOnScreen));
  36069. moveLineDelta (linesOnScreen, selecting);
  36070. }
  36071. void CodeEditorComponent::pageUp (const bool selecting)
  36072. {
  36073. newTransaction();
  36074. scrollBy (-linesOnScreen);
  36075. moveLineDelta (-linesOnScreen, selecting);
  36076. }
  36077. void CodeEditorComponent::scrollUp()
  36078. {
  36079. newTransaction();
  36080. scrollBy (1);
  36081. if (caretPos.getLineNumber() < firstLineOnScreen)
  36082. moveLineDelta (1, false);
  36083. }
  36084. void CodeEditorComponent::scrollDown()
  36085. {
  36086. newTransaction();
  36087. scrollBy (-1);
  36088. if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  36089. moveLineDelta (-1, false);
  36090. }
  36091. void CodeEditorComponent::goToStartOfDocument (const bool selecting)
  36092. {
  36093. newTransaction();
  36094. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36095. }
  36096. static int findFirstNonWhitespaceChar (const String& line) throw()
  36097. {
  36098. const int len = line.length();
  36099. for (int i = 0; i < len; ++i)
  36100. if (! CharacterFunctions::isWhitespace (line [i]))
  36101. return i;
  36102. return 0;
  36103. }
  36104. void CodeEditorComponent::goToStartOfLine (const bool selecting)
  36105. {
  36106. newTransaction();
  36107. int index = findFirstNonWhitespaceChar (caretPos.getLineText());
  36108. if (index >= caretPos.getIndexInLine() && caretPos.getIndexInLine() > 0)
  36109. index = 0;
  36110. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), index), selecting);
  36111. }
  36112. void CodeEditorComponent::goToEndOfDocument (const bool selecting)
  36113. {
  36114. newTransaction();
  36115. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36116. }
  36117. void CodeEditorComponent::goToEndOfLine (const bool selecting)
  36118. {
  36119. newTransaction();
  36120. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), std::numeric_limits<int>::max()), selecting);
  36121. }
  36122. void CodeEditorComponent::backspace (const bool moveInWholeWordSteps)
  36123. {
  36124. if (moveInWholeWordSteps)
  36125. {
  36126. cut(); // in case something is already highlighted
  36127. moveCaretTo (document.findWordBreakBefore (caretPos), true);
  36128. }
  36129. else
  36130. {
  36131. if (selectionStart == selectionEnd)
  36132. selectionStart.moveBy (-1);
  36133. }
  36134. cut();
  36135. }
  36136. void CodeEditorComponent::deleteForward (const bool moveInWholeWordSteps)
  36137. {
  36138. if (moveInWholeWordSteps)
  36139. {
  36140. cut(); // in case something is already highlighted
  36141. moveCaretTo (document.findWordBreakAfter (caretPos), true);
  36142. }
  36143. else
  36144. {
  36145. if (selectionStart == selectionEnd)
  36146. selectionEnd.moveBy (1);
  36147. else
  36148. newTransaction();
  36149. }
  36150. cut();
  36151. }
  36152. void CodeEditorComponent::selectAll()
  36153. {
  36154. newTransaction();
  36155. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), false);
  36156. moveCaretTo (CodeDocument::Position (&document, 0, 0), true);
  36157. }
  36158. void CodeEditorComponent::undo()
  36159. {
  36160. document.undo();
  36161. scrollToKeepCaretOnScreen();
  36162. }
  36163. void CodeEditorComponent::redo()
  36164. {
  36165. document.redo();
  36166. scrollToKeepCaretOnScreen();
  36167. }
  36168. void CodeEditorComponent::newTransaction()
  36169. {
  36170. document.newTransaction();
  36171. startTimer (600);
  36172. }
  36173. void CodeEditorComponent::timerCallback()
  36174. {
  36175. newTransaction();
  36176. }
  36177. const Range<int> CodeEditorComponent::getHighlightedRegion() const
  36178. {
  36179. return Range<int> (selectionStart.getPosition(), selectionEnd.getPosition());
  36180. }
  36181. void CodeEditorComponent::setHighlightedRegion (const Range<int>& newRange)
  36182. {
  36183. moveCaretTo (CodeDocument::Position (&document, newRange.getStart()), false);
  36184. moveCaretTo (CodeDocument::Position (&document, newRange.getEnd()), true);
  36185. }
  36186. const String CodeEditorComponent::getTextInRange (const Range<int>& range) const
  36187. {
  36188. return document.getTextBetween (CodeDocument::Position (&document, range.getStart()),
  36189. CodeDocument::Position (&document, range.getEnd()));
  36190. }
  36191. bool CodeEditorComponent::keyPressed (const KeyPress& key)
  36192. {
  36193. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  36194. const bool shiftDown = key.getModifiers().isShiftDown();
  36195. if (key.isKeyCode (KeyPress::leftKey))
  36196. {
  36197. cursorLeft (moveInWholeWordSteps, shiftDown);
  36198. }
  36199. else if (key.isKeyCode (KeyPress::rightKey))
  36200. {
  36201. cursorRight (moveInWholeWordSteps, shiftDown);
  36202. }
  36203. else if (key.isKeyCode (KeyPress::upKey))
  36204. {
  36205. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36206. scrollDown();
  36207. #if JUCE_MAC
  36208. else if (key.getModifiers().isCommandDown())
  36209. goToStartOfDocument (shiftDown);
  36210. #endif
  36211. else
  36212. cursorUp (shiftDown);
  36213. }
  36214. else if (key.isKeyCode (KeyPress::downKey))
  36215. {
  36216. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36217. scrollUp();
  36218. #if JUCE_MAC
  36219. else if (key.getModifiers().isCommandDown())
  36220. goToEndOfDocument (shiftDown);
  36221. #endif
  36222. else
  36223. cursorDown (shiftDown);
  36224. }
  36225. else if (key.isKeyCode (KeyPress::pageDownKey))
  36226. {
  36227. pageDown (shiftDown);
  36228. }
  36229. else if (key.isKeyCode (KeyPress::pageUpKey))
  36230. {
  36231. pageUp (shiftDown);
  36232. }
  36233. else if (key.isKeyCode (KeyPress::homeKey))
  36234. {
  36235. if (moveInWholeWordSteps)
  36236. goToStartOfDocument (shiftDown);
  36237. else
  36238. goToStartOfLine (shiftDown);
  36239. }
  36240. else if (key.isKeyCode (KeyPress::endKey))
  36241. {
  36242. if (moveInWholeWordSteps)
  36243. goToEndOfDocument (shiftDown);
  36244. else
  36245. goToEndOfLine (shiftDown);
  36246. }
  36247. else if (key.isKeyCode (KeyPress::backspaceKey))
  36248. {
  36249. backspace (moveInWholeWordSteps);
  36250. }
  36251. else if (key.isKeyCode (KeyPress::deleteKey))
  36252. {
  36253. deleteForward (moveInWholeWordSteps);
  36254. }
  36255. else if (key == KeyPress ('c', ModifierKeys::commandModifier, 0))
  36256. {
  36257. copy();
  36258. }
  36259. else if (key == KeyPress ('x', ModifierKeys::commandModifier, 0))
  36260. {
  36261. copyThenCut();
  36262. }
  36263. else if (key == KeyPress ('v', ModifierKeys::commandModifier, 0))
  36264. {
  36265. paste();
  36266. }
  36267. else if (key == KeyPress ('z', ModifierKeys::commandModifier, 0))
  36268. {
  36269. undo();
  36270. }
  36271. else if (key == KeyPress ('y', ModifierKeys::commandModifier, 0)
  36272. || key == KeyPress ('z', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0))
  36273. {
  36274. redo();
  36275. }
  36276. else if (key == KeyPress ('a', ModifierKeys::commandModifier, 0))
  36277. {
  36278. selectAll();
  36279. }
  36280. else if (key == KeyPress::tabKey || key.getTextCharacter() == '\t')
  36281. {
  36282. insertTabAtCaret();
  36283. }
  36284. else if (key == KeyPress::returnKey)
  36285. {
  36286. newTransaction();
  36287. insertTextAtCaret (document.getNewLineCharacters());
  36288. }
  36289. else if (key.isKeyCode (KeyPress::escapeKey))
  36290. {
  36291. newTransaction();
  36292. }
  36293. else if (key.getTextCharacter() >= ' ')
  36294. {
  36295. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  36296. }
  36297. else
  36298. {
  36299. return false;
  36300. }
  36301. return true;
  36302. }
  36303. void CodeEditorComponent::mouseDown (const MouseEvent& e)
  36304. {
  36305. newTransaction();
  36306. dragType = notDragging;
  36307. if (! e.mods.isPopupMenu())
  36308. {
  36309. beginDragAutoRepeat (100);
  36310. moveCaretTo (getPositionAt (e.x, e.y), e.mods.isShiftDown());
  36311. }
  36312. else
  36313. {
  36314. }
  36315. }
  36316. void CodeEditorComponent::mouseDrag (const MouseEvent& e)
  36317. {
  36318. if (! e.mods.isPopupMenu())
  36319. moveCaretTo (getPositionAt (e.x, e.y), true);
  36320. }
  36321. void CodeEditorComponent::mouseUp (const MouseEvent&)
  36322. {
  36323. newTransaction();
  36324. beginDragAutoRepeat (0);
  36325. dragType = notDragging;
  36326. }
  36327. void CodeEditorComponent::mouseDoubleClick (const MouseEvent& e)
  36328. {
  36329. CodeDocument::Position tokenStart (getPositionAt (e.x, e.y));
  36330. CodeDocument::Position tokenEnd (tokenStart);
  36331. if (e.getNumberOfClicks() > 2)
  36332. {
  36333. tokenStart.setLineAndIndex (tokenStart.getLineNumber(), 0);
  36334. tokenEnd.setLineAndIndex (tokenStart.getLineNumber() + 1, 0);
  36335. }
  36336. else
  36337. {
  36338. while (CharacterFunctions::isLetterOrDigit (tokenEnd.getCharacter()))
  36339. tokenEnd.moveBy (1);
  36340. tokenStart = tokenEnd;
  36341. while (tokenStart.getIndexInLine() > 0
  36342. && CharacterFunctions::isLetterOrDigit (tokenStart.movedBy (-1).getCharacter()))
  36343. tokenStart.moveBy (-1);
  36344. }
  36345. moveCaretTo (tokenEnd, false);
  36346. moveCaretTo (tokenStart, true);
  36347. }
  36348. void CodeEditorComponent::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  36349. {
  36350. verticalScrollBar->mouseWheelMove (e, 0, wheelIncrementY);
  36351. horizontalScrollBar->mouseWheelMove (e, wheelIncrementX, 0);
  36352. }
  36353. void CodeEditorComponent::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, double newRangeStart)
  36354. {
  36355. if (scrollBarThatHasMoved == verticalScrollBar)
  36356. scrollToLineInternal ((int) newRangeStart);
  36357. else
  36358. scrollToColumnInternal (newRangeStart);
  36359. }
  36360. void CodeEditorComponent::setTabSize (const int numSpaces, const bool insertSpaces) throw()
  36361. {
  36362. useSpacesForTabs = insertSpaces;
  36363. if (spacesPerTab != numSpaces)
  36364. {
  36365. spacesPerTab = numSpaces;
  36366. triggerAsyncUpdate();
  36367. }
  36368. }
  36369. int CodeEditorComponent::indexToColumn (int lineNum, int index) const throw()
  36370. {
  36371. const String line (document.getLine (lineNum));
  36372. jassert (index <= line.length());
  36373. int col = 0;
  36374. for (int i = 0; i < index; ++i)
  36375. {
  36376. if (line[i] != '\t')
  36377. ++col;
  36378. else
  36379. col += getTabSize() - (col % getTabSize());
  36380. }
  36381. return col;
  36382. }
  36383. int CodeEditorComponent::columnToIndex (int lineNum, int column) const throw()
  36384. {
  36385. const String line (document.getLine (lineNum));
  36386. const int lineLength = line.length();
  36387. int i, col = 0;
  36388. for (i = 0; i < lineLength; ++i)
  36389. {
  36390. if (line[i] != '\t')
  36391. ++col;
  36392. else
  36393. col += getTabSize() - (col % getTabSize());
  36394. if (col > column)
  36395. break;
  36396. }
  36397. return i;
  36398. }
  36399. void CodeEditorComponent::setFont (const Font& newFont)
  36400. {
  36401. font = newFont;
  36402. charWidth = font.getStringWidthFloat ("0");
  36403. lineHeight = roundToInt (font.getHeight());
  36404. resized();
  36405. }
  36406. void CodeEditorComponent::resetToDefaultColours()
  36407. {
  36408. coloursForTokenCategories.clear();
  36409. if (codeTokeniser != 0)
  36410. {
  36411. for (int i = codeTokeniser->getTokenTypes().size(); --i >= 0;)
  36412. setColourForTokenType (i, codeTokeniser->getDefaultColour (i));
  36413. }
  36414. }
  36415. void CodeEditorComponent::setColourForTokenType (const int tokenType, const Colour& colour)
  36416. {
  36417. jassert (tokenType < 256);
  36418. while (coloursForTokenCategories.size() < tokenType)
  36419. coloursForTokenCategories.add (Colours::black);
  36420. coloursForTokenCategories.set (tokenType, colour);
  36421. repaint();
  36422. }
  36423. const Colour CodeEditorComponent::getColourForTokenType (const int tokenType) const throw()
  36424. {
  36425. if (((unsigned int) tokenType) >= (unsigned int) coloursForTokenCategories.size())
  36426. return findColour (CodeEditorComponent::defaultTextColourId);
  36427. return coloursForTokenCategories.getReference (tokenType);
  36428. }
  36429. void CodeEditorComponent::clearCachedIterators (const int firstLineToBeInvalid) throw()
  36430. {
  36431. int i;
  36432. for (i = cachedIterators.size(); --i >= 0;)
  36433. if (cachedIterators.getUnchecked (i)->getLine() < firstLineToBeInvalid)
  36434. break;
  36435. cachedIterators.removeRange (jmax (0, i - 1), cachedIterators.size());
  36436. }
  36437. void CodeEditorComponent::updateCachedIterators (int maxLineNum)
  36438. {
  36439. const int maxNumCachedPositions = 5000;
  36440. const int linesBetweenCachedSources = jmax (10, document.getNumLines() / maxNumCachedPositions);
  36441. if (cachedIterators.size() == 0)
  36442. cachedIterators.add (new CodeDocument::Iterator (&document));
  36443. if (codeTokeniser == 0)
  36444. return;
  36445. for (;;)
  36446. {
  36447. CodeDocument::Iterator* last = cachedIterators.getLast();
  36448. if (last->getLine() >= maxLineNum)
  36449. break;
  36450. CodeDocument::Iterator* t = new CodeDocument::Iterator (*last);
  36451. cachedIterators.add (t);
  36452. const int targetLine = last->getLine() + linesBetweenCachedSources;
  36453. for (;;)
  36454. {
  36455. codeTokeniser->readNextToken (*t);
  36456. if (t->getLine() >= targetLine)
  36457. break;
  36458. if (t->isEOF())
  36459. return;
  36460. }
  36461. }
  36462. }
  36463. void CodeEditorComponent::getIteratorForPosition (int position, CodeDocument::Iterator& source)
  36464. {
  36465. if (codeTokeniser == 0)
  36466. return;
  36467. for (int i = cachedIterators.size(); --i >= 0;)
  36468. {
  36469. CodeDocument::Iterator* t = cachedIterators.getUnchecked (i);
  36470. if (t->getPosition() <= position)
  36471. {
  36472. source = *t;
  36473. break;
  36474. }
  36475. }
  36476. while (source.getPosition() < position)
  36477. {
  36478. const CodeDocument::Iterator original (source);
  36479. codeTokeniser->readNextToken (source);
  36480. if (source.getPosition() > position || source.isEOF())
  36481. {
  36482. source = original;
  36483. break;
  36484. }
  36485. }
  36486. }
  36487. END_JUCE_NAMESPACE
  36488. /*** End of inlined file: juce_CodeEditorComponent.cpp ***/
  36489. /*** Start of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  36490. BEGIN_JUCE_NAMESPACE
  36491. CPlusPlusCodeTokeniser::CPlusPlusCodeTokeniser()
  36492. {
  36493. }
  36494. CPlusPlusCodeTokeniser::~CPlusPlusCodeTokeniser()
  36495. {
  36496. }
  36497. namespace CppTokeniser
  36498. {
  36499. static bool isIdentifierStart (const tchar c) throw()
  36500. {
  36501. return CharacterFunctions::isLetter (c)
  36502. || c == '_' || c == '@';
  36503. }
  36504. static bool isIdentifierBody (const tchar c) throw()
  36505. {
  36506. return CharacterFunctions::isLetter (c)
  36507. || CharacterFunctions::isDigit (c)
  36508. || c == '_' || c == '@';
  36509. }
  36510. static int parseIdentifier (CodeDocument::Iterator& source) throw()
  36511. {
  36512. static const tchar* keywords2Char[] =
  36513. { T("if"), T("do"), T("or"), 0 };
  36514. static const tchar* keywords3Char[] =
  36515. { T("for"), T("int"), T("new"), T("try"), T("xor"), T("and"), T("asm"), T("not"), 0 };
  36516. static const tchar* keywords4Char[] =
  36517. { T("bool"), T("void"), T("this"), T("true"), T("long"), T("else"), T("char"),
  36518. T("enum"), T("case"), T("goto"), T("auto"), 0 };
  36519. static const tchar* keywords5Char[] =
  36520. { T("while"), T("bitor"), T("break"), T("catch"), T("class"), T("compl"), T("const"), T("false"),
  36521. T("float"), T("short"), T("throw"), T("union"), T("using"), T("or_eq"), 0 };
  36522. static const tchar* keywords6Char[] =
  36523. { T("return"), T("struct"), T("and_eq"), T("bitand"), T("delete"), T("double"), T("extern"),
  36524. T("friend"), T("inline"), T("not_eq"), T("public"), T("sizeof"), T("static"), T("signed"),
  36525. T("switch"), T("typeid"), T("wchar_t"), T("xor_eq"), 0};
  36526. static const tchar* keywordsOther[] =
  36527. { T("const_cast"), T("continue"), T("default"), T("explicit"), T("mutable"), T("namespace"),
  36528. T("operator"), T("private"), T("protected"), T("register"), T("reinterpret_cast"), T("static_cast"),
  36529. T("template"), T("typedef"), T("typename"), T("unsigned"), T("virtual"), T("volatile"),
  36530. T("@implementation"), T("@interface"), T("@end"), T("@synthesize"), T("@dynamic"), T("@public"),
  36531. T("@private"), T("@property"), T("@protected"), T("@class"), 0 };
  36532. int tokenLength = 0;
  36533. tchar possibleIdentifier [19];
  36534. while (isIdentifierBody (source.peekNextChar()))
  36535. {
  36536. const tchar c = source.nextChar();
  36537. if (tokenLength < numElementsInArray (possibleIdentifier) - 1)
  36538. possibleIdentifier [tokenLength] = c;
  36539. ++tokenLength;
  36540. }
  36541. if (tokenLength > 1 && tokenLength <= 16)
  36542. {
  36543. possibleIdentifier [tokenLength] = 0;
  36544. const tchar** k;
  36545. switch (tokenLength)
  36546. {
  36547. case 2: k = keywords2Char; break;
  36548. case 3: k = keywords3Char; break;
  36549. case 4: k = keywords4Char; break;
  36550. case 5: k = keywords5Char; break;
  36551. case 6: k = keywords6Char; break;
  36552. default: k = keywordsOther; break;
  36553. }
  36554. int i = 0;
  36555. while (k[i] != 0)
  36556. {
  36557. if (k[i][0] == possibleIdentifier[0] && CharacterFunctions::compare (k[i], possibleIdentifier) == 0)
  36558. return CPlusPlusCodeTokeniser::tokenType_builtInKeyword;
  36559. ++i;
  36560. }
  36561. }
  36562. return CPlusPlusCodeTokeniser::tokenType_identifier;
  36563. }
  36564. static bool skipNumberSuffix (CodeDocument::Iterator& source)
  36565. {
  36566. const juce_wchar c = source.peekNextChar();
  36567. if (c == 'l' || c == 'L' || c == 'u' || c == 'U')
  36568. source.skip();
  36569. if (CharacterFunctions::isLetterOrDigit (source.peekNextChar()))
  36570. return false;
  36571. return true;
  36572. }
  36573. static bool isHexDigit (const juce_wchar c) throw()
  36574. {
  36575. return (c >= '0' && c <= '9')
  36576. || (c >= 'a' && c <= 'f')
  36577. || (c >= 'A' && c <= 'F');
  36578. }
  36579. static bool parseHexLiteral (CodeDocument::Iterator& source) throw()
  36580. {
  36581. if (source.nextChar() != '0')
  36582. return false;
  36583. juce_wchar c = source.nextChar();
  36584. if (c != 'x' && c != 'X')
  36585. return false;
  36586. int numDigits = 0;
  36587. while (isHexDigit (source.peekNextChar()))
  36588. {
  36589. ++numDigits;
  36590. source.skip();
  36591. }
  36592. if (numDigits == 0)
  36593. return false;
  36594. return skipNumberSuffix (source);
  36595. }
  36596. static bool isOctalDigit (const juce_wchar c) throw()
  36597. {
  36598. return c >= '0' && c <= '7';
  36599. }
  36600. static bool parseOctalLiteral (CodeDocument::Iterator& source) throw()
  36601. {
  36602. if (source.nextChar() != '0')
  36603. return false;
  36604. if (! isOctalDigit (source.nextChar()))
  36605. return false;
  36606. while (isOctalDigit (source.peekNextChar()))
  36607. source.skip();
  36608. return skipNumberSuffix (source);
  36609. }
  36610. static bool isDecimalDigit (const juce_wchar c) throw()
  36611. {
  36612. return c >= '0' && c <= '9';
  36613. }
  36614. static bool parseDecimalLiteral (CodeDocument::Iterator& source) throw()
  36615. {
  36616. int numChars = 0;
  36617. while (isDecimalDigit (source.peekNextChar()))
  36618. {
  36619. ++numChars;
  36620. source.skip();
  36621. }
  36622. if (numChars == 0)
  36623. return false;
  36624. return skipNumberSuffix (source);
  36625. }
  36626. static bool parseFloatLiteral (CodeDocument::Iterator& source) throw()
  36627. {
  36628. int numDigits = 0;
  36629. while (isDecimalDigit (source.peekNextChar()))
  36630. {
  36631. source.skip();
  36632. ++numDigits;
  36633. }
  36634. const bool hasPoint = (source.peekNextChar() == '.');
  36635. if (hasPoint)
  36636. {
  36637. source.skip();
  36638. while (isDecimalDigit (source.peekNextChar()))
  36639. {
  36640. source.skip();
  36641. ++numDigits;
  36642. }
  36643. }
  36644. if (numDigits == 0)
  36645. return false;
  36646. juce_wchar c = source.peekNextChar();
  36647. const bool hasExponent = (c == 'e' || c == 'E');
  36648. if (hasExponent)
  36649. {
  36650. source.skip();
  36651. c = source.peekNextChar();
  36652. if (c == '+' || c == '-')
  36653. source.skip();
  36654. int numExpDigits = 0;
  36655. while (isDecimalDigit (source.peekNextChar()))
  36656. {
  36657. source.skip();
  36658. ++numExpDigits;
  36659. }
  36660. if (numExpDigits == 0)
  36661. return false;
  36662. }
  36663. c = source.peekNextChar();
  36664. if (c == 'f' || c == 'F')
  36665. source.skip();
  36666. else if (! (hasExponent || hasPoint))
  36667. return false;
  36668. return true;
  36669. }
  36670. static int parseNumber (CodeDocument::Iterator& source)
  36671. {
  36672. const CodeDocument::Iterator original (source);
  36673. if (parseFloatLiteral (source))
  36674. return CPlusPlusCodeTokeniser::tokenType_floatLiteral;
  36675. source = original;
  36676. if (parseHexLiteral (source))
  36677. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36678. source = original;
  36679. if (parseOctalLiteral (source))
  36680. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36681. source = original;
  36682. if (parseDecimalLiteral (source))
  36683. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36684. source = original;
  36685. source.skip();
  36686. return CPlusPlusCodeTokeniser::tokenType_error;
  36687. }
  36688. static void skipQuotedString (CodeDocument::Iterator& source) throw()
  36689. {
  36690. const juce_wchar quote = source.nextChar();
  36691. for (;;)
  36692. {
  36693. const juce_wchar c = source.nextChar();
  36694. if (c == quote || c == 0)
  36695. break;
  36696. if (c == '\\')
  36697. source.skip();
  36698. }
  36699. }
  36700. static void skipComment (CodeDocument::Iterator& source) throw()
  36701. {
  36702. bool lastWasStar = false;
  36703. for (;;)
  36704. {
  36705. const juce_wchar c = source.nextChar();
  36706. if (c == 0 || (c == '/' && lastWasStar))
  36707. break;
  36708. lastWasStar = (c == '*');
  36709. }
  36710. }
  36711. }
  36712. int CPlusPlusCodeTokeniser::readNextToken (CodeDocument::Iterator& source)
  36713. {
  36714. int result = tokenType_error;
  36715. source.skipWhitespace();
  36716. tchar firstChar = source.peekNextChar();
  36717. switch (firstChar)
  36718. {
  36719. case 0:
  36720. source.skip();
  36721. break;
  36722. case '0':
  36723. case '1':
  36724. case '2':
  36725. case '3':
  36726. case '4':
  36727. case '5':
  36728. case '6':
  36729. case '7':
  36730. case '8':
  36731. case '9':
  36732. result = CppTokeniser::parseNumber (source);
  36733. break;
  36734. case '.':
  36735. result = CppTokeniser::parseNumber (source);
  36736. if (result == tokenType_error)
  36737. result = tokenType_punctuation;
  36738. break;
  36739. case ',':
  36740. case ';':
  36741. case ':':
  36742. source.skip();
  36743. result = tokenType_punctuation;
  36744. break;
  36745. case '(':
  36746. case ')':
  36747. case '{':
  36748. case '}':
  36749. case '[':
  36750. case ']':
  36751. source.skip();
  36752. result = tokenType_bracket;
  36753. break;
  36754. case '"':
  36755. case '\'':
  36756. CppTokeniser::skipQuotedString (source);
  36757. result = tokenType_stringLiteral;
  36758. break;
  36759. case '+':
  36760. result = tokenType_operator;
  36761. source.skip();
  36762. if (source.peekNextChar() == '+')
  36763. source.skip();
  36764. else if (source.peekNextChar() == '=')
  36765. source.skip();
  36766. break;
  36767. case '-':
  36768. source.skip();
  36769. result = CppTokeniser::parseNumber (source);
  36770. if (result == tokenType_error)
  36771. {
  36772. result = tokenType_operator;
  36773. if (source.peekNextChar() == '-')
  36774. source.skip();
  36775. else if (source.peekNextChar() == '=')
  36776. source.skip();
  36777. }
  36778. break;
  36779. case '*':
  36780. case '%':
  36781. case '=':
  36782. case '!':
  36783. result = tokenType_operator;
  36784. source.skip();
  36785. if (source.peekNextChar() == '=')
  36786. source.skip();
  36787. break;
  36788. case '/':
  36789. result = tokenType_operator;
  36790. source.skip();
  36791. if (source.peekNextChar() == '=')
  36792. {
  36793. source.skip();
  36794. }
  36795. else if (source.peekNextChar() == '/')
  36796. {
  36797. result = tokenType_comment;
  36798. source.skipToEndOfLine();
  36799. }
  36800. else if (source.peekNextChar() == '*')
  36801. {
  36802. source.skip();
  36803. result = tokenType_comment;
  36804. CppTokeniser::skipComment (source);
  36805. }
  36806. break;
  36807. case '?':
  36808. case '~':
  36809. source.skip();
  36810. result = tokenType_operator;
  36811. break;
  36812. case '<':
  36813. source.skip();
  36814. result = tokenType_operator;
  36815. if (source.peekNextChar() == '=')
  36816. {
  36817. source.skip();
  36818. }
  36819. else if (source.peekNextChar() == '<')
  36820. {
  36821. source.skip();
  36822. if (source.peekNextChar() == '=')
  36823. source.skip();
  36824. }
  36825. break;
  36826. case '>':
  36827. source.skip();
  36828. result = tokenType_operator;
  36829. if (source.peekNextChar() == '=')
  36830. {
  36831. source.skip();
  36832. }
  36833. else if (source.peekNextChar() == '<')
  36834. {
  36835. source.skip();
  36836. if (source.peekNextChar() == '=')
  36837. source.skip();
  36838. }
  36839. break;
  36840. case '|':
  36841. source.skip();
  36842. result = tokenType_operator;
  36843. if (source.peekNextChar() == '=')
  36844. {
  36845. source.skip();
  36846. }
  36847. else if (source.peekNextChar() == '|')
  36848. {
  36849. source.skip();
  36850. if (source.peekNextChar() == '=')
  36851. source.skip();
  36852. }
  36853. break;
  36854. case '&':
  36855. source.skip();
  36856. result = tokenType_operator;
  36857. if (source.peekNextChar() == '=')
  36858. {
  36859. source.skip();
  36860. }
  36861. else if (source.peekNextChar() == '&')
  36862. {
  36863. source.skip();
  36864. if (source.peekNextChar() == '=')
  36865. source.skip();
  36866. }
  36867. break;
  36868. case '^':
  36869. source.skip();
  36870. result = tokenType_operator;
  36871. if (source.peekNextChar() == '=')
  36872. {
  36873. source.skip();
  36874. }
  36875. else if (source.peekNextChar() == '^')
  36876. {
  36877. source.skip();
  36878. if (source.peekNextChar() == '=')
  36879. source.skip();
  36880. }
  36881. break;
  36882. case '#':
  36883. result = tokenType_preprocessor;
  36884. source.skipToEndOfLine();
  36885. break;
  36886. default:
  36887. if (CppTokeniser::isIdentifierStart (firstChar))
  36888. result = CppTokeniser::parseIdentifier (source);
  36889. else
  36890. source.skip();
  36891. break;
  36892. }
  36893. //jassert (result != tokenType_unknown);
  36894. return result;
  36895. }
  36896. const StringArray CPlusPlusCodeTokeniser::getTokenTypes()
  36897. {
  36898. StringArray s;
  36899. s.add ("Error");
  36900. s.add ("Comment");
  36901. s.add ("C++ keyword");
  36902. s.add ("Identifier");
  36903. s.add ("Integer literal");
  36904. s.add ("Float literal");
  36905. s.add ("String literal");
  36906. s.add ("Operator");
  36907. s.add ("Bracket");
  36908. s.add ("Punctuation");
  36909. s.add ("Preprocessor line");
  36910. return s;
  36911. }
  36912. const Colour CPlusPlusCodeTokeniser::getDefaultColour (const int tokenType)
  36913. {
  36914. const uint32 colours[] =
  36915. {
  36916. 0xffcc0000, // error
  36917. 0xff00aa00, // comment
  36918. 0xff0000cc, // keyword
  36919. 0xff000000, // identifier
  36920. 0xff880000, // int literal
  36921. 0xff885500, // float literal
  36922. 0xff990099, // string literal
  36923. 0xff225500, // operator
  36924. 0xff000055, // bracket
  36925. 0xff004400, // punctuation
  36926. 0xff660000 // preprocessor
  36927. };
  36928. if (tokenType >= 0 && tokenType < numElementsInArray (colours))
  36929. return Colour (colours [tokenType]);
  36930. return Colours::black;
  36931. }
  36932. END_JUCE_NAMESPACE
  36933. /*** End of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  36934. /*** Start of inlined file: juce_ComboBox.cpp ***/
  36935. BEGIN_JUCE_NAMESPACE
  36936. ComboBox::ComboBox (const String& name)
  36937. : Component (name),
  36938. lastCurrentId (0),
  36939. isButtonDown (false),
  36940. separatorPending (false),
  36941. menuActive (false),
  36942. label (0)
  36943. {
  36944. noChoicesMessage = TRANS("(no choices)");
  36945. setRepaintsOnMouseActivity (true);
  36946. lookAndFeelChanged();
  36947. currentId.addListener (this);
  36948. }
  36949. ComboBox::~ComboBox()
  36950. {
  36951. currentId.removeListener (this);
  36952. if (menuActive)
  36953. PopupMenu::dismissAllActiveMenus();
  36954. label = 0;
  36955. deleteAllChildren();
  36956. }
  36957. void ComboBox::setEditableText (const bool isEditable)
  36958. {
  36959. label->setEditable (isEditable, isEditable, false);
  36960. setWantsKeyboardFocus (! isEditable);
  36961. resized();
  36962. }
  36963. bool ComboBox::isTextEditable() const throw()
  36964. {
  36965. return label->isEditable();
  36966. }
  36967. void ComboBox::setJustificationType (const Justification& justification) throw()
  36968. {
  36969. label->setJustificationType (justification);
  36970. }
  36971. const Justification ComboBox::getJustificationType() const throw()
  36972. {
  36973. return label->getJustificationType();
  36974. }
  36975. void ComboBox::setTooltip (const String& newTooltip)
  36976. {
  36977. SettableTooltipClient::setTooltip (newTooltip);
  36978. label->setTooltip (newTooltip);
  36979. }
  36980. void ComboBox::addItem (const String& newItemText,
  36981. const int newItemId) throw()
  36982. {
  36983. // you can't add empty strings to the list..
  36984. jassert (newItemText.isNotEmpty());
  36985. // IDs must be non-zero, as zero is used to indicate a lack of selecion.
  36986. jassert (newItemId != 0);
  36987. // you shouldn't use duplicate item IDs!
  36988. jassert (getItemForId (newItemId) == 0);
  36989. if (newItemText.isNotEmpty() && newItemId != 0)
  36990. {
  36991. if (separatorPending)
  36992. {
  36993. separatorPending = false;
  36994. ItemInfo* const item = new ItemInfo();
  36995. item->itemId = 0;
  36996. item->isEnabled = false;
  36997. item->isHeading = false;
  36998. items.add (item);
  36999. }
  37000. ItemInfo* const item = new ItemInfo();
  37001. item->name = newItemText;
  37002. item->itemId = newItemId;
  37003. item->isEnabled = true;
  37004. item->isHeading = false;
  37005. items.add (item);
  37006. }
  37007. }
  37008. void ComboBox::addSeparator() throw()
  37009. {
  37010. separatorPending = (items.size() > 0);
  37011. }
  37012. void ComboBox::addSectionHeading (const String& headingName) throw()
  37013. {
  37014. // you can't add empty strings to the list..
  37015. jassert (headingName.isNotEmpty());
  37016. if (headingName.isNotEmpty())
  37017. {
  37018. if (separatorPending)
  37019. {
  37020. separatorPending = false;
  37021. ItemInfo* const item = new ItemInfo();
  37022. item->itemId = 0;
  37023. item->isEnabled = false;
  37024. item->isHeading = false;
  37025. items.add (item);
  37026. }
  37027. ItemInfo* const item = new ItemInfo();
  37028. item->name = headingName;
  37029. item->itemId = 0;
  37030. item->isEnabled = true;
  37031. item->isHeading = true;
  37032. items.add (item);
  37033. }
  37034. }
  37035. void ComboBox::setItemEnabled (const int itemId,
  37036. const bool shouldBeEnabled) throw()
  37037. {
  37038. ItemInfo* const item = getItemForId (itemId);
  37039. if (item != 0)
  37040. item->isEnabled = shouldBeEnabled;
  37041. }
  37042. void ComboBox::changeItemText (const int itemId,
  37043. const String& newText) throw()
  37044. {
  37045. ItemInfo* const item = getItemForId (itemId);
  37046. jassert (item != 0);
  37047. if (item != 0)
  37048. item->name = newText;
  37049. }
  37050. void ComboBox::clear (const bool dontSendChangeMessage)
  37051. {
  37052. items.clear();
  37053. separatorPending = false;
  37054. if (! label->isEditable())
  37055. setSelectedItemIndex (-1, dontSendChangeMessage);
  37056. }
  37057. bool ComboBox::ItemInfo::isSeparator() const throw()
  37058. {
  37059. return name.isEmpty();
  37060. }
  37061. bool ComboBox::ItemInfo::isRealItem() const throw()
  37062. {
  37063. return ! (isHeading || name.isEmpty());
  37064. }
  37065. ComboBox::ItemInfo* ComboBox::getItemForId (const int itemId) const throw()
  37066. {
  37067. if (itemId != 0)
  37068. {
  37069. for (int i = items.size(); --i >= 0;)
  37070. if (items.getUnchecked(i)->itemId == itemId)
  37071. return items.getUnchecked(i);
  37072. }
  37073. return 0;
  37074. }
  37075. ComboBox::ItemInfo* ComboBox::getItemForIndex (const int index) const throw()
  37076. {
  37077. int n = 0;
  37078. for (int i = 0; i < items.size(); ++i)
  37079. {
  37080. ItemInfo* const item = items.getUnchecked(i);
  37081. if (item->isRealItem())
  37082. if (n++ == index)
  37083. return item;
  37084. }
  37085. return 0;
  37086. }
  37087. int ComboBox::getNumItems() const throw()
  37088. {
  37089. int n = 0;
  37090. for (int i = items.size(); --i >= 0;)
  37091. if (items.getUnchecked(i)->isRealItem())
  37092. ++n;
  37093. return n;
  37094. }
  37095. const String ComboBox::getItemText (const int index) const throw()
  37096. {
  37097. const ItemInfo* const item = getItemForIndex (index);
  37098. if (item != 0)
  37099. return item->name;
  37100. return String::empty;
  37101. }
  37102. int ComboBox::getItemId (const int index) const throw()
  37103. {
  37104. const ItemInfo* const item = getItemForIndex (index);
  37105. return (item != 0) ? item->itemId : 0;
  37106. }
  37107. int ComboBox::indexOfItemId (const int itemId) const throw()
  37108. {
  37109. int n = 0;
  37110. for (int i = 0; i < items.size(); ++i)
  37111. {
  37112. const ItemInfo* const item = items.getUnchecked(i);
  37113. if (item->isRealItem())
  37114. {
  37115. if (item->itemId == itemId)
  37116. return n;
  37117. ++n;
  37118. }
  37119. }
  37120. return -1;
  37121. }
  37122. int ComboBox::getSelectedItemIndex() const throw()
  37123. {
  37124. int index = indexOfItemId (currentId.getValue());
  37125. if (getText() != getItemText (index))
  37126. index = -1;
  37127. return index;
  37128. }
  37129. void ComboBox::setSelectedItemIndex (const int index,
  37130. const bool dontSendChangeMessage) throw()
  37131. {
  37132. setSelectedId (getItemId (index), dontSendChangeMessage);
  37133. }
  37134. int ComboBox::getSelectedId() const throw()
  37135. {
  37136. const ItemInfo* const item = getItemForId (currentId.getValue());
  37137. return (item != 0 && getText() == item->name)
  37138. ? item->itemId
  37139. : 0;
  37140. }
  37141. void ComboBox::setSelectedId (const int newItemId,
  37142. const bool dontSendChangeMessage) throw()
  37143. {
  37144. const ItemInfo* const item = getItemForId (newItemId);
  37145. const String newItemText (item != 0 ? item->name : String::empty);
  37146. if (lastCurrentId != newItemId || label->getText() != newItemText)
  37147. {
  37148. if (! dontSendChangeMessage)
  37149. triggerAsyncUpdate();
  37150. label->setText (newItemText, false);
  37151. lastCurrentId = newItemId;
  37152. currentId = newItemId;
  37153. repaint(); // for the benefit of the 'none selected' text
  37154. }
  37155. }
  37156. void ComboBox::valueChanged (Value&)
  37157. {
  37158. if (lastCurrentId != (int) currentId.getValue())
  37159. setSelectedId (currentId.getValue(), false);
  37160. }
  37161. const String ComboBox::getText() const throw()
  37162. {
  37163. return label->getText();
  37164. }
  37165. void ComboBox::setText (const String& newText,
  37166. const bool dontSendChangeMessage) throw()
  37167. {
  37168. for (int i = items.size(); --i >= 0;)
  37169. {
  37170. const ItemInfo* const item = items.getUnchecked(i);
  37171. if (item->isRealItem()
  37172. && item->name == newText)
  37173. {
  37174. setSelectedId (item->itemId, dontSendChangeMessage);
  37175. return;
  37176. }
  37177. }
  37178. lastCurrentId = 0;
  37179. currentId = 0;
  37180. if (label->getText() != newText)
  37181. {
  37182. label->setText (newText, false);
  37183. if (! dontSendChangeMessage)
  37184. triggerAsyncUpdate();
  37185. }
  37186. repaint();
  37187. }
  37188. void ComboBox::showEditor()
  37189. {
  37190. jassert (isTextEditable()); // you probably shouldn't do this to a non-editable combo box?
  37191. label->showEditor();
  37192. }
  37193. void ComboBox::setTextWhenNothingSelected (const String& newMessage) throw()
  37194. {
  37195. textWhenNothingSelected = newMessage;
  37196. repaint();
  37197. }
  37198. const String ComboBox::getTextWhenNothingSelected() const throw()
  37199. {
  37200. return textWhenNothingSelected;
  37201. }
  37202. void ComboBox::setTextWhenNoChoicesAvailable (const String& newMessage) throw()
  37203. {
  37204. noChoicesMessage = newMessage;
  37205. }
  37206. const String ComboBox::getTextWhenNoChoicesAvailable() const throw()
  37207. {
  37208. return noChoicesMessage;
  37209. }
  37210. void ComboBox::paint (Graphics& g)
  37211. {
  37212. getLookAndFeel().drawComboBox (g,
  37213. getWidth(),
  37214. getHeight(),
  37215. isButtonDown,
  37216. label->getRight(),
  37217. 0,
  37218. getWidth() - label->getRight(),
  37219. getHeight(),
  37220. *this);
  37221. if (textWhenNothingSelected.isNotEmpty()
  37222. && label->getText().isEmpty()
  37223. && ! label->isBeingEdited())
  37224. {
  37225. g.setColour (findColour (textColourId).withMultipliedAlpha (0.5f));
  37226. g.setFont (label->getFont());
  37227. g.drawFittedText (textWhenNothingSelected,
  37228. label->getX() + 2, label->getY() + 1,
  37229. label->getWidth() - 4, label->getHeight() - 2,
  37230. label->getJustificationType(),
  37231. jmax (1, (int) (label->getHeight() / label->getFont().getHeight())));
  37232. }
  37233. }
  37234. void ComboBox::resized()
  37235. {
  37236. if (getHeight() > 0 && getWidth() > 0)
  37237. getLookAndFeel().positionComboBoxText (*this, *label);
  37238. }
  37239. void ComboBox::enablementChanged()
  37240. {
  37241. repaint();
  37242. }
  37243. void ComboBox::lookAndFeelChanged()
  37244. {
  37245. repaint();
  37246. Label* const newLabel = getLookAndFeel().createComboBoxTextBox (*this);
  37247. if (label != 0)
  37248. {
  37249. newLabel->setEditable (label->isEditable());
  37250. newLabel->setJustificationType (label->getJustificationType());
  37251. newLabel->setTooltip (label->getTooltip());
  37252. newLabel->setText (label->getText(), false);
  37253. }
  37254. label = newLabel;
  37255. addAndMakeVisible (newLabel);
  37256. newLabel->addListener (this);
  37257. newLabel->addMouseListener (this, false);
  37258. newLabel->setColour (Label::backgroundColourId, Colours::transparentBlack);
  37259. newLabel->setColour (Label::textColourId, findColour (ComboBox::textColourId));
  37260. newLabel->setColour (TextEditor::textColourId, findColour (ComboBox::textColourId));
  37261. newLabel->setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37262. newLabel->setColour (TextEditor::highlightColourId, findColour (TextEditor::highlightColourId));
  37263. newLabel->setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37264. resized();
  37265. }
  37266. void ComboBox::colourChanged()
  37267. {
  37268. lookAndFeelChanged();
  37269. }
  37270. bool ComboBox::keyPressed (const KeyPress& key)
  37271. {
  37272. bool used = false;
  37273. if (key.isKeyCode (KeyPress::upKey)
  37274. || key.isKeyCode (KeyPress::leftKey))
  37275. {
  37276. setSelectedItemIndex (jmax (0, getSelectedItemIndex() - 1));
  37277. used = true;
  37278. }
  37279. else if (key.isKeyCode (KeyPress::downKey)
  37280. || key.isKeyCode (KeyPress::rightKey))
  37281. {
  37282. setSelectedItemIndex (jmin (getSelectedItemIndex() + 1, getNumItems() - 1));
  37283. used = true;
  37284. }
  37285. else if (key.isKeyCode (KeyPress::returnKey))
  37286. {
  37287. showPopup();
  37288. used = true;
  37289. }
  37290. return used;
  37291. }
  37292. bool ComboBox::keyStateChanged (const bool isKeyDown)
  37293. {
  37294. // only forward key events that aren't used by this component
  37295. return isKeyDown
  37296. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  37297. || KeyPress::isKeyCurrentlyDown (KeyPress::leftKey)
  37298. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  37299. || KeyPress::isKeyCurrentlyDown (KeyPress::rightKey));
  37300. }
  37301. void ComboBox::focusGained (FocusChangeType)
  37302. {
  37303. repaint();
  37304. }
  37305. void ComboBox::focusLost (FocusChangeType)
  37306. {
  37307. repaint();
  37308. }
  37309. void ComboBox::labelTextChanged (Label*)
  37310. {
  37311. triggerAsyncUpdate();
  37312. }
  37313. void ComboBox::showPopup()
  37314. {
  37315. if (! menuActive)
  37316. {
  37317. const int selectedId = getSelectedId();
  37318. Component::SafePointer<Component> deletionWatcher (this);
  37319. PopupMenu menu;
  37320. menu.setLookAndFeel (&getLookAndFeel());
  37321. for (int i = 0; i < items.size(); ++i)
  37322. {
  37323. const ItemInfo* const item = items.getUnchecked(i);
  37324. if (item->isSeparator())
  37325. menu.addSeparator();
  37326. else if (item->isHeading)
  37327. menu.addSectionHeader (item->name);
  37328. else
  37329. menu.addItem (item->itemId, item->name,
  37330. item->isEnabled, item->itemId == selectedId);
  37331. }
  37332. if (items.size() == 0)
  37333. menu.addItem (1, noChoicesMessage, false);
  37334. const int itemHeight = jlimit (12, 24, getHeight());
  37335. menuActive = true;
  37336. const int resultId = menu.showAt (this, selectedId,
  37337. getWidth(), 1, itemHeight);
  37338. if (deletionWatcher == 0)
  37339. return;
  37340. menuActive = false;
  37341. if (resultId != 0)
  37342. setSelectedId (resultId);
  37343. }
  37344. }
  37345. void ComboBox::mouseDown (const MouseEvent& e)
  37346. {
  37347. beginDragAutoRepeat (300);
  37348. isButtonDown = isEnabled();
  37349. if (isButtonDown
  37350. && (e.eventComponent == this || ! label->isEditable()))
  37351. {
  37352. showPopup();
  37353. }
  37354. }
  37355. void ComboBox::mouseDrag (const MouseEvent& e)
  37356. {
  37357. beginDragAutoRepeat (50);
  37358. if (isButtonDown && ! e.mouseWasClicked())
  37359. showPopup();
  37360. }
  37361. void ComboBox::mouseUp (const MouseEvent& e2)
  37362. {
  37363. if (isButtonDown)
  37364. {
  37365. isButtonDown = false;
  37366. repaint();
  37367. const MouseEvent e (e2.getEventRelativeTo (this));
  37368. if (reallyContains (e.x, e.y, true)
  37369. && (e2.eventComponent == this || ! label->isEditable()))
  37370. {
  37371. showPopup();
  37372. }
  37373. }
  37374. }
  37375. void ComboBox::addListener (ComboBoxListener* const listener) throw()
  37376. {
  37377. listeners.add (listener);
  37378. }
  37379. void ComboBox::removeListener (ComboBoxListener* const listener) throw()
  37380. {
  37381. listeners.remove (listener);
  37382. }
  37383. void ComboBox::handleAsyncUpdate()
  37384. {
  37385. Component::BailOutChecker checker (this);
  37386. listeners.callChecked (checker, &ComboBoxListener::comboBoxChanged, this);
  37387. }
  37388. END_JUCE_NAMESPACE
  37389. /*** End of inlined file: juce_ComboBox.cpp ***/
  37390. /*** Start of inlined file: juce_Label.cpp ***/
  37391. BEGIN_JUCE_NAMESPACE
  37392. Label::Label (const String& componentName,
  37393. const String& labelText)
  37394. : Component (componentName),
  37395. textValue (labelText),
  37396. lastTextValue (labelText),
  37397. font (15.0f),
  37398. justification (Justification::centredLeft),
  37399. ownerComponent (0),
  37400. horizontalBorderSize (5),
  37401. verticalBorderSize (1),
  37402. minimumHorizontalScale (0.7f),
  37403. editSingleClick (false),
  37404. editDoubleClick (false),
  37405. lossOfFocusDiscardsChanges (false)
  37406. {
  37407. setColour (TextEditor::textColourId, Colours::black);
  37408. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37409. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37410. textValue.addListener (this);
  37411. }
  37412. Label::~Label()
  37413. {
  37414. textValue.removeListener (this);
  37415. if (ownerComponent != 0)
  37416. ownerComponent->removeComponentListener (this);
  37417. editor = 0;
  37418. }
  37419. void Label::setText (const String& newText,
  37420. const bool broadcastChangeMessage)
  37421. {
  37422. hideEditor (true);
  37423. if (lastTextValue != newText)
  37424. {
  37425. lastTextValue = newText;
  37426. textValue = newText;
  37427. repaint();
  37428. textWasChanged();
  37429. if (ownerComponent != 0)
  37430. componentMovedOrResized (*ownerComponent, true, true);
  37431. if (broadcastChangeMessage)
  37432. callChangeListeners();
  37433. }
  37434. }
  37435. const String Label::getText (const bool returnActiveEditorContents) const throw()
  37436. {
  37437. return (returnActiveEditorContents && isBeingEdited())
  37438. ? editor->getText()
  37439. : textValue.toString();
  37440. }
  37441. void Label::valueChanged (Value&)
  37442. {
  37443. if (lastTextValue != textValue.toString())
  37444. setText (textValue.toString(), true);
  37445. }
  37446. void Label::setFont (const Font& newFont) throw()
  37447. {
  37448. font = newFont;
  37449. repaint();
  37450. }
  37451. const Font& Label::getFont() const throw()
  37452. {
  37453. return font;
  37454. }
  37455. void Label::setEditable (const bool editOnSingleClick,
  37456. const bool editOnDoubleClick,
  37457. const bool lossOfFocusDiscardsChanges_) throw()
  37458. {
  37459. editSingleClick = editOnSingleClick;
  37460. editDoubleClick = editOnDoubleClick;
  37461. lossOfFocusDiscardsChanges = lossOfFocusDiscardsChanges_;
  37462. setWantsKeyboardFocus (editOnSingleClick || editOnDoubleClick);
  37463. setFocusContainer (editOnSingleClick || editOnDoubleClick);
  37464. }
  37465. void Label::setJustificationType (const Justification& justification_) throw()
  37466. {
  37467. justification = justification_;
  37468. repaint();
  37469. }
  37470. void Label::setBorderSize (int h, int v)
  37471. {
  37472. horizontalBorderSize = h;
  37473. verticalBorderSize = v;
  37474. repaint();
  37475. }
  37476. Component* Label::getAttachedComponent() const
  37477. {
  37478. return static_cast<Component*> (ownerComponent);
  37479. }
  37480. void Label::attachToComponent (Component* owner,
  37481. const bool onLeft)
  37482. {
  37483. if (ownerComponent != 0)
  37484. ownerComponent->removeComponentListener (this);
  37485. ownerComponent = owner;
  37486. leftOfOwnerComp = onLeft;
  37487. if (ownerComponent != 0)
  37488. {
  37489. setVisible (owner->isVisible());
  37490. ownerComponent->addComponentListener (this);
  37491. componentParentHierarchyChanged (*ownerComponent);
  37492. componentMovedOrResized (*ownerComponent, true, true);
  37493. }
  37494. }
  37495. void Label::componentMovedOrResized (Component& component,
  37496. bool /*wasMoved*/,
  37497. bool /*wasResized*/)
  37498. {
  37499. if (leftOfOwnerComp)
  37500. {
  37501. setSize (jmin (getFont().getStringWidth (textValue.toString()) + 8, component.getX()),
  37502. component.getHeight());
  37503. setTopRightPosition (component.getX(), component.getY());
  37504. }
  37505. else
  37506. {
  37507. setSize (component.getWidth(),
  37508. 8 + roundToInt (getFont().getHeight()));
  37509. setTopLeftPosition (component.getX(), component.getY() - getHeight());
  37510. }
  37511. }
  37512. void Label::componentParentHierarchyChanged (Component& component)
  37513. {
  37514. if (component.getParentComponent() != 0)
  37515. component.getParentComponent()->addChildComponent (this);
  37516. }
  37517. void Label::componentVisibilityChanged (Component& component)
  37518. {
  37519. setVisible (component.isVisible());
  37520. }
  37521. void Label::textWasEdited()
  37522. {
  37523. }
  37524. void Label::textWasChanged()
  37525. {
  37526. }
  37527. void Label::showEditor()
  37528. {
  37529. if (editor == 0)
  37530. {
  37531. addAndMakeVisible (editor = createEditorComponent());
  37532. editor->setText (getText(), false);
  37533. editor->addListener (this);
  37534. editor->grabKeyboardFocus();
  37535. editor->setHighlightedRegion (Range<int> (0, textValue.toString().length()));
  37536. editor->addListener (this);
  37537. resized();
  37538. repaint();
  37539. editorShown (editor);
  37540. enterModalState();
  37541. editor->grabKeyboardFocus();
  37542. }
  37543. }
  37544. void Label::editorShown (TextEditor* /*editorComponent*/)
  37545. {
  37546. }
  37547. void Label::editorAboutToBeHidden (TextEditor* /*editorComponent*/)
  37548. {
  37549. }
  37550. bool Label::updateFromTextEditorContents()
  37551. {
  37552. jassert (editor != 0);
  37553. const String newText (editor->getText());
  37554. if (textValue.toString() != newText)
  37555. {
  37556. lastTextValue = newText;
  37557. textValue = newText;
  37558. repaint();
  37559. textWasChanged();
  37560. if (ownerComponent != 0)
  37561. componentMovedOrResized (*ownerComponent, true, true);
  37562. return true;
  37563. }
  37564. return false;
  37565. }
  37566. void Label::hideEditor (const bool discardCurrentEditorContents)
  37567. {
  37568. if (editor != 0)
  37569. {
  37570. Component::SafePointer<Component> deletionChecker (this);
  37571. editorAboutToBeHidden (editor);
  37572. const bool changed = (! discardCurrentEditorContents)
  37573. && updateFromTextEditorContents();
  37574. editor = 0;
  37575. repaint();
  37576. if (changed)
  37577. textWasEdited();
  37578. if (deletionChecker != 0)
  37579. exitModalState (0);
  37580. if (changed && deletionChecker != 0)
  37581. callChangeListeners();
  37582. }
  37583. }
  37584. void Label::inputAttemptWhenModal()
  37585. {
  37586. if (editor != 0)
  37587. {
  37588. if (lossOfFocusDiscardsChanges)
  37589. textEditorEscapeKeyPressed (*editor);
  37590. else
  37591. textEditorReturnKeyPressed (*editor);
  37592. }
  37593. }
  37594. bool Label::isBeingEdited() const throw()
  37595. {
  37596. return editor != 0;
  37597. }
  37598. TextEditor* Label::createEditorComponent()
  37599. {
  37600. TextEditor* const ed = new TextEditor (getName());
  37601. ed->setFont (font);
  37602. // copy these colours from our own settings..
  37603. const int cols[] = { TextEditor::backgroundColourId,
  37604. TextEditor::textColourId,
  37605. TextEditor::highlightColourId,
  37606. TextEditor::highlightedTextColourId,
  37607. TextEditor::caretColourId,
  37608. TextEditor::outlineColourId,
  37609. TextEditor::focusedOutlineColourId,
  37610. TextEditor::shadowColourId };
  37611. for (int i = 0; i < numElementsInArray (cols); ++i)
  37612. ed->setColour (cols[i], findColour (cols[i]));
  37613. return ed;
  37614. }
  37615. void Label::paint (Graphics& g)
  37616. {
  37617. getLookAndFeel().drawLabel (g, *this);
  37618. }
  37619. void Label::mouseUp (const MouseEvent& e)
  37620. {
  37621. if (editSingleClick
  37622. && e.mouseWasClicked()
  37623. && contains (e.x, e.y)
  37624. && ! e.mods.isPopupMenu())
  37625. {
  37626. showEditor();
  37627. }
  37628. }
  37629. void Label::mouseDoubleClick (const MouseEvent& e)
  37630. {
  37631. if (editDoubleClick && ! e.mods.isPopupMenu())
  37632. showEditor();
  37633. }
  37634. void Label::resized()
  37635. {
  37636. if (editor != 0)
  37637. editor->setBoundsInset (BorderSize (0));
  37638. }
  37639. void Label::focusGained (FocusChangeType cause)
  37640. {
  37641. if (editSingleClick && cause == focusChangedByTabKey)
  37642. showEditor();
  37643. }
  37644. void Label::enablementChanged()
  37645. {
  37646. repaint();
  37647. }
  37648. void Label::colourChanged()
  37649. {
  37650. repaint();
  37651. }
  37652. void Label::setMinimumHorizontalScale (const float newScale)
  37653. {
  37654. if (minimumHorizontalScale != newScale)
  37655. {
  37656. minimumHorizontalScale = newScale;
  37657. repaint();
  37658. }
  37659. }
  37660. // We'll use a custom focus traverser here to make sure focus goes from the
  37661. // text editor to another component rather than back to the label itself.
  37662. class LabelKeyboardFocusTraverser : public KeyboardFocusTraverser
  37663. {
  37664. public:
  37665. LabelKeyboardFocusTraverser() {}
  37666. Component* getNextComponent (Component* current)
  37667. {
  37668. return KeyboardFocusTraverser::getNextComponent (dynamic_cast <TextEditor*> (current) != 0
  37669. ? current->getParentComponent() : current);
  37670. }
  37671. Component* getPreviousComponent (Component* current)
  37672. {
  37673. return KeyboardFocusTraverser::getPreviousComponent (dynamic_cast <TextEditor*> (current) != 0
  37674. ? current->getParentComponent() : current);
  37675. }
  37676. };
  37677. KeyboardFocusTraverser* Label::createFocusTraverser()
  37678. {
  37679. return new LabelKeyboardFocusTraverser();
  37680. }
  37681. void Label::addListener (LabelListener* const listener) throw()
  37682. {
  37683. listeners.add (listener);
  37684. }
  37685. void Label::removeListener (LabelListener* const listener) throw()
  37686. {
  37687. listeners.remove (listener);
  37688. }
  37689. void Label::callChangeListeners()
  37690. {
  37691. Component::BailOutChecker checker (this);
  37692. listeners.callChecked (checker, &LabelListener::labelTextChanged, this);
  37693. }
  37694. void Label::textEditorTextChanged (TextEditor& ed)
  37695. {
  37696. if (editor != 0)
  37697. {
  37698. jassert (&ed == editor);
  37699. if (! (hasKeyboardFocus (true) || isCurrentlyBlockedByAnotherModalComponent()))
  37700. {
  37701. if (lossOfFocusDiscardsChanges)
  37702. textEditorEscapeKeyPressed (ed);
  37703. else
  37704. textEditorReturnKeyPressed (ed);
  37705. }
  37706. }
  37707. }
  37708. void Label::textEditorReturnKeyPressed (TextEditor& ed)
  37709. {
  37710. if (editor != 0)
  37711. {
  37712. jassert (&ed == editor);
  37713. (void) ed;
  37714. const bool changed = updateFromTextEditorContents();
  37715. hideEditor (true);
  37716. if (changed)
  37717. {
  37718. Component::SafePointer<Component> deletionChecker (this);
  37719. textWasEdited();
  37720. if (deletionChecker != 0)
  37721. callChangeListeners();
  37722. }
  37723. }
  37724. }
  37725. void Label::textEditorEscapeKeyPressed (TextEditor& ed)
  37726. {
  37727. if (editor != 0)
  37728. {
  37729. jassert (&ed == editor);
  37730. (void) ed;
  37731. editor->setText (textValue.toString(), false);
  37732. hideEditor (true);
  37733. }
  37734. }
  37735. void Label::textEditorFocusLost (TextEditor& ed)
  37736. {
  37737. textEditorTextChanged (ed);
  37738. }
  37739. END_JUCE_NAMESPACE
  37740. /*** End of inlined file: juce_Label.cpp ***/
  37741. /*** Start of inlined file: juce_ListBox.cpp ***/
  37742. BEGIN_JUCE_NAMESPACE
  37743. class ListBoxRowComponent : public Component,
  37744. public TooltipClient
  37745. {
  37746. public:
  37747. ListBoxRowComponent (ListBox& owner_)
  37748. : owner (owner_),
  37749. row (-1),
  37750. selected (false),
  37751. isDragging (false)
  37752. {
  37753. }
  37754. ~ListBoxRowComponent()
  37755. {
  37756. deleteAllChildren();
  37757. }
  37758. void paint (Graphics& g)
  37759. {
  37760. if (owner.getModel() != 0)
  37761. owner.getModel()->paintListBoxItem (row, g, getWidth(), getHeight(), selected);
  37762. }
  37763. void update (const int row_, const bool selected_)
  37764. {
  37765. if (row != row_ || selected != selected_)
  37766. {
  37767. repaint();
  37768. row = row_;
  37769. selected = selected_;
  37770. }
  37771. if (owner.getModel() != 0)
  37772. {
  37773. Component* const customComp = owner.getModel()->refreshComponentForRow (row_, selected_, getChildComponent (0));
  37774. if (customComp != 0)
  37775. {
  37776. addAndMakeVisible (customComp);
  37777. customComp->setBounds (0, 0, getWidth(), getHeight());
  37778. for (int i = getNumChildComponents(); --i >= 0;)
  37779. if (getChildComponent (i) != customComp)
  37780. delete getChildComponent (i);
  37781. }
  37782. else
  37783. {
  37784. deleteAllChildren();
  37785. }
  37786. }
  37787. }
  37788. void mouseDown (const MouseEvent& e)
  37789. {
  37790. isDragging = false;
  37791. selectRowOnMouseUp = false;
  37792. if (isEnabled())
  37793. {
  37794. if (! selected)
  37795. {
  37796. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  37797. if (owner.getModel() != 0)
  37798. owner.getModel()->listBoxItemClicked (row, e);
  37799. }
  37800. else
  37801. {
  37802. selectRowOnMouseUp = true;
  37803. }
  37804. }
  37805. }
  37806. void mouseUp (const MouseEvent& e)
  37807. {
  37808. if (isEnabled() && selectRowOnMouseUp && ! isDragging)
  37809. {
  37810. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  37811. if (owner.getModel() != 0)
  37812. owner.getModel()->listBoxItemClicked (row, e);
  37813. }
  37814. }
  37815. void mouseDoubleClick (const MouseEvent& e)
  37816. {
  37817. if (owner.getModel() != 0 && isEnabled())
  37818. owner.getModel()->listBoxItemDoubleClicked (row, e);
  37819. }
  37820. void mouseDrag (const MouseEvent& e)
  37821. {
  37822. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  37823. {
  37824. const SparseSet <int> selectedRows (owner.getSelectedRows());
  37825. if (selectedRows.size() > 0)
  37826. {
  37827. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  37828. if (dragDescription.isNotEmpty())
  37829. {
  37830. isDragging = true;
  37831. owner.startDragAndDrop (e, dragDescription);
  37832. }
  37833. }
  37834. }
  37835. }
  37836. void resized()
  37837. {
  37838. if (getNumChildComponents() > 0)
  37839. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  37840. }
  37841. const String getTooltip()
  37842. {
  37843. if (owner.getModel() != 0)
  37844. return owner.getModel()->getTooltipForRow (row);
  37845. return String::empty;
  37846. }
  37847. juce_UseDebuggingNewOperator
  37848. bool neededFlag;
  37849. private:
  37850. ListBox& owner;
  37851. int row;
  37852. bool selected, isDragging, selectRowOnMouseUp;
  37853. ListBoxRowComponent (const ListBoxRowComponent&);
  37854. ListBoxRowComponent& operator= (const ListBoxRowComponent&);
  37855. };
  37856. class ListViewport : public Viewport
  37857. {
  37858. public:
  37859. int firstIndex, firstWholeIndex, lastWholeIndex;
  37860. bool hasUpdated;
  37861. ListViewport (ListBox& owner_)
  37862. : owner (owner_)
  37863. {
  37864. setWantsKeyboardFocus (false);
  37865. setViewedComponent (new Component());
  37866. getViewedComponent()->addMouseListener (this, false);
  37867. getViewedComponent()->setWantsKeyboardFocus (false);
  37868. }
  37869. ~ListViewport()
  37870. {
  37871. getViewedComponent()->removeMouseListener (this);
  37872. getViewedComponent()->deleteAllChildren();
  37873. }
  37874. ListBoxRowComponent* getComponentForRow (const int row) const throw()
  37875. {
  37876. return (ListBoxRowComponent*) getViewedComponent()
  37877. ->getChildComponent (row % jmax (1, getViewedComponent()->getNumChildComponents()));
  37878. }
  37879. int getRowNumberOfComponent (Component* const rowComponent) const throw()
  37880. {
  37881. const int index = getIndexOfChildComponent (rowComponent);
  37882. const int num = getViewedComponent()->getNumChildComponents();
  37883. for (int i = num; --i >= 0;)
  37884. if (((firstIndex + i) % jmax (1, num)) == index)
  37885. return firstIndex + i;
  37886. return -1;
  37887. }
  37888. Component* getComponentForRowIfOnscreen (const int row) const throw()
  37889. {
  37890. return (row >= firstIndex && row < firstIndex + getViewedComponent()->getNumChildComponents())
  37891. ? getComponentForRow (row) : 0;
  37892. }
  37893. void visibleAreaChanged (int, int, int, int)
  37894. {
  37895. updateVisibleArea (true);
  37896. if (owner.getModel() != 0)
  37897. owner.getModel()->listWasScrolled();
  37898. }
  37899. void updateVisibleArea (const bool makeSureItUpdatesContent)
  37900. {
  37901. hasUpdated = false;
  37902. const int newX = getViewedComponent()->getX();
  37903. int newY = getViewedComponent()->getY();
  37904. const int newW = jmax (owner.minimumRowWidth, getMaximumVisibleWidth());
  37905. const int newH = owner.totalItems * owner.getRowHeight();
  37906. if (newY + newH < getMaximumVisibleHeight() && newH > getMaximumVisibleHeight())
  37907. newY = getMaximumVisibleHeight() - newH;
  37908. getViewedComponent()->setBounds (newX, newY, newW, newH);
  37909. if (makeSureItUpdatesContent && ! hasUpdated)
  37910. updateContents();
  37911. }
  37912. void updateContents()
  37913. {
  37914. hasUpdated = true;
  37915. const int rowHeight = owner.getRowHeight();
  37916. if (rowHeight > 0)
  37917. {
  37918. const int y = getViewPositionY();
  37919. const int w = getViewedComponent()->getWidth();
  37920. const int numNeeded = 2 + getMaximumVisibleHeight() / rowHeight;
  37921. while (numNeeded > getViewedComponent()->getNumChildComponents())
  37922. getViewedComponent()->addAndMakeVisible (new ListBoxRowComponent (owner));
  37923. jassert (numNeeded >= 0);
  37924. while (numNeeded < getViewedComponent()->getNumChildComponents())
  37925. {
  37926. Component* const rowToRemove
  37927. = getViewedComponent()->getChildComponent (getViewedComponent()->getNumChildComponents() - 1);
  37928. delete rowToRemove;
  37929. }
  37930. firstIndex = y / rowHeight;
  37931. firstWholeIndex = (y + rowHeight - 1) / rowHeight;
  37932. lastWholeIndex = (y + getMaximumVisibleHeight() - 1) / rowHeight;
  37933. for (int i = 0; i < numNeeded; ++i)
  37934. {
  37935. const int row = i + firstIndex;
  37936. ListBoxRowComponent* const rowComp = getComponentForRow (row);
  37937. if (rowComp != 0)
  37938. {
  37939. rowComp->setBounds (0, row * rowHeight, w, rowHeight);
  37940. rowComp->update (row, owner.isRowSelected (row));
  37941. }
  37942. }
  37943. }
  37944. if (owner.headerComponent != 0)
  37945. owner.headerComponent->setBounds (owner.outlineThickness + getViewedComponent()->getX(),
  37946. owner.outlineThickness,
  37947. jmax (owner.getWidth() - owner.outlineThickness * 2,
  37948. getViewedComponent()->getWidth()),
  37949. owner.headerComponent->getHeight());
  37950. }
  37951. void paint (Graphics& g)
  37952. {
  37953. if (isOpaque())
  37954. g.fillAll (owner.findColour (ListBox::backgroundColourId));
  37955. }
  37956. bool keyPressed (const KeyPress& key)
  37957. {
  37958. if (key.isKeyCode (KeyPress::upKey)
  37959. || key.isKeyCode (KeyPress::downKey)
  37960. || key.isKeyCode (KeyPress::pageUpKey)
  37961. || key.isKeyCode (KeyPress::pageDownKey)
  37962. || key.isKeyCode (KeyPress::homeKey)
  37963. || key.isKeyCode (KeyPress::endKey))
  37964. {
  37965. // we want to avoid these keypresses going to the viewport, and instead allow
  37966. // them to pass up to our listbox..
  37967. return false;
  37968. }
  37969. return Viewport::keyPressed (key);
  37970. }
  37971. juce_UseDebuggingNewOperator
  37972. private:
  37973. ListBox& owner;
  37974. ListViewport (const ListViewport&);
  37975. ListViewport& operator= (const ListViewport&);
  37976. };
  37977. ListBox::ListBox (const String& name, ListBoxModel* const model_)
  37978. : Component (name),
  37979. model (model_),
  37980. headerComponent (0),
  37981. totalItems (0),
  37982. rowHeight (22),
  37983. minimumRowWidth (0),
  37984. outlineThickness (0),
  37985. lastRowSelected (-1),
  37986. mouseMoveSelects (false),
  37987. multipleSelection (false),
  37988. hasDoneInitialUpdate (false)
  37989. {
  37990. addAndMakeVisible (viewport = new ListViewport (*this));
  37991. setWantsKeyboardFocus (true);
  37992. colourChanged();
  37993. }
  37994. ListBox::~ListBox()
  37995. {
  37996. deleteAllChildren();
  37997. }
  37998. void ListBox::setModel (ListBoxModel* const newModel)
  37999. {
  38000. if (model != newModel)
  38001. {
  38002. model = newModel;
  38003. updateContent();
  38004. }
  38005. }
  38006. void ListBox::setMultipleSelectionEnabled (bool b)
  38007. {
  38008. multipleSelection = b;
  38009. }
  38010. void ListBox::setMouseMoveSelectsRows (bool b)
  38011. {
  38012. mouseMoveSelects = b;
  38013. if (b)
  38014. addMouseListener (this, true);
  38015. }
  38016. void ListBox::paint (Graphics& g)
  38017. {
  38018. if (! hasDoneInitialUpdate)
  38019. updateContent();
  38020. g.fillAll (findColour (backgroundColourId));
  38021. }
  38022. void ListBox::paintOverChildren (Graphics& g)
  38023. {
  38024. if (outlineThickness > 0)
  38025. {
  38026. g.setColour (findColour (outlineColourId));
  38027. g.drawRect (0, 0, getWidth(), getHeight(), outlineThickness);
  38028. }
  38029. }
  38030. void ListBox::resized()
  38031. {
  38032. viewport->setBoundsInset (BorderSize (outlineThickness + ((headerComponent != 0) ? headerComponent->getHeight() : 0),
  38033. outlineThickness,
  38034. outlineThickness,
  38035. outlineThickness));
  38036. viewport->setSingleStepSizes (20, getRowHeight());
  38037. viewport->updateVisibleArea (false);
  38038. }
  38039. void ListBox::visibilityChanged()
  38040. {
  38041. viewport->updateVisibleArea (true);
  38042. }
  38043. Viewport* ListBox::getViewport() const throw()
  38044. {
  38045. return viewport;
  38046. }
  38047. void ListBox::updateContent()
  38048. {
  38049. hasDoneInitialUpdate = true;
  38050. totalItems = (model != 0) ? model->getNumRows() : 0;
  38051. bool selectionChanged = false;
  38052. if (selected [selected.size() - 1] >= totalItems)
  38053. {
  38054. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38055. lastRowSelected = getSelectedRow (0);
  38056. selectionChanged = true;
  38057. }
  38058. viewport->updateVisibleArea (isVisible());
  38059. viewport->resized();
  38060. if (selectionChanged && model != 0)
  38061. model->selectedRowsChanged (lastRowSelected);
  38062. }
  38063. void ListBox::selectRow (const int row,
  38064. bool dontScroll,
  38065. bool deselectOthersFirst)
  38066. {
  38067. selectRowInternal (row, dontScroll, deselectOthersFirst, false);
  38068. }
  38069. void ListBox::selectRowInternal (const int row,
  38070. bool dontScroll,
  38071. bool deselectOthersFirst,
  38072. bool isMouseClick)
  38073. {
  38074. if (! multipleSelection)
  38075. deselectOthersFirst = true;
  38076. if ((! isRowSelected (row))
  38077. || (deselectOthersFirst && getNumSelectedRows() > 1))
  38078. {
  38079. if (((unsigned int) row) < (unsigned int) totalItems)
  38080. {
  38081. if (deselectOthersFirst)
  38082. selected.clear();
  38083. selected.addRange (row, 1);
  38084. if (getHeight() == 0 || getWidth() == 0)
  38085. dontScroll = true;
  38086. viewport->hasUpdated = false;
  38087. if (row < viewport->firstWholeIndex && ! dontScroll)
  38088. {
  38089. viewport->setViewPosition (viewport->getViewPositionX(),
  38090. row * getRowHeight());
  38091. }
  38092. else if (row >= viewport->lastWholeIndex && ! dontScroll)
  38093. {
  38094. const int rowsOnScreen = viewport->lastWholeIndex - viewport->firstWholeIndex;
  38095. if (row >= lastRowSelected + rowsOnScreen
  38096. && rowsOnScreen < totalItems - 1
  38097. && ! isMouseClick)
  38098. {
  38099. viewport->setViewPosition (viewport->getViewPositionX(),
  38100. jlimit (0, jmax (0, totalItems - rowsOnScreen), row)
  38101. * getRowHeight());
  38102. }
  38103. else
  38104. {
  38105. viewport->setViewPosition (viewport->getViewPositionX(),
  38106. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38107. }
  38108. }
  38109. if (! viewport->hasUpdated)
  38110. viewport->updateContents();
  38111. lastRowSelected = row;
  38112. model->selectedRowsChanged (row);
  38113. }
  38114. else
  38115. {
  38116. if (deselectOthersFirst)
  38117. deselectAllRows();
  38118. }
  38119. }
  38120. }
  38121. void ListBox::deselectRow (const int row)
  38122. {
  38123. if (selected.contains (row))
  38124. {
  38125. selected.removeRange (row, 1);
  38126. if (row == lastRowSelected)
  38127. lastRowSelected = getSelectedRow (0);
  38128. viewport->updateContents();
  38129. model->selectedRowsChanged (lastRowSelected);
  38130. }
  38131. }
  38132. void ListBox::setSelectedRows (const SparseSet<int>& setOfRowsToBeSelected,
  38133. const bool sendNotificationEventToModel)
  38134. {
  38135. selected = setOfRowsToBeSelected;
  38136. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38137. if (! isRowSelected (lastRowSelected))
  38138. lastRowSelected = getSelectedRow (0);
  38139. viewport->updateContents();
  38140. if ((model != 0) && sendNotificationEventToModel)
  38141. model->selectedRowsChanged (lastRowSelected);
  38142. }
  38143. const SparseSet<int> ListBox::getSelectedRows() const
  38144. {
  38145. return selected;
  38146. }
  38147. void ListBox::selectRangeOfRows (int firstRow, int lastRow)
  38148. {
  38149. if (multipleSelection && (firstRow != lastRow))
  38150. {
  38151. const int numRows = totalItems - 1;
  38152. firstRow = jlimit (0, jmax (0, numRows), firstRow);
  38153. lastRow = jlimit (0, jmax (0, numRows), lastRow);
  38154. selected.addRange (jmin (firstRow, lastRow),
  38155. abs (firstRow - lastRow) + 1);
  38156. selected.removeRange (lastRow, 1);
  38157. }
  38158. selectRowInternal (lastRow, false, false, true);
  38159. }
  38160. void ListBox::flipRowSelection (const int row)
  38161. {
  38162. if (isRowSelected (row))
  38163. deselectRow (row);
  38164. else
  38165. selectRowInternal (row, false, false, true);
  38166. }
  38167. void ListBox::deselectAllRows()
  38168. {
  38169. if (! selected.isEmpty())
  38170. {
  38171. selected.clear();
  38172. lastRowSelected = -1;
  38173. viewport->updateContents();
  38174. if (model != 0)
  38175. model->selectedRowsChanged (lastRowSelected);
  38176. }
  38177. }
  38178. void ListBox::selectRowsBasedOnModifierKeys (const int row,
  38179. const ModifierKeys& mods)
  38180. {
  38181. if (multipleSelection && mods.isCommandDown())
  38182. {
  38183. flipRowSelection (row);
  38184. }
  38185. else if (multipleSelection && mods.isShiftDown() && lastRowSelected >= 0)
  38186. {
  38187. selectRangeOfRows (lastRowSelected, row);
  38188. }
  38189. else if ((! mods.isPopupMenu()) || ! isRowSelected (row))
  38190. {
  38191. selectRowInternal (row, false, true, true);
  38192. }
  38193. }
  38194. int ListBox::getNumSelectedRows() const
  38195. {
  38196. return selected.size();
  38197. }
  38198. int ListBox::getSelectedRow (const int index) const
  38199. {
  38200. return (((unsigned int) index) < (unsigned int) selected.size())
  38201. ? selected [index] : -1;
  38202. }
  38203. bool ListBox::isRowSelected (const int row) const
  38204. {
  38205. return selected.contains (row);
  38206. }
  38207. int ListBox::getLastRowSelected() const
  38208. {
  38209. return (isRowSelected (lastRowSelected)) ? lastRowSelected : -1;
  38210. }
  38211. int ListBox::getRowContainingPosition (const int x, const int y) const throw()
  38212. {
  38213. if (((unsigned int) x) < (unsigned int) getWidth())
  38214. {
  38215. const int row = (viewport->getViewPositionY() + y - viewport->getY()) / rowHeight;
  38216. if (((unsigned int) row) < (unsigned int) totalItems)
  38217. return row;
  38218. }
  38219. return -1;
  38220. }
  38221. int ListBox::getInsertionIndexForPosition (const int x, const int y) const throw()
  38222. {
  38223. if (((unsigned int) x) < (unsigned int) getWidth())
  38224. {
  38225. const int row = (viewport->getViewPositionY() + y + rowHeight / 2 - viewport->getY()) / rowHeight;
  38226. return jlimit (0, totalItems, row);
  38227. }
  38228. return -1;
  38229. }
  38230. Component* ListBox::getComponentForRowNumber (const int row) const throw()
  38231. {
  38232. Component* const listRowComp = viewport->getComponentForRowIfOnscreen (row);
  38233. return listRowComp != 0 ? listRowComp->getChildComponent (0) : 0;
  38234. }
  38235. int ListBox::getRowNumberOfComponent (Component* const rowComponent) const throw()
  38236. {
  38237. return viewport->getRowNumberOfComponent (rowComponent);
  38238. }
  38239. const Rectangle<int> ListBox::getRowPosition (const int rowNumber,
  38240. const bool relativeToComponentTopLeft) const throw()
  38241. {
  38242. const int rowHeight = getRowHeight();
  38243. int y = viewport->getY() + rowHeight * rowNumber;
  38244. if (relativeToComponentTopLeft)
  38245. y -= viewport->getViewPositionY();
  38246. return Rectangle<int> (viewport->getX(), y,
  38247. viewport->getViewedComponent()->getWidth(), rowHeight);
  38248. }
  38249. void ListBox::setVerticalPosition (const double proportion)
  38250. {
  38251. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38252. viewport->setViewPosition (viewport->getViewPositionX(),
  38253. jmax (0, roundToInt (proportion * offscreen)));
  38254. }
  38255. double ListBox::getVerticalPosition() const
  38256. {
  38257. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38258. return (offscreen > 0) ? viewport->getViewPositionY() / (double) offscreen
  38259. : 0;
  38260. }
  38261. int ListBox::getVisibleRowWidth() const throw()
  38262. {
  38263. return viewport->getViewWidth();
  38264. }
  38265. void ListBox::scrollToEnsureRowIsOnscreen (const int row)
  38266. {
  38267. if (row < viewport->firstWholeIndex)
  38268. {
  38269. viewport->setViewPosition (viewport->getViewPositionX(),
  38270. row * getRowHeight());
  38271. }
  38272. else if (row >= viewport->lastWholeIndex)
  38273. {
  38274. viewport->setViewPosition (viewport->getViewPositionX(),
  38275. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38276. }
  38277. }
  38278. bool ListBox::keyPressed (const KeyPress& key)
  38279. {
  38280. const int numVisibleRows = viewport->getHeight() / getRowHeight();
  38281. const bool multiple = multipleSelection
  38282. && (lastRowSelected >= 0)
  38283. && (key.getModifiers().isShiftDown()
  38284. || key.getModifiers().isCtrlDown()
  38285. || key.getModifiers().isCommandDown());
  38286. if (key.isKeyCode (KeyPress::upKey))
  38287. {
  38288. if (multiple)
  38289. selectRangeOfRows (lastRowSelected, lastRowSelected - 1);
  38290. else
  38291. selectRow (jmax (0, lastRowSelected - 1));
  38292. }
  38293. else if (key.isKeyCode (KeyPress::returnKey)
  38294. && isRowSelected (lastRowSelected))
  38295. {
  38296. if (model != 0)
  38297. model->returnKeyPressed (lastRowSelected);
  38298. }
  38299. else if (key.isKeyCode (KeyPress::pageUpKey))
  38300. {
  38301. if (multiple)
  38302. selectRangeOfRows (lastRowSelected, lastRowSelected - numVisibleRows);
  38303. else
  38304. selectRow (jmax (0, jmax (0, lastRowSelected) - numVisibleRows));
  38305. }
  38306. else if (key.isKeyCode (KeyPress::pageDownKey))
  38307. {
  38308. if (multiple)
  38309. selectRangeOfRows (lastRowSelected, lastRowSelected + numVisibleRows);
  38310. else
  38311. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + numVisibleRows));
  38312. }
  38313. else if (key.isKeyCode (KeyPress::homeKey))
  38314. {
  38315. if (multiple && key.getModifiers().isShiftDown())
  38316. selectRangeOfRows (lastRowSelected, 0);
  38317. else
  38318. selectRow (0);
  38319. }
  38320. else if (key.isKeyCode (KeyPress::endKey))
  38321. {
  38322. if (multiple && key.getModifiers().isShiftDown())
  38323. selectRangeOfRows (lastRowSelected, totalItems - 1);
  38324. else
  38325. selectRow (totalItems - 1);
  38326. }
  38327. else if (key.isKeyCode (KeyPress::downKey))
  38328. {
  38329. if (multiple)
  38330. selectRangeOfRows (lastRowSelected, lastRowSelected + 1);
  38331. else
  38332. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + 1));
  38333. }
  38334. else if ((key.isKeyCode (KeyPress::deleteKey) || key.isKeyCode (KeyPress::backspaceKey))
  38335. && isRowSelected (lastRowSelected))
  38336. {
  38337. if (model != 0)
  38338. model->deleteKeyPressed (lastRowSelected);
  38339. }
  38340. else if (multiple && key == KeyPress ('a', ModifierKeys::commandModifier, 0))
  38341. {
  38342. selectRangeOfRows (0, std::numeric_limits<int>::max());
  38343. }
  38344. else
  38345. {
  38346. return false;
  38347. }
  38348. return true;
  38349. }
  38350. bool ListBox::keyStateChanged (const bool isKeyDown)
  38351. {
  38352. return isKeyDown
  38353. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  38354. || KeyPress::isKeyCurrentlyDown (KeyPress::pageUpKey)
  38355. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  38356. || KeyPress::isKeyCurrentlyDown (KeyPress::pageDownKey)
  38357. || KeyPress::isKeyCurrentlyDown (KeyPress::homeKey)
  38358. || KeyPress::isKeyCurrentlyDown (KeyPress::endKey)
  38359. || KeyPress::isKeyCurrentlyDown (KeyPress::returnKey));
  38360. }
  38361. void ListBox::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  38362. {
  38363. getHorizontalScrollBar()->mouseWheelMove (e, wheelIncrementX, 0);
  38364. getVerticalScrollBar()->mouseWheelMove (e, 0, wheelIncrementY);
  38365. }
  38366. void ListBox::mouseMove (const MouseEvent& e)
  38367. {
  38368. if (mouseMoveSelects)
  38369. {
  38370. const MouseEvent e2 (e.getEventRelativeTo (this));
  38371. selectRow (getRowContainingPosition (e2.x, e2.y), true);
  38372. }
  38373. }
  38374. void ListBox::mouseExit (const MouseEvent& e)
  38375. {
  38376. mouseMove (e);
  38377. }
  38378. void ListBox::mouseUp (const MouseEvent& e)
  38379. {
  38380. if (e.mouseWasClicked() && model != 0)
  38381. model->backgroundClicked();
  38382. }
  38383. void ListBox::setRowHeight (const int newHeight)
  38384. {
  38385. rowHeight = jmax (1, newHeight);
  38386. viewport->setSingleStepSizes (20, rowHeight);
  38387. updateContent();
  38388. }
  38389. int ListBox::getNumRowsOnScreen() const throw()
  38390. {
  38391. return viewport->getMaximumVisibleHeight() / rowHeight;
  38392. }
  38393. void ListBox::setMinimumContentWidth (const int newMinimumWidth)
  38394. {
  38395. minimumRowWidth = newMinimumWidth;
  38396. updateContent();
  38397. }
  38398. int ListBox::getVisibleContentWidth() const throw()
  38399. {
  38400. return viewport->getMaximumVisibleWidth();
  38401. }
  38402. ScrollBar* ListBox::getVerticalScrollBar() const throw()
  38403. {
  38404. return viewport->getVerticalScrollBar();
  38405. }
  38406. ScrollBar* ListBox::getHorizontalScrollBar() const throw()
  38407. {
  38408. return viewport->getHorizontalScrollBar();
  38409. }
  38410. void ListBox::colourChanged()
  38411. {
  38412. setOpaque (findColour (backgroundColourId).isOpaque());
  38413. viewport->setOpaque (isOpaque());
  38414. repaint();
  38415. }
  38416. void ListBox::setOutlineThickness (const int outlineThickness_)
  38417. {
  38418. outlineThickness = outlineThickness_;
  38419. resized();
  38420. }
  38421. void ListBox::setHeaderComponent (Component* const newHeaderComponent)
  38422. {
  38423. if (headerComponent != newHeaderComponent)
  38424. {
  38425. delete headerComponent;
  38426. headerComponent = newHeaderComponent;
  38427. addAndMakeVisible (newHeaderComponent);
  38428. ListBox::resized();
  38429. }
  38430. }
  38431. void ListBox::repaintRow (const int rowNumber) throw()
  38432. {
  38433. const Rectangle<int> r (getRowPosition (rowNumber, true));
  38434. repaint (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  38435. }
  38436. Image* ListBox::createSnapshotOfSelectedRows (int& imageX, int& imageY)
  38437. {
  38438. Rectangle<int> imageArea;
  38439. const int firstRow = getRowContainingPosition (0, 0);
  38440. int i;
  38441. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38442. {
  38443. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38444. if (rowComp != 0 && isRowSelected (firstRow + i))
  38445. {
  38446. const Point<int> pos (rowComp->relativePositionToOtherComponent (this, Point<int>()));
  38447. const Rectangle<int> rowRect (pos.getX(), pos.getY(), rowComp->getWidth(), rowComp->getHeight());
  38448. if (imageArea.isEmpty())
  38449. imageArea = rowRect;
  38450. else
  38451. imageArea = imageArea.getUnion (rowRect);
  38452. }
  38453. }
  38454. imageArea = imageArea.getIntersection (Rectangle<int> (0, 0, getWidth(), getHeight()));
  38455. imageX = imageArea.getX();
  38456. imageY = imageArea.getY();
  38457. Image* snapshot = Image::createNativeImage (Image::ARGB, imageArea.getWidth(), imageArea.getHeight(), true);
  38458. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38459. {
  38460. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38461. if (rowComp != 0 && isRowSelected (firstRow + i))
  38462. {
  38463. const Point<int> pos (rowComp->relativePositionToOtherComponent (this, Point<int>()));
  38464. Graphics g (*snapshot);
  38465. g.setOrigin (pos.getX() - imageX, pos.getY() - imageY);
  38466. if (g.reduceClipRegion (0, 0, rowComp->getWidth(), rowComp->getHeight()))
  38467. rowComp->paintEntireComponent (g);
  38468. }
  38469. }
  38470. return snapshot;
  38471. }
  38472. void ListBox::startDragAndDrop (const MouseEvent& e, const String& dragDescription)
  38473. {
  38474. DragAndDropContainer* const dragContainer
  38475. = DragAndDropContainer::findParentDragContainerFor (this);
  38476. if (dragContainer != 0)
  38477. {
  38478. int x, y;
  38479. Image* dragImage = createSnapshotOfSelectedRows (x, y);
  38480. dragImage->multiplyAllAlphas (0.6f);
  38481. MouseEvent e2 (e.getEventRelativeTo (this));
  38482. const Point<int> p (x - e2.x, y - e2.y);
  38483. dragContainer->startDragging (dragDescription, this, dragImage, true, &p);
  38484. }
  38485. else
  38486. {
  38487. // to be able to do a drag-and-drop operation, the listbox needs to
  38488. // be inside a component which is also a DragAndDropContainer.
  38489. jassertfalse
  38490. }
  38491. }
  38492. Component* ListBoxModel::refreshComponentForRow (int, bool, Component* existingComponentToUpdate)
  38493. {
  38494. (void) existingComponentToUpdate;
  38495. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  38496. return 0;
  38497. }
  38498. void ListBoxModel::listBoxItemClicked (int, const MouseEvent&)
  38499. {
  38500. }
  38501. void ListBoxModel::listBoxItemDoubleClicked (int, const MouseEvent&)
  38502. {
  38503. }
  38504. void ListBoxModel::backgroundClicked()
  38505. {
  38506. }
  38507. void ListBoxModel::selectedRowsChanged (int)
  38508. {
  38509. }
  38510. void ListBoxModel::deleteKeyPressed (int)
  38511. {
  38512. }
  38513. void ListBoxModel::returnKeyPressed (int)
  38514. {
  38515. }
  38516. void ListBoxModel::listWasScrolled()
  38517. {
  38518. }
  38519. const String ListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  38520. {
  38521. return String::empty;
  38522. }
  38523. const String ListBoxModel::getTooltipForRow (int)
  38524. {
  38525. return String::empty;
  38526. }
  38527. END_JUCE_NAMESPACE
  38528. /*** End of inlined file: juce_ListBox.cpp ***/
  38529. /*** Start of inlined file: juce_ProgressBar.cpp ***/
  38530. BEGIN_JUCE_NAMESPACE
  38531. ProgressBar::ProgressBar (double& progress_)
  38532. : progress (progress_),
  38533. displayPercentage (true),
  38534. lastCallbackTime (0)
  38535. {
  38536. currentValue = jlimit (0.0, 1.0, progress);
  38537. }
  38538. ProgressBar::~ProgressBar()
  38539. {
  38540. }
  38541. void ProgressBar::setPercentageDisplay (const bool shouldDisplayPercentage)
  38542. {
  38543. displayPercentage = shouldDisplayPercentage;
  38544. repaint();
  38545. }
  38546. void ProgressBar::setTextToDisplay (const String& text)
  38547. {
  38548. displayPercentage = false;
  38549. displayedMessage = text;
  38550. }
  38551. void ProgressBar::lookAndFeelChanged()
  38552. {
  38553. setOpaque (findColour (backgroundColourId).isOpaque());
  38554. }
  38555. void ProgressBar::colourChanged()
  38556. {
  38557. lookAndFeelChanged();
  38558. }
  38559. void ProgressBar::paint (Graphics& g)
  38560. {
  38561. String text;
  38562. if (displayPercentage)
  38563. {
  38564. if (currentValue >= 0 && currentValue <= 1.0)
  38565. text << roundToInt (currentValue * 100.0) << '%';
  38566. }
  38567. else
  38568. {
  38569. text = displayedMessage;
  38570. }
  38571. getLookAndFeel().drawProgressBar (g, *this,
  38572. getWidth(), getHeight(),
  38573. currentValue, text);
  38574. }
  38575. void ProgressBar::visibilityChanged()
  38576. {
  38577. if (isVisible())
  38578. startTimer (30);
  38579. else
  38580. stopTimer();
  38581. }
  38582. void ProgressBar::timerCallback()
  38583. {
  38584. double newProgress = progress;
  38585. const uint32 now = Time::getMillisecondCounter();
  38586. const int timeSinceLastCallback = (int) (now - lastCallbackTime);
  38587. lastCallbackTime = now;
  38588. if (currentValue != newProgress
  38589. || newProgress < 0 || newProgress >= 1.0
  38590. || currentMessage != displayedMessage)
  38591. {
  38592. if (currentValue < newProgress
  38593. && newProgress >= 0 && newProgress < 1.0
  38594. && currentValue >= 0 && currentValue < 1.0)
  38595. {
  38596. newProgress = jmin (currentValue + 0.0008 * timeSinceLastCallback,
  38597. newProgress);
  38598. }
  38599. currentValue = newProgress;
  38600. currentMessage = displayedMessage;
  38601. repaint();
  38602. }
  38603. }
  38604. END_JUCE_NAMESPACE
  38605. /*** End of inlined file: juce_ProgressBar.cpp ***/
  38606. /*** Start of inlined file: juce_Slider.cpp ***/
  38607. BEGIN_JUCE_NAMESPACE
  38608. class SliderPopupDisplayComponent : public BubbleComponent
  38609. {
  38610. public:
  38611. SliderPopupDisplayComponent (Slider* const owner_)
  38612. : owner (owner_),
  38613. font (15.0f, Font::bold)
  38614. {
  38615. setAlwaysOnTop (true);
  38616. }
  38617. ~SliderPopupDisplayComponent()
  38618. {
  38619. }
  38620. void paintContent (Graphics& g, int w, int h)
  38621. {
  38622. g.setFont (font);
  38623. g.setColour (Colours::black);
  38624. g.drawFittedText (text, 0, 0, w, h, Justification::centred, 1);
  38625. }
  38626. void getContentSize (int& w, int& h)
  38627. {
  38628. w = font.getStringWidth (text) + 18;
  38629. h = (int) (font.getHeight() * 1.6f);
  38630. }
  38631. void updatePosition (const String& newText)
  38632. {
  38633. if (text != newText)
  38634. {
  38635. text = newText;
  38636. repaint();
  38637. }
  38638. BubbleComponent::setPosition (owner);
  38639. }
  38640. juce_UseDebuggingNewOperator
  38641. private:
  38642. Slider* owner;
  38643. Font font;
  38644. String text;
  38645. SliderPopupDisplayComponent (const SliderPopupDisplayComponent&);
  38646. SliderPopupDisplayComponent& operator= (const SliderPopupDisplayComponent&);
  38647. };
  38648. Slider::Slider (const String& name)
  38649. : Component (name),
  38650. lastCurrentValue (0),
  38651. lastValueMin (0),
  38652. lastValueMax (0),
  38653. minimum (0),
  38654. maximum (10),
  38655. interval (0),
  38656. skewFactor (1.0),
  38657. velocityModeSensitivity (1.0),
  38658. velocityModeOffset (0.0),
  38659. velocityModeThreshold (1),
  38660. rotaryStart (float_Pi * 1.2f),
  38661. rotaryEnd (float_Pi * 2.8f),
  38662. numDecimalPlaces (7),
  38663. sliderRegionStart (0),
  38664. sliderRegionSize (1),
  38665. sliderBeingDragged (-1),
  38666. pixelsForFullDragExtent (250),
  38667. style (LinearHorizontal),
  38668. textBoxPos (TextBoxLeft),
  38669. textBoxWidth (80),
  38670. textBoxHeight (20),
  38671. incDecButtonMode (incDecButtonsNotDraggable),
  38672. editableText (true),
  38673. doubleClickToValue (false),
  38674. isVelocityBased (false),
  38675. userKeyOverridesVelocity (true),
  38676. rotaryStop (true),
  38677. incDecButtonsSideBySide (false),
  38678. sendChangeOnlyOnRelease (false),
  38679. popupDisplayEnabled (false),
  38680. menuEnabled (false),
  38681. menuShown (false),
  38682. scrollWheelEnabled (true),
  38683. snapsToMousePos (true),
  38684. valueBox (0),
  38685. incButton (0),
  38686. decButton (0),
  38687. popupDisplay (0),
  38688. parentForPopupDisplay (0)
  38689. {
  38690. setWantsKeyboardFocus (false);
  38691. setRepaintsOnMouseActivity (true);
  38692. lookAndFeelChanged();
  38693. updateText();
  38694. currentValue.addListener (this);
  38695. valueMin.addListener (this);
  38696. valueMax.addListener (this);
  38697. }
  38698. Slider::~Slider()
  38699. {
  38700. currentValue.removeListener (this);
  38701. valueMin.removeListener (this);
  38702. valueMax.removeListener (this);
  38703. popupDisplay = 0;
  38704. deleteAllChildren();
  38705. }
  38706. void Slider::handleAsyncUpdate()
  38707. {
  38708. cancelPendingUpdate();
  38709. Component::BailOutChecker checker (this);
  38710. listeners.callChecked (checker, &SliderListener::sliderValueChanged, this);
  38711. }
  38712. void Slider::sendDragStart()
  38713. {
  38714. startedDragging();
  38715. Component::BailOutChecker checker (this);
  38716. listeners.callChecked (checker, &SliderListener::sliderDragStarted, this);
  38717. }
  38718. void Slider::sendDragEnd()
  38719. {
  38720. stoppedDragging();
  38721. sliderBeingDragged = -1;
  38722. Component::BailOutChecker checker (this);
  38723. listeners.callChecked (checker, &SliderListener::sliderDragEnded, this);
  38724. }
  38725. void Slider::addListener (SliderListener* const listener)
  38726. {
  38727. listeners.add (listener);
  38728. }
  38729. void Slider::removeListener (SliderListener* const listener)
  38730. {
  38731. listeners.remove (listener);
  38732. }
  38733. void Slider::setSliderStyle (const SliderStyle newStyle)
  38734. {
  38735. if (style != newStyle)
  38736. {
  38737. style = newStyle;
  38738. repaint();
  38739. lookAndFeelChanged();
  38740. }
  38741. }
  38742. void Slider::setRotaryParameters (const float startAngleRadians,
  38743. const float endAngleRadians,
  38744. const bool stopAtEnd)
  38745. {
  38746. // make sure the values are sensible..
  38747. jassert (rotaryStart >= 0 && rotaryEnd >= 0);
  38748. jassert (rotaryStart < float_Pi * 4.0f && rotaryEnd < float_Pi * 4.0f);
  38749. jassert (rotaryStart < rotaryEnd);
  38750. rotaryStart = startAngleRadians;
  38751. rotaryEnd = endAngleRadians;
  38752. rotaryStop = stopAtEnd;
  38753. }
  38754. void Slider::setVelocityBasedMode (const bool velBased)
  38755. {
  38756. isVelocityBased = velBased;
  38757. }
  38758. void Slider::setVelocityModeParameters (const double sensitivity,
  38759. const int threshold,
  38760. const double offset,
  38761. const bool userCanPressKeyToSwapMode)
  38762. {
  38763. jassert (threshold >= 0);
  38764. jassert (sensitivity > 0);
  38765. jassert (offset >= 0);
  38766. velocityModeSensitivity = sensitivity;
  38767. velocityModeOffset = offset;
  38768. velocityModeThreshold = threshold;
  38769. userKeyOverridesVelocity = userCanPressKeyToSwapMode;
  38770. }
  38771. void Slider::setSkewFactor (const double factor)
  38772. {
  38773. skewFactor = factor;
  38774. }
  38775. void Slider::setSkewFactorFromMidPoint (const double sliderValueToShowAtMidPoint)
  38776. {
  38777. if (maximum > minimum)
  38778. skewFactor = log (0.5) / log ((sliderValueToShowAtMidPoint - minimum)
  38779. / (maximum - minimum));
  38780. }
  38781. void Slider::setMouseDragSensitivity (const int distanceForFullScaleDrag)
  38782. {
  38783. jassert (distanceForFullScaleDrag > 0);
  38784. pixelsForFullDragExtent = distanceForFullScaleDrag;
  38785. }
  38786. void Slider::setIncDecButtonsMode (const IncDecButtonMode mode)
  38787. {
  38788. if (incDecButtonMode != mode)
  38789. {
  38790. incDecButtonMode = mode;
  38791. lookAndFeelChanged();
  38792. }
  38793. }
  38794. void Slider::setTextBoxStyle (const TextEntryBoxPosition newPosition,
  38795. const bool isReadOnly,
  38796. const int textEntryBoxWidth,
  38797. const int textEntryBoxHeight)
  38798. {
  38799. textBoxPos = newPosition;
  38800. editableText = ! isReadOnly;
  38801. textBoxWidth = textEntryBoxWidth;
  38802. textBoxHeight = textEntryBoxHeight;
  38803. repaint();
  38804. lookAndFeelChanged();
  38805. }
  38806. void Slider::setTextBoxIsEditable (const bool shouldBeEditable)
  38807. {
  38808. editableText = shouldBeEditable;
  38809. if (valueBox != 0)
  38810. valueBox->setEditable (shouldBeEditable && isEnabled());
  38811. }
  38812. void Slider::showTextBox()
  38813. {
  38814. jassert (editableText); // this should probably be avoided in read-only sliders.
  38815. if (valueBox != 0)
  38816. valueBox->showEditor();
  38817. }
  38818. void Slider::hideTextBox (const bool discardCurrentEditorContents)
  38819. {
  38820. if (valueBox != 0)
  38821. {
  38822. valueBox->hideEditor (discardCurrentEditorContents);
  38823. if (discardCurrentEditorContents)
  38824. updateText();
  38825. }
  38826. }
  38827. void Slider::setChangeNotificationOnlyOnRelease (const bool onlyNotifyOnRelease)
  38828. {
  38829. sendChangeOnlyOnRelease = onlyNotifyOnRelease;
  38830. }
  38831. void Slider::setSliderSnapsToMousePosition (const bool shouldSnapToMouse)
  38832. {
  38833. snapsToMousePos = shouldSnapToMouse;
  38834. }
  38835. void Slider::setPopupDisplayEnabled (const bool enabled,
  38836. Component* const parentComponentToUse)
  38837. {
  38838. popupDisplayEnabled = enabled;
  38839. parentForPopupDisplay = parentComponentToUse;
  38840. }
  38841. void Slider::colourChanged()
  38842. {
  38843. lookAndFeelChanged();
  38844. }
  38845. void Slider::lookAndFeelChanged()
  38846. {
  38847. const String previousTextBoxContent (valueBox != 0 ? valueBox->getText()
  38848. : getTextFromValue (currentValue.getValue()));
  38849. deleteAllChildren();
  38850. valueBox = 0;
  38851. LookAndFeel& lf = getLookAndFeel();
  38852. if (textBoxPos != NoTextBox)
  38853. {
  38854. addAndMakeVisible (valueBox = getLookAndFeel().createSliderTextBox (*this));
  38855. valueBox->setWantsKeyboardFocus (false);
  38856. valueBox->setText (previousTextBoxContent, false);
  38857. valueBox->setEditable (editableText && isEnabled());
  38858. valueBox->addListener (this);
  38859. if (style == LinearBar)
  38860. valueBox->addMouseListener (this, false);
  38861. valueBox->setTooltip (getTooltip());
  38862. }
  38863. if (style == IncDecButtons)
  38864. {
  38865. addAndMakeVisible (incButton = lf.createSliderButton (true));
  38866. incButton->addButtonListener (this);
  38867. addAndMakeVisible (decButton = lf.createSliderButton (false));
  38868. decButton->addButtonListener (this);
  38869. if (incDecButtonMode != incDecButtonsNotDraggable)
  38870. {
  38871. incButton->addMouseListener (this, false);
  38872. decButton->addMouseListener (this, false);
  38873. }
  38874. else
  38875. {
  38876. incButton->setRepeatSpeed (300, 100, 20);
  38877. incButton->addMouseListener (decButton, false);
  38878. decButton->setRepeatSpeed (300, 100, 20);
  38879. decButton->addMouseListener (incButton, false);
  38880. }
  38881. incButton->setTooltip (getTooltip());
  38882. decButton->setTooltip (getTooltip());
  38883. }
  38884. setComponentEffect (lf.getSliderEffect());
  38885. resized();
  38886. repaint();
  38887. }
  38888. void Slider::setRange (const double newMin,
  38889. const double newMax,
  38890. const double newInt)
  38891. {
  38892. if (minimum != newMin
  38893. || maximum != newMax
  38894. || interval != newInt)
  38895. {
  38896. minimum = newMin;
  38897. maximum = newMax;
  38898. interval = newInt;
  38899. // figure out the number of DPs needed to display all values at this
  38900. // interval setting.
  38901. numDecimalPlaces = 7;
  38902. if (newInt != 0)
  38903. {
  38904. int v = abs ((int) (newInt * 10000000));
  38905. while ((v % 10) == 0)
  38906. {
  38907. --numDecimalPlaces;
  38908. v /= 10;
  38909. }
  38910. }
  38911. // keep the current values inside the new range..
  38912. if (style != TwoValueHorizontal && style != TwoValueVertical)
  38913. {
  38914. setValue (getValue(), false, false);
  38915. }
  38916. else
  38917. {
  38918. setMinValue (getMinValue(), false, false);
  38919. setMaxValue (getMaxValue(), false, false);
  38920. }
  38921. updateText();
  38922. }
  38923. }
  38924. void Slider::triggerChangeMessage (const bool synchronous)
  38925. {
  38926. if (synchronous)
  38927. handleAsyncUpdate();
  38928. else
  38929. triggerAsyncUpdate();
  38930. valueChanged();
  38931. }
  38932. void Slider::valueChanged (Value& value)
  38933. {
  38934. if (value.refersToSameSourceAs (currentValue))
  38935. {
  38936. if (style != TwoValueHorizontal && style != TwoValueVertical)
  38937. setValue (currentValue.getValue(), false, false);
  38938. }
  38939. else if (value.refersToSameSourceAs (valueMin))
  38940. setMinValue (valueMin.getValue(), false, false, true);
  38941. else if (value.refersToSameSourceAs (valueMax))
  38942. setMaxValue (valueMax.getValue(), false, false, true);
  38943. }
  38944. double Slider::getValue() const
  38945. {
  38946. // for a two-value style slider, you should use the getMinValue() and getMaxValue()
  38947. // methods to get the two values.
  38948. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  38949. return currentValue.getValue();
  38950. }
  38951. void Slider::setValue (double newValue,
  38952. const bool sendUpdateMessage,
  38953. const bool sendMessageSynchronously)
  38954. {
  38955. // for a two-value style slider, you should use the setMinValue() and setMaxValue()
  38956. // methods to set the two values.
  38957. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  38958. newValue = constrainedValue (newValue);
  38959. if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  38960. {
  38961. jassert ((double) valueMin.getValue() <= (double) valueMax.getValue());
  38962. newValue = jlimit ((double) valueMin.getValue(),
  38963. (double) valueMax.getValue(),
  38964. newValue);
  38965. }
  38966. if (newValue != lastCurrentValue)
  38967. {
  38968. if (valueBox != 0)
  38969. valueBox->hideEditor (true);
  38970. lastCurrentValue = newValue;
  38971. currentValue = newValue;
  38972. updateText();
  38973. repaint();
  38974. if (popupDisplay != 0)
  38975. {
  38976. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  38977. ->updatePosition (getTextFromValue (newValue));
  38978. popupDisplay->repaint();
  38979. }
  38980. if (sendUpdateMessage)
  38981. triggerChangeMessage (sendMessageSynchronously);
  38982. }
  38983. }
  38984. double Slider::getMinValue() const
  38985. {
  38986. // The minimum value only applies to sliders that are in two- or three-value mode.
  38987. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  38988. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  38989. return valueMin.getValue();
  38990. }
  38991. double Slider::getMaxValue() const
  38992. {
  38993. // The maximum value only applies to sliders that are in two- or three-value mode.
  38994. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  38995. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  38996. return valueMax.getValue();
  38997. }
  38998. void Slider::setMinValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  38999. {
  39000. // The minimum value only applies to sliders that are in two- or three-value mode.
  39001. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39002. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39003. newValue = constrainedValue (newValue);
  39004. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39005. {
  39006. if (allowNudgingOfOtherValues && newValue > (double) valueMax.getValue())
  39007. setMaxValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39008. newValue = jmin ((double) valueMax.getValue(), newValue);
  39009. }
  39010. else
  39011. {
  39012. if (allowNudgingOfOtherValues && newValue > lastCurrentValue)
  39013. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39014. newValue = jmin (lastCurrentValue, newValue);
  39015. }
  39016. if (lastValueMin != newValue)
  39017. {
  39018. lastValueMin = newValue;
  39019. valueMin = newValue;
  39020. repaint();
  39021. if (popupDisplay != 0)
  39022. {
  39023. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  39024. ->updatePosition (getTextFromValue (newValue));
  39025. popupDisplay->repaint();
  39026. }
  39027. if (sendUpdateMessage)
  39028. triggerChangeMessage (sendMessageSynchronously);
  39029. }
  39030. }
  39031. void Slider::setMaxValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  39032. {
  39033. // The maximum value only applies to sliders that are in two- or three-value mode.
  39034. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39035. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39036. newValue = constrainedValue (newValue);
  39037. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39038. {
  39039. if (allowNudgingOfOtherValues && newValue < (double) valueMin.getValue())
  39040. setMinValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39041. newValue = jmax ((double) valueMin.getValue(), newValue);
  39042. }
  39043. else
  39044. {
  39045. if (allowNudgingOfOtherValues && newValue < lastCurrentValue)
  39046. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39047. newValue = jmax (lastCurrentValue, newValue);
  39048. }
  39049. if (lastValueMax != newValue)
  39050. {
  39051. lastValueMax = newValue;
  39052. valueMax = newValue;
  39053. repaint();
  39054. if (popupDisplay != 0)
  39055. {
  39056. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  39057. ->updatePosition (getTextFromValue (valueMax.getValue()));
  39058. popupDisplay->repaint();
  39059. }
  39060. if (sendUpdateMessage)
  39061. triggerChangeMessage (sendMessageSynchronously);
  39062. }
  39063. }
  39064. void Slider::setDoubleClickReturnValue (const bool isDoubleClickEnabled,
  39065. const double valueToSetOnDoubleClick)
  39066. {
  39067. doubleClickToValue = isDoubleClickEnabled;
  39068. doubleClickReturnValue = valueToSetOnDoubleClick;
  39069. }
  39070. double Slider::getDoubleClickReturnValue (bool& isEnabled_) const
  39071. {
  39072. isEnabled_ = doubleClickToValue;
  39073. return doubleClickReturnValue;
  39074. }
  39075. void Slider::updateText()
  39076. {
  39077. if (valueBox != 0)
  39078. valueBox->setText (getTextFromValue (currentValue.getValue()), false);
  39079. }
  39080. void Slider::setTextValueSuffix (const String& suffix)
  39081. {
  39082. if (textSuffix != suffix)
  39083. {
  39084. textSuffix = suffix;
  39085. updateText();
  39086. }
  39087. }
  39088. const String Slider::getTextFromValue (double v)
  39089. {
  39090. if (numDecimalPlaces > 0)
  39091. return String (v, numDecimalPlaces) + textSuffix;
  39092. else
  39093. return String (roundToInt (v)) + textSuffix;
  39094. }
  39095. double Slider::getValueFromText (const String& text)
  39096. {
  39097. String t (text.trimStart());
  39098. if (t.endsWith (textSuffix))
  39099. t = t.substring (0, t.length() - textSuffix.length());
  39100. while (t.startsWithChar ('+'))
  39101. t = t.substring (1).trimStart();
  39102. return t.initialSectionContainingOnly (T("0123456789.,-"))
  39103. .getDoubleValue();
  39104. }
  39105. double Slider::proportionOfLengthToValue (double proportion)
  39106. {
  39107. if (skewFactor != 1.0 && proportion > 0.0)
  39108. proportion = exp (log (proportion) / skewFactor);
  39109. return minimum + (maximum - minimum) * proportion;
  39110. }
  39111. double Slider::valueToProportionOfLength (double value)
  39112. {
  39113. const double n = (value - minimum) / (maximum - minimum);
  39114. return skewFactor == 1.0 ? n : pow (n, skewFactor);
  39115. }
  39116. double Slider::snapValue (double attemptedValue, const bool)
  39117. {
  39118. return attemptedValue;
  39119. }
  39120. void Slider::startedDragging()
  39121. {
  39122. }
  39123. void Slider::stoppedDragging()
  39124. {
  39125. }
  39126. void Slider::valueChanged()
  39127. {
  39128. }
  39129. void Slider::enablementChanged()
  39130. {
  39131. repaint();
  39132. }
  39133. void Slider::setPopupMenuEnabled (const bool menuEnabled_)
  39134. {
  39135. menuEnabled = menuEnabled_;
  39136. }
  39137. void Slider::setScrollWheelEnabled (const bool enabled)
  39138. {
  39139. scrollWheelEnabled = enabled;
  39140. }
  39141. void Slider::labelTextChanged (Label* label)
  39142. {
  39143. const double newValue = snapValue (getValueFromText (label->getText()), false);
  39144. if (newValue != (double) currentValue.getValue())
  39145. {
  39146. sendDragStart();
  39147. setValue (newValue, true, true);
  39148. sendDragEnd();
  39149. }
  39150. updateText(); // force a clean-up of the text, needed in case setValue() hasn't done this.
  39151. }
  39152. void Slider::buttonClicked (Button* button)
  39153. {
  39154. if (style == IncDecButtons)
  39155. {
  39156. sendDragStart();
  39157. if (button == incButton)
  39158. setValue (snapValue (getValue() + interval, false), true, true);
  39159. else if (button == decButton)
  39160. setValue (snapValue (getValue() - interval, false), true, true);
  39161. sendDragEnd();
  39162. }
  39163. }
  39164. double Slider::constrainedValue (double value) const
  39165. {
  39166. if (interval > 0)
  39167. value = minimum + interval * floor ((value - minimum) / interval + 0.5);
  39168. if (value <= minimum || maximum <= minimum)
  39169. value = minimum;
  39170. else if (value >= maximum)
  39171. value = maximum;
  39172. return value;
  39173. }
  39174. float Slider::getLinearSliderPos (const double value)
  39175. {
  39176. double sliderPosProportional;
  39177. if (maximum > minimum)
  39178. {
  39179. if (value < minimum)
  39180. {
  39181. sliderPosProportional = 0.0;
  39182. }
  39183. else if (value > maximum)
  39184. {
  39185. sliderPosProportional = 1.0;
  39186. }
  39187. else
  39188. {
  39189. sliderPosProportional = valueToProportionOfLength (value);
  39190. jassert (sliderPosProportional >= 0 && sliderPosProportional <= 1.0);
  39191. }
  39192. }
  39193. else
  39194. {
  39195. sliderPosProportional = 0.5;
  39196. }
  39197. if (isVertical() || style == IncDecButtons)
  39198. sliderPosProportional = 1.0 - sliderPosProportional;
  39199. return (float) (sliderRegionStart + sliderPosProportional * sliderRegionSize);
  39200. }
  39201. bool Slider::isHorizontal() const
  39202. {
  39203. return style == LinearHorizontal
  39204. || style == LinearBar
  39205. || style == TwoValueHorizontal
  39206. || style == ThreeValueHorizontal;
  39207. }
  39208. bool Slider::isVertical() const
  39209. {
  39210. return style == LinearVertical
  39211. || style == TwoValueVertical
  39212. || style == ThreeValueVertical;
  39213. }
  39214. bool Slider::incDecDragDirectionIsHorizontal() const
  39215. {
  39216. return incDecButtonMode == incDecButtonsDraggable_Horizontal
  39217. || (incDecButtonMode == incDecButtonsDraggable_AutoDirection && incDecButtonsSideBySide);
  39218. }
  39219. float Slider::getPositionOfValue (const double value)
  39220. {
  39221. if (isHorizontal() || isVertical())
  39222. {
  39223. return getLinearSliderPos (value);
  39224. }
  39225. else
  39226. {
  39227. jassertfalse // not a valid call on a slider that doesn't work linearly!
  39228. return 0.0f;
  39229. }
  39230. }
  39231. void Slider::paint (Graphics& g)
  39232. {
  39233. if (style != IncDecButtons)
  39234. {
  39235. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39236. {
  39237. const float sliderPos = (float) valueToProportionOfLength (lastCurrentValue);
  39238. jassert (sliderPos >= 0 && sliderPos <= 1.0f);
  39239. getLookAndFeel().drawRotarySlider (g,
  39240. sliderRect.getX(),
  39241. sliderRect.getY(),
  39242. sliderRect.getWidth(),
  39243. sliderRect.getHeight(),
  39244. sliderPos,
  39245. rotaryStart, rotaryEnd,
  39246. *this);
  39247. }
  39248. else
  39249. {
  39250. getLookAndFeel().drawLinearSlider (g,
  39251. sliderRect.getX(),
  39252. sliderRect.getY(),
  39253. sliderRect.getWidth(),
  39254. sliderRect.getHeight(),
  39255. getLinearSliderPos (lastCurrentValue),
  39256. getLinearSliderPos (lastValueMin),
  39257. getLinearSliderPos (lastValueMax),
  39258. style,
  39259. *this);
  39260. }
  39261. if (style == LinearBar && valueBox == 0)
  39262. {
  39263. g.setColour (findColour (Slider::textBoxOutlineColourId));
  39264. g.drawRect (0, 0, getWidth(), getHeight(), 1);
  39265. }
  39266. }
  39267. }
  39268. void Slider::resized()
  39269. {
  39270. int minXSpace = 0;
  39271. int minYSpace = 0;
  39272. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39273. minXSpace = 30;
  39274. else
  39275. minYSpace = 15;
  39276. const int tbw = jmax (0, jmin (textBoxWidth, getWidth() - minXSpace));
  39277. const int tbh = jmax (0, jmin (textBoxHeight, getHeight() - minYSpace));
  39278. if (style == LinearBar)
  39279. {
  39280. if (valueBox != 0)
  39281. valueBox->setBounds (0, 0, getWidth(), getHeight());
  39282. }
  39283. else
  39284. {
  39285. if (textBoxPos == NoTextBox)
  39286. {
  39287. sliderRect.setBounds (0, 0, getWidth(), getHeight());
  39288. }
  39289. else if (textBoxPos == TextBoxLeft)
  39290. {
  39291. valueBox->setBounds (0, (getHeight() - tbh) / 2, tbw, tbh);
  39292. sliderRect.setBounds (tbw, 0, getWidth() - tbw, getHeight());
  39293. }
  39294. else if (textBoxPos == TextBoxRight)
  39295. {
  39296. valueBox->setBounds (getWidth() - tbw, (getHeight() - tbh) / 2, tbw, tbh);
  39297. sliderRect.setBounds (0, 0, getWidth() - tbw, getHeight());
  39298. }
  39299. else if (textBoxPos == TextBoxAbove)
  39300. {
  39301. valueBox->setBounds ((getWidth() - tbw) / 2, 0, tbw, tbh);
  39302. sliderRect.setBounds (0, tbh, getWidth(), getHeight() - tbh);
  39303. }
  39304. else if (textBoxPos == TextBoxBelow)
  39305. {
  39306. valueBox->setBounds ((getWidth() - tbw) / 2, getHeight() - tbh, tbw, tbh);
  39307. sliderRect.setBounds (0, 0, getWidth(), getHeight() - tbh);
  39308. }
  39309. }
  39310. const int indent = getLookAndFeel().getSliderThumbRadius (*this);
  39311. if (style == LinearBar)
  39312. {
  39313. const int barIndent = 1;
  39314. sliderRegionStart = barIndent;
  39315. sliderRegionSize = getWidth() - barIndent * 2;
  39316. sliderRect.setBounds (sliderRegionStart, barIndent,
  39317. sliderRegionSize, getHeight() - barIndent * 2);
  39318. }
  39319. else if (isHorizontal())
  39320. {
  39321. sliderRegionStart = sliderRect.getX() + indent;
  39322. sliderRegionSize = jmax (1, sliderRect.getWidth() - indent * 2);
  39323. sliderRect.setBounds (sliderRegionStart, sliderRect.getY(),
  39324. sliderRegionSize, sliderRect.getHeight());
  39325. }
  39326. else if (isVertical())
  39327. {
  39328. sliderRegionStart = sliderRect.getY() + indent;
  39329. sliderRegionSize = jmax (1, sliderRect.getHeight() - indent * 2);
  39330. sliderRect.setBounds (sliderRect.getX(), sliderRegionStart,
  39331. sliderRect.getWidth(), sliderRegionSize);
  39332. }
  39333. else
  39334. {
  39335. sliderRegionStart = 0;
  39336. sliderRegionSize = 100;
  39337. }
  39338. if (style == IncDecButtons)
  39339. {
  39340. Rectangle<int> buttonRect (sliderRect);
  39341. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39342. buttonRect.expand (-2, 0);
  39343. else
  39344. buttonRect.expand (0, -2);
  39345. incDecButtonsSideBySide = buttonRect.getWidth() > buttonRect.getHeight();
  39346. if (incDecButtonsSideBySide)
  39347. {
  39348. decButton->setBounds (buttonRect.getX(),
  39349. buttonRect.getY(),
  39350. buttonRect.getWidth() / 2,
  39351. buttonRect.getHeight());
  39352. decButton->setConnectedEdges (Button::ConnectedOnRight);
  39353. incButton->setBounds (buttonRect.getCentreX(),
  39354. buttonRect.getY(),
  39355. buttonRect.getWidth() / 2,
  39356. buttonRect.getHeight());
  39357. incButton->setConnectedEdges (Button::ConnectedOnLeft);
  39358. }
  39359. else
  39360. {
  39361. incButton->setBounds (buttonRect.getX(),
  39362. buttonRect.getY(),
  39363. buttonRect.getWidth(),
  39364. buttonRect.getHeight() / 2);
  39365. incButton->setConnectedEdges (Button::ConnectedOnBottom);
  39366. decButton->setBounds (buttonRect.getX(),
  39367. buttonRect.getCentreY(),
  39368. buttonRect.getWidth(),
  39369. buttonRect.getHeight() / 2);
  39370. decButton->setConnectedEdges (Button::ConnectedOnTop);
  39371. }
  39372. }
  39373. }
  39374. void Slider::focusOfChildComponentChanged (FocusChangeType)
  39375. {
  39376. repaint();
  39377. }
  39378. void Slider::mouseDown (const MouseEvent& e)
  39379. {
  39380. mouseWasHidden = false;
  39381. incDecDragged = false;
  39382. mouseXWhenLastDragged = e.x;
  39383. mouseYWhenLastDragged = e.y;
  39384. mouseDragStartX = e.getMouseDownX();
  39385. mouseDragStartY = e.getMouseDownY();
  39386. if (isEnabled())
  39387. {
  39388. if (e.mods.isPopupMenu() && menuEnabled)
  39389. {
  39390. menuShown = true;
  39391. PopupMenu m;
  39392. m.setLookAndFeel (&getLookAndFeel());
  39393. m.addItem (1, TRANS ("velocity-sensitive mode"), true, isVelocityBased);
  39394. m.addSeparator();
  39395. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39396. {
  39397. PopupMenu rotaryMenu;
  39398. rotaryMenu.addItem (2, TRANS ("use circular dragging"), true, style == Rotary);
  39399. rotaryMenu.addItem (3, TRANS ("use left-right dragging"), true, style == RotaryHorizontalDrag);
  39400. rotaryMenu.addItem (4, TRANS ("use up-down dragging"), true, style == RotaryVerticalDrag);
  39401. m.addSubMenu (TRANS ("rotary mode"), rotaryMenu);
  39402. }
  39403. const int r = m.show();
  39404. if (r == 1)
  39405. {
  39406. setVelocityBasedMode (! isVelocityBased);
  39407. }
  39408. else if (r == 2)
  39409. {
  39410. setSliderStyle (Rotary);
  39411. }
  39412. else if (r == 3)
  39413. {
  39414. setSliderStyle (RotaryHorizontalDrag);
  39415. }
  39416. else if (r == 4)
  39417. {
  39418. setSliderStyle (RotaryVerticalDrag);
  39419. }
  39420. }
  39421. else if (maximum > minimum)
  39422. {
  39423. menuShown = false;
  39424. if (valueBox != 0)
  39425. valueBox->hideEditor (true);
  39426. sliderBeingDragged = 0;
  39427. if (style == TwoValueHorizontal
  39428. || style == TwoValueVertical
  39429. || style == ThreeValueHorizontal
  39430. || style == ThreeValueVertical)
  39431. {
  39432. const float mousePos = (float) (isVertical() ? e.y : e.x);
  39433. const float normalPosDistance = fabsf (getLinearSliderPos (currentValue.getValue()) - mousePos);
  39434. const float minPosDistance = fabsf (getLinearSliderPos (valueMin.getValue()) - 0.1f - mousePos);
  39435. const float maxPosDistance = fabsf (getLinearSliderPos (valueMax.getValue()) + 0.1f - mousePos);
  39436. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39437. {
  39438. if (maxPosDistance <= minPosDistance)
  39439. sliderBeingDragged = 2;
  39440. else
  39441. sliderBeingDragged = 1;
  39442. }
  39443. else if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  39444. {
  39445. if (normalPosDistance >= minPosDistance && maxPosDistance >= minPosDistance)
  39446. sliderBeingDragged = 1;
  39447. else if (normalPosDistance >= maxPosDistance)
  39448. sliderBeingDragged = 2;
  39449. }
  39450. }
  39451. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39452. lastAngle = rotaryStart + (rotaryEnd - rotaryStart)
  39453. * valueToProportionOfLength (currentValue.getValue());
  39454. valueWhenLastDragged = ((sliderBeingDragged == 2) ? valueMax
  39455. : ((sliderBeingDragged == 1) ? valueMin
  39456. : currentValue)).getValue();
  39457. valueOnMouseDown = valueWhenLastDragged;
  39458. if (popupDisplayEnabled)
  39459. {
  39460. SliderPopupDisplayComponent* const popup = new SliderPopupDisplayComponent (this);
  39461. popupDisplay = popup;
  39462. if (parentForPopupDisplay != 0)
  39463. {
  39464. parentForPopupDisplay->addChildComponent (popup);
  39465. }
  39466. else
  39467. {
  39468. popup->addToDesktop (0);
  39469. }
  39470. popup->setVisible (true);
  39471. }
  39472. sendDragStart();
  39473. mouseDrag (e);
  39474. }
  39475. }
  39476. }
  39477. void Slider::mouseUp (const MouseEvent&)
  39478. {
  39479. if (isEnabled()
  39480. && (! menuShown)
  39481. && (maximum > minimum)
  39482. && (style != IncDecButtons || incDecDragged))
  39483. {
  39484. restoreMouseIfHidden();
  39485. if (sendChangeOnlyOnRelease && valueOnMouseDown != (double) currentValue.getValue())
  39486. triggerChangeMessage (false);
  39487. sendDragEnd();
  39488. popupDisplay = 0;
  39489. if (style == IncDecButtons)
  39490. {
  39491. incButton->setState (Button::buttonNormal);
  39492. decButton->setState (Button::buttonNormal);
  39493. }
  39494. }
  39495. }
  39496. void Slider::restoreMouseIfHidden()
  39497. {
  39498. if (mouseWasHidden)
  39499. {
  39500. mouseWasHidden = false;
  39501. for (int i = Desktop::getInstance().getNumMouseSources(); --i >= 0;)
  39502. Desktop::getInstance().getMouseSource(i)->enableUnboundedMouseMovement (false);
  39503. const double pos = (sliderBeingDragged == 2) ? getMaxValue()
  39504. : ((sliderBeingDragged == 1) ? getMinValue()
  39505. : (double) currentValue.getValue());
  39506. Point<int> mousePos;
  39507. if (style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39508. {
  39509. mousePos = Desktop::getLastMouseDownPosition();
  39510. if (style == RotaryHorizontalDrag)
  39511. {
  39512. const double posDiff = valueToProportionOfLength (pos) - valueToProportionOfLength (valueOnMouseDown);
  39513. mousePos += Point<int> (roundToInt (pixelsForFullDragExtent * posDiff), 0);
  39514. }
  39515. else
  39516. {
  39517. const double posDiff = valueToProportionOfLength (valueOnMouseDown) - valueToProportionOfLength (pos);
  39518. mousePos += Point<int> (0, roundToInt (pixelsForFullDragExtent * posDiff));
  39519. }
  39520. }
  39521. else
  39522. {
  39523. const int pixelPos = (int) getLinearSliderPos (pos);
  39524. mousePos = relativePositionToGlobal (Point<int> (isHorizontal() ? pixelPos : (getWidth() / 2),
  39525. isVertical() ? pixelPos : (getHeight() / 2)));
  39526. }
  39527. Desktop::setMousePosition (mousePos);
  39528. }
  39529. }
  39530. void Slider::modifierKeysChanged (const ModifierKeys& modifiers)
  39531. {
  39532. if (isEnabled()
  39533. && style != IncDecButtons
  39534. && style != Rotary
  39535. && isVelocityBased == modifiers.isAnyModifierKeyDown())
  39536. {
  39537. restoreMouseIfHidden();
  39538. }
  39539. }
  39540. static double smallestAngleBetween (double a1, double a2)
  39541. {
  39542. return jmin (fabs (a1 - a2),
  39543. fabs (a1 + double_Pi * 2.0 - a2),
  39544. fabs (a2 + double_Pi * 2.0 - a1));
  39545. }
  39546. void Slider::mouseDrag (const MouseEvent& e)
  39547. {
  39548. if (isEnabled()
  39549. && (! menuShown)
  39550. && (maximum > minimum))
  39551. {
  39552. if (style == Rotary)
  39553. {
  39554. int dx = e.x - sliderRect.getCentreX();
  39555. int dy = e.y - sliderRect.getCentreY();
  39556. if (dx * dx + dy * dy > 25)
  39557. {
  39558. double angle = atan2 ((double) dx, (double) -dy);
  39559. while (angle < 0.0)
  39560. angle += double_Pi * 2.0;
  39561. if (rotaryStop && ! e.mouseWasClicked())
  39562. {
  39563. if (fabs (angle - lastAngle) > double_Pi)
  39564. {
  39565. if (angle >= lastAngle)
  39566. angle -= double_Pi * 2.0;
  39567. else
  39568. angle += double_Pi * 2.0;
  39569. }
  39570. if (angle >= lastAngle)
  39571. angle = jmin (angle, (double) jmax (rotaryStart, rotaryEnd));
  39572. else
  39573. angle = jmax (angle, (double) jmin (rotaryStart, rotaryEnd));
  39574. }
  39575. else
  39576. {
  39577. while (angle < rotaryStart)
  39578. angle += double_Pi * 2.0;
  39579. if (angle > rotaryEnd)
  39580. {
  39581. if (smallestAngleBetween (angle, rotaryStart) <= smallestAngleBetween (angle, rotaryEnd))
  39582. angle = rotaryStart;
  39583. else
  39584. angle = rotaryEnd;
  39585. }
  39586. }
  39587. const double proportion = (angle - rotaryStart) / (rotaryEnd - rotaryStart);
  39588. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, proportion));
  39589. lastAngle = angle;
  39590. }
  39591. }
  39592. else
  39593. {
  39594. if (style == LinearBar && e.mouseWasClicked()
  39595. && valueBox != 0 && valueBox->isEditable())
  39596. return;
  39597. if (style == IncDecButtons && ! incDecDragged)
  39598. {
  39599. if (e.getDistanceFromDragStart() < 10 || e.mouseWasClicked())
  39600. return;
  39601. incDecDragged = true;
  39602. mouseDragStartX = e.x;
  39603. mouseDragStartY = e.y;
  39604. }
  39605. if ((isVelocityBased == (userKeyOverridesVelocity ? e.mods.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::commandModifier | ModifierKeys::altModifier)
  39606. : false))
  39607. || ((maximum - minimum) / sliderRegionSize < interval))
  39608. {
  39609. const int mousePos = (isHorizontal() || style == RotaryHorizontalDrag) ? e.x : e.y;
  39610. double scaledMousePos = (mousePos - sliderRegionStart) / (double) sliderRegionSize;
  39611. if (style == RotaryHorizontalDrag
  39612. || style == RotaryVerticalDrag
  39613. || style == IncDecButtons
  39614. || ((style == LinearHorizontal || style == LinearVertical || style == LinearBar)
  39615. && ! snapsToMousePos))
  39616. {
  39617. const int mouseDiff = (style == RotaryHorizontalDrag
  39618. || style == LinearHorizontal
  39619. || style == LinearBar
  39620. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  39621. ? e.x - mouseDragStartX
  39622. : mouseDragStartY - e.y;
  39623. double newPos = valueToProportionOfLength (valueOnMouseDown)
  39624. + mouseDiff * (1.0 / pixelsForFullDragExtent);
  39625. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, newPos));
  39626. if (style == IncDecButtons)
  39627. {
  39628. incButton->setState (mouseDiff < 0 ? Button::buttonNormal : Button::buttonDown);
  39629. decButton->setState (mouseDiff > 0 ? Button::buttonNormal : Button::buttonDown);
  39630. }
  39631. }
  39632. else
  39633. {
  39634. if (isVertical())
  39635. scaledMousePos = 1.0 - scaledMousePos;
  39636. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, scaledMousePos));
  39637. }
  39638. }
  39639. else
  39640. {
  39641. const int mouseDiff = (isHorizontal() || style == RotaryHorizontalDrag
  39642. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  39643. ? e.x - mouseXWhenLastDragged
  39644. : e.y - mouseYWhenLastDragged;
  39645. const double maxSpeed = jmax (200, sliderRegionSize);
  39646. double speed = jlimit (0.0, maxSpeed, (double) abs (mouseDiff));
  39647. if (speed != 0)
  39648. {
  39649. speed = 0.2 * velocityModeSensitivity
  39650. * (1.0 + sin (double_Pi * (1.5 + jmin (0.5, velocityModeOffset
  39651. + jmax (0.0, (double) (speed - velocityModeThreshold))
  39652. / maxSpeed))));
  39653. if (mouseDiff < 0)
  39654. speed = -speed;
  39655. if (isVertical() || style == RotaryVerticalDrag
  39656. || (style == IncDecButtons && ! incDecDragDirectionIsHorizontal()))
  39657. speed = -speed;
  39658. const double currentPos = valueToProportionOfLength (valueWhenLastDragged);
  39659. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + speed));
  39660. e.source.enableUnboundedMouseMovement (true, false);
  39661. mouseWasHidden = true;
  39662. }
  39663. }
  39664. }
  39665. valueWhenLastDragged = jlimit (minimum, maximum, valueWhenLastDragged);
  39666. if (sliderBeingDragged == 0)
  39667. {
  39668. setValue (snapValue (valueWhenLastDragged, true),
  39669. ! sendChangeOnlyOnRelease, true);
  39670. }
  39671. else if (sliderBeingDragged == 1)
  39672. {
  39673. setMinValue (snapValue (valueWhenLastDragged, true),
  39674. ! sendChangeOnlyOnRelease, false, true);
  39675. if (e.mods.isShiftDown())
  39676. setMaxValue (getMinValue() + minMaxDiff, false, false, true);
  39677. else
  39678. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39679. }
  39680. else
  39681. {
  39682. jassert (sliderBeingDragged == 2);
  39683. setMaxValue (snapValue (valueWhenLastDragged, true),
  39684. ! sendChangeOnlyOnRelease, false, true);
  39685. if (e.mods.isShiftDown())
  39686. setMinValue (getMaxValue() - minMaxDiff, false, false, true);
  39687. else
  39688. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39689. }
  39690. mouseXWhenLastDragged = e.x;
  39691. mouseYWhenLastDragged = e.y;
  39692. }
  39693. }
  39694. void Slider::mouseDoubleClick (const MouseEvent&)
  39695. {
  39696. if (doubleClickToValue
  39697. && isEnabled()
  39698. && style != IncDecButtons
  39699. && minimum <= doubleClickReturnValue
  39700. && maximum >= doubleClickReturnValue)
  39701. {
  39702. sendDragStart();
  39703. setValue (doubleClickReturnValue, true, true);
  39704. sendDragEnd();
  39705. }
  39706. }
  39707. void Slider::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  39708. {
  39709. if (scrollWheelEnabled && isEnabled()
  39710. && style != TwoValueHorizontal
  39711. && style != TwoValueVertical)
  39712. {
  39713. if (maximum > minimum && ! e.mods.isAnyMouseButtonDown())
  39714. {
  39715. if (valueBox != 0)
  39716. valueBox->hideEditor (false);
  39717. const double value = (double) currentValue.getValue();
  39718. const double proportionDelta = (wheelIncrementX != 0 ? -wheelIncrementX : wheelIncrementY) * 0.15f;
  39719. const double currentPos = valueToProportionOfLength (value);
  39720. const double newValue = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + proportionDelta));
  39721. double delta = (newValue != value)
  39722. ? jmax (fabs (newValue - value), interval) : 0;
  39723. if (value > newValue)
  39724. delta = -delta;
  39725. sendDragStart();
  39726. setValue (snapValue (value + delta, false), true, true);
  39727. sendDragEnd();
  39728. }
  39729. }
  39730. else
  39731. {
  39732. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  39733. }
  39734. }
  39735. void SliderListener::sliderDragStarted (Slider*)
  39736. {
  39737. }
  39738. void SliderListener::sliderDragEnded (Slider*)
  39739. {
  39740. }
  39741. END_JUCE_NAMESPACE
  39742. /*** End of inlined file: juce_Slider.cpp ***/
  39743. /*** Start of inlined file: juce_TableHeaderComponent.cpp ***/
  39744. BEGIN_JUCE_NAMESPACE
  39745. class DragOverlayComp : public Component
  39746. {
  39747. public:
  39748. DragOverlayComp (Image* const image_)
  39749. : image (image_)
  39750. {
  39751. image->multiplyAllAlphas (0.8f);
  39752. setAlwaysOnTop (true);
  39753. }
  39754. ~DragOverlayComp()
  39755. {
  39756. }
  39757. void paint (Graphics& g)
  39758. {
  39759. g.drawImageAt (image, 0, 0);
  39760. }
  39761. private:
  39762. ScopedPointer <Image> image;
  39763. DragOverlayComp (const DragOverlayComp&);
  39764. DragOverlayComp& operator= (const DragOverlayComp&);
  39765. };
  39766. TableHeaderComponent::TableHeaderComponent()
  39767. : columnsChanged (false),
  39768. columnsResized (false),
  39769. sortChanged (false),
  39770. menuActive (true),
  39771. stretchToFit (false),
  39772. columnIdBeingResized (0),
  39773. columnIdBeingDragged (0),
  39774. columnIdUnderMouse (0),
  39775. lastDeliberateWidth (0)
  39776. {
  39777. }
  39778. TableHeaderComponent::~TableHeaderComponent()
  39779. {
  39780. dragOverlayComp = 0;
  39781. }
  39782. void TableHeaderComponent::setPopupMenuActive (const bool hasMenu)
  39783. {
  39784. menuActive = hasMenu;
  39785. }
  39786. bool TableHeaderComponent::isPopupMenuActive() const { return menuActive; }
  39787. int TableHeaderComponent::getNumColumns (const bool onlyCountVisibleColumns) const
  39788. {
  39789. if (onlyCountVisibleColumns)
  39790. {
  39791. int num = 0;
  39792. for (int i = columns.size(); --i >= 0;)
  39793. if (columns.getUnchecked(i)->isVisible())
  39794. ++num;
  39795. return num;
  39796. }
  39797. else
  39798. {
  39799. return columns.size();
  39800. }
  39801. }
  39802. const String TableHeaderComponent::getColumnName (const int columnId) const
  39803. {
  39804. const ColumnInfo* const ci = getInfoForId (columnId);
  39805. return ci != 0 ? ci->name : String::empty;
  39806. }
  39807. void TableHeaderComponent::setColumnName (const int columnId, const String& newName)
  39808. {
  39809. ColumnInfo* const ci = getInfoForId (columnId);
  39810. if (ci != 0 && ci->name != newName)
  39811. {
  39812. ci->name = newName;
  39813. sendColumnsChanged();
  39814. }
  39815. }
  39816. void TableHeaderComponent::addColumn (const String& columnName,
  39817. const int columnId,
  39818. const int width,
  39819. const int minimumWidth,
  39820. const int maximumWidth,
  39821. const int propertyFlags,
  39822. const int insertIndex)
  39823. {
  39824. // can't have a duplicate or null ID!
  39825. jassert (columnId != 0 && getIndexOfColumnId (columnId, false) < 0);
  39826. jassert (width > 0);
  39827. ColumnInfo* const ci = new ColumnInfo();
  39828. ci->name = columnName;
  39829. ci->id = columnId;
  39830. ci->width = width;
  39831. ci->lastDeliberateWidth = width;
  39832. ci->minimumWidth = minimumWidth;
  39833. ci->maximumWidth = maximumWidth;
  39834. if (ci->maximumWidth < 0)
  39835. ci->maximumWidth = std::numeric_limits<int>::max();
  39836. jassert (ci->maximumWidth >= ci->minimumWidth);
  39837. ci->propertyFlags = propertyFlags;
  39838. columns.insert (insertIndex, ci);
  39839. sendColumnsChanged();
  39840. }
  39841. void TableHeaderComponent::removeColumn (const int columnIdToRemove)
  39842. {
  39843. const int index = getIndexOfColumnId (columnIdToRemove, false);
  39844. if (index >= 0)
  39845. {
  39846. columns.remove (index);
  39847. sortChanged = true;
  39848. sendColumnsChanged();
  39849. }
  39850. }
  39851. void TableHeaderComponent::removeAllColumns()
  39852. {
  39853. if (columns.size() > 0)
  39854. {
  39855. columns.clear();
  39856. sendColumnsChanged();
  39857. }
  39858. }
  39859. void TableHeaderComponent::moveColumn (const int columnId, int newIndex)
  39860. {
  39861. const int currentIndex = getIndexOfColumnId (columnId, false);
  39862. newIndex = visibleIndexToTotalIndex (newIndex);
  39863. if (columns [currentIndex] != 0 && currentIndex != newIndex)
  39864. {
  39865. columns.move (currentIndex, newIndex);
  39866. sendColumnsChanged();
  39867. }
  39868. }
  39869. int TableHeaderComponent::getColumnWidth (const int columnId) const
  39870. {
  39871. const ColumnInfo* const ci = getInfoForId (columnId);
  39872. return ci != 0 ? ci->width : 0;
  39873. }
  39874. void TableHeaderComponent::setColumnWidth (const int columnId, const int newWidth)
  39875. {
  39876. ColumnInfo* const ci = getInfoForId (columnId);
  39877. if (ci != 0 && ci->width != newWidth)
  39878. {
  39879. const int numColumns = getNumColumns (true);
  39880. ci->lastDeliberateWidth = ci->width
  39881. = jlimit (ci->minimumWidth, ci->maximumWidth, newWidth);
  39882. if (stretchToFit)
  39883. {
  39884. const int index = getIndexOfColumnId (columnId, true) + 1;
  39885. if (((unsigned int) index) < (unsigned int) numColumns)
  39886. {
  39887. const int x = getColumnPosition (index).getX();
  39888. if (lastDeliberateWidth == 0)
  39889. lastDeliberateWidth = getTotalWidth();
  39890. resizeColumnsToFit (visibleIndexToTotalIndex (index), lastDeliberateWidth - x);
  39891. }
  39892. }
  39893. repaint();
  39894. columnsResized = true;
  39895. triggerAsyncUpdate();
  39896. }
  39897. }
  39898. int TableHeaderComponent::getIndexOfColumnId (const int columnId, const bool onlyCountVisibleColumns) const
  39899. {
  39900. int n = 0;
  39901. for (int i = 0; i < columns.size(); ++i)
  39902. {
  39903. if ((! onlyCountVisibleColumns) || columns.getUnchecked(i)->isVisible())
  39904. {
  39905. if (columns.getUnchecked(i)->id == columnId)
  39906. return n;
  39907. ++n;
  39908. }
  39909. }
  39910. return -1;
  39911. }
  39912. int TableHeaderComponent::getColumnIdOfIndex (int index, const bool onlyCountVisibleColumns) const
  39913. {
  39914. if (onlyCountVisibleColumns)
  39915. index = visibleIndexToTotalIndex (index);
  39916. const ColumnInfo* const ci = columns [index];
  39917. return (ci != 0) ? ci->id : 0;
  39918. }
  39919. const Rectangle<int> TableHeaderComponent::getColumnPosition (const int index) const
  39920. {
  39921. int x = 0, width = 0, n = 0;
  39922. for (int i = 0; i < columns.size(); ++i)
  39923. {
  39924. x += width;
  39925. if (columns.getUnchecked(i)->isVisible())
  39926. {
  39927. width = columns.getUnchecked(i)->width;
  39928. if (n++ == index)
  39929. break;
  39930. }
  39931. else
  39932. {
  39933. width = 0;
  39934. }
  39935. }
  39936. return Rectangle<int> (x, 0, width, getHeight());
  39937. }
  39938. int TableHeaderComponent::getColumnIdAtX (const int xToFind) const
  39939. {
  39940. if (xToFind >= 0)
  39941. {
  39942. int x = 0;
  39943. for (int i = 0; i < columns.size(); ++i)
  39944. {
  39945. const ColumnInfo* const ci = columns.getUnchecked(i);
  39946. if (ci->isVisible())
  39947. {
  39948. x += ci->width;
  39949. if (xToFind < x)
  39950. return ci->id;
  39951. }
  39952. }
  39953. }
  39954. return 0;
  39955. }
  39956. int TableHeaderComponent::getTotalWidth() const
  39957. {
  39958. int w = 0;
  39959. for (int i = columns.size(); --i >= 0;)
  39960. if (columns.getUnchecked(i)->isVisible())
  39961. w += columns.getUnchecked(i)->width;
  39962. return w;
  39963. }
  39964. void TableHeaderComponent::setStretchToFitActive (const bool shouldStretchToFit)
  39965. {
  39966. stretchToFit = shouldStretchToFit;
  39967. lastDeliberateWidth = getTotalWidth();
  39968. resized();
  39969. }
  39970. bool TableHeaderComponent::isStretchToFitActive() const
  39971. {
  39972. return stretchToFit;
  39973. }
  39974. void TableHeaderComponent::resizeAllColumnsToFit (int targetTotalWidth)
  39975. {
  39976. if (stretchToFit && getWidth() > 0
  39977. && columnIdBeingResized == 0 && columnIdBeingDragged == 0)
  39978. {
  39979. lastDeliberateWidth = targetTotalWidth;
  39980. resizeColumnsToFit (0, targetTotalWidth);
  39981. }
  39982. }
  39983. void TableHeaderComponent::resizeColumnsToFit (int firstColumnIndex, int targetTotalWidth)
  39984. {
  39985. targetTotalWidth = jmax (targetTotalWidth, 0);
  39986. StretchableObjectResizer sor;
  39987. int i;
  39988. for (i = firstColumnIndex; i < columns.size(); ++i)
  39989. {
  39990. ColumnInfo* const ci = columns.getUnchecked(i);
  39991. if (ci->isVisible())
  39992. sor.addItem (ci->lastDeliberateWidth, ci->minimumWidth, ci->maximumWidth);
  39993. }
  39994. sor.resizeToFit (targetTotalWidth);
  39995. int visIndex = 0;
  39996. for (i = firstColumnIndex; i < columns.size(); ++i)
  39997. {
  39998. ColumnInfo* const ci = columns.getUnchecked(i);
  39999. if (ci->isVisible())
  40000. {
  40001. const int newWidth = jlimit (ci->minimumWidth, ci->maximumWidth,
  40002. (int) floor (sor.getItemSize (visIndex++)));
  40003. if (newWidth != ci->width)
  40004. {
  40005. ci->width = newWidth;
  40006. repaint();
  40007. columnsResized = true;
  40008. triggerAsyncUpdate();
  40009. }
  40010. }
  40011. }
  40012. }
  40013. void TableHeaderComponent::setColumnVisible (const int columnId, const bool shouldBeVisible)
  40014. {
  40015. ColumnInfo* const ci = getInfoForId (columnId);
  40016. if (ci != 0 && shouldBeVisible != ci->isVisible())
  40017. {
  40018. if (shouldBeVisible)
  40019. ci->propertyFlags |= visible;
  40020. else
  40021. ci->propertyFlags &= ~visible;
  40022. sendColumnsChanged();
  40023. resized();
  40024. }
  40025. }
  40026. bool TableHeaderComponent::isColumnVisible (const int columnId) const
  40027. {
  40028. const ColumnInfo* const ci = getInfoForId (columnId);
  40029. return ci != 0 && ci->isVisible();
  40030. }
  40031. void TableHeaderComponent::setSortColumnId (const int columnId, const bool sortForwards)
  40032. {
  40033. if (getSortColumnId() != columnId || isSortedForwards() != sortForwards)
  40034. {
  40035. for (int i = columns.size(); --i >= 0;)
  40036. columns.getUnchecked(i)->propertyFlags &= ~(sortedForwards | sortedBackwards);
  40037. ColumnInfo* const ci = getInfoForId (columnId);
  40038. if (ci != 0)
  40039. ci->propertyFlags |= (sortForwards ? sortedForwards : sortedBackwards);
  40040. reSortTable();
  40041. }
  40042. }
  40043. int TableHeaderComponent::getSortColumnId() const
  40044. {
  40045. for (int i = columns.size(); --i >= 0;)
  40046. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40047. return columns.getUnchecked(i)->id;
  40048. return 0;
  40049. }
  40050. bool TableHeaderComponent::isSortedForwards() const
  40051. {
  40052. for (int i = columns.size(); --i >= 0;)
  40053. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40054. return (columns.getUnchecked(i)->propertyFlags & sortedForwards) != 0;
  40055. return true;
  40056. }
  40057. void TableHeaderComponent::reSortTable()
  40058. {
  40059. sortChanged = true;
  40060. repaint();
  40061. triggerAsyncUpdate();
  40062. }
  40063. const String TableHeaderComponent::toString() const
  40064. {
  40065. String s;
  40066. XmlElement doc ("TABLELAYOUT");
  40067. doc.setAttribute ("sortedCol", getSortColumnId());
  40068. doc.setAttribute ("sortForwards", isSortedForwards());
  40069. for (int i = 0; i < columns.size(); ++i)
  40070. {
  40071. const ColumnInfo* const ci = columns.getUnchecked (i);
  40072. XmlElement* const e = doc.createNewChildElement ("COLUMN");
  40073. e->setAttribute ("id", ci->id);
  40074. e->setAttribute ("visible", ci->isVisible());
  40075. e->setAttribute ("width", ci->width);
  40076. }
  40077. return doc.createDocument (String::empty, true, false);
  40078. }
  40079. void TableHeaderComponent::restoreFromString (const String& storedVersion)
  40080. {
  40081. XmlDocument doc (storedVersion);
  40082. ScopedPointer <XmlElement> storedXml (doc.getDocumentElement());
  40083. int index = 0;
  40084. if (storedXml != 0 && storedXml->hasTagName ("TABLELAYOUT"))
  40085. {
  40086. forEachXmlChildElement (*storedXml, col)
  40087. {
  40088. const int tabId = col->getIntAttribute ("id");
  40089. ColumnInfo* const ci = getInfoForId (tabId);
  40090. if (ci != 0)
  40091. {
  40092. columns.move (columns.indexOf (ci), index);
  40093. ci->width = col->getIntAttribute ("width");
  40094. setColumnVisible (tabId, col->getBoolAttribute ("visible"));
  40095. }
  40096. ++index;
  40097. }
  40098. columnsResized = true;
  40099. sendColumnsChanged();
  40100. setSortColumnId (storedXml->getIntAttribute ("sortedCol"),
  40101. storedXml->getBoolAttribute ("sortForwards", true));
  40102. }
  40103. }
  40104. void TableHeaderComponent::addListener (TableHeaderListener* const newListener)
  40105. {
  40106. listeners.addIfNotAlreadyThere (newListener);
  40107. }
  40108. void TableHeaderComponent::removeListener (TableHeaderListener* const listenerToRemove)
  40109. {
  40110. listeners.removeValue (listenerToRemove);
  40111. }
  40112. void TableHeaderComponent::columnClicked (int columnId, const ModifierKeys& mods)
  40113. {
  40114. const ColumnInfo* const ci = getInfoForId (columnId);
  40115. if (ci != 0 && (ci->propertyFlags & sortable) != 0 && ! mods.isPopupMenu())
  40116. setSortColumnId (columnId, (ci->propertyFlags & sortedForwards) == 0);
  40117. }
  40118. void TableHeaderComponent::addMenuItems (PopupMenu& menu, const int /*columnIdClicked*/)
  40119. {
  40120. for (int i = 0; i < columns.size(); ++i)
  40121. {
  40122. const ColumnInfo* const ci = columns.getUnchecked(i);
  40123. if ((ci->propertyFlags & appearsOnColumnMenu) != 0)
  40124. menu.addItem (ci->id, ci->name,
  40125. (ci->propertyFlags & (sortedForwards | sortedBackwards)) == 0,
  40126. isColumnVisible (ci->id));
  40127. }
  40128. }
  40129. void TableHeaderComponent::reactToMenuItem (const int menuReturnId, const int /*columnIdClicked*/)
  40130. {
  40131. if (getIndexOfColumnId (menuReturnId, false) >= 0)
  40132. setColumnVisible (menuReturnId, ! isColumnVisible (menuReturnId));
  40133. }
  40134. void TableHeaderComponent::paint (Graphics& g)
  40135. {
  40136. LookAndFeel& lf = getLookAndFeel();
  40137. lf.drawTableHeaderBackground (g, *this);
  40138. const Rectangle<int> clip (g.getClipBounds());
  40139. int x = 0;
  40140. for (int i = 0; i < columns.size(); ++i)
  40141. {
  40142. const ColumnInfo* const ci = columns.getUnchecked(i);
  40143. if (ci->isVisible())
  40144. {
  40145. if (x + ci->width > clip.getX()
  40146. && (ci->id != columnIdBeingDragged
  40147. || dragOverlayComp == 0
  40148. || ! dragOverlayComp->isVisible()))
  40149. {
  40150. g.saveState();
  40151. g.setOrigin (x, 0);
  40152. g.reduceClipRegion (0, 0, ci->width, getHeight());
  40153. lf.drawTableHeaderColumn (g, ci->name, ci->id, ci->width, getHeight(),
  40154. ci->id == columnIdUnderMouse,
  40155. ci->id == columnIdUnderMouse && isMouseButtonDown(),
  40156. ci->propertyFlags);
  40157. g.restoreState();
  40158. }
  40159. x += ci->width;
  40160. if (x >= clip.getRight())
  40161. break;
  40162. }
  40163. }
  40164. }
  40165. void TableHeaderComponent::resized()
  40166. {
  40167. }
  40168. void TableHeaderComponent::mouseMove (const MouseEvent& e)
  40169. {
  40170. updateColumnUnderMouse (e.x, e.y);
  40171. }
  40172. void TableHeaderComponent::mouseEnter (const MouseEvent& e)
  40173. {
  40174. updateColumnUnderMouse (e.x, e.y);
  40175. }
  40176. void TableHeaderComponent::mouseExit (const MouseEvent& e)
  40177. {
  40178. updateColumnUnderMouse (e.x, e.y);
  40179. }
  40180. void TableHeaderComponent::mouseDown (const MouseEvent& e)
  40181. {
  40182. repaint();
  40183. columnIdBeingResized = 0;
  40184. columnIdBeingDragged = 0;
  40185. if (columnIdUnderMouse != 0)
  40186. {
  40187. draggingColumnOffset = e.x - getColumnPosition (getIndexOfColumnId (columnIdUnderMouse, true)).getX();
  40188. if (e.mods.isPopupMenu())
  40189. columnClicked (columnIdUnderMouse, e.mods);
  40190. }
  40191. if (menuActive && e.mods.isPopupMenu())
  40192. showColumnChooserMenu (columnIdUnderMouse);
  40193. }
  40194. void TableHeaderComponent::mouseDrag (const MouseEvent& e)
  40195. {
  40196. if (columnIdBeingResized == 0
  40197. && columnIdBeingDragged == 0
  40198. && ! (e.mouseWasClicked() || e.mods.isPopupMenu()))
  40199. {
  40200. dragOverlayComp = 0;
  40201. columnIdBeingResized = getResizeDraggerAt (e.getMouseDownX());
  40202. if (columnIdBeingResized != 0)
  40203. {
  40204. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40205. initialColumnWidth = ci->width;
  40206. }
  40207. else
  40208. {
  40209. beginDrag (e);
  40210. }
  40211. }
  40212. if (columnIdBeingResized != 0)
  40213. {
  40214. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40215. if (ci != 0)
  40216. {
  40217. int w = jlimit (ci->minimumWidth, ci->maximumWidth,
  40218. initialColumnWidth + e.getDistanceFromDragStartX());
  40219. if (stretchToFit)
  40220. {
  40221. // prevent us dragging a column too far right if we're in stretch-to-fit mode
  40222. int minWidthOnRight = 0;
  40223. for (int i = getIndexOfColumnId (columnIdBeingResized, false) + 1; i < columns.size(); ++i)
  40224. if (columns.getUnchecked (i)->isVisible())
  40225. minWidthOnRight += columns.getUnchecked (i)->minimumWidth;
  40226. const Rectangle<int> currentPos (getColumnPosition (getIndexOfColumnId (columnIdBeingResized, true)));
  40227. w = jmax (ci->minimumWidth, jmin (w, getWidth() - minWidthOnRight - currentPos.getX()));
  40228. }
  40229. setColumnWidth (columnIdBeingResized, w);
  40230. }
  40231. }
  40232. else if (columnIdBeingDragged != 0)
  40233. {
  40234. if (e.y >= -50 && e.y < getHeight() + 50)
  40235. {
  40236. if (dragOverlayComp != 0)
  40237. {
  40238. dragOverlayComp->setVisible (true);
  40239. dragOverlayComp->setBounds (jlimit (0,
  40240. jmax (0, getTotalWidth() - dragOverlayComp->getWidth()),
  40241. e.x - draggingColumnOffset),
  40242. 0,
  40243. dragOverlayComp->getWidth(),
  40244. getHeight());
  40245. for (int i = columns.size(); --i >= 0;)
  40246. {
  40247. const int currentIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40248. int newIndex = currentIndex;
  40249. if (newIndex > 0)
  40250. {
  40251. // if the previous column isn't draggable, we can't move our column
  40252. // past it, because that'd change the undraggable column's position..
  40253. const ColumnInfo* const previous = columns.getUnchecked (newIndex - 1);
  40254. if ((previous->propertyFlags & draggable) != 0)
  40255. {
  40256. const int leftOfPrevious = getColumnPosition (newIndex - 1).getX();
  40257. const int rightOfCurrent = getColumnPosition (newIndex).getRight();
  40258. if (abs (dragOverlayComp->getX() - leftOfPrevious)
  40259. < abs (dragOverlayComp->getRight() - rightOfCurrent))
  40260. {
  40261. --newIndex;
  40262. }
  40263. }
  40264. }
  40265. if (newIndex < columns.size() - 1)
  40266. {
  40267. // if the next column isn't draggable, we can't move our column
  40268. // past it, because that'd change the undraggable column's position..
  40269. const ColumnInfo* const nextCol = columns.getUnchecked (newIndex + 1);
  40270. if ((nextCol->propertyFlags & draggable) != 0)
  40271. {
  40272. const int leftOfCurrent = getColumnPosition (newIndex).getX();
  40273. const int rightOfNext = getColumnPosition (newIndex + 1).getRight();
  40274. if (abs (dragOverlayComp->getX() - leftOfCurrent)
  40275. > abs (dragOverlayComp->getRight() - rightOfNext))
  40276. {
  40277. ++newIndex;
  40278. }
  40279. }
  40280. }
  40281. if (newIndex != currentIndex)
  40282. moveColumn (columnIdBeingDragged, newIndex);
  40283. else
  40284. break;
  40285. }
  40286. }
  40287. }
  40288. else
  40289. {
  40290. endDrag (draggingColumnOriginalIndex);
  40291. }
  40292. }
  40293. }
  40294. void TableHeaderComponent::beginDrag (const MouseEvent& e)
  40295. {
  40296. if (columnIdBeingDragged == 0)
  40297. {
  40298. columnIdBeingDragged = getColumnIdAtX (e.getMouseDownX());
  40299. const ColumnInfo* const ci = getInfoForId (columnIdBeingDragged);
  40300. if (ci == 0 || (ci->propertyFlags & draggable) == 0)
  40301. {
  40302. columnIdBeingDragged = 0;
  40303. }
  40304. else
  40305. {
  40306. draggingColumnOriginalIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40307. const Rectangle<int> columnRect (getColumnPosition (draggingColumnOriginalIndex));
  40308. const int temp = columnIdBeingDragged;
  40309. columnIdBeingDragged = 0;
  40310. addAndMakeVisible (dragOverlayComp = new DragOverlayComp (createComponentSnapshot (columnRect, false)));
  40311. columnIdBeingDragged = temp;
  40312. dragOverlayComp->setBounds (columnRect);
  40313. for (int i = listeners.size(); --i >= 0;)
  40314. {
  40315. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, columnIdBeingDragged);
  40316. i = jmin (i, listeners.size() - 1);
  40317. }
  40318. }
  40319. }
  40320. }
  40321. void TableHeaderComponent::endDrag (const int finalIndex)
  40322. {
  40323. if (columnIdBeingDragged != 0)
  40324. {
  40325. moveColumn (columnIdBeingDragged, finalIndex);
  40326. columnIdBeingDragged = 0;
  40327. repaint();
  40328. for (int i = listeners.size(); --i >= 0;)
  40329. {
  40330. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, 0);
  40331. i = jmin (i, listeners.size() - 1);
  40332. }
  40333. }
  40334. }
  40335. void TableHeaderComponent::mouseUp (const MouseEvent& e)
  40336. {
  40337. mouseDrag (e);
  40338. for (int i = columns.size(); --i >= 0;)
  40339. if (columns.getUnchecked (i)->isVisible())
  40340. columns.getUnchecked (i)->lastDeliberateWidth = columns.getUnchecked (i)->width;
  40341. columnIdBeingResized = 0;
  40342. repaint();
  40343. endDrag (getIndexOfColumnId (columnIdBeingDragged, true));
  40344. updateColumnUnderMouse (e.x, e.y);
  40345. if (columnIdUnderMouse != 0 && e.mouseWasClicked() && ! e.mods.isPopupMenu())
  40346. columnClicked (columnIdUnderMouse, e.mods);
  40347. dragOverlayComp = 0;
  40348. }
  40349. const MouseCursor TableHeaderComponent::getMouseCursor()
  40350. {
  40351. if (columnIdBeingResized != 0 || (getResizeDraggerAt (getMouseXYRelative().getX()) != 0 && ! isMouseButtonDown()))
  40352. return MouseCursor (MouseCursor::LeftRightResizeCursor);
  40353. return Component::getMouseCursor();
  40354. }
  40355. bool TableHeaderComponent::ColumnInfo::isVisible() const
  40356. {
  40357. return (propertyFlags & TableHeaderComponent::visible) != 0;
  40358. }
  40359. TableHeaderComponent::ColumnInfo* TableHeaderComponent::getInfoForId (const int id) const
  40360. {
  40361. for (int i = columns.size(); --i >= 0;)
  40362. if (columns.getUnchecked(i)->id == id)
  40363. return columns.getUnchecked(i);
  40364. return 0;
  40365. }
  40366. int TableHeaderComponent::visibleIndexToTotalIndex (const int visibleIndex) const
  40367. {
  40368. int n = 0;
  40369. for (int i = 0; i < columns.size(); ++i)
  40370. {
  40371. if (columns.getUnchecked(i)->isVisible())
  40372. {
  40373. if (n == visibleIndex)
  40374. return i;
  40375. ++n;
  40376. }
  40377. }
  40378. return -1;
  40379. }
  40380. void TableHeaderComponent::sendColumnsChanged()
  40381. {
  40382. if (stretchToFit && lastDeliberateWidth > 0)
  40383. resizeAllColumnsToFit (lastDeliberateWidth);
  40384. repaint();
  40385. columnsChanged = true;
  40386. triggerAsyncUpdate();
  40387. }
  40388. void TableHeaderComponent::handleAsyncUpdate()
  40389. {
  40390. const bool changed = columnsChanged || sortChanged;
  40391. const bool sized = columnsResized || changed;
  40392. const bool sorted = sortChanged;
  40393. columnsChanged = false;
  40394. columnsResized = false;
  40395. sortChanged = false;
  40396. if (sorted)
  40397. {
  40398. for (int i = listeners.size(); --i >= 0;)
  40399. {
  40400. listeners.getUnchecked(i)->tableSortOrderChanged (this);
  40401. i = jmin (i, listeners.size() - 1);
  40402. }
  40403. }
  40404. if (changed)
  40405. {
  40406. for (int i = listeners.size(); --i >= 0;)
  40407. {
  40408. listeners.getUnchecked(i)->tableColumnsChanged (this);
  40409. i = jmin (i, listeners.size() - 1);
  40410. }
  40411. }
  40412. if (sized)
  40413. {
  40414. for (int i = listeners.size(); --i >= 0;)
  40415. {
  40416. listeners.getUnchecked(i)->tableColumnsResized (this);
  40417. i = jmin (i, listeners.size() - 1);
  40418. }
  40419. }
  40420. }
  40421. int TableHeaderComponent::getResizeDraggerAt (const int mouseX) const
  40422. {
  40423. if (((unsigned int) mouseX) < (unsigned int) getWidth())
  40424. {
  40425. const int draggableDistance = 3;
  40426. int x = 0;
  40427. for (int i = 0; i < columns.size(); ++i)
  40428. {
  40429. const ColumnInfo* const ci = columns.getUnchecked(i);
  40430. if (ci->isVisible())
  40431. {
  40432. if (abs (mouseX - (x + ci->width)) <= draggableDistance
  40433. && (ci->propertyFlags & resizable) != 0)
  40434. return ci->id;
  40435. x += ci->width;
  40436. }
  40437. }
  40438. }
  40439. return 0;
  40440. }
  40441. void TableHeaderComponent::updateColumnUnderMouse (int x, int y)
  40442. {
  40443. const int newCol = (reallyContains (x, y, true) && getResizeDraggerAt (x) == 0)
  40444. ? getColumnIdAtX (x) : 0;
  40445. if (newCol != columnIdUnderMouse)
  40446. {
  40447. columnIdUnderMouse = newCol;
  40448. repaint();
  40449. }
  40450. }
  40451. void TableHeaderComponent::showColumnChooserMenu (const int columnIdClicked)
  40452. {
  40453. PopupMenu m;
  40454. addMenuItems (m, columnIdClicked);
  40455. if (m.getNumItems() > 0)
  40456. {
  40457. m.setLookAndFeel (&getLookAndFeel());
  40458. const int result = m.show();
  40459. if (result != 0)
  40460. reactToMenuItem (result, columnIdClicked);
  40461. }
  40462. }
  40463. void TableHeaderListener::tableColumnDraggingChanged (TableHeaderComponent*, int)
  40464. {
  40465. }
  40466. END_JUCE_NAMESPACE
  40467. /*** End of inlined file: juce_TableHeaderComponent.cpp ***/
  40468. /*** Start of inlined file: juce_TableListBox.cpp ***/
  40469. BEGIN_JUCE_NAMESPACE
  40470. static const char* const tableColumnPropertyTag = "_tableColumnID";
  40471. class TableListRowComp : public Component,
  40472. public TooltipClient
  40473. {
  40474. public:
  40475. TableListRowComp (TableListBox& owner_)
  40476. : owner (owner_),
  40477. row (-1),
  40478. isSelected (false)
  40479. {
  40480. }
  40481. ~TableListRowComp()
  40482. {
  40483. deleteAllChildren();
  40484. }
  40485. void paint (Graphics& g)
  40486. {
  40487. TableListBoxModel* const model = owner.getModel();
  40488. if (model != 0)
  40489. {
  40490. const TableHeaderComponent* const header = owner.getHeader();
  40491. model->paintRowBackground (g, row, getWidth(), getHeight(), isSelected);
  40492. const int numColumns = header->getNumColumns (true);
  40493. for (int i = 0; i < numColumns; ++i)
  40494. {
  40495. if (! columnsWithComponents [i])
  40496. {
  40497. const int columnId = header->getColumnIdOfIndex (i, true);
  40498. Rectangle<int> columnRect (header->getColumnPosition (i));
  40499. columnRect.setSize (columnRect.getWidth(), getHeight());
  40500. g.saveState();
  40501. g.reduceClipRegion (columnRect);
  40502. g.setOrigin (columnRect.getX(), 0);
  40503. model->paintCell (g, row, columnId, columnRect.getWidth(), columnRect.getHeight(), isSelected);
  40504. g.restoreState();
  40505. }
  40506. }
  40507. }
  40508. }
  40509. void update (const int newRow, const bool isNowSelected)
  40510. {
  40511. if (newRow != row || isNowSelected != isSelected)
  40512. {
  40513. row = newRow;
  40514. isSelected = isNowSelected;
  40515. repaint();
  40516. }
  40517. if (row < owner.getNumRows())
  40518. {
  40519. jassert (row >= 0);
  40520. const var::identifier tagPropertyName ("_tableLastUseNum");
  40521. const int newTag = Random::getSystemRandom().nextInt();
  40522. const TableHeaderComponent* const header = owner.getHeader();
  40523. const int numColumns = header->getNumColumns (true);
  40524. int i;
  40525. columnsWithComponents.clear();
  40526. if (owner.getModel() != 0)
  40527. {
  40528. for (i = 0; i < numColumns; ++i)
  40529. {
  40530. const int columnId = header->getColumnIdOfIndex (i, true);
  40531. Component* const newComp
  40532. = owner.getModel()->refreshComponentForCell (row, columnId, isSelected,
  40533. findChildComponentForColumn (columnId));
  40534. if (newComp != 0)
  40535. {
  40536. addAndMakeVisible (newComp);
  40537. newComp->getProperties().set (tagPropertyName, newTag);
  40538. newComp->getProperties().set (tableColumnPropertyTag, columnId);
  40539. const Rectangle<int> columnRect (header->getColumnPosition (i));
  40540. newComp->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  40541. columnsWithComponents.setBit (i);
  40542. }
  40543. }
  40544. }
  40545. for (i = getNumChildComponents(); --i >= 0;)
  40546. {
  40547. Component* const c = getChildComponent (i);
  40548. if ((int) c->getProperties() [tagPropertyName] != newTag)
  40549. delete c;
  40550. }
  40551. }
  40552. else
  40553. {
  40554. columnsWithComponents.clear();
  40555. deleteAllChildren();
  40556. }
  40557. }
  40558. void resized()
  40559. {
  40560. for (int i = getNumChildComponents(); --i >= 0;)
  40561. {
  40562. Component* const c = getChildComponent (i);
  40563. const int columnId = c->getProperties() [tableColumnPropertyTag];
  40564. if (columnId != 0)
  40565. {
  40566. const Rectangle<int> columnRect (owner.getHeader()->getColumnPosition (owner.getHeader()->getIndexOfColumnId (columnId, true)));
  40567. c->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  40568. }
  40569. }
  40570. }
  40571. void mouseDown (const MouseEvent& e)
  40572. {
  40573. isDragging = false;
  40574. selectRowOnMouseUp = false;
  40575. if (isEnabled())
  40576. {
  40577. if (! isSelected)
  40578. {
  40579. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  40580. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40581. if (columnId != 0 && owner.getModel() != 0)
  40582. owner.getModel()->cellClicked (row, columnId, e);
  40583. }
  40584. else
  40585. {
  40586. selectRowOnMouseUp = true;
  40587. }
  40588. }
  40589. }
  40590. void mouseDrag (const MouseEvent& e)
  40591. {
  40592. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  40593. {
  40594. const SparseSet <int> selectedRows (owner.getSelectedRows());
  40595. if (selectedRows.size() > 0)
  40596. {
  40597. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  40598. if (dragDescription.isNotEmpty())
  40599. {
  40600. isDragging = true;
  40601. owner.startDragAndDrop (e, dragDescription);
  40602. }
  40603. }
  40604. }
  40605. }
  40606. void mouseUp (const MouseEvent& e)
  40607. {
  40608. if (selectRowOnMouseUp && e.mouseWasClicked() && isEnabled())
  40609. {
  40610. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  40611. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40612. if (columnId != 0 && owner.getModel() != 0)
  40613. owner.getModel()->cellClicked (row, columnId, e);
  40614. }
  40615. }
  40616. void mouseDoubleClick (const MouseEvent& e)
  40617. {
  40618. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40619. if (columnId != 0 && owner.getModel() != 0)
  40620. owner.getModel()->cellDoubleClicked (row, columnId, e);
  40621. }
  40622. const String getTooltip()
  40623. {
  40624. const int columnId = owner.getHeader()->getColumnIdAtX (getMouseXYRelative().getX());
  40625. if (columnId != 0 && owner.getModel() != 0)
  40626. return owner.getModel()->getCellTooltip (row, columnId);
  40627. return String::empty;
  40628. }
  40629. juce_UseDebuggingNewOperator
  40630. private:
  40631. TableListBox& owner;
  40632. int row;
  40633. bool isSelected, isDragging, selectRowOnMouseUp;
  40634. BigInteger columnsWithComponents;
  40635. Component* findChildComponentForColumn (const int columnId) const
  40636. {
  40637. for (int i = getNumChildComponents(); --i >= 0;)
  40638. {
  40639. Component* const c = getChildComponent (i);
  40640. if ((int) c->getProperties() [tableColumnPropertyTag] == columnId)
  40641. return c;
  40642. }
  40643. return 0;
  40644. }
  40645. TableListRowComp (const TableListRowComp&);
  40646. TableListRowComp& operator= (const TableListRowComp&);
  40647. };
  40648. class TableListBoxHeader : public TableHeaderComponent
  40649. {
  40650. public:
  40651. TableListBoxHeader (TableListBox& owner_)
  40652. : owner (owner_)
  40653. {
  40654. }
  40655. ~TableListBoxHeader()
  40656. {
  40657. }
  40658. void addMenuItems (PopupMenu& menu, int columnIdClicked)
  40659. {
  40660. if (owner.isAutoSizeMenuOptionShown())
  40661. {
  40662. menu.addItem (0xf836743, TRANS("Auto-size this column"), columnIdClicked != 0);
  40663. menu.addItem (0xf836744, TRANS("Auto-size all columns"), owner.getHeader()->getNumColumns (true) > 0);
  40664. menu.addSeparator();
  40665. }
  40666. TableHeaderComponent::addMenuItems (menu, columnIdClicked);
  40667. }
  40668. void reactToMenuItem (int menuReturnId, int columnIdClicked)
  40669. {
  40670. if (menuReturnId == 0xf836743)
  40671. {
  40672. owner.autoSizeColumn (columnIdClicked);
  40673. }
  40674. else if (menuReturnId == 0xf836744)
  40675. {
  40676. owner.autoSizeAllColumns();
  40677. }
  40678. else
  40679. {
  40680. TableHeaderComponent::reactToMenuItem (menuReturnId, columnIdClicked);
  40681. }
  40682. }
  40683. juce_UseDebuggingNewOperator
  40684. private:
  40685. TableListBox& owner;
  40686. TableListBoxHeader (const TableListBoxHeader&);
  40687. TableListBoxHeader& operator= (const TableListBoxHeader&);
  40688. };
  40689. TableListBox::TableListBox (const String& name, TableListBoxModel* const model_)
  40690. : ListBox (name, 0),
  40691. model (model_),
  40692. autoSizeOptionsShown (true)
  40693. {
  40694. ListBox::model = this;
  40695. header = new TableListBoxHeader (*this);
  40696. header->setSize (100, 28);
  40697. header->addListener (this);
  40698. setHeaderComponent (header);
  40699. }
  40700. TableListBox::~TableListBox()
  40701. {
  40702. deleteAllChildren();
  40703. }
  40704. void TableListBox::setModel (TableListBoxModel* const newModel)
  40705. {
  40706. if (model != newModel)
  40707. {
  40708. model = newModel;
  40709. updateContent();
  40710. }
  40711. }
  40712. int TableListBox::getHeaderHeight() const
  40713. {
  40714. return header->getHeight();
  40715. }
  40716. void TableListBox::setHeaderHeight (const int newHeight)
  40717. {
  40718. header->setSize (header->getWidth(), newHeight);
  40719. resized();
  40720. }
  40721. void TableListBox::autoSizeColumn (const int columnId)
  40722. {
  40723. const int width = model != 0 ? model->getColumnAutoSizeWidth (columnId) : 0;
  40724. if (width > 0)
  40725. header->setColumnWidth (columnId, width);
  40726. }
  40727. void TableListBox::autoSizeAllColumns()
  40728. {
  40729. for (int i = 0; i < header->getNumColumns (true); ++i)
  40730. autoSizeColumn (header->getColumnIdOfIndex (i, true));
  40731. }
  40732. void TableListBox::setAutoSizeMenuOptionShown (const bool shouldBeShown)
  40733. {
  40734. autoSizeOptionsShown = shouldBeShown;
  40735. }
  40736. bool TableListBox::isAutoSizeMenuOptionShown() const
  40737. {
  40738. return autoSizeOptionsShown;
  40739. }
  40740. const Rectangle<int> TableListBox::getCellPosition (const int columnId,
  40741. const int rowNumber,
  40742. const bool relativeToComponentTopLeft) const
  40743. {
  40744. Rectangle<int> headerCell (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  40745. if (relativeToComponentTopLeft)
  40746. headerCell.translate (header->getX(), 0);
  40747. const Rectangle<int> row (getRowPosition (rowNumber, relativeToComponentTopLeft));
  40748. return Rectangle<int> (headerCell.getX(), row.getY(),
  40749. headerCell.getWidth(), row.getHeight());
  40750. }
  40751. void TableListBox::scrollToEnsureColumnIsOnscreen (const int columnId)
  40752. {
  40753. ScrollBar* const scrollbar = getHorizontalScrollBar();
  40754. if (scrollbar != 0)
  40755. {
  40756. const Rectangle<int> pos (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  40757. double x = scrollbar->getCurrentRangeStart();
  40758. const double w = scrollbar->getCurrentRangeSize();
  40759. if (pos.getX() < x)
  40760. x = pos.getX();
  40761. else if (pos.getRight() > x + w)
  40762. x += jmax (0.0, pos.getRight() - (x + w));
  40763. scrollbar->setCurrentRangeStart (x);
  40764. }
  40765. }
  40766. int TableListBox::getNumRows()
  40767. {
  40768. return model != 0 ? model->getNumRows() : 0;
  40769. }
  40770. void TableListBox::paintListBoxItem (int, Graphics&, int, int, bool)
  40771. {
  40772. }
  40773. Component* TableListBox::refreshComponentForRow (int rowNumber, bool isRowSelected_, Component* existingComponentToUpdate)
  40774. {
  40775. if (existingComponentToUpdate == 0)
  40776. existingComponentToUpdate = new TableListRowComp (*this);
  40777. ((TableListRowComp*) existingComponentToUpdate)->update (rowNumber, isRowSelected_);
  40778. return existingComponentToUpdate;
  40779. }
  40780. void TableListBox::selectedRowsChanged (int row)
  40781. {
  40782. if (model != 0)
  40783. model->selectedRowsChanged (row);
  40784. }
  40785. void TableListBox::deleteKeyPressed (int row)
  40786. {
  40787. if (model != 0)
  40788. model->deleteKeyPressed (row);
  40789. }
  40790. void TableListBox::returnKeyPressed (int row)
  40791. {
  40792. if (model != 0)
  40793. model->returnKeyPressed (row);
  40794. }
  40795. void TableListBox::backgroundClicked()
  40796. {
  40797. if (model != 0)
  40798. model->backgroundClicked();
  40799. }
  40800. void TableListBox::listWasScrolled()
  40801. {
  40802. if (model != 0)
  40803. model->listWasScrolled();
  40804. }
  40805. void TableListBox::tableColumnsChanged (TableHeaderComponent*)
  40806. {
  40807. setMinimumContentWidth (header->getTotalWidth());
  40808. repaint();
  40809. updateColumnComponents();
  40810. }
  40811. void TableListBox::tableColumnsResized (TableHeaderComponent*)
  40812. {
  40813. setMinimumContentWidth (header->getTotalWidth());
  40814. repaint();
  40815. updateColumnComponents();
  40816. }
  40817. void TableListBox::tableSortOrderChanged (TableHeaderComponent*)
  40818. {
  40819. if (model != 0)
  40820. model->sortOrderChanged (header->getSortColumnId(),
  40821. header->isSortedForwards());
  40822. }
  40823. void TableListBox::tableColumnDraggingChanged (TableHeaderComponent*, int columnIdNowBeingDragged_)
  40824. {
  40825. columnIdNowBeingDragged = columnIdNowBeingDragged_;
  40826. repaint();
  40827. }
  40828. void TableListBox::resized()
  40829. {
  40830. ListBox::resized();
  40831. header->resizeAllColumnsToFit (getVisibleContentWidth());
  40832. setMinimumContentWidth (header->getTotalWidth());
  40833. }
  40834. void TableListBox::updateColumnComponents() const
  40835. {
  40836. const int firstRow = getRowContainingPosition (0, 0);
  40837. for (int i = firstRow + getNumRowsOnScreen() + 2; --i >= firstRow;)
  40838. {
  40839. TableListRowComp* const rowComp = dynamic_cast <TableListRowComp*> (getComponentForRowNumber (i));
  40840. if (rowComp != 0)
  40841. rowComp->resized();
  40842. }
  40843. }
  40844. void TableListBoxModel::cellClicked (int, int, const MouseEvent&)
  40845. {
  40846. }
  40847. void TableListBoxModel::cellDoubleClicked (int, int, const MouseEvent&)
  40848. {
  40849. }
  40850. void TableListBoxModel::backgroundClicked()
  40851. {
  40852. }
  40853. void TableListBoxModel::sortOrderChanged (int, const bool)
  40854. {
  40855. }
  40856. int TableListBoxModel::getColumnAutoSizeWidth (int)
  40857. {
  40858. return 0;
  40859. }
  40860. void TableListBoxModel::selectedRowsChanged (int)
  40861. {
  40862. }
  40863. void TableListBoxModel::deleteKeyPressed (int)
  40864. {
  40865. }
  40866. void TableListBoxModel::returnKeyPressed (int)
  40867. {
  40868. }
  40869. void TableListBoxModel::listWasScrolled()
  40870. {
  40871. }
  40872. const String TableListBoxModel::getCellTooltip (int /*rowNumber*/, int /*columnId*/)
  40873. {
  40874. return String::empty;
  40875. }
  40876. const String TableListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  40877. {
  40878. return String::empty;
  40879. }
  40880. Component* TableListBoxModel::refreshComponentForCell (int, int, bool, Component* existingComponentToUpdate)
  40881. {
  40882. (void) existingComponentToUpdate;
  40883. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  40884. return 0;
  40885. }
  40886. END_JUCE_NAMESPACE
  40887. /*** End of inlined file: juce_TableListBox.cpp ***/
  40888. /*** Start of inlined file: juce_TextEditor.cpp ***/
  40889. BEGIN_JUCE_NAMESPACE
  40890. // a word or space that can't be broken down any further
  40891. struct TextAtom
  40892. {
  40893. String atomText;
  40894. float width;
  40895. uint16 numChars;
  40896. bool isWhitespace() const { return CharacterFunctions::isWhitespace (atomText[0]); }
  40897. bool isNewLine() const { return atomText[0] == '\r' || atomText[0] == '\n'; }
  40898. const String getText (const tchar passwordCharacter) const
  40899. {
  40900. if (passwordCharacter == 0)
  40901. return atomText;
  40902. else
  40903. return String::repeatedString (String::charToString (passwordCharacter),
  40904. atomText.length());
  40905. }
  40906. const String getTrimmedText (const tchar passwordCharacter) const
  40907. {
  40908. if (passwordCharacter == 0)
  40909. return atomText.substring (0, numChars);
  40910. else if (isNewLine())
  40911. return String::empty;
  40912. else
  40913. return String::repeatedString (String::charToString (passwordCharacter), numChars);
  40914. }
  40915. };
  40916. // a run of text with a single font and colour
  40917. class UniformTextSection
  40918. {
  40919. public:
  40920. UniformTextSection (const String& text,
  40921. const Font& font_,
  40922. const Colour& colour_,
  40923. const tchar passwordCharacter)
  40924. : font (font_),
  40925. colour (colour_)
  40926. {
  40927. initialiseAtoms (text, passwordCharacter);
  40928. }
  40929. UniformTextSection (const UniformTextSection& other)
  40930. : font (other.font),
  40931. colour (other.colour)
  40932. {
  40933. atoms.ensureStorageAllocated (other.atoms.size());
  40934. for (int i = 0; i < other.atoms.size(); ++i)
  40935. atoms.add (new TextAtom (*(const TextAtom*) other.atoms.getUnchecked(i)));
  40936. }
  40937. ~UniformTextSection()
  40938. {
  40939. // (no need to delete the atoms, as they're explicitly deleted by the caller)
  40940. }
  40941. void clear()
  40942. {
  40943. for (int i = atoms.size(); --i >= 0;)
  40944. delete getAtom(i);
  40945. atoms.clear();
  40946. }
  40947. int getNumAtoms() const
  40948. {
  40949. return atoms.size();
  40950. }
  40951. TextAtom* getAtom (const int index) const
  40952. {
  40953. return (TextAtom*) atoms.getUnchecked (index);
  40954. }
  40955. void append (const UniformTextSection& other, const tchar passwordCharacter)
  40956. {
  40957. if (other.atoms.size() > 0)
  40958. {
  40959. TextAtom* const lastAtom = (TextAtom*) atoms.getLast();
  40960. int i = 0;
  40961. if (lastAtom != 0)
  40962. {
  40963. if (! CharacterFunctions::isWhitespace (lastAtom->atomText.getLastCharacter()))
  40964. {
  40965. TextAtom* const first = other.getAtom(0);
  40966. if (! CharacterFunctions::isWhitespace (first->atomText[0]))
  40967. {
  40968. lastAtom->atomText += first->atomText;
  40969. lastAtom->numChars = (uint16) (lastAtom->numChars + first->numChars);
  40970. lastAtom->width = font.getStringWidthFloat (lastAtom->getText (passwordCharacter));
  40971. delete first;
  40972. ++i;
  40973. }
  40974. }
  40975. }
  40976. atoms.ensureStorageAllocated (atoms.size() + other.atoms.size() - i);
  40977. while (i < other.atoms.size())
  40978. {
  40979. atoms.add (other.getAtom(i));
  40980. ++i;
  40981. }
  40982. }
  40983. }
  40984. UniformTextSection* split (const int indexToBreakAt,
  40985. const tchar passwordCharacter)
  40986. {
  40987. UniformTextSection* const section2 = new UniformTextSection (String::empty,
  40988. font, colour,
  40989. passwordCharacter);
  40990. int index = 0;
  40991. for (int i = 0; i < atoms.size(); ++i)
  40992. {
  40993. TextAtom* const atom = getAtom(i);
  40994. const int nextIndex = index + atom->numChars;
  40995. if (index == indexToBreakAt)
  40996. {
  40997. int j;
  40998. for (j = i; j < atoms.size(); ++j)
  40999. section2->atoms.add (getAtom (j));
  41000. for (j = atoms.size(); --j >= i;)
  41001. atoms.remove (j);
  41002. break;
  41003. }
  41004. else if (indexToBreakAt >= index && indexToBreakAt < nextIndex)
  41005. {
  41006. TextAtom* const secondAtom = new TextAtom();
  41007. secondAtom->atomText = atom->atomText.substring (indexToBreakAt - index);
  41008. secondAtom->width = font.getStringWidthFloat (secondAtom->getText (passwordCharacter));
  41009. secondAtom->numChars = (uint16) secondAtom->atomText.length();
  41010. section2->atoms.add (secondAtom);
  41011. atom->atomText = atom->atomText.substring (0, indexToBreakAt - index);
  41012. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41013. atom->numChars = (uint16) (indexToBreakAt - index);
  41014. int j;
  41015. for (j = i + 1; j < atoms.size(); ++j)
  41016. section2->atoms.add (getAtom (j));
  41017. for (j = atoms.size(); --j > i;)
  41018. atoms.remove (j);
  41019. break;
  41020. }
  41021. index = nextIndex;
  41022. }
  41023. return section2;
  41024. }
  41025. void appendAllText (String::Concatenator& concatenator) const
  41026. {
  41027. for (int i = 0; i < atoms.size(); ++i)
  41028. concatenator.append (getAtom(i)->atomText);
  41029. }
  41030. void appendSubstring (String::Concatenator& concatenator,
  41031. const Range<int>& range) const
  41032. {
  41033. int index = 0;
  41034. for (int i = 0; i < atoms.size(); ++i)
  41035. {
  41036. const TextAtom* const atom = getAtom (i);
  41037. const int nextIndex = index + atom->numChars;
  41038. if (range.getStart() < nextIndex)
  41039. {
  41040. if (range.getEnd() <= index)
  41041. break;
  41042. const Range<int> r ((range - index).getIntersectionWith (Range<int> (0, (int) atom->numChars)));
  41043. if (! r.isEmpty())
  41044. concatenator.append (atom->atomText.substring (r.getStart(), r.getEnd()));
  41045. }
  41046. index = nextIndex;
  41047. }
  41048. }
  41049. int getTotalLength() const
  41050. {
  41051. int total = 0;
  41052. for (int i = atoms.size(); --i >= 0;)
  41053. total += getAtom(i)->numChars;
  41054. return total;
  41055. }
  41056. void setFont (const Font& newFont,
  41057. const tchar passwordCharacter)
  41058. {
  41059. if (font != newFont)
  41060. {
  41061. font = newFont;
  41062. for (int i = atoms.size(); --i >= 0;)
  41063. {
  41064. TextAtom* const atom = (TextAtom*) atoms.getUnchecked(i);
  41065. atom->width = newFont.getStringWidthFloat (atom->getText (passwordCharacter));
  41066. }
  41067. }
  41068. }
  41069. juce_UseDebuggingNewOperator
  41070. Font font;
  41071. Colour colour;
  41072. private:
  41073. VoidArray atoms;
  41074. void initialiseAtoms (const String& textToParse,
  41075. const tchar passwordCharacter)
  41076. {
  41077. int i = 0;
  41078. const int len = textToParse.length();
  41079. const tchar* const text = (const tchar*) textToParse;
  41080. while (i < len)
  41081. {
  41082. int start = i;
  41083. // create a whitespace atom unless it starts with non-ws
  41084. if (CharacterFunctions::isWhitespace (text[i])
  41085. && text[i] != '\r'
  41086. && text[i] != '\n')
  41087. {
  41088. while (i < len
  41089. && CharacterFunctions::isWhitespace (text[i])
  41090. && text[i] != '\r'
  41091. && text[i] != '\n')
  41092. {
  41093. ++i;
  41094. }
  41095. }
  41096. else
  41097. {
  41098. if (text[i] == '\r')
  41099. {
  41100. ++i;
  41101. if ((i < len) && (text[i] == '\n'))
  41102. {
  41103. ++start;
  41104. ++i;
  41105. }
  41106. }
  41107. else if (text[i] == '\n')
  41108. {
  41109. ++i;
  41110. }
  41111. else
  41112. {
  41113. while ((i < len) && ! CharacterFunctions::isWhitespace (text[i]))
  41114. ++i;
  41115. }
  41116. }
  41117. TextAtom* const atom = new TextAtom();
  41118. atom->atomText = String (text + start, i - start);
  41119. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41120. atom->numChars = (uint16) (i - start);
  41121. atoms.add (atom);
  41122. }
  41123. }
  41124. UniformTextSection& operator= (const UniformTextSection& other);
  41125. };
  41126. class TextEditorIterator
  41127. {
  41128. public:
  41129. TextEditorIterator (const VoidArray& sections_,
  41130. const float wordWrapWidth_,
  41131. const tchar passwordCharacter_)
  41132. : indexInText (0),
  41133. lineY (0),
  41134. lineHeight (0),
  41135. maxDescent (0),
  41136. atomX (0),
  41137. atomRight (0),
  41138. atom (0),
  41139. currentSection (0),
  41140. sections (sections_),
  41141. sectionIndex (0),
  41142. atomIndex (0),
  41143. wordWrapWidth (wordWrapWidth_),
  41144. passwordCharacter (passwordCharacter_)
  41145. {
  41146. jassert (wordWrapWidth_ > 0);
  41147. if (sections.size() > 0)
  41148. {
  41149. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41150. if (currentSection != 0)
  41151. beginNewLine();
  41152. }
  41153. }
  41154. TextEditorIterator (const TextEditorIterator& other)
  41155. : indexInText (other.indexInText),
  41156. lineY (other.lineY),
  41157. lineHeight (other.lineHeight),
  41158. maxDescent (other.maxDescent),
  41159. atomX (other.atomX),
  41160. atomRight (other.atomRight),
  41161. atom (other.atom),
  41162. currentSection (other.currentSection),
  41163. sections (other.sections),
  41164. sectionIndex (other.sectionIndex),
  41165. atomIndex (other.atomIndex),
  41166. wordWrapWidth (other.wordWrapWidth),
  41167. passwordCharacter (other.passwordCharacter),
  41168. tempAtom (other.tempAtom)
  41169. {
  41170. }
  41171. ~TextEditorIterator()
  41172. {
  41173. }
  41174. bool next()
  41175. {
  41176. if (atom == &tempAtom)
  41177. {
  41178. const int numRemaining = tempAtom.atomText.length() - tempAtom.numChars;
  41179. if (numRemaining > 0)
  41180. {
  41181. tempAtom.atomText = tempAtom.atomText.substring (tempAtom.numChars);
  41182. atomX = 0;
  41183. if (tempAtom.numChars > 0)
  41184. lineY += lineHeight;
  41185. indexInText += tempAtom.numChars;
  41186. GlyphArrangement g;
  41187. g.addLineOfText (currentSection->font, atom->getText (passwordCharacter), 0.0f, 0.0f);
  41188. int split;
  41189. for (split = 0; split < g.getNumGlyphs(); ++split)
  41190. if (shouldWrap (g.getGlyph (split).getRight()))
  41191. break;
  41192. if (split > 0 && split <= numRemaining)
  41193. {
  41194. tempAtom.numChars = (uint16) split;
  41195. tempAtom.width = g.getGlyph (split - 1).getRight();
  41196. atomRight = atomX + tempAtom.width;
  41197. return true;
  41198. }
  41199. }
  41200. }
  41201. bool forceNewLine = false;
  41202. if (sectionIndex >= sections.size())
  41203. {
  41204. moveToEndOfLastAtom();
  41205. return false;
  41206. }
  41207. else if (atomIndex >= currentSection->getNumAtoms() - 1)
  41208. {
  41209. if (atomIndex >= currentSection->getNumAtoms())
  41210. {
  41211. if (++sectionIndex >= sections.size())
  41212. {
  41213. moveToEndOfLastAtom();
  41214. return false;
  41215. }
  41216. atomIndex = 0;
  41217. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41218. }
  41219. else
  41220. {
  41221. const TextAtom* const lastAtom = currentSection->getAtom (atomIndex);
  41222. if (! lastAtom->isWhitespace())
  41223. {
  41224. // handle the case where the last atom in a section is actually part of the same
  41225. // word as the first atom of the next section...
  41226. float right = atomRight + lastAtom->width;
  41227. float lineHeight2 = lineHeight;
  41228. float maxDescent2 = maxDescent;
  41229. for (int section = sectionIndex + 1; section < sections.size(); ++section)
  41230. {
  41231. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked (section);
  41232. if (s->getNumAtoms() == 0)
  41233. break;
  41234. const TextAtom* const nextAtom = s->getAtom (0);
  41235. if (nextAtom->isWhitespace())
  41236. break;
  41237. right += nextAtom->width;
  41238. lineHeight2 = jmax (lineHeight2, s->font.getHeight());
  41239. maxDescent2 = jmax (maxDescent2, s->font.getDescent());
  41240. if (shouldWrap (right))
  41241. {
  41242. lineHeight = lineHeight2;
  41243. maxDescent = maxDescent2;
  41244. forceNewLine = true;
  41245. break;
  41246. }
  41247. if (s->getNumAtoms() > 1)
  41248. break;
  41249. }
  41250. }
  41251. }
  41252. }
  41253. if (atom != 0)
  41254. {
  41255. atomX = atomRight;
  41256. indexInText += atom->numChars;
  41257. if (atom->isNewLine())
  41258. beginNewLine();
  41259. }
  41260. atom = currentSection->getAtom (atomIndex);
  41261. atomRight = atomX + atom->width;
  41262. ++atomIndex;
  41263. if (shouldWrap (atomRight) || forceNewLine)
  41264. {
  41265. if (atom->isWhitespace())
  41266. {
  41267. // leave whitespace at the end of a line, but truncate it to avoid scrolling
  41268. atomRight = jmin (atomRight, wordWrapWidth);
  41269. }
  41270. else
  41271. {
  41272. atomRight = atom->width;
  41273. if (shouldWrap (atomRight)) // atom too big to fit on a line, so break it up..
  41274. {
  41275. tempAtom = *atom;
  41276. tempAtom.width = 0;
  41277. tempAtom.numChars = 0;
  41278. atom = &tempAtom;
  41279. if (atomX > 0)
  41280. beginNewLine();
  41281. return next();
  41282. }
  41283. beginNewLine();
  41284. return true;
  41285. }
  41286. }
  41287. return true;
  41288. }
  41289. void beginNewLine()
  41290. {
  41291. atomX = 0;
  41292. lineY += lineHeight;
  41293. int tempSectionIndex = sectionIndex;
  41294. int tempAtomIndex = atomIndex;
  41295. const UniformTextSection* section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41296. lineHeight = section->font.getHeight();
  41297. maxDescent = section->font.getDescent();
  41298. float x = (atom != 0) ? atom->width : 0;
  41299. while (! shouldWrap (x))
  41300. {
  41301. if (tempSectionIndex >= sections.size())
  41302. break;
  41303. bool checkSize = false;
  41304. if (tempAtomIndex >= section->getNumAtoms())
  41305. {
  41306. if (++tempSectionIndex >= sections.size())
  41307. break;
  41308. tempAtomIndex = 0;
  41309. section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41310. checkSize = true;
  41311. }
  41312. const TextAtom* const nextAtom = section->getAtom (tempAtomIndex);
  41313. if (nextAtom == 0)
  41314. break;
  41315. x += nextAtom->width;
  41316. if (shouldWrap (x) || nextAtom->isNewLine())
  41317. break;
  41318. if (checkSize)
  41319. {
  41320. lineHeight = jmax (lineHeight, section->font.getHeight());
  41321. maxDescent = jmax (maxDescent, section->font.getDescent());
  41322. }
  41323. ++tempAtomIndex;
  41324. }
  41325. }
  41326. void draw (Graphics& g, const UniformTextSection*& lastSection) const
  41327. {
  41328. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41329. {
  41330. if (lastSection != currentSection)
  41331. {
  41332. lastSection = currentSection;
  41333. g.setColour (currentSection->colour);
  41334. g.setFont (currentSection->font);
  41335. }
  41336. jassert (atom->getTrimmedText (passwordCharacter).isNotEmpty());
  41337. GlyphArrangement ga;
  41338. ga.addLineOfText (currentSection->font,
  41339. atom->getTrimmedText (passwordCharacter),
  41340. atomX,
  41341. (float) roundToInt (lineY + lineHeight - maxDescent));
  41342. ga.draw (g);
  41343. }
  41344. }
  41345. void drawSelection (Graphics& g,
  41346. const Range<int>& selection) const
  41347. {
  41348. const int startX = roundToInt (indexToX (selection.getStart()));
  41349. const int endX = roundToInt (indexToX (selection.getEnd()));
  41350. const int y = roundToInt (lineY);
  41351. const int nextY = roundToInt (lineY + lineHeight);
  41352. g.fillRect (startX, y, endX - startX, nextY - y);
  41353. }
  41354. void drawSelectedText (Graphics& g,
  41355. const Range<int>& selection,
  41356. const Colour& selectedTextColour) const
  41357. {
  41358. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41359. {
  41360. GlyphArrangement ga;
  41361. ga.addLineOfText (currentSection->font,
  41362. atom->getTrimmedText (passwordCharacter),
  41363. atomX,
  41364. (float) roundToInt (lineY + lineHeight - maxDescent));
  41365. if (selection.getEnd() < indexInText + atom->numChars)
  41366. {
  41367. GlyphArrangement ga2 (ga);
  41368. ga2.removeRangeOfGlyphs (0, selection.getEnd() - indexInText);
  41369. ga.removeRangeOfGlyphs (selection.getEnd() - indexInText, -1);
  41370. g.setColour (currentSection->colour);
  41371. ga2.draw (g);
  41372. }
  41373. if (selection.getStart() > indexInText)
  41374. {
  41375. GlyphArrangement ga2 (ga);
  41376. ga2.removeRangeOfGlyphs (selection.getStart() - indexInText, -1);
  41377. ga.removeRangeOfGlyphs (0, selection.getStart() - indexInText);
  41378. g.setColour (currentSection->colour);
  41379. ga2.draw (g);
  41380. }
  41381. g.setColour (selectedTextColour);
  41382. ga.draw (g);
  41383. }
  41384. }
  41385. float indexToX (const int indexToFind) const
  41386. {
  41387. if (indexToFind <= indexInText)
  41388. return atomX;
  41389. if (indexToFind >= indexInText + atom->numChars)
  41390. return atomRight;
  41391. GlyphArrangement g;
  41392. g.addLineOfText (currentSection->font,
  41393. atom->getText (passwordCharacter),
  41394. atomX, 0.0f);
  41395. if (indexToFind - indexInText >= g.getNumGlyphs())
  41396. return atomRight;
  41397. return jmin (atomRight, g.getGlyph (indexToFind - indexInText).getLeft());
  41398. }
  41399. int xToIndex (const float xToFind) const
  41400. {
  41401. if (xToFind <= atomX || atom->isNewLine())
  41402. return indexInText;
  41403. if (xToFind >= atomRight)
  41404. return indexInText + atom->numChars;
  41405. GlyphArrangement g;
  41406. g.addLineOfText (currentSection->font,
  41407. atom->getText (passwordCharacter),
  41408. atomX, 0.0f);
  41409. int j;
  41410. for (j = 0; j < g.getNumGlyphs(); ++j)
  41411. if ((g.getGlyph(j).getLeft() + g.getGlyph(j).getRight()) / 2 > xToFind)
  41412. break;
  41413. return indexInText + j;
  41414. }
  41415. bool getCharPosition (const int index, float& cx, float& cy, float& lineHeight_)
  41416. {
  41417. while (next())
  41418. {
  41419. if (indexInText + atom->numChars > index)
  41420. {
  41421. cx = indexToX (index);
  41422. cy = lineY;
  41423. lineHeight_ = lineHeight;
  41424. return true;
  41425. }
  41426. }
  41427. cx = atomX;
  41428. cy = lineY;
  41429. lineHeight_ = lineHeight;
  41430. return false;
  41431. }
  41432. juce_UseDebuggingNewOperator
  41433. int indexInText;
  41434. float lineY, lineHeight, maxDescent;
  41435. float atomX, atomRight;
  41436. const TextAtom* atom;
  41437. const UniformTextSection* currentSection;
  41438. private:
  41439. const VoidArray& sections;
  41440. int sectionIndex, atomIndex;
  41441. const float wordWrapWidth;
  41442. const tchar passwordCharacter;
  41443. TextAtom tempAtom;
  41444. TextEditorIterator& operator= (const TextEditorIterator&);
  41445. void moveToEndOfLastAtom()
  41446. {
  41447. if (atom != 0)
  41448. {
  41449. atomX = atomRight;
  41450. if (atom->isNewLine())
  41451. {
  41452. atomX = 0.0f;
  41453. lineY += lineHeight;
  41454. }
  41455. }
  41456. }
  41457. bool shouldWrap (const float x) const
  41458. {
  41459. return (x - 0.0001f) >= wordWrapWidth;
  41460. }
  41461. };
  41462. class TextEditorInsertAction : public UndoableAction
  41463. {
  41464. TextEditor& owner;
  41465. const String text;
  41466. const int insertIndex, oldCaretPos, newCaretPos;
  41467. const Font font;
  41468. const Colour colour;
  41469. TextEditorInsertAction (const TextEditorInsertAction&);
  41470. TextEditorInsertAction& operator= (const TextEditorInsertAction&);
  41471. public:
  41472. TextEditorInsertAction (TextEditor& owner_,
  41473. const String& text_,
  41474. const int insertIndex_,
  41475. const Font& font_,
  41476. const Colour& colour_,
  41477. const int oldCaretPos_,
  41478. const int newCaretPos_)
  41479. : owner (owner_),
  41480. text (text_),
  41481. insertIndex (insertIndex_),
  41482. oldCaretPos (oldCaretPos_),
  41483. newCaretPos (newCaretPos_),
  41484. font (font_),
  41485. colour (colour_)
  41486. {
  41487. }
  41488. ~TextEditorInsertAction()
  41489. {
  41490. }
  41491. bool perform()
  41492. {
  41493. owner.insert (text, insertIndex, font, colour, 0, newCaretPos);
  41494. return true;
  41495. }
  41496. bool undo()
  41497. {
  41498. owner.remove (Range<int> (insertIndex, insertIndex + text.length()), 0, oldCaretPos);
  41499. return true;
  41500. }
  41501. int getSizeInUnits()
  41502. {
  41503. return text.length() + 16;
  41504. }
  41505. };
  41506. class TextEditorRemoveAction : public UndoableAction
  41507. {
  41508. TextEditor& owner;
  41509. const Range<int> range;
  41510. const int oldCaretPos, newCaretPos;
  41511. VoidArray removedSections;
  41512. TextEditorRemoveAction (const TextEditorRemoveAction&);
  41513. TextEditorRemoveAction& operator= (const TextEditorRemoveAction&);
  41514. public:
  41515. TextEditorRemoveAction (TextEditor& owner_,
  41516. const Range<int> range_,
  41517. const int oldCaretPos_,
  41518. const int newCaretPos_,
  41519. const VoidArray& removedSections_)
  41520. : owner (owner_),
  41521. range (range_),
  41522. oldCaretPos (oldCaretPos_),
  41523. newCaretPos (newCaretPos_),
  41524. removedSections (removedSections_)
  41525. {
  41526. }
  41527. ~TextEditorRemoveAction()
  41528. {
  41529. for (int i = removedSections.size(); --i >= 0;)
  41530. {
  41531. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  41532. section->clear();
  41533. delete section;
  41534. }
  41535. }
  41536. bool perform()
  41537. {
  41538. owner.remove (range, 0, newCaretPos);
  41539. return true;
  41540. }
  41541. bool undo()
  41542. {
  41543. owner.reinsert (range.getStart(), removedSections);
  41544. owner.moveCursorTo (oldCaretPos, false);
  41545. return true;
  41546. }
  41547. int getSizeInUnits()
  41548. {
  41549. int n = 0;
  41550. for (int i = removedSections.size(); --i >= 0;)
  41551. {
  41552. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  41553. n += section->getTotalLength();
  41554. }
  41555. return n + 16;
  41556. }
  41557. };
  41558. class TextHolderComponent : public Component,
  41559. public Timer,
  41560. public Value::Listener
  41561. {
  41562. TextEditor& owner;
  41563. TextHolderComponent (const TextHolderComponent&);
  41564. TextHolderComponent& operator= (const TextHolderComponent&);
  41565. public:
  41566. TextHolderComponent (TextEditor& owner_)
  41567. : owner (owner_)
  41568. {
  41569. setWantsKeyboardFocus (false);
  41570. setInterceptsMouseClicks (false, true);
  41571. owner.getTextValue().addListener (this);
  41572. }
  41573. ~TextHolderComponent()
  41574. {
  41575. owner.getTextValue().removeListener (this);
  41576. }
  41577. void paint (Graphics& g)
  41578. {
  41579. owner.drawContent (g);
  41580. }
  41581. void timerCallback()
  41582. {
  41583. owner.timerCallbackInt();
  41584. }
  41585. const MouseCursor getMouseCursor()
  41586. {
  41587. return owner.getMouseCursor();
  41588. }
  41589. void valueChanged (Value&)
  41590. {
  41591. owner.textWasChangedByValue();
  41592. }
  41593. };
  41594. class TextEditorViewport : public Viewport
  41595. {
  41596. TextEditor* const owner;
  41597. float lastWordWrapWidth;
  41598. TextEditorViewport (const TextEditorViewport&);
  41599. TextEditorViewport& operator= (const TextEditorViewport&);
  41600. public:
  41601. TextEditorViewport (TextEditor* const owner_)
  41602. : owner (owner_),
  41603. lastWordWrapWidth (0)
  41604. {
  41605. }
  41606. ~TextEditorViewport()
  41607. {
  41608. }
  41609. void visibleAreaChanged (int, int, int, int)
  41610. {
  41611. const float wordWrapWidth = owner->getWordWrapWidth();
  41612. if (wordWrapWidth != lastWordWrapWidth)
  41613. {
  41614. lastWordWrapWidth = wordWrapWidth;
  41615. owner->updateTextHolderSize();
  41616. }
  41617. }
  41618. };
  41619. namespace TextEditorDefs
  41620. {
  41621. const int flashSpeedIntervalMs = 380;
  41622. const int textChangeMessageId = 0x10003001;
  41623. const int returnKeyMessageId = 0x10003002;
  41624. const int escapeKeyMessageId = 0x10003003;
  41625. const int focusLossMessageId = 0x10003004;
  41626. const int maxActionsPerTransaction = 100;
  41627. }
  41628. TextEditor::TextEditor (const String& name,
  41629. const tchar passwordCharacter_)
  41630. : Component (name),
  41631. borderSize (1, 1, 1, 3),
  41632. readOnly (false),
  41633. multiline (false),
  41634. wordWrap (false),
  41635. returnKeyStartsNewLine (false),
  41636. caretVisible (true),
  41637. popupMenuEnabled (true),
  41638. selectAllTextWhenFocused (false),
  41639. scrollbarVisible (true),
  41640. wasFocused (false),
  41641. caretFlashState (true),
  41642. keepCursorOnScreen (true),
  41643. tabKeyUsed (false),
  41644. menuActive (false),
  41645. valueTextNeedsUpdating (false),
  41646. cursorX (0),
  41647. cursorY (0),
  41648. cursorHeight (0),
  41649. maxTextLength (0),
  41650. leftIndent (4),
  41651. topIndent (4),
  41652. lastTransactionTime (0),
  41653. currentFont (14.0f),
  41654. totalNumChars (0),
  41655. caretPosition (0),
  41656. passwordCharacter (passwordCharacter_),
  41657. dragType (notDragging)
  41658. {
  41659. setOpaque (true);
  41660. addAndMakeVisible (viewport = new TextEditorViewport (this));
  41661. viewport->setViewedComponent (textHolder = new TextHolderComponent (*this));
  41662. viewport->setWantsKeyboardFocus (false);
  41663. viewport->setScrollBarsShown (false, false);
  41664. setMouseCursor (MouseCursor::IBeamCursor);
  41665. setWantsKeyboardFocus (true);
  41666. }
  41667. TextEditor::~TextEditor()
  41668. {
  41669. textValue.referTo (Value());
  41670. clearInternal (0);
  41671. viewport = 0;
  41672. textHolder = 0;
  41673. }
  41674. void TextEditor::newTransaction()
  41675. {
  41676. lastTransactionTime = Time::getApproximateMillisecondCounter();
  41677. undoManager.beginNewTransaction();
  41678. }
  41679. void TextEditor::doUndoRedo (const bool isRedo)
  41680. {
  41681. if (! isReadOnly())
  41682. {
  41683. if (isRedo ? undoManager.redo()
  41684. : undoManager.undo())
  41685. {
  41686. scrollToMakeSureCursorIsVisible();
  41687. repaint();
  41688. textChanged();
  41689. }
  41690. }
  41691. }
  41692. void TextEditor::setMultiLine (const bool shouldBeMultiLine,
  41693. const bool shouldWordWrap)
  41694. {
  41695. multiline = shouldBeMultiLine;
  41696. wordWrap = shouldWordWrap && shouldBeMultiLine;
  41697. setScrollbarsShown (scrollbarVisible);
  41698. viewport->setViewPosition (0, 0);
  41699. resized();
  41700. scrollToMakeSureCursorIsVisible();
  41701. }
  41702. bool TextEditor::isMultiLine() const
  41703. {
  41704. return multiline;
  41705. }
  41706. void TextEditor::setScrollbarsShown (bool enabled)
  41707. {
  41708. scrollbarVisible = enabled;
  41709. enabled = enabled && isMultiLine();
  41710. viewport->setScrollBarsShown (enabled, enabled);
  41711. }
  41712. void TextEditor::setReadOnly (const bool shouldBeReadOnly)
  41713. {
  41714. readOnly = shouldBeReadOnly;
  41715. enablementChanged();
  41716. }
  41717. bool TextEditor::isReadOnly() const
  41718. {
  41719. return readOnly || ! isEnabled();
  41720. }
  41721. void TextEditor::setReturnKeyStartsNewLine (const bool shouldStartNewLine)
  41722. {
  41723. returnKeyStartsNewLine = shouldStartNewLine;
  41724. }
  41725. void TextEditor::setTabKeyUsedAsCharacter (const bool shouldTabKeyBeUsed)
  41726. {
  41727. tabKeyUsed = shouldTabKeyBeUsed;
  41728. }
  41729. void TextEditor::setPopupMenuEnabled (const bool b)
  41730. {
  41731. popupMenuEnabled = b;
  41732. }
  41733. void TextEditor::setSelectAllWhenFocused (const bool b)
  41734. {
  41735. selectAllTextWhenFocused = b;
  41736. }
  41737. const Font TextEditor::getFont() const
  41738. {
  41739. return currentFont;
  41740. }
  41741. void TextEditor::setFont (const Font& newFont)
  41742. {
  41743. currentFont = newFont;
  41744. scrollToMakeSureCursorIsVisible();
  41745. }
  41746. void TextEditor::applyFontToAllText (const Font& newFont)
  41747. {
  41748. currentFont = newFont;
  41749. const Colour overallColour (findColour (textColourId));
  41750. for (int i = sections.size(); --i >= 0;)
  41751. {
  41752. UniformTextSection* const uts = (UniformTextSection*) sections.getUnchecked(i);
  41753. uts->setFont (newFont, passwordCharacter);
  41754. uts->colour = overallColour;
  41755. }
  41756. coalesceSimilarSections();
  41757. updateTextHolderSize();
  41758. scrollToMakeSureCursorIsVisible();
  41759. repaint();
  41760. }
  41761. void TextEditor::colourChanged()
  41762. {
  41763. setOpaque (findColour (backgroundColourId).isOpaque());
  41764. repaint();
  41765. }
  41766. void TextEditor::setCaretVisible (const bool shouldCaretBeVisible)
  41767. {
  41768. caretVisible = shouldCaretBeVisible;
  41769. if (shouldCaretBeVisible)
  41770. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  41771. setMouseCursor (shouldCaretBeVisible ? MouseCursor::IBeamCursor
  41772. : MouseCursor::NormalCursor);
  41773. }
  41774. void TextEditor::setInputRestrictions (const int maxLen,
  41775. const String& chars)
  41776. {
  41777. maxTextLength = jmax (0, maxLen);
  41778. allowedCharacters = chars;
  41779. }
  41780. void TextEditor::setTextToShowWhenEmpty (const String& text, const Colour& colourToUse)
  41781. {
  41782. textToShowWhenEmpty = text;
  41783. colourForTextWhenEmpty = colourToUse;
  41784. }
  41785. void TextEditor::setPasswordCharacter (const tchar newPasswordCharacter)
  41786. {
  41787. if (passwordCharacter != newPasswordCharacter)
  41788. {
  41789. passwordCharacter = newPasswordCharacter;
  41790. resized();
  41791. repaint();
  41792. }
  41793. }
  41794. void TextEditor::setScrollBarThickness (const int newThicknessPixels)
  41795. {
  41796. viewport->setScrollBarThickness (newThicknessPixels);
  41797. }
  41798. void TextEditor::setScrollBarButtonVisibility (const bool buttonsVisible)
  41799. {
  41800. viewport->setScrollBarButtonVisibility (buttonsVisible);
  41801. }
  41802. void TextEditor::clear()
  41803. {
  41804. clearInternal (0);
  41805. updateTextHolderSize();
  41806. undoManager.clearUndoHistory();
  41807. }
  41808. void TextEditor::setText (const String& newText,
  41809. const bool sendTextChangeMessage)
  41810. {
  41811. const int newLength = newText.length();
  41812. if (newLength != getTotalNumChars() || getText() != newText)
  41813. {
  41814. const int oldCursorPos = caretPosition;
  41815. const bool cursorWasAtEnd = oldCursorPos >= getTotalNumChars();
  41816. clearInternal (0);
  41817. insert (newText, 0, currentFont, findColour (textColourId), 0, caretPosition);
  41818. // if you're adding text with line-feeds to a single-line text editor, it
  41819. // ain't gonna look right!
  41820. jassert (multiline || ! newText.containsAnyOf (T("\r\n")));
  41821. if (cursorWasAtEnd && ! isMultiLine())
  41822. moveCursorTo (getTotalNumChars(), false);
  41823. else
  41824. moveCursorTo (oldCursorPos, false);
  41825. if (sendTextChangeMessage)
  41826. textChanged();
  41827. repaint();
  41828. }
  41829. updateTextHolderSize();
  41830. scrollToMakeSureCursorIsVisible();
  41831. undoManager.clearUndoHistory();
  41832. }
  41833. Value& TextEditor::getTextValue()
  41834. {
  41835. if (valueTextNeedsUpdating)
  41836. {
  41837. valueTextNeedsUpdating = false;
  41838. textValue = getText();
  41839. }
  41840. return textValue;
  41841. }
  41842. void TextEditor::textWasChangedByValue()
  41843. {
  41844. if (textValue.getValueSource().getReferenceCount() > 1)
  41845. setText (textValue.getValue());
  41846. }
  41847. void TextEditor::textChanged()
  41848. {
  41849. updateTextHolderSize();
  41850. postCommandMessage (TextEditorDefs::textChangeMessageId);
  41851. if (textValue.getValueSource().getReferenceCount() > 1)
  41852. {
  41853. valueTextNeedsUpdating = false;
  41854. textValue = getText();
  41855. }
  41856. }
  41857. void TextEditor::returnPressed()
  41858. {
  41859. postCommandMessage (TextEditorDefs::returnKeyMessageId);
  41860. }
  41861. void TextEditor::escapePressed()
  41862. {
  41863. postCommandMessage (TextEditorDefs::escapeKeyMessageId);
  41864. }
  41865. void TextEditor::addListener (TextEditorListener* const newListener)
  41866. {
  41867. listeners.add (newListener);
  41868. }
  41869. void TextEditor::removeListener (TextEditorListener* const listenerToRemove)
  41870. {
  41871. listeners.remove (listenerToRemove);
  41872. }
  41873. void TextEditor::timerCallbackInt()
  41874. {
  41875. const bool newState = (! caretFlashState) && ! isCurrentlyBlockedByAnotherModalComponent();
  41876. if (caretFlashState != newState)
  41877. {
  41878. caretFlashState = newState;
  41879. if (caretFlashState)
  41880. wasFocused = true;
  41881. if (caretVisible
  41882. && hasKeyboardFocus (false)
  41883. && ! isReadOnly())
  41884. {
  41885. repaintCaret();
  41886. }
  41887. }
  41888. const unsigned int now = Time::getApproximateMillisecondCounter();
  41889. if (now > lastTransactionTime + 200)
  41890. newTransaction();
  41891. }
  41892. void TextEditor::repaintCaret()
  41893. {
  41894. if (! findColour (caretColourId).isTransparent())
  41895. repaint (borderSize.getLeft() + textHolder->getX() + leftIndent + roundToInt (cursorX) - 1,
  41896. borderSize.getTop() + textHolder->getY() + topIndent + roundToInt (cursorY) - 1,
  41897. 4,
  41898. roundToInt (cursorHeight) + 2);
  41899. }
  41900. void TextEditor::repaintText (const Range<int>& range)
  41901. {
  41902. if (! range.isEmpty())
  41903. {
  41904. float x = 0, y = 0, lh = currentFont.getHeight();
  41905. const float wordWrapWidth = getWordWrapWidth();
  41906. if (wordWrapWidth > 0)
  41907. {
  41908. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  41909. i.getCharPosition (range.getStart(), x, y, lh);
  41910. const int y1 = (int) y;
  41911. int y2;
  41912. if (range.getEnd() >= getTotalNumChars())
  41913. {
  41914. y2 = textHolder->getHeight();
  41915. }
  41916. else
  41917. {
  41918. i.getCharPosition (range.getEnd(), x, y, lh);
  41919. y2 = (int) (y + lh * 2.0f);
  41920. }
  41921. textHolder->repaint (0, y1, textHolder->getWidth(), y2 - y1);
  41922. }
  41923. }
  41924. }
  41925. void TextEditor::moveCaret (int newCaretPos)
  41926. {
  41927. if (newCaretPos < 0)
  41928. newCaretPos = 0;
  41929. else if (newCaretPos > getTotalNumChars())
  41930. newCaretPos = getTotalNumChars();
  41931. if (newCaretPos != getCaretPosition())
  41932. {
  41933. repaintCaret();
  41934. caretFlashState = true;
  41935. caretPosition = newCaretPos;
  41936. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  41937. scrollToMakeSureCursorIsVisible();
  41938. repaintCaret();
  41939. }
  41940. }
  41941. void TextEditor::setCaretPosition (const int newIndex)
  41942. {
  41943. moveCursorTo (newIndex, false);
  41944. }
  41945. int TextEditor::getCaretPosition() const
  41946. {
  41947. return caretPosition;
  41948. }
  41949. void TextEditor::scrollEditorToPositionCaret (const int desiredCaretX,
  41950. const int desiredCaretY)
  41951. {
  41952. updateCaretPosition();
  41953. int vx = roundToInt (cursorX) - desiredCaretX;
  41954. int vy = roundToInt (cursorY) - desiredCaretY;
  41955. if (desiredCaretX < jmax (1, proportionOfWidth (0.05f)))
  41956. {
  41957. vx += desiredCaretX - proportionOfWidth (0.2f);
  41958. }
  41959. else if (desiredCaretX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  41960. {
  41961. vx += desiredCaretX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  41962. }
  41963. vx = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), vx);
  41964. if (! isMultiLine())
  41965. {
  41966. vy = viewport->getViewPositionY();
  41967. }
  41968. else
  41969. {
  41970. vy = jlimit (0, jmax (0, textHolder->getHeight() - viewport->getMaximumVisibleHeight()), vy);
  41971. const int curH = roundToInt (cursorHeight);
  41972. if (desiredCaretY < 0)
  41973. {
  41974. vy = jmax (0, desiredCaretY + vy);
  41975. }
  41976. else if (desiredCaretY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  41977. {
  41978. vy += desiredCaretY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  41979. }
  41980. }
  41981. viewport->setViewPosition (vx, vy);
  41982. }
  41983. const Rectangle<int> TextEditor::getCaretRectangle()
  41984. {
  41985. updateCaretPosition();
  41986. return Rectangle<int> (roundToInt (cursorX) - viewport->getX(),
  41987. roundToInt (cursorY) - viewport->getY(),
  41988. 1, roundToInt (cursorHeight));
  41989. }
  41990. float TextEditor::getWordWrapWidth() const
  41991. {
  41992. return (wordWrap) ? (float) (viewport->getMaximumVisibleWidth() - leftIndent - leftIndent / 2)
  41993. : 1.0e10f;
  41994. }
  41995. void TextEditor::updateTextHolderSize()
  41996. {
  41997. const float wordWrapWidth = getWordWrapWidth();
  41998. if (wordWrapWidth > 0)
  41999. {
  42000. float maxWidth = 0.0f;
  42001. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42002. while (i.next())
  42003. maxWidth = jmax (maxWidth, i.atomRight);
  42004. const int w = leftIndent + roundToInt (maxWidth);
  42005. const int h = topIndent + roundToInt (jmax (i.lineY + i.lineHeight,
  42006. currentFont.getHeight()));
  42007. textHolder->setSize (w + 1, h + 1);
  42008. }
  42009. }
  42010. int TextEditor::getTextWidth() const
  42011. {
  42012. return textHolder->getWidth();
  42013. }
  42014. int TextEditor::getTextHeight() const
  42015. {
  42016. return textHolder->getHeight();
  42017. }
  42018. void TextEditor::setIndents (const int newLeftIndent,
  42019. const int newTopIndent)
  42020. {
  42021. leftIndent = newLeftIndent;
  42022. topIndent = newTopIndent;
  42023. }
  42024. void TextEditor::setBorder (const BorderSize& border)
  42025. {
  42026. borderSize = border;
  42027. resized();
  42028. }
  42029. const BorderSize TextEditor::getBorder() const
  42030. {
  42031. return borderSize;
  42032. }
  42033. void TextEditor::setScrollToShowCursor (const bool shouldScrollToShowCursor)
  42034. {
  42035. keepCursorOnScreen = shouldScrollToShowCursor;
  42036. }
  42037. void TextEditor::updateCaretPosition()
  42038. {
  42039. cursorHeight = currentFont.getHeight(); // (in case the text is empty and the call below doesn't set this value)
  42040. getCharPosition (caretPosition, cursorX, cursorY, cursorHeight);
  42041. }
  42042. void TextEditor::scrollToMakeSureCursorIsVisible()
  42043. {
  42044. updateCaretPosition();
  42045. if (keepCursorOnScreen)
  42046. {
  42047. int x = viewport->getViewPositionX();
  42048. int y = viewport->getViewPositionY();
  42049. const int relativeCursorX = roundToInt (cursorX) - x;
  42050. const int relativeCursorY = roundToInt (cursorY) - y;
  42051. if (relativeCursorX < jmax (1, proportionOfWidth (0.05f)))
  42052. {
  42053. x += relativeCursorX - proportionOfWidth (0.2f);
  42054. }
  42055. else if (relativeCursorX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  42056. {
  42057. x += relativeCursorX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  42058. }
  42059. x = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), x);
  42060. if (! isMultiLine())
  42061. {
  42062. y = (getHeight() - textHolder->getHeight() - topIndent) / -2;
  42063. }
  42064. else
  42065. {
  42066. const int curH = roundToInt (cursorHeight);
  42067. if (relativeCursorY < 0)
  42068. {
  42069. y = jmax (0, relativeCursorY + y);
  42070. }
  42071. else if (relativeCursorY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42072. {
  42073. y += relativeCursorY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42074. }
  42075. }
  42076. viewport->setViewPosition (x, y);
  42077. }
  42078. }
  42079. void TextEditor::moveCursorTo (const int newPosition,
  42080. const bool isSelecting)
  42081. {
  42082. if (isSelecting)
  42083. {
  42084. moveCaret (newPosition);
  42085. const Range<int> oldSelection (selection);
  42086. if (dragType == notDragging)
  42087. {
  42088. if (abs (getCaretPosition() - selection.getStart()) < abs (getCaretPosition() - selection.getEnd()))
  42089. dragType = draggingSelectionStart;
  42090. else
  42091. dragType = draggingSelectionEnd;
  42092. }
  42093. if (dragType == draggingSelectionStart)
  42094. {
  42095. if (getCaretPosition() >= selection.getEnd())
  42096. dragType = draggingSelectionEnd;
  42097. selection = Range<int>::between (getCaretPosition(), selection.getEnd());
  42098. }
  42099. else
  42100. {
  42101. if (getCaretPosition() < selection.getStart())
  42102. dragType = draggingSelectionStart;
  42103. selection = Range<int>::between (getCaretPosition(), selection.getStart());
  42104. }
  42105. repaintText (selection.getUnionWith (oldSelection));
  42106. }
  42107. else
  42108. {
  42109. dragType = notDragging;
  42110. repaintText (selection);
  42111. moveCaret (newPosition);
  42112. selection = Range<int>::emptyRange (getCaretPosition());
  42113. }
  42114. }
  42115. int TextEditor::getTextIndexAt (const int x,
  42116. const int y)
  42117. {
  42118. return indexAtPosition ((float) (x + viewport->getViewPositionX() - leftIndent),
  42119. (float) (y + viewport->getViewPositionY() - topIndent));
  42120. }
  42121. void TextEditor::insertTextAtCaret (const String& newText_)
  42122. {
  42123. String newText (newText_);
  42124. if (allowedCharacters.isNotEmpty())
  42125. newText = newText.retainCharacters (allowedCharacters);
  42126. if ((! returnKeyStartsNewLine) && newText == "\n")
  42127. {
  42128. returnPressed();
  42129. return;
  42130. }
  42131. if (! isMultiLine())
  42132. newText = newText.replaceCharacters (T("\r\n"), T(" "));
  42133. else
  42134. newText = newText.replace (T("\r\n"), T("\n"));
  42135. const int newCaretPos = selection.getStart() + newText.length();
  42136. const int insertIndex = selection.getStart();
  42137. remove (selection, getUndoManager(),
  42138. newText.isNotEmpty() ? newCaretPos - 1 : newCaretPos);
  42139. if (maxTextLength > 0)
  42140. newText = newText.substring (0, maxTextLength - getTotalNumChars());
  42141. if (newText.isNotEmpty())
  42142. insert (newText,
  42143. insertIndex,
  42144. currentFont,
  42145. findColour (textColourId),
  42146. getUndoManager(),
  42147. newCaretPos);
  42148. textChanged();
  42149. }
  42150. void TextEditor::setHighlightedRegion (const Range<int>& newSelection)
  42151. {
  42152. moveCursorTo (newSelection.getStart(), false);
  42153. moveCursorTo (newSelection.getEnd(), true);
  42154. }
  42155. void TextEditor::copy()
  42156. {
  42157. if (passwordCharacter == 0)
  42158. {
  42159. const String selection (getHighlightedText());
  42160. if (selection.isNotEmpty())
  42161. SystemClipboard::copyTextToClipboard (selection);
  42162. }
  42163. }
  42164. void TextEditor::paste()
  42165. {
  42166. if (! isReadOnly())
  42167. {
  42168. const String clip (SystemClipboard::getTextFromClipboard());
  42169. if (clip.isNotEmpty())
  42170. insertTextAtCaret (clip);
  42171. }
  42172. }
  42173. void TextEditor::cut()
  42174. {
  42175. if (! isReadOnly())
  42176. {
  42177. moveCaret (selection.getEnd());
  42178. insertTextAtCaret (String::empty);
  42179. }
  42180. }
  42181. void TextEditor::drawContent (Graphics& g)
  42182. {
  42183. const float wordWrapWidth = getWordWrapWidth();
  42184. if (wordWrapWidth > 0)
  42185. {
  42186. g.setOrigin (leftIndent, topIndent);
  42187. const Rectangle<int> clip (g.getClipBounds());
  42188. Colour selectedTextColour;
  42189. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42190. while (i.lineY + 200.0 < clip.getY() && i.next())
  42191. {}
  42192. if (! selection.isEmpty())
  42193. {
  42194. g.setColour (findColour (highlightColourId)
  42195. .withMultipliedAlpha (hasKeyboardFocus (true) ? 1.0f : 0.5f));
  42196. selectedTextColour = findColour (highlightedTextColourId);
  42197. TextEditorIterator i2 (i);
  42198. while (i2.next() && i2.lineY < clip.getBottom())
  42199. {
  42200. if (i2.lineY + i2.lineHeight >= clip.getY()
  42201. && selection.intersects (Range<int> (i2.indexInText, i2.indexInText + i2.atom->numChars)))
  42202. {
  42203. i2.drawSelection (g, selection);
  42204. }
  42205. }
  42206. }
  42207. const UniformTextSection* lastSection = 0;
  42208. while (i.next() && i.lineY < clip.getBottom())
  42209. {
  42210. if (i.lineY + i.lineHeight >= clip.getY())
  42211. {
  42212. if (selection.intersects (Range<int> (i.indexInText, i.indexInText + i.atom->numChars)))
  42213. {
  42214. i.drawSelectedText (g, selection, selectedTextColour);
  42215. lastSection = 0;
  42216. }
  42217. else
  42218. {
  42219. i.draw (g, lastSection);
  42220. }
  42221. }
  42222. }
  42223. }
  42224. }
  42225. void TextEditor::paint (Graphics& g)
  42226. {
  42227. getLookAndFeel().fillTextEditorBackground (g, getWidth(), getHeight(), *this);
  42228. }
  42229. void TextEditor::paintOverChildren (Graphics& g)
  42230. {
  42231. if (caretFlashState
  42232. && hasKeyboardFocus (false)
  42233. && caretVisible
  42234. && ! isReadOnly())
  42235. {
  42236. g.setColour (findColour (caretColourId));
  42237. g.fillRect (borderSize.getLeft() + textHolder->getX() + leftIndent + cursorX,
  42238. borderSize.getTop() + textHolder->getY() + topIndent + cursorY,
  42239. 2.0f, cursorHeight);
  42240. }
  42241. if (textToShowWhenEmpty.isNotEmpty()
  42242. && (! hasKeyboardFocus (false))
  42243. && getTotalNumChars() == 0)
  42244. {
  42245. g.setColour (colourForTextWhenEmpty);
  42246. g.setFont (getFont());
  42247. if (isMultiLine())
  42248. {
  42249. g.drawText (textToShowWhenEmpty,
  42250. 0, 0, getWidth(), getHeight(),
  42251. Justification::centred, true);
  42252. }
  42253. else
  42254. {
  42255. g.drawText (textToShowWhenEmpty,
  42256. leftIndent, topIndent,
  42257. viewport->getWidth() - leftIndent,
  42258. viewport->getHeight() - topIndent,
  42259. Justification::centredLeft, true);
  42260. }
  42261. }
  42262. getLookAndFeel().drawTextEditorOutline (g, getWidth(), getHeight(), *this);
  42263. }
  42264. void TextEditor::mouseDown (const MouseEvent& e)
  42265. {
  42266. beginDragAutoRepeat (100);
  42267. newTransaction();
  42268. if (wasFocused || ! selectAllTextWhenFocused)
  42269. {
  42270. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42271. {
  42272. moveCursorTo (getTextIndexAt (e.x, e.y),
  42273. e.mods.isShiftDown());
  42274. }
  42275. else
  42276. {
  42277. PopupMenu m;
  42278. m.setLookAndFeel (&getLookAndFeel());
  42279. addPopupMenuItems (m, &e);
  42280. menuActive = true;
  42281. const int result = m.show();
  42282. menuActive = false;
  42283. if (result != 0)
  42284. performPopupMenuAction (result);
  42285. }
  42286. }
  42287. }
  42288. void TextEditor::mouseDrag (const MouseEvent& e)
  42289. {
  42290. if (wasFocused || ! selectAllTextWhenFocused)
  42291. {
  42292. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42293. {
  42294. moveCursorTo (getTextIndexAt (e.x, e.y), true);
  42295. }
  42296. }
  42297. }
  42298. void TextEditor::mouseUp (const MouseEvent& e)
  42299. {
  42300. newTransaction();
  42301. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42302. if (wasFocused || ! selectAllTextWhenFocused)
  42303. {
  42304. if (e.mouseWasClicked() && ! (popupMenuEnabled && e.mods.isPopupMenu()))
  42305. {
  42306. moveCaret (getTextIndexAt (e.x, e.y));
  42307. }
  42308. }
  42309. wasFocused = true;
  42310. }
  42311. void TextEditor::mouseDoubleClick (const MouseEvent& e)
  42312. {
  42313. int tokenEnd = getTextIndexAt (e.x, e.y);
  42314. int tokenStart = tokenEnd;
  42315. if (e.getNumberOfClicks() > 3)
  42316. {
  42317. tokenStart = 0;
  42318. tokenEnd = getTotalNumChars();
  42319. }
  42320. else
  42321. {
  42322. const String t (getText());
  42323. const int totalLength = getTotalNumChars();
  42324. while (tokenEnd < totalLength)
  42325. {
  42326. if (CharacterFunctions::isLetterOrDigit (t [tokenEnd]))
  42327. ++tokenEnd;
  42328. else
  42329. break;
  42330. }
  42331. tokenStart = tokenEnd;
  42332. while (tokenStart > 0)
  42333. {
  42334. if (CharacterFunctions::isLetterOrDigit (t [tokenStart - 1]))
  42335. --tokenStart;
  42336. else
  42337. break;
  42338. }
  42339. if (e.getNumberOfClicks() > 2)
  42340. {
  42341. while (tokenEnd < totalLength)
  42342. {
  42343. if (t [tokenEnd] != '\r' && t [tokenEnd] != '\n')
  42344. ++tokenEnd;
  42345. else
  42346. break;
  42347. }
  42348. while (tokenStart > 0)
  42349. {
  42350. if (t [tokenStart - 1] != '\r' && t [tokenStart - 1] != '\n')
  42351. --tokenStart;
  42352. else
  42353. break;
  42354. }
  42355. }
  42356. }
  42357. moveCursorTo (tokenEnd, false);
  42358. moveCursorTo (tokenStart, true);
  42359. }
  42360. void TextEditor::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  42361. {
  42362. if (! viewport->useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  42363. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  42364. }
  42365. bool TextEditor::keyPressed (const KeyPress& key)
  42366. {
  42367. if (isReadOnly() && key != KeyPress ('c', ModifierKeys::commandModifier, 0))
  42368. return false;
  42369. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  42370. if (key.isKeyCode (KeyPress::leftKey)
  42371. || key.isKeyCode (KeyPress::upKey))
  42372. {
  42373. newTransaction();
  42374. int newPos;
  42375. if (isMultiLine() && key.isKeyCode (KeyPress::upKey))
  42376. newPos = indexAtPosition (cursorX, cursorY - 1);
  42377. else if (moveInWholeWordSteps)
  42378. newPos = findWordBreakBefore (getCaretPosition());
  42379. else
  42380. newPos = getCaretPosition() - 1;
  42381. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42382. }
  42383. else if (key.isKeyCode (KeyPress::rightKey)
  42384. || key.isKeyCode (KeyPress::downKey))
  42385. {
  42386. newTransaction();
  42387. int newPos;
  42388. if (isMultiLine() && key.isKeyCode (KeyPress::downKey))
  42389. newPos = indexAtPosition (cursorX, cursorY + cursorHeight + 1);
  42390. else if (moveInWholeWordSteps)
  42391. newPos = findWordBreakAfter (getCaretPosition());
  42392. else
  42393. newPos = getCaretPosition() + 1;
  42394. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42395. }
  42396. else if (key.isKeyCode (KeyPress::pageDownKey) && isMultiLine())
  42397. {
  42398. newTransaction();
  42399. moveCursorTo (indexAtPosition (cursorX, cursorY + cursorHeight + viewport->getViewHeight()),
  42400. key.getModifiers().isShiftDown());
  42401. }
  42402. else if (key.isKeyCode (KeyPress::pageUpKey) && isMultiLine())
  42403. {
  42404. newTransaction();
  42405. moveCursorTo (indexAtPosition (cursorX, cursorY - viewport->getViewHeight()),
  42406. key.getModifiers().isShiftDown());
  42407. }
  42408. else if (key.isKeyCode (KeyPress::homeKey))
  42409. {
  42410. newTransaction();
  42411. if (isMultiLine() && ! moveInWholeWordSteps)
  42412. moveCursorTo (indexAtPosition (0.0f, cursorY),
  42413. key.getModifiers().isShiftDown());
  42414. else
  42415. moveCursorTo (0, key.getModifiers().isShiftDown());
  42416. }
  42417. else if (key.isKeyCode (KeyPress::endKey))
  42418. {
  42419. newTransaction();
  42420. if (isMultiLine() && ! moveInWholeWordSteps)
  42421. moveCursorTo (indexAtPosition ((float) textHolder->getWidth(), cursorY),
  42422. key.getModifiers().isShiftDown());
  42423. else
  42424. moveCursorTo (getTotalNumChars(), key.getModifiers().isShiftDown());
  42425. }
  42426. else if (key.isKeyCode (KeyPress::backspaceKey))
  42427. {
  42428. if (moveInWholeWordSteps)
  42429. {
  42430. moveCursorTo (findWordBreakBefore (getCaretPosition()), true);
  42431. }
  42432. else
  42433. {
  42434. if (selection.isEmpty() && selection.getStart() > 0)
  42435. selection.setStart (selection.getEnd() - 1);
  42436. }
  42437. cut();
  42438. }
  42439. else if (key.isKeyCode (KeyPress::deleteKey))
  42440. {
  42441. if (key.getModifiers().isShiftDown())
  42442. copy();
  42443. if (selection.isEmpty() && selection.getStart() < getTotalNumChars())
  42444. selection.setEnd (selection.getStart() + 1);
  42445. cut();
  42446. }
  42447. else if (key == KeyPress ('c', ModifierKeys::commandModifier, 0)
  42448. || key == KeyPress (KeyPress::insertKey, ModifierKeys::ctrlModifier, 0))
  42449. {
  42450. newTransaction();
  42451. copy();
  42452. }
  42453. else if (key == KeyPress ('x', ModifierKeys::commandModifier, 0))
  42454. {
  42455. newTransaction();
  42456. copy();
  42457. cut();
  42458. }
  42459. else if (key == KeyPress ('v', ModifierKeys::commandModifier, 0)
  42460. || key == KeyPress (KeyPress::insertKey, ModifierKeys::shiftModifier, 0))
  42461. {
  42462. newTransaction();
  42463. paste();
  42464. }
  42465. else if (key == KeyPress ('z', ModifierKeys::commandModifier, 0))
  42466. {
  42467. newTransaction();
  42468. doUndoRedo (false);
  42469. }
  42470. else if (key == KeyPress ('y', ModifierKeys::commandModifier, 0))
  42471. {
  42472. newTransaction();
  42473. doUndoRedo (true);
  42474. }
  42475. else if (key == KeyPress ('a', ModifierKeys::commandModifier, 0))
  42476. {
  42477. newTransaction();
  42478. moveCursorTo (getTotalNumChars(), false);
  42479. moveCursorTo (0, true);
  42480. }
  42481. else if (key == KeyPress::returnKey)
  42482. {
  42483. newTransaction();
  42484. insertTextAtCaret ("\n");
  42485. }
  42486. else if (key.isKeyCode (KeyPress::escapeKey))
  42487. {
  42488. newTransaction();
  42489. moveCursorTo (getCaretPosition(), false);
  42490. escapePressed();
  42491. }
  42492. else if (key.getTextCharacter() >= ' '
  42493. || (tabKeyUsed && (key.getTextCharacter() == '\t')))
  42494. {
  42495. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  42496. lastTransactionTime = Time::getApproximateMillisecondCounter();
  42497. }
  42498. else
  42499. {
  42500. return false;
  42501. }
  42502. return true;
  42503. }
  42504. bool TextEditor::keyStateChanged (const bool isKeyDown)
  42505. {
  42506. if (! isKeyDown)
  42507. return false;
  42508. #if JUCE_WIN32
  42509. if (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0).isCurrentlyDown())
  42510. return false; // We need to explicitly allow alt-F4 to pass through on Windows
  42511. #endif
  42512. // (overridden to avoid forwarding key events to the parent)
  42513. return ! ModifierKeys::getCurrentModifiers().isCommandDown();
  42514. }
  42515. const int baseMenuItemID = 0x7fff0000;
  42516. void TextEditor::addPopupMenuItems (PopupMenu& m, const MouseEvent*)
  42517. {
  42518. const bool writable = ! isReadOnly();
  42519. if (passwordCharacter == 0)
  42520. {
  42521. m.addItem (baseMenuItemID + 1, TRANS("cut"), writable);
  42522. m.addItem (baseMenuItemID + 2, TRANS("copy"), ! selection.isEmpty());
  42523. m.addItem (baseMenuItemID + 3, TRANS("paste"), writable);
  42524. }
  42525. m.addItem (baseMenuItemID + 4, TRANS("delete"), writable);
  42526. m.addSeparator();
  42527. m.addItem (baseMenuItemID + 5, TRANS("select all"));
  42528. m.addSeparator();
  42529. if (getUndoManager() != 0)
  42530. {
  42531. m.addItem (baseMenuItemID + 6, TRANS("undo"), undoManager.canUndo());
  42532. m.addItem (baseMenuItemID + 7, TRANS("redo"), undoManager.canRedo());
  42533. }
  42534. }
  42535. void TextEditor::performPopupMenuAction (const int menuItemID)
  42536. {
  42537. switch (menuItemID)
  42538. {
  42539. case baseMenuItemID + 1:
  42540. copy();
  42541. cut();
  42542. break;
  42543. case baseMenuItemID + 2:
  42544. copy();
  42545. break;
  42546. case baseMenuItemID + 3:
  42547. paste();
  42548. break;
  42549. case baseMenuItemID + 4:
  42550. cut();
  42551. break;
  42552. case baseMenuItemID + 5:
  42553. moveCursorTo (getTotalNumChars(), false);
  42554. moveCursorTo (0, true);
  42555. break;
  42556. case baseMenuItemID + 6:
  42557. doUndoRedo (false);
  42558. break;
  42559. case baseMenuItemID + 7:
  42560. doUndoRedo (true);
  42561. break;
  42562. default:
  42563. break;
  42564. }
  42565. }
  42566. void TextEditor::focusGained (FocusChangeType)
  42567. {
  42568. newTransaction();
  42569. caretFlashState = true;
  42570. if (selectAllTextWhenFocused)
  42571. {
  42572. moveCursorTo (0, false);
  42573. moveCursorTo (getTotalNumChars(), true);
  42574. }
  42575. repaint();
  42576. if (caretVisible)
  42577. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42578. ComponentPeer* const peer = getPeer();
  42579. if (peer != 0 && ! isReadOnly())
  42580. peer->textInputRequired (getScreenPosition() - peer->getScreenPosition());
  42581. }
  42582. void TextEditor::focusLost (FocusChangeType)
  42583. {
  42584. newTransaction();
  42585. wasFocused = false;
  42586. textHolder->stopTimer();
  42587. caretFlashState = false;
  42588. postCommandMessage (TextEditorDefs::focusLossMessageId);
  42589. repaint();
  42590. }
  42591. void TextEditor::resized()
  42592. {
  42593. viewport->setBoundsInset (borderSize);
  42594. viewport->setSingleStepSizes (16, roundToInt (currentFont.getHeight()));
  42595. updateTextHolderSize();
  42596. if (! isMultiLine())
  42597. {
  42598. scrollToMakeSureCursorIsVisible();
  42599. }
  42600. else
  42601. {
  42602. updateCaretPosition();
  42603. }
  42604. }
  42605. void TextEditor::handleCommandMessage (const int commandId)
  42606. {
  42607. Component::BailOutChecker checker (this);
  42608. switch (commandId)
  42609. {
  42610. case TextEditorDefs::textChangeMessageId:
  42611. listeners.callChecked (checker, &TextEditorListener::textEditorTextChanged, (TextEditor&) *this);
  42612. break;
  42613. case TextEditorDefs::returnKeyMessageId:
  42614. listeners.callChecked (checker, &TextEditorListener::textEditorReturnKeyPressed, (TextEditor&) *this);
  42615. break;
  42616. case TextEditorDefs::escapeKeyMessageId:
  42617. listeners.callChecked (checker, &TextEditorListener::textEditorEscapeKeyPressed, (TextEditor&) *this);
  42618. break;
  42619. case TextEditorDefs::focusLossMessageId:
  42620. listeners.callChecked (checker, &TextEditorListener::textEditorFocusLost, (TextEditor&) *this);
  42621. break;
  42622. default:
  42623. jassertfalse
  42624. break;
  42625. }
  42626. }
  42627. void TextEditor::enablementChanged()
  42628. {
  42629. setMouseCursor (isReadOnly() ? MouseCursor::NormalCursor
  42630. : MouseCursor::IBeamCursor);
  42631. repaint();
  42632. }
  42633. UndoManager* TextEditor::getUndoManager() throw()
  42634. {
  42635. return isReadOnly() ? &undoManager : 0;
  42636. }
  42637. void TextEditor::clearInternal (UndoManager* const um)
  42638. {
  42639. remove (Range<int> (0, getTotalNumChars()), um, caretPosition);
  42640. }
  42641. void TextEditor::insert (const String& text,
  42642. const int insertIndex,
  42643. const Font& font,
  42644. const Colour& colour,
  42645. UndoManager* const um,
  42646. const int caretPositionToMoveTo)
  42647. {
  42648. if (text.isNotEmpty())
  42649. {
  42650. if (um != 0)
  42651. {
  42652. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  42653. newTransaction();
  42654. um->perform (new TextEditorInsertAction (*this,
  42655. text,
  42656. insertIndex,
  42657. font,
  42658. colour,
  42659. caretPosition,
  42660. caretPositionToMoveTo));
  42661. }
  42662. else
  42663. {
  42664. repaintText (Range<int> (insertIndex, getTotalNumChars())); // must do this before and after changing the data, in case
  42665. // a line gets moved due to word wrap
  42666. int index = 0;
  42667. int nextIndex = 0;
  42668. for (int i = 0; i < sections.size(); ++i)
  42669. {
  42670. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  42671. if (insertIndex == index)
  42672. {
  42673. sections.insert (i, new UniformTextSection (text,
  42674. font, colour,
  42675. passwordCharacter));
  42676. break;
  42677. }
  42678. else if (insertIndex > index && insertIndex < nextIndex)
  42679. {
  42680. splitSection (i, insertIndex - index);
  42681. sections.insert (i + 1, new UniformTextSection (text,
  42682. font, colour,
  42683. passwordCharacter));
  42684. break;
  42685. }
  42686. index = nextIndex;
  42687. }
  42688. if (nextIndex == insertIndex)
  42689. sections.add (new UniformTextSection (text,
  42690. font, colour,
  42691. passwordCharacter));
  42692. coalesceSimilarSections();
  42693. totalNumChars = -1;
  42694. valueTextNeedsUpdating = true;
  42695. moveCursorTo (caretPositionToMoveTo, false);
  42696. repaintText (Range<int> (insertIndex, getTotalNumChars()));
  42697. }
  42698. }
  42699. }
  42700. void TextEditor::reinsert (const int insertIndex,
  42701. const VoidArray& sectionsToInsert)
  42702. {
  42703. int index = 0;
  42704. int nextIndex = 0;
  42705. for (int i = 0; i < sections.size(); ++i)
  42706. {
  42707. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  42708. if (insertIndex == index)
  42709. {
  42710. for (int j = sectionsToInsert.size(); --j >= 0;)
  42711. sections.insert (i, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  42712. break;
  42713. }
  42714. else if (insertIndex > index && insertIndex < nextIndex)
  42715. {
  42716. splitSection (i, insertIndex - index);
  42717. for (int j = sectionsToInsert.size(); --j >= 0;)
  42718. sections.insert (i + 1, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  42719. break;
  42720. }
  42721. index = nextIndex;
  42722. }
  42723. if (nextIndex == insertIndex)
  42724. {
  42725. for (int j = 0; j < sectionsToInsert.size(); ++j)
  42726. sections.add (new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  42727. }
  42728. coalesceSimilarSections();
  42729. totalNumChars = -1;
  42730. valueTextNeedsUpdating = true;
  42731. }
  42732. void TextEditor::remove (const Range<int>& range,
  42733. UndoManager* const um,
  42734. const int caretPositionToMoveTo)
  42735. {
  42736. if (! range.isEmpty())
  42737. {
  42738. int index = 0;
  42739. for (int i = 0; i < sections.size(); ++i)
  42740. {
  42741. const int nextIndex = index + ((UniformTextSection*) sections[i])->getTotalLength();
  42742. if (range.getStart() > index && range.getStart() < nextIndex)
  42743. {
  42744. splitSection (i, range.getStart() - index);
  42745. --i;
  42746. }
  42747. else if (range.getEnd() > index && range.getEnd() < nextIndex)
  42748. {
  42749. splitSection (i, range.getEnd() - index);
  42750. --i;
  42751. }
  42752. else
  42753. {
  42754. index = nextIndex;
  42755. if (index > range.getEnd())
  42756. break;
  42757. }
  42758. }
  42759. index = 0;
  42760. if (um != 0)
  42761. {
  42762. VoidArray removedSections;
  42763. for (int i = 0; i < sections.size(); ++i)
  42764. {
  42765. if (range.getEnd() <= range.getStart())
  42766. break;
  42767. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  42768. const int nextIndex = index + section->getTotalLength();
  42769. if (range.getStart() <= index && range.getEnd() >= nextIndex)
  42770. removedSections.add (new UniformTextSection (*section));
  42771. index = nextIndex;
  42772. }
  42773. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  42774. newTransaction();
  42775. um->perform (new TextEditorRemoveAction (*this,
  42776. range,
  42777. caretPosition,
  42778. caretPositionToMoveTo,
  42779. removedSections));
  42780. }
  42781. else
  42782. {
  42783. Range<int> remainingRange (range);
  42784. for (int i = 0; i < sections.size(); ++i)
  42785. {
  42786. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  42787. const int nextIndex = index + section->getTotalLength();
  42788. if (remainingRange.getStart() <= index && remainingRange.getEnd() >= nextIndex)
  42789. {
  42790. sections.remove(i);
  42791. section->clear();
  42792. delete section;
  42793. remainingRange.setEnd (remainingRange.getEnd() - (nextIndex - index));
  42794. if (remainingRange.isEmpty())
  42795. break;
  42796. --i;
  42797. }
  42798. else
  42799. {
  42800. index = nextIndex;
  42801. }
  42802. }
  42803. coalesceSimilarSections();
  42804. totalNumChars = -1;
  42805. valueTextNeedsUpdating = true;
  42806. moveCursorTo (caretPositionToMoveTo, false);
  42807. repaintText (Range<int> (range.getStart(), getTotalNumChars()));
  42808. }
  42809. }
  42810. }
  42811. const String TextEditor::getText() const
  42812. {
  42813. String t;
  42814. t.preallocateStorage (getTotalNumChars());
  42815. String::Concatenator concatenator (t);
  42816. for (int i = 0; i < sections.size(); ++i)
  42817. ((const UniformTextSection*) sections.getUnchecked(i))->appendAllText (concatenator);
  42818. return t;
  42819. }
  42820. const String TextEditor::getTextInRange (const Range<int>& range) const
  42821. {
  42822. String t;
  42823. if (! range.isEmpty())
  42824. {
  42825. t.preallocateStorage (jmin (getTotalNumChars(), range.getLength()));
  42826. String::Concatenator concatenator (t);
  42827. int index = 0;
  42828. for (int i = 0; i < sections.size(); ++i)
  42829. {
  42830. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked(i);
  42831. const int nextIndex = index + s->getTotalLength();
  42832. if (range.getStart() < nextIndex)
  42833. {
  42834. if (range.getEnd() <= index)
  42835. break;
  42836. s->appendSubstring (concatenator, range - index);
  42837. }
  42838. index = nextIndex;
  42839. }
  42840. }
  42841. return t;
  42842. }
  42843. const String TextEditor::getHighlightedText() const
  42844. {
  42845. return getTextInRange (selection);
  42846. }
  42847. int TextEditor::getTotalNumChars() const
  42848. {
  42849. if (totalNumChars < 0)
  42850. {
  42851. totalNumChars = 0;
  42852. for (int i = sections.size(); --i >= 0;)
  42853. totalNumChars += ((const UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  42854. }
  42855. return totalNumChars;
  42856. }
  42857. bool TextEditor::isEmpty() const
  42858. {
  42859. return getTotalNumChars() == 0;
  42860. }
  42861. void TextEditor::getCharPosition (const int index, float& cx, float& cy, float& lineHeight) const
  42862. {
  42863. const float wordWrapWidth = getWordWrapWidth();
  42864. if (wordWrapWidth > 0 && sections.size() > 0)
  42865. {
  42866. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42867. i.getCharPosition (index, cx, cy, lineHeight);
  42868. }
  42869. else
  42870. {
  42871. cx = cy = 0;
  42872. lineHeight = currentFont.getHeight();
  42873. }
  42874. }
  42875. int TextEditor::indexAtPosition (const float x, const float y)
  42876. {
  42877. const float wordWrapWidth = getWordWrapWidth();
  42878. if (wordWrapWidth > 0)
  42879. {
  42880. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42881. while (i.next())
  42882. {
  42883. if (i.lineY + i.lineHeight > y)
  42884. {
  42885. if (i.lineY > y)
  42886. return jmax (0, i.indexInText - 1);
  42887. if (i.atomX >= x)
  42888. return i.indexInText;
  42889. if (x < i.atomRight)
  42890. return i.xToIndex (x);
  42891. }
  42892. }
  42893. }
  42894. return getTotalNumChars();
  42895. }
  42896. static int getCharacterCategory (const tchar character)
  42897. {
  42898. return CharacterFunctions::isLetterOrDigit (character)
  42899. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  42900. }
  42901. int TextEditor::findWordBreakAfter (const int position) const
  42902. {
  42903. const String t (getTextInRange (Range<int> (position, position + 512)));
  42904. const int totalLength = t.length();
  42905. int i = 0;
  42906. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  42907. ++i;
  42908. const int type = getCharacterCategory (t[i]);
  42909. while (i < totalLength && type == getCharacterCategory (t[i]))
  42910. ++i;
  42911. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  42912. ++i;
  42913. return position + i;
  42914. }
  42915. int TextEditor::findWordBreakBefore (const int position) const
  42916. {
  42917. if (position <= 0)
  42918. return 0;
  42919. const int startOfBuffer = jmax (0, position - 512);
  42920. const String t (getTextInRange (Range<int> (startOfBuffer, position)));
  42921. int i = position - startOfBuffer;
  42922. while (i > 0 && CharacterFunctions::isWhitespace (t [i - 1]))
  42923. --i;
  42924. if (i > 0)
  42925. {
  42926. const int type = getCharacterCategory (t [i - 1]);
  42927. while (i > 0 && type == getCharacterCategory (t [i - 1]))
  42928. --i;
  42929. }
  42930. jassert (startOfBuffer + i >= 0);
  42931. return startOfBuffer + i;
  42932. }
  42933. void TextEditor::splitSection (const int sectionIndex,
  42934. const int charToSplitAt)
  42935. {
  42936. jassert (sections[sectionIndex] != 0);
  42937. sections.insert (sectionIndex + 1,
  42938. ((UniformTextSection*) sections.getUnchecked (sectionIndex))
  42939. ->split (charToSplitAt, passwordCharacter));
  42940. }
  42941. void TextEditor::coalesceSimilarSections()
  42942. {
  42943. for (int i = 0; i < sections.size() - 1; ++i)
  42944. {
  42945. UniformTextSection* const s1 = (UniformTextSection*) sections.getUnchecked (i);
  42946. UniformTextSection* const s2 = (UniformTextSection*) sections.getUnchecked (i + 1);
  42947. if (s1->font == s2->font
  42948. && s1->colour == s2->colour)
  42949. {
  42950. s1->append (*s2, passwordCharacter);
  42951. sections.remove (i + 1);
  42952. delete s2;
  42953. --i;
  42954. }
  42955. }
  42956. }
  42957. END_JUCE_NAMESPACE
  42958. /*** End of inlined file: juce_TextEditor.cpp ***/
  42959. /*** Start of inlined file: juce_Toolbar.cpp ***/
  42960. BEGIN_JUCE_NAMESPACE
  42961. const tchar* const Toolbar::toolbarDragDescriptor = T("_toolbarItem_");
  42962. class ToolbarSpacerComp : public ToolbarItemComponent
  42963. {
  42964. public:
  42965. ToolbarSpacerComp (const int itemId_, const float fixedSize_, const bool drawBar_)
  42966. : ToolbarItemComponent (itemId_, String::empty, false),
  42967. fixedSize (fixedSize_),
  42968. drawBar (drawBar_)
  42969. {
  42970. }
  42971. ~ToolbarSpacerComp()
  42972. {
  42973. }
  42974. bool getToolbarItemSizes (int toolbarThickness, bool /*isToolbarVertical*/,
  42975. int& preferredSize, int& minSize, int& maxSize)
  42976. {
  42977. if (fixedSize <= 0)
  42978. {
  42979. preferredSize = toolbarThickness * 2;
  42980. minSize = 4;
  42981. maxSize = 32768;
  42982. }
  42983. else
  42984. {
  42985. maxSize = roundToInt (toolbarThickness * fixedSize);
  42986. minSize = drawBar ? maxSize : jmin (4, maxSize);
  42987. preferredSize = maxSize;
  42988. if (getEditingMode() == editableOnPalette)
  42989. preferredSize = maxSize = toolbarThickness / (drawBar ? 3 : 2);
  42990. }
  42991. return true;
  42992. }
  42993. void paintButtonArea (Graphics&, int, int, bool, bool)
  42994. {
  42995. }
  42996. void contentAreaChanged (const Rectangle<int>&)
  42997. {
  42998. }
  42999. int getResizeOrder() const throw()
  43000. {
  43001. return fixedSize <= 0 ? 0 : 1;
  43002. }
  43003. void paint (Graphics& g)
  43004. {
  43005. const int w = getWidth();
  43006. const int h = getHeight();
  43007. if (drawBar)
  43008. {
  43009. g.setColour (findColour (Toolbar::separatorColourId, true));
  43010. const float thickness = 0.2f;
  43011. if (isToolbarVertical())
  43012. g.fillRect (w * 0.1f, h * (0.5f - thickness * 0.5f), w * 0.8f, h * thickness);
  43013. else
  43014. g.fillRect (w * (0.5f - thickness * 0.5f), h * 0.1f, w * thickness, h * 0.8f);
  43015. }
  43016. if (getEditingMode() != normalMode && ! drawBar)
  43017. {
  43018. g.setColour (findColour (Toolbar::separatorColourId, true));
  43019. const int indentX = jmin (2, (w - 3) / 2);
  43020. const int indentY = jmin (2, (h - 3) / 2);
  43021. g.drawRect (indentX, indentY, w - indentX * 2, h - indentY * 2, 1);
  43022. if (fixedSize <= 0)
  43023. {
  43024. float x1, y1, x2, y2, x3, y3, x4, y4, hw, hl;
  43025. if (isToolbarVertical())
  43026. {
  43027. x1 = w * 0.5f;
  43028. y1 = h * 0.4f;
  43029. x2 = x1;
  43030. y2 = indentX * 2.0f;
  43031. x3 = x1;
  43032. y3 = h * 0.6f;
  43033. x4 = x1;
  43034. y4 = h - y2;
  43035. hw = w * 0.15f;
  43036. hl = w * 0.2f;
  43037. }
  43038. else
  43039. {
  43040. x1 = w * 0.4f;
  43041. y1 = h * 0.5f;
  43042. x2 = indentX * 2.0f;
  43043. y2 = y1;
  43044. x3 = w * 0.6f;
  43045. y3 = y1;
  43046. x4 = w - x2;
  43047. y4 = y1;
  43048. hw = h * 0.15f;
  43049. hl = h * 0.2f;
  43050. }
  43051. Path p;
  43052. p.addArrow (x1, y1, x2, y2, 1.5f, hw, hl);
  43053. p.addArrow (x3, y3, x4, y4, 1.5f, hw, hl);
  43054. g.fillPath (p);
  43055. }
  43056. }
  43057. }
  43058. juce_UseDebuggingNewOperator
  43059. private:
  43060. const float fixedSize;
  43061. const bool drawBar;
  43062. ToolbarSpacerComp (const ToolbarSpacerComp&);
  43063. ToolbarSpacerComp& operator= (const ToolbarSpacerComp&);
  43064. };
  43065. class MissingItemsComponent : public PopupMenuCustomComponent
  43066. {
  43067. public:
  43068. MissingItemsComponent (Toolbar& owner_, const int height_)
  43069. : PopupMenuCustomComponent (true),
  43070. owner (owner_),
  43071. height (height_)
  43072. {
  43073. for (int i = owner_.items.size(); --i >= 0;)
  43074. {
  43075. ToolbarItemComponent* const tc = owner_.items.getUnchecked(i);
  43076. if (dynamic_cast <ToolbarSpacerComp*> (tc) == 0 && ! tc->isVisible())
  43077. {
  43078. oldIndexes.insert (0, i);
  43079. addAndMakeVisible (tc, 0);
  43080. }
  43081. }
  43082. layout (400);
  43083. }
  43084. ~MissingItemsComponent()
  43085. {
  43086. // deleting the toolbar while its menu it open??
  43087. jassert (owner.isValidComponent());
  43088. for (int i = 0; i < getNumChildComponents(); ++i)
  43089. {
  43090. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43091. if (tc != 0)
  43092. {
  43093. tc->setVisible (false);
  43094. const int index = oldIndexes.remove (i);
  43095. owner.addChildComponent (tc, index);
  43096. --i;
  43097. }
  43098. }
  43099. owner.resized();
  43100. }
  43101. void layout (const int preferredWidth)
  43102. {
  43103. const int indent = 8;
  43104. int x = indent;
  43105. int y = indent;
  43106. int maxX = 0;
  43107. for (int i = 0; i < getNumChildComponents(); ++i)
  43108. {
  43109. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43110. if (tc != 0)
  43111. {
  43112. int preferredSize = 1, minSize = 1, maxSize = 1;
  43113. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  43114. {
  43115. if (x + preferredSize > preferredWidth && x > indent)
  43116. {
  43117. x = indent;
  43118. y += height;
  43119. }
  43120. tc->setBounds (x, y, preferredSize, height);
  43121. x += preferredSize;
  43122. maxX = jmax (maxX, x);
  43123. }
  43124. }
  43125. }
  43126. setSize (maxX + 8, y + height + 8);
  43127. }
  43128. void getIdealSize (int& idealWidth, int& idealHeight)
  43129. {
  43130. idealWidth = getWidth();
  43131. idealHeight = getHeight();
  43132. }
  43133. juce_UseDebuggingNewOperator
  43134. private:
  43135. Toolbar& owner;
  43136. const int height;
  43137. Array <int> oldIndexes;
  43138. MissingItemsComponent (const MissingItemsComponent&);
  43139. MissingItemsComponent& operator= (const MissingItemsComponent&);
  43140. };
  43141. Toolbar::Toolbar()
  43142. : vertical (false),
  43143. isEditingActive (false),
  43144. toolbarStyle (Toolbar::iconsOnly)
  43145. {
  43146. addChildComponent (missingItemsButton = getLookAndFeel().createToolbarMissingItemsButton (*this));
  43147. missingItemsButton->setAlwaysOnTop (true);
  43148. missingItemsButton->addButtonListener (this);
  43149. }
  43150. Toolbar::~Toolbar()
  43151. {
  43152. animator.cancelAllAnimations (true);
  43153. deleteAllChildren();
  43154. }
  43155. void Toolbar::setVertical (const bool shouldBeVertical)
  43156. {
  43157. if (vertical != shouldBeVertical)
  43158. {
  43159. vertical = shouldBeVertical;
  43160. resized();
  43161. }
  43162. }
  43163. void Toolbar::clear()
  43164. {
  43165. for (int i = items.size(); --i >= 0;)
  43166. {
  43167. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43168. items.remove (i);
  43169. delete tc;
  43170. }
  43171. resized();
  43172. }
  43173. ToolbarItemComponent* Toolbar::createItem (ToolbarItemFactory& factory, const int itemId)
  43174. {
  43175. if (itemId == ToolbarItemFactory::separatorBarId)
  43176. return new ToolbarSpacerComp (itemId, 0.1f, true);
  43177. else if (itemId == ToolbarItemFactory::spacerId)
  43178. return new ToolbarSpacerComp (itemId, 0.5f, false);
  43179. else if (itemId == ToolbarItemFactory::flexibleSpacerId)
  43180. return new ToolbarSpacerComp (itemId, 0, false);
  43181. return factory.createItem (itemId);
  43182. }
  43183. void Toolbar::addItemInternal (ToolbarItemFactory& factory,
  43184. const int itemId,
  43185. const int insertIndex)
  43186. {
  43187. // An ID can't be zero - this might indicate a mistake somewhere?
  43188. jassert (itemId != 0);
  43189. ToolbarItemComponent* const tc = createItem (factory, itemId);
  43190. if (tc != 0)
  43191. {
  43192. #ifdef JUCE_DEBUG
  43193. Array <int> allowedIds;
  43194. factory.getAllToolbarItemIds (allowedIds);
  43195. // If your factory can create an item for a given ID, it must also return
  43196. // that ID from its getAllToolbarItemIds() method!
  43197. jassert (allowedIds.contains (itemId));
  43198. #endif
  43199. items.insert (insertIndex, tc);
  43200. addAndMakeVisible (tc, insertIndex);
  43201. }
  43202. }
  43203. void Toolbar::addItem (ToolbarItemFactory& factory,
  43204. const int itemId,
  43205. const int insertIndex)
  43206. {
  43207. addItemInternal (factory, itemId, insertIndex);
  43208. resized();
  43209. }
  43210. void Toolbar::addDefaultItems (ToolbarItemFactory& factoryToUse)
  43211. {
  43212. Array <int> ids;
  43213. factoryToUse.getDefaultItemSet (ids);
  43214. clear();
  43215. for (int i = 0; i < ids.size(); ++i)
  43216. addItemInternal (factoryToUse, ids.getUnchecked (i), -1);
  43217. resized();
  43218. }
  43219. void Toolbar::removeToolbarItem (const int itemIndex)
  43220. {
  43221. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43222. if (tc != 0)
  43223. {
  43224. items.removeValue (tc);
  43225. delete tc;
  43226. resized();
  43227. }
  43228. }
  43229. int Toolbar::getNumItems() const throw()
  43230. {
  43231. return items.size();
  43232. }
  43233. int Toolbar::getItemId (const int itemIndex) const throw()
  43234. {
  43235. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43236. return tc != 0 ? tc->getItemId() : 0;
  43237. }
  43238. ToolbarItemComponent* Toolbar::getItemComponent (const int itemIndex) const throw()
  43239. {
  43240. return items [itemIndex];
  43241. }
  43242. ToolbarItemComponent* Toolbar::getNextActiveComponent (int index, const int delta) const
  43243. {
  43244. for (;;)
  43245. {
  43246. index += delta;
  43247. ToolbarItemComponent* const tc = getItemComponent (index);
  43248. if (tc == 0)
  43249. break;
  43250. if (tc->isActive)
  43251. return tc;
  43252. }
  43253. return 0;
  43254. }
  43255. void Toolbar::setStyle (const ToolbarItemStyle& newStyle)
  43256. {
  43257. if (toolbarStyle != newStyle)
  43258. {
  43259. toolbarStyle = newStyle;
  43260. updateAllItemPositions (false);
  43261. }
  43262. }
  43263. const String Toolbar::toString() const
  43264. {
  43265. String s ("TB:");
  43266. for (int i = 0; i < getNumItems(); ++i)
  43267. s << getItemId(i) << ' ';
  43268. return s.trimEnd();
  43269. }
  43270. bool Toolbar::restoreFromString (ToolbarItemFactory& factoryToUse,
  43271. const String& savedVersion)
  43272. {
  43273. if (! savedVersion.startsWith (T("TB:")))
  43274. return false;
  43275. StringArray tokens;
  43276. tokens.addTokens (savedVersion.substring (3), false);
  43277. clear();
  43278. for (int i = 0; i < tokens.size(); ++i)
  43279. addItemInternal (factoryToUse, tokens[i].getIntValue(), -1);
  43280. resized();
  43281. return true;
  43282. }
  43283. void Toolbar::paint (Graphics& g)
  43284. {
  43285. getLookAndFeel().paintToolbarBackground (g, getWidth(), getHeight(), *this);
  43286. }
  43287. int Toolbar::getThickness() const throw()
  43288. {
  43289. return vertical ? getWidth() : getHeight();
  43290. }
  43291. int Toolbar::getLength() const throw()
  43292. {
  43293. return vertical ? getHeight() : getWidth();
  43294. }
  43295. void Toolbar::setEditingActive (const bool active)
  43296. {
  43297. if (isEditingActive != active)
  43298. {
  43299. isEditingActive = active;
  43300. updateAllItemPositions (false);
  43301. }
  43302. }
  43303. void Toolbar::resized()
  43304. {
  43305. updateAllItemPositions (false);
  43306. }
  43307. void Toolbar::updateAllItemPositions (const bool animate)
  43308. {
  43309. if (getWidth() > 0 && getHeight() > 0)
  43310. {
  43311. StretchableObjectResizer resizer;
  43312. int i;
  43313. for (i = 0; i < items.size(); ++i)
  43314. {
  43315. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43316. tc->setEditingMode (isEditingActive ? ToolbarItemComponent::editableOnToolbar
  43317. : ToolbarItemComponent::normalMode);
  43318. tc->setStyle (toolbarStyle);
  43319. ToolbarSpacerComp* const spacer = dynamic_cast <ToolbarSpacerComp*> (tc);
  43320. int preferredSize = 1, minSize = 1, maxSize = 1;
  43321. if (tc->getToolbarItemSizes (getThickness(), isVertical(),
  43322. preferredSize, minSize, maxSize))
  43323. {
  43324. tc->isActive = true;
  43325. resizer.addItem (preferredSize, minSize, maxSize,
  43326. spacer != 0 ? spacer->getResizeOrder() : 2);
  43327. }
  43328. else
  43329. {
  43330. tc->isActive = false;
  43331. tc->setVisible (false);
  43332. }
  43333. }
  43334. resizer.resizeToFit (getLength());
  43335. int totalLength = 0;
  43336. for (i = 0; i < resizer.getNumItems(); ++i)
  43337. totalLength += (int) resizer.getItemSize (i);
  43338. const bool itemsOffTheEnd = totalLength > getLength();
  43339. const int extrasButtonSize = getThickness() / 2;
  43340. missingItemsButton->setSize (extrasButtonSize, extrasButtonSize);
  43341. missingItemsButton->setVisible (itemsOffTheEnd);
  43342. missingItemsButton->setEnabled (! isEditingActive);
  43343. if (vertical)
  43344. missingItemsButton->setCentrePosition (getWidth() / 2,
  43345. getHeight() - 4 - extrasButtonSize / 2);
  43346. else
  43347. missingItemsButton->setCentrePosition (getWidth() - 4 - extrasButtonSize / 2,
  43348. getHeight() / 2);
  43349. const int maxLength = itemsOffTheEnd ? (vertical ? missingItemsButton->getY()
  43350. : missingItemsButton->getX()) - 4
  43351. : getLength();
  43352. int pos = 0, activeIndex = 0;
  43353. for (i = 0; i < items.size(); ++i)
  43354. {
  43355. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43356. if (tc->isActive)
  43357. {
  43358. const int size = (int) resizer.getItemSize (activeIndex++);
  43359. Rectangle<int> newBounds;
  43360. if (vertical)
  43361. newBounds.setBounds (0, pos, getWidth(), size);
  43362. else
  43363. newBounds.setBounds (pos, 0, size, getHeight());
  43364. if (animate)
  43365. {
  43366. animator.animateComponent (tc, newBounds, 200, 3.0, 0.0);
  43367. }
  43368. else
  43369. {
  43370. animator.cancelAnimation (tc, false);
  43371. tc->setBounds (newBounds);
  43372. }
  43373. pos += size;
  43374. tc->setVisible (pos <= maxLength
  43375. && ((! tc->isBeingDragged)
  43376. || tc->getEditingMode() == ToolbarItemComponent::editableOnPalette));
  43377. }
  43378. }
  43379. }
  43380. }
  43381. void Toolbar::buttonClicked (Button*)
  43382. {
  43383. jassert (missingItemsButton->isShowing());
  43384. if (missingItemsButton->isShowing())
  43385. {
  43386. PopupMenu m;
  43387. m.addCustomItem (1, new MissingItemsComponent (*this, getThickness()));
  43388. m.showAt (missingItemsButton);
  43389. }
  43390. }
  43391. bool Toolbar::isInterestedInDragSource (const String& sourceDescription,
  43392. Component* /*sourceComponent*/)
  43393. {
  43394. return sourceDescription == toolbarDragDescriptor && isEditingActive;
  43395. }
  43396. void Toolbar::itemDragMove (const String&, Component* sourceComponent, int x, int y)
  43397. {
  43398. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  43399. if (tc != 0)
  43400. {
  43401. if (getNumItems() == 0)
  43402. {
  43403. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43404. {
  43405. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43406. if (palette != 0)
  43407. palette->replaceComponent (tc);
  43408. }
  43409. else
  43410. {
  43411. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43412. }
  43413. items.add (tc);
  43414. addChildComponent (tc);
  43415. updateAllItemPositions (false);
  43416. }
  43417. else
  43418. {
  43419. for (int i = getNumItems(); --i >= 0;)
  43420. {
  43421. int currentIndex = getIndexOfChildComponent (tc);
  43422. if (currentIndex < 0)
  43423. {
  43424. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43425. {
  43426. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43427. if (palette != 0)
  43428. palette->replaceComponent (tc);
  43429. }
  43430. else
  43431. {
  43432. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43433. }
  43434. items.add (tc);
  43435. addChildComponent (tc);
  43436. currentIndex = getIndexOfChildComponent (tc);
  43437. updateAllItemPositions (true);
  43438. }
  43439. int newIndex = currentIndex;
  43440. const int dragObjectLeft = vertical ? (y - tc->dragOffsetY) : (x - tc->dragOffsetX);
  43441. const int dragObjectRight = dragObjectLeft + (vertical ? tc->getHeight() : tc->getWidth());
  43442. const Rectangle<int> current (animator.getComponentDestination (getChildComponent (newIndex)));
  43443. ToolbarItemComponent* const prev = getNextActiveComponent (newIndex, -1);
  43444. if (prev != 0)
  43445. {
  43446. const Rectangle<int> previousPos (animator.getComponentDestination (prev));
  43447. if (abs (dragObjectLeft - (vertical ? previousPos.getY() : previousPos.getX())
  43448. < abs (dragObjectRight - (vertical ? current.getBottom() : current.getRight()))))
  43449. {
  43450. newIndex = getIndexOfChildComponent (prev);
  43451. }
  43452. }
  43453. ToolbarItemComponent* const next = getNextActiveComponent (newIndex, 1);
  43454. if (next != 0)
  43455. {
  43456. const Rectangle<int> nextPos (animator.getComponentDestination (next));
  43457. if (abs (dragObjectLeft - (vertical ? current.getY() : current.getX())
  43458. > abs (dragObjectRight - (vertical ? nextPos.getBottom() : nextPos.getRight()))))
  43459. {
  43460. newIndex = getIndexOfChildComponent (next) + 1;
  43461. }
  43462. }
  43463. if (newIndex != currentIndex)
  43464. {
  43465. items.removeValue (tc);
  43466. removeChildComponent (tc);
  43467. addChildComponent (tc, newIndex);
  43468. items.insert (newIndex, tc);
  43469. updateAllItemPositions (true);
  43470. }
  43471. else
  43472. {
  43473. break;
  43474. }
  43475. }
  43476. }
  43477. }
  43478. }
  43479. void Toolbar::itemDragExit (const String&, Component* sourceComponent)
  43480. {
  43481. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  43482. if (tc != 0)
  43483. {
  43484. if (isParentOf (tc))
  43485. {
  43486. items.removeValue (tc);
  43487. removeChildComponent (tc);
  43488. updateAllItemPositions (true);
  43489. }
  43490. }
  43491. }
  43492. void Toolbar::itemDropped (const String&, Component*, int, int)
  43493. {
  43494. }
  43495. void Toolbar::mouseDown (const MouseEvent& e)
  43496. {
  43497. if (e.mods.isPopupMenu())
  43498. {
  43499. }
  43500. }
  43501. class ToolbarCustomisationDialog : public DialogWindow
  43502. {
  43503. public:
  43504. ToolbarCustomisationDialog (ToolbarItemFactory& factory,
  43505. Toolbar* const toolbar_,
  43506. const int optionFlags)
  43507. : DialogWindow (TRANS("Add/remove items from toolbar"), Colours::white, true, true),
  43508. toolbar (toolbar_)
  43509. {
  43510. setContentComponent (new CustomiserPanel (factory, toolbar, optionFlags), true, true);
  43511. setResizable (true, true);
  43512. setResizeLimits (400, 300, 1500, 1000);
  43513. positionNearBar();
  43514. }
  43515. ~ToolbarCustomisationDialog()
  43516. {
  43517. setContentComponent (0, true);
  43518. }
  43519. void closeButtonPressed()
  43520. {
  43521. setVisible (false);
  43522. }
  43523. bool canModalEventBeSentToComponent (const Component* comp)
  43524. {
  43525. return toolbar->isParentOf (comp);
  43526. }
  43527. void positionNearBar()
  43528. {
  43529. const Rectangle<int> screenSize (toolbar->getParentMonitorArea());
  43530. const int tbx = toolbar->getScreenX();
  43531. const int tby = toolbar->getScreenY();
  43532. const int gap = 8;
  43533. int x, y;
  43534. if (toolbar->isVertical())
  43535. {
  43536. y = tby;
  43537. if (tbx > screenSize.getCentreX())
  43538. x = tbx - getWidth() - gap;
  43539. else
  43540. x = tbx + toolbar->getWidth() + gap;
  43541. }
  43542. else
  43543. {
  43544. x = tbx + (toolbar->getWidth() - getWidth()) / 2;
  43545. if (tby > screenSize.getCentreY())
  43546. y = tby - getHeight() - gap;
  43547. else
  43548. y = tby + toolbar->getHeight() + gap;
  43549. }
  43550. setTopLeftPosition (x, y);
  43551. }
  43552. private:
  43553. Toolbar* const toolbar;
  43554. class CustomiserPanel : public Component,
  43555. private ComboBoxListener,
  43556. private ButtonListener
  43557. {
  43558. public:
  43559. CustomiserPanel (ToolbarItemFactory& factory_,
  43560. Toolbar* const toolbar_,
  43561. const int optionFlags)
  43562. : factory (factory_),
  43563. toolbar (toolbar_),
  43564. styleBox (0),
  43565. defaultButton (0)
  43566. {
  43567. addAndMakeVisible (palette = new ToolbarItemPalette (factory, toolbar));
  43568. if ((optionFlags & (Toolbar::allowIconsOnlyChoice
  43569. | Toolbar::allowIconsWithTextChoice
  43570. | Toolbar::allowTextOnlyChoice)) != 0)
  43571. {
  43572. addAndMakeVisible (styleBox = new ComboBox (String::empty));
  43573. styleBox->setEditableText (false);
  43574. if ((optionFlags & Toolbar::allowIconsOnlyChoice) != 0)
  43575. styleBox->addItem (TRANS("Show icons only"), 1);
  43576. if ((optionFlags & Toolbar::allowIconsWithTextChoice) != 0)
  43577. styleBox->addItem (TRANS("Show icons and descriptions"), 2);
  43578. if ((optionFlags & Toolbar::allowTextOnlyChoice) != 0)
  43579. styleBox->addItem (TRANS("Show descriptions only"), 3);
  43580. if (toolbar_->getStyle() == Toolbar::iconsOnly)
  43581. styleBox->setSelectedId (1);
  43582. else if (toolbar_->getStyle() == Toolbar::iconsWithText)
  43583. styleBox->setSelectedId (2);
  43584. else if (toolbar_->getStyle() == Toolbar::textOnly)
  43585. styleBox->setSelectedId (3);
  43586. styleBox->addListener (this);
  43587. }
  43588. if ((optionFlags & Toolbar::showResetToDefaultsButton) != 0)
  43589. {
  43590. addAndMakeVisible (defaultButton = new TextButton (TRANS ("Restore to default set of items")));
  43591. defaultButton->addButtonListener (this);
  43592. }
  43593. addAndMakeVisible (instructions = new Label (String::empty,
  43594. 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.")));
  43595. instructions->setFont (Font (13.0f));
  43596. setSize (500, 300);
  43597. }
  43598. ~CustomiserPanel()
  43599. {
  43600. deleteAllChildren();
  43601. }
  43602. void comboBoxChanged (ComboBox*)
  43603. {
  43604. if (styleBox->getSelectedId() == 1)
  43605. toolbar->setStyle (Toolbar::iconsOnly);
  43606. else if (styleBox->getSelectedId() == 2)
  43607. toolbar->setStyle (Toolbar::iconsWithText);
  43608. else if (styleBox->getSelectedId() == 3)
  43609. toolbar->setStyle (Toolbar::textOnly);
  43610. palette->resized(); // to make it update the styles
  43611. }
  43612. void buttonClicked (Button*)
  43613. {
  43614. toolbar->addDefaultItems (factory);
  43615. }
  43616. void paint (Graphics& g)
  43617. {
  43618. Colour background;
  43619. DialogWindow* const dw = findParentComponentOfClass ((DialogWindow*) 0);
  43620. if (dw != 0)
  43621. background = dw->getBackgroundColour();
  43622. g.setColour (background.contrasting().withAlpha (0.3f));
  43623. g.fillRect (palette->getX(), palette->getBottom() - 1, palette->getWidth(), 1);
  43624. }
  43625. void resized()
  43626. {
  43627. palette->setBounds (0, 0, getWidth(), getHeight() - 120);
  43628. if (styleBox != 0)
  43629. styleBox->setBounds (10, getHeight() - 110, 200, 22);
  43630. if (defaultButton != 0)
  43631. {
  43632. defaultButton->changeWidthToFitText (22);
  43633. defaultButton->setTopLeftPosition (240, getHeight() - 110);
  43634. }
  43635. instructions->setBounds (10, getHeight() - 80, getWidth() - 20, 80);
  43636. }
  43637. private:
  43638. ToolbarItemFactory& factory;
  43639. Toolbar* const toolbar;
  43640. Label* instructions;
  43641. ToolbarItemPalette* palette;
  43642. ComboBox* styleBox;
  43643. TextButton* defaultButton;
  43644. };
  43645. };
  43646. void Toolbar::showCustomisationDialog (ToolbarItemFactory& factory, const int optionFlags)
  43647. {
  43648. setEditingActive (true);
  43649. ToolbarCustomisationDialog dw (factory, this, optionFlags);
  43650. dw.runModalLoop();
  43651. jassert (isValidComponent()); // ? deleting the toolbar while it's being edited?
  43652. setEditingActive (false);
  43653. }
  43654. END_JUCE_NAMESPACE
  43655. /*** End of inlined file: juce_Toolbar.cpp ***/
  43656. /*** Start of inlined file: juce_ToolbarItemComponent.cpp ***/
  43657. BEGIN_JUCE_NAMESPACE
  43658. ToolbarItemFactory::ToolbarItemFactory()
  43659. {
  43660. }
  43661. ToolbarItemFactory::~ToolbarItemFactory()
  43662. {
  43663. }
  43664. class ItemDragAndDropOverlayComponent : public Component
  43665. {
  43666. public:
  43667. ItemDragAndDropOverlayComponent()
  43668. : isDragging (false)
  43669. {
  43670. setAlwaysOnTop (true);
  43671. setRepaintsOnMouseActivity (true);
  43672. setMouseCursor (MouseCursor::DraggingHandCursor);
  43673. }
  43674. ~ItemDragAndDropOverlayComponent()
  43675. {
  43676. }
  43677. void paint (Graphics& g)
  43678. {
  43679. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43680. if (isMouseOverOrDragging()
  43681. && tc != 0
  43682. && tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43683. {
  43684. g.setColour (findColour (Toolbar::editingModeOutlineColourId, true));
  43685. g.drawRect (0, 0, getWidth(), getHeight(),
  43686. jmin (2, (getWidth() - 1) / 2, (getHeight() - 1) / 2));
  43687. }
  43688. }
  43689. void mouseDown (const MouseEvent& e)
  43690. {
  43691. isDragging = false;
  43692. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43693. if (tc != 0)
  43694. {
  43695. tc->dragOffsetX = e.x;
  43696. tc->dragOffsetY = e.y;
  43697. }
  43698. }
  43699. void mouseDrag (const MouseEvent& e)
  43700. {
  43701. if (! (isDragging || e.mouseWasClicked()))
  43702. {
  43703. isDragging = true;
  43704. DragAndDropContainer* const dnd = DragAndDropContainer::findParentDragContainerFor (this);
  43705. if (dnd != 0)
  43706. {
  43707. dnd->startDragging (Toolbar::toolbarDragDescriptor, getParentComponent(), 0, true);
  43708. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43709. if (tc != 0)
  43710. {
  43711. tc->isBeingDragged = true;
  43712. if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43713. tc->setVisible (false);
  43714. }
  43715. }
  43716. }
  43717. }
  43718. void mouseUp (const MouseEvent&)
  43719. {
  43720. isDragging = false;
  43721. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43722. if (tc != 0)
  43723. {
  43724. tc->isBeingDragged = false;
  43725. Toolbar* const tb = tc->getToolbar();
  43726. if (tb != 0)
  43727. tb->updateAllItemPositions (true);
  43728. else if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43729. delete tc;
  43730. }
  43731. }
  43732. void parentSizeChanged()
  43733. {
  43734. setBounds (0, 0, getParentWidth(), getParentHeight());
  43735. }
  43736. juce_UseDebuggingNewOperator
  43737. private:
  43738. bool isDragging;
  43739. ItemDragAndDropOverlayComponent (const ItemDragAndDropOverlayComponent&);
  43740. ItemDragAndDropOverlayComponent& operator= (const ItemDragAndDropOverlayComponent&);
  43741. };
  43742. ToolbarItemComponent::ToolbarItemComponent (const int itemId_,
  43743. const String& labelText,
  43744. const bool isBeingUsedAsAButton_)
  43745. : Button (labelText),
  43746. itemId (itemId_),
  43747. mode (normalMode),
  43748. toolbarStyle (Toolbar::iconsOnly),
  43749. dragOffsetX (0),
  43750. dragOffsetY (0),
  43751. isActive (true),
  43752. isBeingDragged (false),
  43753. isBeingUsedAsAButton (isBeingUsedAsAButton_)
  43754. {
  43755. // Your item ID can't be 0!
  43756. jassert (itemId_ != 0);
  43757. }
  43758. ToolbarItemComponent::~ToolbarItemComponent()
  43759. {
  43760. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  43761. overlayComp = 0;
  43762. }
  43763. Toolbar* ToolbarItemComponent::getToolbar() const
  43764. {
  43765. return dynamic_cast <Toolbar*> (getParentComponent());
  43766. }
  43767. bool ToolbarItemComponent::isToolbarVertical() const
  43768. {
  43769. const Toolbar* const t = getToolbar();
  43770. return t != 0 && t->isVertical();
  43771. }
  43772. void ToolbarItemComponent::setStyle (const Toolbar::ToolbarItemStyle& newStyle)
  43773. {
  43774. if (toolbarStyle != newStyle)
  43775. {
  43776. toolbarStyle = newStyle;
  43777. repaint();
  43778. resized();
  43779. }
  43780. }
  43781. void ToolbarItemComponent::paintButton (Graphics& g, bool isMouseOver, bool isMouseDown)
  43782. {
  43783. if (isBeingUsedAsAButton)
  43784. getLookAndFeel().paintToolbarButtonBackground (g, getWidth(), getHeight(),
  43785. isMouseOver, isMouseDown, *this);
  43786. if (toolbarStyle != Toolbar::iconsOnly)
  43787. {
  43788. const int indent = contentArea.getX();
  43789. int y = indent;
  43790. int h = getHeight() - indent * 2;
  43791. if (toolbarStyle == Toolbar::iconsWithText)
  43792. {
  43793. y = contentArea.getBottom() + indent / 2;
  43794. h -= contentArea.getHeight();
  43795. }
  43796. getLookAndFeel().paintToolbarButtonLabel (g, indent, y, getWidth() - indent * 2, h,
  43797. getButtonText(), *this);
  43798. }
  43799. if (! contentArea.isEmpty())
  43800. {
  43801. g.saveState();
  43802. g.setOrigin (contentArea.getX(), contentArea.getY());
  43803. g.reduceClipRegion (0, 0, contentArea.getWidth(), contentArea.getHeight());
  43804. paintButtonArea (g, contentArea.getWidth(), contentArea.getHeight(), isMouseOver, isMouseDown);
  43805. g.restoreState();
  43806. }
  43807. }
  43808. void ToolbarItemComponent::resized()
  43809. {
  43810. if (toolbarStyle != Toolbar::textOnly)
  43811. {
  43812. const int indent = jmin (proportionOfWidth (0.08f),
  43813. proportionOfHeight (0.08f));
  43814. contentArea = Rectangle<int> (indent, indent,
  43815. getWidth() - indent * 2,
  43816. toolbarStyle == Toolbar::iconsWithText ? proportionOfHeight (0.55f)
  43817. : (getHeight() - indent * 2));
  43818. }
  43819. else
  43820. {
  43821. contentArea = Rectangle<int>();
  43822. }
  43823. contentAreaChanged (contentArea);
  43824. }
  43825. void ToolbarItemComponent::setEditingMode (const ToolbarEditingMode newMode)
  43826. {
  43827. if (mode != newMode)
  43828. {
  43829. mode = newMode;
  43830. repaint();
  43831. if (mode == normalMode)
  43832. {
  43833. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  43834. overlayComp = 0;
  43835. }
  43836. else if (overlayComp == 0)
  43837. {
  43838. addAndMakeVisible (overlayComp = new ItemDragAndDropOverlayComponent());
  43839. overlayComp->parentSizeChanged();
  43840. }
  43841. resized();
  43842. }
  43843. }
  43844. END_JUCE_NAMESPACE
  43845. /*** End of inlined file: juce_ToolbarItemComponent.cpp ***/
  43846. /*** Start of inlined file: juce_ToolbarItemPalette.cpp ***/
  43847. BEGIN_JUCE_NAMESPACE
  43848. ToolbarItemPalette::ToolbarItemPalette (ToolbarItemFactory& factory_,
  43849. Toolbar* const toolbar_)
  43850. : factory (factory_),
  43851. toolbar (toolbar_)
  43852. {
  43853. Component* const itemHolder = new Component();
  43854. Array <int> allIds;
  43855. factory_.getAllToolbarItemIds (allIds);
  43856. for (int i = 0; i < allIds.size(); ++i)
  43857. {
  43858. ToolbarItemComponent* const tc = Toolbar::createItem (factory_, allIds.getUnchecked (i));
  43859. jassert (tc != 0);
  43860. if (tc != 0)
  43861. {
  43862. itemHolder->addAndMakeVisible (tc);
  43863. tc->setEditingMode (ToolbarItemComponent::editableOnPalette);
  43864. }
  43865. }
  43866. viewport = new Viewport();
  43867. viewport->setViewedComponent (itemHolder);
  43868. addAndMakeVisible (viewport);
  43869. }
  43870. ToolbarItemPalette::~ToolbarItemPalette()
  43871. {
  43872. viewport->getViewedComponent()->deleteAllChildren();
  43873. deleteAllChildren();
  43874. }
  43875. void ToolbarItemPalette::resized()
  43876. {
  43877. viewport->setBoundsInset (BorderSize (1));
  43878. Component* const itemHolder = viewport->getViewedComponent();
  43879. const int indent = 8;
  43880. const int preferredWidth = viewport->getWidth() - viewport->getScrollBarThickness() - indent;
  43881. const int height = toolbar->getThickness();
  43882. int x = indent;
  43883. int y = indent;
  43884. int maxX = 0;
  43885. for (int i = 0; i < itemHolder->getNumChildComponents(); ++i)
  43886. {
  43887. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (itemHolder->getChildComponent (i));
  43888. if (tc != 0)
  43889. {
  43890. tc->setStyle (toolbar->getStyle());
  43891. int preferredSize = 1, minSize = 1, maxSize = 1;
  43892. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  43893. {
  43894. if (x + preferredSize > preferredWidth && x > indent)
  43895. {
  43896. x = indent;
  43897. y += height;
  43898. }
  43899. tc->setBounds (x, y, preferredSize, height);
  43900. x += preferredSize + 8;
  43901. maxX = jmax (maxX, x);
  43902. }
  43903. }
  43904. }
  43905. itemHolder->setSize (maxX, y + height + 8);
  43906. }
  43907. void ToolbarItemPalette::replaceComponent (ToolbarItemComponent* const comp)
  43908. {
  43909. ToolbarItemComponent* const tc = Toolbar::createItem (factory, comp->getItemId());
  43910. jassert (tc != 0);
  43911. if (tc != 0)
  43912. {
  43913. tc->setBounds (comp->getBounds());
  43914. tc->setStyle (toolbar->getStyle());
  43915. tc->setEditingMode (comp->getEditingMode());
  43916. viewport->getViewedComponent()->addAndMakeVisible (tc, getIndexOfChildComponent (comp));
  43917. }
  43918. }
  43919. END_JUCE_NAMESPACE
  43920. /*** End of inlined file: juce_ToolbarItemPalette.cpp ***/
  43921. /*** Start of inlined file: juce_TreeView.cpp ***/
  43922. BEGIN_JUCE_NAMESPACE
  43923. class TreeViewContentComponent : public Component,
  43924. public TooltipClient
  43925. {
  43926. public:
  43927. TreeViewContentComponent (TreeView* const owner_)
  43928. : owner (owner_),
  43929. buttonUnderMouse (0),
  43930. isDragging (false)
  43931. {
  43932. }
  43933. ~TreeViewContentComponent()
  43934. {
  43935. deleteAllChildren();
  43936. }
  43937. void mouseDown (const MouseEvent& e)
  43938. {
  43939. updateButtonUnderMouse (e);
  43940. isDragging = false;
  43941. needSelectionOnMouseUp = false;
  43942. Rectangle<int> pos;
  43943. TreeViewItem* const item = findItemAt (e.y, pos);
  43944. if (item == 0)
  43945. return;
  43946. // (if the open/close buttons are hidden, we'll treat clicks to the left of the item
  43947. // as selection clicks)
  43948. if (e.x < pos.getX() && owner->openCloseButtonsVisible)
  43949. {
  43950. if (e.x >= pos.getX() - owner->getIndentSize())
  43951. item->setOpen (! item->isOpen());
  43952. // (clicks to the left of an open/close button are ignored)
  43953. }
  43954. else
  43955. {
  43956. // mouse-down inside the body of the item..
  43957. if (! owner->isMultiSelectEnabled())
  43958. item->setSelected (true, true);
  43959. else if (item->isSelected())
  43960. needSelectionOnMouseUp = ! e.mods.isPopupMenu();
  43961. else
  43962. selectBasedOnModifiers (item, e.mods);
  43963. if (e.x >= pos.getX())
  43964. item->itemClicked (e.withNewPosition (e.getPosition() - pos.getPosition()));
  43965. }
  43966. }
  43967. void mouseUp (const MouseEvent& e)
  43968. {
  43969. updateButtonUnderMouse (e);
  43970. if (needSelectionOnMouseUp && e.mouseWasClicked())
  43971. {
  43972. Rectangle<int> pos;
  43973. TreeViewItem* const item = findItemAt (e.y, pos);
  43974. if (item != 0)
  43975. selectBasedOnModifiers (item, e.mods);
  43976. }
  43977. }
  43978. void mouseDoubleClick (const MouseEvent& e)
  43979. {
  43980. if (e.getNumberOfClicks() != 3) // ignore triple clicks
  43981. {
  43982. Rectangle<int> pos;
  43983. TreeViewItem* const item = findItemAt (e.y, pos);
  43984. if (item != 0 && (e.x >= pos.getX() || ! owner->openCloseButtonsVisible))
  43985. item->itemDoubleClicked (e.withNewPosition (e.getPosition() - pos.getPosition()));
  43986. }
  43987. }
  43988. void mouseDrag (const MouseEvent& e)
  43989. {
  43990. if (isEnabled()
  43991. && ! (isDragging || e.mouseWasClicked()
  43992. || e.getDistanceFromDragStart() < 5
  43993. || e.mods.isPopupMenu()))
  43994. {
  43995. isDragging = true;
  43996. Rectangle<int> pos;
  43997. TreeViewItem* const item = findItemAt (e.getMouseDownY(), pos);
  43998. if (item != 0 && e.getMouseDownX() >= pos.getX())
  43999. {
  44000. const String dragDescription (item->getDragSourceDescription());
  44001. if (dragDescription.isNotEmpty())
  44002. {
  44003. DragAndDropContainer* const dragContainer
  44004. = DragAndDropContainer::findParentDragContainerFor (this);
  44005. if (dragContainer != 0)
  44006. {
  44007. pos.setSize (pos.getWidth(), item->itemHeight);
  44008. Image* dragImage = Component::createComponentSnapshot (pos, true);
  44009. dragImage->multiplyAllAlphas (0.6f);
  44010. Point<int> imageOffset (pos.getX() - e.x, pos.getY() - e.y);
  44011. dragContainer->startDragging (dragDescription, owner, dragImage, true, &imageOffset);
  44012. }
  44013. else
  44014. {
  44015. // to be able to do a drag-and-drop operation, the treeview needs to
  44016. // be inside a component which is also a DragAndDropContainer.
  44017. jassertfalse
  44018. }
  44019. }
  44020. }
  44021. }
  44022. }
  44023. void mouseMove (const MouseEvent& e)
  44024. {
  44025. updateButtonUnderMouse (e);
  44026. }
  44027. void mouseExit (const MouseEvent& e)
  44028. {
  44029. updateButtonUnderMouse (e);
  44030. }
  44031. void paint (Graphics& g);
  44032. TreeViewItem* findItemAt (int y, Rectangle<int>& itemPosition) const;
  44033. static bool isMouseDraggingInChildCompOf (Component* const comp)
  44034. {
  44035. for (int i = Desktop::getInstance().getNumMouseSources(); --i >= 0;)
  44036. {
  44037. MouseInputSource* source = Desktop::getInstance().getMouseSource(i);
  44038. if (source->isDragging())
  44039. {
  44040. Component* const underMouse = source->getComponentUnderMouse();
  44041. if (underMouse != 0 && (comp == underMouse || comp->isParentOf (underMouse)))
  44042. return true;
  44043. }
  44044. }
  44045. return false;
  44046. }
  44047. void updateComponents()
  44048. {
  44049. const int visibleTop = -getY();
  44050. const int visibleBottom = visibleTop + getParentHeight();
  44051. BigInteger itemsToKeep;
  44052. TreeViewItem* item = owner->rootItem;
  44053. int y = (item != 0 && !owner->rootItemVisible) ? -item->itemHeight : 0;
  44054. while (item != 0 && y < visibleBottom)
  44055. {
  44056. y += item->itemHeight;
  44057. if (y >= visibleTop)
  44058. {
  44059. const int index = rowComponentIds.indexOf (item->uid);
  44060. if (index < 0)
  44061. {
  44062. Component* const comp = item->createItemComponent();
  44063. if (comp != 0)
  44064. {
  44065. addAndMakeVisible (comp);
  44066. itemsToKeep.setBit (rowComponentItems.size());
  44067. rowComponentItems.add (item);
  44068. rowComponentIds.add (item->uid);
  44069. rowComponents.add (comp);
  44070. }
  44071. }
  44072. else
  44073. {
  44074. itemsToKeep.setBit (index);
  44075. }
  44076. }
  44077. item = item->getNextVisibleItem (true);
  44078. }
  44079. for (int i = rowComponentItems.size(); --i >= 0;)
  44080. {
  44081. Component* const comp = (Component*) rowComponents.getUnchecked(i);
  44082. bool keep = false;
  44083. if (isParentOf (comp))
  44084. {
  44085. if (itemsToKeep[i])
  44086. {
  44087. const TreeViewItem* const item = (TreeViewItem*) rowComponentItems.getUnchecked(i);
  44088. Rectangle<int> pos (item->getItemPosition (false));
  44089. pos.setSize (pos.getWidth(), item->itemHeight);
  44090. if (pos.getBottom() >= visibleTop && pos.getY() < visibleBottom)
  44091. {
  44092. keep = true;
  44093. comp->setBounds (pos);
  44094. }
  44095. }
  44096. if ((! keep) && isMouseDraggingInChildCompOf (comp))
  44097. {
  44098. keep = true;
  44099. comp->setSize (0, 0);
  44100. }
  44101. }
  44102. if (! keep)
  44103. {
  44104. delete comp;
  44105. rowComponents.remove (i);
  44106. rowComponentIds.remove (i);
  44107. rowComponentItems.remove (i);
  44108. }
  44109. }
  44110. }
  44111. void updateButtonUnderMouse (const MouseEvent& e)
  44112. {
  44113. TreeViewItem* newItem = 0;
  44114. if (owner->openCloseButtonsVisible)
  44115. {
  44116. Rectangle<int> pos;
  44117. TreeViewItem* item = findItemAt (e.y, pos);
  44118. if (item != 0 && e.x < pos.getX() && e.x >= pos.getX() - owner->getIndentSize())
  44119. {
  44120. newItem = item;
  44121. if (! newItem->mightContainSubItems())
  44122. newItem = 0;
  44123. }
  44124. }
  44125. if (buttonUnderMouse != newItem)
  44126. {
  44127. if (buttonUnderMouse != 0 && containsItem (buttonUnderMouse))
  44128. {
  44129. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44130. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44131. }
  44132. buttonUnderMouse = newItem;
  44133. if (buttonUnderMouse != 0)
  44134. {
  44135. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44136. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44137. }
  44138. }
  44139. }
  44140. bool isMouseOverButton (TreeViewItem* item) const throw()
  44141. {
  44142. return item == buttonUnderMouse;
  44143. }
  44144. void resized()
  44145. {
  44146. owner->itemsChanged();
  44147. }
  44148. const String getTooltip()
  44149. {
  44150. Rectangle<int> pos;
  44151. TreeViewItem* const item = findItemAt (getMouseXYRelative().getY(), pos);
  44152. if (item != 0)
  44153. return item->getTooltip();
  44154. return owner->getTooltip();
  44155. }
  44156. juce_UseDebuggingNewOperator
  44157. private:
  44158. TreeView* const owner;
  44159. VoidArray rowComponentItems;
  44160. Array <int> rowComponentIds;
  44161. VoidArray rowComponents;
  44162. TreeViewItem* buttonUnderMouse;
  44163. bool isDragging, needSelectionOnMouseUp;
  44164. TreeViewContentComponent (const TreeViewContentComponent&);
  44165. TreeViewContentComponent& operator= (const TreeViewContentComponent&);
  44166. void selectBasedOnModifiers (TreeViewItem* const item, const ModifierKeys& modifiers)
  44167. {
  44168. TreeViewItem* firstSelected = 0;
  44169. if (modifiers.isShiftDown() && ((firstSelected = owner->getSelectedItem (0)) != 0))
  44170. {
  44171. TreeViewItem* const lastSelected = owner->getSelectedItem (owner->getNumSelectedItems() - 1);
  44172. jassert (lastSelected != 0);
  44173. int rowStart = firstSelected->getRowNumberInTree();
  44174. int rowEnd = lastSelected->getRowNumberInTree();
  44175. if (rowStart > rowEnd)
  44176. swapVariables (rowStart, rowEnd);
  44177. int ourRow = item->getRowNumberInTree();
  44178. int otherEnd = ourRow < rowEnd ? rowStart : rowEnd;
  44179. if (ourRow > otherEnd)
  44180. swapVariables (ourRow, otherEnd);
  44181. for (int i = ourRow; i <= otherEnd; ++i)
  44182. owner->getItemOnRow (i)->setSelected (true, false);
  44183. }
  44184. else
  44185. {
  44186. const bool cmd = modifiers.isCommandDown();
  44187. item->setSelected ((! cmd) || (! item->isSelected()), ! cmd);
  44188. }
  44189. }
  44190. bool containsItem (TreeViewItem* const item) const
  44191. {
  44192. for (int i = rowComponentItems.size(); --i >= 0;)
  44193. if ((TreeViewItem*) rowComponentItems.getUnchecked (i) == item)
  44194. return true;
  44195. return false;
  44196. }
  44197. };
  44198. class TreeViewport : public Viewport
  44199. {
  44200. public:
  44201. TreeViewport() throw() {}
  44202. ~TreeViewport() throw() {}
  44203. void updateComponents()
  44204. {
  44205. if (getViewedComponent() != 0)
  44206. ((TreeViewContentComponent*) getViewedComponent())->updateComponents();
  44207. repaint();
  44208. }
  44209. void visibleAreaChanged (int, int, int, int)
  44210. {
  44211. updateComponents();
  44212. }
  44213. juce_UseDebuggingNewOperator
  44214. private:
  44215. TreeViewport (const TreeViewport&);
  44216. TreeViewport& operator= (const TreeViewport&);
  44217. };
  44218. TreeView::TreeView (const String& componentName)
  44219. : Component (componentName),
  44220. rootItem (0),
  44221. dragInsertPointHighlight (0),
  44222. dragTargetGroupHighlight (0),
  44223. indentSize (24),
  44224. defaultOpenness (false),
  44225. needsRecalculating (true),
  44226. rootItemVisible (true),
  44227. multiSelectEnabled (false),
  44228. openCloseButtonsVisible (true)
  44229. {
  44230. addAndMakeVisible (viewport = new TreeViewport());
  44231. viewport->setViewedComponent (new TreeViewContentComponent (this));
  44232. viewport->setWantsKeyboardFocus (false);
  44233. setWantsKeyboardFocus (true);
  44234. }
  44235. TreeView::~TreeView()
  44236. {
  44237. if (rootItem != 0)
  44238. rootItem->setOwnerView (0);
  44239. deleteAllChildren();
  44240. }
  44241. void TreeView::setRootItem (TreeViewItem* const newRootItem)
  44242. {
  44243. if (rootItem != newRootItem)
  44244. {
  44245. if (newRootItem != 0)
  44246. {
  44247. jassert (newRootItem->ownerView == 0); // can't use a tree item in more than one tree at once..
  44248. if (newRootItem->ownerView != 0)
  44249. newRootItem->ownerView->setRootItem (0);
  44250. }
  44251. if (rootItem != 0)
  44252. rootItem->setOwnerView (0);
  44253. rootItem = newRootItem;
  44254. if (newRootItem != 0)
  44255. newRootItem->setOwnerView (this);
  44256. needsRecalculating = true;
  44257. handleAsyncUpdate();
  44258. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44259. {
  44260. rootItem->setOpen (false); // force a re-open
  44261. rootItem->setOpen (true);
  44262. }
  44263. }
  44264. }
  44265. void TreeView::deleteRootItem()
  44266. {
  44267. const ScopedPointer <TreeViewItem> deleter (rootItem);
  44268. setRootItem (0);
  44269. }
  44270. void TreeView::setRootItemVisible (const bool shouldBeVisible)
  44271. {
  44272. rootItemVisible = shouldBeVisible;
  44273. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44274. {
  44275. rootItem->setOpen (false); // force a re-open
  44276. rootItem->setOpen (true);
  44277. }
  44278. itemsChanged();
  44279. }
  44280. void TreeView::colourChanged()
  44281. {
  44282. setOpaque (findColour (backgroundColourId).isOpaque());
  44283. repaint();
  44284. }
  44285. void TreeView::setIndentSize (const int newIndentSize)
  44286. {
  44287. if (indentSize != newIndentSize)
  44288. {
  44289. indentSize = newIndentSize;
  44290. resized();
  44291. }
  44292. }
  44293. void TreeView::setDefaultOpenness (const bool isOpenByDefault)
  44294. {
  44295. if (defaultOpenness != isOpenByDefault)
  44296. {
  44297. defaultOpenness = isOpenByDefault;
  44298. itemsChanged();
  44299. }
  44300. }
  44301. void TreeView::setMultiSelectEnabled (const bool canMultiSelect)
  44302. {
  44303. multiSelectEnabled = canMultiSelect;
  44304. }
  44305. void TreeView::setOpenCloseButtonsVisible (const bool shouldBeVisible)
  44306. {
  44307. if (openCloseButtonsVisible != shouldBeVisible)
  44308. {
  44309. openCloseButtonsVisible = shouldBeVisible;
  44310. itemsChanged();
  44311. }
  44312. }
  44313. void TreeView::clearSelectedItems()
  44314. {
  44315. if (rootItem != 0)
  44316. rootItem->deselectAllRecursively();
  44317. }
  44318. int TreeView::getNumSelectedItems() const throw()
  44319. {
  44320. return (rootItem != 0) ? rootItem->countSelectedItemsRecursively() : 0;
  44321. }
  44322. TreeViewItem* TreeView::getSelectedItem (const int index) const throw()
  44323. {
  44324. return (rootItem != 0) ? rootItem->getSelectedItemWithIndex (index) : 0;
  44325. }
  44326. int TreeView::getNumRowsInTree() const
  44327. {
  44328. if (rootItem != 0)
  44329. return rootItem->getNumRows() - (rootItemVisible ? 0 : 1);
  44330. return 0;
  44331. }
  44332. TreeViewItem* TreeView::getItemOnRow (int index) const
  44333. {
  44334. if (! rootItemVisible)
  44335. ++index;
  44336. if (rootItem != 0 && index >= 0)
  44337. return rootItem->getItemOnRow (index);
  44338. return 0;
  44339. }
  44340. TreeViewItem* TreeView::getItemAt (int y) const throw()
  44341. {
  44342. TreeViewContentComponent* const tc = (TreeViewContentComponent*) viewport->getViewedComponent();
  44343. Rectangle<int> pos;
  44344. return tc->findItemAt (relativePositionToOtherComponent (tc, Point<int> (0, y)).getY(), pos);
  44345. }
  44346. TreeViewItem* TreeView::findItemFromIdentifierString (const String& identifierString) const
  44347. {
  44348. if (rootItem == 0)
  44349. return 0;
  44350. return rootItem->findItemFromIdentifierString (identifierString);
  44351. }
  44352. XmlElement* TreeView::getOpennessState (const bool alsoIncludeScrollPosition) const
  44353. {
  44354. XmlElement* e = 0;
  44355. if (rootItem != 0)
  44356. {
  44357. e = rootItem->getOpennessState();
  44358. if (e != 0 && alsoIncludeScrollPosition)
  44359. e->setAttribute ("scrollPos", viewport->getViewPositionY());
  44360. }
  44361. return e;
  44362. }
  44363. void TreeView::restoreOpennessState (const XmlElement& newState)
  44364. {
  44365. if (rootItem != 0)
  44366. {
  44367. rootItem->restoreOpennessState (newState);
  44368. if (newState.hasAttribute ("scrollPos"))
  44369. viewport->setViewPosition (viewport->getViewPositionX(),
  44370. newState.getIntAttribute ("scrollPos"));
  44371. }
  44372. }
  44373. void TreeView::paint (Graphics& g)
  44374. {
  44375. g.fillAll (findColour (backgroundColourId));
  44376. }
  44377. void TreeView::resized()
  44378. {
  44379. viewport->setBounds (0, 0, getWidth(), getHeight());
  44380. itemsChanged();
  44381. handleAsyncUpdate();
  44382. }
  44383. void TreeView::enablementChanged()
  44384. {
  44385. repaint();
  44386. }
  44387. void TreeView::moveSelectedRow (int delta)
  44388. {
  44389. if (delta == 0)
  44390. return;
  44391. int rowSelected = 0;
  44392. TreeViewItem* const firstSelected = getSelectedItem (0);
  44393. if (firstSelected != 0)
  44394. rowSelected = firstSelected->getRowNumberInTree();
  44395. rowSelected = jlimit (0, getNumRowsInTree() - 1, rowSelected + delta);
  44396. for (;;)
  44397. {
  44398. TreeViewItem* item = getItemOnRow (rowSelected);
  44399. if (item != 0)
  44400. {
  44401. if (! item->canBeSelected())
  44402. {
  44403. // if the row we want to highlight doesn't allow it, try skipping
  44404. // to the next item..
  44405. const int nextRowToTry = jlimit (0, getNumRowsInTree() - 1,
  44406. rowSelected + (delta < 0 ? -1 : 1));
  44407. if (rowSelected != nextRowToTry)
  44408. {
  44409. rowSelected = nextRowToTry;
  44410. continue;
  44411. }
  44412. else
  44413. {
  44414. break;
  44415. }
  44416. }
  44417. item->setSelected (true, true);
  44418. scrollToKeepItemVisible (item);
  44419. }
  44420. break;
  44421. }
  44422. }
  44423. void TreeView::scrollToKeepItemVisible (TreeViewItem* item)
  44424. {
  44425. if (item != 0 && item->ownerView == this)
  44426. {
  44427. handleAsyncUpdate();
  44428. item = item->getDeepestOpenParentItem();
  44429. int y = item->y;
  44430. int viewTop = viewport->getViewPositionY();
  44431. if (y < viewTop)
  44432. {
  44433. viewport->setViewPosition (viewport->getViewPositionX(), y);
  44434. }
  44435. else if (y + item->itemHeight > viewTop + viewport->getViewHeight())
  44436. {
  44437. viewport->setViewPosition (viewport->getViewPositionX(),
  44438. (y + item->itemHeight) - viewport->getViewHeight());
  44439. }
  44440. }
  44441. }
  44442. bool TreeView::keyPressed (const KeyPress& key)
  44443. {
  44444. if (key.isKeyCode (KeyPress::upKey))
  44445. {
  44446. moveSelectedRow (-1);
  44447. }
  44448. else if (key.isKeyCode (KeyPress::downKey))
  44449. {
  44450. moveSelectedRow (1);
  44451. }
  44452. else if (key.isKeyCode (KeyPress::pageDownKey) || key.isKeyCode (KeyPress::pageUpKey))
  44453. {
  44454. if (rootItem != 0)
  44455. {
  44456. int rowsOnScreen = getHeight() / jmax (1, rootItem->itemHeight);
  44457. if (key.isKeyCode (KeyPress::pageUpKey))
  44458. rowsOnScreen = -rowsOnScreen;
  44459. moveSelectedRow (rowsOnScreen);
  44460. }
  44461. }
  44462. else if (key.isKeyCode (KeyPress::homeKey))
  44463. {
  44464. moveSelectedRow (-0x3fffffff);
  44465. }
  44466. else if (key.isKeyCode (KeyPress::endKey))
  44467. {
  44468. moveSelectedRow (0x3fffffff);
  44469. }
  44470. else if (key.isKeyCode (KeyPress::returnKey))
  44471. {
  44472. TreeViewItem* const firstSelected = getSelectedItem (0);
  44473. if (firstSelected != 0)
  44474. firstSelected->setOpen (! firstSelected->isOpen());
  44475. }
  44476. else if (key.isKeyCode (KeyPress::leftKey))
  44477. {
  44478. TreeViewItem* const firstSelected = getSelectedItem (0);
  44479. if (firstSelected != 0)
  44480. {
  44481. if (firstSelected->isOpen())
  44482. {
  44483. firstSelected->setOpen (false);
  44484. }
  44485. else
  44486. {
  44487. TreeViewItem* parent = firstSelected->parentItem;
  44488. if ((! rootItemVisible) && parent == rootItem)
  44489. parent = 0;
  44490. if (parent != 0)
  44491. {
  44492. parent->setSelected (true, true);
  44493. scrollToKeepItemVisible (parent);
  44494. }
  44495. }
  44496. }
  44497. }
  44498. else if (key.isKeyCode (KeyPress::rightKey))
  44499. {
  44500. TreeViewItem* const firstSelected = getSelectedItem (0);
  44501. if (firstSelected != 0)
  44502. {
  44503. if (firstSelected->isOpen() || ! firstSelected->mightContainSubItems())
  44504. moveSelectedRow (1);
  44505. else
  44506. firstSelected->setOpen (true);
  44507. }
  44508. }
  44509. else
  44510. {
  44511. return false;
  44512. }
  44513. return true;
  44514. }
  44515. void TreeView::itemsChanged() throw()
  44516. {
  44517. needsRecalculating = true;
  44518. repaint();
  44519. triggerAsyncUpdate();
  44520. }
  44521. void TreeView::handleAsyncUpdate()
  44522. {
  44523. if (needsRecalculating)
  44524. {
  44525. needsRecalculating = false;
  44526. const ScopedLock sl (nodeAlterationLock);
  44527. if (rootItem != 0)
  44528. rootItem->updatePositions (rootItemVisible ? 0 : -rootItem->itemHeight);
  44529. ((TreeViewport*) viewport)->updateComponents();
  44530. if (rootItem != 0)
  44531. {
  44532. viewport->getViewedComponent()
  44533. ->setSize (jmax (viewport->getMaximumVisibleWidth(), rootItem->totalWidth),
  44534. rootItem->totalHeight - (rootItemVisible ? 0 : rootItem->itemHeight));
  44535. }
  44536. else
  44537. {
  44538. viewport->getViewedComponent()->setSize (0, 0);
  44539. }
  44540. }
  44541. }
  44542. class TreeViewDragInsertPointHighlight : public Component
  44543. {
  44544. public:
  44545. TreeViewDragInsertPointHighlight()
  44546. : lastItem (0)
  44547. {
  44548. setSize (100, 12);
  44549. setAlwaysOnTop (true);
  44550. setInterceptsMouseClicks (false, false);
  44551. }
  44552. ~TreeViewDragInsertPointHighlight() {}
  44553. void setTargetPosition (TreeViewItem* const item, int insertIndex, const int x, const int y, const int width) throw()
  44554. {
  44555. lastItem = item;
  44556. lastIndex = insertIndex;
  44557. const int offset = getHeight() / 2;
  44558. setBounds (x - offset, y - offset, width - (x - offset), getHeight());
  44559. }
  44560. void paint (Graphics& g)
  44561. {
  44562. Path p;
  44563. const float h = (float) getHeight();
  44564. p.addEllipse (2.0f, 2.0f, h - 4.0f, h - 4.0f);
  44565. p.startNewSubPath (h - 2.0f, h / 2.0f);
  44566. p.lineTo ((float) getWidth(), h / 2.0f);
  44567. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  44568. g.strokePath (p, PathStrokeType (2.0f));
  44569. }
  44570. TreeViewItem* lastItem;
  44571. int lastIndex;
  44572. };
  44573. class TreeViewDragTargetGroupHighlight : public Component
  44574. {
  44575. public:
  44576. TreeViewDragTargetGroupHighlight()
  44577. {
  44578. setAlwaysOnTop (true);
  44579. setInterceptsMouseClicks (false, false);
  44580. }
  44581. ~TreeViewDragTargetGroupHighlight() {}
  44582. void setTargetPosition (TreeViewItem* const item) throw()
  44583. {
  44584. Rectangle<int> r (item->getItemPosition (true));
  44585. r.setHeight (item->getItemHeight());
  44586. setBounds (r);
  44587. }
  44588. void paint (Graphics& g)
  44589. {
  44590. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  44591. g.drawRoundedRectangle (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 3.0f, 2.0f);
  44592. }
  44593. };
  44594. void TreeView::showDragHighlight (TreeViewItem* item, int insertIndex, int x, int y) throw()
  44595. {
  44596. beginDragAutoRepeat (1000 / 30);
  44597. if (dragInsertPointHighlight == 0)
  44598. {
  44599. addAndMakeVisible (dragInsertPointHighlight = new TreeViewDragInsertPointHighlight());
  44600. addAndMakeVisible (dragTargetGroupHighlight = new TreeViewDragTargetGroupHighlight());
  44601. }
  44602. ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)
  44603. ->setTargetPosition (item, insertIndex, x, y, viewport->getViewWidth());
  44604. ((TreeViewDragTargetGroupHighlight*) dragTargetGroupHighlight)
  44605. ->setTargetPosition (item);
  44606. }
  44607. void TreeView::hideDragHighlight() throw()
  44608. {
  44609. deleteAndZero (dragInsertPointHighlight);
  44610. deleteAndZero (dragTargetGroupHighlight);
  44611. }
  44612. TreeViewItem* TreeView::getInsertPosition (int& x, int& y, int& insertIndex,
  44613. const StringArray& files, const String& sourceDescription,
  44614. Component* sourceComponent) const throw()
  44615. {
  44616. insertIndex = 0;
  44617. TreeViewItem* item = getItemAt (y);
  44618. if (item == 0)
  44619. return 0;
  44620. Rectangle<int> itemPos (item->getItemPosition (true));
  44621. insertIndex = item->getIndexInParent();
  44622. const int oldY = y;
  44623. y = itemPos.getY();
  44624. if (item->getNumSubItems() == 0 || ! item->isOpen())
  44625. {
  44626. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  44627. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44628. {
  44629. // Check if we're trying to drag into an empty group item..
  44630. if (oldY > itemPos.getY() + itemPos.getHeight() / 4
  44631. && oldY < itemPos.getBottom() - itemPos.getHeight() / 4)
  44632. {
  44633. insertIndex = 0;
  44634. x = itemPos.getX() + getIndentSize();
  44635. y = itemPos.getBottom();
  44636. return item;
  44637. }
  44638. }
  44639. }
  44640. if (oldY > itemPos.getCentreY())
  44641. {
  44642. y += item->getItemHeight();
  44643. while (item->isLastOfSiblings() && item->parentItem != 0
  44644. && item->parentItem->parentItem != 0)
  44645. {
  44646. if (x > itemPos.getX())
  44647. break;
  44648. item = item->parentItem;
  44649. itemPos = item->getItemPosition (true);
  44650. insertIndex = item->getIndexInParent();
  44651. }
  44652. ++insertIndex;
  44653. }
  44654. x = itemPos.getX();
  44655. return item->parentItem;
  44656. }
  44657. void TreeView::handleDrag (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  44658. {
  44659. const bool scrolled = viewport->autoScroll (x, y, 20, 10);
  44660. int insertIndex;
  44661. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  44662. if (item != 0)
  44663. {
  44664. if (scrolled || dragInsertPointHighlight == 0
  44665. || ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)->lastItem != item
  44666. || ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)->lastIndex != insertIndex)
  44667. {
  44668. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  44669. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44670. showDragHighlight (item, insertIndex, x, y);
  44671. else
  44672. hideDragHighlight();
  44673. }
  44674. }
  44675. else
  44676. {
  44677. hideDragHighlight();
  44678. }
  44679. }
  44680. void TreeView::handleDrop (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  44681. {
  44682. hideDragHighlight();
  44683. int insertIndex;
  44684. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  44685. if (item != 0)
  44686. {
  44687. if (files.size() > 0)
  44688. {
  44689. if (item->isInterestedInFileDrag (files))
  44690. item->filesDropped (files, insertIndex);
  44691. }
  44692. else
  44693. {
  44694. if (item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44695. item->itemDropped (sourceDescription, sourceComponent, insertIndex);
  44696. }
  44697. }
  44698. }
  44699. bool TreeView::isInterestedInFileDrag (const StringArray&)
  44700. {
  44701. return true;
  44702. }
  44703. void TreeView::fileDragEnter (const StringArray& files, int x, int y)
  44704. {
  44705. fileDragMove (files, x, y);
  44706. }
  44707. void TreeView::fileDragMove (const StringArray& files, int x, int y)
  44708. {
  44709. handleDrag (files, String::empty, 0, x, y);
  44710. }
  44711. void TreeView::fileDragExit (const StringArray&)
  44712. {
  44713. hideDragHighlight();
  44714. }
  44715. void TreeView::filesDropped (const StringArray& files, int x, int y)
  44716. {
  44717. handleDrop (files, String::empty, 0, x, y);
  44718. }
  44719. bool TreeView::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  44720. {
  44721. return true;
  44722. }
  44723. void TreeView::itemDragEnter (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44724. {
  44725. itemDragMove (sourceDescription, sourceComponent, x, y);
  44726. }
  44727. void TreeView::itemDragMove (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44728. {
  44729. handleDrag (StringArray(), sourceDescription, sourceComponent, x, y);
  44730. }
  44731. void TreeView::itemDragExit (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  44732. {
  44733. hideDragHighlight();
  44734. }
  44735. void TreeView::itemDropped (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44736. {
  44737. handleDrop (StringArray(), sourceDescription, sourceComponent, x, y);
  44738. }
  44739. void TreeViewContentComponent::paint (Graphics& g)
  44740. {
  44741. if (owner->rootItem != 0)
  44742. {
  44743. owner->handleAsyncUpdate();
  44744. if (! owner->rootItemVisible)
  44745. g.setOrigin (0, -owner->rootItem->itemHeight);
  44746. owner->rootItem->paintRecursively (g, getWidth());
  44747. }
  44748. }
  44749. TreeViewItem* TreeViewContentComponent::findItemAt (int y, Rectangle<int>& itemPosition) const
  44750. {
  44751. if (owner->rootItem != 0)
  44752. {
  44753. owner->handleAsyncUpdate();
  44754. if (! owner->rootItemVisible)
  44755. y += owner->rootItem->itemHeight;
  44756. TreeViewItem* const ti = owner->rootItem->findItemRecursively (y);
  44757. if (ti != 0)
  44758. itemPosition = ti->getItemPosition (false);
  44759. return ti;
  44760. }
  44761. return 0;
  44762. }
  44763. enum TreeViewOpenness
  44764. {
  44765. opennessDefault = 0,
  44766. opennessClosed = 1,
  44767. opennessOpen = 2
  44768. };
  44769. TreeViewItem::TreeViewItem()
  44770. : ownerView (0),
  44771. parentItem (0),
  44772. y (0),
  44773. itemHeight (0),
  44774. totalHeight (0),
  44775. selected (false),
  44776. redrawNeeded (true),
  44777. drawLinesInside (true),
  44778. drawsInLeftMargin (false),
  44779. openness (opennessDefault)
  44780. {
  44781. static int nextUID = 0;
  44782. uid = nextUID++;
  44783. }
  44784. TreeViewItem::~TreeViewItem()
  44785. {
  44786. }
  44787. const String TreeViewItem::getUniqueName() const
  44788. {
  44789. return String::empty;
  44790. }
  44791. void TreeViewItem::itemOpennessChanged (bool)
  44792. {
  44793. }
  44794. int TreeViewItem::getNumSubItems() const throw()
  44795. {
  44796. return subItems.size();
  44797. }
  44798. TreeViewItem* TreeViewItem::getSubItem (const int index) const throw()
  44799. {
  44800. return subItems [index];
  44801. }
  44802. void TreeViewItem::clearSubItems()
  44803. {
  44804. if (subItems.size() > 0)
  44805. {
  44806. if (ownerView != 0)
  44807. {
  44808. const ScopedLock sl (ownerView->nodeAlterationLock);
  44809. subItems.clear();
  44810. treeHasChanged();
  44811. }
  44812. else
  44813. {
  44814. subItems.clear();
  44815. }
  44816. }
  44817. }
  44818. void TreeViewItem::addSubItem (TreeViewItem* const newItem, const int insertPosition)
  44819. {
  44820. if (newItem != 0)
  44821. {
  44822. newItem->parentItem = this;
  44823. newItem->setOwnerView (ownerView);
  44824. newItem->y = 0;
  44825. newItem->itemHeight = newItem->getItemHeight();
  44826. newItem->totalHeight = 0;
  44827. newItem->itemWidth = newItem->getItemWidth();
  44828. newItem->totalWidth = 0;
  44829. if (ownerView != 0)
  44830. {
  44831. const ScopedLock sl (ownerView->nodeAlterationLock);
  44832. subItems.insert (insertPosition, newItem);
  44833. treeHasChanged();
  44834. if (newItem->isOpen())
  44835. newItem->itemOpennessChanged (true);
  44836. }
  44837. else
  44838. {
  44839. subItems.insert (insertPosition, newItem);
  44840. if (newItem->isOpen())
  44841. newItem->itemOpennessChanged (true);
  44842. }
  44843. }
  44844. }
  44845. void TreeViewItem::removeSubItem (const int index, const bool deleteItem)
  44846. {
  44847. if (ownerView != 0)
  44848. {
  44849. const ScopedLock sl (ownerView->nodeAlterationLock);
  44850. if (((unsigned int) index) < (unsigned int) subItems.size())
  44851. {
  44852. subItems.remove (index, deleteItem);
  44853. treeHasChanged();
  44854. }
  44855. }
  44856. else
  44857. {
  44858. subItems.remove (index, deleteItem);
  44859. }
  44860. }
  44861. bool TreeViewItem::isOpen() const throw()
  44862. {
  44863. if (openness == opennessDefault)
  44864. return ownerView != 0 && ownerView->defaultOpenness;
  44865. else
  44866. return openness == opennessOpen;
  44867. }
  44868. void TreeViewItem::setOpen (const bool shouldBeOpen)
  44869. {
  44870. if (isOpen() != shouldBeOpen)
  44871. {
  44872. openness = shouldBeOpen ? opennessOpen
  44873. : opennessClosed;
  44874. treeHasChanged();
  44875. itemOpennessChanged (isOpen());
  44876. }
  44877. }
  44878. bool TreeViewItem::isSelected() const throw()
  44879. {
  44880. return selected;
  44881. }
  44882. void TreeViewItem::deselectAllRecursively()
  44883. {
  44884. setSelected (false, false);
  44885. for (int i = 0; i < subItems.size(); ++i)
  44886. subItems.getUnchecked(i)->deselectAllRecursively();
  44887. }
  44888. void TreeViewItem::setSelected (const bool shouldBeSelected,
  44889. const bool deselectOtherItemsFirst)
  44890. {
  44891. if (shouldBeSelected && ! canBeSelected())
  44892. return;
  44893. if (deselectOtherItemsFirst)
  44894. getTopLevelItem()->deselectAllRecursively();
  44895. if (shouldBeSelected != selected)
  44896. {
  44897. selected = shouldBeSelected;
  44898. if (ownerView != 0)
  44899. ownerView->repaint();
  44900. itemSelectionChanged (shouldBeSelected);
  44901. }
  44902. }
  44903. void TreeViewItem::paintItem (Graphics&, int, int)
  44904. {
  44905. }
  44906. void TreeViewItem::paintOpenCloseButton (Graphics& g, int width, int height, bool isMouseOver)
  44907. {
  44908. ownerView->getLookAndFeel()
  44909. .drawTreeviewPlusMinusBox (g, 0, 0, width, height, ! isOpen(), isMouseOver);
  44910. }
  44911. void TreeViewItem::itemClicked (const MouseEvent&)
  44912. {
  44913. }
  44914. void TreeViewItem::itemDoubleClicked (const MouseEvent&)
  44915. {
  44916. if (mightContainSubItems())
  44917. setOpen (! isOpen());
  44918. }
  44919. void TreeViewItem::itemSelectionChanged (bool)
  44920. {
  44921. }
  44922. const String TreeViewItem::getTooltip()
  44923. {
  44924. return String::empty;
  44925. }
  44926. const String TreeViewItem::getDragSourceDescription()
  44927. {
  44928. return String::empty;
  44929. }
  44930. bool TreeViewItem::isInterestedInFileDrag (const StringArray&)
  44931. {
  44932. return false;
  44933. }
  44934. void TreeViewItem::filesDropped (const StringArray& /*files*/, int /*insertIndex*/)
  44935. {
  44936. }
  44937. bool TreeViewItem::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  44938. {
  44939. return false;
  44940. }
  44941. void TreeViewItem::itemDropped (const String& /*sourceDescription*/, Component* /*sourceComponent*/, int /*insertIndex*/)
  44942. {
  44943. }
  44944. const Rectangle<int> TreeViewItem::getItemPosition (const bool relativeToTreeViewTopLeft) const throw()
  44945. {
  44946. const int indentX = getIndentX();
  44947. int width = itemWidth;
  44948. if (ownerView != 0 && width < 0)
  44949. width = ownerView->viewport->getViewWidth() - indentX;
  44950. Rectangle<int> r (indentX, y, jmax (0, width), totalHeight);
  44951. if (relativeToTreeViewTopLeft)
  44952. r.setPosition (r.getX() - ownerView->viewport->getViewPositionX(),
  44953. r.getY() - ownerView->viewport->getViewPositionY());
  44954. return r;
  44955. }
  44956. void TreeViewItem::treeHasChanged() const throw()
  44957. {
  44958. if (ownerView != 0)
  44959. ownerView->itemsChanged();
  44960. }
  44961. void TreeViewItem::repaintItem() const
  44962. {
  44963. if (ownerView != 0 && areAllParentsOpen())
  44964. {
  44965. const Rectangle<int> r (getItemPosition (true));
  44966. ownerView->viewport->repaint (0, r.getY(), r.getRight(), r.getHeight());
  44967. }
  44968. }
  44969. bool TreeViewItem::areAllParentsOpen() const throw()
  44970. {
  44971. return parentItem == 0
  44972. || (parentItem->isOpen() && parentItem->areAllParentsOpen());
  44973. }
  44974. void TreeViewItem::updatePositions (int newY)
  44975. {
  44976. y = newY;
  44977. itemHeight = getItemHeight();
  44978. totalHeight = itemHeight;
  44979. itemWidth = getItemWidth();
  44980. totalWidth = jmax (itemWidth, 0) + getIndentX();
  44981. if (isOpen())
  44982. {
  44983. newY += totalHeight;
  44984. for (int i = 0; i < subItems.size(); ++i)
  44985. {
  44986. TreeViewItem* const ti = subItems.getUnchecked(i);
  44987. ti->updatePositions (newY);
  44988. newY += ti->totalHeight;
  44989. totalHeight += ti->totalHeight;
  44990. totalWidth = jmax (totalWidth, ti->totalWidth);
  44991. }
  44992. }
  44993. }
  44994. TreeViewItem* TreeViewItem::getDeepestOpenParentItem() throw()
  44995. {
  44996. TreeViewItem* result = this;
  44997. TreeViewItem* item = this;
  44998. while (item->parentItem != 0)
  44999. {
  45000. item = item->parentItem;
  45001. if (! item->isOpen())
  45002. result = item;
  45003. }
  45004. return result;
  45005. }
  45006. void TreeViewItem::setOwnerView (TreeView* const newOwner) throw()
  45007. {
  45008. ownerView = newOwner;
  45009. for (int i = subItems.size(); --i >= 0;)
  45010. subItems.getUnchecked(i)->setOwnerView (newOwner);
  45011. }
  45012. int TreeViewItem::getIndentX() const throw()
  45013. {
  45014. const int indentWidth = ownerView->getIndentSize();
  45015. int x = ownerView->rootItemVisible ? indentWidth : 0;
  45016. if (! ownerView->openCloseButtonsVisible)
  45017. x -= indentWidth;
  45018. TreeViewItem* p = parentItem;
  45019. while (p != 0)
  45020. {
  45021. x += indentWidth;
  45022. p = p->parentItem;
  45023. }
  45024. return x;
  45025. }
  45026. void TreeViewItem::setDrawsInLeftMargin (bool canDrawInLeftMargin) throw()
  45027. {
  45028. drawsInLeftMargin = canDrawInLeftMargin;
  45029. }
  45030. void TreeViewItem::paintRecursively (Graphics& g, int width)
  45031. {
  45032. jassert (ownerView != 0);
  45033. if (ownerView == 0)
  45034. return;
  45035. const int indent = getIndentX();
  45036. const int itemW = itemWidth < 0 ? width - indent : itemWidth;
  45037. g.setColour (ownerView->findColour (TreeView::linesColourId));
  45038. const float halfH = itemHeight * 0.5f;
  45039. int depth = 0;
  45040. TreeViewItem* p = parentItem;
  45041. while (p != 0)
  45042. {
  45043. ++depth;
  45044. p = p->parentItem;
  45045. }
  45046. if (! ownerView->rootItemVisible)
  45047. --depth;
  45048. const int indentWidth = ownerView->getIndentSize();
  45049. if (depth >= 0 && ownerView->openCloseButtonsVisible)
  45050. {
  45051. float x = (depth + 0.5f) * indentWidth;
  45052. if (depth >= 0)
  45053. {
  45054. if (parentItem != 0 && parentItem->drawLinesInside)
  45055. g.drawLine (x, 0, x, isLastOfSiblings() ? halfH : (float) itemHeight);
  45056. if ((parentItem != 0 && parentItem->drawLinesInside)
  45057. || (parentItem == 0 && drawLinesInside))
  45058. g.drawLine (x, halfH, x + indentWidth / 2, halfH);
  45059. }
  45060. p = parentItem;
  45061. int d = depth;
  45062. while (p != 0 && --d >= 0)
  45063. {
  45064. x -= (float) indentWidth;
  45065. if ((p->parentItem == 0 || p->parentItem->drawLinesInside)
  45066. && ! p->isLastOfSiblings())
  45067. {
  45068. g.drawLine (x, 0, x, (float) itemHeight);
  45069. }
  45070. p = p->parentItem;
  45071. }
  45072. if (mightContainSubItems())
  45073. {
  45074. g.saveState();
  45075. g.setOrigin (depth * indentWidth, 0);
  45076. g.reduceClipRegion (0, 0, indentWidth, itemHeight);
  45077. paintOpenCloseButton (g, indentWidth, itemHeight,
  45078. ((TreeViewContentComponent*) ownerView->viewport->getViewedComponent())
  45079. ->isMouseOverButton (this));
  45080. g.restoreState();
  45081. }
  45082. }
  45083. {
  45084. g.saveState();
  45085. g.setOrigin (indent, 0);
  45086. if (g.reduceClipRegion (drawsInLeftMargin ? -indent : 0, 0,
  45087. drawsInLeftMargin ? itemW + indent : itemW, itemHeight))
  45088. paintItem (g, itemW, itemHeight);
  45089. g.restoreState();
  45090. }
  45091. if (isOpen())
  45092. {
  45093. const Rectangle<int> clip (g.getClipBounds());
  45094. for (int i = 0; i < subItems.size(); ++i)
  45095. {
  45096. TreeViewItem* const ti = subItems.getUnchecked(i);
  45097. const int relY = ti->y - y;
  45098. if (relY >= clip.getBottom())
  45099. break;
  45100. if (relY + ti->totalHeight >= clip.getY())
  45101. {
  45102. g.saveState();
  45103. g.setOrigin (0, relY);
  45104. if (g.reduceClipRegion (0, 0, width, ti->totalHeight))
  45105. ti->paintRecursively (g, width);
  45106. g.restoreState();
  45107. }
  45108. }
  45109. }
  45110. }
  45111. bool TreeViewItem::isLastOfSiblings() const throw()
  45112. {
  45113. return parentItem == 0
  45114. || parentItem->subItems.getLast() == this;
  45115. }
  45116. int TreeViewItem::getIndexInParent() const throw()
  45117. {
  45118. if (parentItem == 0)
  45119. return 0;
  45120. return parentItem->subItems.indexOf (this);
  45121. }
  45122. TreeViewItem* TreeViewItem::getTopLevelItem() throw()
  45123. {
  45124. return (parentItem == 0) ? this
  45125. : parentItem->getTopLevelItem();
  45126. }
  45127. int TreeViewItem::getNumRows() const throw()
  45128. {
  45129. int num = 1;
  45130. if (isOpen())
  45131. {
  45132. for (int i = subItems.size(); --i >= 0;)
  45133. num += subItems.getUnchecked(i)->getNumRows();
  45134. }
  45135. return num;
  45136. }
  45137. TreeViewItem* TreeViewItem::getItemOnRow (int index) throw()
  45138. {
  45139. if (index == 0)
  45140. return this;
  45141. if (index > 0 && isOpen())
  45142. {
  45143. --index;
  45144. for (int i = 0; i < subItems.size(); ++i)
  45145. {
  45146. TreeViewItem* const item = subItems.getUnchecked(i);
  45147. if (index == 0)
  45148. return item;
  45149. const int numRows = item->getNumRows();
  45150. if (numRows > index)
  45151. return item->getItemOnRow (index);
  45152. index -= numRows;
  45153. }
  45154. }
  45155. return 0;
  45156. }
  45157. TreeViewItem* TreeViewItem::findItemRecursively (int targetY) throw()
  45158. {
  45159. if (((unsigned int) targetY) < (unsigned int) totalHeight)
  45160. {
  45161. const int h = itemHeight;
  45162. if (targetY < h)
  45163. return this;
  45164. if (isOpen())
  45165. {
  45166. targetY -= h;
  45167. for (int i = 0; i < subItems.size(); ++i)
  45168. {
  45169. TreeViewItem* const ti = subItems.getUnchecked(i);
  45170. if (targetY < ti->totalHeight)
  45171. return ti->findItemRecursively (targetY);
  45172. targetY -= ti->totalHeight;
  45173. }
  45174. }
  45175. }
  45176. return 0;
  45177. }
  45178. int TreeViewItem::countSelectedItemsRecursively() const throw()
  45179. {
  45180. int total = 0;
  45181. if (isSelected())
  45182. ++total;
  45183. for (int i = subItems.size(); --i >= 0;)
  45184. total += subItems.getUnchecked(i)->countSelectedItemsRecursively();
  45185. return total;
  45186. }
  45187. TreeViewItem* TreeViewItem::getSelectedItemWithIndex (int index) throw()
  45188. {
  45189. if (isSelected())
  45190. {
  45191. if (index == 0)
  45192. return this;
  45193. --index;
  45194. }
  45195. if (index >= 0)
  45196. {
  45197. for (int i = 0; i < subItems.size(); ++i)
  45198. {
  45199. TreeViewItem* const item = subItems.getUnchecked(i);
  45200. TreeViewItem* const found = item->getSelectedItemWithIndex (index);
  45201. if (found != 0)
  45202. return found;
  45203. index -= item->countSelectedItemsRecursively();
  45204. }
  45205. }
  45206. return 0;
  45207. }
  45208. int TreeViewItem::getRowNumberInTree() const throw()
  45209. {
  45210. if (parentItem != 0 && ownerView != 0)
  45211. {
  45212. int n = 1 + parentItem->getRowNumberInTree();
  45213. int ourIndex = parentItem->subItems.indexOf (this);
  45214. jassert (ourIndex >= 0);
  45215. while (--ourIndex >= 0)
  45216. n += parentItem->subItems [ourIndex]->getNumRows();
  45217. if (parentItem->parentItem == 0
  45218. && ! ownerView->rootItemVisible)
  45219. --n;
  45220. return n;
  45221. }
  45222. else
  45223. {
  45224. return 0;
  45225. }
  45226. }
  45227. void TreeViewItem::setLinesDrawnForSubItems (const bool drawLines) throw()
  45228. {
  45229. drawLinesInside = drawLines;
  45230. }
  45231. TreeViewItem* TreeViewItem::getNextVisibleItem (const bool recurse) const throw()
  45232. {
  45233. if (recurse && isOpen() && subItems.size() > 0)
  45234. return subItems [0];
  45235. if (parentItem != 0)
  45236. {
  45237. const int nextIndex = parentItem->subItems.indexOf (this) + 1;
  45238. if (nextIndex >= parentItem->subItems.size())
  45239. return parentItem->getNextVisibleItem (false);
  45240. return parentItem->subItems [nextIndex];
  45241. }
  45242. return 0;
  45243. }
  45244. const String TreeViewItem::getItemIdentifierString() const
  45245. {
  45246. String s;
  45247. if (parentItem != 0)
  45248. s = parentItem->getItemIdentifierString();
  45249. return s + "/" + getUniqueName().replaceCharacter ('/', '\\');
  45250. }
  45251. TreeViewItem* TreeViewItem::findItemFromIdentifierString (const String& identifierString)
  45252. {
  45253. const String uid (getUniqueName());
  45254. if (uid == identifierString)
  45255. return this;
  45256. if (identifierString.startsWith (uid + "/"))
  45257. {
  45258. const String remainingPath (identifierString.substring (uid.length() + 1));
  45259. bool wasOpen = isOpen();
  45260. setOpen (true);
  45261. for (int i = subItems.size(); --i >= 0;)
  45262. {
  45263. TreeViewItem* item = subItems.getUnchecked(i)->findItemFromIdentifierString (remainingPath);
  45264. if (item != 0)
  45265. return item;
  45266. }
  45267. setOpen (wasOpen);
  45268. }
  45269. return 0;
  45270. }
  45271. void TreeViewItem::restoreOpennessState (const XmlElement& e) throw()
  45272. {
  45273. if (e.hasTagName ("CLOSED"))
  45274. {
  45275. setOpen (false);
  45276. }
  45277. else if (e.hasTagName ("OPEN"))
  45278. {
  45279. setOpen (true);
  45280. forEachXmlChildElement (e, n)
  45281. {
  45282. const String id (n->getStringAttribute ("id"));
  45283. for (int i = 0; i < subItems.size(); ++i)
  45284. {
  45285. TreeViewItem* const ti = subItems.getUnchecked(i);
  45286. if (ti->getUniqueName() == id)
  45287. {
  45288. ti->restoreOpennessState (*n);
  45289. break;
  45290. }
  45291. }
  45292. }
  45293. }
  45294. }
  45295. XmlElement* TreeViewItem::getOpennessState() const throw()
  45296. {
  45297. const String name (getUniqueName());
  45298. if (name.isNotEmpty())
  45299. {
  45300. XmlElement* e;
  45301. if (isOpen())
  45302. {
  45303. e = new XmlElement ("OPEN");
  45304. for (int i = 0; i < subItems.size(); ++i)
  45305. e->addChildElement (subItems.getUnchecked(i)->getOpennessState());
  45306. }
  45307. else
  45308. {
  45309. e = new XmlElement ("CLOSED");
  45310. }
  45311. e->setAttribute ("id", name);
  45312. return e;
  45313. }
  45314. else
  45315. {
  45316. // trying to save the openness for an element that has no name - this won't
  45317. // work because it needs the names to identify what to open.
  45318. jassertfalse
  45319. }
  45320. return 0;
  45321. }
  45322. END_JUCE_NAMESPACE
  45323. /*** End of inlined file: juce_TreeView.cpp ***/
  45324. /*** Start of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45325. BEGIN_JUCE_NAMESPACE
  45326. DirectoryContentsDisplayComponent::DirectoryContentsDisplayComponent (DirectoryContentsList& listToShow)
  45327. : fileList (listToShow)
  45328. {
  45329. }
  45330. DirectoryContentsDisplayComponent::~DirectoryContentsDisplayComponent()
  45331. {
  45332. }
  45333. FileBrowserListener::~FileBrowserListener()
  45334. {
  45335. }
  45336. void DirectoryContentsDisplayComponent::addListener (FileBrowserListener* const listener) throw()
  45337. {
  45338. listeners.add (listener);
  45339. }
  45340. void DirectoryContentsDisplayComponent::removeListener (FileBrowserListener* const listener) throw()
  45341. {
  45342. listeners.remove (listener);
  45343. }
  45344. void DirectoryContentsDisplayComponent::sendSelectionChangeMessage()
  45345. {
  45346. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45347. listeners.callChecked (checker, &FileBrowserListener::selectionChanged);
  45348. }
  45349. void DirectoryContentsDisplayComponent::sendMouseClickMessage (const File& file, const MouseEvent& e)
  45350. {
  45351. if (fileList.getDirectory().exists())
  45352. {
  45353. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45354. listeners.callChecked (checker, &FileBrowserListener::fileClicked, file, e);
  45355. }
  45356. }
  45357. void DirectoryContentsDisplayComponent::sendDoubleClickMessage (const File& file)
  45358. {
  45359. if (fileList.getDirectory().exists())
  45360. {
  45361. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45362. listeners.callChecked (checker, &FileBrowserListener::fileDoubleClicked, file);
  45363. }
  45364. }
  45365. END_JUCE_NAMESPACE
  45366. /*** End of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45367. /*** Start of inlined file: juce_DirectoryContentsList.cpp ***/
  45368. BEGIN_JUCE_NAMESPACE
  45369. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  45370. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  45371. Time* creationTime, bool* isReadOnly);
  45372. bool juce_findFileNext (void* handle, String& resultFile,
  45373. bool* isDirectory, bool* isHidden, int64* fileSize,
  45374. Time* modTime, Time* creationTime, bool* isReadOnly);
  45375. void juce_findFileClose (void* handle);
  45376. DirectoryContentsList::DirectoryContentsList (const FileFilter* const fileFilter_,
  45377. TimeSliceThread& thread_)
  45378. : fileFilter (fileFilter_),
  45379. thread (thread_),
  45380. includeDirectories (false),
  45381. includeFiles (false),
  45382. ignoreHiddenFiles (true),
  45383. fileFindHandle (0),
  45384. shouldStop (true)
  45385. {
  45386. }
  45387. DirectoryContentsList::~DirectoryContentsList()
  45388. {
  45389. clear();
  45390. }
  45391. void DirectoryContentsList::setIgnoresHiddenFiles (const bool shouldIgnoreHiddenFiles)
  45392. {
  45393. ignoreHiddenFiles = shouldIgnoreHiddenFiles;
  45394. }
  45395. const File& DirectoryContentsList::getDirectory() const
  45396. {
  45397. return root;
  45398. }
  45399. void DirectoryContentsList::setDirectory (const File& directory,
  45400. const bool includeDirectories_,
  45401. const bool includeFiles_)
  45402. {
  45403. if (directory != root
  45404. || includeDirectories != includeDirectories_
  45405. || includeFiles != includeFiles_)
  45406. {
  45407. clear();
  45408. root = directory;
  45409. includeDirectories = includeDirectories_;
  45410. includeFiles = includeFiles_;
  45411. refresh();
  45412. }
  45413. }
  45414. void DirectoryContentsList::clear()
  45415. {
  45416. shouldStop = true;
  45417. thread.removeTimeSliceClient (this);
  45418. if (fileFindHandle != 0)
  45419. {
  45420. juce_findFileClose (fileFindHandle);
  45421. fileFindHandle = 0;
  45422. }
  45423. if (files.size() > 0)
  45424. {
  45425. files.clear();
  45426. changed();
  45427. }
  45428. }
  45429. void DirectoryContentsList::refresh()
  45430. {
  45431. clear();
  45432. if (root.isDirectory())
  45433. {
  45434. String fileFound;
  45435. bool fileFoundIsDir, isHidden, isReadOnly;
  45436. int64 fileSize;
  45437. Time modTime, creationTime;
  45438. String path (root.getFullPathName());
  45439. if (! path.endsWithChar (File::separator))
  45440. path += File::separator;
  45441. jassert (fileFindHandle == 0);
  45442. fileFindHandle = juce_findFileStart (path, "*", fileFound,
  45443. &fileFoundIsDir,
  45444. &isHidden,
  45445. &fileSize,
  45446. &modTime,
  45447. &creationTime,
  45448. &isReadOnly);
  45449. if (fileFindHandle != 0 && fileFound.isNotEmpty())
  45450. {
  45451. if (addFile (fileFound, fileFoundIsDir, isHidden,
  45452. fileSize, modTime, creationTime, isReadOnly))
  45453. {
  45454. changed();
  45455. }
  45456. }
  45457. shouldStop = false;
  45458. thread.addTimeSliceClient (this);
  45459. }
  45460. }
  45461. int DirectoryContentsList::getNumFiles() const
  45462. {
  45463. return files.size();
  45464. }
  45465. bool DirectoryContentsList::getFileInfo (const int index,
  45466. FileInfo& result) const
  45467. {
  45468. const ScopedLock sl (fileListLock);
  45469. const FileInfo* const info = files [index];
  45470. if (info != 0)
  45471. {
  45472. result = *info;
  45473. return true;
  45474. }
  45475. return false;
  45476. }
  45477. const File DirectoryContentsList::getFile (const int index) const
  45478. {
  45479. const ScopedLock sl (fileListLock);
  45480. const FileInfo* const info = files [index];
  45481. if (info != 0)
  45482. return root.getChildFile (info->filename);
  45483. return File::nonexistent;
  45484. }
  45485. bool DirectoryContentsList::isStillLoading() const
  45486. {
  45487. return fileFindHandle != 0;
  45488. }
  45489. void DirectoryContentsList::changed()
  45490. {
  45491. sendChangeMessage (this);
  45492. }
  45493. bool DirectoryContentsList::useTimeSlice()
  45494. {
  45495. const uint32 startTime = Time::getApproximateMillisecondCounter();
  45496. bool hasChanged = false;
  45497. for (int i = 100; --i >= 0;)
  45498. {
  45499. if (! checkNextFile (hasChanged))
  45500. {
  45501. if (hasChanged)
  45502. changed();
  45503. return false;
  45504. }
  45505. if (shouldStop || (Time::getApproximateMillisecondCounter() > startTime + 150))
  45506. break;
  45507. }
  45508. if (hasChanged)
  45509. changed();
  45510. return true;
  45511. }
  45512. bool DirectoryContentsList::checkNextFile (bool& hasChanged)
  45513. {
  45514. if (fileFindHandle != 0)
  45515. {
  45516. String fileFound;
  45517. bool fileFoundIsDir, isHidden, isReadOnly;
  45518. int64 fileSize;
  45519. Time modTime, creationTime;
  45520. if (juce_findFileNext (fileFindHandle, fileFound,
  45521. &fileFoundIsDir, &isHidden,
  45522. &fileSize,
  45523. &modTime,
  45524. &creationTime,
  45525. &isReadOnly))
  45526. {
  45527. if (addFile (fileFound, fileFoundIsDir, isHidden, fileSize,
  45528. modTime, creationTime, isReadOnly))
  45529. {
  45530. hasChanged = true;
  45531. }
  45532. return true;
  45533. }
  45534. else
  45535. {
  45536. juce_findFileClose (fileFindHandle);
  45537. fileFindHandle = 0;
  45538. }
  45539. }
  45540. return false;
  45541. }
  45542. int DirectoryContentsList::compareElements (const DirectoryContentsList::FileInfo* const first,
  45543. const DirectoryContentsList::FileInfo* const second)
  45544. {
  45545. #if JUCE_WINDOWS
  45546. if (first->isDirectory != second->isDirectory)
  45547. return first->isDirectory ? -1 : 1;
  45548. #endif
  45549. return first->filename.compareIgnoreCase (second->filename);
  45550. }
  45551. bool DirectoryContentsList::addFile (const String& filename,
  45552. const bool isDir,
  45553. const bool isHidden,
  45554. const int64 fileSize,
  45555. const Time& modTime,
  45556. const Time& creationTime,
  45557. const bool isReadOnly)
  45558. {
  45559. if (filename == ".."
  45560. || filename == "."
  45561. || (ignoreHiddenFiles && isHidden))
  45562. return false;
  45563. const File file (root.getChildFile (filename));
  45564. if (((isDir && includeDirectories) || ((! isDir) && includeFiles))
  45565. && (fileFilter == 0
  45566. || ((! isDir) && fileFilter->isFileSuitable (file))
  45567. || (isDir && fileFilter->isDirectorySuitable (file))))
  45568. {
  45569. ScopedPointer <FileInfo> info (new FileInfo());
  45570. info->filename = filename;
  45571. info->fileSize = fileSize;
  45572. info->modificationTime = modTime;
  45573. info->creationTime = creationTime;
  45574. info->isDirectory = isDir;
  45575. info->isReadOnly = isReadOnly;
  45576. const ScopedLock sl (fileListLock);
  45577. for (int i = files.size(); --i >= 0;)
  45578. if (files.getUnchecked(i)->filename == info->filename)
  45579. return false;
  45580. files.addSorted (*this, info.release());
  45581. return true;
  45582. }
  45583. return false;
  45584. }
  45585. END_JUCE_NAMESPACE
  45586. /*** End of inlined file: juce_DirectoryContentsList.cpp ***/
  45587. /*** Start of inlined file: juce_FileBrowserComponent.cpp ***/
  45588. BEGIN_JUCE_NAMESPACE
  45589. FileBrowserComponent::FileBrowserComponent (int flags_,
  45590. const File& initialFileOrDirectory,
  45591. const FileFilter* fileFilter_,
  45592. FilePreviewComponent* previewComp_)
  45593. : FileFilter (String::empty),
  45594. fileFilter (fileFilter_),
  45595. flags (flags_),
  45596. previewComp (previewComp_),
  45597. thread ("Juce FileBrowser")
  45598. {
  45599. // You need to specify one or other of the open/save flags..
  45600. jassert ((flags & (saveMode | openMode)) != 0);
  45601. jassert ((flags & (saveMode | openMode)) != (saveMode | openMode));
  45602. // You need to specify at least one of these flags..
  45603. jassert ((flags & (canSelectFiles | canSelectDirectories)) != 0);
  45604. String filename;
  45605. if (initialFileOrDirectory == File::nonexistent)
  45606. {
  45607. currentRoot = File::getCurrentWorkingDirectory();
  45608. }
  45609. else if (initialFileOrDirectory.isDirectory())
  45610. {
  45611. currentRoot = initialFileOrDirectory;
  45612. }
  45613. else
  45614. {
  45615. chosenFiles.add (initialFileOrDirectory);
  45616. currentRoot = initialFileOrDirectory.getParentDirectory();
  45617. filename = initialFileOrDirectory.getFileName();
  45618. }
  45619. fileList = new DirectoryContentsList (this, thread);
  45620. if ((flags & useTreeView) != 0)
  45621. {
  45622. FileTreeComponent* const tree = new FileTreeComponent (*fileList);
  45623. if ((flags & canSelectMultipleItems) != 0)
  45624. tree->setMultiSelectEnabled (true);
  45625. addAndMakeVisible (tree);
  45626. fileListComponent = tree;
  45627. }
  45628. else
  45629. {
  45630. FileListComponent* const list = new FileListComponent (*fileList);
  45631. list->setOutlineThickness (1);
  45632. if ((flags & canSelectMultipleItems) != 0)
  45633. list->setMultipleSelectionEnabled (true);
  45634. addAndMakeVisible (list);
  45635. fileListComponent = list;
  45636. }
  45637. fileListComponent->addListener (this);
  45638. addAndMakeVisible (currentPathBox = new ComboBox ("path"));
  45639. currentPathBox->setEditableText (true);
  45640. StringArray rootNames, rootPaths;
  45641. const BigInteger separators (getRoots (rootNames, rootPaths));
  45642. for (int i = 0; i < rootNames.size(); ++i)
  45643. {
  45644. if (separators [i])
  45645. currentPathBox->addSeparator();
  45646. currentPathBox->addItem (rootNames[i], i + 1);
  45647. }
  45648. currentPathBox->addSeparator();
  45649. currentPathBox->addListener (this);
  45650. addAndMakeVisible (filenameBox = new TextEditor());
  45651. filenameBox->setMultiLine (false);
  45652. filenameBox->setSelectAllWhenFocused (true);
  45653. filenameBox->setText (filename, false);
  45654. filenameBox->addListener (this);
  45655. filenameBox->setReadOnly ((flags & (filenameBoxIsReadOnly | canSelectMultipleItems)) != 0);
  45656. Label* label = new Label ("f", TRANS("file:"));
  45657. addAndMakeVisible (label);
  45658. label->attachToComponent (filenameBox, true);
  45659. addAndMakeVisible (goUpButton = getLookAndFeel().createFileBrowserGoUpButton());
  45660. goUpButton->addButtonListener (this);
  45661. goUpButton->setTooltip (TRANS ("go up to parent directory"));
  45662. if (previewComp != 0)
  45663. addAndMakeVisible (previewComp);
  45664. setRoot (currentRoot);
  45665. thread.startThread (4);
  45666. }
  45667. FileBrowserComponent::~FileBrowserComponent()
  45668. {
  45669. if (previewComp != 0)
  45670. removeChildComponent (previewComp);
  45671. deleteAllChildren();
  45672. fileList = 0;
  45673. thread.stopThread (10000);
  45674. }
  45675. void FileBrowserComponent::addListener (FileBrowserListener* const newListener) throw()
  45676. {
  45677. listeners.add (newListener);
  45678. }
  45679. void FileBrowserComponent::removeListener (FileBrowserListener* const listener) throw()
  45680. {
  45681. listeners.remove (listener);
  45682. }
  45683. bool FileBrowserComponent::isSaveMode() const throw()
  45684. {
  45685. return (flags & saveMode) != 0;
  45686. }
  45687. int FileBrowserComponent::getNumSelectedFiles() const throw()
  45688. {
  45689. if (chosenFiles.size() == 0 && currentFileIsValid())
  45690. return 1;
  45691. return chosenFiles.size();
  45692. }
  45693. const File FileBrowserComponent::getSelectedFile (int index) const throw()
  45694. {
  45695. if (! filenameBox->isReadOnly())
  45696. return currentRoot.getChildFile (filenameBox->getText());
  45697. else
  45698. return chosenFiles[index];
  45699. }
  45700. bool FileBrowserComponent::currentFileIsValid() const
  45701. {
  45702. if (isSaveMode())
  45703. return ! getSelectedFile (0).isDirectory();
  45704. else
  45705. return getSelectedFile (0).exists();
  45706. }
  45707. const File FileBrowserComponent::getHighlightedFile() const throw()
  45708. {
  45709. return fileListComponent->getSelectedFile (0);
  45710. }
  45711. bool FileBrowserComponent::isFileSuitable (const File& file) const
  45712. {
  45713. return (flags & canSelectFiles) != 0 ? (fileFilter == 0 || fileFilter->isFileSuitable (file))
  45714. : false;
  45715. }
  45716. bool FileBrowserComponent::isDirectorySuitable (const File&) const
  45717. {
  45718. return true;
  45719. }
  45720. bool FileBrowserComponent::isFileOrDirSuitable (const File& f) const
  45721. {
  45722. if (f.isDirectory())
  45723. return (flags & canSelectDirectories) != 0 && (fileFilter == 0 || fileFilter->isDirectorySuitable (f));
  45724. return (flags & canSelectFiles) != 0 && f.exists()
  45725. && (fileFilter == 0 || fileFilter->isFileSuitable (f));
  45726. }
  45727. const File FileBrowserComponent::getRoot() const
  45728. {
  45729. return currentRoot;
  45730. }
  45731. void FileBrowserComponent::setRoot (const File& newRootDirectory)
  45732. {
  45733. if (currentRoot != newRootDirectory)
  45734. {
  45735. fileListComponent->scrollToTop();
  45736. String path (newRootDirectory.getFullPathName());
  45737. if (path.isEmpty())
  45738. path += File::separator;
  45739. StringArray rootNames, rootPaths;
  45740. getRoots (rootNames, rootPaths);
  45741. if (! rootPaths.contains (path, true))
  45742. {
  45743. bool alreadyListed = false;
  45744. for (int i = currentPathBox->getNumItems(); --i >= 0;)
  45745. {
  45746. if (currentPathBox->getItemText (i).equalsIgnoreCase (path))
  45747. {
  45748. alreadyListed = true;
  45749. break;
  45750. }
  45751. }
  45752. if (! alreadyListed)
  45753. currentPathBox->addItem (path, currentPathBox->getNumItems() + 2);
  45754. }
  45755. }
  45756. currentRoot = newRootDirectory;
  45757. fileList->setDirectory (currentRoot, true, true);
  45758. String currentRootName (currentRoot.getFullPathName());
  45759. if (currentRootName.isEmpty())
  45760. currentRootName += File::separator;
  45761. currentPathBox->setText (currentRootName, true);
  45762. goUpButton->setEnabled (currentRoot.getParentDirectory().isDirectory()
  45763. && currentRoot.getParentDirectory() != currentRoot);
  45764. }
  45765. void FileBrowserComponent::goUp()
  45766. {
  45767. setRoot (getRoot().getParentDirectory());
  45768. }
  45769. void FileBrowserComponent::refresh()
  45770. {
  45771. fileList->refresh();
  45772. }
  45773. const String FileBrowserComponent::getActionVerb() const
  45774. {
  45775. return isSaveMode() ? TRANS("Save") : TRANS("Open");
  45776. }
  45777. FilePreviewComponent* FileBrowserComponent::getPreviewComponent() const throw()
  45778. {
  45779. return previewComp;
  45780. }
  45781. void FileBrowserComponent::resized()
  45782. {
  45783. getLookAndFeel()
  45784. .layoutFileBrowserComponent (*this, fileListComponent,
  45785. previewComp, currentPathBox,
  45786. filenameBox, goUpButton);
  45787. }
  45788. void FileBrowserComponent::sendListenerChangeMessage()
  45789. {
  45790. Component::BailOutChecker checker (this);
  45791. if (previewComp != 0)
  45792. previewComp->selectedFileChanged (getSelectedFile (0));
  45793. // You shouldn't delete the browser when the file gets changed!
  45794. jassert (! checker.shouldBailOut());
  45795. listeners.callChecked (checker, &FileBrowserListener::selectionChanged);
  45796. }
  45797. void FileBrowserComponent::selectionChanged()
  45798. {
  45799. StringArray newFilenames;
  45800. bool resetChosenFiles = true;
  45801. for (int i = 0; i < fileListComponent->getNumSelectedFiles(); ++i)
  45802. {
  45803. const File f (fileListComponent->getSelectedFile (i));
  45804. if (isFileOrDirSuitable (f))
  45805. {
  45806. if (resetChosenFiles)
  45807. {
  45808. chosenFiles.clear();
  45809. resetChosenFiles = false;
  45810. }
  45811. chosenFiles.add (f);
  45812. newFilenames.add (f.getRelativePathFrom (getRoot()));
  45813. }
  45814. }
  45815. if (newFilenames.size() > 0)
  45816. filenameBox->setText (newFilenames.joinIntoString (", "), false);
  45817. sendListenerChangeMessage();
  45818. }
  45819. void FileBrowserComponent::fileClicked (const File& f, const MouseEvent& e)
  45820. {
  45821. Component::BailOutChecker checker (this);
  45822. listeners.callChecked (checker, &FileBrowserListener::fileClicked, f, e);
  45823. }
  45824. void FileBrowserComponent::fileDoubleClicked (const File& f)
  45825. {
  45826. if (f.isDirectory())
  45827. {
  45828. setRoot (f);
  45829. }
  45830. else
  45831. {
  45832. Component::BailOutChecker checker (this);
  45833. listeners.callChecked (checker, &FileBrowserListener::fileDoubleClicked, f);
  45834. }
  45835. }
  45836. bool FileBrowserComponent::keyPressed (const KeyPress& key)
  45837. {
  45838. #if JUCE_LINUX || JUCE_WINDOWS
  45839. if (key.getModifiers().isCommandDown()
  45840. && (key.getKeyCode() == 'H' || key.getKeyCode() == 'h'))
  45841. {
  45842. fileList->setIgnoresHiddenFiles (! fileList->ignoresHiddenFiles());
  45843. fileList->refresh();
  45844. return true;
  45845. }
  45846. #endif
  45847. return false;
  45848. }
  45849. void FileBrowserComponent::textEditorTextChanged (TextEditor&)
  45850. {
  45851. sendListenerChangeMessage();
  45852. }
  45853. void FileBrowserComponent::textEditorReturnKeyPressed (TextEditor&)
  45854. {
  45855. if (filenameBox->getText().containsChar (File::separator))
  45856. {
  45857. const File f (currentRoot.getChildFile (filenameBox->getText()));
  45858. if (f.isDirectory())
  45859. {
  45860. setRoot (f);
  45861. chosenFiles.clear();
  45862. filenameBox->setText (String::empty);
  45863. }
  45864. else
  45865. {
  45866. setRoot (f.getParentDirectory());
  45867. chosenFiles.clear();
  45868. chosenFiles.add (f);
  45869. filenameBox->setText (f.getFileName());
  45870. }
  45871. }
  45872. else
  45873. {
  45874. fileDoubleClicked (getSelectedFile (0));
  45875. }
  45876. }
  45877. void FileBrowserComponent::textEditorEscapeKeyPressed (TextEditor&)
  45878. {
  45879. }
  45880. void FileBrowserComponent::textEditorFocusLost (TextEditor&)
  45881. {
  45882. if (! isSaveMode())
  45883. selectionChanged();
  45884. }
  45885. void FileBrowserComponent::buttonClicked (Button*)
  45886. {
  45887. goUp();
  45888. }
  45889. void FileBrowserComponent::comboBoxChanged (ComboBox*)
  45890. {
  45891. const String newText (currentPathBox->getText().trim().unquoted());
  45892. if (newText.isNotEmpty())
  45893. {
  45894. const int index = currentPathBox->getSelectedId() - 1;
  45895. StringArray rootNames, rootPaths;
  45896. getRoots (rootNames, rootPaths);
  45897. if (rootPaths [index].isNotEmpty())
  45898. {
  45899. setRoot (File (rootPaths [index]));
  45900. }
  45901. else
  45902. {
  45903. File f (newText);
  45904. for (;;)
  45905. {
  45906. if (f.isDirectory())
  45907. {
  45908. setRoot (f);
  45909. break;
  45910. }
  45911. if (f.getParentDirectory() == f)
  45912. break;
  45913. f = f.getParentDirectory();
  45914. }
  45915. }
  45916. }
  45917. }
  45918. const BigInteger FileBrowserComponent::getRoots (StringArray& rootNames, StringArray& rootPaths)
  45919. {
  45920. BigInteger separators;
  45921. #if JUCE_WINDOWS
  45922. Array<File> roots;
  45923. File::findFileSystemRoots (roots);
  45924. rootPaths.clear();
  45925. for (int i = 0; i < roots.size(); ++i)
  45926. {
  45927. const File& drive = roots.getReference(i);
  45928. String name (drive.getFullPathName());
  45929. rootPaths.add (name);
  45930. if (drive.isOnHardDisk())
  45931. {
  45932. String volume (drive.getVolumeLabel());
  45933. if (volume.isEmpty())
  45934. volume = TRANS("Hard Drive");
  45935. name << " [" << drive.getVolumeLabel() << ']';
  45936. }
  45937. else if (drive.isOnCDRomDrive())
  45938. {
  45939. name << TRANS(" [CD/DVD drive]");
  45940. }
  45941. rootNames.add (name);
  45942. }
  45943. separators.setBit (rootPaths.size());
  45944. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  45945. rootNames.add ("Documents");
  45946. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  45947. rootNames.add ("Desktop");
  45948. #endif
  45949. #if JUCE_MAC
  45950. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  45951. rootNames.add ("Home folder");
  45952. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  45953. rootNames.add ("Documents");
  45954. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  45955. rootNames.add ("Desktop");
  45956. separators.setBit (rootPaths.size());
  45957. Array <File> volumes;
  45958. File vol ("/Volumes");
  45959. vol.findChildFiles (volumes, File::findDirectories, false);
  45960. for (int i = 0; i < volumes.size(); ++i)
  45961. {
  45962. const File& volume = volumes.getReference(i);
  45963. if (volume.isDirectory() && ! volume.getFileName().startsWithChar ('.'))
  45964. {
  45965. rootPaths.add (volume.getFullPathName());
  45966. rootNames.add (volume.getFileName());
  45967. }
  45968. }
  45969. #endif
  45970. #if JUCE_LINUX
  45971. rootPaths.add ("/");
  45972. rootNames.add ("/");
  45973. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  45974. rootNames.add ("Home folder");
  45975. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  45976. rootNames.add ("Desktop");
  45977. #endif
  45978. return separators;
  45979. }
  45980. END_JUCE_NAMESPACE
  45981. /*** End of inlined file: juce_FileBrowserComponent.cpp ***/
  45982. /*** Start of inlined file: juce_FileChooser.cpp ***/
  45983. BEGIN_JUCE_NAMESPACE
  45984. FileChooser::FileChooser (const String& chooserBoxTitle,
  45985. const File& currentFileOrDirectory,
  45986. const String& fileFilters,
  45987. const bool useNativeDialogBox_)
  45988. : title (chooserBoxTitle),
  45989. filters (fileFilters),
  45990. startingFile (currentFileOrDirectory),
  45991. useNativeDialogBox (useNativeDialogBox_)
  45992. {
  45993. #if JUCE_LINUX
  45994. useNativeDialogBox = false;
  45995. #endif
  45996. if (! fileFilters.containsNonWhitespaceChars())
  45997. filters = "*";
  45998. }
  45999. FileChooser::~FileChooser()
  46000. {
  46001. }
  46002. bool FileChooser::browseForFileToOpen (FilePreviewComponent* previewComponent)
  46003. {
  46004. return showDialog (false, true, false, false, false, previewComponent);
  46005. }
  46006. bool FileChooser::browseForMultipleFilesToOpen (FilePreviewComponent* previewComponent)
  46007. {
  46008. return showDialog (false, true, false, false, true, previewComponent);
  46009. }
  46010. bool FileChooser::browseForMultipleFilesOrDirectories (FilePreviewComponent* previewComponent)
  46011. {
  46012. return showDialog (true, true, false, false, true, previewComponent);
  46013. }
  46014. bool FileChooser::browseForFileToSave (const bool warnAboutOverwritingExistingFiles)
  46015. {
  46016. return showDialog (false, true, true, warnAboutOverwritingExistingFiles, false, 0);
  46017. }
  46018. bool FileChooser::browseForDirectory()
  46019. {
  46020. return showDialog (true, false, false, false, false, 0);
  46021. }
  46022. const File FileChooser::getResult() const
  46023. {
  46024. // if you've used a multiple-file select, you should use the getResults() method
  46025. // to retrieve all the files that were chosen.
  46026. jassert (results.size() <= 1);
  46027. return results.getFirst();
  46028. }
  46029. const Array<File>& FileChooser::getResults() const
  46030. {
  46031. return results;
  46032. }
  46033. bool FileChooser::showDialog (const bool selectsDirectories,
  46034. const bool selectsFiles,
  46035. const bool isSave,
  46036. const bool warnAboutOverwritingExistingFiles,
  46037. const bool selectMultipleFiles,
  46038. FilePreviewComponent* const previewComponent)
  46039. {
  46040. Component::SafePointer<Component> previouslyFocused (Component::getCurrentlyFocusedComponent());
  46041. results.clear();
  46042. // the preview component needs to be the right size before you pass it in here..
  46043. jassert (previewComponent == 0 || (previewComponent->getWidth() > 10
  46044. && previewComponent->getHeight() > 10));
  46045. #if JUCE_WINDOWS
  46046. if (useNativeDialogBox && ! (selectsFiles && selectsDirectories))
  46047. #elif JUCE_MAC
  46048. if (useNativeDialogBox && (previewComponent == 0))
  46049. #else
  46050. if (false)
  46051. #endif
  46052. {
  46053. showPlatformDialog (results, title, startingFile, filters,
  46054. selectsDirectories, selectsFiles, isSave,
  46055. warnAboutOverwritingExistingFiles,
  46056. selectMultipleFiles,
  46057. previewComponent);
  46058. }
  46059. else
  46060. {
  46061. WildcardFileFilter wildcard (selectsFiles ? filters : String::empty,
  46062. selectsDirectories ? "*" : String::empty,
  46063. String::empty);
  46064. int flags = isSave ? FileBrowserComponent::saveMode
  46065. : FileBrowserComponent::openMode;
  46066. if (selectsFiles)
  46067. flags |= FileBrowserComponent::canSelectFiles;
  46068. if (selectsDirectories)
  46069. flags |= FileBrowserComponent::canSelectDirectories;
  46070. if (selectMultipleFiles)
  46071. flags |= FileBrowserComponent::canSelectMultipleItems;
  46072. FileBrowserComponent browserComponent (flags, startingFile, &wildcard, previewComponent);
  46073. FileChooserDialogBox box (title, String::empty,
  46074. browserComponent,
  46075. warnAboutOverwritingExistingFiles,
  46076. browserComponent.findColour (AlertWindow::backgroundColourId));
  46077. if (box.show())
  46078. {
  46079. for (int i = 0; i < browserComponent.getNumSelectedFiles(); ++i)
  46080. results.add (browserComponent.getSelectedFile (i));
  46081. }
  46082. }
  46083. if (previouslyFocused != 0)
  46084. previouslyFocused->grabKeyboardFocus();
  46085. return results.size() > 0;
  46086. }
  46087. FilePreviewComponent::FilePreviewComponent()
  46088. {
  46089. }
  46090. FilePreviewComponent::~FilePreviewComponent()
  46091. {
  46092. }
  46093. END_JUCE_NAMESPACE
  46094. /*** End of inlined file: juce_FileChooser.cpp ***/
  46095. /*** Start of inlined file: juce_FileChooserDialogBox.cpp ***/
  46096. BEGIN_JUCE_NAMESPACE
  46097. FileChooserDialogBox::FileChooserDialogBox (const String& name,
  46098. const String& instructions,
  46099. FileBrowserComponent& chooserComponent,
  46100. const bool warnAboutOverwritingExistingFiles_,
  46101. const Colour& backgroundColour)
  46102. : ResizableWindow (name, backgroundColour, true),
  46103. warnAboutOverwritingExistingFiles (warnAboutOverwritingExistingFiles_)
  46104. {
  46105. content = new ContentComponent();
  46106. content->setName (name);
  46107. content->instructions = instructions;
  46108. content->chooserComponent = &chooserComponent;
  46109. content->addAndMakeVisible (&chooserComponent);
  46110. content->okButton = new TextButton (chooserComponent.getActionVerb());
  46111. content->addAndMakeVisible (content->okButton);
  46112. content->okButton->addButtonListener (this);
  46113. content->okButton->setEnabled (chooserComponent.currentFileIsValid());
  46114. content->okButton->addShortcut (KeyPress (KeyPress::returnKey, 0, 0));
  46115. content->cancelButton = new TextButton (TRANS("Cancel"));
  46116. content->addAndMakeVisible (content->cancelButton);
  46117. content->cancelButton->addButtonListener (this);
  46118. content->cancelButton->addShortcut (KeyPress (KeyPress::escapeKey, 0, 0));
  46119. setContentComponent (content);
  46120. setResizable (true, true);
  46121. setResizeLimits (300, 300, 1200, 1000);
  46122. content->chooserComponent->addListener (this);
  46123. }
  46124. FileChooserDialogBox::~FileChooserDialogBox()
  46125. {
  46126. content->chooserComponent->removeListener (this);
  46127. }
  46128. bool FileChooserDialogBox::show (int w, int h)
  46129. {
  46130. if (w <= 0)
  46131. {
  46132. Component* const previewComp = content->chooserComponent->getPreviewComponent();
  46133. if (previewComp != 0)
  46134. w = 400 + previewComp->getWidth();
  46135. else
  46136. w = 600;
  46137. }
  46138. if (h <= 0)
  46139. h = 500;
  46140. centreWithSize (w, h);
  46141. const bool ok = (runModalLoop() != 0);
  46142. setVisible (false);
  46143. return ok;
  46144. }
  46145. void FileChooserDialogBox::buttonClicked (Button* button)
  46146. {
  46147. if (button == content->okButton)
  46148. {
  46149. if (warnAboutOverwritingExistingFiles
  46150. && content->chooserComponent->isSaveMode()
  46151. && content->chooserComponent->getSelectedFile(0).exists())
  46152. {
  46153. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  46154. TRANS("File already exists"),
  46155. TRANS("There's already a file called:")
  46156. + "\n\n" + content->chooserComponent->getSelectedFile(0).getFullPathName()
  46157. + "\n\n" + TRANS("Are you sure you want to overwrite it?"),
  46158. TRANS("overwrite"),
  46159. TRANS("cancel")))
  46160. {
  46161. return;
  46162. }
  46163. }
  46164. exitModalState (1);
  46165. }
  46166. else if (button == content->cancelButton)
  46167. closeButtonPressed();
  46168. }
  46169. void FileChooserDialogBox::closeButtonPressed()
  46170. {
  46171. setVisible (false);
  46172. }
  46173. void FileChooserDialogBox::selectionChanged()
  46174. {
  46175. content->okButton->setEnabled (content->chooserComponent->currentFileIsValid());
  46176. }
  46177. void FileChooserDialogBox::fileClicked (const File&, const MouseEvent&)
  46178. {
  46179. }
  46180. void FileChooserDialogBox::fileDoubleClicked (const File&)
  46181. {
  46182. selectionChanged();
  46183. content->okButton->triggerClick();
  46184. }
  46185. FileChooserDialogBox::ContentComponent::ContentComponent()
  46186. {
  46187. setInterceptsMouseClicks (false, true);
  46188. }
  46189. FileChooserDialogBox::ContentComponent::~ContentComponent()
  46190. {
  46191. delete okButton;
  46192. delete cancelButton;
  46193. }
  46194. void FileChooserDialogBox::ContentComponent::paint (Graphics& g)
  46195. {
  46196. g.setColour (getLookAndFeel().findColour (FileChooserDialogBox::titleTextColourId));
  46197. text.draw (g);
  46198. }
  46199. void FileChooserDialogBox::ContentComponent::resized()
  46200. {
  46201. getLookAndFeel().createFileChooserHeaderText (getName(), instructions, text, getWidth());
  46202. float left, top, right, bottom;
  46203. text.getBoundingBox (0, text.getNumGlyphs(), left, top, right, bottom, false);
  46204. const int y = roundToInt (bottom) + 10;
  46205. const int buttonHeight = 26;
  46206. const int buttonY = getHeight() - buttonHeight - 8;
  46207. chooserComponent->setBounds (0, y, getWidth(), buttonY - y - 20);
  46208. okButton->setBounds (proportionOfWidth (0.25f), buttonY,
  46209. proportionOfWidth (0.2f), buttonHeight);
  46210. cancelButton->setBounds (proportionOfWidth (0.55f), buttonY,
  46211. proportionOfWidth (0.2f), buttonHeight);
  46212. }
  46213. END_JUCE_NAMESPACE
  46214. /*** End of inlined file: juce_FileChooserDialogBox.cpp ***/
  46215. /*** Start of inlined file: juce_FileFilter.cpp ***/
  46216. BEGIN_JUCE_NAMESPACE
  46217. FileFilter::FileFilter (const String& filterDescription)
  46218. : description (filterDescription)
  46219. {
  46220. }
  46221. FileFilter::~FileFilter()
  46222. {
  46223. }
  46224. const String& FileFilter::getDescription() const throw()
  46225. {
  46226. return description;
  46227. }
  46228. END_JUCE_NAMESPACE
  46229. /*** End of inlined file: juce_FileFilter.cpp ***/
  46230. /*** Start of inlined file: juce_FileListComponent.cpp ***/
  46231. BEGIN_JUCE_NAMESPACE
  46232. Image* juce_createIconForFile (const File& file);
  46233. FileListComponent::FileListComponent (DirectoryContentsList& listToShow)
  46234. : ListBox (String::empty, 0),
  46235. DirectoryContentsDisplayComponent (listToShow)
  46236. {
  46237. setModel (this);
  46238. fileList.addChangeListener (this);
  46239. }
  46240. FileListComponent::~FileListComponent()
  46241. {
  46242. fileList.removeChangeListener (this);
  46243. deleteAllChildren();
  46244. }
  46245. int FileListComponent::getNumSelectedFiles() const
  46246. {
  46247. return getNumSelectedRows();
  46248. }
  46249. const File FileListComponent::getSelectedFile (int index) const
  46250. {
  46251. return fileList.getFile (getSelectedRow (index));
  46252. }
  46253. void FileListComponent::scrollToTop()
  46254. {
  46255. getVerticalScrollBar()->setCurrentRangeStart (0);
  46256. }
  46257. void FileListComponent::changeListenerCallback (void*)
  46258. {
  46259. updateContent();
  46260. if (lastDirectory != fileList.getDirectory())
  46261. {
  46262. lastDirectory = fileList.getDirectory();
  46263. deselectAllRows();
  46264. }
  46265. }
  46266. class FileListItemComponent : public Component,
  46267. public TimeSliceClient,
  46268. public AsyncUpdater
  46269. {
  46270. public:
  46271. FileListItemComponent (FileListComponent& owner_,
  46272. TimeSliceThread& thread_) throw()
  46273. : owner (owner_),
  46274. thread (thread_),
  46275. icon (0)
  46276. {
  46277. }
  46278. ~FileListItemComponent() throw()
  46279. {
  46280. thread.removeTimeSliceClient (this);
  46281. clearIcon();
  46282. }
  46283. void paint (Graphics& g)
  46284. {
  46285. getLookAndFeel().drawFileBrowserRow (g, getWidth(), getHeight(),
  46286. file.getFileName(),
  46287. icon,
  46288. fileSize, modTime,
  46289. isDirectory, highlighted,
  46290. index);
  46291. }
  46292. void mouseDown (const MouseEvent& e)
  46293. {
  46294. owner.selectRowsBasedOnModifierKeys (index, e.mods);
  46295. owner.sendMouseClickMessage (file, e);
  46296. }
  46297. void mouseDoubleClick (const MouseEvent&)
  46298. {
  46299. owner.sendDoubleClickMessage (file);
  46300. }
  46301. void update (const File& root,
  46302. const DirectoryContentsList::FileInfo* const fileInfo,
  46303. const int index_,
  46304. const bool highlighted_) throw()
  46305. {
  46306. thread.removeTimeSliceClient (this);
  46307. if (highlighted_ != highlighted
  46308. || index_ != index)
  46309. {
  46310. index = index_;
  46311. highlighted = highlighted_;
  46312. repaint();
  46313. }
  46314. File newFile;
  46315. String newFileSize;
  46316. String newModTime;
  46317. if (fileInfo != 0)
  46318. {
  46319. newFile = root.getChildFile (fileInfo->filename);
  46320. newFileSize = File::descriptionOfSizeInBytes (fileInfo->fileSize);
  46321. newModTime = fileInfo->modificationTime.formatted (T("%d %b '%y %H:%M"));
  46322. }
  46323. if (newFile != file
  46324. || fileSize != newFileSize
  46325. || modTime != newModTime)
  46326. {
  46327. file = newFile;
  46328. fileSize = newFileSize;
  46329. modTime = newModTime;
  46330. isDirectory = fileInfo != 0 && fileInfo->isDirectory;
  46331. repaint();
  46332. clearIcon();
  46333. }
  46334. if (file != File::nonexistent
  46335. && icon == 0 && ! isDirectory)
  46336. {
  46337. updateIcon (true);
  46338. if (icon == 0)
  46339. thread.addTimeSliceClient (this);
  46340. }
  46341. }
  46342. bool useTimeSlice()
  46343. {
  46344. updateIcon (false);
  46345. return false;
  46346. }
  46347. void handleAsyncUpdate()
  46348. {
  46349. repaint();
  46350. }
  46351. juce_UseDebuggingNewOperator
  46352. private:
  46353. FileListComponent& owner;
  46354. TimeSliceThread& thread;
  46355. bool highlighted;
  46356. int index;
  46357. File file;
  46358. String fileSize;
  46359. String modTime;
  46360. Image* icon;
  46361. bool isDirectory;
  46362. void clearIcon() throw()
  46363. {
  46364. ImageCache::release (icon);
  46365. icon = 0;
  46366. }
  46367. void updateIcon (const bool onlyUpdateIfCached) throw()
  46368. {
  46369. if (icon == 0)
  46370. {
  46371. const int hashCode = (file.getFullPathName() + "_iconCacheSalt").hashCode();
  46372. Image* im = ImageCache::getFromHashCode (hashCode);
  46373. if (im == 0 && ! onlyUpdateIfCached)
  46374. {
  46375. im = juce_createIconForFile (file);
  46376. if (im != 0)
  46377. ImageCache::addImageToCache (im, hashCode);
  46378. }
  46379. if (im != 0)
  46380. {
  46381. icon = im;
  46382. triggerAsyncUpdate();
  46383. }
  46384. }
  46385. }
  46386. };
  46387. int FileListComponent::getNumRows()
  46388. {
  46389. return fileList.getNumFiles();
  46390. }
  46391. void FileListComponent::paintListBoxItem (int, Graphics&, int, int, bool)
  46392. {
  46393. }
  46394. Component* FileListComponent::refreshComponentForRow (int row, bool isSelected, Component* existingComponentToUpdate)
  46395. {
  46396. FileListItemComponent* comp = dynamic_cast <FileListItemComponent*> (existingComponentToUpdate);
  46397. if (comp == 0)
  46398. {
  46399. delete existingComponentToUpdate;
  46400. comp = new FileListItemComponent (*this, fileList.getTimeSliceThread());
  46401. }
  46402. DirectoryContentsList::FileInfo fileInfo;
  46403. if (fileList.getFileInfo (row, fileInfo))
  46404. comp->update (fileList.getDirectory(), &fileInfo, row, isSelected);
  46405. else
  46406. comp->update (fileList.getDirectory(), 0, row, isSelected);
  46407. return comp;
  46408. }
  46409. void FileListComponent::selectedRowsChanged (int /*lastRowSelected*/)
  46410. {
  46411. sendSelectionChangeMessage();
  46412. }
  46413. void FileListComponent::deleteKeyPressed (int /*currentSelectedRow*/)
  46414. {
  46415. }
  46416. void FileListComponent::returnKeyPressed (int currentSelectedRow)
  46417. {
  46418. sendDoubleClickMessage (fileList.getFile (currentSelectedRow));
  46419. }
  46420. END_JUCE_NAMESPACE
  46421. /*** End of inlined file: juce_FileListComponent.cpp ***/
  46422. /*** Start of inlined file: juce_FilenameComponent.cpp ***/
  46423. BEGIN_JUCE_NAMESPACE
  46424. FilenameComponent::FilenameComponent (const String& name,
  46425. const File& currentFile,
  46426. const bool canEditFilename,
  46427. const bool isDirectory,
  46428. const bool isForSaving,
  46429. const String& fileBrowserWildcard,
  46430. const String& enforcedSuffix_,
  46431. const String& textWhenNothingSelected)
  46432. : Component (name),
  46433. maxRecentFiles (30),
  46434. isDir (isDirectory),
  46435. isSaving (isForSaving),
  46436. isFileDragOver (false),
  46437. wildcard (fileBrowserWildcard),
  46438. enforcedSuffix (enforcedSuffix_)
  46439. {
  46440. addAndMakeVisible (filenameBox = new ComboBox ("fn"));
  46441. filenameBox->setEditableText (canEditFilename);
  46442. filenameBox->addListener (this);
  46443. filenameBox->setTextWhenNothingSelected (textWhenNothingSelected);
  46444. filenameBox->setTextWhenNoChoicesAvailable (TRANS("(no recently seleced files)"));
  46445. browseButton = 0;
  46446. setBrowseButtonText ("...");
  46447. setCurrentFile (currentFile, true);
  46448. }
  46449. FilenameComponent::~FilenameComponent()
  46450. {
  46451. deleteAllChildren();
  46452. }
  46453. void FilenameComponent::paintOverChildren (Graphics& g)
  46454. {
  46455. if (isFileDragOver)
  46456. {
  46457. g.setColour (Colours::red.withAlpha (0.2f));
  46458. g.drawRect (0, 0, getWidth(), getHeight(), 3);
  46459. }
  46460. }
  46461. void FilenameComponent::resized()
  46462. {
  46463. getLookAndFeel().layoutFilenameComponent (*this, filenameBox, browseButton);
  46464. }
  46465. void FilenameComponent::setBrowseButtonText (const String& newBrowseButtonText)
  46466. {
  46467. browseButtonText = newBrowseButtonText;
  46468. lookAndFeelChanged();
  46469. }
  46470. void FilenameComponent::lookAndFeelChanged()
  46471. {
  46472. deleteAndZero (browseButton);
  46473. addAndMakeVisible (browseButton = getLookAndFeel().createFilenameComponentBrowseButton (browseButtonText));
  46474. browseButton->setConnectedEdges (Button::ConnectedOnLeft);
  46475. resized();
  46476. browseButton->addButtonListener (this);
  46477. }
  46478. void FilenameComponent::setTooltip (const String& newTooltip)
  46479. {
  46480. SettableTooltipClient::setTooltip (newTooltip);
  46481. filenameBox->setTooltip (newTooltip);
  46482. }
  46483. void FilenameComponent::setDefaultBrowseTarget (const File& newDefaultDirectory) throw()
  46484. {
  46485. defaultBrowseFile = newDefaultDirectory;
  46486. }
  46487. void FilenameComponent::buttonClicked (Button*)
  46488. {
  46489. FileChooser fc (TRANS("Choose a new file"),
  46490. getCurrentFile() == File::nonexistent ? defaultBrowseFile
  46491. : getCurrentFile(),
  46492. wildcard);
  46493. if (isDir ? fc.browseForDirectory()
  46494. : (isSaving ? fc.browseForFileToSave (false)
  46495. : fc.browseForFileToOpen()))
  46496. {
  46497. setCurrentFile (fc.getResult(), true);
  46498. }
  46499. }
  46500. void FilenameComponent::comboBoxChanged (ComboBox*)
  46501. {
  46502. setCurrentFile (getCurrentFile(), true);
  46503. }
  46504. bool FilenameComponent::isInterestedInFileDrag (const StringArray&)
  46505. {
  46506. return true;
  46507. }
  46508. void FilenameComponent::filesDropped (const StringArray& filenames, int, int)
  46509. {
  46510. isFileDragOver = false;
  46511. repaint();
  46512. const File f (filenames[0]);
  46513. if (f.exists() && (f.isDirectory() == isDir))
  46514. setCurrentFile (f, true);
  46515. }
  46516. void FilenameComponent::fileDragEnter (const StringArray&, int, int)
  46517. {
  46518. isFileDragOver = true;
  46519. repaint();
  46520. }
  46521. void FilenameComponent::fileDragExit (const StringArray&)
  46522. {
  46523. isFileDragOver = false;
  46524. repaint();
  46525. }
  46526. const File FilenameComponent::getCurrentFile() const
  46527. {
  46528. File f (filenameBox->getText());
  46529. if (enforcedSuffix.isNotEmpty())
  46530. f = f.withFileExtension (enforcedSuffix);
  46531. return f;
  46532. }
  46533. void FilenameComponent::setCurrentFile (File newFile,
  46534. const bool addToRecentlyUsedList,
  46535. const bool sendChangeNotification)
  46536. {
  46537. if (enforcedSuffix.isNotEmpty())
  46538. newFile = newFile.withFileExtension (enforcedSuffix);
  46539. if (newFile.getFullPathName() != lastFilename)
  46540. {
  46541. lastFilename = newFile.getFullPathName();
  46542. if (addToRecentlyUsedList)
  46543. addRecentlyUsedFile (newFile);
  46544. filenameBox->setText (lastFilename, true);
  46545. if (sendChangeNotification)
  46546. triggerAsyncUpdate();
  46547. }
  46548. }
  46549. void FilenameComponent::setFilenameIsEditable (const bool shouldBeEditable)
  46550. {
  46551. filenameBox->setEditableText (shouldBeEditable);
  46552. }
  46553. const StringArray FilenameComponent::getRecentlyUsedFilenames() const
  46554. {
  46555. StringArray names;
  46556. for (int i = 0; i < filenameBox->getNumItems(); ++i)
  46557. names.add (filenameBox->getItemText (i));
  46558. return names;
  46559. }
  46560. void FilenameComponent::setRecentlyUsedFilenames (const StringArray& filenames)
  46561. {
  46562. if (filenames != getRecentlyUsedFilenames())
  46563. {
  46564. filenameBox->clear();
  46565. for (int i = 0; i < jmin (filenames.size(), maxRecentFiles); ++i)
  46566. filenameBox->addItem (filenames[i], i + 1);
  46567. }
  46568. }
  46569. void FilenameComponent::setMaxNumberOfRecentFiles (const int newMaximum)
  46570. {
  46571. maxRecentFiles = jmax (1, newMaximum);
  46572. setRecentlyUsedFilenames (getRecentlyUsedFilenames());
  46573. }
  46574. void FilenameComponent::addRecentlyUsedFile (const File& file)
  46575. {
  46576. StringArray files (getRecentlyUsedFilenames());
  46577. if (file.getFullPathName().isNotEmpty())
  46578. {
  46579. files.removeString (file.getFullPathName(), true);
  46580. files.insert (0, file.getFullPathName());
  46581. setRecentlyUsedFilenames (files);
  46582. }
  46583. }
  46584. void FilenameComponent::addListener (FilenameComponentListener* const listener) throw()
  46585. {
  46586. listeners.add (listener);
  46587. }
  46588. void FilenameComponent::removeListener (FilenameComponentListener* const listener) throw()
  46589. {
  46590. listeners.remove (listener);
  46591. }
  46592. void FilenameComponent::handleAsyncUpdate()
  46593. {
  46594. Component::BailOutChecker checker (this);
  46595. listeners.callChecked (checker, &FilenameComponentListener::filenameComponentChanged, this);
  46596. }
  46597. END_JUCE_NAMESPACE
  46598. /*** End of inlined file: juce_FilenameComponent.cpp ***/
  46599. /*** Start of inlined file: juce_FileSearchPathListComponent.cpp ***/
  46600. BEGIN_JUCE_NAMESPACE
  46601. FileSearchPathListComponent::FileSearchPathListComponent()
  46602. {
  46603. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  46604. listBox->setColour (ListBox::backgroundColourId, Colours::black.withAlpha (0.02f));
  46605. listBox->setColour (ListBox::outlineColourId, Colours::black.withAlpha (0.1f));
  46606. listBox->setOutlineThickness (1);
  46607. addAndMakeVisible (addButton = new TextButton ("+"));
  46608. addButton->addButtonListener (this);
  46609. addButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  46610. addAndMakeVisible (removeButton = new TextButton ("-"));
  46611. removeButton->addButtonListener (this);
  46612. removeButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  46613. addAndMakeVisible (changeButton = new TextButton (TRANS("change...")));
  46614. changeButton->addButtonListener (this);
  46615. addAndMakeVisible (upButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  46616. upButton->addButtonListener (this);
  46617. {
  46618. Path arrowPath;
  46619. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  46620. DrawablePath arrowImage;
  46621. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  46622. arrowImage.setPath (arrowPath);
  46623. ((DrawableButton*) upButton)->setImages (&arrowImage);
  46624. }
  46625. addAndMakeVisible (downButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  46626. downButton->addButtonListener (this);
  46627. {
  46628. Path arrowPath;
  46629. arrowPath.addArrow (50.0f, 0.0f, 50.0f, 100.0f, 40.0f, 100.0f, 50.0f);
  46630. DrawablePath arrowImage;
  46631. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  46632. arrowImage.setPath (arrowPath);
  46633. ((DrawableButton*) downButton)->setImages (&arrowImage);
  46634. }
  46635. updateButtons();
  46636. }
  46637. FileSearchPathListComponent::~FileSearchPathListComponent()
  46638. {
  46639. deleteAllChildren();
  46640. }
  46641. void FileSearchPathListComponent::updateButtons() throw()
  46642. {
  46643. const bool anythingSelected = listBox->getNumSelectedRows() > 0;
  46644. removeButton->setEnabled (anythingSelected);
  46645. changeButton->setEnabled (anythingSelected);
  46646. upButton->setEnabled (anythingSelected);
  46647. downButton->setEnabled (anythingSelected);
  46648. }
  46649. void FileSearchPathListComponent::changed() throw()
  46650. {
  46651. listBox->updateContent();
  46652. listBox->repaint();
  46653. updateButtons();
  46654. }
  46655. void FileSearchPathListComponent::setPath (const FileSearchPath& newPath)
  46656. {
  46657. if (newPath.toString() != path.toString())
  46658. {
  46659. path = newPath;
  46660. changed();
  46661. }
  46662. }
  46663. void FileSearchPathListComponent::setDefaultBrowseTarget (const File& newDefaultDirectory) throw()
  46664. {
  46665. defaultBrowseTarget = newDefaultDirectory;
  46666. }
  46667. int FileSearchPathListComponent::getNumRows()
  46668. {
  46669. return path.getNumPaths();
  46670. }
  46671. void FileSearchPathListComponent::paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool rowIsSelected)
  46672. {
  46673. if (rowIsSelected)
  46674. g.fillAll (findColour (TextEditor::highlightColourId));
  46675. g.setColour (findColour (ListBox::textColourId));
  46676. Font f (height * 0.7f);
  46677. f.setHorizontalScale (0.9f);
  46678. g.setFont (f);
  46679. g.drawText (path [rowNumber].getFullPathName(),
  46680. 4, 0, width - 6, height,
  46681. Justification::centredLeft, true);
  46682. }
  46683. void FileSearchPathListComponent::deleteKeyPressed (int row)
  46684. {
  46685. if (((unsigned int) row) < (unsigned int) path.getNumPaths())
  46686. {
  46687. path.remove (row);
  46688. changed();
  46689. }
  46690. }
  46691. void FileSearchPathListComponent::returnKeyPressed (int row)
  46692. {
  46693. FileChooser chooser (TRANS("Change folder..."), path [row], "*");
  46694. if (chooser.browseForDirectory())
  46695. {
  46696. path.remove (row);
  46697. path.add (chooser.getResult(), row);
  46698. changed();
  46699. }
  46700. }
  46701. void FileSearchPathListComponent::listBoxItemDoubleClicked (int row, const MouseEvent&)
  46702. {
  46703. returnKeyPressed (row);
  46704. }
  46705. void FileSearchPathListComponent::selectedRowsChanged (int)
  46706. {
  46707. updateButtons();
  46708. }
  46709. void FileSearchPathListComponent::paint (Graphics& g)
  46710. {
  46711. g.fillAll (findColour (backgroundColourId));
  46712. }
  46713. void FileSearchPathListComponent::resized()
  46714. {
  46715. const int buttonH = 22;
  46716. const int buttonY = getHeight() - buttonH - 4;
  46717. listBox->setBounds (2, 2, getWidth() - 4, buttonY - 5);
  46718. addButton->setBounds (2, buttonY, buttonH, buttonH);
  46719. removeButton->setBounds (addButton->getRight(), buttonY, buttonH, buttonH);
  46720. ((TextButton*) changeButton)->changeWidthToFitText (buttonH);
  46721. downButton->setSize (buttonH * 2, buttonH);
  46722. upButton->setSize (buttonH * 2, buttonH);
  46723. downButton->setTopRightPosition (getWidth() - 2, buttonY);
  46724. upButton->setTopRightPosition (downButton->getX() - 4, buttonY);
  46725. changeButton->setTopRightPosition (upButton->getX() - 8, buttonY);
  46726. }
  46727. bool FileSearchPathListComponent::isInterestedInFileDrag (const StringArray&)
  46728. {
  46729. return true;
  46730. }
  46731. void FileSearchPathListComponent::filesDropped (const StringArray& filenames, int, int mouseY)
  46732. {
  46733. for (int i = filenames.size(); --i >= 0;)
  46734. {
  46735. const File f (filenames[i]);
  46736. if (f.isDirectory())
  46737. {
  46738. const int row = listBox->getRowContainingPosition (0, mouseY - listBox->getY());
  46739. path.add (f, row);
  46740. changed();
  46741. }
  46742. }
  46743. }
  46744. void FileSearchPathListComponent::buttonClicked (Button* button)
  46745. {
  46746. const int currentRow = listBox->getSelectedRow();
  46747. if (button == removeButton)
  46748. {
  46749. deleteKeyPressed (currentRow);
  46750. }
  46751. else if (button == addButton)
  46752. {
  46753. File start (defaultBrowseTarget);
  46754. if (start == File::nonexistent)
  46755. start = path [0];
  46756. if (start == File::nonexistent)
  46757. start = File::getCurrentWorkingDirectory();
  46758. FileChooser chooser (TRANS("Add a folder..."), start, "*");
  46759. if (chooser.browseForDirectory())
  46760. {
  46761. path.add (chooser.getResult(), currentRow);
  46762. }
  46763. }
  46764. else if (button == changeButton)
  46765. {
  46766. returnKeyPressed (currentRow);
  46767. }
  46768. else if (button == upButton)
  46769. {
  46770. if (currentRow > 0 && currentRow < path.getNumPaths())
  46771. {
  46772. const File f (path[currentRow]);
  46773. path.remove (currentRow);
  46774. path.add (f, currentRow - 1);
  46775. listBox->selectRow (currentRow - 1);
  46776. }
  46777. }
  46778. else if (button == downButton)
  46779. {
  46780. if (currentRow >= 0 && currentRow < path.getNumPaths() - 1)
  46781. {
  46782. const File f (path[currentRow]);
  46783. path.remove (currentRow);
  46784. path.add (f, currentRow + 1);
  46785. listBox->selectRow (currentRow + 1);
  46786. }
  46787. }
  46788. changed();
  46789. }
  46790. END_JUCE_NAMESPACE
  46791. /*** End of inlined file: juce_FileSearchPathListComponent.cpp ***/
  46792. /*** Start of inlined file: juce_FileTreeComponent.cpp ***/
  46793. BEGIN_JUCE_NAMESPACE
  46794. Image* juce_createIconForFile (const File& file);
  46795. class FileListTreeItem : public TreeViewItem,
  46796. public TimeSliceClient,
  46797. public AsyncUpdater,
  46798. public ChangeListener
  46799. {
  46800. public:
  46801. FileListTreeItem (FileTreeComponent& owner_,
  46802. DirectoryContentsList* const parentContentsList_,
  46803. const int indexInContentsList_,
  46804. const File& file_,
  46805. TimeSliceThread& thread_) throw()
  46806. : file (file_),
  46807. owner (owner_),
  46808. parentContentsList (parentContentsList_),
  46809. indexInContentsList (indexInContentsList_),
  46810. subContentsList (0),
  46811. canDeleteSubContentsList (false),
  46812. thread (thread_),
  46813. icon (0)
  46814. {
  46815. DirectoryContentsList::FileInfo fileInfo;
  46816. if (parentContentsList_ != 0
  46817. && parentContentsList_->getFileInfo (indexInContentsList_, fileInfo))
  46818. {
  46819. fileSize = File::descriptionOfSizeInBytes (fileInfo.fileSize);
  46820. modTime = fileInfo.modificationTime.formatted (T("%d %b '%y %H:%M"));
  46821. isDirectory = fileInfo.isDirectory;
  46822. }
  46823. else
  46824. {
  46825. isDirectory = true;
  46826. }
  46827. }
  46828. ~FileListTreeItem() throw()
  46829. {
  46830. thread.removeTimeSliceClient (this);
  46831. clearSubItems();
  46832. ImageCache::release (icon);
  46833. if (canDeleteSubContentsList)
  46834. delete subContentsList;
  46835. }
  46836. bool mightContainSubItems() { return isDirectory; }
  46837. const String getUniqueName() const { return file.getFullPathName(); }
  46838. int getItemHeight() const { return 22; }
  46839. const String getDragSourceDescription() { return owner.getDragAndDropDescription(); }
  46840. void itemOpennessChanged (bool isNowOpen)
  46841. {
  46842. if (isNowOpen)
  46843. {
  46844. clearSubItems();
  46845. isDirectory = file.isDirectory();
  46846. if (isDirectory)
  46847. {
  46848. if (subContentsList == 0)
  46849. {
  46850. jassert (parentContentsList != 0);
  46851. DirectoryContentsList* const l = new DirectoryContentsList (parentContentsList->getFilter(), thread);
  46852. l->setDirectory (file, true, true);
  46853. setSubContentsList (l);
  46854. canDeleteSubContentsList = true;
  46855. }
  46856. changeListenerCallback (0);
  46857. }
  46858. }
  46859. }
  46860. void setSubContentsList (DirectoryContentsList* newList) throw()
  46861. {
  46862. jassert (subContentsList == 0);
  46863. subContentsList = newList;
  46864. newList->addChangeListener (this);
  46865. }
  46866. void changeListenerCallback (void*)
  46867. {
  46868. clearSubItems();
  46869. if (isOpen() && subContentsList != 0)
  46870. {
  46871. for (int i = 0; i < subContentsList->getNumFiles(); ++i)
  46872. {
  46873. FileListTreeItem* const item
  46874. = new FileListTreeItem (owner, subContentsList, i, subContentsList->getFile(i), thread);
  46875. addSubItem (item);
  46876. }
  46877. }
  46878. }
  46879. void paintItem (Graphics& g, int width, int height)
  46880. {
  46881. if (file != File::nonexistent)
  46882. {
  46883. updateIcon (true);
  46884. if (icon == 0)
  46885. thread.addTimeSliceClient (this);
  46886. }
  46887. owner.getLookAndFeel()
  46888. .drawFileBrowserRow (g, width, height,
  46889. file.getFileName(),
  46890. icon,
  46891. fileSize, modTime,
  46892. isDirectory, isSelected(),
  46893. indexInContentsList);
  46894. }
  46895. void itemClicked (const MouseEvent& e)
  46896. {
  46897. owner.sendMouseClickMessage (file, e);
  46898. }
  46899. void itemDoubleClicked (const MouseEvent& e)
  46900. {
  46901. TreeViewItem::itemDoubleClicked (e);
  46902. owner.sendDoubleClickMessage (file);
  46903. }
  46904. void itemSelectionChanged (bool)
  46905. {
  46906. owner.sendSelectionChangeMessage();
  46907. }
  46908. bool useTimeSlice()
  46909. {
  46910. updateIcon (false);
  46911. thread.removeTimeSliceClient (this);
  46912. return false;
  46913. }
  46914. void handleAsyncUpdate()
  46915. {
  46916. owner.repaint();
  46917. }
  46918. const File file;
  46919. juce_UseDebuggingNewOperator
  46920. private:
  46921. FileTreeComponent& owner;
  46922. DirectoryContentsList* parentContentsList;
  46923. int indexInContentsList;
  46924. DirectoryContentsList* subContentsList;
  46925. bool isDirectory, canDeleteSubContentsList;
  46926. TimeSliceThread& thread;
  46927. Image* icon;
  46928. String fileSize;
  46929. String modTime;
  46930. void updateIcon (const bool onlyUpdateIfCached) throw()
  46931. {
  46932. if (icon == 0)
  46933. {
  46934. const int hashCode = (file.getFullPathName() + "_iconCacheSalt").hashCode();
  46935. Image* im = ImageCache::getFromHashCode (hashCode);
  46936. if (im == 0 && ! onlyUpdateIfCached)
  46937. {
  46938. im = juce_createIconForFile (file);
  46939. if (im != 0)
  46940. ImageCache::addImageToCache (im, hashCode);
  46941. }
  46942. if (im != 0)
  46943. {
  46944. icon = im;
  46945. triggerAsyncUpdate();
  46946. }
  46947. }
  46948. }
  46949. };
  46950. FileTreeComponent::FileTreeComponent (DirectoryContentsList& listToShow)
  46951. : DirectoryContentsDisplayComponent (listToShow)
  46952. {
  46953. FileListTreeItem* const root
  46954. = new FileListTreeItem (*this, 0, 0, listToShow.getDirectory(),
  46955. listToShow.getTimeSliceThread());
  46956. root->setSubContentsList (&listToShow);
  46957. setRootItemVisible (false);
  46958. setRootItem (root);
  46959. }
  46960. FileTreeComponent::~FileTreeComponent()
  46961. {
  46962. deleteRootItem();
  46963. }
  46964. const File FileTreeComponent::getSelectedFile (const int index) const
  46965. {
  46966. const FileListTreeItem* const item = dynamic_cast <const FileListTreeItem*> (getSelectedItem (index));
  46967. if (item != 0)
  46968. return item->file;
  46969. return File::nonexistent;
  46970. }
  46971. void FileTreeComponent::scrollToTop()
  46972. {
  46973. getViewport()->getVerticalScrollBar()->setCurrentRangeStart (0);
  46974. }
  46975. void FileTreeComponent::setDragAndDropDescription (const String& description) throw()
  46976. {
  46977. dragAndDropDescription = description;
  46978. }
  46979. END_JUCE_NAMESPACE
  46980. /*** End of inlined file: juce_FileTreeComponent.cpp ***/
  46981. /*** Start of inlined file: juce_ImagePreviewComponent.cpp ***/
  46982. BEGIN_JUCE_NAMESPACE
  46983. ImagePreviewComponent::ImagePreviewComponent()
  46984. {
  46985. }
  46986. ImagePreviewComponent::~ImagePreviewComponent()
  46987. {
  46988. }
  46989. void ImagePreviewComponent::getThumbSize (int& w, int& h) const
  46990. {
  46991. const int availableW = proportionOfWidth (0.97f);
  46992. const int availableH = getHeight() - 13 * 4;
  46993. const double scale = jmin (1.0,
  46994. availableW / (double) w,
  46995. availableH / (double) h);
  46996. w = roundToInt (scale * w);
  46997. h = roundToInt (scale * h);
  46998. }
  46999. void ImagePreviewComponent::selectedFileChanged (const File& file)
  47000. {
  47001. if (fileToLoad != file)
  47002. {
  47003. fileToLoad = file;
  47004. startTimer (100);
  47005. }
  47006. }
  47007. void ImagePreviewComponent::timerCallback()
  47008. {
  47009. stopTimer();
  47010. currentThumbnail = 0;
  47011. currentDetails = String::empty;
  47012. repaint();
  47013. ScopedPointer <FileInputStream> in (fileToLoad.createInputStream());
  47014. if (in != 0)
  47015. {
  47016. ImageFileFormat* const format = ImageFileFormat::findImageFormatForStream (*in);
  47017. if (format != 0)
  47018. {
  47019. currentThumbnail = format->decodeImage (*in);
  47020. if (currentThumbnail != 0)
  47021. {
  47022. int w = currentThumbnail->getWidth();
  47023. int h = currentThumbnail->getHeight();
  47024. currentDetails
  47025. << fileToLoad.getFileName() << "\n"
  47026. << format->getFormatName() << "\n"
  47027. << w << " x " << h << " pixels\n"
  47028. << File::descriptionOfSizeInBytes (fileToLoad.getSize());
  47029. getThumbSize (w, h);
  47030. currentThumbnail = currentThumbnail->createCopy (w, h);
  47031. }
  47032. }
  47033. }
  47034. }
  47035. void ImagePreviewComponent::paint (Graphics& g)
  47036. {
  47037. if (currentThumbnail != 0)
  47038. {
  47039. g.setFont (13.0f);
  47040. int w = currentThumbnail->getWidth();
  47041. int h = currentThumbnail->getHeight();
  47042. getThumbSize (w, h);
  47043. const int numLines = 4;
  47044. const int totalH = 13 * numLines + h + 4;
  47045. const int y = (getHeight() - totalH) / 2;
  47046. g.drawImageWithin (currentThumbnail,
  47047. (getWidth() - w) / 2, y, w, h,
  47048. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  47049. false);
  47050. g.drawFittedText (currentDetails,
  47051. 0, y + h + 4, getWidth(), 100,
  47052. Justification::centredTop, numLines);
  47053. }
  47054. }
  47055. END_JUCE_NAMESPACE
  47056. /*** End of inlined file: juce_ImagePreviewComponent.cpp ***/
  47057. /*** Start of inlined file: juce_WildcardFileFilter.cpp ***/
  47058. BEGIN_JUCE_NAMESPACE
  47059. WildcardFileFilter::WildcardFileFilter (const String& fileWildcardPatterns,
  47060. const String& directoryWildcardPatterns,
  47061. const String& description_)
  47062. : FileFilter (description_.isEmpty() ? fileWildcardPatterns
  47063. : (description_ + " (" + fileWildcardPatterns + ")"))
  47064. {
  47065. parse (fileWildcardPatterns, fileWildcards);
  47066. parse (directoryWildcardPatterns, directoryWildcards);
  47067. }
  47068. WildcardFileFilter::~WildcardFileFilter()
  47069. {
  47070. }
  47071. bool WildcardFileFilter::isFileSuitable (const File& file) const
  47072. {
  47073. return match (file, fileWildcards);
  47074. }
  47075. bool WildcardFileFilter::isDirectorySuitable (const File& file) const
  47076. {
  47077. return match (file, directoryWildcards);
  47078. }
  47079. void WildcardFileFilter::parse (const String& pattern, StringArray& result) throw()
  47080. {
  47081. result.addTokens (pattern.toLowerCase(), ";,", "\"'");
  47082. result.trim();
  47083. result.removeEmptyStrings();
  47084. // special case for *.*, because people use it to mean "any file", but it
  47085. // would actually ignore files with no extension.
  47086. for (int i = result.size(); --i >= 0;)
  47087. if (result[i] == "*.*")
  47088. result.set (i, "*");
  47089. }
  47090. bool WildcardFileFilter::match (const File& file, const StringArray& wildcards) throw()
  47091. {
  47092. const String filename (file.getFileName());
  47093. for (int i = wildcards.size(); --i >= 0;)
  47094. if (filename.matchesWildcard (wildcards[i], true))
  47095. return true;
  47096. return false;
  47097. }
  47098. END_JUCE_NAMESPACE
  47099. /*** End of inlined file: juce_WildcardFileFilter.cpp ***/
  47100. /*** Start of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47101. BEGIN_JUCE_NAMESPACE
  47102. KeyboardFocusTraverser::KeyboardFocusTraverser()
  47103. {
  47104. }
  47105. KeyboardFocusTraverser::~KeyboardFocusTraverser()
  47106. {
  47107. }
  47108. namespace KeyboardFocusHelpers
  47109. {
  47110. // This will sort a set of components, so that they are ordered in terms of
  47111. // left-to-right and then top-to-bottom.
  47112. class ScreenPositionComparator
  47113. {
  47114. public:
  47115. ScreenPositionComparator() {}
  47116. static int compareElements (const Component* const first, const Component* const second) throw()
  47117. {
  47118. int explicitOrder1 = first->getExplicitFocusOrder();
  47119. if (explicitOrder1 <= 0)
  47120. explicitOrder1 = std::numeric_limits<int>::max() / 2;
  47121. int explicitOrder2 = second->getExplicitFocusOrder();
  47122. if (explicitOrder2 <= 0)
  47123. explicitOrder2 = std::numeric_limits<int>::max() / 2;
  47124. if (explicitOrder1 != explicitOrder2)
  47125. return explicitOrder1 - explicitOrder2;
  47126. const int diff = first->getY() - second->getY();
  47127. return (diff == 0) ? first->getX() - second->getX()
  47128. : diff;
  47129. }
  47130. };
  47131. static void findAllFocusableComponents (Component* const parent, Array <Component*>& comps)
  47132. {
  47133. if (parent->getNumChildComponents() > 0)
  47134. {
  47135. Array <Component*> localComps;
  47136. ScreenPositionComparator comparator;
  47137. int i;
  47138. for (i = parent->getNumChildComponents(); --i >= 0;)
  47139. {
  47140. Component* const c = parent->getChildComponent (i);
  47141. if (c->isVisible() && c->isEnabled())
  47142. localComps.addSorted (comparator, c);
  47143. }
  47144. for (i = 0; i < localComps.size(); ++i)
  47145. {
  47146. Component* const c = localComps.getUnchecked (i);
  47147. if (c->getWantsKeyboardFocus())
  47148. comps.add (c);
  47149. if (! c->isFocusContainer())
  47150. findAllFocusableComponents (c, comps);
  47151. }
  47152. }
  47153. }
  47154. }
  47155. static Component* getIncrementedComponent (Component* const current, const int delta) throw()
  47156. {
  47157. Component* focusContainer = current->getParentComponent();
  47158. if (focusContainer != 0)
  47159. {
  47160. while (focusContainer->getParentComponent() != 0 && ! focusContainer->isFocusContainer())
  47161. focusContainer = focusContainer->getParentComponent();
  47162. if (focusContainer != 0)
  47163. {
  47164. Array <Component*> comps;
  47165. KeyboardFocusHelpers::findAllFocusableComponents (focusContainer, comps);
  47166. if (comps.size() > 0)
  47167. {
  47168. const int index = comps.indexOf (current);
  47169. return comps [(index + comps.size() + delta) % comps.size()];
  47170. }
  47171. }
  47172. }
  47173. return 0;
  47174. }
  47175. Component* KeyboardFocusTraverser::getNextComponent (Component* current)
  47176. {
  47177. return getIncrementedComponent (current, 1);
  47178. }
  47179. Component* KeyboardFocusTraverser::getPreviousComponent (Component* current)
  47180. {
  47181. return getIncrementedComponent (current, -1);
  47182. }
  47183. Component* KeyboardFocusTraverser::getDefaultComponent (Component* parentComponent)
  47184. {
  47185. Array <Component*> comps;
  47186. if (parentComponent != 0)
  47187. KeyboardFocusHelpers::findAllFocusableComponents (parentComponent, comps);
  47188. return comps.getFirst();
  47189. }
  47190. END_JUCE_NAMESPACE
  47191. /*** End of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47192. /*** Start of inlined file: juce_KeyListener.cpp ***/
  47193. BEGIN_JUCE_NAMESPACE
  47194. bool KeyListener::keyStateChanged (const bool, Component*)
  47195. {
  47196. return false;
  47197. }
  47198. END_JUCE_NAMESPACE
  47199. /*** End of inlined file: juce_KeyListener.cpp ***/
  47200. /*** Start of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  47201. BEGIN_JUCE_NAMESPACE
  47202. // N.B. these two includes are put here deliberately to avoid problems with
  47203. // old GCCs failing on long include paths
  47204. const int maxKeys = 3;
  47205. class KeyMappingChangeButton : public Button
  47206. {
  47207. public:
  47208. KeyMappingChangeButton (KeyMappingEditorComponent* const owner_,
  47209. const CommandID commandID_,
  47210. const String& keyName,
  47211. const int keyNum_)
  47212. : Button (keyName),
  47213. owner (owner_),
  47214. commandID (commandID_),
  47215. keyNum (keyNum_)
  47216. {
  47217. setWantsKeyboardFocus (false);
  47218. setTriggeredOnMouseDown (keyNum >= 0);
  47219. if (keyNum_ < 0)
  47220. setTooltip (TRANS("adds a new key-mapping"));
  47221. else
  47222. setTooltip (TRANS("click to change this key-mapping"));
  47223. }
  47224. ~KeyMappingChangeButton()
  47225. {
  47226. }
  47227. void paintButton (Graphics& g, bool /*isOver*/, bool /*isDown*/)
  47228. {
  47229. getLookAndFeel().drawKeymapChangeButton (g, getWidth(), getHeight(), *this,
  47230. keyNum >= 0 ? getName() : String::empty);
  47231. }
  47232. void clicked()
  47233. {
  47234. if (keyNum >= 0)
  47235. {
  47236. // existing key clicked..
  47237. PopupMenu m;
  47238. m.addItem (1, TRANS("change this key-mapping"));
  47239. m.addSeparator();
  47240. m.addItem (2, TRANS("remove this key-mapping"));
  47241. const int res = m.show();
  47242. if (res == 1)
  47243. {
  47244. owner->assignNewKey (commandID, keyNum);
  47245. }
  47246. else if (res == 2)
  47247. {
  47248. owner->getMappings()->removeKeyPress (commandID, keyNum);
  47249. }
  47250. }
  47251. else
  47252. {
  47253. // + button pressed..
  47254. owner->assignNewKey (commandID, -1);
  47255. }
  47256. }
  47257. void fitToContent (const int h) throw()
  47258. {
  47259. if (keyNum < 0)
  47260. {
  47261. setSize (h, h);
  47262. }
  47263. else
  47264. {
  47265. Font f (h * 0.6f);
  47266. setSize (jlimit (h * 4, h * 8, 6 + f.getStringWidth (getName())), h);
  47267. }
  47268. }
  47269. juce_UseDebuggingNewOperator
  47270. private:
  47271. KeyMappingEditorComponent* const owner;
  47272. const CommandID commandID;
  47273. const int keyNum;
  47274. KeyMappingChangeButton (const KeyMappingChangeButton&);
  47275. KeyMappingChangeButton& operator= (const KeyMappingChangeButton&);
  47276. };
  47277. class KeyMappingItemComponent : public Component
  47278. {
  47279. public:
  47280. KeyMappingItemComponent (KeyMappingEditorComponent* const owner_,
  47281. const CommandID commandID_)
  47282. : owner (owner_),
  47283. commandID (commandID_)
  47284. {
  47285. setInterceptsMouseClicks (false, true);
  47286. const bool isReadOnly = owner_->isCommandReadOnly (commandID);
  47287. const Array <KeyPress> keyPresses (owner_->getMappings()->getKeyPressesAssignedToCommand (commandID));
  47288. for (int i = 0; i < jmin (maxKeys, keyPresses.size()); ++i)
  47289. {
  47290. KeyMappingChangeButton* const kb
  47291. = new KeyMappingChangeButton (owner_, commandID,
  47292. owner_->getDescriptionForKeyPress (keyPresses.getReference (i)), i);
  47293. kb->setEnabled (! isReadOnly);
  47294. addAndMakeVisible (kb);
  47295. }
  47296. KeyMappingChangeButton* const kb
  47297. = new KeyMappingChangeButton (owner_, commandID, String::empty, -1);
  47298. addChildComponent (kb);
  47299. kb->setVisible (keyPresses.size() < maxKeys && ! isReadOnly);
  47300. }
  47301. ~KeyMappingItemComponent()
  47302. {
  47303. deleteAllChildren();
  47304. }
  47305. void paint (Graphics& g)
  47306. {
  47307. g.setFont (getHeight() * 0.7f);
  47308. g.setColour (findColour (KeyMappingEditorComponent::textColourId));
  47309. g.drawFittedText (owner->getMappings()->getCommandManager()->getNameOfCommand (commandID),
  47310. 4, 0, jmax (40, getChildComponent (0)->getX() - 5), getHeight(),
  47311. Justification::centredLeft, true);
  47312. }
  47313. void resized()
  47314. {
  47315. int x = getWidth() - 4;
  47316. for (int i = getNumChildComponents(); --i >= 0;)
  47317. {
  47318. KeyMappingChangeButton* const kb = dynamic_cast <KeyMappingChangeButton*> (getChildComponent (i));
  47319. kb->fitToContent (getHeight() - 2);
  47320. kb->setTopRightPosition (x, 1);
  47321. x -= kb->getWidth() + 5;
  47322. }
  47323. }
  47324. juce_UseDebuggingNewOperator
  47325. private:
  47326. KeyMappingEditorComponent* const owner;
  47327. const CommandID commandID;
  47328. KeyMappingItemComponent (const KeyMappingItemComponent&);
  47329. KeyMappingItemComponent& operator= (const KeyMappingItemComponent&);
  47330. };
  47331. class KeyMappingTreeViewItem : public TreeViewItem
  47332. {
  47333. public:
  47334. KeyMappingTreeViewItem (KeyMappingEditorComponent* const owner_,
  47335. const CommandID commandID_)
  47336. : owner (owner_),
  47337. commandID (commandID_)
  47338. {
  47339. }
  47340. ~KeyMappingTreeViewItem()
  47341. {
  47342. }
  47343. const String getUniqueName() const { return String ((int) commandID) + "_id"; }
  47344. bool mightContainSubItems() { return false; }
  47345. int getItemHeight() const { return 20; }
  47346. Component* createItemComponent()
  47347. {
  47348. return new KeyMappingItemComponent (owner, commandID);
  47349. }
  47350. juce_UseDebuggingNewOperator
  47351. private:
  47352. KeyMappingEditorComponent* const owner;
  47353. const CommandID commandID;
  47354. KeyMappingTreeViewItem (const KeyMappingTreeViewItem&);
  47355. KeyMappingTreeViewItem& operator= (const KeyMappingTreeViewItem&);
  47356. };
  47357. class KeyCategoryTreeViewItem : public TreeViewItem
  47358. {
  47359. public:
  47360. KeyCategoryTreeViewItem (KeyMappingEditorComponent* const owner_,
  47361. const String& name)
  47362. : owner (owner_),
  47363. categoryName (name)
  47364. {
  47365. }
  47366. ~KeyCategoryTreeViewItem()
  47367. {
  47368. }
  47369. const String getUniqueName() const { return categoryName + "_cat"; }
  47370. bool mightContainSubItems() { return true; }
  47371. int getItemHeight() const { return 28; }
  47372. void paintItem (Graphics& g, int width, int height)
  47373. {
  47374. g.setFont (height * 0.6f, Font::bold);
  47375. g.setColour (owner->findColour (KeyMappingEditorComponent::textColourId));
  47376. g.drawText (categoryName,
  47377. 2, 0, width - 2, height,
  47378. Justification::centredLeft, true);
  47379. }
  47380. void itemOpennessChanged (bool isNowOpen)
  47381. {
  47382. if (isNowOpen)
  47383. {
  47384. if (getNumSubItems() == 0)
  47385. {
  47386. Array <CommandID> commands (owner->getMappings()->getCommandManager()->getCommandsInCategory (categoryName));
  47387. for (int i = 0; i < commands.size(); ++i)
  47388. {
  47389. if (owner->shouldCommandBeIncluded (commands[i]))
  47390. addSubItem (new KeyMappingTreeViewItem (owner, commands[i]));
  47391. }
  47392. }
  47393. }
  47394. else
  47395. {
  47396. clearSubItems();
  47397. }
  47398. }
  47399. juce_UseDebuggingNewOperator
  47400. private:
  47401. KeyMappingEditorComponent* owner;
  47402. String categoryName;
  47403. KeyCategoryTreeViewItem (const KeyCategoryTreeViewItem&);
  47404. KeyCategoryTreeViewItem& operator= (const KeyCategoryTreeViewItem&);
  47405. };
  47406. KeyMappingEditorComponent::KeyMappingEditorComponent (KeyPressMappingSet* const mappingManager,
  47407. const bool showResetToDefaultButton)
  47408. : mappings (mappingManager)
  47409. {
  47410. jassert (mappingManager != 0); // can't be null!
  47411. mappingManager->addChangeListener (this);
  47412. setLinesDrawnForSubItems (false);
  47413. resetButton = 0;
  47414. if (showResetToDefaultButton)
  47415. {
  47416. addAndMakeVisible (resetButton = new TextButton (TRANS("reset to defaults")));
  47417. resetButton->addButtonListener (this);
  47418. }
  47419. addAndMakeVisible (tree = new TreeView());
  47420. tree->setColour (TreeView::backgroundColourId, findColour (backgroundColourId));
  47421. tree->setRootItemVisible (false);
  47422. tree->setDefaultOpenness (true);
  47423. tree->setRootItem (this);
  47424. }
  47425. KeyMappingEditorComponent::~KeyMappingEditorComponent()
  47426. {
  47427. mappings->removeChangeListener (this);
  47428. deleteAllChildren();
  47429. }
  47430. bool KeyMappingEditorComponent::mightContainSubItems()
  47431. {
  47432. return true;
  47433. }
  47434. const String KeyMappingEditorComponent::getUniqueName() const
  47435. {
  47436. return "keys";
  47437. }
  47438. void KeyMappingEditorComponent::setColours (const Colour& mainBackground,
  47439. const Colour& textColour)
  47440. {
  47441. setColour (backgroundColourId, mainBackground);
  47442. setColour (textColourId, textColour);
  47443. tree->setColour (TreeView::backgroundColourId, mainBackground);
  47444. }
  47445. void KeyMappingEditorComponent::parentHierarchyChanged()
  47446. {
  47447. changeListenerCallback (0);
  47448. }
  47449. void KeyMappingEditorComponent::resized()
  47450. {
  47451. int h = getHeight();
  47452. if (resetButton != 0)
  47453. {
  47454. const int buttonHeight = 20;
  47455. h -= buttonHeight + 8;
  47456. int x = getWidth() - 8;
  47457. const int y = h + 6;
  47458. resetButton->changeWidthToFitText (buttonHeight);
  47459. resetButton->setTopRightPosition (x, y);
  47460. }
  47461. tree->setBounds (0, 0, getWidth(), h);
  47462. }
  47463. void KeyMappingEditorComponent::buttonClicked (Button* button)
  47464. {
  47465. if (button == resetButton)
  47466. {
  47467. if (AlertWindow::showOkCancelBox (AlertWindow::QuestionIcon,
  47468. TRANS("Reset to defaults"),
  47469. TRANS("Are you sure you want to reset all the key-mappings to their default state?"),
  47470. TRANS("Reset")))
  47471. {
  47472. mappings->resetToDefaultMappings();
  47473. }
  47474. }
  47475. }
  47476. void KeyMappingEditorComponent::changeListenerCallback (void*)
  47477. {
  47478. ScopedPointer <XmlElement> openness (tree->getOpennessState (true));
  47479. clearSubItems();
  47480. const StringArray categories (mappings->getCommandManager()->getCommandCategories());
  47481. for (int i = 0; i < categories.size(); ++i)
  47482. {
  47483. const Array <CommandID> commands (mappings->getCommandManager()->getCommandsInCategory (categories[i]));
  47484. int count = 0;
  47485. for (int j = 0; j < commands.size(); ++j)
  47486. if (shouldCommandBeIncluded (commands[j]))
  47487. ++count;
  47488. if (count > 0)
  47489. addSubItem (new KeyCategoryTreeViewItem (this, categories[i]));
  47490. }
  47491. if (openness != 0)
  47492. tree->restoreOpennessState (*openness);
  47493. }
  47494. class KeyEntryWindow : public AlertWindow
  47495. {
  47496. public:
  47497. KeyEntryWindow (KeyMappingEditorComponent* const owner_)
  47498. : AlertWindow (TRANS("New key-mapping"),
  47499. TRANS("Please press a key combination now..."),
  47500. AlertWindow::NoIcon),
  47501. owner (owner_)
  47502. {
  47503. addButton (TRANS("ok"), 1);
  47504. addButton (TRANS("cancel"), 0);
  47505. // (avoid return + escape keys getting processed by the buttons..)
  47506. for (int i = getNumChildComponents(); --i >= 0;)
  47507. getChildComponent (i)->setWantsKeyboardFocus (false);
  47508. setWantsKeyboardFocus (true);
  47509. grabKeyboardFocus();
  47510. }
  47511. ~KeyEntryWindow()
  47512. {
  47513. }
  47514. bool keyPressed (const KeyPress& key)
  47515. {
  47516. lastPress = key;
  47517. String message (TRANS("Key: ") + owner->getDescriptionForKeyPress (key));
  47518. const CommandID previousCommand = owner->getMappings()->findCommandForKeyPress (key);
  47519. if (previousCommand != 0)
  47520. {
  47521. message << "\n\n"
  47522. << TRANS("(Currently assigned to \"")
  47523. << owner->getMappings()->getCommandManager()->getNameOfCommand (previousCommand)
  47524. << "\")";
  47525. }
  47526. setMessage (message);
  47527. return true;
  47528. }
  47529. bool keyStateChanged (bool)
  47530. {
  47531. return true;
  47532. }
  47533. KeyPress lastPress;
  47534. juce_UseDebuggingNewOperator
  47535. private:
  47536. KeyMappingEditorComponent* owner;
  47537. KeyEntryWindow (const KeyEntryWindow&);
  47538. KeyEntryWindow& operator= (const KeyEntryWindow&);
  47539. };
  47540. void KeyMappingEditorComponent::assignNewKey (const CommandID commandID, const int index)
  47541. {
  47542. KeyEntryWindow entryWindow (this);
  47543. if (entryWindow.runModalLoop() != 0)
  47544. {
  47545. entryWindow.setVisible (false);
  47546. if (entryWindow.lastPress.isValid())
  47547. {
  47548. const CommandID previousCommand = mappings->findCommandForKeyPress (entryWindow.lastPress);
  47549. if (previousCommand != 0)
  47550. {
  47551. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  47552. TRANS("Change key-mapping"),
  47553. TRANS("This key is already assigned to the command \"")
  47554. + mappings->getCommandManager()->getNameOfCommand (previousCommand)
  47555. + TRANS("\"\n\nDo you want to re-assign it to this new command instead?"),
  47556. TRANS("re-assign"),
  47557. TRANS("cancel")))
  47558. {
  47559. return;
  47560. }
  47561. }
  47562. mappings->removeKeyPress (entryWindow.lastPress);
  47563. if (index >= 0)
  47564. mappings->removeKeyPress (commandID, index);
  47565. mappings->addKeyPress (commandID, entryWindow.lastPress, index);
  47566. }
  47567. }
  47568. }
  47569. bool KeyMappingEditorComponent::shouldCommandBeIncluded (const CommandID commandID)
  47570. {
  47571. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  47572. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::hiddenFromKeyEditor) == 0);
  47573. }
  47574. bool KeyMappingEditorComponent::isCommandReadOnly (const CommandID commandID)
  47575. {
  47576. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  47577. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::readOnlyInKeyEditor) != 0);
  47578. }
  47579. const String KeyMappingEditorComponent::getDescriptionForKeyPress (const KeyPress& key)
  47580. {
  47581. return key.getTextDescription();
  47582. }
  47583. END_JUCE_NAMESPACE
  47584. /*** End of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  47585. /*** Start of inlined file: juce_KeyPress.cpp ***/
  47586. BEGIN_JUCE_NAMESPACE
  47587. KeyPress::KeyPress() throw()
  47588. : keyCode (0),
  47589. mods (0),
  47590. textCharacter (0)
  47591. {
  47592. }
  47593. KeyPress::KeyPress (const int keyCode_,
  47594. const ModifierKeys& mods_,
  47595. const juce_wchar textCharacter_) throw()
  47596. : keyCode (keyCode_),
  47597. mods (mods_),
  47598. textCharacter (textCharacter_)
  47599. {
  47600. }
  47601. KeyPress::KeyPress (const int keyCode_) throw()
  47602. : keyCode (keyCode_),
  47603. textCharacter (0)
  47604. {
  47605. }
  47606. KeyPress::KeyPress (const KeyPress& other) throw()
  47607. : keyCode (other.keyCode),
  47608. mods (other.mods),
  47609. textCharacter (other.textCharacter)
  47610. {
  47611. }
  47612. KeyPress& KeyPress::operator= (const KeyPress& other) throw()
  47613. {
  47614. keyCode = other.keyCode;
  47615. mods = other.mods;
  47616. textCharacter = other.textCharacter;
  47617. return *this;
  47618. }
  47619. bool KeyPress::operator== (const KeyPress& other) const throw()
  47620. {
  47621. return mods.getRawFlags() == other.mods.getRawFlags()
  47622. && (textCharacter == other.textCharacter
  47623. || textCharacter == 0
  47624. || other.textCharacter == 0)
  47625. && (keyCode == other.keyCode
  47626. || (keyCode < 256
  47627. && other.keyCode < 256
  47628. && CharacterFunctions::toLowerCase ((tchar) keyCode)
  47629. == CharacterFunctions::toLowerCase ((tchar) other.keyCode)));
  47630. }
  47631. bool KeyPress::operator!= (const KeyPress& other) const throw()
  47632. {
  47633. return ! operator== (other);
  47634. }
  47635. bool KeyPress::isCurrentlyDown() const throw()
  47636. {
  47637. return isKeyCurrentlyDown (keyCode)
  47638. && (ModifierKeys::getCurrentModifiers().getRawFlags() & ModifierKeys::allKeyboardModifiers)
  47639. == (mods.getRawFlags() & ModifierKeys::allKeyboardModifiers);
  47640. }
  47641. namespace KeyPressHelpers
  47642. {
  47643. struct KeyNameAndCode
  47644. {
  47645. const char* name;
  47646. int code;
  47647. };
  47648. static const KeyNameAndCode translations[] =
  47649. {
  47650. { "spacebar", KeyPress::spaceKey },
  47651. { "return", KeyPress::returnKey },
  47652. { "escape", KeyPress::escapeKey },
  47653. { "backspace", KeyPress::backspaceKey },
  47654. { "cursor left", KeyPress::leftKey },
  47655. { "cursor right", KeyPress::rightKey },
  47656. { "cursor up", KeyPress::upKey },
  47657. { "cursor down", KeyPress::downKey },
  47658. { "page up", KeyPress::pageUpKey },
  47659. { "page down", KeyPress::pageDownKey },
  47660. { "home", KeyPress::homeKey },
  47661. { "end", KeyPress::endKey },
  47662. { "delete", KeyPress::deleteKey },
  47663. { "insert", KeyPress::insertKey },
  47664. { "tab", KeyPress::tabKey },
  47665. { "play", KeyPress::playKey },
  47666. { "stop", KeyPress::stopKey },
  47667. { "fast forward", KeyPress::fastForwardKey },
  47668. { "rewind", KeyPress::rewindKey }
  47669. };
  47670. static const String numberPadPrefix() { return "numpad "; }
  47671. }
  47672. const KeyPress KeyPress::createFromDescription (const String& desc) throw()
  47673. {
  47674. int modifiers = 0;
  47675. if (desc.containsWholeWordIgnoreCase (T("ctrl"))
  47676. || desc.containsWholeWordIgnoreCase (T("control"))
  47677. || desc.containsWholeWordIgnoreCase (T("ctl")))
  47678. modifiers |= ModifierKeys::ctrlModifier;
  47679. if (desc.containsWholeWordIgnoreCase (T("shift"))
  47680. || desc.containsWholeWordIgnoreCase (T("shft")))
  47681. modifiers |= ModifierKeys::shiftModifier;
  47682. if (desc.containsWholeWordIgnoreCase (T("alt"))
  47683. || desc.containsWholeWordIgnoreCase (T("option")))
  47684. modifiers |= ModifierKeys::altModifier;
  47685. if (desc.containsWholeWordIgnoreCase (T("command"))
  47686. || desc.containsWholeWordIgnoreCase (T("cmd")))
  47687. modifiers |= ModifierKeys::commandModifier;
  47688. int key = 0;
  47689. for (int i = 0; i < numElementsInArray (KeyPressHelpers::translations); ++i)
  47690. {
  47691. if (desc.containsWholeWordIgnoreCase (String (KeyPressHelpers::translations[i].name)))
  47692. {
  47693. key = KeyPressHelpers::translations[i].code;
  47694. break;
  47695. }
  47696. }
  47697. if (key == 0)
  47698. {
  47699. // see if it's a numpad key..
  47700. if (desc.containsIgnoreCase (KeyPressHelpers::numberPadPrefix()))
  47701. {
  47702. const tchar lastChar = desc.trimEnd().getLastCharacter();
  47703. if (lastChar >= '0' && lastChar <= '9')
  47704. key = numberPad0 + lastChar - '0';
  47705. else if (lastChar == '+')
  47706. key = numberPadAdd;
  47707. else if (lastChar == '-')
  47708. key = numberPadSubtract;
  47709. else if (lastChar == '*')
  47710. key = numberPadMultiply;
  47711. else if (lastChar == '/')
  47712. key = numberPadDivide;
  47713. else if (lastChar == '.')
  47714. key = numberPadDecimalPoint;
  47715. else if (lastChar == '=')
  47716. key = numberPadEquals;
  47717. else if (desc.endsWith (T("separator")))
  47718. key = numberPadSeparator;
  47719. else if (desc.endsWith (T("delete")))
  47720. key = numberPadDelete;
  47721. }
  47722. if (key == 0)
  47723. {
  47724. // see if it's a function key..
  47725. for (int i = 1; i <= 12; ++i)
  47726. if (desc.containsWholeWordIgnoreCase ("f" + String (i)))
  47727. key = F1Key + i - 1;
  47728. if (key == 0)
  47729. {
  47730. // give up and use the hex code..
  47731. const int hexCode = desc.fromFirstOccurrenceOf (T("#"), false, false)
  47732. .toLowerCase()
  47733. .retainCharacters (T("0123456789abcdef"))
  47734. .getHexValue32();
  47735. if (hexCode > 0)
  47736. key = hexCode;
  47737. else
  47738. key = CharacterFunctions::toUpperCase (desc.getLastCharacter());
  47739. }
  47740. }
  47741. }
  47742. return KeyPress (key, ModifierKeys (modifiers), 0);
  47743. }
  47744. const String KeyPress::getTextDescription() const throw()
  47745. {
  47746. String desc;
  47747. if (keyCode > 0)
  47748. {
  47749. // some keyboard layouts use a shift-key to get the slash, but in those cases, we
  47750. // want to store it as being a slash, not shift+whatever.
  47751. if (textCharacter == '/')
  47752. return "/";
  47753. if (mods.isCtrlDown())
  47754. desc << "ctrl + ";
  47755. if (mods.isShiftDown())
  47756. desc << "shift + ";
  47757. #if JUCE_MAC
  47758. // only do this on the mac, because on Windows ctrl and command are the same,
  47759. // and this would get confusing
  47760. if (mods.isCommandDown())
  47761. desc << "command + ";
  47762. if (mods.isAltDown())
  47763. desc << "option + ";
  47764. #else
  47765. if (mods.isAltDown())
  47766. desc << "alt + ";
  47767. #endif
  47768. for (int i = 0; i < numElementsInArray (KeyPressHelpers::translations); ++i)
  47769. if (keyCode == KeyPressHelpers::translations[i].code)
  47770. return desc + KeyPressHelpers::translations[i].name;
  47771. if (keyCode >= F1Key && keyCode <= F16Key)
  47772. desc << 'F' << (1 + keyCode - F1Key);
  47773. else if (keyCode >= numberPad0 && keyCode <= numberPad9)
  47774. desc << KeyPressHelpers::numberPadPrefix() << (keyCode - numberPad0);
  47775. else if (keyCode >= 33 && keyCode < 176)
  47776. desc += CharacterFunctions::toUpperCase ((tchar) keyCode);
  47777. else if (keyCode == numberPadAdd)
  47778. desc << KeyPressHelpers::numberPadPrefix() << '+';
  47779. else if (keyCode == numberPadSubtract)
  47780. desc << KeyPressHelpers::numberPadPrefix() << '-';
  47781. else if (keyCode == numberPadMultiply)
  47782. desc << KeyPressHelpers::numberPadPrefix() << '*';
  47783. else if (keyCode == numberPadDivide)
  47784. desc << KeyPressHelpers::numberPadPrefix() << '/';
  47785. else if (keyCode == numberPadSeparator)
  47786. desc << KeyPressHelpers::numberPadPrefix() << "separator";
  47787. else if (keyCode == numberPadDecimalPoint)
  47788. desc << KeyPressHelpers::numberPadPrefix() << '.';
  47789. else if (keyCode == numberPadDelete)
  47790. desc << KeyPressHelpers::numberPadPrefix() << "delete";
  47791. else
  47792. desc << '#' << String::toHexString (keyCode);
  47793. }
  47794. return desc;
  47795. }
  47796. END_JUCE_NAMESPACE
  47797. /*** End of inlined file: juce_KeyPress.cpp ***/
  47798. /*** Start of inlined file: juce_KeyPressMappingSet.cpp ***/
  47799. BEGIN_JUCE_NAMESPACE
  47800. KeyPressMappingSet::KeyPressMappingSet (ApplicationCommandManager* const commandManager_) throw()
  47801. : commandManager (commandManager_)
  47802. {
  47803. // A manager is needed to get the descriptions of commands, and will be called when
  47804. // a command is invoked. So you can't leave this null..
  47805. jassert (commandManager_ != 0);
  47806. Desktop::getInstance().addFocusChangeListener (this);
  47807. }
  47808. KeyPressMappingSet::KeyPressMappingSet (const KeyPressMappingSet& other) throw()
  47809. : commandManager (other.commandManager)
  47810. {
  47811. Desktop::getInstance().addFocusChangeListener (this);
  47812. }
  47813. KeyPressMappingSet::~KeyPressMappingSet()
  47814. {
  47815. Desktop::getInstance().removeFocusChangeListener (this);
  47816. }
  47817. const Array <KeyPress> KeyPressMappingSet::getKeyPressesAssignedToCommand (const CommandID commandID) const throw()
  47818. {
  47819. for (int i = 0; i < mappings.size(); ++i)
  47820. if (mappings.getUnchecked(i)->commandID == commandID)
  47821. return mappings.getUnchecked (i)->keypresses;
  47822. return Array <KeyPress> ();
  47823. }
  47824. void KeyPressMappingSet::addKeyPress (const CommandID commandID,
  47825. const KeyPress& newKeyPress,
  47826. int insertIndex) throw()
  47827. {
  47828. // If you specify an upper-case letter but no shift key, how is the user supposed to press it!?
  47829. // Stick to lower-case letters when defining a keypress, to avoid ambiguity.
  47830. jassert (! (CharacterFunctions::isUpperCase (newKeyPress.getTextCharacter())
  47831. && ! newKeyPress.getModifiers().isShiftDown()));
  47832. if (findCommandForKeyPress (newKeyPress) != commandID)
  47833. {
  47834. removeKeyPress (newKeyPress);
  47835. if (newKeyPress.isValid())
  47836. {
  47837. for (int i = mappings.size(); --i >= 0;)
  47838. {
  47839. if (mappings.getUnchecked(i)->commandID == commandID)
  47840. {
  47841. mappings.getUnchecked(i)->keypresses.insert (insertIndex, newKeyPress);
  47842. sendChangeMessage (this);
  47843. return;
  47844. }
  47845. }
  47846. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  47847. if (ci != 0)
  47848. {
  47849. CommandMapping* const cm = new CommandMapping();
  47850. cm->commandID = commandID;
  47851. cm->keypresses.add (newKeyPress);
  47852. cm->wantsKeyUpDownCallbacks = (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) != 0;
  47853. mappings.add (cm);
  47854. sendChangeMessage (this);
  47855. }
  47856. }
  47857. }
  47858. }
  47859. void KeyPressMappingSet::resetToDefaultMappings() throw()
  47860. {
  47861. mappings.clear();
  47862. for (int i = 0; i < commandManager->getNumCommands(); ++i)
  47863. {
  47864. const ApplicationCommandInfo* const ci = commandManager->getCommandForIndex (i);
  47865. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  47866. {
  47867. addKeyPress (ci->commandID,
  47868. ci->defaultKeypresses.getReference (j));
  47869. }
  47870. }
  47871. sendChangeMessage (this);
  47872. }
  47873. void KeyPressMappingSet::resetToDefaultMapping (const CommandID commandID) throw()
  47874. {
  47875. clearAllKeyPresses (commandID);
  47876. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  47877. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  47878. {
  47879. addKeyPress (ci->commandID,
  47880. ci->defaultKeypresses.getReference (j));
  47881. }
  47882. }
  47883. void KeyPressMappingSet::clearAllKeyPresses() throw()
  47884. {
  47885. if (mappings.size() > 0)
  47886. {
  47887. sendChangeMessage (this);
  47888. mappings.clear();
  47889. }
  47890. }
  47891. void KeyPressMappingSet::clearAllKeyPresses (const CommandID commandID) throw()
  47892. {
  47893. for (int i = mappings.size(); --i >= 0;)
  47894. {
  47895. if (mappings.getUnchecked(i)->commandID == commandID)
  47896. {
  47897. mappings.remove (i);
  47898. sendChangeMessage (this);
  47899. }
  47900. }
  47901. }
  47902. void KeyPressMappingSet::removeKeyPress (const KeyPress& keypress) throw()
  47903. {
  47904. if (keypress.isValid())
  47905. {
  47906. for (int i = mappings.size(); --i >= 0;)
  47907. {
  47908. CommandMapping* const cm = mappings.getUnchecked(i);
  47909. for (int j = cm->keypresses.size(); --j >= 0;)
  47910. {
  47911. if (keypress == cm->keypresses [j])
  47912. {
  47913. cm->keypresses.remove (j);
  47914. sendChangeMessage (this);
  47915. }
  47916. }
  47917. }
  47918. }
  47919. }
  47920. void KeyPressMappingSet::removeKeyPress (const CommandID commandID,
  47921. const int keyPressIndex) throw()
  47922. {
  47923. for (int i = mappings.size(); --i >= 0;)
  47924. {
  47925. if (mappings.getUnchecked(i)->commandID == commandID)
  47926. {
  47927. mappings.getUnchecked(i)->keypresses.remove (keyPressIndex);
  47928. sendChangeMessage (this);
  47929. break;
  47930. }
  47931. }
  47932. }
  47933. CommandID KeyPressMappingSet::findCommandForKeyPress (const KeyPress& keyPress) const throw()
  47934. {
  47935. for (int i = 0; i < mappings.size(); ++i)
  47936. if (mappings.getUnchecked(i)->keypresses.contains (keyPress))
  47937. return mappings.getUnchecked(i)->commandID;
  47938. return 0;
  47939. }
  47940. bool KeyPressMappingSet::containsMapping (const CommandID commandID,
  47941. const KeyPress& keyPress) const throw()
  47942. {
  47943. for (int i = mappings.size(); --i >= 0;)
  47944. if (mappings.getUnchecked(i)->commandID == commandID)
  47945. return mappings.getUnchecked(i)->keypresses.contains (keyPress);
  47946. return false;
  47947. }
  47948. void KeyPressMappingSet::invokeCommand (const CommandID commandID,
  47949. const KeyPress& key,
  47950. const bool isKeyDown,
  47951. const int millisecsSinceKeyPressed,
  47952. Component* const originatingComponent) const
  47953. {
  47954. ApplicationCommandTarget::InvocationInfo info (commandID);
  47955. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromKeyPress;
  47956. info.isKeyDown = isKeyDown;
  47957. info.keyPress = key;
  47958. info.millisecsSinceKeyPressed = millisecsSinceKeyPressed;
  47959. info.originatingComponent = originatingComponent;
  47960. commandManager->invoke (info, false);
  47961. }
  47962. bool KeyPressMappingSet::restoreFromXml (const XmlElement& xmlVersion)
  47963. {
  47964. if (xmlVersion.hasTagName ("KEYMAPPINGS"))
  47965. {
  47966. if (xmlVersion.getBoolAttribute ("basedOnDefaults", true))
  47967. {
  47968. // if the XML was created as a set of differences from the default mappings,
  47969. // (i.e. by calling createXml (true)), then we need to first restore the defaults.
  47970. resetToDefaultMappings();
  47971. }
  47972. else
  47973. {
  47974. // if the XML was created calling createXml (false), then we need to clear all
  47975. // the keys and treat the xml as describing the entire set of mappings.
  47976. clearAllKeyPresses();
  47977. }
  47978. forEachXmlChildElement (xmlVersion, map)
  47979. {
  47980. const CommandID commandId = map->getStringAttribute ("commandId").getHexValue32();
  47981. if (commandId != 0)
  47982. {
  47983. const KeyPress key (KeyPress::createFromDescription (map->getStringAttribute ("key")));
  47984. if (map->hasTagName ("MAPPING"))
  47985. {
  47986. addKeyPress (commandId, key);
  47987. }
  47988. else if (map->hasTagName ("UNMAPPING"))
  47989. {
  47990. if (containsMapping (commandId, key))
  47991. removeKeyPress (key);
  47992. }
  47993. }
  47994. }
  47995. return true;
  47996. }
  47997. return false;
  47998. }
  47999. XmlElement* KeyPressMappingSet::createXml (const bool saveDifferencesFromDefaultSet) const
  48000. {
  48001. ScopedPointer <KeyPressMappingSet> defaultSet;
  48002. if (saveDifferencesFromDefaultSet)
  48003. {
  48004. defaultSet = new KeyPressMappingSet (commandManager);
  48005. defaultSet->resetToDefaultMappings();
  48006. }
  48007. XmlElement* const doc = new XmlElement ("KEYMAPPINGS");
  48008. doc->setAttribute ("basedOnDefaults", saveDifferencesFromDefaultSet);
  48009. int i;
  48010. for (i = 0; i < mappings.size(); ++i)
  48011. {
  48012. const CommandMapping* const cm = mappings.getUnchecked(i);
  48013. for (int j = 0; j < cm->keypresses.size(); ++j)
  48014. {
  48015. if (defaultSet == 0
  48016. || ! defaultSet->containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48017. {
  48018. XmlElement* const map = doc->createNewChildElement ("MAPPING");
  48019. map->setAttribute ("commandId", String::toHexString ((int) cm->commandID));
  48020. map->setAttribute ("description", commandManager->getDescriptionOfCommand (cm->commandID));
  48021. map->setAttribute ("key", cm->keypresses.getReference (j).getTextDescription());
  48022. }
  48023. }
  48024. }
  48025. if (defaultSet != 0)
  48026. {
  48027. for (i = 0; i < defaultSet->mappings.size(); ++i)
  48028. {
  48029. const CommandMapping* const cm = defaultSet->mappings.getUnchecked(i);
  48030. for (int j = 0; j < cm->keypresses.size(); ++j)
  48031. {
  48032. if (! containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48033. {
  48034. XmlElement* const map = doc->createNewChildElement ("UNMAPPING");
  48035. map->setAttribute ("commandId", String::toHexString ((int) cm->commandID));
  48036. map->setAttribute ("description", commandManager->getDescriptionOfCommand (cm->commandID));
  48037. map->setAttribute ("key", cm->keypresses.getReference (j).getTextDescription());
  48038. }
  48039. }
  48040. }
  48041. }
  48042. return doc;
  48043. }
  48044. bool KeyPressMappingSet::keyPressed (const KeyPress& key,
  48045. Component* originatingComponent)
  48046. {
  48047. bool used = false;
  48048. const CommandID commandID = findCommandForKeyPress (key);
  48049. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48050. if (ci != 0
  48051. && (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) == 0)
  48052. {
  48053. ApplicationCommandInfo info (0);
  48054. if (commandManager->getTargetForCommand (commandID, info) != 0
  48055. && (info.flags & ApplicationCommandInfo::isDisabled) == 0)
  48056. {
  48057. invokeCommand (commandID, key, true, 0, originatingComponent);
  48058. used = true;
  48059. }
  48060. else
  48061. {
  48062. if (originatingComponent != 0)
  48063. originatingComponent->getLookAndFeel().playAlertSound();
  48064. }
  48065. }
  48066. return used;
  48067. }
  48068. bool KeyPressMappingSet::keyStateChanged (const bool /*isKeyDown*/, Component* originatingComponent)
  48069. {
  48070. bool used = false;
  48071. const uint32 now = Time::getMillisecondCounter();
  48072. for (int i = mappings.size(); --i >= 0;)
  48073. {
  48074. CommandMapping* const cm = mappings.getUnchecked(i);
  48075. if (cm->wantsKeyUpDownCallbacks)
  48076. {
  48077. for (int j = cm->keypresses.size(); --j >= 0;)
  48078. {
  48079. const KeyPress key (cm->keypresses.getReference (j));
  48080. const bool isDown = key.isCurrentlyDown();
  48081. int keyPressEntryIndex = 0;
  48082. bool wasDown = false;
  48083. for (int k = keysDown.size(); --k >= 0;)
  48084. {
  48085. if (key == keysDown.getUnchecked(k)->key)
  48086. {
  48087. keyPressEntryIndex = k;
  48088. wasDown = true;
  48089. used = true;
  48090. break;
  48091. }
  48092. }
  48093. if (isDown != wasDown)
  48094. {
  48095. int millisecs = 0;
  48096. if (isDown)
  48097. {
  48098. KeyPressTime* const k = new KeyPressTime();
  48099. k->key = key;
  48100. k->timeWhenPressed = now;
  48101. keysDown.add (k);
  48102. }
  48103. else
  48104. {
  48105. const uint32 pressTime = keysDown.getUnchecked (keyPressEntryIndex)->timeWhenPressed;
  48106. if (now > pressTime)
  48107. millisecs = now - pressTime;
  48108. keysDown.remove (keyPressEntryIndex);
  48109. }
  48110. invokeCommand (cm->commandID, key, isDown, millisecs, originatingComponent);
  48111. used = true;
  48112. }
  48113. }
  48114. }
  48115. }
  48116. return used;
  48117. }
  48118. void KeyPressMappingSet::globalFocusChanged (Component* focusedComponent)
  48119. {
  48120. if (focusedComponent != 0)
  48121. focusedComponent->keyStateChanged (false);
  48122. }
  48123. END_JUCE_NAMESPACE
  48124. /*** End of inlined file: juce_KeyPressMappingSet.cpp ***/
  48125. /*** Start of inlined file: juce_ModifierKeys.cpp ***/
  48126. BEGIN_JUCE_NAMESPACE
  48127. ModifierKeys::ModifierKeys (const int flags_) throw()
  48128. : flags (flags_)
  48129. {
  48130. }
  48131. ModifierKeys::ModifierKeys (const ModifierKeys& other) throw()
  48132. : flags (other.flags)
  48133. {
  48134. }
  48135. ModifierKeys& ModifierKeys::operator= (const ModifierKeys& other) throw()
  48136. {
  48137. flags = other.flags;
  48138. return *this;
  48139. }
  48140. ModifierKeys ModifierKeys::currentModifiers;
  48141. const ModifierKeys ModifierKeys::getCurrentModifiers() throw()
  48142. {
  48143. return currentModifiers;
  48144. }
  48145. int ModifierKeys::getNumMouseButtonsDown() const throw()
  48146. {
  48147. int num = 0;
  48148. if (isLeftButtonDown()) ++num;
  48149. if (isRightButtonDown()) ++num;
  48150. if (isMiddleButtonDown()) ++num;
  48151. return num;
  48152. }
  48153. END_JUCE_NAMESPACE
  48154. /*** End of inlined file: juce_ModifierKeys.cpp ***/
  48155. /*** Start of inlined file: juce_ComponentAnimator.cpp ***/
  48156. BEGIN_JUCE_NAMESPACE
  48157. struct AnimationTask
  48158. {
  48159. AnimationTask (Component* const comp)
  48160. : component (comp)
  48161. {
  48162. }
  48163. Component::SafePointer<Component> component;
  48164. Rectangle<int> destination;
  48165. int msElapsed, msTotal;
  48166. double startSpeed, midSpeed, endSpeed, lastProgress;
  48167. double left, top, right, bottom;
  48168. bool useTimeslice (const int elapsed)
  48169. {
  48170. if (component == 0)
  48171. return false;
  48172. msElapsed += elapsed;
  48173. double newProgress = msElapsed / (double) msTotal;
  48174. if (newProgress >= 0 && newProgress < 1.0)
  48175. {
  48176. newProgress = timeToDistance (newProgress);
  48177. const double delta = (newProgress - lastProgress) / (1.0 - lastProgress);
  48178. jassert (newProgress >= lastProgress);
  48179. lastProgress = newProgress;
  48180. left += (destination.getX() - left) * delta;
  48181. top += (destination.getY() - top) * delta;
  48182. right += (destination.getRight() - right) * delta;
  48183. bottom += (destination.getBottom() - bottom) * delta;
  48184. if (delta < 1.0)
  48185. {
  48186. const Rectangle<int> newBounds (roundToInt (left),
  48187. roundToInt (top),
  48188. roundToInt (right - left),
  48189. roundToInt (bottom - top));
  48190. if (newBounds != destination)
  48191. {
  48192. component->setBounds (newBounds);
  48193. return true;
  48194. }
  48195. }
  48196. }
  48197. component->setBounds (destination);
  48198. return false;
  48199. }
  48200. void moveToFinalDestination()
  48201. {
  48202. if (component != 0)
  48203. component->setBounds (destination);
  48204. }
  48205. private:
  48206. inline double timeToDistance (const double time) const
  48207. {
  48208. return (time < 0.5) ? time * (startSpeed + time * (midSpeed - startSpeed))
  48209. : 0.5 * (startSpeed + 0.5 * (midSpeed - startSpeed))
  48210. + (time - 0.5) * (midSpeed + (time - 0.5) * (endSpeed - midSpeed));
  48211. }
  48212. };
  48213. ComponentAnimator::ComponentAnimator()
  48214. : lastTime (0)
  48215. {
  48216. }
  48217. ComponentAnimator::~ComponentAnimator()
  48218. {
  48219. cancelAllAnimations (false);
  48220. jassert (tasks.size() == 0);
  48221. }
  48222. void* ComponentAnimator::findTaskFor (Component* const component) const
  48223. {
  48224. for (int i = tasks.size(); --i >= 0;)
  48225. if (component == ((AnimationTask*) tasks.getUnchecked(i))->component.getComponent())
  48226. return tasks.getUnchecked(i);
  48227. return 0;
  48228. }
  48229. void ComponentAnimator::animateComponent (Component* const component,
  48230. const Rectangle<int>& finalPosition,
  48231. const int millisecondsToSpendMoving,
  48232. const double startSpeed,
  48233. const double endSpeed)
  48234. {
  48235. if (component != 0)
  48236. {
  48237. AnimationTask* at = (AnimationTask*) findTaskFor (component);
  48238. if (at == 0)
  48239. {
  48240. at = new AnimationTask (component);
  48241. tasks.add (at);
  48242. sendChangeMessage (this);
  48243. }
  48244. at->msElapsed = 0;
  48245. at->lastProgress = 0;
  48246. at->msTotal = jmax (1, millisecondsToSpendMoving);
  48247. at->destination = finalPosition;
  48248. // the speeds must be 0 or greater!
  48249. jassert (startSpeed >= 0 && endSpeed >= 0)
  48250. const double invTotalDistance = 4.0 / (startSpeed + endSpeed + 2.0);
  48251. at->startSpeed = jmax (0.0, startSpeed * invTotalDistance);
  48252. at->midSpeed = invTotalDistance;
  48253. at->endSpeed = jmax (0.0, endSpeed * invTotalDistance);
  48254. at->left = component->getX();
  48255. at->top = component->getY();
  48256. at->right = component->getRight();
  48257. at->bottom = component->getBottom();
  48258. if (! isTimerRunning())
  48259. {
  48260. lastTime = Time::getMillisecondCounter();
  48261. startTimer (1000 / 50);
  48262. }
  48263. }
  48264. }
  48265. void ComponentAnimator::cancelAllAnimations (const bool moveComponentsToTheirFinalPositions)
  48266. {
  48267. for (int i = tasks.size(); --i >= 0;)
  48268. {
  48269. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48270. if (moveComponentsToTheirFinalPositions)
  48271. at->moveToFinalDestination();
  48272. delete at;
  48273. tasks.remove (i);
  48274. sendChangeMessage (this);
  48275. }
  48276. }
  48277. void ComponentAnimator::cancelAnimation (Component* const component,
  48278. const bool moveComponentToItsFinalPosition)
  48279. {
  48280. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48281. if (at != 0)
  48282. {
  48283. if (moveComponentToItsFinalPosition)
  48284. at->moveToFinalDestination();
  48285. tasks.removeValue (at);
  48286. delete at;
  48287. sendChangeMessage (this);
  48288. }
  48289. }
  48290. const Rectangle<int> ComponentAnimator::getComponentDestination (Component* const component)
  48291. {
  48292. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48293. if (at != 0)
  48294. return at->destination;
  48295. else if (component != 0)
  48296. return component->getBounds();
  48297. return Rectangle<int>();
  48298. }
  48299. bool ComponentAnimator::isAnimating (Component* component) const
  48300. {
  48301. return findTaskFor (component) != 0;
  48302. }
  48303. void ComponentAnimator::timerCallback()
  48304. {
  48305. const uint32 timeNow = Time::getMillisecondCounter();
  48306. if (lastTime == 0 || lastTime == timeNow)
  48307. lastTime = timeNow;
  48308. const int elapsed = timeNow - lastTime;
  48309. for (int i = tasks.size(); --i >= 0;)
  48310. {
  48311. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48312. if (! at->useTimeslice (elapsed))
  48313. {
  48314. tasks.remove (i);
  48315. delete at;
  48316. sendChangeMessage (this);
  48317. }
  48318. }
  48319. lastTime = timeNow;
  48320. if (tasks.size() == 0)
  48321. stopTimer();
  48322. }
  48323. END_JUCE_NAMESPACE
  48324. /*** End of inlined file: juce_ComponentAnimator.cpp ***/
  48325. /*** Start of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  48326. BEGIN_JUCE_NAMESPACE
  48327. ComponentBoundsConstrainer::ComponentBoundsConstrainer() throw()
  48328. : minW (0),
  48329. maxW (0x3fffffff),
  48330. minH (0),
  48331. maxH (0x3fffffff),
  48332. minOffTop (0),
  48333. minOffLeft (0),
  48334. minOffBottom (0),
  48335. minOffRight (0),
  48336. aspectRatio (0.0)
  48337. {
  48338. }
  48339. ComponentBoundsConstrainer::~ComponentBoundsConstrainer()
  48340. {
  48341. }
  48342. void ComponentBoundsConstrainer::setMinimumWidth (const int minimumWidth) throw()
  48343. {
  48344. minW = minimumWidth;
  48345. }
  48346. void ComponentBoundsConstrainer::setMaximumWidth (const int maximumWidth) throw()
  48347. {
  48348. maxW = maximumWidth;
  48349. }
  48350. void ComponentBoundsConstrainer::setMinimumHeight (const int minimumHeight) throw()
  48351. {
  48352. minH = minimumHeight;
  48353. }
  48354. void ComponentBoundsConstrainer::setMaximumHeight (const int maximumHeight) throw()
  48355. {
  48356. maxH = maximumHeight;
  48357. }
  48358. void ComponentBoundsConstrainer::setMinimumSize (const int minimumWidth, const int minimumHeight) throw()
  48359. {
  48360. jassert (maxW >= minimumWidth);
  48361. jassert (maxH >= minimumHeight);
  48362. jassert (minimumWidth > 0 && minimumHeight > 0);
  48363. minW = minimumWidth;
  48364. minH = minimumHeight;
  48365. if (minW > maxW)
  48366. maxW = minW;
  48367. if (minH > maxH)
  48368. maxH = minH;
  48369. }
  48370. void ComponentBoundsConstrainer::setMaximumSize (const int maximumWidth, const int maximumHeight) throw()
  48371. {
  48372. jassert (maximumWidth >= minW);
  48373. jassert (maximumHeight >= minH);
  48374. jassert (maximumWidth > 0 && maximumHeight > 0);
  48375. maxW = jmax (minW, maximumWidth);
  48376. maxH = jmax (minH, maximumHeight);
  48377. }
  48378. void ComponentBoundsConstrainer::setSizeLimits (const int minimumWidth,
  48379. const int minimumHeight,
  48380. const int maximumWidth,
  48381. const int maximumHeight) throw()
  48382. {
  48383. jassert (maximumWidth >= minimumWidth);
  48384. jassert (maximumHeight >= minimumHeight);
  48385. jassert (maximumWidth > 0 && maximumHeight > 0);
  48386. jassert (minimumWidth > 0 && minimumHeight > 0);
  48387. minW = jmax (0, minimumWidth);
  48388. minH = jmax (0, minimumHeight);
  48389. maxW = jmax (minW, maximumWidth);
  48390. maxH = jmax (minH, maximumHeight);
  48391. }
  48392. void ComponentBoundsConstrainer::setMinimumOnscreenAmounts (const int minimumWhenOffTheTop,
  48393. const int minimumWhenOffTheLeft,
  48394. const int minimumWhenOffTheBottom,
  48395. const int minimumWhenOffTheRight) throw()
  48396. {
  48397. minOffTop = minimumWhenOffTheTop;
  48398. minOffLeft = minimumWhenOffTheLeft;
  48399. minOffBottom = minimumWhenOffTheBottom;
  48400. minOffRight = minimumWhenOffTheRight;
  48401. }
  48402. void ComponentBoundsConstrainer::setFixedAspectRatio (const double widthOverHeight) throw()
  48403. {
  48404. aspectRatio = jmax (0.0, widthOverHeight);
  48405. }
  48406. double ComponentBoundsConstrainer::getFixedAspectRatio() const throw()
  48407. {
  48408. return aspectRatio;
  48409. }
  48410. void ComponentBoundsConstrainer::setBoundsForComponent (Component* const component,
  48411. const Rectangle<int>& targetBounds,
  48412. const bool isStretchingTop,
  48413. const bool isStretchingLeft,
  48414. const bool isStretchingBottom,
  48415. const bool isStretchingRight)
  48416. {
  48417. jassert (component != 0);
  48418. Rectangle<int> limits, bounds (targetBounds);
  48419. BorderSize border;
  48420. Component* const parent = component->getParentComponent();
  48421. if (parent == 0)
  48422. {
  48423. ComponentPeer* peer = component->getPeer();
  48424. if (peer != 0)
  48425. border = peer->getFrameSize();
  48426. limits = Desktop::getInstance().getMonitorAreaContaining (bounds.getCentre());
  48427. }
  48428. else
  48429. {
  48430. limits.setSize (parent->getWidth(), parent->getHeight());
  48431. }
  48432. border.addTo (bounds);
  48433. checkBounds (bounds,
  48434. border.addedTo (component->getBounds()), limits,
  48435. isStretchingTop, isStretchingLeft,
  48436. isStretchingBottom, isStretchingRight);
  48437. border.subtractFrom (bounds);
  48438. applyBoundsToComponent (component, bounds);
  48439. }
  48440. void ComponentBoundsConstrainer::checkComponentBounds (Component* component)
  48441. {
  48442. setBoundsForComponent (component, component->getBounds(),
  48443. false, false, false, false);
  48444. }
  48445. void ComponentBoundsConstrainer::applyBoundsToComponent (Component* component,
  48446. const Rectangle<int>& bounds)
  48447. {
  48448. component->setBounds (bounds);
  48449. }
  48450. void ComponentBoundsConstrainer::resizeStart()
  48451. {
  48452. }
  48453. void ComponentBoundsConstrainer::resizeEnd()
  48454. {
  48455. }
  48456. void ComponentBoundsConstrainer::checkBounds (Rectangle<int>& bounds,
  48457. const Rectangle<int>& old,
  48458. const Rectangle<int>& limits,
  48459. const bool isStretchingTop,
  48460. const bool isStretchingLeft,
  48461. const bool isStretchingBottom,
  48462. const bool isStretchingRight)
  48463. {
  48464. int x = bounds.getX();
  48465. int y = bounds.getY();
  48466. int w = bounds.getWidth();
  48467. int h = bounds.getHeight();
  48468. // constrain the size if it's being stretched..
  48469. if (isStretchingLeft)
  48470. {
  48471. x = jlimit (old.getRight() - maxW, old.getRight() - minW, x);
  48472. w = old.getRight() - x;
  48473. }
  48474. if (isStretchingRight)
  48475. {
  48476. w = jlimit (minW, maxW, w);
  48477. }
  48478. if (isStretchingTop)
  48479. {
  48480. y = jlimit (old.getBottom() - maxH, old.getBottom() - minH, y);
  48481. h = old.getBottom() - y;
  48482. }
  48483. if (isStretchingBottom)
  48484. {
  48485. h = jlimit (minH, maxH, h);
  48486. }
  48487. // constrain the aspect ratio if one has been specified..
  48488. if (aspectRatio > 0.0 && w > 0 && h > 0)
  48489. {
  48490. bool adjustWidth;
  48491. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  48492. {
  48493. adjustWidth = true;
  48494. }
  48495. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  48496. {
  48497. adjustWidth = false;
  48498. }
  48499. else
  48500. {
  48501. const double oldRatio = (old.getHeight() > 0) ? fabs (old.getWidth() / (double) old.getHeight()) : 0.0;
  48502. const double newRatio = fabs (w / (double) h);
  48503. adjustWidth = (oldRatio > newRatio);
  48504. }
  48505. if (adjustWidth)
  48506. {
  48507. w = roundToInt (h * aspectRatio);
  48508. if (w > maxW || w < minW)
  48509. {
  48510. w = jlimit (minW, maxW, w);
  48511. h = roundToInt (w / aspectRatio);
  48512. }
  48513. }
  48514. else
  48515. {
  48516. h = roundToInt (w / aspectRatio);
  48517. if (h > maxH || h < minH)
  48518. {
  48519. h = jlimit (minH, maxH, h);
  48520. w = roundToInt (h * aspectRatio);
  48521. }
  48522. }
  48523. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  48524. {
  48525. x = old.getX() + (old.getWidth() - w) / 2;
  48526. }
  48527. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  48528. {
  48529. y = old.getY() + (old.getHeight() - h) / 2;
  48530. }
  48531. else
  48532. {
  48533. if (isStretchingLeft)
  48534. x = old.getRight() - w;
  48535. if (isStretchingTop)
  48536. y = old.getBottom() - h;
  48537. }
  48538. }
  48539. // ...and constrain the position if limits have been set for that.
  48540. if (minOffTop > 0 || minOffLeft > 0 || minOffBottom > 0 || minOffRight > 0)
  48541. {
  48542. if (minOffTop > 0)
  48543. {
  48544. const int limit = limits.getY() + jmin (minOffTop - h, 0);
  48545. if (y < limit)
  48546. {
  48547. if (isStretchingTop)
  48548. h -= (limit - y);
  48549. y = limit;
  48550. }
  48551. }
  48552. if (minOffLeft > 0)
  48553. {
  48554. const int limit = limits.getX() + jmin (minOffLeft - w, 0);
  48555. if (x < limit)
  48556. {
  48557. if (isStretchingLeft)
  48558. w -= (limit - x);
  48559. x = limit;
  48560. }
  48561. }
  48562. if (minOffBottom > 0)
  48563. {
  48564. const int limit = limits.getBottom() - jmin (minOffBottom, h);
  48565. if (y > limit)
  48566. {
  48567. if (isStretchingBottom)
  48568. h += (limit - y);
  48569. else
  48570. y = limit;
  48571. }
  48572. }
  48573. if (minOffRight > 0)
  48574. {
  48575. const int limit = limits.getRight() - jmin (minOffRight, w);
  48576. if (x > limit)
  48577. {
  48578. if (isStretchingRight)
  48579. w += (limit - x);
  48580. else
  48581. x = limit;
  48582. }
  48583. }
  48584. }
  48585. jassert (w >= 0 && h >= 0);
  48586. bounds = Rectangle<int> (x, y, w, h);
  48587. }
  48588. END_JUCE_NAMESPACE
  48589. /*** End of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  48590. /*** Start of inlined file: juce_ComponentMovementWatcher.cpp ***/
  48591. BEGIN_JUCE_NAMESPACE
  48592. ComponentMovementWatcher::ComponentMovementWatcher (Component* const component_)
  48593. : component (component_),
  48594. lastPeer (0),
  48595. reentrant (false)
  48596. {
  48597. jassert (component != 0); // can't use this with a null pointer..
  48598. component->addComponentListener (this);
  48599. registerWithParentComps();
  48600. }
  48601. ComponentMovementWatcher::~ComponentMovementWatcher()
  48602. {
  48603. component->removeComponentListener (this);
  48604. unregister();
  48605. }
  48606. void ComponentMovementWatcher::componentParentHierarchyChanged (Component&)
  48607. {
  48608. // agh! don't delete the target component without deleting this object first!
  48609. jassert (component != 0);
  48610. if (! reentrant)
  48611. {
  48612. reentrant = true;
  48613. ComponentPeer* const peer = component->getPeer();
  48614. if (peer != lastPeer)
  48615. {
  48616. componentPeerChanged();
  48617. if (component == 0)
  48618. return;
  48619. lastPeer = peer;
  48620. }
  48621. unregister();
  48622. registerWithParentComps();
  48623. reentrant = false;
  48624. componentMovedOrResized (*component, true, true);
  48625. }
  48626. }
  48627. void ComponentMovementWatcher::componentMovedOrResized (Component&, bool wasMoved, bool wasResized)
  48628. {
  48629. // agh! don't delete the target component without deleting this object first!
  48630. jassert (component != 0);
  48631. if (wasMoved)
  48632. {
  48633. const Point<int> pos (component->relativePositionToOtherComponent (component->getTopLevelComponent(), Point<int>()));
  48634. wasMoved = lastBounds.getPosition() != pos;
  48635. lastBounds.setPosition (pos);
  48636. }
  48637. wasResized = (lastBounds.getWidth() != component->getWidth() || lastBounds.getHeight() != component->getHeight());
  48638. lastBounds.setSize (component->getWidth(), component->getHeight());
  48639. if (wasMoved || wasResized)
  48640. componentMovedOrResized (wasMoved, wasResized);
  48641. }
  48642. void ComponentMovementWatcher::registerWithParentComps() throw()
  48643. {
  48644. Component* p = component->getParentComponent();
  48645. while (p != 0)
  48646. {
  48647. p->addComponentListener (this);
  48648. registeredParentComps.add (p);
  48649. p = p->getParentComponent();
  48650. }
  48651. }
  48652. void ComponentMovementWatcher::unregister() throw()
  48653. {
  48654. for (int i = registeredParentComps.size(); --i >= 0;)
  48655. ((Component*) registeredParentComps.getUnchecked(i))->removeComponentListener (this);
  48656. registeredParentComps.clear();
  48657. }
  48658. END_JUCE_NAMESPACE
  48659. /*** End of inlined file: juce_ComponentMovementWatcher.cpp ***/
  48660. /*** Start of inlined file: juce_GroupComponent.cpp ***/
  48661. BEGIN_JUCE_NAMESPACE
  48662. GroupComponent::GroupComponent (const String& componentName,
  48663. const String& labelText)
  48664. : Component (componentName),
  48665. text (labelText),
  48666. justification (Justification::left)
  48667. {
  48668. setInterceptsMouseClicks (false, true);
  48669. }
  48670. GroupComponent::~GroupComponent()
  48671. {
  48672. }
  48673. void GroupComponent::setText (const String& newText) throw()
  48674. {
  48675. if (text != newText)
  48676. {
  48677. text = newText;
  48678. repaint();
  48679. }
  48680. }
  48681. const String GroupComponent::getText() const throw()
  48682. {
  48683. return text;
  48684. }
  48685. void GroupComponent::setTextLabelPosition (const Justification& newJustification)
  48686. {
  48687. if (justification.getFlags() != newJustification.getFlags())
  48688. {
  48689. justification = newJustification;
  48690. repaint();
  48691. }
  48692. }
  48693. void GroupComponent::paint (Graphics& g)
  48694. {
  48695. getLookAndFeel()
  48696. .drawGroupComponentOutline (g, getWidth(), getHeight(),
  48697. text, justification,
  48698. *this);
  48699. }
  48700. void GroupComponent::enablementChanged()
  48701. {
  48702. repaint();
  48703. }
  48704. void GroupComponent::colourChanged()
  48705. {
  48706. repaint();
  48707. }
  48708. END_JUCE_NAMESPACE
  48709. /*** End of inlined file: juce_GroupComponent.cpp ***/
  48710. /*** Start of inlined file: juce_MultiDocumentPanel.cpp ***/
  48711. BEGIN_JUCE_NAMESPACE
  48712. MultiDocumentPanelWindow::MultiDocumentPanelWindow (const Colour& backgroundColour)
  48713. : DocumentWindow (String::empty, backgroundColour,
  48714. DocumentWindow::maximiseButton | DocumentWindow::closeButton, false)
  48715. {
  48716. }
  48717. MultiDocumentPanelWindow::~MultiDocumentPanelWindow()
  48718. {
  48719. }
  48720. void MultiDocumentPanelWindow::maximiseButtonPressed()
  48721. {
  48722. MultiDocumentPanel* const owner = getOwner();
  48723. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  48724. if (owner != 0)
  48725. owner->setLayoutMode (MultiDocumentPanel::MaximisedWindowsWithTabs);
  48726. }
  48727. void MultiDocumentPanelWindow::closeButtonPressed()
  48728. {
  48729. MultiDocumentPanel* const owner = getOwner();
  48730. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  48731. if (owner != 0)
  48732. owner->closeDocument (getContentComponent(), true);
  48733. }
  48734. void MultiDocumentPanelWindow::activeWindowStatusChanged()
  48735. {
  48736. DocumentWindow::activeWindowStatusChanged();
  48737. updateOrder();
  48738. }
  48739. void MultiDocumentPanelWindow::broughtToFront()
  48740. {
  48741. DocumentWindow::broughtToFront();
  48742. updateOrder();
  48743. }
  48744. void MultiDocumentPanelWindow::updateOrder()
  48745. {
  48746. MultiDocumentPanel* const owner = getOwner();
  48747. if (owner != 0)
  48748. owner->updateOrder();
  48749. }
  48750. MultiDocumentPanel* MultiDocumentPanelWindow::getOwner() const throw()
  48751. {
  48752. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  48753. return findParentComponentOfClass ((MultiDocumentPanel*) 0);
  48754. }
  48755. class MDITabbedComponentInternal : public TabbedComponent
  48756. {
  48757. public:
  48758. MDITabbedComponentInternal()
  48759. : TabbedComponent (TabbedButtonBar::TabsAtTop)
  48760. {
  48761. }
  48762. ~MDITabbedComponentInternal()
  48763. {
  48764. }
  48765. void currentTabChanged (const int, const String&)
  48766. {
  48767. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  48768. MultiDocumentPanel* const owner = findParentComponentOfClass ((MultiDocumentPanel*) 0);
  48769. if (owner != 0)
  48770. owner->updateOrder();
  48771. }
  48772. };
  48773. MultiDocumentPanel::MultiDocumentPanel()
  48774. : mode (MaximisedWindowsWithTabs),
  48775. tabComponent (0),
  48776. backgroundColour (Colours::lightblue),
  48777. maximumNumDocuments (0),
  48778. numDocsBeforeTabsUsed (0)
  48779. {
  48780. setOpaque (true);
  48781. }
  48782. MultiDocumentPanel::~MultiDocumentPanel()
  48783. {
  48784. closeAllDocuments (false);
  48785. }
  48786. static bool shouldDeleteComp (Component* const c)
  48787. {
  48788. return c->getProperties() ["mdiDocumentDelete_"];
  48789. }
  48790. bool MultiDocumentPanel::closeAllDocuments (const bool checkItsOkToCloseFirst)
  48791. {
  48792. while (components.size() > 0)
  48793. if (! closeDocument (components.getLast(), checkItsOkToCloseFirst))
  48794. return false;
  48795. return true;
  48796. }
  48797. MultiDocumentPanelWindow* MultiDocumentPanel::createNewDocumentWindow()
  48798. {
  48799. return new MultiDocumentPanelWindow (backgroundColour);
  48800. }
  48801. void MultiDocumentPanel::addWindow (Component* component)
  48802. {
  48803. MultiDocumentPanelWindow* const dw = createNewDocumentWindow();
  48804. dw->setResizable (true, false);
  48805. dw->setContentComponent (component, false, true);
  48806. dw->setName (component->getName());
  48807. const var bkg (component->getProperties() ["mdiDocumentBkg_"]);
  48808. dw->setBackgroundColour (bkg.isVoid() ? backgroundColour : Colour ((int) bkg));
  48809. int x = 4;
  48810. Component* const topComp = getChildComponent (getNumChildComponents() - 1);
  48811. if (topComp != 0 && topComp->getX() == x && topComp->getY() == x)
  48812. x += 16;
  48813. dw->setTopLeftPosition (x, x);
  48814. const var pos (component->getProperties() ["mdiDocumentPos_"]);
  48815. if (pos.toString().isNotEmpty())
  48816. dw->restoreWindowStateFromString (pos.toString());
  48817. addAndMakeVisible (dw);
  48818. dw->toFront (true);
  48819. }
  48820. bool MultiDocumentPanel::addDocument (Component* const component,
  48821. const Colour& docColour,
  48822. const bool deleteWhenRemoved)
  48823. {
  48824. // If you try passing a full DocumentWindow or ResizableWindow in here, you'll end up
  48825. // with a frame-within-a-frame! Just pass in the bare content component.
  48826. jassert (dynamic_cast <ResizableWindow*> (component) == 0);
  48827. if (component == 0 || (maximumNumDocuments > 0 && components.size() >= maximumNumDocuments))
  48828. return false;
  48829. components.add (component);
  48830. component->getProperties().set ("mdiDocumentDelete_", deleteWhenRemoved);
  48831. component->getProperties().set ("mdiDocumentBkg_", (int) docColour.getARGB());
  48832. component->addComponentListener (this);
  48833. if (mode == FloatingWindows)
  48834. {
  48835. if (isFullscreenWhenOneDocument())
  48836. {
  48837. if (components.size() == 1)
  48838. {
  48839. addAndMakeVisible (component);
  48840. }
  48841. else
  48842. {
  48843. if (components.size() == 2)
  48844. addWindow (components.getFirst());
  48845. addWindow (component);
  48846. }
  48847. }
  48848. else
  48849. {
  48850. addWindow (component);
  48851. }
  48852. }
  48853. else
  48854. {
  48855. if (tabComponent == 0 && components.size() > numDocsBeforeTabsUsed)
  48856. {
  48857. addAndMakeVisible (tabComponent = new MDITabbedComponentInternal());
  48858. Array <Component*> temp (components);
  48859. for (int i = 0; i < temp.size(); ++i)
  48860. tabComponent->addTab (temp[i]->getName(), docColour, temp[i], false);
  48861. resized();
  48862. }
  48863. else
  48864. {
  48865. if (tabComponent != 0)
  48866. tabComponent->addTab (component->getName(), docColour, component, false);
  48867. else
  48868. addAndMakeVisible (component);
  48869. }
  48870. setActiveDocument (component);
  48871. }
  48872. resized();
  48873. activeDocumentChanged();
  48874. return true;
  48875. }
  48876. bool MultiDocumentPanel::closeDocument (Component* component,
  48877. const bool checkItsOkToCloseFirst)
  48878. {
  48879. if (components.contains (component))
  48880. {
  48881. if (checkItsOkToCloseFirst && ! tryToCloseDocument (component))
  48882. return false;
  48883. component->removeComponentListener (this);
  48884. const bool shouldDelete = shouldDeleteComp (component);
  48885. component->getProperties().remove ("mdiDocumentDelete_");
  48886. component->getProperties().remove ("mdiDocumentBkg_");
  48887. if (mode == FloatingWindows)
  48888. {
  48889. for (int i = getNumChildComponents(); --i >= 0;)
  48890. {
  48891. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48892. if (dw != 0 && dw->getContentComponent() == component)
  48893. {
  48894. dw->setContentComponent (0, false);
  48895. delete dw;
  48896. break;
  48897. }
  48898. }
  48899. if (shouldDelete)
  48900. delete component;
  48901. components.removeValue (component);
  48902. if (isFullscreenWhenOneDocument() && components.size() == 1)
  48903. {
  48904. for (int i = getNumChildComponents(); --i >= 0;)
  48905. {
  48906. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48907. if (dw != 0)
  48908. {
  48909. dw->setContentComponent (0, false);
  48910. delete dw;
  48911. }
  48912. }
  48913. addAndMakeVisible (components.getFirst());
  48914. }
  48915. }
  48916. else
  48917. {
  48918. jassert (components.indexOf (component) >= 0);
  48919. if (tabComponent != 0)
  48920. {
  48921. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  48922. if (tabComponent->getTabContentComponent (i) == component)
  48923. tabComponent->removeTab (i);
  48924. }
  48925. else
  48926. {
  48927. removeChildComponent (component);
  48928. }
  48929. if (shouldDelete)
  48930. delete component;
  48931. if (tabComponent != 0 && tabComponent->getNumTabs() <= numDocsBeforeTabsUsed)
  48932. deleteAndZero (tabComponent);
  48933. components.removeValue (component);
  48934. if (components.size() > 0 && tabComponent == 0)
  48935. addAndMakeVisible (components.getFirst());
  48936. }
  48937. resized();
  48938. activeDocumentChanged();
  48939. }
  48940. else
  48941. {
  48942. jassertfalse
  48943. }
  48944. return true;
  48945. }
  48946. int MultiDocumentPanel::getNumDocuments() const throw()
  48947. {
  48948. return components.size();
  48949. }
  48950. Component* MultiDocumentPanel::getDocument (const int index) const throw()
  48951. {
  48952. return components [index];
  48953. }
  48954. Component* MultiDocumentPanel::getActiveDocument() const throw()
  48955. {
  48956. if (mode == FloatingWindows)
  48957. {
  48958. for (int i = getNumChildComponents(); --i >= 0;)
  48959. {
  48960. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48961. if (dw != 0 && dw->isActiveWindow())
  48962. return dw->getContentComponent();
  48963. }
  48964. }
  48965. return components.getLast();
  48966. }
  48967. void MultiDocumentPanel::setActiveDocument (Component* component)
  48968. {
  48969. if (mode == FloatingWindows)
  48970. {
  48971. component = getContainerComp (component);
  48972. if (component != 0)
  48973. component->toFront (true);
  48974. }
  48975. else if (tabComponent != 0)
  48976. {
  48977. jassert (components.indexOf (component) >= 0);
  48978. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  48979. {
  48980. if (tabComponent->getTabContentComponent (i) == component)
  48981. {
  48982. tabComponent->setCurrentTabIndex (i);
  48983. break;
  48984. }
  48985. }
  48986. }
  48987. else
  48988. {
  48989. component->grabKeyboardFocus();
  48990. }
  48991. }
  48992. void MultiDocumentPanel::activeDocumentChanged()
  48993. {
  48994. }
  48995. void MultiDocumentPanel::setMaximumNumDocuments (const int newNumber)
  48996. {
  48997. maximumNumDocuments = newNumber;
  48998. }
  48999. void MultiDocumentPanel::useFullscreenWhenOneDocument (const bool shouldUseTabs)
  49000. {
  49001. numDocsBeforeTabsUsed = shouldUseTabs ? 1 : 0;
  49002. }
  49003. bool MultiDocumentPanel::isFullscreenWhenOneDocument() const throw()
  49004. {
  49005. return numDocsBeforeTabsUsed != 0;
  49006. }
  49007. void MultiDocumentPanel::setLayoutMode (const LayoutMode newLayoutMode)
  49008. {
  49009. if (mode != newLayoutMode)
  49010. {
  49011. mode = newLayoutMode;
  49012. if (mode == FloatingWindows)
  49013. {
  49014. deleteAndZero (tabComponent);
  49015. }
  49016. else
  49017. {
  49018. for (int i = getNumChildComponents(); --i >= 0;)
  49019. {
  49020. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49021. if (dw != 0)
  49022. {
  49023. dw->getContentComponent()->getProperties().set ("mdiDocumentPos_", dw->getWindowStateAsString());
  49024. dw->setContentComponent (0, false);
  49025. delete dw;
  49026. }
  49027. }
  49028. }
  49029. resized();
  49030. const Array <Component*> tempComps (components);
  49031. components.clear();
  49032. for (int i = 0; i < tempComps.size(); ++i)
  49033. {
  49034. Component* const c = tempComps.getUnchecked(i);
  49035. addDocument (c,
  49036. Colour ((int) c->getProperties().getWithDefault ("mdiDocumentBkg_", (int) Colours::white.getARGB())),
  49037. shouldDeleteComp (c));
  49038. }
  49039. }
  49040. }
  49041. void MultiDocumentPanel::setBackgroundColour (const Colour& newBackgroundColour)
  49042. {
  49043. if (backgroundColour != newBackgroundColour)
  49044. {
  49045. backgroundColour = newBackgroundColour;
  49046. setOpaque (newBackgroundColour.isOpaque());
  49047. repaint();
  49048. }
  49049. }
  49050. void MultiDocumentPanel::paint (Graphics& g)
  49051. {
  49052. g.fillAll (backgroundColour);
  49053. }
  49054. void MultiDocumentPanel::resized()
  49055. {
  49056. if (mode == MaximisedWindowsWithTabs || components.size() == numDocsBeforeTabsUsed)
  49057. {
  49058. for (int i = getNumChildComponents(); --i >= 0;)
  49059. getChildComponent (i)->setBounds (0, 0, getWidth(), getHeight());
  49060. }
  49061. setWantsKeyboardFocus (components.size() == 0);
  49062. }
  49063. Component* MultiDocumentPanel::getContainerComp (Component* c) const
  49064. {
  49065. if (mode == FloatingWindows)
  49066. {
  49067. for (int i = 0; i < getNumChildComponents(); ++i)
  49068. {
  49069. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49070. if (dw != 0 && dw->getContentComponent() == c)
  49071. {
  49072. c = dw;
  49073. break;
  49074. }
  49075. }
  49076. }
  49077. return c;
  49078. }
  49079. void MultiDocumentPanel::componentNameChanged (Component&)
  49080. {
  49081. if (mode == FloatingWindows)
  49082. {
  49083. for (int i = 0; i < getNumChildComponents(); ++i)
  49084. {
  49085. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49086. if (dw != 0)
  49087. dw->setName (dw->getContentComponent()->getName());
  49088. }
  49089. }
  49090. else if (tabComponent != 0)
  49091. {
  49092. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49093. tabComponent->setTabName (i, tabComponent->getTabContentComponent (i)->getName());
  49094. }
  49095. }
  49096. void MultiDocumentPanel::updateOrder()
  49097. {
  49098. const Array <Component*> oldList (components);
  49099. if (mode == FloatingWindows)
  49100. {
  49101. components.clear();
  49102. for (int i = 0; i < getNumChildComponents(); ++i)
  49103. {
  49104. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49105. if (dw != 0)
  49106. components.add (dw->getContentComponent());
  49107. }
  49108. }
  49109. else
  49110. {
  49111. if (tabComponent != 0)
  49112. {
  49113. Component* const current = tabComponent->getCurrentContentComponent();
  49114. if (current != 0)
  49115. {
  49116. components.removeValue (current);
  49117. components.add (current);
  49118. }
  49119. }
  49120. }
  49121. if (components != oldList)
  49122. activeDocumentChanged();
  49123. }
  49124. END_JUCE_NAMESPACE
  49125. /*** End of inlined file: juce_MultiDocumentPanel.cpp ***/
  49126. /*** Start of inlined file: juce_ResizableBorderComponent.cpp ***/
  49127. BEGIN_JUCE_NAMESPACE
  49128. enum ResizableBorderComponentZones
  49129. {
  49130. zoneL = 1,
  49131. zoneR = 2,
  49132. zoneT = 4,
  49133. zoneB = 8
  49134. };
  49135. ResizableBorderComponent::ResizableBorderComponent (Component* const componentToResize,
  49136. ComponentBoundsConstrainer* const constrainer_)
  49137. : component (componentToResize),
  49138. constrainer (constrainer_),
  49139. borderSize (5),
  49140. mouseZone (0)
  49141. {
  49142. }
  49143. ResizableBorderComponent::~ResizableBorderComponent()
  49144. {
  49145. }
  49146. void ResizableBorderComponent::paint (Graphics& g)
  49147. {
  49148. getLookAndFeel().drawResizableFrame (g, getWidth(), getHeight(), borderSize);
  49149. }
  49150. void ResizableBorderComponent::mouseEnter (const MouseEvent& e)
  49151. {
  49152. updateMouseZone (e);
  49153. }
  49154. void ResizableBorderComponent::mouseMove (const MouseEvent& e)
  49155. {
  49156. updateMouseZone (e);
  49157. }
  49158. void ResizableBorderComponent::mouseDown (const MouseEvent& e)
  49159. {
  49160. if (component == 0)
  49161. {
  49162. jassertfalse // You've deleted the component that this resizer was supposed to be using!
  49163. return;
  49164. }
  49165. updateMouseZone (e);
  49166. originalBounds = component->getBounds();
  49167. if (constrainer != 0)
  49168. constrainer->resizeStart();
  49169. }
  49170. void ResizableBorderComponent::mouseDrag (const MouseEvent& e)
  49171. {
  49172. if (component == 0)
  49173. {
  49174. jassertfalse // You've deleted the component that this resizer was supposed to be using!
  49175. return;
  49176. }
  49177. Rectangle<int> bounds (originalBounds);
  49178. if ((mouseZone & zoneL) != 0)
  49179. bounds.setLeft (bounds.getX() + e.getDistanceFromDragStartX());
  49180. if ((mouseZone & zoneT) != 0)
  49181. bounds.setTop (bounds.getY() + e.getDistanceFromDragStartY());
  49182. if ((mouseZone & zoneR) != 0)
  49183. bounds.setWidth (bounds.getWidth() + e.getDistanceFromDragStartX());
  49184. if ((mouseZone & zoneB) != 0)
  49185. bounds.setHeight (bounds.getHeight() + e.getDistanceFromDragStartY());
  49186. if (constrainer != 0)
  49187. constrainer->setBoundsForComponent (component, bounds,
  49188. (mouseZone & zoneT) != 0,
  49189. (mouseZone & zoneL) != 0,
  49190. (mouseZone & zoneB) != 0,
  49191. (mouseZone & zoneR) != 0);
  49192. else
  49193. component->setBounds (bounds);
  49194. }
  49195. void ResizableBorderComponent::mouseUp (const MouseEvent&)
  49196. {
  49197. if (constrainer != 0)
  49198. constrainer->resizeEnd();
  49199. }
  49200. bool ResizableBorderComponent::hitTest (int x, int y)
  49201. {
  49202. return x < borderSize.getLeft()
  49203. || x >= getWidth() - borderSize.getRight()
  49204. || y < borderSize.getTop()
  49205. || y >= getHeight() - borderSize.getBottom();
  49206. }
  49207. void ResizableBorderComponent::setBorderThickness (const BorderSize& newBorderSize)
  49208. {
  49209. if (borderSize != newBorderSize)
  49210. {
  49211. borderSize = newBorderSize;
  49212. repaint();
  49213. }
  49214. }
  49215. const BorderSize ResizableBorderComponent::getBorderThickness() const
  49216. {
  49217. return borderSize;
  49218. }
  49219. void ResizableBorderComponent::updateMouseZone (const MouseEvent& e)
  49220. {
  49221. int newZone = 0;
  49222. if (ResizableBorderComponent::hitTest (e.x, e.y))
  49223. {
  49224. if (e.x < jmax (borderSize.getLeft(),
  49225. proportionOfWidth (0.1f),
  49226. jmin (10, proportionOfWidth (0.33f))))
  49227. newZone |= zoneL;
  49228. else if (e.x >= jmin (getWidth() - borderSize.getRight(),
  49229. proportionOfWidth (0.9f),
  49230. getWidth() - jmin (10, proportionOfWidth (0.33f))))
  49231. newZone |= zoneR;
  49232. if (e.y < jmax (borderSize.getTop(),
  49233. proportionOfHeight (0.1f),
  49234. jmin (10, proportionOfHeight (0.33f))))
  49235. newZone |= zoneT;
  49236. else if (e.y >= jmin (getHeight() - borderSize.getBottom(),
  49237. proportionOfHeight (0.9f),
  49238. getHeight() - jmin (10, proportionOfHeight (0.33f))))
  49239. newZone |= zoneB;
  49240. }
  49241. if (mouseZone != newZone)
  49242. {
  49243. mouseZone = newZone;
  49244. MouseCursor::StandardCursorType mc = MouseCursor::NormalCursor;
  49245. switch (newZone)
  49246. {
  49247. case (zoneL | zoneT): mc = MouseCursor::TopLeftCornerResizeCursor; break;
  49248. case zoneT: mc = MouseCursor::TopEdgeResizeCursor; break;
  49249. case (zoneR | zoneT): mc = MouseCursor::TopRightCornerResizeCursor; break;
  49250. case zoneL: mc = MouseCursor::LeftEdgeResizeCursor; break;
  49251. case zoneR: mc = MouseCursor::RightEdgeResizeCursor; break;
  49252. case (zoneL | zoneB): mc = MouseCursor::BottomLeftCornerResizeCursor; break;
  49253. case zoneB: mc = MouseCursor::BottomEdgeResizeCursor; break;
  49254. case (zoneR | zoneB): mc = MouseCursor::BottomRightCornerResizeCursor; break;
  49255. default: break;
  49256. }
  49257. setMouseCursor (mc);
  49258. }
  49259. }
  49260. END_JUCE_NAMESPACE
  49261. /*** End of inlined file: juce_ResizableBorderComponent.cpp ***/
  49262. /*** Start of inlined file: juce_ResizableCornerComponent.cpp ***/
  49263. BEGIN_JUCE_NAMESPACE
  49264. ResizableCornerComponent::ResizableCornerComponent (Component* const componentToResize,
  49265. ComponentBoundsConstrainer* const constrainer_)
  49266. : component (componentToResize),
  49267. constrainer (constrainer_)
  49268. {
  49269. setRepaintsOnMouseActivity (true);
  49270. setMouseCursor (MouseCursor::BottomRightCornerResizeCursor);
  49271. }
  49272. ResizableCornerComponent::~ResizableCornerComponent()
  49273. {
  49274. }
  49275. void ResizableCornerComponent::paint (Graphics& g)
  49276. {
  49277. getLookAndFeel()
  49278. .drawCornerResizer (g, getWidth(), getHeight(),
  49279. isMouseOverOrDragging(),
  49280. isMouseButtonDown());
  49281. }
  49282. void ResizableCornerComponent::mouseDown (const MouseEvent&)
  49283. {
  49284. if (component == 0)
  49285. {
  49286. jassertfalse; // You've deleted the component that this resizer is supposed to be controlling!
  49287. return;
  49288. }
  49289. originalBounds = component->getBounds();
  49290. if (constrainer != 0)
  49291. constrainer->resizeStart();
  49292. }
  49293. void ResizableCornerComponent::mouseDrag (const MouseEvent& e)
  49294. {
  49295. if (component == 0)
  49296. {
  49297. jassertfalse; // You've deleted the component that this resizer is supposed to be controlling!
  49298. return;
  49299. }
  49300. Rectangle<int> r (originalBounds.withSize (originalBounds.getWidth() + e.getDistanceFromDragStartX(),
  49301. originalBounds.getHeight() + e.getDistanceFromDragStartY()));
  49302. if (constrainer != 0)
  49303. constrainer->setBoundsForComponent (component, r, false, false, true, true);
  49304. else
  49305. component->setBounds (r);
  49306. }
  49307. void ResizableCornerComponent::mouseUp (const MouseEvent&)
  49308. {
  49309. if (constrainer != 0)
  49310. constrainer->resizeStart();
  49311. }
  49312. bool ResizableCornerComponent::hitTest (int x, int y)
  49313. {
  49314. if (getWidth() <= 0)
  49315. return false;
  49316. const int yAtX = getHeight() - (getHeight() * x / getWidth());
  49317. return y >= yAtX - getHeight() / 4;
  49318. }
  49319. END_JUCE_NAMESPACE
  49320. /*** End of inlined file: juce_ResizableCornerComponent.cpp ***/
  49321. /*** Start of inlined file: juce_ScrollBar.cpp ***/
  49322. BEGIN_JUCE_NAMESPACE
  49323. class ScrollbarButton : public Button
  49324. {
  49325. public:
  49326. int direction;
  49327. ScrollbarButton (const int direction_,
  49328. ScrollBar& owner_) throw()
  49329. : Button (String::empty),
  49330. direction (direction_),
  49331. owner (owner_)
  49332. {
  49333. setWantsKeyboardFocus (false);
  49334. }
  49335. ~ScrollbarButton()
  49336. {
  49337. }
  49338. void paintButton (Graphics& g,
  49339. bool isMouseOver,
  49340. bool isMouseDown)
  49341. {
  49342. getLookAndFeel()
  49343. .drawScrollbarButton (g, owner,
  49344. getWidth(), getHeight(),
  49345. direction,
  49346. owner.isVertical(),
  49347. isMouseOver, isMouseDown);
  49348. }
  49349. void clicked()
  49350. {
  49351. owner.moveScrollbarInSteps ((direction == 1 || direction == 2) ? 1 : -1);
  49352. }
  49353. juce_UseDebuggingNewOperator
  49354. private:
  49355. ScrollBar& owner;
  49356. ScrollbarButton (const ScrollbarButton&);
  49357. ScrollbarButton& operator= (const ScrollbarButton&);
  49358. };
  49359. ScrollBar::ScrollBar (const bool vertical_,
  49360. const bool buttonsAreVisible)
  49361. : minimum (0.0),
  49362. maximum (1.0),
  49363. rangeStart (0.0),
  49364. rangeSize (0.1),
  49365. singleStepSize (0.1),
  49366. thumbAreaStart (0),
  49367. thumbAreaSize (0),
  49368. thumbStart (0),
  49369. thumbSize (0),
  49370. initialDelayInMillisecs (100),
  49371. repeatDelayInMillisecs (50),
  49372. minimumDelayInMillisecs (10),
  49373. vertical (vertical_),
  49374. isDraggingThumb (false),
  49375. alwaysVisible (false),
  49376. upButton (0),
  49377. downButton (0)
  49378. {
  49379. setButtonVisibility (buttonsAreVisible);
  49380. setRepaintsOnMouseActivity (true);
  49381. setFocusContainer (true);
  49382. }
  49383. ScrollBar::~ScrollBar()
  49384. {
  49385. deleteAllChildren();
  49386. }
  49387. void ScrollBar::setRangeLimits (const double newMinimum,
  49388. const double newMaximum) throw()
  49389. {
  49390. minimum = newMinimum;
  49391. maximum = newMaximum;
  49392. jassert (maximum >= minimum); // these can't be the wrong way round!
  49393. setCurrentRangeStart (rangeStart);
  49394. updateThumbPosition();
  49395. }
  49396. void ScrollBar::setCurrentRange (double newStart,
  49397. double newSize) throw()
  49398. {
  49399. newSize = jlimit (0.0, maximum - minimum, newSize);
  49400. newStart = jlimit (minimum, maximum - newSize, newStart);
  49401. if (rangeStart != newStart
  49402. || rangeSize != newSize)
  49403. {
  49404. rangeStart = newStart;
  49405. rangeSize = newSize;
  49406. updateThumbPosition();
  49407. triggerAsyncUpdate();
  49408. }
  49409. }
  49410. void ScrollBar::setCurrentRangeStart (double newStart) throw()
  49411. {
  49412. setCurrentRange (newStart, rangeSize);
  49413. }
  49414. void ScrollBar::setSingleStepSize (const double newSingleStepSize) throw()
  49415. {
  49416. singleStepSize = newSingleStepSize;
  49417. }
  49418. void ScrollBar::moveScrollbarInSteps (const int howManySteps) throw()
  49419. {
  49420. setCurrentRangeStart (rangeStart + howManySteps * singleStepSize);
  49421. }
  49422. void ScrollBar::moveScrollbarInPages (const int howManyPages) throw()
  49423. {
  49424. setCurrentRangeStart (rangeStart + howManyPages * rangeSize);
  49425. }
  49426. void ScrollBar::scrollToTop() throw()
  49427. {
  49428. setCurrentRangeStart (minimum);
  49429. }
  49430. void ScrollBar::scrollToBottom() throw()
  49431. {
  49432. setCurrentRangeStart (maximum - rangeSize);
  49433. }
  49434. void ScrollBar::setButtonRepeatSpeed (const int initialDelayInMillisecs_,
  49435. const int repeatDelayInMillisecs_,
  49436. const int minimumDelayInMillisecs_) throw()
  49437. {
  49438. initialDelayInMillisecs = initialDelayInMillisecs_;
  49439. repeatDelayInMillisecs = repeatDelayInMillisecs_;
  49440. minimumDelayInMillisecs = minimumDelayInMillisecs_;
  49441. if (upButton != 0)
  49442. {
  49443. upButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49444. downButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49445. }
  49446. }
  49447. void ScrollBar::addListener (ScrollBarListener* const listener) throw()
  49448. {
  49449. listeners.add (listener);
  49450. }
  49451. void ScrollBar::removeListener (ScrollBarListener* const listener) throw()
  49452. {
  49453. listeners.remove (listener);
  49454. }
  49455. void ScrollBar::handleAsyncUpdate()
  49456. {
  49457. listeners.call (&ScrollBarListener::scrollBarMoved, this, rangeStart);
  49458. }
  49459. void ScrollBar::updateThumbPosition() throw()
  49460. {
  49461. int newThumbSize = roundToInt ((maximum > minimum) ? (rangeSize * thumbAreaSize) / (maximum - minimum)
  49462. : thumbAreaSize);
  49463. if (newThumbSize < getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49464. newThumbSize = jmin (getLookAndFeel().getMinimumScrollbarThumbSize (*this), thumbAreaSize - 1);
  49465. if (newThumbSize > thumbAreaSize)
  49466. newThumbSize = thumbAreaSize;
  49467. int newThumbStart = thumbAreaStart;
  49468. if (maximum - minimum > rangeSize)
  49469. newThumbStart += roundToInt (((rangeStart - minimum) * (thumbAreaSize - newThumbSize))
  49470. / ((maximum - minimum) - rangeSize));
  49471. setVisible (alwaysVisible || (maximum - minimum > rangeSize && rangeSize > 0.0));
  49472. if (thumbStart != newThumbStart || thumbSize != newThumbSize)
  49473. {
  49474. const int repaintStart = jmin (thumbStart, newThumbStart) - 4;
  49475. const int repaintSize = jmax (thumbStart + thumbSize, newThumbStart + newThumbSize) + 8 - repaintStart;
  49476. if (vertical)
  49477. repaint (0, repaintStart, getWidth(), repaintSize);
  49478. else
  49479. repaint (repaintStart, 0, repaintSize, getHeight());
  49480. thumbStart = newThumbStart;
  49481. thumbSize = newThumbSize;
  49482. }
  49483. }
  49484. void ScrollBar::setOrientation (const bool shouldBeVertical) throw()
  49485. {
  49486. if (vertical != shouldBeVertical)
  49487. {
  49488. vertical = shouldBeVertical;
  49489. if (upButton != 0)
  49490. {
  49491. ((ScrollbarButton*) upButton)->direction = (vertical) ? 0 : 3;
  49492. ((ScrollbarButton*) downButton)->direction = (vertical) ? 2 : 1;
  49493. }
  49494. updateThumbPosition();
  49495. }
  49496. }
  49497. void ScrollBar::setButtonVisibility (const bool buttonsAreVisible)
  49498. {
  49499. deleteAndZero (upButton);
  49500. deleteAndZero (downButton);
  49501. if (buttonsAreVisible)
  49502. {
  49503. addAndMakeVisible (upButton = new ScrollbarButton ((vertical) ? 0 : 3, *this));
  49504. addAndMakeVisible (downButton = new ScrollbarButton ((vertical) ? 2 : 1, *this));
  49505. setButtonRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49506. }
  49507. updateThumbPosition();
  49508. }
  49509. void ScrollBar::setAutoHide (const bool shouldHideWhenFullRange)
  49510. {
  49511. alwaysVisible = ! shouldHideWhenFullRange;
  49512. updateThumbPosition();
  49513. }
  49514. void ScrollBar::paint (Graphics& g)
  49515. {
  49516. if (thumbAreaSize > 0)
  49517. {
  49518. LookAndFeel& lf = getLookAndFeel();
  49519. const int thumb = (thumbAreaSize > lf.getMinimumScrollbarThumbSize (*this))
  49520. ? thumbSize : 0;
  49521. if (vertical)
  49522. {
  49523. lf.drawScrollbar (g, *this,
  49524. 0, thumbAreaStart,
  49525. getWidth(), thumbAreaSize,
  49526. vertical,
  49527. thumbStart, thumb,
  49528. isMouseOver(), isMouseButtonDown());
  49529. }
  49530. else
  49531. {
  49532. lf.drawScrollbar (g, *this,
  49533. thumbAreaStart, 0,
  49534. thumbAreaSize, getHeight(),
  49535. vertical,
  49536. thumbStart, thumb,
  49537. isMouseOver(), isMouseButtonDown());
  49538. }
  49539. }
  49540. }
  49541. void ScrollBar::lookAndFeelChanged()
  49542. {
  49543. setComponentEffect (getLookAndFeel().getScrollbarEffect());
  49544. }
  49545. void ScrollBar::resized()
  49546. {
  49547. const int length = ((vertical) ? getHeight() : getWidth());
  49548. const int buttonSize = (upButton != 0) ? jmin (getLookAndFeel().getScrollbarButtonSize (*this), (length >> 1))
  49549. : 0;
  49550. if (length < 32 + getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49551. {
  49552. thumbAreaStart = length >> 1;
  49553. thumbAreaSize = 0;
  49554. }
  49555. else
  49556. {
  49557. thumbAreaStart = buttonSize;
  49558. thumbAreaSize = length - (buttonSize << 1);
  49559. }
  49560. if (upButton != 0)
  49561. {
  49562. if (vertical)
  49563. {
  49564. upButton->setBounds (0, 0, getWidth(), buttonSize);
  49565. downButton->setBounds (0, thumbAreaStart + thumbAreaSize, getWidth(), buttonSize);
  49566. }
  49567. else
  49568. {
  49569. upButton->setBounds (0, 0, buttonSize, getHeight());
  49570. downButton->setBounds (thumbAreaStart + thumbAreaSize, 0, buttonSize, getHeight());
  49571. }
  49572. }
  49573. updateThumbPosition();
  49574. }
  49575. void ScrollBar::mouseDown (const MouseEvent& e)
  49576. {
  49577. isDraggingThumb = false;
  49578. lastMousePos = vertical ? e.y : e.x;
  49579. dragStartMousePos = lastMousePos;
  49580. dragStartRange = rangeStart;
  49581. if (dragStartMousePos < thumbStart)
  49582. {
  49583. moveScrollbarInPages (-1);
  49584. startTimer (400);
  49585. }
  49586. else if (dragStartMousePos >= thumbStart + thumbSize)
  49587. {
  49588. moveScrollbarInPages (1);
  49589. startTimer (400);
  49590. }
  49591. else
  49592. {
  49593. isDraggingThumb = (thumbAreaSize > getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49594. && (thumbAreaSize > thumbSize);
  49595. }
  49596. }
  49597. void ScrollBar::mouseDrag (const MouseEvent& e)
  49598. {
  49599. if (isDraggingThumb)
  49600. {
  49601. const int deltaPixels = ((vertical) ? e.y : e.x) - dragStartMousePos;
  49602. setCurrentRangeStart (dragStartRange
  49603. + deltaPixels * ((maximum - minimum) - rangeSize)
  49604. / (thumbAreaSize - thumbSize));
  49605. }
  49606. else
  49607. {
  49608. lastMousePos = (vertical) ? e.y : e.x;
  49609. }
  49610. }
  49611. void ScrollBar::mouseUp (const MouseEvent&)
  49612. {
  49613. isDraggingThumb = false;
  49614. stopTimer();
  49615. repaint();
  49616. }
  49617. void ScrollBar::mouseWheelMove (const MouseEvent&,
  49618. float wheelIncrementX,
  49619. float wheelIncrementY)
  49620. {
  49621. float increment = vertical ? wheelIncrementY : wheelIncrementX;
  49622. if (increment < 0)
  49623. increment = jmin (increment * 10.0f, -1.0f);
  49624. else if (increment > 0)
  49625. increment = jmax (increment * 10.0f, 1.0f);
  49626. setCurrentRangeStart (rangeStart - singleStepSize * increment);
  49627. }
  49628. void ScrollBar::timerCallback()
  49629. {
  49630. if (isMouseButtonDown())
  49631. {
  49632. startTimer (40);
  49633. if (lastMousePos < thumbStart)
  49634. setCurrentRangeStart (rangeStart - rangeSize);
  49635. else if (lastMousePos > thumbStart + thumbSize)
  49636. setCurrentRangeStart (rangeStart + rangeSize);
  49637. }
  49638. else
  49639. {
  49640. stopTimer();
  49641. }
  49642. }
  49643. bool ScrollBar::keyPressed (const KeyPress& key)
  49644. {
  49645. if (! isVisible())
  49646. return false;
  49647. if (key.isKeyCode (KeyPress::upKey) || key.isKeyCode (KeyPress::leftKey))
  49648. moveScrollbarInSteps (-1);
  49649. else if (key.isKeyCode (KeyPress::downKey) || key.isKeyCode (KeyPress::rightKey))
  49650. moveScrollbarInSteps (1);
  49651. else if (key.isKeyCode (KeyPress::pageUpKey))
  49652. moveScrollbarInPages (-1);
  49653. else if (key.isKeyCode (KeyPress::pageDownKey))
  49654. moveScrollbarInPages (1);
  49655. else if (key.isKeyCode (KeyPress::homeKey))
  49656. scrollToTop();
  49657. else if (key.isKeyCode (KeyPress::endKey))
  49658. scrollToBottom();
  49659. else
  49660. return false;
  49661. return true;
  49662. }
  49663. END_JUCE_NAMESPACE
  49664. /*** End of inlined file: juce_ScrollBar.cpp ***/
  49665. /*** Start of inlined file: juce_StretchableLayoutManager.cpp ***/
  49666. BEGIN_JUCE_NAMESPACE
  49667. StretchableLayoutManager::StretchableLayoutManager()
  49668. : totalSize (0)
  49669. {
  49670. }
  49671. StretchableLayoutManager::~StretchableLayoutManager()
  49672. {
  49673. }
  49674. void StretchableLayoutManager::clearAllItems()
  49675. {
  49676. items.clear();
  49677. totalSize = 0;
  49678. }
  49679. void StretchableLayoutManager::setItemLayout (const int itemIndex,
  49680. const double minimumSize,
  49681. const double maximumSize,
  49682. const double preferredSize)
  49683. {
  49684. ItemLayoutProperties* layout = getInfoFor (itemIndex);
  49685. if (layout == 0)
  49686. {
  49687. layout = new ItemLayoutProperties();
  49688. layout->itemIndex = itemIndex;
  49689. int i;
  49690. for (i = 0; i < items.size(); ++i)
  49691. if (items.getUnchecked (i)->itemIndex > itemIndex)
  49692. break;
  49693. items.insert (i, layout);
  49694. }
  49695. layout->minSize = minimumSize;
  49696. layout->maxSize = maximumSize;
  49697. layout->preferredSize = preferredSize;
  49698. layout->currentSize = 0;
  49699. }
  49700. bool StretchableLayoutManager::getItemLayout (const int itemIndex,
  49701. double& minimumSize,
  49702. double& maximumSize,
  49703. double& preferredSize) const
  49704. {
  49705. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49706. if (layout != 0)
  49707. {
  49708. minimumSize = layout->minSize;
  49709. maximumSize = layout->maxSize;
  49710. preferredSize = layout->preferredSize;
  49711. return true;
  49712. }
  49713. return false;
  49714. }
  49715. void StretchableLayoutManager::setTotalSize (const int newTotalSize)
  49716. {
  49717. totalSize = newTotalSize;
  49718. fitComponentsIntoSpace (0, items.size(), totalSize, 0);
  49719. }
  49720. int StretchableLayoutManager::getItemCurrentPosition (const int itemIndex) const
  49721. {
  49722. int pos = 0;
  49723. for (int i = 0; i < itemIndex; ++i)
  49724. {
  49725. const ItemLayoutProperties* const layout = getInfoFor (i);
  49726. if (layout != 0)
  49727. pos += layout->currentSize;
  49728. }
  49729. return pos;
  49730. }
  49731. int StretchableLayoutManager::getItemCurrentAbsoluteSize (const int itemIndex) const
  49732. {
  49733. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49734. if (layout != 0)
  49735. return layout->currentSize;
  49736. return 0;
  49737. }
  49738. double StretchableLayoutManager::getItemCurrentRelativeSize (const int itemIndex) const
  49739. {
  49740. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49741. if (layout != 0)
  49742. return -layout->currentSize / (double) totalSize;
  49743. return 0;
  49744. }
  49745. void StretchableLayoutManager::setItemPosition (const int itemIndex,
  49746. int newPosition)
  49747. {
  49748. for (int i = items.size(); --i >= 0;)
  49749. {
  49750. const ItemLayoutProperties* const layout = items.getUnchecked(i);
  49751. if (layout->itemIndex == itemIndex)
  49752. {
  49753. int realTotalSize = jmax (totalSize, getMinimumSizeOfItems (0, items.size()));
  49754. const int minSizeAfterThisComp = getMinimumSizeOfItems (i, items.size());
  49755. const int maxSizeAfterThisComp = getMaximumSizeOfItems (i + 1, items.size());
  49756. newPosition = jmax (newPosition, totalSize - maxSizeAfterThisComp - layout->currentSize);
  49757. newPosition = jmin (newPosition, realTotalSize - minSizeAfterThisComp);
  49758. int endPos = fitComponentsIntoSpace (0, i, newPosition, 0);
  49759. endPos += layout->currentSize;
  49760. fitComponentsIntoSpace (i + 1, items.size(), totalSize - endPos, endPos);
  49761. updatePrefSizesToMatchCurrentPositions();
  49762. break;
  49763. }
  49764. }
  49765. }
  49766. void StretchableLayoutManager::layOutComponents (Component** const components,
  49767. int numComponents,
  49768. int x, int y, int w, int h,
  49769. const bool vertically,
  49770. const bool resizeOtherDimension)
  49771. {
  49772. setTotalSize (vertically ? h : w);
  49773. int pos = vertically ? y : x;
  49774. for (int i = 0; i < numComponents; ++i)
  49775. {
  49776. const ItemLayoutProperties* const layout = getInfoFor (i);
  49777. if (layout != 0)
  49778. {
  49779. Component* const c = components[i];
  49780. if (c != 0)
  49781. {
  49782. if (i == numComponents - 1)
  49783. {
  49784. // if it's the last item, crop it to exactly fit the available space..
  49785. if (resizeOtherDimension)
  49786. {
  49787. if (vertically)
  49788. c->setBounds (x, pos, w, jmax (layout->currentSize, h - pos));
  49789. else
  49790. c->setBounds (pos, y, jmax (layout->currentSize, w - pos), h);
  49791. }
  49792. else
  49793. {
  49794. if (vertically)
  49795. c->setBounds (c->getX(), pos, c->getWidth(), jmax (layout->currentSize, h - pos));
  49796. else
  49797. c->setBounds (pos, c->getY(), jmax (layout->currentSize, w - pos), c->getHeight());
  49798. }
  49799. }
  49800. else
  49801. {
  49802. if (resizeOtherDimension)
  49803. {
  49804. if (vertically)
  49805. c->setBounds (x, pos, w, layout->currentSize);
  49806. else
  49807. c->setBounds (pos, y, layout->currentSize, h);
  49808. }
  49809. else
  49810. {
  49811. if (vertically)
  49812. c->setBounds (c->getX(), pos, c->getWidth(), layout->currentSize);
  49813. else
  49814. c->setBounds (pos, c->getY(), layout->currentSize, c->getHeight());
  49815. }
  49816. }
  49817. }
  49818. pos += layout->currentSize;
  49819. }
  49820. }
  49821. }
  49822. StretchableLayoutManager::ItemLayoutProperties* StretchableLayoutManager::getInfoFor (const int itemIndex) const
  49823. {
  49824. for (int i = items.size(); --i >= 0;)
  49825. if (items.getUnchecked(i)->itemIndex == itemIndex)
  49826. return items.getUnchecked(i);
  49827. return 0;
  49828. }
  49829. int StretchableLayoutManager::fitComponentsIntoSpace (const int startIndex,
  49830. const int endIndex,
  49831. const int availableSpace,
  49832. int startPos)
  49833. {
  49834. // calculate the total sizes
  49835. int i;
  49836. double totalIdealSize = 0.0;
  49837. int totalMinimums = 0;
  49838. for (i = startIndex; i < endIndex; ++i)
  49839. {
  49840. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49841. layout->currentSize = sizeToRealSize (layout->minSize, totalSize);
  49842. totalMinimums += layout->currentSize;
  49843. totalIdealSize += sizeToRealSize (layout->preferredSize, availableSpace);
  49844. }
  49845. if (totalIdealSize <= 0)
  49846. totalIdealSize = 1.0;
  49847. // now calc the best sizes..
  49848. int extraSpace = availableSpace - totalMinimums;
  49849. while (extraSpace > 0)
  49850. {
  49851. int numWantingMoreSpace = 0;
  49852. int numHavingTakenExtraSpace = 0;
  49853. // first figure out how many comps want a slice of the extra space..
  49854. for (i = startIndex; i < endIndex; ++i)
  49855. {
  49856. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49857. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  49858. const int bestSize = jlimit (layout->currentSize,
  49859. jmax (layout->currentSize,
  49860. sizeToRealSize (layout->maxSize, totalSize)),
  49861. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  49862. if (bestSize > layout->currentSize)
  49863. ++numWantingMoreSpace;
  49864. }
  49865. // ..share out the extra space..
  49866. for (i = startIndex; i < endIndex; ++i)
  49867. {
  49868. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49869. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  49870. int bestSize = jlimit (layout->currentSize,
  49871. jmax (layout->currentSize, sizeToRealSize (layout->maxSize, totalSize)),
  49872. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  49873. const int extraWanted = bestSize - layout->currentSize;
  49874. if (extraWanted > 0)
  49875. {
  49876. const int extraAllowed = jmin (extraWanted,
  49877. extraSpace / jmax (1, numWantingMoreSpace));
  49878. if (extraAllowed > 0)
  49879. {
  49880. ++numHavingTakenExtraSpace;
  49881. --numWantingMoreSpace;
  49882. layout->currentSize += extraAllowed;
  49883. extraSpace -= extraAllowed;
  49884. }
  49885. }
  49886. }
  49887. if (numHavingTakenExtraSpace <= 0)
  49888. break;
  49889. }
  49890. // ..and calculate the end position
  49891. for (i = startIndex; i < endIndex; ++i)
  49892. {
  49893. ItemLayoutProperties* const layout = items.getUnchecked(i);
  49894. startPos += layout->currentSize;
  49895. }
  49896. return startPos;
  49897. }
  49898. int StretchableLayoutManager::getMinimumSizeOfItems (const int startIndex,
  49899. const int endIndex) const
  49900. {
  49901. int totalMinimums = 0;
  49902. for (int i = startIndex; i < endIndex; ++i)
  49903. totalMinimums += sizeToRealSize (items.getUnchecked (i)->minSize, totalSize);
  49904. return totalMinimums;
  49905. }
  49906. int StretchableLayoutManager::getMaximumSizeOfItems (const int startIndex, const int endIndex) const
  49907. {
  49908. int totalMaximums = 0;
  49909. for (int i = startIndex; i < endIndex; ++i)
  49910. totalMaximums += sizeToRealSize (items.getUnchecked (i)->maxSize, totalSize);
  49911. return totalMaximums;
  49912. }
  49913. void StretchableLayoutManager::updatePrefSizesToMatchCurrentPositions()
  49914. {
  49915. for (int i = 0; i < items.size(); ++i)
  49916. {
  49917. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49918. layout->preferredSize
  49919. = (layout->preferredSize < 0) ? getItemCurrentRelativeSize (i)
  49920. : getItemCurrentAbsoluteSize (i);
  49921. }
  49922. }
  49923. int StretchableLayoutManager::sizeToRealSize (double size, int totalSpace)
  49924. {
  49925. if (size < 0)
  49926. size *= -totalSpace;
  49927. return roundToInt (size);
  49928. }
  49929. END_JUCE_NAMESPACE
  49930. /*** End of inlined file: juce_StretchableLayoutManager.cpp ***/
  49931. /*** Start of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  49932. BEGIN_JUCE_NAMESPACE
  49933. StretchableLayoutResizerBar::StretchableLayoutResizerBar (StretchableLayoutManager* layout_,
  49934. const int itemIndex_,
  49935. const bool isVertical_)
  49936. : layout (layout_),
  49937. itemIndex (itemIndex_),
  49938. isVertical (isVertical_)
  49939. {
  49940. setRepaintsOnMouseActivity (true);
  49941. setMouseCursor (MouseCursor (isVertical_ ? MouseCursor::LeftRightResizeCursor
  49942. : MouseCursor::UpDownResizeCursor));
  49943. }
  49944. StretchableLayoutResizerBar::~StretchableLayoutResizerBar()
  49945. {
  49946. }
  49947. void StretchableLayoutResizerBar::paint (Graphics& g)
  49948. {
  49949. getLookAndFeel().drawStretchableLayoutResizerBar (g,
  49950. getWidth(), getHeight(),
  49951. isVertical,
  49952. isMouseOver(),
  49953. isMouseButtonDown());
  49954. }
  49955. void StretchableLayoutResizerBar::mouseDown (const MouseEvent&)
  49956. {
  49957. mouseDownPos = layout->getItemCurrentPosition (itemIndex);
  49958. }
  49959. void StretchableLayoutResizerBar::mouseDrag (const MouseEvent& e)
  49960. {
  49961. const int desiredPos = mouseDownPos + (isVertical ? e.getDistanceFromDragStartX()
  49962. : e.getDistanceFromDragStartY());
  49963. layout->setItemPosition (itemIndex, desiredPos);
  49964. hasBeenMoved();
  49965. }
  49966. void StretchableLayoutResizerBar::hasBeenMoved()
  49967. {
  49968. if (getParentComponent() != 0)
  49969. getParentComponent()->resized();
  49970. }
  49971. END_JUCE_NAMESPACE
  49972. /*** End of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  49973. /*** Start of inlined file: juce_StretchableObjectResizer.cpp ***/
  49974. BEGIN_JUCE_NAMESPACE
  49975. StretchableObjectResizer::StretchableObjectResizer()
  49976. {
  49977. }
  49978. StretchableObjectResizer::~StretchableObjectResizer()
  49979. {
  49980. }
  49981. void StretchableObjectResizer::addItem (const double size,
  49982. const double minSize, const double maxSize,
  49983. const int order)
  49984. {
  49985. // the order must be >= 0 but less than the maximum integer value.
  49986. jassert (order >= 0 && order < std::numeric_limits<int>::max());
  49987. Item* const item = new Item();
  49988. item->size = size;
  49989. item->minSize = minSize;
  49990. item->maxSize = maxSize;
  49991. item->order = order;
  49992. items.add (item);
  49993. }
  49994. double StretchableObjectResizer::getItemSize (const int index) const throw()
  49995. {
  49996. const Item* const it = items [index];
  49997. return it != 0 ? it->size : 0;
  49998. }
  49999. void StretchableObjectResizer::resizeToFit (const double targetSize)
  50000. {
  50001. int order = 0;
  50002. for (;;)
  50003. {
  50004. double currentSize = 0;
  50005. double minSize = 0;
  50006. double maxSize = 0;
  50007. int nextHighestOrder = std::numeric_limits<int>::max();
  50008. for (int i = 0; i < items.size(); ++i)
  50009. {
  50010. const Item* const it = items.getUnchecked(i);
  50011. currentSize += it->size;
  50012. if (it->order <= order)
  50013. {
  50014. minSize += it->minSize;
  50015. maxSize += it->maxSize;
  50016. }
  50017. else
  50018. {
  50019. minSize += it->size;
  50020. maxSize += it->size;
  50021. nextHighestOrder = jmin (nextHighestOrder, it->order);
  50022. }
  50023. }
  50024. const double thisIterationTarget = jlimit (minSize, maxSize, targetSize);
  50025. if (thisIterationTarget >= currentSize)
  50026. {
  50027. const double availableExtraSpace = maxSize - currentSize;
  50028. const double targetAmountOfExtraSpace = thisIterationTarget - currentSize;
  50029. const double scale = targetAmountOfExtraSpace / availableExtraSpace;
  50030. for (int i = 0; i < items.size(); ++i)
  50031. {
  50032. Item* const it = items.getUnchecked(i);
  50033. if (it->order <= order)
  50034. it->size = jmin (it->maxSize, it->size + (it->maxSize - it->size) * scale);
  50035. }
  50036. }
  50037. else
  50038. {
  50039. const double amountOfSlack = currentSize - minSize;
  50040. const double targetAmountOfSlack = thisIterationTarget - minSize;
  50041. const double scale = targetAmountOfSlack / amountOfSlack;
  50042. for (int i = 0; i < items.size(); ++i)
  50043. {
  50044. Item* const it = items.getUnchecked(i);
  50045. if (it->order <= order)
  50046. it->size = jmax (it->minSize, it->minSize + (it->size - it->minSize) * scale);
  50047. }
  50048. }
  50049. if (nextHighestOrder < std::numeric_limits<int>::max())
  50050. order = nextHighestOrder;
  50051. else
  50052. break;
  50053. }
  50054. }
  50055. END_JUCE_NAMESPACE
  50056. /*** End of inlined file: juce_StretchableObjectResizer.cpp ***/
  50057. /*** Start of inlined file: juce_TabbedButtonBar.cpp ***/
  50058. BEGIN_JUCE_NAMESPACE
  50059. TabBarButton::TabBarButton (const String& name,
  50060. TabbedButtonBar* const owner_,
  50061. const int index)
  50062. : Button (name),
  50063. owner (owner_),
  50064. tabIndex (index),
  50065. overlapPixels (0)
  50066. {
  50067. shadow.setShadowProperties (2.2f, 0.7f, 0, 0);
  50068. setComponentEffect (&shadow);
  50069. setWantsKeyboardFocus (false);
  50070. }
  50071. TabBarButton::~TabBarButton()
  50072. {
  50073. }
  50074. void TabBarButton::paintButton (Graphics& g,
  50075. bool isMouseOverButton,
  50076. bool isButtonDown)
  50077. {
  50078. int x, y, w, h;
  50079. getActiveArea (x, y, w, h);
  50080. g.setOrigin (x, y);
  50081. getLookAndFeel()
  50082. .drawTabButton (g, w, h,
  50083. owner->getTabBackgroundColour (tabIndex),
  50084. tabIndex, getButtonText(), *this,
  50085. owner->getOrientation(),
  50086. isMouseOverButton, isButtonDown,
  50087. getToggleState());
  50088. }
  50089. void TabBarButton::clicked (const ModifierKeys& mods)
  50090. {
  50091. if (mods.isPopupMenu())
  50092. owner->popupMenuClickOnTab (tabIndex, getButtonText());
  50093. else
  50094. owner->setCurrentTabIndex (tabIndex);
  50095. }
  50096. bool TabBarButton::hitTest (int mx, int my)
  50097. {
  50098. int x, y, w, h;
  50099. getActiveArea (x, y, w, h);
  50100. if (owner->getOrientation() == TabbedButtonBar::TabsAtLeft
  50101. || owner->getOrientation() == TabbedButtonBar::TabsAtRight)
  50102. {
  50103. if (((unsigned int) mx) < (unsigned int) getWidth()
  50104. && my >= y + overlapPixels
  50105. && my < y + h - overlapPixels)
  50106. return true;
  50107. }
  50108. else
  50109. {
  50110. if (mx >= x + overlapPixels && mx < x + w - overlapPixels
  50111. && ((unsigned int) my) < (unsigned int) getHeight())
  50112. return true;
  50113. }
  50114. Path p;
  50115. getLookAndFeel()
  50116. .createTabButtonShape (p, w, h, tabIndex, getButtonText(), *this,
  50117. owner->getOrientation(),
  50118. false, false, getToggleState());
  50119. return p.contains ((float) (mx - x),
  50120. (float) (my - y));
  50121. }
  50122. int TabBarButton::getBestTabLength (const int depth)
  50123. {
  50124. return jlimit (depth * 2,
  50125. depth * 7,
  50126. getLookAndFeel().getTabButtonBestWidth (tabIndex, getButtonText(), depth, *this));
  50127. }
  50128. void TabBarButton::getActiveArea (int& x, int& y, int& w, int& h)
  50129. {
  50130. x = 0;
  50131. y = 0;
  50132. int r = getWidth();
  50133. int b = getHeight();
  50134. const int spaceAroundImage = getLookAndFeel().getTabButtonSpaceAroundImage();
  50135. if (owner->getOrientation() != TabbedButtonBar::TabsAtLeft)
  50136. r -= spaceAroundImage;
  50137. if (owner->getOrientation() != TabbedButtonBar::TabsAtRight)
  50138. x += spaceAroundImage;
  50139. if (owner->getOrientation() != TabbedButtonBar::TabsAtBottom)
  50140. y += spaceAroundImage;
  50141. if (owner->getOrientation() != TabbedButtonBar::TabsAtTop)
  50142. b -= spaceAroundImage;
  50143. w = r - x;
  50144. h = b - y;
  50145. }
  50146. class TabAreaBehindFrontButtonComponent : public Component
  50147. {
  50148. public:
  50149. TabAreaBehindFrontButtonComponent (TabbedButtonBar* const owner_)
  50150. : owner (owner_)
  50151. {
  50152. setInterceptsMouseClicks (false, false);
  50153. }
  50154. ~TabAreaBehindFrontButtonComponent()
  50155. {
  50156. }
  50157. void paint (Graphics& g)
  50158. {
  50159. getLookAndFeel()
  50160. .drawTabAreaBehindFrontButton (g, getWidth(), getHeight(),
  50161. *owner, owner->getOrientation());
  50162. }
  50163. void enablementChanged()
  50164. {
  50165. repaint();
  50166. }
  50167. private:
  50168. TabbedButtonBar* const owner;
  50169. TabAreaBehindFrontButtonComponent (const TabAreaBehindFrontButtonComponent&);
  50170. TabAreaBehindFrontButtonComponent& operator= (const TabAreaBehindFrontButtonComponent&);
  50171. };
  50172. TabbedButtonBar::TabbedButtonBar (const Orientation orientation_)
  50173. : orientation (orientation_),
  50174. currentTabIndex (-1),
  50175. extraTabsButton (0)
  50176. {
  50177. setInterceptsMouseClicks (false, true);
  50178. addAndMakeVisible (behindFrontTab = new TabAreaBehindFrontButtonComponent (this));
  50179. setFocusContainer (true);
  50180. }
  50181. TabbedButtonBar::~TabbedButtonBar()
  50182. {
  50183. deleteAllChildren();
  50184. }
  50185. void TabbedButtonBar::setOrientation (const Orientation newOrientation)
  50186. {
  50187. orientation = newOrientation;
  50188. for (int i = getNumChildComponents(); --i >= 0;)
  50189. getChildComponent (i)->resized();
  50190. resized();
  50191. }
  50192. TabBarButton* TabbedButtonBar::createTabButton (const String& name, const int index)
  50193. {
  50194. return new TabBarButton (name, this, index);
  50195. }
  50196. void TabbedButtonBar::clearTabs()
  50197. {
  50198. tabs.clear();
  50199. tabColours.clear();
  50200. currentTabIndex = -1;
  50201. deleteAndZero (extraTabsButton);
  50202. removeChildComponent (behindFrontTab);
  50203. deleteAllChildren();
  50204. addChildComponent (behindFrontTab);
  50205. setCurrentTabIndex (-1);
  50206. }
  50207. void TabbedButtonBar::addTab (const String& tabName,
  50208. const Colour& tabBackgroundColour,
  50209. int insertIndex)
  50210. {
  50211. jassert (tabName.isNotEmpty()); // you have to give them all a name..
  50212. if (tabName.isNotEmpty())
  50213. {
  50214. if (((unsigned int) insertIndex) > (unsigned int) tabs.size())
  50215. insertIndex = tabs.size();
  50216. for (int i = tabs.size(); --i >= insertIndex;)
  50217. {
  50218. TabBarButton* const tb = getTabButton (i);
  50219. if (tb != 0)
  50220. tb->tabIndex++;
  50221. }
  50222. tabs.insert (insertIndex, tabName);
  50223. tabColours.insert (insertIndex, tabBackgroundColour);
  50224. TabBarButton* const tb = createTabButton (tabName, insertIndex);
  50225. jassert (tb != 0); // your createTabButton() mustn't return zero!
  50226. addAndMakeVisible (tb, insertIndex);
  50227. resized();
  50228. if (currentTabIndex < 0)
  50229. setCurrentTabIndex (0);
  50230. }
  50231. }
  50232. void TabbedButtonBar::setTabName (const int tabIndex,
  50233. const String& newName)
  50234. {
  50235. if (((unsigned int) tabIndex) < (unsigned int) tabs.size()
  50236. && tabs[tabIndex] != newName)
  50237. {
  50238. tabs.set (tabIndex, newName);
  50239. TabBarButton* const tb = getTabButton (tabIndex);
  50240. if (tb != 0)
  50241. tb->setButtonText (newName);
  50242. resized();
  50243. }
  50244. }
  50245. void TabbedButtonBar::removeTab (const int tabIndex)
  50246. {
  50247. if (((unsigned int) tabIndex) < (unsigned int) tabs.size())
  50248. {
  50249. const int oldTabIndex = currentTabIndex;
  50250. if (currentTabIndex == tabIndex)
  50251. currentTabIndex = -1;
  50252. tabs.remove (tabIndex);
  50253. tabColours.remove (tabIndex);
  50254. delete getTabButton (tabIndex);
  50255. for (int i = tabIndex + 1; i <= tabs.size(); ++i)
  50256. {
  50257. TabBarButton* const tb = getTabButton (i);
  50258. if (tb != 0)
  50259. tb->tabIndex--;
  50260. }
  50261. resized();
  50262. setCurrentTabIndex (jlimit (0, jmax (0, tabs.size() - 1), oldTabIndex));
  50263. }
  50264. }
  50265. void TabbedButtonBar::moveTab (const int currentIndex,
  50266. const int newIndex)
  50267. {
  50268. tabs.move (currentIndex, newIndex);
  50269. tabColours.move (currentIndex, newIndex);
  50270. resized();
  50271. }
  50272. int TabbedButtonBar::getNumTabs() const
  50273. {
  50274. return tabs.size();
  50275. }
  50276. const StringArray TabbedButtonBar::getTabNames() const
  50277. {
  50278. return tabs;
  50279. }
  50280. void TabbedButtonBar::setCurrentTabIndex (int newIndex, const bool sendChangeMessage_)
  50281. {
  50282. if (currentTabIndex != newIndex)
  50283. {
  50284. if (((unsigned int) newIndex) >= (unsigned int) tabs.size())
  50285. newIndex = -1;
  50286. currentTabIndex = newIndex;
  50287. for (int i = 0; i < getNumChildComponents(); ++i)
  50288. {
  50289. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50290. if (tb != 0)
  50291. tb->setToggleState (tb->tabIndex == newIndex, false);
  50292. }
  50293. resized();
  50294. if (sendChangeMessage_)
  50295. sendChangeMessage (this);
  50296. currentTabChanged (newIndex, newIndex >= 0 ? tabs [newIndex] : String::empty);
  50297. }
  50298. }
  50299. TabBarButton* TabbedButtonBar::getTabButton (const int index) const
  50300. {
  50301. for (int i = getNumChildComponents(); --i >= 0;)
  50302. {
  50303. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50304. if (tb != 0 && tb->tabIndex == index)
  50305. return tb;
  50306. }
  50307. return 0;
  50308. }
  50309. void TabbedButtonBar::lookAndFeelChanged()
  50310. {
  50311. deleteAndZero (extraTabsButton);
  50312. resized();
  50313. }
  50314. void TabbedButtonBar::resized()
  50315. {
  50316. const double minimumScale = 0.7;
  50317. int depth = getWidth();
  50318. int length = getHeight();
  50319. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50320. swapVariables (depth, length);
  50321. const int overlap = getLookAndFeel().getTabButtonOverlap (depth)
  50322. + getLookAndFeel().getTabButtonSpaceAroundImage() * 2;
  50323. int i, totalLength = overlap;
  50324. int numVisibleButtons = tabs.size();
  50325. for (i = 0; i < getNumChildComponents(); ++i)
  50326. {
  50327. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50328. if (tb != 0)
  50329. {
  50330. totalLength += tb->getBestTabLength (depth) - overlap;
  50331. tb->overlapPixels = overlap / 2;
  50332. }
  50333. }
  50334. double scale = 1.0;
  50335. if (totalLength > length)
  50336. scale = jmax (minimumScale, length / (double) totalLength);
  50337. const bool isTooBig = totalLength * scale > length;
  50338. int tabsButtonPos = 0;
  50339. if (isTooBig)
  50340. {
  50341. if (extraTabsButton == 0)
  50342. {
  50343. addAndMakeVisible (extraTabsButton = getLookAndFeel().createTabBarExtrasButton());
  50344. extraTabsButton->addButtonListener (this);
  50345. extraTabsButton->setAlwaysOnTop (true);
  50346. extraTabsButton->setTriggeredOnMouseDown (true);
  50347. }
  50348. const int buttonSize = jmin (proportionOfWidth (0.7f), proportionOfHeight (0.7f));
  50349. extraTabsButton->setSize (buttonSize, buttonSize);
  50350. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50351. {
  50352. tabsButtonPos = getWidth() - buttonSize / 2 - 1;
  50353. extraTabsButton->setCentrePosition (tabsButtonPos, getHeight() / 2);
  50354. }
  50355. else
  50356. {
  50357. tabsButtonPos = getHeight() - buttonSize / 2 - 1;
  50358. extraTabsButton->setCentrePosition (getWidth() / 2, tabsButtonPos);
  50359. }
  50360. totalLength = 0;
  50361. for (i = 0; i < tabs.size(); ++i)
  50362. {
  50363. TabBarButton* const tb = getTabButton (i);
  50364. if (tb != 0)
  50365. {
  50366. const int newLength = totalLength + tb->getBestTabLength (depth);
  50367. if (i > 0 && newLength * minimumScale > tabsButtonPos)
  50368. {
  50369. totalLength += overlap;
  50370. break;
  50371. }
  50372. numVisibleButtons = i + 1;
  50373. totalLength = newLength - overlap;
  50374. }
  50375. }
  50376. scale = jmax (minimumScale, tabsButtonPos / (double) totalLength);
  50377. }
  50378. else
  50379. {
  50380. deleteAndZero (extraTabsButton);
  50381. }
  50382. int pos = 0;
  50383. TabBarButton* frontTab = 0;
  50384. for (i = 0; i < tabs.size(); ++i)
  50385. {
  50386. TabBarButton* const tb = getTabButton (i);
  50387. if (tb != 0)
  50388. {
  50389. const int bestLength = roundToInt (scale * tb->getBestTabLength (depth));
  50390. if (i < numVisibleButtons)
  50391. {
  50392. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50393. tb->setBounds (pos, 0, bestLength, getHeight());
  50394. else
  50395. tb->setBounds (0, pos, getWidth(), bestLength);
  50396. tb->toBack();
  50397. if (tb->tabIndex == currentTabIndex)
  50398. frontTab = tb;
  50399. tb->setVisible (true);
  50400. }
  50401. else
  50402. {
  50403. tb->setVisible (false);
  50404. }
  50405. pos += bestLength - overlap;
  50406. }
  50407. }
  50408. behindFrontTab->setBounds (0, 0, getWidth(), getHeight());
  50409. if (frontTab != 0)
  50410. {
  50411. frontTab->toFront (false);
  50412. behindFrontTab->toBehind (frontTab);
  50413. }
  50414. }
  50415. const Colour TabbedButtonBar::getTabBackgroundColour (const int tabIndex)
  50416. {
  50417. return tabColours [tabIndex];
  50418. }
  50419. void TabbedButtonBar::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  50420. {
  50421. if (((unsigned int) tabIndex) < (unsigned int) tabColours.size()
  50422. && tabColours [tabIndex] != newColour)
  50423. {
  50424. tabColours.set (tabIndex, newColour);
  50425. repaint();
  50426. }
  50427. }
  50428. void TabbedButtonBar::buttonClicked (Button* button)
  50429. {
  50430. if (extraTabsButton == button)
  50431. {
  50432. PopupMenu m;
  50433. for (int i = 0; i < tabs.size(); ++i)
  50434. {
  50435. TabBarButton* const tb = getTabButton (i);
  50436. if (tb != 0 && ! tb->isVisible())
  50437. m.addItem (tb->tabIndex + 1, tabs[i], true, i == currentTabIndex);
  50438. }
  50439. const int res = m.showAt (extraTabsButton);
  50440. if (res != 0)
  50441. setCurrentTabIndex (res - 1);
  50442. }
  50443. }
  50444. void TabbedButtonBar::currentTabChanged (const int, const String&)
  50445. {
  50446. }
  50447. void TabbedButtonBar::popupMenuClickOnTab (const int, const String&)
  50448. {
  50449. }
  50450. END_JUCE_NAMESPACE
  50451. /*** End of inlined file: juce_TabbedButtonBar.cpp ***/
  50452. /*** Start of inlined file: juce_TabbedComponent.cpp ***/
  50453. BEGIN_JUCE_NAMESPACE
  50454. class TabCompButtonBar : public TabbedButtonBar
  50455. {
  50456. public:
  50457. TabCompButtonBar (TabbedComponent* const owner_,
  50458. const TabbedButtonBar::Orientation orientation)
  50459. : TabbedButtonBar (orientation),
  50460. owner (owner_)
  50461. {
  50462. }
  50463. ~TabCompButtonBar()
  50464. {
  50465. }
  50466. void currentTabChanged (const int newCurrentTabIndex,
  50467. const String& newTabName)
  50468. {
  50469. owner->changeCallback (newCurrentTabIndex, newTabName);
  50470. }
  50471. void popupMenuClickOnTab (const int tabIndex,
  50472. const String& tabName)
  50473. {
  50474. owner->popupMenuClickOnTab (tabIndex, tabName);
  50475. }
  50476. const Colour getTabBackgroundColour (const int tabIndex)
  50477. {
  50478. return owner->tabs->getTabBackgroundColour (tabIndex);
  50479. }
  50480. TabBarButton* createTabButton (const String& tabName, const int tabIndex)
  50481. {
  50482. return owner->createTabButton (tabName, tabIndex);
  50483. }
  50484. juce_UseDebuggingNewOperator
  50485. private:
  50486. TabbedComponent* const owner;
  50487. TabCompButtonBar (const TabCompButtonBar&);
  50488. TabCompButtonBar& operator= (const TabCompButtonBar&);
  50489. };
  50490. TabbedComponent::TabbedComponent (const TabbedButtonBar::Orientation orientation)
  50491. : panelComponent (0),
  50492. tabDepth (30),
  50493. outlineThickness (1),
  50494. edgeIndent (0)
  50495. {
  50496. addAndMakeVisible (tabs = new TabCompButtonBar (this, orientation));
  50497. }
  50498. TabbedComponent::~TabbedComponent()
  50499. {
  50500. clearTabs();
  50501. delete tabs;
  50502. }
  50503. void TabbedComponent::setOrientation (const TabbedButtonBar::Orientation orientation)
  50504. {
  50505. tabs->setOrientation (orientation);
  50506. resized();
  50507. }
  50508. TabbedButtonBar::Orientation TabbedComponent::getOrientation() const throw()
  50509. {
  50510. return tabs->getOrientation();
  50511. }
  50512. void TabbedComponent::setTabBarDepth (const int newDepth)
  50513. {
  50514. if (tabDepth != newDepth)
  50515. {
  50516. tabDepth = newDepth;
  50517. resized();
  50518. }
  50519. }
  50520. TabBarButton* TabbedComponent::createTabButton (const String& tabName, const int tabIndex)
  50521. {
  50522. return new TabBarButton (tabName, tabs, tabIndex);
  50523. }
  50524. void TabbedComponent::clearTabs()
  50525. {
  50526. if (panelComponent != 0)
  50527. {
  50528. panelComponent->setVisible (false);
  50529. removeChildComponent (panelComponent);
  50530. panelComponent = 0;
  50531. }
  50532. tabs->clearTabs();
  50533. for (int i = contentComponents.size(); --i >= 0;)
  50534. {
  50535. Component* const c = contentComponents.getUnchecked(i);
  50536. // be careful not to delete these components until they've been removed from the tab component
  50537. jassert (c == 0 || c->isValidComponent());
  50538. if (c != 0 && (bool) c->getProperties() ["deleteByTabComp_"])
  50539. delete c;
  50540. }
  50541. contentComponents.clear();
  50542. }
  50543. void TabbedComponent::addTab (const String& tabName,
  50544. const Colour& tabBackgroundColour,
  50545. Component* const contentComponent,
  50546. const bool deleteComponentWhenNotNeeded,
  50547. const int insertIndex)
  50548. {
  50549. contentComponents.insert (insertIndex, contentComponent);
  50550. if (contentComponent != 0)
  50551. contentComponent->getProperties().set ("deleteByTabComp_", deleteComponentWhenNotNeeded);
  50552. tabs->addTab (tabName, tabBackgroundColour, insertIndex);
  50553. }
  50554. void TabbedComponent::setTabName (const int tabIndex,
  50555. const String& newName)
  50556. {
  50557. tabs->setTabName (tabIndex, newName);
  50558. }
  50559. void TabbedComponent::removeTab (const int tabIndex)
  50560. {
  50561. Component* const c = contentComponents [tabIndex];
  50562. if (c != 0 && (bool) c->getProperties() ["deleteByTabComp_"])
  50563. {
  50564. if (c == panelComponent)
  50565. panelComponent = 0;
  50566. delete c;
  50567. }
  50568. contentComponents.remove (tabIndex);
  50569. tabs->removeTab (tabIndex);
  50570. }
  50571. int TabbedComponent::getNumTabs() const
  50572. {
  50573. return tabs->getNumTabs();
  50574. }
  50575. const StringArray TabbedComponent::getTabNames() const
  50576. {
  50577. return tabs->getTabNames();
  50578. }
  50579. Component* TabbedComponent::getTabContentComponent (const int tabIndex) const throw()
  50580. {
  50581. return contentComponents [tabIndex];
  50582. }
  50583. const Colour TabbedComponent::getTabBackgroundColour (const int tabIndex) const throw()
  50584. {
  50585. return tabs->getTabBackgroundColour (tabIndex);
  50586. }
  50587. void TabbedComponent::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  50588. {
  50589. tabs->setTabBackgroundColour (tabIndex, newColour);
  50590. if (getCurrentTabIndex() == tabIndex)
  50591. repaint();
  50592. }
  50593. void TabbedComponent::setCurrentTabIndex (const int newTabIndex, const bool sendChangeMessage)
  50594. {
  50595. tabs->setCurrentTabIndex (newTabIndex, sendChangeMessage);
  50596. }
  50597. int TabbedComponent::getCurrentTabIndex() const
  50598. {
  50599. return tabs->getCurrentTabIndex();
  50600. }
  50601. const String& TabbedComponent::getCurrentTabName() const
  50602. {
  50603. return tabs->getCurrentTabName();
  50604. }
  50605. void TabbedComponent::setOutline (int thickness)
  50606. {
  50607. outlineThickness = thickness;
  50608. repaint();
  50609. }
  50610. void TabbedComponent::setIndent (const int indentThickness)
  50611. {
  50612. edgeIndent = indentThickness;
  50613. }
  50614. void TabbedComponent::paint (Graphics& g)
  50615. {
  50616. g.fillAll (findColour (backgroundColourId));
  50617. const TabbedButtonBar::Orientation o = getOrientation();
  50618. int x = 0;
  50619. int y = 0;
  50620. int r = getWidth();
  50621. int b = getHeight();
  50622. if (o == TabbedButtonBar::TabsAtTop)
  50623. y += tabDepth;
  50624. else if (o == TabbedButtonBar::TabsAtBottom)
  50625. b -= tabDepth;
  50626. else if (o == TabbedButtonBar::TabsAtLeft)
  50627. x += tabDepth;
  50628. else if (o == TabbedButtonBar::TabsAtRight)
  50629. r -= tabDepth;
  50630. g.reduceClipRegion (x, y, r - x, b - y);
  50631. g.fillAll (tabs->getTabBackgroundColour (getCurrentTabIndex()));
  50632. if (outlineThickness > 0)
  50633. {
  50634. if (o == TabbedButtonBar::TabsAtTop)
  50635. --y;
  50636. else if (o == TabbedButtonBar::TabsAtBottom)
  50637. ++b;
  50638. else if (o == TabbedButtonBar::TabsAtLeft)
  50639. --x;
  50640. else if (o == TabbedButtonBar::TabsAtRight)
  50641. ++r;
  50642. g.setColour (findColour (outlineColourId));
  50643. g.drawRect (x, y, r - x, b - y, outlineThickness);
  50644. }
  50645. }
  50646. void TabbedComponent::resized()
  50647. {
  50648. const TabbedButtonBar::Orientation o = getOrientation();
  50649. const int indent = edgeIndent + outlineThickness;
  50650. BorderSize indents (indent);
  50651. if (o == TabbedButtonBar::TabsAtTop)
  50652. {
  50653. tabs->setBounds (0, 0, getWidth(), tabDepth);
  50654. indents.setTop (tabDepth + edgeIndent);
  50655. }
  50656. else if (o == TabbedButtonBar::TabsAtBottom)
  50657. {
  50658. tabs->setBounds (0, getHeight() - tabDepth, getWidth(), tabDepth);
  50659. indents.setBottom (tabDepth + edgeIndent);
  50660. }
  50661. else if (o == TabbedButtonBar::TabsAtLeft)
  50662. {
  50663. tabs->setBounds (0, 0, tabDepth, getHeight());
  50664. indents.setLeft (tabDepth + edgeIndent);
  50665. }
  50666. else if (o == TabbedButtonBar::TabsAtRight)
  50667. {
  50668. tabs->setBounds (getWidth() - tabDepth, 0, tabDepth, getHeight());
  50669. indents.setRight (tabDepth + edgeIndent);
  50670. }
  50671. const Rectangle<int> bounds (indents.subtractedFrom (Rectangle<int> (0, 0, getWidth(), getHeight())));
  50672. for (int i = contentComponents.size(); --i >= 0;)
  50673. if (contentComponents.getUnchecked (i) != 0)
  50674. contentComponents.getUnchecked (i)->setBounds (bounds);
  50675. }
  50676. void TabbedComponent::lookAndFeelChanged()
  50677. {
  50678. for (int i = contentComponents.size(); --i >= 0;)
  50679. if (contentComponents.getUnchecked (i) != 0)
  50680. contentComponents.getUnchecked (i)->lookAndFeelChanged();
  50681. }
  50682. void TabbedComponent::changeCallback (const int newCurrentTabIndex,
  50683. const String& newTabName)
  50684. {
  50685. if (panelComponent != 0)
  50686. {
  50687. panelComponent->setVisible (false);
  50688. removeChildComponent (panelComponent);
  50689. panelComponent = 0;
  50690. }
  50691. if (getCurrentTabIndex() >= 0)
  50692. {
  50693. panelComponent = contentComponents [getCurrentTabIndex()];
  50694. if (panelComponent != 0)
  50695. {
  50696. // do these ops as two stages instead of addAndMakeVisible() so that the
  50697. // component has always got a parent when it gets the visibilityChanged() callback
  50698. addChildComponent (panelComponent);
  50699. panelComponent->setVisible (true);
  50700. panelComponent->toFront (true);
  50701. }
  50702. repaint();
  50703. }
  50704. resized();
  50705. currentTabChanged (newCurrentTabIndex, newTabName);
  50706. }
  50707. void TabbedComponent::currentTabChanged (const int, const String&)
  50708. {
  50709. }
  50710. void TabbedComponent::popupMenuClickOnTab (const int, const String&)
  50711. {
  50712. }
  50713. END_JUCE_NAMESPACE
  50714. /*** End of inlined file: juce_TabbedComponent.cpp ***/
  50715. /*** Start of inlined file: juce_Viewport.cpp ***/
  50716. BEGIN_JUCE_NAMESPACE
  50717. Viewport::Viewport (const String& componentName)
  50718. : Component (componentName),
  50719. contentComp (0),
  50720. lastVX (0),
  50721. lastVY (0),
  50722. lastVW (0),
  50723. lastVH (0),
  50724. scrollBarThickness (0),
  50725. singleStepX (16),
  50726. singleStepY (16),
  50727. showHScrollbar (true),
  50728. showVScrollbar (true)
  50729. {
  50730. // content holder is used to clip the contents so they don't overlap the scrollbars
  50731. addAndMakeVisible (contentHolder = new Component());
  50732. contentHolder->setInterceptsMouseClicks (false, true);
  50733. verticalScrollBar = new ScrollBar (true);
  50734. horizontalScrollBar = new ScrollBar (false);
  50735. addChildComponent (verticalScrollBar);
  50736. addChildComponent (horizontalScrollBar);
  50737. verticalScrollBar->addListener (this);
  50738. horizontalScrollBar->addListener (this);
  50739. setInterceptsMouseClicks (false, true);
  50740. setWantsKeyboardFocus (true);
  50741. }
  50742. Viewport::~Viewport()
  50743. {
  50744. contentHolder->deleteAllChildren();
  50745. deleteAllChildren();
  50746. }
  50747. void Viewport::visibleAreaChanged (int, int, int, int)
  50748. {
  50749. }
  50750. void Viewport::setViewedComponent (Component* const newViewedComponent)
  50751. {
  50752. if (contentComp.getComponent() != newViewedComponent)
  50753. {
  50754. {
  50755. ScopedPointer<Component> oldCompDeleter (contentComp);
  50756. contentComp = 0;
  50757. }
  50758. contentComp = newViewedComponent;
  50759. if (contentComp != 0)
  50760. {
  50761. contentComp->setTopLeftPosition (0, 0);
  50762. contentHolder->addAndMakeVisible (contentComp);
  50763. contentComp->addComponentListener (this);
  50764. }
  50765. updateVisibleRegion();
  50766. }
  50767. }
  50768. int Viewport::getMaximumVisibleWidth() const throw()
  50769. {
  50770. return jmax (0, getWidth() - (verticalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  50771. }
  50772. int Viewport::getMaximumVisibleHeight() const throw()
  50773. {
  50774. return jmax (0, getHeight() - (horizontalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  50775. }
  50776. void Viewport::setViewPosition (const int xPixelsOffset,
  50777. const int yPixelsOffset)
  50778. {
  50779. if (contentComp != 0)
  50780. contentComp->setTopLeftPosition (-xPixelsOffset,
  50781. -yPixelsOffset);
  50782. }
  50783. void Viewport::setViewPositionProportionately (const double x,
  50784. const double y)
  50785. {
  50786. if (contentComp != 0)
  50787. setViewPosition (jmax (0, roundToInt (x * (contentComp->getWidth() - getWidth()))),
  50788. jmax (0, roundToInt (y * (contentComp->getHeight() - getHeight()))));
  50789. }
  50790. bool Viewport::autoScroll (int mouseX, int mouseY, int activeBorderThickness, int maximumSpeed)
  50791. {
  50792. if (contentComp != 0)
  50793. {
  50794. int dx = 0, dy = 0;
  50795. if (mouseX < activeBorderThickness)
  50796. dx = activeBorderThickness - mouseX;
  50797. else if (mouseX >= contentHolder->getWidth() - activeBorderThickness)
  50798. dx = (contentHolder->getWidth() - activeBorderThickness) - mouseX;
  50799. if (dx < 0)
  50800. dx = jmax (dx, -maximumSpeed, contentHolder->getWidth() - contentComp->getRight());
  50801. else
  50802. dx = jmin (dx, maximumSpeed, -contentComp->getX());
  50803. if (mouseY < activeBorderThickness)
  50804. dy = activeBorderThickness - mouseY;
  50805. else if (mouseY >= contentHolder->getHeight() - activeBorderThickness)
  50806. dy = (contentHolder->getHeight() - activeBorderThickness) - mouseY;
  50807. if (dy < 0)
  50808. dy = jmax (dy, -maximumSpeed, contentHolder->getHeight() - contentComp->getBottom());
  50809. else
  50810. dy = jmin (dy, maximumSpeed, -contentComp->getY());
  50811. if (dx != 0 || dy != 0)
  50812. {
  50813. contentComp->setTopLeftPosition (contentComp->getX() + dx,
  50814. contentComp->getY() + dy);
  50815. return true;
  50816. }
  50817. }
  50818. return false;
  50819. }
  50820. void Viewport::componentMovedOrResized (Component&, bool, bool)
  50821. {
  50822. updateVisibleRegion();
  50823. }
  50824. void Viewport::resized()
  50825. {
  50826. updateVisibleRegion();
  50827. }
  50828. void Viewport::updateVisibleRegion()
  50829. {
  50830. if (contentComp != 0)
  50831. {
  50832. const int newVX = -contentComp->getX();
  50833. const int newVY = -contentComp->getY();
  50834. if (newVX == 0 && newVY == 0
  50835. && contentComp->getWidth() <= getWidth()
  50836. && contentComp->getHeight() <= getHeight())
  50837. {
  50838. horizontalScrollBar->setVisible (false);
  50839. verticalScrollBar->setVisible (false);
  50840. }
  50841. horizontalScrollBar->setRangeLimits (0.0, contentComp->getWidth());
  50842. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  50843. horizontalScrollBar->setSingleStepSize (singleStepX);
  50844. if (! (contentComp->getWidth() > 0 && showHScrollbar && getHeight() > getScrollBarThickness()))
  50845. horizontalScrollBar->setVisible (false);
  50846. verticalScrollBar->setRangeLimits (0.0, contentComp->getHeight());
  50847. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  50848. verticalScrollBar->setSingleStepSize (singleStepY);
  50849. if (! (contentComp->getHeight() > 0 && showVScrollbar && getWidth() > getScrollBarThickness()))
  50850. verticalScrollBar->setVisible (false);
  50851. if (verticalScrollBar->isVisible())
  50852. {
  50853. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  50854. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  50855. verticalScrollBar
  50856. ->setBounds (getMaximumVisibleWidth(), 0,
  50857. getScrollBarThickness(), getMaximumVisibleHeight());
  50858. }
  50859. if (horizontalScrollBar->isVisible())
  50860. {
  50861. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  50862. horizontalScrollBar
  50863. ->setBounds (0, getMaximumVisibleHeight(),
  50864. getMaximumVisibleWidth(), getScrollBarThickness());
  50865. }
  50866. contentHolder->setSize (getMaximumVisibleWidth(),
  50867. getMaximumVisibleHeight());
  50868. const int newVW = jmin (contentComp->getRight(), getMaximumVisibleWidth());
  50869. const int newVH = jmin (contentComp->getBottom(), getMaximumVisibleHeight());
  50870. if (newVX != lastVX
  50871. || newVY != lastVY
  50872. || newVW != lastVW
  50873. || newVH != lastVH)
  50874. {
  50875. lastVX = newVX;
  50876. lastVY = newVY;
  50877. lastVW = newVW;
  50878. lastVH = newVH;
  50879. visibleAreaChanged (newVX, newVY, newVW, newVH);
  50880. }
  50881. horizontalScrollBar->handleUpdateNowIfNeeded();
  50882. verticalScrollBar->handleUpdateNowIfNeeded();
  50883. }
  50884. else
  50885. {
  50886. horizontalScrollBar->setVisible (false);
  50887. verticalScrollBar->setVisible (false);
  50888. }
  50889. }
  50890. void Viewport::setSingleStepSizes (const int stepX,
  50891. const int stepY)
  50892. {
  50893. singleStepX = stepX;
  50894. singleStepY = stepY;
  50895. updateVisibleRegion();
  50896. }
  50897. void Viewport::setScrollBarsShown (const bool showVerticalScrollbarIfNeeded,
  50898. const bool showHorizontalScrollbarIfNeeded)
  50899. {
  50900. showVScrollbar = showVerticalScrollbarIfNeeded;
  50901. showHScrollbar = showHorizontalScrollbarIfNeeded;
  50902. updateVisibleRegion();
  50903. }
  50904. void Viewport::setScrollBarThickness (const int thickness)
  50905. {
  50906. scrollBarThickness = thickness;
  50907. updateVisibleRegion();
  50908. }
  50909. int Viewport::getScrollBarThickness() const throw()
  50910. {
  50911. return (scrollBarThickness > 0) ? scrollBarThickness
  50912. : getLookAndFeel().getDefaultScrollbarWidth();
  50913. }
  50914. void Viewport::setScrollBarButtonVisibility (const bool buttonsVisible)
  50915. {
  50916. verticalScrollBar->setButtonVisibility (buttonsVisible);
  50917. horizontalScrollBar->setButtonVisibility (buttonsVisible);
  50918. }
  50919. void Viewport::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, double newRangeStart)
  50920. {
  50921. if (scrollBarThatHasMoved == horizontalScrollBar)
  50922. {
  50923. setViewPosition (roundToInt (newRangeStart), getViewPositionY());
  50924. }
  50925. else if (scrollBarThatHasMoved == verticalScrollBar)
  50926. {
  50927. setViewPosition (getViewPositionX(), roundToInt (newRangeStart));
  50928. }
  50929. }
  50930. void Viewport::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  50931. {
  50932. if (! useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  50933. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  50934. }
  50935. bool Viewport::useMouseWheelMoveIfNeeded (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  50936. {
  50937. if (! (e.mods.isAltDown() || e.mods.isCtrlDown()))
  50938. {
  50939. const bool hasVertBar = verticalScrollBar->isVisible();
  50940. const bool hasHorzBar = horizontalScrollBar->isVisible();
  50941. if (hasHorzBar && (wheelIncrementX != 0 || e.mods.isShiftDown() || ! hasVertBar))
  50942. {
  50943. if (wheelIncrementX == 0 && ! hasVertBar)
  50944. wheelIncrementX = wheelIncrementY;
  50945. horizontalScrollBar->mouseWheelMove (e.getEventRelativeTo (horizontalScrollBar),
  50946. wheelIncrementX, wheelIncrementY);
  50947. return true;
  50948. }
  50949. else if (hasVertBar && wheelIncrementY != 0)
  50950. {
  50951. verticalScrollBar->mouseWheelMove (e.getEventRelativeTo (verticalScrollBar),
  50952. wheelIncrementX, wheelIncrementY);
  50953. return true;
  50954. }
  50955. }
  50956. return false;
  50957. }
  50958. bool Viewport::keyPressed (const KeyPress& key)
  50959. {
  50960. const bool isUpDownKey = key.isKeyCode (KeyPress::upKey)
  50961. || key.isKeyCode (KeyPress::downKey)
  50962. || key.isKeyCode (KeyPress::pageUpKey)
  50963. || key.isKeyCode (KeyPress::pageDownKey)
  50964. || key.isKeyCode (KeyPress::homeKey)
  50965. || key.isKeyCode (KeyPress::endKey);
  50966. if (verticalScrollBar->isVisible() && isUpDownKey)
  50967. return verticalScrollBar->keyPressed (key);
  50968. const bool isLeftRightKey = key.isKeyCode (KeyPress::leftKey)
  50969. || key.isKeyCode (KeyPress::rightKey);
  50970. if (horizontalScrollBar->isVisible() && (isUpDownKey || isLeftRightKey))
  50971. return horizontalScrollBar->keyPressed (key);
  50972. return false;
  50973. }
  50974. END_JUCE_NAMESPACE
  50975. /*** End of inlined file: juce_Viewport.cpp ***/
  50976. /*** Start of inlined file: juce_LookAndFeel.cpp ***/
  50977. BEGIN_JUCE_NAMESPACE
  50978. static const Colour createBaseColour (const Colour& buttonColour,
  50979. const bool hasKeyboardFocus,
  50980. const bool isMouseOverButton,
  50981. const bool isButtonDown) throw()
  50982. {
  50983. const float sat = hasKeyboardFocus ? 1.3f : 0.9f;
  50984. const Colour baseColour (buttonColour.withMultipliedSaturation (sat));
  50985. if (isButtonDown)
  50986. return baseColour.contrasting (0.2f);
  50987. else if (isMouseOverButton)
  50988. return baseColour.contrasting (0.1f);
  50989. return baseColour;
  50990. }
  50991. LookAndFeel::LookAndFeel()
  50992. {
  50993. /* if this fails it means you're trying to create a LookAndFeel object before
  50994. the static Colours have been initialised. That ain't gonna work. It probably
  50995. means that you're using a static LookAndFeel object and that your compiler has
  50996. decided to intialise it before the Colours class.
  50997. */
  50998. jassert (Colours::white == Colour (0xffffffff));
  50999. // set up the standard set of colours..
  51000. const int textButtonColour = 0xffbbbbff;
  51001. const int textHighlightColour = 0x401111ee;
  51002. const int standardOutlineColour = 0xb2808080;
  51003. static const int standardColours[] =
  51004. {
  51005. TextButton::buttonColourId, textButtonColour,
  51006. TextButton::buttonOnColourId, 0xff4444ff,
  51007. TextButton::textColourOnId, 0xff000000,
  51008. TextButton::textColourOffId, 0xff000000,
  51009. ComboBox::buttonColourId, 0xffbbbbff,
  51010. ComboBox::outlineColourId, standardOutlineColour,
  51011. ToggleButton::textColourId, 0xff000000,
  51012. TextEditor::backgroundColourId, 0xffffffff,
  51013. TextEditor::textColourId, 0xff000000,
  51014. TextEditor::highlightColourId, textHighlightColour,
  51015. TextEditor::highlightedTextColourId, 0xff000000,
  51016. TextEditor::caretColourId, 0xff000000,
  51017. TextEditor::outlineColourId, 0x00000000,
  51018. TextEditor::focusedOutlineColourId, textButtonColour,
  51019. TextEditor::shadowColourId, 0x38000000,
  51020. Label::backgroundColourId, 0x00000000,
  51021. Label::textColourId, 0xff000000,
  51022. Label::outlineColourId, 0x00000000,
  51023. ScrollBar::backgroundColourId, 0x00000000,
  51024. ScrollBar::thumbColourId, 0xffffffff,
  51025. ScrollBar::trackColourId, 0xffffffff,
  51026. TreeView::linesColourId, 0x4c000000,
  51027. TreeView::backgroundColourId, 0x00000000,
  51028. TreeView::dragAndDropIndicatorColourId, 0x80ff0000,
  51029. PopupMenu::backgroundColourId, 0xffffffff,
  51030. PopupMenu::textColourId, 0xff000000,
  51031. PopupMenu::headerTextColourId, 0xff000000,
  51032. PopupMenu::highlightedTextColourId, 0xffffffff,
  51033. PopupMenu::highlightedBackgroundColourId, 0x991111aa,
  51034. ComboBox::textColourId, 0xff000000,
  51035. ComboBox::backgroundColourId, 0xffffffff,
  51036. ComboBox::arrowColourId, 0x99000000,
  51037. ListBox::backgroundColourId, 0xffffffff,
  51038. ListBox::outlineColourId, standardOutlineColour,
  51039. ListBox::textColourId, 0xff000000,
  51040. Slider::backgroundColourId, 0x00000000,
  51041. Slider::thumbColourId, textButtonColour,
  51042. Slider::trackColourId, 0x7fffffff,
  51043. Slider::rotarySliderFillColourId, 0x7f0000ff,
  51044. Slider::rotarySliderOutlineColourId, 0x66000000,
  51045. Slider::textBoxTextColourId, 0xff000000,
  51046. Slider::textBoxBackgroundColourId, 0xffffffff,
  51047. Slider::textBoxHighlightColourId, textHighlightColour,
  51048. Slider::textBoxOutlineColourId, standardOutlineColour,
  51049. ResizableWindow::backgroundColourId, 0xff777777,
  51050. //DocumentWindow::textColourId, 0xff000000, // (this is deliberately not set)
  51051. AlertWindow::backgroundColourId, 0xffededed,
  51052. AlertWindow::textColourId, 0xff000000,
  51053. AlertWindow::outlineColourId, 0xff666666,
  51054. ProgressBar::backgroundColourId, 0xffeeeeee,
  51055. ProgressBar::foregroundColourId, 0xffaaaaee,
  51056. TooltipWindow::backgroundColourId, 0xffeeeebb,
  51057. TooltipWindow::textColourId, 0xff000000,
  51058. TooltipWindow::outlineColourId, 0x4c000000,
  51059. TabbedComponent::backgroundColourId, 0x00000000,
  51060. TabbedComponent::outlineColourId, 0xff777777,
  51061. TabbedButtonBar::tabOutlineColourId, 0x80000000,
  51062. TabbedButtonBar::frontOutlineColourId, 0x90000000,
  51063. Toolbar::backgroundColourId, 0xfff6f8f9,
  51064. Toolbar::separatorColourId, 0x4c000000,
  51065. Toolbar::buttonMouseOverBackgroundColourId, 0x4c0000ff,
  51066. Toolbar::buttonMouseDownBackgroundColourId, 0x800000ff,
  51067. Toolbar::labelTextColourId, 0xff000000,
  51068. Toolbar::editingModeOutlineColourId, 0xffff0000,
  51069. HyperlinkButton::textColourId, 0xcc1111ee,
  51070. GroupComponent::outlineColourId, 0x66000000,
  51071. GroupComponent::textColourId, 0xff000000,
  51072. DirectoryContentsDisplayComponent::highlightColourId, textHighlightColour,
  51073. DirectoryContentsDisplayComponent::textColourId, 0xff000000,
  51074. 0x1000440, /*LassoComponent::lassoFillColourId*/ 0x66dddddd,
  51075. 0x1000441, /*LassoComponent::lassoOutlineColourId*/ 0x99111111,
  51076. MidiKeyboardComponent::whiteNoteColourId, 0xffffffff,
  51077. MidiKeyboardComponent::blackNoteColourId, 0xff000000,
  51078. MidiKeyboardComponent::keySeparatorLineColourId, 0x66000000,
  51079. MidiKeyboardComponent::mouseOverKeyOverlayColourId, 0x80ffff00,
  51080. MidiKeyboardComponent::keyDownOverlayColourId, 0xffb6b600,
  51081. MidiKeyboardComponent::textLabelColourId, 0xff000000,
  51082. MidiKeyboardComponent::upDownButtonBackgroundColourId, 0xffd3d3d3,
  51083. MidiKeyboardComponent::upDownButtonArrowColourId, 0xff000000,
  51084. CodeEditorComponent::backgroundColourId, 0xffffffff,
  51085. CodeEditorComponent::caretColourId, 0xff000000,
  51086. CodeEditorComponent::highlightColourId, textHighlightColour,
  51087. CodeEditorComponent::defaultTextColourId, 0xff000000,
  51088. ColourSelector::backgroundColourId, 0xffe5e5e5,
  51089. ColourSelector::labelTextColourId, 0xff000000,
  51090. KeyMappingEditorComponent::backgroundColourId, 0x00000000,
  51091. KeyMappingEditorComponent::textColourId, 0xff000000,
  51092. FileSearchPathListComponent::backgroundColourId, 0xffffffff,
  51093. FileChooserDialogBox::titleTextColourId, 0xff000000,
  51094. };
  51095. for (int i = 0; i < numElementsInArray (standardColours); i += 2)
  51096. setColour (standardColours [i], Colour (standardColours [i + 1]));
  51097. static String defaultSansName, defaultSerifName, defaultFixedName;
  51098. if (defaultSansName.isEmpty())
  51099. Font::getPlatformDefaultFontNames (defaultSansName, defaultSerifName, defaultFixedName);
  51100. defaultSans = defaultSansName;
  51101. defaultSerif = defaultSerifName;
  51102. defaultFixed = defaultFixedName;
  51103. }
  51104. LookAndFeel::~LookAndFeel()
  51105. {
  51106. }
  51107. const Colour LookAndFeel::findColour (const int colourId) const throw()
  51108. {
  51109. const int index = colourIds.indexOf (colourId);
  51110. if (index >= 0)
  51111. return colours [index];
  51112. jassertfalse
  51113. return Colours::black;
  51114. }
  51115. void LookAndFeel::setColour (const int colourId, const Colour& colour) throw()
  51116. {
  51117. const int index = colourIds.indexOf (colourId);
  51118. if (index >= 0)
  51119. colours.set (index, colour);
  51120. colourIds.add (colourId);
  51121. colours.add (colour);
  51122. }
  51123. bool LookAndFeel::isColourSpecified (const int colourId) const throw()
  51124. {
  51125. return colourIds.contains (colourId);
  51126. }
  51127. static LookAndFeel* defaultLF = 0;
  51128. static LookAndFeel* currentDefaultLF = 0;
  51129. LookAndFeel& LookAndFeel::getDefaultLookAndFeel() throw()
  51130. {
  51131. // if this happens, your app hasn't initialised itself properly.. if you're
  51132. // trying to hack your own main() function, have a look at
  51133. // JUCEApplication::initialiseForGUI()
  51134. jassert (currentDefaultLF != 0);
  51135. return *currentDefaultLF;
  51136. }
  51137. void LookAndFeel::setDefaultLookAndFeel (LookAndFeel* newDefaultLookAndFeel) throw()
  51138. {
  51139. if (newDefaultLookAndFeel == 0)
  51140. {
  51141. if (defaultLF == 0)
  51142. defaultLF = new LookAndFeel();
  51143. newDefaultLookAndFeel = defaultLF;
  51144. }
  51145. currentDefaultLF = newDefaultLookAndFeel;
  51146. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  51147. {
  51148. Component* const c = Desktop::getInstance().getComponent (i);
  51149. if (c != 0)
  51150. c->sendLookAndFeelChange();
  51151. }
  51152. }
  51153. void LookAndFeel::clearDefaultLookAndFeel() throw()
  51154. {
  51155. if (currentDefaultLF == defaultLF)
  51156. currentDefaultLF = 0;
  51157. deleteAndZero (defaultLF);
  51158. }
  51159. const Typeface::Ptr LookAndFeel::getTypefaceForFont (const Font& font)
  51160. {
  51161. String faceName (font.getTypefaceName());
  51162. if (faceName == Font::getDefaultSansSerifFontName())
  51163. faceName = defaultSans;
  51164. else if (faceName == Font::getDefaultSerifFontName())
  51165. faceName = defaultSerif;
  51166. else if (faceName == Font::getDefaultMonospacedFontName())
  51167. faceName = defaultFixed;
  51168. Font f (font);
  51169. f.setTypefaceName (faceName);
  51170. return Typeface::createSystemTypefaceFor (f);
  51171. }
  51172. void LookAndFeel::setDefaultSansSerifTypefaceName (const String& newName)
  51173. {
  51174. defaultSans = newName;
  51175. }
  51176. const MouseCursor LookAndFeel::getMouseCursorFor (Component& component)
  51177. {
  51178. return component.getMouseCursor();
  51179. }
  51180. void LookAndFeel::drawButtonBackground (Graphics& g,
  51181. Button& button,
  51182. const Colour& backgroundColour,
  51183. bool isMouseOverButton,
  51184. bool isButtonDown)
  51185. {
  51186. const int width = button.getWidth();
  51187. const int height = button.getHeight();
  51188. const float outlineThickness = button.isEnabled() ? ((isButtonDown || isMouseOverButton) ? 1.2f : 0.7f) : 0.4f;
  51189. const float halfThickness = outlineThickness * 0.5f;
  51190. const float indentL = button.isConnectedOnLeft() ? 0.1f : halfThickness;
  51191. const float indentR = button.isConnectedOnRight() ? 0.1f : halfThickness;
  51192. const float indentT = button.isConnectedOnTop() ? 0.1f : halfThickness;
  51193. const float indentB = button.isConnectedOnBottom() ? 0.1f : halfThickness;
  51194. const Colour baseColour (createBaseColour (backgroundColour,
  51195. button.hasKeyboardFocus (true),
  51196. isMouseOverButton, isButtonDown)
  51197. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51198. drawGlassLozenge (g,
  51199. indentL,
  51200. indentT,
  51201. width - indentL - indentR,
  51202. height - indentT - indentB,
  51203. baseColour, outlineThickness, -1.0f,
  51204. button.isConnectedOnLeft(),
  51205. button.isConnectedOnRight(),
  51206. button.isConnectedOnTop(),
  51207. button.isConnectedOnBottom());
  51208. }
  51209. const Font LookAndFeel::getFontForTextButton (TextButton& button)
  51210. {
  51211. return button.getFont();
  51212. }
  51213. void LookAndFeel::drawButtonText (Graphics& g, TextButton& button,
  51214. bool /*isMouseOverButton*/, bool /*isButtonDown*/)
  51215. {
  51216. Font font (getFontForTextButton (button));
  51217. g.setFont (font);
  51218. g.setColour (button.findColour (button.getToggleState() ? TextButton::textColourOnId
  51219. : TextButton::textColourOffId)
  51220. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51221. const int yIndent = jmin (4, button.proportionOfHeight (0.3f));
  51222. const int cornerSize = jmin (button.getHeight(), button.getWidth()) / 2;
  51223. const int fontHeight = roundToInt (font.getHeight() * 0.6f);
  51224. const int leftIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnLeft() ? 4 : 2));
  51225. const int rightIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnRight() ? 4 : 2));
  51226. g.drawFittedText (button.getButtonText(),
  51227. leftIndent,
  51228. yIndent,
  51229. button.getWidth() - leftIndent - rightIndent,
  51230. button.getHeight() - yIndent * 2,
  51231. Justification::centred, 2);
  51232. }
  51233. void LookAndFeel::drawTickBox (Graphics& g,
  51234. Component& component,
  51235. float x, float y, float w, float h,
  51236. const bool ticked,
  51237. const bool isEnabled,
  51238. const bool isMouseOverButton,
  51239. const bool isButtonDown)
  51240. {
  51241. const float boxSize = w * 0.7f;
  51242. drawGlassSphere (g, x, y + (h - boxSize) * 0.5f, boxSize,
  51243. createBaseColour (component.findColour (TextButton::buttonColourId)
  51244. .withMultipliedAlpha (isEnabled ? 1.0f : 0.5f),
  51245. true,
  51246. isMouseOverButton,
  51247. isButtonDown),
  51248. isEnabled ? ((isButtonDown || isMouseOverButton) ? 1.1f : 0.5f) : 0.3f);
  51249. if (ticked)
  51250. {
  51251. Path tick;
  51252. tick.startNewSubPath (1.5f, 3.0f);
  51253. tick.lineTo (3.0f, 6.0f);
  51254. tick.lineTo (6.0f, 0.0f);
  51255. g.setColour (isEnabled ? Colours::black : Colours::grey);
  51256. const AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f)
  51257. .translated (x, y));
  51258. g.strokePath (tick, PathStrokeType (2.5f), trans);
  51259. }
  51260. }
  51261. void LookAndFeel::drawToggleButton (Graphics& g,
  51262. ToggleButton& button,
  51263. bool isMouseOverButton,
  51264. bool isButtonDown)
  51265. {
  51266. if (button.hasKeyboardFocus (true))
  51267. {
  51268. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  51269. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  51270. }
  51271. float fontSize = jmin (15.0f, button.getHeight() * 0.75f);
  51272. const float tickWidth = fontSize * 1.1f;
  51273. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  51274. tickWidth, tickWidth,
  51275. button.getToggleState(),
  51276. button.isEnabled(),
  51277. isMouseOverButton,
  51278. isButtonDown);
  51279. g.setColour (button.findColour (ToggleButton::textColourId));
  51280. g.setFont (fontSize);
  51281. if (! button.isEnabled())
  51282. g.setOpacity (0.5f);
  51283. const int textX = (int) tickWidth + 5;
  51284. g.drawFittedText (button.getButtonText(),
  51285. textX, 0,
  51286. button.getWidth() - textX - 2, button.getHeight(),
  51287. Justification::centredLeft, 10);
  51288. }
  51289. void LookAndFeel::changeToggleButtonWidthToFitText (ToggleButton& button)
  51290. {
  51291. Font font (jmin (15.0f, button.getHeight() * 0.6f));
  51292. const int tickWidth = jmin (24, button.getHeight());
  51293. button.setSize (font.getStringWidth (button.getButtonText()) + tickWidth + 8,
  51294. button.getHeight());
  51295. }
  51296. AlertWindow* LookAndFeel::createAlertWindow (const String& title,
  51297. const String& message,
  51298. const String& button1,
  51299. const String& button2,
  51300. const String& button3,
  51301. AlertWindow::AlertIconType iconType,
  51302. int numButtons,
  51303. Component* associatedComponent)
  51304. {
  51305. AlertWindow* aw = new AlertWindow (title, message, iconType, associatedComponent);
  51306. if (numButtons == 1)
  51307. {
  51308. aw->addButton (button1, 0,
  51309. KeyPress (KeyPress::escapeKey, 0, 0),
  51310. KeyPress (KeyPress::returnKey, 0, 0));
  51311. }
  51312. else
  51313. {
  51314. const KeyPress button1ShortCut (CharacterFunctions::toLowerCase (button1[0]), 0, 0);
  51315. KeyPress button2ShortCut (CharacterFunctions::toLowerCase (button2[0]), 0, 0);
  51316. if (button1ShortCut == button2ShortCut)
  51317. button2ShortCut = KeyPress();
  51318. if (numButtons == 2)
  51319. {
  51320. aw->addButton (button1, 1, KeyPress (KeyPress::returnKey, 0, 0), button1ShortCut);
  51321. aw->addButton (button2, 0, KeyPress (KeyPress::escapeKey, 0, 0), button2ShortCut);
  51322. }
  51323. else if (numButtons == 3)
  51324. {
  51325. aw->addButton (button1, 1, button1ShortCut);
  51326. aw->addButton (button2, 2, button2ShortCut);
  51327. aw->addButton (button3, 0, KeyPress (KeyPress::escapeKey, 0, 0));
  51328. }
  51329. }
  51330. return aw;
  51331. }
  51332. void LookAndFeel::drawAlertBox (Graphics& g,
  51333. AlertWindow& alert,
  51334. const Rectangle<int>& textArea,
  51335. TextLayout& textLayout)
  51336. {
  51337. g.fillAll (alert.findColour (AlertWindow::backgroundColourId));
  51338. int iconSpaceUsed = 0;
  51339. Justification alignment (Justification::horizontallyCentred);
  51340. const int iconWidth = 80;
  51341. int iconSize = jmin (iconWidth + 50, alert.getHeight() + 20);
  51342. if (alert.containsAnyExtraComponents() || alert.getNumButtons() > 2)
  51343. iconSize = jmin (iconSize, textArea.getHeight() + 50);
  51344. const Rectangle<int> iconRect (iconSize / -10, iconSize / -10,
  51345. iconSize, iconSize);
  51346. if (alert.getAlertType() != AlertWindow::NoIcon)
  51347. {
  51348. Path icon;
  51349. uint32 colour;
  51350. char character;
  51351. if (alert.getAlertType() == AlertWindow::WarningIcon)
  51352. {
  51353. colour = 0x55ff5555;
  51354. character = '!';
  51355. icon.addTriangle (iconRect.getX() + iconRect.getWidth() * 0.5f, (float) iconRect.getY(),
  51356. (float) iconRect.getRight(), (float) iconRect.getBottom(),
  51357. (float) iconRect.getX(), (float) iconRect.getBottom());
  51358. icon = icon.createPathWithRoundedCorners (5.0f);
  51359. }
  51360. else
  51361. {
  51362. colour = alert.getAlertType() == AlertWindow::InfoIcon ? 0x605555ff : 0x40b69900;
  51363. character = alert.getAlertType() == AlertWindow::InfoIcon ? 'i' : '?';
  51364. icon.addEllipse ((float) iconRect.getX(), (float) iconRect.getY(),
  51365. (float) iconRect.getWidth(), (float) iconRect.getHeight());
  51366. }
  51367. GlyphArrangement ga;
  51368. ga.addFittedText (Font (iconRect.getHeight() * 0.9f, Font::bold),
  51369. String::charToString (character),
  51370. (float) iconRect.getX(), (float) iconRect.getY(),
  51371. (float) iconRect.getWidth(), (float) iconRect.getHeight(),
  51372. Justification::centred, false);
  51373. ga.createPath (icon);
  51374. icon.setUsingNonZeroWinding (false);
  51375. g.setColour (Colour (colour));
  51376. g.fillPath (icon);
  51377. iconSpaceUsed = iconWidth;
  51378. alignment = Justification::left;
  51379. }
  51380. g.setColour (alert.findColour (AlertWindow::textColourId));
  51381. textLayout.drawWithin (g,
  51382. textArea.getX() + iconSpaceUsed, textArea.getY(),
  51383. textArea.getWidth() - iconSpaceUsed, textArea.getHeight(),
  51384. alignment.getFlags() | Justification::top);
  51385. g.setColour (alert.findColour (AlertWindow::outlineColourId));
  51386. g.drawRect (0, 0, alert.getWidth(), alert.getHeight());
  51387. }
  51388. int LookAndFeel::getAlertBoxWindowFlags()
  51389. {
  51390. return ComponentPeer::windowAppearsOnTaskbar
  51391. | ComponentPeer::windowHasDropShadow;
  51392. }
  51393. int LookAndFeel::getAlertWindowButtonHeight()
  51394. {
  51395. return 28;
  51396. }
  51397. const Font LookAndFeel::getAlertWindowFont()
  51398. {
  51399. return Font (12.0f);
  51400. }
  51401. void LookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  51402. int width, int height,
  51403. double progress, const String& textToShow)
  51404. {
  51405. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  51406. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  51407. g.fillAll (background);
  51408. if (progress >= 0.0f && progress < 1.0f)
  51409. {
  51410. drawGlassLozenge (g, 1.0f, 1.0f,
  51411. (float) jlimit (0.0, width - 2.0, progress * (width - 2.0)),
  51412. (float) (height - 2),
  51413. foreground,
  51414. 0.5f, 0.0f,
  51415. true, true, true, true);
  51416. }
  51417. else
  51418. {
  51419. // spinning bar..
  51420. g.setColour (foreground);
  51421. const int stripeWidth = height * 2;
  51422. const int position = (Time::getMillisecondCounter() / 15) % stripeWidth;
  51423. Path p;
  51424. for (float x = (float) (- position); x < width + stripeWidth; x += stripeWidth)
  51425. p.addQuadrilateral (x, 0.0f,
  51426. x + stripeWidth * 0.5f, 0.0f,
  51427. x, (float) height,
  51428. x - stripeWidth * 0.5f, (float) height);
  51429. Image im (Image::ARGB, width, height, true);
  51430. {
  51431. Graphics g2 (im);
  51432. drawGlassLozenge (g2, 1.0f, 1.0f,
  51433. (float) (width - 2),
  51434. (float) (height - 2),
  51435. foreground,
  51436. 0.5f, 0.0f,
  51437. true, true, true, true);
  51438. }
  51439. g.setTiledImageFill (im, 0, 0, 0.85f);
  51440. g.fillPath (p);
  51441. }
  51442. if (textToShow.isNotEmpty())
  51443. {
  51444. g.setColour (Colour::contrasting (background, foreground));
  51445. g.setFont (height * 0.6f);
  51446. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  51447. }
  51448. }
  51449. void LookAndFeel::drawSpinningWaitAnimation (Graphics& g, const Colour& colour, int x, int y, int w, int h)
  51450. {
  51451. const float radius = jmin (w, h) * 0.4f;
  51452. const float thickness = radius * 0.15f;
  51453. Path p;
  51454. p.addRoundedRectangle (radius * 0.4f, thickness * -0.5f,
  51455. radius * 0.6f, thickness,
  51456. thickness * 0.5f);
  51457. const float cx = x + w * 0.5f;
  51458. const float cy = y + h * 0.5f;
  51459. const uint32 animationIndex = (Time::getMillisecondCounter() / (1000 / 10)) % 12;
  51460. for (int i = 0; i < 12; ++i)
  51461. {
  51462. const int n = (i + 12 - animationIndex) % 12;
  51463. g.setColour (colour.withMultipliedAlpha ((n + 1) / 12.0f));
  51464. g.fillPath (p, AffineTransform::rotation (i * (float_Pi / 6.0f))
  51465. .translated (cx, cy));
  51466. }
  51467. }
  51468. void LookAndFeel::drawScrollbarButton (Graphics& g,
  51469. ScrollBar& scrollbar,
  51470. int width, int height,
  51471. int buttonDirection,
  51472. bool /*isScrollbarVertical*/,
  51473. bool /*isMouseOverButton*/,
  51474. bool isButtonDown)
  51475. {
  51476. Path p;
  51477. if (buttonDirection == 0)
  51478. p.addTriangle (width * 0.5f, height * 0.2f,
  51479. width * 0.1f, height * 0.7f,
  51480. width * 0.9f, height * 0.7f);
  51481. else if (buttonDirection == 1)
  51482. p.addTriangle (width * 0.8f, height * 0.5f,
  51483. width * 0.3f, height * 0.1f,
  51484. width * 0.3f, height * 0.9f);
  51485. else if (buttonDirection == 2)
  51486. p.addTriangle (width * 0.5f, height * 0.8f,
  51487. width * 0.1f, height * 0.3f,
  51488. width * 0.9f, height * 0.3f);
  51489. else if (buttonDirection == 3)
  51490. p.addTriangle (width * 0.2f, height * 0.5f,
  51491. width * 0.7f, height * 0.1f,
  51492. width * 0.7f, height * 0.9f);
  51493. if (isButtonDown)
  51494. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId).contrasting (0.2f));
  51495. else
  51496. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId));
  51497. g.fillPath (p);
  51498. g.setColour (Colour (0x80000000));
  51499. g.strokePath (p, PathStrokeType (0.5f));
  51500. }
  51501. void LookAndFeel::drawScrollbar (Graphics& g,
  51502. ScrollBar& scrollbar,
  51503. int x, int y,
  51504. int width, int height,
  51505. bool isScrollbarVertical,
  51506. int thumbStartPosition,
  51507. int thumbSize,
  51508. bool /*isMouseOver*/,
  51509. bool /*isMouseDown*/)
  51510. {
  51511. g.fillAll (scrollbar.findColour (ScrollBar::backgroundColourId));
  51512. Path slotPath, thumbPath;
  51513. const float slotIndent = jmin (width, height) > 15 ? 1.0f : 0.0f;
  51514. const float slotIndentx2 = slotIndent * 2.0f;
  51515. const float thumbIndent = slotIndent + 1.0f;
  51516. const float thumbIndentx2 = thumbIndent * 2.0f;
  51517. float gx1 = 0.0f, gy1 = 0.0f, gx2 = 0.0f, gy2 = 0.0f;
  51518. if (isScrollbarVertical)
  51519. {
  51520. slotPath.addRoundedRectangle (x + slotIndent,
  51521. y + slotIndent,
  51522. width - slotIndentx2,
  51523. height - slotIndentx2,
  51524. (width - slotIndentx2) * 0.5f);
  51525. if (thumbSize > 0)
  51526. thumbPath.addRoundedRectangle (x + thumbIndent,
  51527. thumbStartPosition + thumbIndent,
  51528. width - thumbIndentx2,
  51529. thumbSize - thumbIndentx2,
  51530. (width - thumbIndentx2) * 0.5f);
  51531. gx1 = (float) x;
  51532. gx2 = x + width * 0.7f;
  51533. }
  51534. else
  51535. {
  51536. slotPath.addRoundedRectangle (x + slotIndent,
  51537. y + slotIndent,
  51538. width - slotIndentx2,
  51539. height - slotIndentx2,
  51540. (height - slotIndentx2) * 0.5f);
  51541. if (thumbSize > 0)
  51542. thumbPath.addRoundedRectangle (thumbStartPosition + thumbIndent,
  51543. y + thumbIndent,
  51544. thumbSize - thumbIndentx2,
  51545. height - thumbIndentx2,
  51546. (height - thumbIndentx2) * 0.5f);
  51547. gy1 = (float) y;
  51548. gy2 = y + height * 0.7f;
  51549. }
  51550. const Colour thumbColour (scrollbar.findColour (ScrollBar::thumbColourId));
  51551. g.setGradientFill (ColourGradient (thumbColour.overlaidWith (Colour (0x44000000)), gx1, gy1,
  51552. thumbColour.overlaidWith (Colour (0x19000000)), gx2, gy2, false));
  51553. g.fillPath (slotPath);
  51554. if (isScrollbarVertical)
  51555. {
  51556. gx1 = x + width * 0.6f;
  51557. gx2 = (float) x + width;
  51558. }
  51559. else
  51560. {
  51561. gy1 = y + height * 0.6f;
  51562. gy2 = (float) y + height;
  51563. }
  51564. g.setGradientFill (ColourGradient (Colours::transparentBlack,gx1, gy1,
  51565. Colour (0x19000000), gx2, gy2, false));
  51566. g.fillPath (slotPath);
  51567. g.setColour (thumbColour);
  51568. g.fillPath (thumbPath);
  51569. g.setGradientFill (ColourGradient (Colour (0x10000000), gx1, gy1,
  51570. Colours::transparentBlack, gx2, gy2, false));
  51571. g.saveState();
  51572. if (isScrollbarVertical)
  51573. g.reduceClipRegion (x + width / 2, y, width, height);
  51574. else
  51575. g.reduceClipRegion (x, y + height / 2, width, height);
  51576. g.fillPath (thumbPath);
  51577. g.restoreState();
  51578. g.setColour (Colour (0x4c000000));
  51579. g.strokePath (thumbPath, PathStrokeType (0.4f));
  51580. }
  51581. ImageEffectFilter* LookAndFeel::getScrollbarEffect()
  51582. {
  51583. return 0;
  51584. }
  51585. int LookAndFeel::getMinimumScrollbarThumbSize (ScrollBar& scrollbar)
  51586. {
  51587. return jmin (scrollbar.getWidth(), scrollbar.getHeight()) * 2;
  51588. }
  51589. int LookAndFeel::getDefaultScrollbarWidth()
  51590. {
  51591. return 18;
  51592. }
  51593. int LookAndFeel::getScrollbarButtonSize (ScrollBar& scrollbar)
  51594. {
  51595. return 2 + (scrollbar.isVertical() ? scrollbar.getWidth()
  51596. : scrollbar.getHeight());
  51597. }
  51598. const Path LookAndFeel::getTickShape (const float height)
  51599. {
  51600. static const unsigned char tickShapeData[] =
  51601. {
  51602. 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,
  51603. 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,
  51604. 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,
  51605. 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,
  51606. 96,140,68,0,128,188,67,0,224,168,68,0,0,119,67,99,101
  51607. };
  51608. Path p;
  51609. p.loadPathFromData (tickShapeData, sizeof (tickShapeData));
  51610. p.scaleToFit (0, 0, height * 2.0f, height, true);
  51611. return p;
  51612. }
  51613. const Path LookAndFeel::getCrossShape (const float height)
  51614. {
  51615. static const unsigned char crossShapeData[] =
  51616. {
  51617. 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,
  51618. 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,
  51619. 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,
  51620. 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,
  51621. 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,
  51622. 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,
  51623. 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
  51624. };
  51625. Path p;
  51626. p.loadPathFromData (crossShapeData, sizeof (crossShapeData));
  51627. p.scaleToFit (0, 0, height * 2.0f, height, true);
  51628. return p;
  51629. }
  51630. void LookAndFeel::drawTreeviewPlusMinusBox (Graphics& g, int x, int y, int w, int h, bool isPlus, bool /*isMouseOver*/)
  51631. {
  51632. const int boxSize = ((jmin (16, w, h) << 1) / 3) | 1;
  51633. x += (w - boxSize) >> 1;
  51634. y += (h - boxSize) >> 1;
  51635. w = boxSize;
  51636. h = boxSize;
  51637. g.setColour (Colour (0xe5ffffff));
  51638. g.fillRect (x, y, w, h);
  51639. g.setColour (Colour (0x80000000));
  51640. g.drawRect (x, y, w, h);
  51641. const float size = boxSize / 2 + 1.0f;
  51642. const float centre = (float) (boxSize / 2);
  51643. g.fillRect (x + (w - size) * 0.5f, y + centre, size, 1.0f);
  51644. if (isPlus)
  51645. g.fillRect (x + centre, y + (h - size) * 0.5f, 1.0f, size);
  51646. }
  51647. void LookAndFeel::drawBubble (Graphics& g,
  51648. float tipX, float tipY,
  51649. float boxX, float boxY,
  51650. float boxW, float boxH)
  51651. {
  51652. int side = 0;
  51653. if (tipX < boxX)
  51654. side = 1;
  51655. else if (tipX > boxX + boxW)
  51656. side = 3;
  51657. else if (tipY > boxY + boxH)
  51658. side = 2;
  51659. const float indent = 2.0f;
  51660. Path p;
  51661. p.addBubble (boxX + indent,
  51662. boxY + indent,
  51663. boxW - indent * 2.0f,
  51664. boxH - indent * 2.0f,
  51665. 5.0f,
  51666. tipX, tipY,
  51667. side,
  51668. 0.5f,
  51669. jmin (15.0f, boxW * 0.3f, boxH * 0.3f));
  51670. //xxx need to take comp as param for colour
  51671. g.setColour (findColour (TooltipWindow::backgroundColourId).withAlpha (0.9f));
  51672. g.fillPath (p);
  51673. //xxx as above
  51674. g.setColour (findColour (TooltipWindow::textColourId).withAlpha (0.4f));
  51675. g.strokePath (p, PathStrokeType (1.33f));
  51676. }
  51677. const Font LookAndFeel::getPopupMenuFont()
  51678. {
  51679. return Font (17.0f);
  51680. }
  51681. void LookAndFeel::getIdealPopupMenuItemSize (const String& text,
  51682. const bool isSeparator,
  51683. int standardMenuItemHeight,
  51684. int& idealWidth,
  51685. int& idealHeight)
  51686. {
  51687. if (isSeparator)
  51688. {
  51689. idealWidth = 50;
  51690. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight / 2 : 10;
  51691. }
  51692. else
  51693. {
  51694. Font font (getPopupMenuFont());
  51695. if (standardMenuItemHeight > 0 && font.getHeight() > standardMenuItemHeight / 1.3f)
  51696. font.setHeight (standardMenuItemHeight / 1.3f);
  51697. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight : roundToInt (font.getHeight() * 1.3f);
  51698. idealWidth = font.getStringWidth (text) + idealHeight * 2;
  51699. }
  51700. }
  51701. void LookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  51702. {
  51703. const Colour background (findColour (PopupMenu::backgroundColourId));
  51704. g.fillAll (background);
  51705. g.setColour (background.overlaidWith (Colour (0x2badd8e6)));
  51706. for (int i = 0; i < height; i += 3)
  51707. g.fillRect (0, i, width, 1);
  51708. #if ! JUCE_MAC
  51709. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.6f));
  51710. g.drawRect (0, 0, width, height);
  51711. #endif
  51712. }
  51713. void LookAndFeel::drawPopupMenuUpDownArrow (Graphics& g,
  51714. int width, int height,
  51715. bool isScrollUpArrow)
  51716. {
  51717. const Colour background (findColour (PopupMenu::backgroundColourId));
  51718. g.setGradientFill (ColourGradient (background, 0.0f, height * 0.5f,
  51719. background.withAlpha (0.0f),
  51720. 0.0f, isScrollUpArrow ? ((float) height) : 0.0f,
  51721. false));
  51722. g.fillRect (1, 1, width - 2, height - 2);
  51723. const float hw = width * 0.5f;
  51724. const float arrowW = height * 0.3f;
  51725. const float y1 = height * (isScrollUpArrow ? 0.6f : 0.3f);
  51726. const float y2 = height * (isScrollUpArrow ? 0.3f : 0.6f);
  51727. Path p;
  51728. p.addTriangle (hw - arrowW, y1,
  51729. hw + arrowW, y1,
  51730. hw, y2);
  51731. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.5f));
  51732. g.fillPath (p);
  51733. }
  51734. void LookAndFeel::drawPopupMenuItem (Graphics& g,
  51735. int width, int height,
  51736. const bool isSeparator,
  51737. const bool isActive,
  51738. const bool isHighlighted,
  51739. const bool isTicked,
  51740. const bool hasSubMenu,
  51741. const String& text,
  51742. const String& shortcutKeyText,
  51743. Image* image,
  51744. const Colour* const textColourToUse)
  51745. {
  51746. const float halfH = height * 0.5f;
  51747. if (isSeparator)
  51748. {
  51749. const float separatorIndent = 5.5f;
  51750. g.setColour (Colour (0x33000000));
  51751. g.drawLine (separatorIndent, halfH, width - separatorIndent, halfH);
  51752. g.setColour (Colour (0x66ffffff));
  51753. g.drawLine (separatorIndent, halfH + 1.0f, width - separatorIndent, halfH + 1.0f);
  51754. }
  51755. else
  51756. {
  51757. Colour textColour (findColour (PopupMenu::textColourId));
  51758. if (textColourToUse != 0)
  51759. textColour = *textColourToUse;
  51760. if (isHighlighted)
  51761. {
  51762. g.setColour (findColour (PopupMenu::highlightedBackgroundColourId));
  51763. g.fillRect (1, 1, width - 2, height - 2);
  51764. g.setColour (findColour (PopupMenu::highlightedTextColourId));
  51765. }
  51766. else
  51767. {
  51768. g.setColour (textColour);
  51769. }
  51770. if (! isActive)
  51771. g.setOpacity (0.3f);
  51772. Font font (getPopupMenuFont());
  51773. if (font.getHeight() > height / 1.3f)
  51774. font.setHeight (height / 1.3f);
  51775. g.setFont (font);
  51776. const int leftBorder = (height * 5) / 4;
  51777. const int rightBorder = 4;
  51778. if (image != 0)
  51779. {
  51780. g.drawImageWithin (image,
  51781. 2, 1, leftBorder - 4, height - 2,
  51782. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, false);
  51783. }
  51784. else if (isTicked)
  51785. {
  51786. const Path tick (getTickShape (1.0f));
  51787. const float th = font.getAscent();
  51788. const float ty = halfH - th * 0.5f;
  51789. g.fillPath (tick, tick.getTransformToScaleToFit (2.0f, ty, (float) (leftBorder - 4),
  51790. th, true));
  51791. }
  51792. g.drawFittedText (text,
  51793. leftBorder, 0,
  51794. width - (leftBorder + rightBorder), height,
  51795. Justification::centredLeft, 1);
  51796. if (shortcutKeyText.isNotEmpty())
  51797. {
  51798. Font f2 (font);
  51799. f2.setHeight (f2.getHeight() * 0.75f);
  51800. f2.setHorizontalScale (0.95f);
  51801. g.setFont (f2);
  51802. g.drawText (shortcutKeyText,
  51803. leftBorder,
  51804. 0,
  51805. width - (leftBorder + rightBorder + 4),
  51806. height,
  51807. Justification::centredRight,
  51808. true);
  51809. }
  51810. if (hasSubMenu)
  51811. {
  51812. const float arrowH = 0.6f * getPopupMenuFont().getAscent();
  51813. const float x = width - height * 0.6f;
  51814. Path p;
  51815. p.addTriangle (x, halfH - arrowH * 0.5f,
  51816. x, halfH + arrowH * 0.5f,
  51817. x + arrowH * 0.6f, halfH);
  51818. g.fillPath (p);
  51819. }
  51820. }
  51821. }
  51822. int LookAndFeel::getMenuWindowFlags()
  51823. {
  51824. return ComponentPeer::windowHasDropShadow;
  51825. }
  51826. void LookAndFeel::drawMenuBarBackground (Graphics& g, int width, int height,
  51827. bool, MenuBarComponent& menuBar)
  51828. {
  51829. const Colour baseColour (createBaseColour (menuBar.findColour (PopupMenu::backgroundColourId), false, false, false));
  51830. if (menuBar.isEnabled())
  51831. {
  51832. drawShinyButtonShape (g,
  51833. -4.0f, 0.0f,
  51834. width + 8.0f, (float) height,
  51835. 0.0f,
  51836. baseColour,
  51837. 0.4f,
  51838. true, true, true, true);
  51839. }
  51840. else
  51841. {
  51842. g.fillAll (baseColour);
  51843. }
  51844. }
  51845. const Font LookAndFeel::getMenuBarFont (MenuBarComponent& menuBar, int /*itemIndex*/, const String& /*itemText*/)
  51846. {
  51847. return Font (menuBar.getHeight() * 0.7f);
  51848. }
  51849. int LookAndFeel::getMenuBarItemWidth (MenuBarComponent& menuBar, int itemIndex, const String& itemText)
  51850. {
  51851. return getMenuBarFont (menuBar, itemIndex, itemText)
  51852. .getStringWidth (itemText) + menuBar.getHeight();
  51853. }
  51854. void LookAndFeel::drawMenuBarItem (Graphics& g,
  51855. int width, int height,
  51856. int itemIndex,
  51857. const String& itemText,
  51858. bool isMouseOverItem,
  51859. bool isMenuOpen,
  51860. bool /*isMouseOverBar*/,
  51861. MenuBarComponent& menuBar)
  51862. {
  51863. if (! menuBar.isEnabled())
  51864. {
  51865. g.setColour (menuBar.findColour (PopupMenu::textColourId)
  51866. .withMultipliedAlpha (0.5f));
  51867. }
  51868. else if (isMenuOpen || isMouseOverItem)
  51869. {
  51870. g.fillAll (menuBar.findColour (PopupMenu::highlightedBackgroundColourId));
  51871. g.setColour (menuBar.findColour (PopupMenu::highlightedTextColourId));
  51872. }
  51873. else
  51874. {
  51875. g.setColour (menuBar.findColour (PopupMenu::textColourId));
  51876. }
  51877. g.setFont (getMenuBarFont (menuBar, itemIndex, itemText));
  51878. g.drawFittedText (itemText, 0, 0, width, height, Justification::centred, 1);
  51879. }
  51880. void LookAndFeel::fillTextEditorBackground (Graphics& g, int /*width*/, int /*height*/,
  51881. TextEditor& textEditor)
  51882. {
  51883. g.fillAll (textEditor.findColour (TextEditor::backgroundColourId));
  51884. }
  51885. void LookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  51886. {
  51887. if (textEditor.isEnabled())
  51888. {
  51889. if (textEditor.hasKeyboardFocus (true) && ! textEditor.isReadOnly())
  51890. {
  51891. const int border = 2;
  51892. g.setColour (textEditor.findColour (TextEditor::focusedOutlineColourId));
  51893. g.drawRect (0, 0, width, height, border);
  51894. g.setOpacity (1.0f);
  51895. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId).withMultipliedAlpha (0.75f));
  51896. g.drawBevel (0, 0, width, height + 2, border + 2, shadowColour, shadowColour);
  51897. }
  51898. else
  51899. {
  51900. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  51901. g.drawRect (0, 0, width, height);
  51902. g.setOpacity (1.0f);
  51903. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId));
  51904. g.drawBevel (0, 0, width, height + 2, 3, shadowColour, shadowColour);
  51905. }
  51906. }
  51907. }
  51908. void LookAndFeel::drawComboBox (Graphics& g, int width, int height,
  51909. const bool isButtonDown,
  51910. int buttonX, int buttonY,
  51911. int buttonW, int buttonH,
  51912. ComboBox& box)
  51913. {
  51914. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  51915. if (box.isEnabled() && box.hasKeyboardFocus (false))
  51916. {
  51917. g.setColour (box.findColour (TextButton::buttonColourId));
  51918. g.drawRect (0, 0, width, height, 2);
  51919. }
  51920. else
  51921. {
  51922. g.setColour (box.findColour (ComboBox::outlineColourId));
  51923. g.drawRect (0, 0, width, height);
  51924. }
  51925. const float outlineThickness = box.isEnabled() ? (isButtonDown ? 1.2f : 0.5f) : 0.3f;
  51926. const Colour baseColour (createBaseColour (box.findColour (ComboBox::buttonColourId),
  51927. box.hasKeyboardFocus (true),
  51928. false, isButtonDown)
  51929. .withMultipliedAlpha (box.isEnabled() ? 1.0f : 0.5f));
  51930. drawGlassLozenge (g,
  51931. buttonX + outlineThickness, buttonY + outlineThickness,
  51932. buttonW - outlineThickness * 2.0f, buttonH - outlineThickness * 2.0f,
  51933. baseColour, outlineThickness, -1.0f,
  51934. true, true, true, true);
  51935. if (box.isEnabled())
  51936. {
  51937. const float arrowX = 0.3f;
  51938. const float arrowH = 0.2f;
  51939. Path p;
  51940. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  51941. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  51942. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  51943. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  51944. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  51945. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  51946. g.setColour (box.findColour (ComboBox::arrowColourId));
  51947. g.fillPath (p);
  51948. }
  51949. }
  51950. const Font LookAndFeel::getComboBoxFont (ComboBox& box)
  51951. {
  51952. return Font (jmin (15.0f, box.getHeight() * 0.85f));
  51953. }
  51954. Label* LookAndFeel::createComboBoxTextBox (ComboBox&)
  51955. {
  51956. return new Label (String::empty, String::empty);
  51957. }
  51958. void LookAndFeel::positionComboBoxText (ComboBox& box, Label& label)
  51959. {
  51960. label.setBounds (1, 1,
  51961. box.getWidth() + 3 - box.getHeight(),
  51962. box.getHeight() - 2);
  51963. label.setFont (getComboBoxFont (box));
  51964. }
  51965. void LookAndFeel::drawLabel (Graphics& g, Label& label)
  51966. {
  51967. g.fillAll (label.findColour (Label::backgroundColourId));
  51968. if (! label.isBeingEdited())
  51969. {
  51970. const float alpha = label.isEnabled() ? 1.0f : 0.5f;
  51971. g.setColour (label.findColour (Label::textColourId).withMultipliedAlpha (alpha));
  51972. g.setFont (label.getFont());
  51973. g.drawFittedText (label.getText(),
  51974. label.getHorizontalBorderSize(),
  51975. label.getVerticalBorderSize(),
  51976. label.getWidth() - 2 * label.getHorizontalBorderSize(),
  51977. label.getHeight() - 2 * label.getVerticalBorderSize(),
  51978. label.getJustificationType(),
  51979. jmax (1, (int) (label.getHeight() / label.getFont().getHeight())),
  51980. label.getMinimumHorizontalScale());
  51981. g.setColour (label.findColour (Label::outlineColourId).withMultipliedAlpha (alpha));
  51982. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  51983. }
  51984. else if (label.isEnabled())
  51985. {
  51986. g.setColour (label.findColour (Label::outlineColourId));
  51987. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  51988. }
  51989. }
  51990. void LookAndFeel::drawLinearSliderBackground (Graphics& g,
  51991. int x, int y,
  51992. int width, int height,
  51993. float /*sliderPos*/,
  51994. float /*minSliderPos*/,
  51995. float /*maxSliderPos*/,
  51996. const Slider::SliderStyle /*style*/,
  51997. Slider& slider)
  51998. {
  51999. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52000. const Colour trackColour (slider.findColour (Slider::trackColourId));
  52001. const Colour gradCol1 (trackColour.overlaidWith (Colours::black.withAlpha (slider.isEnabled() ? 0.25f : 0.13f)));
  52002. const Colour gradCol2 (trackColour.overlaidWith (Colour (0x14000000)));
  52003. Path indent;
  52004. if (slider.isHorizontal())
  52005. {
  52006. const float iy = y + height * 0.5f - sliderRadius * 0.5f;
  52007. const float ih = sliderRadius;
  52008. g.setGradientFill (ColourGradient (gradCol1, 0.0f, iy,
  52009. gradCol2, 0.0f, iy + ih, false));
  52010. indent.addRoundedRectangle (x - sliderRadius * 0.5f, iy,
  52011. width + sliderRadius, ih,
  52012. 5.0f);
  52013. g.fillPath (indent);
  52014. }
  52015. else
  52016. {
  52017. const float ix = x + width * 0.5f - sliderRadius * 0.5f;
  52018. const float iw = sliderRadius;
  52019. g.setGradientFill (ColourGradient (gradCol1, ix, 0.0f,
  52020. gradCol2, ix + iw, 0.0f, false));
  52021. indent.addRoundedRectangle (ix, y - sliderRadius * 0.5f,
  52022. iw, height + sliderRadius,
  52023. 5.0f);
  52024. g.fillPath (indent);
  52025. }
  52026. g.setColour (Colour (0x4c000000));
  52027. g.strokePath (indent, PathStrokeType (0.5f));
  52028. }
  52029. void LookAndFeel::drawLinearSliderThumb (Graphics& g,
  52030. int x, int y,
  52031. int width, int height,
  52032. float sliderPos,
  52033. float minSliderPos,
  52034. float maxSliderPos,
  52035. const Slider::SliderStyle style,
  52036. Slider& slider)
  52037. {
  52038. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52039. Colour knobColour (createBaseColour (slider.findColour (Slider::thumbColourId),
  52040. slider.hasKeyboardFocus (false) && slider.isEnabled(),
  52041. slider.isMouseOverOrDragging() && slider.isEnabled(),
  52042. slider.isMouseButtonDown() && slider.isEnabled()));
  52043. const float outlineThickness = slider.isEnabled() ? 0.8f : 0.3f;
  52044. if (style == Slider::LinearHorizontal || style == Slider::LinearVertical)
  52045. {
  52046. float kx, ky;
  52047. if (style == Slider::LinearVertical)
  52048. {
  52049. kx = x + width * 0.5f;
  52050. ky = sliderPos;
  52051. }
  52052. else
  52053. {
  52054. kx = sliderPos;
  52055. ky = y + height * 0.5f;
  52056. }
  52057. drawGlassSphere (g,
  52058. kx - sliderRadius,
  52059. ky - sliderRadius,
  52060. sliderRadius * 2.0f,
  52061. knobColour, outlineThickness);
  52062. }
  52063. else
  52064. {
  52065. if (style == Slider::ThreeValueVertical)
  52066. {
  52067. drawGlassSphere (g, x + width * 0.5f - sliderRadius,
  52068. sliderPos - sliderRadius,
  52069. sliderRadius * 2.0f,
  52070. knobColour, outlineThickness);
  52071. }
  52072. else if (style == Slider::ThreeValueHorizontal)
  52073. {
  52074. drawGlassSphere (g,sliderPos - sliderRadius,
  52075. y + height * 0.5f - sliderRadius,
  52076. sliderRadius * 2.0f,
  52077. knobColour, outlineThickness);
  52078. }
  52079. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  52080. {
  52081. const float sr = jmin (sliderRadius, width * 0.4f);
  52082. drawGlassPointer (g, jmax (0.0f, x + width * 0.5f - sliderRadius * 2.0f),
  52083. minSliderPos - sliderRadius,
  52084. sliderRadius * 2.0f, knobColour, outlineThickness, 1);
  52085. drawGlassPointer (g, jmin (x + width - sliderRadius * 2.0f, x + width * 0.5f), maxSliderPos - sr,
  52086. sliderRadius * 2.0f, knobColour, outlineThickness, 3);
  52087. }
  52088. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  52089. {
  52090. const float sr = jmin (sliderRadius, height * 0.4f);
  52091. drawGlassPointer (g, minSliderPos - sr,
  52092. jmax (0.0f, y + height * 0.5f - sliderRadius * 2.0f),
  52093. sliderRadius * 2.0f, knobColour, outlineThickness, 2);
  52094. drawGlassPointer (g, maxSliderPos - sliderRadius,
  52095. jmin (y + height - sliderRadius * 2.0f, y + height * 0.5f),
  52096. sliderRadius * 2.0f, knobColour, outlineThickness, 4);
  52097. }
  52098. }
  52099. }
  52100. void LookAndFeel::drawLinearSlider (Graphics& g,
  52101. int x, int y,
  52102. int width, int height,
  52103. float sliderPos,
  52104. float minSliderPos,
  52105. float maxSliderPos,
  52106. const Slider::SliderStyle style,
  52107. Slider& slider)
  52108. {
  52109. g.fillAll (slider.findColour (Slider::backgroundColourId));
  52110. if (style == Slider::LinearBar)
  52111. {
  52112. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52113. Colour baseColour (createBaseColour (slider.findColour (Slider::thumbColourId)
  52114. .withMultipliedSaturation (slider.isEnabled() ? 1.0f : 0.5f),
  52115. false,
  52116. isMouseOver,
  52117. isMouseOver || slider.isMouseButtonDown()));
  52118. drawShinyButtonShape (g,
  52119. (float) x, (float) y, sliderPos - (float) x, (float) height, 0.0f,
  52120. baseColour,
  52121. slider.isEnabled() ? 0.9f : 0.3f,
  52122. true, true, true, true);
  52123. }
  52124. else
  52125. {
  52126. drawLinearSliderBackground (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52127. drawLinearSliderThumb (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52128. }
  52129. }
  52130. int LookAndFeel::getSliderThumbRadius (Slider& slider)
  52131. {
  52132. return jmin (7,
  52133. slider.getHeight() / 2,
  52134. slider.getWidth() / 2) + 2;
  52135. }
  52136. void LookAndFeel::drawRotarySlider (Graphics& g,
  52137. int x, int y,
  52138. int width, int height,
  52139. float sliderPos,
  52140. const float rotaryStartAngle,
  52141. const float rotaryEndAngle,
  52142. Slider& slider)
  52143. {
  52144. const float radius = jmin (width / 2, height / 2) - 2.0f;
  52145. const float centreX = x + width * 0.5f;
  52146. const float centreY = y + height * 0.5f;
  52147. const float rx = centreX - radius;
  52148. const float ry = centreY - radius;
  52149. const float rw = radius * 2.0f;
  52150. const float angle = rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle);
  52151. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52152. if (radius > 12.0f)
  52153. {
  52154. if (slider.isEnabled())
  52155. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52156. else
  52157. g.setColour (Colour (0x80808080));
  52158. const float thickness = 0.7f;
  52159. {
  52160. Path filledArc;
  52161. filledArc.addPieSegment (rx, ry, rw, rw,
  52162. rotaryStartAngle,
  52163. angle,
  52164. thickness);
  52165. g.fillPath (filledArc);
  52166. }
  52167. if (thickness > 0)
  52168. {
  52169. const float innerRadius = radius * 0.2f;
  52170. Path p;
  52171. p.addTriangle (-innerRadius, 0.0f,
  52172. 0.0f, -radius * thickness * 1.1f,
  52173. innerRadius, 0.0f);
  52174. p.addEllipse (-innerRadius, -innerRadius, innerRadius * 2.0f, innerRadius * 2.0f);
  52175. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52176. }
  52177. if (slider.isEnabled())
  52178. g.setColour (slider.findColour (Slider::rotarySliderOutlineColourId));
  52179. else
  52180. g.setColour (Colour (0x80808080));
  52181. Path outlineArc;
  52182. outlineArc.addPieSegment (rx, ry, rw, rw, rotaryStartAngle, rotaryEndAngle, thickness);
  52183. outlineArc.closeSubPath();
  52184. g.strokePath (outlineArc, PathStrokeType (slider.isEnabled() ? (isMouseOver ? 2.0f : 1.2f) : 0.3f));
  52185. }
  52186. else
  52187. {
  52188. if (slider.isEnabled())
  52189. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52190. else
  52191. g.setColour (Colour (0x80808080));
  52192. Path p;
  52193. p.addEllipse (-0.4f * rw, -0.4f * rw, rw * 0.8f, rw * 0.8f);
  52194. PathStrokeType (rw * 0.1f).createStrokedPath (p, p);
  52195. p.addLineSegment (0.0f, 0.0f, 0.0f, -radius, rw * 0.2f);
  52196. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52197. }
  52198. }
  52199. Button* LookAndFeel::createSliderButton (const bool isIncrement)
  52200. {
  52201. return new TextButton (isIncrement ? "+" : "-", String::empty);
  52202. }
  52203. class SliderLabelComp : public Label
  52204. {
  52205. public:
  52206. SliderLabelComp() : Label (String::empty, String::empty) {}
  52207. ~SliderLabelComp() {}
  52208. void mouseWheelMove (const MouseEvent&, float, float) {}
  52209. };
  52210. Label* LookAndFeel::createSliderTextBox (Slider& slider)
  52211. {
  52212. Label* const l = new SliderLabelComp();
  52213. l->setJustificationType (Justification::centred);
  52214. l->setColour (Label::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52215. l->setColour (Label::backgroundColourId,
  52216. (slider.getSliderStyle() == Slider::LinearBar) ? Colours::transparentBlack
  52217. : slider.findColour (Slider::textBoxBackgroundColourId));
  52218. l->setColour (Label::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52219. l->setColour (TextEditor::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52220. l->setColour (TextEditor::backgroundColourId,
  52221. slider.findColour (Slider::textBoxBackgroundColourId)
  52222. .withAlpha (slider.getSliderStyle() == Slider::LinearBar ? 0.7f : 1.0f));
  52223. l->setColour (TextEditor::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52224. return l;
  52225. }
  52226. ImageEffectFilter* LookAndFeel::getSliderEffect()
  52227. {
  52228. return 0;
  52229. }
  52230. static const TextLayout layoutTooltipText (const String& text) throw()
  52231. {
  52232. const float tooltipFontSize = 12.0f;
  52233. const int maxToolTipWidth = 400;
  52234. const Font f (tooltipFontSize, Font::bold);
  52235. TextLayout tl (text, f);
  52236. tl.layout (maxToolTipWidth, Justification::left, true);
  52237. return tl;
  52238. }
  52239. void LookAndFeel::getTooltipSize (const String& tipText, int& width, int& height)
  52240. {
  52241. const TextLayout tl (layoutTooltipText (tipText));
  52242. width = tl.getWidth() + 14;
  52243. height = tl.getHeight() + 6;
  52244. }
  52245. void LookAndFeel::drawTooltip (Graphics& g, const String& text, int width, int height)
  52246. {
  52247. g.fillAll (findColour (TooltipWindow::backgroundColourId));
  52248. const Colour textCol (findColour (TooltipWindow::textColourId));
  52249. #if ! JUCE_MAC // The mac windows already have a non-optional 1 pix outline, so don't double it here..
  52250. g.setColour (findColour (TooltipWindow::outlineColourId));
  52251. g.drawRect (0, 0, width, height, 1);
  52252. #endif
  52253. const TextLayout tl (layoutTooltipText (text));
  52254. g.setColour (findColour (TooltipWindow::textColourId));
  52255. tl.drawWithin (g, 0, 0, width, height, Justification::centred);
  52256. }
  52257. Button* LookAndFeel::createFilenameComponentBrowseButton (const String& text)
  52258. {
  52259. return new TextButton (text, TRANS("click to browse for a different file"));
  52260. }
  52261. void LookAndFeel::layoutFilenameComponent (FilenameComponent& filenameComp,
  52262. ComboBox* filenameBox,
  52263. Button* browseButton)
  52264. {
  52265. browseButton->setSize (80, filenameComp.getHeight());
  52266. TextButton* const tb = dynamic_cast <TextButton*> (browseButton);
  52267. if (tb != 0)
  52268. tb->changeWidthToFitText();
  52269. browseButton->setTopRightPosition (filenameComp.getWidth(), 0);
  52270. filenameBox->setBounds (0, 0, browseButton->getX(), filenameComp.getHeight());
  52271. }
  52272. void LookAndFeel::drawImageButton (Graphics& g, Image* image,
  52273. int imageX, int imageY, int imageW, int imageH,
  52274. const Colour& overlayColour,
  52275. float imageOpacity,
  52276. ImageButton& button)
  52277. {
  52278. if (! button.isEnabled())
  52279. imageOpacity *= 0.3f;
  52280. if (! overlayColour.isOpaque())
  52281. {
  52282. g.setOpacity (imageOpacity);
  52283. g.drawImage (image, imageX, imageY, imageW, imageH,
  52284. 0, 0, image->getWidth(), image->getHeight(), false);
  52285. }
  52286. if (! overlayColour.isTransparent())
  52287. {
  52288. g.setColour (overlayColour);
  52289. g.drawImage (image, imageX, imageY, imageW, imageH,
  52290. 0, 0, image->getWidth(), image->getHeight(), true);
  52291. }
  52292. }
  52293. void LookAndFeel::drawCornerResizer (Graphics& g,
  52294. int w, int h,
  52295. bool /*isMouseOver*/,
  52296. bool /*isMouseDragging*/)
  52297. {
  52298. const float lineThickness = jmin (w, h) * 0.075f;
  52299. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  52300. {
  52301. g.setColour (Colours::lightgrey);
  52302. g.drawLine (w * i,
  52303. h + 1.0f,
  52304. w + 1.0f,
  52305. h * i,
  52306. lineThickness);
  52307. g.setColour (Colours::darkgrey);
  52308. g.drawLine (w * i + lineThickness,
  52309. h + 1.0f,
  52310. w + 1.0f,
  52311. h * i + lineThickness,
  52312. lineThickness);
  52313. }
  52314. }
  52315. void LookAndFeel::drawResizableFrame (Graphics&, int /*w*/, int /*h*/,
  52316. const BorderSize& /*borders*/)
  52317. {
  52318. }
  52319. void LookAndFeel::fillResizableWindowBackground (Graphics& g, int /*w*/, int /*h*/,
  52320. const BorderSize& /*border*/, ResizableWindow& window)
  52321. {
  52322. g.fillAll (window.getBackgroundColour());
  52323. }
  52324. void LookAndFeel::drawResizableWindowBorder (Graphics& g, int w, int h,
  52325. const BorderSize& border, ResizableWindow&)
  52326. {
  52327. g.setColour (Colour (0x80000000));
  52328. g.drawRect (0, 0, w, h);
  52329. g.setColour (Colour (0x19000000));
  52330. g.drawRect (border.getLeft() - 1,
  52331. border.getTop() - 1,
  52332. w + 2 - border.getLeftAndRight(),
  52333. h + 2 - border.getTopAndBottom());
  52334. }
  52335. void LookAndFeel::drawDocumentWindowTitleBar (DocumentWindow& window,
  52336. Graphics& g, int w, int h,
  52337. int titleSpaceX, int titleSpaceW,
  52338. const Image* icon,
  52339. bool drawTitleTextOnLeft)
  52340. {
  52341. const bool isActive = window.isActiveWindow();
  52342. g.setGradientFill (ColourGradient (window.getBackgroundColour(),
  52343. 0.0f, 0.0f,
  52344. window.getBackgroundColour().contrasting (isActive ? 0.15f : 0.05f),
  52345. 0.0f, (float) h, false));
  52346. g.fillAll();
  52347. Font font (h * 0.65f, Font::bold);
  52348. g.setFont (font);
  52349. int textW = font.getStringWidth (window.getName());
  52350. int iconW = 0;
  52351. int iconH = 0;
  52352. if (icon != 0)
  52353. {
  52354. iconH = (int) font.getHeight();
  52355. iconW = icon->getWidth() * iconH / icon->getHeight() + 4;
  52356. }
  52357. textW = jmin (titleSpaceW, textW + iconW);
  52358. int textX = drawTitleTextOnLeft ? titleSpaceX
  52359. : jmax (titleSpaceX, (w - textW) / 2);
  52360. if (textX + textW > titleSpaceX + titleSpaceW)
  52361. textX = titleSpaceX + titleSpaceW - textW;
  52362. if (icon != 0)
  52363. {
  52364. g.setOpacity (isActive ? 1.0f : 0.6f);
  52365. g.drawImageWithin (icon, textX, (h - iconH) / 2, iconW, iconH,
  52366. RectanglePlacement::centred, false);
  52367. textX += iconW;
  52368. textW -= iconW;
  52369. }
  52370. if (window.isColourSpecified (DocumentWindow::textColourId) || isColourSpecified (DocumentWindow::textColourId))
  52371. g.setColour (findColour (DocumentWindow::textColourId));
  52372. else
  52373. g.setColour (window.getBackgroundColour().contrasting (isActive ? 0.7f : 0.4f));
  52374. g.drawText (window.getName(), textX, 0, textW, h, Justification::centredLeft, true);
  52375. }
  52376. class GlassWindowButton : public Button
  52377. {
  52378. public:
  52379. GlassWindowButton (const String& name, const Colour& col,
  52380. const Path& normalShape_,
  52381. const Path& toggledShape_) throw()
  52382. : Button (name),
  52383. colour (col),
  52384. normalShape (normalShape_),
  52385. toggledShape (toggledShape_)
  52386. {
  52387. }
  52388. ~GlassWindowButton()
  52389. {
  52390. }
  52391. void paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  52392. {
  52393. float alpha = isMouseOverButton ? (isButtonDown ? 1.0f : 0.8f) : 0.55f;
  52394. if (! isEnabled())
  52395. alpha *= 0.5f;
  52396. float x = 0, y = 0, diam;
  52397. if (getWidth() < getHeight())
  52398. {
  52399. diam = (float) getWidth();
  52400. y = (getHeight() - getWidth()) * 0.5f;
  52401. }
  52402. else
  52403. {
  52404. diam = (float) getHeight();
  52405. y = (getWidth() - getHeight()) * 0.5f;
  52406. }
  52407. x += diam * 0.05f;
  52408. y += diam * 0.05f;
  52409. diam *= 0.9f;
  52410. g.setGradientFill (ColourGradient (Colour::greyLevel (0.9f).withAlpha (alpha), 0, y + diam,
  52411. Colour::greyLevel (0.6f).withAlpha (alpha), 0, y, false));
  52412. g.fillEllipse (x, y, diam, diam);
  52413. x += 2.0f;
  52414. y += 2.0f;
  52415. diam -= 4.0f;
  52416. LookAndFeel::drawGlassSphere (g, x, y, diam, colour.withAlpha (alpha), 1.0f);
  52417. Path& p = getToggleState() ? toggledShape : normalShape;
  52418. const AffineTransform t (p.getTransformToScaleToFit (x + diam * 0.3f, y + diam * 0.3f,
  52419. diam * 0.4f, diam * 0.4f, true));
  52420. g.setColour (Colours::black.withAlpha (alpha * 0.6f));
  52421. g.fillPath (p, t);
  52422. }
  52423. juce_UseDebuggingNewOperator
  52424. private:
  52425. Colour colour;
  52426. Path normalShape, toggledShape;
  52427. GlassWindowButton (const GlassWindowButton&);
  52428. GlassWindowButton& operator= (const GlassWindowButton&);
  52429. };
  52430. Button* LookAndFeel::createDocumentWindowButton (int buttonType)
  52431. {
  52432. Path shape;
  52433. const float crossThickness = 0.25f;
  52434. if (buttonType == DocumentWindow::closeButton)
  52435. {
  52436. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, crossThickness * 1.4f);
  52437. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, crossThickness * 1.4f);
  52438. return new GlassWindowButton ("close", Colour (0xffdd1100), shape, shape);
  52439. }
  52440. else if (buttonType == DocumentWindow::minimiseButton)
  52441. {
  52442. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  52443. return new GlassWindowButton ("minimise", Colour (0xffaa8811), shape, shape);
  52444. }
  52445. else if (buttonType == DocumentWindow::maximiseButton)
  52446. {
  52447. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, crossThickness);
  52448. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  52449. Path fullscreenShape;
  52450. fullscreenShape.startNewSubPath (45.0f, 100.0f);
  52451. fullscreenShape.lineTo (0.0f, 100.0f);
  52452. fullscreenShape.lineTo (0.0f, 0.0f);
  52453. fullscreenShape.lineTo (100.0f, 0.0f);
  52454. fullscreenShape.lineTo (100.0f, 45.0f);
  52455. fullscreenShape.addRectangle (45.0f, 45.0f, 100.0f, 100.0f);
  52456. PathStrokeType (30.0f).createStrokedPath (fullscreenShape, fullscreenShape);
  52457. return new GlassWindowButton ("maximise", Colour (0xff119911), shape, fullscreenShape);
  52458. }
  52459. jassertfalse
  52460. return 0;
  52461. }
  52462. void LookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  52463. int titleBarX,
  52464. int titleBarY,
  52465. int titleBarW,
  52466. int titleBarH,
  52467. Button* minimiseButton,
  52468. Button* maximiseButton,
  52469. Button* closeButton,
  52470. bool positionTitleBarButtonsOnLeft)
  52471. {
  52472. const int buttonW = titleBarH - titleBarH / 8;
  52473. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  52474. : titleBarX + titleBarW - buttonW - buttonW / 4;
  52475. if (closeButton != 0)
  52476. {
  52477. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52478. x += positionTitleBarButtonsOnLeft ? buttonW : -(buttonW + buttonW / 4);
  52479. }
  52480. if (positionTitleBarButtonsOnLeft)
  52481. swapVariables (minimiseButton, maximiseButton);
  52482. if (maximiseButton != 0)
  52483. {
  52484. maximiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52485. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  52486. }
  52487. if (minimiseButton != 0)
  52488. minimiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52489. }
  52490. int LookAndFeel::getDefaultMenuBarHeight()
  52491. {
  52492. return 24;
  52493. }
  52494. DropShadower* LookAndFeel::createDropShadowerForComponent (Component*)
  52495. {
  52496. return new DropShadower (0.4f, 1, 5, 10);
  52497. }
  52498. void LookAndFeel::drawStretchableLayoutResizerBar (Graphics& g,
  52499. int w, int h,
  52500. bool /*isVerticalBar*/,
  52501. bool isMouseOver,
  52502. bool isMouseDragging)
  52503. {
  52504. float alpha = 0.5f;
  52505. if (isMouseOver || isMouseDragging)
  52506. {
  52507. g.fillAll (Colour (0x190000ff));
  52508. alpha = 1.0f;
  52509. }
  52510. const float cx = w * 0.5f;
  52511. const float cy = h * 0.5f;
  52512. const float cr = jmin (w, h) * 0.4f;
  52513. g.setGradientFill (ColourGradient (Colours::white.withAlpha (alpha), cx + cr * 0.1f, cy + cr,
  52514. Colours::black.withAlpha (alpha), cx, cy - cr * 4.0f,
  52515. true));
  52516. g.fillEllipse (cx - cr, cy - cr, cr * 2.0f, cr * 2.0f);
  52517. }
  52518. void LookAndFeel::drawGroupComponentOutline (Graphics& g, int width, int height,
  52519. const String& text,
  52520. const Justification& position,
  52521. GroupComponent& group)
  52522. {
  52523. const float textH = 15.0f;
  52524. const float indent = 3.0f;
  52525. const float textEdgeGap = 4.0f;
  52526. float cs = 5.0f;
  52527. Font f (textH);
  52528. Path p;
  52529. float x = indent;
  52530. float y = f.getAscent() - 3.0f;
  52531. float w = jmax (0.0f, width - x * 2.0f);
  52532. float h = jmax (0.0f, height - y - indent);
  52533. cs = jmin (cs, w * 0.5f, h * 0.5f);
  52534. const float cs2 = 2.0f * cs;
  52535. float textW = text.isEmpty() ? 0 : jlimit (0.0f, jmax (0.0f, w - cs2 - textEdgeGap * 2), f.getStringWidth (text) + textEdgeGap * 2.0f);
  52536. float textX = cs + textEdgeGap;
  52537. if (position.testFlags (Justification::horizontallyCentred))
  52538. textX = cs + (w - cs2 - textW) * 0.5f;
  52539. else if (position.testFlags (Justification::right))
  52540. textX = w - cs - textW - textEdgeGap;
  52541. p.startNewSubPath (x + textX + textW, y);
  52542. p.lineTo (x + w - cs, y);
  52543. p.addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  52544. p.lineTo (x + w, y + h - cs);
  52545. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  52546. p.lineTo (x + cs, y + h);
  52547. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  52548. p.lineTo (x, y + cs);
  52549. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  52550. p.lineTo (x + textX, y);
  52551. const float alpha = group.isEnabled() ? 1.0f : 0.5f;
  52552. g.setColour (group.findColour (GroupComponent::outlineColourId)
  52553. .withMultipliedAlpha (alpha));
  52554. g.strokePath (p, PathStrokeType (2.0f));
  52555. g.setColour (group.findColour (GroupComponent::textColourId)
  52556. .withMultipliedAlpha (alpha));
  52557. g.setFont (f);
  52558. g.drawText (text,
  52559. roundToInt (x + textX), 0,
  52560. roundToInt (textW),
  52561. roundToInt (textH),
  52562. Justification::centred, true);
  52563. }
  52564. int LookAndFeel::getTabButtonOverlap (int tabDepth)
  52565. {
  52566. return 1 + tabDepth / 3;
  52567. }
  52568. int LookAndFeel::getTabButtonSpaceAroundImage()
  52569. {
  52570. return 4;
  52571. }
  52572. void LookAndFeel::createTabButtonShape (Path& p,
  52573. int width, int height,
  52574. int /*tabIndex*/,
  52575. const String& /*text*/,
  52576. Button& /*button*/,
  52577. TabbedButtonBar::Orientation orientation,
  52578. const bool /*isMouseOver*/,
  52579. const bool /*isMouseDown*/,
  52580. const bool /*isFrontTab*/)
  52581. {
  52582. const float w = (float) width;
  52583. const float h = (float) height;
  52584. float length = w;
  52585. float depth = h;
  52586. if (orientation == TabbedButtonBar::TabsAtLeft
  52587. || orientation == TabbedButtonBar::TabsAtRight)
  52588. {
  52589. swapVariables (length, depth);
  52590. }
  52591. const float indent = (float) getTabButtonOverlap ((int) depth);
  52592. const float overhang = 4.0f;
  52593. if (orientation == TabbedButtonBar::TabsAtLeft)
  52594. {
  52595. p.startNewSubPath (w, 0.0f);
  52596. p.lineTo (0.0f, indent);
  52597. p.lineTo (0.0f, h - indent);
  52598. p.lineTo (w, h);
  52599. p.lineTo (w + overhang, h + overhang);
  52600. p.lineTo (w + overhang, -overhang);
  52601. }
  52602. else if (orientation == TabbedButtonBar::TabsAtRight)
  52603. {
  52604. p.startNewSubPath (0.0f, 0.0f);
  52605. p.lineTo (w, indent);
  52606. p.lineTo (w, h - indent);
  52607. p.lineTo (0.0f, h);
  52608. p.lineTo (-overhang, h + overhang);
  52609. p.lineTo (-overhang, -overhang);
  52610. }
  52611. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52612. {
  52613. p.startNewSubPath (0.0f, 0.0f);
  52614. p.lineTo (indent, h);
  52615. p.lineTo (w - indent, h);
  52616. p.lineTo (w, 0.0f);
  52617. p.lineTo (w + overhang, -overhang);
  52618. p.lineTo (-overhang, -overhang);
  52619. }
  52620. else
  52621. {
  52622. p.startNewSubPath (0.0f, h);
  52623. p.lineTo (indent, 0.0f);
  52624. p.lineTo (w - indent, 0.0f);
  52625. p.lineTo (w, h);
  52626. p.lineTo (w + overhang, h + overhang);
  52627. p.lineTo (-overhang, h + overhang);
  52628. }
  52629. p.closeSubPath();
  52630. p = p.createPathWithRoundedCorners (3.0f);
  52631. }
  52632. void LookAndFeel::fillTabButtonShape (Graphics& g,
  52633. const Path& path,
  52634. const Colour& preferredColour,
  52635. int /*tabIndex*/,
  52636. const String& /*text*/,
  52637. Button& button,
  52638. TabbedButtonBar::Orientation /*orientation*/,
  52639. const bool /*isMouseOver*/,
  52640. const bool /*isMouseDown*/,
  52641. const bool isFrontTab)
  52642. {
  52643. g.setColour (isFrontTab ? preferredColour
  52644. : preferredColour.withMultipliedAlpha (0.9f));
  52645. g.fillPath (path);
  52646. g.setColour (button.findColour (isFrontTab ? TabbedButtonBar::frontOutlineColourId
  52647. : TabbedButtonBar::tabOutlineColourId, false)
  52648. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  52649. g.strokePath (path, PathStrokeType (isFrontTab ? 1.0f : 0.5f));
  52650. }
  52651. void LookAndFeel::drawTabButtonText (Graphics& g,
  52652. int x, int y, int w, int h,
  52653. const Colour& preferredBackgroundColour,
  52654. int /*tabIndex*/,
  52655. const String& text,
  52656. Button& button,
  52657. TabbedButtonBar::Orientation orientation,
  52658. const bool isMouseOver,
  52659. const bool isMouseDown,
  52660. const bool isFrontTab)
  52661. {
  52662. int length = w;
  52663. int depth = h;
  52664. if (orientation == TabbedButtonBar::TabsAtLeft
  52665. || orientation == TabbedButtonBar::TabsAtRight)
  52666. {
  52667. swapVariables (length, depth);
  52668. }
  52669. Font font (depth * 0.6f);
  52670. font.setUnderline (button.hasKeyboardFocus (false));
  52671. GlyphArrangement textLayout;
  52672. textLayout.addFittedText (font, text.trim(),
  52673. 0.0f, 0.0f, (float) length, (float) depth,
  52674. Justification::centred,
  52675. jmax (1, depth / 12));
  52676. AffineTransform transform;
  52677. if (orientation == TabbedButtonBar::TabsAtLeft)
  52678. {
  52679. transform = transform.rotated (float_Pi * -0.5f)
  52680. .translated ((float) x, (float) (y + h));
  52681. }
  52682. else if (orientation == TabbedButtonBar::TabsAtRight)
  52683. {
  52684. transform = transform.rotated (float_Pi * 0.5f)
  52685. .translated ((float) (x + w), (float) y);
  52686. }
  52687. else
  52688. {
  52689. transform = transform.translated ((float) x, (float) y);
  52690. }
  52691. if (isFrontTab && (button.isColourSpecified (TabbedButtonBar::frontTextColourId) || isColourSpecified (TabbedButtonBar::frontTextColourId)))
  52692. g.setColour (findColour (TabbedButtonBar::frontTextColourId));
  52693. else if (button.isColourSpecified (TabbedButtonBar::tabTextColourId) || isColourSpecified (TabbedButtonBar::tabTextColourId))
  52694. g.setColour (findColour (TabbedButtonBar::tabTextColourId));
  52695. else
  52696. g.setColour (preferredBackgroundColour.contrasting());
  52697. if (! (isMouseOver || isMouseDown))
  52698. g.setOpacity (0.8f);
  52699. if (! button.isEnabled())
  52700. g.setOpacity (0.3f);
  52701. textLayout.draw (g, transform);
  52702. }
  52703. int LookAndFeel::getTabButtonBestWidth (int /*tabIndex*/,
  52704. const String& text,
  52705. int tabDepth,
  52706. Button&)
  52707. {
  52708. Font f (tabDepth * 0.6f);
  52709. return f.getStringWidth (text.trim()) + getTabButtonOverlap (tabDepth) * 2;
  52710. }
  52711. void LookAndFeel::drawTabButton (Graphics& g,
  52712. int w, int h,
  52713. const Colour& preferredColour,
  52714. int tabIndex,
  52715. const String& text,
  52716. Button& button,
  52717. TabbedButtonBar::Orientation orientation,
  52718. const bool isMouseOver,
  52719. const bool isMouseDown,
  52720. const bool isFrontTab)
  52721. {
  52722. int length = w;
  52723. int depth = h;
  52724. if (orientation == TabbedButtonBar::TabsAtLeft
  52725. || orientation == TabbedButtonBar::TabsAtRight)
  52726. {
  52727. swapVariables (length, depth);
  52728. }
  52729. Path tabShape;
  52730. createTabButtonShape (tabShape, w, h,
  52731. tabIndex, text, button, orientation,
  52732. isMouseOver, isMouseDown, isFrontTab);
  52733. fillTabButtonShape (g, tabShape, preferredColour,
  52734. tabIndex, text, button, orientation,
  52735. isMouseOver, isMouseDown, isFrontTab);
  52736. const int indent = getTabButtonOverlap (depth);
  52737. int x = 0, y = 0;
  52738. if (orientation == TabbedButtonBar::TabsAtLeft
  52739. || orientation == TabbedButtonBar::TabsAtRight)
  52740. {
  52741. y += indent;
  52742. h -= indent * 2;
  52743. }
  52744. else
  52745. {
  52746. x += indent;
  52747. w -= indent * 2;
  52748. }
  52749. drawTabButtonText (g, x, y, w, h, preferredColour,
  52750. tabIndex, text, button, orientation,
  52751. isMouseOver, isMouseDown, isFrontTab);
  52752. }
  52753. void LookAndFeel::drawTabAreaBehindFrontButton (Graphics& g,
  52754. int w, int h,
  52755. TabbedButtonBar& tabBar,
  52756. TabbedButtonBar::Orientation orientation)
  52757. {
  52758. const float shadowSize = 0.2f;
  52759. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  52760. Rectangle<int> shadowRect;
  52761. if (orientation == TabbedButtonBar::TabsAtLeft)
  52762. {
  52763. x1 = (float) w;
  52764. x2 = w * (1.0f - shadowSize);
  52765. shadowRect.setBounds ((int) x2, 0, w - (int) x2, h);
  52766. }
  52767. else if (orientation == TabbedButtonBar::TabsAtRight)
  52768. {
  52769. x2 = w * shadowSize;
  52770. shadowRect.setBounds (0, 0, (int) x2, h);
  52771. }
  52772. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52773. {
  52774. y2 = h * shadowSize;
  52775. shadowRect.setBounds (0, 0, w, (int) y2);
  52776. }
  52777. else
  52778. {
  52779. y1 = (float) h;
  52780. y2 = h * (1.0f - shadowSize);
  52781. shadowRect.setBounds (0, (int) y2, w, h - (int) y2);
  52782. }
  52783. g.setGradientFill (ColourGradient (Colours::black.withAlpha (tabBar.isEnabled() ? 0.3f : 0.15f), x1, y1,
  52784. Colours::transparentBlack, x2, y2, false));
  52785. shadowRect.expand (2, 2);
  52786. g.fillRect (shadowRect);
  52787. g.setColour (Colour (0x80000000));
  52788. if (orientation == TabbedButtonBar::TabsAtLeft)
  52789. {
  52790. g.fillRect (w - 1, 0, 1, h);
  52791. }
  52792. else if (orientation == TabbedButtonBar::TabsAtRight)
  52793. {
  52794. g.fillRect (0, 0, 1, h);
  52795. }
  52796. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52797. {
  52798. g.fillRect (0, 0, w, 1);
  52799. }
  52800. else
  52801. {
  52802. g.fillRect (0, h - 1, w, 1);
  52803. }
  52804. }
  52805. Button* LookAndFeel::createTabBarExtrasButton()
  52806. {
  52807. const float thickness = 7.0f;
  52808. const float indent = 22.0f;
  52809. Path p;
  52810. p.addEllipse (-10.0f, -10.0f, 120.0f, 120.0f);
  52811. DrawablePath ellipse;
  52812. ellipse.setPath (p);
  52813. ellipse.setFill (Colour (0x99ffffff));
  52814. p.clear();
  52815. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  52816. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  52817. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  52818. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  52819. p.setUsingNonZeroWinding (false);
  52820. DrawablePath dp;
  52821. dp.setPath (p);
  52822. dp.setFill (Colour (0x59000000));
  52823. DrawableComposite normalImage;
  52824. normalImage.insertDrawable (ellipse);
  52825. normalImage.insertDrawable (dp);
  52826. dp.setFill (Colour (0xcc000000));
  52827. DrawableComposite overImage;
  52828. overImage.insertDrawable (ellipse);
  52829. overImage.insertDrawable (dp);
  52830. DrawableButton* db = new DrawableButton ("tabs", DrawableButton::ImageFitted);
  52831. db->setImages (&normalImage, &overImage, 0);
  52832. return db;
  52833. }
  52834. void LookAndFeel::drawTableHeaderBackground (Graphics& g, TableHeaderComponent& header)
  52835. {
  52836. g.fillAll (Colours::white);
  52837. const int w = header.getWidth();
  52838. const int h = header.getHeight();
  52839. g.setGradientFill (ColourGradient (Colour (0xffe8ebf9), 0.0f, h * 0.5f,
  52840. Colour (0xfff6f8f9), 0.0f, h - 1.0f,
  52841. false));
  52842. g.fillRect (0, h / 2, w, h);
  52843. g.setColour (Colour (0x33000000));
  52844. g.fillRect (0, h - 1, w, 1);
  52845. for (int i = header.getNumColumns (true); --i >= 0;)
  52846. g.fillRect (header.getColumnPosition (i).getRight() - 1, 0, 1, h - 1);
  52847. }
  52848. void LookAndFeel::drawTableHeaderColumn (Graphics& g, const String& columnName, int /*columnId*/,
  52849. int width, int height,
  52850. bool isMouseOver, bool isMouseDown,
  52851. int columnFlags)
  52852. {
  52853. if (isMouseDown)
  52854. g.fillAll (Colour (0x8899aadd));
  52855. else if (isMouseOver)
  52856. g.fillAll (Colour (0x5599aadd));
  52857. int rightOfText = width - 4;
  52858. if ((columnFlags & (TableHeaderComponent::sortedForwards | TableHeaderComponent::sortedBackwards)) != 0)
  52859. {
  52860. const float top = height * ((columnFlags & TableHeaderComponent::sortedForwards) != 0 ? 0.35f : (1.0f - 0.35f));
  52861. const float bottom = height - top;
  52862. const float w = height * 0.5f;
  52863. const float x = rightOfText - (w * 1.25f);
  52864. rightOfText = (int) x;
  52865. Path sortArrow;
  52866. sortArrow.addTriangle (x, bottom, x + w * 0.5f, top, x + w, bottom);
  52867. g.setColour (Colour (0x99000000));
  52868. g.fillPath (sortArrow);
  52869. }
  52870. g.setColour (Colours::black);
  52871. g.setFont (height * 0.5f, Font::bold);
  52872. const int textX = 4;
  52873. g.drawFittedText (columnName, textX, 0, rightOfText - textX, height, Justification::centredLeft, 1);
  52874. }
  52875. void LookAndFeel::paintToolbarBackground (Graphics& g, int w, int h, Toolbar& toolbar)
  52876. {
  52877. const Colour background (toolbar.findColour (Toolbar::backgroundColourId));
  52878. g.setGradientFill (ColourGradient (background, 0.0f, 0.0f,
  52879. background.darker (0.1f),
  52880. toolbar.isVertical() ? w - 1.0f : 0.0f,
  52881. toolbar.isVertical() ? 0.0f : h - 1.0f,
  52882. false));
  52883. g.fillAll();
  52884. }
  52885. Button* LookAndFeel::createToolbarMissingItemsButton (Toolbar& /*toolbar*/)
  52886. {
  52887. return createTabBarExtrasButton();
  52888. }
  52889. void LookAndFeel::paintToolbarButtonBackground (Graphics& g, int /*width*/, int /*height*/,
  52890. bool isMouseOver, bool isMouseDown,
  52891. ToolbarItemComponent& component)
  52892. {
  52893. if (isMouseDown)
  52894. g.fillAll (component.findColour (Toolbar::buttonMouseDownBackgroundColourId, true));
  52895. else if (isMouseOver)
  52896. g.fillAll (component.findColour (Toolbar::buttonMouseOverBackgroundColourId, true));
  52897. }
  52898. void LookAndFeel::paintToolbarButtonLabel (Graphics& g, int x, int y, int width, int height,
  52899. const String& text, ToolbarItemComponent& component)
  52900. {
  52901. g.setColour (component.findColour (Toolbar::labelTextColourId, true)
  52902. .withAlpha (component.isEnabled() ? 1.0f : 0.25f));
  52903. const float fontHeight = jmin (14.0f, height * 0.85f);
  52904. g.setFont (fontHeight);
  52905. g.drawFittedText (text,
  52906. x, y, width, height,
  52907. Justification::centred,
  52908. jmax (1, height / (int) fontHeight));
  52909. }
  52910. void LookAndFeel::drawPropertyPanelSectionHeader (Graphics& g, const String& name,
  52911. bool isOpen, int width, int height)
  52912. {
  52913. const int buttonSize = (height * 3) / 4;
  52914. const int buttonIndent = (height - buttonSize) / 2;
  52915. drawTreeviewPlusMinusBox (g, buttonIndent, buttonIndent, buttonSize, buttonSize, ! isOpen, false);
  52916. const int textX = buttonIndent * 2 + buttonSize + 2;
  52917. g.setColour (Colours::black);
  52918. g.setFont (height * 0.7f, Font::bold);
  52919. g.drawText (name, textX, 0, width - textX - 4, height, Justification::centredLeft, true);
  52920. }
  52921. void LookAndFeel::drawPropertyComponentBackground (Graphics& g, int width, int height,
  52922. PropertyComponent&)
  52923. {
  52924. g.setColour (Colour (0x66ffffff));
  52925. g.fillRect (0, 0, width, height - 1);
  52926. }
  52927. void LookAndFeel::drawPropertyComponentLabel (Graphics& g, int, int height,
  52928. PropertyComponent& component)
  52929. {
  52930. g.setColour (Colours::black);
  52931. if (! component.isEnabled())
  52932. g.setOpacity (0.6f);
  52933. g.setFont (jmin (height, 24) * 0.65f);
  52934. const Rectangle<int> r (getPropertyComponentContentPosition (component));
  52935. g.drawFittedText (component.getName(),
  52936. 3, r.getY(), r.getX() - 5, r.getHeight(),
  52937. Justification::centredLeft, 2);
  52938. }
  52939. const Rectangle<int> LookAndFeel::getPropertyComponentContentPosition (PropertyComponent& component)
  52940. {
  52941. return Rectangle<int> (component.getWidth() / 3, 1,
  52942. component.getWidth() - component.getWidth() / 3 - 1, component.getHeight() - 3);
  52943. }
  52944. void LookAndFeel::createFileChooserHeaderText (const String& title,
  52945. const String& instructions,
  52946. GlyphArrangement& text,
  52947. int width)
  52948. {
  52949. text.clear();
  52950. text.addJustifiedText (Font (17.0f, Font::bold), title,
  52951. 8.0f, 22.0f, width - 16.0f,
  52952. Justification::centred);
  52953. text.addJustifiedText (Font (14.0f), instructions,
  52954. 8.0f, 24.0f + 16.0f, width - 16.0f,
  52955. Justification::centred);
  52956. }
  52957. void LookAndFeel::drawFileBrowserRow (Graphics& g, int width, int height,
  52958. const String& filename, Image* icon,
  52959. const String& fileSizeDescription,
  52960. const String& fileTimeDescription,
  52961. const bool isDirectory,
  52962. const bool isItemSelected,
  52963. const int /*itemIndex*/)
  52964. {
  52965. if (isItemSelected)
  52966. g.fillAll (findColour (DirectoryContentsDisplayComponent::highlightColourId));
  52967. g.setColour (findColour (DirectoryContentsDisplayComponent::textColourId));
  52968. g.setFont (height * 0.7f);
  52969. Image* im = icon;
  52970. Image* toRelease = 0;
  52971. if (im == 0)
  52972. {
  52973. toRelease = im = (isDirectory ? getDefaultFolderImage()
  52974. : getDefaultDocumentFileImage());
  52975. }
  52976. const int x = 32;
  52977. if (im != 0)
  52978. {
  52979. g.drawImageWithin (im, 2, 2, x - 4, height - 4,
  52980. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  52981. false);
  52982. ImageCache::release (toRelease);
  52983. }
  52984. if (width > 450 && ! isDirectory)
  52985. {
  52986. const int sizeX = roundToInt (width * 0.7f);
  52987. const int dateX = roundToInt (width * 0.8f);
  52988. g.drawFittedText (filename,
  52989. x, 0, sizeX - x, height,
  52990. Justification::centredLeft, 1);
  52991. g.setFont (height * 0.5f);
  52992. g.setColour (Colours::darkgrey);
  52993. if (! isDirectory)
  52994. {
  52995. g.drawFittedText (fileSizeDescription,
  52996. sizeX, 0, dateX - sizeX - 8, height,
  52997. Justification::centredRight, 1);
  52998. g.drawFittedText (fileTimeDescription,
  52999. dateX, 0, width - 8 - dateX, height,
  53000. Justification::centredRight, 1);
  53001. }
  53002. }
  53003. else
  53004. {
  53005. g.drawFittedText (filename,
  53006. x, 0, width - x, height,
  53007. Justification::centredLeft, 1);
  53008. }
  53009. }
  53010. Button* LookAndFeel::createFileBrowserGoUpButton()
  53011. {
  53012. DrawableButton* goUpButton = new DrawableButton ("up", DrawableButton::ImageOnButtonBackground);
  53013. Path arrowPath;
  53014. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  53015. DrawablePath arrowImage;
  53016. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  53017. arrowImage.setPath (arrowPath);
  53018. goUpButton->setImages (&arrowImage);
  53019. return goUpButton;
  53020. }
  53021. void LookAndFeel::layoutFileBrowserComponent (FileBrowserComponent& browserComp,
  53022. DirectoryContentsDisplayComponent* fileListComponent,
  53023. FilePreviewComponent* previewComp,
  53024. ComboBox* currentPathBox,
  53025. TextEditor* filenameBox,
  53026. Button* goUpButton)
  53027. {
  53028. const int x = 8;
  53029. int w = browserComp.getWidth() - x - x;
  53030. if (previewComp != 0)
  53031. {
  53032. const int previewWidth = w / 3;
  53033. previewComp->setBounds (x + w - previewWidth, 0, previewWidth, browserComp.getHeight());
  53034. w -= previewWidth + 4;
  53035. }
  53036. int y = 4;
  53037. const int controlsHeight = 22;
  53038. const int bottomSectionHeight = controlsHeight + 8;
  53039. const int upButtonWidth = 50;
  53040. currentPathBox->setBounds (x, y, w - upButtonWidth - 6, controlsHeight);
  53041. goUpButton->setBounds (x + w - upButtonWidth, y, upButtonWidth, controlsHeight);
  53042. y += controlsHeight + 4;
  53043. Component* const listAsComp = dynamic_cast <Component*> (fileListComponent);
  53044. listAsComp->setBounds (x, y, w, browserComp.getHeight() - y - bottomSectionHeight);
  53045. y = listAsComp->getBottom() + 4;
  53046. filenameBox->setBounds (x + 50, y, w - 50, controlsHeight);
  53047. }
  53048. Image* LookAndFeel::getDefaultFolderImage()
  53049. {
  53050. 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,
  53051. 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,
  53052. 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,
  53053. 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,
  53054. 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,
  53055. 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,
  53056. 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,
  53057. 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,
  53058. 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,
  53059. 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,
  53060. 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,
  53061. 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,
  53062. 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,
  53063. 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,
  53064. 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,
  53065. 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,
  53066. 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,
  53067. 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,
  53068. 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,
  53069. 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,
  53070. 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,
  53071. 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,
  53072. 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,
  53073. 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,
  53074. 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,
  53075. 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,
  53076. 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,
  53077. 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,
  53078. 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,
  53079. 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,
  53080. 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,
  53081. 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,
  53082. 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,
  53083. 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,
  53084. 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,
  53085. 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,
  53086. 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,
  53087. 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,
  53088. 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,
  53089. 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,
  53090. 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,
  53091. 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,
  53092. 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,
  53093. 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};
  53094. return ImageCache::getFromMemory (foldericon_png, sizeof (foldericon_png));
  53095. }
  53096. Image* LookAndFeel::getDefaultDocumentFileImage()
  53097. {
  53098. 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,
  53099. 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,
  53100. 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,
  53101. 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,
  53102. 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,
  53103. 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,
  53104. 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,
  53105. 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,
  53106. 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,
  53107. 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,
  53108. 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,
  53109. 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,
  53110. 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,
  53111. 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,
  53112. 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,
  53113. 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,
  53114. 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,
  53115. 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,
  53116. 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,
  53117. 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,
  53118. 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,
  53119. 174,66,96,130,0,0};
  53120. return ImageCache::getFromMemory (fileicon_png, sizeof (fileicon_png));
  53121. }
  53122. void LookAndFeel::playAlertSound()
  53123. {
  53124. PlatformUtilities::beep();
  53125. }
  53126. void LookAndFeel::drawLevelMeter (Graphics& g, int width, int height, float level)
  53127. {
  53128. g.setColour (Colours::white.withAlpha (0.7f));
  53129. g.fillRoundedRectangle (0.0f, 0.0f, (float) width, (float) height, 3.0f);
  53130. g.setColour (Colours::black.withAlpha (0.2f));
  53131. g.drawRoundedRectangle (1.0f, 1.0f, width - 2.0f, height - 2.0f, 3.0f, 1.0f);
  53132. const int totalBlocks = 7;
  53133. const int numBlocks = roundToInt (totalBlocks * level);
  53134. const float w = (width - 6.0f) / (float) totalBlocks;
  53135. for (int i = 0; i < totalBlocks; ++i)
  53136. {
  53137. if (i >= numBlocks)
  53138. g.setColour (Colours::lightblue.withAlpha (0.6f));
  53139. else
  53140. g.setColour (i < totalBlocks - 1 ? Colours::blue.withAlpha (0.5f)
  53141. : Colours::red);
  53142. g.fillRoundedRectangle (3.0f + i * w + w * 0.1f, 3.0f, w * 0.8f, height - 6.0f, w * 0.4f);
  53143. }
  53144. }
  53145. void LookAndFeel::drawKeymapChangeButton (Graphics& g, int width, int height, Button& button, const String& keyDescription)
  53146. {
  53147. const Colour textColour (button.findColour (KeyMappingEditorComponent::textColourId, true));
  53148. if (keyDescription.isNotEmpty())
  53149. {
  53150. if (button.isEnabled())
  53151. {
  53152. const float alpha = button.isDown() ? 0.3f : (button.isOver() ? 0.15f : 0.08f);
  53153. g.fillAll (textColour.withAlpha (alpha));
  53154. g.setOpacity (0.3f);
  53155. g.drawBevel (0, 0, width, height, 2);
  53156. }
  53157. g.setColour (textColour);
  53158. g.setFont (height * 0.6f);
  53159. g.drawFittedText (keyDescription,
  53160. 3, 0, width - 6, height,
  53161. Justification::centred, 1);
  53162. }
  53163. else
  53164. {
  53165. const float thickness = 7.0f;
  53166. const float indent = 22.0f;
  53167. Path p;
  53168. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  53169. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  53170. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  53171. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  53172. p.setUsingNonZeroWinding (false);
  53173. g.setColour (textColour.withAlpha (button.isDown() ? 0.7f : (button.isOver() ? 0.5f : 0.3f)));
  53174. g.fillPath (p, p.getTransformToScaleToFit (2.0f, 2.0f, width - 4.0f, height - 4.0f, true));
  53175. }
  53176. if (button.hasKeyboardFocus (false))
  53177. {
  53178. g.setColour (textColour.withAlpha (0.4f));
  53179. g.drawRect (0, 0, width, height);
  53180. }
  53181. }
  53182. static void createRoundedPath (Path& p,
  53183. const float x, const float y,
  53184. const float w, const float h,
  53185. const float cs,
  53186. const bool curveTopLeft, const bool curveTopRight,
  53187. const bool curveBottomLeft, const bool curveBottomRight) throw()
  53188. {
  53189. const float cs2 = 2.0f * cs;
  53190. if (curveTopLeft)
  53191. {
  53192. p.startNewSubPath (x, y + cs);
  53193. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  53194. }
  53195. else
  53196. {
  53197. p.startNewSubPath (x, y);
  53198. }
  53199. if (curveTopRight)
  53200. {
  53201. p.lineTo (x + w - cs, y);
  53202. p.addArc (x + w - cs2, y, cs2, cs2, 0.0f, float_Pi * 0.5f);
  53203. }
  53204. else
  53205. {
  53206. p.lineTo (x + w, y);
  53207. }
  53208. if (curveBottomRight)
  53209. {
  53210. p.lineTo (x + w, y + h - cs);
  53211. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  53212. }
  53213. else
  53214. {
  53215. p.lineTo (x + w, y + h);
  53216. }
  53217. if (curveBottomLeft)
  53218. {
  53219. p.lineTo (x + cs, y + h);
  53220. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  53221. }
  53222. else
  53223. {
  53224. p.lineTo (x, y + h);
  53225. }
  53226. p.closeSubPath();
  53227. }
  53228. void LookAndFeel::drawShinyButtonShape (Graphics& g,
  53229. float x, float y, float w, float h,
  53230. float maxCornerSize,
  53231. const Colour& baseColour,
  53232. const float strokeWidth,
  53233. const bool flatOnLeft,
  53234. const bool flatOnRight,
  53235. const bool flatOnTop,
  53236. const bool flatOnBottom) throw()
  53237. {
  53238. if (w <= strokeWidth * 1.1f || h <= strokeWidth * 1.1f)
  53239. return;
  53240. const float cs = jmin (maxCornerSize, w * 0.5f, h * 0.5f);
  53241. Path outline;
  53242. createRoundedPath (outline, x, y, w, h, cs,
  53243. ! (flatOnLeft || flatOnTop),
  53244. ! (flatOnRight || flatOnTop),
  53245. ! (flatOnLeft || flatOnBottom),
  53246. ! (flatOnRight || flatOnBottom));
  53247. ColourGradient cg (baseColour, 0.0f, y,
  53248. baseColour.overlaidWith (Colour (0x070000ff)), 0.0f, y + h,
  53249. false);
  53250. cg.addColour (0.5, baseColour.overlaidWith (Colour (0x33ffffff)));
  53251. cg.addColour (0.51, baseColour.overlaidWith (Colour (0x110000ff)));
  53252. g.setGradientFill (cg);
  53253. g.fillPath (outline);
  53254. g.setColour (Colour (0x80000000));
  53255. g.strokePath (outline, PathStrokeType (strokeWidth));
  53256. }
  53257. void LookAndFeel::drawGlassSphere (Graphics& g,
  53258. const float x, const float y,
  53259. const float diameter,
  53260. const Colour& colour,
  53261. const float outlineThickness) throw()
  53262. {
  53263. if (diameter <= outlineThickness)
  53264. return;
  53265. Path p;
  53266. p.addEllipse (x, y, diameter, diameter);
  53267. {
  53268. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53269. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53270. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53271. g.setGradientFill (cg);
  53272. g.fillPath (p);
  53273. }
  53274. g.setGradientFill (ColourGradient (Colours::white, 0, y + diameter * 0.06f,
  53275. Colours::transparentWhite, 0, y + diameter * 0.3f, false));
  53276. g.fillEllipse (x + diameter * 0.2f, y + diameter * 0.05f, diameter * 0.6f, diameter * 0.4f);
  53277. ColourGradient cg (Colours::transparentBlack,
  53278. x + diameter * 0.5f, y + diameter * 0.5f,
  53279. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53280. x, y + diameter * 0.5f, true);
  53281. cg.addColour (0.7, Colours::transparentBlack);
  53282. cg.addColour (0.8, Colours::black.withAlpha (0.1f * outlineThickness));
  53283. g.setGradientFill (cg);
  53284. g.fillPath (p);
  53285. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53286. g.drawEllipse (x, y, diameter, diameter, outlineThickness);
  53287. }
  53288. void LookAndFeel::drawGlassPointer (Graphics& g,
  53289. const float x, const float y,
  53290. const float diameter,
  53291. const Colour& colour, const float outlineThickness,
  53292. const int direction) throw()
  53293. {
  53294. if (diameter <= outlineThickness)
  53295. return;
  53296. Path p;
  53297. p.startNewSubPath (x + diameter * 0.5f, y);
  53298. p.lineTo (x + diameter, y + diameter * 0.6f);
  53299. p.lineTo (x + diameter, y + diameter);
  53300. p.lineTo (x, y + diameter);
  53301. p.lineTo (x, y + diameter * 0.6f);
  53302. p.closeSubPath();
  53303. p.applyTransform (AffineTransform::rotation (direction * (float_Pi * 0.5f), x + diameter * 0.5f, y + diameter * 0.5f));
  53304. {
  53305. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53306. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53307. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53308. g.setGradientFill (cg);
  53309. g.fillPath (p);
  53310. }
  53311. ColourGradient cg (Colours::transparentBlack,
  53312. x + diameter * 0.5f, y + diameter * 0.5f,
  53313. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53314. x - diameter * 0.2f, y + diameter * 0.5f, true);
  53315. cg.addColour (0.5, Colours::transparentBlack);
  53316. cg.addColour (0.7, Colours::black.withAlpha (0.07f * outlineThickness));
  53317. g.setGradientFill (cg);
  53318. g.fillPath (p);
  53319. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53320. g.strokePath (p, PathStrokeType (outlineThickness));
  53321. }
  53322. void LookAndFeel::drawGlassLozenge (Graphics& g,
  53323. const float x, const float y,
  53324. const float width, const float height,
  53325. const Colour& colour,
  53326. const float outlineThickness,
  53327. const float cornerSize,
  53328. const bool flatOnLeft,
  53329. const bool flatOnRight,
  53330. const bool flatOnTop,
  53331. const bool flatOnBottom) throw()
  53332. {
  53333. if (width <= outlineThickness || height <= outlineThickness)
  53334. return;
  53335. const int intX = (int) x;
  53336. const int intY = (int) y;
  53337. const int intW = (int) width;
  53338. const int intH = (int) height;
  53339. const float cs = cornerSize < 0 ? jmin (width * 0.5f, height * 0.5f) : cornerSize;
  53340. const float edgeBlurRadius = height * 0.75f + (height - cs * 2.0f);
  53341. const int intEdge = (int) edgeBlurRadius;
  53342. Path outline;
  53343. createRoundedPath (outline, x, y, width, height, cs,
  53344. ! (flatOnLeft || flatOnTop),
  53345. ! (flatOnRight || flatOnTop),
  53346. ! (flatOnLeft || flatOnBottom),
  53347. ! (flatOnRight || flatOnBottom));
  53348. {
  53349. ColourGradient cg (colour.darker (0.2f), 0, y,
  53350. colour.darker (0.2f), 0, y + height, false);
  53351. cg.addColour (0.03, colour.withMultipliedAlpha (0.3f));
  53352. cg.addColour (0.4, colour);
  53353. cg.addColour (0.97, colour.withMultipliedAlpha (0.3f));
  53354. g.setGradientFill (cg);
  53355. g.fillPath (outline);
  53356. }
  53357. ColourGradient cg (Colours::transparentBlack, x + edgeBlurRadius, y + height * 0.5f,
  53358. colour.darker (0.2f), x, y + height * 0.5f, true);
  53359. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.5f) / edgeBlurRadius), Colours::transparentBlack);
  53360. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.25f) / edgeBlurRadius), colour.darker (0.2f).withMultipliedAlpha (0.3f));
  53361. if (! (flatOnLeft || flatOnTop || flatOnBottom))
  53362. {
  53363. g.saveState();
  53364. g.setGradientFill (cg);
  53365. g.reduceClipRegion (intX, intY, intEdge, intH);
  53366. g.fillPath (outline);
  53367. g.restoreState();
  53368. }
  53369. if (! (flatOnRight || flatOnTop || flatOnBottom))
  53370. {
  53371. cg.x1 = x + width - edgeBlurRadius;
  53372. cg.x2 = x + width;
  53373. g.saveState();
  53374. g.setGradientFill (cg);
  53375. g.reduceClipRegion (intX + intW - intEdge, intY, 2 + intEdge, intH);
  53376. g.fillPath (outline);
  53377. g.restoreState();
  53378. }
  53379. {
  53380. const float leftIndent = flatOnLeft ? 0.0f : cs * 0.4f;
  53381. const float rightIndent = flatOnRight ? 0.0f : cs * 0.4f;
  53382. Path highlight;
  53383. createRoundedPath (highlight,
  53384. x + leftIndent,
  53385. y + cs * 0.1f,
  53386. width - (leftIndent + rightIndent),
  53387. height * 0.4f, cs * 0.4f,
  53388. ! (flatOnLeft || flatOnTop),
  53389. ! (flatOnRight || flatOnTop),
  53390. ! (flatOnLeft || flatOnBottom),
  53391. ! (flatOnRight || flatOnBottom));
  53392. g.setGradientFill (ColourGradient (colour.brighter (10.0f), 0, y + height * 0.06f,
  53393. Colours::transparentWhite, 0, y + height * 0.4f, false));
  53394. g.fillPath (highlight);
  53395. }
  53396. g.setColour (colour.darker().withMultipliedAlpha (1.5f));
  53397. g.strokePath (outline, PathStrokeType (outlineThickness));
  53398. }
  53399. END_JUCE_NAMESPACE
  53400. /*** End of inlined file: juce_LookAndFeel.cpp ***/
  53401. /*** Start of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  53402. BEGIN_JUCE_NAMESPACE
  53403. OldSchoolLookAndFeel::OldSchoolLookAndFeel()
  53404. {
  53405. setColour (TextButton::buttonColourId, Colour (0xffbbbbff));
  53406. setColour (ListBox::outlineColourId, findColour (ComboBox::outlineColourId));
  53407. setColour (ScrollBar::thumbColourId, Colour (0xffbbbbdd));
  53408. setColour (ScrollBar::backgroundColourId, Colours::transparentBlack);
  53409. setColour (Slider::thumbColourId, Colours::white);
  53410. setColour (Slider::trackColourId, Colour (0x7f000000));
  53411. setColour (Slider::textBoxOutlineColourId, Colours::grey);
  53412. setColour (ProgressBar::backgroundColourId, Colours::white.withAlpha (0.6f));
  53413. setColour (ProgressBar::foregroundColourId, Colours::green.withAlpha (0.7f));
  53414. setColour (PopupMenu::backgroundColourId, Colour (0xffeef5f8));
  53415. setColour (PopupMenu::highlightedBackgroundColourId, Colour (0xbfa4c2ce));
  53416. setColour (PopupMenu::highlightedTextColourId, Colours::black);
  53417. setColour (TextEditor::focusedOutlineColourId, findColour (TextButton::buttonColourId));
  53418. scrollbarShadow.setShadowProperties (2.2f, 0.5f, 0, 0);
  53419. }
  53420. OldSchoolLookAndFeel::~OldSchoolLookAndFeel()
  53421. {
  53422. }
  53423. void OldSchoolLookAndFeel::drawButtonBackground (Graphics& g,
  53424. Button& button,
  53425. const Colour& backgroundColour,
  53426. bool isMouseOverButton,
  53427. bool isButtonDown)
  53428. {
  53429. const int width = button.getWidth();
  53430. const int height = button.getHeight();
  53431. const float indent = 2.0f;
  53432. const int cornerSize = jmin (roundToInt (width * 0.4f),
  53433. roundToInt (height * 0.4f));
  53434. Path p;
  53435. p.addRoundedRectangle (indent, indent,
  53436. width - indent * 2.0f,
  53437. height - indent * 2.0f,
  53438. (float) cornerSize);
  53439. Colour bc (backgroundColour.withMultipliedSaturation (0.3f));
  53440. if (isMouseOverButton)
  53441. {
  53442. if (isButtonDown)
  53443. bc = bc.brighter();
  53444. else if (bc.getBrightness() > 0.5f)
  53445. bc = bc.darker (0.1f);
  53446. else
  53447. bc = bc.brighter (0.1f);
  53448. }
  53449. g.setColour (bc);
  53450. g.fillPath (p);
  53451. g.setColour (bc.contrasting().withAlpha ((isMouseOverButton) ? 0.6f : 0.4f));
  53452. g.strokePath (p, PathStrokeType ((isMouseOverButton) ? 2.0f : 1.4f));
  53453. }
  53454. void OldSchoolLookAndFeel::drawTickBox (Graphics& g,
  53455. Component& /*component*/,
  53456. float x, float y, float w, float h,
  53457. const bool ticked,
  53458. const bool isEnabled,
  53459. const bool /*isMouseOverButton*/,
  53460. const bool isButtonDown)
  53461. {
  53462. Path box;
  53463. box.addRoundedRectangle (0.0f, 2.0f, 6.0f, 6.0f, 1.0f);
  53464. g.setColour (isEnabled ? Colours::blue.withAlpha (isButtonDown ? 0.3f : 0.1f)
  53465. : Colours::lightgrey.withAlpha (0.1f));
  53466. AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f).translated (x, y));
  53467. g.fillPath (box, trans);
  53468. g.setColour (Colours::black.withAlpha (0.6f));
  53469. g.strokePath (box, PathStrokeType (0.9f), trans);
  53470. if (ticked)
  53471. {
  53472. Path tick;
  53473. tick.startNewSubPath (1.5f, 3.0f);
  53474. tick.lineTo (3.0f, 6.0f);
  53475. tick.lineTo (6.0f, 0.0f);
  53476. g.setColour (isEnabled ? Colours::black : Colours::grey);
  53477. g.strokePath (tick, PathStrokeType (2.5f), trans);
  53478. }
  53479. }
  53480. void OldSchoolLookAndFeel::drawToggleButton (Graphics& g,
  53481. ToggleButton& button,
  53482. bool isMouseOverButton,
  53483. bool isButtonDown)
  53484. {
  53485. if (button.hasKeyboardFocus (true))
  53486. {
  53487. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  53488. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  53489. }
  53490. const int tickWidth = jmin (20, button.getHeight() - 4);
  53491. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  53492. (float) tickWidth, (float) tickWidth,
  53493. button.getToggleState(),
  53494. button.isEnabled(),
  53495. isMouseOverButton,
  53496. isButtonDown);
  53497. g.setColour (button.findColour (ToggleButton::textColourId));
  53498. g.setFont (jmin (15.0f, button.getHeight() * 0.6f));
  53499. if (! button.isEnabled())
  53500. g.setOpacity (0.5f);
  53501. const int textX = tickWidth + 5;
  53502. g.drawFittedText (button.getButtonText(),
  53503. textX, 4,
  53504. button.getWidth() - textX - 2, button.getHeight() - 8,
  53505. Justification::centredLeft, 10);
  53506. }
  53507. void OldSchoolLookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  53508. int width, int height,
  53509. double progress, const String& textToShow)
  53510. {
  53511. if (progress < 0 || progress >= 1.0)
  53512. {
  53513. LookAndFeel::drawProgressBar (g, progressBar, width, height, progress, textToShow);
  53514. }
  53515. else
  53516. {
  53517. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  53518. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  53519. g.fillAll (background);
  53520. g.setColour (foreground);
  53521. g.fillRect (1, 1,
  53522. jlimit (0, width - 2, roundToInt (progress * (width - 2))),
  53523. height - 2);
  53524. if (textToShow.isNotEmpty())
  53525. {
  53526. g.setColour (Colour::contrasting (background, foreground));
  53527. g.setFont (height * 0.6f);
  53528. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  53529. }
  53530. }
  53531. }
  53532. void OldSchoolLookAndFeel::drawScrollbarButton (Graphics& g,
  53533. ScrollBar& bar,
  53534. int width, int height,
  53535. int buttonDirection,
  53536. bool isScrollbarVertical,
  53537. bool isMouseOverButton,
  53538. bool isButtonDown)
  53539. {
  53540. if (isScrollbarVertical)
  53541. width -= 2;
  53542. else
  53543. height -= 2;
  53544. Path p;
  53545. if (buttonDirection == 0)
  53546. p.addTriangle (width * 0.5f, height * 0.2f,
  53547. width * 0.1f, height * 0.7f,
  53548. width * 0.9f, height * 0.7f);
  53549. else if (buttonDirection == 1)
  53550. p.addTriangle (width * 0.8f, height * 0.5f,
  53551. width * 0.3f, height * 0.1f,
  53552. width * 0.3f, height * 0.9f);
  53553. else if (buttonDirection == 2)
  53554. p.addTriangle (width * 0.5f, height * 0.8f,
  53555. width * 0.1f, height * 0.3f,
  53556. width * 0.9f, height * 0.3f);
  53557. else if (buttonDirection == 3)
  53558. p.addTriangle (width * 0.2f, height * 0.5f,
  53559. width * 0.7f, height * 0.1f,
  53560. width * 0.7f, height * 0.9f);
  53561. if (isButtonDown)
  53562. g.setColour (Colours::white);
  53563. else if (isMouseOverButton)
  53564. g.setColour (Colours::white.withAlpha (0.7f));
  53565. else
  53566. g.setColour (bar.findColour (ScrollBar::thumbColourId).withAlpha (0.5f));
  53567. g.fillPath (p);
  53568. g.setColour (Colours::black.withAlpha (0.5f));
  53569. g.strokePath (p, PathStrokeType (0.5f));
  53570. }
  53571. void OldSchoolLookAndFeel::drawScrollbar (Graphics& g,
  53572. ScrollBar& bar,
  53573. int x, int y,
  53574. int width, int height,
  53575. bool isScrollbarVertical,
  53576. int thumbStartPosition,
  53577. int thumbSize,
  53578. bool isMouseOver,
  53579. bool isMouseDown)
  53580. {
  53581. g.fillAll (bar.findColour (ScrollBar::backgroundColourId));
  53582. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  53583. .withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.15f));
  53584. if (thumbSize > 0.0f)
  53585. {
  53586. Rectangle<int> thumb;
  53587. if (isScrollbarVertical)
  53588. {
  53589. width -= 2;
  53590. g.fillRect (x + roundToInt (width * 0.35f), y,
  53591. roundToInt (width * 0.3f), height);
  53592. thumb.setBounds (x + 1, thumbStartPosition,
  53593. width - 2, thumbSize);
  53594. }
  53595. else
  53596. {
  53597. height -= 2;
  53598. g.fillRect (x, y + roundToInt (height * 0.35f),
  53599. width, roundToInt (height * 0.3f));
  53600. thumb.setBounds (thumbStartPosition, y + 1,
  53601. thumbSize, height - 2);
  53602. }
  53603. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  53604. .withAlpha ((isMouseOver || isMouseDown) ? 0.95f : 0.7f));
  53605. g.fillRect (thumb);
  53606. g.setColour (Colours::black.withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.25f));
  53607. g.drawRect (thumb.getX(), thumb.getY(), thumb.getWidth(), thumb.getHeight());
  53608. if (thumbSize > 16)
  53609. {
  53610. for (int i = 3; --i >= 0;)
  53611. {
  53612. const float linePos = thumbStartPosition + thumbSize / 2 + (i - 1) * 4.0f;
  53613. g.setColour (Colours::black.withAlpha (0.15f));
  53614. if (isScrollbarVertical)
  53615. {
  53616. g.drawLine (x + width * 0.2f, linePos, width * 0.8f, linePos);
  53617. g.setColour (Colours::white.withAlpha (0.15f));
  53618. g.drawLine (width * 0.2f, linePos - 1, width * 0.8f, linePos - 1);
  53619. }
  53620. else
  53621. {
  53622. g.drawLine (linePos, height * 0.2f, linePos, height * 0.8f);
  53623. g.setColour (Colours::white.withAlpha (0.15f));
  53624. g.drawLine (linePos - 1, height * 0.2f, linePos - 1, height * 0.8f);
  53625. }
  53626. }
  53627. }
  53628. }
  53629. }
  53630. ImageEffectFilter* OldSchoolLookAndFeel::getScrollbarEffect()
  53631. {
  53632. return &scrollbarShadow;
  53633. }
  53634. void OldSchoolLookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  53635. {
  53636. g.fillAll (findColour (PopupMenu::backgroundColourId));
  53637. g.setColour (Colours::black.withAlpha (0.6f));
  53638. g.drawRect (0, 0, width, height);
  53639. }
  53640. void OldSchoolLookAndFeel::drawMenuBarBackground (Graphics& g, int /*width*/, int /*height*/,
  53641. bool, MenuBarComponent& menuBar)
  53642. {
  53643. g.fillAll (menuBar.findColour (PopupMenu::backgroundColourId));
  53644. }
  53645. void OldSchoolLookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  53646. {
  53647. if (textEditor.isEnabled())
  53648. {
  53649. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  53650. g.drawRect (0, 0, width, height);
  53651. }
  53652. }
  53653. void OldSchoolLookAndFeel::drawComboBox (Graphics& g, int width, int height,
  53654. const bool isButtonDown,
  53655. int buttonX, int buttonY,
  53656. int buttonW, int buttonH,
  53657. ComboBox& box)
  53658. {
  53659. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  53660. g.setColour (box.findColour ((isButtonDown) ? ComboBox::buttonColourId
  53661. : ComboBox::backgroundColourId));
  53662. g.fillRect (buttonX, buttonY, buttonW, buttonH);
  53663. g.setColour (box.findColour (ComboBox::outlineColourId));
  53664. g.drawRect (0, 0, width, height);
  53665. const float arrowX = 0.2f;
  53666. const float arrowH = 0.3f;
  53667. if (box.isEnabled())
  53668. {
  53669. Path p;
  53670. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  53671. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  53672. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  53673. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  53674. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  53675. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  53676. g.setColour (box.findColour ((isButtonDown) ? ComboBox::backgroundColourId
  53677. : ComboBox::buttonColourId));
  53678. g.fillPath (p);
  53679. }
  53680. }
  53681. const Font OldSchoolLookAndFeel::getComboBoxFont (ComboBox& box)
  53682. {
  53683. Font f (jmin (15.0f, box.getHeight() * 0.85f));
  53684. f.setHorizontalScale (0.9f);
  53685. return f;
  53686. }
  53687. static void drawTriangle (Graphics& g, float x1, float y1, float x2, float y2, float x3, float y3, const Colour& fill, const Colour& outline) throw()
  53688. {
  53689. Path p;
  53690. p.addTriangle (x1, y1, x2, y2, x3, y3);
  53691. g.setColour (fill);
  53692. g.fillPath (p);
  53693. g.setColour (outline);
  53694. g.strokePath (p, PathStrokeType (0.3f));
  53695. }
  53696. void OldSchoolLookAndFeel::drawLinearSlider (Graphics& g,
  53697. int x, int y,
  53698. int w, int h,
  53699. float sliderPos,
  53700. float minSliderPos,
  53701. float maxSliderPos,
  53702. const Slider::SliderStyle style,
  53703. Slider& slider)
  53704. {
  53705. g.fillAll (slider.findColour (Slider::backgroundColourId));
  53706. if (style == Slider::LinearBar)
  53707. {
  53708. g.setColour (slider.findColour (Slider::thumbColourId));
  53709. g.fillRect (x, y, (int) sliderPos - x, h);
  53710. g.setColour (slider.findColour (Slider::textBoxTextColourId).withMultipliedAlpha (0.5f));
  53711. g.drawRect (x, y, (int) sliderPos - x, h);
  53712. }
  53713. else
  53714. {
  53715. g.setColour (slider.findColour (Slider::trackColourId)
  53716. .withMultipliedAlpha (slider.isEnabled() ? 1.0f : 0.3f));
  53717. if (slider.isHorizontal())
  53718. {
  53719. g.fillRect (x, y + roundToInt (h * 0.6f),
  53720. w, roundToInt (h * 0.2f));
  53721. }
  53722. else
  53723. {
  53724. g.fillRect (x + roundToInt (w * 0.5f - jmin (3.0f, w * 0.1f)), y,
  53725. jmin (4, roundToInt (w * 0.2f)), h);
  53726. }
  53727. float alpha = 0.35f;
  53728. if (slider.isEnabled())
  53729. alpha = slider.isMouseOverOrDragging() ? 1.0f : 0.7f;
  53730. const Colour fill (slider.findColour (Slider::thumbColourId).withAlpha (alpha));
  53731. const Colour outline (Colours::black.withAlpha (slider.isEnabled() ? 0.7f : 0.35f));
  53732. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  53733. {
  53734. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), minSliderPos,
  53735. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos - 7.0f,
  53736. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos,
  53737. fill, outline);
  53738. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), maxSliderPos,
  53739. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos,
  53740. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos + 7.0f,
  53741. fill, outline);
  53742. }
  53743. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  53744. {
  53745. drawTriangle (g, minSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  53746. minSliderPos - 7.0f, y + h * 0.9f ,
  53747. minSliderPos, y + h * 0.9f,
  53748. fill, outline);
  53749. drawTriangle (g, maxSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  53750. maxSliderPos, y + h * 0.9f,
  53751. maxSliderPos + 7.0f, y + h * 0.9f,
  53752. fill, outline);
  53753. }
  53754. if (style == Slider::LinearHorizontal || style == Slider::ThreeValueHorizontal)
  53755. {
  53756. drawTriangle (g, sliderPos, y + h * 0.9f,
  53757. sliderPos - 7.0f, y + h * 0.2f,
  53758. sliderPos + 7.0f, y + h * 0.2f,
  53759. fill, outline);
  53760. }
  53761. else if (style == Slider::LinearVertical || style == Slider::ThreeValueVertical)
  53762. {
  53763. drawTriangle (g, x + w * 0.5f - jmin (4.0f, w * 0.3f), sliderPos,
  53764. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos - 7.0f,
  53765. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos + 7.0f,
  53766. fill, outline);
  53767. }
  53768. }
  53769. }
  53770. Button* OldSchoolLookAndFeel::createSliderButton (const bool isIncrement)
  53771. {
  53772. if (isIncrement)
  53773. return new ArrowButton ("u", 0.75f, Colours::white.withAlpha (0.8f));
  53774. else
  53775. return new ArrowButton ("d", 0.25f, Colours::white.withAlpha (0.8f));
  53776. }
  53777. ImageEffectFilter* OldSchoolLookAndFeel::getSliderEffect()
  53778. {
  53779. return &scrollbarShadow;
  53780. }
  53781. int OldSchoolLookAndFeel::getSliderThumbRadius (Slider&)
  53782. {
  53783. return 8;
  53784. }
  53785. void OldSchoolLookAndFeel::drawCornerResizer (Graphics& g,
  53786. int w, int h,
  53787. bool isMouseOver,
  53788. bool isMouseDragging)
  53789. {
  53790. g.setColour ((isMouseOver || isMouseDragging) ? Colours::lightgrey
  53791. : Colours::darkgrey);
  53792. const float lineThickness = jmin (w, h) * 0.1f;
  53793. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  53794. {
  53795. g.drawLine (w * i,
  53796. h + 1.0f,
  53797. w + 1.0f,
  53798. h * i,
  53799. lineThickness);
  53800. }
  53801. }
  53802. Button* OldSchoolLookAndFeel::createDocumentWindowButton (int buttonType)
  53803. {
  53804. Path shape;
  53805. if (buttonType == DocumentWindow::closeButton)
  53806. {
  53807. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, 0.35f);
  53808. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, 0.35f);
  53809. ShapeButton* const b = new ShapeButton ("close",
  53810. Colour (0x7fff3333),
  53811. Colour (0xd7ff3333),
  53812. Colour (0xf7ff3333));
  53813. b->setShape (shape, true, true, true);
  53814. return b;
  53815. }
  53816. else if (buttonType == DocumentWindow::minimiseButton)
  53817. {
  53818. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  53819. DrawableButton* b = new DrawableButton ("minimise", DrawableButton::ImageFitted);
  53820. DrawablePath dp;
  53821. dp.setPath (shape);
  53822. dp.setFill (Colours::black.withAlpha (0.3f));
  53823. b->setImages (&dp);
  53824. return b;
  53825. }
  53826. else if (buttonType == DocumentWindow::maximiseButton)
  53827. {
  53828. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, 0.25f);
  53829. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  53830. DrawableButton* b = new DrawableButton ("maximise", DrawableButton::ImageFitted);
  53831. DrawablePath dp;
  53832. dp.setPath (shape);
  53833. dp.setFill (Colours::black.withAlpha (0.3f));
  53834. b->setImages (&dp);
  53835. return b;
  53836. }
  53837. jassertfalse
  53838. return 0;
  53839. }
  53840. void OldSchoolLookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  53841. int titleBarX,
  53842. int titleBarY,
  53843. int titleBarW,
  53844. int titleBarH,
  53845. Button* minimiseButton,
  53846. Button* maximiseButton,
  53847. Button* closeButton,
  53848. bool positionTitleBarButtonsOnLeft)
  53849. {
  53850. titleBarY += titleBarH / 8;
  53851. titleBarH -= titleBarH / 4;
  53852. const int buttonW = titleBarH;
  53853. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  53854. : titleBarX + titleBarW - buttonW - 4;
  53855. if (closeButton != 0)
  53856. {
  53857. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53858. x += positionTitleBarButtonsOnLeft ? buttonW + buttonW / 5
  53859. : -(buttonW + buttonW / 5);
  53860. }
  53861. if (positionTitleBarButtonsOnLeft)
  53862. swapVariables (minimiseButton, maximiseButton);
  53863. if (maximiseButton != 0)
  53864. {
  53865. maximiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  53866. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  53867. }
  53868. if (minimiseButton != 0)
  53869. minimiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  53870. }
  53871. END_JUCE_NAMESPACE
  53872. /*** End of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  53873. /*** Start of inlined file: juce_MenuBarComponent.cpp ***/
  53874. BEGIN_JUCE_NAMESPACE
  53875. class DummyMenuComponent : public Component
  53876. {
  53877. DummyMenuComponent (const DummyMenuComponent&);
  53878. DummyMenuComponent& operator= (const DummyMenuComponent&);
  53879. public:
  53880. DummyMenuComponent() {}
  53881. ~DummyMenuComponent() {}
  53882. void inputAttemptWhenModal()
  53883. {
  53884. exitModalState (0);
  53885. }
  53886. };
  53887. MenuBarComponent::MenuBarComponent (MenuBarModel* model_)
  53888. : model (0),
  53889. itemUnderMouse (-1),
  53890. currentPopupIndex (-1),
  53891. indexToShowAgain (-1),
  53892. lastMouseX (0),
  53893. lastMouseY (0),
  53894. inModalState (false)
  53895. {
  53896. setRepaintsOnMouseActivity (true);
  53897. setWantsKeyboardFocus (false);
  53898. setMouseClickGrabsKeyboardFocus (false);
  53899. setModel (model_);
  53900. }
  53901. MenuBarComponent::~MenuBarComponent()
  53902. {
  53903. setModel (0);
  53904. Desktop::getInstance().removeGlobalMouseListener (this);
  53905. currentPopup = 0;
  53906. }
  53907. void MenuBarComponent::setModel (MenuBarModel* const newModel)
  53908. {
  53909. if (model != newModel)
  53910. {
  53911. if (model != 0)
  53912. model->removeListener (this);
  53913. model = newModel;
  53914. if (model != 0)
  53915. model->addListener (this);
  53916. repaint();
  53917. menuBarItemsChanged (0);
  53918. }
  53919. }
  53920. void MenuBarComponent::paint (Graphics& g)
  53921. {
  53922. const bool isMouseOverBar = currentPopupIndex >= 0 || itemUnderMouse >= 0 || isMouseOver();
  53923. getLookAndFeel().drawMenuBarBackground (g,
  53924. getWidth(),
  53925. getHeight(),
  53926. isMouseOverBar,
  53927. *this);
  53928. if (model != 0)
  53929. {
  53930. for (int i = 0; i < menuNames.size(); ++i)
  53931. {
  53932. g.saveState();
  53933. g.setOrigin (xPositions [i], 0);
  53934. g.reduceClipRegion (0, 0, xPositions[i + 1] - xPositions[i], getHeight());
  53935. getLookAndFeel().drawMenuBarItem (g,
  53936. xPositions[i + 1] - xPositions[i],
  53937. getHeight(),
  53938. i,
  53939. menuNames[i],
  53940. i == itemUnderMouse,
  53941. i == currentPopupIndex,
  53942. isMouseOverBar,
  53943. *this);
  53944. g.restoreState();
  53945. }
  53946. }
  53947. }
  53948. void MenuBarComponent::resized()
  53949. {
  53950. xPositions.clear();
  53951. int x = 2;
  53952. xPositions.add (x);
  53953. for (int i = 0; i < menuNames.size(); ++i)
  53954. {
  53955. x += getLookAndFeel().getMenuBarItemWidth (*this, i, menuNames[i]);
  53956. xPositions.add (x);
  53957. }
  53958. }
  53959. int MenuBarComponent::getItemAt (const int x, const int y)
  53960. {
  53961. for (int i = 0; i < xPositions.size(); ++i)
  53962. if (x >= xPositions[i] && x < xPositions[i + 1])
  53963. return reallyContains (x, y, true) ? i : -1;
  53964. return -1;
  53965. }
  53966. void MenuBarComponent::repaintMenuItem (int index)
  53967. {
  53968. if (((unsigned int) index) < (unsigned int) xPositions.size())
  53969. {
  53970. const int x1 = xPositions [index];
  53971. const int x2 = xPositions [index + 1];
  53972. repaint (x1 - 2, 0, x2 - x1 + 4, getHeight());
  53973. }
  53974. }
  53975. void MenuBarComponent::updateItemUnderMouse (int x, int y)
  53976. {
  53977. const int newItem = getItemAt (x, y);
  53978. if (itemUnderMouse != newItem)
  53979. {
  53980. repaintMenuItem (itemUnderMouse);
  53981. itemUnderMouse = newItem;
  53982. repaintMenuItem (itemUnderMouse);
  53983. }
  53984. }
  53985. void MenuBarComponent::hideCurrentMenu()
  53986. {
  53987. currentPopup = 0;
  53988. repaint();
  53989. }
  53990. void MenuBarComponent::showMenu (int index)
  53991. {
  53992. if (index != currentPopupIndex)
  53993. {
  53994. if (inModalState)
  53995. {
  53996. hideCurrentMenu();
  53997. indexToShowAgain = index;
  53998. return;
  53999. }
  54000. indexToShowAgain = -1;
  54001. currentPopupIndex = -1;
  54002. itemUnderMouse = index;
  54003. currentPopup = 0;
  54004. menuBarItemsChanged (0);
  54005. Component::SafePointer<Component> prevFocused (getCurrentlyFocusedComponent());
  54006. Component::SafePointer<Component> deletionChecker (this);
  54007. enterModalState (false);
  54008. inModalState = true;
  54009. int result = 0;
  54010. ApplicationCommandManager* managerOfChosenCommand = 0;
  54011. Desktop::getInstance().addGlobalMouseListener (this);
  54012. for (;;)
  54013. {
  54014. const int x = getScreenX() + xPositions [itemUnderMouse];
  54015. const int w = xPositions [itemUnderMouse + 1] - xPositions [itemUnderMouse];
  54016. currentPopupIndex = itemUnderMouse;
  54017. indexToShowAgain = -1;
  54018. repaint();
  54019. if (((unsigned int) itemUnderMouse) < (unsigned int) menuNames.size())
  54020. {
  54021. PopupMenu m (model->getMenuForIndex (itemUnderMouse,
  54022. menuNames [itemUnderMouse]));
  54023. if (m.lookAndFeel == 0)
  54024. m.setLookAndFeel (&getLookAndFeel());
  54025. currentPopup = m.createMenuComponent (x, getScreenY(),
  54026. w, getHeight(),
  54027. 0, w, 0, 0,
  54028. true, this,
  54029. &managerOfChosenCommand,
  54030. this);
  54031. }
  54032. if (currentPopup == 0)
  54033. {
  54034. currentPopup = new DummyMenuComponent();
  54035. addAndMakeVisible (currentPopup);
  54036. }
  54037. currentPopup->enterModalState (false);
  54038. currentPopup->toFront (false); // need to do this after making it modal, or it could
  54039. // be stuck behind other comps that are already modal..
  54040. result = currentPopup->runModalLoop();
  54041. if (deletionChecker == 0)
  54042. return;
  54043. const int lastPopupIndex = currentPopupIndex;
  54044. currentPopup = 0;
  54045. currentPopupIndex = -1;
  54046. if (result != 0)
  54047. {
  54048. topLevelIndexClicked = lastPopupIndex;
  54049. break;
  54050. }
  54051. else if (indexToShowAgain >= 0)
  54052. {
  54053. menuBarItemsChanged (0);
  54054. repaint();
  54055. itemUnderMouse = indexToShowAgain;
  54056. if (((unsigned int) itemUnderMouse) >= (unsigned int) menuNames.size())
  54057. break;
  54058. }
  54059. else
  54060. {
  54061. break;
  54062. }
  54063. }
  54064. Desktop::getInstance().removeGlobalMouseListener (this);
  54065. inModalState = false;
  54066. exitModalState (0);
  54067. if (prevFocused != 0)
  54068. prevFocused->grabKeyboardFocus();
  54069. const Point<int> mousePos (getMouseXYRelative());
  54070. updateItemUnderMouse (mousePos.getX(), mousePos.getY());
  54071. repaint();
  54072. if (result != 0)
  54073. {
  54074. if (managerOfChosenCommand != 0)
  54075. {
  54076. ApplicationCommandTarget::InvocationInfo info (result);
  54077. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  54078. managerOfChosenCommand->invoke (info, true);
  54079. }
  54080. postCommandMessage (result);
  54081. }
  54082. }
  54083. }
  54084. void MenuBarComponent::handleCommandMessage (int commandId)
  54085. {
  54086. if (model != 0)
  54087. model->menuItemSelected (commandId, topLevelIndexClicked);
  54088. }
  54089. void MenuBarComponent::mouseEnter (const MouseEvent& e)
  54090. {
  54091. if (e.eventComponent == this)
  54092. updateItemUnderMouse (e.x, e.y);
  54093. }
  54094. void MenuBarComponent::mouseExit (const MouseEvent& e)
  54095. {
  54096. if (e.eventComponent == this)
  54097. updateItemUnderMouse (e.x, e.y);
  54098. }
  54099. void MenuBarComponent::mouseDown (const MouseEvent& e)
  54100. {
  54101. if (currentPopupIndex < 0)
  54102. {
  54103. const MouseEvent e2 (e.getEventRelativeTo (this));
  54104. updateItemUnderMouse (e2.x, e2.y);
  54105. currentPopupIndex = -2;
  54106. showMenu (itemUnderMouse);
  54107. }
  54108. }
  54109. void MenuBarComponent::mouseDrag (const MouseEvent& e)
  54110. {
  54111. const MouseEvent e2 (e.getEventRelativeTo (this));
  54112. const int item = getItemAt (e2.x, e2.y);
  54113. if (item >= 0)
  54114. showMenu (item);
  54115. }
  54116. void MenuBarComponent::mouseUp (const MouseEvent& e)
  54117. {
  54118. const MouseEvent e2 (e.getEventRelativeTo (this));
  54119. updateItemUnderMouse (e2.x, e2.y);
  54120. if (itemUnderMouse < 0 && dynamic_cast <DummyMenuComponent*> ((Component*) currentPopup) != 0)
  54121. hideCurrentMenu();
  54122. }
  54123. void MenuBarComponent::mouseMove (const MouseEvent& e)
  54124. {
  54125. const MouseEvent e2 (e.getEventRelativeTo (this));
  54126. if (lastMouseX != e2.x || lastMouseY != e2.y)
  54127. {
  54128. if (currentPopupIndex >= 0)
  54129. {
  54130. const int item = getItemAt (e2.x, e2.y);
  54131. if (item >= 0)
  54132. showMenu (item);
  54133. }
  54134. else
  54135. {
  54136. updateItemUnderMouse (e2.x, e2.y);
  54137. }
  54138. lastMouseX = e2.x;
  54139. lastMouseY = e2.y;
  54140. }
  54141. }
  54142. bool MenuBarComponent::keyPressed (const KeyPress& key)
  54143. {
  54144. bool used = false;
  54145. const int numMenus = menuNames.size();
  54146. const int currentIndex = jlimit (0, menuNames.size() - 1, currentPopupIndex);
  54147. if (key.isKeyCode (KeyPress::leftKey))
  54148. {
  54149. showMenu ((currentIndex + numMenus - 1) % numMenus);
  54150. used = true;
  54151. }
  54152. else if (key.isKeyCode (KeyPress::rightKey))
  54153. {
  54154. showMenu ((currentIndex + 1) % numMenus);
  54155. used = true;
  54156. }
  54157. return used;
  54158. }
  54159. void MenuBarComponent::inputAttemptWhenModal()
  54160. {
  54161. hideCurrentMenu();
  54162. }
  54163. void MenuBarComponent::menuBarItemsChanged (MenuBarModel* /*menuBarModel*/)
  54164. {
  54165. StringArray newNames;
  54166. if (model != 0)
  54167. newNames = model->getMenuBarNames();
  54168. if (newNames != menuNames)
  54169. {
  54170. menuNames = newNames;
  54171. repaint();
  54172. resized();
  54173. }
  54174. }
  54175. void MenuBarComponent::menuCommandInvoked (MenuBarModel* /*menuBarModel*/,
  54176. const ApplicationCommandTarget::InvocationInfo& info)
  54177. {
  54178. if (model == 0
  54179. || (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) != 0)
  54180. return;
  54181. for (int i = 0; i < menuNames.size(); ++i)
  54182. {
  54183. const PopupMenu menu (model->getMenuForIndex (i, menuNames [i]));
  54184. if (menu.containsCommandItem (info.commandID))
  54185. {
  54186. itemUnderMouse = i;
  54187. repaintMenuItem (i);
  54188. startTimer (200);
  54189. break;
  54190. }
  54191. }
  54192. }
  54193. void MenuBarComponent::timerCallback()
  54194. {
  54195. stopTimer();
  54196. const Point<int> mousePos (getMouseXYRelative());
  54197. updateItemUnderMouse (mousePos.getX(), mousePos.getY());
  54198. }
  54199. END_JUCE_NAMESPACE
  54200. /*** End of inlined file: juce_MenuBarComponent.cpp ***/
  54201. /*** Start of inlined file: juce_MenuBarModel.cpp ***/
  54202. BEGIN_JUCE_NAMESPACE
  54203. MenuBarModel::MenuBarModel() throw()
  54204. : manager (0)
  54205. {
  54206. }
  54207. MenuBarModel::~MenuBarModel()
  54208. {
  54209. setApplicationCommandManagerToWatch (0);
  54210. }
  54211. void MenuBarModel::menuItemsChanged()
  54212. {
  54213. triggerAsyncUpdate();
  54214. }
  54215. void MenuBarModel::setApplicationCommandManagerToWatch (ApplicationCommandManager* const newManager) throw()
  54216. {
  54217. if (manager != newManager)
  54218. {
  54219. if (manager != 0)
  54220. manager->removeListener (this);
  54221. manager = newManager;
  54222. if (manager != 0)
  54223. manager->addListener (this);
  54224. }
  54225. }
  54226. void MenuBarModel::addListener (MenuBarModelListener* const newListener) throw()
  54227. {
  54228. listeners.add (newListener);
  54229. }
  54230. void MenuBarModel::removeListener (MenuBarModelListener* const listenerToRemove) throw()
  54231. {
  54232. // Trying to remove a listener that isn't on the list!
  54233. // If this assertion happens because this object is a dangling pointer, make sure you've not
  54234. // deleted this menu model while it's still being used by something (e.g. by a MenuBarComponent)
  54235. jassert (listeners.contains (listenerToRemove));
  54236. listeners.remove (listenerToRemove);
  54237. }
  54238. void MenuBarModel::handleAsyncUpdate()
  54239. {
  54240. listeners.call (&MenuBarModelListener::menuBarItemsChanged, this);
  54241. }
  54242. void MenuBarModel::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  54243. {
  54244. listeners.call (&MenuBarModelListener::menuCommandInvoked, this, info);
  54245. }
  54246. void MenuBarModel::applicationCommandListChanged()
  54247. {
  54248. menuItemsChanged();
  54249. }
  54250. END_JUCE_NAMESPACE
  54251. /*** End of inlined file: juce_MenuBarModel.cpp ***/
  54252. /*** Start of inlined file: juce_PopupMenu.cpp ***/
  54253. BEGIN_JUCE_NAMESPACE
  54254. class PopupMenu::Item
  54255. {
  54256. public:
  54257. Item()
  54258. : itemId (0), active (true), isSeparator (true), isTicked (false),
  54259. usesColour (false), customComp (0), commandManager (0)
  54260. {
  54261. }
  54262. Item (const int itemId_,
  54263. const String& text_,
  54264. const bool active_,
  54265. const bool isTicked_,
  54266. const Image* im,
  54267. const Colour& textColour_,
  54268. const bool usesColour_,
  54269. PopupMenuCustomComponent* const customComp_,
  54270. const PopupMenu* const subMenu_,
  54271. ApplicationCommandManager* const commandManager_)
  54272. : itemId (itemId_), text (text_), textColour (textColour_),
  54273. active (active_), isSeparator (false), isTicked (isTicked_),
  54274. usesColour (usesColour_), customComp (customComp_),
  54275. commandManager (commandManager_)
  54276. {
  54277. if (subMenu_ != 0)
  54278. subMenu = new PopupMenu (*subMenu_);
  54279. if (im != 0)
  54280. image = im->createCopy();
  54281. if (commandManager_ != 0 && itemId_ != 0)
  54282. {
  54283. String shortcutKey;
  54284. Array <KeyPress> keyPresses (commandManager_->getKeyMappings()
  54285. ->getKeyPressesAssignedToCommand (itemId_));
  54286. for (int i = 0; i < keyPresses.size(); ++i)
  54287. {
  54288. const String key (keyPresses.getReference(i).getTextDescription());
  54289. if (shortcutKey.isNotEmpty())
  54290. shortcutKey << ", ";
  54291. if (key.length() == 1)
  54292. shortcutKey << "shortcut: '" << key << '\'';
  54293. else
  54294. shortcutKey << key;
  54295. }
  54296. shortcutKey = shortcutKey.trim();
  54297. if (shortcutKey.isNotEmpty())
  54298. text << "<end>" << shortcutKey;
  54299. }
  54300. }
  54301. Item (const Item& other)
  54302. : itemId (other.itemId),
  54303. text (other.text),
  54304. textColour (other.textColour),
  54305. active (other.active),
  54306. isSeparator (other.isSeparator),
  54307. isTicked (other.isTicked),
  54308. usesColour (other.usesColour),
  54309. customComp (other.customComp),
  54310. commandManager (other.commandManager)
  54311. {
  54312. if (other.subMenu != 0)
  54313. subMenu = new PopupMenu (*(other.subMenu));
  54314. if (other.image != 0)
  54315. image = other.image->createCopy();
  54316. }
  54317. ~Item()
  54318. {
  54319. customComp = 0;
  54320. }
  54321. bool canBeTriggered() const throw()
  54322. {
  54323. return active && ! (isSeparator || (subMenu != 0));
  54324. }
  54325. bool hasActiveSubMenu() const throw()
  54326. {
  54327. return active && (subMenu != 0);
  54328. }
  54329. const int itemId;
  54330. String text;
  54331. const Colour textColour;
  54332. const bool active, isSeparator, isTicked, usesColour;
  54333. ScopedPointer <Image> image;
  54334. ReferenceCountedObjectPtr <PopupMenuCustomComponent> customComp;
  54335. ScopedPointer <PopupMenu> subMenu;
  54336. ApplicationCommandManager* const commandManager;
  54337. juce_UseDebuggingNewOperator
  54338. private:
  54339. Item& operator= (const Item&);
  54340. };
  54341. class PopupMenu::ItemComponent : public Component
  54342. {
  54343. public:
  54344. ItemComponent (const PopupMenu::Item& itemInfo_)
  54345. : itemInfo (itemInfo_),
  54346. isHighlighted (false)
  54347. {
  54348. if (itemInfo.customComp != 0)
  54349. addAndMakeVisible (itemInfo.customComp);
  54350. }
  54351. ~ItemComponent()
  54352. {
  54353. if (itemInfo.customComp != 0)
  54354. removeChildComponent (itemInfo.customComp);
  54355. }
  54356. void getIdealSize (int& idealWidth,
  54357. int& idealHeight,
  54358. const int standardItemHeight)
  54359. {
  54360. if (itemInfo.customComp != 0)
  54361. {
  54362. itemInfo.customComp->getIdealSize (idealWidth, idealHeight);
  54363. }
  54364. else
  54365. {
  54366. getLookAndFeel().getIdealPopupMenuItemSize (itemInfo.text,
  54367. itemInfo.isSeparator,
  54368. standardItemHeight,
  54369. idealWidth,
  54370. idealHeight);
  54371. }
  54372. }
  54373. void paint (Graphics& g)
  54374. {
  54375. if (itemInfo.customComp == 0)
  54376. {
  54377. String mainText (itemInfo.text);
  54378. String endText;
  54379. const int endIndex = mainText.indexOf (T("<end>"));
  54380. if (endIndex >= 0)
  54381. {
  54382. endText = mainText.substring (endIndex + 5).trim();
  54383. mainText = mainText.substring (0, endIndex);
  54384. }
  54385. getLookAndFeel()
  54386. .drawPopupMenuItem (g, getWidth(), getHeight(),
  54387. itemInfo.isSeparator,
  54388. itemInfo.active,
  54389. isHighlighted,
  54390. itemInfo.isTicked,
  54391. itemInfo.subMenu != 0,
  54392. mainText, endText,
  54393. itemInfo.image,
  54394. itemInfo.usesColour ? &(itemInfo.textColour) : 0);
  54395. }
  54396. }
  54397. void resized()
  54398. {
  54399. if (getNumChildComponents() > 0)
  54400. getChildComponent(0)->setBounds (2, 0, getWidth() - 4, getHeight());
  54401. }
  54402. void setHighlighted (bool shouldBeHighlighted)
  54403. {
  54404. shouldBeHighlighted = shouldBeHighlighted && itemInfo.active;
  54405. if (isHighlighted != shouldBeHighlighted)
  54406. {
  54407. isHighlighted = shouldBeHighlighted;
  54408. if (itemInfo.customComp != 0)
  54409. {
  54410. itemInfo.customComp->isHighlighted = shouldBeHighlighted;
  54411. itemInfo.customComp->repaint();
  54412. }
  54413. repaint();
  54414. }
  54415. }
  54416. PopupMenu::Item itemInfo;
  54417. juce_UseDebuggingNewOperator
  54418. private:
  54419. bool isHighlighted;
  54420. ItemComponent (const ItemComponent&);
  54421. ItemComponent& operator= (const ItemComponent&);
  54422. };
  54423. namespace PopupMenuSettings
  54424. {
  54425. static const int scrollZone = 24;
  54426. static const int borderSize = 2;
  54427. static const int timerInterval = 50;
  54428. static const int dismissCommandId = 0x6287345f;
  54429. }
  54430. class PopupMenu::Window : public Component,
  54431. private Timer
  54432. {
  54433. public:
  54434. Window()
  54435. : Component ("menu"),
  54436. owner (0),
  54437. currentChild (0),
  54438. activeSubMenu (0),
  54439. menuBarComponent (0),
  54440. managerOfChosenCommand (0),
  54441. minimumWidth (0),
  54442. maximumNumColumns (7),
  54443. standardItemHeight (0),
  54444. isOver (false),
  54445. hasBeenOver (false),
  54446. isDown (false),
  54447. needsToScroll (false),
  54448. hideOnExit (false),
  54449. disableMouseMoves (false),
  54450. hasAnyJuceCompHadFocus (false),
  54451. numColumns (0),
  54452. contentHeight (0),
  54453. childYOffset (0),
  54454. timeEnteredCurrentChildComp (0),
  54455. scrollAcceleration (1.0)
  54456. {
  54457. menuCreationTime = lastFocused = lastScroll = Time::getMillisecondCounter();
  54458. setWantsKeyboardFocus (true);
  54459. setMouseClickGrabsKeyboardFocus (false);
  54460. setOpaque (true);
  54461. setAlwaysOnTop (true);
  54462. Desktop::getInstance().addGlobalMouseListener (this);
  54463. getActiveWindows().add (this);
  54464. }
  54465. ~Window()
  54466. {
  54467. getActiveWindows().removeValue (this);
  54468. Desktop::getInstance().removeGlobalMouseListener (this);
  54469. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54470. activeSubMenu = 0;
  54471. deleteAllChildren();
  54472. }
  54473. static Window* create (const PopupMenu& menu,
  54474. const bool dismissOnMouseUp,
  54475. Window* const owner_,
  54476. const int minX, const int maxX,
  54477. const int minY, const int maxY,
  54478. const int minimumWidth,
  54479. const int maximumNumColumns,
  54480. const int standardItemHeight,
  54481. const bool alignToRectangle,
  54482. const int itemIdThatMustBeVisible,
  54483. Component* const menuBarComponent,
  54484. ApplicationCommandManager** managerOfChosenCommand,
  54485. Component* const componentAttachedTo)
  54486. {
  54487. if (menu.items.size() > 0)
  54488. {
  54489. int totalItems = 0;
  54490. ScopedPointer <Window> mw (new Window());
  54491. mw->setLookAndFeel (menu.lookAndFeel);
  54492. mw->setWantsKeyboardFocus (false);
  54493. mw->minimumWidth = minimumWidth;
  54494. mw->maximumNumColumns = maximumNumColumns;
  54495. mw->standardItemHeight = standardItemHeight;
  54496. mw->dismissOnMouseUp = dismissOnMouseUp;
  54497. for (int i = 0; i < menu.items.size(); ++i)
  54498. {
  54499. PopupMenu::Item* const item = menu.items.getUnchecked(i);
  54500. mw->addItem (*item);
  54501. ++totalItems;
  54502. }
  54503. if (totalItems > 0)
  54504. {
  54505. mw->owner = owner_;
  54506. mw->menuBarComponent = menuBarComponent;
  54507. mw->managerOfChosenCommand = managerOfChosenCommand;
  54508. mw->componentAttachedTo = componentAttachedTo;
  54509. mw->componentAttachedToOriginal = componentAttachedTo;
  54510. mw->calculateWindowPos (minX, maxX, minY, maxY, alignToRectangle);
  54511. mw->setTopLeftPosition (mw->windowPos.getX(),
  54512. mw->windowPos.getY());
  54513. mw->updateYPositions();
  54514. if (itemIdThatMustBeVisible != 0)
  54515. {
  54516. const int y = minY - mw->windowPos.getY();
  54517. mw->ensureItemIsVisible (itemIdThatMustBeVisible,
  54518. (((unsigned int) y) < (unsigned int) mw->windowPos.getHeight()) ? y : -1);
  54519. }
  54520. mw->resizeToBestWindowPos();
  54521. mw->addToDesktop (ComponentPeer::windowIsTemporary
  54522. | mw->getLookAndFeel().getMenuWindowFlags());
  54523. return mw.release();
  54524. }
  54525. }
  54526. return 0;
  54527. }
  54528. void paint (Graphics& g)
  54529. {
  54530. getLookAndFeel().drawPopupMenuBackground (g, getWidth(), getHeight());
  54531. }
  54532. void paintOverChildren (Graphics& g)
  54533. {
  54534. if (isScrolling())
  54535. {
  54536. LookAndFeel& lf = getLookAndFeel();
  54537. if (isScrollZoneActive (false))
  54538. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, true);
  54539. if (isScrollZoneActive (true))
  54540. {
  54541. g.setOrigin (0, getHeight() - PopupMenuSettings::scrollZone);
  54542. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, false);
  54543. }
  54544. }
  54545. }
  54546. bool isScrollZoneActive (bool bottomOne) const
  54547. {
  54548. return isScrolling()
  54549. && (bottomOne
  54550. ? childYOffset < contentHeight - windowPos.getHeight()
  54551. : childYOffset > 0);
  54552. }
  54553. void addItem (const PopupMenu::Item& item)
  54554. {
  54555. PopupMenu::ItemComponent* const mic = new PopupMenu::ItemComponent (item);
  54556. addAndMakeVisible (mic);
  54557. int itemW = 80;
  54558. int itemH = 16;
  54559. mic->getIdealSize (itemW, itemH, standardItemHeight);
  54560. mic->setSize (itemW, jlimit (2, 600, itemH));
  54561. mic->addMouseListener (this, false);
  54562. }
  54563. // hide this and all sub-comps
  54564. void hide (const PopupMenu::Item* const item)
  54565. {
  54566. if (isVisible())
  54567. {
  54568. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54569. activeSubMenu = 0;
  54570. currentChild = 0;
  54571. exitModalState (item != 0 ? item->itemId : 0);
  54572. setVisible (false);
  54573. if (item != 0
  54574. && item->commandManager != 0
  54575. && item->itemId != 0)
  54576. {
  54577. *managerOfChosenCommand = item->commandManager;
  54578. }
  54579. }
  54580. }
  54581. void dismissMenu (const PopupMenu::Item* const item)
  54582. {
  54583. if (owner != 0)
  54584. {
  54585. owner->dismissMenu (item);
  54586. }
  54587. else
  54588. {
  54589. if (item != 0)
  54590. {
  54591. // need a copy of this on the stack as the one passed in will get deleted during this call
  54592. const PopupMenu::Item mi (*item);
  54593. hide (&mi);
  54594. }
  54595. else
  54596. {
  54597. hide (0);
  54598. }
  54599. }
  54600. }
  54601. void mouseMove (const MouseEvent&)
  54602. {
  54603. timerCallback();
  54604. }
  54605. void mouseDown (const MouseEvent&)
  54606. {
  54607. timerCallback();
  54608. }
  54609. void mouseDrag (const MouseEvent&)
  54610. {
  54611. timerCallback();
  54612. }
  54613. void mouseUp (const MouseEvent&)
  54614. {
  54615. timerCallback();
  54616. }
  54617. void mouseWheelMove (const MouseEvent&, float /*amountX*/, float amountY)
  54618. {
  54619. alterChildYPos (roundToInt (-10.0f * amountY * PopupMenuSettings::scrollZone));
  54620. lastMouse = Point<int> (-1, -1);
  54621. }
  54622. bool keyPressed (const KeyPress& key)
  54623. {
  54624. if (key.isKeyCode (KeyPress::downKey))
  54625. {
  54626. selectNextItem (1);
  54627. }
  54628. else if (key.isKeyCode (KeyPress::upKey))
  54629. {
  54630. selectNextItem (-1);
  54631. }
  54632. else if (key.isKeyCode (KeyPress::leftKey))
  54633. {
  54634. if (owner != 0)
  54635. {
  54636. Component::SafePointer<Window> parentWindow (owner);
  54637. PopupMenu::ItemComponent* currentChildOfParent = parentWindow->currentChild;
  54638. hide (0);
  54639. if (parentWindow != 0)
  54640. parentWindow->setCurrentlyHighlightedChild (currentChildOfParent);
  54641. disableTimerUntilMouseMoves();
  54642. }
  54643. else if (menuBarComponent != 0)
  54644. {
  54645. menuBarComponent->keyPressed (key);
  54646. }
  54647. }
  54648. else if (key.isKeyCode (KeyPress::rightKey))
  54649. {
  54650. disableTimerUntilMouseMoves();
  54651. if (showSubMenuFor (currentChild))
  54652. {
  54653. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54654. if (activeSubMenu != 0 && activeSubMenu->isVisible())
  54655. activeSubMenu->selectNextItem (1);
  54656. }
  54657. else if (menuBarComponent != 0)
  54658. {
  54659. menuBarComponent->keyPressed (key);
  54660. }
  54661. }
  54662. else if (key.isKeyCode (KeyPress::returnKey))
  54663. {
  54664. triggerCurrentlyHighlightedItem();
  54665. }
  54666. else if (key.isKeyCode (KeyPress::escapeKey))
  54667. {
  54668. dismissMenu (0);
  54669. }
  54670. else
  54671. {
  54672. return false;
  54673. }
  54674. return true;
  54675. }
  54676. void inputAttemptWhenModal()
  54677. {
  54678. timerCallback();
  54679. if (! isOverAnyMenu())
  54680. {
  54681. if (componentAttachedTo != 0)
  54682. {
  54683. // we want to dismiss the menu, but if we do it synchronously, then
  54684. // the mouse-click will be allowed to pass through. That's good, except
  54685. // when the user clicks on the button that orginally popped the menu up,
  54686. // as they'll expect the menu to go away, and in fact it'll just
  54687. // come back. So only dismiss synchronously if they're not on the original
  54688. // comp that we're attached to.
  54689. const Point<int> mousePos (componentAttachedTo->getMouseXYRelative());
  54690. if (componentAttachedTo->reallyContains (mousePos.getX(), mousePos.getY(), true))
  54691. {
  54692. postCommandMessage (PopupMenuSettings::dismissCommandId); // dismiss asynchrounously
  54693. return;
  54694. }
  54695. }
  54696. dismissMenu (0);
  54697. }
  54698. }
  54699. void handleCommandMessage (int commandId)
  54700. {
  54701. Component::handleCommandMessage (commandId);
  54702. if (commandId == PopupMenuSettings::dismissCommandId)
  54703. dismissMenu (0);
  54704. }
  54705. void timerCallback()
  54706. {
  54707. if (! isVisible())
  54708. return;
  54709. if (componentAttachedTo != componentAttachedToOriginal)
  54710. {
  54711. dismissMenu (0);
  54712. return;
  54713. }
  54714. Window* currentlyModalWindow = dynamic_cast <Window*> (Component::getCurrentlyModalComponent());
  54715. if (currentlyModalWindow != 0 && ! treeContains (currentlyModalWindow))
  54716. return;
  54717. startTimer (PopupMenuSettings::timerInterval); // do this in case it was called from a mouse
  54718. // move rather than a real timer callback
  54719. const Point<int> globalMousePos (Desktop::getMousePosition());
  54720. const Point<int> localMousePos (globalPositionToRelative (globalMousePos));
  54721. const uint32 now = Time::getMillisecondCounter();
  54722. if (now > timeEnteredCurrentChildComp + 100
  54723. && reallyContains (localMousePos.getX(), localMousePos.getY(), true)
  54724. && currentChild->isValidComponent()
  54725. && (! disableMouseMoves)
  54726. && ! (activeSubMenu != 0 && activeSubMenu->isVisible()))
  54727. {
  54728. showSubMenuFor (currentChild);
  54729. }
  54730. if (globalMousePos != lastMouse || now > lastMouseMoveTime + 350)
  54731. {
  54732. highlightItemUnderMouse (globalMousePos, localMousePos);
  54733. }
  54734. bool overScrollArea = false;
  54735. if (isScrolling()
  54736. && (isOver || (isDown && ((unsigned int) localMousePos.getX()) < (unsigned int) getWidth()))
  54737. && ((isScrollZoneActive (false) && localMousePos.getY() < PopupMenuSettings::scrollZone)
  54738. || (isScrollZoneActive (true) && localMousePos.getY() > getHeight() - PopupMenuSettings::scrollZone)))
  54739. {
  54740. if (now > lastScroll + 20)
  54741. {
  54742. scrollAcceleration = jmin (4.0, scrollAcceleration * 1.04);
  54743. int amount = 0;
  54744. for (int i = 0; i < getNumChildComponents() && amount == 0; ++i)
  54745. amount = ((int) scrollAcceleration) * getChildComponent (i)->getHeight();
  54746. alterChildYPos (localMousePos.getY() < PopupMenuSettings::scrollZone ? -amount : amount);
  54747. lastScroll = now;
  54748. }
  54749. overScrollArea = true;
  54750. lastMouse = Point<int> (-1, -1); // trigger a mouse-move
  54751. }
  54752. else
  54753. {
  54754. scrollAcceleration = 1.0;
  54755. }
  54756. const bool wasDown = isDown;
  54757. bool isOverAny = isOverAnyMenu();
  54758. if (hideOnExit && hasBeenOver && (! isOverAny) && activeSubMenu != 0)
  54759. {
  54760. activeSubMenu->updateMouseOverStatus (globalMousePos);
  54761. isOverAny = isOverAnyMenu();
  54762. }
  54763. if (hideOnExit && hasBeenOver && ! isOverAny)
  54764. {
  54765. hide (0);
  54766. }
  54767. else
  54768. {
  54769. isDown = hasBeenOver
  54770. && (ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown()
  54771. || ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown());
  54772. bool anyFocused = Process::isForegroundProcess();
  54773. if (anyFocused && Component::getCurrentlyFocusedComponent() == 0)
  54774. {
  54775. // because no component at all may have focus, our test here will
  54776. // only be triggered when something has focus and then loses it.
  54777. anyFocused = ! hasAnyJuceCompHadFocus;
  54778. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  54779. {
  54780. if (ComponentPeer::getPeer (i)->isFocused())
  54781. {
  54782. anyFocused = true;
  54783. hasAnyJuceCompHadFocus = true;
  54784. break;
  54785. }
  54786. }
  54787. }
  54788. if (! anyFocused)
  54789. {
  54790. if (now > lastFocused + 10)
  54791. {
  54792. wasHiddenBecauseOfAppChange() = true;
  54793. dismissMenu (0);
  54794. return; // may have been deleted by the previous call..
  54795. }
  54796. }
  54797. else if (wasDown && now > menuCreationTime + 250
  54798. && ! (isDown || overScrollArea))
  54799. {
  54800. isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true);
  54801. if (isOver)
  54802. {
  54803. triggerCurrentlyHighlightedItem();
  54804. }
  54805. else if ((hasBeenOver || ! dismissOnMouseUp) && ! isOverAny)
  54806. {
  54807. dismissMenu (0);
  54808. }
  54809. return; // may have been deleted by the previous calls..
  54810. }
  54811. else
  54812. {
  54813. lastFocused = now;
  54814. }
  54815. }
  54816. }
  54817. static Array<Window*>& getActiveWindows()
  54818. {
  54819. static Array<Window*> activeMenuWindows;
  54820. return activeMenuWindows;
  54821. }
  54822. static bool& wasHiddenBecauseOfAppChange() throw()
  54823. {
  54824. static bool b = false;
  54825. return b;
  54826. }
  54827. juce_UseDebuggingNewOperator
  54828. private:
  54829. Window* owner;
  54830. PopupMenu::ItemComponent* currentChild;
  54831. ScopedPointer <Window> activeSubMenu;
  54832. Component* menuBarComponent;
  54833. ApplicationCommandManager** managerOfChosenCommand;
  54834. Component::SafePointer<Component> componentAttachedTo;
  54835. Component* componentAttachedToOriginal;
  54836. Rectangle<int> windowPos;
  54837. Point<int> lastMouse;
  54838. int minimumWidth, maximumNumColumns, standardItemHeight;
  54839. bool isOver, hasBeenOver, isDown, needsToScroll;
  54840. bool dismissOnMouseUp, hideOnExit, disableMouseMoves, hasAnyJuceCompHadFocus;
  54841. int numColumns, contentHeight, childYOffset;
  54842. Array <int> columnWidths;
  54843. uint32 menuCreationTime, lastFocused, lastScroll, lastMouseMoveTime, timeEnteredCurrentChildComp;
  54844. double scrollAcceleration;
  54845. bool overlaps (const Rectangle<int>& r) const
  54846. {
  54847. return r.intersects (getBounds())
  54848. || (owner != 0 && owner->overlaps (r));
  54849. }
  54850. bool isOverAnyMenu() const
  54851. {
  54852. return (owner != 0) ? owner->isOverAnyMenu()
  54853. : isOverChildren();
  54854. }
  54855. bool isOverChildren() const
  54856. {
  54857. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54858. return isVisible()
  54859. && (isOver || (activeSubMenu != 0 && activeSubMenu->isOverChildren()));
  54860. }
  54861. void updateMouseOverStatus (const Point<int>& globalMousePos)
  54862. {
  54863. const Point<int> relPos (globalPositionToRelative (globalMousePos));
  54864. isOver = reallyContains (relPos.getX(), relPos.getY(), true);
  54865. if (activeSubMenu != 0)
  54866. activeSubMenu->updateMouseOverStatus (globalMousePos);
  54867. }
  54868. bool treeContains (const Window* const window) const throw()
  54869. {
  54870. const Window* mw = this;
  54871. while (mw->owner != 0)
  54872. mw = mw->owner;
  54873. while (mw != 0)
  54874. {
  54875. if (mw == window)
  54876. return true;
  54877. mw = mw->activeSubMenu;
  54878. }
  54879. return false;
  54880. }
  54881. void calculateWindowPos (const int minX, const int maxX,
  54882. const int minY, const int maxY,
  54883. const bool alignToRectangle)
  54884. {
  54885. const Rectangle<int> mon (Desktop::getInstance()
  54886. .getMonitorAreaContaining (Point<int> ((minX + maxX) / 2,
  54887. (minY + maxY) / 2),
  54888. #if JUCE_MAC
  54889. true));
  54890. #else
  54891. false)); // on windows, don't stop the menu overlapping the taskbar
  54892. #endif
  54893. int x, y, widthToUse, heightToUse;
  54894. layoutMenuItems (mon.getWidth() - 24, widthToUse, heightToUse);
  54895. if (alignToRectangle)
  54896. {
  54897. x = minX;
  54898. const int spaceUnder = mon.getHeight() - (maxY - mon.getY());
  54899. const int spaceOver = minY - mon.getY();
  54900. if (heightToUse < spaceUnder - 30 || spaceUnder >= spaceOver)
  54901. y = maxY;
  54902. else
  54903. y = minY - heightToUse;
  54904. }
  54905. else
  54906. {
  54907. bool tendTowardsRight = (minX + maxX) / 2 < mon.getCentreX();
  54908. if (owner != 0)
  54909. {
  54910. if (owner->owner != 0)
  54911. {
  54912. const bool ownerGoingRight = (owner->getX() + owner->getWidth() / 2
  54913. > owner->owner->getX() + owner->owner->getWidth() / 2);
  54914. if (ownerGoingRight && maxX + widthToUse < mon.getRight() - 4)
  54915. tendTowardsRight = true;
  54916. else if ((! ownerGoingRight) && minX > widthToUse + 4)
  54917. tendTowardsRight = false;
  54918. }
  54919. else if (maxX + widthToUse < mon.getRight() - 32)
  54920. {
  54921. tendTowardsRight = true;
  54922. }
  54923. }
  54924. const int biggestSpace = jmax (mon.getRight() - maxX,
  54925. minX - mon.getX()) - 32;
  54926. if (biggestSpace < widthToUse)
  54927. {
  54928. layoutMenuItems (biggestSpace + (maxX - minX) / 3, widthToUse, heightToUse);
  54929. if (numColumns > 1)
  54930. layoutMenuItems (biggestSpace - 4, widthToUse, heightToUse);
  54931. tendTowardsRight = (mon.getRight() - maxX) >= (minX - mon.getX());
  54932. }
  54933. if (tendTowardsRight)
  54934. x = jmin (mon.getRight() - widthToUse - 4, maxX);
  54935. else
  54936. x = jmax (mon.getX() + 4, minX - widthToUse);
  54937. y = minY;
  54938. if ((minY + maxY) / 2 > mon.getCentreY())
  54939. y = jmax (mon.getY(), maxY - heightToUse);
  54940. }
  54941. x = jmax (mon.getX() + 1, jmin (mon.getRight() - (widthToUse + 6), x));
  54942. y = jmax (mon.getY() + 1, jmin (mon.getBottom() - (heightToUse + 6), y));
  54943. windowPos.setBounds (x, y, widthToUse, heightToUse);
  54944. // sets this flag if it's big enough to obscure any of its parent menus
  54945. hideOnExit = (owner != 0)
  54946. && owner->windowPos.intersects (windowPos.expanded (-4, -4));
  54947. }
  54948. void layoutMenuItems (const int maxMenuW, int& width, int& height)
  54949. {
  54950. numColumns = 0;
  54951. contentHeight = 0;
  54952. const int maxMenuH = getParentHeight() - 24;
  54953. int totalW;
  54954. do
  54955. {
  54956. ++numColumns;
  54957. totalW = workOutBestSize (maxMenuW);
  54958. if (totalW > maxMenuW)
  54959. {
  54960. numColumns = jmax (1, numColumns - 1);
  54961. totalW = workOutBestSize (maxMenuW); // to update col widths
  54962. break;
  54963. }
  54964. else if (totalW > maxMenuW / 2 || contentHeight < maxMenuH)
  54965. {
  54966. break;
  54967. }
  54968. } while (numColumns < maximumNumColumns);
  54969. const int actualH = jmin (contentHeight, maxMenuH);
  54970. needsToScroll = contentHeight > actualH;
  54971. width = updateYPositions();
  54972. height = actualH + PopupMenuSettings::borderSize * 2;
  54973. }
  54974. int workOutBestSize (const int maxMenuW)
  54975. {
  54976. int totalW = 0;
  54977. contentHeight = 0;
  54978. int childNum = 0;
  54979. for (int col = 0; col < numColumns; ++col)
  54980. {
  54981. int i, colW = 50, colH = 0;
  54982. const int numChildren = jmin (getNumChildComponents() - childNum,
  54983. (getNumChildComponents() + numColumns - 1) / numColumns);
  54984. for (i = numChildren; --i >= 0;)
  54985. {
  54986. colW = jmax (colW, getChildComponent (childNum + i)->getWidth());
  54987. colH += getChildComponent (childNum + i)->getHeight();
  54988. }
  54989. colW = jmin (maxMenuW / jmax (1, numColumns - 2), colW + PopupMenuSettings::borderSize * 2);
  54990. columnWidths.set (col, colW);
  54991. totalW += colW;
  54992. contentHeight = jmax (contentHeight, colH);
  54993. childNum += numChildren;
  54994. }
  54995. if (totalW < minimumWidth)
  54996. {
  54997. totalW = minimumWidth;
  54998. for (int col = 0; col < numColumns; ++col)
  54999. columnWidths.set (0, totalW / numColumns);
  55000. }
  55001. return totalW;
  55002. }
  55003. void ensureItemIsVisible (const int itemId, int wantedY)
  55004. {
  55005. jassert (itemId != 0)
  55006. for (int i = getNumChildComponents(); --i >= 0;)
  55007. {
  55008. PopupMenu::ItemComponent* const m = (PopupMenu::ItemComponent*) getChildComponent (i);
  55009. if (m != 0
  55010. && m->itemInfo.itemId == itemId
  55011. && windowPos.getHeight() > PopupMenuSettings::scrollZone * 4)
  55012. {
  55013. const int currentY = m->getY();
  55014. if (wantedY > 0 || currentY < 0 || m->getBottom() > windowPos.getHeight())
  55015. {
  55016. if (wantedY < 0)
  55017. wantedY = jlimit (PopupMenuSettings::scrollZone,
  55018. jmax (PopupMenuSettings::scrollZone,
  55019. windowPos.getHeight() - (PopupMenuSettings::scrollZone + m->getHeight())),
  55020. currentY);
  55021. const Rectangle<int> mon (Desktop::getInstance().getMonitorAreaContaining (windowPos.getPosition(), true));
  55022. int deltaY = wantedY - currentY;
  55023. windowPos.setSize (jmin (windowPos.getWidth(), mon.getWidth()),
  55024. jmin (windowPos.getHeight(), mon.getHeight()));
  55025. const int newY = jlimit (mon.getY(),
  55026. mon.getBottom() - windowPos.getHeight(),
  55027. windowPos.getY() + deltaY);
  55028. deltaY -= newY - windowPos.getY();
  55029. childYOffset -= deltaY;
  55030. windowPos.setPosition (windowPos.getX(), newY);
  55031. updateYPositions();
  55032. }
  55033. break;
  55034. }
  55035. }
  55036. }
  55037. void resizeToBestWindowPos()
  55038. {
  55039. Rectangle<int> r (windowPos);
  55040. if (childYOffset < 0)
  55041. {
  55042. r.setBounds (r.getX(), r.getY() - childYOffset,
  55043. r.getWidth(), r.getHeight() + childYOffset);
  55044. }
  55045. else if (childYOffset > 0)
  55046. {
  55047. const int spaceAtBottom = r.getHeight() - (contentHeight - childYOffset);
  55048. if (spaceAtBottom > 0)
  55049. r.setSize (r.getWidth(), r.getHeight() - spaceAtBottom);
  55050. }
  55051. setBounds (r);
  55052. updateYPositions();
  55053. }
  55054. void alterChildYPos (const int delta)
  55055. {
  55056. if (isScrolling())
  55057. {
  55058. childYOffset += delta;
  55059. if (delta < 0)
  55060. {
  55061. childYOffset = jmax (childYOffset, 0);
  55062. }
  55063. else if (delta > 0)
  55064. {
  55065. childYOffset = jmin (childYOffset,
  55066. contentHeight - windowPos.getHeight() + PopupMenuSettings::borderSize);
  55067. }
  55068. updateYPositions();
  55069. }
  55070. else
  55071. {
  55072. childYOffset = 0;
  55073. }
  55074. resizeToBestWindowPos();
  55075. repaint();
  55076. }
  55077. int updateYPositions()
  55078. {
  55079. int x = 0;
  55080. int childNum = 0;
  55081. for (int col = 0; col < numColumns; ++col)
  55082. {
  55083. const int numChildren = jmin (getNumChildComponents() - childNum,
  55084. (getNumChildComponents() + numColumns - 1) / numColumns);
  55085. const int colW = columnWidths [col];
  55086. int y = PopupMenuSettings::borderSize - (childYOffset + (getY() - windowPos.getY()));
  55087. for (int i = 0; i < numChildren; ++i)
  55088. {
  55089. Component* const c = getChildComponent (childNum + i);
  55090. c->setBounds (x, y, colW, c->getHeight());
  55091. y += c->getHeight();
  55092. }
  55093. x += colW;
  55094. childNum += numChildren;
  55095. }
  55096. return x;
  55097. }
  55098. bool isScrolling() const throw()
  55099. {
  55100. return childYOffset != 0 || needsToScroll;
  55101. }
  55102. void setCurrentlyHighlightedChild (PopupMenu::ItemComponent* const child)
  55103. {
  55104. if (currentChild->isValidComponent())
  55105. currentChild->setHighlighted (false);
  55106. currentChild = child;
  55107. if (currentChild != 0)
  55108. {
  55109. currentChild->setHighlighted (true);
  55110. timeEnteredCurrentChildComp = Time::getApproximateMillisecondCounter();
  55111. }
  55112. }
  55113. bool showSubMenuFor (PopupMenu::ItemComponent* const childComp)
  55114. {
  55115. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55116. activeSubMenu = 0;
  55117. if (childComp->isValidComponent() && childComp->itemInfo.hasActiveSubMenu())
  55118. {
  55119. const Point<int> topLeft (childComp->relativePositionToGlobal (Point<int>()));
  55120. const Point<int> bottomRight (childComp->relativePositionToGlobal (Point<int> (childComp->getWidth(), childComp->getHeight())));
  55121. activeSubMenu = Window::create (*(childComp->itemInfo.subMenu),
  55122. dismissOnMouseUp,
  55123. this,
  55124. topLeft.getX(), bottomRight.getX(), topLeft.getY(), bottomRight.getY(),
  55125. 0, maximumNumColumns,
  55126. standardItemHeight,
  55127. false, 0, menuBarComponent,
  55128. managerOfChosenCommand,
  55129. componentAttachedTo);
  55130. if (activeSubMenu != 0)
  55131. {
  55132. activeSubMenu->setVisible (true);
  55133. activeSubMenu->enterModalState (false);
  55134. activeSubMenu->toFront (false);
  55135. return true;
  55136. }
  55137. }
  55138. return false;
  55139. }
  55140. void highlightItemUnderMouse (const Point<int>& globalMousePos, const Point<int>& localMousePos)
  55141. {
  55142. isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true);
  55143. if (isOver)
  55144. hasBeenOver = true;
  55145. if (lastMouse.getDistanceFrom (globalMousePos) > 2)
  55146. {
  55147. lastMouseMoveTime = Time::getApproximateMillisecondCounter();
  55148. if (disableMouseMoves && isOver)
  55149. disableMouseMoves = false;
  55150. }
  55151. if (disableMouseMoves)
  55152. return;
  55153. bool isMovingTowardsMenu = false;
  55154. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent())
  55155. if (isOver && (activeSubMenu != 0) && globalMousePos != lastMouse)
  55156. {
  55157. // try to intelligently guess whether the user is moving the mouse towards a currently-open
  55158. // submenu. To do this, look at whether the mouse stays inside a triangular region that
  55159. // extends from the last mouse pos to the submenu's rectangle..
  55160. float subX = (float) activeSubMenu->getScreenX();
  55161. if (activeSubMenu->getX() > getX())
  55162. {
  55163. lastMouse -= Point<int> (2, 0); // to enlarge the triangle a bit, in case the mouse only moves a couple of pixels
  55164. }
  55165. else
  55166. {
  55167. lastMouse += Point<int> (2, 0);
  55168. subX += activeSubMenu->getWidth();
  55169. }
  55170. Path areaTowardsSubMenu;
  55171. areaTowardsSubMenu.addTriangle ((float) lastMouse.getX(),
  55172. (float) lastMouse.getY(),
  55173. subX,
  55174. (float) activeSubMenu->getScreenY(),
  55175. subX,
  55176. (float) (activeSubMenu->getScreenY() + activeSubMenu->getHeight()));
  55177. isMovingTowardsMenu = areaTowardsSubMenu.contains ((float) globalMousePos.getX(), (float) globalMousePos.getY());
  55178. }
  55179. lastMouse = globalMousePos;
  55180. if (! isMovingTowardsMenu)
  55181. {
  55182. Component* c = getComponentAt (localMousePos.getX(), localMousePos.getY());
  55183. if (c == this)
  55184. c = 0;
  55185. PopupMenu::ItemComponent* mic = dynamic_cast <PopupMenu::ItemComponent*> (c);
  55186. if (mic == 0 && c != 0)
  55187. mic = c->findParentComponentOfClass ((PopupMenu::ItemComponent*) 0);
  55188. if (mic != currentChild
  55189. && (isOver || (activeSubMenu == 0) || ! activeSubMenu->isVisible()))
  55190. {
  55191. if (isOver && (c != 0) && (activeSubMenu != 0))
  55192. {
  55193. activeSubMenu->hide (0);
  55194. }
  55195. if (! isOver)
  55196. mic = 0;
  55197. setCurrentlyHighlightedChild (mic);
  55198. }
  55199. }
  55200. }
  55201. void triggerCurrentlyHighlightedItem()
  55202. {
  55203. if (currentChild->isValidComponent()
  55204. && currentChild->itemInfo.canBeTriggered()
  55205. && (currentChild->itemInfo.customComp == 0
  55206. || currentChild->itemInfo.customComp->isTriggeredAutomatically))
  55207. {
  55208. dismissMenu (&currentChild->itemInfo);
  55209. }
  55210. }
  55211. void selectNextItem (const int delta)
  55212. {
  55213. disableTimerUntilMouseMoves();
  55214. PopupMenu::ItemComponent* mic = 0;
  55215. bool wasLastOne = (currentChild == 0);
  55216. const int numItems = getNumChildComponents();
  55217. for (int i = 0; i < numItems + 1; ++i)
  55218. {
  55219. int index = (delta > 0) ? i : (numItems - 1 - i);
  55220. index = (index + numItems) % numItems;
  55221. mic = dynamic_cast <PopupMenu::ItemComponent*> (getChildComponent (index));
  55222. if (mic != 0 && (mic->itemInfo.canBeTriggered() || mic->itemInfo.hasActiveSubMenu())
  55223. && wasLastOne)
  55224. break;
  55225. if (mic == currentChild)
  55226. wasLastOne = true;
  55227. }
  55228. setCurrentlyHighlightedChild (mic);
  55229. }
  55230. void disableTimerUntilMouseMoves()
  55231. {
  55232. disableMouseMoves = true;
  55233. if (owner != 0)
  55234. owner->disableTimerUntilMouseMoves();
  55235. }
  55236. Window (const Window&);
  55237. Window& operator= (const Window&);
  55238. };
  55239. PopupMenu::PopupMenu()
  55240. : lookAndFeel (0),
  55241. separatorPending (false)
  55242. {
  55243. }
  55244. PopupMenu::PopupMenu (const PopupMenu& other)
  55245. : lookAndFeel (other.lookAndFeel),
  55246. separatorPending (false)
  55247. {
  55248. items.ensureStorageAllocated (other.items.size());
  55249. for (int i = 0; i < other.items.size(); ++i)
  55250. items.add (new Item (*other.items.getUnchecked(i)));
  55251. }
  55252. PopupMenu& PopupMenu::operator= (const PopupMenu& other)
  55253. {
  55254. if (this != &other)
  55255. {
  55256. lookAndFeel = other.lookAndFeel;
  55257. clear();
  55258. items.ensureStorageAllocated (other.items.size());
  55259. for (int i = 0; i < other.items.size(); ++i)
  55260. items.add (new Item (*other.items.getUnchecked(i)));
  55261. }
  55262. return *this;
  55263. }
  55264. PopupMenu::~PopupMenu()
  55265. {
  55266. clear();
  55267. }
  55268. void PopupMenu::clear()
  55269. {
  55270. items.clear();
  55271. separatorPending = false;
  55272. }
  55273. void PopupMenu::addSeparatorIfPending()
  55274. {
  55275. if (separatorPending)
  55276. {
  55277. separatorPending = false;
  55278. if (items.size() > 0)
  55279. items.add (new Item());
  55280. }
  55281. }
  55282. void PopupMenu::addItem (const int itemResultId,
  55283. const String& itemText,
  55284. const bool isActive,
  55285. const bool isTicked,
  55286. const Image* const iconToUse)
  55287. {
  55288. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55289. // didn't pick anything, so you shouldn't use it as the id
  55290. // for an item..
  55291. addSeparatorIfPending();
  55292. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  55293. iconToUse, Colours::black, false, 0, 0, 0));
  55294. }
  55295. void PopupMenu::addCommandItem (ApplicationCommandManager* commandManager,
  55296. const int commandID,
  55297. const String& displayName)
  55298. {
  55299. jassert (commandManager != 0 && commandID != 0);
  55300. const ApplicationCommandInfo* const registeredInfo = commandManager->getCommandForID (commandID);
  55301. if (registeredInfo != 0)
  55302. {
  55303. ApplicationCommandInfo info (*registeredInfo);
  55304. ApplicationCommandTarget* const target = commandManager->getTargetForCommand (commandID, info);
  55305. addSeparatorIfPending();
  55306. items.add (new Item (commandID,
  55307. displayName.isNotEmpty() ? displayName
  55308. : info.shortName,
  55309. target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0,
  55310. (info.flags & ApplicationCommandInfo::isTicked) != 0,
  55311. 0,
  55312. Colours::black,
  55313. false,
  55314. 0, 0,
  55315. commandManager));
  55316. }
  55317. }
  55318. void PopupMenu::addColouredItem (const int itemResultId,
  55319. const String& itemText,
  55320. const Colour& itemTextColour,
  55321. const bool isActive,
  55322. const bool isTicked,
  55323. const Image* const iconToUse)
  55324. {
  55325. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55326. // didn't pick anything, so you shouldn't use it as the id
  55327. // for an item..
  55328. addSeparatorIfPending();
  55329. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  55330. iconToUse, itemTextColour, true, 0, 0, 0));
  55331. }
  55332. void PopupMenu::addCustomItem (const int itemResultId,
  55333. PopupMenuCustomComponent* const customComponent)
  55334. {
  55335. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55336. // didn't pick anything, so you shouldn't use it as the id
  55337. // for an item..
  55338. addSeparatorIfPending();
  55339. items.add (new Item (itemResultId, String::empty, true, false, 0,
  55340. Colours::black, false, customComponent, 0, 0));
  55341. }
  55342. class NormalComponentWrapper : public PopupMenuCustomComponent
  55343. {
  55344. public:
  55345. NormalComponentWrapper (Component* const comp,
  55346. const int w, const int h,
  55347. const bool triggerMenuItemAutomaticallyWhenClicked)
  55348. : PopupMenuCustomComponent (triggerMenuItemAutomaticallyWhenClicked),
  55349. width (w),
  55350. height (h)
  55351. {
  55352. addAndMakeVisible (comp);
  55353. }
  55354. ~NormalComponentWrapper() {}
  55355. void getIdealSize (int& idealWidth, int& idealHeight)
  55356. {
  55357. idealWidth = width;
  55358. idealHeight = height;
  55359. }
  55360. void resized()
  55361. {
  55362. if (getChildComponent(0) != 0)
  55363. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  55364. }
  55365. juce_UseDebuggingNewOperator
  55366. private:
  55367. const int width, height;
  55368. NormalComponentWrapper (const NormalComponentWrapper&);
  55369. NormalComponentWrapper& operator= (const NormalComponentWrapper&);
  55370. };
  55371. void PopupMenu::addCustomItem (const int itemResultId,
  55372. Component* customComponent,
  55373. int idealWidth, int idealHeight,
  55374. const bool triggerMenuItemAutomaticallyWhenClicked)
  55375. {
  55376. addCustomItem (itemResultId,
  55377. new NormalComponentWrapper (customComponent,
  55378. idealWidth, idealHeight,
  55379. triggerMenuItemAutomaticallyWhenClicked));
  55380. }
  55381. void PopupMenu::addSubMenu (const String& subMenuName,
  55382. const PopupMenu& subMenu,
  55383. const bool isActive,
  55384. Image* const iconToUse,
  55385. const bool isTicked)
  55386. {
  55387. addSeparatorIfPending();
  55388. items.add (new Item (0, subMenuName, isActive && (subMenu.getNumItems() > 0), isTicked,
  55389. iconToUse, Colours::black, false, 0, &subMenu, 0));
  55390. }
  55391. void PopupMenu::addSeparator()
  55392. {
  55393. separatorPending = true;
  55394. }
  55395. class HeaderItemComponent : public PopupMenuCustomComponent
  55396. {
  55397. public:
  55398. HeaderItemComponent (const String& name)
  55399. : PopupMenuCustomComponent (false)
  55400. {
  55401. setName (name);
  55402. }
  55403. ~HeaderItemComponent()
  55404. {
  55405. }
  55406. void paint (Graphics& g)
  55407. {
  55408. Font f (getLookAndFeel().getPopupMenuFont());
  55409. f.setBold (true);
  55410. g.setFont (f);
  55411. g.setColour (findColour (PopupMenu::headerTextColourId));
  55412. g.drawFittedText (getName(),
  55413. 12, 0, getWidth() - 16, proportionOfHeight (0.8f),
  55414. Justification::bottomLeft, 1);
  55415. }
  55416. void getIdealSize (int& idealWidth,
  55417. int& idealHeight)
  55418. {
  55419. getLookAndFeel().getIdealPopupMenuItemSize (getName(), false, -1, idealWidth, idealHeight);
  55420. idealHeight += idealHeight / 2;
  55421. idealWidth += idealWidth / 4;
  55422. }
  55423. juce_UseDebuggingNewOperator
  55424. };
  55425. void PopupMenu::addSectionHeader (const String& title)
  55426. {
  55427. addCustomItem (0X4734a34f, new HeaderItemComponent (title));
  55428. }
  55429. Component* PopupMenu::createMenuComponent (const int x, const int y, const int w, const int h,
  55430. const int itemIdThatMustBeVisible,
  55431. const int minimumWidth,
  55432. const int maximumNumColumns,
  55433. const int standardItemHeight,
  55434. const bool alignToRectangle,
  55435. Component* menuBarComponent,
  55436. ApplicationCommandManager** managerOfChosenCommand,
  55437. Component* const componentAttachedTo)
  55438. {
  55439. Window* const pw
  55440. = Window::create (*this,
  55441. ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown(),
  55442. 0,
  55443. x, x + w,
  55444. y, y + h,
  55445. minimumWidth,
  55446. maximumNumColumns,
  55447. standardItemHeight,
  55448. alignToRectangle,
  55449. itemIdThatMustBeVisible,
  55450. menuBarComponent,
  55451. managerOfChosenCommand,
  55452. componentAttachedTo);
  55453. if (pw != 0)
  55454. pw->setVisible (true);
  55455. return pw;
  55456. }
  55457. int PopupMenu::showMenu (const int x, const int y, const int w, const int h,
  55458. const int itemIdThatMustBeVisible,
  55459. const int minimumWidth,
  55460. const int maximumNumColumns,
  55461. const int standardItemHeight,
  55462. const bool alignToRectangle,
  55463. Component* const componentAttachedTo)
  55464. {
  55465. Component::SafePointer<Component> prevFocused (Component::getCurrentlyFocusedComponent());
  55466. Component::SafePointer<Component> prevTopLevel ((prevFocused != 0) ? prevFocused->getTopLevelComponent() : 0);
  55467. Window::wasHiddenBecauseOfAppChange() = false;
  55468. int result = 0;
  55469. ApplicationCommandManager* managerOfChosenCommand = 0;
  55470. ScopedPointer <Component> popupComp (createMenuComponent (x, y, w, h,
  55471. itemIdThatMustBeVisible,
  55472. minimumWidth,
  55473. maximumNumColumns > 0 ? maximumNumColumns : 7,
  55474. standardItemHeight,
  55475. alignToRectangle, 0,
  55476. &managerOfChosenCommand,
  55477. componentAttachedTo));
  55478. if (popupComp != 0)
  55479. {
  55480. popupComp->enterModalState (false);
  55481. popupComp->toFront (false); // need to do this after making it modal, or it could
  55482. // be stuck behind other comps that are already modal..
  55483. result = popupComp->runModalLoop();
  55484. popupComp = 0;
  55485. if (! Window::wasHiddenBecauseOfAppChange())
  55486. {
  55487. if (prevTopLevel != 0)
  55488. prevTopLevel->toFront (true);
  55489. if (prevFocused != 0)
  55490. prevFocused->grabKeyboardFocus();
  55491. }
  55492. }
  55493. if (managerOfChosenCommand != 0 && result != 0)
  55494. {
  55495. ApplicationCommandTarget::InvocationInfo info (result);
  55496. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  55497. managerOfChosenCommand->invoke (info, true);
  55498. }
  55499. return result;
  55500. }
  55501. int PopupMenu::show (const int itemIdThatMustBeVisible,
  55502. const int minimumWidth,
  55503. const int maximumNumColumns,
  55504. const int standardItemHeight)
  55505. {
  55506. const Point<int> mousePos (Desktop::getMousePosition());
  55507. return showAt (mousePos.getX(), mousePos.getY(),
  55508. itemIdThatMustBeVisible,
  55509. minimumWidth,
  55510. maximumNumColumns,
  55511. standardItemHeight);
  55512. }
  55513. int PopupMenu::showAt (const int screenX,
  55514. const int screenY,
  55515. const int itemIdThatMustBeVisible,
  55516. const int minimumWidth,
  55517. const int maximumNumColumns,
  55518. const int standardItemHeight)
  55519. {
  55520. return showMenu (screenX, screenY, 1, 1,
  55521. itemIdThatMustBeVisible,
  55522. minimumWidth, maximumNumColumns,
  55523. standardItemHeight,
  55524. false, 0);
  55525. }
  55526. int PopupMenu::showAt (Component* componentToAttachTo,
  55527. const int itemIdThatMustBeVisible,
  55528. const int minimumWidth,
  55529. const int maximumNumColumns,
  55530. const int standardItemHeight)
  55531. {
  55532. if (componentToAttachTo != 0)
  55533. {
  55534. return showMenu (componentToAttachTo->getScreenX(),
  55535. componentToAttachTo->getScreenY(),
  55536. componentToAttachTo->getWidth(),
  55537. componentToAttachTo->getHeight(),
  55538. itemIdThatMustBeVisible,
  55539. minimumWidth,
  55540. maximumNumColumns,
  55541. standardItemHeight,
  55542. true, componentToAttachTo);
  55543. }
  55544. else
  55545. {
  55546. return show (itemIdThatMustBeVisible,
  55547. minimumWidth,
  55548. maximumNumColumns,
  55549. standardItemHeight);
  55550. }
  55551. }
  55552. void JUCE_CALLTYPE PopupMenu::dismissAllActiveMenus()
  55553. {
  55554. for (int i = Window::getActiveWindows().size(); --i >= 0;)
  55555. {
  55556. Window* const pmw = Window::getActiveWindows()[i];
  55557. if (pmw != 0)
  55558. pmw->dismissMenu (0);
  55559. }
  55560. }
  55561. int PopupMenu::getNumItems() const throw()
  55562. {
  55563. int num = 0;
  55564. for (int i = items.size(); --i >= 0;)
  55565. if (! (items.getUnchecked(i))->isSeparator)
  55566. ++num;
  55567. return num;
  55568. }
  55569. bool PopupMenu::containsCommandItem (const int commandID) const
  55570. {
  55571. for (int i = items.size(); --i >= 0;)
  55572. {
  55573. const Item* mi = items.getUnchecked (i);
  55574. if ((mi->itemId == commandID && mi->commandManager != 0)
  55575. || (mi->subMenu != 0 && mi->subMenu->containsCommandItem (commandID)))
  55576. {
  55577. return true;
  55578. }
  55579. }
  55580. return false;
  55581. }
  55582. bool PopupMenu::containsAnyActiveItems() const throw()
  55583. {
  55584. for (int i = items.size(); --i >= 0;)
  55585. {
  55586. const Item* const mi = items.getUnchecked (i);
  55587. if (mi->subMenu != 0)
  55588. {
  55589. if (mi->subMenu->containsAnyActiveItems())
  55590. return true;
  55591. }
  55592. else if (mi->active)
  55593. {
  55594. return true;
  55595. }
  55596. }
  55597. return false;
  55598. }
  55599. void PopupMenu::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  55600. {
  55601. lookAndFeel = newLookAndFeel;
  55602. }
  55603. PopupMenuCustomComponent::PopupMenuCustomComponent (const bool isTriggeredAutomatically_)
  55604. : isHighlighted (false),
  55605. isTriggeredAutomatically (isTriggeredAutomatically_)
  55606. {
  55607. }
  55608. PopupMenuCustomComponent::~PopupMenuCustomComponent()
  55609. {
  55610. }
  55611. void PopupMenuCustomComponent::triggerMenuItem()
  55612. {
  55613. PopupMenu::ItemComponent* const mic = dynamic_cast <PopupMenu::ItemComponent*> (getParentComponent());
  55614. if (mic != 0)
  55615. {
  55616. PopupMenu::Window* const pmw = dynamic_cast <PopupMenu::Window*> (mic->getParentComponent());
  55617. if (pmw != 0)
  55618. {
  55619. pmw->dismissMenu (&mic->itemInfo);
  55620. }
  55621. else
  55622. {
  55623. // something must have gone wrong with the component hierarchy if this happens..
  55624. jassertfalse
  55625. }
  55626. }
  55627. else
  55628. {
  55629. // why isn't this component inside a menu? Not much point triggering the item if
  55630. // there's no menu.
  55631. jassertfalse
  55632. }
  55633. }
  55634. PopupMenu::MenuItemIterator::MenuItemIterator (const PopupMenu& menu_)
  55635. : subMenu (0),
  55636. itemId (0),
  55637. isSeparator (false),
  55638. isTicked (false),
  55639. isEnabled (false),
  55640. isCustomComponent (false),
  55641. isSectionHeader (false),
  55642. customColour (0),
  55643. customImage (0),
  55644. menu (menu_),
  55645. index (0)
  55646. {
  55647. }
  55648. PopupMenu::MenuItemIterator::~MenuItemIterator()
  55649. {
  55650. }
  55651. bool PopupMenu::MenuItemIterator::next()
  55652. {
  55653. if (index >= menu.items.size())
  55654. return false;
  55655. const Item* const item = menu.items.getUnchecked (index);
  55656. ++index;
  55657. itemName = item->customComp != 0 ? item->customComp->getName() : item->text;
  55658. subMenu = item->subMenu;
  55659. itemId = item->itemId;
  55660. isSeparator = item->isSeparator;
  55661. isTicked = item->isTicked;
  55662. isEnabled = item->active;
  55663. isSectionHeader = dynamic_cast <HeaderItemComponent*> ((PopupMenuCustomComponent*) item->customComp) != 0;
  55664. isCustomComponent = (! isSectionHeader) && item->customComp != 0;
  55665. customColour = item->usesColour ? &(item->textColour) : 0;
  55666. customImage = item->image;
  55667. commandManager = item->commandManager;
  55668. return true;
  55669. }
  55670. END_JUCE_NAMESPACE
  55671. /*** End of inlined file: juce_PopupMenu.cpp ***/
  55672. /*** Start of inlined file: juce_ComponentDragger.cpp ***/
  55673. BEGIN_JUCE_NAMESPACE
  55674. ComponentDragger::ComponentDragger()
  55675. : constrainer (0)
  55676. {
  55677. }
  55678. ComponentDragger::~ComponentDragger()
  55679. {
  55680. }
  55681. void ComponentDragger::startDraggingComponent (Component* const componentToDrag,
  55682. ComponentBoundsConstrainer* const constrainer_)
  55683. {
  55684. jassert (componentToDrag->isValidComponent());
  55685. if (componentToDrag != 0)
  55686. {
  55687. constrainer = constrainer_;
  55688. originalPos = componentToDrag->relativePositionToGlobal (Point<int>());
  55689. }
  55690. }
  55691. void ComponentDragger::dragComponent (Component* const componentToDrag, const MouseEvent& e)
  55692. {
  55693. jassert (componentToDrag->isValidComponent());
  55694. jassert (e.mods.isAnyMouseButtonDown()); // (the event has to be a drag event..)
  55695. if (componentToDrag != 0)
  55696. {
  55697. Rectangle<int> bounds (componentToDrag->getBounds().withPosition (originalPos));
  55698. const Component* const parentComp = componentToDrag->getParentComponent();
  55699. if (parentComp != 0)
  55700. bounds.setPosition (parentComp->globalPositionToRelative (originalPos));
  55701. bounds.setPosition (bounds.getPosition() + e.getOffsetFromDragStart());
  55702. if (constrainer != 0)
  55703. constrainer->setBoundsForComponent (componentToDrag, bounds, false, false, false, false);
  55704. else
  55705. componentToDrag->setBounds (bounds);
  55706. }
  55707. }
  55708. END_JUCE_NAMESPACE
  55709. /*** End of inlined file: juce_ComponentDragger.cpp ***/
  55710. /*** Start of inlined file: juce_DragAndDropContainer.cpp ***/
  55711. BEGIN_JUCE_NAMESPACE
  55712. bool juce_performDragDropFiles (const StringArray& files, const bool copyFiles, bool& shouldStop);
  55713. bool juce_performDragDropText (const String& text, bool& shouldStop);
  55714. class DragImageComponent : public Component,
  55715. public Timer
  55716. {
  55717. public:
  55718. DragImageComponent (Image* const im,
  55719. const String& desc,
  55720. Component* const sourceComponent,
  55721. Component* const mouseDragSource_,
  55722. DragAndDropContainer* const o,
  55723. const Point<int>& imageOffset_)
  55724. : image (im),
  55725. source (sourceComponent),
  55726. mouseDragSource (mouseDragSource_),
  55727. owner (o),
  55728. dragDesc (desc),
  55729. imageOffset (imageOffset_),
  55730. hasCheckedForExternalDrag (false),
  55731. drawImage (true)
  55732. {
  55733. setSize (im->getWidth(), im->getHeight());
  55734. if (mouseDragSource == 0)
  55735. mouseDragSource = source;
  55736. mouseDragSource->addMouseListener (this, false);
  55737. startTimer (200);
  55738. setInterceptsMouseClicks (false, false);
  55739. setAlwaysOnTop (true);
  55740. }
  55741. ~DragImageComponent()
  55742. {
  55743. if (owner->dragImageComponent == this)
  55744. owner->dragImageComponent.release();
  55745. if (mouseDragSource != 0)
  55746. {
  55747. mouseDragSource->removeMouseListener (this);
  55748. if (getCurrentlyOver() != 0 && getCurrentlyOver()->isInterestedInDragSource (dragDesc, source))
  55749. getCurrentlyOver()->itemDragExit (dragDesc, source);
  55750. }
  55751. }
  55752. void paint (Graphics& g)
  55753. {
  55754. if (isOpaque())
  55755. g.fillAll (Colours::white);
  55756. if (drawImage)
  55757. {
  55758. g.setOpacity (1.0f);
  55759. g.drawImageAt (image, 0, 0);
  55760. }
  55761. }
  55762. DragAndDropTarget* findTarget (const Point<int>& screenPos, Point<int>& relativePos)
  55763. {
  55764. Component* hit = getParentComponent();
  55765. if (hit == 0)
  55766. {
  55767. hit = Desktop::getInstance().findComponentAt (screenPos);
  55768. }
  55769. else
  55770. {
  55771. const Point<int> relPos (hit->globalPositionToRelative (screenPos));
  55772. hit = hit->getComponentAt (relPos.getX(), relPos.getY());
  55773. }
  55774. // (note: use a local copy of the dragDesc member in case the callback runs
  55775. // a modal loop and deletes this object before the method completes)
  55776. const String dragDescLocal (dragDesc);
  55777. while (hit != 0)
  55778. {
  55779. DragAndDropTarget* const ddt = dynamic_cast <DragAndDropTarget*> (hit);
  55780. if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
  55781. {
  55782. relativePos = hit->globalPositionToRelative (screenPos);
  55783. return ddt;
  55784. }
  55785. hit = hit->getParentComponent();
  55786. }
  55787. return 0;
  55788. }
  55789. void mouseUp (const MouseEvent& e)
  55790. {
  55791. if (e.originalComponent != this)
  55792. {
  55793. if (mouseDragSource != 0)
  55794. mouseDragSource->removeMouseListener (this);
  55795. bool dropAccepted = false;
  55796. DragAndDropTarget* ddt = 0;
  55797. Point<int> relPos;
  55798. if (isVisible())
  55799. {
  55800. setVisible (false);
  55801. ddt = findTarget (e.getScreenPosition(), relPos);
  55802. // fade this component and remove it - it'll be deleted later by the timer callback
  55803. dropAccepted = ddt != 0;
  55804. setVisible (true);
  55805. if (dropAccepted || source == 0)
  55806. {
  55807. fadeOutComponent (120);
  55808. }
  55809. else
  55810. {
  55811. const Point<int> target (source->relativePositionToGlobal (Point<int> (source->getWidth() / 2,
  55812. source->getHeight() / 2)));
  55813. const Point<int> ourCentre (relativePositionToGlobal (Point<int> (getWidth() / 2,
  55814. getHeight() / 2)));
  55815. fadeOutComponent (120,
  55816. target.getX() - ourCentre.getX(),
  55817. target.getY() - ourCentre.getY());
  55818. }
  55819. }
  55820. if (getParentComponent() != 0)
  55821. getParentComponent()->removeChildComponent (this);
  55822. if (dropAccepted && ddt != 0)
  55823. {
  55824. // (note: use a local copy of the dragDesc member in case the callback runs
  55825. // a modal loop and deletes this object before the method completes)
  55826. const String dragDescLocal (dragDesc);
  55827. currentlyOverComp = 0;
  55828. ddt->itemDropped (dragDescLocal, source, relPos.getX(), relPos.getY());
  55829. }
  55830. // careful - this object could now be deleted..
  55831. }
  55832. }
  55833. void updateLocation (const bool canDoExternalDrag, const Point<int>& screenPos)
  55834. {
  55835. // (note: use a local copy of the dragDesc member in case the callback runs
  55836. // a modal loop and deletes this object before it returns)
  55837. const String dragDescLocal (dragDesc);
  55838. Point<int> newPos (screenPos + imageOffset);
  55839. if (getParentComponent() != 0)
  55840. newPos = getParentComponent()->globalPositionToRelative (newPos);
  55841. //if (newX != getX() || newY != getY())
  55842. {
  55843. setTopLeftPosition (newPos.getX(), newPos.getY());
  55844. Point<int> relPos;
  55845. DragAndDropTarget* const ddt = findTarget (screenPos, relPos);
  55846. Component* ddtComp = dynamic_cast <Component*> (ddt);
  55847. drawImage = (ddt == 0) || ddt->shouldDrawDragImageWhenOver();
  55848. if (ddtComp != currentlyOverComp)
  55849. {
  55850. if (currentlyOverComp != 0 && source != 0
  55851. && getCurrentlyOver()->isInterestedInDragSource (dragDescLocal, source))
  55852. {
  55853. getCurrentlyOver()->itemDragExit (dragDescLocal, source);
  55854. }
  55855. currentlyOverComp = ddtComp;
  55856. if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
  55857. ddt->itemDragEnter (dragDescLocal, source, relPos.getX(), relPos.getY());
  55858. }
  55859. if (getCurrentlyOver() != 0 && getCurrentlyOver()->isInterestedInDragSource (dragDescLocal, source))
  55860. getCurrentlyOver()->itemDragMove (dragDescLocal, source, relPos.getX(), relPos.getY());
  55861. if (getCurrentlyOver() == 0
  55862. && canDoExternalDrag
  55863. && ! hasCheckedForExternalDrag)
  55864. {
  55865. if (Desktop::getInstance().findComponentAt (screenPos) == 0)
  55866. {
  55867. hasCheckedForExternalDrag = true;
  55868. StringArray files;
  55869. bool canMoveFiles = false;
  55870. if (owner->shouldDropFilesWhenDraggedExternally (dragDescLocal, source, files, canMoveFiles)
  55871. && files.size() > 0)
  55872. {
  55873. Component::SafePointer<Component> cdw (this);
  55874. setVisible (false);
  55875. if (ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown())
  55876. DragAndDropContainer::performExternalDragDropOfFiles (files, canMoveFiles);
  55877. if (cdw != 0)
  55878. delete this;
  55879. return;
  55880. }
  55881. }
  55882. }
  55883. }
  55884. }
  55885. void mouseDrag (const MouseEvent& e)
  55886. {
  55887. if (e.originalComponent != this)
  55888. updateLocation (true, e.getScreenPosition());
  55889. }
  55890. void timerCallback()
  55891. {
  55892. if (source == 0)
  55893. {
  55894. delete this;
  55895. }
  55896. else if (! isMouseButtonDownAnywhere())
  55897. {
  55898. if (mouseDragSource != 0)
  55899. mouseDragSource->removeMouseListener (this);
  55900. delete this;
  55901. }
  55902. }
  55903. private:
  55904. ScopedPointer<Image> image;
  55905. Component::SafePointer<Component> source;
  55906. Component::SafePointer<Component> mouseDragSource;
  55907. DragAndDropContainer* const owner;
  55908. Component::SafePointer<Component> currentlyOverComp;
  55909. DragAndDropTarget* getCurrentlyOver()
  55910. {
  55911. return dynamic_cast <DragAndDropTarget*> (static_cast <Component*> (currentlyOverComp));
  55912. }
  55913. String dragDesc;
  55914. const Point<int> imageOffset;
  55915. bool hasCheckedForExternalDrag, drawImage;
  55916. DragImageComponent (const DragImageComponent&);
  55917. DragImageComponent& operator= (const DragImageComponent&);
  55918. };
  55919. DragAndDropContainer::DragAndDropContainer()
  55920. {
  55921. }
  55922. DragAndDropContainer::~DragAndDropContainer()
  55923. {
  55924. dragImageComponent = 0;
  55925. }
  55926. void DragAndDropContainer::startDragging (const String& sourceDescription,
  55927. Component* sourceComponent,
  55928. Image* dragImage_,
  55929. const bool allowDraggingToExternalWindows,
  55930. const Point<int>* imageOffsetFromMouse)
  55931. {
  55932. ScopedPointer <Image> dragImage (dragImage_);
  55933. if (dragImageComponent == 0)
  55934. {
  55935. Component* const thisComp = dynamic_cast <Component*> (this);
  55936. if (thisComp == 0)
  55937. {
  55938. jassertfalse; // Your DragAndDropContainer needs to be a Component!
  55939. return;
  55940. }
  55941. MouseInputSource* draggingSource = Desktop::getInstance().getDraggingMouseSource (0);
  55942. if (draggingSource == 0 || ! draggingSource->isDragging())
  55943. {
  55944. jassertfalse; // You must call startDragging() from within a mouseDown or mouseDrag callback!
  55945. return;
  55946. }
  55947. const Point<int> lastMouseDown (Desktop::getLastMouseDownPosition());
  55948. Point<int> imageOffset;
  55949. if (dragImage == 0)
  55950. {
  55951. dragImage = sourceComponent->createComponentSnapshot (Rectangle<int> (0, 0, sourceComponent->getWidth(), sourceComponent->getHeight()));
  55952. if (dragImage->getFormat() != Image::ARGB)
  55953. {
  55954. Image* newIm = Image::createNativeImage (Image::ARGB, dragImage->getWidth(), dragImage->getHeight(), true);
  55955. Graphics g2 (*newIm);
  55956. g2.drawImageAt (dragImage, 0, 0);
  55957. dragImage = newIm;
  55958. }
  55959. dragImage->multiplyAllAlphas (0.6f);
  55960. const int lo = 150;
  55961. const int hi = 400;
  55962. Point<int> relPos (sourceComponent->globalPositionToRelative (lastMouseDown));
  55963. Point<int> clipped (Rectangle<int> (0, 0, dragImage->getWidth(), dragImage->getHeight())
  55964. .getConstrainedPoint (relPos));
  55965. for (int y = dragImage->getHeight(); --y >= 0;)
  55966. {
  55967. const double dy = (y - clipped.getY()) * (y - clipped.getY());
  55968. for (int x = dragImage->getWidth(); --x >= 0;)
  55969. {
  55970. const int dx = x - clipped.getX();
  55971. const int distance = roundToInt (sqrt (dx * dx + dy));
  55972. if (distance > lo)
  55973. {
  55974. const float alpha = (distance > hi) ? 0
  55975. : (hi - distance) / (float) (hi - lo)
  55976. + Random::getSystemRandom().nextFloat() * 0.008f;
  55977. dragImage->multiplyAlphaAt (x, y, alpha);
  55978. }
  55979. }
  55980. }
  55981. imageOffset = -clipped;
  55982. }
  55983. else
  55984. {
  55985. if (imageOffsetFromMouse == 0)
  55986. imageOffset = Point<int> (dragImage->getWidth() / -2,
  55987. dragImage->getHeight() / -2);
  55988. else
  55989. imageOffset = *imageOffsetFromMouse;
  55990. }
  55991. dragImageComponent = new DragImageComponent (dragImage.release(), sourceDescription, sourceComponent,
  55992. draggingSource->getComponentUnderMouse(), this, imageOffset);
  55993. currentDragDesc = sourceDescription;
  55994. if (allowDraggingToExternalWindows)
  55995. {
  55996. if (! Desktop::canUseSemiTransparentWindows())
  55997. dragImageComponent->setOpaque (true);
  55998. dragImageComponent->addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  55999. | ComponentPeer::windowIsTemporary
  56000. | ComponentPeer::windowIgnoresKeyPresses);
  56001. }
  56002. else
  56003. thisComp->addChildComponent (dragImageComponent);
  56004. static_cast <DragImageComponent*> (static_cast <Component*> (dragImageComponent))->updateLocation (false, lastMouseDown);
  56005. dragImageComponent->setVisible (true);
  56006. }
  56007. }
  56008. bool DragAndDropContainer::isDragAndDropActive() const
  56009. {
  56010. return dragImageComponent != 0;
  56011. }
  56012. const String DragAndDropContainer::getCurrentDragDescription() const
  56013. {
  56014. return (dragImageComponent != 0) ? currentDragDesc
  56015. : String::empty;
  56016. }
  56017. DragAndDropContainer* DragAndDropContainer::findParentDragContainerFor (Component* c)
  56018. {
  56019. if (c == 0)
  56020. return 0;
  56021. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  56022. return c->findParentComponentOfClass ((DragAndDropContainer*) 0);
  56023. }
  56024. bool DragAndDropContainer::shouldDropFilesWhenDraggedExternally (const String&, Component*, StringArray&, bool&)
  56025. {
  56026. return false;
  56027. }
  56028. void DragAndDropTarget::itemDragEnter (const String&, Component*, int, int)
  56029. {
  56030. }
  56031. void DragAndDropTarget::itemDragMove (const String&, Component*, int, int)
  56032. {
  56033. }
  56034. void DragAndDropTarget::itemDragExit (const String&, Component*)
  56035. {
  56036. }
  56037. bool DragAndDropTarget::shouldDrawDragImageWhenOver()
  56038. {
  56039. return true;
  56040. }
  56041. void FileDragAndDropTarget::fileDragEnter (const StringArray&, int, int)
  56042. {
  56043. }
  56044. void FileDragAndDropTarget::fileDragMove (const StringArray&, int, int)
  56045. {
  56046. }
  56047. void FileDragAndDropTarget::fileDragExit (const StringArray&)
  56048. {
  56049. }
  56050. END_JUCE_NAMESPACE
  56051. /*** End of inlined file: juce_DragAndDropContainer.cpp ***/
  56052. /*** Start of inlined file: juce_MouseCursor.cpp ***/
  56053. BEGIN_JUCE_NAMESPACE
  56054. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw();
  56055. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw();
  56056. // isStandard set depending on which interface was used to create the cursor
  56057. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw();
  56058. static CriticalSection activeCursorListLock;
  56059. static VoidArray activeCursors;
  56060. class SharedMouseCursorInternal : public ReferenceCountedObject
  56061. {
  56062. public:
  56063. SharedMouseCursorInternal (const MouseCursor::StandardCursorType type) throw()
  56064. : standardType (type),
  56065. isStandard (true)
  56066. {
  56067. handle = juce_createStandardMouseCursor (standardType);
  56068. activeCursors.add (this);
  56069. }
  56070. SharedMouseCursorInternal (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56071. : standardType (MouseCursor::NormalCursor),
  56072. isStandard (false)
  56073. {
  56074. handle = juce_createMouseCursorFromImage (image, hotSpotX, hotSpotY);
  56075. }
  56076. ~SharedMouseCursorInternal() throw()
  56077. {
  56078. juce_deleteMouseCursor (handle, isStandard);
  56079. activeCursors.removeValue (this);
  56080. }
  56081. void* getHandle() const throw()
  56082. {
  56083. return handle;
  56084. }
  56085. static SharedMouseCursorInternal* findInstance (MouseCursor::StandardCursorType type) throw()
  56086. {
  56087. for (int i = activeCursors.size(); --i >= 0;)
  56088. {
  56089. SharedMouseCursorInternal* const r = (SharedMouseCursorInternal*) activeCursors.getUnchecked(i);
  56090. if (r->standardType == type)
  56091. return r;
  56092. }
  56093. return new SharedMouseCursorInternal (type);
  56094. }
  56095. juce_UseDebuggingNewOperator
  56096. private:
  56097. void* handle;
  56098. const MouseCursor::StandardCursorType standardType;
  56099. const bool isStandard;
  56100. SharedMouseCursorInternal& operator= (const SharedMouseCursorInternal&);
  56101. };
  56102. MouseCursor::MouseCursor() throw()
  56103. {
  56104. const ScopedLock sl (activeCursorListLock);
  56105. cursorHandle = SharedMouseCursorInternal::findInstance (NormalCursor);
  56106. }
  56107. MouseCursor::MouseCursor (const StandardCursorType type) throw()
  56108. {
  56109. const ScopedLock sl (activeCursorListLock);
  56110. cursorHandle = SharedMouseCursorInternal::findInstance (type);
  56111. }
  56112. MouseCursor::MouseCursor (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56113. {
  56114. const ScopedLock sl (activeCursorListLock);
  56115. cursorHandle = new SharedMouseCursorInternal (image, hotSpotX, hotSpotY);
  56116. }
  56117. MouseCursor::MouseCursor (const MouseCursor& other) throw()
  56118. : cursorHandle (other.cursorHandle)
  56119. {
  56120. }
  56121. MouseCursor::~MouseCursor() throw()
  56122. {
  56123. }
  56124. MouseCursor& MouseCursor::operator= (const MouseCursor& other) throw()
  56125. {
  56126. cursorHandle = other.cursorHandle;
  56127. return *this;
  56128. }
  56129. bool MouseCursor::operator== (const MouseCursor& other) const throw()
  56130. {
  56131. return cursorHandle == other.cursorHandle;
  56132. }
  56133. bool MouseCursor::operator!= (const MouseCursor& other) const throw()
  56134. {
  56135. return cursorHandle != other.cursorHandle;
  56136. }
  56137. void* MouseCursor::getHandle() const throw()
  56138. {
  56139. return cursorHandle->getHandle();
  56140. }
  56141. void MouseCursor::showWaitCursor() throw()
  56142. {
  56143. Desktop::getInstance().getMainMouseSource().showMouseCursor (MouseCursor::WaitCursor);
  56144. }
  56145. void MouseCursor::hideWaitCursor() throw()
  56146. {
  56147. Desktop::getInstance().getMainMouseSource().revealCursor();
  56148. }
  56149. END_JUCE_NAMESPACE
  56150. /*** End of inlined file: juce_MouseCursor.cpp ***/
  56151. /*** Start of inlined file: juce_MouseEvent.cpp ***/
  56152. BEGIN_JUCE_NAMESPACE
  56153. MouseEvent::MouseEvent (MouseInputSource& source_,
  56154. const Point<int>& position,
  56155. const ModifierKeys& mods_,
  56156. Component* const originator,
  56157. const Time& eventTime_,
  56158. const Point<int> mouseDownPos_,
  56159. const Time& mouseDownTime_,
  56160. const int numberOfClicks_,
  56161. const bool mouseWasDragged) throw()
  56162. : x (position.getX()),
  56163. y (position.getY()),
  56164. mods (mods_),
  56165. eventComponent (originator),
  56166. originalComponent (originator),
  56167. eventTime (eventTime_),
  56168. source (source_),
  56169. mouseDownPos (mouseDownPos_),
  56170. mouseDownTime (mouseDownTime_),
  56171. numberOfClicks (numberOfClicks_),
  56172. wasMovedSinceMouseDown (mouseWasDragged)
  56173. {
  56174. }
  56175. MouseEvent::~MouseEvent() throw()
  56176. {
  56177. }
  56178. const MouseEvent MouseEvent::getEventRelativeTo (Component* const otherComponent) const throw()
  56179. {
  56180. if (otherComponent == 0)
  56181. {
  56182. jassertfalse
  56183. return *this;
  56184. }
  56185. return MouseEvent (source, eventComponent->relativePositionToOtherComponent (otherComponent, getPosition()),
  56186. mods, originalComponent, eventTime,
  56187. eventComponent->relativePositionToOtherComponent (otherComponent, mouseDownPos),
  56188. mouseDownTime, numberOfClicks, wasMovedSinceMouseDown);
  56189. }
  56190. const MouseEvent MouseEvent::withNewPosition (const Point<int>& newPosition) const throw()
  56191. {
  56192. return MouseEvent (source, newPosition, mods, originalComponent,
  56193. eventTime, mouseDownPos, mouseDownTime,
  56194. numberOfClicks, wasMovedSinceMouseDown);
  56195. }
  56196. bool MouseEvent::mouseWasClicked() const throw()
  56197. {
  56198. return ! wasMovedSinceMouseDown;
  56199. }
  56200. int MouseEvent::getMouseDownX() const throw()
  56201. {
  56202. return mouseDownPos.getX();
  56203. }
  56204. int MouseEvent::getMouseDownY() const throw()
  56205. {
  56206. return mouseDownPos.getY();
  56207. }
  56208. const Point<int> MouseEvent::getMouseDownPosition() const throw()
  56209. {
  56210. return mouseDownPos;
  56211. }
  56212. int MouseEvent::getDistanceFromDragStartX() const throw()
  56213. {
  56214. return x - mouseDownPos.getX();
  56215. }
  56216. int MouseEvent::getDistanceFromDragStartY() const throw()
  56217. {
  56218. return y - mouseDownPos.getY();
  56219. }
  56220. int MouseEvent::getDistanceFromDragStart() const throw()
  56221. {
  56222. return mouseDownPos.getDistanceFrom (getPosition());
  56223. }
  56224. const Point<int> MouseEvent::getOffsetFromDragStart() const throw()
  56225. {
  56226. return getPosition() - mouseDownPos;
  56227. }
  56228. int MouseEvent::getLengthOfMousePress() const throw()
  56229. {
  56230. if (mouseDownTime.toMilliseconds() > 0)
  56231. return jmax (0, (int) (eventTime - mouseDownTime).inMilliseconds());
  56232. return 0;
  56233. }
  56234. const Point<int> MouseEvent::getPosition() const throw()
  56235. {
  56236. return Point<int> (x, y);
  56237. }
  56238. int MouseEvent::getScreenX() const
  56239. {
  56240. return getScreenPosition().getX();
  56241. }
  56242. int MouseEvent::getScreenY() const
  56243. {
  56244. return getScreenPosition().getY();
  56245. }
  56246. const Point<int> MouseEvent::getScreenPosition() const
  56247. {
  56248. return eventComponent->relativePositionToGlobal (Point<int> (x, y));
  56249. }
  56250. int MouseEvent::getMouseDownScreenX() const
  56251. {
  56252. return getMouseDownScreenPosition().getX();
  56253. }
  56254. int MouseEvent::getMouseDownScreenY() const
  56255. {
  56256. return getMouseDownScreenPosition().getY();
  56257. }
  56258. const Point<int> MouseEvent::getMouseDownScreenPosition() const
  56259. {
  56260. return eventComponent->relativePositionToGlobal (mouseDownPos);
  56261. }
  56262. static int doubleClickTimeOutMs = 400;
  56263. void MouseEvent::setDoubleClickTimeout (const int newTime) throw()
  56264. {
  56265. doubleClickTimeOutMs = newTime;
  56266. }
  56267. int MouseEvent::getDoubleClickTimeout() throw()
  56268. {
  56269. return doubleClickTimeOutMs;
  56270. }
  56271. END_JUCE_NAMESPACE
  56272. /*** End of inlined file: juce_MouseEvent.cpp ***/
  56273. /*** Start of inlined file: juce_MouseInputSource.cpp ***/
  56274. BEGIN_JUCE_NAMESPACE
  56275. class MouseInputSourceInternal : public AsyncUpdater
  56276. {
  56277. public:
  56278. MouseInputSourceInternal (MouseInputSource& source_, const int index_, const bool isMouseDevice_)
  56279. : index (index_), isMouseDevice (isMouseDevice_), source (source_), lastPeer (0), lastTime (0),
  56280. isUnboundedMouseModeOn (false), isCursorVisibleUntilOffscreen (false), currentCursorHandle (0)
  56281. {
  56282. zerostruct (mouseDowns);
  56283. }
  56284. ~MouseInputSourceInternal()
  56285. {
  56286. }
  56287. bool isDragging() const throw()
  56288. {
  56289. return buttonState.isAnyMouseButtonDown();
  56290. }
  56291. Component* getComponentUnderMouse() const
  56292. {
  56293. return static_cast <Component*> (componentUnderMouse);
  56294. }
  56295. const ModifierKeys getCurrentModifiers() const
  56296. {
  56297. return ModifierKeys::getCurrentModifiers().withoutMouseButtons().withFlags (buttonState.getRawFlags());
  56298. }
  56299. ComponentPeer* getPeer()
  56300. {
  56301. if (! ComponentPeer::isValidPeer (lastPeer))
  56302. lastPeer = 0;
  56303. return lastPeer;
  56304. }
  56305. Component* findComponentAt (const Point<int>& screenPos)
  56306. {
  56307. ComponentPeer* const peer = getPeer();
  56308. if (peer != 0)
  56309. {
  56310. Component* const comp = peer->getComponent();
  56311. const Point<int> relativePos (comp->globalPositionToRelative (screenPos));
  56312. // (the contains() call is needed to test for overlapping desktop windows)
  56313. if (comp->contains (relativePos.getX(), relativePos.getY()))
  56314. return comp->getComponentAt (relativePos);
  56315. }
  56316. return 0;
  56317. }
  56318. const Point<int> getScreenPosition() const throw()
  56319. {
  56320. return lastScreenPos + unboundedMouseOffset;
  56321. }
  56322. void sendMouseEnter (Component* const comp, const Point<int>& screenPos, const int64 time)
  56323. {
  56324. //DBG ("Mouse " + String (source.getIndex()) + " enter: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56325. comp->internalMouseEnter (source, comp->globalPositionToRelative (screenPos), time);
  56326. }
  56327. void sendMouseExit (Component* const comp, const Point<int>& screenPos, const int64 time)
  56328. {
  56329. //DBG ("Mouse " + String (source.getIndex()) + " exit: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56330. comp->internalMouseExit (source, comp->globalPositionToRelative (screenPos), time);
  56331. }
  56332. void sendMouseMove (Component* const comp, const Point<int>& screenPos, const int64 time)
  56333. {
  56334. //DBG ("Mouse " + String (source.getIndex()) + " move: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56335. comp->internalMouseMove (source, comp->globalPositionToRelative (screenPos), time);
  56336. }
  56337. void sendMouseDown (Component* const comp, const Point<int>& screenPos, const int64 time)
  56338. {
  56339. //DBG ("Mouse " + String (source.getIndex()) + " down: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56340. comp->internalMouseDown (source, comp->globalPositionToRelative (screenPos), time);
  56341. }
  56342. void sendMouseDrag (Component* const comp, const Point<int>& screenPos, const int64 time)
  56343. {
  56344. //DBG ("Mouse " + String (source.getIndex()) + " drag: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56345. comp->internalMouseDrag (source, comp->globalPositionToRelative (screenPos), time);
  56346. }
  56347. void sendMouseUp (Component* const comp, const Point<int>& screenPos, const int64 time)
  56348. {
  56349. //DBG ("Mouse " + String (source.getIndex()) + " up: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56350. comp->internalMouseUp (source, comp->globalPositionToRelative (screenPos), time, getCurrentModifiers());
  56351. }
  56352. void sendMouseWheel (Component* const comp, const Point<int>& screenPos, const int64 time, float x, float y)
  56353. {
  56354. //DBG ("Mouse " + String (source.getIndex()) + " wheel: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56355. comp->internalMouseWheel (source, comp->globalPositionToRelative (screenPos), time, x, y);
  56356. }
  56357. void setButtons (const Point<int>& screenPos, const int64 time, const ModifierKeys& newButtonState)
  56358. {
  56359. if (buttonState != newButtonState)
  56360. {
  56361. // (ignore secondary clicks when there's already a button down)
  56362. if (buttonState.isAnyMouseButtonDown() == newButtonState.isAnyMouseButtonDown())
  56363. {
  56364. buttonState = newButtonState;
  56365. return;
  56366. }
  56367. if (buttonState.isAnyMouseButtonDown())
  56368. {
  56369. Component* const current = getComponentUnderMouse();
  56370. if (current != 0)
  56371. sendMouseUp (current, screenPos + unboundedMouseOffset, time);
  56372. enableUnboundedMouseMovement (false, false);
  56373. }
  56374. buttonState = newButtonState;
  56375. if (buttonState.isAnyMouseButtonDown())
  56376. {
  56377. Desktop::getInstance().incrementMouseClickCounter();
  56378. Component* const current = getComponentUnderMouse();
  56379. if (current != 0)
  56380. {
  56381. registerMouseDown (screenPos, time, current);
  56382. sendMouseDown (current, screenPos, time);
  56383. }
  56384. }
  56385. }
  56386. }
  56387. void setComponentUnderMouse (Component* const newComponent, const Point<int>& screenPos, const int64 time)
  56388. {
  56389. Component* current = getComponentUnderMouse();
  56390. if (newComponent != current)
  56391. {
  56392. Component::SafePointer<Component> safeNewComp (newComponent);
  56393. const ModifierKeys originalButtonState (buttonState);
  56394. if (current != 0)
  56395. {
  56396. setButtons (screenPos, time, ModifierKeys());
  56397. sendMouseExit (current, screenPos, time);
  56398. buttonState = originalButtonState;
  56399. }
  56400. componentUnderMouse = safeNewComp;
  56401. current = getComponentUnderMouse();
  56402. if (current != 0)
  56403. sendMouseEnter (current, screenPos, time);
  56404. revealCursor (false);
  56405. setButtons (screenPos, time, originalButtonState);
  56406. }
  56407. }
  56408. void setPeer (ComponentPeer* const newPeer, const Point<int>& screenPos, const int64 time)
  56409. {
  56410. ModifierKeys::updateCurrentModifiers();
  56411. if (newPeer != lastPeer)
  56412. {
  56413. setComponentUnderMouse (0, screenPos, time);
  56414. lastPeer = newPeer;
  56415. setComponentUnderMouse (findComponentAt (screenPos), screenPos, time);
  56416. }
  56417. }
  56418. void setScreenPos (const Point<int>& newScreenPos, const int64 time, const bool forceUpdate)
  56419. {
  56420. if (! isDragging())
  56421. setComponentUnderMouse (findComponentAt (newScreenPos), newScreenPos, time);
  56422. if (newScreenPos != lastScreenPos || forceUpdate)
  56423. {
  56424. cancelPendingUpdate();
  56425. lastScreenPos = newScreenPos;
  56426. Component* const current = getComponentUnderMouse();
  56427. if (current != 0)
  56428. {
  56429. if (isDragging())
  56430. {
  56431. registerMouseDrag (newScreenPos);
  56432. sendMouseDrag (current, newScreenPos + unboundedMouseOffset, time);
  56433. if (isUnboundedMouseModeOn)
  56434. handleUnboundedDrag (current);
  56435. }
  56436. else
  56437. {
  56438. sendMouseMove (current, newScreenPos, time);
  56439. }
  56440. }
  56441. revealCursor (false);
  56442. }
  56443. }
  56444. void handleEvent (ComponentPeer* const newPeer, const Point<int>& positionWithinPeer, const int64 time, const ModifierKeys& newMods)
  56445. {
  56446. jassert (newPeer != 0);
  56447. lastTime = time;
  56448. const Point<int> screenPos (newPeer->relativePositionToGlobal (positionWithinPeer));
  56449. if (isDragging() && newMods.isAnyMouseButtonDown())
  56450. {
  56451. setScreenPos (screenPos, time, false);
  56452. }
  56453. else
  56454. {
  56455. setPeer (newPeer, screenPos, time);
  56456. ComponentPeer* peer = getPeer();
  56457. if (peer != 0)
  56458. {
  56459. setButtons (screenPos, time, newMods);
  56460. peer = getPeer();
  56461. if (peer != 0)
  56462. setScreenPos (peer->relativePositionToGlobal (positionWithinPeer), time, false);
  56463. }
  56464. }
  56465. }
  56466. void handleWheel (ComponentPeer* const peer, const Point<int>& positionWithinPeer, int64 time, float x, float y)
  56467. {
  56468. jassert (peer != 0);
  56469. lastTime = time;
  56470. const Point<int> screenPos (peer->relativePositionToGlobal (positionWithinPeer));
  56471. setPeer (peer, screenPos, time);
  56472. setScreenPos (screenPos, time, false);
  56473. triggerFakeMove();
  56474. if (! isDragging())
  56475. {
  56476. Component* current = getComponentUnderMouse();
  56477. if (current != 0)
  56478. sendMouseWheel (current, screenPos, time, x, y);
  56479. }
  56480. }
  56481. const Time getLastMouseDownTime() const throw()
  56482. {
  56483. return Time (mouseDowns[0].time);
  56484. }
  56485. const Point<int> getLastMouseDownPosition() const throw()
  56486. {
  56487. return mouseDowns[0].position;
  56488. }
  56489. int getNumberOfMultipleClicks() const throw()
  56490. {
  56491. int numClicks = 0;
  56492. if (mouseDowns[0].time != 0)
  56493. {
  56494. if (! mouseMovedSignificantlySincePressed)
  56495. ++numClicks;
  56496. for (int i = 1; i < numElementsInArray (mouseDowns); ++i)
  56497. {
  56498. if (mouseDowns[0].time - mouseDowns[i].time < (int) (MouseEvent::getDoubleClickTimeout() * (1.0 + 0.25 * (i - 1)))
  56499. && abs (mouseDowns[0].position.getX() - mouseDowns[i].position.getX()) < 8
  56500. && abs (mouseDowns[0].position.getY() - mouseDowns[i].position.getY()) < 8
  56501. && mouseDowns[0].component == mouseDowns[i].component)
  56502. {
  56503. ++numClicks;
  56504. }
  56505. else
  56506. {
  56507. break;
  56508. }
  56509. }
  56510. }
  56511. return numClicks;
  56512. }
  56513. bool hasMouseMovedSignificantlySincePressed() const throw()
  56514. {
  56515. return mouseMovedSignificantlySincePressed
  56516. || lastTime > mouseDowns[0].time + 300;
  56517. }
  56518. void triggerFakeMove()
  56519. {
  56520. triggerAsyncUpdate();
  56521. }
  56522. void handleAsyncUpdate()
  56523. {
  56524. if (! isDragging())
  56525. setScreenPos (Desktop::getMousePosition(), jmax (lastTime, Time::currentTimeMillis()), true);
  56526. }
  56527. void enableUnboundedMouseMovement (bool enable, bool keepCursorVisibleUntilOffscreen)
  56528. {
  56529. enable = enable && isDragging();
  56530. isCursorVisibleUntilOffscreen = keepCursorVisibleUntilOffscreen;
  56531. if (enable != isUnboundedMouseModeOn)
  56532. {
  56533. if ((! enable) && ((! isCursorVisibleUntilOffscreen) || ! unboundedMouseOffset.isOrigin()))
  56534. {
  56535. // when released, return the mouse to within the component's bounds
  56536. Component* current = getComponentUnderMouse();
  56537. if (current != 0)
  56538. Desktop::setMousePosition (current->getScreenBounds()
  56539. .getConstrainedPoint (current->getMouseXYRelative()));
  56540. }
  56541. isUnboundedMouseModeOn = enable;
  56542. unboundedMouseOffset = Point<int>();
  56543. revealCursor (true);
  56544. }
  56545. }
  56546. void handleUnboundedDrag (Component* current)
  56547. {
  56548. const Rectangle<int> screenArea (current->getParentMonitorArea().expanded (-2, -2));
  56549. if (! screenArea.contains (lastScreenPos))
  56550. {
  56551. const Point<int> componentCentre (current->getScreenBounds().getCentre());
  56552. unboundedMouseOffset += (lastScreenPos - componentCentre);
  56553. Desktop::setMousePosition (componentCentre);
  56554. }
  56555. else if (isCursorVisibleUntilOffscreen
  56556. && (! unboundedMouseOffset.isOrigin())
  56557. && screenArea.contains (lastScreenPos + unboundedMouseOffset))
  56558. {
  56559. Desktop::setMousePosition (lastScreenPos + unboundedMouseOffset);
  56560. unboundedMouseOffset = Point<int>();
  56561. }
  56562. }
  56563. void showMouseCursor (MouseCursor cursor, bool forcedUpdate)
  56564. {
  56565. if (isUnboundedMouseModeOn && ((! unboundedMouseOffset.isOrigin()) || ! isCursorVisibleUntilOffscreen))
  56566. {
  56567. cursor = MouseCursor::NoCursor;
  56568. forcedUpdate = true;
  56569. }
  56570. if (forcedUpdate || cursor.getHandle() != currentCursorHandle)
  56571. {
  56572. currentCursorHandle = cursor.getHandle();
  56573. cursor.showInWindow (getPeer());
  56574. }
  56575. }
  56576. void hideCursor()
  56577. {
  56578. showMouseCursor (MouseCursor::NoCursor, true);
  56579. }
  56580. void revealCursor (bool forcedUpdate)
  56581. {
  56582. MouseCursor mc (MouseCursor::NormalCursor);
  56583. Component* current = getComponentUnderMouse();
  56584. if (current != 0)
  56585. mc = current->getLookAndFeel().getMouseCursorFor (*current);
  56586. showMouseCursor (mc, forcedUpdate);
  56587. }
  56588. int index;
  56589. bool isMouseDevice;
  56590. Point<int> lastScreenPos;
  56591. ModifierKeys buttonState;
  56592. private:
  56593. MouseInputSource& source;
  56594. Component::SafePointer<Component> componentUnderMouse;
  56595. ComponentPeer* lastPeer;
  56596. Point<int> unboundedMouseOffset;
  56597. bool isUnboundedMouseModeOn, isCursorVisibleUntilOffscreen;
  56598. void* currentCursorHandle;
  56599. struct RecentMouseDown
  56600. {
  56601. Point<int> position;
  56602. int64 time;
  56603. Component* component;
  56604. };
  56605. RecentMouseDown mouseDowns[4];
  56606. bool mouseMovedSignificantlySincePressed;
  56607. int64 lastTime;
  56608. void registerMouseDown (const Point<int>& screenPos, const int64 time, Component* const component) throw()
  56609. {
  56610. for (int i = numElementsInArray (mouseDowns); --i > 0;)
  56611. mouseDowns[i] = mouseDowns[i - 1];
  56612. mouseDowns[0].position = screenPos;
  56613. mouseDowns[0].time = time;
  56614. mouseDowns[0].component = component;
  56615. mouseMovedSignificantlySincePressed = false;
  56616. }
  56617. void registerMouseDrag (const Point<int>& screenPos) throw()
  56618. {
  56619. mouseMovedSignificantlySincePressed = mouseMovedSignificantlySincePressed
  56620. || mouseDowns[0].position.getDistanceFrom (screenPos) >= 4;
  56621. }
  56622. };
  56623. MouseInputSource::MouseInputSource (const int index, const bool isMouseDevice)
  56624. {
  56625. pimpl = new MouseInputSourceInternal (*this, index, isMouseDevice);
  56626. }
  56627. MouseInputSource::~MouseInputSource()
  56628. {
  56629. }
  56630. bool MouseInputSource::isMouse() const { return pimpl->isMouseDevice; }
  56631. bool MouseInputSource::isTouch() const { return ! isMouse(); }
  56632. bool MouseInputSource::canHover() const { return isMouse(); }
  56633. bool MouseInputSource::hasMouseWheel() const { return isMouse(); }
  56634. int MouseInputSource::getIndex() const { return pimpl->index; }
  56635. bool MouseInputSource::isDragging() const { return pimpl->isDragging(); }
  56636. const Point<int> MouseInputSource::getScreenPosition() const { return pimpl->getScreenPosition(); }
  56637. const ModifierKeys MouseInputSource::getCurrentModifiers() const { return pimpl->getCurrentModifiers(); }
  56638. Component* MouseInputSource::getComponentUnderMouse() const { return pimpl->getComponentUnderMouse(); }
  56639. void MouseInputSource::triggerFakeMove() const { pimpl->triggerFakeMove(); }
  56640. int MouseInputSource::getNumberOfMultipleClicks() const throw() { return pimpl->getNumberOfMultipleClicks(); }
  56641. const Time MouseInputSource::getLastMouseDownTime() const throw() { return pimpl->getLastMouseDownTime(); }
  56642. const Point<int> MouseInputSource::getLastMouseDownPosition() const throw() { return pimpl->getLastMouseDownPosition(); }
  56643. bool MouseInputSource::hasMouseMovedSignificantlySincePressed() const throw() { return pimpl->hasMouseMovedSignificantlySincePressed(); }
  56644. bool MouseInputSource::canDoUnboundedMovement() const throw() { return isMouse(); }
  56645. void MouseInputSource::enableUnboundedMouseMovement (bool isEnabled, bool keepCursorVisibleUntilOffscreen) { pimpl->enableUnboundedMouseMovement (isEnabled, keepCursorVisibleUntilOffscreen); }
  56646. bool MouseInputSource::hasMouseCursor() const throw() { return isMouse(); }
  56647. void MouseInputSource::showMouseCursor (const MouseCursor& cursor) { pimpl->showMouseCursor (cursor, false); }
  56648. void MouseInputSource::hideCursor() { pimpl->hideCursor(); }
  56649. void MouseInputSource::revealCursor() { pimpl->revealCursor (false); }
  56650. void MouseInputSource::forceMouseCursorUpdate() { pimpl->revealCursor (true); }
  56651. void MouseInputSource::handleEvent (ComponentPeer* peer, const Point<int>& positionWithinPeer, const int64 time, const ModifierKeys& mods)
  56652. {
  56653. pimpl->handleEvent (peer, positionWithinPeer, time, mods.withOnlyMouseButtons());
  56654. }
  56655. void MouseInputSource::handleWheel (ComponentPeer* const peer, const Point<int>& positionWithinPeer, const int64 time, const float x, const float y)
  56656. {
  56657. pimpl->handleWheel (peer, positionWithinPeer, time, x, y);
  56658. }
  56659. END_JUCE_NAMESPACE
  56660. /*** End of inlined file: juce_MouseInputSource.cpp ***/
  56661. /*** Start of inlined file: juce_MouseHoverDetector.cpp ***/
  56662. BEGIN_JUCE_NAMESPACE
  56663. MouseHoverDetector::MouseHoverDetector (const int hoverTimeMillisecs_)
  56664. : source (0),
  56665. hoverTimeMillisecs (hoverTimeMillisecs_),
  56666. hasJustHovered (false)
  56667. {
  56668. internalTimer.owner = this;
  56669. }
  56670. MouseHoverDetector::~MouseHoverDetector()
  56671. {
  56672. setHoverComponent (0);
  56673. }
  56674. void MouseHoverDetector::setHoverTimeMillisecs (const int newTimeInMillisecs)
  56675. {
  56676. hoverTimeMillisecs = newTimeInMillisecs;
  56677. }
  56678. void MouseHoverDetector::setHoverComponent (Component* const newSourceComponent)
  56679. {
  56680. if (source != newSourceComponent)
  56681. {
  56682. internalTimer.stopTimer();
  56683. hasJustHovered = false;
  56684. if (source != 0)
  56685. {
  56686. // ! you need to delete the hover detector before deleting its component
  56687. jassert (source->isValidComponent());
  56688. source->removeMouseListener (&internalTimer);
  56689. }
  56690. source = newSourceComponent;
  56691. if (newSourceComponent != 0)
  56692. newSourceComponent->addMouseListener (&internalTimer, false);
  56693. }
  56694. }
  56695. void MouseHoverDetector::hoverTimerCallback()
  56696. {
  56697. internalTimer.stopTimer();
  56698. if (source != 0)
  56699. {
  56700. const Point<int> pos (source->getMouseXYRelative());
  56701. if (source->reallyContains (pos.getX(), pos.getY(), false))
  56702. {
  56703. hasJustHovered = true;
  56704. mouseHovered (pos.getX(), pos.getY());
  56705. }
  56706. }
  56707. }
  56708. void MouseHoverDetector::checkJustHoveredCallback()
  56709. {
  56710. if (hasJustHovered)
  56711. {
  56712. hasJustHovered = false;
  56713. mouseMovedAfterHover();
  56714. }
  56715. }
  56716. void MouseHoverDetector::HoverDetectorInternal::timerCallback()
  56717. {
  56718. owner->hoverTimerCallback();
  56719. }
  56720. void MouseHoverDetector::HoverDetectorInternal::mouseEnter (const MouseEvent&)
  56721. {
  56722. stopTimer();
  56723. owner->checkJustHoveredCallback();
  56724. }
  56725. void MouseHoverDetector::HoverDetectorInternal::mouseExit (const MouseEvent&)
  56726. {
  56727. stopTimer();
  56728. owner->checkJustHoveredCallback();
  56729. }
  56730. void MouseHoverDetector::HoverDetectorInternal::mouseDown (const MouseEvent&)
  56731. {
  56732. stopTimer();
  56733. owner->checkJustHoveredCallback();
  56734. }
  56735. void MouseHoverDetector::HoverDetectorInternal::mouseUp (const MouseEvent&)
  56736. {
  56737. stopTimer();
  56738. owner->checkJustHoveredCallback();
  56739. }
  56740. void MouseHoverDetector::HoverDetectorInternal::mouseMove (const MouseEvent& e)
  56741. {
  56742. if (lastX != e.x || lastY != e.y) // to avoid fake mouse-moves setting it off
  56743. {
  56744. lastX = e.x;
  56745. lastY = e.y;
  56746. if (owner->source != 0)
  56747. startTimer (owner->hoverTimeMillisecs);
  56748. owner->checkJustHoveredCallback();
  56749. }
  56750. }
  56751. void MouseHoverDetector::HoverDetectorInternal::mouseWheelMove (const MouseEvent&, float, float)
  56752. {
  56753. stopTimer();
  56754. owner->checkJustHoveredCallback();
  56755. }
  56756. END_JUCE_NAMESPACE
  56757. /*** End of inlined file: juce_MouseHoverDetector.cpp ***/
  56758. /*** Start of inlined file: juce_MouseListener.cpp ***/
  56759. BEGIN_JUCE_NAMESPACE
  56760. void MouseListener::mouseEnter (const MouseEvent&)
  56761. {
  56762. }
  56763. void MouseListener::mouseExit (const MouseEvent&)
  56764. {
  56765. }
  56766. void MouseListener::mouseDown (const MouseEvent&)
  56767. {
  56768. }
  56769. void MouseListener::mouseUp (const MouseEvent&)
  56770. {
  56771. }
  56772. void MouseListener::mouseDrag (const MouseEvent&)
  56773. {
  56774. }
  56775. void MouseListener::mouseMove (const MouseEvent&)
  56776. {
  56777. }
  56778. void MouseListener::mouseDoubleClick (const MouseEvent&)
  56779. {
  56780. }
  56781. void MouseListener::mouseWheelMove (const MouseEvent&, float, float)
  56782. {
  56783. }
  56784. END_JUCE_NAMESPACE
  56785. /*** End of inlined file: juce_MouseListener.cpp ***/
  56786. /*** Start of inlined file: juce_BooleanPropertyComponent.cpp ***/
  56787. BEGIN_JUCE_NAMESPACE
  56788. BooleanPropertyComponent::BooleanPropertyComponent (const String& name,
  56789. const String& buttonTextWhenTrue,
  56790. const String& buttonTextWhenFalse)
  56791. : PropertyComponent (name),
  56792. onText (buttonTextWhenTrue),
  56793. offText (buttonTextWhenFalse)
  56794. {
  56795. createButton();
  56796. button->addButtonListener (this);
  56797. }
  56798. BooleanPropertyComponent::BooleanPropertyComponent (const Value& valueToControl,
  56799. const String& name,
  56800. const String& buttonText)
  56801. : PropertyComponent (name),
  56802. onText (buttonText),
  56803. offText (buttonText)
  56804. {
  56805. createButton();
  56806. button->setButtonText (buttonText);
  56807. button->getToggleStateValue().referTo (valueToControl);
  56808. button->setClickingTogglesState (true);
  56809. }
  56810. BooleanPropertyComponent::~BooleanPropertyComponent()
  56811. {
  56812. deleteAllChildren();
  56813. }
  56814. void BooleanPropertyComponent::createButton()
  56815. {
  56816. addAndMakeVisible (button = new ToggleButton (String::empty));
  56817. button->setClickingTogglesState (false);
  56818. }
  56819. void BooleanPropertyComponent::setState (const bool newState)
  56820. {
  56821. button->setToggleState (newState, true);
  56822. }
  56823. bool BooleanPropertyComponent::getState() const
  56824. {
  56825. return button->getToggleState();
  56826. }
  56827. void BooleanPropertyComponent::paint (Graphics& g)
  56828. {
  56829. PropertyComponent::paint (g);
  56830. const Rectangle<int> r (button->getBounds());
  56831. g.setColour (Colours::white);
  56832. g.fillRect (r);
  56833. g.setColour (findColour (ComboBox::outlineColourId));
  56834. g.drawRect (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  56835. }
  56836. void BooleanPropertyComponent::refresh()
  56837. {
  56838. button->setToggleState (getState(), false);
  56839. button->setButtonText (button->getToggleState() ? onText : offText);
  56840. }
  56841. void BooleanPropertyComponent::buttonClicked (Button*)
  56842. {
  56843. setState (! getState());
  56844. }
  56845. END_JUCE_NAMESPACE
  56846. /*** End of inlined file: juce_BooleanPropertyComponent.cpp ***/
  56847. /*** Start of inlined file: juce_ButtonPropertyComponent.cpp ***/
  56848. BEGIN_JUCE_NAMESPACE
  56849. ButtonPropertyComponent::ButtonPropertyComponent (const String& name,
  56850. const bool triggerOnMouseDown)
  56851. : PropertyComponent (name)
  56852. {
  56853. addAndMakeVisible (button = new TextButton (String::empty));
  56854. button->setTriggeredOnMouseDown (triggerOnMouseDown);
  56855. button->addButtonListener (this);
  56856. }
  56857. ButtonPropertyComponent::~ButtonPropertyComponent()
  56858. {
  56859. deleteAllChildren();
  56860. }
  56861. void ButtonPropertyComponent::refresh()
  56862. {
  56863. button->setButtonText (getButtonText());
  56864. }
  56865. void ButtonPropertyComponent::buttonClicked (Button*)
  56866. {
  56867. buttonClicked();
  56868. }
  56869. END_JUCE_NAMESPACE
  56870. /*** End of inlined file: juce_ButtonPropertyComponent.cpp ***/
  56871. /*** Start of inlined file: juce_ChoicePropertyComponent.cpp ***/
  56872. BEGIN_JUCE_NAMESPACE
  56873. ChoicePropertyComponent::ChoicePropertyComponent (const String& name)
  56874. : PropertyComponent (name),
  56875. comboBox (0)
  56876. {
  56877. }
  56878. ChoicePropertyComponent::ChoicePropertyComponent (const Value& valueToControl,
  56879. const String& name,
  56880. const StringArray& choices_,
  56881. const Array <int>* choiceIDs)
  56882. : PropertyComponent (name),
  56883. choices (choices_),
  56884. comboBox (0)
  56885. {
  56886. createComboBox (choiceIDs);
  56887. comboBox->getSelectedIdAsValue().referTo (valueToControl);
  56888. }
  56889. ChoicePropertyComponent::~ChoicePropertyComponent()
  56890. {
  56891. deleteAllChildren();
  56892. }
  56893. void ChoicePropertyComponent::createComboBox (const Array <int>* choiceIDs)
  56894. {
  56895. // The array of IDs must contain the same number of values as the choices list!
  56896. jassert (choiceIDs == 0 || choiceIDs->size() == choices.size());
  56897. addAndMakeVisible (comboBox = new ComboBox (String::empty));
  56898. for (int i = 0; i < choices.size(); ++i)
  56899. {
  56900. if (choices[i].isNotEmpty())
  56901. comboBox->addItem (choices[i], choiceIDs == 0 ? (i + 1)
  56902. : ((*choiceIDs)[i]));
  56903. else
  56904. comboBox->addSeparator();
  56905. }
  56906. comboBox->setEditableText (false);
  56907. }
  56908. void ChoicePropertyComponent::setIndex (const int newIndex)
  56909. {
  56910. comboBox->setSelectedId (comboBox->getItemId (newIndex));
  56911. }
  56912. int ChoicePropertyComponent::getIndex() const
  56913. {
  56914. return comboBox->getSelectedItemIndex();
  56915. }
  56916. const StringArray& ChoicePropertyComponent::getChoices() const
  56917. {
  56918. return choices;
  56919. }
  56920. void ChoicePropertyComponent::refresh()
  56921. {
  56922. if (comboBox == 0)
  56923. {
  56924. createComboBox (0);
  56925. comboBox->addListener (this);
  56926. }
  56927. comboBox->setSelectedId (getIndex() + 1, true);
  56928. }
  56929. void ChoicePropertyComponent::comboBoxChanged (ComboBox*)
  56930. {
  56931. const int newIndex = comboBox->getSelectedId() - 1;
  56932. if (newIndex != getIndex())
  56933. setIndex (newIndex);
  56934. }
  56935. END_JUCE_NAMESPACE
  56936. /*** End of inlined file: juce_ChoicePropertyComponent.cpp ***/
  56937. /*** Start of inlined file: juce_PropertyComponent.cpp ***/
  56938. BEGIN_JUCE_NAMESPACE
  56939. PropertyComponent::PropertyComponent (const String& name,
  56940. const int preferredHeight_)
  56941. : Component (name),
  56942. preferredHeight (preferredHeight_)
  56943. {
  56944. jassert (name.isNotEmpty());
  56945. }
  56946. PropertyComponent::~PropertyComponent()
  56947. {
  56948. }
  56949. void PropertyComponent::paint (Graphics& g)
  56950. {
  56951. getLookAndFeel().drawPropertyComponentBackground (g, getWidth(), getHeight(), *this);
  56952. getLookAndFeel().drawPropertyComponentLabel (g, getWidth(), getHeight(), *this);
  56953. }
  56954. void PropertyComponent::resized()
  56955. {
  56956. if (getNumChildComponents() > 0)
  56957. getChildComponent (0)->setBounds (getLookAndFeel().getPropertyComponentContentPosition (*this));
  56958. }
  56959. void PropertyComponent::enablementChanged()
  56960. {
  56961. repaint();
  56962. }
  56963. END_JUCE_NAMESPACE
  56964. /*** End of inlined file: juce_PropertyComponent.cpp ***/
  56965. /*** Start of inlined file: juce_PropertyPanel.cpp ***/
  56966. BEGIN_JUCE_NAMESPACE
  56967. class PropertyHolderComponent : public Component
  56968. {
  56969. public:
  56970. PropertyHolderComponent()
  56971. {
  56972. }
  56973. ~PropertyHolderComponent()
  56974. {
  56975. deleteAllChildren();
  56976. }
  56977. void paint (Graphics&)
  56978. {
  56979. }
  56980. void updateLayout (const int width);
  56981. void refreshAll() const;
  56982. };
  56983. class PropertySectionComponent : public Component
  56984. {
  56985. public:
  56986. PropertySectionComponent (const String& sectionTitle,
  56987. const Array <PropertyComponent*>& newProperties,
  56988. const bool open)
  56989. : Component (sectionTitle),
  56990. titleHeight (sectionTitle.isNotEmpty() ? 22 : 0),
  56991. isOpen_ (open)
  56992. {
  56993. for (int i = newProperties.size(); --i >= 0;)
  56994. {
  56995. addAndMakeVisible (newProperties.getUnchecked(i));
  56996. newProperties.getUnchecked(i)->refresh();
  56997. }
  56998. }
  56999. ~PropertySectionComponent()
  57000. {
  57001. deleteAllChildren();
  57002. }
  57003. void paint (Graphics& g)
  57004. {
  57005. if (titleHeight > 0)
  57006. getLookAndFeel().drawPropertyPanelSectionHeader (g, getName(), isOpen(), getWidth(), titleHeight);
  57007. }
  57008. void resized()
  57009. {
  57010. int y = titleHeight;
  57011. for (int i = getNumChildComponents(); --i >= 0;)
  57012. {
  57013. PropertyComponent* const pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57014. if (pec != 0)
  57015. {
  57016. const int prefH = pec->getPreferredHeight();
  57017. pec->setBounds (1, y, getWidth() - 2, prefH);
  57018. y += prefH;
  57019. }
  57020. }
  57021. }
  57022. int getPreferredHeight() const
  57023. {
  57024. int y = titleHeight;
  57025. if (isOpen())
  57026. {
  57027. for (int i = 0; i < getNumChildComponents(); ++i)
  57028. {
  57029. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57030. if (pec != 0)
  57031. y += pec->getPreferredHeight();
  57032. }
  57033. }
  57034. return y;
  57035. }
  57036. void setOpen (const bool open)
  57037. {
  57038. if (isOpen_ != open)
  57039. {
  57040. isOpen_ = open;
  57041. for (int i = 0; i < getNumChildComponents(); ++i)
  57042. {
  57043. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57044. if (pec != 0)
  57045. pec->setVisible (open);
  57046. }
  57047. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  57048. PropertyPanel* const pp = findParentComponentOfClass ((PropertyPanel*) 0);
  57049. if (pp != 0)
  57050. pp->resized();
  57051. }
  57052. }
  57053. bool isOpen() const
  57054. {
  57055. return isOpen_;
  57056. }
  57057. void refreshAll() const
  57058. {
  57059. for (int i = 0; i < getNumChildComponents(); ++i)
  57060. {
  57061. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57062. if (pec != 0)
  57063. pec->refresh();
  57064. }
  57065. }
  57066. void mouseDown (const MouseEvent&)
  57067. {
  57068. }
  57069. void mouseUp (const MouseEvent& e)
  57070. {
  57071. if (e.getMouseDownX() < titleHeight
  57072. && e.x < titleHeight
  57073. && e.y < titleHeight
  57074. && e.getNumberOfClicks() != 2)
  57075. {
  57076. setOpen (! isOpen());
  57077. }
  57078. }
  57079. void mouseDoubleClick (const MouseEvent& e)
  57080. {
  57081. if (e.y < titleHeight)
  57082. setOpen (! isOpen());
  57083. }
  57084. private:
  57085. int titleHeight;
  57086. bool isOpen_;
  57087. };
  57088. void PropertyHolderComponent::updateLayout (const int width)
  57089. {
  57090. int y = 0;
  57091. for (int i = getNumChildComponents(); --i >= 0;)
  57092. {
  57093. PropertySectionComponent* const section
  57094. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57095. if (section != 0)
  57096. {
  57097. const int prefH = section->getPreferredHeight();
  57098. section->setBounds (0, y, width, prefH);
  57099. y += prefH;
  57100. }
  57101. }
  57102. setSize (width, y);
  57103. repaint();
  57104. }
  57105. void PropertyHolderComponent::refreshAll() const
  57106. {
  57107. for (int i = getNumChildComponents(); --i >= 0;)
  57108. {
  57109. PropertySectionComponent* const section
  57110. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57111. if (section != 0)
  57112. section->refreshAll();
  57113. }
  57114. }
  57115. PropertyPanel::PropertyPanel()
  57116. {
  57117. messageWhenEmpty = TRANS("(nothing selected)");
  57118. addAndMakeVisible (viewport = new Viewport());
  57119. viewport->setViewedComponent (propertyHolderComponent = new PropertyHolderComponent());
  57120. viewport->setFocusContainer (true);
  57121. }
  57122. PropertyPanel::~PropertyPanel()
  57123. {
  57124. clear();
  57125. deleteAllChildren();
  57126. }
  57127. void PropertyPanel::paint (Graphics& g)
  57128. {
  57129. if (propertyHolderComponent->getNumChildComponents() == 0)
  57130. {
  57131. g.setColour (Colours::black.withAlpha (0.5f));
  57132. g.setFont (14.0f);
  57133. g.drawText (messageWhenEmpty, 0, 0, getWidth(), 30,
  57134. Justification::centred, true);
  57135. }
  57136. }
  57137. void PropertyPanel::resized()
  57138. {
  57139. viewport->setBounds (0, 0, getWidth(), getHeight());
  57140. updatePropHolderLayout();
  57141. }
  57142. void PropertyPanel::clear()
  57143. {
  57144. if (propertyHolderComponent->getNumChildComponents() > 0)
  57145. {
  57146. propertyHolderComponent->deleteAllChildren();
  57147. repaint();
  57148. }
  57149. }
  57150. void PropertyPanel::addProperties (const Array <PropertyComponent*>& newProperties)
  57151. {
  57152. if (propertyHolderComponent->getNumChildComponents() == 0)
  57153. repaint();
  57154. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (String::empty,
  57155. newProperties,
  57156. true), 0);
  57157. updatePropHolderLayout();
  57158. }
  57159. void PropertyPanel::addSection (const String& sectionTitle,
  57160. const Array <PropertyComponent*>& newProperties,
  57161. const bool shouldBeOpen)
  57162. {
  57163. jassert (sectionTitle.isNotEmpty());
  57164. if (propertyHolderComponent->getNumChildComponents() == 0)
  57165. repaint();
  57166. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (sectionTitle,
  57167. newProperties,
  57168. shouldBeOpen), 0);
  57169. updatePropHolderLayout();
  57170. }
  57171. void PropertyPanel::updatePropHolderLayout() const
  57172. {
  57173. const int maxWidth = viewport->getMaximumVisibleWidth();
  57174. ((PropertyHolderComponent*) propertyHolderComponent)->updateLayout (maxWidth);
  57175. const int newMaxWidth = viewport->getMaximumVisibleWidth();
  57176. if (maxWidth != newMaxWidth)
  57177. {
  57178. // need to do this twice because of scrollbars changing the size, etc.
  57179. ((PropertyHolderComponent*) propertyHolderComponent)->updateLayout (newMaxWidth);
  57180. }
  57181. }
  57182. void PropertyPanel::refreshAll() const
  57183. {
  57184. ((PropertyHolderComponent*) propertyHolderComponent)->refreshAll();
  57185. }
  57186. const StringArray PropertyPanel::getSectionNames() const
  57187. {
  57188. StringArray s;
  57189. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57190. {
  57191. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57192. if (section != 0 && section->getName().isNotEmpty())
  57193. s.add (section->getName());
  57194. }
  57195. return s;
  57196. }
  57197. bool PropertyPanel::isSectionOpen (const int sectionIndex) const
  57198. {
  57199. int index = 0;
  57200. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57201. {
  57202. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57203. if (section != 0 && section->getName().isNotEmpty())
  57204. {
  57205. if (index == sectionIndex)
  57206. return section->isOpen();
  57207. ++index;
  57208. }
  57209. }
  57210. return false;
  57211. }
  57212. void PropertyPanel::setSectionOpen (const int sectionIndex, const bool shouldBeOpen)
  57213. {
  57214. int index = 0;
  57215. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57216. {
  57217. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57218. if (section != 0 && section->getName().isNotEmpty())
  57219. {
  57220. if (index == sectionIndex)
  57221. {
  57222. section->setOpen (shouldBeOpen);
  57223. break;
  57224. }
  57225. ++index;
  57226. }
  57227. }
  57228. }
  57229. void PropertyPanel::setSectionEnabled (const int sectionIndex, const bool shouldBeEnabled)
  57230. {
  57231. int index = 0;
  57232. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57233. {
  57234. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57235. if (section != 0 && section->getName().isNotEmpty())
  57236. {
  57237. if (index == sectionIndex)
  57238. {
  57239. section->setEnabled (shouldBeEnabled);
  57240. break;
  57241. }
  57242. ++index;
  57243. }
  57244. }
  57245. }
  57246. XmlElement* PropertyPanel::getOpennessState() const
  57247. {
  57248. XmlElement* const xml = new XmlElement ("PROPERTYPANELSTATE");
  57249. xml->setAttribute ("scrollPos", viewport->getViewPositionY());
  57250. const StringArray sections (getSectionNames());
  57251. for (int i = 0; i < sections.size(); ++i)
  57252. {
  57253. if (sections[i].isNotEmpty())
  57254. {
  57255. XmlElement* const e = xml->createNewChildElement ("SECTION");
  57256. e->setAttribute ("name", sections[i]);
  57257. e->setAttribute ("open", isSectionOpen (i) ? 1 : 0);
  57258. }
  57259. }
  57260. return xml;
  57261. }
  57262. void PropertyPanel::restoreOpennessState (const XmlElement& xml)
  57263. {
  57264. if (xml.hasTagName ("PROPERTYPANELSTATE"))
  57265. {
  57266. const StringArray sections (getSectionNames());
  57267. forEachXmlChildElementWithTagName (xml, e, "SECTION")
  57268. {
  57269. setSectionOpen (sections.indexOf (e->getStringAttribute ("name")),
  57270. e->getBoolAttribute ("open"));
  57271. }
  57272. viewport->setViewPosition (viewport->getViewPositionX(),
  57273. xml.getIntAttribute ("scrollPos", viewport->getViewPositionY()));
  57274. }
  57275. }
  57276. void PropertyPanel::setMessageWhenEmpty (const String& newMessage)
  57277. {
  57278. if (messageWhenEmpty != newMessage)
  57279. {
  57280. messageWhenEmpty = newMessage;
  57281. repaint();
  57282. }
  57283. }
  57284. const String& PropertyPanel::getMessageWhenEmpty() const
  57285. {
  57286. return messageWhenEmpty;
  57287. }
  57288. END_JUCE_NAMESPACE
  57289. /*** End of inlined file: juce_PropertyPanel.cpp ***/
  57290. /*** Start of inlined file: juce_SliderPropertyComponent.cpp ***/
  57291. BEGIN_JUCE_NAMESPACE
  57292. SliderPropertyComponent::SliderPropertyComponent (const String& name,
  57293. const double rangeMin,
  57294. const double rangeMax,
  57295. const double interval,
  57296. const double skewFactor)
  57297. : PropertyComponent (name)
  57298. {
  57299. addAndMakeVisible (slider = new Slider (name));
  57300. slider->setRange (rangeMin, rangeMax, interval);
  57301. slider->setSkewFactor (skewFactor);
  57302. slider->setSliderStyle (Slider::LinearBar);
  57303. slider->addListener (this);
  57304. }
  57305. SliderPropertyComponent::SliderPropertyComponent (Value& valueToControl,
  57306. const String& name,
  57307. const double rangeMin,
  57308. const double rangeMax,
  57309. const double interval,
  57310. const double skewFactor)
  57311. : PropertyComponent (name)
  57312. {
  57313. addAndMakeVisible (slider = new Slider (name));
  57314. slider->setRange (rangeMin, rangeMax, interval);
  57315. slider->setSkewFactor (skewFactor);
  57316. slider->setSliderStyle (Slider::LinearBar);
  57317. slider->getValueObject().referTo (valueToControl);
  57318. }
  57319. SliderPropertyComponent::~SliderPropertyComponent()
  57320. {
  57321. deleteAllChildren();
  57322. }
  57323. void SliderPropertyComponent::setValue (const double /*newValue*/)
  57324. {
  57325. }
  57326. double SliderPropertyComponent::getValue() const
  57327. {
  57328. return slider->getValue();
  57329. }
  57330. void SliderPropertyComponent::refresh()
  57331. {
  57332. slider->setValue (getValue(), false);
  57333. }
  57334. void SliderPropertyComponent::sliderValueChanged (Slider*)
  57335. {
  57336. if (getValue() != slider->getValue())
  57337. setValue (slider->getValue());
  57338. }
  57339. END_JUCE_NAMESPACE
  57340. /*** End of inlined file: juce_SliderPropertyComponent.cpp ***/
  57341. /*** Start of inlined file: juce_TextPropertyComponent.cpp ***/
  57342. BEGIN_JUCE_NAMESPACE
  57343. class TextPropLabel : public Label
  57344. {
  57345. TextPropertyComponent& owner;
  57346. int maxChars;
  57347. bool isMultiline;
  57348. public:
  57349. TextPropLabel (TextPropertyComponent& owner_,
  57350. const int maxChars_, const bool isMultiline_)
  57351. : Label (String::empty, String::empty),
  57352. owner (owner_),
  57353. maxChars (maxChars_),
  57354. isMultiline (isMultiline_)
  57355. {
  57356. setEditable (true, true, false);
  57357. setColour (backgroundColourId, Colours::white);
  57358. setColour (outlineColourId, findColour (ComboBox::outlineColourId));
  57359. }
  57360. ~TextPropLabel()
  57361. {
  57362. }
  57363. TextEditor* createEditorComponent()
  57364. {
  57365. TextEditor* const textEditor = Label::createEditorComponent();
  57366. textEditor->setInputRestrictions (maxChars);
  57367. if (isMultiline)
  57368. {
  57369. textEditor->setMultiLine (true, true);
  57370. textEditor->setReturnKeyStartsNewLine (true);
  57371. }
  57372. return textEditor;
  57373. }
  57374. void textWasEdited()
  57375. {
  57376. owner.textWasEdited();
  57377. }
  57378. };
  57379. TextPropertyComponent::TextPropertyComponent (const String& name,
  57380. const int maxNumChars,
  57381. const bool isMultiLine)
  57382. : PropertyComponent (name)
  57383. {
  57384. createEditor (maxNumChars, isMultiLine);
  57385. }
  57386. TextPropertyComponent::TextPropertyComponent (const Value& valueToControl,
  57387. const String& name,
  57388. const int maxNumChars,
  57389. const bool isMultiLine)
  57390. : PropertyComponent (name)
  57391. {
  57392. createEditor (maxNumChars, isMultiLine);
  57393. textEditor->getTextValue().referTo (valueToControl);
  57394. }
  57395. TextPropertyComponent::~TextPropertyComponent()
  57396. {
  57397. deleteAllChildren();
  57398. }
  57399. void TextPropertyComponent::setText (const String& newText)
  57400. {
  57401. textEditor->setText (newText, true);
  57402. }
  57403. const String TextPropertyComponent::getText() const
  57404. {
  57405. return textEditor->getText();
  57406. }
  57407. void TextPropertyComponent::createEditor (const int maxNumChars, const bool isMultiLine)
  57408. {
  57409. addAndMakeVisible (textEditor = new TextPropLabel (*this, maxNumChars, isMultiLine));
  57410. if (isMultiLine)
  57411. {
  57412. textEditor->setJustificationType (Justification::topLeft);
  57413. preferredHeight = 120;
  57414. }
  57415. }
  57416. void TextPropertyComponent::refresh()
  57417. {
  57418. textEditor->setText (getText(), false);
  57419. }
  57420. void TextPropertyComponent::textWasEdited()
  57421. {
  57422. const String newText (textEditor->getText());
  57423. if (getText() != newText)
  57424. setText (newText);
  57425. }
  57426. END_JUCE_NAMESPACE
  57427. /*** End of inlined file: juce_TextPropertyComponent.cpp ***/
  57428. /*** Start of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  57429. BEGIN_JUCE_NAMESPACE
  57430. class SimpleDeviceManagerInputLevelMeter : public Component,
  57431. public Timer
  57432. {
  57433. public:
  57434. SimpleDeviceManagerInputLevelMeter (AudioDeviceManager* const manager_)
  57435. : manager (manager_),
  57436. level (0)
  57437. {
  57438. startTimer (50);
  57439. manager->enableInputLevelMeasurement (true);
  57440. }
  57441. ~SimpleDeviceManagerInputLevelMeter()
  57442. {
  57443. manager->enableInputLevelMeasurement (false);
  57444. }
  57445. void timerCallback()
  57446. {
  57447. const float newLevel = (float) manager->getCurrentInputLevel();
  57448. if (fabsf (level - newLevel) > 0.005f)
  57449. {
  57450. level = newLevel;
  57451. repaint();
  57452. }
  57453. }
  57454. void paint (Graphics& g)
  57455. {
  57456. getLookAndFeel().drawLevelMeter (g, getWidth(), getHeight(),
  57457. (float) exp (log (level) / 3.0)); // (add a bit of a skew to make the level more obvious)
  57458. }
  57459. private:
  57460. AudioDeviceManager* const manager;
  57461. float level;
  57462. SimpleDeviceManagerInputLevelMeter (const SimpleDeviceManagerInputLevelMeter&);
  57463. SimpleDeviceManagerInputLevelMeter& operator= (const SimpleDeviceManagerInputLevelMeter&);
  57464. };
  57465. class MidiInputSelectorComponentListBox : public ListBox,
  57466. public ListBoxModel
  57467. {
  57468. public:
  57469. MidiInputSelectorComponentListBox (AudioDeviceManager& deviceManager_,
  57470. const String& noItemsMessage_,
  57471. const int minNumber_,
  57472. const int maxNumber_)
  57473. : ListBox (String::empty, 0),
  57474. deviceManager (deviceManager_),
  57475. noItemsMessage (noItemsMessage_),
  57476. minNumber (minNumber_),
  57477. maxNumber (maxNumber_)
  57478. {
  57479. items = MidiInput::getDevices();
  57480. setModel (this);
  57481. setOutlineThickness (1);
  57482. }
  57483. ~MidiInputSelectorComponentListBox()
  57484. {
  57485. }
  57486. int getNumRows()
  57487. {
  57488. return items.size();
  57489. }
  57490. void paintListBoxItem (int row,
  57491. Graphics& g,
  57492. int width, int height,
  57493. bool rowIsSelected)
  57494. {
  57495. if (((unsigned int) row) < (unsigned int) items.size())
  57496. {
  57497. if (rowIsSelected)
  57498. g.fillAll (findColour (TextEditor::highlightColourId)
  57499. .withMultipliedAlpha (0.3f));
  57500. const String item (items [row]);
  57501. bool enabled = deviceManager.isMidiInputEnabled (item);
  57502. const int x = getTickX();
  57503. const float tickW = height * 0.75f;
  57504. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  57505. enabled, true, true, false);
  57506. g.setFont (height * 0.6f);
  57507. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  57508. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  57509. }
  57510. }
  57511. void listBoxItemClicked (int row, const MouseEvent& e)
  57512. {
  57513. selectRow (row);
  57514. if (e.x < getTickX())
  57515. flipEnablement (row);
  57516. }
  57517. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  57518. {
  57519. flipEnablement (row);
  57520. }
  57521. void returnKeyPressed (int row)
  57522. {
  57523. flipEnablement (row);
  57524. }
  57525. void paint (Graphics& g)
  57526. {
  57527. ListBox::paint (g);
  57528. if (items.size() == 0)
  57529. {
  57530. g.setColour (Colours::grey);
  57531. g.setFont (13.0f);
  57532. g.drawText (noItemsMessage,
  57533. 0, 0, getWidth(), getHeight() / 2,
  57534. Justification::centred, true);
  57535. }
  57536. }
  57537. int getBestHeight (const int preferredHeight)
  57538. {
  57539. const int extra = getOutlineThickness() * 2;
  57540. return jmax (getRowHeight() * 2 + extra,
  57541. jmin (getRowHeight() * getNumRows() + extra,
  57542. preferredHeight));
  57543. }
  57544. juce_UseDebuggingNewOperator
  57545. private:
  57546. AudioDeviceManager& deviceManager;
  57547. const String noItemsMessage;
  57548. StringArray items;
  57549. int minNumber, maxNumber;
  57550. void flipEnablement (const int row)
  57551. {
  57552. if (((unsigned int) row) < (unsigned int) items.size())
  57553. {
  57554. const String item (items [row]);
  57555. deviceManager.setMidiInputEnabled (item, ! deviceManager.isMidiInputEnabled (item));
  57556. }
  57557. }
  57558. int getTickX() const
  57559. {
  57560. return getRowHeight() + 5;
  57561. }
  57562. MidiInputSelectorComponentListBox (const MidiInputSelectorComponentListBox&);
  57563. MidiInputSelectorComponentListBox& operator= (const MidiInputSelectorComponentListBox&);
  57564. };
  57565. class AudioDeviceSettingsPanel : public Component,
  57566. public ComboBoxListener,
  57567. public ChangeListener,
  57568. public ButtonListener
  57569. {
  57570. public:
  57571. AudioDeviceSettingsPanel (AudioIODeviceType* type_,
  57572. AudioIODeviceType::DeviceSetupDetails& setup_,
  57573. const bool hideAdvancedOptionsWithButton)
  57574. : type (type_),
  57575. setup (setup_)
  57576. {
  57577. sampleRateDropDown = 0;
  57578. sampleRateLabel = 0;
  57579. bufferSizeDropDown = 0;
  57580. bufferSizeLabel = 0;
  57581. outputDeviceDropDown = 0;
  57582. outputDeviceLabel = 0;
  57583. inputDeviceDropDown = 0;
  57584. inputDeviceLabel = 0;
  57585. testButton = 0;
  57586. inputLevelMeter = 0;
  57587. showUIButton = 0;
  57588. inputChanList = 0;
  57589. outputChanList = 0;
  57590. inputChanLabel = 0;
  57591. outputChanLabel = 0;
  57592. showAdvancedSettingsButton = 0;
  57593. if (hideAdvancedOptionsWithButton)
  57594. {
  57595. addAndMakeVisible (showAdvancedSettingsButton = new TextButton (TRANS("Show advanced settings...")));
  57596. showAdvancedSettingsButton->addButtonListener (this);
  57597. }
  57598. type->scanForDevices();
  57599. setup.manager->addChangeListener (this);
  57600. changeListenerCallback (0);
  57601. }
  57602. ~AudioDeviceSettingsPanel()
  57603. {
  57604. setup.manager->removeChangeListener (this);
  57605. deleteAndZero (outputDeviceLabel);
  57606. deleteAndZero (inputDeviceLabel);
  57607. deleteAndZero (sampleRateLabel);
  57608. deleteAndZero (bufferSizeLabel);
  57609. deleteAndZero (showUIButton);
  57610. deleteAndZero (inputChanLabel);
  57611. deleteAndZero (outputChanLabel);
  57612. deleteAndZero (showAdvancedSettingsButton);
  57613. deleteAllChildren();
  57614. }
  57615. void resized()
  57616. {
  57617. const int lx = proportionOfWidth (0.35f);
  57618. const int w = proportionOfWidth (0.4f);
  57619. const int h = 24;
  57620. const int space = 6;
  57621. const int dh = h + space;
  57622. int y = 0;
  57623. if (outputDeviceDropDown != 0)
  57624. {
  57625. outputDeviceDropDown->setBounds (lx, y, w, h);
  57626. if (testButton != 0)
  57627. testButton->setBounds (proportionOfWidth (0.77f),
  57628. outputDeviceDropDown->getY(),
  57629. proportionOfWidth (0.18f),
  57630. h);
  57631. y += dh;
  57632. }
  57633. if (inputDeviceDropDown != 0)
  57634. {
  57635. inputDeviceDropDown->setBounds (lx, y, w, h);
  57636. inputLevelMeter->setBounds (proportionOfWidth (0.77f),
  57637. inputDeviceDropDown->getY(),
  57638. proportionOfWidth (0.18f),
  57639. h);
  57640. y += dh;
  57641. }
  57642. const int maxBoxHeight = 100;//(getHeight() - y - dh * 2) / numBoxes;
  57643. if (outputChanList != 0)
  57644. {
  57645. const int bh = outputChanList->getBestHeight (maxBoxHeight);
  57646. outputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  57647. y += bh + space;
  57648. }
  57649. if (inputChanList != 0)
  57650. {
  57651. const int bh = inputChanList->getBestHeight (maxBoxHeight);
  57652. inputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  57653. y += bh + space;
  57654. }
  57655. y += space * 2;
  57656. if (showAdvancedSettingsButton != 0)
  57657. {
  57658. showAdvancedSettingsButton->changeWidthToFitText (h);
  57659. showAdvancedSettingsButton->setTopLeftPosition (lx, y);
  57660. }
  57661. if (sampleRateDropDown != 0)
  57662. {
  57663. sampleRateDropDown->setVisible (showAdvancedSettingsButton == 0
  57664. || ! showAdvancedSettingsButton->isVisible());
  57665. sampleRateDropDown->setBounds (lx, y, w, h);
  57666. y += dh;
  57667. }
  57668. if (bufferSizeDropDown != 0)
  57669. {
  57670. bufferSizeDropDown->setVisible (showAdvancedSettingsButton == 0
  57671. || ! showAdvancedSettingsButton->isVisible());
  57672. bufferSizeDropDown->setBounds (lx, y, w, h);
  57673. y += dh;
  57674. }
  57675. if (showUIButton != 0)
  57676. {
  57677. showUIButton->setVisible (showAdvancedSettingsButton == 0
  57678. || ! showAdvancedSettingsButton->isVisible());
  57679. showUIButton->changeWidthToFitText (h);
  57680. showUIButton->setTopLeftPosition (lx, y);
  57681. }
  57682. }
  57683. void comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  57684. {
  57685. if (comboBoxThatHasChanged == 0)
  57686. return;
  57687. AudioDeviceManager::AudioDeviceSetup config;
  57688. setup.manager->getAudioDeviceSetup (config);
  57689. String error;
  57690. if (comboBoxThatHasChanged == outputDeviceDropDown
  57691. || comboBoxThatHasChanged == inputDeviceDropDown)
  57692. {
  57693. if (outputDeviceDropDown != 0)
  57694. config.outputDeviceName = outputDeviceDropDown->getSelectedId() < 0 ? String::empty
  57695. : outputDeviceDropDown->getText();
  57696. if (inputDeviceDropDown != 0)
  57697. config.inputDeviceName = inputDeviceDropDown->getSelectedId() < 0 ? String::empty
  57698. : inputDeviceDropDown->getText();
  57699. if (! type->hasSeparateInputsAndOutputs())
  57700. config.inputDeviceName = config.outputDeviceName;
  57701. if (comboBoxThatHasChanged == inputDeviceDropDown)
  57702. config.useDefaultInputChannels = true;
  57703. else
  57704. config.useDefaultOutputChannels = true;
  57705. error = setup.manager->setAudioDeviceSetup (config, true);
  57706. showCorrectDeviceName (inputDeviceDropDown, true);
  57707. showCorrectDeviceName (outputDeviceDropDown, false);
  57708. updateControlPanelButton();
  57709. resized();
  57710. }
  57711. else if (comboBoxThatHasChanged == sampleRateDropDown)
  57712. {
  57713. if (sampleRateDropDown->getSelectedId() > 0)
  57714. {
  57715. config.sampleRate = sampleRateDropDown->getSelectedId();
  57716. error = setup.manager->setAudioDeviceSetup (config, true);
  57717. }
  57718. }
  57719. else if (comboBoxThatHasChanged == bufferSizeDropDown)
  57720. {
  57721. if (bufferSizeDropDown->getSelectedId() > 0)
  57722. {
  57723. config.bufferSize = bufferSizeDropDown->getSelectedId();
  57724. error = setup.manager->setAudioDeviceSetup (config, true);
  57725. }
  57726. }
  57727. if (error.isNotEmpty())
  57728. {
  57729. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  57730. "Error when trying to open audio device!",
  57731. error);
  57732. }
  57733. }
  57734. void buttonClicked (Button* button)
  57735. {
  57736. if (button == showAdvancedSettingsButton)
  57737. {
  57738. showAdvancedSettingsButton->setVisible (false);
  57739. resized();
  57740. }
  57741. else if (button == showUIButton)
  57742. {
  57743. AudioIODevice* const device = setup.manager->getCurrentAudioDevice();
  57744. if (device != 0 && device->showControlPanel())
  57745. {
  57746. setup.manager->closeAudioDevice();
  57747. setup.manager->restartLastAudioDevice();
  57748. getTopLevelComponent()->toFront (true);
  57749. }
  57750. }
  57751. else if (button == testButton && testButton != 0)
  57752. {
  57753. setup.manager->playTestSound();
  57754. }
  57755. }
  57756. void updateControlPanelButton()
  57757. {
  57758. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  57759. deleteAndZero (showUIButton);
  57760. if (currentDevice != 0 && currentDevice->hasControlPanel())
  57761. {
  57762. addAndMakeVisible (showUIButton = new TextButton (TRANS ("show this device's control panel"),
  57763. TRANS ("opens the device's own control panel")));
  57764. showUIButton->addButtonListener (this);
  57765. }
  57766. resized();
  57767. }
  57768. void changeListenerCallback (void*)
  57769. {
  57770. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  57771. if (setup.maxNumOutputChannels > 0 || ! type->hasSeparateInputsAndOutputs())
  57772. {
  57773. if (outputDeviceDropDown == 0)
  57774. {
  57775. outputDeviceDropDown = new ComboBox (String::empty);
  57776. outputDeviceDropDown->addListener (this);
  57777. addAndMakeVisible (outputDeviceDropDown);
  57778. outputDeviceLabel = new Label (String::empty,
  57779. type->hasSeparateInputsAndOutputs() ? TRANS ("output:")
  57780. : TRANS ("device:"));
  57781. outputDeviceLabel->attachToComponent (outputDeviceDropDown, true);
  57782. if (setup.maxNumOutputChannels > 0)
  57783. {
  57784. addAndMakeVisible (testButton = new TextButton (TRANS ("Test")));
  57785. testButton->addButtonListener (this);
  57786. }
  57787. }
  57788. addNamesToDeviceBox (*outputDeviceDropDown, false);
  57789. }
  57790. if (setup.maxNumInputChannels > 0 && type->hasSeparateInputsAndOutputs())
  57791. {
  57792. if (inputDeviceDropDown == 0)
  57793. {
  57794. inputDeviceDropDown = new ComboBox (String::empty);
  57795. inputDeviceDropDown->addListener (this);
  57796. addAndMakeVisible (inputDeviceDropDown);
  57797. inputDeviceLabel = new Label (String::empty, TRANS ("input:"));
  57798. inputDeviceLabel->attachToComponent (inputDeviceDropDown, true);
  57799. addAndMakeVisible (inputLevelMeter
  57800. = new SimpleDeviceManagerInputLevelMeter (setup.manager));
  57801. }
  57802. addNamesToDeviceBox (*inputDeviceDropDown, true);
  57803. }
  57804. updateControlPanelButton();
  57805. showCorrectDeviceName (inputDeviceDropDown, true);
  57806. showCorrectDeviceName (outputDeviceDropDown, false);
  57807. if (currentDevice != 0)
  57808. {
  57809. if (setup.maxNumOutputChannels > 0
  57810. && setup.minNumOutputChannels < setup.manager->getCurrentAudioDevice()->getOutputChannelNames().size())
  57811. {
  57812. if (outputChanList == 0)
  57813. {
  57814. addAndMakeVisible (outputChanList
  57815. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioOutputType,
  57816. TRANS ("(no audio output channels found)")));
  57817. outputChanLabel = new Label (String::empty, TRANS ("active output channels:"));
  57818. outputChanLabel->attachToComponent (outputChanList, true);
  57819. }
  57820. outputChanList->refresh();
  57821. }
  57822. else
  57823. {
  57824. deleteAndZero (outputChanLabel);
  57825. deleteAndZero (outputChanList);
  57826. }
  57827. if (setup.maxNumInputChannels > 0
  57828. && setup.minNumInputChannels < setup.manager->getCurrentAudioDevice()->getInputChannelNames().size())
  57829. {
  57830. if (inputChanList == 0)
  57831. {
  57832. addAndMakeVisible (inputChanList
  57833. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioInputType,
  57834. TRANS ("(no audio input channels found)")));
  57835. inputChanLabel = new Label (String::empty, TRANS ("active input channels:"));
  57836. inputChanLabel->attachToComponent (inputChanList, true);
  57837. }
  57838. inputChanList->refresh();
  57839. }
  57840. else
  57841. {
  57842. deleteAndZero (inputChanLabel);
  57843. deleteAndZero (inputChanList);
  57844. }
  57845. // sample rate..
  57846. {
  57847. if (sampleRateDropDown == 0)
  57848. {
  57849. addAndMakeVisible (sampleRateDropDown = new ComboBox (String::empty));
  57850. sampleRateDropDown->addListener (this);
  57851. delete sampleRateLabel;
  57852. sampleRateLabel = new Label (String::empty, TRANS ("sample rate:"));
  57853. sampleRateLabel->attachToComponent (sampleRateDropDown, true);
  57854. }
  57855. else
  57856. {
  57857. sampleRateDropDown->clear();
  57858. sampleRateDropDown->removeListener (this);
  57859. }
  57860. const int numRates = currentDevice->getNumSampleRates();
  57861. for (int i = 0; i < numRates; ++i)
  57862. {
  57863. const int rate = roundToInt (currentDevice->getSampleRate (i));
  57864. sampleRateDropDown->addItem (String (rate) + " Hz", rate);
  57865. }
  57866. sampleRateDropDown->setSelectedId (roundToInt (currentDevice->getCurrentSampleRate()), true);
  57867. sampleRateDropDown->addListener (this);
  57868. }
  57869. // buffer size
  57870. {
  57871. if (bufferSizeDropDown == 0)
  57872. {
  57873. addAndMakeVisible (bufferSizeDropDown = new ComboBox (String::empty));
  57874. bufferSizeDropDown->addListener (this);
  57875. delete bufferSizeLabel;
  57876. bufferSizeLabel = new Label (String::empty, TRANS ("audio buffer size:"));
  57877. bufferSizeLabel->attachToComponent (bufferSizeDropDown, true);
  57878. }
  57879. else
  57880. {
  57881. bufferSizeDropDown->clear();
  57882. }
  57883. const int numBufferSizes = currentDevice->getNumBufferSizesAvailable();
  57884. double currentRate = currentDevice->getCurrentSampleRate();
  57885. if (currentRate == 0)
  57886. currentRate = 48000.0;
  57887. for (int i = 0; i < numBufferSizes; ++i)
  57888. {
  57889. const int bs = currentDevice->getBufferSizeSamples (i);
  57890. bufferSizeDropDown->addItem (String (bs)
  57891. + " samples ("
  57892. + String (bs * 1000.0 / currentRate, 1)
  57893. + " ms)",
  57894. bs);
  57895. }
  57896. bufferSizeDropDown->setSelectedId (currentDevice->getCurrentBufferSizeSamples(), true);
  57897. }
  57898. }
  57899. else
  57900. {
  57901. jassert (setup.manager->getCurrentAudioDevice() == 0); // not the correct device type!
  57902. deleteAndZero (sampleRateLabel);
  57903. deleteAndZero (bufferSizeLabel);
  57904. deleteAndZero (sampleRateDropDown);
  57905. deleteAndZero (bufferSizeDropDown);
  57906. if (outputDeviceDropDown != 0)
  57907. outputDeviceDropDown->setSelectedId (-1, true);
  57908. if (inputDeviceDropDown != 0)
  57909. inputDeviceDropDown->setSelectedId (-1, true);
  57910. }
  57911. resized();
  57912. setSize (getWidth(), getLowestY() + 4);
  57913. }
  57914. private:
  57915. AudioIODeviceType* const type;
  57916. const AudioIODeviceType::DeviceSetupDetails setup;
  57917. ComboBox* outputDeviceDropDown;
  57918. ComboBox* inputDeviceDropDown;
  57919. ComboBox* sampleRateDropDown;
  57920. ComboBox* bufferSizeDropDown;
  57921. Label* outputDeviceLabel;
  57922. Label* inputDeviceLabel;
  57923. Label* sampleRateLabel;
  57924. Label* bufferSizeLabel;
  57925. Label* inputChanLabel;
  57926. Label* outputChanLabel;
  57927. TextButton* testButton;
  57928. Component* inputLevelMeter;
  57929. TextButton* showUIButton;
  57930. TextButton* showAdvancedSettingsButton;
  57931. void showCorrectDeviceName (ComboBox* const box, const bool isInput)
  57932. {
  57933. if (box != 0)
  57934. {
  57935. AudioIODevice* const currentDevice = dynamic_cast <AudioIODevice*> (setup.manager->getCurrentAudioDevice());
  57936. const int index = type->getIndexOfDevice (currentDevice, isInput);
  57937. box->setSelectedId (index + 1, true);
  57938. if (testButton != 0 && ! isInput)
  57939. testButton->setEnabled (index >= 0);
  57940. }
  57941. }
  57942. void addNamesToDeviceBox (ComboBox& combo, bool isInputs)
  57943. {
  57944. const StringArray devs (type->getDeviceNames (isInputs));
  57945. combo.clear (true);
  57946. for (int i = 0; i < devs.size(); ++i)
  57947. combo.addItem (devs[i], i + 1);
  57948. combo.addItem (TRANS("<< none >>"), -1);
  57949. combo.setSelectedId (-1, true);
  57950. }
  57951. int getLowestY() const
  57952. {
  57953. int y = 0;
  57954. for (int i = getNumChildComponents(); --i >= 0;)
  57955. y = jmax (y, getChildComponent (i)->getBottom());
  57956. return y;
  57957. }
  57958. public:
  57959. class ChannelSelectorListBox : public ListBox,
  57960. public ListBoxModel
  57961. {
  57962. public:
  57963. enum BoxType
  57964. {
  57965. audioInputType,
  57966. audioOutputType
  57967. };
  57968. ChannelSelectorListBox (const AudioIODeviceType::DeviceSetupDetails& setup_,
  57969. const BoxType type_,
  57970. const String& noItemsMessage_)
  57971. : ListBox (String::empty, 0),
  57972. setup (setup_),
  57973. type (type_),
  57974. noItemsMessage (noItemsMessage_)
  57975. {
  57976. refresh();
  57977. setModel (this);
  57978. setOutlineThickness (1);
  57979. }
  57980. ~ChannelSelectorListBox()
  57981. {
  57982. }
  57983. void refresh()
  57984. {
  57985. items.clear();
  57986. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  57987. if (currentDevice != 0)
  57988. {
  57989. if (type == audioInputType)
  57990. items = currentDevice->getInputChannelNames();
  57991. else if (type == audioOutputType)
  57992. items = currentDevice->getOutputChannelNames();
  57993. if (setup.useStereoPairs)
  57994. {
  57995. StringArray pairs;
  57996. for (int i = 0; i < items.size(); i += 2)
  57997. {
  57998. String name (items[i]);
  57999. String name2 (items[i + 1]);
  58000. String commonBit;
  58001. for (int j = 0; j < name.length(); ++j)
  58002. if (name.substring (0, j).equalsIgnoreCase (name2.substring (0, j)))
  58003. commonBit = name.substring (0, j);
  58004. pairs.add (name.trim()
  58005. + " + "
  58006. + name2.substring (commonBit.length()).trim());
  58007. }
  58008. items = pairs;
  58009. }
  58010. }
  58011. updateContent();
  58012. repaint();
  58013. }
  58014. int getNumRows()
  58015. {
  58016. return items.size();
  58017. }
  58018. void paintListBoxItem (int row,
  58019. Graphics& g,
  58020. int width, int height,
  58021. bool rowIsSelected)
  58022. {
  58023. if (((unsigned int) row) < (unsigned int) items.size())
  58024. {
  58025. if (rowIsSelected)
  58026. g.fillAll (findColour (TextEditor::highlightColourId)
  58027. .withMultipliedAlpha (0.3f));
  58028. const String item (items [row]);
  58029. bool enabled = false;
  58030. AudioDeviceManager::AudioDeviceSetup config;
  58031. setup.manager->getAudioDeviceSetup (config);
  58032. if (setup.useStereoPairs)
  58033. {
  58034. if (type == audioInputType)
  58035. enabled = config.inputChannels [row * 2] || config.inputChannels [row * 2 + 1];
  58036. else if (type == audioOutputType)
  58037. enabled = config.outputChannels [row * 2] || config.outputChannels [row * 2 + 1];
  58038. }
  58039. else
  58040. {
  58041. if (type == audioInputType)
  58042. enabled = config.inputChannels [row];
  58043. else if (type == audioOutputType)
  58044. enabled = config.outputChannels [row];
  58045. }
  58046. const int x = getTickX();
  58047. const float tickW = height * 0.75f;
  58048. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  58049. enabled, true, true, false);
  58050. g.setFont (height * 0.6f);
  58051. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  58052. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  58053. }
  58054. }
  58055. void listBoxItemClicked (int row, const MouseEvent& e)
  58056. {
  58057. selectRow (row);
  58058. if (e.x < getTickX())
  58059. flipEnablement (row);
  58060. }
  58061. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  58062. {
  58063. flipEnablement (row);
  58064. }
  58065. void returnKeyPressed (int row)
  58066. {
  58067. flipEnablement (row);
  58068. }
  58069. void paint (Graphics& g)
  58070. {
  58071. ListBox::paint (g);
  58072. if (items.size() == 0)
  58073. {
  58074. g.setColour (Colours::grey);
  58075. g.setFont (13.0f);
  58076. g.drawText (noItemsMessage,
  58077. 0, 0, getWidth(), getHeight() / 2,
  58078. Justification::centred, true);
  58079. }
  58080. }
  58081. int getBestHeight (int maxHeight)
  58082. {
  58083. return getRowHeight() * jlimit (2, jmax (2, maxHeight / getRowHeight()),
  58084. getNumRows())
  58085. + getOutlineThickness() * 2;
  58086. }
  58087. juce_UseDebuggingNewOperator
  58088. private:
  58089. const AudioIODeviceType::DeviceSetupDetails setup;
  58090. const BoxType type;
  58091. const String noItemsMessage;
  58092. StringArray items;
  58093. void flipEnablement (const int row)
  58094. {
  58095. jassert (type == audioInputType || type == audioOutputType);
  58096. if (((unsigned int) row) < (unsigned int) items.size())
  58097. {
  58098. AudioDeviceManager::AudioDeviceSetup config;
  58099. setup.manager->getAudioDeviceSetup (config);
  58100. if (setup.useStereoPairs)
  58101. {
  58102. BigInteger bits;
  58103. BigInteger& original = (type == audioInputType ? config.inputChannels
  58104. : config.outputChannels);
  58105. int i;
  58106. for (i = 0; i < 256; i += 2)
  58107. bits.setBit (i / 2, original [i] || original [i + 1]);
  58108. if (type == audioInputType)
  58109. {
  58110. config.useDefaultInputChannels = false;
  58111. flipBit (bits, row, setup.minNumInputChannels / 2, setup.maxNumInputChannels / 2);
  58112. }
  58113. else
  58114. {
  58115. config.useDefaultOutputChannels = false;
  58116. flipBit (bits, row, setup.minNumOutputChannels / 2, setup.maxNumOutputChannels / 2);
  58117. }
  58118. for (i = 0; i < 256; ++i)
  58119. original.setBit (i, bits [i / 2]);
  58120. }
  58121. else
  58122. {
  58123. if (type == audioInputType)
  58124. {
  58125. config.useDefaultInputChannels = false;
  58126. flipBit (config.inputChannels, row, setup.minNumInputChannels, setup.maxNumInputChannels);
  58127. }
  58128. else
  58129. {
  58130. config.useDefaultOutputChannels = false;
  58131. flipBit (config.outputChannels, row, setup.minNumOutputChannels, setup.maxNumOutputChannels);
  58132. }
  58133. }
  58134. String error (setup.manager->setAudioDeviceSetup (config, true));
  58135. if (! error.isEmpty())
  58136. {
  58137. //xxx
  58138. }
  58139. }
  58140. }
  58141. static void flipBit (BigInteger& chans, int index, int minNumber, int maxNumber)
  58142. {
  58143. const int numActive = chans.countNumberOfSetBits();
  58144. if (chans [index])
  58145. {
  58146. if (numActive > minNumber)
  58147. chans.setBit (index, false);
  58148. }
  58149. else
  58150. {
  58151. if (numActive >= maxNumber)
  58152. {
  58153. const int firstActiveChan = chans.findNextSetBit();
  58154. chans.setBit (index > firstActiveChan
  58155. ? firstActiveChan : chans.getHighestBit(),
  58156. false);
  58157. }
  58158. chans.setBit (index, true);
  58159. }
  58160. }
  58161. int getTickX() const
  58162. {
  58163. return getRowHeight() + 5;
  58164. }
  58165. ChannelSelectorListBox (const ChannelSelectorListBox&);
  58166. ChannelSelectorListBox& operator= (const ChannelSelectorListBox&);
  58167. };
  58168. private:
  58169. ChannelSelectorListBox* inputChanList;
  58170. ChannelSelectorListBox* outputChanList;
  58171. AudioDeviceSettingsPanel (const AudioDeviceSettingsPanel&);
  58172. AudioDeviceSettingsPanel& operator= (const AudioDeviceSettingsPanel&);
  58173. };
  58174. AudioDeviceSelectorComponent::AudioDeviceSelectorComponent (AudioDeviceManager& deviceManager_,
  58175. const int minInputChannels_,
  58176. const int maxInputChannels_,
  58177. const int minOutputChannels_,
  58178. const int maxOutputChannels_,
  58179. const bool showMidiInputOptions,
  58180. const bool showMidiOutputSelector,
  58181. const bool showChannelsAsStereoPairs_,
  58182. const bool hideAdvancedOptionsWithButton_)
  58183. : deviceManager (deviceManager_),
  58184. deviceTypeDropDown (0),
  58185. deviceTypeDropDownLabel (0),
  58186. audioDeviceSettingsComp (0),
  58187. minOutputChannels (minOutputChannels_),
  58188. maxOutputChannels (maxOutputChannels_),
  58189. minInputChannels (minInputChannels_),
  58190. maxInputChannels (maxInputChannels_),
  58191. showChannelsAsStereoPairs (showChannelsAsStereoPairs_),
  58192. hideAdvancedOptionsWithButton (hideAdvancedOptionsWithButton_)
  58193. {
  58194. jassert (minOutputChannels >= 0 && minOutputChannels <= maxOutputChannels);
  58195. jassert (minInputChannels >= 0 && minInputChannels <= maxInputChannels);
  58196. if (deviceManager_.getAvailableDeviceTypes().size() > 1)
  58197. {
  58198. deviceTypeDropDown = new ComboBox (String::empty);
  58199. for (int i = 0; i < deviceManager_.getAvailableDeviceTypes().size(); ++i)
  58200. {
  58201. deviceTypeDropDown
  58202. ->addItem (deviceManager_.getAvailableDeviceTypes().getUnchecked(i)->getTypeName(),
  58203. i + 1);
  58204. }
  58205. addAndMakeVisible (deviceTypeDropDown);
  58206. deviceTypeDropDown->addListener (this);
  58207. deviceTypeDropDownLabel = new Label (String::empty, TRANS ("audio device type:"));
  58208. deviceTypeDropDownLabel->setJustificationType (Justification::centredRight);
  58209. deviceTypeDropDownLabel->attachToComponent (deviceTypeDropDown, true);
  58210. }
  58211. if (showMidiInputOptions)
  58212. {
  58213. addAndMakeVisible (midiInputsList
  58214. = new MidiInputSelectorComponentListBox (deviceManager,
  58215. TRANS("(no midi inputs available)"),
  58216. 0, 0));
  58217. midiInputsLabel = new Label (String::empty, TRANS ("active midi inputs:"));
  58218. midiInputsLabel->setJustificationType (Justification::topRight);
  58219. midiInputsLabel->attachToComponent (midiInputsList, true);
  58220. }
  58221. else
  58222. {
  58223. midiInputsList = 0;
  58224. midiInputsLabel = 0;
  58225. }
  58226. if (showMidiOutputSelector)
  58227. {
  58228. addAndMakeVisible (midiOutputSelector = new ComboBox (String::empty));
  58229. midiOutputSelector->addListener (this);
  58230. midiOutputLabel = new Label ("lm", TRANS("Midi Output:"));
  58231. midiOutputLabel->attachToComponent (midiOutputSelector, true);
  58232. }
  58233. else
  58234. {
  58235. midiOutputSelector = 0;
  58236. midiOutputLabel = 0;
  58237. }
  58238. deviceManager_.addChangeListener (this);
  58239. changeListenerCallback (0);
  58240. }
  58241. AudioDeviceSelectorComponent::~AudioDeviceSelectorComponent()
  58242. {
  58243. deviceManager.removeChangeListener (this);
  58244. deleteAllChildren();
  58245. }
  58246. void AudioDeviceSelectorComponent::resized()
  58247. {
  58248. const int lx = proportionOfWidth (0.35f);
  58249. const int w = proportionOfWidth (0.4f);
  58250. const int h = 24;
  58251. const int space = 6;
  58252. const int dh = h + space;
  58253. int y = 15;
  58254. if (deviceTypeDropDown != 0)
  58255. {
  58256. deviceTypeDropDown->setBounds (lx, y, proportionOfWidth (0.3f), h);
  58257. y += dh + space * 2;
  58258. }
  58259. if (audioDeviceSettingsComp != 0)
  58260. {
  58261. audioDeviceSettingsComp->setBounds (0, y, getWidth(), audioDeviceSettingsComp->getHeight());
  58262. y += audioDeviceSettingsComp->getHeight() + space;
  58263. }
  58264. if (midiInputsList != 0)
  58265. {
  58266. const int bh = midiInputsList->getBestHeight (jmin (h * 8, getHeight() - y - space - h));
  58267. midiInputsList->setBounds (lx, y, w, bh);
  58268. y += bh + space;
  58269. }
  58270. if (midiOutputSelector != 0)
  58271. midiOutputSelector->setBounds (lx, y, w, h);
  58272. }
  58273. void AudioDeviceSelectorComponent::childBoundsChanged (Component* child)
  58274. {
  58275. if (child == audioDeviceSettingsComp)
  58276. resized();
  58277. }
  58278. void AudioDeviceSelectorComponent::buttonClicked (Button*)
  58279. {
  58280. AudioIODevice* const device = deviceManager.getCurrentAudioDevice();
  58281. if (device != 0 && device->hasControlPanel())
  58282. {
  58283. if (device->showControlPanel())
  58284. deviceManager.restartLastAudioDevice();
  58285. getTopLevelComponent()->toFront (true);
  58286. }
  58287. }
  58288. void AudioDeviceSelectorComponent::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  58289. {
  58290. if (comboBoxThatHasChanged == deviceTypeDropDown)
  58291. {
  58292. AudioIODeviceType* const type = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown->getSelectedId() - 1];
  58293. if (type != 0)
  58294. {
  58295. deleteAndZero (audioDeviceSettingsComp);
  58296. deviceManager.setCurrentAudioDeviceType (type->getTypeName(), true);
  58297. changeListenerCallback (0); // needed in case the type hasn't actally changed
  58298. }
  58299. }
  58300. else if (comboBoxThatHasChanged == midiOutputSelector)
  58301. {
  58302. deviceManager.setDefaultMidiOutput (midiOutputSelector->getText());
  58303. }
  58304. }
  58305. void AudioDeviceSelectorComponent::changeListenerCallback (void*)
  58306. {
  58307. if (deviceTypeDropDown != 0)
  58308. {
  58309. deviceTypeDropDown->setText (deviceManager.getCurrentAudioDeviceType(), false);
  58310. }
  58311. if (audioDeviceSettingsComp == 0
  58312. || audioDeviceSettingsCompType != deviceManager.getCurrentAudioDeviceType())
  58313. {
  58314. audioDeviceSettingsCompType = deviceManager.getCurrentAudioDeviceType();
  58315. deleteAndZero (audioDeviceSettingsComp);
  58316. AudioIODeviceType* const type
  58317. = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown == 0
  58318. ? 0 : deviceTypeDropDown->getSelectedId() - 1];
  58319. if (type != 0)
  58320. {
  58321. AudioIODeviceType::DeviceSetupDetails details;
  58322. details.manager = &deviceManager;
  58323. details.minNumInputChannels = minInputChannels;
  58324. details.maxNumInputChannels = maxInputChannels;
  58325. details.minNumOutputChannels = minOutputChannels;
  58326. details.maxNumOutputChannels = maxOutputChannels;
  58327. details.useStereoPairs = showChannelsAsStereoPairs;
  58328. audioDeviceSettingsComp = new AudioDeviceSettingsPanel (type, details, hideAdvancedOptionsWithButton);
  58329. if (audioDeviceSettingsComp != 0)
  58330. {
  58331. addAndMakeVisible (audioDeviceSettingsComp);
  58332. audioDeviceSettingsComp->resized();
  58333. }
  58334. }
  58335. }
  58336. if (midiInputsList != 0)
  58337. {
  58338. midiInputsList->updateContent();
  58339. midiInputsList->repaint();
  58340. }
  58341. if (midiOutputSelector != 0)
  58342. {
  58343. midiOutputSelector->clear();
  58344. const StringArray midiOuts (MidiOutput::getDevices());
  58345. midiOutputSelector->addItem (TRANS("<< none >>"), -1);
  58346. midiOutputSelector->addSeparator();
  58347. for (int i = 0; i < midiOuts.size(); ++i)
  58348. midiOutputSelector->addItem (midiOuts[i], i + 1);
  58349. int current = -1;
  58350. if (deviceManager.getDefaultMidiOutput() != 0)
  58351. current = 1 + midiOuts.indexOf (deviceManager.getDefaultMidiOutputName());
  58352. midiOutputSelector->setSelectedId (current, true);
  58353. }
  58354. resized();
  58355. }
  58356. END_JUCE_NAMESPACE
  58357. /*** End of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  58358. /*** Start of inlined file: juce_BubbleComponent.cpp ***/
  58359. BEGIN_JUCE_NAMESPACE
  58360. BubbleComponent::BubbleComponent()
  58361. : side (0),
  58362. allowablePlacements (above | below | left | right),
  58363. arrowTipX (0.0f),
  58364. arrowTipY (0.0f)
  58365. {
  58366. setInterceptsMouseClicks (false, false);
  58367. shadow.setShadowProperties (5.0f, 0.35f, 0, 0);
  58368. setComponentEffect (&shadow);
  58369. }
  58370. BubbleComponent::~BubbleComponent()
  58371. {
  58372. }
  58373. void BubbleComponent::paint (Graphics& g)
  58374. {
  58375. int x = content.getX();
  58376. int y = content.getY();
  58377. int w = content.getWidth();
  58378. int h = content.getHeight();
  58379. int cw, ch;
  58380. getContentSize (cw, ch);
  58381. if (side == 3)
  58382. x += w - cw;
  58383. else if (side != 1)
  58384. x += (w - cw) / 2;
  58385. w = cw;
  58386. if (side == 2)
  58387. y += h - ch;
  58388. else if (side != 0)
  58389. y += (h - ch) / 2;
  58390. h = ch;
  58391. getLookAndFeel().drawBubble (g, arrowTipX, arrowTipY,
  58392. (float) x, (float) y,
  58393. (float) w, (float) h);
  58394. const int cx = x + (w - cw) / 2;
  58395. const int cy = y + (h - ch) / 2;
  58396. const int indent = 3;
  58397. g.setOrigin (cx + indent, cy + indent);
  58398. g.reduceClipRegion (0, 0, cw - indent * 2, ch - indent * 2);
  58399. paintContent (g, cw - indent * 2, ch - indent * 2);
  58400. }
  58401. void BubbleComponent::setAllowedPlacement (const int newPlacement)
  58402. {
  58403. allowablePlacements = newPlacement;
  58404. }
  58405. void BubbleComponent::setPosition (Component* componentToPointTo)
  58406. {
  58407. jassert (componentToPointTo->isValidComponent());
  58408. Point<int> pos;
  58409. if (getParentComponent() != 0)
  58410. pos = componentToPointTo->relativePositionToOtherComponent (getParentComponent(), pos);
  58411. else
  58412. pos = componentToPointTo->relativePositionToGlobal (pos);
  58413. setPosition (Rectangle<int> (pos.getX(), pos.getY(), componentToPointTo->getWidth(), componentToPointTo->getHeight()));
  58414. }
  58415. void BubbleComponent::setPosition (const int arrowTipX_,
  58416. const int arrowTipY_)
  58417. {
  58418. setPosition (Rectangle<int> (arrowTipX_, arrowTipY_, 1, 1));
  58419. }
  58420. void BubbleComponent::setPosition (const Rectangle<int>& rectangleToPointTo)
  58421. {
  58422. Rectangle<int> availableSpace;
  58423. if (getParentComponent() != 0)
  58424. {
  58425. availableSpace.setSize (getParentComponent()->getWidth(),
  58426. getParentComponent()->getHeight());
  58427. }
  58428. else
  58429. {
  58430. availableSpace = getParentMonitorArea();
  58431. }
  58432. int x = 0;
  58433. int y = 0;
  58434. int w = 150;
  58435. int h = 30;
  58436. getContentSize (w, h);
  58437. w += 30;
  58438. h += 30;
  58439. const float edgeIndent = 2.0f;
  58440. const int arrowLength = jmin (10, h / 3, w / 3);
  58441. int spaceAbove = ((allowablePlacements & above) != 0) ? jmax (0, rectangleToPointTo.getY() - availableSpace.getY()) : -1;
  58442. int spaceBelow = ((allowablePlacements & below) != 0) ? jmax (0, availableSpace.getBottom() - rectangleToPointTo.getBottom()) : -1;
  58443. int spaceLeft = ((allowablePlacements & left) != 0) ? jmax (0, rectangleToPointTo.getX() - availableSpace.getX()) : -1;
  58444. int spaceRight = ((allowablePlacements & right) != 0) ? jmax (0, availableSpace.getRight() - rectangleToPointTo.getRight()) : -1;
  58445. // look at whether the component is elongated, and if so, try to position next to its longer dimension.
  58446. if (rectangleToPointTo.getWidth() > rectangleToPointTo.getHeight() * 2
  58447. && (spaceAbove > h + 20 || spaceBelow > h + 20))
  58448. {
  58449. spaceLeft = spaceRight = 0;
  58450. }
  58451. else if (rectangleToPointTo.getWidth() < rectangleToPointTo.getHeight() / 2
  58452. && (spaceLeft > w + 20 || spaceRight > w + 20))
  58453. {
  58454. spaceAbove = spaceBelow = 0;
  58455. }
  58456. if (jmax (spaceAbove, spaceBelow) >= jmax (spaceLeft, spaceRight))
  58457. {
  58458. x = rectangleToPointTo.getX() + (rectangleToPointTo.getWidth() - w) / 2;
  58459. arrowTipX = w * 0.5f;
  58460. content.setSize (w, h - arrowLength);
  58461. if (spaceAbove >= spaceBelow)
  58462. {
  58463. // above
  58464. y = rectangleToPointTo.getY() - h;
  58465. content.setPosition (0, 0);
  58466. arrowTipY = h - edgeIndent;
  58467. side = 2;
  58468. }
  58469. else
  58470. {
  58471. // below
  58472. y = rectangleToPointTo.getBottom();
  58473. content.setPosition (0, arrowLength);
  58474. arrowTipY = edgeIndent;
  58475. side = 0;
  58476. }
  58477. }
  58478. else
  58479. {
  58480. y = rectangleToPointTo.getY() + (rectangleToPointTo.getHeight() - h) / 2;
  58481. arrowTipY = h * 0.5f;
  58482. content.setSize (w - arrowLength, h);
  58483. if (spaceLeft > spaceRight)
  58484. {
  58485. // on the left
  58486. x = rectangleToPointTo.getX() - w;
  58487. content.setPosition (0, 0);
  58488. arrowTipX = w - edgeIndent;
  58489. side = 3;
  58490. }
  58491. else
  58492. {
  58493. // on the right
  58494. x = rectangleToPointTo.getRight();
  58495. content.setPosition (arrowLength, 0);
  58496. arrowTipX = edgeIndent;
  58497. side = 1;
  58498. }
  58499. }
  58500. setBounds (x, y, w, h);
  58501. }
  58502. END_JUCE_NAMESPACE
  58503. /*** End of inlined file: juce_BubbleComponent.cpp ***/
  58504. /*** Start of inlined file: juce_BubbleMessageComponent.cpp ***/
  58505. BEGIN_JUCE_NAMESPACE
  58506. BubbleMessageComponent::BubbleMessageComponent (int fadeOutLengthMs)
  58507. : fadeOutLength (fadeOutLengthMs),
  58508. deleteAfterUse (false)
  58509. {
  58510. }
  58511. BubbleMessageComponent::~BubbleMessageComponent()
  58512. {
  58513. fadeOutComponent (fadeOutLength);
  58514. }
  58515. void BubbleMessageComponent::showAt (int x, int y,
  58516. const String& text,
  58517. const int numMillisecondsBeforeRemoving,
  58518. const bool removeWhenMouseClicked,
  58519. const bool deleteSelfAfterUse)
  58520. {
  58521. textLayout.clear();
  58522. textLayout.setText (text, Font (14.0f));
  58523. textLayout.layout (256, Justification::centredLeft, true);
  58524. setPosition (x, y);
  58525. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58526. }
  58527. void BubbleMessageComponent::showAt (Component* const component,
  58528. const String& text,
  58529. const int numMillisecondsBeforeRemoving,
  58530. const bool removeWhenMouseClicked,
  58531. const bool deleteSelfAfterUse)
  58532. {
  58533. textLayout.clear();
  58534. textLayout.setText (text, Font (14.0f));
  58535. textLayout.layout (256, Justification::centredLeft, true);
  58536. setPosition (component);
  58537. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58538. }
  58539. void BubbleMessageComponent::init (const int numMillisecondsBeforeRemoving,
  58540. const bool removeWhenMouseClicked,
  58541. const bool deleteSelfAfterUse)
  58542. {
  58543. setVisible (true);
  58544. deleteAfterUse = deleteSelfAfterUse;
  58545. if (numMillisecondsBeforeRemoving > 0)
  58546. expiryTime = Time::getMillisecondCounter() + numMillisecondsBeforeRemoving;
  58547. else
  58548. expiryTime = 0;
  58549. startTimer (77);
  58550. mouseClickCounter = Desktop::getInstance().getMouseButtonClickCounter();
  58551. if (! (removeWhenMouseClicked && isShowing()))
  58552. mouseClickCounter += 0xfffff;
  58553. repaint();
  58554. }
  58555. void BubbleMessageComponent::getContentSize (int& w, int& h)
  58556. {
  58557. w = textLayout.getWidth() + 16;
  58558. h = textLayout.getHeight() + 16;
  58559. }
  58560. void BubbleMessageComponent::paintContent (Graphics& g, int w, int h)
  58561. {
  58562. g.setColour (findColour (TooltipWindow::textColourId));
  58563. textLayout.drawWithin (g, 0, 0, w, h, Justification::centred);
  58564. }
  58565. void BubbleMessageComponent::timerCallback()
  58566. {
  58567. if (Desktop::getInstance().getMouseButtonClickCounter() > mouseClickCounter)
  58568. {
  58569. stopTimer();
  58570. setVisible (false);
  58571. if (deleteAfterUse)
  58572. delete this;
  58573. }
  58574. else if (expiryTime != 0 && Time::getMillisecondCounter() > expiryTime)
  58575. {
  58576. stopTimer();
  58577. fadeOutComponent (fadeOutLength);
  58578. if (deleteAfterUse)
  58579. delete this;
  58580. }
  58581. }
  58582. END_JUCE_NAMESPACE
  58583. /*** End of inlined file: juce_BubbleMessageComponent.cpp ***/
  58584. /*** Start of inlined file: juce_ColourSelector.cpp ***/
  58585. BEGIN_JUCE_NAMESPACE
  58586. static const int swatchesPerRow = 8;
  58587. static const int swatchHeight = 22;
  58588. class ColourComponentSlider : public Slider
  58589. {
  58590. public:
  58591. ColourComponentSlider (const String& name)
  58592. : Slider (name)
  58593. {
  58594. setRange (0.0, 255.0, 1.0);
  58595. }
  58596. ~ColourComponentSlider()
  58597. {
  58598. }
  58599. const String getTextFromValue (double value)
  58600. {
  58601. return String::toHexString ((int) value).toUpperCase().paddedLeft ('0', 2);
  58602. }
  58603. double getValueFromText (const String& text)
  58604. {
  58605. return (double) text.getHexValue32();
  58606. }
  58607. private:
  58608. ColourComponentSlider (const ColourComponentSlider&);
  58609. ColourComponentSlider& operator= (const ColourComponentSlider&);
  58610. };
  58611. class ColourSpaceMarker : public Component
  58612. {
  58613. public:
  58614. ColourSpaceMarker()
  58615. {
  58616. setInterceptsMouseClicks (false, false);
  58617. }
  58618. ~ColourSpaceMarker()
  58619. {
  58620. }
  58621. void paint (Graphics& g)
  58622. {
  58623. g.setColour (Colour::greyLevel (0.1f));
  58624. g.drawEllipse (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 1.0f);
  58625. g.setColour (Colour::greyLevel (0.9f));
  58626. g.drawEllipse (2.0f, 2.0f, getWidth() - 4.0f, getHeight() - 4.0f, 1.0f);
  58627. }
  58628. private:
  58629. ColourSpaceMarker (const ColourSpaceMarker&);
  58630. ColourSpaceMarker& operator= (const ColourSpaceMarker&);
  58631. };
  58632. class ColourSpaceView : public Component
  58633. {
  58634. ColourSelector* const owner;
  58635. float& h;
  58636. float& s;
  58637. float& v;
  58638. float lastHue;
  58639. ColourSpaceMarker* marker;
  58640. const int edge;
  58641. public:
  58642. ColourSpaceView (ColourSelector* owner_,
  58643. float& h_, float& s_, float& v_,
  58644. const int edgeSize)
  58645. : owner (owner_),
  58646. h (h_), s (s_), v (v_),
  58647. lastHue (0.0f),
  58648. edge (edgeSize)
  58649. {
  58650. addAndMakeVisible (marker = new ColourSpaceMarker());
  58651. setMouseCursor (MouseCursor::CrosshairCursor);
  58652. }
  58653. ~ColourSpaceView()
  58654. {
  58655. deleteAllChildren();
  58656. }
  58657. void paint (Graphics& g)
  58658. {
  58659. if (colours == 0)
  58660. {
  58661. const int width = getWidth() / 2;
  58662. const int height = getHeight() / 2;
  58663. colours = new Image (Image::RGB, width, height, false);
  58664. Image::BitmapData pixels (*colours, 0, 0, width, height, true);
  58665. for (int y = 0; y < height; ++y)
  58666. {
  58667. const float v = 1.0f - y / (float) height;
  58668. for (int x = 0; x < width; ++x)
  58669. {
  58670. const float s = x / (float) width;
  58671. const Colour col (h, s, v, 1.0f);
  58672. PixelRGB* const pix = (PixelRGB*) pixels.getPixelPointer (x, y);
  58673. pix->set (col.getPixelARGB());
  58674. }
  58675. }
  58676. }
  58677. g.setOpacity (1.0f);
  58678. g.drawImage (colours, edge, edge, getWidth() - edge * 2, getHeight() - edge * 2,
  58679. 0, 0, colours->getWidth(), colours->getHeight());
  58680. }
  58681. void mouseDown (const MouseEvent& e)
  58682. {
  58683. mouseDrag (e);
  58684. }
  58685. void mouseDrag (const MouseEvent& e)
  58686. {
  58687. const float s = (e.x - edge) / (float) (getWidth() - edge * 2);
  58688. const float v = 1.0f - (e.y - edge) / (float) (getHeight() - edge * 2);
  58689. owner->setSV (s, v);
  58690. }
  58691. void updateIfNeeded()
  58692. {
  58693. if (lastHue != h)
  58694. {
  58695. lastHue = h;
  58696. colours = 0;
  58697. repaint();
  58698. }
  58699. updateMarker();
  58700. }
  58701. void resized()
  58702. {
  58703. colours = 0;
  58704. updateMarker();
  58705. }
  58706. private:
  58707. ScopedPointer <Image> colours;
  58708. void updateMarker() const throw()
  58709. {
  58710. marker->setBounds (roundToInt ((getWidth() - edge * 2) * s),
  58711. roundToInt ((getHeight() - edge * 2) * (1.0f - v)),
  58712. edge * 2, edge * 2);
  58713. }
  58714. ColourSpaceView (const ColourSpaceView&);
  58715. ColourSpaceView& operator= (const ColourSpaceView&);
  58716. };
  58717. class HueSelectorMarker : public Component
  58718. {
  58719. public:
  58720. HueSelectorMarker()
  58721. {
  58722. setInterceptsMouseClicks (false, false);
  58723. }
  58724. ~HueSelectorMarker()
  58725. {
  58726. }
  58727. void paint (Graphics& g)
  58728. {
  58729. Path p;
  58730. p.addTriangle (1.0f, 1.0f,
  58731. getWidth() * 0.3f, getHeight() * 0.5f,
  58732. 1.0f, getHeight() - 1.0f);
  58733. p.addTriangle (getWidth() - 1.0f, 1.0f,
  58734. getWidth() * 0.7f, getHeight() * 0.5f,
  58735. getWidth() - 1.0f, getHeight() - 1.0f);
  58736. g.setColour (Colours::white.withAlpha (0.75f));
  58737. g.fillPath (p);
  58738. g.setColour (Colours::black.withAlpha (0.75f));
  58739. g.strokePath (p, PathStrokeType (1.2f));
  58740. }
  58741. private:
  58742. HueSelectorMarker (const HueSelectorMarker&);
  58743. HueSelectorMarker& operator= (const HueSelectorMarker&);
  58744. };
  58745. class HueSelectorComp : public Component
  58746. {
  58747. public:
  58748. HueSelectorComp (ColourSelector* owner_,
  58749. float& h_, float& s_, float& v_,
  58750. const int edgeSize)
  58751. : owner (owner_),
  58752. h (h_), s (s_), v (v_),
  58753. lastHue (0.0f),
  58754. edge (edgeSize)
  58755. {
  58756. addAndMakeVisible (marker = new HueSelectorMarker());
  58757. }
  58758. ~HueSelectorComp()
  58759. {
  58760. deleteAllChildren();
  58761. }
  58762. void paint (Graphics& g)
  58763. {
  58764. const float yScale = 1.0f / (getHeight() - edge * 2);
  58765. const Rectangle<int> clip (g.getClipBounds());
  58766. for (int y = jmin (clip.getBottom(), getHeight() - edge); --y >= jmax (edge, clip.getY());)
  58767. {
  58768. g.setColour (Colour ((y - edge) * yScale, 1.0f, 1.0f, 1.0f));
  58769. g.fillRect (edge, y, getWidth() - edge * 2, 1);
  58770. }
  58771. }
  58772. void resized()
  58773. {
  58774. marker->setBounds (0, roundToInt ((getHeight() - edge * 2) * h),
  58775. getWidth(), edge * 2);
  58776. }
  58777. void mouseDown (const MouseEvent& e)
  58778. {
  58779. mouseDrag (e);
  58780. }
  58781. void mouseDrag (const MouseEvent& e)
  58782. {
  58783. const float hue = (e.y - edge) / (float) (getHeight() - edge * 2);
  58784. owner->setHue (hue);
  58785. }
  58786. void updateIfNeeded()
  58787. {
  58788. resized();
  58789. }
  58790. private:
  58791. ColourSelector* const owner;
  58792. float& h;
  58793. float& s;
  58794. float& v;
  58795. float lastHue;
  58796. HueSelectorMarker* marker;
  58797. const int edge;
  58798. HueSelectorComp (const HueSelectorComp&);
  58799. HueSelectorComp& operator= (const HueSelectorComp&);
  58800. };
  58801. class ColourSelector::SwatchComponent : public Component
  58802. {
  58803. public:
  58804. SwatchComponent (ColourSelector* owner_, int index_)
  58805. : owner (owner_),
  58806. index (index_)
  58807. {
  58808. }
  58809. ~SwatchComponent()
  58810. {
  58811. }
  58812. void paint (Graphics& g)
  58813. {
  58814. const Colour colour (owner->getSwatchColour (index));
  58815. g.fillCheckerBoard (0, 0, getWidth(), getHeight(),
  58816. 6, 6,
  58817. Colour (0xffdddddd).overlaidWith (colour),
  58818. Colour (0xffffffff).overlaidWith (colour));
  58819. }
  58820. void mouseDown (const MouseEvent&)
  58821. {
  58822. PopupMenu m;
  58823. m.addItem (1, TRANS("Use this swatch as the current colour"));
  58824. m.addSeparator();
  58825. m.addItem (2, TRANS("Set this swatch to the current colour"));
  58826. const int r = m.showAt (this);
  58827. if (r == 1)
  58828. {
  58829. owner->setCurrentColour (owner->getSwatchColour (index));
  58830. }
  58831. else if (r == 2)
  58832. {
  58833. if (owner->getSwatchColour (index) != owner->getCurrentColour())
  58834. {
  58835. owner->setSwatchColour (index, owner->getCurrentColour());
  58836. repaint();
  58837. }
  58838. }
  58839. }
  58840. private:
  58841. ColourSelector* const owner;
  58842. const int index;
  58843. SwatchComponent (const SwatchComponent&);
  58844. SwatchComponent& operator= (const SwatchComponent&);
  58845. };
  58846. ColourSelector::ColourSelector (const int flags_,
  58847. const int edgeGap_,
  58848. const int gapAroundColourSpaceComponent)
  58849. : colour (Colours::white),
  58850. flags (flags_),
  58851. topSpace (0),
  58852. edgeGap (edgeGap_)
  58853. {
  58854. // not much point having a selector with no components in it!
  58855. jassert ((flags_ & (showColourAtTop | showSliders | showColourspace)) != 0);
  58856. updateHSV();
  58857. if ((flags & showSliders) != 0)
  58858. {
  58859. addAndMakeVisible (sliders[0] = new ColourComponentSlider (TRANS ("red")));
  58860. addAndMakeVisible (sliders[1] = new ColourComponentSlider (TRANS ("green")));
  58861. addAndMakeVisible (sliders[2] = new ColourComponentSlider (TRANS ("blue")));
  58862. addChildComponent (sliders[3] = new ColourComponentSlider (TRANS ("alpha")));
  58863. sliders[3]->setVisible ((flags & showAlphaChannel) != 0);
  58864. for (int i = 4; --i >= 0;)
  58865. sliders[i]->addListener (this);
  58866. }
  58867. else
  58868. {
  58869. zeromem (sliders, sizeof (sliders));
  58870. }
  58871. if ((flags & showColourspace) != 0)
  58872. {
  58873. addAndMakeVisible (colourSpace = new ColourSpaceView (this, h, s, v, gapAroundColourSpaceComponent));
  58874. addAndMakeVisible (hueSelector = new HueSelectorComp (this, h, s, v, gapAroundColourSpaceComponent));
  58875. }
  58876. else
  58877. {
  58878. colourSpace = 0;
  58879. hueSelector = 0;
  58880. }
  58881. update();
  58882. }
  58883. ColourSelector::~ColourSelector()
  58884. {
  58885. dispatchPendingMessages();
  58886. swatchComponents.clear();
  58887. deleteAllChildren();
  58888. }
  58889. const Colour ColourSelector::getCurrentColour() const
  58890. {
  58891. return ((flags & showAlphaChannel) != 0) ? colour
  58892. : colour.withAlpha ((uint8) 0xff);
  58893. }
  58894. void ColourSelector::setCurrentColour (const Colour& c)
  58895. {
  58896. if (c != colour)
  58897. {
  58898. colour = ((flags & showAlphaChannel) != 0) ? c : c.withAlpha ((uint8) 0xff);
  58899. updateHSV();
  58900. update();
  58901. }
  58902. }
  58903. void ColourSelector::setHue (float newH)
  58904. {
  58905. newH = jlimit (0.0f, 1.0f, newH);
  58906. if (h != newH)
  58907. {
  58908. h = newH;
  58909. colour = Colour (h, s, v, colour.getFloatAlpha());
  58910. update();
  58911. }
  58912. }
  58913. void ColourSelector::setSV (float newS, float newV)
  58914. {
  58915. newS = jlimit (0.0f, 1.0f, newS);
  58916. newV = jlimit (0.0f, 1.0f, newV);
  58917. if (s != newS || v != newV)
  58918. {
  58919. s = newS;
  58920. v = newV;
  58921. colour = Colour (h, s, v, colour.getFloatAlpha());
  58922. update();
  58923. }
  58924. }
  58925. void ColourSelector::updateHSV()
  58926. {
  58927. colour.getHSB (h, s, v);
  58928. }
  58929. void ColourSelector::update()
  58930. {
  58931. if (sliders[0] != 0)
  58932. {
  58933. sliders[0]->setValue ((int) colour.getRed());
  58934. sliders[1]->setValue ((int) colour.getGreen());
  58935. sliders[2]->setValue ((int) colour.getBlue());
  58936. sliders[3]->setValue ((int) colour.getAlpha());
  58937. }
  58938. if (colourSpace != 0)
  58939. {
  58940. ((ColourSpaceView*) colourSpace)->updateIfNeeded();
  58941. ((HueSelectorComp*) hueSelector)->updateIfNeeded();
  58942. }
  58943. if ((flags & showColourAtTop) != 0)
  58944. repaint (0, edgeGap, getWidth(), topSpace - edgeGap);
  58945. sendChangeMessage (this);
  58946. }
  58947. void ColourSelector::paint (Graphics& g)
  58948. {
  58949. g.fillAll (findColour (backgroundColourId));
  58950. if ((flags & showColourAtTop) != 0)
  58951. {
  58952. const Colour colour (getCurrentColour());
  58953. g.fillCheckerBoard (edgeGap, edgeGap, getWidth() - edgeGap - edgeGap, topSpace - edgeGap - edgeGap,
  58954. 10, 10,
  58955. Colour (0xffdddddd).overlaidWith (colour),
  58956. Colour (0xffffffff).overlaidWith (colour));
  58957. g.setColour (Colours::white.overlaidWith (colour).contrasting());
  58958. g.setFont (14.0f, true);
  58959. g.drawText (colour.toDisplayString ((flags & showAlphaChannel) != 0),
  58960. 0, edgeGap, getWidth(), topSpace - edgeGap * 2,
  58961. Justification::centred, false);
  58962. }
  58963. if ((flags & showSliders) != 0)
  58964. {
  58965. g.setColour (findColour (labelTextColourId));
  58966. g.setFont (11.0f);
  58967. for (int i = 4; --i >= 0;)
  58968. {
  58969. if (sliders[i]->isVisible())
  58970. g.drawText (sliders[i]->getName() + ":",
  58971. 0, sliders[i]->getY(),
  58972. sliders[i]->getX() - 8, sliders[i]->getHeight(),
  58973. Justification::centredRight, false);
  58974. }
  58975. }
  58976. }
  58977. void ColourSelector::resized()
  58978. {
  58979. const int numSliders = ((flags & showAlphaChannel) != 0) ? 4 : 3;
  58980. const int numSwatches = getNumSwatches();
  58981. const int swatchSpace = numSwatches > 0 ? edgeGap + swatchHeight * ((numSwatches + 7) / swatchesPerRow) : 0;
  58982. const int sliderSpace = ((flags & showSliders) != 0) ? jmin (22 * numSliders + edgeGap, proportionOfHeight (0.3f)) : 0;
  58983. topSpace = ((flags & showColourAtTop) != 0) ? jmin (30 + edgeGap * 2, proportionOfHeight (0.2f)) : edgeGap;
  58984. int y = topSpace;
  58985. if ((flags & showColourspace) != 0)
  58986. {
  58987. const int hueWidth = jmin (50, proportionOfWidth (0.15f));
  58988. colourSpace->setBounds (edgeGap, y,
  58989. getWidth() - hueWidth - edgeGap - 4,
  58990. getHeight() - topSpace - sliderSpace - swatchSpace - edgeGap);
  58991. hueSelector->setBounds (colourSpace->getRight() + 4, y,
  58992. getWidth() - edgeGap - (colourSpace->getRight() + 4),
  58993. colourSpace->getHeight());
  58994. y = getHeight() - sliderSpace - swatchSpace - edgeGap;
  58995. }
  58996. if ((flags & showSliders) != 0)
  58997. {
  58998. const int sliderHeight = jmax (4, sliderSpace / numSliders);
  58999. for (int i = 0; i < numSliders; ++i)
  59000. {
  59001. sliders[i]->setBounds (proportionOfWidth (0.2f), y,
  59002. proportionOfWidth (0.72f), sliderHeight - 2);
  59003. y += sliderHeight;
  59004. }
  59005. }
  59006. if (numSwatches > 0)
  59007. {
  59008. const int startX = 8;
  59009. const int xGap = 4;
  59010. const int yGap = 4;
  59011. const int swatchWidth = (getWidth() - startX * 2) / swatchesPerRow;
  59012. y += edgeGap;
  59013. if (swatchComponents.size() != numSwatches)
  59014. {
  59015. swatchComponents.clear();
  59016. for (int i = 0; i < numSwatches; ++i)
  59017. {
  59018. SwatchComponent* const sc = new SwatchComponent (this, i);
  59019. swatchComponents.add (sc);
  59020. addAndMakeVisible (sc);
  59021. }
  59022. }
  59023. int x = startX;
  59024. for (int i = 0; i < swatchComponents.size(); ++i)
  59025. {
  59026. SwatchComponent* const sc = swatchComponents.getUnchecked(i);
  59027. sc->setBounds (x + xGap / 2,
  59028. y + yGap / 2,
  59029. swatchWidth - xGap,
  59030. swatchHeight - yGap);
  59031. if (((i + 1) % swatchesPerRow) == 0)
  59032. {
  59033. x = startX;
  59034. y += swatchHeight;
  59035. }
  59036. else
  59037. {
  59038. x += swatchWidth;
  59039. }
  59040. }
  59041. }
  59042. }
  59043. void ColourSelector::sliderValueChanged (Slider*)
  59044. {
  59045. if (sliders[0] != 0)
  59046. setCurrentColour (Colour ((uint8) sliders[0]->getValue(),
  59047. (uint8) sliders[1]->getValue(),
  59048. (uint8) sliders[2]->getValue(),
  59049. (uint8) sliders[3]->getValue()));
  59050. }
  59051. int ColourSelector::getNumSwatches() const
  59052. {
  59053. return 0;
  59054. }
  59055. const Colour ColourSelector::getSwatchColour (const int) const
  59056. {
  59057. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59058. return Colours::black;
  59059. }
  59060. void ColourSelector::setSwatchColour (const int, const Colour&) const
  59061. {
  59062. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59063. }
  59064. END_JUCE_NAMESPACE
  59065. /*** End of inlined file: juce_ColourSelector.cpp ***/
  59066. /*** Start of inlined file: juce_DropShadower.cpp ***/
  59067. BEGIN_JUCE_NAMESPACE
  59068. class ShadowWindow : public Component
  59069. {
  59070. Component* owner;
  59071. Image** shadowImageSections;
  59072. const int type; // 0 = left, 1 = right, 2 = top, 3 = bottom. left + right are full-height
  59073. public:
  59074. ShadowWindow (Component* const owner_,
  59075. const int type_,
  59076. Image** const shadowImageSections_)
  59077. : owner (owner_),
  59078. shadowImageSections (shadowImageSections_),
  59079. type (type_)
  59080. {
  59081. setInterceptsMouseClicks (false, false);
  59082. if (owner_->isOnDesktop())
  59083. {
  59084. setSize (1, 1); // to keep the OS happy by not having zero-size windows
  59085. addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  59086. | ComponentPeer::windowIsTemporary
  59087. | ComponentPeer::windowIgnoresKeyPresses);
  59088. }
  59089. else if (owner_->getParentComponent() != 0)
  59090. {
  59091. owner_->getParentComponent()->addChildComponent (this);
  59092. }
  59093. }
  59094. ~ShadowWindow()
  59095. {
  59096. }
  59097. void paint (Graphics& g)
  59098. {
  59099. Image* const topLeft = shadowImageSections [type * 3];
  59100. Image* const bottomRight = shadowImageSections [type * 3 + 1];
  59101. Image* const filler = shadowImageSections [type * 3 + 2];
  59102. g.setOpacity (1.0f);
  59103. if (type < 2)
  59104. {
  59105. int imH = jmin (topLeft->getHeight(), getHeight() / 2);
  59106. g.drawImage (topLeft,
  59107. 0, 0, topLeft->getWidth(), imH,
  59108. 0, 0, topLeft->getWidth(), imH);
  59109. imH = jmin (bottomRight->getHeight(), getHeight() - getHeight() / 2);
  59110. g.drawImage (bottomRight,
  59111. 0, getHeight() - imH, bottomRight->getWidth(), imH,
  59112. 0, bottomRight->getHeight() - imH, bottomRight->getWidth(), imH);
  59113. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59114. g.fillRect (0, topLeft->getHeight(), getWidth(), getHeight() - (topLeft->getHeight() + bottomRight->getHeight()));
  59115. }
  59116. else
  59117. {
  59118. int imW = jmin (topLeft->getWidth(), getWidth() / 2);
  59119. g.drawImage (topLeft,
  59120. 0, 0, imW, topLeft->getHeight(),
  59121. 0, 0, imW, topLeft->getHeight());
  59122. imW = jmin (bottomRight->getWidth(), getWidth() - getWidth() / 2);
  59123. g.drawImage (bottomRight,
  59124. getWidth() - imW, 0, imW, bottomRight->getHeight(),
  59125. bottomRight->getWidth() - imW, 0, imW, bottomRight->getHeight());
  59126. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59127. g.fillRect (topLeft->getWidth(), 0, getWidth() - (topLeft->getWidth() + bottomRight->getWidth()), getHeight());
  59128. }
  59129. }
  59130. void resized()
  59131. {
  59132. repaint(); // (needed for correct repainting)
  59133. }
  59134. private:
  59135. ShadowWindow (const ShadowWindow&);
  59136. ShadowWindow& operator= (const ShadowWindow&);
  59137. };
  59138. DropShadower::DropShadower (const float alpha_,
  59139. const int xOffset_,
  59140. const int yOffset_,
  59141. const float blurRadius_)
  59142. : owner (0),
  59143. numShadows (0),
  59144. shadowEdge (jmax (xOffset_, yOffset_) + (int) blurRadius_),
  59145. xOffset (xOffset_),
  59146. yOffset (yOffset_),
  59147. alpha (alpha_),
  59148. blurRadius (blurRadius_),
  59149. inDestructor (false),
  59150. reentrant (false)
  59151. {
  59152. }
  59153. DropShadower::~DropShadower()
  59154. {
  59155. if (owner != 0)
  59156. owner->removeComponentListener (this);
  59157. inDestructor = true;
  59158. deleteShadowWindows();
  59159. }
  59160. void DropShadower::deleteShadowWindows()
  59161. {
  59162. if (numShadows > 0)
  59163. {
  59164. int i;
  59165. for (i = numShadows; --i >= 0;)
  59166. delete shadowWindows[i];
  59167. for (i = 12; --i >= 0;)
  59168. delete shadowImageSections[i];
  59169. numShadows = 0;
  59170. }
  59171. }
  59172. void DropShadower::setOwner (Component* componentToFollow)
  59173. {
  59174. if (componentToFollow != owner)
  59175. {
  59176. if (owner != 0)
  59177. owner->removeComponentListener (this);
  59178. // (the component can't be null)
  59179. jassert (componentToFollow != 0);
  59180. owner = componentToFollow;
  59181. jassert (owner != 0);
  59182. jassert (owner->isOpaque()); // doesn't work properly for semi-transparent comps!
  59183. owner->addComponentListener (this);
  59184. updateShadows();
  59185. }
  59186. }
  59187. void DropShadower::componentMovedOrResized (Component&, bool /*wasMoved*/, bool /*wasResized*/)
  59188. {
  59189. updateShadows();
  59190. }
  59191. void DropShadower::componentBroughtToFront (Component&)
  59192. {
  59193. bringShadowWindowsToFront();
  59194. }
  59195. void DropShadower::componentChildrenChanged (Component&)
  59196. {
  59197. }
  59198. void DropShadower::componentParentHierarchyChanged (Component&)
  59199. {
  59200. deleteShadowWindows();
  59201. updateShadows();
  59202. }
  59203. void DropShadower::componentVisibilityChanged (Component&)
  59204. {
  59205. updateShadows();
  59206. }
  59207. void DropShadower::updateShadows()
  59208. {
  59209. if (reentrant || inDestructor || (owner == 0))
  59210. return;
  59211. reentrant = true;
  59212. ComponentPeer* const nw = owner->getPeer();
  59213. const bool isOwnerVisible = owner->isVisible()
  59214. && (nw == 0 || ! nw->isMinimised());
  59215. const bool createShadowWindows = numShadows == 0
  59216. && owner->getWidth() > 0
  59217. && owner->getHeight() > 0
  59218. && isOwnerVisible
  59219. && (Desktop::canUseSemiTransparentWindows()
  59220. || owner->getParentComponent() != 0);
  59221. if (createShadowWindows)
  59222. {
  59223. // keep a cached version of the image to save doing the gaussian too often
  59224. String imageId;
  59225. imageId << shadowEdge << ',' << xOffset << ',' << yOffset << ',' << alpha;
  59226. const int hash = imageId.hashCode();
  59227. Image* bigIm = ImageCache::getFromHashCode (hash);
  59228. if (bigIm == 0)
  59229. {
  59230. bigIm = Image::createNativeImage (Image::ARGB, shadowEdge * 5, shadowEdge * 5, true);
  59231. Graphics bigG (*bigIm);
  59232. bigG.setColour (Colours::black.withAlpha (alpha));
  59233. bigG.fillRect (shadowEdge + xOffset,
  59234. shadowEdge + yOffset,
  59235. bigIm->getWidth() - (shadowEdge * 2),
  59236. bigIm->getHeight() - (shadowEdge * 2));
  59237. ImageConvolutionKernel blurKernel (roundToInt (blurRadius * 2.0f));
  59238. blurKernel.createGaussianBlur (blurRadius);
  59239. blurKernel.applyToImage (*bigIm, 0,
  59240. xOffset,
  59241. yOffset,
  59242. bigIm->getWidth(),
  59243. bigIm->getHeight());
  59244. ImageCache::addImageToCache (bigIm, hash);
  59245. }
  59246. const int iw = bigIm->getWidth();
  59247. const int ih = bigIm->getHeight();
  59248. const int shadowEdge2 = shadowEdge * 2;
  59249. setShadowImage (bigIm, 0, shadowEdge, shadowEdge2, 0, 0);
  59250. setShadowImage (bigIm, 1, shadowEdge, shadowEdge2, 0, ih - shadowEdge2);
  59251. setShadowImage (bigIm, 2, shadowEdge, shadowEdge, 0, shadowEdge2);
  59252. setShadowImage (bigIm, 3, shadowEdge, shadowEdge2, iw - shadowEdge, 0);
  59253. setShadowImage (bigIm, 4, shadowEdge, shadowEdge2, iw - shadowEdge, ih - shadowEdge2);
  59254. setShadowImage (bigIm, 5, shadowEdge, shadowEdge, iw - shadowEdge, shadowEdge2);
  59255. setShadowImage (bigIm, 6, shadowEdge, shadowEdge, shadowEdge, 0);
  59256. setShadowImage (bigIm, 7, shadowEdge, shadowEdge, iw - shadowEdge2, 0);
  59257. setShadowImage (bigIm, 8, shadowEdge, shadowEdge, shadowEdge2, 0);
  59258. setShadowImage (bigIm, 9, shadowEdge, shadowEdge, shadowEdge, ih - shadowEdge);
  59259. setShadowImage (bigIm, 10, shadowEdge, shadowEdge, iw - shadowEdge2, ih - shadowEdge);
  59260. setShadowImage (bigIm, 11, shadowEdge, shadowEdge, shadowEdge2, ih - shadowEdge);
  59261. ImageCache::release (bigIm);
  59262. for (int i = 0; i < 4; ++i)
  59263. {
  59264. shadowWindows[numShadows] = new ShadowWindow (owner, i, shadowImageSections);
  59265. ++numShadows;
  59266. }
  59267. }
  59268. if (numShadows > 0)
  59269. {
  59270. for (int i = numShadows; --i >= 0;)
  59271. {
  59272. shadowWindows[i]->setAlwaysOnTop (owner->isAlwaysOnTop());
  59273. shadowWindows[i]->setVisible (isOwnerVisible);
  59274. }
  59275. const int x = owner->getX();
  59276. const int y = owner->getY() - shadowEdge;
  59277. const int w = owner->getWidth();
  59278. const int h = owner->getHeight() + shadowEdge + shadowEdge;
  59279. shadowWindows[0]->setBounds (x - shadowEdge,
  59280. y,
  59281. shadowEdge,
  59282. h);
  59283. shadowWindows[1]->setBounds (x + w,
  59284. y,
  59285. shadowEdge,
  59286. h);
  59287. shadowWindows[2]->setBounds (x,
  59288. y,
  59289. w,
  59290. shadowEdge);
  59291. shadowWindows[3]->setBounds (x,
  59292. owner->getBottom(),
  59293. w,
  59294. shadowEdge);
  59295. }
  59296. reentrant = false;
  59297. if (createShadowWindows)
  59298. bringShadowWindowsToFront();
  59299. }
  59300. void DropShadower::setShadowImage (Image* const src, const int num, const int w, const int h,
  59301. const int sx, const int sy)
  59302. {
  59303. shadowImageSections[num] = new Image (Image::ARGB, w, h, true);
  59304. Graphics g (*shadowImageSections[num]);
  59305. g.drawImage (src, 0, 0, w, h, sx, sy, w, h);
  59306. }
  59307. void DropShadower::bringShadowWindowsToFront()
  59308. {
  59309. if (! (inDestructor || reentrant))
  59310. {
  59311. updateShadows();
  59312. reentrant = true;
  59313. for (int i = numShadows; --i >= 0;)
  59314. shadowWindows[i]->toBehind (owner);
  59315. reentrant = false;
  59316. }
  59317. }
  59318. END_JUCE_NAMESPACE
  59319. /*** End of inlined file: juce_DropShadower.cpp ***/
  59320. /*** Start of inlined file: juce_MagnifierComponent.cpp ***/
  59321. BEGIN_JUCE_NAMESPACE
  59322. class MagnifyingPeer : public ComponentPeer
  59323. {
  59324. public:
  59325. MagnifyingPeer (Component* const component_,
  59326. MagnifierComponent* const magnifierComp_)
  59327. : ComponentPeer (component_, 0),
  59328. magnifierComp (magnifierComp_)
  59329. {
  59330. }
  59331. ~MagnifyingPeer()
  59332. {
  59333. }
  59334. void* getNativeHandle() const { return 0; }
  59335. void setVisible (bool) {}
  59336. void setTitle (const String&) {}
  59337. void setPosition (int, int) {}
  59338. void setSize (int, int) {}
  59339. void setBounds (int, int, int, int, bool) {}
  59340. void setMinimised (bool) {}
  59341. bool isMinimised() const { return false; }
  59342. void setFullScreen (bool) {}
  59343. bool isFullScreen() const { return false; }
  59344. const BorderSize getFrameSize() const { return BorderSize (0); }
  59345. bool setAlwaysOnTop (bool) { return true; }
  59346. void toFront (bool) {}
  59347. void toBehind (ComponentPeer*) {}
  59348. void setIcon (const Image&) {}
  59349. bool isFocused() const
  59350. {
  59351. return magnifierComp->hasKeyboardFocus (true);
  59352. }
  59353. void grabFocus()
  59354. {
  59355. ComponentPeer* peer = magnifierComp->getPeer();
  59356. if (peer != 0)
  59357. peer->grabFocus();
  59358. }
  59359. void textInputRequired (const Point<int>& position)
  59360. {
  59361. ComponentPeer* peer = magnifierComp->getPeer();
  59362. if (peer != 0)
  59363. peer->textInputRequired (position);
  59364. }
  59365. const Rectangle<int> getBounds() const
  59366. {
  59367. return Rectangle<int> (magnifierComp->getScreenX(), magnifierComp->getScreenY(),
  59368. component->getWidth(), component->getHeight());
  59369. }
  59370. const Point<int> getScreenPosition() const
  59371. {
  59372. return magnifierComp->getScreenPosition();
  59373. }
  59374. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  59375. {
  59376. const double zoom = magnifierComp->getScaleFactor();
  59377. return magnifierComp->relativePositionToGlobal (Point<int> (roundToInt (relativePosition.getX() * zoom),
  59378. roundToInt (relativePosition.getY() * zoom)));
  59379. }
  59380. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  59381. {
  59382. const Point<int> p (magnifierComp->globalPositionToRelative (screenPosition));
  59383. const double zoom = magnifierComp->getScaleFactor();
  59384. return Point<int> (roundToInt (p.getX() / zoom),
  59385. roundToInt (p.getY() / zoom));
  59386. }
  59387. bool contains (const Point<int>& position, bool) const
  59388. {
  59389. return ((unsigned int) position.getX()) < (unsigned int) magnifierComp->getWidth()
  59390. && ((unsigned int) position.getY()) < (unsigned int) magnifierComp->getHeight();
  59391. }
  59392. void repaint (int x, int y, int w, int h)
  59393. {
  59394. const double zoom = magnifierComp->getScaleFactor();
  59395. magnifierComp->repaint ((int) (x * zoom),
  59396. (int) (y * zoom),
  59397. roundToInt (w * zoom) + 1,
  59398. roundToInt (h * zoom) + 1);
  59399. }
  59400. void performAnyPendingRepaintsNow()
  59401. {
  59402. }
  59403. juce_UseDebuggingNewOperator
  59404. private:
  59405. MagnifierComponent* const magnifierComp;
  59406. MagnifyingPeer (const MagnifyingPeer&);
  59407. MagnifyingPeer& operator= (const MagnifyingPeer&);
  59408. };
  59409. class PeerHolderComp : public Component
  59410. {
  59411. public:
  59412. PeerHolderComp (MagnifierComponent* const magnifierComp_)
  59413. : magnifierComp (magnifierComp_)
  59414. {
  59415. setVisible (true);
  59416. }
  59417. ~PeerHolderComp()
  59418. {
  59419. }
  59420. ComponentPeer* createNewPeer (int, void*)
  59421. {
  59422. return new MagnifyingPeer (this, magnifierComp);
  59423. }
  59424. void childBoundsChanged (Component* c)
  59425. {
  59426. if (c != 0)
  59427. {
  59428. setSize (c->getWidth(), c->getHeight());
  59429. magnifierComp->childBoundsChanged (this);
  59430. }
  59431. }
  59432. void mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59433. {
  59434. // unhandled mouse wheel moves can be referred upwards to the parent comp..
  59435. Component* const p = magnifierComp->getParentComponent();
  59436. if (p != 0)
  59437. p->mouseWheelMove (e.getEventRelativeTo (p), ix, iy);
  59438. }
  59439. private:
  59440. MagnifierComponent* const magnifierComp;
  59441. PeerHolderComp (const PeerHolderComp&);
  59442. PeerHolderComp& operator= (const PeerHolderComp&);
  59443. };
  59444. MagnifierComponent::MagnifierComponent (Component* const content_,
  59445. const bool deleteContentCompWhenNoLongerNeeded)
  59446. : content (content_),
  59447. scaleFactor (0.0),
  59448. peer (0),
  59449. deleteContent (deleteContentCompWhenNoLongerNeeded),
  59450. quality (Graphics::lowResamplingQuality),
  59451. mouseSource (0, true)
  59452. {
  59453. holderComp = new PeerHolderComp (this);
  59454. setScaleFactor (1.0);
  59455. }
  59456. MagnifierComponent::~MagnifierComponent()
  59457. {
  59458. delete holderComp;
  59459. if (deleteContent)
  59460. delete content;
  59461. }
  59462. void MagnifierComponent::setScaleFactor (double newScaleFactor)
  59463. {
  59464. jassert (newScaleFactor > 0.0); // hmm - unlikely to work well with a negative scale factor
  59465. newScaleFactor = jlimit (1.0 / 8.0, 1000.0, newScaleFactor);
  59466. if (scaleFactor != newScaleFactor)
  59467. {
  59468. scaleFactor = newScaleFactor;
  59469. if (scaleFactor == 1.0)
  59470. {
  59471. holderComp->removeFromDesktop();
  59472. peer = 0;
  59473. addChildComponent (content);
  59474. childBoundsChanged (content);
  59475. }
  59476. else
  59477. {
  59478. holderComp->addAndMakeVisible (content);
  59479. holderComp->childBoundsChanged (content);
  59480. childBoundsChanged (holderComp);
  59481. holderComp->addToDesktop (0);
  59482. peer = holderComp->getPeer();
  59483. }
  59484. repaint();
  59485. }
  59486. }
  59487. void MagnifierComponent::setResamplingQuality (Graphics::ResamplingQuality newQuality)
  59488. {
  59489. quality = newQuality;
  59490. }
  59491. void MagnifierComponent::paint (Graphics& g)
  59492. {
  59493. const int w = holderComp->getWidth();
  59494. const int h = holderComp->getHeight();
  59495. if (w == 0 || h == 0)
  59496. return;
  59497. const Rectangle<int> r (g.getClipBounds());
  59498. const int srcX = (int) (r.getX() / scaleFactor);
  59499. const int srcY = (int) (r.getY() / scaleFactor);
  59500. int srcW = roundToInt (r.getRight() / scaleFactor) - srcX;
  59501. int srcH = roundToInt (r.getBottom() / scaleFactor) - srcY;
  59502. if (scaleFactor >= 1.0)
  59503. {
  59504. ++srcW;
  59505. ++srcH;
  59506. }
  59507. Image temp (Image::ARGB, jmax (w, srcX + srcW), jmax (h, srcY + srcH), false);
  59508. temp.clear (srcX, srcY, srcW, srcH);
  59509. {
  59510. Graphics g2 (temp);
  59511. g2.reduceClipRegion (srcX, srcY, srcW, srcH);
  59512. holderComp->paintEntireComponent (g2);
  59513. }
  59514. g.setImageResamplingQuality (quality);
  59515. g.drawImageTransformed (&temp, temp.getBounds(),
  59516. AffineTransform::scale ((float) scaleFactor, (float) scaleFactor),
  59517. false);
  59518. }
  59519. void MagnifierComponent::childBoundsChanged (Component* c)
  59520. {
  59521. if (c != 0)
  59522. setSize (roundToInt (c->getWidth() * scaleFactor),
  59523. roundToInt (c->getHeight() * scaleFactor));
  59524. }
  59525. void MagnifierComponent::passOnMouseEventToPeer (const MouseEvent& e)
  59526. {
  59527. if (peer != 0)
  59528. mouseSource.handleEvent (peer, Point<int> (scaleInt (e.x), scaleInt (e.y)),
  59529. e.eventTime.toMilliseconds(), ModifierKeys::getCurrentModifiers());
  59530. }
  59531. void MagnifierComponent::mouseDown (const MouseEvent& e)
  59532. {
  59533. passOnMouseEventToPeer (e);
  59534. }
  59535. void MagnifierComponent::mouseUp (const MouseEvent& e)
  59536. {
  59537. passOnMouseEventToPeer (e);
  59538. }
  59539. void MagnifierComponent::mouseDrag (const MouseEvent& e)
  59540. {
  59541. passOnMouseEventToPeer (e);
  59542. }
  59543. void MagnifierComponent::mouseMove (const MouseEvent& e)
  59544. {
  59545. passOnMouseEventToPeer (e);
  59546. }
  59547. void MagnifierComponent::mouseEnter (const MouseEvent& e)
  59548. {
  59549. passOnMouseEventToPeer (e);
  59550. }
  59551. void MagnifierComponent::mouseExit (const MouseEvent& e)
  59552. {
  59553. passOnMouseEventToPeer (e);
  59554. }
  59555. void MagnifierComponent::mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59556. {
  59557. if (peer != 0)
  59558. peer->handleMouseWheel (e.source.getIndex(),
  59559. Point<int> (scaleInt (e.x), scaleInt (e.y)), e.eventTime.toMilliseconds(),
  59560. ix * 256.0f, iy * 256.0f);
  59561. else
  59562. Component::mouseWheelMove (e, ix, iy);
  59563. }
  59564. int MagnifierComponent::scaleInt (const int n) const
  59565. {
  59566. return roundToInt (n / scaleFactor);
  59567. }
  59568. END_JUCE_NAMESPACE
  59569. /*** End of inlined file: juce_MagnifierComponent.cpp ***/
  59570. /*** Start of inlined file: juce_MidiKeyboardComponent.cpp ***/
  59571. BEGIN_JUCE_NAMESPACE
  59572. class MidiKeyboardUpDownButton : public Button
  59573. {
  59574. public:
  59575. MidiKeyboardUpDownButton (MidiKeyboardComponent* const owner_,
  59576. const int delta_)
  59577. : Button (String::empty),
  59578. owner (owner_),
  59579. delta (delta_)
  59580. {
  59581. setOpaque (true);
  59582. }
  59583. ~MidiKeyboardUpDownButton()
  59584. {
  59585. }
  59586. void clicked()
  59587. {
  59588. int note = owner->getLowestVisibleKey();
  59589. if (delta < 0)
  59590. note = (note - 1) / 12;
  59591. else
  59592. note = note / 12 + 1;
  59593. owner->setLowestVisibleKey (note * 12);
  59594. }
  59595. void paintButton (Graphics& g,
  59596. bool isMouseOverButton,
  59597. bool isButtonDown)
  59598. {
  59599. owner->drawUpDownButton (g, getWidth(), getHeight(),
  59600. isMouseOverButton, isButtonDown,
  59601. delta > 0);
  59602. }
  59603. private:
  59604. MidiKeyboardComponent* const owner;
  59605. const int delta;
  59606. MidiKeyboardUpDownButton (const MidiKeyboardUpDownButton&);
  59607. MidiKeyboardUpDownButton& operator= (const MidiKeyboardUpDownButton&);
  59608. };
  59609. MidiKeyboardComponent::MidiKeyboardComponent (MidiKeyboardState& state_,
  59610. const Orientation orientation_)
  59611. : state (state_),
  59612. xOffset (0),
  59613. blackNoteLength (1),
  59614. keyWidth (16.0f),
  59615. orientation (orientation_),
  59616. midiChannel (1),
  59617. midiInChannelMask (0xffff),
  59618. velocity (1.0f),
  59619. noteUnderMouse (-1),
  59620. mouseDownNote (-1),
  59621. rangeStart (0),
  59622. rangeEnd (127),
  59623. firstKey (12 * 4),
  59624. canScroll (true),
  59625. mouseDragging (false),
  59626. useMousePositionForVelocity (true),
  59627. keyMappingOctave (6),
  59628. octaveNumForMiddleC (3)
  59629. {
  59630. addChildComponent (scrollDown = new MidiKeyboardUpDownButton (this, -1));
  59631. addChildComponent (scrollUp = new MidiKeyboardUpDownButton (this, 1));
  59632. // initialise with a default set of querty key-mappings..
  59633. const char* const keymap = "awsedftgyhujkolp;";
  59634. for (int i = String (keymap).length(); --i >= 0;)
  59635. setKeyPressForNote (KeyPress (keymap[i], 0, 0), i);
  59636. setOpaque (true);
  59637. setWantsKeyboardFocus (true);
  59638. state.addListener (this);
  59639. }
  59640. MidiKeyboardComponent::~MidiKeyboardComponent()
  59641. {
  59642. state.removeListener (this);
  59643. jassert (mouseDownNote < 0 && keysPressed.countNumberOfSetBits() == 0); // leaving stuck notes!
  59644. deleteAllChildren();
  59645. }
  59646. void MidiKeyboardComponent::setKeyWidth (const float widthInPixels)
  59647. {
  59648. keyWidth = widthInPixels;
  59649. resized();
  59650. }
  59651. void MidiKeyboardComponent::setOrientation (const Orientation newOrientation)
  59652. {
  59653. if (orientation != newOrientation)
  59654. {
  59655. orientation = newOrientation;
  59656. resized();
  59657. }
  59658. }
  59659. void MidiKeyboardComponent::setAvailableRange (const int lowestNote,
  59660. const int highestNote)
  59661. {
  59662. jassert (lowestNote >= 0 && lowestNote <= 127);
  59663. jassert (highestNote >= 0 && highestNote <= 127);
  59664. jassert (lowestNote <= highestNote);
  59665. if (rangeStart != lowestNote || rangeEnd != highestNote)
  59666. {
  59667. rangeStart = jlimit (0, 127, lowestNote);
  59668. rangeEnd = jlimit (0, 127, highestNote);
  59669. firstKey = jlimit (rangeStart, rangeEnd, firstKey);
  59670. resized();
  59671. }
  59672. }
  59673. void MidiKeyboardComponent::setLowestVisibleKey (int noteNumber)
  59674. {
  59675. noteNumber = jlimit (rangeStart, rangeEnd, noteNumber);
  59676. if (noteNumber != firstKey)
  59677. {
  59678. firstKey = noteNumber;
  59679. sendChangeMessage (this);
  59680. resized();
  59681. }
  59682. }
  59683. void MidiKeyboardComponent::setScrollButtonsVisible (const bool canScroll_)
  59684. {
  59685. if (canScroll != canScroll_)
  59686. {
  59687. canScroll = canScroll_;
  59688. resized();
  59689. }
  59690. }
  59691. void MidiKeyboardComponent::colourChanged()
  59692. {
  59693. repaint();
  59694. }
  59695. void MidiKeyboardComponent::setMidiChannel (const int midiChannelNumber)
  59696. {
  59697. jassert (midiChannelNumber > 0 && midiChannelNumber <= 16);
  59698. if (midiChannel != midiChannelNumber)
  59699. {
  59700. resetAnyKeysInUse();
  59701. midiChannel = jlimit (1, 16, midiChannelNumber);
  59702. }
  59703. }
  59704. void MidiKeyboardComponent::setMidiChannelsToDisplay (const int midiChannelMask)
  59705. {
  59706. midiInChannelMask = midiChannelMask;
  59707. triggerAsyncUpdate();
  59708. }
  59709. void MidiKeyboardComponent::setVelocity (const float velocity_, const bool useMousePositionForVelocity_)
  59710. {
  59711. velocity = jlimit (0.0f, 1.0f, velocity_);
  59712. useMousePositionForVelocity = useMousePositionForVelocity_;
  59713. }
  59714. void MidiKeyboardComponent::getKeyPosition (int midiNoteNumber, const float keyWidth, int& x, int& w) const
  59715. {
  59716. jassert (midiNoteNumber >= 0 && midiNoteNumber < 128);
  59717. static const float blackNoteWidth = 0.7f;
  59718. static const float notePos[] = { 0.0f, 1 - blackNoteWidth * 0.6f,
  59719. 1.0f, 2 - blackNoteWidth * 0.4f,
  59720. 2.0f, 3.0f, 4 - blackNoteWidth * 0.7f,
  59721. 4.0f, 5 - blackNoteWidth * 0.5f,
  59722. 5.0f, 6 - blackNoteWidth * 0.3f,
  59723. 6.0f };
  59724. static const float widths[] = { 1.0f, blackNoteWidth,
  59725. 1.0f, blackNoteWidth,
  59726. 1.0f, 1.0f, blackNoteWidth,
  59727. 1.0f, blackNoteWidth,
  59728. 1.0f, blackNoteWidth,
  59729. 1.0f };
  59730. const int octave = midiNoteNumber / 12;
  59731. const int note = midiNoteNumber % 12;
  59732. x = roundToInt (octave * 7.0f * keyWidth + notePos [note] * keyWidth);
  59733. w = roundToInt (widths [note] * keyWidth);
  59734. }
  59735. void MidiKeyboardComponent::getKeyPos (int midiNoteNumber, int& x, int& w) const
  59736. {
  59737. getKeyPosition (midiNoteNumber, keyWidth, x, w);
  59738. int rx, rw;
  59739. getKeyPosition (rangeStart, keyWidth, rx, rw);
  59740. x -= xOffset + rx;
  59741. }
  59742. int MidiKeyboardComponent::getKeyStartPosition (const int midiNoteNumber) const
  59743. {
  59744. int x, y;
  59745. getKeyPos (midiNoteNumber, x, y);
  59746. return x;
  59747. }
  59748. static const uint8 whiteNotes[] = { 0, 2, 4, 5, 7, 9, 11 };
  59749. static const uint8 blackNotes[] = { 1, 3, 6, 8, 10 };
  59750. int MidiKeyboardComponent::xyToNote (const Point<int>& pos, float& mousePositionVelocity)
  59751. {
  59752. if (! reallyContains (pos.getX(), pos.getY(), false))
  59753. return -1;
  59754. Point<int> p (pos);
  59755. if (orientation != horizontalKeyboard)
  59756. {
  59757. p = Point<int> (p.getY(), p.getX());
  59758. if (orientation == verticalKeyboardFacingLeft)
  59759. p = Point<int> (p.getX(), getWidth() - p.getY());
  59760. else
  59761. p = Point<int> (getHeight() - p.getX(), p.getY());
  59762. }
  59763. return remappedXYToNote (p + Point<int> (xOffset, 0), mousePositionVelocity);
  59764. }
  59765. int MidiKeyboardComponent::remappedXYToNote (const Point<int>& pos, float& mousePositionVelocity) const
  59766. {
  59767. if (pos.getY() < blackNoteLength)
  59768. {
  59769. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  59770. {
  59771. for (int i = 0; i < 5; ++i)
  59772. {
  59773. const int note = octaveStart + blackNotes [i];
  59774. if (note >= rangeStart && note <= rangeEnd)
  59775. {
  59776. int kx, kw;
  59777. getKeyPos (note, kx, kw);
  59778. kx += xOffset;
  59779. if (pos.getX() >= kx && pos.getX() < kx + kw)
  59780. {
  59781. mousePositionVelocity = pos.getY() / (float) blackNoteLength;
  59782. return note;
  59783. }
  59784. }
  59785. }
  59786. }
  59787. }
  59788. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  59789. {
  59790. for (int i = 0; i < 7; ++i)
  59791. {
  59792. const int note = octaveStart + whiteNotes [i];
  59793. if (note >= rangeStart && note <= rangeEnd)
  59794. {
  59795. int kx, kw;
  59796. getKeyPos (note, kx, kw);
  59797. kx += xOffset;
  59798. if (pos.getX() >= kx && pos.getX() < kx + kw)
  59799. {
  59800. const int whiteNoteLength = (orientation == horizontalKeyboard) ? getHeight() : getWidth();
  59801. mousePositionVelocity = pos.getY() / (float) whiteNoteLength;
  59802. return note;
  59803. }
  59804. }
  59805. }
  59806. }
  59807. mousePositionVelocity = 0;
  59808. return -1;
  59809. }
  59810. void MidiKeyboardComponent::repaintNote (const int noteNum)
  59811. {
  59812. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  59813. {
  59814. int x, w;
  59815. getKeyPos (noteNum, x, w);
  59816. if (orientation == horizontalKeyboard)
  59817. repaint (x, 0, w, getHeight());
  59818. else if (orientation == verticalKeyboardFacingLeft)
  59819. repaint (0, x, getWidth(), w);
  59820. else if (orientation == verticalKeyboardFacingRight)
  59821. repaint (0, getHeight() - x - w, getWidth(), w);
  59822. }
  59823. }
  59824. void MidiKeyboardComponent::paint (Graphics& g)
  59825. {
  59826. g.fillAll (Colours::white.overlaidWith (findColour (whiteNoteColourId)));
  59827. const Colour lineColour (findColour (keySeparatorLineColourId));
  59828. const Colour textColour (findColour (textLabelColourId));
  59829. int x, w, octave;
  59830. for (octave = 0; octave < 128; octave += 12)
  59831. {
  59832. for (int white = 0; white < 7; ++white)
  59833. {
  59834. const int noteNum = octave + whiteNotes [white];
  59835. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  59836. {
  59837. getKeyPos (noteNum, x, w);
  59838. if (orientation == horizontalKeyboard)
  59839. drawWhiteNote (noteNum, g, x, 0, w, getHeight(),
  59840. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59841. noteUnderMouse == noteNum,
  59842. lineColour, textColour);
  59843. else if (orientation == verticalKeyboardFacingLeft)
  59844. drawWhiteNote (noteNum, g, 0, x, getWidth(), w,
  59845. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59846. noteUnderMouse == noteNum,
  59847. lineColour, textColour);
  59848. else if (orientation == verticalKeyboardFacingRight)
  59849. drawWhiteNote (noteNum, g, 0, getHeight() - x - w, getWidth(), w,
  59850. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59851. noteUnderMouse == noteNum,
  59852. lineColour, textColour);
  59853. }
  59854. }
  59855. }
  59856. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  59857. if (orientation == verticalKeyboardFacingLeft)
  59858. {
  59859. x1 = getWidth() - 1.0f;
  59860. x2 = getWidth() - 5.0f;
  59861. }
  59862. else if (orientation == verticalKeyboardFacingRight)
  59863. x2 = 5.0f;
  59864. else
  59865. y2 = 5.0f;
  59866. g.setGradientFill (ColourGradient (Colours::black.withAlpha (0.3f), x1, y1,
  59867. Colours::transparentBlack, x2, y2, false));
  59868. getKeyPos (rangeEnd, x, w);
  59869. x += w;
  59870. if (orientation == verticalKeyboardFacingLeft)
  59871. g.fillRect (getWidth() - 5, 0, 5, x);
  59872. else if (orientation == verticalKeyboardFacingRight)
  59873. g.fillRect (0, 0, 5, x);
  59874. else
  59875. g.fillRect (0, 0, x, 5);
  59876. g.setColour (lineColour);
  59877. if (orientation == verticalKeyboardFacingLeft)
  59878. g.fillRect (0, 0, 1, x);
  59879. else if (orientation == verticalKeyboardFacingRight)
  59880. g.fillRect (getWidth() - 1, 0, 1, x);
  59881. else
  59882. g.fillRect (0, getHeight() - 1, x, 1);
  59883. const Colour blackNoteColour (findColour (blackNoteColourId));
  59884. for (octave = 0; octave < 128; octave += 12)
  59885. {
  59886. for (int black = 0; black < 5; ++black)
  59887. {
  59888. const int noteNum = octave + blackNotes [black];
  59889. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  59890. {
  59891. getKeyPos (noteNum, x, w);
  59892. if (orientation == horizontalKeyboard)
  59893. drawBlackNote (noteNum, g, x, 0, w, blackNoteLength,
  59894. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59895. noteUnderMouse == noteNum,
  59896. blackNoteColour);
  59897. else if (orientation == verticalKeyboardFacingLeft)
  59898. drawBlackNote (noteNum, g, getWidth() - blackNoteLength, x, blackNoteLength, w,
  59899. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59900. noteUnderMouse == noteNum,
  59901. blackNoteColour);
  59902. else if (orientation == verticalKeyboardFacingRight)
  59903. drawBlackNote (noteNum, g, 0, getHeight() - x - w, blackNoteLength, w,
  59904. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59905. noteUnderMouse == noteNum,
  59906. blackNoteColour);
  59907. }
  59908. }
  59909. }
  59910. }
  59911. void MidiKeyboardComponent::drawWhiteNote (int midiNoteNumber,
  59912. Graphics& g, int x, int y, int w, int h,
  59913. bool isDown, bool isOver,
  59914. const Colour& lineColour,
  59915. const Colour& textColour)
  59916. {
  59917. Colour c (Colours::transparentWhite);
  59918. if (isDown)
  59919. c = findColour (keyDownOverlayColourId);
  59920. if (isOver)
  59921. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  59922. g.setColour (c);
  59923. g.fillRect (x, y, w, h);
  59924. const String text (getWhiteNoteText (midiNoteNumber));
  59925. if (! text.isEmpty())
  59926. {
  59927. g.setColour (textColour);
  59928. Font f (jmin (12.0f, keyWidth * 0.9f));
  59929. f.setHorizontalScale (0.8f);
  59930. g.setFont (f);
  59931. Justification justification (Justification::centredBottom);
  59932. if (orientation == verticalKeyboardFacingLeft)
  59933. justification = Justification::centredLeft;
  59934. else if (orientation == verticalKeyboardFacingRight)
  59935. justification = Justification::centredRight;
  59936. g.drawFittedText (text, x + 2, y + 2, w - 4, h - 4, justification, 1);
  59937. }
  59938. g.setColour (lineColour);
  59939. if (orientation == horizontalKeyboard)
  59940. g.fillRect (x, y, 1, h);
  59941. else if (orientation == verticalKeyboardFacingLeft)
  59942. g.fillRect (x, y, w, 1);
  59943. else if (orientation == verticalKeyboardFacingRight)
  59944. g.fillRect (x, y + h - 1, w, 1);
  59945. if (midiNoteNumber == rangeEnd)
  59946. {
  59947. if (orientation == horizontalKeyboard)
  59948. g.fillRect (x + w, y, 1, h);
  59949. else if (orientation == verticalKeyboardFacingLeft)
  59950. g.fillRect (x, y + h, w, 1);
  59951. else if (orientation == verticalKeyboardFacingRight)
  59952. g.fillRect (x, y - 1, w, 1);
  59953. }
  59954. }
  59955. void MidiKeyboardComponent::drawBlackNote (int /*midiNoteNumber*/,
  59956. Graphics& g, int x, int y, int w, int h,
  59957. bool isDown, bool isOver,
  59958. const Colour& noteFillColour)
  59959. {
  59960. Colour c (noteFillColour);
  59961. if (isDown)
  59962. c = c.overlaidWith (findColour (keyDownOverlayColourId));
  59963. if (isOver)
  59964. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  59965. g.setColour (c);
  59966. g.fillRect (x, y, w, h);
  59967. if (isDown)
  59968. {
  59969. g.setColour (noteFillColour);
  59970. g.drawRect (x, y, w, h);
  59971. }
  59972. else
  59973. {
  59974. const int xIndent = jmax (1, jmin (w, h) / 8);
  59975. g.setColour (c.brighter());
  59976. if (orientation == horizontalKeyboard)
  59977. g.fillRect (x + xIndent, y, w - xIndent * 2, 7 * h / 8);
  59978. else if (orientation == verticalKeyboardFacingLeft)
  59979. g.fillRect (x + w / 8, y + xIndent, w - w / 8, h - xIndent * 2);
  59980. else if (orientation == verticalKeyboardFacingRight)
  59981. g.fillRect (x, y + xIndent, 7 * w / 8, h - xIndent * 2);
  59982. }
  59983. }
  59984. void MidiKeyboardComponent::setOctaveForMiddleC (const int octaveNumForMiddleC_) throw()
  59985. {
  59986. octaveNumForMiddleC = octaveNumForMiddleC_;
  59987. repaint();
  59988. }
  59989. const String MidiKeyboardComponent::getWhiteNoteText (const int midiNoteNumber)
  59990. {
  59991. if (keyWidth > 14.0f && midiNoteNumber % 12 == 0)
  59992. return MidiMessage::getMidiNoteName (midiNoteNumber, true, true, octaveNumForMiddleC);
  59993. return String::empty;
  59994. }
  59995. void MidiKeyboardComponent::drawUpDownButton (Graphics& g, int w, int h,
  59996. const bool isMouseOver,
  59997. const bool isButtonDown,
  59998. const bool movesOctavesUp)
  59999. {
  60000. g.fillAll (findColour (upDownButtonBackgroundColourId));
  60001. float angle;
  60002. if (orientation == MidiKeyboardComponent::horizontalKeyboard)
  60003. angle = movesOctavesUp ? 0.0f : 0.5f;
  60004. else if (orientation == MidiKeyboardComponent::verticalKeyboardFacingLeft)
  60005. angle = movesOctavesUp ? 0.25f : 0.75f;
  60006. else
  60007. angle = movesOctavesUp ? 0.75f : 0.25f;
  60008. Path path;
  60009. path.lineTo (0.0f, 1.0f);
  60010. path.lineTo (1.0f, 0.5f);
  60011. path.closeSubPath();
  60012. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * angle, 0.5f, 0.5f));
  60013. g.setColour (findColour (upDownButtonArrowColourId)
  60014. .withAlpha (isButtonDown ? 1.0f : (isMouseOver ? 0.6f : 0.4f)));
  60015. g.fillPath (path, path.getTransformToScaleToFit (1.0f, 1.0f,
  60016. w - 2.0f,
  60017. h - 2.0f,
  60018. true));
  60019. }
  60020. void MidiKeyboardComponent::resized()
  60021. {
  60022. int w = getWidth();
  60023. int h = getHeight();
  60024. if (w > 0 && h > 0)
  60025. {
  60026. if (orientation != horizontalKeyboard)
  60027. swapVariables (w, h);
  60028. blackNoteLength = roundToInt (h * 0.7f);
  60029. int kx2, kw2;
  60030. getKeyPos (rangeEnd, kx2, kw2);
  60031. kx2 += kw2;
  60032. if (firstKey != rangeStart)
  60033. {
  60034. int kx1, kw1;
  60035. getKeyPos (rangeStart, kx1, kw1);
  60036. if (kx2 - kx1 <= w)
  60037. {
  60038. firstKey = rangeStart;
  60039. sendChangeMessage (this);
  60040. repaint();
  60041. }
  60042. }
  60043. const bool showScrollButtons = canScroll && (firstKey > rangeStart || kx2 > w + xOffset * 2);
  60044. scrollDown->setVisible (showScrollButtons);
  60045. scrollUp->setVisible (showScrollButtons);
  60046. xOffset = 0;
  60047. if (showScrollButtons)
  60048. {
  60049. const int scrollButtonW = jmin (12, w / 2);
  60050. if (orientation == horizontalKeyboard)
  60051. {
  60052. scrollDown->setBounds (0, 0, scrollButtonW, getHeight());
  60053. scrollUp->setBounds (getWidth() - scrollButtonW, 0, scrollButtonW, getHeight());
  60054. }
  60055. else if (orientation == verticalKeyboardFacingLeft)
  60056. {
  60057. scrollDown->setBounds (0, 0, getWidth(), scrollButtonW);
  60058. scrollUp->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60059. }
  60060. else if (orientation == verticalKeyboardFacingRight)
  60061. {
  60062. scrollDown->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60063. scrollUp->setBounds (0, 0, getWidth(), scrollButtonW);
  60064. }
  60065. int endOfLastKey, kw;
  60066. getKeyPos (rangeEnd, endOfLastKey, kw);
  60067. endOfLastKey += kw;
  60068. float mousePositionVelocity;
  60069. const int spaceAvailable = w - scrollButtonW * 2;
  60070. const int lastStartKey = remappedXYToNote (Point<int> (endOfLastKey - spaceAvailable, 0), mousePositionVelocity) + 1;
  60071. if (lastStartKey >= 0 && firstKey > lastStartKey)
  60072. {
  60073. firstKey = jlimit (rangeStart, rangeEnd, lastStartKey);
  60074. sendChangeMessage (this);
  60075. }
  60076. int newOffset = 0;
  60077. getKeyPos (firstKey, newOffset, kw);
  60078. xOffset = newOffset - scrollButtonW;
  60079. }
  60080. else
  60081. {
  60082. firstKey = rangeStart;
  60083. }
  60084. timerCallback();
  60085. repaint();
  60086. }
  60087. }
  60088. void MidiKeyboardComponent::handleNoteOn (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/, float /*velocity*/)
  60089. {
  60090. triggerAsyncUpdate();
  60091. }
  60092. void MidiKeyboardComponent::handleNoteOff (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/)
  60093. {
  60094. triggerAsyncUpdate();
  60095. }
  60096. void MidiKeyboardComponent::handleAsyncUpdate()
  60097. {
  60098. for (int i = rangeStart; i <= rangeEnd; ++i)
  60099. {
  60100. if (keysCurrentlyDrawnDown[i] != state.isNoteOnForChannels (midiInChannelMask, i))
  60101. {
  60102. keysCurrentlyDrawnDown.setBit (i, state.isNoteOnForChannels (midiInChannelMask, i));
  60103. repaintNote (i);
  60104. }
  60105. }
  60106. }
  60107. void MidiKeyboardComponent::resetAnyKeysInUse()
  60108. {
  60109. if (keysPressed.countNumberOfSetBits() > 0 || mouseDownNote > 0)
  60110. {
  60111. state.allNotesOff (midiChannel);
  60112. keysPressed.clear();
  60113. mouseDownNote = -1;
  60114. }
  60115. }
  60116. void MidiKeyboardComponent::updateNoteUnderMouse (const Point<int>& pos)
  60117. {
  60118. float mousePositionVelocity = 0.0f;
  60119. const int newNote = (mouseDragging || isMouseOver())
  60120. ? xyToNote (pos, mousePositionVelocity) : -1;
  60121. if (noteUnderMouse != newNote)
  60122. {
  60123. if (mouseDownNote >= 0)
  60124. {
  60125. state.noteOff (midiChannel, mouseDownNote);
  60126. mouseDownNote = -1;
  60127. }
  60128. if (mouseDragging && newNote >= 0)
  60129. {
  60130. if (! useMousePositionForVelocity)
  60131. mousePositionVelocity = 1.0f;
  60132. state.noteOn (midiChannel, newNote, mousePositionVelocity * velocity);
  60133. mouseDownNote = newNote;
  60134. }
  60135. repaintNote (noteUnderMouse);
  60136. noteUnderMouse = newNote;
  60137. repaintNote (noteUnderMouse);
  60138. }
  60139. else if (mouseDownNote >= 0 && ! mouseDragging)
  60140. {
  60141. state.noteOff (midiChannel, mouseDownNote);
  60142. mouseDownNote = -1;
  60143. }
  60144. }
  60145. void MidiKeyboardComponent::mouseMove (const MouseEvent& e)
  60146. {
  60147. updateNoteUnderMouse (e.getPosition());
  60148. stopTimer();
  60149. }
  60150. void MidiKeyboardComponent::mouseDrag (const MouseEvent& e)
  60151. {
  60152. float mousePositionVelocity;
  60153. const int newNote = xyToNote (e.getPosition(), mousePositionVelocity);
  60154. if (newNote >= 0)
  60155. mouseDraggedToKey (newNote, e);
  60156. updateNoteUnderMouse (e.getPosition());
  60157. }
  60158. bool MidiKeyboardComponent::mouseDownOnKey (int /*midiNoteNumber*/, const MouseEvent&)
  60159. {
  60160. return true;
  60161. }
  60162. void MidiKeyboardComponent::mouseDraggedToKey (int /*midiNoteNumber*/, const MouseEvent&)
  60163. {
  60164. }
  60165. void MidiKeyboardComponent::mouseDown (const MouseEvent& e)
  60166. {
  60167. float mousePositionVelocity;
  60168. const int newNote = xyToNote (e.getPosition(), mousePositionVelocity);
  60169. mouseDragging = false;
  60170. if (newNote >= 0 && mouseDownOnKey (newNote, e))
  60171. {
  60172. repaintNote (noteUnderMouse);
  60173. noteUnderMouse = -1;
  60174. mouseDragging = true;
  60175. updateNoteUnderMouse (e.getPosition());
  60176. startTimer (500);
  60177. }
  60178. }
  60179. void MidiKeyboardComponent::mouseUp (const MouseEvent& e)
  60180. {
  60181. mouseDragging = false;
  60182. updateNoteUnderMouse (e.getPosition());
  60183. stopTimer();
  60184. }
  60185. void MidiKeyboardComponent::mouseEnter (const MouseEvent& e)
  60186. {
  60187. updateNoteUnderMouse (e.getPosition());
  60188. }
  60189. void MidiKeyboardComponent::mouseExit (const MouseEvent& e)
  60190. {
  60191. updateNoteUnderMouse (e.getPosition());
  60192. }
  60193. void MidiKeyboardComponent::mouseWheelMove (const MouseEvent&, float ix, float iy)
  60194. {
  60195. setLowestVisibleKey (getLowestVisibleKey() + roundToInt ((ix != 0 ? ix : iy) * 5.0f));
  60196. }
  60197. void MidiKeyboardComponent::timerCallback()
  60198. {
  60199. updateNoteUnderMouse (getMouseXYRelative());
  60200. }
  60201. void MidiKeyboardComponent::clearKeyMappings()
  60202. {
  60203. resetAnyKeysInUse();
  60204. keyPressNotes.clear();
  60205. keyPresses.clear();
  60206. }
  60207. void MidiKeyboardComponent::setKeyPressForNote (const KeyPress& key,
  60208. const int midiNoteOffsetFromC)
  60209. {
  60210. removeKeyPressForNote (midiNoteOffsetFromC);
  60211. keyPressNotes.add (midiNoteOffsetFromC);
  60212. keyPresses.add (key);
  60213. }
  60214. void MidiKeyboardComponent::removeKeyPressForNote (const int midiNoteOffsetFromC)
  60215. {
  60216. for (int i = keyPressNotes.size(); --i >= 0;)
  60217. {
  60218. if (keyPressNotes.getUnchecked (i) == midiNoteOffsetFromC)
  60219. {
  60220. keyPressNotes.remove (i);
  60221. keyPresses.remove (i);
  60222. }
  60223. }
  60224. }
  60225. void MidiKeyboardComponent::setKeyPressBaseOctave (const int newOctaveNumber)
  60226. {
  60227. jassert (newOctaveNumber >= 0 && newOctaveNumber <= 10);
  60228. keyMappingOctave = newOctaveNumber;
  60229. }
  60230. bool MidiKeyboardComponent::keyStateChanged (const bool /*isKeyDown*/)
  60231. {
  60232. bool keyPressUsed = false;
  60233. for (int i = keyPresses.size(); --i >= 0;)
  60234. {
  60235. const int note = 12 * keyMappingOctave + keyPressNotes.getUnchecked (i);
  60236. if (keyPresses.getReference(i).isCurrentlyDown())
  60237. {
  60238. if (! keysPressed [note])
  60239. {
  60240. keysPressed.setBit (note);
  60241. state.noteOn (midiChannel, note, velocity);
  60242. keyPressUsed = true;
  60243. }
  60244. }
  60245. else
  60246. {
  60247. if (keysPressed [note])
  60248. {
  60249. keysPressed.clearBit (note);
  60250. state.noteOff (midiChannel, note);
  60251. keyPressUsed = true;
  60252. }
  60253. }
  60254. }
  60255. return keyPressUsed;
  60256. }
  60257. void MidiKeyboardComponent::focusLost (FocusChangeType)
  60258. {
  60259. resetAnyKeysInUse();
  60260. }
  60261. END_JUCE_NAMESPACE
  60262. /*** End of inlined file: juce_MidiKeyboardComponent.cpp ***/
  60263. /*** Start of inlined file: juce_OpenGLComponent.cpp ***/
  60264. #if JUCE_OPENGL
  60265. BEGIN_JUCE_NAMESPACE
  60266. extern void juce_glViewport (const int w, const int h);
  60267. OpenGLPixelFormat::OpenGLPixelFormat (const int bitsPerRGBComponent,
  60268. const int alphaBits_,
  60269. const int depthBufferBits_,
  60270. const int stencilBufferBits_)
  60271. : redBits (bitsPerRGBComponent),
  60272. greenBits (bitsPerRGBComponent),
  60273. blueBits (bitsPerRGBComponent),
  60274. alphaBits (alphaBits_),
  60275. depthBufferBits (depthBufferBits_),
  60276. stencilBufferBits (stencilBufferBits_),
  60277. accumulationBufferRedBits (0),
  60278. accumulationBufferGreenBits (0),
  60279. accumulationBufferBlueBits (0),
  60280. accumulationBufferAlphaBits (0),
  60281. fullSceneAntiAliasingNumSamples (0)
  60282. {
  60283. }
  60284. OpenGLPixelFormat::OpenGLPixelFormat (const OpenGLPixelFormat& other)
  60285. : redBits (other.redBits),
  60286. greenBits (other.greenBits),
  60287. blueBits (other.blueBits),
  60288. alphaBits (other.alphaBits),
  60289. depthBufferBits (other.depthBufferBits),
  60290. stencilBufferBits (other.stencilBufferBits),
  60291. accumulationBufferRedBits (other.accumulationBufferRedBits),
  60292. accumulationBufferGreenBits (other.accumulationBufferGreenBits),
  60293. accumulationBufferBlueBits (other.accumulationBufferBlueBits),
  60294. accumulationBufferAlphaBits (other.accumulationBufferAlphaBits),
  60295. fullSceneAntiAliasingNumSamples (other.fullSceneAntiAliasingNumSamples)
  60296. {
  60297. }
  60298. OpenGLPixelFormat& OpenGLPixelFormat::operator= (const OpenGLPixelFormat& other)
  60299. {
  60300. redBits = other.redBits;
  60301. greenBits = other.greenBits;
  60302. blueBits = other.blueBits;
  60303. alphaBits = other.alphaBits;
  60304. depthBufferBits = other.depthBufferBits;
  60305. stencilBufferBits = other.stencilBufferBits;
  60306. accumulationBufferRedBits = other.accumulationBufferRedBits;
  60307. accumulationBufferGreenBits = other.accumulationBufferGreenBits;
  60308. accumulationBufferBlueBits = other.accumulationBufferBlueBits;
  60309. accumulationBufferAlphaBits = other.accumulationBufferAlphaBits;
  60310. fullSceneAntiAliasingNumSamples = other.fullSceneAntiAliasingNumSamples;
  60311. return *this;
  60312. }
  60313. bool OpenGLPixelFormat::operator== (const OpenGLPixelFormat& other) const
  60314. {
  60315. return redBits == other.redBits
  60316. && greenBits == other.greenBits
  60317. && blueBits == other.blueBits
  60318. && alphaBits == other.alphaBits
  60319. && depthBufferBits == other.depthBufferBits
  60320. && stencilBufferBits == other.stencilBufferBits
  60321. && accumulationBufferRedBits == other.accumulationBufferRedBits
  60322. && accumulationBufferGreenBits == other.accumulationBufferGreenBits
  60323. && accumulationBufferBlueBits == other.accumulationBufferBlueBits
  60324. && accumulationBufferAlphaBits == other.accumulationBufferAlphaBits
  60325. && fullSceneAntiAliasingNumSamples == other.fullSceneAntiAliasingNumSamples;
  60326. }
  60327. static VoidArray knownContexts;
  60328. OpenGLContext::OpenGLContext() throw()
  60329. {
  60330. knownContexts.add (this);
  60331. }
  60332. OpenGLContext::~OpenGLContext()
  60333. {
  60334. knownContexts.removeValue (this);
  60335. }
  60336. OpenGLContext* OpenGLContext::getCurrentContext()
  60337. {
  60338. for (int i = knownContexts.size(); --i >= 0;)
  60339. {
  60340. OpenGLContext* const oglc = (OpenGLContext*) knownContexts.getUnchecked(i);
  60341. if (oglc->isActive())
  60342. return oglc;
  60343. }
  60344. return 0;
  60345. }
  60346. class OpenGLComponent::OpenGLComponentWatcher : public ComponentMovementWatcher
  60347. {
  60348. public:
  60349. OpenGLComponentWatcher (OpenGLComponent* const owner_)
  60350. : ComponentMovementWatcher (owner_),
  60351. owner (owner_),
  60352. wasShowing (false)
  60353. {
  60354. }
  60355. ~OpenGLComponentWatcher() {}
  60356. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  60357. {
  60358. owner->updateContextPosition();
  60359. }
  60360. void componentPeerChanged()
  60361. {
  60362. const ScopedLock sl (owner->getContextLock());
  60363. owner->deleteContext();
  60364. }
  60365. void componentVisibilityChanged (Component&)
  60366. {
  60367. const bool isShowingNow = owner->isShowing();
  60368. if (wasShowing != isShowingNow)
  60369. {
  60370. wasShowing = isShowingNow;
  60371. owner->updateContextPosition();
  60372. }
  60373. }
  60374. juce_UseDebuggingNewOperator
  60375. private:
  60376. OpenGLComponent* const owner;
  60377. bool wasShowing;
  60378. };
  60379. OpenGLComponent::OpenGLComponent (const OpenGLType type_)
  60380. : type (type_),
  60381. contextToShareListsWith (0),
  60382. needToUpdateViewport (true)
  60383. {
  60384. setOpaque (true);
  60385. componentWatcher = new OpenGLComponentWatcher (this);
  60386. }
  60387. OpenGLComponent::~OpenGLComponent()
  60388. {
  60389. deleteContext();
  60390. componentWatcher = 0;
  60391. }
  60392. void OpenGLComponent::deleteContext()
  60393. {
  60394. const ScopedLock sl (contextLock);
  60395. context = 0;
  60396. }
  60397. void OpenGLComponent::updateContextPosition()
  60398. {
  60399. needToUpdateViewport = true;
  60400. if (getWidth() > 0 && getHeight() > 0)
  60401. {
  60402. Component* const topComp = getTopLevelComponent();
  60403. if (topComp->getPeer() != 0)
  60404. {
  60405. const ScopedLock sl (contextLock);
  60406. if (context != 0)
  60407. context->updateWindowPosition (getScreenX() - topComp->getScreenX(),
  60408. getScreenY() - topComp->getScreenY(),
  60409. getWidth(),
  60410. getHeight(),
  60411. topComp->getHeight());
  60412. }
  60413. }
  60414. }
  60415. const OpenGLPixelFormat OpenGLComponent::getPixelFormat() const
  60416. {
  60417. OpenGLPixelFormat pf;
  60418. const ScopedLock sl (contextLock);
  60419. if (context != 0)
  60420. pf = context->getPixelFormat();
  60421. return pf;
  60422. }
  60423. void OpenGLComponent::setPixelFormat (const OpenGLPixelFormat& formatToUse)
  60424. {
  60425. if (! (preferredPixelFormat == formatToUse))
  60426. {
  60427. const ScopedLock sl (contextLock);
  60428. deleteContext();
  60429. preferredPixelFormat = formatToUse;
  60430. }
  60431. }
  60432. void OpenGLComponent::shareWith (OpenGLContext* c)
  60433. {
  60434. if (contextToShareListsWith != c)
  60435. {
  60436. const ScopedLock sl (contextLock);
  60437. deleteContext();
  60438. contextToShareListsWith = c;
  60439. }
  60440. }
  60441. bool OpenGLComponent::makeCurrentContextActive()
  60442. {
  60443. if (context == 0)
  60444. {
  60445. const ScopedLock sl (contextLock);
  60446. if (isShowing() && getTopLevelComponent()->getPeer() != 0)
  60447. {
  60448. context = createContext();
  60449. if (context != 0)
  60450. {
  60451. updateContextPosition();
  60452. if (context->makeActive())
  60453. newOpenGLContextCreated();
  60454. }
  60455. }
  60456. }
  60457. return context != 0 && context->makeActive();
  60458. }
  60459. void OpenGLComponent::makeCurrentContextInactive()
  60460. {
  60461. if (context != 0)
  60462. context->makeInactive();
  60463. }
  60464. bool OpenGLComponent::isActiveContext() const throw()
  60465. {
  60466. return context != 0 && context->isActive();
  60467. }
  60468. void OpenGLComponent::swapBuffers()
  60469. {
  60470. if (context != 0)
  60471. context->swapBuffers();
  60472. }
  60473. void OpenGLComponent::paint (Graphics&)
  60474. {
  60475. if (renderAndSwapBuffers())
  60476. {
  60477. ComponentPeer* const peer = getPeer();
  60478. if (peer != 0)
  60479. {
  60480. const Point<int> topLeft (getScreenPosition() - peer->getScreenPosition());
  60481. peer->addMaskedRegion (topLeft.getX(), topLeft.getY(), getWidth(), getHeight());
  60482. }
  60483. }
  60484. }
  60485. bool OpenGLComponent::renderAndSwapBuffers()
  60486. {
  60487. const ScopedLock sl (contextLock);
  60488. if (! makeCurrentContextActive())
  60489. return false;
  60490. if (needToUpdateViewport)
  60491. {
  60492. needToUpdateViewport = false;
  60493. juce_glViewport (getWidth(), getHeight());
  60494. }
  60495. renderOpenGL();
  60496. swapBuffers();
  60497. return true;
  60498. }
  60499. void OpenGLComponent::internalRepaint (int x, int y, int w, int h)
  60500. {
  60501. Component::internalRepaint (x, y, w, h);
  60502. if (context != 0)
  60503. context->repaint();
  60504. }
  60505. END_JUCE_NAMESPACE
  60506. #endif
  60507. /*** End of inlined file: juce_OpenGLComponent.cpp ***/
  60508. /*** Start of inlined file: juce_PreferencesPanel.cpp ***/
  60509. BEGIN_JUCE_NAMESPACE
  60510. PreferencesPanel::PreferencesPanel()
  60511. : buttonSize (70)
  60512. {
  60513. }
  60514. PreferencesPanel::~PreferencesPanel()
  60515. {
  60516. currentPage = 0;
  60517. deleteAllChildren();
  60518. }
  60519. void PreferencesPanel::addSettingsPage (const String& title,
  60520. const Drawable* icon,
  60521. const Drawable* overIcon,
  60522. const Drawable* downIcon)
  60523. {
  60524. DrawableButton* button = new DrawableButton (title, DrawableButton::ImageAboveTextLabel);
  60525. button->setImages (icon, overIcon, downIcon);
  60526. button->setRadioGroupId (1);
  60527. button->addButtonListener (this);
  60528. button->setClickingTogglesState (true);
  60529. button->setWantsKeyboardFocus (false);
  60530. addAndMakeVisible (button);
  60531. resized();
  60532. if (currentPage == 0)
  60533. setCurrentPage (title);
  60534. }
  60535. void PreferencesPanel::addSettingsPage (const String& title,
  60536. const char* imageData,
  60537. const int imageDataSize)
  60538. {
  60539. DrawableImage icon, iconOver, iconDown;
  60540. icon.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60541. iconOver.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60542. iconOver.setOverlayColour (Colours::black.withAlpha (0.12f));
  60543. iconDown.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60544. iconDown.setOverlayColour (Colours::black.withAlpha (0.25f));
  60545. addSettingsPage (title, &icon, &iconOver, &iconDown);
  60546. }
  60547. class PrefsDialogWindow : public DialogWindow
  60548. {
  60549. public:
  60550. PrefsDialogWindow (const String& dialogtitle,
  60551. const Colour& backgroundColour)
  60552. : DialogWindow (dialogtitle, backgroundColour, true)
  60553. {
  60554. }
  60555. ~PrefsDialogWindow()
  60556. {
  60557. }
  60558. void closeButtonPressed()
  60559. {
  60560. exitModalState (0);
  60561. }
  60562. private:
  60563. PrefsDialogWindow (const PrefsDialogWindow&);
  60564. PrefsDialogWindow& operator= (const PrefsDialogWindow&);
  60565. };
  60566. void PreferencesPanel::showInDialogBox (const String& dialogtitle,
  60567. int dialogWidth,
  60568. int dialogHeight,
  60569. const Colour& backgroundColour)
  60570. {
  60571. setSize (dialogWidth, dialogHeight);
  60572. PrefsDialogWindow dw (dialogtitle, backgroundColour);
  60573. dw.setContentComponent (this, true, true);
  60574. dw.centreAroundComponent (0, dw.getWidth(), dw.getHeight());
  60575. dw.runModalLoop();
  60576. dw.setContentComponent (0, false, false);
  60577. }
  60578. void PreferencesPanel::resized()
  60579. {
  60580. int x = 0;
  60581. for (int i = 0; i < getNumChildComponents(); ++i)
  60582. {
  60583. Component* c = getChildComponent (i);
  60584. if (dynamic_cast <DrawableButton*> (c) == 0)
  60585. {
  60586. c->setBounds (0, buttonSize + 5, getWidth(), getHeight() - buttonSize - 5);
  60587. }
  60588. else
  60589. {
  60590. c->setBounds (x, 0, buttonSize, buttonSize);
  60591. x += buttonSize;
  60592. }
  60593. }
  60594. }
  60595. void PreferencesPanel::paint (Graphics& g)
  60596. {
  60597. g.setColour (Colours::grey);
  60598. g.fillRect (0, buttonSize + 2, getWidth(), 1);
  60599. }
  60600. void PreferencesPanel::setCurrentPage (const String& pageName)
  60601. {
  60602. if (currentPageName != pageName)
  60603. {
  60604. currentPageName = pageName;
  60605. currentPage = 0;
  60606. currentPage = createComponentForPage (pageName);
  60607. if (currentPage != 0)
  60608. {
  60609. addAndMakeVisible (currentPage);
  60610. currentPage->toBack();
  60611. resized();
  60612. }
  60613. for (int i = 0; i < getNumChildComponents(); ++i)
  60614. {
  60615. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60616. if (db != 0 && db->getName() == pageName)
  60617. {
  60618. db->setToggleState (true, false);
  60619. break;
  60620. }
  60621. }
  60622. }
  60623. }
  60624. void PreferencesPanel::buttonClicked (Button*)
  60625. {
  60626. for (int i = 0; i < getNumChildComponents(); ++i)
  60627. {
  60628. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60629. if (db != 0 && db->getToggleState())
  60630. {
  60631. setCurrentPage (db->getName());
  60632. break;
  60633. }
  60634. }
  60635. }
  60636. END_JUCE_NAMESPACE
  60637. /*** End of inlined file: juce_PreferencesPanel.cpp ***/
  60638. /*** Start of inlined file: juce_SystemTrayIconComponent.cpp ***/
  60639. #if JUCE_WINDOWS || JUCE_LINUX
  60640. BEGIN_JUCE_NAMESPACE
  60641. SystemTrayIconComponent::SystemTrayIconComponent()
  60642. {
  60643. addToDesktop (0);
  60644. }
  60645. SystemTrayIconComponent::~SystemTrayIconComponent()
  60646. {
  60647. }
  60648. END_JUCE_NAMESPACE
  60649. #endif
  60650. /*** End of inlined file: juce_SystemTrayIconComponent.cpp ***/
  60651. /*** Start of inlined file: juce_AlertWindow.cpp ***/
  60652. BEGIN_JUCE_NAMESPACE
  60653. static const int titleH = 24;
  60654. static const int iconWidth = 80;
  60655. class AlertWindowTextEditor : public TextEditor
  60656. {
  60657. public:
  60658. static const tchar passwordChar;
  60659. AlertWindowTextEditor (const String& name, const bool isPasswordBox)
  60660. : TextEditor (name, isPasswordBox ? passwordChar : 0)
  60661. {
  60662. setSelectAllWhenFocused (true);
  60663. }
  60664. ~AlertWindowTextEditor()
  60665. {
  60666. }
  60667. void returnPressed()
  60668. {
  60669. // pass these up the component hierarchy to be trigger the buttons
  60670. getParentComponent()->keyPressed (KeyPress (KeyPress::returnKey, 0, '\n'));
  60671. }
  60672. void escapePressed()
  60673. {
  60674. // pass these up the component hierarchy to be trigger the buttons
  60675. getParentComponent()->keyPressed (KeyPress (KeyPress::escapeKey, 0, 0));
  60676. }
  60677. private:
  60678. AlertWindowTextEditor (const AlertWindowTextEditor&);
  60679. AlertWindowTextEditor& operator= (const AlertWindowTextEditor&);
  60680. };
  60681. #if JUCE_LINUX
  60682. const tchar AlertWindowTextEditor::passwordChar = 0x2022;
  60683. #else
  60684. const tchar AlertWindowTextEditor::passwordChar = 0x25cf;
  60685. #endif
  60686. AlertWindow::AlertWindow (const String& title,
  60687. const String& message,
  60688. AlertIconType iconType,
  60689. Component* associatedComponent_)
  60690. : TopLevelWindow (title, true),
  60691. alertIconType (iconType),
  60692. associatedComponent (associatedComponent_)
  60693. {
  60694. if (message.isEmpty())
  60695. text = " "; // to force an update if the message is empty
  60696. setMessage (message);
  60697. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  60698. {
  60699. Component* const c = Desktop::getInstance().getComponent (i);
  60700. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  60701. {
  60702. setAlwaysOnTop (true);
  60703. break;
  60704. }
  60705. }
  60706. if (JUCEApplication::getInstance() == 0)
  60707. setAlwaysOnTop (true); // for a plugin, make it always-on-top because the host windows are often top-level
  60708. lookAndFeelChanged();
  60709. constrainer.setMinimumOnscreenAmounts (0x10000, 0x10000, 0x10000, 0x10000);
  60710. }
  60711. AlertWindow::~AlertWindow()
  60712. {
  60713. for (int i = customComps.size(); --i >= 0;)
  60714. removeChildComponent ((Component*) customComps[i]);
  60715. deleteAllChildren();
  60716. }
  60717. void AlertWindow::userTriedToCloseWindow()
  60718. {
  60719. exitModalState (0);
  60720. }
  60721. void AlertWindow::setMessage (const String& message)
  60722. {
  60723. const String newMessage (message.substring (0, 2048));
  60724. if (text != newMessage)
  60725. {
  60726. text = newMessage;
  60727. font.setHeight (15.0f);
  60728. Font titleFont (font.getHeight() * 1.1f, Font::bold);
  60729. textLayout.setText (getName() + "\n\n", titleFont);
  60730. textLayout.appendText (text, font);
  60731. updateLayout (true);
  60732. repaint();
  60733. }
  60734. }
  60735. void AlertWindow::buttonClicked (Button* button)
  60736. {
  60737. for (int i = 0; i < buttons.size(); i++)
  60738. {
  60739. TextButton* const c = (TextButton*) buttons[i];
  60740. if (button->getName() == c->getName())
  60741. {
  60742. if (c->getParentComponent() != 0)
  60743. c->getParentComponent()->exitModalState (c->getCommandID());
  60744. break;
  60745. }
  60746. }
  60747. }
  60748. void AlertWindow::addButton (const String& name,
  60749. const int returnValue,
  60750. const KeyPress& shortcutKey1,
  60751. const KeyPress& shortcutKey2)
  60752. {
  60753. TextButton* const b = new TextButton (name, String::empty);
  60754. b->setWantsKeyboardFocus (true);
  60755. b->setMouseClickGrabsKeyboardFocus (false);
  60756. b->setCommandToTrigger (0, returnValue, false);
  60757. b->addShortcut (shortcutKey1);
  60758. b->addShortcut (shortcutKey2);
  60759. b->addButtonListener (this);
  60760. b->changeWidthToFitText (getLookAndFeel().getAlertWindowButtonHeight());
  60761. addAndMakeVisible (b, 0);
  60762. buttons.add (b);
  60763. updateLayout (false);
  60764. }
  60765. int AlertWindow::getNumButtons() const
  60766. {
  60767. return buttons.size();
  60768. }
  60769. void AlertWindow::addTextEditor (const String& name,
  60770. const String& initialContents,
  60771. const String& onScreenLabel,
  60772. const bool isPasswordBox)
  60773. {
  60774. AlertWindowTextEditor* const tc = new AlertWindowTextEditor (name, isPasswordBox);
  60775. tc->setColour (TextEditor::outlineColourId, findColour (ComboBox::outlineColourId));
  60776. tc->setFont (font);
  60777. tc->setText (initialContents);
  60778. tc->setCaretPosition (initialContents.length());
  60779. addAndMakeVisible (tc);
  60780. textBoxes.add (tc);
  60781. allComps.add (tc);
  60782. textboxNames.add (onScreenLabel);
  60783. updateLayout (false);
  60784. }
  60785. const String AlertWindow::getTextEditorContents (const String& nameOfTextEditor) const
  60786. {
  60787. for (int i = textBoxes.size(); --i >= 0;)
  60788. if (((TextEditor*)textBoxes[i])->getName() == nameOfTextEditor)
  60789. return ((TextEditor*)textBoxes[i])->getText();
  60790. return String::empty;
  60791. }
  60792. void AlertWindow::addComboBox (const String& name,
  60793. const StringArray& items,
  60794. const String& onScreenLabel)
  60795. {
  60796. ComboBox* const cb = new ComboBox (name);
  60797. for (int i = 0; i < items.size(); ++i)
  60798. cb->addItem (items[i], i + 1);
  60799. addAndMakeVisible (cb);
  60800. cb->setSelectedItemIndex (0);
  60801. comboBoxes.add (cb);
  60802. allComps.add (cb);
  60803. comboBoxNames.add (onScreenLabel);
  60804. updateLayout (false);
  60805. }
  60806. ComboBox* AlertWindow::getComboBoxComponent (const String& nameOfList) const
  60807. {
  60808. for (int i = comboBoxes.size(); --i >= 0;)
  60809. if (((ComboBox*) comboBoxes[i])->getName() == nameOfList)
  60810. return (ComboBox*) comboBoxes[i];
  60811. return 0;
  60812. }
  60813. class AlertTextComp : public TextEditor
  60814. {
  60815. public:
  60816. AlertTextComp (const String& message,
  60817. const Font& font)
  60818. {
  60819. setReadOnly (true);
  60820. setMultiLine (true, true);
  60821. setCaretVisible (false);
  60822. setScrollbarsShown (true);
  60823. lookAndFeelChanged();
  60824. setWantsKeyboardFocus (false);
  60825. setFont (font);
  60826. setText (message, false);
  60827. bestWidth = 2 * (int) sqrt (font.getHeight() * font.getStringWidth (message));
  60828. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  60829. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  60830. setColour (TextEditor::shadowColourId, Colours::transparentBlack);
  60831. }
  60832. ~AlertTextComp()
  60833. {
  60834. }
  60835. int getPreferredWidth() const throw() { return bestWidth; }
  60836. void updateLayout (const int width)
  60837. {
  60838. TextLayout text;
  60839. text.appendText (getText(), getFont());
  60840. text.layout (width - 8, Justification::topLeft, true);
  60841. setSize (width, jmin (width, text.getHeight() + (int) getFont().getHeight()));
  60842. }
  60843. private:
  60844. int bestWidth;
  60845. AlertTextComp (const AlertTextComp&);
  60846. AlertTextComp& operator= (const AlertTextComp&);
  60847. };
  60848. void AlertWindow::addTextBlock (const String& text)
  60849. {
  60850. AlertTextComp* const c = new AlertTextComp (text, font);
  60851. textBlocks.add (c);
  60852. allComps.add (c);
  60853. addAndMakeVisible (c);
  60854. updateLayout (false);
  60855. }
  60856. void AlertWindow::addProgressBarComponent (double& progressValue)
  60857. {
  60858. ProgressBar* const pb = new ProgressBar (progressValue);
  60859. progressBars.add (pb);
  60860. allComps.add (pb);
  60861. addAndMakeVisible (pb);
  60862. updateLayout (false);
  60863. }
  60864. void AlertWindow::addCustomComponent (Component* const component)
  60865. {
  60866. customComps.add (component);
  60867. allComps.add (component);
  60868. addAndMakeVisible (component);
  60869. updateLayout (false);
  60870. }
  60871. int AlertWindow::getNumCustomComponents() const
  60872. {
  60873. return customComps.size();
  60874. }
  60875. Component* AlertWindow::getCustomComponent (const int index) const
  60876. {
  60877. return (Component*) customComps [index];
  60878. }
  60879. Component* AlertWindow::removeCustomComponent (const int index)
  60880. {
  60881. Component* const c = getCustomComponent (index);
  60882. if (c != 0)
  60883. {
  60884. customComps.removeValue (c);
  60885. allComps.removeValue (c);
  60886. removeChildComponent (c);
  60887. updateLayout (false);
  60888. }
  60889. return c;
  60890. }
  60891. void AlertWindow::paint (Graphics& g)
  60892. {
  60893. getLookAndFeel().drawAlertBox (g, *this, textArea, textLayout);
  60894. g.setColour (findColour (textColourId));
  60895. g.setFont (getLookAndFeel().getAlertWindowFont());
  60896. int i;
  60897. for (i = textBoxes.size(); --i >= 0;)
  60898. {
  60899. const TextEditor* const te = (TextEditor*) textBoxes[i];
  60900. g.drawFittedText (textboxNames[i],
  60901. te->getX(), te->getY() - 14,
  60902. te->getWidth(), 14,
  60903. Justification::centredLeft, 1);
  60904. }
  60905. for (i = comboBoxNames.size(); --i >= 0;)
  60906. {
  60907. const ComboBox* const cb = (ComboBox*) comboBoxes[i];
  60908. g.drawFittedText (comboBoxNames[i],
  60909. cb->getX(), cb->getY() - 14,
  60910. cb->getWidth(), 14,
  60911. Justification::centredLeft, 1);
  60912. }
  60913. for (i = customComps.size(); --i >= 0;)
  60914. {
  60915. const Component* const c = (Component*) customComps[i];
  60916. g.drawFittedText (c->getName(),
  60917. c->getX(), c->getY() - 14,
  60918. c->getWidth(), 14,
  60919. Justification::centredLeft, 1);
  60920. }
  60921. }
  60922. void AlertWindow::updateLayout (const bool onlyIncreaseSize)
  60923. {
  60924. const int wid = jmax (font.getStringWidth (text),
  60925. font.getStringWidth (getName()));
  60926. const int sw = (int) sqrt (font.getHeight() * wid);
  60927. int w = jmin (300 + sw * 2, (int) (getParentWidth() * 0.7f));
  60928. const int edgeGap = 10;
  60929. const int labelHeight = 18;
  60930. int iconSpace;
  60931. if (alertIconType == NoIcon)
  60932. {
  60933. textLayout.layout (w, Justification::horizontallyCentred, true);
  60934. iconSpace = 0;
  60935. }
  60936. else
  60937. {
  60938. textLayout.layout (w, Justification::left, true);
  60939. iconSpace = iconWidth;
  60940. }
  60941. w = jmax (350, textLayout.getWidth() + iconSpace + edgeGap * 4);
  60942. w = jmin (w, (int) (getParentWidth() * 0.7f));
  60943. const int textLayoutH = textLayout.getHeight();
  60944. const int textBottom = 16 + titleH + textLayoutH;
  60945. int h = textBottom;
  60946. int buttonW = 40;
  60947. int i;
  60948. for (i = 0; i < buttons.size(); ++i)
  60949. buttonW += 16 + ((const TextButton*) buttons[i])->getWidth();
  60950. w = jmax (buttonW, w);
  60951. h += (textBoxes.size() + comboBoxes.size() + progressBars.size()) * 50;
  60952. if (buttons.size() > 0)
  60953. h += 20 + ((TextButton*) buttons[0])->getHeight();
  60954. for (i = customComps.size(); --i >= 0;)
  60955. {
  60956. Component* c = (Component*) customComps[i];
  60957. w = jmax (w, (c->getWidth() * 100) / 80);
  60958. h += 10 + c->getHeight();
  60959. if (c->getName().isNotEmpty())
  60960. h += labelHeight;
  60961. }
  60962. for (i = textBlocks.size(); --i >= 0;)
  60963. {
  60964. const AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  60965. w = jmax (w, ac->getPreferredWidth());
  60966. }
  60967. w = jmin (w, (int) (getParentWidth() * 0.7f));
  60968. for (i = textBlocks.size(); --i >= 0;)
  60969. {
  60970. AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  60971. ac->updateLayout ((int) (w * 0.8f));
  60972. h += ac->getHeight() + 10;
  60973. }
  60974. h = jmin (getParentHeight() - 50, h);
  60975. if (onlyIncreaseSize)
  60976. {
  60977. w = jmax (w, getWidth());
  60978. h = jmax (h, getHeight());
  60979. }
  60980. if (! isVisible())
  60981. {
  60982. centreAroundComponent (associatedComponent, w, h);
  60983. }
  60984. else
  60985. {
  60986. const int cx = getX() + getWidth() / 2;
  60987. const int cy = getY() + getHeight() / 2;
  60988. setBounds (cx - w / 2,
  60989. cy - h / 2,
  60990. w, h);
  60991. }
  60992. textArea.setBounds (edgeGap, edgeGap, w - (edgeGap * 2), h - edgeGap);
  60993. const int spacer = 16;
  60994. int totalWidth = -spacer;
  60995. for (i = buttons.size(); --i >= 0;)
  60996. totalWidth += ((TextButton*) buttons[i])->getWidth() + spacer;
  60997. int x = (w - totalWidth) / 2;
  60998. int y = (int) (getHeight() * 0.95f);
  60999. for (i = 0; i < buttons.size(); ++i)
  61000. {
  61001. TextButton* const c = (TextButton*) buttons[i];
  61002. int ny = proportionOfHeight (0.95f) - c->getHeight();
  61003. c->setTopLeftPosition (x, ny);
  61004. if (ny < y)
  61005. y = ny;
  61006. x += c->getWidth() + spacer;
  61007. c->toFront (false);
  61008. }
  61009. y = textBottom;
  61010. for (i = 0; i < allComps.size(); ++i)
  61011. {
  61012. Component* const c = (Component*) allComps[i];
  61013. int h = 22;
  61014. const int comboIndex = comboBoxes.indexOf (c);
  61015. if (comboIndex >= 0 && comboBoxNames [comboIndex].isNotEmpty())
  61016. y += labelHeight;
  61017. const int tbIndex = textBoxes.indexOf (c);
  61018. if (tbIndex >= 0 && textboxNames[tbIndex].isNotEmpty())
  61019. y += labelHeight;
  61020. if (customComps.contains (c))
  61021. {
  61022. if (c->getName().isNotEmpty())
  61023. y += labelHeight;
  61024. c->setTopLeftPosition (proportionOfWidth (0.1f), y);
  61025. h = c->getHeight();
  61026. }
  61027. else if (textBlocks.contains (c))
  61028. {
  61029. c->setTopLeftPosition ((getWidth() - c->getWidth()) / 2, y);
  61030. h = c->getHeight();
  61031. }
  61032. else
  61033. {
  61034. c->setBounds (proportionOfWidth (0.1f), y, proportionOfWidth (0.8f), h);
  61035. }
  61036. y += h + 10;
  61037. }
  61038. setWantsKeyboardFocus (getNumChildComponents() == 0);
  61039. }
  61040. bool AlertWindow::containsAnyExtraComponents() const
  61041. {
  61042. return textBoxes.size()
  61043. + comboBoxes.size()
  61044. + progressBars.size()
  61045. + customComps.size() > 0;
  61046. }
  61047. void AlertWindow::mouseDown (const MouseEvent&)
  61048. {
  61049. dragger.startDraggingComponent (this, &constrainer);
  61050. }
  61051. void AlertWindow::mouseDrag (const MouseEvent& e)
  61052. {
  61053. dragger.dragComponent (this, e);
  61054. }
  61055. bool AlertWindow::keyPressed (const KeyPress& key)
  61056. {
  61057. for (int i = buttons.size(); --i >= 0;)
  61058. {
  61059. TextButton* const b = (TextButton*) buttons[i];
  61060. if (b->isRegisteredForShortcut (key))
  61061. {
  61062. b->triggerClick();
  61063. return true;
  61064. }
  61065. }
  61066. if (key.isKeyCode (KeyPress::escapeKey) && buttons.size() == 0)
  61067. {
  61068. exitModalState (0);
  61069. return true;
  61070. }
  61071. else if (key.isKeyCode (KeyPress::returnKey) && buttons.size() == 1)
  61072. {
  61073. ((TextButton*) buttons.getFirst())->triggerClick();
  61074. return true;
  61075. }
  61076. return false;
  61077. }
  61078. void AlertWindow::lookAndFeelChanged()
  61079. {
  61080. const int flags = getLookAndFeel().getAlertBoxWindowFlags();
  61081. setUsingNativeTitleBar ((flags & ComponentPeer::windowHasTitleBar) != 0);
  61082. setDropShadowEnabled (isOpaque() && (flags & ComponentPeer::windowHasDropShadow) != 0);
  61083. }
  61084. int AlertWindow::getDesktopWindowStyleFlags() const
  61085. {
  61086. return getLookAndFeel().getAlertBoxWindowFlags();
  61087. }
  61088. struct AlertWindowInfo
  61089. {
  61090. String title, message, button1, button2, button3;
  61091. AlertWindow::AlertIconType iconType;
  61092. int numButtons;
  61093. Component::SafePointer<Component> associatedComponent;
  61094. int run() const
  61095. {
  61096. return (int) (pointer_sized_int)
  61097. MessageManager::getInstance()->callFunctionOnMessageThread (showCallback, (void*) this);
  61098. }
  61099. private:
  61100. int show() const
  61101. {
  61102. LookAndFeel& lf = associatedComponent != 0 ? associatedComponent->getLookAndFeel()
  61103. : LookAndFeel::getDefaultLookAndFeel();
  61104. ScopedPointer <Component> alertBox (lf.createAlertWindow (title, message, button1, button2, button3,
  61105. iconType, numButtons, associatedComponent));
  61106. jassert (alertBox != 0); // you have to return one of these!
  61107. return alertBox->runModalLoop();
  61108. }
  61109. static void* showCallback (void* userData)
  61110. {
  61111. return (void*) (pointer_sized_int) ((const AlertWindowInfo*) userData)->show();
  61112. }
  61113. };
  61114. void AlertWindow::showMessageBox (AlertIconType iconType,
  61115. const String& title,
  61116. const String& message,
  61117. const String& buttonText,
  61118. Component* associatedComponent)
  61119. {
  61120. AlertWindowInfo info;
  61121. info.title = title;
  61122. info.message = message;
  61123. info.button1 = buttonText.isEmpty() ? TRANS("ok") : buttonText;
  61124. info.iconType = iconType;
  61125. info.numButtons = 1;
  61126. info.associatedComponent = associatedComponent;
  61127. info.run();
  61128. }
  61129. bool AlertWindow::showOkCancelBox (AlertIconType iconType,
  61130. const String& title,
  61131. const String& message,
  61132. const String& button1Text,
  61133. const String& button2Text,
  61134. Component* associatedComponent)
  61135. {
  61136. AlertWindowInfo info;
  61137. info.title = title;
  61138. info.message = message;
  61139. info.button1 = button1Text.isEmpty() ? TRANS("ok") : button1Text;
  61140. info.button2 = button2Text.isEmpty() ? TRANS("cancel") : button2Text;
  61141. info.iconType = iconType;
  61142. info.numButtons = 2;
  61143. info.associatedComponent = associatedComponent;
  61144. return info.run() != 0;
  61145. }
  61146. int AlertWindow::showYesNoCancelBox (AlertIconType iconType,
  61147. const String& title,
  61148. const String& message,
  61149. const String& button1Text,
  61150. const String& button2Text,
  61151. const String& button3Text,
  61152. Component* associatedComponent)
  61153. {
  61154. AlertWindowInfo info;
  61155. info.title = title;
  61156. info.message = message;
  61157. info.button1 = button1Text.isEmpty() ? TRANS("yes") : button1Text;
  61158. info.button2 = button2Text.isEmpty() ? TRANS("no") : button2Text;
  61159. info.button3 = button3Text.isEmpty() ? TRANS("cancel") : button3Text;
  61160. info.iconType = iconType;
  61161. info.numButtons = 3;
  61162. info.associatedComponent = associatedComponent;
  61163. return info.run();
  61164. }
  61165. END_JUCE_NAMESPACE
  61166. /*** End of inlined file: juce_AlertWindow.cpp ***/
  61167. /*** Start of inlined file: juce_ComponentPeer.cpp ***/
  61168. BEGIN_JUCE_NAMESPACE
  61169. //#define JUCE_ENABLE_REPAINT_DEBUGGING 1
  61170. static VoidArray heavyweightPeers;
  61171. ComponentPeer::ComponentPeer (Component* const component_,
  61172. const int styleFlags_) throw()
  61173. : component (component_),
  61174. styleFlags (styleFlags_),
  61175. lastPaintTime (0),
  61176. constrainer (0),
  61177. lastDragAndDropCompUnderMouse (0),
  61178. fakeMouseMessageSent (false),
  61179. isWindowMinimised (false)
  61180. {
  61181. heavyweightPeers.add (this);
  61182. }
  61183. ComponentPeer::~ComponentPeer()
  61184. {
  61185. heavyweightPeers.removeValue (this);
  61186. Desktop::getInstance().triggerFocusCallback();
  61187. }
  61188. int ComponentPeer::getNumPeers() throw()
  61189. {
  61190. return heavyweightPeers.size();
  61191. }
  61192. ComponentPeer* ComponentPeer::getPeer (const int index) throw()
  61193. {
  61194. return (ComponentPeer*) heavyweightPeers [index];
  61195. }
  61196. ComponentPeer* ComponentPeer::getPeerFor (const Component* const component) throw()
  61197. {
  61198. for (int i = heavyweightPeers.size(); --i >= 0;)
  61199. {
  61200. ComponentPeer* const peer = (ComponentPeer*) heavyweightPeers.getUnchecked(i);
  61201. if (peer->getComponent() == component)
  61202. return peer;
  61203. }
  61204. return 0;
  61205. }
  61206. bool ComponentPeer::isValidPeer (const ComponentPeer* const peer) throw()
  61207. {
  61208. return heavyweightPeers.contains (const_cast <ComponentPeer*> (peer));
  61209. }
  61210. void ComponentPeer::updateCurrentModifiers() throw()
  61211. {
  61212. ModifierKeys::updateCurrentModifiers();
  61213. }
  61214. void ComponentPeer::handleMouseEvent (const int touchIndex, const Point<int>& positionWithinPeer, const ModifierKeys& newMods, const int64 time)
  61215. {
  61216. MouseInputSource* const mouse = Desktop::getInstance().getMouseSource (touchIndex);
  61217. jassert (mouse != 0); // not enough sources!
  61218. mouse->handleEvent (this, positionWithinPeer, time, newMods);
  61219. }
  61220. void ComponentPeer::handleMouseWheel (const int touchIndex, const Point<int>& positionWithinPeer, const int64 time, const float x, const float y)
  61221. {
  61222. MouseInputSource* const mouse = Desktop::getInstance().getMouseSource (touchIndex);
  61223. jassert (mouse != 0); // not enough sources!
  61224. mouse->handleWheel (this, positionWithinPeer, time, x, y);
  61225. }
  61226. void ComponentPeer::handlePaint (LowLevelGraphicsContext& contextToPaintTo)
  61227. {
  61228. Graphics g (&contextToPaintTo);
  61229. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61230. g.saveState();
  61231. #endif
  61232. JUCE_TRY
  61233. {
  61234. component->paintEntireComponent (g);
  61235. }
  61236. JUCE_CATCH_EXCEPTION
  61237. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61238. // enabling this code will fill all areas that get repainted with a colour overlay, to show
  61239. // clearly when things are being repainted.
  61240. {
  61241. g.restoreState();
  61242. g.fillAll (Colour ((uint8) Random::getSystemRandom().nextInt (255),
  61243. (uint8) Random::getSystemRandom().nextInt (255),
  61244. (uint8) Random::getSystemRandom().nextInt (255),
  61245. (uint8) 0x50));
  61246. }
  61247. #endif
  61248. }
  61249. bool ComponentPeer::handleKeyPress (const int keyCode,
  61250. const juce_wchar textCharacter)
  61251. {
  61252. updateCurrentModifiers();
  61253. Component* target = Component::getCurrentlyFocusedComponent() != 0
  61254. ? Component::getCurrentlyFocusedComponent()
  61255. : component;
  61256. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61257. {
  61258. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61259. if (currentModalComp != 0)
  61260. target = currentModalComp;
  61261. }
  61262. const KeyPress keyInfo (keyCode,
  61263. ModifierKeys::getCurrentModifiers().getRawFlags()
  61264. & ModifierKeys::allKeyboardModifiers,
  61265. textCharacter);
  61266. bool keyWasUsed = false;
  61267. while (target != 0)
  61268. {
  61269. const Component::SafePointer<Component> deletionChecker (target);
  61270. if (target->keyListeners_ != 0)
  61271. {
  61272. for (int i = target->keyListeners_->size(); --i >= 0;)
  61273. {
  61274. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyPressed (keyInfo, target);
  61275. if (keyWasUsed || deletionChecker == 0)
  61276. return keyWasUsed;
  61277. i = jmin (i, target->keyListeners_->size());
  61278. }
  61279. }
  61280. keyWasUsed = target->keyPressed (keyInfo);
  61281. if (keyWasUsed || deletionChecker == 0)
  61282. break;
  61283. if (keyInfo.isKeyCode (KeyPress::tabKey) && Component::getCurrentlyFocusedComponent() != 0)
  61284. {
  61285. Component* const currentlyFocused = Component::getCurrentlyFocusedComponent();
  61286. currentlyFocused->moveKeyboardFocusToSibling (! keyInfo.getModifiers().isShiftDown());
  61287. keyWasUsed = (currentlyFocused != Component::getCurrentlyFocusedComponent());
  61288. break;
  61289. }
  61290. target = target->parentComponent_;
  61291. }
  61292. return keyWasUsed;
  61293. }
  61294. bool ComponentPeer::handleKeyUpOrDown (const bool isKeyDown)
  61295. {
  61296. updateCurrentModifiers();
  61297. Component* target = Component::getCurrentlyFocusedComponent() != 0
  61298. ? Component::getCurrentlyFocusedComponent()
  61299. : component;
  61300. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61301. {
  61302. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61303. if (currentModalComp != 0)
  61304. target = currentModalComp;
  61305. }
  61306. bool keyWasUsed = false;
  61307. while (target != 0)
  61308. {
  61309. const Component::SafePointer<Component> deletionChecker (target);
  61310. keyWasUsed = target->keyStateChanged (isKeyDown);
  61311. if (keyWasUsed || deletionChecker == 0)
  61312. break;
  61313. if (target->keyListeners_ != 0)
  61314. {
  61315. for (int i = target->keyListeners_->size(); --i >= 0;)
  61316. {
  61317. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyStateChanged (isKeyDown, target);
  61318. if (keyWasUsed || deletionChecker == 0)
  61319. return keyWasUsed;
  61320. i = jmin (i, target->keyListeners_->size());
  61321. }
  61322. }
  61323. target = target->parentComponent_;
  61324. }
  61325. return keyWasUsed;
  61326. }
  61327. void ComponentPeer::handleModifierKeysChange()
  61328. {
  61329. updateCurrentModifiers();
  61330. Component* target = Desktop::getInstance().getMainMouseSource().getComponentUnderMouse();
  61331. if (target == 0)
  61332. target = Component::getCurrentlyFocusedComponent();
  61333. if (target == 0)
  61334. target = component;
  61335. if (target != 0)
  61336. target->internalModifierKeysChanged();
  61337. }
  61338. TextInputTarget* ComponentPeer::findCurrentTextInputTarget()
  61339. {
  61340. Component* const c = Component::getCurrentlyFocusedComponent();
  61341. if (component->isParentOf (c))
  61342. return dynamic_cast <TextInputTarget*> (c);
  61343. return 0;
  61344. }
  61345. void ComponentPeer::handleBroughtToFront()
  61346. {
  61347. updateCurrentModifiers();
  61348. if (component != 0)
  61349. component->internalBroughtToFront();
  61350. }
  61351. void ComponentPeer::setConstrainer (ComponentBoundsConstrainer* const newConstrainer) throw()
  61352. {
  61353. constrainer = newConstrainer;
  61354. }
  61355. void ComponentPeer::handleMovedOrResized()
  61356. {
  61357. jassert (component->isValidComponent());
  61358. updateCurrentModifiers();
  61359. const bool nowMinimised = isMinimised();
  61360. if (component->flags.hasHeavyweightPeerFlag && ! nowMinimised)
  61361. {
  61362. const Component::SafePointer<Component> deletionChecker (component);
  61363. const Rectangle<int> newBounds (getBounds());
  61364. const bool wasMoved = (component->getPosition() != newBounds.getPosition());
  61365. const bool wasResized = (component->getWidth() != newBounds.getWidth() || component->getHeight() != newBounds.getHeight());
  61366. if (wasMoved || wasResized)
  61367. {
  61368. component->bounds_ = newBounds;
  61369. if (wasResized)
  61370. component->repaint();
  61371. component->sendMovedResizedMessages (wasMoved, wasResized);
  61372. if (deletionChecker == 0)
  61373. return;
  61374. }
  61375. }
  61376. if (isWindowMinimised != nowMinimised)
  61377. {
  61378. isWindowMinimised = nowMinimised;
  61379. component->minimisationStateChanged (nowMinimised);
  61380. component->sendVisibilityChangeMessage();
  61381. }
  61382. if (! isFullScreen())
  61383. lastNonFullscreenBounds = component->getBounds();
  61384. }
  61385. void ComponentPeer::handleFocusGain()
  61386. {
  61387. updateCurrentModifiers();
  61388. if (component->isParentOf (lastFocusedComponent))
  61389. {
  61390. Component::currentlyFocusedComponent = lastFocusedComponent;
  61391. Desktop::getInstance().triggerFocusCallback();
  61392. lastFocusedComponent->internalFocusGain (Component::focusChangedDirectly);
  61393. }
  61394. else
  61395. {
  61396. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  61397. component->grabKeyboardFocus();
  61398. else
  61399. Component::bringModalComponentToFront();
  61400. }
  61401. }
  61402. void ComponentPeer::handleFocusLoss()
  61403. {
  61404. updateCurrentModifiers();
  61405. if (component->hasKeyboardFocus (true))
  61406. {
  61407. lastFocusedComponent = Component::currentlyFocusedComponent;
  61408. if (lastFocusedComponent != 0)
  61409. {
  61410. Component::currentlyFocusedComponent = 0;
  61411. Desktop::getInstance().triggerFocusCallback();
  61412. lastFocusedComponent->internalFocusLoss (Component::focusChangedByMouseClick);
  61413. }
  61414. }
  61415. }
  61416. Component* ComponentPeer::getLastFocusedSubcomponent() const throw()
  61417. {
  61418. return (component->isParentOf (lastFocusedComponent) && lastFocusedComponent->isShowing())
  61419. ? static_cast <Component*> (lastFocusedComponent)
  61420. : component;
  61421. }
  61422. void ComponentPeer::handleScreenSizeChange()
  61423. {
  61424. updateCurrentModifiers();
  61425. component->parentSizeChanged();
  61426. handleMovedOrResized();
  61427. }
  61428. void ComponentPeer::setNonFullScreenBounds (const Rectangle<int>& newBounds) throw()
  61429. {
  61430. lastNonFullscreenBounds = newBounds;
  61431. }
  61432. const Rectangle<int>& ComponentPeer::getNonFullScreenBounds() const throw()
  61433. {
  61434. return lastNonFullscreenBounds;
  61435. }
  61436. static FileDragAndDropTarget* findDragAndDropTarget (Component* c,
  61437. const StringArray& files,
  61438. FileDragAndDropTarget* const lastOne)
  61439. {
  61440. while (c != 0)
  61441. {
  61442. FileDragAndDropTarget* const t = dynamic_cast <FileDragAndDropTarget*> (c);
  61443. if (t != 0 && (t == lastOne || t->isInterestedInFileDrag (files)))
  61444. return t;
  61445. c = c->getParentComponent();
  61446. }
  61447. return 0;
  61448. }
  61449. void ComponentPeer::handleFileDragMove (const StringArray& files, const Point<int>& position)
  61450. {
  61451. updateCurrentModifiers();
  61452. FileDragAndDropTarget* lastTarget
  61453. = dynamic_cast<FileDragAndDropTarget*> (static_cast<Component*> (dragAndDropTargetComponent));
  61454. FileDragAndDropTarget* newTarget = 0;
  61455. Component* const compUnderMouse = component->getComponentAt (position);
  61456. if (compUnderMouse != lastDragAndDropCompUnderMouse)
  61457. {
  61458. lastDragAndDropCompUnderMouse = compUnderMouse;
  61459. newTarget = findDragAndDropTarget (compUnderMouse, files, lastTarget);
  61460. if (newTarget != lastTarget)
  61461. {
  61462. if (lastTarget != 0)
  61463. lastTarget->fileDragExit (files);
  61464. dragAndDropTargetComponent = 0;
  61465. if (newTarget != 0)
  61466. {
  61467. dragAndDropTargetComponent = dynamic_cast <Component*> (newTarget);
  61468. const Point<int> pos (component->relativePositionToOtherComponent (dragAndDropTargetComponent, position));
  61469. newTarget->fileDragEnter (files, pos.getX(), pos.getY());
  61470. }
  61471. }
  61472. }
  61473. else
  61474. {
  61475. newTarget = lastTarget;
  61476. }
  61477. if (newTarget != 0)
  61478. {
  61479. Component* const targetComp = dynamic_cast <Component*> (newTarget);
  61480. const Point<int> pos (component->relativePositionToOtherComponent (targetComp, position));
  61481. newTarget->fileDragMove (files, pos.getX(), pos.getY());
  61482. }
  61483. }
  61484. void ComponentPeer::handleFileDragExit (const StringArray& files)
  61485. {
  61486. handleFileDragMove (files, Point<int> (-1, -1));
  61487. jassert (dragAndDropTargetComponent == 0);
  61488. lastDragAndDropCompUnderMouse = 0;
  61489. }
  61490. void ComponentPeer::handleFileDragDrop (const StringArray& files, const Point<int>& position)
  61491. {
  61492. handleFileDragMove (files, position);
  61493. if (dragAndDropTargetComponent != 0)
  61494. {
  61495. FileDragAndDropTarget* const target
  61496. = dynamic_cast<FileDragAndDropTarget*> (static_cast<Component*> (dragAndDropTargetComponent));
  61497. dragAndDropTargetComponent = 0;
  61498. lastDragAndDropCompUnderMouse = 0;
  61499. if (target != 0)
  61500. {
  61501. Component* const targetComp = dynamic_cast <Component*> (target);
  61502. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  61503. {
  61504. targetComp->internalModalInputAttempt();
  61505. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  61506. return;
  61507. }
  61508. const Point<int> pos (component->relativePositionToOtherComponent (targetComp, position));
  61509. target->filesDropped (files, pos.getX(), pos.getY());
  61510. }
  61511. }
  61512. }
  61513. void ComponentPeer::handleUserClosingWindow()
  61514. {
  61515. updateCurrentModifiers();
  61516. component->userTriedToCloseWindow();
  61517. }
  61518. void ComponentPeer::bringModalComponentToFront()
  61519. {
  61520. Component::bringModalComponentToFront();
  61521. }
  61522. void ComponentPeer::clearMaskedRegion() throw()
  61523. {
  61524. maskedRegion.clear();
  61525. }
  61526. void ComponentPeer::addMaskedRegion (int x, int y, int w, int h) throw()
  61527. {
  61528. maskedRegion.add (x, y, w, h);
  61529. }
  61530. const StringArray ComponentPeer::getAvailableRenderingEngines() throw()
  61531. {
  61532. StringArray s;
  61533. s.add ("Software Renderer");
  61534. return s;
  61535. }
  61536. int ComponentPeer::getCurrentRenderingEngine() throw()
  61537. {
  61538. return 0;
  61539. }
  61540. void ComponentPeer::setCurrentRenderingEngine (int /*index*/) throw()
  61541. {
  61542. }
  61543. END_JUCE_NAMESPACE
  61544. /*** End of inlined file: juce_ComponentPeer.cpp ***/
  61545. /*** Start of inlined file: juce_DialogWindow.cpp ***/
  61546. BEGIN_JUCE_NAMESPACE
  61547. DialogWindow::DialogWindow (const String& name,
  61548. const Colour& backgroundColour_,
  61549. const bool escapeKeyTriggersCloseButton_,
  61550. const bool addToDesktop_)
  61551. : DocumentWindow (name, backgroundColour_, DocumentWindow::closeButton, addToDesktop_),
  61552. escapeKeyTriggersCloseButton (escapeKeyTriggersCloseButton_)
  61553. {
  61554. }
  61555. DialogWindow::~DialogWindow()
  61556. {
  61557. }
  61558. void DialogWindow::resized()
  61559. {
  61560. DocumentWindow::resized();
  61561. const KeyPress esc (KeyPress::escapeKey, 0, 0);
  61562. if (escapeKeyTriggersCloseButton
  61563. && getCloseButton() != 0
  61564. && ! getCloseButton()->isRegisteredForShortcut (esc))
  61565. {
  61566. getCloseButton()->addShortcut (esc);
  61567. }
  61568. }
  61569. class TempDialogWindow : public DialogWindow
  61570. {
  61571. public:
  61572. TempDialogWindow (const String& title, const Colour& colour, const bool escapeCloses)
  61573. : DialogWindow (title, colour, escapeCloses, true)
  61574. {
  61575. }
  61576. ~TempDialogWindow()
  61577. {
  61578. }
  61579. void closeButtonPressed()
  61580. {
  61581. setVisible (false);
  61582. }
  61583. private:
  61584. TempDialogWindow (const TempDialogWindow&);
  61585. TempDialogWindow& operator= (const TempDialogWindow&);
  61586. };
  61587. int DialogWindow::showModalDialog (const String& dialogTitle,
  61588. Component* contentComponent,
  61589. Component* componentToCentreAround,
  61590. const Colour& colour,
  61591. const bool escapeKeyTriggersCloseButton,
  61592. const bool shouldBeResizable,
  61593. const bool useBottomRightCornerResizer)
  61594. {
  61595. TempDialogWindow dw (dialogTitle, colour, escapeKeyTriggersCloseButton);
  61596. dw.setContentComponent (contentComponent, true, true);
  61597. dw.centreAroundComponent (componentToCentreAround, dw.getWidth(), dw.getHeight());
  61598. dw.setResizable (shouldBeResizable, useBottomRightCornerResizer);
  61599. const int result = dw.runModalLoop();
  61600. dw.setContentComponent (0, false);
  61601. return result;
  61602. }
  61603. END_JUCE_NAMESPACE
  61604. /*** End of inlined file: juce_DialogWindow.cpp ***/
  61605. /*** Start of inlined file: juce_DocumentWindow.cpp ***/
  61606. BEGIN_JUCE_NAMESPACE
  61607. class DocumentWindow::ButtonListenerProxy : public ButtonListener
  61608. {
  61609. public:
  61610. ButtonListenerProxy (DocumentWindow& owner_)
  61611. : owner (owner_)
  61612. {
  61613. }
  61614. void buttonClicked (Button* button)
  61615. {
  61616. if (button == owner.getMinimiseButton())
  61617. owner.minimiseButtonPressed();
  61618. else if (button == owner.getMaximiseButton())
  61619. owner.maximiseButtonPressed();
  61620. else if (button == owner.getCloseButton())
  61621. owner.closeButtonPressed();
  61622. }
  61623. juce_UseDebuggingNewOperator
  61624. private:
  61625. DocumentWindow& owner;
  61626. ButtonListenerProxy (const ButtonListenerProxy&);
  61627. ButtonListenerProxy& operator= (const ButtonListenerProxy&);
  61628. };
  61629. DocumentWindow::DocumentWindow (const String& title,
  61630. const Colour& backgroundColour,
  61631. const int requiredButtons_,
  61632. const bool addToDesktop_)
  61633. : ResizableWindow (title, backgroundColour, addToDesktop_),
  61634. titleBarHeight (26),
  61635. menuBarHeight (24),
  61636. requiredButtons (requiredButtons_),
  61637. #if JUCE_MAC
  61638. positionTitleBarButtonsOnLeft (true),
  61639. #else
  61640. positionTitleBarButtonsOnLeft (false),
  61641. #endif
  61642. drawTitleTextCentred (true),
  61643. menuBarModel (0)
  61644. {
  61645. setResizeLimits (128, 128, 32768, 32768);
  61646. lookAndFeelChanged();
  61647. }
  61648. DocumentWindow::~DocumentWindow()
  61649. {
  61650. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  61651. titleBarButtons[i] = 0;
  61652. menuBar = 0;
  61653. }
  61654. void DocumentWindow::repaintTitleBar()
  61655. {
  61656. const Rectangle<int> titleBarArea (getTitleBarArea());
  61657. repaint (titleBarArea.getX(), titleBarArea.getY(),
  61658. titleBarArea.getWidth(), titleBarArea.getHeight());
  61659. }
  61660. void DocumentWindow::setName (const String& newName)
  61661. {
  61662. if (newName != getName())
  61663. {
  61664. Component::setName (newName);
  61665. repaintTitleBar();
  61666. }
  61667. }
  61668. void DocumentWindow::setIcon (const Image* imageToUse)
  61669. {
  61670. titleBarIcon = imageToUse != 0 ? imageToUse->createCopy() : 0;
  61671. repaintTitleBar();
  61672. }
  61673. void DocumentWindow::setTitleBarHeight (const int newHeight)
  61674. {
  61675. titleBarHeight = newHeight;
  61676. resized();
  61677. repaintTitleBar();
  61678. }
  61679. void DocumentWindow::setTitleBarButtonsRequired (const int requiredButtons_,
  61680. const bool positionTitleBarButtonsOnLeft_)
  61681. {
  61682. requiredButtons = requiredButtons_;
  61683. positionTitleBarButtonsOnLeft = positionTitleBarButtonsOnLeft_;
  61684. lookAndFeelChanged();
  61685. }
  61686. void DocumentWindow::setTitleBarTextCentred (const bool textShouldBeCentred)
  61687. {
  61688. drawTitleTextCentred = textShouldBeCentred;
  61689. repaintTitleBar();
  61690. }
  61691. void DocumentWindow::setMenuBar (MenuBarModel* menuBarModel_,
  61692. const int menuBarHeight_)
  61693. {
  61694. if (menuBarModel != menuBarModel_)
  61695. {
  61696. menuBar = 0;
  61697. menuBarModel = menuBarModel_;
  61698. menuBarHeight = (menuBarHeight_ > 0) ? menuBarHeight_
  61699. : getLookAndFeel().getDefaultMenuBarHeight();
  61700. if (menuBarModel != 0)
  61701. {
  61702. // (call the Component method directly to avoid the assertion in ResizableWindow)
  61703. Component::addAndMakeVisible (menuBar = new MenuBarComponent (menuBarModel));
  61704. menuBar->setEnabled (isActiveWindow());
  61705. }
  61706. resized();
  61707. }
  61708. }
  61709. void DocumentWindow::closeButtonPressed()
  61710. {
  61711. /* If you've got a close button, you have to override this method to get
  61712. rid of your window!
  61713. If the window is just a pop-up, you should override this method and make
  61714. it delete the window in whatever way is appropriate for your app. E.g. you
  61715. might just want to call "delete this".
  61716. If your app is centred around this window such that the whole app should quit when
  61717. the window is closed, then you will probably want to use this method as an opportunity
  61718. to call JUCEApplication::quit(), and leave the window to be deleted later by your
  61719. JUCEApplication::shutdown() method. (Doing it this way means that your window will
  61720. still get cleaned-up if the app is quit by some other means (e.g. a cmd-Q on the mac
  61721. or closing it via the taskbar icon on Windows).
  61722. */
  61723. jassertfalse
  61724. }
  61725. void DocumentWindow::minimiseButtonPressed()
  61726. {
  61727. setMinimised (true);
  61728. }
  61729. void DocumentWindow::maximiseButtonPressed()
  61730. {
  61731. setFullScreen (! isFullScreen());
  61732. }
  61733. void DocumentWindow::paint (Graphics& g)
  61734. {
  61735. ResizableWindow::paint (g);
  61736. if (resizableBorder == 0)
  61737. {
  61738. g.setColour (getBackgroundColour().overlaidWith (Colour (0x80000000)));
  61739. const BorderSize border (getBorderThickness());
  61740. g.fillRect (0, 0, getWidth(), border.getTop());
  61741. g.fillRect (0, border.getTop(), border.getLeft(), getHeight() - border.getTopAndBottom());
  61742. g.fillRect (getWidth() - border.getRight(), border.getTop(), border.getRight(), getHeight() - border.getTopAndBottom());
  61743. g.fillRect (0, getHeight() - border.getBottom(), getWidth(), border.getBottom());
  61744. }
  61745. const Rectangle<int> titleBarArea (getTitleBarArea());
  61746. g.setOrigin (titleBarArea.getX(), titleBarArea.getY());
  61747. g.reduceClipRegion (0, 0, titleBarArea.getWidth(), titleBarArea.getHeight());
  61748. int titleSpaceX1 = 6;
  61749. int titleSpaceX2 = titleBarArea.getWidth() - 6;
  61750. for (int i = 0; i < 3; ++i)
  61751. {
  61752. if (titleBarButtons[i] != 0)
  61753. {
  61754. if (positionTitleBarButtonsOnLeft)
  61755. titleSpaceX1 = jmax (titleSpaceX1, titleBarButtons[i]->getRight() + (getWidth() - titleBarButtons[i]->getRight()) / 8);
  61756. else
  61757. titleSpaceX2 = jmin (titleSpaceX2, titleBarButtons[i]->getX() - (titleBarButtons[i]->getX() / 8));
  61758. }
  61759. }
  61760. getLookAndFeel().drawDocumentWindowTitleBar (*this, g,
  61761. titleBarArea.getWidth(),
  61762. titleBarArea.getHeight(),
  61763. titleSpaceX1,
  61764. jmax (1, titleSpaceX2 - titleSpaceX1),
  61765. titleBarIcon,
  61766. ! drawTitleTextCentred);
  61767. }
  61768. void DocumentWindow::resized()
  61769. {
  61770. ResizableWindow::resized();
  61771. if (titleBarButtons[1] != 0)
  61772. titleBarButtons[1]->setToggleState (isFullScreen(), false);
  61773. const Rectangle<int> titleBarArea (getTitleBarArea());
  61774. getLookAndFeel()
  61775. .positionDocumentWindowButtons (*this,
  61776. titleBarArea.getX(), titleBarArea.getY(),
  61777. titleBarArea.getWidth(), titleBarArea.getHeight(),
  61778. titleBarButtons[0],
  61779. titleBarButtons[1],
  61780. titleBarButtons[2],
  61781. positionTitleBarButtonsOnLeft);
  61782. if (menuBar != 0)
  61783. menuBar->setBounds (titleBarArea.getX(), titleBarArea.getBottom(),
  61784. titleBarArea.getWidth(), menuBarHeight);
  61785. }
  61786. const BorderSize DocumentWindow::getBorderThickness()
  61787. {
  61788. return BorderSize ((isFullScreen() || isUsingNativeTitleBar())
  61789. ? 0 : (resizableBorder != 0 ? 4 : 1));
  61790. }
  61791. const BorderSize DocumentWindow::getContentComponentBorder()
  61792. {
  61793. BorderSize border (getBorderThickness());
  61794. border.setTop (border.getTop()
  61795. + (isUsingNativeTitleBar() ? 0 : titleBarHeight)
  61796. + (menuBar != 0 ? menuBarHeight : 0));
  61797. return border;
  61798. }
  61799. int DocumentWindow::getTitleBarHeight() const
  61800. {
  61801. return isUsingNativeTitleBar() ? 0 : jmin (titleBarHeight, getHeight() - 4);
  61802. }
  61803. const Rectangle<int> DocumentWindow::getTitleBarArea()
  61804. {
  61805. const BorderSize border (getBorderThickness());
  61806. return Rectangle<int> (border.getLeft(), border.getTop(),
  61807. getWidth() - border.getLeftAndRight(),
  61808. getTitleBarHeight());
  61809. }
  61810. Button* DocumentWindow::getCloseButton() const throw()
  61811. {
  61812. return titleBarButtons[2];
  61813. }
  61814. Button* DocumentWindow::getMinimiseButton() const throw()
  61815. {
  61816. return titleBarButtons[0];
  61817. }
  61818. Button* DocumentWindow::getMaximiseButton() const throw()
  61819. {
  61820. return titleBarButtons[1];
  61821. }
  61822. int DocumentWindow::getDesktopWindowStyleFlags() const
  61823. {
  61824. int flags = ResizableWindow::getDesktopWindowStyleFlags();
  61825. if ((requiredButtons & minimiseButton) != 0)
  61826. flags |= ComponentPeer::windowHasMinimiseButton;
  61827. if ((requiredButtons & maximiseButton) != 0)
  61828. flags |= ComponentPeer::windowHasMaximiseButton;
  61829. if ((requiredButtons & closeButton) != 0)
  61830. flags |= ComponentPeer::windowHasCloseButton;
  61831. return flags;
  61832. }
  61833. void DocumentWindow::lookAndFeelChanged()
  61834. {
  61835. int i;
  61836. for (i = numElementsInArray (titleBarButtons); --i >= 0;)
  61837. titleBarButtons[i] = 0;
  61838. if (! isUsingNativeTitleBar())
  61839. {
  61840. titleBarButtons[0] = ((requiredButtons & minimiseButton) != 0)
  61841. ? getLookAndFeel().createDocumentWindowButton (minimiseButton) : 0;
  61842. titleBarButtons[1] = ((requiredButtons & maximiseButton) != 0)
  61843. ? getLookAndFeel().createDocumentWindowButton (maximiseButton) : 0;
  61844. titleBarButtons[2] = ((requiredButtons & closeButton) != 0)
  61845. ? getLookAndFeel().createDocumentWindowButton (closeButton) : 0;
  61846. for (i = 0; i < 3; ++i)
  61847. {
  61848. if (titleBarButtons[i] != 0)
  61849. {
  61850. if (buttonListener == 0)
  61851. buttonListener = new ButtonListenerProxy (*this);
  61852. titleBarButtons[i]->addButtonListener (buttonListener);
  61853. titleBarButtons[i]->setWantsKeyboardFocus (false);
  61854. // (call the Component method directly to avoid the assertion in ResizableWindow)
  61855. Component::addAndMakeVisible (titleBarButtons[i]);
  61856. }
  61857. }
  61858. if (getCloseButton() != 0)
  61859. {
  61860. #if JUCE_MAC
  61861. getCloseButton()->addShortcut (KeyPress ('w', ModifierKeys::commandModifier, 0));
  61862. #else
  61863. getCloseButton()->addShortcut (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0));
  61864. #endif
  61865. }
  61866. }
  61867. activeWindowStatusChanged();
  61868. ResizableWindow::lookAndFeelChanged();
  61869. }
  61870. void DocumentWindow::parentHierarchyChanged()
  61871. {
  61872. lookAndFeelChanged();
  61873. }
  61874. void DocumentWindow::activeWindowStatusChanged()
  61875. {
  61876. ResizableWindow::activeWindowStatusChanged();
  61877. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  61878. if (titleBarButtons[i] != 0)
  61879. titleBarButtons[i]->setEnabled (isActiveWindow());
  61880. if (menuBar != 0)
  61881. menuBar->setEnabled (isActiveWindow());
  61882. }
  61883. void DocumentWindow::mouseDoubleClick (const MouseEvent& e)
  61884. {
  61885. if (getTitleBarArea().contains (e.x, e.y)
  61886. && getMaximiseButton() != 0)
  61887. {
  61888. getMaximiseButton()->triggerClick();
  61889. }
  61890. }
  61891. void DocumentWindow::userTriedToCloseWindow()
  61892. {
  61893. closeButtonPressed();
  61894. }
  61895. END_JUCE_NAMESPACE
  61896. /*** End of inlined file: juce_DocumentWindow.cpp ***/
  61897. /*** Start of inlined file: juce_ResizableWindow.cpp ***/
  61898. BEGIN_JUCE_NAMESPACE
  61899. ResizableWindow::ResizableWindow (const String& name,
  61900. const bool addToDesktop_)
  61901. : TopLevelWindow (name, addToDesktop_),
  61902. resizeToFitContent (false),
  61903. fullscreen (false),
  61904. lastNonFullScreenPos (50, 50, 256, 256),
  61905. constrainer (0)
  61906. #ifdef JUCE_DEBUG
  61907. , hasBeenResized (false)
  61908. #endif
  61909. {
  61910. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  61911. lastNonFullScreenPos.setBounds (50, 50, 256, 256);
  61912. if (addToDesktop_)
  61913. Component::addToDesktop (getDesktopWindowStyleFlags());
  61914. }
  61915. ResizableWindow::ResizableWindow (const String& name,
  61916. const Colour& backgroundColour_,
  61917. const bool addToDesktop_)
  61918. : TopLevelWindow (name, addToDesktop_),
  61919. resizeToFitContent (false),
  61920. fullscreen (false),
  61921. lastNonFullScreenPos (50, 50, 256, 256),
  61922. constrainer (0)
  61923. #ifdef JUCE_DEBUG
  61924. , hasBeenResized (false)
  61925. #endif
  61926. {
  61927. setBackgroundColour (backgroundColour_);
  61928. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  61929. if (addToDesktop_)
  61930. Component::addToDesktop (getDesktopWindowStyleFlags());
  61931. }
  61932. ResizableWindow::~ResizableWindow()
  61933. {
  61934. resizableCorner = 0;
  61935. resizableBorder = 0;
  61936. contentComponent = 0;
  61937. // have you been adding your own components directly to this window..? tut tut tut.
  61938. // Read the instructions for using a ResizableWindow!
  61939. jassert (getNumChildComponents() == 0);
  61940. }
  61941. int ResizableWindow::getDesktopWindowStyleFlags() const
  61942. {
  61943. int flags = TopLevelWindow::getDesktopWindowStyleFlags();
  61944. if (isResizable() && (flags & ComponentPeer::windowHasTitleBar) != 0)
  61945. flags |= ComponentPeer::windowIsResizable;
  61946. return flags;
  61947. }
  61948. void ResizableWindow::setContentComponent (Component* const newContentComponent,
  61949. const bool deleteOldOne,
  61950. const bool resizeToFit)
  61951. {
  61952. resizeToFitContent = resizeToFit;
  61953. if (newContentComponent != (Component*) contentComponent)
  61954. {
  61955. if (! deleteOldOne)
  61956. removeChildComponent (contentComponent.release());
  61957. contentComponent = newContentComponent;
  61958. Component::addAndMakeVisible (contentComponent);
  61959. }
  61960. if (resizeToFit)
  61961. childBoundsChanged (contentComponent);
  61962. resized(); // must always be called to position the new content comp
  61963. }
  61964. void ResizableWindow::setContentComponentSize (int width, int height)
  61965. {
  61966. jassert (width > 0 && height > 0); // not a great idea to give it a zero size..
  61967. const BorderSize border (getContentComponentBorder());
  61968. setSize (width + border.getLeftAndRight(),
  61969. height + border.getTopAndBottom());
  61970. }
  61971. const BorderSize ResizableWindow::getBorderThickness()
  61972. {
  61973. return BorderSize (isUsingNativeTitleBar() ? 0 : ((resizableBorder != 0 && ! isFullScreen()) ? 5 : 3));
  61974. }
  61975. const BorderSize ResizableWindow::getContentComponentBorder()
  61976. {
  61977. return getBorderThickness();
  61978. }
  61979. void ResizableWindow::moved()
  61980. {
  61981. updateLastPos();
  61982. }
  61983. void ResizableWindow::visibilityChanged()
  61984. {
  61985. TopLevelWindow::visibilityChanged();
  61986. updateLastPos();
  61987. }
  61988. void ResizableWindow::resized()
  61989. {
  61990. if (resizableBorder != 0)
  61991. {
  61992. resizableBorder->setVisible (! isFullScreen());
  61993. resizableBorder->setBorderThickness (getBorderThickness());
  61994. resizableBorder->setSize (getWidth(), getHeight());
  61995. resizableBorder->toBack();
  61996. }
  61997. if (resizableCorner != 0)
  61998. {
  61999. resizableCorner->setVisible (! isFullScreen());
  62000. const int resizerSize = 18;
  62001. resizableCorner->setBounds (getWidth() - resizerSize,
  62002. getHeight() - resizerSize,
  62003. resizerSize, resizerSize);
  62004. }
  62005. if (contentComponent != 0)
  62006. contentComponent->setBoundsInset (getContentComponentBorder());
  62007. updateLastPos();
  62008. #ifdef JUCE_DEBUG
  62009. hasBeenResized = true;
  62010. #endif
  62011. }
  62012. void ResizableWindow::childBoundsChanged (Component* child)
  62013. {
  62014. if ((child == contentComponent) && (child != 0) && resizeToFitContent)
  62015. {
  62016. // not going to look very good if this component has a zero size..
  62017. jassert (child->getWidth() > 0);
  62018. jassert (child->getHeight() > 0);
  62019. const BorderSize borders (getContentComponentBorder());
  62020. setSize (child->getWidth() + borders.getLeftAndRight(),
  62021. child->getHeight() + borders.getTopAndBottom());
  62022. }
  62023. }
  62024. void ResizableWindow::activeWindowStatusChanged()
  62025. {
  62026. const BorderSize borders (getContentComponentBorder());
  62027. repaint (0, 0, getWidth(), borders.getTop());
  62028. repaint (0, borders.getTop(), borders.getLeft(), getHeight() - borders.getBottom() - borders.getTop());
  62029. repaint (0, getHeight() - borders.getBottom(), getWidth(), borders.getBottom());
  62030. repaint (getWidth() - borders.getRight(), borders.getTop(), borders.getRight(), getHeight() - borders.getBottom() - borders.getTop());
  62031. }
  62032. void ResizableWindow::setResizable (const bool shouldBeResizable,
  62033. const bool useBottomRightCornerResizer)
  62034. {
  62035. if (shouldBeResizable)
  62036. {
  62037. if (useBottomRightCornerResizer)
  62038. {
  62039. resizableBorder = 0;
  62040. if (resizableCorner == 0)
  62041. {
  62042. Component::addChildComponent (resizableCorner = new ResizableCornerComponent (this, constrainer));
  62043. resizableCorner->setAlwaysOnTop (true);
  62044. }
  62045. }
  62046. else
  62047. {
  62048. resizableCorner = 0;
  62049. if (resizableBorder == 0)
  62050. Component::addChildComponent (resizableBorder = new ResizableBorderComponent (this, constrainer));
  62051. }
  62052. }
  62053. else
  62054. {
  62055. resizableCorner = 0;
  62056. resizableBorder = 0;
  62057. }
  62058. if (isUsingNativeTitleBar())
  62059. recreateDesktopWindow();
  62060. childBoundsChanged (contentComponent);
  62061. resized();
  62062. }
  62063. bool ResizableWindow::isResizable() const throw()
  62064. {
  62065. return resizableCorner != 0
  62066. || resizableBorder != 0;
  62067. }
  62068. void ResizableWindow::setResizeLimits (const int newMinimumWidth,
  62069. const int newMinimumHeight,
  62070. const int newMaximumWidth,
  62071. const int newMaximumHeight) throw()
  62072. {
  62073. // if you've set up a custom constrainer then these settings won't have any effect..
  62074. jassert (constrainer == &defaultConstrainer || constrainer == 0);
  62075. if (constrainer == 0)
  62076. setConstrainer (&defaultConstrainer);
  62077. defaultConstrainer.setSizeLimits (newMinimumWidth, newMinimumHeight,
  62078. newMaximumWidth, newMaximumHeight);
  62079. setBoundsConstrained (getBounds());
  62080. }
  62081. void ResizableWindow::setConstrainer (ComponentBoundsConstrainer* newConstrainer)
  62082. {
  62083. if (constrainer != newConstrainer)
  62084. {
  62085. constrainer = newConstrainer;
  62086. const bool useBottomRightCornerResizer = resizableCorner != 0;
  62087. const bool shouldBeResizable = useBottomRightCornerResizer || resizableBorder != 0;
  62088. resizableCorner = 0;
  62089. resizableBorder = 0;
  62090. setResizable (shouldBeResizable, useBottomRightCornerResizer);
  62091. ComponentPeer* const peer = getPeer();
  62092. if (peer != 0)
  62093. peer->setConstrainer (newConstrainer);
  62094. }
  62095. }
  62096. void ResizableWindow::setBoundsConstrained (const Rectangle<int>& bounds)
  62097. {
  62098. if (constrainer != 0)
  62099. constrainer->setBoundsForComponent (this, bounds, false, false, false, false);
  62100. else
  62101. setBounds (bounds);
  62102. }
  62103. void ResizableWindow::paint (Graphics& g)
  62104. {
  62105. getLookAndFeel().fillResizableWindowBackground (g, getWidth(), getHeight(),
  62106. getBorderThickness(), *this);
  62107. if (! isFullScreen())
  62108. {
  62109. getLookAndFeel().drawResizableWindowBorder (g, getWidth(), getHeight(),
  62110. getBorderThickness(), *this);
  62111. }
  62112. #ifdef JUCE_DEBUG
  62113. /* If this fails, then you've probably written a subclass with a resized()
  62114. callback but forgotten to make it call its parent class's resized() method.
  62115. It's important when you override methods like resized(), moved(),
  62116. etc., that you make sure the base class methods also get called.
  62117. Of course you shouldn't really be overriding ResizableWindow::resized() anyway,
  62118. because your content should all be inside the content component - and it's the
  62119. content component's resized() method that you should be using to do your
  62120. layout.
  62121. */
  62122. jassert (hasBeenResized || (getWidth() == 0 && getHeight() == 0));
  62123. #endif
  62124. }
  62125. void ResizableWindow::lookAndFeelChanged()
  62126. {
  62127. resized();
  62128. if (isOnDesktop())
  62129. {
  62130. Component::addToDesktop (getDesktopWindowStyleFlags());
  62131. ComponentPeer* const peer = getPeer();
  62132. if (peer != 0)
  62133. peer->setConstrainer (constrainer);
  62134. }
  62135. }
  62136. const Colour ResizableWindow::getBackgroundColour() const throw()
  62137. {
  62138. return findColour (backgroundColourId, false);
  62139. }
  62140. void ResizableWindow::setBackgroundColour (const Colour& newColour)
  62141. {
  62142. Colour backgroundColour (newColour);
  62143. if (! Desktop::canUseSemiTransparentWindows())
  62144. backgroundColour = newColour.withAlpha (1.0f);
  62145. setColour (backgroundColourId, backgroundColour);
  62146. setOpaque (backgroundColour.isOpaque());
  62147. repaint();
  62148. }
  62149. bool ResizableWindow::isFullScreen() const
  62150. {
  62151. if (isOnDesktop())
  62152. {
  62153. ComponentPeer* const peer = getPeer();
  62154. return peer != 0 && peer->isFullScreen();
  62155. }
  62156. return fullscreen;
  62157. }
  62158. void ResizableWindow::setFullScreen (const bool shouldBeFullScreen)
  62159. {
  62160. if (shouldBeFullScreen != isFullScreen())
  62161. {
  62162. updateLastPos();
  62163. fullscreen = shouldBeFullScreen;
  62164. if (isOnDesktop())
  62165. {
  62166. ComponentPeer* const peer = getPeer();
  62167. if (peer != 0)
  62168. {
  62169. // keep a copy of this intact in case the real one gets messed-up while we're un-maximising
  62170. const Rectangle<int> lastPos (lastNonFullScreenPos);
  62171. peer->setFullScreen (shouldBeFullScreen);
  62172. if (! shouldBeFullScreen)
  62173. setBounds (lastPos);
  62174. }
  62175. else
  62176. {
  62177. jassertfalse
  62178. }
  62179. }
  62180. else
  62181. {
  62182. if (shouldBeFullScreen)
  62183. setBounds (0, 0, getParentWidth(), getParentHeight());
  62184. else
  62185. setBounds (lastNonFullScreenPos);
  62186. }
  62187. resized();
  62188. }
  62189. }
  62190. bool ResizableWindow::isMinimised() const
  62191. {
  62192. ComponentPeer* const peer = getPeer();
  62193. return (peer != 0) && peer->isMinimised();
  62194. }
  62195. void ResizableWindow::setMinimised (const bool shouldMinimise)
  62196. {
  62197. if (shouldMinimise != isMinimised())
  62198. {
  62199. ComponentPeer* const peer = getPeer();
  62200. if (peer != 0)
  62201. {
  62202. updateLastPos();
  62203. peer->setMinimised (shouldMinimise);
  62204. }
  62205. else
  62206. {
  62207. jassertfalse
  62208. }
  62209. }
  62210. }
  62211. void ResizableWindow::updateLastPos()
  62212. {
  62213. if (isShowing() && ! (isFullScreen() || isMinimised()))
  62214. {
  62215. lastNonFullScreenPos = getBounds();
  62216. }
  62217. }
  62218. void ResizableWindow::parentSizeChanged()
  62219. {
  62220. if (isFullScreen() && getParentComponent() != 0)
  62221. {
  62222. setBounds (0, 0, getParentWidth(), getParentHeight());
  62223. }
  62224. }
  62225. const String ResizableWindow::getWindowStateAsString()
  62226. {
  62227. updateLastPos();
  62228. return (isFullScreen() ? "fs " : "") + lastNonFullScreenPos.toString();
  62229. }
  62230. bool ResizableWindow::restoreWindowStateFromString (const String& s)
  62231. {
  62232. StringArray tokens;
  62233. tokens.addTokens (s, false);
  62234. tokens.removeEmptyStrings();
  62235. tokens.trim();
  62236. const bool fs = tokens[0].startsWithIgnoreCase (T("fs"));
  62237. const int firstCoord = fs ? 1 : 0;
  62238. if (tokens.size() != firstCoord + 4)
  62239. return false;
  62240. Rectangle<int> newPos (tokens[firstCoord].getIntValue(),
  62241. tokens[firstCoord + 1].getIntValue(),
  62242. tokens[firstCoord + 2].getIntValue(),
  62243. tokens[firstCoord + 3].getIntValue());
  62244. if (newPos.isEmpty())
  62245. return false;
  62246. const Rectangle<int> screen (Desktop::getInstance().getMonitorAreaContaining (newPos.getCentre()));
  62247. ComponentPeer* const peer = isOnDesktop() ? getPeer() : 0;
  62248. if (peer != 0)
  62249. peer->getFrameSize().addTo (newPos);
  62250. if (! screen.contains (newPos))
  62251. {
  62252. newPos.setSize (jmin (newPos.getWidth(), screen.getWidth()),
  62253. jmin (newPos.getHeight(), screen.getHeight()));
  62254. newPos.setPosition (jlimit (screen.getX(), screen.getRight() - newPos.getWidth(), newPos.getX()),
  62255. jlimit (screen.getY(), screen.getBottom() - newPos.getHeight(), newPos.getY()));
  62256. }
  62257. if (peer != 0)
  62258. {
  62259. peer->getFrameSize().subtractFrom (newPos);
  62260. peer->setNonFullScreenBounds (newPos);
  62261. }
  62262. lastNonFullScreenPos = newPos;
  62263. setFullScreen (fs);
  62264. if (! fs)
  62265. setBoundsConstrained (newPos);
  62266. return true;
  62267. }
  62268. void ResizableWindow::mouseDown (const MouseEvent&)
  62269. {
  62270. if (! isFullScreen())
  62271. dragger.startDraggingComponent (this, constrainer);
  62272. }
  62273. void ResizableWindow::mouseDrag (const MouseEvent& e)
  62274. {
  62275. if (! isFullScreen())
  62276. dragger.dragComponent (this, e);
  62277. }
  62278. #ifdef JUCE_DEBUG
  62279. void ResizableWindow::addChildComponent (Component* const child, int zOrder)
  62280. {
  62281. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62282. manages its child components automatically, and if you add your own it'll cause
  62283. trouble. Instead, use setContentComponent() to give it a component which
  62284. will be automatically resized and kept in the right place - then you can add
  62285. subcomponents to the content comp. See the notes for the ResizableWindow class
  62286. for more info.
  62287. If you really know what you're doing and want to avoid this assertion, just call
  62288. Component::addChildComponent directly.
  62289. */
  62290. jassertfalse
  62291. Component::addChildComponent (child, zOrder);
  62292. }
  62293. void ResizableWindow::addAndMakeVisible (Component* const child, int zOrder)
  62294. {
  62295. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62296. manages its child components automatically, and if you add your own it'll cause
  62297. trouble. Instead, use setContentComponent() to give it a component which
  62298. will be automatically resized and kept in the right place - then you can add
  62299. subcomponents to the content comp. See the notes for the ResizableWindow class
  62300. for more info.
  62301. If you really know what you're doing and want to avoid this assertion, just call
  62302. Component::addAndMakeVisible directly.
  62303. */
  62304. jassertfalse
  62305. Component::addAndMakeVisible (child, zOrder);
  62306. }
  62307. #endif
  62308. END_JUCE_NAMESPACE
  62309. /*** End of inlined file: juce_ResizableWindow.cpp ***/
  62310. /*** Start of inlined file: juce_SplashScreen.cpp ***/
  62311. BEGIN_JUCE_NAMESPACE
  62312. SplashScreen::SplashScreen()
  62313. : backgroundImage (0)
  62314. {
  62315. setOpaque (true);
  62316. }
  62317. SplashScreen::~SplashScreen()
  62318. {
  62319. ImageCache::releaseOrDelete (backgroundImage);
  62320. }
  62321. void SplashScreen::show (const String& title,
  62322. Image* const backgroundImage_,
  62323. const int minimumTimeToDisplayFor,
  62324. const bool useDropShadow,
  62325. const bool removeOnMouseClick)
  62326. {
  62327. backgroundImage = backgroundImage_;
  62328. jassert (backgroundImage_ != 0);
  62329. if (backgroundImage_ != 0)
  62330. {
  62331. setOpaque (! backgroundImage_->hasAlphaChannel());
  62332. show (title,
  62333. backgroundImage_->getWidth(),
  62334. backgroundImage_->getHeight(),
  62335. minimumTimeToDisplayFor,
  62336. useDropShadow,
  62337. removeOnMouseClick);
  62338. }
  62339. }
  62340. void SplashScreen::show (const String& title,
  62341. const int width,
  62342. const int height,
  62343. const int minimumTimeToDisplayFor,
  62344. const bool useDropShadow,
  62345. const bool removeOnMouseClick)
  62346. {
  62347. setName (title);
  62348. setAlwaysOnTop (true);
  62349. setVisible (true);
  62350. centreWithSize (width, height);
  62351. addToDesktop (useDropShadow ? ComponentPeer::windowHasDropShadow : 0);
  62352. toFront (false);
  62353. MessageManager::getInstance()->runDispatchLoopUntil (300);
  62354. repaint();
  62355. originalClickCounter = removeOnMouseClick
  62356. ? Desktop::getMouseButtonClickCounter()
  62357. : std::numeric_limits<int>::max();
  62358. earliestTimeToDelete = Time::getCurrentTime() + RelativeTime::milliseconds (minimumTimeToDisplayFor);
  62359. startTimer (50);
  62360. }
  62361. void SplashScreen::paint (Graphics& g)
  62362. {
  62363. if (backgroundImage != 0)
  62364. {
  62365. g.setOpacity (1.0f);
  62366. g.drawImage (backgroundImage,
  62367. 0, 0, getWidth(), getHeight(),
  62368. 0, 0, backgroundImage->getWidth(), backgroundImage->getHeight());
  62369. }
  62370. }
  62371. void SplashScreen::timerCallback()
  62372. {
  62373. if (Time::getCurrentTime() > earliestTimeToDelete
  62374. || Desktop::getMouseButtonClickCounter() > originalClickCounter)
  62375. {
  62376. delete this;
  62377. }
  62378. }
  62379. END_JUCE_NAMESPACE
  62380. /*** End of inlined file: juce_SplashScreen.cpp ***/
  62381. /*** Start of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62382. BEGIN_JUCE_NAMESPACE
  62383. ThreadWithProgressWindow::ThreadWithProgressWindow (const String& title,
  62384. const bool hasProgressBar,
  62385. const bool hasCancelButton,
  62386. const int timeOutMsWhenCancelling_,
  62387. const String& cancelButtonText)
  62388. : Thread ("Juce Progress Window"),
  62389. progress (0.0),
  62390. timeOutMsWhenCancelling (timeOutMsWhenCancelling_)
  62391. {
  62392. alertWindow = LookAndFeel::getDefaultLookAndFeel()
  62393. .createAlertWindow (title, String::empty, cancelButtonText,
  62394. String::empty, String::empty,
  62395. AlertWindow::NoIcon, hasCancelButton ? 1 : 0, 0);
  62396. if (hasProgressBar)
  62397. alertWindow->addProgressBarComponent (progress);
  62398. }
  62399. ThreadWithProgressWindow::~ThreadWithProgressWindow()
  62400. {
  62401. stopThread (timeOutMsWhenCancelling);
  62402. }
  62403. bool ThreadWithProgressWindow::runThread (const int priority)
  62404. {
  62405. startThread (priority);
  62406. startTimer (100);
  62407. {
  62408. const ScopedLock sl (messageLock);
  62409. alertWindow->setMessage (message);
  62410. }
  62411. const bool finishedNaturally = alertWindow->runModalLoop() != 0;
  62412. stopThread (timeOutMsWhenCancelling);
  62413. alertWindow->setVisible (false);
  62414. return finishedNaturally;
  62415. }
  62416. void ThreadWithProgressWindow::setProgress (const double newProgress)
  62417. {
  62418. progress = newProgress;
  62419. }
  62420. void ThreadWithProgressWindow::setStatusMessage (const String& newStatusMessage)
  62421. {
  62422. const ScopedLock sl (messageLock);
  62423. message = newStatusMessage;
  62424. }
  62425. void ThreadWithProgressWindow::timerCallback()
  62426. {
  62427. if (! isThreadRunning())
  62428. {
  62429. // thread has finished normally..
  62430. alertWindow->exitModalState (1);
  62431. alertWindow->setVisible (false);
  62432. }
  62433. else
  62434. {
  62435. const ScopedLock sl (messageLock);
  62436. alertWindow->setMessage (message);
  62437. }
  62438. }
  62439. END_JUCE_NAMESPACE
  62440. /*** End of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62441. /*** Start of inlined file: juce_TooltipWindow.cpp ***/
  62442. BEGIN_JUCE_NAMESPACE
  62443. TooltipWindow::TooltipWindow (Component* const parentComponent,
  62444. const int millisecondsBeforeTipAppears_)
  62445. : Component ("tooltip"),
  62446. millisecondsBeforeTipAppears (millisecondsBeforeTipAppears_),
  62447. lastHideTime (0),
  62448. lastComponentUnderMouse (0),
  62449. changedCompsSinceShown (true)
  62450. {
  62451. if (Desktop::getInstance().getMainMouseSource().canHover())
  62452. startTimer (123);
  62453. setAlwaysOnTop (true);
  62454. setOpaque (true);
  62455. if (parentComponent != 0)
  62456. parentComponent->addChildComponent (this);
  62457. }
  62458. TooltipWindow::~TooltipWindow()
  62459. {
  62460. hide();
  62461. }
  62462. void TooltipWindow::setMillisecondsBeforeTipAppears (const int newTimeMs) throw()
  62463. {
  62464. millisecondsBeforeTipAppears = newTimeMs;
  62465. }
  62466. void TooltipWindow::paint (Graphics& g)
  62467. {
  62468. getLookAndFeel().drawTooltip (g, tipShowing, getWidth(), getHeight());
  62469. }
  62470. void TooltipWindow::mouseEnter (const MouseEvent&)
  62471. {
  62472. hide();
  62473. }
  62474. void TooltipWindow::showFor (const String& tip)
  62475. {
  62476. jassert (tip.isNotEmpty());
  62477. tipShowing = tip;
  62478. Point<int> mousePos (Desktop::getMousePosition());
  62479. if (getParentComponent() != 0)
  62480. mousePos = getParentComponent()->globalPositionToRelative (mousePos);
  62481. int x, y, w, h;
  62482. getLookAndFeel().getTooltipSize (tip, w, h);
  62483. if (mousePos.getX() > getParentWidth() / 2)
  62484. x = mousePos.getX() - (w + 12);
  62485. else
  62486. x = mousePos.getX() + 24;
  62487. if (mousePos.getY() > getParentHeight() / 2)
  62488. y = mousePos.getY() - (h + 6);
  62489. else
  62490. y = mousePos.getY() + 6;
  62491. setBounds (x, y, w, h);
  62492. setVisible (true);
  62493. if (getParentComponent() == 0)
  62494. {
  62495. addToDesktop (ComponentPeer::windowHasDropShadow
  62496. | ComponentPeer::windowIsTemporary
  62497. | ComponentPeer::windowIgnoresKeyPresses);
  62498. }
  62499. toFront (false);
  62500. }
  62501. const String TooltipWindow::getTipFor (Component* const c)
  62502. {
  62503. if (c != 0
  62504. && Process::isForegroundProcess()
  62505. && ! Component::isMouseButtonDownAnywhere())
  62506. {
  62507. TooltipClient* const ttc = dynamic_cast <TooltipClient*> (c);
  62508. if (ttc != 0 && ! c->isCurrentlyBlockedByAnotherModalComponent())
  62509. return ttc->getTooltip();
  62510. }
  62511. return String::empty;
  62512. }
  62513. void TooltipWindow::hide()
  62514. {
  62515. tipShowing = String::empty;
  62516. removeFromDesktop();
  62517. setVisible (false);
  62518. }
  62519. void TooltipWindow::timerCallback()
  62520. {
  62521. const unsigned int now = Time::getApproximateMillisecondCounter();
  62522. Component* const newComp = Desktop::getInstance().getMainMouseSource().getComponentUnderMouse();
  62523. const String newTip (getTipFor (newComp));
  62524. const bool tipChanged = (newTip != lastTipUnderMouse || newComp != lastComponentUnderMouse);
  62525. lastComponentUnderMouse = newComp;
  62526. lastTipUnderMouse = newTip;
  62527. const int clickCount = Desktop::getInstance().getMouseButtonClickCounter();
  62528. const bool mouseWasClicked = clickCount > mouseClicks;
  62529. mouseClicks = clickCount;
  62530. const Point<int> mousePos (Desktop::getMousePosition());
  62531. const bool mouseMovedQuickly = mousePos.getDistanceFrom (lastMousePos) > 12;
  62532. lastMousePos = mousePos;
  62533. if (tipChanged || mouseWasClicked || mouseMovedQuickly)
  62534. lastCompChangeTime = now;
  62535. if (isVisible() || now < lastHideTime + 500)
  62536. {
  62537. // if a tip is currently visible (or has just disappeared), update to a new one
  62538. // immediately if needed..
  62539. if (newComp == 0 || mouseWasClicked || newTip.isEmpty())
  62540. {
  62541. if (isVisible())
  62542. {
  62543. lastHideTime = now;
  62544. hide();
  62545. }
  62546. }
  62547. else if (tipChanged)
  62548. {
  62549. showFor (newTip);
  62550. }
  62551. }
  62552. else
  62553. {
  62554. // if there isn't currently a tip, but one is needed, only let it
  62555. // appear after a timeout..
  62556. if (newTip.isNotEmpty()
  62557. && newTip != tipShowing
  62558. && now > lastCompChangeTime + millisecondsBeforeTipAppears)
  62559. {
  62560. showFor (newTip);
  62561. }
  62562. }
  62563. }
  62564. END_JUCE_NAMESPACE
  62565. /*** End of inlined file: juce_TooltipWindow.cpp ***/
  62566. /*** Start of inlined file: juce_TopLevelWindow.cpp ***/
  62567. BEGIN_JUCE_NAMESPACE
  62568. class TopLevelWindowManager : public Timer,
  62569. public DeletedAtShutdown
  62570. {
  62571. public:
  62572. TopLevelWindowManager()
  62573. : currentActive (0)
  62574. {
  62575. }
  62576. ~TopLevelWindowManager()
  62577. {
  62578. clearSingletonInstance();
  62579. }
  62580. juce_DeclareSingleton_SingleThreaded_Minimal (TopLevelWindowManager)
  62581. void timerCallback()
  62582. {
  62583. startTimer (jmin (1731, getTimerInterval() * 2));
  62584. TopLevelWindow* active = 0;
  62585. if (Process::isForegroundProcess())
  62586. {
  62587. active = currentActive;
  62588. Component* const c = Component::getCurrentlyFocusedComponent();
  62589. TopLevelWindow* tlw = dynamic_cast <TopLevelWindow*> (c);
  62590. if (tlw == 0 && c != 0)
  62591. // (unable to use the syntax findParentComponentOfClass <TopLevelWindow> () because of a VC6 compiler bug)
  62592. tlw = c->findParentComponentOfClass ((TopLevelWindow*) 0);
  62593. if (tlw != 0)
  62594. active = tlw;
  62595. }
  62596. if (active != currentActive)
  62597. {
  62598. currentActive = active;
  62599. for (int i = windows.size(); --i >= 0;)
  62600. {
  62601. TopLevelWindow* const tlw = (TopLevelWindow*) windows.getUnchecked (i);
  62602. tlw->setWindowActive (isWindowActive (tlw));
  62603. i = jmin (i, windows.size() - 1);
  62604. }
  62605. Desktop::getInstance().triggerFocusCallback();
  62606. }
  62607. }
  62608. bool addWindow (TopLevelWindow* const w) throw()
  62609. {
  62610. windows.add (w);
  62611. startTimer (10);
  62612. return isWindowActive (w);
  62613. }
  62614. void removeWindow (TopLevelWindow* const w) throw()
  62615. {
  62616. startTimer (10);
  62617. if (currentActive == w)
  62618. currentActive = 0;
  62619. windows.removeValue (w);
  62620. if (windows.size() == 0)
  62621. deleteInstance();
  62622. }
  62623. VoidArray windows;
  62624. private:
  62625. TopLevelWindow* currentActive;
  62626. bool isWindowActive (TopLevelWindow* const tlw) const throw()
  62627. {
  62628. return (tlw == currentActive
  62629. || tlw->isParentOf (currentActive)
  62630. || tlw->hasKeyboardFocus (true))
  62631. && tlw->isShowing();
  62632. }
  62633. TopLevelWindowManager (const TopLevelWindowManager&);
  62634. TopLevelWindowManager& operator= (const TopLevelWindowManager&);
  62635. };
  62636. juce_ImplementSingleton_SingleThreaded (TopLevelWindowManager)
  62637. void juce_CheckCurrentlyFocusedTopLevelWindow()
  62638. {
  62639. if (TopLevelWindowManager::getInstanceWithoutCreating() != 0)
  62640. TopLevelWindowManager::getInstanceWithoutCreating()->startTimer (20);
  62641. }
  62642. TopLevelWindow::TopLevelWindow (const String& name,
  62643. const bool addToDesktop_)
  62644. : Component (name),
  62645. useDropShadow (true),
  62646. useNativeTitleBar (false),
  62647. windowIsActive_ (false)
  62648. {
  62649. setOpaque (true);
  62650. if (addToDesktop_)
  62651. Component::addToDesktop (getDesktopWindowStyleFlags());
  62652. else
  62653. setDropShadowEnabled (true);
  62654. setWantsKeyboardFocus (true);
  62655. setBroughtToFrontOnMouseClick (true);
  62656. windowIsActive_ = TopLevelWindowManager::getInstance()->addWindow (this);
  62657. }
  62658. TopLevelWindow::~TopLevelWindow()
  62659. {
  62660. shadower = 0;
  62661. TopLevelWindowManager::getInstance()->removeWindow (this);
  62662. }
  62663. void TopLevelWindow::focusOfChildComponentChanged (FocusChangeType)
  62664. {
  62665. if (hasKeyboardFocus (true))
  62666. TopLevelWindowManager::getInstance()->timerCallback();
  62667. else
  62668. TopLevelWindowManager::getInstance()->startTimer (10);
  62669. }
  62670. void TopLevelWindow::setWindowActive (const bool isNowActive) throw()
  62671. {
  62672. if (windowIsActive_ != isNowActive)
  62673. {
  62674. windowIsActive_ = isNowActive;
  62675. activeWindowStatusChanged();
  62676. }
  62677. }
  62678. void TopLevelWindow::activeWindowStatusChanged()
  62679. {
  62680. }
  62681. void TopLevelWindow::parentHierarchyChanged()
  62682. {
  62683. setDropShadowEnabled (useDropShadow);
  62684. }
  62685. void TopLevelWindow::visibilityChanged()
  62686. {
  62687. if (isShowing())
  62688. toFront (true);
  62689. }
  62690. int TopLevelWindow::getDesktopWindowStyleFlags() const
  62691. {
  62692. int flags = ComponentPeer::windowAppearsOnTaskbar;
  62693. if (useDropShadow)
  62694. flags |= ComponentPeer::windowHasDropShadow;
  62695. if (useNativeTitleBar)
  62696. flags |= ComponentPeer::windowHasTitleBar;
  62697. return flags;
  62698. }
  62699. void TopLevelWindow::setDropShadowEnabled (const bool useShadow)
  62700. {
  62701. useDropShadow = useShadow;
  62702. if (isOnDesktop())
  62703. {
  62704. shadower = 0;
  62705. Component::addToDesktop (getDesktopWindowStyleFlags());
  62706. }
  62707. else
  62708. {
  62709. if (useShadow && isOpaque())
  62710. {
  62711. if (shadower == 0)
  62712. {
  62713. shadower = getLookAndFeel().createDropShadowerForComponent (this);
  62714. if (shadower != 0)
  62715. shadower->setOwner (this);
  62716. }
  62717. }
  62718. else
  62719. {
  62720. shadower = 0;
  62721. }
  62722. }
  62723. }
  62724. void TopLevelWindow::setUsingNativeTitleBar (const bool useNativeTitleBar_)
  62725. {
  62726. if (useNativeTitleBar != useNativeTitleBar_)
  62727. {
  62728. useNativeTitleBar = useNativeTitleBar_;
  62729. recreateDesktopWindow();
  62730. sendLookAndFeelChange();
  62731. }
  62732. }
  62733. void TopLevelWindow::recreateDesktopWindow()
  62734. {
  62735. if (isOnDesktop())
  62736. {
  62737. Component::addToDesktop (getDesktopWindowStyleFlags());
  62738. toFront (true);
  62739. }
  62740. }
  62741. void TopLevelWindow::addToDesktop (int windowStyleFlags, void* nativeWindowToAttachTo)
  62742. {
  62743. /* It's not recommended to change the desktop window flags directly for a TopLevelWindow,
  62744. because this class needs to make sure its layout corresponds with settings like whether
  62745. it's got a native title bar or not.
  62746. If you need custom flags for your window, you can override the getDesktopWindowStyleFlags()
  62747. method. If you do this, it's best to call the base class's getDesktopWindowStyleFlags()
  62748. method, then add or remove whatever flags are necessary from this value before returning it.
  62749. */
  62750. jassert ((windowStyleFlags & ~ComponentPeer::windowIsSemiTransparent)
  62751. == (getDesktopWindowStyleFlags() & ~ComponentPeer::windowIsSemiTransparent));
  62752. Component::addToDesktop (windowStyleFlags, nativeWindowToAttachTo);
  62753. if (windowStyleFlags != getDesktopWindowStyleFlags())
  62754. sendLookAndFeelChange();
  62755. }
  62756. void TopLevelWindow::centreAroundComponent (Component* c, const int width, const int height)
  62757. {
  62758. if (c == 0)
  62759. c = TopLevelWindow::getActiveTopLevelWindow();
  62760. if (c == 0)
  62761. {
  62762. centreWithSize (width, height);
  62763. }
  62764. else
  62765. {
  62766. Point<int> p (c->relativePositionToGlobal (Point<int> ((c->getWidth() - width) / 2,
  62767. (c->getHeight() - height) / 2)));
  62768. Rectangle<int> parentArea (c->getParentMonitorArea());
  62769. if (getParentComponent() != 0)
  62770. {
  62771. p = getParentComponent()->globalPositionToRelative (p);
  62772. parentArea.setBounds (0, 0, getParentWidth(), getParentHeight());
  62773. }
  62774. parentArea.reduce (12, 12);
  62775. setBounds (jlimit (parentArea.getX(), jmax (parentArea.getX(), parentArea.getRight() - width), p.getX()),
  62776. jlimit (parentArea.getY(), jmax (parentArea.getY(), parentArea.getBottom() - height), p.getY()),
  62777. width, height);
  62778. }
  62779. }
  62780. int TopLevelWindow::getNumTopLevelWindows() throw()
  62781. {
  62782. return TopLevelWindowManager::getInstance()->windows.size();
  62783. }
  62784. TopLevelWindow* TopLevelWindow::getTopLevelWindow (const int index) throw()
  62785. {
  62786. return (TopLevelWindow*) TopLevelWindowManager::getInstance()->windows [index];
  62787. }
  62788. TopLevelWindow* TopLevelWindow::getActiveTopLevelWindow() throw()
  62789. {
  62790. TopLevelWindow* best = 0;
  62791. int bestNumTWLParents = -1;
  62792. for (int i = TopLevelWindow::getNumTopLevelWindows(); --i >= 0;)
  62793. {
  62794. TopLevelWindow* const tlw = TopLevelWindow::getTopLevelWindow (i);
  62795. if (tlw->isActiveWindow())
  62796. {
  62797. int numTWLParents = 0;
  62798. const Component* c = tlw->getParentComponent();
  62799. while (c != 0)
  62800. {
  62801. if (dynamic_cast <const TopLevelWindow*> (c) != 0)
  62802. ++numTWLParents;
  62803. c = c->getParentComponent();
  62804. }
  62805. if (bestNumTWLParents < numTWLParents)
  62806. {
  62807. best = tlw;
  62808. bestNumTWLParents = numTWLParents;
  62809. }
  62810. }
  62811. }
  62812. return best;
  62813. }
  62814. END_JUCE_NAMESPACE
  62815. /*** End of inlined file: juce_TopLevelWindow.cpp ***/
  62816. /*** Start of inlined file: juce_Colour.cpp ***/
  62817. BEGIN_JUCE_NAMESPACE
  62818. namespace ColourHelpers
  62819. {
  62820. static uint8 floatAlphaToInt (const float alpha) throw()
  62821. {
  62822. return (uint8) jlimit (0, 0xff, roundToInt (alpha * 255.0f));
  62823. }
  62824. static void convertHSBtoRGB (float h, float s, float v,
  62825. uint8& r, uint8& g, uint8& b) throw()
  62826. {
  62827. v = jlimit (0.0f, 1.0f, v);
  62828. v *= 255.0f;
  62829. const uint8 intV = (uint8) roundToInt (v);
  62830. if (s <= 0)
  62831. {
  62832. r = intV;
  62833. g = intV;
  62834. b = intV;
  62835. }
  62836. else
  62837. {
  62838. s = jmin (1.0f, s);
  62839. h = jlimit (0.0f, 1.0f, h);
  62840. h = (h - floorf (h)) * 6.0f + 0.00001f; // need a small adjustment to compensate for rounding errors
  62841. const float f = h - floorf (h);
  62842. const uint8 x = (uint8) roundToInt (v * (1.0f - s));
  62843. const float y = v * (1.0f - s * f);
  62844. const float z = v * (1.0f - (s * (1.0f - f)));
  62845. if (h < 1.0f)
  62846. {
  62847. r = intV;
  62848. g = (uint8) roundToInt (z);
  62849. b = x;
  62850. }
  62851. else if (h < 2.0f)
  62852. {
  62853. r = (uint8) roundToInt (y);
  62854. g = intV;
  62855. b = x;
  62856. }
  62857. else if (h < 3.0f)
  62858. {
  62859. r = x;
  62860. g = intV;
  62861. b = (uint8) roundToInt (z);
  62862. }
  62863. else if (h < 4.0f)
  62864. {
  62865. r = x;
  62866. g = (uint8) roundToInt (y);
  62867. b = intV;
  62868. }
  62869. else if (h < 5.0f)
  62870. {
  62871. r = (uint8) roundToInt (z);
  62872. g = x;
  62873. b = intV;
  62874. }
  62875. else if (h < 6.0f)
  62876. {
  62877. r = intV;
  62878. g = x;
  62879. b = (uint8) roundToInt (y);
  62880. }
  62881. else
  62882. {
  62883. r = 0;
  62884. g = 0;
  62885. b = 0;
  62886. }
  62887. }
  62888. }
  62889. }
  62890. Colour::Colour() throw()
  62891. : argb (0)
  62892. {
  62893. }
  62894. Colour::Colour (const Colour& other) throw()
  62895. : argb (other.argb)
  62896. {
  62897. }
  62898. Colour& Colour::operator= (const Colour& other) throw()
  62899. {
  62900. argb = other.argb;
  62901. return *this;
  62902. }
  62903. bool Colour::operator== (const Colour& other) const throw()
  62904. {
  62905. return argb.getARGB() == other.argb.getARGB();
  62906. }
  62907. bool Colour::operator!= (const Colour& other) const throw()
  62908. {
  62909. return argb.getARGB() != other.argb.getARGB();
  62910. }
  62911. Colour::Colour (const uint32 argb_) throw()
  62912. : argb (argb_)
  62913. {
  62914. }
  62915. Colour::Colour (const uint8 red,
  62916. const uint8 green,
  62917. const uint8 blue) throw()
  62918. {
  62919. argb.setARGB (0xff, red, green, blue);
  62920. }
  62921. const Colour Colour::fromRGB (const uint8 red,
  62922. const uint8 green,
  62923. const uint8 blue) throw()
  62924. {
  62925. return Colour (red, green, blue);
  62926. }
  62927. Colour::Colour (const uint8 red,
  62928. const uint8 green,
  62929. const uint8 blue,
  62930. const uint8 alpha) throw()
  62931. {
  62932. argb.setARGB (alpha, red, green, blue);
  62933. }
  62934. const Colour Colour::fromRGBA (const uint8 red,
  62935. const uint8 green,
  62936. const uint8 blue,
  62937. const uint8 alpha) throw()
  62938. {
  62939. return Colour (red, green, blue, alpha);
  62940. }
  62941. Colour::Colour (const uint8 red,
  62942. const uint8 green,
  62943. const uint8 blue,
  62944. const float alpha) throw()
  62945. {
  62946. argb.setARGB (ColourHelpers::floatAlphaToInt (alpha), red, green, blue);
  62947. }
  62948. const Colour Colour::fromRGBAFloat (const uint8 red,
  62949. const uint8 green,
  62950. const uint8 blue,
  62951. const float alpha) throw()
  62952. {
  62953. return Colour (red, green, blue, alpha);
  62954. }
  62955. Colour::Colour (const float hue,
  62956. const float saturation,
  62957. const float brightness,
  62958. const float alpha) throw()
  62959. {
  62960. uint8 r = getRed(), g = getGreen(), b = getBlue();
  62961. ColourHelpers::convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  62962. argb.setARGB (ColourHelpers::floatAlphaToInt (alpha), r, g, b);
  62963. }
  62964. const Colour Colour::fromHSV (const float hue,
  62965. const float saturation,
  62966. const float brightness,
  62967. const float alpha) throw()
  62968. {
  62969. return Colour (hue, saturation, brightness, alpha);
  62970. }
  62971. Colour::Colour (const float hue,
  62972. const float saturation,
  62973. const float brightness,
  62974. const uint8 alpha) throw()
  62975. {
  62976. uint8 r = getRed(), g = getGreen(), b = getBlue();
  62977. ColourHelpers::convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  62978. argb.setARGB (alpha, r, g, b);
  62979. }
  62980. Colour::~Colour() throw()
  62981. {
  62982. }
  62983. const PixelARGB Colour::getPixelARGB() const throw()
  62984. {
  62985. PixelARGB p (argb);
  62986. p.premultiply();
  62987. return p;
  62988. }
  62989. uint32 Colour::getARGB() const throw()
  62990. {
  62991. return argb.getARGB();
  62992. }
  62993. bool Colour::isTransparent() const throw()
  62994. {
  62995. return getAlpha() == 0;
  62996. }
  62997. bool Colour::isOpaque() const throw()
  62998. {
  62999. return getAlpha() == 0xff;
  63000. }
  63001. const Colour Colour::withAlpha (const uint8 newAlpha) const throw()
  63002. {
  63003. PixelARGB newCol (argb);
  63004. newCol.setAlpha (newAlpha);
  63005. return Colour (newCol.getARGB());
  63006. }
  63007. const Colour Colour::withAlpha (const float newAlpha) const throw()
  63008. {
  63009. jassert (newAlpha >= 0 && newAlpha <= 1.0f);
  63010. PixelARGB newCol (argb);
  63011. newCol.setAlpha (ColourHelpers::floatAlphaToInt (newAlpha));
  63012. return Colour (newCol.getARGB());
  63013. }
  63014. const Colour Colour::withMultipliedAlpha (const float alphaMultiplier) const throw()
  63015. {
  63016. jassert (alphaMultiplier >= 0);
  63017. PixelARGB newCol (argb);
  63018. newCol.setAlpha ((uint8) jmin (0xff, roundToInt (alphaMultiplier * newCol.getAlpha())));
  63019. return Colour (newCol.getARGB());
  63020. }
  63021. const Colour Colour::overlaidWith (const Colour& src) const throw()
  63022. {
  63023. const int destAlpha = getAlpha();
  63024. if (destAlpha > 0)
  63025. {
  63026. const int invA = 0xff - (int) src.getAlpha();
  63027. const int resA = 0xff - (((0xff - destAlpha) * invA) >> 8);
  63028. if (resA > 0)
  63029. {
  63030. const int da = (invA * destAlpha) / resA;
  63031. return Colour ((uint8) (src.getRed() + ((((int) getRed() - src.getRed()) * da) >> 8)),
  63032. (uint8) (src.getGreen() + ((((int) getGreen() - src.getGreen()) * da) >> 8)),
  63033. (uint8) (src.getBlue() + ((((int) getBlue() - src.getBlue()) * da) >> 8)),
  63034. (uint8) resA);
  63035. }
  63036. return *this;
  63037. }
  63038. else
  63039. {
  63040. return src;
  63041. }
  63042. }
  63043. const Colour Colour::interpolatedWith (const Colour& other, float proportionOfOther) const throw()
  63044. {
  63045. if (proportionOfOther <= 0)
  63046. return *this;
  63047. if (proportionOfOther >= 1.0f)
  63048. return other;
  63049. PixelARGB c1 (getPixelARGB());
  63050. const PixelARGB c2 (other.getPixelARGB());
  63051. c1.tween (c2, roundToInt (proportionOfOther * 255.0f));
  63052. c1.unpremultiply();
  63053. return Colour (c1.getARGB());
  63054. }
  63055. float Colour::getFloatRed() const throw()
  63056. {
  63057. return getRed() / 255.0f;
  63058. }
  63059. float Colour::getFloatGreen() const throw()
  63060. {
  63061. return getGreen() / 255.0f;
  63062. }
  63063. float Colour::getFloatBlue() const throw()
  63064. {
  63065. return getBlue() / 255.0f;
  63066. }
  63067. float Colour::getFloatAlpha() const throw()
  63068. {
  63069. return getAlpha() / 255.0f;
  63070. }
  63071. void Colour::getHSB (float& h, float& s, float& v) const throw()
  63072. {
  63073. const int r = getRed();
  63074. const int g = getGreen();
  63075. const int b = getBlue();
  63076. const int hi = jmax (r, g, b);
  63077. const int lo = jmin (r, g, b);
  63078. if (hi != 0)
  63079. {
  63080. s = (hi - lo) / (float) hi;
  63081. if (s != 0)
  63082. {
  63083. const float invDiff = 1.0f / (hi - lo);
  63084. const float red = (hi - r) * invDiff;
  63085. const float green = (hi - g) * invDiff;
  63086. const float blue = (hi - b) * invDiff;
  63087. if (r == hi)
  63088. h = blue - green;
  63089. else if (g == hi)
  63090. h = 2.0f + red - blue;
  63091. else
  63092. h = 4.0f + green - red;
  63093. h *= 1.0f / 6.0f;
  63094. if (h < 0)
  63095. ++h;
  63096. }
  63097. else
  63098. {
  63099. h = 0;
  63100. }
  63101. }
  63102. else
  63103. {
  63104. s = 0;
  63105. h = 0;
  63106. }
  63107. v = hi / 255.0f;
  63108. }
  63109. float Colour::getHue() const throw()
  63110. {
  63111. float h, s, b;
  63112. getHSB (h, s, b);
  63113. return h;
  63114. }
  63115. const Colour Colour::withHue (const float hue) const throw()
  63116. {
  63117. float h, s, b;
  63118. getHSB (h, s, b);
  63119. return Colour (hue, s, b, getAlpha());
  63120. }
  63121. const Colour Colour::withRotatedHue (const float amountToRotate) const throw()
  63122. {
  63123. float h, s, b;
  63124. getHSB (h, s, b);
  63125. h += amountToRotate;
  63126. h -= floorf (h);
  63127. return Colour (h, s, b, getAlpha());
  63128. }
  63129. float Colour::getSaturation() const throw()
  63130. {
  63131. float h, s, b;
  63132. getHSB (h, s, b);
  63133. return s;
  63134. }
  63135. const Colour Colour::withSaturation (const float saturation) const throw()
  63136. {
  63137. float h, s, b;
  63138. getHSB (h, s, b);
  63139. return Colour (h, saturation, b, getAlpha());
  63140. }
  63141. const Colour Colour::withMultipliedSaturation (const float amount) const throw()
  63142. {
  63143. float h, s, b;
  63144. getHSB (h, s, b);
  63145. return Colour (h, jmin (1.0f, s * amount), b, getAlpha());
  63146. }
  63147. float Colour::getBrightness() const throw()
  63148. {
  63149. float h, s, b;
  63150. getHSB (h, s, b);
  63151. return b;
  63152. }
  63153. const Colour Colour::withBrightness (const float brightness) const throw()
  63154. {
  63155. float h, s, b;
  63156. getHSB (h, s, b);
  63157. return Colour (h, s, brightness, getAlpha());
  63158. }
  63159. const Colour Colour::withMultipliedBrightness (const float amount) const throw()
  63160. {
  63161. float h, s, b;
  63162. getHSB (h, s, b);
  63163. b *= amount;
  63164. if (b > 1.0f)
  63165. b = 1.0f;
  63166. return Colour (h, s, b, getAlpha());
  63167. }
  63168. const Colour Colour::brighter (float amount) const throw()
  63169. {
  63170. amount = 1.0f / (1.0f + amount);
  63171. return Colour ((uint8) (255 - (amount * (255 - getRed()))),
  63172. (uint8) (255 - (amount * (255 - getGreen()))),
  63173. (uint8) (255 - (amount * (255 - getBlue()))),
  63174. getAlpha());
  63175. }
  63176. const Colour Colour::darker (float amount) const throw()
  63177. {
  63178. amount = 1.0f / (1.0f + amount);
  63179. return Colour ((uint8) (amount * getRed()),
  63180. (uint8) (amount * getGreen()),
  63181. (uint8) (amount * getBlue()),
  63182. getAlpha());
  63183. }
  63184. const Colour Colour::greyLevel (const float brightness) throw()
  63185. {
  63186. const uint8 level
  63187. = (uint8) jlimit (0x00, 0xff, roundToInt (brightness * 255.0f));
  63188. return Colour (level, level, level);
  63189. }
  63190. const Colour Colour::contrasting (const float amount) const throw()
  63191. {
  63192. return overlaidWith ((((int) getRed() + (int) getGreen() + (int) getBlue() >= 3 * 128)
  63193. ? Colours::black
  63194. : Colours::white).withAlpha (amount));
  63195. }
  63196. const Colour Colour::contrasting (const Colour& colour1,
  63197. const Colour& colour2) throw()
  63198. {
  63199. const float b1 = colour1.getBrightness();
  63200. const float b2 = colour2.getBrightness();
  63201. float best = 0.0f;
  63202. float bestDist = 0.0f;
  63203. for (float i = 0.0f; i < 1.0f; i += 0.02f)
  63204. {
  63205. const float d1 = fabsf (i - b1);
  63206. const float d2 = fabsf (i - b2);
  63207. const float dist = jmin (d1, d2, 1.0f - d1, 1.0f - d2);
  63208. if (dist > bestDist)
  63209. {
  63210. best = i;
  63211. bestDist = dist;
  63212. }
  63213. }
  63214. return colour1.overlaidWith (colour2.withMultipliedAlpha (0.5f))
  63215. .withBrightness (best);
  63216. }
  63217. const String Colour::toString() const
  63218. {
  63219. return String::toHexString ((int) argb.getARGB());
  63220. }
  63221. const Colour Colour::fromString (const String& encodedColourString)
  63222. {
  63223. return Colour ((uint32) encodedColourString.getHexValue32());
  63224. }
  63225. const String Colour::toDisplayString (const bool includeAlphaValue) const
  63226. {
  63227. return String::toHexString ((int) (argb.getARGB() & (includeAlphaValue ? 0xffffffff : 0xffffff)))
  63228. .paddedLeft ('0', includeAlphaValue ? 8 : 6)
  63229. .toUpperCase();
  63230. }
  63231. END_JUCE_NAMESPACE
  63232. /*** End of inlined file: juce_Colour.cpp ***/
  63233. /*** Start of inlined file: juce_ColourGradient.cpp ***/
  63234. BEGIN_JUCE_NAMESPACE
  63235. ColourGradient::ColourGradient() throw()
  63236. {
  63237. #ifdef JUCE_DEBUG
  63238. x1 = 987654.0f;
  63239. #endif
  63240. }
  63241. ColourGradient::ColourGradient (const Colour& colour1,
  63242. const float x1_,
  63243. const float y1_,
  63244. const Colour& colour2,
  63245. const float x2_,
  63246. const float y2_,
  63247. const bool isRadial_) throw()
  63248. : x1 (x1_),
  63249. y1 (y1_),
  63250. x2 (x2_),
  63251. y2 (y2_),
  63252. isRadial (isRadial_)
  63253. {
  63254. colours.add (0);
  63255. colours.add (colour1.getARGB());
  63256. colours.add (1 << 16);
  63257. colours.add (colour2.getARGB());
  63258. }
  63259. ColourGradient::~ColourGradient() throw()
  63260. {
  63261. }
  63262. void ColourGradient::clearColours() throw()
  63263. {
  63264. colours.clear();
  63265. }
  63266. void ColourGradient::addColour (const double proportionAlongGradient,
  63267. const Colour& colour) throw()
  63268. {
  63269. // must be within the two end-points
  63270. jassert (proportionAlongGradient >= 0 && proportionAlongGradient <= 1.0);
  63271. const uint32 pos = jlimit (0, 65535, roundToInt (proportionAlongGradient * 65536.0));
  63272. int i;
  63273. for (i = 0; i < colours.size(); i += 2)
  63274. if (colours.getUnchecked(i) > pos)
  63275. break;
  63276. colours.insert (i, pos);
  63277. colours.insert (i + 1, colour.getARGB());
  63278. }
  63279. void ColourGradient::multiplyOpacity (const float multiplier) throw()
  63280. {
  63281. for (int i = 1; i < colours.size(); i += 2)
  63282. {
  63283. const Colour c (colours.getUnchecked(i));
  63284. colours.set (i, c.withMultipliedAlpha (multiplier).getARGB());
  63285. }
  63286. }
  63287. int ColourGradient::getNumColours() const throw()
  63288. {
  63289. return colours.size() >> 1;
  63290. }
  63291. double ColourGradient::getColourPosition (const int index) const throw()
  63292. {
  63293. return jlimit (0.0, 1.0, colours [index << 1] / 65535.0);
  63294. }
  63295. const Colour ColourGradient::getColour (const int index) const throw()
  63296. {
  63297. return Colour (colours [(index << 1) + 1]);
  63298. }
  63299. const Colour ColourGradient::getColourAtPosition (const float position) const throw()
  63300. {
  63301. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63302. const int integerPos = jlimit (0, 65535, roundToInt (position * 65536.0f));
  63303. if (integerPos <= 0 || colours.size() <= 2)
  63304. return getColour (0);
  63305. int i = colours.size() - 2;
  63306. while (integerPos < (int) colours.getUnchecked(i))
  63307. i -= 2;
  63308. if (i >= colours.size() - 2)
  63309. return Colour (colours.getUnchecked(i));
  63310. const int pos1 = colours.getUnchecked (i);
  63311. const Colour col1 (colours.getUnchecked (i + 1));
  63312. const int pos2 = colours.getUnchecked (i + 2);
  63313. const Colour col2 (colours.getUnchecked (i + 3));
  63314. return col1.interpolatedWith (col2, (integerPos - pos1) / (float) (pos2 - pos1));
  63315. }
  63316. int ColourGradient::createLookupTable (const AffineTransform& transform, HeapBlock <PixelARGB>& lookupTable) const throw()
  63317. {
  63318. #ifdef JUCE_DEBUG
  63319. // trying to use the object without setting its co-ordinates? Have a careful read of
  63320. // the comments for the constructors.
  63321. jassert (x1 != 987654.0f);
  63322. #endif
  63323. const int numColours = colours.size() >> 1;
  63324. float tx1 = x1, ty1 = y1, tx2 = x2, ty2 = y2;
  63325. transform.transformPoint (tx1, ty1);
  63326. transform.transformPoint (tx2, ty2);
  63327. const double distance = juce_hypot (tx1 - tx2, ty1 - ty2);
  63328. const int numEntries = jlimit (1, (numColours - 1) << 8, 3 * (int) distance);
  63329. lookupTable.malloc (numEntries);
  63330. if (numColours >= 2)
  63331. {
  63332. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63333. PixelARGB pix1 (colours.getUnchecked (1));
  63334. pix1.premultiply();
  63335. int index = 0;
  63336. for (int j = 2; j < colours.size(); j += 2)
  63337. {
  63338. const int numToDo = ((colours.getUnchecked (j) * (numEntries - 1)) >> 16) - index;
  63339. PixelARGB pix2 (colours.getUnchecked (j + 1));
  63340. pix2.premultiply();
  63341. for (int i = 0; i < numToDo; ++i)
  63342. {
  63343. jassert (index >= 0 && index < numEntries);
  63344. lookupTable[index] = pix1;
  63345. lookupTable[index].tween (pix2, (i << 8) / numToDo);
  63346. ++index;
  63347. }
  63348. pix1 = pix2;
  63349. }
  63350. while (index < numEntries)
  63351. lookupTable [index++] = pix1;
  63352. }
  63353. else
  63354. {
  63355. jassertfalse // no colours specified!
  63356. }
  63357. return numEntries;
  63358. }
  63359. bool ColourGradient::isOpaque() const throw()
  63360. {
  63361. for (int i = 1; i < colours.size(); i += 2)
  63362. if (PixelARGB (colours.getUnchecked(i)).getAlpha() < 0xff)
  63363. return false;
  63364. return true;
  63365. }
  63366. bool ColourGradient::isInvisible() const throw()
  63367. {
  63368. for (int i = 1; i < colours.size(); i += 2)
  63369. if (PixelARGB (colours.getUnchecked(i)).getAlpha() > 0)
  63370. return false;
  63371. return true;
  63372. }
  63373. END_JUCE_NAMESPACE
  63374. /*** End of inlined file: juce_ColourGradient.cpp ***/
  63375. /*** Start of inlined file: juce_Colours.cpp ***/
  63376. BEGIN_JUCE_NAMESPACE
  63377. const Colour Colours::transparentBlack (0);
  63378. const Colour Colours::transparentWhite (0x00ffffff);
  63379. const Colour Colours::aliceblue (0xfff0f8ff);
  63380. const Colour Colours::antiquewhite (0xfffaebd7);
  63381. const Colour Colours::aqua (0xff00ffff);
  63382. const Colour Colours::aquamarine (0xff7fffd4);
  63383. const Colour Colours::azure (0xfff0ffff);
  63384. const Colour Colours::beige (0xfff5f5dc);
  63385. const Colour Colours::bisque (0xffffe4c4);
  63386. const Colour Colours::black (0xff000000);
  63387. const Colour Colours::blanchedalmond (0xffffebcd);
  63388. const Colour Colours::blue (0xff0000ff);
  63389. const Colour Colours::blueviolet (0xff8a2be2);
  63390. const Colour Colours::brown (0xffa52a2a);
  63391. const Colour Colours::burlywood (0xffdeb887);
  63392. const Colour Colours::cadetblue (0xff5f9ea0);
  63393. const Colour Colours::chartreuse (0xff7fff00);
  63394. const Colour Colours::chocolate (0xffd2691e);
  63395. const Colour Colours::coral (0xffff7f50);
  63396. const Colour Colours::cornflowerblue (0xff6495ed);
  63397. const Colour Colours::cornsilk (0xfffff8dc);
  63398. const Colour Colours::crimson (0xffdc143c);
  63399. const Colour Colours::cyan (0xff00ffff);
  63400. const Colour Colours::darkblue (0xff00008b);
  63401. const Colour Colours::darkcyan (0xff008b8b);
  63402. const Colour Colours::darkgoldenrod (0xffb8860b);
  63403. const Colour Colours::darkgrey (0xff555555);
  63404. const Colour Colours::darkgreen (0xff006400);
  63405. const Colour Colours::darkkhaki (0xffbdb76b);
  63406. const Colour Colours::darkmagenta (0xff8b008b);
  63407. const Colour Colours::darkolivegreen (0xff556b2f);
  63408. const Colour Colours::darkorange (0xffff8c00);
  63409. const Colour Colours::darkorchid (0xff9932cc);
  63410. const Colour Colours::darkred (0xff8b0000);
  63411. const Colour Colours::darksalmon (0xffe9967a);
  63412. const Colour Colours::darkseagreen (0xff8fbc8f);
  63413. const Colour Colours::darkslateblue (0xff483d8b);
  63414. const Colour Colours::darkslategrey (0xff2f4f4f);
  63415. const Colour Colours::darkturquoise (0xff00ced1);
  63416. const Colour Colours::darkviolet (0xff9400d3);
  63417. const Colour Colours::deeppink (0xffff1493);
  63418. const Colour Colours::deepskyblue (0xff00bfff);
  63419. const Colour Colours::dimgrey (0xff696969);
  63420. const Colour Colours::dodgerblue (0xff1e90ff);
  63421. const Colour Colours::firebrick (0xffb22222);
  63422. const Colour Colours::floralwhite (0xfffffaf0);
  63423. const Colour Colours::forestgreen (0xff228b22);
  63424. const Colour Colours::fuchsia (0xffff00ff);
  63425. const Colour Colours::gainsboro (0xffdcdcdc);
  63426. const Colour Colours::gold (0xffffd700);
  63427. const Colour Colours::goldenrod (0xffdaa520);
  63428. const Colour Colours::grey (0xff808080);
  63429. const Colour Colours::green (0xff008000);
  63430. const Colour Colours::greenyellow (0xffadff2f);
  63431. const Colour Colours::honeydew (0xfff0fff0);
  63432. const Colour Colours::hotpink (0xffff69b4);
  63433. const Colour Colours::indianred (0xffcd5c5c);
  63434. const Colour Colours::indigo (0xff4b0082);
  63435. const Colour Colours::ivory (0xfffffff0);
  63436. const Colour Colours::khaki (0xfff0e68c);
  63437. const Colour Colours::lavender (0xffe6e6fa);
  63438. const Colour Colours::lavenderblush (0xfffff0f5);
  63439. const Colour Colours::lemonchiffon (0xfffffacd);
  63440. const Colour Colours::lightblue (0xffadd8e6);
  63441. const Colour Colours::lightcoral (0xfff08080);
  63442. const Colour Colours::lightcyan (0xffe0ffff);
  63443. const Colour Colours::lightgoldenrodyellow (0xfffafad2);
  63444. const Colour Colours::lightgreen (0xff90ee90);
  63445. const Colour Colours::lightgrey (0xffd3d3d3);
  63446. const Colour Colours::lightpink (0xffffb6c1);
  63447. const Colour Colours::lightsalmon (0xffffa07a);
  63448. const Colour Colours::lightseagreen (0xff20b2aa);
  63449. const Colour Colours::lightskyblue (0xff87cefa);
  63450. const Colour Colours::lightslategrey (0xff778899);
  63451. const Colour Colours::lightsteelblue (0xffb0c4de);
  63452. const Colour Colours::lightyellow (0xffffffe0);
  63453. const Colour Colours::lime (0xff00ff00);
  63454. const Colour Colours::limegreen (0xff32cd32);
  63455. const Colour Colours::linen (0xfffaf0e6);
  63456. const Colour Colours::magenta (0xffff00ff);
  63457. const Colour Colours::maroon (0xff800000);
  63458. const Colour Colours::mediumaquamarine (0xff66cdaa);
  63459. const Colour Colours::mediumblue (0xff0000cd);
  63460. const Colour Colours::mediumorchid (0xffba55d3);
  63461. const Colour Colours::mediumpurple (0xff9370db);
  63462. const Colour Colours::mediumseagreen (0xff3cb371);
  63463. const Colour Colours::mediumslateblue (0xff7b68ee);
  63464. const Colour Colours::mediumspringgreen (0xff00fa9a);
  63465. const Colour Colours::mediumturquoise (0xff48d1cc);
  63466. const Colour Colours::mediumvioletred (0xffc71585);
  63467. const Colour Colours::midnightblue (0xff191970);
  63468. const Colour Colours::mintcream (0xfff5fffa);
  63469. const Colour Colours::mistyrose (0xffffe4e1);
  63470. const Colour Colours::navajowhite (0xffffdead);
  63471. const Colour Colours::navy (0xff000080);
  63472. const Colour Colours::oldlace (0xfffdf5e6);
  63473. const Colour Colours::olive (0xff808000);
  63474. const Colour Colours::olivedrab (0xff6b8e23);
  63475. const Colour Colours::orange (0xffffa500);
  63476. const Colour Colours::orangered (0xffff4500);
  63477. const Colour Colours::orchid (0xffda70d6);
  63478. const Colour Colours::palegoldenrod (0xffeee8aa);
  63479. const Colour Colours::palegreen (0xff98fb98);
  63480. const Colour Colours::paleturquoise (0xffafeeee);
  63481. const Colour Colours::palevioletred (0xffdb7093);
  63482. const Colour Colours::papayawhip (0xffffefd5);
  63483. const Colour Colours::peachpuff (0xffffdab9);
  63484. const Colour Colours::peru (0xffcd853f);
  63485. const Colour Colours::pink (0xffffc0cb);
  63486. const Colour Colours::plum (0xffdda0dd);
  63487. const Colour Colours::powderblue (0xffb0e0e6);
  63488. const Colour Colours::purple (0xff800080);
  63489. const Colour Colours::red (0xffff0000);
  63490. const Colour Colours::rosybrown (0xffbc8f8f);
  63491. const Colour Colours::royalblue (0xff4169e1);
  63492. const Colour Colours::saddlebrown (0xff8b4513);
  63493. const Colour Colours::salmon (0xfffa8072);
  63494. const Colour Colours::sandybrown (0xfff4a460);
  63495. const Colour Colours::seagreen (0xff2e8b57);
  63496. const Colour Colours::seashell (0xfffff5ee);
  63497. const Colour Colours::sienna (0xffa0522d);
  63498. const Colour Colours::silver (0xffc0c0c0);
  63499. const Colour Colours::skyblue (0xff87ceeb);
  63500. const Colour Colours::slateblue (0xff6a5acd);
  63501. const Colour Colours::slategrey (0xff708090);
  63502. const Colour Colours::snow (0xfffffafa);
  63503. const Colour Colours::springgreen (0xff00ff7f);
  63504. const Colour Colours::steelblue (0xff4682b4);
  63505. const Colour Colours::tan (0xffd2b48c);
  63506. const Colour Colours::teal (0xff008080);
  63507. const Colour Colours::thistle (0xffd8bfd8);
  63508. const Colour Colours::tomato (0xffff6347);
  63509. const Colour Colours::turquoise (0xff40e0d0);
  63510. const Colour Colours::violet (0xffee82ee);
  63511. const Colour Colours::wheat (0xfff5deb3);
  63512. const Colour Colours::white (0xffffffff);
  63513. const Colour Colours::whitesmoke (0xfff5f5f5);
  63514. const Colour Colours::yellow (0xffffff00);
  63515. const Colour Colours::yellowgreen (0xff9acd32);
  63516. const Colour Colours::findColourForName (const String& colourName,
  63517. const Colour& defaultColour)
  63518. {
  63519. static const int presets[] =
  63520. {
  63521. // (first value is the string's hashcode, second is ARGB)
  63522. 0x05978fff, 0xff000000, /* black */
  63523. 0x06bdcc29, 0xffffffff, /* white */
  63524. 0x002e305a, 0xff0000ff, /* blue */
  63525. 0x00308adf, 0xff808080, /* grey */
  63526. 0x05e0cf03, 0xff008000, /* green */
  63527. 0x0001b891, 0xffff0000, /* red */
  63528. 0xd43c6474, 0xffffff00, /* yellow */
  63529. 0x620886da, 0xfff0f8ff, /* aliceblue */
  63530. 0x20a2676a, 0xfffaebd7, /* antiquewhite */
  63531. 0x002dcebc, 0xff00ffff, /* aqua */
  63532. 0x46bb5f7e, 0xff7fffd4, /* aquamarine */
  63533. 0x0590228f, 0xfff0ffff, /* azure */
  63534. 0x05947fe4, 0xfff5f5dc, /* beige */
  63535. 0xad388e35, 0xffffe4c4, /* bisque */
  63536. 0x00674f7e, 0xffffebcd, /* blanchedalmond */
  63537. 0x39129959, 0xff8a2be2, /* blueviolet */
  63538. 0x059a8136, 0xffa52a2a, /* brown */
  63539. 0x89cea8f9, 0xffdeb887, /* burlywood */
  63540. 0x0fa260cf, 0xff5f9ea0, /* cadetblue */
  63541. 0x6b748956, 0xff7fff00, /* chartreuse */
  63542. 0x2903623c, 0xffd2691e, /* chocolate */
  63543. 0x05a74431, 0xffff7f50, /* coral */
  63544. 0x618d42dd, 0xff6495ed, /* cornflowerblue */
  63545. 0xe4b479fd, 0xfffff8dc, /* cornsilk */
  63546. 0x3d8c4edf, 0xffdc143c, /* crimson */
  63547. 0x002ed323, 0xff00ffff, /* cyan */
  63548. 0x67cc74d0, 0xff00008b, /* darkblue */
  63549. 0x67cd1799, 0xff008b8b, /* darkcyan */
  63550. 0x31bbd168, 0xffb8860b, /* darkgoldenrod */
  63551. 0x67cecf55, 0xff555555, /* darkgrey */
  63552. 0x920b194d, 0xff006400, /* darkgreen */
  63553. 0x923edd4c, 0xffbdb76b, /* darkkhaki */
  63554. 0x5c293873, 0xff8b008b, /* darkmagenta */
  63555. 0x6b6671fe, 0xff556b2f, /* darkolivegreen */
  63556. 0xbcfd2524, 0xffff8c00, /* darkorange */
  63557. 0xbcfdf799, 0xff9932cc, /* darkorchid */
  63558. 0x55ee0d5b, 0xff8b0000, /* darkred */
  63559. 0xc2e5f564, 0xffe9967a, /* darksalmon */
  63560. 0x61be858a, 0xff8fbc8f, /* darkseagreen */
  63561. 0xc2b0f2bd, 0xff483d8b, /* darkslateblue */
  63562. 0xc2b34d42, 0xff2f4f4f, /* darkslategrey */
  63563. 0x7cf2b06b, 0xff00ced1, /* darkturquoise */
  63564. 0xc8769375, 0xff9400d3, /* darkviolet */
  63565. 0x25832862, 0xffff1493, /* deeppink */
  63566. 0xfcad568f, 0xff00bfff, /* deepskyblue */
  63567. 0x634c8b67, 0xff696969, /* dimgrey */
  63568. 0x45c1ce55, 0xff1e90ff, /* dodgerblue */
  63569. 0xef19e3cb, 0xffb22222, /* firebrick */
  63570. 0xb852b195, 0xfffffaf0, /* floralwhite */
  63571. 0xd086fd06, 0xff228b22, /* forestgreen */
  63572. 0xe106b6d7, 0xffff00ff, /* fuchsia */
  63573. 0x7880d61e, 0xffdcdcdc, /* gainsboro */
  63574. 0x00308060, 0xffffd700, /* gold */
  63575. 0xb3b3bc1e, 0xffdaa520, /* goldenrod */
  63576. 0xbab8a537, 0xffadff2f, /* greenyellow */
  63577. 0xe4cacafb, 0xfff0fff0, /* honeydew */
  63578. 0x41892743, 0xffff69b4, /* hotpink */
  63579. 0xd5796f1a, 0xffcd5c5c, /* indianred */
  63580. 0xb969fed2, 0xff4b0082, /* indigo */
  63581. 0x05fef6a9, 0xfffffff0, /* ivory */
  63582. 0x06149302, 0xfff0e68c, /* khaki */
  63583. 0xad5a05c7, 0xffe6e6fa, /* lavender */
  63584. 0x7c4d5b99, 0xfffff0f5, /* lavenderblush */
  63585. 0x195756f0, 0xfffffacd, /* lemonchiffon */
  63586. 0x28e4ea70, 0xffadd8e6, /* lightblue */
  63587. 0xf3c7ccdb, 0xfff08080, /* lightcoral */
  63588. 0x28e58d39, 0xffe0ffff, /* lightcyan */
  63589. 0x21234e3c, 0xfffafad2, /* lightgoldenrodyellow */
  63590. 0xf40157ad, 0xff90ee90, /* lightgreen */
  63591. 0x28e744f5, 0xffd3d3d3, /* lightgrey */
  63592. 0x28eb3b8c, 0xffffb6c1, /* lightpink */
  63593. 0x9fb78304, 0xffffa07a, /* lightsalmon */
  63594. 0x50632b2a, 0xff20b2aa, /* lightseagreen */
  63595. 0x68fb7b25, 0xff87cefa, /* lightskyblue */
  63596. 0xa8a35ba2, 0xff778899, /* lightslategrey */
  63597. 0xa20d484f, 0xffb0c4de, /* lightsteelblue */
  63598. 0xaa2cf10a, 0xffffffe0, /* lightyellow */
  63599. 0x0032afd5, 0xff00ff00, /* lime */
  63600. 0x607bbc4e, 0xff32cd32, /* limegreen */
  63601. 0x06234efa, 0xfffaf0e6, /* linen */
  63602. 0x316858a9, 0xffff00ff, /* magenta */
  63603. 0xbf8ca470, 0xff800000, /* maroon */
  63604. 0xbd58e0b3, 0xff66cdaa, /* mediumaquamarine */
  63605. 0x967dfd4f, 0xff0000cd, /* mediumblue */
  63606. 0x056f5c58, 0xffba55d3, /* mediumorchid */
  63607. 0x07556b71, 0xff9370db, /* mediumpurple */
  63608. 0x5369b689, 0xff3cb371, /* mediumseagreen */
  63609. 0x066be19e, 0xff7b68ee, /* mediumslateblue */
  63610. 0x3256b281, 0xff00fa9a, /* mediumspringgreen */
  63611. 0xc0ad9f4c, 0xff48d1cc, /* mediumturquoise */
  63612. 0x628e63dd, 0xffc71585, /* mediumvioletred */
  63613. 0x168eb32a, 0xff191970, /* midnightblue */
  63614. 0x4306b960, 0xfff5fffa, /* mintcream */
  63615. 0x4cbc0e6b, 0xffffe4e1, /* mistyrose */
  63616. 0xe97218a6, 0xffffdead, /* navajowhite */
  63617. 0x00337bb6, 0xff000080, /* navy */
  63618. 0xadd2d33e, 0xfffdf5e6, /* oldlace */
  63619. 0x064ee1db, 0xff808000, /* olive */
  63620. 0x9e33a98a, 0xff6b8e23, /* olivedrab */
  63621. 0xc3de262e, 0xffffa500, /* orange */
  63622. 0x58bebba3, 0xffff4500, /* orangered */
  63623. 0xc3def8a3, 0xffda70d6, /* orchid */
  63624. 0x28cb4834, 0xffeee8aa, /* palegoldenrod */
  63625. 0x3d9dd619, 0xff98fb98, /* palegreen */
  63626. 0x74022737, 0xffafeeee, /* paleturquoise */
  63627. 0x15e2ebc8, 0xffdb7093, /* palevioletred */
  63628. 0x5fd898e2, 0xffffefd5, /* papayawhip */
  63629. 0x93e1b776, 0xffffdab9, /* peachpuff */
  63630. 0x003472f8, 0xffcd853f, /* peru */
  63631. 0x00348176, 0xffffc0cb, /* pink */
  63632. 0x00348d94, 0xffdda0dd, /* plum */
  63633. 0xd036be93, 0xffb0e0e6, /* powderblue */
  63634. 0xc5c507bc, 0xff800080, /* purple */
  63635. 0xa89d65b3, 0xffbc8f8f, /* rosybrown */
  63636. 0xbd9413e1, 0xff4169e1, /* royalblue */
  63637. 0xf456044f, 0xff8b4513, /* saddlebrown */
  63638. 0xc9c6f66e, 0xfffa8072, /* salmon */
  63639. 0x0bb131e1, 0xfff4a460, /* sandybrown */
  63640. 0x34636c14, 0xff2e8b57, /* seagreen */
  63641. 0x3507fb41, 0xfffff5ee, /* seashell */
  63642. 0xca348772, 0xffa0522d, /* sienna */
  63643. 0xca37d30d, 0xffc0c0c0, /* silver */
  63644. 0x80da74fb, 0xff87ceeb, /* skyblue */
  63645. 0x44a8dd73, 0xff6a5acd, /* slateblue */
  63646. 0x44ab37f8, 0xff708090, /* slategrey */
  63647. 0x0035f183, 0xfffffafa, /* snow */
  63648. 0xd5440d16, 0xff00ff7f, /* springgreen */
  63649. 0x3e1524a5, 0xff4682b4, /* steelblue */
  63650. 0x0001bfa1, 0xffd2b48c, /* tan */
  63651. 0x0036425c, 0xff008080, /* teal */
  63652. 0xafc8858f, 0xffd8bfd8, /* thistle */
  63653. 0xcc41600a, 0xffff6347, /* tomato */
  63654. 0xfeea9b21, 0xff40e0d0, /* turquoise */
  63655. 0xcf57947f, 0xffee82ee, /* violet */
  63656. 0x06bdbae7, 0xfff5deb3, /* wheat */
  63657. 0x10802ee6, 0xfff5f5f5, /* whitesmoke */
  63658. 0xe1b5130f, 0xff9acd32 /* yellowgreen */
  63659. };
  63660. const int hash = colourName.trim().toLowerCase().hashCode();
  63661. for (int i = 0; i < numElementsInArray (presets); i += 2)
  63662. if (presets [i] == hash)
  63663. return Colour (presets [i + 1]);
  63664. return defaultColour;
  63665. }
  63666. END_JUCE_NAMESPACE
  63667. /*** End of inlined file: juce_Colours.cpp ***/
  63668. /*** Start of inlined file: juce_EdgeTable.cpp ***/
  63669. BEGIN_JUCE_NAMESPACE
  63670. const int juce_edgeTableDefaultEdgesPerLine = 32;
  63671. EdgeTable::EdgeTable (const Rectangle<int>& bounds_,
  63672. const Path& path, const AffineTransform& transform)
  63673. : bounds (bounds_),
  63674. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63675. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63676. needToCheckEmptinesss (true)
  63677. {
  63678. table.malloc ((bounds.getHeight() + 1) * lineStrideElements);
  63679. int* t = table;
  63680. for (int i = bounds.getHeight(); --i >= 0;)
  63681. {
  63682. *t = 0;
  63683. t += lineStrideElements;
  63684. }
  63685. const int topLimit = bounds.getY() << 8;
  63686. const int heightLimit = bounds.getHeight() << 8;
  63687. const int leftLimit = bounds.getX() << 8;
  63688. const int rightLimit = bounds.getRight() << 8;
  63689. PathFlatteningIterator iter (path, transform);
  63690. while (iter.next())
  63691. {
  63692. int y1 = roundToInt (iter.y1 * 256.0f);
  63693. int y2 = roundToInt (iter.y2 * 256.0f);
  63694. if (y1 != y2)
  63695. {
  63696. y1 -= topLimit;
  63697. y2 -= topLimit;
  63698. const int startY = y1;
  63699. int direction = -1;
  63700. if (y1 > y2)
  63701. {
  63702. swapVariables (y1, y2);
  63703. direction = 1;
  63704. }
  63705. if (y1 < 0)
  63706. y1 = 0;
  63707. if (y2 > heightLimit)
  63708. y2 = heightLimit;
  63709. if (y1 < y2)
  63710. {
  63711. const double startX = 256.0f * iter.x1;
  63712. const double multiplier = (iter.x2 - iter.x1) / (iter.y2 - iter.y1);
  63713. const int stepSize = jlimit (1, 256, 256 / (1 + (int) fabs (multiplier)));
  63714. do
  63715. {
  63716. const int step = jmin (stepSize, y2 - y1, 256 - (y1 & 255));
  63717. int x = roundToInt (startX + multiplier * ((y1 + (step >> 1)) - startY));
  63718. if (x < leftLimit)
  63719. x = leftLimit;
  63720. else if (x >= rightLimit)
  63721. x = rightLimit - 1;
  63722. addEdgePoint (x, y1 >> 8, direction * step);
  63723. y1 += step;
  63724. }
  63725. while (y1 < y2);
  63726. }
  63727. }
  63728. }
  63729. sanitiseLevels (path.isUsingNonZeroWinding());
  63730. }
  63731. EdgeTable::EdgeTable (const Rectangle<int>& rectangleToAdd)
  63732. : bounds (rectangleToAdd),
  63733. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63734. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63735. needToCheckEmptinesss (true)
  63736. {
  63737. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63738. table[0] = 0;
  63739. const int x1 = rectangleToAdd.getX() << 8;
  63740. const int x2 = rectangleToAdd.getRight() << 8;
  63741. int* t = table;
  63742. for (int i = rectangleToAdd.getHeight(); --i >= 0;)
  63743. {
  63744. t[0] = 2;
  63745. t[1] = x1;
  63746. t[2] = 255;
  63747. t[3] = x2;
  63748. t[4] = 0;
  63749. t += lineStrideElements;
  63750. }
  63751. }
  63752. EdgeTable::EdgeTable (const RectangleList& rectanglesToAdd)
  63753. : bounds (rectanglesToAdd.getBounds()),
  63754. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63755. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63756. needToCheckEmptinesss (true)
  63757. {
  63758. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63759. int* t = table;
  63760. for (int i = bounds.getHeight(); --i >= 0;)
  63761. {
  63762. *t = 0;
  63763. t += lineStrideElements;
  63764. }
  63765. for (RectangleList::Iterator iter (rectanglesToAdd); iter.next();)
  63766. {
  63767. const Rectangle<int>* const r = iter.getRectangle();
  63768. const int x1 = r->getX() << 8;
  63769. const int x2 = r->getRight() << 8;
  63770. int y = r->getY() - bounds.getY();
  63771. for (int j = r->getHeight(); --j >= 0;)
  63772. {
  63773. addEdgePoint (x1, y, 255);
  63774. addEdgePoint (x2, y, -255);
  63775. ++y;
  63776. }
  63777. }
  63778. sanitiseLevels (true);
  63779. }
  63780. EdgeTable::EdgeTable (const float x, const float y, const float w, const float h)
  63781. : bounds (Rectangle<int> ((int) floorf (x), roundToInt (y * 256.0f) >> 8, 2 + (int) w, 2 + (int) h)),
  63782. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63783. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63784. needToCheckEmptinesss (true)
  63785. {
  63786. jassert (w > 0 && h > 0);
  63787. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63788. table[0] = 0;
  63789. const int x1 = roundToInt (x * 256.0f);
  63790. const int x2 = roundToInt ((x + w) * 256.0f);
  63791. int y1 = roundToInt (y * 256.0f) - (bounds.getY() << 8);
  63792. jassert (y1 < 256);
  63793. int y2 = roundToInt ((y + h) * 256.0f) - (bounds.getY() << 8);
  63794. if (x2 <= x1 || y2 <= y1)
  63795. {
  63796. bounds.setHeight (0);
  63797. return;
  63798. }
  63799. int lineY = 0;
  63800. int* t = table;
  63801. if ((y1 >> 8) == (y2 >> 8))
  63802. {
  63803. t[0] = 2;
  63804. t[1] = x1;
  63805. t[2] = y2 - y1;
  63806. t[3] = x2;
  63807. t[4] = 0;
  63808. ++lineY;
  63809. t += lineStrideElements;
  63810. }
  63811. else
  63812. {
  63813. t[0] = 2;
  63814. t[1] = x1;
  63815. t[2] = 255 - (y1 & 255);
  63816. t[3] = x2;
  63817. t[4] = 0;
  63818. ++lineY;
  63819. t += lineStrideElements;
  63820. while (lineY < (y2 >> 8))
  63821. {
  63822. t[0] = 2;
  63823. t[1] = x1;
  63824. t[2] = 255;
  63825. t[3] = x2;
  63826. t[4] = 0;
  63827. ++lineY;
  63828. t += lineStrideElements;
  63829. }
  63830. jassert (lineY < bounds.getHeight());
  63831. t[0] = 2;
  63832. t[1] = x1;
  63833. t[2] = y2 & 255;
  63834. t[3] = x2;
  63835. t[4] = 0;
  63836. ++lineY;
  63837. t += lineStrideElements;
  63838. }
  63839. while (lineY < bounds.getHeight())
  63840. {
  63841. t[0] = 0;
  63842. t += lineStrideElements;
  63843. ++lineY;
  63844. }
  63845. }
  63846. EdgeTable::EdgeTable (const EdgeTable& other)
  63847. : table (0)
  63848. {
  63849. operator= (other);
  63850. }
  63851. EdgeTable& EdgeTable::operator= (const EdgeTable& other)
  63852. {
  63853. bounds = other.bounds;
  63854. maxEdgesPerLine = other.maxEdgesPerLine;
  63855. lineStrideElements = other.lineStrideElements;
  63856. needToCheckEmptinesss = other.needToCheckEmptinesss;
  63857. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63858. copyEdgeTableData (table, lineStrideElements, other.table, lineStrideElements, bounds.getHeight());
  63859. return *this;
  63860. }
  63861. EdgeTable::~EdgeTable()
  63862. {
  63863. }
  63864. void EdgeTable::copyEdgeTableData (int* dest, const int destLineStride, const int* src, const int srcLineStride, int numLines) throw()
  63865. {
  63866. while (--numLines >= 0)
  63867. {
  63868. memcpy (dest, src, (src[0] * 2 + 1) * sizeof (int));
  63869. src += srcLineStride;
  63870. dest += destLineStride;
  63871. }
  63872. }
  63873. void EdgeTable::sanitiseLevels (const bool useNonZeroWinding) throw()
  63874. {
  63875. // Convert the table from relative windings to absolute levels..
  63876. int* lineStart = table;
  63877. for (int i = bounds.getHeight(); --i >= 0;)
  63878. {
  63879. int* line = lineStart;
  63880. lineStart += lineStrideElements;
  63881. int num = *line;
  63882. if (num == 0)
  63883. continue;
  63884. int level = 0;
  63885. if (useNonZeroWinding)
  63886. {
  63887. while (--num > 0)
  63888. {
  63889. line += 2;
  63890. level += *line;
  63891. int corrected = abs (level);
  63892. if (corrected >> 8)
  63893. corrected = 255;
  63894. *line = corrected;
  63895. }
  63896. }
  63897. else
  63898. {
  63899. while (--num > 0)
  63900. {
  63901. line += 2;
  63902. level += *line;
  63903. int corrected = abs (level);
  63904. if (corrected >> 8)
  63905. {
  63906. corrected &= 511;
  63907. if (corrected >> 8)
  63908. corrected = 511 - corrected;
  63909. }
  63910. *line = corrected;
  63911. }
  63912. }
  63913. line[2] = 0; // force the last level to 0, just in case something went wrong in creating the table
  63914. }
  63915. }
  63916. void EdgeTable::remapTableForNumEdges (const int newNumEdgesPerLine) throw()
  63917. {
  63918. if (newNumEdgesPerLine != maxEdgesPerLine)
  63919. {
  63920. maxEdgesPerLine = newNumEdgesPerLine;
  63921. jassert (bounds.getHeight() > 0);
  63922. const int newLineStrideElements = maxEdgesPerLine * 2 + 1;
  63923. HeapBlock <int> newTable (bounds.getHeight() * newLineStrideElements);
  63924. copyEdgeTableData (newTable, newLineStrideElements, table, lineStrideElements, bounds.getHeight());
  63925. table.swapWith (newTable);
  63926. lineStrideElements = newLineStrideElements;
  63927. }
  63928. }
  63929. void EdgeTable::optimiseTable() throw()
  63930. {
  63931. int maxLineElements = 0;
  63932. for (int i = bounds.getHeight(); --i >= 0;)
  63933. maxLineElements = jmax (maxLineElements, table [i * lineStrideElements]);
  63934. remapTableForNumEdges (maxLineElements);
  63935. }
  63936. void EdgeTable::addEdgePoint (const int x, const int y, const int winding) throw()
  63937. {
  63938. jassert (y >= 0 && y < bounds.getHeight());
  63939. int* line = table + lineStrideElements * y;
  63940. const int numPoints = line[0];
  63941. int n = numPoints << 1;
  63942. if (n > 0)
  63943. {
  63944. while (n > 0)
  63945. {
  63946. const int cx = line [n - 1];
  63947. if (cx <= x)
  63948. {
  63949. if (cx == x)
  63950. {
  63951. line [n] += winding;
  63952. return;
  63953. }
  63954. break;
  63955. }
  63956. n -= 2;
  63957. }
  63958. if (numPoints >= maxEdgesPerLine)
  63959. {
  63960. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  63961. jassert (numPoints < maxEdgesPerLine);
  63962. line = table + lineStrideElements * y;
  63963. }
  63964. memmove (line + (n + 3), line + (n + 1), sizeof (int) * ((numPoints << 1) - n));
  63965. }
  63966. line [n + 1] = x;
  63967. line [n + 2] = winding;
  63968. line[0]++;
  63969. }
  63970. void EdgeTable::translate (float dx, int dy) throw()
  63971. {
  63972. bounds.setPosition (bounds.getX() + (int) floorf (dx), bounds.getY() + dy);
  63973. int* lineStart = table;
  63974. const int intDx = (int) (dx * 256.0f);
  63975. for (int i = bounds.getHeight(); --i >= 0;)
  63976. {
  63977. int* line = lineStart;
  63978. lineStart += lineStrideElements;
  63979. int num = *line++;
  63980. while (--num >= 0)
  63981. {
  63982. *line += intDx;
  63983. line += 2;
  63984. }
  63985. }
  63986. }
  63987. void EdgeTable::intersectWithEdgeTableLine (const int y, const int* otherLine) throw()
  63988. {
  63989. jassert (y >= 0 && y < bounds.getHeight());
  63990. int* dest = table + lineStrideElements * y;
  63991. if (dest[0] == 0)
  63992. return;
  63993. int otherNumPoints = *otherLine;
  63994. if (otherNumPoints == 0)
  63995. {
  63996. *dest = 0;
  63997. return;
  63998. }
  63999. const int right = bounds.getRight() << 8;
  64000. // optimise for the common case where our line lies entirely within a
  64001. // single pair of points, as happens when clipping to a simple rect.
  64002. if (otherNumPoints == 2 && otherLine[2] >= 255)
  64003. {
  64004. clipEdgeTableLineToRange (dest, otherLine[1], jmin (right, otherLine[3]));
  64005. return;
  64006. }
  64007. ++otherLine;
  64008. const size_t lineSizeBytes = (dest[0] * 2 + 1) * sizeof (int);
  64009. int* temp = (int*) alloca (lineSizeBytes);
  64010. memcpy (temp, dest, lineSizeBytes);
  64011. const int* src1 = temp;
  64012. int srcNum1 = *src1++;
  64013. int x1 = *src1++;
  64014. const int* src2 = otherLine;
  64015. int srcNum2 = otherNumPoints;
  64016. int x2 = *src2++;
  64017. int destIndex = 0, destTotal = 0;
  64018. int level1 = 0, level2 = 0;
  64019. int lastX = std::numeric_limits<int>::min(), lastLevel = 0;
  64020. while (srcNum1 > 0 && srcNum2 > 0)
  64021. {
  64022. int nextX;
  64023. if (x1 < x2)
  64024. {
  64025. nextX = x1;
  64026. level1 = *src1++;
  64027. x1 = *src1++;
  64028. --srcNum1;
  64029. }
  64030. else if (x1 == x2)
  64031. {
  64032. nextX = x1;
  64033. level1 = *src1++;
  64034. level2 = *src2++;
  64035. x1 = *src1++;
  64036. x2 = *src2++;
  64037. --srcNum1;
  64038. --srcNum2;
  64039. }
  64040. else
  64041. {
  64042. nextX = x2;
  64043. level2 = *src2++;
  64044. x2 = *src2++;
  64045. --srcNum2;
  64046. }
  64047. if (nextX > lastX)
  64048. {
  64049. if (nextX >= right)
  64050. break;
  64051. lastX = nextX;
  64052. const int nextLevel = (level1 * (level2 + 1)) >> 8;
  64053. jassert (((unsigned int) nextLevel) < (unsigned int) 256);
  64054. if (nextLevel != lastLevel)
  64055. {
  64056. if (destTotal >= maxEdgesPerLine)
  64057. {
  64058. dest[0] = destTotal;
  64059. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64060. dest = table + lineStrideElements * y;
  64061. }
  64062. ++destTotal;
  64063. lastLevel = nextLevel;
  64064. dest[++destIndex] = nextX;
  64065. dest[++destIndex] = nextLevel;
  64066. }
  64067. }
  64068. }
  64069. if (lastLevel > 0)
  64070. {
  64071. if (destTotal >= maxEdgesPerLine)
  64072. {
  64073. dest[0] = destTotal;
  64074. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64075. dest = table + lineStrideElements * y;
  64076. }
  64077. ++destTotal;
  64078. dest[++destIndex] = right;
  64079. dest[++destIndex] = 0;
  64080. }
  64081. dest[0] = destTotal;
  64082. #if JUCE_DEBUG
  64083. int last = std::numeric_limits<int>::min();
  64084. for (int i = 0; i < dest[0]; ++i)
  64085. {
  64086. jassert (dest[i * 2 + 1] > last);
  64087. last = dest[i * 2 + 1];
  64088. }
  64089. jassert (dest [dest[0] * 2] == 0);
  64090. #endif
  64091. }
  64092. void EdgeTable::clipEdgeTableLineToRange (int* dest, const int x1, const int x2) throw()
  64093. {
  64094. int* lastItem = dest + (dest[0] * 2 - 1);
  64095. if (x2 < lastItem[0])
  64096. {
  64097. if (x2 <= dest[1])
  64098. {
  64099. dest[0] = 0;
  64100. return;
  64101. }
  64102. while (x2 < lastItem[-2])
  64103. {
  64104. --(dest[0]);
  64105. lastItem -= 2;
  64106. }
  64107. lastItem[0] = x2;
  64108. lastItem[1] = 0;
  64109. }
  64110. if (x1 > dest[1])
  64111. {
  64112. while (lastItem[0] > x1)
  64113. lastItem -= 2;
  64114. const int itemsRemoved = (int) (lastItem - (dest + 1)) / 2;
  64115. if (itemsRemoved > 0)
  64116. {
  64117. dest[0] -= itemsRemoved;
  64118. memmove (dest + 1, lastItem, dest[0] * (sizeof (int) * 2));
  64119. }
  64120. dest[1] = x1;
  64121. }
  64122. }
  64123. void EdgeTable::clipToRectangle (const Rectangle<int>& r) throw()
  64124. {
  64125. const Rectangle<int> clipped (r.getIntersection (bounds));
  64126. if (clipped.isEmpty())
  64127. {
  64128. needToCheckEmptinesss = false;
  64129. bounds.setHeight (0);
  64130. }
  64131. else
  64132. {
  64133. const int top = clipped.getY() - bounds.getY();
  64134. const int bottom = clipped.getBottom() - bounds.getY();
  64135. if (bottom < bounds.getHeight())
  64136. bounds.setHeight (bottom);
  64137. if (clipped.getRight() < bounds.getRight())
  64138. bounds.setRight (clipped.getRight());
  64139. for (int i = top; --i >= 0;)
  64140. table [lineStrideElements * i] = 0;
  64141. if (clipped.getX() > bounds.getX())
  64142. {
  64143. const int x1 = clipped.getX() << 8;
  64144. const int x2 = jmin (bounds.getRight(), clipped.getRight()) << 8;
  64145. int* line = table + lineStrideElements * top;
  64146. for (int i = bottom - top; --i >= 0;)
  64147. {
  64148. if (line[0] != 0)
  64149. clipEdgeTableLineToRange (line, x1, x2);
  64150. line += lineStrideElements;
  64151. }
  64152. }
  64153. needToCheckEmptinesss = true;
  64154. }
  64155. }
  64156. void EdgeTable::excludeRectangle (const Rectangle<int>& r) throw()
  64157. {
  64158. const Rectangle<int> clipped (r.getIntersection (bounds));
  64159. if (! clipped.isEmpty())
  64160. {
  64161. const int top = clipped.getY() - bounds.getY();
  64162. const int bottom = clipped.getBottom() - bounds.getY();
  64163. //XXX optimise here by shortening the table if it fills top or bottom
  64164. const int rectLine[] = { 4, std::numeric_limits<int>::min(), 255,
  64165. clipped.getX() << 8, 0,
  64166. clipped.getRight() << 8, 255,
  64167. std::numeric_limits<int>::max(), 0 };
  64168. for (int i = top; i < bottom; ++i)
  64169. intersectWithEdgeTableLine (i, rectLine);
  64170. needToCheckEmptinesss = true;
  64171. }
  64172. }
  64173. void EdgeTable::clipToEdgeTable (const EdgeTable& other)
  64174. {
  64175. const Rectangle<int> clipped (other.bounds.getIntersection (bounds));
  64176. if (clipped.isEmpty())
  64177. {
  64178. needToCheckEmptinesss = false;
  64179. bounds.setHeight (0);
  64180. }
  64181. else
  64182. {
  64183. const int top = clipped.getY() - bounds.getY();
  64184. const int bottom = clipped.getBottom() - bounds.getY();
  64185. if (bottom < bounds.getHeight())
  64186. bounds.setHeight (bottom);
  64187. if (clipped.getRight() < bounds.getRight())
  64188. bounds.setRight (clipped.getRight());
  64189. int i = 0;
  64190. for (i = top; --i >= 0;)
  64191. table [lineStrideElements * i] = 0;
  64192. const int* otherLine = other.table + other.lineStrideElements * (clipped.getY() - other.bounds.getY());
  64193. for (i = top; i < bottom; ++i)
  64194. {
  64195. intersectWithEdgeTableLine (i, otherLine);
  64196. otherLine += other.lineStrideElements;
  64197. }
  64198. needToCheckEmptinesss = true;
  64199. }
  64200. }
  64201. void EdgeTable::clipLineToMask (int x, int y, const uint8* mask, int maskStride, int numPixels) throw()
  64202. {
  64203. y -= bounds.getY();
  64204. if (y < 0 || y >= bounds.getHeight())
  64205. return;
  64206. needToCheckEmptinesss = true;
  64207. if (numPixels <= 0)
  64208. {
  64209. table [lineStrideElements * y] = 0;
  64210. return;
  64211. }
  64212. int* tempLine = (int*) alloca ((numPixels * 2 + 4) * sizeof (int));
  64213. int destIndex = 0, lastLevel = 0;
  64214. while (--numPixels >= 0)
  64215. {
  64216. const int alpha = *mask;
  64217. mask += maskStride;
  64218. if (alpha != lastLevel)
  64219. {
  64220. tempLine[++destIndex] = (x << 8);
  64221. tempLine[++destIndex] = alpha;
  64222. lastLevel = alpha;
  64223. }
  64224. ++x;
  64225. }
  64226. if (lastLevel > 0)
  64227. {
  64228. tempLine[++destIndex] = (x << 8);
  64229. tempLine[++destIndex] = 0;
  64230. }
  64231. tempLine[0] = destIndex >> 1;
  64232. intersectWithEdgeTableLine (y, tempLine);
  64233. }
  64234. bool EdgeTable::isEmpty() throw()
  64235. {
  64236. if (needToCheckEmptinesss)
  64237. {
  64238. needToCheckEmptinesss = false;
  64239. int* t = table;
  64240. for (int i = bounds.getHeight(); --i >= 0;)
  64241. {
  64242. if (t[0] > 1)
  64243. return false;
  64244. t += lineStrideElements;
  64245. }
  64246. bounds.setHeight (0);
  64247. }
  64248. return bounds.getHeight() == 0;
  64249. }
  64250. END_JUCE_NAMESPACE
  64251. /*** End of inlined file: juce_EdgeTable.cpp ***/
  64252. /*** Start of inlined file: juce_FillType.cpp ***/
  64253. BEGIN_JUCE_NAMESPACE
  64254. FillType::FillType() throw()
  64255. : colour (0xff000000), image (0)
  64256. {
  64257. }
  64258. FillType::FillType (const Colour& colour_) throw()
  64259. : colour (colour_), image (0)
  64260. {
  64261. }
  64262. FillType::FillType (const ColourGradient& gradient_) throw()
  64263. : colour (0xff000000), gradient (new ColourGradient (gradient_)), image (0)
  64264. {
  64265. }
  64266. FillType::FillType (const Image& image_, const AffineTransform& transform_) throw()
  64267. : colour (0xff000000), image (&image_), transform (transform_)
  64268. {
  64269. }
  64270. FillType::FillType (const FillType& other) throw()
  64271. : colour (other.colour),
  64272. gradient (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0),
  64273. image (other.image), transform (other.transform)
  64274. {
  64275. }
  64276. FillType& FillType::operator= (const FillType& other) throw()
  64277. {
  64278. if (this != &other)
  64279. {
  64280. colour = other.colour;
  64281. gradient = (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0);
  64282. image = other.image;
  64283. transform = other.transform;
  64284. }
  64285. return *this;
  64286. }
  64287. FillType::~FillType() throw()
  64288. {
  64289. }
  64290. void FillType::setColour (const Colour& newColour) throw()
  64291. {
  64292. gradient = 0;
  64293. image = 0;
  64294. colour = newColour;
  64295. }
  64296. void FillType::setGradient (const ColourGradient& newGradient) throw()
  64297. {
  64298. if (gradient != 0)
  64299. {
  64300. *gradient = newGradient;
  64301. }
  64302. else
  64303. {
  64304. image = 0;
  64305. gradient = new ColourGradient (newGradient);
  64306. colour = Colours::black;
  64307. }
  64308. }
  64309. void FillType::setTiledImage (const Image& image_, const AffineTransform& transform_) throw()
  64310. {
  64311. gradient = 0;
  64312. image = &image_;
  64313. transform = transform_;
  64314. colour = Colours::black;
  64315. }
  64316. void FillType::setOpacity (const float newOpacity) throw()
  64317. {
  64318. colour = colour.withAlpha (newOpacity);
  64319. }
  64320. END_JUCE_NAMESPACE
  64321. /*** End of inlined file: juce_FillType.cpp ***/
  64322. /*** Start of inlined file: juce_Graphics.cpp ***/
  64323. BEGIN_JUCE_NAMESPACE
  64324. static const Graphics::ResamplingQuality defaultQuality = Graphics::mediumResamplingQuality;
  64325. template <typename Type>
  64326. static bool areCoordsSensibleNumbers (Type x, Type y, Type w, Type h)
  64327. {
  64328. const int maxVal = 0x3fffffff;
  64329. return (int) x >= -maxVal && (int) x <= maxVal
  64330. && (int) y >= -maxVal && (int) y <= maxVal
  64331. && (int) w >= -maxVal && (int) w <= maxVal
  64332. && (int) h >= -maxVal && (int) h <= maxVal;
  64333. }
  64334. LowLevelGraphicsContext::LowLevelGraphicsContext()
  64335. {
  64336. }
  64337. LowLevelGraphicsContext::~LowLevelGraphicsContext()
  64338. {
  64339. }
  64340. Graphics::Graphics (Image& imageToDrawOnto) throw()
  64341. : context (imageToDrawOnto.createLowLevelContext()),
  64342. contextToDelete (context),
  64343. saveStatePending (false)
  64344. {
  64345. }
  64346. Graphics::Graphics (LowLevelGraphicsContext* const internalContext) throw()
  64347. : context (internalContext),
  64348. saveStatePending (false)
  64349. {
  64350. }
  64351. Graphics::~Graphics() throw()
  64352. {
  64353. }
  64354. void Graphics::resetToDefaultState() throw()
  64355. {
  64356. saveStateIfPending();
  64357. context->setFill (FillType());
  64358. context->setFont (Font());
  64359. context->setInterpolationQuality (defaultQuality);
  64360. }
  64361. bool Graphics::isVectorDevice() const throw()
  64362. {
  64363. return context->isVectorDevice();
  64364. }
  64365. bool Graphics::reduceClipRegion (const int x, const int y,
  64366. const int w, const int h) throw()
  64367. {
  64368. saveStateIfPending();
  64369. return context->clipToRectangle (Rectangle<int> (x, y, w, h));
  64370. }
  64371. bool Graphics::reduceClipRegion (const RectangleList& clipRegion) throw()
  64372. {
  64373. saveStateIfPending();
  64374. return context->clipToRectangleList (clipRegion);
  64375. }
  64376. bool Graphics::reduceClipRegion (const Path& path, const AffineTransform& transform) throw()
  64377. {
  64378. saveStateIfPending();
  64379. context->clipToPath (path, transform);
  64380. return ! context->isClipEmpty();
  64381. }
  64382. bool Graphics::reduceClipRegion (const Image& image, const Rectangle<int>& sourceClipRegion, const AffineTransform& transform) throw()
  64383. {
  64384. saveStateIfPending();
  64385. context->clipToImageAlpha (image, sourceClipRegion, transform);
  64386. return ! context->isClipEmpty();
  64387. }
  64388. void Graphics::excludeClipRegion (const Rectangle<int>& rectangleToExclude) throw()
  64389. {
  64390. saveStateIfPending();
  64391. context->excludeClipRectangle (rectangleToExclude);
  64392. }
  64393. bool Graphics::isClipEmpty() const throw()
  64394. {
  64395. return context->isClipEmpty();
  64396. }
  64397. const Rectangle<int> Graphics::getClipBounds() const throw()
  64398. {
  64399. return context->getClipBounds();
  64400. }
  64401. void Graphics::saveState() throw()
  64402. {
  64403. saveStateIfPending();
  64404. saveStatePending = true;
  64405. }
  64406. void Graphics::restoreState() throw()
  64407. {
  64408. if (saveStatePending)
  64409. saveStatePending = false;
  64410. else
  64411. context->restoreState();
  64412. }
  64413. void Graphics::saveStateIfPending() throw()
  64414. {
  64415. if (saveStatePending)
  64416. {
  64417. saveStatePending = false;
  64418. context->saveState();
  64419. }
  64420. }
  64421. void Graphics::setOrigin (const int newOriginX,
  64422. const int newOriginY) throw()
  64423. {
  64424. saveStateIfPending();
  64425. context->setOrigin (newOriginX, newOriginY);
  64426. }
  64427. bool Graphics::clipRegionIntersects (const int x, const int y,
  64428. const int w, const int h) const throw()
  64429. {
  64430. return context->clipRegionIntersects (Rectangle<int> (x, y, w, h));
  64431. }
  64432. void Graphics::setColour (const Colour& newColour) throw()
  64433. {
  64434. saveStateIfPending();
  64435. context->setFill (FillType (newColour));
  64436. }
  64437. void Graphics::setOpacity (const float newOpacity) throw()
  64438. {
  64439. saveStateIfPending();
  64440. context->setOpacity (newOpacity);
  64441. }
  64442. void Graphics::setGradientFill (const ColourGradient& gradient) throw()
  64443. {
  64444. saveStateIfPending();
  64445. context->setFill (FillType (gradient));
  64446. }
  64447. void Graphics::setTiledImageFill (const Image& imageToUse,
  64448. const int anchorX,
  64449. const int anchorY,
  64450. const float opacity) throw()
  64451. {
  64452. saveStateIfPending();
  64453. context->setFill (FillType (imageToUse, AffineTransform::translation ((float) anchorX, (float) anchorY)));
  64454. context->setOpacity (opacity);
  64455. }
  64456. void Graphics::setFillType (const FillType& newFill) throw()
  64457. {
  64458. saveStateIfPending();
  64459. context->setFill (newFill);
  64460. }
  64461. void Graphics::setFont (const Font& newFont) throw()
  64462. {
  64463. saveStateIfPending();
  64464. context->setFont (newFont);
  64465. }
  64466. void Graphics::setFont (const float newFontHeight,
  64467. const int newFontStyleFlags) throw()
  64468. {
  64469. saveStateIfPending();
  64470. Font f (context->getFont());
  64471. f.setSizeAndStyle (newFontHeight, newFontStyleFlags, 1.0f, 0);
  64472. context->setFont (f);
  64473. }
  64474. void Graphics::drawSingleLineText (const String& text,
  64475. const int startX,
  64476. const int baselineY) const throw()
  64477. {
  64478. if (text.isNotEmpty()
  64479. && startX < context->getClipBounds().getRight())
  64480. {
  64481. GlyphArrangement arr;
  64482. arr.addLineOfText (context->getFont(), text, (float) startX, (float) baselineY);
  64483. arr.draw (*this);
  64484. }
  64485. }
  64486. void Graphics::drawTextAsPath (const String& text,
  64487. const AffineTransform& transform) const throw()
  64488. {
  64489. if (text.isNotEmpty())
  64490. {
  64491. GlyphArrangement arr;
  64492. arr.addLineOfText (context->getFont(), text, 0.0f, 0.0f);
  64493. arr.draw (*this, transform);
  64494. }
  64495. }
  64496. void Graphics::drawMultiLineText (const String& text,
  64497. const int startX,
  64498. const int baselineY,
  64499. const int maximumLineWidth) const throw()
  64500. {
  64501. if (text.isNotEmpty()
  64502. && startX < context->getClipBounds().getRight())
  64503. {
  64504. GlyphArrangement arr;
  64505. arr.addJustifiedText (context->getFont(), text,
  64506. (float) startX, (float) baselineY, (float) maximumLineWidth,
  64507. Justification::left);
  64508. arr.draw (*this);
  64509. }
  64510. }
  64511. void Graphics::drawText (const String& text,
  64512. const int x,
  64513. const int y,
  64514. const int width,
  64515. const int height,
  64516. const Justification& justificationType,
  64517. const bool useEllipsesIfTooBig) const throw()
  64518. {
  64519. if (text.isNotEmpty() && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  64520. {
  64521. GlyphArrangement arr;
  64522. arr.addCurtailedLineOfText (context->getFont(), text,
  64523. 0.0f, 0.0f, (float)width,
  64524. useEllipsesIfTooBig);
  64525. arr.justifyGlyphs (0, arr.getNumGlyphs(),
  64526. (float) x, (float) y,
  64527. (float) width, (float) height,
  64528. justificationType);
  64529. arr.draw (*this);
  64530. }
  64531. }
  64532. void Graphics::drawFittedText (const String& text,
  64533. const int x,
  64534. const int y,
  64535. const int width,
  64536. const int height,
  64537. const Justification& justification,
  64538. const int maximumNumberOfLines,
  64539. const float minimumHorizontalScale) const throw()
  64540. {
  64541. if (text.isNotEmpty()
  64542. && width > 0 && height > 0
  64543. && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  64544. {
  64545. GlyphArrangement arr;
  64546. arr.addFittedText (context->getFont(), text,
  64547. (float) x, (float) y,
  64548. (float) width, (float) height,
  64549. justification,
  64550. maximumNumberOfLines,
  64551. minimumHorizontalScale);
  64552. arr.draw (*this);
  64553. }
  64554. }
  64555. void Graphics::fillRect (int x,
  64556. int y,
  64557. int width,
  64558. int height) const throw()
  64559. {
  64560. // passing in a silly number can cause maths problems in rendering!
  64561. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64562. context->fillRect (Rectangle<int> (x, y, width, height), false);
  64563. }
  64564. void Graphics::fillRect (const Rectangle<int>& r) const throw()
  64565. {
  64566. context->fillRect (r, false);
  64567. }
  64568. void Graphics::fillRect (const float x,
  64569. const float y,
  64570. const float width,
  64571. const float height) const throw()
  64572. {
  64573. // passing in a silly number can cause maths problems in rendering!
  64574. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64575. Path p;
  64576. p.addRectangle (x, y, width, height);
  64577. fillPath (p);
  64578. }
  64579. void Graphics::setPixel (int x, int y) const throw()
  64580. {
  64581. context->fillRect (Rectangle<int> (x, y, 1, 1), false);
  64582. }
  64583. void Graphics::fillAll() const throw()
  64584. {
  64585. fillRect (context->getClipBounds());
  64586. }
  64587. void Graphics::fillAll (const Colour& colourToUse) const throw()
  64588. {
  64589. if (! colourToUse.isTransparent())
  64590. {
  64591. const Rectangle<int> clip (context->getClipBounds());
  64592. context->saveState();
  64593. context->setFill (FillType (colourToUse));
  64594. context->fillRect (clip, false);
  64595. context->restoreState();
  64596. }
  64597. }
  64598. void Graphics::fillPath (const Path& path,
  64599. const AffineTransform& transform) const throw()
  64600. {
  64601. if ((! context->isClipEmpty()) && ! path.isEmpty())
  64602. context->fillPath (path, transform);
  64603. }
  64604. void Graphics::strokePath (const Path& path,
  64605. const PathStrokeType& strokeType,
  64606. const AffineTransform& transform) const throw()
  64607. {
  64608. Path stroke;
  64609. strokeType.createStrokedPath (stroke, path, transform);
  64610. fillPath (stroke);
  64611. }
  64612. void Graphics::drawRect (const int x,
  64613. const int y,
  64614. const int width,
  64615. const int height,
  64616. const int lineThickness) const throw()
  64617. {
  64618. // passing in a silly number can cause maths problems in rendering!
  64619. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64620. context->fillRect (Rectangle<int> (x, y, width, lineThickness), false);
  64621. context->fillRect (Rectangle<int> (x, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  64622. context->fillRect (Rectangle<int> (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  64623. context->fillRect (Rectangle<int> (x, y + height - lineThickness, width, lineThickness), false);
  64624. }
  64625. void Graphics::drawRect (const float x,
  64626. const float y,
  64627. const float width,
  64628. const float height,
  64629. const float lineThickness) const throw()
  64630. {
  64631. // passing in a silly number can cause maths problems in rendering!
  64632. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64633. Path p;
  64634. p.addRectangle (x, y, width, lineThickness);
  64635. p.addRectangle (x, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  64636. p.addRectangle (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  64637. p.addRectangle (x, y + height - lineThickness, width, lineThickness);
  64638. fillPath (p);
  64639. }
  64640. void Graphics::drawRect (const Rectangle<int>& r,
  64641. const int lineThickness) const throw()
  64642. {
  64643. drawRect (r.getX(), r.getY(),
  64644. r.getWidth(), r.getHeight(),
  64645. lineThickness);
  64646. }
  64647. void Graphics::drawBevel (const int x,
  64648. const int y,
  64649. const int width,
  64650. const int height,
  64651. const int bevelThickness,
  64652. const Colour& topLeftColour,
  64653. const Colour& bottomRightColour,
  64654. const bool useGradient,
  64655. const bool sharpEdgeOnOutside) const throw()
  64656. {
  64657. // passing in a silly number can cause maths problems in rendering!
  64658. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64659. if (clipRegionIntersects (x, y, width, height))
  64660. {
  64661. context->saveState();
  64662. const float oldOpacity = 1.0f;//xxx state->colour.getFloatAlpha();
  64663. const float ramp = oldOpacity / bevelThickness;
  64664. for (int i = bevelThickness; --i >= 0;)
  64665. {
  64666. const float op = useGradient ? ramp * (sharpEdgeOnOutside ? bevelThickness - i : i)
  64667. : oldOpacity;
  64668. context->setFill (FillType (topLeftColour.withMultipliedAlpha (op)));
  64669. context->fillRect (Rectangle<int> (x + i, y + i, width - i * 2, 1), false);
  64670. context->setFill (FillType (topLeftColour.withMultipliedAlpha (op * 0.75f)));
  64671. context->fillRect (Rectangle<int> (x + i, y + i + 1, 1, height - i * 2 - 2), false);
  64672. context->setFill (FillType (bottomRightColour.withMultipliedAlpha (op)));
  64673. context->fillRect (Rectangle<int> (x + i, y + height - i - 1, width - i * 2, 1), false);
  64674. context->setFill (FillType (bottomRightColour.withMultipliedAlpha (op * 0.75f)));
  64675. context->fillRect (Rectangle<int> (x + width - i - 1, y + i + 1, 1, height - i * 2 - 2), false);
  64676. }
  64677. context->restoreState();
  64678. }
  64679. }
  64680. void Graphics::fillEllipse (const float x,
  64681. const float y,
  64682. const float width,
  64683. const float height) const throw()
  64684. {
  64685. // passing in a silly number can cause maths problems in rendering!
  64686. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64687. Path p;
  64688. p.addEllipse (x, y, width, height);
  64689. fillPath (p);
  64690. }
  64691. void Graphics::drawEllipse (const float x,
  64692. const float y,
  64693. const float width,
  64694. const float height,
  64695. const float lineThickness) const throw()
  64696. {
  64697. // passing in a silly number can cause maths problems in rendering!
  64698. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64699. Path p;
  64700. p.addEllipse (x, y, width, height);
  64701. strokePath (p, PathStrokeType (lineThickness));
  64702. }
  64703. void Graphics::fillRoundedRectangle (const float x,
  64704. const float y,
  64705. const float width,
  64706. const float height,
  64707. const float cornerSize) const throw()
  64708. {
  64709. // passing in a silly number can cause maths problems in rendering!
  64710. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64711. Path p;
  64712. p.addRoundedRectangle (x, y, width, height, cornerSize);
  64713. fillPath (p);
  64714. }
  64715. void Graphics::fillRoundedRectangle (const Rectangle<int>& r,
  64716. const float cornerSize) const throw()
  64717. {
  64718. fillRoundedRectangle ((float) r.getX(),
  64719. (float) r.getY(),
  64720. (float) r.getWidth(),
  64721. (float) r.getHeight(),
  64722. cornerSize);
  64723. }
  64724. void Graphics::drawRoundedRectangle (const float x,
  64725. const float y,
  64726. const float width,
  64727. const float height,
  64728. const float cornerSize,
  64729. const float lineThickness) const throw()
  64730. {
  64731. // passing in a silly number can cause maths problems in rendering!
  64732. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64733. Path p;
  64734. p.addRoundedRectangle (x, y, width, height, cornerSize);
  64735. strokePath (p, PathStrokeType (lineThickness));
  64736. }
  64737. void Graphics::drawRoundedRectangle (const Rectangle<int>& r,
  64738. const float cornerSize,
  64739. const float lineThickness) const throw()
  64740. {
  64741. drawRoundedRectangle ((float) r.getX(),
  64742. (float) r.getY(),
  64743. (float) r.getWidth(),
  64744. (float) r.getHeight(),
  64745. cornerSize, lineThickness);
  64746. }
  64747. void Graphics::drawArrow (const float startX,
  64748. const float startY,
  64749. const float endX,
  64750. const float endY,
  64751. const float lineThickness,
  64752. const float arrowheadWidth,
  64753. const float arrowheadLength) const throw()
  64754. {
  64755. Path p;
  64756. p.addArrow (startX, startY, endX, endY,
  64757. lineThickness, arrowheadWidth, arrowheadLength);
  64758. fillPath (p);
  64759. }
  64760. void Graphics::fillCheckerBoard (int x, int y,
  64761. int width, int height,
  64762. const int checkWidth,
  64763. const int checkHeight,
  64764. const Colour& colour1,
  64765. const Colour& colour2) const throw()
  64766. {
  64767. jassert (checkWidth > 0 && checkHeight > 0); // can't be zero or less!
  64768. if (checkWidth > 0 && checkHeight > 0)
  64769. {
  64770. context->saveState();
  64771. if (colour1 == colour2)
  64772. {
  64773. context->setFill (FillType (colour1));
  64774. context->fillRect (Rectangle<int> (x, y, width, height), false);
  64775. }
  64776. else
  64777. {
  64778. const Rectangle<int> clip (context->getClipBounds());
  64779. const int right = jmin (x + width, clip.getRight());
  64780. const int bottom = jmin (y + height, clip.getBottom());
  64781. int cy = 0;
  64782. while (y < bottom)
  64783. {
  64784. int cx = cy;
  64785. for (int xx = x; xx < right; xx += checkWidth)
  64786. {
  64787. context->setFill (FillType (((cx++ & 1) == 0) ? colour1 : colour2));
  64788. context->fillRect (Rectangle<int> (xx, y, jmin (checkWidth, right - xx), jmin (checkHeight, bottom - y)),
  64789. false);
  64790. }
  64791. ++cy;
  64792. y += checkHeight;
  64793. }
  64794. }
  64795. context->restoreState();
  64796. }
  64797. }
  64798. void Graphics::drawVerticalLine (const int x, float top, float bottom) const throw()
  64799. {
  64800. context->drawVerticalLine (x, top, bottom);
  64801. }
  64802. void Graphics::drawHorizontalLine (const int y, float left, float right) const throw()
  64803. {
  64804. context->drawHorizontalLine (y, left, right);
  64805. }
  64806. void Graphics::drawLine (float x1, float y1, float x2, float y2) const throw()
  64807. {
  64808. context->drawLine (x1, y1, x2, y2);
  64809. }
  64810. void Graphics::drawLine (const float startX,
  64811. const float startY,
  64812. const float endX,
  64813. const float endY,
  64814. const float lineThickness) const throw()
  64815. {
  64816. Path p;
  64817. p.addLineSegment (startX, startY, endX, endY, lineThickness);
  64818. fillPath (p);
  64819. }
  64820. void Graphics::drawLine (const Line& line) const throw()
  64821. {
  64822. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY());
  64823. }
  64824. void Graphics::drawLine (const Line& line,
  64825. const float lineThickness) const throw()
  64826. {
  64827. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY(), lineThickness);
  64828. }
  64829. void Graphics::drawDashedLine (const float startX,
  64830. const float startY,
  64831. const float endX,
  64832. const float endY,
  64833. const float* const dashLengths,
  64834. const int numDashLengths,
  64835. const float lineThickness) const throw()
  64836. {
  64837. const double dx = endX - startX;
  64838. const double dy = endY - startY;
  64839. const double totalLen = juce_hypot (dx, dy);
  64840. if (totalLen >= 0.5)
  64841. {
  64842. const double onePixAlpha = 1.0 / totalLen;
  64843. double alpha = 0.0;
  64844. float x = startX;
  64845. float y = startY;
  64846. int n = 0;
  64847. while (alpha < 1.0f)
  64848. {
  64849. alpha = jmin (1.0, alpha + dashLengths[n++] * onePixAlpha);
  64850. n = n % numDashLengths;
  64851. const float oldX = x;
  64852. const float oldY = y;
  64853. x = (float) (startX + dx * alpha);
  64854. y = (float) (startY + dy * alpha);
  64855. if ((n & 1) != 0)
  64856. {
  64857. if (lineThickness != 1.0f)
  64858. drawLine (oldX, oldY, x, y, lineThickness);
  64859. else
  64860. drawLine (oldX, oldY, x, y);
  64861. }
  64862. }
  64863. }
  64864. }
  64865. void Graphics::setImageResamplingQuality (const Graphics::ResamplingQuality newQuality) throw()
  64866. {
  64867. saveStateIfPending();
  64868. context->setInterpolationQuality (newQuality);
  64869. }
  64870. void Graphics::drawImageAt (const Image* const imageToDraw,
  64871. const int topLeftX,
  64872. const int topLeftY,
  64873. const bool fillAlphaChannelWithCurrentBrush) const throw()
  64874. {
  64875. if (imageToDraw != 0)
  64876. {
  64877. const int imageW = imageToDraw->getWidth();
  64878. const int imageH = imageToDraw->getHeight();
  64879. drawImage (imageToDraw,
  64880. topLeftX, topLeftY, imageW, imageH,
  64881. 0, 0, imageW, imageH,
  64882. fillAlphaChannelWithCurrentBrush);
  64883. }
  64884. }
  64885. void Graphics::drawImageWithin (const Image* const imageToDraw,
  64886. const int destX,
  64887. const int destY,
  64888. const int destW,
  64889. const int destH,
  64890. const RectanglePlacement& placementWithinTarget,
  64891. const bool fillAlphaChannelWithCurrentBrush) const throw()
  64892. {
  64893. // passing in a silly number can cause maths problems in rendering!
  64894. jassert (areCoordsSensibleNumbers (destX, destY, destW, destH));
  64895. if (imageToDraw != 0)
  64896. {
  64897. const int imageW = imageToDraw->getWidth();
  64898. const int imageH = imageToDraw->getHeight();
  64899. if (imageW > 0 && imageH > 0)
  64900. {
  64901. double newX = 0.0, newY = 0.0;
  64902. double newW = imageW;
  64903. double newH = imageH;
  64904. placementWithinTarget.applyTo (newX, newY, newW, newH,
  64905. destX, destY, destW, destH);
  64906. if (newW > 0 && newH > 0)
  64907. {
  64908. drawImage (imageToDraw,
  64909. roundToInt (newX), roundToInt (newY),
  64910. roundToInt (newW), roundToInt (newH),
  64911. 0, 0, imageW, imageH,
  64912. fillAlphaChannelWithCurrentBrush);
  64913. }
  64914. }
  64915. }
  64916. }
  64917. void Graphics::drawImage (const Image* const imageToDraw,
  64918. int dx, int dy, int dw, int dh,
  64919. int sx, int sy, int sw, int sh,
  64920. const bool fillAlphaChannelWithCurrentBrush) const throw()
  64921. {
  64922. // passing in a silly number can cause maths problems in rendering!
  64923. jassert (areCoordsSensibleNumbers (dx, dy, dw, dh));
  64924. jassert (areCoordsSensibleNumbers (sx, sy, sw, sh));
  64925. if (context->clipRegionIntersects (Rectangle<int> (dx, dy, dw, dh)))
  64926. {
  64927. drawImageTransformed (imageToDraw, Rectangle<int> (sx, sy, sw, sh),
  64928. AffineTransform::scale (dw / (float) sw, dh / (float) sh)
  64929. .translated ((float) dx, (float) dy),
  64930. fillAlphaChannelWithCurrentBrush);
  64931. }
  64932. }
  64933. void Graphics::drawImageTransformed (const Image* const imageToDraw,
  64934. const Rectangle<int>& imageSubRegion,
  64935. const AffineTransform& transform,
  64936. const bool fillAlphaChannelWithCurrentBrush) const throw()
  64937. {
  64938. if (imageToDraw != 0 && ! context->isClipEmpty())
  64939. {
  64940. const Rectangle<int> srcClip (imageSubRegion.getIntersection (imageToDraw->getBounds()));
  64941. if (fillAlphaChannelWithCurrentBrush)
  64942. {
  64943. context->saveState();
  64944. context->clipToImageAlpha (*imageToDraw, srcClip, transform);
  64945. fillAll();
  64946. context->restoreState();
  64947. }
  64948. else
  64949. {
  64950. context->drawImage (*imageToDraw, srcClip, transform, false);
  64951. }
  64952. }
  64953. }
  64954. END_JUCE_NAMESPACE
  64955. /*** End of inlined file: juce_Graphics.cpp ***/
  64956. /*** Start of inlined file: juce_Justification.cpp ***/
  64957. BEGIN_JUCE_NAMESPACE
  64958. Justification::Justification (const Justification& other) throw()
  64959. : flags (other.flags)
  64960. {
  64961. }
  64962. Justification& Justification::operator= (const Justification& other) throw()
  64963. {
  64964. flags = other.flags;
  64965. return *this;
  64966. }
  64967. int Justification::getOnlyVerticalFlags() const throw()
  64968. {
  64969. return flags & (top | bottom | verticallyCentred);
  64970. }
  64971. int Justification::getOnlyHorizontalFlags() const throw()
  64972. {
  64973. return flags & (left | right | horizontallyCentred | horizontallyJustified);
  64974. }
  64975. void Justification::applyToRectangle (int& x, int& y,
  64976. const int w, const int h,
  64977. const int spaceX, const int spaceY,
  64978. const int spaceW, const int spaceH) const throw()
  64979. {
  64980. if ((flags & horizontallyCentred) != 0)
  64981. {
  64982. x = spaceX + ((spaceW - w) >> 1);
  64983. }
  64984. else if ((flags & right) != 0)
  64985. {
  64986. x = spaceX + spaceW - w;
  64987. }
  64988. else
  64989. {
  64990. x = spaceX;
  64991. }
  64992. if ((flags & verticallyCentred) != 0)
  64993. {
  64994. y = spaceY + ((spaceH - h) >> 1);
  64995. }
  64996. else if ((flags & bottom) != 0)
  64997. {
  64998. y = spaceY + spaceH - h;
  64999. }
  65000. else
  65001. {
  65002. y = spaceY;
  65003. }
  65004. }
  65005. END_JUCE_NAMESPACE
  65006. /*** End of inlined file: juce_Justification.cpp ***/
  65007. /*** Start of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65008. BEGIN_JUCE_NAMESPACE
  65009. // this will throw an assertion if you try to draw something that's not
  65010. // possible in postscript
  65011. #define WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS 0
  65012. #if defined (JUCE_DEBUG) && WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS
  65013. #define notPossibleInPostscriptAssert jassertfalse
  65014. #else
  65015. #define notPossibleInPostscriptAssert
  65016. #endif
  65017. LowLevelGraphicsPostScriptRenderer::LowLevelGraphicsPostScriptRenderer (OutputStream& resultingPostScript,
  65018. const String& documentTitle,
  65019. const int totalWidth_,
  65020. const int totalHeight_)
  65021. : out (resultingPostScript),
  65022. totalWidth (totalWidth_),
  65023. totalHeight (totalHeight_),
  65024. needToClip (true)
  65025. {
  65026. stateStack.add (new SavedState());
  65027. stateStack.getLast()->clip = Rectangle<int> (0, 0, totalWidth_, totalHeight_);
  65028. const float scale = jmin ((520.0f / totalWidth_), (750.0f / totalHeight));
  65029. out << "%!PS-Adobe-3.0 EPSF-3.0"
  65030. "\n%%BoundingBox: 0 0 600 824"
  65031. "\n%%Pages: 0"
  65032. "\n%%Creator: Raw Material Software JUCE"
  65033. "\n%%Title: " << documentTitle <<
  65034. "\n%%CreationDate: none"
  65035. "\n%%LanguageLevel: 2"
  65036. "\n%%EndComments"
  65037. "\n%%BeginProlog"
  65038. "\n%%BeginResource: JRes"
  65039. "\n/bd {bind def} bind def"
  65040. "\n/c {setrgbcolor} bd"
  65041. "\n/m {moveto} bd"
  65042. "\n/l {lineto} bd"
  65043. "\n/rl {rlineto} bd"
  65044. "\n/ct {curveto} bd"
  65045. "\n/cp {closepath} bd"
  65046. "\n/pr {3 index 3 index moveto 1 index 0 rlineto 0 1 index rlineto pop neg 0 rlineto pop pop closepath} bd"
  65047. "\n/doclip {initclip newpath} bd"
  65048. "\n/endclip {clip newpath} bd"
  65049. "\n%%EndResource"
  65050. "\n%%EndProlog"
  65051. "\n%%BeginSetup"
  65052. "\n%%EndSetup"
  65053. "\n%%Page: 1 1"
  65054. "\n%%BeginPageSetup"
  65055. "\n%%EndPageSetup\n\n"
  65056. << "40 800 translate\n"
  65057. << scale << ' ' << scale << " scale\n\n";
  65058. }
  65059. LowLevelGraphicsPostScriptRenderer::~LowLevelGraphicsPostScriptRenderer()
  65060. {
  65061. }
  65062. bool LowLevelGraphicsPostScriptRenderer::isVectorDevice() const
  65063. {
  65064. return true;
  65065. }
  65066. void LowLevelGraphicsPostScriptRenderer::setOrigin (int x, int y)
  65067. {
  65068. if (x != 0 || y != 0)
  65069. {
  65070. stateStack.getLast()->xOffset += x;
  65071. stateStack.getLast()->yOffset += y;
  65072. needToClip = true;
  65073. }
  65074. }
  65075. bool LowLevelGraphicsPostScriptRenderer::clipToRectangle (const Rectangle<int>& r)
  65076. {
  65077. needToClip = true;
  65078. return stateStack.getLast()->clip.clipTo (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65079. }
  65080. bool LowLevelGraphicsPostScriptRenderer::clipToRectangleList (const RectangleList& clipRegion)
  65081. {
  65082. needToClip = true;
  65083. return stateStack.getLast()->clip.clipTo (clipRegion);
  65084. }
  65085. void LowLevelGraphicsPostScriptRenderer::excludeClipRectangle (const Rectangle<int>& r)
  65086. {
  65087. needToClip = true;
  65088. stateStack.getLast()->clip.subtract (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65089. }
  65090. void LowLevelGraphicsPostScriptRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  65091. {
  65092. writeClip();
  65093. Path p (path);
  65094. p.applyTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65095. writePath (p);
  65096. out << "clip\n";
  65097. }
  65098. void LowLevelGraphicsPostScriptRenderer::clipToImageAlpha (const Image& /*sourceImage*/, const Rectangle<int>& /*srcClip*/, const AffineTransform& /*transform*/)
  65099. {
  65100. needToClip = true;
  65101. jassertfalse // xxx
  65102. }
  65103. bool LowLevelGraphicsPostScriptRenderer::clipRegionIntersects (const Rectangle<int>& r)
  65104. {
  65105. return stateStack.getLast()->clip.intersectsRectangle (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65106. }
  65107. const Rectangle<int> LowLevelGraphicsPostScriptRenderer::getClipBounds() const
  65108. {
  65109. return stateStack.getLast()->clip.getBounds().translated (-stateStack.getLast()->xOffset,
  65110. -stateStack.getLast()->yOffset);
  65111. }
  65112. bool LowLevelGraphicsPostScriptRenderer::isClipEmpty() const
  65113. {
  65114. return stateStack.getLast()->clip.isEmpty();
  65115. }
  65116. LowLevelGraphicsPostScriptRenderer::SavedState::SavedState()
  65117. : xOffset (0),
  65118. yOffset (0)
  65119. {
  65120. }
  65121. LowLevelGraphicsPostScriptRenderer::SavedState::~SavedState()
  65122. {
  65123. }
  65124. void LowLevelGraphicsPostScriptRenderer::saveState()
  65125. {
  65126. stateStack.add (new SavedState (*stateStack.getLast()));
  65127. }
  65128. void LowLevelGraphicsPostScriptRenderer::restoreState()
  65129. {
  65130. jassert (stateStack.size() > 0);
  65131. if (stateStack.size() > 0)
  65132. stateStack.removeLast();
  65133. }
  65134. void LowLevelGraphicsPostScriptRenderer::writeClip()
  65135. {
  65136. if (needToClip)
  65137. {
  65138. needToClip = false;
  65139. out << "doclip ";
  65140. int itemsOnLine = 0;
  65141. for (RectangleList::Iterator i (stateStack.getLast()->clip); i.next();)
  65142. {
  65143. if (++itemsOnLine == 6)
  65144. {
  65145. itemsOnLine = 0;
  65146. out << '\n';
  65147. }
  65148. const Rectangle<int>& r = *i.getRectangle();
  65149. out << r.getX() << ' ' << -r.getY() << ' '
  65150. << r.getWidth() << ' ' << -r.getHeight() << " pr ";
  65151. }
  65152. out << "endclip\n";
  65153. }
  65154. }
  65155. void LowLevelGraphicsPostScriptRenderer::writeColour (const Colour& colour)
  65156. {
  65157. Colour c (Colours::white.overlaidWith (colour));
  65158. if (lastColour != c)
  65159. {
  65160. lastColour = c;
  65161. out << String (c.getFloatRed(), 3) << ' '
  65162. << String (c.getFloatGreen(), 3) << ' '
  65163. << String (c.getFloatBlue(), 3) << " c\n";
  65164. }
  65165. }
  65166. void LowLevelGraphicsPostScriptRenderer::writeXY (const float x, const float y) const
  65167. {
  65168. out << String (x, 2) << ' '
  65169. << String (-y, 2) << ' ';
  65170. }
  65171. void LowLevelGraphicsPostScriptRenderer::writePath (const Path& path) const
  65172. {
  65173. out << "newpath ";
  65174. float lastX = 0.0f;
  65175. float lastY = 0.0f;
  65176. int itemsOnLine = 0;
  65177. Path::Iterator i (path);
  65178. while (i.next())
  65179. {
  65180. if (++itemsOnLine == 4)
  65181. {
  65182. itemsOnLine = 0;
  65183. out << '\n';
  65184. }
  65185. switch (i.elementType)
  65186. {
  65187. case Path::Iterator::startNewSubPath:
  65188. writeXY (i.x1, i.y1);
  65189. lastX = i.x1;
  65190. lastY = i.y1;
  65191. out << "m ";
  65192. break;
  65193. case Path::Iterator::lineTo:
  65194. writeXY (i.x1, i.y1);
  65195. lastX = i.x1;
  65196. lastY = i.y1;
  65197. out << "l ";
  65198. break;
  65199. case Path::Iterator::quadraticTo:
  65200. {
  65201. const float cp1x = lastX + (i.x1 - lastX) * 2.0f / 3.0f;
  65202. const float cp1y = lastY + (i.y1 - lastY) * 2.0f / 3.0f;
  65203. const float cp2x = cp1x + (i.x2 - lastX) / 3.0f;
  65204. const float cp2y = cp1y + (i.y2 - lastY) / 3.0f;
  65205. writeXY (cp1x, cp1y);
  65206. writeXY (cp2x, cp2y);
  65207. writeXY (i.x2, i.y2);
  65208. out << "ct ";
  65209. lastX = i.x2;
  65210. lastY = i.y2;
  65211. }
  65212. break;
  65213. case Path::Iterator::cubicTo:
  65214. writeXY (i.x1, i.y1);
  65215. writeXY (i.x2, i.y2);
  65216. writeXY (i.x3, i.y3);
  65217. out << "ct ";
  65218. lastX = i.x3;
  65219. lastY = i.y3;
  65220. break;
  65221. case Path::Iterator::closePath:
  65222. out << "cp ";
  65223. break;
  65224. default:
  65225. jassertfalse
  65226. break;
  65227. }
  65228. }
  65229. out << '\n';
  65230. }
  65231. void LowLevelGraphicsPostScriptRenderer::writeTransform (const AffineTransform& trans) const
  65232. {
  65233. out << "[ "
  65234. << trans.mat00 << ' '
  65235. << trans.mat10 << ' '
  65236. << trans.mat01 << ' '
  65237. << trans.mat11 << ' '
  65238. << trans.mat02 << ' '
  65239. << trans.mat12 << " ] concat ";
  65240. }
  65241. void LowLevelGraphicsPostScriptRenderer::setFill (const FillType& fillType)
  65242. {
  65243. stateStack.getLast()->fillType = fillType;
  65244. }
  65245. void LowLevelGraphicsPostScriptRenderer::setOpacity (float /*opacity*/)
  65246. {
  65247. }
  65248. void LowLevelGraphicsPostScriptRenderer::setInterpolationQuality (Graphics::ResamplingQuality /*quality*/)
  65249. {
  65250. }
  65251. void LowLevelGraphicsPostScriptRenderer::fillRect (const Rectangle<int>& r, const bool /*replaceExistingContents*/)
  65252. {
  65253. if (stateStack.getLast()->fillType.isColour())
  65254. {
  65255. writeClip();
  65256. writeColour (stateStack.getLast()->fillType.colour);
  65257. Rectangle<int> r2 (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65258. out << r2.getX() << ' ' << -r2.getBottom() << ' ' << r2.getWidth() << ' ' << r2.getHeight() << " rectfill\n";
  65259. }
  65260. else
  65261. {
  65262. Path p;
  65263. p.addRectangle (r);
  65264. fillPath (p, AffineTransform::identity);
  65265. }
  65266. }
  65267. void LowLevelGraphicsPostScriptRenderer::fillPath (const Path& path, const AffineTransform& t)
  65268. {
  65269. if (stateStack.getLast()->fillType.isColour())
  65270. {
  65271. writeClip();
  65272. Path p (path);
  65273. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset,
  65274. (float) stateStack.getLast()->yOffset));
  65275. writePath (p);
  65276. writeColour (stateStack.getLast()->fillType.colour);
  65277. out << "fill\n";
  65278. }
  65279. else if (stateStack.getLast()->fillType.isGradient())
  65280. {
  65281. // this doesn't work correctly yet - it could be improved to handle solid gradients, but
  65282. // postscript can't do semi-transparent ones.
  65283. notPossibleInPostscriptAssert // you can disable this warning by setting the WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS flag at the top of this file
  65284. writeClip();
  65285. out << "gsave ";
  65286. {
  65287. Path p (path);
  65288. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65289. writePath (p);
  65290. out << "clip\n";
  65291. }
  65292. const Rectangle<int> bounds (stateStack.getLast()->clip.getBounds());
  65293. // ideally this would draw lots of lines or ellipses to approximate the gradient, but for the
  65294. // time-being, this just fills it with the average colour..
  65295. writeColour (stateStack.getLast()->fillType.gradient->getColourAtPosition (0.5f));
  65296. out << bounds.getX() << ' ' << -bounds.getBottom() << ' ' << bounds.getWidth() << ' ' << bounds.getHeight() << " rectfill\n";
  65297. out << "grestore\n";
  65298. }
  65299. }
  65300. void LowLevelGraphicsPostScriptRenderer::writeImage (const Image& im,
  65301. const int sx, const int sy,
  65302. const int maxW, const int maxH) const
  65303. {
  65304. out << "{<\n";
  65305. const int w = jmin (maxW, im.getWidth());
  65306. const int h = jmin (maxH, im.getHeight());
  65307. int charsOnLine = 0;
  65308. const Image::BitmapData srcData (im, 0, 0, w, h);
  65309. Colour pixel;
  65310. for (int y = h; --y >= 0;)
  65311. {
  65312. for (int x = 0; x < w; ++x)
  65313. {
  65314. const uint8* pixelData = srcData.getPixelPointer (x, y);
  65315. if (x >= sx && y >= sy)
  65316. {
  65317. if (im.isARGB())
  65318. {
  65319. PixelARGB p (*(const PixelARGB*) pixelData);
  65320. p.unpremultiply();
  65321. pixel = Colours::white.overlaidWith (Colour (p.getARGB()));
  65322. }
  65323. else if (im.isRGB())
  65324. {
  65325. pixel = Colour (((const PixelRGB*) pixelData)->getARGB());
  65326. }
  65327. else
  65328. {
  65329. pixel = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *pixelData);
  65330. }
  65331. }
  65332. else
  65333. {
  65334. pixel = Colours::transparentWhite;
  65335. }
  65336. const uint8 pixelValues[3] = { pixel.getRed(), pixel.getGreen(), pixel.getBlue() };
  65337. out << String::toHexString (pixelValues, 3, 0);
  65338. charsOnLine += 3;
  65339. if (charsOnLine > 100)
  65340. {
  65341. out << '\n';
  65342. charsOnLine = 0;
  65343. }
  65344. }
  65345. }
  65346. out << "\n>}\n";
  65347. }
  65348. void LowLevelGraphicsPostScriptRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  65349. const AffineTransform& transform, const bool /*fillEntireClipAsTiles*/)
  65350. {
  65351. const int w = jmin (sourceImage.getWidth(), srcClip.getRight());
  65352. const int h = jmin (sourceImage.getHeight(), srcClip.getBottom());
  65353. writeClip();
  65354. out << "gsave ";
  65355. writeTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset)
  65356. .scaled (1.0f, -1.0f));
  65357. RectangleList imageClip;
  65358. sourceImage.createSolidAreaMask (imageClip, 0.5f);
  65359. imageClip.clipTo (srcClip);
  65360. out << "newpath ";
  65361. int itemsOnLine = 0;
  65362. for (RectangleList::Iterator i (imageClip); i.next();)
  65363. {
  65364. if (++itemsOnLine == 6)
  65365. {
  65366. out << '\n';
  65367. itemsOnLine = 0;
  65368. }
  65369. const Rectangle<int>& r = *i.getRectangle();
  65370. out << r.getX() << ' ' << r.getY() << ' ' << r.getWidth() << ' ' << r.getHeight() << " pr ";
  65371. }
  65372. out << " clip newpath\n";
  65373. out << w << ' ' << h << " scale\n";
  65374. out << w << ' ' << h << " 8 [" << w << " 0 0 -" << h << ' ' << (int) 0 << ' ' << h << " ]\n";
  65375. writeImage (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  65376. out << "false 3 colorimage grestore\n";
  65377. needToClip = true;
  65378. }
  65379. void LowLevelGraphicsPostScriptRenderer::drawLine (double x1, double y1, double x2, double y2)
  65380. {
  65381. Path p;
  65382. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  65383. fillPath (p, AffineTransform::identity);
  65384. }
  65385. void LowLevelGraphicsPostScriptRenderer::drawVerticalLine (const int x, double top, double bottom)
  65386. {
  65387. drawLine (x, top, x, bottom);
  65388. }
  65389. void LowLevelGraphicsPostScriptRenderer::drawHorizontalLine (const int y, double left, double right)
  65390. {
  65391. drawLine (left, y, right, y);
  65392. }
  65393. void LowLevelGraphicsPostScriptRenderer::setFont (const Font& newFont)
  65394. {
  65395. stateStack.getLast()->font = newFont;
  65396. }
  65397. const Font LowLevelGraphicsPostScriptRenderer::getFont()
  65398. {
  65399. return stateStack.getLast()->font;
  65400. }
  65401. void LowLevelGraphicsPostScriptRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  65402. {
  65403. Path p;
  65404. Font& font = stateStack.getLast()->font;
  65405. font.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  65406. fillPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight()).followedBy (transform));
  65407. }
  65408. END_JUCE_NAMESPACE
  65409. /*** End of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65410. /*** Start of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  65411. BEGIN_JUCE_NAMESPACE
  65412. #if (JUCE_WINDOWS || JUCE_LINUX) && ! JUCE_64BIT
  65413. #define JUCE_USE_SSE_INSTRUCTIONS 1
  65414. #endif
  65415. #if JUCE_MSVC && JUCE_DEBUG
  65416. #pragma warning (disable: 4714) // warning about forcedinline methods not being inlined
  65417. #endif
  65418. #if JUCE_MSVC
  65419. #pragma warning (push)
  65420. #pragma warning (disable: 4127) // "expression is constant" warning
  65421. #endif
  65422. template <class PixelType, bool replaceExisting = false>
  65423. class SolidColourEdgeTableRenderer
  65424. {
  65425. public:
  65426. SolidColourEdgeTableRenderer (const Image::BitmapData& data_, const PixelARGB& colour) throw()
  65427. : data (data_),
  65428. sourceColour (colour)
  65429. {
  65430. if (sizeof (PixelType) == 3)
  65431. {
  65432. areRGBComponentsEqual = sourceColour.getRed() == sourceColour.getGreen()
  65433. && sourceColour.getGreen() == sourceColour.getBlue();
  65434. filler[0].set (sourceColour);
  65435. filler[1].set (sourceColour);
  65436. filler[2].set (sourceColour);
  65437. filler[3].set (sourceColour);
  65438. }
  65439. }
  65440. forcedinline void setEdgeTableYPos (const int y) throw()
  65441. {
  65442. linePixels = (PixelType*) data.getLinePointer (y);
  65443. }
  65444. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  65445. {
  65446. if (replaceExisting)
  65447. linePixels[x].set (sourceColour);
  65448. else
  65449. linePixels[x].blend (sourceColour, alphaLevel);
  65450. }
  65451. forcedinline void handleEdgeTableLine (const int x, int width, const int alphaLevel) const throw()
  65452. {
  65453. PixelARGB p (sourceColour);
  65454. p.multiplyAlpha (alphaLevel);
  65455. PixelType* dest = linePixels + x;
  65456. if (replaceExisting || p.getAlpha() >= 0xff)
  65457. replaceLine (dest, p, width);
  65458. else
  65459. blendLine (dest, p, width);
  65460. }
  65461. private:
  65462. const Image::BitmapData& data;
  65463. PixelType* linePixels;
  65464. PixelARGB sourceColour;
  65465. PixelRGB filler [4];
  65466. bool areRGBComponentsEqual;
  65467. inline void blendLine (PixelType* dest, const PixelARGB& colour, int width) const throw()
  65468. {
  65469. do
  65470. {
  65471. dest->blend (colour);
  65472. ++dest;
  65473. } while (--width > 0);
  65474. }
  65475. forcedinline void replaceLine (PixelRGB* dest, const PixelARGB& colour, int width) const throw()
  65476. {
  65477. if (areRGBComponentsEqual) // if all the component values are the same, we can cheat..
  65478. {
  65479. memset (dest, colour.getRed(), width * 3);
  65480. }
  65481. else
  65482. {
  65483. if (width >> 5)
  65484. {
  65485. const int* const intFiller = (const int*) filler;
  65486. while (width > 8 && (((pointer_sized_int) dest) & 7) != 0)
  65487. {
  65488. dest->set (colour);
  65489. ++dest;
  65490. --width;
  65491. }
  65492. while (width > 4)
  65493. {
  65494. ((int*) dest) [0] = intFiller[0];
  65495. ((int*) dest) [1] = intFiller[1];
  65496. ((int*) dest) [2] = intFiller[2];
  65497. dest = (PixelRGB*) (((uint8*) dest) + 12);
  65498. width -= 4;
  65499. }
  65500. }
  65501. while (--width >= 0)
  65502. {
  65503. dest->set (colour);
  65504. ++dest;
  65505. }
  65506. }
  65507. }
  65508. forcedinline void replaceLine (PixelAlpha* dest, const PixelARGB& colour, int width) const throw()
  65509. {
  65510. memset (dest, colour.getAlpha(), width);
  65511. }
  65512. forcedinline void replaceLine (PixelARGB* dest, const PixelARGB& colour, int width) const throw()
  65513. {
  65514. do
  65515. {
  65516. dest->set (colour);
  65517. ++dest;
  65518. } while (--width > 0);
  65519. }
  65520. SolidColourEdgeTableRenderer (const SolidColourEdgeTableRenderer&);
  65521. SolidColourEdgeTableRenderer& operator= (const SolidColourEdgeTableRenderer&);
  65522. };
  65523. class LinearGradientPixelGenerator
  65524. {
  65525. public:
  65526. LinearGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform, const PixelARGB* const lookupTable_, const int numEntries_)
  65527. : lookupTable (lookupTable_), numEntries (numEntries_)
  65528. {
  65529. jassert (numEntries_ >= 0);
  65530. float x1 = gradient.x1;
  65531. float y1 = gradient.y1;
  65532. float x2 = gradient.x2;
  65533. float y2 = gradient.y2;
  65534. if (! transform.isIdentity())
  65535. {
  65536. const Line l (x2, y2, x1, y1);
  65537. const Point<float> p3 = l.getPointAlongLine (0.0f, 100.0f);
  65538. float x3 = p3.getX();
  65539. float y3 = p3.getY();
  65540. transform.transformPoint (x1, y1);
  65541. transform.transformPoint (x2, y2);
  65542. transform.transformPoint (x3, y3);
  65543. const Line l2 (x2, y2, x3, y3);
  65544. const float prop = l2.findNearestPointTo (x1, y1);
  65545. const Point<float> newP2 (l2.getPointAlongLineProportionally (prop));
  65546. x2 = newP2.getX();
  65547. y2 = newP2.getY();
  65548. }
  65549. vertical = fabs (x1 - x2) < 0.001f;
  65550. horizontal = fabs (y1 - y2) < 0.001f;
  65551. if (vertical)
  65552. {
  65553. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (y2 - y1));
  65554. start = roundToInt (y1 * scale);
  65555. }
  65556. else if (horizontal)
  65557. {
  65558. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (x2 - x1));
  65559. start = roundToInt (x1 * scale);
  65560. }
  65561. else
  65562. {
  65563. grad = (y2 - y1) / (double) (x1 - x2);
  65564. yTerm = y1 - x1 / grad;
  65565. scale = roundToInt ((numEntries << (int) numScaleBits) / (yTerm * grad - (y2 * grad - x2)));
  65566. grad *= scale;
  65567. }
  65568. }
  65569. forcedinline void setY (const int y) throw()
  65570. {
  65571. if (vertical)
  65572. linePix = lookupTable [jlimit (0, numEntries, (y * scale - start) >> (int) numScaleBits)];
  65573. else if (! horizontal)
  65574. start = roundToInt ((y - yTerm) * grad);
  65575. }
  65576. inline const PixelARGB getPixel (const int x) const throw()
  65577. {
  65578. return vertical ? linePix
  65579. : lookupTable [jlimit (0, numEntries, (x * scale - start) >> (int) numScaleBits)];
  65580. }
  65581. private:
  65582. const PixelARGB* const lookupTable;
  65583. const int numEntries;
  65584. PixelARGB linePix;
  65585. int start, scale;
  65586. double grad, yTerm;
  65587. bool vertical, horizontal;
  65588. enum { numScaleBits = 12 };
  65589. LinearGradientPixelGenerator (const LinearGradientPixelGenerator&);
  65590. LinearGradientPixelGenerator& operator= (const LinearGradientPixelGenerator&);
  65591. };
  65592. class RadialGradientPixelGenerator
  65593. {
  65594. public:
  65595. RadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform&,
  65596. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65597. : lookupTable (lookupTable_),
  65598. numEntries (numEntries_),
  65599. gx1 (gradient.x1),
  65600. gy1 (gradient.y1)
  65601. {
  65602. jassert (numEntries_ >= 0);
  65603. const float gdx = gradient.x1 - gradient.x2;
  65604. const float gdy = gradient.y1 - gradient.y2;
  65605. maxDist = gdx * gdx + gdy * gdy;
  65606. invScale = numEntries / sqrt (maxDist);
  65607. jassert (roundToInt (sqrt (maxDist) * invScale) <= numEntries);
  65608. }
  65609. forcedinline void setY (const int y) throw()
  65610. {
  65611. dy = y - gy1;
  65612. dy *= dy;
  65613. }
  65614. inline const PixelARGB getPixel (const int px) const throw()
  65615. {
  65616. double x = px - gx1;
  65617. x *= x;
  65618. x += dy;
  65619. return lookupTable [x >= maxDist ? numEntries : roundToInt (sqrt (x) * invScale)];
  65620. }
  65621. protected:
  65622. const PixelARGB* const lookupTable;
  65623. const int numEntries;
  65624. const double gx1, gy1;
  65625. double maxDist, invScale, dy;
  65626. RadialGradientPixelGenerator (const RadialGradientPixelGenerator&);
  65627. RadialGradientPixelGenerator& operator= (const RadialGradientPixelGenerator&);
  65628. };
  65629. class TransformedRadialGradientPixelGenerator : public RadialGradientPixelGenerator
  65630. {
  65631. public:
  65632. TransformedRadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform,
  65633. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65634. : RadialGradientPixelGenerator (gradient, transform, lookupTable_, numEntries_),
  65635. inverseTransform (transform.inverted())
  65636. {
  65637. tM10 = inverseTransform.mat10;
  65638. tM00 = inverseTransform.mat00;
  65639. }
  65640. forcedinline void setY (const int y) throw()
  65641. {
  65642. lineYM01 = inverseTransform.mat01 * y + inverseTransform.mat02 - gx1;
  65643. lineYM11 = inverseTransform.mat11 * y + inverseTransform.mat12 - gy1;
  65644. }
  65645. inline const PixelARGB getPixel (const int px) const throw()
  65646. {
  65647. double x = px;
  65648. const double y = tM10 * x + lineYM11;
  65649. x = tM00 * x + lineYM01;
  65650. x *= x;
  65651. x += y * y;
  65652. if (x >= maxDist)
  65653. return lookupTable [numEntries];
  65654. else
  65655. return lookupTable [jmin (numEntries, roundToInt (sqrt (x) * invScale))];
  65656. }
  65657. private:
  65658. double tM10, tM00, lineYM01, lineYM11;
  65659. const AffineTransform inverseTransform;
  65660. TransformedRadialGradientPixelGenerator (const TransformedRadialGradientPixelGenerator&);
  65661. TransformedRadialGradientPixelGenerator& operator= (const TransformedRadialGradientPixelGenerator&);
  65662. };
  65663. template <class PixelType, class GradientType>
  65664. class GradientEdgeTableRenderer : public GradientType
  65665. {
  65666. public:
  65667. GradientEdgeTableRenderer (const Image::BitmapData& destData_, const ColourGradient& gradient, const AffineTransform& transform,
  65668. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65669. : GradientType (gradient, transform, lookupTable_, numEntries_ - 1),
  65670. destData (destData_)
  65671. {
  65672. }
  65673. forcedinline void setEdgeTableYPos (const int y) throw()
  65674. {
  65675. linePixels = (PixelType*) destData.getLinePointer (y);
  65676. GradientType::setY (y);
  65677. }
  65678. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  65679. {
  65680. linePixels[x].blend (GradientType::getPixel (x), alphaLevel);
  65681. }
  65682. forcedinline void handleEdgeTableLine (int x, int width, const int alphaLevel) const throw()
  65683. {
  65684. PixelType* dest = linePixels + x;
  65685. if (alphaLevel < 0xff)
  65686. {
  65687. do
  65688. {
  65689. (dest++)->blend (GradientType::getPixel (x++), alphaLevel);
  65690. } while (--width > 0);
  65691. }
  65692. else
  65693. {
  65694. do
  65695. {
  65696. (dest++)->blend (GradientType::getPixel (x++));
  65697. } while (--width > 0);
  65698. }
  65699. }
  65700. private:
  65701. const Image::BitmapData& destData;
  65702. PixelType* linePixels;
  65703. GradientEdgeTableRenderer (const GradientEdgeTableRenderer&);
  65704. GradientEdgeTableRenderer& operator= (const GradientEdgeTableRenderer&);
  65705. };
  65706. static forcedinline int safeModulo (int n, const int divisor) throw()
  65707. {
  65708. jassert (divisor > 0);
  65709. n %= divisor;
  65710. return (n < 0) ? (n + divisor) : n;
  65711. }
  65712. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  65713. class ImageFillEdgeTableRenderer
  65714. {
  65715. public:
  65716. ImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  65717. const Image::BitmapData& srcData_,
  65718. const int extraAlpha_,
  65719. const int x, const int y) throw()
  65720. : destData (destData_),
  65721. srcData (srcData_),
  65722. extraAlpha (extraAlpha_ + 1),
  65723. xOffset (repeatPattern ? safeModulo (x, srcData_.width) - srcData_.width : x),
  65724. yOffset (repeatPattern ? safeModulo (y, srcData_.height) - srcData_.height : y)
  65725. {
  65726. }
  65727. forcedinline void setEdgeTableYPos (int y) throw()
  65728. {
  65729. linePixels = (DestPixelType*) destData.getLinePointer (y);
  65730. y -= yOffset;
  65731. if (repeatPattern)
  65732. {
  65733. jassert (y >= 0);
  65734. y %= srcData.height;
  65735. }
  65736. sourceLineStart = (SrcPixelType*) srcData.getLinePointer (y);
  65737. }
  65738. forcedinline void handleEdgeTablePixel (int x, int alphaLevel) const throw()
  65739. {
  65740. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  65741. linePixels[x].blend (sourceLineStart [repeatPattern ? ((x - xOffset) % srcData.width) : (x - xOffset)], alphaLevel);
  65742. }
  65743. forcedinline void handleEdgeTableLine (int x, int width, int alphaLevel) const throw()
  65744. {
  65745. DestPixelType* dest = linePixels + x;
  65746. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  65747. x -= xOffset;
  65748. jassert (repeatPattern || (x >= 0 && x + width <= srcData.width));
  65749. if (alphaLevel < 0xfe)
  65750. {
  65751. do
  65752. {
  65753. dest++ ->blend (sourceLineStart [repeatPattern ? (x++ % srcData.width) : x++], alphaLevel);
  65754. } while (--width > 0);
  65755. }
  65756. else
  65757. {
  65758. if (repeatPattern)
  65759. {
  65760. do
  65761. {
  65762. dest++ ->blend (sourceLineStart [x++ % srcData.width]);
  65763. } while (--width > 0);
  65764. }
  65765. else
  65766. {
  65767. copyRow (dest, sourceLineStart + x, width);
  65768. }
  65769. }
  65770. }
  65771. void clipEdgeTableLine (EdgeTable& et, int x, int y, int width) throw()
  65772. {
  65773. jassert (x - xOffset >= 0 && x + width - xOffset <= srcData.width);
  65774. SrcPixelType* s = (SrcPixelType*) srcData.getLinePointer (y - yOffset);
  65775. uint8* mask = (uint8*) (s + x - xOffset);
  65776. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  65777. mask += PixelARGB::indexA;
  65778. et.clipLineToMask (x, y, mask, sizeof (SrcPixelType), width);
  65779. }
  65780. private:
  65781. const Image::BitmapData& destData;
  65782. const Image::BitmapData& srcData;
  65783. const int extraAlpha, xOffset, yOffset;
  65784. DestPixelType* linePixels;
  65785. SrcPixelType* sourceLineStart;
  65786. template <class PixelType1, class PixelType2>
  65787. forcedinline static void copyRow (PixelType1* dest, PixelType2* src, int width) throw()
  65788. {
  65789. do
  65790. {
  65791. dest++ ->blend (*src++);
  65792. } while (--width > 0);
  65793. }
  65794. forcedinline static void copyRow (PixelRGB* dest, PixelRGB* src, int width) throw()
  65795. {
  65796. memcpy (dest, src, width * sizeof (PixelRGB));
  65797. }
  65798. ImageFillEdgeTableRenderer (const ImageFillEdgeTableRenderer&);
  65799. ImageFillEdgeTableRenderer& operator= (const ImageFillEdgeTableRenderer&);
  65800. };
  65801. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  65802. class TransformedImageFillEdgeTableRenderer
  65803. {
  65804. public:
  65805. TransformedImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  65806. const Image::BitmapData& srcData_,
  65807. const AffineTransform& transform,
  65808. const int extraAlpha_,
  65809. const bool betterQuality_) throw()
  65810. : interpolator (transform),
  65811. destData (destData_),
  65812. srcData (srcData_),
  65813. extraAlpha (extraAlpha_ + 1),
  65814. betterQuality (betterQuality_),
  65815. pixelOffset (betterQuality_ ? 0.5f : 0.0f),
  65816. pixelOffsetInt (betterQuality_ ? -128 : 0),
  65817. maxX (srcData_.width - 1),
  65818. maxY (srcData_.height - 1),
  65819. scratchSize (2048)
  65820. {
  65821. scratchBuffer.malloc (scratchSize);
  65822. }
  65823. ~TransformedImageFillEdgeTableRenderer() throw()
  65824. {
  65825. }
  65826. forcedinline void setEdgeTableYPos (const int newY) throw()
  65827. {
  65828. y = newY;
  65829. linePixels = (DestPixelType*) destData.getLinePointer (newY);
  65830. }
  65831. forcedinline void handleEdgeTablePixel (const int x, int alphaLevel) throw()
  65832. {
  65833. alphaLevel *= extraAlpha;
  65834. alphaLevel >>= 8;
  65835. SrcPixelType p;
  65836. generate (&p, x, 1);
  65837. linePixels[x].blend (p, alphaLevel);
  65838. }
  65839. forcedinline void handleEdgeTableLine (const int x, int width, int alphaLevel) throw()
  65840. {
  65841. if (width > scratchSize)
  65842. {
  65843. scratchSize = width;
  65844. scratchBuffer.malloc (scratchSize);
  65845. }
  65846. SrcPixelType* span = scratchBuffer;
  65847. generate (span, x, width);
  65848. DestPixelType* dest = linePixels + x;
  65849. alphaLevel *= extraAlpha;
  65850. alphaLevel >>= 8;
  65851. if (alphaLevel < 0xfe)
  65852. {
  65853. do
  65854. {
  65855. dest++ ->blend (*span++, alphaLevel);
  65856. } while (--width > 0);
  65857. }
  65858. else
  65859. {
  65860. do
  65861. {
  65862. dest++ ->blend (*span++);
  65863. } while (--width > 0);
  65864. }
  65865. }
  65866. void clipEdgeTableLine (EdgeTable& et, int x, int y_, int width) throw()
  65867. {
  65868. if (width > scratchSize)
  65869. {
  65870. scratchSize = width;
  65871. scratchBuffer.malloc (scratchSize);
  65872. }
  65873. y = y_;
  65874. generate (scratchBuffer, x, width);
  65875. const uint8* mask = reinterpret_cast <uint8*> (scratchBuffer.getData());
  65876. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  65877. mask += PixelARGB::indexA;
  65878. et.clipLineToMask (x, y_, mask, sizeof (SrcPixelType), width);
  65879. }
  65880. private:
  65881. void generate (PixelARGB* dest, const int x, int numPixels) throw()
  65882. {
  65883. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  65884. do
  65885. {
  65886. int hiResX, hiResY;
  65887. this->interpolator.next (hiResX, hiResY);
  65888. hiResX += pixelOffsetInt;
  65889. hiResY += pixelOffsetInt;
  65890. int loResX = hiResX >> 8;
  65891. int loResY = hiResY >> 8;
  65892. if (repeatPattern)
  65893. {
  65894. loResX = safeModulo (loResX, srcData.width);
  65895. loResY = safeModulo (loResY, srcData.height);
  65896. }
  65897. if (betterQuality
  65898. && ((unsigned int) loResX) < (unsigned int) maxX
  65899. && ((unsigned int) loResY) < (unsigned int) maxY)
  65900. {
  65901. uint32 c[4] = { 256 * 128, 256 * 128, 256 * 128, 256 * 128 };
  65902. hiResX &= 255;
  65903. hiResY &= 255;
  65904. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  65905. uint32 weight = (256 - hiResX) * (256 - hiResY);
  65906. c[0] += weight * src[0];
  65907. c[1] += weight * src[1];
  65908. c[2] += weight * src[2];
  65909. c[3] += weight * src[3];
  65910. weight = hiResX * (256 - hiResY);
  65911. c[0] += weight * src[4];
  65912. c[1] += weight * src[5];
  65913. c[2] += weight * src[6];
  65914. c[3] += weight * src[7];
  65915. src += this->srcData.lineStride;
  65916. weight = (256 - hiResX) * hiResY;
  65917. c[0] += weight * src[0];
  65918. c[1] += weight * src[1];
  65919. c[2] += weight * src[2];
  65920. c[3] += weight * src[3];
  65921. weight = hiResX * hiResY;
  65922. c[0] += weight * src[4];
  65923. c[1] += weight * src[5];
  65924. c[2] += weight * src[6];
  65925. c[3] += weight * src[7];
  65926. dest->setARGB ((uint8) (c[PixelARGB::indexA] >> 16),
  65927. (uint8) (c[PixelARGB::indexR] >> 16),
  65928. (uint8) (c[PixelARGB::indexG] >> 16),
  65929. (uint8) (c[PixelARGB::indexB] >> 16));
  65930. }
  65931. else
  65932. {
  65933. if (! repeatPattern)
  65934. {
  65935. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  65936. if (loResX < 0) loResX = 0;
  65937. if (loResY < 0) loResY = 0;
  65938. if (loResX > maxX) loResX = maxX;
  65939. if (loResY > maxY) loResY = maxY;
  65940. }
  65941. dest->set (*(const PixelARGB*) this->srcData.getPixelPointer (loResX, loResY));
  65942. }
  65943. ++dest;
  65944. } while (--numPixels > 0);
  65945. }
  65946. void generate (PixelRGB* dest, const int x, int numPixels) throw()
  65947. {
  65948. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  65949. do
  65950. {
  65951. int hiResX, hiResY;
  65952. this->interpolator.next (hiResX, hiResY);
  65953. hiResX += pixelOffsetInt;
  65954. hiResY += pixelOffsetInt;
  65955. int loResX = hiResX >> 8;
  65956. int loResY = hiResY >> 8;
  65957. if (repeatPattern)
  65958. {
  65959. loResX = safeModulo (loResX, srcData.width);
  65960. loResY = safeModulo (loResY, srcData.height);
  65961. }
  65962. if (betterQuality
  65963. && ((unsigned int) loResX) < (unsigned int) maxX
  65964. && ((unsigned int) loResY) < (unsigned int) maxY)
  65965. {
  65966. uint32 c[3] = { 256 * 128, 256 * 128, 256 * 128 };
  65967. hiResX &= 255;
  65968. hiResY &= 255;
  65969. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  65970. unsigned int weight = (256 - hiResX) * (256 - hiResY);
  65971. c[0] += weight * src[0];
  65972. c[1] += weight * src[1];
  65973. c[2] += weight * src[2];
  65974. weight = hiResX * (256 - hiResY);
  65975. c[0] += weight * src[3];
  65976. c[1] += weight * src[4];
  65977. c[2] += weight * src[5];
  65978. src += this->srcData.lineStride;
  65979. weight = (256 - hiResX) * hiResY;
  65980. c[0] += weight * src[0];
  65981. c[1] += weight * src[1];
  65982. c[2] += weight * src[2];
  65983. weight = hiResX * hiResY;
  65984. c[0] += weight * src[3];
  65985. c[1] += weight * src[4];
  65986. c[2] += weight * src[5];
  65987. dest->setARGB ((uint8) 255,
  65988. (uint8) (c[PixelRGB::indexR] >> 16),
  65989. (uint8) (c[PixelRGB::indexG] >> 16),
  65990. (uint8) (c[PixelRGB::indexB] >> 16));
  65991. }
  65992. else
  65993. {
  65994. if (! repeatPattern)
  65995. {
  65996. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  65997. if (loResX < 0) loResX = 0;
  65998. if (loResY < 0) loResY = 0;
  65999. if (loResX > maxX) loResX = maxX;
  66000. if (loResY > maxY) loResY = maxY;
  66001. }
  66002. dest->set (*(const PixelRGB*) this->srcData.getPixelPointer (loResX, loResY));
  66003. }
  66004. ++dest;
  66005. } while (--numPixels > 0);
  66006. }
  66007. void generate (PixelAlpha* dest, const int x, int numPixels) throw()
  66008. {
  66009. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66010. do
  66011. {
  66012. int hiResX, hiResY;
  66013. this->interpolator.next (hiResX, hiResY);
  66014. hiResX += pixelOffsetInt;
  66015. hiResY += pixelOffsetInt;
  66016. int loResX = hiResX >> 8;
  66017. int loResY = hiResY >> 8;
  66018. if (repeatPattern)
  66019. {
  66020. loResX = safeModulo (loResX, srcData.width);
  66021. loResY = safeModulo (loResY, srcData.height);
  66022. }
  66023. if (betterQuality
  66024. && ((unsigned int) loResX) < (unsigned int) maxX
  66025. && ((unsigned int) loResY) < (unsigned int) maxY)
  66026. {
  66027. hiResX &= 255;
  66028. hiResY &= 255;
  66029. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66030. uint32 c = 256 * 128;
  66031. c += src[0] * ((256 - hiResX) * (256 - hiResY));
  66032. c += src[1] * (hiResX * (256 - hiResY));
  66033. src += this->srcData.lineStride;
  66034. c += src[0] * ((256 - hiResX) * hiResY);
  66035. c += src[1] * (hiResX * hiResY);
  66036. *((uint8*) dest) = (uint8) c;
  66037. }
  66038. else
  66039. {
  66040. if (! repeatPattern)
  66041. {
  66042. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66043. if (loResX < 0) loResX = 0;
  66044. if (loResY < 0) loResY = 0;
  66045. if (loResX > maxX) loResX = maxX;
  66046. if (loResY > maxY) loResY = maxY;
  66047. }
  66048. *((uint8*) dest) = *(this->srcData.getPixelPointer (loResX, loResY));
  66049. }
  66050. ++dest;
  66051. } while (--numPixels > 0);
  66052. }
  66053. class TransformedImageSpanInterpolator
  66054. {
  66055. public:
  66056. TransformedImageSpanInterpolator (const AffineTransform& transform) throw()
  66057. : inverseTransform (transform.inverted())
  66058. {}
  66059. void setStartOfLine (float x, float y, const int numPixels) throw()
  66060. {
  66061. float x1 = x, y1 = y;
  66062. inverseTransform.transformPoint (x1, y1);
  66063. x += numPixels;
  66064. inverseTransform.transformPoint (x, y);
  66065. xBresenham.set ((int) (x1 * 256.0f), (int) (x * 256.0f), numPixels);
  66066. yBresenham.set ((int) (y1 * 256.0f), (int) (y * 256.0f), numPixels);
  66067. }
  66068. void next (int& x, int& y) throw()
  66069. {
  66070. x = xBresenham.n;
  66071. xBresenham.stepToNext();
  66072. y = yBresenham.n;
  66073. yBresenham.stepToNext();
  66074. }
  66075. private:
  66076. class BresenhamInterpolator
  66077. {
  66078. public:
  66079. BresenhamInterpolator() throw() {}
  66080. void set (const int n1, const int n2, const int numSteps_) throw()
  66081. {
  66082. numSteps = jmax (1, numSteps_);
  66083. step = (n2 - n1) / numSteps;
  66084. remainder = modulo = (n2 - n1) % numSteps;
  66085. n = n1;
  66086. if (modulo <= 0)
  66087. {
  66088. modulo += numSteps;
  66089. remainder += numSteps;
  66090. --step;
  66091. }
  66092. modulo -= numSteps;
  66093. }
  66094. forcedinline void stepToNext() throw()
  66095. {
  66096. modulo += remainder;
  66097. n += step;
  66098. if (modulo > 0)
  66099. {
  66100. modulo -= numSteps;
  66101. ++n;
  66102. }
  66103. }
  66104. int n;
  66105. private:
  66106. int numSteps, step, modulo, remainder;
  66107. };
  66108. const AffineTransform inverseTransform;
  66109. BresenhamInterpolator xBresenham, yBresenham;
  66110. TransformedImageSpanInterpolator (const TransformedImageSpanInterpolator&);
  66111. TransformedImageSpanInterpolator& operator= (const TransformedImageSpanInterpolator&);
  66112. };
  66113. TransformedImageSpanInterpolator interpolator;
  66114. const Image::BitmapData& destData;
  66115. const Image::BitmapData& srcData;
  66116. const int extraAlpha;
  66117. const bool betterQuality;
  66118. const float pixelOffset;
  66119. const int pixelOffsetInt, maxX, maxY;
  66120. int y;
  66121. DestPixelType* linePixels;
  66122. HeapBlock <SrcPixelType> scratchBuffer;
  66123. int scratchSize;
  66124. TransformedImageFillEdgeTableRenderer (const TransformedImageFillEdgeTableRenderer&);
  66125. TransformedImageFillEdgeTableRenderer& operator= (const TransformedImageFillEdgeTableRenderer&);
  66126. };
  66127. class LLGCSavedState
  66128. {
  66129. public:
  66130. LLGCSavedState (const Rectangle<int>& clip_, const int xOffset_, const int yOffset_,
  66131. const Font& font_, const FillType& fillType_,
  66132. const Graphics::ResamplingQuality interpolationQuality_) throw()
  66133. : edgeTable (new EdgeTableHolder (EdgeTable (clip_))),
  66134. xOffset (xOffset_), yOffset (yOffset_),
  66135. font (font_), fillType (fillType_),
  66136. interpolationQuality (interpolationQuality_)
  66137. {
  66138. }
  66139. LLGCSavedState (const LLGCSavedState& other) throw()
  66140. : edgeTable (other.edgeTable), xOffset (other.xOffset),
  66141. yOffset (other.yOffset), font (other.font),
  66142. fillType (other.fillType), interpolationQuality (other.interpolationQuality)
  66143. {
  66144. }
  66145. ~LLGCSavedState() throw()
  66146. {
  66147. }
  66148. bool clipToRectangle (const Rectangle<int>& r) throw()
  66149. {
  66150. dupeEdgeTableIfMultiplyReferenced();
  66151. edgeTable->edgeTable.clipToRectangle (r.translated (xOffset, yOffset));
  66152. return ! edgeTable->edgeTable.isEmpty();
  66153. }
  66154. bool clipToRectangleList (const RectangleList& r) throw()
  66155. {
  66156. dupeEdgeTableIfMultiplyReferenced();
  66157. RectangleList offsetList (r);
  66158. offsetList.offsetAll (xOffset, yOffset);
  66159. EdgeTable e2 (offsetList);
  66160. edgeTable->edgeTable.clipToEdgeTable (e2);
  66161. return ! edgeTable->edgeTable.isEmpty();
  66162. }
  66163. bool excludeClipRectangle (const Rectangle<int>& r) throw()
  66164. {
  66165. dupeEdgeTableIfMultiplyReferenced();
  66166. edgeTable->edgeTable.excludeRectangle (r.translated (xOffset, yOffset));
  66167. return ! edgeTable->edgeTable.isEmpty();
  66168. }
  66169. void clipToPath (const Path& p, const AffineTransform& transform) throw()
  66170. {
  66171. dupeEdgeTableIfMultiplyReferenced();
  66172. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform.translated ((float) xOffset, (float) yOffset));
  66173. edgeTable->edgeTable.clipToEdgeTable (et);
  66174. }
  66175. void fillEdgeTable (Image& image, EdgeTable& et, const bool replaceContents = false) throw()
  66176. {
  66177. et.clipToEdgeTable (edgeTable->edgeTable);
  66178. Image::BitmapData destData (image, 0, 0, image.getWidth(), image.getHeight(), true);
  66179. if (fillType.isGradient())
  66180. {
  66181. jassert (! replaceContents); // that option is just for solid colours
  66182. ColourGradient g2 (*(fillType.gradient));
  66183. g2.multiplyOpacity (fillType.getOpacity());
  66184. g2.x1 -= 0.5f; g2.y1 -= 0.5f;
  66185. g2.x2 -= 0.5f; g2.y2 -= 0.5f;
  66186. AffineTransform transform (fillType.transform.translated ((float) xOffset, (float) yOffset));
  66187. const bool isIdentity = transform.isOnlyTranslation();
  66188. if (isIdentity)
  66189. {
  66190. // If our translation doesn't involve any distortion, we can speed it up..
  66191. transform.transformPoint (g2.x1, g2.y1);
  66192. transform.transformPoint (g2.x2, g2.y2);
  66193. transform = AffineTransform::identity;
  66194. }
  66195. HeapBlock <PixelARGB> lookupTable;
  66196. const int numLookupEntries = g2.createLookupTable (transform, lookupTable);
  66197. jassert (numLookupEntries > 0);
  66198. switch (image.getFormat())
  66199. {
  66200. case Image::ARGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelARGB*) 0); break;
  66201. case Image::RGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelRGB*) 0); break;
  66202. default: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelAlpha*) 0); break;
  66203. }
  66204. }
  66205. else if (fillType.isTiledImage())
  66206. {
  66207. renderImage (image, *(fillType.image), fillType.image->getBounds(), fillType.transform, &et);
  66208. }
  66209. else
  66210. {
  66211. const PixelARGB fillColour (fillType.colour.getPixelARGB());
  66212. switch (image.getFormat())
  66213. {
  66214. case Image::ARGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelARGB*) 0); break;
  66215. case Image::RGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelRGB*) 0); break;
  66216. default: renderSolidFill (et, destData, fillColour, replaceContents, (PixelAlpha*) 0); break;
  66217. }
  66218. }
  66219. }
  66220. void renderImage (Image& destImage, const Image& sourceImage, const Rectangle<int>& srcClip,
  66221. const AffineTransform& t, const EdgeTable* const tiledFillClipRegion) throw()
  66222. {
  66223. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66224. const Image::BitmapData destData (destImage, 0, 0, destImage.getWidth(), destImage.getHeight(), true);
  66225. const Image::BitmapData srcData (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66226. const int alpha = fillType.colour.getAlpha();
  66227. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66228. if (transform.isOnlyTranslation())
  66229. {
  66230. // If our translation doesn't involve any distortion, just use a simple blit..
  66231. int tx = (int) (transform.getTranslationX() * 256.0f);
  66232. int ty = (int) (transform.getTranslationY() * 256.0f);
  66233. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66234. {
  66235. tx = ((tx + 128) >> 8);
  66236. ty = ((ty + 128) >> 8);
  66237. if (tiledFillClipRegion != 0)
  66238. {
  66239. blittedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, tx, ty, true);
  66240. }
  66241. else
  66242. {
  66243. EdgeTable et (Rectangle<int> (tx, ty, srcClip.getWidth(), srcClip.getHeight()).getIntersection (destImage.getBounds()));
  66244. et.clipToEdgeTable (edgeTable->edgeTable);
  66245. if (! et.isEmpty())
  66246. blittedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, tx, ty, false);
  66247. }
  66248. return;
  66249. }
  66250. }
  66251. if (transform.isSingularity())
  66252. return;
  66253. if (tiledFillClipRegion != 0)
  66254. {
  66255. transformedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, transform, betterQuality, true);
  66256. }
  66257. else
  66258. {
  66259. Path p;
  66260. p.addRectangle (0.0f, 0.0f, (float) srcClip.getWidth(), (float) srcClip.getHeight());
  66261. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform);
  66262. et.clipToEdgeTable (edgeTable->edgeTable);
  66263. if (! et.isEmpty())
  66264. transformedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, transform, betterQuality, false);
  66265. }
  66266. }
  66267. void clipToImageAlpha (const Image& image, const Rectangle<int>& srcClip, const AffineTransform& t) throw()
  66268. {
  66269. if (! image.hasAlphaChannel())
  66270. {
  66271. Path p;
  66272. p.addRectangle (srcClip);
  66273. clipToPath (p, t);
  66274. return;
  66275. }
  66276. dupeEdgeTableIfMultiplyReferenced();
  66277. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66278. const Image::BitmapData srcData (image, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66279. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66280. EdgeTable& et = edgeTable->edgeTable;
  66281. if (transform.isOnlyTranslation())
  66282. {
  66283. // If our translation doesn't involve any distortion, just use a simple blit..
  66284. const int tx = (int) (transform.getTranslationX() * 256.0f);
  66285. const int ty = (int) (transform.getTranslationY() * 256.0f);
  66286. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66287. {
  66288. const int imageX = ((tx + 128) >> 8);
  66289. const int imageY = ((ty + 128) >> 8);
  66290. if (image.getFormat() == Image::ARGB)
  66291. straightClipImage (et, srcData, imageX, imageY, (PixelARGB*)0);
  66292. else
  66293. straightClipImage (et, srcData, imageX, imageY, (PixelAlpha*)0);
  66294. return;
  66295. }
  66296. }
  66297. if (transform.isSingularity())
  66298. {
  66299. et.clipToRectangle (Rectangle<int>());
  66300. return;
  66301. }
  66302. {
  66303. Path p;
  66304. p.addRectangle (0, 0, (float) srcData.width, (float) srcData.height);
  66305. EdgeTable et2 (et.getMaximumBounds(), p, transform);
  66306. et.clipToEdgeTable (et2);
  66307. }
  66308. if (! et.isEmpty())
  66309. {
  66310. if (image.getFormat() == Image::ARGB)
  66311. transformedClipImage (et, srcData, transform, betterQuality, (PixelARGB*)0);
  66312. else
  66313. transformedClipImage (et, srcData, transform, betterQuality, (PixelAlpha*)0);
  66314. }
  66315. }
  66316. template <class SrcPixelType>
  66317. void transformedClipImage (EdgeTable& et, const Image::BitmapData& srcData, const AffineTransform& transform, const bool betterQuality, const SrcPixelType *) throw()
  66318. {
  66319. TransformedImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, transform, 255, betterQuality);
  66320. for (int y = 0; y < et.getMaximumBounds().getHeight(); ++y)
  66321. renderer.clipEdgeTableLine (et, et.getMaximumBounds().getX(), y + et.getMaximumBounds().getY(),
  66322. et.getMaximumBounds().getWidth());
  66323. }
  66324. template <class SrcPixelType>
  66325. void straightClipImage (EdgeTable& et, const Image::BitmapData& srcData, int imageX, int imageY, const SrcPixelType *) throw()
  66326. {
  66327. Rectangle<int> r (imageX, imageY, srcData.width, srcData.height);
  66328. et.clipToRectangle (r);
  66329. ImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, 255, imageX, imageY);
  66330. for (int y = 0; y < r.getHeight(); ++y)
  66331. renderer.clipEdgeTableLine (et, r.getX(), y + r.getY(), r.getWidth());
  66332. }
  66333. class EdgeTableHolder : public ReferenceCountedObject
  66334. {
  66335. public:
  66336. EdgeTableHolder (const EdgeTable& e) throw() : edgeTable (e) {}
  66337. EdgeTable edgeTable;
  66338. };
  66339. ReferenceCountedObjectPtr<EdgeTableHolder> edgeTable;
  66340. int xOffset, yOffset;
  66341. Font font;
  66342. FillType fillType;
  66343. Graphics::ResamplingQuality interpolationQuality;
  66344. private:
  66345. LLGCSavedState& operator= (const LLGCSavedState&);
  66346. void dupeEdgeTableIfMultiplyReferenced() throw()
  66347. {
  66348. if (edgeTable->getReferenceCount() > 1)
  66349. edgeTable = new EdgeTableHolder (edgeTable->edgeTable);
  66350. }
  66351. template <class DestPixelType>
  66352. void renderGradient (EdgeTable& et, const Image::BitmapData& destData, const ColourGradient& g, const AffineTransform& transform,
  66353. const PixelARGB* const lookupTable, const int numLookupEntries, const bool isIdentity, DestPixelType*) throw()
  66354. {
  66355. jassert (destData.pixelStride == sizeof (DestPixelType));
  66356. if (g.isRadial)
  66357. {
  66358. if (isIdentity)
  66359. {
  66360. GradientEdgeTableRenderer <DestPixelType, RadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66361. et.iterate (renderer);
  66362. }
  66363. else
  66364. {
  66365. GradientEdgeTableRenderer <DestPixelType, TransformedRadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66366. et.iterate (renderer);
  66367. }
  66368. }
  66369. else
  66370. {
  66371. GradientEdgeTableRenderer <DestPixelType, LinearGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66372. et.iterate (renderer);
  66373. }
  66374. }
  66375. template <class DestPixelType>
  66376. void renderSolidFill (EdgeTable& et, const Image::BitmapData& destData, const PixelARGB& fillColour, const bool replaceContents, DestPixelType*) throw()
  66377. {
  66378. jassert (destData.pixelStride == sizeof (DestPixelType));
  66379. if (replaceContents)
  66380. {
  66381. SolidColourEdgeTableRenderer <DestPixelType, true> r (destData, fillColour);
  66382. et.iterate (r);
  66383. }
  66384. else
  66385. {
  66386. SolidColourEdgeTableRenderer <DestPixelType, false> r (destData, fillColour);
  66387. et.iterate (r);
  66388. }
  66389. }
  66390. void transformedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData, const Image::BitmapData& srcData,
  66391. const int alpha, const AffineTransform& transform, const bool betterQuality, const bool repeatPattern) throw()
  66392. {
  66393. switch (destImage.getFormat())
  66394. {
  66395. case Image::ARGB:
  66396. switch (srcImage.getFormat())
  66397. {
  66398. case Image::ARGB:
  66399. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66400. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66401. break;
  66402. case Image::RGB:
  66403. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66404. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66405. break;
  66406. default:
  66407. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66408. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66409. break;
  66410. }
  66411. break;
  66412. case Image::RGB:
  66413. switch (srcImage.getFormat())
  66414. {
  66415. case Image::ARGB:
  66416. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66417. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66418. break;
  66419. case Image::RGB:
  66420. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66421. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66422. break;
  66423. default:
  66424. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66425. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66426. break;
  66427. }
  66428. break;
  66429. default:
  66430. switch (srcImage.getFormat())
  66431. {
  66432. case Image::ARGB:
  66433. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66434. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66435. break;
  66436. case Image::RGB:
  66437. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66438. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66439. break;
  66440. default:
  66441. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66442. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66443. break;
  66444. }
  66445. break;
  66446. }
  66447. }
  66448. void blittedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData,
  66449. const Image::BitmapData& srcData, const int alpha, int x, int y, const bool repeatPattern) throw()
  66450. {
  66451. switch (destImage.getFormat())
  66452. {
  66453. case Image::ARGB:
  66454. switch (srcImage.getFormat())
  66455. {
  66456. case Image::ARGB:
  66457. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66458. else { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66459. break;
  66460. case Image::RGB:
  66461. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66462. else { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66463. break;
  66464. default:
  66465. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66466. else { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66467. break;
  66468. }
  66469. break;
  66470. case Image::RGB:
  66471. switch (srcImage.getFormat())
  66472. {
  66473. case Image::ARGB:
  66474. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66475. else { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66476. break;
  66477. case Image::RGB:
  66478. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66479. else { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66480. break;
  66481. default:
  66482. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66483. else { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66484. break;
  66485. }
  66486. break;
  66487. default:
  66488. switch (srcImage.getFormat())
  66489. {
  66490. case Image::ARGB:
  66491. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66492. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66493. break;
  66494. case Image::RGB:
  66495. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66496. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66497. break;
  66498. default:
  66499. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66500. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66501. break;
  66502. }
  66503. break;
  66504. }
  66505. }
  66506. };
  66507. LowLevelGraphicsSoftwareRenderer::LowLevelGraphicsSoftwareRenderer (Image& image_)
  66508. : image (image_)
  66509. {
  66510. currentState = new LLGCSavedState (image_.getBounds(), 0, 0, Font(),
  66511. FillType(), Graphics::mediumResamplingQuality);
  66512. }
  66513. LowLevelGraphicsSoftwareRenderer::~LowLevelGraphicsSoftwareRenderer()
  66514. {
  66515. }
  66516. bool LowLevelGraphicsSoftwareRenderer::isVectorDevice() const
  66517. {
  66518. return false;
  66519. }
  66520. void LowLevelGraphicsSoftwareRenderer::setOrigin (int x, int y)
  66521. {
  66522. currentState->xOffset += x;
  66523. currentState->yOffset += y;
  66524. }
  66525. bool LowLevelGraphicsSoftwareRenderer::clipToRectangle (const Rectangle<int>& r)
  66526. {
  66527. return currentState->clipToRectangle (r);
  66528. }
  66529. bool LowLevelGraphicsSoftwareRenderer::clipToRectangleList (const RectangleList& clipRegion)
  66530. {
  66531. return currentState->clipToRectangleList (clipRegion);
  66532. }
  66533. void LowLevelGraphicsSoftwareRenderer::excludeClipRectangle (const Rectangle<int>& r)
  66534. {
  66535. currentState->excludeClipRectangle (r);
  66536. }
  66537. void LowLevelGraphicsSoftwareRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  66538. {
  66539. currentState->clipToPath (path, transform);
  66540. }
  66541. void LowLevelGraphicsSoftwareRenderer::clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  66542. {
  66543. currentState->clipToImageAlpha (sourceImage, srcClip, transform);
  66544. }
  66545. bool LowLevelGraphicsSoftwareRenderer::clipRegionIntersects (const Rectangle<int>& r)
  66546. {
  66547. return currentState->edgeTable->edgeTable.getMaximumBounds()
  66548. .intersects (r.translated (currentState->xOffset, currentState->yOffset));
  66549. }
  66550. const Rectangle<int> LowLevelGraphicsSoftwareRenderer::getClipBounds() const
  66551. {
  66552. return currentState->edgeTable->edgeTable.getMaximumBounds().translated (-currentState->xOffset, -currentState->yOffset);
  66553. }
  66554. bool LowLevelGraphicsSoftwareRenderer::isClipEmpty() const
  66555. {
  66556. return currentState->edgeTable->edgeTable.isEmpty();
  66557. }
  66558. void LowLevelGraphicsSoftwareRenderer::saveState()
  66559. {
  66560. stateStack.add (new LLGCSavedState (*currentState));
  66561. }
  66562. void LowLevelGraphicsSoftwareRenderer::restoreState()
  66563. {
  66564. LLGCSavedState* const top = stateStack.getLast();
  66565. if (top != 0)
  66566. {
  66567. currentState = top;
  66568. stateStack.removeLast (1, false);
  66569. }
  66570. else
  66571. {
  66572. jassertfalse // trying to pop with an empty stack!
  66573. }
  66574. }
  66575. void LowLevelGraphicsSoftwareRenderer::setFill (const FillType& fillType)
  66576. {
  66577. currentState->fillType = fillType;
  66578. }
  66579. void LowLevelGraphicsSoftwareRenderer::setOpacity (float newOpacity)
  66580. {
  66581. currentState->fillType.setOpacity (newOpacity);
  66582. }
  66583. void LowLevelGraphicsSoftwareRenderer::setInterpolationQuality (Graphics::ResamplingQuality quality)
  66584. {
  66585. currentState->interpolationQuality = quality;
  66586. }
  66587. void LowLevelGraphicsSoftwareRenderer::fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  66588. {
  66589. const Rectangle<int>& totalClip = currentState->edgeTable->edgeTable.getMaximumBounds();
  66590. const Rectangle<int> clipped (totalClip.getIntersection (r.translated (currentState->xOffset, currentState->yOffset)));
  66591. if (! clipped.isEmpty())
  66592. {
  66593. EdgeTable et (clipped);
  66594. currentState->fillEdgeTable (image, et, replaceExistingContents);
  66595. }
  66596. }
  66597. void LowLevelGraphicsSoftwareRenderer::fillPath (const Path& path, const AffineTransform& transform)
  66598. {
  66599. EdgeTable et (currentState->edgeTable->edgeTable.getMaximumBounds(),
  66600. path, transform.translated ((float) currentState->xOffset,
  66601. (float) currentState->yOffset));
  66602. currentState->fillEdgeTable (image, et);
  66603. }
  66604. void LowLevelGraphicsSoftwareRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  66605. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  66606. {
  66607. jassert (sourceImage.getBounds().contains (srcClip));
  66608. currentState->renderImage (image, sourceImage, srcClip, transform,
  66609. fillEntireClipAsTiles ? &(currentState->edgeTable->edgeTable) : 0);
  66610. }
  66611. void LowLevelGraphicsSoftwareRenderer::drawLine (double x1, double y1, double x2, double y2)
  66612. {
  66613. Path p;
  66614. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  66615. fillPath (p, AffineTransform::identity);
  66616. }
  66617. void LowLevelGraphicsSoftwareRenderer::drawVerticalLine (const int x, double top, double bottom)
  66618. {
  66619. if (bottom > top)
  66620. {
  66621. EdgeTable et ((float) (x + currentState->xOffset), (float) (top + currentState->yOffset), 1.0f, (float) (bottom - top));
  66622. currentState->fillEdgeTable (image, et);
  66623. }
  66624. }
  66625. void LowLevelGraphicsSoftwareRenderer::drawHorizontalLine (const int y, double left, double right)
  66626. {
  66627. if (right > left)
  66628. {
  66629. EdgeTable et ((float) (left + currentState->xOffset), (float) (y + currentState->yOffset),
  66630. (float) (right - left), 1.0f);
  66631. currentState->fillEdgeTable (image, et);
  66632. }
  66633. }
  66634. class GlyphCache : private DeletedAtShutdown
  66635. {
  66636. public:
  66637. GlyphCache() throw()
  66638. : accessCounter (0), hits (0), misses (0)
  66639. {
  66640. for (int i = 120; --i >= 0;)
  66641. glyphs.add (new CachedGlyph());
  66642. }
  66643. ~GlyphCache() throw()
  66644. {
  66645. clearSingletonInstance();
  66646. }
  66647. juce_DeclareSingleton_SingleThreaded_Minimal (GlyphCache);
  66648. void drawGlyph (LLGCSavedState& state, Image& image, const Font& font, const int glyphNumber, float x, float y) throw()
  66649. {
  66650. ++accessCounter;
  66651. int oldestCounter = std::numeric_limits<int>::max();
  66652. CachedGlyph* oldest = 0;
  66653. for (int i = glyphs.size(); --i >= 0;)
  66654. {
  66655. CachedGlyph* const glyph = glyphs.getUnchecked (i);
  66656. if (glyph->glyph == glyphNumber && glyph->font == font)
  66657. {
  66658. ++hits;
  66659. glyph->lastAccessCount = accessCounter;
  66660. glyph->draw (state, image, x, y);
  66661. return;
  66662. }
  66663. if (glyph->lastAccessCount <= oldestCounter)
  66664. {
  66665. oldestCounter = glyph->lastAccessCount;
  66666. oldest = glyph;
  66667. }
  66668. }
  66669. if (hits + ++misses > (glyphs.size() << 4))
  66670. {
  66671. if (misses * 2 > hits)
  66672. {
  66673. for (int i = 32; --i >= 0;)
  66674. glyphs.add (new CachedGlyph());
  66675. }
  66676. hits = misses = 0;
  66677. oldest = glyphs.getLast();
  66678. }
  66679. jassert (oldest != 0);
  66680. oldest->lastAccessCount = accessCounter;
  66681. oldest->generate (font, glyphNumber);
  66682. oldest->draw (state, image, x, y);
  66683. }
  66684. class CachedGlyph
  66685. {
  66686. public:
  66687. CachedGlyph() : glyph (0), lastAccessCount (0) {}
  66688. ~CachedGlyph() {}
  66689. void draw (LLGCSavedState& state, Image& image, const float x, const float y) const throw()
  66690. {
  66691. if (edgeTable != 0)
  66692. {
  66693. EdgeTable et (*edgeTable);
  66694. et.translate (x, roundToInt (y));
  66695. state.fillEdgeTable (image, et, false);
  66696. }
  66697. }
  66698. void generate (const Font& newFont, const int glyphNumber) throw()
  66699. {
  66700. font = newFont;
  66701. glyph = glyphNumber;
  66702. edgeTable = 0;
  66703. Path glyphPath;
  66704. font.getTypeface()->getOutlineForGlyph (glyphNumber, glyphPath);
  66705. if (! glyphPath.isEmpty())
  66706. {
  66707. const float fontHeight = font.getHeight();
  66708. const AffineTransform transform (AffineTransform::scale (fontHeight * font.getHorizontalScale(), fontHeight)
  66709. .translated (0.0f, -0.5f));
  66710. edgeTable = new EdgeTable (glyphPath.getBoundsTransformed (transform).getSmallestIntegerContainer().expanded (1, 0),
  66711. glyphPath, transform);
  66712. }
  66713. }
  66714. int glyph, lastAccessCount;
  66715. Font font;
  66716. juce_UseDebuggingNewOperator
  66717. private:
  66718. ScopedPointer <EdgeTable> edgeTable;
  66719. CachedGlyph (const CachedGlyph&);
  66720. CachedGlyph& operator= (const CachedGlyph&);
  66721. };
  66722. juce_UseDebuggingNewOperator
  66723. private:
  66724. OwnedArray <CachedGlyph> glyphs;
  66725. int accessCounter, hits, misses;
  66726. GlyphCache (const GlyphCache&);
  66727. GlyphCache& operator= (const GlyphCache&);
  66728. };
  66729. juce_ImplementSingleton_SingleThreaded (GlyphCache);
  66730. void LowLevelGraphicsSoftwareRenderer::setFont (const Font& newFont)
  66731. {
  66732. currentState->font = newFont;
  66733. }
  66734. const Font LowLevelGraphicsSoftwareRenderer::getFont()
  66735. {
  66736. return currentState->font;
  66737. }
  66738. void LowLevelGraphicsSoftwareRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  66739. {
  66740. Font& f = currentState->font;
  66741. if (transform.isOnlyTranslation())
  66742. {
  66743. GlyphCache::getInstance()->drawGlyph (*currentState, image, f, glyphNumber,
  66744. transform.getTranslationX() + (float) currentState->xOffset,
  66745. transform.getTranslationY() + (float) currentState->yOffset);
  66746. }
  66747. else
  66748. {
  66749. Path p;
  66750. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  66751. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight()).followedBy (transform));
  66752. }
  66753. }
  66754. #if JUCE_MSVC
  66755. #pragma warning (pop)
  66756. #endif
  66757. END_JUCE_NAMESPACE
  66758. /*** End of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  66759. /*** Start of inlined file: juce_RectanglePlacement.cpp ***/
  66760. BEGIN_JUCE_NAMESPACE
  66761. RectanglePlacement::RectanglePlacement (const RectanglePlacement& other) throw()
  66762. : flags (other.flags)
  66763. {
  66764. }
  66765. RectanglePlacement& RectanglePlacement::operator= (const RectanglePlacement& other) throw()
  66766. {
  66767. flags = other.flags;
  66768. return *this;
  66769. }
  66770. void RectanglePlacement::applyTo (double& x, double& y,
  66771. double& w, double& h,
  66772. const double dx, const double dy,
  66773. const double dw, const double dh) const throw()
  66774. {
  66775. if (w == 0 || h == 0)
  66776. return;
  66777. if ((flags & stretchToFit) != 0)
  66778. {
  66779. x = dx;
  66780. y = dy;
  66781. w = dw;
  66782. h = dh;
  66783. }
  66784. else
  66785. {
  66786. double scale = (flags & fillDestination) != 0 ? jmax (dw / w, dh / h)
  66787. : jmin (dw / w, dh / h);
  66788. if ((flags & onlyReduceInSize) != 0)
  66789. scale = jmin (scale, 1.0);
  66790. if ((flags & onlyIncreaseInSize) != 0)
  66791. scale = jmax (scale, 1.0);
  66792. w *= scale;
  66793. h *= scale;
  66794. if ((flags & xLeft) != 0)
  66795. x = dx;
  66796. else if ((flags & xRight) != 0)
  66797. x = dx + dw - w;
  66798. else
  66799. x = dx + (dw - w) * 0.5;
  66800. if ((flags & yTop) != 0)
  66801. y = dy;
  66802. else if ((flags & yBottom) != 0)
  66803. y = dy + dh - h;
  66804. else
  66805. y = dy + (dh - h) * 0.5;
  66806. }
  66807. }
  66808. const AffineTransform RectanglePlacement::getTransformToFit (float x, float y,
  66809. float w, float h,
  66810. const float dx, const float dy,
  66811. const float dw, const float dh) const throw()
  66812. {
  66813. if (w == 0 || h == 0)
  66814. return AffineTransform::identity;
  66815. const float scaleX = dw / w;
  66816. const float scaleY = dh / h;
  66817. if ((flags & stretchToFit) != 0)
  66818. return AffineTransform::translation (-x, -y)
  66819. .scaled (scaleX, scaleY)
  66820. .translated (dx, dy);
  66821. float scale = (flags & fillDestination) != 0 ? jmax (scaleX, scaleY)
  66822. : jmin (scaleX, scaleY);
  66823. if ((flags & onlyReduceInSize) != 0)
  66824. scale = jmin (scale, 1.0f);
  66825. if ((flags & onlyIncreaseInSize) != 0)
  66826. scale = jmax (scale, 1.0f);
  66827. w *= scale;
  66828. h *= scale;
  66829. float newX = dx;
  66830. if ((flags & xRight) != 0)
  66831. newX += dw - w; // right
  66832. else if ((flags & xLeft) == 0)
  66833. newX += (dw - w) / 2.0f; // centre
  66834. float newY = dy;
  66835. if ((flags & yBottom) != 0)
  66836. newY += dh - h; // bottom
  66837. else if ((flags & yTop) == 0)
  66838. newY += (dh - h) / 2.0f; // centre
  66839. return AffineTransform::translation (-x, -y)
  66840. .scaled (scale, scale)
  66841. .translated (newX, newY);
  66842. }
  66843. END_JUCE_NAMESPACE
  66844. /*** End of inlined file: juce_RectanglePlacement.cpp ***/
  66845. /*** Start of inlined file: juce_Drawable.cpp ***/
  66846. BEGIN_JUCE_NAMESPACE
  66847. Drawable::RenderingContext::RenderingContext (Graphics& g_,
  66848. const AffineTransform& transform_,
  66849. const float opacity_) throw()
  66850. : g (g_),
  66851. transform (transform_),
  66852. opacity (opacity_)
  66853. {
  66854. }
  66855. Drawable::Drawable()
  66856. {
  66857. }
  66858. Drawable::~Drawable()
  66859. {
  66860. }
  66861. void Drawable::draw (Graphics& g, const float opacity,
  66862. const AffineTransform& transform) const
  66863. {
  66864. render (RenderingContext (g, transform, opacity));
  66865. }
  66866. void Drawable::drawAt (Graphics& g, const float x, const float y, const float opacity) const
  66867. {
  66868. draw (g, opacity, AffineTransform::translation (x, y));
  66869. }
  66870. void Drawable::drawWithin (Graphics& g,
  66871. const int destX,
  66872. const int destY,
  66873. const int destW,
  66874. const int destH,
  66875. const RectanglePlacement& placement,
  66876. const float opacity) const
  66877. {
  66878. if (destW > 0 && destH > 0)
  66879. {
  66880. Rectangle<float> bounds (getBounds());
  66881. draw (g, opacity,
  66882. placement.getTransformToFit (bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(),
  66883. (float) destX, (float) destY,
  66884. (float) destW, (float) destH));
  66885. }
  66886. }
  66887. Drawable* Drawable::createFromImageData (const void* data, const size_t numBytes)
  66888. {
  66889. Drawable* result = 0;
  66890. Image* const image = ImageFileFormat::loadFrom (data, (int) numBytes);
  66891. if (image != 0)
  66892. {
  66893. DrawableImage* const di = new DrawableImage();
  66894. di->setImage (image, true);
  66895. result = di;
  66896. }
  66897. else
  66898. {
  66899. const String asString (String::createStringFromData (data, (int) numBytes));
  66900. XmlDocument doc (asString);
  66901. ScopedPointer <XmlElement> outer (doc.getDocumentElement (true));
  66902. if (outer != 0 && outer->hasTagName ("svg"))
  66903. {
  66904. ScopedPointer <XmlElement> svg (doc.getDocumentElement());
  66905. if (svg != 0)
  66906. result = Drawable::createFromSVG (*svg);
  66907. }
  66908. }
  66909. return result;
  66910. }
  66911. Drawable* Drawable::createFromImageDataStream (InputStream& dataSource)
  66912. {
  66913. MemoryBlock mb;
  66914. dataSource.readIntoMemoryBlock (mb);
  66915. return createFromImageData (mb.getData(), mb.getSize());
  66916. }
  66917. Drawable* Drawable::createFromImageFile (const File& file)
  66918. {
  66919. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  66920. return fin != 0 ? createFromImageDataStream (*fin) : 0;
  66921. }
  66922. Drawable* Drawable::createFromValueTree (const ValueTree& tree) throw()
  66923. {
  66924. Drawable* d = DrawablePath::createFromValueTree (tree);
  66925. if (d == 0)
  66926. {
  66927. d = DrawableComposite::createFromValueTree (tree);
  66928. if (d == 0)
  66929. {
  66930. d = DrawableImage::createFromValueTree (tree);
  66931. if (d == 0)
  66932. d = DrawableText::createFromValueTree (tree);
  66933. }
  66934. }
  66935. return d;
  66936. }
  66937. END_JUCE_NAMESPACE
  66938. /*** End of inlined file: juce_Drawable.cpp ***/
  66939. /*** Start of inlined file: juce_DrawableComposite.cpp ***/
  66940. BEGIN_JUCE_NAMESPACE
  66941. DrawableComposite::DrawableComposite()
  66942. {
  66943. }
  66944. DrawableComposite::~DrawableComposite()
  66945. {
  66946. }
  66947. void DrawableComposite::insertDrawable (Drawable* drawable,
  66948. const AffineTransform& transform,
  66949. const int index)
  66950. {
  66951. if (drawable != 0)
  66952. {
  66953. if (! drawables.contains (drawable))
  66954. {
  66955. drawables.insert (index, drawable);
  66956. if (transform.isIdentity())
  66957. transforms.insert (index, 0);
  66958. else
  66959. transforms.insert (index, new AffineTransform (transform));
  66960. }
  66961. else
  66962. {
  66963. jassertfalse // trying to add a drawable that's already in here!
  66964. }
  66965. }
  66966. }
  66967. void DrawableComposite::insertDrawable (const Drawable& drawable,
  66968. const AffineTransform& transform,
  66969. const int index)
  66970. {
  66971. insertDrawable (drawable.createCopy(), transform, index);
  66972. }
  66973. void DrawableComposite::removeDrawable (const int index, const bool deleteDrawable)
  66974. {
  66975. drawables.remove (index, deleteDrawable);
  66976. transforms.remove (index);
  66977. }
  66978. void DrawableComposite::bringToFront (const int index)
  66979. {
  66980. if (index >= 0 && index < drawables.size() - 1)
  66981. {
  66982. drawables.move (index, -1);
  66983. transforms.move (index, -1);
  66984. }
  66985. }
  66986. void DrawableComposite::render (const Drawable::RenderingContext& context) const
  66987. {
  66988. if (drawables.size() > 0 && context.opacity > 0)
  66989. {
  66990. if (context.opacity >= 1.0f || drawables.size() == 1)
  66991. {
  66992. Drawable::RenderingContext contextCopy (context);
  66993. for (int i = 0; i < drawables.size(); ++i)
  66994. {
  66995. const AffineTransform* const t = transforms.getUnchecked(i);
  66996. contextCopy.transform = (t == 0) ? context.transform
  66997. : t->followedBy (context.transform);
  66998. drawables.getUnchecked(i)->render (contextCopy);
  66999. }
  67000. }
  67001. else
  67002. {
  67003. // To correctly render a whole composite layer with an overall transparency,
  67004. // we need to render everything opaquely into a temp buffer, then blend that
  67005. // with the target opacity...
  67006. const Rectangle<int> clipBounds (context.g.getClipBounds());
  67007. Image tempImage (Image::ARGB, clipBounds.getWidth(), clipBounds.getHeight(), true);
  67008. {
  67009. Graphics tempG (tempImage);
  67010. tempG.setOrigin (-clipBounds.getX(), -clipBounds.getY());
  67011. Drawable::RenderingContext tempContext (tempG, context.transform, 1.0f);
  67012. render (tempContext);
  67013. }
  67014. context.g.setOpacity (context.opacity);
  67015. context.g.drawImageAt (&tempImage, clipBounds.getX(), clipBounds.getY());
  67016. }
  67017. }
  67018. }
  67019. const Rectangle<float> DrawableComposite::getBounds() const
  67020. {
  67021. Rectangle<float> bounds;
  67022. for (int i = 0; i < drawables.size(); ++i)
  67023. {
  67024. const Drawable* const d = drawables.getUnchecked(i);
  67025. const AffineTransform* const t = transforms.getUnchecked(i);
  67026. const Rectangle<float> childBounds (t == 0 ? d->getBounds()
  67027. : d->getBounds().transformed (*t));
  67028. if (bounds.isEmpty())
  67029. bounds = childBounds;
  67030. else if (! childBounds.isEmpty())
  67031. bounds = bounds.getUnion (childBounds);
  67032. }
  67033. return bounds;
  67034. }
  67035. bool DrawableComposite::hitTest (float x, float y) const
  67036. {
  67037. for (int i = 0; i < drawables.size(); ++i)
  67038. {
  67039. float tx = x;
  67040. float ty = y;
  67041. const AffineTransform* const t = transforms.getUnchecked(i);
  67042. if (t != 0)
  67043. t->inverted().transformPoint (tx, ty);
  67044. if (drawables.getUnchecked(i)->hitTest (tx, ty))
  67045. return true;
  67046. }
  67047. return false;
  67048. }
  67049. Drawable* DrawableComposite::createCopy() const
  67050. {
  67051. DrawableComposite* const dc = new DrawableComposite();
  67052. for (int i = 0; i < drawables.size(); ++i)
  67053. {
  67054. dc->drawables.add (drawables.getUnchecked(i)->createCopy());
  67055. const AffineTransform* const t = transforms.getUnchecked(i);
  67056. dc->transforms.add (t != 0 ? new AffineTransform (*t) : 0);
  67057. }
  67058. return dc;
  67059. }
  67060. ValueTree DrawableComposite::createValueTree() const throw()
  67061. {
  67062. ValueTree v ("Group");
  67063. if (getName().isNotEmpty())
  67064. v.setProperty ("id", getName(), 0);
  67065. for (int i = 0; i < drawables.size(); ++i)
  67066. {
  67067. Drawable* const d = drawables.getUnchecked(i);
  67068. ValueTree child (d->createValueTree());
  67069. AffineTransform* transform = transforms.getUnchecked(i);
  67070. if (transform != 0)
  67071. {
  67072. String t;
  67073. t << transform->mat00 << " " << transform->mat01 << " " << transform->mat02 << " "
  67074. << transform->mat10 << " " << transform->mat11 << " " << transform->mat12;
  67075. child.setProperty ("transform", t, 0);
  67076. }
  67077. v.addChild (child, -1, 0);
  67078. }
  67079. return v;
  67080. }
  67081. DrawableComposite* DrawableComposite::createFromValueTree (const ValueTree& tree) throw()
  67082. {
  67083. if (! tree.hasType ("Group"))
  67084. return 0;
  67085. DrawableComposite* dc = new DrawableComposite();
  67086. dc->setName (tree ["id"]);
  67087. for (int i = 0; i < tree.getNumChildren(); ++i)
  67088. {
  67089. ValueTree childTree (tree.getChild (i));
  67090. Drawable* d = Drawable::createFromValueTree (childTree);
  67091. if (d != 0)
  67092. {
  67093. AffineTransform transform;
  67094. const String transformAtt (childTree ["transform"].toString());
  67095. if (transformAtt.isNotEmpty())
  67096. {
  67097. StringArray tokens;
  67098. tokens.addTokens (transformAtt.trim(), false);
  67099. tokens.removeEmptyStrings (true);
  67100. if (tokens.size() == 6)
  67101. {
  67102. float f[6];
  67103. for (int j = 0; j < 6; ++j)
  67104. f[j] = (float) tokens[j].getDoubleValue();
  67105. transform = AffineTransform (f[0], f[1], f[2], f[3], f[4], f[5]);
  67106. }
  67107. }
  67108. dc->insertDrawable (d, transform);
  67109. }
  67110. }
  67111. return dc;
  67112. }
  67113. END_JUCE_NAMESPACE
  67114. /*** End of inlined file: juce_DrawableComposite.cpp ***/
  67115. /*** Start of inlined file: juce_DrawableImage.cpp ***/
  67116. BEGIN_JUCE_NAMESPACE
  67117. DrawableImage::DrawableImage()
  67118. : image (0),
  67119. canDeleteImage (false),
  67120. opacity (1.0f),
  67121. overlayColour (0x00000000)
  67122. {
  67123. }
  67124. DrawableImage::~DrawableImage()
  67125. {
  67126. clearImage();
  67127. }
  67128. void DrawableImage::clearImage()
  67129. {
  67130. if (canDeleteImage && image != 0)
  67131. ImageCache::releaseOrDelete (image);
  67132. image = 0;
  67133. }
  67134. void DrawableImage::setImage (const Image& imageToCopy)
  67135. {
  67136. clearImage();
  67137. image = new Image (imageToCopy);
  67138. canDeleteImage = true;
  67139. }
  67140. void DrawableImage::setImage (Image* imageToUse,
  67141. const bool releaseWhenNotNeeded)
  67142. {
  67143. clearImage();
  67144. image = imageToUse;
  67145. canDeleteImage = releaseWhenNotNeeded;
  67146. }
  67147. void DrawableImage::setOpacity (const float newOpacity)
  67148. {
  67149. opacity = newOpacity;
  67150. }
  67151. void DrawableImage::setOverlayColour (const Colour& newOverlayColour)
  67152. {
  67153. overlayColour = newOverlayColour;
  67154. }
  67155. void DrawableImage::render (const Drawable::RenderingContext& context) const
  67156. {
  67157. if (image != 0)
  67158. {
  67159. if (opacity > 0.0f && ! overlayColour.isOpaque())
  67160. {
  67161. context.g.setOpacity (context.opacity * opacity);
  67162. context.g.drawImageTransformed (image, image->getBounds(),
  67163. context.transform, false);
  67164. }
  67165. if (! overlayColour.isTransparent())
  67166. {
  67167. context.g.setColour (overlayColour.withMultipliedAlpha (context.opacity));
  67168. context.g.drawImageTransformed (image, image->getBounds(),
  67169. context.transform, true);
  67170. }
  67171. }
  67172. }
  67173. const Rectangle<float> DrawableImage::getBounds() const
  67174. {
  67175. if (image == 0)
  67176. return Rectangle<float>();
  67177. return Rectangle<float> (0, 0, (float) image->getWidth(), (float) image->getHeight());
  67178. }
  67179. bool DrawableImage::hitTest (float x, float y) const
  67180. {
  67181. return image != 0
  67182. && x >= 0.0f
  67183. && y >= 0.0f
  67184. && x < image->getWidth()
  67185. && y < image->getHeight()
  67186. && image->getPixelAt (roundToInt (x), roundToInt (y)).getAlpha() >= 127;
  67187. }
  67188. Drawable* DrawableImage::createCopy() const
  67189. {
  67190. DrawableImage* const di = new DrawableImage();
  67191. di->opacity = opacity;
  67192. di->overlayColour = overlayColour;
  67193. if (image != 0)
  67194. {
  67195. if ((! canDeleteImage) || ! ImageCache::isImageInCache (image))
  67196. {
  67197. di->setImage (*image);
  67198. }
  67199. else
  67200. {
  67201. ImageCache::incReferenceCount (image);
  67202. di->setImage (image, true);
  67203. }
  67204. }
  67205. return di;
  67206. }
  67207. ValueTree DrawableImage::createValueTree() const throw()
  67208. {
  67209. ValueTree v ("Image");
  67210. if (getName().isNotEmpty())
  67211. v.setProperty ("id", getName(), 0);
  67212. if (opacity < 1.0f)
  67213. v.setProperty ("opacity", (double) opacity, 0);
  67214. if (! overlayColour.isTransparent())
  67215. v.setProperty ("overlay", String::toHexString ((int) overlayColour.getARGB()), 0);
  67216. if (image != 0)
  67217. {
  67218. MemoryOutputStream imageData;
  67219. PNGImageFormat pngFormat;
  67220. if (pngFormat.writeImageToStream (*image, imageData))
  67221. {
  67222. String base64 (MemoryBlock (imageData.getData(), imageData.getDataSize()).toBase64Encoding());
  67223. for (int i = (base64.length() & ~127); i >= 0; i -= 128)
  67224. base64 = base64.substring (0, i) + "\n" + base64.substring (i);
  67225. v.setProperty ("data", base64, 0);
  67226. }
  67227. }
  67228. return v;
  67229. }
  67230. DrawableImage* DrawableImage::createFromValueTree (const ValueTree& tree) throw()
  67231. {
  67232. if (! tree.hasType ("Image"))
  67233. return 0;
  67234. DrawableImage* di = new DrawableImage();
  67235. di->setName (tree ["id"]);
  67236. di->opacity = tree.hasProperty ("opacity") ? (float) tree ["opacity"] : 1.0f;
  67237. di->overlayColour = Colour (tree ["overlay"].toString().getHexValue32());
  67238. MemoryBlock imageData;
  67239. if (imageData.fromBase64Encoding (tree ["data"]))
  67240. {
  67241. Image* const im = ImageFileFormat::loadFrom (imageData.getData(), (int) imageData.getSize());
  67242. if (im == 0)
  67243. return false;
  67244. di->setImage (im, true);
  67245. }
  67246. return di;
  67247. }
  67248. END_JUCE_NAMESPACE
  67249. /*** End of inlined file: juce_DrawableImage.cpp ***/
  67250. /*** Start of inlined file: juce_DrawablePath.cpp ***/
  67251. BEGIN_JUCE_NAMESPACE
  67252. DrawablePath::DrawablePath()
  67253. : mainFill (FillType (Colours::black)),
  67254. strokeFill (FillType (Colours::transparentBlack)),
  67255. strokeType (0.0f)
  67256. {
  67257. }
  67258. DrawablePath::~DrawablePath()
  67259. {
  67260. }
  67261. void DrawablePath::setPath (const Path& newPath) throw()
  67262. {
  67263. path = newPath;
  67264. updateOutline();
  67265. }
  67266. void DrawablePath::setFill (const FillType& newFill) throw()
  67267. {
  67268. mainFill = newFill;
  67269. }
  67270. void DrawablePath::setStrokeFill (const FillType& newFill) throw()
  67271. {
  67272. strokeFill = newFill;
  67273. }
  67274. void DrawablePath::setStrokeType (const PathStrokeType& newStrokeType) throw()
  67275. {
  67276. strokeType = newStrokeType;
  67277. updateOutline();
  67278. }
  67279. void DrawablePath::setStrokeThickness (const float newThickness) throw()
  67280. {
  67281. setStrokeType (PathStrokeType (newThickness, strokeType.getJointStyle(), strokeType.getEndStyle()));
  67282. }
  67283. void DrawablePath::render (const Drawable::RenderingContext& context) const
  67284. {
  67285. {
  67286. FillType f (mainFill);
  67287. if (f.isGradient())
  67288. f.gradient->multiplyOpacity (context.opacity);
  67289. f.transform = f.transform.followedBy (context.transform);
  67290. context.g.setFillType (f);
  67291. context.g.fillPath (path, context.transform);
  67292. }
  67293. if (strokeType.getStrokeThickness() > 0.0f)
  67294. {
  67295. FillType f (strokeFill);
  67296. if (f.isGradient())
  67297. f.gradient->multiplyOpacity (context.opacity);
  67298. f.transform = f.transform.followedBy (context.transform);
  67299. context.g.setFillType (f);
  67300. context.g.fillPath (stroke, context.transform);
  67301. }
  67302. }
  67303. void DrawablePath::updateOutline()
  67304. {
  67305. stroke.clear();
  67306. strokeType.createStrokedPath (stroke, path, AffineTransform::identity, 4.0f);
  67307. }
  67308. const Rectangle<float> DrawablePath::getBounds() const
  67309. {
  67310. if (strokeType.getStrokeThickness() > 0.0f)
  67311. return stroke.getBounds();
  67312. else
  67313. return path.getBounds();
  67314. }
  67315. bool DrawablePath::hitTest (float x, float y) const
  67316. {
  67317. return path.contains (x, y)
  67318. || stroke.contains (x, y);
  67319. }
  67320. Drawable* DrawablePath::createCopy() const
  67321. {
  67322. DrawablePath* const dp = new DrawablePath();
  67323. dp->path = path;
  67324. dp->stroke = stroke;
  67325. dp->mainFill = mainFill;
  67326. dp->strokeFill = strokeFill;
  67327. dp->strokeType = strokeType;
  67328. return dp;
  67329. }
  67330. static const FillType readFillTypeFromTree (const ValueTree& v)
  67331. {
  67332. const String type (v["type"].toString());
  67333. if (type.equalsIgnoreCase (T("solid")))
  67334. {
  67335. const String colour (v ["colour"].toString());
  67336. return FillType (Colour (colour.isEmpty() ? (uint32) 0xff000000
  67337. : (uint32) colour.getHexValue32()));
  67338. }
  67339. else if (type.equalsIgnoreCase ("gradient"))
  67340. {
  67341. ColourGradient g;
  67342. g.x1 = v["x1"];
  67343. g.y1 = v["y1"];
  67344. g.x2 = v["x2"];
  67345. g.y2 = v["y2"];
  67346. g.isRadial = v["radial"];
  67347. StringArray colours;
  67348. colours.addTokens (v["colours"].toString(), false);
  67349. for (int i = 0; i < colours.size() / 2; ++i)
  67350. g.addColour (colours[i * 2].getDoubleValue(),
  67351. Colour ((uint32) colours[i * 2 + 1].getHexValue32()));
  67352. return FillType (g);
  67353. }
  67354. jassertfalse
  67355. return FillType();
  67356. }
  67357. static ValueTree createTreeForFillType (const String& tagName, const FillType& fillType)
  67358. {
  67359. ValueTree v (tagName);
  67360. if (fillType.isColour())
  67361. {
  67362. v.setProperty ("type", "solid", 0);
  67363. v.setProperty ("colour", String::toHexString ((int) fillType.colour.getARGB()), 0);
  67364. }
  67365. else if (fillType.isGradient())
  67366. {
  67367. v.setProperty ("type", "gradient", 0);
  67368. v.setProperty ("x1", fillType.gradient->x1, 0);
  67369. v.setProperty ("y1", fillType.gradient->y1, 0);
  67370. v.setProperty ("x2", fillType.gradient->x2, 0);
  67371. v.setProperty ("y2", fillType.gradient->y2, 0);
  67372. v.setProperty ("radial", fillType.gradient->isRadial, 0);
  67373. String s;
  67374. for (int i = 0; i < fillType.gradient->getNumColours(); ++i)
  67375. s << " " << fillType.gradient->getColourPosition (i)
  67376. << " " << String::toHexString ((int) fillType.gradient->getColour(i).getARGB());
  67377. v.setProperty ("colours", s.trimStart(), 0);
  67378. }
  67379. else
  67380. {
  67381. jassertfalse //xxx
  67382. }
  67383. return v;
  67384. }
  67385. ValueTree DrawablePath::createValueTree() const throw()
  67386. {
  67387. ValueTree v ("Path");
  67388. v.addChild (createTreeForFillType ("fill", mainFill), -1, 0);
  67389. v.addChild (createTreeForFillType ("stroke", strokeFill), -1, 0);
  67390. if (getName().isNotEmpty())
  67391. v.setProperty ("id", getName(), 0);
  67392. v.setProperty ("strokeWidth", (double) strokeType.getStrokeThickness(), 0);
  67393. v.setProperty ("jointStyle", strokeType.getJointStyle() == PathStrokeType::mitered
  67394. ? "miter" : (strokeType.getJointStyle() == PathStrokeType::curved ? "curved" : "bevel"), 0);
  67395. v.setProperty ("capStyle", strokeType.getEndStyle() == PathStrokeType::butt
  67396. ? "butt" : (strokeType.getEndStyle() == PathStrokeType::square ? "square" : "round"), 0);
  67397. v.setProperty ("path", path.toString(), 0);
  67398. return v;
  67399. }
  67400. DrawablePath* DrawablePath::createFromValueTree (const ValueTree& tree) throw()
  67401. {
  67402. if (! tree.hasType ("Path"))
  67403. return 0;
  67404. DrawablePath* p = new DrawablePath();
  67405. p->setName (tree ["id"]);
  67406. p->mainFill = readFillTypeFromTree (tree.getChildWithName ("fill"));
  67407. p->strokeFill = readFillTypeFromTree (tree.getChildWithName ("stroke"));
  67408. const String jointStyle (tree ["jointStyle"].toString());
  67409. const String endStyle (tree ["capStyle"].toString());
  67410. p->strokeType
  67411. = PathStrokeType (tree ["strokeWidth"],
  67412. jointStyle.equalsIgnoreCase (T("curved")) ? PathStrokeType::curved
  67413. : (jointStyle.equalsIgnoreCase (T("bevel")) ? PathStrokeType::beveled
  67414. : PathStrokeType::mitered),
  67415. endStyle.equalsIgnoreCase (T("square")) ? PathStrokeType::square
  67416. : (endStyle.equalsIgnoreCase (T("round")) ? PathStrokeType::rounded
  67417. : PathStrokeType::butt));
  67418. p->path.clear();
  67419. p->path.restoreFromString (tree ["path"]);
  67420. p->updateOutline();
  67421. return p;
  67422. }
  67423. END_JUCE_NAMESPACE
  67424. /*** End of inlined file: juce_DrawablePath.cpp ***/
  67425. /*** Start of inlined file: juce_DrawableText.cpp ***/
  67426. BEGIN_JUCE_NAMESPACE
  67427. DrawableText::DrawableText()
  67428. : colour (Colours::white)
  67429. {
  67430. }
  67431. DrawableText::~DrawableText()
  67432. {
  67433. }
  67434. void DrawableText::setText (const GlyphArrangement& newText)
  67435. {
  67436. text = newText;
  67437. }
  67438. void DrawableText::setText (const String& newText, const Font& fontToUse)
  67439. {
  67440. text.clear();
  67441. text.addLineOfText (fontToUse, newText, 0.0f, 0.0f);
  67442. }
  67443. void DrawableText::setColour (const Colour& newColour)
  67444. {
  67445. colour = newColour;
  67446. }
  67447. void DrawableText::render (const Drawable::RenderingContext& context) const
  67448. {
  67449. context.g.setColour (colour.withMultipliedAlpha (context.opacity));
  67450. text.draw (context.g, context.transform);
  67451. }
  67452. const Rectangle<float> DrawableText::getBounds() const
  67453. {
  67454. float x, y, w, h;
  67455. text.getBoundingBox (0, -1, x, y, w, h, false); // (really returns top, left, bottom, right)
  67456. w -= x;
  67457. h -= y;
  67458. return Rectangle<float> (x, y, w, h);
  67459. }
  67460. bool DrawableText::hitTest (float x, float y) const
  67461. {
  67462. return text.findGlyphIndexAt (x, y) >= 0;
  67463. }
  67464. Drawable* DrawableText::createCopy() const
  67465. {
  67466. DrawableText* const dt = new DrawableText();
  67467. dt->text = text;
  67468. dt->colour = colour;
  67469. return dt;
  67470. }
  67471. ValueTree DrawableText::createValueTree() const throw()
  67472. {
  67473. ValueTree v ("Text");
  67474. if (getName().isNotEmpty())
  67475. v.setProperty ("id", getName(), 0);
  67476. jassertfalse // xxx not finished!
  67477. return v;
  67478. }
  67479. DrawableText* DrawableText::createFromValueTree (const ValueTree& tree) throw()
  67480. {
  67481. if (! tree.hasType ("Text"))
  67482. return 0;
  67483. DrawableText* dt = new DrawableText();
  67484. dt->setName (tree ["id"]);
  67485. jassertfalse // xxx not finished!
  67486. return dt;
  67487. }
  67488. END_JUCE_NAMESPACE
  67489. /*** End of inlined file: juce_DrawableText.cpp ***/
  67490. /*** Start of inlined file: juce_SVGParser.cpp ***/
  67491. BEGIN_JUCE_NAMESPACE
  67492. class SVGState
  67493. {
  67494. public:
  67495. SVGState (const XmlElement* const topLevel)
  67496. : topLevelXml (topLevel),
  67497. elementX (0), elementY (0),
  67498. width (512), height (512),
  67499. viewBoxW (0), viewBoxH (0)
  67500. {
  67501. }
  67502. ~SVGState()
  67503. {
  67504. }
  67505. Drawable* parseSVGElement (const XmlElement& xml)
  67506. {
  67507. if (! xml.hasTagName ("svg"))
  67508. return 0;
  67509. DrawableComposite* const drawable = new DrawableComposite();
  67510. drawable->setName (xml.getStringAttribute ("id"));
  67511. SVGState newState (*this);
  67512. if (xml.hasAttribute ("transform"))
  67513. newState.addTransform (xml);
  67514. newState.elementX = getCoordLength (xml.getStringAttribute ("x", String (newState.elementX)), viewBoxW);
  67515. newState.elementY = getCoordLength (xml.getStringAttribute ("y", String (newState.elementY)), viewBoxH);
  67516. newState.width = getCoordLength (xml.getStringAttribute ("width", String (newState.width)), viewBoxW);
  67517. newState.height = getCoordLength (xml.getStringAttribute ("height", String (newState.height)), viewBoxH);
  67518. if (xml.hasAttribute ("viewBox"))
  67519. {
  67520. const String viewParams (xml.getStringAttribute ("viewBox"));
  67521. int i = 0;
  67522. float vx, vy, vw, vh;
  67523. if (parseCoords (viewParams, vx, vy, i, true)
  67524. && parseCoords (viewParams, vw, vh, i, true)
  67525. && vw > 0
  67526. && vh > 0)
  67527. {
  67528. newState.viewBoxW = vw;
  67529. newState.viewBoxH = vh;
  67530. int placementFlags = 0;
  67531. const String aspect (xml.getStringAttribute ("preserveAspectRatio"));
  67532. if (aspect.containsIgnoreCase (T("none")))
  67533. {
  67534. placementFlags = RectanglePlacement::stretchToFit;
  67535. }
  67536. else
  67537. {
  67538. if (aspect.containsIgnoreCase (T("slice")))
  67539. placementFlags |= RectanglePlacement::fillDestination;
  67540. if (aspect.containsIgnoreCase (T("xMin")))
  67541. placementFlags |= RectanglePlacement::xLeft;
  67542. else if (aspect.containsIgnoreCase (T("xMax")))
  67543. placementFlags |= RectanglePlacement::xRight;
  67544. else
  67545. placementFlags |= RectanglePlacement::xMid;
  67546. if (aspect.containsIgnoreCase (T("yMin")))
  67547. placementFlags |= RectanglePlacement::yTop;
  67548. else if (aspect.containsIgnoreCase (T("yMax")))
  67549. placementFlags |= RectanglePlacement::yBottom;
  67550. else
  67551. placementFlags |= RectanglePlacement::yMid;
  67552. }
  67553. const RectanglePlacement placement (placementFlags);
  67554. newState.transform
  67555. = placement.getTransformToFit (vx, vy, vw, vh,
  67556. 0.0f, 0.0f, newState.width, newState.height)
  67557. .followedBy (newState.transform);
  67558. }
  67559. }
  67560. else
  67561. {
  67562. if (viewBoxW == 0)
  67563. newState.viewBoxW = newState.width;
  67564. if (viewBoxH == 0)
  67565. newState.viewBoxH = newState.height;
  67566. }
  67567. newState.parseSubElements (xml, drawable);
  67568. return drawable;
  67569. }
  67570. private:
  67571. const XmlElement* const topLevelXml;
  67572. float elementX, elementY, width, height, viewBoxW, viewBoxH;
  67573. AffineTransform transform;
  67574. String cssStyleText;
  67575. void parseSubElements (const XmlElement& xml, DrawableComposite* const parentDrawable)
  67576. {
  67577. forEachXmlChildElement (xml, e)
  67578. {
  67579. Drawable* d = 0;
  67580. if (e->hasTagName ("g"))
  67581. d = parseGroupElement (*e);
  67582. else if (e->hasTagName ("svg"))
  67583. d = parseSVGElement (*e);
  67584. else if (e->hasTagName ("path"))
  67585. d = parsePath (*e);
  67586. else if (e->hasTagName ("rect"))
  67587. d = parseRect (*e);
  67588. else if (e->hasTagName ("circle"))
  67589. d = parseCircle (*e);
  67590. else if (e->hasTagName ("ellipse"))
  67591. d = parseEllipse (*e);
  67592. else if (e->hasTagName ("line"))
  67593. d = parseLine (*e);
  67594. else if (e->hasTagName ("polyline"))
  67595. d = parsePolygon (*e, true);
  67596. else if (e->hasTagName ("polygon"))
  67597. d = parsePolygon (*e, false);
  67598. else if (e->hasTagName ("text"))
  67599. d = parseText (*e);
  67600. else if (e->hasTagName ("switch"))
  67601. d = parseSwitch (*e);
  67602. else if (e->hasTagName ("style"))
  67603. parseCSSStyle (*e);
  67604. parentDrawable->insertDrawable (d);
  67605. }
  67606. }
  67607. DrawableComposite* parseSwitch (const XmlElement& xml)
  67608. {
  67609. const XmlElement* const group = xml.getChildByName ("g");
  67610. if (group != 0)
  67611. return parseGroupElement (*group);
  67612. return 0;
  67613. }
  67614. DrawableComposite* parseGroupElement (const XmlElement& xml)
  67615. {
  67616. DrawableComposite* const drawable = new DrawableComposite();
  67617. drawable->setName (xml.getStringAttribute ("id"));
  67618. if (xml.hasAttribute ("transform"))
  67619. {
  67620. SVGState newState (*this);
  67621. newState.addTransform (xml);
  67622. newState.parseSubElements (xml, drawable);
  67623. }
  67624. else
  67625. {
  67626. parseSubElements (xml, drawable);
  67627. }
  67628. return drawable;
  67629. }
  67630. Drawable* parsePath (const XmlElement& xml) const
  67631. {
  67632. const String d (xml.getStringAttribute ("d").trimStart());
  67633. Path path;
  67634. if (getStyleAttribute (&xml, "fill-rule").trim().equalsIgnoreCase (T("evenodd")))
  67635. path.setUsingNonZeroWinding (false);
  67636. int index = 0;
  67637. float lastX = 0, lastY = 0;
  67638. float lastX2 = 0, lastY2 = 0;
  67639. tchar lastCommandChar = 0;
  67640. bool isRelative = true;
  67641. bool carryOn = true;
  67642. const String validCommandChars ("MmLlHhVvCcSsQqTtAaZz");
  67643. for (;;)
  67644. {
  67645. float x, y, x2, y2, x3, y3;
  67646. if (validCommandChars.containsChar (d[index]))
  67647. {
  67648. lastCommandChar = d [index++];
  67649. isRelative = (lastCommandChar >= 'a' && lastCommandChar <= 'z');
  67650. }
  67651. switch (lastCommandChar)
  67652. {
  67653. case 'M':
  67654. case 'm':
  67655. case 'L':
  67656. case 'l':
  67657. if (parseCoords (d, x, y, index, false))
  67658. {
  67659. if (isRelative)
  67660. {
  67661. x += lastX;
  67662. y += lastY;
  67663. }
  67664. if (lastCommandChar == 'M' || lastCommandChar == 'm')
  67665. path.startNewSubPath (x, y);
  67666. else
  67667. path.lineTo (x, y);
  67668. lastX2 = lastX;
  67669. lastY2 = lastY;
  67670. lastX = x;
  67671. lastY = y;
  67672. }
  67673. else
  67674. {
  67675. ++index;
  67676. }
  67677. break;
  67678. case 'H':
  67679. case 'h':
  67680. if (parseCoord (d, x, index, false, true))
  67681. {
  67682. if (isRelative)
  67683. x += lastX;
  67684. path.lineTo (x, lastY);
  67685. lastX2 = lastX;
  67686. lastX = x;
  67687. }
  67688. else
  67689. {
  67690. ++index;
  67691. }
  67692. break;
  67693. case 'V':
  67694. case 'v':
  67695. if (parseCoord (d, y, index, false, false))
  67696. {
  67697. if (isRelative)
  67698. y += lastY;
  67699. path.lineTo (lastX, y);
  67700. lastY2 = lastY;
  67701. lastY = y;
  67702. }
  67703. else
  67704. {
  67705. ++index;
  67706. }
  67707. break;
  67708. case 'C':
  67709. case 'c':
  67710. if (parseCoords (d, x, y, index, false)
  67711. && parseCoords (d, x2, y2, index, false)
  67712. && parseCoords (d, x3, y3, index, false))
  67713. {
  67714. if (isRelative)
  67715. {
  67716. x += lastX;
  67717. y += lastY;
  67718. x2 += lastX;
  67719. y2 += lastY;
  67720. x3 += lastX;
  67721. y3 += lastY;
  67722. }
  67723. path.cubicTo (x, y, x2, y2, x3, y3);
  67724. lastX2 = x2;
  67725. lastY2 = y2;
  67726. lastX = x3;
  67727. lastY = y3;
  67728. }
  67729. else
  67730. {
  67731. ++index;
  67732. }
  67733. break;
  67734. case 'S':
  67735. case 's':
  67736. if (parseCoords (d, x, y, index, false)
  67737. && parseCoords (d, x3, y3, index, false))
  67738. {
  67739. if (isRelative)
  67740. {
  67741. x += lastX;
  67742. y += lastY;
  67743. x3 += lastX;
  67744. y3 += lastY;
  67745. }
  67746. x2 = lastX + (lastX - lastX2);
  67747. y2 = lastY + (lastY - lastY2);
  67748. path.cubicTo (x2, y2, x, y, x3, y3);
  67749. lastX2 = x;
  67750. lastY2 = y;
  67751. lastX = x3;
  67752. lastY = y3;
  67753. }
  67754. else
  67755. {
  67756. ++index;
  67757. }
  67758. break;
  67759. case 'Q':
  67760. case 'q':
  67761. if (parseCoords (d, x, y, index, false)
  67762. && parseCoords (d, x2, y2, index, false))
  67763. {
  67764. if (isRelative)
  67765. {
  67766. x += lastX;
  67767. y += lastY;
  67768. x2 += lastX;
  67769. y2 += lastY;
  67770. }
  67771. path.quadraticTo (x, y, x2, y2);
  67772. lastX2 = x;
  67773. lastY2 = y;
  67774. lastX = x2;
  67775. lastY = y2;
  67776. }
  67777. else
  67778. {
  67779. ++index;
  67780. }
  67781. break;
  67782. case 'T':
  67783. case 't':
  67784. if (parseCoords (d, x, y, index, false))
  67785. {
  67786. if (isRelative)
  67787. {
  67788. x += lastX;
  67789. y += lastY;
  67790. }
  67791. x2 = lastX + (lastX - lastX2);
  67792. y2 = lastY + (lastY - lastY2);
  67793. path.quadraticTo (x2, y2, x, y);
  67794. lastX2 = x2;
  67795. lastY2 = y2;
  67796. lastX = x;
  67797. lastY = y;
  67798. }
  67799. else
  67800. {
  67801. ++index;
  67802. }
  67803. break;
  67804. case 'A':
  67805. case 'a':
  67806. if (parseCoords (d, x, y, index, false))
  67807. {
  67808. String num;
  67809. if (parseNextNumber (d, num, index, false))
  67810. {
  67811. const float angle = num.getFloatValue() * (180.0f / float_Pi);
  67812. if (parseNextNumber (d, num, index, false))
  67813. {
  67814. const bool largeArc = num.getIntValue() != 0;
  67815. if (parseNextNumber (d, num, index, false))
  67816. {
  67817. const bool sweep = num.getIntValue() != 0;
  67818. if (parseCoords (d, x2, y2, index, false))
  67819. {
  67820. if (isRelative)
  67821. {
  67822. x2 += lastX;
  67823. y2 += lastY;
  67824. }
  67825. if (lastX != x2 || lastY != y2)
  67826. {
  67827. double centreX, centreY, startAngle, deltaAngle;
  67828. double rx = x, ry = y;
  67829. endpointToCentreParameters (lastX, lastY, x2, y2,
  67830. angle, largeArc, sweep,
  67831. rx, ry, centreX, centreY,
  67832. startAngle, deltaAngle);
  67833. path.addCentredArc ((float) centreX, (float) centreY,
  67834. (float) rx, (float) ry,
  67835. angle, (float) startAngle, (float) (startAngle + deltaAngle),
  67836. false);
  67837. path.lineTo (x2, y2);
  67838. }
  67839. lastX2 = lastX;
  67840. lastY2 = lastY;
  67841. lastX = x2;
  67842. lastY = y2;
  67843. }
  67844. }
  67845. }
  67846. }
  67847. }
  67848. else
  67849. {
  67850. ++index;
  67851. }
  67852. break;
  67853. case 'Z':
  67854. case 'z':
  67855. path.closeSubPath();
  67856. while (CharacterFunctions::isWhitespace (d [index]))
  67857. ++index;
  67858. break;
  67859. default:
  67860. carryOn = false;
  67861. break;
  67862. }
  67863. if (! carryOn)
  67864. break;
  67865. }
  67866. return parseShape (xml, path);
  67867. }
  67868. Drawable* parseRect (const XmlElement& xml) const
  67869. {
  67870. Path rect;
  67871. const bool hasRX = xml.hasAttribute ("rx");
  67872. const bool hasRY = xml.hasAttribute ("ry");
  67873. if (hasRX || hasRY)
  67874. {
  67875. float rx = getCoordLength (xml.getStringAttribute ("rx"), viewBoxW);
  67876. float ry = getCoordLength (xml.getStringAttribute ("ry"), viewBoxH);
  67877. if (! hasRX)
  67878. rx = ry;
  67879. else if (! hasRY)
  67880. ry = rx;
  67881. rect.addRoundedRectangle (getCoordLength (xml.getStringAttribute ("x"), viewBoxW),
  67882. getCoordLength (xml.getStringAttribute ("y"), viewBoxH),
  67883. getCoordLength (xml.getStringAttribute ("width"), viewBoxW),
  67884. getCoordLength (xml.getStringAttribute ("height"), viewBoxH),
  67885. rx, ry);
  67886. }
  67887. else
  67888. {
  67889. rect.addRectangle (getCoordLength (xml.getStringAttribute ("x"), viewBoxW),
  67890. getCoordLength (xml.getStringAttribute ("y"), viewBoxH),
  67891. getCoordLength (xml.getStringAttribute ("width"), viewBoxW),
  67892. getCoordLength (xml.getStringAttribute ("height"), viewBoxH));
  67893. }
  67894. return parseShape (xml, rect);
  67895. }
  67896. Drawable* parseCircle (const XmlElement& xml) const
  67897. {
  67898. Path circle;
  67899. const float cx = getCoordLength (xml.getStringAttribute ("cx"), viewBoxW);
  67900. const float cy = getCoordLength (xml.getStringAttribute ("cy"), viewBoxH);
  67901. const float radius = getCoordLength (xml.getStringAttribute ("r"), viewBoxW);
  67902. circle.addEllipse (cx - radius, cy - radius, radius * 2.0f, radius * 2.0f);
  67903. return parseShape (xml, circle);
  67904. }
  67905. Drawable* parseEllipse (const XmlElement& xml) const
  67906. {
  67907. Path ellipse;
  67908. const float cx = getCoordLength (xml.getStringAttribute ("cx"), viewBoxW);
  67909. const float cy = getCoordLength (xml.getStringAttribute ("cy"), viewBoxH);
  67910. const float radiusX = getCoordLength (xml.getStringAttribute ("rx"), viewBoxW);
  67911. const float radiusY = getCoordLength (xml.getStringAttribute ("ry"), viewBoxH);
  67912. ellipse.addEllipse (cx - radiusX, cy - radiusY, radiusX * 2.0f, radiusY * 2.0f);
  67913. return parseShape (xml, ellipse);
  67914. }
  67915. Drawable* parseLine (const XmlElement& xml) const
  67916. {
  67917. Path line;
  67918. const float x1 = getCoordLength (xml.getStringAttribute ("x1"), viewBoxW);
  67919. const float y1 = getCoordLength (xml.getStringAttribute ("y1"), viewBoxH);
  67920. const float x2 = getCoordLength (xml.getStringAttribute ("x2"), viewBoxW);
  67921. const float y2 = getCoordLength (xml.getStringAttribute ("y2"), viewBoxH);
  67922. line.startNewSubPath (x1, y1);
  67923. line.lineTo (x2, y2);
  67924. return parseShape (xml, line);
  67925. }
  67926. Drawable* parsePolygon (const XmlElement& xml, const bool isPolyline) const
  67927. {
  67928. const String points (xml.getStringAttribute ("points"));
  67929. Path path;
  67930. int index = 0;
  67931. float x, y;
  67932. if (parseCoords (points, x, y, index, true))
  67933. {
  67934. float firstX = x;
  67935. float firstY = y;
  67936. float lastX = 0, lastY = 0;
  67937. path.startNewSubPath (x, y);
  67938. while (parseCoords (points, x, y, index, true))
  67939. {
  67940. lastX = x;
  67941. lastY = y;
  67942. path.lineTo (x, y);
  67943. }
  67944. if ((! isPolyline) || (firstX == lastX && firstY == lastY))
  67945. path.closeSubPath();
  67946. }
  67947. return parseShape (xml, path);
  67948. }
  67949. Drawable* parseShape (const XmlElement& xml, Path& path,
  67950. const bool shouldParseTransform = true) const
  67951. {
  67952. if (shouldParseTransform && xml.hasAttribute ("transform"))
  67953. {
  67954. SVGState newState (*this);
  67955. newState.addTransform (xml);
  67956. return newState.parseShape (xml, path, false);
  67957. }
  67958. DrawablePath* dp = new DrawablePath();
  67959. dp->setName (xml.getStringAttribute ("id"));
  67960. dp->setFill (FillType (Colours::transparentBlack));
  67961. path.applyTransform (transform);
  67962. dp->setPath (path);
  67963. Path::Iterator iter (path);
  67964. bool containsClosedSubPath = false;
  67965. while (iter.next())
  67966. {
  67967. if (iter.elementType == Path::Iterator::closePath)
  67968. {
  67969. containsClosedSubPath = true;
  67970. break;
  67971. }
  67972. }
  67973. dp->setFill (getPathFillType (path,
  67974. getStyleAttribute (&xml, "fill"),
  67975. getStyleAttribute (&xml, "fill-opacity"),
  67976. getStyleAttribute (&xml, "opacity"),
  67977. containsClosedSubPath ? Colours::black
  67978. : Colours::transparentBlack));
  67979. const String strokeType (getStyleAttribute (&xml, "stroke"));
  67980. if (strokeType.isNotEmpty() && ! strokeType.equalsIgnoreCase ("none"))
  67981. {
  67982. dp->setStrokeFill (getPathFillType (path, strokeType,
  67983. getStyleAttribute (&xml, "stroke-opacity"),
  67984. getStyleAttribute (&xml, "opacity"),
  67985. Colours::transparentBlack));
  67986. dp->setStrokeType (getStrokeFor (&xml));
  67987. }
  67988. return dp;
  67989. }
  67990. const XmlElement* findLinkedElement (const XmlElement* e) const
  67991. {
  67992. const String id (e->getStringAttribute ("xlink:href"));
  67993. if (! id.startsWithChar ('#'))
  67994. return 0;
  67995. return findElementForId (topLevelXml, id.substring (1));
  67996. }
  67997. void addGradientStopsIn (ColourGradient& cg, const XmlElement* const fillXml) const
  67998. {
  67999. if (fillXml == 0)
  68000. return;
  68001. forEachXmlChildElementWithTagName (*fillXml, e, "stop")
  68002. {
  68003. int index = 0;
  68004. Colour col (parseColour (getStyleAttribute (e, "stop-color"), index, Colours::black));
  68005. const String opacity (getStyleAttribute (e, "stop-opacity", "1"));
  68006. col = col.withMultipliedAlpha (jlimit (0.0f, 1.0f, opacity.getFloatValue()));
  68007. double offset = e->getDoubleAttribute ("offset");
  68008. if (e->getStringAttribute ("offset").containsChar ('%'))
  68009. offset *= 0.01;
  68010. cg.addColour (jlimit (0.0, 1.0, offset), col);
  68011. }
  68012. }
  68013. const FillType getPathFillType (const Path& path,
  68014. const String& fill,
  68015. const String& fillOpacity,
  68016. const String& overallOpacity,
  68017. const Colour& defaultColour) const
  68018. {
  68019. float opacity = 1.0f;
  68020. if (overallOpacity.isNotEmpty())
  68021. opacity = jlimit (0.0f, 1.0f, overallOpacity.getFloatValue());
  68022. if (fillOpacity.isNotEmpty())
  68023. opacity *= (jlimit (0.0f, 1.0f, fillOpacity.getFloatValue()));
  68024. if (fill.startsWithIgnoreCase (T("url")))
  68025. {
  68026. const String id (fill.fromFirstOccurrenceOf (T("#"), false, false)
  68027. .upToLastOccurrenceOf (T(")"), false, false).trim());
  68028. const XmlElement* const fillXml = findElementForId (topLevelXml, id);
  68029. if (fillXml != 0
  68030. && (fillXml->hasTagName ("linearGradient")
  68031. || fillXml->hasTagName ("radialGradient")))
  68032. {
  68033. const XmlElement* inheritedFrom = findLinkedElement (fillXml);
  68034. ColourGradient gradient;
  68035. addGradientStopsIn (gradient, inheritedFrom);
  68036. addGradientStopsIn (gradient, fillXml);
  68037. if (gradient.getNumColours() > 0)
  68038. {
  68039. gradient.addColour (0.0, gradient.getColour (0));
  68040. gradient.addColour (1.0, gradient.getColour (gradient.getNumColours() - 1));
  68041. }
  68042. else
  68043. {
  68044. gradient.addColour (0.0, Colours::black);
  68045. gradient.addColour (1.0, Colours::black);
  68046. }
  68047. if (overallOpacity.isNotEmpty())
  68048. gradient.multiplyOpacity (overallOpacity.getFloatValue());
  68049. jassert (gradient.getNumColours() > 0);
  68050. gradient.isRadial = fillXml->hasTagName ("radialGradient");
  68051. float width = viewBoxW;
  68052. float height = viewBoxH;
  68053. float dx = 0.0f;
  68054. float dy = 0.0f;
  68055. const bool userSpace = fillXml->getStringAttribute ("gradientUnits").equalsIgnoreCase (T("userSpaceOnUse"));
  68056. if (! userSpace)
  68057. {
  68058. const Rectangle<float> bounds (path.getBounds());
  68059. dx = bounds.getX();
  68060. dy = bounds.getY();
  68061. width = bounds.getWidth();
  68062. height = bounds.getHeight();
  68063. }
  68064. if (gradient.isRadial)
  68065. {
  68066. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute ("cx", "50%"), width);
  68067. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute ("cy", "50%"), height);
  68068. const float radius = getCoordLength (fillXml->getStringAttribute ("r", "50%"), width);
  68069. gradient.x2 = gradient.x1 + radius;
  68070. gradient.y2 = gradient.y1;
  68071. //xxx (the fx, fy focal point isn't handled properly here..)
  68072. }
  68073. else
  68074. {
  68075. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute ("x1", "0%"), width);
  68076. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute ("y1", "0%"), height);
  68077. gradient.x2 = dx + getCoordLength (fillXml->getStringAttribute ("x2", "100%"), width);
  68078. gradient.y2 = dy + getCoordLength (fillXml->getStringAttribute ("y2", "0%"), height);
  68079. if (gradient.x1 == gradient.x2 && gradient.y1 == gradient.y2)
  68080. return Colour (gradient.getColour (gradient.getNumColours() - 1));
  68081. }
  68082. FillType type (gradient);
  68083. type.transform = parseTransform (fillXml->getStringAttribute ("gradientTransform"))
  68084. .followedBy (transform);
  68085. return type;
  68086. }
  68087. }
  68088. if (fill.equalsIgnoreCase (T("none")))
  68089. return Colours::transparentBlack;
  68090. int i = 0;
  68091. const Colour colour (parseColour (fill, i, defaultColour));
  68092. return colour.withMultipliedAlpha (opacity);
  68093. }
  68094. const PathStrokeType getStrokeFor (const XmlElement* const xml) const
  68095. {
  68096. const String width (getStyleAttribute (xml, "stroke-width"));
  68097. const String cap (getStyleAttribute (xml, "stroke-linecap"));
  68098. const String join (getStyleAttribute (xml, "stroke-linejoin"));
  68099. //const String mitreLimit (getStyleAttribute (xml, T("stroke-miterlimit")));
  68100. //const String dashArray (getStyleAttribute (xml, T("stroke-dasharray")));
  68101. //const String dashOffset (getStyleAttribute (xml, T("stroke-dashoffset")));
  68102. PathStrokeType::JointStyle joinStyle = PathStrokeType::mitered;
  68103. PathStrokeType::EndCapStyle capStyle = PathStrokeType::butt;
  68104. if (join.equalsIgnoreCase (T("round")))
  68105. joinStyle = PathStrokeType::curved;
  68106. else if (join.equalsIgnoreCase (T("bevel")))
  68107. joinStyle = PathStrokeType::beveled;
  68108. if (cap.equalsIgnoreCase (T("round")))
  68109. capStyle = PathStrokeType::rounded;
  68110. else if (cap.equalsIgnoreCase (T("square")))
  68111. capStyle = PathStrokeType::square;
  68112. float ox = 0.0f, oy = 0.0f;
  68113. transform.transformPoint (ox, oy);
  68114. float x = getCoordLength (width, viewBoxW), y = 0.0f;
  68115. transform.transformPoint (x, y);
  68116. return PathStrokeType (width.isNotEmpty() ? juce_hypotf (x - ox, y - oy) : 1.0f,
  68117. joinStyle, capStyle);
  68118. }
  68119. Drawable* parseText (const XmlElement& xml)
  68120. {
  68121. Array <float> xCoords, yCoords, dxCoords, dyCoords;
  68122. getCoordList (xCoords, getInheritedAttribute (&xml, "x"), true, true);
  68123. getCoordList (yCoords, getInheritedAttribute (&xml, "y"), true, false);
  68124. getCoordList (dxCoords, getInheritedAttribute (&xml, "dx"), true, true);
  68125. getCoordList (dyCoords, getInheritedAttribute (&xml, "dy"), true, false);
  68126. //xxx not done text yet!
  68127. forEachXmlChildElement (xml, e)
  68128. {
  68129. if (e->isTextElement())
  68130. {
  68131. const String text (e->getText());
  68132. Path path;
  68133. Drawable* s = parseShape (*e, path);
  68134. delete s;
  68135. }
  68136. else if (e->hasTagName ("tspan"))
  68137. {
  68138. Drawable* s = parseText (*e);
  68139. delete s;
  68140. }
  68141. }
  68142. return 0;
  68143. }
  68144. void addTransform (const XmlElement& xml)
  68145. {
  68146. transform = parseTransform (xml.getStringAttribute ("transform"))
  68147. .followedBy (transform);
  68148. }
  68149. bool parseCoord (const String& s, float& value, int& index,
  68150. const bool allowUnits, const bool isX) const
  68151. {
  68152. String number;
  68153. if (! parseNextNumber (s, number, index, allowUnits))
  68154. {
  68155. value = 0;
  68156. return false;
  68157. }
  68158. value = getCoordLength (number, isX ? viewBoxW : viewBoxH);
  68159. return true;
  68160. }
  68161. bool parseCoords (const String& s, float& x, float& y,
  68162. int& index, const bool allowUnits) const
  68163. {
  68164. return parseCoord (s, x, index, allowUnits, true)
  68165. && parseCoord (s, y, index, allowUnits, false);
  68166. }
  68167. float getCoordLength (const String& s, const float sizeForProportions) const
  68168. {
  68169. float n = s.getFloatValue();
  68170. const int len = s.length();
  68171. if (len > 2)
  68172. {
  68173. const float dpi = 96.0f;
  68174. const tchar n1 = s [len - 2];
  68175. const tchar n2 = s [len - 1];
  68176. if (n1 == 'i' && n2 == 'n')
  68177. n *= dpi;
  68178. else if (n1 == 'm' && n2 == 'm')
  68179. n *= dpi / 25.4f;
  68180. else if (n1 == 'c' && n2 == 'm')
  68181. n *= dpi / 2.54f;
  68182. else if (n1 == 'p' && n2 == 'c')
  68183. n *= 15.0f;
  68184. else if (n2 == '%')
  68185. n *= 0.01f * sizeForProportions;
  68186. }
  68187. return n;
  68188. }
  68189. void getCoordList (Array <float>& coords, const String& list,
  68190. const bool allowUnits, const bool isX) const
  68191. {
  68192. int index = 0;
  68193. float value;
  68194. while (parseCoord (list, value, index, allowUnits, isX))
  68195. coords.add (value);
  68196. }
  68197. void parseCSSStyle (const XmlElement& xml)
  68198. {
  68199. cssStyleText = xml.getAllSubText() + "\n" + cssStyleText;
  68200. }
  68201. const String getStyleAttribute (const XmlElement* xml, const String& attributeName,
  68202. const String& defaultValue = String::empty) const
  68203. {
  68204. if (xml->hasAttribute (attributeName))
  68205. return xml->getStringAttribute (attributeName, defaultValue);
  68206. const String styleAtt (xml->getStringAttribute ("style"));
  68207. if (styleAtt.isNotEmpty())
  68208. {
  68209. const String value (getAttributeFromStyleList (styleAtt, attributeName, String::empty));
  68210. if (value.isNotEmpty())
  68211. return value;
  68212. }
  68213. else if (xml->hasAttribute ("class"))
  68214. {
  68215. const String className ("." + xml->getStringAttribute ("class"));
  68216. int index = cssStyleText.indexOfIgnoreCase (className + " ");
  68217. if (index < 0)
  68218. index = cssStyleText.indexOfIgnoreCase (className + "{");
  68219. if (index >= 0)
  68220. {
  68221. const int openBracket = cssStyleText.indexOfChar (index, '{');
  68222. if (openBracket > index)
  68223. {
  68224. const int closeBracket = cssStyleText.indexOfChar (openBracket, '}');
  68225. if (closeBracket > openBracket)
  68226. {
  68227. const String value (getAttributeFromStyleList (cssStyleText.substring (openBracket + 1, closeBracket), attributeName, defaultValue));
  68228. if (value.isNotEmpty())
  68229. return value;
  68230. }
  68231. }
  68232. }
  68233. }
  68234. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68235. if (xml != 0)
  68236. return getStyleAttribute (xml, attributeName, defaultValue);
  68237. return defaultValue;
  68238. }
  68239. const String getInheritedAttribute (const XmlElement* xml, const String& attributeName) const
  68240. {
  68241. if (xml->hasAttribute (attributeName))
  68242. return xml->getStringAttribute (attributeName);
  68243. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68244. if (xml != 0)
  68245. return getInheritedAttribute (xml, attributeName);
  68246. return String::empty;
  68247. }
  68248. static bool isIdentifierChar (const tchar c)
  68249. {
  68250. return CharacterFunctions::isLetter (c) || c == '-';
  68251. }
  68252. static const String getAttributeFromStyleList (const String& list, const String& attributeName, const String& defaultValue)
  68253. {
  68254. int i = 0;
  68255. for (;;)
  68256. {
  68257. i = list.indexOf (i, attributeName);
  68258. if (i < 0)
  68259. break;
  68260. if ((i == 0 || (i > 0 && ! isIdentifierChar (list [i - 1])))
  68261. && ! isIdentifierChar (list [i + attributeName.length()]))
  68262. {
  68263. i = list.indexOfChar (i, ':');
  68264. if (i < 0)
  68265. break;
  68266. int end = list.indexOfChar (i, ';');
  68267. if (end < 0)
  68268. end = 0x7ffff;
  68269. return list.substring (i + 1, end).trim();
  68270. }
  68271. ++i;
  68272. }
  68273. return defaultValue;
  68274. }
  68275. static bool parseNextNumber (const String& source, String& value, int& index, const bool allowUnits)
  68276. {
  68277. const tchar* const s = (const tchar*) source;
  68278. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == ',')
  68279. ++index;
  68280. int start = index;
  68281. if (CharacterFunctions::isDigit (s[index]) || s[index] == '.' || s[index] == '-')
  68282. ++index;
  68283. while (CharacterFunctions::isDigit (s[index]) || s[index] == '.')
  68284. ++index;
  68285. if ((s[index] == 'e' || s[index] == 'E')
  68286. && (CharacterFunctions::isDigit (s[index + 1])
  68287. || s[index + 1] == '-'
  68288. || s[index + 1] == '+'))
  68289. {
  68290. index += 2;
  68291. while (CharacterFunctions::isDigit (s[index]))
  68292. ++index;
  68293. }
  68294. if (allowUnits)
  68295. {
  68296. while (CharacterFunctions::isLetter (s[index]))
  68297. ++index;
  68298. }
  68299. if (index == start)
  68300. return false;
  68301. value = String (s + start, index - start);
  68302. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == ',')
  68303. ++index;
  68304. return true;
  68305. }
  68306. static const Colour parseColour (const String& s, int& index, const Colour& defaultColour)
  68307. {
  68308. if (s [index] == '#')
  68309. {
  68310. uint32 hex [6];
  68311. zeromem (hex, sizeof (hex));
  68312. int numChars = 0;
  68313. for (int i = 6; --i >= 0;)
  68314. {
  68315. const int hexValue = CharacterFunctions::getHexDigitValue (s [++index]);
  68316. if (hexValue >= 0)
  68317. hex [numChars++] = hexValue;
  68318. else
  68319. break;
  68320. }
  68321. if (numChars <= 3)
  68322. return Colour ((uint8) (hex [0] * 0x11),
  68323. (uint8) (hex [1] * 0x11),
  68324. (uint8) (hex [2] * 0x11));
  68325. else
  68326. return Colour ((uint8) ((hex [0] << 4) + hex [1]),
  68327. (uint8) ((hex [2] << 4) + hex [3]),
  68328. (uint8) ((hex [4] << 4) + hex [5]));
  68329. }
  68330. else if (s [index] == 'r'
  68331. && s [index + 1] == 'g'
  68332. && s [index + 2] == 'b')
  68333. {
  68334. const int openBracket = s.indexOfChar (index, '(');
  68335. const int closeBracket = s.indexOfChar (openBracket, ')');
  68336. if (openBracket >= 3 && closeBracket > openBracket)
  68337. {
  68338. index = closeBracket;
  68339. StringArray tokens;
  68340. tokens.addTokens (s.substring (openBracket + 1, closeBracket), ",", "");
  68341. tokens.trim();
  68342. tokens.removeEmptyStrings();
  68343. if (tokens[0].containsChar ('%'))
  68344. return Colour ((uint8) roundToInt (2.55 * tokens[0].getDoubleValue()),
  68345. (uint8) roundToInt (2.55 * tokens[1].getDoubleValue()),
  68346. (uint8) roundToInt (2.55 * tokens[2].getDoubleValue()));
  68347. else
  68348. return Colour ((uint8) tokens[0].getIntValue(),
  68349. (uint8) tokens[1].getIntValue(),
  68350. (uint8) tokens[2].getIntValue());
  68351. }
  68352. }
  68353. return Colours::findColourForName (s, defaultColour);
  68354. }
  68355. static const AffineTransform parseTransform (String t)
  68356. {
  68357. AffineTransform result;
  68358. while (t.isNotEmpty())
  68359. {
  68360. StringArray tokens;
  68361. tokens.addTokens (t.fromFirstOccurrenceOf (T("("), false, false)
  68362. .upToFirstOccurrenceOf (T(")"), false, false),
  68363. ", ", String::empty);
  68364. tokens.removeEmptyStrings (true);
  68365. float numbers [6];
  68366. for (int i = 0; i < 6; ++i)
  68367. numbers[i] = tokens[i].getFloatValue();
  68368. AffineTransform trans;
  68369. if (t.startsWithIgnoreCase (T("matrix")))
  68370. {
  68371. trans = AffineTransform (numbers[0], numbers[2], numbers[4],
  68372. numbers[1], numbers[3], numbers[5]);
  68373. }
  68374. else if (t.startsWithIgnoreCase (T("translate")))
  68375. {
  68376. jassert (tokens.size() == 2);
  68377. trans = AffineTransform::translation (numbers[0], numbers[1]);
  68378. }
  68379. else if (t.startsWithIgnoreCase (T("scale")))
  68380. {
  68381. if (tokens.size() == 1)
  68382. trans = AffineTransform::scale (numbers[0], numbers[0]);
  68383. else
  68384. trans = AffineTransform::scale (numbers[0], numbers[1]);
  68385. }
  68386. else if (t.startsWithIgnoreCase (T("rotate")))
  68387. {
  68388. if (tokens.size() != 3)
  68389. trans = AffineTransform::rotation (numbers[0] / (180.0f / float_Pi));
  68390. else
  68391. trans = AffineTransform::rotation (numbers[0] / (180.0f / float_Pi),
  68392. numbers[1], numbers[2]);
  68393. }
  68394. else if (t.startsWithIgnoreCase (T("skewX")))
  68395. {
  68396. trans = AffineTransform (1.0f, tanf (numbers[0] * (float_Pi / 180.0f)), 0.0f,
  68397. 0.0f, 1.0f, 0.0f);
  68398. }
  68399. else if (t.startsWithIgnoreCase (T("skewY")))
  68400. {
  68401. trans = AffineTransform (1.0f, 0.0f, 0.0f,
  68402. tanf (numbers[0] * (float_Pi / 180.0f)), 1.0f, 0.0f);
  68403. }
  68404. result = trans.followedBy (result);
  68405. t = t.fromFirstOccurrenceOf (T(")"), false, false).trimStart();
  68406. }
  68407. return result;
  68408. }
  68409. static void endpointToCentreParameters (const double x1, const double y1,
  68410. const double x2, const double y2,
  68411. const double angle,
  68412. const bool largeArc, const bool sweep,
  68413. double& rx, double& ry,
  68414. double& centreX, double& centreY,
  68415. double& startAngle, double& deltaAngle)
  68416. {
  68417. const double midX = (x1 - x2) * 0.5;
  68418. const double midY = (y1 - y2) * 0.5;
  68419. const double cosAngle = cos (angle);
  68420. const double sinAngle = sin (angle);
  68421. const double xp = cosAngle * midX + sinAngle * midY;
  68422. const double yp = cosAngle * midY - sinAngle * midX;
  68423. const double xp2 = xp * xp;
  68424. const double yp2 = yp * yp;
  68425. double rx2 = rx * rx;
  68426. double ry2 = ry * ry;
  68427. const double s = (xp2 / rx2) + (yp2 / ry2);
  68428. double c;
  68429. if (s <= 1.0)
  68430. {
  68431. c = sqrt (jmax (0.0, ((rx2 * ry2) - (rx2 * yp2) - (ry2 * xp2))
  68432. / (( rx2 * yp2) + (ry2 * xp2))));
  68433. if (largeArc == sweep)
  68434. c = -c;
  68435. }
  68436. else
  68437. {
  68438. const double s2 = sqrt (s);
  68439. rx *= s2;
  68440. ry *= s2;
  68441. rx2 = rx * rx;
  68442. ry2 = ry * ry;
  68443. c = 0;
  68444. }
  68445. const double cpx = ((rx * yp) / ry) * c;
  68446. const double cpy = ((-ry * xp) / rx) * c;
  68447. centreX = ((x1 + x2) * 0.5) + (cosAngle * cpx) - (sinAngle * cpy);
  68448. centreY = ((y1 + y2) * 0.5) + (sinAngle * cpx) + (cosAngle * cpy);
  68449. const double ux = (xp - cpx) / rx;
  68450. const double uy = (yp - cpy) / ry;
  68451. const double vx = (-xp - cpx) / rx;
  68452. const double vy = (-yp - cpy) / ry;
  68453. const double length = juce_hypot (ux, uy);
  68454. startAngle = acos (jlimit (-1.0, 1.0, ux / length));
  68455. if (uy < 0)
  68456. startAngle = -startAngle;
  68457. startAngle += double_Pi * 0.5;
  68458. deltaAngle = acos (jlimit (-1.0, 1.0, ((ux * vx) + (uy * vy))
  68459. / (length * juce_hypot (vx, vy))));
  68460. if ((ux * vy) - (uy * vx) < 0)
  68461. deltaAngle = -deltaAngle;
  68462. if (sweep)
  68463. {
  68464. if (deltaAngle < 0)
  68465. deltaAngle += double_Pi * 2.0;
  68466. }
  68467. else
  68468. {
  68469. if (deltaAngle > 0)
  68470. deltaAngle -= double_Pi * 2.0;
  68471. }
  68472. deltaAngle = fmod (deltaAngle, double_Pi * 2.0);
  68473. }
  68474. static const XmlElement* findElementForId (const XmlElement* const parent, const String& id)
  68475. {
  68476. forEachXmlChildElement (*parent, e)
  68477. {
  68478. if (e->compareAttribute ("id", id))
  68479. return e;
  68480. const XmlElement* const found = findElementForId (e, id);
  68481. if (found != 0)
  68482. return found;
  68483. }
  68484. return 0;
  68485. }
  68486. SVGState& operator= (const SVGState&);
  68487. };
  68488. Drawable* Drawable::createFromSVG (const XmlElement& svgDocument)
  68489. {
  68490. SVGState state (&svgDocument);
  68491. return state.parseSVGElement (svgDocument);
  68492. }
  68493. END_JUCE_NAMESPACE
  68494. /*** End of inlined file: juce_SVGParser.cpp ***/
  68495. /*** Start of inlined file: juce_DropShadowEffect.cpp ***/
  68496. BEGIN_JUCE_NAMESPACE
  68497. #if JUCE_MSVC
  68498. #pragma optimize ("t", on) // try to avoid slowing everything down in debug builds
  68499. #endif
  68500. DropShadowEffect::DropShadowEffect()
  68501. : offsetX (0),
  68502. offsetY (0),
  68503. radius (4),
  68504. opacity (0.6f)
  68505. {
  68506. }
  68507. DropShadowEffect::~DropShadowEffect()
  68508. {
  68509. }
  68510. void DropShadowEffect::setShadowProperties (const float newRadius,
  68511. const float newOpacity,
  68512. const int newShadowOffsetX,
  68513. const int newShadowOffsetY)
  68514. {
  68515. radius = jmax (1.1f, newRadius);
  68516. offsetX = newShadowOffsetX;
  68517. offsetY = newShadowOffsetY;
  68518. opacity = newOpacity;
  68519. }
  68520. void DropShadowEffect::applyEffect (Image& image, Graphics& g)
  68521. {
  68522. const int w = image.getWidth();
  68523. const int h = image.getHeight();
  68524. Image shadowImage (Image::SingleChannel, w, h, false);
  68525. const Image::BitmapData srcData (image, 0, 0, w, h);
  68526. const Image::BitmapData destData (shadowImage, 0, 0, w, h, true);
  68527. const int filter = roundToInt (63.0f / radius);
  68528. const int radiusMinus1 = roundToInt ((radius - 1.0f) * 63.0f);
  68529. for (int x = w; --x >= 0;)
  68530. {
  68531. int shadowAlpha = 0;
  68532. const PixelARGB* src = ((const PixelARGB*) srcData.data) + x;
  68533. uint8* shadowPix = destData.data + x;
  68534. for (int y = h; --y >= 0;)
  68535. {
  68536. shadowAlpha = ((shadowAlpha * radiusMinus1 + (src->getAlpha() << 6)) * filter) >> 12;
  68537. *shadowPix = (uint8) shadowAlpha;
  68538. src = (const PixelARGB*) (((const uint8*) src) + srcData.lineStride);
  68539. shadowPix += destData.lineStride;
  68540. }
  68541. }
  68542. for (int y = h; --y >= 0;)
  68543. {
  68544. int shadowAlpha = 0;
  68545. uint8* shadowPix = destData.getLinePointer (y);
  68546. for (int x = w; --x >= 0;)
  68547. {
  68548. shadowAlpha = ((shadowAlpha * radiusMinus1 + (*shadowPix << 6)) * filter) >> 12;
  68549. *shadowPix++ = (uint8) shadowAlpha;
  68550. }
  68551. }
  68552. g.setColour (Colours::black.withAlpha (opacity));
  68553. g.drawImageAt (&shadowImage, offsetX, offsetY, true);
  68554. g.setOpacity (1.0f);
  68555. g.drawImageAt (&image, 0, 0);
  68556. }
  68557. END_JUCE_NAMESPACE
  68558. /*** End of inlined file: juce_DropShadowEffect.cpp ***/
  68559. /*** Start of inlined file: juce_GlowEffect.cpp ***/
  68560. BEGIN_JUCE_NAMESPACE
  68561. GlowEffect::GlowEffect()
  68562. : radius (2.0f),
  68563. colour (Colours::white)
  68564. {
  68565. }
  68566. GlowEffect::~GlowEffect()
  68567. {
  68568. }
  68569. void GlowEffect::setGlowProperties (const float newRadius,
  68570. const Colour& newColour)
  68571. {
  68572. radius = newRadius;
  68573. colour = newColour;
  68574. }
  68575. void GlowEffect::applyEffect (Image& image, Graphics& g)
  68576. {
  68577. const int w = image.getWidth();
  68578. const int h = image.getHeight();
  68579. Image temp (image.getFormat(), w, h, true);
  68580. ImageConvolutionKernel blurKernel (roundToInt (radius * 2.0f));
  68581. blurKernel.createGaussianBlur (radius);
  68582. blurKernel.rescaleAllValues (radius);
  68583. blurKernel.applyToImage (temp, &image, 0, 0, w, h);
  68584. g.setColour (colour);
  68585. g.drawImageAt (&temp, 0, 0, true);
  68586. g.setOpacity (1.0f);
  68587. g.drawImageAt (&image, 0, 0, false);
  68588. }
  68589. END_JUCE_NAMESPACE
  68590. /*** End of inlined file: juce_GlowEffect.cpp ***/
  68591. /*** Start of inlined file: juce_ReduceOpacityEffect.cpp ***/
  68592. BEGIN_JUCE_NAMESPACE
  68593. ReduceOpacityEffect::ReduceOpacityEffect (const float opacity_)
  68594. : opacity (opacity_)
  68595. {
  68596. }
  68597. ReduceOpacityEffect::~ReduceOpacityEffect()
  68598. {
  68599. }
  68600. void ReduceOpacityEffect::setOpacity (const float newOpacity)
  68601. {
  68602. opacity = jlimit (0.0f, 1.0f, newOpacity);
  68603. }
  68604. void ReduceOpacityEffect::applyEffect (Image& image, Graphics& g)
  68605. {
  68606. g.setOpacity (opacity);
  68607. g.drawImageAt (&image, 0, 0);
  68608. }
  68609. END_JUCE_NAMESPACE
  68610. /*** End of inlined file: juce_ReduceOpacityEffect.cpp ***/
  68611. /*** Start of inlined file: juce_Font.cpp ***/
  68612. BEGIN_JUCE_NAMESPACE
  68613. namespace FontValues
  68614. {
  68615. static float limitFontHeight (const float height) throw()
  68616. {
  68617. return jlimit (0.1f, 10000.0f, height);
  68618. }
  68619. static const float defaultFontHeight = 14.0f;
  68620. }
  68621. Font::SharedFontInternal::SharedFontInternal (const String& typefaceName_, const float height_, const float horizontalScale_,
  68622. const float kerning_, const float ascent_, const int styleFlags_,
  68623. Typeface* const typeface_) throw()
  68624. : typefaceName (typefaceName_),
  68625. height (height_),
  68626. horizontalScale (horizontalScale_),
  68627. kerning (kerning_),
  68628. ascent (ascent_),
  68629. styleFlags (styleFlags_),
  68630. typeface (typeface_)
  68631. {
  68632. }
  68633. Font::SharedFontInternal::SharedFontInternal (const SharedFontInternal& other) throw()
  68634. : typefaceName (other.typefaceName),
  68635. height (other.height),
  68636. horizontalScale (other.horizontalScale),
  68637. kerning (other.kerning),
  68638. ascent (other.ascent),
  68639. styleFlags (other.styleFlags),
  68640. typeface (other.typeface)
  68641. {
  68642. }
  68643. Font::Font() throw()
  68644. : font (new SharedFontInternal (getDefaultSansSerifFontName(), FontValues::defaultFontHeight,
  68645. 1.0f, 0, 0, Font::plain, 0))
  68646. {
  68647. }
  68648. Font::Font (const float fontHeight, const int styleFlags_) throw()
  68649. : font (new SharedFontInternal (getDefaultSansSerifFontName(), FontValues::limitFontHeight (fontHeight),
  68650. 1.0f, 0, 0, styleFlags_, 0))
  68651. {
  68652. }
  68653. Font::Font (const String& typefaceName_,
  68654. const float fontHeight,
  68655. const int styleFlags_) throw()
  68656. : font (new SharedFontInternal (typefaceName_, FontValues::limitFontHeight (fontHeight),
  68657. 1.0f, 0, 0, styleFlags_, 0))
  68658. {
  68659. }
  68660. Font::Font (const Font& other) throw()
  68661. : font (other.font)
  68662. {
  68663. }
  68664. Font& Font::operator= (const Font& other) throw()
  68665. {
  68666. font = other.font;
  68667. return *this;
  68668. }
  68669. Font::~Font() throw()
  68670. {
  68671. }
  68672. Font::Font (const Typeface::Ptr& typeface) throw()
  68673. : font (new SharedFontInternal (typeface->getName(), FontValues::defaultFontHeight,
  68674. 1.0f, 0, 0, Font::plain, typeface))
  68675. {
  68676. }
  68677. bool Font::operator== (const Font& other) const throw()
  68678. {
  68679. return font == other.font
  68680. || (font->height == other.font->height
  68681. && font->styleFlags == other.font->styleFlags
  68682. && font->horizontalScale == other.font->horizontalScale
  68683. && font->kerning == other.font->kerning
  68684. && font->typefaceName == other.font->typefaceName);
  68685. }
  68686. bool Font::operator!= (const Font& other) const throw()
  68687. {
  68688. return ! operator== (other);
  68689. }
  68690. void Font::dupeInternalIfShared() throw()
  68691. {
  68692. if (font->getReferenceCount() > 1)
  68693. font = new SharedFontInternal (*font);
  68694. }
  68695. const String Font::getDefaultSansSerifFontName() throw()
  68696. {
  68697. static const String name ("<Sans-Serif>");
  68698. return name;
  68699. }
  68700. const String Font::getDefaultSerifFontName() throw()
  68701. {
  68702. static const String name ("<Serif>");
  68703. return name;
  68704. }
  68705. const String Font::getDefaultMonospacedFontName() throw()
  68706. {
  68707. static const String name ("<Monospaced>");
  68708. return name;
  68709. }
  68710. void Font::setTypefaceName (const String& faceName) throw()
  68711. {
  68712. if (faceName != font->typefaceName)
  68713. {
  68714. dupeInternalIfShared();
  68715. font->typefaceName = faceName;
  68716. font->typeface = 0;
  68717. font->ascent = 0;
  68718. }
  68719. }
  68720. static String fallbackFont;
  68721. const String Font::getFallbackFontName() throw()
  68722. {
  68723. return fallbackFont;
  68724. }
  68725. void Font::setFallbackFontName (const String& name) throw()
  68726. {
  68727. fallbackFont = name;
  68728. }
  68729. void Font::setHeight (float newHeight) throw()
  68730. {
  68731. newHeight = FontValues::limitFontHeight (newHeight);
  68732. if (font->height != newHeight)
  68733. {
  68734. dupeInternalIfShared();
  68735. font->height = newHeight;
  68736. }
  68737. }
  68738. void Font::setHeightWithoutChangingWidth (float newHeight) throw()
  68739. {
  68740. newHeight = FontValues::limitFontHeight (newHeight);
  68741. if (font->height != newHeight)
  68742. {
  68743. dupeInternalIfShared();
  68744. font->horizontalScale *= (font->height / newHeight);
  68745. font->height = newHeight;
  68746. }
  68747. }
  68748. void Font::setStyleFlags (const int newFlags) throw()
  68749. {
  68750. if (font->styleFlags != newFlags)
  68751. {
  68752. dupeInternalIfShared();
  68753. font->styleFlags = newFlags;
  68754. font->typeface = 0;
  68755. font->ascent = 0;
  68756. }
  68757. }
  68758. void Font::setSizeAndStyle (float newHeight,
  68759. const int newStyleFlags,
  68760. const float newHorizontalScale,
  68761. const float newKerningAmount) throw()
  68762. {
  68763. newHeight = FontValues::limitFontHeight (newHeight);
  68764. if (font->height != newHeight
  68765. || font->horizontalScale != newHorizontalScale
  68766. || font->kerning != newKerningAmount)
  68767. {
  68768. dupeInternalIfShared();
  68769. font->height = newHeight;
  68770. font->horizontalScale = newHorizontalScale;
  68771. font->kerning = newKerningAmount;
  68772. }
  68773. setStyleFlags (newStyleFlags);
  68774. }
  68775. void Font::setHorizontalScale (const float scaleFactor) throw()
  68776. {
  68777. dupeInternalIfShared();
  68778. font->horizontalScale = scaleFactor;
  68779. }
  68780. void Font::setExtraKerningFactor (const float extraKerning) throw()
  68781. {
  68782. dupeInternalIfShared();
  68783. font->kerning = extraKerning;
  68784. }
  68785. void Font::setBold (const bool shouldBeBold) throw()
  68786. {
  68787. setStyleFlags (shouldBeBold ? (font->styleFlags | bold)
  68788. : (font->styleFlags & ~bold));
  68789. }
  68790. bool Font::isBold() const throw()
  68791. {
  68792. return (font->styleFlags & bold) != 0;
  68793. }
  68794. void Font::setItalic (const bool shouldBeItalic) throw()
  68795. {
  68796. setStyleFlags (shouldBeItalic ? (font->styleFlags | italic)
  68797. : (font->styleFlags & ~italic));
  68798. }
  68799. bool Font::isItalic() const throw()
  68800. {
  68801. return (font->styleFlags & italic) != 0;
  68802. }
  68803. void Font::setUnderline (const bool shouldBeUnderlined) throw()
  68804. {
  68805. setStyleFlags (shouldBeUnderlined ? (font->styleFlags | underlined)
  68806. : (font->styleFlags & ~underlined));
  68807. }
  68808. bool Font::isUnderlined() const throw()
  68809. {
  68810. return (font->styleFlags & underlined) != 0;
  68811. }
  68812. float Font::getAscent() const throw()
  68813. {
  68814. if (font->ascent == 0)
  68815. font->ascent = getTypeface()->getAscent();
  68816. return font->height * font->ascent;
  68817. }
  68818. float Font::getDescent() const throw()
  68819. {
  68820. return font->height - getAscent();
  68821. }
  68822. int Font::getStringWidth (const String& text) const throw()
  68823. {
  68824. return roundToInt (getStringWidthFloat (text));
  68825. }
  68826. float Font::getStringWidthFloat (const String& text) const throw()
  68827. {
  68828. float w = getTypeface()->getStringWidth (text);
  68829. if (font->kerning != 0)
  68830. w += font->kerning * text.length();
  68831. return w * font->height * font->horizontalScale;
  68832. }
  68833. void Font::getGlyphPositions (const String& text, Array <int>& glyphs, Array <float>& xOffsets) const throw()
  68834. {
  68835. getTypeface()->getGlyphPositions (text, glyphs, xOffsets);
  68836. const float scale = font->height * font->horizontalScale;
  68837. const int num = xOffsets.size();
  68838. if (num > 0)
  68839. {
  68840. float* const x = &(xOffsets.getReference(0));
  68841. if (font->kerning != 0)
  68842. {
  68843. for (int i = 0; i < num; ++i)
  68844. x[i] = (x[i] + i * font->kerning) * scale;
  68845. }
  68846. else
  68847. {
  68848. for (int i = 0; i < num; ++i)
  68849. x[i] *= scale;
  68850. }
  68851. }
  68852. }
  68853. void Font::findFonts (Array<Font>& destArray) throw()
  68854. {
  68855. const StringArray names (findAllTypefaceNames());
  68856. for (int i = 0; i < names.size(); ++i)
  68857. destArray.add (Font (names[i], FontValues::defaultFontHeight, Font::plain));
  68858. }
  68859. class TypefaceCache : public DeletedAtShutdown
  68860. {
  68861. public:
  68862. TypefaceCache (int numToCache = 10) throw()
  68863. : counter (1)
  68864. {
  68865. while (--numToCache >= 0)
  68866. faces.add (new CachedFace());
  68867. }
  68868. ~TypefaceCache()
  68869. {
  68870. clearSingletonInstance();
  68871. }
  68872. juce_DeclareSingleton_SingleThreaded_Minimal (TypefaceCache)
  68873. const Typeface::Ptr findTypefaceFor (const Font& font) throw()
  68874. {
  68875. const int flags = font.getStyleFlags() & (Font::bold | Font::italic);
  68876. const String faceName (font.getTypefaceName());
  68877. int i;
  68878. for (i = faces.size(); --i >= 0;)
  68879. {
  68880. CachedFace* const face = faces.getUnchecked(i);
  68881. if (face->flags == flags
  68882. && face->typefaceName == faceName)
  68883. {
  68884. face->lastUsageCount = ++counter;
  68885. return face->typeFace;
  68886. }
  68887. }
  68888. int replaceIndex = 0;
  68889. int bestLastUsageCount = std::numeric_limits<int>::max();
  68890. for (i = faces.size(); --i >= 0;)
  68891. {
  68892. const int lu = faces.getUnchecked(i)->lastUsageCount;
  68893. if (bestLastUsageCount > lu)
  68894. {
  68895. bestLastUsageCount = lu;
  68896. replaceIndex = i;
  68897. }
  68898. }
  68899. CachedFace* const face = faces.getUnchecked (replaceIndex);
  68900. face->typefaceName = faceName;
  68901. face->flags = flags;
  68902. face->lastUsageCount = ++counter;
  68903. face->typeFace = LookAndFeel::getDefaultLookAndFeel().getTypefaceForFont (font);
  68904. jassert (face->typeFace != 0); // the look and feel must return a typeface!
  68905. return face->typeFace;
  68906. }
  68907. juce_UseDebuggingNewOperator
  68908. private:
  68909. struct CachedFace
  68910. {
  68911. CachedFace() throw()
  68912. : lastUsageCount (0), flags (-1)
  68913. {
  68914. }
  68915. String typefaceName;
  68916. int lastUsageCount;
  68917. int flags;
  68918. Typeface::Ptr typeFace;
  68919. };
  68920. int counter;
  68921. OwnedArray <CachedFace> faces;
  68922. TypefaceCache (const TypefaceCache&);
  68923. TypefaceCache& operator= (const TypefaceCache&);
  68924. };
  68925. juce_ImplementSingleton_SingleThreaded (TypefaceCache)
  68926. Typeface* Font::getTypeface() const throw()
  68927. {
  68928. if (font->typeface == 0)
  68929. font->typeface = TypefaceCache::getInstance()->findTypefaceFor (*this);
  68930. return font->typeface;
  68931. }
  68932. END_JUCE_NAMESPACE
  68933. /*** End of inlined file: juce_Font.cpp ***/
  68934. /*** Start of inlined file: juce_GlyphArrangement.cpp ***/
  68935. BEGIN_JUCE_NAMESPACE
  68936. PositionedGlyph::PositionedGlyph (const float x_, const float y_, const float w_, const Font& font_,
  68937. const juce_wchar character_, const int glyph_)
  68938. : x (x_),
  68939. y (y_),
  68940. w (w_),
  68941. font (font_),
  68942. character (character_),
  68943. glyph (glyph_)
  68944. {
  68945. }
  68946. PositionedGlyph::PositionedGlyph (const PositionedGlyph& other)
  68947. : x (other.x),
  68948. y (other.y),
  68949. w (other.w),
  68950. font (other.font),
  68951. character (other.character),
  68952. glyph (other.glyph)
  68953. {
  68954. }
  68955. void PositionedGlyph::draw (const Graphics& g) const
  68956. {
  68957. if (! isWhitespace())
  68958. {
  68959. g.getInternalContext()->setFont (font);
  68960. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y));
  68961. }
  68962. }
  68963. void PositionedGlyph::draw (const Graphics& g,
  68964. const AffineTransform& transform) const
  68965. {
  68966. if (! isWhitespace())
  68967. {
  68968. g.getInternalContext()->setFont (font);
  68969. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y)
  68970. .followedBy (transform));
  68971. }
  68972. }
  68973. void PositionedGlyph::createPath (Path& path) const
  68974. {
  68975. if (! isWhitespace())
  68976. {
  68977. Typeface* const t = font.getTypeface();
  68978. if (t != 0)
  68979. {
  68980. Path p;
  68981. t->getOutlineForGlyph (glyph, p);
  68982. path.addPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight())
  68983. .translated (x, y));
  68984. }
  68985. }
  68986. }
  68987. bool PositionedGlyph::hitTest (float px, float py) const
  68988. {
  68989. if (px >= getLeft() && px < getRight()
  68990. && py >= getTop() && py < getBottom()
  68991. && ! isWhitespace())
  68992. {
  68993. Typeface* const t = font.getTypeface();
  68994. if (t != 0)
  68995. {
  68996. Path p;
  68997. t->getOutlineForGlyph (glyph, p);
  68998. AffineTransform::translation (-x, -y)
  68999. .scaled (1.0f / (font.getHeight() * font.getHorizontalScale()), 1.0f / font.getHeight())
  69000. .transformPoint (px, py);
  69001. return p.contains (px, py);
  69002. }
  69003. }
  69004. return false;
  69005. }
  69006. void PositionedGlyph::moveBy (const float deltaX,
  69007. const float deltaY)
  69008. {
  69009. x += deltaX;
  69010. y += deltaY;
  69011. }
  69012. GlyphArrangement::GlyphArrangement()
  69013. {
  69014. glyphs.ensureStorageAllocated (128);
  69015. }
  69016. GlyphArrangement::GlyphArrangement (const GlyphArrangement& other)
  69017. {
  69018. addGlyphArrangement (other);
  69019. }
  69020. GlyphArrangement& GlyphArrangement::operator= (const GlyphArrangement& other)
  69021. {
  69022. if (this != &other)
  69023. {
  69024. clear();
  69025. addGlyphArrangement (other);
  69026. }
  69027. return *this;
  69028. }
  69029. GlyphArrangement::~GlyphArrangement()
  69030. {
  69031. }
  69032. void GlyphArrangement::clear()
  69033. {
  69034. glyphs.clear();
  69035. }
  69036. PositionedGlyph& GlyphArrangement::getGlyph (const int index) const
  69037. {
  69038. jassert (((unsigned int) index) < (unsigned int) glyphs.size());
  69039. return *glyphs [index];
  69040. }
  69041. void GlyphArrangement::addGlyphArrangement (const GlyphArrangement& other)
  69042. {
  69043. glyphs.ensureStorageAllocated (glyphs.size() + other.glyphs.size());
  69044. for (int i = 0; i < other.glyphs.size(); ++i)
  69045. glyphs.add (new PositionedGlyph (*other.glyphs.getUnchecked (i)));
  69046. }
  69047. void GlyphArrangement::removeRangeOfGlyphs (int startIndex, const int num)
  69048. {
  69049. glyphs.removeRange (startIndex, num < 0 ? glyphs.size() : num);
  69050. }
  69051. void GlyphArrangement::addLineOfText (const Font& font,
  69052. const String& text,
  69053. const float xOffset,
  69054. const float yOffset)
  69055. {
  69056. addCurtailedLineOfText (font, text,
  69057. xOffset, yOffset,
  69058. 1.0e10f, false);
  69059. }
  69060. void GlyphArrangement::addCurtailedLineOfText (const Font& font,
  69061. const String& text,
  69062. float xOffset,
  69063. const float yOffset,
  69064. const float maxWidthPixels,
  69065. const bool useEllipsis)
  69066. {
  69067. if (text.isNotEmpty())
  69068. {
  69069. Array <int> newGlyphs;
  69070. Array <float> xOffsets;
  69071. font.getGlyphPositions (text, newGlyphs, xOffsets);
  69072. const int textLen = newGlyphs.size();
  69073. const juce_wchar* const unicodeText = (const juce_wchar*) text;
  69074. for (int i = 0; i < textLen; ++i)
  69075. {
  69076. const float thisX = xOffsets.getUnchecked (i);
  69077. const float nextX = xOffsets.getUnchecked (i + 1);
  69078. if (nextX > maxWidthPixels + 1.0f)
  69079. {
  69080. // curtail the string if it's too wide..
  69081. if (useEllipsis && textLen > 3 && glyphs.size() >= 3)
  69082. insertEllipsis (font, xOffset + maxWidthPixels, 0, glyphs.size());
  69083. break;
  69084. }
  69085. else
  69086. {
  69087. glyphs.add (new PositionedGlyph (xOffset + thisX, yOffset, nextX - thisX,
  69088. font, unicodeText[i], newGlyphs.getUnchecked(i)));
  69089. }
  69090. }
  69091. }
  69092. }
  69093. int GlyphArrangement::insertEllipsis (const Font& font, const float maxXPos,
  69094. const int startIndex, int endIndex)
  69095. {
  69096. int numDeleted = 0;
  69097. if (glyphs.size() > 0)
  69098. {
  69099. Array<int> dotGlyphs;
  69100. Array<float> dotXs;
  69101. font.getGlyphPositions ("..", dotGlyphs, dotXs);
  69102. const float dx = dotXs[1];
  69103. float xOffset = 0.0f, yOffset = 0.0f;
  69104. while (endIndex > startIndex)
  69105. {
  69106. const PositionedGlyph* pg = glyphs.getUnchecked (--endIndex);
  69107. xOffset = pg->x;
  69108. yOffset = pg->y;
  69109. glyphs.remove (endIndex);
  69110. ++numDeleted;
  69111. if (xOffset + dx * 3 <= maxXPos)
  69112. break;
  69113. }
  69114. for (int i = 3; --i >= 0;)
  69115. {
  69116. glyphs.insert (endIndex++, new PositionedGlyph (xOffset, yOffset, dx,
  69117. font, '.', dotGlyphs.getFirst()));
  69118. --numDeleted;
  69119. xOffset += dx;
  69120. if (xOffset > maxXPos)
  69121. break;
  69122. }
  69123. }
  69124. return numDeleted;
  69125. }
  69126. void GlyphArrangement::addJustifiedText (const Font& font,
  69127. const String& text,
  69128. float x, float y,
  69129. const float maxLineWidth,
  69130. const Justification& horizontalLayout)
  69131. {
  69132. int lineStartIndex = glyphs.size();
  69133. addLineOfText (font, text, x, y);
  69134. const float originalY = y;
  69135. while (lineStartIndex < glyphs.size())
  69136. {
  69137. int i = lineStartIndex;
  69138. if (glyphs.getUnchecked(i)->getCharacter() != '\n'
  69139. && glyphs.getUnchecked(i)->getCharacter() != '\r')
  69140. ++i;
  69141. const float lineMaxX = glyphs.getUnchecked (lineStartIndex)->getLeft() + maxLineWidth;
  69142. int lastWordBreakIndex = -1;
  69143. while (i < glyphs.size())
  69144. {
  69145. const PositionedGlyph* pg = glyphs.getUnchecked (i);
  69146. const juce_wchar c = pg->getCharacter();
  69147. if (c == '\r' || c == '\n')
  69148. {
  69149. ++i;
  69150. if (c == '\r' && i < glyphs.size()
  69151. && glyphs.getUnchecked(i)->getCharacter() == '\n')
  69152. ++i;
  69153. break;
  69154. }
  69155. else if (pg->isWhitespace())
  69156. {
  69157. lastWordBreakIndex = i + 1;
  69158. }
  69159. else if (pg->getRight() - 0.0001f >= lineMaxX)
  69160. {
  69161. if (lastWordBreakIndex >= 0)
  69162. i = lastWordBreakIndex;
  69163. break;
  69164. }
  69165. ++i;
  69166. }
  69167. const float currentLineStartX = glyphs.getUnchecked (lineStartIndex)->getLeft();
  69168. float currentLineEndX = currentLineStartX;
  69169. for (int j = i; --j >= lineStartIndex;)
  69170. {
  69171. if (! glyphs.getUnchecked (j)->isWhitespace())
  69172. {
  69173. currentLineEndX = glyphs.getUnchecked (j)->getRight();
  69174. break;
  69175. }
  69176. }
  69177. float deltaX = 0.0f;
  69178. if (horizontalLayout.testFlags (Justification::horizontallyJustified))
  69179. spreadOutLine (lineStartIndex, i - lineStartIndex, maxLineWidth);
  69180. else if (horizontalLayout.testFlags (Justification::horizontallyCentred))
  69181. deltaX = (maxLineWidth - (currentLineEndX - currentLineStartX)) * 0.5f;
  69182. else if (horizontalLayout.testFlags (Justification::right))
  69183. deltaX = maxLineWidth - (currentLineEndX - currentLineStartX);
  69184. moveRangeOfGlyphs (lineStartIndex, i - lineStartIndex,
  69185. x + deltaX - currentLineStartX, y - originalY);
  69186. lineStartIndex = i;
  69187. y += font.getHeight();
  69188. }
  69189. }
  69190. void GlyphArrangement::addFittedText (const Font& f,
  69191. const String& text,
  69192. const float x, const float y,
  69193. const float width, const float height,
  69194. const Justification& layout,
  69195. int maximumLines,
  69196. const float minimumHorizontalScale)
  69197. {
  69198. // doesn't make much sense if this is outside a sensible range of 0.5 to 1.0
  69199. jassert (minimumHorizontalScale > 0 && minimumHorizontalScale <= 1.0f);
  69200. if (text.containsAnyOf (T("\r\n")))
  69201. {
  69202. GlyphArrangement ga;
  69203. ga.addJustifiedText (f, text, x, y, width, layout);
  69204. float l, t, r, b;
  69205. ga.getBoundingBox (0, -1, l, t, r, b, false);
  69206. float dy = y - t;
  69207. if (layout.testFlags (Justification::verticallyCentred))
  69208. dy += (height - (b - t)) * 0.5f;
  69209. else if (layout.testFlags (Justification::bottom))
  69210. dy += height - (b - t);
  69211. ga.moveRangeOfGlyphs (0, -1, 0.0f, dy);
  69212. glyphs.ensureStorageAllocated (glyphs.size() + ga.glyphs.size());
  69213. for (int i = 0; i < ga.glyphs.size(); ++i)
  69214. glyphs.add (ga.glyphs.getUnchecked (i));
  69215. ga.glyphs.clear (false);
  69216. return;
  69217. }
  69218. int startIndex = glyphs.size();
  69219. addLineOfText (f, text.trim(), x, y);
  69220. if (glyphs.size() > startIndex)
  69221. {
  69222. float lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69223. - glyphs.getUnchecked (startIndex)->getLeft();
  69224. if (lineWidth <= 0)
  69225. return;
  69226. if (lineWidth * minimumHorizontalScale < width)
  69227. {
  69228. if (lineWidth > width)
  69229. stretchRangeOfGlyphs (startIndex, glyphs.size() - startIndex,
  69230. width / lineWidth);
  69231. justifyGlyphs (startIndex, glyphs.size() - startIndex,
  69232. x, y, width, height, layout);
  69233. }
  69234. else if (maximumLines <= 1)
  69235. {
  69236. fitLineIntoSpace (startIndex, glyphs.size() - startIndex,
  69237. x, y, width, height, f, layout, minimumHorizontalScale);
  69238. }
  69239. else
  69240. {
  69241. Font font (f);
  69242. String txt (text.trim());
  69243. const int length = txt.length();
  69244. const int originalStartIndex = startIndex;
  69245. int numLines = 1;
  69246. if (length <= 12 && ! txt.containsAnyOf (T(" -\t\r\n")))
  69247. maximumLines = 1;
  69248. maximumLines = jmin (maximumLines, length);
  69249. while (numLines < maximumLines)
  69250. {
  69251. ++numLines;
  69252. const float newFontHeight = height / (float) numLines;
  69253. if (newFontHeight < font.getHeight())
  69254. {
  69255. font.setHeight (jmax (8.0f, newFontHeight));
  69256. removeRangeOfGlyphs (startIndex, -1);
  69257. addLineOfText (font, txt, x, y);
  69258. lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69259. - glyphs.getUnchecked (startIndex)->getLeft();
  69260. }
  69261. if (numLines > lineWidth / width || newFontHeight < 8.0f)
  69262. break;
  69263. }
  69264. if (numLines < 1)
  69265. numLines = 1;
  69266. float lineY = y;
  69267. float widthPerLine = lineWidth / numLines;
  69268. int lastLineStartIndex = 0;
  69269. for (int line = 0; line < numLines; ++line)
  69270. {
  69271. int i = startIndex;
  69272. lastLineStartIndex = i;
  69273. float lineStartX = glyphs.getUnchecked (startIndex)->getLeft();
  69274. if (line == numLines - 1)
  69275. {
  69276. widthPerLine = width;
  69277. i = glyphs.size();
  69278. }
  69279. else
  69280. {
  69281. while (i < glyphs.size())
  69282. {
  69283. lineWidth = (glyphs.getUnchecked (i)->getRight() - lineStartX);
  69284. if (lineWidth > widthPerLine)
  69285. {
  69286. // got to a point where the line's too long, so skip forward to find a
  69287. // good place to break it..
  69288. const int searchStartIndex = i;
  69289. while (i < glyphs.size())
  69290. {
  69291. if ((glyphs.getUnchecked (i)->getRight() - lineStartX) * minimumHorizontalScale < width)
  69292. {
  69293. if (glyphs.getUnchecked (i)->isWhitespace()
  69294. || glyphs.getUnchecked (i)->getCharacter() == '-')
  69295. {
  69296. ++i;
  69297. break;
  69298. }
  69299. }
  69300. else
  69301. {
  69302. // can't find a suitable break, so try looking backwards..
  69303. i = searchStartIndex;
  69304. for (int back = 1; back < jmin (5, i - startIndex - 1); ++back)
  69305. {
  69306. if (glyphs.getUnchecked (i - back)->isWhitespace()
  69307. || glyphs.getUnchecked (i - back)->getCharacter() == '-')
  69308. {
  69309. i -= back - 1;
  69310. break;
  69311. }
  69312. }
  69313. break;
  69314. }
  69315. ++i;
  69316. }
  69317. break;
  69318. }
  69319. ++i;
  69320. }
  69321. int wsStart = i;
  69322. while (wsStart > 0 && glyphs.getUnchecked (wsStart - 1)->isWhitespace())
  69323. --wsStart;
  69324. int wsEnd = i;
  69325. while (wsEnd < glyphs.size() && glyphs.getUnchecked (wsEnd)->isWhitespace())
  69326. ++wsEnd;
  69327. removeRangeOfGlyphs (wsStart, wsEnd - wsStart);
  69328. i = jmax (wsStart, startIndex + 1);
  69329. }
  69330. i -= fitLineIntoSpace (startIndex, i - startIndex,
  69331. x, lineY, width, font.getHeight(), font,
  69332. layout.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  69333. minimumHorizontalScale);
  69334. startIndex = i;
  69335. lineY += font.getHeight();
  69336. if (startIndex >= glyphs.size())
  69337. break;
  69338. }
  69339. justifyGlyphs (originalStartIndex, glyphs.size() - originalStartIndex,
  69340. x, y, width, height, layout.getFlags() & ~Justification::horizontallyJustified);
  69341. }
  69342. }
  69343. }
  69344. void GlyphArrangement::moveRangeOfGlyphs (int startIndex, int num,
  69345. const float dx, const float dy)
  69346. {
  69347. jassert (startIndex >= 0);
  69348. if (dx != 0.0f || dy != 0.0f)
  69349. {
  69350. if (num < 0 || startIndex + num > glyphs.size())
  69351. num = glyphs.size() - startIndex;
  69352. while (--num >= 0)
  69353. glyphs.getUnchecked (startIndex++)->moveBy (dx, dy);
  69354. }
  69355. }
  69356. int GlyphArrangement::fitLineIntoSpace (int start, int numGlyphs, float x, float y, float w, float h, const Font& font,
  69357. const Justification& justification, float minimumHorizontalScale)
  69358. {
  69359. int numDeleted = 0;
  69360. const float lineStartX = glyphs.getUnchecked (start)->getLeft();
  69361. float lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX;
  69362. if (lineWidth > w)
  69363. {
  69364. if (minimumHorizontalScale < 1.0f)
  69365. {
  69366. stretchRangeOfGlyphs (start, numGlyphs, jmax (minimumHorizontalScale, w / lineWidth));
  69367. lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX - 0.5f;
  69368. }
  69369. if (lineWidth > w)
  69370. {
  69371. numDeleted = insertEllipsis (font, lineStartX + w, start, start + numGlyphs);
  69372. numGlyphs -= numDeleted;
  69373. }
  69374. }
  69375. justifyGlyphs (start, numGlyphs, x, y, w, h, justification);
  69376. return numDeleted;
  69377. }
  69378. void GlyphArrangement::stretchRangeOfGlyphs (int startIndex, int num,
  69379. const float horizontalScaleFactor)
  69380. {
  69381. jassert (startIndex >= 0);
  69382. if (num < 0 || startIndex + num > glyphs.size())
  69383. num = glyphs.size() - startIndex;
  69384. if (num > 0)
  69385. {
  69386. const float xAnchor = glyphs.getUnchecked (startIndex)->getLeft();
  69387. while (--num >= 0)
  69388. {
  69389. PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69390. pg->x = xAnchor + (pg->x - xAnchor) * horizontalScaleFactor;
  69391. pg->font.setHorizontalScale (pg->font.getHorizontalScale() * horizontalScaleFactor);
  69392. pg->w *= horizontalScaleFactor;
  69393. }
  69394. }
  69395. }
  69396. void GlyphArrangement::getBoundingBox (int startIndex, int num,
  69397. float& left,
  69398. float& top,
  69399. float& right,
  69400. float& bottom,
  69401. const bool includeWhitespace) const
  69402. {
  69403. jassert (startIndex >= 0);
  69404. if (num < 0 || startIndex + num > glyphs.size())
  69405. num = glyphs.size() - startIndex;
  69406. left = 0.0f;
  69407. top = 0.0f;
  69408. right = 0.0f;
  69409. bottom = 0.0f;
  69410. bool isFirst = true;
  69411. while (--num >= 0)
  69412. {
  69413. const PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69414. if (includeWhitespace || ! pg->isWhitespace())
  69415. {
  69416. if (isFirst)
  69417. {
  69418. isFirst = false;
  69419. left = pg->getLeft();
  69420. top = pg->getTop();
  69421. right = pg->getRight();
  69422. bottom = pg->getBottom();
  69423. }
  69424. else
  69425. {
  69426. left = jmin (left, pg->getLeft());
  69427. top = jmin (top, pg->getTop());
  69428. right = jmax (right, pg->getRight());
  69429. bottom = jmax (bottom, pg->getBottom());
  69430. }
  69431. }
  69432. }
  69433. }
  69434. void GlyphArrangement::justifyGlyphs (const int startIndex,
  69435. const int num,
  69436. const float x, const float y,
  69437. const float width, const float height,
  69438. const Justification& justification)
  69439. {
  69440. jassert (num >= 0 && startIndex >= 0);
  69441. if (glyphs.size() > 0 && num > 0)
  69442. {
  69443. float left, top, right, bottom;
  69444. getBoundingBox (startIndex, num, left, top, right, bottom,
  69445. ! justification.testFlags (Justification::horizontallyJustified
  69446. | Justification::horizontallyCentred));
  69447. float deltaX = 0.0f;
  69448. if (justification.testFlags (Justification::horizontallyJustified))
  69449. deltaX = x - left;
  69450. else if (justification.testFlags (Justification::horizontallyCentred))
  69451. deltaX = x + (width - (right - left)) * 0.5f - left;
  69452. else if (justification.testFlags (Justification::right))
  69453. deltaX = (x + width) - right;
  69454. else
  69455. deltaX = x - left;
  69456. float deltaY = 0.0f;
  69457. if (justification.testFlags (Justification::top))
  69458. deltaY = y - top;
  69459. else if (justification.testFlags (Justification::bottom))
  69460. deltaY = (y + height) - bottom;
  69461. else
  69462. deltaY = y + (height - (bottom - top)) * 0.5f - top;
  69463. moveRangeOfGlyphs (startIndex, num, deltaX, deltaY);
  69464. if (justification.testFlags (Justification::horizontallyJustified))
  69465. {
  69466. int lineStart = 0;
  69467. float baseY = glyphs.getUnchecked (startIndex)->getBaselineY();
  69468. int i;
  69469. for (i = 0; i < num; ++i)
  69470. {
  69471. const float glyphY = glyphs.getUnchecked (startIndex + i)->getBaselineY();
  69472. if (glyphY != baseY)
  69473. {
  69474. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69475. lineStart = i;
  69476. baseY = glyphY;
  69477. }
  69478. }
  69479. if (i > lineStart)
  69480. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69481. }
  69482. }
  69483. }
  69484. void GlyphArrangement::spreadOutLine (const int start, const int num, const float targetWidth)
  69485. {
  69486. if (start + num < glyphs.size()
  69487. && glyphs.getUnchecked (start + num - 1)->getCharacter() != '\r'
  69488. && glyphs.getUnchecked (start + num - 1)->getCharacter() != '\n')
  69489. {
  69490. int numSpaces = 0;
  69491. int spacesAtEnd = 0;
  69492. for (int i = 0; i < num; ++i)
  69493. {
  69494. if (glyphs.getUnchecked (start + i)->isWhitespace())
  69495. {
  69496. ++spacesAtEnd;
  69497. ++numSpaces;
  69498. }
  69499. else
  69500. {
  69501. spacesAtEnd = 0;
  69502. }
  69503. }
  69504. numSpaces -= spacesAtEnd;
  69505. if (numSpaces > 0)
  69506. {
  69507. const float startX = glyphs.getUnchecked (start)->getLeft();
  69508. const float endX = glyphs.getUnchecked (start + num - 1 - spacesAtEnd)->getRight();
  69509. const float extraPaddingBetweenWords
  69510. = (targetWidth - (endX - startX)) / (float) numSpaces;
  69511. float deltaX = 0.0f;
  69512. for (int i = 0; i < num; ++i)
  69513. {
  69514. glyphs.getUnchecked (start + i)->moveBy (deltaX, 0.0f);
  69515. if (glyphs.getUnchecked (start + i)->isWhitespace())
  69516. deltaX += extraPaddingBetweenWords;
  69517. }
  69518. }
  69519. }
  69520. }
  69521. void GlyphArrangement::draw (const Graphics& g) const
  69522. {
  69523. for (int i = 0; i < glyphs.size(); ++i)
  69524. {
  69525. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  69526. if (pg->font.isUnderlined())
  69527. {
  69528. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  69529. float nextX = pg->x + pg->w;
  69530. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  69531. nextX = glyphs.getUnchecked (i + 1)->x;
  69532. g.fillRect (pg->x, pg->y + lineThickness * 2.0f,
  69533. nextX - pg->x, lineThickness);
  69534. }
  69535. pg->draw (g);
  69536. }
  69537. }
  69538. void GlyphArrangement::draw (const Graphics& g, const AffineTransform& transform) const
  69539. {
  69540. for (int i = 0; i < glyphs.size(); ++i)
  69541. {
  69542. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  69543. if (pg->font.isUnderlined())
  69544. {
  69545. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  69546. float nextX = pg->x + pg->w;
  69547. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  69548. nextX = glyphs.getUnchecked (i + 1)->x;
  69549. Path p;
  69550. p.addLineSegment (pg->x, pg->y + lineThickness * 2.0f,
  69551. nextX, pg->y + lineThickness * 2.0f,
  69552. lineThickness);
  69553. g.fillPath (p, transform);
  69554. }
  69555. pg->draw (g, transform);
  69556. }
  69557. }
  69558. void GlyphArrangement::createPath (Path& path) const
  69559. {
  69560. for (int i = 0; i < glyphs.size(); ++i)
  69561. glyphs.getUnchecked (i)->createPath (path);
  69562. }
  69563. int GlyphArrangement::findGlyphIndexAt (float x, float y) const
  69564. {
  69565. for (int i = 0; i < glyphs.size(); ++i)
  69566. if (glyphs.getUnchecked (i)->hitTest (x, y))
  69567. return i;
  69568. return -1;
  69569. }
  69570. END_JUCE_NAMESPACE
  69571. /*** End of inlined file: juce_GlyphArrangement.cpp ***/
  69572. /*** Start of inlined file: juce_TextLayout.cpp ***/
  69573. BEGIN_JUCE_NAMESPACE
  69574. class TextLayout::Token
  69575. {
  69576. public:
  69577. String text;
  69578. Font font;
  69579. int x, y, w, h;
  69580. int line, lineHeight;
  69581. bool isWhitespace, isNewLine;
  69582. Token (const String& t,
  69583. const Font& f,
  69584. const bool isWhitespace_) throw()
  69585. : text (t),
  69586. font (f),
  69587. x(0),
  69588. y(0),
  69589. isWhitespace (isWhitespace_)
  69590. {
  69591. w = font.getStringWidth (t);
  69592. h = roundToInt (f.getHeight());
  69593. isNewLine = t.containsAnyOf (T("\r\n"));
  69594. }
  69595. Token (const Token& other) throw()
  69596. : text (other.text),
  69597. font (other.font),
  69598. x (other.x),
  69599. y (other.y),
  69600. w (other.w),
  69601. h (other.h),
  69602. line (other.line),
  69603. lineHeight (other.lineHeight),
  69604. isWhitespace (other.isWhitespace),
  69605. isNewLine (other.isNewLine)
  69606. {
  69607. }
  69608. ~Token() throw()
  69609. {
  69610. }
  69611. void draw (Graphics& g,
  69612. const int xOffset,
  69613. const int yOffset) throw()
  69614. {
  69615. if (! isWhitespace)
  69616. {
  69617. g.setFont (font);
  69618. g.drawSingleLineText (text.trimEnd(),
  69619. xOffset + x,
  69620. yOffset + y + (lineHeight - h)
  69621. + roundToInt (font.getAscent()));
  69622. }
  69623. }
  69624. juce_UseDebuggingNewOperator
  69625. };
  69626. TextLayout::TextLayout() throw()
  69627. : totalLines (0)
  69628. {
  69629. tokens.ensureStorageAllocated (64);
  69630. }
  69631. TextLayout::TextLayout (const String& text,
  69632. const Font& font) throw()
  69633. : totalLines (0)
  69634. {
  69635. tokens.ensureStorageAllocated (64);
  69636. appendText (text, font);
  69637. }
  69638. TextLayout::TextLayout (const TextLayout& other) throw()
  69639. : totalLines (0)
  69640. {
  69641. *this = other;
  69642. }
  69643. TextLayout& TextLayout::operator= (const TextLayout& other) throw()
  69644. {
  69645. if (this != &other)
  69646. {
  69647. clear();
  69648. totalLines = other.totalLines;
  69649. for (int i = 0; i < other.tokens.size(); ++i)
  69650. tokens.add (new Token (*other.tokens.getUnchecked(i)));
  69651. }
  69652. return *this;
  69653. }
  69654. TextLayout::~TextLayout() throw()
  69655. {
  69656. clear();
  69657. }
  69658. void TextLayout::clear() throw()
  69659. {
  69660. tokens.clear();
  69661. totalLines = 0;
  69662. }
  69663. void TextLayout::appendText (const String& text,
  69664. const Font& font) throw()
  69665. {
  69666. const tchar* t = text;
  69667. String currentString;
  69668. int lastCharType = 0;
  69669. for (;;)
  69670. {
  69671. const tchar c = *t++;
  69672. if (c == 0)
  69673. break;
  69674. int charType;
  69675. if (c == '\r' || c == '\n')
  69676. {
  69677. charType = 0;
  69678. }
  69679. else if (CharacterFunctions::isWhitespace (c))
  69680. {
  69681. charType = 2;
  69682. }
  69683. else
  69684. {
  69685. charType = 1;
  69686. }
  69687. if (charType == 0 || charType != lastCharType)
  69688. {
  69689. if (currentString.isNotEmpty())
  69690. {
  69691. tokens.add (new Token (currentString, font,
  69692. lastCharType == 2 || lastCharType == 0));
  69693. }
  69694. currentString = String::charToString (c);
  69695. if (c == '\r' && *t == '\n')
  69696. currentString += *t++;
  69697. }
  69698. else
  69699. {
  69700. currentString += c;
  69701. }
  69702. lastCharType = charType;
  69703. }
  69704. if (currentString.isNotEmpty())
  69705. tokens.add (new Token (currentString, font, lastCharType == 2));
  69706. }
  69707. void TextLayout::setText (const String& text, const Font& font) throw()
  69708. {
  69709. clear();
  69710. appendText (text, font);
  69711. }
  69712. void TextLayout::layout (int maxWidth,
  69713. const Justification& justification,
  69714. const bool attemptToBalanceLineLengths) throw()
  69715. {
  69716. if (attemptToBalanceLineLengths)
  69717. {
  69718. const int originalW = maxWidth;
  69719. int bestWidth = maxWidth;
  69720. float bestLineProportion = 0.0f;
  69721. while (maxWidth > originalW / 2)
  69722. {
  69723. layout (maxWidth, justification, false);
  69724. if (getNumLines() <= 1)
  69725. return;
  69726. const int lastLineW = getLineWidth (getNumLines() - 1);
  69727. const int lastButOneLineW = getLineWidth (getNumLines() - 2);
  69728. const float prop = lastLineW / (float) lastButOneLineW;
  69729. if (prop > 0.9f)
  69730. return;
  69731. if (prop > bestLineProportion)
  69732. {
  69733. bestLineProportion = prop;
  69734. bestWidth = maxWidth;
  69735. }
  69736. maxWidth -= 10;
  69737. }
  69738. layout (bestWidth, justification, false);
  69739. }
  69740. else
  69741. {
  69742. int x = 0;
  69743. int y = 0;
  69744. int h = 0;
  69745. totalLines = 0;
  69746. int i;
  69747. for (i = 0; i < tokens.size(); ++i)
  69748. {
  69749. Token* const t = tokens.getUnchecked(i);
  69750. t->x = x;
  69751. t->y = y;
  69752. t->line = totalLines;
  69753. x += t->w;
  69754. h = jmax (h, t->h);
  69755. const Token* nextTok = tokens [i + 1];
  69756. if (nextTok == 0)
  69757. break;
  69758. if (t->isNewLine || ((! nextTok->isWhitespace) && x + nextTok->w > maxWidth))
  69759. {
  69760. // finished a line, so go back and update the heights of the things on it
  69761. for (int j = i; j >= 0; --j)
  69762. {
  69763. Token* const tok = tokens.getUnchecked(j);
  69764. if (tok->line == totalLines)
  69765. tok->lineHeight = h;
  69766. else
  69767. break;
  69768. }
  69769. x = 0;
  69770. y += h;
  69771. h = 0;
  69772. ++totalLines;
  69773. }
  69774. }
  69775. // finished a line, so go back and update the heights of the things on it
  69776. for (int j = jmin (i, tokens.size() - 1); j >= 0; --j)
  69777. {
  69778. Token* const t = tokens.getUnchecked(j);
  69779. if (t->line == totalLines)
  69780. t->lineHeight = h;
  69781. else
  69782. break;
  69783. }
  69784. ++totalLines;
  69785. if (! justification.testFlags (Justification::left))
  69786. {
  69787. int totalW = getWidth();
  69788. for (i = totalLines; --i >= 0;)
  69789. {
  69790. const int lineW = getLineWidth (i);
  69791. int dx = 0;
  69792. if (justification.testFlags (Justification::horizontallyCentred))
  69793. dx = (totalW - lineW) / 2;
  69794. else if (justification.testFlags (Justification::right))
  69795. dx = totalW - lineW;
  69796. for (int j = tokens.size(); --j >= 0;)
  69797. {
  69798. Token* const t = tokens.getUnchecked(j);
  69799. if (t->line == i)
  69800. t->x += dx;
  69801. }
  69802. }
  69803. }
  69804. }
  69805. }
  69806. int TextLayout::getLineWidth (const int lineNumber) const throw()
  69807. {
  69808. int maxW = 0;
  69809. for (int i = tokens.size(); --i >= 0;)
  69810. {
  69811. const Token* const t = tokens.getUnchecked(i);
  69812. if (t->line == lineNumber && ! t->isWhitespace)
  69813. maxW = jmax (maxW, t->x + t->w);
  69814. }
  69815. return maxW;
  69816. }
  69817. int TextLayout::getWidth() const throw()
  69818. {
  69819. int maxW = 0;
  69820. for (int i = tokens.size(); --i >= 0;)
  69821. {
  69822. const Token* const t = tokens.getUnchecked(i);
  69823. if (! t->isWhitespace)
  69824. maxW = jmax (maxW, t->x + t->w);
  69825. }
  69826. return maxW;
  69827. }
  69828. int TextLayout::getHeight() const throw()
  69829. {
  69830. int maxH = 0;
  69831. for (int i = tokens.size(); --i >= 0;)
  69832. {
  69833. const Token* const t = tokens.getUnchecked(i);
  69834. if (! t->isWhitespace)
  69835. maxH = jmax (maxH, t->y + t->h);
  69836. }
  69837. return maxH;
  69838. }
  69839. void TextLayout::draw (Graphics& g,
  69840. const int xOffset,
  69841. const int yOffset) const throw()
  69842. {
  69843. for (int i = tokens.size(); --i >= 0;)
  69844. tokens.getUnchecked(i)->draw (g, xOffset, yOffset);
  69845. }
  69846. void TextLayout::drawWithin (Graphics& g,
  69847. int x, int y, int w, int h,
  69848. const Justification& justification) const throw()
  69849. {
  69850. justification.applyToRectangle (x, y, getWidth(), getHeight(),
  69851. x, y, w, h);
  69852. draw (g, x, y);
  69853. }
  69854. END_JUCE_NAMESPACE
  69855. /*** End of inlined file: juce_TextLayout.cpp ***/
  69856. /*** Start of inlined file: juce_Typeface.cpp ***/
  69857. BEGIN_JUCE_NAMESPACE
  69858. Typeface::Typeface (const String& name_) throw()
  69859. : name (name_)
  69860. {
  69861. }
  69862. Typeface::~Typeface()
  69863. {
  69864. }
  69865. class CustomTypeface::GlyphInfo
  69866. {
  69867. public:
  69868. GlyphInfo (const juce_wchar character_, const Path& path_, const float width_) throw()
  69869. : character (character_), path (path_), width (width_)
  69870. {
  69871. }
  69872. ~GlyphInfo() throw()
  69873. {
  69874. }
  69875. struct KerningPair
  69876. {
  69877. juce_wchar character2;
  69878. float kerningAmount;
  69879. };
  69880. void addKerningPair (const juce_wchar subsequentCharacter,
  69881. const float extraKerningAmount) throw()
  69882. {
  69883. KerningPair kp;
  69884. kp.character2 = subsequentCharacter;
  69885. kp.kerningAmount = extraKerningAmount;
  69886. kerningPairs.add (kp);
  69887. }
  69888. float getHorizontalSpacing (const juce_wchar subsequentCharacter) const throw()
  69889. {
  69890. if (subsequentCharacter != 0)
  69891. {
  69892. for (int i = kerningPairs.size(); --i >= 0;)
  69893. if (kerningPairs.getReference(i).character2 == subsequentCharacter)
  69894. return width + kerningPairs.getReference(i).kerningAmount;
  69895. }
  69896. return width;
  69897. }
  69898. const juce_wchar character;
  69899. const Path path;
  69900. float width;
  69901. Array <KerningPair> kerningPairs;
  69902. juce_UseDebuggingNewOperator
  69903. private:
  69904. GlyphInfo (const GlyphInfo&);
  69905. GlyphInfo& operator= (const GlyphInfo&);
  69906. };
  69907. CustomTypeface::CustomTypeface()
  69908. : Typeface (String::empty)
  69909. {
  69910. clear();
  69911. }
  69912. CustomTypeface::CustomTypeface (InputStream& serialisedTypefaceStream)
  69913. : Typeface (String::empty)
  69914. {
  69915. clear();
  69916. GZIPDecompressorInputStream gzin (&serialisedTypefaceStream, false);
  69917. BufferedInputStream in (&gzin, 32768, false);
  69918. name = in.readString();
  69919. isBold = in.readBool();
  69920. isItalic = in.readBool();
  69921. ascent = in.readFloat();
  69922. defaultCharacter = (juce_wchar) in.readShort();
  69923. int i, numChars = in.readInt();
  69924. for (i = 0; i < numChars; ++i)
  69925. {
  69926. const juce_wchar c = (juce_wchar) in.readShort();
  69927. const float width = in.readFloat();
  69928. Path p;
  69929. p.loadPathFromStream (in);
  69930. addGlyph (c, p, width);
  69931. }
  69932. const int numKerningPairs = in.readInt();
  69933. for (i = 0; i < numKerningPairs; ++i)
  69934. {
  69935. const juce_wchar char1 = (juce_wchar) in.readShort();
  69936. const juce_wchar char2 = (juce_wchar) in.readShort();
  69937. addKerningPair (char1, char2, in.readFloat());
  69938. }
  69939. }
  69940. CustomTypeface::~CustomTypeface()
  69941. {
  69942. }
  69943. void CustomTypeface::clear()
  69944. {
  69945. defaultCharacter = 0;
  69946. ascent = 1.0f;
  69947. isBold = isItalic = false;
  69948. zeromem (lookupTable, sizeof (lookupTable));
  69949. glyphs.clear();
  69950. }
  69951. void CustomTypeface::setCharacteristics (const String& name_, const float ascent_, const bool isBold_,
  69952. const bool isItalic_, const juce_wchar defaultCharacter_) throw()
  69953. {
  69954. name = name_;
  69955. defaultCharacter = defaultCharacter_;
  69956. ascent = ascent_;
  69957. isBold = isBold_;
  69958. isItalic = isItalic_;
  69959. }
  69960. void CustomTypeface::addGlyph (const juce_wchar character, const Path& path, const float width) throw()
  69961. {
  69962. // Check that you're not trying to add the same character twice..
  69963. jassert (findGlyph (character, false) == 0);
  69964. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable))
  69965. lookupTable [character] = (short) glyphs.size();
  69966. glyphs.add (new GlyphInfo (character, path, width));
  69967. }
  69968. void CustomTypeface::addKerningPair (const juce_wchar char1, const juce_wchar char2, const float extraAmount) throw()
  69969. {
  69970. if (extraAmount != 0)
  69971. {
  69972. GlyphInfo* const g = findGlyph (char1, true);
  69973. jassert (g != 0); // can only add kerning pairs for characters that exist!
  69974. if (g != 0)
  69975. g->addKerningPair (char2, extraAmount);
  69976. }
  69977. }
  69978. CustomTypeface::GlyphInfo* CustomTypeface::findGlyph (const juce_wchar character, const bool loadIfNeeded) throw()
  69979. {
  69980. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable) && lookupTable [character] > 0)
  69981. return glyphs [(int) lookupTable [(int) character]];
  69982. for (int i = 0; i < glyphs.size(); ++i)
  69983. {
  69984. GlyphInfo* const g = glyphs.getUnchecked(i);
  69985. if (g->character == character)
  69986. return g;
  69987. }
  69988. if (loadIfNeeded && loadGlyphIfPossible (character))
  69989. return findGlyph (character, false);
  69990. return 0;
  69991. }
  69992. CustomTypeface::GlyphInfo* CustomTypeface::findGlyphSubstituting (const juce_wchar character) throw()
  69993. {
  69994. GlyphInfo* glyph = findGlyph (character, true);
  69995. if (glyph == 0)
  69996. {
  69997. if (CharacterFunctions::isWhitespace (character) && character != L' ')
  69998. glyph = findGlyph (L' ', true);
  69999. if (glyph == 0)
  70000. {
  70001. const Font fallbackFont (Font::getFallbackFontName(), 10, 0);
  70002. Typeface* const fallbackTypeface = fallbackFont.getTypeface();
  70003. if (fallbackTypeface != 0 && fallbackTypeface != this)
  70004. {
  70005. //xxx
  70006. }
  70007. if (glyph == 0)
  70008. glyph = findGlyph (defaultCharacter, true);
  70009. }
  70010. }
  70011. return glyph;
  70012. }
  70013. bool CustomTypeface::loadGlyphIfPossible (const juce_wchar /*characterNeeded*/)
  70014. {
  70015. return false;
  70016. }
  70017. void CustomTypeface::addGlyphsFromOtherTypeface (Typeface& typefaceToCopy, juce_wchar characterStartIndex, int numCharacters) throw()
  70018. {
  70019. for (int i = 0; i < numCharacters; ++i)
  70020. {
  70021. const juce_wchar c = (juce_wchar) (characterStartIndex + i);
  70022. Array <int> glyphIndexes;
  70023. Array <float> offsets;
  70024. typefaceToCopy.getGlyphPositions (String::charToString (c), glyphIndexes, offsets);
  70025. const int glyphIndex = glyphIndexes.getFirst();
  70026. if (glyphIndex >= 0 && glyphIndexes.size() > 0)
  70027. {
  70028. const float glyphWidth = offsets[1];
  70029. Path p;
  70030. typefaceToCopy.getOutlineForGlyph (glyphIndex, p);
  70031. addGlyph (c, p, glyphWidth);
  70032. for (int j = glyphs.size() - 1; --j >= 0;)
  70033. {
  70034. const juce_wchar char2 = glyphs.getUnchecked (j)->character;
  70035. glyphIndexes.clearQuick();
  70036. offsets.clearQuick();
  70037. typefaceToCopy.getGlyphPositions (String::charToString (c) + String::charToString (char2), glyphIndexes, offsets);
  70038. if (offsets.size() > 1)
  70039. addKerningPair (c, char2, offsets[1] - glyphWidth);
  70040. }
  70041. }
  70042. }
  70043. }
  70044. bool CustomTypeface::writeToStream (OutputStream& outputStream)
  70045. {
  70046. GZIPCompressorOutputStream out (&outputStream);
  70047. out.writeString (name);
  70048. out.writeBool (isBold);
  70049. out.writeBool (isItalic);
  70050. out.writeFloat (ascent);
  70051. out.writeShort ((short) (unsigned short) defaultCharacter);
  70052. out.writeInt (glyphs.size());
  70053. int i, numKerningPairs = 0;
  70054. for (i = 0; i < glyphs.size(); ++i)
  70055. {
  70056. const GlyphInfo* const g = glyphs.getUnchecked (i);
  70057. out.writeShort ((short) (unsigned short) g->character);
  70058. out.writeFloat (g->width);
  70059. g->path.writePathToStream (out);
  70060. numKerningPairs += g->kerningPairs.size();
  70061. }
  70062. out.writeInt (numKerningPairs);
  70063. for (i = 0; i < glyphs.size(); ++i)
  70064. {
  70065. const GlyphInfo* const g = glyphs.getUnchecked (i);
  70066. for (int j = 0; j < g->kerningPairs.size(); ++j)
  70067. {
  70068. const GlyphInfo::KerningPair& p = g->kerningPairs.getReference (j);
  70069. out.writeShort ((short) (unsigned short) g->character);
  70070. out.writeShort ((short) (unsigned short) p.character2);
  70071. out.writeFloat (p.kerningAmount);
  70072. }
  70073. }
  70074. return true;
  70075. }
  70076. float CustomTypeface::getAscent() const
  70077. {
  70078. return ascent;
  70079. }
  70080. float CustomTypeface::getDescent() const
  70081. {
  70082. return 1.0f - ascent;
  70083. }
  70084. float CustomTypeface::getStringWidth (const String& text)
  70085. {
  70086. float x = 0;
  70087. const juce_wchar* t = (const juce_wchar*) text;
  70088. while (*t != 0)
  70089. {
  70090. const GlyphInfo* const glyph = findGlyphSubstituting (*t++);
  70091. if (glyph != 0)
  70092. x += glyph->getHorizontalSpacing (*t);
  70093. }
  70094. return x;
  70095. }
  70096. void CustomTypeface::getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array<float>& xOffsets)
  70097. {
  70098. xOffsets.add (0);
  70099. float x = 0;
  70100. const juce_wchar* t = (const juce_wchar*) text;
  70101. while (*t != 0)
  70102. {
  70103. const juce_wchar c = *t++;
  70104. const GlyphInfo* const glyph = findGlyphSubstituting (c);
  70105. if (glyph != 0)
  70106. {
  70107. x += glyph->getHorizontalSpacing (*t);
  70108. resultGlyphs.add ((int) glyph->character);
  70109. xOffsets.add (x);
  70110. }
  70111. }
  70112. }
  70113. bool CustomTypeface::getOutlineForGlyph (int glyphNumber, Path& path)
  70114. {
  70115. const GlyphInfo* const glyph = findGlyphSubstituting ((juce_wchar) glyphNumber);
  70116. if (glyph != 0)
  70117. {
  70118. path = glyph->path;
  70119. return true;
  70120. }
  70121. return false;
  70122. }
  70123. END_JUCE_NAMESPACE
  70124. /*** End of inlined file: juce_Typeface.cpp ***/
  70125. /*** Start of inlined file: juce_AffineTransform.cpp ***/
  70126. BEGIN_JUCE_NAMESPACE
  70127. AffineTransform::AffineTransform() throw()
  70128. : mat00 (1.0f),
  70129. mat01 (0),
  70130. mat02 (0),
  70131. mat10 (0),
  70132. mat11 (1.0f),
  70133. mat12 (0)
  70134. {
  70135. }
  70136. AffineTransform::AffineTransform (const AffineTransform& other) throw()
  70137. : mat00 (other.mat00),
  70138. mat01 (other.mat01),
  70139. mat02 (other.mat02),
  70140. mat10 (other.mat10),
  70141. mat11 (other.mat11),
  70142. mat12 (other.mat12)
  70143. {
  70144. }
  70145. AffineTransform::AffineTransform (const float mat00_,
  70146. const float mat01_,
  70147. const float mat02_,
  70148. const float mat10_,
  70149. const float mat11_,
  70150. const float mat12_) throw()
  70151. : mat00 (mat00_),
  70152. mat01 (mat01_),
  70153. mat02 (mat02_),
  70154. mat10 (mat10_),
  70155. mat11 (mat11_),
  70156. mat12 (mat12_)
  70157. {
  70158. }
  70159. AffineTransform& AffineTransform::operator= (const AffineTransform& other) throw()
  70160. {
  70161. mat00 = other.mat00;
  70162. mat01 = other.mat01;
  70163. mat02 = other.mat02;
  70164. mat10 = other.mat10;
  70165. mat11 = other.mat11;
  70166. mat12 = other.mat12;
  70167. return *this;
  70168. }
  70169. bool AffineTransform::operator== (const AffineTransform& other) const throw()
  70170. {
  70171. return mat00 == other.mat00
  70172. && mat01 == other.mat01
  70173. && mat02 == other.mat02
  70174. && mat10 == other.mat10
  70175. && mat11 == other.mat11
  70176. && mat12 == other.mat12;
  70177. }
  70178. bool AffineTransform::operator!= (const AffineTransform& other) const throw()
  70179. {
  70180. return ! operator== (other);
  70181. }
  70182. bool AffineTransform::isIdentity() const throw()
  70183. {
  70184. return (mat01 == 0)
  70185. && (mat02 == 0)
  70186. && (mat10 == 0)
  70187. && (mat12 == 0)
  70188. && (mat00 == 1.0f)
  70189. && (mat11 == 1.0f);
  70190. }
  70191. const AffineTransform AffineTransform::identity;
  70192. const AffineTransform AffineTransform::followedBy (const AffineTransform& other) const throw()
  70193. {
  70194. return AffineTransform (other.mat00 * mat00 + other.mat01 * mat10,
  70195. other.mat00 * mat01 + other.mat01 * mat11,
  70196. other.mat00 * mat02 + other.mat01 * mat12 + other.mat02,
  70197. other.mat10 * mat00 + other.mat11 * mat10,
  70198. other.mat10 * mat01 + other.mat11 * mat11,
  70199. other.mat10 * mat02 + other.mat11 * mat12 + other.mat12);
  70200. }
  70201. const AffineTransform AffineTransform::followedBy (const float omat00,
  70202. const float omat01,
  70203. const float omat02,
  70204. const float omat10,
  70205. const float omat11,
  70206. const float omat12) const throw()
  70207. {
  70208. return AffineTransform (omat00 * mat00 + omat01 * mat10,
  70209. omat00 * mat01 + omat01 * mat11,
  70210. omat00 * mat02 + omat01 * mat12 + omat02,
  70211. omat10 * mat00 + omat11 * mat10,
  70212. omat10 * mat01 + omat11 * mat11,
  70213. omat10 * mat02 + omat11 * mat12 + omat12);
  70214. }
  70215. const AffineTransform AffineTransform::translated (const float dx,
  70216. const float dy) const throw()
  70217. {
  70218. return AffineTransform (mat00, mat01, mat02 + dx,
  70219. mat10, mat11, mat12 + dy);
  70220. }
  70221. const AffineTransform AffineTransform::translation (const float dx,
  70222. const float dy) throw()
  70223. {
  70224. return AffineTransform (1.0f, 0, dx,
  70225. 0, 1.0f, dy);
  70226. }
  70227. const AffineTransform AffineTransform::rotated (const float rad) const throw()
  70228. {
  70229. const float cosRad = cosf (rad);
  70230. const float sinRad = sinf (rad);
  70231. return followedBy (cosRad, -sinRad, 0,
  70232. sinRad, cosRad, 0);
  70233. }
  70234. const AffineTransform AffineTransform::rotation (const float rad) throw()
  70235. {
  70236. const float cosRad = cosf (rad);
  70237. const float sinRad = sinf (rad);
  70238. return AffineTransform (cosRad, -sinRad, 0,
  70239. sinRad, cosRad, 0);
  70240. }
  70241. const AffineTransform AffineTransform::rotated (const float angle,
  70242. const float pivotX,
  70243. const float pivotY) const throw()
  70244. {
  70245. return translated (-pivotX, -pivotY)
  70246. .rotated (angle)
  70247. .translated (pivotX, pivotY);
  70248. }
  70249. const AffineTransform AffineTransform::rotation (const float angle,
  70250. const float pivotX,
  70251. const float pivotY) throw()
  70252. {
  70253. return translation (-pivotX, -pivotY)
  70254. .rotated (angle)
  70255. .translated (pivotX, pivotY);
  70256. }
  70257. const AffineTransform AffineTransform::scaled (const float factorX,
  70258. const float factorY) const throw()
  70259. {
  70260. return AffineTransform (factorX * mat00, factorX * mat01, factorX * mat02,
  70261. factorY * mat10, factorY * mat11, factorY * mat12);
  70262. }
  70263. const AffineTransform AffineTransform::scale (const float factorX,
  70264. const float factorY) throw()
  70265. {
  70266. return AffineTransform (factorX, 0, 0,
  70267. 0, factorY, 0);
  70268. }
  70269. const AffineTransform AffineTransform::sheared (const float shearX,
  70270. const float shearY) const throw()
  70271. {
  70272. return followedBy (1.0f, shearX, 0,
  70273. shearY, 1.0f, 0);
  70274. }
  70275. const AffineTransform AffineTransform::inverted() const throw()
  70276. {
  70277. double determinant = (mat00 * mat11 - mat10 * mat01);
  70278. if (determinant != 0.0)
  70279. {
  70280. determinant = 1.0 / determinant;
  70281. const float dst00 = (float) (mat11 * determinant);
  70282. const float dst10 = (float) (-mat10 * determinant);
  70283. const float dst01 = (float) (-mat01 * determinant);
  70284. const float dst11 = (float) (mat00 * determinant);
  70285. return AffineTransform (dst00, dst01, -mat02 * dst00 - mat12 * dst01,
  70286. dst10, dst11, -mat02 * dst10 - mat12 * dst11);
  70287. }
  70288. else
  70289. {
  70290. // singularity..
  70291. return *this;
  70292. }
  70293. }
  70294. bool AffineTransform::isSingularity() const throw()
  70295. {
  70296. return (mat00 * mat11 - mat10 * mat01) == 0.0;
  70297. }
  70298. bool AffineTransform::isOnlyTranslation() const throw()
  70299. {
  70300. return (mat01 == 0)
  70301. && (mat10 == 0)
  70302. && (mat00 == 1.0f)
  70303. && (mat11 == 1.0f);
  70304. }
  70305. void AffineTransform::transformPoint (float& x,
  70306. float& y) const throw()
  70307. {
  70308. const float oldX = x;
  70309. x = mat00 * oldX + mat01 * y + mat02;
  70310. y = mat10 * oldX + mat11 * y + mat12;
  70311. }
  70312. void AffineTransform::transformPoint (double& x,
  70313. double& y) const throw()
  70314. {
  70315. const double oldX = x;
  70316. x = mat00 * oldX + mat01 * y + mat02;
  70317. y = mat10 * oldX + mat11 * y + mat12;
  70318. }
  70319. END_JUCE_NAMESPACE
  70320. /*** End of inlined file: juce_AffineTransform.cpp ***/
  70321. /*** Start of inlined file: juce_BorderSize.cpp ***/
  70322. BEGIN_JUCE_NAMESPACE
  70323. BorderSize::BorderSize() throw()
  70324. : top (0),
  70325. left (0),
  70326. bottom (0),
  70327. right (0)
  70328. {
  70329. }
  70330. BorderSize::BorderSize (const BorderSize& other) throw()
  70331. : top (other.top),
  70332. left (other.left),
  70333. bottom (other.bottom),
  70334. right (other.right)
  70335. {
  70336. }
  70337. BorderSize::BorderSize (const int topGap,
  70338. const int leftGap,
  70339. const int bottomGap,
  70340. const int rightGap) throw()
  70341. : top (topGap),
  70342. left (leftGap),
  70343. bottom (bottomGap),
  70344. right (rightGap)
  70345. {
  70346. }
  70347. BorderSize::BorderSize (const int allGaps) throw()
  70348. : top (allGaps),
  70349. left (allGaps),
  70350. bottom (allGaps),
  70351. right (allGaps)
  70352. {
  70353. }
  70354. BorderSize::~BorderSize() throw()
  70355. {
  70356. }
  70357. void BorderSize::setTop (const int newTopGap) throw()
  70358. {
  70359. top = newTopGap;
  70360. }
  70361. void BorderSize::setLeft (const int newLeftGap) throw()
  70362. {
  70363. left = newLeftGap;
  70364. }
  70365. void BorderSize::setBottom (const int newBottomGap) throw()
  70366. {
  70367. bottom = newBottomGap;
  70368. }
  70369. void BorderSize::setRight (const int newRightGap) throw()
  70370. {
  70371. right = newRightGap;
  70372. }
  70373. const Rectangle<int> BorderSize::subtractedFrom (const Rectangle<int>& r) const throw()
  70374. {
  70375. return Rectangle<int> (r.getX() + left,
  70376. r.getY() + top,
  70377. r.getWidth() - (left + right),
  70378. r.getHeight() - (top + bottom));
  70379. }
  70380. void BorderSize::subtractFrom (Rectangle<int>& r) const throw()
  70381. {
  70382. r.setBounds (r.getX() + left,
  70383. r.getY() + top,
  70384. r.getWidth() - (left + right),
  70385. r.getHeight() - (top + bottom));
  70386. }
  70387. const Rectangle<int> BorderSize::addedTo (const Rectangle<int>& r) const throw()
  70388. {
  70389. return Rectangle<int> (r.getX() - left,
  70390. r.getY() - top,
  70391. r.getWidth() + (left + right),
  70392. r.getHeight() + (top + bottom));
  70393. }
  70394. void BorderSize::addTo (Rectangle<int>& r) const throw()
  70395. {
  70396. r.setBounds (r.getX() - left,
  70397. r.getY() - top,
  70398. r.getWidth() + (left + right),
  70399. r.getHeight() + (top + bottom));
  70400. }
  70401. bool BorderSize::operator== (const BorderSize& other) const throw()
  70402. {
  70403. return top == other.top
  70404. && left == other.left
  70405. && bottom == other.bottom
  70406. && right == other.right;
  70407. }
  70408. bool BorderSize::operator!= (const BorderSize& other) const throw()
  70409. {
  70410. return ! operator== (other);
  70411. }
  70412. END_JUCE_NAMESPACE
  70413. /*** End of inlined file: juce_BorderSize.cpp ***/
  70414. /*** Start of inlined file: juce_Line.cpp ***/
  70415. BEGIN_JUCE_NAMESPACE
  70416. static bool juce_lineIntersection (const float x1, const float y1,
  70417. const float x2, const float y2,
  70418. const float x3, const float y3,
  70419. const float x4, const float y4,
  70420. float& intersectionX,
  70421. float& intersectionY) throw()
  70422. {
  70423. if (x2 != x3 || y2 != y3)
  70424. {
  70425. const float dx1 = x2 - x1;
  70426. const float dy1 = y2 - y1;
  70427. const float dx2 = x4 - x3;
  70428. const float dy2 = y4 - y3;
  70429. const float divisor = dx1 * dy2 - dx2 * dy1;
  70430. if (divisor == 0)
  70431. {
  70432. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  70433. {
  70434. if (dy1 == 0 && dy2 != 0)
  70435. {
  70436. const float along = (y1 - y3) / dy2;
  70437. intersectionX = x3 + along * dx2;
  70438. intersectionY = y1;
  70439. return along >= 0 && along <= 1.0f;
  70440. }
  70441. else if (dy2 == 0 && dy1 != 0)
  70442. {
  70443. const float along = (y3 - y1) / dy1;
  70444. intersectionX = x1 + along * dx1;
  70445. intersectionY = y3;
  70446. return along >= 0 && along <= 1.0f;
  70447. }
  70448. else if (dx1 == 0 && dx2 != 0)
  70449. {
  70450. const float along = (x1 - x3) / dx2;
  70451. intersectionX = x1;
  70452. intersectionY = y3 + along * dy2;
  70453. return along >= 0 && along <= 1.0f;
  70454. }
  70455. else if (dx2 == 0 && dx1 != 0)
  70456. {
  70457. const float along = (x3 - x1) / dx1;
  70458. intersectionX = x3;
  70459. intersectionY = y1 + along * dy1;
  70460. return along >= 0 && along <= 1.0f;
  70461. }
  70462. }
  70463. intersectionX = 0.5f * (x2 + x3);
  70464. intersectionY = 0.5f * (y2 + y3);
  70465. return false;
  70466. }
  70467. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  70468. intersectionX = x1 + along1 * dx1;
  70469. intersectionY = y1 + along1 * dy1;
  70470. if (along1 < 0 || along1 > 1.0f)
  70471. return false;
  70472. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1) / divisor;
  70473. return along2 >= 0 && along2 <= 1.0f;
  70474. }
  70475. intersectionX = x2;
  70476. intersectionY = y2;
  70477. return true;
  70478. }
  70479. Line::Line() throw()
  70480. : startX (0.0f),
  70481. startY (0.0f),
  70482. endX (0.0f),
  70483. endY (0.0f)
  70484. {
  70485. }
  70486. Line::Line (const Line& other) throw()
  70487. : startX (other.startX),
  70488. startY (other.startY),
  70489. endX (other.endX),
  70490. endY (other.endY)
  70491. {
  70492. }
  70493. Line::Line (const float startX_, const float startY_,
  70494. const float endX_, const float endY_) throw()
  70495. : startX (startX_),
  70496. startY (startY_),
  70497. endX (endX_),
  70498. endY (endY_)
  70499. {
  70500. }
  70501. Line::Line (const Point<float>& start,
  70502. const Point<float>& end) throw()
  70503. : startX (start.getX()),
  70504. startY (start.getY()),
  70505. endX (end.getX()),
  70506. endY (end.getY())
  70507. {
  70508. }
  70509. Line& Line::operator= (const Line& other) throw()
  70510. {
  70511. startX = other.startX;
  70512. startY = other.startY;
  70513. endX = other.endX;
  70514. endY = other.endY;
  70515. return *this;
  70516. }
  70517. Line::~Line() throw()
  70518. {
  70519. }
  70520. const Point<float> Line::getStart() const throw()
  70521. {
  70522. return Point<float> (startX, startY);
  70523. }
  70524. const Point<float> Line::getEnd() const throw()
  70525. {
  70526. return Point<float> (endX, endY);
  70527. }
  70528. void Line::setStart (const float newStartX,
  70529. const float newStartY) throw()
  70530. {
  70531. startX = newStartX;
  70532. startY = newStartY;
  70533. }
  70534. void Line::setStart (const Point<float>& newStart) throw()
  70535. {
  70536. startX = newStart.getX();
  70537. startY = newStart.getY();
  70538. }
  70539. void Line::setEnd (const float newEndX,
  70540. const float newEndY) throw()
  70541. {
  70542. endX = newEndX;
  70543. endY = newEndY;
  70544. }
  70545. void Line::setEnd (const Point<float>& newEnd) throw()
  70546. {
  70547. endX = newEnd.getX();
  70548. endY = newEnd.getY();
  70549. }
  70550. bool Line::operator== (const Line& other) const throw()
  70551. {
  70552. return startX == other.startX
  70553. && startY == other.startY
  70554. && endX == other.endX
  70555. && endY == other.endY;
  70556. }
  70557. bool Line::operator!= (const Line& other) const throw()
  70558. {
  70559. return startX != other.startX
  70560. || startY != other.startY
  70561. || endX != other.endX
  70562. || endY != other.endY;
  70563. }
  70564. void Line::applyTransform (const AffineTransform& transform) throw()
  70565. {
  70566. transform.transformPoint (startX, startY);
  70567. transform.transformPoint (endX, endY);
  70568. }
  70569. float Line::getLength() const throw()
  70570. {
  70571. return (float) juce_hypot (startX - endX,
  70572. startY - endY);
  70573. }
  70574. float Line::getAngle() const throw()
  70575. {
  70576. return atan2f (endX - startX,
  70577. endY - startY);
  70578. }
  70579. const Point<float> Line::getPointAlongLine (const float distanceFromStart) const throw()
  70580. {
  70581. const float alpha = distanceFromStart / getLength();
  70582. return Point<float> (startX + (endX - startX) * alpha,
  70583. startY + (endY - startY) * alpha);
  70584. }
  70585. const Point<float> Line::getPointAlongLine (const float offsetX,
  70586. const float offsetY) const throw()
  70587. {
  70588. const float dx = endX - startX;
  70589. const float dy = endY - startY;
  70590. const double length = juce_hypot (dx, dy);
  70591. if (length == 0)
  70592. return Point<float> (startX, startY);
  70593. else
  70594. return Point<float> (startX + (float) (((dx * offsetX) - (dy * offsetY)) / length),
  70595. startY + (float) (((dy * offsetX) + (dx * offsetY)) / length));
  70596. }
  70597. const Point<float> Line::getPointAlongLineProportionally (const float alpha) const throw()
  70598. {
  70599. return Point<float> (startX + (endX - startX) * alpha,
  70600. startY + (endY - startY) * alpha);
  70601. }
  70602. float Line::getDistanceFromLine (const float x,
  70603. const float y) const throw()
  70604. {
  70605. const double dx = endX - startX;
  70606. const double dy = endY - startY;
  70607. const double length = dx * dx + dy * dy;
  70608. if (length > 0)
  70609. {
  70610. const double prop = ((x - startX) * dx + (y - startY) * dy) / length;
  70611. if (prop >= 0.0f && prop < 1.0f)
  70612. {
  70613. return (float) juce_hypot (x - (startX + prop * dx),
  70614. y - (startY + prop * dy));
  70615. }
  70616. }
  70617. return (float) jmin (juce_hypot (x - startX, y - startY),
  70618. juce_hypot (x - endX, y - endY));
  70619. }
  70620. float Line::findNearestPointTo (const float x,
  70621. const float y) const throw()
  70622. {
  70623. const double dx = endX - startX;
  70624. const double dy = endY - startY;
  70625. const double length = dx * dx + dy * dy;
  70626. if (length <= 0.0)
  70627. return 0.0f;
  70628. return jlimit (0.0f, 1.0f,
  70629. (float) (((x - startX) * dx + (y - startY) * dy) / length));
  70630. }
  70631. const Line Line::withShortenedStart (const float distanceToShortenBy) const throw()
  70632. {
  70633. const float length = getLength();
  70634. return Line (getPointAlongLine (jmin (distanceToShortenBy, length)),
  70635. getEnd());
  70636. }
  70637. const Line Line::withShortenedEnd (const float distanceToShortenBy) const throw()
  70638. {
  70639. const float length = getLength();
  70640. return Line (getStart(),
  70641. getPointAlongLine (length - jmin (distanceToShortenBy, length)));
  70642. }
  70643. bool Line::clipToPath (const Path& path,
  70644. const bool keepSectionOutsidePath) throw()
  70645. {
  70646. const bool startInside = path.contains (startX, startY);
  70647. const bool endInside = path.contains (endX, endY);
  70648. if (startInside == endInside)
  70649. {
  70650. if (keepSectionOutsidePath != startInside)
  70651. {
  70652. // entirely outside the path
  70653. return false;
  70654. }
  70655. else
  70656. {
  70657. // entirely inside the path
  70658. startX = 0.0f;
  70659. startY = 0.0f;
  70660. endX = 0.0f;
  70661. endY = 0.0f;
  70662. return true;
  70663. }
  70664. }
  70665. else
  70666. {
  70667. bool changed = false;
  70668. PathFlatteningIterator iter (path, AffineTransform::identity);
  70669. while (iter.next())
  70670. {
  70671. float ix, iy;
  70672. if (intersects (Line (iter.x1, iter.y1,
  70673. iter.x2, iter.y2),
  70674. ix, iy))
  70675. {
  70676. if ((startInside && keepSectionOutsidePath)
  70677. || (endInside && ! keepSectionOutsidePath))
  70678. {
  70679. setStart (ix, iy);
  70680. }
  70681. else
  70682. {
  70683. setEnd (ix, iy);
  70684. }
  70685. changed = true;
  70686. }
  70687. }
  70688. return changed;
  70689. }
  70690. }
  70691. bool Line::intersects (const Line& line,
  70692. float& intersectionX,
  70693. float& intersectionY) const throw()
  70694. {
  70695. return juce_lineIntersection (startX, startY,
  70696. endX, endY,
  70697. line.startX, line.startY,
  70698. line.endX, line.endY,
  70699. intersectionX,
  70700. intersectionY);
  70701. }
  70702. bool Line::isVertical() const throw()
  70703. {
  70704. return startX == endX;
  70705. }
  70706. bool Line::isHorizontal() const throw()
  70707. {
  70708. return startY == endY;
  70709. }
  70710. bool Line::isPointAbove (const float x, const float y) const throw()
  70711. {
  70712. return startX != endX
  70713. && y < ((endY - startY) * (x - startX)) / (endX - startX) + startY;
  70714. }
  70715. END_JUCE_NAMESPACE
  70716. /*** End of inlined file: juce_Line.cpp ***/
  70717. /*** Start of inlined file: juce_Path.cpp ***/
  70718. BEGIN_JUCE_NAMESPACE
  70719. // tests that some co-ords aren't NaNs
  70720. #define CHECK_COORDS_ARE_VALID(x, y) \
  70721. jassert (x == x && y == y);
  70722. namespace PathHelpers
  70723. {
  70724. static const float ellipseAngularIncrement = 0.05f;
  70725. static void perpendicularOffset (const float x1, const float y1,
  70726. const float x2, const float y2,
  70727. const float offsetX, const float offsetY,
  70728. float& resultX, float& resultY) throw()
  70729. {
  70730. const float dx = x2 - x1;
  70731. const float dy = y2 - y1;
  70732. const float len = juce_hypotf (dx, dy);
  70733. if (len == 0)
  70734. {
  70735. resultX = x1;
  70736. resultY = y1;
  70737. }
  70738. else
  70739. {
  70740. resultX = x1 + ((dx * offsetX) - (dy * offsetY)) / len;
  70741. resultY = y1 + ((dy * offsetX) + (dx * offsetY)) / len;
  70742. }
  70743. }
  70744. static const String nextToken (const tchar*& t)
  70745. {
  70746. while (CharacterFunctions::isWhitespace (*t))
  70747. ++t;
  70748. const tchar* const start = t;
  70749. while (*t != 0 && ! CharacterFunctions::isWhitespace (*t))
  70750. ++t;
  70751. const int length = (int) (t - start);
  70752. while (CharacterFunctions::isWhitespace (*t))
  70753. ++t;
  70754. return String (start, length);
  70755. }
  70756. }
  70757. const float Path::lineMarker = 100001.0f;
  70758. const float Path::moveMarker = 100002.0f;
  70759. const float Path::quadMarker = 100003.0f;
  70760. const float Path::cubicMarker = 100004.0f;
  70761. const float Path::closeSubPathMarker = 100005.0f;
  70762. Path::Path()
  70763. : numElements (0),
  70764. pathXMin (0),
  70765. pathXMax (0),
  70766. pathYMin (0),
  70767. pathYMax (0),
  70768. useNonZeroWinding (true)
  70769. {
  70770. }
  70771. Path::~Path()
  70772. {
  70773. }
  70774. Path::Path (const Path& other)
  70775. : numElements (other.numElements),
  70776. pathXMin (other.pathXMin),
  70777. pathXMax (other.pathXMax),
  70778. pathYMin (other.pathYMin),
  70779. pathYMax (other.pathYMax),
  70780. useNonZeroWinding (other.useNonZeroWinding)
  70781. {
  70782. if (numElements > 0)
  70783. {
  70784. data.setAllocatedSize (numElements);
  70785. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  70786. }
  70787. }
  70788. Path& Path::operator= (const Path& other)
  70789. {
  70790. if (this != &other)
  70791. {
  70792. data.ensureAllocatedSize (other.numElements);
  70793. numElements = other.numElements;
  70794. pathXMin = other.pathXMin;
  70795. pathXMax = other.pathXMax;
  70796. pathYMin = other.pathYMin;
  70797. pathYMax = other.pathYMax;
  70798. useNonZeroWinding = other.useNonZeroWinding;
  70799. if (numElements > 0)
  70800. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  70801. }
  70802. return *this;
  70803. }
  70804. void Path::clear() throw()
  70805. {
  70806. numElements = 0;
  70807. pathXMin = 0;
  70808. pathYMin = 0;
  70809. pathYMax = 0;
  70810. pathXMax = 0;
  70811. }
  70812. void Path::swapWithPath (Path& other)
  70813. {
  70814. data.swapWith (other.data);
  70815. swapVariables <size_t> (numElements, other.numElements);
  70816. swapVariables <float> (pathXMin, other.pathXMin);
  70817. swapVariables <float> (pathXMax, other.pathXMax);
  70818. swapVariables <float> (pathYMin, other.pathYMin);
  70819. swapVariables <float> (pathYMax, other.pathYMax);
  70820. swapVariables <bool> (useNonZeroWinding, other.useNonZeroWinding);
  70821. }
  70822. void Path::setUsingNonZeroWinding (const bool isNonZero) throw()
  70823. {
  70824. useNonZeroWinding = isNonZero;
  70825. }
  70826. void Path::scaleToFit (const float x, const float y, const float w, const float h,
  70827. const bool preserveProportions) throw()
  70828. {
  70829. applyTransform (getTransformToScaleToFit (x, y, w, h, preserveProportions));
  70830. }
  70831. bool Path::isEmpty() const throw()
  70832. {
  70833. size_t i = 0;
  70834. while (i < numElements)
  70835. {
  70836. const float type = data.elements [i++];
  70837. if (type == moveMarker)
  70838. {
  70839. i += 2;
  70840. }
  70841. else if (type == lineMarker
  70842. || type == quadMarker
  70843. || type == cubicMarker)
  70844. {
  70845. return false;
  70846. }
  70847. }
  70848. return true;
  70849. }
  70850. const Rectangle<float> Path::getBounds() const throw()
  70851. {
  70852. return Rectangle<float> (pathXMin, pathYMin,
  70853. pathXMax - pathXMin,
  70854. pathYMax - pathYMin);
  70855. }
  70856. const Rectangle<float> Path::getBoundsTransformed (const AffineTransform& transform) const throw()
  70857. {
  70858. return getBounds().transformed (transform);
  70859. }
  70860. void Path::startNewSubPath (const float x, const float y)
  70861. {
  70862. CHECK_COORDS_ARE_VALID (x, y);
  70863. if (numElements == 0)
  70864. {
  70865. pathXMin = pathXMax = x;
  70866. pathYMin = pathYMax = y;
  70867. }
  70868. else
  70869. {
  70870. pathXMin = jmin (pathXMin, x);
  70871. pathXMax = jmax (pathXMax, x);
  70872. pathYMin = jmin (pathYMin, y);
  70873. pathYMax = jmax (pathYMax, y);
  70874. }
  70875. data.ensureAllocatedSize (numElements + 3);
  70876. data.elements [numElements++] = moveMarker;
  70877. data.elements [numElements++] = x;
  70878. data.elements [numElements++] = y;
  70879. }
  70880. void Path::lineTo (const float x, const float y)
  70881. {
  70882. CHECK_COORDS_ARE_VALID (x, y);
  70883. if (numElements == 0)
  70884. startNewSubPath (0, 0);
  70885. data.ensureAllocatedSize (numElements + 3);
  70886. data.elements [numElements++] = lineMarker;
  70887. data.elements [numElements++] = x;
  70888. data.elements [numElements++] = y;
  70889. pathXMin = jmin (pathXMin, x);
  70890. pathXMax = jmax (pathXMax, x);
  70891. pathYMin = jmin (pathYMin, y);
  70892. pathYMax = jmax (pathYMax, y);
  70893. }
  70894. void Path::quadraticTo (const float x1, const float y1,
  70895. const float x2, const float y2)
  70896. {
  70897. CHECK_COORDS_ARE_VALID (x1, y1);
  70898. CHECK_COORDS_ARE_VALID (x2, y2);
  70899. if (numElements == 0)
  70900. startNewSubPath (0, 0);
  70901. data.ensureAllocatedSize (numElements + 5);
  70902. data.elements [numElements++] = quadMarker;
  70903. data.elements [numElements++] = x1;
  70904. data.elements [numElements++] = y1;
  70905. data.elements [numElements++] = x2;
  70906. data.elements [numElements++] = y2;
  70907. pathXMin = jmin (pathXMin, x1, x2);
  70908. pathXMax = jmax (pathXMax, x1, x2);
  70909. pathYMin = jmin (pathYMin, y1, y2);
  70910. pathYMax = jmax (pathYMax, y1, y2);
  70911. }
  70912. void Path::cubicTo (const float x1, const float y1,
  70913. const float x2, const float y2,
  70914. const float x3, const float y3)
  70915. {
  70916. CHECK_COORDS_ARE_VALID (x1, y1);
  70917. CHECK_COORDS_ARE_VALID (x2, y2);
  70918. CHECK_COORDS_ARE_VALID (x3, y3);
  70919. if (numElements == 0)
  70920. startNewSubPath (0, 0);
  70921. data.ensureAllocatedSize (numElements + 7);
  70922. data.elements [numElements++] = cubicMarker;
  70923. data.elements [numElements++] = x1;
  70924. data.elements [numElements++] = y1;
  70925. data.elements [numElements++] = x2;
  70926. data.elements [numElements++] = y2;
  70927. data.elements [numElements++] = x3;
  70928. data.elements [numElements++] = y3;
  70929. pathXMin = jmin (pathXMin, x1, x2, x3);
  70930. pathXMax = jmax (pathXMax, x1, x2, x3);
  70931. pathYMin = jmin (pathYMin, y1, y2, y3);
  70932. pathYMax = jmax (pathYMax, y1, y2, y3);
  70933. }
  70934. void Path::closeSubPath()
  70935. {
  70936. if (numElements > 0
  70937. && data.elements [numElements - 1] != closeSubPathMarker)
  70938. {
  70939. data.ensureAllocatedSize (numElements + 1);
  70940. data.elements [numElements++] = closeSubPathMarker;
  70941. }
  70942. }
  70943. const Point<float> Path::getCurrentPosition() const
  70944. {
  70945. int i = numElements - 1;
  70946. if (i > 0 && data.elements[i] == closeSubPathMarker)
  70947. {
  70948. while (i >= 0)
  70949. {
  70950. if (data.elements[i] == moveMarker)
  70951. {
  70952. i += 2;
  70953. break;
  70954. }
  70955. --i;
  70956. }
  70957. }
  70958. if (i > 0)
  70959. return Point<float> (data.elements [i - 1], data.elements [i]);
  70960. return Point<float>();
  70961. }
  70962. void Path::addRectangle (const float x, const float y,
  70963. const float w, const float h)
  70964. {
  70965. float x1 = x, y1 = y, x2 = x + w, y2 = y + h;
  70966. if (w < 0)
  70967. swapVariables (x1, x2);
  70968. if (h < 0)
  70969. swapVariables (y1, y2);
  70970. data.ensureAllocatedSize (numElements + 13);
  70971. if (numElements == 0)
  70972. {
  70973. pathXMin = x1;
  70974. pathXMax = x2;
  70975. pathYMin = y1;
  70976. pathYMax = y2;
  70977. }
  70978. else
  70979. {
  70980. pathXMin = jmin (pathXMin, x1);
  70981. pathXMax = jmax (pathXMax, x2);
  70982. pathYMin = jmin (pathYMin, y1);
  70983. pathYMax = jmax (pathYMax, y2);
  70984. }
  70985. data.elements [numElements++] = moveMarker;
  70986. data.elements [numElements++] = x1;
  70987. data.elements [numElements++] = y2;
  70988. data.elements [numElements++] = lineMarker;
  70989. data.elements [numElements++] = x1;
  70990. data.elements [numElements++] = y1;
  70991. data.elements [numElements++] = lineMarker;
  70992. data.elements [numElements++] = x2;
  70993. data.elements [numElements++] = y1;
  70994. data.elements [numElements++] = lineMarker;
  70995. data.elements [numElements++] = x2;
  70996. data.elements [numElements++] = y2;
  70997. data.elements [numElements++] = closeSubPathMarker;
  70998. }
  70999. void Path::addRectangle (const Rectangle<int>& rectangle)
  71000. {
  71001. addRectangle ((float) rectangle.getX(), (float) rectangle.getY(),
  71002. (float) rectangle.getWidth(), (float) rectangle.getHeight());
  71003. }
  71004. void Path::addRoundedRectangle (const float x, const float y,
  71005. const float w, const float h,
  71006. float csx,
  71007. float csy)
  71008. {
  71009. csx = jmin (csx, w * 0.5f);
  71010. csy = jmin (csy, h * 0.5f);
  71011. const float cs45x = csx * 0.45f;
  71012. const float cs45y = csy * 0.45f;
  71013. const float x2 = x + w;
  71014. const float y2 = y + h;
  71015. startNewSubPath (x + csx, y);
  71016. lineTo (x2 - csx, y);
  71017. cubicTo (x2 - cs45x, y, x2, y + cs45y, x2, y + csy);
  71018. lineTo (x2, y2 - csy);
  71019. cubicTo (x2, y2 - cs45y, x2 - cs45x, y2, x2 - csx, y2);
  71020. lineTo (x + csx, y2);
  71021. cubicTo (x + cs45x, y2, x, y2 - cs45y, x, y2 - csy);
  71022. lineTo (x, y + csy);
  71023. cubicTo (x, y + cs45y, x + cs45x, y, x + csx, y);
  71024. closeSubPath();
  71025. }
  71026. void Path::addRoundedRectangle (const float x, const float y,
  71027. const float w, const float h,
  71028. float cs)
  71029. {
  71030. addRoundedRectangle (x, y, w, h, cs, cs);
  71031. }
  71032. void Path::addTriangle (const float x1, const float y1,
  71033. const float x2, const float y2,
  71034. const float x3, const float y3)
  71035. {
  71036. startNewSubPath (x1, y1);
  71037. lineTo (x2, y2);
  71038. lineTo (x3, y3);
  71039. closeSubPath();
  71040. }
  71041. void Path::addQuadrilateral (const float x1, const float y1,
  71042. const float x2, const float y2,
  71043. const float x3, const float y3,
  71044. const float x4, const float y4)
  71045. {
  71046. startNewSubPath (x1, y1);
  71047. lineTo (x2, y2);
  71048. lineTo (x3, y3);
  71049. lineTo (x4, y4);
  71050. closeSubPath();
  71051. }
  71052. void Path::addEllipse (const float x, const float y,
  71053. const float w, const float h)
  71054. {
  71055. const float hw = w * 0.5f;
  71056. const float hw55 = hw * 0.55f;
  71057. const float hh = h * 0.5f;
  71058. const float hh45 = hh * 0.55f;
  71059. const float cx = x + hw;
  71060. const float cy = y + hh;
  71061. startNewSubPath (cx, cy - hh);
  71062. cubicTo (cx + hw55, cy - hh, cx + hw, cy - hh45, cx + hw, cy);
  71063. cubicTo (cx + hw, cy + hh45, cx + hw55, cy + hh, cx, cy + hh);
  71064. cubicTo (cx - hw55, cy + hh, cx - hw, cy + hh45, cx - hw, cy);
  71065. cubicTo (cx - hw, cy - hh45, cx - hw55, cy - hh, cx, cy - hh);
  71066. closeSubPath();
  71067. }
  71068. void Path::addArc (const float x, const float y,
  71069. const float w, const float h,
  71070. const float fromRadians,
  71071. const float toRadians,
  71072. const bool startAsNewSubPath)
  71073. {
  71074. const float radiusX = w / 2.0f;
  71075. const float radiusY = h / 2.0f;
  71076. addCentredArc (x + radiusX,
  71077. y + radiusY,
  71078. radiusX, radiusY,
  71079. 0.0f,
  71080. fromRadians, toRadians,
  71081. startAsNewSubPath);
  71082. }
  71083. void Path::addCentredArc (const float centreX, const float centreY,
  71084. const float radiusX, const float radiusY,
  71085. const float rotationOfEllipse,
  71086. const float fromRadians,
  71087. const float toRadians,
  71088. const bool startAsNewSubPath)
  71089. {
  71090. if (radiusX > 0.0f && radiusY > 0.0f)
  71091. {
  71092. const AffineTransform rotation (AffineTransform::rotation (rotationOfEllipse, centreX, centreY));
  71093. float angle = fromRadians;
  71094. if (startAsNewSubPath)
  71095. {
  71096. float x = centreX + radiusX * sinf (angle);
  71097. float y = centreY - radiusY * cosf (angle);
  71098. if (rotationOfEllipse != 0)
  71099. rotation.transformPoint (x, y);
  71100. startNewSubPath (x, y);
  71101. }
  71102. if (fromRadians < toRadians)
  71103. {
  71104. if (startAsNewSubPath)
  71105. angle += PathHelpers::ellipseAngularIncrement;
  71106. while (angle < toRadians)
  71107. {
  71108. float x = centreX + radiusX * sinf (angle);
  71109. float y = centreY - radiusY * cosf (angle);
  71110. if (rotationOfEllipse != 0)
  71111. rotation.transformPoint (x, y);
  71112. lineTo (x, y);
  71113. angle += PathHelpers::ellipseAngularIncrement;
  71114. }
  71115. }
  71116. else
  71117. {
  71118. if (startAsNewSubPath)
  71119. angle -= PathHelpers::ellipseAngularIncrement;
  71120. while (angle > toRadians)
  71121. {
  71122. float x = centreX + radiusX * sinf (angle);
  71123. float y = centreY - radiusY * cosf (angle);
  71124. if (rotationOfEllipse != 0)
  71125. rotation.transformPoint (x, y);
  71126. lineTo (x, y);
  71127. angle -= PathHelpers::ellipseAngularIncrement;
  71128. }
  71129. }
  71130. float x = centreX + radiusX * sinf (toRadians);
  71131. float y = centreY - radiusY * cosf (toRadians);
  71132. if (rotationOfEllipse != 0)
  71133. rotation.transformPoint (x, y);
  71134. lineTo (x, y);
  71135. }
  71136. }
  71137. void Path::addPieSegment (const float x, const float y,
  71138. const float width, const float height,
  71139. const float fromRadians,
  71140. const float toRadians,
  71141. const float innerCircleProportionalSize)
  71142. {
  71143. float hw = width * 0.5f;
  71144. float hh = height * 0.5f;
  71145. const float centreX = x + hw;
  71146. const float centreY = y + hh;
  71147. startNewSubPath (centreX + hw * sinf (fromRadians),
  71148. centreY - hh * cosf (fromRadians));
  71149. addArc (x, y, width, height, fromRadians, toRadians);
  71150. if (fabs (fromRadians - toRadians) > float_Pi * 1.999f)
  71151. {
  71152. closeSubPath();
  71153. if (innerCircleProportionalSize > 0)
  71154. {
  71155. hw *= innerCircleProportionalSize;
  71156. hh *= innerCircleProportionalSize;
  71157. startNewSubPath (centreX + hw * sinf (toRadians),
  71158. centreY - hh * cosf (toRadians));
  71159. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71160. toRadians, fromRadians);
  71161. }
  71162. }
  71163. else
  71164. {
  71165. if (innerCircleProportionalSize > 0)
  71166. {
  71167. hw *= innerCircleProportionalSize;
  71168. hh *= innerCircleProportionalSize;
  71169. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71170. toRadians, fromRadians);
  71171. }
  71172. else
  71173. {
  71174. lineTo (centreX, centreY);
  71175. }
  71176. }
  71177. closeSubPath();
  71178. }
  71179. void Path::addLineSegment (const float startX, const float startY,
  71180. const float endX, const float endY,
  71181. float lineThickness)
  71182. {
  71183. lineThickness *= 0.5f;
  71184. float x, y;
  71185. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  71186. 0, lineThickness, x, y);
  71187. startNewSubPath (x, y);
  71188. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  71189. 0, -lineThickness, x, y);
  71190. lineTo (x, y);
  71191. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71192. 0, lineThickness, x, y);
  71193. lineTo (x, y);
  71194. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71195. 0, -lineThickness, x, y);
  71196. lineTo (x, y);
  71197. closeSubPath();
  71198. }
  71199. void Path::addArrow (const float startX, const float startY,
  71200. const float endX, const float endY,
  71201. float lineThickness,
  71202. float arrowheadWidth,
  71203. float arrowheadLength)
  71204. {
  71205. lineThickness *= 0.5f;
  71206. arrowheadWidth *= 0.5f;
  71207. arrowheadLength = jmin (arrowheadLength, 0.8f * juce_hypotf (startX - endX,
  71208. startY - endY));
  71209. float x, y;
  71210. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  71211. 0, lineThickness, x, y);
  71212. startNewSubPath (x, y);
  71213. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  71214. 0, -lineThickness, x, y);
  71215. lineTo (x, y);
  71216. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71217. arrowheadLength, lineThickness, x, y);
  71218. lineTo (x, y);
  71219. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71220. arrowheadLength, arrowheadWidth, x, y);
  71221. lineTo (x, y);
  71222. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71223. 0, 0, x, y);
  71224. lineTo (x, y);
  71225. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71226. arrowheadLength, -arrowheadWidth, x, y);
  71227. lineTo (x, y);
  71228. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71229. arrowheadLength, -lineThickness, x, y);
  71230. lineTo (x, y);
  71231. closeSubPath();
  71232. }
  71233. void Path::addStar (const float centreX,
  71234. const float centreY,
  71235. const int numberOfPoints,
  71236. const float innerRadius,
  71237. const float outerRadius,
  71238. const float startAngle)
  71239. {
  71240. jassert (numberOfPoints > 1); // this would be silly.
  71241. if (numberOfPoints > 1)
  71242. {
  71243. const float angleBetweenPoints = float_Pi * 2.0f / numberOfPoints;
  71244. for (int i = 0; i < numberOfPoints; ++i)
  71245. {
  71246. float angle = startAngle + i * angleBetweenPoints;
  71247. const float x = centreX + outerRadius * sinf (angle);
  71248. const float y = centreY - outerRadius * cosf (angle);
  71249. if (i == 0)
  71250. startNewSubPath (x, y);
  71251. else
  71252. lineTo (x, y);
  71253. angle += angleBetweenPoints * 0.5f;
  71254. lineTo (centreX + innerRadius * sinf (angle),
  71255. centreY - innerRadius * cosf (angle));
  71256. }
  71257. closeSubPath();
  71258. }
  71259. }
  71260. void Path::addBubble (float x, float y,
  71261. float w, float h,
  71262. float cs,
  71263. float tipX,
  71264. float tipY,
  71265. int whichSide,
  71266. float arrowPos,
  71267. float arrowWidth)
  71268. {
  71269. if (w > 1.0f && h > 1.0f)
  71270. {
  71271. cs = jmin (cs, w * 0.5f, h * 0.5f);
  71272. const float cs2 = 2.0f * cs;
  71273. startNewSubPath (x + cs, y);
  71274. if (whichSide == 0)
  71275. {
  71276. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71277. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71278. lineTo (arrowX1, y);
  71279. lineTo (tipX, tipY);
  71280. lineTo (arrowX1 + halfArrowW * 2.0f, y);
  71281. }
  71282. lineTo (x + w - cs, y);
  71283. if (cs > 0.0f)
  71284. addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  71285. if (whichSide == 3)
  71286. {
  71287. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71288. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71289. lineTo (x + w, arrowY1);
  71290. lineTo (tipX, tipY);
  71291. lineTo (x + w, arrowY1 + halfArrowH * 2.0f);
  71292. }
  71293. lineTo (x + w, y + h - cs);
  71294. if (cs > 0.0f)
  71295. addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  71296. if (whichSide == 2)
  71297. {
  71298. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71299. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71300. lineTo (arrowX1 + halfArrowW * 2.0f, y + h);
  71301. lineTo (tipX, tipY);
  71302. lineTo (arrowX1, y + h);
  71303. }
  71304. lineTo (x + cs, y + h);
  71305. if (cs > 0.0f)
  71306. addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  71307. if (whichSide == 1)
  71308. {
  71309. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71310. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71311. lineTo (x, arrowY1 + halfArrowH * 2.0f);
  71312. lineTo (tipX, tipY);
  71313. lineTo (x, arrowY1);
  71314. }
  71315. lineTo (x, y + cs);
  71316. if (cs > 0.0f)
  71317. addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f - PathHelpers::ellipseAngularIncrement);
  71318. closeSubPath();
  71319. }
  71320. }
  71321. void Path::addPath (const Path& other)
  71322. {
  71323. size_t i = 0;
  71324. while (i < other.numElements)
  71325. {
  71326. const float type = other.data.elements [i++];
  71327. if (type == moveMarker)
  71328. {
  71329. startNewSubPath (other.data.elements [i],
  71330. other.data.elements [i + 1]);
  71331. i += 2;
  71332. }
  71333. else if (type == lineMarker)
  71334. {
  71335. lineTo (other.data.elements [i],
  71336. other.data.elements [i + 1]);
  71337. i += 2;
  71338. }
  71339. else if (type == quadMarker)
  71340. {
  71341. quadraticTo (other.data.elements [i],
  71342. other.data.elements [i + 1],
  71343. other.data.elements [i + 2],
  71344. other.data.elements [i + 3]);
  71345. i += 4;
  71346. }
  71347. else if (type == cubicMarker)
  71348. {
  71349. cubicTo (other.data.elements [i],
  71350. other.data.elements [i + 1],
  71351. other.data.elements [i + 2],
  71352. other.data.elements [i + 3],
  71353. other.data.elements [i + 4],
  71354. other.data.elements [i + 5]);
  71355. i += 6;
  71356. }
  71357. else if (type == closeSubPathMarker)
  71358. {
  71359. closeSubPath();
  71360. }
  71361. else
  71362. {
  71363. // something's gone wrong with the element list!
  71364. jassertfalse
  71365. }
  71366. }
  71367. }
  71368. void Path::addPath (const Path& other,
  71369. const AffineTransform& transformToApply)
  71370. {
  71371. size_t i = 0;
  71372. while (i < other.numElements)
  71373. {
  71374. const float type = other.data.elements [i++];
  71375. if (type == closeSubPathMarker)
  71376. {
  71377. closeSubPath();
  71378. }
  71379. else
  71380. {
  71381. float x = other.data.elements [i++];
  71382. float y = other.data.elements [i++];
  71383. transformToApply.transformPoint (x, y);
  71384. if (type == moveMarker)
  71385. {
  71386. startNewSubPath (x, y);
  71387. }
  71388. else if (type == lineMarker)
  71389. {
  71390. lineTo (x, y);
  71391. }
  71392. else if (type == quadMarker)
  71393. {
  71394. float x2 = other.data.elements [i++];
  71395. float y2 = other.data.elements [i++];
  71396. transformToApply.transformPoint (x2, y2);
  71397. quadraticTo (x, y, x2, y2);
  71398. }
  71399. else if (type == cubicMarker)
  71400. {
  71401. float x2 = other.data.elements [i++];
  71402. float y2 = other.data.elements [i++];
  71403. float x3 = other.data.elements [i++];
  71404. float y3 = other.data.elements [i++];
  71405. transformToApply.transformPoint (x2, y2);
  71406. transformToApply.transformPoint (x3, y3);
  71407. cubicTo (x, y, x2, y2, x3, y3);
  71408. }
  71409. else
  71410. {
  71411. // something's gone wrong with the element list!
  71412. jassertfalse
  71413. }
  71414. }
  71415. }
  71416. }
  71417. void Path::applyTransform (const AffineTransform& transform) throw()
  71418. {
  71419. size_t i = 0;
  71420. pathYMin = pathXMin = 0;
  71421. pathYMax = pathXMax = 0;
  71422. bool setMaxMin = false;
  71423. while (i < numElements)
  71424. {
  71425. const float type = data.elements [i++];
  71426. if (type == moveMarker)
  71427. {
  71428. transform.transformPoint (data.elements [i],
  71429. data.elements [i + 1]);
  71430. if (setMaxMin)
  71431. {
  71432. pathXMin = jmin (pathXMin, data.elements [i]);
  71433. pathXMax = jmax (pathXMax, data.elements [i]);
  71434. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71435. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71436. }
  71437. else
  71438. {
  71439. pathXMin = pathXMax = data.elements [i];
  71440. pathYMin = pathYMax = data.elements [i + 1];
  71441. setMaxMin = true;
  71442. }
  71443. i += 2;
  71444. }
  71445. else if (type == lineMarker)
  71446. {
  71447. transform.transformPoint (data.elements [i],
  71448. data.elements [i + 1]);
  71449. pathXMin = jmin (pathXMin, data.elements [i]);
  71450. pathXMax = jmax (pathXMax, data.elements [i]);
  71451. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71452. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71453. i += 2;
  71454. }
  71455. else if (type == quadMarker)
  71456. {
  71457. transform.transformPoint (data.elements [i],
  71458. data.elements [i + 1]);
  71459. transform.transformPoint (data.elements [i + 2],
  71460. data.elements [i + 3]);
  71461. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2]);
  71462. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2]);
  71463. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3]);
  71464. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3]);
  71465. i += 4;
  71466. }
  71467. else if (type == cubicMarker)
  71468. {
  71469. transform.transformPoint (data.elements [i],
  71470. data.elements [i + 1]);
  71471. transform.transformPoint (data.elements [i + 2],
  71472. data.elements [i + 3]);
  71473. transform.transformPoint (data.elements [i + 4],
  71474. data.elements [i + 5]);
  71475. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71476. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71477. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71478. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71479. i += 6;
  71480. }
  71481. }
  71482. }
  71483. const AffineTransform Path::getTransformToScaleToFit (const float x, const float y,
  71484. const float w, const float h,
  71485. const bool preserveProportions,
  71486. const Justification& justification) const
  71487. {
  71488. Rectangle<float> bounds (getBounds());
  71489. if (preserveProportions)
  71490. {
  71491. if (w <= 0 || h <= 0 || bounds.isEmpty())
  71492. return AffineTransform::identity;
  71493. float newW, newH;
  71494. const float srcRatio = bounds.getHeight() / bounds.getWidth();
  71495. if (srcRatio > h / w)
  71496. {
  71497. newW = h / srcRatio;
  71498. newH = h;
  71499. }
  71500. else
  71501. {
  71502. newW = w;
  71503. newH = w * srcRatio;
  71504. }
  71505. float newXCentre = x;
  71506. float newYCentre = y;
  71507. if (justification.testFlags (Justification::left))
  71508. newXCentre += newW * 0.5f;
  71509. else if (justification.testFlags (Justification::right))
  71510. newXCentre += w - newW * 0.5f;
  71511. else
  71512. newXCentre += w * 0.5f;
  71513. if (justification.testFlags (Justification::top))
  71514. newYCentre += newH * 0.5f;
  71515. else if (justification.testFlags (Justification::bottom))
  71516. newYCentre += h - newH * 0.5f;
  71517. else
  71518. newYCentre += h * 0.5f;
  71519. return AffineTransform::translation (bounds.getWidth() * -0.5f - bounds.getX(),
  71520. bounds.getHeight() * -0.5f - bounds.getY())
  71521. .scaled (newW / bounds.getWidth(), newH / bounds.getHeight())
  71522. .translated (newXCentre, newYCentre);
  71523. }
  71524. else
  71525. {
  71526. return AffineTransform::translation (-bounds.getX(), -bounds.getY())
  71527. .scaled (w / bounds.getWidth(), h / bounds.getHeight())
  71528. .translated (x, y);
  71529. }
  71530. }
  71531. bool Path::contains (const float x, const float y, const float tolerence) const
  71532. {
  71533. if (x <= pathXMin || x >= pathXMax
  71534. || y <= pathYMin || y >= pathYMax)
  71535. return false;
  71536. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  71537. int positiveCrossings = 0;
  71538. int negativeCrossings = 0;
  71539. while (i.next())
  71540. {
  71541. if ((i.y1 <= y && i.y2 > y)
  71542. || (i.y2 <= y && i.y1 > y))
  71543. {
  71544. const float intersectX = i.x1 + (i.x2 - i.x1) * (y - i.y1) / (i.y2 - i.y1);
  71545. if (intersectX <= x)
  71546. {
  71547. if (i.y1 < i.y2)
  71548. ++positiveCrossings;
  71549. else
  71550. ++negativeCrossings;
  71551. }
  71552. }
  71553. }
  71554. return (useNonZeroWinding) ? (negativeCrossings != positiveCrossings)
  71555. : ((negativeCrossings + positiveCrossings) & 1) != 0;
  71556. }
  71557. bool Path::intersectsLine (const float x1, const float y1,
  71558. const float x2, const float y2,
  71559. const float tolerence)
  71560. {
  71561. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  71562. const Line line1 (x1, y1, x2, y2);
  71563. while (i.next())
  71564. {
  71565. const Line line2 (i.x1, i.y1, i.x2, i.y2);
  71566. float ix, iy;
  71567. if (line1.intersects (line2, ix, iy))
  71568. return true;
  71569. }
  71570. return false;
  71571. }
  71572. const Path Path::createPathWithRoundedCorners (const float cornerRadius) const
  71573. {
  71574. if (cornerRadius <= 0.01f)
  71575. return *this;
  71576. int indexOfPathStart = 0, indexOfPathStartThis = 0;
  71577. size_t n = 0;
  71578. bool lastWasLine = false, firstWasLine = false;
  71579. Path p;
  71580. while (n < numElements)
  71581. {
  71582. const float type = data.elements [n++];
  71583. if (type == moveMarker)
  71584. {
  71585. indexOfPathStart = p.numElements;
  71586. indexOfPathStartThis = n - 1;
  71587. const float x = data.elements [n++];
  71588. const float y = data.elements [n++];
  71589. p.startNewSubPath (x, y);
  71590. lastWasLine = false;
  71591. firstWasLine = (data.elements [n] == lineMarker);
  71592. }
  71593. else if (type == lineMarker || type == closeSubPathMarker)
  71594. {
  71595. float startX = 0, startY = 0, joinX = 0, joinY = 0, endX, endY;
  71596. if (type == lineMarker)
  71597. {
  71598. endX = data.elements [n++];
  71599. endY = data.elements [n++];
  71600. if (n > 8)
  71601. {
  71602. startX = data.elements [n - 8];
  71603. startY = data.elements [n - 7];
  71604. joinX = data.elements [n - 5];
  71605. joinY = data.elements [n - 4];
  71606. }
  71607. }
  71608. else
  71609. {
  71610. endX = data.elements [indexOfPathStartThis + 1];
  71611. endY = data.elements [indexOfPathStartThis + 2];
  71612. if (n > 6)
  71613. {
  71614. startX = data.elements [n - 6];
  71615. startY = data.elements [n - 5];
  71616. joinX = data.elements [n - 3];
  71617. joinY = data.elements [n - 2];
  71618. }
  71619. }
  71620. if (lastWasLine)
  71621. {
  71622. const double len1 = juce_hypot (startX - joinX,
  71623. startY - joinY);
  71624. if (len1 > 0)
  71625. {
  71626. const double propNeeded = jmin (0.5, cornerRadius / len1);
  71627. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  71628. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  71629. }
  71630. const double len2 = juce_hypot (endX - joinX,
  71631. endY - joinY);
  71632. if (len2 > 0)
  71633. {
  71634. const double propNeeded = jmin (0.5, cornerRadius / len2);
  71635. p.quadraticTo (joinX, joinY,
  71636. (float) (joinX + (endX - joinX) * propNeeded),
  71637. (float) (joinY + (endY - joinY) * propNeeded));
  71638. }
  71639. p.lineTo (endX, endY);
  71640. }
  71641. else if (type == lineMarker)
  71642. {
  71643. p.lineTo (endX, endY);
  71644. lastWasLine = true;
  71645. }
  71646. if (type == closeSubPathMarker)
  71647. {
  71648. if (firstWasLine)
  71649. {
  71650. startX = data.elements [n - 3];
  71651. startY = data.elements [n - 2];
  71652. joinX = endX;
  71653. joinY = endY;
  71654. endX = data.elements [indexOfPathStartThis + 4];
  71655. endY = data.elements [indexOfPathStartThis + 5];
  71656. const double len1 = juce_hypot (startX - joinX,
  71657. startY - joinY);
  71658. if (len1 > 0)
  71659. {
  71660. const double propNeeded = jmin (0.5, cornerRadius / len1);
  71661. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  71662. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  71663. }
  71664. const double len2 = juce_hypot (endX - joinX,
  71665. endY - joinY);
  71666. if (len2 > 0)
  71667. {
  71668. const double propNeeded = jmin (0.5, cornerRadius / len2);
  71669. endX = (float) (joinX + (endX - joinX) * propNeeded);
  71670. endY = (float) (joinY + (endY - joinY) * propNeeded);
  71671. p.quadraticTo (joinX, joinY, endX, endY);
  71672. p.data.elements [indexOfPathStart + 1] = endX;
  71673. p.data.elements [indexOfPathStart + 2] = endY;
  71674. }
  71675. }
  71676. p.closeSubPath();
  71677. }
  71678. }
  71679. else if (type == quadMarker)
  71680. {
  71681. lastWasLine = false;
  71682. const float x1 = data.elements [n++];
  71683. const float y1 = data.elements [n++];
  71684. const float x2 = data.elements [n++];
  71685. const float y2 = data.elements [n++];
  71686. p.quadraticTo (x1, y1, x2, y2);
  71687. }
  71688. else if (type == cubicMarker)
  71689. {
  71690. lastWasLine = false;
  71691. const float x1 = data.elements [n++];
  71692. const float y1 = data.elements [n++];
  71693. const float x2 = data.elements [n++];
  71694. const float y2 = data.elements [n++];
  71695. const float x3 = data.elements [n++];
  71696. const float y3 = data.elements [n++];
  71697. p.cubicTo (x1, y1, x2, y2, x3, y3);
  71698. }
  71699. }
  71700. return p;
  71701. }
  71702. void Path::loadPathFromStream (InputStream& source)
  71703. {
  71704. while (! source.isExhausted())
  71705. {
  71706. switch (source.readByte())
  71707. {
  71708. case 'm':
  71709. {
  71710. const float x = source.readFloat();
  71711. const float y = source.readFloat();
  71712. startNewSubPath (x, y);
  71713. break;
  71714. }
  71715. case 'l':
  71716. {
  71717. const float x = source.readFloat();
  71718. const float y = source.readFloat();
  71719. lineTo (x, y);
  71720. break;
  71721. }
  71722. case 'q':
  71723. {
  71724. const float x1 = source.readFloat();
  71725. const float y1 = source.readFloat();
  71726. const float x2 = source.readFloat();
  71727. const float y2 = source.readFloat();
  71728. quadraticTo (x1, y1, x2, y2);
  71729. break;
  71730. }
  71731. case 'b':
  71732. {
  71733. const float x1 = source.readFloat();
  71734. const float y1 = source.readFloat();
  71735. const float x2 = source.readFloat();
  71736. const float y2 = source.readFloat();
  71737. const float x3 = source.readFloat();
  71738. const float y3 = source.readFloat();
  71739. cubicTo (x1, y1, x2, y2, x3, y3);
  71740. break;
  71741. }
  71742. case 'c':
  71743. closeSubPath();
  71744. break;
  71745. case 'n':
  71746. useNonZeroWinding = true;
  71747. break;
  71748. case 'z':
  71749. useNonZeroWinding = false;
  71750. break;
  71751. case 'e':
  71752. return; // end of path marker
  71753. default:
  71754. jassertfalse // illegal char in the stream
  71755. break;
  71756. }
  71757. }
  71758. }
  71759. void Path::loadPathFromData (const void* const data, const int numberOfBytes)
  71760. {
  71761. MemoryInputStream in (data, numberOfBytes, false);
  71762. loadPathFromStream (in);
  71763. }
  71764. void Path::writePathToStream (OutputStream& dest) const
  71765. {
  71766. dest.writeByte (useNonZeroWinding ? 'n' : 'z');
  71767. size_t i = 0;
  71768. while (i < numElements)
  71769. {
  71770. const float type = data.elements [i++];
  71771. if (type == moveMarker)
  71772. {
  71773. dest.writeByte ('m');
  71774. dest.writeFloat (data.elements [i++]);
  71775. dest.writeFloat (data.elements [i++]);
  71776. }
  71777. else if (type == lineMarker)
  71778. {
  71779. dest.writeByte ('l');
  71780. dest.writeFloat (data.elements [i++]);
  71781. dest.writeFloat (data.elements [i++]);
  71782. }
  71783. else if (type == quadMarker)
  71784. {
  71785. dest.writeByte ('q');
  71786. dest.writeFloat (data.elements [i++]);
  71787. dest.writeFloat (data.elements [i++]);
  71788. dest.writeFloat (data.elements [i++]);
  71789. dest.writeFloat (data.elements [i++]);
  71790. }
  71791. else if (type == cubicMarker)
  71792. {
  71793. dest.writeByte ('b');
  71794. dest.writeFloat (data.elements [i++]);
  71795. dest.writeFloat (data.elements [i++]);
  71796. dest.writeFloat (data.elements [i++]);
  71797. dest.writeFloat (data.elements [i++]);
  71798. dest.writeFloat (data.elements [i++]);
  71799. dest.writeFloat (data.elements [i++]);
  71800. }
  71801. else if (type == closeSubPathMarker)
  71802. {
  71803. dest.writeByte ('c');
  71804. }
  71805. }
  71806. dest.writeByte ('e'); // marks the end-of-path
  71807. }
  71808. const String Path::toString() const
  71809. {
  71810. MemoryOutputStream s (2048, 2048);
  71811. if (! useNonZeroWinding)
  71812. s << "a ";
  71813. size_t i = 0;
  71814. float lastMarker = 0.0f;
  71815. while (i < numElements)
  71816. {
  71817. const float marker = data.elements [i++];
  71818. char markerChar = 0;
  71819. int numCoords = 0;
  71820. if (marker == moveMarker)
  71821. {
  71822. markerChar = 'm';
  71823. numCoords = 2;
  71824. }
  71825. else if (marker == lineMarker)
  71826. {
  71827. markerChar = 'l';
  71828. numCoords = 2;
  71829. }
  71830. else if (marker == quadMarker)
  71831. {
  71832. markerChar = 'q';
  71833. numCoords = 4;
  71834. }
  71835. else if (marker == cubicMarker)
  71836. {
  71837. markerChar = 'c';
  71838. numCoords = 6;
  71839. }
  71840. else
  71841. {
  71842. jassert (marker == closeSubPathMarker);
  71843. markerChar = 'z';
  71844. }
  71845. if (marker != lastMarker)
  71846. {
  71847. s << markerChar << ' ';
  71848. lastMarker = marker;
  71849. }
  71850. while (--numCoords >= 0 && i < numElements)
  71851. {
  71852. String n (data.elements [i++], 3);
  71853. if (n.endsWithChar ('0'))
  71854. {
  71855. do
  71856. {
  71857. n = n.dropLastCharacters (1);
  71858. } while (n.endsWithChar ('0'));
  71859. if (n.endsWithChar ('.'))
  71860. n = n.dropLastCharacters (1);
  71861. }
  71862. s << n << ' ';
  71863. }
  71864. }
  71865. const char* const result = (const char*) s.getData();
  71866. size_t len = s.getDataSize();
  71867. while (len > 0 && CharacterFunctions::isWhitespace (result [len - 1]))
  71868. --len;
  71869. return String (result, len);
  71870. }
  71871. void Path::restoreFromString (const String& stringVersion)
  71872. {
  71873. clear();
  71874. setUsingNonZeroWinding (true);
  71875. const juce_wchar* t = stringVersion;
  71876. juce_wchar marker = 'm';
  71877. int numValues = 2;
  71878. float values [6];
  71879. while (*t != 0)
  71880. {
  71881. const String token (PathHelpers::nextToken (t));
  71882. const tchar firstChar = token[0];
  71883. int startNum = 0;
  71884. if (firstChar == 'm' || firstChar == 'l')
  71885. {
  71886. marker = firstChar;
  71887. numValues = 2;
  71888. }
  71889. else if (firstChar == 'q')
  71890. {
  71891. marker = firstChar;
  71892. numValues = 4;
  71893. }
  71894. else if (firstChar == 'c')
  71895. {
  71896. marker = firstChar;
  71897. numValues = 6;
  71898. }
  71899. else if (firstChar == 'z')
  71900. {
  71901. marker = firstChar;
  71902. numValues = 0;
  71903. }
  71904. else if (firstChar == 'a')
  71905. {
  71906. setUsingNonZeroWinding (false);
  71907. continue;
  71908. }
  71909. else
  71910. {
  71911. ++startNum;
  71912. values [0] = token.getFloatValue();
  71913. }
  71914. for (int i = startNum; i < numValues; ++i)
  71915. values [i] = PathHelpers::nextToken (t).getFloatValue();
  71916. switch (marker)
  71917. {
  71918. case 'm':
  71919. startNewSubPath (values[0], values[1]);
  71920. break;
  71921. case 'l':
  71922. lineTo (values[0], values[1]);
  71923. break;
  71924. case 'q':
  71925. quadraticTo (values[0], values[1],
  71926. values[2], values[3]);
  71927. break;
  71928. case 'c':
  71929. cubicTo (values[0], values[1],
  71930. values[2], values[3],
  71931. values[4], values[5]);
  71932. break;
  71933. case 'z':
  71934. closeSubPath();
  71935. break;
  71936. default:
  71937. jassertfalse // illegal string format?
  71938. break;
  71939. }
  71940. }
  71941. }
  71942. Path::Iterator::Iterator (const Path& path_)
  71943. : path (path_),
  71944. index (0)
  71945. {
  71946. }
  71947. Path::Iterator::~Iterator()
  71948. {
  71949. }
  71950. bool Path::Iterator::next()
  71951. {
  71952. const float* const elements = path.data.elements;
  71953. if (index < path.numElements)
  71954. {
  71955. const float type = elements [index++];
  71956. if (type == moveMarker)
  71957. {
  71958. elementType = startNewSubPath;
  71959. x1 = elements [index++];
  71960. y1 = elements [index++];
  71961. }
  71962. else if (type == lineMarker)
  71963. {
  71964. elementType = lineTo;
  71965. x1 = elements [index++];
  71966. y1 = elements [index++];
  71967. }
  71968. else if (type == quadMarker)
  71969. {
  71970. elementType = quadraticTo;
  71971. x1 = elements [index++];
  71972. y1 = elements [index++];
  71973. x2 = elements [index++];
  71974. y2 = elements [index++];
  71975. }
  71976. else if (type == cubicMarker)
  71977. {
  71978. elementType = cubicTo;
  71979. x1 = elements [index++];
  71980. y1 = elements [index++];
  71981. x2 = elements [index++];
  71982. y2 = elements [index++];
  71983. x3 = elements [index++];
  71984. y3 = elements [index++];
  71985. }
  71986. else if (type == closeSubPathMarker)
  71987. {
  71988. elementType = closePath;
  71989. }
  71990. return true;
  71991. }
  71992. return false;
  71993. }
  71994. END_JUCE_NAMESPACE
  71995. /*** End of inlined file: juce_Path.cpp ***/
  71996. /*** Start of inlined file: juce_PathIterator.cpp ***/
  71997. BEGIN_JUCE_NAMESPACE
  71998. #if JUCE_MSVC
  71999. #pragma optimize ("t", on)
  72000. #endif
  72001. PathFlatteningIterator::PathFlatteningIterator (const Path& path_,
  72002. const AffineTransform& transform_,
  72003. float tolerence_)
  72004. : x2 (0),
  72005. y2 (0),
  72006. closesSubPath (false),
  72007. subPathIndex (-1),
  72008. path (path_),
  72009. transform (transform_),
  72010. points (path_.data.elements),
  72011. tolerence (tolerence_ * tolerence_),
  72012. subPathCloseX (0),
  72013. subPathCloseY (0),
  72014. isIdentityTransform (transform_.isIdentity()),
  72015. stackBase (32),
  72016. index (0),
  72017. stackSize (32)
  72018. {
  72019. stackPos = stackBase;
  72020. }
  72021. PathFlatteningIterator::~PathFlatteningIterator()
  72022. {
  72023. }
  72024. bool PathFlatteningIterator::next()
  72025. {
  72026. x1 = x2;
  72027. y1 = y2;
  72028. float x3 = 0;
  72029. float y3 = 0;
  72030. float x4 = 0;
  72031. float y4 = 0;
  72032. float type;
  72033. for (;;)
  72034. {
  72035. if (stackPos == stackBase)
  72036. {
  72037. if (index >= path.numElements)
  72038. {
  72039. return false;
  72040. }
  72041. else
  72042. {
  72043. type = points [index++];
  72044. if (type != Path::closeSubPathMarker)
  72045. {
  72046. x2 = points [index++];
  72047. y2 = points [index++];
  72048. if (! isIdentityTransform)
  72049. transform.transformPoint (x2, y2);
  72050. if (type == Path::quadMarker)
  72051. {
  72052. x3 = points [index++];
  72053. y3 = points [index++];
  72054. if (! isIdentityTransform)
  72055. transform.transformPoint (x3, y3);
  72056. }
  72057. else if (type == Path::cubicMarker)
  72058. {
  72059. x3 = points [index++];
  72060. y3 = points [index++];
  72061. x4 = points [index++];
  72062. y4 = points [index++];
  72063. if (! isIdentityTransform)
  72064. {
  72065. transform.transformPoint (x3, y3);
  72066. transform.transformPoint (x4, y4);
  72067. }
  72068. }
  72069. }
  72070. }
  72071. }
  72072. else
  72073. {
  72074. type = *--stackPos;
  72075. if (type != Path::closeSubPathMarker)
  72076. {
  72077. x2 = *--stackPos;
  72078. y2 = *--stackPos;
  72079. if (type == Path::quadMarker)
  72080. {
  72081. x3 = *--stackPos;
  72082. y3 = *--stackPos;
  72083. }
  72084. else if (type == Path::cubicMarker)
  72085. {
  72086. x3 = *--stackPos;
  72087. y3 = *--stackPos;
  72088. x4 = *--stackPos;
  72089. y4 = *--stackPos;
  72090. }
  72091. }
  72092. }
  72093. if (type == Path::lineMarker)
  72094. {
  72095. ++subPathIndex;
  72096. closesSubPath = (stackPos == stackBase)
  72097. && (index < path.numElements)
  72098. && (points [index] == Path::closeSubPathMarker)
  72099. && x2 == subPathCloseX
  72100. && y2 == subPathCloseY;
  72101. return true;
  72102. }
  72103. else if (type == Path::quadMarker)
  72104. {
  72105. const size_t offset = (size_t) (stackPos - stackBase);
  72106. if (offset >= stackSize - 10)
  72107. {
  72108. stackSize <<= 1;
  72109. stackBase.realloc (stackSize);
  72110. stackPos = stackBase + offset;
  72111. }
  72112. const float dx1 = x1 - x2;
  72113. const float dy1 = y1 - y2;
  72114. const float dx2 = x2 - x3;
  72115. const float dy2 = y2 - y3;
  72116. const float m1x = (x1 + x2) * 0.5f;
  72117. const float m1y = (y1 + y2) * 0.5f;
  72118. const float m2x = (x2 + x3) * 0.5f;
  72119. const float m2y = (y2 + y3) * 0.5f;
  72120. const float m3x = (m1x + m2x) * 0.5f;
  72121. const float m3y = (m1y + m2y) * 0.5f;
  72122. if (dx1*dx1 + dy1*dy1 + dx2*dx2 + dy2*dy2 > tolerence)
  72123. {
  72124. *stackPos++ = y3;
  72125. *stackPos++ = x3;
  72126. *stackPos++ = m2y;
  72127. *stackPos++ = m2x;
  72128. *stackPos++ = Path::quadMarker;
  72129. *stackPos++ = m3y;
  72130. *stackPos++ = m3x;
  72131. *stackPos++ = m1y;
  72132. *stackPos++ = m1x;
  72133. *stackPos++ = Path::quadMarker;
  72134. }
  72135. else
  72136. {
  72137. *stackPos++ = y3;
  72138. *stackPos++ = x3;
  72139. *stackPos++ = Path::lineMarker;
  72140. *stackPos++ = m3y;
  72141. *stackPos++ = m3x;
  72142. *stackPos++ = Path::lineMarker;
  72143. }
  72144. jassert (stackPos < stackBase + stackSize);
  72145. }
  72146. else if (type == Path::cubicMarker)
  72147. {
  72148. const size_t offset = (size_t) (stackPos - stackBase);
  72149. if (offset >= stackSize - 16)
  72150. {
  72151. stackSize <<= 1;
  72152. stackBase.realloc (stackSize);
  72153. stackPos = stackBase + offset;
  72154. }
  72155. const float dx1 = x1 - x2;
  72156. const float dy1 = y1 - y2;
  72157. const float dx2 = x2 - x3;
  72158. const float dy2 = y2 - y3;
  72159. const float dx3 = x3 - x4;
  72160. const float dy3 = y3 - y4;
  72161. const float m1x = (x1 + x2) * 0.5f;
  72162. const float m1y = (y1 + y2) * 0.5f;
  72163. const float m2x = (x3 + x2) * 0.5f;
  72164. const float m2y = (y3 + y2) * 0.5f;
  72165. const float m3x = (x3 + x4) * 0.5f;
  72166. const float m3y = (y3 + y4) * 0.5f;
  72167. const float m4x = (m1x + m2x) * 0.5f;
  72168. const float m4y = (m1y + m2y) * 0.5f;
  72169. const float m5x = (m3x + m2x) * 0.5f;
  72170. const float m5y = (m3y + m2y) * 0.5f;
  72171. if (dx1*dx1 + dy1*dy1 + dx2*dx2
  72172. + dy2*dy2 + dx3*dx3 + dy3*dy3 > tolerence)
  72173. {
  72174. *stackPos++ = y4;
  72175. *stackPos++ = x4;
  72176. *stackPos++ = m3y;
  72177. *stackPos++ = m3x;
  72178. *stackPos++ = m5y;
  72179. *stackPos++ = m5x;
  72180. *stackPos++ = Path::cubicMarker;
  72181. *stackPos++ = (m4y + m5y) * 0.5f;
  72182. *stackPos++ = (m4x + m5x) * 0.5f;
  72183. *stackPos++ = m4y;
  72184. *stackPos++ = m4x;
  72185. *stackPos++ = m1y;
  72186. *stackPos++ = m1x;
  72187. *stackPos++ = Path::cubicMarker;
  72188. }
  72189. else
  72190. {
  72191. *stackPos++ = y4;
  72192. *stackPos++ = x4;
  72193. *stackPos++ = Path::lineMarker;
  72194. *stackPos++ = m5y;
  72195. *stackPos++ = m5x;
  72196. *stackPos++ = Path::lineMarker;
  72197. *stackPos++ = m4y;
  72198. *stackPos++ = m4x;
  72199. *stackPos++ = Path::lineMarker;
  72200. }
  72201. }
  72202. else if (type == Path::closeSubPathMarker)
  72203. {
  72204. if (x2 != subPathCloseX || y2 != subPathCloseY)
  72205. {
  72206. x1 = x2;
  72207. y1 = y2;
  72208. x2 = subPathCloseX;
  72209. y2 = subPathCloseY;
  72210. closesSubPath = true;
  72211. return true;
  72212. }
  72213. }
  72214. else
  72215. {
  72216. jassert (type == Path::moveMarker);
  72217. subPathIndex = -1;
  72218. subPathCloseX = x1 = x2;
  72219. subPathCloseY = y1 = y2;
  72220. }
  72221. }
  72222. }
  72223. END_JUCE_NAMESPACE
  72224. /*** End of inlined file: juce_PathIterator.cpp ***/
  72225. /*** Start of inlined file: juce_PathStrokeType.cpp ***/
  72226. BEGIN_JUCE_NAMESPACE
  72227. PathStrokeType::PathStrokeType (const float strokeThickness,
  72228. const JointStyle jointStyle_,
  72229. const EndCapStyle endStyle_) throw()
  72230. : thickness (strokeThickness),
  72231. jointStyle (jointStyle_),
  72232. endStyle (endStyle_)
  72233. {
  72234. }
  72235. PathStrokeType::PathStrokeType (const PathStrokeType& other) throw()
  72236. : thickness (other.thickness),
  72237. jointStyle (other.jointStyle),
  72238. endStyle (other.endStyle)
  72239. {
  72240. }
  72241. PathStrokeType& PathStrokeType::operator= (const PathStrokeType& other) throw()
  72242. {
  72243. thickness = other.thickness;
  72244. jointStyle = other.jointStyle;
  72245. endStyle = other.endStyle;
  72246. return *this;
  72247. }
  72248. PathStrokeType::~PathStrokeType() throw()
  72249. {
  72250. }
  72251. bool PathStrokeType::operator== (const PathStrokeType& other) const throw()
  72252. {
  72253. return thickness == other.thickness
  72254. && jointStyle == other.jointStyle
  72255. && endStyle == other.endStyle;
  72256. }
  72257. bool PathStrokeType::operator!= (const PathStrokeType& other) const throw()
  72258. {
  72259. return ! operator== (other);
  72260. }
  72261. static bool lineIntersection (const float x1, const float y1,
  72262. const float x2, const float y2,
  72263. const float x3, const float y3,
  72264. const float x4, const float y4,
  72265. float& intersectionX,
  72266. float& intersectionY,
  72267. float& distanceBeyondLine1EndSquared) throw()
  72268. {
  72269. if (x2 != x3 || y2 != y3)
  72270. {
  72271. const float dx1 = x2 - x1;
  72272. const float dy1 = y2 - y1;
  72273. const float dx2 = x4 - x3;
  72274. const float dy2 = y4 - y3;
  72275. const float divisor = dx1 * dy2 - dx2 * dy1;
  72276. if (divisor == 0)
  72277. {
  72278. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  72279. {
  72280. if (dy1 == 0 && dy2 != 0)
  72281. {
  72282. const float along = (y1 - y3) / dy2;
  72283. intersectionX = x3 + along * dx2;
  72284. intersectionY = y1;
  72285. distanceBeyondLine1EndSquared = intersectionX - x2;
  72286. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72287. if ((x2 > x1) == (intersectionX < x2))
  72288. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72289. return along >= 0 && along <= 1.0f;
  72290. }
  72291. else if (dy2 == 0 && dy1 != 0)
  72292. {
  72293. const float along = (y3 - y1) / dy1;
  72294. intersectionX = x1 + along * dx1;
  72295. intersectionY = y3;
  72296. distanceBeyondLine1EndSquared = (along - 1.0f) * dx1;
  72297. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72298. if (along < 1.0f)
  72299. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72300. return along >= 0 && along <= 1.0f;
  72301. }
  72302. else if (dx1 == 0 && dx2 != 0)
  72303. {
  72304. const float along = (x1 - x3) / dx2;
  72305. intersectionX = x1;
  72306. intersectionY = y3 + along * dy2;
  72307. distanceBeyondLine1EndSquared = intersectionY - y2;
  72308. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72309. if ((y2 > y1) == (intersectionY < y2))
  72310. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72311. return along >= 0 && along <= 1.0f;
  72312. }
  72313. else if (dx2 == 0 && dx1 != 0)
  72314. {
  72315. const float along = (x3 - x1) / dx1;
  72316. intersectionX = x3;
  72317. intersectionY = y1 + along * dy1;
  72318. distanceBeyondLine1EndSquared = (along - 1.0f) * dy1;
  72319. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72320. if (along < 1.0f)
  72321. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72322. return along >= 0 && along <= 1.0f;
  72323. }
  72324. }
  72325. intersectionX = 0.5f * (x2 + x3);
  72326. intersectionY = 0.5f * (y2 + y3);
  72327. distanceBeyondLine1EndSquared = 0.0f;
  72328. return false;
  72329. }
  72330. else
  72331. {
  72332. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  72333. intersectionX = x1 + along1 * dx1;
  72334. intersectionY = y1 + along1 * dy1;
  72335. if (along1 >= 0 && along1 <= 1.0f)
  72336. {
  72337. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1);
  72338. if (along2 >= 0 && along2 <= divisor)
  72339. {
  72340. distanceBeyondLine1EndSquared = 0.0f;
  72341. return true;
  72342. }
  72343. }
  72344. distanceBeyondLine1EndSquared = along1 - 1.0f;
  72345. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72346. distanceBeyondLine1EndSquared *= (dx1 * dx1 + dy1 * dy1);
  72347. if (along1 < 1.0f)
  72348. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72349. return false;
  72350. }
  72351. }
  72352. intersectionX = x2;
  72353. intersectionY = y2;
  72354. distanceBeyondLine1EndSquared = 0.0f;
  72355. return true;
  72356. }
  72357. namespace PathFunctions
  72358. {
  72359. // part of stroke drawing stuff
  72360. static void addEdgeAndJoint (Path& destPath,
  72361. const PathStrokeType::JointStyle style,
  72362. const float maxMiterExtensionSquared, const float width,
  72363. const float x1, const float y1,
  72364. const float x2, const float y2,
  72365. const float x3, const float y3,
  72366. const float x4, const float y4,
  72367. const float midX, const float midY)
  72368. {
  72369. if (style == PathStrokeType::beveled
  72370. || (x3 == x4 && y3 == y4)
  72371. || (x1 == x2 && y1 == y2))
  72372. {
  72373. destPath.lineTo (x2, y2);
  72374. destPath.lineTo (x3, y3);
  72375. }
  72376. else
  72377. {
  72378. float jx, jy, distanceBeyondLine1EndSquared;
  72379. // if they intersect, use this point..
  72380. if (lineIntersection (x1, y1, x2, y2,
  72381. x3, y3, x4, y4,
  72382. jx, jy, distanceBeyondLine1EndSquared))
  72383. {
  72384. destPath.lineTo (jx, jy);
  72385. }
  72386. else
  72387. {
  72388. if (style == PathStrokeType::mitered)
  72389. {
  72390. if (distanceBeyondLine1EndSquared < maxMiterExtensionSquared
  72391. && distanceBeyondLine1EndSquared > 0.0f)
  72392. {
  72393. destPath.lineTo (jx, jy);
  72394. }
  72395. else
  72396. {
  72397. // the end sticks out too far, so just use a blunt joint
  72398. destPath.lineTo (x2, y2);
  72399. destPath.lineTo (x3, y3);
  72400. }
  72401. }
  72402. else
  72403. {
  72404. // curved joints
  72405. float angle1 = atan2f (x2 - midX, y2 - midY);
  72406. float angle2 = atan2f (x3 - midX, y3 - midY);
  72407. const float angleIncrement = 0.1f;
  72408. destPath.lineTo (x2, y2);
  72409. if (fabs (angle1 - angle2) > angleIncrement)
  72410. {
  72411. if (angle2 > angle1 + float_Pi
  72412. || (angle2 < angle1 && angle2 >= angle1 - float_Pi))
  72413. {
  72414. if (angle2 > angle1)
  72415. angle2 -= float_Pi * 2.0f;
  72416. jassert (angle1 <= angle2 + float_Pi);
  72417. angle1 -= angleIncrement;
  72418. while (angle1 > angle2)
  72419. {
  72420. destPath.lineTo (midX + width * sinf (angle1),
  72421. midY + width * cosf (angle1));
  72422. angle1 -= angleIncrement;
  72423. }
  72424. }
  72425. else
  72426. {
  72427. if (angle1 > angle2)
  72428. angle1 -= float_Pi * 2.0f;
  72429. jassert (angle1 >= angle2 - float_Pi);
  72430. angle1 += angleIncrement;
  72431. while (angle1 < angle2)
  72432. {
  72433. destPath.lineTo (midX + width * sinf (angle1),
  72434. midY + width * cosf (angle1));
  72435. angle1 += angleIncrement;
  72436. }
  72437. }
  72438. }
  72439. destPath.lineTo (x3, y3);
  72440. }
  72441. }
  72442. }
  72443. }
  72444. static void addLineEnd (Path& destPath,
  72445. const PathStrokeType::EndCapStyle style,
  72446. const float x1, const float y1,
  72447. const float x2, const float y2,
  72448. const float width)
  72449. {
  72450. if (style == PathStrokeType::butt)
  72451. {
  72452. destPath.lineTo (x2, y2);
  72453. }
  72454. else
  72455. {
  72456. float offx1, offy1, offx2, offy2;
  72457. float dx = x2 - x1;
  72458. float dy = y2 - y1;
  72459. const float len = juce_hypotf (dx, dy);
  72460. if (len == 0)
  72461. {
  72462. offx1 = offx2 = x1;
  72463. offy1 = offy2 = y1;
  72464. }
  72465. else
  72466. {
  72467. const float offset = width / len;
  72468. dx *= offset;
  72469. dy *= offset;
  72470. offx1 = x1 + dy;
  72471. offy1 = y1 - dx;
  72472. offx2 = x2 + dy;
  72473. offy2 = y2 - dx;
  72474. }
  72475. if (style == PathStrokeType::square)
  72476. {
  72477. // sqaure ends
  72478. destPath.lineTo (offx1, offy1);
  72479. destPath.lineTo (offx2, offy2);
  72480. destPath.lineTo (x2, y2);
  72481. }
  72482. else
  72483. {
  72484. // rounded ends
  72485. const float midx = (offx1 + offx2) * 0.5f;
  72486. const float midy = (offy1 + offy2) * 0.5f;
  72487. destPath.cubicTo (x1 + (offx1 - x1) * 0.55f, y1 + (offy1 - y1) * 0.55f,
  72488. offx1 + (midx - offx1) * 0.45f, offy1 + (midy - offy1) * 0.45f,
  72489. midx, midy);
  72490. destPath.cubicTo (midx + (offx2 - midx) * 0.55f, midy + (offy2 - midy) * 0.55f,
  72491. offx2 + (x2 - offx2) * 0.45f, offy2 + (y2 - offy2) * 0.45f,
  72492. x2, y2);
  72493. }
  72494. }
  72495. }
  72496. struct LineSection
  72497. {
  72498. LineSection() {}
  72499. LineSection (int) {}
  72500. float x1, y1, x2, y2; // original line
  72501. float lx1, ly1, lx2, ly2; // the left-hand stroke
  72502. float rx1, ry1, rx2, ry2; // the right-hand stroke
  72503. };
  72504. static void addSubPath (Path& destPath, const Array <LineSection>& subPath,
  72505. const bool isClosed,
  72506. const float width, const float maxMiterExtensionSquared,
  72507. const PathStrokeType::JointStyle jointStyle, const PathStrokeType::EndCapStyle endStyle)
  72508. {
  72509. jassert (subPath.size() > 0);
  72510. const LineSection& firstLine = subPath.getReference (0);
  72511. float lastX1 = firstLine.lx1;
  72512. float lastY1 = firstLine.ly1;
  72513. float lastX2 = firstLine.lx2;
  72514. float lastY2 = firstLine.ly2;
  72515. if (isClosed)
  72516. {
  72517. destPath.startNewSubPath (lastX1, lastY1);
  72518. }
  72519. else
  72520. {
  72521. destPath.startNewSubPath (firstLine.rx2, firstLine.ry2);
  72522. addLineEnd (destPath, endStyle,
  72523. firstLine.rx2, firstLine.ry2,
  72524. lastX1, lastY1,
  72525. width);
  72526. }
  72527. int i;
  72528. for (i = 1; i < subPath.size(); ++i)
  72529. {
  72530. const LineSection& l = subPath.getReference (i);
  72531. addEdgeAndJoint (destPath, jointStyle,
  72532. maxMiterExtensionSquared, width,
  72533. lastX1, lastY1, lastX2, lastY2,
  72534. l.lx1, l.ly1, l.lx2, l.ly2,
  72535. l.x1, l.y1);
  72536. lastX1 = l.lx1;
  72537. lastY1 = l.ly1;
  72538. lastX2 = l.lx2;
  72539. lastY2 = l.ly2;
  72540. }
  72541. const LineSection& lastLine = subPath.getReference (subPath.size() - 1);
  72542. if (isClosed)
  72543. {
  72544. const LineSection& l = subPath.getReference (0);
  72545. addEdgeAndJoint (destPath, jointStyle,
  72546. maxMiterExtensionSquared, width,
  72547. lastX1, lastY1, lastX2, lastY2,
  72548. l.lx1, l.ly1, l.lx2, l.ly2,
  72549. l.x1, l.y1);
  72550. destPath.closeSubPath();
  72551. destPath.startNewSubPath (lastLine.rx1, lastLine.ry1);
  72552. }
  72553. else
  72554. {
  72555. destPath.lineTo (lastX2, lastY2);
  72556. addLineEnd (destPath, endStyle,
  72557. lastX2, lastY2,
  72558. lastLine.rx1, lastLine.ry1,
  72559. width);
  72560. }
  72561. lastX1 = lastLine.rx1;
  72562. lastY1 = lastLine.ry1;
  72563. lastX2 = lastLine.rx2;
  72564. lastY2 = lastLine.ry2;
  72565. for (i = subPath.size() - 1; --i >= 0;)
  72566. {
  72567. const LineSection& l = subPath.getReference (i);
  72568. addEdgeAndJoint (destPath, jointStyle,
  72569. maxMiterExtensionSquared, width,
  72570. lastX1, lastY1, lastX2, lastY2,
  72571. l.rx1, l.ry1, l.rx2, l.ry2,
  72572. l.x2, l.y2);
  72573. lastX1 = l.rx1;
  72574. lastY1 = l.ry1;
  72575. lastX2 = l.rx2;
  72576. lastY2 = l.ry2;
  72577. }
  72578. if (isClosed)
  72579. {
  72580. addEdgeAndJoint (destPath, jointStyle,
  72581. maxMiterExtensionSquared, width,
  72582. lastX1, lastY1, lastX2, lastY2,
  72583. lastLine.rx1, lastLine.ry1, lastLine.rx2, lastLine.ry2,
  72584. lastLine.x2, lastLine.y2);
  72585. }
  72586. else
  72587. {
  72588. // do the last line
  72589. destPath.lineTo (lastX2, lastY2);
  72590. }
  72591. destPath.closeSubPath();
  72592. }
  72593. }
  72594. void PathStrokeType::createStrokedPath (Path& destPath,
  72595. const Path& source,
  72596. const AffineTransform& transform,
  72597. const float extraAccuracy) const
  72598. {
  72599. if (thickness <= 0)
  72600. {
  72601. destPath.clear();
  72602. return;
  72603. }
  72604. const Path* sourcePath = &source;
  72605. Path temp;
  72606. if (sourcePath == &destPath)
  72607. {
  72608. destPath.swapWithPath (temp);
  72609. sourcePath = &temp;
  72610. }
  72611. else
  72612. {
  72613. destPath.clear();
  72614. }
  72615. destPath.setUsingNonZeroWinding (true);
  72616. const float maxMiterExtensionSquared = 9.0f * thickness * thickness;
  72617. const float width = 0.5f * thickness;
  72618. // Iterate the path, creating a list of the
  72619. // left/right-hand lines along either side of it...
  72620. PathFlatteningIterator it (*sourcePath, transform, 9.0f / extraAccuracy);
  72621. using namespace PathFunctions;
  72622. Array <LineSection> subPath;
  72623. LineSection l;
  72624. l.x1 = 0;
  72625. l.y1 = 0;
  72626. const float minSegmentLength = 2.0f / (extraAccuracy * extraAccuracy);
  72627. while (it.next())
  72628. {
  72629. if (it.subPathIndex == 0)
  72630. {
  72631. if (subPath.size() > 0)
  72632. {
  72633. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72634. subPath.clearQuick();
  72635. }
  72636. l.x1 = it.x1;
  72637. l.y1 = it.y1;
  72638. }
  72639. l.x2 = it.x2;
  72640. l.y2 = it.y2;
  72641. float dx = l.x2 - l.x1;
  72642. float dy = l.y2 - l.y1;
  72643. const float hypotSquared = dx*dx + dy*dy;
  72644. if (it.closesSubPath || hypotSquared > minSegmentLength || it.isLastInSubpath())
  72645. {
  72646. const float len = sqrtf (hypotSquared);
  72647. if (len == 0)
  72648. {
  72649. l.rx1 = l.rx2 = l.lx1 = l.lx2 = l.x1;
  72650. l.ry1 = l.ry2 = l.ly1 = l.ly2 = l.y1;
  72651. }
  72652. else
  72653. {
  72654. const float offset = width / len;
  72655. dx *= offset;
  72656. dy *= offset;
  72657. l.rx2 = l.x1 - dy;
  72658. l.ry2 = l.y1 + dx;
  72659. l.lx1 = l.x1 + dy;
  72660. l.ly1 = l.y1 - dx;
  72661. l.lx2 = l.x2 + dy;
  72662. l.ly2 = l.y2 - dx;
  72663. l.rx1 = l.x2 - dy;
  72664. l.ry1 = l.y2 + dx;
  72665. }
  72666. subPath.add (l);
  72667. if (it.closesSubPath)
  72668. {
  72669. addSubPath (destPath, subPath, true, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72670. subPath.clearQuick();
  72671. }
  72672. else
  72673. {
  72674. l.x1 = it.x2;
  72675. l.y1 = it.y2;
  72676. }
  72677. }
  72678. }
  72679. if (subPath.size() > 0)
  72680. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72681. }
  72682. void PathStrokeType::createDashedStroke (Path& destPath,
  72683. const Path& sourcePath,
  72684. const float* dashLengths,
  72685. int numDashLengths,
  72686. const AffineTransform& transform,
  72687. const float extraAccuracy) const
  72688. {
  72689. if (thickness <= 0)
  72690. return;
  72691. // this should really be an even number..
  72692. jassert ((numDashLengths & 1) == 0);
  72693. Path newDestPath;
  72694. PathFlatteningIterator it (sourcePath, transform, 9.0f / extraAccuracy);
  72695. bool first = true;
  72696. int dashNum = 0;
  72697. float pos = 0.0f, lineLen = 0.0f, lineEndPos = 0.0f;
  72698. float dx = 0.0f, dy = 0.0f;
  72699. for (;;)
  72700. {
  72701. const bool isSolid = ((dashNum & 1) == 0);
  72702. const float dashLen = dashLengths [dashNum++ % numDashLengths];
  72703. jassert (dashLen > 0); // must be a positive increment!
  72704. if (dashLen <= 0)
  72705. break;
  72706. pos += dashLen;
  72707. while (pos > lineEndPos)
  72708. {
  72709. if (! it.next())
  72710. {
  72711. if (isSolid && ! first)
  72712. newDestPath.lineTo (it.x2, it.y2);
  72713. createStrokedPath (destPath, newDestPath, AffineTransform::identity, extraAccuracy);
  72714. return;
  72715. }
  72716. if (isSolid && ! first)
  72717. newDestPath.lineTo (it.x1, it.y1);
  72718. else
  72719. newDestPath.startNewSubPath (it.x1, it.y1);
  72720. dx = it.x2 - it.x1;
  72721. dy = it.y2 - it.y1;
  72722. lineLen = juce_hypotf (dx, dy);
  72723. lineEndPos += lineLen;
  72724. first = it.closesSubPath;
  72725. }
  72726. const float alpha = (pos - (lineEndPos - lineLen)) / lineLen;
  72727. if (isSolid)
  72728. newDestPath.lineTo (it.x1 + dx * alpha,
  72729. it.y1 + dy * alpha);
  72730. else
  72731. newDestPath.startNewSubPath (it.x1 + dx * alpha,
  72732. it.y1 + dy * alpha);
  72733. }
  72734. }
  72735. END_JUCE_NAMESPACE
  72736. /*** End of inlined file: juce_PathStrokeType.cpp ***/
  72737. /*** Start of inlined file: juce_PositionedRectangle.cpp ***/
  72738. BEGIN_JUCE_NAMESPACE
  72739. PositionedRectangle::PositionedRectangle() throw()
  72740. : x (0.0),
  72741. y (0.0),
  72742. w (0.0),
  72743. h (0.0),
  72744. xMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  72745. yMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  72746. wMode (absoluteSize),
  72747. hMode (absoluteSize)
  72748. {
  72749. }
  72750. PositionedRectangle::PositionedRectangle (const PositionedRectangle& other) throw()
  72751. : x (other.x),
  72752. y (other.y),
  72753. w (other.w),
  72754. h (other.h),
  72755. xMode (other.xMode),
  72756. yMode (other.yMode),
  72757. wMode (other.wMode),
  72758. hMode (other.hMode)
  72759. {
  72760. }
  72761. PositionedRectangle& PositionedRectangle::operator= (const PositionedRectangle& other) throw()
  72762. {
  72763. x = other.x;
  72764. y = other.y;
  72765. w = other.w;
  72766. h = other.h;
  72767. xMode = other.xMode;
  72768. yMode = other.yMode;
  72769. wMode = other.wMode;
  72770. hMode = other.hMode;
  72771. return *this;
  72772. }
  72773. PositionedRectangle::~PositionedRectangle() throw()
  72774. {
  72775. }
  72776. bool PositionedRectangle::operator== (const PositionedRectangle& other) const throw()
  72777. {
  72778. return x == other.x
  72779. && y == other.y
  72780. && w == other.w
  72781. && h == other.h
  72782. && xMode == other.xMode
  72783. && yMode == other.yMode
  72784. && wMode == other.wMode
  72785. && hMode == other.hMode;
  72786. }
  72787. bool PositionedRectangle::operator!= (const PositionedRectangle& other) const throw()
  72788. {
  72789. return ! operator== (other);
  72790. }
  72791. PositionedRectangle::PositionedRectangle (const String& stringVersion) throw()
  72792. {
  72793. StringArray tokens;
  72794. tokens.addTokens (stringVersion, false);
  72795. decodePosString (tokens [0], xMode, x);
  72796. decodePosString (tokens [1], yMode, y);
  72797. decodeSizeString (tokens [2], wMode, w);
  72798. decodeSizeString (tokens [3], hMode, h);
  72799. }
  72800. const String PositionedRectangle::toString() const throw()
  72801. {
  72802. String s;
  72803. s.preallocateStorage (12);
  72804. addPosDescription (s, xMode, x);
  72805. s << ' ';
  72806. addPosDescription (s, yMode, y);
  72807. s << ' ';
  72808. addSizeDescription (s, wMode, w);
  72809. s << ' ';
  72810. addSizeDescription (s, hMode, h);
  72811. return s;
  72812. }
  72813. const Rectangle<int> PositionedRectangle::getRectangle (const Rectangle<int>& target) const throw()
  72814. {
  72815. jassert (! target.isEmpty());
  72816. double x_, y_, w_, h_;
  72817. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  72818. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  72819. return Rectangle<int> (roundToInt (x_), roundToInt (y_),
  72820. roundToInt (w_), roundToInt (h_));
  72821. }
  72822. void PositionedRectangle::getRectangleDouble (const Rectangle<int>& target,
  72823. double& x_, double& y_,
  72824. double& w_, double& h_) const throw()
  72825. {
  72826. jassert (! target.isEmpty());
  72827. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  72828. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  72829. }
  72830. void PositionedRectangle::applyToComponent (Component& comp) const throw()
  72831. {
  72832. comp.setBounds (getRectangle (Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight())));
  72833. }
  72834. void PositionedRectangle::updateFrom (const Rectangle<int>& rectangle,
  72835. const Rectangle<int>& target) throw()
  72836. {
  72837. updatePosAndSize (x, w, rectangle.getX(), rectangle.getWidth(), xMode, wMode, target.getX(), target.getWidth());
  72838. updatePosAndSize (y, h, rectangle.getY(), rectangle.getHeight(), yMode, hMode, target.getY(), target.getHeight());
  72839. }
  72840. void PositionedRectangle::updateFromDouble (const double newX, const double newY,
  72841. const double newW, const double newH,
  72842. const Rectangle<int>& target) throw()
  72843. {
  72844. updatePosAndSize (x, w, newX, newW, xMode, wMode, target.getX(), target.getWidth());
  72845. updatePosAndSize (y, h, newY, newH, yMode, hMode, target.getY(), target.getHeight());
  72846. }
  72847. void PositionedRectangle::updateFromComponent (const Component& comp) throw()
  72848. {
  72849. if (comp.getParentComponent() == 0 && ! comp.isOnDesktop())
  72850. updateFrom (comp.getBounds(), Rectangle<int>());
  72851. else
  72852. updateFrom (comp.getBounds(), Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight()));
  72853. }
  72854. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointX() const throw()
  72855. {
  72856. return (AnchorPoint) (xMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  72857. }
  72858. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeX() const throw()
  72859. {
  72860. return (PositionMode) (xMode & (absoluteFromParentTopLeft
  72861. | absoluteFromParentBottomRight
  72862. | absoluteFromParentCentre
  72863. | proportionOfParentSize));
  72864. }
  72865. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointY() const throw()
  72866. {
  72867. return (AnchorPoint) (yMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  72868. }
  72869. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeY() const throw()
  72870. {
  72871. return (PositionMode) (yMode & (absoluteFromParentTopLeft
  72872. | absoluteFromParentBottomRight
  72873. | absoluteFromParentCentre
  72874. | proportionOfParentSize));
  72875. }
  72876. PositionedRectangle::SizeMode PositionedRectangle::getWidthMode() const throw()
  72877. {
  72878. return (SizeMode) wMode;
  72879. }
  72880. PositionedRectangle::SizeMode PositionedRectangle::getHeightMode() const throw()
  72881. {
  72882. return (SizeMode) hMode;
  72883. }
  72884. void PositionedRectangle::setModes (const AnchorPoint xAnchor,
  72885. const PositionMode xMode_,
  72886. const AnchorPoint yAnchor,
  72887. const PositionMode yMode_,
  72888. const SizeMode widthMode,
  72889. const SizeMode heightMode,
  72890. const Rectangle<int>& target) throw()
  72891. {
  72892. if (xMode != (xAnchor | xMode_) || wMode != widthMode)
  72893. {
  72894. double tx, tw;
  72895. applyPosAndSize (tx, tw, x, w, xMode, wMode, target.getX(), target.getWidth());
  72896. xMode = (uint8) (xAnchor | xMode_);
  72897. wMode = (uint8) widthMode;
  72898. updatePosAndSize (x, w, tx, tw, xMode, wMode, target.getX(), target.getWidth());
  72899. }
  72900. if (yMode != (yAnchor | yMode_) || hMode != heightMode)
  72901. {
  72902. double ty, th;
  72903. applyPosAndSize (ty, th, y, h, yMode, hMode, target.getY(), target.getHeight());
  72904. yMode = (uint8) (yAnchor | yMode_);
  72905. hMode = (uint8) heightMode;
  72906. updatePosAndSize (y, h, ty, th, yMode, hMode, target.getY(), target.getHeight());
  72907. }
  72908. }
  72909. bool PositionedRectangle::isPositionAbsolute() const throw()
  72910. {
  72911. return xMode == absoluteFromParentTopLeft
  72912. && yMode == absoluteFromParentTopLeft
  72913. && wMode == absoluteSize
  72914. && hMode == absoluteSize;
  72915. }
  72916. void PositionedRectangle::addPosDescription (String& s, const uint8 mode, const double value) const throw()
  72917. {
  72918. if ((mode & proportionOfParentSize) != 0)
  72919. {
  72920. s << (roundToInt (value * 100000.0) / 1000.0) << '%';
  72921. }
  72922. else
  72923. {
  72924. s << (roundToInt (value * 100.0) / 100.0);
  72925. if ((mode & absoluteFromParentBottomRight) != 0)
  72926. s << 'R';
  72927. else if ((mode & absoluteFromParentCentre) != 0)
  72928. s << 'C';
  72929. }
  72930. if ((mode & anchorAtRightOrBottom) != 0)
  72931. s << 'r';
  72932. else if ((mode & anchorAtCentre) != 0)
  72933. s << 'c';
  72934. }
  72935. void PositionedRectangle::addSizeDescription (String& s, const uint8 mode, const double value) const throw()
  72936. {
  72937. if (mode == proportionalSize)
  72938. s << (roundToInt (value * 100000.0) / 1000.0) << '%';
  72939. else if (mode == parentSizeMinusAbsolute)
  72940. s << (roundToInt (value * 100.0) / 100.0) << 'M';
  72941. else
  72942. s << (roundToInt (value * 100.0) / 100.0);
  72943. }
  72944. void PositionedRectangle::decodePosString (const String& s, uint8& mode, double& value) throw()
  72945. {
  72946. if (s.containsChar ('r'))
  72947. mode = anchorAtRightOrBottom;
  72948. else if (s.containsChar ('c'))
  72949. mode = anchorAtCentre;
  72950. else
  72951. mode = anchorAtLeftOrTop;
  72952. if (s.containsChar ('%'))
  72953. {
  72954. mode |= proportionOfParentSize;
  72955. value = s.removeCharacters (T("%rcRC")).getDoubleValue() / 100.0;
  72956. }
  72957. else
  72958. {
  72959. if (s.containsChar ('R'))
  72960. mode |= absoluteFromParentBottomRight;
  72961. else if (s.containsChar ('C'))
  72962. mode |= absoluteFromParentCentre;
  72963. else
  72964. mode |= absoluteFromParentTopLeft;
  72965. value = s.removeCharacters (T("rcRC")).getDoubleValue();
  72966. }
  72967. }
  72968. void PositionedRectangle::decodeSizeString (const String& s, uint8& mode, double& value) throw()
  72969. {
  72970. if (s.containsChar ('%'))
  72971. {
  72972. mode = proportionalSize;
  72973. value = s.upToFirstOccurrenceOf (T("%"), false, false).getDoubleValue() / 100.0;
  72974. }
  72975. else if (s.containsChar ('M'))
  72976. {
  72977. mode = parentSizeMinusAbsolute;
  72978. value = s.getDoubleValue();
  72979. }
  72980. else
  72981. {
  72982. mode = absoluteSize;
  72983. value = s.getDoubleValue();
  72984. }
  72985. }
  72986. void PositionedRectangle::applyPosAndSize (double& xOut, double& wOut,
  72987. const double x_, const double w_,
  72988. const uint8 xMode_, const uint8 wMode_,
  72989. const int parentPos,
  72990. const int parentSize) const throw()
  72991. {
  72992. if (wMode_ == proportionalSize)
  72993. wOut = roundToInt (w_ * parentSize);
  72994. else if (wMode_ == parentSizeMinusAbsolute)
  72995. wOut = jmax (0, parentSize - roundToInt (w_));
  72996. else
  72997. wOut = roundToInt (w_);
  72998. if ((xMode_ & proportionOfParentSize) != 0)
  72999. xOut = parentPos + x_ * parentSize;
  73000. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  73001. xOut = (parentPos + parentSize) - x_;
  73002. else if ((xMode_ & absoluteFromParentCentre) != 0)
  73003. xOut = x_ + (parentPos + parentSize / 2);
  73004. else
  73005. xOut = x_ + parentPos;
  73006. if ((xMode_ & anchorAtRightOrBottom) != 0)
  73007. xOut -= wOut;
  73008. else if ((xMode_ & anchorAtCentre) != 0)
  73009. xOut -= wOut / 2;
  73010. }
  73011. void PositionedRectangle::updatePosAndSize (double& xOut, double& wOut,
  73012. double x_, const double w_,
  73013. const uint8 xMode_, const uint8 wMode_,
  73014. const int parentPos,
  73015. const int parentSize) const throw()
  73016. {
  73017. if (wMode_ == proportionalSize)
  73018. {
  73019. if (parentSize > 0)
  73020. wOut = w_ / parentSize;
  73021. }
  73022. else if (wMode_ == parentSizeMinusAbsolute)
  73023. wOut = parentSize - w_;
  73024. else
  73025. wOut = w_;
  73026. if ((xMode_ & anchorAtRightOrBottom) != 0)
  73027. x_ += w_;
  73028. else if ((xMode_ & anchorAtCentre) != 0)
  73029. x_ += w_ / 2;
  73030. if ((xMode_ & proportionOfParentSize) != 0)
  73031. {
  73032. if (parentSize > 0)
  73033. xOut = (x_ - parentPos) / parentSize;
  73034. }
  73035. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  73036. xOut = (parentPos + parentSize) - x_;
  73037. else if ((xMode_ & absoluteFromParentCentre) != 0)
  73038. xOut = x_ - (parentPos + parentSize / 2);
  73039. else
  73040. xOut = x_ - parentPos;
  73041. }
  73042. END_JUCE_NAMESPACE
  73043. /*** End of inlined file: juce_PositionedRectangle.cpp ***/
  73044. /*** Start of inlined file: juce_RectangleList.cpp ***/
  73045. BEGIN_JUCE_NAMESPACE
  73046. RectangleList::RectangleList() throw()
  73047. {
  73048. }
  73049. RectangleList::RectangleList (const Rectangle<int>& rect) throw()
  73050. {
  73051. if (! rect.isEmpty())
  73052. rects.add (rect);
  73053. }
  73054. RectangleList::RectangleList (const RectangleList& other) throw()
  73055. : rects (other.rects)
  73056. {
  73057. }
  73058. RectangleList& RectangleList::operator= (const RectangleList& other) throw()
  73059. {
  73060. rects = other.rects;
  73061. return *this;
  73062. }
  73063. RectangleList::~RectangleList() throw()
  73064. {
  73065. }
  73066. void RectangleList::clear() throw()
  73067. {
  73068. rects.clearQuick();
  73069. }
  73070. const Rectangle<int> RectangleList::getRectangle (const int index) const throw()
  73071. {
  73072. if (((unsigned int) index) < (unsigned int) rects.size())
  73073. return rects.getReference (index);
  73074. return Rectangle<int>();
  73075. }
  73076. bool RectangleList::isEmpty() const throw()
  73077. {
  73078. return rects.size() == 0;
  73079. }
  73080. RectangleList::Iterator::Iterator (const RectangleList& list) throw()
  73081. : current (0),
  73082. owner (list),
  73083. index (list.rects.size())
  73084. {
  73085. }
  73086. RectangleList::Iterator::~Iterator() throw()
  73087. {
  73088. }
  73089. bool RectangleList::Iterator::next() throw()
  73090. {
  73091. if (--index >= 0)
  73092. {
  73093. current = & (owner.rects.getReference (index));
  73094. return true;
  73095. }
  73096. return false;
  73097. }
  73098. void RectangleList::add (const Rectangle<int>& rect) throw()
  73099. {
  73100. if (! rect.isEmpty())
  73101. {
  73102. if (rects.size() == 0)
  73103. {
  73104. rects.add (rect);
  73105. }
  73106. else
  73107. {
  73108. bool anyOverlaps = false;
  73109. int i;
  73110. for (i = rects.size(); --i >= 0;)
  73111. {
  73112. Rectangle<int>& ourRect = rects.getReference (i);
  73113. if (rect.intersects (ourRect))
  73114. {
  73115. if (rect.contains (ourRect))
  73116. rects.remove (i);
  73117. else if (! ourRect.reduceIfPartlyContainedIn (rect))
  73118. anyOverlaps = true;
  73119. }
  73120. }
  73121. if (anyOverlaps && rects.size() > 0)
  73122. {
  73123. RectangleList r (rect);
  73124. for (i = rects.size(); --i >= 0;)
  73125. {
  73126. const Rectangle<int>& ourRect = rects.getReference (i);
  73127. if (rect.intersects (ourRect))
  73128. {
  73129. r.subtract (ourRect);
  73130. if (r.rects.size() == 0)
  73131. return;
  73132. }
  73133. }
  73134. for (i = r.getNumRectangles(); --i >= 0;)
  73135. rects.add (r.rects.getReference (i));
  73136. }
  73137. else
  73138. {
  73139. rects.add (rect);
  73140. }
  73141. }
  73142. }
  73143. }
  73144. void RectangleList::addWithoutMerging (const Rectangle<int>& rect) throw()
  73145. {
  73146. rects.add (rect);
  73147. }
  73148. void RectangleList::add (const int x, const int y, const int w, const int h) throw()
  73149. {
  73150. if (rects.size() == 0)
  73151. {
  73152. if (w > 0 && h > 0)
  73153. rects.add (Rectangle<int> (x, y, w, h));
  73154. }
  73155. else
  73156. {
  73157. add (Rectangle<int> (x, y, w, h));
  73158. }
  73159. }
  73160. void RectangleList::add (const RectangleList& other) throw()
  73161. {
  73162. for (int i = 0; i < other.rects.size(); ++i)
  73163. add (other.rects.getReference (i));
  73164. }
  73165. void RectangleList::subtract (const Rectangle<int>& rect) throw()
  73166. {
  73167. const int originalNumRects = rects.size();
  73168. if (originalNumRects > 0)
  73169. {
  73170. const int x1 = rect.x;
  73171. const int y1 = rect.y;
  73172. const int x2 = x1 + rect.w;
  73173. const int y2 = y1 + rect.h;
  73174. for (int i = getNumRectangles(); --i >= 0;)
  73175. {
  73176. Rectangle<int>& r = rects.getReference (i);
  73177. const int rx1 = r.x;
  73178. const int ry1 = r.y;
  73179. const int rx2 = rx1 + r.w;
  73180. const int ry2 = ry1 + r.h;
  73181. if (! (x2 <= rx1 || x1 >= rx2 || y2 <= ry1 || y1 >= ry2))
  73182. {
  73183. if (x1 > rx1 && x1 < rx2)
  73184. {
  73185. if (y1 <= ry1 && y2 >= ry2 && x2 >= rx2)
  73186. {
  73187. r.w = x1 - rx1;
  73188. }
  73189. else
  73190. {
  73191. r.x = x1;
  73192. r.w = rx2 - x1;
  73193. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x1 - rx1, ry2 - ry1));
  73194. i += 2;
  73195. }
  73196. }
  73197. else if (x2 > rx1 && x2 < rx2)
  73198. {
  73199. r.x = x2;
  73200. r.w = rx2 - x2;
  73201. if (y1 > ry1 || y2 < ry2 || x1 > rx1)
  73202. {
  73203. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x2 - rx1, ry2 - ry1));
  73204. i += 2;
  73205. }
  73206. }
  73207. else if (y1 > ry1 && y1 < ry2)
  73208. {
  73209. if (x1 <= rx1 && x2 >= rx2 && y2 >= ry2)
  73210. {
  73211. r.h = y1 - ry1;
  73212. }
  73213. else
  73214. {
  73215. r.y = y1;
  73216. r.h = ry2 - y1;
  73217. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y1 - ry1));
  73218. i += 2;
  73219. }
  73220. }
  73221. else if (y2 > ry1 && y2 < ry2)
  73222. {
  73223. r.y = y2;
  73224. r.h = ry2 - y2;
  73225. if (x1 > rx1 || x2 < rx2 || y1 > ry1)
  73226. {
  73227. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y2 - ry1));
  73228. i += 2;
  73229. }
  73230. }
  73231. else
  73232. {
  73233. rects.remove (i);
  73234. }
  73235. }
  73236. }
  73237. if (rects.size() > originalNumRects + 10)
  73238. consolidate();
  73239. }
  73240. }
  73241. void RectangleList::subtract (const RectangleList& otherList) throw()
  73242. {
  73243. for (int i = otherList.rects.size(); --i >= 0;)
  73244. subtract (otherList.rects.getReference (i));
  73245. }
  73246. bool RectangleList::clipTo (const Rectangle<int>& rect) throw()
  73247. {
  73248. bool notEmpty = false;
  73249. if (rect.isEmpty())
  73250. {
  73251. clear();
  73252. }
  73253. else
  73254. {
  73255. for (int i = rects.size(); --i >= 0;)
  73256. {
  73257. Rectangle<int>& r = rects.getReference (i);
  73258. if (! rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73259. rects.remove (i);
  73260. else
  73261. notEmpty = true;
  73262. }
  73263. }
  73264. return notEmpty;
  73265. }
  73266. bool RectangleList::clipTo (const RectangleList& other) throw()
  73267. {
  73268. if (rects.size() == 0)
  73269. return false;
  73270. RectangleList result;
  73271. for (int j = 0; j < rects.size(); ++j)
  73272. {
  73273. const Rectangle<int>& rect = rects.getReference (j);
  73274. for (int i = other.rects.size(); --i >= 0;)
  73275. {
  73276. Rectangle<int> r (other.rects.getReference (i));
  73277. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73278. result.rects.add (r);
  73279. }
  73280. }
  73281. swapWith (result);
  73282. return ! isEmpty();
  73283. }
  73284. bool RectangleList::getIntersectionWith (const Rectangle<int>& rect, RectangleList& destRegion) const throw()
  73285. {
  73286. destRegion.clear();
  73287. if (! rect.isEmpty())
  73288. {
  73289. for (int i = rects.size(); --i >= 0;)
  73290. {
  73291. Rectangle<int> r (rects.getReference (i));
  73292. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73293. destRegion.rects.add (r);
  73294. }
  73295. }
  73296. return destRegion.rects.size() > 0;
  73297. }
  73298. void RectangleList::swapWith (RectangleList& otherList) throw()
  73299. {
  73300. rects.swapWithArray (otherList.rects);
  73301. }
  73302. void RectangleList::consolidate() throw()
  73303. {
  73304. int i;
  73305. for (i = 0; i < getNumRectangles() - 1; ++i)
  73306. {
  73307. Rectangle<int>& r = rects.getReference (i);
  73308. const int rx1 = r.x;
  73309. const int ry1 = r.y;
  73310. const int rx2 = rx1 + r.w;
  73311. const int ry2 = ry1 + r.h;
  73312. for (int j = rects.size(); --j > i;)
  73313. {
  73314. Rectangle<int>& r2 = rects.getReference (j);
  73315. const int jrx1 = r2.x;
  73316. const int jry1 = r2.y;
  73317. const int jrx2 = jrx1 + r2.w;
  73318. const int jry2 = jry1 + r2.h;
  73319. // if the vertical edges of any blocks are touching and their horizontals don't
  73320. // line up, split them horizontally..
  73321. if (jrx1 == rx2 || jrx2 == rx1)
  73322. {
  73323. if (jry1 > ry1 && jry1 < ry2)
  73324. {
  73325. r.h = jry1 - ry1;
  73326. rects.add (Rectangle<int> (rx1, jry1, rx2 - rx1, ry2 - jry1));
  73327. i = -1;
  73328. break;
  73329. }
  73330. if (jry2 > ry1 && jry2 < ry2)
  73331. {
  73332. r.h = jry2 - ry1;
  73333. rects.add (Rectangle<int> (rx1, jry2, rx2 - rx1, ry2 - jry2));
  73334. i = -1;
  73335. break;
  73336. }
  73337. else if (ry1 > jry1 && ry1 < jry2)
  73338. {
  73339. r2.h = ry1 - jry1;
  73340. rects.add (Rectangle<int> (jrx1, ry1, jrx2 - jrx1, jry2 - ry1));
  73341. i = -1;
  73342. break;
  73343. }
  73344. else if (ry2 > jry1 && ry2 < jry2)
  73345. {
  73346. r2.h = ry2 - jry1;
  73347. rects.add (Rectangle<int> (jrx1, ry2, jrx2 - jrx1, jry2 - ry2));
  73348. i = -1;
  73349. break;
  73350. }
  73351. }
  73352. }
  73353. }
  73354. for (i = 0; i < rects.size() - 1; ++i)
  73355. {
  73356. Rectangle<int>& r = rects.getReference (i);
  73357. for (int j = rects.size(); --j > i;)
  73358. {
  73359. if (r.enlargeIfAdjacent (rects.getReference (j)))
  73360. {
  73361. rects.remove (j);
  73362. i = -1;
  73363. break;
  73364. }
  73365. }
  73366. }
  73367. }
  73368. bool RectangleList::containsPoint (const int x, const int y) const throw()
  73369. {
  73370. for (int i = getNumRectangles(); --i >= 0;)
  73371. if (rects.getReference (i).contains (x, y))
  73372. return true;
  73373. return false;
  73374. }
  73375. bool RectangleList::containsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73376. {
  73377. if (rects.size() > 1)
  73378. {
  73379. RectangleList r (rectangleToCheck);
  73380. for (int i = rects.size(); --i >= 0;)
  73381. {
  73382. r.subtract (rects.getReference (i));
  73383. if (r.rects.size() == 0)
  73384. return true;
  73385. }
  73386. }
  73387. else if (rects.size() > 0)
  73388. {
  73389. return rects.getReference (0).contains (rectangleToCheck);
  73390. }
  73391. return false;
  73392. }
  73393. bool RectangleList::intersectsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73394. {
  73395. for (int i = rects.size(); --i >= 0;)
  73396. if (rects.getReference (i).intersects (rectangleToCheck))
  73397. return true;
  73398. return false;
  73399. }
  73400. bool RectangleList::intersects (const RectangleList& other) const throw()
  73401. {
  73402. for (int i = rects.size(); --i >= 0;)
  73403. if (other.intersectsRectangle (rects.getReference (i)))
  73404. return true;
  73405. return false;
  73406. }
  73407. const Rectangle<int> RectangleList::getBounds() const throw()
  73408. {
  73409. if (rects.size() <= 1)
  73410. {
  73411. if (rects.size() == 0)
  73412. return Rectangle<int>();
  73413. else
  73414. return rects.getReference (0);
  73415. }
  73416. else
  73417. {
  73418. const Rectangle<int>& r = rects.getReference (0);
  73419. int minX = r.x;
  73420. int minY = r.y;
  73421. int maxX = minX + r.w;
  73422. int maxY = minY + r.h;
  73423. for (int i = rects.size(); --i > 0;)
  73424. {
  73425. const Rectangle<int>& r2 = rects.getReference (i);
  73426. minX = jmin (minX, r2.x);
  73427. minY = jmin (minY, r2.y);
  73428. maxX = jmax (maxX, r2.getRight());
  73429. maxY = jmax (maxY, r2.getBottom());
  73430. }
  73431. return Rectangle<int> (minX, minY, maxX - minX, maxY - minY);
  73432. }
  73433. }
  73434. void RectangleList::offsetAll (const int dx, const int dy) throw()
  73435. {
  73436. for (int i = rects.size(); --i >= 0;)
  73437. {
  73438. Rectangle<int>& r = rects.getReference (i);
  73439. r.x += dx;
  73440. r.y += dy;
  73441. }
  73442. }
  73443. const Path RectangleList::toPath() const throw()
  73444. {
  73445. Path p;
  73446. for (int i = rects.size(); --i >= 0;)
  73447. {
  73448. const Rectangle<int>& r = rects.getReference (i);
  73449. p.addRectangle ((float) r.x,
  73450. (float) r.y,
  73451. (float) r.w,
  73452. (float) r.h);
  73453. }
  73454. return p;
  73455. }
  73456. END_JUCE_NAMESPACE
  73457. /*** End of inlined file: juce_RectangleList.cpp ***/
  73458. /*** Start of inlined file: juce_Image.cpp ***/
  73459. BEGIN_JUCE_NAMESPACE
  73460. static const int fullAlphaThreshold = 253;
  73461. Image::Image (const PixelFormat format_,
  73462. const int imageWidth_,
  73463. const int imageHeight_)
  73464. : format (format_),
  73465. imageWidth (imageWidth_),
  73466. imageHeight (imageHeight_),
  73467. imageData (0)
  73468. {
  73469. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73470. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73471. // actual image will be at least 1x1.
  73472. }
  73473. Image::Image (const PixelFormat format_,
  73474. const int imageWidth_,
  73475. const int imageHeight_,
  73476. const bool clearImage)
  73477. : format (format_),
  73478. imageWidth (imageWidth_),
  73479. imageHeight (imageHeight_)
  73480. {
  73481. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73482. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73483. // actual image will be at least 1x1.
  73484. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  73485. lineStride = (pixelStride * jmax (1, imageWidth_) + 3) & ~3;
  73486. imageDataAllocated.allocate (lineStride * jmax (1, imageHeight_), clearImage);
  73487. imageData = imageDataAllocated;
  73488. }
  73489. Image::Image (const Image& other)
  73490. : format (other.format),
  73491. imageWidth (other.imageWidth),
  73492. imageHeight (other.imageHeight)
  73493. {
  73494. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  73495. lineStride = (pixelStride * jmax (1, imageWidth) + 3) & ~3;
  73496. imageDataAllocated.malloc (lineStride * jmax (1, imageHeight));
  73497. imageData = imageDataAllocated;
  73498. BitmapData srcData (other, 0, 0, imageWidth, imageHeight);
  73499. setPixelData (0, 0, imageWidth, imageHeight, srcData.data, srcData.lineStride);
  73500. }
  73501. Image::~Image()
  73502. {
  73503. }
  73504. LowLevelGraphicsContext* Image::createLowLevelContext()
  73505. {
  73506. return new LowLevelGraphicsSoftwareRenderer (*this);
  73507. }
  73508. Image::BitmapData::BitmapData (Image& image, int x, int y, int w, int h, const bool /*makeWritable*/)
  73509. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  73510. lineStride (image.lineStride),
  73511. pixelStride (image.pixelStride),
  73512. width (w),
  73513. height (h)
  73514. {
  73515. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  73516. }
  73517. Image::BitmapData::BitmapData (const Image& image, int x, int y, int w, int h)
  73518. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  73519. lineStride (image.lineStride),
  73520. pixelStride (image.pixelStride),
  73521. width (w),
  73522. height (h)
  73523. {
  73524. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  73525. }
  73526. Image::BitmapData::~BitmapData()
  73527. {
  73528. }
  73529. void Image::setPixelData (int x, int y, int w, int h,
  73530. const uint8* sourcePixelData, int sourceLineStride)
  73531. {
  73532. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= imageWidth && y + h <= imageHeight);
  73533. if (Rectangle<int>::intersectRectangles (x, y, w, h, 0, 0, imageWidth, imageHeight))
  73534. {
  73535. const BitmapData dest (*this, x, y, w, h, true);
  73536. for (int i = 0; i < h; ++i)
  73537. {
  73538. memcpy (dest.getLinePointer(i),
  73539. sourcePixelData + sourceLineStride * i,
  73540. w * dest.pixelStride);
  73541. }
  73542. }
  73543. }
  73544. void Image::clear (int dx, int dy, int dw, int dh, const Colour& colourToClearTo)
  73545. {
  73546. if (Rectangle<int>::intersectRectangles (dx, dy, dw, dh, 0, 0, imageWidth, imageHeight))
  73547. {
  73548. const PixelARGB col (colourToClearTo.getPixelARGB());
  73549. const BitmapData destData (*this, dx, dy, dw, dh, true);
  73550. uint8* dest = destData.data;
  73551. while (--dh >= 0)
  73552. {
  73553. uint8* line = dest;
  73554. dest += destData.lineStride;
  73555. if (isARGB())
  73556. {
  73557. for (int x = dw; --x >= 0;)
  73558. {
  73559. ((PixelARGB*) line)->set (col);
  73560. line += destData.pixelStride;
  73561. }
  73562. }
  73563. else if (isRGB())
  73564. {
  73565. for (int x = dw; --x >= 0;)
  73566. {
  73567. ((PixelRGB*) line)->set (col);
  73568. line += destData.pixelStride;
  73569. }
  73570. }
  73571. else
  73572. {
  73573. for (int x = dw; --x >= 0;)
  73574. {
  73575. *line = col.getAlpha();
  73576. line += destData.pixelStride;
  73577. }
  73578. }
  73579. }
  73580. }
  73581. }
  73582. Image* Image::createCopy (int newWidth, int newHeight,
  73583. const Graphics::ResamplingQuality quality) const
  73584. {
  73585. if (newWidth < 0)
  73586. newWidth = imageWidth;
  73587. if (newHeight < 0)
  73588. newHeight = imageHeight;
  73589. Image* const newImage = Image::createNativeImage (format, newWidth, newHeight, true);
  73590. Graphics g (*newImage);
  73591. g.setImageResamplingQuality (quality);
  73592. g.drawImage (this,
  73593. 0, 0, newWidth, newHeight,
  73594. 0, 0, imageWidth, imageHeight,
  73595. false);
  73596. return newImage;
  73597. }
  73598. Image* Image::createCopyOfAlphaChannel() const
  73599. {
  73600. jassert (format != SingleChannel);
  73601. Image* const newImage = Image::createNativeImage (SingleChannel, imageWidth, imageHeight, false);
  73602. if (! hasAlphaChannel())
  73603. {
  73604. newImage->clear (0, 0, imageWidth, imageHeight, Colours::black);
  73605. }
  73606. else
  73607. {
  73608. const BitmapData destData (*newImage, 0, 0, imageWidth, imageHeight, true);
  73609. const BitmapData srcData (*this, 0, 0, imageWidth, imageHeight);
  73610. for (int y = 0; y < imageHeight; ++y)
  73611. {
  73612. const PixelARGB* src = (const PixelARGB*) srcData.getLinePointer(y);
  73613. uint8* dst = destData.getLinePointer (y);
  73614. for (int x = imageWidth; --x >= 0;)
  73615. {
  73616. *dst++ = src->getAlpha();
  73617. ++src;
  73618. }
  73619. }
  73620. }
  73621. return newImage;
  73622. }
  73623. const Colour Image::getPixelAt (const int x, const int y) const
  73624. {
  73625. Colour c;
  73626. if (((unsigned int) x) < (unsigned int) imageWidth
  73627. && ((unsigned int) y) < (unsigned int) imageHeight)
  73628. {
  73629. const BitmapData srcData (*this, x, y, 1, 1);
  73630. if (isARGB())
  73631. {
  73632. PixelARGB p (*(const PixelARGB*) srcData.data);
  73633. p.unpremultiply();
  73634. c = Colour (p.getARGB());
  73635. }
  73636. else if (isRGB())
  73637. c = Colour (((const PixelRGB*) srcData.data)->getARGB());
  73638. else
  73639. c = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *(srcData.data));
  73640. }
  73641. return c;
  73642. }
  73643. void Image::setPixelAt (const int x, const int y,
  73644. const Colour& colour)
  73645. {
  73646. if (((unsigned int) x) < (unsigned int) imageWidth
  73647. && ((unsigned int) y) < (unsigned int) imageHeight)
  73648. {
  73649. const BitmapData destData (*this, x, y, 1, 1, true);
  73650. const PixelARGB col (colour.getPixelARGB());
  73651. if (isARGB())
  73652. ((PixelARGB*) destData.data)->set (col);
  73653. else if (isRGB())
  73654. ((PixelRGB*) destData.data)->set (col);
  73655. else
  73656. *(destData.data) = col.getAlpha();
  73657. }
  73658. }
  73659. void Image::multiplyAlphaAt (const int x, const int y,
  73660. const float multiplier)
  73661. {
  73662. if (((unsigned int) x) < (unsigned int) imageWidth
  73663. && ((unsigned int) y) < (unsigned int) imageHeight
  73664. && hasAlphaChannel())
  73665. {
  73666. const BitmapData destData (*this, x, y, 1, 1, true);
  73667. if (isARGB())
  73668. ((PixelARGB*) destData.data)->multiplyAlpha (multiplier);
  73669. else
  73670. *(destData.data) = (uint8) (*(destData.data) * multiplier);
  73671. }
  73672. }
  73673. void Image::multiplyAllAlphas (const float amountToMultiplyBy)
  73674. {
  73675. if (hasAlphaChannel())
  73676. {
  73677. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  73678. if (isARGB())
  73679. {
  73680. for (int y = 0; y < imageHeight; ++y)
  73681. {
  73682. uint8* p = destData.getLinePointer (y);
  73683. for (int x = 0; x < imageWidth; ++x)
  73684. {
  73685. ((PixelARGB*) p)->multiplyAlpha (amountToMultiplyBy);
  73686. p += destData.pixelStride;
  73687. }
  73688. }
  73689. }
  73690. else
  73691. {
  73692. for (int y = 0; y < imageHeight; ++y)
  73693. {
  73694. uint8* p = destData.getLinePointer (y);
  73695. for (int x = 0; x < imageWidth; ++x)
  73696. {
  73697. *p = (uint8) (*p * amountToMultiplyBy);
  73698. p += destData.pixelStride;
  73699. }
  73700. }
  73701. }
  73702. }
  73703. else
  73704. {
  73705. jassertfalse // can't do this without an alpha-channel!
  73706. }
  73707. }
  73708. void Image::desaturate()
  73709. {
  73710. if (isARGB() || isRGB())
  73711. {
  73712. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  73713. if (isARGB())
  73714. {
  73715. for (int y = 0; y < imageHeight; ++y)
  73716. {
  73717. uint8* p = destData.getLinePointer (y);
  73718. for (int x = 0; x < imageWidth; ++x)
  73719. {
  73720. ((PixelARGB*) p)->desaturate();
  73721. p += destData.pixelStride;
  73722. }
  73723. }
  73724. }
  73725. else
  73726. {
  73727. for (int y = 0; y < imageHeight; ++y)
  73728. {
  73729. uint8* p = destData.getLinePointer (y);
  73730. for (int x = 0; x < imageWidth; ++x)
  73731. {
  73732. ((PixelRGB*) p)->desaturate();
  73733. p += destData.pixelStride;
  73734. }
  73735. }
  73736. }
  73737. }
  73738. }
  73739. void Image::createSolidAreaMask (RectangleList& result, const float alphaThreshold) const
  73740. {
  73741. if (hasAlphaChannel())
  73742. {
  73743. const uint8 threshold = (uint8) jlimit (0, 255, roundToInt (alphaThreshold * 255.0f));
  73744. SparseSet <int> pixelsOnRow;
  73745. const BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  73746. for (int y = 0; y < imageHeight; ++y)
  73747. {
  73748. pixelsOnRow.clear();
  73749. const uint8* lineData = srcData.getLinePointer (y);
  73750. if (isARGB())
  73751. {
  73752. for (int x = 0; x < imageWidth; ++x)
  73753. {
  73754. if (((const PixelARGB*) lineData)->getAlpha() >= threshold)
  73755. pixelsOnRow.addRange (x, 1);
  73756. lineData += srcData.pixelStride;
  73757. }
  73758. }
  73759. else
  73760. {
  73761. for (int x = 0; x < imageWidth; ++x)
  73762. {
  73763. if (*lineData >= threshold)
  73764. pixelsOnRow.addRange (x, 1);
  73765. lineData += srcData.pixelStride;
  73766. }
  73767. }
  73768. for (int i = 0; i < pixelsOnRow.getNumRanges(); ++i)
  73769. {
  73770. int x, w;
  73771. if (pixelsOnRow.getRange (i, x, w))
  73772. result.add (Rectangle<int> (x, y, w, 1));
  73773. }
  73774. result.consolidate();
  73775. }
  73776. }
  73777. else
  73778. {
  73779. result.add (0, 0, imageWidth, imageHeight);
  73780. }
  73781. }
  73782. void Image::moveImageSection (int dx, int dy,
  73783. int sx, int sy,
  73784. int w, int h)
  73785. {
  73786. if (dx < 0)
  73787. {
  73788. w += dx;
  73789. sx -= dx;
  73790. dx = 0;
  73791. }
  73792. if (dy < 0)
  73793. {
  73794. h += dy;
  73795. sy -= dy;
  73796. dy = 0;
  73797. }
  73798. if (sx < 0)
  73799. {
  73800. w += sx;
  73801. dx -= sx;
  73802. sx = 0;
  73803. }
  73804. if (sy < 0)
  73805. {
  73806. h += sy;
  73807. dy -= sy;
  73808. sy = 0;
  73809. }
  73810. const int minX = jmin (dx, sx);
  73811. const int minY = jmin (dy, sy);
  73812. w = jmin (w, getWidth() - jmax (sx, dx));
  73813. h = jmin (h, getHeight() - jmax (sy, dy));
  73814. if (w > 0 && h > 0)
  73815. {
  73816. const int maxX = jmax (dx, sx) + w;
  73817. const int maxY = jmax (dy, sy) + h;
  73818. const BitmapData destData (*this, minX, minY, maxX - minX, maxY - minY, true);
  73819. uint8* dst = destData.getPixelPointer (dx - minX, dy - minY);
  73820. const uint8* src = destData.getPixelPointer (sx - minX, sy - minY);
  73821. const int lineSize = destData.pixelStride * w;
  73822. if (dy > sy)
  73823. {
  73824. while (--h >= 0)
  73825. {
  73826. const int offset = h * destData.lineStride;
  73827. memmove (dst + offset, src + offset, lineSize);
  73828. }
  73829. }
  73830. else if (dst != src)
  73831. {
  73832. while (--h >= 0)
  73833. {
  73834. memmove (dst, src, lineSize);
  73835. dst += destData.lineStride;
  73836. src += destData.lineStride;
  73837. }
  73838. }
  73839. }
  73840. }
  73841. END_JUCE_NAMESPACE
  73842. /*** End of inlined file: juce_Image.cpp ***/
  73843. /*** Start of inlined file: juce_ImageCache.cpp ***/
  73844. BEGIN_JUCE_NAMESPACE
  73845. struct ImageCache::Item
  73846. {
  73847. ScopedPointer <Image> image;
  73848. int64 hashCode;
  73849. int refCount;
  73850. uint32 releaseTime;
  73851. juce_UseDebuggingNewOperator
  73852. };
  73853. ImageCache* ImageCache::instance = 0;
  73854. int ImageCache::cacheTimeout = 5000;
  73855. ImageCache::ImageCache()
  73856. {
  73857. }
  73858. ImageCache::~ImageCache()
  73859. {
  73860. jassert (instance == this);
  73861. instance = 0;
  73862. }
  73863. Image* ImageCache::getFromHashCode (const int64 hashCode)
  73864. {
  73865. if (instance != 0)
  73866. {
  73867. const ScopedLock sl (instance->lock);
  73868. for (int i = instance->images.size(); --i >= 0;)
  73869. {
  73870. Item* const ci = instance->images.getUnchecked(i);
  73871. if (ci->hashCode == hashCode)
  73872. {
  73873. ci->refCount++;
  73874. return ci->image;
  73875. }
  73876. }
  73877. }
  73878. return 0;
  73879. }
  73880. void ImageCache::addImageToCache (Image* const image, const int64 hashCode)
  73881. {
  73882. if (image != 0)
  73883. {
  73884. if (instance == 0)
  73885. instance = new ImageCache();
  73886. Item* const newC = new Item();
  73887. newC->hashCode = hashCode;
  73888. newC->image = image;
  73889. newC->refCount = 1;
  73890. newC->releaseTime = 0;
  73891. const ScopedLock sl (instance->lock);
  73892. instance->images.add (newC);
  73893. }
  73894. }
  73895. void ImageCache::release (Image* const imageToRelease)
  73896. {
  73897. if (imageToRelease != 0 && instance != 0)
  73898. {
  73899. const ScopedLock sl (instance->lock);
  73900. for (int i = instance->images.size(); --i >= 0;)
  73901. {
  73902. Item* const ci = instance->images.getUnchecked(i);
  73903. if (static_cast <Image*> (ci->image) == imageToRelease)
  73904. {
  73905. if (--(ci->refCount) == 0)
  73906. ci->releaseTime = Time::getApproximateMillisecondCounter();
  73907. if (! instance->isTimerRunning())
  73908. instance->startTimer (999);
  73909. break;
  73910. }
  73911. }
  73912. }
  73913. }
  73914. void ImageCache::releaseOrDelete (Image* const imageToRelease)
  73915. {
  73916. if (isImageInCache (imageToRelease))
  73917. release (imageToRelease);
  73918. else
  73919. delete imageToRelease;
  73920. }
  73921. bool ImageCache::isImageInCache (Image* const imageToLookFor)
  73922. {
  73923. if (instance != 0)
  73924. {
  73925. const ScopedLock sl (instance->lock);
  73926. for (int i = instance->images.size(); --i >= 0;)
  73927. if (static_cast <Image*> (instance->images.getUnchecked(i)->image) == imageToLookFor)
  73928. return true;
  73929. }
  73930. return false;
  73931. }
  73932. void ImageCache::incReferenceCount (Image* const image)
  73933. {
  73934. if (instance != 0)
  73935. {
  73936. const ScopedLock sl (instance->lock);
  73937. for (int i = instance->images.size(); --i >= 0;)
  73938. {
  73939. Item* const ci = instance->images.getUnchecked(i);
  73940. if (static_cast <Image*> (ci->image) == image)
  73941. {
  73942. ci->refCount++;
  73943. return;
  73944. }
  73945. }
  73946. }
  73947. jassertfalse // (trying to inc the ref count of an image that's not in the cache)
  73948. }
  73949. void ImageCache::timerCallback()
  73950. {
  73951. int numberStillNeedingReleasing = 0;
  73952. const uint32 now = Time::getApproximateMillisecondCounter();
  73953. const ScopedLock sl (lock);
  73954. for (int i = images.size(); --i >= 0;)
  73955. {
  73956. Item* const ci = images.getUnchecked(i);
  73957. if (ci->refCount <= 0)
  73958. {
  73959. if (now > ci->releaseTime + cacheTimeout
  73960. || now < ci->releaseTime - 1000)
  73961. {
  73962. images.remove (i);
  73963. }
  73964. else
  73965. {
  73966. ++numberStillNeedingReleasing;
  73967. }
  73968. }
  73969. }
  73970. if (numberStillNeedingReleasing == 0)
  73971. stopTimer();
  73972. }
  73973. Image* ImageCache::getFromFile (const File& file)
  73974. {
  73975. const int64 hashCode = file.hashCode64();
  73976. Image* image = getFromHashCode (hashCode);
  73977. if (image == 0)
  73978. {
  73979. image = ImageFileFormat::loadFrom (file);
  73980. addImageToCache (image, hashCode);
  73981. }
  73982. return image;
  73983. }
  73984. Image* ImageCache::getFromMemory (const void* imageData, const int dataSize)
  73985. {
  73986. const int64 hashCode = (int64) (pointer_sized_int) imageData;
  73987. Image* image = getFromHashCode (hashCode);
  73988. if (image == 0)
  73989. {
  73990. image = ImageFileFormat::loadFrom (imageData, dataSize);
  73991. addImageToCache (image, hashCode);
  73992. }
  73993. return image;
  73994. }
  73995. void ImageCache::setCacheTimeout (const int millisecs)
  73996. {
  73997. cacheTimeout = millisecs;
  73998. }
  73999. END_JUCE_NAMESPACE
  74000. /*** End of inlined file: juce_ImageCache.cpp ***/
  74001. /*** Start of inlined file: juce_ImageConvolutionKernel.cpp ***/
  74002. BEGIN_JUCE_NAMESPACE
  74003. ImageConvolutionKernel::ImageConvolutionKernel (const int size_)
  74004. : values (size_ * size_),
  74005. size (size_)
  74006. {
  74007. clear();
  74008. }
  74009. ImageConvolutionKernel::~ImageConvolutionKernel()
  74010. {
  74011. }
  74012. float ImageConvolutionKernel::getKernelValue (const int x, const int y) const throw()
  74013. {
  74014. if (((unsigned int) x) < (unsigned int) size
  74015. && ((unsigned int) y) < (unsigned int) size)
  74016. {
  74017. return values [x + y * size];
  74018. }
  74019. else
  74020. {
  74021. jassertfalse;
  74022. return 0;
  74023. }
  74024. }
  74025. void ImageConvolutionKernel::setKernelValue (const int x, const int y, const float value) throw()
  74026. {
  74027. if (((unsigned int) x) < (unsigned int) size
  74028. && ((unsigned int) y) < (unsigned int) size)
  74029. {
  74030. values [x + y * size] = value;
  74031. }
  74032. else
  74033. {
  74034. jassertfalse;
  74035. }
  74036. }
  74037. void ImageConvolutionKernel::clear()
  74038. {
  74039. for (int i = size * size; --i >= 0;)
  74040. values[i] = 0;
  74041. }
  74042. void ImageConvolutionKernel::setOverallSum (const float desiredTotalSum)
  74043. {
  74044. double currentTotal = 0.0;
  74045. for (int i = size * size; --i >= 0;)
  74046. currentTotal += values[i];
  74047. rescaleAllValues ((float) (desiredTotalSum / currentTotal));
  74048. }
  74049. void ImageConvolutionKernel::rescaleAllValues (const float multiplier)
  74050. {
  74051. for (int i = size * size; --i >= 0;)
  74052. values[i] *= multiplier;
  74053. }
  74054. void ImageConvolutionKernel::createGaussianBlur (const float radius)
  74055. {
  74056. const double radiusFactor = -1.0 / (radius * radius * 2);
  74057. const int centre = size >> 1;
  74058. for (int y = size; --y >= 0;)
  74059. {
  74060. for (int x = size; --x >= 0;)
  74061. {
  74062. const int cx = x - centre;
  74063. const int cy = y - centre;
  74064. values [x + y * size] = (float) exp (radiusFactor * (cx * cx + cy * cy));
  74065. }
  74066. }
  74067. setOverallSum (1.0f);
  74068. }
  74069. void ImageConvolutionKernel::applyToImage (Image& destImage,
  74070. const Image* sourceImage,
  74071. int dx,
  74072. int dy,
  74073. int dw,
  74074. int dh) const
  74075. {
  74076. ScopedPointer <Image> imageCreated;
  74077. if (sourceImage == 0)
  74078. {
  74079. sourceImage = imageCreated = destImage.createCopy();
  74080. }
  74081. else
  74082. {
  74083. jassert (sourceImage->getWidth() == destImage.getWidth()
  74084. && sourceImage->getHeight() == destImage.getHeight()
  74085. && sourceImage->getFormat() == destImage.getFormat());
  74086. if (sourceImage->getWidth() != destImage.getWidth()
  74087. || sourceImage->getHeight() != destImage.getHeight()
  74088. || sourceImage->getFormat() != destImage.getFormat())
  74089. return;
  74090. }
  74091. const int imageWidth = destImage.getWidth();
  74092. const int imageHeight = destImage.getHeight();
  74093. if (dx >= imageWidth || dy >= imageHeight)
  74094. return;
  74095. if (dx + dw > imageWidth)
  74096. dw = imageWidth - dx;
  74097. if (dy + dh > imageHeight)
  74098. dh = imageHeight - dy;
  74099. const int dx2 = dx + dw;
  74100. const int dy2 = dy + dh;
  74101. const Image::BitmapData destData (destImage, dx, dy, dw, dh, true);
  74102. uint8* line = destData.data;
  74103. const Image::BitmapData srcData (*sourceImage, 0, 0, sourceImage->getWidth(), sourceImage->getHeight());
  74104. if (destData.pixelStride == 4)
  74105. {
  74106. for (int y = dy; y < dy2; ++y)
  74107. {
  74108. uint8* dest = line;
  74109. line += destData.lineStride;
  74110. for (int x = dx; x < dx2; ++x)
  74111. {
  74112. float c1 = 0;
  74113. float c2 = 0;
  74114. float c3 = 0;
  74115. float c4 = 0;
  74116. for (int yy = 0; yy < size; ++yy)
  74117. {
  74118. const int sy = y + yy - (size >> 1);
  74119. if (sy >= imageHeight)
  74120. break;
  74121. if (sy >= 0)
  74122. {
  74123. int sx = x - (size >> 1);
  74124. const uint8* src = srcData.getPixelPointer (sx, sy);
  74125. for (int xx = 0; xx < size; ++xx)
  74126. {
  74127. if (sx >= imageWidth)
  74128. break;
  74129. if (sx >= 0)
  74130. {
  74131. const float kernelMult = values [xx + yy * size];
  74132. c1 += kernelMult * *src++;
  74133. c2 += kernelMult * *src++;
  74134. c3 += kernelMult * *src++;
  74135. c4 += kernelMult * *src++;
  74136. }
  74137. else
  74138. {
  74139. src += 4;
  74140. }
  74141. ++sx;
  74142. }
  74143. }
  74144. }
  74145. *dest++ = (uint8) jmin (0xff, roundToInt (c1));
  74146. *dest++ = (uint8) jmin (0xff, roundToInt (c2));
  74147. *dest++ = (uint8) jmin (0xff, roundToInt (c3));
  74148. *dest++ = (uint8) jmin (0xff, roundToInt (c4));
  74149. }
  74150. }
  74151. }
  74152. else if (destData.pixelStride == 3)
  74153. {
  74154. for (int y = dy; y < dy2; ++y)
  74155. {
  74156. uint8* dest = line;
  74157. line += destData.lineStride;
  74158. for (int x = dx; x < dx2; ++x)
  74159. {
  74160. float c1 = 0;
  74161. float c2 = 0;
  74162. float c3 = 0;
  74163. for (int yy = 0; yy < size; ++yy)
  74164. {
  74165. const int sy = y + yy - (size >> 1);
  74166. if (sy >= imageHeight)
  74167. break;
  74168. if (sy >= 0)
  74169. {
  74170. int sx = x - (size >> 1);
  74171. const uint8* src = srcData.getPixelPointer (sx, sy);
  74172. for (int xx = 0; xx < size; ++xx)
  74173. {
  74174. if (sx >= imageWidth)
  74175. break;
  74176. if (sx >= 0)
  74177. {
  74178. const float kernelMult = values [xx + yy * size];
  74179. c1 += kernelMult * *src++;
  74180. c2 += kernelMult * *src++;
  74181. c3 += kernelMult * *src++;
  74182. }
  74183. else
  74184. {
  74185. src += 3;
  74186. }
  74187. ++sx;
  74188. }
  74189. }
  74190. }
  74191. *dest++ = (uint8) roundToInt (c1);
  74192. *dest++ = (uint8) roundToInt (c2);
  74193. *dest++ = (uint8) roundToInt (c3);
  74194. }
  74195. }
  74196. }
  74197. }
  74198. END_JUCE_NAMESPACE
  74199. /*** End of inlined file: juce_ImageConvolutionKernel.cpp ***/
  74200. /*** Start of inlined file: juce_ImageFileFormat.cpp ***/
  74201. BEGIN_JUCE_NAMESPACE
  74202. /*** Start of inlined file: juce_GIFLoader.h ***/
  74203. #ifndef __JUCE_GIFLOADER_JUCEHEADER__
  74204. #define __JUCE_GIFLOADER_JUCEHEADER__
  74205. #ifndef DOXYGEN
  74206. class GIFLoader
  74207. {
  74208. public:
  74209. GIFLoader (InputStream& in);
  74210. ~GIFLoader();
  74211. Image* getImage() const { return image; }
  74212. private:
  74213. Image* image;
  74214. InputStream& input;
  74215. uint8 buffer [300];
  74216. uint8 palette [256][4];
  74217. bool dataBlockIsZero, fresh, finished;
  74218. int currentBit, lastBit, lastByteIndex;
  74219. int codeSize, setCodeSize;
  74220. int maxCode, maxCodeSize;
  74221. int firstcode, oldcode;
  74222. int clearCode, end_code;
  74223. enum { maxGifCode = 1 << 12 };
  74224. int table [2] [maxGifCode];
  74225. int stack [2 * maxGifCode];
  74226. int *sp;
  74227. bool getSizeFromHeader (int& width, int& height);
  74228. bool readPalette (const int numCols);
  74229. int readDataBlock (unsigned char* dest);
  74230. int processExtension (int type, int& transparent);
  74231. int readLZWByte (bool initialise, int input_code_size);
  74232. int getCode (int code_size, bool initialise);
  74233. bool readImage (int width, int height, int interlace, int transparent);
  74234. static inline int makeWord (const uint8 a, const uint8 b) { return (b << 8) | a; }
  74235. GIFLoader (const GIFLoader&);
  74236. GIFLoader& operator= (const GIFLoader&);
  74237. };
  74238. #endif // DOXYGEN
  74239. #endif // __JUCE_GIFLOADER_JUCEHEADER__
  74240. /*** End of inlined file: juce_GIFLoader.h ***/
  74241. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  74242. bool juce_writePNGImageToStream (const Image& image, OutputStream& out);
  74243. PNGImageFormat::PNGImageFormat() {}
  74244. PNGImageFormat::~PNGImageFormat() {}
  74245. const String PNGImageFormat::getFormatName()
  74246. {
  74247. return "PNG";
  74248. }
  74249. bool PNGImageFormat::canUnderstand (InputStream& in)
  74250. {
  74251. const int bytesNeeded = 4;
  74252. char header [bytesNeeded];
  74253. return in.read (header, bytesNeeded) == bytesNeeded
  74254. && header[1] == 'P'
  74255. && header[2] == 'N'
  74256. && header[3] == 'G';
  74257. }
  74258. Image* PNGImageFormat::decodeImage (InputStream& in)
  74259. {
  74260. return juce_loadPNGImageFromStream (in);
  74261. }
  74262. bool PNGImageFormat::writeImageToStream (const Image& sourceImage,
  74263. OutputStream& destStream)
  74264. {
  74265. return juce_writePNGImageToStream (sourceImage, destStream);
  74266. }
  74267. Image* juce_loadJPEGImageFromStream (InputStream& inputStream);
  74268. bool juce_writeJPEGImageToStream (const Image& image, OutputStream& out, float quality);
  74269. JPEGImageFormat::JPEGImageFormat()
  74270. : quality (-1.0f)
  74271. {
  74272. }
  74273. JPEGImageFormat::~JPEGImageFormat() {}
  74274. void JPEGImageFormat::setQuality (const float newQuality)
  74275. {
  74276. quality = newQuality;
  74277. }
  74278. const String JPEGImageFormat::getFormatName()
  74279. {
  74280. return "JPEG";
  74281. }
  74282. bool JPEGImageFormat::canUnderstand (InputStream& in)
  74283. {
  74284. const int bytesNeeded = 10;
  74285. uint8 header [bytesNeeded];
  74286. if (in.read (header, bytesNeeded) == bytesNeeded)
  74287. {
  74288. return header[0] == 0xff
  74289. && header[1] == 0xd8
  74290. && header[2] == 0xff
  74291. && (header[3] == 0xe0 || header[3] == 0xe1);
  74292. }
  74293. return false;
  74294. }
  74295. Image* JPEGImageFormat::decodeImage (InputStream& in)
  74296. {
  74297. return juce_loadJPEGImageFromStream (in);
  74298. }
  74299. bool JPEGImageFormat::writeImageToStream (const Image& sourceImage,
  74300. OutputStream& destStream)
  74301. {
  74302. return juce_writeJPEGImageToStream (sourceImage, destStream, quality);
  74303. }
  74304. class GIFImageFormat : public ImageFileFormat
  74305. {
  74306. public:
  74307. GIFImageFormat() {}
  74308. ~GIFImageFormat() {}
  74309. const String getFormatName()
  74310. {
  74311. return "GIF";
  74312. }
  74313. bool canUnderstand (InputStream& in)
  74314. {
  74315. const int bytesNeeded = 4;
  74316. char header [bytesNeeded];
  74317. return (in.read (header, bytesNeeded) == bytesNeeded)
  74318. && header[0] == 'G'
  74319. && header[1] == 'I'
  74320. && header[2] == 'F';
  74321. }
  74322. Image* decodeImage (InputStream& in)
  74323. {
  74324. const ScopedPointer <GIFLoader> loader (new GIFLoader (in));
  74325. return loader->getImage();
  74326. }
  74327. bool writeImageToStream (const Image& /*sourceImage*/, OutputStream& /*destStream*/)
  74328. {
  74329. return false;
  74330. }
  74331. };
  74332. ImageFileFormat* ImageFileFormat::findImageFormatForStream (InputStream& input)
  74333. {
  74334. static PNGImageFormat png;
  74335. static JPEGImageFormat jpg;
  74336. static GIFImageFormat gif;
  74337. ImageFileFormat* formats[4];
  74338. int numFormats = 0;
  74339. formats [numFormats++] = &png;
  74340. formats [numFormats++] = &jpg;
  74341. formats [numFormats++] = &gif;
  74342. const int64 streamPos = input.getPosition();
  74343. for (int i = 0; i < numFormats; ++i)
  74344. {
  74345. const bool found = formats[i]->canUnderstand (input);
  74346. input.setPosition (streamPos);
  74347. if (found)
  74348. return formats[i];
  74349. }
  74350. return 0;
  74351. }
  74352. Image* ImageFileFormat::loadFrom (InputStream& input)
  74353. {
  74354. ImageFileFormat* const format = findImageFormatForStream (input);
  74355. if (format != 0)
  74356. return format->decodeImage (input);
  74357. return 0;
  74358. }
  74359. Image* ImageFileFormat::loadFrom (const File& file)
  74360. {
  74361. InputStream* const in = file.createInputStream();
  74362. if (in != 0)
  74363. {
  74364. BufferedInputStream b (in, 8192, true);
  74365. return loadFrom (b);
  74366. }
  74367. return 0;
  74368. }
  74369. Image* ImageFileFormat::loadFrom (const void* rawData, const int numBytes)
  74370. {
  74371. if (rawData != 0 && numBytes > 4)
  74372. {
  74373. MemoryInputStream stream (rawData, numBytes, false);
  74374. return loadFrom (stream);
  74375. }
  74376. return 0;
  74377. }
  74378. END_JUCE_NAMESPACE
  74379. /*** End of inlined file: juce_ImageFileFormat.cpp ***/
  74380. /*** Start of inlined file: juce_GIFLoader.cpp ***/
  74381. BEGIN_JUCE_NAMESPACE
  74382. GIFLoader::GIFLoader (InputStream& in)
  74383. : image (0),
  74384. input (in),
  74385. dataBlockIsZero (false),
  74386. fresh (false),
  74387. finished (false)
  74388. {
  74389. currentBit = lastBit = lastByteIndex = 0;
  74390. maxCode = maxCodeSize = codeSize = setCodeSize = 0;
  74391. firstcode = oldcode = 0;
  74392. clearCode = end_code = 0;
  74393. int imageWidth, imageHeight;
  74394. int transparent = -1;
  74395. if (! getSizeFromHeader (imageWidth, imageHeight))
  74396. return;
  74397. if ((imageWidth <= 0) || (imageHeight <= 0))
  74398. return;
  74399. unsigned char buf [16];
  74400. if (in.read (buf, 3) != 3)
  74401. return;
  74402. int numColours = 2 << (buf[0] & 7);
  74403. if ((buf[0] & 0x80) != 0)
  74404. readPalette (numColours);
  74405. for (;;)
  74406. {
  74407. if (input.read (buf, 1) != 1)
  74408. break;
  74409. if (buf[0] == ';')
  74410. break;
  74411. if (buf[0] == '!')
  74412. {
  74413. if (input.read (buf, 1) != 1)
  74414. break;
  74415. if (processExtension (buf[0], transparent) < 0)
  74416. break;
  74417. continue;
  74418. }
  74419. if (buf[0] != ',')
  74420. continue;
  74421. if (input.read (buf, 9) != 9)
  74422. break;
  74423. imageWidth = makeWord (buf[4], buf[5]);
  74424. imageHeight = makeWord (buf[6], buf[7]);
  74425. numColours = 2 << (buf[8] & 7);
  74426. if ((buf[8] & 0x80) != 0)
  74427. if (! readPalette (numColours))
  74428. break;
  74429. image = Image::createNativeImage ((transparent >= 0) ? Image::ARGB : Image::RGB,
  74430. imageWidth, imageHeight, (transparent >= 0));
  74431. readImage (imageWidth, imageHeight,
  74432. (buf[8] & 0x40) != 0,
  74433. transparent);
  74434. break;
  74435. }
  74436. }
  74437. GIFLoader::~GIFLoader()
  74438. {
  74439. }
  74440. bool GIFLoader::getSizeFromHeader (int& w, int& h)
  74441. {
  74442. unsigned char b [8];
  74443. if (input.read (b, 6) == 6)
  74444. {
  74445. if ((strncmp ("GIF87a", (char*) b, 6) == 0)
  74446. || (strncmp ("GIF89a", (char*) b, 6) == 0))
  74447. {
  74448. if (input.read (b, 4) == 4)
  74449. {
  74450. w = makeWord (b[0], b[1]);
  74451. h = makeWord (b[2], b[3]);
  74452. return true;
  74453. }
  74454. }
  74455. }
  74456. return false;
  74457. }
  74458. bool GIFLoader::readPalette (const int numCols)
  74459. {
  74460. unsigned char rgb[4];
  74461. for (int i = 0; i < numCols; ++i)
  74462. {
  74463. input.read (rgb, 3);
  74464. palette [i][0] = rgb[0];
  74465. palette [i][1] = rgb[1];
  74466. palette [i][2] = rgb[2];
  74467. palette [i][3] = 0xff;
  74468. }
  74469. return true;
  74470. }
  74471. int GIFLoader::readDataBlock (unsigned char* const dest)
  74472. {
  74473. unsigned char n;
  74474. if (input.read (&n, 1) == 1)
  74475. {
  74476. dataBlockIsZero = (n == 0);
  74477. if (dataBlockIsZero || (input.read (dest, n) == n))
  74478. return n;
  74479. }
  74480. return -1;
  74481. }
  74482. int GIFLoader::processExtension (const int type, int& transparent)
  74483. {
  74484. unsigned char b [300];
  74485. int n = 0;
  74486. if (type == 0xf9)
  74487. {
  74488. n = readDataBlock (b);
  74489. if (n < 0)
  74490. return 1;
  74491. if ((b[0] & 0x1) != 0)
  74492. transparent = b[3];
  74493. }
  74494. do
  74495. {
  74496. n = readDataBlock (b);
  74497. }
  74498. while (n > 0);
  74499. return n;
  74500. }
  74501. int GIFLoader::getCode (const int codeSize_, const bool initialise)
  74502. {
  74503. if (initialise)
  74504. {
  74505. currentBit = 0;
  74506. lastBit = 0;
  74507. finished = false;
  74508. return 0;
  74509. }
  74510. if ((currentBit + codeSize_) >= lastBit)
  74511. {
  74512. if (finished)
  74513. return -1;
  74514. buffer[0] = buffer [lastByteIndex - 2];
  74515. buffer[1] = buffer [lastByteIndex - 1];
  74516. const int n = readDataBlock (&buffer[2]);
  74517. if (n == 0)
  74518. finished = true;
  74519. lastByteIndex = 2 + n;
  74520. currentBit = (currentBit - lastBit) + 16;
  74521. lastBit = (2 + n) * 8 ;
  74522. }
  74523. int result = 0;
  74524. int i = currentBit;
  74525. for (int j = 0; j < codeSize_; ++j)
  74526. {
  74527. result |= ((buffer[i >> 3] & (1 << (i & 7))) != 0) << j;
  74528. ++i;
  74529. }
  74530. currentBit += codeSize_;
  74531. return result;
  74532. }
  74533. int GIFLoader::readLZWByte (const bool initialise, const int inputCodeSize)
  74534. {
  74535. int code, incode, i;
  74536. if (initialise)
  74537. {
  74538. setCodeSize = inputCodeSize;
  74539. codeSize = setCodeSize + 1;
  74540. clearCode = 1 << setCodeSize;
  74541. end_code = clearCode + 1;
  74542. maxCodeSize = 2 * clearCode;
  74543. maxCode = clearCode + 2;
  74544. getCode (0, true);
  74545. fresh = true;
  74546. for (i = 0; i < clearCode; ++i)
  74547. {
  74548. table[0][i] = 0;
  74549. table[1][i] = i;
  74550. }
  74551. for (; i < maxGifCode; ++i)
  74552. {
  74553. table[0][i] = 0;
  74554. table[1][i] = 0;
  74555. }
  74556. sp = stack;
  74557. return 0;
  74558. }
  74559. else if (fresh)
  74560. {
  74561. fresh = false;
  74562. do
  74563. {
  74564. firstcode = oldcode
  74565. = getCode (codeSize, false);
  74566. }
  74567. while (firstcode == clearCode);
  74568. return firstcode;
  74569. }
  74570. if (sp > stack)
  74571. return *--sp;
  74572. while ((code = getCode (codeSize, false)) >= 0)
  74573. {
  74574. if (code == clearCode)
  74575. {
  74576. for (i = 0; i < clearCode; ++i)
  74577. {
  74578. table[0][i] = 0;
  74579. table[1][i] = i;
  74580. }
  74581. for (; i < maxGifCode; ++i)
  74582. {
  74583. table[0][i] = 0;
  74584. table[1][i] = 0;
  74585. }
  74586. codeSize = setCodeSize + 1;
  74587. maxCodeSize = 2 * clearCode;
  74588. maxCode = clearCode + 2;
  74589. sp = stack;
  74590. firstcode = oldcode = getCode (codeSize, false);
  74591. return firstcode;
  74592. }
  74593. else if (code == end_code)
  74594. {
  74595. if (dataBlockIsZero)
  74596. return -2;
  74597. unsigned char buf [260];
  74598. int n;
  74599. while ((n = readDataBlock (buf)) > 0)
  74600. {}
  74601. if (n != 0)
  74602. return -2;
  74603. }
  74604. incode = code;
  74605. if (code >= maxCode)
  74606. {
  74607. *sp++ = firstcode;
  74608. code = oldcode;
  74609. }
  74610. while (code >= clearCode)
  74611. {
  74612. *sp++ = table[1][code];
  74613. if (code == table[0][code])
  74614. return -2;
  74615. code = table[0][code];
  74616. }
  74617. *sp++ = firstcode = table[1][code];
  74618. if ((code = maxCode) < maxGifCode)
  74619. {
  74620. table[0][code] = oldcode;
  74621. table[1][code] = firstcode;
  74622. ++maxCode;
  74623. if ((maxCode >= maxCodeSize)
  74624. && (maxCodeSize < maxGifCode))
  74625. {
  74626. maxCodeSize <<= 1;
  74627. ++codeSize;
  74628. }
  74629. }
  74630. oldcode = incode;
  74631. if (sp > stack)
  74632. return *--sp;
  74633. }
  74634. return code;
  74635. }
  74636. bool GIFLoader::readImage (const int width, const int height,
  74637. const int interlace, const int transparent)
  74638. {
  74639. unsigned char c;
  74640. if (input.read (&c, 1) != 1
  74641. || readLZWByte (true, c) < 0)
  74642. return false;
  74643. if (transparent >= 0)
  74644. {
  74645. palette [transparent][0] = 0;
  74646. palette [transparent][1] = 0;
  74647. palette [transparent][2] = 0;
  74648. palette [transparent][3] = 0;
  74649. }
  74650. int index;
  74651. int xpos = 0, ypos = 0, pass = 0;
  74652. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  74653. uint8* p = destData.data;
  74654. const bool hasAlpha = image->hasAlphaChannel();
  74655. while ((index = readLZWByte (false, c)) >= 0)
  74656. {
  74657. const uint8* const paletteEntry = palette [index];
  74658. if (hasAlpha)
  74659. {
  74660. ((PixelARGB*) p)->setARGB (paletteEntry[3],
  74661. paletteEntry[0],
  74662. paletteEntry[1],
  74663. paletteEntry[2]);
  74664. ((PixelARGB*) p)->premultiply();
  74665. }
  74666. else
  74667. {
  74668. ((PixelRGB*) p)->setARGB (0,
  74669. paletteEntry[0],
  74670. paletteEntry[1],
  74671. paletteEntry[2]);
  74672. }
  74673. p += destData.pixelStride;
  74674. ++xpos;
  74675. if (xpos == width)
  74676. {
  74677. xpos = 0;
  74678. if (interlace)
  74679. {
  74680. switch (pass)
  74681. {
  74682. case 0:
  74683. case 1:
  74684. ypos += 8;
  74685. break;
  74686. case 2:
  74687. ypos += 4;
  74688. break;
  74689. case 3:
  74690. ypos += 2;
  74691. break;
  74692. }
  74693. while (ypos >= height)
  74694. {
  74695. ++pass;
  74696. switch (pass)
  74697. {
  74698. case 1:
  74699. ypos = 4;
  74700. break;
  74701. case 2:
  74702. ypos = 2;
  74703. break;
  74704. case 3:
  74705. ypos = 1;
  74706. break;
  74707. default:
  74708. return true;
  74709. }
  74710. }
  74711. }
  74712. else
  74713. {
  74714. ++ypos;
  74715. }
  74716. p = destData.getPixelPointer (xpos, ypos);
  74717. }
  74718. if (ypos >= height)
  74719. break;
  74720. }
  74721. return true;
  74722. }
  74723. END_JUCE_NAMESPACE
  74724. /*** End of inlined file: juce_GIFLoader.cpp ***/
  74725. #endif
  74726. //==============================================================================
  74727. // some files include lots of library code, so leave them to the end to avoid cluttering
  74728. // up the build for the clean files.
  74729. #if JUCE_BUILD_CORE
  74730. /*** Start of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  74731. namespace zlibNamespace
  74732. {
  74733. #if JUCE_INCLUDE_ZLIB_CODE
  74734. #undef OS_CODE
  74735. #undef fdopen
  74736. /*** Start of inlined file: zlib.h ***/
  74737. #ifndef ZLIB_H
  74738. #define ZLIB_H
  74739. /*** Start of inlined file: zconf.h ***/
  74740. #ifndef ZCONF_H
  74741. #define ZCONF_H
  74742. // *** Just a few hacks here to make it compile nicely with Juce..
  74743. #define Z_PREFIX 1
  74744. #undef __MACTYPES__
  74745. #ifdef _MSC_VER
  74746. #pragma warning (disable : 4131 4127 4244 4267)
  74747. #endif
  74748. #ifdef Z_PREFIX
  74749. # define deflateInit_ z_deflateInit_
  74750. # define deflate z_deflate
  74751. # define deflateEnd z_deflateEnd
  74752. # define inflateInit_ z_inflateInit_
  74753. # define inflate z_inflate
  74754. # define inflateEnd z_inflateEnd
  74755. # define deflateInit2_ z_deflateInit2_
  74756. # define deflateSetDictionary z_deflateSetDictionary
  74757. # define deflateCopy z_deflateCopy
  74758. # define deflateReset z_deflateReset
  74759. # define deflateParams z_deflateParams
  74760. # define deflateBound z_deflateBound
  74761. # define deflatePrime z_deflatePrime
  74762. # define inflateInit2_ z_inflateInit2_
  74763. # define inflateSetDictionary z_inflateSetDictionary
  74764. # define inflateSync z_inflateSync
  74765. # define inflateSyncPoint z_inflateSyncPoint
  74766. # define inflateCopy z_inflateCopy
  74767. # define inflateReset z_inflateReset
  74768. # define inflateBack z_inflateBack
  74769. # define inflateBackEnd z_inflateBackEnd
  74770. # define compress z_compress
  74771. # define compress2 z_compress2
  74772. # define compressBound z_compressBound
  74773. # define uncompress z_uncompress
  74774. # define adler32 z_adler32
  74775. # define crc32 z_crc32
  74776. # define get_crc_table z_get_crc_table
  74777. # define zError z_zError
  74778. # define alloc_func z_alloc_func
  74779. # define free_func z_free_func
  74780. # define in_func z_in_func
  74781. # define out_func z_out_func
  74782. # define Byte z_Byte
  74783. # define uInt z_uInt
  74784. # define uLong z_uLong
  74785. # define Bytef z_Bytef
  74786. # define charf z_charf
  74787. # define intf z_intf
  74788. # define uIntf z_uIntf
  74789. # define uLongf z_uLongf
  74790. # define voidpf z_voidpf
  74791. # define voidp z_voidp
  74792. #endif
  74793. #if defined(__MSDOS__) && !defined(MSDOS)
  74794. # define MSDOS
  74795. #endif
  74796. #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
  74797. # define OS2
  74798. #endif
  74799. #if defined(_WINDOWS) && !defined(WINDOWS)
  74800. # define WINDOWS
  74801. #endif
  74802. #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
  74803. # ifndef WIN32
  74804. # define WIN32
  74805. # endif
  74806. #endif
  74807. #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
  74808. # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
  74809. # ifndef SYS16BIT
  74810. # define SYS16BIT
  74811. # endif
  74812. # endif
  74813. #endif
  74814. #ifdef SYS16BIT
  74815. # define MAXSEG_64K
  74816. #endif
  74817. #ifdef MSDOS
  74818. # define UNALIGNED_OK
  74819. #endif
  74820. #ifdef __STDC_VERSION__
  74821. # ifndef STDC
  74822. # define STDC
  74823. # endif
  74824. # if __STDC_VERSION__ >= 199901L
  74825. # ifndef STDC99
  74826. # define STDC99
  74827. # endif
  74828. # endif
  74829. #endif
  74830. #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
  74831. # define STDC
  74832. #endif
  74833. #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
  74834. # define STDC
  74835. #endif
  74836. #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
  74837. # define STDC
  74838. #endif
  74839. #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
  74840. # define STDC
  74841. #endif
  74842. #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
  74843. # define STDC
  74844. #endif
  74845. #ifndef STDC
  74846. # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
  74847. # define const /* note: need a more gentle solution here */
  74848. # endif
  74849. #endif
  74850. #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
  74851. # define NO_DUMMY_DECL
  74852. #endif
  74853. #ifndef MAX_MEM_LEVEL
  74854. # ifdef MAXSEG_64K
  74855. # define MAX_MEM_LEVEL 8
  74856. # else
  74857. # define MAX_MEM_LEVEL 9
  74858. # endif
  74859. #endif
  74860. #ifndef MAX_WBITS
  74861. # define MAX_WBITS 15 /* 32K LZ77 window */
  74862. #endif
  74863. #ifndef OF /* function prototypes */
  74864. # ifdef STDC
  74865. # define OF(args) args
  74866. # else
  74867. # define OF(args) ()
  74868. # endif
  74869. #endif
  74870. #ifdef SYS16BIT
  74871. # if defined(M_I86SM) || defined(M_I86MM)
  74872. # define SMALL_MEDIUM
  74873. # ifdef _MSC_VER
  74874. # define FAR _far
  74875. # else
  74876. # define FAR far
  74877. # endif
  74878. # endif
  74879. # if (defined(__SMALL__) || defined(__MEDIUM__))
  74880. # define SMALL_MEDIUM
  74881. # ifdef __BORLANDC__
  74882. # define FAR _far
  74883. # else
  74884. # define FAR far
  74885. # endif
  74886. # endif
  74887. #endif
  74888. #if defined(WINDOWS) || defined(WIN32)
  74889. # ifdef ZLIB_DLL
  74890. # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
  74891. # ifdef ZLIB_INTERNAL
  74892. # define ZEXTERN extern __declspec(dllexport)
  74893. # else
  74894. # define ZEXTERN extern __declspec(dllimport)
  74895. # endif
  74896. # endif
  74897. # endif /* ZLIB_DLL */
  74898. # ifdef ZLIB_WINAPI
  74899. # ifdef FAR
  74900. # undef FAR
  74901. # endif
  74902. # include <windows.h>
  74903. # define ZEXPORT WINAPI
  74904. # ifdef WIN32
  74905. # define ZEXPORTVA WINAPIV
  74906. # else
  74907. # define ZEXPORTVA FAR CDECL
  74908. # endif
  74909. # endif
  74910. #endif
  74911. #if defined (__BEOS__)
  74912. # ifdef ZLIB_DLL
  74913. # ifdef ZLIB_INTERNAL
  74914. # define ZEXPORT __declspec(dllexport)
  74915. # define ZEXPORTVA __declspec(dllexport)
  74916. # else
  74917. # define ZEXPORT __declspec(dllimport)
  74918. # define ZEXPORTVA __declspec(dllimport)
  74919. # endif
  74920. # endif
  74921. #endif
  74922. #ifndef ZEXTERN
  74923. # define ZEXTERN extern
  74924. #endif
  74925. #ifndef ZEXPORT
  74926. # define ZEXPORT
  74927. #endif
  74928. #ifndef ZEXPORTVA
  74929. # define ZEXPORTVA
  74930. #endif
  74931. #ifndef FAR
  74932. # define FAR
  74933. #endif
  74934. #if !defined(__MACTYPES__)
  74935. typedef unsigned char Byte; /* 8 bits */
  74936. #endif
  74937. typedef unsigned int uInt; /* 16 bits or more */
  74938. typedef unsigned long uLong; /* 32 bits or more */
  74939. #ifdef SMALL_MEDIUM
  74940. # define Bytef Byte FAR
  74941. #else
  74942. typedef Byte FAR Bytef;
  74943. #endif
  74944. typedef char FAR charf;
  74945. typedef int FAR intf;
  74946. typedef uInt FAR uIntf;
  74947. typedef uLong FAR uLongf;
  74948. #ifdef STDC
  74949. typedef void const *voidpc;
  74950. typedef void FAR *voidpf;
  74951. typedef void *voidp;
  74952. #else
  74953. typedef Byte const *voidpc;
  74954. typedef Byte FAR *voidpf;
  74955. typedef Byte *voidp;
  74956. #endif
  74957. #if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
  74958. # include <sys/types.h> /* for off_t */
  74959. # include <unistd.h> /* for SEEK_* and off_t */
  74960. # ifdef VMS
  74961. # include <unixio.h> /* for off_t */
  74962. # endif
  74963. # define z_off_t off_t
  74964. #endif
  74965. #ifndef SEEK_SET
  74966. # define SEEK_SET 0 /* Seek from beginning of file. */
  74967. # define SEEK_CUR 1 /* Seek from current position. */
  74968. # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
  74969. #endif
  74970. #ifndef z_off_t
  74971. # define z_off_t long
  74972. #endif
  74973. #if defined(__OS400__)
  74974. # define NO_vsnprintf
  74975. #endif
  74976. #if defined(__MVS__)
  74977. # define NO_vsnprintf
  74978. # ifdef FAR
  74979. # undef FAR
  74980. # endif
  74981. #endif
  74982. #if defined(__MVS__)
  74983. # pragma map(deflateInit_,"DEIN")
  74984. # pragma map(deflateInit2_,"DEIN2")
  74985. # pragma map(deflateEnd,"DEEND")
  74986. # pragma map(deflateBound,"DEBND")
  74987. # pragma map(inflateInit_,"ININ")
  74988. # pragma map(inflateInit2_,"ININ2")
  74989. # pragma map(inflateEnd,"INEND")
  74990. # pragma map(inflateSync,"INSY")
  74991. # pragma map(inflateSetDictionary,"INSEDI")
  74992. # pragma map(compressBound,"CMBND")
  74993. # pragma map(inflate_table,"INTABL")
  74994. # pragma map(inflate_fast,"INFA")
  74995. # pragma map(inflate_copyright,"INCOPY")
  74996. #endif
  74997. #endif /* ZCONF_H */
  74998. /*** End of inlined file: zconf.h ***/
  74999. #ifdef __cplusplus
  75000. extern "C" {
  75001. #endif
  75002. #define ZLIB_VERSION "1.2.3"
  75003. #define ZLIB_VERNUM 0x1230
  75004. typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
  75005. typedef void (*free_func) OF((voidpf opaque, voidpf address));
  75006. struct internal_state;
  75007. typedef struct z_stream_s {
  75008. Bytef *next_in; /* next input byte */
  75009. uInt avail_in; /* number of bytes available at next_in */
  75010. uLong total_in; /* total nb of input bytes read so far */
  75011. Bytef *next_out; /* next output byte should be put there */
  75012. uInt avail_out; /* remaining free space at next_out */
  75013. uLong total_out; /* total nb of bytes output so far */
  75014. char *msg; /* last error message, NULL if no error */
  75015. struct internal_state FAR *state; /* not visible by applications */
  75016. alloc_func zalloc; /* used to allocate the internal state */
  75017. free_func zfree; /* used to free the internal state */
  75018. voidpf opaque; /* private data object passed to zalloc and zfree */
  75019. int data_type; /* best guess about the data type: binary or text */
  75020. uLong adler; /* adler32 value of the uncompressed data */
  75021. uLong reserved; /* reserved for future use */
  75022. } z_stream;
  75023. typedef z_stream FAR *z_streamp;
  75024. typedef struct gz_header_s {
  75025. int text; /* true if compressed data believed to be text */
  75026. uLong time; /* modification time */
  75027. int xflags; /* extra flags (not used when writing a gzip file) */
  75028. int os; /* operating system */
  75029. Bytef *extra; /* pointer to extra field or Z_NULL if none */
  75030. uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
  75031. uInt extra_max; /* space at extra (only when reading header) */
  75032. Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
  75033. uInt name_max; /* space at name (only when reading header) */
  75034. Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
  75035. uInt comm_max; /* space at comment (only when reading header) */
  75036. int hcrc; /* true if there was or will be a header crc */
  75037. int done; /* true when done reading gzip header (not used
  75038. when writing a gzip file) */
  75039. } gz_header;
  75040. typedef gz_header FAR *gz_headerp;
  75041. #define Z_NO_FLUSH 0
  75042. #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
  75043. #define Z_SYNC_FLUSH 2
  75044. #define Z_FULL_FLUSH 3
  75045. #define Z_FINISH 4
  75046. #define Z_BLOCK 5
  75047. #define Z_OK 0
  75048. #define Z_STREAM_END 1
  75049. #define Z_NEED_DICT 2
  75050. #define Z_ERRNO (-1)
  75051. #define Z_STREAM_ERROR (-2)
  75052. #define Z_DATA_ERROR (-3)
  75053. #define Z_MEM_ERROR (-4)
  75054. #define Z_BUF_ERROR (-5)
  75055. #define Z_VERSION_ERROR (-6)
  75056. #define Z_NO_COMPRESSION 0
  75057. #define Z_BEST_SPEED 1
  75058. #define Z_BEST_COMPRESSION 9
  75059. #define Z_DEFAULT_COMPRESSION (-1)
  75060. #define Z_FILTERED 1
  75061. #define Z_HUFFMAN_ONLY 2
  75062. #define Z_RLE 3
  75063. #define Z_FIXED 4
  75064. #define Z_DEFAULT_STRATEGY 0
  75065. #define Z_BINARY 0
  75066. #define Z_TEXT 1
  75067. #define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
  75068. #define Z_UNKNOWN 2
  75069. #define Z_DEFLATED 8
  75070. #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
  75071. #define zlib_version zlibVersion()
  75072. //ZEXTERN const char * ZEXPORT zlibVersion OF((void));
  75073. ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
  75074. ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
  75075. ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
  75076. ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
  75077. ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
  75078. const Bytef *dictionary,
  75079. uInt dictLength));
  75080. ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
  75081. z_streamp source));
  75082. ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
  75083. ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
  75084. int level,
  75085. int strategy));
  75086. ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
  75087. int good_length,
  75088. int max_lazy,
  75089. int nice_length,
  75090. int max_chain));
  75091. ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
  75092. uLong sourceLen));
  75093. ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
  75094. int bits,
  75095. int value));
  75096. ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
  75097. gz_headerp head));
  75098. ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
  75099. const Bytef *dictionary,
  75100. uInt dictLength));
  75101. ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
  75102. ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
  75103. z_streamp source));
  75104. ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
  75105. ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
  75106. int bits,
  75107. int value));
  75108. ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
  75109. gz_headerp head));
  75110. typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
  75111. typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
  75112. ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
  75113. in_func in, void FAR *in_desc,
  75114. out_func out, void FAR *out_desc));
  75115. ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
  75116. //ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
  75117. ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
  75118. const Bytef *source, uLong sourceLen));
  75119. ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
  75120. const Bytef *source, uLong sourceLen,
  75121. int level));
  75122. ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
  75123. ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
  75124. const Bytef *source, uLong sourceLen));
  75125. typedef voidp gzFile;
  75126. ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
  75127. ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
  75128. ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
  75129. ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
  75130. ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
  75131. voidpc buf, unsigned len));
  75132. ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
  75133. ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
  75134. ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
  75135. ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
  75136. ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
  75137. ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
  75138. ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
  75139. ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
  75140. z_off_t offset, int whence));
  75141. ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
  75142. ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
  75143. ZEXTERN int ZEXPORT gzeof OF((gzFile file));
  75144. ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
  75145. ZEXTERN int ZEXPORT gzclose OF((gzFile file));
  75146. ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
  75147. ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
  75148. ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
  75149. ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
  75150. z_off_t len2));
  75151. ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
  75152. ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
  75153. ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
  75154. const char *version, int stream_size));
  75155. ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
  75156. const char *version, int stream_size));
  75157. ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
  75158. int windowBits, int memLevel,
  75159. int strategy, const char *version,
  75160. int stream_size));
  75161. ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
  75162. const char *version, int stream_size));
  75163. ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
  75164. unsigned char FAR *window,
  75165. const char *version,
  75166. int stream_size));
  75167. #define deflateInit(strm, level) \
  75168. deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
  75169. #define inflateInit(strm) \
  75170. inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
  75171. #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
  75172. deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
  75173. (strategy), ZLIB_VERSION, sizeof(z_stream))
  75174. #define inflateInit2(strm, windowBits) \
  75175. inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
  75176. #define inflateBackInit(strm, windowBits, window) \
  75177. inflateBackInit_((strm), (windowBits), (window), \
  75178. ZLIB_VERSION, sizeof(z_stream))
  75179. #if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
  75180. struct internal_state {int dummy;}; /* hack for buggy compilers */
  75181. #endif
  75182. ZEXTERN const char * ZEXPORT zError OF((int));
  75183. ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
  75184. ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
  75185. #ifdef __cplusplus
  75186. }
  75187. #endif
  75188. #endif /* ZLIB_H */
  75189. /*** End of inlined file: zlib.h ***/
  75190. #undef OS_CODE
  75191. #else
  75192. #include <zlib.h>
  75193. #endif
  75194. }
  75195. BEGIN_JUCE_NAMESPACE
  75196. // internal helper object that holds the zlib structures so they don't have to be
  75197. // included publicly.
  75198. class GZIPCompressorHelper
  75199. {
  75200. public:
  75201. GZIPCompressorHelper (const int compressionLevel, const bool nowrap)
  75202. : data (0),
  75203. dataSize (0),
  75204. compLevel (compressionLevel),
  75205. strategy (0),
  75206. setParams (true),
  75207. streamIsValid (false),
  75208. finished (false),
  75209. shouldFinish (false)
  75210. {
  75211. using namespace zlibNamespace;
  75212. zerostruct (stream);
  75213. streamIsValid = (deflateInit2 (&stream, compLevel, Z_DEFLATED,
  75214. nowrap ? -MAX_WBITS : MAX_WBITS,
  75215. 8, strategy) == Z_OK);
  75216. }
  75217. ~GZIPCompressorHelper()
  75218. {
  75219. using namespace zlibNamespace;
  75220. if (streamIsValid)
  75221. deflateEnd (&stream);
  75222. }
  75223. bool needsInput() const throw()
  75224. {
  75225. return dataSize <= 0;
  75226. }
  75227. void setInput (uint8* const newData, const int size) throw()
  75228. {
  75229. data = newData;
  75230. dataSize = size;
  75231. }
  75232. int doNextBlock (uint8* const dest, const int destSize) throw()
  75233. {
  75234. using namespace zlibNamespace;
  75235. if (streamIsValid)
  75236. {
  75237. stream.next_in = data;
  75238. stream.next_out = dest;
  75239. stream.avail_in = dataSize;
  75240. stream.avail_out = destSize;
  75241. const int result = setParams ? deflateParams (&stream, compLevel, strategy)
  75242. : deflate (&stream, shouldFinish ? Z_FINISH : Z_NO_FLUSH);
  75243. setParams = false;
  75244. switch (result)
  75245. {
  75246. case Z_STREAM_END:
  75247. finished = true;
  75248. // Deliberate fall-through..
  75249. case Z_OK:
  75250. data += dataSize - stream.avail_in;
  75251. dataSize = stream.avail_in;
  75252. return destSize - stream.avail_out;
  75253. default:
  75254. break;
  75255. }
  75256. }
  75257. return 0;
  75258. }
  75259. private:
  75260. zlibNamespace::z_stream stream;
  75261. uint8* data;
  75262. int dataSize, compLevel, strategy;
  75263. bool setParams, streamIsValid;
  75264. public:
  75265. bool finished, shouldFinish;
  75266. };
  75267. const int gzipCompBufferSize = 32768;
  75268. GZIPCompressorOutputStream::GZIPCompressorOutputStream (OutputStream* const destStream_,
  75269. int compressionLevel,
  75270. const bool deleteDestStream,
  75271. const bool noWrap)
  75272. : destStream (destStream_),
  75273. streamToDelete (deleteDestStream ? destStream_ : 0),
  75274. buffer (gzipCompBufferSize)
  75275. {
  75276. if (compressionLevel < 1 || compressionLevel > 9)
  75277. compressionLevel = -1;
  75278. helper = new GZIPCompressorHelper (compressionLevel, noWrap);
  75279. }
  75280. GZIPCompressorOutputStream::~GZIPCompressorOutputStream()
  75281. {
  75282. flush();
  75283. }
  75284. void GZIPCompressorOutputStream::flush()
  75285. {
  75286. if (! helper->finished)
  75287. {
  75288. helper->shouldFinish = true;
  75289. while (! helper->finished)
  75290. doNextBlock();
  75291. }
  75292. destStream->flush();
  75293. }
  75294. bool GZIPCompressorOutputStream::write (const void* destBuffer, int howMany)
  75295. {
  75296. if (! helper->finished)
  75297. {
  75298. helper->setInput ((uint8*) destBuffer, howMany);
  75299. while (! helper->needsInput())
  75300. {
  75301. if (! doNextBlock())
  75302. return false;
  75303. }
  75304. }
  75305. return true;
  75306. }
  75307. bool GZIPCompressorOutputStream::doNextBlock()
  75308. {
  75309. const int len = helper->doNextBlock (buffer, gzipCompBufferSize);
  75310. if (len > 0)
  75311. return destStream->write (buffer, len);
  75312. else
  75313. return true;
  75314. }
  75315. int64 GZIPCompressorOutputStream::getPosition()
  75316. {
  75317. return destStream->getPosition();
  75318. }
  75319. bool GZIPCompressorOutputStream::setPosition (int64 /*newPosition*/)
  75320. {
  75321. jassertfalse // can't do it!
  75322. return false;
  75323. }
  75324. END_JUCE_NAMESPACE
  75325. /*** End of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  75326. /*** Start of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  75327. #if JUCE_MSVC
  75328. #pragma warning (push)
  75329. #pragma warning (disable: 4309 4305)
  75330. #endif
  75331. namespace zlibNamespace
  75332. {
  75333. #if JUCE_INCLUDE_ZLIB_CODE
  75334. extern "C"
  75335. {
  75336. #undef OS_CODE
  75337. #undef fdopen
  75338. #define ZLIB_INTERNAL
  75339. #define NO_DUMMY_DECL
  75340. /*** Start of inlined file: adler32.c ***/
  75341. #define ZLIB_INTERNAL
  75342. #define BASE 65521UL /* largest prime smaller than 65536 */
  75343. #define NMAX 5552
  75344. #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
  75345. #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
  75346. #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
  75347. #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
  75348. #define DO16(buf) DO8(buf,0); DO8(buf,8);
  75349. #ifdef NO_DIVIDE
  75350. # define MOD(a) \
  75351. do { \
  75352. if (a >= (BASE << 16)) a -= (BASE << 16); \
  75353. if (a >= (BASE << 15)) a -= (BASE << 15); \
  75354. if (a >= (BASE << 14)) a -= (BASE << 14); \
  75355. if (a >= (BASE << 13)) a -= (BASE << 13); \
  75356. if (a >= (BASE << 12)) a -= (BASE << 12); \
  75357. if (a >= (BASE << 11)) a -= (BASE << 11); \
  75358. if (a >= (BASE << 10)) a -= (BASE << 10); \
  75359. if (a >= (BASE << 9)) a -= (BASE << 9); \
  75360. if (a >= (BASE << 8)) a -= (BASE << 8); \
  75361. if (a >= (BASE << 7)) a -= (BASE << 7); \
  75362. if (a >= (BASE << 6)) a -= (BASE << 6); \
  75363. if (a >= (BASE << 5)) a -= (BASE << 5); \
  75364. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75365. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75366. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75367. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75368. if (a >= BASE) a -= BASE; \
  75369. } while (0)
  75370. # define MOD4(a) \
  75371. do { \
  75372. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75373. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75374. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75375. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75376. if (a >= BASE) a -= BASE; \
  75377. } while (0)
  75378. #else
  75379. # define MOD(a) a %= BASE
  75380. # define MOD4(a) a %= BASE
  75381. #endif
  75382. uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
  75383. {
  75384. unsigned long sum2;
  75385. unsigned n;
  75386. sum2 = (adler >> 16) & 0xffff;
  75387. adler &= 0xffff;
  75388. if (len == 1) {
  75389. adler += buf[0];
  75390. if (adler >= BASE)
  75391. adler -= BASE;
  75392. sum2 += adler;
  75393. if (sum2 >= BASE)
  75394. sum2 -= BASE;
  75395. return adler | (sum2 << 16);
  75396. }
  75397. if (buf == Z_NULL)
  75398. return 1L;
  75399. if (len < 16) {
  75400. while (len--) {
  75401. adler += *buf++;
  75402. sum2 += adler;
  75403. }
  75404. if (adler >= BASE)
  75405. adler -= BASE;
  75406. MOD4(sum2); /* only added so many BASE's */
  75407. return adler | (sum2 << 16);
  75408. }
  75409. while (len >= NMAX) {
  75410. len -= NMAX;
  75411. n = NMAX / 16; /* NMAX is divisible by 16 */
  75412. do {
  75413. DO16(buf); /* 16 sums unrolled */
  75414. buf += 16;
  75415. } while (--n);
  75416. MOD(adler);
  75417. MOD(sum2);
  75418. }
  75419. if (len) { /* avoid modulos if none remaining */
  75420. while (len >= 16) {
  75421. len -= 16;
  75422. DO16(buf);
  75423. buf += 16;
  75424. }
  75425. while (len--) {
  75426. adler += *buf++;
  75427. sum2 += adler;
  75428. }
  75429. MOD(adler);
  75430. MOD(sum2);
  75431. }
  75432. return adler | (sum2 << 16);
  75433. }
  75434. uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2)
  75435. {
  75436. unsigned long sum1;
  75437. unsigned long sum2;
  75438. unsigned rem;
  75439. rem = (unsigned)(len2 % BASE);
  75440. sum1 = adler1 & 0xffff;
  75441. sum2 = rem * sum1;
  75442. MOD(sum2);
  75443. sum1 += (adler2 & 0xffff) + BASE - 1;
  75444. sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
  75445. if (sum1 > BASE) sum1 -= BASE;
  75446. if (sum1 > BASE) sum1 -= BASE;
  75447. if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
  75448. if (sum2 > BASE) sum2 -= BASE;
  75449. return sum1 | (sum2 << 16);
  75450. }
  75451. /*** End of inlined file: adler32.c ***/
  75452. /*** Start of inlined file: compress.c ***/
  75453. #define ZLIB_INTERNAL
  75454. int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source,
  75455. uLong sourceLen, int level)
  75456. {
  75457. z_stream stream;
  75458. int err;
  75459. stream.next_in = (Bytef*)source;
  75460. stream.avail_in = (uInt)sourceLen;
  75461. #ifdef MAXSEG_64K
  75462. if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
  75463. #endif
  75464. stream.next_out = dest;
  75465. stream.avail_out = (uInt)*destLen;
  75466. if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
  75467. stream.zalloc = (alloc_func)0;
  75468. stream.zfree = (free_func)0;
  75469. stream.opaque = (voidpf)0;
  75470. err = deflateInit(&stream, level);
  75471. if (err != Z_OK) return err;
  75472. err = deflate(&stream, Z_FINISH);
  75473. if (err != Z_STREAM_END) {
  75474. deflateEnd(&stream);
  75475. return err == Z_OK ? Z_BUF_ERROR : err;
  75476. }
  75477. *destLen = stream.total_out;
  75478. err = deflateEnd(&stream);
  75479. return err;
  75480. }
  75481. int ZEXPORT compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
  75482. {
  75483. return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
  75484. }
  75485. uLong ZEXPORT compressBound (uLong sourceLen)
  75486. {
  75487. return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
  75488. }
  75489. /*** End of inlined file: compress.c ***/
  75490. #undef DO1
  75491. #undef DO8
  75492. /*** Start of inlined file: crc32.c ***/
  75493. #ifdef MAKECRCH
  75494. # include <stdio.h>
  75495. # ifndef DYNAMIC_CRC_TABLE
  75496. # define DYNAMIC_CRC_TABLE
  75497. # endif /* !DYNAMIC_CRC_TABLE */
  75498. #endif /* MAKECRCH */
  75499. /*** Start of inlined file: zutil.h ***/
  75500. #ifndef ZUTIL_H
  75501. #define ZUTIL_H
  75502. #define ZLIB_INTERNAL
  75503. #ifdef STDC
  75504. # ifndef _WIN32_WCE
  75505. # include <stddef.h>
  75506. # endif
  75507. # include <string.h>
  75508. # include <stdlib.h>
  75509. #endif
  75510. #ifdef NO_ERRNO_H
  75511. # ifdef _WIN32_WCE
  75512. # define errno z_errno
  75513. # endif
  75514. extern int errno;
  75515. #else
  75516. # ifndef _WIN32_WCE
  75517. # include <errno.h>
  75518. # endif
  75519. #endif
  75520. #ifndef local
  75521. # define local static
  75522. #endif
  75523. typedef unsigned char uch;
  75524. typedef uch FAR uchf;
  75525. typedef unsigned short ush;
  75526. typedef ush FAR ushf;
  75527. typedef unsigned long ulg;
  75528. extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
  75529. #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
  75530. #define ERR_RETURN(strm,err) \
  75531. return (strm->msg = (char*)ERR_MSG(err), (err))
  75532. #ifndef DEF_WBITS
  75533. # define DEF_WBITS MAX_WBITS
  75534. #endif
  75535. #if MAX_MEM_LEVEL >= 8
  75536. # define DEF_MEM_LEVEL 8
  75537. #else
  75538. # define DEF_MEM_LEVEL MAX_MEM_LEVEL
  75539. #endif
  75540. #define STORED_BLOCK 0
  75541. #define STATIC_TREES 1
  75542. #define DYN_TREES 2
  75543. #define MIN_MATCH 3
  75544. #define MAX_MATCH 258
  75545. #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
  75546. #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
  75547. # define OS_CODE 0x00
  75548. # if defined(__TURBOC__) || defined(__BORLANDC__)
  75549. # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
  75550. void _Cdecl farfree( void *block );
  75551. void *_Cdecl farmalloc( unsigned long nbytes );
  75552. # else
  75553. # include <alloc.h>
  75554. # endif
  75555. # else /* MSC or DJGPP */
  75556. # include <malloc.h>
  75557. # endif
  75558. #endif
  75559. #ifdef AMIGA
  75560. # define OS_CODE 0x01
  75561. #endif
  75562. #if defined(VAXC) || defined(VMS)
  75563. # define OS_CODE 0x02
  75564. # define F_OPEN(name, mode) \
  75565. fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
  75566. #endif
  75567. #if defined(ATARI) || defined(atarist)
  75568. # define OS_CODE 0x05
  75569. #endif
  75570. #ifdef OS2
  75571. # define OS_CODE 0x06
  75572. # ifdef M_I86
  75573. #include <malloc.h>
  75574. # endif
  75575. #endif
  75576. #if defined(MACOS) || TARGET_OS_MAC
  75577. # define OS_CODE 0x07
  75578. # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
  75579. # include <unix.h> /* for fdopen */
  75580. # else
  75581. # ifndef fdopen
  75582. # define fdopen(fd,mode) NULL /* No fdopen() */
  75583. # endif
  75584. # endif
  75585. #endif
  75586. #ifdef TOPS20
  75587. # define OS_CODE 0x0a
  75588. #endif
  75589. #ifdef WIN32
  75590. # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
  75591. # define OS_CODE 0x0b
  75592. # endif
  75593. #endif
  75594. #ifdef __50SERIES /* Prime/PRIMOS */
  75595. # define OS_CODE 0x0f
  75596. #endif
  75597. #if defined(_BEOS_) || defined(RISCOS)
  75598. # define fdopen(fd,mode) NULL /* No fdopen() */
  75599. #endif
  75600. #if (defined(_MSC_VER) && (_MSC_VER > 600))
  75601. # if defined(_WIN32_WCE)
  75602. # define fdopen(fd,mode) NULL /* No fdopen() */
  75603. # ifndef _PTRDIFF_T_DEFINED
  75604. typedef int ptrdiff_t;
  75605. # define _PTRDIFF_T_DEFINED
  75606. # endif
  75607. # else
  75608. # define fdopen(fd,type) _fdopen(fd,type)
  75609. # endif
  75610. #endif
  75611. #ifndef OS_CODE
  75612. # define OS_CODE 0x03 /* assume Unix */
  75613. #endif
  75614. #ifndef F_OPEN
  75615. # define F_OPEN(name, mode) fopen((name), (mode))
  75616. #endif
  75617. #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
  75618. # ifndef HAVE_VSNPRINTF
  75619. # define HAVE_VSNPRINTF
  75620. # endif
  75621. #endif
  75622. #if defined(__CYGWIN__)
  75623. # ifndef HAVE_VSNPRINTF
  75624. # define HAVE_VSNPRINTF
  75625. # endif
  75626. #endif
  75627. #ifndef HAVE_VSNPRINTF
  75628. # ifdef MSDOS
  75629. # define NO_vsnprintf
  75630. # endif
  75631. # ifdef __TURBOC__
  75632. # define NO_vsnprintf
  75633. # endif
  75634. # ifdef WIN32
  75635. # if !defined(vsnprintf) && !defined(NO_vsnprintf)
  75636. # define vsnprintf _vsnprintf
  75637. # endif
  75638. # endif
  75639. # ifdef __SASC
  75640. # define NO_vsnprintf
  75641. # endif
  75642. #endif
  75643. #ifdef VMS
  75644. # define NO_vsnprintf
  75645. #endif
  75646. #if defined(pyr)
  75647. # define NO_MEMCPY
  75648. #endif
  75649. #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
  75650. # define NO_MEMCPY
  75651. #endif
  75652. #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
  75653. # define HAVE_MEMCPY
  75654. #endif
  75655. #ifdef HAVE_MEMCPY
  75656. # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
  75657. # define zmemcpy _fmemcpy
  75658. # define zmemcmp _fmemcmp
  75659. # define zmemzero(dest, len) _fmemset(dest, 0, len)
  75660. # else
  75661. # define zmemcpy memcpy
  75662. # define zmemcmp memcmp
  75663. # define zmemzero(dest, len) memset(dest, 0, len)
  75664. # endif
  75665. #else
  75666. extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
  75667. extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
  75668. extern void zmemzero OF((Bytef* dest, uInt len));
  75669. #endif
  75670. #ifdef DEBUG
  75671. # include <stdio.h>
  75672. extern int z_verbose;
  75673. extern void z_error OF((const char *m));
  75674. # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
  75675. # define Trace(x) {if (z_verbose>=0) fprintf x ;}
  75676. # define Tracev(x) {if (z_verbose>0) fprintf x ;}
  75677. # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
  75678. # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
  75679. # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
  75680. #else
  75681. # define Assert(cond,msg)
  75682. # define Trace(x)
  75683. # define Tracev(x)
  75684. # define Tracevv(x)
  75685. # define Tracec(c,x)
  75686. # define Tracecv(c,x)
  75687. #endif
  75688. voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
  75689. void zcfree OF((voidpf opaque, voidpf ptr));
  75690. #define ZALLOC(strm, items, size) \
  75691. (*((strm)->zalloc))((strm)->opaque, (items), (size))
  75692. #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
  75693. #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
  75694. #endif /* ZUTIL_H */
  75695. /*** End of inlined file: zutil.h ***/
  75696. /* for STDC and FAR definitions */
  75697. #define local static
  75698. #ifndef NOBYFOUR
  75699. # ifdef STDC /* need ANSI C limits.h to determine sizes */
  75700. # include <limits.h>
  75701. # define BYFOUR
  75702. # if (UINT_MAX == 0xffffffffUL)
  75703. typedef unsigned int u4;
  75704. # else
  75705. # if (ULONG_MAX == 0xffffffffUL)
  75706. typedef unsigned long u4;
  75707. # else
  75708. # if (USHRT_MAX == 0xffffffffUL)
  75709. typedef unsigned short u4;
  75710. # else
  75711. # undef BYFOUR /* can't find a four-byte integer type! */
  75712. # endif
  75713. # endif
  75714. # endif
  75715. # endif /* STDC */
  75716. #endif /* !NOBYFOUR */
  75717. #ifdef BYFOUR
  75718. # define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
  75719. (((w)&0xff00)<<8)+(((w)&0xff)<<24))
  75720. local unsigned long crc32_little OF((unsigned long,
  75721. const unsigned char FAR *, unsigned));
  75722. local unsigned long crc32_big OF((unsigned long,
  75723. const unsigned char FAR *, unsigned));
  75724. # define TBLS 8
  75725. #else
  75726. # define TBLS 1
  75727. #endif /* BYFOUR */
  75728. local unsigned long gf2_matrix_times OF((unsigned long *mat,
  75729. unsigned long vec));
  75730. local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
  75731. #ifdef DYNAMIC_CRC_TABLE
  75732. local volatile int crc_table_empty = 1;
  75733. local unsigned long FAR crc_table[TBLS][256];
  75734. local void make_crc_table OF((void));
  75735. #ifdef MAKECRCH
  75736. local void write_table OF((FILE *, const unsigned long FAR *));
  75737. #endif /* MAKECRCH */
  75738. local void make_crc_table()
  75739. {
  75740. unsigned long c;
  75741. int n, k;
  75742. unsigned long poly; /* polynomial exclusive-or pattern */
  75743. static volatile int first = 1; /* flag to limit concurrent making */
  75744. static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
  75745. if (first) {
  75746. first = 0;
  75747. poly = 0UL;
  75748. for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
  75749. poly |= 1UL << (31 - p[n]);
  75750. for (n = 0; n < 256; n++) {
  75751. c = (unsigned long)n;
  75752. for (k = 0; k < 8; k++)
  75753. c = c & 1 ? poly ^ (c >> 1) : c >> 1;
  75754. crc_table[0][n] = c;
  75755. }
  75756. #ifdef BYFOUR
  75757. for (n = 0; n < 256; n++) {
  75758. c = crc_table[0][n];
  75759. crc_table[4][n] = REV(c);
  75760. for (k = 1; k < 4; k++) {
  75761. c = crc_table[0][c & 0xff] ^ (c >> 8);
  75762. crc_table[k][n] = c;
  75763. crc_table[k + 4][n] = REV(c);
  75764. }
  75765. }
  75766. #endif /* BYFOUR */
  75767. crc_table_empty = 0;
  75768. }
  75769. else { /* not first */
  75770. while (crc_table_empty)
  75771. ;
  75772. }
  75773. #ifdef MAKECRCH
  75774. {
  75775. FILE *out;
  75776. out = fopen("crc32.h", "w");
  75777. if (out == NULL) return;
  75778. fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
  75779. fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
  75780. fprintf(out, "local const unsigned long FAR ");
  75781. fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
  75782. write_table(out, crc_table[0]);
  75783. # ifdef BYFOUR
  75784. fprintf(out, "#ifdef BYFOUR\n");
  75785. for (k = 1; k < 8; k++) {
  75786. fprintf(out, " },\n {\n");
  75787. write_table(out, crc_table[k]);
  75788. }
  75789. fprintf(out, "#endif\n");
  75790. # endif /* BYFOUR */
  75791. fprintf(out, " }\n};\n");
  75792. fclose(out);
  75793. }
  75794. #endif /* MAKECRCH */
  75795. }
  75796. #ifdef MAKECRCH
  75797. local void write_table(out, table)
  75798. FILE *out;
  75799. const unsigned long FAR *table;
  75800. {
  75801. int n;
  75802. for (n = 0; n < 256; n++)
  75803. fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
  75804. n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
  75805. }
  75806. #endif /* MAKECRCH */
  75807. #else /* !DYNAMIC_CRC_TABLE */
  75808. /*** Start of inlined file: crc32.h ***/
  75809. local const unsigned long FAR crc_table[TBLS][256] =
  75810. {
  75811. {
  75812. 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
  75813. 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
  75814. 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
  75815. 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
  75816. 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
  75817. 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
  75818. 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
  75819. 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
  75820. 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
  75821. 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
  75822. 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
  75823. 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
  75824. 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
  75825. 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
  75826. 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
  75827. 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
  75828. 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
  75829. 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
  75830. 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
  75831. 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
  75832. 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
  75833. 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
  75834. 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
  75835. 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
  75836. 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
  75837. 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
  75838. 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
  75839. 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
  75840. 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
  75841. 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
  75842. 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
  75843. 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
  75844. 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
  75845. 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
  75846. 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
  75847. 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
  75848. 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
  75849. 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
  75850. 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
  75851. 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
  75852. 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
  75853. 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
  75854. 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
  75855. 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
  75856. 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
  75857. 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
  75858. 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
  75859. 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
  75860. 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
  75861. 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
  75862. 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
  75863. 0x2d02ef8dUL
  75864. #ifdef BYFOUR
  75865. },
  75866. {
  75867. 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL,
  75868. 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL,
  75869. 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL,
  75870. 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL,
  75871. 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL,
  75872. 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL,
  75873. 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL,
  75874. 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL,
  75875. 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL,
  75876. 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL,
  75877. 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL,
  75878. 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL,
  75879. 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL,
  75880. 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL,
  75881. 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL,
  75882. 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL,
  75883. 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL,
  75884. 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL,
  75885. 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL,
  75886. 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL,
  75887. 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL,
  75888. 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL,
  75889. 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL,
  75890. 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL,
  75891. 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL,
  75892. 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL,
  75893. 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL,
  75894. 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL,
  75895. 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL,
  75896. 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL,
  75897. 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL,
  75898. 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL,
  75899. 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL,
  75900. 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL,
  75901. 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL,
  75902. 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL,
  75903. 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL,
  75904. 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL,
  75905. 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL,
  75906. 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL,
  75907. 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL,
  75908. 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL,
  75909. 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL,
  75910. 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL,
  75911. 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL,
  75912. 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL,
  75913. 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL,
  75914. 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL,
  75915. 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL,
  75916. 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL,
  75917. 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL,
  75918. 0x9324fd72UL
  75919. },
  75920. {
  75921. 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL,
  75922. 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL,
  75923. 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL,
  75924. 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL,
  75925. 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL,
  75926. 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL,
  75927. 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL,
  75928. 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL,
  75929. 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL,
  75930. 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL,
  75931. 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL,
  75932. 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL,
  75933. 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL,
  75934. 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL,
  75935. 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL,
  75936. 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL,
  75937. 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL,
  75938. 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL,
  75939. 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL,
  75940. 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL,
  75941. 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL,
  75942. 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL,
  75943. 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL,
  75944. 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL,
  75945. 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL,
  75946. 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL,
  75947. 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL,
  75948. 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL,
  75949. 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL,
  75950. 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL,
  75951. 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL,
  75952. 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL,
  75953. 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL,
  75954. 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL,
  75955. 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL,
  75956. 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL,
  75957. 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL,
  75958. 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL,
  75959. 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL,
  75960. 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL,
  75961. 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL,
  75962. 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL,
  75963. 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL,
  75964. 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL,
  75965. 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL,
  75966. 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL,
  75967. 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL,
  75968. 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL,
  75969. 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL,
  75970. 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL,
  75971. 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL,
  75972. 0xbe9834edUL
  75973. },
  75974. {
  75975. 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL,
  75976. 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL,
  75977. 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL,
  75978. 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL,
  75979. 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL,
  75980. 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL,
  75981. 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL,
  75982. 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL,
  75983. 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL,
  75984. 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL,
  75985. 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL,
  75986. 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL,
  75987. 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL,
  75988. 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL,
  75989. 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL,
  75990. 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL,
  75991. 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL,
  75992. 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL,
  75993. 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL,
  75994. 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL,
  75995. 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL,
  75996. 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL,
  75997. 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL,
  75998. 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL,
  75999. 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL,
  76000. 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL,
  76001. 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL,
  76002. 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL,
  76003. 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL,
  76004. 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL,
  76005. 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL,
  76006. 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL,
  76007. 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL,
  76008. 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL,
  76009. 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL,
  76010. 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL,
  76011. 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL,
  76012. 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL,
  76013. 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL,
  76014. 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL,
  76015. 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL,
  76016. 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL,
  76017. 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL,
  76018. 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL,
  76019. 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL,
  76020. 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL,
  76021. 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL,
  76022. 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL,
  76023. 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL,
  76024. 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL,
  76025. 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL,
  76026. 0xde0506f1UL
  76027. },
  76028. {
  76029. 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL,
  76030. 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL,
  76031. 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL,
  76032. 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL,
  76033. 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL,
  76034. 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL,
  76035. 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL,
  76036. 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL,
  76037. 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL,
  76038. 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL,
  76039. 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL,
  76040. 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL,
  76041. 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL,
  76042. 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL,
  76043. 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL,
  76044. 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL,
  76045. 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL,
  76046. 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL,
  76047. 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL,
  76048. 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL,
  76049. 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL,
  76050. 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL,
  76051. 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL,
  76052. 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL,
  76053. 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL,
  76054. 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL,
  76055. 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL,
  76056. 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL,
  76057. 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL,
  76058. 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL,
  76059. 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL,
  76060. 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL,
  76061. 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL,
  76062. 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL,
  76063. 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL,
  76064. 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL,
  76065. 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL,
  76066. 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL,
  76067. 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL,
  76068. 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL,
  76069. 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL,
  76070. 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL,
  76071. 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL,
  76072. 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL,
  76073. 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL,
  76074. 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL,
  76075. 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL,
  76076. 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL,
  76077. 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL,
  76078. 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL,
  76079. 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL,
  76080. 0x8def022dUL
  76081. },
  76082. {
  76083. 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL,
  76084. 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL,
  76085. 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL,
  76086. 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL,
  76087. 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL,
  76088. 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL,
  76089. 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL,
  76090. 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL,
  76091. 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL,
  76092. 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL,
  76093. 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL,
  76094. 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL,
  76095. 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL,
  76096. 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL,
  76097. 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL,
  76098. 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL,
  76099. 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL,
  76100. 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL,
  76101. 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL,
  76102. 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL,
  76103. 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL,
  76104. 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL,
  76105. 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL,
  76106. 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL,
  76107. 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL,
  76108. 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL,
  76109. 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL,
  76110. 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL,
  76111. 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL,
  76112. 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL,
  76113. 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL,
  76114. 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL,
  76115. 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL,
  76116. 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL,
  76117. 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL,
  76118. 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL,
  76119. 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL,
  76120. 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL,
  76121. 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL,
  76122. 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL,
  76123. 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL,
  76124. 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL,
  76125. 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL,
  76126. 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL,
  76127. 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL,
  76128. 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL,
  76129. 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL,
  76130. 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL,
  76131. 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL,
  76132. 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL,
  76133. 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL,
  76134. 0x72fd2493UL
  76135. },
  76136. {
  76137. 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL,
  76138. 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL,
  76139. 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL,
  76140. 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL,
  76141. 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL,
  76142. 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL,
  76143. 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL,
  76144. 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL,
  76145. 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL,
  76146. 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL,
  76147. 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL,
  76148. 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL,
  76149. 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL,
  76150. 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL,
  76151. 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL,
  76152. 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL,
  76153. 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL,
  76154. 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL,
  76155. 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL,
  76156. 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL,
  76157. 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL,
  76158. 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL,
  76159. 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL,
  76160. 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL,
  76161. 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL,
  76162. 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL,
  76163. 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL,
  76164. 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL,
  76165. 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL,
  76166. 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL,
  76167. 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL,
  76168. 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL,
  76169. 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL,
  76170. 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL,
  76171. 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL,
  76172. 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL,
  76173. 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL,
  76174. 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL,
  76175. 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL,
  76176. 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL,
  76177. 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL,
  76178. 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL,
  76179. 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL,
  76180. 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL,
  76181. 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL,
  76182. 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL,
  76183. 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL,
  76184. 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL,
  76185. 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL,
  76186. 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL,
  76187. 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL,
  76188. 0xed3498beUL
  76189. },
  76190. {
  76191. 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL,
  76192. 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL,
  76193. 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL,
  76194. 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL,
  76195. 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL,
  76196. 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL,
  76197. 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL,
  76198. 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL,
  76199. 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL,
  76200. 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL,
  76201. 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL,
  76202. 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL,
  76203. 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL,
  76204. 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL,
  76205. 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL,
  76206. 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL,
  76207. 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL,
  76208. 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL,
  76209. 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL,
  76210. 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL,
  76211. 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL,
  76212. 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL,
  76213. 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL,
  76214. 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL,
  76215. 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL,
  76216. 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL,
  76217. 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL,
  76218. 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL,
  76219. 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL,
  76220. 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL,
  76221. 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL,
  76222. 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL,
  76223. 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL,
  76224. 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL,
  76225. 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL,
  76226. 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL,
  76227. 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL,
  76228. 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL,
  76229. 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL,
  76230. 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL,
  76231. 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL,
  76232. 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL,
  76233. 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL,
  76234. 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL,
  76235. 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL,
  76236. 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL,
  76237. 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL,
  76238. 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL,
  76239. 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL,
  76240. 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL,
  76241. 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL,
  76242. 0xf10605deUL
  76243. #endif
  76244. }
  76245. };
  76246. /*** End of inlined file: crc32.h ***/
  76247. #endif /* DYNAMIC_CRC_TABLE */
  76248. const unsigned long FAR * ZEXPORT get_crc_table()
  76249. {
  76250. #ifdef DYNAMIC_CRC_TABLE
  76251. if (crc_table_empty)
  76252. make_crc_table();
  76253. #endif /* DYNAMIC_CRC_TABLE */
  76254. return (const unsigned long FAR *)crc_table;
  76255. }
  76256. #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
  76257. #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
  76258. unsigned long ZEXPORT crc32 (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76259. {
  76260. if (buf == Z_NULL) return 0UL;
  76261. #ifdef DYNAMIC_CRC_TABLE
  76262. if (crc_table_empty)
  76263. make_crc_table();
  76264. #endif /* DYNAMIC_CRC_TABLE */
  76265. #ifdef BYFOUR
  76266. if (sizeof(void *) == sizeof(ptrdiff_t)) {
  76267. u4 endian;
  76268. endian = 1;
  76269. if (*((unsigned char *)(&endian)))
  76270. return crc32_little(crc, buf, len);
  76271. else
  76272. return crc32_big(crc, buf, len);
  76273. }
  76274. #endif /* BYFOUR */
  76275. crc = crc ^ 0xffffffffUL;
  76276. while (len >= 8) {
  76277. DO8;
  76278. len -= 8;
  76279. }
  76280. if (len) do {
  76281. DO1;
  76282. } while (--len);
  76283. return crc ^ 0xffffffffUL;
  76284. }
  76285. #ifdef BYFOUR
  76286. #define DOLIT4 c ^= *buf4++; \
  76287. c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
  76288. crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
  76289. #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
  76290. local unsigned long crc32_little(unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76291. {
  76292. register u4 c;
  76293. register const u4 FAR *buf4;
  76294. c = (u4)crc;
  76295. c = ~c;
  76296. while (len && ((ptrdiff_t)buf & 3)) {
  76297. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76298. len--;
  76299. }
  76300. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76301. while (len >= 32) {
  76302. DOLIT32;
  76303. len -= 32;
  76304. }
  76305. while (len >= 4) {
  76306. DOLIT4;
  76307. len -= 4;
  76308. }
  76309. buf = (const unsigned char FAR *)buf4;
  76310. if (len) do {
  76311. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76312. } while (--len);
  76313. c = ~c;
  76314. return (unsigned long)c;
  76315. }
  76316. #define DOBIG4 c ^= *++buf4; \
  76317. c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
  76318. crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
  76319. #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
  76320. local unsigned long crc32_big (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76321. {
  76322. register u4 c;
  76323. register const u4 FAR *buf4;
  76324. c = REV((u4)crc);
  76325. c = ~c;
  76326. while (len && ((ptrdiff_t)buf & 3)) {
  76327. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76328. len--;
  76329. }
  76330. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76331. buf4--;
  76332. while (len >= 32) {
  76333. DOBIG32;
  76334. len -= 32;
  76335. }
  76336. while (len >= 4) {
  76337. DOBIG4;
  76338. len -= 4;
  76339. }
  76340. buf4++;
  76341. buf = (const unsigned char FAR *)buf4;
  76342. if (len) do {
  76343. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76344. } while (--len);
  76345. c = ~c;
  76346. return (unsigned long)(REV(c));
  76347. }
  76348. #endif /* BYFOUR */
  76349. #define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
  76350. local unsigned long gf2_matrix_times (unsigned long *mat, unsigned long vec)
  76351. {
  76352. unsigned long sum;
  76353. sum = 0;
  76354. while (vec) {
  76355. if (vec & 1)
  76356. sum ^= *mat;
  76357. vec >>= 1;
  76358. mat++;
  76359. }
  76360. return sum;
  76361. }
  76362. local void gf2_matrix_square (unsigned long *square, unsigned long *mat)
  76363. {
  76364. int n;
  76365. for (n = 0; n < GF2_DIM; n++)
  76366. square[n] = gf2_matrix_times(mat, mat[n]);
  76367. }
  76368. uLong ZEXPORT crc32_combine (uLong crc1, uLong crc2, z_off_t len2)
  76369. {
  76370. int n;
  76371. unsigned long row;
  76372. unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
  76373. unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
  76374. if (len2 == 0)
  76375. return crc1;
  76376. odd[0] = 0xedb88320L; /* CRC-32 polynomial */
  76377. row = 1;
  76378. for (n = 1; n < GF2_DIM; n++) {
  76379. odd[n] = row;
  76380. row <<= 1;
  76381. }
  76382. gf2_matrix_square(even, odd);
  76383. gf2_matrix_square(odd, even);
  76384. do {
  76385. gf2_matrix_square(even, odd);
  76386. if (len2 & 1)
  76387. crc1 = gf2_matrix_times(even, crc1);
  76388. len2 >>= 1;
  76389. if (len2 == 0)
  76390. break;
  76391. gf2_matrix_square(odd, even);
  76392. if (len2 & 1)
  76393. crc1 = gf2_matrix_times(odd, crc1);
  76394. len2 >>= 1;
  76395. } while (len2 != 0);
  76396. crc1 ^= crc2;
  76397. return crc1;
  76398. }
  76399. /*** End of inlined file: crc32.c ***/
  76400. /*** Start of inlined file: deflate.c ***/
  76401. /*** Start of inlined file: deflate.h ***/
  76402. #ifndef DEFLATE_H
  76403. #define DEFLATE_H
  76404. #ifndef NO_GZIP
  76405. # define GZIP
  76406. #endif
  76407. #define NO_DUMMY_DECL
  76408. #define LENGTH_CODES 29
  76409. #define LITERALS 256
  76410. #define L_CODES (LITERALS+1+LENGTH_CODES)
  76411. #define D_CODES 30
  76412. #define BL_CODES 19
  76413. #define HEAP_SIZE (2*L_CODES+1)
  76414. #define MAX_BITS 15
  76415. #define INIT_STATE 42
  76416. #define EXTRA_STATE 69
  76417. #define NAME_STATE 73
  76418. #define COMMENT_STATE 91
  76419. #define HCRC_STATE 103
  76420. #define BUSY_STATE 113
  76421. #define FINISH_STATE 666
  76422. typedef struct ct_data_s {
  76423. union {
  76424. ush freq; /* frequency count */
  76425. ush code; /* bit string */
  76426. } fc;
  76427. union {
  76428. ush dad; /* father node in Huffman tree */
  76429. ush len; /* length of bit string */
  76430. } dl;
  76431. } FAR ct_data;
  76432. #define Freq fc.freq
  76433. #define Code fc.code
  76434. #define Dad dl.dad
  76435. #define Len dl.len
  76436. typedef struct static_tree_desc_s static_tree_desc;
  76437. typedef struct tree_desc_s {
  76438. ct_data *dyn_tree; /* the dynamic tree */
  76439. int max_code; /* largest code with non zero frequency */
  76440. static_tree_desc *stat_desc; /* the corresponding static tree */
  76441. } FAR tree_desc;
  76442. typedef ush Pos;
  76443. typedef Pos FAR Posf;
  76444. typedef unsigned IPos;
  76445. typedef struct internal_state {
  76446. z_streamp strm; /* pointer back to this zlib stream */
  76447. int status; /* as the name implies */
  76448. Bytef *pending_buf; /* output still pending */
  76449. ulg pending_buf_size; /* size of pending_buf */
  76450. Bytef *pending_out; /* next pending byte to output to the stream */
  76451. uInt pending; /* nb of bytes in the pending buffer */
  76452. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  76453. gz_headerp gzhead; /* gzip header information to write */
  76454. uInt gzindex; /* where in extra, name, or comment */
  76455. Byte method; /* STORED (for zip only) or DEFLATED */
  76456. int last_flush; /* value of flush param for previous deflate call */
  76457. uInt w_size; /* LZ77 window size (32K by default) */
  76458. uInt w_bits; /* log2(w_size) (8..16) */
  76459. uInt w_mask; /* w_size - 1 */
  76460. Bytef *window;
  76461. ulg window_size;
  76462. Posf *prev;
  76463. Posf *head; /* Heads of the hash chains or NIL. */
  76464. uInt ins_h; /* hash index of string to be inserted */
  76465. uInt hash_size; /* number of elements in hash table */
  76466. uInt hash_bits; /* log2(hash_size) */
  76467. uInt hash_mask; /* hash_size-1 */
  76468. uInt hash_shift;
  76469. long block_start;
  76470. uInt match_length; /* length of best match */
  76471. IPos prev_match; /* previous match */
  76472. int match_available; /* set if previous match exists */
  76473. uInt strstart; /* start of string to insert */
  76474. uInt match_start; /* start of matching string */
  76475. uInt lookahead; /* number of valid bytes ahead in window */
  76476. uInt prev_length;
  76477. uInt max_chain_length;
  76478. uInt max_lazy_match;
  76479. # define max_insert_length max_lazy_match
  76480. int level; /* compression level (1..9) */
  76481. int strategy; /* favor or force Huffman coding*/
  76482. uInt good_match;
  76483. int nice_match; /* Stop searching when current match exceeds this */
  76484. struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
  76485. struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
  76486. struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
  76487. struct tree_desc_s l_desc; /* desc. for literal tree */
  76488. struct tree_desc_s d_desc; /* desc. for distance tree */
  76489. struct tree_desc_s bl_desc; /* desc. for bit length tree */
  76490. ush bl_count[MAX_BITS+1];
  76491. int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
  76492. int heap_len; /* number of elements in the heap */
  76493. int heap_max; /* element of largest frequency */
  76494. uch depth[2*L_CODES+1];
  76495. uchf *l_buf; /* buffer for literals or lengths */
  76496. uInt lit_bufsize;
  76497. uInt last_lit; /* running index in l_buf */
  76498. ushf *d_buf;
  76499. ulg opt_len; /* bit length of current block with optimal trees */
  76500. ulg static_len; /* bit length of current block with static trees */
  76501. uInt matches; /* number of string matches in current block */
  76502. int last_eob_len; /* bit length of EOB code for last block */
  76503. #ifdef DEBUG
  76504. ulg compressed_len; /* total bit length of compressed file mod 2^32 */
  76505. ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
  76506. #endif
  76507. ush bi_buf;
  76508. int bi_valid;
  76509. } FAR deflate_state;
  76510. #define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
  76511. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  76512. #define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
  76513. void _tr_init OF((deflate_state *s));
  76514. int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
  76515. void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
  76516. int eof));
  76517. void _tr_align OF((deflate_state *s));
  76518. void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
  76519. int eof));
  76520. #define d_code(dist) \
  76521. ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
  76522. #ifndef DEBUG
  76523. #if defined(GEN_TREES_H) || !defined(STDC)
  76524. extern uch _length_code[];
  76525. extern uch _dist_code[];
  76526. #else
  76527. extern const uch _length_code[];
  76528. extern const uch _dist_code[];
  76529. #endif
  76530. # define _tr_tally_lit(s, c, flush) \
  76531. { uch cc = (c); \
  76532. s->d_buf[s->last_lit] = 0; \
  76533. s->l_buf[s->last_lit++] = cc; \
  76534. s->dyn_ltree[cc].Freq++; \
  76535. flush = (s->last_lit == s->lit_bufsize-1); \
  76536. }
  76537. # define _tr_tally_dist(s, distance, length, flush) \
  76538. { uch len = (length); \
  76539. ush dist = (distance); \
  76540. s->d_buf[s->last_lit] = dist; \
  76541. s->l_buf[s->last_lit++] = len; \
  76542. dist--; \
  76543. s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
  76544. s->dyn_dtree[d_code(dist)].Freq++; \
  76545. flush = (s->last_lit == s->lit_bufsize-1); \
  76546. }
  76547. #else
  76548. # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
  76549. # define _tr_tally_dist(s, distance, length, flush) \
  76550. flush = _tr_tally(s, distance, length)
  76551. #endif
  76552. #endif /* DEFLATE_H */
  76553. /*** End of inlined file: deflate.h ***/
  76554. const char deflate_copyright[] =
  76555. " deflate 1.2.3 Copyright 1995-2005 Jean-loup Gailly ";
  76556. typedef enum {
  76557. need_more, /* block not completed, need more input or more output */
  76558. block_done, /* block flush performed */
  76559. finish_started, /* finish started, need only more output at next deflate */
  76560. finish_done /* finish done, accept no more input or output */
  76561. } block_state;
  76562. typedef block_state (*compress_func) OF((deflate_state *s, int flush));
  76563. local void fill_window OF((deflate_state *s));
  76564. local block_state deflate_stored OF((deflate_state *s, int flush));
  76565. local block_state deflate_fast OF((deflate_state *s, int flush));
  76566. #ifndef FASTEST
  76567. local block_state deflate_slow OF((deflate_state *s, int flush));
  76568. #endif
  76569. local void lm_init OF((deflate_state *s));
  76570. local void putShortMSB OF((deflate_state *s, uInt b));
  76571. local void flush_pending OF((z_streamp strm));
  76572. local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
  76573. #ifndef FASTEST
  76574. #ifdef ASMV
  76575. void match_init OF((void)); /* asm code initialization */
  76576. uInt longest_match OF((deflate_state *s, IPos cur_match));
  76577. #else
  76578. local uInt longest_match OF((deflate_state *s, IPos cur_match));
  76579. #endif
  76580. #endif
  76581. local uInt longest_match_fast OF((deflate_state *s, IPos cur_match));
  76582. #ifdef DEBUG
  76583. local void check_match OF((deflate_state *s, IPos start, IPos match,
  76584. int length));
  76585. #endif
  76586. #define NIL 0
  76587. #ifndef TOO_FAR
  76588. # define TOO_FAR 4096
  76589. #endif
  76590. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  76591. typedef struct config_s {
  76592. ush good_length; /* reduce lazy search above this match length */
  76593. ush max_lazy; /* do not perform lazy search above this match length */
  76594. ush nice_length; /* quit search above this match length */
  76595. ush max_chain;
  76596. compress_func func;
  76597. } config;
  76598. #ifdef FASTEST
  76599. local const config configuration_table[2] = {
  76600. {0, 0, 0, 0, deflate_stored}, /* store only */
  76601. {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */
  76602. #else
  76603. local const config configuration_table[10] = {
  76604. {0, 0, 0, 0, deflate_stored}, /* store only */
  76605. {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */
  76606. {4, 5, 16, 8, deflate_fast},
  76607. {4, 6, 32, 32, deflate_fast},
  76608. {4, 4, 16, 16, deflate_slow}, /* lazy matches */
  76609. {8, 16, 32, 32, deflate_slow},
  76610. {8, 16, 128, 128, deflate_slow},
  76611. {8, 32, 128, 256, deflate_slow},
  76612. {32, 128, 258, 1024, deflate_slow},
  76613. {32, 258, 258, 4096, deflate_slow}}; /* max compression */
  76614. #endif
  76615. #define EQUAL 0
  76616. #ifndef NO_DUMMY_DECL
  76617. struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
  76618. #endif
  76619. #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
  76620. #ifdef FASTEST
  76621. #define INSERT_STRING(s, str, match_head) \
  76622. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  76623. match_head = s->head[s->ins_h], \
  76624. s->head[s->ins_h] = (Pos)(str))
  76625. #else
  76626. #define INSERT_STRING(s, str, match_head) \
  76627. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  76628. match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
  76629. s->head[s->ins_h] = (Pos)(str))
  76630. #endif
  76631. #define CLEAR_HASH(s) \
  76632. s->head[s->hash_size-1] = NIL; \
  76633. zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
  76634. int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, int stream_size)
  76635. {
  76636. return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
  76637. Z_DEFAULT_STRATEGY, version, stream_size);
  76638. }
  76639. int ZEXPORT deflateInit2_ (z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
  76640. {
  76641. deflate_state *s;
  76642. int wrap = 1;
  76643. static const char my_version[] = ZLIB_VERSION;
  76644. ushf *overlay;
  76645. if (version == Z_NULL || version[0] != my_version[0] ||
  76646. stream_size != sizeof(z_stream)) {
  76647. return Z_VERSION_ERROR;
  76648. }
  76649. if (strm == Z_NULL) return Z_STREAM_ERROR;
  76650. strm->msg = Z_NULL;
  76651. if (strm->zalloc == (alloc_func)0) {
  76652. strm->zalloc = zcalloc;
  76653. strm->opaque = (voidpf)0;
  76654. }
  76655. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  76656. #ifdef FASTEST
  76657. if (level != 0) level = 1;
  76658. #else
  76659. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  76660. #endif
  76661. if (windowBits < 0) { /* suppress zlib wrapper */
  76662. wrap = 0;
  76663. windowBits = -windowBits;
  76664. }
  76665. #ifdef GZIP
  76666. else if (windowBits > 15) {
  76667. wrap = 2; /* write gzip wrapper instead */
  76668. windowBits -= 16;
  76669. }
  76670. #endif
  76671. if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
  76672. windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
  76673. strategy < 0 || strategy > Z_FIXED) {
  76674. return Z_STREAM_ERROR;
  76675. }
  76676. if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
  76677. s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
  76678. if (s == Z_NULL) return Z_MEM_ERROR;
  76679. strm->state = (struct internal_state FAR *)s;
  76680. s->strm = strm;
  76681. s->wrap = wrap;
  76682. s->gzhead = Z_NULL;
  76683. s->w_bits = windowBits;
  76684. s->w_size = 1 << s->w_bits;
  76685. s->w_mask = s->w_size - 1;
  76686. s->hash_bits = memLevel + 7;
  76687. s->hash_size = 1 << s->hash_bits;
  76688. s->hash_mask = s->hash_size - 1;
  76689. s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
  76690. s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
  76691. s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
  76692. s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
  76693. s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
  76694. overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
  76695. s->pending_buf = (uchf *) overlay;
  76696. s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
  76697. if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
  76698. s->pending_buf == Z_NULL) {
  76699. s->status = FINISH_STATE;
  76700. strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
  76701. deflateEnd (strm);
  76702. return Z_MEM_ERROR;
  76703. }
  76704. s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
  76705. s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
  76706. s->level = level;
  76707. s->strategy = strategy;
  76708. s->method = (Byte)method;
  76709. return deflateReset(strm);
  76710. }
  76711. int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  76712. {
  76713. deflate_state *s;
  76714. uInt length = dictLength;
  76715. uInt n;
  76716. IPos hash_head = 0;
  76717. if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
  76718. strm->state->wrap == 2 ||
  76719. (strm->state->wrap == 1 && strm->state->status != INIT_STATE))
  76720. return Z_STREAM_ERROR;
  76721. s = strm->state;
  76722. if (s->wrap)
  76723. strm->adler = adler32(strm->adler, dictionary, dictLength);
  76724. if (length < MIN_MATCH) return Z_OK;
  76725. if (length > MAX_DIST(s)) {
  76726. length = MAX_DIST(s);
  76727. dictionary += dictLength - length; /* use the tail of the dictionary */
  76728. }
  76729. zmemcpy(s->window, dictionary, length);
  76730. s->strstart = length;
  76731. s->block_start = (long)length;
  76732. s->ins_h = s->window[0];
  76733. UPDATE_HASH(s, s->ins_h, s->window[1]);
  76734. for (n = 0; n <= length - MIN_MATCH; n++) {
  76735. INSERT_STRING(s, n, hash_head);
  76736. }
  76737. if (hash_head) hash_head = 0; /* to make compiler happy */
  76738. return Z_OK;
  76739. }
  76740. int ZEXPORT deflateReset (z_streamp strm)
  76741. {
  76742. deflate_state *s;
  76743. if (strm == Z_NULL || strm->state == Z_NULL ||
  76744. strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
  76745. return Z_STREAM_ERROR;
  76746. }
  76747. strm->total_in = strm->total_out = 0;
  76748. strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
  76749. strm->data_type = Z_UNKNOWN;
  76750. s = (deflate_state *)strm->state;
  76751. s->pending = 0;
  76752. s->pending_out = s->pending_buf;
  76753. if (s->wrap < 0) {
  76754. s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
  76755. }
  76756. s->status = s->wrap ? INIT_STATE : BUSY_STATE;
  76757. strm->adler =
  76758. #ifdef GZIP
  76759. s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
  76760. #endif
  76761. adler32(0L, Z_NULL, 0);
  76762. s->last_flush = Z_NO_FLUSH;
  76763. _tr_init(s);
  76764. lm_init(s);
  76765. return Z_OK;
  76766. }
  76767. int ZEXPORT deflateSetHeader (z_streamp strm, gz_headerp head)
  76768. {
  76769. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76770. if (strm->state->wrap != 2) return Z_STREAM_ERROR;
  76771. strm->state->gzhead = head;
  76772. return Z_OK;
  76773. }
  76774. int ZEXPORT deflatePrime (z_streamp strm, int bits, int value)
  76775. {
  76776. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76777. strm->state->bi_valid = bits;
  76778. strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
  76779. return Z_OK;
  76780. }
  76781. int ZEXPORT deflateParams (z_streamp strm, int level, int strategy)
  76782. {
  76783. deflate_state *s;
  76784. compress_func func;
  76785. int err = Z_OK;
  76786. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76787. s = strm->state;
  76788. #ifdef FASTEST
  76789. if (level != 0) level = 1;
  76790. #else
  76791. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  76792. #endif
  76793. if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
  76794. return Z_STREAM_ERROR;
  76795. }
  76796. func = configuration_table[s->level].func;
  76797. if (func != configuration_table[level].func && strm->total_in != 0) {
  76798. err = deflate(strm, Z_PARTIAL_FLUSH);
  76799. }
  76800. if (s->level != level) {
  76801. s->level = level;
  76802. s->max_lazy_match = configuration_table[level].max_lazy;
  76803. s->good_match = configuration_table[level].good_length;
  76804. s->nice_match = configuration_table[level].nice_length;
  76805. s->max_chain_length = configuration_table[level].max_chain;
  76806. }
  76807. s->strategy = strategy;
  76808. return err;
  76809. }
  76810. int ZEXPORT deflateTune (z_streamp strm, int good_length, int max_lazy, int nice_length, int max_chain)
  76811. {
  76812. deflate_state *s;
  76813. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76814. s = strm->state;
  76815. s->good_match = good_length;
  76816. s->max_lazy_match = max_lazy;
  76817. s->nice_match = nice_length;
  76818. s->max_chain_length = max_chain;
  76819. return Z_OK;
  76820. }
  76821. uLong ZEXPORT deflateBound (z_streamp strm, uLong sourceLen)
  76822. {
  76823. deflate_state *s;
  76824. uLong destLen;
  76825. destLen = sourceLen +
  76826. ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11;
  76827. if (strm == Z_NULL || strm->state == Z_NULL)
  76828. return destLen;
  76829. s = strm->state;
  76830. if (s->w_bits != 15 || s->hash_bits != 8 + 7)
  76831. return destLen;
  76832. return compressBound(sourceLen);
  76833. }
  76834. local void putShortMSB (deflate_state *s, uInt b)
  76835. {
  76836. put_byte(s, (Byte)(b >> 8));
  76837. put_byte(s, (Byte)(b & 0xff));
  76838. }
  76839. local void flush_pending (z_streamp strm)
  76840. {
  76841. unsigned len = strm->state->pending;
  76842. if (len > strm->avail_out) len = strm->avail_out;
  76843. if (len == 0) return;
  76844. zmemcpy(strm->next_out, strm->state->pending_out, len);
  76845. strm->next_out += len;
  76846. strm->state->pending_out += len;
  76847. strm->total_out += len;
  76848. strm->avail_out -= len;
  76849. strm->state->pending -= len;
  76850. if (strm->state->pending == 0) {
  76851. strm->state->pending_out = strm->state->pending_buf;
  76852. }
  76853. }
  76854. int ZEXPORT deflate (z_streamp strm, int flush)
  76855. {
  76856. int old_flush; /* value of flush param for previous deflate call */
  76857. deflate_state *s;
  76858. if (strm == Z_NULL || strm->state == Z_NULL ||
  76859. flush > Z_FINISH || flush < 0) {
  76860. return Z_STREAM_ERROR;
  76861. }
  76862. s = strm->state;
  76863. if (strm->next_out == Z_NULL ||
  76864. (strm->next_in == Z_NULL && strm->avail_in != 0) ||
  76865. (s->status == FINISH_STATE && flush != Z_FINISH)) {
  76866. ERR_RETURN(strm, Z_STREAM_ERROR);
  76867. }
  76868. if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
  76869. s->strm = strm; /* just in case */
  76870. old_flush = s->last_flush;
  76871. s->last_flush = flush;
  76872. if (s->status == INIT_STATE) {
  76873. #ifdef GZIP
  76874. if (s->wrap == 2) {
  76875. strm->adler = crc32(0L, Z_NULL, 0);
  76876. put_byte(s, 31);
  76877. put_byte(s, 139);
  76878. put_byte(s, 8);
  76879. if (s->gzhead == NULL) {
  76880. put_byte(s, 0);
  76881. put_byte(s, 0);
  76882. put_byte(s, 0);
  76883. put_byte(s, 0);
  76884. put_byte(s, 0);
  76885. put_byte(s, s->level == 9 ? 2 :
  76886. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  76887. 4 : 0));
  76888. put_byte(s, OS_CODE);
  76889. s->status = BUSY_STATE;
  76890. }
  76891. else {
  76892. put_byte(s, (s->gzhead->text ? 1 : 0) +
  76893. (s->gzhead->hcrc ? 2 : 0) +
  76894. (s->gzhead->extra == Z_NULL ? 0 : 4) +
  76895. (s->gzhead->name == Z_NULL ? 0 : 8) +
  76896. (s->gzhead->comment == Z_NULL ? 0 : 16)
  76897. );
  76898. put_byte(s, (Byte)(s->gzhead->time & 0xff));
  76899. put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
  76900. put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
  76901. put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
  76902. put_byte(s, s->level == 9 ? 2 :
  76903. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  76904. 4 : 0));
  76905. put_byte(s, s->gzhead->os & 0xff);
  76906. if (s->gzhead->extra != NULL) {
  76907. put_byte(s, s->gzhead->extra_len & 0xff);
  76908. put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
  76909. }
  76910. if (s->gzhead->hcrc)
  76911. strm->adler = crc32(strm->adler, s->pending_buf,
  76912. s->pending);
  76913. s->gzindex = 0;
  76914. s->status = EXTRA_STATE;
  76915. }
  76916. }
  76917. else
  76918. #endif
  76919. {
  76920. uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
  76921. uInt level_flags;
  76922. if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
  76923. level_flags = 0;
  76924. else if (s->level < 6)
  76925. level_flags = 1;
  76926. else if (s->level == 6)
  76927. level_flags = 2;
  76928. else
  76929. level_flags = 3;
  76930. header |= (level_flags << 6);
  76931. if (s->strstart != 0) header |= PRESET_DICT;
  76932. header += 31 - (header % 31);
  76933. s->status = BUSY_STATE;
  76934. putShortMSB(s, header);
  76935. if (s->strstart != 0) {
  76936. putShortMSB(s, (uInt)(strm->adler >> 16));
  76937. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  76938. }
  76939. strm->adler = adler32(0L, Z_NULL, 0);
  76940. }
  76941. }
  76942. #ifdef GZIP
  76943. if (s->status == EXTRA_STATE) {
  76944. if (s->gzhead->extra != NULL) {
  76945. uInt beg = s->pending; /* start of bytes to update crc */
  76946. while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
  76947. if (s->pending == s->pending_buf_size) {
  76948. if (s->gzhead->hcrc && s->pending > beg)
  76949. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76950. s->pending - beg);
  76951. flush_pending(strm);
  76952. beg = s->pending;
  76953. if (s->pending == s->pending_buf_size)
  76954. break;
  76955. }
  76956. put_byte(s, s->gzhead->extra[s->gzindex]);
  76957. s->gzindex++;
  76958. }
  76959. if (s->gzhead->hcrc && s->pending > beg)
  76960. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76961. s->pending - beg);
  76962. if (s->gzindex == s->gzhead->extra_len) {
  76963. s->gzindex = 0;
  76964. s->status = NAME_STATE;
  76965. }
  76966. }
  76967. else
  76968. s->status = NAME_STATE;
  76969. }
  76970. if (s->status == NAME_STATE) {
  76971. if (s->gzhead->name != NULL) {
  76972. uInt beg = s->pending; /* start of bytes to update crc */
  76973. int val;
  76974. do {
  76975. if (s->pending == s->pending_buf_size) {
  76976. if (s->gzhead->hcrc && s->pending > beg)
  76977. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76978. s->pending - beg);
  76979. flush_pending(strm);
  76980. beg = s->pending;
  76981. if (s->pending == s->pending_buf_size) {
  76982. val = 1;
  76983. break;
  76984. }
  76985. }
  76986. val = s->gzhead->name[s->gzindex++];
  76987. put_byte(s, val);
  76988. } while (val != 0);
  76989. if (s->gzhead->hcrc && s->pending > beg)
  76990. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76991. s->pending - beg);
  76992. if (val == 0) {
  76993. s->gzindex = 0;
  76994. s->status = COMMENT_STATE;
  76995. }
  76996. }
  76997. else
  76998. s->status = COMMENT_STATE;
  76999. }
  77000. if (s->status == COMMENT_STATE) {
  77001. if (s->gzhead->comment != NULL) {
  77002. uInt beg = s->pending; /* start of bytes to update crc */
  77003. int val;
  77004. do {
  77005. if (s->pending == s->pending_buf_size) {
  77006. if (s->gzhead->hcrc && s->pending > beg)
  77007. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77008. s->pending - beg);
  77009. flush_pending(strm);
  77010. beg = s->pending;
  77011. if (s->pending == s->pending_buf_size) {
  77012. val = 1;
  77013. break;
  77014. }
  77015. }
  77016. val = s->gzhead->comment[s->gzindex++];
  77017. put_byte(s, val);
  77018. } while (val != 0);
  77019. if (s->gzhead->hcrc && s->pending > beg)
  77020. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77021. s->pending - beg);
  77022. if (val == 0)
  77023. s->status = HCRC_STATE;
  77024. }
  77025. else
  77026. s->status = HCRC_STATE;
  77027. }
  77028. if (s->status == HCRC_STATE) {
  77029. if (s->gzhead->hcrc) {
  77030. if (s->pending + 2 > s->pending_buf_size)
  77031. flush_pending(strm);
  77032. if (s->pending + 2 <= s->pending_buf_size) {
  77033. put_byte(s, (Byte)(strm->adler & 0xff));
  77034. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77035. strm->adler = crc32(0L, Z_NULL, 0);
  77036. s->status = BUSY_STATE;
  77037. }
  77038. }
  77039. else
  77040. s->status = BUSY_STATE;
  77041. }
  77042. #endif
  77043. if (s->pending != 0) {
  77044. flush_pending(strm);
  77045. if (strm->avail_out == 0) {
  77046. s->last_flush = -1;
  77047. return Z_OK;
  77048. }
  77049. } else if (strm->avail_in == 0 && flush <= old_flush &&
  77050. flush != Z_FINISH) {
  77051. ERR_RETURN(strm, Z_BUF_ERROR);
  77052. }
  77053. if (s->status == FINISH_STATE && strm->avail_in != 0) {
  77054. ERR_RETURN(strm, Z_BUF_ERROR);
  77055. }
  77056. if (strm->avail_in != 0 || s->lookahead != 0 ||
  77057. (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
  77058. block_state bstate;
  77059. bstate = (*(configuration_table[s->level].func))(s, flush);
  77060. if (bstate == finish_started || bstate == finish_done) {
  77061. s->status = FINISH_STATE;
  77062. }
  77063. if (bstate == need_more || bstate == finish_started) {
  77064. if (strm->avail_out == 0) {
  77065. s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
  77066. }
  77067. return Z_OK;
  77068. }
  77069. if (bstate == block_done) {
  77070. if (flush == Z_PARTIAL_FLUSH) {
  77071. _tr_align(s);
  77072. } else { /* FULL_FLUSH or SYNC_FLUSH */
  77073. _tr_stored_block(s, (char*)0, 0L, 0);
  77074. if (flush == Z_FULL_FLUSH) {
  77075. CLEAR_HASH(s); /* forget history */
  77076. }
  77077. }
  77078. flush_pending(strm);
  77079. if (strm->avail_out == 0) {
  77080. s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
  77081. return Z_OK;
  77082. }
  77083. }
  77084. }
  77085. Assert(strm->avail_out > 0, "bug2");
  77086. if (flush != Z_FINISH) return Z_OK;
  77087. if (s->wrap <= 0) return Z_STREAM_END;
  77088. #ifdef GZIP
  77089. if (s->wrap == 2) {
  77090. put_byte(s, (Byte)(strm->adler & 0xff));
  77091. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77092. put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
  77093. put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
  77094. put_byte(s, (Byte)(strm->total_in & 0xff));
  77095. put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
  77096. put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
  77097. put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
  77098. }
  77099. else
  77100. #endif
  77101. {
  77102. putShortMSB(s, (uInt)(strm->adler >> 16));
  77103. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  77104. }
  77105. flush_pending(strm);
  77106. if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
  77107. return s->pending != 0 ? Z_OK : Z_STREAM_END;
  77108. }
  77109. int ZEXPORT deflateEnd (z_streamp strm)
  77110. {
  77111. int status;
  77112. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77113. status = strm->state->status;
  77114. if (status != INIT_STATE &&
  77115. status != EXTRA_STATE &&
  77116. status != NAME_STATE &&
  77117. status != COMMENT_STATE &&
  77118. status != HCRC_STATE &&
  77119. status != BUSY_STATE &&
  77120. status != FINISH_STATE) {
  77121. return Z_STREAM_ERROR;
  77122. }
  77123. TRY_FREE(strm, strm->state->pending_buf);
  77124. TRY_FREE(strm, strm->state->head);
  77125. TRY_FREE(strm, strm->state->prev);
  77126. TRY_FREE(strm, strm->state->window);
  77127. ZFREE(strm, strm->state);
  77128. strm->state = Z_NULL;
  77129. return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
  77130. }
  77131. int ZEXPORT deflateCopy (z_streamp dest, z_streamp source)
  77132. {
  77133. #ifdef MAXSEG_64K
  77134. return Z_STREAM_ERROR;
  77135. #else
  77136. deflate_state *ds;
  77137. deflate_state *ss;
  77138. ushf *overlay;
  77139. if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
  77140. return Z_STREAM_ERROR;
  77141. }
  77142. ss = source->state;
  77143. zmemcpy(dest, source, sizeof(z_stream));
  77144. ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
  77145. if (ds == Z_NULL) return Z_MEM_ERROR;
  77146. dest->state = (struct internal_state FAR *) ds;
  77147. zmemcpy(ds, ss, sizeof(deflate_state));
  77148. ds->strm = dest;
  77149. ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
  77150. ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
  77151. ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
  77152. overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
  77153. ds->pending_buf = (uchf *) overlay;
  77154. if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
  77155. ds->pending_buf == Z_NULL) {
  77156. deflateEnd (dest);
  77157. return Z_MEM_ERROR;
  77158. }
  77159. zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
  77160. zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
  77161. zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
  77162. zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
  77163. ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
  77164. ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
  77165. ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
  77166. ds->l_desc.dyn_tree = ds->dyn_ltree;
  77167. ds->d_desc.dyn_tree = ds->dyn_dtree;
  77168. ds->bl_desc.dyn_tree = ds->bl_tree;
  77169. return Z_OK;
  77170. #endif /* MAXSEG_64K */
  77171. }
  77172. local int read_buf (z_streamp strm, Bytef *buf, unsigned size)
  77173. {
  77174. unsigned len = strm->avail_in;
  77175. if (len > size) len = size;
  77176. if (len == 0) return 0;
  77177. strm->avail_in -= len;
  77178. if (strm->state->wrap == 1) {
  77179. strm->adler = adler32(strm->adler, strm->next_in, len);
  77180. }
  77181. #ifdef GZIP
  77182. else if (strm->state->wrap == 2) {
  77183. strm->adler = crc32(strm->adler, strm->next_in, len);
  77184. }
  77185. #endif
  77186. zmemcpy(buf, strm->next_in, len);
  77187. strm->next_in += len;
  77188. strm->total_in += len;
  77189. return (int)len;
  77190. }
  77191. local void lm_init (deflate_state *s)
  77192. {
  77193. s->window_size = (ulg)2L*s->w_size;
  77194. CLEAR_HASH(s);
  77195. s->max_lazy_match = configuration_table[s->level].max_lazy;
  77196. s->good_match = configuration_table[s->level].good_length;
  77197. s->nice_match = configuration_table[s->level].nice_length;
  77198. s->max_chain_length = configuration_table[s->level].max_chain;
  77199. s->strstart = 0;
  77200. s->block_start = 0L;
  77201. s->lookahead = 0;
  77202. s->match_length = s->prev_length = MIN_MATCH-1;
  77203. s->match_available = 0;
  77204. s->ins_h = 0;
  77205. #ifndef FASTEST
  77206. #ifdef ASMV
  77207. match_init(); /* initialize the asm code */
  77208. #endif
  77209. #endif
  77210. }
  77211. #ifndef FASTEST
  77212. #ifndef ASMV
  77213. local uInt longest_match(deflate_state *s, IPos cur_match)
  77214. {
  77215. unsigned chain_length = s->max_chain_length;/* max hash chain length */
  77216. register Bytef *scan = s->window + s->strstart; /* current string */
  77217. register Bytef *match; /* matched string */
  77218. register int len; /* length of current match */
  77219. int best_len = s->prev_length; /* best match length so far */
  77220. int nice_match = s->nice_match; /* stop if match long enough */
  77221. IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
  77222. s->strstart - (IPos)MAX_DIST(s) : NIL;
  77223. Posf *prev = s->prev;
  77224. uInt wmask = s->w_mask;
  77225. #ifdef UNALIGNED_OK
  77226. register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
  77227. register ush scan_start = *(ushf*)scan;
  77228. register ush scan_end = *(ushf*)(scan+best_len-1);
  77229. #else
  77230. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77231. register Byte scan_end1 = scan[best_len-1];
  77232. register Byte scan_end = scan[best_len];
  77233. #endif
  77234. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77235. if (s->prev_length >= s->good_match) {
  77236. chain_length >>= 2;
  77237. }
  77238. if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
  77239. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77240. do {
  77241. Assert(cur_match < s->strstart, "no future");
  77242. match = s->window + cur_match;
  77243. #if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
  77244. if (*(ushf*)(match+best_len-1) != scan_end ||
  77245. *(ushf*)match != scan_start) continue;
  77246. Assert(scan[2] == match[2], "scan[2]?");
  77247. scan++, match++;
  77248. do {
  77249. } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77250. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77251. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77252. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77253. scan < strend);
  77254. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77255. if (*scan == *match) scan++;
  77256. len = (MAX_MATCH - 1) - (int)(strend-scan);
  77257. scan = strend - (MAX_MATCH-1);
  77258. #else /* UNALIGNED_OK */
  77259. if (match[best_len] != scan_end ||
  77260. match[best_len-1] != scan_end1 ||
  77261. *match != *scan ||
  77262. *++match != scan[1]) continue;
  77263. scan += 2, match++;
  77264. Assert(*scan == *match, "match[2]?");
  77265. do {
  77266. } while (*++scan == *++match && *++scan == *++match &&
  77267. *++scan == *++match && *++scan == *++match &&
  77268. *++scan == *++match && *++scan == *++match &&
  77269. *++scan == *++match && *++scan == *++match &&
  77270. scan < strend);
  77271. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77272. len = MAX_MATCH - (int)(strend - scan);
  77273. scan = strend - MAX_MATCH;
  77274. #endif /* UNALIGNED_OK */
  77275. if (len > best_len) {
  77276. s->match_start = cur_match;
  77277. best_len = len;
  77278. if (len >= nice_match) break;
  77279. #ifdef UNALIGNED_OK
  77280. scan_end = *(ushf*)(scan+best_len-1);
  77281. #else
  77282. scan_end1 = scan[best_len-1];
  77283. scan_end = scan[best_len];
  77284. #endif
  77285. }
  77286. } while ((cur_match = prev[cur_match & wmask]) > limit
  77287. && --chain_length != 0);
  77288. if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
  77289. return s->lookahead;
  77290. }
  77291. #endif /* ASMV */
  77292. #endif /* FASTEST */
  77293. local uInt longest_match_fast (deflate_state *s, IPos cur_match)
  77294. {
  77295. register Bytef *scan = s->window + s->strstart; /* current string */
  77296. register Bytef *match; /* matched string */
  77297. register int len; /* length of current match */
  77298. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77299. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77300. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77301. Assert(cur_match < s->strstart, "no future");
  77302. match = s->window + cur_match;
  77303. if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
  77304. scan += 2, match += 2;
  77305. Assert(*scan == *match, "match[2]?");
  77306. do {
  77307. } while (*++scan == *++match && *++scan == *++match &&
  77308. *++scan == *++match && *++scan == *++match &&
  77309. *++scan == *++match && *++scan == *++match &&
  77310. *++scan == *++match && *++scan == *++match &&
  77311. scan < strend);
  77312. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77313. len = MAX_MATCH - (int)(strend - scan);
  77314. if (len < MIN_MATCH) return MIN_MATCH - 1;
  77315. s->match_start = cur_match;
  77316. return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
  77317. }
  77318. #ifdef DEBUG
  77319. local void check_match(deflate_state *s, IPos start, IPos match, int length)
  77320. {
  77321. if (zmemcmp(s->window + match,
  77322. s->window + start, length) != EQUAL) {
  77323. fprintf(stderr, " start %u, match %u, length %d\n",
  77324. start, match, length);
  77325. do {
  77326. fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
  77327. } while (--length != 0);
  77328. z_error("invalid match");
  77329. }
  77330. if (z_verbose > 1) {
  77331. fprintf(stderr,"\\[%d,%d]", start-match, length);
  77332. do { putc(s->window[start++], stderr); } while (--length != 0);
  77333. }
  77334. }
  77335. #else
  77336. # define check_match(s, start, match, length)
  77337. #endif /* DEBUG */
  77338. local void fill_window (deflate_state *s)
  77339. {
  77340. register unsigned n, m;
  77341. register Posf *p;
  77342. unsigned more; /* Amount of free space at the end of the window. */
  77343. uInt wsize = s->w_size;
  77344. do {
  77345. more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
  77346. if (sizeof(int) <= 2) {
  77347. if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
  77348. more = wsize;
  77349. } else if (more == (unsigned)(-1)) {
  77350. more--;
  77351. }
  77352. }
  77353. if (s->strstart >= wsize+MAX_DIST(s)) {
  77354. zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
  77355. s->match_start -= wsize;
  77356. s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
  77357. s->block_start -= (long) wsize;
  77358. n = s->hash_size;
  77359. p = &s->head[n];
  77360. do {
  77361. m = *--p;
  77362. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77363. } while (--n);
  77364. n = wsize;
  77365. #ifndef FASTEST
  77366. p = &s->prev[n];
  77367. do {
  77368. m = *--p;
  77369. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77370. } while (--n);
  77371. #endif
  77372. more += wsize;
  77373. }
  77374. if (s->strm->avail_in == 0) return;
  77375. Assert(more >= 2, "more < 2");
  77376. n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
  77377. s->lookahead += n;
  77378. if (s->lookahead >= MIN_MATCH) {
  77379. s->ins_h = s->window[s->strstart];
  77380. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77381. #if MIN_MATCH != 3
  77382. Call UPDATE_HASH() MIN_MATCH-3 more times
  77383. #endif
  77384. }
  77385. } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
  77386. }
  77387. #define FLUSH_BLOCK_ONLY(s, eof) { \
  77388. _tr_flush_block(s, (s->block_start >= 0L ? \
  77389. (charf *)&s->window[(unsigned)s->block_start] : \
  77390. (charf *)Z_NULL), \
  77391. (ulg)((long)s->strstart - s->block_start), \
  77392. (eof)); \
  77393. s->block_start = s->strstart; \
  77394. flush_pending(s->strm); \
  77395. Tracev((stderr,"[FLUSH]")); \
  77396. }
  77397. #define FLUSH_BLOCK(s, eof) { \
  77398. FLUSH_BLOCK_ONLY(s, eof); \
  77399. if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
  77400. }
  77401. local block_state deflate_stored(deflate_state *s, int flush)
  77402. {
  77403. ulg max_block_size = 0xffff;
  77404. ulg max_start;
  77405. if (max_block_size > s->pending_buf_size - 5) {
  77406. max_block_size = s->pending_buf_size - 5;
  77407. }
  77408. for (;;) {
  77409. if (s->lookahead <= 1) {
  77410. Assert(s->strstart < s->w_size+MAX_DIST(s) ||
  77411. s->block_start >= (long)s->w_size, "slide too late");
  77412. fill_window(s);
  77413. if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
  77414. if (s->lookahead == 0) break; /* flush the current block */
  77415. }
  77416. Assert(s->block_start >= 0L, "block gone");
  77417. s->strstart += s->lookahead;
  77418. s->lookahead = 0;
  77419. max_start = s->block_start + max_block_size;
  77420. if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
  77421. s->lookahead = (uInt)(s->strstart - max_start);
  77422. s->strstart = (uInt)max_start;
  77423. FLUSH_BLOCK(s, 0);
  77424. }
  77425. if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
  77426. FLUSH_BLOCK(s, 0);
  77427. }
  77428. }
  77429. FLUSH_BLOCK(s, flush == Z_FINISH);
  77430. return flush == Z_FINISH ? finish_done : block_done;
  77431. }
  77432. local block_state deflate_fast(deflate_state *s, int flush)
  77433. {
  77434. IPos hash_head = NIL; /* head of the hash chain */
  77435. int bflush; /* set if current block must be flushed */
  77436. for (;;) {
  77437. if (s->lookahead < MIN_LOOKAHEAD) {
  77438. fill_window(s);
  77439. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77440. return need_more;
  77441. }
  77442. if (s->lookahead == 0) break; /* flush the current block */
  77443. }
  77444. if (s->lookahead >= MIN_MATCH) {
  77445. INSERT_STRING(s, s->strstart, hash_head);
  77446. }
  77447. if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
  77448. #ifdef FASTEST
  77449. if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) ||
  77450. (s->strategy == Z_RLE && s->strstart - hash_head == 1)) {
  77451. s->match_length = longest_match_fast (s, hash_head);
  77452. }
  77453. #else
  77454. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77455. s->match_length = longest_match (s, hash_head);
  77456. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77457. s->match_length = longest_match_fast (s, hash_head);
  77458. }
  77459. #endif
  77460. }
  77461. if (s->match_length >= MIN_MATCH) {
  77462. check_match(s, s->strstart, s->match_start, s->match_length);
  77463. _tr_tally_dist(s, s->strstart - s->match_start,
  77464. s->match_length - MIN_MATCH, bflush);
  77465. s->lookahead -= s->match_length;
  77466. #ifndef FASTEST
  77467. if (s->match_length <= s->max_insert_length &&
  77468. s->lookahead >= MIN_MATCH) {
  77469. s->match_length--; /* string at strstart already in table */
  77470. do {
  77471. s->strstart++;
  77472. INSERT_STRING(s, s->strstart, hash_head);
  77473. } while (--s->match_length != 0);
  77474. s->strstart++;
  77475. } else
  77476. #endif
  77477. {
  77478. s->strstart += s->match_length;
  77479. s->match_length = 0;
  77480. s->ins_h = s->window[s->strstart];
  77481. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77482. #if MIN_MATCH != 3
  77483. Call UPDATE_HASH() MIN_MATCH-3 more times
  77484. #endif
  77485. }
  77486. } else {
  77487. Tracevv((stderr,"%c", s->window[s->strstart]));
  77488. _tr_tally_lit (s, s->window[s->strstart], bflush);
  77489. s->lookahead--;
  77490. s->strstart++;
  77491. }
  77492. if (bflush) FLUSH_BLOCK(s, 0);
  77493. }
  77494. FLUSH_BLOCK(s, flush == Z_FINISH);
  77495. return flush == Z_FINISH ? finish_done : block_done;
  77496. }
  77497. #ifndef FASTEST
  77498. local block_state deflate_slow(deflate_state *s, int flush)
  77499. {
  77500. IPos hash_head = NIL; /* head of hash chain */
  77501. int bflush; /* set if current block must be flushed */
  77502. for (;;) {
  77503. if (s->lookahead < MIN_LOOKAHEAD) {
  77504. fill_window(s);
  77505. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77506. return need_more;
  77507. }
  77508. if (s->lookahead == 0) break; /* flush the current block */
  77509. }
  77510. if (s->lookahead >= MIN_MATCH) {
  77511. INSERT_STRING(s, s->strstart, hash_head);
  77512. }
  77513. s->prev_length = s->match_length, s->prev_match = s->match_start;
  77514. s->match_length = MIN_MATCH-1;
  77515. if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
  77516. s->strstart - hash_head <= MAX_DIST(s)) {
  77517. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77518. s->match_length = longest_match (s, hash_head);
  77519. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77520. s->match_length = longest_match_fast (s, hash_head);
  77521. }
  77522. if (s->match_length <= 5 && (s->strategy == Z_FILTERED
  77523. #if TOO_FAR <= 32767
  77524. || (s->match_length == MIN_MATCH &&
  77525. s->strstart - s->match_start > TOO_FAR)
  77526. #endif
  77527. )) {
  77528. s->match_length = MIN_MATCH-1;
  77529. }
  77530. }
  77531. if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
  77532. uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
  77533. check_match(s, s->strstart-1, s->prev_match, s->prev_length);
  77534. _tr_tally_dist(s, s->strstart -1 - s->prev_match,
  77535. s->prev_length - MIN_MATCH, bflush);
  77536. s->lookahead -= s->prev_length-1;
  77537. s->prev_length -= 2;
  77538. do {
  77539. if (++s->strstart <= max_insert) {
  77540. INSERT_STRING(s, s->strstart, hash_head);
  77541. }
  77542. } while (--s->prev_length != 0);
  77543. s->match_available = 0;
  77544. s->match_length = MIN_MATCH-1;
  77545. s->strstart++;
  77546. if (bflush) FLUSH_BLOCK(s, 0);
  77547. } else if (s->match_available) {
  77548. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  77549. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  77550. if (bflush) {
  77551. FLUSH_BLOCK_ONLY(s, 0);
  77552. }
  77553. s->strstart++;
  77554. s->lookahead--;
  77555. if (s->strm->avail_out == 0) return need_more;
  77556. } else {
  77557. s->match_available = 1;
  77558. s->strstart++;
  77559. s->lookahead--;
  77560. }
  77561. }
  77562. Assert (flush != Z_NO_FLUSH, "no flush?");
  77563. if (s->match_available) {
  77564. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  77565. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  77566. s->match_available = 0;
  77567. }
  77568. FLUSH_BLOCK(s, flush == Z_FINISH);
  77569. return flush == Z_FINISH ? finish_done : block_done;
  77570. }
  77571. #endif /* FASTEST */
  77572. #if 0
  77573. local block_state deflate_rle(s, flush)
  77574. deflate_state *s;
  77575. int flush;
  77576. {
  77577. int bflush; /* set if current block must be flushed */
  77578. uInt run; /* length of run */
  77579. uInt max; /* maximum length of run */
  77580. uInt prev; /* byte at distance one to match */
  77581. Bytef *scan; /* scan for end of run */
  77582. for (;;) {
  77583. if (s->lookahead < MAX_MATCH) {
  77584. fill_window(s);
  77585. if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
  77586. return need_more;
  77587. }
  77588. if (s->lookahead == 0) break; /* flush the current block */
  77589. }
  77590. run = 0;
  77591. if (s->strstart > 0) { /* if there is a previous byte, that is */
  77592. max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH;
  77593. scan = s->window + s->strstart - 1;
  77594. prev = *scan++;
  77595. do {
  77596. if (*scan++ != prev)
  77597. break;
  77598. } while (++run < max);
  77599. }
  77600. if (run >= MIN_MATCH) {
  77601. check_match(s, s->strstart, s->strstart - 1, run);
  77602. _tr_tally_dist(s, 1, run - MIN_MATCH, bflush);
  77603. s->lookahead -= run;
  77604. s->strstart += run;
  77605. } else {
  77606. Tracevv((stderr,"%c", s->window[s->strstart]));
  77607. _tr_tally_lit (s, s->window[s->strstart], bflush);
  77608. s->lookahead--;
  77609. s->strstart++;
  77610. }
  77611. if (bflush) FLUSH_BLOCK(s, 0);
  77612. }
  77613. FLUSH_BLOCK(s, flush == Z_FINISH);
  77614. return flush == Z_FINISH ? finish_done : block_done;
  77615. }
  77616. #endif
  77617. /*** End of inlined file: deflate.c ***/
  77618. /*** Start of inlined file: inffast.c ***/
  77619. /*** Start of inlined file: inftrees.h ***/
  77620. #ifndef _INFTREES_H_
  77621. #define _INFTREES_H_
  77622. typedef struct {
  77623. unsigned char op; /* operation, extra bits, table bits */
  77624. unsigned char bits; /* bits in this part of the code */
  77625. unsigned short val; /* offset in table or code value */
  77626. } code;
  77627. #define ENOUGH 2048
  77628. #define MAXD 592
  77629. typedef enum {
  77630. CODES,
  77631. LENS,
  77632. DISTS
  77633. } codetype;
  77634. extern int inflate_table OF((codetype type, unsigned short FAR *lens,
  77635. unsigned codes, code FAR * FAR *table,
  77636. unsigned FAR *bits, unsigned short FAR *work));
  77637. #endif
  77638. /*** End of inlined file: inftrees.h ***/
  77639. /*** Start of inlined file: inflate.h ***/
  77640. #ifndef _INFLATE_H_
  77641. #define _INFLATE_H_
  77642. #ifndef NO_GZIP
  77643. # define GUNZIP
  77644. #endif
  77645. typedef enum {
  77646. HEAD, /* i: waiting for magic header */
  77647. FLAGS, /* i: waiting for method and flags (gzip) */
  77648. TIME, /* i: waiting for modification time (gzip) */
  77649. OS, /* i: waiting for extra flags and operating system (gzip) */
  77650. EXLEN, /* i: waiting for extra length (gzip) */
  77651. EXTRA, /* i: waiting for extra bytes (gzip) */
  77652. NAME, /* i: waiting for end of file name (gzip) */
  77653. COMMENT, /* i: waiting for end of comment (gzip) */
  77654. HCRC, /* i: waiting for header crc (gzip) */
  77655. DICTID, /* i: waiting for dictionary check value */
  77656. DICT, /* waiting for inflateSetDictionary() call */
  77657. TYPE, /* i: waiting for type bits, including last-flag bit */
  77658. TYPEDO, /* i: same, but skip check to exit inflate on new block */
  77659. STORED, /* i: waiting for stored size (length and complement) */
  77660. COPY, /* i/o: waiting for input or output to copy stored block */
  77661. TABLE, /* i: waiting for dynamic block table lengths */
  77662. LENLENS, /* i: waiting for code length code lengths */
  77663. CODELENS, /* i: waiting for length/lit and distance code lengths */
  77664. LEN, /* i: waiting for length/lit code */
  77665. LENEXT, /* i: waiting for length extra bits */
  77666. DIST, /* i: waiting for distance code */
  77667. DISTEXT, /* i: waiting for distance extra bits */
  77668. MATCH, /* o: waiting for output space to copy string */
  77669. LIT, /* o: waiting for output space to write literal */
  77670. CHECK, /* i: waiting for 32-bit check value */
  77671. LENGTH, /* i: waiting for 32-bit length (gzip) */
  77672. DONE, /* finished check, done -- remain here until reset */
  77673. BAD, /* got a data error -- remain here until reset */
  77674. MEM, /* got an inflate() memory error -- remain here until reset */
  77675. SYNC /* looking for synchronization bytes to restart inflate() */
  77676. } inflate_mode;
  77677. struct inflate_state {
  77678. inflate_mode mode; /* current inflate mode */
  77679. int last; /* true if processing last block */
  77680. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  77681. int havedict; /* true if dictionary provided */
  77682. int flags; /* gzip header method and flags (0 if zlib) */
  77683. unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
  77684. unsigned long check; /* protected copy of check value */
  77685. unsigned long total; /* protected copy of output count */
  77686. gz_headerp head; /* where to save gzip header information */
  77687. unsigned wbits; /* log base 2 of requested window size */
  77688. unsigned wsize; /* window size or zero if not using window */
  77689. unsigned whave; /* valid bytes in the window */
  77690. unsigned write; /* window write index */
  77691. unsigned char FAR *window; /* allocated sliding window, if needed */
  77692. unsigned long hold; /* input bit accumulator */
  77693. unsigned bits; /* number of bits in "in" */
  77694. unsigned length; /* literal or length of data to copy */
  77695. unsigned offset; /* distance back to copy string from */
  77696. unsigned extra; /* extra bits needed */
  77697. code const FAR *lencode; /* starting table for length/literal codes */
  77698. code const FAR *distcode; /* starting table for distance codes */
  77699. unsigned lenbits; /* index bits for lencode */
  77700. unsigned distbits; /* index bits for distcode */
  77701. unsigned ncode; /* number of code length code lengths */
  77702. unsigned nlen; /* number of length code lengths */
  77703. unsigned ndist; /* number of distance code lengths */
  77704. unsigned have; /* number of code lengths in lens[] */
  77705. code FAR *next; /* next available space in codes[] */
  77706. unsigned short lens[320]; /* temporary storage for code lengths */
  77707. unsigned short work[288]; /* work area for code table building */
  77708. code codes[ENOUGH]; /* space for code tables */
  77709. };
  77710. #endif
  77711. /*** End of inlined file: inflate.h ***/
  77712. /*** Start of inlined file: inffast.h ***/
  77713. void inflate_fast OF((z_streamp strm, unsigned start));
  77714. /*** End of inlined file: inffast.h ***/
  77715. #ifndef ASMINF
  77716. #ifdef POSTINC
  77717. # define OFF 0
  77718. # define PUP(a) *(a)++
  77719. #else
  77720. # define OFF 1
  77721. # define PUP(a) *++(a)
  77722. #endif
  77723. void inflate_fast (z_streamp strm, unsigned start)
  77724. {
  77725. struct inflate_state FAR *state;
  77726. unsigned char FAR *in; /* local strm->next_in */
  77727. unsigned char FAR *last; /* while in < last, enough input available */
  77728. unsigned char FAR *out; /* local strm->next_out */
  77729. unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
  77730. unsigned char FAR *end; /* while out < end, enough space available */
  77731. #ifdef INFLATE_STRICT
  77732. unsigned dmax; /* maximum distance from zlib header */
  77733. #endif
  77734. unsigned wsize; /* window size or zero if not using window */
  77735. unsigned whave; /* valid bytes in the window */
  77736. unsigned write; /* window write index */
  77737. unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
  77738. unsigned long hold; /* local strm->hold */
  77739. unsigned bits; /* local strm->bits */
  77740. code const FAR *lcode; /* local strm->lencode */
  77741. code const FAR *dcode; /* local strm->distcode */
  77742. unsigned lmask; /* mask for first level of length codes */
  77743. unsigned dmask; /* mask for first level of distance codes */
  77744. code thisx; /* retrieved table entry */
  77745. unsigned op; /* code bits, operation, extra bits, or */
  77746. unsigned len; /* match length, unused bytes */
  77747. unsigned dist; /* match distance */
  77748. unsigned char FAR *from; /* where to copy match from */
  77749. state = (struct inflate_state FAR *)strm->state;
  77750. in = strm->next_in - OFF;
  77751. last = in + (strm->avail_in - 5);
  77752. out = strm->next_out - OFF;
  77753. beg = out - (start - strm->avail_out);
  77754. end = out + (strm->avail_out - 257);
  77755. #ifdef INFLATE_STRICT
  77756. dmax = state->dmax;
  77757. #endif
  77758. wsize = state->wsize;
  77759. whave = state->whave;
  77760. write = state->write;
  77761. window = state->window;
  77762. hold = state->hold;
  77763. bits = state->bits;
  77764. lcode = state->lencode;
  77765. dcode = state->distcode;
  77766. lmask = (1U << state->lenbits) - 1;
  77767. dmask = (1U << state->distbits) - 1;
  77768. do {
  77769. if (bits < 15) {
  77770. hold += (unsigned long)(PUP(in)) << bits;
  77771. bits += 8;
  77772. hold += (unsigned long)(PUP(in)) << bits;
  77773. bits += 8;
  77774. }
  77775. thisx = lcode[hold & lmask];
  77776. dolen:
  77777. op = (unsigned)(thisx.bits);
  77778. hold >>= op;
  77779. bits -= op;
  77780. op = (unsigned)(thisx.op);
  77781. if (op == 0) { /* literal */
  77782. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  77783. "inflate: literal '%c'\n" :
  77784. "inflate: literal 0x%02x\n", thisx.val));
  77785. PUP(out) = (unsigned char)(thisx.val);
  77786. }
  77787. else if (op & 16) { /* length base */
  77788. len = (unsigned)(thisx.val);
  77789. op &= 15; /* number of extra bits */
  77790. if (op) {
  77791. if (bits < op) {
  77792. hold += (unsigned long)(PUP(in)) << bits;
  77793. bits += 8;
  77794. }
  77795. len += (unsigned)hold & ((1U << op) - 1);
  77796. hold >>= op;
  77797. bits -= op;
  77798. }
  77799. Tracevv((stderr, "inflate: length %u\n", len));
  77800. if (bits < 15) {
  77801. hold += (unsigned long)(PUP(in)) << bits;
  77802. bits += 8;
  77803. hold += (unsigned long)(PUP(in)) << bits;
  77804. bits += 8;
  77805. }
  77806. thisx = dcode[hold & dmask];
  77807. dodist:
  77808. op = (unsigned)(thisx.bits);
  77809. hold >>= op;
  77810. bits -= op;
  77811. op = (unsigned)(thisx.op);
  77812. if (op & 16) { /* distance base */
  77813. dist = (unsigned)(thisx.val);
  77814. op &= 15; /* number of extra bits */
  77815. if (bits < op) {
  77816. hold += (unsigned long)(PUP(in)) << bits;
  77817. bits += 8;
  77818. if (bits < op) {
  77819. hold += (unsigned long)(PUP(in)) << bits;
  77820. bits += 8;
  77821. }
  77822. }
  77823. dist += (unsigned)hold & ((1U << op) - 1);
  77824. #ifdef INFLATE_STRICT
  77825. if (dist > dmax) {
  77826. strm->msg = (char *)"invalid distance too far back";
  77827. state->mode = BAD;
  77828. break;
  77829. }
  77830. #endif
  77831. hold >>= op;
  77832. bits -= op;
  77833. Tracevv((stderr, "inflate: distance %u\n", dist));
  77834. op = (unsigned)(out - beg); /* max distance in output */
  77835. if (dist > op) { /* see if copy from window */
  77836. op = dist - op; /* distance back in window */
  77837. if (op > whave) {
  77838. strm->msg = (char *)"invalid distance too far back";
  77839. state->mode = BAD;
  77840. break;
  77841. }
  77842. from = window - OFF;
  77843. if (write == 0) { /* very common case */
  77844. from += wsize - op;
  77845. if (op < len) { /* some from window */
  77846. len -= op;
  77847. do {
  77848. PUP(out) = PUP(from);
  77849. } while (--op);
  77850. from = out - dist; /* rest from output */
  77851. }
  77852. }
  77853. else if (write < op) { /* wrap around window */
  77854. from += wsize + write - op;
  77855. op -= write;
  77856. if (op < len) { /* some from end of window */
  77857. len -= op;
  77858. do {
  77859. PUP(out) = PUP(from);
  77860. } while (--op);
  77861. from = window - OFF;
  77862. if (write < len) { /* some from start of window */
  77863. op = write;
  77864. len -= op;
  77865. do {
  77866. PUP(out) = PUP(from);
  77867. } while (--op);
  77868. from = out - dist; /* rest from output */
  77869. }
  77870. }
  77871. }
  77872. else { /* contiguous in window */
  77873. from += write - op;
  77874. if (op < len) { /* some from window */
  77875. len -= op;
  77876. do {
  77877. PUP(out) = PUP(from);
  77878. } while (--op);
  77879. from = out - dist; /* rest from output */
  77880. }
  77881. }
  77882. while (len > 2) {
  77883. PUP(out) = PUP(from);
  77884. PUP(out) = PUP(from);
  77885. PUP(out) = PUP(from);
  77886. len -= 3;
  77887. }
  77888. if (len) {
  77889. PUP(out) = PUP(from);
  77890. if (len > 1)
  77891. PUP(out) = PUP(from);
  77892. }
  77893. }
  77894. else {
  77895. from = out - dist; /* copy direct from output */
  77896. do { /* minimum length is three */
  77897. PUP(out) = PUP(from);
  77898. PUP(out) = PUP(from);
  77899. PUP(out) = PUP(from);
  77900. len -= 3;
  77901. } while (len > 2);
  77902. if (len) {
  77903. PUP(out) = PUP(from);
  77904. if (len > 1)
  77905. PUP(out) = PUP(from);
  77906. }
  77907. }
  77908. }
  77909. else if ((op & 64) == 0) { /* 2nd level distance code */
  77910. thisx = dcode[thisx.val + (hold & ((1U << op) - 1))];
  77911. goto dodist;
  77912. }
  77913. else {
  77914. strm->msg = (char *)"invalid distance code";
  77915. state->mode = BAD;
  77916. break;
  77917. }
  77918. }
  77919. else if ((op & 64) == 0) { /* 2nd level length code */
  77920. thisx = lcode[thisx.val + (hold & ((1U << op) - 1))];
  77921. goto dolen;
  77922. }
  77923. else if (op & 32) { /* end-of-block */
  77924. Tracevv((stderr, "inflate: end of block\n"));
  77925. state->mode = TYPE;
  77926. break;
  77927. }
  77928. else {
  77929. strm->msg = (char *)"invalid literal/length code";
  77930. state->mode = BAD;
  77931. break;
  77932. }
  77933. } while (in < last && out < end);
  77934. len = bits >> 3;
  77935. in -= len;
  77936. bits -= len << 3;
  77937. hold &= (1U << bits) - 1;
  77938. strm->next_in = in + OFF;
  77939. strm->next_out = out + OFF;
  77940. strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
  77941. strm->avail_out = (unsigned)(out < end ?
  77942. 257 + (end - out) : 257 - (out - end));
  77943. state->hold = hold;
  77944. state->bits = bits;
  77945. return;
  77946. }
  77947. #endif /* !ASMINF */
  77948. /*** End of inlined file: inffast.c ***/
  77949. #undef PULLBYTE
  77950. #undef LOAD
  77951. #undef RESTORE
  77952. #undef INITBITS
  77953. #undef NEEDBITS
  77954. #undef DROPBITS
  77955. #undef BYTEBITS
  77956. /*** Start of inlined file: inflate.c ***/
  77957. /*** Start of inlined file: inffast.h ***/
  77958. void inflate_fast OF((z_streamp strm, unsigned start));
  77959. /*** End of inlined file: inffast.h ***/
  77960. #ifdef MAKEFIXED
  77961. # ifndef BUILDFIXED
  77962. # define BUILDFIXED
  77963. # endif
  77964. #endif
  77965. local void fixedtables OF((struct inflate_state FAR *state));
  77966. local int updatewindow OF((z_streamp strm, unsigned out));
  77967. #ifdef BUILDFIXED
  77968. void makefixed OF((void));
  77969. #endif
  77970. local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf,
  77971. unsigned len));
  77972. int ZEXPORT inflateReset (z_streamp strm)
  77973. {
  77974. struct inflate_state FAR *state;
  77975. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77976. state = (struct inflate_state FAR *)strm->state;
  77977. strm->total_in = strm->total_out = state->total = 0;
  77978. strm->msg = Z_NULL;
  77979. strm->adler = 1; /* to support ill-conceived Java test suite */
  77980. state->mode = HEAD;
  77981. state->last = 0;
  77982. state->havedict = 0;
  77983. state->dmax = 32768U;
  77984. state->head = Z_NULL;
  77985. state->wsize = 0;
  77986. state->whave = 0;
  77987. state->write = 0;
  77988. state->hold = 0;
  77989. state->bits = 0;
  77990. state->lencode = state->distcode = state->next = state->codes;
  77991. Tracev((stderr, "inflate: reset\n"));
  77992. return Z_OK;
  77993. }
  77994. int ZEXPORT inflatePrime (z_streamp strm, int bits, int value)
  77995. {
  77996. struct inflate_state FAR *state;
  77997. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77998. state = (struct inflate_state FAR *)strm->state;
  77999. if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
  78000. value &= (1L << bits) - 1;
  78001. state->hold += value << state->bits;
  78002. state->bits += bits;
  78003. return Z_OK;
  78004. }
  78005. int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
  78006. {
  78007. struct inflate_state FAR *state;
  78008. if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
  78009. stream_size != (int)(sizeof(z_stream)))
  78010. return Z_VERSION_ERROR;
  78011. if (strm == Z_NULL) return Z_STREAM_ERROR;
  78012. strm->msg = Z_NULL; /* in case we return an error */
  78013. if (strm->zalloc == (alloc_func)0) {
  78014. strm->zalloc = zcalloc;
  78015. strm->opaque = (voidpf)0;
  78016. }
  78017. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  78018. state = (struct inflate_state FAR *)
  78019. ZALLOC(strm, 1, sizeof(struct inflate_state));
  78020. if (state == Z_NULL) return Z_MEM_ERROR;
  78021. Tracev((stderr, "inflate: allocated\n"));
  78022. strm->state = (struct internal_state FAR *)state;
  78023. if (windowBits < 0) {
  78024. state->wrap = 0;
  78025. windowBits = -windowBits;
  78026. }
  78027. else {
  78028. state->wrap = (windowBits >> 4) + 1;
  78029. #ifdef GUNZIP
  78030. if (windowBits < 48) windowBits &= 15;
  78031. #endif
  78032. }
  78033. if (windowBits < 8 || windowBits > 15) {
  78034. ZFREE(strm, state);
  78035. strm->state = Z_NULL;
  78036. return Z_STREAM_ERROR;
  78037. }
  78038. state->wbits = (unsigned)windowBits;
  78039. state->window = Z_NULL;
  78040. return inflateReset(strm);
  78041. }
  78042. int ZEXPORT inflateInit_ (z_streamp strm, const char *version, int stream_size)
  78043. {
  78044. return inflateInit2_(strm, DEF_WBITS, version, stream_size);
  78045. }
  78046. local void fixedtables (struct inflate_state FAR *state)
  78047. {
  78048. #ifdef BUILDFIXED
  78049. static int virgin = 1;
  78050. static code *lenfix, *distfix;
  78051. static code fixed[544];
  78052. if (virgin) {
  78053. unsigned sym, bits;
  78054. static code *next;
  78055. sym = 0;
  78056. while (sym < 144) state->lens[sym++] = 8;
  78057. while (sym < 256) state->lens[sym++] = 9;
  78058. while (sym < 280) state->lens[sym++] = 7;
  78059. while (sym < 288) state->lens[sym++] = 8;
  78060. next = fixed;
  78061. lenfix = next;
  78062. bits = 9;
  78063. inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
  78064. sym = 0;
  78065. while (sym < 32) state->lens[sym++] = 5;
  78066. distfix = next;
  78067. bits = 5;
  78068. inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
  78069. virgin = 0;
  78070. }
  78071. #else /* !BUILDFIXED */
  78072. /*** Start of inlined file: inffixed.h ***/
  78073. static const code lenfix[512] = {
  78074. {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
  78075. {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
  78076. {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
  78077. {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
  78078. {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
  78079. {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
  78080. {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
  78081. {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
  78082. {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
  78083. {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
  78084. {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
  78085. {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
  78086. {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
  78087. {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
  78088. {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
  78089. {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
  78090. {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
  78091. {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
  78092. {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
  78093. {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
  78094. {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
  78095. {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
  78096. {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
  78097. {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
  78098. {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
  78099. {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
  78100. {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
  78101. {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
  78102. {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
  78103. {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
  78104. {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
  78105. {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
  78106. {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
  78107. {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
  78108. {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
  78109. {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
  78110. {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
  78111. {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
  78112. {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
  78113. {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
  78114. {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
  78115. {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
  78116. {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
  78117. {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
  78118. {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
  78119. {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
  78120. {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
  78121. {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
  78122. {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
  78123. {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
  78124. {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
  78125. {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
  78126. {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
  78127. {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
  78128. {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
  78129. {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
  78130. {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
  78131. {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
  78132. {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
  78133. {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
  78134. {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
  78135. {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
  78136. {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
  78137. {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
  78138. {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
  78139. {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
  78140. {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
  78141. {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
  78142. {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
  78143. {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
  78144. {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
  78145. {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
  78146. {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
  78147. {0,9,255}
  78148. };
  78149. static const code distfix[32] = {
  78150. {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
  78151. {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
  78152. {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
  78153. {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
  78154. {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
  78155. {22,5,193},{64,5,0}
  78156. };
  78157. /*** End of inlined file: inffixed.h ***/
  78158. #endif /* BUILDFIXED */
  78159. state->lencode = lenfix;
  78160. state->lenbits = 9;
  78161. state->distcode = distfix;
  78162. state->distbits = 5;
  78163. }
  78164. #ifdef MAKEFIXED
  78165. #include <stdio.h>
  78166. void makefixed()
  78167. {
  78168. unsigned low, size;
  78169. struct inflate_state state;
  78170. fixedtables(&state);
  78171. puts(" /* inffixed.h -- table for decoding fixed codes");
  78172. puts(" * Generated automatically by makefixed().");
  78173. puts(" */");
  78174. puts("");
  78175. puts(" /* WARNING: this file should *not* be used by applications.");
  78176. puts(" It is part of the implementation of this library and is");
  78177. puts(" subject to change. Applications should only use zlib.h.");
  78178. puts(" */");
  78179. puts("");
  78180. size = 1U << 9;
  78181. printf(" static const code lenfix[%u] = {", size);
  78182. low = 0;
  78183. for (;;) {
  78184. if ((low % 7) == 0) printf("\n ");
  78185. printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
  78186. state.lencode[low].val);
  78187. if (++low == size) break;
  78188. putchar(',');
  78189. }
  78190. puts("\n };");
  78191. size = 1U << 5;
  78192. printf("\n static const code distfix[%u] = {", size);
  78193. low = 0;
  78194. for (;;) {
  78195. if ((low % 6) == 0) printf("\n ");
  78196. printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
  78197. state.distcode[low].val);
  78198. if (++low == size) break;
  78199. putchar(',');
  78200. }
  78201. puts("\n };");
  78202. }
  78203. #endif /* MAKEFIXED */
  78204. local int updatewindow (z_streamp strm, unsigned out)
  78205. {
  78206. struct inflate_state FAR *state;
  78207. unsigned copy, dist;
  78208. state = (struct inflate_state FAR *)strm->state;
  78209. if (state->window == Z_NULL) {
  78210. state->window = (unsigned char FAR *)
  78211. ZALLOC(strm, 1U << state->wbits,
  78212. sizeof(unsigned char));
  78213. if (state->window == Z_NULL) return 1;
  78214. }
  78215. if (state->wsize == 0) {
  78216. state->wsize = 1U << state->wbits;
  78217. state->write = 0;
  78218. state->whave = 0;
  78219. }
  78220. copy = out - strm->avail_out;
  78221. if (copy >= state->wsize) {
  78222. zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
  78223. state->write = 0;
  78224. state->whave = state->wsize;
  78225. }
  78226. else {
  78227. dist = state->wsize - state->write;
  78228. if (dist > copy) dist = copy;
  78229. zmemcpy(state->window + state->write, strm->next_out - copy, dist);
  78230. copy -= dist;
  78231. if (copy) {
  78232. zmemcpy(state->window, strm->next_out - copy, copy);
  78233. state->write = copy;
  78234. state->whave = state->wsize;
  78235. }
  78236. else {
  78237. state->write += dist;
  78238. if (state->write == state->wsize) state->write = 0;
  78239. if (state->whave < state->wsize) state->whave += dist;
  78240. }
  78241. }
  78242. return 0;
  78243. }
  78244. #ifdef GUNZIP
  78245. # define UPDATE(check, buf, len) \
  78246. (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
  78247. #else
  78248. # define UPDATE(check, buf, len) adler32(check, buf, len)
  78249. #endif
  78250. #ifdef GUNZIP
  78251. # define CRC2(check, word) \
  78252. do { \
  78253. hbuf[0] = (unsigned char)(word); \
  78254. hbuf[1] = (unsigned char)((word) >> 8); \
  78255. check = crc32(check, hbuf, 2); \
  78256. } while (0)
  78257. # define CRC4(check, word) \
  78258. do { \
  78259. hbuf[0] = (unsigned char)(word); \
  78260. hbuf[1] = (unsigned char)((word) >> 8); \
  78261. hbuf[2] = (unsigned char)((word) >> 16); \
  78262. hbuf[3] = (unsigned char)((word) >> 24); \
  78263. check = crc32(check, hbuf, 4); \
  78264. } while (0)
  78265. #endif
  78266. #define LOAD() \
  78267. do { \
  78268. put = strm->next_out; \
  78269. left = strm->avail_out; \
  78270. next = strm->next_in; \
  78271. have = strm->avail_in; \
  78272. hold = state->hold; \
  78273. bits = state->bits; \
  78274. } while (0)
  78275. #define RESTORE() \
  78276. do { \
  78277. strm->next_out = put; \
  78278. strm->avail_out = left; \
  78279. strm->next_in = next; \
  78280. strm->avail_in = have; \
  78281. state->hold = hold; \
  78282. state->bits = bits; \
  78283. } while (0)
  78284. #define INITBITS() \
  78285. do { \
  78286. hold = 0; \
  78287. bits = 0; \
  78288. } while (0)
  78289. #define PULLBYTE() \
  78290. do { \
  78291. if (have == 0) goto inf_leave; \
  78292. have--; \
  78293. hold += (unsigned long)(*next++) << bits; \
  78294. bits += 8; \
  78295. } while (0)
  78296. #define NEEDBITS(n) \
  78297. do { \
  78298. while (bits < (unsigned)(n)) \
  78299. PULLBYTE(); \
  78300. } while (0)
  78301. #define BITS(n) \
  78302. ((unsigned)hold & ((1U << (n)) - 1))
  78303. #define DROPBITS(n) \
  78304. do { \
  78305. hold >>= (n); \
  78306. bits -= (unsigned)(n); \
  78307. } while (0)
  78308. #define BYTEBITS() \
  78309. do { \
  78310. hold >>= bits & 7; \
  78311. bits -= bits & 7; \
  78312. } while (0)
  78313. #define REVERSE(q) \
  78314. ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
  78315. (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
  78316. int ZEXPORT inflate (z_streamp strm, int flush)
  78317. {
  78318. struct inflate_state FAR *state;
  78319. unsigned char FAR *next; /* next input */
  78320. unsigned char FAR *put; /* next output */
  78321. unsigned have, left; /* available input and output */
  78322. unsigned long hold; /* bit buffer */
  78323. unsigned bits; /* bits in bit buffer */
  78324. unsigned in, out; /* save starting available input and output */
  78325. unsigned copy; /* number of stored or match bytes to copy */
  78326. unsigned char FAR *from; /* where to copy match bytes from */
  78327. code thisx; /* current decoding table entry */
  78328. code last; /* parent table entry */
  78329. unsigned len; /* length to copy for repeats, bits to drop */
  78330. int ret; /* return code */
  78331. #ifdef GUNZIP
  78332. unsigned char hbuf[4]; /* buffer for gzip header crc calculation */
  78333. #endif
  78334. static const unsigned short order[19] = /* permutation of code lengths */
  78335. {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
  78336. if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
  78337. (strm->next_in == Z_NULL && strm->avail_in != 0))
  78338. return Z_STREAM_ERROR;
  78339. state = (struct inflate_state FAR *)strm->state;
  78340. if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
  78341. LOAD();
  78342. in = have;
  78343. out = left;
  78344. ret = Z_OK;
  78345. for (;;)
  78346. switch (state->mode) {
  78347. case HEAD:
  78348. if (state->wrap == 0) {
  78349. state->mode = TYPEDO;
  78350. break;
  78351. }
  78352. NEEDBITS(16);
  78353. #ifdef GUNZIP
  78354. if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
  78355. state->check = crc32(0L, Z_NULL, 0);
  78356. CRC2(state->check, hold);
  78357. INITBITS();
  78358. state->mode = FLAGS;
  78359. break;
  78360. }
  78361. state->flags = 0; /* expect zlib header */
  78362. if (state->head != Z_NULL)
  78363. state->head->done = -1;
  78364. if (!(state->wrap & 1) || /* check if zlib header allowed */
  78365. #else
  78366. if (
  78367. #endif
  78368. ((BITS(8) << 8) + (hold >> 8)) % 31) {
  78369. strm->msg = (char *)"incorrect header check";
  78370. state->mode = BAD;
  78371. break;
  78372. }
  78373. if (BITS(4) != Z_DEFLATED) {
  78374. strm->msg = (char *)"unknown compression method";
  78375. state->mode = BAD;
  78376. break;
  78377. }
  78378. DROPBITS(4);
  78379. len = BITS(4) + 8;
  78380. if (len > state->wbits) {
  78381. strm->msg = (char *)"invalid window size";
  78382. state->mode = BAD;
  78383. break;
  78384. }
  78385. state->dmax = 1U << len;
  78386. Tracev((stderr, "inflate: zlib header ok\n"));
  78387. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78388. state->mode = hold & 0x200 ? DICTID : TYPE;
  78389. INITBITS();
  78390. break;
  78391. #ifdef GUNZIP
  78392. case FLAGS:
  78393. NEEDBITS(16);
  78394. state->flags = (int)(hold);
  78395. if ((state->flags & 0xff) != Z_DEFLATED) {
  78396. strm->msg = (char *)"unknown compression method";
  78397. state->mode = BAD;
  78398. break;
  78399. }
  78400. if (state->flags & 0xe000) {
  78401. strm->msg = (char *)"unknown header flags set";
  78402. state->mode = BAD;
  78403. break;
  78404. }
  78405. if (state->head != Z_NULL)
  78406. state->head->text = (int)((hold >> 8) & 1);
  78407. if (state->flags & 0x0200) CRC2(state->check, hold);
  78408. INITBITS();
  78409. state->mode = TIME;
  78410. case TIME:
  78411. NEEDBITS(32);
  78412. if (state->head != Z_NULL)
  78413. state->head->time = hold;
  78414. if (state->flags & 0x0200) CRC4(state->check, hold);
  78415. INITBITS();
  78416. state->mode = OS;
  78417. case OS:
  78418. NEEDBITS(16);
  78419. if (state->head != Z_NULL) {
  78420. state->head->xflags = (int)(hold & 0xff);
  78421. state->head->os = (int)(hold >> 8);
  78422. }
  78423. if (state->flags & 0x0200) CRC2(state->check, hold);
  78424. INITBITS();
  78425. state->mode = EXLEN;
  78426. case EXLEN:
  78427. if (state->flags & 0x0400) {
  78428. NEEDBITS(16);
  78429. state->length = (unsigned)(hold);
  78430. if (state->head != Z_NULL)
  78431. state->head->extra_len = (unsigned)hold;
  78432. if (state->flags & 0x0200) CRC2(state->check, hold);
  78433. INITBITS();
  78434. }
  78435. else if (state->head != Z_NULL)
  78436. state->head->extra = Z_NULL;
  78437. state->mode = EXTRA;
  78438. case EXTRA:
  78439. if (state->flags & 0x0400) {
  78440. copy = state->length;
  78441. if (copy > have) copy = have;
  78442. if (copy) {
  78443. if (state->head != Z_NULL &&
  78444. state->head->extra != Z_NULL) {
  78445. len = state->head->extra_len - state->length;
  78446. zmemcpy(state->head->extra + len, next,
  78447. len + copy > state->head->extra_max ?
  78448. state->head->extra_max - len : copy);
  78449. }
  78450. if (state->flags & 0x0200)
  78451. state->check = crc32(state->check, next, copy);
  78452. have -= copy;
  78453. next += copy;
  78454. state->length -= copy;
  78455. }
  78456. if (state->length) goto inf_leave;
  78457. }
  78458. state->length = 0;
  78459. state->mode = NAME;
  78460. case NAME:
  78461. if (state->flags & 0x0800) {
  78462. if (have == 0) goto inf_leave;
  78463. copy = 0;
  78464. do {
  78465. len = (unsigned)(next[copy++]);
  78466. if (state->head != Z_NULL &&
  78467. state->head->name != Z_NULL &&
  78468. state->length < state->head->name_max)
  78469. state->head->name[state->length++] = len;
  78470. } while (len && copy < have);
  78471. if (state->flags & 0x0200)
  78472. state->check = crc32(state->check, next, copy);
  78473. have -= copy;
  78474. next += copy;
  78475. if (len) goto inf_leave;
  78476. }
  78477. else if (state->head != Z_NULL)
  78478. state->head->name = Z_NULL;
  78479. state->length = 0;
  78480. state->mode = COMMENT;
  78481. case COMMENT:
  78482. if (state->flags & 0x1000) {
  78483. if (have == 0) goto inf_leave;
  78484. copy = 0;
  78485. do {
  78486. len = (unsigned)(next[copy++]);
  78487. if (state->head != Z_NULL &&
  78488. state->head->comment != Z_NULL &&
  78489. state->length < state->head->comm_max)
  78490. state->head->comment[state->length++] = len;
  78491. } while (len && copy < have);
  78492. if (state->flags & 0x0200)
  78493. state->check = crc32(state->check, next, copy);
  78494. have -= copy;
  78495. next += copy;
  78496. if (len) goto inf_leave;
  78497. }
  78498. else if (state->head != Z_NULL)
  78499. state->head->comment = Z_NULL;
  78500. state->mode = HCRC;
  78501. case HCRC:
  78502. if (state->flags & 0x0200) {
  78503. NEEDBITS(16);
  78504. if (hold != (state->check & 0xffff)) {
  78505. strm->msg = (char *)"header crc mismatch";
  78506. state->mode = BAD;
  78507. break;
  78508. }
  78509. INITBITS();
  78510. }
  78511. if (state->head != Z_NULL) {
  78512. state->head->hcrc = (int)((state->flags >> 9) & 1);
  78513. state->head->done = 1;
  78514. }
  78515. strm->adler = state->check = crc32(0L, Z_NULL, 0);
  78516. state->mode = TYPE;
  78517. break;
  78518. #endif
  78519. case DICTID:
  78520. NEEDBITS(32);
  78521. strm->adler = state->check = REVERSE(hold);
  78522. INITBITS();
  78523. state->mode = DICT;
  78524. case DICT:
  78525. if (state->havedict == 0) {
  78526. RESTORE();
  78527. return Z_NEED_DICT;
  78528. }
  78529. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78530. state->mode = TYPE;
  78531. case TYPE:
  78532. if (flush == Z_BLOCK) goto inf_leave;
  78533. case TYPEDO:
  78534. if (state->last) {
  78535. BYTEBITS();
  78536. state->mode = CHECK;
  78537. break;
  78538. }
  78539. NEEDBITS(3);
  78540. state->last = BITS(1);
  78541. DROPBITS(1);
  78542. switch (BITS(2)) {
  78543. case 0: /* stored block */
  78544. Tracev((stderr, "inflate: stored block%s\n",
  78545. state->last ? " (last)" : ""));
  78546. state->mode = STORED;
  78547. break;
  78548. case 1: /* fixed block */
  78549. fixedtables(state);
  78550. Tracev((stderr, "inflate: fixed codes block%s\n",
  78551. state->last ? " (last)" : ""));
  78552. state->mode = LEN; /* decode codes */
  78553. break;
  78554. case 2: /* dynamic block */
  78555. Tracev((stderr, "inflate: dynamic codes block%s\n",
  78556. state->last ? " (last)" : ""));
  78557. state->mode = TABLE;
  78558. break;
  78559. case 3:
  78560. strm->msg = (char *)"invalid block type";
  78561. state->mode = BAD;
  78562. }
  78563. DROPBITS(2);
  78564. break;
  78565. case STORED:
  78566. BYTEBITS(); /* go to byte boundary */
  78567. NEEDBITS(32);
  78568. if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
  78569. strm->msg = (char *)"invalid stored block lengths";
  78570. state->mode = BAD;
  78571. break;
  78572. }
  78573. state->length = (unsigned)hold & 0xffff;
  78574. Tracev((stderr, "inflate: stored length %u\n",
  78575. state->length));
  78576. INITBITS();
  78577. state->mode = COPY;
  78578. case COPY:
  78579. copy = state->length;
  78580. if (copy) {
  78581. if (copy > have) copy = have;
  78582. if (copy > left) copy = left;
  78583. if (copy == 0) goto inf_leave;
  78584. zmemcpy(put, next, copy);
  78585. have -= copy;
  78586. next += copy;
  78587. left -= copy;
  78588. put += copy;
  78589. state->length -= copy;
  78590. break;
  78591. }
  78592. Tracev((stderr, "inflate: stored end\n"));
  78593. state->mode = TYPE;
  78594. break;
  78595. case TABLE:
  78596. NEEDBITS(14);
  78597. state->nlen = BITS(5) + 257;
  78598. DROPBITS(5);
  78599. state->ndist = BITS(5) + 1;
  78600. DROPBITS(5);
  78601. state->ncode = BITS(4) + 4;
  78602. DROPBITS(4);
  78603. #ifndef PKZIP_BUG_WORKAROUND
  78604. if (state->nlen > 286 || state->ndist > 30) {
  78605. strm->msg = (char *)"too many length or distance symbols";
  78606. state->mode = BAD;
  78607. break;
  78608. }
  78609. #endif
  78610. Tracev((stderr, "inflate: table sizes ok\n"));
  78611. state->have = 0;
  78612. state->mode = LENLENS;
  78613. case LENLENS:
  78614. while (state->have < state->ncode) {
  78615. NEEDBITS(3);
  78616. state->lens[order[state->have++]] = (unsigned short)BITS(3);
  78617. DROPBITS(3);
  78618. }
  78619. while (state->have < 19)
  78620. state->lens[order[state->have++]] = 0;
  78621. state->next = state->codes;
  78622. state->lencode = (code const FAR *)(state->next);
  78623. state->lenbits = 7;
  78624. ret = inflate_table(CODES, state->lens, 19, &(state->next),
  78625. &(state->lenbits), state->work);
  78626. if (ret) {
  78627. strm->msg = (char *)"invalid code lengths set";
  78628. state->mode = BAD;
  78629. break;
  78630. }
  78631. Tracev((stderr, "inflate: code lengths ok\n"));
  78632. state->have = 0;
  78633. state->mode = CODELENS;
  78634. case CODELENS:
  78635. while (state->have < state->nlen + state->ndist) {
  78636. for (;;) {
  78637. thisx = state->lencode[BITS(state->lenbits)];
  78638. if ((unsigned)(thisx.bits) <= bits) break;
  78639. PULLBYTE();
  78640. }
  78641. if (thisx.val < 16) {
  78642. NEEDBITS(thisx.bits);
  78643. DROPBITS(thisx.bits);
  78644. state->lens[state->have++] = thisx.val;
  78645. }
  78646. else {
  78647. if (thisx.val == 16) {
  78648. NEEDBITS(thisx.bits + 2);
  78649. DROPBITS(thisx.bits);
  78650. if (state->have == 0) {
  78651. strm->msg = (char *)"invalid bit length repeat";
  78652. state->mode = BAD;
  78653. break;
  78654. }
  78655. len = state->lens[state->have - 1];
  78656. copy = 3 + BITS(2);
  78657. DROPBITS(2);
  78658. }
  78659. else if (thisx.val == 17) {
  78660. NEEDBITS(thisx.bits + 3);
  78661. DROPBITS(thisx.bits);
  78662. len = 0;
  78663. copy = 3 + BITS(3);
  78664. DROPBITS(3);
  78665. }
  78666. else {
  78667. NEEDBITS(thisx.bits + 7);
  78668. DROPBITS(thisx.bits);
  78669. len = 0;
  78670. copy = 11 + BITS(7);
  78671. DROPBITS(7);
  78672. }
  78673. if (state->have + copy > state->nlen + state->ndist) {
  78674. strm->msg = (char *)"invalid bit length repeat";
  78675. state->mode = BAD;
  78676. break;
  78677. }
  78678. while (copy--)
  78679. state->lens[state->have++] = (unsigned short)len;
  78680. }
  78681. }
  78682. if (state->mode == BAD) break;
  78683. state->next = state->codes;
  78684. state->lencode = (code const FAR *)(state->next);
  78685. state->lenbits = 9;
  78686. ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
  78687. &(state->lenbits), state->work);
  78688. if (ret) {
  78689. strm->msg = (char *)"invalid literal/lengths set";
  78690. state->mode = BAD;
  78691. break;
  78692. }
  78693. state->distcode = (code const FAR *)(state->next);
  78694. state->distbits = 6;
  78695. ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
  78696. &(state->next), &(state->distbits), state->work);
  78697. if (ret) {
  78698. strm->msg = (char *)"invalid distances set";
  78699. state->mode = BAD;
  78700. break;
  78701. }
  78702. Tracev((stderr, "inflate: codes ok\n"));
  78703. state->mode = LEN;
  78704. case LEN:
  78705. if (have >= 6 && left >= 258) {
  78706. RESTORE();
  78707. inflate_fast(strm, out);
  78708. LOAD();
  78709. break;
  78710. }
  78711. for (;;) {
  78712. thisx = state->lencode[BITS(state->lenbits)];
  78713. if ((unsigned)(thisx.bits) <= bits) break;
  78714. PULLBYTE();
  78715. }
  78716. if (thisx.op && (thisx.op & 0xf0) == 0) {
  78717. last = thisx;
  78718. for (;;) {
  78719. thisx = state->lencode[last.val +
  78720. (BITS(last.bits + last.op) >> last.bits)];
  78721. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  78722. PULLBYTE();
  78723. }
  78724. DROPBITS(last.bits);
  78725. }
  78726. DROPBITS(thisx.bits);
  78727. state->length = (unsigned)thisx.val;
  78728. if ((int)(thisx.op) == 0) {
  78729. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  78730. "inflate: literal '%c'\n" :
  78731. "inflate: literal 0x%02x\n", thisx.val));
  78732. state->mode = LIT;
  78733. break;
  78734. }
  78735. if (thisx.op & 32) {
  78736. Tracevv((stderr, "inflate: end of block\n"));
  78737. state->mode = TYPE;
  78738. break;
  78739. }
  78740. if (thisx.op & 64) {
  78741. strm->msg = (char *)"invalid literal/length code";
  78742. state->mode = BAD;
  78743. break;
  78744. }
  78745. state->extra = (unsigned)(thisx.op) & 15;
  78746. state->mode = LENEXT;
  78747. case LENEXT:
  78748. if (state->extra) {
  78749. NEEDBITS(state->extra);
  78750. state->length += BITS(state->extra);
  78751. DROPBITS(state->extra);
  78752. }
  78753. Tracevv((stderr, "inflate: length %u\n", state->length));
  78754. state->mode = DIST;
  78755. case DIST:
  78756. for (;;) {
  78757. thisx = state->distcode[BITS(state->distbits)];
  78758. if ((unsigned)(thisx.bits) <= bits) break;
  78759. PULLBYTE();
  78760. }
  78761. if ((thisx.op & 0xf0) == 0) {
  78762. last = thisx;
  78763. for (;;) {
  78764. thisx = state->distcode[last.val +
  78765. (BITS(last.bits + last.op) >> last.bits)];
  78766. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  78767. PULLBYTE();
  78768. }
  78769. DROPBITS(last.bits);
  78770. }
  78771. DROPBITS(thisx.bits);
  78772. if (thisx.op & 64) {
  78773. strm->msg = (char *)"invalid distance code";
  78774. state->mode = BAD;
  78775. break;
  78776. }
  78777. state->offset = (unsigned)thisx.val;
  78778. state->extra = (unsigned)(thisx.op) & 15;
  78779. state->mode = DISTEXT;
  78780. case DISTEXT:
  78781. if (state->extra) {
  78782. NEEDBITS(state->extra);
  78783. state->offset += BITS(state->extra);
  78784. DROPBITS(state->extra);
  78785. }
  78786. #ifdef INFLATE_STRICT
  78787. if (state->offset > state->dmax) {
  78788. strm->msg = (char *)"invalid distance too far back";
  78789. state->mode = BAD;
  78790. break;
  78791. }
  78792. #endif
  78793. if (state->offset > state->whave + out - left) {
  78794. strm->msg = (char *)"invalid distance too far back";
  78795. state->mode = BAD;
  78796. break;
  78797. }
  78798. Tracevv((stderr, "inflate: distance %u\n", state->offset));
  78799. state->mode = MATCH;
  78800. case MATCH:
  78801. if (left == 0) goto inf_leave;
  78802. copy = out - left;
  78803. if (state->offset > copy) { /* copy from window */
  78804. copy = state->offset - copy;
  78805. if (copy > state->write) {
  78806. copy -= state->write;
  78807. from = state->window + (state->wsize - copy);
  78808. }
  78809. else
  78810. from = state->window + (state->write - copy);
  78811. if (copy > state->length) copy = state->length;
  78812. }
  78813. else { /* copy from output */
  78814. from = put - state->offset;
  78815. copy = state->length;
  78816. }
  78817. if (copy > left) copy = left;
  78818. left -= copy;
  78819. state->length -= copy;
  78820. do {
  78821. *put++ = *from++;
  78822. } while (--copy);
  78823. if (state->length == 0) state->mode = LEN;
  78824. break;
  78825. case LIT:
  78826. if (left == 0) goto inf_leave;
  78827. *put++ = (unsigned char)(state->length);
  78828. left--;
  78829. state->mode = LEN;
  78830. break;
  78831. case CHECK:
  78832. if (state->wrap) {
  78833. NEEDBITS(32);
  78834. out -= left;
  78835. strm->total_out += out;
  78836. state->total += out;
  78837. if (out)
  78838. strm->adler = state->check =
  78839. UPDATE(state->check, put - out, out);
  78840. out = left;
  78841. if ((
  78842. #ifdef GUNZIP
  78843. state->flags ? hold :
  78844. #endif
  78845. REVERSE(hold)) != state->check) {
  78846. strm->msg = (char *)"incorrect data check";
  78847. state->mode = BAD;
  78848. break;
  78849. }
  78850. INITBITS();
  78851. Tracev((stderr, "inflate: check matches trailer\n"));
  78852. }
  78853. #ifdef GUNZIP
  78854. state->mode = LENGTH;
  78855. case LENGTH:
  78856. if (state->wrap && state->flags) {
  78857. NEEDBITS(32);
  78858. if (hold != (state->total & 0xffffffffUL)) {
  78859. strm->msg = (char *)"incorrect length check";
  78860. state->mode = BAD;
  78861. break;
  78862. }
  78863. INITBITS();
  78864. Tracev((stderr, "inflate: length matches trailer\n"));
  78865. }
  78866. #endif
  78867. state->mode = DONE;
  78868. case DONE:
  78869. ret = Z_STREAM_END;
  78870. goto inf_leave;
  78871. case BAD:
  78872. ret = Z_DATA_ERROR;
  78873. goto inf_leave;
  78874. case MEM:
  78875. return Z_MEM_ERROR;
  78876. case SYNC:
  78877. default:
  78878. return Z_STREAM_ERROR;
  78879. }
  78880. inf_leave:
  78881. RESTORE();
  78882. if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
  78883. if (updatewindow(strm, out)) {
  78884. state->mode = MEM;
  78885. return Z_MEM_ERROR;
  78886. }
  78887. in -= strm->avail_in;
  78888. out -= strm->avail_out;
  78889. strm->total_in += in;
  78890. strm->total_out += out;
  78891. state->total += out;
  78892. if (state->wrap && out)
  78893. strm->adler = state->check =
  78894. UPDATE(state->check, strm->next_out - out, out);
  78895. strm->data_type = state->bits + (state->last ? 64 : 0) +
  78896. (state->mode == TYPE ? 128 : 0);
  78897. if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
  78898. ret = Z_BUF_ERROR;
  78899. return ret;
  78900. }
  78901. int ZEXPORT inflateEnd (z_streamp strm)
  78902. {
  78903. struct inflate_state FAR *state;
  78904. if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
  78905. return Z_STREAM_ERROR;
  78906. state = (struct inflate_state FAR *)strm->state;
  78907. if (state->window != Z_NULL) ZFREE(strm, state->window);
  78908. ZFREE(strm, strm->state);
  78909. strm->state = Z_NULL;
  78910. Tracev((stderr, "inflate: end\n"));
  78911. return Z_OK;
  78912. }
  78913. int ZEXPORT inflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  78914. {
  78915. struct inflate_state FAR *state;
  78916. unsigned long id_;
  78917. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78918. state = (struct inflate_state FAR *)strm->state;
  78919. if (state->wrap != 0 && state->mode != DICT)
  78920. return Z_STREAM_ERROR;
  78921. if (state->mode == DICT) {
  78922. id_ = adler32(0L, Z_NULL, 0);
  78923. id_ = adler32(id_, dictionary, dictLength);
  78924. if (id_ != state->check)
  78925. return Z_DATA_ERROR;
  78926. }
  78927. if (updatewindow(strm, strm->avail_out)) {
  78928. state->mode = MEM;
  78929. return Z_MEM_ERROR;
  78930. }
  78931. if (dictLength > state->wsize) {
  78932. zmemcpy(state->window, dictionary + dictLength - state->wsize,
  78933. state->wsize);
  78934. state->whave = state->wsize;
  78935. }
  78936. else {
  78937. zmemcpy(state->window + state->wsize - dictLength, dictionary,
  78938. dictLength);
  78939. state->whave = dictLength;
  78940. }
  78941. state->havedict = 1;
  78942. Tracev((stderr, "inflate: dictionary set\n"));
  78943. return Z_OK;
  78944. }
  78945. int ZEXPORT inflateGetHeader (z_streamp strm, gz_headerp head)
  78946. {
  78947. struct inflate_state FAR *state;
  78948. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78949. state = (struct inflate_state FAR *)strm->state;
  78950. if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
  78951. state->head = head;
  78952. head->done = 0;
  78953. return Z_OK;
  78954. }
  78955. local unsigned syncsearch (unsigned FAR *have, unsigned char FAR *buf, unsigned len)
  78956. {
  78957. unsigned got;
  78958. unsigned next;
  78959. got = *have;
  78960. next = 0;
  78961. while (next < len && got < 4) {
  78962. if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
  78963. got++;
  78964. else if (buf[next])
  78965. got = 0;
  78966. else
  78967. got = 4 - got;
  78968. next++;
  78969. }
  78970. *have = got;
  78971. return next;
  78972. }
  78973. int ZEXPORT inflateSync (z_streamp strm)
  78974. {
  78975. unsigned len; /* number of bytes to look at or looked at */
  78976. unsigned long in, out; /* temporary to save total_in and total_out */
  78977. unsigned char buf[4]; /* to restore bit buffer to byte string */
  78978. struct inflate_state FAR *state;
  78979. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78980. state = (struct inflate_state FAR *)strm->state;
  78981. if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
  78982. if (state->mode != SYNC) {
  78983. state->mode = SYNC;
  78984. state->hold <<= state->bits & 7;
  78985. state->bits -= state->bits & 7;
  78986. len = 0;
  78987. while (state->bits >= 8) {
  78988. buf[len++] = (unsigned char)(state->hold);
  78989. state->hold >>= 8;
  78990. state->bits -= 8;
  78991. }
  78992. state->have = 0;
  78993. syncsearch(&(state->have), buf, len);
  78994. }
  78995. len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
  78996. strm->avail_in -= len;
  78997. strm->next_in += len;
  78998. strm->total_in += len;
  78999. if (state->have != 4) return Z_DATA_ERROR;
  79000. in = strm->total_in; out = strm->total_out;
  79001. inflateReset(strm);
  79002. strm->total_in = in; strm->total_out = out;
  79003. state->mode = TYPE;
  79004. return Z_OK;
  79005. }
  79006. int ZEXPORT inflateSyncPoint (z_streamp strm)
  79007. {
  79008. struct inflate_state FAR *state;
  79009. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79010. state = (struct inflate_state FAR *)strm->state;
  79011. return state->mode == STORED && state->bits == 0;
  79012. }
  79013. int ZEXPORT inflateCopy(z_streamp dest, z_streamp source)
  79014. {
  79015. struct inflate_state FAR *state;
  79016. struct inflate_state FAR *copy;
  79017. unsigned char FAR *window;
  79018. unsigned wsize;
  79019. if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
  79020. source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
  79021. return Z_STREAM_ERROR;
  79022. state = (struct inflate_state FAR *)source->state;
  79023. copy = (struct inflate_state FAR *)
  79024. ZALLOC(source, 1, sizeof(struct inflate_state));
  79025. if (copy == Z_NULL) return Z_MEM_ERROR;
  79026. window = Z_NULL;
  79027. if (state->window != Z_NULL) {
  79028. window = (unsigned char FAR *)
  79029. ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
  79030. if (window == Z_NULL) {
  79031. ZFREE(source, copy);
  79032. return Z_MEM_ERROR;
  79033. }
  79034. }
  79035. zmemcpy(dest, source, sizeof(z_stream));
  79036. zmemcpy(copy, state, sizeof(struct inflate_state));
  79037. if (state->lencode >= state->codes &&
  79038. state->lencode <= state->codes + ENOUGH - 1) {
  79039. copy->lencode = copy->codes + (state->lencode - state->codes);
  79040. copy->distcode = copy->codes + (state->distcode - state->codes);
  79041. }
  79042. copy->next = copy->codes + (state->next - state->codes);
  79043. if (window != Z_NULL) {
  79044. wsize = 1U << state->wbits;
  79045. zmemcpy(window, state->window, wsize);
  79046. }
  79047. copy->window = window;
  79048. dest->state = (struct internal_state FAR *)copy;
  79049. return Z_OK;
  79050. }
  79051. /*** End of inlined file: inflate.c ***/
  79052. /*** Start of inlined file: inftrees.c ***/
  79053. #define MAXBITS 15
  79054. const char inflate_copyright[] =
  79055. " inflate 1.2.3 Copyright 1995-2005 Mark Adler ";
  79056. int inflate_table (codetype type,
  79057. unsigned short FAR *lens,
  79058. unsigned codes,
  79059. code FAR * FAR *table,
  79060. unsigned FAR *bits,
  79061. unsigned short FAR *work)
  79062. {
  79063. unsigned len; /* a code's length in bits */
  79064. unsigned sym; /* index of code symbols */
  79065. unsigned min, max; /* minimum and maximum code lengths */
  79066. unsigned root; /* number of index bits for root table */
  79067. unsigned curr; /* number of index bits for current table */
  79068. unsigned drop; /* code bits to drop for sub-table */
  79069. int left; /* number of prefix codes available */
  79070. unsigned used; /* code entries in table used */
  79071. unsigned huff; /* Huffman code */
  79072. unsigned incr; /* for incrementing code, index */
  79073. unsigned fill; /* index for replicating entries */
  79074. unsigned low; /* low bits for current root entry */
  79075. unsigned mask; /* mask for low root bits */
  79076. code thisx; /* table entry for duplication */
  79077. code FAR *next; /* next available space in table */
  79078. const unsigned short FAR *base; /* base value table to use */
  79079. const unsigned short FAR *extra; /* extra bits table to use */
  79080. int end; /* use base and extra for symbol > end */
  79081. unsigned short count[MAXBITS+1]; /* number of codes of each length */
  79082. unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
  79083. static const unsigned short lbase[31] = { /* Length codes 257..285 base */
  79084. 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
  79085. 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
  79086. static const unsigned short lext[31] = { /* Length codes 257..285 extra */
  79087. 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
  79088. 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196};
  79089. static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
  79090. 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
  79091. 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
  79092. 8193, 12289, 16385, 24577, 0, 0};
  79093. static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
  79094. 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
  79095. 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
  79096. 28, 28, 29, 29, 64, 64};
  79097. for (len = 0; len <= MAXBITS; len++)
  79098. count[len] = 0;
  79099. for (sym = 0; sym < codes; sym++)
  79100. count[lens[sym]]++;
  79101. root = *bits;
  79102. for (max = MAXBITS; max >= 1; max--)
  79103. if (count[max] != 0) break;
  79104. if (root > max) root = max;
  79105. if (max == 0) { /* no symbols to code at all */
  79106. thisx.op = (unsigned char)64; /* invalid code marker */
  79107. thisx.bits = (unsigned char)1;
  79108. thisx.val = (unsigned short)0;
  79109. *(*table)++ = thisx; /* make a table to force an error */
  79110. *(*table)++ = thisx;
  79111. *bits = 1;
  79112. return 0; /* no symbols, but wait for decoding to report error */
  79113. }
  79114. for (min = 1; min <= MAXBITS; min++)
  79115. if (count[min] != 0) break;
  79116. if (root < min) root = min;
  79117. left = 1;
  79118. for (len = 1; len <= MAXBITS; len++) {
  79119. left <<= 1;
  79120. left -= count[len];
  79121. if (left < 0) return -1; /* over-subscribed */
  79122. }
  79123. if (left > 0 && (type == CODES || max != 1))
  79124. return -1; /* incomplete set */
  79125. offs[1] = 0;
  79126. for (len = 1; len < MAXBITS; len++)
  79127. offs[len + 1] = offs[len] + count[len];
  79128. for (sym = 0; sym < codes; sym++)
  79129. if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
  79130. switch (type) {
  79131. case CODES:
  79132. base = extra = work; /* dummy value--not used */
  79133. end = 19;
  79134. break;
  79135. case LENS:
  79136. base = lbase;
  79137. base -= 257;
  79138. extra = lext;
  79139. extra -= 257;
  79140. end = 256;
  79141. break;
  79142. default: /* DISTS */
  79143. base = dbase;
  79144. extra = dext;
  79145. end = -1;
  79146. }
  79147. huff = 0; /* starting code */
  79148. sym = 0; /* starting code symbol */
  79149. len = min; /* starting code length */
  79150. next = *table; /* current table to fill in */
  79151. curr = root; /* current table index bits */
  79152. drop = 0; /* current bits to drop from code for index */
  79153. low = (unsigned)(-1); /* trigger new sub-table when len > root */
  79154. used = 1U << root; /* use root table entries */
  79155. mask = used - 1; /* mask for comparing low */
  79156. if (type == LENS && used >= ENOUGH - MAXD)
  79157. return 1;
  79158. for (;;) {
  79159. thisx.bits = (unsigned char)(len - drop);
  79160. if ((int)(work[sym]) < end) {
  79161. thisx.op = (unsigned char)0;
  79162. thisx.val = work[sym];
  79163. }
  79164. else if ((int)(work[sym]) > end) {
  79165. thisx.op = (unsigned char)(extra[work[sym]]);
  79166. thisx.val = base[work[sym]];
  79167. }
  79168. else {
  79169. thisx.op = (unsigned char)(32 + 64); /* end of block */
  79170. thisx.val = 0;
  79171. }
  79172. incr = 1U << (len - drop);
  79173. fill = 1U << curr;
  79174. min = fill; /* save offset to next table */
  79175. do {
  79176. fill -= incr;
  79177. next[(huff >> drop) + fill] = thisx;
  79178. } while (fill != 0);
  79179. incr = 1U << (len - 1);
  79180. while (huff & incr)
  79181. incr >>= 1;
  79182. if (incr != 0) {
  79183. huff &= incr - 1;
  79184. huff += incr;
  79185. }
  79186. else
  79187. huff = 0;
  79188. sym++;
  79189. if (--(count[len]) == 0) {
  79190. if (len == max) break;
  79191. len = lens[work[sym]];
  79192. }
  79193. if (len > root && (huff & mask) != low) {
  79194. if (drop == 0)
  79195. drop = root;
  79196. next += min; /* here min is 1 << curr */
  79197. curr = len - drop;
  79198. left = (int)(1 << curr);
  79199. while (curr + drop < max) {
  79200. left -= count[curr + drop];
  79201. if (left <= 0) break;
  79202. curr++;
  79203. left <<= 1;
  79204. }
  79205. used += 1U << curr;
  79206. if (type == LENS && used >= ENOUGH - MAXD)
  79207. return 1;
  79208. low = huff & mask;
  79209. (*table)[low].op = (unsigned char)curr;
  79210. (*table)[low].bits = (unsigned char)root;
  79211. (*table)[low].val = (unsigned short)(next - *table);
  79212. }
  79213. }
  79214. thisx.op = (unsigned char)64; /* invalid code marker */
  79215. thisx.bits = (unsigned char)(len - drop);
  79216. thisx.val = (unsigned short)0;
  79217. while (huff != 0) {
  79218. if (drop != 0 && (huff & mask) != low) {
  79219. drop = 0;
  79220. len = root;
  79221. next = *table;
  79222. thisx.bits = (unsigned char)len;
  79223. }
  79224. next[huff >> drop] = thisx;
  79225. incr = 1U << (len - 1);
  79226. while (huff & incr)
  79227. incr >>= 1;
  79228. if (incr != 0) {
  79229. huff &= incr - 1;
  79230. huff += incr;
  79231. }
  79232. else
  79233. huff = 0;
  79234. }
  79235. *table += used;
  79236. *bits = root;
  79237. return 0;
  79238. }
  79239. /*** End of inlined file: inftrees.c ***/
  79240. /*** Start of inlined file: trees.c ***/
  79241. #ifdef DEBUG
  79242. # include <ctype.h>
  79243. #endif
  79244. #define MAX_BL_BITS 7
  79245. #define END_BLOCK 256
  79246. #define REP_3_6 16
  79247. #define REPZ_3_10 17
  79248. #define REPZ_11_138 18
  79249. local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
  79250. = {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};
  79251. local const int extra_dbits[D_CODES] /* extra bits for each distance code */
  79252. = {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};
  79253. local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
  79254. = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
  79255. local const uch bl_order[BL_CODES]
  79256. = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
  79257. #define Buf_size (8 * 2*sizeof(char))
  79258. #define DIST_CODE_LEN 512 /* see definition of array dist_code below */
  79259. #if defined(GEN_TREES_H) || !defined(STDC)
  79260. local ct_data static_ltree[L_CODES+2];
  79261. local ct_data static_dtree[D_CODES];
  79262. uch _dist_code[DIST_CODE_LEN];
  79263. uch _length_code[MAX_MATCH-MIN_MATCH+1];
  79264. local int base_length[LENGTH_CODES];
  79265. local int base_dist[D_CODES];
  79266. #else
  79267. /*** Start of inlined file: trees.h ***/
  79268. local const ct_data static_ltree[L_CODES+2] = {
  79269. {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
  79270. {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
  79271. {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}},
  79272. {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}},
  79273. {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}},
  79274. {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}},
  79275. {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}},
  79276. {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}},
  79277. {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}},
  79278. {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}},
  79279. {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}},
  79280. {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}},
  79281. {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}},
  79282. {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}},
  79283. {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}},
  79284. {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}},
  79285. {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}},
  79286. {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}},
  79287. {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}},
  79288. {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}},
  79289. {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}},
  79290. {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}},
  79291. {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}},
  79292. {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}},
  79293. {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}},
  79294. {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}},
  79295. {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}},
  79296. {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}},
  79297. {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}},
  79298. {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}},
  79299. {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}},
  79300. {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}},
  79301. {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}},
  79302. {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}},
  79303. {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}},
  79304. {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}},
  79305. {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}},
  79306. {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}},
  79307. {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}},
  79308. {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}},
  79309. {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}},
  79310. {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}},
  79311. {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}},
  79312. {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}},
  79313. {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}},
  79314. {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}},
  79315. {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}},
  79316. {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}},
  79317. {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}},
  79318. {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}},
  79319. {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}},
  79320. {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}},
  79321. {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}},
  79322. {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}},
  79323. {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}},
  79324. {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}},
  79325. {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
  79326. {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
  79327. };
  79328. local const ct_data static_dtree[D_CODES] = {
  79329. {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
  79330. {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
  79331. {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
  79332. {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
  79333. {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
  79334. {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
  79335. };
  79336. const uch _dist_code[DIST_CODE_LEN] = {
  79337. 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
  79338. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
  79339. 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
  79340. 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  79341. 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
  79342. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  79343. 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79344. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79345. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79346. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
  79347. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79348. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79349. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
  79350. 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
  79351. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79352. 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79353. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79354. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
  79355. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79356. 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79357. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79358. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79359. 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79360. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79361. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79362. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
  79363. };
  79364. const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
  79365. 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
  79366. 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
  79367. 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
  79368. 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  79369. 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
  79370. 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
  79371. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79372. 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79373. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79374. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
  79375. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79376. 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79377. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
  79378. };
  79379. local const int base_length[LENGTH_CODES] = {
  79380. 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
  79381. 64, 80, 96, 112, 128, 160, 192, 224, 0
  79382. };
  79383. local const int base_dist[D_CODES] = {
  79384. 0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
  79385. 32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
  79386. 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
  79387. };
  79388. /*** End of inlined file: trees.h ***/
  79389. #endif /* GEN_TREES_H */
  79390. struct static_tree_desc_s {
  79391. const ct_data *static_tree; /* static tree or NULL */
  79392. const intf *extra_bits; /* extra bits for each code or NULL */
  79393. int extra_base; /* base index for extra_bits */
  79394. int elems; /* max number of elements in the tree */
  79395. int max_length; /* max bit length for the codes */
  79396. };
  79397. local static_tree_desc static_l_desc =
  79398. {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
  79399. local static_tree_desc static_d_desc =
  79400. {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
  79401. local static_tree_desc static_bl_desc =
  79402. {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
  79403. local void tr_static_init OF((void));
  79404. local void init_block OF((deflate_state *s));
  79405. local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
  79406. local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
  79407. local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
  79408. local void build_tree OF((deflate_state *s, tree_desc *desc));
  79409. local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79410. local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79411. local int build_bl_tree OF((deflate_state *s));
  79412. local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
  79413. int blcodes));
  79414. local void compress_block OF((deflate_state *s, ct_data *ltree,
  79415. ct_data *dtree));
  79416. local void set_data_type OF((deflate_state *s));
  79417. local unsigned bi_reverse OF((unsigned value, int length));
  79418. local void bi_windup OF((deflate_state *s));
  79419. local void bi_flush OF((deflate_state *s));
  79420. local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
  79421. int header));
  79422. #ifdef GEN_TREES_H
  79423. local void gen_trees_header OF((void));
  79424. #endif
  79425. #ifndef DEBUG
  79426. # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
  79427. #else /* DEBUG */
  79428. # define send_code(s, c, tree) \
  79429. { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
  79430. send_bits(s, tree[c].Code, tree[c].Len); }
  79431. #endif
  79432. #define put_short(s, w) { \
  79433. put_byte(s, (uch)((w) & 0xff)); \
  79434. put_byte(s, (uch)((ush)(w) >> 8)); \
  79435. }
  79436. #ifdef DEBUG
  79437. local void send_bits OF((deflate_state *s, int value, int length));
  79438. local void send_bits (deflate_state *s, int value, int length)
  79439. {
  79440. Tracevv((stderr," l %2d v %4x ", length, value));
  79441. Assert(length > 0 && length <= 15, "invalid length");
  79442. s->bits_sent += (ulg)length;
  79443. if (s->bi_valid > (int)Buf_size - length) {
  79444. s->bi_buf |= (value << s->bi_valid);
  79445. put_short(s, s->bi_buf);
  79446. s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
  79447. s->bi_valid += length - Buf_size;
  79448. } else {
  79449. s->bi_buf |= value << s->bi_valid;
  79450. s->bi_valid += length;
  79451. }
  79452. }
  79453. #else /* !DEBUG */
  79454. #define send_bits(s, value, length) \
  79455. { int len = length;\
  79456. if (s->bi_valid > (int)Buf_size - len) {\
  79457. int val = value;\
  79458. s->bi_buf |= (val << s->bi_valid);\
  79459. put_short(s, s->bi_buf);\
  79460. s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
  79461. s->bi_valid += len - Buf_size;\
  79462. } else {\
  79463. s->bi_buf |= (value) << s->bi_valid;\
  79464. s->bi_valid += len;\
  79465. }\
  79466. }
  79467. #endif /* DEBUG */
  79468. local void tr_static_init()
  79469. {
  79470. #if defined(GEN_TREES_H) || !defined(STDC)
  79471. static int static_init_done = 0;
  79472. int n; /* iterates over tree elements */
  79473. int bits; /* bit counter */
  79474. int length; /* length value */
  79475. int code; /* code value */
  79476. int dist; /* distance index */
  79477. ush bl_count[MAX_BITS+1];
  79478. if (static_init_done) return;
  79479. static_l_desc.static_tree = static_ltree;
  79480. static_l_desc.extra_bits = extra_lbits;
  79481. static_d_desc.static_tree = static_dtree;
  79482. static_d_desc.extra_bits = extra_dbits;
  79483. static_bl_desc.extra_bits = extra_blbits;
  79484. length = 0;
  79485. for (code = 0; code < LENGTH_CODES-1; code++) {
  79486. base_length[code] = length;
  79487. for (n = 0; n < (1<<extra_lbits[code]); n++) {
  79488. _length_code[length++] = (uch)code;
  79489. }
  79490. }
  79491. Assert (length == 256, "tr_static_init: length != 256");
  79492. _length_code[length-1] = (uch)code;
  79493. dist = 0;
  79494. for (code = 0 ; code < 16; code++) {
  79495. base_dist[code] = dist;
  79496. for (n = 0; n < (1<<extra_dbits[code]); n++) {
  79497. _dist_code[dist++] = (uch)code;
  79498. }
  79499. }
  79500. Assert (dist == 256, "tr_static_init: dist != 256");
  79501. dist >>= 7; /* from now on, all distances are divided by 128 */
  79502. for ( ; code < D_CODES; code++) {
  79503. base_dist[code] = dist << 7;
  79504. for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
  79505. _dist_code[256 + dist++] = (uch)code;
  79506. }
  79507. }
  79508. Assert (dist == 256, "tr_static_init: 256+dist != 512");
  79509. for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
  79510. n = 0;
  79511. while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
  79512. while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
  79513. while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
  79514. while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
  79515. gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
  79516. for (n = 0; n < D_CODES; n++) {
  79517. static_dtree[n].Len = 5;
  79518. static_dtree[n].Code = bi_reverse((unsigned)n, 5);
  79519. }
  79520. static_init_done = 1;
  79521. # ifdef GEN_TREES_H
  79522. gen_trees_header();
  79523. # endif
  79524. #endif /* defined(GEN_TREES_H) || !defined(STDC) */
  79525. }
  79526. #ifdef GEN_TREES_H
  79527. # ifndef DEBUG
  79528. # include <stdio.h>
  79529. # endif
  79530. # define SEPARATOR(i, last, width) \
  79531. ((i) == (last)? "\n};\n\n" : \
  79532. ((i) % (width) == (width)-1 ? ",\n" : ", "))
  79533. void gen_trees_header()
  79534. {
  79535. FILE *header = fopen("trees.h", "w");
  79536. int i;
  79537. Assert (header != NULL, "Can't open trees.h");
  79538. fprintf(header,
  79539. "/* header created automatically with -DGEN_TREES_H */\n\n");
  79540. fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
  79541. for (i = 0; i < L_CODES+2; i++) {
  79542. fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
  79543. static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
  79544. }
  79545. fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
  79546. for (i = 0; i < D_CODES; i++) {
  79547. fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
  79548. static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
  79549. }
  79550. fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n");
  79551. for (i = 0; i < DIST_CODE_LEN; i++) {
  79552. fprintf(header, "%2u%s", _dist_code[i],
  79553. SEPARATOR(i, DIST_CODE_LEN-1, 20));
  79554. }
  79555. fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
  79556. for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
  79557. fprintf(header, "%2u%s", _length_code[i],
  79558. SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
  79559. }
  79560. fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
  79561. for (i = 0; i < LENGTH_CODES; i++) {
  79562. fprintf(header, "%1u%s", base_length[i],
  79563. SEPARATOR(i, LENGTH_CODES-1, 20));
  79564. }
  79565. fprintf(header, "local const int base_dist[D_CODES] = {\n");
  79566. for (i = 0; i < D_CODES; i++) {
  79567. fprintf(header, "%5u%s", base_dist[i],
  79568. SEPARATOR(i, D_CODES-1, 10));
  79569. }
  79570. fclose(header);
  79571. }
  79572. #endif /* GEN_TREES_H */
  79573. void _tr_init(deflate_state *s)
  79574. {
  79575. tr_static_init();
  79576. s->l_desc.dyn_tree = s->dyn_ltree;
  79577. s->l_desc.stat_desc = &static_l_desc;
  79578. s->d_desc.dyn_tree = s->dyn_dtree;
  79579. s->d_desc.stat_desc = &static_d_desc;
  79580. s->bl_desc.dyn_tree = s->bl_tree;
  79581. s->bl_desc.stat_desc = &static_bl_desc;
  79582. s->bi_buf = 0;
  79583. s->bi_valid = 0;
  79584. s->last_eob_len = 8; /* enough lookahead for inflate */
  79585. #ifdef DEBUG
  79586. s->compressed_len = 0L;
  79587. s->bits_sent = 0L;
  79588. #endif
  79589. init_block(s);
  79590. }
  79591. local void init_block (deflate_state *s)
  79592. {
  79593. int n; /* iterates over tree elements */
  79594. for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
  79595. for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
  79596. for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
  79597. s->dyn_ltree[END_BLOCK].Freq = 1;
  79598. s->opt_len = s->static_len = 0L;
  79599. s->last_lit = s->matches = 0;
  79600. }
  79601. #define SMALLEST 1
  79602. #define pqremove(s, tree, top) \
  79603. {\
  79604. top = s->heap[SMALLEST]; \
  79605. s->heap[SMALLEST] = s->heap[s->heap_len--]; \
  79606. pqdownheap(s, tree, SMALLEST); \
  79607. }
  79608. #define smaller(tree, n, m, depth) \
  79609. (tree[n].Freq < tree[m].Freq || \
  79610. (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
  79611. local void pqdownheap (deflate_state *s,
  79612. ct_data *tree, /* the tree to restore */
  79613. int k) /* node to move down */
  79614. {
  79615. int v = s->heap[k];
  79616. int j = k << 1; /* left son of k */
  79617. while (j <= s->heap_len) {
  79618. if (j < s->heap_len &&
  79619. smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
  79620. j++;
  79621. }
  79622. if (smaller(tree, v, s->heap[j], s->depth)) break;
  79623. s->heap[k] = s->heap[j]; k = j;
  79624. j <<= 1;
  79625. }
  79626. s->heap[k] = v;
  79627. }
  79628. local void gen_bitlen (deflate_state *s, tree_desc *desc)
  79629. {
  79630. ct_data *tree = desc->dyn_tree;
  79631. int max_code = desc->max_code;
  79632. const ct_data *stree = desc->stat_desc->static_tree;
  79633. const intf *extra = desc->stat_desc->extra_bits;
  79634. int base = desc->stat_desc->extra_base;
  79635. int max_length = desc->stat_desc->max_length;
  79636. int h; /* heap index */
  79637. int n, m; /* iterate over the tree elements */
  79638. int bits; /* bit length */
  79639. int xbits; /* extra bits */
  79640. ush f; /* frequency */
  79641. int overflow = 0; /* number of elements with bit length too large */
  79642. for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
  79643. tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
  79644. for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
  79645. n = s->heap[h];
  79646. bits = tree[tree[n].Dad].Len + 1;
  79647. if (bits > max_length) bits = max_length, overflow++;
  79648. tree[n].Len = (ush)bits;
  79649. if (n > max_code) continue; /* not a leaf node */
  79650. s->bl_count[bits]++;
  79651. xbits = 0;
  79652. if (n >= base) xbits = extra[n-base];
  79653. f = tree[n].Freq;
  79654. s->opt_len += (ulg)f * (bits + xbits);
  79655. if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
  79656. }
  79657. if (overflow == 0) return;
  79658. Trace((stderr,"\nbit length overflow\n"));
  79659. do {
  79660. bits = max_length-1;
  79661. while (s->bl_count[bits] == 0) bits--;
  79662. s->bl_count[bits]--; /* move one leaf down the tree */
  79663. s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
  79664. s->bl_count[max_length]--;
  79665. overflow -= 2;
  79666. } while (overflow > 0);
  79667. for (bits = max_length; bits != 0; bits--) {
  79668. n = s->bl_count[bits];
  79669. while (n != 0) {
  79670. m = s->heap[--h];
  79671. if (m > max_code) continue;
  79672. if ((unsigned) tree[m].Len != (unsigned) bits) {
  79673. Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
  79674. s->opt_len += ((long)bits - (long)tree[m].Len)
  79675. *(long)tree[m].Freq;
  79676. tree[m].Len = (ush)bits;
  79677. }
  79678. n--;
  79679. }
  79680. }
  79681. }
  79682. local void gen_codes (ct_data *tree, /* the tree to decorate */
  79683. int max_code, /* largest code with non zero frequency */
  79684. ushf *bl_count) /* number of codes at each bit length */
  79685. {
  79686. ush next_code[MAX_BITS+1]; /* next code value for each bit length */
  79687. ush code = 0; /* running code value */
  79688. int bits; /* bit index */
  79689. int n; /* code index */
  79690. for (bits = 1; bits <= MAX_BITS; bits++) {
  79691. next_code[bits] = code = (code + bl_count[bits-1]) << 1;
  79692. }
  79693. Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
  79694. "inconsistent bit counts");
  79695. Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
  79696. for (n = 0; n <= max_code; n++) {
  79697. int len = tree[n].Len;
  79698. if (len == 0) continue;
  79699. tree[n].Code = bi_reverse(next_code[len]++, len);
  79700. Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
  79701. n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
  79702. }
  79703. }
  79704. local void build_tree (deflate_state *s,
  79705. tree_desc *desc) /* the tree descriptor */
  79706. {
  79707. ct_data *tree = desc->dyn_tree;
  79708. const ct_data *stree = desc->stat_desc->static_tree;
  79709. int elems = desc->stat_desc->elems;
  79710. int n, m; /* iterate over heap elements */
  79711. int max_code = -1; /* largest code with non zero frequency */
  79712. int node; /* new node being created */
  79713. s->heap_len = 0, s->heap_max = HEAP_SIZE;
  79714. for (n = 0; n < elems; n++) {
  79715. if (tree[n].Freq != 0) {
  79716. s->heap[++(s->heap_len)] = max_code = n;
  79717. s->depth[n] = 0;
  79718. } else {
  79719. tree[n].Len = 0;
  79720. }
  79721. }
  79722. while (s->heap_len < 2) {
  79723. node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
  79724. tree[node].Freq = 1;
  79725. s->depth[node] = 0;
  79726. s->opt_len--; if (stree) s->static_len -= stree[node].Len;
  79727. }
  79728. desc->max_code = max_code;
  79729. for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
  79730. node = elems; /* next internal node of the tree */
  79731. do {
  79732. pqremove(s, tree, n); /* n = node of least frequency */
  79733. m = s->heap[SMALLEST]; /* m = node of next least frequency */
  79734. s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
  79735. s->heap[--(s->heap_max)] = m;
  79736. tree[node].Freq = tree[n].Freq + tree[m].Freq;
  79737. s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
  79738. s->depth[n] : s->depth[m]) + 1);
  79739. tree[n].Dad = tree[m].Dad = (ush)node;
  79740. #ifdef DUMP_BL_TREE
  79741. if (tree == s->bl_tree) {
  79742. fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
  79743. node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
  79744. }
  79745. #endif
  79746. s->heap[SMALLEST] = node++;
  79747. pqdownheap(s, tree, SMALLEST);
  79748. } while (s->heap_len >= 2);
  79749. s->heap[--(s->heap_max)] = s->heap[SMALLEST];
  79750. gen_bitlen(s, (tree_desc *)desc);
  79751. gen_codes ((ct_data *)tree, max_code, s->bl_count);
  79752. }
  79753. local void scan_tree (deflate_state *s,
  79754. ct_data *tree, /* the tree to be scanned */
  79755. int max_code) /* and its largest code of non zero frequency */
  79756. {
  79757. int n; /* iterates over all tree elements */
  79758. int prevlen = -1; /* last emitted length */
  79759. int curlen; /* length of current code */
  79760. int nextlen = tree[0].Len; /* length of next code */
  79761. int count = 0; /* repeat count of the current code */
  79762. int max_count = 7; /* max repeat count */
  79763. int min_count = 4; /* min repeat count */
  79764. if (nextlen == 0) max_count = 138, min_count = 3;
  79765. tree[max_code+1].Len = (ush)0xffff; /* guard */
  79766. for (n = 0; n <= max_code; n++) {
  79767. curlen = nextlen; nextlen = tree[n+1].Len;
  79768. if (++count < max_count && curlen == nextlen) {
  79769. continue;
  79770. } else if (count < min_count) {
  79771. s->bl_tree[curlen].Freq += count;
  79772. } else if (curlen != 0) {
  79773. if (curlen != prevlen) s->bl_tree[curlen].Freq++;
  79774. s->bl_tree[REP_3_6].Freq++;
  79775. } else if (count <= 10) {
  79776. s->bl_tree[REPZ_3_10].Freq++;
  79777. } else {
  79778. s->bl_tree[REPZ_11_138].Freq++;
  79779. }
  79780. count = 0; prevlen = curlen;
  79781. if (nextlen == 0) {
  79782. max_count = 138, min_count = 3;
  79783. } else if (curlen == nextlen) {
  79784. max_count = 6, min_count = 3;
  79785. } else {
  79786. max_count = 7, min_count = 4;
  79787. }
  79788. }
  79789. }
  79790. local void send_tree (deflate_state *s,
  79791. ct_data *tree, /* the tree to be scanned */
  79792. int max_code) /* and its largest code of non zero frequency */
  79793. {
  79794. int n; /* iterates over all tree elements */
  79795. int prevlen = -1; /* last emitted length */
  79796. int curlen; /* length of current code */
  79797. int nextlen = tree[0].Len; /* length of next code */
  79798. int count = 0; /* repeat count of the current code */
  79799. int max_count = 7; /* max repeat count */
  79800. int min_count = 4; /* min repeat count */
  79801. /* guard already set */
  79802. if (nextlen == 0) max_count = 138, min_count = 3;
  79803. for (n = 0; n <= max_code; n++) {
  79804. curlen = nextlen; nextlen = tree[n+1].Len;
  79805. if (++count < max_count && curlen == nextlen) {
  79806. continue;
  79807. } else if (count < min_count) {
  79808. do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
  79809. } else if (curlen != 0) {
  79810. if (curlen != prevlen) {
  79811. send_code(s, curlen, s->bl_tree); count--;
  79812. }
  79813. Assert(count >= 3 && count <= 6, " 3_6?");
  79814. send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
  79815. } else if (count <= 10) {
  79816. send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
  79817. } else {
  79818. send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
  79819. }
  79820. count = 0; prevlen = curlen;
  79821. if (nextlen == 0) {
  79822. max_count = 138, min_count = 3;
  79823. } else if (curlen == nextlen) {
  79824. max_count = 6, min_count = 3;
  79825. } else {
  79826. max_count = 7, min_count = 4;
  79827. }
  79828. }
  79829. }
  79830. local int build_bl_tree (deflate_state *s)
  79831. {
  79832. int max_blindex; /* index of last bit length code of non zero freq */
  79833. scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
  79834. scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
  79835. build_tree(s, (tree_desc *)(&(s->bl_desc)));
  79836. for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
  79837. if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
  79838. }
  79839. s->opt_len += 3*(max_blindex+1) + 5+5+4;
  79840. Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
  79841. s->opt_len, s->static_len));
  79842. return max_blindex;
  79843. }
  79844. local void send_all_trees (deflate_state *s,
  79845. int lcodes, int dcodes, int blcodes) /* number of codes for each tree */
  79846. {
  79847. int rank; /* index in bl_order */
  79848. Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
  79849. Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
  79850. "too many codes");
  79851. Tracev((stderr, "\nbl counts: "));
  79852. send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
  79853. send_bits(s, dcodes-1, 5);
  79854. send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */
  79855. for (rank = 0; rank < blcodes; rank++) {
  79856. Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
  79857. send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
  79858. }
  79859. Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
  79860. send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
  79861. Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
  79862. send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
  79863. Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
  79864. }
  79865. void _tr_stored_block (deflate_state *s, charf *buf, ulg stored_len, int eof)
  79866. {
  79867. send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
  79868. #ifdef DEBUG
  79869. s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
  79870. s->compressed_len += (stored_len + 4) << 3;
  79871. #endif
  79872. copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
  79873. }
  79874. void _tr_align (deflate_state *s)
  79875. {
  79876. send_bits(s, STATIC_TREES<<1, 3);
  79877. send_code(s, END_BLOCK, static_ltree);
  79878. #ifdef DEBUG
  79879. s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
  79880. #endif
  79881. bi_flush(s);
  79882. if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
  79883. send_bits(s, STATIC_TREES<<1, 3);
  79884. send_code(s, END_BLOCK, static_ltree);
  79885. #ifdef DEBUG
  79886. s->compressed_len += 10L;
  79887. #endif
  79888. bi_flush(s);
  79889. }
  79890. s->last_eob_len = 7;
  79891. }
  79892. void _tr_flush_block (deflate_state *s,
  79893. charf *buf, /* input block, or NULL if too old */
  79894. ulg stored_len, /* length of input block */
  79895. int eof) /* true if this is the last block for a file */
  79896. {
  79897. ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
  79898. int max_blindex = 0; /* index of last bit length code of non zero freq */
  79899. if (s->level > 0) {
  79900. if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN)
  79901. set_data_type(s);
  79902. build_tree(s, (tree_desc *)(&(s->l_desc)));
  79903. Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
  79904. s->static_len));
  79905. build_tree(s, (tree_desc *)(&(s->d_desc)));
  79906. Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
  79907. s->static_len));
  79908. max_blindex = build_bl_tree(s);
  79909. opt_lenb = (s->opt_len+3+7)>>3;
  79910. static_lenb = (s->static_len+3+7)>>3;
  79911. Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
  79912. opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
  79913. s->last_lit));
  79914. if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
  79915. } else {
  79916. Assert(buf != (char*)0, "lost buf");
  79917. opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
  79918. }
  79919. #ifdef FORCE_STORED
  79920. if (buf != (char*)0) { /* force stored block */
  79921. #else
  79922. if (stored_len+4 <= opt_lenb && buf != (char*)0) {
  79923. #endif
  79924. _tr_stored_block(s, buf, stored_len, eof);
  79925. #ifdef FORCE_STATIC
  79926. } else if (static_lenb >= 0) { /* force static trees */
  79927. #else
  79928. } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
  79929. #endif
  79930. send_bits(s, (STATIC_TREES<<1)+eof, 3);
  79931. compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
  79932. #ifdef DEBUG
  79933. s->compressed_len += 3 + s->static_len;
  79934. #endif
  79935. } else {
  79936. send_bits(s, (DYN_TREES<<1)+eof, 3);
  79937. send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
  79938. max_blindex+1);
  79939. compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
  79940. #ifdef DEBUG
  79941. s->compressed_len += 3 + s->opt_len;
  79942. #endif
  79943. }
  79944. Assert (s->compressed_len == s->bits_sent, "bad compressed size");
  79945. init_block(s);
  79946. if (eof) {
  79947. bi_windup(s);
  79948. #ifdef DEBUG
  79949. s->compressed_len += 7; /* align on byte boundary */
  79950. #endif
  79951. }
  79952. Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
  79953. s->compressed_len-7*eof));
  79954. }
  79955. int _tr_tally (deflate_state *s,
  79956. unsigned dist, /* distance of matched string */
  79957. unsigned lc) /* match length-MIN_MATCH or unmatched char (if dist==0) */
  79958. {
  79959. s->d_buf[s->last_lit] = (ush)dist;
  79960. s->l_buf[s->last_lit++] = (uch)lc;
  79961. if (dist == 0) {
  79962. s->dyn_ltree[lc].Freq++;
  79963. } else {
  79964. s->matches++;
  79965. dist--; /* dist = match distance - 1 */
  79966. Assert((ush)dist < (ush)MAX_DIST(s) &&
  79967. (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
  79968. (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
  79969. s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
  79970. s->dyn_dtree[d_code(dist)].Freq++;
  79971. }
  79972. #ifdef TRUNCATE_BLOCK
  79973. if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
  79974. ulg out_length = (ulg)s->last_lit*8L;
  79975. ulg in_length = (ulg)((long)s->strstart - s->block_start);
  79976. int dcode;
  79977. for (dcode = 0; dcode < D_CODES; dcode++) {
  79978. out_length += (ulg)s->dyn_dtree[dcode].Freq *
  79979. (5L+extra_dbits[dcode]);
  79980. }
  79981. out_length >>= 3;
  79982. Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
  79983. s->last_lit, in_length, out_length,
  79984. 100L - out_length*100L/in_length));
  79985. if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
  79986. }
  79987. #endif
  79988. return (s->last_lit == s->lit_bufsize-1);
  79989. }
  79990. local void compress_block (deflate_state *s,
  79991. ct_data *ltree, /* literal tree */
  79992. ct_data *dtree) /* distance tree */
  79993. {
  79994. unsigned dist; /* distance of matched string */
  79995. int lc; /* match length or unmatched char (if dist == 0) */
  79996. unsigned lx = 0; /* running index in l_buf */
  79997. unsigned code; /* the code to send */
  79998. int extra; /* number of extra bits to send */
  79999. if (s->last_lit != 0) do {
  80000. dist = s->d_buf[lx];
  80001. lc = s->l_buf[lx++];
  80002. if (dist == 0) {
  80003. send_code(s, lc, ltree); /* send a literal byte */
  80004. Tracecv(isgraph(lc), (stderr," '%c' ", lc));
  80005. } else {
  80006. code = _length_code[lc];
  80007. send_code(s, code+LITERALS+1, ltree); /* send the length code */
  80008. extra = extra_lbits[code];
  80009. if (extra != 0) {
  80010. lc -= base_length[code];
  80011. send_bits(s, lc, extra); /* send the extra length bits */
  80012. }
  80013. dist--; /* dist is now the match distance - 1 */
  80014. code = d_code(dist);
  80015. Assert (code < D_CODES, "bad d_code");
  80016. send_code(s, code, dtree); /* send the distance code */
  80017. extra = extra_dbits[code];
  80018. if (extra != 0) {
  80019. dist -= base_dist[code];
  80020. send_bits(s, dist, extra); /* send the extra distance bits */
  80021. }
  80022. } /* literal or match pair ? */
  80023. Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
  80024. "pendingBuf overflow");
  80025. } while (lx < s->last_lit);
  80026. send_code(s, END_BLOCK, ltree);
  80027. s->last_eob_len = ltree[END_BLOCK].Len;
  80028. }
  80029. local void set_data_type (deflate_state *s)
  80030. {
  80031. int n;
  80032. for (n = 0; n < 9; n++)
  80033. if (s->dyn_ltree[n].Freq != 0)
  80034. break;
  80035. if (n == 9)
  80036. for (n = 14; n < 32; n++)
  80037. if (s->dyn_ltree[n].Freq != 0)
  80038. break;
  80039. s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY;
  80040. }
  80041. local unsigned bi_reverse (unsigned code, int len)
  80042. {
  80043. register unsigned res = 0;
  80044. do {
  80045. res |= code & 1;
  80046. code >>= 1, res <<= 1;
  80047. } while (--len > 0);
  80048. return res >> 1;
  80049. }
  80050. local void bi_flush (deflate_state *s)
  80051. {
  80052. if (s->bi_valid == 16) {
  80053. put_short(s, s->bi_buf);
  80054. s->bi_buf = 0;
  80055. s->bi_valid = 0;
  80056. } else if (s->bi_valid >= 8) {
  80057. put_byte(s, (Byte)s->bi_buf);
  80058. s->bi_buf >>= 8;
  80059. s->bi_valid -= 8;
  80060. }
  80061. }
  80062. local void bi_windup (deflate_state *s)
  80063. {
  80064. if (s->bi_valid > 8) {
  80065. put_short(s, s->bi_buf);
  80066. } else if (s->bi_valid > 0) {
  80067. put_byte(s, (Byte)s->bi_buf);
  80068. }
  80069. s->bi_buf = 0;
  80070. s->bi_valid = 0;
  80071. #ifdef DEBUG
  80072. s->bits_sent = (s->bits_sent+7) & ~7;
  80073. #endif
  80074. }
  80075. local void copy_block(deflate_state *s,
  80076. charf *buf, /* the input data */
  80077. unsigned len, /* its length */
  80078. int header) /* true if block header must be written */
  80079. {
  80080. bi_windup(s); /* align on byte boundary */
  80081. s->last_eob_len = 8; /* enough lookahead for inflate */
  80082. if (header) {
  80083. put_short(s, (ush)len);
  80084. put_short(s, (ush)~len);
  80085. #ifdef DEBUG
  80086. s->bits_sent += 2*16;
  80087. #endif
  80088. }
  80089. #ifdef DEBUG
  80090. s->bits_sent += (ulg)len<<3;
  80091. #endif
  80092. while (len--) {
  80093. put_byte(s, *buf++);
  80094. }
  80095. }
  80096. /*** End of inlined file: trees.c ***/
  80097. /*** Start of inlined file: zutil.c ***/
  80098. #ifndef NO_DUMMY_DECL
  80099. struct internal_state {int dummy;}; /* for buggy compilers */
  80100. #endif
  80101. const char * const z_errmsg[10] = {
  80102. "need dictionary", /* Z_NEED_DICT 2 */
  80103. "stream end", /* Z_STREAM_END 1 */
  80104. "", /* Z_OK 0 */
  80105. "file error", /* Z_ERRNO (-1) */
  80106. "stream error", /* Z_STREAM_ERROR (-2) */
  80107. "data error", /* Z_DATA_ERROR (-3) */
  80108. "insufficient memory", /* Z_MEM_ERROR (-4) */
  80109. "buffer error", /* Z_BUF_ERROR (-5) */
  80110. "incompatible version",/* Z_VERSION_ERROR (-6) */
  80111. ""};
  80112. #ifdef DEBUG
  80113. # ifndef verbose
  80114. # define verbose 0
  80115. # endif
  80116. int z_verbose = verbose;
  80117. void z_error (const char *m)
  80118. {
  80119. fprintf(stderr, "%s\n", m);
  80120. exit(1);
  80121. }
  80122. #endif
  80123. const char * ZEXPORT zError(int err)
  80124. {
  80125. return ERR_MSG(err);
  80126. }
  80127. #if defined(_WIN32_WCE)
  80128. int errno = 0;
  80129. #endif
  80130. #ifndef HAVE_MEMCPY
  80131. void zmemcpy(dest, source, len)
  80132. Bytef* dest;
  80133. const Bytef* source;
  80134. uInt len;
  80135. {
  80136. if (len == 0) return;
  80137. do {
  80138. *dest++ = *source++; /* ??? to be unrolled */
  80139. } while (--len != 0);
  80140. }
  80141. int zmemcmp(s1, s2, len)
  80142. const Bytef* s1;
  80143. const Bytef* s2;
  80144. uInt len;
  80145. {
  80146. uInt j;
  80147. for (j = 0; j < len; j++) {
  80148. if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
  80149. }
  80150. return 0;
  80151. }
  80152. void zmemzero(dest, len)
  80153. Bytef* dest;
  80154. uInt len;
  80155. {
  80156. if (len == 0) return;
  80157. do {
  80158. *dest++ = 0; /* ??? to be unrolled */
  80159. } while (--len != 0);
  80160. }
  80161. #endif
  80162. #ifdef SYS16BIT
  80163. #ifdef __TURBOC__
  80164. # define MY_ZCALLOC
  80165. #define MAX_PTR 10
  80166. local int next_ptr = 0;
  80167. typedef struct ptr_table_s {
  80168. voidpf org_ptr;
  80169. voidpf new_ptr;
  80170. } ptr_table;
  80171. local ptr_table table[MAX_PTR];
  80172. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80173. {
  80174. voidpf buf = opaque; /* just to make some compilers happy */
  80175. ulg bsize = (ulg)items*size;
  80176. if (bsize < 65520L) {
  80177. buf = farmalloc(bsize);
  80178. if (*(ush*)&buf != 0) return buf;
  80179. } else {
  80180. buf = farmalloc(bsize + 16L);
  80181. }
  80182. if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
  80183. table[next_ptr].org_ptr = buf;
  80184. *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
  80185. *(ush*)&buf = 0;
  80186. table[next_ptr++].new_ptr = buf;
  80187. return buf;
  80188. }
  80189. void zcfree (voidpf opaque, voidpf ptr)
  80190. {
  80191. int n;
  80192. if (*(ush*)&ptr != 0) { /* object < 64K */
  80193. farfree(ptr);
  80194. return;
  80195. }
  80196. for (n = 0; n < next_ptr; n++) {
  80197. if (ptr != table[n].new_ptr) continue;
  80198. farfree(table[n].org_ptr);
  80199. while (++n < next_ptr) {
  80200. table[n-1] = table[n];
  80201. }
  80202. next_ptr--;
  80203. return;
  80204. }
  80205. ptr = opaque; /* just to make some compilers happy */
  80206. Assert(0, "zcfree: ptr not found");
  80207. }
  80208. #endif /* __TURBOC__ */
  80209. #ifdef M_I86
  80210. # define MY_ZCALLOC
  80211. #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
  80212. # define _halloc halloc
  80213. # define _hfree hfree
  80214. #endif
  80215. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80216. {
  80217. if (opaque) opaque = 0; /* to make compiler happy */
  80218. return _halloc((long)items, size);
  80219. }
  80220. void zcfree (voidpf opaque, voidpf ptr)
  80221. {
  80222. if (opaque) opaque = 0; /* to make compiler happy */
  80223. _hfree(ptr);
  80224. }
  80225. #endif /* M_I86 */
  80226. #endif /* SYS16BIT */
  80227. #ifndef MY_ZCALLOC /* Any system without a special alloc function */
  80228. #ifndef STDC
  80229. extern voidp malloc OF((uInt size));
  80230. extern voidp calloc OF((uInt items, uInt size));
  80231. extern void free OF((voidpf ptr));
  80232. #endif
  80233. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80234. {
  80235. if (opaque) items += size - size; /* make compiler happy */
  80236. return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
  80237. (voidpf)calloc(items, size);
  80238. }
  80239. void zcfree (voidpf opaque, voidpf ptr)
  80240. {
  80241. free(ptr);
  80242. if (opaque) return; /* make compiler happy */
  80243. }
  80244. #endif /* MY_ZCALLOC */
  80245. /*** End of inlined file: zutil.c ***/
  80246. #undef Byte
  80247. }
  80248. #else
  80249. #include <zlib.h>
  80250. #endif
  80251. }
  80252. #if JUCE_MSVC
  80253. #pragma warning (pop)
  80254. #endif
  80255. BEGIN_JUCE_NAMESPACE
  80256. // internal helper object that holds the zlib structures so they don't have to be
  80257. // included publicly.
  80258. class GZIPDecompressHelper
  80259. {
  80260. public:
  80261. GZIPDecompressHelper (const bool noWrap)
  80262. : finished (true),
  80263. needsDictionary (false),
  80264. error (true),
  80265. streamIsValid (false),
  80266. data (0),
  80267. dataSize (0)
  80268. {
  80269. using namespace zlibNamespace;
  80270. zerostruct (stream);
  80271. streamIsValid = (inflateInit2 (&stream, noWrap ? -MAX_WBITS : MAX_WBITS) == Z_OK);
  80272. finished = error = ! streamIsValid;
  80273. }
  80274. ~GZIPDecompressHelper()
  80275. {
  80276. using namespace zlibNamespace;
  80277. if (streamIsValid)
  80278. inflateEnd (&stream);
  80279. }
  80280. bool needsInput() const throw() { return dataSize <= 0; }
  80281. void setInput (uint8* const data_, const int size) throw()
  80282. {
  80283. data = data_;
  80284. dataSize = size;
  80285. }
  80286. int doNextBlock (uint8* const dest, const int destSize)
  80287. {
  80288. using namespace zlibNamespace;
  80289. if (streamIsValid && data != 0 && ! finished)
  80290. {
  80291. stream.next_in = data;
  80292. stream.next_out = dest;
  80293. stream.avail_in = dataSize;
  80294. stream.avail_out = destSize;
  80295. switch (inflate (&stream, Z_PARTIAL_FLUSH))
  80296. {
  80297. case Z_STREAM_END:
  80298. finished = true;
  80299. // deliberate fall-through
  80300. case Z_OK:
  80301. data += dataSize - stream.avail_in;
  80302. dataSize = stream.avail_in;
  80303. return destSize - stream.avail_out;
  80304. case Z_NEED_DICT:
  80305. needsDictionary = true;
  80306. data += dataSize - stream.avail_in;
  80307. dataSize = stream.avail_in;
  80308. break;
  80309. case Z_DATA_ERROR:
  80310. case Z_MEM_ERROR:
  80311. error = true;
  80312. default:
  80313. break;
  80314. }
  80315. }
  80316. return 0;
  80317. }
  80318. bool finished, needsDictionary, error, streamIsValid;
  80319. private:
  80320. zlibNamespace::z_stream stream;
  80321. uint8* data;
  80322. int dataSize;
  80323. GZIPDecompressHelper (const GZIPDecompressHelper&);
  80324. GZIPDecompressHelper& operator= (const GZIPDecompressHelper&);
  80325. };
  80326. const int gzipDecompBufferSize = 32768;
  80327. GZIPDecompressorInputStream::GZIPDecompressorInputStream (InputStream* const sourceStream_,
  80328. const bool deleteSourceWhenDestroyed,
  80329. const bool noWrap_,
  80330. const int64 uncompressedStreamLength_)
  80331. : sourceStream (sourceStream_),
  80332. streamToDelete (deleteSourceWhenDestroyed ? sourceStream_ : 0),
  80333. uncompressedStreamLength (uncompressedStreamLength_),
  80334. noWrap (noWrap_),
  80335. isEof (false),
  80336. activeBufferSize (0),
  80337. originalSourcePos (sourceStream_->getPosition()),
  80338. currentPos (0),
  80339. buffer (gzipDecompBufferSize),
  80340. helper (new GZIPDecompressHelper (noWrap_))
  80341. {
  80342. }
  80343. GZIPDecompressorInputStream::~GZIPDecompressorInputStream()
  80344. {
  80345. }
  80346. int64 GZIPDecompressorInputStream::getTotalLength()
  80347. {
  80348. return uncompressedStreamLength;
  80349. }
  80350. int GZIPDecompressorInputStream::read (void* destBuffer, int howMany)
  80351. {
  80352. if ((howMany > 0) && ! isEof)
  80353. {
  80354. jassert (destBuffer != 0);
  80355. if (destBuffer != 0)
  80356. {
  80357. int numRead = 0;
  80358. uint8* d = (uint8*) destBuffer;
  80359. while (! helper->error)
  80360. {
  80361. const int n = helper->doNextBlock (d, howMany);
  80362. currentPos += n;
  80363. if (n == 0)
  80364. {
  80365. if (helper->finished || helper->needsDictionary)
  80366. {
  80367. isEof = true;
  80368. return numRead;
  80369. }
  80370. if (helper->needsInput())
  80371. {
  80372. activeBufferSize = sourceStream->read (buffer, gzipDecompBufferSize);
  80373. if (activeBufferSize > 0)
  80374. {
  80375. helper->setInput ((uint8*) buffer, activeBufferSize);
  80376. }
  80377. else
  80378. {
  80379. isEof = true;
  80380. return numRead;
  80381. }
  80382. }
  80383. }
  80384. else
  80385. {
  80386. numRead += n;
  80387. howMany -= n;
  80388. d += n;
  80389. if (howMany <= 0)
  80390. return numRead;
  80391. }
  80392. }
  80393. }
  80394. }
  80395. return 0;
  80396. }
  80397. bool GZIPDecompressorInputStream::isExhausted()
  80398. {
  80399. return helper->error || isEof;
  80400. }
  80401. int64 GZIPDecompressorInputStream::getPosition()
  80402. {
  80403. return currentPos;
  80404. }
  80405. bool GZIPDecompressorInputStream::setPosition (int64 newPos)
  80406. {
  80407. if (newPos < currentPos)
  80408. {
  80409. // to go backwards, reset the stream and start again..
  80410. isEof = false;
  80411. activeBufferSize = 0;
  80412. currentPos = 0;
  80413. helper = new GZIPDecompressHelper (noWrap);
  80414. sourceStream->setPosition (originalSourcePos);
  80415. }
  80416. skipNextBytes (newPos - currentPos);
  80417. return true;
  80418. }
  80419. END_JUCE_NAMESPACE
  80420. /*** End of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  80421. #endif
  80422. #if JUCE_BUILD_NATIVE && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  80423. /*** Start of inlined file: juce_FlacAudioFormat.cpp ***/
  80424. #if JUCE_USE_FLAC
  80425. #if JUCE_WINDOWS
  80426. #include <windows.h>
  80427. #endif
  80428. #ifdef _MSC_VER
  80429. #pragma warning (disable : 4505)
  80430. #pragma warning (push)
  80431. #endif
  80432. namespace FlacNamespace
  80433. {
  80434. #if JUCE_INCLUDE_FLAC_CODE
  80435. #define FLAC__NO_DLL 1
  80436. #if ! defined (SIZE_MAX)
  80437. #define SIZE_MAX 0xffffffff
  80438. #endif
  80439. #define __STDC_LIMIT_MACROS 1
  80440. /*** Start of inlined file: all.h ***/
  80441. #ifndef FLAC__ALL_H
  80442. #define FLAC__ALL_H
  80443. /*** Start of inlined file: export.h ***/
  80444. #ifndef FLAC__EXPORT_H
  80445. #define FLAC__EXPORT_H
  80446. #if defined(FLAC__NO_DLL) || !defined(_MSC_VER)
  80447. #define FLAC_API
  80448. #else
  80449. #ifdef FLAC_API_EXPORTS
  80450. #define FLAC_API _declspec(dllexport)
  80451. #else
  80452. #define FLAC_API _declspec(dllimport)
  80453. #endif
  80454. #endif
  80455. #define FLAC_API_VERSION_CURRENT 10
  80456. #define FLAC_API_VERSION_REVISION 0 /**< see above */
  80457. #define FLAC_API_VERSION_AGE 2 /**< see above */
  80458. #ifdef __cplusplus
  80459. extern "C" {
  80460. #endif
  80461. extern FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC;
  80462. #ifdef __cplusplus
  80463. }
  80464. #endif
  80465. #endif
  80466. /*** End of inlined file: export.h ***/
  80467. /*** Start of inlined file: assert.h ***/
  80468. #ifndef FLAC__ASSERT_H
  80469. #define FLAC__ASSERT_H
  80470. /* we need this since some compilers (like MSVC) leave assert()s on release code (and we don't want to use their ASSERT) */
  80471. #ifdef DEBUG
  80472. #include <assert.h>
  80473. #define FLAC__ASSERT(x) assert(x)
  80474. #define FLAC__ASSERT_DECLARATION(x) x
  80475. #else
  80476. #define FLAC__ASSERT(x)
  80477. #define FLAC__ASSERT_DECLARATION(x)
  80478. #endif
  80479. #endif
  80480. /*** End of inlined file: assert.h ***/
  80481. /*** Start of inlined file: callback.h ***/
  80482. #ifndef FLAC__CALLBACK_H
  80483. #define FLAC__CALLBACK_H
  80484. /*** Start of inlined file: ordinals.h ***/
  80485. #ifndef FLAC__ORDINALS_H
  80486. #define FLAC__ORDINALS_H
  80487. #if !(defined(_MSC_VER) || defined(__BORLANDC__) || defined(__EMX__))
  80488. #include <inttypes.h>
  80489. #endif
  80490. typedef signed char FLAC__int8;
  80491. typedef unsigned char FLAC__uint8;
  80492. #if defined(_MSC_VER) || defined(__BORLANDC__)
  80493. typedef __int16 FLAC__int16;
  80494. typedef __int32 FLAC__int32;
  80495. typedef __int64 FLAC__int64;
  80496. typedef unsigned __int16 FLAC__uint16;
  80497. typedef unsigned __int32 FLAC__uint32;
  80498. typedef unsigned __int64 FLAC__uint64;
  80499. #elif defined(__EMX__)
  80500. typedef short FLAC__int16;
  80501. typedef long FLAC__int32;
  80502. typedef long long FLAC__int64;
  80503. typedef unsigned short FLAC__uint16;
  80504. typedef unsigned long FLAC__uint32;
  80505. typedef unsigned long long FLAC__uint64;
  80506. #else
  80507. typedef int16_t FLAC__int16;
  80508. typedef int32_t FLAC__int32;
  80509. typedef int64_t FLAC__int64;
  80510. typedef uint16_t FLAC__uint16;
  80511. typedef uint32_t FLAC__uint32;
  80512. typedef uint64_t FLAC__uint64;
  80513. #endif
  80514. typedef int FLAC__bool;
  80515. typedef FLAC__uint8 FLAC__byte;
  80516. #ifdef true
  80517. #undef true
  80518. #endif
  80519. #ifdef false
  80520. #undef false
  80521. #endif
  80522. #ifndef __cplusplus
  80523. #define true 1
  80524. #define false 0
  80525. #endif
  80526. #endif
  80527. /*** End of inlined file: ordinals.h ***/
  80528. #include <stdlib.h> /* for size_t */
  80529. #ifdef __cplusplus
  80530. extern "C" {
  80531. #endif
  80532. typedef void* FLAC__IOHandle;
  80533. typedef size_t (*FLAC__IOCallback_Read) (void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  80534. typedef size_t (*FLAC__IOCallback_Write) (const void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  80535. typedef int (*FLAC__IOCallback_Seek) (FLAC__IOHandle handle, FLAC__int64 offset, int whence);
  80536. typedef FLAC__int64 (*FLAC__IOCallback_Tell) (FLAC__IOHandle handle);
  80537. typedef int (*FLAC__IOCallback_Eof) (FLAC__IOHandle handle);
  80538. typedef int (*FLAC__IOCallback_Close) (FLAC__IOHandle handle);
  80539. typedef struct {
  80540. FLAC__IOCallback_Read read;
  80541. FLAC__IOCallback_Write write;
  80542. FLAC__IOCallback_Seek seek;
  80543. FLAC__IOCallback_Tell tell;
  80544. FLAC__IOCallback_Eof eof;
  80545. FLAC__IOCallback_Close close;
  80546. } FLAC__IOCallbacks;
  80547. #ifdef __cplusplus
  80548. }
  80549. #endif
  80550. #endif
  80551. /*** End of inlined file: callback.h ***/
  80552. /*** Start of inlined file: format.h ***/
  80553. #ifndef FLAC__FORMAT_H
  80554. #define FLAC__FORMAT_H
  80555. #ifdef __cplusplus
  80556. extern "C" {
  80557. #endif
  80558. #define FLAC__MAX_METADATA_TYPE_CODE (126u)
  80559. #define FLAC__MIN_BLOCK_SIZE (16u)
  80560. #define FLAC__MAX_BLOCK_SIZE (65535u)
  80561. #define FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ (4608u)
  80562. #define FLAC__MAX_CHANNELS (8u)
  80563. #define FLAC__MIN_BITS_PER_SAMPLE (4u)
  80564. #define FLAC__MAX_BITS_PER_SAMPLE (32u)
  80565. #define FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE (24u)
  80566. #define FLAC__MAX_SAMPLE_RATE (655350u)
  80567. #define FLAC__MAX_LPC_ORDER (32u)
  80568. #define FLAC__SUBSET_MAX_LPC_ORDER_48000HZ (12u)
  80569. #define FLAC__MIN_QLP_COEFF_PRECISION (5u)
  80570. #define FLAC__MAX_QLP_COEFF_PRECISION (15u)
  80571. #define FLAC__MAX_FIXED_ORDER (4u)
  80572. #define FLAC__MAX_RICE_PARTITION_ORDER (15u)
  80573. #define FLAC__SUBSET_MAX_RICE_PARTITION_ORDER (8u)
  80574. extern FLAC_API const char *FLAC__VERSION_STRING;
  80575. extern FLAC_API const char *FLAC__VENDOR_STRING;
  80576. extern FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4]; /* = "fLaC" */
  80577. extern FLAC_API const unsigned FLAC__STREAM_SYNC; /* = 0x664C6143 */
  80578. extern FLAC_API const unsigned FLAC__STREAM_SYNC_LEN; /* = 32 bits */
  80579. #define FLAC__STREAM_SYNC_LENGTH (4u)
  80580. typedef enum {
  80581. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE = 0,
  80582. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2 = 1
  80583. } FLAC__EntropyCodingMethodType;
  80584. extern FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[];
  80585. typedef struct {
  80586. unsigned *parameters;
  80587. unsigned *raw_bits;
  80588. unsigned capacity_by_order;
  80589. } FLAC__EntropyCodingMethod_PartitionedRiceContents;
  80590. typedef struct {
  80591. unsigned order;
  80592. const FLAC__EntropyCodingMethod_PartitionedRiceContents *contents;
  80593. } FLAC__EntropyCodingMethod_PartitionedRice;
  80594. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN; /**< == 4 (bits) */
  80595. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; /**< == 4 (bits) */
  80596. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN; /**< == 5 (bits) */
  80597. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN; /**< == 5 (bits) */
  80598. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  80599. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER;
  80600. typedef struct {
  80601. FLAC__EntropyCodingMethodType type;
  80602. union {
  80603. FLAC__EntropyCodingMethod_PartitionedRice partitioned_rice;
  80604. } data;
  80605. } FLAC__EntropyCodingMethod;
  80606. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN; /**< == 2 (bits) */
  80607. typedef enum {
  80608. FLAC__SUBFRAME_TYPE_CONSTANT = 0, /**< constant signal */
  80609. FLAC__SUBFRAME_TYPE_VERBATIM = 1, /**< uncompressed signal */
  80610. FLAC__SUBFRAME_TYPE_FIXED = 2, /**< fixed polynomial prediction */
  80611. FLAC__SUBFRAME_TYPE_LPC = 3 /**< linear prediction */
  80612. } FLAC__SubframeType;
  80613. extern FLAC_API const char * const FLAC__SubframeTypeString[];
  80614. typedef struct {
  80615. FLAC__int32 value; /**< The constant signal value. */
  80616. } FLAC__Subframe_Constant;
  80617. typedef struct {
  80618. const FLAC__int32 *data; /**< A pointer to verbatim signal. */
  80619. } FLAC__Subframe_Verbatim;
  80620. typedef struct {
  80621. FLAC__EntropyCodingMethod entropy_coding_method;
  80622. unsigned order;
  80623. FLAC__int32 warmup[FLAC__MAX_FIXED_ORDER];
  80624. const FLAC__int32 *residual;
  80625. } FLAC__Subframe_Fixed;
  80626. typedef struct {
  80627. FLAC__EntropyCodingMethod entropy_coding_method;
  80628. unsigned order;
  80629. unsigned qlp_coeff_precision;
  80630. int quantization_level;
  80631. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  80632. FLAC__int32 warmup[FLAC__MAX_LPC_ORDER];
  80633. const FLAC__int32 *residual;
  80634. } FLAC__Subframe_LPC;
  80635. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN; /**< == 4 (bits) */
  80636. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN; /**< == 5 (bits) */
  80637. typedef struct {
  80638. FLAC__SubframeType type;
  80639. union {
  80640. FLAC__Subframe_Constant constant;
  80641. FLAC__Subframe_Fixed fixed;
  80642. FLAC__Subframe_LPC lpc;
  80643. FLAC__Subframe_Verbatim verbatim;
  80644. } data;
  80645. unsigned wasted_bits;
  80646. } FLAC__Subframe;
  80647. extern FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN;
  80648. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN; /**< == 6 (bits) */
  80649. extern FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN; /**< == 1 (bit) */
  80650. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK; /**< = 0x00 */
  80651. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK; /**< = 0x02 */
  80652. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK; /**< = 0x10 */
  80653. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK; /**< = 0x40 */
  80654. typedef enum {
  80655. FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT = 0, /**< independent channels */
  80656. FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE = 1, /**< left+side stereo */
  80657. FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE = 2, /**< right+side stereo */
  80658. FLAC__CHANNEL_ASSIGNMENT_MID_SIDE = 3 /**< mid+side stereo */
  80659. } FLAC__ChannelAssignment;
  80660. extern FLAC_API const char * const FLAC__ChannelAssignmentString[];
  80661. typedef enum {
  80662. FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER, /**< number contains the frame number */
  80663. FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER /**< number contains the sample number of first sample in frame */
  80664. } FLAC__FrameNumberType;
  80665. extern FLAC_API const char * const FLAC__FrameNumberTypeString[];
  80666. typedef struct {
  80667. unsigned blocksize;
  80668. unsigned sample_rate;
  80669. unsigned channels;
  80670. FLAC__ChannelAssignment channel_assignment;
  80671. unsigned bits_per_sample;
  80672. FLAC__FrameNumberType number_type;
  80673. union {
  80674. FLAC__uint32 frame_number;
  80675. FLAC__uint64 sample_number;
  80676. } number;
  80677. FLAC__uint8 crc;
  80678. } FLAC__FrameHeader;
  80679. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC; /**< == 0x3ffe; the frame header sync code */
  80680. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN; /**< == 14 (bits) */
  80681. extern FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN; /**< == 1 (bits) */
  80682. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN; /**< == 1 (bits) */
  80683. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN; /**< == 4 (bits) */
  80684. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN; /**< == 4 (bits) */
  80685. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN; /**< == 4 (bits) */
  80686. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN; /**< == 3 (bits) */
  80687. extern FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN; /**< == 1 (bit) */
  80688. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN; /**< == 8 (bits) */
  80689. typedef struct {
  80690. FLAC__uint16 crc;
  80691. } FLAC__FrameFooter;
  80692. extern FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN; /**< == 16 (bits) */
  80693. typedef struct {
  80694. FLAC__FrameHeader header;
  80695. FLAC__Subframe subframes[FLAC__MAX_CHANNELS];
  80696. FLAC__FrameFooter footer;
  80697. } FLAC__Frame;
  80698. typedef enum {
  80699. FLAC__METADATA_TYPE_STREAMINFO = 0,
  80700. FLAC__METADATA_TYPE_PADDING = 1,
  80701. FLAC__METADATA_TYPE_APPLICATION = 2,
  80702. FLAC__METADATA_TYPE_SEEKTABLE = 3,
  80703. FLAC__METADATA_TYPE_VORBIS_COMMENT = 4,
  80704. FLAC__METADATA_TYPE_CUESHEET = 5,
  80705. FLAC__METADATA_TYPE_PICTURE = 6,
  80706. FLAC__METADATA_TYPE_UNDEFINED = 7
  80707. } FLAC__MetadataType;
  80708. extern FLAC_API const char * const FLAC__MetadataTypeString[];
  80709. typedef struct {
  80710. unsigned min_blocksize, max_blocksize;
  80711. unsigned min_framesize, max_framesize;
  80712. unsigned sample_rate;
  80713. unsigned channels;
  80714. unsigned bits_per_sample;
  80715. FLAC__uint64 total_samples;
  80716. FLAC__byte md5sum[16];
  80717. } FLAC__StreamMetadata_StreamInfo;
  80718. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  80719. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  80720. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN; /**< == 24 (bits) */
  80721. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN; /**< == 24 (bits) */
  80722. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN; /**< == 20 (bits) */
  80723. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN; /**< == 3 (bits) */
  80724. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN; /**< == 5 (bits) */
  80725. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN; /**< == 36 (bits) */
  80726. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN; /**< == 128 (bits) */
  80727. #define FLAC__STREAM_METADATA_STREAMINFO_LENGTH (34u)
  80728. typedef struct {
  80729. int dummy;
  80730. } FLAC__StreamMetadata_Padding;
  80731. typedef struct {
  80732. FLAC__byte id[4];
  80733. FLAC__byte *data;
  80734. } FLAC__StreamMetadata_Application;
  80735. extern FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN; /**< == 32 (bits) */
  80736. typedef struct {
  80737. FLAC__uint64 sample_number;
  80738. FLAC__uint64 stream_offset;
  80739. unsigned frame_samples;
  80740. } FLAC__StreamMetadata_SeekPoint;
  80741. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN; /**< == 64 (bits) */
  80742. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN; /**< == 64 (bits) */
  80743. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN; /**< == 16 (bits) */
  80744. #define FLAC__STREAM_METADATA_SEEKPOINT_LENGTH (18u)
  80745. extern FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  80746. typedef struct {
  80747. unsigned num_points;
  80748. FLAC__StreamMetadata_SeekPoint *points;
  80749. } FLAC__StreamMetadata_SeekTable;
  80750. typedef struct {
  80751. FLAC__uint32 length;
  80752. FLAC__byte *entry;
  80753. } FLAC__StreamMetadata_VorbisComment_Entry;
  80754. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN; /**< == 32 (bits) */
  80755. typedef struct {
  80756. FLAC__StreamMetadata_VorbisComment_Entry vendor_string;
  80757. FLAC__uint32 num_comments;
  80758. FLAC__StreamMetadata_VorbisComment_Entry *comments;
  80759. } FLAC__StreamMetadata_VorbisComment;
  80760. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN; /**< == 32 (bits) */
  80761. typedef struct {
  80762. FLAC__uint64 offset;
  80763. FLAC__byte number;
  80764. } FLAC__StreamMetadata_CueSheet_Index;
  80765. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN; /**< == 64 (bits) */
  80766. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN; /**< == 8 (bits) */
  80767. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN; /**< == 3*8 (bits) */
  80768. typedef struct {
  80769. FLAC__uint64 offset;
  80770. FLAC__byte number;
  80771. char isrc[13];
  80772. unsigned type:1;
  80773. unsigned pre_emphasis:1;
  80774. FLAC__byte num_indices;
  80775. FLAC__StreamMetadata_CueSheet_Index *indices;
  80776. } FLAC__StreamMetadata_CueSheet_Track;
  80777. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN; /**< == 64 (bits) */
  80778. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN; /**< == 8 (bits) */
  80779. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN; /**< == 12*8 (bits) */
  80780. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN; /**< == 1 (bit) */
  80781. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN; /**< == 1 (bit) */
  80782. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN; /**< == 6+13*8 (bits) */
  80783. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN; /**< == 8 (bits) */
  80784. typedef struct {
  80785. char media_catalog_number[129];
  80786. FLAC__uint64 lead_in;
  80787. FLAC__bool is_cd;
  80788. unsigned num_tracks;
  80789. FLAC__StreamMetadata_CueSheet_Track *tracks;
  80790. } FLAC__StreamMetadata_CueSheet;
  80791. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN; /**< == 128*8 (bits) */
  80792. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN; /**< == 64 (bits) */
  80793. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN; /**< == 1 (bit) */
  80794. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN; /**< == 7+258*8 (bits) */
  80795. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN; /**< == 8 (bits) */
  80796. typedef enum {
  80797. FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER = 0, /**< Other */
  80798. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD = 1, /**< 32x32 pixels 'file icon' (PNG only) */
  80799. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON = 2, /**< Other file icon */
  80800. FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER = 3, /**< Cover (front) */
  80801. FLAC__STREAM_METADATA_PICTURE_TYPE_BACK_COVER = 4, /**< Cover (back) */
  80802. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAFLET_PAGE = 5, /**< Leaflet page */
  80803. FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA = 6, /**< Media (e.g. label side of CD) */
  80804. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAD_ARTIST = 7, /**< Lead artist/lead performer/soloist */
  80805. FLAC__STREAM_METADATA_PICTURE_TYPE_ARTIST = 8, /**< Artist/performer */
  80806. FLAC__STREAM_METADATA_PICTURE_TYPE_CONDUCTOR = 9, /**< Conductor */
  80807. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND = 10, /**< Band/Orchestra */
  80808. FLAC__STREAM_METADATA_PICTURE_TYPE_COMPOSER = 11, /**< Composer */
  80809. FLAC__STREAM_METADATA_PICTURE_TYPE_LYRICIST = 12, /**< Lyricist/text writer */
  80810. FLAC__STREAM_METADATA_PICTURE_TYPE_RECORDING_LOCATION = 13, /**< Recording Location */
  80811. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_RECORDING = 14, /**< During recording */
  80812. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_PERFORMANCE = 15, /**< During performance */
  80813. FLAC__STREAM_METADATA_PICTURE_TYPE_VIDEO_SCREEN_CAPTURE = 16, /**< Movie/video screen capture */
  80814. FLAC__STREAM_METADATA_PICTURE_TYPE_FISH = 17, /**< A bright coloured fish */
  80815. FLAC__STREAM_METADATA_PICTURE_TYPE_ILLUSTRATION = 18, /**< Illustration */
  80816. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND_LOGOTYPE = 19, /**< Band/artist logotype */
  80817. FLAC__STREAM_METADATA_PICTURE_TYPE_PUBLISHER_LOGOTYPE = 20, /**< Publisher/Studio logotype */
  80818. FLAC__STREAM_METADATA_PICTURE_TYPE_UNDEFINED
  80819. } FLAC__StreamMetadata_Picture_Type;
  80820. extern FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[];
  80821. typedef struct {
  80822. FLAC__StreamMetadata_Picture_Type type;
  80823. char *mime_type;
  80824. FLAC__byte *description;
  80825. FLAC__uint32 width;
  80826. FLAC__uint32 height;
  80827. FLAC__uint32 depth;
  80828. FLAC__uint32 colors;
  80829. FLAC__uint32 data_length;
  80830. FLAC__byte *data;
  80831. } FLAC__StreamMetadata_Picture;
  80832. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN; /**< == 32 (bits) */
  80833. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN; /**< == 32 (bits) */
  80834. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN; /**< == 32 (bits) */
  80835. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN; /**< == 32 (bits) */
  80836. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN; /**< == 32 (bits) */
  80837. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN; /**< == 32 (bits) */
  80838. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN; /**< == 32 (bits) */
  80839. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN; /**< == 32 (bits) */
  80840. typedef struct {
  80841. FLAC__byte *data;
  80842. } FLAC__StreamMetadata_Unknown;
  80843. typedef struct {
  80844. FLAC__MetadataType type;
  80845. FLAC__bool is_last;
  80846. unsigned length;
  80847. union {
  80848. FLAC__StreamMetadata_StreamInfo stream_info;
  80849. FLAC__StreamMetadata_Padding padding;
  80850. FLAC__StreamMetadata_Application application;
  80851. FLAC__StreamMetadata_SeekTable seek_table;
  80852. FLAC__StreamMetadata_VorbisComment vorbis_comment;
  80853. FLAC__StreamMetadata_CueSheet cue_sheet;
  80854. FLAC__StreamMetadata_Picture picture;
  80855. FLAC__StreamMetadata_Unknown unknown;
  80856. } data;
  80857. } FLAC__StreamMetadata;
  80858. extern FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN; /**< == 1 (bit) */
  80859. extern FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN; /**< == 7 (bits) */
  80860. extern FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN; /**< == 24 (bits) */
  80861. #define FLAC__STREAM_METADATA_HEADER_LENGTH (4u)
  80862. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate);
  80863. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate);
  80864. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name);
  80865. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length);
  80866. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length);
  80867. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table);
  80868. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table);
  80869. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation);
  80870. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation);
  80871. #ifdef __cplusplus
  80872. }
  80873. #endif
  80874. #endif
  80875. /*** End of inlined file: format.h ***/
  80876. /*** Start of inlined file: metadata.h ***/
  80877. #ifndef FLAC__METADATA_H
  80878. #define FLAC__METADATA_H
  80879. #include <sys/types.h> /* for off_t */
  80880. #ifdef __cplusplus
  80881. extern "C" {
  80882. #endif
  80883. FLAC_API FLAC__bool FLAC__metadata_get_streaminfo(const char *filename, FLAC__StreamMetadata *streaminfo);
  80884. FLAC_API FLAC__bool FLAC__metadata_get_tags(const char *filename, FLAC__StreamMetadata **tags);
  80885. FLAC_API FLAC__bool FLAC__metadata_get_cuesheet(const char *filename, FLAC__StreamMetadata **cuesheet);
  80886. 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);
  80887. struct FLAC__Metadata_SimpleIterator;
  80888. typedef struct FLAC__Metadata_SimpleIterator FLAC__Metadata_SimpleIterator;
  80889. typedef enum {
  80890. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK = 0,
  80891. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT,
  80892. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE,
  80893. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE,
  80894. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE,
  80895. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA,
  80896. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR,
  80897. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR,
  80898. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR,
  80899. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR,
  80900. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR,
  80901. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR,
  80902. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR
  80903. } FLAC__Metadata_SimpleIteratorStatus;
  80904. extern FLAC_API const char * const FLAC__Metadata_SimpleIteratorStatusString[];
  80905. FLAC_API FLAC__Metadata_SimpleIterator *FLAC__metadata_simple_iterator_new(void);
  80906. FLAC_API void FLAC__metadata_simple_iterator_delete(FLAC__Metadata_SimpleIterator *iterator);
  80907. FLAC_API FLAC__Metadata_SimpleIteratorStatus FLAC__metadata_simple_iterator_status(FLAC__Metadata_SimpleIterator *iterator);
  80908. 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);
  80909. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_writable(const FLAC__Metadata_SimpleIterator *iterator);
  80910. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_next(FLAC__Metadata_SimpleIterator *iterator);
  80911. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_prev(FLAC__Metadata_SimpleIterator *iterator);
  80912. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_last(const FLAC__Metadata_SimpleIterator *iterator);
  80913. FLAC_API off_t FLAC__metadata_simple_iterator_get_block_offset(const FLAC__Metadata_SimpleIterator *iterator);
  80914. FLAC_API FLAC__MetadataType FLAC__metadata_simple_iterator_get_block_type(const FLAC__Metadata_SimpleIterator *iterator);
  80915. FLAC_API unsigned FLAC__metadata_simple_iterator_get_block_length(const FLAC__Metadata_SimpleIterator *iterator);
  80916. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_get_application_id(FLAC__Metadata_SimpleIterator *iterator, FLAC__byte *id);
  80917. FLAC_API FLAC__StreamMetadata *FLAC__metadata_simple_iterator_get_block(FLAC__Metadata_SimpleIterator *iterator);
  80918. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_set_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  80919. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_insert_block_after(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  80920. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__bool use_padding);
  80921. struct FLAC__Metadata_Chain;
  80922. typedef struct FLAC__Metadata_Chain FLAC__Metadata_Chain;
  80923. struct FLAC__Metadata_Iterator;
  80924. typedef struct FLAC__Metadata_Iterator FLAC__Metadata_Iterator;
  80925. typedef enum {
  80926. FLAC__METADATA_CHAIN_STATUS_OK = 0,
  80927. FLAC__METADATA_CHAIN_STATUS_ILLEGAL_INPUT,
  80928. FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE,
  80929. FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE,
  80930. FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE,
  80931. FLAC__METADATA_CHAIN_STATUS_BAD_METADATA,
  80932. FLAC__METADATA_CHAIN_STATUS_READ_ERROR,
  80933. FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR,
  80934. FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR,
  80935. FLAC__METADATA_CHAIN_STATUS_RENAME_ERROR,
  80936. FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR,
  80937. FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR,
  80938. FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR,
  80939. FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS,
  80940. FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH,
  80941. FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL
  80942. } FLAC__Metadata_ChainStatus;
  80943. extern FLAC_API const char * const FLAC__Metadata_ChainStatusString[];
  80944. FLAC_API FLAC__Metadata_Chain *FLAC__metadata_chain_new(void);
  80945. FLAC_API void FLAC__metadata_chain_delete(FLAC__Metadata_Chain *chain);
  80946. FLAC_API FLAC__Metadata_ChainStatus FLAC__metadata_chain_status(FLAC__Metadata_Chain *chain);
  80947. FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename);
  80948. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg(FLAC__Metadata_Chain *chain, const char *filename);
  80949. FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  80950. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  80951. FLAC_API FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata_Chain *chain, FLAC__bool use_padding);
  80952. FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__bool preserve_file_stats);
  80953. FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  80954. 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);
  80955. FLAC_API void FLAC__metadata_chain_merge_padding(FLAC__Metadata_Chain *chain);
  80956. FLAC_API void FLAC__metadata_chain_sort_padding(FLAC__Metadata_Chain *chain);
  80957. FLAC_API FLAC__Metadata_Iterator *FLAC__metadata_iterator_new(void);
  80958. FLAC_API void FLAC__metadata_iterator_delete(FLAC__Metadata_Iterator *iterator);
  80959. FLAC_API void FLAC__metadata_iterator_init(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Chain *chain);
  80960. FLAC_API FLAC__bool FLAC__metadata_iterator_next(FLAC__Metadata_Iterator *iterator);
  80961. FLAC_API FLAC__bool FLAC__metadata_iterator_prev(FLAC__Metadata_Iterator *iterator);
  80962. FLAC_API FLAC__MetadataType FLAC__metadata_iterator_get_block_type(const FLAC__Metadata_Iterator *iterator);
  80963. FLAC_API FLAC__StreamMetadata *FLAC__metadata_iterator_get_block(FLAC__Metadata_Iterator *iterator);
  80964. FLAC_API FLAC__bool FLAC__metadata_iterator_set_block(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  80965. FLAC_API FLAC__bool FLAC__metadata_iterator_delete_block(FLAC__Metadata_Iterator *iterator, FLAC__bool replace_with_padding);
  80966. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_before(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  80967. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_after(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  80968. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type);
  80969. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMetadata *object);
  80970. FLAC_API void FLAC__metadata_object_delete(FLAC__StreamMetadata *object);
  80971. FLAC_API FLAC__bool FLAC__metadata_object_is_equal(const FLAC__StreamMetadata *block1, const FLAC__StreamMetadata *block2);
  80972. FLAC_API FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, unsigned length, FLAC__bool copy);
  80973. FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata *object, unsigned new_num_points);
  80974. FLAC_API void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  80975. FLAC_API FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  80976. FLAC_API FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata *object, unsigned point_num);
  80977. FLAC_API FLAC__bool FLAC__metadata_object_seektable_is_legal(const FLAC__StreamMetadata *object);
  80978. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata *object, unsigned num);
  80979. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_point(FLAC__StreamMetadata *object, FLAC__uint64 sample_number);
  80980. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata *object, FLAC__uint64 sample_numbers[], unsigned num);
  80981. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata *object, unsigned num, FLAC__uint64 total_samples);
  80982. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(FLAC__StreamMetadata *object, unsigned samples, FLAC__uint64 total_samples);
  80983. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_sort(FLAC__StreamMetadata *object, FLAC__bool compact);
  80984. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_vendor_string(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  80985. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata *object, unsigned new_num_comments);
  80986. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  80987. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  80988. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_append_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  80989. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_replace_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool all, FLAC__bool copy);
  80990. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata *object, unsigned comment_num);
  80991. 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);
  80992. 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);
  80993. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_matches(const FLAC__StreamMetadata_VorbisComment_Entry entry, const char *field_name, unsigned field_name_length);
  80994. FLAC_API int FLAC__metadata_object_vorbiscomment_find_entry_from(const FLAC__StreamMetadata *object, unsigned offset, const char *field_name);
  80995. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entry_matching(FLAC__StreamMetadata *object, const char *field_name);
  80996. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entries_matching(FLAC__StreamMetadata *object, const char *field_name);
  80997. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_new(void);
  80998. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_clone(const FLAC__StreamMetadata_CueSheet_Track *object);
  80999. FLAC_API void FLAC__metadata_object_cuesheet_track_delete(FLAC__StreamMetadata_CueSheet_Track *object);
  81000. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, unsigned track_num, unsigned new_num_indices);
  81001. 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);
  81002. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  81003. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  81004. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata *object, unsigned new_num_tracks);
  81005. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  81006. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  81007. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata *object, unsigned track_num);
  81008. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, unsigned track_num);
  81009. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_is_legal(const FLAC__StreamMetadata *object, FLAC__bool check_cd_da_subset, const char **violation);
  81010. FLAC_API FLAC__uint32 FLAC__metadata_object_cuesheet_calculate_cddb_id(const FLAC__StreamMetadata *object);
  81011. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_mime_type(FLAC__StreamMetadata *object, char *mime_type, FLAC__bool copy);
  81012. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_description(FLAC__StreamMetadata *object, FLAC__byte *description, FLAC__bool copy);
  81013. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, FLAC__uint32 length, FLAC__bool copy);
  81014. FLAC_API FLAC__bool FLAC__metadata_object_picture_is_legal(const FLAC__StreamMetadata *object, const char **violation);
  81015. #ifdef __cplusplus
  81016. }
  81017. #endif
  81018. #endif
  81019. /*** End of inlined file: metadata.h ***/
  81020. /*** Start of inlined file: stream_decoder.h ***/
  81021. #ifndef FLAC__STREAM_DECODER_H
  81022. #define FLAC__STREAM_DECODER_H
  81023. #include <stdio.h> /* for FILE */
  81024. #ifdef __cplusplus
  81025. extern "C" {
  81026. #endif
  81027. typedef enum {
  81028. FLAC__STREAM_DECODER_SEARCH_FOR_METADATA = 0,
  81029. FLAC__STREAM_DECODER_READ_METADATA,
  81030. FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC,
  81031. FLAC__STREAM_DECODER_READ_FRAME,
  81032. FLAC__STREAM_DECODER_END_OF_STREAM,
  81033. FLAC__STREAM_DECODER_OGG_ERROR,
  81034. FLAC__STREAM_DECODER_SEEK_ERROR,
  81035. FLAC__STREAM_DECODER_ABORTED,
  81036. FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR,
  81037. FLAC__STREAM_DECODER_UNINITIALIZED
  81038. } FLAC__StreamDecoderState;
  81039. extern FLAC_API const char * const FLAC__StreamDecoderStateString[];
  81040. typedef enum {
  81041. FLAC__STREAM_DECODER_INIT_STATUS_OK = 0,
  81042. FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81043. FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS,
  81044. FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR,
  81045. FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE,
  81046. FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED
  81047. } FLAC__StreamDecoderInitStatus;
  81048. extern FLAC_API const char * const FLAC__StreamDecoderInitStatusString[];
  81049. typedef enum {
  81050. FLAC__STREAM_DECODER_READ_STATUS_CONTINUE,
  81051. FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM,
  81052. FLAC__STREAM_DECODER_READ_STATUS_ABORT
  81053. } FLAC__StreamDecoderReadStatus;
  81054. extern FLAC_API const char * const FLAC__StreamDecoderReadStatusString[];
  81055. typedef enum {
  81056. FLAC__STREAM_DECODER_SEEK_STATUS_OK,
  81057. FLAC__STREAM_DECODER_SEEK_STATUS_ERROR,
  81058. FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED
  81059. } FLAC__StreamDecoderSeekStatus;
  81060. extern FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[];
  81061. typedef enum {
  81062. FLAC__STREAM_DECODER_TELL_STATUS_OK,
  81063. FLAC__STREAM_DECODER_TELL_STATUS_ERROR,
  81064. FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED
  81065. } FLAC__StreamDecoderTellStatus;
  81066. extern FLAC_API const char * const FLAC__StreamDecoderTellStatusString[];
  81067. typedef enum {
  81068. FLAC__STREAM_DECODER_LENGTH_STATUS_OK,
  81069. FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR,
  81070. FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED
  81071. } FLAC__StreamDecoderLengthStatus;
  81072. extern FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[];
  81073. typedef enum {
  81074. FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE,
  81075. FLAC__STREAM_DECODER_WRITE_STATUS_ABORT
  81076. } FLAC__StreamDecoderWriteStatus;
  81077. extern FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[];
  81078. typedef enum {
  81079. FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC,
  81080. FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER,
  81081. FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH,
  81082. FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM
  81083. } FLAC__StreamDecoderErrorStatus;
  81084. extern FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[];
  81085. struct FLAC__StreamDecoderProtected;
  81086. struct FLAC__StreamDecoderPrivate;
  81087. typedef struct {
  81088. struct FLAC__StreamDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81089. struct FLAC__StreamDecoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81090. } FLAC__StreamDecoder;
  81091. typedef FLAC__StreamDecoderReadStatus (*FLAC__StreamDecoderReadCallback)(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81092. typedef FLAC__StreamDecoderSeekStatus (*FLAC__StreamDecoderSeekCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81093. typedef FLAC__StreamDecoderTellStatus (*FLAC__StreamDecoderTellCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81094. typedef FLAC__StreamDecoderLengthStatus (*FLAC__StreamDecoderLengthCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  81095. typedef FLAC__bool (*FLAC__StreamDecoderEofCallback)(const FLAC__StreamDecoder *decoder, void *client_data);
  81096. typedef FLAC__StreamDecoderWriteStatus (*FLAC__StreamDecoderWriteCallback)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  81097. typedef void (*FLAC__StreamDecoderMetadataCallback)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81098. typedef void (*FLAC__StreamDecoderErrorCallback)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  81099. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void);
  81100. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder);
  81101. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long serial_number);
  81102. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value);
  81103. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81104. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81105. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder);
  81106. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81107. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81108. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder);
  81109. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder);
  81110. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder);
  81111. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder);
  81112. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder);
  81113. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder);
  81114. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder);
  81115. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder);
  81116. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder);
  81117. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder);
  81118. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position);
  81119. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  81120. FLAC__StreamDecoder *decoder,
  81121. FLAC__StreamDecoderReadCallback read_callback,
  81122. FLAC__StreamDecoderSeekCallback seek_callback,
  81123. FLAC__StreamDecoderTellCallback tell_callback,
  81124. FLAC__StreamDecoderLengthCallback length_callback,
  81125. FLAC__StreamDecoderEofCallback eof_callback,
  81126. FLAC__StreamDecoderWriteCallback write_callback,
  81127. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81128. FLAC__StreamDecoderErrorCallback error_callback,
  81129. void *client_data
  81130. );
  81131. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  81132. FLAC__StreamDecoder *decoder,
  81133. FLAC__StreamDecoderReadCallback read_callback,
  81134. FLAC__StreamDecoderSeekCallback seek_callback,
  81135. FLAC__StreamDecoderTellCallback tell_callback,
  81136. FLAC__StreamDecoderLengthCallback length_callback,
  81137. FLAC__StreamDecoderEofCallback eof_callback,
  81138. FLAC__StreamDecoderWriteCallback write_callback,
  81139. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81140. FLAC__StreamDecoderErrorCallback error_callback,
  81141. void *client_data
  81142. );
  81143. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  81144. FLAC__StreamDecoder *decoder,
  81145. FILE *file,
  81146. FLAC__StreamDecoderWriteCallback write_callback,
  81147. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81148. FLAC__StreamDecoderErrorCallback error_callback,
  81149. void *client_data
  81150. );
  81151. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  81152. FLAC__StreamDecoder *decoder,
  81153. FILE *file,
  81154. FLAC__StreamDecoderWriteCallback write_callback,
  81155. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81156. FLAC__StreamDecoderErrorCallback error_callback,
  81157. void *client_data
  81158. );
  81159. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  81160. FLAC__StreamDecoder *decoder,
  81161. const char *filename,
  81162. FLAC__StreamDecoderWriteCallback write_callback,
  81163. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81164. FLAC__StreamDecoderErrorCallback error_callback,
  81165. void *client_data
  81166. );
  81167. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  81168. FLAC__StreamDecoder *decoder,
  81169. const char *filename,
  81170. FLAC__StreamDecoderWriteCallback write_callback,
  81171. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81172. FLAC__StreamDecoderErrorCallback error_callback,
  81173. void *client_data
  81174. );
  81175. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder);
  81176. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder);
  81177. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder);
  81178. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder);
  81179. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder);
  81180. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder);
  81181. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder);
  81182. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample);
  81183. #ifdef __cplusplus
  81184. }
  81185. #endif
  81186. #endif
  81187. /*** End of inlined file: stream_decoder.h ***/
  81188. /*** Start of inlined file: stream_encoder.h ***/
  81189. #ifndef FLAC__STREAM_ENCODER_H
  81190. #define FLAC__STREAM_ENCODER_H
  81191. #include <stdio.h> /* for FILE */
  81192. #ifdef __cplusplus
  81193. extern "C" {
  81194. #endif
  81195. typedef enum {
  81196. FLAC__STREAM_ENCODER_OK = 0,
  81197. FLAC__STREAM_ENCODER_UNINITIALIZED,
  81198. FLAC__STREAM_ENCODER_OGG_ERROR,
  81199. FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR,
  81200. FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA,
  81201. FLAC__STREAM_ENCODER_CLIENT_ERROR,
  81202. FLAC__STREAM_ENCODER_IO_ERROR,
  81203. FLAC__STREAM_ENCODER_FRAMING_ERROR,
  81204. FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR
  81205. } FLAC__StreamEncoderState;
  81206. extern FLAC_API const char * const FLAC__StreamEncoderStateString[];
  81207. typedef enum {
  81208. FLAC__STREAM_ENCODER_INIT_STATUS_OK = 0,
  81209. FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR,
  81210. FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81211. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS,
  81212. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS,
  81213. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE,
  81214. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE,
  81215. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE,
  81216. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER,
  81217. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION,
  81218. FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
  81219. FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE,
  81220. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA,
  81221. FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED
  81222. } FLAC__StreamEncoderInitStatus;
  81223. extern FLAC_API const char * const FLAC__StreamEncoderInitStatusString[];
  81224. typedef enum {
  81225. FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE,
  81226. FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM,
  81227. FLAC__STREAM_ENCODER_READ_STATUS_ABORT,
  81228. FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED
  81229. } FLAC__StreamEncoderReadStatus;
  81230. extern FLAC_API const char * const FLAC__StreamEncoderReadStatusString[];
  81231. typedef enum {
  81232. FLAC__STREAM_ENCODER_WRITE_STATUS_OK = 0,
  81233. FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR
  81234. } FLAC__StreamEncoderWriteStatus;
  81235. extern FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[];
  81236. typedef enum {
  81237. FLAC__STREAM_ENCODER_SEEK_STATUS_OK,
  81238. FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR,
  81239. FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
  81240. } FLAC__StreamEncoderSeekStatus;
  81241. extern FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[];
  81242. typedef enum {
  81243. FLAC__STREAM_ENCODER_TELL_STATUS_OK,
  81244. FLAC__STREAM_ENCODER_TELL_STATUS_ERROR,
  81245. FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
  81246. } FLAC__StreamEncoderTellStatus;
  81247. extern FLAC_API const char * const FLAC__StreamEncoderTellStatusString[];
  81248. struct FLAC__StreamEncoderProtected;
  81249. struct FLAC__StreamEncoderPrivate;
  81250. typedef struct {
  81251. struct FLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81252. struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81253. } FLAC__StreamEncoder;
  81254. typedef FLAC__StreamEncoderReadStatus (*FLAC__StreamEncoderReadCallback)(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81255. typedef FLAC__StreamEncoderWriteStatus (*FLAC__StreamEncoderWriteCallback)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data);
  81256. typedef FLAC__StreamEncoderSeekStatus (*FLAC__StreamEncoderSeekCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81257. typedef FLAC__StreamEncoderTellStatus (*FLAC__StreamEncoderTellCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81258. typedef void (*FLAC__StreamEncoderMetadataCallback)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81259. 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);
  81260. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void);
  81261. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder);
  81262. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long serial_number);
  81263. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81264. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81265. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value);
  81266. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value);
  81267. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value);
  81268. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value);
  81269. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value);
  81270. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81271. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81272. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification);
  81273. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value);
  81274. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value);
  81275. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81276. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81277. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81278. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81279. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81280. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value);
  81281. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value);
  81282. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
  81283. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder);
  81284. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder);
  81285. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder);
  81286. 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);
  81287. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder);
  81288. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder);
  81289. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder);
  81290. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder);
  81291. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder);
  81292. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
  81293. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81294. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81295. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder);
  81296. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
  81297. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder);
  81298. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder);
  81299. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder);
  81300. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81301. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81302. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
  81303. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder);
  81304. 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);
  81305. 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);
  81306. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81307. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81308. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81309. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81310. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
  81311. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples);
  81312. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples);
  81313. #ifdef __cplusplus
  81314. }
  81315. #endif
  81316. #endif
  81317. /*** End of inlined file: stream_encoder.h ***/
  81318. #ifdef _MSC_VER
  81319. static _inline FLAC__uint32 local_swap32_(FLAC__uint32 x)
  81320. {
  81321. x = ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
  81322. return (x>>16) | (x<<16);
  81323. }
  81324. #endif
  81325. #if defined(_MSC_VER) && defined(_X86_)
  81326. static void local_swap32_block_(FLAC__uint32 *start, FLAC__uint32 len)
  81327. {
  81328. __asm {
  81329. mov edx, start
  81330. mov ecx, len
  81331. test ecx, ecx
  81332. loop1:
  81333. jz done1
  81334. mov eax, [edx]
  81335. bswap eax
  81336. mov [edx], eax
  81337. add edx, 4
  81338. dec ecx
  81339. jmp short loop1
  81340. done1:
  81341. }
  81342. }
  81343. #endif
  81344. #endif
  81345. /*** End of inlined file: all.h ***/
  81346. /*** Start of inlined file: bitmath.c ***/
  81347. /*** Start of inlined file: juce_FlacHeader.h ***/
  81348. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81349. // tasks..
  81350. #define VERSION "1.2.1"
  81351. #define FLAC__NO_DLL 1
  81352. #if JUCE_MSVC
  81353. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81354. #endif
  81355. #if JUCE_MAC
  81356. #define FLAC__SYS_DARWIN 1
  81357. #endif
  81358. /*** End of inlined file: juce_FlacHeader.h ***/
  81359. #if JUCE_USE_FLAC
  81360. #if HAVE_CONFIG_H
  81361. # include <config.h>
  81362. #endif
  81363. /*** Start of inlined file: bitmath.h ***/
  81364. #ifndef FLAC__PRIVATE__BITMATH_H
  81365. #define FLAC__PRIVATE__BITMATH_H
  81366. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v);
  81367. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v);
  81368. unsigned FLAC__bitmath_silog2(int v);
  81369. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v);
  81370. #endif
  81371. /*** End of inlined file: bitmath.h ***/
  81372. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v)
  81373. {
  81374. unsigned l = 0;
  81375. FLAC__ASSERT(v > 0);
  81376. while(v >>= 1)
  81377. l++;
  81378. return l;
  81379. }
  81380. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v)
  81381. {
  81382. unsigned l = 0;
  81383. FLAC__ASSERT(v > 0);
  81384. while(v >>= 1)
  81385. l++;
  81386. return l;
  81387. }
  81388. unsigned FLAC__bitmath_silog2(int v)
  81389. {
  81390. while(1) {
  81391. if(v == 0) {
  81392. return 0;
  81393. }
  81394. else if(v > 0) {
  81395. unsigned l = 0;
  81396. while(v) {
  81397. l++;
  81398. v >>= 1;
  81399. }
  81400. return l+1;
  81401. }
  81402. else if(v == -1) {
  81403. return 2;
  81404. }
  81405. else {
  81406. v++;
  81407. v = -v;
  81408. }
  81409. }
  81410. }
  81411. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v)
  81412. {
  81413. while(1) {
  81414. if(v == 0) {
  81415. return 0;
  81416. }
  81417. else if(v > 0) {
  81418. unsigned l = 0;
  81419. while(v) {
  81420. l++;
  81421. v >>= 1;
  81422. }
  81423. return l+1;
  81424. }
  81425. else if(v == -1) {
  81426. return 2;
  81427. }
  81428. else {
  81429. v++;
  81430. v = -v;
  81431. }
  81432. }
  81433. }
  81434. #endif
  81435. /*** End of inlined file: bitmath.c ***/
  81436. /*** Start of inlined file: bitreader.c ***/
  81437. /*** Start of inlined file: juce_FlacHeader.h ***/
  81438. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81439. // tasks..
  81440. #define VERSION "1.2.1"
  81441. #define FLAC__NO_DLL 1
  81442. #if JUCE_MSVC
  81443. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81444. #endif
  81445. #if JUCE_MAC
  81446. #define FLAC__SYS_DARWIN 1
  81447. #endif
  81448. /*** End of inlined file: juce_FlacHeader.h ***/
  81449. #if JUCE_USE_FLAC
  81450. #if HAVE_CONFIG_H
  81451. # include <config.h>
  81452. #endif
  81453. #include <stdlib.h> /* for malloc() */
  81454. #include <string.h> /* for memcpy(), memset() */
  81455. #ifdef _MSC_VER
  81456. #include <winsock.h> /* for ntohl() */
  81457. #elif defined FLAC__SYS_DARWIN
  81458. #include <machine/endian.h> /* for ntohl() */
  81459. #elif defined __MINGW32__
  81460. #include <winsock.h> /* for ntohl() */
  81461. #else
  81462. #include <netinet/in.h> /* for ntohl() */
  81463. #endif
  81464. /*** Start of inlined file: bitreader.h ***/
  81465. #ifndef FLAC__PRIVATE__BITREADER_H
  81466. #define FLAC__PRIVATE__BITREADER_H
  81467. #include <stdio.h> /* for FILE */
  81468. /*** Start of inlined file: cpu.h ***/
  81469. #ifndef FLAC__PRIVATE__CPU_H
  81470. #define FLAC__PRIVATE__CPU_H
  81471. #ifdef HAVE_CONFIG_H
  81472. #include <config.h>
  81473. #endif
  81474. typedef enum {
  81475. FLAC__CPUINFO_TYPE_IA32,
  81476. FLAC__CPUINFO_TYPE_PPC,
  81477. FLAC__CPUINFO_TYPE_UNKNOWN
  81478. } FLAC__CPUInfo_Type;
  81479. typedef struct {
  81480. FLAC__bool cpuid;
  81481. FLAC__bool bswap;
  81482. FLAC__bool cmov;
  81483. FLAC__bool mmx;
  81484. FLAC__bool fxsr;
  81485. FLAC__bool sse;
  81486. FLAC__bool sse2;
  81487. FLAC__bool sse3;
  81488. FLAC__bool ssse3;
  81489. FLAC__bool _3dnow;
  81490. FLAC__bool ext3dnow;
  81491. FLAC__bool extmmx;
  81492. } FLAC__CPUInfo_IA32;
  81493. typedef struct {
  81494. FLAC__bool altivec;
  81495. FLAC__bool ppc64;
  81496. } FLAC__CPUInfo_PPC;
  81497. typedef struct {
  81498. FLAC__bool use_asm;
  81499. FLAC__CPUInfo_Type type;
  81500. union {
  81501. FLAC__CPUInfo_IA32 ia32;
  81502. FLAC__CPUInfo_PPC ppc;
  81503. } data;
  81504. } FLAC__CPUInfo;
  81505. void FLAC__cpu_info(FLAC__CPUInfo *info);
  81506. #ifndef FLAC__NO_ASM
  81507. #ifdef FLAC__CPU_IA32
  81508. #ifdef FLAC__HAS_NASM
  81509. FLAC__uint32 FLAC__cpu_have_cpuid_asm_ia32(void);
  81510. void FLAC__cpu_info_asm_ia32(FLAC__uint32 *flags_edx, FLAC__uint32 *flags_ecx);
  81511. FLAC__uint32 FLAC__cpu_info_extended_amd_asm_ia32(void);
  81512. #endif
  81513. #endif
  81514. #endif
  81515. #endif
  81516. /*** End of inlined file: cpu.h ***/
  81517. struct FLAC__BitReader;
  81518. typedef struct FLAC__BitReader FLAC__BitReader;
  81519. typedef FLAC__bool (*FLAC__BitReaderReadCallback)(FLAC__byte buffer[], size_t *bytes, void *client_data);
  81520. FLAC__BitReader *FLAC__bitreader_new(void);
  81521. void FLAC__bitreader_delete(FLAC__BitReader *br);
  81522. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd);
  81523. void FLAC__bitreader_free(FLAC__BitReader *br); /* does not 'free(br)' */
  81524. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br);
  81525. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out);
  81526. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed);
  81527. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br);
  81528. FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br);
  81529. unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br);
  81530. unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br);
  81531. FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits);
  81532. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits);
  81533. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits);
  81534. FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val); /*only for bits=32*/
  81535. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits); /* WATCHOUT: does not CRC the skipped data! */ /*@@@@ add to unit tests */
  81536. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals); /* WATCHOUT: does not CRC the read data! */
  81537. 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! */
  81538. FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val);
  81539. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  81540. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  81541. #ifndef FLAC__NO_ASM
  81542. # ifdef FLAC__CPU_IA32
  81543. # ifdef FLAC__HAS_NASM
  81544. FLAC__bool FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  81545. # endif
  81546. # endif
  81547. #endif
  81548. #if 0 /* UNUSED */
  81549. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  81550. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter);
  81551. #endif
  81552. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen);
  81553. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen);
  81554. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br);
  81555. #endif
  81556. /*** End of inlined file: bitreader.h ***/
  81557. /*** Start of inlined file: crc.h ***/
  81558. #ifndef FLAC__PRIVATE__CRC_H
  81559. #define FLAC__PRIVATE__CRC_H
  81560. extern FLAC__byte const FLAC__crc8_table[256];
  81561. #define FLAC__CRC8_UPDATE(data, crc) (crc) = FLAC__crc8_table[(crc) ^ (data)];
  81562. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc);
  81563. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc);
  81564. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len);
  81565. extern unsigned FLAC__crc16_table[256];
  81566. #define FLAC__CRC16_UPDATE(data, crc) (((((crc)<<8) & 0xffff) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]))
  81567. #if 0
  81568. #define FLAC__CRC16_UPDATE(data, crc) ((((crc)<<8) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]) & 0xffff)
  81569. #endif
  81570. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len);
  81571. #endif
  81572. /*** End of inlined file: crc.h ***/
  81573. typedef FLAC__uint32 brword;
  81574. #define FLAC__BYTES_PER_WORD 4
  81575. #define FLAC__BITS_PER_WORD 32
  81576. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  81577. #if WORDS_BIGENDIAN
  81578. #define SWAP_BE_WORD_TO_HOST(x) (x)
  81579. #else
  81580. #if defined (_MSC_VER) && defined (_X86_)
  81581. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  81582. #else
  81583. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  81584. #endif
  81585. #endif
  81586. #define COUNT_ZERO_MSBS(word) ( \
  81587. (word) <= 0xffff ? \
  81588. ( (word) <= 0xff? byte_to_unary_table[word] + 24 : byte_to_unary_table[(word) >> 8] + 16 ) : \
  81589. ( (word) <= 0xffffff? byte_to_unary_table[word >> 16] + 8 : byte_to_unary_table[(word) >> 24] ) \
  81590. )
  81591. #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])) )
  81592. static const unsigned FLAC__BITREADER_DEFAULT_CAPACITY = 65536u / FLAC__BITS_PER_WORD; /* in words */
  81593. static const unsigned char byte_to_unary_table[] = {
  81594. 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
  81595. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  81596. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  81597. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  81598. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81599. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81600. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81601. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  81610. };
  81611. #ifdef min
  81612. #undef min
  81613. #endif
  81614. #define min(x,y) ((x)<(y)?(x):(y))
  81615. #ifdef max
  81616. #undef max
  81617. #endif
  81618. #define max(x,y) ((x)>(y)?(x):(y))
  81619. #ifdef _MSC_VER
  81620. #define FLAC__U64L(x) x
  81621. #else
  81622. #define FLAC__U64L(x) x##LLU
  81623. #endif
  81624. #ifndef FLaC__INLINE
  81625. #define FLaC__INLINE
  81626. #endif
  81627. struct FLAC__BitReader {
  81628. brword *buffer;
  81629. unsigned capacity; /* in words */
  81630. unsigned words; /* # of completed words in buffer */
  81631. unsigned bytes; /* # of bytes in incomplete word at buffer[words] */
  81632. unsigned consumed_words; /* #words ... */
  81633. unsigned consumed_bits; /* ... + (#bits of head word) already consumed from the front of buffer */
  81634. unsigned read_crc16; /* the running frame CRC */
  81635. unsigned crc16_align; /* the number of bits in the current consumed word that should not be CRC'd */
  81636. FLAC__BitReaderReadCallback read_callback;
  81637. void *client_data;
  81638. FLAC__CPUInfo cpu_info;
  81639. };
  81640. static FLaC__INLINE void crc16_update_word_(FLAC__BitReader *br, brword word)
  81641. {
  81642. register unsigned crc = br->read_crc16;
  81643. #if FLAC__BYTES_PER_WORD == 4
  81644. switch(br->crc16_align) {
  81645. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 24), crc);
  81646. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  81647. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  81648. case 24: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  81649. }
  81650. #elif FLAC__BYTES_PER_WORD == 8
  81651. switch(br->crc16_align) {
  81652. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 56), crc);
  81653. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 48) & 0xff), crc);
  81654. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 40) & 0xff), crc);
  81655. case 24: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 32) & 0xff), crc);
  81656. case 32: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 24) & 0xff), crc);
  81657. case 40: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  81658. case 48: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  81659. case 56: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  81660. }
  81661. #else
  81662. for( ; br->crc16_align < FLAC__BITS_PER_WORD; br->crc16_align += 8)
  81663. crc = FLAC__CRC16_UPDATE((unsigned)((word >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), crc);
  81664. br->read_crc16 = crc;
  81665. #endif
  81666. br->crc16_align = 0;
  81667. }
  81668. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br)
  81669. {
  81670. unsigned start, end;
  81671. size_t bytes;
  81672. FLAC__byte *target;
  81673. if(br->consumed_words > 0) {
  81674. start = br->consumed_words;
  81675. end = br->words + (br->bytes? 1:0);
  81676. memmove(br->buffer, br->buffer+start, FLAC__BYTES_PER_WORD * (end - start));
  81677. br->words -= start;
  81678. br->consumed_words = 0;
  81679. }
  81680. bytes = (br->capacity - br->words) * FLAC__BYTES_PER_WORD - br->bytes;
  81681. if(bytes == 0)
  81682. return false; /* no space left, buffer is too small; see note for FLAC__BITREADER_DEFAULT_CAPACITY */
  81683. target = ((FLAC__byte*)(br->buffer+br->words)) + br->bytes;
  81684. #if WORDS_BIGENDIAN
  81685. #else
  81686. if(br->bytes)
  81687. br->buffer[br->words] = SWAP_BE_WORD_TO_HOST(br->buffer[br->words]);
  81688. #endif
  81689. if(!br->read_callback(target, &bytes, br->client_data))
  81690. return false;
  81691. #if WORDS_BIGENDIAN
  81692. #else
  81693. end = (br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes + (FLAC__BYTES_PER_WORD-1)) / FLAC__BYTES_PER_WORD;
  81694. # if defined(_MSC_VER) && defined (_X86_) && (FLAC__BYTES_PER_WORD == 4)
  81695. if(br->cpu_info.type == FLAC__CPUINFO_TYPE_IA32 && br->cpu_info.data.ia32.bswap) {
  81696. start = br->words;
  81697. local_swap32_block_(br->buffer + start, end - start);
  81698. }
  81699. else
  81700. # endif
  81701. for(start = br->words; start < end; start++)
  81702. br->buffer[start] = SWAP_BE_WORD_TO_HOST(br->buffer[start]);
  81703. #endif
  81704. end = br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes;
  81705. br->words = end / FLAC__BYTES_PER_WORD;
  81706. br->bytes = end % FLAC__BYTES_PER_WORD;
  81707. return true;
  81708. }
  81709. FLAC__BitReader *FLAC__bitreader_new(void)
  81710. {
  81711. FLAC__BitReader *br = (FLAC__BitReader*)calloc(1, sizeof(FLAC__BitReader));
  81712. return br;
  81713. }
  81714. void FLAC__bitreader_delete(FLAC__BitReader *br)
  81715. {
  81716. FLAC__ASSERT(0 != br);
  81717. FLAC__bitreader_free(br);
  81718. free(br);
  81719. }
  81720. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd)
  81721. {
  81722. FLAC__ASSERT(0 != br);
  81723. br->words = br->bytes = 0;
  81724. br->consumed_words = br->consumed_bits = 0;
  81725. br->capacity = FLAC__BITREADER_DEFAULT_CAPACITY;
  81726. br->buffer = (brword*)malloc(sizeof(brword) * br->capacity);
  81727. if(br->buffer == 0)
  81728. return false;
  81729. br->read_callback = rcb;
  81730. br->client_data = cd;
  81731. br->cpu_info = cpu;
  81732. return true;
  81733. }
  81734. void FLAC__bitreader_free(FLAC__BitReader *br)
  81735. {
  81736. FLAC__ASSERT(0 != br);
  81737. if(0 != br->buffer)
  81738. free(br->buffer);
  81739. br->buffer = 0;
  81740. br->capacity = 0;
  81741. br->words = br->bytes = 0;
  81742. br->consumed_words = br->consumed_bits = 0;
  81743. br->read_callback = 0;
  81744. br->client_data = 0;
  81745. }
  81746. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br)
  81747. {
  81748. br->words = br->bytes = 0;
  81749. br->consumed_words = br->consumed_bits = 0;
  81750. return true;
  81751. }
  81752. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out)
  81753. {
  81754. unsigned i, j;
  81755. if(br == 0) {
  81756. fprintf(out, "bitreader is NULL\n");
  81757. }
  81758. else {
  81759. 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);
  81760. for(i = 0; i < br->words; i++) {
  81761. fprintf(out, "%08X: ", i);
  81762. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  81763. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  81764. fprintf(out, ".");
  81765. else
  81766. fprintf(out, "%01u", br->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  81767. fprintf(out, "\n");
  81768. }
  81769. if(br->bytes > 0) {
  81770. fprintf(out, "%08X: ", i);
  81771. for(j = 0; j < br->bytes*8; j++)
  81772. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  81773. fprintf(out, ".");
  81774. else
  81775. fprintf(out, "%01u", br->buffer[i] & (1 << (br->bytes*8-j-1)) ? 1:0);
  81776. fprintf(out, "\n");
  81777. }
  81778. }
  81779. }
  81780. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed)
  81781. {
  81782. FLAC__ASSERT(0 != br);
  81783. FLAC__ASSERT(0 != br->buffer);
  81784. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  81785. br->read_crc16 = (unsigned)seed;
  81786. br->crc16_align = br->consumed_bits;
  81787. }
  81788. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br)
  81789. {
  81790. FLAC__ASSERT(0 != br);
  81791. FLAC__ASSERT(0 != br->buffer);
  81792. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  81793. FLAC__ASSERT(br->crc16_align <= br->consumed_bits);
  81794. if(br->consumed_bits) {
  81795. const brword tail = br->buffer[br->consumed_words];
  81796. for( ; br->crc16_align < br->consumed_bits; br->crc16_align += 8)
  81797. br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)((tail >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), br->read_crc16);
  81798. }
  81799. return br->read_crc16;
  81800. }
  81801. FLaC__INLINE FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br)
  81802. {
  81803. return ((br->consumed_bits & 7) == 0);
  81804. }
  81805. FLaC__INLINE unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br)
  81806. {
  81807. return 8 - (br->consumed_bits & 7);
  81808. }
  81809. FLaC__INLINE unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br)
  81810. {
  81811. return (br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits;
  81812. }
  81813. FLaC__INLINE FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits)
  81814. {
  81815. FLAC__ASSERT(0 != br);
  81816. FLAC__ASSERT(0 != br->buffer);
  81817. FLAC__ASSERT(bits <= 32);
  81818. FLAC__ASSERT((br->capacity*FLAC__BITS_PER_WORD) * 2 >= bits);
  81819. FLAC__ASSERT(br->consumed_words <= br->words);
  81820. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  81821. if(bits == 0) { /* OPT: investigate if this can ever happen, maybe change to assertion */
  81822. *val = 0;
  81823. return true;
  81824. }
  81825. while((br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits < bits) {
  81826. if(!bitreader_read_from_client_(br))
  81827. return false;
  81828. }
  81829. if(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  81830. if(br->consumed_bits) {
  81831. const unsigned n = FLAC__BITS_PER_WORD - br->consumed_bits;
  81832. const brword word = br->buffer[br->consumed_words];
  81833. if(bits < n) {
  81834. *val = (word & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (n-bits);
  81835. br->consumed_bits += bits;
  81836. return true;
  81837. }
  81838. *val = word & (FLAC__WORD_ALL_ONES >> br->consumed_bits);
  81839. bits -= n;
  81840. crc16_update_word_(br, word);
  81841. br->consumed_words++;
  81842. br->consumed_bits = 0;
  81843. 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 */
  81844. *val <<= bits;
  81845. *val |= (br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits));
  81846. br->consumed_bits = bits;
  81847. }
  81848. return true;
  81849. }
  81850. else {
  81851. const brword word = br->buffer[br->consumed_words];
  81852. if(bits < FLAC__BITS_PER_WORD) {
  81853. *val = word >> (FLAC__BITS_PER_WORD-bits);
  81854. br->consumed_bits = bits;
  81855. return true;
  81856. }
  81857. *val = word;
  81858. crc16_update_word_(br, word);
  81859. br->consumed_words++;
  81860. return true;
  81861. }
  81862. }
  81863. else {
  81864. if(br->consumed_bits) {
  81865. FLAC__ASSERT(br->consumed_bits + bits <= br->bytes*8);
  81866. *val = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (FLAC__BITS_PER_WORD-br->consumed_bits-bits);
  81867. br->consumed_bits += bits;
  81868. return true;
  81869. }
  81870. else {
  81871. *val = br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits);
  81872. br->consumed_bits += bits;
  81873. return true;
  81874. }
  81875. }
  81876. }
  81877. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits)
  81878. {
  81879. if(!FLAC__bitreader_read_raw_uint32(br, (FLAC__uint32*)val, bits))
  81880. return false;
  81881. *val <<= (32-bits);
  81882. *val >>= (32-bits);
  81883. return true;
  81884. }
  81885. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits)
  81886. {
  81887. FLAC__uint32 hi, lo;
  81888. if(bits > 32) {
  81889. if(!FLAC__bitreader_read_raw_uint32(br, &hi, bits-32))
  81890. return false;
  81891. if(!FLAC__bitreader_read_raw_uint32(br, &lo, 32))
  81892. return false;
  81893. *val = hi;
  81894. *val <<= 32;
  81895. *val |= lo;
  81896. }
  81897. else {
  81898. if(!FLAC__bitreader_read_raw_uint32(br, &lo, bits))
  81899. return false;
  81900. *val = lo;
  81901. }
  81902. return true;
  81903. }
  81904. FLaC__INLINE FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val)
  81905. {
  81906. FLAC__uint32 x8, x32 = 0;
  81907. if(!FLAC__bitreader_read_raw_uint32(br, &x32, 8))
  81908. return false;
  81909. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  81910. return false;
  81911. x32 |= (x8 << 8);
  81912. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  81913. return false;
  81914. x32 |= (x8 << 16);
  81915. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  81916. return false;
  81917. x32 |= (x8 << 24);
  81918. *val = x32;
  81919. return true;
  81920. }
  81921. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits)
  81922. {
  81923. FLAC__ASSERT(0 != br);
  81924. FLAC__ASSERT(0 != br->buffer);
  81925. if(bits > 0) {
  81926. const unsigned n = br->consumed_bits & 7;
  81927. unsigned m;
  81928. FLAC__uint32 x;
  81929. if(n != 0) {
  81930. m = min(8-n, bits);
  81931. if(!FLAC__bitreader_read_raw_uint32(br, &x, m))
  81932. return false;
  81933. bits -= m;
  81934. }
  81935. m = bits / 8;
  81936. if(m > 0) {
  81937. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(br, m))
  81938. return false;
  81939. bits %= 8;
  81940. }
  81941. if(bits > 0) {
  81942. if(!FLAC__bitreader_read_raw_uint32(br, &x, bits))
  81943. return false;
  81944. }
  81945. }
  81946. return true;
  81947. }
  81948. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals)
  81949. {
  81950. FLAC__uint32 x;
  81951. FLAC__ASSERT(0 != br);
  81952. FLAC__ASSERT(0 != br->buffer);
  81953. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  81954. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  81955. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  81956. return false;
  81957. nvals--;
  81958. }
  81959. if(0 == nvals)
  81960. return true;
  81961. while(nvals >= FLAC__BYTES_PER_WORD) {
  81962. if(br->consumed_words < br->words) {
  81963. br->consumed_words++;
  81964. nvals -= FLAC__BYTES_PER_WORD;
  81965. }
  81966. else if(!bitreader_read_from_client_(br))
  81967. return false;
  81968. }
  81969. while(nvals) {
  81970. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  81971. return false;
  81972. nvals--;
  81973. }
  81974. return true;
  81975. }
  81976. FLAC__bool FLAC__bitreader_read_byte_block_aligned_no_crc(FLAC__BitReader *br, FLAC__byte *val, unsigned nvals)
  81977. {
  81978. FLAC__uint32 x;
  81979. FLAC__ASSERT(0 != br);
  81980. FLAC__ASSERT(0 != br->buffer);
  81981. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  81982. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  81983. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  81984. return false;
  81985. *val++ = (FLAC__byte)x;
  81986. nvals--;
  81987. }
  81988. if(0 == nvals)
  81989. return true;
  81990. while(nvals >= FLAC__BYTES_PER_WORD) {
  81991. if(br->consumed_words < br->words) {
  81992. const brword word = br->buffer[br->consumed_words++];
  81993. #if FLAC__BYTES_PER_WORD == 4
  81994. val[0] = (FLAC__byte)(word >> 24);
  81995. val[1] = (FLAC__byte)(word >> 16);
  81996. val[2] = (FLAC__byte)(word >> 8);
  81997. val[3] = (FLAC__byte)word;
  81998. #elif FLAC__BYTES_PER_WORD == 8
  81999. val[0] = (FLAC__byte)(word >> 56);
  82000. val[1] = (FLAC__byte)(word >> 48);
  82001. val[2] = (FLAC__byte)(word >> 40);
  82002. val[3] = (FLAC__byte)(word >> 32);
  82003. val[4] = (FLAC__byte)(word >> 24);
  82004. val[5] = (FLAC__byte)(word >> 16);
  82005. val[6] = (FLAC__byte)(word >> 8);
  82006. val[7] = (FLAC__byte)word;
  82007. #else
  82008. for(x = 0; x < FLAC__BYTES_PER_WORD; x++)
  82009. val[x] = (FLAC__byte)(word >> (8*(FLAC__BYTES_PER_WORD-x-1)));
  82010. #endif
  82011. val += FLAC__BYTES_PER_WORD;
  82012. nvals -= FLAC__BYTES_PER_WORD;
  82013. }
  82014. else if(!bitreader_read_from_client_(br))
  82015. return false;
  82016. }
  82017. while(nvals) {
  82018. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82019. return false;
  82020. *val++ = (FLAC__byte)x;
  82021. nvals--;
  82022. }
  82023. return true;
  82024. }
  82025. FLaC__INLINE FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val)
  82026. #if 0 /* slow but readable version */
  82027. {
  82028. unsigned bit;
  82029. FLAC__ASSERT(0 != br);
  82030. FLAC__ASSERT(0 != br->buffer);
  82031. *val = 0;
  82032. while(1) {
  82033. if(!FLAC__bitreader_read_bit(br, &bit))
  82034. return false;
  82035. if(bit)
  82036. break;
  82037. else
  82038. *val++;
  82039. }
  82040. return true;
  82041. }
  82042. #else
  82043. {
  82044. unsigned i;
  82045. FLAC__ASSERT(0 != br);
  82046. FLAC__ASSERT(0 != br->buffer);
  82047. *val = 0;
  82048. while(1) {
  82049. while(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  82050. brword b = br->buffer[br->consumed_words] << br->consumed_bits;
  82051. if(b) {
  82052. i = COUNT_ZERO_MSBS(b);
  82053. *val += i;
  82054. i++;
  82055. br->consumed_bits += i;
  82056. if(br->consumed_bits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(br->consumed_bits == FLAC__BITS_PER_WORD) */
  82057. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82058. br->consumed_words++;
  82059. br->consumed_bits = 0;
  82060. }
  82061. return true;
  82062. }
  82063. else {
  82064. *val += FLAC__BITS_PER_WORD - br->consumed_bits;
  82065. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82066. br->consumed_words++;
  82067. br->consumed_bits = 0;
  82068. }
  82069. }
  82070. if(br->bytes) {
  82071. const unsigned end = br->bytes * 8;
  82072. brword b = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << br->consumed_bits;
  82073. if(b) {
  82074. i = COUNT_ZERO_MSBS(b);
  82075. *val += i;
  82076. i++;
  82077. br->consumed_bits += i;
  82078. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82079. return true;
  82080. }
  82081. else {
  82082. *val += end - br->consumed_bits;
  82083. br->consumed_bits += end;
  82084. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82085. }
  82086. }
  82087. if(!bitreader_read_from_client_(br))
  82088. return false;
  82089. }
  82090. }
  82091. #endif
  82092. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82093. {
  82094. FLAC__uint32 lsbs = 0, msbs = 0;
  82095. unsigned uval;
  82096. FLAC__ASSERT(0 != br);
  82097. FLAC__ASSERT(0 != br->buffer);
  82098. FLAC__ASSERT(parameter <= 31);
  82099. if(!FLAC__bitreader_read_unary_unsigned(br, (unsigned int*) &msbs))
  82100. return false;
  82101. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, parameter))
  82102. return false;
  82103. uval = (msbs << parameter) | lsbs;
  82104. if(uval & 1)
  82105. *val = -((int)(uval >> 1)) - 1;
  82106. else
  82107. *val = (int)(uval >> 1);
  82108. return true;
  82109. }
  82110. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter)
  82111. #ifdef _MSC_VER
  82112. {
  82113. unsigned i;
  82114. unsigned uval = 0;
  82115. unsigned bits; /* the # of binary LSBs left to read to finish a rice codeword */
  82116. register unsigned cwords;
  82117. register unsigned cbits;
  82118. FLAC__ASSERT(0 != br);
  82119. FLAC__ASSERT(0 != br->buffer);
  82120. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82121. FLAC__ASSERT(parameter < 32);
  82122. if(nvals == 0)
  82123. return true;
  82124. cbits = br->consumed_bits;
  82125. cwords = br->consumed_words;
  82126. while(1) {
  82127. while(1) {
  82128. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82129. brword b = br->buffer[cwords] << cbits;
  82130. if(b) {
  82131. #if 0 /* slower, probably due to bad register allocation... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32
  82132. __asm {
  82133. bsr eax, b
  82134. not eax
  82135. and eax, 31
  82136. mov i, eax
  82137. }
  82138. #else
  82139. i = COUNT_ZERO_MSBS(b);
  82140. #endif
  82141. uval += i;
  82142. bits = parameter;
  82143. i++;
  82144. cbits += i;
  82145. if(cbits == FLAC__BITS_PER_WORD) {
  82146. crc16_update_word_(br, br->buffer[cwords]);
  82147. cwords++;
  82148. cbits = 0;
  82149. }
  82150. goto break1;
  82151. }
  82152. else {
  82153. uval += FLAC__BITS_PER_WORD - cbits;
  82154. crc16_update_word_(br, br->buffer[cwords]);
  82155. cwords++;
  82156. cbits = 0;
  82157. }
  82158. }
  82159. if(br->bytes) {
  82160. const unsigned end = br->bytes * 8;
  82161. brword b = (br->buffer[cwords] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << cbits;
  82162. if(b) {
  82163. i = COUNT_ZERO_MSBS(b);
  82164. uval += i;
  82165. bits = parameter;
  82166. i++;
  82167. cbits += i;
  82168. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82169. goto break1;
  82170. }
  82171. else {
  82172. uval += end - cbits;
  82173. cbits += end;
  82174. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82175. }
  82176. }
  82177. br->consumed_bits = cbits;
  82178. br->consumed_words = cwords;
  82179. if(!bitreader_read_from_client_(br))
  82180. return false;
  82181. cwords = br->consumed_words;
  82182. }
  82183. break1:
  82184. FLAC__ASSERT(cwords <= br->words);
  82185. if(bits) {
  82186. while((br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits < bits) {
  82187. br->consumed_bits = cbits;
  82188. br->consumed_words = cwords;
  82189. if(!bitreader_read_from_client_(br))
  82190. return false;
  82191. cwords = br->consumed_words;
  82192. }
  82193. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82194. if(cbits) {
  82195. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82196. const brword word = br->buffer[cwords];
  82197. if(bits < n) {
  82198. uval <<= bits;
  82199. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-bits);
  82200. cbits += bits;
  82201. goto break2;
  82202. }
  82203. uval <<= n;
  82204. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82205. bits -= n;
  82206. crc16_update_word_(br, word);
  82207. cwords++;
  82208. cbits = 0;
  82209. 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 */
  82210. uval <<= bits;
  82211. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits));
  82212. cbits = bits;
  82213. }
  82214. goto break2;
  82215. }
  82216. else {
  82217. FLAC__ASSERT(bits < FLAC__BITS_PER_WORD);
  82218. uval <<= bits;
  82219. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82220. cbits = bits;
  82221. goto break2;
  82222. }
  82223. }
  82224. else {
  82225. uval <<= bits;
  82226. if(cbits) {
  82227. FLAC__ASSERT(cbits + bits <= br->bytes*8);
  82228. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-bits);
  82229. cbits += bits;
  82230. goto break2;
  82231. }
  82232. else {
  82233. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82234. cbits += bits;
  82235. goto break2;
  82236. }
  82237. }
  82238. }
  82239. break2:
  82240. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82241. --nvals;
  82242. if(nvals == 0) {
  82243. br->consumed_bits = cbits;
  82244. br->consumed_words = cwords;
  82245. return true;
  82246. }
  82247. uval = 0;
  82248. ++vals;
  82249. }
  82250. }
  82251. #else
  82252. {
  82253. unsigned i;
  82254. unsigned uval = 0;
  82255. register unsigned cwords;
  82256. register unsigned cbits;
  82257. unsigned ucbits; /* keep track of the number of unconsumed bits in the buffer */
  82258. FLAC__ASSERT(0 != br);
  82259. FLAC__ASSERT(0 != br->buffer);
  82260. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82261. FLAC__ASSERT(parameter < 32);
  82262. if(nvals == 0)
  82263. return true;
  82264. cbits = br->consumed_bits;
  82265. cwords = br->consumed_words;
  82266. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82267. while(1) {
  82268. while(1) {
  82269. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82270. brword b = br->buffer[cwords] << cbits;
  82271. if(b) {
  82272. #if 0 /* is not discernably faster... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32 && defined __GNUC__
  82273. asm volatile (
  82274. "bsrl %1, %0;"
  82275. "notl %0;"
  82276. "andl $31, %0;"
  82277. : "=r"(i)
  82278. : "r"(b)
  82279. );
  82280. #else
  82281. i = COUNT_ZERO_MSBS(b);
  82282. #endif
  82283. uval += i;
  82284. cbits += i;
  82285. cbits++; /* skip over stop bit */
  82286. if(cbits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(cbits == FLAC__BITS_PER_WORD) */
  82287. crc16_update_word_(br, br->buffer[cwords]);
  82288. cwords++;
  82289. cbits = 0;
  82290. }
  82291. goto break1;
  82292. }
  82293. else {
  82294. uval += FLAC__BITS_PER_WORD - cbits;
  82295. crc16_update_word_(br, br->buffer[cwords]);
  82296. cwords++;
  82297. cbits = 0;
  82298. }
  82299. }
  82300. if(br->bytes) {
  82301. const unsigned end = br->bytes * 8;
  82302. brword b = (br->buffer[cwords] & ~(FLAC__WORD_ALL_ONES >> end)) << cbits;
  82303. if(b) {
  82304. i = COUNT_ZERO_MSBS(b);
  82305. uval += i;
  82306. cbits += i;
  82307. cbits++; /* skip over stop bit */
  82308. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82309. goto break1;
  82310. }
  82311. else {
  82312. uval += end - cbits;
  82313. cbits += end;
  82314. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82315. }
  82316. }
  82317. br->consumed_bits = cbits;
  82318. br->consumed_words = cwords;
  82319. if(!bitreader_read_from_client_(br))
  82320. return false;
  82321. cwords = br->consumed_words;
  82322. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits + uval;
  82323. }
  82324. break1:
  82325. ucbits -= uval;
  82326. ucbits--; /* account for stop bit */
  82327. FLAC__ASSERT(cwords <= br->words);
  82328. if(parameter) {
  82329. while(ucbits < parameter) {
  82330. br->consumed_bits = cbits;
  82331. br->consumed_words = cwords;
  82332. if(!bitreader_read_from_client_(br))
  82333. return false;
  82334. cwords = br->consumed_words;
  82335. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82336. }
  82337. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82338. if(cbits) {
  82339. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82340. const brword word = br->buffer[cwords];
  82341. if(parameter < n) {
  82342. uval <<= parameter;
  82343. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-parameter);
  82344. cbits += parameter;
  82345. }
  82346. else {
  82347. uval <<= n;
  82348. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82349. crc16_update_word_(br, word);
  82350. cwords++;
  82351. cbits = parameter - n;
  82352. 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 */
  82353. uval <<= cbits;
  82354. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits));
  82355. }
  82356. }
  82357. }
  82358. else {
  82359. cbits = parameter;
  82360. uval <<= parameter;
  82361. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82362. }
  82363. }
  82364. else {
  82365. uval <<= parameter;
  82366. if(cbits) {
  82367. FLAC__ASSERT(cbits + parameter <= br->bytes*8);
  82368. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-parameter);
  82369. cbits += parameter;
  82370. }
  82371. else {
  82372. cbits = parameter;
  82373. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82374. }
  82375. }
  82376. }
  82377. ucbits -= parameter;
  82378. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82379. --nvals;
  82380. if(nvals == 0) {
  82381. br->consumed_bits = cbits;
  82382. br->consumed_words = cwords;
  82383. return true;
  82384. }
  82385. uval = 0;
  82386. ++vals;
  82387. }
  82388. }
  82389. #endif
  82390. #if 0 /* UNUSED */
  82391. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82392. {
  82393. FLAC__uint32 lsbs = 0, msbs = 0;
  82394. unsigned bit, uval, k;
  82395. FLAC__ASSERT(0 != br);
  82396. FLAC__ASSERT(0 != br->buffer);
  82397. k = FLAC__bitmath_ilog2(parameter);
  82398. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82399. return false;
  82400. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82401. return false;
  82402. if(parameter == 1u<<k) {
  82403. uval = (msbs << k) | lsbs;
  82404. }
  82405. else {
  82406. unsigned d = (1 << (k+1)) - parameter;
  82407. if(lsbs >= d) {
  82408. if(!FLAC__bitreader_read_bit(br, &bit))
  82409. return false;
  82410. lsbs <<= 1;
  82411. lsbs |= bit;
  82412. lsbs -= d;
  82413. }
  82414. uval = msbs * parameter + lsbs;
  82415. }
  82416. if(uval & 1)
  82417. *val = -((int)(uval >> 1)) - 1;
  82418. else
  82419. *val = (int)(uval >> 1);
  82420. return true;
  82421. }
  82422. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter)
  82423. {
  82424. FLAC__uint32 lsbs, msbs = 0;
  82425. unsigned bit, k;
  82426. FLAC__ASSERT(0 != br);
  82427. FLAC__ASSERT(0 != br->buffer);
  82428. k = FLAC__bitmath_ilog2(parameter);
  82429. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82430. return false;
  82431. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82432. return false;
  82433. if(parameter == 1u<<k) {
  82434. *val = (msbs << k) | lsbs;
  82435. }
  82436. else {
  82437. unsigned d = (1 << (k+1)) - parameter;
  82438. if(lsbs >= d) {
  82439. if(!FLAC__bitreader_read_bit(br, &bit))
  82440. return false;
  82441. lsbs <<= 1;
  82442. lsbs |= bit;
  82443. lsbs -= d;
  82444. }
  82445. *val = msbs * parameter + lsbs;
  82446. }
  82447. return true;
  82448. }
  82449. #endif /* UNUSED */
  82450. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen)
  82451. {
  82452. FLAC__uint32 v = 0;
  82453. FLAC__uint32 x;
  82454. unsigned i;
  82455. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82456. return false;
  82457. if(raw)
  82458. raw[(*rawlen)++] = (FLAC__byte)x;
  82459. if(!(x & 0x80)) { /* 0xxxxxxx */
  82460. v = x;
  82461. i = 0;
  82462. }
  82463. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82464. v = x & 0x1F;
  82465. i = 1;
  82466. }
  82467. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82468. v = x & 0x0F;
  82469. i = 2;
  82470. }
  82471. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82472. v = x & 0x07;
  82473. i = 3;
  82474. }
  82475. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82476. v = x & 0x03;
  82477. i = 4;
  82478. }
  82479. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82480. v = x & 0x01;
  82481. i = 5;
  82482. }
  82483. else {
  82484. *val = 0xffffffff;
  82485. return true;
  82486. }
  82487. for( ; i; i--) {
  82488. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82489. return false;
  82490. if(raw)
  82491. raw[(*rawlen)++] = (FLAC__byte)x;
  82492. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82493. *val = 0xffffffff;
  82494. return true;
  82495. }
  82496. v <<= 6;
  82497. v |= (x & 0x3F);
  82498. }
  82499. *val = v;
  82500. return true;
  82501. }
  82502. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen)
  82503. {
  82504. FLAC__uint64 v = 0;
  82505. FLAC__uint32 x;
  82506. unsigned i;
  82507. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82508. return false;
  82509. if(raw)
  82510. raw[(*rawlen)++] = (FLAC__byte)x;
  82511. if(!(x & 0x80)) { /* 0xxxxxxx */
  82512. v = x;
  82513. i = 0;
  82514. }
  82515. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82516. v = x & 0x1F;
  82517. i = 1;
  82518. }
  82519. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82520. v = x & 0x0F;
  82521. i = 2;
  82522. }
  82523. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82524. v = x & 0x07;
  82525. i = 3;
  82526. }
  82527. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82528. v = x & 0x03;
  82529. i = 4;
  82530. }
  82531. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82532. v = x & 0x01;
  82533. i = 5;
  82534. }
  82535. else if(x & 0xFE && !(x & 0x01)) { /* 11111110 */
  82536. v = 0;
  82537. i = 6;
  82538. }
  82539. else {
  82540. *val = FLAC__U64L(0xffffffffffffffff);
  82541. return true;
  82542. }
  82543. for( ; i; i--) {
  82544. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82545. return false;
  82546. if(raw)
  82547. raw[(*rawlen)++] = (FLAC__byte)x;
  82548. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82549. *val = FLAC__U64L(0xffffffffffffffff);
  82550. return true;
  82551. }
  82552. v <<= 6;
  82553. v |= (x & 0x3F);
  82554. }
  82555. *val = v;
  82556. return true;
  82557. }
  82558. #endif
  82559. /*** End of inlined file: bitreader.c ***/
  82560. /*** Start of inlined file: bitwriter.c ***/
  82561. /*** Start of inlined file: juce_FlacHeader.h ***/
  82562. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  82563. // tasks..
  82564. #define VERSION "1.2.1"
  82565. #define FLAC__NO_DLL 1
  82566. #if JUCE_MSVC
  82567. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  82568. #endif
  82569. #if JUCE_MAC
  82570. #define FLAC__SYS_DARWIN 1
  82571. #endif
  82572. /*** End of inlined file: juce_FlacHeader.h ***/
  82573. #if JUCE_USE_FLAC
  82574. #if HAVE_CONFIG_H
  82575. # include <config.h>
  82576. #endif
  82577. #include <stdlib.h> /* for malloc() */
  82578. #include <string.h> /* for memcpy(), memset() */
  82579. #ifdef _MSC_VER
  82580. #include <winsock.h> /* for ntohl() */
  82581. #elif defined FLAC__SYS_DARWIN
  82582. #include <machine/endian.h> /* for ntohl() */
  82583. #elif defined __MINGW32__
  82584. #include <winsock.h> /* for ntohl() */
  82585. #else
  82586. #include <netinet/in.h> /* for ntohl() */
  82587. #endif
  82588. #if 0 /* UNUSED */
  82589. #endif
  82590. /*** Start of inlined file: bitwriter.h ***/
  82591. #ifndef FLAC__PRIVATE__BITWRITER_H
  82592. #define FLAC__PRIVATE__BITWRITER_H
  82593. #include <stdio.h> /* for FILE */
  82594. struct FLAC__BitWriter;
  82595. typedef struct FLAC__BitWriter FLAC__BitWriter;
  82596. FLAC__BitWriter *FLAC__bitwriter_new(void);
  82597. void FLAC__bitwriter_delete(FLAC__BitWriter *bw);
  82598. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw);
  82599. void FLAC__bitwriter_free(FLAC__BitWriter *bw); /* does not 'free(buffer)' */
  82600. void FLAC__bitwriter_clear(FLAC__BitWriter *bw);
  82601. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out);
  82602. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc);
  82603. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc);
  82604. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw);
  82605. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw); /* can be called anytime, returns total # of bits unconsumed */
  82606. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes);
  82607. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw);
  82608. FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits);
  82609. FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits);
  82610. FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits);
  82611. FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits);
  82612. FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val); /*only for bits=32*/
  82613. FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals);
  82614. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val);
  82615. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter);
  82616. #if 0 /* UNUSED */
  82617. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter);
  82618. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned val, unsigned parameter);
  82619. #endif
  82620. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter);
  82621. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter);
  82622. #if 0 /* UNUSED */
  82623. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter);
  82624. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned val, unsigned parameter);
  82625. #endif
  82626. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val);
  82627. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val);
  82628. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw);
  82629. #endif
  82630. /*** End of inlined file: bitwriter.h ***/
  82631. /*** Start of inlined file: alloc.h ***/
  82632. #ifndef FLAC__SHARE__ALLOC_H
  82633. #define FLAC__SHARE__ALLOC_H
  82634. #if HAVE_CONFIG_H
  82635. # include <config.h>
  82636. #endif
  82637. #include <limits.h> /* for SIZE_MAX */
  82638. #if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
  82639. #include <stdint.h> /* for SIZE_MAX in case limits.h didn't get it */
  82640. #endif
  82641. #include <stdlib.h> /* for size_t, malloc(), etc */
  82642. #ifndef SIZE_MAX
  82643. # ifndef SIZE_T_MAX
  82644. # ifdef _MSC_VER
  82645. # define SIZE_T_MAX UINT_MAX
  82646. # else
  82647. # error
  82648. # endif
  82649. # endif
  82650. # define SIZE_MAX SIZE_T_MAX
  82651. #endif
  82652. #ifndef FLaC__INLINE
  82653. #define FLaC__INLINE
  82654. #endif
  82655. static FLaC__INLINE void *safe_malloc_(size_t size)
  82656. {
  82657. if(!size)
  82658. size++;
  82659. return malloc(size);
  82660. }
  82661. static FLaC__INLINE void *safe_calloc_(size_t nmemb, size_t size)
  82662. {
  82663. if(!nmemb || !size)
  82664. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82665. return calloc(nmemb, size);
  82666. }
  82667. static FLaC__INLINE void *safe_malloc_add_2op_(size_t size1, size_t size2)
  82668. {
  82669. size2 += size1;
  82670. if(size2 < size1)
  82671. return 0;
  82672. return safe_malloc_(size2);
  82673. }
  82674. static FLaC__INLINE void *safe_malloc_add_3op_(size_t size1, size_t size2, size_t size3)
  82675. {
  82676. size2 += size1;
  82677. if(size2 < size1)
  82678. return 0;
  82679. size3 += size2;
  82680. if(size3 < size2)
  82681. return 0;
  82682. return safe_malloc_(size3);
  82683. }
  82684. static FLaC__INLINE void *safe_malloc_add_4op_(size_t size1, size_t size2, size_t size3, size_t size4)
  82685. {
  82686. size2 += size1;
  82687. if(size2 < size1)
  82688. return 0;
  82689. size3 += size2;
  82690. if(size3 < size2)
  82691. return 0;
  82692. size4 += size3;
  82693. if(size4 < size3)
  82694. return 0;
  82695. return safe_malloc_(size4);
  82696. }
  82697. static FLaC__INLINE void *safe_malloc_mul_2op_(size_t size1, size_t size2)
  82698. #if 0
  82699. needs support for cases where sizeof(size_t) != 4
  82700. {
  82701. if(sizeof(size_t) == 4) {
  82702. if ((double)size1 * (double)size2 < 4294967296.0)
  82703. return malloc(size1*size2);
  82704. }
  82705. return 0;
  82706. }
  82707. #else
  82708. {
  82709. if(!size1 || !size2)
  82710. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82711. if(size1 > SIZE_MAX / size2)
  82712. return 0;
  82713. return malloc(size1*size2);
  82714. }
  82715. #endif
  82716. static FLaC__INLINE void *safe_malloc_mul_3op_(size_t size1, size_t size2, size_t size3)
  82717. {
  82718. if(!size1 || !size2 || !size3)
  82719. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82720. if(size1 > SIZE_MAX / size2)
  82721. return 0;
  82722. size1 *= size2;
  82723. if(size1 > SIZE_MAX / size3)
  82724. return 0;
  82725. return malloc(size1*size3);
  82726. }
  82727. static FLaC__INLINE void *safe_malloc_mul2add_(size_t size1, size_t size2, size_t size3)
  82728. {
  82729. if(!size1 || !size2)
  82730. return safe_malloc_(size3);
  82731. if(size1 > SIZE_MAX / size2)
  82732. return 0;
  82733. return safe_malloc_add_2op_(size1*size2, size3);
  82734. }
  82735. static FLaC__INLINE void *safe_malloc_muladd2_(size_t size1, size_t size2, size_t size3)
  82736. {
  82737. if(!size1 || (!size2 && !size3))
  82738. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82739. size2 += size3;
  82740. if(size2 < size3)
  82741. return 0;
  82742. return safe_malloc_mul_2op_(size1, size2);
  82743. }
  82744. static FLaC__INLINE void *safe_realloc_add_2op_(void *ptr, size_t size1, size_t size2)
  82745. {
  82746. size2 += size1;
  82747. if(size2 < size1)
  82748. return 0;
  82749. return realloc(ptr, size2);
  82750. }
  82751. static FLaC__INLINE void *safe_realloc_add_3op_(void *ptr, size_t size1, size_t size2, size_t size3)
  82752. {
  82753. size2 += size1;
  82754. if(size2 < size1)
  82755. return 0;
  82756. size3 += size2;
  82757. if(size3 < size2)
  82758. return 0;
  82759. return realloc(ptr, size3);
  82760. }
  82761. static FLaC__INLINE void *safe_realloc_add_4op_(void *ptr, size_t size1, size_t size2, size_t size3, size_t size4)
  82762. {
  82763. size2 += size1;
  82764. if(size2 < size1)
  82765. return 0;
  82766. size3 += size2;
  82767. if(size3 < size2)
  82768. return 0;
  82769. size4 += size3;
  82770. if(size4 < size3)
  82771. return 0;
  82772. return realloc(ptr, size4);
  82773. }
  82774. static FLaC__INLINE void *safe_realloc_mul_2op_(void *ptr, size_t size1, size_t size2)
  82775. {
  82776. if(!size1 || !size2)
  82777. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  82778. if(size1 > SIZE_MAX / size2)
  82779. return 0;
  82780. return realloc(ptr, size1*size2);
  82781. }
  82782. static FLaC__INLINE void *safe_realloc_muladd2_(void *ptr, size_t size1, size_t size2, size_t size3)
  82783. {
  82784. if(!size1 || (!size2 && !size3))
  82785. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  82786. size2 += size3;
  82787. if(size2 < size3)
  82788. return 0;
  82789. return safe_realloc_mul_2op_(ptr, size1, size2);
  82790. }
  82791. #endif
  82792. /*** End of inlined file: alloc.h ***/
  82793. typedef FLAC__uint32 bwword;
  82794. #define FLAC__BYTES_PER_WORD 4
  82795. #define FLAC__BITS_PER_WORD 32
  82796. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  82797. #if WORDS_BIGENDIAN
  82798. #define SWAP_BE_WORD_TO_HOST(x) (x)
  82799. #else
  82800. #ifdef _MSC_VER
  82801. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  82802. #else
  82803. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  82804. #endif
  82805. #endif
  82806. static const unsigned FLAC__BITWRITER_DEFAULT_CAPACITY = 32768u / sizeof(bwword); /* size in words */
  82807. static const unsigned FLAC__BITWRITER_DEFAULT_INCREMENT = 4096u / sizeof(bwword); /* size in words */
  82808. #define FLAC__WORDS_TO_BITS(words) ((words) * FLAC__BITS_PER_WORD)
  82809. #define FLAC__TOTAL_BITS(bw) (FLAC__WORDS_TO_BITS((bw)->words) + (bw)->bits)
  82810. #ifdef min
  82811. #undef min
  82812. #endif
  82813. #define min(x,y) ((x)<(y)?(x):(y))
  82814. #ifdef _MSC_VER
  82815. #define FLAC__U64L(x) x
  82816. #else
  82817. #define FLAC__U64L(x) x##LLU
  82818. #endif
  82819. #ifndef FLaC__INLINE
  82820. #define FLaC__INLINE
  82821. #endif
  82822. struct FLAC__BitWriter {
  82823. bwword *buffer;
  82824. bwword accum; /* accumulator; bits are right-justified; when full, accum is appended to buffer */
  82825. unsigned capacity; /* capacity of buffer in words */
  82826. unsigned words; /* # of complete words in buffer */
  82827. unsigned bits; /* # of used bits in accum */
  82828. };
  82829. static FLAC__bool bitwriter_grow_(FLAC__BitWriter *bw, unsigned bits_to_add)
  82830. {
  82831. unsigned new_capacity;
  82832. bwword *new_buffer;
  82833. FLAC__ASSERT(0 != bw);
  82834. FLAC__ASSERT(0 != bw->buffer);
  82835. new_capacity = bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD);
  82836. if(bw->capacity >= new_capacity)
  82837. return true;
  82838. if((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT)
  82839. new_capacity += FLAC__BITWRITER_DEFAULT_INCREMENT - ((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  82840. FLAC__ASSERT(0 == (new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  82841. FLAC__ASSERT(new_capacity > bw->capacity);
  82842. FLAC__ASSERT(new_capacity >= bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD));
  82843. new_buffer = (bwword*)safe_realloc_mul_2op_(bw->buffer, sizeof(bwword), /*times*/new_capacity);
  82844. if(new_buffer == 0)
  82845. return false;
  82846. bw->buffer = new_buffer;
  82847. bw->capacity = new_capacity;
  82848. return true;
  82849. }
  82850. FLAC__BitWriter *FLAC__bitwriter_new(void)
  82851. {
  82852. FLAC__BitWriter *bw = (FLAC__BitWriter*)calloc(1, sizeof(FLAC__BitWriter));
  82853. return bw;
  82854. }
  82855. void FLAC__bitwriter_delete(FLAC__BitWriter *bw)
  82856. {
  82857. FLAC__ASSERT(0 != bw);
  82858. FLAC__bitwriter_free(bw);
  82859. free(bw);
  82860. }
  82861. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw)
  82862. {
  82863. FLAC__ASSERT(0 != bw);
  82864. bw->words = bw->bits = 0;
  82865. bw->capacity = FLAC__BITWRITER_DEFAULT_CAPACITY;
  82866. bw->buffer = (bwword*)malloc(sizeof(bwword) * bw->capacity);
  82867. if(bw->buffer == 0)
  82868. return false;
  82869. return true;
  82870. }
  82871. void FLAC__bitwriter_free(FLAC__BitWriter *bw)
  82872. {
  82873. FLAC__ASSERT(0 != bw);
  82874. if(0 != bw->buffer)
  82875. free(bw->buffer);
  82876. bw->buffer = 0;
  82877. bw->capacity = 0;
  82878. bw->words = bw->bits = 0;
  82879. }
  82880. void FLAC__bitwriter_clear(FLAC__BitWriter *bw)
  82881. {
  82882. bw->words = bw->bits = 0;
  82883. }
  82884. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out)
  82885. {
  82886. unsigned i, j;
  82887. if(bw == 0) {
  82888. fprintf(out, "bitwriter is NULL\n");
  82889. }
  82890. else {
  82891. fprintf(out, "bitwriter: capacity=%u words=%u bits=%u total_bits=%u\n", bw->capacity, bw->words, bw->bits, FLAC__TOTAL_BITS(bw));
  82892. for(i = 0; i < bw->words; i++) {
  82893. fprintf(out, "%08X: ", i);
  82894. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  82895. fprintf(out, "%01u", bw->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  82896. fprintf(out, "\n");
  82897. }
  82898. if(bw->bits > 0) {
  82899. fprintf(out, "%08X: ", i);
  82900. for(j = 0; j < bw->bits; j++)
  82901. fprintf(out, "%01u", bw->accum & (1 << (bw->bits-j-1)) ? 1:0);
  82902. fprintf(out, "\n");
  82903. }
  82904. }
  82905. }
  82906. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc)
  82907. {
  82908. const FLAC__byte *buffer;
  82909. size_t bytes;
  82910. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  82911. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  82912. return false;
  82913. *crc = (FLAC__uint16)FLAC__crc16(buffer, bytes);
  82914. FLAC__bitwriter_release_buffer(bw);
  82915. return true;
  82916. }
  82917. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc)
  82918. {
  82919. const FLAC__byte *buffer;
  82920. size_t bytes;
  82921. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  82922. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  82923. return false;
  82924. *crc = FLAC__crc8(buffer, bytes);
  82925. FLAC__bitwriter_release_buffer(bw);
  82926. return true;
  82927. }
  82928. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw)
  82929. {
  82930. return ((bw->bits & 7) == 0);
  82931. }
  82932. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw)
  82933. {
  82934. return FLAC__TOTAL_BITS(bw);
  82935. }
  82936. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes)
  82937. {
  82938. FLAC__ASSERT((bw->bits & 7) == 0);
  82939. if(bw->bits & 7)
  82940. return false;
  82941. if(bw->bits) {
  82942. FLAC__ASSERT(bw->words <= bw->capacity);
  82943. if(bw->words == bw->capacity && !bitwriter_grow_(bw, FLAC__BITS_PER_WORD))
  82944. return false;
  82945. bw->buffer[bw->words] = SWAP_BE_WORD_TO_HOST(bw->accum << (FLAC__BITS_PER_WORD-bw->bits));
  82946. }
  82947. *buffer = (FLAC__byte*)bw->buffer;
  82948. *bytes = (FLAC__BYTES_PER_WORD * bw->words) + (bw->bits >> 3);
  82949. return true;
  82950. }
  82951. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw)
  82952. {
  82953. (void)bw;
  82954. }
  82955. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits)
  82956. {
  82957. unsigned n;
  82958. FLAC__ASSERT(0 != bw);
  82959. FLAC__ASSERT(0 != bw->buffer);
  82960. if(bits == 0)
  82961. return true;
  82962. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  82963. return false;
  82964. if(bw->bits) {
  82965. n = min(FLAC__BITS_PER_WORD - bw->bits, bits);
  82966. bw->accum <<= n;
  82967. bits -= n;
  82968. bw->bits += n;
  82969. if(bw->bits == FLAC__BITS_PER_WORD) {
  82970. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  82971. bw->bits = 0;
  82972. }
  82973. else
  82974. return true;
  82975. }
  82976. while(bits >= FLAC__BITS_PER_WORD) {
  82977. bw->buffer[bw->words++] = 0;
  82978. bits -= FLAC__BITS_PER_WORD;
  82979. }
  82980. if(bits > 0) {
  82981. bw->accum = 0;
  82982. bw->bits = bits;
  82983. }
  82984. return true;
  82985. }
  82986. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits)
  82987. {
  82988. register unsigned left;
  82989. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82990. FLAC__ASSERT(0 != bw);
  82991. FLAC__ASSERT(0 != bw->buffer);
  82992. FLAC__ASSERT(bits <= 32);
  82993. if(bits == 0)
  82994. return true;
  82995. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  82996. return false;
  82997. left = FLAC__BITS_PER_WORD - bw->bits;
  82998. if(bits < left) {
  82999. bw->accum <<= bits;
  83000. bw->accum |= val;
  83001. bw->bits += bits;
  83002. }
  83003. 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 */
  83004. bw->accum <<= left;
  83005. bw->accum |= val >> (bw->bits = bits - left);
  83006. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83007. bw->accum = val;
  83008. }
  83009. else {
  83010. bw->accum = val;
  83011. bw->bits = 0;
  83012. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(val);
  83013. }
  83014. return true;
  83015. }
  83016. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits)
  83017. {
  83018. if(bits < 32)
  83019. val &= (~(0xffffffff << bits));
  83020. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  83021. }
  83022. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits)
  83023. {
  83024. if(bits > 32) {
  83025. return
  83026. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(val>>32), bits-32) &&
  83027. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 32);
  83028. }
  83029. else
  83030. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  83031. }
  83032. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val)
  83033. {
  83034. if(!FLAC__bitwriter_write_raw_uint32(bw, val & 0xff, 8))
  83035. return false;
  83036. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>8) & 0xff, 8))
  83037. return false;
  83038. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>16) & 0xff, 8))
  83039. return false;
  83040. if(!FLAC__bitwriter_write_raw_uint32(bw, val>>24, 8))
  83041. return false;
  83042. return true;
  83043. }
  83044. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals)
  83045. {
  83046. unsigned i;
  83047. for(i = 0; i < nvals; i++) {
  83048. if(!FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(vals[i]), 8))
  83049. return false;
  83050. }
  83051. return true;
  83052. }
  83053. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val)
  83054. {
  83055. if(val < 32)
  83056. return FLAC__bitwriter_write_raw_uint32(bw, 1, ++val);
  83057. else
  83058. return
  83059. FLAC__bitwriter_write_zeroes(bw, val) &&
  83060. FLAC__bitwriter_write_raw_uint32(bw, 1, 1);
  83061. }
  83062. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter)
  83063. {
  83064. FLAC__uint32 uval;
  83065. FLAC__ASSERT(parameter < sizeof(unsigned)*8);
  83066. uval = (val<<1) ^ (val>>31);
  83067. return 1 + parameter + (uval >> parameter);
  83068. }
  83069. #if 0 /* UNUSED */
  83070. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter)
  83071. {
  83072. unsigned bits, msbs, uval;
  83073. unsigned k;
  83074. FLAC__ASSERT(parameter > 0);
  83075. if(val < 0)
  83076. uval = (unsigned)(((-(++val)) << 1) + 1);
  83077. else
  83078. uval = (unsigned)(val << 1);
  83079. k = FLAC__bitmath_ilog2(parameter);
  83080. if(parameter == 1u<<k) {
  83081. FLAC__ASSERT(k <= 30);
  83082. msbs = uval >> k;
  83083. bits = 1 + k + msbs;
  83084. }
  83085. else {
  83086. unsigned q, r, d;
  83087. d = (1 << (k+1)) - parameter;
  83088. q = uval / parameter;
  83089. r = uval - (q * parameter);
  83090. bits = 1 + q + k;
  83091. if(r >= d)
  83092. bits++;
  83093. }
  83094. return bits;
  83095. }
  83096. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned uval, unsigned parameter)
  83097. {
  83098. unsigned bits, msbs;
  83099. unsigned k;
  83100. FLAC__ASSERT(parameter > 0);
  83101. k = FLAC__bitmath_ilog2(parameter);
  83102. if(parameter == 1u<<k) {
  83103. FLAC__ASSERT(k <= 30);
  83104. msbs = uval >> k;
  83105. bits = 1 + k + msbs;
  83106. }
  83107. else {
  83108. unsigned q, r, d;
  83109. d = (1 << (k+1)) - parameter;
  83110. q = uval / parameter;
  83111. r = uval - (q * parameter);
  83112. bits = 1 + q + k;
  83113. if(r >= d)
  83114. bits++;
  83115. }
  83116. return bits;
  83117. }
  83118. #endif /* UNUSED */
  83119. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter)
  83120. {
  83121. unsigned total_bits, interesting_bits, msbs;
  83122. FLAC__uint32 uval, pattern;
  83123. FLAC__ASSERT(0 != bw);
  83124. FLAC__ASSERT(0 != bw->buffer);
  83125. FLAC__ASSERT(parameter < 8*sizeof(uval));
  83126. uval = (val<<1) ^ (val>>31);
  83127. msbs = uval >> parameter;
  83128. interesting_bits = 1 + parameter;
  83129. total_bits = interesting_bits + msbs;
  83130. pattern = 1 << parameter; /* the unary end bit */
  83131. pattern |= (uval & ((1<<parameter)-1)); /* the binary LSBs */
  83132. if(total_bits <= 32)
  83133. return FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits);
  83134. else
  83135. return
  83136. FLAC__bitwriter_write_zeroes(bw, msbs) && /* write the unary MSBs */
  83137. FLAC__bitwriter_write_raw_uint32(bw, pattern, interesting_bits); /* write the unary end bit and binary LSBs */
  83138. }
  83139. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter)
  83140. {
  83141. const FLAC__uint32 mask1 = FLAC__WORD_ALL_ONES << parameter; /* we val|=mask1 to set the stop bit above it... */
  83142. const FLAC__uint32 mask2 = FLAC__WORD_ALL_ONES >> (31-parameter); /* ...then mask off the bits above the stop bit with val&=mask2*/
  83143. FLAC__uint32 uval;
  83144. unsigned left;
  83145. const unsigned lsbits = 1 + parameter;
  83146. unsigned msbits;
  83147. FLAC__ASSERT(0 != bw);
  83148. FLAC__ASSERT(0 != bw->buffer);
  83149. FLAC__ASSERT(parameter < 8*sizeof(bwword)-1);
  83150. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83151. while(nvals) {
  83152. uval = (*vals<<1) ^ (*vals>>31);
  83153. msbits = uval >> parameter;
  83154. #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) */
  83155. if(bw->bits && bw->bits + msbits + lsbits <= FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83156. bw->bits = bw->bits + msbits + lsbits;
  83157. uval |= mask1; /* set stop bit */
  83158. uval &= mask2; /* mask off unused top bits */
  83159. bw->accum <<= msbits;
  83160. bw->accum <<= lsbits;
  83161. bw->accum |= uval;
  83162. if(bw->bits == FLAC__BITS_PER_WORD) {
  83163. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83164. bw->bits = 0;
  83165. if(bw->capacity <= bw->words && nvals > 1 && !bitwriter_grow_(bw, 1)) {
  83166. FLAC__ASSERT(bw->capacity == bw->words);
  83167. return false;
  83168. }
  83169. }
  83170. }
  83171. else {
  83172. #elif 1 /*@@@@@@ OPT: try this version with MSVC6 to see if better, not much difference for gcc-4 */
  83173. if(bw->bits && bw->bits + msbits + lsbits < FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83174. bw->bits = bw->bits + msbits + lsbits;
  83175. uval |= mask1; /* set stop bit */
  83176. uval &= mask2; /* mask off unused top bits */
  83177. bw->accum <<= msbits + lsbits;
  83178. bw->accum |= uval;
  83179. }
  83180. else {
  83181. #endif
  83182. if(bw->capacity <= bw->words + bw->bits + msbits + 1/*lsbits always fit in 1 bwword*/ && !bitwriter_grow_(bw, msbits+lsbits))
  83183. return false;
  83184. if(msbits) {
  83185. if(bw->bits) {
  83186. left = FLAC__BITS_PER_WORD - bw->bits;
  83187. if(msbits < left) {
  83188. bw->accum <<= msbits;
  83189. bw->bits += msbits;
  83190. goto break1;
  83191. }
  83192. else {
  83193. bw->accum <<= left;
  83194. msbits -= left;
  83195. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83196. bw->bits = 0;
  83197. }
  83198. }
  83199. while(msbits >= FLAC__BITS_PER_WORD) {
  83200. bw->buffer[bw->words++] = 0;
  83201. msbits -= FLAC__BITS_PER_WORD;
  83202. }
  83203. if(msbits > 0) {
  83204. bw->accum = 0;
  83205. bw->bits = msbits;
  83206. }
  83207. }
  83208. break1:
  83209. uval |= mask1; /* set stop bit */
  83210. uval &= mask2; /* mask off unused top bits */
  83211. left = FLAC__BITS_PER_WORD - bw->bits;
  83212. if(lsbits < left) {
  83213. bw->accum <<= lsbits;
  83214. bw->accum |= uval;
  83215. bw->bits += lsbits;
  83216. }
  83217. else {
  83218. FLAC__ASSERT(bw->bits);
  83219. FLAC__ASSERT(left < FLAC__BITS_PER_WORD);
  83220. bw->accum <<= left;
  83221. bw->accum |= uval >> (bw->bits = lsbits - left);
  83222. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83223. bw->accum = uval;
  83224. }
  83225. #if 1
  83226. }
  83227. #endif
  83228. vals++;
  83229. nvals--;
  83230. }
  83231. return true;
  83232. }
  83233. #if 0 /* UNUSED */
  83234. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter)
  83235. {
  83236. unsigned total_bits, msbs, uval;
  83237. unsigned k;
  83238. FLAC__ASSERT(0 != bw);
  83239. FLAC__ASSERT(0 != bw->buffer);
  83240. FLAC__ASSERT(parameter > 0);
  83241. if(val < 0)
  83242. uval = (unsigned)(((-(++val)) << 1) + 1);
  83243. else
  83244. uval = (unsigned)(val << 1);
  83245. k = FLAC__bitmath_ilog2(parameter);
  83246. if(parameter == 1u<<k) {
  83247. unsigned pattern;
  83248. FLAC__ASSERT(k <= 30);
  83249. msbs = uval >> k;
  83250. total_bits = 1 + k + msbs;
  83251. pattern = 1 << k; /* the unary end bit */
  83252. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83253. if(total_bits <= 32) {
  83254. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83255. return false;
  83256. }
  83257. else {
  83258. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83259. return false;
  83260. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83261. return false;
  83262. }
  83263. }
  83264. else {
  83265. unsigned q, r, d;
  83266. d = (1 << (k+1)) - parameter;
  83267. q = uval / parameter;
  83268. r = uval - (q * parameter);
  83269. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83270. return false;
  83271. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83272. return false;
  83273. if(r >= d) {
  83274. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83275. return false;
  83276. }
  83277. else {
  83278. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83279. return false;
  83280. }
  83281. }
  83282. return true;
  83283. }
  83284. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned uval, unsigned parameter)
  83285. {
  83286. unsigned total_bits, msbs;
  83287. unsigned k;
  83288. FLAC__ASSERT(0 != bw);
  83289. FLAC__ASSERT(0 != bw->buffer);
  83290. FLAC__ASSERT(parameter > 0);
  83291. k = FLAC__bitmath_ilog2(parameter);
  83292. if(parameter == 1u<<k) {
  83293. unsigned pattern;
  83294. FLAC__ASSERT(k <= 30);
  83295. msbs = uval >> k;
  83296. total_bits = 1 + k + msbs;
  83297. pattern = 1 << k; /* the unary end bit */
  83298. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83299. if(total_bits <= 32) {
  83300. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83301. return false;
  83302. }
  83303. else {
  83304. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83305. return false;
  83306. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83307. return false;
  83308. }
  83309. }
  83310. else {
  83311. unsigned q, r, d;
  83312. d = (1 << (k+1)) - parameter;
  83313. q = uval / parameter;
  83314. r = uval - (q * parameter);
  83315. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83316. return false;
  83317. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83318. return false;
  83319. if(r >= d) {
  83320. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83321. return false;
  83322. }
  83323. else {
  83324. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83325. return false;
  83326. }
  83327. }
  83328. return true;
  83329. }
  83330. #endif /* UNUSED */
  83331. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val)
  83332. {
  83333. FLAC__bool ok = 1;
  83334. FLAC__ASSERT(0 != bw);
  83335. FLAC__ASSERT(0 != bw->buffer);
  83336. FLAC__ASSERT(!(val & 0x80000000)); /* this version only handles 31 bits */
  83337. if(val < 0x80) {
  83338. return FLAC__bitwriter_write_raw_uint32(bw, val, 8);
  83339. }
  83340. else if(val < 0x800) {
  83341. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (val>>6), 8);
  83342. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83343. }
  83344. else if(val < 0x10000) {
  83345. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (val>>12), 8);
  83346. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83347. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83348. }
  83349. else if(val < 0x200000) {
  83350. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (val>>18), 8);
  83351. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83352. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83353. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83354. }
  83355. else if(val < 0x4000000) {
  83356. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (val>>24), 8);
  83357. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83358. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83359. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83360. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83361. }
  83362. else {
  83363. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (val>>30), 8);
  83364. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>24)&0x3F), 8);
  83365. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83366. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83367. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83368. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83369. }
  83370. return ok;
  83371. }
  83372. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val)
  83373. {
  83374. FLAC__bool ok = 1;
  83375. FLAC__ASSERT(0 != bw);
  83376. FLAC__ASSERT(0 != bw->buffer);
  83377. FLAC__ASSERT(!(val & FLAC__U64L(0xFFFFFFF000000000))); /* this version only handles 36 bits */
  83378. if(val < 0x80) {
  83379. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 8);
  83380. }
  83381. else if(val < 0x800) {
  83382. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (FLAC__uint32)(val>>6), 8);
  83383. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83384. }
  83385. else if(val < 0x10000) {
  83386. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (FLAC__uint32)(val>>12), 8);
  83387. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83388. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83389. }
  83390. else if(val < 0x200000) {
  83391. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (FLAC__uint32)(val>>18), 8);
  83392. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83393. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83394. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83395. }
  83396. else if(val < 0x4000000) {
  83397. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (FLAC__uint32)(val>>24), 8);
  83398. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83399. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83400. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83401. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83402. }
  83403. else if(val < 0x80000000) {
  83404. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (FLAC__uint32)(val>>30), 8);
  83405. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83406. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83407. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83408. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83409. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83410. }
  83411. else {
  83412. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFE, 8);
  83413. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>30)&0x3F), 8);
  83414. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83415. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83416. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83417. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83418. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83419. }
  83420. return ok;
  83421. }
  83422. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw)
  83423. {
  83424. if(bw->bits & 7u)
  83425. return FLAC__bitwriter_write_zeroes(bw, 8 - (bw->bits & 7u));
  83426. else
  83427. return true;
  83428. }
  83429. #endif
  83430. /*** End of inlined file: bitwriter.c ***/
  83431. /*** Start of inlined file: cpu.c ***/
  83432. /*** Start of inlined file: juce_FlacHeader.h ***/
  83433. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83434. // tasks..
  83435. #define VERSION "1.2.1"
  83436. #define FLAC__NO_DLL 1
  83437. #if JUCE_MSVC
  83438. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83439. #endif
  83440. #if JUCE_MAC
  83441. #define FLAC__SYS_DARWIN 1
  83442. #endif
  83443. /*** End of inlined file: juce_FlacHeader.h ***/
  83444. #if JUCE_USE_FLAC
  83445. #if HAVE_CONFIG_H
  83446. # include <config.h>
  83447. #endif
  83448. #include <stdlib.h>
  83449. #include <stdio.h>
  83450. #if defined FLAC__CPU_IA32
  83451. # include <signal.h>
  83452. #elif defined FLAC__CPU_PPC
  83453. # if !defined FLAC__NO_ASM
  83454. # if defined FLAC__SYS_DARWIN
  83455. # include <sys/sysctl.h>
  83456. # include <mach/mach.h>
  83457. # include <mach/mach_host.h>
  83458. # include <mach/host_info.h>
  83459. # include <mach/machine.h>
  83460. # ifndef CPU_SUBTYPE_POWERPC_970
  83461. # define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100)
  83462. # endif
  83463. # else /* FLAC__SYS_DARWIN */
  83464. # include <signal.h>
  83465. # include <setjmp.h>
  83466. static sigjmp_buf jmpbuf;
  83467. static volatile sig_atomic_t canjump = 0;
  83468. static void sigill_handler (int sig)
  83469. {
  83470. if (!canjump) {
  83471. signal (sig, SIG_DFL);
  83472. raise (sig);
  83473. }
  83474. canjump = 0;
  83475. siglongjmp (jmpbuf, 1);
  83476. }
  83477. # endif /* FLAC__SYS_DARWIN */
  83478. # endif /* FLAC__NO_ASM */
  83479. #endif /* FLAC__CPU_PPC */
  83480. #if defined (__NetBSD__) || defined(__OpenBSD__)
  83481. #include <sys/param.h>
  83482. #include <sys/sysctl.h>
  83483. #include <machine/cpu.h>
  83484. #endif
  83485. #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
  83486. #include <sys/types.h>
  83487. #include <sys/sysctl.h>
  83488. #endif
  83489. #if defined(__APPLE__)
  83490. #endif
  83491. static const unsigned FLAC__CPUINFO_IA32_CPUID_CMOV = 0x00008000;
  83492. static const unsigned FLAC__CPUINFO_IA32_CPUID_MMX = 0x00800000;
  83493. static const unsigned FLAC__CPUINFO_IA32_CPUID_FXSR = 0x01000000;
  83494. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE = 0x02000000;
  83495. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE2 = 0x04000000;
  83496. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE3 = 0x00000001;
  83497. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSSE3 = 0x00000200;
  83498. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW = 0x80000000;
  83499. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW = 0x40000000;
  83500. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX = 0x00400000;
  83501. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM && !defined FLAC__NO_SSE_OS && !defined FLAC__SSE_OS
  83502. # if defined(__linux__)
  83503. # undef USE_OBSOLETE_SIGCONTEXT_FLAVOR /* #define this to use the older signal handler method */
  83504. # ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  83505. static void sigill_handler_sse_os(int signal, struct sigcontext sc)
  83506. {
  83507. (void)signal;
  83508. sc.eip += 3 + 3 + 6;
  83509. }
  83510. # else
  83511. # include <sys/ucontext.h>
  83512. static void sigill_handler_sse_os(int signal, siginfo_t *si, void *uc)
  83513. {
  83514. (void)signal, (void)si;
  83515. ((ucontext_t*)uc)->uc_mcontext.gregs[14/*REG_EIP*/] += 3 + 3 + 6;
  83516. }
  83517. # endif
  83518. # elif defined(_MSC_VER)
  83519. # include <windows.h>
  83520. # undef USE_TRY_CATCH_FLAVOR /* #define this to use the try/catch method for catching illegal opcode exception */
  83521. # ifdef USE_TRY_CATCH_FLAVOR
  83522. # else
  83523. LONG CALLBACK sigill_handler_sse_os(EXCEPTION_POINTERS *ep)
  83524. {
  83525. if(ep->ExceptionRecord->ExceptionCode == EXCEPTION_ILLEGAL_INSTRUCTION) {
  83526. ep->ContextRecord->Eip += 3 + 3 + 6;
  83527. return EXCEPTION_CONTINUE_EXECUTION;
  83528. }
  83529. return EXCEPTION_CONTINUE_SEARCH;
  83530. }
  83531. # endif
  83532. # endif
  83533. #endif
  83534. void FLAC__cpu_info(FLAC__CPUInfo *info)
  83535. {
  83536. #ifdef FLAC__CPU_IA32
  83537. info->type = FLAC__CPUINFO_TYPE_IA32;
  83538. #if !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  83539. info->use_asm = true; /* we assume a minimum of 80386 with FLAC__CPU_IA32 */
  83540. info->data.ia32.cpuid = FLAC__cpu_have_cpuid_asm_ia32()? true : false;
  83541. info->data.ia32.bswap = info->data.ia32.cpuid; /* CPUID => BSWAP since it came after */
  83542. info->data.ia32.cmov = false;
  83543. info->data.ia32.mmx = false;
  83544. info->data.ia32.fxsr = false;
  83545. info->data.ia32.sse = false;
  83546. info->data.ia32.sse2 = false;
  83547. info->data.ia32.sse3 = false;
  83548. info->data.ia32.ssse3 = false;
  83549. info->data.ia32._3dnow = false;
  83550. info->data.ia32.ext3dnow = false;
  83551. info->data.ia32.extmmx = false;
  83552. if(info->data.ia32.cpuid) {
  83553. FLAC__uint32 flags_edx, flags_ecx;
  83554. FLAC__cpu_info_asm_ia32(&flags_edx, &flags_ecx);
  83555. info->data.ia32.cmov = (flags_edx & FLAC__CPUINFO_IA32_CPUID_CMOV )? true : false;
  83556. info->data.ia32.mmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_MMX )? true : false;
  83557. info->data.ia32.fxsr = (flags_edx & FLAC__CPUINFO_IA32_CPUID_FXSR )? true : false;
  83558. info->data.ia32.sse = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE )? true : false;
  83559. info->data.ia32.sse2 = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE2 )? true : false;
  83560. info->data.ia32.sse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSE3 )? true : false;
  83561. info->data.ia32.ssse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSSE3)? true : false;
  83562. #ifdef FLAC__USE_3DNOW
  83563. flags_edx = FLAC__cpu_info_extended_amd_asm_ia32();
  83564. info->data.ia32._3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW )? true : false;
  83565. info->data.ia32.ext3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW)? true : false;
  83566. info->data.ia32.extmmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX )? true : false;
  83567. #else
  83568. info->data.ia32._3dnow = info->data.ia32.ext3dnow = info->data.ia32.extmmx = false;
  83569. #endif
  83570. #ifdef DEBUG
  83571. fprintf(stderr, "CPU info (IA-32):\n");
  83572. fprintf(stderr, " CPUID ...... %c\n", info->data.ia32.cpuid ? 'Y' : 'n');
  83573. fprintf(stderr, " BSWAP ...... %c\n", info->data.ia32.bswap ? 'Y' : 'n');
  83574. fprintf(stderr, " CMOV ....... %c\n", info->data.ia32.cmov ? 'Y' : 'n');
  83575. fprintf(stderr, " MMX ........ %c\n", info->data.ia32.mmx ? 'Y' : 'n');
  83576. fprintf(stderr, " FXSR ....... %c\n", info->data.ia32.fxsr ? 'Y' : 'n');
  83577. fprintf(stderr, " SSE ........ %c\n", info->data.ia32.sse ? 'Y' : 'n');
  83578. fprintf(stderr, " SSE2 ....... %c\n", info->data.ia32.sse2 ? 'Y' : 'n');
  83579. fprintf(stderr, " SSE3 ....... %c\n", info->data.ia32.sse3 ? 'Y' : 'n');
  83580. fprintf(stderr, " SSSE3 ...... %c\n", info->data.ia32.ssse3 ? 'Y' : 'n');
  83581. fprintf(stderr, " 3DNow! ..... %c\n", info->data.ia32._3dnow ? 'Y' : 'n');
  83582. fprintf(stderr, " 3DNow!-ext . %c\n", info->data.ia32.ext3dnow? 'Y' : 'n');
  83583. fprintf(stderr, " 3DNow!-MMX . %c\n", info->data.ia32.extmmx ? 'Y' : 'n');
  83584. #endif
  83585. if(info->data.ia32.fxsr || info->data.ia32.sse || info->data.ia32.sse2) {
  83586. #if defined FLAC__NO_SSE_OS
  83587. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83588. #elif defined FLAC__SSE_OS
  83589. #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__APPLE__)
  83590. int sse = 0;
  83591. size_t len;
  83592. len = sizeof(sse); sse = sse || (sysctlbyname("hw.instruction_sse", &sse, &len, NULL, 0) == 0 && sse);
  83593. len = sizeof(sse); sse = sse || (sysctlbyname("hw.optional.sse" , &sse, &len, NULL, 0) == 0 && sse); /* __APPLE__ ? */
  83594. if(!sse)
  83595. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83596. #elif defined(__NetBSD__) || defined (__OpenBSD__)
  83597. # if __NetBSD_Version__ >= 105250000 || (defined __OpenBSD__)
  83598. int val = 0, mib[2] = { CTL_MACHDEP, CPU_SSE };
  83599. size_t len = sizeof(val);
  83600. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  83601. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83602. else { /* double-check SSE2 */
  83603. mib[1] = CPU_SSE2;
  83604. len = sizeof(val);
  83605. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  83606. info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83607. }
  83608. # else
  83609. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83610. # endif
  83611. #elif defined(__linux__)
  83612. int sse = 0;
  83613. struct sigaction sigill_save;
  83614. #ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  83615. if(0 == sigaction(SIGILL, NULL, &sigill_save) && signal(SIGILL, (void (*)(int))sigill_handler_sse_os) != SIG_ERR)
  83616. #else
  83617. struct sigaction sigill_sse;
  83618. sigill_sse.sa_sigaction = sigill_handler_sse_os;
  83619. __sigemptyset(&sigill_sse.sa_mask);
  83620. 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 */
  83621. if(0 == sigaction(SIGILL, &sigill_sse, &sigill_save))
  83622. #endif
  83623. {
  83624. asm volatile (
  83625. "xorl %0,%0\n\t" /* for some reason, still need to do this to clear 'sse' var */
  83626. "xorps %%xmm0,%%xmm0\n\t" /* will cause SIGILL if unsupported by OS */
  83627. "incl %0\n\t" /* SIGILL handler will jump over this */
  83628. "nop\n\t" /* SIGILL jump lands here if "inc" is 9 bytes */
  83629. "nop\n\t"
  83630. "nop\n\t"
  83631. "nop\n\t"
  83632. "nop\n\t"
  83633. "nop\n\t"
  83634. "nop\n\t" /* SIGILL jump lands here if "inc" is 3 bytes (expected) */
  83635. "nop\n\t"
  83636. "nop" /* SIGILL jump lands here if "inc" is 1 byte */
  83637. : "=r"(sse)
  83638. : "r"(sse)
  83639. );
  83640. sigaction(SIGILL, &sigill_save, NULL);
  83641. }
  83642. if(!sse)
  83643. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83644. #elif defined(_MSC_VER)
  83645. # ifdef USE_TRY_CATCH_FLAVOR
  83646. _try {
  83647. __asm {
  83648. # if _MSC_VER <= 1200
  83649. _emit 0x0F
  83650. _emit 0x57
  83651. _emit 0xC0
  83652. # else
  83653. xorps xmm0,xmm0
  83654. # endif
  83655. }
  83656. }
  83657. _except(EXCEPTION_EXECUTE_HANDLER) {
  83658. if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION)
  83659. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83660. }
  83661. # else
  83662. int sse = 0;
  83663. LPTOP_LEVEL_EXCEPTION_FILTER save = SetUnhandledExceptionFilter(sigill_handler_sse_os);
  83664. __asm {
  83665. # if _MSC_VER <= 1200
  83666. _emit 0x0F
  83667. _emit 0x57
  83668. _emit 0xC0
  83669. # else
  83670. xorps xmm0,xmm0
  83671. # endif
  83672. inc sse
  83673. nop
  83674. nop
  83675. nop
  83676. nop
  83677. nop
  83678. nop
  83679. nop
  83680. nop
  83681. nop
  83682. }
  83683. SetUnhandledExceptionFilter(save);
  83684. if(!sse)
  83685. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83686. # endif
  83687. #else
  83688. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83689. #endif
  83690. #ifdef DEBUG
  83691. fprintf(stderr, " SSE OS sup . %c\n", info->data.ia32.sse ? 'Y' : 'n');
  83692. #endif
  83693. }
  83694. }
  83695. #else
  83696. info->use_asm = false;
  83697. #endif
  83698. #elif defined FLAC__CPU_PPC
  83699. info->type = FLAC__CPUINFO_TYPE_PPC;
  83700. # if !defined FLAC__NO_ASM
  83701. info->use_asm = true;
  83702. # ifdef FLAC__USE_ALTIVEC
  83703. # if defined FLAC__SYS_DARWIN
  83704. {
  83705. int val = 0, mib[2] = { CTL_HW, HW_VECTORUNIT };
  83706. size_t len = sizeof(val);
  83707. info->data.ppc.altivec = !(sysctl(mib, 2, &val, &len, NULL, 0) || !val);
  83708. }
  83709. {
  83710. host_basic_info_data_t hostInfo;
  83711. mach_msg_type_number_t infoCount;
  83712. infoCount = HOST_BASIC_INFO_COUNT;
  83713. host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount);
  83714. info->data.ppc.ppc64 = (hostInfo.cpu_type == CPU_TYPE_POWERPC) && (hostInfo.cpu_subtype == CPU_SUBTYPE_POWERPC_970);
  83715. }
  83716. # else /* FLAC__USE_ALTIVEC && !FLAC__SYS_DARWIN */
  83717. {
  83718. info->data.ppc.altivec = 0;
  83719. info->data.ppc.ppc64 = 0;
  83720. signal (SIGILL, sigill_handler);
  83721. canjump = 0;
  83722. if (!sigsetjmp (jmpbuf, 1)) {
  83723. canjump = 1;
  83724. asm volatile (
  83725. "mtspr 256, %0\n\t"
  83726. "vand %%v0, %%v0, %%v0"
  83727. :
  83728. : "r" (-1)
  83729. );
  83730. info->data.ppc.altivec = 1;
  83731. }
  83732. canjump = 0;
  83733. if (!sigsetjmp (jmpbuf, 1)) {
  83734. int x = 0;
  83735. canjump = 1;
  83736. asm volatile ("cntlzd %0, %1" : "=r" (x) : "r" (x) );
  83737. info->data.ppc.ppc64 = 1;
  83738. }
  83739. signal (SIGILL, SIG_DFL); /*@@@@@@ should save and restore old signal */
  83740. }
  83741. # endif
  83742. # else /* !FLAC__USE_ALTIVEC */
  83743. info->data.ppc.altivec = 0;
  83744. info->data.ppc.ppc64 = 0;
  83745. # endif
  83746. # else
  83747. info->use_asm = false;
  83748. # endif
  83749. #else
  83750. info->type = FLAC__CPUINFO_TYPE_UNKNOWN;
  83751. info->use_asm = false;
  83752. #endif
  83753. }
  83754. #endif
  83755. /*** End of inlined file: cpu.c ***/
  83756. /*** Start of inlined file: crc.c ***/
  83757. /*** Start of inlined file: juce_FlacHeader.h ***/
  83758. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83759. // tasks..
  83760. #define VERSION "1.2.1"
  83761. #define FLAC__NO_DLL 1
  83762. #if JUCE_MSVC
  83763. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83764. #endif
  83765. #if JUCE_MAC
  83766. #define FLAC__SYS_DARWIN 1
  83767. #endif
  83768. /*** End of inlined file: juce_FlacHeader.h ***/
  83769. #if JUCE_USE_FLAC
  83770. #if HAVE_CONFIG_H
  83771. # include <config.h>
  83772. #endif
  83773. FLAC__byte const FLAC__crc8_table[256] = {
  83774. 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15,
  83775. 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,
  83776. 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65,
  83777. 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D,
  83778. 0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5,
  83779. 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,
  83780. 0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85,
  83781. 0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD,
  83782. 0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2,
  83783. 0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA,
  83784. 0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2,
  83785. 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A,
  83786. 0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32,
  83787. 0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A,
  83788. 0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42,
  83789. 0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A,
  83790. 0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C,
  83791. 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4,
  83792. 0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC,
  83793. 0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4,
  83794. 0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C,
  83795. 0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44,
  83796. 0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C,
  83797. 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34,
  83798. 0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B,
  83799. 0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63,
  83800. 0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B,
  83801. 0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13,
  83802. 0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB,
  83803. 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,
  83804. 0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB,
  83805. 0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3
  83806. };
  83807. unsigned FLAC__crc16_table[256] = {
  83808. 0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011,
  83809. 0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d, 0x8027, 0x0022,
  83810. 0x8063, 0x0066, 0x006c, 0x8069, 0x0078, 0x807d, 0x8077, 0x0072,
  83811. 0x0050, 0x8055, 0x805f, 0x005a, 0x804b, 0x004e, 0x0044, 0x8041,
  83812. 0x80c3, 0x00c6, 0x00cc, 0x80c9, 0x00d8, 0x80dd, 0x80d7, 0x00d2,
  83813. 0x00f0, 0x80f5, 0x80ff, 0x00fa, 0x80eb, 0x00ee, 0x00e4, 0x80e1,
  83814. 0x00a0, 0x80a5, 0x80af, 0x00aa, 0x80bb, 0x00be, 0x00b4, 0x80b1,
  83815. 0x8093, 0x0096, 0x009c, 0x8099, 0x0088, 0x808d, 0x8087, 0x0082,
  83816. 0x8183, 0x0186, 0x018c, 0x8189, 0x0198, 0x819d, 0x8197, 0x0192,
  83817. 0x01b0, 0x81b5, 0x81bf, 0x01ba, 0x81ab, 0x01ae, 0x01a4, 0x81a1,
  83818. 0x01e0, 0x81e5, 0x81ef, 0x01ea, 0x81fb, 0x01fe, 0x01f4, 0x81f1,
  83819. 0x81d3, 0x01d6, 0x01dc, 0x81d9, 0x01c8, 0x81cd, 0x81c7, 0x01c2,
  83820. 0x0140, 0x8145, 0x814f, 0x014a, 0x815b, 0x015e, 0x0154, 0x8151,
  83821. 0x8173, 0x0176, 0x017c, 0x8179, 0x0168, 0x816d, 0x8167, 0x0162,
  83822. 0x8123, 0x0126, 0x012c, 0x8129, 0x0138, 0x813d, 0x8137, 0x0132,
  83823. 0x0110, 0x8115, 0x811f, 0x011a, 0x810b, 0x010e, 0x0104, 0x8101,
  83824. 0x8303, 0x0306, 0x030c, 0x8309, 0x0318, 0x831d, 0x8317, 0x0312,
  83825. 0x0330, 0x8335, 0x833f, 0x033a, 0x832b, 0x032e, 0x0324, 0x8321,
  83826. 0x0360, 0x8365, 0x836f, 0x036a, 0x837b, 0x037e, 0x0374, 0x8371,
  83827. 0x8353, 0x0356, 0x035c, 0x8359, 0x0348, 0x834d, 0x8347, 0x0342,
  83828. 0x03c0, 0x83c5, 0x83cf, 0x03ca, 0x83db, 0x03de, 0x03d4, 0x83d1,
  83829. 0x83f3, 0x03f6, 0x03fc, 0x83f9, 0x03e8, 0x83ed, 0x83e7, 0x03e2,
  83830. 0x83a3, 0x03a6, 0x03ac, 0x83a9, 0x03b8, 0x83bd, 0x83b7, 0x03b2,
  83831. 0x0390, 0x8395, 0x839f, 0x039a, 0x838b, 0x038e, 0x0384, 0x8381,
  83832. 0x0280, 0x8285, 0x828f, 0x028a, 0x829b, 0x029e, 0x0294, 0x8291,
  83833. 0x82b3, 0x02b6, 0x02bc, 0x82b9, 0x02a8, 0x82ad, 0x82a7, 0x02a2,
  83834. 0x82e3, 0x02e6, 0x02ec, 0x82e9, 0x02f8, 0x82fd, 0x82f7, 0x02f2,
  83835. 0x02d0, 0x82d5, 0x82df, 0x02da, 0x82cb, 0x02ce, 0x02c4, 0x82c1,
  83836. 0x8243, 0x0246, 0x024c, 0x8249, 0x0258, 0x825d, 0x8257, 0x0252,
  83837. 0x0270, 0x8275, 0x827f, 0x027a, 0x826b, 0x026e, 0x0264, 0x8261,
  83838. 0x0220, 0x8225, 0x822f, 0x022a, 0x823b, 0x023e, 0x0234, 0x8231,
  83839. 0x8213, 0x0216, 0x021c, 0x8219, 0x0208, 0x820d, 0x8207, 0x0202
  83840. };
  83841. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc)
  83842. {
  83843. *crc = FLAC__crc8_table[*crc ^ data];
  83844. }
  83845. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc)
  83846. {
  83847. while(len--)
  83848. *crc = FLAC__crc8_table[*crc ^ *data++];
  83849. }
  83850. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len)
  83851. {
  83852. FLAC__uint8 crc = 0;
  83853. while(len--)
  83854. crc = FLAC__crc8_table[crc ^ *data++];
  83855. return crc;
  83856. }
  83857. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len)
  83858. {
  83859. unsigned crc = 0;
  83860. while(len--)
  83861. crc = ((crc<<8) ^ FLAC__crc16_table[(crc>>8) ^ *data++]) & 0xffff;
  83862. return crc;
  83863. }
  83864. #endif
  83865. /*** End of inlined file: crc.c ***/
  83866. /*** Start of inlined file: fixed.c ***/
  83867. /*** Start of inlined file: juce_FlacHeader.h ***/
  83868. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83869. // tasks..
  83870. #define VERSION "1.2.1"
  83871. #define FLAC__NO_DLL 1
  83872. #if JUCE_MSVC
  83873. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83874. #endif
  83875. #if JUCE_MAC
  83876. #define FLAC__SYS_DARWIN 1
  83877. #endif
  83878. /*** End of inlined file: juce_FlacHeader.h ***/
  83879. #if JUCE_USE_FLAC
  83880. #if HAVE_CONFIG_H
  83881. # include <config.h>
  83882. #endif
  83883. #include <math.h>
  83884. #include <string.h>
  83885. /*** Start of inlined file: fixed.h ***/
  83886. #ifndef FLAC__PRIVATE__FIXED_H
  83887. #define FLAC__PRIVATE__FIXED_H
  83888. #ifdef HAVE_CONFIG_H
  83889. #include <config.h>
  83890. #endif
  83891. /*** Start of inlined file: float.h ***/
  83892. #ifndef FLAC__PRIVATE__FLOAT_H
  83893. #define FLAC__PRIVATE__FLOAT_H
  83894. #ifdef HAVE_CONFIG_H
  83895. #include <config.h>
  83896. #endif
  83897. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83898. typedef double FLAC__double;
  83899. typedef float FLAC__float;
  83900. typedef float FLAC__real;
  83901. #else
  83902. typedef FLAC__int32 FLAC__fixedpoint;
  83903. extern const FLAC__fixedpoint FLAC__FP_ZERO;
  83904. extern const FLAC__fixedpoint FLAC__FP_ONE_HALF;
  83905. extern const FLAC__fixedpoint FLAC__FP_ONE;
  83906. extern const FLAC__fixedpoint FLAC__FP_LN2;
  83907. extern const FLAC__fixedpoint FLAC__FP_E;
  83908. #define FLAC__fixedpoint_trunc(x) ((x)>>16)
  83909. #define FLAC__fixedpoint_mul(x, y) ( (FLAC__fixedpoint) ( ((FLAC__int64)(x)*(FLAC__int64)(y)) >> 16 ) )
  83910. #define FLAC__fixedpoint_div(x, y) ( (FLAC__fixedpoint) ( ( ((FLAC__int64)(x)<<32) / (FLAC__int64)(y) ) >> 16 ) )
  83911. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision);
  83912. #endif
  83913. #endif
  83914. /*** End of inlined file: float.h ***/
  83915. /*** Start of inlined file: format.h ***/
  83916. #ifndef FLAC__PRIVATE__FORMAT_H
  83917. #define FLAC__PRIVATE__FORMAT_H
  83918. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order);
  83919. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize);
  83920. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order);
  83921. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  83922. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  83923. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order);
  83924. #endif
  83925. /*** End of inlined file: format.h ***/
  83926. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83927. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  83928. # ifndef FLAC__NO_ASM
  83929. # ifdef FLAC__CPU_IA32
  83930. # ifdef FLAC__HAS_NASM
  83931. 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]);
  83932. # endif
  83933. # endif
  83934. # endif
  83935. 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]);
  83936. #else
  83937. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  83938. 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]);
  83939. #endif
  83940. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[]);
  83941. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[]);
  83942. #endif
  83943. /*** End of inlined file: fixed.h ***/
  83944. #ifndef M_LN2
  83945. #define M_LN2 0.69314718055994530942
  83946. #endif
  83947. #ifdef min
  83948. #undef min
  83949. #endif
  83950. #define min(x,y) ((x) < (y)? (x) : (y))
  83951. #ifdef local_abs
  83952. #undef local_abs
  83953. #endif
  83954. #define local_abs(x) ((unsigned)((x)<0? -(x) : (x)))
  83955. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  83956. static FLAC__fixedpoint local__compute_rbps_integerized(FLAC__uint32 err, FLAC__uint32 n)
  83957. {
  83958. FLAC__uint32 rbps;
  83959. unsigned bits; /* the number of bits required to represent a number */
  83960. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  83961. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  83962. FLAC__ASSERT(err > 0);
  83963. FLAC__ASSERT(n > 0);
  83964. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  83965. if(err <= n)
  83966. return 0;
  83967. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2(err)+1);
  83968. err <<= fracbits;
  83969. err /= n;
  83970. FLAC__ASSERT(err > 0);
  83971. bits = FLAC__bitmath_ilog2(err)+1;
  83972. if(bits > 16) {
  83973. err >>= (bits-16);
  83974. fracbits -= (bits-16);
  83975. }
  83976. rbps = (FLAC__uint32)err;
  83977. rbps *= FLAC__FP_LN2;
  83978. fracbits += 16;
  83979. FLAC__ASSERT(fracbits >= 0);
  83980. {
  83981. const int f = fracbits & 3;
  83982. if(f) {
  83983. rbps >>= f;
  83984. fracbits -= f;
  83985. }
  83986. }
  83987. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  83988. if(rbps == 0)
  83989. return 0;
  83990. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  83991. FLAC__ASSERT(fracbits >= -3);
  83992. if(fracbits < 16)
  83993. return rbps << (16-fracbits);
  83994. else if(fracbits > 16)
  83995. return rbps >> (fracbits-16);
  83996. else
  83997. return rbps;
  83998. }
  83999. static FLAC__fixedpoint local__compute_rbps_wide_integerized(FLAC__uint64 err, FLAC__uint32 n)
  84000. {
  84001. FLAC__uint32 rbps;
  84002. unsigned bits; /* the number of bits required to represent a number */
  84003. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  84004. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  84005. FLAC__ASSERT(err > 0);
  84006. FLAC__ASSERT(n > 0);
  84007. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  84008. if(err <= n)
  84009. return 0;
  84010. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2_wide(err)+1);
  84011. err <<= fracbits;
  84012. err /= n;
  84013. FLAC__ASSERT(err > 0);
  84014. bits = FLAC__bitmath_ilog2_wide(err)+1;
  84015. if(bits > 16) {
  84016. err >>= (bits-16);
  84017. fracbits -= (bits-16);
  84018. }
  84019. rbps = (FLAC__uint32)err;
  84020. rbps *= FLAC__FP_LN2;
  84021. fracbits += 16;
  84022. FLAC__ASSERT(fracbits >= 0);
  84023. {
  84024. const int f = fracbits & 3;
  84025. if(f) {
  84026. rbps >>= f;
  84027. fracbits -= f;
  84028. }
  84029. }
  84030. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  84031. if(rbps == 0)
  84032. return 0;
  84033. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  84034. FLAC__ASSERT(fracbits >= -3);
  84035. if(fracbits < 16)
  84036. return rbps << (16-fracbits);
  84037. else if(fracbits > 16)
  84038. return rbps >> (fracbits-16);
  84039. else
  84040. return rbps;
  84041. }
  84042. #endif
  84043. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84044. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84045. #else
  84046. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84047. #endif
  84048. {
  84049. FLAC__int32 last_error_0 = data[-1];
  84050. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84051. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84052. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84053. FLAC__int32 error, save;
  84054. FLAC__uint32 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84055. unsigned i, order;
  84056. for(i = 0; i < data_len; i++) {
  84057. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84058. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84059. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84060. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84061. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84062. }
  84063. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84064. order = 0;
  84065. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84066. order = 1;
  84067. else if(total_error_2 < min(total_error_3, total_error_4))
  84068. order = 2;
  84069. else if(total_error_3 < total_error_4)
  84070. order = 3;
  84071. else
  84072. order = 4;
  84073. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84074. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84075. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84076. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84077. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84078. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84079. 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);
  84080. 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);
  84081. 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);
  84082. 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);
  84083. 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);
  84084. #else
  84085. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_integerized(total_error_0, data_len) : 0;
  84086. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_integerized(total_error_1, data_len) : 0;
  84087. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_integerized(total_error_2, data_len) : 0;
  84088. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_integerized(total_error_3, data_len) : 0;
  84089. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_integerized(total_error_4, data_len) : 0;
  84090. #endif
  84091. return order;
  84092. }
  84093. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84094. 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])
  84095. #else
  84096. 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])
  84097. #endif
  84098. {
  84099. FLAC__int32 last_error_0 = data[-1];
  84100. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84101. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84102. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84103. FLAC__int32 error, save;
  84104. FLAC__uint64 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84105. unsigned i, order;
  84106. for(i = 0; i < data_len; i++) {
  84107. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84108. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84109. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84110. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84111. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84112. }
  84113. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84114. order = 0;
  84115. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84116. order = 1;
  84117. else if(total_error_2 < min(total_error_3, total_error_4))
  84118. order = 2;
  84119. else if(total_error_3 < total_error_4)
  84120. order = 3;
  84121. else
  84122. order = 4;
  84123. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84124. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84125. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84126. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84127. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84128. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84129. #if defined _MSC_VER || defined __MINGW32__
  84130. 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);
  84131. 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);
  84132. 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);
  84133. 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);
  84134. 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);
  84135. #else
  84136. 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);
  84137. 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);
  84138. 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);
  84139. 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);
  84140. 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);
  84141. #endif
  84142. #else
  84143. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_wide_integerized(total_error_0, data_len) : 0;
  84144. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_wide_integerized(total_error_1, data_len) : 0;
  84145. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_wide_integerized(total_error_2, data_len) : 0;
  84146. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_wide_integerized(total_error_3, data_len) : 0;
  84147. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_wide_integerized(total_error_4, data_len) : 0;
  84148. #endif
  84149. return order;
  84150. }
  84151. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[])
  84152. {
  84153. const int idata_len = (int)data_len;
  84154. int i;
  84155. switch(order) {
  84156. case 0:
  84157. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84158. memcpy(residual, data, sizeof(residual[0])*data_len);
  84159. break;
  84160. case 1:
  84161. for(i = 0; i < idata_len; i++)
  84162. residual[i] = data[i] - data[i-1];
  84163. break;
  84164. case 2:
  84165. for(i = 0; i < idata_len; i++)
  84166. #if 1 /* OPT: may be faster with some compilers on some systems */
  84167. residual[i] = data[i] - (data[i-1] << 1) + data[i-2];
  84168. #else
  84169. residual[i] = data[i] - 2*data[i-1] + data[i-2];
  84170. #endif
  84171. break;
  84172. case 3:
  84173. for(i = 0; i < idata_len; i++)
  84174. #if 1 /* OPT: may be faster with some compilers on some systems */
  84175. residual[i] = data[i] - (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) - data[i-3];
  84176. #else
  84177. residual[i] = data[i] - 3*data[i-1] + 3*data[i-2] - data[i-3];
  84178. #endif
  84179. break;
  84180. case 4:
  84181. for(i = 0; i < idata_len; i++)
  84182. #if 1 /* OPT: may be faster with some compilers on some systems */
  84183. residual[i] = data[i] - ((data[i-1]+data[i-3])<<2) + ((data[i-2]<<2) + (data[i-2]<<1)) + data[i-4];
  84184. #else
  84185. residual[i] = data[i] - 4*data[i-1] + 6*data[i-2] - 4*data[i-3] + data[i-4];
  84186. #endif
  84187. break;
  84188. default:
  84189. FLAC__ASSERT(0);
  84190. }
  84191. }
  84192. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[])
  84193. {
  84194. int i, idata_len = (int)data_len;
  84195. switch(order) {
  84196. case 0:
  84197. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84198. memcpy(data, residual, sizeof(residual[0])*data_len);
  84199. break;
  84200. case 1:
  84201. for(i = 0; i < idata_len; i++)
  84202. data[i] = residual[i] + data[i-1];
  84203. break;
  84204. case 2:
  84205. for(i = 0; i < idata_len; i++)
  84206. #if 1 /* OPT: may be faster with some compilers on some systems */
  84207. data[i] = residual[i] + (data[i-1]<<1) - data[i-2];
  84208. #else
  84209. data[i] = residual[i] + 2*data[i-1] - data[i-2];
  84210. #endif
  84211. break;
  84212. case 3:
  84213. for(i = 0; i < idata_len; i++)
  84214. #if 1 /* OPT: may be faster with some compilers on some systems */
  84215. data[i] = residual[i] + (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) + data[i-3];
  84216. #else
  84217. data[i] = residual[i] + 3*data[i-1] - 3*data[i-2] + data[i-3];
  84218. #endif
  84219. break;
  84220. case 4:
  84221. for(i = 0; i < idata_len; i++)
  84222. #if 1 /* OPT: may be faster with some compilers on some systems */
  84223. data[i] = residual[i] + ((data[i-1]+data[i-3])<<2) - ((data[i-2]<<2) + (data[i-2]<<1)) - data[i-4];
  84224. #else
  84225. data[i] = residual[i] + 4*data[i-1] - 6*data[i-2] + 4*data[i-3] - data[i-4];
  84226. #endif
  84227. break;
  84228. default:
  84229. FLAC__ASSERT(0);
  84230. }
  84231. }
  84232. #endif
  84233. /*** End of inlined file: fixed.c ***/
  84234. /*** Start of inlined file: float.c ***/
  84235. /*** Start of inlined file: juce_FlacHeader.h ***/
  84236. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84237. // tasks..
  84238. #define VERSION "1.2.1"
  84239. #define FLAC__NO_DLL 1
  84240. #if JUCE_MSVC
  84241. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84242. #endif
  84243. #if JUCE_MAC
  84244. #define FLAC__SYS_DARWIN 1
  84245. #endif
  84246. /*** End of inlined file: juce_FlacHeader.h ***/
  84247. #if JUCE_USE_FLAC
  84248. #if HAVE_CONFIG_H
  84249. # include <config.h>
  84250. #endif
  84251. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  84252. #ifdef _MSC_VER
  84253. #define FLAC__U64L(x) x
  84254. #else
  84255. #define FLAC__U64L(x) x##LLU
  84256. #endif
  84257. const FLAC__fixedpoint FLAC__FP_ZERO = 0;
  84258. const FLAC__fixedpoint FLAC__FP_ONE_HALF = 0x00008000;
  84259. const FLAC__fixedpoint FLAC__FP_ONE = 0x00010000;
  84260. const FLAC__fixedpoint FLAC__FP_LN2 = 45426;
  84261. const FLAC__fixedpoint FLAC__FP_E = 178145;
  84262. #define LOG2_LOOKUP_PRECISION 16
  84263. static const FLAC__uint32 log2_lookup[][LOG2_LOOKUP_PRECISION] = {
  84264. {
  84265. 0x00000000,
  84266. 0x00000001,
  84267. 0x00000000,
  84268. 0x00000000,
  84269. 0x00000000,
  84270. 0x00000000,
  84271. 0x00000000,
  84272. 0x00000000,
  84273. 0x00000000,
  84274. 0x00000000,
  84275. 0x00000000,
  84276. 0x00000000,
  84277. 0x00000000,
  84278. 0x00000000,
  84279. 0x00000000,
  84280. 0x00000000
  84281. },
  84282. {
  84283. 0x00000000,
  84284. 0x00000010,
  84285. 0x00000007,
  84286. 0x00000003,
  84287. 0x00000001,
  84288. 0x00000001,
  84289. 0x00000000,
  84290. 0x00000000,
  84291. 0x00000000,
  84292. 0x00000000,
  84293. 0x00000000,
  84294. 0x00000000,
  84295. 0x00000000,
  84296. 0x00000000,
  84297. 0x00000000,
  84298. 0x00000000
  84299. },
  84300. {
  84301. 0x00000000,
  84302. 0x00000100,
  84303. 0x0000006a,
  84304. 0x00000031,
  84305. 0x00000018,
  84306. 0x0000000c,
  84307. 0x00000006,
  84308. 0x00000003,
  84309. 0x00000001,
  84310. 0x00000001,
  84311. 0x00000000,
  84312. 0x00000000,
  84313. 0x00000000,
  84314. 0x00000000,
  84315. 0x00000000,
  84316. 0x00000000
  84317. },
  84318. {
  84319. 0x00000000,
  84320. 0x00001000,
  84321. 0x000006a4,
  84322. 0x00000315,
  84323. 0x0000017d,
  84324. 0x000000bc,
  84325. 0x0000005d,
  84326. 0x0000002e,
  84327. 0x00000017,
  84328. 0x0000000c,
  84329. 0x00000006,
  84330. 0x00000003,
  84331. 0x00000001,
  84332. 0x00000001,
  84333. 0x00000000,
  84334. 0x00000000
  84335. },
  84336. {
  84337. 0x00000000,
  84338. 0x00010000,
  84339. 0x00006a40,
  84340. 0x00003151,
  84341. 0x000017d6,
  84342. 0x00000bba,
  84343. 0x000005d1,
  84344. 0x000002e6,
  84345. 0x00000172,
  84346. 0x000000b9,
  84347. 0x0000005c,
  84348. 0x0000002e,
  84349. 0x00000017,
  84350. 0x0000000c,
  84351. 0x00000006,
  84352. 0x00000003
  84353. },
  84354. {
  84355. 0x00000000,
  84356. 0x00100000,
  84357. 0x0006a3fe,
  84358. 0x00031513,
  84359. 0x00017d60,
  84360. 0x0000bb9d,
  84361. 0x00005d10,
  84362. 0x00002e59,
  84363. 0x00001721,
  84364. 0x00000b8e,
  84365. 0x000005c6,
  84366. 0x000002e3,
  84367. 0x00000171,
  84368. 0x000000b9,
  84369. 0x0000005c,
  84370. 0x0000002e
  84371. },
  84372. {
  84373. 0x00000000,
  84374. 0x01000000,
  84375. 0x006a3fe6,
  84376. 0x00315130,
  84377. 0x0017d605,
  84378. 0x000bb9ca,
  84379. 0x0005d0fc,
  84380. 0x0002e58f,
  84381. 0x0001720e,
  84382. 0x0000b8d8,
  84383. 0x00005c61,
  84384. 0x00002e2d,
  84385. 0x00001716,
  84386. 0x00000b8b,
  84387. 0x000005c5,
  84388. 0x000002e3
  84389. },
  84390. {
  84391. 0x00000000,
  84392. 0x10000000,
  84393. 0x06a3fe5c,
  84394. 0x03151301,
  84395. 0x017d6049,
  84396. 0x00bb9ca6,
  84397. 0x005d0fba,
  84398. 0x002e58f7,
  84399. 0x001720da,
  84400. 0x000b8d87,
  84401. 0x0005c60b,
  84402. 0x0002e2d7,
  84403. 0x00017160,
  84404. 0x0000b8ad,
  84405. 0x00005c56,
  84406. 0x00002e2b
  84407. }
  84408. };
  84409. #if 0
  84410. static const FLAC__uint64 log2_lookup_wide[] = {
  84411. {
  84412. 0x00000000,
  84413. FLAC__U64L(0x100000000),
  84414. FLAC__U64L(0x6a3fe5c6),
  84415. FLAC__U64L(0x31513015),
  84416. FLAC__U64L(0x17d60497),
  84417. FLAC__U64L(0x0bb9ca65),
  84418. FLAC__U64L(0x05d0fba2),
  84419. FLAC__U64L(0x02e58f74),
  84420. FLAC__U64L(0x01720d9c),
  84421. FLAC__U64L(0x00b8d875),
  84422. FLAC__U64L(0x005c60aa),
  84423. FLAC__U64L(0x002e2d72),
  84424. FLAC__U64L(0x00171600),
  84425. FLAC__U64L(0x000b8ad2),
  84426. FLAC__U64L(0x0005c55d),
  84427. FLAC__U64L(0x0002e2ac)
  84428. },
  84429. {
  84430. 0x00000000,
  84431. FLAC__U64L(0x1000000000000),
  84432. FLAC__U64L(0x6a3fe5c60429),
  84433. FLAC__U64L(0x315130157f7a),
  84434. FLAC__U64L(0x17d60496cfbb),
  84435. FLAC__U64L(0xbb9ca64ecac),
  84436. FLAC__U64L(0x5d0fba187cd),
  84437. FLAC__U64L(0x2e58f7441ee),
  84438. FLAC__U64L(0x1720d9c06a8),
  84439. FLAC__U64L(0xb8d8752173),
  84440. FLAC__U64L(0x5c60aa252e),
  84441. FLAC__U64L(0x2e2d71b0d8),
  84442. FLAC__U64L(0x1716001719),
  84443. FLAC__U64L(0xb8ad1de1b),
  84444. FLAC__U64L(0x5c55d640d),
  84445. FLAC__U64L(0x2e2abcf52)
  84446. }
  84447. };
  84448. #endif
  84449. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision)
  84450. {
  84451. const FLAC__uint32 ONE = (1u << fracbits);
  84452. const FLAC__uint32 *table = log2_lookup[fracbits >> 2];
  84453. FLAC__ASSERT(fracbits < 32);
  84454. FLAC__ASSERT((fracbits & 0x3) == 0);
  84455. if(x < ONE)
  84456. return 0;
  84457. if(precision > LOG2_LOOKUP_PRECISION)
  84458. precision = LOG2_LOOKUP_PRECISION;
  84459. {
  84460. FLAC__uint32 y = 0;
  84461. FLAC__uint32 z = x >> 1, k = 1;
  84462. while (x > ONE && k < precision) {
  84463. if (x - z >= ONE) {
  84464. x -= z;
  84465. z = x >> k;
  84466. y += table[k];
  84467. }
  84468. else {
  84469. z >>= 1;
  84470. k++;
  84471. }
  84472. }
  84473. return y;
  84474. }
  84475. }
  84476. #endif /* defined FLAC__INTEGER_ONLY_LIBRARY */
  84477. #endif
  84478. /*** End of inlined file: float.c ***/
  84479. /*** Start of inlined file: format.c ***/
  84480. /*** Start of inlined file: juce_FlacHeader.h ***/
  84481. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84482. // tasks..
  84483. #define VERSION "1.2.1"
  84484. #define FLAC__NO_DLL 1
  84485. #if JUCE_MSVC
  84486. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84487. #endif
  84488. #if JUCE_MAC
  84489. #define FLAC__SYS_DARWIN 1
  84490. #endif
  84491. /*** End of inlined file: juce_FlacHeader.h ***/
  84492. #if JUCE_USE_FLAC
  84493. #if HAVE_CONFIG_H
  84494. # include <config.h>
  84495. #endif
  84496. #include <stdio.h>
  84497. #include <stdlib.h> /* for qsort() */
  84498. #include <string.h> /* for memset() */
  84499. #ifndef FLaC__INLINE
  84500. #define FLaC__INLINE
  84501. #endif
  84502. #ifdef min
  84503. #undef min
  84504. #endif
  84505. #define min(a,b) ((a)<(b)?(a):(b))
  84506. #ifdef _MSC_VER
  84507. #define FLAC__U64L(x) x
  84508. #else
  84509. #define FLAC__U64L(x) x##LLU
  84510. #endif
  84511. FLAC_API const char *FLAC__VERSION_STRING = VERSION
  84512. ;
  84513. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINW32__
  84514. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC 1.2.1 20070917";
  84515. #else
  84516. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " VERSION " 20070917";
  84517. #endif
  84518. FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4] = { 'f','L','a','C' };
  84519. FLAC_API const unsigned FLAC__STREAM_SYNC = 0x664C6143;
  84520. FLAC_API const unsigned FLAC__STREAM_SYNC_LEN = 32; /* bits */
  84521. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN = 16; /* bits */
  84522. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN = 16; /* bits */
  84523. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN = 24; /* bits */
  84524. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN = 24; /* bits */
  84525. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN = 20; /* bits */
  84526. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN = 3; /* bits */
  84527. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN = 5; /* bits */
  84528. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN = 36; /* bits */
  84529. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN = 128; /* bits */
  84530. FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN = 32; /* bits */
  84531. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN = 64; /* bits */
  84532. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN = 64; /* bits */
  84533. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN = 16; /* bits */
  84534. FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER = FLAC__U64L(0xffffffffffffffff);
  84535. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN = 32; /* bits */
  84536. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN = 32; /* bits */
  84537. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN = 64; /* bits */
  84538. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN = 8; /* bits */
  84539. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN = 3*8; /* bits */
  84540. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN = 64; /* bits */
  84541. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN = 8; /* bits */
  84542. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN = 12*8; /* bits */
  84543. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN = 1; /* bit */
  84544. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN = 1; /* bit */
  84545. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN = 6+13*8; /* bits */
  84546. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN = 8; /* bits */
  84547. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN = 128*8; /* bits */
  84548. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN = 64; /* bits */
  84549. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN = 1; /* bit */
  84550. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN = 7+258*8; /* bits */
  84551. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN = 8; /* bits */
  84552. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN = 32; /* bits */
  84553. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN = 32; /* bits */
  84554. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN = 32; /* bits */
  84555. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN = 32; /* bits */
  84556. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN = 32; /* bits */
  84557. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN = 32; /* bits */
  84558. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN = 32; /* bits */
  84559. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN = 32; /* bits */
  84560. FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN = 1; /* bits */
  84561. FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN = 7; /* bits */
  84562. FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN = 24; /* bits */
  84563. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC = 0x3ffe;
  84564. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN = 14; /* bits */
  84565. FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN = 1; /* bits */
  84566. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN = 1; /* bits */
  84567. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN = 4; /* bits */
  84568. FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN = 4; /* bits */
  84569. FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN = 4; /* bits */
  84570. FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN = 3; /* bits */
  84571. FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN = 1; /* bits */
  84572. FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN = 8; /* bits */
  84573. FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN = 16; /* bits */
  84574. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN = 2; /* bits */
  84575. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN = 4; /* bits */
  84576. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN = 4; /* bits */
  84577. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN = 5; /* bits */
  84578. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN = 5; /* bits */
  84579. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER = 15; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN)-1 */
  84580. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER = 31; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN)-1 */
  84581. FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[] = {
  84582. "PARTITIONED_RICE",
  84583. "PARTITIONED_RICE2"
  84584. };
  84585. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN = 4; /* bits */
  84586. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN = 5; /* bits */
  84587. FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN = 1; /* bits */
  84588. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN = 6; /* bits */
  84589. FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN = 1; /* bits */
  84590. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK = 0x00;
  84591. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK = 0x02;
  84592. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK = 0x10;
  84593. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK = 0x40;
  84594. FLAC_API const char * const FLAC__SubframeTypeString[] = {
  84595. "CONSTANT",
  84596. "VERBATIM",
  84597. "FIXED",
  84598. "LPC"
  84599. };
  84600. FLAC_API const char * const FLAC__ChannelAssignmentString[] = {
  84601. "INDEPENDENT",
  84602. "LEFT_SIDE",
  84603. "RIGHT_SIDE",
  84604. "MID_SIDE"
  84605. };
  84606. FLAC_API const char * const FLAC__FrameNumberTypeString[] = {
  84607. "FRAME_NUMBER_TYPE_FRAME_NUMBER",
  84608. "FRAME_NUMBER_TYPE_SAMPLE_NUMBER"
  84609. };
  84610. FLAC_API const char * const FLAC__MetadataTypeString[] = {
  84611. "STREAMINFO",
  84612. "PADDING",
  84613. "APPLICATION",
  84614. "SEEKTABLE",
  84615. "VORBIS_COMMENT",
  84616. "CUESHEET",
  84617. "PICTURE"
  84618. };
  84619. FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[] = {
  84620. "Other",
  84621. "32x32 pixels 'file icon' (PNG only)",
  84622. "Other file icon",
  84623. "Cover (front)",
  84624. "Cover (back)",
  84625. "Leaflet page",
  84626. "Media (e.g. label side of CD)",
  84627. "Lead artist/lead performer/soloist",
  84628. "Artist/performer",
  84629. "Conductor",
  84630. "Band/Orchestra",
  84631. "Composer",
  84632. "Lyricist/text writer",
  84633. "Recording Location",
  84634. "During recording",
  84635. "During performance",
  84636. "Movie/video screen capture",
  84637. "A bright coloured fish",
  84638. "Illustration",
  84639. "Band/artist logotype",
  84640. "Publisher/Studio logotype"
  84641. };
  84642. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate)
  84643. {
  84644. if(sample_rate == 0 || sample_rate > FLAC__MAX_SAMPLE_RATE) {
  84645. return false;
  84646. }
  84647. else
  84648. return true;
  84649. }
  84650. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate)
  84651. {
  84652. if(
  84653. !FLAC__format_sample_rate_is_valid(sample_rate) ||
  84654. (
  84655. sample_rate >= (1u << 16) &&
  84656. !(sample_rate % 1000 == 0 || sample_rate % 10 == 0)
  84657. )
  84658. ) {
  84659. return false;
  84660. }
  84661. else
  84662. return true;
  84663. }
  84664. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table)
  84665. {
  84666. unsigned i;
  84667. FLAC__uint64 prev_sample_number = 0;
  84668. FLAC__bool got_prev = false;
  84669. FLAC__ASSERT(0 != seek_table);
  84670. for(i = 0; i < seek_table->num_points; i++) {
  84671. if(got_prev) {
  84672. if(
  84673. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  84674. seek_table->points[i].sample_number <= prev_sample_number
  84675. )
  84676. return false;
  84677. }
  84678. prev_sample_number = seek_table->points[i].sample_number;
  84679. got_prev = true;
  84680. }
  84681. return true;
  84682. }
  84683. static int seekpoint_compare_(const FLAC__StreamMetadata_SeekPoint *l, const FLAC__StreamMetadata_SeekPoint *r)
  84684. {
  84685. if(l->sample_number == r->sample_number)
  84686. return 0;
  84687. else if(l->sample_number < r->sample_number)
  84688. return -1;
  84689. else
  84690. return 1;
  84691. }
  84692. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table)
  84693. {
  84694. unsigned i, j;
  84695. FLAC__bool first;
  84696. FLAC__ASSERT(0 != seek_table);
  84697. qsort(seek_table->points, seek_table->num_points, sizeof(FLAC__StreamMetadata_SeekPoint), (int (*)(const void *, const void *))seekpoint_compare_);
  84698. first = true;
  84699. for(i = j = 0; i < seek_table->num_points; i++) {
  84700. if(seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER) {
  84701. if(!first) {
  84702. if(seek_table->points[i].sample_number == seek_table->points[j-1].sample_number)
  84703. continue;
  84704. }
  84705. }
  84706. first = false;
  84707. seek_table->points[j++] = seek_table->points[i];
  84708. }
  84709. for(i = j; i < seek_table->num_points; i++) {
  84710. seek_table->points[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  84711. seek_table->points[i].stream_offset = 0;
  84712. seek_table->points[i].frame_samples = 0;
  84713. }
  84714. return j;
  84715. }
  84716. static FLaC__INLINE unsigned utf8len_(const FLAC__byte *utf8)
  84717. {
  84718. FLAC__ASSERT(0 != utf8);
  84719. if ((utf8[0] & 0x80) == 0) {
  84720. return 1;
  84721. }
  84722. else if ((utf8[0] & 0xE0) == 0xC0 && (utf8[1] & 0xC0) == 0x80) {
  84723. if ((utf8[0] & 0xFE) == 0xC0) /* overlong sequence check */
  84724. return 0;
  84725. return 2;
  84726. }
  84727. else if ((utf8[0] & 0xF0) == 0xE0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80) {
  84728. if (utf8[0] == 0xE0 && (utf8[1] & 0xE0) == 0x80) /* overlong sequence check */
  84729. return 0;
  84730. if (utf8[0] == 0xED && (utf8[1] & 0xE0) == 0xA0) /* D800-DFFF */
  84731. return 0;
  84732. if (utf8[0] == 0xEF && utf8[1] == 0xBF && (utf8[2] & 0xFE) == 0xBE) /* FFFE-FFFF */
  84733. return 0;
  84734. return 3;
  84735. }
  84736. else if ((utf8[0] & 0xF8) == 0xF0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80) {
  84737. if (utf8[0] == 0xF0 && (utf8[1] & 0xF0) == 0x80) /* overlong sequence check */
  84738. return 0;
  84739. return 4;
  84740. }
  84741. else if ((utf8[0] & 0xFC) == 0xF8 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80 && (utf8[4] & 0xC0) == 0x80) {
  84742. if (utf8[0] == 0xF8 && (utf8[1] & 0xF8) == 0x80) /* overlong sequence check */
  84743. return 0;
  84744. return 5;
  84745. }
  84746. 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) {
  84747. if (utf8[0] == 0xFC && (utf8[1] & 0xFC) == 0x80) /* overlong sequence check */
  84748. return 0;
  84749. return 6;
  84750. }
  84751. else {
  84752. return 0;
  84753. }
  84754. }
  84755. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name)
  84756. {
  84757. char c;
  84758. for(c = *name; c; c = *(++name))
  84759. if(c < 0x20 || c == 0x3d || c > 0x7d)
  84760. return false;
  84761. return true;
  84762. }
  84763. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length)
  84764. {
  84765. if(length == (unsigned)(-1)) {
  84766. while(*value) {
  84767. unsigned n = utf8len_(value);
  84768. if(n == 0)
  84769. return false;
  84770. value += n;
  84771. }
  84772. }
  84773. else {
  84774. const FLAC__byte *end = value + length;
  84775. while(value < end) {
  84776. unsigned n = utf8len_(value);
  84777. if(n == 0)
  84778. return false;
  84779. value += n;
  84780. }
  84781. if(value != end)
  84782. return false;
  84783. }
  84784. return true;
  84785. }
  84786. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length)
  84787. {
  84788. const FLAC__byte *s, *end;
  84789. for(s = entry, end = s + length; s < end && *s != '='; s++) {
  84790. if(*s < 0x20 || *s > 0x7D)
  84791. return false;
  84792. }
  84793. if(s == end)
  84794. return false;
  84795. s++; /* skip '=' */
  84796. while(s < end) {
  84797. unsigned n = utf8len_(s);
  84798. if(n == 0)
  84799. return false;
  84800. s += n;
  84801. }
  84802. if(s != end)
  84803. return false;
  84804. return true;
  84805. }
  84806. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation)
  84807. {
  84808. unsigned i, j;
  84809. if(check_cd_da_subset) {
  84810. if(cue_sheet->lead_in < 2 * 44100) {
  84811. if(violation) *violation = "CD-DA cue sheet must have a lead-in length of at least 2 seconds";
  84812. return false;
  84813. }
  84814. if(cue_sheet->lead_in % 588 != 0) {
  84815. if(violation) *violation = "CD-DA cue sheet lead-in length must be evenly divisible by 588 samples";
  84816. return false;
  84817. }
  84818. }
  84819. if(cue_sheet->num_tracks == 0) {
  84820. if(violation) *violation = "cue sheet must have at least one track (the lead-out)";
  84821. return false;
  84822. }
  84823. if(check_cd_da_subset && cue_sheet->tracks[cue_sheet->num_tracks-1].number != 170) {
  84824. if(violation) *violation = "CD-DA cue sheet must have a lead-out track number 170 (0xAA)";
  84825. return false;
  84826. }
  84827. for(i = 0; i < cue_sheet->num_tracks; i++) {
  84828. if(cue_sheet->tracks[i].number == 0) {
  84829. if(violation) *violation = "cue sheet may not have a track number 0";
  84830. return false;
  84831. }
  84832. if(check_cd_da_subset) {
  84833. if(!((cue_sheet->tracks[i].number >= 1 && cue_sheet->tracks[i].number <= 99) || cue_sheet->tracks[i].number == 170)) {
  84834. if(violation) *violation = "CD-DA cue sheet track number must be 1-99 or 170";
  84835. return false;
  84836. }
  84837. }
  84838. if(check_cd_da_subset && cue_sheet->tracks[i].offset % 588 != 0) {
  84839. if(violation) {
  84840. if(i == cue_sheet->num_tracks-1) /* the lead-out track... */
  84841. *violation = "CD-DA cue sheet lead-out offset must be evenly divisible by 588 samples";
  84842. else
  84843. *violation = "CD-DA cue sheet track offset must be evenly divisible by 588 samples";
  84844. }
  84845. return false;
  84846. }
  84847. if(i < cue_sheet->num_tracks - 1) {
  84848. if(cue_sheet->tracks[i].num_indices == 0) {
  84849. if(violation) *violation = "cue sheet track must have at least one index point";
  84850. return false;
  84851. }
  84852. if(cue_sheet->tracks[i].indices[0].number > 1) {
  84853. if(violation) *violation = "cue sheet track's first index number must be 0 or 1";
  84854. return false;
  84855. }
  84856. }
  84857. for(j = 0; j < cue_sheet->tracks[i].num_indices; j++) {
  84858. if(check_cd_da_subset && cue_sheet->tracks[i].indices[j].offset % 588 != 0) {
  84859. if(violation) *violation = "CD-DA cue sheet track index offset must be evenly divisible by 588 samples";
  84860. return false;
  84861. }
  84862. if(j > 0) {
  84863. if(cue_sheet->tracks[i].indices[j].number != cue_sheet->tracks[i].indices[j-1].number + 1) {
  84864. if(violation) *violation = "cue sheet track index numbers must increase by 1";
  84865. return false;
  84866. }
  84867. }
  84868. }
  84869. }
  84870. return true;
  84871. }
  84872. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation)
  84873. {
  84874. char *p;
  84875. FLAC__byte *b;
  84876. for(p = picture->mime_type; *p; p++) {
  84877. if(*p < 0x20 || *p > 0x7e) {
  84878. if(violation) *violation = "MIME type string must contain only printable ASCII characters (0x20-0x7e)";
  84879. return false;
  84880. }
  84881. }
  84882. for(b = picture->description; *b; ) {
  84883. unsigned n = utf8len_(b);
  84884. if(n == 0) {
  84885. if(violation) *violation = "description string must be valid UTF-8";
  84886. return false;
  84887. }
  84888. b += n;
  84889. }
  84890. return true;
  84891. }
  84892. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order)
  84893. {
  84894. return
  84895. FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(
  84896. FLAC__format_get_max_rice_partition_order_from_blocksize(blocksize),
  84897. blocksize,
  84898. predictor_order
  84899. );
  84900. }
  84901. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize)
  84902. {
  84903. unsigned max_rice_partition_order = 0;
  84904. while(!(blocksize & 1)) {
  84905. max_rice_partition_order++;
  84906. blocksize >>= 1;
  84907. }
  84908. return min(FLAC__MAX_RICE_PARTITION_ORDER, max_rice_partition_order);
  84909. }
  84910. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order)
  84911. {
  84912. unsigned max_rice_partition_order = limit;
  84913. while(max_rice_partition_order > 0 && (blocksize >> max_rice_partition_order) <= predictor_order)
  84914. max_rice_partition_order--;
  84915. FLAC__ASSERT(
  84916. (max_rice_partition_order == 0 && blocksize >= predictor_order) ||
  84917. (max_rice_partition_order > 0 && blocksize >> max_rice_partition_order > predictor_order)
  84918. );
  84919. return max_rice_partition_order;
  84920. }
  84921. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  84922. {
  84923. FLAC__ASSERT(0 != object);
  84924. object->parameters = 0;
  84925. object->raw_bits = 0;
  84926. object->capacity_by_order = 0;
  84927. }
  84928. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  84929. {
  84930. FLAC__ASSERT(0 != object);
  84931. if(0 != object->parameters)
  84932. free(object->parameters);
  84933. if(0 != object->raw_bits)
  84934. free(object->raw_bits);
  84935. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(object);
  84936. }
  84937. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order)
  84938. {
  84939. FLAC__ASSERT(0 != object);
  84940. FLAC__ASSERT(object->capacity_by_order > 0 || (0 == object->parameters && 0 == object->raw_bits));
  84941. if(object->capacity_by_order < max_partition_order) {
  84942. if(0 == (object->parameters = (unsigned*)realloc(object->parameters, sizeof(unsigned)*(1 << max_partition_order))))
  84943. return false;
  84944. if(0 == (object->raw_bits = (unsigned*)realloc(object->raw_bits, sizeof(unsigned)*(1 << max_partition_order))))
  84945. return false;
  84946. memset(object->raw_bits, 0, sizeof(unsigned)*(1 << max_partition_order));
  84947. object->capacity_by_order = max_partition_order;
  84948. }
  84949. return true;
  84950. }
  84951. #endif
  84952. /*** End of inlined file: format.c ***/
  84953. /*** Start of inlined file: lpc_flac.c ***/
  84954. /*** Start of inlined file: juce_FlacHeader.h ***/
  84955. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84956. // tasks..
  84957. #define VERSION "1.2.1"
  84958. #define FLAC__NO_DLL 1
  84959. #if JUCE_MSVC
  84960. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84961. #endif
  84962. #if JUCE_MAC
  84963. #define FLAC__SYS_DARWIN 1
  84964. #endif
  84965. /*** End of inlined file: juce_FlacHeader.h ***/
  84966. #if JUCE_USE_FLAC
  84967. #if HAVE_CONFIG_H
  84968. # include <config.h>
  84969. #endif
  84970. #include <math.h>
  84971. /*** Start of inlined file: lpc.h ***/
  84972. #ifndef FLAC__PRIVATE__LPC_H
  84973. #define FLAC__PRIVATE__LPC_H
  84974. #ifdef HAVE_CONFIG_H
  84975. #include <config.h>
  84976. #endif
  84977. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84978. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len);
  84979. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84980. #ifndef FLAC__NO_ASM
  84981. # ifdef FLAC__CPU_IA32
  84982. # ifdef FLAC__HAS_NASM
  84983. void FLAC__lpc_compute_autocorrelation_asm_ia32(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84984. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84985. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84986. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84987. void FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84988. # endif
  84989. # endif
  84990. #endif
  84991. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[]);
  84992. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift);
  84993. 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[]);
  84994. 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[]);
  84995. #ifndef FLAC__NO_ASM
  84996. # ifdef FLAC__CPU_IA32
  84997. # ifdef FLAC__HAS_NASM
  84998. 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[]);
  84999. 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[]);
  85000. # endif
  85001. # endif
  85002. #endif
  85003. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85004. 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[]);
  85005. 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[]);
  85006. #ifndef FLAC__NO_ASM
  85007. # ifdef FLAC__CPU_IA32
  85008. # ifdef FLAC__HAS_NASM
  85009. 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[]);
  85010. 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[]);
  85011. # endif /* FLAC__HAS_NASM */
  85012. # elif defined FLAC__CPU_PPC
  85013. 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[]);
  85014. 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[]);
  85015. # endif/* FLAC__CPU_IA32 || FLAC__CPU_PPC */
  85016. #endif /* FLAC__NO_ASM */
  85017. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85018. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples);
  85019. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale);
  85020. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order);
  85021. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85022. #endif
  85023. /*** End of inlined file: lpc.h ***/
  85024. #if defined DEBUG || defined FLAC__OVERFLOW_DETECT || defined FLAC__OVERFLOW_DETECT_VERBOSE
  85025. #include <stdio.h>
  85026. #endif
  85027. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85028. #ifndef M_LN2
  85029. #define M_LN2 0.69314718055994530942
  85030. #endif
  85031. #define FLAC__LPC_UNROLLED_FILTER_LOOPS
  85032. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len)
  85033. {
  85034. unsigned i;
  85035. for(i = 0; i < data_len; i++)
  85036. out[i] = in[i] * window[i];
  85037. }
  85038. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[])
  85039. {
  85040. #if 0
  85041. FLAC__real d;
  85042. unsigned i;
  85043. FLAC__ASSERT(lag > 0);
  85044. FLAC__ASSERT(lag <= data_len);
  85045. while(lag--) {
  85046. for(i = lag, d = 0.0; i < data_len; i++)
  85047. d += data[i] * data[i - lag];
  85048. autoc[lag] = d;
  85049. }
  85050. #endif
  85051. FLAC__real d;
  85052. unsigned sample, coeff;
  85053. const unsigned limit = data_len - lag;
  85054. FLAC__ASSERT(lag > 0);
  85055. FLAC__ASSERT(lag <= data_len);
  85056. for(coeff = 0; coeff < lag; coeff++)
  85057. autoc[coeff] = 0.0;
  85058. for(sample = 0; sample <= limit; sample++) {
  85059. d = data[sample];
  85060. for(coeff = 0; coeff < lag; coeff++)
  85061. autoc[coeff] += d * data[sample+coeff];
  85062. }
  85063. for(; sample < data_len; sample++) {
  85064. d = data[sample];
  85065. for(coeff = 0; coeff < data_len - sample; coeff++)
  85066. autoc[coeff] += d * data[sample+coeff];
  85067. }
  85068. }
  85069. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[])
  85070. {
  85071. unsigned i, j;
  85072. FLAC__double r, err, ref[FLAC__MAX_LPC_ORDER], lpc[FLAC__MAX_LPC_ORDER];
  85073. FLAC__ASSERT(0 != max_order);
  85074. FLAC__ASSERT(0 < *max_order);
  85075. FLAC__ASSERT(*max_order <= FLAC__MAX_LPC_ORDER);
  85076. FLAC__ASSERT(autoc[0] != 0.0);
  85077. err = autoc[0];
  85078. for(i = 0; i < *max_order; i++) {
  85079. r = -autoc[i+1];
  85080. for(j = 0; j < i; j++)
  85081. r -= lpc[j] * autoc[i-j];
  85082. ref[i] = (r/=err);
  85083. lpc[i]=r;
  85084. for(j = 0; j < (i>>1); j++) {
  85085. FLAC__double tmp = lpc[j];
  85086. lpc[j] += r * lpc[i-1-j];
  85087. lpc[i-1-j] += r * tmp;
  85088. }
  85089. if(i & 1)
  85090. lpc[j] += lpc[j] * r;
  85091. err *= (1.0 - r * r);
  85092. for(j = 0; j <= i; j++)
  85093. lp_coeff[i][j] = (FLAC__real)(-lpc[j]); /* negate FIR filter coeff to get predictor coeff */
  85094. error[i] = err;
  85095. if(err == 0.0) {
  85096. *max_order = i+1;
  85097. return;
  85098. }
  85099. }
  85100. }
  85101. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift)
  85102. {
  85103. unsigned i;
  85104. FLAC__double cmax;
  85105. FLAC__int32 qmax, qmin;
  85106. FLAC__ASSERT(precision > 0);
  85107. FLAC__ASSERT(precision >= FLAC__MIN_QLP_COEFF_PRECISION);
  85108. precision--;
  85109. qmax = 1 << precision;
  85110. qmin = -qmax;
  85111. qmax--;
  85112. cmax = 0.0;
  85113. for(i = 0; i < order; i++) {
  85114. const FLAC__double d = fabs(lp_coeff[i]);
  85115. if(d > cmax)
  85116. cmax = d;
  85117. }
  85118. if(cmax <= 0.0) {
  85119. return 2;
  85120. }
  85121. else {
  85122. const int max_shiftlimit = (1 << (FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN-1)) - 1;
  85123. const int min_shiftlimit = -max_shiftlimit - 1;
  85124. int log2cmax;
  85125. (void)frexp(cmax, &log2cmax);
  85126. log2cmax--;
  85127. *shift = (int)precision - log2cmax - 1;
  85128. if(*shift > max_shiftlimit)
  85129. *shift = max_shiftlimit;
  85130. else if(*shift < min_shiftlimit)
  85131. return 1;
  85132. }
  85133. if(*shift >= 0) {
  85134. FLAC__double error = 0.0;
  85135. FLAC__int32 q;
  85136. for(i = 0; i < order; i++) {
  85137. error += lp_coeff[i] * (1 << *shift);
  85138. #if 1 /* unfortunately lround() is C99 */
  85139. if(error >= 0.0)
  85140. q = (FLAC__int32)(error + 0.5);
  85141. else
  85142. q = (FLAC__int32)(error - 0.5);
  85143. #else
  85144. q = lround(error);
  85145. #endif
  85146. #ifdef FLAC__OVERFLOW_DETECT
  85147. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85148. 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]);
  85149. else if(q < qmin)
  85150. 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]);
  85151. #endif
  85152. if(q > qmax)
  85153. q = qmax;
  85154. else if(q < qmin)
  85155. q = qmin;
  85156. error -= q;
  85157. qlp_coeff[i] = q;
  85158. }
  85159. }
  85160. else {
  85161. const int nshift = -(*shift);
  85162. FLAC__double error = 0.0;
  85163. FLAC__int32 q;
  85164. #ifdef DEBUG
  85165. fprintf(stderr,"FLAC__lpc_quantize_coefficients: negative shift=%d order=%u cmax=%f\n", *shift, order, cmax);
  85166. #endif
  85167. for(i = 0; i < order; i++) {
  85168. error += lp_coeff[i] / (1 << nshift);
  85169. #if 1 /* unfortunately lround() is C99 */
  85170. if(error >= 0.0)
  85171. q = (FLAC__int32)(error + 0.5);
  85172. else
  85173. q = (FLAC__int32)(error - 0.5);
  85174. #else
  85175. q = lround(error);
  85176. #endif
  85177. #ifdef FLAC__OVERFLOW_DETECT
  85178. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85179. 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]);
  85180. else if(q < qmin)
  85181. 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]);
  85182. #endif
  85183. if(q > qmax)
  85184. q = qmax;
  85185. else if(q < qmin)
  85186. q = qmin;
  85187. error -= q;
  85188. qlp_coeff[i] = q;
  85189. }
  85190. *shift = 0;
  85191. }
  85192. return 0;
  85193. }
  85194. 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[])
  85195. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85196. {
  85197. FLAC__int64 sumo;
  85198. unsigned i, j;
  85199. FLAC__int32 sum;
  85200. const FLAC__int32 *history;
  85201. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85202. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85203. for(i=0;i<order;i++)
  85204. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85205. fprintf(stderr,"\n");
  85206. #endif
  85207. FLAC__ASSERT(order > 0);
  85208. for(i = 0; i < data_len; i++) {
  85209. sumo = 0;
  85210. sum = 0;
  85211. history = data;
  85212. for(j = 0; j < order; j++) {
  85213. sum += qlp_coeff[j] * (*(--history));
  85214. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  85215. #if defined _MSC_VER
  85216. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  85217. 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);
  85218. #else
  85219. if(sumo > 2147483647ll || sumo < -2147483648ll)
  85220. 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);
  85221. #endif
  85222. }
  85223. *(residual++) = *(data++) - (sum >> lp_quantization);
  85224. }
  85225. }
  85226. #else /* fully unrolled version for normal use */
  85227. {
  85228. int i;
  85229. FLAC__int32 sum;
  85230. FLAC__ASSERT(order > 0);
  85231. FLAC__ASSERT(order <= 32);
  85232. if(order <= 12) {
  85233. if(order > 8) {
  85234. if(order > 10) {
  85235. if(order == 12) {
  85236. for(i = 0; i < (int)data_len; i++) {
  85237. sum = 0;
  85238. sum += qlp_coeff[11] * data[i-12];
  85239. sum += qlp_coeff[10] * data[i-11];
  85240. sum += qlp_coeff[9] * data[i-10];
  85241. sum += qlp_coeff[8] * data[i-9];
  85242. sum += qlp_coeff[7] * data[i-8];
  85243. sum += qlp_coeff[6] * data[i-7];
  85244. sum += qlp_coeff[5] * data[i-6];
  85245. sum += qlp_coeff[4] * data[i-5];
  85246. sum += qlp_coeff[3] * data[i-4];
  85247. sum += qlp_coeff[2] * data[i-3];
  85248. sum += qlp_coeff[1] * data[i-2];
  85249. sum += qlp_coeff[0] * data[i-1];
  85250. residual[i] = data[i] - (sum >> lp_quantization);
  85251. }
  85252. }
  85253. else { /* order == 11 */
  85254. for(i = 0; i < (int)data_len; i++) {
  85255. sum = 0;
  85256. sum += qlp_coeff[10] * data[i-11];
  85257. sum += qlp_coeff[9] * data[i-10];
  85258. sum += qlp_coeff[8] * data[i-9];
  85259. sum += qlp_coeff[7] * data[i-8];
  85260. sum += qlp_coeff[6] * data[i-7];
  85261. sum += qlp_coeff[5] * data[i-6];
  85262. sum += qlp_coeff[4] * data[i-5];
  85263. sum += qlp_coeff[3] * data[i-4];
  85264. sum += qlp_coeff[2] * data[i-3];
  85265. sum += qlp_coeff[1] * data[i-2];
  85266. sum += qlp_coeff[0] * data[i-1];
  85267. residual[i] = data[i] - (sum >> lp_quantization);
  85268. }
  85269. }
  85270. }
  85271. else {
  85272. if(order == 10) {
  85273. for(i = 0; i < (int)data_len; i++) {
  85274. sum = 0;
  85275. sum += qlp_coeff[9] * data[i-10];
  85276. sum += qlp_coeff[8] * data[i-9];
  85277. sum += qlp_coeff[7] * data[i-8];
  85278. sum += qlp_coeff[6] * data[i-7];
  85279. sum += qlp_coeff[5] * data[i-6];
  85280. sum += qlp_coeff[4] * data[i-5];
  85281. sum += qlp_coeff[3] * data[i-4];
  85282. sum += qlp_coeff[2] * data[i-3];
  85283. sum += qlp_coeff[1] * data[i-2];
  85284. sum += qlp_coeff[0] * data[i-1];
  85285. residual[i] = data[i] - (sum >> lp_quantization);
  85286. }
  85287. }
  85288. else { /* order == 9 */
  85289. for(i = 0; i < (int)data_len; i++) {
  85290. sum = 0;
  85291. sum += qlp_coeff[8] * data[i-9];
  85292. sum += qlp_coeff[7] * data[i-8];
  85293. sum += qlp_coeff[6] * data[i-7];
  85294. sum += qlp_coeff[5] * data[i-6];
  85295. sum += qlp_coeff[4] * data[i-5];
  85296. sum += qlp_coeff[3] * data[i-4];
  85297. sum += qlp_coeff[2] * data[i-3];
  85298. sum += qlp_coeff[1] * data[i-2];
  85299. sum += qlp_coeff[0] * data[i-1];
  85300. residual[i] = data[i] - (sum >> lp_quantization);
  85301. }
  85302. }
  85303. }
  85304. }
  85305. else if(order > 4) {
  85306. if(order > 6) {
  85307. if(order == 8) {
  85308. for(i = 0; i < (int)data_len; i++) {
  85309. sum = 0;
  85310. sum += qlp_coeff[7] * data[i-8];
  85311. sum += qlp_coeff[6] * data[i-7];
  85312. sum += qlp_coeff[5] * data[i-6];
  85313. sum += qlp_coeff[4] * data[i-5];
  85314. sum += qlp_coeff[3] * data[i-4];
  85315. sum += qlp_coeff[2] * data[i-3];
  85316. sum += qlp_coeff[1] * data[i-2];
  85317. sum += qlp_coeff[0] * data[i-1];
  85318. residual[i] = data[i] - (sum >> lp_quantization);
  85319. }
  85320. }
  85321. else { /* order == 7 */
  85322. for(i = 0; i < (int)data_len; i++) {
  85323. sum = 0;
  85324. sum += qlp_coeff[6] * data[i-7];
  85325. sum += qlp_coeff[5] * data[i-6];
  85326. sum += qlp_coeff[4] * data[i-5];
  85327. sum += qlp_coeff[3] * data[i-4];
  85328. sum += qlp_coeff[2] * data[i-3];
  85329. sum += qlp_coeff[1] * data[i-2];
  85330. sum += qlp_coeff[0] * data[i-1];
  85331. residual[i] = data[i] - (sum >> lp_quantization);
  85332. }
  85333. }
  85334. }
  85335. else {
  85336. if(order == 6) {
  85337. for(i = 0; i < (int)data_len; i++) {
  85338. sum = 0;
  85339. sum += qlp_coeff[5] * data[i-6];
  85340. sum += qlp_coeff[4] * data[i-5];
  85341. sum += qlp_coeff[3] * data[i-4];
  85342. sum += qlp_coeff[2] * data[i-3];
  85343. sum += qlp_coeff[1] * data[i-2];
  85344. sum += qlp_coeff[0] * data[i-1];
  85345. residual[i] = data[i] - (sum >> lp_quantization);
  85346. }
  85347. }
  85348. else { /* order == 5 */
  85349. for(i = 0; i < (int)data_len; i++) {
  85350. sum = 0;
  85351. sum += qlp_coeff[4] * data[i-5];
  85352. sum += qlp_coeff[3] * data[i-4];
  85353. sum += qlp_coeff[2] * data[i-3];
  85354. sum += qlp_coeff[1] * data[i-2];
  85355. sum += qlp_coeff[0] * data[i-1];
  85356. residual[i] = data[i] - (sum >> lp_quantization);
  85357. }
  85358. }
  85359. }
  85360. }
  85361. else {
  85362. if(order > 2) {
  85363. if(order == 4) {
  85364. for(i = 0; i < (int)data_len; i++) {
  85365. sum = 0;
  85366. sum += qlp_coeff[3] * data[i-4];
  85367. sum += qlp_coeff[2] * data[i-3];
  85368. sum += qlp_coeff[1] * data[i-2];
  85369. sum += qlp_coeff[0] * data[i-1];
  85370. residual[i] = data[i] - (sum >> lp_quantization);
  85371. }
  85372. }
  85373. else { /* order == 3 */
  85374. for(i = 0; i < (int)data_len; i++) {
  85375. sum = 0;
  85376. sum += qlp_coeff[2] * data[i-3];
  85377. sum += qlp_coeff[1] * data[i-2];
  85378. sum += qlp_coeff[0] * data[i-1];
  85379. residual[i] = data[i] - (sum >> lp_quantization);
  85380. }
  85381. }
  85382. }
  85383. else {
  85384. if(order == 2) {
  85385. for(i = 0; i < (int)data_len; i++) {
  85386. sum = 0;
  85387. sum += qlp_coeff[1] * data[i-2];
  85388. sum += qlp_coeff[0] * data[i-1];
  85389. residual[i] = data[i] - (sum >> lp_quantization);
  85390. }
  85391. }
  85392. else { /* order == 1 */
  85393. for(i = 0; i < (int)data_len; i++)
  85394. residual[i] = data[i] - ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  85395. }
  85396. }
  85397. }
  85398. }
  85399. else { /* order > 12 */
  85400. for(i = 0; i < (int)data_len; i++) {
  85401. sum = 0;
  85402. switch(order) {
  85403. case 32: sum += qlp_coeff[31] * data[i-32];
  85404. case 31: sum += qlp_coeff[30] * data[i-31];
  85405. case 30: sum += qlp_coeff[29] * data[i-30];
  85406. case 29: sum += qlp_coeff[28] * data[i-29];
  85407. case 28: sum += qlp_coeff[27] * data[i-28];
  85408. case 27: sum += qlp_coeff[26] * data[i-27];
  85409. case 26: sum += qlp_coeff[25] * data[i-26];
  85410. case 25: sum += qlp_coeff[24] * data[i-25];
  85411. case 24: sum += qlp_coeff[23] * data[i-24];
  85412. case 23: sum += qlp_coeff[22] * data[i-23];
  85413. case 22: sum += qlp_coeff[21] * data[i-22];
  85414. case 21: sum += qlp_coeff[20] * data[i-21];
  85415. case 20: sum += qlp_coeff[19] * data[i-20];
  85416. case 19: sum += qlp_coeff[18] * data[i-19];
  85417. case 18: sum += qlp_coeff[17] * data[i-18];
  85418. case 17: sum += qlp_coeff[16] * data[i-17];
  85419. case 16: sum += qlp_coeff[15] * data[i-16];
  85420. case 15: sum += qlp_coeff[14] * data[i-15];
  85421. case 14: sum += qlp_coeff[13] * data[i-14];
  85422. case 13: sum += qlp_coeff[12] * data[i-13];
  85423. sum += qlp_coeff[11] * data[i-12];
  85424. sum += qlp_coeff[10] * data[i-11];
  85425. sum += qlp_coeff[ 9] * data[i-10];
  85426. sum += qlp_coeff[ 8] * data[i- 9];
  85427. sum += qlp_coeff[ 7] * data[i- 8];
  85428. sum += qlp_coeff[ 6] * data[i- 7];
  85429. sum += qlp_coeff[ 5] * data[i- 6];
  85430. sum += qlp_coeff[ 4] * data[i- 5];
  85431. sum += qlp_coeff[ 3] * data[i- 4];
  85432. sum += qlp_coeff[ 2] * data[i- 3];
  85433. sum += qlp_coeff[ 1] * data[i- 2];
  85434. sum += qlp_coeff[ 0] * data[i- 1];
  85435. }
  85436. residual[i] = data[i] - (sum >> lp_quantization);
  85437. }
  85438. }
  85439. }
  85440. #endif
  85441. 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[])
  85442. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85443. {
  85444. unsigned i, j;
  85445. FLAC__int64 sum;
  85446. const FLAC__int32 *history;
  85447. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85448. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85449. for(i=0;i<order;i++)
  85450. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85451. fprintf(stderr,"\n");
  85452. #endif
  85453. FLAC__ASSERT(order > 0);
  85454. for(i = 0; i < data_len; i++) {
  85455. sum = 0;
  85456. history = data;
  85457. for(j = 0; j < order; j++)
  85458. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  85459. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  85460. #if defined _MSC_VER
  85461. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  85462. #else
  85463. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  85464. #endif
  85465. break;
  85466. }
  85467. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*data) - (sum >> lp_quantization)) > 32) {
  85468. #if defined _MSC_VER
  85469. 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));
  85470. #else
  85471. 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)));
  85472. #endif
  85473. break;
  85474. }
  85475. *(residual++) = *(data++) - (FLAC__int32)(sum >> lp_quantization);
  85476. }
  85477. }
  85478. #else /* fully unrolled version for normal use */
  85479. {
  85480. int i;
  85481. FLAC__int64 sum;
  85482. FLAC__ASSERT(order > 0);
  85483. FLAC__ASSERT(order <= 32);
  85484. if(order <= 12) {
  85485. if(order > 8) {
  85486. if(order > 10) {
  85487. if(order == 12) {
  85488. for(i = 0; i < (int)data_len; i++) {
  85489. sum = 0;
  85490. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85491. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85492. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85493. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85494. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85495. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85496. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85497. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85498. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85499. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85500. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85501. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85502. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85503. }
  85504. }
  85505. else { /* order == 11 */
  85506. for(i = 0; i < (int)data_len; i++) {
  85507. sum = 0;
  85508. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85509. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85510. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85511. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85512. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85513. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85514. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85515. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85516. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85517. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85518. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85519. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85520. }
  85521. }
  85522. }
  85523. else {
  85524. if(order == 10) {
  85525. for(i = 0; i < (int)data_len; i++) {
  85526. sum = 0;
  85527. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85528. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85529. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85530. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85531. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85532. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85533. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85534. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85535. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85536. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85537. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85538. }
  85539. }
  85540. else { /* order == 9 */
  85541. for(i = 0; i < (int)data_len; i++) {
  85542. sum = 0;
  85543. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85544. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85545. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85546. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85547. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85548. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85549. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85550. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85551. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85552. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85553. }
  85554. }
  85555. }
  85556. }
  85557. else if(order > 4) {
  85558. if(order > 6) {
  85559. if(order == 8) {
  85560. for(i = 0; i < (int)data_len; i++) {
  85561. sum = 0;
  85562. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85563. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85564. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85565. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85566. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85567. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85568. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85569. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85570. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85571. }
  85572. }
  85573. else { /* order == 7 */
  85574. for(i = 0; i < (int)data_len; i++) {
  85575. sum = 0;
  85576. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85577. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85578. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85579. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85580. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85581. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85582. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85583. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85584. }
  85585. }
  85586. }
  85587. else {
  85588. if(order == 6) {
  85589. for(i = 0; i < (int)data_len; i++) {
  85590. sum = 0;
  85591. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85592. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85593. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85594. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85595. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85596. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85597. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85598. }
  85599. }
  85600. else { /* order == 5 */
  85601. for(i = 0; i < (int)data_len; i++) {
  85602. sum = 0;
  85603. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85604. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85605. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85606. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85607. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85608. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85609. }
  85610. }
  85611. }
  85612. }
  85613. else {
  85614. if(order > 2) {
  85615. if(order == 4) {
  85616. for(i = 0; i < (int)data_len; i++) {
  85617. sum = 0;
  85618. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85619. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85620. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85621. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85622. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85623. }
  85624. }
  85625. else { /* order == 3 */
  85626. for(i = 0; i < (int)data_len; i++) {
  85627. sum = 0;
  85628. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85629. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85630. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85631. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85632. }
  85633. }
  85634. }
  85635. else {
  85636. if(order == 2) {
  85637. for(i = 0; i < (int)data_len; i++) {
  85638. sum = 0;
  85639. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85640. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85641. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85642. }
  85643. }
  85644. else { /* order == 1 */
  85645. for(i = 0; i < (int)data_len; i++)
  85646. residual[i] = data[i] - (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  85647. }
  85648. }
  85649. }
  85650. }
  85651. else { /* order > 12 */
  85652. for(i = 0; i < (int)data_len; i++) {
  85653. sum = 0;
  85654. switch(order) {
  85655. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  85656. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  85657. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  85658. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  85659. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  85660. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  85661. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  85662. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  85663. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  85664. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  85665. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  85666. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  85667. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  85668. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  85669. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  85670. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  85671. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  85672. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  85673. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  85674. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  85675. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85676. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85677. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  85678. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  85679. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  85680. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  85681. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  85682. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  85683. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  85684. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  85685. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  85686. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  85687. }
  85688. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85689. }
  85690. }
  85691. }
  85692. #endif
  85693. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85694. 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[])
  85695. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85696. {
  85697. FLAC__int64 sumo;
  85698. unsigned i, j;
  85699. FLAC__int32 sum;
  85700. const FLAC__int32 *r = residual, *history;
  85701. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85702. fprintf(stderr,"FLAC__lpc_restore_signal: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85703. for(i=0;i<order;i++)
  85704. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85705. fprintf(stderr,"\n");
  85706. #endif
  85707. FLAC__ASSERT(order > 0);
  85708. for(i = 0; i < data_len; i++) {
  85709. sumo = 0;
  85710. sum = 0;
  85711. history = data;
  85712. for(j = 0; j < order; j++) {
  85713. sum += qlp_coeff[j] * (*(--history));
  85714. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  85715. #if defined _MSC_VER
  85716. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  85717. 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);
  85718. #else
  85719. if(sumo > 2147483647ll || sumo < -2147483648ll)
  85720. 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);
  85721. #endif
  85722. }
  85723. *(data++) = *(r++) + (sum >> lp_quantization);
  85724. }
  85725. }
  85726. #else /* fully unrolled version for normal use */
  85727. {
  85728. int i;
  85729. FLAC__int32 sum;
  85730. FLAC__ASSERT(order > 0);
  85731. FLAC__ASSERT(order <= 32);
  85732. if(order <= 12) {
  85733. if(order > 8) {
  85734. if(order > 10) {
  85735. if(order == 12) {
  85736. for(i = 0; i < (int)data_len; i++) {
  85737. sum = 0;
  85738. sum += qlp_coeff[11] * data[i-12];
  85739. sum += qlp_coeff[10] * data[i-11];
  85740. sum += qlp_coeff[9] * data[i-10];
  85741. sum += qlp_coeff[8] * data[i-9];
  85742. sum += qlp_coeff[7] * data[i-8];
  85743. sum += qlp_coeff[6] * data[i-7];
  85744. sum += qlp_coeff[5] * data[i-6];
  85745. sum += qlp_coeff[4] * data[i-5];
  85746. sum += qlp_coeff[3] * data[i-4];
  85747. sum += qlp_coeff[2] * data[i-3];
  85748. sum += qlp_coeff[1] * data[i-2];
  85749. sum += qlp_coeff[0] * data[i-1];
  85750. data[i] = residual[i] + (sum >> lp_quantization);
  85751. }
  85752. }
  85753. else { /* order == 11 */
  85754. for(i = 0; i < (int)data_len; i++) {
  85755. sum = 0;
  85756. sum += qlp_coeff[10] * data[i-11];
  85757. sum += qlp_coeff[9] * data[i-10];
  85758. sum += qlp_coeff[8] * data[i-9];
  85759. sum += qlp_coeff[7] * data[i-8];
  85760. sum += qlp_coeff[6] * data[i-7];
  85761. sum += qlp_coeff[5] * data[i-6];
  85762. sum += qlp_coeff[4] * data[i-5];
  85763. sum += qlp_coeff[3] * data[i-4];
  85764. sum += qlp_coeff[2] * data[i-3];
  85765. sum += qlp_coeff[1] * data[i-2];
  85766. sum += qlp_coeff[0] * data[i-1];
  85767. data[i] = residual[i] + (sum >> lp_quantization);
  85768. }
  85769. }
  85770. }
  85771. else {
  85772. if(order == 10) {
  85773. for(i = 0; i < (int)data_len; i++) {
  85774. sum = 0;
  85775. sum += qlp_coeff[9] * data[i-10];
  85776. sum += qlp_coeff[8] * data[i-9];
  85777. sum += qlp_coeff[7] * data[i-8];
  85778. sum += qlp_coeff[6] * data[i-7];
  85779. sum += qlp_coeff[5] * data[i-6];
  85780. sum += qlp_coeff[4] * data[i-5];
  85781. sum += qlp_coeff[3] * data[i-4];
  85782. sum += qlp_coeff[2] * data[i-3];
  85783. sum += qlp_coeff[1] * data[i-2];
  85784. sum += qlp_coeff[0] * data[i-1];
  85785. data[i] = residual[i] + (sum >> lp_quantization);
  85786. }
  85787. }
  85788. else { /* order == 9 */
  85789. for(i = 0; i < (int)data_len; i++) {
  85790. sum = 0;
  85791. sum += qlp_coeff[8] * data[i-9];
  85792. sum += qlp_coeff[7] * data[i-8];
  85793. sum += qlp_coeff[6] * data[i-7];
  85794. sum += qlp_coeff[5] * data[i-6];
  85795. sum += qlp_coeff[4] * data[i-5];
  85796. sum += qlp_coeff[3] * data[i-4];
  85797. sum += qlp_coeff[2] * data[i-3];
  85798. sum += qlp_coeff[1] * data[i-2];
  85799. sum += qlp_coeff[0] * data[i-1];
  85800. data[i] = residual[i] + (sum >> lp_quantization);
  85801. }
  85802. }
  85803. }
  85804. }
  85805. else if(order > 4) {
  85806. if(order > 6) {
  85807. if(order == 8) {
  85808. for(i = 0; i < (int)data_len; i++) {
  85809. sum = 0;
  85810. sum += qlp_coeff[7] * data[i-8];
  85811. sum += qlp_coeff[6] * data[i-7];
  85812. sum += qlp_coeff[5] * data[i-6];
  85813. sum += qlp_coeff[4] * data[i-5];
  85814. sum += qlp_coeff[3] * data[i-4];
  85815. sum += qlp_coeff[2] * data[i-3];
  85816. sum += qlp_coeff[1] * data[i-2];
  85817. sum += qlp_coeff[0] * data[i-1];
  85818. data[i] = residual[i] + (sum >> lp_quantization);
  85819. }
  85820. }
  85821. else { /* order == 7 */
  85822. for(i = 0; i < (int)data_len; i++) {
  85823. sum = 0;
  85824. sum += qlp_coeff[6] * data[i-7];
  85825. sum += qlp_coeff[5] * data[i-6];
  85826. sum += qlp_coeff[4] * data[i-5];
  85827. sum += qlp_coeff[3] * data[i-4];
  85828. sum += qlp_coeff[2] * data[i-3];
  85829. sum += qlp_coeff[1] * data[i-2];
  85830. sum += qlp_coeff[0] * data[i-1];
  85831. data[i] = residual[i] + (sum >> lp_quantization);
  85832. }
  85833. }
  85834. }
  85835. else {
  85836. if(order == 6) {
  85837. for(i = 0; i < (int)data_len; i++) {
  85838. sum = 0;
  85839. sum += qlp_coeff[5] * data[i-6];
  85840. sum += qlp_coeff[4] * data[i-5];
  85841. sum += qlp_coeff[3] * data[i-4];
  85842. sum += qlp_coeff[2] * data[i-3];
  85843. sum += qlp_coeff[1] * data[i-2];
  85844. sum += qlp_coeff[0] * data[i-1];
  85845. data[i] = residual[i] + (sum >> lp_quantization);
  85846. }
  85847. }
  85848. else { /* order == 5 */
  85849. for(i = 0; i < (int)data_len; i++) {
  85850. sum = 0;
  85851. sum += qlp_coeff[4] * data[i-5];
  85852. sum += qlp_coeff[3] * data[i-4];
  85853. sum += qlp_coeff[2] * data[i-3];
  85854. sum += qlp_coeff[1] * data[i-2];
  85855. sum += qlp_coeff[0] * data[i-1];
  85856. data[i] = residual[i] + (sum >> lp_quantization);
  85857. }
  85858. }
  85859. }
  85860. }
  85861. else {
  85862. if(order > 2) {
  85863. if(order == 4) {
  85864. for(i = 0; i < (int)data_len; i++) {
  85865. sum = 0;
  85866. sum += qlp_coeff[3] * data[i-4];
  85867. sum += qlp_coeff[2] * data[i-3];
  85868. sum += qlp_coeff[1] * data[i-2];
  85869. sum += qlp_coeff[0] * data[i-1];
  85870. data[i] = residual[i] + (sum >> lp_quantization);
  85871. }
  85872. }
  85873. else { /* order == 3 */
  85874. for(i = 0; i < (int)data_len; i++) {
  85875. sum = 0;
  85876. sum += qlp_coeff[2] * data[i-3];
  85877. sum += qlp_coeff[1] * data[i-2];
  85878. sum += qlp_coeff[0] * data[i-1];
  85879. data[i] = residual[i] + (sum >> lp_quantization);
  85880. }
  85881. }
  85882. }
  85883. else {
  85884. if(order == 2) {
  85885. for(i = 0; i < (int)data_len; i++) {
  85886. sum = 0;
  85887. sum += qlp_coeff[1] * data[i-2];
  85888. sum += qlp_coeff[0] * data[i-1];
  85889. data[i] = residual[i] + (sum >> lp_quantization);
  85890. }
  85891. }
  85892. else { /* order == 1 */
  85893. for(i = 0; i < (int)data_len; i++)
  85894. data[i] = residual[i] + ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  85895. }
  85896. }
  85897. }
  85898. }
  85899. else { /* order > 12 */
  85900. for(i = 0; i < (int)data_len; i++) {
  85901. sum = 0;
  85902. switch(order) {
  85903. case 32: sum += qlp_coeff[31] * data[i-32];
  85904. case 31: sum += qlp_coeff[30] * data[i-31];
  85905. case 30: sum += qlp_coeff[29] * data[i-30];
  85906. case 29: sum += qlp_coeff[28] * data[i-29];
  85907. case 28: sum += qlp_coeff[27] * data[i-28];
  85908. case 27: sum += qlp_coeff[26] * data[i-27];
  85909. case 26: sum += qlp_coeff[25] * data[i-26];
  85910. case 25: sum += qlp_coeff[24] * data[i-25];
  85911. case 24: sum += qlp_coeff[23] * data[i-24];
  85912. case 23: sum += qlp_coeff[22] * data[i-23];
  85913. case 22: sum += qlp_coeff[21] * data[i-22];
  85914. case 21: sum += qlp_coeff[20] * data[i-21];
  85915. case 20: sum += qlp_coeff[19] * data[i-20];
  85916. case 19: sum += qlp_coeff[18] * data[i-19];
  85917. case 18: sum += qlp_coeff[17] * data[i-18];
  85918. case 17: sum += qlp_coeff[16] * data[i-17];
  85919. case 16: sum += qlp_coeff[15] * data[i-16];
  85920. case 15: sum += qlp_coeff[14] * data[i-15];
  85921. case 14: sum += qlp_coeff[13] * data[i-14];
  85922. case 13: sum += qlp_coeff[12] * data[i-13];
  85923. sum += qlp_coeff[11] * data[i-12];
  85924. sum += qlp_coeff[10] * data[i-11];
  85925. sum += qlp_coeff[ 9] * data[i-10];
  85926. sum += qlp_coeff[ 8] * data[i- 9];
  85927. sum += qlp_coeff[ 7] * data[i- 8];
  85928. sum += qlp_coeff[ 6] * data[i- 7];
  85929. sum += qlp_coeff[ 5] * data[i- 6];
  85930. sum += qlp_coeff[ 4] * data[i- 5];
  85931. sum += qlp_coeff[ 3] * data[i- 4];
  85932. sum += qlp_coeff[ 2] * data[i- 3];
  85933. sum += qlp_coeff[ 1] * data[i- 2];
  85934. sum += qlp_coeff[ 0] * data[i- 1];
  85935. }
  85936. data[i] = residual[i] + (sum >> lp_quantization);
  85937. }
  85938. }
  85939. }
  85940. #endif
  85941. 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[])
  85942. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85943. {
  85944. unsigned i, j;
  85945. FLAC__int64 sum;
  85946. const FLAC__int32 *r = residual, *history;
  85947. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85948. fprintf(stderr,"FLAC__lpc_restore_signal_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85949. for(i=0;i<order;i++)
  85950. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85951. fprintf(stderr,"\n");
  85952. #endif
  85953. FLAC__ASSERT(order > 0);
  85954. for(i = 0; i < data_len; i++) {
  85955. sum = 0;
  85956. history = data;
  85957. for(j = 0; j < order; j++)
  85958. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  85959. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  85960. #ifdef _MSC_VER
  85961. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  85962. #else
  85963. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  85964. #endif
  85965. break;
  85966. }
  85967. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*r) + (sum >> lp_quantization)) > 32) {
  85968. #ifdef _MSC_VER
  85969. 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));
  85970. #else
  85971. 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)));
  85972. #endif
  85973. break;
  85974. }
  85975. *(data++) = *(r++) + (FLAC__int32)(sum >> lp_quantization);
  85976. }
  85977. }
  85978. #else /* fully unrolled version for normal use */
  85979. {
  85980. int i;
  85981. FLAC__int64 sum;
  85982. FLAC__ASSERT(order > 0);
  85983. FLAC__ASSERT(order <= 32);
  85984. if(order <= 12) {
  85985. if(order > 8) {
  85986. if(order > 10) {
  85987. if(order == 12) {
  85988. for(i = 0; i < (int)data_len; i++) {
  85989. sum = 0;
  85990. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85991. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85992. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85993. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85994. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85995. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85996. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85997. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85998. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85999. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86000. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86001. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86002. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86003. }
  86004. }
  86005. else { /* order == 11 */
  86006. for(i = 0; i < (int)data_len; i++) {
  86007. sum = 0;
  86008. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86009. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86010. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86011. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86012. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86013. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86014. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86015. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86016. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86017. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86018. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86019. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86020. }
  86021. }
  86022. }
  86023. else {
  86024. if(order == 10) {
  86025. for(i = 0; i < (int)data_len; i++) {
  86026. sum = 0;
  86027. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86028. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86029. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86030. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86031. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86032. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86033. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86034. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86035. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86036. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86037. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86038. }
  86039. }
  86040. else { /* order == 9 */
  86041. for(i = 0; i < (int)data_len; i++) {
  86042. sum = 0;
  86043. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86044. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86045. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86046. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86047. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86048. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86049. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86050. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86051. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86052. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86053. }
  86054. }
  86055. }
  86056. }
  86057. else if(order > 4) {
  86058. if(order > 6) {
  86059. if(order == 8) {
  86060. for(i = 0; i < (int)data_len; i++) {
  86061. sum = 0;
  86062. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86063. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86064. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86065. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86066. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86067. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86068. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86069. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86070. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86071. }
  86072. }
  86073. else { /* order == 7 */
  86074. for(i = 0; i < (int)data_len; i++) {
  86075. sum = 0;
  86076. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86077. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86078. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86079. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86080. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86081. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86082. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86083. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86084. }
  86085. }
  86086. }
  86087. else {
  86088. if(order == 6) {
  86089. for(i = 0; i < (int)data_len; i++) {
  86090. sum = 0;
  86091. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86092. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86093. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86094. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86095. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86096. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86097. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86098. }
  86099. }
  86100. else { /* order == 5 */
  86101. for(i = 0; i < (int)data_len; i++) {
  86102. sum = 0;
  86103. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86104. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86105. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86106. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86107. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86108. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86109. }
  86110. }
  86111. }
  86112. }
  86113. else {
  86114. if(order > 2) {
  86115. if(order == 4) {
  86116. for(i = 0; i < (int)data_len; i++) {
  86117. sum = 0;
  86118. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86119. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86120. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86121. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86122. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86123. }
  86124. }
  86125. else { /* order == 3 */
  86126. for(i = 0; i < (int)data_len; i++) {
  86127. sum = 0;
  86128. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86129. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86130. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86131. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86132. }
  86133. }
  86134. }
  86135. else {
  86136. if(order == 2) {
  86137. for(i = 0; i < (int)data_len; i++) {
  86138. sum = 0;
  86139. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86140. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86141. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86142. }
  86143. }
  86144. else { /* order == 1 */
  86145. for(i = 0; i < (int)data_len; i++)
  86146. data[i] = residual[i] + (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  86147. }
  86148. }
  86149. }
  86150. }
  86151. else { /* order > 12 */
  86152. for(i = 0; i < (int)data_len; i++) {
  86153. sum = 0;
  86154. switch(order) {
  86155. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  86156. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  86157. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  86158. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  86159. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  86160. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  86161. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  86162. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  86163. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  86164. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  86165. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  86166. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  86167. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  86168. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  86169. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  86170. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  86171. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  86172. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  86173. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  86174. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  86175. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86176. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86177. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  86178. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  86179. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  86180. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  86181. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  86182. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  86183. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  86184. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  86185. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  86186. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  86187. }
  86188. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86189. }
  86190. }
  86191. }
  86192. #endif
  86193. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86194. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples)
  86195. {
  86196. FLAC__double error_scale;
  86197. FLAC__ASSERT(total_samples > 0);
  86198. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86199. return FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(lpc_error, error_scale);
  86200. }
  86201. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale)
  86202. {
  86203. if(lpc_error > 0.0) {
  86204. FLAC__double bps = (FLAC__double)0.5 * log(error_scale * lpc_error) / M_LN2;
  86205. if(bps >= 0.0)
  86206. return bps;
  86207. else
  86208. return 0.0;
  86209. }
  86210. else if(lpc_error < 0.0) { /* error should not be negative but can happen due to inadequate floating-point resolution */
  86211. return 1e32;
  86212. }
  86213. else {
  86214. return 0.0;
  86215. }
  86216. }
  86217. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order)
  86218. {
  86219. 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 */
  86220. FLAC__double bits, best_bits, error_scale;
  86221. FLAC__ASSERT(max_order > 0);
  86222. FLAC__ASSERT(total_samples > 0);
  86223. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86224. best_index = 0;
  86225. best_bits = (unsigned)(-1);
  86226. for(index = 0, order = 1; index < max_order; index++, order++) {
  86227. 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);
  86228. if(bits < best_bits) {
  86229. best_index = index;
  86230. best_bits = bits;
  86231. }
  86232. }
  86233. return best_index+1; /* +1 since index of lpc_error[] is order-1 */
  86234. }
  86235. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  86236. #endif
  86237. /*** End of inlined file: lpc_flac.c ***/
  86238. /*** Start of inlined file: md5.c ***/
  86239. /*** Start of inlined file: juce_FlacHeader.h ***/
  86240. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86241. // tasks..
  86242. #define VERSION "1.2.1"
  86243. #define FLAC__NO_DLL 1
  86244. #if JUCE_MSVC
  86245. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86246. #endif
  86247. #if JUCE_MAC
  86248. #define FLAC__SYS_DARWIN 1
  86249. #endif
  86250. /*** End of inlined file: juce_FlacHeader.h ***/
  86251. #if JUCE_USE_FLAC
  86252. #if HAVE_CONFIG_H
  86253. # include <config.h>
  86254. #endif
  86255. #include <stdlib.h> /* for malloc() */
  86256. #include <string.h> /* for memcpy() */
  86257. /*** Start of inlined file: md5.h ***/
  86258. #ifndef FLAC__PRIVATE__MD5_H
  86259. #define FLAC__PRIVATE__MD5_H
  86260. typedef struct {
  86261. FLAC__uint32 in[16];
  86262. FLAC__uint32 buf[4];
  86263. FLAC__uint32 bytes[2];
  86264. FLAC__byte *internal_buf;
  86265. size_t capacity;
  86266. } FLAC__MD5Context;
  86267. void FLAC__MD5Init(FLAC__MD5Context *context);
  86268. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *context);
  86269. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample);
  86270. #endif
  86271. /*** End of inlined file: md5.h ***/
  86272. #ifndef FLaC__INLINE
  86273. #define FLaC__INLINE
  86274. #endif
  86275. #define F1(x, y, z) (z ^ (x & (y ^ z)))
  86276. #define F2(x, y, z) F1(z, x, y)
  86277. #define F3(x, y, z) (x ^ y ^ z)
  86278. #define F4(x, y, z) (y ^ (x | ~z))
  86279. #define MD5STEP(f,w,x,y,z,in,s) \
  86280. (w += f(x,y,z) + in, w = (w<<s | w>>(32-s)) + x)
  86281. static void FLAC__MD5Transform(FLAC__uint32 buf[4], FLAC__uint32 const in[16])
  86282. {
  86283. register FLAC__uint32 a, b, c, d;
  86284. a = buf[0];
  86285. b = buf[1];
  86286. c = buf[2];
  86287. d = buf[3];
  86288. MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
  86289. MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
  86290. MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
  86291. MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
  86292. MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
  86293. MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
  86294. MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
  86295. MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
  86296. MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
  86297. MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
  86298. MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
  86299. MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
  86300. MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
  86301. MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
  86302. MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
  86303. MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
  86304. MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
  86305. MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
  86306. MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
  86307. MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
  86308. MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
  86309. MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
  86310. MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
  86311. MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
  86312. MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
  86313. MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
  86314. MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
  86315. MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
  86316. MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
  86317. MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
  86318. MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
  86319. MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
  86320. MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
  86321. MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
  86322. MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
  86323. MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
  86324. MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
  86325. MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
  86326. MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
  86327. MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
  86328. MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
  86329. MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
  86330. MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
  86331. MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
  86332. MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
  86333. MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
  86334. MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
  86335. MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
  86336. MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
  86337. MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
  86338. MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
  86339. MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
  86340. MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
  86341. MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
  86342. MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
  86343. MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
  86344. MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
  86345. MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
  86346. MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
  86347. MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
  86348. MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
  86349. MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
  86350. MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
  86351. MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
  86352. buf[0] += a;
  86353. buf[1] += b;
  86354. buf[2] += c;
  86355. buf[3] += d;
  86356. }
  86357. #if WORDS_BIGENDIAN
  86358. //@@@@@@ OPT: use bswap/intrinsics
  86359. static void byteSwap(FLAC__uint32 *buf, unsigned words)
  86360. {
  86361. register FLAC__uint32 x;
  86362. do {
  86363. x = *buf;
  86364. x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff);
  86365. *buf++ = (x >> 16) | (x << 16);
  86366. } while (--words);
  86367. }
  86368. static void byteSwapX16(FLAC__uint32 *buf)
  86369. {
  86370. register FLAC__uint32 x;
  86371. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86372. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86373. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86374. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86375. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86376. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86377. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86378. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86379. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86380. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86381. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86382. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86383. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86384. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86385. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86386. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf = (x >> 16) | (x << 16);
  86387. }
  86388. #else
  86389. #define byteSwap(buf, words)
  86390. #define byteSwapX16(buf)
  86391. #endif
  86392. static void FLAC__MD5Update(FLAC__MD5Context *ctx, FLAC__byte const *buf, unsigned len)
  86393. {
  86394. FLAC__uint32 t;
  86395. t = ctx->bytes[0];
  86396. if ((ctx->bytes[0] = t + len) < t)
  86397. ctx->bytes[1]++; /* Carry from low to high */
  86398. t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */
  86399. if (t > len) {
  86400. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, len);
  86401. return;
  86402. }
  86403. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, t);
  86404. byteSwapX16(ctx->in);
  86405. FLAC__MD5Transform(ctx->buf, ctx->in);
  86406. buf += t;
  86407. len -= t;
  86408. while (len >= 64) {
  86409. memcpy(ctx->in, buf, 64);
  86410. byteSwapX16(ctx->in);
  86411. FLAC__MD5Transform(ctx->buf, ctx->in);
  86412. buf += 64;
  86413. len -= 64;
  86414. }
  86415. memcpy(ctx->in, buf, len);
  86416. }
  86417. void FLAC__MD5Init(FLAC__MD5Context *ctx)
  86418. {
  86419. ctx->buf[0] = 0x67452301;
  86420. ctx->buf[1] = 0xefcdab89;
  86421. ctx->buf[2] = 0x98badcfe;
  86422. ctx->buf[3] = 0x10325476;
  86423. ctx->bytes[0] = 0;
  86424. ctx->bytes[1] = 0;
  86425. ctx->internal_buf = 0;
  86426. ctx->capacity = 0;
  86427. }
  86428. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *ctx)
  86429. {
  86430. int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */
  86431. FLAC__byte *p = (FLAC__byte *)ctx->in + count;
  86432. *p++ = 0x80;
  86433. count = 56 - 1 - count;
  86434. if (count < 0) { /* Padding forces an extra block */
  86435. memset(p, 0, count + 8);
  86436. byteSwapX16(ctx->in);
  86437. FLAC__MD5Transform(ctx->buf, ctx->in);
  86438. p = (FLAC__byte *)ctx->in;
  86439. count = 56;
  86440. }
  86441. memset(p, 0, count);
  86442. byteSwap(ctx->in, 14);
  86443. ctx->in[14] = ctx->bytes[0] << 3;
  86444. ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29;
  86445. FLAC__MD5Transform(ctx->buf, ctx->in);
  86446. byteSwap(ctx->buf, 4);
  86447. memcpy(digest, ctx->buf, 16);
  86448. memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
  86449. if(0 != ctx->internal_buf) {
  86450. free(ctx->internal_buf);
  86451. ctx->internal_buf = 0;
  86452. ctx->capacity = 0;
  86453. }
  86454. }
  86455. static void format_input_(FLAC__byte *buf, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86456. {
  86457. unsigned channel, sample;
  86458. register FLAC__int32 a_word;
  86459. register FLAC__byte *buf_ = buf;
  86460. #if WORDS_BIGENDIAN
  86461. #else
  86462. if(channels == 2 && bytes_per_sample == 2) {
  86463. FLAC__int16 *buf1_ = ((FLAC__int16*)buf_) + 1;
  86464. memcpy(buf_, signal[0], sizeof(FLAC__int32) * samples);
  86465. for(sample = 0; sample < samples; sample++, buf1_+=2)
  86466. *buf1_ = (FLAC__int16)signal[1][sample];
  86467. }
  86468. else if(channels == 1 && bytes_per_sample == 2) {
  86469. FLAC__int16 *buf1_ = (FLAC__int16*)buf_;
  86470. for(sample = 0; sample < samples; sample++)
  86471. *buf1_++ = (FLAC__int16)signal[0][sample];
  86472. }
  86473. else
  86474. #endif
  86475. if(bytes_per_sample == 2) {
  86476. if(channels == 2) {
  86477. for(sample = 0; sample < samples; sample++) {
  86478. a_word = signal[0][sample];
  86479. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86480. *buf_++ = (FLAC__byte)a_word;
  86481. a_word = signal[1][sample];
  86482. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86483. *buf_++ = (FLAC__byte)a_word;
  86484. }
  86485. }
  86486. else if(channels == 1) {
  86487. for(sample = 0; sample < samples; sample++) {
  86488. a_word = signal[0][sample];
  86489. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86490. *buf_++ = (FLAC__byte)a_word;
  86491. }
  86492. }
  86493. else {
  86494. for(sample = 0; sample < samples; sample++) {
  86495. for(channel = 0; channel < channels; channel++) {
  86496. a_word = signal[channel][sample];
  86497. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86498. *buf_++ = (FLAC__byte)a_word;
  86499. }
  86500. }
  86501. }
  86502. }
  86503. else if(bytes_per_sample == 3) {
  86504. if(channels == 2) {
  86505. for(sample = 0; sample < samples; sample++) {
  86506. a_word = signal[0][sample];
  86507. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86508. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86509. *buf_++ = (FLAC__byte)a_word;
  86510. a_word = signal[1][sample];
  86511. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86512. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86513. *buf_++ = (FLAC__byte)a_word;
  86514. }
  86515. }
  86516. else if(channels == 1) {
  86517. for(sample = 0; sample < samples; sample++) {
  86518. a_word = signal[0][sample];
  86519. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86520. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86521. *buf_++ = (FLAC__byte)a_word;
  86522. }
  86523. }
  86524. else {
  86525. for(sample = 0; sample < samples; sample++) {
  86526. for(channel = 0; channel < channels; channel++) {
  86527. a_word = signal[channel][sample];
  86528. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86529. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86530. *buf_++ = (FLAC__byte)a_word;
  86531. }
  86532. }
  86533. }
  86534. }
  86535. else if(bytes_per_sample == 1) {
  86536. if(channels == 2) {
  86537. for(sample = 0; sample < samples; sample++) {
  86538. a_word = signal[0][sample];
  86539. *buf_++ = (FLAC__byte)a_word;
  86540. a_word = signal[1][sample];
  86541. *buf_++ = (FLAC__byte)a_word;
  86542. }
  86543. }
  86544. else if(channels == 1) {
  86545. for(sample = 0; sample < samples; sample++) {
  86546. a_word = signal[0][sample];
  86547. *buf_++ = (FLAC__byte)a_word;
  86548. }
  86549. }
  86550. else {
  86551. for(sample = 0; sample < samples; sample++) {
  86552. for(channel = 0; channel < channels; channel++) {
  86553. a_word = signal[channel][sample];
  86554. *buf_++ = (FLAC__byte)a_word;
  86555. }
  86556. }
  86557. }
  86558. }
  86559. else { /* bytes_per_sample == 4, maybe optimize more later */
  86560. for(sample = 0; sample < samples; sample++) {
  86561. for(channel = 0; channel < channels; channel++) {
  86562. a_word = signal[channel][sample];
  86563. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86564. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86565. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86566. *buf_++ = (FLAC__byte)a_word;
  86567. }
  86568. }
  86569. }
  86570. }
  86571. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86572. {
  86573. const size_t bytes_needed = (size_t)channels * (size_t)samples * (size_t)bytes_per_sample;
  86574. if((size_t)channels > SIZE_MAX / (size_t)bytes_per_sample)
  86575. return false;
  86576. if((size_t)channels * (size_t)bytes_per_sample > SIZE_MAX / (size_t)samples)
  86577. return false;
  86578. if(ctx->capacity < bytes_needed) {
  86579. FLAC__byte *tmp = (FLAC__byte*)realloc(ctx->internal_buf, bytes_needed);
  86580. if(0 == tmp) {
  86581. free(ctx->internal_buf);
  86582. if(0 == (ctx->internal_buf = (FLAC__byte*)safe_malloc_(bytes_needed)))
  86583. return false;
  86584. }
  86585. ctx->internal_buf = tmp;
  86586. ctx->capacity = bytes_needed;
  86587. }
  86588. format_input_(ctx->internal_buf, signal, channels, samples, bytes_per_sample);
  86589. FLAC__MD5Update(ctx, ctx->internal_buf, bytes_needed);
  86590. return true;
  86591. }
  86592. #endif
  86593. /*** End of inlined file: md5.c ***/
  86594. /*** Start of inlined file: memory.c ***/
  86595. /*** Start of inlined file: juce_FlacHeader.h ***/
  86596. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86597. // tasks..
  86598. #define VERSION "1.2.1"
  86599. #define FLAC__NO_DLL 1
  86600. #if JUCE_MSVC
  86601. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86602. #endif
  86603. #if JUCE_MAC
  86604. #define FLAC__SYS_DARWIN 1
  86605. #endif
  86606. /*** End of inlined file: juce_FlacHeader.h ***/
  86607. #if JUCE_USE_FLAC
  86608. #if HAVE_CONFIG_H
  86609. # include <config.h>
  86610. #endif
  86611. /*** Start of inlined file: memory.h ***/
  86612. #ifndef FLAC__PRIVATE__MEMORY_H
  86613. #define FLAC__PRIVATE__MEMORY_H
  86614. #ifdef HAVE_CONFIG_H
  86615. #include <config.h>
  86616. #endif
  86617. #include <stdlib.h> /* for size_t */
  86618. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address);
  86619. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer);
  86620. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer);
  86621. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer);
  86622. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer);
  86623. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86624. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer);
  86625. #endif
  86626. #endif
  86627. /*** End of inlined file: memory.h ***/
  86628. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address)
  86629. {
  86630. void *x;
  86631. FLAC__ASSERT(0 != aligned_address);
  86632. #ifdef FLAC__ALIGN_MALLOC_DATA
  86633. x = safe_malloc_add_2op_(bytes, /*+*/31);
  86634. #ifdef SIZEOF_VOIDP
  86635. #if SIZEOF_VOIDP == 4
  86636. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  86637. #elif SIZEOF_VOIDP == 8
  86638. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  86639. #else
  86640. # error Unsupported sizeof(void*)
  86641. #endif
  86642. #else
  86643. if(sizeof(void*) == sizeof(unsigned))
  86644. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  86645. else if(sizeof(void*) == sizeof(FLAC__uint64))
  86646. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  86647. else
  86648. return 0;
  86649. #endif
  86650. #else
  86651. x = safe_malloc_(bytes);
  86652. *aligned_address = x;
  86653. #endif
  86654. return x;
  86655. }
  86656. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer)
  86657. {
  86658. FLAC__int32 *pu; /* unaligned pointer */
  86659. union { /* union needed to comply with C99 pointer aliasing rules */
  86660. FLAC__int32 *pa; /* aligned pointer */
  86661. void *pv; /* aligned pointer alias */
  86662. } u;
  86663. FLAC__ASSERT(elements > 0);
  86664. FLAC__ASSERT(0 != unaligned_pointer);
  86665. FLAC__ASSERT(0 != aligned_pointer);
  86666. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86667. pu = (FLAC__int32*)FLAC__memory_alloc_aligned(sizeof(*pu) * (size_t)elements, &u.pv);
  86668. if(0 == pu) {
  86669. return false;
  86670. }
  86671. else {
  86672. if(*unaligned_pointer != 0)
  86673. free(*unaligned_pointer);
  86674. *unaligned_pointer = pu;
  86675. *aligned_pointer = u.pa;
  86676. return true;
  86677. }
  86678. }
  86679. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer)
  86680. {
  86681. FLAC__uint32 *pu; /* unaligned pointer */
  86682. union { /* union needed to comply with C99 pointer aliasing rules */
  86683. FLAC__uint32 *pa; /* aligned pointer */
  86684. void *pv; /* aligned pointer alias */
  86685. } u;
  86686. FLAC__ASSERT(elements > 0);
  86687. FLAC__ASSERT(0 != unaligned_pointer);
  86688. FLAC__ASSERT(0 != aligned_pointer);
  86689. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86690. pu = (FLAC__uint32*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86691. if(0 == pu) {
  86692. return false;
  86693. }
  86694. else {
  86695. if(*unaligned_pointer != 0)
  86696. free(*unaligned_pointer);
  86697. *unaligned_pointer = pu;
  86698. *aligned_pointer = u.pa;
  86699. return true;
  86700. }
  86701. }
  86702. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer)
  86703. {
  86704. FLAC__uint64 *pu; /* unaligned pointer */
  86705. union { /* union needed to comply with C99 pointer aliasing rules */
  86706. FLAC__uint64 *pa; /* aligned pointer */
  86707. void *pv; /* aligned pointer alias */
  86708. } u;
  86709. FLAC__ASSERT(elements > 0);
  86710. FLAC__ASSERT(0 != unaligned_pointer);
  86711. FLAC__ASSERT(0 != aligned_pointer);
  86712. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86713. pu = (FLAC__uint64*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86714. if(0 == pu) {
  86715. return false;
  86716. }
  86717. else {
  86718. if(*unaligned_pointer != 0)
  86719. free(*unaligned_pointer);
  86720. *unaligned_pointer = pu;
  86721. *aligned_pointer = u.pa;
  86722. return true;
  86723. }
  86724. }
  86725. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer)
  86726. {
  86727. unsigned *pu; /* unaligned pointer */
  86728. union { /* union needed to comply with C99 pointer aliasing rules */
  86729. unsigned *pa; /* aligned pointer */
  86730. void *pv; /* aligned pointer alias */
  86731. } u;
  86732. FLAC__ASSERT(elements > 0);
  86733. FLAC__ASSERT(0 != unaligned_pointer);
  86734. FLAC__ASSERT(0 != aligned_pointer);
  86735. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86736. pu = (unsigned*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86737. if(0 == pu) {
  86738. return false;
  86739. }
  86740. else {
  86741. if(*unaligned_pointer != 0)
  86742. free(*unaligned_pointer);
  86743. *unaligned_pointer = pu;
  86744. *aligned_pointer = u.pa;
  86745. return true;
  86746. }
  86747. }
  86748. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86749. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer)
  86750. {
  86751. FLAC__real *pu; /* unaligned pointer */
  86752. union { /* union needed to comply with C99 pointer aliasing rules */
  86753. FLAC__real *pa; /* aligned pointer */
  86754. void *pv; /* aligned pointer alias */
  86755. } u;
  86756. FLAC__ASSERT(elements > 0);
  86757. FLAC__ASSERT(0 != unaligned_pointer);
  86758. FLAC__ASSERT(0 != aligned_pointer);
  86759. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86760. pu = (FLAC__real*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86761. if(0 == pu) {
  86762. return false;
  86763. }
  86764. else {
  86765. if(*unaligned_pointer != 0)
  86766. free(*unaligned_pointer);
  86767. *unaligned_pointer = pu;
  86768. *aligned_pointer = u.pa;
  86769. return true;
  86770. }
  86771. }
  86772. #endif
  86773. #endif
  86774. /*** End of inlined file: memory.c ***/
  86775. /*** Start of inlined file: stream_decoder.c ***/
  86776. /*** Start of inlined file: juce_FlacHeader.h ***/
  86777. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86778. // tasks..
  86779. #define VERSION "1.2.1"
  86780. #define FLAC__NO_DLL 1
  86781. #if JUCE_MSVC
  86782. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86783. #endif
  86784. #if JUCE_MAC
  86785. #define FLAC__SYS_DARWIN 1
  86786. #endif
  86787. /*** End of inlined file: juce_FlacHeader.h ***/
  86788. #if JUCE_USE_FLAC
  86789. #if HAVE_CONFIG_H
  86790. # include <config.h>
  86791. #endif
  86792. #if defined _MSC_VER || defined __MINGW32__
  86793. #include <io.h> /* for _setmode() */
  86794. #include <fcntl.h> /* for _O_BINARY */
  86795. #endif
  86796. #if defined __CYGWIN__ || defined __EMX__
  86797. #include <io.h> /* for setmode(), O_BINARY */
  86798. #include <fcntl.h> /* for _O_BINARY */
  86799. #endif
  86800. #include <stdio.h>
  86801. #include <stdlib.h> /* for malloc() */
  86802. #include <string.h> /* for memset/memcpy() */
  86803. #include <sys/stat.h> /* for stat() */
  86804. #include <sys/types.h> /* for off_t */
  86805. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  86806. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  86807. #define fseeko fseek
  86808. #define ftello ftell
  86809. #endif
  86810. #endif
  86811. /*** Start of inlined file: stream_decoder.h ***/
  86812. #ifndef FLAC__PROTECTED__STREAM_DECODER_H
  86813. #define FLAC__PROTECTED__STREAM_DECODER_H
  86814. #if FLAC__HAS_OGG
  86815. #include "include/private/ogg_decoder_aspect.h"
  86816. #endif
  86817. typedef struct FLAC__StreamDecoderProtected {
  86818. FLAC__StreamDecoderState state;
  86819. unsigned channels;
  86820. FLAC__ChannelAssignment channel_assignment;
  86821. unsigned bits_per_sample;
  86822. unsigned sample_rate; /* in Hz */
  86823. unsigned blocksize; /* in samples (per channel) */
  86824. FLAC__bool md5_checking; /* if true, generate MD5 signature of decoded data and compare against signature in the STREAMINFO metadata block */
  86825. #if FLAC__HAS_OGG
  86826. FLAC__OggDecoderAspect ogg_decoder_aspect;
  86827. #endif
  86828. } FLAC__StreamDecoderProtected;
  86829. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder);
  86830. #endif
  86831. /*** End of inlined file: stream_decoder.h ***/
  86832. #ifdef max
  86833. #undef max
  86834. #endif
  86835. #define max(a,b) ((a)>(b)?(a):(b))
  86836. #ifdef _MSC_VER
  86837. #define FLAC__U64L(x) x
  86838. #else
  86839. #define FLAC__U64L(x) x##LLU
  86840. #endif
  86841. FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC =
  86842. #if FLAC__HAS_OGG
  86843. 1
  86844. #else
  86845. 0
  86846. #endif
  86847. ;
  86848. static FLAC__byte ID3V2_TAG_[3] = { 'I', 'D', '3' };
  86849. static void set_defaults_dec(FLAC__StreamDecoder *decoder);
  86850. static FILE *get_binary_stdin_(void);
  86851. static FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels);
  86852. static FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id);
  86853. static FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder);
  86854. static FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder);
  86855. static FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  86856. static FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  86857. static FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj);
  86858. static FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj);
  86859. static FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj);
  86860. static FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder);
  86861. static FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder);
  86862. static FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode);
  86863. static FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder);
  86864. static FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  86865. static FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  86866. static FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  86867. static FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  86868. static FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  86869. 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);
  86870. static FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder);
  86871. static FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data);
  86872. #if FLAC__HAS_OGG
  86873. static FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes);
  86874. static FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  86875. #endif
  86876. static FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
  86877. static void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status);
  86878. static FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  86879. #if FLAC__HAS_OGG
  86880. static FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  86881. #endif
  86882. static FLAC__StreamDecoderReadStatus file_read_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  86883. static FLAC__StreamDecoderSeekStatus file_seek_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  86884. static FLAC__StreamDecoderTellStatus file_tell_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  86885. static FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  86886. static FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data);
  86887. typedef struct FLAC__StreamDecoderPrivate {
  86888. #if FLAC__HAS_OGG
  86889. FLAC__bool is_ogg;
  86890. #endif
  86891. FLAC__StreamDecoderReadCallback read_callback;
  86892. FLAC__StreamDecoderSeekCallback seek_callback;
  86893. FLAC__StreamDecoderTellCallback tell_callback;
  86894. FLAC__StreamDecoderLengthCallback length_callback;
  86895. FLAC__StreamDecoderEofCallback eof_callback;
  86896. FLAC__StreamDecoderWriteCallback write_callback;
  86897. FLAC__StreamDecoderMetadataCallback metadata_callback;
  86898. FLAC__StreamDecoderErrorCallback error_callback;
  86899. 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[]);
  86900. 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[]);
  86901. 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[]);
  86902. 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[]);
  86903. FLAC__bool (*local_bitreader_read_rice_signed_block)(FLAC__BitReader *br, int* vals, unsigned nvals, unsigned parameter);
  86904. void *client_data;
  86905. FILE *file; /* only used if FLAC__stream_decoder_init_file()/FLAC__stream_decoder_init_file() called, else NULL */
  86906. FLAC__BitReader *input;
  86907. FLAC__int32 *output[FLAC__MAX_CHANNELS];
  86908. FLAC__int32 *residual[FLAC__MAX_CHANNELS]; /* WATCHOUT: these are the aligned pointers; the real pointers that should be free()'d are residual_unaligned[] below */
  86909. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents[FLAC__MAX_CHANNELS];
  86910. unsigned output_capacity, output_channels;
  86911. FLAC__uint32 fixed_block_size, next_fixed_block_size;
  86912. FLAC__uint64 samples_decoded;
  86913. FLAC__bool has_stream_info, has_seek_table;
  86914. FLAC__StreamMetadata stream_info;
  86915. FLAC__StreamMetadata seek_table;
  86916. FLAC__bool metadata_filter[128]; /* MAGIC number 128 == total number of metadata block types == 1 << 7 */
  86917. FLAC__byte *metadata_filter_ids;
  86918. size_t metadata_filter_ids_count, metadata_filter_ids_capacity; /* units for both are IDs, not bytes */
  86919. FLAC__Frame frame;
  86920. FLAC__bool cached; /* true if there is a byte in lookahead */
  86921. FLAC__CPUInfo cpuinfo;
  86922. FLAC__byte header_warmup[2]; /* contains the sync code and reserved bits */
  86923. FLAC__byte lookahead; /* temp storage when we need to look ahead one byte in the stream */
  86924. FLAC__int32 *residual_unaligned[FLAC__MAX_CHANNELS];
  86925. 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 */
  86926. FLAC__bool internal_reset_hack; /* used only during init() so we can call reset to set up the decoder without rewinding the input */
  86927. FLAC__bool is_seeking;
  86928. FLAC__MD5Context md5context;
  86929. FLAC__byte computed_md5sum[16]; /* this is the sum we computed from the decoded data */
  86930. FLAC__Frame last_frame; /* holds the info of the last frame we seeked to */
  86931. FLAC__uint64 first_frame_offset; /* hint to the seek routine of where in the stream the first audio frame starts */
  86932. FLAC__uint64 target_sample;
  86933. unsigned unparseable_frame_count; /* used to tell whether we're decoding a future version of FLAC or just got a bad sync */
  86934. #if FLAC__HAS_OGG
  86935. FLAC__bool got_a_frame; /* hack needed in Ogg FLAC seek routine to check when process_single() actually writes a frame */
  86936. #endif
  86937. } FLAC__StreamDecoderPrivate;
  86938. FLAC_API const char * const FLAC__StreamDecoderStateString[] = {
  86939. "FLAC__STREAM_DECODER_SEARCH_FOR_METADATA",
  86940. "FLAC__STREAM_DECODER_READ_METADATA",
  86941. "FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC",
  86942. "FLAC__STREAM_DECODER_READ_FRAME",
  86943. "FLAC__STREAM_DECODER_END_OF_STREAM",
  86944. "FLAC__STREAM_DECODER_OGG_ERROR",
  86945. "FLAC__STREAM_DECODER_SEEK_ERROR",
  86946. "FLAC__STREAM_DECODER_ABORTED",
  86947. "FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR",
  86948. "FLAC__STREAM_DECODER_UNINITIALIZED"
  86949. };
  86950. FLAC_API const char * const FLAC__StreamDecoderInitStatusString[] = {
  86951. "FLAC__STREAM_DECODER_INIT_STATUS_OK",
  86952. "FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  86953. "FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS",
  86954. "FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR",
  86955. "FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE",
  86956. "FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED"
  86957. };
  86958. FLAC_API const char * const FLAC__StreamDecoderReadStatusString[] = {
  86959. "FLAC__STREAM_DECODER_READ_STATUS_CONTINUE",
  86960. "FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM",
  86961. "FLAC__STREAM_DECODER_READ_STATUS_ABORT"
  86962. };
  86963. FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[] = {
  86964. "FLAC__STREAM_DECODER_SEEK_STATUS_OK",
  86965. "FLAC__STREAM_DECODER_SEEK_STATUS_ERROR",
  86966. "FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED"
  86967. };
  86968. FLAC_API const char * const FLAC__StreamDecoderTellStatusString[] = {
  86969. "FLAC__STREAM_DECODER_TELL_STATUS_OK",
  86970. "FLAC__STREAM_DECODER_TELL_STATUS_ERROR",
  86971. "FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED"
  86972. };
  86973. FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[] = {
  86974. "FLAC__STREAM_DECODER_LENGTH_STATUS_OK",
  86975. "FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR",
  86976. "FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED"
  86977. };
  86978. FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[] = {
  86979. "FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE",
  86980. "FLAC__STREAM_DECODER_WRITE_STATUS_ABORT"
  86981. };
  86982. FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[] = {
  86983. "FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC",
  86984. "FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER",
  86985. "FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH",
  86986. "FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM"
  86987. };
  86988. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void)
  86989. {
  86990. FLAC__StreamDecoder *decoder;
  86991. unsigned i;
  86992. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  86993. decoder = (FLAC__StreamDecoder*)calloc(1, sizeof(FLAC__StreamDecoder));
  86994. if(decoder == 0) {
  86995. return 0;
  86996. }
  86997. decoder->protected_ = (FLAC__StreamDecoderProtected*)calloc(1, sizeof(FLAC__StreamDecoderProtected));
  86998. if(decoder->protected_ == 0) {
  86999. free(decoder);
  87000. return 0;
  87001. }
  87002. decoder->private_ = (FLAC__StreamDecoderPrivate*)calloc(1, sizeof(FLAC__StreamDecoderPrivate));
  87003. if(decoder->private_ == 0) {
  87004. free(decoder->protected_);
  87005. free(decoder);
  87006. return 0;
  87007. }
  87008. decoder->private_->input = FLAC__bitreader_new();
  87009. if(decoder->private_->input == 0) {
  87010. free(decoder->private_);
  87011. free(decoder->protected_);
  87012. free(decoder);
  87013. return 0;
  87014. }
  87015. decoder->private_->metadata_filter_ids_capacity = 16;
  87016. if(0 == (decoder->private_->metadata_filter_ids = (FLAC__byte*)malloc((FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) * decoder->private_->metadata_filter_ids_capacity))) {
  87017. FLAC__bitreader_delete(decoder->private_->input);
  87018. free(decoder->private_);
  87019. free(decoder->protected_);
  87020. free(decoder);
  87021. return 0;
  87022. }
  87023. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87024. decoder->private_->output[i] = 0;
  87025. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87026. }
  87027. decoder->private_->output_capacity = 0;
  87028. decoder->private_->output_channels = 0;
  87029. decoder->private_->has_seek_table = false;
  87030. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  87031. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&decoder->private_->partitioned_rice_contents[i]);
  87032. decoder->private_->file = 0;
  87033. set_defaults_dec(decoder);
  87034. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87035. return decoder;
  87036. }
  87037. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder)
  87038. {
  87039. unsigned i;
  87040. FLAC__ASSERT(0 != decoder);
  87041. FLAC__ASSERT(0 != decoder->protected_);
  87042. FLAC__ASSERT(0 != decoder->private_);
  87043. FLAC__ASSERT(0 != decoder->private_->input);
  87044. (void)FLAC__stream_decoder_finish(decoder);
  87045. if(0 != decoder->private_->metadata_filter_ids)
  87046. free(decoder->private_->metadata_filter_ids);
  87047. FLAC__bitreader_delete(decoder->private_->input);
  87048. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  87049. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&decoder->private_->partitioned_rice_contents[i]);
  87050. free(decoder->private_);
  87051. free(decoder->protected_);
  87052. free(decoder);
  87053. }
  87054. static FLAC__StreamDecoderInitStatus init_stream_internal_dec(
  87055. FLAC__StreamDecoder *decoder,
  87056. FLAC__StreamDecoderReadCallback read_callback,
  87057. FLAC__StreamDecoderSeekCallback seek_callback,
  87058. FLAC__StreamDecoderTellCallback tell_callback,
  87059. FLAC__StreamDecoderLengthCallback length_callback,
  87060. FLAC__StreamDecoderEofCallback eof_callback,
  87061. FLAC__StreamDecoderWriteCallback write_callback,
  87062. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87063. FLAC__StreamDecoderErrorCallback error_callback,
  87064. void *client_data,
  87065. FLAC__bool is_ogg
  87066. )
  87067. {
  87068. FLAC__ASSERT(0 != decoder);
  87069. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87070. return FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED;
  87071. #if !FLAC__HAS_OGG
  87072. if(is_ogg)
  87073. return FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  87074. #endif
  87075. if(
  87076. 0 == read_callback ||
  87077. 0 == write_callback ||
  87078. 0 == error_callback ||
  87079. (seek_callback && (0 == tell_callback || 0 == length_callback || 0 == eof_callback))
  87080. )
  87081. return FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS;
  87082. #if FLAC__HAS_OGG
  87083. decoder->private_->is_ogg = is_ogg;
  87084. if(is_ogg && !FLAC__ogg_decoder_aspect_init(&decoder->protected_->ogg_decoder_aspect))
  87085. return decoder->protected_->state = FLAC__STREAM_DECODER_OGG_ERROR;
  87086. #endif
  87087. FLAC__cpu_info(&decoder->private_->cpuinfo);
  87088. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal;
  87089. decoder->private_->local_lpc_restore_signal_64bit = FLAC__lpc_restore_signal_wide;
  87090. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal;
  87091. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal;
  87092. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block;
  87093. #ifndef FLAC__NO_ASM
  87094. if(decoder->private_->cpuinfo.use_asm) {
  87095. #ifdef FLAC__CPU_IA32
  87096. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  87097. #ifdef FLAC__HAS_NASM
  87098. #if 1 /*@@@@@@ OPT: not clearly faster, needs more testing */
  87099. if(decoder->private_->cpuinfo.data.ia32.bswap)
  87100. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap;
  87101. #endif
  87102. if(decoder->private_->cpuinfo.data.ia32.mmx) {
  87103. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87104. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87105. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87106. }
  87107. else {
  87108. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87109. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32;
  87110. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32;
  87111. }
  87112. #endif
  87113. #elif defined FLAC__CPU_PPC
  87114. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_PPC);
  87115. if(decoder->private_->cpuinfo.data.ppc.altivec) {
  87116. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ppc_altivec_16;
  87117. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ppc_altivec_16_order8;
  87118. }
  87119. #endif
  87120. }
  87121. #endif
  87122. if(!FLAC__bitreader_init(decoder->private_->input, decoder->private_->cpuinfo, read_callback_, decoder)) {
  87123. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87124. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87125. }
  87126. decoder->private_->read_callback = read_callback;
  87127. decoder->private_->seek_callback = seek_callback;
  87128. decoder->private_->tell_callback = tell_callback;
  87129. decoder->private_->length_callback = length_callback;
  87130. decoder->private_->eof_callback = eof_callback;
  87131. decoder->private_->write_callback = write_callback;
  87132. decoder->private_->metadata_callback = metadata_callback;
  87133. decoder->private_->error_callback = error_callback;
  87134. decoder->private_->client_data = client_data;
  87135. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  87136. decoder->private_->samples_decoded = 0;
  87137. decoder->private_->has_stream_info = false;
  87138. decoder->private_->cached = false;
  87139. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  87140. decoder->private_->is_seeking = false;
  87141. decoder->private_->internal_reset_hack = true; /* so the following reset does not try to rewind the input */
  87142. if(!FLAC__stream_decoder_reset(decoder)) {
  87143. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87144. }
  87145. return FLAC__STREAM_DECODER_INIT_STATUS_OK;
  87146. }
  87147. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  87148. FLAC__StreamDecoder *decoder,
  87149. FLAC__StreamDecoderReadCallback read_callback,
  87150. FLAC__StreamDecoderSeekCallback seek_callback,
  87151. FLAC__StreamDecoderTellCallback tell_callback,
  87152. FLAC__StreamDecoderLengthCallback length_callback,
  87153. FLAC__StreamDecoderEofCallback eof_callback,
  87154. FLAC__StreamDecoderWriteCallback write_callback,
  87155. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87156. FLAC__StreamDecoderErrorCallback error_callback,
  87157. void *client_data
  87158. )
  87159. {
  87160. return init_stream_internal_dec(
  87161. decoder,
  87162. read_callback,
  87163. seek_callback,
  87164. tell_callback,
  87165. length_callback,
  87166. eof_callback,
  87167. write_callback,
  87168. metadata_callback,
  87169. error_callback,
  87170. client_data,
  87171. false
  87172. );
  87173. }
  87174. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  87175. FLAC__StreamDecoder *decoder,
  87176. FLAC__StreamDecoderReadCallback read_callback,
  87177. FLAC__StreamDecoderSeekCallback seek_callback,
  87178. FLAC__StreamDecoderTellCallback tell_callback,
  87179. FLAC__StreamDecoderLengthCallback length_callback,
  87180. FLAC__StreamDecoderEofCallback eof_callback,
  87181. FLAC__StreamDecoderWriteCallback write_callback,
  87182. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87183. FLAC__StreamDecoderErrorCallback error_callback,
  87184. void *client_data
  87185. )
  87186. {
  87187. return init_stream_internal_dec(
  87188. decoder,
  87189. read_callback,
  87190. seek_callback,
  87191. tell_callback,
  87192. length_callback,
  87193. eof_callback,
  87194. write_callback,
  87195. metadata_callback,
  87196. error_callback,
  87197. client_data,
  87198. true
  87199. );
  87200. }
  87201. static FLAC__StreamDecoderInitStatus init_FILE_internal_(
  87202. FLAC__StreamDecoder *decoder,
  87203. FILE *file,
  87204. FLAC__StreamDecoderWriteCallback write_callback,
  87205. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87206. FLAC__StreamDecoderErrorCallback error_callback,
  87207. void *client_data,
  87208. FLAC__bool is_ogg
  87209. )
  87210. {
  87211. FLAC__ASSERT(0 != decoder);
  87212. FLAC__ASSERT(0 != file);
  87213. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87214. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87215. if(0 == write_callback || 0 == error_callback)
  87216. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87217. if(file == stdin)
  87218. file = get_binary_stdin_(); /* just to be safe */
  87219. decoder->private_->file = file;
  87220. return init_stream_internal_dec(
  87221. decoder,
  87222. file_read_callback_dec,
  87223. decoder->private_->file == stdin? 0: file_seek_callback_dec,
  87224. decoder->private_->file == stdin? 0: file_tell_callback_dec,
  87225. decoder->private_->file == stdin? 0: file_length_callback_,
  87226. file_eof_callback_,
  87227. write_callback,
  87228. metadata_callback,
  87229. error_callback,
  87230. client_data,
  87231. is_ogg
  87232. );
  87233. }
  87234. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  87235. FLAC__StreamDecoder *decoder,
  87236. FILE *file,
  87237. FLAC__StreamDecoderWriteCallback write_callback,
  87238. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87239. FLAC__StreamDecoderErrorCallback error_callback,
  87240. void *client_data
  87241. )
  87242. {
  87243. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87244. }
  87245. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  87246. FLAC__StreamDecoder *decoder,
  87247. FILE *file,
  87248. FLAC__StreamDecoderWriteCallback write_callback,
  87249. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87250. FLAC__StreamDecoderErrorCallback error_callback,
  87251. void *client_data
  87252. )
  87253. {
  87254. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87255. }
  87256. static FLAC__StreamDecoderInitStatus init_file_internal_(
  87257. FLAC__StreamDecoder *decoder,
  87258. const char *filename,
  87259. FLAC__StreamDecoderWriteCallback write_callback,
  87260. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87261. FLAC__StreamDecoderErrorCallback error_callback,
  87262. void *client_data,
  87263. FLAC__bool is_ogg
  87264. )
  87265. {
  87266. FILE *file;
  87267. FLAC__ASSERT(0 != decoder);
  87268. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87269. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87270. if(0 == write_callback || 0 == error_callback)
  87271. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87272. file = filename? fopen(filename, "rb") : stdin;
  87273. if(0 == file)
  87274. return FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE;
  87275. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, is_ogg);
  87276. }
  87277. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  87278. FLAC__StreamDecoder *decoder,
  87279. const char *filename,
  87280. FLAC__StreamDecoderWriteCallback write_callback,
  87281. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87282. FLAC__StreamDecoderErrorCallback error_callback,
  87283. void *client_data
  87284. )
  87285. {
  87286. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87287. }
  87288. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  87289. FLAC__StreamDecoder *decoder,
  87290. const char *filename,
  87291. FLAC__StreamDecoderWriteCallback write_callback,
  87292. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87293. FLAC__StreamDecoderErrorCallback error_callback,
  87294. void *client_data
  87295. )
  87296. {
  87297. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87298. }
  87299. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder)
  87300. {
  87301. FLAC__bool md5_failed = false;
  87302. unsigned i;
  87303. FLAC__ASSERT(0 != decoder);
  87304. FLAC__ASSERT(0 != decoder->private_);
  87305. FLAC__ASSERT(0 != decoder->protected_);
  87306. if(decoder->protected_->state == FLAC__STREAM_DECODER_UNINITIALIZED)
  87307. return true;
  87308. FLAC__MD5Final(decoder->private_->computed_md5sum, &decoder->private_->md5context);
  87309. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87310. free(decoder->private_->seek_table.data.seek_table.points);
  87311. decoder->private_->seek_table.data.seek_table.points = 0;
  87312. decoder->private_->has_seek_table = false;
  87313. }
  87314. FLAC__bitreader_free(decoder->private_->input);
  87315. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87316. if(0 != decoder->private_->output[i]) {
  87317. free(decoder->private_->output[i]-4);
  87318. decoder->private_->output[i] = 0;
  87319. }
  87320. if(0 != decoder->private_->residual_unaligned[i]) {
  87321. free(decoder->private_->residual_unaligned[i]);
  87322. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87323. }
  87324. }
  87325. decoder->private_->output_capacity = 0;
  87326. decoder->private_->output_channels = 0;
  87327. #if FLAC__HAS_OGG
  87328. if(decoder->private_->is_ogg)
  87329. FLAC__ogg_decoder_aspect_finish(&decoder->protected_->ogg_decoder_aspect);
  87330. #endif
  87331. if(0 != decoder->private_->file) {
  87332. if(decoder->private_->file != stdin)
  87333. fclose(decoder->private_->file);
  87334. decoder->private_->file = 0;
  87335. }
  87336. if(decoder->private_->do_md5_checking) {
  87337. if(memcmp(decoder->private_->stream_info.data.stream_info.md5sum, decoder->private_->computed_md5sum, 16))
  87338. md5_failed = true;
  87339. }
  87340. decoder->private_->is_seeking = false;
  87341. set_defaults_dec(decoder);
  87342. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87343. return !md5_failed;
  87344. }
  87345. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long value)
  87346. {
  87347. FLAC__ASSERT(0 != decoder);
  87348. FLAC__ASSERT(0 != decoder->private_);
  87349. FLAC__ASSERT(0 != decoder->protected_);
  87350. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87351. return false;
  87352. #if FLAC__HAS_OGG
  87353. FLAC__ogg_decoder_aspect_set_serial_number(&decoder->protected_->ogg_decoder_aspect, value);
  87354. return true;
  87355. #else
  87356. (void)value;
  87357. return false;
  87358. #endif
  87359. }
  87360. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value)
  87361. {
  87362. FLAC__ASSERT(0 != decoder);
  87363. FLAC__ASSERT(0 != decoder->protected_);
  87364. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87365. return false;
  87366. decoder->protected_->md5_checking = value;
  87367. return true;
  87368. }
  87369. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87370. {
  87371. FLAC__ASSERT(0 != decoder);
  87372. FLAC__ASSERT(0 != decoder->private_);
  87373. FLAC__ASSERT(0 != decoder->protected_);
  87374. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87375. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87376. return false;
  87377. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87378. return false;
  87379. decoder->private_->metadata_filter[type] = true;
  87380. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87381. decoder->private_->metadata_filter_ids_count = 0;
  87382. return true;
  87383. }
  87384. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87385. {
  87386. FLAC__ASSERT(0 != decoder);
  87387. FLAC__ASSERT(0 != decoder->private_);
  87388. FLAC__ASSERT(0 != decoder->protected_);
  87389. FLAC__ASSERT(0 != id);
  87390. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87391. return false;
  87392. if(decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87393. return true;
  87394. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87395. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87396. 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))) {
  87397. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87398. return false;
  87399. }
  87400. decoder->private_->metadata_filter_ids_capacity *= 2;
  87401. }
  87402. 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));
  87403. decoder->private_->metadata_filter_ids_count++;
  87404. return true;
  87405. }
  87406. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder)
  87407. {
  87408. unsigned i;
  87409. FLAC__ASSERT(0 != decoder);
  87410. FLAC__ASSERT(0 != decoder->private_);
  87411. FLAC__ASSERT(0 != decoder->protected_);
  87412. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87413. return false;
  87414. for(i = 0; i < sizeof(decoder->private_->metadata_filter) / sizeof(decoder->private_->metadata_filter[0]); i++)
  87415. decoder->private_->metadata_filter[i] = true;
  87416. decoder->private_->metadata_filter_ids_count = 0;
  87417. return true;
  87418. }
  87419. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87420. {
  87421. FLAC__ASSERT(0 != decoder);
  87422. FLAC__ASSERT(0 != decoder->private_);
  87423. FLAC__ASSERT(0 != decoder->protected_);
  87424. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87425. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87426. return false;
  87427. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87428. return false;
  87429. decoder->private_->metadata_filter[type] = false;
  87430. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87431. decoder->private_->metadata_filter_ids_count = 0;
  87432. return true;
  87433. }
  87434. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87435. {
  87436. FLAC__ASSERT(0 != decoder);
  87437. FLAC__ASSERT(0 != decoder->private_);
  87438. FLAC__ASSERT(0 != decoder->protected_);
  87439. FLAC__ASSERT(0 != id);
  87440. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87441. return false;
  87442. if(!decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87443. return true;
  87444. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87445. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87446. 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))) {
  87447. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87448. return false;
  87449. }
  87450. decoder->private_->metadata_filter_ids_capacity *= 2;
  87451. }
  87452. 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));
  87453. decoder->private_->metadata_filter_ids_count++;
  87454. return true;
  87455. }
  87456. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder)
  87457. {
  87458. FLAC__ASSERT(0 != decoder);
  87459. FLAC__ASSERT(0 != decoder->private_);
  87460. FLAC__ASSERT(0 != decoder->protected_);
  87461. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87462. return false;
  87463. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  87464. decoder->private_->metadata_filter_ids_count = 0;
  87465. return true;
  87466. }
  87467. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder)
  87468. {
  87469. FLAC__ASSERT(0 != decoder);
  87470. FLAC__ASSERT(0 != decoder->protected_);
  87471. return decoder->protected_->state;
  87472. }
  87473. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder)
  87474. {
  87475. return FLAC__StreamDecoderStateString[decoder->protected_->state];
  87476. }
  87477. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder)
  87478. {
  87479. FLAC__ASSERT(0 != decoder);
  87480. FLAC__ASSERT(0 != decoder->protected_);
  87481. return decoder->protected_->md5_checking;
  87482. }
  87483. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder)
  87484. {
  87485. FLAC__ASSERT(0 != decoder);
  87486. FLAC__ASSERT(0 != decoder->protected_);
  87487. return decoder->private_->has_stream_info? decoder->private_->stream_info.data.stream_info.total_samples : 0;
  87488. }
  87489. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder)
  87490. {
  87491. FLAC__ASSERT(0 != decoder);
  87492. FLAC__ASSERT(0 != decoder->protected_);
  87493. return decoder->protected_->channels;
  87494. }
  87495. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder)
  87496. {
  87497. FLAC__ASSERT(0 != decoder);
  87498. FLAC__ASSERT(0 != decoder->protected_);
  87499. return decoder->protected_->channel_assignment;
  87500. }
  87501. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder)
  87502. {
  87503. FLAC__ASSERT(0 != decoder);
  87504. FLAC__ASSERT(0 != decoder->protected_);
  87505. return decoder->protected_->bits_per_sample;
  87506. }
  87507. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder)
  87508. {
  87509. FLAC__ASSERT(0 != decoder);
  87510. FLAC__ASSERT(0 != decoder->protected_);
  87511. return decoder->protected_->sample_rate;
  87512. }
  87513. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder)
  87514. {
  87515. FLAC__ASSERT(0 != decoder);
  87516. FLAC__ASSERT(0 != decoder->protected_);
  87517. return decoder->protected_->blocksize;
  87518. }
  87519. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position)
  87520. {
  87521. FLAC__ASSERT(0 != decoder);
  87522. FLAC__ASSERT(0 != decoder->private_);
  87523. FLAC__ASSERT(0 != position);
  87524. #if FLAC__HAS_OGG
  87525. if(decoder->private_->is_ogg)
  87526. return false;
  87527. #endif
  87528. if(0 == decoder->private_->tell_callback)
  87529. return false;
  87530. if(decoder->private_->tell_callback(decoder, position, decoder->private_->client_data) != FLAC__STREAM_DECODER_TELL_STATUS_OK)
  87531. return false;
  87532. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input))
  87533. return false;
  87534. FLAC__ASSERT(*position >= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder));
  87535. *position -= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder);
  87536. return true;
  87537. }
  87538. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder)
  87539. {
  87540. FLAC__ASSERT(0 != decoder);
  87541. FLAC__ASSERT(0 != decoder->private_);
  87542. FLAC__ASSERT(0 != decoder->protected_);
  87543. decoder->private_->samples_decoded = 0;
  87544. decoder->private_->do_md5_checking = false;
  87545. #if FLAC__HAS_OGG
  87546. if(decoder->private_->is_ogg)
  87547. FLAC__ogg_decoder_aspect_flush(&decoder->protected_->ogg_decoder_aspect);
  87548. #endif
  87549. if(!FLAC__bitreader_clear(decoder->private_->input)) {
  87550. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87551. return false;
  87552. }
  87553. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  87554. return true;
  87555. }
  87556. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder)
  87557. {
  87558. FLAC__ASSERT(0 != decoder);
  87559. FLAC__ASSERT(0 != decoder->private_);
  87560. FLAC__ASSERT(0 != decoder->protected_);
  87561. if(!FLAC__stream_decoder_flush(decoder)) {
  87562. return false;
  87563. }
  87564. #if FLAC__HAS_OGG
  87565. if(decoder->private_->is_ogg)
  87566. FLAC__ogg_decoder_aspect_reset(&decoder->protected_->ogg_decoder_aspect);
  87567. #endif
  87568. if(!decoder->private_->internal_reset_hack) {
  87569. if(decoder->private_->file == stdin)
  87570. return false; /* can't rewind stdin, reset fails */
  87571. if(decoder->private_->seek_callback && decoder->private_->seek_callback(decoder, 0, decoder->private_->client_data) == FLAC__STREAM_DECODER_SEEK_STATUS_ERROR)
  87572. return false; /* seekable and seek fails, reset fails */
  87573. }
  87574. else
  87575. decoder->private_->internal_reset_hack = false;
  87576. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_METADATA;
  87577. decoder->private_->has_stream_info = false;
  87578. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87579. free(decoder->private_->seek_table.data.seek_table.points);
  87580. decoder->private_->seek_table.data.seek_table.points = 0;
  87581. decoder->private_->has_seek_table = false;
  87582. }
  87583. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  87584. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  87585. FLAC__MD5Init(&decoder->private_->md5context);
  87586. decoder->private_->first_frame_offset = 0;
  87587. decoder->private_->unparseable_frame_count = 0;
  87588. return true;
  87589. }
  87590. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder)
  87591. {
  87592. FLAC__bool got_a_frame;
  87593. FLAC__ASSERT(0 != decoder);
  87594. FLAC__ASSERT(0 != decoder->protected_);
  87595. while(1) {
  87596. switch(decoder->protected_->state) {
  87597. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87598. if(!find_metadata_(decoder))
  87599. return false; /* above function sets the status for us */
  87600. break;
  87601. case FLAC__STREAM_DECODER_READ_METADATA:
  87602. if(!read_metadata_(decoder))
  87603. return false; /* above function sets the status for us */
  87604. else
  87605. return true;
  87606. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87607. if(!frame_sync_(decoder))
  87608. return true; /* above function sets the status for us */
  87609. break;
  87610. case FLAC__STREAM_DECODER_READ_FRAME:
  87611. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/true))
  87612. return false; /* above function sets the status for us */
  87613. if(got_a_frame)
  87614. return true; /* above function sets the status for us */
  87615. break;
  87616. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87617. case FLAC__STREAM_DECODER_ABORTED:
  87618. return true;
  87619. default:
  87620. FLAC__ASSERT(0);
  87621. return false;
  87622. }
  87623. }
  87624. }
  87625. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder)
  87626. {
  87627. FLAC__ASSERT(0 != decoder);
  87628. FLAC__ASSERT(0 != decoder->protected_);
  87629. while(1) {
  87630. switch(decoder->protected_->state) {
  87631. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87632. if(!find_metadata_(decoder))
  87633. return false; /* above function sets the status for us */
  87634. break;
  87635. case FLAC__STREAM_DECODER_READ_METADATA:
  87636. if(!read_metadata_(decoder))
  87637. return false; /* above function sets the status for us */
  87638. break;
  87639. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87640. case FLAC__STREAM_DECODER_READ_FRAME:
  87641. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87642. case FLAC__STREAM_DECODER_ABORTED:
  87643. return true;
  87644. default:
  87645. FLAC__ASSERT(0);
  87646. return false;
  87647. }
  87648. }
  87649. }
  87650. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder)
  87651. {
  87652. FLAC__bool dummy;
  87653. FLAC__ASSERT(0 != decoder);
  87654. FLAC__ASSERT(0 != decoder->protected_);
  87655. while(1) {
  87656. switch(decoder->protected_->state) {
  87657. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87658. if(!find_metadata_(decoder))
  87659. return false; /* above function sets the status for us */
  87660. break;
  87661. case FLAC__STREAM_DECODER_READ_METADATA:
  87662. if(!read_metadata_(decoder))
  87663. return false; /* above function sets the status for us */
  87664. break;
  87665. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87666. if(!frame_sync_(decoder))
  87667. return true; /* above function sets the status for us */
  87668. break;
  87669. case FLAC__STREAM_DECODER_READ_FRAME:
  87670. if(!read_frame_(decoder, &dummy, /*do_full_decode=*/true))
  87671. return false; /* above function sets the status for us */
  87672. break;
  87673. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87674. case FLAC__STREAM_DECODER_ABORTED:
  87675. return true;
  87676. default:
  87677. FLAC__ASSERT(0);
  87678. return false;
  87679. }
  87680. }
  87681. }
  87682. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder)
  87683. {
  87684. FLAC__bool got_a_frame;
  87685. FLAC__ASSERT(0 != decoder);
  87686. FLAC__ASSERT(0 != decoder->protected_);
  87687. while(1) {
  87688. switch(decoder->protected_->state) {
  87689. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87690. case FLAC__STREAM_DECODER_READ_METADATA:
  87691. return false; /* above function sets the status for us */
  87692. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87693. if(!frame_sync_(decoder))
  87694. return true; /* above function sets the status for us */
  87695. break;
  87696. case FLAC__STREAM_DECODER_READ_FRAME:
  87697. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/false))
  87698. return false; /* above function sets the status for us */
  87699. if(got_a_frame)
  87700. return true; /* above function sets the status for us */
  87701. break;
  87702. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87703. case FLAC__STREAM_DECODER_ABORTED:
  87704. return true;
  87705. default:
  87706. FLAC__ASSERT(0);
  87707. return false;
  87708. }
  87709. }
  87710. }
  87711. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample)
  87712. {
  87713. FLAC__uint64 length;
  87714. FLAC__ASSERT(0 != decoder);
  87715. if(
  87716. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA &&
  87717. decoder->protected_->state != FLAC__STREAM_DECODER_READ_METADATA &&
  87718. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC &&
  87719. decoder->protected_->state != FLAC__STREAM_DECODER_READ_FRAME &&
  87720. decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM
  87721. )
  87722. return false;
  87723. if(0 == decoder->private_->seek_callback)
  87724. return false;
  87725. FLAC__ASSERT(decoder->private_->seek_callback);
  87726. FLAC__ASSERT(decoder->private_->tell_callback);
  87727. FLAC__ASSERT(decoder->private_->length_callback);
  87728. FLAC__ASSERT(decoder->private_->eof_callback);
  87729. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder))
  87730. return false;
  87731. decoder->private_->is_seeking = true;
  87732. decoder->private_->do_md5_checking = false;
  87733. if(decoder->private_->length_callback(decoder, &length, decoder->private_->client_data) != FLAC__STREAM_DECODER_LENGTH_STATUS_OK) {
  87734. decoder->private_->is_seeking = false;
  87735. return false;
  87736. }
  87737. if(
  87738. decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA ||
  87739. decoder->protected_->state == FLAC__STREAM_DECODER_READ_METADATA
  87740. ) {
  87741. if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder)) {
  87742. decoder->private_->is_seeking = false;
  87743. return false;
  87744. }
  87745. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder)) {
  87746. decoder->private_->is_seeking = false;
  87747. return false;
  87748. }
  87749. }
  87750. {
  87751. const FLAC__bool ok =
  87752. #if FLAC__HAS_OGG
  87753. decoder->private_->is_ogg?
  87754. seek_to_absolute_sample_ogg_(decoder, length, sample) :
  87755. #endif
  87756. seek_to_absolute_sample_(decoder, length, sample)
  87757. ;
  87758. decoder->private_->is_seeking = false;
  87759. return ok;
  87760. }
  87761. }
  87762. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder)
  87763. {
  87764. FLAC__ASSERT(0 != decoder);
  87765. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87766. FLAC__ASSERT(!(FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) & 7));
  87767. return FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) / 8;
  87768. }
  87769. void set_defaults_dec(FLAC__StreamDecoder *decoder)
  87770. {
  87771. #if FLAC__HAS_OGG
  87772. decoder->private_->is_ogg = false;
  87773. #endif
  87774. decoder->private_->read_callback = 0;
  87775. decoder->private_->seek_callback = 0;
  87776. decoder->private_->tell_callback = 0;
  87777. decoder->private_->length_callback = 0;
  87778. decoder->private_->eof_callback = 0;
  87779. decoder->private_->write_callback = 0;
  87780. decoder->private_->metadata_callback = 0;
  87781. decoder->private_->error_callback = 0;
  87782. decoder->private_->client_data = 0;
  87783. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  87784. decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] = true;
  87785. decoder->private_->metadata_filter_ids_count = 0;
  87786. decoder->protected_->md5_checking = false;
  87787. #if FLAC__HAS_OGG
  87788. FLAC__ogg_decoder_aspect_set_defaults(&decoder->protected_->ogg_decoder_aspect);
  87789. #endif
  87790. }
  87791. FILE *get_binary_stdin_(void)
  87792. {
  87793. #if defined _MSC_VER || defined __MINGW32__
  87794. _setmode(_fileno(stdin), _O_BINARY);
  87795. #elif defined __CYGWIN__
  87796. setmode(_fileno(stdin), _O_BINARY);
  87797. #elif defined __EMX__
  87798. setmode(fileno(stdin), O_BINARY);
  87799. #endif
  87800. return stdin;
  87801. }
  87802. FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels)
  87803. {
  87804. unsigned i;
  87805. FLAC__int32 *tmp;
  87806. if(size <= decoder->private_->output_capacity && channels <= decoder->private_->output_channels)
  87807. return true;
  87808. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87809. if(0 != decoder->private_->output[i]) {
  87810. free(decoder->private_->output[i]-4);
  87811. decoder->private_->output[i] = 0;
  87812. }
  87813. if(0 != decoder->private_->residual_unaligned[i]) {
  87814. free(decoder->private_->residual_unaligned[i]);
  87815. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87816. }
  87817. }
  87818. for(i = 0; i < channels; i++) {
  87819. tmp = (FLAC__int32*)safe_malloc_muladd2_(sizeof(FLAC__int32), /*times (*/size, /*+*/4/*)*/);
  87820. if(tmp == 0) {
  87821. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87822. return false;
  87823. }
  87824. memset(tmp, 0, sizeof(FLAC__int32)*4);
  87825. decoder->private_->output[i] = tmp + 4;
  87826. if(!FLAC__memory_alloc_aligned_int32_array(size, &decoder->private_->residual_unaligned[i], &decoder->private_->residual[i])) {
  87827. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87828. return false;
  87829. }
  87830. }
  87831. decoder->private_->output_capacity = size;
  87832. decoder->private_->output_channels = channels;
  87833. return true;
  87834. }
  87835. FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id)
  87836. {
  87837. size_t i;
  87838. FLAC__ASSERT(0 != decoder);
  87839. FLAC__ASSERT(0 != decoder->private_);
  87840. for(i = 0; i < decoder->private_->metadata_filter_ids_count; i++)
  87841. if(0 == memcmp(decoder->private_->metadata_filter_ids + i * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8)))
  87842. return true;
  87843. return false;
  87844. }
  87845. FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder)
  87846. {
  87847. FLAC__uint32 x;
  87848. unsigned i, id_;
  87849. FLAC__bool first = true;
  87850. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87851. for(i = id_ = 0; i < 4; ) {
  87852. if(decoder->private_->cached) {
  87853. x = (FLAC__uint32)decoder->private_->lookahead;
  87854. decoder->private_->cached = false;
  87855. }
  87856. else {
  87857. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  87858. return false; /* read_callback_ sets the state for us */
  87859. }
  87860. if(x == FLAC__STREAM_SYNC_STRING[i]) {
  87861. first = true;
  87862. i++;
  87863. id_ = 0;
  87864. continue;
  87865. }
  87866. if(x == ID3V2_TAG_[id_]) {
  87867. id_++;
  87868. i = 0;
  87869. if(id_ == 3) {
  87870. if(!skip_id3v2_tag_(decoder))
  87871. return false; /* skip_id3v2_tag_ sets the state for us */
  87872. }
  87873. continue;
  87874. }
  87875. id_ = 0;
  87876. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  87877. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  87878. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  87879. return false; /* read_callback_ sets the state for us */
  87880. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  87881. decoder->private_->lookahead = (FLAC__byte)x;
  87882. decoder->private_->cached = true;
  87883. }
  87884. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  87885. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  87886. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  87887. return true;
  87888. }
  87889. }
  87890. i = 0;
  87891. if(first) {
  87892. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  87893. first = false;
  87894. }
  87895. }
  87896. decoder->protected_->state = FLAC__STREAM_DECODER_READ_METADATA;
  87897. return true;
  87898. }
  87899. FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder)
  87900. {
  87901. FLAC__bool is_last;
  87902. FLAC__uint32 i, x, type, length;
  87903. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87904. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_IS_LAST_LEN))
  87905. return false; /* read_callback_ sets the state for us */
  87906. is_last = x? true : false;
  87907. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &type, FLAC__STREAM_METADATA_TYPE_LEN))
  87908. return false; /* read_callback_ sets the state for us */
  87909. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &length, FLAC__STREAM_METADATA_LENGTH_LEN))
  87910. return false; /* read_callback_ sets the state for us */
  87911. if(type == FLAC__METADATA_TYPE_STREAMINFO) {
  87912. if(!read_metadata_streaminfo_(decoder, is_last, length))
  87913. return false;
  87914. decoder->private_->has_stream_info = true;
  87915. 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))
  87916. decoder->private_->do_md5_checking = false;
  87917. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] && decoder->private_->metadata_callback)
  87918. decoder->private_->metadata_callback(decoder, &decoder->private_->stream_info, decoder->private_->client_data);
  87919. }
  87920. else if(type == FLAC__METADATA_TYPE_SEEKTABLE) {
  87921. if(!read_metadata_seektable_(decoder, is_last, length))
  87922. return false;
  87923. decoder->private_->has_seek_table = true;
  87924. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_SEEKTABLE] && decoder->private_->metadata_callback)
  87925. decoder->private_->metadata_callback(decoder, &decoder->private_->seek_table, decoder->private_->client_data);
  87926. }
  87927. else {
  87928. FLAC__bool skip_it = !decoder->private_->metadata_filter[type];
  87929. unsigned real_length = length;
  87930. FLAC__StreamMetadata block;
  87931. block.is_last = is_last;
  87932. block.type = (FLAC__MetadataType)type;
  87933. block.length = length;
  87934. if(type == FLAC__METADATA_TYPE_APPLICATION) {
  87935. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8))
  87936. return false; /* read_callback_ sets the state for us */
  87937. if(real_length < FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) { /* underflow check */
  87938. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;/*@@@@@@ maybe wrong error? need to resync?*/
  87939. return false;
  87940. }
  87941. real_length -= FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8;
  87942. if(decoder->private_->metadata_filter_ids_count > 0 && has_id_filtered_(decoder, block.data.application.id))
  87943. skip_it = !skip_it;
  87944. }
  87945. if(skip_it) {
  87946. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  87947. return false; /* read_callback_ sets the state for us */
  87948. }
  87949. else {
  87950. switch(type) {
  87951. case FLAC__METADATA_TYPE_PADDING:
  87952. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  87953. return false; /* read_callback_ sets the state for us */
  87954. break;
  87955. case FLAC__METADATA_TYPE_APPLICATION:
  87956. if(real_length > 0) {
  87957. if(0 == (block.data.application.data = (FLAC__byte*)malloc(real_length))) {
  87958. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87959. return false;
  87960. }
  87961. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.data, real_length))
  87962. return false; /* read_callback_ sets the state for us */
  87963. }
  87964. else
  87965. block.data.application.data = 0;
  87966. break;
  87967. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  87968. if(!read_metadata_vorbiscomment_(decoder, &block.data.vorbis_comment))
  87969. return false;
  87970. break;
  87971. case FLAC__METADATA_TYPE_CUESHEET:
  87972. if(!read_metadata_cuesheet_(decoder, &block.data.cue_sheet))
  87973. return false;
  87974. break;
  87975. case FLAC__METADATA_TYPE_PICTURE:
  87976. if(!read_metadata_picture_(decoder, &block.data.picture))
  87977. return false;
  87978. break;
  87979. case FLAC__METADATA_TYPE_STREAMINFO:
  87980. case FLAC__METADATA_TYPE_SEEKTABLE:
  87981. FLAC__ASSERT(0);
  87982. break;
  87983. default:
  87984. if(real_length > 0) {
  87985. if(0 == (block.data.unknown.data = (FLAC__byte*)malloc(real_length))) {
  87986. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87987. return false;
  87988. }
  87989. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.unknown.data, real_length))
  87990. return false; /* read_callback_ sets the state for us */
  87991. }
  87992. else
  87993. block.data.unknown.data = 0;
  87994. break;
  87995. }
  87996. if(!decoder->private_->is_seeking && decoder->private_->metadata_callback)
  87997. decoder->private_->metadata_callback(decoder, &block, decoder->private_->client_data);
  87998. switch(type) {
  87999. case FLAC__METADATA_TYPE_PADDING:
  88000. break;
  88001. case FLAC__METADATA_TYPE_APPLICATION:
  88002. if(0 != block.data.application.data)
  88003. free(block.data.application.data);
  88004. break;
  88005. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  88006. if(0 != block.data.vorbis_comment.vendor_string.entry)
  88007. free(block.data.vorbis_comment.vendor_string.entry);
  88008. if(block.data.vorbis_comment.num_comments > 0)
  88009. for(i = 0; i < block.data.vorbis_comment.num_comments; i++)
  88010. if(0 != block.data.vorbis_comment.comments[i].entry)
  88011. free(block.data.vorbis_comment.comments[i].entry);
  88012. if(0 != block.data.vorbis_comment.comments)
  88013. free(block.data.vorbis_comment.comments);
  88014. break;
  88015. case FLAC__METADATA_TYPE_CUESHEET:
  88016. if(block.data.cue_sheet.num_tracks > 0)
  88017. for(i = 0; i < block.data.cue_sheet.num_tracks; i++)
  88018. if(0 != block.data.cue_sheet.tracks[i].indices)
  88019. free(block.data.cue_sheet.tracks[i].indices);
  88020. if(0 != block.data.cue_sheet.tracks)
  88021. free(block.data.cue_sheet.tracks);
  88022. break;
  88023. case FLAC__METADATA_TYPE_PICTURE:
  88024. if(0 != block.data.picture.mime_type)
  88025. free(block.data.picture.mime_type);
  88026. if(0 != block.data.picture.description)
  88027. free(block.data.picture.description);
  88028. if(0 != block.data.picture.data)
  88029. free(block.data.picture.data);
  88030. break;
  88031. case FLAC__METADATA_TYPE_STREAMINFO:
  88032. case FLAC__METADATA_TYPE_SEEKTABLE:
  88033. FLAC__ASSERT(0);
  88034. default:
  88035. if(0 != block.data.unknown.data)
  88036. free(block.data.unknown.data);
  88037. break;
  88038. }
  88039. }
  88040. }
  88041. if(is_last) {
  88042. if(!FLAC__stream_decoder_get_decode_position(decoder, &decoder->private_->first_frame_offset))
  88043. decoder->private_->first_frame_offset = 0;
  88044. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88045. }
  88046. return true;
  88047. }
  88048. FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88049. {
  88050. FLAC__uint32 x;
  88051. unsigned bits, used_bits = 0;
  88052. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88053. decoder->private_->stream_info.type = FLAC__METADATA_TYPE_STREAMINFO;
  88054. decoder->private_->stream_info.is_last = is_last;
  88055. decoder->private_->stream_info.length = length;
  88056. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN;
  88057. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, bits))
  88058. return false; /* read_callback_ sets the state for us */
  88059. decoder->private_->stream_info.data.stream_info.min_blocksize = x;
  88060. used_bits += bits;
  88061. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN;
  88062. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  88063. return false; /* read_callback_ sets the state for us */
  88064. decoder->private_->stream_info.data.stream_info.max_blocksize = x;
  88065. used_bits += bits;
  88066. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN;
  88067. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  88068. return false; /* read_callback_ sets the state for us */
  88069. decoder->private_->stream_info.data.stream_info.min_framesize = x;
  88070. used_bits += bits;
  88071. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN;
  88072. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  88073. return false; /* read_callback_ sets the state for us */
  88074. decoder->private_->stream_info.data.stream_info.max_framesize = x;
  88075. used_bits += bits;
  88076. bits = FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN;
  88077. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  88078. return false; /* read_callback_ sets the state for us */
  88079. decoder->private_->stream_info.data.stream_info.sample_rate = x;
  88080. used_bits += bits;
  88081. bits = FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN;
  88082. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  88083. return false; /* read_callback_ sets the state for us */
  88084. decoder->private_->stream_info.data.stream_info.channels = x+1;
  88085. used_bits += bits;
  88086. bits = FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN;
  88087. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  88088. return false; /* read_callback_ sets the state for us */
  88089. decoder->private_->stream_info.data.stream_info.bits_per_sample = x+1;
  88090. used_bits += bits;
  88091. bits = FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN;
  88092. 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))
  88093. return false; /* read_callback_ sets the state for us */
  88094. used_bits += bits;
  88095. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, decoder->private_->stream_info.data.stream_info.md5sum, 16))
  88096. return false; /* read_callback_ sets the state for us */
  88097. used_bits += 16*8;
  88098. FLAC__ASSERT(used_bits % 8 == 0);
  88099. length -= (used_bits / 8);
  88100. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88101. return false; /* read_callback_ sets the state for us */
  88102. return true;
  88103. }
  88104. FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88105. {
  88106. FLAC__uint32 i, x;
  88107. FLAC__uint64 xx;
  88108. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88109. decoder->private_->seek_table.type = FLAC__METADATA_TYPE_SEEKTABLE;
  88110. decoder->private_->seek_table.is_last = is_last;
  88111. decoder->private_->seek_table.length = length;
  88112. decoder->private_->seek_table.data.seek_table.num_points = length / FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
  88113. 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)))) {
  88114. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88115. return false;
  88116. }
  88117. for(i = 0; i < decoder->private_->seek_table.data.seek_table.num_points; i++) {
  88118. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  88119. return false; /* read_callback_ sets the state for us */
  88120. decoder->private_->seek_table.data.seek_table.points[i].sample_number = xx;
  88121. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  88122. return false; /* read_callback_ sets the state for us */
  88123. decoder->private_->seek_table.data.seek_table.points[i].stream_offset = xx;
  88124. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  88125. return false; /* read_callback_ sets the state for us */
  88126. decoder->private_->seek_table.data.seek_table.points[i].frame_samples = x;
  88127. }
  88128. length -= (decoder->private_->seek_table.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH);
  88129. if(length > 0) {
  88130. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88131. return false; /* read_callback_ sets the state for us */
  88132. }
  88133. return true;
  88134. }
  88135. FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj)
  88136. {
  88137. FLAC__uint32 i;
  88138. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88139. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88140. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->vendor_string.length))
  88141. return false; /* read_callback_ sets the state for us */
  88142. if(obj->vendor_string.length > 0) {
  88143. if(0 == (obj->vendor_string.entry = (FLAC__byte*)safe_malloc_add_2op_(obj->vendor_string.length, /*+*/1))) {
  88144. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88145. return false;
  88146. }
  88147. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->vendor_string.entry, obj->vendor_string.length))
  88148. return false; /* read_callback_ sets the state for us */
  88149. obj->vendor_string.entry[obj->vendor_string.length] = '\0';
  88150. }
  88151. else
  88152. obj->vendor_string.entry = 0;
  88153. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN == 32);
  88154. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->num_comments))
  88155. return false; /* read_callback_ sets the state for us */
  88156. if(obj->num_comments > 0) {
  88157. if(0 == (obj->comments = (FLAC__StreamMetadata_VorbisComment_Entry*)safe_malloc_mul_2op_(obj->num_comments, /*times*/sizeof(FLAC__StreamMetadata_VorbisComment_Entry)))) {
  88158. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88159. return false;
  88160. }
  88161. for(i = 0; i < obj->num_comments; i++) {
  88162. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88163. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->comments[i].length))
  88164. return false; /* read_callback_ sets the state for us */
  88165. if(obj->comments[i].length > 0) {
  88166. if(0 == (obj->comments[i].entry = (FLAC__byte*)safe_malloc_add_2op_(obj->comments[i].length, /*+*/1))) {
  88167. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88168. return false;
  88169. }
  88170. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->comments[i].entry, obj->comments[i].length))
  88171. return false; /* read_callback_ sets the state for us */
  88172. obj->comments[i].entry[obj->comments[i].length] = '\0';
  88173. }
  88174. else
  88175. obj->comments[i].entry = 0;
  88176. }
  88177. }
  88178. else {
  88179. obj->comments = 0;
  88180. }
  88181. return true;
  88182. }
  88183. FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj)
  88184. {
  88185. FLAC__uint32 i, j, x;
  88186. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88187. memset(obj, 0, sizeof(FLAC__StreamMetadata_CueSheet));
  88188. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  88189. 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))
  88190. return false; /* read_callback_ sets the state for us */
  88191. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &obj->lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  88192. return false; /* read_callback_ sets the state for us */
  88193. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  88194. return false; /* read_callback_ sets the state for us */
  88195. obj->is_cd = x? true : false;
  88196. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  88197. return false; /* read_callback_ sets the state for us */
  88198. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  88199. return false; /* read_callback_ sets the state for us */
  88200. obj->num_tracks = x;
  88201. if(obj->num_tracks > 0) {
  88202. if(0 == (obj->tracks = (FLAC__StreamMetadata_CueSheet_Track*)safe_calloc_(obj->num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)))) {
  88203. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88204. return false;
  88205. }
  88206. for(i = 0; i < obj->num_tracks; i++) {
  88207. FLAC__StreamMetadata_CueSheet_Track *track = &obj->tracks[i];
  88208. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  88209. return false; /* read_callback_ sets the state for us */
  88210. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  88211. return false; /* read_callback_ sets the state for us */
  88212. track->number = (FLAC__byte)x;
  88213. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  88214. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  88215. return false; /* read_callback_ sets the state for us */
  88216. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  88217. return false; /* read_callback_ sets the state for us */
  88218. track->type = x;
  88219. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  88220. return false; /* read_callback_ sets the state for us */
  88221. track->pre_emphasis = x;
  88222. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  88223. return false; /* read_callback_ sets the state for us */
  88224. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  88225. return false; /* read_callback_ sets the state for us */
  88226. track->num_indices = (FLAC__byte)x;
  88227. if(track->num_indices > 0) {
  88228. if(0 == (track->indices = (FLAC__StreamMetadata_CueSheet_Index*)safe_calloc_(track->num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)))) {
  88229. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88230. return false;
  88231. }
  88232. for(j = 0; j < track->num_indices; j++) {
  88233. FLAC__StreamMetadata_CueSheet_Index *index = &track->indices[j];
  88234. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  88235. return false; /* read_callback_ sets the state for us */
  88236. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  88237. return false; /* read_callback_ sets the state for us */
  88238. index->number = (FLAC__byte)x;
  88239. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  88240. return false; /* read_callback_ sets the state for us */
  88241. }
  88242. }
  88243. }
  88244. }
  88245. return true;
  88246. }
  88247. FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj)
  88248. {
  88249. FLAC__uint32 x;
  88250. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88251. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  88252. return false; /* read_callback_ sets the state for us */
  88253. obj->type = (FLAC__StreamMetadata_Picture_Type) x;
  88254. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  88255. return false; /* read_callback_ sets the state for us */
  88256. if(0 == (obj->mime_type = (char*)safe_malloc_add_2op_(x, /*+*/1))) {
  88257. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88258. return false;
  88259. }
  88260. if(x > 0) {
  88261. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)obj->mime_type, x))
  88262. return false; /* read_callback_ sets the state for us */
  88263. }
  88264. obj->mime_type[x] = '\0';
  88265. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  88266. return false; /* read_callback_ sets the state for us */
  88267. if(0 == (obj->description = (FLAC__byte*)safe_malloc_add_2op_(x, /*+*/1))) {
  88268. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88269. return false;
  88270. }
  88271. if(x > 0) {
  88272. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->description, x))
  88273. return false; /* read_callback_ sets the state for us */
  88274. }
  88275. obj->description[x] = '\0';
  88276. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  88277. return false; /* read_callback_ sets the state for us */
  88278. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  88279. return false; /* read_callback_ sets the state for us */
  88280. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  88281. return false; /* read_callback_ sets the state for us */
  88282. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  88283. return false; /* read_callback_ sets the state for us */
  88284. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &(obj->data_length), FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  88285. return false; /* read_callback_ sets the state for us */
  88286. if(0 == (obj->data = (FLAC__byte*)safe_malloc_(obj->data_length))) {
  88287. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88288. return false;
  88289. }
  88290. if(obj->data_length > 0) {
  88291. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->data, obj->data_length))
  88292. return false; /* read_callback_ sets the state for us */
  88293. }
  88294. return true;
  88295. }
  88296. FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder)
  88297. {
  88298. FLAC__uint32 x;
  88299. unsigned i, skip;
  88300. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 24))
  88301. return false; /* read_callback_ sets the state for us */
  88302. skip = 0;
  88303. for(i = 0; i < 4; i++) {
  88304. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88305. return false; /* read_callback_ sets the state for us */
  88306. skip <<= 7;
  88307. skip |= (x & 0x7f);
  88308. }
  88309. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, skip))
  88310. return false; /* read_callback_ sets the state for us */
  88311. return true;
  88312. }
  88313. FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder)
  88314. {
  88315. FLAC__uint32 x;
  88316. FLAC__bool first = true;
  88317. if(FLAC__stream_decoder_get_total_samples(decoder) > 0) {
  88318. if(decoder->private_->samples_decoded >= FLAC__stream_decoder_get_total_samples(decoder)) {
  88319. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  88320. return true;
  88321. }
  88322. }
  88323. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  88324. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  88325. return false; /* read_callback_ sets the state for us */
  88326. }
  88327. while(1) {
  88328. if(decoder->private_->cached) {
  88329. x = (FLAC__uint32)decoder->private_->lookahead;
  88330. decoder->private_->cached = false;
  88331. }
  88332. else {
  88333. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88334. return false; /* read_callback_ sets the state for us */
  88335. }
  88336. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88337. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  88338. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88339. return false; /* read_callback_ sets the state for us */
  88340. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88341. decoder->private_->lookahead = (FLAC__byte)x;
  88342. decoder->private_->cached = true;
  88343. }
  88344. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  88345. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  88346. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  88347. return true;
  88348. }
  88349. }
  88350. if(first) {
  88351. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88352. first = false;
  88353. }
  88354. }
  88355. return true;
  88356. }
  88357. FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode)
  88358. {
  88359. unsigned channel;
  88360. unsigned i;
  88361. FLAC__int32 mid, side;
  88362. unsigned frame_crc; /* the one we calculate from the input stream */
  88363. FLAC__uint32 x;
  88364. *got_a_frame = false;
  88365. frame_crc = 0;
  88366. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[0], frame_crc);
  88367. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[1], frame_crc);
  88368. FLAC__bitreader_reset_read_crc16(decoder->private_->input, (FLAC__uint16)frame_crc);
  88369. if(!read_frame_header_(decoder))
  88370. return false;
  88371. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means we didn't sync on a valid header */
  88372. return true;
  88373. if(!allocate_output_(decoder, decoder->private_->frame.header.blocksize, decoder->private_->frame.header.channels))
  88374. return false;
  88375. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88376. unsigned bps = decoder->private_->frame.header.bits_per_sample;
  88377. switch(decoder->private_->frame.header.channel_assignment) {
  88378. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88379. break;
  88380. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88381. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88382. if(channel == 1)
  88383. bps++;
  88384. break;
  88385. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88386. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88387. if(channel == 0)
  88388. bps++;
  88389. break;
  88390. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88391. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88392. if(channel == 1)
  88393. bps++;
  88394. break;
  88395. default:
  88396. FLAC__ASSERT(0);
  88397. }
  88398. if(!read_subframe_(decoder, channel, bps, do_full_decode))
  88399. return false;
  88400. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88401. return true;
  88402. }
  88403. if(!read_zero_padding_(decoder))
  88404. return false;
  88405. 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) */
  88406. return true;
  88407. frame_crc = FLAC__bitreader_get_read_crc16(decoder->private_->input);
  88408. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__FRAME_FOOTER_CRC_LEN))
  88409. return false; /* read_callback_ sets the state for us */
  88410. if(frame_crc == x) {
  88411. if(do_full_decode) {
  88412. switch(decoder->private_->frame.header.channel_assignment) {
  88413. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88414. break;
  88415. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88416. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88417. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88418. decoder->private_->output[1][i] = decoder->private_->output[0][i] - decoder->private_->output[1][i];
  88419. break;
  88420. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88421. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88422. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88423. decoder->private_->output[0][i] += decoder->private_->output[1][i];
  88424. break;
  88425. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88426. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88427. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  88428. #if 1
  88429. mid = decoder->private_->output[0][i];
  88430. side = decoder->private_->output[1][i];
  88431. mid <<= 1;
  88432. mid |= (side & 1); /* i.e. if 'side' is odd... */
  88433. decoder->private_->output[0][i] = (mid + side) >> 1;
  88434. decoder->private_->output[1][i] = (mid - side) >> 1;
  88435. #else
  88436. mid = (decoder->private_->output[0][i] << 1) | (decoder->private_->output[1][i] & 1); /* i.e. if 'side' is odd... */
  88437. decoder->private_->output[0][i] = (mid + decoder->private_->output[1][i]) >> 1;
  88438. decoder->private_->output[1][i] = (mid - decoder->private_->output[1][i]) >> 1;
  88439. #endif
  88440. }
  88441. break;
  88442. default:
  88443. FLAC__ASSERT(0);
  88444. break;
  88445. }
  88446. }
  88447. }
  88448. else {
  88449. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH);
  88450. if(do_full_decode) {
  88451. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88452. memset(decoder->private_->output[channel], 0, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  88453. }
  88454. }
  88455. }
  88456. *got_a_frame = true;
  88457. if(decoder->private_->next_fixed_block_size)
  88458. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size;
  88459. decoder->protected_->channels = decoder->private_->frame.header.channels;
  88460. decoder->protected_->channel_assignment = decoder->private_->frame.header.channel_assignment;
  88461. decoder->protected_->bits_per_sample = decoder->private_->frame.header.bits_per_sample;
  88462. decoder->protected_->sample_rate = decoder->private_->frame.header.sample_rate;
  88463. decoder->protected_->blocksize = decoder->private_->frame.header.blocksize;
  88464. FLAC__ASSERT(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  88465. decoder->private_->samples_decoded = decoder->private_->frame.header.number.sample_number + decoder->private_->frame.header.blocksize;
  88466. if(do_full_decode) {
  88467. if(write_audio_frame_to_client_(decoder, &decoder->private_->frame, (const FLAC__int32 * const *)decoder->private_->output) != FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE)
  88468. return false;
  88469. }
  88470. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88471. return true;
  88472. }
  88473. FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder)
  88474. {
  88475. FLAC__uint32 x;
  88476. FLAC__uint64 xx;
  88477. unsigned i, blocksize_hint = 0, sample_rate_hint = 0;
  88478. FLAC__byte crc8, raw_header[16]; /* MAGIC NUMBER based on the maximum frame header size, including CRC */
  88479. unsigned raw_header_len;
  88480. FLAC__bool is_unparseable = false;
  88481. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88482. raw_header[0] = decoder->private_->header_warmup[0];
  88483. raw_header[1] = decoder->private_->header_warmup[1];
  88484. raw_header_len = 2;
  88485. if(raw_header[1] & 0x02) /* MAGIC NUMBER */
  88486. is_unparseable = true;
  88487. for(i = 0; i < 2; i++) {
  88488. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88489. return false; /* read_callback_ sets the state for us */
  88490. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88491. decoder->private_->lookahead = (FLAC__byte)x;
  88492. decoder->private_->cached = true;
  88493. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88494. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88495. return true;
  88496. }
  88497. raw_header[raw_header_len++] = (FLAC__byte)x;
  88498. }
  88499. switch(x = raw_header[2] >> 4) {
  88500. case 0:
  88501. is_unparseable = true;
  88502. break;
  88503. case 1:
  88504. decoder->private_->frame.header.blocksize = 192;
  88505. break;
  88506. case 2:
  88507. case 3:
  88508. case 4:
  88509. case 5:
  88510. decoder->private_->frame.header.blocksize = 576 << (x-2);
  88511. break;
  88512. case 6:
  88513. case 7:
  88514. blocksize_hint = x;
  88515. break;
  88516. case 8:
  88517. case 9:
  88518. case 10:
  88519. case 11:
  88520. case 12:
  88521. case 13:
  88522. case 14:
  88523. case 15:
  88524. decoder->private_->frame.header.blocksize = 256 << (x-8);
  88525. break;
  88526. default:
  88527. FLAC__ASSERT(0);
  88528. break;
  88529. }
  88530. switch(x = raw_header[2] & 0x0f) {
  88531. case 0:
  88532. if(decoder->private_->has_stream_info)
  88533. decoder->private_->frame.header.sample_rate = decoder->private_->stream_info.data.stream_info.sample_rate;
  88534. else
  88535. is_unparseable = true;
  88536. break;
  88537. case 1:
  88538. decoder->private_->frame.header.sample_rate = 88200;
  88539. break;
  88540. case 2:
  88541. decoder->private_->frame.header.sample_rate = 176400;
  88542. break;
  88543. case 3:
  88544. decoder->private_->frame.header.sample_rate = 192000;
  88545. break;
  88546. case 4:
  88547. decoder->private_->frame.header.sample_rate = 8000;
  88548. break;
  88549. case 5:
  88550. decoder->private_->frame.header.sample_rate = 16000;
  88551. break;
  88552. case 6:
  88553. decoder->private_->frame.header.sample_rate = 22050;
  88554. break;
  88555. case 7:
  88556. decoder->private_->frame.header.sample_rate = 24000;
  88557. break;
  88558. case 8:
  88559. decoder->private_->frame.header.sample_rate = 32000;
  88560. break;
  88561. case 9:
  88562. decoder->private_->frame.header.sample_rate = 44100;
  88563. break;
  88564. case 10:
  88565. decoder->private_->frame.header.sample_rate = 48000;
  88566. break;
  88567. case 11:
  88568. decoder->private_->frame.header.sample_rate = 96000;
  88569. break;
  88570. case 12:
  88571. case 13:
  88572. case 14:
  88573. sample_rate_hint = x;
  88574. break;
  88575. case 15:
  88576. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88577. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88578. return true;
  88579. default:
  88580. FLAC__ASSERT(0);
  88581. }
  88582. x = (unsigned)(raw_header[3] >> 4);
  88583. if(x & 8) {
  88584. decoder->private_->frame.header.channels = 2;
  88585. switch(x & 7) {
  88586. case 0:
  88587. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE;
  88588. break;
  88589. case 1:
  88590. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE;
  88591. break;
  88592. case 2:
  88593. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_MID_SIDE;
  88594. break;
  88595. default:
  88596. is_unparseable = true;
  88597. break;
  88598. }
  88599. }
  88600. else {
  88601. decoder->private_->frame.header.channels = (unsigned)x + 1;
  88602. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  88603. }
  88604. switch(x = (unsigned)(raw_header[3] & 0x0e) >> 1) {
  88605. case 0:
  88606. if(decoder->private_->has_stream_info)
  88607. decoder->private_->frame.header.bits_per_sample = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  88608. else
  88609. is_unparseable = true;
  88610. break;
  88611. case 1:
  88612. decoder->private_->frame.header.bits_per_sample = 8;
  88613. break;
  88614. case 2:
  88615. decoder->private_->frame.header.bits_per_sample = 12;
  88616. break;
  88617. case 4:
  88618. decoder->private_->frame.header.bits_per_sample = 16;
  88619. break;
  88620. case 5:
  88621. decoder->private_->frame.header.bits_per_sample = 20;
  88622. break;
  88623. case 6:
  88624. decoder->private_->frame.header.bits_per_sample = 24;
  88625. break;
  88626. case 3:
  88627. case 7:
  88628. is_unparseable = true;
  88629. break;
  88630. default:
  88631. FLAC__ASSERT(0);
  88632. break;
  88633. }
  88634. if(raw_header[3] & 0x01) /* MAGIC NUMBER */
  88635. is_unparseable = true;
  88636. if(
  88637. raw_header[1] & 0x01 ||
  88638. (decoder->private_->has_stream_info && decoder->private_->stream_info.data.stream_info.min_blocksize != decoder->private_->stream_info.data.stream_info.max_blocksize)
  88639. ) { /* variable blocksize */
  88640. if(!FLAC__bitreader_read_utf8_uint64(decoder->private_->input, &xx, raw_header, &raw_header_len))
  88641. return false; /* read_callback_ sets the state for us */
  88642. if(xx == FLAC__U64L(0xffffffffffffffff)) { /* i.e. non-UTF8 code... */
  88643. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  88644. decoder->private_->cached = true;
  88645. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88646. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88647. return true;
  88648. }
  88649. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  88650. decoder->private_->frame.header.number.sample_number = xx;
  88651. }
  88652. else { /* fixed blocksize */
  88653. if(!FLAC__bitreader_read_utf8_uint32(decoder->private_->input, &x, raw_header, &raw_header_len))
  88654. return false; /* read_callback_ sets the state for us */
  88655. if(x == 0xffffffff) { /* i.e. non-UTF8 code... */
  88656. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  88657. decoder->private_->cached = true;
  88658. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88659. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88660. return true;
  88661. }
  88662. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  88663. decoder->private_->frame.header.number.frame_number = x;
  88664. }
  88665. if(blocksize_hint) {
  88666. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88667. return false; /* read_callback_ sets the state for us */
  88668. raw_header[raw_header_len++] = (FLAC__byte)x;
  88669. if(blocksize_hint == 7) {
  88670. FLAC__uint32 _x;
  88671. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  88672. return false; /* read_callback_ sets the state for us */
  88673. raw_header[raw_header_len++] = (FLAC__byte)_x;
  88674. x = (x << 8) | _x;
  88675. }
  88676. decoder->private_->frame.header.blocksize = x+1;
  88677. }
  88678. if(sample_rate_hint) {
  88679. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88680. return false; /* read_callback_ sets the state for us */
  88681. raw_header[raw_header_len++] = (FLAC__byte)x;
  88682. if(sample_rate_hint != 12) {
  88683. FLAC__uint32 _x;
  88684. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  88685. return false; /* read_callback_ sets the state for us */
  88686. raw_header[raw_header_len++] = (FLAC__byte)_x;
  88687. x = (x << 8) | _x;
  88688. }
  88689. if(sample_rate_hint == 12)
  88690. decoder->private_->frame.header.sample_rate = x*1000;
  88691. else if(sample_rate_hint == 13)
  88692. decoder->private_->frame.header.sample_rate = x;
  88693. else
  88694. decoder->private_->frame.header.sample_rate = x*10;
  88695. }
  88696. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88697. return false; /* read_callback_ sets the state for us */
  88698. crc8 = (FLAC__byte)x;
  88699. if(FLAC__crc8(raw_header, raw_header_len) != crc8) {
  88700. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88701. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88702. return true;
  88703. }
  88704. decoder->private_->next_fixed_block_size = 0;
  88705. if(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  88706. x = decoder->private_->frame.header.number.frame_number;
  88707. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  88708. if(decoder->private_->fixed_block_size)
  88709. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->fixed_block_size * (FLAC__uint64)x;
  88710. else if(decoder->private_->has_stream_info) {
  88711. if(decoder->private_->stream_info.data.stream_info.min_blocksize == decoder->private_->stream_info.data.stream_info.max_blocksize) {
  88712. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->stream_info.data.stream_info.min_blocksize * (FLAC__uint64)x;
  88713. decoder->private_->next_fixed_block_size = decoder->private_->stream_info.data.stream_info.max_blocksize;
  88714. }
  88715. else
  88716. is_unparseable = true;
  88717. }
  88718. else if(x == 0) {
  88719. decoder->private_->frame.header.number.sample_number = 0;
  88720. decoder->private_->next_fixed_block_size = decoder->private_->frame.header.blocksize;
  88721. }
  88722. else {
  88723. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->frame.header.blocksize * (FLAC__uint64)x;
  88724. }
  88725. }
  88726. if(is_unparseable) {
  88727. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88728. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88729. return true;
  88730. }
  88731. return true;
  88732. }
  88733. FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  88734. {
  88735. FLAC__uint32 x;
  88736. FLAC__bool wasted_bits;
  88737. unsigned i;
  88738. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) /* MAGIC NUMBER */
  88739. return false; /* read_callback_ sets the state for us */
  88740. wasted_bits = (x & 1);
  88741. x &= 0xfe;
  88742. if(wasted_bits) {
  88743. unsigned u;
  88744. if(!FLAC__bitreader_read_unary_unsigned(decoder->private_->input, &u))
  88745. return false; /* read_callback_ sets the state for us */
  88746. decoder->private_->frame.subframes[channel].wasted_bits = u+1;
  88747. bps -= decoder->private_->frame.subframes[channel].wasted_bits;
  88748. }
  88749. else
  88750. decoder->private_->frame.subframes[channel].wasted_bits = 0;
  88751. if(x & 0x80) {
  88752. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88753. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88754. return true;
  88755. }
  88756. else if(x == 0) {
  88757. if(!read_subframe_constant_(decoder, channel, bps, do_full_decode))
  88758. return false;
  88759. }
  88760. else if(x == 2) {
  88761. if(!read_subframe_verbatim_(decoder, channel, bps, do_full_decode))
  88762. return false;
  88763. }
  88764. else if(x < 16) {
  88765. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88766. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88767. return true;
  88768. }
  88769. else if(x <= 24) {
  88770. if(!read_subframe_fixed_(decoder, channel, bps, (x>>1)&7, do_full_decode))
  88771. return false;
  88772. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88773. return true;
  88774. }
  88775. else if(x < 64) {
  88776. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88777. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88778. return true;
  88779. }
  88780. else {
  88781. if(!read_subframe_lpc_(decoder, channel, bps, ((x>>1)&31)+1, do_full_decode))
  88782. return false;
  88783. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88784. return true;
  88785. }
  88786. if(wasted_bits && do_full_decode) {
  88787. x = decoder->private_->frame.subframes[channel].wasted_bits;
  88788. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88789. decoder->private_->output[channel][i] <<= x;
  88790. }
  88791. return true;
  88792. }
  88793. FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  88794. {
  88795. FLAC__Subframe_Constant *subframe = &decoder->private_->frame.subframes[channel].data.constant;
  88796. FLAC__int32 x;
  88797. unsigned i;
  88798. FLAC__int32 *output = decoder->private_->output[channel];
  88799. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_CONSTANT;
  88800. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  88801. return false; /* read_callback_ sets the state for us */
  88802. subframe->value = x;
  88803. if(do_full_decode) {
  88804. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88805. output[i] = x;
  88806. }
  88807. return true;
  88808. }
  88809. FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  88810. {
  88811. FLAC__Subframe_Fixed *subframe = &decoder->private_->frame.subframes[channel].data.fixed;
  88812. FLAC__int32 i32;
  88813. FLAC__uint32 u32;
  88814. unsigned u;
  88815. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_FIXED;
  88816. subframe->residual = decoder->private_->residual[channel];
  88817. subframe->order = order;
  88818. for(u = 0; u < order; u++) {
  88819. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  88820. return false; /* read_callback_ sets the state for us */
  88821. subframe->warmup[u] = i32;
  88822. }
  88823. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  88824. return false; /* read_callback_ sets the state for us */
  88825. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  88826. switch(subframe->entropy_coding_method.type) {
  88827. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88828. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88829. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  88830. return false; /* read_callback_ sets the state for us */
  88831. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  88832. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  88833. break;
  88834. default:
  88835. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88836. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88837. return true;
  88838. }
  88839. switch(subframe->entropy_coding_method.type) {
  88840. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88841. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88842. 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))
  88843. return false;
  88844. break;
  88845. default:
  88846. FLAC__ASSERT(0);
  88847. }
  88848. if(do_full_decode) {
  88849. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  88850. FLAC__fixed_restore_signal(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, order, decoder->private_->output[channel]+order);
  88851. }
  88852. return true;
  88853. }
  88854. FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  88855. {
  88856. FLAC__Subframe_LPC *subframe = &decoder->private_->frame.subframes[channel].data.lpc;
  88857. FLAC__int32 i32;
  88858. FLAC__uint32 u32;
  88859. unsigned u;
  88860. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_LPC;
  88861. subframe->residual = decoder->private_->residual[channel];
  88862. subframe->order = order;
  88863. for(u = 0; u < order; u++) {
  88864. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  88865. return false; /* read_callback_ sets the state for us */
  88866. subframe->warmup[u] = i32;
  88867. }
  88868. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  88869. return false; /* read_callback_ sets the state for us */
  88870. if(u32 == (1u << FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN) - 1) {
  88871. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88872. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88873. return true;
  88874. }
  88875. subframe->qlp_coeff_precision = u32+1;
  88876. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  88877. return false; /* read_callback_ sets the state for us */
  88878. subframe->quantization_level = i32;
  88879. for(u = 0; u < order; u++) {
  88880. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, subframe->qlp_coeff_precision))
  88881. return false; /* read_callback_ sets the state for us */
  88882. subframe->qlp_coeff[u] = i32;
  88883. }
  88884. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  88885. return false; /* read_callback_ sets the state for us */
  88886. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  88887. switch(subframe->entropy_coding_method.type) {
  88888. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88889. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88890. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  88891. return false; /* read_callback_ sets the state for us */
  88892. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  88893. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  88894. break;
  88895. default:
  88896. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88897. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88898. return true;
  88899. }
  88900. switch(subframe->entropy_coding_method.type) {
  88901. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88902. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88903. 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))
  88904. return false;
  88905. break;
  88906. default:
  88907. FLAC__ASSERT(0);
  88908. }
  88909. if(do_full_decode) {
  88910. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  88911. if(bps + subframe->qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  88912. if(bps <= 16 && subframe->qlp_coeff_precision <= 16) {
  88913. if(order <= 8)
  88914. 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);
  88915. else
  88916. 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);
  88917. }
  88918. else
  88919. 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);
  88920. else
  88921. 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);
  88922. }
  88923. return true;
  88924. }
  88925. FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  88926. {
  88927. FLAC__Subframe_Verbatim *subframe = &decoder->private_->frame.subframes[channel].data.verbatim;
  88928. FLAC__int32 x, *residual = decoder->private_->residual[channel];
  88929. unsigned i;
  88930. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_VERBATIM;
  88931. subframe->data = residual;
  88932. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  88933. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  88934. return false; /* read_callback_ sets the state for us */
  88935. residual[i] = x;
  88936. }
  88937. if(do_full_decode)
  88938. memcpy(decoder->private_->output[channel], subframe->data, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  88939. return true;
  88940. }
  88941. 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)
  88942. {
  88943. FLAC__uint32 rice_parameter;
  88944. int i;
  88945. unsigned partition, sample, u;
  88946. const unsigned partitions = 1u << partition_order;
  88947. const unsigned partition_samples = partition_order > 0? decoder->private_->frame.header.blocksize >> partition_order : decoder->private_->frame.header.blocksize - predictor_order;
  88948. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  88949. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  88950. if(partition_order == 0) {
  88951. if(decoder->private_->frame.header.blocksize < predictor_order) {
  88952. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88953. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88954. return true;
  88955. }
  88956. }
  88957. else {
  88958. if(partition_samples < predictor_order) {
  88959. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88960. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88961. return true;
  88962. }
  88963. }
  88964. if(!FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order))) {
  88965. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88966. return false;
  88967. }
  88968. sample = 0;
  88969. for(partition = 0; partition < partitions; partition++) {
  88970. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, plen))
  88971. return false; /* read_callback_ sets the state for us */
  88972. partitioned_rice_contents->parameters[partition] = rice_parameter;
  88973. if(rice_parameter < pesc) {
  88974. partitioned_rice_contents->raw_bits[partition] = 0;
  88975. u = (partition_order == 0 || partition > 0)? partition_samples : partition_samples - predictor_order;
  88976. if(!decoder->private_->local_bitreader_read_rice_signed_block(decoder->private_->input, (int*) residual + sample, u, rice_parameter))
  88977. return false; /* read_callback_ sets the state for us */
  88978. sample += u;
  88979. }
  88980. else {
  88981. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  88982. return false; /* read_callback_ sets the state for us */
  88983. partitioned_rice_contents->raw_bits[partition] = rice_parameter;
  88984. for(u = (partition_order == 0 || partition > 0)? 0 : predictor_order; u < partition_samples; u++, sample++) {
  88985. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, (FLAC__int32*) &i, rice_parameter))
  88986. return false; /* read_callback_ sets the state for us */
  88987. residual[sample] = i;
  88988. }
  88989. }
  88990. }
  88991. return true;
  88992. }
  88993. FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder)
  88994. {
  88995. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  88996. FLAC__uint32 zero = 0;
  88997. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &zero, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  88998. return false; /* read_callback_ sets the state for us */
  88999. if(zero != 0) {
  89000. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89001. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89002. }
  89003. }
  89004. return true;
  89005. }
  89006. FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data)
  89007. {
  89008. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder *)client_data;
  89009. if(
  89010. #if FLAC__HAS_OGG
  89011. !decoder->private_->is_ogg &&
  89012. #endif
  89013. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  89014. ) {
  89015. *bytes = 0;
  89016. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89017. return false;
  89018. }
  89019. else if(*bytes > 0) {
  89020. if(decoder->private_->is_seeking && decoder->private_->unparseable_frame_count > 20) {
  89021. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89022. return false;
  89023. }
  89024. else {
  89025. const FLAC__StreamDecoderReadStatus status =
  89026. #if FLAC__HAS_OGG
  89027. decoder->private_->is_ogg?
  89028. read_callback_ogg_aspect_(decoder, buffer, bytes) :
  89029. #endif
  89030. decoder->private_->read_callback(decoder, buffer, bytes, decoder->private_->client_data)
  89031. ;
  89032. if(status == FLAC__STREAM_DECODER_READ_STATUS_ABORT) {
  89033. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89034. return false;
  89035. }
  89036. else if(*bytes == 0) {
  89037. if(
  89038. status == FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM ||
  89039. (
  89040. #if FLAC__HAS_OGG
  89041. !decoder->private_->is_ogg &&
  89042. #endif
  89043. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  89044. )
  89045. ) {
  89046. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89047. return false;
  89048. }
  89049. else
  89050. return true;
  89051. }
  89052. else
  89053. return true;
  89054. }
  89055. }
  89056. else {
  89057. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89058. return false;
  89059. }
  89060. }
  89061. #if FLAC__HAS_OGG
  89062. FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes)
  89063. {
  89064. switch(FLAC__ogg_decoder_aspect_read_callback_wrapper(&decoder->protected_->ogg_decoder_aspect, buffer, bytes, read_callback_proxy_, decoder, decoder->private_->client_data)) {
  89065. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK:
  89066. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89067. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC:
  89068. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89069. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM:
  89070. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89071. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC:
  89072. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION:
  89073. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT:
  89074. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR:
  89075. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR:
  89076. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89077. default:
  89078. FLAC__ASSERT(0);
  89079. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89080. }
  89081. }
  89082. FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89083. {
  89084. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder*)void_decoder;
  89085. switch(decoder->private_->read_callback(decoder, buffer, bytes, client_data)) {
  89086. case FLAC__STREAM_DECODER_READ_STATUS_CONTINUE:
  89087. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK;
  89088. case FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
  89089. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM;
  89090. case FLAC__STREAM_DECODER_READ_STATUS_ABORT:
  89091. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89092. default:
  89093. FLAC__ASSERT(0);
  89094. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89095. }
  89096. }
  89097. #endif
  89098. FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[])
  89099. {
  89100. if(decoder->private_->is_seeking) {
  89101. FLAC__uint64 this_frame_sample = frame->header.number.sample_number;
  89102. FLAC__uint64 next_frame_sample = this_frame_sample + (FLAC__uint64)frame->header.blocksize;
  89103. FLAC__uint64 target_sample = decoder->private_->target_sample;
  89104. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89105. #if FLAC__HAS_OGG
  89106. decoder->private_->got_a_frame = true;
  89107. #endif
  89108. decoder->private_->last_frame = *frame; /* save the frame */
  89109. if(this_frame_sample <= target_sample && target_sample < next_frame_sample) { /* we hit our target frame */
  89110. unsigned delta = (unsigned)(target_sample - this_frame_sample);
  89111. decoder->private_->is_seeking = false;
  89112. if(delta > 0) {
  89113. unsigned channel;
  89114. const FLAC__int32 *newbuffer[FLAC__MAX_CHANNELS];
  89115. for(channel = 0; channel < frame->header.channels; channel++)
  89116. newbuffer[channel] = buffer[channel] + delta;
  89117. decoder->private_->last_frame.header.blocksize -= delta;
  89118. decoder->private_->last_frame.header.number.sample_number += (FLAC__uint64)delta;
  89119. return decoder->private_->write_callback(decoder, &decoder->private_->last_frame, newbuffer, decoder->private_->client_data);
  89120. }
  89121. else {
  89122. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89123. }
  89124. }
  89125. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  89126. }
  89127. if(!decoder->private_->has_stream_info)
  89128. decoder->private_->do_md5_checking = false;
  89129. if(decoder->private_->do_md5_checking) {
  89130. if(!FLAC__MD5Accumulate(&decoder->private_->md5context, buffer, frame->header.channels, frame->header.blocksize, (frame->header.bits_per_sample+7) / 8))
  89131. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  89132. }
  89133. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89134. }
  89135. void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status)
  89136. {
  89137. if(!decoder->private_->is_seeking)
  89138. decoder->private_->error_callback(decoder, status, decoder->private_->client_data);
  89139. else if(status == FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM)
  89140. decoder->private_->unparseable_frame_count++;
  89141. }
  89142. FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89143. {
  89144. FLAC__uint64 first_frame_offset = decoder->private_->first_frame_offset, lower_bound, upper_bound, lower_bound_sample, upper_bound_sample, this_frame_sample;
  89145. FLAC__int64 pos = -1;
  89146. int i;
  89147. unsigned approx_bytes_per_frame;
  89148. FLAC__bool first_seek = true;
  89149. const FLAC__uint64 total_samples = FLAC__stream_decoder_get_total_samples(decoder);
  89150. const unsigned min_blocksize = decoder->private_->stream_info.data.stream_info.min_blocksize;
  89151. const unsigned max_blocksize = decoder->private_->stream_info.data.stream_info.max_blocksize;
  89152. const unsigned max_framesize = decoder->private_->stream_info.data.stream_info.max_framesize;
  89153. const unsigned min_framesize = decoder->private_->stream_info.data.stream_info.min_framesize;
  89154. unsigned channels = FLAC__stream_decoder_get_channels(decoder);
  89155. unsigned bps = FLAC__stream_decoder_get_bits_per_sample(decoder);
  89156. const FLAC__StreamMetadata_SeekTable *seek_table = decoder->private_->has_seek_table? &decoder->private_->seek_table.data.seek_table : 0;
  89157. if(channels == 0)
  89158. channels = decoder->private_->stream_info.data.stream_info.channels;
  89159. if(bps == 0)
  89160. bps = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  89161. if(max_framesize > 0)
  89162. approx_bytes_per_frame = (max_framesize + min_framesize) / 2 + 1;
  89163. else if(min_blocksize == max_blocksize && min_blocksize > 0) {
  89164. approx_bytes_per_frame = min_blocksize * channels * bps/8 + 64;
  89165. }
  89166. else
  89167. approx_bytes_per_frame = 4096 * channels * bps/8 + 64;
  89168. lower_bound = first_frame_offset;
  89169. lower_bound_sample = 0;
  89170. upper_bound = stream_length;
  89171. upper_bound_sample = total_samples > 0 ? total_samples : target_sample /*estimate it*/;
  89172. if(seek_table) {
  89173. FLAC__uint64 new_lower_bound = lower_bound;
  89174. FLAC__uint64 new_upper_bound = upper_bound;
  89175. FLAC__uint64 new_lower_bound_sample = lower_bound_sample;
  89176. FLAC__uint64 new_upper_bound_sample = upper_bound_sample;
  89177. for(i = (int)seek_table->num_points - 1; i >= 0; i--) {
  89178. if(
  89179. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89180. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89181. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89182. seek_table->points[i].sample_number <= target_sample
  89183. )
  89184. break;
  89185. }
  89186. if(i >= 0) { /* i.e. we found a suitable seek point... */
  89187. new_lower_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89188. new_lower_bound_sample = seek_table->points[i].sample_number;
  89189. }
  89190. for(i = 0; i < (int)seek_table->num_points; i++) {
  89191. if(
  89192. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89193. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89194. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89195. seek_table->points[i].sample_number > target_sample
  89196. )
  89197. break;
  89198. }
  89199. if(i < (int)seek_table->num_points) { /* i.e. we found a suitable seek point... */
  89200. new_upper_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89201. new_upper_bound_sample = seek_table->points[i].sample_number;
  89202. }
  89203. if(new_upper_bound >= new_lower_bound) {
  89204. lower_bound = new_lower_bound;
  89205. upper_bound = new_upper_bound;
  89206. lower_bound_sample = new_lower_bound_sample;
  89207. upper_bound_sample = new_upper_bound_sample;
  89208. }
  89209. }
  89210. FLAC__ASSERT(upper_bound_sample >= lower_bound_sample);
  89211. if(upper_bound_sample == lower_bound_sample)
  89212. upper_bound_sample++;
  89213. decoder->private_->target_sample = target_sample;
  89214. while(1) {
  89215. if (lower_bound_sample >= upper_bound_sample || lower_bound > upper_bound) {
  89216. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89217. return false;
  89218. }
  89219. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89220. #if defined _MSC_VER || defined __MINGW32__
  89221. 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;
  89222. #else
  89223. 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;
  89224. #endif
  89225. #else
  89226. if(upper_bound - lower_bound < 0xffffffff)
  89227. 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;
  89228. else /* @@@ WATCHOUT, ~2TB limit */
  89229. 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;
  89230. #endif
  89231. if(pos >= (FLAC__int64)upper_bound)
  89232. pos = (FLAC__int64)upper_bound - 1;
  89233. if(pos < (FLAC__int64)lower_bound)
  89234. pos = (FLAC__int64)lower_bound;
  89235. if(decoder->private_->seek_callback(decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89236. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89237. return false;
  89238. }
  89239. if(!FLAC__stream_decoder_flush(decoder)) {
  89240. return false;
  89241. }
  89242. decoder->private_->unparseable_frame_count = 0;
  89243. if(!FLAC__stream_decoder_process_single(decoder)) {
  89244. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89245. return false;
  89246. }
  89247. #if 0
  89248. if(decoder->protected_->state != FLAC__SEEKABLE_STREAM_DECODER_SEEKING && decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM)
  89249. break;
  89250. #endif
  89251. if(!decoder->private_->is_seeking)
  89252. break;
  89253. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89254. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89255. if (0 == decoder->private_->samples_decoded || (this_frame_sample + decoder->private_->last_frame.header.blocksize >= upper_bound_sample && !first_seek)) {
  89256. if (pos == (FLAC__int64)lower_bound) {
  89257. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89258. return false;
  89259. }
  89260. approx_bytes_per_frame = approx_bytes_per_frame? approx_bytes_per_frame * 2 : 16;
  89261. continue;
  89262. }
  89263. first_seek = false;
  89264. if (this_frame_sample < lower_bound_sample) {
  89265. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89266. return false;
  89267. }
  89268. if(target_sample < this_frame_sample) {
  89269. upper_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89270. if(!FLAC__stream_decoder_get_decode_position(decoder, &upper_bound)) {
  89271. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89272. return false;
  89273. }
  89274. approx_bytes_per_frame = (unsigned)(2 * (upper_bound - pos) / 3 + 16);
  89275. }
  89276. else { /* target_sample >= this_frame_sample + this frame's blocksize */
  89277. lower_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89278. if(!FLAC__stream_decoder_get_decode_position(decoder, &lower_bound)) {
  89279. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89280. return false;
  89281. }
  89282. approx_bytes_per_frame = (unsigned)(2 * (lower_bound - pos) / 3 + 16);
  89283. }
  89284. }
  89285. return true;
  89286. }
  89287. #if FLAC__HAS_OGG
  89288. FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89289. {
  89290. FLAC__uint64 left_pos = 0, right_pos = stream_length;
  89291. FLAC__uint64 left_sample = 0, right_sample = FLAC__stream_decoder_get_total_samples(decoder);
  89292. FLAC__uint64 this_frame_sample = (FLAC__uint64)0 - 1;
  89293. FLAC__uint64 pos = 0; /* only initialized to avoid compiler warning */
  89294. FLAC__bool did_a_seek;
  89295. unsigned iteration = 0;
  89296. unsigned BINARY_SEARCH_AFTER_ITERATION = 2;
  89297. static const FLAC__uint64 LINEAR_SEARCH_WITHIN_SAMPLES = FLAC__MAX_BLOCK_SIZE * 2;
  89298. if(right_sample == 0) {
  89299. right_sample = (FLAC__uint64)(-1);
  89300. BINARY_SEARCH_AFTER_ITERATION = 0;
  89301. }
  89302. decoder->private_->target_sample = target_sample;
  89303. for( ; ; iteration++) {
  89304. if (iteration == 0 || this_frame_sample > target_sample || target_sample - this_frame_sample > LINEAR_SEARCH_WITHIN_SAMPLES) {
  89305. if (iteration >= BINARY_SEARCH_AFTER_ITERATION) {
  89306. pos = (right_pos + left_pos) / 2;
  89307. }
  89308. else {
  89309. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89310. #if defined _MSC_VER || defined __MINGW32__
  89311. 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));
  89312. #else
  89313. pos = (FLAC__uint64)((FLAC__double)(target_sample - left_sample) / (FLAC__double)(right_sample - left_sample) * (FLAC__double)(right_pos - left_pos));
  89314. #endif
  89315. #else
  89316. if ((target_sample-left_sample <= 0xffffffff) && (right_pos-left_pos <= 0xffffffff))
  89317. pos = (FLAC__int64)(((target_sample-left_sample) * (right_pos-left_pos)) / (right_sample-left_sample));
  89318. else /* @@@ WATCHOUT, ~2TB limit */
  89319. pos = (FLAC__int64)((((target_sample-left_sample)>>8) * ((right_pos-left_pos)>>8)) / ((right_sample-left_sample)>>16));
  89320. #endif
  89321. }
  89322. if(decoder->private_->seek_callback((FLAC__StreamDecoder*)decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89323. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89324. return false;
  89325. }
  89326. if(!FLAC__stream_decoder_flush(decoder)) {
  89327. return false;
  89328. }
  89329. did_a_seek = true;
  89330. }
  89331. else
  89332. did_a_seek = false;
  89333. decoder->private_->got_a_frame = false;
  89334. if(!FLAC__stream_decoder_process_single(decoder)) {
  89335. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89336. return false;
  89337. }
  89338. if(!decoder->private_->got_a_frame) {
  89339. if(did_a_seek) {
  89340. right_pos = pos;
  89341. BINARY_SEARCH_AFTER_ITERATION = 0;
  89342. }
  89343. else {
  89344. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89345. return false;
  89346. }
  89347. }
  89348. else if(!decoder->private_->is_seeking) {
  89349. break;
  89350. }
  89351. else {
  89352. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89353. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89354. if (did_a_seek) {
  89355. if (this_frame_sample <= target_sample) {
  89356. FLAC__ASSERT(this_frame_sample != target_sample);
  89357. left_sample = this_frame_sample;
  89358. if (left_pos == pos) {
  89359. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89360. return false;
  89361. }
  89362. left_pos = pos;
  89363. }
  89364. else if(this_frame_sample > target_sample) {
  89365. right_sample = this_frame_sample;
  89366. if (right_pos == pos) {
  89367. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89368. return false;
  89369. }
  89370. right_pos = pos;
  89371. }
  89372. }
  89373. }
  89374. }
  89375. return true;
  89376. }
  89377. #endif
  89378. FLAC__StreamDecoderReadStatus file_read_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89379. {
  89380. (void)client_data;
  89381. if(*bytes > 0) {
  89382. *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, decoder->private_->file);
  89383. if(ferror(decoder->private_->file))
  89384. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89385. else if(*bytes == 0)
  89386. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89387. else
  89388. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89389. }
  89390. else
  89391. return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
  89392. }
  89393. FLAC__StreamDecoderSeekStatus file_seek_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  89394. {
  89395. (void)client_data;
  89396. if(decoder->private_->file == stdin)
  89397. return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
  89398. else if(fseeko(decoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  89399. return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
  89400. else
  89401. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  89402. }
  89403. FLAC__StreamDecoderTellStatus file_tell_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  89404. {
  89405. off_t pos;
  89406. (void)client_data;
  89407. if(decoder->private_->file == stdin)
  89408. return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED;
  89409. else if((pos = ftello(decoder->private_->file)) < 0)
  89410. return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
  89411. else {
  89412. *absolute_byte_offset = (FLAC__uint64)pos;
  89413. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  89414. }
  89415. }
  89416. FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
  89417. {
  89418. struct stat filestats;
  89419. (void)client_data;
  89420. if(decoder->private_->file == stdin)
  89421. return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
  89422. else if(fstat(fileno(decoder->private_->file), &filestats) != 0)
  89423. return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
  89424. else {
  89425. *stream_length = (FLAC__uint64)filestats.st_size;
  89426. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  89427. }
  89428. }
  89429. FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data)
  89430. {
  89431. (void)client_data;
  89432. return feof(decoder->private_->file)? true : false;
  89433. }
  89434. #endif
  89435. /*** End of inlined file: stream_decoder.c ***/
  89436. /*** Start of inlined file: stream_encoder.c ***/
  89437. /*** Start of inlined file: juce_FlacHeader.h ***/
  89438. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  89439. // tasks..
  89440. #define VERSION "1.2.1"
  89441. #define FLAC__NO_DLL 1
  89442. #if JUCE_MSVC
  89443. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  89444. #endif
  89445. #if JUCE_MAC
  89446. #define FLAC__SYS_DARWIN 1
  89447. #endif
  89448. /*** End of inlined file: juce_FlacHeader.h ***/
  89449. #if JUCE_USE_FLAC
  89450. #if HAVE_CONFIG_H
  89451. # include <config.h>
  89452. #endif
  89453. #if defined _MSC_VER || defined __MINGW32__
  89454. #include <io.h> /* for _setmode() */
  89455. #include <fcntl.h> /* for _O_BINARY */
  89456. #endif
  89457. #if defined __CYGWIN__ || defined __EMX__
  89458. #include <io.h> /* for setmode(), O_BINARY */
  89459. #include <fcntl.h> /* for _O_BINARY */
  89460. #endif
  89461. #include <limits.h>
  89462. #include <stdio.h>
  89463. #include <stdlib.h> /* for malloc() */
  89464. #include <string.h> /* for memcpy() */
  89465. #include <sys/types.h> /* for off_t */
  89466. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  89467. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  89468. #define fseeko fseek
  89469. #define ftello ftell
  89470. #endif
  89471. #endif
  89472. /*** Start of inlined file: stream_encoder.h ***/
  89473. #ifndef FLAC__PROTECTED__STREAM_ENCODER_H
  89474. #define FLAC__PROTECTED__STREAM_ENCODER_H
  89475. #if FLAC__HAS_OGG
  89476. #include "private/ogg_encoder_aspect.h"
  89477. #endif
  89478. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89479. #define FLAC__MAX_APODIZATION_FUNCTIONS 32
  89480. typedef enum {
  89481. FLAC__APODIZATION_BARTLETT,
  89482. FLAC__APODIZATION_BARTLETT_HANN,
  89483. FLAC__APODIZATION_BLACKMAN,
  89484. FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE,
  89485. FLAC__APODIZATION_CONNES,
  89486. FLAC__APODIZATION_FLATTOP,
  89487. FLAC__APODIZATION_GAUSS,
  89488. FLAC__APODIZATION_HAMMING,
  89489. FLAC__APODIZATION_HANN,
  89490. FLAC__APODIZATION_KAISER_BESSEL,
  89491. FLAC__APODIZATION_NUTTALL,
  89492. FLAC__APODIZATION_RECTANGLE,
  89493. FLAC__APODIZATION_TRIANGLE,
  89494. FLAC__APODIZATION_TUKEY,
  89495. FLAC__APODIZATION_WELCH
  89496. } FLAC__ApodizationFunction;
  89497. typedef struct {
  89498. FLAC__ApodizationFunction type;
  89499. union {
  89500. struct {
  89501. FLAC__real stddev;
  89502. } gauss;
  89503. struct {
  89504. FLAC__real p;
  89505. } tukey;
  89506. } parameters;
  89507. } FLAC__ApodizationSpecification;
  89508. #endif // #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89509. typedef struct FLAC__StreamEncoderProtected {
  89510. FLAC__StreamEncoderState state;
  89511. FLAC__bool verify;
  89512. FLAC__bool streamable_subset;
  89513. FLAC__bool do_md5;
  89514. FLAC__bool do_mid_side_stereo;
  89515. FLAC__bool loose_mid_side_stereo;
  89516. unsigned channels;
  89517. unsigned bits_per_sample;
  89518. unsigned sample_rate;
  89519. unsigned blocksize;
  89520. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89521. unsigned num_apodizations;
  89522. FLAC__ApodizationSpecification apodizations[FLAC__MAX_APODIZATION_FUNCTIONS];
  89523. #endif
  89524. unsigned max_lpc_order;
  89525. unsigned qlp_coeff_precision;
  89526. FLAC__bool do_qlp_coeff_prec_search;
  89527. FLAC__bool do_exhaustive_model_search;
  89528. FLAC__bool do_escape_coding;
  89529. unsigned min_residual_partition_order;
  89530. unsigned max_residual_partition_order;
  89531. unsigned rice_parameter_search_dist;
  89532. FLAC__uint64 total_samples_estimate;
  89533. FLAC__StreamMetadata **metadata;
  89534. unsigned num_metadata_blocks;
  89535. FLAC__uint64 streaminfo_offset, seektable_offset, audio_offset;
  89536. #if FLAC__HAS_OGG
  89537. FLAC__OggEncoderAspect ogg_encoder_aspect;
  89538. #endif
  89539. } FLAC__StreamEncoderProtected;
  89540. #endif
  89541. /*** End of inlined file: stream_encoder.h ***/
  89542. #if FLAC__HAS_OGG
  89543. #include "include/private/ogg_helper.h"
  89544. #include "include/private/ogg_mapping.h"
  89545. #endif
  89546. /*** Start of inlined file: stream_encoder_framing.h ***/
  89547. #ifndef FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  89548. #define FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  89549. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw);
  89550. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw);
  89551. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89552. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89553. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89554. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89555. #endif
  89556. /*** End of inlined file: stream_encoder_framing.h ***/
  89557. /*** Start of inlined file: window.h ***/
  89558. #ifndef FLAC__PRIVATE__WINDOW_H
  89559. #define FLAC__PRIVATE__WINDOW_H
  89560. #ifdef HAVE_CONFIG_H
  89561. #include <config.h>
  89562. #endif
  89563. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89564. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L);
  89565. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L);
  89566. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L);
  89567. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L);
  89568. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L);
  89569. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L);
  89570. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev); /* 0.0 < stddev <= 0.5 */
  89571. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L);
  89572. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L);
  89573. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L);
  89574. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L);
  89575. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L);
  89576. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L);
  89577. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p);
  89578. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L);
  89579. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  89580. #endif
  89581. /*** End of inlined file: window.h ***/
  89582. #ifndef FLaC__INLINE
  89583. #define FLaC__INLINE
  89584. #endif
  89585. #ifdef min
  89586. #undef min
  89587. #endif
  89588. #define min(x,y) ((x)<(y)?(x):(y))
  89589. #ifdef max
  89590. #undef max
  89591. #endif
  89592. #define max(x,y) ((x)>(y)?(x):(y))
  89593. #undef EXACT_RICE_BITS_CALCULATION
  89594. #undef ENABLE_RICE_PARAMETER_SEARCH
  89595. typedef struct {
  89596. FLAC__int32 *data[FLAC__MAX_CHANNELS];
  89597. unsigned size; /* of each data[] in samples */
  89598. unsigned tail;
  89599. } verify_input_fifo;
  89600. typedef struct {
  89601. const FLAC__byte *data;
  89602. unsigned capacity;
  89603. unsigned bytes;
  89604. } verify_output;
  89605. typedef enum {
  89606. ENCODER_IN_MAGIC = 0,
  89607. ENCODER_IN_METADATA = 1,
  89608. ENCODER_IN_AUDIO = 2
  89609. } EncoderStateHint;
  89610. static struct CompressionLevels {
  89611. FLAC__bool do_mid_side_stereo;
  89612. FLAC__bool loose_mid_side_stereo;
  89613. unsigned max_lpc_order;
  89614. unsigned qlp_coeff_precision;
  89615. FLAC__bool do_qlp_coeff_prec_search;
  89616. FLAC__bool do_escape_coding;
  89617. FLAC__bool do_exhaustive_model_search;
  89618. unsigned min_residual_partition_order;
  89619. unsigned max_residual_partition_order;
  89620. unsigned rice_parameter_search_dist;
  89621. } compression_levels_[] = {
  89622. { false, false, 0, 0, false, false, false, 0, 3, 0 },
  89623. { true , true , 0, 0, false, false, false, 0, 3, 0 },
  89624. { true , false, 0, 0, false, false, false, 0, 3, 0 },
  89625. { false, false, 6, 0, false, false, false, 0, 4, 0 },
  89626. { true , true , 8, 0, false, false, false, 0, 4, 0 },
  89627. { true , false, 8, 0, false, false, false, 0, 5, 0 },
  89628. { true , false, 8, 0, false, false, false, 0, 6, 0 },
  89629. { true , false, 8, 0, false, false, true , 0, 6, 0 },
  89630. { true , false, 12, 0, false, false, true , 0, 6, 0 }
  89631. };
  89632. static void set_defaults_enc(FLAC__StreamEncoder *encoder);
  89633. static void free_(FLAC__StreamEncoder *encoder);
  89634. static FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize);
  89635. static FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block);
  89636. static FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block);
  89637. static void update_metadata_(const FLAC__StreamEncoder *encoder);
  89638. #if FLAC__HAS_OGG
  89639. static void update_ogg_metadata_(FLAC__StreamEncoder *encoder);
  89640. #endif
  89641. static FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block);
  89642. static FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block);
  89643. static FLAC__bool process_subframe_(
  89644. FLAC__StreamEncoder *encoder,
  89645. unsigned min_partition_order,
  89646. unsigned max_partition_order,
  89647. const FLAC__FrameHeader *frame_header,
  89648. unsigned subframe_bps,
  89649. const FLAC__int32 integer_signal[],
  89650. FLAC__Subframe *subframe[2],
  89651. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  89652. FLAC__int32 *residual[2],
  89653. unsigned *best_subframe,
  89654. unsigned *best_bits
  89655. );
  89656. static FLAC__bool add_subframe_(
  89657. FLAC__StreamEncoder *encoder,
  89658. unsigned blocksize,
  89659. unsigned subframe_bps,
  89660. const FLAC__Subframe *subframe,
  89661. FLAC__BitWriter *frame
  89662. );
  89663. static unsigned evaluate_constant_subframe_(
  89664. FLAC__StreamEncoder *encoder,
  89665. const FLAC__int32 signal,
  89666. unsigned blocksize,
  89667. unsigned subframe_bps,
  89668. FLAC__Subframe *subframe
  89669. );
  89670. static unsigned evaluate_fixed_subframe_(
  89671. FLAC__StreamEncoder *encoder,
  89672. const FLAC__int32 signal[],
  89673. FLAC__int32 residual[],
  89674. FLAC__uint64 abs_residual_partition_sums[],
  89675. unsigned raw_bits_per_partition[],
  89676. unsigned blocksize,
  89677. unsigned subframe_bps,
  89678. unsigned order,
  89679. unsigned rice_parameter,
  89680. unsigned rice_parameter_limit,
  89681. unsigned min_partition_order,
  89682. unsigned max_partition_order,
  89683. FLAC__bool do_escape_coding,
  89684. unsigned rice_parameter_search_dist,
  89685. FLAC__Subframe *subframe,
  89686. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  89687. );
  89688. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89689. static unsigned evaluate_lpc_subframe_(
  89690. FLAC__StreamEncoder *encoder,
  89691. const FLAC__int32 signal[],
  89692. FLAC__int32 residual[],
  89693. FLAC__uint64 abs_residual_partition_sums[],
  89694. unsigned raw_bits_per_partition[],
  89695. const FLAC__real lp_coeff[],
  89696. unsigned blocksize,
  89697. unsigned subframe_bps,
  89698. unsigned order,
  89699. unsigned qlp_coeff_precision,
  89700. unsigned rice_parameter,
  89701. unsigned rice_parameter_limit,
  89702. unsigned min_partition_order,
  89703. unsigned max_partition_order,
  89704. FLAC__bool do_escape_coding,
  89705. unsigned rice_parameter_search_dist,
  89706. FLAC__Subframe *subframe,
  89707. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  89708. );
  89709. #endif
  89710. static unsigned evaluate_verbatim_subframe_(
  89711. FLAC__StreamEncoder *encoder,
  89712. const FLAC__int32 signal[],
  89713. unsigned blocksize,
  89714. unsigned subframe_bps,
  89715. FLAC__Subframe *subframe
  89716. );
  89717. static unsigned find_best_partition_order_(
  89718. struct FLAC__StreamEncoderPrivate *private_,
  89719. const FLAC__int32 residual[],
  89720. FLAC__uint64 abs_residual_partition_sums[],
  89721. unsigned raw_bits_per_partition[],
  89722. unsigned residual_samples,
  89723. unsigned predictor_order,
  89724. unsigned rice_parameter,
  89725. unsigned rice_parameter_limit,
  89726. unsigned min_partition_order,
  89727. unsigned max_partition_order,
  89728. unsigned bps,
  89729. FLAC__bool do_escape_coding,
  89730. unsigned rice_parameter_search_dist,
  89731. FLAC__EntropyCodingMethod *best_ecm
  89732. );
  89733. static void precompute_partition_info_sums_(
  89734. const FLAC__int32 residual[],
  89735. FLAC__uint64 abs_residual_partition_sums[],
  89736. unsigned residual_samples,
  89737. unsigned predictor_order,
  89738. unsigned min_partition_order,
  89739. unsigned max_partition_order,
  89740. unsigned bps
  89741. );
  89742. static void precompute_partition_info_escapes_(
  89743. const FLAC__int32 residual[],
  89744. unsigned raw_bits_per_partition[],
  89745. unsigned residual_samples,
  89746. unsigned predictor_order,
  89747. unsigned min_partition_order,
  89748. unsigned max_partition_order
  89749. );
  89750. static FLAC__bool set_partitioned_rice_(
  89751. #ifdef EXACT_RICE_BITS_CALCULATION
  89752. const FLAC__int32 residual[],
  89753. #endif
  89754. const FLAC__uint64 abs_residual_partition_sums[],
  89755. const unsigned raw_bits_per_partition[],
  89756. const unsigned residual_samples,
  89757. const unsigned predictor_order,
  89758. const unsigned suggested_rice_parameter,
  89759. const unsigned rice_parameter_limit,
  89760. const unsigned rice_parameter_search_dist,
  89761. const unsigned partition_order,
  89762. const FLAC__bool search_for_escapes,
  89763. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  89764. unsigned *bits
  89765. );
  89766. static unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples);
  89767. static void append_to_verify_fifo_(
  89768. verify_input_fifo *fifo,
  89769. const FLAC__int32 * const input[],
  89770. unsigned input_offset,
  89771. unsigned channels,
  89772. unsigned wide_samples
  89773. );
  89774. static void append_to_verify_fifo_interleaved_(
  89775. verify_input_fifo *fifo,
  89776. const FLAC__int32 input[],
  89777. unsigned input_offset,
  89778. unsigned channels,
  89779. unsigned wide_samples
  89780. );
  89781. static FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  89782. static FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  89783. static void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  89784. static void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  89785. static FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  89786. static FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  89787. static FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  89788. 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);
  89789. static FILE *get_binary_stdout_(void);
  89790. typedef struct FLAC__StreamEncoderPrivate {
  89791. unsigned input_capacity; /* current size (in samples) of the signal and residual buffers */
  89792. FLAC__int32 *integer_signal[FLAC__MAX_CHANNELS]; /* the integer version of the input signal */
  89793. FLAC__int32 *integer_signal_mid_side[2]; /* the integer version of the mid-side input signal (stereo only) */
  89794. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89795. FLAC__real *real_signal[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) the floating-point version of the input signal */
  89796. FLAC__real *real_signal_mid_side[2]; /* (@@@ currently unused) the floating-point version of the mid-side input signal (stereo only) */
  89797. FLAC__real *window[FLAC__MAX_APODIZATION_FUNCTIONS]; /* the pre-computed floating-point window for each apodization function */
  89798. FLAC__real *windowed_signal; /* the integer_signal[] * current window[] */
  89799. #endif
  89800. unsigned subframe_bps[FLAC__MAX_CHANNELS]; /* the effective bits per sample of the input signal (stream bps - wasted bits) */
  89801. unsigned subframe_bps_mid_side[2]; /* the effective bits per sample of the mid-side input signal (stream bps - wasted bits + 0/1) */
  89802. FLAC__int32 *residual_workspace[FLAC__MAX_CHANNELS][2]; /* each channel has a candidate and best workspace where the subframe residual signals will be stored */
  89803. FLAC__int32 *residual_workspace_mid_side[2][2];
  89804. FLAC__Subframe subframe_workspace[FLAC__MAX_CHANNELS][2];
  89805. FLAC__Subframe subframe_workspace_mid_side[2][2];
  89806. FLAC__Subframe *subframe_workspace_ptr[FLAC__MAX_CHANNELS][2];
  89807. FLAC__Subframe *subframe_workspace_ptr_mid_side[2][2];
  89808. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace[FLAC__MAX_CHANNELS][2];
  89809. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace_mid_side[FLAC__MAX_CHANNELS][2];
  89810. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr[FLAC__MAX_CHANNELS][2];
  89811. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr_mid_side[FLAC__MAX_CHANNELS][2];
  89812. unsigned best_subframe[FLAC__MAX_CHANNELS]; /* index (0 or 1) into 2nd dimension of the above workspaces */
  89813. unsigned best_subframe_mid_side[2];
  89814. unsigned best_subframe_bits[FLAC__MAX_CHANNELS]; /* size in bits of the best subframe for each channel */
  89815. unsigned best_subframe_bits_mid_side[2];
  89816. FLAC__uint64 *abs_residual_partition_sums; /* workspace where the sum of abs(candidate residual) for each partition is stored */
  89817. unsigned *raw_bits_per_partition; /* workspace where the sum of silog2(candidate residual) for each partition is stored */
  89818. FLAC__BitWriter *frame; /* the current frame being worked on */
  89819. unsigned loose_mid_side_stereo_frames; /* rounded number of frames the encoder will use before trying both independent and mid/side frames again */
  89820. unsigned loose_mid_side_stereo_frame_count; /* number of frames using the current channel assignment */
  89821. FLAC__ChannelAssignment last_channel_assignment;
  89822. FLAC__StreamMetadata streaminfo; /* scratchpad for STREAMINFO as it is built */
  89823. FLAC__StreamMetadata_SeekTable *seek_table; /* pointer into encoder->protected_->metadata_ where the seek table is */
  89824. unsigned current_sample_number;
  89825. unsigned current_frame_number;
  89826. FLAC__MD5Context md5context;
  89827. FLAC__CPUInfo cpuinfo;
  89828. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89829. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  89830. #else
  89831. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  89832. #endif
  89833. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89834. void (*local_lpc_compute_autocorrelation)(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  89835. 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[]);
  89836. 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[]);
  89837. 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[]);
  89838. #endif
  89839. FLAC__bool use_wide_by_block; /* use slow 64-bit versions of some functions because of the block size */
  89840. FLAC__bool use_wide_by_partition; /* use slow 64-bit versions of some functions because of the min partition order and blocksize */
  89841. FLAC__bool use_wide_by_order; /* use slow 64-bit versions of some functions because of the lpc order */
  89842. FLAC__bool disable_constant_subframes;
  89843. FLAC__bool disable_fixed_subframes;
  89844. FLAC__bool disable_verbatim_subframes;
  89845. #if FLAC__HAS_OGG
  89846. FLAC__bool is_ogg;
  89847. #endif
  89848. FLAC__StreamEncoderReadCallback read_callback; /* currently only needed for Ogg FLAC */
  89849. FLAC__StreamEncoderSeekCallback seek_callback;
  89850. FLAC__StreamEncoderTellCallback tell_callback;
  89851. FLAC__StreamEncoderWriteCallback write_callback;
  89852. FLAC__StreamEncoderMetadataCallback metadata_callback;
  89853. FLAC__StreamEncoderProgressCallback progress_callback;
  89854. void *client_data;
  89855. unsigned first_seekpoint_to_check;
  89856. FILE *file; /* only used when encoding to a file */
  89857. FLAC__uint64 bytes_written;
  89858. FLAC__uint64 samples_written;
  89859. unsigned frames_written;
  89860. unsigned total_frames_estimate;
  89861. FLAC__int32 *integer_signal_unaligned[FLAC__MAX_CHANNELS];
  89862. FLAC__int32 *integer_signal_mid_side_unaligned[2];
  89863. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89864. FLAC__real *real_signal_unaligned[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) */
  89865. FLAC__real *real_signal_mid_side_unaligned[2]; /* (@@@ currently unused) */
  89866. FLAC__real *window_unaligned[FLAC__MAX_APODIZATION_FUNCTIONS];
  89867. FLAC__real *windowed_signal_unaligned;
  89868. #endif
  89869. FLAC__int32 *residual_workspace_unaligned[FLAC__MAX_CHANNELS][2];
  89870. FLAC__int32 *residual_workspace_mid_side_unaligned[2][2];
  89871. FLAC__uint64 *abs_residual_partition_sums_unaligned;
  89872. unsigned *raw_bits_per_partition_unaligned;
  89873. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89874. FLAC__real lp_coeff[FLAC__MAX_LPC_ORDER][FLAC__MAX_LPC_ORDER]; /* from process_subframe_() */
  89875. #endif
  89876. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_extra[2]; /* from find_best_partition_order_() */
  89877. struct {
  89878. FLAC__StreamDecoder *decoder;
  89879. EncoderStateHint state_hint;
  89880. FLAC__bool needs_magic_hack;
  89881. verify_input_fifo input_fifo;
  89882. verify_output output;
  89883. struct {
  89884. FLAC__uint64 absolute_sample;
  89885. unsigned frame_number;
  89886. unsigned channel;
  89887. unsigned sample;
  89888. FLAC__int32 expected;
  89889. FLAC__int32 got;
  89890. } error_stats;
  89891. } verify;
  89892. FLAC__bool is_being_deleted; /* if true, call to ..._finish() from ..._delete() will not call the callbacks */
  89893. } FLAC__StreamEncoderPrivate;
  89894. FLAC_API const char * const FLAC__StreamEncoderStateString[] = {
  89895. "FLAC__STREAM_ENCODER_OK",
  89896. "FLAC__STREAM_ENCODER_UNINITIALIZED",
  89897. "FLAC__STREAM_ENCODER_OGG_ERROR",
  89898. "FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR",
  89899. "FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA",
  89900. "FLAC__STREAM_ENCODER_CLIENT_ERROR",
  89901. "FLAC__STREAM_ENCODER_IO_ERROR",
  89902. "FLAC__STREAM_ENCODER_FRAMING_ERROR",
  89903. "FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR"
  89904. };
  89905. FLAC_API const char * const FLAC__StreamEncoderInitStatusString[] = {
  89906. "FLAC__STREAM_ENCODER_INIT_STATUS_OK",
  89907. "FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR",
  89908. "FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  89909. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS",
  89910. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS",
  89911. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE",
  89912. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE",
  89913. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE",
  89914. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER",
  89915. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION",
  89916. "FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER",
  89917. "FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE",
  89918. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA",
  89919. "FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED"
  89920. };
  89921. FLAC_API const char * const FLAC__treamEncoderReadStatusString[] = {
  89922. "FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE",
  89923. "FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM",
  89924. "FLAC__STREAM_ENCODER_READ_STATUS_ABORT",
  89925. "FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED"
  89926. };
  89927. FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[] = {
  89928. "FLAC__STREAM_ENCODER_WRITE_STATUS_OK",
  89929. "FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR"
  89930. };
  89931. FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[] = {
  89932. "FLAC__STREAM_ENCODER_SEEK_STATUS_OK",
  89933. "FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR",
  89934. "FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED"
  89935. };
  89936. FLAC_API const char * const FLAC__StreamEncoderTellStatusString[] = {
  89937. "FLAC__STREAM_ENCODER_TELL_STATUS_OK",
  89938. "FLAC__STREAM_ENCODER_TELL_STATUS_ERROR",
  89939. "FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED"
  89940. };
  89941. static const unsigned OVERREAD_ = 1;
  89942. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void)
  89943. {
  89944. FLAC__StreamEncoder *encoder;
  89945. unsigned i;
  89946. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  89947. encoder = (FLAC__StreamEncoder*)calloc(1, sizeof(FLAC__StreamEncoder));
  89948. if(encoder == 0) {
  89949. return 0;
  89950. }
  89951. encoder->protected_ = (FLAC__StreamEncoderProtected*)calloc(1, sizeof(FLAC__StreamEncoderProtected));
  89952. if(encoder->protected_ == 0) {
  89953. free(encoder);
  89954. return 0;
  89955. }
  89956. encoder->private_ = (FLAC__StreamEncoderPrivate*)calloc(1, sizeof(FLAC__StreamEncoderPrivate));
  89957. if(encoder->private_ == 0) {
  89958. free(encoder->protected_);
  89959. free(encoder);
  89960. return 0;
  89961. }
  89962. encoder->private_->frame = FLAC__bitwriter_new();
  89963. if(encoder->private_->frame == 0) {
  89964. free(encoder->private_);
  89965. free(encoder->protected_);
  89966. free(encoder);
  89967. return 0;
  89968. }
  89969. encoder->private_->file = 0;
  89970. set_defaults_enc(encoder);
  89971. encoder->private_->is_being_deleted = false;
  89972. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  89973. encoder->private_->subframe_workspace_ptr[i][0] = &encoder->private_->subframe_workspace[i][0];
  89974. encoder->private_->subframe_workspace_ptr[i][1] = &encoder->private_->subframe_workspace[i][1];
  89975. }
  89976. for(i = 0; i < 2; i++) {
  89977. encoder->private_->subframe_workspace_ptr_mid_side[i][0] = &encoder->private_->subframe_workspace_mid_side[i][0];
  89978. encoder->private_->subframe_workspace_ptr_mid_side[i][1] = &encoder->private_->subframe_workspace_mid_side[i][1];
  89979. }
  89980. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  89981. encoder->private_->partitioned_rice_contents_workspace_ptr[i][0] = &encoder->private_->partitioned_rice_contents_workspace[i][0];
  89982. encoder->private_->partitioned_rice_contents_workspace_ptr[i][1] = &encoder->private_->partitioned_rice_contents_workspace[i][1];
  89983. }
  89984. for(i = 0; i < 2; i++) {
  89985. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][0] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0];
  89986. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][1] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1];
  89987. }
  89988. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  89989. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  89990. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  89991. }
  89992. for(i = 0; i < 2; i++) {
  89993. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  89994. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  89995. }
  89996. for(i = 0; i < 2; i++)
  89997. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_extra[i]);
  89998. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  89999. return encoder;
  90000. }
  90001. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder)
  90002. {
  90003. unsigned i;
  90004. FLAC__ASSERT(0 != encoder);
  90005. FLAC__ASSERT(0 != encoder->protected_);
  90006. FLAC__ASSERT(0 != encoder->private_);
  90007. FLAC__ASSERT(0 != encoder->private_->frame);
  90008. encoder->private_->is_being_deleted = true;
  90009. (void)FLAC__stream_encoder_finish(encoder);
  90010. if(0 != encoder->private_->verify.decoder)
  90011. FLAC__stream_decoder_delete(encoder->private_->verify.decoder);
  90012. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90013. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  90014. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  90015. }
  90016. for(i = 0; i < 2; i++) {
  90017. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  90018. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  90019. }
  90020. for(i = 0; i < 2; i++)
  90021. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_extra[i]);
  90022. FLAC__bitwriter_delete(encoder->private_->frame);
  90023. free(encoder->private_);
  90024. free(encoder->protected_);
  90025. free(encoder);
  90026. }
  90027. static FLAC__StreamEncoderInitStatus init_stream_internal_enc(
  90028. FLAC__StreamEncoder *encoder,
  90029. FLAC__StreamEncoderReadCallback read_callback,
  90030. FLAC__StreamEncoderWriteCallback write_callback,
  90031. FLAC__StreamEncoderSeekCallback seek_callback,
  90032. FLAC__StreamEncoderTellCallback tell_callback,
  90033. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90034. void *client_data,
  90035. FLAC__bool is_ogg
  90036. )
  90037. {
  90038. unsigned i;
  90039. FLAC__bool metadata_has_seektable, metadata_has_vorbis_comment, metadata_picture_has_type1, metadata_picture_has_type2;
  90040. FLAC__ASSERT(0 != encoder);
  90041. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90042. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90043. #if !FLAC__HAS_OGG
  90044. if(is_ogg)
  90045. return FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  90046. #endif
  90047. if(0 == write_callback || (seek_callback && 0 == tell_callback))
  90048. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS;
  90049. if(encoder->protected_->channels == 0 || encoder->protected_->channels > FLAC__MAX_CHANNELS)
  90050. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS;
  90051. if(encoder->protected_->channels != 2) {
  90052. encoder->protected_->do_mid_side_stereo = false;
  90053. encoder->protected_->loose_mid_side_stereo = false;
  90054. }
  90055. else if(!encoder->protected_->do_mid_side_stereo)
  90056. encoder->protected_->loose_mid_side_stereo = false;
  90057. if(encoder->protected_->bits_per_sample >= 32)
  90058. encoder->protected_->do_mid_side_stereo = false; /* since we currenty do 32-bit math, the side channel would have 33 bps and overflow */
  90059. if(encoder->protected_->bits_per_sample < FLAC__MIN_BITS_PER_SAMPLE || encoder->protected_->bits_per_sample > FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE)
  90060. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE;
  90061. if(!FLAC__format_sample_rate_is_valid(encoder->protected_->sample_rate))
  90062. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE;
  90063. if(encoder->protected_->blocksize == 0) {
  90064. if(encoder->protected_->max_lpc_order == 0)
  90065. encoder->protected_->blocksize = 1152;
  90066. else
  90067. encoder->protected_->blocksize = 4096;
  90068. }
  90069. if(encoder->protected_->blocksize < FLAC__MIN_BLOCK_SIZE || encoder->protected_->blocksize > FLAC__MAX_BLOCK_SIZE)
  90070. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE;
  90071. if(encoder->protected_->max_lpc_order > FLAC__MAX_LPC_ORDER)
  90072. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER;
  90073. if(encoder->protected_->blocksize < encoder->protected_->max_lpc_order)
  90074. return FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER;
  90075. if(encoder->protected_->qlp_coeff_precision == 0) {
  90076. if(encoder->protected_->bits_per_sample < 16) {
  90077. encoder->protected_->qlp_coeff_precision = max(FLAC__MIN_QLP_COEFF_PRECISION, 2 + encoder->protected_->bits_per_sample / 2);
  90078. }
  90079. else if(encoder->protected_->bits_per_sample == 16) {
  90080. if(encoder->protected_->blocksize <= 192)
  90081. encoder->protected_->qlp_coeff_precision = 7;
  90082. else if(encoder->protected_->blocksize <= 384)
  90083. encoder->protected_->qlp_coeff_precision = 8;
  90084. else if(encoder->protected_->blocksize <= 576)
  90085. encoder->protected_->qlp_coeff_precision = 9;
  90086. else if(encoder->protected_->blocksize <= 1152)
  90087. encoder->protected_->qlp_coeff_precision = 10;
  90088. else if(encoder->protected_->blocksize <= 2304)
  90089. encoder->protected_->qlp_coeff_precision = 11;
  90090. else if(encoder->protected_->blocksize <= 4608)
  90091. encoder->protected_->qlp_coeff_precision = 12;
  90092. else
  90093. encoder->protected_->qlp_coeff_precision = 13;
  90094. }
  90095. else {
  90096. if(encoder->protected_->blocksize <= 384)
  90097. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-2;
  90098. else if(encoder->protected_->blocksize <= 1152)
  90099. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-1;
  90100. else
  90101. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  90102. }
  90103. FLAC__ASSERT(encoder->protected_->qlp_coeff_precision <= FLAC__MAX_QLP_COEFF_PRECISION);
  90104. }
  90105. else if(encoder->protected_->qlp_coeff_precision < FLAC__MIN_QLP_COEFF_PRECISION || encoder->protected_->qlp_coeff_precision > FLAC__MAX_QLP_COEFF_PRECISION)
  90106. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION;
  90107. if(encoder->protected_->streamable_subset) {
  90108. if(
  90109. encoder->protected_->blocksize != 192 &&
  90110. encoder->protected_->blocksize != 576 &&
  90111. encoder->protected_->blocksize != 1152 &&
  90112. encoder->protected_->blocksize != 2304 &&
  90113. encoder->protected_->blocksize != 4608 &&
  90114. encoder->protected_->blocksize != 256 &&
  90115. encoder->protected_->blocksize != 512 &&
  90116. encoder->protected_->blocksize != 1024 &&
  90117. encoder->protected_->blocksize != 2048 &&
  90118. encoder->protected_->blocksize != 4096 &&
  90119. encoder->protected_->blocksize != 8192 &&
  90120. encoder->protected_->blocksize != 16384
  90121. )
  90122. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90123. if(!FLAC__format_sample_rate_is_subset(encoder->protected_->sample_rate))
  90124. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90125. if(
  90126. encoder->protected_->bits_per_sample != 8 &&
  90127. encoder->protected_->bits_per_sample != 12 &&
  90128. encoder->protected_->bits_per_sample != 16 &&
  90129. encoder->protected_->bits_per_sample != 20 &&
  90130. encoder->protected_->bits_per_sample != 24
  90131. )
  90132. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90133. if(encoder->protected_->max_residual_partition_order > FLAC__SUBSET_MAX_RICE_PARTITION_ORDER)
  90134. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90135. if(
  90136. encoder->protected_->sample_rate <= 48000 &&
  90137. (
  90138. encoder->protected_->blocksize > FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ ||
  90139. encoder->protected_->max_lpc_order > FLAC__SUBSET_MAX_LPC_ORDER_48000HZ
  90140. )
  90141. ) {
  90142. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90143. }
  90144. }
  90145. if(encoder->protected_->max_residual_partition_order >= (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  90146. encoder->protected_->max_residual_partition_order = (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN) - 1;
  90147. if(encoder->protected_->min_residual_partition_order >= encoder->protected_->max_residual_partition_order)
  90148. encoder->protected_->min_residual_partition_order = encoder->protected_->max_residual_partition_order;
  90149. #if FLAC__HAS_OGG
  90150. if(is_ogg && 0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 1) {
  90151. unsigned i;
  90152. for(i = 1; i < encoder->protected_->num_metadata_blocks; i++) {
  90153. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90154. FLAC__StreamMetadata *vc = encoder->protected_->metadata[i];
  90155. for( ; i > 0; i--)
  90156. encoder->protected_->metadata[i] = encoder->protected_->metadata[i-1];
  90157. encoder->protected_->metadata[0] = vc;
  90158. break;
  90159. }
  90160. }
  90161. }
  90162. #endif
  90163. if(0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0) {
  90164. unsigned i;
  90165. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90166. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90167. encoder->private_->seek_table = &encoder->protected_->metadata[i]->data.seek_table;
  90168. break; /* take only the first one */
  90169. }
  90170. }
  90171. }
  90172. if(0 == encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0)
  90173. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90174. metadata_has_seektable = false;
  90175. metadata_has_vorbis_comment = false;
  90176. metadata_picture_has_type1 = false;
  90177. metadata_picture_has_type2 = false;
  90178. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90179. const FLAC__StreamMetadata *m = encoder->protected_->metadata[i];
  90180. if(m->type == FLAC__METADATA_TYPE_STREAMINFO)
  90181. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90182. else if(m->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90183. if(metadata_has_seektable) /* only one is allowed */
  90184. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90185. metadata_has_seektable = true;
  90186. if(!FLAC__format_seektable_is_legal(&m->data.seek_table))
  90187. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90188. }
  90189. else if(m->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90190. if(metadata_has_vorbis_comment) /* only one is allowed */
  90191. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90192. metadata_has_vorbis_comment = true;
  90193. }
  90194. else if(m->type == FLAC__METADATA_TYPE_CUESHEET) {
  90195. if(!FLAC__format_cuesheet_is_legal(&m->data.cue_sheet, m->data.cue_sheet.is_cd, /*violation=*/0))
  90196. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90197. }
  90198. else if(m->type == FLAC__METADATA_TYPE_PICTURE) {
  90199. if(!FLAC__format_picture_is_legal(&m->data.picture, /*violation=*/0))
  90200. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90201. if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD) {
  90202. if(metadata_picture_has_type1) /* there should only be 1 per stream */
  90203. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90204. metadata_picture_has_type1 = true;
  90205. if(
  90206. m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD &&
  90207. (
  90208. (strcmp(m->data.picture.mime_type, "image/png") && strcmp(m->data.picture.mime_type, "-->")) ||
  90209. m->data.picture.width != 32 ||
  90210. m->data.picture.height != 32
  90211. )
  90212. )
  90213. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90214. }
  90215. else if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON) {
  90216. if(metadata_picture_has_type2) /* there should only be 1 per stream */
  90217. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90218. metadata_picture_has_type2 = true;
  90219. }
  90220. }
  90221. }
  90222. encoder->private_->input_capacity = 0;
  90223. for(i = 0; i < encoder->protected_->channels; i++) {
  90224. encoder->private_->integer_signal_unaligned[i] = encoder->private_->integer_signal[i] = 0;
  90225. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90226. encoder->private_->real_signal_unaligned[i] = encoder->private_->real_signal[i] = 0;
  90227. #endif
  90228. }
  90229. for(i = 0; i < 2; i++) {
  90230. encoder->private_->integer_signal_mid_side_unaligned[i] = encoder->private_->integer_signal_mid_side[i] = 0;
  90231. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90232. encoder->private_->real_signal_mid_side_unaligned[i] = encoder->private_->real_signal_mid_side[i] = 0;
  90233. #endif
  90234. }
  90235. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90236. for(i = 0; i < encoder->protected_->num_apodizations; i++)
  90237. encoder->private_->window_unaligned[i] = encoder->private_->window[i] = 0;
  90238. encoder->private_->windowed_signal_unaligned = encoder->private_->windowed_signal = 0;
  90239. #endif
  90240. for(i = 0; i < encoder->protected_->channels; i++) {
  90241. encoder->private_->residual_workspace_unaligned[i][0] = encoder->private_->residual_workspace[i][0] = 0;
  90242. encoder->private_->residual_workspace_unaligned[i][1] = encoder->private_->residual_workspace[i][1] = 0;
  90243. encoder->private_->best_subframe[i] = 0;
  90244. }
  90245. for(i = 0; i < 2; i++) {
  90246. encoder->private_->residual_workspace_mid_side_unaligned[i][0] = encoder->private_->residual_workspace_mid_side[i][0] = 0;
  90247. encoder->private_->residual_workspace_mid_side_unaligned[i][1] = encoder->private_->residual_workspace_mid_side[i][1] = 0;
  90248. encoder->private_->best_subframe_mid_side[i] = 0;
  90249. }
  90250. encoder->private_->abs_residual_partition_sums_unaligned = encoder->private_->abs_residual_partition_sums = 0;
  90251. encoder->private_->raw_bits_per_partition_unaligned = encoder->private_->raw_bits_per_partition = 0;
  90252. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90253. encoder->private_->loose_mid_side_stereo_frames = (unsigned)((FLAC__double)encoder->protected_->sample_rate * 0.4 / (FLAC__double)encoder->protected_->blocksize + 0.5);
  90254. #else
  90255. FLAC__ASSERT(FLAC__MAX_SAMPLE_RATE <= 655350);
  90256. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535);
  90257. FLAC__ASSERT(encoder->protected_->sample_rate <= 655350);
  90258. FLAC__ASSERT(encoder->protected_->blocksize <= 65535);
  90259. 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);
  90260. #endif
  90261. if(encoder->private_->loose_mid_side_stereo_frames == 0)
  90262. encoder->private_->loose_mid_side_stereo_frames = 1;
  90263. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  90264. encoder->private_->current_sample_number = 0;
  90265. encoder->private_->current_frame_number = 0;
  90266. encoder->private_->use_wide_by_block = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(encoder->protected_->blocksize)+1 > 30);
  90267. 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? */
  90268. encoder->private_->use_wide_by_partition = (false); /*@@@ need to set this */
  90269. FLAC__cpu_info(&encoder->private_->cpuinfo);
  90270. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90271. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation;
  90272. #endif
  90273. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor;
  90274. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90275. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90276. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide;
  90277. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90278. #endif
  90279. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90280. # ifndef FLAC__NO_ASM
  90281. if(encoder->private_->cpuinfo.use_asm) {
  90282. # ifdef FLAC__CPU_IA32
  90283. FLAC__ASSERT(encoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  90284. # ifdef FLAC__HAS_NASM
  90285. if(encoder->private_->cpuinfo.data.ia32.sse) {
  90286. if(encoder->protected_->max_lpc_order < 4)
  90287. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4;
  90288. else if(encoder->protected_->max_lpc_order < 8)
  90289. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8;
  90290. else if(encoder->protected_->max_lpc_order < 12)
  90291. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12;
  90292. else
  90293. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90294. }
  90295. else if(encoder->private_->cpuinfo.data.ia32._3dnow)
  90296. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow;
  90297. else
  90298. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90299. if(encoder->private_->cpuinfo.data.ia32.mmx) {
  90300. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90301. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mmx;
  90302. }
  90303. else {
  90304. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90305. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90306. }
  90307. if(encoder->private_->cpuinfo.data.ia32.mmx && encoder->private_->cpuinfo.data.ia32.cmov)
  90308. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_asm_ia32_mmx_cmov;
  90309. # endif /* FLAC__HAS_NASM */
  90310. # endif /* FLAC__CPU_IA32 */
  90311. }
  90312. # endif /* !FLAC__NO_ASM */
  90313. #endif /* !FLAC__INTEGER_ONLY_LIBRARY */
  90314. if(encoder->private_->use_wide_by_block) {
  90315. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_wide;
  90316. }
  90317. encoder->protected_->state = FLAC__STREAM_ENCODER_OK;
  90318. #if FLAC__HAS_OGG
  90319. encoder->private_->is_ogg = is_ogg;
  90320. if(is_ogg && !FLAC__ogg_encoder_aspect_init(&encoder->protected_->ogg_encoder_aspect)) {
  90321. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  90322. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90323. }
  90324. #endif
  90325. encoder->private_->read_callback = read_callback;
  90326. encoder->private_->write_callback = write_callback;
  90327. encoder->private_->seek_callback = seek_callback;
  90328. encoder->private_->tell_callback = tell_callback;
  90329. encoder->private_->metadata_callback = metadata_callback;
  90330. encoder->private_->client_data = client_data;
  90331. if(!resize_buffers_(encoder, encoder->protected_->blocksize)) {
  90332. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90333. }
  90334. if(!FLAC__bitwriter_init(encoder->private_->frame)) {
  90335. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90336. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90337. }
  90338. if(encoder->protected_->verify) {
  90339. encoder->private_->verify.input_fifo.size = encoder->protected_->blocksize+OVERREAD_;
  90340. for(i = 0; i < encoder->protected_->channels; i++) {
  90341. 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))) {
  90342. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90343. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90344. }
  90345. }
  90346. encoder->private_->verify.input_fifo.tail = 0;
  90347. encoder->private_->verify.decoder = FLAC__stream_decoder_new();
  90348. if(0 == encoder->private_->verify.decoder) {
  90349. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90350. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90351. }
  90352. 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) {
  90353. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90354. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90355. }
  90356. }
  90357. encoder->private_->verify.error_stats.absolute_sample = 0;
  90358. encoder->private_->verify.error_stats.frame_number = 0;
  90359. encoder->private_->verify.error_stats.channel = 0;
  90360. encoder->private_->verify.error_stats.sample = 0;
  90361. encoder->private_->verify.error_stats.expected = 0;
  90362. encoder->private_->verify.error_stats.got = 0;
  90363. encoder->private_->first_seekpoint_to_check = 0;
  90364. encoder->private_->samples_written = 0;
  90365. encoder->protected_->streaminfo_offset = 0;
  90366. encoder->protected_->seektable_offset = 0;
  90367. encoder->protected_->audio_offset = 0;
  90368. if(encoder->protected_->verify)
  90369. encoder->private_->verify.state_hint = ENCODER_IN_MAGIC;
  90370. if(!FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, FLAC__STREAM_SYNC, FLAC__STREAM_SYNC_LEN)) {
  90371. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90372. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90373. }
  90374. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90375. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90376. }
  90377. if(encoder->protected_->verify)
  90378. encoder->private_->verify.state_hint = ENCODER_IN_METADATA;
  90379. encoder->private_->streaminfo.type = FLAC__METADATA_TYPE_STREAMINFO;
  90380. encoder->private_->streaminfo.is_last = false; /* we will have at a minimum a VORBIS_COMMENT afterwards */
  90381. encoder->private_->streaminfo.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
  90382. encoder->private_->streaminfo.data.stream_info.min_blocksize = encoder->protected_->blocksize; /* this encoder uses the same blocksize for the whole stream */
  90383. encoder->private_->streaminfo.data.stream_info.max_blocksize = encoder->protected_->blocksize;
  90384. encoder->private_->streaminfo.data.stream_info.min_framesize = 0; /* we don't know this yet; have to fill it in later */
  90385. encoder->private_->streaminfo.data.stream_info.max_framesize = 0; /* we don't know this yet; have to fill it in later */
  90386. encoder->private_->streaminfo.data.stream_info.sample_rate = encoder->protected_->sample_rate;
  90387. encoder->private_->streaminfo.data.stream_info.channels = encoder->protected_->channels;
  90388. encoder->private_->streaminfo.data.stream_info.bits_per_sample = encoder->protected_->bits_per_sample;
  90389. encoder->private_->streaminfo.data.stream_info.total_samples = encoder->protected_->total_samples_estimate; /* we will replace this later with the real total */
  90390. memset(encoder->private_->streaminfo.data.stream_info.md5sum, 0, 16); /* we don't know this yet; have to fill it in later */
  90391. if(encoder->protected_->do_md5)
  90392. FLAC__MD5Init(&encoder->private_->md5context);
  90393. if(!FLAC__add_metadata_block(&encoder->private_->streaminfo, encoder->private_->frame)) {
  90394. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90395. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90396. }
  90397. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90398. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90399. }
  90400. encoder->private_->streaminfo.data.stream_info.min_framesize = (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN) - 1;
  90401. encoder->private_->streaminfo.data.stream_info.total_samples = 0;
  90402. if(!metadata_has_vorbis_comment) {
  90403. FLAC__StreamMetadata vorbis_comment;
  90404. vorbis_comment.type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
  90405. vorbis_comment.is_last = (encoder->protected_->num_metadata_blocks == 0);
  90406. vorbis_comment.length = 4 + 4; /* MAGIC NUMBER */
  90407. vorbis_comment.data.vorbis_comment.vendor_string.length = 0;
  90408. vorbis_comment.data.vorbis_comment.vendor_string.entry = 0;
  90409. vorbis_comment.data.vorbis_comment.num_comments = 0;
  90410. vorbis_comment.data.vorbis_comment.comments = 0;
  90411. if(!FLAC__add_metadata_block(&vorbis_comment, encoder->private_->frame)) {
  90412. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90413. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90414. }
  90415. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90416. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90417. }
  90418. }
  90419. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90420. encoder->protected_->metadata[i]->is_last = (i == encoder->protected_->num_metadata_blocks - 1);
  90421. if(!FLAC__add_metadata_block(encoder->protected_->metadata[i], encoder->private_->frame)) {
  90422. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90423. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90424. }
  90425. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90426. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90427. }
  90428. }
  90429. 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 */
  90430. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  90431. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90432. }
  90433. if(encoder->protected_->verify)
  90434. encoder->private_->verify.state_hint = ENCODER_IN_AUDIO;
  90435. return FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  90436. }
  90437. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(
  90438. FLAC__StreamEncoder *encoder,
  90439. FLAC__StreamEncoderWriteCallback write_callback,
  90440. FLAC__StreamEncoderSeekCallback seek_callback,
  90441. FLAC__StreamEncoderTellCallback tell_callback,
  90442. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90443. void *client_data
  90444. )
  90445. {
  90446. return init_stream_internal_enc(
  90447. encoder,
  90448. 0,
  90449. write_callback,
  90450. seek_callback,
  90451. tell_callback,
  90452. metadata_callback,
  90453. client_data,
  90454. false
  90455. );
  90456. }
  90457. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream(
  90458. FLAC__StreamEncoder *encoder,
  90459. FLAC__StreamEncoderReadCallback read_callback,
  90460. FLAC__StreamEncoderWriteCallback write_callback,
  90461. FLAC__StreamEncoderSeekCallback seek_callback,
  90462. FLAC__StreamEncoderTellCallback tell_callback,
  90463. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90464. void *client_data
  90465. )
  90466. {
  90467. return init_stream_internal_enc(
  90468. encoder,
  90469. read_callback,
  90470. write_callback,
  90471. seek_callback,
  90472. tell_callback,
  90473. metadata_callback,
  90474. client_data,
  90475. true
  90476. );
  90477. }
  90478. static FLAC__StreamEncoderInitStatus init_FILE_internal_enc(
  90479. FLAC__StreamEncoder *encoder,
  90480. FILE *file,
  90481. FLAC__StreamEncoderProgressCallback progress_callback,
  90482. void *client_data,
  90483. FLAC__bool is_ogg
  90484. )
  90485. {
  90486. FLAC__StreamEncoderInitStatus init_status;
  90487. FLAC__ASSERT(0 != encoder);
  90488. FLAC__ASSERT(0 != file);
  90489. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90490. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90491. if(file == 0) {
  90492. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90493. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90494. }
  90495. if(file == stdout)
  90496. file = get_binary_stdout_(); /* just to be safe */
  90497. encoder->private_->file = file;
  90498. encoder->private_->progress_callback = progress_callback;
  90499. encoder->private_->bytes_written = 0;
  90500. encoder->private_->samples_written = 0;
  90501. encoder->private_->frames_written = 0;
  90502. init_status = init_stream_internal_enc(
  90503. encoder,
  90504. encoder->private_->file == stdout? 0 : is_ogg? file_read_callback_enc : 0,
  90505. file_write_callback_,
  90506. encoder->private_->file == stdout? 0 : file_seek_callback_enc,
  90507. encoder->private_->file == stdout? 0 : file_tell_callback_enc,
  90508. 0,
  90509. client_data,
  90510. is_ogg
  90511. );
  90512. if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
  90513. return init_status;
  90514. }
  90515. {
  90516. unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  90517. FLAC__ASSERT(blocksize != 0);
  90518. encoder->private_->total_frames_estimate = (unsigned)((FLAC__stream_encoder_get_total_samples_estimate(encoder) + blocksize - 1) / blocksize);
  90519. }
  90520. return init_status;
  90521. }
  90522. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(
  90523. FLAC__StreamEncoder *encoder,
  90524. FILE *file,
  90525. FLAC__StreamEncoderProgressCallback progress_callback,
  90526. void *client_data
  90527. )
  90528. {
  90529. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/false);
  90530. }
  90531. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(
  90532. FLAC__StreamEncoder *encoder,
  90533. FILE *file,
  90534. FLAC__StreamEncoderProgressCallback progress_callback,
  90535. void *client_data
  90536. )
  90537. {
  90538. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/true);
  90539. }
  90540. static FLAC__StreamEncoderInitStatus init_file_internal_enc(
  90541. FLAC__StreamEncoder *encoder,
  90542. const char *filename,
  90543. FLAC__StreamEncoderProgressCallback progress_callback,
  90544. void *client_data,
  90545. FLAC__bool is_ogg
  90546. )
  90547. {
  90548. FILE *file;
  90549. FLAC__ASSERT(0 != encoder);
  90550. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90551. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90552. file = filename? fopen(filename, "w+b") : stdout;
  90553. if(file == 0) {
  90554. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90555. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90556. }
  90557. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, is_ogg);
  90558. }
  90559. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(
  90560. FLAC__StreamEncoder *encoder,
  90561. const char *filename,
  90562. FLAC__StreamEncoderProgressCallback progress_callback,
  90563. void *client_data
  90564. )
  90565. {
  90566. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/false);
  90567. }
  90568. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(
  90569. FLAC__StreamEncoder *encoder,
  90570. const char *filename,
  90571. FLAC__StreamEncoderProgressCallback progress_callback,
  90572. void *client_data
  90573. )
  90574. {
  90575. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/true);
  90576. }
  90577. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder)
  90578. {
  90579. FLAC__bool error = false;
  90580. FLAC__ASSERT(0 != encoder);
  90581. FLAC__ASSERT(0 != encoder->private_);
  90582. FLAC__ASSERT(0 != encoder->protected_);
  90583. if(encoder->protected_->state == FLAC__STREAM_ENCODER_UNINITIALIZED)
  90584. return true;
  90585. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK && !encoder->private_->is_being_deleted) {
  90586. if(encoder->private_->current_sample_number != 0) {
  90587. const FLAC__bool is_fractional_block = encoder->protected_->blocksize != encoder->private_->current_sample_number;
  90588. encoder->protected_->blocksize = encoder->private_->current_sample_number;
  90589. if(!process_frame_(encoder, is_fractional_block, /*is_last_block=*/true))
  90590. error = true;
  90591. }
  90592. }
  90593. if(encoder->protected_->do_md5)
  90594. FLAC__MD5Final(encoder->private_->streaminfo.data.stream_info.md5sum, &encoder->private_->md5context);
  90595. if(!encoder->private_->is_being_deleted) {
  90596. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK) {
  90597. if(encoder->private_->seek_callback) {
  90598. #if FLAC__HAS_OGG
  90599. if(encoder->private_->is_ogg)
  90600. update_ogg_metadata_(encoder);
  90601. else
  90602. #endif
  90603. update_metadata_(encoder);
  90604. if(encoder->protected_->state != FLAC__STREAM_ENCODER_OK)
  90605. error = true;
  90606. }
  90607. if(encoder->private_->metadata_callback)
  90608. encoder->private_->metadata_callback(encoder, &encoder->private_->streaminfo, encoder->private_->client_data);
  90609. }
  90610. if(encoder->protected_->verify && 0 != encoder->private_->verify.decoder && !FLAC__stream_decoder_finish(encoder->private_->verify.decoder)) {
  90611. if(!error)
  90612. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  90613. error = true;
  90614. }
  90615. }
  90616. if(0 != encoder->private_->file) {
  90617. if(encoder->private_->file != stdout)
  90618. fclose(encoder->private_->file);
  90619. encoder->private_->file = 0;
  90620. }
  90621. #if FLAC__HAS_OGG
  90622. if(encoder->private_->is_ogg)
  90623. FLAC__ogg_encoder_aspect_finish(&encoder->protected_->ogg_encoder_aspect);
  90624. #endif
  90625. free_(encoder);
  90626. set_defaults_enc(encoder);
  90627. if(!error)
  90628. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  90629. return !error;
  90630. }
  90631. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long value)
  90632. {
  90633. FLAC__ASSERT(0 != encoder);
  90634. FLAC__ASSERT(0 != encoder->private_);
  90635. FLAC__ASSERT(0 != encoder->protected_);
  90636. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90637. return false;
  90638. #if FLAC__HAS_OGG
  90639. FLAC__ogg_encoder_aspect_set_serial_number(&encoder->protected_->ogg_encoder_aspect, value);
  90640. return true;
  90641. #else
  90642. (void)value;
  90643. return false;
  90644. #endif
  90645. }
  90646. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90647. {
  90648. FLAC__ASSERT(0 != encoder);
  90649. FLAC__ASSERT(0 != encoder->private_);
  90650. FLAC__ASSERT(0 != encoder->protected_);
  90651. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90652. return false;
  90653. #ifndef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  90654. encoder->protected_->verify = value;
  90655. #endif
  90656. return true;
  90657. }
  90658. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90659. {
  90660. FLAC__ASSERT(0 != encoder);
  90661. FLAC__ASSERT(0 != encoder->private_);
  90662. FLAC__ASSERT(0 != encoder->protected_);
  90663. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90664. return false;
  90665. encoder->protected_->streamable_subset = value;
  90666. return true;
  90667. }
  90668. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_md5(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90669. {
  90670. FLAC__ASSERT(0 != encoder);
  90671. FLAC__ASSERT(0 != encoder->private_);
  90672. FLAC__ASSERT(0 != encoder->protected_);
  90673. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90674. return false;
  90675. encoder->protected_->do_md5 = value;
  90676. return true;
  90677. }
  90678. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value)
  90679. {
  90680. FLAC__ASSERT(0 != encoder);
  90681. FLAC__ASSERT(0 != encoder->private_);
  90682. FLAC__ASSERT(0 != encoder->protected_);
  90683. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90684. return false;
  90685. encoder->protected_->channels = value;
  90686. return true;
  90687. }
  90688. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value)
  90689. {
  90690. FLAC__ASSERT(0 != encoder);
  90691. FLAC__ASSERT(0 != encoder->private_);
  90692. FLAC__ASSERT(0 != encoder->protected_);
  90693. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90694. return false;
  90695. encoder->protected_->bits_per_sample = value;
  90696. return true;
  90697. }
  90698. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value)
  90699. {
  90700. FLAC__ASSERT(0 != encoder);
  90701. FLAC__ASSERT(0 != encoder->private_);
  90702. FLAC__ASSERT(0 != encoder->protected_);
  90703. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90704. return false;
  90705. encoder->protected_->sample_rate = value;
  90706. return true;
  90707. }
  90708. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value)
  90709. {
  90710. FLAC__bool ok = true;
  90711. FLAC__ASSERT(0 != encoder);
  90712. FLAC__ASSERT(0 != encoder->private_);
  90713. FLAC__ASSERT(0 != encoder->protected_);
  90714. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90715. return false;
  90716. if(value >= sizeof(compression_levels_)/sizeof(compression_levels_[0]))
  90717. value = sizeof(compression_levels_)/sizeof(compression_levels_[0]) - 1;
  90718. ok &= FLAC__stream_encoder_set_do_mid_side_stereo (encoder, compression_levels_[value].do_mid_side_stereo);
  90719. ok &= FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, compression_levels_[value].loose_mid_side_stereo);
  90720. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90721. #if 0
  90722. ok &= FLAC__stream_encoder_set_apodization (encoder, compression_levels_[value].apodization);
  90723. #else
  90724. encoder->protected_->num_apodizations = 1;
  90725. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  90726. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  90727. #endif
  90728. #endif
  90729. ok &= FLAC__stream_encoder_set_max_lpc_order (encoder, compression_levels_[value].max_lpc_order);
  90730. ok &= FLAC__stream_encoder_set_qlp_coeff_precision (encoder, compression_levels_[value].qlp_coeff_precision);
  90731. ok &= FLAC__stream_encoder_set_do_qlp_coeff_prec_search (encoder, compression_levels_[value].do_qlp_coeff_prec_search);
  90732. ok &= FLAC__stream_encoder_set_do_escape_coding (encoder, compression_levels_[value].do_escape_coding);
  90733. ok &= FLAC__stream_encoder_set_do_exhaustive_model_search (encoder, compression_levels_[value].do_exhaustive_model_search);
  90734. ok &= FLAC__stream_encoder_set_min_residual_partition_order(encoder, compression_levels_[value].min_residual_partition_order);
  90735. ok &= FLAC__stream_encoder_set_max_residual_partition_order(encoder, compression_levels_[value].max_residual_partition_order);
  90736. ok &= FLAC__stream_encoder_set_rice_parameter_search_dist (encoder, compression_levels_[value].rice_parameter_search_dist);
  90737. return ok;
  90738. }
  90739. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value)
  90740. {
  90741. FLAC__ASSERT(0 != encoder);
  90742. FLAC__ASSERT(0 != encoder->private_);
  90743. FLAC__ASSERT(0 != encoder->protected_);
  90744. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90745. return false;
  90746. encoder->protected_->blocksize = value;
  90747. return true;
  90748. }
  90749. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90750. {
  90751. FLAC__ASSERT(0 != encoder);
  90752. FLAC__ASSERT(0 != encoder->private_);
  90753. FLAC__ASSERT(0 != encoder->protected_);
  90754. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90755. return false;
  90756. encoder->protected_->do_mid_side_stereo = value;
  90757. return true;
  90758. }
  90759. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90760. {
  90761. FLAC__ASSERT(0 != encoder);
  90762. FLAC__ASSERT(0 != encoder->private_);
  90763. FLAC__ASSERT(0 != encoder->protected_);
  90764. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90765. return false;
  90766. encoder->protected_->loose_mid_side_stereo = value;
  90767. return true;
  90768. }
  90769. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification)
  90770. {
  90771. FLAC__ASSERT(0 != encoder);
  90772. FLAC__ASSERT(0 != encoder->private_);
  90773. FLAC__ASSERT(0 != encoder->protected_);
  90774. FLAC__ASSERT(0 != specification);
  90775. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90776. return false;
  90777. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  90778. (void)specification; /* silently ignore since we haven't integerized; will always use a rectangular window */
  90779. #else
  90780. encoder->protected_->num_apodizations = 0;
  90781. while(1) {
  90782. const char *s = strchr(specification, ';');
  90783. const size_t n = s? (size_t)(s - specification) : strlen(specification);
  90784. if (n==8 && 0 == strncmp("bartlett" , specification, n))
  90785. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT;
  90786. else if(n==13 && 0 == strncmp("bartlett_hann", specification, n))
  90787. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT_HANN;
  90788. else if(n==8 && 0 == strncmp("blackman" , specification, n))
  90789. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN;
  90790. else if(n==26 && 0 == strncmp("blackman_harris_4term_92db", specification, n))
  90791. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE;
  90792. else if(n==6 && 0 == strncmp("connes" , specification, n))
  90793. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_CONNES;
  90794. else if(n==7 && 0 == strncmp("flattop" , specification, n))
  90795. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_FLATTOP;
  90796. else if(n>7 && 0 == strncmp("gauss(" , specification, 6)) {
  90797. FLAC__real stddev = (FLAC__real)strtod(specification+6, 0);
  90798. if (stddev > 0.0 && stddev <= 0.5) {
  90799. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.gauss.stddev = stddev;
  90800. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_GAUSS;
  90801. }
  90802. }
  90803. else if(n==7 && 0 == strncmp("hamming" , specification, n))
  90804. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HAMMING;
  90805. else if(n==4 && 0 == strncmp("hann" , specification, n))
  90806. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HANN;
  90807. else if(n==13 && 0 == strncmp("kaiser_bessel", specification, n))
  90808. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_KAISER_BESSEL;
  90809. else if(n==7 && 0 == strncmp("nuttall" , specification, n))
  90810. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_NUTTALL;
  90811. else if(n==9 && 0 == strncmp("rectangle" , specification, n))
  90812. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_RECTANGLE;
  90813. else if(n==8 && 0 == strncmp("triangle" , specification, n))
  90814. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TRIANGLE;
  90815. else if(n>7 && 0 == strncmp("tukey(" , specification, 6)) {
  90816. FLAC__real p = (FLAC__real)strtod(specification+6, 0);
  90817. if (p >= 0.0 && p <= 1.0) {
  90818. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.tukey.p = p;
  90819. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TUKEY;
  90820. }
  90821. }
  90822. else if(n==5 && 0 == strncmp("welch" , specification, n))
  90823. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_WELCH;
  90824. if (encoder->protected_->num_apodizations == 32)
  90825. break;
  90826. if (s)
  90827. specification = s+1;
  90828. else
  90829. break;
  90830. }
  90831. if(encoder->protected_->num_apodizations == 0) {
  90832. encoder->protected_->num_apodizations = 1;
  90833. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  90834. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  90835. }
  90836. #endif
  90837. return true;
  90838. }
  90839. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value)
  90840. {
  90841. FLAC__ASSERT(0 != encoder);
  90842. FLAC__ASSERT(0 != encoder->private_);
  90843. FLAC__ASSERT(0 != encoder->protected_);
  90844. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90845. return false;
  90846. encoder->protected_->max_lpc_order = value;
  90847. return true;
  90848. }
  90849. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value)
  90850. {
  90851. FLAC__ASSERT(0 != encoder);
  90852. FLAC__ASSERT(0 != encoder->private_);
  90853. FLAC__ASSERT(0 != encoder->protected_);
  90854. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90855. return false;
  90856. encoder->protected_->qlp_coeff_precision = value;
  90857. return true;
  90858. }
  90859. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90860. {
  90861. FLAC__ASSERT(0 != encoder);
  90862. FLAC__ASSERT(0 != encoder->private_);
  90863. FLAC__ASSERT(0 != encoder->protected_);
  90864. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90865. return false;
  90866. encoder->protected_->do_qlp_coeff_prec_search = value;
  90867. return true;
  90868. }
  90869. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90870. {
  90871. FLAC__ASSERT(0 != encoder);
  90872. FLAC__ASSERT(0 != encoder->private_);
  90873. FLAC__ASSERT(0 != encoder->protected_);
  90874. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90875. return false;
  90876. #if 0
  90877. encoder->protected_->do_escape_coding = value;
  90878. #else
  90879. (void)value;
  90880. #endif
  90881. return true;
  90882. }
  90883. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90884. {
  90885. FLAC__ASSERT(0 != encoder);
  90886. FLAC__ASSERT(0 != encoder->private_);
  90887. FLAC__ASSERT(0 != encoder->protected_);
  90888. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90889. return false;
  90890. encoder->protected_->do_exhaustive_model_search = value;
  90891. return true;
  90892. }
  90893. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  90894. {
  90895. FLAC__ASSERT(0 != encoder);
  90896. FLAC__ASSERT(0 != encoder->private_);
  90897. FLAC__ASSERT(0 != encoder->protected_);
  90898. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90899. return false;
  90900. encoder->protected_->min_residual_partition_order = value;
  90901. return true;
  90902. }
  90903. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  90904. {
  90905. FLAC__ASSERT(0 != encoder);
  90906. FLAC__ASSERT(0 != encoder->private_);
  90907. FLAC__ASSERT(0 != encoder->protected_);
  90908. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90909. return false;
  90910. encoder->protected_->max_residual_partition_order = value;
  90911. return true;
  90912. }
  90913. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value)
  90914. {
  90915. FLAC__ASSERT(0 != encoder);
  90916. FLAC__ASSERT(0 != encoder->private_);
  90917. FLAC__ASSERT(0 != encoder->protected_);
  90918. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90919. return false;
  90920. #if 0
  90921. encoder->protected_->rice_parameter_search_dist = value;
  90922. #else
  90923. (void)value;
  90924. #endif
  90925. return true;
  90926. }
  90927. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value)
  90928. {
  90929. FLAC__ASSERT(0 != encoder);
  90930. FLAC__ASSERT(0 != encoder->private_);
  90931. FLAC__ASSERT(0 != encoder->protected_);
  90932. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90933. return false;
  90934. encoder->protected_->total_samples_estimate = value;
  90935. return true;
  90936. }
  90937. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks)
  90938. {
  90939. FLAC__ASSERT(0 != encoder);
  90940. FLAC__ASSERT(0 != encoder->private_);
  90941. FLAC__ASSERT(0 != encoder->protected_);
  90942. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90943. return false;
  90944. if(0 == metadata)
  90945. num_blocks = 0;
  90946. if(0 == num_blocks)
  90947. metadata = 0;
  90948. if(encoder->protected_->metadata) {
  90949. free(encoder->protected_->metadata);
  90950. encoder->protected_->metadata = 0;
  90951. encoder->protected_->num_metadata_blocks = 0;
  90952. }
  90953. if(num_blocks) {
  90954. FLAC__StreamMetadata **m;
  90955. if(0 == (m = (FLAC__StreamMetadata**)safe_malloc_mul_2op_(sizeof(m[0]), /*times*/num_blocks)))
  90956. return false;
  90957. memcpy(m, metadata, sizeof(m[0]) * num_blocks);
  90958. encoder->protected_->metadata = m;
  90959. encoder->protected_->num_metadata_blocks = num_blocks;
  90960. }
  90961. #if FLAC__HAS_OGG
  90962. if(!FLAC__ogg_encoder_aspect_set_num_metadata(&encoder->protected_->ogg_encoder_aspect, num_blocks))
  90963. return false;
  90964. #endif
  90965. return true;
  90966. }
  90967. FLAC_API FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90968. {
  90969. FLAC__ASSERT(0 != encoder);
  90970. FLAC__ASSERT(0 != encoder->private_);
  90971. FLAC__ASSERT(0 != encoder->protected_);
  90972. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90973. return false;
  90974. encoder->private_->disable_constant_subframes = value;
  90975. return true;
  90976. }
  90977. FLAC_API FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90978. {
  90979. FLAC__ASSERT(0 != encoder);
  90980. FLAC__ASSERT(0 != encoder->private_);
  90981. FLAC__ASSERT(0 != encoder->protected_);
  90982. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90983. return false;
  90984. encoder->private_->disable_fixed_subframes = value;
  90985. return true;
  90986. }
  90987. FLAC_API FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90988. {
  90989. FLAC__ASSERT(0 != encoder);
  90990. FLAC__ASSERT(0 != encoder->private_);
  90991. FLAC__ASSERT(0 != encoder->protected_);
  90992. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90993. return false;
  90994. encoder->private_->disable_verbatim_subframes = value;
  90995. return true;
  90996. }
  90997. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder)
  90998. {
  90999. FLAC__ASSERT(0 != encoder);
  91000. FLAC__ASSERT(0 != encoder->private_);
  91001. FLAC__ASSERT(0 != encoder->protected_);
  91002. return encoder->protected_->state;
  91003. }
  91004. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder)
  91005. {
  91006. FLAC__ASSERT(0 != encoder);
  91007. FLAC__ASSERT(0 != encoder->private_);
  91008. FLAC__ASSERT(0 != encoder->protected_);
  91009. if(encoder->protected_->verify)
  91010. return FLAC__stream_decoder_get_state(encoder->private_->verify.decoder);
  91011. else
  91012. return FLAC__STREAM_DECODER_UNINITIALIZED;
  91013. }
  91014. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder)
  91015. {
  91016. FLAC__ASSERT(0 != encoder);
  91017. FLAC__ASSERT(0 != encoder->private_);
  91018. FLAC__ASSERT(0 != encoder->protected_);
  91019. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR)
  91020. return FLAC__StreamEncoderStateString[encoder->protected_->state];
  91021. else
  91022. return FLAC__stream_decoder_get_resolved_state_string(encoder->private_->verify.decoder);
  91023. }
  91024. 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)
  91025. {
  91026. FLAC__ASSERT(0 != encoder);
  91027. FLAC__ASSERT(0 != encoder->private_);
  91028. FLAC__ASSERT(0 != encoder->protected_);
  91029. if(0 != absolute_sample)
  91030. *absolute_sample = encoder->private_->verify.error_stats.absolute_sample;
  91031. if(0 != frame_number)
  91032. *frame_number = encoder->private_->verify.error_stats.frame_number;
  91033. if(0 != channel)
  91034. *channel = encoder->private_->verify.error_stats.channel;
  91035. if(0 != sample)
  91036. *sample = encoder->private_->verify.error_stats.sample;
  91037. if(0 != expected)
  91038. *expected = encoder->private_->verify.error_stats.expected;
  91039. if(0 != got)
  91040. *got = encoder->private_->verify.error_stats.got;
  91041. }
  91042. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder)
  91043. {
  91044. FLAC__ASSERT(0 != encoder);
  91045. FLAC__ASSERT(0 != encoder->private_);
  91046. FLAC__ASSERT(0 != encoder->protected_);
  91047. return encoder->protected_->verify;
  91048. }
  91049. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder)
  91050. {
  91051. FLAC__ASSERT(0 != encoder);
  91052. FLAC__ASSERT(0 != encoder->private_);
  91053. FLAC__ASSERT(0 != encoder->protected_);
  91054. return encoder->protected_->streamable_subset;
  91055. }
  91056. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_md5(const FLAC__StreamEncoder *encoder)
  91057. {
  91058. FLAC__ASSERT(0 != encoder);
  91059. FLAC__ASSERT(0 != encoder->private_);
  91060. FLAC__ASSERT(0 != encoder->protected_);
  91061. return encoder->protected_->do_md5;
  91062. }
  91063. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder)
  91064. {
  91065. FLAC__ASSERT(0 != encoder);
  91066. FLAC__ASSERT(0 != encoder->private_);
  91067. FLAC__ASSERT(0 != encoder->protected_);
  91068. return encoder->protected_->channels;
  91069. }
  91070. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder)
  91071. {
  91072. FLAC__ASSERT(0 != encoder);
  91073. FLAC__ASSERT(0 != encoder->private_);
  91074. FLAC__ASSERT(0 != encoder->protected_);
  91075. return encoder->protected_->bits_per_sample;
  91076. }
  91077. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder)
  91078. {
  91079. FLAC__ASSERT(0 != encoder);
  91080. FLAC__ASSERT(0 != encoder->private_);
  91081. FLAC__ASSERT(0 != encoder->protected_);
  91082. return encoder->protected_->sample_rate;
  91083. }
  91084. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder)
  91085. {
  91086. FLAC__ASSERT(0 != encoder);
  91087. FLAC__ASSERT(0 != encoder->private_);
  91088. FLAC__ASSERT(0 != encoder->protected_);
  91089. return encoder->protected_->blocksize;
  91090. }
  91091. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91092. {
  91093. FLAC__ASSERT(0 != encoder);
  91094. FLAC__ASSERT(0 != encoder->private_);
  91095. FLAC__ASSERT(0 != encoder->protected_);
  91096. return encoder->protected_->do_mid_side_stereo;
  91097. }
  91098. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91099. {
  91100. FLAC__ASSERT(0 != encoder);
  91101. FLAC__ASSERT(0 != encoder->private_);
  91102. FLAC__ASSERT(0 != encoder->protected_);
  91103. return encoder->protected_->loose_mid_side_stereo;
  91104. }
  91105. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder)
  91106. {
  91107. FLAC__ASSERT(0 != encoder);
  91108. FLAC__ASSERT(0 != encoder->private_);
  91109. FLAC__ASSERT(0 != encoder->protected_);
  91110. return encoder->protected_->max_lpc_order;
  91111. }
  91112. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder)
  91113. {
  91114. FLAC__ASSERT(0 != encoder);
  91115. FLAC__ASSERT(0 != encoder->private_);
  91116. FLAC__ASSERT(0 != encoder->protected_);
  91117. return encoder->protected_->qlp_coeff_precision;
  91118. }
  91119. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder)
  91120. {
  91121. FLAC__ASSERT(0 != encoder);
  91122. FLAC__ASSERT(0 != encoder->private_);
  91123. FLAC__ASSERT(0 != encoder->protected_);
  91124. return encoder->protected_->do_qlp_coeff_prec_search;
  91125. }
  91126. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder)
  91127. {
  91128. FLAC__ASSERT(0 != encoder);
  91129. FLAC__ASSERT(0 != encoder->private_);
  91130. FLAC__ASSERT(0 != encoder->protected_);
  91131. return encoder->protected_->do_escape_coding;
  91132. }
  91133. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder)
  91134. {
  91135. FLAC__ASSERT(0 != encoder);
  91136. FLAC__ASSERT(0 != encoder->private_);
  91137. FLAC__ASSERT(0 != encoder->protected_);
  91138. return encoder->protected_->do_exhaustive_model_search;
  91139. }
  91140. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91141. {
  91142. FLAC__ASSERT(0 != encoder);
  91143. FLAC__ASSERT(0 != encoder->private_);
  91144. FLAC__ASSERT(0 != encoder->protected_);
  91145. return encoder->protected_->min_residual_partition_order;
  91146. }
  91147. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91148. {
  91149. FLAC__ASSERT(0 != encoder);
  91150. FLAC__ASSERT(0 != encoder->private_);
  91151. FLAC__ASSERT(0 != encoder->protected_);
  91152. return encoder->protected_->max_residual_partition_order;
  91153. }
  91154. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder)
  91155. {
  91156. FLAC__ASSERT(0 != encoder);
  91157. FLAC__ASSERT(0 != encoder->private_);
  91158. FLAC__ASSERT(0 != encoder->protected_);
  91159. return encoder->protected_->rice_parameter_search_dist;
  91160. }
  91161. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder)
  91162. {
  91163. FLAC__ASSERT(0 != encoder);
  91164. FLAC__ASSERT(0 != encoder->private_);
  91165. FLAC__ASSERT(0 != encoder->protected_);
  91166. return encoder->protected_->total_samples_estimate;
  91167. }
  91168. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples)
  91169. {
  91170. unsigned i, j = 0, channel;
  91171. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91172. FLAC__ASSERT(0 != encoder);
  91173. FLAC__ASSERT(0 != encoder->private_);
  91174. FLAC__ASSERT(0 != encoder->protected_);
  91175. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91176. do {
  91177. const unsigned n = min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j);
  91178. if(encoder->protected_->verify)
  91179. append_to_verify_fifo_(&encoder->private_->verify.input_fifo, buffer, j, channels, n);
  91180. for(channel = 0; channel < channels; channel++)
  91181. memcpy(&encoder->private_->integer_signal[channel][encoder->private_->current_sample_number], &buffer[channel][j], sizeof(buffer[channel][0]) * n);
  91182. if(encoder->protected_->do_mid_side_stereo) {
  91183. FLAC__ASSERT(channels == 2);
  91184. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91185. encoder->private_->integer_signal_mid_side[1][i] = buffer[0][j] - buffer[1][j];
  91186. 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' ! */
  91187. }
  91188. }
  91189. else
  91190. j += n;
  91191. encoder->private_->current_sample_number += n;
  91192. if(encoder->private_->current_sample_number > blocksize) {
  91193. FLAC__ASSERT(encoder->private_->current_sample_number == blocksize+OVERREAD_);
  91194. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91195. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91196. return false;
  91197. for(channel = 0; channel < channels; channel++)
  91198. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91199. if(encoder->protected_->do_mid_side_stereo) {
  91200. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91201. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91202. }
  91203. encoder->private_->current_sample_number = 1;
  91204. }
  91205. } while(j < samples);
  91206. return true;
  91207. }
  91208. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples)
  91209. {
  91210. unsigned i, j, k, channel;
  91211. FLAC__int32 x, mid, side;
  91212. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91213. FLAC__ASSERT(0 != encoder);
  91214. FLAC__ASSERT(0 != encoder->private_);
  91215. FLAC__ASSERT(0 != encoder->protected_);
  91216. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91217. j = k = 0;
  91218. if(encoder->protected_->do_mid_side_stereo && channels == 2) {
  91219. do {
  91220. if(encoder->protected_->verify)
  91221. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91222. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91223. encoder->private_->integer_signal[0][i] = mid = side = buffer[k++];
  91224. x = buffer[k++];
  91225. encoder->private_->integer_signal[1][i] = x;
  91226. mid += x;
  91227. side -= x;
  91228. mid >>= 1; /* NOTE: not the same as 'mid = (left + right) / 2' ! */
  91229. encoder->private_->integer_signal_mid_side[1][i] = side;
  91230. encoder->private_->integer_signal_mid_side[0][i] = mid;
  91231. }
  91232. encoder->private_->current_sample_number = i;
  91233. if(i > blocksize) {
  91234. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91235. return false;
  91236. /* move unprocessed overread samples to beginnings of arrays */
  91237. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91238. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91239. encoder->private_->integer_signal[0][0] = encoder->private_->integer_signal[0][blocksize];
  91240. encoder->private_->integer_signal[1][0] = encoder->private_->integer_signal[1][blocksize];
  91241. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91242. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91243. encoder->private_->current_sample_number = 1;
  91244. }
  91245. } while(j < samples);
  91246. }
  91247. else {
  91248. do {
  91249. if(encoder->protected_->verify)
  91250. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91251. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91252. for(channel = 0; channel < channels; channel++)
  91253. encoder->private_->integer_signal[channel][i] = buffer[k++];
  91254. }
  91255. encoder->private_->current_sample_number = i;
  91256. if(i > blocksize) {
  91257. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91258. return false;
  91259. /* move unprocessed overread samples to beginnings of arrays */
  91260. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91261. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91262. for(channel = 0; channel < channels; channel++)
  91263. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91264. encoder->private_->current_sample_number = 1;
  91265. }
  91266. } while(j < samples);
  91267. }
  91268. return true;
  91269. }
  91270. void set_defaults_enc(FLAC__StreamEncoder *encoder)
  91271. {
  91272. FLAC__ASSERT(0 != encoder);
  91273. #ifdef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  91274. encoder->protected_->verify = true;
  91275. #else
  91276. encoder->protected_->verify = false;
  91277. #endif
  91278. encoder->protected_->streamable_subset = true;
  91279. encoder->protected_->do_md5 = true;
  91280. encoder->protected_->do_mid_side_stereo = false;
  91281. encoder->protected_->loose_mid_side_stereo = false;
  91282. encoder->protected_->channels = 2;
  91283. encoder->protected_->bits_per_sample = 16;
  91284. encoder->protected_->sample_rate = 44100;
  91285. encoder->protected_->blocksize = 0;
  91286. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91287. encoder->protected_->num_apodizations = 1;
  91288. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91289. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91290. #endif
  91291. encoder->protected_->max_lpc_order = 0;
  91292. encoder->protected_->qlp_coeff_precision = 0;
  91293. encoder->protected_->do_qlp_coeff_prec_search = false;
  91294. encoder->protected_->do_exhaustive_model_search = false;
  91295. encoder->protected_->do_escape_coding = false;
  91296. encoder->protected_->min_residual_partition_order = 0;
  91297. encoder->protected_->max_residual_partition_order = 0;
  91298. encoder->protected_->rice_parameter_search_dist = 0;
  91299. encoder->protected_->total_samples_estimate = 0;
  91300. encoder->protected_->metadata = 0;
  91301. encoder->protected_->num_metadata_blocks = 0;
  91302. encoder->private_->seek_table = 0;
  91303. encoder->private_->disable_constant_subframes = false;
  91304. encoder->private_->disable_fixed_subframes = false;
  91305. encoder->private_->disable_verbatim_subframes = false;
  91306. #if FLAC__HAS_OGG
  91307. encoder->private_->is_ogg = false;
  91308. #endif
  91309. encoder->private_->read_callback = 0;
  91310. encoder->private_->write_callback = 0;
  91311. encoder->private_->seek_callback = 0;
  91312. encoder->private_->tell_callback = 0;
  91313. encoder->private_->metadata_callback = 0;
  91314. encoder->private_->progress_callback = 0;
  91315. encoder->private_->client_data = 0;
  91316. #if FLAC__HAS_OGG
  91317. FLAC__ogg_encoder_aspect_set_defaults(&encoder->protected_->ogg_encoder_aspect);
  91318. #endif
  91319. }
  91320. void free_(FLAC__StreamEncoder *encoder)
  91321. {
  91322. unsigned i, channel;
  91323. FLAC__ASSERT(0 != encoder);
  91324. if(encoder->protected_->metadata) {
  91325. free(encoder->protected_->metadata);
  91326. encoder->protected_->metadata = 0;
  91327. encoder->protected_->num_metadata_blocks = 0;
  91328. }
  91329. for(i = 0; i < encoder->protected_->channels; i++) {
  91330. if(0 != encoder->private_->integer_signal_unaligned[i]) {
  91331. free(encoder->private_->integer_signal_unaligned[i]);
  91332. encoder->private_->integer_signal_unaligned[i] = 0;
  91333. }
  91334. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91335. if(0 != encoder->private_->real_signal_unaligned[i]) {
  91336. free(encoder->private_->real_signal_unaligned[i]);
  91337. encoder->private_->real_signal_unaligned[i] = 0;
  91338. }
  91339. #endif
  91340. }
  91341. for(i = 0; i < 2; i++) {
  91342. if(0 != encoder->private_->integer_signal_mid_side_unaligned[i]) {
  91343. free(encoder->private_->integer_signal_mid_side_unaligned[i]);
  91344. encoder->private_->integer_signal_mid_side_unaligned[i] = 0;
  91345. }
  91346. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91347. if(0 != encoder->private_->real_signal_mid_side_unaligned[i]) {
  91348. free(encoder->private_->real_signal_mid_side_unaligned[i]);
  91349. encoder->private_->real_signal_mid_side_unaligned[i] = 0;
  91350. }
  91351. #endif
  91352. }
  91353. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91354. for(i = 0; i < encoder->protected_->num_apodizations; i++) {
  91355. if(0 != encoder->private_->window_unaligned[i]) {
  91356. free(encoder->private_->window_unaligned[i]);
  91357. encoder->private_->window_unaligned[i] = 0;
  91358. }
  91359. }
  91360. if(0 != encoder->private_->windowed_signal_unaligned) {
  91361. free(encoder->private_->windowed_signal_unaligned);
  91362. encoder->private_->windowed_signal_unaligned = 0;
  91363. }
  91364. #endif
  91365. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91366. for(i = 0; i < 2; i++) {
  91367. if(0 != encoder->private_->residual_workspace_unaligned[channel][i]) {
  91368. free(encoder->private_->residual_workspace_unaligned[channel][i]);
  91369. encoder->private_->residual_workspace_unaligned[channel][i] = 0;
  91370. }
  91371. }
  91372. }
  91373. for(channel = 0; channel < 2; channel++) {
  91374. for(i = 0; i < 2; i++) {
  91375. if(0 != encoder->private_->residual_workspace_mid_side_unaligned[channel][i]) {
  91376. free(encoder->private_->residual_workspace_mid_side_unaligned[channel][i]);
  91377. encoder->private_->residual_workspace_mid_side_unaligned[channel][i] = 0;
  91378. }
  91379. }
  91380. }
  91381. if(0 != encoder->private_->abs_residual_partition_sums_unaligned) {
  91382. free(encoder->private_->abs_residual_partition_sums_unaligned);
  91383. encoder->private_->abs_residual_partition_sums_unaligned = 0;
  91384. }
  91385. if(0 != encoder->private_->raw_bits_per_partition_unaligned) {
  91386. free(encoder->private_->raw_bits_per_partition_unaligned);
  91387. encoder->private_->raw_bits_per_partition_unaligned = 0;
  91388. }
  91389. if(encoder->protected_->verify) {
  91390. for(i = 0; i < encoder->protected_->channels; i++) {
  91391. if(0 != encoder->private_->verify.input_fifo.data[i]) {
  91392. free(encoder->private_->verify.input_fifo.data[i]);
  91393. encoder->private_->verify.input_fifo.data[i] = 0;
  91394. }
  91395. }
  91396. }
  91397. FLAC__bitwriter_free(encoder->private_->frame);
  91398. }
  91399. FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize)
  91400. {
  91401. FLAC__bool ok;
  91402. unsigned i, channel;
  91403. FLAC__ASSERT(new_blocksize > 0);
  91404. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91405. FLAC__ASSERT(encoder->private_->current_sample_number == 0);
  91406. if(new_blocksize <= encoder->private_->input_capacity)
  91407. return true;
  91408. ok = true;
  91409. for(i = 0; ok && i < encoder->protected_->channels; i++) {
  91410. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_unaligned[i], &encoder->private_->integer_signal[i]);
  91411. memset(encoder->private_->integer_signal[i], 0, sizeof(FLAC__int32)*4);
  91412. encoder->private_->integer_signal[i] += 4;
  91413. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91414. #if 0 /* @@@ currently unused */
  91415. if(encoder->protected_->max_lpc_order > 0)
  91416. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize+OVERREAD_, &encoder->private_->real_signal_unaligned[i], &encoder->private_->real_signal[i]);
  91417. #endif
  91418. #endif
  91419. }
  91420. for(i = 0; ok && i < 2; i++) {
  91421. 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]);
  91422. memset(encoder->private_->integer_signal_mid_side[i], 0, sizeof(FLAC__int32)*4);
  91423. encoder->private_->integer_signal_mid_side[i] += 4;
  91424. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91425. #if 0 /* @@@ currently unused */
  91426. if(encoder->protected_->max_lpc_order > 0)
  91427. 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]);
  91428. #endif
  91429. #endif
  91430. }
  91431. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91432. if(ok && encoder->protected_->max_lpc_order > 0) {
  91433. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++)
  91434. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->window_unaligned[i], &encoder->private_->window[i]);
  91435. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->windowed_signal_unaligned, &encoder->private_->windowed_signal);
  91436. }
  91437. #endif
  91438. for(channel = 0; ok && channel < encoder->protected_->channels; channel++) {
  91439. for(i = 0; ok && i < 2; i++) {
  91440. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize, &encoder->private_->residual_workspace_unaligned[channel][i], &encoder->private_->residual_workspace[channel][i]);
  91441. }
  91442. }
  91443. for(channel = 0; ok && channel < 2; channel++) {
  91444. for(i = 0; ok && i < 2; i++) {
  91445. 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]);
  91446. }
  91447. }
  91448. ok = ok && FLAC__memory_alloc_aligned_uint64_array(new_blocksize * 2, &encoder->private_->abs_residual_partition_sums_unaligned, &encoder->private_->abs_residual_partition_sums);
  91449. if(encoder->protected_->do_escape_coding)
  91450. ok = ok && FLAC__memory_alloc_aligned_unsigned_array(new_blocksize * 2, &encoder->private_->raw_bits_per_partition_unaligned, &encoder->private_->raw_bits_per_partition);
  91451. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91452. if(ok && new_blocksize != encoder->private_->input_capacity && encoder->protected_->max_lpc_order > 0) {
  91453. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++) {
  91454. switch(encoder->protected_->apodizations[i].type) {
  91455. case FLAC__APODIZATION_BARTLETT:
  91456. FLAC__window_bartlett(encoder->private_->window[i], new_blocksize);
  91457. break;
  91458. case FLAC__APODIZATION_BARTLETT_HANN:
  91459. FLAC__window_bartlett_hann(encoder->private_->window[i], new_blocksize);
  91460. break;
  91461. case FLAC__APODIZATION_BLACKMAN:
  91462. FLAC__window_blackman(encoder->private_->window[i], new_blocksize);
  91463. break;
  91464. case FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE:
  91465. FLAC__window_blackman_harris_4term_92db_sidelobe(encoder->private_->window[i], new_blocksize);
  91466. break;
  91467. case FLAC__APODIZATION_CONNES:
  91468. FLAC__window_connes(encoder->private_->window[i], new_blocksize);
  91469. break;
  91470. case FLAC__APODIZATION_FLATTOP:
  91471. FLAC__window_flattop(encoder->private_->window[i], new_blocksize);
  91472. break;
  91473. case FLAC__APODIZATION_GAUSS:
  91474. FLAC__window_gauss(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.gauss.stddev);
  91475. break;
  91476. case FLAC__APODIZATION_HAMMING:
  91477. FLAC__window_hamming(encoder->private_->window[i], new_blocksize);
  91478. break;
  91479. case FLAC__APODIZATION_HANN:
  91480. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91481. break;
  91482. case FLAC__APODIZATION_KAISER_BESSEL:
  91483. FLAC__window_kaiser_bessel(encoder->private_->window[i], new_blocksize);
  91484. break;
  91485. case FLAC__APODIZATION_NUTTALL:
  91486. FLAC__window_nuttall(encoder->private_->window[i], new_blocksize);
  91487. break;
  91488. case FLAC__APODIZATION_RECTANGLE:
  91489. FLAC__window_rectangle(encoder->private_->window[i], new_blocksize);
  91490. break;
  91491. case FLAC__APODIZATION_TRIANGLE:
  91492. FLAC__window_triangle(encoder->private_->window[i], new_blocksize);
  91493. break;
  91494. case FLAC__APODIZATION_TUKEY:
  91495. FLAC__window_tukey(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.tukey.p);
  91496. break;
  91497. case FLAC__APODIZATION_WELCH:
  91498. FLAC__window_welch(encoder->private_->window[i], new_blocksize);
  91499. break;
  91500. default:
  91501. FLAC__ASSERT(0);
  91502. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91503. break;
  91504. }
  91505. }
  91506. }
  91507. #endif
  91508. if(ok)
  91509. encoder->private_->input_capacity = new_blocksize;
  91510. else
  91511. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91512. return ok;
  91513. }
  91514. FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block)
  91515. {
  91516. const FLAC__byte *buffer;
  91517. size_t bytes;
  91518. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  91519. if(!FLAC__bitwriter_get_buffer(encoder->private_->frame, &buffer, &bytes)) {
  91520. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91521. return false;
  91522. }
  91523. if(encoder->protected_->verify) {
  91524. encoder->private_->verify.output.data = buffer;
  91525. encoder->private_->verify.output.bytes = bytes;
  91526. if(encoder->private_->verify.state_hint == ENCODER_IN_MAGIC) {
  91527. encoder->private_->verify.needs_magic_hack = true;
  91528. }
  91529. else {
  91530. if(!FLAC__stream_decoder_process_single(encoder->private_->verify.decoder)) {
  91531. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91532. FLAC__bitwriter_clear(encoder->private_->frame);
  91533. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA)
  91534. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  91535. return false;
  91536. }
  91537. }
  91538. }
  91539. if(write_frame_(encoder, buffer, bytes, samples, is_last_block) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91540. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91541. FLAC__bitwriter_clear(encoder->private_->frame);
  91542. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91543. return false;
  91544. }
  91545. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91546. FLAC__bitwriter_clear(encoder->private_->frame);
  91547. if(samples > 0) {
  91548. encoder->private_->streaminfo.data.stream_info.min_framesize = min(bytes, encoder->private_->streaminfo.data.stream_info.min_framesize);
  91549. encoder->private_->streaminfo.data.stream_info.max_framesize = max(bytes, encoder->private_->streaminfo.data.stream_info.max_framesize);
  91550. }
  91551. return true;
  91552. }
  91553. FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block)
  91554. {
  91555. FLAC__StreamEncoderWriteStatus status;
  91556. FLAC__uint64 output_position = 0;
  91557. if(encoder->private_->tell_callback && encoder->private_->tell_callback(encoder, &output_position, encoder->private_->client_data) == FLAC__STREAM_ENCODER_TELL_STATUS_ERROR) {
  91558. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91559. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  91560. }
  91561. if(samples == 0) {
  91562. FLAC__MetadataType type = (FLAC__MetadataType) (buffer[0] & 0x7f);
  91563. if(type == FLAC__METADATA_TYPE_STREAMINFO)
  91564. encoder->protected_->streaminfo_offset = output_position;
  91565. else if(type == FLAC__METADATA_TYPE_SEEKTABLE && encoder->protected_->seektable_offset == 0)
  91566. encoder->protected_->seektable_offset = output_position;
  91567. }
  91568. if(0 != encoder->private_->seek_table && encoder->protected_->audio_offset > 0 && encoder->private_->seek_table->num_points > 0) {
  91569. const unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  91570. const FLAC__uint64 frame_first_sample = encoder->private_->samples_written;
  91571. const FLAC__uint64 frame_last_sample = frame_first_sample + (FLAC__uint64)blocksize - 1;
  91572. FLAC__uint64 test_sample;
  91573. unsigned i;
  91574. for(i = encoder->private_->first_seekpoint_to_check; i < encoder->private_->seek_table->num_points; i++) {
  91575. test_sample = encoder->private_->seek_table->points[i].sample_number;
  91576. if(test_sample > frame_last_sample) {
  91577. break;
  91578. }
  91579. else if(test_sample >= frame_first_sample) {
  91580. encoder->private_->seek_table->points[i].sample_number = frame_first_sample;
  91581. encoder->private_->seek_table->points[i].stream_offset = output_position - encoder->protected_->audio_offset;
  91582. encoder->private_->seek_table->points[i].frame_samples = blocksize;
  91583. encoder->private_->first_seekpoint_to_check++;
  91584. }
  91585. else {
  91586. encoder->private_->first_seekpoint_to_check++;
  91587. }
  91588. }
  91589. }
  91590. #if FLAC__HAS_OGG
  91591. if(encoder->private_->is_ogg) {
  91592. status = FLAC__ogg_encoder_aspect_write_callback_wrapper(
  91593. &encoder->protected_->ogg_encoder_aspect,
  91594. buffer,
  91595. bytes,
  91596. samples,
  91597. encoder->private_->current_frame_number,
  91598. is_last_block,
  91599. (FLAC__OggEncoderAspectWriteCallbackProxy)encoder->private_->write_callback,
  91600. encoder,
  91601. encoder->private_->client_data
  91602. );
  91603. }
  91604. else
  91605. #endif
  91606. status = encoder->private_->write_callback(encoder, buffer, bytes, samples, encoder->private_->current_frame_number, encoder->private_->client_data);
  91607. if(status == FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91608. encoder->private_->bytes_written += bytes;
  91609. encoder->private_->samples_written += samples;
  91610. encoder->private_->frames_written = max(encoder->private_->frames_written, encoder->private_->current_frame_number+1);
  91611. }
  91612. else
  91613. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91614. return status;
  91615. }
  91616. void update_metadata_(const FLAC__StreamEncoder *encoder)
  91617. {
  91618. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  91619. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  91620. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  91621. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  91622. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  91623. const unsigned bps = metadata->data.stream_info.bits_per_sample;
  91624. FLAC__StreamEncoderSeekStatus seek_status;
  91625. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  91626. {
  91627. const unsigned md5_offset =
  91628. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91629. (
  91630. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91631. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91632. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91633. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91634. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91635. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91636. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  91637. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  91638. ) / 8;
  91639. if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + md5_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
  91640. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91641. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91642. return;
  91643. }
  91644. if(encoder->private_->write_callback(encoder, metadata->data.stream_info.md5sum, 16, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91645. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91646. return;
  91647. }
  91648. }
  91649. {
  91650. const unsigned total_samples_byte_offset =
  91651. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91652. (
  91653. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91654. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91655. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91656. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91657. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91658. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91659. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  91660. - 4
  91661. ) / 8;
  91662. b[0] = ((FLAC__byte)(bps-1) << 4) | (FLAC__byte)((samples >> 32) & 0x0F);
  91663. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  91664. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  91665. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  91666. b[4] = (FLAC__byte)(samples & 0xFF);
  91667. 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) {
  91668. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91669. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91670. return;
  91671. }
  91672. if(encoder->private_->write_callback(encoder, b, 5, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91673. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91674. return;
  91675. }
  91676. }
  91677. {
  91678. const unsigned min_framesize_offset =
  91679. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91680. (
  91681. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91682. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  91683. ) / 8;
  91684. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  91685. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  91686. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  91687. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  91688. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  91689. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  91690. 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) {
  91691. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91692. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91693. return;
  91694. }
  91695. if(encoder->private_->write_callback(encoder, b, 6, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91696. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91697. return;
  91698. }
  91699. }
  91700. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  91701. unsigned i;
  91702. FLAC__format_seektable_sort(encoder->private_->seek_table);
  91703. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  91704. 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) {
  91705. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91706. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91707. return;
  91708. }
  91709. for(i = 0; i < encoder->private_->seek_table->num_points; i++) {
  91710. FLAC__uint64 xx;
  91711. unsigned x;
  91712. xx = encoder->private_->seek_table->points[i].sample_number;
  91713. b[7] = (FLAC__byte)xx; xx >>= 8;
  91714. b[6] = (FLAC__byte)xx; xx >>= 8;
  91715. b[5] = (FLAC__byte)xx; xx >>= 8;
  91716. b[4] = (FLAC__byte)xx; xx >>= 8;
  91717. b[3] = (FLAC__byte)xx; xx >>= 8;
  91718. b[2] = (FLAC__byte)xx; xx >>= 8;
  91719. b[1] = (FLAC__byte)xx; xx >>= 8;
  91720. b[0] = (FLAC__byte)xx; xx >>= 8;
  91721. xx = encoder->private_->seek_table->points[i].stream_offset;
  91722. b[15] = (FLAC__byte)xx; xx >>= 8;
  91723. b[14] = (FLAC__byte)xx; xx >>= 8;
  91724. b[13] = (FLAC__byte)xx; xx >>= 8;
  91725. b[12] = (FLAC__byte)xx; xx >>= 8;
  91726. b[11] = (FLAC__byte)xx; xx >>= 8;
  91727. b[10] = (FLAC__byte)xx; xx >>= 8;
  91728. b[9] = (FLAC__byte)xx; xx >>= 8;
  91729. b[8] = (FLAC__byte)xx; xx >>= 8;
  91730. x = encoder->private_->seek_table->points[i].frame_samples;
  91731. b[17] = (FLAC__byte)x; x >>= 8;
  91732. b[16] = (FLAC__byte)x; x >>= 8;
  91733. if(encoder->private_->write_callback(encoder, b, 18, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91734. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91735. return;
  91736. }
  91737. }
  91738. }
  91739. }
  91740. #if FLAC__HAS_OGG
  91741. void update_ogg_metadata_(FLAC__StreamEncoder *encoder)
  91742. {
  91743. static const unsigned FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH =
  91744. FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH +
  91745. FLAC__OGG_MAPPING_MAGIC_LENGTH +
  91746. FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH +
  91747. FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH +
  91748. FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH +
  91749. FLAC__STREAM_SYNC_LENGTH
  91750. ;
  91751. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  91752. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  91753. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  91754. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  91755. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  91756. ogg_page page;
  91757. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  91758. FLAC__ASSERT(0 != encoder->private_->seek_callback);
  91759. if(encoder->private_->seek_callback(encoder, 0, encoder->private_->client_data) == FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED)
  91760. return;
  91761. simple_ogg_page__init(&page);
  91762. if(!simple_ogg_page__get_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  91763. simple_ogg_page__clear(&page);
  91764. return; /* state already set */
  91765. }
  91766. {
  91767. const unsigned md5_offset =
  91768. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91769. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91770. (
  91771. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91772. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91773. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91774. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91775. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91776. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91777. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  91778. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  91779. ) / 8;
  91780. if(md5_offset + 16 > (unsigned)page.body_len) {
  91781. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91782. simple_ogg_page__clear(&page);
  91783. return;
  91784. }
  91785. memcpy(page.body + md5_offset, metadata->data.stream_info.md5sum, 16);
  91786. }
  91787. {
  91788. const unsigned total_samples_byte_offset =
  91789. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91790. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91791. (
  91792. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91793. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91794. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91795. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91796. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91797. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91798. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  91799. - 4
  91800. ) / 8;
  91801. if(total_samples_byte_offset + 5 > (unsigned)page.body_len) {
  91802. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91803. simple_ogg_page__clear(&page);
  91804. return;
  91805. }
  91806. b[0] = (FLAC__byte)page.body[total_samples_byte_offset] & 0xF0;
  91807. b[0] |= (FLAC__byte)((samples >> 32) & 0x0F);
  91808. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  91809. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  91810. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  91811. b[4] = (FLAC__byte)(samples & 0xFF);
  91812. memcpy(page.body + total_samples_byte_offset, b, 5);
  91813. }
  91814. {
  91815. const unsigned min_framesize_offset =
  91816. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91817. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91818. (
  91819. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91820. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  91821. ) / 8;
  91822. if(min_framesize_offset + 6 > (unsigned)page.body_len) {
  91823. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91824. simple_ogg_page__clear(&page);
  91825. return;
  91826. }
  91827. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  91828. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  91829. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  91830. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  91831. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  91832. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  91833. memcpy(page.body + min_framesize_offset, b, 6);
  91834. }
  91835. if(!simple_ogg_page__set_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  91836. simple_ogg_page__clear(&page);
  91837. return; /* state already set */
  91838. }
  91839. simple_ogg_page__clear(&page);
  91840. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  91841. unsigned i;
  91842. FLAC__byte *p;
  91843. FLAC__format_seektable_sort(encoder->private_->seek_table);
  91844. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  91845. simple_ogg_page__init(&page);
  91846. if(!simple_ogg_page__get_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  91847. simple_ogg_page__clear(&page);
  91848. return; /* state already set */
  91849. }
  91850. if((FLAC__STREAM_METADATA_HEADER_LENGTH + 18*encoder->private_->seek_table->num_points) != (unsigned)page.body_len) {
  91851. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91852. simple_ogg_page__clear(&page);
  91853. return;
  91854. }
  91855. for(i = 0, p = page.body + FLAC__STREAM_METADATA_HEADER_LENGTH; i < encoder->private_->seek_table->num_points; i++, p += 18) {
  91856. FLAC__uint64 xx;
  91857. unsigned x;
  91858. xx = encoder->private_->seek_table->points[i].sample_number;
  91859. b[7] = (FLAC__byte)xx; xx >>= 8;
  91860. b[6] = (FLAC__byte)xx; xx >>= 8;
  91861. b[5] = (FLAC__byte)xx; xx >>= 8;
  91862. b[4] = (FLAC__byte)xx; xx >>= 8;
  91863. b[3] = (FLAC__byte)xx; xx >>= 8;
  91864. b[2] = (FLAC__byte)xx; xx >>= 8;
  91865. b[1] = (FLAC__byte)xx; xx >>= 8;
  91866. b[0] = (FLAC__byte)xx; xx >>= 8;
  91867. xx = encoder->private_->seek_table->points[i].stream_offset;
  91868. b[15] = (FLAC__byte)xx; xx >>= 8;
  91869. b[14] = (FLAC__byte)xx; xx >>= 8;
  91870. b[13] = (FLAC__byte)xx; xx >>= 8;
  91871. b[12] = (FLAC__byte)xx; xx >>= 8;
  91872. b[11] = (FLAC__byte)xx; xx >>= 8;
  91873. b[10] = (FLAC__byte)xx; xx >>= 8;
  91874. b[9] = (FLAC__byte)xx; xx >>= 8;
  91875. b[8] = (FLAC__byte)xx; xx >>= 8;
  91876. x = encoder->private_->seek_table->points[i].frame_samples;
  91877. b[17] = (FLAC__byte)x; x >>= 8;
  91878. b[16] = (FLAC__byte)x; x >>= 8;
  91879. memcpy(p, b, 18);
  91880. }
  91881. if(!simple_ogg_page__set_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  91882. simple_ogg_page__clear(&page);
  91883. return; /* state already set */
  91884. }
  91885. simple_ogg_page__clear(&page);
  91886. }
  91887. }
  91888. #endif
  91889. FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block)
  91890. {
  91891. FLAC__uint16 crc;
  91892. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91893. 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)) {
  91894. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91895. return false;
  91896. }
  91897. if(!process_subframes_(encoder, is_fractional_block)) {
  91898. return false;
  91899. }
  91900. if(!FLAC__bitwriter_zero_pad_to_byte_boundary(encoder->private_->frame)) {
  91901. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91902. return false;
  91903. }
  91904. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  91905. if(
  91906. !FLAC__bitwriter_get_write_crc16(encoder->private_->frame, &crc) ||
  91907. !FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, crc, FLAC__FRAME_FOOTER_CRC_LEN)
  91908. ) {
  91909. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91910. return false;
  91911. }
  91912. if(!write_bitbuffer_(encoder, encoder->protected_->blocksize, is_last_block)) {
  91913. return false;
  91914. }
  91915. encoder->private_->current_sample_number = 0;
  91916. encoder->private_->current_frame_number++;
  91917. encoder->private_->streaminfo.data.stream_info.total_samples += (FLAC__uint64)encoder->protected_->blocksize;
  91918. return true;
  91919. }
  91920. FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block)
  91921. {
  91922. FLAC__FrameHeader frame_header;
  91923. unsigned channel, min_partition_order = encoder->protected_->min_residual_partition_order, max_partition_order;
  91924. FLAC__bool do_independent, do_mid_side;
  91925. if(is_fractional_block) {
  91926. max_partition_order = 0;
  91927. }
  91928. else {
  91929. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize(encoder->protected_->blocksize);
  91930. max_partition_order = min(max_partition_order, encoder->protected_->max_residual_partition_order);
  91931. }
  91932. min_partition_order = min(min_partition_order, max_partition_order);
  91933. frame_header.blocksize = encoder->protected_->blocksize;
  91934. frame_header.sample_rate = encoder->protected_->sample_rate;
  91935. frame_header.channels = encoder->protected_->channels;
  91936. frame_header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT; /* the default unless the encoder determines otherwise */
  91937. frame_header.bits_per_sample = encoder->protected_->bits_per_sample;
  91938. frame_header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  91939. frame_header.number.frame_number = encoder->private_->current_frame_number;
  91940. if(encoder->protected_->do_mid_side_stereo) {
  91941. if(encoder->protected_->loose_mid_side_stereo) {
  91942. if(encoder->private_->loose_mid_side_stereo_frame_count == 0) {
  91943. do_independent = true;
  91944. do_mid_side = true;
  91945. }
  91946. else {
  91947. do_independent = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT);
  91948. do_mid_side = !do_independent;
  91949. }
  91950. }
  91951. else {
  91952. do_independent = true;
  91953. do_mid_side = true;
  91954. }
  91955. }
  91956. else {
  91957. do_independent = true;
  91958. do_mid_side = false;
  91959. }
  91960. FLAC__ASSERT(do_independent || do_mid_side);
  91961. if(do_independent) {
  91962. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91963. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal[channel], encoder->protected_->blocksize);
  91964. encoder->private_->subframe_workspace[channel][0].wasted_bits = encoder->private_->subframe_workspace[channel][1].wasted_bits = w;
  91965. encoder->private_->subframe_bps[channel] = encoder->protected_->bits_per_sample - w;
  91966. }
  91967. }
  91968. if(do_mid_side) {
  91969. FLAC__ASSERT(encoder->protected_->channels == 2);
  91970. for(channel = 0; channel < 2; channel++) {
  91971. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal_mid_side[channel], encoder->protected_->blocksize);
  91972. encoder->private_->subframe_workspace_mid_side[channel][0].wasted_bits = encoder->private_->subframe_workspace_mid_side[channel][1].wasted_bits = w;
  91973. encoder->private_->subframe_bps_mid_side[channel] = encoder->protected_->bits_per_sample - w + (channel==0? 0:1);
  91974. }
  91975. }
  91976. if(do_independent) {
  91977. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91978. if(!
  91979. process_subframe_(
  91980. encoder,
  91981. min_partition_order,
  91982. max_partition_order,
  91983. &frame_header,
  91984. encoder->private_->subframe_bps[channel],
  91985. encoder->private_->integer_signal[channel],
  91986. encoder->private_->subframe_workspace_ptr[channel],
  91987. encoder->private_->partitioned_rice_contents_workspace_ptr[channel],
  91988. encoder->private_->residual_workspace[channel],
  91989. encoder->private_->best_subframe+channel,
  91990. encoder->private_->best_subframe_bits+channel
  91991. )
  91992. )
  91993. return false;
  91994. }
  91995. }
  91996. if(do_mid_side) {
  91997. FLAC__ASSERT(encoder->protected_->channels == 2);
  91998. for(channel = 0; channel < 2; channel++) {
  91999. if(!
  92000. process_subframe_(
  92001. encoder,
  92002. min_partition_order,
  92003. max_partition_order,
  92004. &frame_header,
  92005. encoder->private_->subframe_bps_mid_side[channel],
  92006. encoder->private_->integer_signal_mid_side[channel],
  92007. encoder->private_->subframe_workspace_ptr_mid_side[channel],
  92008. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[channel],
  92009. encoder->private_->residual_workspace_mid_side[channel],
  92010. encoder->private_->best_subframe_mid_side+channel,
  92011. encoder->private_->best_subframe_bits_mid_side+channel
  92012. )
  92013. )
  92014. return false;
  92015. }
  92016. }
  92017. if(do_mid_side) {
  92018. unsigned left_bps = 0, right_bps = 0; /* initialized only to prevent superfluous compiler warning */
  92019. FLAC__Subframe *left_subframe = 0, *right_subframe = 0; /* initialized only to prevent superfluous compiler warning */
  92020. FLAC__ChannelAssignment channel_assignment;
  92021. FLAC__ASSERT(encoder->protected_->channels == 2);
  92022. if(encoder->protected_->loose_mid_side_stereo && encoder->private_->loose_mid_side_stereo_frame_count > 0) {
  92023. channel_assignment = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT? FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT : FLAC__CHANNEL_ASSIGNMENT_MID_SIDE);
  92024. }
  92025. else {
  92026. unsigned bits[4]; /* WATCHOUT - indexed by FLAC__ChannelAssignment */
  92027. unsigned min_bits;
  92028. int ca;
  92029. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT == 0);
  92030. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE == 1);
  92031. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE == 2);
  92032. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_MID_SIDE == 3);
  92033. FLAC__ASSERT(do_independent && do_mid_side);
  92034. bits[FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits [1];
  92035. bits[FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE ] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits_mid_side[1];
  92036. bits[FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE ] = encoder->private_->best_subframe_bits [1] + encoder->private_->best_subframe_bits_mid_side[1];
  92037. bits[FLAC__CHANNEL_ASSIGNMENT_MID_SIDE ] = encoder->private_->best_subframe_bits_mid_side[0] + encoder->private_->best_subframe_bits_mid_side[1];
  92038. channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  92039. min_bits = bits[channel_assignment];
  92040. for(ca = 1; ca <= 3; ca++) {
  92041. if(bits[ca] < min_bits) {
  92042. min_bits = bits[ca];
  92043. channel_assignment = (FLAC__ChannelAssignment)ca;
  92044. }
  92045. }
  92046. }
  92047. frame_header.channel_assignment = channel_assignment;
  92048. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92049. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92050. return false;
  92051. }
  92052. switch(channel_assignment) {
  92053. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92054. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92055. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92056. break;
  92057. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92058. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92059. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92060. break;
  92061. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92062. left_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92063. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92064. break;
  92065. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92066. left_subframe = &encoder->private_->subframe_workspace_mid_side[0][encoder->private_->best_subframe_mid_side[0]];
  92067. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92068. break;
  92069. default:
  92070. FLAC__ASSERT(0);
  92071. }
  92072. switch(channel_assignment) {
  92073. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92074. left_bps = encoder->private_->subframe_bps [0];
  92075. right_bps = encoder->private_->subframe_bps [1];
  92076. break;
  92077. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92078. left_bps = encoder->private_->subframe_bps [0];
  92079. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92080. break;
  92081. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92082. left_bps = encoder->private_->subframe_bps_mid_side[1];
  92083. right_bps = encoder->private_->subframe_bps [1];
  92084. break;
  92085. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92086. left_bps = encoder->private_->subframe_bps_mid_side[0];
  92087. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92088. break;
  92089. default:
  92090. FLAC__ASSERT(0);
  92091. }
  92092. if(!add_subframe_(encoder, frame_header.blocksize, left_bps , left_subframe , encoder->private_->frame))
  92093. return false;
  92094. if(!add_subframe_(encoder, frame_header.blocksize, right_bps, right_subframe, encoder->private_->frame))
  92095. return false;
  92096. }
  92097. else {
  92098. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92099. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92100. return false;
  92101. }
  92102. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92103. 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)) {
  92104. return false;
  92105. }
  92106. }
  92107. }
  92108. if(encoder->protected_->loose_mid_side_stereo) {
  92109. encoder->private_->loose_mid_side_stereo_frame_count++;
  92110. if(encoder->private_->loose_mid_side_stereo_frame_count >= encoder->private_->loose_mid_side_stereo_frames)
  92111. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  92112. }
  92113. encoder->private_->last_channel_assignment = frame_header.channel_assignment;
  92114. return true;
  92115. }
  92116. FLAC__bool process_subframe_(
  92117. FLAC__StreamEncoder *encoder,
  92118. unsigned min_partition_order,
  92119. unsigned max_partition_order,
  92120. const FLAC__FrameHeader *frame_header,
  92121. unsigned subframe_bps,
  92122. const FLAC__int32 integer_signal[],
  92123. FLAC__Subframe *subframe[2],
  92124. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  92125. FLAC__int32 *residual[2],
  92126. unsigned *best_subframe,
  92127. unsigned *best_bits
  92128. )
  92129. {
  92130. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92131. FLAC__float fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92132. #else
  92133. FLAC__fixedpoint fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92134. #endif
  92135. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92136. FLAC__double lpc_residual_bits_per_sample;
  92137. 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 */
  92138. FLAC__double lpc_error[FLAC__MAX_LPC_ORDER];
  92139. unsigned min_lpc_order, max_lpc_order, lpc_order;
  92140. unsigned min_qlp_coeff_precision, max_qlp_coeff_precision, qlp_coeff_precision;
  92141. #endif
  92142. unsigned min_fixed_order, max_fixed_order, guess_fixed_order, fixed_order;
  92143. unsigned rice_parameter;
  92144. unsigned _candidate_bits, _best_bits;
  92145. unsigned _best_subframe;
  92146. 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;
  92147. FLAC__ASSERT(frame_header->blocksize > 0);
  92148. _best_subframe = 0;
  92149. if(encoder->private_->disable_verbatim_subframes && frame_header->blocksize >= FLAC__MAX_FIXED_ORDER)
  92150. _best_bits = UINT_MAX;
  92151. else
  92152. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92153. if(frame_header->blocksize >= FLAC__MAX_FIXED_ORDER) {
  92154. unsigned signal_is_constant = false;
  92155. 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);
  92156. if(
  92157. !encoder->private_->disable_constant_subframes &&
  92158. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92159. fixed_residual_bits_per_sample[1] == 0.0
  92160. #else
  92161. fixed_residual_bits_per_sample[1] == FLAC__FP_ZERO
  92162. #endif
  92163. ) {
  92164. unsigned i;
  92165. signal_is_constant = true;
  92166. for(i = 1; i < frame_header->blocksize; i++) {
  92167. if(integer_signal[0] != integer_signal[i]) {
  92168. signal_is_constant = false;
  92169. break;
  92170. }
  92171. }
  92172. }
  92173. if(signal_is_constant) {
  92174. _candidate_bits = evaluate_constant_subframe_(encoder, integer_signal[0], frame_header->blocksize, subframe_bps, subframe[!_best_subframe]);
  92175. if(_candidate_bits < _best_bits) {
  92176. _best_subframe = !_best_subframe;
  92177. _best_bits = _candidate_bits;
  92178. }
  92179. }
  92180. else {
  92181. if(!encoder->private_->disable_fixed_subframes || (encoder->protected_->max_lpc_order == 0 && _best_bits == UINT_MAX)) {
  92182. if(encoder->protected_->do_exhaustive_model_search) {
  92183. min_fixed_order = 0;
  92184. max_fixed_order = FLAC__MAX_FIXED_ORDER;
  92185. }
  92186. else {
  92187. min_fixed_order = max_fixed_order = guess_fixed_order;
  92188. }
  92189. if(max_fixed_order >= frame_header->blocksize)
  92190. max_fixed_order = frame_header->blocksize - 1;
  92191. for(fixed_order = min_fixed_order; fixed_order <= max_fixed_order; fixed_order++) {
  92192. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92193. if(fixed_residual_bits_per_sample[fixed_order] >= (FLAC__float)subframe_bps)
  92194. continue; /* don't even try */
  92195. 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 */
  92196. #else
  92197. if(FLAC__fixedpoint_trunc(fixed_residual_bits_per_sample[fixed_order]) >= (int)subframe_bps)
  92198. continue; /* don't even try */
  92199. 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 */
  92200. #endif
  92201. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92202. if(rice_parameter >= rice_parameter_limit) {
  92203. #ifdef DEBUG_VERBOSE
  92204. fprintf(stderr, "clipping rice_parameter (%u -> %u) @0\n", rice_parameter, rice_parameter_limit - 1);
  92205. #endif
  92206. rice_parameter = rice_parameter_limit - 1;
  92207. }
  92208. _candidate_bits =
  92209. evaluate_fixed_subframe_(
  92210. encoder,
  92211. integer_signal,
  92212. residual[!_best_subframe],
  92213. encoder->private_->abs_residual_partition_sums,
  92214. encoder->private_->raw_bits_per_partition,
  92215. frame_header->blocksize,
  92216. subframe_bps,
  92217. fixed_order,
  92218. rice_parameter,
  92219. rice_parameter_limit,
  92220. min_partition_order,
  92221. max_partition_order,
  92222. encoder->protected_->do_escape_coding,
  92223. encoder->protected_->rice_parameter_search_dist,
  92224. subframe[!_best_subframe],
  92225. partitioned_rice_contents[!_best_subframe]
  92226. );
  92227. if(_candidate_bits < _best_bits) {
  92228. _best_subframe = !_best_subframe;
  92229. _best_bits = _candidate_bits;
  92230. }
  92231. }
  92232. }
  92233. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92234. if(encoder->protected_->max_lpc_order > 0) {
  92235. if(encoder->protected_->max_lpc_order >= frame_header->blocksize)
  92236. max_lpc_order = frame_header->blocksize-1;
  92237. else
  92238. max_lpc_order = encoder->protected_->max_lpc_order;
  92239. if(max_lpc_order > 0) {
  92240. unsigned a;
  92241. for (a = 0; a < encoder->protected_->num_apodizations; a++) {
  92242. FLAC__lpc_window_data(integer_signal, encoder->private_->window[a], encoder->private_->windowed_signal, frame_header->blocksize);
  92243. encoder->private_->local_lpc_compute_autocorrelation(encoder->private_->windowed_signal, frame_header->blocksize, max_lpc_order+1, autoc);
  92244. if(autoc[0] != 0.0) {
  92245. FLAC__lpc_compute_lp_coefficients(autoc, &max_lpc_order, encoder->private_->lp_coeff, lpc_error);
  92246. if(encoder->protected_->do_exhaustive_model_search) {
  92247. min_lpc_order = 1;
  92248. }
  92249. else {
  92250. const unsigned guess_lpc_order =
  92251. FLAC__lpc_compute_best_order(
  92252. lpc_error,
  92253. max_lpc_order,
  92254. frame_header->blocksize,
  92255. subframe_bps + (
  92256. encoder->protected_->do_qlp_coeff_prec_search?
  92257. FLAC__MIN_QLP_COEFF_PRECISION : /* have to guess; use the min possible size to avoid accidentally favoring lower orders */
  92258. encoder->protected_->qlp_coeff_precision
  92259. )
  92260. );
  92261. min_lpc_order = max_lpc_order = guess_lpc_order;
  92262. }
  92263. if(max_lpc_order >= frame_header->blocksize)
  92264. max_lpc_order = frame_header->blocksize - 1;
  92265. for(lpc_order = min_lpc_order; lpc_order <= max_lpc_order; lpc_order++) {
  92266. lpc_residual_bits_per_sample = FLAC__lpc_compute_expected_bits_per_residual_sample(lpc_error[lpc_order-1], frame_header->blocksize-lpc_order);
  92267. if(lpc_residual_bits_per_sample >= (FLAC__double)subframe_bps)
  92268. continue; /* don't even try */
  92269. rice_parameter = (lpc_residual_bits_per_sample > 0.0)? (unsigned)(lpc_residual_bits_per_sample+0.5) : 0; /* 0.5 is for rounding */
  92270. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92271. if(rice_parameter >= rice_parameter_limit) {
  92272. #ifdef DEBUG_VERBOSE
  92273. fprintf(stderr, "clipping rice_parameter (%u -> %u) @1\n", rice_parameter, rice_parameter_limit - 1);
  92274. #endif
  92275. rice_parameter = rice_parameter_limit - 1;
  92276. }
  92277. if(encoder->protected_->do_qlp_coeff_prec_search) {
  92278. min_qlp_coeff_precision = FLAC__MIN_QLP_COEFF_PRECISION;
  92279. if(subframe_bps <= 17) {
  92280. max_qlp_coeff_precision = min(32 - subframe_bps - lpc_order, FLAC__MAX_QLP_COEFF_PRECISION);
  92281. max_qlp_coeff_precision = max(max_qlp_coeff_precision, min_qlp_coeff_precision);
  92282. }
  92283. else
  92284. max_qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  92285. }
  92286. else {
  92287. min_qlp_coeff_precision = max_qlp_coeff_precision = encoder->protected_->qlp_coeff_precision;
  92288. }
  92289. for(qlp_coeff_precision = min_qlp_coeff_precision; qlp_coeff_precision <= max_qlp_coeff_precision; qlp_coeff_precision++) {
  92290. _candidate_bits =
  92291. evaluate_lpc_subframe_(
  92292. encoder,
  92293. integer_signal,
  92294. residual[!_best_subframe],
  92295. encoder->private_->abs_residual_partition_sums,
  92296. encoder->private_->raw_bits_per_partition,
  92297. encoder->private_->lp_coeff[lpc_order-1],
  92298. frame_header->blocksize,
  92299. subframe_bps,
  92300. lpc_order,
  92301. qlp_coeff_precision,
  92302. rice_parameter,
  92303. rice_parameter_limit,
  92304. min_partition_order,
  92305. max_partition_order,
  92306. encoder->protected_->do_escape_coding,
  92307. encoder->protected_->rice_parameter_search_dist,
  92308. subframe[!_best_subframe],
  92309. partitioned_rice_contents[!_best_subframe]
  92310. );
  92311. if(_candidate_bits > 0) { /* if == 0, there was a problem quantizing the lpcoeffs */
  92312. if(_candidate_bits < _best_bits) {
  92313. _best_subframe = !_best_subframe;
  92314. _best_bits = _candidate_bits;
  92315. }
  92316. }
  92317. }
  92318. }
  92319. }
  92320. }
  92321. }
  92322. }
  92323. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  92324. }
  92325. }
  92326. if(_best_bits == UINT_MAX) {
  92327. FLAC__ASSERT(_best_subframe == 0);
  92328. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92329. }
  92330. *best_subframe = _best_subframe;
  92331. *best_bits = _best_bits;
  92332. return true;
  92333. }
  92334. FLAC__bool add_subframe_(
  92335. FLAC__StreamEncoder *encoder,
  92336. unsigned blocksize,
  92337. unsigned subframe_bps,
  92338. const FLAC__Subframe *subframe,
  92339. FLAC__BitWriter *frame
  92340. )
  92341. {
  92342. switch(subframe->type) {
  92343. case FLAC__SUBFRAME_TYPE_CONSTANT:
  92344. if(!FLAC__subframe_add_constant(&(subframe->data.constant), subframe_bps, subframe->wasted_bits, frame)) {
  92345. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92346. return false;
  92347. }
  92348. break;
  92349. case FLAC__SUBFRAME_TYPE_FIXED:
  92350. if(!FLAC__subframe_add_fixed(&(subframe->data.fixed), blocksize - subframe->data.fixed.order, subframe_bps, subframe->wasted_bits, frame)) {
  92351. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92352. return false;
  92353. }
  92354. break;
  92355. case FLAC__SUBFRAME_TYPE_LPC:
  92356. if(!FLAC__subframe_add_lpc(&(subframe->data.lpc), blocksize - subframe->data.lpc.order, subframe_bps, subframe->wasted_bits, frame)) {
  92357. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92358. return false;
  92359. }
  92360. break;
  92361. case FLAC__SUBFRAME_TYPE_VERBATIM:
  92362. if(!FLAC__subframe_add_verbatim(&(subframe->data.verbatim), blocksize, subframe_bps, subframe->wasted_bits, frame)) {
  92363. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92364. return false;
  92365. }
  92366. break;
  92367. default:
  92368. FLAC__ASSERT(0);
  92369. }
  92370. return true;
  92371. }
  92372. #define SPOTCHECK_ESTIMATE 0
  92373. #if SPOTCHECK_ESTIMATE
  92374. static void spotcheck_subframe_estimate_(
  92375. FLAC__StreamEncoder *encoder,
  92376. unsigned blocksize,
  92377. unsigned subframe_bps,
  92378. const FLAC__Subframe *subframe,
  92379. unsigned estimate
  92380. )
  92381. {
  92382. FLAC__bool ret;
  92383. FLAC__BitWriter *frame = FLAC__bitwriter_new();
  92384. if(frame == 0) {
  92385. fprintf(stderr, "EST: can't allocate frame\n");
  92386. return;
  92387. }
  92388. if(!FLAC__bitwriter_init(frame)) {
  92389. fprintf(stderr, "EST: can't init frame\n");
  92390. return;
  92391. }
  92392. ret = add_subframe_(encoder, blocksize, subframe_bps, subframe, frame);
  92393. FLAC__ASSERT(ret);
  92394. {
  92395. const unsigned actual = FLAC__bitwriter_get_input_bits_unconsumed(frame);
  92396. if(estimate != actual)
  92397. 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);
  92398. }
  92399. FLAC__bitwriter_delete(frame);
  92400. }
  92401. #endif
  92402. unsigned evaluate_constant_subframe_(
  92403. FLAC__StreamEncoder *encoder,
  92404. const FLAC__int32 signal,
  92405. unsigned blocksize,
  92406. unsigned subframe_bps,
  92407. FLAC__Subframe *subframe
  92408. )
  92409. {
  92410. unsigned estimate;
  92411. subframe->type = FLAC__SUBFRAME_TYPE_CONSTANT;
  92412. subframe->data.constant.value = signal;
  92413. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + subframe_bps;
  92414. #if SPOTCHECK_ESTIMATE
  92415. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92416. #else
  92417. (void)encoder, (void)blocksize;
  92418. #endif
  92419. return estimate;
  92420. }
  92421. unsigned evaluate_fixed_subframe_(
  92422. FLAC__StreamEncoder *encoder,
  92423. const FLAC__int32 signal[],
  92424. FLAC__int32 residual[],
  92425. FLAC__uint64 abs_residual_partition_sums[],
  92426. unsigned raw_bits_per_partition[],
  92427. unsigned blocksize,
  92428. unsigned subframe_bps,
  92429. unsigned order,
  92430. unsigned rice_parameter,
  92431. unsigned rice_parameter_limit,
  92432. unsigned min_partition_order,
  92433. unsigned max_partition_order,
  92434. FLAC__bool do_escape_coding,
  92435. unsigned rice_parameter_search_dist,
  92436. FLAC__Subframe *subframe,
  92437. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92438. )
  92439. {
  92440. unsigned i, residual_bits, estimate;
  92441. const unsigned residual_samples = blocksize - order;
  92442. FLAC__fixed_compute_residual(signal+order, residual_samples, order, residual);
  92443. subframe->type = FLAC__SUBFRAME_TYPE_FIXED;
  92444. subframe->data.fixed.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92445. subframe->data.fixed.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92446. subframe->data.fixed.residual = residual;
  92447. residual_bits =
  92448. find_best_partition_order_(
  92449. encoder->private_,
  92450. residual,
  92451. abs_residual_partition_sums,
  92452. raw_bits_per_partition,
  92453. residual_samples,
  92454. order,
  92455. rice_parameter,
  92456. rice_parameter_limit,
  92457. min_partition_order,
  92458. max_partition_order,
  92459. subframe_bps,
  92460. do_escape_coding,
  92461. rice_parameter_search_dist,
  92462. &subframe->data.fixed.entropy_coding_method
  92463. );
  92464. subframe->data.fixed.order = order;
  92465. for(i = 0; i < order; i++)
  92466. subframe->data.fixed.warmup[i] = signal[i];
  92467. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (order * subframe_bps) + residual_bits;
  92468. #if SPOTCHECK_ESTIMATE
  92469. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92470. #endif
  92471. return estimate;
  92472. }
  92473. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92474. unsigned evaluate_lpc_subframe_(
  92475. FLAC__StreamEncoder *encoder,
  92476. const FLAC__int32 signal[],
  92477. FLAC__int32 residual[],
  92478. FLAC__uint64 abs_residual_partition_sums[],
  92479. unsigned raw_bits_per_partition[],
  92480. const FLAC__real lp_coeff[],
  92481. unsigned blocksize,
  92482. unsigned subframe_bps,
  92483. unsigned order,
  92484. unsigned qlp_coeff_precision,
  92485. unsigned rice_parameter,
  92486. unsigned rice_parameter_limit,
  92487. unsigned min_partition_order,
  92488. unsigned max_partition_order,
  92489. FLAC__bool do_escape_coding,
  92490. unsigned rice_parameter_search_dist,
  92491. FLAC__Subframe *subframe,
  92492. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92493. )
  92494. {
  92495. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  92496. unsigned i, residual_bits, estimate;
  92497. int quantization, ret;
  92498. const unsigned residual_samples = blocksize - order;
  92499. if(subframe_bps <= 16) {
  92500. FLAC__ASSERT(order > 0);
  92501. FLAC__ASSERT(order <= FLAC__MAX_LPC_ORDER);
  92502. qlp_coeff_precision = min(qlp_coeff_precision, 32 - subframe_bps - FLAC__bitmath_ilog2(order));
  92503. }
  92504. ret = FLAC__lpc_quantize_coefficients(lp_coeff, order, qlp_coeff_precision, qlp_coeff, &quantization);
  92505. if(ret != 0)
  92506. return 0; /* this is a hack to indicate to the caller that we can't do lp at this order on this subframe */
  92507. if(subframe_bps + qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  92508. if(subframe_bps <= 16 && qlp_coeff_precision <= 16)
  92509. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92510. else
  92511. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92512. else
  92513. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92514. subframe->type = FLAC__SUBFRAME_TYPE_LPC;
  92515. subframe->data.lpc.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92516. subframe->data.lpc.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92517. subframe->data.lpc.residual = residual;
  92518. residual_bits =
  92519. find_best_partition_order_(
  92520. encoder->private_,
  92521. residual,
  92522. abs_residual_partition_sums,
  92523. raw_bits_per_partition,
  92524. residual_samples,
  92525. order,
  92526. rice_parameter,
  92527. rice_parameter_limit,
  92528. min_partition_order,
  92529. max_partition_order,
  92530. subframe_bps,
  92531. do_escape_coding,
  92532. rice_parameter_search_dist,
  92533. &subframe->data.lpc.entropy_coding_method
  92534. );
  92535. subframe->data.lpc.order = order;
  92536. subframe->data.lpc.qlp_coeff_precision = qlp_coeff_precision;
  92537. subframe->data.lpc.quantization_level = quantization;
  92538. memcpy(subframe->data.lpc.qlp_coeff, qlp_coeff, sizeof(FLAC__int32)*FLAC__MAX_LPC_ORDER);
  92539. for(i = 0; i < order; i++)
  92540. subframe->data.lpc.warmup[i] = signal[i];
  92541. 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;
  92542. #if SPOTCHECK_ESTIMATE
  92543. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92544. #endif
  92545. return estimate;
  92546. }
  92547. #endif
  92548. unsigned evaluate_verbatim_subframe_(
  92549. FLAC__StreamEncoder *encoder,
  92550. const FLAC__int32 signal[],
  92551. unsigned blocksize,
  92552. unsigned subframe_bps,
  92553. FLAC__Subframe *subframe
  92554. )
  92555. {
  92556. unsigned estimate;
  92557. subframe->type = FLAC__SUBFRAME_TYPE_VERBATIM;
  92558. subframe->data.verbatim.data = signal;
  92559. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (blocksize * subframe_bps);
  92560. #if SPOTCHECK_ESTIMATE
  92561. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92562. #else
  92563. (void)encoder;
  92564. #endif
  92565. return estimate;
  92566. }
  92567. unsigned find_best_partition_order_(
  92568. FLAC__StreamEncoderPrivate *private_,
  92569. const FLAC__int32 residual[],
  92570. FLAC__uint64 abs_residual_partition_sums[],
  92571. unsigned raw_bits_per_partition[],
  92572. unsigned residual_samples,
  92573. unsigned predictor_order,
  92574. unsigned rice_parameter,
  92575. unsigned rice_parameter_limit,
  92576. unsigned min_partition_order,
  92577. unsigned max_partition_order,
  92578. unsigned bps,
  92579. FLAC__bool do_escape_coding,
  92580. unsigned rice_parameter_search_dist,
  92581. FLAC__EntropyCodingMethod *best_ecm
  92582. )
  92583. {
  92584. unsigned residual_bits, best_residual_bits = 0;
  92585. unsigned best_parameters_index = 0;
  92586. unsigned best_partition_order = 0;
  92587. const unsigned blocksize = residual_samples + predictor_order;
  92588. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(max_partition_order, blocksize, predictor_order);
  92589. min_partition_order = min(min_partition_order, max_partition_order);
  92590. precompute_partition_info_sums_(residual, abs_residual_partition_sums, residual_samples, predictor_order, min_partition_order, max_partition_order, bps);
  92591. if(do_escape_coding)
  92592. precompute_partition_info_escapes_(residual, raw_bits_per_partition, residual_samples, predictor_order, min_partition_order, max_partition_order);
  92593. {
  92594. int partition_order;
  92595. unsigned sum;
  92596. for(partition_order = (int)max_partition_order, sum = 0; partition_order >= (int)min_partition_order; partition_order--) {
  92597. if(!
  92598. set_partitioned_rice_(
  92599. #ifdef EXACT_RICE_BITS_CALCULATION
  92600. residual,
  92601. #endif
  92602. abs_residual_partition_sums+sum,
  92603. raw_bits_per_partition+sum,
  92604. residual_samples,
  92605. predictor_order,
  92606. rice_parameter,
  92607. rice_parameter_limit,
  92608. rice_parameter_search_dist,
  92609. (unsigned)partition_order,
  92610. do_escape_coding,
  92611. &private_->partitioned_rice_contents_extra[!best_parameters_index],
  92612. &residual_bits
  92613. )
  92614. )
  92615. {
  92616. FLAC__ASSERT(best_residual_bits != 0);
  92617. break;
  92618. }
  92619. sum += 1u << partition_order;
  92620. if(best_residual_bits == 0 || residual_bits < best_residual_bits) {
  92621. best_residual_bits = residual_bits;
  92622. best_parameters_index = !best_parameters_index;
  92623. best_partition_order = partition_order;
  92624. }
  92625. }
  92626. }
  92627. best_ecm->data.partitioned_rice.order = best_partition_order;
  92628. {
  92629. FLAC__EntropyCodingMethod_PartitionedRiceContents* prc = (FLAC__EntropyCodingMethod_PartitionedRiceContents*)best_ecm->data.partitioned_rice.contents;
  92630. unsigned partition;
  92631. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(prc, max(6, best_partition_order));
  92632. memcpy(prc->parameters, private_->partitioned_rice_contents_extra[best_parameters_index].parameters, sizeof(unsigned)*(1<<(best_partition_order)));
  92633. if(do_escape_coding)
  92634. memcpy(prc->raw_bits, private_->partitioned_rice_contents_extra[best_parameters_index].raw_bits, sizeof(unsigned)*(1<<(best_partition_order)));
  92635. for(partition = 0; partition < (1u<<best_partition_order); partition++) {
  92636. if(prc->parameters[partition] >= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
  92637. best_ecm->type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2;
  92638. break;
  92639. }
  92640. }
  92641. }
  92642. return best_residual_bits;
  92643. }
  92644. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  92645. extern void precompute_partition_info_sums_32bit_asm_ia32_(
  92646. const FLAC__int32 residual[],
  92647. FLAC__uint64 abs_residual_partition_sums[],
  92648. unsigned blocksize,
  92649. unsigned predictor_order,
  92650. unsigned min_partition_order,
  92651. unsigned max_partition_order
  92652. );
  92653. #endif
  92654. void precompute_partition_info_sums_(
  92655. const FLAC__int32 residual[],
  92656. FLAC__uint64 abs_residual_partition_sums[],
  92657. unsigned residual_samples,
  92658. unsigned predictor_order,
  92659. unsigned min_partition_order,
  92660. unsigned max_partition_order,
  92661. unsigned bps
  92662. )
  92663. {
  92664. const unsigned default_partition_samples = (residual_samples + predictor_order) >> max_partition_order;
  92665. unsigned partitions = 1u << max_partition_order;
  92666. FLAC__ASSERT(default_partition_samples > predictor_order);
  92667. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  92668. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  92669. precompute_partition_info_sums_32bit_asm_ia32_(residual, abs_residual_partition_sums, residual_samples + predictor_order, predictor_order, min_partition_order, max_partition_order);
  92670. return;
  92671. }
  92672. #endif
  92673. {
  92674. unsigned partition, residual_sample, end = (unsigned)(-(int)predictor_order);
  92675. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  92676. FLAC__uint32 abs_residual_partition_sum;
  92677. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92678. end += default_partition_samples;
  92679. abs_residual_partition_sum = 0;
  92680. for( ; residual_sample < end; residual_sample++)
  92681. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  92682. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  92683. }
  92684. }
  92685. else { /* have to pessimistically use 64 bits for accumulator */
  92686. FLAC__uint64 abs_residual_partition_sum;
  92687. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92688. end += default_partition_samples;
  92689. abs_residual_partition_sum = 0;
  92690. for( ; residual_sample < end; residual_sample++)
  92691. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  92692. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  92693. }
  92694. }
  92695. }
  92696. {
  92697. unsigned from_partition = 0, to_partition = partitions;
  92698. int partition_order;
  92699. for(partition_order = (int)max_partition_order - 1; partition_order >= (int)min_partition_order; partition_order--) {
  92700. unsigned i;
  92701. partitions >>= 1;
  92702. for(i = 0; i < partitions; i++) {
  92703. abs_residual_partition_sums[to_partition++] =
  92704. abs_residual_partition_sums[from_partition ] +
  92705. abs_residual_partition_sums[from_partition+1];
  92706. from_partition += 2;
  92707. }
  92708. }
  92709. }
  92710. }
  92711. void precompute_partition_info_escapes_(
  92712. const FLAC__int32 residual[],
  92713. unsigned raw_bits_per_partition[],
  92714. unsigned residual_samples,
  92715. unsigned predictor_order,
  92716. unsigned min_partition_order,
  92717. unsigned max_partition_order
  92718. )
  92719. {
  92720. int partition_order;
  92721. unsigned from_partition, to_partition = 0;
  92722. const unsigned blocksize = residual_samples + predictor_order;
  92723. for(partition_order = (int)max_partition_order; partition_order >= 0; partition_order--) {
  92724. FLAC__int32 r;
  92725. FLAC__uint32 rmax;
  92726. unsigned partition, partition_sample, partition_samples, residual_sample;
  92727. const unsigned partitions = 1u << partition_order;
  92728. const unsigned default_partition_samples = blocksize >> partition_order;
  92729. FLAC__ASSERT(default_partition_samples > predictor_order);
  92730. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92731. partition_samples = default_partition_samples;
  92732. if(partition == 0)
  92733. partition_samples -= predictor_order;
  92734. rmax = 0;
  92735. for(partition_sample = 0; partition_sample < partition_samples; partition_sample++) {
  92736. r = residual[residual_sample++];
  92737. if(r < 0)
  92738. rmax |= ~r;
  92739. else
  92740. rmax |= r;
  92741. }
  92742. raw_bits_per_partition[partition] = rmax? FLAC__bitmath_ilog2(rmax) + 2 : 1;
  92743. }
  92744. to_partition = partitions;
  92745. break; /*@@@ yuck, should remove the 'for' loop instead */
  92746. }
  92747. for(from_partition = 0, --partition_order; partition_order >= (int)min_partition_order; partition_order--) {
  92748. unsigned m;
  92749. unsigned i;
  92750. const unsigned partitions = 1u << partition_order;
  92751. for(i = 0; i < partitions; i++) {
  92752. m = raw_bits_per_partition[from_partition];
  92753. from_partition++;
  92754. raw_bits_per_partition[to_partition] = max(m, raw_bits_per_partition[from_partition]);
  92755. from_partition++;
  92756. to_partition++;
  92757. }
  92758. }
  92759. }
  92760. #ifdef EXACT_RICE_BITS_CALCULATION
  92761. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  92762. const unsigned rice_parameter,
  92763. const unsigned partition_samples,
  92764. const FLAC__int32 *residual
  92765. )
  92766. {
  92767. unsigned i, partition_bits =
  92768. 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 */
  92769. (1+rice_parameter) * partition_samples /* 1 for unary stop bit + rice_parameter for the binary portion */
  92770. ;
  92771. for(i = 0; i < partition_samples; i++)
  92772. partition_bits += ( (FLAC__uint32)((residual[i]<<1)^(residual[i]>>31)) >> rice_parameter );
  92773. return partition_bits;
  92774. }
  92775. #else
  92776. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  92777. const unsigned rice_parameter,
  92778. const unsigned partition_samples,
  92779. const FLAC__uint64 abs_residual_partition_sum
  92780. )
  92781. {
  92782. return
  92783. 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 */
  92784. (1+rice_parameter) * partition_samples + /* 1 for unary stop bit + rice_parameter for the binary portion */
  92785. (
  92786. rice_parameter?
  92787. (unsigned)(abs_residual_partition_sum >> (rice_parameter-1)) /* rice_parameter-1 because the real coder sign-folds instead of using a sign bit */
  92788. : (unsigned)(abs_residual_partition_sum << 1) /* can't shift by negative number, so reverse */
  92789. )
  92790. - (partition_samples >> 1)
  92791. ;
  92792. }
  92793. #endif
  92794. FLAC__bool set_partitioned_rice_(
  92795. #ifdef EXACT_RICE_BITS_CALCULATION
  92796. const FLAC__int32 residual[],
  92797. #endif
  92798. const FLAC__uint64 abs_residual_partition_sums[],
  92799. const unsigned raw_bits_per_partition[],
  92800. const unsigned residual_samples,
  92801. const unsigned predictor_order,
  92802. const unsigned suggested_rice_parameter,
  92803. const unsigned rice_parameter_limit,
  92804. const unsigned rice_parameter_search_dist,
  92805. const unsigned partition_order,
  92806. const FLAC__bool search_for_escapes,
  92807. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  92808. unsigned *bits
  92809. )
  92810. {
  92811. unsigned rice_parameter, partition_bits;
  92812. unsigned best_partition_bits, best_rice_parameter = 0;
  92813. unsigned bits_ = FLAC__ENTROPY_CODING_METHOD_TYPE_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN;
  92814. unsigned *parameters, *raw_bits;
  92815. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92816. unsigned min_rice_parameter, max_rice_parameter;
  92817. #else
  92818. (void)rice_parameter_search_dist;
  92819. #endif
  92820. FLAC__ASSERT(suggested_rice_parameter < FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  92821. FLAC__ASSERT(rice_parameter_limit <= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  92822. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order));
  92823. parameters = partitioned_rice_contents->parameters;
  92824. raw_bits = partitioned_rice_contents->raw_bits;
  92825. if(partition_order == 0) {
  92826. best_partition_bits = (unsigned)(-1);
  92827. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92828. if(rice_parameter_search_dist) {
  92829. if(suggested_rice_parameter < rice_parameter_search_dist)
  92830. min_rice_parameter = 0;
  92831. else
  92832. min_rice_parameter = suggested_rice_parameter - rice_parameter_search_dist;
  92833. max_rice_parameter = suggested_rice_parameter + rice_parameter_search_dist;
  92834. if(max_rice_parameter >= rice_parameter_limit) {
  92835. #ifdef DEBUG_VERBOSE
  92836. fprintf(stderr, "clipping rice_parameter (%u -> %u) @5\n", max_rice_parameter, rice_parameter_limit - 1);
  92837. #endif
  92838. max_rice_parameter = rice_parameter_limit - 1;
  92839. }
  92840. }
  92841. else
  92842. min_rice_parameter = max_rice_parameter = suggested_rice_parameter;
  92843. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  92844. #else
  92845. rice_parameter = suggested_rice_parameter;
  92846. #endif
  92847. #ifdef EXACT_RICE_BITS_CALCULATION
  92848. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, residual);
  92849. #else
  92850. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, abs_residual_partition_sums[0]);
  92851. #endif
  92852. if(partition_bits < best_partition_bits) {
  92853. best_rice_parameter = rice_parameter;
  92854. best_partition_bits = partition_bits;
  92855. }
  92856. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92857. }
  92858. #endif
  92859. if(search_for_escapes) {
  92860. 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;
  92861. if(partition_bits <= best_partition_bits) {
  92862. raw_bits[0] = raw_bits_per_partition[0];
  92863. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  92864. best_partition_bits = partition_bits;
  92865. }
  92866. else
  92867. raw_bits[0] = 0;
  92868. }
  92869. parameters[0] = best_rice_parameter;
  92870. bits_ += best_partition_bits;
  92871. }
  92872. else {
  92873. unsigned partition, residual_sample;
  92874. unsigned partition_samples;
  92875. FLAC__uint64 mean, k;
  92876. const unsigned partitions = 1u << partition_order;
  92877. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92878. partition_samples = (residual_samples+predictor_order) >> partition_order;
  92879. if(partition == 0) {
  92880. if(partition_samples <= predictor_order)
  92881. return false;
  92882. else
  92883. partition_samples -= predictor_order;
  92884. }
  92885. mean = abs_residual_partition_sums[partition];
  92886. for(rice_parameter = 0, k = partition_samples; k < mean; rice_parameter++, k <<= 1)
  92887. ;
  92888. if(rice_parameter >= rice_parameter_limit) {
  92889. #ifdef DEBUG_VERBOSE
  92890. fprintf(stderr, "clipping rice_parameter (%u -> %u) @6\n", rice_parameter, rice_parameter_limit - 1);
  92891. #endif
  92892. rice_parameter = rice_parameter_limit - 1;
  92893. }
  92894. best_partition_bits = (unsigned)(-1);
  92895. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92896. if(rice_parameter_search_dist) {
  92897. if(rice_parameter < rice_parameter_search_dist)
  92898. min_rice_parameter = 0;
  92899. else
  92900. min_rice_parameter = rice_parameter - rice_parameter_search_dist;
  92901. max_rice_parameter = rice_parameter + rice_parameter_search_dist;
  92902. if(max_rice_parameter >= rice_parameter_limit) {
  92903. #ifdef DEBUG_VERBOSE
  92904. fprintf(stderr, "clipping rice_parameter (%u -> %u) @7\n", max_rice_parameter, rice_parameter_limit - 1);
  92905. #endif
  92906. max_rice_parameter = rice_parameter_limit - 1;
  92907. }
  92908. }
  92909. else
  92910. min_rice_parameter = max_rice_parameter = rice_parameter;
  92911. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  92912. #endif
  92913. #ifdef EXACT_RICE_BITS_CALCULATION
  92914. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, residual+residual_sample);
  92915. #else
  92916. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, abs_residual_partition_sums[partition]);
  92917. #endif
  92918. if(partition_bits < best_partition_bits) {
  92919. best_rice_parameter = rice_parameter;
  92920. best_partition_bits = partition_bits;
  92921. }
  92922. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92923. }
  92924. #endif
  92925. if(search_for_escapes) {
  92926. 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;
  92927. if(partition_bits <= best_partition_bits) {
  92928. raw_bits[partition] = raw_bits_per_partition[partition];
  92929. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  92930. best_partition_bits = partition_bits;
  92931. }
  92932. else
  92933. raw_bits[partition] = 0;
  92934. }
  92935. parameters[partition] = best_rice_parameter;
  92936. bits_ += best_partition_bits;
  92937. residual_sample += partition_samples;
  92938. }
  92939. }
  92940. *bits = bits_;
  92941. return true;
  92942. }
  92943. unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples)
  92944. {
  92945. unsigned i, shift;
  92946. FLAC__int32 x = 0;
  92947. for(i = 0; i < samples && !(x&1); i++)
  92948. x |= signal[i];
  92949. if(x == 0) {
  92950. shift = 0;
  92951. }
  92952. else {
  92953. for(shift = 0; !(x&1); shift++)
  92954. x >>= 1;
  92955. }
  92956. if(shift > 0) {
  92957. for(i = 0; i < samples; i++)
  92958. signal[i] >>= shift;
  92959. }
  92960. return shift;
  92961. }
  92962. void append_to_verify_fifo_(verify_input_fifo *fifo, const FLAC__int32 * const input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  92963. {
  92964. unsigned channel;
  92965. for(channel = 0; channel < channels; channel++)
  92966. memcpy(&fifo->data[channel][fifo->tail], &input[channel][input_offset], sizeof(FLAC__int32) * wide_samples);
  92967. fifo->tail += wide_samples;
  92968. FLAC__ASSERT(fifo->tail <= fifo->size);
  92969. }
  92970. void append_to_verify_fifo_interleaved_(verify_input_fifo *fifo, const FLAC__int32 input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  92971. {
  92972. unsigned channel;
  92973. unsigned sample, wide_sample;
  92974. unsigned tail = fifo->tail;
  92975. sample = input_offset * channels;
  92976. for(wide_sample = 0; wide_sample < wide_samples; wide_sample++) {
  92977. for(channel = 0; channel < channels; channel++)
  92978. fifo->data[channel][tail] = input[sample++];
  92979. tail++;
  92980. }
  92981. fifo->tail = tail;
  92982. FLAC__ASSERT(fifo->tail <= fifo->size);
  92983. }
  92984. FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  92985. {
  92986. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  92987. const size_t encoded_bytes = encoder->private_->verify.output.bytes;
  92988. (void)decoder;
  92989. if(encoder->private_->verify.needs_magic_hack) {
  92990. FLAC__ASSERT(*bytes >= FLAC__STREAM_SYNC_LENGTH);
  92991. *bytes = FLAC__STREAM_SYNC_LENGTH;
  92992. memcpy(buffer, FLAC__STREAM_SYNC_STRING, *bytes);
  92993. encoder->private_->verify.needs_magic_hack = false;
  92994. }
  92995. else {
  92996. if(encoded_bytes == 0) {
  92997. FLAC__ASSERT(0);
  92998. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  92999. }
  93000. else if(encoded_bytes < *bytes)
  93001. *bytes = encoded_bytes;
  93002. memcpy(buffer, encoder->private_->verify.output.data, *bytes);
  93003. encoder->private_->verify.output.data += *bytes;
  93004. encoder->private_->verify.output.bytes -= *bytes;
  93005. }
  93006. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  93007. }
  93008. FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
  93009. {
  93010. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder *)client_data;
  93011. unsigned channel;
  93012. const unsigned channels = frame->header.channels;
  93013. const unsigned blocksize = frame->header.blocksize;
  93014. const unsigned bytes_per_block = sizeof(FLAC__int32) * blocksize;
  93015. (void)decoder;
  93016. for(channel = 0; channel < channels; channel++) {
  93017. if(0 != memcmp(buffer[channel], encoder->private_->verify.input_fifo.data[channel], bytes_per_block)) {
  93018. unsigned i, sample = 0;
  93019. FLAC__int32 expect = 0, got = 0;
  93020. for(i = 0; i < blocksize; i++) {
  93021. if(buffer[channel][i] != encoder->private_->verify.input_fifo.data[channel][i]) {
  93022. sample = i;
  93023. expect = (FLAC__int32)encoder->private_->verify.input_fifo.data[channel][i];
  93024. got = (FLAC__int32)buffer[channel][i];
  93025. break;
  93026. }
  93027. }
  93028. FLAC__ASSERT(i < blocksize);
  93029. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  93030. encoder->private_->verify.error_stats.absolute_sample = frame->header.number.sample_number + sample;
  93031. encoder->private_->verify.error_stats.frame_number = (unsigned)(frame->header.number.sample_number / blocksize);
  93032. encoder->private_->verify.error_stats.channel = channel;
  93033. encoder->private_->verify.error_stats.sample = sample;
  93034. encoder->private_->verify.error_stats.expected = expect;
  93035. encoder->private_->verify.error_stats.got = got;
  93036. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  93037. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  93038. }
  93039. }
  93040. encoder->private_->verify.input_fifo.tail -= blocksize;
  93041. FLAC__ASSERT(encoder->private_->verify.input_fifo.tail <= OVERREAD_);
  93042. for(channel = 0; channel < channels; channel++)
  93043. 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]));
  93044. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  93045. }
  93046. void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
  93047. {
  93048. (void)decoder, (void)metadata, (void)client_data;
  93049. }
  93050. void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
  93051. {
  93052. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  93053. (void)decoder, (void)status;
  93054. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  93055. }
  93056. FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  93057. {
  93058. (void)client_data;
  93059. *bytes = fread(buffer, 1, *bytes, encoder->private_->file);
  93060. if (*bytes == 0) {
  93061. if (feof(encoder->private_->file))
  93062. return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM;
  93063. else if (ferror(encoder->private_->file))
  93064. return FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
  93065. }
  93066. return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE;
  93067. }
  93068. FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  93069. {
  93070. (void)client_data;
  93071. if(fseeko(encoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  93072. return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
  93073. else
  93074. return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
  93075. }
  93076. FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  93077. {
  93078. off_t offset;
  93079. (void)client_data;
  93080. offset = ftello(encoder->private_->file);
  93081. if(offset < 0) {
  93082. return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR;
  93083. }
  93084. else {
  93085. *absolute_byte_offset = (FLAC__uint64)offset;
  93086. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  93087. }
  93088. }
  93089. #ifdef FLAC__VALGRIND_TESTING
  93090. static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
  93091. {
  93092. size_t ret = fwrite(ptr, size, nmemb, stream);
  93093. if(!ferror(stream))
  93094. fflush(stream);
  93095. return ret;
  93096. }
  93097. #else
  93098. #define local__fwrite fwrite
  93099. #endif
  93100. FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data)
  93101. {
  93102. (void)client_data, (void)current_frame;
  93103. if(local__fwrite(buffer, sizeof(FLAC__byte), bytes, encoder->private_->file) == bytes) {
  93104. FLAC__bool call_it = 0 != encoder->private_->progress_callback && (
  93105. #if FLAC__HAS_OGG
  93106. encoder->private_->is_ogg? true :
  93107. #endif
  93108. samples > 0
  93109. );
  93110. if(call_it) {
  93111. 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);
  93112. }
  93113. return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
  93114. }
  93115. else
  93116. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  93117. }
  93118. FILE *get_binary_stdout_(void)
  93119. {
  93120. #if defined _MSC_VER || defined __MINGW32__
  93121. _setmode(_fileno(stdout), _O_BINARY);
  93122. #elif defined __CYGWIN__
  93123. setmode(_fileno(stdout), _O_BINARY);
  93124. #elif defined __EMX__
  93125. setmode(fileno(stdout), O_BINARY);
  93126. #endif
  93127. return stdout;
  93128. }
  93129. #endif
  93130. /*** End of inlined file: stream_encoder.c ***/
  93131. /*** Start of inlined file: stream_encoder_framing.c ***/
  93132. /*** Start of inlined file: juce_FlacHeader.h ***/
  93133. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  93134. // tasks..
  93135. #define VERSION "1.2.1"
  93136. #define FLAC__NO_DLL 1
  93137. #if JUCE_MSVC
  93138. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  93139. #endif
  93140. #if JUCE_MAC
  93141. #define FLAC__SYS_DARWIN 1
  93142. #endif
  93143. /*** End of inlined file: juce_FlacHeader.h ***/
  93144. #if JUCE_USE_FLAC
  93145. #if HAVE_CONFIG_H
  93146. # include <config.h>
  93147. #endif
  93148. #include <stdio.h>
  93149. #include <string.h> /* for strlen() */
  93150. #ifdef max
  93151. #undef max
  93152. #endif
  93153. #define max(x,y) ((x)>(y)?(x):(y))
  93154. static FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method);
  93155. 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);
  93156. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw)
  93157. {
  93158. unsigned i, j;
  93159. const unsigned vendor_string_length = (unsigned)strlen(FLAC__VENDOR_STRING);
  93160. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->is_last, FLAC__STREAM_METADATA_IS_LAST_LEN))
  93161. return false;
  93162. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->type, FLAC__STREAM_METADATA_TYPE_LEN))
  93163. return false;
  93164. i = metadata->length;
  93165. if(metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  93166. FLAC__ASSERT(metadata->data.vorbis_comment.vendor_string.length == 0 || 0 != metadata->data.vorbis_comment.vendor_string.entry);
  93167. i -= metadata->data.vorbis_comment.vendor_string.length;
  93168. i += vendor_string_length;
  93169. }
  93170. FLAC__ASSERT(i < (1u << FLAC__STREAM_METADATA_LENGTH_LEN));
  93171. if(!FLAC__bitwriter_write_raw_uint32(bw, i, FLAC__STREAM_METADATA_LENGTH_LEN))
  93172. return false;
  93173. switch(metadata->type) {
  93174. case FLAC__METADATA_TYPE_STREAMINFO:
  93175. FLAC__ASSERT(metadata->data.stream_info.min_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN));
  93176. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN))
  93177. return false;
  93178. FLAC__ASSERT(metadata->data.stream_info.max_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN));
  93179. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  93180. return false;
  93181. FLAC__ASSERT(metadata->data.stream_info.min_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN));
  93182. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_framesize, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  93183. return false;
  93184. FLAC__ASSERT(metadata->data.stream_info.max_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN));
  93185. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_framesize, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  93186. return false;
  93187. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(metadata->data.stream_info.sample_rate));
  93188. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.sample_rate, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  93189. return false;
  93190. FLAC__ASSERT(metadata->data.stream_info.channels > 0);
  93191. FLAC__ASSERT(metadata->data.stream_info.channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN));
  93192. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.channels-1, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  93193. return false;
  93194. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample > 0);
  93195. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93196. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.bits_per_sample-1, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  93197. return false;
  93198. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.stream_info.total_samples, FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN))
  93199. return false;
  93200. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.stream_info.md5sum, 16))
  93201. return false;
  93202. break;
  93203. case FLAC__METADATA_TYPE_PADDING:
  93204. if(!FLAC__bitwriter_write_zeroes(bw, metadata->length * 8))
  93205. return false;
  93206. break;
  93207. case FLAC__METADATA_TYPE_APPLICATION:
  93208. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8))
  93209. return false;
  93210. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.data, metadata->length - (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8)))
  93211. return false;
  93212. break;
  93213. case FLAC__METADATA_TYPE_SEEKTABLE:
  93214. for(i = 0; i < metadata->data.seek_table.num_points; i++) {
  93215. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].sample_number, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  93216. return false;
  93217. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].stream_offset, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  93218. return false;
  93219. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.seek_table.points[i].frame_samples, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  93220. return false;
  93221. }
  93222. break;
  93223. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  93224. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, vendor_string_length))
  93225. return false;
  93226. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)FLAC__VENDOR_STRING, vendor_string_length))
  93227. return false;
  93228. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.num_comments))
  93229. return false;
  93230. for(i = 0; i < metadata->data.vorbis_comment.num_comments; i++) {
  93231. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.comments[i].length))
  93232. return false;
  93233. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.vorbis_comment.comments[i].entry, metadata->data.vorbis_comment.comments[i].length))
  93234. return false;
  93235. }
  93236. break;
  93237. case FLAC__METADATA_TYPE_CUESHEET:
  93238. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  93239. 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))
  93240. return false;
  93241. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.cue_sheet.lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  93242. return false;
  93243. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.is_cd? 1 : 0, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  93244. return false;
  93245. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  93246. return false;
  93247. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.num_tracks, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  93248. return false;
  93249. for(i = 0; i < metadata->data.cue_sheet.num_tracks; i++) {
  93250. const FLAC__StreamMetadata_CueSheet_Track *track = metadata->data.cue_sheet.tracks + i;
  93251. if(!FLAC__bitwriter_write_raw_uint64(bw, track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  93252. return false;
  93253. if(!FLAC__bitwriter_write_raw_uint32(bw, track->number, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  93254. return false;
  93255. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  93256. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  93257. return false;
  93258. if(!FLAC__bitwriter_write_raw_uint32(bw, track->type, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  93259. return false;
  93260. if(!FLAC__bitwriter_write_raw_uint32(bw, track->pre_emphasis, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  93261. return false;
  93262. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  93263. return false;
  93264. if(!FLAC__bitwriter_write_raw_uint32(bw, track->num_indices, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  93265. return false;
  93266. for(j = 0; j < track->num_indices; j++) {
  93267. const FLAC__StreamMetadata_CueSheet_Index *index = track->indices + j;
  93268. if(!FLAC__bitwriter_write_raw_uint64(bw, index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  93269. return false;
  93270. if(!FLAC__bitwriter_write_raw_uint32(bw, index->number, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  93271. return false;
  93272. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  93273. return false;
  93274. }
  93275. }
  93276. break;
  93277. case FLAC__METADATA_TYPE_PICTURE:
  93278. {
  93279. size_t len;
  93280. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.type, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  93281. return false;
  93282. len = strlen(metadata->data.picture.mime_type);
  93283. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  93284. return false;
  93285. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)metadata->data.picture.mime_type, len))
  93286. return false;
  93287. len = strlen((const char *)metadata->data.picture.description);
  93288. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  93289. return false;
  93290. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.description, len))
  93291. return false;
  93292. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  93293. return false;
  93294. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  93295. return false;
  93296. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  93297. return false;
  93298. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  93299. return false;
  93300. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.data_length, FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  93301. return false;
  93302. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.data, metadata->data.picture.data_length))
  93303. return false;
  93304. }
  93305. break;
  93306. default:
  93307. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.unknown.data, metadata->length))
  93308. return false;
  93309. break;
  93310. }
  93311. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93312. return true;
  93313. }
  93314. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw)
  93315. {
  93316. unsigned u, blocksize_hint, sample_rate_hint;
  93317. FLAC__byte crc;
  93318. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93319. if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__FRAME_HEADER_SYNC, FLAC__FRAME_HEADER_SYNC_LEN))
  93320. return false;
  93321. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_RESERVED_LEN))
  93322. return false;
  93323. if(!FLAC__bitwriter_write_raw_uint32(bw, (header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER)? 0 : 1, FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN))
  93324. return false;
  93325. FLAC__ASSERT(header->blocksize > 0 && header->blocksize <= FLAC__MAX_BLOCK_SIZE);
  93326. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535u);
  93327. blocksize_hint = 0;
  93328. switch(header->blocksize) {
  93329. case 192: u = 1; break;
  93330. case 576: u = 2; break;
  93331. case 1152: u = 3; break;
  93332. case 2304: u = 4; break;
  93333. case 4608: u = 5; break;
  93334. case 256: u = 8; break;
  93335. case 512: u = 9; break;
  93336. case 1024: u = 10; break;
  93337. case 2048: u = 11; break;
  93338. case 4096: u = 12; break;
  93339. case 8192: u = 13; break;
  93340. case 16384: u = 14; break;
  93341. case 32768: u = 15; break;
  93342. default:
  93343. if(header->blocksize <= 0x100)
  93344. blocksize_hint = u = 6;
  93345. else
  93346. blocksize_hint = u = 7;
  93347. break;
  93348. }
  93349. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BLOCK_SIZE_LEN))
  93350. return false;
  93351. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(header->sample_rate));
  93352. sample_rate_hint = 0;
  93353. switch(header->sample_rate) {
  93354. case 88200: u = 1; break;
  93355. case 176400: u = 2; break;
  93356. case 192000: u = 3; break;
  93357. case 8000: u = 4; break;
  93358. case 16000: u = 5; break;
  93359. case 22050: u = 6; break;
  93360. case 24000: u = 7; break;
  93361. case 32000: u = 8; break;
  93362. case 44100: u = 9; break;
  93363. case 48000: u = 10; break;
  93364. case 96000: u = 11; break;
  93365. default:
  93366. if(header->sample_rate <= 255000 && header->sample_rate % 1000 == 0)
  93367. sample_rate_hint = u = 12;
  93368. else if(header->sample_rate % 10 == 0)
  93369. sample_rate_hint = u = 14;
  93370. else if(header->sample_rate <= 0xffff)
  93371. sample_rate_hint = u = 13;
  93372. else
  93373. u = 0;
  93374. break;
  93375. }
  93376. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_SAMPLE_RATE_LEN))
  93377. return false;
  93378. FLAC__ASSERT(header->channels > 0 && header->channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN) && header->channels <= FLAC__MAX_CHANNELS);
  93379. switch(header->channel_assignment) {
  93380. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  93381. u = header->channels - 1;
  93382. break;
  93383. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  93384. FLAC__ASSERT(header->channels == 2);
  93385. u = 8;
  93386. break;
  93387. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  93388. FLAC__ASSERT(header->channels == 2);
  93389. u = 9;
  93390. break;
  93391. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  93392. FLAC__ASSERT(header->channels == 2);
  93393. u = 10;
  93394. break;
  93395. default:
  93396. FLAC__ASSERT(0);
  93397. }
  93398. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN))
  93399. return false;
  93400. FLAC__ASSERT(header->bits_per_sample > 0 && header->bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93401. switch(header->bits_per_sample) {
  93402. case 8 : u = 1; break;
  93403. case 12: u = 2; break;
  93404. case 16: u = 4; break;
  93405. case 20: u = 5; break;
  93406. case 24: u = 6; break;
  93407. default: u = 0; break;
  93408. }
  93409. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN))
  93410. return false;
  93411. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_ZERO_PAD_LEN))
  93412. return false;
  93413. if(header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  93414. if(!FLAC__bitwriter_write_utf8_uint32(bw, header->number.frame_number))
  93415. return false;
  93416. }
  93417. else {
  93418. if(!FLAC__bitwriter_write_utf8_uint64(bw, header->number.sample_number))
  93419. return false;
  93420. }
  93421. if(blocksize_hint)
  93422. if(!FLAC__bitwriter_write_raw_uint32(bw, header->blocksize-1, (blocksize_hint==6)? 8:16))
  93423. return false;
  93424. switch(sample_rate_hint) {
  93425. case 12:
  93426. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 1000, 8))
  93427. return false;
  93428. break;
  93429. case 13:
  93430. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate, 16))
  93431. return false;
  93432. break;
  93433. case 14:
  93434. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 10, 16))
  93435. return false;
  93436. break;
  93437. }
  93438. if(!FLAC__bitwriter_get_write_crc8(bw, &crc))
  93439. return false;
  93440. if(!FLAC__bitwriter_write_raw_uint32(bw, crc, FLAC__FRAME_HEADER_CRC_LEN))
  93441. return false;
  93442. return true;
  93443. }
  93444. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93445. {
  93446. FLAC__bool ok;
  93447. ok =
  93448. 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) &&
  93449. (wasted_bits? FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1) : true) &&
  93450. FLAC__bitwriter_write_raw_int32(bw, subframe->value, subframe_bps)
  93451. ;
  93452. return ok;
  93453. }
  93454. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93455. {
  93456. unsigned i;
  93457. 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))
  93458. return false;
  93459. if(wasted_bits)
  93460. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93461. return false;
  93462. for(i = 0; i < subframe->order; i++)
  93463. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93464. return false;
  93465. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93466. return false;
  93467. switch(subframe->entropy_coding_method.type) {
  93468. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93469. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93470. if(!add_residual_partitioned_rice_(
  93471. bw,
  93472. subframe->residual,
  93473. residual_samples,
  93474. subframe->order,
  93475. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93476. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93477. subframe->entropy_coding_method.data.partitioned_rice.order,
  93478. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93479. ))
  93480. return false;
  93481. break;
  93482. default:
  93483. FLAC__ASSERT(0);
  93484. }
  93485. return true;
  93486. }
  93487. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93488. {
  93489. unsigned i;
  93490. 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))
  93491. return false;
  93492. if(wasted_bits)
  93493. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93494. return false;
  93495. for(i = 0; i < subframe->order; i++)
  93496. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93497. return false;
  93498. if(!FLAC__bitwriter_write_raw_uint32(bw, subframe->qlp_coeff_precision-1, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  93499. return false;
  93500. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->quantization_level, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  93501. return false;
  93502. for(i = 0; i < subframe->order; i++)
  93503. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->qlp_coeff[i], subframe->qlp_coeff_precision))
  93504. return false;
  93505. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93506. return false;
  93507. switch(subframe->entropy_coding_method.type) {
  93508. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93509. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93510. if(!add_residual_partitioned_rice_(
  93511. bw,
  93512. subframe->residual,
  93513. residual_samples,
  93514. subframe->order,
  93515. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93516. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93517. subframe->entropy_coding_method.data.partitioned_rice.order,
  93518. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93519. ))
  93520. return false;
  93521. break;
  93522. default:
  93523. FLAC__ASSERT(0);
  93524. }
  93525. return true;
  93526. }
  93527. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93528. {
  93529. unsigned i;
  93530. const FLAC__int32 *signal = subframe->data;
  93531. 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))
  93532. return false;
  93533. if(wasted_bits)
  93534. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93535. return false;
  93536. for(i = 0; i < samples; i++)
  93537. if(!FLAC__bitwriter_write_raw_int32(bw, signal[i], subframe_bps))
  93538. return false;
  93539. return true;
  93540. }
  93541. FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method)
  93542. {
  93543. if(!FLAC__bitwriter_write_raw_uint32(bw, method->type, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  93544. return false;
  93545. switch(method->type) {
  93546. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93547. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93548. if(!FLAC__bitwriter_write_raw_uint32(bw, method->data.partitioned_rice.order, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  93549. return false;
  93550. break;
  93551. default:
  93552. FLAC__ASSERT(0);
  93553. }
  93554. return true;
  93555. }
  93556. 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)
  93557. {
  93558. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  93559. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  93560. if(partition_order == 0) {
  93561. unsigned i;
  93562. if(raw_bits[0] == 0) {
  93563. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[0], plen))
  93564. return false;
  93565. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual, residual_samples, rice_parameters[0]))
  93566. return false;
  93567. }
  93568. else {
  93569. FLAC__ASSERT(rice_parameters[0] == 0);
  93570. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  93571. return false;
  93572. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[0], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  93573. return false;
  93574. for(i = 0; i < residual_samples; i++) {
  93575. if(!FLAC__bitwriter_write_raw_int32(bw, residual[i], raw_bits[0]))
  93576. return false;
  93577. }
  93578. }
  93579. return true;
  93580. }
  93581. else {
  93582. unsigned i, j, k = 0, k_last = 0;
  93583. unsigned partition_samples;
  93584. const unsigned default_partition_samples = (residual_samples+predictor_order) >> partition_order;
  93585. for(i = 0; i < (1u<<partition_order); i++) {
  93586. partition_samples = default_partition_samples;
  93587. if(i == 0)
  93588. partition_samples -= predictor_order;
  93589. k += partition_samples;
  93590. if(raw_bits[i] == 0) {
  93591. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[i], plen))
  93592. return false;
  93593. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual+k_last, k-k_last, rice_parameters[i]))
  93594. return false;
  93595. }
  93596. else {
  93597. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  93598. return false;
  93599. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[i], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  93600. return false;
  93601. for(j = k_last; j < k; j++) {
  93602. if(!FLAC__bitwriter_write_raw_int32(bw, residual[j], raw_bits[i]))
  93603. return false;
  93604. }
  93605. }
  93606. k_last = k;
  93607. }
  93608. return true;
  93609. }
  93610. }
  93611. #endif
  93612. /*** End of inlined file: stream_encoder_framing.c ***/
  93613. /*** Start of inlined file: window_flac.c ***/
  93614. /*** Start of inlined file: juce_FlacHeader.h ***/
  93615. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  93616. // tasks..
  93617. #define VERSION "1.2.1"
  93618. #define FLAC__NO_DLL 1
  93619. #if JUCE_MSVC
  93620. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  93621. #endif
  93622. #if JUCE_MAC
  93623. #define FLAC__SYS_DARWIN 1
  93624. #endif
  93625. /*** End of inlined file: juce_FlacHeader.h ***/
  93626. #if JUCE_USE_FLAC
  93627. #if HAVE_CONFIG_H
  93628. # include <config.h>
  93629. #endif
  93630. #include <math.h>
  93631. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  93632. #ifndef M_PI
  93633. #define M_PI 3.14159265358979323846
  93634. #endif
  93635. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L)
  93636. {
  93637. const FLAC__int32 N = L - 1;
  93638. FLAC__int32 n;
  93639. if (L & 1) {
  93640. for (n = 0; n <= N/2; n++)
  93641. window[n] = 2.0f * n / (float)N;
  93642. for (; n <= N; n++)
  93643. window[n] = 2.0f - 2.0f * n / (float)N;
  93644. }
  93645. else {
  93646. for (n = 0; n <= L/2-1; n++)
  93647. window[n] = 2.0f * n / (float)N;
  93648. for (; n <= N; n++)
  93649. window[n] = 2.0f - 2.0f * (N-n) / (float)N;
  93650. }
  93651. }
  93652. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L)
  93653. {
  93654. const FLAC__int32 N = L - 1;
  93655. FLAC__int32 n;
  93656. for (n = 0; n < L; n++)
  93657. 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)));
  93658. }
  93659. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L)
  93660. {
  93661. const FLAC__int32 N = L - 1;
  93662. FLAC__int32 n;
  93663. for (n = 0; n < L; n++)
  93664. window[n] = (FLAC__real)(0.42f - 0.5f * cos(2.0f * M_PI * n / N) + 0.08f * cos(4.0f * M_PI * n / N));
  93665. }
  93666. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L)
  93667. {
  93668. const FLAC__int32 N = L - 1;
  93669. FLAC__int32 n;
  93670. for (n = 0; n <= N; n++)
  93671. 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));
  93672. }
  93673. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L)
  93674. {
  93675. const FLAC__int32 N = L - 1;
  93676. const double N2 = (double)N / 2.;
  93677. FLAC__int32 n;
  93678. for (n = 0; n <= N; n++) {
  93679. double k = ((double)n - N2) / N2;
  93680. k = 1.0f - k * k;
  93681. window[n] = (FLAC__real)(k * k);
  93682. }
  93683. }
  93684. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L)
  93685. {
  93686. const FLAC__int32 N = L - 1;
  93687. FLAC__int32 n;
  93688. for (n = 0; n < L; n++)
  93689. 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));
  93690. }
  93691. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev)
  93692. {
  93693. const FLAC__int32 N = L - 1;
  93694. const double N2 = (double)N / 2.;
  93695. FLAC__int32 n;
  93696. for (n = 0; n <= N; n++) {
  93697. const double k = ((double)n - N2) / (stddev * N2);
  93698. window[n] = (FLAC__real)exp(-0.5f * k * k);
  93699. }
  93700. }
  93701. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L)
  93702. {
  93703. const FLAC__int32 N = L - 1;
  93704. FLAC__int32 n;
  93705. for (n = 0; n < L; n++)
  93706. window[n] = (FLAC__real)(0.54f - 0.46f * cos(2.0f * M_PI * n / N));
  93707. }
  93708. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L)
  93709. {
  93710. const FLAC__int32 N = L - 1;
  93711. FLAC__int32 n;
  93712. for (n = 0; n < L; n++)
  93713. window[n] = (FLAC__real)(0.5f - 0.5f * cos(2.0f * M_PI * n / N));
  93714. }
  93715. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L)
  93716. {
  93717. const FLAC__int32 N = L - 1;
  93718. FLAC__int32 n;
  93719. for (n = 0; n < L; n++)
  93720. 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));
  93721. }
  93722. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L)
  93723. {
  93724. const FLAC__int32 N = L - 1;
  93725. FLAC__int32 n;
  93726. for (n = 0; n < L; n++)
  93727. 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));
  93728. }
  93729. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L)
  93730. {
  93731. FLAC__int32 n;
  93732. for (n = 0; n < L; n++)
  93733. window[n] = 1.0f;
  93734. }
  93735. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L)
  93736. {
  93737. FLAC__int32 n;
  93738. if (L & 1) {
  93739. for (n = 1; n <= L+1/2; n++)
  93740. window[n-1] = 2.0f * n / ((float)L + 1.0f);
  93741. for (; n <= L; n++)
  93742. window[n-1] = - (float)(2 * (L - n + 1)) / ((float)L + 1.0f);
  93743. }
  93744. else {
  93745. for (n = 1; n <= L/2; n++)
  93746. window[n-1] = 2.0f * n / (float)L;
  93747. for (; n <= L; n++)
  93748. window[n-1] = ((float)(2 * (L - n)) + 1.0f) / (float)L;
  93749. }
  93750. }
  93751. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p)
  93752. {
  93753. if (p <= 0.0)
  93754. FLAC__window_rectangle(window, L);
  93755. else if (p >= 1.0)
  93756. FLAC__window_hann(window, L);
  93757. else {
  93758. const FLAC__int32 Np = (FLAC__int32)(p / 2.0f * L) - 1;
  93759. FLAC__int32 n;
  93760. FLAC__window_rectangle(window, L);
  93761. if (Np > 0) {
  93762. for (n = 0; n <= Np; n++) {
  93763. window[n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * n / Np));
  93764. window[L-Np-1+n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * (n+Np) / Np));
  93765. }
  93766. }
  93767. }
  93768. }
  93769. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L)
  93770. {
  93771. const FLAC__int32 N = L - 1;
  93772. const double N2 = (double)N / 2.;
  93773. FLAC__int32 n;
  93774. for (n = 0; n <= N; n++) {
  93775. const double k = ((double)n - N2) / N2;
  93776. window[n] = (FLAC__real)(1.0f - k * k);
  93777. }
  93778. }
  93779. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  93780. #endif
  93781. /*** End of inlined file: window_flac.c ***/
  93782. #else
  93783. #include <FLAC/all.h>
  93784. #endif
  93785. }
  93786. #undef max
  93787. #undef min
  93788. #ifdef _MSC_VER
  93789. #pragma warning (pop)
  93790. #endif
  93791. BEGIN_JUCE_NAMESPACE
  93792. static const char* const flacFormatName = "FLAC file";
  93793. static const juce_wchar* const flacExtensions[] = { T(".flac"), 0 };
  93794. class FlacReader : public AudioFormatReader
  93795. {
  93796. public:
  93797. FlacReader (InputStream* const in)
  93798. : AudioFormatReader (in, TRANS (flacFormatName)),
  93799. reservoir (2, 0),
  93800. reservoirStart (0),
  93801. samplesInReservoir (0),
  93802. scanningForLength (false)
  93803. {
  93804. using namespace FlacNamespace;
  93805. lengthInSamples = 0;
  93806. decoder = FLAC__stream_decoder_new();
  93807. ok = FLAC__stream_decoder_init_stream (decoder,
  93808. readCallback_, seekCallback_, tellCallback_, lengthCallback_,
  93809. eofCallback_, writeCallback_, metadataCallback_, errorCallback_,
  93810. (void*) this) == FLAC__STREAM_DECODER_INIT_STATUS_OK;
  93811. if (ok)
  93812. {
  93813. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  93814. if (lengthInSamples == 0 && sampleRate > 0)
  93815. {
  93816. // the length hasn't been stored in the metadata, so we'll need to
  93817. // work it out the length the hard way, by scanning the whole file..
  93818. scanningForLength = true;
  93819. FLAC__stream_decoder_process_until_end_of_stream (decoder);
  93820. scanningForLength = false;
  93821. const int64 tempLength = lengthInSamples;
  93822. FLAC__stream_decoder_reset (decoder);
  93823. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  93824. lengthInSamples = tempLength;
  93825. }
  93826. }
  93827. }
  93828. ~FlacReader()
  93829. {
  93830. FlacNamespace::FLAC__stream_decoder_delete (decoder);
  93831. }
  93832. void useMetadata (const FlacNamespace::FLAC__StreamMetadata_StreamInfo& info)
  93833. {
  93834. sampleRate = info.sample_rate;
  93835. bitsPerSample = info.bits_per_sample;
  93836. lengthInSamples = (unsigned int) info.total_samples;
  93837. numChannels = info.channels;
  93838. reservoir.setSize (numChannels, 2 * info.max_blocksize, false, false, true);
  93839. }
  93840. // returns the number of samples read
  93841. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  93842. int64 startSampleInFile, int numSamples)
  93843. {
  93844. using namespace FlacNamespace;
  93845. if (! ok)
  93846. return false;
  93847. while (numSamples > 0)
  93848. {
  93849. if (startSampleInFile >= reservoirStart
  93850. && startSampleInFile < reservoirStart + samplesInReservoir)
  93851. {
  93852. const int num = (int) jmin ((int64) numSamples,
  93853. reservoirStart + samplesInReservoir - startSampleInFile);
  93854. jassert (num > 0);
  93855. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  93856. if (destSamples[i] != 0)
  93857. memcpy (destSamples[i] + startOffsetInDestBuffer,
  93858. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  93859. sizeof (int) * num);
  93860. startOffsetInDestBuffer += num;
  93861. startSampleInFile += num;
  93862. numSamples -= num;
  93863. }
  93864. else
  93865. {
  93866. if (startSampleInFile >= (int) lengthInSamples)
  93867. {
  93868. samplesInReservoir = 0;
  93869. }
  93870. else if (startSampleInFile < reservoirStart
  93871. || startSampleInFile > reservoirStart + jmax (samplesInReservoir, 511))
  93872. {
  93873. // had some problems with flac crashing if the read pos is aligned more
  93874. // accurately than this. Probably fixed in newer versions of the library, though.
  93875. reservoirStart = (int) (startSampleInFile & ~511);
  93876. samplesInReservoir = 0;
  93877. FLAC__stream_decoder_seek_absolute (decoder, (FLAC__uint64) reservoirStart);
  93878. }
  93879. else
  93880. {
  93881. reservoirStart += samplesInReservoir;
  93882. samplesInReservoir = 0;
  93883. FLAC__stream_decoder_process_single (decoder);
  93884. }
  93885. if (samplesInReservoir == 0)
  93886. break;
  93887. }
  93888. }
  93889. if (numSamples > 0)
  93890. {
  93891. for (int i = numDestChannels; --i >= 0;)
  93892. if (destSamples[i] != 0)
  93893. zeromem (destSamples[i] + startOffsetInDestBuffer,
  93894. sizeof (int) * numSamples);
  93895. }
  93896. return true;
  93897. }
  93898. void useSamples (const FlacNamespace::FLAC__int32* const buffer[], int numSamples)
  93899. {
  93900. if (scanningForLength)
  93901. {
  93902. lengthInSamples += numSamples;
  93903. }
  93904. else
  93905. {
  93906. if (numSamples > reservoir.getNumSamples())
  93907. reservoir.setSize (numChannels, numSamples, false, false, true);
  93908. const int bitsToShift = 32 - bitsPerSample;
  93909. for (int i = 0; i < (int) numChannels; ++i)
  93910. {
  93911. const FlacNamespace::FLAC__int32* src = buffer[i];
  93912. int n = i;
  93913. while (src == 0 && n > 0)
  93914. src = buffer [--n];
  93915. if (src != 0)
  93916. {
  93917. int* dest = (int*) reservoir.getSampleData(i);
  93918. for (int j = 0; j < numSamples; ++j)
  93919. dest[j] = src[j] << bitsToShift;
  93920. }
  93921. }
  93922. samplesInReservoir = numSamples;
  93923. }
  93924. }
  93925. static FlacNamespace::FLAC__StreamDecoderReadStatus readCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__byte buffer[], size_t* bytes, void* client_data)
  93926. {
  93927. using namespace FlacNamespace;
  93928. *bytes = (size_t) static_cast <const FlacReader*> (client_data)->input->read (buffer, (int) *bytes);
  93929. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  93930. }
  93931. static FlacNamespace::FLAC__StreamDecoderSeekStatus seekCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__uint64 absolute_byte_offset, void* client_data)
  93932. {
  93933. using namespace FlacNamespace;
  93934. static_cast <const FlacReader*> (client_data)->input->setPosition ((int) absolute_byte_offset);
  93935. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  93936. }
  93937. static FlacNamespace::FLAC__StreamDecoderTellStatus tellCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__uint64* absolute_byte_offset, void* client_data)
  93938. {
  93939. using namespace FlacNamespace;
  93940. *absolute_byte_offset = static_cast <const FlacReader*> (client_data)->input->getPosition();
  93941. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  93942. }
  93943. static FlacNamespace::FLAC__StreamDecoderLengthStatus lengthCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__uint64* stream_length, void* client_data)
  93944. {
  93945. using namespace FlacNamespace;
  93946. *stream_length = static_cast <const FlacReader*> (client_data)->input->getTotalLength();
  93947. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  93948. }
  93949. static FlacNamespace::FLAC__bool eofCallback_ (const FlacNamespace::FLAC__StreamDecoder*, void* client_data)
  93950. {
  93951. return static_cast <const FlacReader*> (client_data)->input->isExhausted();
  93952. }
  93953. static FlacNamespace::FLAC__StreamDecoderWriteStatus writeCallback_ (const FlacNamespace::FLAC__StreamDecoder*,
  93954. const FlacNamespace::FLAC__Frame* frame,
  93955. const FlacNamespace::FLAC__int32* const buffer[],
  93956. void* client_data)
  93957. {
  93958. using namespace FlacNamespace;
  93959. static_cast <FlacReader*> (client_data)->useSamples (buffer, frame->header.blocksize);
  93960. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  93961. }
  93962. static void metadataCallback_ (const FlacNamespace::FLAC__StreamDecoder*,
  93963. const FlacNamespace::FLAC__StreamMetadata* metadata,
  93964. void* client_data)
  93965. {
  93966. static_cast <FlacReader*> (client_data)->useMetadata (metadata->data.stream_info);
  93967. }
  93968. static void errorCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__StreamDecoderErrorStatus, void*)
  93969. {
  93970. }
  93971. juce_UseDebuggingNewOperator
  93972. private:
  93973. FlacNamespace::FLAC__StreamDecoder* decoder;
  93974. AudioSampleBuffer reservoir;
  93975. int reservoirStart, samplesInReservoir;
  93976. bool ok, scanningForLength;
  93977. FlacReader (const FlacReader&);
  93978. FlacReader& operator= (const FlacReader&);
  93979. };
  93980. class FlacWriter : public AudioFormatWriter
  93981. {
  93982. public:
  93983. FlacWriter (OutputStream* const out,
  93984. const double sampleRate_,
  93985. const int numChannels_,
  93986. const int bitsPerSample_)
  93987. : AudioFormatWriter (out, TRANS (flacFormatName),
  93988. sampleRate_,
  93989. numChannels_,
  93990. bitsPerSample_)
  93991. {
  93992. using namespace FlacNamespace;
  93993. encoder = FLAC__stream_encoder_new();
  93994. FLAC__stream_encoder_set_do_mid_side_stereo (encoder, numChannels == 2);
  93995. FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, numChannels == 2);
  93996. FLAC__stream_encoder_set_channels (encoder, numChannels);
  93997. FLAC__stream_encoder_set_bits_per_sample (encoder, jmin ((unsigned int) 24, bitsPerSample));
  93998. FLAC__stream_encoder_set_sample_rate (encoder, (unsigned int) sampleRate);
  93999. FLAC__stream_encoder_set_blocksize (encoder, 2048);
  94000. FLAC__stream_encoder_set_do_escape_coding (encoder, true);
  94001. ok = FLAC__stream_encoder_init_stream (encoder,
  94002. encodeWriteCallback, encodeSeekCallback,
  94003. encodeTellCallback, encodeMetadataCallback,
  94004. (void*) this) == FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  94005. }
  94006. ~FlacWriter()
  94007. {
  94008. if (ok)
  94009. {
  94010. FlacNamespace::FLAC__stream_encoder_finish (encoder);
  94011. output->flush();
  94012. }
  94013. else
  94014. {
  94015. output = 0; // to stop the base class deleting this, as it needs to be returned
  94016. // to the caller of createWriter()
  94017. }
  94018. FlacNamespace::FLAC__stream_encoder_delete (encoder);
  94019. }
  94020. bool write (const int** samplesToWrite, int numSamples)
  94021. {
  94022. using namespace FlacNamespace;
  94023. if (! ok)
  94024. return false;
  94025. int* buf[3];
  94026. const int bitsToShift = 32 - bitsPerSample;
  94027. if (bitsToShift > 0)
  94028. {
  94029. const int numChannelsToWrite = (samplesToWrite[1] == 0) ? 1 : 2;
  94030. temp.setSize (sizeof (int) * numSamples * numChannelsToWrite);
  94031. buf[0] = (int*) temp.getData();
  94032. buf[1] = buf[0] + numSamples;
  94033. buf[2] = 0;
  94034. for (int i = numChannelsToWrite; --i >= 0;)
  94035. {
  94036. if (samplesToWrite[i] != 0)
  94037. {
  94038. for (int j = 0; j < numSamples; ++j)
  94039. buf [i][j] = (samplesToWrite [i][j] >> bitsToShift);
  94040. }
  94041. }
  94042. samplesToWrite = (const int**) buf;
  94043. }
  94044. return FLAC__stream_encoder_process (encoder,
  94045. (const FLAC__int32**) samplesToWrite,
  94046. numSamples) != 0;
  94047. }
  94048. bool writeData (const void* const data, const int size) const
  94049. {
  94050. return output->write (data, size);
  94051. }
  94052. static void packUint32 (FlacNamespace::FLAC__uint32 val, FlacNamespace::FLAC__byte* b, const int bytes)
  94053. {
  94054. using namespace FlacNamespace;
  94055. b += bytes;
  94056. for (int i = 0; i < bytes; ++i)
  94057. {
  94058. *(--b) = (FLAC__byte) (val & 0xff);
  94059. val >>= 8;
  94060. }
  94061. }
  94062. void writeMetaData (const FlacNamespace::FLAC__StreamMetadata* metadata)
  94063. {
  94064. using namespace FlacNamespace;
  94065. const FLAC__StreamMetadata_StreamInfo& info = metadata->data.stream_info;
  94066. unsigned char buffer [FLAC__STREAM_METADATA_STREAMINFO_LENGTH];
  94067. const unsigned int channelsMinus1 = info.channels - 1;
  94068. const unsigned int bitsMinus1 = info.bits_per_sample - 1;
  94069. packUint32 (info.min_blocksize, buffer, 2);
  94070. packUint32 (info.max_blocksize, buffer + 2, 2);
  94071. packUint32 (info.min_framesize, buffer + 4, 3);
  94072. packUint32 (info.max_framesize, buffer + 7, 3);
  94073. buffer[10] = (uint8) ((info.sample_rate >> 12) & 0xff);
  94074. buffer[11] = (uint8) ((info.sample_rate >> 4) & 0xff);
  94075. buffer[12] = (uint8) (((info.sample_rate & 0x0f) << 4) | (channelsMinus1 << 1) | (bitsMinus1 >> 4));
  94076. buffer[13] = (FLAC__byte) (((bitsMinus1 & 0x0f) << 4) | (unsigned int) ((info.total_samples >> 32) & 0x0f));
  94077. packUint32 ((FLAC__uint32) info.total_samples, buffer + 14, 4);
  94078. memcpy (buffer + 18, info.md5sum, 16);
  94079. const bool seekOk = output->setPosition (4);
  94080. (void) seekOk;
  94081. // if this fails, you've given it an output stream that can't seek! It needs
  94082. // to be able to seek back to write the header
  94083. jassert (seekOk);
  94084. output->writeIntBigEndian (FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94085. output->write (buffer, FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94086. }
  94087. static FlacNamespace::FLAC__StreamEncoderWriteStatus encodeWriteCallback (const FlacNamespace::FLAC__StreamEncoder*,
  94088. const FlacNamespace::FLAC__byte buffer[],
  94089. size_t bytes,
  94090. unsigned int /*samples*/,
  94091. unsigned int /*current_frame*/,
  94092. void* client_data)
  94093. {
  94094. using namespace FlacNamespace;
  94095. return static_cast <FlacWriter*> (client_data)->writeData (buffer, (int) bytes)
  94096. ? FLAC__STREAM_ENCODER_WRITE_STATUS_OK
  94097. : FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  94098. }
  94099. static FlacNamespace::FLAC__StreamEncoderSeekStatus encodeSeekCallback (const FlacNamespace::FLAC__StreamEncoder*, FlacNamespace::FLAC__uint64, void*)
  94100. {
  94101. using namespace FlacNamespace;
  94102. return FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED;
  94103. }
  94104. static FlacNamespace::FLAC__StreamEncoderTellStatus encodeTellCallback (const FlacNamespace::FLAC__StreamEncoder*, FlacNamespace::FLAC__uint64* absolute_byte_offset, void* client_data)
  94105. {
  94106. using namespace FlacNamespace;
  94107. if (client_data == 0)
  94108. return FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED;
  94109. *absolute_byte_offset = (FLAC__uint64) static_cast <FlacWriter*> (client_data)->output->getPosition();
  94110. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  94111. }
  94112. static void encodeMetadataCallback (const FlacNamespace::FLAC__StreamEncoder*, const FlacNamespace::FLAC__StreamMetadata* metadata, void* client_data)
  94113. {
  94114. static_cast <FlacWriter*> (client_data)->writeMetaData (metadata);
  94115. }
  94116. juce_UseDebuggingNewOperator
  94117. bool ok;
  94118. private:
  94119. FlacNamespace::FLAC__StreamEncoder* encoder;
  94120. MemoryBlock temp;
  94121. FlacWriter (const FlacWriter&);
  94122. FlacWriter& operator= (const FlacWriter&);
  94123. };
  94124. FlacAudioFormat::FlacAudioFormat()
  94125. : AudioFormat (TRANS (flacFormatName), (const juce_wchar**) flacExtensions)
  94126. {
  94127. }
  94128. FlacAudioFormat::~FlacAudioFormat()
  94129. {
  94130. }
  94131. const Array <int> FlacAudioFormat::getPossibleSampleRates()
  94132. {
  94133. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 0 };
  94134. return Array <int> (rates);
  94135. }
  94136. const Array <int> FlacAudioFormat::getPossibleBitDepths()
  94137. {
  94138. const int depths[] = { 16, 24, 0 };
  94139. return Array <int> (depths);
  94140. }
  94141. bool FlacAudioFormat::canDoStereo()
  94142. {
  94143. return true;
  94144. }
  94145. bool FlacAudioFormat::canDoMono()
  94146. {
  94147. return true;
  94148. }
  94149. bool FlacAudioFormat::isCompressed()
  94150. {
  94151. return true;
  94152. }
  94153. AudioFormatReader* FlacAudioFormat::createReaderFor (InputStream* in,
  94154. const bool deleteStreamIfOpeningFails)
  94155. {
  94156. ScopedPointer<FlacReader> r (new FlacReader (in));
  94157. if (r->sampleRate != 0)
  94158. return r.release();
  94159. if (! deleteStreamIfOpeningFails)
  94160. r->input = 0;
  94161. return 0;
  94162. }
  94163. AudioFormatWriter* FlacAudioFormat::createWriterFor (OutputStream* out,
  94164. double sampleRate,
  94165. unsigned int numberOfChannels,
  94166. int bitsPerSample,
  94167. const StringPairArray& /*metadataValues*/,
  94168. int /*qualityOptionIndex*/)
  94169. {
  94170. if (getPossibleBitDepths().contains (bitsPerSample))
  94171. {
  94172. ScopedPointer<FlacWriter> w (new FlacWriter (out, sampleRate, numberOfChannels, bitsPerSample));
  94173. if (w->ok)
  94174. return w.release();
  94175. }
  94176. return 0;
  94177. }
  94178. END_JUCE_NAMESPACE
  94179. #endif
  94180. /*** End of inlined file: juce_FlacAudioFormat.cpp ***/
  94181. /*** Start of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  94182. #if JUCE_USE_OGGVORBIS
  94183. #if JUCE_MAC
  94184. #define __MACOSX__ 1
  94185. #endif
  94186. namespace OggVorbisNamespace
  94187. {
  94188. #if JUCE_INCLUDE_OGGVORBIS_CODE
  94189. /*** Start of inlined file: vorbisenc.h ***/
  94190. #ifndef _OV_ENC_H_
  94191. #define _OV_ENC_H_
  94192. #ifdef __cplusplus
  94193. extern "C"
  94194. {
  94195. #endif /* __cplusplus */
  94196. /*** Start of inlined file: codec.h ***/
  94197. #ifndef _vorbis_codec_h_
  94198. #define _vorbis_codec_h_
  94199. #ifdef __cplusplus
  94200. extern "C"
  94201. {
  94202. #endif /* __cplusplus */
  94203. /*** Start of inlined file: ogg.h ***/
  94204. #ifndef _OGG_H
  94205. #define _OGG_H
  94206. #ifdef __cplusplus
  94207. extern "C" {
  94208. #endif
  94209. /*** Start of inlined file: os_types.h ***/
  94210. #ifndef _OS_TYPES_H
  94211. #define _OS_TYPES_H
  94212. #define _ogg_malloc malloc
  94213. #define _ogg_calloc calloc
  94214. #define _ogg_realloc realloc
  94215. #define _ogg_free free
  94216. #if defined(_WIN32)
  94217. # if defined(__CYGWIN__)
  94218. # include <_G_config.h>
  94219. typedef _G_int64_t ogg_int64_t;
  94220. typedef _G_int32_t ogg_int32_t;
  94221. typedef _G_uint32_t ogg_uint32_t;
  94222. typedef _G_int16_t ogg_int16_t;
  94223. typedef _G_uint16_t ogg_uint16_t;
  94224. # elif defined(__MINGW32__)
  94225. typedef short ogg_int16_t;
  94226. typedef unsigned short ogg_uint16_t;
  94227. typedef int ogg_int32_t;
  94228. typedef unsigned int ogg_uint32_t;
  94229. typedef long long ogg_int64_t;
  94230. typedef unsigned long long ogg_uint64_t;
  94231. # elif defined(__MWERKS__)
  94232. typedef long long ogg_int64_t;
  94233. typedef int ogg_int32_t;
  94234. typedef unsigned int ogg_uint32_t;
  94235. typedef short ogg_int16_t;
  94236. typedef unsigned short ogg_uint16_t;
  94237. # else
  94238. typedef __int64 ogg_int64_t;
  94239. typedef __int32 ogg_int32_t;
  94240. typedef unsigned __int32 ogg_uint32_t;
  94241. typedef __int16 ogg_int16_t;
  94242. typedef unsigned __int16 ogg_uint16_t;
  94243. # endif
  94244. #elif defined(__MACOS__)
  94245. # include <sys/types.h>
  94246. typedef SInt16 ogg_int16_t;
  94247. typedef UInt16 ogg_uint16_t;
  94248. typedef SInt32 ogg_int32_t;
  94249. typedef UInt32 ogg_uint32_t;
  94250. typedef SInt64 ogg_int64_t;
  94251. #elif defined(__MACOSX__) /* MacOS X Framework build */
  94252. # include <sys/types.h>
  94253. typedef int16_t ogg_int16_t;
  94254. typedef u_int16_t ogg_uint16_t;
  94255. typedef int32_t ogg_int32_t;
  94256. typedef u_int32_t ogg_uint32_t;
  94257. typedef int64_t ogg_int64_t;
  94258. #elif defined(__BEOS__)
  94259. # include <inttypes.h>
  94260. typedef int16_t ogg_int16_t;
  94261. typedef u_int16_t ogg_uint16_t;
  94262. typedef int32_t ogg_int32_t;
  94263. typedef u_int32_t ogg_uint32_t;
  94264. typedef int64_t ogg_int64_t;
  94265. #elif defined (__EMX__)
  94266. typedef short ogg_int16_t;
  94267. typedef unsigned short ogg_uint16_t;
  94268. typedef int ogg_int32_t;
  94269. typedef unsigned int ogg_uint32_t;
  94270. typedef long long ogg_int64_t;
  94271. #elif defined (DJGPP)
  94272. typedef short ogg_int16_t;
  94273. typedef int ogg_int32_t;
  94274. typedef unsigned int ogg_uint32_t;
  94275. typedef long long ogg_int64_t;
  94276. #elif defined(R5900)
  94277. typedef long ogg_int64_t;
  94278. typedef int ogg_int32_t;
  94279. typedef unsigned ogg_uint32_t;
  94280. typedef short ogg_int16_t;
  94281. #elif defined(__SYMBIAN32__)
  94282. typedef signed short ogg_int16_t;
  94283. typedef unsigned short ogg_uint16_t;
  94284. typedef signed int ogg_int32_t;
  94285. typedef unsigned int ogg_uint32_t;
  94286. typedef long long int ogg_int64_t;
  94287. #else
  94288. # include <sys/types.h>
  94289. /*** Start of inlined file: config_types.h ***/
  94290. #ifndef __CONFIG_TYPES_H__
  94291. #define __CONFIG_TYPES_H__
  94292. typedef int16_t ogg_int16_t;
  94293. typedef unsigned short ogg_uint16_t;
  94294. typedef int32_t ogg_int32_t;
  94295. typedef unsigned int ogg_uint32_t;
  94296. typedef int64_t ogg_int64_t;
  94297. #endif
  94298. /*** End of inlined file: config_types.h ***/
  94299. #endif
  94300. #endif /* _OS_TYPES_H */
  94301. /*** End of inlined file: os_types.h ***/
  94302. typedef struct {
  94303. long endbyte;
  94304. int endbit;
  94305. unsigned char *buffer;
  94306. unsigned char *ptr;
  94307. long storage;
  94308. } oggpack_buffer;
  94309. typedef struct {
  94310. unsigned char *header;
  94311. long header_len;
  94312. unsigned char *body;
  94313. long body_len;
  94314. } ogg_page;
  94315. ogg_uint32_t ogg_bitreverse(ogg_uint32_t x){
  94316. x= ((x>>16)&0x0000ffffUL) | ((x<<16)&0xffff0000UL);
  94317. x= ((x>> 8)&0x00ff00ffUL) | ((x<< 8)&0xff00ff00UL);
  94318. x= ((x>> 4)&0x0f0f0f0fUL) | ((x<< 4)&0xf0f0f0f0UL);
  94319. x= ((x>> 2)&0x33333333UL) | ((x<< 2)&0xccccccccUL);
  94320. return((x>> 1)&0x55555555UL) | ((x<< 1)&0xaaaaaaaaUL);
  94321. }
  94322. typedef struct {
  94323. unsigned char *body_data; /* bytes from packet bodies */
  94324. long body_storage; /* storage elements allocated */
  94325. long body_fill; /* elements stored; fill mark */
  94326. long body_returned; /* elements of fill returned */
  94327. int *lacing_vals; /* The values that will go to the segment table */
  94328. ogg_int64_t *granule_vals; /* granulepos values for headers. Not compact
  94329. this way, but it is simple coupled to the
  94330. lacing fifo */
  94331. long lacing_storage;
  94332. long lacing_fill;
  94333. long lacing_packet;
  94334. long lacing_returned;
  94335. unsigned char header[282]; /* working space for header encode */
  94336. int header_fill;
  94337. int e_o_s; /* set when we have buffered the last packet in the
  94338. logical bitstream */
  94339. int b_o_s; /* set after we've written the initial page
  94340. of a logical bitstream */
  94341. long serialno;
  94342. long pageno;
  94343. ogg_int64_t packetno; /* sequence number for decode; the framing
  94344. knows where there's a hole in the data,
  94345. but we need coupling so that the codec
  94346. (which is in a seperate abstraction
  94347. layer) also knows about the gap */
  94348. ogg_int64_t granulepos;
  94349. } ogg_stream_state;
  94350. typedef struct {
  94351. unsigned char *packet;
  94352. long bytes;
  94353. long b_o_s;
  94354. long e_o_s;
  94355. ogg_int64_t granulepos;
  94356. ogg_int64_t packetno; /* sequence number for decode; the framing
  94357. knows where there's a hole in the data,
  94358. but we need coupling so that the codec
  94359. (which is in a seperate abstraction
  94360. layer) also knows about the gap */
  94361. } ogg_packet;
  94362. typedef struct {
  94363. unsigned char *data;
  94364. int storage;
  94365. int fill;
  94366. int returned;
  94367. int unsynced;
  94368. int headerbytes;
  94369. int bodybytes;
  94370. } ogg_sync_state;
  94371. extern void oggpack_writeinit(oggpack_buffer *b);
  94372. extern void oggpack_writetrunc(oggpack_buffer *b,long bits);
  94373. extern void oggpack_writealign(oggpack_buffer *b);
  94374. extern void oggpack_writecopy(oggpack_buffer *b,void *source,long bits);
  94375. extern void oggpack_reset(oggpack_buffer *b);
  94376. extern void oggpack_writeclear(oggpack_buffer *b);
  94377. extern void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94378. extern void oggpack_write(oggpack_buffer *b,unsigned long value,int bits);
  94379. extern long oggpack_look(oggpack_buffer *b,int bits);
  94380. extern long oggpack_look1(oggpack_buffer *b);
  94381. extern void oggpack_adv(oggpack_buffer *b,int bits);
  94382. extern void oggpack_adv1(oggpack_buffer *b);
  94383. extern long oggpack_read(oggpack_buffer *b,int bits);
  94384. extern long oggpack_read1(oggpack_buffer *b);
  94385. extern long oggpack_bytes(oggpack_buffer *b);
  94386. extern long oggpack_bits(oggpack_buffer *b);
  94387. extern unsigned char *oggpack_get_buffer(oggpack_buffer *b);
  94388. extern void oggpackB_writeinit(oggpack_buffer *b);
  94389. extern void oggpackB_writetrunc(oggpack_buffer *b,long bits);
  94390. extern void oggpackB_writealign(oggpack_buffer *b);
  94391. extern void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits);
  94392. extern void oggpackB_reset(oggpack_buffer *b);
  94393. extern void oggpackB_writeclear(oggpack_buffer *b);
  94394. extern void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94395. extern void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits);
  94396. extern long oggpackB_look(oggpack_buffer *b,int bits);
  94397. extern long oggpackB_look1(oggpack_buffer *b);
  94398. extern void oggpackB_adv(oggpack_buffer *b,int bits);
  94399. extern void oggpackB_adv1(oggpack_buffer *b);
  94400. extern long oggpackB_read(oggpack_buffer *b,int bits);
  94401. extern long oggpackB_read1(oggpack_buffer *b);
  94402. extern long oggpackB_bytes(oggpack_buffer *b);
  94403. extern long oggpackB_bits(oggpack_buffer *b);
  94404. extern unsigned char *oggpackB_get_buffer(oggpack_buffer *b);
  94405. extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
  94406. extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
  94407. extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og);
  94408. extern int ogg_sync_init(ogg_sync_state *oy);
  94409. extern int ogg_sync_clear(ogg_sync_state *oy);
  94410. extern int ogg_sync_reset(ogg_sync_state *oy);
  94411. extern int ogg_sync_destroy(ogg_sync_state *oy);
  94412. extern char *ogg_sync_buffer(ogg_sync_state *oy, long size);
  94413. extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
  94414. extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
  94415. extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
  94416. extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
  94417. extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
  94418. extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
  94419. extern int ogg_stream_init(ogg_stream_state *os,int serialno);
  94420. extern int ogg_stream_clear(ogg_stream_state *os);
  94421. extern int ogg_stream_reset(ogg_stream_state *os);
  94422. extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno);
  94423. extern int ogg_stream_destroy(ogg_stream_state *os);
  94424. extern int ogg_stream_eos(ogg_stream_state *os);
  94425. extern void ogg_page_checksum_set(ogg_page *og);
  94426. extern int ogg_page_version(ogg_page *og);
  94427. extern int ogg_page_continued(ogg_page *og);
  94428. extern int ogg_page_bos(ogg_page *og);
  94429. extern int ogg_page_eos(ogg_page *og);
  94430. extern ogg_int64_t ogg_page_granulepos(ogg_page *og);
  94431. extern int ogg_page_serialno(ogg_page *og);
  94432. extern long ogg_page_pageno(ogg_page *og);
  94433. extern int ogg_page_packets(ogg_page *og);
  94434. extern void ogg_packet_clear(ogg_packet *op);
  94435. #ifdef __cplusplus
  94436. }
  94437. #endif
  94438. #endif /* _OGG_H */
  94439. /*** End of inlined file: ogg.h ***/
  94440. typedef struct vorbis_info{
  94441. int version;
  94442. int channels;
  94443. long rate;
  94444. long bitrate_upper;
  94445. long bitrate_nominal;
  94446. long bitrate_lower;
  94447. long bitrate_window;
  94448. void *codec_setup;
  94449. } vorbis_info;
  94450. typedef struct vorbis_dsp_state{
  94451. int analysisp;
  94452. vorbis_info *vi;
  94453. float **pcm;
  94454. float **pcmret;
  94455. int pcm_storage;
  94456. int pcm_current;
  94457. int pcm_returned;
  94458. int preextrapolate;
  94459. int eofflag;
  94460. long lW;
  94461. long W;
  94462. long nW;
  94463. long centerW;
  94464. ogg_int64_t granulepos;
  94465. ogg_int64_t sequence;
  94466. ogg_int64_t glue_bits;
  94467. ogg_int64_t time_bits;
  94468. ogg_int64_t floor_bits;
  94469. ogg_int64_t res_bits;
  94470. void *backend_state;
  94471. } vorbis_dsp_state;
  94472. typedef struct vorbis_block{
  94473. float **pcm; /* this is a pointer into local storage */
  94474. oggpack_buffer opb;
  94475. long lW;
  94476. long W;
  94477. long nW;
  94478. int pcmend;
  94479. int mode;
  94480. int eofflag;
  94481. ogg_int64_t granulepos;
  94482. ogg_int64_t sequence;
  94483. vorbis_dsp_state *vd; /* For read-only access of configuration */
  94484. void *localstore;
  94485. long localtop;
  94486. long localalloc;
  94487. long totaluse;
  94488. struct alloc_chain *reap;
  94489. long glue_bits;
  94490. long time_bits;
  94491. long floor_bits;
  94492. long res_bits;
  94493. void *internal;
  94494. } vorbis_block;
  94495. struct alloc_chain{
  94496. void *ptr;
  94497. struct alloc_chain *next;
  94498. };
  94499. typedef struct vorbis_comment{
  94500. char **user_comments;
  94501. int *comment_lengths;
  94502. int comments;
  94503. char *vendor;
  94504. } vorbis_comment;
  94505. extern void vorbis_info_init(vorbis_info *vi);
  94506. extern void vorbis_info_clear(vorbis_info *vi);
  94507. extern int vorbis_info_blocksize(vorbis_info *vi,int zo);
  94508. extern void vorbis_comment_init(vorbis_comment *vc);
  94509. extern void vorbis_comment_add(vorbis_comment *vc, char *comment);
  94510. extern void vorbis_comment_add_tag(vorbis_comment *vc,
  94511. const char *tag, char *contents);
  94512. extern char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count);
  94513. extern int vorbis_comment_query_count(vorbis_comment *vc, char *tag);
  94514. extern void vorbis_comment_clear(vorbis_comment *vc);
  94515. extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
  94516. extern int vorbis_block_clear(vorbis_block *vb);
  94517. extern void vorbis_dsp_clear(vorbis_dsp_state *v);
  94518. extern double vorbis_granule_time(vorbis_dsp_state *v,
  94519. ogg_int64_t granulepos);
  94520. extern int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi);
  94521. extern int vorbis_commentheader_out(vorbis_comment *vc, ogg_packet *op);
  94522. extern int vorbis_analysis_headerout(vorbis_dsp_state *v,
  94523. vorbis_comment *vc,
  94524. ogg_packet *op,
  94525. ogg_packet *op_comm,
  94526. ogg_packet *op_code);
  94527. extern float **vorbis_analysis_buffer(vorbis_dsp_state *v,int vals);
  94528. extern int vorbis_analysis_wrote(vorbis_dsp_state *v,int vals);
  94529. extern int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb);
  94530. extern int vorbis_analysis(vorbis_block *vb,ogg_packet *op);
  94531. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  94532. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,
  94533. ogg_packet *op);
  94534. extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,
  94535. ogg_packet *op);
  94536. extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi);
  94537. extern int vorbis_synthesis_restart(vorbis_dsp_state *v);
  94538. extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op);
  94539. extern int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op);
  94540. extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb);
  94541. extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm);
  94542. extern int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm);
  94543. extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples);
  94544. extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op);
  94545. extern int vorbis_synthesis_halfrate(vorbis_info *v,int flag);
  94546. extern int vorbis_synthesis_halfrate_p(vorbis_info *v);
  94547. #define OV_FALSE -1
  94548. #define OV_EOF -2
  94549. #define OV_HOLE -3
  94550. #define OV_EREAD -128
  94551. #define OV_EFAULT -129
  94552. #define OV_EIMPL -130
  94553. #define OV_EINVAL -131
  94554. #define OV_ENOTVORBIS -132
  94555. #define OV_EBADHEADER -133
  94556. #define OV_EVERSION -134
  94557. #define OV_ENOTAUDIO -135
  94558. #define OV_EBADPACKET -136
  94559. #define OV_EBADLINK -137
  94560. #define OV_ENOSEEK -138
  94561. #ifdef __cplusplus
  94562. }
  94563. #endif /* __cplusplus */
  94564. #endif
  94565. /*** End of inlined file: codec.h ***/
  94566. extern int vorbis_encode_init(vorbis_info *vi,
  94567. long channels,
  94568. long rate,
  94569. long max_bitrate,
  94570. long nominal_bitrate,
  94571. long min_bitrate);
  94572. extern int vorbis_encode_setup_managed(vorbis_info *vi,
  94573. long channels,
  94574. long rate,
  94575. long max_bitrate,
  94576. long nominal_bitrate,
  94577. long min_bitrate);
  94578. extern int vorbis_encode_setup_vbr(vorbis_info *vi,
  94579. long channels,
  94580. long rate,
  94581. float quality /* quality level from 0. (lo) to 1. (hi) */
  94582. );
  94583. extern int vorbis_encode_init_vbr(vorbis_info *vi,
  94584. long channels,
  94585. long rate,
  94586. float base_quality /* quality level from 0. (lo) to 1. (hi) */
  94587. );
  94588. extern int vorbis_encode_setup_init(vorbis_info *vi);
  94589. extern int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg);
  94590. #define OV_ECTL_RATEMANAGE_GET 0x10
  94591. #define OV_ECTL_RATEMANAGE_SET 0x11
  94592. #define OV_ECTL_RATEMANAGE_AVG 0x12
  94593. #define OV_ECTL_RATEMANAGE_HARD 0x13
  94594. struct ovectl_ratemanage_arg {
  94595. int management_active;
  94596. long bitrate_hard_min;
  94597. long bitrate_hard_max;
  94598. double bitrate_hard_window;
  94599. long bitrate_av_lo;
  94600. long bitrate_av_hi;
  94601. double bitrate_av_window;
  94602. double bitrate_av_window_center;
  94603. };
  94604. #define OV_ECTL_RATEMANAGE2_GET 0x14
  94605. #define OV_ECTL_RATEMANAGE2_SET 0x15
  94606. struct ovectl_ratemanage2_arg {
  94607. int management_active;
  94608. long bitrate_limit_min_kbps;
  94609. long bitrate_limit_max_kbps;
  94610. long bitrate_limit_reservoir_bits;
  94611. double bitrate_limit_reservoir_bias;
  94612. long bitrate_average_kbps;
  94613. double bitrate_average_damping;
  94614. };
  94615. #define OV_ECTL_LOWPASS_GET 0x20
  94616. #define OV_ECTL_LOWPASS_SET 0x21
  94617. #define OV_ECTL_IBLOCK_GET 0x30
  94618. #define OV_ECTL_IBLOCK_SET 0x31
  94619. #ifdef __cplusplus
  94620. }
  94621. #endif /* __cplusplus */
  94622. #endif
  94623. /*** End of inlined file: vorbisenc.h ***/
  94624. /*** Start of inlined file: vorbisfile.h ***/
  94625. #ifndef _OV_FILE_H_
  94626. #define _OV_FILE_H_
  94627. #ifdef __cplusplus
  94628. extern "C"
  94629. {
  94630. #endif /* __cplusplus */
  94631. #include <stdio.h>
  94632. typedef struct {
  94633. size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource);
  94634. int (*seek_func) (void *datasource, ogg_int64_t offset, int whence);
  94635. int (*close_func) (void *datasource);
  94636. long (*tell_func) (void *datasource);
  94637. } ov_callbacks;
  94638. #define NOTOPEN 0
  94639. #define PARTOPEN 1
  94640. #define OPENED 2
  94641. #define STREAMSET 3
  94642. #define INITSET 4
  94643. typedef struct OggVorbis_File {
  94644. void *datasource; /* Pointer to a FILE *, etc. */
  94645. int seekable;
  94646. ogg_int64_t offset;
  94647. ogg_int64_t end;
  94648. ogg_sync_state oy;
  94649. int links;
  94650. ogg_int64_t *offsets;
  94651. ogg_int64_t *dataoffsets;
  94652. long *serialnos;
  94653. ogg_int64_t *pcmlengths; /* overloaded to maintain binary
  94654. compatability; x2 size, stores both
  94655. beginning and end values */
  94656. vorbis_info *vi;
  94657. vorbis_comment *vc;
  94658. ogg_int64_t pcm_offset;
  94659. int ready_state;
  94660. long current_serialno;
  94661. int current_link;
  94662. double bittrack;
  94663. double samptrack;
  94664. ogg_stream_state os; /* take physical pages, weld into a logical
  94665. stream of packets */
  94666. vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
  94667. vorbis_block vb; /* local working space for packet->PCM decode */
  94668. ov_callbacks callbacks;
  94669. } OggVorbis_File;
  94670. extern int ov_clear(OggVorbis_File *vf);
  94671. extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  94672. extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
  94673. char *initial, long ibytes, ov_callbacks callbacks);
  94674. extern int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  94675. extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf,
  94676. char *initial, long ibytes, ov_callbacks callbacks);
  94677. extern int ov_test_open(OggVorbis_File *vf);
  94678. extern long ov_bitrate(OggVorbis_File *vf,int i);
  94679. extern long ov_bitrate_instant(OggVorbis_File *vf);
  94680. extern long ov_streams(OggVorbis_File *vf);
  94681. extern long ov_seekable(OggVorbis_File *vf);
  94682. extern long ov_serialnumber(OggVorbis_File *vf,int i);
  94683. extern ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i);
  94684. extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
  94685. extern double ov_time_total(OggVorbis_File *vf,int i);
  94686. extern int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos);
  94687. extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos);
  94688. extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
  94689. extern int ov_time_seek(OggVorbis_File *vf,double pos);
  94690. extern int ov_time_seek_page(OggVorbis_File *vf,double pos);
  94691. extern int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94692. extern int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94693. extern int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94694. extern int ov_time_seek_lap(OggVorbis_File *vf,double pos);
  94695. extern int ov_time_seek_page_lap(OggVorbis_File *vf,double pos);
  94696. extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf);
  94697. extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf);
  94698. extern double ov_time_tell(OggVorbis_File *vf);
  94699. extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
  94700. extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
  94701. extern long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int samples,
  94702. int *bitstream);
  94703. extern long ov_read(OggVorbis_File *vf,char *buffer,int length,
  94704. int bigendianp,int word,int sgned,int *bitstream);
  94705. extern int ov_crosslap(OggVorbis_File *vf1,OggVorbis_File *vf2);
  94706. extern int ov_halfrate(OggVorbis_File *vf,int flag);
  94707. extern int ov_halfrate_p(OggVorbis_File *vf);
  94708. #ifdef __cplusplus
  94709. }
  94710. #endif /* __cplusplus */
  94711. #endif
  94712. /*** End of inlined file: vorbisfile.h ***/
  94713. /*** Start of inlined file: bitwise.c ***/
  94714. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  94715. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  94716. // tasks..
  94717. #if JUCE_MSVC
  94718. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  94719. #endif
  94720. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  94721. #if JUCE_USE_OGGVORBIS
  94722. #include <string.h>
  94723. #include <stdlib.h>
  94724. #define BUFFER_INCREMENT 256
  94725. static const unsigned long mask[]=
  94726. {0x00000000,0x00000001,0x00000003,0x00000007,0x0000000f,
  94727. 0x0000001f,0x0000003f,0x0000007f,0x000000ff,0x000001ff,
  94728. 0x000003ff,0x000007ff,0x00000fff,0x00001fff,0x00003fff,
  94729. 0x00007fff,0x0000ffff,0x0001ffff,0x0003ffff,0x0007ffff,
  94730. 0x000fffff,0x001fffff,0x003fffff,0x007fffff,0x00ffffff,
  94731. 0x01ffffff,0x03ffffff,0x07ffffff,0x0fffffff,0x1fffffff,
  94732. 0x3fffffff,0x7fffffff,0xffffffff };
  94733. static const unsigned int mask8B[]=
  94734. {0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
  94735. void oggpack_writeinit(oggpack_buffer *b){
  94736. memset(b,0,sizeof(*b));
  94737. b->ptr=b->buffer=(unsigned char*) _ogg_malloc(BUFFER_INCREMENT);
  94738. b->buffer[0]='\0';
  94739. b->storage=BUFFER_INCREMENT;
  94740. }
  94741. void oggpackB_writeinit(oggpack_buffer *b){
  94742. oggpack_writeinit(b);
  94743. }
  94744. void oggpack_writetrunc(oggpack_buffer *b,long bits){
  94745. long bytes=bits>>3;
  94746. bits-=bytes*8;
  94747. b->ptr=b->buffer+bytes;
  94748. b->endbit=bits;
  94749. b->endbyte=bytes;
  94750. *b->ptr&=mask[bits];
  94751. }
  94752. void oggpackB_writetrunc(oggpack_buffer *b,long bits){
  94753. long bytes=bits>>3;
  94754. bits-=bytes*8;
  94755. b->ptr=b->buffer+bytes;
  94756. b->endbit=bits;
  94757. b->endbyte=bytes;
  94758. *b->ptr&=mask8B[bits];
  94759. }
  94760. void oggpack_write(oggpack_buffer *b,unsigned long value,int bits){
  94761. if(b->endbyte+4>=b->storage){
  94762. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  94763. b->storage+=BUFFER_INCREMENT;
  94764. b->ptr=b->buffer+b->endbyte;
  94765. }
  94766. value&=mask[bits];
  94767. bits+=b->endbit;
  94768. b->ptr[0]|=value<<b->endbit;
  94769. if(bits>=8){
  94770. b->ptr[1]=(unsigned char)(value>>(8-b->endbit));
  94771. if(bits>=16){
  94772. b->ptr[2]=(unsigned char)(value>>(16-b->endbit));
  94773. if(bits>=24){
  94774. b->ptr[3]=(unsigned char)(value>>(24-b->endbit));
  94775. if(bits>=32){
  94776. if(b->endbit)
  94777. b->ptr[4]=(unsigned char)(value>>(32-b->endbit));
  94778. else
  94779. b->ptr[4]=0;
  94780. }
  94781. }
  94782. }
  94783. }
  94784. b->endbyte+=bits/8;
  94785. b->ptr+=bits/8;
  94786. b->endbit=bits&7;
  94787. }
  94788. void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits){
  94789. if(b->endbyte+4>=b->storage){
  94790. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  94791. b->storage+=BUFFER_INCREMENT;
  94792. b->ptr=b->buffer+b->endbyte;
  94793. }
  94794. value=(value&mask[bits])<<(32-bits);
  94795. bits+=b->endbit;
  94796. b->ptr[0]|=value>>(24+b->endbit);
  94797. if(bits>=8){
  94798. b->ptr[1]=(unsigned char)(value>>(16+b->endbit));
  94799. if(bits>=16){
  94800. b->ptr[2]=(unsigned char)(value>>(8+b->endbit));
  94801. if(bits>=24){
  94802. b->ptr[3]=(unsigned char)(value>>(b->endbit));
  94803. if(bits>=32){
  94804. if(b->endbit)
  94805. b->ptr[4]=(unsigned char)(value<<(8-b->endbit));
  94806. else
  94807. b->ptr[4]=0;
  94808. }
  94809. }
  94810. }
  94811. }
  94812. b->endbyte+=bits/8;
  94813. b->ptr+=bits/8;
  94814. b->endbit=bits&7;
  94815. }
  94816. void oggpack_writealign(oggpack_buffer *b){
  94817. int bits=8-b->endbit;
  94818. if(bits<8)
  94819. oggpack_write(b,0,bits);
  94820. }
  94821. void oggpackB_writealign(oggpack_buffer *b){
  94822. int bits=8-b->endbit;
  94823. if(bits<8)
  94824. oggpackB_write(b,0,bits);
  94825. }
  94826. static void oggpack_writecopy_helper(oggpack_buffer *b,
  94827. void *source,
  94828. long bits,
  94829. void (*w)(oggpack_buffer *,
  94830. unsigned long,
  94831. int),
  94832. int msb){
  94833. unsigned char *ptr=(unsigned char *)source;
  94834. long bytes=bits/8;
  94835. bits-=bytes*8;
  94836. if(b->endbit){
  94837. int i;
  94838. for(i=0;i<bytes;i++)
  94839. w(b,(unsigned long)(ptr[i]),8);
  94840. }else{
  94841. if(b->endbyte+bytes+1>=b->storage){
  94842. b->storage=b->endbyte+bytes+BUFFER_INCREMENT;
  94843. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage);
  94844. b->ptr=b->buffer+b->endbyte;
  94845. }
  94846. memmove(b->ptr,source,bytes);
  94847. b->ptr+=bytes;
  94848. b->endbyte+=bytes;
  94849. *b->ptr=0;
  94850. }
  94851. if(bits){
  94852. if(msb)
  94853. w(b,(unsigned long)(ptr[bytes]>>(8-bits)),bits);
  94854. else
  94855. w(b,(unsigned long)(ptr[bytes]),bits);
  94856. }
  94857. }
  94858. void oggpack_writecopy(oggpack_buffer *b,void *source,long bits){
  94859. oggpack_writecopy_helper(b,source,bits,oggpack_write,0);
  94860. }
  94861. void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits){
  94862. oggpack_writecopy_helper(b,source,bits,oggpackB_write,1);
  94863. }
  94864. void oggpack_reset(oggpack_buffer *b){
  94865. b->ptr=b->buffer;
  94866. b->buffer[0]=0;
  94867. b->endbit=b->endbyte=0;
  94868. }
  94869. void oggpackB_reset(oggpack_buffer *b){
  94870. oggpack_reset(b);
  94871. }
  94872. void oggpack_writeclear(oggpack_buffer *b){
  94873. _ogg_free(b->buffer);
  94874. memset(b,0,sizeof(*b));
  94875. }
  94876. void oggpackB_writeclear(oggpack_buffer *b){
  94877. oggpack_writeclear(b);
  94878. }
  94879. void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  94880. memset(b,0,sizeof(*b));
  94881. b->buffer=b->ptr=buf;
  94882. b->storage=bytes;
  94883. }
  94884. void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  94885. oggpack_readinit(b,buf,bytes);
  94886. }
  94887. long oggpack_look(oggpack_buffer *b,int bits){
  94888. unsigned long ret;
  94889. unsigned long m=mask[bits];
  94890. bits+=b->endbit;
  94891. if(b->endbyte+4>=b->storage){
  94892. if(b->endbyte*8+bits>b->storage*8)return(-1);
  94893. }
  94894. ret=b->ptr[0]>>b->endbit;
  94895. if(bits>8){
  94896. ret|=b->ptr[1]<<(8-b->endbit);
  94897. if(bits>16){
  94898. ret|=b->ptr[2]<<(16-b->endbit);
  94899. if(bits>24){
  94900. ret|=b->ptr[3]<<(24-b->endbit);
  94901. if(bits>32 && b->endbit)
  94902. ret|=b->ptr[4]<<(32-b->endbit);
  94903. }
  94904. }
  94905. }
  94906. return(m&ret);
  94907. }
  94908. long oggpackB_look(oggpack_buffer *b,int bits){
  94909. unsigned long ret;
  94910. int m=32-bits;
  94911. bits+=b->endbit;
  94912. if(b->endbyte+4>=b->storage){
  94913. if(b->endbyte*8+bits>b->storage*8)return(-1);
  94914. }
  94915. ret=b->ptr[0]<<(24+b->endbit);
  94916. if(bits>8){
  94917. ret|=b->ptr[1]<<(16+b->endbit);
  94918. if(bits>16){
  94919. ret|=b->ptr[2]<<(8+b->endbit);
  94920. if(bits>24){
  94921. ret|=b->ptr[3]<<(b->endbit);
  94922. if(bits>32 && b->endbit)
  94923. ret|=b->ptr[4]>>(8-b->endbit);
  94924. }
  94925. }
  94926. }
  94927. return ((ret&0xffffffff)>>(m>>1))>>((m+1)>>1);
  94928. }
  94929. long oggpack_look1(oggpack_buffer *b){
  94930. if(b->endbyte>=b->storage)return(-1);
  94931. return((b->ptr[0]>>b->endbit)&1);
  94932. }
  94933. long oggpackB_look1(oggpack_buffer *b){
  94934. if(b->endbyte>=b->storage)return(-1);
  94935. return((b->ptr[0]>>(7-b->endbit))&1);
  94936. }
  94937. void oggpack_adv(oggpack_buffer *b,int bits){
  94938. bits+=b->endbit;
  94939. b->ptr+=bits/8;
  94940. b->endbyte+=bits/8;
  94941. b->endbit=bits&7;
  94942. }
  94943. void oggpackB_adv(oggpack_buffer *b,int bits){
  94944. oggpack_adv(b,bits);
  94945. }
  94946. void oggpack_adv1(oggpack_buffer *b){
  94947. if(++(b->endbit)>7){
  94948. b->endbit=0;
  94949. b->ptr++;
  94950. b->endbyte++;
  94951. }
  94952. }
  94953. void oggpackB_adv1(oggpack_buffer *b){
  94954. oggpack_adv1(b);
  94955. }
  94956. long oggpack_read(oggpack_buffer *b,int bits){
  94957. long ret;
  94958. unsigned long m=mask[bits];
  94959. bits+=b->endbit;
  94960. if(b->endbyte+4>=b->storage){
  94961. ret=-1L;
  94962. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  94963. }
  94964. ret=b->ptr[0]>>b->endbit;
  94965. if(bits>8){
  94966. ret|=b->ptr[1]<<(8-b->endbit);
  94967. if(bits>16){
  94968. ret|=b->ptr[2]<<(16-b->endbit);
  94969. if(bits>24){
  94970. ret|=b->ptr[3]<<(24-b->endbit);
  94971. if(bits>32 && b->endbit){
  94972. ret|=b->ptr[4]<<(32-b->endbit);
  94973. }
  94974. }
  94975. }
  94976. }
  94977. ret&=m;
  94978. overflow:
  94979. b->ptr+=bits/8;
  94980. b->endbyte+=bits/8;
  94981. b->endbit=bits&7;
  94982. return(ret);
  94983. }
  94984. long oggpackB_read(oggpack_buffer *b,int bits){
  94985. long ret;
  94986. long m=32-bits;
  94987. bits+=b->endbit;
  94988. if(b->endbyte+4>=b->storage){
  94989. ret=-1L;
  94990. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  94991. }
  94992. ret=b->ptr[0]<<(24+b->endbit);
  94993. if(bits>8){
  94994. ret|=b->ptr[1]<<(16+b->endbit);
  94995. if(bits>16){
  94996. ret|=b->ptr[2]<<(8+b->endbit);
  94997. if(bits>24){
  94998. ret|=b->ptr[3]<<(b->endbit);
  94999. if(bits>32 && b->endbit)
  95000. ret|=b->ptr[4]>>(8-b->endbit);
  95001. }
  95002. }
  95003. }
  95004. ret=((ret&0xffffffffUL)>>(m>>1))>>((m+1)>>1);
  95005. overflow:
  95006. b->ptr+=bits/8;
  95007. b->endbyte+=bits/8;
  95008. b->endbit=bits&7;
  95009. return(ret);
  95010. }
  95011. long oggpack_read1(oggpack_buffer *b){
  95012. long ret;
  95013. if(b->endbyte>=b->storage){
  95014. ret=-1L;
  95015. goto overflow;
  95016. }
  95017. ret=(b->ptr[0]>>b->endbit)&1;
  95018. overflow:
  95019. b->endbit++;
  95020. if(b->endbit>7){
  95021. b->endbit=0;
  95022. b->ptr++;
  95023. b->endbyte++;
  95024. }
  95025. return(ret);
  95026. }
  95027. long oggpackB_read1(oggpack_buffer *b){
  95028. long ret;
  95029. if(b->endbyte>=b->storage){
  95030. ret=-1L;
  95031. goto overflow;
  95032. }
  95033. ret=(b->ptr[0]>>(7-b->endbit))&1;
  95034. overflow:
  95035. b->endbit++;
  95036. if(b->endbit>7){
  95037. b->endbit=0;
  95038. b->ptr++;
  95039. b->endbyte++;
  95040. }
  95041. return(ret);
  95042. }
  95043. long oggpack_bytes(oggpack_buffer *b){
  95044. return(b->endbyte+(b->endbit+7)/8);
  95045. }
  95046. long oggpack_bits(oggpack_buffer *b){
  95047. return(b->endbyte*8+b->endbit);
  95048. }
  95049. long oggpackB_bytes(oggpack_buffer *b){
  95050. return oggpack_bytes(b);
  95051. }
  95052. long oggpackB_bits(oggpack_buffer *b){
  95053. return oggpack_bits(b);
  95054. }
  95055. unsigned char *oggpack_get_buffer(oggpack_buffer *b){
  95056. return(b->buffer);
  95057. }
  95058. unsigned char *oggpackB_get_buffer(oggpack_buffer *b){
  95059. return oggpack_get_buffer(b);
  95060. }
  95061. #ifdef _V_SELFTEST
  95062. #include <stdio.h>
  95063. static int ilog(unsigned int v){
  95064. int ret=0;
  95065. while(v){
  95066. ret++;
  95067. v>>=1;
  95068. }
  95069. return(ret);
  95070. }
  95071. oggpack_buffer o;
  95072. oggpack_buffer r;
  95073. void report(char *in){
  95074. fprintf(stderr,"%s",in);
  95075. exit(1);
  95076. }
  95077. void cliptest(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95078. long bytes,i;
  95079. unsigned char *buffer;
  95080. oggpack_reset(&o);
  95081. for(i=0;i<vals;i++)
  95082. oggpack_write(&o,b[i],bits?bits:ilog(b[i]));
  95083. buffer=oggpack_get_buffer(&o);
  95084. bytes=oggpack_bytes(&o);
  95085. if(bytes!=compsize)report("wrong number of bytes!\n");
  95086. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95087. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95088. report("wrote incorrect value!\n");
  95089. }
  95090. oggpack_readinit(&r,buffer,bytes);
  95091. for(i=0;i<vals;i++){
  95092. int tbit=bits?bits:ilog(b[i]);
  95093. if(oggpack_look(&r,tbit)==-1)
  95094. report("out of data!\n");
  95095. if(oggpack_look(&r,tbit)!=(b[i]&mask[tbit]))
  95096. report("looked at incorrect value!\n");
  95097. if(tbit==1)
  95098. if(oggpack_look1(&r)!=(b[i]&mask[tbit]))
  95099. report("looked at single bit incorrect value!\n");
  95100. if(tbit==1){
  95101. if(oggpack_read1(&r)!=(b[i]&mask[tbit]))
  95102. report("read incorrect single bit value!\n");
  95103. }else{
  95104. if(oggpack_read(&r,tbit)!=(b[i]&mask[tbit]))
  95105. report("read incorrect value!\n");
  95106. }
  95107. }
  95108. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95109. }
  95110. void cliptestB(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95111. long bytes,i;
  95112. unsigned char *buffer;
  95113. oggpackB_reset(&o);
  95114. for(i=0;i<vals;i++)
  95115. oggpackB_write(&o,b[i],bits?bits:ilog(b[i]));
  95116. buffer=oggpackB_get_buffer(&o);
  95117. bytes=oggpackB_bytes(&o);
  95118. if(bytes!=compsize)report("wrong number of bytes!\n");
  95119. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95120. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95121. report("wrote incorrect value!\n");
  95122. }
  95123. oggpackB_readinit(&r,buffer,bytes);
  95124. for(i=0;i<vals;i++){
  95125. int tbit=bits?bits:ilog(b[i]);
  95126. if(oggpackB_look(&r,tbit)==-1)
  95127. report("out of data!\n");
  95128. if(oggpackB_look(&r,tbit)!=(b[i]&mask[tbit]))
  95129. report("looked at incorrect value!\n");
  95130. if(tbit==1)
  95131. if(oggpackB_look1(&r)!=(b[i]&mask[tbit]))
  95132. report("looked at single bit incorrect value!\n");
  95133. if(tbit==1){
  95134. if(oggpackB_read1(&r)!=(b[i]&mask[tbit]))
  95135. report("read incorrect single bit value!\n");
  95136. }else{
  95137. if(oggpackB_read(&r,tbit)!=(b[i]&mask[tbit]))
  95138. report("read incorrect value!\n");
  95139. }
  95140. }
  95141. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95142. }
  95143. int main(void){
  95144. unsigned char *buffer;
  95145. long bytes,i;
  95146. static unsigned long testbuffer1[]=
  95147. {18,12,103948,4325,543,76,432,52,3,65,4,56,32,42,34,21,1,23,32,546,456,7,
  95148. 567,56,8,8,55,3,52,342,341,4,265,7,67,86,2199,21,7,1,5,1,4};
  95149. int test1size=43;
  95150. static unsigned long testbuffer2[]=
  95151. {216531625L,1237861823,56732452,131,3212421,12325343,34547562,12313212,
  95152. 1233432,534,5,346435231,14436467,7869299,76326614,167548585,
  95153. 85525151,0,12321,1,349528352};
  95154. int test2size=21;
  95155. static unsigned long testbuffer3[]=
  95156. {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,
  95157. 0,1,30,1,1,1,0,0,1,0,0,0,12,0,11,0,1,0,0,1};
  95158. int test3size=56;
  95159. static unsigned long large[]=
  95160. {2136531625L,2137861823,56732452,131,3212421,12325343,34547562,12313212,
  95161. 1233432,534,5,2146435231,14436467,7869299,76326614,167548585,
  95162. 85525151,0,12321,1,2146528352};
  95163. int onesize=33;
  95164. static int one[33]={146,25,44,151,195,15,153,176,233,131,196,65,85,172,47,40,
  95165. 34,242,223,136,35,222,211,86,171,50,225,135,214,75,172,
  95166. 223,4};
  95167. static int oneB[33]={150,101,131,33,203,15,204,216,105,193,156,65,84,85,222,
  95168. 8,139,145,227,126,34,55,244,171,85,100,39,195,173,18,
  95169. 245,251,128};
  95170. int twosize=6;
  95171. static int two[6]={61,255,255,251,231,29};
  95172. static int twoB[6]={247,63,255,253,249,120};
  95173. int threesize=54;
  95174. static int three[54]={169,2,232,252,91,132,156,36,89,13,123,176,144,32,254,
  95175. 142,224,85,59,121,144,79,124,23,67,90,90,216,79,23,83,
  95176. 58,135,196,61,55,129,183,54,101,100,170,37,127,126,10,
  95177. 100,52,4,14,18,86,77,1};
  95178. static int threeB[54]={206,128,42,153,57,8,183,251,13,89,36,30,32,144,183,
  95179. 130,59,240,121,59,85,223,19,228,180,134,33,107,74,98,
  95180. 233,253,196,135,63,2,110,114,50,155,90,127,37,170,104,
  95181. 200,20,254,4,58,106,176,144,0};
  95182. int foursize=38;
  95183. static int four[38]={18,6,163,252,97,194,104,131,32,1,7,82,137,42,129,11,72,
  95184. 132,60,220,112,8,196,109,64,179,86,9,137,195,208,122,169,
  95185. 28,2,133,0,1};
  95186. static int fourB[38]={36,48,102,83,243,24,52,7,4,35,132,10,145,21,2,93,2,41,
  95187. 1,219,184,16,33,184,54,149,170,132,18,30,29,98,229,67,
  95188. 129,10,4,32};
  95189. int fivesize=45;
  95190. static int five[45]={169,2,126,139,144,172,30,4,80,72,240,59,130,218,73,62,
  95191. 241,24,210,44,4,20,0,248,116,49,135,100,110,130,181,169,
  95192. 84,75,159,2,1,0,132,192,8,0,0,18,22};
  95193. static int fiveB[45]={1,84,145,111,245,100,128,8,56,36,40,71,126,78,213,226,
  95194. 124,105,12,0,133,128,0,162,233,242,67,152,77,205,77,
  95195. 172,150,169,129,79,128,0,6,4,32,0,27,9,0};
  95196. int sixsize=7;
  95197. static int six[7]={17,177,170,242,169,19,148};
  95198. static int sixB[7]={136,141,85,79,149,200,41};
  95199. oggpack_writeinit(&o);
  95200. fprintf(stderr,"\nSmall preclipped packing (LSb): ");
  95201. cliptest(testbuffer1,test1size,0,one,onesize);
  95202. fprintf(stderr,"ok.");
  95203. fprintf(stderr,"\nNull bit call (LSb): ");
  95204. cliptest(testbuffer3,test3size,0,two,twosize);
  95205. fprintf(stderr,"ok.");
  95206. fprintf(stderr,"\nLarge preclipped packing (LSb): ");
  95207. cliptest(testbuffer2,test2size,0,three,threesize);
  95208. fprintf(stderr,"ok.");
  95209. fprintf(stderr,"\n32 bit preclipped packing (LSb): ");
  95210. oggpack_reset(&o);
  95211. for(i=0;i<test2size;i++)
  95212. oggpack_write(&o,large[i],32);
  95213. buffer=oggpack_get_buffer(&o);
  95214. bytes=oggpack_bytes(&o);
  95215. oggpack_readinit(&r,buffer,bytes);
  95216. for(i=0;i<test2size;i++){
  95217. if(oggpack_look(&r,32)==-1)report("out of data. failed!");
  95218. if(oggpack_look(&r,32)!=large[i]){
  95219. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpack_look(&r,32),large[i],
  95220. oggpack_look(&r,32),large[i]);
  95221. report("read incorrect value!\n");
  95222. }
  95223. oggpack_adv(&r,32);
  95224. }
  95225. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95226. fprintf(stderr,"ok.");
  95227. fprintf(stderr,"\nSmall unclipped packing (LSb): ");
  95228. cliptest(testbuffer1,test1size,7,four,foursize);
  95229. fprintf(stderr,"ok.");
  95230. fprintf(stderr,"\nLarge unclipped packing (LSb): ");
  95231. cliptest(testbuffer2,test2size,17,five,fivesize);
  95232. fprintf(stderr,"ok.");
  95233. fprintf(stderr,"\nSingle bit unclipped packing (LSb): ");
  95234. cliptest(testbuffer3,test3size,1,six,sixsize);
  95235. fprintf(stderr,"ok.");
  95236. fprintf(stderr,"\nTesting read past end (LSb): ");
  95237. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95238. for(i=0;i<64;i++){
  95239. if(oggpack_read(&r,1)!=0){
  95240. fprintf(stderr,"failed; got -1 prematurely.\n");
  95241. exit(1);
  95242. }
  95243. }
  95244. if(oggpack_look(&r,1)!=-1 ||
  95245. oggpack_read(&r,1)!=-1){
  95246. fprintf(stderr,"failed; read past end without -1.\n");
  95247. exit(1);
  95248. }
  95249. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95250. if(oggpack_read(&r,30)!=0 || oggpack_read(&r,16)!=0){
  95251. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95252. exit(1);
  95253. }
  95254. if(oggpack_look(&r,18)!=0 ||
  95255. oggpack_look(&r,18)!=0){
  95256. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95257. exit(1);
  95258. }
  95259. if(oggpack_look(&r,19)!=-1 ||
  95260. oggpack_look(&r,19)!=-1){
  95261. fprintf(stderr,"failed; read past end without -1.\n");
  95262. exit(1);
  95263. }
  95264. if(oggpack_look(&r,32)!=-1 ||
  95265. oggpack_look(&r,32)!=-1){
  95266. fprintf(stderr,"failed; read past end without -1.\n");
  95267. exit(1);
  95268. }
  95269. oggpack_writeclear(&o);
  95270. fprintf(stderr,"ok.\n");
  95271. oggpackB_writeinit(&o);
  95272. fprintf(stderr,"\nSmall preclipped packing (MSb): ");
  95273. cliptestB(testbuffer1,test1size,0,oneB,onesize);
  95274. fprintf(stderr,"ok.");
  95275. fprintf(stderr,"\nNull bit call (MSb): ");
  95276. cliptestB(testbuffer3,test3size,0,twoB,twosize);
  95277. fprintf(stderr,"ok.");
  95278. fprintf(stderr,"\nLarge preclipped packing (MSb): ");
  95279. cliptestB(testbuffer2,test2size,0,threeB,threesize);
  95280. fprintf(stderr,"ok.");
  95281. fprintf(stderr,"\n32 bit preclipped packing (MSb): ");
  95282. oggpackB_reset(&o);
  95283. for(i=0;i<test2size;i++)
  95284. oggpackB_write(&o,large[i],32);
  95285. buffer=oggpackB_get_buffer(&o);
  95286. bytes=oggpackB_bytes(&o);
  95287. oggpackB_readinit(&r,buffer,bytes);
  95288. for(i=0;i<test2size;i++){
  95289. if(oggpackB_look(&r,32)==-1)report("out of data. failed!");
  95290. if(oggpackB_look(&r,32)!=large[i]){
  95291. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpackB_look(&r,32),large[i],
  95292. oggpackB_look(&r,32),large[i]);
  95293. report("read incorrect value!\n");
  95294. }
  95295. oggpackB_adv(&r,32);
  95296. }
  95297. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95298. fprintf(stderr,"ok.");
  95299. fprintf(stderr,"\nSmall unclipped packing (MSb): ");
  95300. cliptestB(testbuffer1,test1size,7,fourB,foursize);
  95301. fprintf(stderr,"ok.");
  95302. fprintf(stderr,"\nLarge unclipped packing (MSb): ");
  95303. cliptestB(testbuffer2,test2size,17,fiveB,fivesize);
  95304. fprintf(stderr,"ok.");
  95305. fprintf(stderr,"\nSingle bit unclipped packing (MSb): ");
  95306. cliptestB(testbuffer3,test3size,1,sixB,sixsize);
  95307. fprintf(stderr,"ok.");
  95308. fprintf(stderr,"\nTesting read past end (MSb): ");
  95309. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95310. for(i=0;i<64;i++){
  95311. if(oggpackB_read(&r,1)!=0){
  95312. fprintf(stderr,"failed; got -1 prematurely.\n");
  95313. exit(1);
  95314. }
  95315. }
  95316. if(oggpackB_look(&r,1)!=-1 ||
  95317. oggpackB_read(&r,1)!=-1){
  95318. fprintf(stderr,"failed; read past end without -1.\n");
  95319. exit(1);
  95320. }
  95321. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95322. if(oggpackB_read(&r,30)!=0 || oggpackB_read(&r,16)!=0){
  95323. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95324. exit(1);
  95325. }
  95326. if(oggpackB_look(&r,18)!=0 ||
  95327. oggpackB_look(&r,18)!=0){
  95328. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95329. exit(1);
  95330. }
  95331. if(oggpackB_look(&r,19)!=-1 ||
  95332. oggpackB_look(&r,19)!=-1){
  95333. fprintf(stderr,"failed; read past end without -1.\n");
  95334. exit(1);
  95335. }
  95336. if(oggpackB_look(&r,32)!=-1 ||
  95337. oggpackB_look(&r,32)!=-1){
  95338. fprintf(stderr,"failed; read past end without -1.\n");
  95339. exit(1);
  95340. }
  95341. oggpackB_writeclear(&o);
  95342. fprintf(stderr,"ok.\n\n");
  95343. return(0);
  95344. }
  95345. #endif /* _V_SELFTEST */
  95346. #undef BUFFER_INCREMENT
  95347. #endif
  95348. /*** End of inlined file: bitwise.c ***/
  95349. /*** Start of inlined file: framing.c ***/
  95350. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  95351. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  95352. // tasks..
  95353. #if JUCE_MSVC
  95354. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  95355. #endif
  95356. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  95357. #if JUCE_USE_OGGVORBIS
  95358. #include <stdlib.h>
  95359. #include <string.h>
  95360. int ogg_page_version(ogg_page *og){
  95361. return((int)(og->header[4]));
  95362. }
  95363. int ogg_page_continued(ogg_page *og){
  95364. return((int)(og->header[5]&0x01));
  95365. }
  95366. int ogg_page_bos(ogg_page *og){
  95367. return((int)(og->header[5]&0x02));
  95368. }
  95369. int ogg_page_eos(ogg_page *og){
  95370. return((int)(og->header[5]&0x04));
  95371. }
  95372. ogg_int64_t ogg_page_granulepos(ogg_page *og){
  95373. unsigned char *page=og->header;
  95374. ogg_int64_t granulepos=page[13]&(0xff);
  95375. granulepos= (granulepos<<8)|(page[12]&0xff);
  95376. granulepos= (granulepos<<8)|(page[11]&0xff);
  95377. granulepos= (granulepos<<8)|(page[10]&0xff);
  95378. granulepos= (granulepos<<8)|(page[9]&0xff);
  95379. granulepos= (granulepos<<8)|(page[8]&0xff);
  95380. granulepos= (granulepos<<8)|(page[7]&0xff);
  95381. granulepos= (granulepos<<8)|(page[6]&0xff);
  95382. return(granulepos);
  95383. }
  95384. int ogg_page_serialno(ogg_page *og){
  95385. return(og->header[14] |
  95386. (og->header[15]<<8) |
  95387. (og->header[16]<<16) |
  95388. (og->header[17]<<24));
  95389. }
  95390. long ogg_page_pageno(ogg_page *og){
  95391. return(og->header[18] |
  95392. (og->header[19]<<8) |
  95393. (og->header[20]<<16) |
  95394. (og->header[21]<<24));
  95395. }
  95396. int ogg_page_packets(ogg_page *og){
  95397. int i,n=og->header[26],count=0;
  95398. for(i=0;i<n;i++)
  95399. if(og->header[27+i]<255)count++;
  95400. return(count);
  95401. }
  95402. #if 0
  95403. static ogg_uint32_t _ogg_crc_entry(unsigned long index){
  95404. int i;
  95405. unsigned long r;
  95406. r = index << 24;
  95407. for (i=0; i<8; i++)
  95408. if (r & 0x80000000UL)
  95409. r = (r << 1) ^ 0x04c11db7; /* The same as the ethernet generator
  95410. polynomial, although we use an
  95411. unreflected alg and an init/final
  95412. of 0, not 0xffffffff */
  95413. else
  95414. r<<=1;
  95415. return (r & 0xffffffffUL);
  95416. }
  95417. #endif
  95418. static const ogg_uint32_t crc_lookup[256]={
  95419. 0x00000000,0x04c11db7,0x09823b6e,0x0d4326d9,
  95420. 0x130476dc,0x17c56b6b,0x1a864db2,0x1e475005,
  95421. 0x2608edb8,0x22c9f00f,0x2f8ad6d6,0x2b4bcb61,
  95422. 0x350c9b64,0x31cd86d3,0x3c8ea00a,0x384fbdbd,
  95423. 0x4c11db70,0x48d0c6c7,0x4593e01e,0x4152fda9,
  95424. 0x5f15adac,0x5bd4b01b,0x569796c2,0x52568b75,
  95425. 0x6a1936c8,0x6ed82b7f,0x639b0da6,0x675a1011,
  95426. 0x791d4014,0x7ddc5da3,0x709f7b7a,0x745e66cd,
  95427. 0x9823b6e0,0x9ce2ab57,0x91a18d8e,0x95609039,
  95428. 0x8b27c03c,0x8fe6dd8b,0x82a5fb52,0x8664e6e5,
  95429. 0xbe2b5b58,0xbaea46ef,0xb7a96036,0xb3687d81,
  95430. 0xad2f2d84,0xa9ee3033,0xa4ad16ea,0xa06c0b5d,
  95431. 0xd4326d90,0xd0f37027,0xddb056fe,0xd9714b49,
  95432. 0xc7361b4c,0xc3f706fb,0xceb42022,0xca753d95,
  95433. 0xf23a8028,0xf6fb9d9f,0xfbb8bb46,0xff79a6f1,
  95434. 0xe13ef6f4,0xe5ffeb43,0xe8bccd9a,0xec7dd02d,
  95435. 0x34867077,0x30476dc0,0x3d044b19,0x39c556ae,
  95436. 0x278206ab,0x23431b1c,0x2e003dc5,0x2ac12072,
  95437. 0x128e9dcf,0x164f8078,0x1b0ca6a1,0x1fcdbb16,
  95438. 0x018aeb13,0x054bf6a4,0x0808d07d,0x0cc9cdca,
  95439. 0x7897ab07,0x7c56b6b0,0x71159069,0x75d48dde,
  95440. 0x6b93dddb,0x6f52c06c,0x6211e6b5,0x66d0fb02,
  95441. 0x5e9f46bf,0x5a5e5b08,0x571d7dd1,0x53dc6066,
  95442. 0x4d9b3063,0x495a2dd4,0x44190b0d,0x40d816ba,
  95443. 0xaca5c697,0xa864db20,0xa527fdf9,0xa1e6e04e,
  95444. 0xbfa1b04b,0xbb60adfc,0xb6238b25,0xb2e29692,
  95445. 0x8aad2b2f,0x8e6c3698,0x832f1041,0x87ee0df6,
  95446. 0x99a95df3,0x9d684044,0x902b669d,0x94ea7b2a,
  95447. 0xe0b41de7,0xe4750050,0xe9362689,0xedf73b3e,
  95448. 0xf3b06b3b,0xf771768c,0xfa325055,0xfef34de2,
  95449. 0xc6bcf05f,0xc27dede8,0xcf3ecb31,0xcbffd686,
  95450. 0xd5b88683,0xd1799b34,0xdc3abded,0xd8fba05a,
  95451. 0x690ce0ee,0x6dcdfd59,0x608edb80,0x644fc637,
  95452. 0x7a089632,0x7ec98b85,0x738aad5c,0x774bb0eb,
  95453. 0x4f040d56,0x4bc510e1,0x46863638,0x42472b8f,
  95454. 0x5c007b8a,0x58c1663d,0x558240e4,0x51435d53,
  95455. 0x251d3b9e,0x21dc2629,0x2c9f00f0,0x285e1d47,
  95456. 0x36194d42,0x32d850f5,0x3f9b762c,0x3b5a6b9b,
  95457. 0x0315d626,0x07d4cb91,0x0a97ed48,0x0e56f0ff,
  95458. 0x1011a0fa,0x14d0bd4d,0x19939b94,0x1d528623,
  95459. 0xf12f560e,0xf5ee4bb9,0xf8ad6d60,0xfc6c70d7,
  95460. 0xe22b20d2,0xe6ea3d65,0xeba91bbc,0xef68060b,
  95461. 0xd727bbb6,0xd3e6a601,0xdea580d8,0xda649d6f,
  95462. 0xc423cd6a,0xc0e2d0dd,0xcda1f604,0xc960ebb3,
  95463. 0xbd3e8d7e,0xb9ff90c9,0xb4bcb610,0xb07daba7,
  95464. 0xae3afba2,0xaafbe615,0xa7b8c0cc,0xa379dd7b,
  95465. 0x9b3660c6,0x9ff77d71,0x92b45ba8,0x9675461f,
  95466. 0x8832161a,0x8cf30bad,0x81b02d74,0x857130c3,
  95467. 0x5d8a9099,0x594b8d2e,0x5408abf7,0x50c9b640,
  95468. 0x4e8ee645,0x4a4ffbf2,0x470cdd2b,0x43cdc09c,
  95469. 0x7b827d21,0x7f436096,0x7200464f,0x76c15bf8,
  95470. 0x68860bfd,0x6c47164a,0x61043093,0x65c52d24,
  95471. 0x119b4be9,0x155a565e,0x18197087,0x1cd86d30,
  95472. 0x029f3d35,0x065e2082,0x0b1d065b,0x0fdc1bec,
  95473. 0x3793a651,0x3352bbe6,0x3e119d3f,0x3ad08088,
  95474. 0x2497d08d,0x2056cd3a,0x2d15ebe3,0x29d4f654,
  95475. 0xc5a92679,0xc1683bce,0xcc2b1d17,0xc8ea00a0,
  95476. 0xd6ad50a5,0xd26c4d12,0xdf2f6bcb,0xdbee767c,
  95477. 0xe3a1cbc1,0xe760d676,0xea23f0af,0xeee2ed18,
  95478. 0xf0a5bd1d,0xf464a0aa,0xf9278673,0xfde69bc4,
  95479. 0x89b8fd09,0x8d79e0be,0x803ac667,0x84fbdbd0,
  95480. 0x9abc8bd5,0x9e7d9662,0x933eb0bb,0x97ffad0c,
  95481. 0xafb010b1,0xab710d06,0xa6322bdf,0xa2f33668,
  95482. 0xbcb4666d,0xb8757bda,0xb5365d03,0xb1f740b4};
  95483. int ogg_stream_init(ogg_stream_state *os,int serialno){
  95484. if(os){
  95485. memset(os,0,sizeof(*os));
  95486. os->body_storage=16*1024;
  95487. os->body_data=(unsigned char*) _ogg_malloc(os->body_storage*sizeof(*os->body_data));
  95488. os->lacing_storage=1024;
  95489. os->lacing_vals=(int*) _ogg_malloc(os->lacing_storage*sizeof(*os->lacing_vals));
  95490. os->granule_vals=(ogg_int64_t*) _ogg_malloc(os->lacing_storage*sizeof(*os->granule_vals));
  95491. os->serialno=serialno;
  95492. return(0);
  95493. }
  95494. return(-1);
  95495. }
  95496. int ogg_stream_clear(ogg_stream_state *os){
  95497. if(os){
  95498. if(os->body_data)_ogg_free(os->body_data);
  95499. if(os->lacing_vals)_ogg_free(os->lacing_vals);
  95500. if(os->granule_vals)_ogg_free(os->granule_vals);
  95501. memset(os,0,sizeof(*os));
  95502. }
  95503. return(0);
  95504. }
  95505. int ogg_stream_destroy(ogg_stream_state *os){
  95506. if(os){
  95507. ogg_stream_clear(os);
  95508. _ogg_free(os);
  95509. }
  95510. return(0);
  95511. }
  95512. static void _os_body_expand(ogg_stream_state *os,int needed){
  95513. if(os->body_storage<=os->body_fill+needed){
  95514. os->body_storage+=(needed+1024);
  95515. os->body_data=(unsigned char*) _ogg_realloc(os->body_data,os->body_storage*sizeof(*os->body_data));
  95516. }
  95517. }
  95518. static void _os_lacing_expand(ogg_stream_state *os,int needed){
  95519. if(os->lacing_storage<=os->lacing_fill+needed){
  95520. os->lacing_storage+=(needed+32);
  95521. os->lacing_vals=(int*)_ogg_realloc(os->lacing_vals,os->lacing_storage*sizeof(*os->lacing_vals));
  95522. os->granule_vals=(ogg_int64_t*)_ogg_realloc(os->granule_vals,os->lacing_storage*sizeof(*os->granule_vals));
  95523. }
  95524. }
  95525. void ogg_page_checksum_set(ogg_page *og){
  95526. if(og){
  95527. ogg_uint32_t crc_reg=0;
  95528. int i;
  95529. og->header[22]=0;
  95530. og->header[23]=0;
  95531. og->header[24]=0;
  95532. og->header[25]=0;
  95533. for(i=0;i<og->header_len;i++)
  95534. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->header[i]];
  95535. for(i=0;i<og->body_len;i++)
  95536. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->body[i]];
  95537. og->header[22]=(unsigned char)(crc_reg&0xff);
  95538. og->header[23]=(unsigned char)((crc_reg>>8)&0xff);
  95539. og->header[24]=(unsigned char)((crc_reg>>16)&0xff);
  95540. og->header[25]=(unsigned char)((crc_reg>>24)&0xff);
  95541. }
  95542. }
  95543. int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){
  95544. int lacing_vals=op->bytes/255+1,i;
  95545. if(os->body_returned){
  95546. os->body_fill-=os->body_returned;
  95547. if(os->body_fill)
  95548. memmove(os->body_data,os->body_data+os->body_returned,
  95549. os->body_fill);
  95550. os->body_returned=0;
  95551. }
  95552. _os_body_expand(os,op->bytes);
  95553. _os_lacing_expand(os,lacing_vals);
  95554. memcpy(os->body_data+os->body_fill,op->packet,op->bytes);
  95555. os->body_fill+=op->bytes;
  95556. for(i=0;i<lacing_vals-1;i++){
  95557. os->lacing_vals[os->lacing_fill+i]=255;
  95558. os->granule_vals[os->lacing_fill+i]=os->granulepos;
  95559. }
  95560. os->lacing_vals[os->lacing_fill+i]=(op->bytes)%255;
  95561. os->granulepos=os->granule_vals[os->lacing_fill+i]=op->granulepos;
  95562. os->lacing_vals[os->lacing_fill]|= 0x100;
  95563. os->lacing_fill+=lacing_vals;
  95564. os->packetno++;
  95565. if(op->e_o_s)os->e_o_s=1;
  95566. return(0);
  95567. }
  95568. int ogg_stream_flush(ogg_stream_state *os,ogg_page *og){
  95569. int i;
  95570. int vals=0;
  95571. int maxvals=(os->lacing_fill>255?255:os->lacing_fill);
  95572. int bytes=0;
  95573. long acc=0;
  95574. ogg_int64_t granule_pos=-1;
  95575. if(maxvals==0)return(0);
  95576. if(os->b_o_s==0){ /* 'initial header page' case */
  95577. granule_pos=0;
  95578. for(vals=0;vals<maxvals;vals++){
  95579. if((os->lacing_vals[vals]&0x0ff)<255){
  95580. vals++;
  95581. break;
  95582. }
  95583. }
  95584. }else{
  95585. for(vals=0;vals<maxvals;vals++){
  95586. if(acc>4096)break;
  95587. acc+=os->lacing_vals[vals]&0x0ff;
  95588. if((os->lacing_vals[vals]&0xff)<255)
  95589. granule_pos=os->granule_vals[vals];
  95590. }
  95591. }
  95592. memcpy(os->header,"OggS",4);
  95593. os->header[4]=0x00;
  95594. os->header[5]=0x00;
  95595. if((os->lacing_vals[0]&0x100)==0)os->header[5]|=0x01;
  95596. if(os->b_o_s==0)os->header[5]|=0x02;
  95597. if(os->e_o_s && os->lacing_fill==vals)os->header[5]|=0x04;
  95598. os->b_o_s=1;
  95599. for(i=6;i<14;i++){
  95600. os->header[i]=(unsigned char)(granule_pos&0xff);
  95601. granule_pos>>=8;
  95602. }
  95603. {
  95604. long serialno=os->serialno;
  95605. for(i=14;i<18;i++){
  95606. os->header[i]=(unsigned char)(serialno&0xff);
  95607. serialno>>=8;
  95608. }
  95609. }
  95610. if(os->pageno==-1)os->pageno=0; /* because someone called
  95611. stream_reset; this would be a
  95612. strange thing to do in an
  95613. encode stream, but it has
  95614. plausible uses */
  95615. {
  95616. long pageno=os->pageno++;
  95617. for(i=18;i<22;i++){
  95618. os->header[i]=(unsigned char)(pageno&0xff);
  95619. pageno>>=8;
  95620. }
  95621. }
  95622. os->header[22]=0;
  95623. os->header[23]=0;
  95624. os->header[24]=0;
  95625. os->header[25]=0;
  95626. os->header[26]=(unsigned char)(vals&0xff);
  95627. for(i=0;i<vals;i++)
  95628. bytes+=os->header[i+27]=(unsigned char)(os->lacing_vals[i]&0xff);
  95629. og->header=os->header;
  95630. og->header_len=os->header_fill=vals+27;
  95631. og->body=os->body_data+os->body_returned;
  95632. og->body_len=bytes;
  95633. os->lacing_fill-=vals;
  95634. memmove(os->lacing_vals,os->lacing_vals+vals,os->lacing_fill*sizeof(*os->lacing_vals));
  95635. memmove(os->granule_vals,os->granule_vals+vals,os->lacing_fill*sizeof(*os->granule_vals));
  95636. os->body_returned+=bytes;
  95637. ogg_page_checksum_set(og);
  95638. return(1);
  95639. }
  95640. int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og){
  95641. if((os->e_o_s&&os->lacing_fill) || /* 'were done, now flush' case */
  95642. os->body_fill-os->body_returned > 4096 ||/* 'page nominal size' case */
  95643. os->lacing_fill>=255 || /* 'segment table full' case */
  95644. (os->lacing_fill&&!os->b_o_s)){ /* 'initial header page' case */
  95645. return(ogg_stream_flush(os,og));
  95646. }
  95647. return(0);
  95648. }
  95649. int ogg_stream_eos(ogg_stream_state *os){
  95650. return os->e_o_s;
  95651. }
  95652. int ogg_sync_init(ogg_sync_state *oy){
  95653. if(oy){
  95654. memset(oy,0,sizeof(*oy));
  95655. }
  95656. return(0);
  95657. }
  95658. int ogg_sync_clear(ogg_sync_state *oy){
  95659. if(oy){
  95660. if(oy->data)_ogg_free(oy->data);
  95661. ogg_sync_init(oy);
  95662. }
  95663. return(0);
  95664. }
  95665. int ogg_sync_destroy(ogg_sync_state *oy){
  95666. if(oy){
  95667. ogg_sync_clear(oy);
  95668. _ogg_free(oy);
  95669. }
  95670. return(0);
  95671. }
  95672. char *ogg_sync_buffer(ogg_sync_state *oy, long size){
  95673. if(oy->returned){
  95674. oy->fill-=oy->returned;
  95675. if(oy->fill>0)
  95676. memmove(oy->data,oy->data+oy->returned,oy->fill);
  95677. oy->returned=0;
  95678. }
  95679. if(size>oy->storage-oy->fill){
  95680. long newsize=size+oy->fill+4096; /* an extra page to be nice */
  95681. if(oy->data)
  95682. oy->data=(unsigned char*) _ogg_realloc(oy->data,newsize);
  95683. else
  95684. oy->data=(unsigned char*) _ogg_malloc(newsize);
  95685. oy->storage=newsize;
  95686. }
  95687. return((char *)oy->data+oy->fill);
  95688. }
  95689. int ogg_sync_wrote(ogg_sync_state *oy, long bytes){
  95690. if(oy->fill+bytes>oy->storage)return(-1);
  95691. oy->fill+=bytes;
  95692. return(0);
  95693. }
  95694. long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){
  95695. unsigned char *page=oy->data+oy->returned;
  95696. unsigned char *next;
  95697. long bytes=oy->fill-oy->returned;
  95698. if(oy->headerbytes==0){
  95699. int headerbytes,i;
  95700. if(bytes<27)return(0); /* not enough for a header */
  95701. if(memcmp(page,"OggS",4))goto sync_fail;
  95702. headerbytes=page[26]+27;
  95703. if(bytes<headerbytes)return(0); /* not enough for header + seg table */
  95704. for(i=0;i<page[26];i++)
  95705. oy->bodybytes+=page[27+i];
  95706. oy->headerbytes=headerbytes;
  95707. }
  95708. if(oy->bodybytes+oy->headerbytes>bytes)return(0);
  95709. {
  95710. char chksum[4];
  95711. ogg_page log;
  95712. memcpy(chksum,page+22,4);
  95713. memset(page+22,0,4);
  95714. log.header=page;
  95715. log.header_len=oy->headerbytes;
  95716. log.body=page+oy->headerbytes;
  95717. log.body_len=oy->bodybytes;
  95718. ogg_page_checksum_set(&log);
  95719. if(memcmp(chksum,page+22,4)){
  95720. memcpy(page+22,chksum,4);
  95721. goto sync_fail;
  95722. }
  95723. }
  95724. {
  95725. unsigned char *page=oy->data+oy->returned;
  95726. long bytes;
  95727. if(og){
  95728. og->header=page;
  95729. og->header_len=oy->headerbytes;
  95730. og->body=page+oy->headerbytes;
  95731. og->body_len=oy->bodybytes;
  95732. }
  95733. oy->unsynced=0;
  95734. oy->returned+=(bytes=oy->headerbytes+oy->bodybytes);
  95735. oy->headerbytes=0;
  95736. oy->bodybytes=0;
  95737. return(bytes);
  95738. }
  95739. sync_fail:
  95740. oy->headerbytes=0;
  95741. oy->bodybytes=0;
  95742. next=(unsigned char*)memchr(page+1,'O',bytes-1);
  95743. if(!next)
  95744. next=oy->data+oy->fill;
  95745. oy->returned=next-oy->data;
  95746. return(-(next-page));
  95747. }
  95748. int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og){
  95749. for(;;){
  95750. long ret=ogg_sync_pageseek(oy,og);
  95751. if(ret>0){
  95752. return(1);
  95753. }
  95754. if(ret==0){
  95755. return(0);
  95756. }
  95757. if(!oy->unsynced){
  95758. oy->unsynced=1;
  95759. return(-1);
  95760. }
  95761. }
  95762. }
  95763. int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
  95764. unsigned char *header=og->header;
  95765. unsigned char *body=og->body;
  95766. long bodysize=og->body_len;
  95767. int segptr=0;
  95768. int version=ogg_page_version(og);
  95769. int continued=ogg_page_continued(og);
  95770. int bos=ogg_page_bos(og);
  95771. int eos=ogg_page_eos(og);
  95772. ogg_int64_t granulepos=ogg_page_granulepos(og);
  95773. int serialno=ogg_page_serialno(og);
  95774. long pageno=ogg_page_pageno(og);
  95775. int segments=header[26];
  95776. {
  95777. long lr=os->lacing_returned;
  95778. long br=os->body_returned;
  95779. if(br){
  95780. os->body_fill-=br;
  95781. if(os->body_fill)
  95782. memmove(os->body_data,os->body_data+br,os->body_fill);
  95783. os->body_returned=0;
  95784. }
  95785. if(lr){
  95786. if(os->lacing_fill-lr){
  95787. memmove(os->lacing_vals,os->lacing_vals+lr,
  95788. (os->lacing_fill-lr)*sizeof(*os->lacing_vals));
  95789. memmove(os->granule_vals,os->granule_vals+lr,
  95790. (os->lacing_fill-lr)*sizeof(*os->granule_vals));
  95791. }
  95792. os->lacing_fill-=lr;
  95793. os->lacing_packet-=lr;
  95794. os->lacing_returned=0;
  95795. }
  95796. }
  95797. if(serialno!=os->serialno)return(-1);
  95798. if(version>0)return(-1);
  95799. _os_lacing_expand(os,segments+1);
  95800. if(pageno!=os->pageno){
  95801. int i;
  95802. for(i=os->lacing_packet;i<os->lacing_fill;i++)
  95803. os->body_fill-=os->lacing_vals[i]&0xff;
  95804. os->lacing_fill=os->lacing_packet;
  95805. if(os->pageno!=-1){
  95806. os->lacing_vals[os->lacing_fill++]=0x400;
  95807. os->lacing_packet++;
  95808. }
  95809. }
  95810. if(continued){
  95811. if(os->lacing_fill<1 ||
  95812. os->lacing_vals[os->lacing_fill-1]==0x400){
  95813. bos=0;
  95814. for(;segptr<segments;segptr++){
  95815. int val=header[27+segptr];
  95816. body+=val;
  95817. bodysize-=val;
  95818. if(val<255){
  95819. segptr++;
  95820. break;
  95821. }
  95822. }
  95823. }
  95824. }
  95825. if(bodysize){
  95826. _os_body_expand(os,bodysize);
  95827. memcpy(os->body_data+os->body_fill,body,bodysize);
  95828. os->body_fill+=bodysize;
  95829. }
  95830. {
  95831. int saved=-1;
  95832. while(segptr<segments){
  95833. int val=header[27+segptr];
  95834. os->lacing_vals[os->lacing_fill]=val;
  95835. os->granule_vals[os->lacing_fill]=-1;
  95836. if(bos){
  95837. os->lacing_vals[os->lacing_fill]|=0x100;
  95838. bos=0;
  95839. }
  95840. if(val<255)saved=os->lacing_fill;
  95841. os->lacing_fill++;
  95842. segptr++;
  95843. if(val<255)os->lacing_packet=os->lacing_fill;
  95844. }
  95845. if(saved!=-1){
  95846. os->granule_vals[saved]=granulepos;
  95847. }
  95848. }
  95849. if(eos){
  95850. os->e_o_s=1;
  95851. if(os->lacing_fill>0)
  95852. os->lacing_vals[os->lacing_fill-1]|=0x200;
  95853. }
  95854. os->pageno=pageno+1;
  95855. return(0);
  95856. }
  95857. int ogg_sync_reset(ogg_sync_state *oy){
  95858. oy->fill=0;
  95859. oy->returned=0;
  95860. oy->unsynced=0;
  95861. oy->headerbytes=0;
  95862. oy->bodybytes=0;
  95863. return(0);
  95864. }
  95865. int ogg_stream_reset(ogg_stream_state *os){
  95866. os->body_fill=0;
  95867. os->body_returned=0;
  95868. os->lacing_fill=0;
  95869. os->lacing_packet=0;
  95870. os->lacing_returned=0;
  95871. os->header_fill=0;
  95872. os->e_o_s=0;
  95873. os->b_o_s=0;
  95874. os->pageno=-1;
  95875. os->packetno=0;
  95876. os->granulepos=0;
  95877. return(0);
  95878. }
  95879. int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno){
  95880. ogg_stream_reset(os);
  95881. os->serialno=serialno;
  95882. return(0);
  95883. }
  95884. static int _packetout(ogg_stream_state *os,ogg_packet *op,int adv){
  95885. int ptr=os->lacing_returned;
  95886. if(os->lacing_packet<=ptr)return(0);
  95887. if(os->lacing_vals[ptr]&0x400){
  95888. os->lacing_returned++;
  95889. os->packetno++;
  95890. return(-1);
  95891. }
  95892. if(!op && !adv)return(1); /* just using peek as an inexpensive way
  95893. to ask if there's a whole packet
  95894. waiting */
  95895. {
  95896. int size=os->lacing_vals[ptr]&0xff;
  95897. int bytes=size;
  95898. int eos=os->lacing_vals[ptr]&0x200; /* last packet of the stream? */
  95899. int bos=os->lacing_vals[ptr]&0x100; /* first packet of the stream? */
  95900. while(size==255){
  95901. int val=os->lacing_vals[++ptr];
  95902. size=val&0xff;
  95903. if(val&0x200)eos=0x200;
  95904. bytes+=size;
  95905. }
  95906. if(op){
  95907. op->e_o_s=eos;
  95908. op->b_o_s=bos;
  95909. op->packet=os->body_data+os->body_returned;
  95910. op->packetno=os->packetno;
  95911. op->granulepos=os->granule_vals[ptr];
  95912. op->bytes=bytes;
  95913. }
  95914. if(adv){
  95915. os->body_returned+=bytes;
  95916. os->lacing_returned=ptr+1;
  95917. os->packetno++;
  95918. }
  95919. }
  95920. return(1);
  95921. }
  95922. int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op){
  95923. return _packetout(os,op,1);
  95924. }
  95925. int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op){
  95926. return _packetout(os,op,0);
  95927. }
  95928. void ogg_packet_clear(ogg_packet *op) {
  95929. _ogg_free(op->packet);
  95930. memset(op, 0, sizeof(*op));
  95931. }
  95932. #ifdef _V_SELFTEST
  95933. #include <stdio.h>
  95934. ogg_stream_state os_en, os_de;
  95935. ogg_sync_state oy;
  95936. void checkpacket(ogg_packet *op,int len, int no, int pos){
  95937. long j;
  95938. static int sequence=0;
  95939. static int lastno=0;
  95940. if(op->bytes!=len){
  95941. fprintf(stderr,"incorrect packet length!\n");
  95942. exit(1);
  95943. }
  95944. if(op->granulepos!=pos){
  95945. fprintf(stderr,"incorrect packet position!\n");
  95946. exit(1);
  95947. }
  95948. if(no==0){
  95949. sequence=0;
  95950. }else{
  95951. sequence++;
  95952. if(no>lastno+1)
  95953. sequence++;
  95954. }
  95955. lastno=no;
  95956. if(op->packetno!=sequence){
  95957. fprintf(stderr,"incorrect packet sequence %ld != %d\n",
  95958. (long)(op->packetno),sequence);
  95959. exit(1);
  95960. }
  95961. for(j=0;j<op->bytes;j++)
  95962. if(op->packet[j]!=((j+no)&0xff)){
  95963. fprintf(stderr,"body data mismatch (1) at pos %ld: %x!=%lx!\n\n",
  95964. j,op->packet[j],(j+no)&0xff);
  95965. exit(1);
  95966. }
  95967. }
  95968. void check_page(unsigned char *data,const int *header,ogg_page *og){
  95969. long j;
  95970. for(j=0;j<og->body_len;j++)
  95971. if(og->body[j]!=data[j]){
  95972. fprintf(stderr,"body data mismatch (2) at pos %ld: %x!=%x!\n\n",
  95973. j,data[j],og->body[j]);
  95974. exit(1);
  95975. }
  95976. for(j=0;j<og->header_len;j++){
  95977. if(og->header[j]!=header[j]){
  95978. fprintf(stderr,"header content mismatch at pos %ld:\n",j);
  95979. for(j=0;j<header[26]+27;j++)
  95980. fprintf(stderr," (%ld)%02x:%02x",j,header[j],og->header[j]);
  95981. fprintf(stderr,"\n");
  95982. exit(1);
  95983. }
  95984. }
  95985. if(og->header_len!=header[26]+27){
  95986. fprintf(stderr,"header length incorrect! (%ld!=%d)\n",
  95987. og->header_len,header[26]+27);
  95988. exit(1);
  95989. }
  95990. }
  95991. void print_header(ogg_page *og){
  95992. int j;
  95993. fprintf(stderr,"\nHEADER:\n");
  95994. fprintf(stderr," capture: %c %c %c %c version: %d flags: %x\n",
  95995. og->header[0],og->header[1],og->header[2],og->header[3],
  95996. (int)og->header[4],(int)og->header[5]);
  95997. fprintf(stderr," granulepos: %d serialno: %d pageno: %ld\n",
  95998. (og->header[9]<<24)|(og->header[8]<<16)|
  95999. (og->header[7]<<8)|og->header[6],
  96000. (og->header[17]<<24)|(og->header[16]<<16)|
  96001. (og->header[15]<<8)|og->header[14],
  96002. ((long)(og->header[21])<<24)|(og->header[20]<<16)|
  96003. (og->header[19]<<8)|og->header[18]);
  96004. fprintf(stderr," checksum: %02x:%02x:%02x:%02x\n segments: %d (",
  96005. (int)og->header[22],(int)og->header[23],
  96006. (int)og->header[24],(int)og->header[25],
  96007. (int)og->header[26]);
  96008. for(j=27;j<og->header_len;j++)
  96009. fprintf(stderr,"%d ",(int)og->header[j]);
  96010. fprintf(stderr,")\n\n");
  96011. }
  96012. void copy_page(ogg_page *og){
  96013. unsigned char *temp=_ogg_malloc(og->header_len);
  96014. memcpy(temp,og->header,og->header_len);
  96015. og->header=temp;
  96016. temp=_ogg_malloc(og->body_len);
  96017. memcpy(temp,og->body,og->body_len);
  96018. og->body=temp;
  96019. }
  96020. void free_page(ogg_page *og){
  96021. _ogg_free (og->header);
  96022. _ogg_free (og->body);
  96023. }
  96024. void error(void){
  96025. fprintf(stderr,"error!\n");
  96026. exit(1);
  96027. }
  96028. const int head1_0[] = {0x4f,0x67,0x67,0x53,0,0x06,
  96029. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96030. 0x01,0x02,0x03,0x04,0,0,0,0,
  96031. 0x15,0xed,0xec,0x91,
  96032. 1,
  96033. 17};
  96034. const int head1_1[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96035. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96036. 0x01,0x02,0x03,0x04,0,0,0,0,
  96037. 0x59,0x10,0x6c,0x2c,
  96038. 1,
  96039. 17};
  96040. const int head2_1[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96041. 0x07,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
  96042. 0x01,0x02,0x03,0x04,1,0,0,0,
  96043. 0x89,0x33,0x85,0xce,
  96044. 13,
  96045. 254,255,0,255,1,255,245,255,255,0,
  96046. 255,255,90};
  96047. const int head1_2[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96048. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96049. 0x01,0x02,0x03,0x04,0,0,0,0,
  96050. 0xff,0x7b,0x23,0x17,
  96051. 1,
  96052. 0};
  96053. const int head2_2[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96054. 0x07,0x28,0x00,0x00,0x00,0x00,0x00,0x00,
  96055. 0x01,0x02,0x03,0x04,1,0,0,0,
  96056. 0x5c,0x3f,0x66,0xcb,
  96057. 17,
  96058. 17,254,255,0,0,255,1,0,255,245,255,255,0,
  96059. 255,255,90,0};
  96060. const int head1_3[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96061. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96062. 0x01,0x02,0x03,0x04,0,0,0,0,
  96063. 0x01,0x27,0x31,0xaa,
  96064. 18,
  96065. 255,255,255,255,255,255,255,255,
  96066. 255,255,255,255,255,255,255,255,255,10};
  96067. const int head2_3[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96068. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96069. 0x01,0x02,0x03,0x04,1,0,0,0,
  96070. 0x7f,0x4e,0x8a,0xd2,
  96071. 4,
  96072. 255,4,255,0};
  96073. const int head1_4[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96074. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96075. 0x01,0x02,0x03,0x04,0,0,0,0,
  96076. 0xff,0x7b,0x23,0x17,
  96077. 1,
  96078. 0};
  96079. const int head2_4[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96080. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96081. 0x01,0x02,0x03,0x04,1,0,0,0,
  96082. 0x54,0x05,0x51,0xc8,
  96083. 17,
  96084. 255,255,255,255,255,255,255,255,
  96085. 255,255,255,255,255,255,255,255,255};
  96086. const int head3_4[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96087. 0x07,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,
  96088. 0x01,0x02,0x03,0x04,2,0,0,0,
  96089. 0xc8,0xc3,0xcb,0xed,
  96090. 5,
  96091. 10,255,4,255,0};
  96092. const int head1_5[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96093. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96094. 0x01,0x02,0x03,0x04,0,0,0,0,
  96095. 0xff,0x7b,0x23,0x17,
  96096. 1,
  96097. 0};
  96098. const int head2_5[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96099. 0x07,0xfc,0x03,0x00,0x00,0x00,0x00,0x00,
  96100. 0x01,0x02,0x03,0x04,1,0,0,0,
  96101. 0xed,0x2a,0x2e,0xa7,
  96102. 255,
  96103. 10,10,10,10,10,10,10,10,
  96104. 10,10,10,10,10,10,10,10,
  96105. 10,10,10,10,10,10,10,10,
  96106. 10,10,10,10,10,10,10,10,
  96107. 10,10,10,10,10,10,10,10,
  96108. 10,10,10,10,10,10,10,10,
  96109. 10,10,10,10,10,10,10,10,
  96110. 10,10,10,10,10,10,10,10,
  96111. 10,10,10,10,10,10,10,10,
  96112. 10,10,10,10,10,10,10,10,
  96113. 10,10,10,10,10,10,10,10,
  96114. 10,10,10,10,10,10,10,10,
  96115. 10,10,10,10,10,10,10,10,
  96116. 10,10,10,10,10,10,10,10,
  96117. 10,10,10,10,10,10,10,10,
  96118. 10,10,10,10,10,10,10,10,
  96119. 10,10,10,10,10,10,10,10,
  96120. 10,10,10,10,10,10,10,10,
  96121. 10,10,10,10,10,10,10,10,
  96122. 10,10,10,10,10,10,10,10,
  96123. 10,10,10,10,10,10,10,10,
  96124. 10,10,10,10,10,10,10,10,
  96125. 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};
  96135. const int head3_5[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96136. 0x07,0x00,0x04,0x00,0x00,0x00,0x00,0x00,
  96137. 0x01,0x02,0x03,0x04,2,0,0,0,
  96138. 0x6c,0x3b,0x82,0x3d,
  96139. 1,
  96140. 50};
  96141. const int head1_6[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96142. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96143. 0x01,0x02,0x03,0x04,0,0,0,0,
  96144. 0xff,0x7b,0x23,0x17,
  96145. 1,
  96146. 0};
  96147. const int head2_6[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96148. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96149. 0x01,0x02,0x03,0x04,1,0,0,0,
  96150. 0x3c,0xd9,0x4d,0x3f,
  96151. 17,
  96152. 100,255,255,255,255,255,255,255,255,
  96153. 255,255,255,255,255,255,255,255};
  96154. const int head3_6[] = {0x4f,0x67,0x67,0x53,0,0x01,
  96155. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96156. 0x01,0x02,0x03,0x04,2,0,0,0,
  96157. 0x01,0xd2,0xe5,0xe5,
  96158. 17,
  96159. 255,255,255,255,255,255,255,255,
  96160. 255,255,255,255,255,255,255,255,255};
  96161. const int head4_6[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96162. 0x07,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
  96163. 0x01,0x02,0x03,0x04,3,0,0,0,
  96164. 0xef,0xdd,0x88,0xde,
  96165. 7,
  96166. 255,255,75,255,4,255,0};
  96167. const int head1_7[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96168. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96169. 0x01,0x02,0x03,0x04,0,0,0,0,
  96170. 0xff,0x7b,0x23,0x17,
  96171. 1,
  96172. 0};
  96173. const int head2_7[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96174. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96175. 0x01,0x02,0x03,0x04,1,0,0,0,
  96176. 0x3c,0xd9,0x4d,0x3f,
  96177. 17,
  96178. 100,255,255,255,255,255,255,255,255,
  96179. 255,255,255,255,255,255,255,255};
  96180. const int head3_7[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96181. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96182. 0x01,0x02,0x03,0x04,2,0,0,0,
  96183. 0xd4,0xe0,0x60,0xe5,
  96184. 1,0};
  96185. void test_pack(const int *pl, const int **headers, int byteskip,
  96186. int pageskip, int packetskip){
  96187. unsigned char *data=_ogg_malloc(1024*1024); /* for scripted test cases only */
  96188. long inptr=0;
  96189. long outptr=0;
  96190. long deptr=0;
  96191. long depacket=0;
  96192. long granule_pos=7,pageno=0;
  96193. int i,j,packets,pageout=pageskip;
  96194. int eosflag=0;
  96195. int bosflag=0;
  96196. int byteskipcount=0;
  96197. ogg_stream_reset(&os_en);
  96198. ogg_stream_reset(&os_de);
  96199. ogg_sync_reset(&oy);
  96200. for(packets=0;packets<packetskip;packets++)
  96201. depacket+=pl[packets];
  96202. for(packets=0;;packets++)if(pl[packets]==-1)break;
  96203. for(i=0;i<packets;i++){
  96204. ogg_packet op;
  96205. int len=pl[i];
  96206. op.packet=data+inptr;
  96207. op.bytes=len;
  96208. op.e_o_s=(pl[i+1]<0?1:0);
  96209. op.granulepos=granule_pos;
  96210. granule_pos+=1024;
  96211. for(j=0;j<len;j++)data[inptr++]=i+j;
  96212. ogg_stream_packetin(&os_en,&op);
  96213. {
  96214. ogg_page og;
  96215. while(ogg_stream_pageout(&os_en,&og)){
  96216. fprintf(stderr,"%ld, ",pageno);
  96217. if(headers[pageno]==NULL){
  96218. fprintf(stderr,"coded too many pages!\n");
  96219. exit(1);
  96220. }
  96221. check_page(data+outptr,headers[pageno],&og);
  96222. outptr+=og.body_len;
  96223. pageno++;
  96224. if(pageskip){
  96225. bosflag=1;
  96226. pageskip--;
  96227. deptr+=og.body_len;
  96228. }
  96229. {
  96230. ogg_page og_de;
  96231. ogg_packet op_de,op_de2;
  96232. char *buf=ogg_sync_buffer(&oy,og.header_len+og.body_len);
  96233. char *next=buf;
  96234. byteskipcount+=og.header_len;
  96235. if(byteskipcount>byteskip){
  96236. memcpy(next,og.header,byteskipcount-byteskip);
  96237. next+=byteskipcount-byteskip;
  96238. byteskipcount=byteskip;
  96239. }
  96240. byteskipcount+=og.body_len;
  96241. if(byteskipcount>byteskip){
  96242. memcpy(next,og.body,byteskipcount-byteskip);
  96243. next+=byteskipcount-byteskip;
  96244. byteskipcount=byteskip;
  96245. }
  96246. ogg_sync_wrote(&oy,next-buf);
  96247. while(1){
  96248. int ret=ogg_sync_pageout(&oy,&og_de);
  96249. if(ret==0)break;
  96250. if(ret<0)continue;
  96251. fprintf(stderr,"(%ld), ",pageout);
  96252. check_page(data+deptr,headers[pageout],&og_de);
  96253. deptr+=og_de.body_len;
  96254. pageout++;
  96255. ogg_stream_pagein(&os_de,&og_de);
  96256. while(ogg_stream_packetpeek(&os_de,&op_de2)>0){
  96257. ogg_stream_packetpeek(&os_de,NULL);
  96258. ogg_stream_packetout(&os_de,&op_de); /* just catching them all */
  96259. if(memcmp(&op_de,&op_de2,sizeof(op_de))){
  96260. fprintf(stderr,"packetout != packetpeek! pos=%ld\n",
  96261. depacket);
  96262. exit(1);
  96263. }
  96264. if(memcmp(data+depacket,op_de.packet,op_de.bytes)){
  96265. fprintf(stderr,"packet data mismatch in decode! pos=%ld\n",
  96266. depacket);
  96267. exit(1);
  96268. }
  96269. if(bosflag==0 && op_de.b_o_s==0){
  96270. fprintf(stderr,"b_o_s flag not set on packet!\n");
  96271. exit(1);
  96272. }
  96273. if(bosflag && op_de.b_o_s){
  96274. fprintf(stderr,"b_o_s flag incorrectly set on packet!\n");
  96275. exit(1);
  96276. }
  96277. bosflag=1;
  96278. depacket+=op_de.bytes;
  96279. if(eosflag){
  96280. fprintf(stderr,"Multiple decoded packets with eos flag!\n");
  96281. exit(1);
  96282. }
  96283. if(op_de.e_o_s)eosflag=1;
  96284. if(op_de.granulepos!=-1){
  96285. fprintf(stderr," granule:%ld ",(long)op_de.granulepos);
  96286. }
  96287. }
  96288. }
  96289. }
  96290. }
  96291. }
  96292. }
  96293. _ogg_free(data);
  96294. if(headers[pageno]!=NULL){
  96295. fprintf(stderr,"did not write last page!\n");
  96296. exit(1);
  96297. }
  96298. if(headers[pageout]!=NULL){
  96299. fprintf(stderr,"did not decode last page!\n");
  96300. exit(1);
  96301. }
  96302. if(inptr!=outptr){
  96303. fprintf(stderr,"encoded page data incomplete!\n");
  96304. exit(1);
  96305. }
  96306. if(inptr!=deptr){
  96307. fprintf(stderr,"decoded page data incomplete!\n");
  96308. exit(1);
  96309. }
  96310. if(inptr!=depacket){
  96311. fprintf(stderr,"decoded packet data incomplete!\n");
  96312. exit(1);
  96313. }
  96314. if(!eosflag){
  96315. fprintf(stderr,"Never got a packet with EOS set!\n");
  96316. exit(1);
  96317. }
  96318. fprintf(stderr,"ok.\n");
  96319. }
  96320. int main(void){
  96321. ogg_stream_init(&os_en,0x04030201);
  96322. ogg_stream_init(&os_de,0x04030201);
  96323. ogg_sync_init(&oy);
  96324. {
  96325. const int packets[]={17, -1};
  96326. const int *headret[]={head1_0,NULL};
  96327. fprintf(stderr,"testing single page encoding... ");
  96328. test_pack(packets,headret,0,0,0);
  96329. }
  96330. {
  96331. const int packets[]={17, 254, 255, 256, 500, 510, 600, -1};
  96332. const int *headret[]={head1_1,head2_1,NULL};
  96333. fprintf(stderr,"testing basic page encoding... ");
  96334. test_pack(packets,headret,0,0,0);
  96335. }
  96336. {
  96337. const int packets[]={0,17, 254, 255, 0, 256, 0, 500, 510, 600, 0, -1};
  96338. const int *headret[]={head1_2,head2_2,NULL};
  96339. fprintf(stderr,"testing basic nil packets... ");
  96340. test_pack(packets,headret,0,0,0);
  96341. }
  96342. {
  96343. const int packets[]={4345,259,255,-1};
  96344. const int *headret[]={head1_3,head2_3,NULL};
  96345. fprintf(stderr,"testing initial-packet lacing > 4k... ");
  96346. test_pack(packets,headret,0,0,0);
  96347. }
  96348. {
  96349. const int packets[]={0,4345,259,255,-1};
  96350. const int *headret[]={head1_4,head2_4,head3_4,NULL};
  96351. fprintf(stderr,"testing single packet page span... ");
  96352. test_pack(packets,headret,0,0,0);
  96353. }
  96354. {
  96355. const int packets[]={0,10,10,10,10,10,10,10,10,
  96356. 10,10,10,10,10,10,10,10,
  96357. 10,10,10,10,10,10,10,10,
  96358. 10,10,10,10,10,10,10,10,
  96359. 10,10,10,10,10,10,10,10,
  96360. 10,10,10,10,10,10,10,10,
  96361. 10,10,10,10,10,10,10,10,
  96362. 10,10,10,10,10,10,10,10,
  96363. 10,10,10,10,10,10,10,10,
  96364. 10,10,10,10,10,10,10,10,
  96365. 10,10,10,10,10,10,10,10,
  96366. 10,10,10,10,10,10,10,10,
  96367. 10,10,10,10,10,10,10,10,
  96368. 10,10,10,10,10,10,10,10,
  96369. 10,10,10,10,10,10,10,10,
  96370. 10,10,10,10,10,10,10,10,
  96371. 10,10,10,10,10,10,10,10,
  96372. 10,10,10,10,10,10,10,10,
  96373. 10,10,10,10,10,10,10,10,
  96374. 10,10,10,10,10,10,10,10,
  96375. 10,10,10,10,10,10,10,10,
  96376. 10,10,10,10,10,10,10,10,
  96377. 10,10,10,10,10,10,10,10,
  96378. 10,10,10,10,10,10,10,10,
  96379. 10,10,10,10,10,10,10,10,
  96380. 10,10,10,10,10,10,10,10,
  96381. 10,10,10,10,10,10,10,10,
  96382. 10,10,10,10,10,10,10,10,
  96383. 10,10,10,10,10,10,10,10,
  96384. 10,10,10,10,10,10,10,10,
  96385. 10,10,10,10,10,10,10,10,
  96386. 10,10,10,10,10,10,10,50,-1};
  96387. const int *headret[]={head1_5,head2_5,head3_5,NULL};
  96388. fprintf(stderr,"testing max packet segments... ");
  96389. test_pack(packets,headret,0,0,0);
  96390. }
  96391. {
  96392. const int packets[]={0,100,9000,259,255,-1};
  96393. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96394. fprintf(stderr,"testing very large packets... ");
  96395. test_pack(packets,headret,0,0,0);
  96396. }
  96397. {
  96398. const int packets[]={0,100,9000,259,255,-1};
  96399. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96400. fprintf(stderr,"testing continuation resync in very large packets... ");
  96401. test_pack(packets,headret,100,2,3);
  96402. }
  96403. {
  96404. const int packets[]={0,100,4080,-1};
  96405. const int *headret[]={head1_7,head2_7,head3_7,NULL};
  96406. fprintf(stderr,"testing zero data page (1 nil packet)... ");
  96407. test_pack(packets,headret,0,0,0);
  96408. }
  96409. {
  96410. unsigned char *data=_ogg_malloc(1024*1024);
  96411. int pl[]={0,100,4079,2956,2057,76,34,912,0,234,1000,1000,1000,300,-1};
  96412. int inptr=0,i,j;
  96413. ogg_page og[5];
  96414. ogg_stream_reset(&os_en);
  96415. for(i=0;pl[i]!=-1;i++){
  96416. ogg_packet op;
  96417. int len=pl[i];
  96418. op.packet=data+inptr;
  96419. op.bytes=len;
  96420. op.e_o_s=(pl[i+1]<0?1:0);
  96421. op.granulepos=(i+1)*1000;
  96422. for(j=0;j<len;j++)data[inptr++]=i+j;
  96423. ogg_stream_packetin(&os_en,&op);
  96424. }
  96425. _ogg_free(data);
  96426. for(i=0;i<5;i++){
  96427. if(ogg_stream_pageout(&os_en,&og[i])==0){
  96428. fprintf(stderr,"Too few pages output building sync tests!\n");
  96429. exit(1);
  96430. }
  96431. copy_page(&og[i]);
  96432. }
  96433. {
  96434. ogg_page temp;
  96435. ogg_packet test;
  96436. fprintf(stderr,"Testing loss of pages... ");
  96437. ogg_sync_reset(&oy);
  96438. ogg_stream_reset(&os_de);
  96439. for(i=0;i<5;i++){
  96440. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96441. og[i].header_len);
  96442. ogg_sync_wrote(&oy,og[i].header_len);
  96443. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96444. ogg_sync_wrote(&oy,og[i].body_len);
  96445. }
  96446. ogg_sync_pageout(&oy,&temp);
  96447. ogg_stream_pagein(&os_de,&temp);
  96448. ogg_sync_pageout(&oy,&temp);
  96449. ogg_stream_pagein(&os_de,&temp);
  96450. ogg_sync_pageout(&oy,&temp);
  96451. ogg_sync_pageout(&oy,&temp);
  96452. ogg_stream_pagein(&os_de,&temp);
  96453. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96454. checkpacket(&test,0,0,0);
  96455. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96456. checkpacket(&test,100,1,-1);
  96457. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96458. checkpacket(&test,4079,2,3000);
  96459. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96460. fprintf(stderr,"Error: loss of page did not return error\n");
  96461. exit(1);
  96462. }
  96463. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96464. checkpacket(&test,76,5,-1);
  96465. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96466. checkpacket(&test,34,6,-1);
  96467. fprintf(stderr,"ok.\n");
  96468. }
  96469. {
  96470. ogg_page temp;
  96471. ogg_packet test;
  96472. fprintf(stderr,"Testing loss of pages (rollback required)... ");
  96473. ogg_sync_reset(&oy);
  96474. ogg_stream_reset(&os_de);
  96475. for(i=0;i<5;i++){
  96476. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96477. og[i].header_len);
  96478. ogg_sync_wrote(&oy,og[i].header_len);
  96479. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96480. ogg_sync_wrote(&oy,og[i].body_len);
  96481. }
  96482. ogg_sync_pageout(&oy,&temp);
  96483. ogg_stream_pagein(&os_de,&temp);
  96484. ogg_sync_pageout(&oy,&temp);
  96485. ogg_stream_pagein(&os_de,&temp);
  96486. ogg_sync_pageout(&oy,&temp);
  96487. ogg_stream_pagein(&os_de,&temp);
  96488. ogg_sync_pageout(&oy,&temp);
  96489. ogg_sync_pageout(&oy,&temp);
  96490. ogg_stream_pagein(&os_de,&temp);
  96491. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96492. checkpacket(&test,0,0,0);
  96493. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96494. checkpacket(&test,100,1,-1);
  96495. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96496. checkpacket(&test,4079,2,3000);
  96497. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96498. checkpacket(&test,2956,3,4000);
  96499. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96500. fprintf(stderr,"Error: loss of page did not return error\n");
  96501. exit(1);
  96502. }
  96503. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96504. checkpacket(&test,300,13,14000);
  96505. fprintf(stderr,"ok.\n");
  96506. }
  96507. {
  96508. ogg_page og_de;
  96509. fprintf(stderr,"Testing sync on partial inputs... ");
  96510. ogg_sync_reset(&oy);
  96511. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96512. 3);
  96513. ogg_sync_wrote(&oy,3);
  96514. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96515. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+3,
  96516. 20);
  96517. ogg_sync_wrote(&oy,20);
  96518. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96519. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+23,
  96520. 5);
  96521. ogg_sync_wrote(&oy,5);
  96522. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96523. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+28,
  96524. og[1].header_len-28);
  96525. ogg_sync_wrote(&oy,og[1].header_len-28);
  96526. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96527. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,1000);
  96528. ogg_sync_wrote(&oy,1000);
  96529. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96530. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body+1000,
  96531. og[1].body_len-1000);
  96532. ogg_sync_wrote(&oy,og[1].body_len-1000);
  96533. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96534. fprintf(stderr,"ok.\n");
  96535. }
  96536. {
  96537. ogg_page og_de;
  96538. fprintf(stderr,"Testing sync on 1+partial inputs... ");
  96539. ogg_sync_reset(&oy);
  96540. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96541. og[1].header_len);
  96542. ogg_sync_wrote(&oy,og[1].header_len);
  96543. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96544. og[1].body_len);
  96545. ogg_sync_wrote(&oy,og[1].body_len);
  96546. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96547. 20);
  96548. ogg_sync_wrote(&oy,20);
  96549. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96550. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96551. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+20,
  96552. og[1].header_len-20);
  96553. ogg_sync_wrote(&oy,og[1].header_len-20);
  96554. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96555. og[1].body_len);
  96556. ogg_sync_wrote(&oy,og[1].body_len);
  96557. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96558. fprintf(stderr,"ok.\n");
  96559. }
  96560. {
  96561. ogg_page og_de;
  96562. fprintf(stderr,"Testing search for capture... ");
  96563. ogg_sync_reset(&oy);
  96564. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96565. og[1].body_len);
  96566. ogg_sync_wrote(&oy,og[1].body_len);
  96567. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96568. og[1].header_len);
  96569. ogg_sync_wrote(&oy,og[1].header_len);
  96570. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96571. og[1].body_len);
  96572. ogg_sync_wrote(&oy,og[1].body_len);
  96573. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96574. 20);
  96575. ogg_sync_wrote(&oy,20);
  96576. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96577. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96578. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96579. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header+20,
  96580. og[2].header_len-20);
  96581. ogg_sync_wrote(&oy,og[2].header_len-20);
  96582. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  96583. og[2].body_len);
  96584. ogg_sync_wrote(&oy,og[2].body_len);
  96585. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96586. fprintf(stderr,"ok.\n");
  96587. }
  96588. {
  96589. ogg_page og_de;
  96590. fprintf(stderr,"Testing recapture... ");
  96591. ogg_sync_reset(&oy);
  96592. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96593. og[1].header_len);
  96594. ogg_sync_wrote(&oy,og[1].header_len);
  96595. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96596. og[1].body_len);
  96597. ogg_sync_wrote(&oy,og[1].body_len);
  96598. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96599. og[2].header_len);
  96600. ogg_sync_wrote(&oy,og[2].header_len);
  96601. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96602. og[2].header_len);
  96603. ogg_sync_wrote(&oy,og[2].header_len);
  96604. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96605. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  96606. og[2].body_len-5);
  96607. ogg_sync_wrote(&oy,og[2].body_len-5);
  96608. memcpy(ogg_sync_buffer(&oy,og[3].header_len),og[3].header,
  96609. og[3].header_len);
  96610. ogg_sync_wrote(&oy,og[3].header_len);
  96611. memcpy(ogg_sync_buffer(&oy,og[3].body_len),og[3].body,
  96612. og[3].body_len);
  96613. ogg_sync_wrote(&oy,og[3].body_len);
  96614. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96615. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96616. fprintf(stderr,"ok.\n");
  96617. }
  96618. {
  96619. for(i=0;i<5;i++){
  96620. free_page(&og[i]);
  96621. }
  96622. }
  96623. }
  96624. return(0);
  96625. }
  96626. #endif
  96627. #endif
  96628. /*** End of inlined file: framing.c ***/
  96629. /*** Start of inlined file: analysis.c ***/
  96630. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  96631. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  96632. // tasks..
  96633. #if JUCE_MSVC
  96634. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  96635. #endif
  96636. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  96637. #if JUCE_USE_OGGVORBIS
  96638. #include <stdio.h>
  96639. #include <string.h>
  96640. #include <math.h>
  96641. /*** Start of inlined file: codec_internal.h ***/
  96642. #ifndef _V_CODECI_H_
  96643. #define _V_CODECI_H_
  96644. /*** Start of inlined file: envelope.h ***/
  96645. #ifndef _V_ENVELOPE_
  96646. #define _V_ENVELOPE_
  96647. /*** Start of inlined file: mdct.h ***/
  96648. #ifndef _OGG_mdct_H_
  96649. #define _OGG_mdct_H_
  96650. #ifdef MDCT_INTEGERIZED
  96651. #define DATA_TYPE int
  96652. #define REG_TYPE register int
  96653. #define TRIGBITS 14
  96654. #define cPI3_8 6270
  96655. #define cPI2_8 11585
  96656. #define cPI1_8 15137
  96657. #define FLOAT_CONV(x) ((int)((x)*(1<<TRIGBITS)+.5))
  96658. #define MULT_NORM(x) ((x)>>TRIGBITS)
  96659. #define HALVE(x) ((x)>>1)
  96660. #else
  96661. #define DATA_TYPE float
  96662. #define REG_TYPE float
  96663. #define cPI3_8 .38268343236508977175F
  96664. #define cPI2_8 .70710678118654752441F
  96665. #define cPI1_8 .92387953251128675613F
  96666. #define FLOAT_CONV(x) (x)
  96667. #define MULT_NORM(x) (x)
  96668. #define HALVE(x) ((x)*.5f)
  96669. #endif
  96670. typedef struct {
  96671. int n;
  96672. int log2n;
  96673. DATA_TYPE *trig;
  96674. int *bitrev;
  96675. DATA_TYPE scale;
  96676. } mdct_lookup;
  96677. extern void mdct_init(mdct_lookup *lookup,int n);
  96678. extern void mdct_clear(mdct_lookup *l);
  96679. extern void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  96680. extern void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  96681. #endif
  96682. /*** End of inlined file: mdct.h ***/
  96683. #define VE_PRE 16
  96684. #define VE_WIN 4
  96685. #define VE_POST 2
  96686. #define VE_AMP (VE_PRE+VE_POST-1)
  96687. #define VE_BANDS 7
  96688. #define VE_NEARDC 15
  96689. #define VE_MINSTRETCH 2 /* a bit less than short block */
  96690. #define VE_MAXSTRETCH 12 /* one-third full block */
  96691. typedef struct {
  96692. float ampbuf[VE_AMP];
  96693. int ampptr;
  96694. float nearDC[VE_NEARDC];
  96695. float nearDC_acc;
  96696. float nearDC_partialacc;
  96697. int nearptr;
  96698. } envelope_filter_state;
  96699. typedef struct {
  96700. int begin;
  96701. int end;
  96702. float *window;
  96703. float total;
  96704. } envelope_band;
  96705. typedef struct {
  96706. int ch;
  96707. int winlength;
  96708. int searchstep;
  96709. float minenergy;
  96710. mdct_lookup mdct;
  96711. float *mdct_win;
  96712. envelope_band band[VE_BANDS];
  96713. envelope_filter_state *filter;
  96714. int stretch;
  96715. int *mark;
  96716. long storage;
  96717. long current;
  96718. long curmark;
  96719. long cursor;
  96720. } envelope_lookup;
  96721. extern void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi);
  96722. extern void _ve_envelope_clear(envelope_lookup *e);
  96723. extern long _ve_envelope_search(vorbis_dsp_state *v);
  96724. extern void _ve_envelope_shift(envelope_lookup *e,long shift);
  96725. extern int _ve_envelope_mark(vorbis_dsp_state *v);
  96726. #endif
  96727. /*** End of inlined file: envelope.h ***/
  96728. /*** Start of inlined file: codebook.h ***/
  96729. #ifndef _V_CODEBOOK_H_
  96730. #define _V_CODEBOOK_H_
  96731. typedef struct static_codebook{
  96732. long dim; /* codebook dimensions (elements per vector) */
  96733. long entries; /* codebook entries */
  96734. long *lengthlist; /* codeword lengths in bits */
  96735. int maptype; /* 0=none
  96736. 1=implicitly populated values from map column
  96737. 2=listed arbitrary values */
  96738. long q_min; /* packed 32 bit float; quant value 0 maps to minval */
  96739. long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */
  96740. int q_quant; /* bits: 0 < quant <= 16 */
  96741. int q_sequencep; /* bitflag */
  96742. long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map
  96743. map == 2: list of dim*entries quantized entry vals
  96744. */
  96745. struct encode_aux_nearestmatch *nearest_tree;
  96746. struct encode_aux_threshmatch *thresh_tree;
  96747. struct encode_aux_pigeonhole *pigeon_tree;
  96748. int allocedp;
  96749. } static_codebook;
  96750. typedef struct encode_aux_nearestmatch{
  96751. long *ptr0;
  96752. long *ptr1;
  96753. long *p; /* decision points (each is an entry) */
  96754. long *q; /* decision points (each is an entry) */
  96755. long aux; /* number of tree entries */
  96756. long alloc;
  96757. } encode_aux_nearestmatch;
  96758. typedef struct encode_aux_threshmatch{
  96759. float *quantthresh;
  96760. long *quantmap;
  96761. int quantvals;
  96762. int threshvals;
  96763. } encode_aux_threshmatch;
  96764. typedef struct encode_aux_pigeonhole{
  96765. float min;
  96766. float del;
  96767. int mapentries;
  96768. int quantvals;
  96769. long *pigeonmap;
  96770. long fittotal;
  96771. long *fitlist;
  96772. long *fitmap;
  96773. long *fitlength;
  96774. } encode_aux_pigeonhole;
  96775. typedef struct codebook{
  96776. long dim; /* codebook dimensions (elements per vector) */
  96777. long entries; /* codebook entries */
  96778. long used_entries; /* populated codebook entries */
  96779. const static_codebook *c;
  96780. float *valuelist; /* list of dim*entries actual entry values */
  96781. ogg_uint32_t *codelist; /* list of bitstream codewords for each entry */
  96782. int *dec_index; /* only used if sparseness collapsed */
  96783. char *dec_codelengths;
  96784. ogg_uint32_t *dec_firsttable;
  96785. int dec_firsttablen;
  96786. int dec_maxlength;
  96787. } codebook;
  96788. extern void vorbis_staticbook_clear(static_codebook *b);
  96789. extern void vorbis_staticbook_destroy(static_codebook *b);
  96790. extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source);
  96791. extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
  96792. extern void vorbis_book_clear(codebook *b);
  96793. extern float *_book_unquantize(const static_codebook *b,int n,int *map);
  96794. extern float *_book_logdist(const static_codebook *b,float *vals);
  96795. extern float _float32_unpack(long val);
  96796. extern long _float32_pack(float val);
  96797. extern int _best(codebook *book, float *a, int step);
  96798. extern int _ilog(unsigned int v);
  96799. extern long _book_maptype1_quantvals(const static_codebook *b);
  96800. extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul);
  96801. extern long vorbis_book_codeword(codebook *book,int entry);
  96802. extern long vorbis_book_codelen(codebook *book,int entry);
  96803. extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b);
  96804. extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_codebook *c);
  96805. extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b);
  96806. extern int vorbis_book_errorv(codebook *book, float *a);
  96807. extern int vorbis_book_encodev(codebook *book, int best,float *a,
  96808. oggpack_buffer *b);
  96809. extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
  96810. extern long vorbis_book_decodevs_add(codebook *book, float *a,
  96811. oggpack_buffer *b,int n);
  96812. extern long vorbis_book_decodev_set(codebook *book, float *a,
  96813. oggpack_buffer *b,int n);
  96814. extern long vorbis_book_decodev_add(codebook *book, float *a,
  96815. oggpack_buffer *b,int n);
  96816. extern long vorbis_book_decodevv_add(codebook *book, float **a,
  96817. long off,int ch,
  96818. oggpack_buffer *b,int n);
  96819. #endif
  96820. /*** End of inlined file: codebook.h ***/
  96821. #define BLOCKTYPE_IMPULSE 0
  96822. #define BLOCKTYPE_PADDING 1
  96823. #define BLOCKTYPE_TRANSITION 0
  96824. #define BLOCKTYPE_LONG 1
  96825. #define PACKETBLOBS 15
  96826. typedef struct vorbis_block_internal{
  96827. float **pcmdelay; /* this is a pointer into local storage */
  96828. float ampmax;
  96829. int blocktype;
  96830. oggpack_buffer *packetblob[PACKETBLOBS]; /* initialized, must be freed;
  96831. blob [PACKETBLOBS/2] points to
  96832. the oggpack_buffer in the
  96833. main vorbis_block */
  96834. } vorbis_block_internal;
  96835. typedef void vorbis_look_floor;
  96836. typedef void vorbis_look_residue;
  96837. typedef void vorbis_look_transform;
  96838. typedef struct {
  96839. int blockflag;
  96840. int windowtype;
  96841. int transformtype;
  96842. int mapping;
  96843. } vorbis_info_mode;
  96844. typedef void vorbis_info_floor;
  96845. typedef void vorbis_info_residue;
  96846. typedef void vorbis_info_mapping;
  96847. /*** Start of inlined file: psy.h ***/
  96848. #ifndef _V_PSY_H_
  96849. #define _V_PSY_H_
  96850. /*** Start of inlined file: smallft.h ***/
  96851. #ifndef _V_SMFT_H_
  96852. #define _V_SMFT_H_
  96853. typedef struct {
  96854. int n;
  96855. float *trigcache;
  96856. int *splitcache;
  96857. } drft_lookup;
  96858. extern void drft_forward(drft_lookup *l,float *data);
  96859. extern void drft_backward(drft_lookup *l,float *data);
  96860. extern void drft_init(drft_lookup *l,int n);
  96861. extern void drft_clear(drft_lookup *l);
  96862. #endif
  96863. /*** End of inlined file: smallft.h ***/
  96864. /*** Start of inlined file: backends.h ***/
  96865. #ifndef _vorbis_backend_h_
  96866. #define _vorbis_backend_h_
  96867. typedef struct{
  96868. void (*pack) (vorbis_info_floor *,oggpack_buffer *);
  96869. vorbis_info_floor *(*unpack)(vorbis_info *,oggpack_buffer *);
  96870. vorbis_look_floor *(*look) (vorbis_dsp_state *,vorbis_info_floor *);
  96871. void (*free_info) (vorbis_info_floor *);
  96872. void (*free_look) (vorbis_look_floor *);
  96873. void *(*inverse1) (struct vorbis_block *,vorbis_look_floor *);
  96874. int (*inverse2) (struct vorbis_block *,vorbis_look_floor *,
  96875. void *buffer,float *);
  96876. } vorbis_func_floor;
  96877. typedef struct{
  96878. int order;
  96879. long rate;
  96880. long barkmap;
  96881. int ampbits;
  96882. int ampdB;
  96883. int numbooks; /* <= 16 */
  96884. int books[16];
  96885. float lessthan; /* encode-only config setting hacks for libvorbis */
  96886. float greaterthan; /* encode-only config setting hacks for libvorbis */
  96887. } vorbis_info_floor0;
  96888. #define VIF_POSIT 63
  96889. #define VIF_CLASS 16
  96890. #define VIF_PARTS 31
  96891. typedef struct{
  96892. int partitions; /* 0 to 31 */
  96893. int partitionclass[VIF_PARTS]; /* 0 to 15 */
  96894. int class_dim[VIF_CLASS]; /* 1 to 8 */
  96895. int class_subs[VIF_CLASS]; /* 0,1,2,3 (bits: 1<<n poss) */
  96896. int class_book[VIF_CLASS]; /* subs ^ dim entries */
  96897. int class_subbook[VIF_CLASS][8]; /* [VIF_CLASS][subs] */
  96898. int mult; /* 1 2 3 or 4 */
  96899. int postlist[VIF_POSIT+2]; /* first two implicit */
  96900. float maxover;
  96901. float maxunder;
  96902. float maxerr;
  96903. float twofitweight;
  96904. float twofitatten;
  96905. int n;
  96906. } vorbis_info_floor1;
  96907. typedef struct{
  96908. void (*pack) (vorbis_info_residue *,oggpack_buffer *);
  96909. vorbis_info_residue *(*unpack)(vorbis_info *,oggpack_buffer *);
  96910. vorbis_look_residue *(*look) (vorbis_dsp_state *,
  96911. vorbis_info_residue *);
  96912. void (*free_info) (vorbis_info_residue *);
  96913. void (*free_look) (vorbis_look_residue *);
  96914. long **(*classx) (struct vorbis_block *,vorbis_look_residue *,
  96915. float **,int *,int);
  96916. int (*forward) (oggpack_buffer *,struct vorbis_block *,
  96917. vorbis_look_residue *,
  96918. float **,float **,int *,int,long **);
  96919. int (*inverse) (struct vorbis_block *,vorbis_look_residue *,
  96920. float **,int *,int);
  96921. } vorbis_func_residue;
  96922. typedef struct vorbis_info_residue0{
  96923. long begin;
  96924. long end;
  96925. int grouping; /* group n vectors per partition */
  96926. int partitions; /* possible codebooks for a partition */
  96927. int groupbook; /* huffbook for partitioning */
  96928. int secondstages[64]; /* expanded out to pointers in lookup */
  96929. int booklist[256]; /* list of second stage books */
  96930. float classmetric1[64];
  96931. float classmetric2[64];
  96932. } vorbis_info_residue0;
  96933. typedef struct{
  96934. void (*pack) (vorbis_info *,vorbis_info_mapping *,
  96935. oggpack_buffer *);
  96936. vorbis_info_mapping *(*unpack)(vorbis_info *,oggpack_buffer *);
  96937. void (*free_info) (vorbis_info_mapping *);
  96938. int (*forward) (struct vorbis_block *vb);
  96939. int (*inverse) (struct vorbis_block *vb,vorbis_info_mapping *);
  96940. } vorbis_func_mapping;
  96941. typedef struct vorbis_info_mapping0{
  96942. int submaps; /* <= 16 */
  96943. int chmuxlist[256]; /* up to 256 channels in a Vorbis stream */
  96944. int floorsubmap[16]; /* [mux] submap to floors */
  96945. int residuesubmap[16]; /* [mux] submap to residue */
  96946. int coupling_steps;
  96947. int coupling_mag[256];
  96948. int coupling_ang[256];
  96949. } vorbis_info_mapping0;
  96950. #endif
  96951. /*** End of inlined file: backends.h ***/
  96952. #ifndef EHMER_MAX
  96953. #define EHMER_MAX 56
  96954. #endif
  96955. #define P_BANDS 17 /* 62Hz to 16kHz */
  96956. #define P_LEVELS 8 /* 30dB to 100dB */
  96957. #define P_LEVEL_0 30. /* 30 dB */
  96958. #define P_NOISECURVES 3
  96959. #define NOISE_COMPAND_LEVELS 40
  96960. typedef struct vorbis_info_psy{
  96961. int blockflag;
  96962. float ath_adjatt;
  96963. float ath_maxatt;
  96964. float tone_masteratt[P_NOISECURVES];
  96965. float tone_centerboost;
  96966. float tone_decay;
  96967. float tone_abs_limit;
  96968. float toneatt[P_BANDS];
  96969. int noisemaskp;
  96970. float noisemaxsupp;
  96971. float noisewindowlo;
  96972. float noisewindowhi;
  96973. int noisewindowlomin;
  96974. int noisewindowhimin;
  96975. int noisewindowfixed;
  96976. float noiseoff[P_NOISECURVES][P_BANDS];
  96977. float noisecompand[NOISE_COMPAND_LEVELS];
  96978. float max_curve_dB;
  96979. int normal_channel_p;
  96980. int normal_point_p;
  96981. int normal_start;
  96982. int normal_partition;
  96983. double normal_thresh;
  96984. } vorbis_info_psy;
  96985. typedef struct{
  96986. int eighth_octave_lines;
  96987. float preecho_thresh[VE_BANDS];
  96988. float postecho_thresh[VE_BANDS];
  96989. float stretch_penalty;
  96990. float preecho_minenergy;
  96991. float ampmax_att_per_sec;
  96992. int coupling_pkHz[PACKETBLOBS];
  96993. int coupling_pointlimit[2][PACKETBLOBS];
  96994. int coupling_prepointamp[PACKETBLOBS];
  96995. int coupling_postpointamp[PACKETBLOBS];
  96996. int sliding_lowpass[2][PACKETBLOBS];
  96997. } vorbis_info_psy_global;
  96998. typedef struct {
  96999. float ampmax;
  97000. int channels;
  97001. vorbis_info_psy_global *gi;
  97002. int coupling_pointlimit[2][P_NOISECURVES];
  97003. } vorbis_look_psy_global;
  97004. typedef struct {
  97005. int n;
  97006. struct vorbis_info_psy *vi;
  97007. float ***tonecurves;
  97008. float **noiseoffset;
  97009. float *ath;
  97010. long *octave; /* in n.ocshift format */
  97011. long *bark;
  97012. long firstoc;
  97013. long shiftoc;
  97014. int eighth_octave_lines; /* power of two, please */
  97015. int total_octave_lines;
  97016. long rate; /* cache it */
  97017. float m_val; /* Masking compensation value */
  97018. } vorbis_look_psy;
  97019. extern void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  97020. vorbis_info_psy_global *gi,int n,long rate);
  97021. extern void _vp_psy_clear(vorbis_look_psy *p);
  97022. extern void *_vi_psy_dup(void *source);
  97023. extern void _vi_psy_free(vorbis_info_psy *i);
  97024. extern vorbis_info_psy *_vi_psy_copy(vorbis_info_psy *i);
  97025. extern void _vp_remove_floor(vorbis_look_psy *p,
  97026. float *mdct,
  97027. int *icodedflr,
  97028. float *residue,
  97029. int sliding_lowpass);
  97030. extern void _vp_noisemask(vorbis_look_psy *p,
  97031. float *logmdct,
  97032. float *logmask);
  97033. extern void _vp_tonemask(vorbis_look_psy *p,
  97034. float *logfft,
  97035. float *logmask,
  97036. float global_specmax,
  97037. float local_specmax);
  97038. extern void _vp_offset_and_mix(vorbis_look_psy *p,
  97039. float *noise,
  97040. float *tone,
  97041. int offset_select,
  97042. float *logmask,
  97043. float *mdct,
  97044. float *logmdct);
  97045. extern float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd);
  97046. extern float **_vp_quantize_couple_memo(vorbis_block *vb,
  97047. vorbis_info_psy_global *g,
  97048. vorbis_look_psy *p,
  97049. vorbis_info_mapping0 *vi,
  97050. float **mdct);
  97051. extern void _vp_couple(int blobno,
  97052. vorbis_info_psy_global *g,
  97053. vorbis_look_psy *p,
  97054. vorbis_info_mapping0 *vi,
  97055. float **res,
  97056. float **mag_memo,
  97057. int **mag_sort,
  97058. int **ifloor,
  97059. int *nonzero,
  97060. int sliding_lowpass);
  97061. extern void _vp_noise_normalize(vorbis_look_psy *p,
  97062. float *in,float *out,int *sortedindex);
  97063. extern void _vp_noise_normalize_sort(vorbis_look_psy *p,
  97064. float *magnitudes,int *sortedindex);
  97065. extern int **_vp_quantize_couple_sort(vorbis_block *vb,
  97066. vorbis_look_psy *p,
  97067. vorbis_info_mapping0 *vi,
  97068. float **mags);
  97069. extern void hf_reduction(vorbis_info_psy_global *g,
  97070. vorbis_look_psy *p,
  97071. vorbis_info_mapping0 *vi,
  97072. float **mdct);
  97073. #endif
  97074. /*** End of inlined file: psy.h ***/
  97075. /*** Start of inlined file: bitrate.h ***/
  97076. #ifndef _V_BITRATE_H_
  97077. #define _V_BITRATE_H_
  97078. /*** Start of inlined file: os.h ***/
  97079. #ifndef _OS_H
  97080. #define _OS_H
  97081. #ifdef HAVE_CONFIG_H
  97082. #include "config.h"
  97083. #endif
  97084. #include <math.h>
  97085. /*** Start of inlined file: misc.h ***/
  97086. #ifndef _V_RANDOM_H_
  97087. #define _V_RANDOM_H_
  97088. extern int analysis_noisy;
  97089. extern void *_vorbis_block_alloc(vorbis_block *vb,long bytes);
  97090. extern void _vorbis_block_ripcord(vorbis_block *vb);
  97091. extern void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97092. ogg_int64_t off);
  97093. #ifdef DEBUG_MALLOC
  97094. #define _VDBG_GRAPHFILE "malloc.m"
  97095. extern void *_VDBG_malloc(void *ptr,long bytes,char *file,long line);
  97096. extern void _VDBG_free(void *ptr,char *file,long line);
  97097. #ifndef MISC_C
  97098. #undef _ogg_malloc
  97099. #undef _ogg_calloc
  97100. #undef _ogg_realloc
  97101. #undef _ogg_free
  97102. #define _ogg_malloc(x) _VDBG_malloc(NULL,(x),__FILE__,__LINE__)
  97103. #define _ogg_calloc(x,y) _VDBG_malloc(NULL,(x)*(y),__FILE__,__LINE__)
  97104. #define _ogg_realloc(x,y) _VDBG_malloc((x),(y),__FILE__,__LINE__)
  97105. #define _ogg_free(x) _VDBG_free((x),__FILE__,__LINE__)
  97106. #endif
  97107. #endif
  97108. #endif
  97109. /*** End of inlined file: misc.h ***/
  97110. #ifndef _V_IFDEFJAIL_H_
  97111. # define _V_IFDEFJAIL_H_
  97112. # ifdef __GNUC__
  97113. # define STIN static __inline__
  97114. # elif _WIN32
  97115. # define STIN static __inline
  97116. # else
  97117. # define STIN static
  97118. # endif
  97119. #ifdef DJGPP
  97120. # define rint(x) (floor((x)+0.5f))
  97121. #endif
  97122. #ifndef M_PI
  97123. # define M_PI (3.1415926536f)
  97124. #endif
  97125. #if defined(_WIN32) && !defined(__SYMBIAN32__)
  97126. # include <malloc.h>
  97127. # define rint(x) (floor((x)+0.5f))
  97128. # define NO_FLOAT_MATH_LIB
  97129. # define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b))
  97130. #endif
  97131. #if defined(__SYMBIAN32__) && defined(__WINS__)
  97132. void *_alloca(size_t size);
  97133. # define alloca _alloca
  97134. #endif
  97135. #ifndef FAST_HYPOT
  97136. # define FAST_HYPOT hypot
  97137. #endif
  97138. #endif
  97139. #ifdef HAVE_ALLOCA_H
  97140. # include <alloca.h>
  97141. #endif
  97142. #ifdef USE_MEMORY_H
  97143. # include <memory.h>
  97144. #endif
  97145. #ifndef min
  97146. # define min(x,y) ((x)>(y)?(y):(x))
  97147. #endif
  97148. #ifndef max
  97149. # define max(x,y) ((x)<(y)?(y):(x))
  97150. #endif
  97151. #if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__)
  97152. # define VORBIS_FPU_CONTROL
  97153. typedef ogg_int16_t vorbis_fpu_control;
  97154. static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97155. ogg_int16_t ret;
  97156. ogg_int16_t temp;
  97157. __asm__ __volatile__("fnstcw %0\n\t"
  97158. "movw %0,%%dx\n\t"
  97159. "orw $62463,%%dx\n\t"
  97160. "movw %%dx,%1\n\t"
  97161. "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx");
  97162. *fpu=ret;
  97163. }
  97164. static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97165. __asm__ __volatile__("fldcw %0":: "m"(fpu));
  97166. }
  97167. static inline int vorbis_ftoi(double f){ /* yes, double! Otherwise,
  97168. we get extra fst/fld to
  97169. truncate precision */
  97170. int i;
  97171. __asm__("fistl %0": "=m"(i) : "t"(f));
  97172. return(i);
  97173. }
  97174. #endif
  97175. #if defined(_WIN32) && defined(_X86_) && !defined(__GNUC__) && !defined(__BORLANDC__)
  97176. # define VORBIS_FPU_CONTROL
  97177. typedef ogg_int16_t vorbis_fpu_control;
  97178. static __inline int vorbis_ftoi(double f){
  97179. int i;
  97180. __asm{
  97181. fld f
  97182. fistp i
  97183. }
  97184. return i;
  97185. }
  97186. static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97187. }
  97188. static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97189. }
  97190. #endif
  97191. #ifndef VORBIS_FPU_CONTROL
  97192. typedef int vorbis_fpu_control;
  97193. static int vorbis_ftoi(double f){
  97194. return (int)(f+.5);
  97195. }
  97196. # define vorbis_fpu_setround(vorbis_fpu_control) {}
  97197. # define vorbis_fpu_restore(vorbis_fpu_control) {}
  97198. #endif
  97199. #endif /* _OS_H */
  97200. /*** End of inlined file: os.h ***/
  97201. typedef struct bitrate_manager_state {
  97202. int managed;
  97203. long avg_reservoir;
  97204. long minmax_reservoir;
  97205. long avg_bitsper;
  97206. long min_bitsper;
  97207. long max_bitsper;
  97208. long short_per_long;
  97209. double avgfloat;
  97210. vorbis_block *vb;
  97211. int choice;
  97212. } bitrate_manager_state;
  97213. typedef struct bitrate_manager_info{
  97214. long avg_rate;
  97215. long min_rate;
  97216. long max_rate;
  97217. long reservoir_bits;
  97218. double reservoir_bias;
  97219. double slew_damp;
  97220. } bitrate_manager_info;
  97221. extern void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bs);
  97222. extern void vorbis_bitrate_clear(bitrate_manager_state *bs);
  97223. extern int vorbis_bitrate_managed(vorbis_block *vb);
  97224. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  97225. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd, ogg_packet *op);
  97226. #endif
  97227. /*** End of inlined file: bitrate.h ***/
  97228. static int ilog(unsigned int v){
  97229. int ret=0;
  97230. while(v){
  97231. ret++;
  97232. v>>=1;
  97233. }
  97234. return(ret);
  97235. }
  97236. static int ilog2(unsigned int v){
  97237. int ret=0;
  97238. if(v)--v;
  97239. while(v){
  97240. ret++;
  97241. v>>=1;
  97242. }
  97243. return(ret);
  97244. }
  97245. typedef struct private_state {
  97246. envelope_lookup *ve; /* envelope lookup */
  97247. int window[2];
  97248. vorbis_look_transform **transform[2]; /* block, type */
  97249. drft_lookup fft_look[2];
  97250. int modebits;
  97251. vorbis_look_floor **flr;
  97252. vorbis_look_residue **residue;
  97253. vorbis_look_psy *psy;
  97254. vorbis_look_psy_global *psy_g_look;
  97255. unsigned char *header;
  97256. unsigned char *header1;
  97257. unsigned char *header2;
  97258. bitrate_manager_state bms;
  97259. ogg_int64_t sample_count;
  97260. } private_state;
  97261. /*** Start of inlined file: highlevel.h ***/
  97262. typedef struct highlevel_byblocktype {
  97263. double tone_mask_setting;
  97264. double tone_peaklimit_setting;
  97265. double noise_bias_setting;
  97266. double noise_compand_setting;
  97267. } highlevel_byblocktype;
  97268. typedef struct highlevel_encode_setup {
  97269. void *setup;
  97270. int set_in_stone;
  97271. double base_setting;
  97272. double long_setting;
  97273. double short_setting;
  97274. double impulse_noisetune;
  97275. int managed;
  97276. long bitrate_min;
  97277. long bitrate_av;
  97278. double bitrate_av_damp;
  97279. long bitrate_max;
  97280. long bitrate_reservoir;
  97281. double bitrate_reservoir_bias;
  97282. int impulse_block_p;
  97283. int noise_normalize_p;
  97284. double stereo_point_setting;
  97285. double lowpass_kHz;
  97286. double ath_floating_dB;
  97287. double ath_absolute_dB;
  97288. double amplitude_track_dBpersec;
  97289. double trigger_setting;
  97290. highlevel_byblocktype block[4]; /* padding, impulse, transition, long */
  97291. } highlevel_encode_setup;
  97292. /*** End of inlined file: highlevel.h ***/
  97293. typedef struct codec_setup_info {
  97294. long blocksizes[2];
  97295. int modes;
  97296. int maps;
  97297. int floors;
  97298. int residues;
  97299. int books;
  97300. int psys; /* encode only */
  97301. vorbis_info_mode *mode_param[64];
  97302. int map_type[64];
  97303. vorbis_info_mapping *map_param[64];
  97304. int floor_type[64];
  97305. vorbis_info_floor *floor_param[64];
  97306. int residue_type[64];
  97307. vorbis_info_residue *residue_param[64];
  97308. static_codebook *book_param[256];
  97309. codebook *fullbooks;
  97310. vorbis_info_psy *psy_param[4]; /* encode only */
  97311. vorbis_info_psy_global psy_g_param;
  97312. bitrate_manager_info bi;
  97313. highlevel_encode_setup hi; /* used only by vorbisenc.c. It's a
  97314. highly redundant structure, but
  97315. improves clarity of program flow. */
  97316. int halfrate_flag; /* painless downsample for decode */
  97317. } codec_setup_info;
  97318. extern vorbis_look_psy_global *_vp_global_look(vorbis_info *vi);
  97319. extern void _vp_global_free(vorbis_look_psy_global *look);
  97320. #endif
  97321. /*** End of inlined file: codec_internal.h ***/
  97322. /*** Start of inlined file: registry.h ***/
  97323. #ifndef _V_REG_H_
  97324. #define _V_REG_H_
  97325. #define VI_TRANSFORMB 1
  97326. #define VI_WINDOWB 1
  97327. #define VI_TIMEB 1
  97328. #define VI_FLOORB 2
  97329. #define VI_RESB 3
  97330. #define VI_MAPB 1
  97331. extern vorbis_func_floor *_floor_P[];
  97332. extern vorbis_func_residue *_residue_P[];
  97333. extern vorbis_func_mapping *_mapping_P[];
  97334. #endif
  97335. /*** End of inlined file: registry.h ***/
  97336. /*** Start of inlined file: scales.h ***/
  97337. #ifndef _V_SCALES_H_
  97338. #define _V_SCALES_H_
  97339. #include <math.h>
  97340. #define VORBIS_IEEE_FLOAT32 1
  97341. #ifdef VORBIS_IEEE_FLOAT32
  97342. static float unitnorm(float x){
  97343. union {
  97344. ogg_uint32_t i;
  97345. float f;
  97346. } ix;
  97347. ix.f = x;
  97348. ix.i = (ix.i & 0x80000000U) | (0x3f800000U);
  97349. return ix.f;
  97350. }
  97351. static float todB(const float *x){
  97352. union {
  97353. ogg_uint32_t i;
  97354. float f;
  97355. } ix;
  97356. ix.f = *x;
  97357. ix.i = ix.i&0x7fffffff;
  97358. return (float)(ix.i * 7.17711438e-7f -764.6161886f);
  97359. }
  97360. #define todB_nn(x) todB(x)
  97361. #else
  97362. static float unitnorm(float x){
  97363. if(x<0)return(-1.f);
  97364. return(1.f);
  97365. }
  97366. #define todB(x) (*(x)==0?-400.f:log(*(x)**(x))*4.34294480f)
  97367. #define todB_nn(x) (*(x)==0.f?-400.f:log(*(x))*8.6858896f)
  97368. #endif
  97369. #define fromdB(x) (exp((x)*.11512925f))
  97370. #define toBARK(n) (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n))
  97371. #define fromBARK(z) (102.f*(z)-2.f*pow(z,2.f)+.4f*pow(z,3.f)+pow(1.46f,z)-1.f)
  97372. #define toMEL(n) (log(1.f+(n)*.001f)*1442.695f)
  97373. #define fromMEL(m) (1000.f*exp((m)/1442.695f)-1000.f)
  97374. #define toOC(n) (log(n)*1.442695f-5.965784f)
  97375. #define fromOC(o) (exp(((o)+5.965784f)*.693147f))
  97376. #endif
  97377. /*** End of inlined file: scales.h ***/
  97378. int analysis_noisy=1;
  97379. int vorbis_analysis(vorbis_block *vb, ogg_packet *op){
  97380. int ret,i;
  97381. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  97382. vb->glue_bits=0;
  97383. vb->time_bits=0;
  97384. vb->floor_bits=0;
  97385. vb->res_bits=0;
  97386. for(i=0;i<PACKETBLOBS;i++)
  97387. oggpack_reset(vbi->packetblob[i]);
  97388. if((ret=_mapping_P[0]->forward(vb)))
  97389. return(ret);
  97390. if(op){
  97391. if(vorbis_bitrate_managed(vb))
  97392. return(OV_EINVAL);
  97393. op->packet=oggpack_get_buffer(&vb->opb);
  97394. op->bytes=oggpack_bytes(&vb->opb);
  97395. op->b_o_s=0;
  97396. op->e_o_s=vb->eofflag;
  97397. op->granulepos=vb->granulepos;
  97398. op->packetno=vb->sequence; /* for sake of completeness */
  97399. }
  97400. return(0);
  97401. }
  97402. void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,ogg_int64_t off){
  97403. int j;
  97404. FILE *of;
  97405. char buffer[80];
  97406. sprintf(buffer,"%s_%d.m",base,i);
  97407. of=fopen(buffer,"w");
  97408. if(!of)perror("failed to open data dump file");
  97409. for(j=0;j<n;j++){
  97410. if(bark){
  97411. float b=toBARK((4000.f*j/n)+.25);
  97412. fprintf(of,"%f ",b);
  97413. }else
  97414. if(off!=0)
  97415. fprintf(of,"%f ",(double)(j+off)/8000.);
  97416. else
  97417. fprintf(of,"%f ",(double)j);
  97418. if(dB){
  97419. float val;
  97420. if(v[j]==0.)
  97421. val=-140.;
  97422. else
  97423. val=todB(v+j);
  97424. fprintf(of,"%f\n",val);
  97425. }else{
  97426. fprintf(of,"%f\n",v[j]);
  97427. }
  97428. }
  97429. fclose(of);
  97430. }
  97431. void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97432. ogg_int64_t off){
  97433. if(analysis_noisy)_analysis_output_always(base,i,v,n,bark,dB,off);
  97434. }
  97435. #endif
  97436. /*** End of inlined file: analysis.c ***/
  97437. /*** Start of inlined file: bitrate.c ***/
  97438. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97439. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97440. // tasks..
  97441. #if JUCE_MSVC
  97442. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97443. #endif
  97444. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97445. #if JUCE_USE_OGGVORBIS
  97446. #include <stdlib.h>
  97447. #include <string.h>
  97448. #include <math.h>
  97449. void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bm){
  97450. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  97451. bitrate_manager_info *bi=&ci->bi;
  97452. memset(bm,0,sizeof(*bm));
  97453. if(bi && (bi->reservoir_bits>0)){
  97454. long ratesamples=vi->rate;
  97455. int halfsamples=ci->blocksizes[0]>>1;
  97456. bm->short_per_long=ci->blocksizes[1]/ci->blocksizes[0];
  97457. bm->managed=1;
  97458. bm->avg_bitsper= rint(1.*bi->avg_rate*halfsamples/ratesamples);
  97459. bm->min_bitsper= rint(1.*bi->min_rate*halfsamples/ratesamples);
  97460. bm->max_bitsper= rint(1.*bi->max_rate*halfsamples/ratesamples);
  97461. bm->avgfloat=PACKETBLOBS/2;
  97462. {
  97463. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97464. bm->minmax_reservoir=desired_fill;
  97465. bm->avg_reservoir=desired_fill;
  97466. }
  97467. }
  97468. }
  97469. void vorbis_bitrate_clear(bitrate_manager_state *bm){
  97470. memset(bm,0,sizeof(*bm));
  97471. return;
  97472. }
  97473. int vorbis_bitrate_managed(vorbis_block *vb){
  97474. vorbis_dsp_state *vd=vb->vd;
  97475. private_state *b=(private_state*)vd->backend_state;
  97476. bitrate_manager_state *bm=&b->bms;
  97477. if(bm && bm->managed)return(1);
  97478. return(0);
  97479. }
  97480. int vorbis_bitrate_addblock(vorbis_block *vb){
  97481. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97482. vorbis_dsp_state *vd=vb->vd;
  97483. private_state *b=(private_state*)vd->backend_state;
  97484. bitrate_manager_state *bm=&b->bms;
  97485. vorbis_info *vi=vd->vi;
  97486. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97487. bitrate_manager_info *bi=&ci->bi;
  97488. int choice=rint(bm->avgfloat);
  97489. long this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97490. long min_target_bits=(vb->W?bm->min_bitsper*bm->short_per_long:bm->min_bitsper);
  97491. long max_target_bits=(vb->W?bm->max_bitsper*bm->short_per_long:bm->max_bitsper);
  97492. int samples=ci->blocksizes[vb->W]>>1;
  97493. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97494. if(!bm->managed){
  97495. if(bm->vb)return(-1); /* one has been submitted without
  97496. being claimed */
  97497. bm->vb=vb;
  97498. return(0);
  97499. }
  97500. bm->vb=vb;
  97501. if(bm->avg_bitsper>0){
  97502. double slew=0.;
  97503. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97504. double slewlimit= 15./bi->slew_damp;
  97505. if(bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97506. while(choice>0 && this_bits>avg_target_bits &&
  97507. bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97508. choice--;
  97509. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97510. }
  97511. }else if(bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  97512. while(choice+1<PACKETBLOBS && this_bits<avg_target_bits &&
  97513. bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  97514. choice++;
  97515. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97516. }
  97517. }
  97518. slew=rint(choice-bm->avgfloat)/samples*vi->rate;
  97519. if(slew<-slewlimit)slew=-slewlimit;
  97520. if(slew>slewlimit)slew=slewlimit;
  97521. choice=rint(bm->avgfloat+= slew/vi->rate*samples);
  97522. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97523. }
  97524. if(bm->min_bitsper>0){
  97525. if(this_bits<min_target_bits){
  97526. while(bm->minmax_reservoir-(min_target_bits-this_bits)<0){
  97527. choice++;
  97528. if(choice>=PACKETBLOBS)break;
  97529. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97530. }
  97531. }
  97532. }
  97533. if(bm->max_bitsper>0){
  97534. if(this_bits>max_target_bits){
  97535. while(bm->minmax_reservoir+(this_bits-max_target_bits)>bi->reservoir_bits){
  97536. choice--;
  97537. if(choice<0)break;
  97538. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97539. }
  97540. }
  97541. }
  97542. if(choice<0){
  97543. long maxsize=(max_target_bits+(bi->reservoir_bits-bm->minmax_reservoir))/8;
  97544. bm->choice=choice=0;
  97545. if(oggpack_bytes(vbi->packetblob[choice])>maxsize){
  97546. oggpack_writetrunc(vbi->packetblob[choice],maxsize*8);
  97547. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97548. }
  97549. }else{
  97550. long minsize=(min_target_bits-bm->minmax_reservoir+7)/8;
  97551. if(choice>=PACKETBLOBS)
  97552. choice=PACKETBLOBS-1;
  97553. bm->choice=choice;
  97554. minsize-=oggpack_bytes(vbi->packetblob[choice]);
  97555. while(minsize-->0)oggpack_write(vbi->packetblob[choice],0,8);
  97556. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97557. }
  97558. if(bm->min_bitsper>0 || bm->max_bitsper>0){
  97559. if(max_target_bits>0 && this_bits>max_target_bits){
  97560. bm->minmax_reservoir+=(this_bits-max_target_bits);
  97561. }else if(min_target_bits>0 && this_bits<min_target_bits){
  97562. bm->minmax_reservoir+=(this_bits-min_target_bits);
  97563. }else{
  97564. if(bm->minmax_reservoir>desired_fill){
  97565. if(max_target_bits>0){ /* logical bulletproofing against initialization state */
  97566. bm->minmax_reservoir+=(this_bits-max_target_bits);
  97567. if(bm->minmax_reservoir<desired_fill)bm->minmax_reservoir=desired_fill;
  97568. }else{
  97569. bm->minmax_reservoir=desired_fill;
  97570. }
  97571. }else{
  97572. if(min_target_bits>0){ /* logical bulletproofing against initialization state */
  97573. bm->minmax_reservoir+=(this_bits-min_target_bits);
  97574. if(bm->minmax_reservoir>desired_fill)bm->minmax_reservoir=desired_fill;
  97575. }else{
  97576. bm->minmax_reservoir=desired_fill;
  97577. }
  97578. }
  97579. }
  97580. }
  97581. if(bm->avg_bitsper>0){
  97582. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97583. bm->avg_reservoir+=this_bits-avg_target_bits;
  97584. }
  97585. return(0);
  97586. }
  97587. int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,ogg_packet *op){
  97588. private_state *b=(private_state*)vd->backend_state;
  97589. bitrate_manager_state *bm=&b->bms;
  97590. vorbis_block *vb=bm->vb;
  97591. int choice=PACKETBLOBS/2;
  97592. if(!vb)return 0;
  97593. if(op){
  97594. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97595. if(vorbis_bitrate_managed(vb))
  97596. choice=bm->choice;
  97597. op->packet=oggpack_get_buffer(vbi->packetblob[choice]);
  97598. op->bytes=oggpack_bytes(vbi->packetblob[choice]);
  97599. op->b_o_s=0;
  97600. op->e_o_s=vb->eofflag;
  97601. op->granulepos=vb->granulepos;
  97602. op->packetno=vb->sequence; /* for sake of completeness */
  97603. }
  97604. bm->vb=0;
  97605. return(1);
  97606. }
  97607. #endif
  97608. /*** End of inlined file: bitrate.c ***/
  97609. /*** Start of inlined file: block.c ***/
  97610. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97611. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97612. // tasks..
  97613. #if JUCE_MSVC
  97614. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97615. #endif
  97616. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97617. #if JUCE_USE_OGGVORBIS
  97618. #include <stdio.h>
  97619. #include <stdlib.h>
  97620. #include <string.h>
  97621. /*** Start of inlined file: window.h ***/
  97622. #ifndef _V_WINDOW_
  97623. #define _V_WINDOW_
  97624. extern float *_vorbis_window_get(int n);
  97625. extern void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  97626. int lW,int W,int nW);
  97627. #endif
  97628. /*** End of inlined file: window.h ***/
  97629. /*** Start of inlined file: lpc.h ***/
  97630. #ifndef _V_LPC_H_
  97631. #define _V_LPC_H_
  97632. extern float vorbis_lpc_from_data(float *data,float *lpc,int n,int m);
  97633. extern void vorbis_lpc_predict(float *coeff,float *prime,int m,
  97634. float *data,long n);
  97635. #endif
  97636. /*** End of inlined file: lpc.h ***/
  97637. #ifndef WORD_ALIGN
  97638. #define WORD_ALIGN 8
  97639. #endif
  97640. int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){
  97641. int i;
  97642. memset(vb,0,sizeof(*vb));
  97643. vb->vd=v;
  97644. vb->localalloc=0;
  97645. vb->localstore=NULL;
  97646. if(v->analysisp){
  97647. vorbis_block_internal *vbi=(vorbis_block_internal*)
  97648. (vb->internal=(vorbis_block_internal*)_ogg_calloc(1,sizeof(vorbis_block_internal)));
  97649. vbi->ampmax=-9999;
  97650. for(i=0;i<PACKETBLOBS;i++){
  97651. if(i==PACKETBLOBS/2){
  97652. vbi->packetblob[i]=&vb->opb;
  97653. }else{
  97654. vbi->packetblob[i]=
  97655. (oggpack_buffer*) _ogg_calloc(1,sizeof(oggpack_buffer));
  97656. }
  97657. oggpack_writeinit(vbi->packetblob[i]);
  97658. }
  97659. }
  97660. return(0);
  97661. }
  97662. void *_vorbis_block_alloc(vorbis_block *vb,long bytes){
  97663. bytes=(bytes+(WORD_ALIGN-1)) & ~(WORD_ALIGN-1);
  97664. if(bytes+vb->localtop>vb->localalloc){
  97665. if(vb->localstore){
  97666. struct alloc_chain *link=(struct alloc_chain*)_ogg_malloc(sizeof(*link));
  97667. vb->totaluse+=vb->localtop;
  97668. link->next=vb->reap;
  97669. link->ptr=vb->localstore;
  97670. vb->reap=link;
  97671. }
  97672. vb->localalloc=bytes;
  97673. vb->localstore=_ogg_malloc(vb->localalloc);
  97674. vb->localtop=0;
  97675. }
  97676. {
  97677. void *ret=(void *)(((char *)vb->localstore)+vb->localtop);
  97678. vb->localtop+=bytes;
  97679. return ret;
  97680. }
  97681. }
  97682. void _vorbis_block_ripcord(vorbis_block *vb){
  97683. struct alloc_chain *reap=vb->reap;
  97684. while(reap){
  97685. struct alloc_chain *next=reap->next;
  97686. _ogg_free(reap->ptr);
  97687. memset(reap,0,sizeof(*reap));
  97688. _ogg_free(reap);
  97689. reap=next;
  97690. }
  97691. if(vb->totaluse){
  97692. vb->localstore=_ogg_realloc(vb->localstore,vb->totaluse+vb->localalloc);
  97693. vb->localalloc+=vb->totaluse;
  97694. vb->totaluse=0;
  97695. }
  97696. vb->localtop=0;
  97697. vb->reap=NULL;
  97698. }
  97699. int vorbis_block_clear(vorbis_block *vb){
  97700. int i;
  97701. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97702. _vorbis_block_ripcord(vb);
  97703. if(vb->localstore)_ogg_free(vb->localstore);
  97704. if(vbi){
  97705. for(i=0;i<PACKETBLOBS;i++){
  97706. oggpack_writeclear(vbi->packetblob[i]);
  97707. if(i!=PACKETBLOBS/2)_ogg_free(vbi->packetblob[i]);
  97708. }
  97709. _ogg_free(vbi);
  97710. }
  97711. memset(vb,0,sizeof(*vb));
  97712. return(0);
  97713. }
  97714. static int _vds_shared_init(vorbis_dsp_state *v,vorbis_info *vi,int encp){
  97715. int i;
  97716. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97717. private_state *b=NULL;
  97718. int hs;
  97719. if(ci==NULL) return 1;
  97720. hs=ci->halfrate_flag;
  97721. memset(v,0,sizeof(*v));
  97722. b=(private_state*) (v->backend_state=(private_state*)_ogg_calloc(1,sizeof(*b)));
  97723. v->vi=vi;
  97724. b->modebits=ilog2(ci->modes);
  97725. b->transform[0]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[0]));
  97726. b->transform[1]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[1]));
  97727. b->transform[0][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  97728. b->transform[1][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  97729. mdct_init((mdct_lookup*)b->transform[0][0],ci->blocksizes[0]>>hs);
  97730. mdct_init((mdct_lookup*)b->transform[1][0],ci->blocksizes[1]>>hs);
  97731. b->window[0]=ilog2(ci->blocksizes[0])-6;
  97732. b->window[1]=ilog2(ci->blocksizes[1])-6;
  97733. if(encp){ /* encode/decode differ here */
  97734. drft_init(&b->fft_look[0],ci->blocksizes[0]);
  97735. drft_init(&b->fft_look[1],ci->blocksizes[1]);
  97736. if(!ci->fullbooks){
  97737. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  97738. for(i=0;i<ci->books;i++)
  97739. vorbis_book_init_encode(ci->fullbooks+i,ci->book_param[i]);
  97740. }
  97741. b->psy=(vorbis_look_psy*)_ogg_calloc(ci->psys,sizeof(*b->psy));
  97742. for(i=0;i<ci->psys;i++){
  97743. _vp_psy_init(b->psy+i,
  97744. ci->psy_param[i],
  97745. &ci->psy_g_param,
  97746. ci->blocksizes[ci->psy_param[i]->blockflag]/2,
  97747. vi->rate);
  97748. }
  97749. v->analysisp=1;
  97750. }else{
  97751. if(!ci->fullbooks){
  97752. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  97753. for(i=0;i<ci->books;i++){
  97754. vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]);
  97755. vorbis_staticbook_destroy(ci->book_param[i]);
  97756. ci->book_param[i]=NULL;
  97757. }
  97758. }
  97759. }
  97760. v->pcm_storage=ci->blocksizes[1];
  97761. v->pcm=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcm));
  97762. v->pcmret=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcmret));
  97763. {
  97764. int i;
  97765. for(i=0;i<vi->channels;i++)
  97766. v->pcm[i]=(float*)_ogg_calloc(v->pcm_storage,sizeof(*v->pcm[i]));
  97767. }
  97768. v->lW=0; /* previous window size */
  97769. v->W=0; /* current window size */
  97770. v->centerW=ci->blocksizes[1]/2;
  97771. v->pcm_current=v->centerW;
  97772. b->flr=(vorbis_look_floor**)_ogg_calloc(ci->floors,sizeof(*b->flr));
  97773. b->residue=(vorbis_look_residue**)_ogg_calloc(ci->residues,sizeof(*b->residue));
  97774. for(i=0;i<ci->floors;i++)
  97775. b->flr[i]=_floor_P[ci->floor_type[i]]->
  97776. look(v,ci->floor_param[i]);
  97777. for(i=0;i<ci->residues;i++)
  97778. b->residue[i]=_residue_P[ci->residue_type[i]]->
  97779. look(v,ci->residue_param[i]);
  97780. return 0;
  97781. }
  97782. int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi){
  97783. private_state *b=NULL;
  97784. if(_vds_shared_init(v,vi,1))return 1;
  97785. b=(private_state*)v->backend_state;
  97786. b->psy_g_look=_vp_global_look(vi);
  97787. b->ve=(envelope_lookup*)_ogg_calloc(1,sizeof(*b->ve));
  97788. _ve_envelope_init(b->ve,vi);
  97789. vorbis_bitrate_init(vi,&b->bms);
  97790. v->sequence=3;
  97791. return(0);
  97792. }
  97793. void vorbis_dsp_clear(vorbis_dsp_state *v){
  97794. int i;
  97795. if(v){
  97796. vorbis_info *vi=v->vi;
  97797. codec_setup_info *ci=(codec_setup_info*)(vi?vi->codec_setup:NULL);
  97798. private_state *b=(private_state*)v->backend_state;
  97799. if(b){
  97800. if(b->ve){
  97801. _ve_envelope_clear(b->ve);
  97802. _ogg_free(b->ve);
  97803. }
  97804. if(b->transform[0]){
  97805. mdct_clear((mdct_lookup*) b->transform[0][0]);
  97806. _ogg_free(b->transform[0][0]);
  97807. _ogg_free(b->transform[0]);
  97808. }
  97809. if(b->transform[1]){
  97810. mdct_clear((mdct_lookup*) b->transform[1][0]);
  97811. _ogg_free(b->transform[1][0]);
  97812. _ogg_free(b->transform[1]);
  97813. }
  97814. if(b->flr){
  97815. for(i=0;i<ci->floors;i++)
  97816. _floor_P[ci->floor_type[i]]->
  97817. free_look(b->flr[i]);
  97818. _ogg_free(b->flr);
  97819. }
  97820. if(b->residue){
  97821. for(i=0;i<ci->residues;i++)
  97822. _residue_P[ci->residue_type[i]]->
  97823. free_look(b->residue[i]);
  97824. _ogg_free(b->residue);
  97825. }
  97826. if(b->psy){
  97827. for(i=0;i<ci->psys;i++)
  97828. _vp_psy_clear(b->psy+i);
  97829. _ogg_free(b->psy);
  97830. }
  97831. if(b->psy_g_look)_vp_global_free(b->psy_g_look);
  97832. vorbis_bitrate_clear(&b->bms);
  97833. drft_clear(&b->fft_look[0]);
  97834. drft_clear(&b->fft_look[1]);
  97835. }
  97836. if(v->pcm){
  97837. for(i=0;i<vi->channels;i++)
  97838. if(v->pcm[i])_ogg_free(v->pcm[i]);
  97839. _ogg_free(v->pcm);
  97840. if(v->pcmret)_ogg_free(v->pcmret);
  97841. }
  97842. if(b){
  97843. if(b->header)_ogg_free(b->header);
  97844. if(b->header1)_ogg_free(b->header1);
  97845. if(b->header2)_ogg_free(b->header2);
  97846. _ogg_free(b);
  97847. }
  97848. memset(v,0,sizeof(*v));
  97849. }
  97850. }
  97851. float **vorbis_analysis_buffer(vorbis_dsp_state *v, int vals){
  97852. int i;
  97853. vorbis_info *vi=v->vi;
  97854. private_state *b=(private_state*)v->backend_state;
  97855. if(b->header)_ogg_free(b->header);b->header=NULL;
  97856. if(b->header1)_ogg_free(b->header1);b->header1=NULL;
  97857. if(b->header2)_ogg_free(b->header2);b->header2=NULL;
  97858. if(v->pcm_current+vals>=v->pcm_storage){
  97859. v->pcm_storage=v->pcm_current+vals*2;
  97860. for(i=0;i<vi->channels;i++){
  97861. v->pcm[i]=(float*)_ogg_realloc(v->pcm[i],v->pcm_storage*sizeof(*v->pcm[i]));
  97862. }
  97863. }
  97864. for(i=0;i<vi->channels;i++)
  97865. v->pcmret[i]=v->pcm[i]+v->pcm_current;
  97866. return(v->pcmret);
  97867. }
  97868. static void _preextrapolate_helper(vorbis_dsp_state *v){
  97869. int i;
  97870. int order=32;
  97871. float *lpc=(float*)alloca(order*sizeof(*lpc));
  97872. float *work=(float*)alloca(v->pcm_current*sizeof(*work));
  97873. long j;
  97874. v->preextrapolate=1;
  97875. if(v->pcm_current-v->centerW>order*2){ /* safety */
  97876. for(i=0;i<v->vi->channels;i++){
  97877. for(j=0;j<v->pcm_current;j++)
  97878. work[j]=v->pcm[i][v->pcm_current-j-1];
  97879. vorbis_lpc_from_data(work,lpc,v->pcm_current-v->centerW,order);
  97880. vorbis_lpc_predict(lpc,work+v->pcm_current-v->centerW-order,
  97881. order,
  97882. work+v->pcm_current-v->centerW,
  97883. v->centerW);
  97884. for(j=0;j<v->pcm_current;j++)
  97885. v->pcm[i][v->pcm_current-j-1]=work[j];
  97886. }
  97887. }
  97888. }
  97889. int vorbis_analysis_wrote(vorbis_dsp_state *v, int vals){
  97890. vorbis_info *vi=v->vi;
  97891. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97892. if(vals<=0){
  97893. int order=32;
  97894. int i;
  97895. float *lpc=(float*) alloca(order*sizeof(*lpc));
  97896. if(!v->preextrapolate)
  97897. _preextrapolate_helper(v);
  97898. vorbis_analysis_buffer(v,ci->blocksizes[1]*3);
  97899. v->eofflag=v->pcm_current;
  97900. v->pcm_current+=ci->blocksizes[1]*3;
  97901. for(i=0;i<vi->channels;i++){
  97902. if(v->eofflag>order*2){
  97903. long n;
  97904. n=v->eofflag;
  97905. if(n>ci->blocksizes[1])n=ci->blocksizes[1];
  97906. vorbis_lpc_from_data(v->pcm[i]+v->eofflag-n,lpc,n,order);
  97907. vorbis_lpc_predict(lpc,v->pcm[i]+v->eofflag-order,order,
  97908. v->pcm[i]+v->eofflag,v->pcm_current-v->eofflag);
  97909. }else{
  97910. memset(v->pcm[i]+v->eofflag,0,
  97911. (v->pcm_current-v->eofflag)*sizeof(*v->pcm[i]));
  97912. }
  97913. }
  97914. }else{
  97915. if(v->pcm_current+vals>v->pcm_storage)
  97916. return(OV_EINVAL);
  97917. v->pcm_current+=vals;
  97918. if(!v->preextrapolate && v->pcm_current-v->centerW>ci->blocksizes[1])
  97919. _preextrapolate_helper(v);
  97920. }
  97921. return(0);
  97922. }
  97923. int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb){
  97924. int i;
  97925. vorbis_info *vi=v->vi;
  97926. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97927. private_state *b=(private_state*)v->backend_state;
  97928. vorbis_look_psy_global *g=b->psy_g_look;
  97929. long beginW=v->centerW-ci->blocksizes[v->W]/2,centerNext;
  97930. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  97931. if(!v->preextrapolate)return(0);
  97932. if(v->eofflag==-1)return(0);
  97933. {
  97934. long bp=_ve_envelope_search(v);
  97935. if(bp==-1){
  97936. if(v->eofflag==0)return(0); /* not enough data currently to search for a
  97937. full long block */
  97938. v->nW=0;
  97939. }else{
  97940. if(ci->blocksizes[0]==ci->blocksizes[1])
  97941. v->nW=0;
  97942. else
  97943. v->nW=bp;
  97944. }
  97945. }
  97946. centerNext=v->centerW+ci->blocksizes[v->W]/4+ci->blocksizes[v->nW]/4;
  97947. {
  97948. long blockbound=centerNext+ci->blocksizes[v->nW]/2;
  97949. if(v->pcm_current<blockbound)return(0); /* not enough data yet;
  97950. although this check is
  97951. less strict that the
  97952. _ve_envelope_search,
  97953. the search is not run
  97954. if we only use one
  97955. block size */
  97956. }
  97957. _vorbis_block_ripcord(vb);
  97958. vb->lW=v->lW;
  97959. vb->W=v->W;
  97960. vb->nW=v->nW;
  97961. if(v->W){
  97962. if(!v->lW || !v->nW){
  97963. vbi->blocktype=BLOCKTYPE_TRANSITION;
  97964. }else{
  97965. vbi->blocktype=BLOCKTYPE_LONG;
  97966. }
  97967. }else{
  97968. if(_ve_envelope_mark(v)){
  97969. vbi->blocktype=BLOCKTYPE_IMPULSE;
  97970. }else{
  97971. vbi->blocktype=BLOCKTYPE_PADDING;
  97972. }
  97973. }
  97974. vb->vd=v;
  97975. vb->sequence=v->sequence++;
  97976. vb->granulepos=v->granulepos;
  97977. vb->pcmend=ci->blocksizes[v->W];
  97978. if(vbi->ampmax>g->ampmax)g->ampmax=vbi->ampmax;
  97979. g->ampmax=_vp_ampmax_decay(g->ampmax,v);
  97980. vbi->ampmax=g->ampmax;
  97981. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  97982. vbi->pcmdelay=(float**)_vorbis_block_alloc(vb,sizeof(*vbi->pcmdelay)*vi->channels);
  97983. for(i=0;i<vi->channels;i++){
  97984. vbi->pcmdelay[i]=
  97985. (float*) _vorbis_block_alloc(vb,(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  97986. memcpy(vbi->pcmdelay[i],v->pcm[i],(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  97987. vb->pcm[i]=vbi->pcmdelay[i]+beginW;
  97988. }
  97989. if(v->eofflag){
  97990. if(v->centerW>=v->eofflag){
  97991. v->eofflag=-1;
  97992. vb->eofflag=1;
  97993. return(1);
  97994. }
  97995. }
  97996. {
  97997. int new_centerNext=ci->blocksizes[1]/2;
  97998. int movementW=centerNext-new_centerNext;
  97999. if(movementW>0){
  98000. _ve_envelope_shift(b->ve,movementW);
  98001. v->pcm_current-=movementW;
  98002. for(i=0;i<vi->channels;i++)
  98003. memmove(v->pcm[i],v->pcm[i]+movementW,
  98004. v->pcm_current*sizeof(*v->pcm[i]));
  98005. v->lW=v->W;
  98006. v->W=v->nW;
  98007. v->centerW=new_centerNext;
  98008. if(v->eofflag){
  98009. v->eofflag-=movementW;
  98010. if(v->eofflag<=0)v->eofflag=-1;
  98011. if(v->centerW>=v->eofflag){
  98012. v->granulepos+=movementW-(v->centerW-v->eofflag);
  98013. }else{
  98014. v->granulepos+=movementW;
  98015. }
  98016. }else{
  98017. v->granulepos+=movementW;
  98018. }
  98019. }
  98020. }
  98021. return(1);
  98022. }
  98023. int vorbis_synthesis_restart(vorbis_dsp_state *v){
  98024. vorbis_info *vi=v->vi;
  98025. codec_setup_info *ci;
  98026. int hs;
  98027. if(!v->backend_state)return -1;
  98028. if(!vi)return -1;
  98029. ci=(codec_setup_info*) vi->codec_setup;
  98030. if(!ci)return -1;
  98031. hs=ci->halfrate_flag;
  98032. v->centerW=ci->blocksizes[1]>>(hs+1);
  98033. v->pcm_current=v->centerW>>hs;
  98034. v->pcm_returned=-1;
  98035. v->granulepos=-1;
  98036. v->sequence=-1;
  98037. v->eofflag=0;
  98038. ((private_state *)(v->backend_state))->sample_count=-1;
  98039. return(0);
  98040. }
  98041. int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
  98042. if(_vds_shared_init(v,vi,0)) return 1;
  98043. vorbis_synthesis_restart(v);
  98044. return 0;
  98045. }
  98046. int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
  98047. vorbis_info *vi=v->vi;
  98048. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98049. private_state *b=(private_state*)v->backend_state;
  98050. int hs=ci->halfrate_flag;
  98051. int i,j;
  98052. if(!vb)return(OV_EINVAL);
  98053. if(v->pcm_current>v->pcm_returned && v->pcm_returned!=-1)return(OV_EINVAL);
  98054. v->lW=v->W;
  98055. v->W=vb->W;
  98056. v->nW=-1;
  98057. if((v->sequence==-1)||
  98058. (v->sequence+1 != vb->sequence)){
  98059. v->granulepos=-1; /* out of sequence; lose count */
  98060. b->sample_count=-1;
  98061. }
  98062. v->sequence=vb->sequence;
  98063. if(vb->pcm){ /* no pcm to process if vorbis_synthesis_trackonly
  98064. was called on block */
  98065. int n=ci->blocksizes[v->W]>>(hs+1);
  98066. int n0=ci->blocksizes[0]>>(hs+1);
  98067. int n1=ci->blocksizes[1]>>(hs+1);
  98068. int thisCenter;
  98069. int prevCenter;
  98070. v->glue_bits+=vb->glue_bits;
  98071. v->time_bits+=vb->time_bits;
  98072. v->floor_bits+=vb->floor_bits;
  98073. v->res_bits+=vb->res_bits;
  98074. if(v->centerW){
  98075. thisCenter=n1;
  98076. prevCenter=0;
  98077. }else{
  98078. thisCenter=0;
  98079. prevCenter=n1;
  98080. }
  98081. for(j=0;j<vi->channels;j++){
  98082. if(v->lW){
  98083. if(v->W){
  98084. float *w=_vorbis_window_get(b->window[1]-hs);
  98085. float *pcm=v->pcm[j]+prevCenter;
  98086. float *p=vb->pcm[j];
  98087. for(i=0;i<n1;i++)
  98088. pcm[i]=pcm[i]*w[n1-i-1] + p[i]*w[i];
  98089. }else{
  98090. float *w=_vorbis_window_get(b->window[0]-hs);
  98091. float *pcm=v->pcm[j]+prevCenter+n1/2-n0/2;
  98092. float *p=vb->pcm[j];
  98093. for(i=0;i<n0;i++)
  98094. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98095. }
  98096. }else{
  98097. if(v->W){
  98098. float *w=_vorbis_window_get(b->window[0]-hs);
  98099. float *pcm=v->pcm[j]+prevCenter;
  98100. float *p=vb->pcm[j]+n1/2-n0/2;
  98101. for(i=0;i<n0;i++)
  98102. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98103. for(;i<n1/2+n0/2;i++)
  98104. pcm[i]=p[i];
  98105. }else{
  98106. float *w=_vorbis_window_get(b->window[0]-hs);
  98107. float *pcm=v->pcm[j]+prevCenter;
  98108. float *p=vb->pcm[j];
  98109. for(i=0;i<n0;i++)
  98110. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98111. }
  98112. }
  98113. {
  98114. float *pcm=v->pcm[j]+thisCenter;
  98115. float *p=vb->pcm[j]+n;
  98116. for(i=0;i<n;i++)
  98117. pcm[i]=p[i];
  98118. }
  98119. }
  98120. if(v->centerW)
  98121. v->centerW=0;
  98122. else
  98123. v->centerW=n1;
  98124. if(v->pcm_returned==-1){
  98125. v->pcm_returned=thisCenter;
  98126. v->pcm_current=thisCenter;
  98127. }else{
  98128. v->pcm_returned=prevCenter;
  98129. v->pcm_current=prevCenter+
  98130. ((ci->blocksizes[v->lW]/4+
  98131. ci->blocksizes[v->W]/4)>>hs);
  98132. }
  98133. }
  98134. if(b->sample_count==-1){
  98135. b->sample_count=0;
  98136. }else{
  98137. b->sample_count+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98138. }
  98139. if(v->granulepos==-1){
  98140. if(vb->granulepos!=-1){ /* only set if we have a position to set to */
  98141. v->granulepos=vb->granulepos;
  98142. if(b->sample_count>v->granulepos){
  98143. if(vb->eofflag){
  98144. v->pcm_current-=(b->sample_count-v->granulepos)>>hs;
  98145. }else{
  98146. v->pcm_returned+=(b->sample_count-v->granulepos)>>hs;
  98147. if(v->pcm_returned>v->pcm_current)
  98148. v->pcm_returned=v->pcm_current;
  98149. }
  98150. }
  98151. }
  98152. }else{
  98153. v->granulepos+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98154. if(vb->granulepos!=-1 && v->granulepos!=vb->granulepos){
  98155. if(v->granulepos>vb->granulepos){
  98156. long extra=v->granulepos-vb->granulepos;
  98157. if(extra)
  98158. if(vb->eofflag){
  98159. v->pcm_current-=extra>>hs;
  98160. } /* else {Shouldn't happen *unless* the bitstream is out of
  98161. spec. Either way, believe the bitstream } */
  98162. } /* else {Shouldn't happen *unless* the bitstream is out of
  98163. spec. Either way, believe the bitstream } */
  98164. v->granulepos=vb->granulepos;
  98165. }
  98166. }
  98167. if(vb->eofflag)v->eofflag=1;
  98168. return(0);
  98169. }
  98170. int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm){
  98171. vorbis_info *vi=v->vi;
  98172. if(v->pcm_returned>-1 && v->pcm_returned<v->pcm_current){
  98173. if(pcm){
  98174. int i;
  98175. for(i=0;i<vi->channels;i++)
  98176. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98177. *pcm=v->pcmret;
  98178. }
  98179. return(v->pcm_current-v->pcm_returned);
  98180. }
  98181. return(0);
  98182. }
  98183. int vorbis_synthesis_read(vorbis_dsp_state *v,int n){
  98184. if(n && v->pcm_returned+n>v->pcm_current)return(OV_EINVAL);
  98185. v->pcm_returned+=n;
  98186. return(0);
  98187. }
  98188. int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm){
  98189. vorbis_info *vi=v->vi;
  98190. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  98191. int hs=ci->halfrate_flag;
  98192. int n=ci->blocksizes[v->W]>>(hs+1);
  98193. int n0=ci->blocksizes[0]>>(hs+1);
  98194. int n1=ci->blocksizes[1]>>(hs+1);
  98195. int i,j;
  98196. if(v->pcm_returned<0)return 0;
  98197. if(v->centerW==n1){
  98198. for(j=0;j<vi->channels;j++){
  98199. float *p=v->pcm[j];
  98200. for(i=0;i<n1;i++){
  98201. float temp=p[i];
  98202. p[i]=p[i+n1];
  98203. p[i+n1]=temp;
  98204. }
  98205. }
  98206. v->pcm_current-=n1;
  98207. v->pcm_returned-=n1;
  98208. v->centerW=0;
  98209. }
  98210. if((v->lW^v->W)==1){
  98211. for(j=0;j<vi->channels;j++){
  98212. float *s=v->pcm[j];
  98213. float *d=v->pcm[j]+(n1-n0)/2;
  98214. for(i=(n1+n0)/2-1;i>=0;--i)
  98215. d[i]=s[i];
  98216. }
  98217. v->pcm_returned+=(n1-n0)/2;
  98218. v->pcm_current+=(n1-n0)/2;
  98219. }else{
  98220. if(v->lW==0){
  98221. for(j=0;j<vi->channels;j++){
  98222. float *s=v->pcm[j];
  98223. float *d=v->pcm[j]+n1-n0;
  98224. for(i=n0-1;i>=0;--i)
  98225. d[i]=s[i];
  98226. }
  98227. v->pcm_returned+=n1-n0;
  98228. v->pcm_current+=n1-n0;
  98229. }
  98230. }
  98231. if(pcm){
  98232. int i;
  98233. for(i=0;i<vi->channels;i++)
  98234. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98235. *pcm=v->pcmret;
  98236. }
  98237. return(n1+n-v->pcm_returned);
  98238. }
  98239. float *vorbis_window(vorbis_dsp_state *v,int W){
  98240. vorbis_info *vi=v->vi;
  98241. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  98242. int hs=ci->halfrate_flag;
  98243. private_state *b=(private_state*)v->backend_state;
  98244. if(b->window[W]-1<0)return NULL;
  98245. return _vorbis_window_get(b->window[W]-hs);
  98246. }
  98247. #endif
  98248. /*** End of inlined file: block.c ***/
  98249. /*** Start of inlined file: codebook.c ***/
  98250. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98251. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98252. // tasks..
  98253. #if JUCE_MSVC
  98254. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98255. #endif
  98256. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98257. #if JUCE_USE_OGGVORBIS
  98258. #include <stdlib.h>
  98259. #include <string.h>
  98260. #include <math.h>
  98261. int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *opb){
  98262. long i,j;
  98263. int ordered=0;
  98264. oggpack_write(opb,0x564342,24);
  98265. oggpack_write(opb,c->dim,16);
  98266. oggpack_write(opb,c->entries,24);
  98267. for(i=1;i<c->entries;i++)
  98268. if(c->lengthlist[i-1]==0 || c->lengthlist[i]<c->lengthlist[i-1])break;
  98269. if(i==c->entries)ordered=1;
  98270. if(ordered){
  98271. long count=0;
  98272. oggpack_write(opb,1,1); /* ordered */
  98273. oggpack_write(opb,c->lengthlist[0]-1,5); /* 1 to 32 */
  98274. for(i=1;i<c->entries;i++){
  98275. long thisx=c->lengthlist[i];
  98276. long last=c->lengthlist[i-1];
  98277. if(thisx>last){
  98278. for(j=last;j<thisx;j++){
  98279. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98280. count=i;
  98281. }
  98282. }
  98283. }
  98284. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98285. }else{
  98286. oggpack_write(opb,0,1); /* unordered */
  98287. for(i=0;i<c->entries;i++)
  98288. if(c->lengthlist[i]==0)break;
  98289. if(i==c->entries){
  98290. oggpack_write(opb,0,1); /* no unused entries */
  98291. for(i=0;i<c->entries;i++)
  98292. oggpack_write(opb,c->lengthlist[i]-1,5);
  98293. }else{
  98294. oggpack_write(opb,1,1); /* we have unused entries; thus we tag */
  98295. for(i=0;i<c->entries;i++){
  98296. if(c->lengthlist[i]==0){
  98297. oggpack_write(opb,0,1);
  98298. }else{
  98299. oggpack_write(opb,1,1);
  98300. oggpack_write(opb,c->lengthlist[i]-1,5);
  98301. }
  98302. }
  98303. }
  98304. }
  98305. oggpack_write(opb,c->maptype,4);
  98306. switch(c->maptype){
  98307. case 0:
  98308. break;
  98309. case 1:case 2:
  98310. if(!c->quantlist){
  98311. return(-1);
  98312. }
  98313. oggpack_write(opb,c->q_min,32);
  98314. oggpack_write(opb,c->q_delta,32);
  98315. oggpack_write(opb,c->q_quant-1,4);
  98316. oggpack_write(opb,c->q_sequencep,1);
  98317. {
  98318. int quantvals;
  98319. switch(c->maptype){
  98320. case 1:
  98321. quantvals=_book_maptype1_quantvals(c);
  98322. break;
  98323. case 2:
  98324. quantvals=c->entries*c->dim;
  98325. break;
  98326. default: /* NOT_REACHABLE */
  98327. quantvals=-1;
  98328. }
  98329. for(i=0;i<quantvals;i++)
  98330. oggpack_write(opb,labs(c->quantlist[i]),c->q_quant);
  98331. }
  98332. break;
  98333. default:
  98334. return(-1);
  98335. }
  98336. return(0);
  98337. }
  98338. int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){
  98339. long i,j;
  98340. memset(s,0,sizeof(*s));
  98341. s->allocedp=1;
  98342. if(oggpack_read(opb,24)!=0x564342)goto _eofout;
  98343. s->dim=oggpack_read(opb,16);
  98344. s->entries=oggpack_read(opb,24);
  98345. if(s->entries==-1)goto _eofout;
  98346. switch((int)oggpack_read(opb,1)){
  98347. case 0:
  98348. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98349. if(oggpack_read(opb,1)){
  98350. for(i=0;i<s->entries;i++){
  98351. if(oggpack_read(opb,1)){
  98352. long num=oggpack_read(opb,5);
  98353. if(num==-1)goto _eofout;
  98354. s->lengthlist[i]=num+1;
  98355. }else
  98356. s->lengthlist[i]=0;
  98357. }
  98358. }else{
  98359. for(i=0;i<s->entries;i++){
  98360. long num=oggpack_read(opb,5);
  98361. if(num==-1)goto _eofout;
  98362. s->lengthlist[i]=num+1;
  98363. }
  98364. }
  98365. break;
  98366. case 1:
  98367. {
  98368. long length=oggpack_read(opb,5)+1;
  98369. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98370. for(i=0;i<s->entries;){
  98371. long num=oggpack_read(opb,_ilog(s->entries-i));
  98372. if(num==-1)goto _eofout;
  98373. for(j=0;j<num && i<s->entries;j++,i++)
  98374. s->lengthlist[i]=length;
  98375. length++;
  98376. }
  98377. }
  98378. break;
  98379. default:
  98380. return(-1);
  98381. }
  98382. switch((s->maptype=oggpack_read(opb,4))){
  98383. case 0:
  98384. break;
  98385. case 1: case 2:
  98386. s->q_min=oggpack_read(opb,32);
  98387. s->q_delta=oggpack_read(opb,32);
  98388. s->q_quant=oggpack_read(opb,4)+1;
  98389. s->q_sequencep=oggpack_read(opb,1);
  98390. {
  98391. int quantvals=0;
  98392. switch(s->maptype){
  98393. case 1:
  98394. quantvals=_book_maptype1_quantvals(s);
  98395. break;
  98396. case 2:
  98397. quantvals=s->entries*s->dim;
  98398. break;
  98399. }
  98400. s->quantlist=(long*)_ogg_malloc(sizeof(*s->quantlist)*quantvals);
  98401. for(i=0;i<quantvals;i++)
  98402. s->quantlist[i]=oggpack_read(opb,s->q_quant);
  98403. if(quantvals&&s->quantlist[quantvals-1]==-1)goto _eofout;
  98404. }
  98405. break;
  98406. default:
  98407. goto _errout;
  98408. }
  98409. return(0);
  98410. _errout:
  98411. _eofout:
  98412. vorbis_staticbook_clear(s);
  98413. return(-1);
  98414. }
  98415. int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b){
  98416. oggpack_write(b,book->codelist[a],book->c->lengthlist[a]);
  98417. return(book->c->lengthlist[a]);
  98418. }
  98419. int vorbis_book_errorv(codebook *book,float *a){
  98420. int dim=book->dim,k;
  98421. int best=_best(book,a,1);
  98422. for(k=0;k<dim;k++)
  98423. a[k]=(book->valuelist+best*dim)[k];
  98424. return(best);
  98425. }
  98426. int vorbis_book_encodev(codebook *book,int best,float *a,oggpack_buffer *b){
  98427. int k,dim=book->dim;
  98428. for(k=0;k<dim;k++)
  98429. a[k]=(book->valuelist+best*dim)[k];
  98430. return(vorbis_book_encode(book,best,b));
  98431. }
  98432. STIN long decode_packed_entry_number(codebook *book, oggpack_buffer *b){
  98433. int read=book->dec_maxlength;
  98434. long lo,hi;
  98435. long lok = oggpack_look(b,book->dec_firsttablen);
  98436. if (lok >= 0) {
  98437. long entry = book->dec_firsttable[lok];
  98438. if(entry&0x80000000UL){
  98439. lo=(entry>>15)&0x7fff;
  98440. hi=book->used_entries-(entry&0x7fff);
  98441. }else{
  98442. oggpack_adv(b, book->dec_codelengths[entry-1]);
  98443. return(entry-1);
  98444. }
  98445. }else{
  98446. lo=0;
  98447. hi=book->used_entries;
  98448. }
  98449. lok = oggpack_look(b, read);
  98450. while(lok<0 && read>1)
  98451. lok = oggpack_look(b, --read);
  98452. if(lok<0)return -1;
  98453. {
  98454. ogg_uint32_t testword=ogg_bitreverse((ogg_uint32_t)lok);
  98455. while(hi-lo>1){
  98456. long p=(hi-lo)>>1;
  98457. long test=book->codelist[lo+p]>testword;
  98458. lo+=p&(test-1);
  98459. hi-=p&(-test);
  98460. }
  98461. if(book->dec_codelengths[lo]<=read){
  98462. oggpack_adv(b, book->dec_codelengths[lo]);
  98463. return(lo);
  98464. }
  98465. }
  98466. oggpack_adv(b, read);
  98467. return(-1);
  98468. }
  98469. long vorbis_book_decode(codebook *book, oggpack_buffer *b){
  98470. long packed_entry=decode_packed_entry_number(book,b);
  98471. if(packed_entry>=0)
  98472. return(book->dec_index[packed_entry]);
  98473. return(packed_entry);
  98474. }
  98475. long vorbis_book_decodevs_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98476. int step=n/book->dim;
  98477. long *entry = (long*)alloca(sizeof(*entry)*step);
  98478. float **t = (float**)alloca(sizeof(*t)*step);
  98479. int i,j,o;
  98480. for (i = 0; i < step; i++) {
  98481. entry[i]=decode_packed_entry_number(book,b);
  98482. if(entry[i]==-1)return(-1);
  98483. t[i] = book->valuelist+entry[i]*book->dim;
  98484. }
  98485. for(i=0,o=0;i<book->dim;i++,o+=step)
  98486. for (j=0;j<step;j++)
  98487. a[o+j]+=t[j][i];
  98488. return(0);
  98489. }
  98490. long vorbis_book_decodev_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98491. int i,j,entry;
  98492. float *t;
  98493. if(book->dim>8){
  98494. for(i=0;i<n;){
  98495. entry = decode_packed_entry_number(book,b);
  98496. if(entry==-1)return(-1);
  98497. t = book->valuelist+entry*book->dim;
  98498. for (j=0;j<book->dim;)
  98499. a[i++]+=t[j++];
  98500. }
  98501. }else{
  98502. for(i=0;i<n;){
  98503. entry = decode_packed_entry_number(book,b);
  98504. if(entry==-1)return(-1);
  98505. t = book->valuelist+entry*book->dim;
  98506. j=0;
  98507. switch((int)book->dim){
  98508. case 8:
  98509. a[i++]+=t[j++];
  98510. case 7:
  98511. a[i++]+=t[j++];
  98512. case 6:
  98513. a[i++]+=t[j++];
  98514. case 5:
  98515. a[i++]+=t[j++];
  98516. case 4:
  98517. a[i++]+=t[j++];
  98518. case 3:
  98519. a[i++]+=t[j++];
  98520. case 2:
  98521. a[i++]+=t[j++];
  98522. case 1:
  98523. a[i++]+=t[j++];
  98524. case 0:
  98525. break;
  98526. }
  98527. }
  98528. }
  98529. return(0);
  98530. }
  98531. long vorbis_book_decodev_set(codebook *book,float *a,oggpack_buffer *b,int n){
  98532. int i,j,entry;
  98533. float *t;
  98534. for(i=0;i<n;){
  98535. entry = decode_packed_entry_number(book,b);
  98536. if(entry==-1)return(-1);
  98537. t = book->valuelist+entry*book->dim;
  98538. for (j=0;j<book->dim;)
  98539. a[i++]=t[j++];
  98540. }
  98541. return(0);
  98542. }
  98543. long vorbis_book_decodevv_add(codebook *book,float **a,long offset,int ch,
  98544. oggpack_buffer *b,int n){
  98545. long i,j,entry;
  98546. int chptr=0;
  98547. for(i=offset/ch;i<(offset+n)/ch;){
  98548. entry = decode_packed_entry_number(book,b);
  98549. if(entry==-1)return(-1);
  98550. {
  98551. const float *t = book->valuelist+entry*book->dim;
  98552. for (j=0;j<book->dim;j++){
  98553. a[chptr++][i]+=t[j];
  98554. if(chptr==ch){
  98555. chptr=0;
  98556. i++;
  98557. }
  98558. }
  98559. }
  98560. }
  98561. return(0);
  98562. }
  98563. #ifdef _V_SELFTEST
  98564. #include <stdio.h>
  98565. #include "vorbis/book/lsp20_0.vqh"
  98566. #include "vorbis/book/res0a_13.vqh"
  98567. #define TESTSIZE 40
  98568. float test1[TESTSIZE]={
  98569. 0.105939f,
  98570. 0.215373f,
  98571. 0.429117f,
  98572. 0.587974f,
  98573. 0.181173f,
  98574. 0.296583f,
  98575. 0.515707f,
  98576. 0.715261f,
  98577. 0.162327f,
  98578. 0.263834f,
  98579. 0.342876f,
  98580. 0.406025f,
  98581. 0.103571f,
  98582. 0.223561f,
  98583. 0.368513f,
  98584. 0.540313f,
  98585. 0.136672f,
  98586. 0.395882f,
  98587. 0.587183f,
  98588. 0.652476f,
  98589. 0.114338f,
  98590. 0.417300f,
  98591. 0.525486f,
  98592. 0.698679f,
  98593. 0.147492f,
  98594. 0.324481f,
  98595. 0.643089f,
  98596. 0.757582f,
  98597. 0.139556f,
  98598. 0.215795f,
  98599. 0.324559f,
  98600. 0.399387f,
  98601. 0.120236f,
  98602. 0.267420f,
  98603. 0.446940f,
  98604. 0.608760f,
  98605. 0.115587f,
  98606. 0.287234f,
  98607. 0.571081f,
  98608. 0.708603f,
  98609. };
  98610. float test3[TESTSIZE]={
  98611. 0,1,-2,3,4,-5,6,7,8,9,
  98612. 8,-2,7,-1,4,6,8,3,1,-9,
  98613. 10,11,12,13,14,15,26,17,18,19,
  98614. 30,-25,-30,-1,-5,-32,4,3,-2,0};
  98615. static_codebook *testlist[]={&_vq_book_lsp20_0,
  98616. &_vq_book_res0a_13,NULL};
  98617. float *testvec[]={test1,test3};
  98618. int main(){
  98619. oggpack_buffer write;
  98620. oggpack_buffer read;
  98621. long ptr=0,i;
  98622. oggpack_writeinit(&write);
  98623. fprintf(stderr,"Testing codebook abstraction...:\n");
  98624. while(testlist[ptr]){
  98625. codebook c;
  98626. static_codebook s;
  98627. float *qv=alloca(sizeof(*qv)*TESTSIZE);
  98628. float *iv=alloca(sizeof(*iv)*TESTSIZE);
  98629. memcpy(qv,testvec[ptr],sizeof(*qv)*TESTSIZE);
  98630. memset(iv,0,sizeof(*iv)*TESTSIZE);
  98631. fprintf(stderr,"\tpacking/coding %ld... ",ptr);
  98632. oggpack_reset(&write);
  98633. vorbis_book_init_encode(&c,testlist[ptr]); /* get it into memory
  98634. we can write */
  98635. vorbis_staticbook_pack(testlist[ptr],&write);
  98636. fprintf(stderr,"Codebook size %ld bytes... ",oggpack_bytes(&write));
  98637. for(i=0;i<TESTSIZE;i+=c.dim){
  98638. int best=_best(&c,qv+i,1);
  98639. vorbis_book_encodev(&c,best,qv+i,&write);
  98640. }
  98641. vorbis_book_clear(&c);
  98642. fprintf(stderr,"OK.\n");
  98643. fprintf(stderr,"\tunpacking/decoding %ld... ",ptr);
  98644. oggpack_readinit(&read,oggpack_get_buffer(&write),oggpack_bytes(&write));
  98645. if(vorbis_staticbook_unpack(&read,&s)){
  98646. fprintf(stderr,"Error unpacking codebook.\n");
  98647. exit(1);
  98648. }
  98649. if(vorbis_book_init_decode(&c,&s)){
  98650. fprintf(stderr,"Error initializing codebook.\n");
  98651. exit(1);
  98652. }
  98653. for(i=0;i<TESTSIZE;i+=c.dim)
  98654. if(vorbis_book_decodev_set(&c,iv+i,&read,c.dim)==-1){
  98655. fprintf(stderr,"Error reading codebook test data (EOP).\n");
  98656. exit(1);
  98657. }
  98658. for(i=0;i<TESTSIZE;i++)
  98659. if(fabs(qv[i]-iv[i])>.000001){
  98660. fprintf(stderr,"read (%g) != written (%g) at position (%ld)\n",
  98661. iv[i],qv[i],i);
  98662. exit(1);
  98663. }
  98664. fprintf(stderr,"OK\n");
  98665. ptr++;
  98666. }
  98667. exit(0);
  98668. }
  98669. #endif
  98670. #endif
  98671. /*** End of inlined file: codebook.c ***/
  98672. /*** Start of inlined file: envelope.c ***/
  98673. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98674. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98675. // tasks..
  98676. #if JUCE_MSVC
  98677. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98678. #endif
  98679. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98680. #if JUCE_USE_OGGVORBIS
  98681. #include <stdlib.h>
  98682. #include <string.h>
  98683. #include <stdio.h>
  98684. #include <math.h>
  98685. void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi){
  98686. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98687. vorbis_info_psy_global *gi=&ci->psy_g_param;
  98688. int ch=vi->channels;
  98689. int i,j;
  98690. int n=e->winlength=128;
  98691. e->searchstep=64; /* not random */
  98692. e->minenergy=gi->preecho_minenergy;
  98693. e->ch=ch;
  98694. e->storage=128;
  98695. e->cursor=ci->blocksizes[1]/2;
  98696. e->mdct_win=(float*)_ogg_calloc(n,sizeof(*e->mdct_win));
  98697. mdct_init(&e->mdct,n);
  98698. for(i=0;i<n;i++){
  98699. e->mdct_win[i]=sin(i/(n-1.)*M_PI);
  98700. e->mdct_win[i]*=e->mdct_win[i];
  98701. }
  98702. e->band[0].begin=2; e->band[0].end=4;
  98703. e->band[1].begin=4; e->band[1].end=5;
  98704. e->band[2].begin=6; e->band[2].end=6;
  98705. e->band[3].begin=9; e->band[3].end=8;
  98706. e->band[4].begin=13; e->band[4].end=8;
  98707. e->band[5].begin=17; e->band[5].end=8;
  98708. e->band[6].begin=22; e->band[6].end=8;
  98709. for(j=0;j<VE_BANDS;j++){
  98710. n=e->band[j].end;
  98711. e->band[j].window=(float*)_ogg_malloc(n*sizeof(*e->band[0].window));
  98712. for(i=0;i<n;i++){
  98713. e->band[j].window[i]=sin((i+.5)/n*M_PI);
  98714. e->band[j].total+=e->band[j].window[i];
  98715. }
  98716. e->band[j].total=1./e->band[j].total;
  98717. }
  98718. e->filter=(envelope_filter_state*)_ogg_calloc(VE_BANDS*ch,sizeof(*e->filter));
  98719. e->mark=(int*)_ogg_calloc(e->storage,sizeof(*e->mark));
  98720. }
  98721. void _ve_envelope_clear(envelope_lookup *e){
  98722. int i;
  98723. mdct_clear(&e->mdct);
  98724. for(i=0;i<VE_BANDS;i++)
  98725. _ogg_free(e->band[i].window);
  98726. _ogg_free(e->mdct_win);
  98727. _ogg_free(e->filter);
  98728. _ogg_free(e->mark);
  98729. memset(e,0,sizeof(*e));
  98730. }
  98731. static int _ve_amp(envelope_lookup *ve,
  98732. vorbis_info_psy_global *gi,
  98733. float *data,
  98734. envelope_band *bands,
  98735. envelope_filter_state *filters,
  98736. long pos){
  98737. long n=ve->winlength;
  98738. int ret=0;
  98739. long i,j;
  98740. float decay;
  98741. float minV=ve->minenergy;
  98742. float *vec=(float*) alloca(n*sizeof(*vec));
  98743. int stretch=max(VE_MINSTRETCH,ve->stretch/2);
  98744. float penalty=gi->stretch_penalty-(ve->stretch/2-VE_MINSTRETCH);
  98745. if(penalty<0.f)penalty=0.f;
  98746. if(penalty>gi->stretch_penalty)penalty=gi->stretch_penalty;
  98747. for(i=0;i<n;i++)
  98748. vec[i]=data[i]*ve->mdct_win[i];
  98749. mdct_forward(&ve->mdct,vec,vec);
  98750. {
  98751. float temp=vec[0]*vec[0]+.7*vec[1]*vec[1]+.2*vec[2]*vec[2];
  98752. int ptr=filters->nearptr;
  98753. if(ptr==0){
  98754. decay=filters->nearDC_acc=filters->nearDC_partialacc+temp;
  98755. filters->nearDC_partialacc=temp;
  98756. }else{
  98757. decay=filters->nearDC_acc+=temp;
  98758. filters->nearDC_partialacc+=temp;
  98759. }
  98760. filters->nearDC_acc-=filters->nearDC[ptr];
  98761. filters->nearDC[ptr]=temp;
  98762. decay*=(1./(VE_NEARDC+1));
  98763. filters->nearptr++;
  98764. if(filters->nearptr>=VE_NEARDC)filters->nearptr=0;
  98765. decay=todB(&decay)*.5-15.f;
  98766. }
  98767. for(i=0;i<n/2;i+=2){
  98768. float val=vec[i]*vec[i]+vec[i+1]*vec[i+1];
  98769. val=todB(&val)*.5f;
  98770. if(val<decay)val=decay;
  98771. if(val<minV)val=minV;
  98772. vec[i>>1]=val;
  98773. decay-=8.;
  98774. }
  98775. for(j=0;j<VE_BANDS;j++){
  98776. float acc=0.;
  98777. float valmax,valmin;
  98778. for(i=0;i<bands[j].end;i++)
  98779. acc+=vec[i+bands[j].begin]*bands[j].window[i];
  98780. acc*=bands[j].total;
  98781. {
  98782. int p,thisx=filters[j].ampptr;
  98783. float postmax,postmin,premax=-99999.f,premin=99999.f;
  98784. p=thisx;
  98785. p--;
  98786. if(p<0)p+=VE_AMP;
  98787. postmax=max(acc,filters[j].ampbuf[p]);
  98788. postmin=min(acc,filters[j].ampbuf[p]);
  98789. for(i=0;i<stretch;i++){
  98790. p--;
  98791. if(p<0)p+=VE_AMP;
  98792. premax=max(premax,filters[j].ampbuf[p]);
  98793. premin=min(premin,filters[j].ampbuf[p]);
  98794. }
  98795. valmin=postmin-premin;
  98796. valmax=postmax-premax;
  98797. filters[j].ampbuf[thisx]=acc;
  98798. filters[j].ampptr++;
  98799. if(filters[j].ampptr>=VE_AMP)filters[j].ampptr=0;
  98800. }
  98801. if(valmax>gi->preecho_thresh[j]+penalty){
  98802. ret|=1;
  98803. ret|=4;
  98804. }
  98805. if(valmin<gi->postecho_thresh[j]-penalty)ret|=2;
  98806. }
  98807. return(ret);
  98808. }
  98809. #if 0
  98810. static int seq=0;
  98811. static ogg_int64_t totalshift=-1024;
  98812. #endif
  98813. long _ve_envelope_search(vorbis_dsp_state *v){
  98814. vorbis_info *vi=v->vi;
  98815. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  98816. vorbis_info_psy_global *gi=&ci->psy_g_param;
  98817. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  98818. long i,j;
  98819. int first=ve->current/ve->searchstep;
  98820. int last=v->pcm_current/ve->searchstep-VE_WIN;
  98821. if(first<0)first=0;
  98822. if(last+VE_WIN+VE_POST>ve->storage){
  98823. ve->storage=last+VE_WIN+VE_POST; /* be sure */
  98824. ve->mark=(int*)_ogg_realloc(ve->mark,ve->storage*sizeof(*ve->mark));
  98825. }
  98826. for(j=first;j<last;j++){
  98827. int ret=0;
  98828. ve->stretch++;
  98829. if(ve->stretch>VE_MAXSTRETCH*2)
  98830. ve->stretch=VE_MAXSTRETCH*2;
  98831. for(i=0;i<ve->ch;i++){
  98832. float *pcm=v->pcm[i]+ve->searchstep*(j);
  98833. ret|=_ve_amp(ve,gi,pcm,ve->band,ve->filter+i*VE_BANDS,j);
  98834. }
  98835. ve->mark[j+VE_POST]=0;
  98836. if(ret&1){
  98837. ve->mark[j]=1;
  98838. ve->mark[j+1]=1;
  98839. }
  98840. if(ret&2){
  98841. ve->mark[j]=1;
  98842. if(j>0)ve->mark[j-1]=1;
  98843. }
  98844. if(ret&4)ve->stretch=-1;
  98845. }
  98846. ve->current=last*ve->searchstep;
  98847. {
  98848. long centerW=v->centerW;
  98849. long testW=
  98850. centerW+
  98851. ci->blocksizes[v->W]/4+
  98852. ci->blocksizes[1]/2+
  98853. ci->blocksizes[0]/4;
  98854. j=ve->cursor;
  98855. while(j<ve->current-(ve->searchstep)){/* account for postecho
  98856. working back one window */
  98857. if(j>=testW)return(1);
  98858. ve->cursor=j;
  98859. if(ve->mark[j/ve->searchstep]){
  98860. if(j>centerW){
  98861. #if 0
  98862. if(j>ve->curmark){
  98863. float *marker=alloca(v->pcm_current*sizeof(*marker));
  98864. int l,m;
  98865. memset(marker,0,sizeof(*marker)*v->pcm_current);
  98866. fprintf(stderr,"mark! seq=%d, cursor:%fs time:%fs\n",
  98867. seq,
  98868. (totalshift+ve->cursor)/44100.,
  98869. (totalshift+j)/44100.);
  98870. _analysis_output_always("pcmL",seq,v->pcm[0],v->pcm_current,0,0,totalshift);
  98871. _analysis_output_always("pcmR",seq,v->pcm[1],v->pcm_current,0,0,totalshift);
  98872. _analysis_output_always("markL",seq,v->pcm[0],j,0,0,totalshift);
  98873. _analysis_output_always("markR",seq,v->pcm[1],j,0,0,totalshift);
  98874. for(m=0;m<VE_BANDS;m++){
  98875. char buf[80];
  98876. sprintf(buf,"delL%d",m);
  98877. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m].markers[l]*.1;
  98878. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  98879. }
  98880. for(m=0;m<VE_BANDS;m++){
  98881. char buf[80];
  98882. sprintf(buf,"delR%d",m);
  98883. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m+VE_BANDS].markers[l]*.1;
  98884. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  98885. }
  98886. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->mark[l]*.4;
  98887. _analysis_output_always("mark",seq,marker,v->pcm_current,0,0,totalshift);
  98888. seq++;
  98889. }
  98890. #endif
  98891. ve->curmark=j;
  98892. if(j>=testW)return(1);
  98893. return(0);
  98894. }
  98895. }
  98896. j+=ve->searchstep;
  98897. }
  98898. }
  98899. return(-1);
  98900. }
  98901. int _ve_envelope_mark(vorbis_dsp_state *v){
  98902. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  98903. vorbis_info *vi=v->vi;
  98904. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98905. long centerW=v->centerW;
  98906. long beginW=centerW-ci->blocksizes[v->W]/4;
  98907. long endW=centerW+ci->blocksizes[v->W]/4;
  98908. if(v->W){
  98909. beginW-=ci->blocksizes[v->lW]/4;
  98910. endW+=ci->blocksizes[v->nW]/4;
  98911. }else{
  98912. beginW-=ci->blocksizes[0]/4;
  98913. endW+=ci->blocksizes[0]/4;
  98914. }
  98915. if(ve->curmark>=beginW && ve->curmark<endW)return(1);
  98916. {
  98917. long first=beginW/ve->searchstep;
  98918. long last=endW/ve->searchstep;
  98919. long i;
  98920. for(i=first;i<last;i++)
  98921. if(ve->mark[i])return(1);
  98922. }
  98923. return(0);
  98924. }
  98925. void _ve_envelope_shift(envelope_lookup *e,long shift){
  98926. int smallsize=e->current/e->searchstep+VE_POST; /* adjust for placing marks
  98927. ahead of ve->current */
  98928. int smallshift=shift/e->searchstep;
  98929. memmove(e->mark,e->mark+smallshift,(smallsize-smallshift)*sizeof(*e->mark));
  98930. #if 0
  98931. for(i=0;i<VE_BANDS*e->ch;i++)
  98932. memmove(e->filter[i].markers,
  98933. e->filter[i].markers+smallshift,
  98934. (1024-smallshift)*sizeof(*(*e->filter).markers));
  98935. totalshift+=shift;
  98936. #endif
  98937. e->current-=shift;
  98938. if(e->curmark>=0)
  98939. e->curmark-=shift;
  98940. e->cursor-=shift;
  98941. }
  98942. #endif
  98943. /*** End of inlined file: envelope.c ***/
  98944. /*** Start of inlined file: floor0.c ***/
  98945. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98946. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98947. // tasks..
  98948. #if JUCE_MSVC
  98949. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98950. #endif
  98951. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98952. #if JUCE_USE_OGGVORBIS
  98953. #include <stdlib.h>
  98954. #include <string.h>
  98955. #include <math.h>
  98956. /*** Start of inlined file: lsp.h ***/
  98957. #ifndef _V_LSP_H_
  98958. #define _V_LSP_H_
  98959. extern int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m);
  98960. extern void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,
  98961. float *lsp,int m,
  98962. float amp,float ampoffset);
  98963. #endif
  98964. /*** End of inlined file: lsp.h ***/
  98965. #include <stdio.h>
  98966. typedef struct {
  98967. int ln;
  98968. int m;
  98969. int **linearmap;
  98970. int n[2];
  98971. vorbis_info_floor0 *vi;
  98972. long bits;
  98973. long frames;
  98974. } vorbis_look_floor0;
  98975. static void floor0_free_info(vorbis_info_floor *i){
  98976. vorbis_info_floor0 *info=(vorbis_info_floor0 *)i;
  98977. if(info){
  98978. memset(info,0,sizeof(*info));
  98979. _ogg_free(info);
  98980. }
  98981. }
  98982. static void floor0_free_look(vorbis_look_floor *i){
  98983. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  98984. if(look){
  98985. if(look->linearmap){
  98986. if(look->linearmap[0])_ogg_free(look->linearmap[0]);
  98987. if(look->linearmap[1])_ogg_free(look->linearmap[1]);
  98988. _ogg_free(look->linearmap);
  98989. }
  98990. memset(look,0,sizeof(*look));
  98991. _ogg_free(look);
  98992. }
  98993. }
  98994. static vorbis_info_floor *floor0_unpack (vorbis_info *vi,oggpack_buffer *opb){
  98995. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98996. int j;
  98997. vorbis_info_floor0 *info=(vorbis_info_floor0*)_ogg_malloc(sizeof(*info));
  98998. info->order=oggpack_read(opb,8);
  98999. info->rate=oggpack_read(opb,16);
  99000. info->barkmap=oggpack_read(opb,16);
  99001. info->ampbits=oggpack_read(opb,6);
  99002. info->ampdB=oggpack_read(opb,8);
  99003. info->numbooks=oggpack_read(opb,4)+1;
  99004. if(info->order<1)goto err_out;
  99005. if(info->rate<1)goto err_out;
  99006. if(info->barkmap<1)goto err_out;
  99007. if(info->numbooks<1)goto err_out;
  99008. for(j=0;j<info->numbooks;j++){
  99009. info->books[j]=oggpack_read(opb,8);
  99010. if(info->books[j]<0 || info->books[j]>=ci->books)goto err_out;
  99011. }
  99012. return(info);
  99013. err_out:
  99014. floor0_free_info(info);
  99015. return(NULL);
  99016. }
  99017. static void floor0_map_lazy_init(vorbis_block *vb,
  99018. vorbis_info_floor *infoX,
  99019. vorbis_look_floor0 *look){
  99020. if(!look->linearmap[vb->W]){
  99021. vorbis_dsp_state *vd=vb->vd;
  99022. vorbis_info *vi=vd->vi;
  99023. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99024. vorbis_info_floor0 *info=(vorbis_info_floor0 *)infoX;
  99025. int W=vb->W;
  99026. int n=ci->blocksizes[W]/2,j;
  99027. float scale=look->ln/toBARK(info->rate/2.f);
  99028. look->linearmap[W]=(int*)_ogg_malloc((n+1)*sizeof(**look->linearmap));
  99029. for(j=0;j<n;j++){
  99030. int val=floor( toBARK((info->rate/2.f)/n*j)
  99031. *scale); /* bark numbers represent band edges */
  99032. if(val>=look->ln)val=look->ln-1; /* guard against the approximation */
  99033. look->linearmap[W][j]=val;
  99034. }
  99035. look->linearmap[W][j]=-1;
  99036. look->n[W]=n;
  99037. }
  99038. }
  99039. static vorbis_look_floor *floor0_look(vorbis_dsp_state *vd,
  99040. vorbis_info_floor *i){
  99041. vorbis_info_floor0 *info=(vorbis_info_floor0*)i;
  99042. vorbis_look_floor0 *look=(vorbis_look_floor0*)_ogg_calloc(1,sizeof(*look));
  99043. look->m=info->order;
  99044. look->ln=info->barkmap;
  99045. look->vi=info;
  99046. look->linearmap=(int**)_ogg_calloc(2,sizeof(*look->linearmap));
  99047. return look;
  99048. }
  99049. static void *floor0_inverse1(vorbis_block *vb,vorbis_look_floor *i){
  99050. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99051. vorbis_info_floor0 *info=look->vi;
  99052. int j,k;
  99053. int ampraw=oggpack_read(&vb->opb,info->ampbits);
  99054. if(ampraw>0){ /* also handles the -1 out of data case */
  99055. long maxval=(1<<info->ampbits)-1;
  99056. float amp=(float)ampraw/maxval*info->ampdB;
  99057. int booknum=oggpack_read(&vb->opb,_ilog(info->numbooks));
  99058. if(booknum!=-1 && booknum<info->numbooks){ /* be paranoid */
  99059. codec_setup_info *ci=(codec_setup_info *)vb->vd->vi->codec_setup;
  99060. codebook *b=ci->fullbooks+info->books[booknum];
  99061. float last=0.f;
  99062. float *lsp=(float*)_vorbis_block_alloc(vb,sizeof(*lsp)*(look->m+b->dim+1));
  99063. for(j=0;j<look->m;j+=b->dim)
  99064. if(vorbis_book_decodev_set(b,lsp+j,&vb->opb,b->dim)==-1)goto eop;
  99065. for(j=0;j<look->m;){
  99066. for(k=0;k<b->dim;k++,j++)lsp[j]+=last;
  99067. last=lsp[j-1];
  99068. }
  99069. lsp[look->m]=amp;
  99070. return(lsp);
  99071. }
  99072. }
  99073. eop:
  99074. return(NULL);
  99075. }
  99076. static int floor0_inverse2(vorbis_block *vb,vorbis_look_floor *i,
  99077. void *memo,float *out){
  99078. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99079. vorbis_info_floor0 *info=look->vi;
  99080. floor0_map_lazy_init(vb,info,look);
  99081. if(memo){
  99082. float *lsp=(float *)memo;
  99083. float amp=lsp[look->m];
  99084. vorbis_lsp_to_curve(out,
  99085. look->linearmap[vb->W],
  99086. look->n[vb->W],
  99087. look->ln,
  99088. lsp,look->m,amp,(float)info->ampdB);
  99089. return(1);
  99090. }
  99091. memset(out,0,sizeof(*out)*look->n[vb->W]);
  99092. return(0);
  99093. }
  99094. vorbis_func_floor floor0_exportbundle={
  99095. NULL,&floor0_unpack,&floor0_look,&floor0_free_info,
  99096. &floor0_free_look,&floor0_inverse1,&floor0_inverse2
  99097. };
  99098. #endif
  99099. /*** End of inlined file: floor0.c ***/
  99100. /*** Start of inlined file: floor1.c ***/
  99101. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99102. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99103. // tasks..
  99104. #if JUCE_MSVC
  99105. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99106. #endif
  99107. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99108. #if JUCE_USE_OGGVORBIS
  99109. #include <stdlib.h>
  99110. #include <string.h>
  99111. #include <math.h>
  99112. #include <stdio.h>
  99113. #define floor1_rangedB 140 /* floor 1 fixed at -140dB to 0dB range */
  99114. typedef struct {
  99115. int sorted_index[VIF_POSIT+2];
  99116. int forward_index[VIF_POSIT+2];
  99117. int reverse_index[VIF_POSIT+2];
  99118. int hineighbor[VIF_POSIT];
  99119. int loneighbor[VIF_POSIT];
  99120. int posts;
  99121. int n;
  99122. int quant_q;
  99123. vorbis_info_floor1 *vi;
  99124. long phrasebits;
  99125. long postbits;
  99126. long frames;
  99127. } vorbis_look_floor1;
  99128. typedef struct lsfit_acc{
  99129. long x0;
  99130. long x1;
  99131. long xa;
  99132. long ya;
  99133. long x2a;
  99134. long y2a;
  99135. long xya;
  99136. long an;
  99137. } lsfit_acc;
  99138. static void floor1_free_info(vorbis_info_floor *i){
  99139. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99140. if(info){
  99141. memset(info,0,sizeof(*info));
  99142. _ogg_free(info);
  99143. }
  99144. }
  99145. static void floor1_free_look(vorbis_look_floor *i){
  99146. vorbis_look_floor1 *look=(vorbis_look_floor1 *)i;
  99147. if(look){
  99148. memset(look,0,sizeof(*look));
  99149. _ogg_free(look);
  99150. }
  99151. }
  99152. static void floor1_pack (vorbis_info_floor *i,oggpack_buffer *opb){
  99153. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99154. int j,k;
  99155. int count=0;
  99156. int rangebits;
  99157. int maxposit=info->postlist[1];
  99158. int maxclass=-1;
  99159. oggpack_write(opb,info->partitions,5); /* only 0 to 31 legal */
  99160. for(j=0;j<info->partitions;j++){
  99161. oggpack_write(opb,info->partitionclass[j],4); /* only 0 to 15 legal */
  99162. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99163. }
  99164. for(j=0;j<maxclass+1;j++){
  99165. oggpack_write(opb,info->class_dim[j]-1,3); /* 1 to 8 */
  99166. oggpack_write(opb,info->class_subs[j],2); /* 0 to 3 */
  99167. if(info->class_subs[j])oggpack_write(opb,info->class_book[j],8);
  99168. for(k=0;k<(1<<info->class_subs[j]);k++)
  99169. oggpack_write(opb,info->class_subbook[j][k]+1,8);
  99170. }
  99171. oggpack_write(opb,info->mult-1,2); /* only 1,2,3,4 legal now */
  99172. oggpack_write(opb,ilog2(maxposit),4);
  99173. rangebits=ilog2(maxposit);
  99174. for(j=0,k=0;j<info->partitions;j++){
  99175. count+=info->class_dim[info->partitionclass[j]];
  99176. for(;k<count;k++)
  99177. oggpack_write(opb,info->postlist[k+2],rangebits);
  99178. }
  99179. }
  99180. static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){
  99181. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99182. int j,k,count=0,maxclass=-1,rangebits;
  99183. vorbis_info_floor1 *info=(vorbis_info_floor1*)_ogg_calloc(1,sizeof(*info));
  99184. info->partitions=oggpack_read(opb,5); /* only 0 to 31 legal */
  99185. for(j=0;j<info->partitions;j++){
  99186. info->partitionclass[j]=oggpack_read(opb,4); /* only 0 to 15 legal */
  99187. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99188. }
  99189. for(j=0;j<maxclass+1;j++){
  99190. info->class_dim[j]=oggpack_read(opb,3)+1; /* 1 to 8 */
  99191. info->class_subs[j]=oggpack_read(opb,2); /* 0,1,2,3 bits */
  99192. if(info->class_subs[j]<0)
  99193. goto err_out;
  99194. if(info->class_subs[j])info->class_book[j]=oggpack_read(opb,8);
  99195. if(info->class_book[j]<0 || info->class_book[j]>=ci->books)
  99196. goto err_out;
  99197. for(k=0;k<(1<<info->class_subs[j]);k++){
  99198. info->class_subbook[j][k]=oggpack_read(opb,8)-1;
  99199. if(info->class_subbook[j][k]<-1 || info->class_subbook[j][k]>=ci->books)
  99200. goto err_out;
  99201. }
  99202. }
  99203. info->mult=oggpack_read(opb,2)+1; /* only 1,2,3,4 legal now */
  99204. rangebits=oggpack_read(opb,4);
  99205. for(j=0,k=0;j<info->partitions;j++){
  99206. count+=info->class_dim[info->partitionclass[j]];
  99207. for(;k<count;k++){
  99208. int t=info->postlist[k+2]=oggpack_read(opb,rangebits);
  99209. if(t<0 || t>=(1<<rangebits))
  99210. goto err_out;
  99211. }
  99212. }
  99213. info->postlist[0]=0;
  99214. info->postlist[1]=1<<rangebits;
  99215. return(info);
  99216. err_out:
  99217. floor1_free_info(info);
  99218. return(NULL);
  99219. }
  99220. static int icomp(const void *a,const void *b){
  99221. return(**(int **)a-**(int **)b);
  99222. }
  99223. static vorbis_look_floor *floor1_look(vorbis_dsp_state *vd,
  99224. vorbis_info_floor *in){
  99225. int *sortpointer[VIF_POSIT+2];
  99226. vorbis_info_floor1 *info=(vorbis_info_floor1*)in;
  99227. vorbis_look_floor1 *look=(vorbis_look_floor1*)_ogg_calloc(1,sizeof(*look));
  99228. int i,j,n=0;
  99229. look->vi=info;
  99230. look->n=info->postlist[1];
  99231. for(i=0;i<info->partitions;i++)n+=info->class_dim[info->partitionclass[i]];
  99232. n+=2;
  99233. look->posts=n;
  99234. for(i=0;i<n;i++)sortpointer[i]=info->postlist+i;
  99235. qsort(sortpointer,n,sizeof(*sortpointer),icomp);
  99236. for(i=0;i<n;i++)look->forward_index[i]=sortpointer[i]-info->postlist;
  99237. for(i=0;i<n;i++)look->reverse_index[look->forward_index[i]]=i;
  99238. for(i=0;i<n;i++)look->sorted_index[i]=info->postlist[look->forward_index[i]];
  99239. switch(info->mult){
  99240. case 1: /* 1024 -> 256 */
  99241. look->quant_q=256;
  99242. break;
  99243. case 2: /* 1024 -> 128 */
  99244. look->quant_q=128;
  99245. break;
  99246. case 3: /* 1024 -> 86 */
  99247. look->quant_q=86;
  99248. break;
  99249. case 4: /* 1024 -> 64 */
  99250. look->quant_q=64;
  99251. break;
  99252. }
  99253. for(i=0;i<n-2;i++){
  99254. int lo=0;
  99255. int hi=1;
  99256. int lx=0;
  99257. int hx=look->n;
  99258. int currentx=info->postlist[i+2];
  99259. for(j=0;j<i+2;j++){
  99260. int x=info->postlist[j];
  99261. if(x>lx && x<currentx){
  99262. lo=j;
  99263. lx=x;
  99264. }
  99265. if(x<hx && x>currentx){
  99266. hi=j;
  99267. hx=x;
  99268. }
  99269. }
  99270. look->loneighbor[i]=lo;
  99271. look->hineighbor[i]=hi;
  99272. }
  99273. return(look);
  99274. }
  99275. static int render_point(int x0,int x1,int y0,int y1,int x){
  99276. y0&=0x7fff; /* mask off flag */
  99277. y1&=0x7fff;
  99278. {
  99279. int dy=y1-y0;
  99280. int adx=x1-x0;
  99281. int ady=abs(dy);
  99282. int err=ady*(x-x0);
  99283. int off=err/adx;
  99284. if(dy<0)return(y0-off);
  99285. return(y0+off);
  99286. }
  99287. }
  99288. static int vorbis_dBquant(const float *x){
  99289. int i= *x*7.3142857f+1023.5f;
  99290. if(i>1023)return(1023);
  99291. if(i<0)return(0);
  99292. return i;
  99293. }
  99294. static float FLOOR1_fromdB_LOOKUP[256]={
  99295. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  99296. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  99297. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  99298. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  99299. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  99300. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  99301. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  99302. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  99303. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  99304. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  99305. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  99306. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  99307. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  99308. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  99309. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  99310. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  99311. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  99312. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  99313. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  99314. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  99315. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  99316. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  99317. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  99318. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  99319. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  99320. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  99321. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  99322. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  99323. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  99324. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  99325. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  99326. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  99327. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  99328. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  99329. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  99330. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  99331. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  99332. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  99333. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  99334. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  99335. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  99336. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  99337. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  99338. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  99339. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  99340. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  99341. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  99342. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  99343. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  99344. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  99345. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  99346. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  99347. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  99348. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  99349. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  99350. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  99351. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  99352. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  99353. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  99354. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  99355. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  99356. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  99357. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  99358. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  99359. };
  99360. static void render_line(int x0,int x1,int y0,int y1,float *d){
  99361. int dy=y1-y0;
  99362. int adx=x1-x0;
  99363. int ady=abs(dy);
  99364. int base=dy/adx;
  99365. int sy=(dy<0?base-1:base+1);
  99366. int x=x0;
  99367. int y=y0;
  99368. int err=0;
  99369. ady-=abs(base*adx);
  99370. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99371. while(++x<x1){
  99372. err=err+ady;
  99373. if(err>=adx){
  99374. err-=adx;
  99375. y+=sy;
  99376. }else{
  99377. y+=base;
  99378. }
  99379. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99380. }
  99381. }
  99382. static void render_line0(int x0,int x1,int y0,int y1,int *d){
  99383. int dy=y1-y0;
  99384. int adx=x1-x0;
  99385. int ady=abs(dy);
  99386. int base=dy/adx;
  99387. int sy=(dy<0?base-1:base+1);
  99388. int x=x0;
  99389. int y=y0;
  99390. int err=0;
  99391. ady-=abs(base*adx);
  99392. d[x]=y;
  99393. while(++x<x1){
  99394. err=err+ady;
  99395. if(err>=adx){
  99396. err-=adx;
  99397. y+=sy;
  99398. }else{
  99399. y+=base;
  99400. }
  99401. d[x]=y;
  99402. }
  99403. }
  99404. static int accumulate_fit(const float *flr,const float *mdct,
  99405. int x0, int x1,lsfit_acc *a,
  99406. int n,vorbis_info_floor1 *info){
  99407. long i;
  99408. 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;
  99409. memset(a,0,sizeof(*a));
  99410. a->x0=x0;
  99411. a->x1=x1;
  99412. if(x1>=n)x1=n-1;
  99413. for(i=x0;i<=x1;i++){
  99414. int quantized=vorbis_dBquant(flr+i);
  99415. if(quantized){
  99416. if(mdct[i]+info->twofitatten>=flr[i]){
  99417. xa += i;
  99418. ya += quantized;
  99419. x2a += i*i;
  99420. y2a += quantized*quantized;
  99421. xya += i*quantized;
  99422. na++;
  99423. }else{
  99424. xb += i;
  99425. yb += quantized;
  99426. x2b += i*i;
  99427. y2b += quantized*quantized;
  99428. xyb += i*quantized;
  99429. nb++;
  99430. }
  99431. }
  99432. }
  99433. xb+=xa;
  99434. yb+=ya;
  99435. x2b+=x2a;
  99436. y2b+=y2a;
  99437. xyb+=xya;
  99438. nb+=na;
  99439. {
  99440. int weight=nb*info->twofitweight/(na+1);
  99441. a->xa=xa*weight+xb;
  99442. a->ya=ya*weight+yb;
  99443. a->x2a=x2a*weight+x2b;
  99444. a->y2a=y2a*weight+y2b;
  99445. a->xya=xya*weight+xyb;
  99446. a->an=na*weight+nb;
  99447. }
  99448. return(na);
  99449. }
  99450. static void fit_line(lsfit_acc *a,int fits,int *y0,int *y1){
  99451. long x=0,y=0,x2=0,y2=0,xy=0,an=0,i;
  99452. long x0=a[0].x0;
  99453. long x1=a[fits-1].x1;
  99454. for(i=0;i<fits;i++){
  99455. x+=a[i].xa;
  99456. y+=a[i].ya;
  99457. x2+=a[i].x2a;
  99458. y2+=a[i].y2a;
  99459. xy+=a[i].xya;
  99460. an+=a[i].an;
  99461. }
  99462. if(*y0>=0){
  99463. x+= x0;
  99464. y+= *y0;
  99465. x2+= x0 * x0;
  99466. y2+= *y0 * *y0;
  99467. xy+= *y0 * x0;
  99468. an++;
  99469. }
  99470. if(*y1>=0){
  99471. x+= x1;
  99472. y+= *y1;
  99473. x2+= x1 * x1;
  99474. y2+= *y1 * *y1;
  99475. xy+= *y1 * x1;
  99476. an++;
  99477. }
  99478. if(an){
  99479. double fx=x;
  99480. double fy=y;
  99481. double fx2=x2;
  99482. double fxy=xy;
  99483. double denom=1./(an*fx2-fx*fx);
  99484. double a=(fy*fx2-fxy*fx)*denom;
  99485. double b=(an*fxy-fx*fy)*denom;
  99486. *y0=rint(a+b*x0);
  99487. *y1=rint(a+b*x1);
  99488. if(*y0>1023)*y0=1023;
  99489. if(*y1>1023)*y1=1023;
  99490. if(*y0<0)*y0=0;
  99491. if(*y1<0)*y1=0;
  99492. }else{
  99493. *y0=0;
  99494. *y1=0;
  99495. }
  99496. }
  99497. static int inspect_error(int x0,int x1,int y0,int y1,const float *mask,
  99498. const float *mdct,
  99499. vorbis_info_floor1 *info){
  99500. int dy=y1-y0;
  99501. int adx=x1-x0;
  99502. int ady=abs(dy);
  99503. int base=dy/adx;
  99504. int sy=(dy<0?base-1:base+1);
  99505. int x=x0;
  99506. int y=y0;
  99507. int err=0;
  99508. int val=vorbis_dBquant(mask+x);
  99509. int mse=0;
  99510. int n=0;
  99511. ady-=abs(base*adx);
  99512. mse=(y-val);
  99513. mse*=mse;
  99514. n++;
  99515. if(mdct[x]+info->twofitatten>=mask[x]){
  99516. if(y+info->maxover<val)return(1);
  99517. if(y-info->maxunder>val)return(1);
  99518. }
  99519. while(++x<x1){
  99520. err=err+ady;
  99521. if(err>=adx){
  99522. err-=adx;
  99523. y+=sy;
  99524. }else{
  99525. y+=base;
  99526. }
  99527. val=vorbis_dBquant(mask+x);
  99528. mse+=((y-val)*(y-val));
  99529. n++;
  99530. if(mdct[x]+info->twofitatten>=mask[x]){
  99531. if(val){
  99532. if(y+info->maxover<val)return(1);
  99533. if(y-info->maxunder>val)return(1);
  99534. }
  99535. }
  99536. }
  99537. if(info->maxover*info->maxover/n>info->maxerr)return(0);
  99538. if(info->maxunder*info->maxunder/n>info->maxerr)return(0);
  99539. if(mse/n>info->maxerr)return(1);
  99540. return(0);
  99541. }
  99542. static int post_Y(int *A,int *B,int pos){
  99543. if(A[pos]<0)
  99544. return B[pos];
  99545. if(B[pos]<0)
  99546. return A[pos];
  99547. return (A[pos]+B[pos])>>1;
  99548. }
  99549. int *floor1_fit(vorbis_block *vb,void *look_,
  99550. const float *logmdct, /* in */
  99551. const float *logmask){
  99552. long i,j;
  99553. vorbis_look_floor1 *look = (vorbis_look_floor1*) look_;
  99554. vorbis_info_floor1 *info=look->vi;
  99555. long n=look->n;
  99556. long posts=look->posts;
  99557. long nonzero=0;
  99558. lsfit_acc fits[VIF_POSIT+1];
  99559. int fit_valueA[VIF_POSIT+2]; /* index by range list position */
  99560. int fit_valueB[VIF_POSIT+2]; /* index by range list position */
  99561. int loneighbor[VIF_POSIT+2]; /* sorted index of range list position (+2) */
  99562. int hineighbor[VIF_POSIT+2];
  99563. int *output=NULL;
  99564. int memo[VIF_POSIT+2];
  99565. for(i=0;i<posts;i++)fit_valueA[i]=-200; /* mark all unused */
  99566. for(i=0;i<posts;i++)fit_valueB[i]=-200; /* mark all unused */
  99567. for(i=0;i<posts;i++)loneighbor[i]=0; /* 0 for the implicit 0 post */
  99568. for(i=0;i<posts;i++)hineighbor[i]=1; /* 1 for the implicit post at n */
  99569. for(i=0;i<posts;i++)memo[i]=-1; /* no neighbor yet */
  99570. if(posts==0){
  99571. nonzero+=accumulate_fit(logmask,logmdct,0,n,fits,n,info);
  99572. }else{
  99573. for(i=0;i<posts-1;i++)
  99574. nonzero+=accumulate_fit(logmask,logmdct,look->sorted_index[i],
  99575. look->sorted_index[i+1],fits+i,
  99576. n,info);
  99577. }
  99578. if(nonzero){
  99579. int y0=-200;
  99580. int y1=-200;
  99581. fit_line(fits,posts-1,&y0,&y1);
  99582. fit_valueA[0]=y0;
  99583. fit_valueB[0]=y0;
  99584. fit_valueB[1]=y1;
  99585. fit_valueA[1]=y1;
  99586. for(i=2;i<posts;i++){
  99587. int sortpos=look->reverse_index[i];
  99588. int ln=loneighbor[sortpos];
  99589. int hn=hineighbor[sortpos];
  99590. if(memo[ln]!=hn){
  99591. int lsortpos=look->reverse_index[ln];
  99592. int hsortpos=look->reverse_index[hn];
  99593. memo[ln]=hn;
  99594. {
  99595. int lx=info->postlist[ln];
  99596. int hx=info->postlist[hn];
  99597. int ly=post_Y(fit_valueA,fit_valueB,ln);
  99598. int hy=post_Y(fit_valueA,fit_valueB,hn);
  99599. if(ly==-1 || hy==-1){
  99600. exit(1);
  99601. }
  99602. if(inspect_error(lx,hx,ly,hy,logmask,logmdct,info)){
  99603. int ly0=-200;
  99604. int ly1=-200;
  99605. int hy0=-200;
  99606. int hy1=-200;
  99607. fit_line(fits+lsortpos,sortpos-lsortpos,&ly0,&ly1);
  99608. fit_line(fits+sortpos,hsortpos-sortpos,&hy0,&hy1);
  99609. fit_valueB[ln]=ly0;
  99610. if(ln==0)fit_valueA[ln]=ly0;
  99611. fit_valueA[i]=ly1;
  99612. fit_valueB[i]=hy0;
  99613. fit_valueA[hn]=hy1;
  99614. if(hn==1)fit_valueB[hn]=hy1;
  99615. if(ly1>=0 || hy0>=0){
  99616. for(j=sortpos-1;j>=0;j--)
  99617. if(hineighbor[j]==hn)
  99618. hineighbor[j]=i;
  99619. else
  99620. break;
  99621. for(j=sortpos+1;j<posts;j++)
  99622. if(loneighbor[j]==ln)
  99623. loneighbor[j]=i;
  99624. else
  99625. break;
  99626. }
  99627. }else{
  99628. fit_valueA[i]=-200;
  99629. fit_valueB[i]=-200;
  99630. }
  99631. }
  99632. }
  99633. }
  99634. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  99635. output[0]=post_Y(fit_valueA,fit_valueB,0);
  99636. output[1]=post_Y(fit_valueA,fit_valueB,1);
  99637. for(i=2;i<posts;i++){
  99638. int ln=look->loneighbor[i-2];
  99639. int hn=look->hineighbor[i-2];
  99640. int x0=info->postlist[ln];
  99641. int x1=info->postlist[hn];
  99642. int y0=output[ln];
  99643. int y1=output[hn];
  99644. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  99645. int vx=post_Y(fit_valueA,fit_valueB,i);
  99646. if(vx>=0 && predicted!=vx){
  99647. output[i]=vx;
  99648. }else{
  99649. output[i]= predicted|0x8000;
  99650. }
  99651. }
  99652. }
  99653. return(output);
  99654. }
  99655. int *floor1_interpolate_fit(vorbis_block *vb,void *look_,
  99656. int *A,int *B,
  99657. int del){
  99658. long i;
  99659. vorbis_look_floor1* look = (vorbis_look_floor1*) look_;
  99660. long posts=look->posts;
  99661. int *output=NULL;
  99662. if(A && B){
  99663. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  99664. for(i=0;i<posts;i++){
  99665. output[i]=((65536-del)*(A[i]&0x7fff)+del*(B[i]&0x7fff)+32768)>>16;
  99666. if(A[i]&0x8000 && B[i]&0x8000)output[i]|=0x8000;
  99667. }
  99668. }
  99669. return(output);
  99670. }
  99671. int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  99672. void*look_,
  99673. int *post,int *ilogmask){
  99674. long i,j;
  99675. vorbis_look_floor1 *look = (vorbis_look_floor1 *) look_;
  99676. vorbis_info_floor1 *info=look->vi;
  99677. long posts=look->posts;
  99678. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  99679. int out[VIF_POSIT+2];
  99680. static_codebook **sbooks=ci->book_param;
  99681. codebook *books=ci->fullbooks;
  99682. static long seq=0;
  99683. if(post){
  99684. for(i=0;i<posts;i++){
  99685. int val=post[i]&0x7fff;
  99686. switch(info->mult){
  99687. case 1: /* 1024 -> 256 */
  99688. val>>=2;
  99689. break;
  99690. case 2: /* 1024 -> 128 */
  99691. val>>=3;
  99692. break;
  99693. case 3: /* 1024 -> 86 */
  99694. val/=12;
  99695. break;
  99696. case 4: /* 1024 -> 64 */
  99697. val>>=4;
  99698. break;
  99699. }
  99700. post[i]=val | (post[i]&0x8000);
  99701. }
  99702. out[0]=post[0];
  99703. out[1]=post[1];
  99704. for(i=2;i<posts;i++){
  99705. int ln=look->loneighbor[i-2];
  99706. int hn=look->hineighbor[i-2];
  99707. int x0=info->postlist[ln];
  99708. int x1=info->postlist[hn];
  99709. int y0=post[ln];
  99710. int y1=post[hn];
  99711. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  99712. if((post[i]&0x8000) || (predicted==post[i])){
  99713. post[i]=predicted|0x8000; /* in case there was roundoff jitter
  99714. in interpolation */
  99715. out[i]=0;
  99716. }else{
  99717. int headroom=(look->quant_q-predicted<predicted?
  99718. look->quant_q-predicted:predicted);
  99719. int val=post[i]-predicted;
  99720. if(val<0)
  99721. if(val<-headroom)
  99722. val=headroom-val-1;
  99723. else
  99724. val=-1-(val<<1);
  99725. else
  99726. if(val>=headroom)
  99727. val= val+headroom;
  99728. else
  99729. val<<=1;
  99730. out[i]=val;
  99731. post[ln]&=0x7fff;
  99732. post[hn]&=0x7fff;
  99733. }
  99734. }
  99735. oggpack_write(opb,1,1);
  99736. look->frames++;
  99737. look->postbits+=ilog(look->quant_q-1)*2;
  99738. oggpack_write(opb,out[0],ilog(look->quant_q-1));
  99739. oggpack_write(opb,out[1],ilog(look->quant_q-1));
  99740. for(i=0,j=2;i<info->partitions;i++){
  99741. int classx=info->partitionclass[i];
  99742. int cdim=info->class_dim[classx];
  99743. int csubbits=info->class_subs[classx];
  99744. int csub=1<<csubbits;
  99745. int bookas[8]={0,0,0,0,0,0,0,0};
  99746. int cval=0;
  99747. int cshift=0;
  99748. int k,l;
  99749. if(csubbits){
  99750. int maxval[8];
  99751. for(k=0;k<csub;k++){
  99752. int booknum=info->class_subbook[classx][k];
  99753. if(booknum<0){
  99754. maxval[k]=1;
  99755. }else{
  99756. maxval[k]=sbooks[info->class_subbook[classx][k]]->entries;
  99757. }
  99758. }
  99759. for(k=0;k<cdim;k++){
  99760. for(l=0;l<csub;l++){
  99761. int val=out[j+k];
  99762. if(val<maxval[l]){
  99763. bookas[k]=l;
  99764. break;
  99765. }
  99766. }
  99767. cval|= bookas[k]<<cshift;
  99768. cshift+=csubbits;
  99769. }
  99770. look->phrasebits+=
  99771. vorbis_book_encode(books+info->class_book[classx],cval,opb);
  99772. #ifdef TRAIN_FLOOR1
  99773. {
  99774. FILE *of;
  99775. char buffer[80];
  99776. sprintf(buffer,"line_%dx%ld_class%d.vqd",
  99777. vb->pcmend/2,posts-2,class);
  99778. of=fopen(buffer,"a");
  99779. fprintf(of,"%d\n",cval);
  99780. fclose(of);
  99781. }
  99782. #endif
  99783. }
  99784. for(k=0;k<cdim;k++){
  99785. int book=info->class_subbook[classx][bookas[k]];
  99786. if(book>=0){
  99787. if(out[j+k]<(books+book)->entries)
  99788. look->postbits+=vorbis_book_encode(books+book,
  99789. out[j+k],opb);
  99790. #ifdef TRAIN_FLOOR1
  99791. {
  99792. FILE *of;
  99793. char buffer[80];
  99794. sprintf(buffer,"line_%dx%ld_%dsub%d.vqd",
  99795. vb->pcmend/2,posts-2,class,bookas[k]);
  99796. of=fopen(buffer,"a");
  99797. fprintf(of,"%d\n",out[j+k]);
  99798. fclose(of);
  99799. }
  99800. #endif
  99801. }
  99802. }
  99803. j+=cdim;
  99804. }
  99805. {
  99806. int hx=0;
  99807. int lx=0;
  99808. int ly=post[0]*info->mult;
  99809. for(j=1;j<look->posts;j++){
  99810. int current=look->forward_index[j];
  99811. int hy=post[current]&0x7fff;
  99812. if(hy==post[current]){
  99813. hy*=info->mult;
  99814. hx=info->postlist[current];
  99815. render_line0(lx,hx,ly,hy,ilogmask);
  99816. lx=hx;
  99817. ly=hy;
  99818. }
  99819. }
  99820. for(j=hx;j<vb->pcmend/2;j++)ilogmask[j]=ly; /* be certain */
  99821. seq++;
  99822. return(1);
  99823. }
  99824. }else{
  99825. oggpack_write(opb,0,1);
  99826. memset(ilogmask,0,vb->pcmend/2*sizeof(*ilogmask));
  99827. seq++;
  99828. return(0);
  99829. }
  99830. }
  99831. static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){
  99832. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  99833. vorbis_info_floor1 *info=look->vi;
  99834. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  99835. int i,j,k;
  99836. codebook *books=ci->fullbooks;
  99837. if(oggpack_read(&vb->opb,1)==1){
  99838. int *fit_value=(int*)_vorbis_block_alloc(vb,(look->posts)*sizeof(*fit_value));
  99839. fit_value[0]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  99840. fit_value[1]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  99841. for(i=0,j=2;i<info->partitions;i++){
  99842. int classx=info->partitionclass[i];
  99843. int cdim=info->class_dim[classx];
  99844. int csubbits=info->class_subs[classx];
  99845. int csub=1<<csubbits;
  99846. int cval=0;
  99847. if(csubbits){
  99848. cval=vorbis_book_decode(books+info->class_book[classx],&vb->opb);
  99849. if(cval==-1)goto eop;
  99850. }
  99851. for(k=0;k<cdim;k++){
  99852. int book=info->class_subbook[classx][cval&(csub-1)];
  99853. cval>>=csubbits;
  99854. if(book>=0){
  99855. if((fit_value[j+k]=vorbis_book_decode(books+book,&vb->opb))==-1)
  99856. goto eop;
  99857. }else{
  99858. fit_value[j+k]=0;
  99859. }
  99860. }
  99861. j+=cdim;
  99862. }
  99863. for(i=2;i<look->posts;i++){
  99864. int predicted=render_point(info->postlist[look->loneighbor[i-2]],
  99865. info->postlist[look->hineighbor[i-2]],
  99866. fit_value[look->loneighbor[i-2]],
  99867. fit_value[look->hineighbor[i-2]],
  99868. info->postlist[i]);
  99869. int hiroom=look->quant_q-predicted;
  99870. int loroom=predicted;
  99871. int room=(hiroom<loroom?hiroom:loroom)<<1;
  99872. int val=fit_value[i];
  99873. if(val){
  99874. if(val>=room){
  99875. if(hiroom>loroom){
  99876. val = val-loroom;
  99877. }else{
  99878. val = -1-(val-hiroom);
  99879. }
  99880. }else{
  99881. if(val&1){
  99882. val= -((val+1)>>1);
  99883. }else{
  99884. val>>=1;
  99885. }
  99886. }
  99887. fit_value[i]=val+predicted;
  99888. fit_value[look->loneighbor[i-2]]&=0x7fff;
  99889. fit_value[look->hineighbor[i-2]]&=0x7fff;
  99890. }else{
  99891. fit_value[i]=predicted|0x8000;
  99892. }
  99893. }
  99894. return(fit_value);
  99895. }
  99896. eop:
  99897. return(NULL);
  99898. }
  99899. static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo,
  99900. float *out){
  99901. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  99902. vorbis_info_floor1 *info=look->vi;
  99903. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  99904. int n=ci->blocksizes[vb->W]/2;
  99905. int j;
  99906. if(memo){
  99907. int *fit_value=(int *)memo;
  99908. int hx=0;
  99909. int lx=0;
  99910. int ly=fit_value[0]*info->mult;
  99911. for(j=1;j<look->posts;j++){
  99912. int current=look->forward_index[j];
  99913. int hy=fit_value[current]&0x7fff;
  99914. if(hy==fit_value[current]){
  99915. hy*=info->mult;
  99916. hx=info->postlist[current];
  99917. render_line(lx,hx,ly,hy,out);
  99918. lx=hx;
  99919. ly=hy;
  99920. }
  99921. }
  99922. for(j=hx;j<n;j++)out[j]*=FLOOR1_fromdB_LOOKUP[ly]; /* be certain */
  99923. return(1);
  99924. }
  99925. memset(out,0,sizeof(*out)*n);
  99926. return(0);
  99927. }
  99928. vorbis_func_floor floor1_exportbundle={
  99929. &floor1_pack,&floor1_unpack,&floor1_look,&floor1_free_info,
  99930. &floor1_free_look,&floor1_inverse1,&floor1_inverse2
  99931. };
  99932. #endif
  99933. /*** End of inlined file: floor1.c ***/
  99934. /*** Start of inlined file: info.c ***/
  99935. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99936. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99937. // tasks..
  99938. #if JUCE_MSVC
  99939. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99940. #endif
  99941. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99942. #if JUCE_USE_OGGVORBIS
  99943. #include <stdlib.h>
  99944. #include <string.h>
  99945. #include <ctype.h>
  99946. static void _v_writestring(oggpack_buffer *o, const char *s, int bytes){
  99947. while(bytes--){
  99948. oggpack_write(o,*s++,8);
  99949. }
  99950. }
  99951. static void _v_readstring(oggpack_buffer *o,char *buf,int bytes){
  99952. while(bytes--){
  99953. *buf++=oggpack_read(o,8);
  99954. }
  99955. }
  99956. void vorbis_comment_init(vorbis_comment *vc){
  99957. memset(vc,0,sizeof(*vc));
  99958. }
  99959. void vorbis_comment_add(vorbis_comment *vc,char *comment){
  99960. vc->user_comments=(char**)_ogg_realloc(vc->user_comments,
  99961. (vc->comments+2)*sizeof(*vc->user_comments));
  99962. vc->comment_lengths=(int*)_ogg_realloc(vc->comment_lengths,
  99963. (vc->comments+2)*sizeof(*vc->comment_lengths));
  99964. vc->comment_lengths[vc->comments]=strlen(comment);
  99965. vc->user_comments[vc->comments]=(char*)_ogg_malloc(vc->comment_lengths[vc->comments]+1);
  99966. strcpy(vc->user_comments[vc->comments], comment);
  99967. vc->comments++;
  99968. vc->user_comments[vc->comments]=NULL;
  99969. }
  99970. void vorbis_comment_add_tag(vorbis_comment *vc, const char *tag, char *contents){
  99971. char *comment=(char*)alloca(strlen(tag)+strlen(contents)+2); /* +2 for = and \0 */
  99972. strcpy(comment, tag);
  99973. strcat(comment, "=");
  99974. strcat(comment, contents);
  99975. vorbis_comment_add(vc, comment);
  99976. }
  99977. static int tagcompare(const char *s1, const char *s2, int n){
  99978. int c=0;
  99979. while(c < n){
  99980. if(toupper(s1[c]) != toupper(s2[c]))
  99981. return !0;
  99982. c++;
  99983. }
  99984. return 0;
  99985. }
  99986. char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){
  99987. long i;
  99988. int found = 0;
  99989. int taglen = strlen(tag)+1; /* +1 for the = we append */
  99990. char *fulltag = (char*)alloca(taglen+ 1);
  99991. strcpy(fulltag, tag);
  99992. strcat(fulltag, "=");
  99993. for(i=0;i<vc->comments;i++){
  99994. if(!tagcompare(vc->user_comments[i], fulltag, taglen)){
  99995. if(count == found)
  99996. return vc->user_comments[i] + taglen;
  99997. else
  99998. found++;
  99999. }
  100000. }
  100001. return NULL; /* didn't find anything */
  100002. }
  100003. int vorbis_comment_query_count(vorbis_comment *vc, char *tag){
  100004. int i,count=0;
  100005. int taglen = strlen(tag)+1; /* +1 for the = we append */
  100006. char *fulltag = (char*)alloca(taglen+1);
  100007. strcpy(fulltag,tag);
  100008. strcat(fulltag, "=");
  100009. for(i=0;i<vc->comments;i++){
  100010. if(!tagcompare(vc->user_comments[i], fulltag, taglen))
  100011. count++;
  100012. }
  100013. return count;
  100014. }
  100015. void vorbis_comment_clear(vorbis_comment *vc){
  100016. if(vc){
  100017. long i;
  100018. for(i=0;i<vc->comments;i++)
  100019. if(vc->user_comments[i])_ogg_free(vc->user_comments[i]);
  100020. if(vc->user_comments)_ogg_free(vc->user_comments);
  100021. if(vc->comment_lengths)_ogg_free(vc->comment_lengths);
  100022. if(vc->vendor)_ogg_free(vc->vendor);
  100023. }
  100024. memset(vc,0,sizeof(*vc));
  100025. }
  100026. int vorbis_info_blocksize(vorbis_info *vi,int zo){
  100027. codec_setup_info *ci = (codec_setup_info*)vi->codec_setup;
  100028. return ci ? ci->blocksizes[zo] : -1;
  100029. }
  100030. void vorbis_info_init(vorbis_info *vi){
  100031. memset(vi,0,sizeof(*vi));
  100032. vi->codec_setup=_ogg_calloc(1,sizeof(codec_setup_info));
  100033. }
  100034. void vorbis_info_clear(vorbis_info *vi){
  100035. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100036. int i;
  100037. if(ci){
  100038. for(i=0;i<ci->modes;i++)
  100039. if(ci->mode_param[i])_ogg_free(ci->mode_param[i]);
  100040. for(i=0;i<ci->maps;i++) /* unpack does the range checking */
  100041. _mapping_P[ci->map_type[i]]->free_info(ci->map_param[i]);
  100042. for(i=0;i<ci->floors;i++) /* unpack does the range checking */
  100043. _floor_P[ci->floor_type[i]]->free_info(ci->floor_param[i]);
  100044. for(i=0;i<ci->residues;i++) /* unpack does the range checking */
  100045. _residue_P[ci->residue_type[i]]->free_info(ci->residue_param[i]);
  100046. for(i=0;i<ci->books;i++){
  100047. if(ci->book_param[i]){
  100048. vorbis_staticbook_destroy(ci->book_param[i]);
  100049. }
  100050. if(ci->fullbooks)
  100051. vorbis_book_clear(ci->fullbooks+i);
  100052. }
  100053. if(ci->fullbooks)
  100054. _ogg_free(ci->fullbooks);
  100055. for(i=0;i<ci->psys;i++)
  100056. _vi_psy_free(ci->psy_param[i]);
  100057. _ogg_free(ci);
  100058. }
  100059. memset(vi,0,sizeof(*vi));
  100060. }
  100061. static int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){
  100062. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100063. if(!ci)return(OV_EFAULT);
  100064. vi->version=oggpack_read(opb,32);
  100065. if(vi->version!=0)return(OV_EVERSION);
  100066. vi->channels=oggpack_read(opb,8);
  100067. vi->rate=oggpack_read(opb,32);
  100068. vi->bitrate_upper=oggpack_read(opb,32);
  100069. vi->bitrate_nominal=oggpack_read(opb,32);
  100070. vi->bitrate_lower=oggpack_read(opb,32);
  100071. ci->blocksizes[0]=1<<oggpack_read(opb,4);
  100072. ci->blocksizes[1]=1<<oggpack_read(opb,4);
  100073. if(vi->rate<1)goto err_out;
  100074. if(vi->channels<1)goto err_out;
  100075. if(ci->blocksizes[0]<8)goto err_out;
  100076. if(ci->blocksizes[1]<ci->blocksizes[0])goto err_out;
  100077. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100078. return(0);
  100079. err_out:
  100080. vorbis_info_clear(vi);
  100081. return(OV_EBADHEADER);
  100082. }
  100083. static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){
  100084. int i;
  100085. int vendorlen=oggpack_read(opb,32);
  100086. if(vendorlen<0)goto err_out;
  100087. vc->vendor=(char*)_ogg_calloc(vendorlen+1,1);
  100088. _v_readstring(opb,vc->vendor,vendorlen);
  100089. vc->comments=oggpack_read(opb,32);
  100090. if(vc->comments<0)goto err_out;
  100091. vc->user_comments=(char**)_ogg_calloc(vc->comments+1,sizeof(*vc->user_comments));
  100092. vc->comment_lengths=(int*)_ogg_calloc(vc->comments+1, sizeof(*vc->comment_lengths));
  100093. for(i=0;i<vc->comments;i++){
  100094. int len=oggpack_read(opb,32);
  100095. if(len<0)goto err_out;
  100096. vc->comment_lengths[i]=len;
  100097. vc->user_comments[i]=(char*)_ogg_calloc(len+1,1);
  100098. _v_readstring(opb,vc->user_comments[i],len);
  100099. }
  100100. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100101. return(0);
  100102. err_out:
  100103. vorbis_comment_clear(vc);
  100104. return(OV_EBADHEADER);
  100105. }
  100106. static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){
  100107. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100108. int i;
  100109. if(!ci)return(OV_EFAULT);
  100110. ci->books=oggpack_read(opb,8)+1;
  100111. for(i=0;i<ci->books;i++){
  100112. ci->book_param[i]=(static_codebook*)_ogg_calloc(1,sizeof(*ci->book_param[i]));
  100113. if(vorbis_staticbook_unpack(opb,ci->book_param[i]))goto err_out;
  100114. }
  100115. {
  100116. int times=oggpack_read(opb,6)+1;
  100117. for(i=0;i<times;i++){
  100118. int test=oggpack_read(opb,16);
  100119. if(test<0 || test>=VI_TIMEB)goto err_out;
  100120. }
  100121. }
  100122. ci->floors=oggpack_read(opb,6)+1;
  100123. for(i=0;i<ci->floors;i++){
  100124. ci->floor_type[i]=oggpack_read(opb,16);
  100125. if(ci->floor_type[i]<0 || ci->floor_type[i]>=VI_FLOORB)goto err_out;
  100126. ci->floor_param[i]=_floor_P[ci->floor_type[i]]->unpack(vi,opb);
  100127. if(!ci->floor_param[i])goto err_out;
  100128. }
  100129. ci->residues=oggpack_read(opb,6)+1;
  100130. for(i=0;i<ci->residues;i++){
  100131. ci->residue_type[i]=oggpack_read(opb,16);
  100132. if(ci->residue_type[i]<0 || ci->residue_type[i]>=VI_RESB)goto err_out;
  100133. ci->residue_param[i]=_residue_P[ci->residue_type[i]]->unpack(vi,opb);
  100134. if(!ci->residue_param[i])goto err_out;
  100135. }
  100136. ci->maps=oggpack_read(opb,6)+1;
  100137. for(i=0;i<ci->maps;i++){
  100138. ci->map_type[i]=oggpack_read(opb,16);
  100139. if(ci->map_type[i]<0 || ci->map_type[i]>=VI_MAPB)goto err_out;
  100140. ci->map_param[i]=_mapping_P[ci->map_type[i]]->unpack(vi,opb);
  100141. if(!ci->map_param[i])goto err_out;
  100142. }
  100143. ci->modes=oggpack_read(opb,6)+1;
  100144. for(i=0;i<ci->modes;i++){
  100145. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*ci->mode_param[i]));
  100146. ci->mode_param[i]->blockflag=oggpack_read(opb,1);
  100147. ci->mode_param[i]->windowtype=oggpack_read(opb,16);
  100148. ci->mode_param[i]->transformtype=oggpack_read(opb,16);
  100149. ci->mode_param[i]->mapping=oggpack_read(opb,8);
  100150. if(ci->mode_param[i]->windowtype>=VI_WINDOWB)goto err_out;
  100151. if(ci->mode_param[i]->transformtype>=VI_WINDOWB)goto err_out;
  100152. if(ci->mode_param[i]->mapping>=ci->maps)goto err_out;
  100153. }
  100154. if(oggpack_read(opb,1)!=1)goto err_out; /* top level EOP check */
  100155. return(0);
  100156. err_out:
  100157. vorbis_info_clear(vi);
  100158. return(OV_EBADHEADER);
  100159. }
  100160. int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op){
  100161. oggpack_buffer opb;
  100162. if(op){
  100163. oggpack_readinit(&opb,op->packet,op->bytes);
  100164. {
  100165. char buffer[6];
  100166. int packtype=oggpack_read(&opb,8);
  100167. memset(buffer,0,6);
  100168. _v_readstring(&opb,buffer,6);
  100169. if(memcmp(buffer,"vorbis",6)){
  100170. return(OV_ENOTVORBIS);
  100171. }
  100172. switch(packtype){
  100173. case 0x01: /* least significant *bit* is read first */
  100174. if(!op->b_o_s){
  100175. return(OV_EBADHEADER);
  100176. }
  100177. if(vi->rate!=0){
  100178. return(OV_EBADHEADER);
  100179. }
  100180. return(_vorbis_unpack_info(vi,&opb));
  100181. case 0x03: /* least significant *bit* is read first */
  100182. if(vi->rate==0){
  100183. return(OV_EBADHEADER);
  100184. }
  100185. return(_vorbis_unpack_comment(vc,&opb));
  100186. case 0x05: /* least significant *bit* is read first */
  100187. if(vi->rate==0 || vc->vendor==NULL){
  100188. return(OV_EBADHEADER);
  100189. }
  100190. return(_vorbis_unpack_books(vi,&opb));
  100191. default:
  100192. return(OV_EBADHEADER);
  100193. break;
  100194. }
  100195. }
  100196. }
  100197. return(OV_EBADHEADER);
  100198. }
  100199. static int _vorbis_pack_info(oggpack_buffer *opb,vorbis_info *vi){
  100200. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100201. if(!ci)return(OV_EFAULT);
  100202. oggpack_write(opb,0x01,8);
  100203. _v_writestring(opb,"vorbis", 6);
  100204. oggpack_write(opb,0x00,32);
  100205. oggpack_write(opb,vi->channels,8);
  100206. oggpack_write(opb,vi->rate,32);
  100207. oggpack_write(opb,vi->bitrate_upper,32);
  100208. oggpack_write(opb,vi->bitrate_nominal,32);
  100209. oggpack_write(opb,vi->bitrate_lower,32);
  100210. oggpack_write(opb,ilog2(ci->blocksizes[0]),4);
  100211. oggpack_write(opb,ilog2(ci->blocksizes[1]),4);
  100212. oggpack_write(opb,1,1);
  100213. return(0);
  100214. }
  100215. static int _vorbis_pack_comment(oggpack_buffer *opb,vorbis_comment *vc){
  100216. char temp[]="Xiph.Org libVorbis I 20050304";
  100217. int bytes = strlen(temp);
  100218. oggpack_write(opb,0x03,8);
  100219. _v_writestring(opb,"vorbis", 6);
  100220. oggpack_write(opb,bytes,32);
  100221. _v_writestring(opb,temp, bytes);
  100222. oggpack_write(opb,vc->comments,32);
  100223. if(vc->comments){
  100224. int i;
  100225. for(i=0;i<vc->comments;i++){
  100226. if(vc->user_comments[i]){
  100227. oggpack_write(opb,vc->comment_lengths[i],32);
  100228. _v_writestring(opb,vc->user_comments[i], vc->comment_lengths[i]);
  100229. }else{
  100230. oggpack_write(opb,0,32);
  100231. }
  100232. }
  100233. }
  100234. oggpack_write(opb,1,1);
  100235. return(0);
  100236. }
  100237. static int _vorbis_pack_books(oggpack_buffer *opb,vorbis_info *vi){
  100238. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100239. int i;
  100240. if(!ci)return(OV_EFAULT);
  100241. oggpack_write(opb,0x05,8);
  100242. _v_writestring(opb,"vorbis", 6);
  100243. oggpack_write(opb,ci->books-1,8);
  100244. for(i=0;i<ci->books;i++)
  100245. if(vorbis_staticbook_pack(ci->book_param[i],opb))goto err_out;
  100246. oggpack_write(opb,0,6);
  100247. oggpack_write(opb,0,16);
  100248. oggpack_write(opb,ci->floors-1,6);
  100249. for(i=0;i<ci->floors;i++){
  100250. oggpack_write(opb,ci->floor_type[i],16);
  100251. if(_floor_P[ci->floor_type[i]]->pack)
  100252. _floor_P[ci->floor_type[i]]->pack(ci->floor_param[i],opb);
  100253. else
  100254. goto err_out;
  100255. }
  100256. oggpack_write(opb,ci->residues-1,6);
  100257. for(i=0;i<ci->residues;i++){
  100258. oggpack_write(opb,ci->residue_type[i],16);
  100259. _residue_P[ci->residue_type[i]]->pack(ci->residue_param[i],opb);
  100260. }
  100261. oggpack_write(opb,ci->maps-1,6);
  100262. for(i=0;i<ci->maps;i++){
  100263. oggpack_write(opb,ci->map_type[i],16);
  100264. _mapping_P[ci->map_type[i]]->pack(vi,ci->map_param[i],opb);
  100265. }
  100266. oggpack_write(opb,ci->modes-1,6);
  100267. for(i=0;i<ci->modes;i++){
  100268. oggpack_write(opb,ci->mode_param[i]->blockflag,1);
  100269. oggpack_write(opb,ci->mode_param[i]->windowtype,16);
  100270. oggpack_write(opb,ci->mode_param[i]->transformtype,16);
  100271. oggpack_write(opb,ci->mode_param[i]->mapping,8);
  100272. }
  100273. oggpack_write(opb,1,1);
  100274. return(0);
  100275. err_out:
  100276. return(-1);
  100277. }
  100278. int vorbis_commentheader_out(vorbis_comment *vc,
  100279. ogg_packet *op){
  100280. oggpack_buffer opb;
  100281. oggpack_writeinit(&opb);
  100282. if(_vorbis_pack_comment(&opb,vc)) return OV_EIMPL;
  100283. op->packet = (unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100284. memcpy(op->packet, opb.buffer, oggpack_bytes(&opb));
  100285. op->bytes=oggpack_bytes(&opb);
  100286. op->b_o_s=0;
  100287. op->e_o_s=0;
  100288. op->granulepos=0;
  100289. op->packetno=1;
  100290. return 0;
  100291. }
  100292. int vorbis_analysis_headerout(vorbis_dsp_state *v,
  100293. vorbis_comment *vc,
  100294. ogg_packet *op,
  100295. ogg_packet *op_comm,
  100296. ogg_packet *op_code){
  100297. int ret=OV_EIMPL;
  100298. vorbis_info *vi=v->vi;
  100299. oggpack_buffer opb;
  100300. private_state *b=(private_state*)v->backend_state;
  100301. if(!b){
  100302. ret=OV_EFAULT;
  100303. goto err_out;
  100304. }
  100305. oggpack_writeinit(&opb);
  100306. if(_vorbis_pack_info(&opb,vi))goto err_out;
  100307. if(b->header)_ogg_free(b->header);
  100308. b->header=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100309. memcpy(b->header,opb.buffer,oggpack_bytes(&opb));
  100310. op->packet=b->header;
  100311. op->bytes=oggpack_bytes(&opb);
  100312. op->b_o_s=1;
  100313. op->e_o_s=0;
  100314. op->granulepos=0;
  100315. op->packetno=0;
  100316. oggpack_reset(&opb);
  100317. if(_vorbis_pack_comment(&opb,vc))goto err_out;
  100318. if(b->header1)_ogg_free(b->header1);
  100319. b->header1=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100320. memcpy(b->header1,opb.buffer,oggpack_bytes(&opb));
  100321. op_comm->packet=b->header1;
  100322. op_comm->bytes=oggpack_bytes(&opb);
  100323. op_comm->b_o_s=0;
  100324. op_comm->e_o_s=0;
  100325. op_comm->granulepos=0;
  100326. op_comm->packetno=1;
  100327. oggpack_reset(&opb);
  100328. if(_vorbis_pack_books(&opb,vi))goto err_out;
  100329. if(b->header2)_ogg_free(b->header2);
  100330. b->header2=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100331. memcpy(b->header2,opb.buffer,oggpack_bytes(&opb));
  100332. op_code->packet=b->header2;
  100333. op_code->bytes=oggpack_bytes(&opb);
  100334. op_code->b_o_s=0;
  100335. op_code->e_o_s=0;
  100336. op_code->granulepos=0;
  100337. op_code->packetno=2;
  100338. oggpack_writeclear(&opb);
  100339. return(0);
  100340. err_out:
  100341. oggpack_writeclear(&opb);
  100342. memset(op,0,sizeof(*op));
  100343. memset(op_comm,0,sizeof(*op_comm));
  100344. memset(op_code,0,sizeof(*op_code));
  100345. if(b->header)_ogg_free(b->header);
  100346. if(b->header1)_ogg_free(b->header1);
  100347. if(b->header2)_ogg_free(b->header2);
  100348. b->header=NULL;
  100349. b->header1=NULL;
  100350. b->header2=NULL;
  100351. return(ret);
  100352. }
  100353. double vorbis_granule_time(vorbis_dsp_state *v,ogg_int64_t granulepos){
  100354. if(granulepos>=0)
  100355. return((double)granulepos/v->vi->rate);
  100356. return(-1);
  100357. }
  100358. #endif
  100359. /*** End of inlined file: info.c ***/
  100360. /*** Start of inlined file: lpc.c ***/
  100361. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100362. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100363. // tasks..
  100364. #if JUCE_MSVC
  100365. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100366. #endif
  100367. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100368. #if JUCE_USE_OGGVORBIS
  100369. #include <stdlib.h>
  100370. #include <string.h>
  100371. #include <math.h>
  100372. float vorbis_lpc_from_data(float *data,float *lpci,int n,int m){
  100373. double *aut=(double*)alloca(sizeof(*aut)*(m+1));
  100374. double *lpc=(double*)alloca(sizeof(*lpc)*(m));
  100375. double error;
  100376. int i,j;
  100377. j=m+1;
  100378. while(j--){
  100379. double d=0; /* double needed for accumulator depth */
  100380. for(i=j;i<n;i++)d+=(double)data[i]*data[i-j];
  100381. aut[j]=d;
  100382. }
  100383. error=aut[0];
  100384. for(i=0;i<m;i++){
  100385. double r= -aut[i+1];
  100386. if(error==0){
  100387. memset(lpci,0,m*sizeof(*lpci));
  100388. return 0;
  100389. }
  100390. for(j=0;j<i;j++)r-=lpc[j]*aut[i-j];
  100391. r/=error;
  100392. lpc[i]=r;
  100393. for(j=0;j<i/2;j++){
  100394. double tmp=lpc[j];
  100395. lpc[j]+=r*lpc[i-1-j];
  100396. lpc[i-1-j]+=r*tmp;
  100397. }
  100398. if(i%2)lpc[j]+=lpc[j]*r;
  100399. error*=1.f-r*r;
  100400. }
  100401. for(j=0;j<m;j++)lpci[j]=(float)lpc[j];
  100402. return error;
  100403. }
  100404. void vorbis_lpc_predict(float *coeff,float *prime,int m,
  100405. float *data,long n){
  100406. long i,j,o,p;
  100407. float y;
  100408. float *work=(float*)alloca(sizeof(*work)*(m+n));
  100409. if(!prime)
  100410. for(i=0;i<m;i++)
  100411. work[i]=0.f;
  100412. else
  100413. for(i=0;i<m;i++)
  100414. work[i]=prime[i];
  100415. for(i=0;i<n;i++){
  100416. y=0;
  100417. o=i;
  100418. p=m;
  100419. for(j=0;j<m;j++)
  100420. y-=work[o++]*coeff[--p];
  100421. data[i]=work[o]=y;
  100422. }
  100423. }
  100424. #endif
  100425. /*** End of inlined file: lpc.c ***/
  100426. /*** Start of inlined file: lsp.c ***/
  100427. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100428. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100429. // tasks..
  100430. #if JUCE_MSVC
  100431. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100432. #endif
  100433. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100434. #if JUCE_USE_OGGVORBIS
  100435. #include <math.h>
  100436. #include <string.h>
  100437. #include <stdlib.h>
  100438. /*** Start of inlined file: lookup.h ***/
  100439. #ifndef _V_LOOKUP_H_
  100440. #ifdef FLOAT_LOOKUP
  100441. extern float vorbis_coslook(float a);
  100442. extern float vorbis_invsqlook(float a);
  100443. extern float vorbis_invsq2explook(int a);
  100444. extern float vorbis_fromdBlook(float a);
  100445. #endif
  100446. #ifdef INT_LOOKUP
  100447. extern long vorbis_invsqlook_i(long a,long e);
  100448. extern long vorbis_coslook_i(long a);
  100449. extern float vorbis_fromdBlook_i(long a);
  100450. #endif
  100451. #endif
  100452. /*** End of inlined file: lookup.h ***/
  100453. #define FLOAT_LOOKUP
  100454. #undef INT_LOOKUP
  100455. #ifdef FLOAT_LOOKUP
  100456. /*** Start of inlined file: lookup.c ***/
  100457. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100458. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100459. // tasks..
  100460. #if JUCE_MSVC
  100461. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100462. #endif
  100463. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100464. #if JUCE_USE_OGGVORBIS
  100465. #include <math.h>
  100466. /*** Start of inlined file: lookup.h ***/
  100467. #ifndef _V_LOOKUP_H_
  100468. #ifdef FLOAT_LOOKUP
  100469. extern float vorbis_coslook(float a);
  100470. extern float vorbis_invsqlook(float a);
  100471. extern float vorbis_invsq2explook(int a);
  100472. extern float vorbis_fromdBlook(float a);
  100473. #endif
  100474. #ifdef INT_LOOKUP
  100475. extern long vorbis_invsqlook_i(long a,long e);
  100476. extern long vorbis_coslook_i(long a);
  100477. extern float vorbis_fromdBlook_i(long a);
  100478. #endif
  100479. #endif
  100480. /*** End of inlined file: lookup.h ***/
  100481. /*** Start of inlined file: lookup_data.h ***/
  100482. #ifndef _V_LOOKUP_DATA_H_
  100483. #ifdef FLOAT_LOOKUP
  100484. #define COS_LOOKUP_SZ 128
  100485. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  100486. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  100487. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  100488. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  100489. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  100490. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  100491. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  100492. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  100493. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  100494. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  100495. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  100496. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  100497. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  100498. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  100499. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  100500. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  100501. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  100502. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  100503. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  100504. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  100505. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  100506. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  100507. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  100508. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  100509. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  100510. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  100511. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  100512. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  100513. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  100514. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  100515. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  100516. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  100517. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  100518. -1.0000000000000f,
  100519. };
  100520. #define INVSQ_LOOKUP_SZ 32
  100521. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  100522. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  100523. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  100524. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  100525. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  100526. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  100527. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  100528. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  100529. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  100530. 1.000000000000f,
  100531. };
  100532. #define INVSQ2EXP_LOOKUP_MIN (-32)
  100533. #define INVSQ2EXP_LOOKUP_MAX 32
  100534. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  100535. INVSQ2EXP_LOOKUP_MIN+1]={
  100536. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  100537. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  100538. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  100539. 1024.f, 724.0773439f, 512.f, 362.038672f,
  100540. 256.f, 181.019336f, 128.f, 90.50966799f,
  100541. 64.f, 45.254834f, 32.f, 22.627417f,
  100542. 16.f, 11.3137085f, 8.f, 5.656854249f,
  100543. 4.f, 2.828427125f, 2.f, 1.414213562f,
  100544. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  100545. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  100546. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  100547. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  100548. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  100549. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  100550. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  100551. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  100552. 1.525878906e-05f,
  100553. };
  100554. #endif
  100555. #define FROMdB_LOOKUP_SZ 35
  100556. #define FROMdB2_LOOKUP_SZ 32
  100557. #define FROMdB_SHIFT 5
  100558. #define FROMdB2_SHIFT 3
  100559. #define FROMdB2_MASK 31
  100560. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  100561. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  100562. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  100563. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  100564. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  100565. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  100566. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  100567. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  100568. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  100569. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  100570. };
  100571. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  100572. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  100573. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  100574. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  100575. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  100576. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  100577. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  100578. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  100579. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  100580. };
  100581. #ifdef INT_LOOKUP
  100582. #define INVSQ_LOOKUP_I_SHIFT 10
  100583. #define INVSQ_LOOKUP_I_MASK 1023
  100584. static long INVSQ_LOOKUP_I[64+1]={
  100585. 92682l, 91966l, 91267l, 90583l,
  100586. 89915l, 89261l, 88621l, 87995l,
  100587. 87381l, 86781l, 86192l, 85616l,
  100588. 85051l, 84497l, 83953l, 83420l,
  100589. 82897l, 82384l, 81880l, 81385l,
  100590. 80899l, 80422l, 79953l, 79492l,
  100591. 79039l, 78594l, 78156l, 77726l,
  100592. 77302l, 76885l, 76475l, 76072l,
  100593. 75674l, 75283l, 74898l, 74519l,
  100594. 74146l, 73778l, 73415l, 73058l,
  100595. 72706l, 72359l, 72016l, 71679l,
  100596. 71347l, 71019l, 70695l, 70376l,
  100597. 70061l, 69750l, 69444l, 69141l,
  100598. 68842l, 68548l, 68256l, 67969l,
  100599. 67685l, 67405l, 67128l, 66855l,
  100600. 66585l, 66318l, 66054l, 65794l,
  100601. 65536l,
  100602. };
  100603. #define COS_LOOKUP_I_SHIFT 9
  100604. #define COS_LOOKUP_I_MASK 511
  100605. #define COS_LOOKUP_I_SZ 128
  100606. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  100607. 16384l, 16379l, 16364l, 16340l,
  100608. 16305l, 16261l, 16207l, 16143l,
  100609. 16069l, 15986l, 15893l, 15791l,
  100610. 15679l, 15557l, 15426l, 15286l,
  100611. 15137l, 14978l, 14811l, 14635l,
  100612. 14449l, 14256l, 14053l, 13842l,
  100613. 13623l, 13395l, 13160l, 12916l,
  100614. 12665l, 12406l, 12140l, 11866l,
  100615. 11585l, 11297l, 11003l, 10702l,
  100616. 10394l, 10080l, 9760l, 9434l,
  100617. 9102l, 8765l, 8423l, 8076l,
  100618. 7723l, 7366l, 7005l, 6639l,
  100619. 6270l, 5897l, 5520l, 5139l,
  100620. 4756l, 4370l, 3981l, 3590l,
  100621. 3196l, 2801l, 2404l, 2006l,
  100622. 1606l, 1205l, 804l, 402l,
  100623. 0l, -401l, -803l, -1204l,
  100624. -1605l, -2005l, -2403l, -2800l,
  100625. -3195l, -3589l, -3980l, -4369l,
  100626. -4755l, -5138l, -5519l, -5896l,
  100627. -6269l, -6638l, -7004l, -7365l,
  100628. -7722l, -8075l, -8422l, -8764l,
  100629. -9101l, -9433l, -9759l, -10079l,
  100630. -10393l, -10701l, -11002l, -11296l,
  100631. -11584l, -11865l, -12139l, -12405l,
  100632. -12664l, -12915l, -13159l, -13394l,
  100633. -13622l, -13841l, -14052l, -14255l,
  100634. -14448l, -14634l, -14810l, -14977l,
  100635. -15136l, -15285l, -15425l, -15556l,
  100636. -15678l, -15790l, -15892l, -15985l,
  100637. -16068l, -16142l, -16206l, -16260l,
  100638. -16304l, -16339l, -16363l, -16378l,
  100639. -16383l,
  100640. };
  100641. #endif
  100642. #endif
  100643. /*** End of inlined file: lookup_data.h ***/
  100644. #ifdef FLOAT_LOOKUP
  100645. float vorbis_coslook(float a){
  100646. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  100647. int i=vorbis_ftoi(d-.5);
  100648. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  100649. }
  100650. float vorbis_invsqlook(float a){
  100651. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  100652. int i=vorbis_ftoi(d-.5f);
  100653. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  100654. }
  100655. float vorbis_invsq2explook(int a){
  100656. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  100657. }
  100658. #include <stdio.h>
  100659. float vorbis_fromdBlook(float a){
  100660. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  100661. return (i<0)?1.f:
  100662. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100663. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100664. }
  100665. #endif
  100666. #ifdef INT_LOOKUP
  100667. long vorbis_invsqlook_i(long a,long e){
  100668. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  100669. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  100670. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  100671. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  100672. d)>>16); /* result 1.16 */
  100673. e+=32;
  100674. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  100675. e=(e>>1)-8;
  100676. return(val>>e);
  100677. }
  100678. float vorbis_fromdBlook_i(long a){
  100679. int i=(-a)>>(12-FROMdB2_SHIFT);
  100680. return (i<0)?1.f:
  100681. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100682. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100683. }
  100684. long vorbis_coslook_i(long a){
  100685. int i=a>>COS_LOOKUP_I_SHIFT;
  100686. int d=a&COS_LOOKUP_I_MASK;
  100687. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  100688. COS_LOOKUP_I_SHIFT);
  100689. }
  100690. #endif
  100691. #endif
  100692. /*** End of inlined file: lookup.c ***/
  100693. /* catch this in the build system; we #include for
  100694. compilers (like gcc) that can't inline across
  100695. modules */
  100696. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  100697. float amp,float ampoffset){
  100698. int i;
  100699. float wdel=M_PI/ln;
  100700. vorbis_fpu_control fpu;
  100701. (void) fpu; // to avoid an unused variable warning
  100702. vorbis_fpu_setround(&fpu);
  100703. for(i=0;i<m;i++)lsp[i]=vorbis_coslook(lsp[i]);
  100704. i=0;
  100705. while(i<n){
  100706. int k=map[i];
  100707. int qexp;
  100708. float p=.7071067812f;
  100709. float q=.7071067812f;
  100710. float w=vorbis_coslook(wdel*k);
  100711. float *ftmp=lsp;
  100712. int c=m>>1;
  100713. do{
  100714. q*=ftmp[0]-w;
  100715. p*=ftmp[1]-w;
  100716. ftmp+=2;
  100717. }while(--c);
  100718. if(m&1){
  100719. q*=ftmp[0]-w;
  100720. q*=q;
  100721. p*=p*(1.f-w*w);
  100722. }else{
  100723. q*=q*(1.f+w);
  100724. p*=p*(1.f-w);
  100725. }
  100726. q=frexp(p+q,&qexp);
  100727. q=vorbis_fromdBlook(amp*
  100728. vorbis_invsqlook(q)*
  100729. vorbis_invsq2explook(qexp+m)-
  100730. ampoffset);
  100731. do{
  100732. curve[i++]*=q;
  100733. }while(map[i]==k);
  100734. }
  100735. vorbis_fpu_restore(fpu);
  100736. }
  100737. #else
  100738. #ifdef INT_LOOKUP
  100739. /*** Start of inlined file: lookup.c ***/
  100740. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100741. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100742. // tasks..
  100743. #if JUCE_MSVC
  100744. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100745. #endif
  100746. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100747. #if JUCE_USE_OGGVORBIS
  100748. #include <math.h>
  100749. /*** Start of inlined file: lookup.h ***/
  100750. #ifndef _V_LOOKUP_H_
  100751. #ifdef FLOAT_LOOKUP
  100752. extern float vorbis_coslook(float a);
  100753. extern float vorbis_invsqlook(float a);
  100754. extern float vorbis_invsq2explook(int a);
  100755. extern float vorbis_fromdBlook(float a);
  100756. #endif
  100757. #ifdef INT_LOOKUP
  100758. extern long vorbis_invsqlook_i(long a,long e);
  100759. extern long vorbis_coslook_i(long a);
  100760. extern float vorbis_fromdBlook_i(long a);
  100761. #endif
  100762. #endif
  100763. /*** End of inlined file: lookup.h ***/
  100764. /*** Start of inlined file: lookup_data.h ***/
  100765. #ifndef _V_LOOKUP_DATA_H_
  100766. #ifdef FLOAT_LOOKUP
  100767. #define COS_LOOKUP_SZ 128
  100768. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  100769. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  100770. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  100771. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  100772. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  100773. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  100774. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  100775. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  100776. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  100777. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  100778. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  100779. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  100780. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  100781. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  100782. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  100783. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  100784. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  100785. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  100786. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  100787. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  100788. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  100789. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  100790. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  100791. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  100792. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  100793. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  100794. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  100795. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  100796. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  100797. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  100798. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  100799. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  100800. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  100801. -1.0000000000000f,
  100802. };
  100803. #define INVSQ_LOOKUP_SZ 32
  100804. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  100805. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  100806. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  100807. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  100808. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  100809. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  100810. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  100811. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  100812. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  100813. 1.000000000000f,
  100814. };
  100815. #define INVSQ2EXP_LOOKUP_MIN (-32)
  100816. #define INVSQ2EXP_LOOKUP_MAX 32
  100817. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  100818. INVSQ2EXP_LOOKUP_MIN+1]={
  100819. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  100820. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  100821. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  100822. 1024.f, 724.0773439f, 512.f, 362.038672f,
  100823. 256.f, 181.019336f, 128.f, 90.50966799f,
  100824. 64.f, 45.254834f, 32.f, 22.627417f,
  100825. 16.f, 11.3137085f, 8.f, 5.656854249f,
  100826. 4.f, 2.828427125f, 2.f, 1.414213562f,
  100827. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  100828. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  100829. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  100830. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  100831. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  100832. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  100833. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  100834. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  100835. 1.525878906e-05f,
  100836. };
  100837. #endif
  100838. #define FROMdB_LOOKUP_SZ 35
  100839. #define FROMdB2_LOOKUP_SZ 32
  100840. #define FROMdB_SHIFT 5
  100841. #define FROMdB2_SHIFT 3
  100842. #define FROMdB2_MASK 31
  100843. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  100844. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  100845. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  100846. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  100847. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  100848. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  100849. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  100850. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  100851. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  100852. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  100853. };
  100854. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  100855. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  100856. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  100857. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  100858. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  100859. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  100860. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  100861. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  100862. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  100863. };
  100864. #ifdef INT_LOOKUP
  100865. #define INVSQ_LOOKUP_I_SHIFT 10
  100866. #define INVSQ_LOOKUP_I_MASK 1023
  100867. static long INVSQ_LOOKUP_I[64+1]={
  100868. 92682l, 91966l, 91267l, 90583l,
  100869. 89915l, 89261l, 88621l, 87995l,
  100870. 87381l, 86781l, 86192l, 85616l,
  100871. 85051l, 84497l, 83953l, 83420l,
  100872. 82897l, 82384l, 81880l, 81385l,
  100873. 80899l, 80422l, 79953l, 79492l,
  100874. 79039l, 78594l, 78156l, 77726l,
  100875. 77302l, 76885l, 76475l, 76072l,
  100876. 75674l, 75283l, 74898l, 74519l,
  100877. 74146l, 73778l, 73415l, 73058l,
  100878. 72706l, 72359l, 72016l, 71679l,
  100879. 71347l, 71019l, 70695l, 70376l,
  100880. 70061l, 69750l, 69444l, 69141l,
  100881. 68842l, 68548l, 68256l, 67969l,
  100882. 67685l, 67405l, 67128l, 66855l,
  100883. 66585l, 66318l, 66054l, 65794l,
  100884. 65536l,
  100885. };
  100886. #define COS_LOOKUP_I_SHIFT 9
  100887. #define COS_LOOKUP_I_MASK 511
  100888. #define COS_LOOKUP_I_SZ 128
  100889. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  100890. 16384l, 16379l, 16364l, 16340l,
  100891. 16305l, 16261l, 16207l, 16143l,
  100892. 16069l, 15986l, 15893l, 15791l,
  100893. 15679l, 15557l, 15426l, 15286l,
  100894. 15137l, 14978l, 14811l, 14635l,
  100895. 14449l, 14256l, 14053l, 13842l,
  100896. 13623l, 13395l, 13160l, 12916l,
  100897. 12665l, 12406l, 12140l, 11866l,
  100898. 11585l, 11297l, 11003l, 10702l,
  100899. 10394l, 10080l, 9760l, 9434l,
  100900. 9102l, 8765l, 8423l, 8076l,
  100901. 7723l, 7366l, 7005l, 6639l,
  100902. 6270l, 5897l, 5520l, 5139l,
  100903. 4756l, 4370l, 3981l, 3590l,
  100904. 3196l, 2801l, 2404l, 2006l,
  100905. 1606l, 1205l, 804l, 402l,
  100906. 0l, -401l, -803l, -1204l,
  100907. -1605l, -2005l, -2403l, -2800l,
  100908. -3195l, -3589l, -3980l, -4369l,
  100909. -4755l, -5138l, -5519l, -5896l,
  100910. -6269l, -6638l, -7004l, -7365l,
  100911. -7722l, -8075l, -8422l, -8764l,
  100912. -9101l, -9433l, -9759l, -10079l,
  100913. -10393l, -10701l, -11002l, -11296l,
  100914. -11584l, -11865l, -12139l, -12405l,
  100915. -12664l, -12915l, -13159l, -13394l,
  100916. -13622l, -13841l, -14052l, -14255l,
  100917. -14448l, -14634l, -14810l, -14977l,
  100918. -15136l, -15285l, -15425l, -15556l,
  100919. -15678l, -15790l, -15892l, -15985l,
  100920. -16068l, -16142l, -16206l, -16260l,
  100921. -16304l, -16339l, -16363l, -16378l,
  100922. -16383l,
  100923. };
  100924. #endif
  100925. #endif
  100926. /*** End of inlined file: lookup_data.h ***/
  100927. #ifdef FLOAT_LOOKUP
  100928. float vorbis_coslook(float a){
  100929. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  100930. int i=vorbis_ftoi(d-.5);
  100931. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  100932. }
  100933. float vorbis_invsqlook(float a){
  100934. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  100935. int i=vorbis_ftoi(d-.5f);
  100936. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  100937. }
  100938. float vorbis_invsq2explook(int a){
  100939. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  100940. }
  100941. #include <stdio.h>
  100942. float vorbis_fromdBlook(float a){
  100943. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  100944. return (i<0)?1.f:
  100945. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100946. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100947. }
  100948. #endif
  100949. #ifdef INT_LOOKUP
  100950. long vorbis_invsqlook_i(long a,long e){
  100951. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  100952. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  100953. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  100954. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  100955. d)>>16); /* result 1.16 */
  100956. e+=32;
  100957. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  100958. e=(e>>1)-8;
  100959. return(val>>e);
  100960. }
  100961. float vorbis_fromdBlook_i(long a){
  100962. int i=(-a)>>(12-FROMdB2_SHIFT);
  100963. return (i<0)?1.f:
  100964. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100965. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100966. }
  100967. long vorbis_coslook_i(long a){
  100968. int i=a>>COS_LOOKUP_I_SHIFT;
  100969. int d=a&COS_LOOKUP_I_MASK;
  100970. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  100971. COS_LOOKUP_I_SHIFT);
  100972. }
  100973. #endif
  100974. #endif
  100975. /*** End of inlined file: lookup.c ***/
  100976. /* catch this in the build system; we #include for
  100977. compilers (like gcc) that can't inline across
  100978. modules */
  100979. static int MLOOP_1[64]={
  100980. 0,10,11,11, 12,12,12,12, 13,13,13,13, 13,13,13,13,
  100981. 14,14,14,14, 14,14,14,14, 14,14,14,14, 14,14,14,14,
  100982. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  100983. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  100984. };
  100985. static int MLOOP_2[64]={
  100986. 0,4,5,5, 6,6,6,6, 7,7,7,7, 7,7,7,7,
  100987. 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8,
  100988. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  100989. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  100990. };
  100991. static int MLOOP_3[8]={0,1,2,2,3,3,3,3};
  100992. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  100993. float amp,float ampoffset){
  100994. int i;
  100995. int ampoffseti=rint(ampoffset*4096.f);
  100996. int ampi=rint(amp*16.f);
  100997. long *ilsp=alloca(m*sizeof(*ilsp));
  100998. for(i=0;i<m;i++)ilsp[i]=vorbis_coslook_i(lsp[i]/M_PI*65536.f+.5f);
  100999. i=0;
  101000. while(i<n){
  101001. int j,k=map[i];
  101002. unsigned long pi=46341; /* 2**-.5 in 0.16 */
  101003. unsigned long qi=46341;
  101004. int qexp=0,shift;
  101005. long wi=vorbis_coslook_i(k*65536/ln);
  101006. qi*=labs(ilsp[0]-wi);
  101007. pi*=labs(ilsp[1]-wi);
  101008. for(j=3;j<m;j+=2){
  101009. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101010. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101011. shift=MLOOP_3[(pi|qi)>>16];
  101012. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  101013. pi=(pi>>shift)*labs(ilsp[j]-wi);
  101014. qexp+=shift;
  101015. }
  101016. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101017. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101018. shift=MLOOP_3[(pi|qi)>>16];
  101019. if(m&1){
  101020. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  101021. pi=(pi>>shift)<<14;
  101022. qexp+=shift;
  101023. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101024. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101025. shift=MLOOP_3[(pi|qi)>>16];
  101026. pi>>=shift;
  101027. qi>>=shift;
  101028. qexp+=shift-14*((m+1)>>1);
  101029. pi=((pi*pi)>>16);
  101030. qi=((qi*qi)>>16);
  101031. qexp=qexp*2+m;
  101032. pi*=(1<<14)-((wi*wi)>>14);
  101033. qi+=pi>>14;
  101034. }else{
  101035. pi>>=shift;
  101036. qi>>=shift;
  101037. qexp+=shift-7*m;
  101038. pi=((pi*pi)>>16);
  101039. qi=((qi*qi)>>16);
  101040. qexp=qexp*2+m;
  101041. pi*=(1<<14)-wi;
  101042. qi*=(1<<14)+wi;
  101043. qi=(qi+pi)>>14;
  101044. }
  101045. if(qi&0xffff0000){ /* checks for 1.xxxxxxxxxxxxxxxx */
  101046. qi>>=1; qexp++;
  101047. }else
  101048. while(qi && !(qi&0x8000)){ /* checks for 0.0xxxxxxxxxxxxxxx or less*/
  101049. qi<<=1; qexp--;
  101050. }
  101051. amp=vorbis_fromdBlook_i(ampi* /* n.4 */
  101052. vorbis_invsqlook_i(qi,qexp)-
  101053. ampoffseti); /* 8.12[0] */
  101054. curve[i]*=amp;
  101055. while(map[++i]==k)curve[i]*=amp;
  101056. }
  101057. }
  101058. #else
  101059. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101060. float amp,float ampoffset){
  101061. int i;
  101062. float wdel=M_PI/ln;
  101063. for(i=0;i<m;i++)lsp[i]=2.f*cos(lsp[i]);
  101064. i=0;
  101065. while(i<n){
  101066. int j,k=map[i];
  101067. float p=.5f;
  101068. float q=.5f;
  101069. float w=2.f*cos(wdel*k);
  101070. for(j=1;j<m;j+=2){
  101071. q *= w-lsp[j-1];
  101072. p *= w-lsp[j];
  101073. }
  101074. if(j==m){
  101075. q*=w-lsp[j-1];
  101076. p*=p*(4.f-w*w);
  101077. q*=q;
  101078. }else{
  101079. p*=p*(2.f-w);
  101080. q*=q*(2.f+w);
  101081. }
  101082. q=fromdB(amp/sqrt(p+q)-ampoffset);
  101083. curve[i]*=q;
  101084. while(map[++i]==k)curve[i]*=q;
  101085. }
  101086. }
  101087. #endif
  101088. #endif
  101089. static void cheby(float *g, int ord) {
  101090. int i, j;
  101091. g[0] *= .5f;
  101092. for(i=2; i<= ord; i++) {
  101093. for(j=ord; j >= i; j--) {
  101094. g[j-2] -= g[j];
  101095. g[j] += g[j];
  101096. }
  101097. }
  101098. }
  101099. static int comp(const void *a,const void *b){
  101100. return (*(float *)a<*(float *)b)-(*(float *)a>*(float *)b);
  101101. }
  101102. #define EPSILON 10e-7
  101103. static int Laguerre_With_Deflation(float *a,int ord,float *r){
  101104. int i,m;
  101105. double lastdelta=0.f;
  101106. double *defl=(double*)alloca(sizeof(*defl)*(ord+1));
  101107. for(i=0;i<=ord;i++)defl[i]=a[i];
  101108. for(m=ord;m>0;m--){
  101109. double newx=0.f,delta;
  101110. while(1){
  101111. double p=defl[m],pp=0.f,ppp=0.f,denom;
  101112. for(i=m;i>0;i--){
  101113. ppp = newx*ppp + pp;
  101114. pp = newx*pp + p;
  101115. p = newx*p + defl[i-1];
  101116. }
  101117. denom=(m-1) * ((m-1)*pp*pp - m*p*ppp);
  101118. if(denom<0)
  101119. return(-1); /* complex root! The LPC generator handed us a bad filter */
  101120. if(pp>0){
  101121. denom = pp + sqrt(denom);
  101122. if(denom<EPSILON)denom=EPSILON;
  101123. }else{
  101124. denom = pp - sqrt(denom);
  101125. if(denom>-(EPSILON))denom=-(EPSILON);
  101126. }
  101127. delta = m*p/denom;
  101128. newx -= delta;
  101129. if(delta<0.f)delta*=-1;
  101130. if(fabs(delta/newx)<10e-12)break;
  101131. lastdelta=delta;
  101132. }
  101133. r[m-1]=newx;
  101134. for(i=m;i>0;i--)
  101135. defl[i-1]+=newx*defl[i];
  101136. defl++;
  101137. }
  101138. return(0);
  101139. }
  101140. static int Newton_Raphson(float *a,int ord,float *r){
  101141. int i, k, count=0;
  101142. double error=1.f;
  101143. double *root=(double*)alloca(ord*sizeof(*root));
  101144. for(i=0; i<ord;i++) root[i] = r[i];
  101145. while(error>1e-20){
  101146. error=0;
  101147. for(i=0; i<ord; i++) { /* Update each point. */
  101148. double pp=0.,delta;
  101149. double rooti=root[i];
  101150. double p=a[ord];
  101151. for(k=ord-1; k>= 0; k--) {
  101152. pp= pp* rooti + p;
  101153. p = p * rooti + a[k];
  101154. }
  101155. delta = p/pp;
  101156. root[i] -= delta;
  101157. error+= delta*delta;
  101158. }
  101159. if(count>40)return(-1);
  101160. count++;
  101161. }
  101162. for(i=0; i<ord;i++) r[i] = root[i];
  101163. return(0);
  101164. }
  101165. int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m){
  101166. int order2=(m+1)>>1;
  101167. int g1_order,g2_order;
  101168. float *g1=(float*)alloca(sizeof(*g1)*(order2+1));
  101169. float *g2=(float*)alloca(sizeof(*g2)*(order2+1));
  101170. float *g1r=(float*)alloca(sizeof(*g1r)*(order2+1));
  101171. float *g2r=(float*)alloca(sizeof(*g2r)*(order2+1));
  101172. int i;
  101173. g1_order=(m+1)>>1;
  101174. g2_order=(m) >>1;
  101175. g1[g1_order] = 1.f;
  101176. for(i=1;i<=g1_order;i++) g1[g1_order-i] = lpc[i-1]+lpc[m-i];
  101177. g2[g2_order] = 1.f;
  101178. for(i=1;i<=g2_order;i++) g2[g2_order-i] = lpc[i-1]-lpc[m-i];
  101179. if(g1_order>g2_order){
  101180. for(i=2; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+2];
  101181. }else{
  101182. for(i=1; i<=g1_order;i++) g1[g1_order-i] -= g1[g1_order-i+1];
  101183. for(i=1; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+1];
  101184. }
  101185. cheby(g1,g1_order);
  101186. cheby(g2,g2_order);
  101187. if(Laguerre_With_Deflation(g1,g1_order,g1r) ||
  101188. Laguerre_With_Deflation(g2,g2_order,g2r))
  101189. return(-1);
  101190. Newton_Raphson(g1,g1_order,g1r); /* if it fails, it leaves g1r alone */
  101191. Newton_Raphson(g2,g2_order,g2r); /* if it fails, it leaves g2r alone */
  101192. qsort(g1r,g1_order,sizeof(*g1r),comp);
  101193. qsort(g2r,g2_order,sizeof(*g2r),comp);
  101194. for(i=0;i<g1_order;i++)
  101195. lsp[i*2] = acos(g1r[i]);
  101196. for(i=0;i<g2_order;i++)
  101197. lsp[i*2+1] = acos(g2r[i]);
  101198. return(0);
  101199. }
  101200. #endif
  101201. /*** End of inlined file: lsp.c ***/
  101202. /*** Start of inlined file: mapping0.c ***/
  101203. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101204. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101205. // tasks..
  101206. #if JUCE_MSVC
  101207. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101208. #endif
  101209. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101210. #if JUCE_USE_OGGVORBIS
  101211. #include <stdlib.h>
  101212. #include <stdio.h>
  101213. #include <string.h>
  101214. #include <math.h>
  101215. static void mapping0_free_info(vorbis_info_mapping *i){
  101216. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)i;
  101217. if(info){
  101218. memset(info,0,sizeof(*info));
  101219. _ogg_free(info);
  101220. }
  101221. }
  101222. static int ilog3(unsigned int v){
  101223. int ret=0;
  101224. if(v)--v;
  101225. while(v){
  101226. ret++;
  101227. v>>=1;
  101228. }
  101229. return(ret);
  101230. }
  101231. static void mapping0_pack(vorbis_info *vi,vorbis_info_mapping *vm,
  101232. oggpack_buffer *opb){
  101233. int i;
  101234. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)vm;
  101235. if(info->submaps>1){
  101236. oggpack_write(opb,1,1);
  101237. oggpack_write(opb,info->submaps-1,4);
  101238. }else
  101239. oggpack_write(opb,0,1);
  101240. if(info->coupling_steps>0){
  101241. oggpack_write(opb,1,1);
  101242. oggpack_write(opb,info->coupling_steps-1,8);
  101243. for(i=0;i<info->coupling_steps;i++){
  101244. oggpack_write(opb,info->coupling_mag[i],ilog3(vi->channels));
  101245. oggpack_write(opb,info->coupling_ang[i],ilog3(vi->channels));
  101246. }
  101247. }else
  101248. oggpack_write(opb,0,1);
  101249. oggpack_write(opb,0,2); /* 2,3:reserved */
  101250. if(info->submaps>1){
  101251. for(i=0;i<vi->channels;i++)
  101252. oggpack_write(opb,info->chmuxlist[i],4);
  101253. }
  101254. for(i=0;i<info->submaps;i++){
  101255. oggpack_write(opb,0,8); /* time submap unused */
  101256. oggpack_write(opb,info->floorsubmap[i],8);
  101257. oggpack_write(opb,info->residuesubmap[i],8);
  101258. }
  101259. }
  101260. static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  101261. int i;
  101262. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)_ogg_calloc(1,sizeof(*info));
  101263. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101264. memset(info,0,sizeof(*info));
  101265. if(oggpack_read(opb,1))
  101266. info->submaps=oggpack_read(opb,4)+1;
  101267. else
  101268. info->submaps=1;
  101269. if(oggpack_read(opb,1)){
  101270. info->coupling_steps=oggpack_read(opb,8)+1;
  101271. for(i=0;i<info->coupling_steps;i++){
  101272. int testM=info->coupling_mag[i]=oggpack_read(opb,ilog3(vi->channels));
  101273. int testA=info->coupling_ang[i]=oggpack_read(opb,ilog3(vi->channels));
  101274. if(testM<0 ||
  101275. testA<0 ||
  101276. testM==testA ||
  101277. testM>=vi->channels ||
  101278. testA>=vi->channels) goto err_out;
  101279. }
  101280. }
  101281. if(oggpack_read(opb,2)>0)goto err_out; /* 2,3:reserved */
  101282. if(info->submaps>1){
  101283. for(i=0;i<vi->channels;i++){
  101284. info->chmuxlist[i]=oggpack_read(opb,4);
  101285. if(info->chmuxlist[i]>=info->submaps)goto err_out;
  101286. }
  101287. }
  101288. for(i=0;i<info->submaps;i++){
  101289. oggpack_read(opb,8); /* time submap unused */
  101290. info->floorsubmap[i]=oggpack_read(opb,8);
  101291. if(info->floorsubmap[i]>=ci->floors)goto err_out;
  101292. info->residuesubmap[i]=oggpack_read(opb,8);
  101293. if(info->residuesubmap[i]>=ci->residues)goto err_out;
  101294. }
  101295. return info;
  101296. err_out:
  101297. mapping0_free_info(info);
  101298. return(NULL);
  101299. }
  101300. #if 0
  101301. static long seq=0;
  101302. static ogg_int64_t total=0;
  101303. static float FLOOR1_fromdB_LOOKUP[256]={
  101304. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  101305. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  101306. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  101307. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  101308. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  101309. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  101310. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  101311. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  101312. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  101313. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  101314. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  101315. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  101316. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  101317. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  101318. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  101319. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  101320. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  101321. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  101322. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  101323. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  101324. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  101325. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  101326. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  101327. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  101328. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  101329. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  101330. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  101331. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  101332. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  101333. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  101334. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  101335. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  101336. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  101337. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  101338. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  101339. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  101340. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  101341. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  101342. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  101343. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  101344. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  101345. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  101346. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  101347. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  101348. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  101349. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  101350. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  101351. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  101352. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  101353. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  101354. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  101355. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  101356. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  101357. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  101358. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  101359. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  101360. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  101361. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  101362. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  101363. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  101364. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  101365. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  101366. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  101367. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  101368. };
  101369. #endif
  101370. extern int *floor1_fit(vorbis_block *vb,void *look,
  101371. const float *logmdct, /* in */
  101372. const float *logmask);
  101373. extern int *floor1_interpolate_fit(vorbis_block *vb,void *look,
  101374. int *A,int *B,
  101375. int del);
  101376. extern int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  101377. void*look,
  101378. int *post,int *ilogmask);
  101379. static int mapping0_forward(vorbis_block *vb){
  101380. vorbis_dsp_state *vd=vb->vd;
  101381. vorbis_info *vi=vd->vi;
  101382. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101383. private_state *b=(private_state*)vb->vd->backend_state;
  101384. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  101385. int n=vb->pcmend;
  101386. int i,j,k;
  101387. int *nonzero = (int*) alloca(sizeof(*nonzero)*vi->channels);
  101388. float **gmdct = (float**) _vorbis_block_alloc(vb,vi->channels*sizeof(*gmdct));
  101389. int **ilogmaskch= (int**) _vorbis_block_alloc(vb,vi->channels*sizeof(*ilogmaskch));
  101390. int ***floor_posts = (int***) _vorbis_block_alloc(vb,vi->channels*sizeof(*floor_posts));
  101391. float global_ampmax=vbi->ampmax;
  101392. float *local_ampmax=(float*)alloca(sizeof(*local_ampmax)*vi->channels);
  101393. int blocktype=vbi->blocktype;
  101394. int modenumber=vb->W;
  101395. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)ci->map_param[modenumber];
  101396. vorbis_look_psy *psy_look=
  101397. b->psy+blocktype+(vb->W?2:0);
  101398. vb->mode=modenumber;
  101399. for(i=0;i<vi->channels;i++){
  101400. float scale=4.f/n;
  101401. float scale_dB;
  101402. float *pcm =vb->pcm[i];
  101403. float *logfft =pcm;
  101404. gmdct[i]=(float*)_vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  101405. scale_dB=todB(&scale) + .345; /* + .345 is a hack; the original
  101406. todB estimation used on IEEE 754
  101407. compliant machines had a bug that
  101408. returned dB values about a third
  101409. of a decibel too high. The bug
  101410. was harmless because tunings
  101411. implicitly took that into
  101412. account. However, fixing the bug
  101413. in the estimator requires
  101414. changing all the tunings as well.
  101415. For now, it's easier to sync
  101416. things back up here, and
  101417. recalibrate the tunings in the
  101418. next major model upgrade. */
  101419. #if 0
  101420. if(vi->channels==2)
  101421. if(i==0)
  101422. _analysis_output("pcmL",seq,pcm,n,0,0,total-n/2);
  101423. else
  101424. _analysis_output("pcmR",seq,pcm,n,0,0,total-n/2);
  101425. #endif
  101426. _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW);
  101427. #if 0
  101428. if(vi->channels==2)
  101429. if(i==0)
  101430. _analysis_output("windowedL",seq,pcm,n,0,0,total-n/2);
  101431. else
  101432. _analysis_output("windowedR",seq,pcm,n,0,0,total-n/2);
  101433. #endif
  101434. mdct_forward((mdct_lookup*) b->transform[vb->W][0],pcm,gmdct[i]);
  101435. drft_forward(&b->fft_look[vb->W],pcm);
  101436. logfft[0]=scale_dB+todB(pcm) + .345; /* + .345 is a hack; the
  101437. original todB estimation used on
  101438. IEEE 754 compliant machines had a
  101439. bug that returned dB values about
  101440. a third of a decibel too high.
  101441. The bug was harmless because
  101442. tunings implicitly took that into
  101443. account. However, fixing the bug
  101444. in the estimator requires
  101445. changing all the tunings as well.
  101446. For now, it's easier to sync
  101447. things back up here, and
  101448. recalibrate the tunings in the
  101449. next major model upgrade. */
  101450. local_ampmax[i]=logfft[0];
  101451. for(j=1;j<n-1;j+=2){
  101452. float temp=pcm[j]*pcm[j]+pcm[j+1]*pcm[j+1];
  101453. temp=logfft[(j+1)>>1]=scale_dB+.5f*todB(&temp) + .345; /* +
  101454. .345 is a hack; the original todB
  101455. estimation used on IEEE 754
  101456. compliant machines had a bug that
  101457. returned dB values about a third
  101458. of a decibel too high. The bug
  101459. was harmless because tunings
  101460. implicitly took that into
  101461. account. However, fixing the bug
  101462. in the estimator requires
  101463. changing all the tunings as well.
  101464. For now, it's easier to sync
  101465. things back up here, and
  101466. recalibrate the tunings in the
  101467. next major model upgrade. */
  101468. if(temp>local_ampmax[i])local_ampmax[i]=temp;
  101469. }
  101470. if(local_ampmax[i]>0.f)local_ampmax[i]=0.f;
  101471. if(local_ampmax[i]>global_ampmax)global_ampmax=local_ampmax[i];
  101472. #if 0
  101473. if(vi->channels==2){
  101474. if(i==0){
  101475. _analysis_output("fftL",seq,logfft,n/2,1,0,0);
  101476. }else{
  101477. _analysis_output("fftR",seq,logfft,n/2,1,0,0);
  101478. }
  101479. }
  101480. #endif
  101481. }
  101482. {
  101483. float *noise = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*noise));
  101484. float *tone = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*tone));
  101485. for(i=0;i<vi->channels;i++){
  101486. int submap=info->chmuxlist[i];
  101487. float *mdct =gmdct[i];
  101488. float *logfft =vb->pcm[i];
  101489. float *logmdct =logfft+n/2;
  101490. float *logmask =logfft;
  101491. vb->mode=modenumber;
  101492. floor_posts[i]=(int**) _vorbis_block_alloc(vb,PACKETBLOBS*sizeof(**floor_posts));
  101493. memset(floor_posts[i],0,sizeof(**floor_posts)*PACKETBLOBS);
  101494. for(j=0;j<n/2;j++)
  101495. logmdct[j]=todB(mdct+j) + .345; /* + .345 is a hack; the original
  101496. todB estimation used on IEEE 754
  101497. compliant machines had a bug that
  101498. returned dB values about a third
  101499. of a decibel too high. The bug
  101500. was harmless because tunings
  101501. implicitly took that into
  101502. account. However, fixing the bug
  101503. in the estimator requires
  101504. changing all the tunings as well.
  101505. For now, it's easier to sync
  101506. things back up here, and
  101507. recalibrate the tunings in the
  101508. next major model upgrade. */
  101509. #if 0
  101510. if(vi->channels==2){
  101511. if(i==0)
  101512. _analysis_output("mdctL",seq,logmdct,n/2,1,0,0);
  101513. else
  101514. _analysis_output("mdctR",seq,logmdct,n/2,1,0,0);
  101515. }else{
  101516. _analysis_output("mdct",seq,logmdct,n/2,1,0,0);
  101517. }
  101518. #endif
  101519. _vp_noisemask(psy_look,
  101520. logmdct,
  101521. noise); /* noise does not have by-frequency offset
  101522. bias applied yet */
  101523. #if 0
  101524. if(vi->channels==2){
  101525. if(i==0)
  101526. _analysis_output("noiseL",seq,noise,n/2,1,0,0);
  101527. else
  101528. _analysis_output("noiseR",seq,noise,n/2,1,0,0);
  101529. }
  101530. #endif
  101531. _vp_tonemask(psy_look,
  101532. logfft,
  101533. tone,
  101534. global_ampmax,
  101535. local_ampmax[i]);
  101536. #if 0
  101537. if(vi->channels==2){
  101538. if(i==0)
  101539. _analysis_output("toneL",seq,tone,n/2,1,0,0);
  101540. else
  101541. _analysis_output("toneR",seq,tone,n/2,1,0,0);
  101542. }
  101543. #endif
  101544. #if 0
  101545. {
  101546. float aotuv[psy_look->n];
  101547. #endif
  101548. _vp_offset_and_mix(psy_look,
  101549. noise,
  101550. tone,
  101551. 1,
  101552. logmask,
  101553. mdct,
  101554. logmdct);
  101555. #if 0
  101556. if(vi->channels==2){
  101557. if(i==0)
  101558. _analysis_output("aotuvM1_L",seq,aotuv,psy_look->n,1,1,0);
  101559. else
  101560. _analysis_output("aotuvM1_R",seq,aotuv,psy_look->n,1,1,0);
  101561. }
  101562. }
  101563. #endif
  101564. #if 0
  101565. if(vi->channels==2){
  101566. if(i==0)
  101567. _analysis_output("mask1L",seq,logmask,n/2,1,0,0);
  101568. else
  101569. _analysis_output("mask1R",seq,logmask,n/2,1,0,0);
  101570. }
  101571. #endif
  101572. if(ci->floor_type[info->floorsubmap[submap]]!=1)return(-1);
  101573. floor_posts[i][PACKETBLOBS/2]=
  101574. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101575. logmdct,
  101576. logmask);
  101577. if(vorbis_bitrate_managed(vb) && floor_posts[i][PACKETBLOBS/2]){
  101578. _vp_offset_and_mix(psy_look,
  101579. noise,
  101580. tone,
  101581. 2,
  101582. logmask,
  101583. mdct,
  101584. logmdct);
  101585. #if 0
  101586. if(vi->channels==2){
  101587. if(i==0)
  101588. _analysis_output("mask2L",seq,logmask,n/2,1,0,0);
  101589. else
  101590. _analysis_output("mask2R",seq,logmask,n/2,1,0,0);
  101591. }
  101592. #endif
  101593. floor_posts[i][PACKETBLOBS-1]=
  101594. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101595. logmdct,
  101596. logmask);
  101597. _vp_offset_and_mix(psy_look,
  101598. noise,
  101599. tone,
  101600. 0,
  101601. logmask,
  101602. mdct,
  101603. logmdct);
  101604. #if 0
  101605. if(vi->channels==2)
  101606. if(i==0)
  101607. _analysis_output("mask0L",seq,logmask,n/2,1,0,0);
  101608. else
  101609. _analysis_output("mask0R",seq,logmask,n/2,1,0,0);
  101610. #endif
  101611. floor_posts[i][0]=
  101612. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101613. logmdct,
  101614. logmask);
  101615. for(k=1;k<PACKETBLOBS/2;k++)
  101616. floor_posts[i][k]=
  101617. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  101618. floor_posts[i][0],
  101619. floor_posts[i][PACKETBLOBS/2],
  101620. k*65536/(PACKETBLOBS/2));
  101621. for(k=PACKETBLOBS/2+1;k<PACKETBLOBS-1;k++)
  101622. floor_posts[i][k]=
  101623. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  101624. floor_posts[i][PACKETBLOBS/2],
  101625. floor_posts[i][PACKETBLOBS-1],
  101626. (k-PACKETBLOBS/2)*65536/(PACKETBLOBS/2));
  101627. }
  101628. }
  101629. }
  101630. vbi->ampmax=global_ampmax;
  101631. {
  101632. float **res_bundle=(float**) alloca(sizeof(*res_bundle)*vi->channels);
  101633. float **couple_bundle=(float**) alloca(sizeof(*couple_bundle)*vi->channels);
  101634. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  101635. int **sortindex=(int**) alloca(sizeof(*sortindex)*vi->channels);
  101636. float **mag_memo;
  101637. int **mag_sort;
  101638. if(info->coupling_steps){
  101639. mag_memo=_vp_quantize_couple_memo(vb,
  101640. &ci->psy_g_param,
  101641. psy_look,
  101642. info,
  101643. gmdct);
  101644. mag_sort=_vp_quantize_couple_sort(vb,
  101645. psy_look,
  101646. info,
  101647. mag_memo);
  101648. hf_reduction(&ci->psy_g_param,
  101649. psy_look,
  101650. info,
  101651. mag_memo);
  101652. }
  101653. memset(sortindex,0,sizeof(*sortindex)*vi->channels);
  101654. if(psy_look->vi->normal_channel_p){
  101655. for(i=0;i<vi->channels;i++){
  101656. float *mdct =gmdct[i];
  101657. sortindex[i]=(int*) alloca(sizeof(**sortindex)*n/2);
  101658. _vp_noise_normalize_sort(psy_look,mdct,sortindex[i]);
  101659. }
  101660. }
  101661. for(k=(vorbis_bitrate_managed(vb)?0:PACKETBLOBS/2);
  101662. k<=(vorbis_bitrate_managed(vb)?PACKETBLOBS-1:PACKETBLOBS/2);
  101663. k++){
  101664. oggpack_buffer *opb=vbi->packetblob[k];
  101665. oggpack_write(opb,0,1);
  101666. oggpack_write(opb,modenumber,b->modebits);
  101667. if(vb->W){
  101668. oggpack_write(opb,vb->lW,1);
  101669. oggpack_write(opb,vb->nW,1);
  101670. }
  101671. for(i=0;i<vi->channels;i++){
  101672. int submap=info->chmuxlist[i];
  101673. float *mdct =gmdct[i];
  101674. float *res =vb->pcm[i];
  101675. int *ilogmask=ilogmaskch[i]=
  101676. (int*) _vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  101677. nonzero[i]=floor1_encode(opb,vb,b->flr[info->floorsubmap[submap]],
  101678. floor_posts[i][k],
  101679. ilogmask);
  101680. #if 0
  101681. {
  101682. char buf[80];
  101683. sprintf(buf,"maskI%c%d",i?'R':'L',k);
  101684. float work[n/2];
  101685. for(j=0;j<n/2;j++)
  101686. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]];
  101687. _analysis_output(buf,seq,work,n/2,1,1,0);
  101688. }
  101689. #endif
  101690. _vp_remove_floor(psy_look,
  101691. mdct,
  101692. ilogmask,
  101693. res,
  101694. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  101695. _vp_noise_normalize(psy_look,res,res+n/2,sortindex[i]);
  101696. #if 0
  101697. {
  101698. char buf[80];
  101699. float work[n/2];
  101700. for(j=0;j<n/2;j++)
  101701. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]]*(res+n/2)[j];
  101702. sprintf(buf,"resI%c%d",i?'R':'L',k);
  101703. _analysis_output(buf,seq,work,n/2,1,1,0);
  101704. }
  101705. #endif
  101706. }
  101707. if(info->coupling_steps){
  101708. _vp_couple(k,
  101709. &ci->psy_g_param,
  101710. psy_look,
  101711. info,
  101712. vb->pcm,
  101713. mag_memo,
  101714. mag_sort,
  101715. ilogmaskch,
  101716. nonzero,
  101717. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  101718. }
  101719. for(i=0;i<info->submaps;i++){
  101720. int ch_in_bundle=0;
  101721. long **classifications;
  101722. int resnum=info->residuesubmap[i];
  101723. for(j=0;j<vi->channels;j++){
  101724. if(info->chmuxlist[j]==i){
  101725. zerobundle[ch_in_bundle]=0;
  101726. if(nonzero[j])zerobundle[ch_in_bundle]=1;
  101727. res_bundle[ch_in_bundle]=vb->pcm[j];
  101728. couple_bundle[ch_in_bundle++]=vb->pcm[j]+n/2;
  101729. }
  101730. }
  101731. classifications=_residue_P[ci->residue_type[resnum]]->
  101732. classx(vb,b->residue[resnum],couple_bundle,zerobundle,ch_in_bundle);
  101733. _residue_P[ci->residue_type[resnum]]->
  101734. forward(opb,vb,b->residue[resnum],
  101735. couple_bundle,NULL,zerobundle,ch_in_bundle,classifications);
  101736. }
  101737. }
  101738. }
  101739. #if 0
  101740. seq++;
  101741. total+=ci->blocksizes[vb->W]/4+ci->blocksizes[vb->nW]/4;
  101742. #endif
  101743. return(0);
  101744. }
  101745. static int mapping0_inverse(vorbis_block *vb,vorbis_info_mapping *l){
  101746. vorbis_dsp_state *vd=vb->vd;
  101747. vorbis_info *vi=vd->vi;
  101748. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  101749. private_state *b=(private_state*)vd->backend_state;
  101750. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)l;
  101751. int i,j;
  101752. long n=vb->pcmend=ci->blocksizes[vb->W];
  101753. float **pcmbundle=(float**) alloca(sizeof(*pcmbundle)*vi->channels);
  101754. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  101755. int *nonzero =(int*) alloca(sizeof(*nonzero)*vi->channels);
  101756. void **floormemo=(void**) alloca(sizeof(*floormemo)*vi->channels);
  101757. for(i=0;i<vi->channels;i++){
  101758. int submap=info->chmuxlist[i];
  101759. floormemo[i]=_floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  101760. inverse1(vb,b->flr[info->floorsubmap[submap]]);
  101761. if(floormemo[i])
  101762. nonzero[i]=1;
  101763. else
  101764. nonzero[i]=0;
  101765. memset(vb->pcm[i],0,sizeof(*vb->pcm[i])*n/2);
  101766. }
  101767. for(i=0;i<info->coupling_steps;i++){
  101768. if(nonzero[info->coupling_mag[i]] ||
  101769. nonzero[info->coupling_ang[i]]){
  101770. nonzero[info->coupling_mag[i]]=1;
  101771. nonzero[info->coupling_ang[i]]=1;
  101772. }
  101773. }
  101774. for(i=0;i<info->submaps;i++){
  101775. int ch_in_bundle=0;
  101776. for(j=0;j<vi->channels;j++){
  101777. if(info->chmuxlist[j]==i){
  101778. if(nonzero[j])
  101779. zerobundle[ch_in_bundle]=1;
  101780. else
  101781. zerobundle[ch_in_bundle]=0;
  101782. pcmbundle[ch_in_bundle++]=vb->pcm[j];
  101783. }
  101784. }
  101785. _residue_P[ci->residue_type[info->residuesubmap[i]]]->
  101786. inverse(vb,b->residue[info->residuesubmap[i]],
  101787. pcmbundle,zerobundle,ch_in_bundle);
  101788. }
  101789. for(i=info->coupling_steps-1;i>=0;i--){
  101790. float *pcmM=vb->pcm[info->coupling_mag[i]];
  101791. float *pcmA=vb->pcm[info->coupling_ang[i]];
  101792. for(j=0;j<n/2;j++){
  101793. float mag=pcmM[j];
  101794. float ang=pcmA[j];
  101795. if(mag>0)
  101796. if(ang>0){
  101797. pcmM[j]=mag;
  101798. pcmA[j]=mag-ang;
  101799. }else{
  101800. pcmA[j]=mag;
  101801. pcmM[j]=mag+ang;
  101802. }
  101803. else
  101804. if(ang>0){
  101805. pcmM[j]=mag;
  101806. pcmA[j]=mag+ang;
  101807. }else{
  101808. pcmA[j]=mag;
  101809. pcmM[j]=mag-ang;
  101810. }
  101811. }
  101812. }
  101813. for(i=0;i<vi->channels;i++){
  101814. float *pcm=vb->pcm[i];
  101815. int submap=info->chmuxlist[i];
  101816. _floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  101817. inverse2(vb,b->flr[info->floorsubmap[submap]],
  101818. floormemo[i],pcm);
  101819. }
  101820. for(i=0;i<vi->channels;i++){
  101821. float *pcm=vb->pcm[i];
  101822. mdct_backward((mdct_lookup*) b->transform[vb->W][0],pcm,pcm);
  101823. }
  101824. return(0);
  101825. }
  101826. vorbis_func_mapping mapping0_exportbundle={
  101827. &mapping0_pack,
  101828. &mapping0_unpack,
  101829. &mapping0_free_info,
  101830. &mapping0_forward,
  101831. &mapping0_inverse
  101832. };
  101833. #endif
  101834. /*** End of inlined file: mapping0.c ***/
  101835. /*** Start of inlined file: mdct.c ***/
  101836. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101837. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101838. // tasks..
  101839. #if JUCE_MSVC
  101840. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101841. #endif
  101842. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101843. #if JUCE_USE_OGGVORBIS
  101844. #include <stdio.h>
  101845. #include <stdlib.h>
  101846. #include <string.h>
  101847. #include <math.h>
  101848. void mdct_init(mdct_lookup *lookup,int n){
  101849. int *bitrev=(int*) _ogg_malloc(sizeof(*bitrev)*(n/4));
  101850. DATA_TYPE *T=(DATA_TYPE*) _ogg_malloc(sizeof(*T)*(n+n/4));
  101851. int i;
  101852. int n2=n>>1;
  101853. int log2n=lookup->log2n=rint(log((float)n)/log(2.f));
  101854. lookup->n=n;
  101855. lookup->trig=T;
  101856. lookup->bitrev=bitrev;
  101857. for(i=0;i<n/4;i++){
  101858. T[i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i)));
  101859. T[i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i)));
  101860. T[n2+i*2]=FLOAT_CONV(cos((M_PI/(2*n))*(2*i+1)));
  101861. T[n2+i*2+1]=FLOAT_CONV(sin((M_PI/(2*n))*(2*i+1)));
  101862. }
  101863. for(i=0;i<n/8;i++){
  101864. T[n+i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i+2))*.5);
  101865. T[n+i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i+2))*.5);
  101866. }
  101867. {
  101868. int mask=(1<<(log2n-1))-1,i,j;
  101869. int msb=1<<(log2n-2);
  101870. for(i=0;i<n/8;i++){
  101871. int acc=0;
  101872. for(j=0;msb>>j;j++)
  101873. if((msb>>j)&i)acc|=1<<j;
  101874. bitrev[i*2]=((~acc)&mask)-1;
  101875. bitrev[i*2+1]=acc;
  101876. }
  101877. }
  101878. lookup->scale=FLOAT_CONV(4.f/n);
  101879. }
  101880. STIN void mdct_butterfly_8(DATA_TYPE *x){
  101881. REG_TYPE r0 = x[6] + x[2];
  101882. REG_TYPE r1 = x[6] - x[2];
  101883. REG_TYPE r2 = x[4] + x[0];
  101884. REG_TYPE r3 = x[4] - x[0];
  101885. x[6] = r0 + r2;
  101886. x[4] = r0 - r2;
  101887. r0 = x[5] - x[1];
  101888. r2 = x[7] - x[3];
  101889. x[0] = r1 + r0;
  101890. x[2] = r1 - r0;
  101891. r0 = x[5] + x[1];
  101892. r1 = x[7] + x[3];
  101893. x[3] = r2 + r3;
  101894. x[1] = r2 - r3;
  101895. x[7] = r1 + r0;
  101896. x[5] = r1 - r0;
  101897. }
  101898. STIN void mdct_butterfly_16(DATA_TYPE *x){
  101899. REG_TYPE r0 = x[1] - x[9];
  101900. REG_TYPE r1 = x[0] - x[8];
  101901. x[8] += x[0];
  101902. x[9] += x[1];
  101903. x[0] = MULT_NORM((r0 + r1) * cPI2_8);
  101904. x[1] = MULT_NORM((r0 - r1) * cPI2_8);
  101905. r0 = x[3] - x[11];
  101906. r1 = x[10] - x[2];
  101907. x[10] += x[2];
  101908. x[11] += x[3];
  101909. x[2] = r0;
  101910. x[3] = r1;
  101911. r0 = x[12] - x[4];
  101912. r1 = x[13] - x[5];
  101913. x[12] += x[4];
  101914. x[13] += x[5];
  101915. x[4] = MULT_NORM((r0 - r1) * cPI2_8);
  101916. x[5] = MULT_NORM((r0 + r1) * cPI2_8);
  101917. r0 = x[14] - x[6];
  101918. r1 = x[15] - x[7];
  101919. x[14] += x[6];
  101920. x[15] += x[7];
  101921. x[6] = r0;
  101922. x[7] = r1;
  101923. mdct_butterfly_8(x);
  101924. mdct_butterfly_8(x+8);
  101925. }
  101926. STIN void mdct_butterfly_32(DATA_TYPE *x){
  101927. REG_TYPE r0 = x[30] - x[14];
  101928. REG_TYPE r1 = x[31] - x[15];
  101929. x[30] += x[14];
  101930. x[31] += x[15];
  101931. x[14] = r0;
  101932. x[15] = r1;
  101933. r0 = x[28] - x[12];
  101934. r1 = x[29] - x[13];
  101935. x[28] += x[12];
  101936. x[29] += x[13];
  101937. x[12] = MULT_NORM( r0 * cPI1_8 - r1 * cPI3_8 );
  101938. x[13] = MULT_NORM( r0 * cPI3_8 + r1 * cPI1_8 );
  101939. r0 = x[26] - x[10];
  101940. r1 = x[27] - x[11];
  101941. x[26] += x[10];
  101942. x[27] += x[11];
  101943. x[10] = MULT_NORM(( r0 - r1 ) * cPI2_8);
  101944. x[11] = MULT_NORM(( r0 + r1 ) * cPI2_8);
  101945. r0 = x[24] - x[8];
  101946. r1 = x[25] - x[9];
  101947. x[24] += x[8];
  101948. x[25] += x[9];
  101949. x[8] = MULT_NORM( r0 * cPI3_8 - r1 * cPI1_8 );
  101950. x[9] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  101951. r0 = x[22] - x[6];
  101952. r1 = x[7] - x[23];
  101953. x[22] += x[6];
  101954. x[23] += x[7];
  101955. x[6] = r1;
  101956. x[7] = r0;
  101957. r0 = x[4] - x[20];
  101958. r1 = x[5] - x[21];
  101959. x[20] += x[4];
  101960. x[21] += x[5];
  101961. x[4] = MULT_NORM( r1 * cPI1_8 + r0 * cPI3_8 );
  101962. x[5] = MULT_NORM( r1 * cPI3_8 - r0 * cPI1_8 );
  101963. r0 = x[2] - x[18];
  101964. r1 = x[3] - x[19];
  101965. x[18] += x[2];
  101966. x[19] += x[3];
  101967. x[2] = MULT_NORM(( r1 + r0 ) * cPI2_8);
  101968. x[3] = MULT_NORM(( r1 - r0 ) * cPI2_8);
  101969. r0 = x[0] - x[16];
  101970. r1 = x[1] - x[17];
  101971. x[16] += x[0];
  101972. x[17] += x[1];
  101973. x[0] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  101974. x[1] = MULT_NORM( r1 * cPI1_8 - r0 * cPI3_8 );
  101975. mdct_butterfly_16(x);
  101976. mdct_butterfly_16(x+16);
  101977. }
  101978. STIN void mdct_butterfly_first(DATA_TYPE *T,
  101979. DATA_TYPE *x,
  101980. int points){
  101981. DATA_TYPE *x1 = x + points - 8;
  101982. DATA_TYPE *x2 = x + (points>>1) - 8;
  101983. REG_TYPE r0;
  101984. REG_TYPE r1;
  101985. do{
  101986. r0 = x1[6] - x2[6];
  101987. r1 = x1[7] - x2[7];
  101988. x1[6] += x2[6];
  101989. x1[7] += x2[7];
  101990. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  101991. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  101992. r0 = x1[4] - x2[4];
  101993. r1 = x1[5] - x2[5];
  101994. x1[4] += x2[4];
  101995. x1[5] += x2[5];
  101996. x2[4] = MULT_NORM(r1 * T[5] + r0 * T[4]);
  101997. x2[5] = MULT_NORM(r1 * T[4] - r0 * T[5]);
  101998. r0 = x1[2] - x2[2];
  101999. r1 = x1[3] - x2[3];
  102000. x1[2] += x2[2];
  102001. x1[3] += x2[3];
  102002. x2[2] = MULT_NORM(r1 * T[9] + r0 * T[8]);
  102003. x2[3] = MULT_NORM(r1 * T[8] - r0 * T[9]);
  102004. r0 = x1[0] - x2[0];
  102005. r1 = x1[1] - x2[1];
  102006. x1[0] += x2[0];
  102007. x1[1] += x2[1];
  102008. x2[0] = MULT_NORM(r1 * T[13] + r0 * T[12]);
  102009. x2[1] = MULT_NORM(r1 * T[12] - r0 * T[13]);
  102010. x1-=8;
  102011. x2-=8;
  102012. T+=16;
  102013. }while(x2>=x);
  102014. }
  102015. STIN void mdct_butterfly_generic(DATA_TYPE *T,
  102016. DATA_TYPE *x,
  102017. int points,
  102018. int trigint){
  102019. DATA_TYPE *x1 = x + points - 8;
  102020. DATA_TYPE *x2 = x + (points>>1) - 8;
  102021. REG_TYPE r0;
  102022. REG_TYPE r1;
  102023. do{
  102024. r0 = x1[6] - x2[6];
  102025. r1 = x1[7] - x2[7];
  102026. x1[6] += x2[6];
  102027. x1[7] += x2[7];
  102028. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102029. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102030. T+=trigint;
  102031. r0 = x1[4] - x2[4];
  102032. r1 = x1[5] - x2[5];
  102033. x1[4] += x2[4];
  102034. x1[5] += x2[5];
  102035. x2[4] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102036. x2[5] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102037. T+=trigint;
  102038. r0 = x1[2] - x2[2];
  102039. r1 = x1[3] - x2[3];
  102040. x1[2] += x2[2];
  102041. x1[3] += x2[3];
  102042. x2[2] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102043. x2[3] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102044. T+=trigint;
  102045. r0 = x1[0] - x2[0];
  102046. r1 = x1[1] - x2[1];
  102047. x1[0] += x2[0];
  102048. x1[1] += x2[1];
  102049. x2[0] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102050. x2[1] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102051. T+=trigint;
  102052. x1-=8;
  102053. x2-=8;
  102054. }while(x2>=x);
  102055. }
  102056. STIN void mdct_butterflies(mdct_lookup *init,
  102057. DATA_TYPE *x,
  102058. int points){
  102059. DATA_TYPE *T=init->trig;
  102060. int stages=init->log2n-5;
  102061. int i,j;
  102062. if(--stages>0){
  102063. mdct_butterfly_first(T,x,points);
  102064. }
  102065. for(i=1;--stages>0;i++){
  102066. for(j=0;j<(1<<i);j++)
  102067. mdct_butterfly_generic(T,x+(points>>i)*j,points>>i,4<<i);
  102068. }
  102069. for(j=0;j<points;j+=32)
  102070. mdct_butterfly_32(x+j);
  102071. }
  102072. void mdct_clear(mdct_lookup *l){
  102073. if(l){
  102074. if(l->trig)_ogg_free(l->trig);
  102075. if(l->bitrev)_ogg_free(l->bitrev);
  102076. memset(l,0,sizeof(*l));
  102077. }
  102078. }
  102079. STIN void mdct_bitreverse(mdct_lookup *init,
  102080. DATA_TYPE *x){
  102081. int n = init->n;
  102082. int *bit = init->bitrev;
  102083. DATA_TYPE *w0 = x;
  102084. DATA_TYPE *w1 = x = w0+(n>>1);
  102085. DATA_TYPE *T = init->trig+n;
  102086. do{
  102087. DATA_TYPE *x0 = x+bit[0];
  102088. DATA_TYPE *x1 = x+bit[1];
  102089. REG_TYPE r0 = x0[1] - x1[1];
  102090. REG_TYPE r1 = x0[0] + x1[0];
  102091. REG_TYPE r2 = MULT_NORM(r1 * T[0] + r0 * T[1]);
  102092. REG_TYPE r3 = MULT_NORM(r1 * T[1] - r0 * T[0]);
  102093. w1 -= 4;
  102094. r0 = HALVE(x0[1] + x1[1]);
  102095. r1 = HALVE(x0[0] - x1[0]);
  102096. w0[0] = r0 + r2;
  102097. w1[2] = r0 - r2;
  102098. w0[1] = r1 + r3;
  102099. w1[3] = r3 - r1;
  102100. x0 = x+bit[2];
  102101. x1 = x+bit[3];
  102102. r0 = x0[1] - x1[1];
  102103. r1 = x0[0] + x1[0];
  102104. r2 = MULT_NORM(r1 * T[2] + r0 * T[3]);
  102105. r3 = MULT_NORM(r1 * T[3] - r0 * T[2]);
  102106. r0 = HALVE(x0[1] + x1[1]);
  102107. r1 = HALVE(x0[0] - x1[0]);
  102108. w0[2] = r0 + r2;
  102109. w1[0] = r0 - r2;
  102110. w0[3] = r1 + r3;
  102111. w1[1] = r3 - r1;
  102112. T += 4;
  102113. bit += 4;
  102114. w0 += 4;
  102115. }while(w0<w1);
  102116. }
  102117. void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102118. int n=init->n;
  102119. int n2=n>>1;
  102120. int n4=n>>2;
  102121. DATA_TYPE *iX = in+n2-7;
  102122. DATA_TYPE *oX = out+n2+n4;
  102123. DATA_TYPE *T = init->trig+n4;
  102124. do{
  102125. oX -= 4;
  102126. oX[0] = MULT_NORM(-iX[2] * T[3] - iX[0] * T[2]);
  102127. oX[1] = MULT_NORM (iX[0] * T[3] - iX[2] * T[2]);
  102128. oX[2] = MULT_NORM(-iX[6] * T[1] - iX[4] * T[0]);
  102129. oX[3] = MULT_NORM (iX[4] * T[1] - iX[6] * T[0]);
  102130. iX -= 8;
  102131. T += 4;
  102132. }while(iX>=in);
  102133. iX = in+n2-8;
  102134. oX = out+n2+n4;
  102135. T = init->trig+n4;
  102136. do{
  102137. T -= 4;
  102138. oX[0] = MULT_NORM (iX[4] * T[3] + iX[6] * T[2]);
  102139. oX[1] = MULT_NORM (iX[4] * T[2] - iX[6] * T[3]);
  102140. oX[2] = MULT_NORM (iX[0] * T[1] + iX[2] * T[0]);
  102141. oX[3] = MULT_NORM (iX[0] * T[0] - iX[2] * T[1]);
  102142. iX -= 8;
  102143. oX += 4;
  102144. }while(iX>=in);
  102145. mdct_butterflies(init,out+n2,n2);
  102146. mdct_bitreverse(init,out);
  102147. {
  102148. DATA_TYPE *oX1=out+n2+n4;
  102149. DATA_TYPE *oX2=out+n2+n4;
  102150. DATA_TYPE *iX =out;
  102151. T =init->trig+n2;
  102152. do{
  102153. oX1-=4;
  102154. oX1[3] = MULT_NORM (iX[0] * T[1] - iX[1] * T[0]);
  102155. oX2[0] = -MULT_NORM (iX[0] * T[0] + iX[1] * T[1]);
  102156. oX1[2] = MULT_NORM (iX[2] * T[3] - iX[3] * T[2]);
  102157. oX2[1] = -MULT_NORM (iX[2] * T[2] + iX[3] * T[3]);
  102158. oX1[1] = MULT_NORM (iX[4] * T[5] - iX[5] * T[4]);
  102159. oX2[2] = -MULT_NORM (iX[4] * T[4] + iX[5] * T[5]);
  102160. oX1[0] = MULT_NORM (iX[6] * T[7] - iX[7] * T[6]);
  102161. oX2[3] = -MULT_NORM (iX[6] * T[6] + iX[7] * T[7]);
  102162. oX2+=4;
  102163. iX += 8;
  102164. T += 8;
  102165. }while(iX<oX1);
  102166. iX=out+n2+n4;
  102167. oX1=out+n4;
  102168. oX2=oX1;
  102169. do{
  102170. oX1-=4;
  102171. iX-=4;
  102172. oX2[0] = -(oX1[3] = iX[3]);
  102173. oX2[1] = -(oX1[2] = iX[2]);
  102174. oX2[2] = -(oX1[1] = iX[1]);
  102175. oX2[3] = -(oX1[0] = iX[0]);
  102176. oX2+=4;
  102177. }while(oX2<iX);
  102178. iX=out+n2+n4;
  102179. oX1=out+n2+n4;
  102180. oX2=out+n2;
  102181. do{
  102182. oX1-=4;
  102183. oX1[0]= iX[3];
  102184. oX1[1]= iX[2];
  102185. oX1[2]= iX[1];
  102186. oX1[3]= iX[0];
  102187. iX+=4;
  102188. }while(oX1>oX2);
  102189. }
  102190. }
  102191. void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102192. int n=init->n;
  102193. int n2=n>>1;
  102194. int n4=n>>2;
  102195. int n8=n>>3;
  102196. DATA_TYPE *w=(DATA_TYPE*) alloca(n*sizeof(*w)); /* forward needs working space */
  102197. DATA_TYPE *w2=w+n2;
  102198. REG_TYPE r0;
  102199. REG_TYPE r1;
  102200. DATA_TYPE *x0=in+n2+n4;
  102201. DATA_TYPE *x1=x0+1;
  102202. DATA_TYPE *T=init->trig+n2;
  102203. int i=0;
  102204. for(i=0;i<n8;i+=2){
  102205. x0 -=4;
  102206. T-=2;
  102207. r0= x0[2] + x1[0];
  102208. r1= x0[0] + x1[2];
  102209. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102210. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102211. x1 +=4;
  102212. }
  102213. x1=in+1;
  102214. for(;i<n2-n8;i+=2){
  102215. T-=2;
  102216. x0 -=4;
  102217. r0= x0[2] - x1[0];
  102218. r1= x0[0] - x1[2];
  102219. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102220. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102221. x1 +=4;
  102222. }
  102223. x0=in+n;
  102224. for(;i<n2;i+=2){
  102225. T-=2;
  102226. x0 -=4;
  102227. r0= -x0[2] - x1[0];
  102228. r1= -x0[0] - x1[2];
  102229. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102230. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102231. x1 +=4;
  102232. }
  102233. mdct_butterflies(init,w+n2,n2);
  102234. mdct_bitreverse(init,w);
  102235. T=init->trig+n2;
  102236. x0=out+n2;
  102237. for(i=0;i<n4;i++){
  102238. x0--;
  102239. out[i] =MULT_NORM((w[0]*T[0]+w[1]*T[1])*init->scale);
  102240. x0[0] =MULT_NORM((w[0]*T[1]-w[1]*T[0])*init->scale);
  102241. w+=2;
  102242. T+=2;
  102243. }
  102244. }
  102245. #endif
  102246. /*** End of inlined file: mdct.c ***/
  102247. /*** Start of inlined file: psy.c ***/
  102248. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  102249. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  102250. // tasks..
  102251. #if JUCE_MSVC
  102252. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  102253. #endif
  102254. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  102255. #if JUCE_USE_OGGVORBIS
  102256. #include <stdlib.h>
  102257. #include <math.h>
  102258. #include <string.h>
  102259. /*** Start of inlined file: masking.h ***/
  102260. #ifndef _V_MASKING_H_
  102261. #define _V_MASKING_H_
  102262. #define MAX_ATH 88
  102263. static float ATH[]={
  102264. -51, -52, -53, -54, -55, -56, -57, -58,
  102265. -59, -60, -61, -62, -63, -64, -65, -66,
  102266. -67, -68, -69, -70, -71, -72, -73, -74,
  102267. -75, -76, -77, -78, -80, -81, -82, -83,
  102268. -84, -85, -86, -87, -88, -88, -89, -89,
  102269. -90, -91, -91, -92, -93, -94, -95, -96,
  102270. -96, -97, -98, -98, -99, -99,-100,-100,
  102271. -101,-102,-103,-104,-106,-107,-107,-107,
  102272. -107,-105,-103,-102,-101, -99, -98, -96,
  102273. -95, -95, -96, -97, -96, -95, -93, -90,
  102274. -80, -70, -50, -40, -30, -30, -30, -30
  102275. };
  102276. #define EHMER_OFFSET 16
  102277. #define EHMER_MAX 56
  102278. static float tonemasks[P_BANDS][6][EHMER_MAX]={
  102279. {{ -60, -60, -60, -60, -60, -60, -60, -60,
  102280. -60, -60, -60, -60, -62, -62, -65, -73,
  102281. -69, -68, -68, -67, -70, -70, -72, -74,
  102282. -75, -79, -79, -80, -83, -88, -93, -100,
  102283. -110, -999, -999, -999, -999, -999, -999, -999,
  102284. -999, -999, -999, -999, -999, -999, -999, -999,
  102285. -999, -999, -999, -999, -999, -999, -999, -999},
  102286. { -48, -48, -48, -48, -48, -48, -48, -48,
  102287. -48, -48, -48, -48, -48, -53, -61, -66,
  102288. -66, -68, -67, -70, -76, -76, -72, -73,
  102289. -75, -76, -78, -79, -83, -88, -93, -100,
  102290. -110, -999, -999, -999, -999, -999, -999, -999,
  102291. -999, -999, -999, -999, -999, -999, -999, -999,
  102292. -999, -999, -999, -999, -999, -999, -999, -999},
  102293. { -37, -37, -37, -37, -37, -37, -37, -37,
  102294. -38, -40, -42, -46, -48, -53, -55, -62,
  102295. -65, -58, -56, -56, -61, -60, -65, -67,
  102296. -69, -71, -77, -77, -78, -80, -82, -84,
  102297. -88, -93, -98, -106, -112, -999, -999, -999,
  102298. -999, -999, -999, -999, -999, -999, -999, -999,
  102299. -999, -999, -999, -999, -999, -999, -999, -999},
  102300. { -25, -25, -25, -25, -25, -25, -25, -25,
  102301. -25, -26, -27, -29, -32, -38, -48, -52,
  102302. -52, -50, -48, -48, -51, -52, -54, -60,
  102303. -67, -67, -66, -68, -69, -73, -73, -76,
  102304. -80, -81, -81, -85, -85, -86, -88, -93,
  102305. -100, -110, -999, -999, -999, -999, -999, -999,
  102306. -999, -999, -999, -999, -999, -999, -999, -999},
  102307. { -16, -16, -16, -16, -16, -16, -16, -16,
  102308. -17, -19, -20, -22, -26, -28, -31, -40,
  102309. -47, -39, -39, -40, -42, -43, -47, -51,
  102310. -57, -52, -55, -55, -60, -58, -62, -63,
  102311. -70, -67, -69, -72, -73, -77, -80, -82,
  102312. -83, -87, -90, -94, -98, -104, -115, -999,
  102313. -999, -999, -999, -999, -999, -999, -999, -999},
  102314. { -8, -8, -8, -8, -8, -8, -8, -8,
  102315. -8, -8, -10, -11, -15, -19, -25, -30,
  102316. -34, -31, -30, -31, -29, -32, -35, -42,
  102317. -48, -42, -44, -46, -50, -50, -51, -52,
  102318. -59, -54, -55, -55, -58, -62, -63, -66,
  102319. -72, -73, -76, -75, -78, -80, -80, -81,
  102320. -84, -88, -90, -94, -98, -101, -106, -110}},
  102321. {{ -66, -66, -66, -66, -66, -66, -66, -66,
  102322. -66, -66, -66, -66, -66, -67, -67, -67,
  102323. -76, -72, -71, -74, -76, -76, -75, -78,
  102324. -79, -79, -81, -83, -86, -89, -93, -97,
  102325. -100, -105, -110, -999, -999, -999, -999, -999,
  102326. -999, -999, -999, -999, -999, -999, -999, -999,
  102327. -999, -999, -999, -999, -999, -999, -999, -999},
  102328. { -47, -47, -47, -47, -47, -47, -47, -47,
  102329. -47, -47, -47, -48, -51, -55, -59, -66,
  102330. -66, -66, -67, -66, -68, -69, -70, -74,
  102331. -79, -77, -77, -78, -80, -81, -82, -84,
  102332. -86, -88, -91, -95, -100, -108, -116, -999,
  102333. -999, -999, -999, -999, -999, -999, -999, -999,
  102334. -999, -999, -999, -999, -999, -999, -999, -999},
  102335. { -36, -36, -36, -36, -36, -36, -36, -36,
  102336. -36, -37, -37, -41, -44, -48, -51, -58,
  102337. -62, -60, -57, -59, -59, -60, -63, -65,
  102338. -72, -71, -70, -72, -74, -77, -76, -78,
  102339. -81, -81, -80, -83, -86, -91, -96, -100,
  102340. -105, -110, -999, -999, -999, -999, -999, -999,
  102341. -999, -999, -999, -999, -999, -999, -999, -999},
  102342. { -28, -28, -28, -28, -28, -28, -28, -28,
  102343. -28, -30, -32, -32, -33, -35, -41, -49,
  102344. -50, -49, -47, -48, -48, -52, -51, -57,
  102345. -65, -61, -59, -61, -64, -69, -70, -74,
  102346. -77, -77, -78, -81, -84, -85, -87, -90,
  102347. -92, -96, -100, -107, -112, -999, -999, -999,
  102348. -999, -999, -999, -999, -999, -999, -999, -999},
  102349. { -19, -19, -19, -19, -19, -19, -19, -19,
  102350. -20, -21, -23, -27, -30, -35, -36, -41,
  102351. -46, -44, -42, -40, -41, -41, -43, -48,
  102352. -55, -53, -52, -53, -56, -59, -58, -60,
  102353. -67, -66, -69, -71, -72, -75, -79, -81,
  102354. -84, -87, -90, -93, -97, -101, -107, -114,
  102355. -999, -999, -999, -999, -999, -999, -999, -999},
  102356. { -9, -9, -9, -9, -9, -9, -9, -9,
  102357. -11, -12, -12, -15, -16, -20, -23, -30,
  102358. -37, -34, -33, -34, -31, -32, -32, -38,
  102359. -47, -44, -41, -40, -47, -49, -46, -46,
  102360. -58, -50, -50, -54, -58, -62, -64, -67,
  102361. -67, -70, -72, -76, -79, -83, -87, -91,
  102362. -96, -100, -104, -110, -999, -999, -999, -999}},
  102363. {{ -62, -62, -62, -62, -62, -62, -62, -62,
  102364. -62, -62, -63, -64, -66, -67, -66, -68,
  102365. -75, -72, -76, -75, -76, -78, -79, -82,
  102366. -84, -85, -90, -94, -101, -110, -999, -999,
  102367. -999, -999, -999, -999, -999, -999, -999, -999,
  102368. -999, -999, -999, -999, -999, -999, -999, -999,
  102369. -999, -999, -999, -999, -999, -999, -999, -999},
  102370. { -59, -59, -59, -59, -59, -59, -59, -59,
  102371. -59, -59, -59, -60, -60, -61, -63, -66,
  102372. -71, -68, -70, -70, -71, -72, -72, -75,
  102373. -81, -78, -79, -82, -83, -86, -90, -97,
  102374. -103, -113, -999, -999, -999, -999, -999, -999,
  102375. -999, -999, -999, -999, -999, -999, -999, -999,
  102376. -999, -999, -999, -999, -999, -999, -999, -999},
  102377. { -53, -53, -53, -53, -53, -53, -53, -53,
  102378. -53, -54, -55, -57, -56, -57, -55, -61,
  102379. -65, -60, -60, -62, -63, -63, -66, -68,
  102380. -74, -73, -75, -75, -78, -80, -80, -82,
  102381. -85, -90, -96, -101, -108, -999, -999, -999,
  102382. -999, -999, -999, -999, -999, -999, -999, -999,
  102383. -999, -999, -999, -999, -999, -999, -999, -999},
  102384. { -46, -46, -46, -46, -46, -46, -46, -46,
  102385. -46, -46, -47, -47, -47, -47, -48, -51,
  102386. -57, -51, -49, -50, -51, -53, -54, -59,
  102387. -66, -60, -62, -67, -67, -70, -72, -75,
  102388. -76, -78, -81, -85, -88, -94, -97, -104,
  102389. -112, -999, -999, -999, -999, -999, -999, -999,
  102390. -999, -999, -999, -999, -999, -999, -999, -999},
  102391. { -36, -36, -36, -36, -36, -36, -36, -36,
  102392. -39, -41, -42, -42, -39, -38, -41, -43,
  102393. -52, -44, -40, -39, -37, -37, -40, -47,
  102394. -54, -50, -48, -50, -55, -61, -59, -62,
  102395. -66, -66, -66, -69, -69, -73, -74, -74,
  102396. -75, -77, -79, -82, -87, -91, -95, -100,
  102397. -108, -115, -999, -999, -999, -999, -999, -999},
  102398. { -28, -26, -24, -22, -20, -20, -23, -29,
  102399. -30, -31, -28, -27, -28, -28, -28, -35,
  102400. -40, -33, -32, -29, -30, -30, -30, -37,
  102401. -45, -41, -37, -38, -45, -47, -47, -48,
  102402. -53, -49, -48, -50, -49, -49, -51, -52,
  102403. -58, -56, -57, -56, -60, -61, -62, -70,
  102404. -72, -74, -78, -83, -88, -93, -100, -106}},
  102405. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102406. -999, -110, -105, -100, -95, -91, -87, -83,
  102407. -80, -78, -76, -78, -78, -81, -83, -85,
  102408. -86, -85, -86, -87, -90, -97, -107, -999,
  102409. -999, -999, -999, -999, -999, -999, -999, -999,
  102410. -999, -999, -999, -999, -999, -999, -999, -999,
  102411. -999, -999, -999, -999, -999, -999, -999, -999},
  102412. {-999, -999, -999, -110, -105, -100, -95, -90,
  102413. -85, -81, -77, -73, -70, -67, -67, -68,
  102414. -75, -73, -70, -69, -70, -72, -75, -79,
  102415. -84, -83, -84, -86, -88, -89, -89, -93,
  102416. -98, -105, -112, -999, -999, -999, -999, -999,
  102417. -999, -999, -999, -999, -999, -999, -999, -999,
  102418. -999, -999, -999, -999, -999, -999, -999, -999},
  102419. {-105, -100, -95, -90, -85, -80, -76, -71,
  102420. -68, -68, -65, -63, -63, -62, -62, -64,
  102421. -65, -64, -61, -62, -63, -64, -66, -68,
  102422. -73, -73, -74, -75, -76, -81, -83, -85,
  102423. -88, -89, -92, -95, -100, -108, -999, -999,
  102424. -999, -999, -999, -999, -999, -999, -999, -999,
  102425. -999, -999, -999, -999, -999, -999, -999, -999},
  102426. { -80, -75, -71, -68, -65, -63, -62, -61,
  102427. -61, -61, -61, -59, -56, -57, -53, -50,
  102428. -58, -52, -50, -50, -52, -53, -54, -58,
  102429. -67, -63, -67, -68, -72, -75, -78, -80,
  102430. -81, -81, -82, -85, -89, -90, -93, -97,
  102431. -101, -107, -114, -999, -999, -999, -999, -999,
  102432. -999, -999, -999, -999, -999, -999, -999, -999},
  102433. { -65, -61, -59, -57, -56, -55, -55, -56,
  102434. -56, -57, -55, -53, -52, -47, -44, -44,
  102435. -50, -44, -41, -39, -39, -42, -40, -46,
  102436. -51, -49, -50, -53, -54, -63, -60, -61,
  102437. -62, -66, -66, -66, -70, -73, -74, -75,
  102438. -76, -75, -79, -85, -89, -91, -96, -102,
  102439. -110, -999, -999, -999, -999, -999, -999, -999},
  102440. { -52, -50, -49, -49, -48, -48, -48, -49,
  102441. -50, -50, -49, -46, -43, -39, -35, -33,
  102442. -38, -36, -32, -29, -32, -32, -32, -35,
  102443. -44, -39, -38, -38, -46, -50, -45, -46,
  102444. -53, -50, -50, -50, -54, -54, -53, -53,
  102445. -56, -57, -59, -66, -70, -72, -74, -79,
  102446. -83, -85, -90, -97, -114, -999, -999, -999}},
  102447. {{-999, -999, -999, -999, -999, -999, -110, -105,
  102448. -100, -95, -90, -86, -80, -75, -75, -79,
  102449. -80, -79, -80, -81, -82, -88, -95, -103,
  102450. -110, -999, -999, -999, -999, -999, -999, -999,
  102451. -999, -999, -999, -999, -999, -999, -999, -999,
  102452. -999, -999, -999, -999, -999, -999, -999, -999,
  102453. -999, -999, -999, -999, -999, -999, -999, -999},
  102454. {-999, -999, -999, -999, -108, -103, -98, -93,
  102455. -88, -83, -79, -78, -75, -71, -67, -68,
  102456. -73, -73, -72, -73, -75, -77, -80, -82,
  102457. -88, -93, -100, -107, -114, -999, -999, -999,
  102458. -999, -999, -999, -999, -999, -999, -999, -999,
  102459. -999, -999, -999, -999, -999, -999, -999, -999,
  102460. -999, -999, -999, -999, -999, -999, -999, -999},
  102461. {-999, -999, -999, -110, -105, -101, -96, -90,
  102462. -86, -81, -77, -73, -69, -66, -61, -62,
  102463. -66, -64, -62, -65, -66, -70, -72, -76,
  102464. -81, -80, -84, -90, -95, -102, -110, -999,
  102465. -999, -999, -999, -999, -999, -999, -999, -999,
  102466. -999, -999, -999, -999, -999, -999, -999, -999,
  102467. -999, -999, -999, -999, -999, -999, -999, -999},
  102468. {-999, -999, -999, -107, -103, -97, -92, -88,
  102469. -83, -79, -74, -70, -66, -59, -53, -58,
  102470. -62, -55, -54, -54, -54, -58, -61, -62,
  102471. -72, -70, -72, -75, -78, -80, -81, -80,
  102472. -83, -83, -88, -93, -100, -107, -115, -999,
  102473. -999, -999, -999, -999, -999, -999, -999, -999,
  102474. -999, -999, -999, -999, -999, -999, -999, -999},
  102475. {-999, -999, -999, -105, -100, -95, -90, -85,
  102476. -80, -75, -70, -66, -62, -56, -48, -44,
  102477. -48, -46, -46, -43, -46, -48, -48, -51,
  102478. -58, -58, -59, -60, -62, -62, -61, -61,
  102479. -65, -64, -65, -68, -70, -74, -75, -78,
  102480. -81, -86, -95, -110, -999, -999, -999, -999,
  102481. -999, -999, -999, -999, -999, -999, -999, -999},
  102482. {-999, -999, -105, -100, -95, -90, -85, -80,
  102483. -75, -70, -65, -61, -55, -49, -39, -33,
  102484. -40, -35, -32, -38, -40, -33, -35, -37,
  102485. -46, -41, -45, -44, -46, -42, -45, -46,
  102486. -52, -50, -50, -50, -54, -54, -55, -57,
  102487. -62, -64, -66, -68, -70, -76, -81, -90,
  102488. -100, -110, -999, -999, -999, -999, -999, -999}},
  102489. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102490. -105, -98, -90, -85, -82, -83, -80, -78,
  102491. -84, -79, -80, -83, -87, -89, -91, -93,
  102492. -99, -106, -117, -999, -999, -999, -999, -999,
  102493. -999, -999, -999, -999, -999, -999, -999, -999,
  102494. -999, -999, -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. -105, -98, -90, -85, -80, -75, -70, -68,
  102498. -74, -72, -74, -77, -80, -82, -85, -87,
  102499. -92, -89, -91, -95, -100, -106, -112, -999,
  102500. -999, -999, -999, -999, -999, -999, -999, -999,
  102501. -999, -999, -999, -999, -999, -999, -999, -999,
  102502. -999, -999, -999, -999, -999, -999, -999, -999},
  102503. {-999, -999, -999, -999, -999, -999, -999, -999,
  102504. -105, -98, -90, -83, -75, -71, -63, -64,
  102505. -67, -62, -64, -67, -70, -73, -77, -81,
  102506. -84, -83, -85, -89, -90, -93, -98, -104,
  102507. -109, -114, -999, -999, -999, -999, -999, -999,
  102508. -999, -999, -999, -999, -999, -999, -999, -999,
  102509. -999, -999, -999, -999, -999, -999, -999, -999},
  102510. {-999, -999, -999, -999, -999, -999, -999, -999,
  102511. -103, -96, -88, -81, -75, -68, -58, -54,
  102512. -56, -54, -56, -56, -58, -60, -63, -66,
  102513. -74, -69, -72, -72, -75, -74, -77, -81,
  102514. -81, -82, -84, -87, -93, -96, -99, -104,
  102515. -110, -999, -999, -999, -999, -999, -999, -999,
  102516. -999, -999, -999, -999, -999, -999, -999, -999},
  102517. {-999, -999, -999, -999, -999, -108, -102, -96,
  102518. -91, -85, -80, -74, -68, -60, -51, -46,
  102519. -48, -46, -43, -45, -47, -47, -49, -48,
  102520. -56, -53, -55, -58, -57, -63, -58, -60,
  102521. -66, -64, -67, -70, -70, -74, -77, -84,
  102522. -86, -89, -91, -93, -94, -101, -109, -118,
  102523. -999, -999, -999, -999, -999, -999, -999, -999},
  102524. {-999, -999, -999, -108, -103, -98, -93, -88,
  102525. -83, -78, -73, -68, -60, -53, -44, -35,
  102526. -38, -38, -34, -34, -36, -40, -41, -44,
  102527. -51, -45, -46, -47, -46, -54, -50, -49,
  102528. -50, -50, -50, -51, -54, -57, -58, -60,
  102529. -66, -66, -66, -64, -65, -68, -77, -82,
  102530. -87, -95, -110, -999, -999, -999, -999, -999}},
  102531. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102532. -107, -102, -97, -92, -87, -83, -78, -75,
  102533. -82, -79, -83, -85, -89, -92, -95, -98,
  102534. -101, -105, -109, -113, -999, -999, -999, -999,
  102535. -999, -999, -999, -999, -999, -999, -999, -999,
  102536. -999, -999, -999, -999, -999, -999, -999, -999,
  102537. -999, -999, -999, -999, -999, -999, -999, -999},
  102538. {-999, -999, -999, -999, -999, -999, -999, -106,
  102539. -100, -95, -90, -86, -81, -78, -74, -69,
  102540. -74, -74, -76, -79, -83, -84, -86, -89,
  102541. -92, -97, -93, -100, -103, -107, -110, -999,
  102542. -999, -999, -999, -999, -999, -999, -999, -999,
  102543. -999, -999, -999, -999, -999, -999, -999, -999,
  102544. -999, -999, -999, -999, -999, -999, -999, -999},
  102545. {-999, -999, -999, -999, -999, -999, -106, -100,
  102546. -95, -90, -87, -83, -80, -75, -69, -60,
  102547. -66, -66, -68, -70, -74, -78, -79, -81,
  102548. -81, -83, -84, -87, -93, -96, -99, -103,
  102549. -107, -110, -999, -999, -999, -999, -999, -999,
  102550. -999, -999, -999, -999, -999, -999, -999, -999,
  102551. -999, -999, -999, -999, -999, -999, -999, -999},
  102552. {-999, -999, -999, -999, -999, -108, -103, -98,
  102553. -93, -89, -85, -82, -78, -71, -62, -55,
  102554. -58, -58, -54, -54, -55, -59, -61, -62,
  102555. -70, -66, -66, -67, -70, -72, -75, -78,
  102556. -84, -84, -84, -88, -91, -90, -95, -98,
  102557. -102, -103, -106, -110, -999, -999, -999, -999,
  102558. -999, -999, -999, -999, -999, -999, -999, -999},
  102559. {-999, -999, -999, -999, -108, -103, -98, -94,
  102560. -90, -87, -82, -79, -73, -67, -58, -47,
  102561. -50, -45, -41, -45, -48, -44, -44, -49,
  102562. -54, -51, -48, -47, -49, -50, -51, -57,
  102563. -58, -60, -63, -69, -70, -69, -71, -74,
  102564. -78, -82, -90, -95, -101, -105, -110, -999,
  102565. -999, -999, -999, -999, -999, -999, -999, -999},
  102566. {-999, -999, -999, -105, -101, -97, -93, -90,
  102567. -85, -80, -77, -72, -65, -56, -48, -37,
  102568. -40, -36, -34, -40, -50, -47, -38, -41,
  102569. -47, -38, -35, -39, -38, -43, -40, -45,
  102570. -50, -45, -44, -47, -50, -55, -48, -48,
  102571. -52, -66, -70, -76, -82, -90, -97, -105,
  102572. -110, -999, -999, -999, -999, -999, -999, -999}},
  102573. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102574. -999, -108, -103, -98, -93, -86, -79, -76,
  102575. -83, -81, -85, -87, -89, -93, -98, -102,
  102576. -107, -112, -999, -999, -999, -999, -999, -999,
  102577. -999, -999, -999, -999, -999, -999, -999, -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, -108, -103, -98, -93, -86, -79, -71,
  102582. -77, -74, -77, -79, -81, -84, -85, -90,
  102583. -92, -93, -92, -98, -101, -108, -112, -999,
  102584. -999, -999, -999, -999, -999, -999, -999, -999,
  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. -108, -103, -98, -93, -87, -78, -68, -65,
  102589. -66, -62, -65, -67, -70, -73, -75, -78,
  102590. -82, -82, -83, -84, -91, -93, -98, -102,
  102591. -106, -110, -999, -999, -999, -999, -999, -999,
  102592. -999, -999, -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. -105, -100, -95, -90, -82, -74, -62, -57,
  102596. -58, -56, -51, -52, -52, -54, -54, -58,
  102597. -66, -59, -60, -63, -66, -69, -73, -79,
  102598. -83, -84, -80, -81, -81, -82, -88, -92,
  102599. -98, -105, -113, -999, -999, -999, -999, -999,
  102600. -999, -999, -999, -999, -999, -999, -999, -999},
  102601. {-999, -999, -999, -999, -999, -999, -999, -107,
  102602. -102, -97, -92, -84, -79, -69, -57, -47,
  102603. -52, -47, -44, -45, -50, -52, -42, -42,
  102604. -53, -43, -43, -48, -51, -56, -55, -52,
  102605. -57, -59, -61, -62, -67, -71, -78, -83,
  102606. -86, -94, -98, -103, -110, -999, -999, -999,
  102607. -999, -999, -999, -999, -999, -999, -999, -999},
  102608. {-999, -999, -999, -999, -999, -999, -105, -100,
  102609. -95, -90, -84, -78, -70, -61, -51, -41,
  102610. -40, -38, -40, -46, -52, -51, -41, -40,
  102611. -46, -40, -38, -38, -41, -46, -41, -46,
  102612. -47, -43, -43, -45, -41, -45, -56, -67,
  102613. -68, -83, -87, -90, -95, -102, -107, -113,
  102614. -999, -999, -999, -999, -999, -999, -999, -999}},
  102615. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102616. -999, -109, -105, -101, -96, -91, -84, -77,
  102617. -82, -82, -85, -89, -94, -100, -106, -110,
  102618. -999, -999, -999, -999, -999, -999, -999, -999,
  102619. -999, -999, -999, -999, -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, -106, -103, -98, -92, -85, -80, -71,
  102624. -75, -72, -76, -80, -84, -86, -89, -93,
  102625. -100, -107, -113, -999, -999, -999, -999, -999,
  102626. -999, -999, -999, -999, -999, -999, -999, -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, -107,
  102630. -104, -101, -97, -92, -88, -84, -80, -64,
  102631. -66, -63, -64, -66, -69, -73, -77, -83,
  102632. -83, -86, -91, -98, -104, -111, -999, -999,
  102633. -999, -999, -999, -999, -999, -999, -999, -999,
  102634. -999, -999, -999, -999, -999, -999, -999, -999,
  102635. -999, -999, -999, -999, -999, -999, -999, -999},
  102636. {-999, -999, -999, -999, -999, -999, -999, -107,
  102637. -104, -101, -97, -92, -90, -84, -74, -57,
  102638. -58, -52, -55, -54, -50, -52, -50, -52,
  102639. -63, -62, -69, -76, -77, -78, -78, -79,
  102640. -82, -88, -94, -100, -106, -111, -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, -106, -102,
  102644. -98, -95, -90, -85, -83, -78, -70, -50,
  102645. -50, -41, -44, -49, -47, -50, -50, -44,
  102646. -55, -46, -47, -48, -48, -54, -49, -49,
  102647. -58, -62, -71, -81, -87, -92, -97, -102,
  102648. -108, -114, -999, -999, -999, -999, -999, -999,
  102649. -999, -999, -999, -999, -999, -999, -999, -999},
  102650. {-999, -999, -999, -999, -999, -999, -106, -102,
  102651. -98, -95, -90, -85, -83, -78, -70, -45,
  102652. -43, -41, -47, -50, -51, -50, -49, -45,
  102653. -47, -41, -44, -41, -39, -43, -38, -37,
  102654. -40, -41, -44, -50, -58, -65, -73, -79,
  102655. -85, -92, -97, -101, -105, -109, -113, -999,
  102656. -999, -999, -999, -999, -999, -999, -999, -999}},
  102657. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102658. -999, -999, -999, -107, -100, -95, -87, -81,
  102659. -85, -83, -88, -93, -100, -107, -114, -999,
  102660. -999, -999, -999, -999, -999, -999, -999, -999,
  102661. -999, -999, -999, -999, -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, -107, -101, -95, -88, -83, -76,
  102666. -73, -72, -79, -84, -90, -95, -100, -105,
  102667. -110, -115, -999, -999, -999, -999, -999, -999,
  102668. -999, -999, -999, -999, -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, -104, -98, -92, -87, -81, -70,
  102673. -65, -62, -67, -71, -74, -80, -85, -91,
  102674. -95, -99, -103, -108, -111, -114, -999, -999,
  102675. -999, -999, -999, -999, -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, -103, -97, -90, -85, -76, -60,
  102680. -56, -54, -60, -62, -61, -56, -63, -65,
  102681. -73, -74, -77, -75, -78, -81, -86, -87,
  102682. -88, -91, -94, -98, -103, -110, -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, -105,
  102686. -100, -97, -92, -86, -81, -79, -70, -57,
  102687. -51, -47, -51, -58, -60, -56, -53, -50,
  102688. -58, -52, -50, -50, -53, -55, -64, -69,
  102689. -71, -85, -82, -78, -81, -85, -95, -102,
  102690. -112, -999, -999, -999, -999, -999, -999, -999,
  102691. -999, -999, -999, -999, -999, -999, -999, -999},
  102692. {-999, -999, -999, -999, -999, -999, -999, -105,
  102693. -100, -97, -92, -85, -83, -79, -72, -49,
  102694. -40, -43, -43, -54, -56, -51, -50, -40,
  102695. -43, -38, -36, -35, -37, -38, -37, -44,
  102696. -54, -60, -57, -60, -70, -75, -84, -92,
  102697. -103, -112, -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, -110, -102, -95, -89, -82,
  102701. -83, -84, -90, -92, -99, -107, -113, -999,
  102702. -999, -999, -999, -999, -999, -999, -999, -999,
  102703. -999, -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, -107, -101, -95, -89, -83, -72,
  102708. -74, -78, -85, -88, -88, -90, -92, -98,
  102709. -105, -111, -999, -999, -999, -999, -999, -999,
  102710. -999, -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, -109, -103, -97, -93, -87, -81, -70,
  102715. -70, -67, -75, -73, -76, -79, -81, -83,
  102716. -88, -89, -97, -103, -110, -999, -999, -999,
  102717. -999, -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, -107, -100, -94, -88, -83, -75, -63,
  102722. -59, -59, -63, -66, -60, -62, -67, -67,
  102723. -77, -76, -81, -88, -86, -92, -96, -102,
  102724. -109, -116, -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, -105, -98, -92, -86, -81, -73, -56,
  102729. -52, -47, -55, -60, -58, -52, -51, -45,
  102730. -49, -50, -53, -54, -61, -71, -70, -69,
  102731. -78, -79, -87, -90, -96, -104, -112, -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, -103, -96, -90, -86, -78, -70, -51,
  102736. -42, -47, -48, -55, -54, -54, -53, -42,
  102737. -35, -28, -33, -38, -37, -44, -47, -49,
  102738. -54, -63, -68, -78, -82, -89, -94, -99,
  102739. -104, -109, -114, -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, -110, -100, -90, -79,
  102743. -85, -81, -82, -82, -89, -94, -99, -103,
  102744. -109, -115, -999, -999, -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, -105, -97, -85, -72,
  102750. -74, -70, -70, -70, -76, -85, -91, -93,
  102751. -97, -103, -109, -115, -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, -112, -93, -81, -68,
  102757. -62, -60, -60, -57, -63, -70, -77, -82,
  102758. -90, -93, -98, -104, -109, -113, -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. -999, -999, -999, -113, -100, -93, -84, -63,
  102764. -58, -48, -53, -54, -52, -52, -57, -64,
  102765. -66, -76, -83, -81, -85, -85, -90, -95,
  102766. -98, -101, -103, -106, -108, -111, -999, -999,
  102767. -999, -999, -999, -999, -999, -999, -999, -999,
  102768. -999, -999, -999, -999, -999, -999, -999, -999},
  102769. {-999, -999, -999, -999, -999, -999, -999, -999,
  102770. -999, -999, -999, -105, -95, -86, -74, -53,
  102771. -50, -38, -43, -49, -43, -42, -39, -39,
  102772. -46, -52, -57, -56, -72, -69, -74, -81,
  102773. -87, -92, -94, -97, -99, -102, -105, -108,
  102774. -999, -999, -999, -999, -999, -999, -999, -999,
  102775. -999, -999, -999, -999, -999, -999, -999, -999},
  102776. {-999, -999, -999, -999, -999, -999, -999, -999,
  102777. -999, -999, -108, -99, -90, -76, -66, -45,
  102778. -43, -41, -44, -47, -43, -47, -40, -30,
  102779. -31, -31, -39, -33, -40, -41, -43, -53,
  102780. -59, -70, -73, -77, -79, -82, -84, -87,
  102781. -999, -999, -999, -999, -999, -999, -999, -999,
  102782. -999, -999, -999, -999, -999, -999, -999, -999}},
  102783. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102784. -999, -999, -999, -999, -999, -110, -91, -76,
  102785. -75, -85, -93, -98, -104, -110, -999, -999,
  102786. -999, -999, -999, -999, -999, -999, -999, -999,
  102787. -999, -999, -999, -999, -999, -999, -999, -999,
  102788. -999, -999, -999, -999, -999, -999, -999, -999,
  102789. -999, -999, -999, -999, -999, -999, -999, -999},
  102790. {-999, -999, -999, -999, -999, -999, -999, -999,
  102791. -999, -999, -999, -999, -999, -110, -91, -70,
  102792. -70, -75, -86, -89, -94, -98, -101, -106,
  102793. -110, -999, -999, -999, -999, -999, -999, -999,
  102794. -999, -999, -999, -999, -999, -999, -999, -999,
  102795. -999, -999, -999, -999, -999, -999, -999, -999,
  102796. -999, -999, -999, -999, -999, -999, -999, -999},
  102797. {-999, -999, -999, -999, -999, -999, -999, -999,
  102798. -999, -999, -999, -999, -110, -95, -80, -60,
  102799. -65, -64, -74, -83, -88, -91, -95, -99,
  102800. -103, -107, -110, -999, -999, -999, -999, -999,
  102801. -999, -999, -999, -999, -999, -999, -999, -999,
  102802. -999, -999, -999, -999, -999, -999, -999, -999,
  102803. -999, -999, -999, -999, -999, -999, -999, -999},
  102804. {-999, -999, -999, -999, -999, -999, -999, -999,
  102805. -999, -999, -999, -999, -110, -95, -80, -58,
  102806. -55, -49, -66, -68, -71, -78, -78, -80,
  102807. -88, -85, -89, -97, -100, -105, -110, -999,
  102808. -999, -999, -999, -999, -999, -999, -999, -999,
  102809. -999, -999, -999, -999, -999, -999, -999, -999,
  102810. -999, -999, -999, -999, -999, -999, -999, -999},
  102811. {-999, -999, -999, -999, -999, -999, -999, -999,
  102812. -999, -999, -999, -999, -110, -95, -80, -53,
  102813. -52, -41, -59, -59, -49, -58, -56, -63,
  102814. -86, -79, -90, -93, -98, -103, -107, -112,
  102815. -999, -999, -999, -999, -999, -999, -999, -999,
  102816. -999, -999, -999, -999, -999, -999, -999, -999,
  102817. -999, -999, -999, -999, -999, -999, -999, -999},
  102818. {-999, -999, -999, -999, -999, -999, -999, -999,
  102819. -999, -999, -999, -110, -97, -91, -73, -45,
  102820. -40, -33, -53, -61, -49, -54, -50, -50,
  102821. -60, -52, -67, -74, -81, -92, -96, -100,
  102822. -105, -110, -999, -999, -999, -999, -999, -999,
  102823. -999, -999, -999, -999, -999, -999, -999, -999,
  102824. -999, -999, -999, -999, -999, -999, -999, -999}},
  102825. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102826. -999, -999, -999, -113, -106, -99, -92, -77,
  102827. -80, -88, -97, -106, -115, -999, -999, -999,
  102828. -999, -999, -999, -999, -999, -999, -999, -999,
  102829. -999, -999, -999, -999, -999, -999, -999, -999,
  102830. -999, -999, -999, -999, -999, -999, -999, -999,
  102831. -999, -999, -999, -999, -999, -999, -999, -999},
  102832. {-999, -999, -999, -999, -999, -999, -999, -999,
  102833. -999, -999, -116, -109, -102, -95, -89, -74,
  102834. -72, -88, -87, -95, -102, -109, -116, -999,
  102835. -999, -999, -999, -999, -999, -999, -999, -999,
  102836. -999, -999, -999, -999, -999, -999, -999, -999,
  102837. -999, -999, -999, -999, -999, -999, -999, -999,
  102838. -999, -999, -999, -999, -999, -999, -999, -999},
  102839. {-999, -999, -999, -999, -999, -999, -999, -999,
  102840. -999, -999, -116, -109, -102, -95, -89, -75,
  102841. -66, -74, -77, -78, -86, -87, -90, -96,
  102842. -105, -115, -999, -999, -999, -999, -999, -999,
  102843. -999, -999, -999, -999, -999, -999, -999, -999,
  102844. -999, -999, -999, -999, -999, -999, -999, -999,
  102845. -999, -999, -999, -999, -999, -999, -999, -999},
  102846. {-999, -999, -999, -999, -999, -999, -999, -999,
  102847. -999, -999, -115, -108, -101, -94, -88, -66,
  102848. -56, -61, -70, -65, -78, -72, -83, -84,
  102849. -93, -98, -105, -110, -999, -999, -999, -999,
  102850. -999, -999, -999, -999, -999, -999, -999, -999,
  102851. -999, -999, -999, -999, -999, -999, -999, -999,
  102852. -999, -999, -999, -999, -999, -999, -999, -999},
  102853. {-999, -999, -999, -999, -999, -999, -999, -999,
  102854. -999, -999, -110, -105, -95, -89, -82, -57,
  102855. -52, -52, -59, -56, -59, -58, -69, -67,
  102856. -88, -82, -82, -89, -94, -100, -108, -999,
  102857. -999, -999, -999, -999, -999, -999, -999, -999,
  102858. -999, -999, -999, -999, -999, -999, -999, -999,
  102859. -999, -999, -999, -999, -999, -999, -999, -999},
  102860. {-999, -999, -999, -999, -999, -999, -999, -999,
  102861. -999, -110, -101, -96, -90, -83, -77, -54,
  102862. -43, -38, -50, -48, -52, -48, -42, -42,
  102863. -51, -52, -53, -59, -65, -71, -78, -85,
  102864. -95, -999, -999, -999, -999, -999, -999, -999,
  102865. -999, -999, -999, -999, -999, -999, -999, -999,
  102866. -999, -999, -999, -999, -999, -999, -999, -999}},
  102867. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102868. -999, -999, -999, -999, -120, -105, -86, -68,
  102869. -78, -79, -90, -100, -110, -999, -999, -999,
  102870. -999, -999, -999, -999, -999, -999, -999, -999,
  102871. -999, -999, -999, -999, -999, -999, -999, -999,
  102872. -999, -999, -999, -999, -999, -999, -999, -999,
  102873. -999, -999, -999, -999, -999, -999, -999, -999},
  102874. {-999, -999, -999, -999, -999, -999, -999, -999,
  102875. -999, -999, -999, -999, -120, -105, -86, -66,
  102876. -73, -77, -88, -96, -105, -115, -999, -999,
  102877. -999, -999, -999, -999, -999, -999, -999, -999,
  102878. -999, -999, -999, -999, -999, -999, -999, -999,
  102879. -999, -999, -999, -999, -999, -999, -999, -999,
  102880. -999, -999, -999, -999, -999, -999, -999, -999},
  102881. {-999, -999, -999, -999, -999, -999, -999, -999,
  102882. -999, -999, -999, -120, -105, -92, -80, -61,
  102883. -64, -68, -80, -87, -92, -100, -110, -999,
  102884. -999, -999, -999, -999, -999, -999, -999, -999,
  102885. -999, -999, -999, -999, -999, -999, -999, -999,
  102886. -999, -999, -999, -999, -999, -999, -999, -999,
  102887. -999, -999, -999, -999, -999, -999, -999, -999},
  102888. {-999, -999, -999, -999, -999, -999, -999, -999,
  102889. -999, -999, -999, -120, -104, -91, -79, -52,
  102890. -60, -54, -64, -69, -77, -80, -82, -84,
  102891. -85, -87, -88, -90, -999, -999, -999, -999,
  102892. -999, -999, -999, -999, -999, -999, -999, -999,
  102893. -999, -999, -999, -999, -999, -999, -999, -999,
  102894. -999, -999, -999, -999, -999, -999, -999, -999},
  102895. {-999, -999, -999, -999, -999, -999, -999, -999,
  102896. -999, -999, -999, -118, -100, -87, -77, -49,
  102897. -50, -44, -58, -61, -61, -67, -65, -62,
  102898. -62, -62, -65, -68, -999, -999, -999, -999,
  102899. -999, -999, -999, -999, -999, -999, -999, -999,
  102900. -999, -999, -999, -999, -999, -999, -999, -999,
  102901. -999, -999, -999, -999, -999, -999, -999, -999},
  102902. {-999, -999, -999, -999, -999, -999, -999, -999,
  102903. -999, -999, -999, -115, -98, -84, -62, -49,
  102904. -44, -38, -46, -49, -49, -46, -39, -37,
  102905. -39, -40, -42, -43, -999, -999, -999, -999,
  102906. -999, -999, -999, -999, -999, -999, -999, -999,
  102907. -999, -999, -999, -999, -999, -999, -999, -999,
  102908. -999, -999, -999, -999, -999, -999, -999, -999}},
  102909. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102910. -999, -999, -999, -999, -999, -110, -88, -74,
  102911. -77, -82, -82, -85, -90, -94, -99, -104,
  102912. -999, -999, -999, -999, -999, -999, -999, -999,
  102913. -999, -999, -999, -999, -999, -999, -999, -999,
  102914. -999, -999, -999, -999, -999, -999, -999, -999,
  102915. -999, -999, -999, -999, -999, -999, -999, -999},
  102916. {-999, -999, -999, -999, -999, -999, -999, -999,
  102917. -999, -999, -999, -999, -999, -110, -88, -66,
  102918. -70, -81, -80, -81, -84, -88, -91, -93,
  102919. -999, -999, -999, -999, -999, -999, -999, -999,
  102920. -999, -999, -999, -999, -999, -999, -999, -999,
  102921. -999, -999, -999, -999, -999, -999, -999, -999,
  102922. -999, -999, -999, -999, -999, -999, -999, -999},
  102923. {-999, -999, -999, -999, -999, -999, -999, -999,
  102924. -999, -999, -999, -999, -999, -110, -88, -61,
  102925. -63, -70, -71, -74, -77, -80, -83, -85,
  102926. -999, -999, -999, -999, -999, -999, -999, -999,
  102927. -999, -999, -999, -999, -999, -999, -999, -999,
  102928. -999, -999, -999, -999, -999, -999, -999, -999,
  102929. -999, -999, -999, -999, -999, -999, -999, -999},
  102930. {-999, -999, -999, -999, -999, -999, -999, -999,
  102931. -999, -999, -999, -999, -999, -110, -86, -62,
  102932. -63, -62, -62, -58, -52, -50, -50, -52,
  102933. -54, -999, -999, -999, -999, -999, -999, -999,
  102934. -999, -999, -999, -999, -999, -999, -999, -999,
  102935. -999, -999, -999, -999, -999, -999, -999, -999,
  102936. -999, -999, -999, -999, -999, -999, -999, -999},
  102937. {-999, -999, -999, -999, -999, -999, -999, -999,
  102938. -999, -999, -999, -999, -118, -108, -84, -53,
  102939. -50, -50, -50, -55, -47, -45, -40, -40,
  102940. -40, -999, -999, -999, -999, -999, -999, -999,
  102941. -999, -999, -999, -999, -999, -999, -999, -999,
  102942. -999, -999, -999, -999, -999, -999, -999, -999,
  102943. -999, -999, -999, -999, -999, -999, -999, -999},
  102944. {-999, -999, -999, -999, -999, -999, -999, -999,
  102945. -999, -999, -999, -999, -118, -100, -73, -43,
  102946. -37, -42, -43, -53, -38, -37, -35, -35,
  102947. -38, -999, -999, -999, -999, -999, -999, -999,
  102948. -999, -999, -999, -999, -999, -999, -999, -999,
  102949. -999, -999, -999, -999, -999, -999, -999, -999,
  102950. -999, -999, -999, -999, -999, -999, -999, -999}},
  102951. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102952. -999, -999, -999, -110, -100, -91, -84, -74,
  102953. -80, -80, -80, -80, -80, -999, -999, -999,
  102954. -999, -999, -999, -999, -999, -999, -999, -999,
  102955. -999, -999, -999, -999, -999, -999, -999, -999,
  102956. -999, -999, -999, -999, -999, -999, -999, -999,
  102957. -999, -999, -999, -999, -999, -999, -999, -999},
  102958. {-999, -999, -999, -999, -999, -999, -999, -999,
  102959. -999, -999, -999, -110, -100, -91, -84, -74,
  102960. -68, -68, -68, -68, -68, -999, -999, -999,
  102961. -999, -999, -999, -999, -999, -999, -999, -999,
  102962. -999, -999, -999, -999, -999, -999, -999, -999,
  102963. -999, -999, -999, -999, -999, -999, -999, -999,
  102964. -999, -999, -999, -999, -999, -999, -999, -999},
  102965. {-999, -999, -999, -999, -999, -999, -999, -999,
  102966. -999, -999, -999, -110, -100, -86, -78, -70,
  102967. -60, -45, -30, -21, -999, -999, -999, -999,
  102968. -999, -999, -999, -999, -999, -999, -999, -999,
  102969. -999, -999, -999, -999, -999, -999, -999, -999,
  102970. -999, -999, -999, -999, -999, -999, -999, -999,
  102971. -999, -999, -999, -999, -999, -999, -999, -999},
  102972. {-999, -999, -999, -999, -999, -999, -999, -999,
  102973. -999, -999, -999, -110, -100, -87, -78, -67,
  102974. -48, -38, -29, -21, -999, -999, -999, -999,
  102975. -999, -999, -999, -999, -999, -999, -999, -999,
  102976. -999, -999, -999, -999, -999, -999, -999, -999,
  102977. -999, -999, -999, -999, -999, -999, -999, -999,
  102978. -999, -999, -999, -999, -999, -999, -999, -999},
  102979. {-999, -999, -999, -999, -999, -999, -999, -999,
  102980. -999, -999, -999, -110, -100, -86, -69, -56,
  102981. -45, -35, -33, -29, -999, -999, -999, -999,
  102982. -999, -999, -999, -999, -999, -999, -999, -999,
  102983. -999, -999, -999, -999, -999, -999, -999, -999,
  102984. -999, -999, -999, -999, -999, -999, -999, -999,
  102985. -999, -999, -999, -999, -999, -999, -999, -999},
  102986. {-999, -999, -999, -999, -999, -999, -999, -999,
  102987. -999, -999, -999, -110, -100, -83, -71, -48,
  102988. -27, -38, -37, -34, -999, -999, -999, -999,
  102989. -999, -999, -999, -999, -999, -999, -999, -999,
  102990. -999, -999, -999, -999, -999, -999, -999, -999,
  102991. -999, -999, -999, -999, -999, -999, -999, -999,
  102992. -999, -999, -999, -999, -999, -999, -999, -999}}
  102993. };
  102994. #endif
  102995. /*** End of inlined file: masking.h ***/
  102996. #define NEGINF -9999.f
  102997. static double stereo_threshholds[]={0.0, .5, 1.0, 1.5, 2.5, 4.5, 8.5, 16.5, 9e10};
  102998. static double stereo_threshholds_limited[]={0.0, .5, 1.0, 1.5, 2.0, 2.5, 4.5, 8.5, 9e10};
  102999. vorbis_look_psy_global *_vp_global_look(vorbis_info *vi){
  103000. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  103001. vorbis_info_psy_global *gi=&ci->psy_g_param;
  103002. vorbis_look_psy_global *look=(vorbis_look_psy_global*)_ogg_calloc(1,sizeof(*look));
  103003. look->channels=vi->channels;
  103004. look->ampmax=-9999.;
  103005. look->gi=gi;
  103006. return(look);
  103007. }
  103008. void _vp_global_free(vorbis_look_psy_global *look){
  103009. if(look){
  103010. memset(look,0,sizeof(*look));
  103011. _ogg_free(look);
  103012. }
  103013. }
  103014. void _vi_gpsy_free(vorbis_info_psy_global *i){
  103015. if(i){
  103016. memset(i,0,sizeof(*i));
  103017. _ogg_free(i);
  103018. }
  103019. }
  103020. void _vi_psy_free(vorbis_info_psy *i){
  103021. if(i){
  103022. memset(i,0,sizeof(*i));
  103023. _ogg_free(i);
  103024. }
  103025. }
  103026. static void min_curve(float *c,
  103027. float *c2){
  103028. int i;
  103029. for(i=0;i<EHMER_MAX;i++)if(c2[i]<c[i])c[i]=c2[i];
  103030. }
  103031. static void max_curve(float *c,
  103032. float *c2){
  103033. int i;
  103034. for(i=0;i<EHMER_MAX;i++)if(c2[i]>c[i])c[i]=c2[i];
  103035. }
  103036. static void attenuate_curve(float *c,float att){
  103037. int i;
  103038. for(i=0;i<EHMER_MAX;i++)
  103039. c[i]+=att;
  103040. }
  103041. static float ***setup_tone_curves(float curveatt_dB[P_BANDS],float binHz,int n,
  103042. float center_boost, float center_decay_rate){
  103043. int i,j,k,m;
  103044. float ath[EHMER_MAX];
  103045. float workc[P_BANDS][P_LEVELS][EHMER_MAX];
  103046. float athc[P_LEVELS][EHMER_MAX];
  103047. float *brute_buffer=(float*) alloca(n*sizeof(*brute_buffer));
  103048. float ***ret=(float***) _ogg_malloc(sizeof(*ret)*P_BANDS);
  103049. memset(workc,0,sizeof(workc));
  103050. for(i=0;i<P_BANDS;i++){
  103051. int ath_offset=i*4;
  103052. for(j=0;j<EHMER_MAX;j++){
  103053. float min=999.;
  103054. for(k=0;k<4;k++)
  103055. if(j+k+ath_offset<MAX_ATH){
  103056. if(min>ATH[j+k+ath_offset])min=ATH[j+k+ath_offset];
  103057. }else{
  103058. if(min>ATH[MAX_ATH-1])min=ATH[MAX_ATH-1];
  103059. }
  103060. ath[j]=min;
  103061. }
  103062. for(j=0;j<6;j++)
  103063. memcpy(workc[i][j+2],tonemasks[i][j],EHMER_MAX*sizeof(*tonemasks[i][j]));
  103064. memcpy(workc[i][0],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103065. memcpy(workc[i][1],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103066. for(j=0;j<P_LEVELS;j++){
  103067. for(k=0;k<EHMER_MAX;k++){
  103068. float adj=center_boost+abs(EHMER_OFFSET-k)*center_decay_rate;
  103069. if(adj<0. && center_boost>0)adj=0.;
  103070. if(adj>0. && center_boost<0)adj=0.;
  103071. workc[i][j][k]+=adj;
  103072. }
  103073. }
  103074. for(j=0;j<P_LEVELS;j++){
  103075. attenuate_curve(workc[i][j],curveatt_dB[i]+100.-(j<2?2:j)*10.-P_LEVEL_0);
  103076. memcpy(athc[j],ath,EHMER_MAX*sizeof(**athc));
  103077. attenuate_curve(athc[j],+100.-j*10.f-P_LEVEL_0);
  103078. max_curve(athc[j],workc[i][j]);
  103079. }
  103080. for(j=1;j<P_LEVELS;j++){
  103081. min_curve(athc[j],athc[j-1]);
  103082. min_curve(workc[i][j],athc[j]);
  103083. }
  103084. }
  103085. for(i=0;i<P_BANDS;i++){
  103086. int hi_curve,lo_curve,bin;
  103087. ret[i]=(float**)_ogg_malloc(sizeof(**ret)*P_LEVELS);
  103088. bin=floor(fromOC(i*.5)/binHz);
  103089. lo_curve= ceil(toOC(bin*binHz+1)*2);
  103090. hi_curve= floor(toOC((bin+1)*binHz)*2);
  103091. if(lo_curve>i)lo_curve=i;
  103092. if(lo_curve<0)lo_curve=0;
  103093. if(hi_curve>=P_BANDS)hi_curve=P_BANDS-1;
  103094. for(m=0;m<P_LEVELS;m++){
  103095. ret[i][m]=(float*)_ogg_malloc(sizeof(***ret)*(EHMER_MAX+2));
  103096. for(j=0;j<n;j++)brute_buffer[j]=999.;
  103097. for(k=lo_curve;k<=hi_curve;k++){
  103098. int l=0;
  103099. for(j=0;j<EHMER_MAX;j++){
  103100. int lo_bin= fromOC(j*.125+k*.5-2.0625)/binHz;
  103101. int hi_bin= fromOC(j*.125+k*.5-1.9375)/binHz+1;
  103102. if(lo_bin<0)lo_bin=0;
  103103. if(lo_bin>n)lo_bin=n;
  103104. if(lo_bin<l)l=lo_bin;
  103105. if(hi_bin<0)hi_bin=0;
  103106. if(hi_bin>n)hi_bin=n;
  103107. for(;l<hi_bin && l<n;l++)
  103108. if(brute_buffer[l]>workc[k][m][j])
  103109. brute_buffer[l]=workc[k][m][j];
  103110. }
  103111. for(;l<n;l++)
  103112. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103113. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103114. }
  103115. if(i+1<P_BANDS){
  103116. int l=0;
  103117. k=i+1;
  103118. for(j=0;j<EHMER_MAX;j++){
  103119. int lo_bin= fromOC(j*.125+i*.5-2.0625)/binHz;
  103120. int hi_bin= fromOC(j*.125+i*.5-1.9375)/binHz+1;
  103121. if(lo_bin<0)lo_bin=0;
  103122. if(lo_bin>n)lo_bin=n;
  103123. if(lo_bin<l)l=lo_bin;
  103124. if(hi_bin<0)hi_bin=0;
  103125. if(hi_bin>n)hi_bin=n;
  103126. for(;l<hi_bin && l<n;l++)
  103127. if(brute_buffer[l]>workc[k][m][j])
  103128. brute_buffer[l]=workc[k][m][j];
  103129. }
  103130. for(;l<n;l++)
  103131. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103132. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103133. }
  103134. for(j=0;j<EHMER_MAX;j++){
  103135. int bin=fromOC(j*.125+i*.5-2.)/binHz;
  103136. if(bin<0){
  103137. ret[i][m][j+2]=-999.;
  103138. }else{
  103139. if(bin>=n){
  103140. ret[i][m][j+2]=-999.;
  103141. }else{
  103142. ret[i][m][j+2]=brute_buffer[bin];
  103143. }
  103144. }
  103145. }
  103146. for(j=0;j<EHMER_OFFSET;j++)
  103147. if(ret[i][m][j+2]>-200.f)break;
  103148. ret[i][m][0]=j;
  103149. for(j=EHMER_MAX-1;j>EHMER_OFFSET+1;j--)
  103150. if(ret[i][m][j+2]>-200.f)
  103151. break;
  103152. ret[i][m][1]=j;
  103153. }
  103154. }
  103155. return(ret);
  103156. }
  103157. void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  103158. vorbis_info_psy_global *gi,int n,long rate){
  103159. long i,j,lo=-99,hi=1;
  103160. long maxoc;
  103161. memset(p,0,sizeof(*p));
  103162. p->eighth_octave_lines=gi->eighth_octave_lines;
  103163. p->shiftoc=rint(log(gi->eighth_octave_lines*8.f)/log(2.f))-1;
  103164. p->firstoc=toOC(.25f*rate*.5/n)*(1<<(p->shiftoc+1))-gi->eighth_octave_lines;
  103165. maxoc=toOC((n+.25f)*rate*.5/n)*(1<<(p->shiftoc+1))+.5f;
  103166. p->total_octave_lines=maxoc-p->firstoc+1;
  103167. p->ath=(float*)_ogg_malloc(n*sizeof(*p->ath));
  103168. p->octave=(long*)_ogg_malloc(n*sizeof(*p->octave));
  103169. p->bark=(long*)_ogg_malloc(n*sizeof(*p->bark));
  103170. p->vi=vi;
  103171. p->n=n;
  103172. p->rate=rate;
  103173. p->m_val = 1.;
  103174. if(rate < 26000) p->m_val = 0;
  103175. else if(rate < 38000) p->m_val = .94; /* 32kHz */
  103176. else if(rate > 46000) p->m_val = 1.275; /* 48kHz */
  103177. for(i=0,j=0;i<MAX_ATH-1;i++){
  103178. int endpos=rint(fromOC((i+1)*.125-2.)*2*n/rate);
  103179. float base=ATH[i];
  103180. if(j<endpos){
  103181. float delta=(ATH[i+1]-base)/(endpos-j);
  103182. for(;j<endpos && j<n;j++){
  103183. p->ath[j]=base+100.;
  103184. base+=delta;
  103185. }
  103186. }
  103187. }
  103188. for(i=0;i<n;i++){
  103189. float bark=toBARK(rate/(2*n)*i);
  103190. for(;lo+vi->noisewindowlomin<i &&
  103191. toBARK(rate/(2*n)*lo)<(bark-vi->noisewindowlo);lo++);
  103192. for(;hi<=n && (hi<i+vi->noisewindowhimin ||
  103193. toBARK(rate/(2*n)*hi)<(bark+vi->noisewindowhi));hi++);
  103194. p->bark[i]=((lo-1)<<16)+(hi-1);
  103195. }
  103196. for(i=0;i<n;i++)
  103197. p->octave[i]=toOC((i+.25f)*.5*rate/n)*(1<<(p->shiftoc+1))+.5f;
  103198. p->tonecurves=setup_tone_curves(vi->toneatt,rate*.5/n,n,
  103199. vi->tone_centerboost,vi->tone_decay);
  103200. p->noiseoffset=(float**)_ogg_malloc(P_NOISECURVES*sizeof(*p->noiseoffset));
  103201. for(i=0;i<P_NOISECURVES;i++)
  103202. p->noiseoffset[i]=(float*)_ogg_malloc(n*sizeof(**p->noiseoffset));
  103203. for(i=0;i<n;i++){
  103204. float halfoc=toOC((i+.5)*rate/(2.*n))*2.;
  103205. int inthalfoc;
  103206. float del;
  103207. if(halfoc<0)halfoc=0;
  103208. if(halfoc>=P_BANDS-1)halfoc=P_BANDS-1;
  103209. inthalfoc=(int)halfoc;
  103210. del=halfoc-inthalfoc;
  103211. for(j=0;j<P_NOISECURVES;j++)
  103212. p->noiseoffset[j][i]=
  103213. p->vi->noiseoff[j][inthalfoc]*(1.-del) +
  103214. p->vi->noiseoff[j][inthalfoc+1]*del;
  103215. }
  103216. #if 0
  103217. {
  103218. static int ls=0;
  103219. _analysis_output_always("noiseoff0",ls,p->noiseoffset[0],n,1,0,0);
  103220. _analysis_output_always("noiseoff1",ls,p->noiseoffset[1],n,1,0,0);
  103221. _analysis_output_always("noiseoff2",ls++,p->noiseoffset[2],n,1,0,0);
  103222. }
  103223. #endif
  103224. }
  103225. void _vp_psy_clear(vorbis_look_psy *p){
  103226. int i,j;
  103227. if(p){
  103228. if(p->ath)_ogg_free(p->ath);
  103229. if(p->octave)_ogg_free(p->octave);
  103230. if(p->bark)_ogg_free(p->bark);
  103231. if(p->tonecurves){
  103232. for(i=0;i<P_BANDS;i++){
  103233. for(j=0;j<P_LEVELS;j++){
  103234. _ogg_free(p->tonecurves[i][j]);
  103235. }
  103236. _ogg_free(p->tonecurves[i]);
  103237. }
  103238. _ogg_free(p->tonecurves);
  103239. }
  103240. if(p->noiseoffset){
  103241. for(i=0;i<P_NOISECURVES;i++){
  103242. _ogg_free(p->noiseoffset[i]);
  103243. }
  103244. _ogg_free(p->noiseoffset);
  103245. }
  103246. memset(p,0,sizeof(*p));
  103247. }
  103248. }
  103249. static void seed_curve(float *seed,
  103250. const float **curves,
  103251. float amp,
  103252. int oc, int n,
  103253. int linesper,float dBoffset){
  103254. int i,post1;
  103255. int seedptr;
  103256. const float *posts,*curve;
  103257. int choice=(int)((amp+dBoffset-P_LEVEL_0)*.1f);
  103258. choice=max(choice,0);
  103259. choice=min(choice,P_LEVELS-1);
  103260. posts=curves[choice];
  103261. curve=posts+2;
  103262. post1=(int)posts[1];
  103263. seedptr=oc+(posts[0]-EHMER_OFFSET)*linesper-(linesper>>1);
  103264. for(i=posts[0];i<post1;i++){
  103265. if(seedptr>0){
  103266. float lin=amp+curve[i];
  103267. if(seed[seedptr]<lin)seed[seedptr]=lin;
  103268. }
  103269. seedptr+=linesper;
  103270. if(seedptr>=n)break;
  103271. }
  103272. }
  103273. static void seed_loop(vorbis_look_psy *p,
  103274. const float ***curves,
  103275. const float *f,
  103276. const float *flr,
  103277. float *seed,
  103278. float specmax){
  103279. vorbis_info_psy *vi=p->vi;
  103280. long n=p->n,i;
  103281. float dBoffset=vi->max_curve_dB-specmax;
  103282. for(i=0;i<n;i++){
  103283. float max=f[i];
  103284. long oc=p->octave[i];
  103285. while(i+1<n && p->octave[i+1]==oc){
  103286. i++;
  103287. if(f[i]>max)max=f[i];
  103288. }
  103289. if(max+6.f>flr[i]){
  103290. oc=oc>>p->shiftoc;
  103291. if(oc>=P_BANDS)oc=P_BANDS-1;
  103292. if(oc<0)oc=0;
  103293. seed_curve(seed,
  103294. curves[oc],
  103295. max,
  103296. p->octave[i]-p->firstoc,
  103297. p->total_octave_lines,
  103298. p->eighth_octave_lines,
  103299. dBoffset);
  103300. }
  103301. }
  103302. }
  103303. static void seed_chase(float *seeds, int linesper, long n){
  103304. long *posstack=(long*)alloca(n*sizeof(*posstack));
  103305. float *ampstack=(float*)alloca(n*sizeof(*ampstack));
  103306. long stack=0;
  103307. long pos=0;
  103308. long i;
  103309. for(i=0;i<n;i++){
  103310. if(stack<2){
  103311. posstack[stack]=i;
  103312. ampstack[stack++]=seeds[i];
  103313. }else{
  103314. while(1){
  103315. if(seeds[i]<ampstack[stack-1]){
  103316. posstack[stack]=i;
  103317. ampstack[stack++]=seeds[i];
  103318. break;
  103319. }else{
  103320. if(i<posstack[stack-1]+linesper){
  103321. if(stack>1 && ampstack[stack-1]<=ampstack[stack-2] &&
  103322. i<posstack[stack-2]+linesper){
  103323. stack--;
  103324. continue;
  103325. }
  103326. }
  103327. posstack[stack]=i;
  103328. ampstack[stack++]=seeds[i];
  103329. break;
  103330. }
  103331. }
  103332. }
  103333. }
  103334. for(i=0;i<stack;i++){
  103335. long endpos;
  103336. if(i<stack-1 && ampstack[i+1]>ampstack[i]){
  103337. endpos=posstack[i+1];
  103338. }else{
  103339. endpos=posstack[i]+linesper+1; /* +1 is important, else bin 0 is
  103340. discarded in short frames */
  103341. }
  103342. if(endpos>n)endpos=n;
  103343. for(;pos<endpos;pos++)
  103344. seeds[pos]=ampstack[i];
  103345. }
  103346. }
  103347. #include<stdio.h>
  103348. static void max_seeds(vorbis_look_psy *p,
  103349. float *seed,
  103350. float *flr){
  103351. long n=p->total_octave_lines;
  103352. int linesper=p->eighth_octave_lines;
  103353. long linpos=0;
  103354. long pos;
  103355. seed_chase(seed,linesper,n); /* for masking */
  103356. pos=p->octave[0]-p->firstoc-(linesper>>1);
  103357. while(linpos+1<p->n){
  103358. float minV=seed[pos];
  103359. long end=((p->octave[linpos]+p->octave[linpos+1])>>1)-p->firstoc;
  103360. if(minV>p->vi->tone_abs_limit)minV=p->vi->tone_abs_limit;
  103361. while(pos+1<=end){
  103362. pos++;
  103363. if((seed[pos]>NEGINF && seed[pos]<minV) || minV==NEGINF)
  103364. minV=seed[pos];
  103365. }
  103366. end=pos+p->firstoc;
  103367. for(;linpos<p->n && p->octave[linpos]<=end;linpos++)
  103368. if(flr[linpos]<minV)flr[linpos]=minV;
  103369. }
  103370. {
  103371. float minV=seed[p->total_octave_lines-1];
  103372. for(;linpos<p->n;linpos++)
  103373. if(flr[linpos]<minV)flr[linpos]=minV;
  103374. }
  103375. }
  103376. static void bark_noise_hybridmp(int n,const long *b,
  103377. const float *f,
  103378. float *noise,
  103379. const float offset,
  103380. const int fixed){
  103381. float *N=(float*) alloca(n*sizeof(*N));
  103382. float *X=(float*) alloca(n*sizeof(*N));
  103383. float *XX=(float*) alloca(n*sizeof(*N));
  103384. float *Y=(float*) alloca(n*sizeof(*N));
  103385. float *XY=(float*) alloca(n*sizeof(*N));
  103386. float tN, tX, tXX, tY, tXY;
  103387. int i;
  103388. int lo, hi;
  103389. float R, A, B, D;
  103390. float w, x, y;
  103391. tN = tX = tXX = tY = tXY = 0.f;
  103392. y = f[0] + offset;
  103393. if (y < 1.f) y = 1.f;
  103394. w = y * y * .5;
  103395. tN += w;
  103396. tX += w;
  103397. tY += w * y;
  103398. N[0] = tN;
  103399. X[0] = tX;
  103400. XX[0] = tXX;
  103401. Y[0] = tY;
  103402. XY[0] = tXY;
  103403. for (i = 1, x = 1.f; i < n; i++, x += 1.f) {
  103404. y = f[i] + offset;
  103405. if (y < 1.f) y = 1.f;
  103406. w = y * y;
  103407. tN += w;
  103408. tX += w * x;
  103409. tXX += w * x * x;
  103410. tY += w * y;
  103411. tXY += w * x * y;
  103412. N[i] = tN;
  103413. X[i] = tX;
  103414. XX[i] = tXX;
  103415. Y[i] = tY;
  103416. XY[i] = tXY;
  103417. }
  103418. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103419. lo = b[i] >> 16;
  103420. if( lo>=0 ) break;
  103421. hi = b[i] & 0xffff;
  103422. tN = N[hi] + N[-lo];
  103423. tX = X[hi] - X[-lo];
  103424. tXX = XX[hi] + XX[-lo];
  103425. tY = Y[hi] + Y[-lo];
  103426. tXY = XY[hi] - XY[-lo];
  103427. A = tY * tXX - tX * tXY;
  103428. B = tN * tXY - tX * tY;
  103429. D = tN * tXX - tX * tX;
  103430. R = (A + x * B) / D;
  103431. if (R < 0.f)
  103432. R = 0.f;
  103433. noise[i] = R - offset;
  103434. }
  103435. for ( ;; i++, x += 1.f) {
  103436. lo = b[i] >> 16;
  103437. hi = b[i] & 0xffff;
  103438. if(hi>=n)break;
  103439. tN = N[hi] - N[lo];
  103440. tX = X[hi] - X[lo];
  103441. tXX = XX[hi] - XX[lo];
  103442. tY = Y[hi] - Y[lo];
  103443. tXY = XY[hi] - XY[lo];
  103444. A = tY * tXX - tX * tXY;
  103445. B = tN * tXY - tX * tY;
  103446. D = tN * tXX - tX * tX;
  103447. R = (A + x * B) / D;
  103448. if (R < 0.f) R = 0.f;
  103449. noise[i] = R - offset;
  103450. }
  103451. for ( ; i < n; i++, x += 1.f) {
  103452. R = (A + x * B) / D;
  103453. if (R < 0.f) R = 0.f;
  103454. noise[i] = R - offset;
  103455. }
  103456. if (fixed <= 0) return;
  103457. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103458. hi = i + fixed / 2;
  103459. lo = hi - fixed;
  103460. if(lo>=0)break;
  103461. tN = N[hi] + N[-lo];
  103462. tX = X[hi] - X[-lo];
  103463. tXX = XX[hi] + XX[-lo];
  103464. tY = Y[hi] + Y[-lo];
  103465. tXY = XY[hi] - XY[-lo];
  103466. A = tY * tXX - tX * tXY;
  103467. B = tN * tXY - tX * tY;
  103468. D = tN * tXX - tX * tX;
  103469. R = (A + x * B) / D;
  103470. if (R - offset < noise[i]) noise[i] = R - offset;
  103471. }
  103472. for ( ;; i++, x += 1.f) {
  103473. hi = i + fixed / 2;
  103474. lo = hi - fixed;
  103475. if(hi>=n)break;
  103476. tN = N[hi] - N[lo];
  103477. tX = X[hi] - X[lo];
  103478. tXX = XX[hi] - XX[lo];
  103479. tY = Y[hi] - Y[lo];
  103480. tXY = XY[hi] - XY[lo];
  103481. A = tY * tXX - tX * tXY;
  103482. B = tN * tXY - tX * tY;
  103483. D = tN * tXX - tX * tX;
  103484. R = (A + x * B) / D;
  103485. if (R - offset < noise[i]) noise[i] = R - offset;
  103486. }
  103487. for ( ; i < n; i++, x += 1.f) {
  103488. R = (A + x * B) / D;
  103489. if (R - offset < noise[i]) noise[i] = R - offset;
  103490. }
  103491. }
  103492. static float FLOOR1_fromdB_INV_LOOKUP[256]={
  103493. 0.F, 8.81683e+06F, 8.27882e+06F, 7.77365e+06F,
  103494. 7.29930e+06F, 6.85389e+06F, 6.43567e+06F, 6.04296e+06F,
  103495. 5.67422e+06F, 5.32798e+06F, 5.00286e+06F, 4.69759e+06F,
  103496. 4.41094e+06F, 4.14178e+06F, 3.88905e+06F, 3.65174e+06F,
  103497. 3.42891e+06F, 3.21968e+06F, 3.02321e+06F, 2.83873e+06F,
  103498. 2.66551e+06F, 2.50286e+06F, 2.35014e+06F, 2.20673e+06F,
  103499. 2.07208e+06F, 1.94564e+06F, 1.82692e+06F, 1.71544e+06F,
  103500. 1.61076e+06F, 1.51247e+06F, 1.42018e+06F, 1.33352e+06F,
  103501. 1.25215e+06F, 1.17574e+06F, 1.10400e+06F, 1.03663e+06F,
  103502. 973377.F, 913981.F, 858210.F, 805842.F,
  103503. 756669.F, 710497.F, 667142.F, 626433.F,
  103504. 588208.F, 552316.F, 518613.F, 486967.F,
  103505. 457252.F, 429351.F, 403152.F, 378551.F,
  103506. 355452.F, 333762.F, 313396.F, 294273.F,
  103507. 276316.F, 259455.F, 243623.F, 228757.F,
  103508. 214798.F, 201691.F, 189384.F, 177828.F,
  103509. 166977.F, 156788.F, 147221.F, 138237.F,
  103510. 129802.F, 121881.F, 114444.F, 107461.F,
  103511. 100903.F, 94746.3F, 88964.9F, 83536.2F,
  103512. 78438.8F, 73652.5F, 69158.2F, 64938.1F,
  103513. 60975.6F, 57254.9F, 53761.2F, 50480.6F,
  103514. 47400.3F, 44507.9F, 41792.0F, 39241.9F,
  103515. 36847.3F, 34598.9F, 32487.7F, 30505.3F,
  103516. 28643.8F, 26896.0F, 25254.8F, 23713.7F,
  103517. 22266.7F, 20908.0F, 19632.2F, 18434.2F,
  103518. 17309.4F, 16253.1F, 15261.4F, 14330.1F,
  103519. 13455.7F, 12634.6F, 11863.7F, 11139.7F,
  103520. 10460.0F, 9821.72F, 9222.39F, 8659.64F,
  103521. 8131.23F, 7635.06F, 7169.17F, 6731.70F,
  103522. 6320.93F, 5935.23F, 5573.06F, 5232.99F,
  103523. 4913.67F, 4613.84F, 4332.30F, 4067.94F,
  103524. 3819.72F, 3586.64F, 3367.78F, 3162.28F,
  103525. 2969.31F, 2788.13F, 2617.99F, 2458.24F,
  103526. 2308.24F, 2167.39F, 2035.14F, 1910.95F,
  103527. 1794.35F, 1684.85F, 1582.04F, 1485.51F,
  103528. 1394.86F, 1309.75F, 1229.83F, 1154.78F,
  103529. 1084.32F, 1018.15F, 956.024F, 897.687F,
  103530. 842.910F, 791.475F, 743.179F, 697.830F,
  103531. 655.249F, 615.265F, 577.722F, 542.469F,
  103532. 509.367F, 478.286F, 449.101F, 421.696F,
  103533. 395.964F, 371.803F, 349.115F, 327.812F,
  103534. 307.809F, 289.026F, 271.390F, 254.830F,
  103535. 239.280F, 224.679F, 210.969F, 198.096F,
  103536. 186.008F, 174.658F, 164.000F, 153.993F,
  103537. 144.596F, 135.773F, 127.488F, 119.708F,
  103538. 112.404F, 105.545F, 99.1046F, 93.0572F,
  103539. 87.3788F, 82.0469F, 77.0404F, 72.3394F,
  103540. 67.9252F, 63.7804F, 59.8885F, 56.2341F,
  103541. 52.8027F, 49.5807F, 46.5553F, 43.7144F,
  103542. 41.0470F, 38.5423F, 36.1904F, 33.9821F,
  103543. 31.9085F, 29.9614F, 28.1332F, 26.4165F,
  103544. 24.8045F, 23.2910F, 21.8697F, 20.5352F,
  103545. 19.2822F, 18.1056F, 17.0008F, 15.9634F,
  103546. 14.9893F, 14.0746F, 13.2158F, 12.4094F,
  103547. 11.6522F, 10.9411F, 10.2735F, 9.64662F,
  103548. 9.05798F, 8.50526F, 7.98626F, 7.49894F,
  103549. 7.04135F, 6.61169F, 6.20824F, 5.82941F,
  103550. 5.47370F, 5.13970F, 4.82607F, 4.53158F,
  103551. 4.25507F, 3.99542F, 3.75162F, 3.52269F,
  103552. 3.30774F, 3.10590F, 2.91638F, 2.73842F,
  103553. 2.57132F, 2.41442F, 2.26709F, 2.12875F,
  103554. 1.99885F, 1.87688F, 1.76236F, 1.65482F,
  103555. 1.55384F, 1.45902F, 1.36999F, 1.28640F,
  103556. 1.20790F, 1.13419F, 1.06499F, 1.F
  103557. };
  103558. void _vp_remove_floor(vorbis_look_psy *p,
  103559. float *mdct,
  103560. int *codedflr,
  103561. float *residue,
  103562. int sliding_lowpass){
  103563. int i,n=p->n;
  103564. if(sliding_lowpass>n)sliding_lowpass=n;
  103565. for(i=0;i<sliding_lowpass;i++){
  103566. residue[i]=
  103567. mdct[i]*FLOOR1_fromdB_INV_LOOKUP[codedflr[i]];
  103568. }
  103569. for(;i<n;i++)
  103570. residue[i]=0.;
  103571. }
  103572. void _vp_noisemask(vorbis_look_psy *p,
  103573. float *logmdct,
  103574. float *logmask){
  103575. int i,n=p->n;
  103576. float *work=(float*) alloca(n*sizeof(*work));
  103577. bark_noise_hybridmp(n,p->bark,logmdct,logmask,
  103578. 140.,-1);
  103579. for(i=0;i<n;i++)work[i]=logmdct[i]-logmask[i];
  103580. bark_noise_hybridmp(n,p->bark,work,logmask,0.,
  103581. p->vi->noisewindowfixed);
  103582. for(i=0;i<n;i++)work[i]=logmdct[i]-work[i];
  103583. #if 0
  103584. {
  103585. static int seq=0;
  103586. float work2[n];
  103587. for(i=0;i<n;i++){
  103588. work2[i]=logmask[i]+work[i];
  103589. }
  103590. if(seq&1)
  103591. _analysis_output("median2R",seq/2,work,n,1,0,0);
  103592. else
  103593. _analysis_output("median2L",seq/2,work,n,1,0,0);
  103594. if(seq&1)
  103595. _analysis_output("envelope2R",seq/2,work2,n,1,0,0);
  103596. else
  103597. _analysis_output("envelope2L",seq/2,work2,n,1,0,0);
  103598. seq++;
  103599. }
  103600. #endif
  103601. for(i=0;i<n;i++){
  103602. int dB=logmask[i]+.5;
  103603. if(dB>=NOISE_COMPAND_LEVELS)dB=NOISE_COMPAND_LEVELS-1;
  103604. if(dB<0)dB=0;
  103605. logmask[i]= work[i]+p->vi->noisecompand[dB];
  103606. }
  103607. }
  103608. void _vp_tonemask(vorbis_look_psy *p,
  103609. float *logfft,
  103610. float *logmask,
  103611. float global_specmax,
  103612. float local_specmax){
  103613. int i,n=p->n;
  103614. float *seed=(float*) alloca(sizeof(*seed)*p->total_octave_lines);
  103615. float att=local_specmax+p->vi->ath_adjatt;
  103616. for(i=0;i<p->total_octave_lines;i++)seed[i]=NEGINF;
  103617. if(att<p->vi->ath_maxatt)att=p->vi->ath_maxatt;
  103618. for(i=0;i<n;i++)
  103619. logmask[i]=p->ath[i]+att;
  103620. seed_loop(p,(const float ***)p->tonecurves,logfft,logmask,seed,global_specmax);
  103621. max_seeds(p,seed,logmask);
  103622. }
  103623. void _vp_offset_and_mix(vorbis_look_psy *p,
  103624. float *noise,
  103625. float *tone,
  103626. int offset_select,
  103627. float *logmask,
  103628. float *mdct,
  103629. float *logmdct){
  103630. int i,n=p->n;
  103631. float de, coeffi, cx;/* AoTuV */
  103632. float toneatt=p->vi->tone_masteratt[offset_select];
  103633. cx = p->m_val;
  103634. for(i=0;i<n;i++){
  103635. float val= noise[i]+p->noiseoffset[offset_select][i];
  103636. if(val>p->vi->noisemaxsupp)val=p->vi->noisemaxsupp;
  103637. logmask[i]=max(val,tone[i]+toneatt);
  103638. if(offset_select == 1) {
  103639. coeffi = -17.2; /* coeffi is a -17.2dB threshold */
  103640. val = val - logmdct[i]; /* val == mdct line value relative to floor in dB */
  103641. if(val > coeffi){
  103642. de = 1.0-((val-coeffi)*0.005*cx);
  103643. if(de < 0) de = 0.0001;
  103644. }else
  103645. de = 1.0-((val-coeffi)*0.0003*cx);
  103646. mdct[i] *= de;
  103647. }
  103648. }
  103649. }
  103650. float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd){
  103651. vorbis_info *vi=vd->vi;
  103652. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  103653. vorbis_info_psy_global *gi=&ci->psy_g_param;
  103654. int n=ci->blocksizes[vd->W]/2;
  103655. float secs=(float)n/vi->rate;
  103656. amp+=secs*gi->ampmax_att_per_sec;
  103657. if(amp<-9999)amp=-9999;
  103658. return(amp);
  103659. }
  103660. static void couple_lossless(float A, float B,
  103661. float *qA, float *qB){
  103662. int test1=fabs(*qA)>fabs(*qB);
  103663. test1-= fabs(*qA)<fabs(*qB);
  103664. if(!test1)test1=((fabs(A)>fabs(B))<<1)-1;
  103665. if(test1==1){
  103666. *qB=(*qA>0.f?*qA-*qB:*qB-*qA);
  103667. }else{
  103668. float temp=*qB;
  103669. *qB=(*qB>0.f?*qA-*qB:*qB-*qA);
  103670. *qA=temp;
  103671. }
  103672. if(*qB>fabs(*qA)*1.9999f){
  103673. *qB= -fabs(*qA)*2.f;
  103674. *qA= -*qA;
  103675. }
  103676. }
  103677. static float hypot_lookup[32]={
  103678. -0.009935, -0.011245, -0.012726, -0.014397,
  103679. -0.016282, -0.018407, -0.020800, -0.023494,
  103680. -0.026522, -0.029923, -0.033737, -0.038010,
  103681. -0.042787, -0.048121, -0.054064, -0.060671,
  103682. -0.068000, -0.076109, -0.085054, -0.094892,
  103683. -0.105675, -0.117451, -0.130260, -0.144134,
  103684. -0.159093, -0.175146, -0.192286, -0.210490,
  103685. -0.229718, -0.249913, -0.271001, -0.292893};
  103686. static void precomputed_couple_point(float premag,
  103687. int floorA,int floorB,
  103688. float *mag, float *ang){
  103689. int test=(floorA>floorB)-1;
  103690. int offset=31-abs(floorA-floorB);
  103691. float floormag=hypot_lookup[((offset<0)-1)&offset]+1.f;
  103692. floormag*=FLOOR1_fromdB_INV_LOOKUP[(floorB&test)|(floorA&(~test))];
  103693. *mag=premag*floormag;
  103694. *ang=0.f;
  103695. }
  103696. static float dipole_hypot(float a, float b){
  103697. if(a>0.){
  103698. if(b>0.)return sqrt(a*a+b*b);
  103699. if(a>-b)return sqrt(a*a-b*b);
  103700. return -sqrt(b*b-a*a);
  103701. }
  103702. if(b<0.)return -sqrt(a*a+b*b);
  103703. if(-a>b)return -sqrt(a*a-b*b);
  103704. return sqrt(b*b-a*a);
  103705. }
  103706. static float round_hypot(float a, float b){
  103707. if(a>0.){
  103708. if(b>0.)return sqrt(a*a+b*b);
  103709. if(a>-b)return sqrt(a*a+b*b);
  103710. return -sqrt(b*b+a*a);
  103711. }
  103712. if(b<0.)return -sqrt(a*a+b*b);
  103713. if(-a>b)return -sqrt(a*a+b*b);
  103714. return sqrt(b*b+a*a);
  103715. }
  103716. float **_vp_quantize_couple_memo(vorbis_block *vb,
  103717. vorbis_info_psy_global *g,
  103718. vorbis_look_psy *p,
  103719. vorbis_info_mapping0 *vi,
  103720. float **mdct){
  103721. int i,j,n=p->n;
  103722. float **ret=(float**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  103723. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  103724. for(i=0;i<vi->coupling_steps;i++){
  103725. float *mdctM=mdct[vi->coupling_mag[i]];
  103726. float *mdctA=mdct[vi->coupling_ang[i]];
  103727. ret[i]=(float*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  103728. for(j=0;j<limit;j++)
  103729. ret[i][j]=dipole_hypot(mdctM[j],mdctA[j]);
  103730. for(;j<n;j++)
  103731. ret[i][j]=round_hypot(mdctM[j],mdctA[j]);
  103732. }
  103733. return(ret);
  103734. }
  103735. static int apsort(const void *a, const void *b){
  103736. float f1=fabs(**(float**)a);
  103737. float f2=fabs(**(float**)b);
  103738. return (f1<f2)-(f1>f2);
  103739. }
  103740. int **_vp_quantize_couple_sort(vorbis_block *vb,
  103741. vorbis_look_psy *p,
  103742. vorbis_info_mapping0 *vi,
  103743. float **mags){
  103744. if(p->vi->normal_point_p){
  103745. int i,j,k,n=p->n;
  103746. int **ret=(int**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  103747. int partition=p->vi->normal_partition;
  103748. float **work=(float**) alloca(sizeof(*work)*partition);
  103749. for(i=0;i<vi->coupling_steps;i++){
  103750. ret[i]=(int*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  103751. for(j=0;j<n;j+=partition){
  103752. for(k=0;k<partition;k++)work[k]=mags[i]+k+j;
  103753. qsort(work,partition,sizeof(*work),apsort);
  103754. for(k=0;k<partition;k++)ret[i][k+j]=work[k]-mags[i];
  103755. }
  103756. }
  103757. return(ret);
  103758. }
  103759. return(NULL);
  103760. }
  103761. void _vp_noise_normalize_sort(vorbis_look_psy *p,
  103762. float *magnitudes,int *sortedindex){
  103763. int i,j,n=p->n;
  103764. vorbis_info_psy *vi=p->vi;
  103765. int partition=vi->normal_partition;
  103766. float **work=(float**) alloca(sizeof(*work)*partition);
  103767. int start=vi->normal_start;
  103768. for(j=start;j<n;j+=partition){
  103769. if(j+partition>n)partition=n-j;
  103770. for(i=0;i<partition;i++)work[i]=magnitudes+i+j;
  103771. qsort(work,partition,sizeof(*work),apsort);
  103772. for(i=0;i<partition;i++){
  103773. sortedindex[i+j-start]=work[i]-magnitudes;
  103774. }
  103775. }
  103776. }
  103777. void _vp_noise_normalize(vorbis_look_psy *p,
  103778. float *in,float *out,int *sortedindex){
  103779. int flag=0,i,j=0,n=p->n;
  103780. vorbis_info_psy *vi=p->vi;
  103781. int partition=vi->normal_partition;
  103782. int start=vi->normal_start;
  103783. if(start>n)start=n;
  103784. if(vi->normal_channel_p){
  103785. for(;j<start;j++)
  103786. out[j]=rint(in[j]);
  103787. for(;j+partition<=n;j+=partition){
  103788. float acc=0.;
  103789. int k;
  103790. for(i=j;i<j+partition;i++)
  103791. acc+=in[i]*in[i];
  103792. for(i=0;i<partition;i++){
  103793. k=sortedindex[i+j-start];
  103794. if(in[k]*in[k]>=.25f){
  103795. out[k]=rint(in[k]);
  103796. acc-=in[k]*in[k];
  103797. flag=1;
  103798. }else{
  103799. if(acc<vi->normal_thresh)break;
  103800. out[k]=unitnorm(in[k]);
  103801. acc-=1.;
  103802. }
  103803. }
  103804. for(;i<partition;i++){
  103805. k=sortedindex[i+j-start];
  103806. out[k]=0.;
  103807. }
  103808. }
  103809. }
  103810. for(;j<n;j++)
  103811. out[j]=rint(in[j]);
  103812. }
  103813. void _vp_couple(int blobno,
  103814. vorbis_info_psy_global *g,
  103815. vorbis_look_psy *p,
  103816. vorbis_info_mapping0 *vi,
  103817. float **res,
  103818. float **mag_memo,
  103819. int **mag_sort,
  103820. int **ifloor,
  103821. int *nonzero,
  103822. int sliding_lowpass){
  103823. int i,j,k,n=p->n;
  103824. for(i=0;i<vi->coupling_steps;i++){
  103825. if(nonzero[vi->coupling_mag[i]] ||
  103826. nonzero[vi->coupling_ang[i]]){
  103827. float *rM=res[vi->coupling_mag[i]];
  103828. float *rA=res[vi->coupling_ang[i]];
  103829. float *qM=rM+n;
  103830. float *qA=rA+n;
  103831. int *floorM=ifloor[vi->coupling_mag[i]];
  103832. int *floorA=ifloor[vi->coupling_ang[i]];
  103833. float prepoint=stereo_threshholds[g->coupling_prepointamp[blobno]];
  103834. float postpoint=stereo_threshholds[g->coupling_postpointamp[blobno]];
  103835. int partition=(p->vi->normal_point_p?p->vi->normal_partition:p->n);
  103836. int limit=g->coupling_pointlimit[p->vi->blockflag][blobno];
  103837. int pointlimit=limit;
  103838. nonzero[vi->coupling_mag[i]]=1;
  103839. nonzero[vi->coupling_ang[i]]=1;
  103840. if(n > 1000)
  103841. postpoint=stereo_threshholds_limited[g->coupling_postpointamp[blobno]];
  103842. for(j=0;j<p->n;j+=partition){
  103843. float acc=0.f;
  103844. for(k=0;k<partition;k++){
  103845. int l=k+j;
  103846. if(l<sliding_lowpass){
  103847. if((l>=limit && fabs(rM[l])<postpoint && fabs(rA[l])<postpoint) ||
  103848. (fabs(rM[l])<prepoint && fabs(rA[l])<prepoint)){
  103849. precomputed_couple_point(mag_memo[i][l],
  103850. floorM[l],floorA[l],
  103851. qM+l,qA+l);
  103852. if(rint(qM[l])==0.f)acc+=qM[l]*qM[l];
  103853. }else{
  103854. couple_lossless(rM[l],rA[l],qM+l,qA+l);
  103855. }
  103856. }else{
  103857. qM[l]=0.;
  103858. qA[l]=0.;
  103859. }
  103860. }
  103861. if(p->vi->normal_point_p){
  103862. for(k=0;k<partition && acc>=p->vi->normal_thresh;k++){
  103863. int l=mag_sort[i][j+k];
  103864. if(l<sliding_lowpass && l>=pointlimit && rint(qM[l])==0.f){
  103865. qM[l]=unitnorm(qM[l]);
  103866. acc-=1.f;
  103867. }
  103868. }
  103869. }
  103870. }
  103871. }
  103872. }
  103873. }
  103874. void hf_reduction(vorbis_info_psy_global *g,
  103875. vorbis_look_psy *p,
  103876. vorbis_info_mapping0 *vi,
  103877. float **mdct){
  103878. int i,j,n=p->n, de=0.3*p->m_val;
  103879. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  103880. for(i=0; i<vi->coupling_steps; i++){
  103881. for(j=limit; j<n; j++)
  103882. mdct[i][j] *= (1.0 - de*((float)(j-limit) / (float)(n-limit)));
  103883. }
  103884. }
  103885. #endif
  103886. /*** End of inlined file: psy.c ***/
  103887. /*** Start of inlined file: registry.c ***/
  103888. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  103889. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  103890. // tasks..
  103891. #if JUCE_MSVC
  103892. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  103893. #endif
  103894. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  103895. #if JUCE_USE_OGGVORBIS
  103896. extern vorbis_func_floor floor0_exportbundle;
  103897. extern vorbis_func_floor floor1_exportbundle;
  103898. extern vorbis_func_residue residue0_exportbundle;
  103899. extern vorbis_func_residue residue1_exportbundle;
  103900. extern vorbis_func_residue residue2_exportbundle;
  103901. extern vorbis_func_mapping mapping0_exportbundle;
  103902. vorbis_func_floor *_floor_P[]={
  103903. &floor0_exportbundle,
  103904. &floor1_exportbundle,
  103905. };
  103906. vorbis_func_residue *_residue_P[]={
  103907. &residue0_exportbundle,
  103908. &residue1_exportbundle,
  103909. &residue2_exportbundle,
  103910. };
  103911. vorbis_func_mapping *_mapping_P[]={
  103912. &mapping0_exportbundle,
  103913. };
  103914. #endif
  103915. /*** End of inlined file: registry.c ***/
  103916. /*** Start of inlined file: res0.c ***/
  103917. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  103918. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  103919. // tasks..
  103920. #if JUCE_MSVC
  103921. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  103922. #endif
  103923. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  103924. #if JUCE_USE_OGGVORBIS
  103925. #include <stdlib.h>
  103926. #include <string.h>
  103927. #include <math.h>
  103928. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  103929. #include <stdio.h>
  103930. #endif
  103931. typedef struct {
  103932. vorbis_info_residue0 *info;
  103933. int parts;
  103934. int stages;
  103935. codebook *fullbooks;
  103936. codebook *phrasebook;
  103937. codebook ***partbooks;
  103938. int partvals;
  103939. int **decodemap;
  103940. long postbits;
  103941. long phrasebits;
  103942. long frames;
  103943. #if defined(TRAIN_RES) || defined(TRAIN_RESAUX)
  103944. int train_seq;
  103945. long *training_data[8][64];
  103946. float training_max[8][64];
  103947. float training_min[8][64];
  103948. float tmin;
  103949. float tmax;
  103950. #endif
  103951. } vorbis_look_residue0;
  103952. void res0_free_info(vorbis_info_residue *i){
  103953. vorbis_info_residue0 *info=(vorbis_info_residue0 *)i;
  103954. if(info){
  103955. memset(info,0,sizeof(*info));
  103956. _ogg_free(info);
  103957. }
  103958. }
  103959. void res0_free_look(vorbis_look_residue *i){
  103960. int j;
  103961. if(i){
  103962. vorbis_look_residue0 *look=(vorbis_look_residue0 *)i;
  103963. #ifdef TRAIN_RES
  103964. {
  103965. int j,k,l;
  103966. for(j=0;j<look->parts;j++){
  103967. for(k=0;k<8;k++)
  103968. if(look->training_data[k][j]){
  103969. char buffer[80];
  103970. FILE *of;
  103971. codebook *statebook=look->partbooks[j][k];
  103972. sprintf(buffer,"res_part%d_pass%d.vqd",j,k);
  103973. of=fopen(buffer,"a");
  103974. for(l=0;l<statebook->entries;l++)
  103975. fprintf(of,"%d:%ld\n",l,look->training_data[k][j][l]);
  103976. fclose(of);
  103977. _ogg_free(look->training_data[k][j]);
  103978. look->training_data[k][j]=NULL;
  103979. }
  103980. }
  103981. }
  103982. fprintf(stderr,"min/max residue: %g::%g\n",look->tmin,look->tmax);
  103983. #endif
  103984. for(j=0;j<look->parts;j++)
  103985. if(look->partbooks[j])_ogg_free(look->partbooks[j]);
  103986. _ogg_free(look->partbooks);
  103987. for(j=0;j<look->partvals;j++)
  103988. _ogg_free(look->decodemap[j]);
  103989. _ogg_free(look->decodemap);
  103990. memset(look,0,sizeof(*look));
  103991. _ogg_free(look);
  103992. }
  103993. }
  103994. static int icount(unsigned int v){
  103995. int ret=0;
  103996. while(v){
  103997. ret+=v&1;
  103998. v>>=1;
  103999. }
  104000. return(ret);
  104001. }
  104002. void res0_pack(vorbis_info_residue *vr,oggpack_buffer *opb){
  104003. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  104004. int j,acc=0;
  104005. oggpack_write(opb,info->begin,24);
  104006. oggpack_write(opb,info->end,24);
  104007. oggpack_write(opb,info->grouping-1,24); /* residue vectors to group and
  104008. code with a partitioned book */
  104009. oggpack_write(opb,info->partitions-1,6); /* possible partition choices */
  104010. oggpack_write(opb,info->groupbook,8); /* group huffman book */
  104011. for(j=0;j<info->partitions;j++){
  104012. if(ilog(info->secondstages[j])>3){
  104013. oggpack_write(opb,info->secondstages[j],3);
  104014. oggpack_write(opb,1,1);
  104015. oggpack_write(opb,info->secondstages[j]>>3,5);
  104016. }else
  104017. oggpack_write(opb,info->secondstages[j],4); /* trailing zero */
  104018. acc+=icount(info->secondstages[j]);
  104019. }
  104020. for(j=0;j<acc;j++)
  104021. oggpack_write(opb,info->booklist[j],8);
  104022. }
  104023. vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  104024. int j,acc=0;
  104025. vorbis_info_residue0 *info=(vorbis_info_residue0*) _ogg_calloc(1,sizeof(*info));
  104026. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  104027. info->begin=oggpack_read(opb,24);
  104028. info->end=oggpack_read(opb,24);
  104029. info->grouping=oggpack_read(opb,24)+1;
  104030. info->partitions=oggpack_read(opb,6)+1;
  104031. info->groupbook=oggpack_read(opb,8);
  104032. for(j=0;j<info->partitions;j++){
  104033. int cascade=oggpack_read(opb,3);
  104034. if(oggpack_read(opb,1))
  104035. cascade|=(oggpack_read(opb,5)<<3);
  104036. info->secondstages[j]=cascade;
  104037. acc+=icount(cascade);
  104038. }
  104039. for(j=0;j<acc;j++)
  104040. info->booklist[j]=oggpack_read(opb,8);
  104041. if(info->groupbook>=ci->books)goto errout;
  104042. for(j=0;j<acc;j++)
  104043. if(info->booklist[j]>=ci->books)goto errout;
  104044. return(info);
  104045. errout:
  104046. res0_free_info(info);
  104047. return(NULL);
  104048. }
  104049. vorbis_look_residue *res0_look(vorbis_dsp_state *vd,
  104050. vorbis_info_residue *vr){
  104051. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  104052. vorbis_look_residue0 *look=(vorbis_look_residue0 *)_ogg_calloc(1,sizeof(*look));
  104053. codec_setup_info *ci=(codec_setup_info*)vd->vi->codec_setup;
  104054. int j,k,acc=0;
  104055. int dim;
  104056. int maxstage=0;
  104057. look->info=info;
  104058. look->parts=info->partitions;
  104059. look->fullbooks=ci->fullbooks;
  104060. look->phrasebook=ci->fullbooks+info->groupbook;
  104061. dim=look->phrasebook->dim;
  104062. look->partbooks=(codebook***)_ogg_calloc(look->parts,sizeof(*look->partbooks));
  104063. for(j=0;j<look->parts;j++){
  104064. int stages=ilog(info->secondstages[j]);
  104065. if(stages){
  104066. if(stages>maxstage)maxstage=stages;
  104067. look->partbooks[j]=(codebook**) _ogg_calloc(stages,sizeof(*look->partbooks[j]));
  104068. for(k=0;k<stages;k++)
  104069. if(info->secondstages[j]&(1<<k)){
  104070. look->partbooks[j][k]=ci->fullbooks+info->booklist[acc++];
  104071. #ifdef TRAIN_RES
  104072. look->training_data[k][j]=_ogg_calloc(look->partbooks[j][k]->entries,
  104073. sizeof(***look->training_data));
  104074. #endif
  104075. }
  104076. }
  104077. }
  104078. look->partvals=rint(pow((float)look->parts,(float)dim));
  104079. look->stages=maxstage;
  104080. look->decodemap=(int**)_ogg_malloc(look->partvals*sizeof(*look->decodemap));
  104081. for(j=0;j<look->partvals;j++){
  104082. long val=j;
  104083. long mult=look->partvals/look->parts;
  104084. look->decodemap[j]=(int*)_ogg_malloc(dim*sizeof(*look->decodemap[j]));
  104085. for(k=0;k<dim;k++){
  104086. long deco=val/mult;
  104087. val-=deco*mult;
  104088. mult/=look->parts;
  104089. look->decodemap[j][k]=deco;
  104090. }
  104091. }
  104092. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104093. {
  104094. static int train_seq=0;
  104095. look->train_seq=train_seq++;
  104096. }
  104097. #endif
  104098. return(look);
  104099. }
  104100. static int local_book_besterror(codebook *book,float *a){
  104101. int dim=book->dim,i,k,o;
  104102. int best=0;
  104103. encode_aux_threshmatch *tt=book->c->thresh_tree;
  104104. for(k=0,o=dim;k<dim;++k){
  104105. float val=a[--o];
  104106. i=tt->threshvals>>1;
  104107. if(val<tt->quantthresh[i]){
  104108. if(val<tt->quantthresh[i-1]){
  104109. for(--i;i>0;--i)
  104110. if(val>=tt->quantthresh[i-1])
  104111. break;
  104112. }
  104113. }else{
  104114. for(++i;i<tt->threshvals-1;++i)
  104115. if(val<tt->quantthresh[i])break;
  104116. }
  104117. best=(best*tt->quantvals)+tt->quantmap[i];
  104118. }
  104119. if(book->c->lengthlist[best]<=0){
  104120. const static_codebook *c=book->c;
  104121. int i,j;
  104122. float bestf=0.f;
  104123. float *e=book->valuelist;
  104124. best=-1;
  104125. for(i=0;i<book->entries;i++){
  104126. if(c->lengthlist[i]>0){
  104127. float thisx=0.f;
  104128. for(j=0;j<dim;j++){
  104129. float val=(e[j]-a[j]);
  104130. thisx+=val*val;
  104131. }
  104132. if(best==-1 || thisx<bestf){
  104133. bestf=thisx;
  104134. best=i;
  104135. }
  104136. }
  104137. e+=dim;
  104138. }
  104139. }
  104140. {
  104141. float *ptr=book->valuelist+best*dim;
  104142. for(i=0;i<dim;i++)
  104143. *a++ -= *ptr++;
  104144. }
  104145. return(best);
  104146. }
  104147. static int _encodepart(oggpack_buffer *opb,float *vec, int n,
  104148. codebook *book,long *acc){
  104149. int i,bits=0;
  104150. int dim=book->dim;
  104151. int step=n/dim;
  104152. for(i=0;i<step;i++){
  104153. int entry=local_book_besterror(book,vec+i*dim);
  104154. #ifdef TRAIN_RES
  104155. acc[entry]++;
  104156. #endif
  104157. bits+=vorbis_book_encode(book,entry,opb);
  104158. }
  104159. return(bits);
  104160. }
  104161. static long **_01class(vorbis_block *vb,vorbis_look_residue *vl,
  104162. float **in,int ch){
  104163. long i,j,k;
  104164. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104165. vorbis_info_residue0 *info=look->info;
  104166. int samples_per_partition=info->grouping;
  104167. int possible_partitions=info->partitions;
  104168. int n=info->end-info->begin;
  104169. int partvals=n/samples_per_partition;
  104170. long **partword=(long**)_vorbis_block_alloc(vb,ch*sizeof(*partword));
  104171. float scale=100./samples_per_partition;
  104172. for(i=0;i<ch;i++){
  104173. partword[i]=(long*)_vorbis_block_alloc(vb,n/samples_per_partition*sizeof(*partword[i]));
  104174. memset(partword[i],0,n/samples_per_partition*sizeof(*partword[i]));
  104175. }
  104176. for(i=0;i<partvals;i++){
  104177. int offset=i*samples_per_partition+info->begin;
  104178. for(j=0;j<ch;j++){
  104179. float max=0.;
  104180. float ent=0.;
  104181. for(k=0;k<samples_per_partition;k++){
  104182. if(fabs(in[j][offset+k])>max)max=fabs(in[j][offset+k]);
  104183. ent+=fabs(rint(in[j][offset+k]));
  104184. }
  104185. ent*=scale;
  104186. for(k=0;k<possible_partitions-1;k++)
  104187. if(max<=info->classmetric1[k] &&
  104188. (info->classmetric2[k]<0 || (int)ent<info->classmetric2[k]))
  104189. break;
  104190. partword[j][i]=k;
  104191. }
  104192. }
  104193. #ifdef TRAIN_RESAUX
  104194. {
  104195. FILE *of;
  104196. char buffer[80];
  104197. for(i=0;i<ch;i++){
  104198. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104199. of=fopen(buffer,"a");
  104200. for(j=0;j<partvals;j++)
  104201. fprintf(of,"%ld, ",partword[i][j]);
  104202. fprintf(of,"\n");
  104203. fclose(of);
  104204. }
  104205. }
  104206. #endif
  104207. look->frames++;
  104208. return(partword);
  104209. }
  104210. static long **_2class(vorbis_block *vb,vorbis_look_residue *vl,float **in,
  104211. int ch){
  104212. long i,j,k,l;
  104213. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104214. vorbis_info_residue0 *info=look->info;
  104215. int samples_per_partition=info->grouping;
  104216. int possible_partitions=info->partitions;
  104217. int n=info->end-info->begin;
  104218. int partvals=n/samples_per_partition;
  104219. long **partword=(long**)_vorbis_block_alloc(vb,sizeof(*partword));
  104220. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104221. FILE *of;
  104222. char buffer[80];
  104223. #endif
  104224. partword[0]=(long*)_vorbis_block_alloc(vb,n*ch/samples_per_partition*sizeof(*partword[0]));
  104225. memset(partword[0],0,n*ch/samples_per_partition*sizeof(*partword[0]));
  104226. for(i=0,l=info->begin/ch;i<partvals;i++){
  104227. float magmax=0.f;
  104228. float angmax=0.f;
  104229. for(j=0;j<samples_per_partition;j+=ch){
  104230. if(fabs(in[0][l])>magmax)magmax=fabs(in[0][l]);
  104231. for(k=1;k<ch;k++)
  104232. if(fabs(in[k][l])>angmax)angmax=fabs(in[k][l]);
  104233. l++;
  104234. }
  104235. for(j=0;j<possible_partitions-1;j++)
  104236. if(magmax<=info->classmetric1[j] &&
  104237. angmax<=info->classmetric2[j])
  104238. break;
  104239. partword[0][i]=j;
  104240. }
  104241. #ifdef TRAIN_RESAUX
  104242. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104243. of=fopen(buffer,"a");
  104244. for(i=0;i<partvals;i++)
  104245. fprintf(of,"%ld, ",partword[0][i]);
  104246. fprintf(of,"\n");
  104247. fclose(of);
  104248. #endif
  104249. look->frames++;
  104250. return(partword);
  104251. }
  104252. static int _01forward(oggpack_buffer *opb,
  104253. vorbis_block *vb,vorbis_look_residue *vl,
  104254. float **in,int ch,
  104255. long **partword,
  104256. int (*encode)(oggpack_buffer *,float *,int,
  104257. codebook *,long *)){
  104258. long i,j,k,s;
  104259. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104260. vorbis_info_residue0 *info=look->info;
  104261. int samples_per_partition=info->grouping;
  104262. int possible_partitions=info->partitions;
  104263. int partitions_per_word=look->phrasebook->dim;
  104264. int n=info->end-info->begin;
  104265. int partvals=n/samples_per_partition;
  104266. long resbits[128];
  104267. long resvals[128];
  104268. #ifdef TRAIN_RES
  104269. for(i=0;i<ch;i++)
  104270. for(j=info->begin;j<info->end;j++){
  104271. if(in[i][j]>look->tmax)look->tmax=in[i][j];
  104272. if(in[i][j]<look->tmin)look->tmin=in[i][j];
  104273. }
  104274. #endif
  104275. memset(resbits,0,sizeof(resbits));
  104276. memset(resvals,0,sizeof(resvals));
  104277. for(s=0;s<look->stages;s++){
  104278. for(i=0;i<partvals;){
  104279. if(s==0){
  104280. for(j=0;j<ch;j++){
  104281. long val=partword[j][i];
  104282. for(k=1;k<partitions_per_word;k++){
  104283. val*=possible_partitions;
  104284. if(i+k<partvals)
  104285. val+=partword[j][i+k];
  104286. }
  104287. if(val<look->phrasebook->entries)
  104288. look->phrasebits+=vorbis_book_encode(look->phrasebook,val,opb);
  104289. #if 0 /*def TRAIN_RES*/
  104290. else
  104291. fprintf(stderr,"!");
  104292. #endif
  104293. }
  104294. }
  104295. for(k=0;k<partitions_per_word && i<partvals;k++,i++){
  104296. long offset=i*samples_per_partition+info->begin;
  104297. for(j=0;j<ch;j++){
  104298. if(s==0)resvals[partword[j][i]]+=samples_per_partition;
  104299. if(info->secondstages[partword[j][i]]&(1<<s)){
  104300. codebook *statebook=look->partbooks[partword[j][i]][s];
  104301. if(statebook){
  104302. int ret;
  104303. long *accumulator=NULL;
  104304. #ifdef TRAIN_RES
  104305. accumulator=look->training_data[s][partword[j][i]];
  104306. {
  104307. int l;
  104308. float *samples=in[j]+offset;
  104309. for(l=0;l<samples_per_partition;l++){
  104310. if(samples[l]<look->training_min[s][partword[j][i]])
  104311. look->training_min[s][partword[j][i]]=samples[l];
  104312. if(samples[l]>look->training_max[s][partword[j][i]])
  104313. look->training_max[s][partword[j][i]]=samples[l];
  104314. }
  104315. }
  104316. #endif
  104317. ret=encode(opb,in[j]+offset,samples_per_partition,
  104318. statebook,accumulator);
  104319. look->postbits+=ret;
  104320. resbits[partword[j][i]]+=ret;
  104321. }
  104322. }
  104323. }
  104324. }
  104325. }
  104326. }
  104327. return(0);
  104328. }
  104329. static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104330. float **in,int ch,
  104331. long (*decodepart)(codebook *, float *,
  104332. oggpack_buffer *,int)){
  104333. long i,j,k,l,s;
  104334. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104335. vorbis_info_residue0 *info=look->info;
  104336. int samples_per_partition=info->grouping;
  104337. int partitions_per_word=look->phrasebook->dim;
  104338. int n=info->end-info->begin;
  104339. int partvals=n/samples_per_partition;
  104340. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104341. int ***partword=(int***)alloca(ch*sizeof(*partword));
  104342. for(j=0;j<ch;j++)
  104343. partword[j]=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword[j]));
  104344. for(s=0;s<look->stages;s++){
  104345. for(i=0,l=0;i<partvals;l++){
  104346. if(s==0){
  104347. for(j=0;j<ch;j++){
  104348. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104349. if(temp==-1)goto eopbreak;
  104350. partword[j][l]=look->decodemap[temp];
  104351. if(partword[j][l]==NULL)goto errout;
  104352. }
  104353. }
  104354. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104355. for(j=0;j<ch;j++){
  104356. long offset=info->begin+i*samples_per_partition;
  104357. if(info->secondstages[partword[j][l][k]]&(1<<s)){
  104358. codebook *stagebook=look->partbooks[partword[j][l][k]][s];
  104359. if(stagebook){
  104360. if(decodepart(stagebook,in[j]+offset,&vb->opb,
  104361. samples_per_partition)==-1)goto eopbreak;
  104362. }
  104363. }
  104364. }
  104365. }
  104366. }
  104367. errout:
  104368. eopbreak:
  104369. return(0);
  104370. }
  104371. #if 0
  104372. long **res0_class(vorbis_block *vb,vorbis_look_residue *vl,
  104373. float **in,int *nonzero,int ch){
  104374. int i,used=0;
  104375. for(i=0;i<ch;i++)
  104376. if(nonzero[i])
  104377. in[used++]=in[i];
  104378. if(used)
  104379. return(_01class(vb,vl,in,used));
  104380. else
  104381. return(0);
  104382. }
  104383. int res0_forward(vorbis_block *vb,vorbis_look_residue *vl,
  104384. float **in,float **out,int *nonzero,int ch,
  104385. long **partword){
  104386. int i,j,used=0,n=vb->pcmend/2;
  104387. for(i=0;i<ch;i++)
  104388. if(nonzero[i]){
  104389. if(out)
  104390. for(j=0;j<n;j++)
  104391. out[i][j]+=in[i][j];
  104392. in[used++]=in[i];
  104393. }
  104394. if(used){
  104395. int ret=_01forward(vb,vl,in,used,partword,
  104396. _interleaved_encodepart);
  104397. if(out){
  104398. used=0;
  104399. for(i=0;i<ch;i++)
  104400. if(nonzero[i]){
  104401. for(j=0;j<n;j++)
  104402. out[i][j]-=in[used][j];
  104403. used++;
  104404. }
  104405. }
  104406. return(ret);
  104407. }else{
  104408. return(0);
  104409. }
  104410. }
  104411. #endif
  104412. int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104413. float **in,int *nonzero,int ch){
  104414. int i,used=0;
  104415. for(i=0;i<ch;i++)
  104416. if(nonzero[i])
  104417. in[used++]=in[i];
  104418. if(used)
  104419. return(_01inverse(vb,vl,in,used,vorbis_book_decodevs_add));
  104420. else
  104421. return(0);
  104422. }
  104423. int res1_forward(oggpack_buffer *opb,vorbis_block *vb,vorbis_look_residue *vl,
  104424. float **in,float **out,int *nonzero,int ch,
  104425. long **partword){
  104426. int i,j,used=0,n=vb->pcmend/2;
  104427. for(i=0;i<ch;i++)
  104428. if(nonzero[i]){
  104429. if(out)
  104430. for(j=0;j<n;j++)
  104431. out[i][j]+=in[i][j];
  104432. in[used++]=in[i];
  104433. }
  104434. if(used){
  104435. int ret=_01forward(opb,vb,vl,in,used,partword,_encodepart);
  104436. if(out){
  104437. used=0;
  104438. for(i=0;i<ch;i++)
  104439. if(nonzero[i]){
  104440. for(j=0;j<n;j++)
  104441. out[i][j]-=in[used][j];
  104442. used++;
  104443. }
  104444. }
  104445. return(ret);
  104446. }else{
  104447. return(0);
  104448. }
  104449. }
  104450. long **res1_class(vorbis_block *vb,vorbis_look_residue *vl,
  104451. float **in,int *nonzero,int ch){
  104452. int i,used=0;
  104453. for(i=0;i<ch;i++)
  104454. if(nonzero[i])
  104455. in[used++]=in[i];
  104456. if(used)
  104457. return(_01class(vb,vl,in,used));
  104458. else
  104459. return(0);
  104460. }
  104461. int res1_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104462. float **in,int *nonzero,int ch){
  104463. int i,used=0;
  104464. for(i=0;i<ch;i++)
  104465. if(nonzero[i])
  104466. in[used++]=in[i];
  104467. if(used)
  104468. return(_01inverse(vb,vl,in,used,vorbis_book_decodev_add));
  104469. else
  104470. return(0);
  104471. }
  104472. long **res2_class(vorbis_block *vb,vorbis_look_residue *vl,
  104473. float **in,int *nonzero,int ch){
  104474. int i,used=0;
  104475. for(i=0;i<ch;i++)
  104476. if(nonzero[i])used++;
  104477. if(used)
  104478. return(_2class(vb,vl,in,ch));
  104479. else
  104480. return(0);
  104481. }
  104482. int res2_forward(oggpack_buffer *opb,
  104483. vorbis_block *vb,vorbis_look_residue *vl,
  104484. float **in,float **out,int *nonzero,int ch,
  104485. long **partword){
  104486. long i,j,k,n=vb->pcmend/2,used=0;
  104487. float *work=(float*)_vorbis_block_alloc(vb,ch*n*sizeof(*work));
  104488. for(i=0;i<ch;i++){
  104489. float *pcm=in[i];
  104490. if(nonzero[i])used++;
  104491. for(j=0,k=i;j<n;j++,k+=ch)
  104492. work[k]=pcm[j];
  104493. }
  104494. if(used){
  104495. int ret=_01forward(opb,vb,vl,&work,1,partword,_encodepart);
  104496. if(out){
  104497. for(i=0;i<ch;i++){
  104498. float *pcm=in[i];
  104499. float *sofar=out[i];
  104500. for(j=0,k=i;j<n;j++,k+=ch)
  104501. sofar[j]+=pcm[j]-work[k];
  104502. }
  104503. }
  104504. return(ret);
  104505. }else{
  104506. return(0);
  104507. }
  104508. }
  104509. int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104510. float **in,int *nonzero,int ch){
  104511. long i,k,l,s;
  104512. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104513. vorbis_info_residue0 *info=look->info;
  104514. int samples_per_partition=info->grouping;
  104515. int partitions_per_word=look->phrasebook->dim;
  104516. int n=info->end-info->begin;
  104517. int partvals=n/samples_per_partition;
  104518. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104519. int **partword=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword));
  104520. for(i=0;i<ch;i++)if(nonzero[i])break;
  104521. if(i==ch)return(0); /* no nonzero vectors */
  104522. for(s=0;s<look->stages;s++){
  104523. for(i=0,l=0;i<partvals;l++){
  104524. if(s==0){
  104525. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104526. if(temp==-1)goto eopbreak;
  104527. partword[l]=look->decodemap[temp];
  104528. if(partword[l]==NULL)goto errout;
  104529. }
  104530. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104531. if(info->secondstages[partword[l][k]]&(1<<s)){
  104532. codebook *stagebook=look->partbooks[partword[l][k]][s];
  104533. if(stagebook){
  104534. if(vorbis_book_decodevv_add(stagebook,in,
  104535. i*samples_per_partition+info->begin,ch,
  104536. &vb->opb,samples_per_partition)==-1)
  104537. goto eopbreak;
  104538. }
  104539. }
  104540. }
  104541. }
  104542. errout:
  104543. eopbreak:
  104544. return(0);
  104545. }
  104546. vorbis_func_residue residue0_exportbundle={
  104547. NULL,
  104548. &res0_unpack,
  104549. &res0_look,
  104550. &res0_free_info,
  104551. &res0_free_look,
  104552. NULL,
  104553. NULL,
  104554. &res0_inverse
  104555. };
  104556. vorbis_func_residue residue1_exportbundle={
  104557. &res0_pack,
  104558. &res0_unpack,
  104559. &res0_look,
  104560. &res0_free_info,
  104561. &res0_free_look,
  104562. &res1_class,
  104563. &res1_forward,
  104564. &res1_inverse
  104565. };
  104566. vorbis_func_residue residue2_exportbundle={
  104567. &res0_pack,
  104568. &res0_unpack,
  104569. &res0_look,
  104570. &res0_free_info,
  104571. &res0_free_look,
  104572. &res2_class,
  104573. &res2_forward,
  104574. &res2_inverse
  104575. };
  104576. #endif
  104577. /*** End of inlined file: res0.c ***/
  104578. /*** Start of inlined file: sharedbook.c ***/
  104579. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104580. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104581. // tasks..
  104582. #if JUCE_MSVC
  104583. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104584. #endif
  104585. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104586. #if JUCE_USE_OGGVORBIS
  104587. #include <stdlib.h>
  104588. #include <math.h>
  104589. #include <string.h>
  104590. int _ilog(unsigned int v){
  104591. int ret=0;
  104592. while(v){
  104593. ret++;
  104594. v>>=1;
  104595. }
  104596. return(ret);
  104597. }
  104598. #define VQ_FEXP 10
  104599. #define VQ_FMAN 21
  104600. #define VQ_FEXP_BIAS 768 /* bias toward values smaller than 1. */
  104601. long _float32_pack(float val){
  104602. int sign=0;
  104603. long exp;
  104604. long mant;
  104605. if(val<0){
  104606. sign=0x80000000;
  104607. val= -val;
  104608. }
  104609. exp= floor(log(val)/log(2.f));
  104610. mant=rint(ldexp(val,(VQ_FMAN-1)-exp));
  104611. exp=(exp+VQ_FEXP_BIAS)<<VQ_FMAN;
  104612. return(sign|exp|mant);
  104613. }
  104614. float _float32_unpack(long val){
  104615. double mant=val&0x1fffff;
  104616. int sign=val&0x80000000;
  104617. long exp =(val&0x7fe00000L)>>VQ_FMAN;
  104618. if(sign)mant= -mant;
  104619. return(ldexp(mant,exp-(VQ_FMAN-1)-VQ_FEXP_BIAS));
  104620. }
  104621. ogg_uint32_t *_make_words(long *l,long n,long sparsecount){
  104622. long i,j,count=0;
  104623. ogg_uint32_t marker[33];
  104624. ogg_uint32_t *r=(ogg_uint32_t*)_ogg_malloc((sparsecount?sparsecount:n)*sizeof(*r));
  104625. memset(marker,0,sizeof(marker));
  104626. for(i=0;i<n;i++){
  104627. long length=l[i];
  104628. if(length>0){
  104629. ogg_uint32_t entry=marker[length];
  104630. if(length<32 && (entry>>length)){
  104631. _ogg_free(r);
  104632. return(NULL);
  104633. }
  104634. r[count++]=entry;
  104635. {
  104636. for(j=length;j>0;j--){
  104637. if(marker[j]&1){
  104638. if(j==1)
  104639. marker[1]++;
  104640. else
  104641. marker[j]=marker[j-1]<<1;
  104642. break; /* invariant says next upper marker would already
  104643. have been moved if it was on the same path */
  104644. }
  104645. marker[j]++;
  104646. }
  104647. }
  104648. for(j=length+1;j<33;j++)
  104649. if((marker[j]>>1) == entry){
  104650. entry=marker[j];
  104651. marker[j]=marker[j-1]<<1;
  104652. }else
  104653. break;
  104654. }else
  104655. if(sparsecount==0)count++;
  104656. }
  104657. for(i=0,count=0;i<n;i++){
  104658. ogg_uint32_t temp=0;
  104659. for(j=0;j<l[i];j++){
  104660. temp<<=1;
  104661. temp|=(r[count]>>j)&1;
  104662. }
  104663. if(sparsecount){
  104664. if(l[i])
  104665. r[count++]=temp;
  104666. }else
  104667. r[count++]=temp;
  104668. }
  104669. return(r);
  104670. }
  104671. long _book_maptype1_quantvals(const static_codebook *b){
  104672. long vals=floor(pow((float)b->entries,1.f/b->dim));
  104673. while(1){
  104674. long acc=1;
  104675. long acc1=1;
  104676. int i;
  104677. for(i=0;i<b->dim;i++){
  104678. acc*=vals;
  104679. acc1*=vals+1;
  104680. }
  104681. if(acc<=b->entries && acc1>b->entries){
  104682. return(vals);
  104683. }else{
  104684. if(acc>b->entries){
  104685. vals--;
  104686. }else{
  104687. vals++;
  104688. }
  104689. }
  104690. }
  104691. }
  104692. float *_book_unquantize(const static_codebook *b,int n,int *sparsemap){
  104693. long j,k,count=0;
  104694. if(b->maptype==1 || b->maptype==2){
  104695. int quantvals;
  104696. float mindel=_float32_unpack(b->q_min);
  104697. float delta=_float32_unpack(b->q_delta);
  104698. float *r=(float*)_ogg_calloc(n*b->dim,sizeof(*r));
  104699. switch(b->maptype){
  104700. case 1:
  104701. quantvals=_book_maptype1_quantvals(b);
  104702. for(j=0;j<b->entries;j++){
  104703. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  104704. float last=0.f;
  104705. int indexdiv=1;
  104706. for(k=0;k<b->dim;k++){
  104707. int index= (j/indexdiv)%quantvals;
  104708. float val=b->quantlist[index];
  104709. val=fabs(val)*delta+mindel+last;
  104710. if(b->q_sequencep)last=val;
  104711. if(sparsemap)
  104712. r[sparsemap[count]*b->dim+k]=val;
  104713. else
  104714. r[count*b->dim+k]=val;
  104715. indexdiv*=quantvals;
  104716. }
  104717. count++;
  104718. }
  104719. }
  104720. break;
  104721. case 2:
  104722. for(j=0;j<b->entries;j++){
  104723. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  104724. float last=0.f;
  104725. for(k=0;k<b->dim;k++){
  104726. float val=b->quantlist[j*b->dim+k];
  104727. val=fabs(val)*delta+mindel+last;
  104728. if(b->q_sequencep)last=val;
  104729. if(sparsemap)
  104730. r[sparsemap[count]*b->dim+k]=val;
  104731. else
  104732. r[count*b->dim+k]=val;
  104733. }
  104734. count++;
  104735. }
  104736. }
  104737. break;
  104738. }
  104739. return(r);
  104740. }
  104741. return(NULL);
  104742. }
  104743. void vorbis_staticbook_clear(static_codebook *b){
  104744. if(b->allocedp){
  104745. if(b->quantlist)_ogg_free(b->quantlist);
  104746. if(b->lengthlist)_ogg_free(b->lengthlist);
  104747. if(b->nearest_tree){
  104748. _ogg_free(b->nearest_tree->ptr0);
  104749. _ogg_free(b->nearest_tree->ptr1);
  104750. _ogg_free(b->nearest_tree->p);
  104751. _ogg_free(b->nearest_tree->q);
  104752. memset(b->nearest_tree,0,sizeof(*b->nearest_tree));
  104753. _ogg_free(b->nearest_tree);
  104754. }
  104755. if(b->thresh_tree){
  104756. _ogg_free(b->thresh_tree->quantthresh);
  104757. _ogg_free(b->thresh_tree->quantmap);
  104758. memset(b->thresh_tree,0,sizeof(*b->thresh_tree));
  104759. _ogg_free(b->thresh_tree);
  104760. }
  104761. memset(b,0,sizeof(*b));
  104762. }
  104763. }
  104764. void vorbis_staticbook_destroy(static_codebook *b){
  104765. if(b->allocedp){
  104766. vorbis_staticbook_clear(b);
  104767. _ogg_free(b);
  104768. }
  104769. }
  104770. void vorbis_book_clear(codebook *b){
  104771. if(b->valuelist)_ogg_free(b->valuelist);
  104772. if(b->codelist)_ogg_free(b->codelist);
  104773. if(b->dec_index)_ogg_free(b->dec_index);
  104774. if(b->dec_codelengths)_ogg_free(b->dec_codelengths);
  104775. if(b->dec_firsttable)_ogg_free(b->dec_firsttable);
  104776. memset(b,0,sizeof(*b));
  104777. }
  104778. int vorbis_book_init_encode(codebook *c,const static_codebook *s){
  104779. memset(c,0,sizeof(*c));
  104780. c->c=s;
  104781. c->entries=s->entries;
  104782. c->used_entries=s->entries;
  104783. c->dim=s->dim;
  104784. c->codelist=_make_words(s->lengthlist,s->entries,0);
  104785. c->valuelist=_book_unquantize(s,s->entries,NULL);
  104786. return(0);
  104787. }
  104788. static int sort32a(const void *a,const void *b){
  104789. return ( **(ogg_uint32_t **)a>**(ogg_uint32_t **)b)-
  104790. ( **(ogg_uint32_t **)a<**(ogg_uint32_t **)b);
  104791. }
  104792. int vorbis_book_init_decode(codebook *c,const static_codebook *s){
  104793. int i,j,n=0,tabn;
  104794. int *sortindex;
  104795. memset(c,0,sizeof(*c));
  104796. for(i=0;i<s->entries;i++)
  104797. if(s->lengthlist[i]>0)
  104798. n++;
  104799. c->entries=s->entries;
  104800. c->used_entries=n;
  104801. c->dim=s->dim;
  104802. {
  104803. ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries);
  104804. ogg_uint32_t **codep=(ogg_uint32_t**)alloca(sizeof(*codep)*n);
  104805. if(codes==NULL)goto err_out;
  104806. for(i=0;i<n;i++){
  104807. codes[i]=ogg_bitreverse(codes[i]);
  104808. codep[i]=codes+i;
  104809. }
  104810. qsort(codep,n,sizeof(*codep),sort32a);
  104811. sortindex=(int*)alloca(n*sizeof(*sortindex));
  104812. c->codelist=(ogg_uint32_t*)_ogg_malloc(n*sizeof(*c->codelist));
  104813. for(i=0;i<n;i++){
  104814. int position=codep[i]-codes;
  104815. sortindex[position]=i;
  104816. }
  104817. for(i=0;i<n;i++)
  104818. c->codelist[sortindex[i]]=codes[i];
  104819. _ogg_free(codes);
  104820. }
  104821. c->valuelist=_book_unquantize(s,n,sortindex);
  104822. c->dec_index=(int*)_ogg_malloc(n*sizeof(*c->dec_index));
  104823. for(n=0,i=0;i<s->entries;i++)
  104824. if(s->lengthlist[i]>0)
  104825. c->dec_index[sortindex[n++]]=i;
  104826. c->dec_codelengths=(char*)_ogg_malloc(n*sizeof(*c->dec_codelengths));
  104827. for(n=0,i=0;i<s->entries;i++)
  104828. if(s->lengthlist[i]>0)
  104829. c->dec_codelengths[sortindex[n++]]=s->lengthlist[i];
  104830. c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */
  104831. if(c->dec_firsttablen<5)c->dec_firsttablen=5;
  104832. if(c->dec_firsttablen>8)c->dec_firsttablen=8;
  104833. tabn=1<<c->dec_firsttablen;
  104834. c->dec_firsttable=(ogg_uint32_t*)_ogg_calloc(tabn,sizeof(*c->dec_firsttable));
  104835. c->dec_maxlength=0;
  104836. for(i=0;i<n;i++){
  104837. if(c->dec_maxlength<c->dec_codelengths[i])
  104838. c->dec_maxlength=c->dec_codelengths[i];
  104839. if(c->dec_codelengths[i]<=c->dec_firsttablen){
  104840. ogg_uint32_t orig=ogg_bitreverse(c->codelist[i]);
  104841. for(j=0;j<(1<<(c->dec_firsttablen-c->dec_codelengths[i]));j++)
  104842. c->dec_firsttable[orig|(j<<c->dec_codelengths[i])]=i+1;
  104843. }
  104844. }
  104845. {
  104846. ogg_uint32_t mask=0xfffffffeUL<<(31-c->dec_firsttablen);
  104847. long lo=0,hi=0;
  104848. for(i=0;i<tabn;i++){
  104849. ogg_uint32_t word=i<<(32-c->dec_firsttablen);
  104850. if(c->dec_firsttable[ogg_bitreverse(word)]==0){
  104851. while((lo+1)<n && c->codelist[lo+1]<=word)lo++;
  104852. while( hi<n && word>=(c->codelist[hi]&mask))hi++;
  104853. {
  104854. unsigned long loval=lo;
  104855. unsigned long hival=n-hi;
  104856. if(loval>0x7fff)loval=0x7fff;
  104857. if(hival>0x7fff)hival=0x7fff;
  104858. c->dec_firsttable[ogg_bitreverse(word)]=
  104859. 0x80000000UL | (loval<<15) | hival;
  104860. }
  104861. }
  104862. }
  104863. }
  104864. return(0);
  104865. err_out:
  104866. vorbis_book_clear(c);
  104867. return(-1);
  104868. }
  104869. static float _dist(int el,float *ref, float *b,int step){
  104870. int i;
  104871. float acc=0.f;
  104872. for(i=0;i<el;i++){
  104873. float val=(ref[i]-b[i*step]);
  104874. acc+=val*val;
  104875. }
  104876. return(acc);
  104877. }
  104878. int _best(codebook *book, float *a, int step){
  104879. encode_aux_threshmatch *tt=book->c->thresh_tree;
  104880. #if 0
  104881. encode_aux_nearestmatch *nt=book->c->nearest_tree;
  104882. encode_aux_pigeonhole *pt=book->c->pigeon_tree;
  104883. #endif
  104884. int dim=book->dim;
  104885. int k,o;
  104886. if(tt){
  104887. int index=0,i;
  104888. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  104889. i=tt->threshvals>>1;
  104890. if(a[o]<tt->quantthresh[i]){
  104891. for(;i>0;i--)
  104892. if(a[o]>=tt->quantthresh[i-1])
  104893. break;
  104894. }else{
  104895. for(i++;i<tt->threshvals-1;i++)
  104896. if(a[o]<tt->quantthresh[i])break;
  104897. }
  104898. index=(index*tt->quantvals)+tt->quantmap[i];
  104899. }
  104900. if(book->c->lengthlist[index]>0) /* is this unused? If so, we'll
  104901. use a decision tree after all
  104902. and fall through*/
  104903. return(index);
  104904. }
  104905. #if 0
  104906. if(pt){
  104907. const static_codebook *c=book->c;
  104908. int i,besti=-1;
  104909. float best=0.f;
  104910. int entry=0;
  104911. if(c->q_sequencep){
  104912. int pv;
  104913. long mul=1;
  104914. float qlast=0;
  104915. for(k=0,o=0;k<dim;k++,o+=step){
  104916. pv=(int)((a[o]-qlast-pt->min)/pt->del);
  104917. if(pv<0 || pv>=pt->mapentries)break;
  104918. entry+=pt->pigeonmap[pv]*mul;
  104919. mul*=pt->quantvals;
  104920. qlast+=pv*pt->del+pt->min;
  104921. }
  104922. }else{
  104923. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  104924. int pv=(int)((a[o]-pt->min)/pt->del);
  104925. if(pv<0 || pv>=pt->mapentries)break;
  104926. entry=entry*pt->quantvals+pt->pigeonmap[pv];
  104927. }
  104928. }
  104929. if(k==dim && pt->fitlength[entry]){
  104930. long *list=pt->fitlist+pt->fitmap[entry];
  104931. for(i=0;i<pt->fitlength[entry];i++){
  104932. float this=_dist(dim,book->valuelist+list[i]*dim,a,step);
  104933. if(besti==-1 || this<best){
  104934. best=this;
  104935. besti=list[i];
  104936. }
  104937. }
  104938. return(besti);
  104939. }
  104940. }
  104941. if(nt){
  104942. while(1){
  104943. float c=0.f;
  104944. float *p=book->valuelist+nt->p[ptr];
  104945. float *q=book->valuelist+nt->q[ptr];
  104946. for(k=0,o=0;k<dim;k++,o+=step)
  104947. c+=(p[k]-q[k])*(a[o]-(p[k]+q[k])*.5);
  104948. if(c>0.f) /* in A */
  104949. ptr= -nt->ptr0[ptr];
  104950. else /* in B */
  104951. ptr= -nt->ptr1[ptr];
  104952. if(ptr<=0)break;
  104953. }
  104954. return(-ptr);
  104955. }
  104956. #endif
  104957. {
  104958. const static_codebook *c=book->c;
  104959. int i,besti=-1;
  104960. float best=0.f;
  104961. float *e=book->valuelist;
  104962. for(i=0;i<book->entries;i++){
  104963. if(c->lengthlist[i]>0){
  104964. float thisx=_dist(dim,e,a,step);
  104965. if(besti==-1 || thisx<best){
  104966. best=thisx;
  104967. besti=i;
  104968. }
  104969. }
  104970. e+=dim;
  104971. }
  104972. return(besti);
  104973. }
  104974. }
  104975. long vorbis_book_codeword(codebook *book,int entry){
  104976. if(book->c) /* only use with encode; decode optimizations are
  104977. allowed to break this */
  104978. return book->codelist[entry];
  104979. return -1;
  104980. }
  104981. long vorbis_book_codelen(codebook *book,int entry){
  104982. if(book->c) /* only use with encode; decode optimizations are
  104983. allowed to break this */
  104984. return book->c->lengthlist[entry];
  104985. return -1;
  104986. }
  104987. #ifdef _V_SELFTEST
  104988. #include <stdio.h>
  104989. static long full_quantlist1[]={0,1,2,3, 4,5,6,7, 8,3,6,1};
  104990. static long partial_quantlist1[]={0,7,2};
  104991. static_codebook test1={
  104992. 4,16,
  104993. NULL,
  104994. 0,
  104995. 0,0,0,0,
  104996. NULL,
  104997. NULL,NULL
  104998. };
  104999. static float *test1_result=NULL;
  105000. static_codebook test2={
  105001. 4,3,
  105002. NULL,
  105003. 2,
  105004. -533200896,1611661312,4,0,
  105005. full_quantlist1,
  105006. NULL,NULL
  105007. };
  105008. static float test2_result[]={-3,-2,-1,0, 1,2,3,4, 5,0,3,-2};
  105009. static_codebook test3={
  105010. 4,3,
  105011. NULL,
  105012. 2,
  105013. -533200896,1611661312,4,1,
  105014. full_quantlist1,
  105015. NULL,NULL
  105016. };
  105017. static float test3_result[]={-3,-5,-6,-6, 1,3,6,10, 5,5,8,6};
  105018. static_codebook test4={
  105019. 3,27,
  105020. NULL,
  105021. 1,
  105022. -533200896,1611661312,4,0,
  105023. partial_quantlist1,
  105024. NULL,NULL
  105025. };
  105026. static float test4_result[]={-3,-3,-3, 4,-3,-3, -1,-3,-3,
  105027. -3, 4,-3, 4, 4,-3, -1, 4,-3,
  105028. -3,-1,-3, 4,-1,-3, -1,-1,-3,
  105029. -3,-3, 4, 4,-3, 4, -1,-3, 4,
  105030. -3, 4, 4, 4, 4, 4, -1, 4, 4,
  105031. -3,-1, 4, 4,-1, 4, -1,-1, 4,
  105032. -3,-3,-1, 4,-3,-1, -1,-3,-1,
  105033. -3, 4,-1, 4, 4,-1, -1, 4,-1,
  105034. -3,-1,-1, 4,-1,-1, -1,-1,-1};
  105035. static_codebook test5={
  105036. 3,27,
  105037. NULL,
  105038. 1,
  105039. -533200896,1611661312,4,1,
  105040. partial_quantlist1,
  105041. NULL,NULL
  105042. };
  105043. static float test5_result[]={-3,-6,-9, 4, 1,-2, -1,-4,-7,
  105044. -3, 1,-2, 4, 8, 5, -1, 3, 0,
  105045. -3,-4,-7, 4, 3, 0, -1,-2,-5,
  105046. -3,-6,-2, 4, 1, 5, -1,-4, 0,
  105047. -3, 1, 5, 4, 8,12, -1, 3, 7,
  105048. -3,-4, 0, 4, 3, 7, -1,-2, 2,
  105049. -3,-6,-7, 4, 1, 0, -1,-4,-5,
  105050. -3, 1, 0, 4, 8, 7, -1, 3, 2,
  105051. -3,-4,-5, 4, 3, 2, -1,-2,-3};
  105052. void run_test(static_codebook *b,float *comp){
  105053. float *out=_book_unquantize(b,b->entries,NULL);
  105054. int i;
  105055. if(comp){
  105056. if(!out){
  105057. fprintf(stderr,"_book_unquantize incorrectly returned NULL\n");
  105058. exit(1);
  105059. }
  105060. for(i=0;i<b->entries*b->dim;i++)
  105061. if(fabs(out[i]-comp[i])>.0001){
  105062. fprintf(stderr,"disagreement in unquantized and reference data:\n"
  105063. "position %d, %g != %g\n",i,out[i],comp[i]);
  105064. exit(1);
  105065. }
  105066. }else{
  105067. if(out){
  105068. fprintf(stderr,"_book_unquantize returned a value array: \n"
  105069. " correct result should have been NULL\n");
  105070. exit(1);
  105071. }
  105072. }
  105073. }
  105074. int main(){
  105075. fprintf(stderr,"Dequant test 1... ");
  105076. run_test(&test1,test1_result);
  105077. fprintf(stderr,"OK\nDequant test 2... ");
  105078. run_test(&test2,test2_result);
  105079. fprintf(stderr,"OK\nDequant test 3... ");
  105080. run_test(&test3,test3_result);
  105081. fprintf(stderr,"OK\nDequant test 4... ");
  105082. run_test(&test4,test4_result);
  105083. fprintf(stderr,"OK\nDequant test 5... ");
  105084. run_test(&test5,test5_result);
  105085. fprintf(stderr,"OK\n\n");
  105086. return(0);
  105087. }
  105088. #endif
  105089. #endif
  105090. /*** End of inlined file: sharedbook.c ***/
  105091. /*** Start of inlined file: smallft.c ***/
  105092. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  105093. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  105094. // tasks..
  105095. #if JUCE_MSVC
  105096. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  105097. #endif
  105098. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  105099. #if JUCE_USE_OGGVORBIS
  105100. #include <stdlib.h>
  105101. #include <string.h>
  105102. #include <math.h>
  105103. static void drfti1(int n, float *wa, int *ifac){
  105104. static int ntryh[4] = { 4,2,3,5 };
  105105. static float tpi = 6.28318530717958648f;
  105106. float arg,argh,argld,fi;
  105107. int ntry=0,i,j=-1;
  105108. int k1, l1, l2, ib;
  105109. int ld, ii, ip, is, nq, nr;
  105110. int ido, ipm, nfm1;
  105111. int nl=n;
  105112. int nf=0;
  105113. L101:
  105114. j++;
  105115. if (j < 4)
  105116. ntry=ntryh[j];
  105117. else
  105118. ntry+=2;
  105119. L104:
  105120. nq=nl/ntry;
  105121. nr=nl-ntry*nq;
  105122. if (nr!=0) goto L101;
  105123. nf++;
  105124. ifac[nf+1]=ntry;
  105125. nl=nq;
  105126. if(ntry!=2)goto L107;
  105127. if(nf==1)goto L107;
  105128. for (i=1;i<nf;i++){
  105129. ib=nf-i+1;
  105130. ifac[ib+1]=ifac[ib];
  105131. }
  105132. ifac[2] = 2;
  105133. L107:
  105134. if(nl!=1)goto L104;
  105135. ifac[0]=n;
  105136. ifac[1]=nf;
  105137. argh=tpi/n;
  105138. is=0;
  105139. nfm1=nf-1;
  105140. l1=1;
  105141. if(nfm1==0)return;
  105142. for (k1=0;k1<nfm1;k1++){
  105143. ip=ifac[k1+2];
  105144. ld=0;
  105145. l2=l1*ip;
  105146. ido=n/l2;
  105147. ipm=ip-1;
  105148. for (j=0;j<ipm;j++){
  105149. ld+=l1;
  105150. i=is;
  105151. argld=(float)ld*argh;
  105152. fi=0.f;
  105153. for (ii=2;ii<ido;ii+=2){
  105154. fi+=1.f;
  105155. arg=fi*argld;
  105156. wa[i++]=cos(arg);
  105157. wa[i++]=sin(arg);
  105158. }
  105159. is+=ido;
  105160. }
  105161. l1=l2;
  105162. }
  105163. }
  105164. static void fdrffti(int n, float *wsave, int *ifac){
  105165. if (n == 1) return;
  105166. drfti1(n, wsave+n, ifac);
  105167. }
  105168. static void dradf2(int ido,int l1,float *cc,float *ch,float *wa1){
  105169. int i,k;
  105170. float ti2,tr2;
  105171. int t0,t1,t2,t3,t4,t5,t6;
  105172. t1=0;
  105173. t0=(t2=l1*ido);
  105174. t3=ido<<1;
  105175. for(k=0;k<l1;k++){
  105176. ch[t1<<1]=cc[t1]+cc[t2];
  105177. ch[(t1<<1)+t3-1]=cc[t1]-cc[t2];
  105178. t1+=ido;
  105179. t2+=ido;
  105180. }
  105181. if(ido<2)return;
  105182. if(ido==2)goto L105;
  105183. t1=0;
  105184. t2=t0;
  105185. for(k=0;k<l1;k++){
  105186. t3=t2;
  105187. t4=(t1<<1)+(ido<<1);
  105188. t5=t1;
  105189. t6=t1+t1;
  105190. for(i=2;i<ido;i+=2){
  105191. t3+=2;
  105192. t4-=2;
  105193. t5+=2;
  105194. t6+=2;
  105195. tr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105196. ti2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105197. ch[t6]=cc[t5]+ti2;
  105198. ch[t4]=ti2-cc[t5];
  105199. ch[t6-1]=cc[t5-1]+tr2;
  105200. ch[t4-1]=cc[t5-1]-tr2;
  105201. }
  105202. t1+=ido;
  105203. t2+=ido;
  105204. }
  105205. if(ido%2==1)return;
  105206. L105:
  105207. t3=(t2=(t1=ido)-1);
  105208. t2+=t0;
  105209. for(k=0;k<l1;k++){
  105210. ch[t1]=-cc[t2];
  105211. ch[t1-1]=cc[t3];
  105212. t1+=ido<<1;
  105213. t2+=ido;
  105214. t3+=ido;
  105215. }
  105216. }
  105217. static void dradf4(int ido,int l1,float *cc,float *ch,float *wa1,
  105218. float *wa2,float *wa3){
  105219. static float hsqt2 = .70710678118654752f;
  105220. int i,k,t0,t1,t2,t3,t4,t5,t6;
  105221. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  105222. t0=l1*ido;
  105223. t1=t0;
  105224. t4=t1<<1;
  105225. t2=t1+(t1<<1);
  105226. t3=0;
  105227. for(k=0;k<l1;k++){
  105228. tr1=cc[t1]+cc[t2];
  105229. tr2=cc[t3]+cc[t4];
  105230. ch[t5=t3<<2]=tr1+tr2;
  105231. ch[(ido<<2)+t5-1]=tr2-tr1;
  105232. ch[(t5+=(ido<<1))-1]=cc[t3]-cc[t4];
  105233. ch[t5]=cc[t2]-cc[t1];
  105234. t1+=ido;
  105235. t2+=ido;
  105236. t3+=ido;
  105237. t4+=ido;
  105238. }
  105239. if(ido<2)return;
  105240. if(ido==2)goto L105;
  105241. t1=0;
  105242. for(k=0;k<l1;k++){
  105243. t2=t1;
  105244. t4=t1<<2;
  105245. t5=(t6=ido<<1)+t4;
  105246. for(i=2;i<ido;i+=2){
  105247. t3=(t2+=2);
  105248. t4+=2;
  105249. t5-=2;
  105250. t3+=t0;
  105251. cr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105252. ci2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105253. t3+=t0;
  105254. cr3=wa2[i-2]*cc[t3-1]+wa2[i-1]*cc[t3];
  105255. ci3=wa2[i-2]*cc[t3]-wa2[i-1]*cc[t3-1];
  105256. t3+=t0;
  105257. cr4=wa3[i-2]*cc[t3-1]+wa3[i-1]*cc[t3];
  105258. ci4=wa3[i-2]*cc[t3]-wa3[i-1]*cc[t3-1];
  105259. tr1=cr2+cr4;
  105260. tr4=cr4-cr2;
  105261. ti1=ci2+ci4;
  105262. ti4=ci2-ci4;
  105263. ti2=cc[t2]+ci3;
  105264. ti3=cc[t2]-ci3;
  105265. tr2=cc[t2-1]+cr3;
  105266. tr3=cc[t2-1]-cr3;
  105267. ch[t4-1]=tr1+tr2;
  105268. ch[t4]=ti1+ti2;
  105269. ch[t5-1]=tr3-ti4;
  105270. ch[t5]=tr4-ti3;
  105271. ch[t4+t6-1]=ti4+tr3;
  105272. ch[t4+t6]=tr4+ti3;
  105273. ch[t5+t6-1]=tr2-tr1;
  105274. ch[t5+t6]=ti1-ti2;
  105275. }
  105276. t1+=ido;
  105277. }
  105278. if(ido&1)return;
  105279. L105:
  105280. t2=(t1=t0+ido-1)+(t0<<1);
  105281. t3=ido<<2;
  105282. t4=ido;
  105283. t5=ido<<1;
  105284. t6=ido;
  105285. for(k=0;k<l1;k++){
  105286. ti1=-hsqt2*(cc[t1]+cc[t2]);
  105287. tr1=hsqt2*(cc[t1]-cc[t2]);
  105288. ch[t4-1]=tr1+cc[t6-1];
  105289. ch[t4+t5-1]=cc[t6-1]-tr1;
  105290. ch[t4]=ti1-cc[t1+t0];
  105291. ch[t4+t5]=ti1+cc[t1+t0];
  105292. t1+=ido;
  105293. t2+=ido;
  105294. t4+=t3;
  105295. t6+=ido;
  105296. }
  105297. }
  105298. static void dradfg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  105299. float *c2,float *ch,float *ch2,float *wa){
  105300. static float tpi=6.283185307179586f;
  105301. int idij,ipph,i,j,k,l,ic,ik,is;
  105302. int t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  105303. float dc2,ai1,ai2,ar1,ar2,ds2;
  105304. int nbd;
  105305. float dcp,arg,dsp,ar1h,ar2h;
  105306. int idp2,ipp2;
  105307. arg=tpi/(float)ip;
  105308. dcp=cos(arg);
  105309. dsp=sin(arg);
  105310. ipph=(ip+1)>>1;
  105311. ipp2=ip;
  105312. idp2=ido;
  105313. nbd=(ido-1)>>1;
  105314. t0=l1*ido;
  105315. t10=ip*ido;
  105316. if(ido==1)goto L119;
  105317. for(ik=0;ik<idl1;ik++)ch2[ik]=c2[ik];
  105318. t1=0;
  105319. for(j=1;j<ip;j++){
  105320. t1+=t0;
  105321. t2=t1;
  105322. for(k=0;k<l1;k++){
  105323. ch[t2]=c1[t2];
  105324. t2+=ido;
  105325. }
  105326. }
  105327. is=-ido;
  105328. t1=0;
  105329. if(nbd>l1){
  105330. for(j=1;j<ip;j++){
  105331. t1+=t0;
  105332. is+=ido;
  105333. t2= -ido+t1;
  105334. for(k=0;k<l1;k++){
  105335. idij=is-1;
  105336. t2+=ido;
  105337. t3=t2;
  105338. for(i=2;i<ido;i+=2){
  105339. idij+=2;
  105340. t3+=2;
  105341. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105342. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105343. }
  105344. }
  105345. }
  105346. }else{
  105347. for(j=1;j<ip;j++){
  105348. is+=ido;
  105349. idij=is-1;
  105350. t1+=t0;
  105351. t2=t1;
  105352. for(i=2;i<ido;i+=2){
  105353. idij+=2;
  105354. t2+=2;
  105355. t3=t2;
  105356. for(k=0;k<l1;k++){
  105357. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105358. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105359. t3+=ido;
  105360. }
  105361. }
  105362. }
  105363. }
  105364. t1=0;
  105365. t2=ipp2*t0;
  105366. if(nbd<l1){
  105367. for(j=1;j<ipph;j++){
  105368. t1+=t0;
  105369. t2-=t0;
  105370. t3=t1;
  105371. t4=t2;
  105372. for(i=2;i<ido;i+=2){
  105373. t3+=2;
  105374. t4+=2;
  105375. t5=t3-ido;
  105376. t6=t4-ido;
  105377. for(k=0;k<l1;k++){
  105378. t5+=ido;
  105379. t6+=ido;
  105380. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105381. c1[t6-1]=ch[t5]-ch[t6];
  105382. c1[t5]=ch[t5]+ch[t6];
  105383. c1[t6]=ch[t6-1]-ch[t5-1];
  105384. }
  105385. }
  105386. }
  105387. }else{
  105388. for(j=1;j<ipph;j++){
  105389. t1+=t0;
  105390. t2-=t0;
  105391. t3=t1;
  105392. t4=t2;
  105393. for(k=0;k<l1;k++){
  105394. t5=t3;
  105395. t6=t4;
  105396. for(i=2;i<ido;i+=2){
  105397. t5+=2;
  105398. t6+=2;
  105399. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105400. c1[t6-1]=ch[t5]-ch[t6];
  105401. c1[t5]=ch[t5]+ch[t6];
  105402. c1[t6]=ch[t6-1]-ch[t5-1];
  105403. }
  105404. t3+=ido;
  105405. t4+=ido;
  105406. }
  105407. }
  105408. }
  105409. L119:
  105410. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  105411. t1=0;
  105412. t2=ipp2*idl1;
  105413. for(j=1;j<ipph;j++){
  105414. t1+=t0;
  105415. t2-=t0;
  105416. t3=t1-ido;
  105417. t4=t2-ido;
  105418. for(k=0;k<l1;k++){
  105419. t3+=ido;
  105420. t4+=ido;
  105421. c1[t3]=ch[t3]+ch[t4];
  105422. c1[t4]=ch[t4]-ch[t3];
  105423. }
  105424. }
  105425. ar1=1.f;
  105426. ai1=0.f;
  105427. t1=0;
  105428. t2=ipp2*idl1;
  105429. t3=(ip-1)*idl1;
  105430. for(l=1;l<ipph;l++){
  105431. t1+=idl1;
  105432. t2-=idl1;
  105433. ar1h=dcp*ar1-dsp*ai1;
  105434. ai1=dcp*ai1+dsp*ar1;
  105435. ar1=ar1h;
  105436. t4=t1;
  105437. t5=t2;
  105438. t6=t3;
  105439. t7=idl1;
  105440. for(ik=0;ik<idl1;ik++){
  105441. ch2[t4++]=c2[ik]+ar1*c2[t7++];
  105442. ch2[t5++]=ai1*c2[t6++];
  105443. }
  105444. dc2=ar1;
  105445. ds2=ai1;
  105446. ar2=ar1;
  105447. ai2=ai1;
  105448. t4=idl1;
  105449. t5=(ipp2-1)*idl1;
  105450. for(j=2;j<ipph;j++){
  105451. t4+=idl1;
  105452. t5-=idl1;
  105453. ar2h=dc2*ar2-ds2*ai2;
  105454. ai2=dc2*ai2+ds2*ar2;
  105455. ar2=ar2h;
  105456. t6=t1;
  105457. t7=t2;
  105458. t8=t4;
  105459. t9=t5;
  105460. for(ik=0;ik<idl1;ik++){
  105461. ch2[t6++]+=ar2*c2[t8++];
  105462. ch2[t7++]+=ai2*c2[t9++];
  105463. }
  105464. }
  105465. }
  105466. t1=0;
  105467. for(j=1;j<ipph;j++){
  105468. t1+=idl1;
  105469. t2=t1;
  105470. for(ik=0;ik<idl1;ik++)ch2[ik]+=c2[t2++];
  105471. }
  105472. if(ido<l1)goto L132;
  105473. t1=0;
  105474. t2=0;
  105475. for(k=0;k<l1;k++){
  105476. t3=t1;
  105477. t4=t2;
  105478. for(i=0;i<ido;i++)cc[t4++]=ch[t3++];
  105479. t1+=ido;
  105480. t2+=t10;
  105481. }
  105482. goto L135;
  105483. L132:
  105484. for(i=0;i<ido;i++){
  105485. t1=i;
  105486. t2=i;
  105487. for(k=0;k<l1;k++){
  105488. cc[t2]=ch[t1];
  105489. t1+=ido;
  105490. t2+=t10;
  105491. }
  105492. }
  105493. L135:
  105494. t1=0;
  105495. t2=ido<<1;
  105496. t3=0;
  105497. t4=ipp2*t0;
  105498. for(j=1;j<ipph;j++){
  105499. t1+=t2;
  105500. t3+=t0;
  105501. t4-=t0;
  105502. t5=t1;
  105503. t6=t3;
  105504. t7=t4;
  105505. for(k=0;k<l1;k++){
  105506. cc[t5-1]=ch[t6];
  105507. cc[t5]=ch[t7];
  105508. t5+=t10;
  105509. t6+=ido;
  105510. t7+=ido;
  105511. }
  105512. }
  105513. if(ido==1)return;
  105514. if(nbd<l1)goto L141;
  105515. t1=-ido;
  105516. t3=0;
  105517. t4=0;
  105518. t5=ipp2*t0;
  105519. for(j=1;j<ipph;j++){
  105520. t1+=t2;
  105521. t3+=t2;
  105522. t4+=t0;
  105523. t5-=t0;
  105524. t6=t1;
  105525. t7=t3;
  105526. t8=t4;
  105527. t9=t5;
  105528. for(k=0;k<l1;k++){
  105529. for(i=2;i<ido;i+=2){
  105530. ic=idp2-i;
  105531. cc[i+t7-1]=ch[i+t8-1]+ch[i+t9-1];
  105532. cc[ic+t6-1]=ch[i+t8-1]-ch[i+t9-1];
  105533. cc[i+t7]=ch[i+t8]+ch[i+t9];
  105534. cc[ic+t6]=ch[i+t9]-ch[i+t8];
  105535. }
  105536. t6+=t10;
  105537. t7+=t10;
  105538. t8+=ido;
  105539. t9+=ido;
  105540. }
  105541. }
  105542. return;
  105543. L141:
  105544. t1=-ido;
  105545. t3=0;
  105546. t4=0;
  105547. t5=ipp2*t0;
  105548. for(j=1;j<ipph;j++){
  105549. t1+=t2;
  105550. t3+=t2;
  105551. t4+=t0;
  105552. t5-=t0;
  105553. for(i=2;i<ido;i+=2){
  105554. t6=idp2+t1-i;
  105555. t7=i+t3;
  105556. t8=i+t4;
  105557. t9=i+t5;
  105558. for(k=0;k<l1;k++){
  105559. cc[t7-1]=ch[t8-1]+ch[t9-1];
  105560. cc[t6-1]=ch[t8-1]-ch[t9-1];
  105561. cc[t7]=ch[t8]+ch[t9];
  105562. cc[t6]=ch[t9]-ch[t8];
  105563. t6+=t10;
  105564. t7+=t10;
  105565. t8+=ido;
  105566. t9+=ido;
  105567. }
  105568. }
  105569. }
  105570. }
  105571. static void drftf1(int n,float *c,float *ch,float *wa,int *ifac){
  105572. int i,k1,l1,l2;
  105573. int na,kh,nf;
  105574. int ip,iw,ido,idl1,ix2,ix3;
  105575. nf=ifac[1];
  105576. na=1;
  105577. l2=n;
  105578. iw=n;
  105579. for(k1=0;k1<nf;k1++){
  105580. kh=nf-k1;
  105581. ip=ifac[kh+1];
  105582. l1=l2/ip;
  105583. ido=n/l2;
  105584. idl1=ido*l1;
  105585. iw-=(ip-1)*ido;
  105586. na=1-na;
  105587. if(ip!=4)goto L102;
  105588. ix2=iw+ido;
  105589. ix3=ix2+ido;
  105590. if(na!=0)
  105591. dradf4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105592. else
  105593. dradf4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105594. goto L110;
  105595. L102:
  105596. if(ip!=2)goto L104;
  105597. if(na!=0)goto L103;
  105598. dradf2(ido,l1,c,ch,wa+iw-1);
  105599. goto L110;
  105600. L103:
  105601. dradf2(ido,l1,ch,c,wa+iw-1);
  105602. goto L110;
  105603. L104:
  105604. if(ido==1)na=1-na;
  105605. if(na!=0)goto L109;
  105606. dradfg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  105607. na=1;
  105608. goto L110;
  105609. L109:
  105610. dradfg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  105611. na=0;
  105612. L110:
  105613. l2=l1;
  105614. }
  105615. if(na==1)return;
  105616. for(i=0;i<n;i++)c[i]=ch[i];
  105617. }
  105618. static void dradb2(int ido,int l1,float *cc,float *ch,float *wa1){
  105619. int i,k,t0,t1,t2,t3,t4,t5,t6;
  105620. float ti2,tr2;
  105621. t0=l1*ido;
  105622. t1=0;
  105623. t2=0;
  105624. t3=(ido<<1)-1;
  105625. for(k=0;k<l1;k++){
  105626. ch[t1]=cc[t2]+cc[t3+t2];
  105627. ch[t1+t0]=cc[t2]-cc[t3+t2];
  105628. t2=(t1+=ido)<<1;
  105629. }
  105630. if(ido<2)return;
  105631. if(ido==2)goto L105;
  105632. t1=0;
  105633. t2=0;
  105634. for(k=0;k<l1;k++){
  105635. t3=t1;
  105636. t5=(t4=t2)+(ido<<1);
  105637. t6=t0+t1;
  105638. for(i=2;i<ido;i+=2){
  105639. t3+=2;
  105640. t4+=2;
  105641. t5-=2;
  105642. t6+=2;
  105643. ch[t3-1]=cc[t4-1]+cc[t5-1];
  105644. tr2=cc[t4-1]-cc[t5-1];
  105645. ch[t3]=cc[t4]-cc[t5];
  105646. ti2=cc[t4]+cc[t5];
  105647. ch[t6-1]=wa1[i-2]*tr2-wa1[i-1]*ti2;
  105648. ch[t6]=wa1[i-2]*ti2+wa1[i-1]*tr2;
  105649. }
  105650. t2=(t1+=ido)<<1;
  105651. }
  105652. if(ido%2==1)return;
  105653. L105:
  105654. t1=ido-1;
  105655. t2=ido-1;
  105656. for(k=0;k<l1;k++){
  105657. ch[t1]=cc[t2]+cc[t2];
  105658. ch[t1+t0]=-(cc[t2+1]+cc[t2+1]);
  105659. t1+=ido;
  105660. t2+=ido<<1;
  105661. }
  105662. }
  105663. static void dradb3(int ido,int l1,float *cc,float *ch,float *wa1,
  105664. float *wa2){
  105665. static float taur = -.5f;
  105666. static float taui = .8660254037844386f;
  105667. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  105668. float ci2,ci3,di2,di3,cr2,cr3,dr2,dr3,ti2,tr2;
  105669. t0=l1*ido;
  105670. t1=0;
  105671. t2=t0<<1;
  105672. t3=ido<<1;
  105673. t4=ido+(ido<<1);
  105674. t5=0;
  105675. for(k=0;k<l1;k++){
  105676. tr2=cc[t3-1]+cc[t3-1];
  105677. cr2=cc[t5]+(taur*tr2);
  105678. ch[t1]=cc[t5]+tr2;
  105679. ci3=taui*(cc[t3]+cc[t3]);
  105680. ch[t1+t0]=cr2-ci3;
  105681. ch[t1+t2]=cr2+ci3;
  105682. t1+=ido;
  105683. t3+=t4;
  105684. t5+=t4;
  105685. }
  105686. if(ido==1)return;
  105687. t1=0;
  105688. t3=ido<<1;
  105689. for(k=0;k<l1;k++){
  105690. t7=t1+(t1<<1);
  105691. t6=(t5=t7+t3);
  105692. t8=t1;
  105693. t10=(t9=t1+t0)+t0;
  105694. for(i=2;i<ido;i+=2){
  105695. t5+=2;
  105696. t6-=2;
  105697. t7+=2;
  105698. t8+=2;
  105699. t9+=2;
  105700. t10+=2;
  105701. tr2=cc[t5-1]+cc[t6-1];
  105702. cr2=cc[t7-1]+(taur*tr2);
  105703. ch[t8-1]=cc[t7-1]+tr2;
  105704. ti2=cc[t5]-cc[t6];
  105705. ci2=cc[t7]+(taur*ti2);
  105706. ch[t8]=cc[t7]+ti2;
  105707. cr3=taui*(cc[t5-1]-cc[t6-1]);
  105708. ci3=taui*(cc[t5]+cc[t6]);
  105709. dr2=cr2-ci3;
  105710. dr3=cr2+ci3;
  105711. di2=ci2+cr3;
  105712. di3=ci2-cr3;
  105713. ch[t9-1]=wa1[i-2]*dr2-wa1[i-1]*di2;
  105714. ch[t9]=wa1[i-2]*di2+wa1[i-1]*dr2;
  105715. ch[t10-1]=wa2[i-2]*dr3-wa2[i-1]*di3;
  105716. ch[t10]=wa2[i-2]*di3+wa2[i-1]*dr3;
  105717. }
  105718. t1+=ido;
  105719. }
  105720. }
  105721. static void dradb4(int ido,int l1,float *cc,float *ch,float *wa1,
  105722. float *wa2,float *wa3){
  105723. static float sqrt2=1.414213562373095f;
  105724. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8;
  105725. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  105726. t0=l1*ido;
  105727. t1=0;
  105728. t2=ido<<2;
  105729. t3=0;
  105730. t6=ido<<1;
  105731. for(k=0;k<l1;k++){
  105732. t4=t3+t6;
  105733. t5=t1;
  105734. tr3=cc[t4-1]+cc[t4-1];
  105735. tr4=cc[t4]+cc[t4];
  105736. tr1=cc[t3]-cc[(t4+=t6)-1];
  105737. tr2=cc[t3]+cc[t4-1];
  105738. ch[t5]=tr2+tr3;
  105739. ch[t5+=t0]=tr1-tr4;
  105740. ch[t5+=t0]=tr2-tr3;
  105741. ch[t5+=t0]=tr1+tr4;
  105742. t1+=ido;
  105743. t3+=t2;
  105744. }
  105745. if(ido<2)return;
  105746. if(ido==2)goto L105;
  105747. t1=0;
  105748. for(k=0;k<l1;k++){
  105749. t5=(t4=(t3=(t2=t1<<2)+t6))+t6;
  105750. t7=t1;
  105751. for(i=2;i<ido;i+=2){
  105752. t2+=2;
  105753. t3+=2;
  105754. t4-=2;
  105755. t5-=2;
  105756. t7+=2;
  105757. ti1=cc[t2]+cc[t5];
  105758. ti2=cc[t2]-cc[t5];
  105759. ti3=cc[t3]-cc[t4];
  105760. tr4=cc[t3]+cc[t4];
  105761. tr1=cc[t2-1]-cc[t5-1];
  105762. tr2=cc[t2-1]+cc[t5-1];
  105763. ti4=cc[t3-1]-cc[t4-1];
  105764. tr3=cc[t3-1]+cc[t4-1];
  105765. ch[t7-1]=tr2+tr3;
  105766. cr3=tr2-tr3;
  105767. ch[t7]=ti2+ti3;
  105768. ci3=ti2-ti3;
  105769. cr2=tr1-tr4;
  105770. cr4=tr1+tr4;
  105771. ci2=ti1+ti4;
  105772. ci4=ti1-ti4;
  105773. ch[(t8=t7+t0)-1]=wa1[i-2]*cr2-wa1[i-1]*ci2;
  105774. ch[t8]=wa1[i-2]*ci2+wa1[i-1]*cr2;
  105775. ch[(t8+=t0)-1]=wa2[i-2]*cr3-wa2[i-1]*ci3;
  105776. ch[t8]=wa2[i-2]*ci3+wa2[i-1]*cr3;
  105777. ch[(t8+=t0)-1]=wa3[i-2]*cr4-wa3[i-1]*ci4;
  105778. ch[t8]=wa3[i-2]*ci4+wa3[i-1]*cr4;
  105779. }
  105780. t1+=ido;
  105781. }
  105782. if(ido%2 == 1)return;
  105783. L105:
  105784. t1=ido;
  105785. t2=ido<<2;
  105786. t3=ido-1;
  105787. t4=ido+(ido<<1);
  105788. for(k=0;k<l1;k++){
  105789. t5=t3;
  105790. ti1=cc[t1]+cc[t4];
  105791. ti2=cc[t4]-cc[t1];
  105792. tr1=cc[t1-1]-cc[t4-1];
  105793. tr2=cc[t1-1]+cc[t4-1];
  105794. ch[t5]=tr2+tr2;
  105795. ch[t5+=t0]=sqrt2*(tr1-ti1);
  105796. ch[t5+=t0]=ti2+ti2;
  105797. ch[t5+=t0]=-sqrt2*(tr1+ti1);
  105798. t3+=ido;
  105799. t1+=t2;
  105800. t4+=t2;
  105801. }
  105802. }
  105803. static void dradbg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  105804. float *c2,float *ch,float *ch2,float *wa){
  105805. static float tpi=6.283185307179586f;
  105806. int idij,ipph,i,j,k,l,ik,is,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,
  105807. t11,t12;
  105808. float dc2,ai1,ai2,ar1,ar2,ds2;
  105809. int nbd;
  105810. float dcp,arg,dsp,ar1h,ar2h;
  105811. int ipp2;
  105812. t10=ip*ido;
  105813. t0=l1*ido;
  105814. arg=tpi/(float)ip;
  105815. dcp=cos(arg);
  105816. dsp=sin(arg);
  105817. nbd=(ido-1)>>1;
  105818. ipp2=ip;
  105819. ipph=(ip+1)>>1;
  105820. if(ido<l1)goto L103;
  105821. t1=0;
  105822. t2=0;
  105823. for(k=0;k<l1;k++){
  105824. t3=t1;
  105825. t4=t2;
  105826. for(i=0;i<ido;i++){
  105827. ch[t3]=cc[t4];
  105828. t3++;
  105829. t4++;
  105830. }
  105831. t1+=ido;
  105832. t2+=t10;
  105833. }
  105834. goto L106;
  105835. L103:
  105836. t1=0;
  105837. for(i=0;i<ido;i++){
  105838. t2=t1;
  105839. t3=t1;
  105840. for(k=0;k<l1;k++){
  105841. ch[t2]=cc[t3];
  105842. t2+=ido;
  105843. t3+=t10;
  105844. }
  105845. t1++;
  105846. }
  105847. L106:
  105848. t1=0;
  105849. t2=ipp2*t0;
  105850. t7=(t5=ido<<1);
  105851. for(j=1;j<ipph;j++){
  105852. t1+=t0;
  105853. t2-=t0;
  105854. t3=t1;
  105855. t4=t2;
  105856. t6=t5;
  105857. for(k=0;k<l1;k++){
  105858. ch[t3]=cc[t6-1]+cc[t6-1];
  105859. ch[t4]=cc[t6]+cc[t6];
  105860. t3+=ido;
  105861. t4+=ido;
  105862. t6+=t10;
  105863. }
  105864. t5+=t7;
  105865. }
  105866. if (ido == 1)goto L116;
  105867. if(nbd<l1)goto L112;
  105868. t1=0;
  105869. t2=ipp2*t0;
  105870. t7=0;
  105871. for(j=1;j<ipph;j++){
  105872. t1+=t0;
  105873. t2-=t0;
  105874. t3=t1;
  105875. t4=t2;
  105876. t7+=(ido<<1);
  105877. t8=t7;
  105878. for(k=0;k<l1;k++){
  105879. t5=t3;
  105880. t6=t4;
  105881. t9=t8;
  105882. t11=t8;
  105883. for(i=2;i<ido;i+=2){
  105884. t5+=2;
  105885. t6+=2;
  105886. t9+=2;
  105887. t11-=2;
  105888. ch[t5-1]=cc[t9-1]+cc[t11-1];
  105889. ch[t6-1]=cc[t9-1]-cc[t11-1];
  105890. ch[t5]=cc[t9]-cc[t11];
  105891. ch[t6]=cc[t9]+cc[t11];
  105892. }
  105893. t3+=ido;
  105894. t4+=ido;
  105895. t8+=t10;
  105896. }
  105897. }
  105898. goto L116;
  105899. L112:
  105900. t1=0;
  105901. t2=ipp2*t0;
  105902. t7=0;
  105903. for(j=1;j<ipph;j++){
  105904. t1+=t0;
  105905. t2-=t0;
  105906. t3=t1;
  105907. t4=t2;
  105908. t7+=(ido<<1);
  105909. t8=t7;
  105910. t9=t7;
  105911. for(i=2;i<ido;i+=2){
  105912. t3+=2;
  105913. t4+=2;
  105914. t8+=2;
  105915. t9-=2;
  105916. t5=t3;
  105917. t6=t4;
  105918. t11=t8;
  105919. t12=t9;
  105920. for(k=0;k<l1;k++){
  105921. ch[t5-1]=cc[t11-1]+cc[t12-1];
  105922. ch[t6-1]=cc[t11-1]-cc[t12-1];
  105923. ch[t5]=cc[t11]-cc[t12];
  105924. ch[t6]=cc[t11]+cc[t12];
  105925. t5+=ido;
  105926. t6+=ido;
  105927. t11+=t10;
  105928. t12+=t10;
  105929. }
  105930. }
  105931. }
  105932. L116:
  105933. ar1=1.f;
  105934. ai1=0.f;
  105935. t1=0;
  105936. t9=(t2=ipp2*idl1);
  105937. t3=(ip-1)*idl1;
  105938. for(l=1;l<ipph;l++){
  105939. t1+=idl1;
  105940. t2-=idl1;
  105941. ar1h=dcp*ar1-dsp*ai1;
  105942. ai1=dcp*ai1+dsp*ar1;
  105943. ar1=ar1h;
  105944. t4=t1;
  105945. t5=t2;
  105946. t6=0;
  105947. t7=idl1;
  105948. t8=t3;
  105949. for(ik=0;ik<idl1;ik++){
  105950. c2[t4++]=ch2[t6++]+ar1*ch2[t7++];
  105951. c2[t5++]=ai1*ch2[t8++];
  105952. }
  105953. dc2=ar1;
  105954. ds2=ai1;
  105955. ar2=ar1;
  105956. ai2=ai1;
  105957. t6=idl1;
  105958. t7=t9-idl1;
  105959. for(j=2;j<ipph;j++){
  105960. t6+=idl1;
  105961. t7-=idl1;
  105962. ar2h=dc2*ar2-ds2*ai2;
  105963. ai2=dc2*ai2+ds2*ar2;
  105964. ar2=ar2h;
  105965. t4=t1;
  105966. t5=t2;
  105967. t11=t6;
  105968. t12=t7;
  105969. for(ik=0;ik<idl1;ik++){
  105970. c2[t4++]+=ar2*ch2[t11++];
  105971. c2[t5++]+=ai2*ch2[t12++];
  105972. }
  105973. }
  105974. }
  105975. t1=0;
  105976. for(j=1;j<ipph;j++){
  105977. t1+=idl1;
  105978. t2=t1;
  105979. for(ik=0;ik<idl1;ik++)ch2[ik]+=ch2[t2++];
  105980. }
  105981. t1=0;
  105982. t2=ipp2*t0;
  105983. for(j=1;j<ipph;j++){
  105984. t1+=t0;
  105985. t2-=t0;
  105986. t3=t1;
  105987. t4=t2;
  105988. for(k=0;k<l1;k++){
  105989. ch[t3]=c1[t3]-c1[t4];
  105990. ch[t4]=c1[t3]+c1[t4];
  105991. t3+=ido;
  105992. t4+=ido;
  105993. }
  105994. }
  105995. if(ido==1)goto L132;
  105996. if(nbd<l1)goto L128;
  105997. t1=0;
  105998. t2=ipp2*t0;
  105999. for(j=1;j<ipph;j++){
  106000. t1+=t0;
  106001. t2-=t0;
  106002. t3=t1;
  106003. t4=t2;
  106004. for(k=0;k<l1;k++){
  106005. t5=t3;
  106006. t6=t4;
  106007. for(i=2;i<ido;i+=2){
  106008. t5+=2;
  106009. t6+=2;
  106010. ch[t5-1]=c1[t5-1]-c1[t6];
  106011. ch[t6-1]=c1[t5-1]+c1[t6];
  106012. ch[t5]=c1[t5]+c1[t6-1];
  106013. ch[t6]=c1[t5]-c1[t6-1];
  106014. }
  106015. t3+=ido;
  106016. t4+=ido;
  106017. }
  106018. }
  106019. goto L132;
  106020. L128:
  106021. t1=0;
  106022. t2=ipp2*t0;
  106023. for(j=1;j<ipph;j++){
  106024. t1+=t0;
  106025. t2-=t0;
  106026. t3=t1;
  106027. t4=t2;
  106028. for(i=2;i<ido;i+=2){
  106029. t3+=2;
  106030. t4+=2;
  106031. t5=t3;
  106032. t6=t4;
  106033. for(k=0;k<l1;k++){
  106034. ch[t5-1]=c1[t5-1]-c1[t6];
  106035. ch[t6-1]=c1[t5-1]+c1[t6];
  106036. ch[t5]=c1[t5]+c1[t6-1];
  106037. ch[t6]=c1[t5]-c1[t6-1];
  106038. t5+=ido;
  106039. t6+=ido;
  106040. }
  106041. }
  106042. }
  106043. L132:
  106044. if(ido==1)return;
  106045. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  106046. t1=0;
  106047. for(j=1;j<ip;j++){
  106048. t2=(t1+=t0);
  106049. for(k=0;k<l1;k++){
  106050. c1[t2]=ch[t2];
  106051. t2+=ido;
  106052. }
  106053. }
  106054. if(nbd>l1)goto L139;
  106055. is= -ido-1;
  106056. t1=0;
  106057. for(j=1;j<ip;j++){
  106058. is+=ido;
  106059. t1+=t0;
  106060. idij=is;
  106061. t2=t1;
  106062. for(i=2;i<ido;i+=2){
  106063. t2+=2;
  106064. idij+=2;
  106065. t3=t2;
  106066. for(k=0;k<l1;k++){
  106067. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106068. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106069. t3+=ido;
  106070. }
  106071. }
  106072. }
  106073. return;
  106074. L139:
  106075. is= -ido-1;
  106076. t1=0;
  106077. for(j=1;j<ip;j++){
  106078. is+=ido;
  106079. t1+=t0;
  106080. t2=t1;
  106081. for(k=0;k<l1;k++){
  106082. idij=is;
  106083. t3=t2;
  106084. for(i=2;i<ido;i+=2){
  106085. idij+=2;
  106086. t3+=2;
  106087. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106088. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106089. }
  106090. t2+=ido;
  106091. }
  106092. }
  106093. }
  106094. static void drftb1(int n, float *c, float *ch, float *wa, int *ifac){
  106095. int i,k1,l1,l2;
  106096. int na;
  106097. int nf,ip,iw,ix2,ix3,ido,idl1;
  106098. nf=ifac[1];
  106099. na=0;
  106100. l1=1;
  106101. iw=1;
  106102. for(k1=0;k1<nf;k1++){
  106103. ip=ifac[k1 + 2];
  106104. l2=ip*l1;
  106105. ido=n/l2;
  106106. idl1=ido*l1;
  106107. if(ip!=4)goto L103;
  106108. ix2=iw+ido;
  106109. ix3=ix2+ido;
  106110. if(na!=0)
  106111. dradb4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106112. else
  106113. dradb4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106114. na=1-na;
  106115. goto L115;
  106116. L103:
  106117. if(ip!=2)goto L106;
  106118. if(na!=0)
  106119. dradb2(ido,l1,ch,c,wa+iw-1);
  106120. else
  106121. dradb2(ido,l1,c,ch,wa+iw-1);
  106122. na=1-na;
  106123. goto L115;
  106124. L106:
  106125. if(ip!=3)goto L109;
  106126. ix2=iw+ido;
  106127. if(na!=0)
  106128. dradb3(ido,l1,ch,c,wa+iw-1,wa+ix2-1);
  106129. else
  106130. dradb3(ido,l1,c,ch,wa+iw-1,wa+ix2-1);
  106131. na=1-na;
  106132. goto L115;
  106133. L109:
  106134. if(na!=0)
  106135. dradbg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  106136. else
  106137. dradbg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  106138. if(ido==1)na=1-na;
  106139. L115:
  106140. l1=l2;
  106141. iw+=(ip-1)*ido;
  106142. }
  106143. if(na==0)return;
  106144. for(i=0;i<n;i++)c[i]=ch[i];
  106145. }
  106146. void drft_forward(drft_lookup *l,float *data){
  106147. if(l->n==1)return;
  106148. drftf1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106149. }
  106150. void drft_backward(drft_lookup *l,float *data){
  106151. if (l->n==1)return;
  106152. drftb1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106153. }
  106154. void drft_init(drft_lookup *l,int n){
  106155. l->n=n;
  106156. l->trigcache=(float*)_ogg_calloc(3*n,sizeof(*l->trigcache));
  106157. l->splitcache=(int*)_ogg_calloc(32,sizeof(*l->splitcache));
  106158. fdrffti(n, l->trigcache, l->splitcache);
  106159. }
  106160. void drft_clear(drft_lookup *l){
  106161. if(l){
  106162. if(l->trigcache)_ogg_free(l->trigcache);
  106163. if(l->splitcache)_ogg_free(l->splitcache);
  106164. memset(l,0,sizeof(*l));
  106165. }
  106166. }
  106167. #endif
  106168. /*** End of inlined file: smallft.c ***/
  106169. /*** Start of inlined file: synthesis.c ***/
  106170. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106171. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106172. // tasks..
  106173. #if JUCE_MSVC
  106174. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106175. #endif
  106176. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106177. #if JUCE_USE_OGGVORBIS
  106178. #include <stdio.h>
  106179. int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
  106180. vorbis_dsp_state *vd=vb->vd;
  106181. private_state *b=(private_state*)vd->backend_state;
  106182. vorbis_info *vi=vd->vi;
  106183. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  106184. oggpack_buffer *opb=&vb->opb;
  106185. int type,mode,i;
  106186. _vorbis_block_ripcord(vb);
  106187. oggpack_readinit(opb,op->packet,op->bytes);
  106188. if(oggpack_read(opb,1)!=0){
  106189. return(OV_ENOTAUDIO);
  106190. }
  106191. mode=oggpack_read(opb,b->modebits);
  106192. if(mode==-1)return(OV_EBADPACKET);
  106193. vb->mode=mode;
  106194. vb->W=ci->mode_param[mode]->blockflag;
  106195. if(vb->W){
  106196. vb->lW=oggpack_read(opb,1);
  106197. vb->nW=oggpack_read(opb,1);
  106198. if(vb->nW==-1) return(OV_EBADPACKET);
  106199. }else{
  106200. vb->lW=0;
  106201. vb->nW=0;
  106202. }
  106203. vb->granulepos=op->granulepos;
  106204. vb->sequence=op->packetno;
  106205. vb->eofflag=op->e_o_s;
  106206. vb->pcmend=ci->blocksizes[vb->W];
  106207. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  106208. for(i=0;i<vi->channels;i++)
  106209. vb->pcm[i]=(float*)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i]));
  106210. type=ci->map_type[ci->mode_param[mode]->mapping];
  106211. return(_mapping_P[type]->inverse(vb,ci->map_param[ci->mode_param[mode]->
  106212. mapping]));
  106213. }
  106214. int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op){
  106215. vorbis_dsp_state *vd=vb->vd;
  106216. private_state *b=(private_state*)vd->backend_state;
  106217. vorbis_info *vi=vd->vi;
  106218. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106219. oggpack_buffer *opb=&vb->opb;
  106220. int mode;
  106221. _vorbis_block_ripcord(vb);
  106222. oggpack_readinit(opb,op->packet,op->bytes);
  106223. if(oggpack_read(opb,1)!=0){
  106224. return(OV_ENOTAUDIO);
  106225. }
  106226. mode=oggpack_read(opb,b->modebits);
  106227. if(mode==-1)return(OV_EBADPACKET);
  106228. vb->mode=mode;
  106229. vb->W=ci->mode_param[mode]->blockflag;
  106230. if(vb->W){
  106231. vb->lW=oggpack_read(opb,1);
  106232. vb->nW=oggpack_read(opb,1);
  106233. if(vb->nW==-1) return(OV_EBADPACKET);
  106234. }else{
  106235. vb->lW=0;
  106236. vb->nW=0;
  106237. }
  106238. vb->granulepos=op->granulepos;
  106239. vb->sequence=op->packetno;
  106240. vb->eofflag=op->e_o_s;
  106241. vb->pcmend=0;
  106242. vb->pcm=NULL;
  106243. return(0);
  106244. }
  106245. long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
  106246. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106247. oggpack_buffer opb;
  106248. int mode;
  106249. oggpack_readinit(&opb,op->packet,op->bytes);
  106250. if(oggpack_read(&opb,1)!=0){
  106251. return(OV_ENOTAUDIO);
  106252. }
  106253. {
  106254. int modebits=0;
  106255. int v=ci->modes;
  106256. while(v>1){
  106257. modebits++;
  106258. v>>=1;
  106259. }
  106260. mode=oggpack_read(&opb,modebits);
  106261. }
  106262. if(mode==-1)return(OV_EBADPACKET);
  106263. return(ci->blocksizes[ci->mode_param[mode]->blockflag]);
  106264. }
  106265. int vorbis_synthesis_halfrate(vorbis_info *vi,int flag){
  106266. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106267. if(ci->blocksizes[0]<=64 && flag)return -1;
  106268. ci->halfrate_flag=(flag?1:0);
  106269. return 0;
  106270. }
  106271. int vorbis_synthesis_halfrate_p(vorbis_info *vi){
  106272. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106273. return ci->halfrate_flag;
  106274. }
  106275. #endif
  106276. /*** End of inlined file: synthesis.c ***/
  106277. /*** Start of inlined file: vorbisenc.c ***/
  106278. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106279. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106280. // tasks..
  106281. #if JUCE_MSVC
  106282. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106283. #endif
  106284. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106285. #if JUCE_USE_OGGVORBIS
  106286. #include <stdlib.h>
  106287. #include <string.h>
  106288. #include <math.h>
  106289. typedef struct {
  106290. static_codebook *books[12][3];
  106291. } static_bookblock;
  106292. typedef struct {
  106293. int res_type;
  106294. int limit_type; /* 0 lowpass limited, 1 point stereo limited */
  106295. vorbis_info_residue0 *res;
  106296. static_codebook *book_aux;
  106297. static_codebook *book_aux_managed;
  106298. static_bookblock *books_base;
  106299. static_bookblock *books_base_managed;
  106300. } vorbis_residue_template;
  106301. typedef struct {
  106302. vorbis_info_mapping0 *map;
  106303. vorbis_residue_template *res;
  106304. } vorbis_mapping_template;
  106305. typedef struct vp_adjblock{
  106306. int block[P_BANDS];
  106307. } vp_adjblock;
  106308. typedef struct {
  106309. int data[NOISE_COMPAND_LEVELS];
  106310. } compandblock;
  106311. typedef struct {
  106312. int att[P_NOISECURVES];
  106313. float boost;
  106314. float decay;
  106315. } att3;
  106316. typedef struct { int data[P_NOISECURVES]; } adj3;
  106317. typedef struct {
  106318. int pre[PACKETBLOBS];
  106319. int post[PACKETBLOBS];
  106320. float kHz[PACKETBLOBS];
  106321. float lowpasskHz[PACKETBLOBS];
  106322. } adj_stereo;
  106323. typedef struct {
  106324. int lo;
  106325. int hi;
  106326. int fixed;
  106327. } noiseguard;
  106328. typedef struct {
  106329. int data[P_NOISECURVES][17];
  106330. } noise3;
  106331. typedef struct {
  106332. int mappings;
  106333. double *rate_mapping;
  106334. double *quality_mapping;
  106335. int coupling_restriction;
  106336. long samplerate_min_restriction;
  106337. long samplerate_max_restriction;
  106338. int *blocksize_short;
  106339. int *blocksize_long;
  106340. att3 *psy_tone_masteratt;
  106341. int *psy_tone_0dB;
  106342. int *psy_tone_dBsuppress;
  106343. vp_adjblock *psy_tone_adj_impulse;
  106344. vp_adjblock *psy_tone_adj_long;
  106345. vp_adjblock *psy_tone_adj_other;
  106346. noiseguard *psy_noiseguards;
  106347. noise3 *psy_noise_bias_impulse;
  106348. noise3 *psy_noise_bias_padding;
  106349. noise3 *psy_noise_bias_trans;
  106350. noise3 *psy_noise_bias_long;
  106351. int *psy_noise_dBsuppress;
  106352. compandblock *psy_noise_compand;
  106353. double *psy_noise_compand_short_mapping;
  106354. double *psy_noise_compand_long_mapping;
  106355. int *psy_noise_normal_start[2];
  106356. int *psy_noise_normal_partition[2];
  106357. double *psy_noise_normal_thresh;
  106358. int *psy_ath_float;
  106359. int *psy_ath_abs;
  106360. double *psy_lowpass;
  106361. vorbis_info_psy_global *global_params;
  106362. double *global_mapping;
  106363. adj_stereo *stereo_modes;
  106364. static_codebook ***floor_books;
  106365. vorbis_info_floor1 *floor_params;
  106366. int *floor_short_mapping;
  106367. int *floor_long_mapping;
  106368. vorbis_mapping_template *maps;
  106369. } ve_setup_data_template;
  106370. static vorbis_info_mode _mode_template[2]={
  106371. {0,0,0,0},
  106372. {1,0,0,1}
  106373. };
  106374. static vorbis_info_mapping0 _map_nominal[2]={
  106375. {1, {0,0}, {0}, {0}, 1,{0},{1}},
  106376. {1, {0,0}, {1}, {1}, 1,{0},{1}}
  106377. };
  106378. /*** Start of inlined file: setup_44.h ***/
  106379. /*** Start of inlined file: floor_all.h ***/
  106380. /*** Start of inlined file: floor_books.h ***/
  106381. static long _huff_lengthlist_line_256x7_0sub1[] = {
  106382. 0, 2, 3, 3, 3, 3, 4, 3, 4,
  106383. };
  106384. static static_codebook _huff_book_line_256x7_0sub1 = {
  106385. 1, 9,
  106386. _huff_lengthlist_line_256x7_0sub1,
  106387. 0, 0, 0, 0, 0,
  106388. NULL,
  106389. NULL,
  106390. NULL,
  106391. NULL,
  106392. 0
  106393. };
  106394. static long _huff_lengthlist_line_256x7_0sub2[] = {
  106395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 4, 3, 5, 3,
  106396. 6, 3, 6, 4, 6, 4, 7, 5, 7,
  106397. };
  106398. static static_codebook _huff_book_line_256x7_0sub2 = {
  106399. 1, 25,
  106400. _huff_lengthlist_line_256x7_0sub2,
  106401. 0, 0, 0, 0, 0,
  106402. NULL,
  106403. NULL,
  106404. NULL,
  106405. NULL,
  106406. 0
  106407. };
  106408. static long _huff_lengthlist_line_256x7_0sub3[] = {
  106409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 2, 5, 3, 5, 3,
  106411. 6, 3, 6, 4, 7, 6, 7, 8, 7, 9, 8, 9, 9, 9,10, 9,
  106412. 11,13,11,13,10,10,13,13,13,13,13,13,12,12,12,12,
  106413. };
  106414. static static_codebook _huff_book_line_256x7_0sub3 = {
  106415. 1, 64,
  106416. _huff_lengthlist_line_256x7_0sub3,
  106417. 0, 0, 0, 0, 0,
  106418. NULL,
  106419. NULL,
  106420. NULL,
  106421. NULL,
  106422. 0
  106423. };
  106424. static long _huff_lengthlist_line_256x7_1sub1[] = {
  106425. 0, 3, 3, 3, 3, 2, 4, 3, 4,
  106426. };
  106427. static static_codebook _huff_book_line_256x7_1sub1 = {
  106428. 1, 9,
  106429. _huff_lengthlist_line_256x7_1sub1,
  106430. 0, 0, 0, 0, 0,
  106431. NULL,
  106432. NULL,
  106433. NULL,
  106434. NULL,
  106435. 0
  106436. };
  106437. static long _huff_lengthlist_line_256x7_1sub2[] = {
  106438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 3, 4, 3, 4, 4,
  106439. 5, 4, 6, 5, 6, 7, 6, 8, 8,
  106440. };
  106441. static static_codebook _huff_book_line_256x7_1sub2 = {
  106442. 1, 25,
  106443. _huff_lengthlist_line_256x7_1sub2,
  106444. 0, 0, 0, 0, 0,
  106445. NULL,
  106446. NULL,
  106447. NULL,
  106448. NULL,
  106449. 0
  106450. };
  106451. static long _huff_lengthlist_line_256x7_1sub3[] = {
  106452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 4, 3, 6, 3, 7,
  106454. 3, 8, 5, 8, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  106455. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7,
  106456. };
  106457. static static_codebook _huff_book_line_256x7_1sub3 = {
  106458. 1, 64,
  106459. _huff_lengthlist_line_256x7_1sub3,
  106460. 0, 0, 0, 0, 0,
  106461. NULL,
  106462. NULL,
  106463. NULL,
  106464. NULL,
  106465. 0
  106466. };
  106467. static long _huff_lengthlist_line_256x7_class0[] = {
  106468. 7, 5, 5, 9, 9, 6, 6, 9,12, 8, 7, 8,11, 8, 9,15,
  106469. 6, 3, 3, 7, 7, 4, 3, 6, 9, 6, 5, 6, 8, 6, 8,15,
  106470. 8, 5, 5, 9, 8, 5, 4, 6,10, 7, 5, 5,11, 8, 7,15,
  106471. 14,15,13,13,13,13, 8,11,15,10, 7, 6,11, 9,10,15,
  106472. };
  106473. static static_codebook _huff_book_line_256x7_class0 = {
  106474. 1, 64,
  106475. _huff_lengthlist_line_256x7_class0,
  106476. 0, 0, 0, 0, 0,
  106477. NULL,
  106478. NULL,
  106479. NULL,
  106480. NULL,
  106481. 0
  106482. };
  106483. static long _huff_lengthlist_line_256x7_class1[] = {
  106484. 5, 6, 8,15, 6, 9,10,15,10,11,12,15,15,15,15,15,
  106485. 4, 6, 7,15, 6, 7, 8,15, 9, 8, 9,15,15,15,15,15,
  106486. 6, 8, 9,15, 7, 7, 8,15,10, 9,10,15,15,15,15,15,
  106487. 15,13,15,15,15,10,11,15,15,13,13,15,15,15,15,15,
  106488. 4, 6, 7,15, 6, 8, 9,15,10,10,12,15,15,15,15,15,
  106489. 2, 5, 6,15, 5, 6, 7,15, 8, 6, 7,15,15,15,15,15,
  106490. 5, 6, 8,15, 5, 6, 7,15, 9, 6, 7,15,15,15,15,15,
  106491. 14,12,13,15,12,10,11,15,15,15,15,15,15,15,15,15,
  106492. 7, 8, 9,15, 9,10,10,15,15,14,14,15,15,15,15,15,
  106493. 5, 6, 7,15, 7, 8, 9,15,12, 9,10,15,15,15,15,15,
  106494. 7, 7, 9,15, 7, 7, 8,15,12, 8, 9,15,15,15,15,15,
  106495. 13,13,14,15,12,11,12,15,15,15,15,15,15,15,15,15,
  106496. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106497. 13,13,13,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106498. 15,12,13,15,15,12,13,15,15,14,15,15,15,15,15,15,
  106499. 15,15,15,15,15,15,13,15,15,15,15,15,15,15,15,15,
  106500. };
  106501. static static_codebook _huff_book_line_256x7_class1 = {
  106502. 1, 256,
  106503. _huff_lengthlist_line_256x7_class1,
  106504. 0, 0, 0, 0, 0,
  106505. NULL,
  106506. NULL,
  106507. NULL,
  106508. NULL,
  106509. 0
  106510. };
  106511. static long _huff_lengthlist_line_512x17_0sub0[] = {
  106512. 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  106513. 5, 6, 5, 6, 6, 6, 6, 5, 6, 6, 7, 6, 7, 6, 7, 6,
  106514. 7, 6, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 9, 7, 9, 7,
  106515. 9, 7, 9, 8, 9, 8,10, 8,10, 8,10, 7,10, 6,10, 8,
  106516. 10, 8,11, 7,10, 7,11, 8,11,11,12,12,11,11,12,11,
  106517. 13,11,13,11,13,12,15,12,13,13,14,14,14,14,14,15,
  106518. 15,15,16,14,17,19,19,18,18,18,18,18,18,18,18,18,
  106519. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  106520. };
  106521. static static_codebook _huff_book_line_512x17_0sub0 = {
  106522. 1, 128,
  106523. _huff_lengthlist_line_512x17_0sub0,
  106524. 0, 0, 0, 0, 0,
  106525. NULL,
  106526. NULL,
  106527. NULL,
  106528. NULL,
  106529. 0
  106530. };
  106531. static long _huff_lengthlist_line_512x17_1sub0[] = {
  106532. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  106533. 6, 5, 6, 6, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 8, 7,
  106534. };
  106535. static static_codebook _huff_book_line_512x17_1sub0 = {
  106536. 1, 32,
  106537. _huff_lengthlist_line_512x17_1sub0,
  106538. 0, 0, 0, 0, 0,
  106539. NULL,
  106540. NULL,
  106541. NULL,
  106542. NULL,
  106543. 0
  106544. };
  106545. static long _huff_lengthlist_line_512x17_1sub1[] = {
  106546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106548. 4, 3, 5, 3, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 6, 5,
  106549. 6, 5, 7, 5, 8, 6, 8, 6, 8, 6, 8, 6, 8, 7, 9, 7,
  106550. 9, 7,11, 9,11,11,12,11,14,12,14,16,14,16,13,16,
  106551. 14,16,12,15,13,16,14,16,13,14,12,15,13,15,13,13,
  106552. 13,15,12,14,14,15,13,15,12,15,15,15,15,15,15,15,
  106553. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106554. };
  106555. static static_codebook _huff_book_line_512x17_1sub1 = {
  106556. 1, 128,
  106557. _huff_lengthlist_line_512x17_1sub1,
  106558. 0, 0, 0, 0, 0,
  106559. NULL,
  106560. NULL,
  106561. NULL,
  106562. NULL,
  106563. 0
  106564. };
  106565. static long _huff_lengthlist_line_512x17_2sub1[] = {
  106566. 0, 4, 5, 4, 4, 4, 5, 4, 4, 4, 5, 4, 5, 4, 5, 3,
  106567. 5, 3,
  106568. };
  106569. static static_codebook _huff_book_line_512x17_2sub1 = {
  106570. 1, 18,
  106571. _huff_lengthlist_line_512x17_2sub1,
  106572. 0, 0, 0, 0, 0,
  106573. NULL,
  106574. NULL,
  106575. NULL,
  106576. NULL,
  106577. 0
  106578. };
  106579. static long _huff_lengthlist_line_512x17_2sub2[] = {
  106580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106581. 0, 0, 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 6, 4, 6, 5,
  106582. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 7, 8, 7, 9, 7,
  106583. 9, 8,
  106584. };
  106585. static static_codebook _huff_book_line_512x17_2sub2 = {
  106586. 1, 50,
  106587. _huff_lengthlist_line_512x17_2sub2,
  106588. 0, 0, 0, 0, 0,
  106589. NULL,
  106590. NULL,
  106591. NULL,
  106592. NULL,
  106593. 0
  106594. };
  106595. static long _huff_lengthlist_line_512x17_2sub3[] = {
  106596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106599. 0, 0, 3, 3, 3, 3, 4, 3, 4, 4, 5, 5, 6, 6, 7, 7,
  106600. 7, 8, 8,11, 8, 9, 9, 9,10,11,11,11, 9,10,10,11,
  106601. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106602. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106603. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106604. };
  106605. static static_codebook _huff_book_line_512x17_2sub3 = {
  106606. 1, 128,
  106607. _huff_lengthlist_line_512x17_2sub3,
  106608. 0, 0, 0, 0, 0,
  106609. NULL,
  106610. NULL,
  106611. NULL,
  106612. NULL,
  106613. 0
  106614. };
  106615. static long _huff_lengthlist_line_512x17_3sub1[] = {
  106616. 0, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 5, 4, 5,
  106617. 5, 5,
  106618. };
  106619. static static_codebook _huff_book_line_512x17_3sub1 = {
  106620. 1, 18,
  106621. _huff_lengthlist_line_512x17_3sub1,
  106622. 0, 0, 0, 0, 0,
  106623. NULL,
  106624. NULL,
  106625. NULL,
  106626. NULL,
  106627. 0
  106628. };
  106629. static long _huff_lengthlist_line_512x17_3sub2[] = {
  106630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106631. 0, 0, 2, 3, 3, 4, 3, 5, 4, 6, 4, 6, 5, 7, 6, 7,
  106632. 6, 8, 6, 8, 7, 9, 8,10, 8,12, 9,13,10,15,10,15,
  106633. 11,14,
  106634. };
  106635. static static_codebook _huff_book_line_512x17_3sub2 = {
  106636. 1, 50,
  106637. _huff_lengthlist_line_512x17_3sub2,
  106638. 0, 0, 0, 0, 0,
  106639. NULL,
  106640. NULL,
  106641. NULL,
  106642. NULL,
  106643. 0
  106644. };
  106645. static long _huff_lengthlist_line_512x17_3sub3[] = {
  106646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106649. 0, 0, 4, 8, 4, 8, 4, 8, 4, 8, 5, 8, 5, 8, 6, 8,
  106650. 4, 8, 4, 8, 5, 8, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106651. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106652. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106653. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106654. };
  106655. static static_codebook _huff_book_line_512x17_3sub3 = {
  106656. 1, 128,
  106657. _huff_lengthlist_line_512x17_3sub3,
  106658. 0, 0, 0, 0, 0,
  106659. NULL,
  106660. NULL,
  106661. NULL,
  106662. NULL,
  106663. 0
  106664. };
  106665. static long _huff_lengthlist_line_512x17_class1[] = {
  106666. 1, 2, 3, 6, 5, 4, 7, 7,
  106667. };
  106668. static static_codebook _huff_book_line_512x17_class1 = {
  106669. 1, 8,
  106670. _huff_lengthlist_line_512x17_class1,
  106671. 0, 0, 0, 0, 0,
  106672. NULL,
  106673. NULL,
  106674. NULL,
  106675. NULL,
  106676. 0
  106677. };
  106678. static long _huff_lengthlist_line_512x17_class2[] = {
  106679. 3, 3, 3,14, 5, 4, 4,11, 8, 6, 6,10,17,12,11,17,
  106680. 6, 5, 5,15, 5, 3, 4,11, 8, 5, 5, 8,16, 9,10,14,
  106681. 10, 8, 9,17, 8, 6, 6,13,10, 7, 7,10,16,11,13,14,
  106682. 17,17,17,17,17,16,16,16,16,15,16,16,16,16,16,16,
  106683. };
  106684. static static_codebook _huff_book_line_512x17_class2 = {
  106685. 1, 64,
  106686. _huff_lengthlist_line_512x17_class2,
  106687. 0, 0, 0, 0, 0,
  106688. NULL,
  106689. NULL,
  106690. NULL,
  106691. NULL,
  106692. 0
  106693. };
  106694. static long _huff_lengthlist_line_512x17_class3[] = {
  106695. 2, 4, 6,17, 4, 5, 7,17, 8, 7,10,17,17,17,17,17,
  106696. 3, 4, 6,15, 3, 3, 6,15, 7, 6, 9,17,17,17,17,17,
  106697. 6, 8,10,17, 6, 6, 8,16, 9, 8,10,17,17,15,16,17,
  106698. 17,17,17,17,12,15,15,16,12,15,15,16,16,16,16,16,
  106699. };
  106700. static static_codebook _huff_book_line_512x17_class3 = {
  106701. 1, 64,
  106702. _huff_lengthlist_line_512x17_class3,
  106703. 0, 0, 0, 0, 0,
  106704. NULL,
  106705. NULL,
  106706. NULL,
  106707. NULL,
  106708. 0
  106709. };
  106710. static long _huff_lengthlist_line_128x4_class0[] = {
  106711. 7, 7, 7,11, 6, 6, 7,11, 7, 6, 6,10,12,10,10,13,
  106712. 7, 7, 8,11, 7, 7, 7,11, 7, 6, 7,10,11,10,10,13,
  106713. 10,10, 9,12, 9, 9, 9,11, 8, 8, 8,11,13,11,10,14,
  106714. 15,15,14,15,15,14,13,14,15,12,12,17,17,17,17,17,
  106715. 7, 7, 6, 9, 6, 6, 6, 9, 7, 6, 6, 8,11,11,10,12,
  106716. 7, 7, 7, 9, 7, 6, 6, 9, 7, 6, 6, 9,13,10,10,11,
  106717. 10, 9, 8,10, 9, 8, 8,10, 8, 8, 7, 9,13,12,10,11,
  106718. 17,14,14,13,15,14,12,13,17,13,12,15,17,17,14,17,
  106719. 7, 6, 6, 7, 6, 6, 5, 7, 6, 6, 6, 6,11, 9, 9, 9,
  106720. 7, 7, 6, 7, 7, 6, 6, 7, 6, 6, 6, 6,10, 9, 8, 9,
  106721. 10, 9, 8, 8, 9, 8, 7, 8, 8, 7, 6, 8,11,10, 9,10,
  106722. 17,17,12,15,15,15,12,14,14,14,10,12,15,13,12,13,
  106723. 11,10, 8,10,11,10, 8, 8,10, 9, 7, 7,10, 9, 9,11,
  106724. 11,11, 9,10,11,10, 8, 9,10, 8, 6, 8,10, 9, 9,11,
  106725. 14,13,10,12,12,11,10,10, 8, 7, 8,10,10,11,11,12,
  106726. 17,17,15,17,17,17,17,17,17,13,12,17,17,17,14,17,
  106727. };
  106728. static static_codebook _huff_book_line_128x4_class0 = {
  106729. 1, 256,
  106730. _huff_lengthlist_line_128x4_class0,
  106731. 0, 0, 0, 0, 0,
  106732. NULL,
  106733. NULL,
  106734. NULL,
  106735. NULL,
  106736. 0
  106737. };
  106738. static long _huff_lengthlist_line_128x4_0sub0[] = {
  106739. 2, 2, 2, 2,
  106740. };
  106741. static static_codebook _huff_book_line_128x4_0sub0 = {
  106742. 1, 4,
  106743. _huff_lengthlist_line_128x4_0sub0,
  106744. 0, 0, 0, 0, 0,
  106745. NULL,
  106746. NULL,
  106747. NULL,
  106748. NULL,
  106749. 0
  106750. };
  106751. static long _huff_lengthlist_line_128x4_0sub1[] = {
  106752. 0, 0, 0, 0, 3, 2, 3, 2, 3, 3,
  106753. };
  106754. static static_codebook _huff_book_line_128x4_0sub1 = {
  106755. 1, 10,
  106756. _huff_lengthlist_line_128x4_0sub1,
  106757. 0, 0, 0, 0, 0,
  106758. NULL,
  106759. NULL,
  106760. NULL,
  106761. NULL,
  106762. 0
  106763. };
  106764. static long _huff_lengthlist_line_128x4_0sub2[] = {
  106765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 4, 3, 4, 3,
  106766. 4, 4, 5, 4, 5, 4, 6, 5, 6,
  106767. };
  106768. static static_codebook _huff_book_line_128x4_0sub2 = {
  106769. 1, 25,
  106770. _huff_lengthlist_line_128x4_0sub2,
  106771. 0, 0, 0, 0, 0,
  106772. NULL,
  106773. NULL,
  106774. NULL,
  106775. NULL,
  106776. 0
  106777. };
  106778. static long _huff_lengthlist_line_128x4_0sub3[] = {
  106779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  106781. 5, 4, 6, 5, 6, 5, 7, 6, 6, 7, 7, 9, 9,11,11,16,
  106782. 11,14,10,11,11,13,16,15,15,15,15,15,15,15,15,15,
  106783. };
  106784. static static_codebook _huff_book_line_128x4_0sub3 = {
  106785. 1, 64,
  106786. _huff_lengthlist_line_128x4_0sub3,
  106787. 0, 0, 0, 0, 0,
  106788. NULL,
  106789. NULL,
  106790. NULL,
  106791. NULL,
  106792. 0
  106793. };
  106794. static long _huff_lengthlist_line_256x4_class0[] = {
  106795. 6, 7, 7,12, 6, 6, 7,12, 7, 6, 6,10,15,12,11,13,
  106796. 7, 7, 8,13, 7, 7, 8,12, 7, 7, 7,11,12,12,11,13,
  106797. 10, 9, 9,11, 9, 9, 9,10,10, 8, 8,12,14,12,12,14,
  106798. 11,11,12,14,11,12,11,15,15,12,13,15,15,15,15,15,
  106799. 6, 6, 7,10, 6, 6, 6,11, 7, 6, 6, 9,14,12,11,13,
  106800. 7, 7, 7,10, 6, 6, 7, 9, 7, 7, 6,10,13,12,10,12,
  106801. 9, 9, 9,11, 9, 9, 8, 9, 9, 8, 8,10,13,12,10,12,
  106802. 12,12,11,13,12,12,11,12,15,13,12,15,15,15,14,14,
  106803. 6, 6, 6, 8, 6, 6, 5, 6, 7, 7, 6, 5,11,10, 9, 8,
  106804. 7, 6, 6, 7, 6, 6, 5, 6, 7, 7, 6, 6,11,10, 9, 8,
  106805. 8, 8, 8, 9, 8, 8, 7, 8, 8, 8, 6, 7,11,10, 9, 9,
  106806. 14,11,10,14,14,11,10,15,13,11, 9,11,15,12,12,11,
  106807. 11, 9, 8, 8,10, 9, 8, 9,11,10, 9, 8,12,11,12,11,
  106808. 13,10, 8, 9,11,10, 8, 9,10, 9, 8, 9,10, 8,12,12,
  106809. 15,11,10,10,13,11,10,10, 8, 8, 7,12,10, 9,11,12,
  106810. 15,12,11,15,13,11,11,15,12,14,11,13,15,15,13,13,
  106811. };
  106812. static static_codebook _huff_book_line_256x4_class0 = {
  106813. 1, 256,
  106814. _huff_lengthlist_line_256x4_class0,
  106815. 0, 0, 0, 0, 0,
  106816. NULL,
  106817. NULL,
  106818. NULL,
  106819. NULL,
  106820. 0
  106821. };
  106822. static long _huff_lengthlist_line_256x4_0sub0[] = {
  106823. 2, 2, 2, 2,
  106824. };
  106825. static static_codebook _huff_book_line_256x4_0sub0 = {
  106826. 1, 4,
  106827. _huff_lengthlist_line_256x4_0sub0,
  106828. 0, 0, 0, 0, 0,
  106829. NULL,
  106830. NULL,
  106831. NULL,
  106832. NULL,
  106833. 0
  106834. };
  106835. static long _huff_lengthlist_line_256x4_0sub1[] = {
  106836. 0, 0, 0, 0, 2, 2, 3, 3, 3, 3,
  106837. };
  106838. static static_codebook _huff_book_line_256x4_0sub1 = {
  106839. 1, 10,
  106840. _huff_lengthlist_line_256x4_0sub1,
  106841. 0, 0, 0, 0, 0,
  106842. NULL,
  106843. NULL,
  106844. NULL,
  106845. NULL,
  106846. 0
  106847. };
  106848. static long _huff_lengthlist_line_256x4_0sub2[] = {
  106849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 3, 4, 3, 4, 3,
  106850. 5, 3, 5, 4, 5, 4, 6, 4, 6,
  106851. };
  106852. static static_codebook _huff_book_line_256x4_0sub2 = {
  106853. 1, 25,
  106854. _huff_lengthlist_line_256x4_0sub2,
  106855. 0, 0, 0, 0, 0,
  106856. NULL,
  106857. NULL,
  106858. NULL,
  106859. NULL,
  106860. 0
  106861. };
  106862. static long _huff_lengthlist_line_256x4_0sub3[] = {
  106863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  106865. 6, 4, 7, 4, 7, 5, 7, 6, 7, 6, 7, 8,10,13,13,13,
  106866. 13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,
  106867. };
  106868. static static_codebook _huff_book_line_256x4_0sub3 = {
  106869. 1, 64,
  106870. _huff_lengthlist_line_256x4_0sub3,
  106871. 0, 0, 0, 0, 0,
  106872. NULL,
  106873. NULL,
  106874. NULL,
  106875. NULL,
  106876. 0
  106877. };
  106878. static long _huff_lengthlist_line_128x7_class0[] = {
  106879. 10, 7, 8,13, 9, 6, 7,11,10, 8, 8,12,17,17,17,17,
  106880. 7, 5, 5, 9, 6, 4, 4, 8, 8, 5, 5, 8,16,14,13,16,
  106881. 7, 5, 5, 7, 6, 3, 3, 5, 8, 5, 4, 7,14,12,12,15,
  106882. 10, 7, 8, 9, 7, 5, 5, 6, 9, 6, 5, 5,15,12, 9,10,
  106883. };
  106884. static static_codebook _huff_book_line_128x7_class0 = {
  106885. 1, 64,
  106886. _huff_lengthlist_line_128x7_class0,
  106887. 0, 0, 0, 0, 0,
  106888. NULL,
  106889. NULL,
  106890. NULL,
  106891. NULL,
  106892. 0
  106893. };
  106894. static long _huff_lengthlist_line_128x7_class1[] = {
  106895. 8,13,17,17, 8,11,17,17,11,13,17,17,17,17,17,17,
  106896. 6,10,16,17, 6,10,15,17, 8,10,16,17,17,17,17,17,
  106897. 9,13,15,17, 8,11,17,17,10,12,17,17,17,17,17,17,
  106898. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  106899. 6,11,15,17, 7,10,15,17, 8,10,17,17,17,15,17,17,
  106900. 4, 8,13,17, 4, 7,13,17, 6, 8,15,17,16,15,17,17,
  106901. 6,11,15,17, 6, 9,13,17, 8,10,17,17,15,17,17,17,
  106902. 16,17,17,17,12,14,15,17,13,14,15,17,17,17,17,17,
  106903. 5,10,14,17, 5, 9,14,17, 7, 9,15,17,15,15,17,17,
  106904. 3, 7,12,17, 3, 6,11,17, 5, 7,13,17,12,12,17,17,
  106905. 5, 9,14,17, 3, 7,11,17, 5, 8,13,17,13,11,16,17,
  106906. 12,17,17,17, 9,14,15,17,10,11,14,17,16,14,17,17,
  106907. 8,12,17,17, 8,12,17,17,10,12,17,17,17,17,17,17,
  106908. 5,10,17,17, 5, 9,15,17, 7, 9,17,17,13,13,17,17,
  106909. 7,11,17,17, 6,10,15,17, 7, 9,15,17,12,11,17,17,
  106910. 12,15,17,17,11,14,17,17,11,10,15,17,17,16,17,17,
  106911. };
  106912. static static_codebook _huff_book_line_128x7_class1 = {
  106913. 1, 256,
  106914. _huff_lengthlist_line_128x7_class1,
  106915. 0, 0, 0, 0, 0,
  106916. NULL,
  106917. NULL,
  106918. NULL,
  106919. NULL,
  106920. 0
  106921. };
  106922. static long _huff_lengthlist_line_128x7_0sub1[] = {
  106923. 0, 3, 3, 3, 3, 3, 3, 3, 3,
  106924. };
  106925. static static_codebook _huff_book_line_128x7_0sub1 = {
  106926. 1, 9,
  106927. _huff_lengthlist_line_128x7_0sub1,
  106928. 0, 0, 0, 0, 0,
  106929. NULL,
  106930. NULL,
  106931. NULL,
  106932. NULL,
  106933. 0
  106934. };
  106935. static long _huff_lengthlist_line_128x7_0sub2[] = {
  106936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 4, 4, 4,
  106937. 5, 4, 5, 4, 5, 4, 6, 4, 6,
  106938. };
  106939. static static_codebook _huff_book_line_128x7_0sub2 = {
  106940. 1, 25,
  106941. _huff_lengthlist_line_128x7_0sub2,
  106942. 0, 0, 0, 0, 0,
  106943. NULL,
  106944. NULL,
  106945. NULL,
  106946. NULL,
  106947. 0
  106948. };
  106949. static long _huff_lengthlist_line_128x7_0sub3[] = {
  106950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 3, 5, 3, 5, 4,
  106952. 5, 4, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  106953. 7, 8, 9,11,13,13,13,13,13,13,13,13,13,13,13,13,
  106954. };
  106955. static static_codebook _huff_book_line_128x7_0sub3 = {
  106956. 1, 64,
  106957. _huff_lengthlist_line_128x7_0sub3,
  106958. 0, 0, 0, 0, 0,
  106959. NULL,
  106960. NULL,
  106961. NULL,
  106962. NULL,
  106963. 0
  106964. };
  106965. static long _huff_lengthlist_line_128x7_1sub1[] = {
  106966. 0, 3, 3, 2, 3, 3, 4, 3, 4,
  106967. };
  106968. static static_codebook _huff_book_line_128x7_1sub1 = {
  106969. 1, 9,
  106970. _huff_lengthlist_line_128x7_1sub1,
  106971. 0, 0, 0, 0, 0,
  106972. NULL,
  106973. NULL,
  106974. NULL,
  106975. NULL,
  106976. 0
  106977. };
  106978. static long _huff_lengthlist_line_128x7_1sub2[] = {
  106979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 6, 3, 6, 3,
  106980. 6, 3, 7, 3, 8, 4, 9, 4, 9,
  106981. };
  106982. static static_codebook _huff_book_line_128x7_1sub2 = {
  106983. 1, 25,
  106984. _huff_lengthlist_line_128x7_1sub2,
  106985. 0, 0, 0, 0, 0,
  106986. NULL,
  106987. NULL,
  106988. NULL,
  106989. NULL,
  106990. 0
  106991. };
  106992. static long _huff_lengthlist_line_128x7_1sub3[] = {
  106993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 2, 7, 3, 8, 4,
  106995. 9, 5, 9, 8,10,11,11,12,14,14,14,14,14,14,14,14,
  106996. 14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,
  106997. };
  106998. static static_codebook _huff_book_line_128x7_1sub3 = {
  106999. 1, 64,
  107000. _huff_lengthlist_line_128x7_1sub3,
  107001. 0, 0, 0, 0, 0,
  107002. NULL,
  107003. NULL,
  107004. NULL,
  107005. NULL,
  107006. 0
  107007. };
  107008. static long _huff_lengthlist_line_128x11_class1[] = {
  107009. 1, 6, 3, 7, 2, 4, 5, 7,
  107010. };
  107011. static static_codebook _huff_book_line_128x11_class1 = {
  107012. 1, 8,
  107013. _huff_lengthlist_line_128x11_class1,
  107014. 0, 0, 0, 0, 0,
  107015. NULL,
  107016. NULL,
  107017. NULL,
  107018. NULL,
  107019. 0
  107020. };
  107021. static long _huff_lengthlist_line_128x11_class2[] = {
  107022. 1, 6,12,16, 4,12,15,16, 9,15,16,16,16,16,16,16,
  107023. 2, 5,11,16, 5,11,13,16, 9,13,16,16,16,16,16,16,
  107024. 4, 8,12,16, 5, 9,12,16, 9,13,15,16,16,16,16,16,
  107025. 15,16,16,16,11,14,13,16,12,15,16,16,16,16,16,15,
  107026. };
  107027. static static_codebook _huff_book_line_128x11_class2 = {
  107028. 1, 64,
  107029. _huff_lengthlist_line_128x11_class2,
  107030. 0, 0, 0, 0, 0,
  107031. NULL,
  107032. NULL,
  107033. NULL,
  107034. NULL,
  107035. 0
  107036. };
  107037. static long _huff_lengthlist_line_128x11_class3[] = {
  107038. 7, 6, 9,17, 7, 6, 8,17,12, 9,11,16,16,16,16,16,
  107039. 5, 4, 7,16, 5, 3, 6,14, 9, 6, 8,15,16,16,16,16,
  107040. 5, 4, 6,13, 3, 2, 4,11, 7, 4, 6,13,16,11,10,14,
  107041. 12,12,12,16, 9, 7,10,15,12, 9,11,16,16,15,15,16,
  107042. };
  107043. static static_codebook _huff_book_line_128x11_class3 = {
  107044. 1, 64,
  107045. _huff_lengthlist_line_128x11_class3,
  107046. 0, 0, 0, 0, 0,
  107047. NULL,
  107048. NULL,
  107049. NULL,
  107050. NULL,
  107051. 0
  107052. };
  107053. static long _huff_lengthlist_line_128x11_0sub0[] = {
  107054. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107055. 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 6, 6, 6, 7, 6,
  107056. 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6, 8, 7,
  107057. 8, 7, 8, 7, 8, 7, 9, 7, 9, 8, 9, 8, 9, 8,10, 8,
  107058. 10, 9,10, 9,10, 9,11, 9,11, 9,10,10,11,10,11,10,
  107059. 11,11,11,11,11,11,12,13,14,14,14,15,15,16,16,16,
  107060. 17,15,16,15,16,16,17,17,16,17,17,17,17,17,17,17,
  107061. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  107062. };
  107063. static static_codebook _huff_book_line_128x11_0sub0 = {
  107064. 1, 128,
  107065. _huff_lengthlist_line_128x11_0sub0,
  107066. 0, 0, 0, 0, 0,
  107067. NULL,
  107068. NULL,
  107069. NULL,
  107070. NULL,
  107071. 0
  107072. };
  107073. static long _huff_lengthlist_line_128x11_1sub0[] = {
  107074. 2, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  107075. 6, 5, 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6,
  107076. };
  107077. static static_codebook _huff_book_line_128x11_1sub0 = {
  107078. 1, 32,
  107079. _huff_lengthlist_line_128x11_1sub0,
  107080. 0, 0, 0, 0, 0,
  107081. NULL,
  107082. NULL,
  107083. NULL,
  107084. NULL,
  107085. 0
  107086. };
  107087. static long _huff_lengthlist_line_128x11_1sub1[] = {
  107088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107090. 5, 3, 5, 3, 6, 4, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107091. 8, 4, 9, 5, 9, 5, 9, 5, 9, 6,10, 6,10, 6,11, 7,
  107092. 10, 7,10, 8,11, 9,11, 9,11,10,11,11,12,11,11,12,
  107093. 15,15,12,14,11,14,12,14,11,14,13,14,12,14,11,14,
  107094. 11,14,12,14,11,14,11,14,13,13,14,14,14,14,14,14,
  107095. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  107096. };
  107097. static static_codebook _huff_book_line_128x11_1sub1 = {
  107098. 1, 128,
  107099. _huff_lengthlist_line_128x11_1sub1,
  107100. 0, 0, 0, 0, 0,
  107101. NULL,
  107102. NULL,
  107103. NULL,
  107104. NULL,
  107105. 0
  107106. };
  107107. static long _huff_lengthlist_line_128x11_2sub1[] = {
  107108. 0, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4,
  107109. 5, 5,
  107110. };
  107111. static static_codebook _huff_book_line_128x11_2sub1 = {
  107112. 1, 18,
  107113. _huff_lengthlist_line_128x11_2sub1,
  107114. 0, 0, 0, 0, 0,
  107115. NULL,
  107116. NULL,
  107117. NULL,
  107118. NULL,
  107119. 0
  107120. };
  107121. static long _huff_lengthlist_line_128x11_2sub2[] = {
  107122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107123. 0, 0, 3, 3, 3, 4, 4, 4, 4, 5, 4, 5, 4, 6, 5, 7,
  107124. 5, 7, 6, 8, 6, 8, 6, 9, 7, 9, 7,10, 7, 9, 8,11,
  107125. 8,11,
  107126. };
  107127. static static_codebook _huff_book_line_128x11_2sub2 = {
  107128. 1, 50,
  107129. _huff_lengthlist_line_128x11_2sub2,
  107130. 0, 0, 0, 0, 0,
  107131. NULL,
  107132. NULL,
  107133. NULL,
  107134. NULL,
  107135. 0
  107136. };
  107137. static long _huff_lengthlist_line_128x11_2sub3[] = {
  107138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107141. 0, 0, 4, 8, 3, 8, 4, 8, 4, 8, 6, 8, 5, 8, 4, 8,
  107142. 4, 8, 6, 8, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107143. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107144. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107145. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107146. };
  107147. static static_codebook _huff_book_line_128x11_2sub3 = {
  107148. 1, 128,
  107149. _huff_lengthlist_line_128x11_2sub3,
  107150. 0, 0, 0, 0, 0,
  107151. NULL,
  107152. NULL,
  107153. NULL,
  107154. NULL,
  107155. 0
  107156. };
  107157. static long _huff_lengthlist_line_128x11_3sub1[] = {
  107158. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4,
  107159. 5, 4,
  107160. };
  107161. static static_codebook _huff_book_line_128x11_3sub1 = {
  107162. 1, 18,
  107163. _huff_lengthlist_line_128x11_3sub1,
  107164. 0, 0, 0, 0, 0,
  107165. NULL,
  107166. NULL,
  107167. NULL,
  107168. NULL,
  107169. 0
  107170. };
  107171. static long _huff_lengthlist_line_128x11_3sub2[] = {
  107172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107173. 0, 0, 5, 3, 5, 4, 6, 4, 6, 4, 7, 4, 7, 4, 8, 4,
  107174. 8, 4, 9, 4, 9, 4,10, 4,10, 5,10, 5,11, 5,12, 6,
  107175. 12, 6,
  107176. };
  107177. static static_codebook _huff_book_line_128x11_3sub2 = {
  107178. 1, 50,
  107179. _huff_lengthlist_line_128x11_3sub2,
  107180. 0, 0, 0, 0, 0,
  107181. NULL,
  107182. NULL,
  107183. NULL,
  107184. NULL,
  107185. 0
  107186. };
  107187. static long _huff_lengthlist_line_128x11_3sub3[] = {
  107188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107191. 0, 0, 7, 1, 6, 3, 7, 3, 8, 4, 8, 5, 8, 8, 8, 9,
  107192. 7, 8, 8, 7, 7, 7, 8, 9,10, 9, 9,10,10,10,10,10,
  107193. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107194. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107195. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  107196. };
  107197. static static_codebook _huff_book_line_128x11_3sub3 = {
  107198. 1, 128,
  107199. _huff_lengthlist_line_128x11_3sub3,
  107200. 0, 0, 0, 0, 0,
  107201. NULL,
  107202. NULL,
  107203. NULL,
  107204. NULL,
  107205. 0
  107206. };
  107207. static long _huff_lengthlist_line_128x17_class1[] = {
  107208. 1, 3, 4, 7, 2, 5, 6, 7,
  107209. };
  107210. static static_codebook _huff_book_line_128x17_class1 = {
  107211. 1, 8,
  107212. _huff_lengthlist_line_128x17_class1,
  107213. 0, 0, 0, 0, 0,
  107214. NULL,
  107215. NULL,
  107216. NULL,
  107217. NULL,
  107218. 0
  107219. };
  107220. static long _huff_lengthlist_line_128x17_class2[] = {
  107221. 1, 4,10,19, 3, 8,13,19, 7,12,19,19,19,19,19,19,
  107222. 2, 6,11,19, 8,13,19,19, 9,11,19,19,19,19,19,19,
  107223. 6, 7,13,19, 9,13,19,19,10,13,18,18,18,18,18,18,
  107224. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  107225. };
  107226. static static_codebook _huff_book_line_128x17_class2 = {
  107227. 1, 64,
  107228. _huff_lengthlist_line_128x17_class2,
  107229. 0, 0, 0, 0, 0,
  107230. NULL,
  107231. NULL,
  107232. NULL,
  107233. NULL,
  107234. 0
  107235. };
  107236. static long _huff_lengthlist_line_128x17_class3[] = {
  107237. 3, 6,10,17, 4, 8,11,20, 8,10,11,20,20,20,20,20,
  107238. 2, 4, 8,18, 4, 6, 8,17, 7, 8,10,20,20,17,20,20,
  107239. 3, 5, 8,17, 3, 4, 6,17, 8, 8,10,17,17,12,16,20,
  107240. 13,13,15,20,10,10,12,20,15,14,15,20,20,20,19,19,
  107241. };
  107242. static static_codebook _huff_book_line_128x17_class3 = {
  107243. 1, 64,
  107244. _huff_lengthlist_line_128x17_class3,
  107245. 0, 0, 0, 0, 0,
  107246. NULL,
  107247. NULL,
  107248. NULL,
  107249. NULL,
  107250. 0
  107251. };
  107252. static long _huff_lengthlist_line_128x17_0sub0[] = {
  107253. 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107254. 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5,
  107255. 8, 5, 8, 5, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6, 9, 6,
  107256. 9, 6, 9, 7, 9, 7, 9, 7, 9, 7,10, 7,10, 8,10, 8,
  107257. 10, 8,10, 8,10, 8,11, 8,11, 8,11, 8,11, 8,11, 9,
  107258. 12, 9,12, 9,12, 9,12, 9,12,10,12,10,13,11,13,11,
  107259. 14,12,14,13,15,14,16,14,17,15,18,16,20,20,20,20,
  107260. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107261. };
  107262. static static_codebook _huff_book_line_128x17_0sub0 = {
  107263. 1, 128,
  107264. _huff_lengthlist_line_128x17_0sub0,
  107265. 0, 0, 0, 0, 0,
  107266. NULL,
  107267. NULL,
  107268. NULL,
  107269. NULL,
  107270. 0
  107271. };
  107272. static long _huff_lengthlist_line_128x17_1sub0[] = {
  107273. 2, 5, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107274. 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7,
  107275. };
  107276. static static_codebook _huff_book_line_128x17_1sub0 = {
  107277. 1, 32,
  107278. _huff_lengthlist_line_128x17_1sub0,
  107279. 0, 0, 0, 0, 0,
  107280. NULL,
  107281. NULL,
  107282. NULL,
  107283. NULL,
  107284. 0
  107285. };
  107286. static long _huff_lengthlist_line_128x17_1sub1[] = {
  107287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107289. 4, 3, 5, 3, 5, 3, 6, 3, 6, 4, 6, 4, 7, 4, 7, 5,
  107290. 8, 5, 8, 6, 9, 7, 9, 7, 9, 8,10, 9,10, 9,11,10,
  107291. 11,11,11,11,11,11,12,12,12,13,12,13,12,14,12,15,
  107292. 12,14,12,16,13,17,13,17,14,17,14,16,13,17,14,17,
  107293. 14,17,15,17,15,15,16,17,17,17,17,17,17,17,17,17,
  107294. 17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16,
  107295. };
  107296. static static_codebook _huff_book_line_128x17_1sub1 = {
  107297. 1, 128,
  107298. _huff_lengthlist_line_128x17_1sub1,
  107299. 0, 0, 0, 0, 0,
  107300. NULL,
  107301. NULL,
  107302. NULL,
  107303. NULL,
  107304. 0
  107305. };
  107306. static long _huff_lengthlist_line_128x17_2sub1[] = {
  107307. 0, 4, 5, 4, 6, 4, 8, 3, 9, 3, 9, 2, 9, 3, 8, 4,
  107308. 9, 4,
  107309. };
  107310. static static_codebook _huff_book_line_128x17_2sub1 = {
  107311. 1, 18,
  107312. _huff_lengthlist_line_128x17_2sub1,
  107313. 0, 0, 0, 0, 0,
  107314. NULL,
  107315. NULL,
  107316. NULL,
  107317. NULL,
  107318. 0
  107319. };
  107320. static long _huff_lengthlist_line_128x17_2sub2[] = {
  107321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107322. 0, 0, 5, 1, 5, 3, 5, 3, 5, 4, 7, 5,10, 7,10, 7,
  107323. 12,10,14,10,14, 9,14,11,14,14,14,13,13,13,13,13,
  107324. 13,13,
  107325. };
  107326. static static_codebook _huff_book_line_128x17_2sub2 = {
  107327. 1, 50,
  107328. _huff_lengthlist_line_128x17_2sub2,
  107329. 0, 0, 0, 0, 0,
  107330. NULL,
  107331. NULL,
  107332. NULL,
  107333. NULL,
  107334. 0
  107335. };
  107336. static long _huff_lengthlist_line_128x17_2sub3[] = {
  107337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107340. 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107341. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6,
  107342. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107343. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107344. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107345. };
  107346. static static_codebook _huff_book_line_128x17_2sub3 = {
  107347. 1, 128,
  107348. _huff_lengthlist_line_128x17_2sub3,
  107349. 0, 0, 0, 0, 0,
  107350. NULL,
  107351. NULL,
  107352. NULL,
  107353. NULL,
  107354. 0
  107355. };
  107356. static long _huff_lengthlist_line_128x17_3sub1[] = {
  107357. 0, 4, 4, 4, 4, 4, 4, 4, 5, 3, 5, 3, 5, 4, 6, 4,
  107358. 6, 4,
  107359. };
  107360. static static_codebook _huff_book_line_128x17_3sub1 = {
  107361. 1, 18,
  107362. _huff_lengthlist_line_128x17_3sub1,
  107363. 0, 0, 0, 0, 0,
  107364. NULL,
  107365. NULL,
  107366. NULL,
  107367. NULL,
  107368. 0
  107369. };
  107370. static long _huff_lengthlist_line_128x17_3sub2[] = {
  107371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107372. 0, 0, 5, 3, 6, 3, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107373. 8, 4, 8, 4, 8, 4, 9, 4, 9, 5,10, 5,10, 7,10, 8,
  107374. 10, 8,
  107375. };
  107376. static static_codebook _huff_book_line_128x17_3sub2 = {
  107377. 1, 50,
  107378. _huff_lengthlist_line_128x17_3sub2,
  107379. 0, 0, 0, 0, 0,
  107380. NULL,
  107381. NULL,
  107382. NULL,
  107383. NULL,
  107384. 0
  107385. };
  107386. static long _huff_lengthlist_line_128x17_3sub3[] = {
  107387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107390. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 4, 7, 5, 8, 5,11,
  107391. 6,10, 6,12, 7,12, 7,12, 8,12, 8,12,10,12,12,12,
  107392. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107393. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107394. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107395. };
  107396. static static_codebook _huff_book_line_128x17_3sub3 = {
  107397. 1, 128,
  107398. _huff_lengthlist_line_128x17_3sub3,
  107399. 0, 0, 0, 0, 0,
  107400. NULL,
  107401. NULL,
  107402. NULL,
  107403. NULL,
  107404. 0
  107405. };
  107406. static long _huff_lengthlist_line_1024x27_class1[] = {
  107407. 2,10, 8,14, 7,12,11,14, 1, 5, 3, 7, 4, 9, 7,13,
  107408. };
  107409. static static_codebook _huff_book_line_1024x27_class1 = {
  107410. 1, 16,
  107411. _huff_lengthlist_line_1024x27_class1,
  107412. 0, 0, 0, 0, 0,
  107413. NULL,
  107414. NULL,
  107415. NULL,
  107416. NULL,
  107417. 0
  107418. };
  107419. static long _huff_lengthlist_line_1024x27_class2[] = {
  107420. 1, 4, 2, 6, 3, 7, 5, 7,
  107421. };
  107422. static static_codebook _huff_book_line_1024x27_class2 = {
  107423. 1, 8,
  107424. _huff_lengthlist_line_1024x27_class2,
  107425. 0, 0, 0, 0, 0,
  107426. NULL,
  107427. NULL,
  107428. NULL,
  107429. NULL,
  107430. 0
  107431. };
  107432. static long _huff_lengthlist_line_1024x27_class3[] = {
  107433. 1, 5, 7,21, 5, 8, 9,21,10, 9,12,20,20,16,20,20,
  107434. 4, 8, 9,20, 6, 8, 9,20,11,11,13,20,20,15,17,20,
  107435. 9,11,14,20, 8,10,15,20,11,13,15,20,20,20,20,20,
  107436. 20,20,20,20,13,20,20,20,18,18,20,20,20,20,20,20,
  107437. 3, 6, 8,20, 6, 7, 9,20,10, 9,12,20,20,20,20,20,
  107438. 5, 7, 9,20, 6, 6, 9,20,10, 9,12,20,20,20,20,20,
  107439. 8,10,13,20, 8, 9,12,20,11,10,12,20,20,20,20,20,
  107440. 18,20,20,20,15,17,18,20,18,17,18,20,20,20,20,20,
  107441. 7,10,12,20, 8, 9,11,20,14,13,14,20,20,20,20,20,
  107442. 6, 9,12,20, 7, 8,11,20,12,11,13,20,20,20,20,20,
  107443. 9,11,15,20, 8,10,14,20,12,11,14,20,20,20,20,20,
  107444. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107445. 11,16,18,20,15,15,17,20,20,17,20,20,20,20,20,20,
  107446. 9,14,16,20,12,12,15,20,17,15,18,20,20,20,20,20,
  107447. 16,19,18,20,15,16,20,20,17,17,20,20,20,20,20,20,
  107448. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107449. };
  107450. static static_codebook _huff_book_line_1024x27_class3 = {
  107451. 1, 256,
  107452. _huff_lengthlist_line_1024x27_class3,
  107453. 0, 0, 0, 0, 0,
  107454. NULL,
  107455. NULL,
  107456. NULL,
  107457. NULL,
  107458. 0
  107459. };
  107460. static long _huff_lengthlist_line_1024x27_class4[] = {
  107461. 2, 3, 7,13, 4, 4, 7,15, 8, 6, 9,17,21,16,15,21,
  107462. 2, 5, 7,11, 5, 5, 7,14, 9, 7,10,16,17,15,16,21,
  107463. 4, 7,10,17, 7, 7, 9,15,11, 9,11,16,21,18,15,21,
  107464. 18,21,21,21,15,17,17,19,21,19,18,20,21,21,21,20,
  107465. };
  107466. static static_codebook _huff_book_line_1024x27_class4 = {
  107467. 1, 64,
  107468. _huff_lengthlist_line_1024x27_class4,
  107469. 0, 0, 0, 0, 0,
  107470. NULL,
  107471. NULL,
  107472. NULL,
  107473. NULL,
  107474. 0
  107475. };
  107476. static long _huff_lengthlist_line_1024x27_0sub0[] = {
  107477. 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107478. 6, 5, 6, 5, 6, 5, 6, 5, 7, 5, 7, 5, 7, 5, 7, 5,
  107479. 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,10, 6,10, 6,11, 6,
  107480. 11, 7,11, 7,12, 7,12, 7,12, 7,12, 7,12, 7,12, 7,
  107481. 12, 7,12, 8,13, 8,12, 8,12, 8,13, 8,13, 9,13, 9,
  107482. 13, 9,13, 9,12,10,12,10,13,10,14,11,14,12,14,13,
  107483. 14,13,14,14,15,16,15,15,15,14,15,17,21,22,22,21,
  107484. 22,22,22,22,22,22,21,21,21,21,21,21,21,21,21,21,
  107485. };
  107486. static static_codebook _huff_book_line_1024x27_0sub0 = {
  107487. 1, 128,
  107488. _huff_lengthlist_line_1024x27_0sub0,
  107489. 0, 0, 0, 0, 0,
  107490. NULL,
  107491. NULL,
  107492. NULL,
  107493. NULL,
  107494. 0
  107495. };
  107496. static long _huff_lengthlist_line_1024x27_1sub0[] = {
  107497. 2, 5, 5, 4, 5, 4, 5, 4, 5, 4, 6, 5, 6, 5, 6, 5,
  107498. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,
  107499. };
  107500. static static_codebook _huff_book_line_1024x27_1sub0 = {
  107501. 1, 32,
  107502. _huff_lengthlist_line_1024x27_1sub0,
  107503. 0, 0, 0, 0, 0,
  107504. NULL,
  107505. NULL,
  107506. NULL,
  107507. NULL,
  107508. 0
  107509. };
  107510. static long _huff_lengthlist_line_1024x27_1sub1[] = {
  107511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107513. 8, 5, 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4,
  107514. 9, 4, 9, 4, 9, 4, 8, 4, 8, 4, 9, 5, 9, 5, 9, 5,
  107515. 9, 5, 9, 6,10, 6,10, 7,10, 8,11, 9,11,11,12,13,
  107516. 12,14,13,15,13,15,14,16,14,17,15,17,15,15,16,16,
  107517. 15,16,16,16,15,18,16,15,17,17,19,19,19,19,19,19,
  107518. 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,
  107519. };
  107520. static static_codebook _huff_book_line_1024x27_1sub1 = {
  107521. 1, 128,
  107522. _huff_lengthlist_line_1024x27_1sub1,
  107523. 0, 0, 0, 0, 0,
  107524. NULL,
  107525. NULL,
  107526. NULL,
  107527. NULL,
  107528. 0
  107529. };
  107530. static long _huff_lengthlist_line_1024x27_2sub0[] = {
  107531. 1, 5, 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107532. 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 9, 8,10, 9,10, 9,
  107533. };
  107534. static static_codebook _huff_book_line_1024x27_2sub0 = {
  107535. 1, 32,
  107536. _huff_lengthlist_line_1024x27_2sub0,
  107537. 0, 0, 0, 0, 0,
  107538. NULL,
  107539. NULL,
  107540. NULL,
  107541. NULL,
  107542. 0
  107543. };
  107544. static long _huff_lengthlist_line_1024x27_2sub1[] = {
  107545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107547. 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 5, 5, 6, 5, 6, 5,
  107548. 7, 5, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 9, 8, 9, 9,
  107549. 9, 9,10,10,10,11, 9,12, 9,12, 9,15,10,14, 9,13,
  107550. 10,13,10,12,10,12,10,13,10,12,11,13,11,14,12,13,
  107551. 13,14,14,13,14,15,14,16,13,13,14,16,16,16,16,16,
  107552. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,15,15,
  107553. };
  107554. static static_codebook _huff_book_line_1024x27_2sub1 = {
  107555. 1, 128,
  107556. _huff_lengthlist_line_1024x27_2sub1,
  107557. 0, 0, 0, 0, 0,
  107558. NULL,
  107559. NULL,
  107560. NULL,
  107561. NULL,
  107562. 0
  107563. };
  107564. static long _huff_lengthlist_line_1024x27_3sub1[] = {
  107565. 0, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4, 4, 5,
  107566. 5, 5,
  107567. };
  107568. static static_codebook _huff_book_line_1024x27_3sub1 = {
  107569. 1, 18,
  107570. _huff_lengthlist_line_1024x27_3sub1,
  107571. 0, 0, 0, 0, 0,
  107572. NULL,
  107573. NULL,
  107574. NULL,
  107575. NULL,
  107576. 0
  107577. };
  107578. static long _huff_lengthlist_line_1024x27_3sub2[] = {
  107579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107580. 0, 0, 3, 3, 4, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6,
  107581. 5, 7, 5, 8, 6, 8, 6, 9, 7,10, 7,10, 8,10, 8,11,
  107582. 9,11,
  107583. };
  107584. static static_codebook _huff_book_line_1024x27_3sub2 = {
  107585. 1, 50,
  107586. _huff_lengthlist_line_1024x27_3sub2,
  107587. 0, 0, 0, 0, 0,
  107588. NULL,
  107589. NULL,
  107590. NULL,
  107591. NULL,
  107592. 0
  107593. };
  107594. static long _huff_lengthlist_line_1024x27_3sub3[] = {
  107595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107598. 0, 0, 3, 7, 3, 8, 3,10, 3, 8, 3, 9, 3, 8, 4, 9,
  107599. 4, 9, 5, 9, 6,10, 6, 9, 7,11, 7,12, 9,13,10,13,
  107600. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107601. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107602. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107603. };
  107604. static static_codebook _huff_book_line_1024x27_3sub3 = {
  107605. 1, 128,
  107606. _huff_lengthlist_line_1024x27_3sub3,
  107607. 0, 0, 0, 0, 0,
  107608. NULL,
  107609. NULL,
  107610. NULL,
  107611. NULL,
  107612. 0
  107613. };
  107614. static long _huff_lengthlist_line_1024x27_4sub1[] = {
  107615. 0, 4, 5, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4,
  107616. 5, 4,
  107617. };
  107618. static static_codebook _huff_book_line_1024x27_4sub1 = {
  107619. 1, 18,
  107620. _huff_lengthlist_line_1024x27_4sub1,
  107621. 0, 0, 0, 0, 0,
  107622. NULL,
  107623. NULL,
  107624. NULL,
  107625. NULL,
  107626. 0
  107627. };
  107628. static long _huff_lengthlist_line_1024x27_4sub2[] = {
  107629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107630. 0, 0, 4, 2, 4, 2, 5, 3, 5, 4, 6, 6, 6, 7, 7, 8,
  107631. 7, 8, 7, 8, 7, 9, 8, 9, 8, 9, 8,10, 8,11, 9,12,
  107632. 9,12,
  107633. };
  107634. static static_codebook _huff_book_line_1024x27_4sub2 = {
  107635. 1, 50,
  107636. _huff_lengthlist_line_1024x27_4sub2,
  107637. 0, 0, 0, 0, 0,
  107638. NULL,
  107639. NULL,
  107640. NULL,
  107641. NULL,
  107642. 0
  107643. };
  107644. static long _huff_lengthlist_line_1024x27_4sub3[] = {
  107645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107648. 0, 0, 2, 5, 2, 6, 3, 6, 4, 7, 4, 7, 5, 9, 5,11,
  107649. 6,11, 6,11, 7,11, 6,11, 6,11, 9,11, 8,11,11,11,
  107650. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107651. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107652. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  107653. };
  107654. static static_codebook _huff_book_line_1024x27_4sub3 = {
  107655. 1, 128,
  107656. _huff_lengthlist_line_1024x27_4sub3,
  107657. 0, 0, 0, 0, 0,
  107658. NULL,
  107659. NULL,
  107660. NULL,
  107661. NULL,
  107662. 0
  107663. };
  107664. static long _huff_lengthlist_line_2048x27_class1[] = {
  107665. 2, 6, 8, 9, 7,11,13,13, 1, 3, 5, 5, 6, 6,12,10,
  107666. };
  107667. static static_codebook _huff_book_line_2048x27_class1 = {
  107668. 1, 16,
  107669. _huff_lengthlist_line_2048x27_class1,
  107670. 0, 0, 0, 0, 0,
  107671. NULL,
  107672. NULL,
  107673. NULL,
  107674. NULL,
  107675. 0
  107676. };
  107677. static long _huff_lengthlist_line_2048x27_class2[] = {
  107678. 1, 2, 3, 6, 4, 7, 5, 7,
  107679. };
  107680. static static_codebook _huff_book_line_2048x27_class2 = {
  107681. 1, 8,
  107682. _huff_lengthlist_line_2048x27_class2,
  107683. 0, 0, 0, 0, 0,
  107684. NULL,
  107685. NULL,
  107686. NULL,
  107687. NULL,
  107688. 0
  107689. };
  107690. static long _huff_lengthlist_line_2048x27_class3[] = {
  107691. 3, 3, 6,16, 5, 5, 7,16, 9, 8,11,16,16,16,16,16,
  107692. 5, 5, 8,16, 5, 5, 7,16, 8, 7, 9,16,16,16,16,16,
  107693. 9, 9,12,16, 6, 8,11,16, 9,10,11,16,16,16,16,16,
  107694. 16,16,16,16,13,16,16,16,15,16,16,16,16,16,16,16,
  107695. 5, 4, 7,16, 6, 5, 8,16, 9, 8,10,16,16,16,16,16,
  107696. 5, 5, 7,15, 5, 4, 6,15, 7, 6, 8,16,16,16,16,16,
  107697. 9, 9,11,15, 7, 7, 9,16, 8, 8, 9,16,16,16,16,16,
  107698. 16,16,16,16,15,15,15,16,15,15,14,16,16,16,16,16,
  107699. 8, 8,11,16, 8, 9,10,16,11,10,14,16,16,16,16,16,
  107700. 6, 8,10,16, 6, 7,10,16, 8, 8,11,16,14,16,16,16,
  107701. 10,11,14,16, 9, 9,11,16,10,10,11,16,16,16,16,16,
  107702. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107703. 16,16,16,16,15,16,16,16,16,16,16,16,16,16,16,16,
  107704. 12,16,15,16,12,14,16,16,16,16,16,16,16,16,16,16,
  107705. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107706. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107707. };
  107708. static static_codebook _huff_book_line_2048x27_class3 = {
  107709. 1, 256,
  107710. _huff_lengthlist_line_2048x27_class3,
  107711. 0, 0, 0, 0, 0,
  107712. NULL,
  107713. NULL,
  107714. NULL,
  107715. NULL,
  107716. 0
  107717. };
  107718. static long _huff_lengthlist_line_2048x27_class4[] = {
  107719. 2, 4, 7,13, 4, 5, 7,15, 8, 7,10,16,16,14,16,16,
  107720. 2, 4, 7,16, 3, 4, 7,14, 8, 8,10,16,16,16,15,16,
  107721. 6, 8,11,16, 7, 7, 9,16,11, 9,13,16,16,16,15,16,
  107722. 16,16,16,16,14,16,16,16,16,16,16,16,16,16,16,16,
  107723. };
  107724. static static_codebook _huff_book_line_2048x27_class4 = {
  107725. 1, 64,
  107726. _huff_lengthlist_line_2048x27_class4,
  107727. 0, 0, 0, 0, 0,
  107728. NULL,
  107729. NULL,
  107730. NULL,
  107731. NULL,
  107732. 0
  107733. };
  107734. static long _huff_lengthlist_line_2048x27_0sub0[] = {
  107735. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107736. 6, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5, 8, 5, 9, 5,
  107737. 9, 6,10, 6,10, 6,11, 6,11, 6,11, 6,11, 6,11, 6,
  107738. 11, 6,11, 6,12, 7,11, 7,11, 7,11, 7,11, 7,10, 7,
  107739. 11, 7,11, 7,12, 7,11, 8,11, 8,11, 8,11, 8,13, 8,
  107740. 12, 9,11, 9,11, 9,11,10,12,10,12, 9,12,10,12,11,
  107741. 14,12,16,12,12,11,14,16,17,17,17,17,17,17,17,17,
  107742. 17,17,17,17,17,17,17,17,17,17,17,17,16,16,16,16,
  107743. };
  107744. static static_codebook _huff_book_line_2048x27_0sub0 = {
  107745. 1, 128,
  107746. _huff_lengthlist_line_2048x27_0sub0,
  107747. 0, 0, 0, 0, 0,
  107748. NULL,
  107749. NULL,
  107750. NULL,
  107751. NULL,
  107752. 0
  107753. };
  107754. static long _huff_lengthlist_line_2048x27_1sub0[] = {
  107755. 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  107756. 5, 5, 6, 6, 6, 6, 6, 6, 7, 6, 7, 6, 7, 6, 7, 6,
  107757. };
  107758. static static_codebook _huff_book_line_2048x27_1sub0 = {
  107759. 1, 32,
  107760. _huff_lengthlist_line_2048x27_1sub0,
  107761. 0, 0, 0, 0, 0,
  107762. NULL,
  107763. NULL,
  107764. NULL,
  107765. NULL,
  107766. 0
  107767. };
  107768. static long _huff_lengthlist_line_2048x27_1sub1[] = {
  107769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107771. 6, 5, 7, 5, 7, 4, 7, 4, 8, 4, 8, 4, 8, 4, 8, 3,
  107772. 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 5, 9, 5, 9, 6,
  107773. 9, 7, 9, 8, 9, 9, 9,10, 9,11, 9,14, 9,15,10,15,
  107774. 10,15,10,15,10,15,11,15,10,14,12,14,11,14,13,14,
  107775. 13,15,15,15,12,15,15,15,13,15,13,15,13,15,15,15,
  107776. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,14,
  107777. };
  107778. static static_codebook _huff_book_line_2048x27_1sub1 = {
  107779. 1, 128,
  107780. _huff_lengthlist_line_2048x27_1sub1,
  107781. 0, 0, 0, 0, 0,
  107782. NULL,
  107783. NULL,
  107784. NULL,
  107785. NULL,
  107786. 0
  107787. };
  107788. static long _huff_lengthlist_line_2048x27_2sub0[] = {
  107789. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107790. 6, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  107791. };
  107792. static static_codebook _huff_book_line_2048x27_2sub0 = {
  107793. 1, 32,
  107794. _huff_lengthlist_line_2048x27_2sub0,
  107795. 0, 0, 0, 0, 0,
  107796. NULL,
  107797. NULL,
  107798. NULL,
  107799. NULL,
  107800. 0
  107801. };
  107802. static long _huff_lengthlist_line_2048x27_2sub1[] = {
  107803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107805. 3, 4, 3, 4, 3, 4, 4, 5, 4, 5, 5, 5, 6, 6, 6, 7,
  107806. 6, 8, 6, 8, 6, 9, 7,10, 7,10, 7,10, 7,12, 7,12,
  107807. 7,12, 9,12,11,12,10,12,10,12,11,12,12,12,10,12,
  107808. 10,12,10,12, 9,12,11,12,12,12,12,12,11,12,11,12,
  107809. 12,12,12,12,12,12,12,12,10,10,12,12,12,12,12,10,
  107810. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107811. };
  107812. static static_codebook _huff_book_line_2048x27_2sub1 = {
  107813. 1, 128,
  107814. _huff_lengthlist_line_2048x27_2sub1,
  107815. 0, 0, 0, 0, 0,
  107816. NULL,
  107817. NULL,
  107818. NULL,
  107819. NULL,
  107820. 0
  107821. };
  107822. static long _huff_lengthlist_line_2048x27_3sub1[] = {
  107823. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  107824. 5, 5,
  107825. };
  107826. static static_codebook _huff_book_line_2048x27_3sub1 = {
  107827. 1, 18,
  107828. _huff_lengthlist_line_2048x27_3sub1,
  107829. 0, 0, 0, 0, 0,
  107830. NULL,
  107831. NULL,
  107832. NULL,
  107833. NULL,
  107834. 0
  107835. };
  107836. static long _huff_lengthlist_line_2048x27_3sub2[] = {
  107837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107838. 0, 0, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6,
  107839. 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7, 9, 9,11, 9,12,
  107840. 10,12,
  107841. };
  107842. static static_codebook _huff_book_line_2048x27_3sub2 = {
  107843. 1, 50,
  107844. _huff_lengthlist_line_2048x27_3sub2,
  107845. 0, 0, 0, 0, 0,
  107846. NULL,
  107847. NULL,
  107848. NULL,
  107849. NULL,
  107850. 0
  107851. };
  107852. static long _huff_lengthlist_line_2048x27_3sub3[] = {
  107853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107856. 0, 0, 3, 6, 3, 7, 3, 7, 5, 7, 7, 7, 7, 7, 6, 7,
  107857. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107858. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107859. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107860. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107861. };
  107862. static static_codebook _huff_book_line_2048x27_3sub3 = {
  107863. 1, 128,
  107864. _huff_lengthlist_line_2048x27_3sub3,
  107865. 0, 0, 0, 0, 0,
  107866. NULL,
  107867. NULL,
  107868. NULL,
  107869. NULL,
  107870. 0
  107871. };
  107872. static long _huff_lengthlist_line_2048x27_4sub1[] = {
  107873. 0, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4, 5, 4, 5, 4,
  107874. 4, 5,
  107875. };
  107876. static static_codebook _huff_book_line_2048x27_4sub1 = {
  107877. 1, 18,
  107878. _huff_lengthlist_line_2048x27_4sub1,
  107879. 0, 0, 0, 0, 0,
  107880. NULL,
  107881. NULL,
  107882. NULL,
  107883. NULL,
  107884. 0
  107885. };
  107886. static long _huff_lengthlist_line_2048x27_4sub2[] = {
  107887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107888. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 5, 6, 5, 6, 5, 7,
  107889. 6, 6, 6, 7, 7, 7, 8, 9, 9, 9,12,10,11,10,10,12,
  107890. 10,10,
  107891. };
  107892. static static_codebook _huff_book_line_2048x27_4sub2 = {
  107893. 1, 50,
  107894. _huff_lengthlist_line_2048x27_4sub2,
  107895. 0, 0, 0, 0, 0,
  107896. NULL,
  107897. NULL,
  107898. NULL,
  107899. NULL,
  107900. 0
  107901. };
  107902. static long _huff_lengthlist_line_2048x27_4sub3[] = {
  107903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107906. 0, 0, 3, 6, 5, 7, 5, 7, 7, 7, 7, 7, 5, 7, 5, 7,
  107907. 5, 7, 5, 7, 7, 7, 7, 7, 4, 7, 7, 7, 7, 7, 7, 7,
  107908. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107909. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107910. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107911. };
  107912. static static_codebook _huff_book_line_2048x27_4sub3 = {
  107913. 1, 128,
  107914. _huff_lengthlist_line_2048x27_4sub3,
  107915. 0, 0, 0, 0, 0,
  107916. NULL,
  107917. NULL,
  107918. NULL,
  107919. NULL,
  107920. 0
  107921. };
  107922. static long _huff_lengthlist_line_256x4low_class0[] = {
  107923. 4, 5, 6,11, 5, 5, 6,10, 7, 7, 6, 6,14,13, 9, 9,
  107924. 6, 6, 6,10, 6, 6, 6, 9, 8, 7, 7, 9,14,12, 8,11,
  107925. 8, 7, 7,11, 8, 8, 7,11, 9, 9, 7, 9,13,11, 9,13,
  107926. 19,19,18,19,15,16,16,19,11,11,10,13,10,10, 9,15,
  107927. 5, 5, 6,13, 6, 6, 6,11, 8, 7, 6, 7,14,11,10,11,
  107928. 6, 6, 6,12, 7, 6, 6,11, 8, 7, 7,11,13,11, 9,11,
  107929. 9, 7, 6,12, 8, 7, 6,12, 9, 8, 8,11,13,10, 7,13,
  107930. 19,19,17,19,17,14,14,19,12,10, 8,12,13,10, 9,16,
  107931. 7, 8, 7,12, 7, 7, 7,11, 8, 7, 7, 8,12,12,11,11,
  107932. 8, 8, 7,12, 8, 7, 6,11, 8, 7, 7,10,10,11,10,11,
  107933. 9, 8, 8,13, 9, 8, 7,12,10, 9, 7,11, 9, 8, 7,11,
  107934. 18,18,15,18,18,16,17,18,15,11,10,18,11, 9, 9,18,
  107935. 16,16,13,16,12,11,10,16,12,11, 9, 6,15,12,11,13,
  107936. 16,16,14,14,13,11,12,16,12, 9, 9,13,13,10,10,12,
  107937. 17,18,17,17,14,15,14,16,14,12,14,15,12,10,11,12,
  107938. 18,18,18,18,18,18,18,18,18,12,13,18,16,11, 9,18,
  107939. };
  107940. static static_codebook _huff_book_line_256x4low_class0 = {
  107941. 1, 256,
  107942. _huff_lengthlist_line_256x4low_class0,
  107943. 0, 0, 0, 0, 0,
  107944. NULL,
  107945. NULL,
  107946. NULL,
  107947. NULL,
  107948. 0
  107949. };
  107950. static long _huff_lengthlist_line_256x4low_0sub0[] = {
  107951. 1, 3, 2, 3,
  107952. };
  107953. static static_codebook _huff_book_line_256x4low_0sub0 = {
  107954. 1, 4,
  107955. _huff_lengthlist_line_256x4low_0sub0,
  107956. 0, 0, 0, 0, 0,
  107957. NULL,
  107958. NULL,
  107959. NULL,
  107960. NULL,
  107961. 0
  107962. };
  107963. static long _huff_lengthlist_line_256x4low_0sub1[] = {
  107964. 0, 0, 0, 0, 2, 3, 2, 3, 3, 3,
  107965. };
  107966. static static_codebook _huff_book_line_256x4low_0sub1 = {
  107967. 1, 10,
  107968. _huff_lengthlist_line_256x4low_0sub1,
  107969. 0, 0, 0, 0, 0,
  107970. NULL,
  107971. NULL,
  107972. NULL,
  107973. NULL,
  107974. 0
  107975. };
  107976. static long _huff_lengthlist_line_256x4low_0sub2[] = {
  107977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 3, 4,
  107978. 4, 4, 4, 4, 5, 5, 5, 6, 6,
  107979. };
  107980. static static_codebook _huff_book_line_256x4low_0sub2 = {
  107981. 1, 25,
  107982. _huff_lengthlist_line_256x4low_0sub2,
  107983. 0, 0, 0, 0, 0,
  107984. NULL,
  107985. NULL,
  107986. NULL,
  107987. NULL,
  107988. 0
  107989. };
  107990. static long _huff_lengthlist_line_256x4low_0sub3[] = {
  107991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 2, 4, 3, 5, 4,
  107993. 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 8, 6, 9,
  107994. 7,12,11,16,13,16,12,15,13,15,12,14,12,15,15,15,
  107995. };
  107996. static static_codebook _huff_book_line_256x4low_0sub3 = {
  107997. 1, 64,
  107998. _huff_lengthlist_line_256x4low_0sub3,
  107999. 0, 0, 0, 0, 0,
  108000. NULL,
  108001. NULL,
  108002. NULL,
  108003. NULL,
  108004. 0
  108005. };
  108006. /*** End of inlined file: floor_books.h ***/
  108007. static static_codebook *_floor_128x4_books[]={
  108008. &_huff_book_line_128x4_class0,
  108009. &_huff_book_line_128x4_0sub0,
  108010. &_huff_book_line_128x4_0sub1,
  108011. &_huff_book_line_128x4_0sub2,
  108012. &_huff_book_line_128x4_0sub3,
  108013. };
  108014. static static_codebook *_floor_256x4_books[]={
  108015. &_huff_book_line_256x4_class0,
  108016. &_huff_book_line_256x4_0sub0,
  108017. &_huff_book_line_256x4_0sub1,
  108018. &_huff_book_line_256x4_0sub2,
  108019. &_huff_book_line_256x4_0sub3,
  108020. };
  108021. static static_codebook *_floor_128x7_books[]={
  108022. &_huff_book_line_128x7_class0,
  108023. &_huff_book_line_128x7_class1,
  108024. &_huff_book_line_128x7_0sub1,
  108025. &_huff_book_line_128x7_0sub2,
  108026. &_huff_book_line_128x7_0sub3,
  108027. &_huff_book_line_128x7_1sub1,
  108028. &_huff_book_line_128x7_1sub2,
  108029. &_huff_book_line_128x7_1sub3,
  108030. };
  108031. static static_codebook *_floor_256x7_books[]={
  108032. &_huff_book_line_256x7_class0,
  108033. &_huff_book_line_256x7_class1,
  108034. &_huff_book_line_256x7_0sub1,
  108035. &_huff_book_line_256x7_0sub2,
  108036. &_huff_book_line_256x7_0sub3,
  108037. &_huff_book_line_256x7_1sub1,
  108038. &_huff_book_line_256x7_1sub2,
  108039. &_huff_book_line_256x7_1sub3,
  108040. };
  108041. static static_codebook *_floor_128x11_books[]={
  108042. &_huff_book_line_128x11_class1,
  108043. &_huff_book_line_128x11_class2,
  108044. &_huff_book_line_128x11_class3,
  108045. &_huff_book_line_128x11_0sub0,
  108046. &_huff_book_line_128x11_1sub0,
  108047. &_huff_book_line_128x11_1sub1,
  108048. &_huff_book_line_128x11_2sub1,
  108049. &_huff_book_line_128x11_2sub2,
  108050. &_huff_book_line_128x11_2sub3,
  108051. &_huff_book_line_128x11_3sub1,
  108052. &_huff_book_line_128x11_3sub2,
  108053. &_huff_book_line_128x11_3sub3,
  108054. };
  108055. static static_codebook *_floor_128x17_books[]={
  108056. &_huff_book_line_128x17_class1,
  108057. &_huff_book_line_128x17_class2,
  108058. &_huff_book_line_128x17_class3,
  108059. &_huff_book_line_128x17_0sub0,
  108060. &_huff_book_line_128x17_1sub0,
  108061. &_huff_book_line_128x17_1sub1,
  108062. &_huff_book_line_128x17_2sub1,
  108063. &_huff_book_line_128x17_2sub2,
  108064. &_huff_book_line_128x17_2sub3,
  108065. &_huff_book_line_128x17_3sub1,
  108066. &_huff_book_line_128x17_3sub2,
  108067. &_huff_book_line_128x17_3sub3,
  108068. };
  108069. static static_codebook *_floor_256x4low_books[]={
  108070. &_huff_book_line_256x4low_class0,
  108071. &_huff_book_line_256x4low_0sub0,
  108072. &_huff_book_line_256x4low_0sub1,
  108073. &_huff_book_line_256x4low_0sub2,
  108074. &_huff_book_line_256x4low_0sub3,
  108075. };
  108076. static static_codebook *_floor_1024x27_books[]={
  108077. &_huff_book_line_1024x27_class1,
  108078. &_huff_book_line_1024x27_class2,
  108079. &_huff_book_line_1024x27_class3,
  108080. &_huff_book_line_1024x27_class4,
  108081. &_huff_book_line_1024x27_0sub0,
  108082. &_huff_book_line_1024x27_1sub0,
  108083. &_huff_book_line_1024x27_1sub1,
  108084. &_huff_book_line_1024x27_2sub0,
  108085. &_huff_book_line_1024x27_2sub1,
  108086. &_huff_book_line_1024x27_3sub1,
  108087. &_huff_book_line_1024x27_3sub2,
  108088. &_huff_book_line_1024x27_3sub3,
  108089. &_huff_book_line_1024x27_4sub1,
  108090. &_huff_book_line_1024x27_4sub2,
  108091. &_huff_book_line_1024x27_4sub3,
  108092. };
  108093. static static_codebook *_floor_2048x27_books[]={
  108094. &_huff_book_line_2048x27_class1,
  108095. &_huff_book_line_2048x27_class2,
  108096. &_huff_book_line_2048x27_class3,
  108097. &_huff_book_line_2048x27_class4,
  108098. &_huff_book_line_2048x27_0sub0,
  108099. &_huff_book_line_2048x27_1sub0,
  108100. &_huff_book_line_2048x27_1sub1,
  108101. &_huff_book_line_2048x27_2sub0,
  108102. &_huff_book_line_2048x27_2sub1,
  108103. &_huff_book_line_2048x27_3sub1,
  108104. &_huff_book_line_2048x27_3sub2,
  108105. &_huff_book_line_2048x27_3sub3,
  108106. &_huff_book_line_2048x27_4sub1,
  108107. &_huff_book_line_2048x27_4sub2,
  108108. &_huff_book_line_2048x27_4sub3,
  108109. };
  108110. static static_codebook *_floor_512x17_books[]={
  108111. &_huff_book_line_512x17_class1,
  108112. &_huff_book_line_512x17_class2,
  108113. &_huff_book_line_512x17_class3,
  108114. &_huff_book_line_512x17_0sub0,
  108115. &_huff_book_line_512x17_1sub0,
  108116. &_huff_book_line_512x17_1sub1,
  108117. &_huff_book_line_512x17_2sub1,
  108118. &_huff_book_line_512x17_2sub2,
  108119. &_huff_book_line_512x17_2sub3,
  108120. &_huff_book_line_512x17_3sub1,
  108121. &_huff_book_line_512x17_3sub2,
  108122. &_huff_book_line_512x17_3sub3,
  108123. };
  108124. static static_codebook **_floor_books[10]={
  108125. _floor_128x4_books,
  108126. _floor_256x4_books,
  108127. _floor_128x7_books,
  108128. _floor_256x7_books,
  108129. _floor_128x11_books,
  108130. _floor_128x17_books,
  108131. _floor_256x4low_books,
  108132. _floor_1024x27_books,
  108133. _floor_2048x27_books,
  108134. _floor_512x17_books,
  108135. };
  108136. static vorbis_info_floor1 _floor[10]={
  108137. {
  108138. 1,{0},{4},{2},{0},
  108139. {{1,2,3,4}},
  108140. 4,{0,128, 33,8,16,70},
  108141. 60,30,500, 1.,18., -1
  108142. },
  108143. {
  108144. 1,{0},{4},{2},{0},
  108145. {{1,2,3,4}},
  108146. 4,{0,256, 66,16,32,140},
  108147. 60,30,500, 1.,18., -1
  108148. },
  108149. {
  108150. 2,{0,1},{3,4},{2,2},{0,1},
  108151. {{-1,2,3,4},{-1,5,6,7}},
  108152. 4,{0,128, 14,4,58, 2,8,28,90},
  108153. 60,30,500, 1.,18., -1
  108154. },
  108155. {
  108156. 2,{0,1},{3,4},{2,2},{0,1},
  108157. {{-1,2,3,4},{-1,5,6,7}},
  108158. 4,{0,256, 28,8,116, 4,16,56,180},
  108159. 60,30,500, 1.,18., -1
  108160. },
  108161. {
  108162. 4,{0,1,2,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108163. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108164. 2,{0,128, 8,33, 4,16,70, 2,6,12, 23,46,90},
  108165. 60,30,500, 1,18., -1
  108166. },
  108167. {
  108168. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108169. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108170. 2,{0,128, 12,46, 4,8,16, 23,33,70, 2,6,10, 14,19,28, 39,58,90},
  108171. 60,30,500, 1,18., -1
  108172. },
  108173. {
  108174. 1,{0},{4},{2},{0},
  108175. {{1,2,3,4}},
  108176. 4,{0,256, 66,16,32,140},
  108177. 60,30,500, 1.,18., -1
  108178. },
  108179. {
  108180. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108181. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108182. 2,{0,1024, 93,23,372, 6,46,186,750, 14,33,65, 130,260,556,
  108183. 3,10,18,28, 39,55,79,111, 158,220,312, 464,650,850},
  108184. 60,30,500, 3,18., -1 /* lowpass */
  108185. },
  108186. {
  108187. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108188. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108189. 2,{0,2048, 186,46,744, 12,92,372,1500, 28,66,130, 260,520,1112,
  108190. 6,20,36,56, 78,110,158,222, 316,440,624, 928,1300,1700},
  108191. 60,30,500, 3,18., -1 /* lowpass */
  108192. },
  108193. {
  108194. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108195. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108196. 2,{0,512, 46,186, 16,33,65, 93,130,278,
  108197. 7,23,39, 55,79,110, 156,232,360},
  108198. 60,30,500, 1,18., -1 /* lowpass! */
  108199. },
  108200. };
  108201. /*** End of inlined file: floor_all.h ***/
  108202. /*** Start of inlined file: residue_44.h ***/
  108203. /*** Start of inlined file: res_books_stereo.h ***/
  108204. static long _vq_quantlist__16c0_s_p1_0[] = {
  108205. 1,
  108206. 0,
  108207. 2,
  108208. };
  108209. static long _vq_lengthlist__16c0_s_p1_0[] = {
  108210. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  108211. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0,
  108216. 0, 0, 0, 7, 9,10, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  108221. 0, 0, 0, 0, 7, 9, 9, 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, 5, 8, 8, 0, 0, 0, 0,
  108256. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0,
  108261. 0, 0, 0, 9, 9,12, 0, 0, 0, 0, 0, 0,10,12,11, 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, 7,10,10, 0, 0,
  108266. 0, 0, 0, 0, 9,12,10, 0, 0, 0, 0, 0, 0,10,11,12,
  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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  108302. 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,12,11, 0,
  108307. 0, 0, 0, 0, 0, 9,10,12, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,12,
  108312. 0, 0, 0, 0, 0, 0, 9,12, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108620. 0,
  108621. };
  108622. static float _vq_quantthresh__16c0_s_p1_0[] = {
  108623. -0.5, 0.5,
  108624. };
  108625. static long _vq_quantmap__16c0_s_p1_0[] = {
  108626. 1, 0, 2,
  108627. };
  108628. static encode_aux_threshmatch _vq_auxt__16c0_s_p1_0 = {
  108629. _vq_quantthresh__16c0_s_p1_0,
  108630. _vq_quantmap__16c0_s_p1_0,
  108631. 3,
  108632. 3
  108633. };
  108634. static static_codebook _16c0_s_p1_0 = {
  108635. 8, 6561,
  108636. _vq_lengthlist__16c0_s_p1_0,
  108637. 1, -535822336, 1611661312, 2, 0,
  108638. _vq_quantlist__16c0_s_p1_0,
  108639. NULL,
  108640. &_vq_auxt__16c0_s_p1_0,
  108641. NULL,
  108642. 0
  108643. };
  108644. static long _vq_quantlist__16c0_s_p2_0[] = {
  108645. 2,
  108646. 1,
  108647. 3,
  108648. 0,
  108649. 4,
  108650. };
  108651. static long _vq_lengthlist__16c0_s_p2_0[] = {
  108652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108691. 0,
  108692. };
  108693. static float _vq_quantthresh__16c0_s_p2_0[] = {
  108694. -1.5, -0.5, 0.5, 1.5,
  108695. };
  108696. static long _vq_quantmap__16c0_s_p2_0[] = {
  108697. 3, 1, 0, 2, 4,
  108698. };
  108699. static encode_aux_threshmatch _vq_auxt__16c0_s_p2_0 = {
  108700. _vq_quantthresh__16c0_s_p2_0,
  108701. _vq_quantmap__16c0_s_p2_0,
  108702. 5,
  108703. 5
  108704. };
  108705. static static_codebook _16c0_s_p2_0 = {
  108706. 4, 625,
  108707. _vq_lengthlist__16c0_s_p2_0,
  108708. 1, -533725184, 1611661312, 3, 0,
  108709. _vq_quantlist__16c0_s_p2_0,
  108710. NULL,
  108711. &_vq_auxt__16c0_s_p2_0,
  108712. NULL,
  108713. 0
  108714. };
  108715. static long _vq_quantlist__16c0_s_p3_0[] = {
  108716. 2,
  108717. 1,
  108718. 3,
  108719. 0,
  108720. 4,
  108721. };
  108722. static long _vq_lengthlist__16c0_s_p3_0[] = {
  108723. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 7, 6, 0, 0,
  108725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108726. 0, 0, 4, 6, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  108728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108729. 0, 0, 0, 0, 6, 6, 6, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  108730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108762. 0,
  108763. };
  108764. static float _vq_quantthresh__16c0_s_p3_0[] = {
  108765. -1.5, -0.5, 0.5, 1.5,
  108766. };
  108767. static long _vq_quantmap__16c0_s_p3_0[] = {
  108768. 3, 1, 0, 2, 4,
  108769. };
  108770. static encode_aux_threshmatch _vq_auxt__16c0_s_p3_0 = {
  108771. _vq_quantthresh__16c0_s_p3_0,
  108772. _vq_quantmap__16c0_s_p3_0,
  108773. 5,
  108774. 5
  108775. };
  108776. static static_codebook _16c0_s_p3_0 = {
  108777. 4, 625,
  108778. _vq_lengthlist__16c0_s_p3_0,
  108779. 1, -533725184, 1611661312, 3, 0,
  108780. _vq_quantlist__16c0_s_p3_0,
  108781. NULL,
  108782. &_vq_auxt__16c0_s_p3_0,
  108783. NULL,
  108784. 0
  108785. };
  108786. static long _vq_quantlist__16c0_s_p4_0[] = {
  108787. 4,
  108788. 3,
  108789. 5,
  108790. 2,
  108791. 6,
  108792. 1,
  108793. 7,
  108794. 0,
  108795. 8,
  108796. };
  108797. static long _vq_lengthlist__16c0_s_p4_0[] = {
  108798. 1, 3, 2, 7, 8, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  108799. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  108800. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  108801. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  108802. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108803. 0,
  108804. };
  108805. static float _vq_quantthresh__16c0_s_p4_0[] = {
  108806. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  108807. };
  108808. static long _vq_quantmap__16c0_s_p4_0[] = {
  108809. 7, 5, 3, 1, 0, 2, 4, 6,
  108810. 8,
  108811. };
  108812. static encode_aux_threshmatch _vq_auxt__16c0_s_p4_0 = {
  108813. _vq_quantthresh__16c0_s_p4_0,
  108814. _vq_quantmap__16c0_s_p4_0,
  108815. 9,
  108816. 9
  108817. };
  108818. static static_codebook _16c0_s_p4_0 = {
  108819. 2, 81,
  108820. _vq_lengthlist__16c0_s_p4_0,
  108821. 1, -531628032, 1611661312, 4, 0,
  108822. _vq_quantlist__16c0_s_p4_0,
  108823. NULL,
  108824. &_vq_auxt__16c0_s_p4_0,
  108825. NULL,
  108826. 0
  108827. };
  108828. static long _vq_quantlist__16c0_s_p5_0[] = {
  108829. 4,
  108830. 3,
  108831. 5,
  108832. 2,
  108833. 6,
  108834. 1,
  108835. 7,
  108836. 0,
  108837. 8,
  108838. };
  108839. static long _vq_lengthlist__16c0_s_p5_0[] = {
  108840. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  108841. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 8, 0, 0, 0, 7, 7,
  108842. 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0, 0, 0,
  108843. 8, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  108844. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  108845. 10,
  108846. };
  108847. static float _vq_quantthresh__16c0_s_p5_0[] = {
  108848. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  108849. };
  108850. static long _vq_quantmap__16c0_s_p5_0[] = {
  108851. 7, 5, 3, 1, 0, 2, 4, 6,
  108852. 8,
  108853. };
  108854. static encode_aux_threshmatch _vq_auxt__16c0_s_p5_0 = {
  108855. _vq_quantthresh__16c0_s_p5_0,
  108856. _vq_quantmap__16c0_s_p5_0,
  108857. 9,
  108858. 9
  108859. };
  108860. static static_codebook _16c0_s_p5_0 = {
  108861. 2, 81,
  108862. _vq_lengthlist__16c0_s_p5_0,
  108863. 1, -531628032, 1611661312, 4, 0,
  108864. _vq_quantlist__16c0_s_p5_0,
  108865. NULL,
  108866. &_vq_auxt__16c0_s_p5_0,
  108867. NULL,
  108868. 0
  108869. };
  108870. static long _vq_quantlist__16c0_s_p6_0[] = {
  108871. 8,
  108872. 7,
  108873. 9,
  108874. 6,
  108875. 10,
  108876. 5,
  108877. 11,
  108878. 4,
  108879. 12,
  108880. 3,
  108881. 13,
  108882. 2,
  108883. 14,
  108884. 1,
  108885. 15,
  108886. 0,
  108887. 16,
  108888. };
  108889. static long _vq_lengthlist__16c0_s_p6_0[] = {
  108890. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  108891. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  108892. 11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  108893. 11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  108894. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  108895. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  108896. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  108897. 10,11,11,12,12,12,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  108898. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10,10,10,
  108899. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  108900. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  108901. 9,10,10,11,11,12,12,13,13,13,14, 0, 0, 0, 0, 0,
  108902. 10,10,10,11,11,11,12,12,13,13,13,14, 0, 0, 0, 0,
  108903. 0, 0, 0,10,10,11,11,12,12,13,13,14,14, 0, 0, 0,
  108904. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  108905. 0, 0, 0, 0, 0,11,11,12,12,12,13,13,14,15,14, 0,
  108906. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,14,14,15,
  108907. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,13,14,
  108908. 14,
  108909. };
  108910. static float _vq_quantthresh__16c0_s_p6_0[] = {
  108911. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  108912. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  108913. };
  108914. static long _vq_quantmap__16c0_s_p6_0[] = {
  108915. 15, 13, 11, 9, 7, 5, 3, 1,
  108916. 0, 2, 4, 6, 8, 10, 12, 14,
  108917. 16,
  108918. };
  108919. static encode_aux_threshmatch _vq_auxt__16c0_s_p6_0 = {
  108920. _vq_quantthresh__16c0_s_p6_0,
  108921. _vq_quantmap__16c0_s_p6_0,
  108922. 17,
  108923. 17
  108924. };
  108925. static static_codebook _16c0_s_p6_0 = {
  108926. 2, 289,
  108927. _vq_lengthlist__16c0_s_p6_0,
  108928. 1, -529530880, 1611661312, 5, 0,
  108929. _vq_quantlist__16c0_s_p6_0,
  108930. NULL,
  108931. &_vq_auxt__16c0_s_p6_0,
  108932. NULL,
  108933. 0
  108934. };
  108935. static long _vq_quantlist__16c0_s_p7_0[] = {
  108936. 1,
  108937. 0,
  108938. 2,
  108939. };
  108940. static long _vq_lengthlist__16c0_s_p7_0[] = {
  108941. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,11,10,10,11,
  108942. 11,10, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  108943. 11,11,11,10, 6, 9, 9,11,12,12,11, 9, 9, 6, 9,10,
  108944. 11,12,12,11, 9,10, 7,11,11,11,11,11,12,13,12, 6,
  108945. 9,10,11,10,10,12,13,13, 6,10, 9,11,10,10,11,12,
  108946. 13,
  108947. };
  108948. static float _vq_quantthresh__16c0_s_p7_0[] = {
  108949. -5.5, 5.5,
  108950. };
  108951. static long _vq_quantmap__16c0_s_p7_0[] = {
  108952. 1, 0, 2,
  108953. };
  108954. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_0 = {
  108955. _vq_quantthresh__16c0_s_p7_0,
  108956. _vq_quantmap__16c0_s_p7_0,
  108957. 3,
  108958. 3
  108959. };
  108960. static static_codebook _16c0_s_p7_0 = {
  108961. 4, 81,
  108962. _vq_lengthlist__16c0_s_p7_0,
  108963. 1, -529137664, 1618345984, 2, 0,
  108964. _vq_quantlist__16c0_s_p7_0,
  108965. NULL,
  108966. &_vq_auxt__16c0_s_p7_0,
  108967. NULL,
  108968. 0
  108969. };
  108970. static long _vq_quantlist__16c0_s_p7_1[] = {
  108971. 5,
  108972. 4,
  108973. 6,
  108974. 3,
  108975. 7,
  108976. 2,
  108977. 8,
  108978. 1,
  108979. 9,
  108980. 0,
  108981. 10,
  108982. };
  108983. static long _vq_lengthlist__16c0_s_p7_1[] = {
  108984. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7,
  108985. 8, 8, 8, 9, 9, 9,10,10,10, 6, 7, 8, 8, 8, 8, 9,
  108986. 8,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10, 7,
  108987. 7, 8, 8, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9, 9,
  108988. 9, 9,11,11,11, 8, 8, 9, 9, 9, 9, 9,10,10,11,11,
  108989. 9, 9, 9, 9, 9, 9, 9,10,11,11,11,10,11, 9, 9, 9,
  108990. 9,10, 9,11,11,11,10,11,10,10, 9, 9,10,10,11,11,
  108991. 11,11,11, 9, 9, 9, 9,10,10,
  108992. };
  108993. static float _vq_quantthresh__16c0_s_p7_1[] = {
  108994. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  108995. 3.5, 4.5,
  108996. };
  108997. static long _vq_quantmap__16c0_s_p7_1[] = {
  108998. 9, 7, 5, 3, 1, 0, 2, 4,
  108999. 6, 8, 10,
  109000. };
  109001. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_1 = {
  109002. _vq_quantthresh__16c0_s_p7_1,
  109003. _vq_quantmap__16c0_s_p7_1,
  109004. 11,
  109005. 11
  109006. };
  109007. static static_codebook _16c0_s_p7_1 = {
  109008. 2, 121,
  109009. _vq_lengthlist__16c0_s_p7_1,
  109010. 1, -531365888, 1611661312, 4, 0,
  109011. _vq_quantlist__16c0_s_p7_1,
  109012. NULL,
  109013. &_vq_auxt__16c0_s_p7_1,
  109014. NULL,
  109015. 0
  109016. };
  109017. static long _vq_quantlist__16c0_s_p8_0[] = {
  109018. 6,
  109019. 5,
  109020. 7,
  109021. 4,
  109022. 8,
  109023. 3,
  109024. 9,
  109025. 2,
  109026. 10,
  109027. 1,
  109028. 11,
  109029. 0,
  109030. 12,
  109031. };
  109032. static long _vq_lengthlist__16c0_s_p8_0[] = {
  109033. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8,10,10, 6, 5, 6,
  109034. 8, 8, 8, 8, 8, 8, 8, 9,10,10, 7, 6, 6, 8, 8, 8,
  109035. 8, 8, 8, 8, 8,10,10, 0, 8, 8, 8, 8, 9, 8, 9, 9,
  109036. 9,10,10,10, 0, 9, 8, 8, 8, 9, 9, 8, 8, 9, 9,10,
  109037. 10, 0,12,11, 8, 8, 9, 9, 9, 9,10,10,11,10, 0,12,
  109038. 13, 8, 8, 9,10, 9, 9,11,11,11,12, 0, 0, 0, 8, 8,
  109039. 8, 8,10, 9,12,13,12,14, 0, 0, 0, 8, 8, 8, 9,10,
  109040. 10,12,12,13,14, 0, 0, 0,13,13, 9, 9,11,11, 0, 0,
  109041. 14, 0, 0, 0, 0,14,14,10,10,12,11,12,14,14,14, 0,
  109042. 0, 0, 0, 0,11,11,13,13,14,13,14,14, 0, 0, 0, 0,
  109043. 0,12,13,13,12,13,14,14,14,
  109044. };
  109045. static float _vq_quantthresh__16c0_s_p8_0[] = {
  109046. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  109047. 12.5, 17.5, 22.5, 27.5,
  109048. };
  109049. static long _vq_quantmap__16c0_s_p8_0[] = {
  109050. 11, 9, 7, 5, 3, 1, 0, 2,
  109051. 4, 6, 8, 10, 12,
  109052. };
  109053. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_0 = {
  109054. _vq_quantthresh__16c0_s_p8_0,
  109055. _vq_quantmap__16c0_s_p8_0,
  109056. 13,
  109057. 13
  109058. };
  109059. static static_codebook _16c0_s_p8_0 = {
  109060. 2, 169,
  109061. _vq_lengthlist__16c0_s_p8_0,
  109062. 1, -526516224, 1616117760, 4, 0,
  109063. _vq_quantlist__16c0_s_p8_0,
  109064. NULL,
  109065. &_vq_auxt__16c0_s_p8_0,
  109066. NULL,
  109067. 0
  109068. };
  109069. static long _vq_quantlist__16c0_s_p8_1[] = {
  109070. 2,
  109071. 1,
  109072. 3,
  109073. 0,
  109074. 4,
  109075. };
  109076. static long _vq_lengthlist__16c0_s_p8_1[] = {
  109077. 1, 4, 3, 5, 5, 7, 7, 7, 6, 6, 7, 7, 7, 5, 5, 7,
  109078. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  109079. };
  109080. static float _vq_quantthresh__16c0_s_p8_1[] = {
  109081. -1.5, -0.5, 0.5, 1.5,
  109082. };
  109083. static long _vq_quantmap__16c0_s_p8_1[] = {
  109084. 3, 1, 0, 2, 4,
  109085. };
  109086. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_1 = {
  109087. _vq_quantthresh__16c0_s_p8_1,
  109088. _vq_quantmap__16c0_s_p8_1,
  109089. 5,
  109090. 5
  109091. };
  109092. static static_codebook _16c0_s_p8_1 = {
  109093. 2, 25,
  109094. _vq_lengthlist__16c0_s_p8_1,
  109095. 1, -533725184, 1611661312, 3, 0,
  109096. _vq_quantlist__16c0_s_p8_1,
  109097. NULL,
  109098. &_vq_auxt__16c0_s_p8_1,
  109099. NULL,
  109100. 0
  109101. };
  109102. static long _vq_quantlist__16c0_s_p9_0[] = {
  109103. 1,
  109104. 0,
  109105. 2,
  109106. };
  109107. static long _vq_lengthlist__16c0_s_p9_0[] = {
  109108. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109109. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109110. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109111. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109112. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109113. 7,
  109114. };
  109115. static float _vq_quantthresh__16c0_s_p9_0[] = {
  109116. -157.5, 157.5,
  109117. };
  109118. static long _vq_quantmap__16c0_s_p9_0[] = {
  109119. 1, 0, 2,
  109120. };
  109121. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_0 = {
  109122. _vq_quantthresh__16c0_s_p9_0,
  109123. _vq_quantmap__16c0_s_p9_0,
  109124. 3,
  109125. 3
  109126. };
  109127. static static_codebook _16c0_s_p9_0 = {
  109128. 4, 81,
  109129. _vq_lengthlist__16c0_s_p9_0,
  109130. 1, -518803456, 1628680192, 2, 0,
  109131. _vq_quantlist__16c0_s_p9_0,
  109132. NULL,
  109133. &_vq_auxt__16c0_s_p9_0,
  109134. NULL,
  109135. 0
  109136. };
  109137. static long _vq_quantlist__16c0_s_p9_1[] = {
  109138. 7,
  109139. 6,
  109140. 8,
  109141. 5,
  109142. 9,
  109143. 4,
  109144. 10,
  109145. 3,
  109146. 11,
  109147. 2,
  109148. 12,
  109149. 1,
  109150. 13,
  109151. 0,
  109152. 14,
  109153. };
  109154. static long _vq_lengthlist__16c0_s_p9_1[] = {
  109155. 1, 5, 5, 5, 5, 9,11,11,10,10,10,10,10,10,10, 7,
  109156. 6, 6, 6, 6,10,10,10,10,10,10,10,10,10,10, 7, 6,
  109157. 6, 6, 6,10, 9,10,10,10,10,10,10,10,10,10, 7, 7,
  109158. 8, 9,10,10,10,10,10,10,10,10,10,10,10, 8, 7,10,
  109159. 10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109160. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109161. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109162. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109163. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109164. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109165. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109166. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109167. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109168. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109169. 10,
  109170. };
  109171. static float _vq_quantthresh__16c0_s_p9_1[] = {
  109172. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  109173. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  109174. };
  109175. static long _vq_quantmap__16c0_s_p9_1[] = {
  109176. 13, 11, 9, 7, 5, 3, 1, 0,
  109177. 2, 4, 6, 8, 10, 12, 14,
  109178. };
  109179. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_1 = {
  109180. _vq_quantthresh__16c0_s_p9_1,
  109181. _vq_quantmap__16c0_s_p9_1,
  109182. 15,
  109183. 15
  109184. };
  109185. static static_codebook _16c0_s_p9_1 = {
  109186. 2, 225,
  109187. _vq_lengthlist__16c0_s_p9_1,
  109188. 1, -520986624, 1620377600, 4, 0,
  109189. _vq_quantlist__16c0_s_p9_1,
  109190. NULL,
  109191. &_vq_auxt__16c0_s_p9_1,
  109192. NULL,
  109193. 0
  109194. };
  109195. static long _vq_quantlist__16c0_s_p9_2[] = {
  109196. 10,
  109197. 9,
  109198. 11,
  109199. 8,
  109200. 12,
  109201. 7,
  109202. 13,
  109203. 6,
  109204. 14,
  109205. 5,
  109206. 15,
  109207. 4,
  109208. 16,
  109209. 3,
  109210. 17,
  109211. 2,
  109212. 18,
  109213. 1,
  109214. 19,
  109215. 0,
  109216. 20,
  109217. };
  109218. static long _vq_lengthlist__16c0_s_p9_2[] = {
  109219. 1, 5, 5, 7, 8, 8, 7, 9, 9, 9,12,12,11,12,12,10,
  109220. 10,11,12,12,12,11,12,12, 8, 9, 8, 7, 9,10,10,11,
  109221. 11,10,11,12,10,12,10,12,12,12,11,12,11, 9, 8, 8,
  109222. 9,10, 9, 8, 9,10,12,12,11,11,12,11,10,11,12,11,
  109223. 12,12, 8, 9, 9, 9,10,11,12,11,12,11,11,11,11,12,
  109224. 12,11,11,12,12,11,11, 9, 9, 8, 9, 9,11, 9, 9,10,
  109225. 9,11,11,11,11,12,11,11,10,12,12,12, 9,12,11,10,
  109226. 11,11,11,11,12,12,12,11,11,11,12,10,12,12,12,10,
  109227. 10, 9,10, 9,10,10, 9, 9, 9,10,10,12,10,11,11, 9,
  109228. 11,11,10,11,11,11,10,10,10, 9, 9,10,10, 9, 9,10,
  109229. 11,11,10,11,10,11,10,11,11,10,11,11,11,10, 9,10,
  109230. 10, 9,10, 9, 9,11, 9, 9,11,10,10,11,11,10,10,11,
  109231. 10,11, 8, 9,11,11,10, 9,10,11,11,10,11,11,10,10,
  109232. 10,11,10, 9,10,10,11, 9,10,10, 9,11,10,10,10,10,
  109233. 11,10,11,11, 9,11,10,11,10,10,11,11,10,10,10, 9,
  109234. 10,10,11,11,11, 9,10,10,10,10,10,11,10,10,10, 9,
  109235. 10,10,11,10,10,10,10,10, 9,10,11,10,10,10,10,11,
  109236. 11,11,10,10,10,10,10,11,10,11,10,11,10,10,10, 9,
  109237. 11,11,10,10,10,11,11,10,10,10,10,10,10,10,10,11,
  109238. 11, 9,10,10,10,11,10,11,10,10,10,11, 9,10,11,10,
  109239. 11,10,10, 9,10,10,10,11,10,11,10,10,10,10,10,11,
  109240. 11,10,11,11,10,10,11,11,10, 9, 9,10,10,10,10,10,
  109241. 9,11, 9,10,10,10,11,11,10,10,10,10,11,11,11,10,
  109242. 9, 9,10,10,11,10,10,10,10,10,11,11,11,10,10,10,
  109243. 11,11,11, 9,10,10,10,10, 9,10, 9,10,11,10,11,10,
  109244. 10,11,11,10,11,11,11,11,11,10,11,10,10,10, 9,11,
  109245. 11,10,11,11,11,11,11,11,11,11,11,10,11,10,10,10,
  109246. 10,11,10,10,11, 9,10,10,10,
  109247. };
  109248. static float _vq_quantthresh__16c0_s_p9_2[] = {
  109249. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  109250. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  109251. 6.5, 7.5, 8.5, 9.5,
  109252. };
  109253. static long _vq_quantmap__16c0_s_p9_2[] = {
  109254. 19, 17, 15, 13, 11, 9, 7, 5,
  109255. 3, 1, 0, 2, 4, 6, 8, 10,
  109256. 12, 14, 16, 18, 20,
  109257. };
  109258. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_2 = {
  109259. _vq_quantthresh__16c0_s_p9_2,
  109260. _vq_quantmap__16c0_s_p9_2,
  109261. 21,
  109262. 21
  109263. };
  109264. static static_codebook _16c0_s_p9_2 = {
  109265. 2, 441,
  109266. _vq_lengthlist__16c0_s_p9_2,
  109267. 1, -529268736, 1611661312, 5, 0,
  109268. _vq_quantlist__16c0_s_p9_2,
  109269. NULL,
  109270. &_vq_auxt__16c0_s_p9_2,
  109271. NULL,
  109272. 0
  109273. };
  109274. static long _huff_lengthlist__16c0_s_single[] = {
  109275. 3, 4,19, 7, 9, 7, 8,11, 9,12, 4, 1,19, 6, 7, 7,
  109276. 8,10,11,13,18,18,18,18,18,18,18,18,18,18, 8, 6,
  109277. 18, 8, 9, 9,11,12,14,18, 9, 6,18, 9, 7, 8, 9,11,
  109278. 12,18, 7, 6,18, 8, 7, 7, 7, 9,11,17, 8, 8,18, 9,
  109279. 7, 6, 6, 8,11,17,10,10,18,12, 9, 8, 7, 9,12,18,
  109280. 13,15,18,15,13,11,10,11,15,18,14,18,18,18,18,18,
  109281. 16,16,18,18,
  109282. };
  109283. static static_codebook _huff_book__16c0_s_single = {
  109284. 2, 100,
  109285. _huff_lengthlist__16c0_s_single,
  109286. 0, 0, 0, 0, 0,
  109287. NULL,
  109288. NULL,
  109289. NULL,
  109290. NULL,
  109291. 0
  109292. };
  109293. static long _huff_lengthlist__16c1_s_long[] = {
  109294. 2, 5,20, 7,10, 7, 8,10,11,11, 4, 2,20, 5, 8, 6,
  109295. 7, 9,10,10,20,20,20,20,19,19,19,19,19,19, 7, 5,
  109296. 19, 6,10, 7, 9,11,13,17,11, 8,19,10, 7, 7, 8,10,
  109297. 11,15, 7, 5,19, 7, 7, 5, 6, 9,11,16, 7, 6,19, 8,
  109298. 7, 6, 6, 7, 9,13, 9, 9,19,11, 9, 8, 6, 7, 8,13,
  109299. 12,14,19,16,13,10, 9, 8, 9,13,14,17,19,18,18,17,
  109300. 12,11,11,13,
  109301. };
  109302. static static_codebook _huff_book__16c1_s_long = {
  109303. 2, 100,
  109304. _huff_lengthlist__16c1_s_long,
  109305. 0, 0, 0, 0, 0,
  109306. NULL,
  109307. NULL,
  109308. NULL,
  109309. NULL,
  109310. 0
  109311. };
  109312. static long _vq_quantlist__16c1_s_p1_0[] = {
  109313. 1,
  109314. 0,
  109315. 2,
  109316. };
  109317. static long _vq_lengthlist__16c1_s_p1_0[] = {
  109318. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  109319. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  109324. 0, 0, 0, 7, 8, 9, 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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  109329. 0, 0, 0, 0, 7, 9, 9, 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, 5, 8, 7, 0, 0, 0, 0,
  109364. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  109369. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 9,11,10, 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, 7, 9, 9, 0, 0,
  109374. 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109410. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  109415. 0, 0, 0, 0, 0, 8, 9,11, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  109420. 0, 0, 0, 0, 0, 0, 9,11, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109728. 0,
  109729. };
  109730. static float _vq_quantthresh__16c1_s_p1_0[] = {
  109731. -0.5, 0.5,
  109732. };
  109733. static long _vq_quantmap__16c1_s_p1_0[] = {
  109734. 1, 0, 2,
  109735. };
  109736. static encode_aux_threshmatch _vq_auxt__16c1_s_p1_0 = {
  109737. _vq_quantthresh__16c1_s_p1_0,
  109738. _vq_quantmap__16c1_s_p1_0,
  109739. 3,
  109740. 3
  109741. };
  109742. static static_codebook _16c1_s_p1_0 = {
  109743. 8, 6561,
  109744. _vq_lengthlist__16c1_s_p1_0,
  109745. 1, -535822336, 1611661312, 2, 0,
  109746. _vq_quantlist__16c1_s_p1_0,
  109747. NULL,
  109748. &_vq_auxt__16c1_s_p1_0,
  109749. NULL,
  109750. 0
  109751. };
  109752. static long _vq_quantlist__16c1_s_p2_0[] = {
  109753. 2,
  109754. 1,
  109755. 3,
  109756. 0,
  109757. 4,
  109758. };
  109759. static long _vq_lengthlist__16c1_s_p2_0[] = {
  109760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109799. 0,
  109800. };
  109801. static float _vq_quantthresh__16c1_s_p2_0[] = {
  109802. -1.5, -0.5, 0.5, 1.5,
  109803. };
  109804. static long _vq_quantmap__16c1_s_p2_0[] = {
  109805. 3, 1, 0, 2, 4,
  109806. };
  109807. static encode_aux_threshmatch _vq_auxt__16c1_s_p2_0 = {
  109808. _vq_quantthresh__16c1_s_p2_0,
  109809. _vq_quantmap__16c1_s_p2_0,
  109810. 5,
  109811. 5
  109812. };
  109813. static static_codebook _16c1_s_p2_0 = {
  109814. 4, 625,
  109815. _vq_lengthlist__16c1_s_p2_0,
  109816. 1, -533725184, 1611661312, 3, 0,
  109817. _vq_quantlist__16c1_s_p2_0,
  109818. NULL,
  109819. &_vq_auxt__16c1_s_p2_0,
  109820. NULL,
  109821. 0
  109822. };
  109823. static long _vq_quantlist__16c1_s_p3_0[] = {
  109824. 2,
  109825. 1,
  109826. 3,
  109827. 0,
  109828. 4,
  109829. };
  109830. static long _vq_lengthlist__16c1_s_p3_0[] = {
  109831. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  109833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109834. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 9, 9,
  109836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109837. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  109838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109870. 0,
  109871. };
  109872. static float _vq_quantthresh__16c1_s_p3_0[] = {
  109873. -1.5, -0.5, 0.5, 1.5,
  109874. };
  109875. static long _vq_quantmap__16c1_s_p3_0[] = {
  109876. 3, 1, 0, 2, 4,
  109877. };
  109878. static encode_aux_threshmatch _vq_auxt__16c1_s_p3_0 = {
  109879. _vq_quantthresh__16c1_s_p3_0,
  109880. _vq_quantmap__16c1_s_p3_0,
  109881. 5,
  109882. 5
  109883. };
  109884. static static_codebook _16c1_s_p3_0 = {
  109885. 4, 625,
  109886. _vq_lengthlist__16c1_s_p3_0,
  109887. 1, -533725184, 1611661312, 3, 0,
  109888. _vq_quantlist__16c1_s_p3_0,
  109889. NULL,
  109890. &_vq_auxt__16c1_s_p3_0,
  109891. NULL,
  109892. 0
  109893. };
  109894. static long _vq_quantlist__16c1_s_p4_0[] = {
  109895. 4,
  109896. 3,
  109897. 5,
  109898. 2,
  109899. 6,
  109900. 1,
  109901. 7,
  109902. 0,
  109903. 8,
  109904. };
  109905. static long _vq_lengthlist__16c1_s_p4_0[] = {
  109906. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  109907. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  109908. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  109909. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 9, 0, 0, 0, 0, 0,
  109910. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109911. 0,
  109912. };
  109913. static float _vq_quantthresh__16c1_s_p4_0[] = {
  109914. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109915. };
  109916. static long _vq_quantmap__16c1_s_p4_0[] = {
  109917. 7, 5, 3, 1, 0, 2, 4, 6,
  109918. 8,
  109919. };
  109920. static encode_aux_threshmatch _vq_auxt__16c1_s_p4_0 = {
  109921. _vq_quantthresh__16c1_s_p4_0,
  109922. _vq_quantmap__16c1_s_p4_0,
  109923. 9,
  109924. 9
  109925. };
  109926. static static_codebook _16c1_s_p4_0 = {
  109927. 2, 81,
  109928. _vq_lengthlist__16c1_s_p4_0,
  109929. 1, -531628032, 1611661312, 4, 0,
  109930. _vq_quantlist__16c1_s_p4_0,
  109931. NULL,
  109932. &_vq_auxt__16c1_s_p4_0,
  109933. NULL,
  109934. 0
  109935. };
  109936. static long _vq_quantlist__16c1_s_p5_0[] = {
  109937. 4,
  109938. 3,
  109939. 5,
  109940. 2,
  109941. 6,
  109942. 1,
  109943. 7,
  109944. 0,
  109945. 8,
  109946. };
  109947. static long _vq_lengthlist__16c1_s_p5_0[] = {
  109948. 1, 3, 3, 5, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  109949. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 8, 8,
  109950. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  109951. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  109952. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  109953. 10,
  109954. };
  109955. static float _vq_quantthresh__16c1_s_p5_0[] = {
  109956. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109957. };
  109958. static long _vq_quantmap__16c1_s_p5_0[] = {
  109959. 7, 5, 3, 1, 0, 2, 4, 6,
  109960. 8,
  109961. };
  109962. static encode_aux_threshmatch _vq_auxt__16c1_s_p5_0 = {
  109963. _vq_quantthresh__16c1_s_p5_0,
  109964. _vq_quantmap__16c1_s_p5_0,
  109965. 9,
  109966. 9
  109967. };
  109968. static static_codebook _16c1_s_p5_0 = {
  109969. 2, 81,
  109970. _vq_lengthlist__16c1_s_p5_0,
  109971. 1, -531628032, 1611661312, 4, 0,
  109972. _vq_quantlist__16c1_s_p5_0,
  109973. NULL,
  109974. &_vq_auxt__16c1_s_p5_0,
  109975. NULL,
  109976. 0
  109977. };
  109978. static long _vq_quantlist__16c1_s_p6_0[] = {
  109979. 8,
  109980. 7,
  109981. 9,
  109982. 6,
  109983. 10,
  109984. 5,
  109985. 11,
  109986. 4,
  109987. 12,
  109988. 3,
  109989. 13,
  109990. 2,
  109991. 14,
  109992. 1,
  109993. 15,
  109994. 0,
  109995. 16,
  109996. };
  109997. static long _vq_lengthlist__16c1_s_p6_0[] = {
  109998. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,12,
  109999. 12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  110000. 12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  110001. 11,12,12, 0, 0, 0, 8, 8, 8, 9,10, 9,10,10,10,10,
  110002. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,11,
  110003. 11,11,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  110004. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  110005. 10,11,11,12,12,13,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  110006. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  110007. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  110008. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  110009. 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0,
  110010. 10,10,11,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0,
  110011. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  110012. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  110013. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0,
  110014. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  110015. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  110016. 14,
  110017. };
  110018. static float _vq_quantthresh__16c1_s_p6_0[] = {
  110019. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  110020. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  110021. };
  110022. static long _vq_quantmap__16c1_s_p6_0[] = {
  110023. 15, 13, 11, 9, 7, 5, 3, 1,
  110024. 0, 2, 4, 6, 8, 10, 12, 14,
  110025. 16,
  110026. };
  110027. static encode_aux_threshmatch _vq_auxt__16c1_s_p6_0 = {
  110028. _vq_quantthresh__16c1_s_p6_0,
  110029. _vq_quantmap__16c1_s_p6_0,
  110030. 17,
  110031. 17
  110032. };
  110033. static static_codebook _16c1_s_p6_0 = {
  110034. 2, 289,
  110035. _vq_lengthlist__16c1_s_p6_0,
  110036. 1, -529530880, 1611661312, 5, 0,
  110037. _vq_quantlist__16c1_s_p6_0,
  110038. NULL,
  110039. &_vq_auxt__16c1_s_p6_0,
  110040. NULL,
  110041. 0
  110042. };
  110043. static long _vq_quantlist__16c1_s_p7_0[] = {
  110044. 1,
  110045. 0,
  110046. 2,
  110047. };
  110048. static long _vq_lengthlist__16c1_s_p7_0[] = {
  110049. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9,10,10,
  110050. 10, 9, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  110051. 11,11,10,10, 6,10, 9,11,11,11,11,10,10, 6,10,10,
  110052. 11,11,11,11,10,10, 7,11,11,11,11,11,12,12,11, 6,
  110053. 10,10,11,10,10,11,11,11, 6,10,10,10,11,10,11,11,
  110054. 11,
  110055. };
  110056. static float _vq_quantthresh__16c1_s_p7_0[] = {
  110057. -5.5, 5.5,
  110058. };
  110059. static long _vq_quantmap__16c1_s_p7_0[] = {
  110060. 1, 0, 2,
  110061. };
  110062. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_0 = {
  110063. _vq_quantthresh__16c1_s_p7_0,
  110064. _vq_quantmap__16c1_s_p7_0,
  110065. 3,
  110066. 3
  110067. };
  110068. static static_codebook _16c1_s_p7_0 = {
  110069. 4, 81,
  110070. _vq_lengthlist__16c1_s_p7_0,
  110071. 1, -529137664, 1618345984, 2, 0,
  110072. _vq_quantlist__16c1_s_p7_0,
  110073. NULL,
  110074. &_vq_auxt__16c1_s_p7_0,
  110075. NULL,
  110076. 0
  110077. };
  110078. static long _vq_quantlist__16c1_s_p7_1[] = {
  110079. 5,
  110080. 4,
  110081. 6,
  110082. 3,
  110083. 7,
  110084. 2,
  110085. 8,
  110086. 1,
  110087. 9,
  110088. 0,
  110089. 10,
  110090. };
  110091. static long _vq_lengthlist__16c1_s_p7_1[] = {
  110092. 2, 3, 3, 5, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  110093. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  110094. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  110095. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  110096. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  110097. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  110098. 8, 9, 9,10,10,10,10,10, 9, 9, 8, 8, 9, 9,10,10,
  110099. 10,10,10, 8, 8, 8, 8, 9, 9,
  110100. };
  110101. static float _vq_quantthresh__16c1_s_p7_1[] = {
  110102. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110103. 3.5, 4.5,
  110104. };
  110105. static long _vq_quantmap__16c1_s_p7_1[] = {
  110106. 9, 7, 5, 3, 1, 0, 2, 4,
  110107. 6, 8, 10,
  110108. };
  110109. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_1 = {
  110110. _vq_quantthresh__16c1_s_p7_1,
  110111. _vq_quantmap__16c1_s_p7_1,
  110112. 11,
  110113. 11
  110114. };
  110115. static static_codebook _16c1_s_p7_1 = {
  110116. 2, 121,
  110117. _vq_lengthlist__16c1_s_p7_1,
  110118. 1, -531365888, 1611661312, 4, 0,
  110119. _vq_quantlist__16c1_s_p7_1,
  110120. NULL,
  110121. &_vq_auxt__16c1_s_p7_1,
  110122. NULL,
  110123. 0
  110124. };
  110125. static long _vq_quantlist__16c1_s_p8_0[] = {
  110126. 6,
  110127. 5,
  110128. 7,
  110129. 4,
  110130. 8,
  110131. 3,
  110132. 9,
  110133. 2,
  110134. 10,
  110135. 1,
  110136. 11,
  110137. 0,
  110138. 12,
  110139. };
  110140. static long _vq_lengthlist__16c1_s_p8_0[] = {
  110141. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  110142. 7, 8, 8, 9, 8, 8, 9, 9,10,11, 6, 5, 5, 8, 8, 9,
  110143. 9, 8, 8, 9,10,10,11, 0, 8, 8, 8, 9, 9, 9, 9, 9,
  110144. 10,10,11,11, 0, 9, 9, 9, 8, 9, 9, 9, 9,10,10,11,
  110145. 11, 0,13,13, 9, 9,10,10,10,10,11,11,12,12, 0,14,
  110146. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  110147. 9, 9,11,11,12,12,13,12, 0, 0, 0,10,10, 9, 9,10,
  110148. 10,12,12,13,13, 0, 0, 0,13,14,11,10,11,11,12,12,
  110149. 13,14, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  110150. 0, 0, 0, 0,12,12,12,12,13,13,14,15, 0, 0, 0, 0,
  110151. 0,12,12,12,12,13,13,14,15,
  110152. };
  110153. static float _vq_quantthresh__16c1_s_p8_0[] = {
  110154. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  110155. 12.5, 17.5, 22.5, 27.5,
  110156. };
  110157. static long _vq_quantmap__16c1_s_p8_0[] = {
  110158. 11, 9, 7, 5, 3, 1, 0, 2,
  110159. 4, 6, 8, 10, 12,
  110160. };
  110161. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_0 = {
  110162. _vq_quantthresh__16c1_s_p8_0,
  110163. _vq_quantmap__16c1_s_p8_0,
  110164. 13,
  110165. 13
  110166. };
  110167. static static_codebook _16c1_s_p8_0 = {
  110168. 2, 169,
  110169. _vq_lengthlist__16c1_s_p8_0,
  110170. 1, -526516224, 1616117760, 4, 0,
  110171. _vq_quantlist__16c1_s_p8_0,
  110172. NULL,
  110173. &_vq_auxt__16c1_s_p8_0,
  110174. NULL,
  110175. 0
  110176. };
  110177. static long _vq_quantlist__16c1_s_p8_1[] = {
  110178. 2,
  110179. 1,
  110180. 3,
  110181. 0,
  110182. 4,
  110183. };
  110184. static long _vq_lengthlist__16c1_s_p8_1[] = {
  110185. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  110186. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  110187. };
  110188. static float _vq_quantthresh__16c1_s_p8_1[] = {
  110189. -1.5, -0.5, 0.5, 1.5,
  110190. };
  110191. static long _vq_quantmap__16c1_s_p8_1[] = {
  110192. 3, 1, 0, 2, 4,
  110193. };
  110194. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_1 = {
  110195. _vq_quantthresh__16c1_s_p8_1,
  110196. _vq_quantmap__16c1_s_p8_1,
  110197. 5,
  110198. 5
  110199. };
  110200. static static_codebook _16c1_s_p8_1 = {
  110201. 2, 25,
  110202. _vq_lengthlist__16c1_s_p8_1,
  110203. 1, -533725184, 1611661312, 3, 0,
  110204. _vq_quantlist__16c1_s_p8_1,
  110205. NULL,
  110206. &_vq_auxt__16c1_s_p8_1,
  110207. NULL,
  110208. 0
  110209. };
  110210. static long _vq_quantlist__16c1_s_p9_0[] = {
  110211. 6,
  110212. 5,
  110213. 7,
  110214. 4,
  110215. 8,
  110216. 3,
  110217. 9,
  110218. 2,
  110219. 10,
  110220. 1,
  110221. 11,
  110222. 0,
  110223. 12,
  110224. };
  110225. static long _vq_lengthlist__16c1_s_p9_0[] = {
  110226. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110227. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110228. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110229. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110230. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110231. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110232. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110233. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110234. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110235. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110236. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110237. };
  110238. static float _vq_quantthresh__16c1_s_p9_0[] = {
  110239. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  110240. 787.5, 1102.5, 1417.5, 1732.5,
  110241. };
  110242. static long _vq_quantmap__16c1_s_p9_0[] = {
  110243. 11, 9, 7, 5, 3, 1, 0, 2,
  110244. 4, 6, 8, 10, 12,
  110245. };
  110246. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_0 = {
  110247. _vq_quantthresh__16c1_s_p9_0,
  110248. _vq_quantmap__16c1_s_p9_0,
  110249. 13,
  110250. 13
  110251. };
  110252. static static_codebook _16c1_s_p9_0 = {
  110253. 2, 169,
  110254. _vq_lengthlist__16c1_s_p9_0,
  110255. 1, -513964032, 1628680192, 4, 0,
  110256. _vq_quantlist__16c1_s_p9_0,
  110257. NULL,
  110258. &_vq_auxt__16c1_s_p9_0,
  110259. NULL,
  110260. 0
  110261. };
  110262. static long _vq_quantlist__16c1_s_p9_1[] = {
  110263. 7,
  110264. 6,
  110265. 8,
  110266. 5,
  110267. 9,
  110268. 4,
  110269. 10,
  110270. 3,
  110271. 11,
  110272. 2,
  110273. 12,
  110274. 1,
  110275. 13,
  110276. 0,
  110277. 14,
  110278. };
  110279. static long _vq_lengthlist__16c1_s_p9_1[] = {
  110280. 1, 4, 4, 4, 4, 8, 8,12,13,14,14,14,14,14,14, 6,
  110281. 6, 6, 6, 6,10, 9,14,14,14,14,14,14,14,14, 7, 6,
  110282. 5, 6, 6,10, 9,12,13,13,13,13,13,13,13,13, 7, 7,
  110283. 9, 9,11,11,12,13,13,13,13,13,13,13,13, 7, 7, 8,
  110284. 8,11,12,13,13,13,13,13,13,13,13,13,12,12,10,10,
  110285. 13,12,13,13,13,13,13,13,13,13,13,12,12,10,10,13,
  110286. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,13,12,
  110287. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110288. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110289. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110290. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110291. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110292. 13,13,13,13,13,13,13,13,13,12,13,13,13,13,13,13,
  110293. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110294. 13,
  110295. };
  110296. static float _vq_quantthresh__16c1_s_p9_1[] = {
  110297. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  110298. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  110299. };
  110300. static long _vq_quantmap__16c1_s_p9_1[] = {
  110301. 13, 11, 9, 7, 5, 3, 1, 0,
  110302. 2, 4, 6, 8, 10, 12, 14,
  110303. };
  110304. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_1 = {
  110305. _vq_quantthresh__16c1_s_p9_1,
  110306. _vq_quantmap__16c1_s_p9_1,
  110307. 15,
  110308. 15
  110309. };
  110310. static static_codebook _16c1_s_p9_1 = {
  110311. 2, 225,
  110312. _vq_lengthlist__16c1_s_p9_1,
  110313. 1, -520986624, 1620377600, 4, 0,
  110314. _vq_quantlist__16c1_s_p9_1,
  110315. NULL,
  110316. &_vq_auxt__16c1_s_p9_1,
  110317. NULL,
  110318. 0
  110319. };
  110320. static long _vq_quantlist__16c1_s_p9_2[] = {
  110321. 10,
  110322. 9,
  110323. 11,
  110324. 8,
  110325. 12,
  110326. 7,
  110327. 13,
  110328. 6,
  110329. 14,
  110330. 5,
  110331. 15,
  110332. 4,
  110333. 16,
  110334. 3,
  110335. 17,
  110336. 2,
  110337. 18,
  110338. 1,
  110339. 19,
  110340. 0,
  110341. 20,
  110342. };
  110343. static long _vq_lengthlist__16c1_s_p9_2[] = {
  110344. 1, 4, 4, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9,10,
  110345. 10,10, 9,10,10,11,12,12, 8, 8, 8, 8, 9, 9, 9, 9,
  110346. 10,10,10,10,10,11,11,10,12,11,11,13,11, 7, 7, 8,
  110347. 8, 8, 8, 9, 9, 9,10,10,10,10, 9,10,10,11,11,12,
  110348. 11,11, 8, 8, 8, 8, 9, 9,10,10,10,10,11,11,11,11,
  110349. 11,11,11,12,11,12,12, 8, 8, 9, 9, 9, 9, 9,10,10,
  110350. 10,10,10,10,11,11,11,11,11,11,12,11, 9, 9, 9, 9,
  110351. 10,10,10,10,11,10,11,11,11,11,11,11,12,12,12,12,
  110352. 11, 9, 9, 9, 9,10,10,10,10,11,11,11,11,11,11,11,
  110353. 11,11,12,12,12,13, 9,10,10, 9,11,10,10,10,10,11,
  110354. 11,11,11,11,10,11,12,11,12,12,11,12,11,10, 9,10,
  110355. 10,11,10,11,11,11,11,11,11,11,11,11,12,12,11,12,
  110356. 12,12,10,10,10,11,10,11,11,11,11,11,11,11,11,11,
  110357. 11,11,12,13,12,12,11, 9,10,10,11,11,10,11,11,11,
  110358. 12,11,11,11,11,11,12,12,13,13,12,13,10,10,12,10,
  110359. 11,11,11,11,11,11,11,11,11,12,12,11,13,12,12,12,
  110360. 12,13,12,11,11,11,11,11,11,12,11,12,11,11,11,11,
  110361. 12,12,13,12,11,12,12,11,11,11,11,11,12,11,11,11,
  110362. 11,12,11,11,12,11,12,13,13,12,12,12,12,11,11,11,
  110363. 11,11,12,11,11,12,11,12,11,11,11,11,13,12,12,12,
  110364. 12,13,11,11,11,12,12,11,11,11,12,11,12,12,12,11,
  110365. 12,13,12,11,11,12,12,11,12,11,11,11,12,12,11,12,
  110366. 11,11,11,12,12,12,12,13,12,13,12,12,12,12,11,11,
  110367. 12,11,11,11,11,11,11,12,12,12,13,12,11,13,13,12,
  110368. 12,11,12,10,11,11,11,11,12,11,12,12,11,12,12,13,
  110369. 12,12,13,12,12,12,12,12,11,12,12,12,11,12,11,11,
  110370. 11,12,13,12,13,13,13,13,13,12,13,13,12,12,13,11,
  110371. 11,11,11,11,12,11,11,12,11,
  110372. };
  110373. static float _vq_quantthresh__16c1_s_p9_2[] = {
  110374. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  110375. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  110376. 6.5, 7.5, 8.5, 9.5,
  110377. };
  110378. static long _vq_quantmap__16c1_s_p9_2[] = {
  110379. 19, 17, 15, 13, 11, 9, 7, 5,
  110380. 3, 1, 0, 2, 4, 6, 8, 10,
  110381. 12, 14, 16, 18, 20,
  110382. };
  110383. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_2 = {
  110384. _vq_quantthresh__16c1_s_p9_2,
  110385. _vq_quantmap__16c1_s_p9_2,
  110386. 21,
  110387. 21
  110388. };
  110389. static static_codebook _16c1_s_p9_2 = {
  110390. 2, 441,
  110391. _vq_lengthlist__16c1_s_p9_2,
  110392. 1, -529268736, 1611661312, 5, 0,
  110393. _vq_quantlist__16c1_s_p9_2,
  110394. NULL,
  110395. &_vq_auxt__16c1_s_p9_2,
  110396. NULL,
  110397. 0
  110398. };
  110399. static long _huff_lengthlist__16c1_s_short[] = {
  110400. 5, 6,17, 8,12, 9,10,10,12,13, 5, 2,17, 4, 9, 5,
  110401. 7, 8,11,13,16,16,16,16,16,16,16,16,16,16, 6, 4,
  110402. 16, 5,10, 5, 7,10,14,16,13, 9,16,11, 8, 7, 8, 9,
  110403. 13,16, 7, 4,16, 5, 7, 4, 6, 8,11,13, 8, 6,16, 7,
  110404. 8, 5, 5, 7, 9,13, 9, 8,16, 9, 8, 6, 6, 7, 9,13,
  110405. 11,11,16,10,10, 7, 7, 7, 9,13,13,13,16,13,13, 9,
  110406. 9, 9,10,13,
  110407. };
  110408. static static_codebook _huff_book__16c1_s_short = {
  110409. 2, 100,
  110410. _huff_lengthlist__16c1_s_short,
  110411. 0, 0, 0, 0, 0,
  110412. NULL,
  110413. NULL,
  110414. NULL,
  110415. NULL,
  110416. 0
  110417. };
  110418. static long _huff_lengthlist__16c2_s_long[] = {
  110419. 4, 7, 9, 9, 9, 8, 9,10,15,19, 5, 4, 5, 6, 7, 7,
  110420. 8, 9,14,16, 6, 5, 4, 5, 6, 7, 8,10,12,19, 7, 6,
  110421. 5, 4, 5, 6, 7, 9,11,18, 8, 7, 6, 5, 5, 5, 7, 9,
  110422. 10,17, 8, 7, 7, 5, 5, 5, 6, 7,12,18, 8, 8, 8, 7,
  110423. 7, 5, 5, 7,12,18, 8, 9,10, 9, 9, 7, 6, 7,12,17,
  110424. 14,18,16,16,15,12,11,10,12,18,15,17,18,18,18,15,
  110425. 14,14,16,18,
  110426. };
  110427. static static_codebook _huff_book__16c2_s_long = {
  110428. 2, 100,
  110429. _huff_lengthlist__16c2_s_long,
  110430. 0, 0, 0, 0, 0,
  110431. NULL,
  110432. NULL,
  110433. NULL,
  110434. NULL,
  110435. 0
  110436. };
  110437. static long _vq_quantlist__16c2_s_p1_0[] = {
  110438. 1,
  110439. 0,
  110440. 2,
  110441. };
  110442. static long _vq_lengthlist__16c2_s_p1_0[] = {
  110443. 1, 3, 3, 0, 0, 0, 0, 0, 0, 4, 5, 5, 0, 0, 0, 0,
  110444. 0, 0, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110448. 0,
  110449. };
  110450. static float _vq_quantthresh__16c2_s_p1_0[] = {
  110451. -0.5, 0.5,
  110452. };
  110453. static long _vq_quantmap__16c2_s_p1_0[] = {
  110454. 1, 0, 2,
  110455. };
  110456. static encode_aux_threshmatch _vq_auxt__16c2_s_p1_0 = {
  110457. _vq_quantthresh__16c2_s_p1_0,
  110458. _vq_quantmap__16c2_s_p1_0,
  110459. 3,
  110460. 3
  110461. };
  110462. static static_codebook _16c2_s_p1_0 = {
  110463. 4, 81,
  110464. _vq_lengthlist__16c2_s_p1_0,
  110465. 1, -535822336, 1611661312, 2, 0,
  110466. _vq_quantlist__16c2_s_p1_0,
  110467. NULL,
  110468. &_vq_auxt__16c2_s_p1_0,
  110469. NULL,
  110470. 0
  110471. };
  110472. static long _vq_quantlist__16c2_s_p2_0[] = {
  110473. 2,
  110474. 1,
  110475. 3,
  110476. 0,
  110477. 4,
  110478. };
  110479. static long _vq_lengthlist__16c2_s_p2_0[] = {
  110480. 2, 4, 3, 7, 7, 0, 0, 0, 7, 8, 0, 0, 0, 8, 8, 0,
  110481. 0, 0, 8, 8, 0, 0, 0, 8, 8, 4, 5, 4, 8, 8, 0, 0,
  110482. 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0,
  110483. 9, 9, 4, 4, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8,
  110484. 8, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 7, 8, 8,10,10,
  110485. 0, 0, 0,12,11, 0, 0, 0,11,11, 0, 0, 0,14,13, 0,
  110486. 0, 0,14,13, 7, 8, 8, 9,10, 0, 0, 0,11,12, 0, 0,
  110487. 0,11,11, 0, 0, 0,14,14, 0, 0, 0,13,14, 0, 0, 0,
  110488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110492. 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8,11,11, 0, 0, 0,
  110493. 11,11, 0, 0, 0,12,11, 0, 0, 0,12,12, 0, 0, 0,13,
  110494. 13, 8, 8, 8,11,11, 0, 0, 0,11,11, 0, 0, 0,11,12,
  110495. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  110496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110500. 0, 0, 0, 0, 0, 8, 8, 8,12,11, 0, 0, 0,12,11, 0,
  110501. 0, 0,11,11, 0, 0, 0,13,13, 0, 0, 0,13,12, 8, 8,
  110502. 8,11,12, 0, 0, 0,11,12, 0, 0, 0,11,11, 0, 0, 0,
  110503. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110508. 0, 0, 8, 9, 9,14,13, 0, 0, 0,13,12, 0, 0, 0,13,
  110509. 13, 0, 0, 0,13,12, 0, 0, 0,13,13, 8, 9, 9,13,14,
  110510. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,13, 0,
  110511. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8,
  110516. 9, 9,14,13, 0, 0, 0,13,13, 0, 0, 0,13,12, 0, 0,
  110517. 0,13,13, 0, 0, 0,13,12, 8, 9, 9,14,14, 0, 0, 0,
  110518. 13,13, 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,
  110519. 13,
  110520. };
  110521. static float _vq_quantthresh__16c2_s_p2_0[] = {
  110522. -1.5, -0.5, 0.5, 1.5,
  110523. };
  110524. static long _vq_quantmap__16c2_s_p2_0[] = {
  110525. 3, 1, 0, 2, 4,
  110526. };
  110527. static encode_aux_threshmatch _vq_auxt__16c2_s_p2_0 = {
  110528. _vq_quantthresh__16c2_s_p2_0,
  110529. _vq_quantmap__16c2_s_p2_0,
  110530. 5,
  110531. 5
  110532. };
  110533. static static_codebook _16c2_s_p2_0 = {
  110534. 4, 625,
  110535. _vq_lengthlist__16c2_s_p2_0,
  110536. 1, -533725184, 1611661312, 3, 0,
  110537. _vq_quantlist__16c2_s_p2_0,
  110538. NULL,
  110539. &_vq_auxt__16c2_s_p2_0,
  110540. NULL,
  110541. 0
  110542. };
  110543. static long _vq_quantlist__16c2_s_p3_0[] = {
  110544. 4,
  110545. 3,
  110546. 5,
  110547. 2,
  110548. 6,
  110549. 1,
  110550. 7,
  110551. 0,
  110552. 8,
  110553. };
  110554. static long _vq_lengthlist__16c2_s_p3_0[] = {
  110555. 1, 3, 3, 6, 6, 7, 7, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  110556. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  110557. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  110558. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 9, 9,10,10, 0,
  110559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110560. 0,
  110561. };
  110562. static float _vq_quantthresh__16c2_s_p3_0[] = {
  110563. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110564. };
  110565. static long _vq_quantmap__16c2_s_p3_0[] = {
  110566. 7, 5, 3, 1, 0, 2, 4, 6,
  110567. 8,
  110568. };
  110569. static encode_aux_threshmatch _vq_auxt__16c2_s_p3_0 = {
  110570. _vq_quantthresh__16c2_s_p3_0,
  110571. _vq_quantmap__16c2_s_p3_0,
  110572. 9,
  110573. 9
  110574. };
  110575. static static_codebook _16c2_s_p3_0 = {
  110576. 2, 81,
  110577. _vq_lengthlist__16c2_s_p3_0,
  110578. 1, -531628032, 1611661312, 4, 0,
  110579. _vq_quantlist__16c2_s_p3_0,
  110580. NULL,
  110581. &_vq_auxt__16c2_s_p3_0,
  110582. NULL,
  110583. 0
  110584. };
  110585. static long _vq_quantlist__16c2_s_p4_0[] = {
  110586. 8,
  110587. 7,
  110588. 9,
  110589. 6,
  110590. 10,
  110591. 5,
  110592. 11,
  110593. 4,
  110594. 12,
  110595. 3,
  110596. 13,
  110597. 2,
  110598. 14,
  110599. 1,
  110600. 15,
  110601. 0,
  110602. 16,
  110603. };
  110604. static long _vq_lengthlist__16c2_s_p4_0[] = {
  110605. 2, 3, 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,
  110606. 10, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  110607. 11,11, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  110608. 10,10,11, 0, 0, 0, 6, 6, 8, 8, 8, 8, 9, 9,10,10,
  110609. 10,11,11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,
  110610. 10,11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,
  110611. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9,
  110612. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  110613. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  110614. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  110615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110623. 0,
  110624. };
  110625. static float _vq_quantthresh__16c2_s_p4_0[] = {
  110626. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  110627. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  110628. };
  110629. static long _vq_quantmap__16c2_s_p4_0[] = {
  110630. 15, 13, 11, 9, 7, 5, 3, 1,
  110631. 0, 2, 4, 6, 8, 10, 12, 14,
  110632. 16,
  110633. };
  110634. static encode_aux_threshmatch _vq_auxt__16c2_s_p4_0 = {
  110635. _vq_quantthresh__16c2_s_p4_0,
  110636. _vq_quantmap__16c2_s_p4_0,
  110637. 17,
  110638. 17
  110639. };
  110640. static static_codebook _16c2_s_p4_0 = {
  110641. 2, 289,
  110642. _vq_lengthlist__16c2_s_p4_0,
  110643. 1, -529530880, 1611661312, 5, 0,
  110644. _vq_quantlist__16c2_s_p4_0,
  110645. NULL,
  110646. &_vq_auxt__16c2_s_p4_0,
  110647. NULL,
  110648. 0
  110649. };
  110650. static long _vq_quantlist__16c2_s_p5_0[] = {
  110651. 1,
  110652. 0,
  110653. 2,
  110654. };
  110655. static long _vq_lengthlist__16c2_s_p5_0[] = {
  110656. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6,10,10,10,10,
  110657. 10,10, 4, 7, 6,10,10,10,10,10,10, 5, 9, 9, 9,12,
  110658. 11,10,11,12, 7,10,10,12,12,12,12,12,12, 7,10,10,
  110659. 11,12,12,12,12,13, 6,10,10,10,12,12,10,12,12, 7,
  110660. 10,10,11,13,12,12,12,12, 7,10,10,11,12,12,12,12,
  110661. 12,
  110662. };
  110663. static float _vq_quantthresh__16c2_s_p5_0[] = {
  110664. -5.5, 5.5,
  110665. };
  110666. static long _vq_quantmap__16c2_s_p5_0[] = {
  110667. 1, 0, 2,
  110668. };
  110669. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_0 = {
  110670. _vq_quantthresh__16c2_s_p5_0,
  110671. _vq_quantmap__16c2_s_p5_0,
  110672. 3,
  110673. 3
  110674. };
  110675. static static_codebook _16c2_s_p5_0 = {
  110676. 4, 81,
  110677. _vq_lengthlist__16c2_s_p5_0,
  110678. 1, -529137664, 1618345984, 2, 0,
  110679. _vq_quantlist__16c2_s_p5_0,
  110680. NULL,
  110681. &_vq_auxt__16c2_s_p5_0,
  110682. NULL,
  110683. 0
  110684. };
  110685. static long _vq_quantlist__16c2_s_p5_1[] = {
  110686. 5,
  110687. 4,
  110688. 6,
  110689. 3,
  110690. 7,
  110691. 2,
  110692. 8,
  110693. 1,
  110694. 9,
  110695. 0,
  110696. 10,
  110697. };
  110698. static long _vq_lengthlist__16c2_s_p5_1[] = {
  110699. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11, 6, 6,
  110700. 7, 7, 8, 8, 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8,
  110701. 8,11,11,11, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  110702. 6, 8, 8, 8, 8, 9, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  110703. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 9,11,11,11,
  110704. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,11,11, 8, 8, 8,
  110705. 8, 8, 8,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  110706. 11,11,11, 7, 7, 8, 8, 8, 8,
  110707. };
  110708. static float _vq_quantthresh__16c2_s_p5_1[] = {
  110709. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110710. 3.5, 4.5,
  110711. };
  110712. static long _vq_quantmap__16c2_s_p5_1[] = {
  110713. 9, 7, 5, 3, 1, 0, 2, 4,
  110714. 6, 8, 10,
  110715. };
  110716. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_1 = {
  110717. _vq_quantthresh__16c2_s_p5_1,
  110718. _vq_quantmap__16c2_s_p5_1,
  110719. 11,
  110720. 11
  110721. };
  110722. static static_codebook _16c2_s_p5_1 = {
  110723. 2, 121,
  110724. _vq_lengthlist__16c2_s_p5_1,
  110725. 1, -531365888, 1611661312, 4, 0,
  110726. _vq_quantlist__16c2_s_p5_1,
  110727. NULL,
  110728. &_vq_auxt__16c2_s_p5_1,
  110729. NULL,
  110730. 0
  110731. };
  110732. static long _vq_quantlist__16c2_s_p6_0[] = {
  110733. 6,
  110734. 5,
  110735. 7,
  110736. 4,
  110737. 8,
  110738. 3,
  110739. 9,
  110740. 2,
  110741. 10,
  110742. 1,
  110743. 11,
  110744. 0,
  110745. 12,
  110746. };
  110747. static long _vq_lengthlist__16c2_s_p6_0[] = {
  110748. 1, 4, 4, 7, 6, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  110749. 7, 7, 9, 9, 9, 9,11,11,12,12, 6, 5, 5, 7, 7, 9,
  110750. 9,10,10,11,11,12,12, 0, 6, 6, 7, 7, 9, 9,10,10,
  110751. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,12,12,
  110752. 12, 0,11,11, 8, 8,10,10,11,11,12,12,13,13, 0,11,
  110753. 12, 8, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  110754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110758. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110759. };
  110760. static float _vq_quantthresh__16c2_s_p6_0[] = {
  110761. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  110762. 12.5, 17.5, 22.5, 27.5,
  110763. };
  110764. static long _vq_quantmap__16c2_s_p6_0[] = {
  110765. 11, 9, 7, 5, 3, 1, 0, 2,
  110766. 4, 6, 8, 10, 12,
  110767. };
  110768. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_0 = {
  110769. _vq_quantthresh__16c2_s_p6_0,
  110770. _vq_quantmap__16c2_s_p6_0,
  110771. 13,
  110772. 13
  110773. };
  110774. static static_codebook _16c2_s_p6_0 = {
  110775. 2, 169,
  110776. _vq_lengthlist__16c2_s_p6_0,
  110777. 1, -526516224, 1616117760, 4, 0,
  110778. _vq_quantlist__16c2_s_p6_0,
  110779. NULL,
  110780. &_vq_auxt__16c2_s_p6_0,
  110781. NULL,
  110782. 0
  110783. };
  110784. static long _vq_quantlist__16c2_s_p6_1[] = {
  110785. 2,
  110786. 1,
  110787. 3,
  110788. 0,
  110789. 4,
  110790. };
  110791. static long _vq_lengthlist__16c2_s_p6_1[] = {
  110792. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  110793. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  110794. };
  110795. static float _vq_quantthresh__16c2_s_p6_1[] = {
  110796. -1.5, -0.5, 0.5, 1.5,
  110797. };
  110798. static long _vq_quantmap__16c2_s_p6_1[] = {
  110799. 3, 1, 0, 2, 4,
  110800. };
  110801. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_1 = {
  110802. _vq_quantthresh__16c2_s_p6_1,
  110803. _vq_quantmap__16c2_s_p6_1,
  110804. 5,
  110805. 5
  110806. };
  110807. static static_codebook _16c2_s_p6_1 = {
  110808. 2, 25,
  110809. _vq_lengthlist__16c2_s_p6_1,
  110810. 1, -533725184, 1611661312, 3, 0,
  110811. _vq_quantlist__16c2_s_p6_1,
  110812. NULL,
  110813. &_vq_auxt__16c2_s_p6_1,
  110814. NULL,
  110815. 0
  110816. };
  110817. static long _vq_quantlist__16c2_s_p7_0[] = {
  110818. 6,
  110819. 5,
  110820. 7,
  110821. 4,
  110822. 8,
  110823. 3,
  110824. 9,
  110825. 2,
  110826. 10,
  110827. 1,
  110828. 11,
  110829. 0,
  110830. 12,
  110831. };
  110832. static long _vq_lengthlist__16c2_s_p7_0[] = {
  110833. 1, 4, 4, 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  110834. 8, 8, 9, 9,10,10,11,11,12,12, 6, 5, 5, 8, 8, 9,
  110835. 9,10,10,11,11,12,13,18, 6, 6, 7, 7, 9, 9,10,10,
  110836. 12,12,13,13,18, 6, 6, 7, 7, 9, 9,10,10,12,12,13,
  110837. 13,18,11,10, 8, 8,10,10,11,11,12,12,13,13,18,11,
  110838. 11, 8, 8,10,10,11,11,12,13,13,13,18,18,18,10,11,
  110839. 11,11,12,12,13,13,14,14,18,18,18,11,11,11,11,12,
  110840. 12,13,13,14,14,18,18,18,14,14,12,12,12,12,14,14,
  110841. 15,14,18,18,18,15,15,11,12,12,12,13,13,15,15,18,
  110842. 18,18,18,18,13,13,13,13,13,14,17,16,18,18,18,18,
  110843. 18,13,14,13,13,14,13,15,14,
  110844. };
  110845. static float _vq_quantthresh__16c2_s_p7_0[] = {
  110846. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  110847. 27.5, 38.5, 49.5, 60.5,
  110848. };
  110849. static long _vq_quantmap__16c2_s_p7_0[] = {
  110850. 11, 9, 7, 5, 3, 1, 0, 2,
  110851. 4, 6, 8, 10, 12,
  110852. };
  110853. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_0 = {
  110854. _vq_quantthresh__16c2_s_p7_0,
  110855. _vq_quantmap__16c2_s_p7_0,
  110856. 13,
  110857. 13
  110858. };
  110859. static static_codebook _16c2_s_p7_0 = {
  110860. 2, 169,
  110861. _vq_lengthlist__16c2_s_p7_0,
  110862. 1, -523206656, 1618345984, 4, 0,
  110863. _vq_quantlist__16c2_s_p7_0,
  110864. NULL,
  110865. &_vq_auxt__16c2_s_p7_0,
  110866. NULL,
  110867. 0
  110868. };
  110869. static long _vq_quantlist__16c2_s_p7_1[] = {
  110870. 5,
  110871. 4,
  110872. 6,
  110873. 3,
  110874. 7,
  110875. 2,
  110876. 8,
  110877. 1,
  110878. 9,
  110879. 0,
  110880. 10,
  110881. };
  110882. static long _vq_lengthlist__16c2_s_p7_1[] = {
  110883. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 9, 9, 6, 6,
  110884. 7, 7, 8, 8, 8, 8, 9, 9, 9, 6, 6, 7, 7, 8, 8, 8,
  110885. 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7,
  110886. 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  110887. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  110888. 7, 7, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 9, 7, 7, 7,
  110889. 7, 8, 8, 9, 9, 9, 9, 9, 8, 8, 7, 7, 8, 8, 9, 9,
  110890. 9, 9, 9, 7, 7, 7, 7, 8, 8,
  110891. };
  110892. static float _vq_quantthresh__16c2_s_p7_1[] = {
  110893. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110894. 3.5, 4.5,
  110895. };
  110896. static long _vq_quantmap__16c2_s_p7_1[] = {
  110897. 9, 7, 5, 3, 1, 0, 2, 4,
  110898. 6, 8, 10,
  110899. };
  110900. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_1 = {
  110901. _vq_quantthresh__16c2_s_p7_1,
  110902. _vq_quantmap__16c2_s_p7_1,
  110903. 11,
  110904. 11
  110905. };
  110906. static static_codebook _16c2_s_p7_1 = {
  110907. 2, 121,
  110908. _vq_lengthlist__16c2_s_p7_1,
  110909. 1, -531365888, 1611661312, 4, 0,
  110910. _vq_quantlist__16c2_s_p7_1,
  110911. NULL,
  110912. &_vq_auxt__16c2_s_p7_1,
  110913. NULL,
  110914. 0
  110915. };
  110916. static long _vq_quantlist__16c2_s_p8_0[] = {
  110917. 7,
  110918. 6,
  110919. 8,
  110920. 5,
  110921. 9,
  110922. 4,
  110923. 10,
  110924. 3,
  110925. 11,
  110926. 2,
  110927. 12,
  110928. 1,
  110929. 13,
  110930. 0,
  110931. 14,
  110932. };
  110933. static long _vq_lengthlist__16c2_s_p8_0[] = {
  110934. 1, 4, 4, 7, 6, 7, 7, 6, 6, 8, 8, 9, 9,10,10, 6,
  110935. 6, 6, 8, 8, 9, 8, 8, 8, 9, 9,11,10,11,11, 7, 6,
  110936. 6, 8, 8, 9, 8, 7, 7, 9, 9,10,10,12,11,14, 8, 8,
  110937. 8, 9, 9, 9, 9, 9,10, 9,10,10,11,13,14, 8, 8, 8,
  110938. 8, 9, 9, 8, 8, 9, 9,10,10,11,12,14,13,11, 9, 9,
  110939. 9, 9, 9, 9, 9,10,11,10,13,12,14,11,13, 8, 9, 9,
  110940. 9, 9, 9,10,10,11,10,13,12,14,14,14, 8, 9, 9, 9,
  110941. 11,11,11,11,11,12,13,13,14,14,14, 9, 8, 9, 9,10,
  110942. 10,12,10,11,12,12,14,14,14,14,11,12,10,10,12,12,
  110943. 12,12,13,14,12,12,14,14,14,12,12, 9,10,11,11,12,
  110944. 14,12,14,14,14,14,14,14,14,14,11,11,12,11,12,14,
  110945. 14,14,14,14,14,14,14,14,14,12,11,11,11,11,14,14,
  110946. 14,14,14,14,14,14,14,14,14,14,13,12,14,14,14,14,
  110947. 14,14,14,14,14,14,14,14,14,12,12,12,13,14,14,13,
  110948. 13,
  110949. };
  110950. static float _vq_quantthresh__16c2_s_p8_0[] = {
  110951. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  110952. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  110953. };
  110954. static long _vq_quantmap__16c2_s_p8_0[] = {
  110955. 13, 11, 9, 7, 5, 3, 1, 0,
  110956. 2, 4, 6, 8, 10, 12, 14,
  110957. };
  110958. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_0 = {
  110959. _vq_quantthresh__16c2_s_p8_0,
  110960. _vq_quantmap__16c2_s_p8_0,
  110961. 15,
  110962. 15
  110963. };
  110964. static static_codebook _16c2_s_p8_0 = {
  110965. 2, 225,
  110966. _vq_lengthlist__16c2_s_p8_0,
  110967. 1, -520986624, 1620377600, 4, 0,
  110968. _vq_quantlist__16c2_s_p8_0,
  110969. NULL,
  110970. &_vq_auxt__16c2_s_p8_0,
  110971. NULL,
  110972. 0
  110973. };
  110974. static long _vq_quantlist__16c2_s_p8_1[] = {
  110975. 10,
  110976. 9,
  110977. 11,
  110978. 8,
  110979. 12,
  110980. 7,
  110981. 13,
  110982. 6,
  110983. 14,
  110984. 5,
  110985. 15,
  110986. 4,
  110987. 16,
  110988. 3,
  110989. 17,
  110990. 2,
  110991. 18,
  110992. 1,
  110993. 19,
  110994. 0,
  110995. 20,
  110996. };
  110997. static long _vq_lengthlist__16c2_s_p8_1[] = {
  110998. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  110999. 8, 8, 8, 8, 8,11,12,11, 7, 7, 8, 8, 8, 8, 9, 9,
  111000. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,11,11,10, 7, 7, 8,
  111001. 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  111002. 11,11, 8, 7, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 9,10,
  111003. 10, 9,10,10,11,11,12, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  111004. 9, 9, 9,10, 9,10,10,10,10,11,11,11, 8, 8, 9, 9,
  111005. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  111006. 11, 8, 8, 9, 8, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,
  111007. 10, 9,10,11,11,11, 9, 9, 9, 9,10, 9, 9, 9,10,10,
  111008. 9,10, 9,10,10,10,10,10,11,12,11,11,11, 9, 9, 9,
  111009. 9, 9,10,10, 9,10,10,10,10,10,10,10,10,12,11,13,
  111010. 13,11, 9, 9, 9, 9,10,10, 9,10,10,10,10,11,10,10,
  111011. 10,10,11,12,11,12,11, 9, 9, 9,10,10, 9,10,10,10,
  111012. 10,10,10,10,10,10,10,11,11,11,12,11, 9,10,10,10,
  111013. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,12,12,
  111014. 11,11,11,10, 9,10,10,10,10,10,10,10,10,11,10,10,
  111015. 10,11,11,11,11,11,11,11,10,10,10,11,10,10,10,10,
  111016. 10,10,10,10,10,10,11,11,11,11,12,12,11,10,10,10,
  111017. 10,10,10,10,10,11,10,10,10,11,10,12,11,11,12,11,
  111018. 11,11,10,10,10,10,10,11,10,10,10,10,10,11,10,10,
  111019. 11,11,11,12,11,12,11,11,12,10,10,10,10,10,10,10,
  111020. 11,10,10,11,10,12,11,11,11,12,11,11,11,11,10,10,
  111021. 10,10,10,10,10,11,11,11,10,11,12,11,11,11,12,11,
  111022. 12,11,12,10,11,10,10,10,10,11,10,10,10,10,10,10,
  111023. 12,11,11,11,11,11,12,12,10,10,10,10,10,11,10,10,
  111024. 11,10,11,11,11,11,11,11,11,11,11,11,11,11,12,11,
  111025. 10,11,10,10,10,10,10,10,10,
  111026. };
  111027. static float _vq_quantthresh__16c2_s_p8_1[] = {
  111028. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  111029. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  111030. 6.5, 7.5, 8.5, 9.5,
  111031. };
  111032. static long _vq_quantmap__16c2_s_p8_1[] = {
  111033. 19, 17, 15, 13, 11, 9, 7, 5,
  111034. 3, 1, 0, 2, 4, 6, 8, 10,
  111035. 12, 14, 16, 18, 20,
  111036. };
  111037. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_1 = {
  111038. _vq_quantthresh__16c2_s_p8_1,
  111039. _vq_quantmap__16c2_s_p8_1,
  111040. 21,
  111041. 21
  111042. };
  111043. static static_codebook _16c2_s_p8_1 = {
  111044. 2, 441,
  111045. _vq_lengthlist__16c2_s_p8_1,
  111046. 1, -529268736, 1611661312, 5, 0,
  111047. _vq_quantlist__16c2_s_p8_1,
  111048. NULL,
  111049. &_vq_auxt__16c2_s_p8_1,
  111050. NULL,
  111051. 0
  111052. };
  111053. static long _vq_quantlist__16c2_s_p9_0[] = {
  111054. 6,
  111055. 5,
  111056. 7,
  111057. 4,
  111058. 8,
  111059. 3,
  111060. 9,
  111061. 2,
  111062. 10,
  111063. 1,
  111064. 11,
  111065. 0,
  111066. 12,
  111067. };
  111068. static long _vq_lengthlist__16c2_s_p9_0[] = {
  111069. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111070. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111071. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111072. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111073. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111074. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111075. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111076. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111077. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111078. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111079. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111080. };
  111081. static float _vq_quantthresh__16c2_s_p9_0[] = {
  111082. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5,
  111083. 2327.5, 3258.5, 4189.5, 5120.5,
  111084. };
  111085. static long _vq_quantmap__16c2_s_p9_0[] = {
  111086. 11, 9, 7, 5, 3, 1, 0, 2,
  111087. 4, 6, 8, 10, 12,
  111088. };
  111089. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_0 = {
  111090. _vq_quantthresh__16c2_s_p9_0,
  111091. _vq_quantmap__16c2_s_p9_0,
  111092. 13,
  111093. 13
  111094. };
  111095. static static_codebook _16c2_s_p9_0 = {
  111096. 2, 169,
  111097. _vq_lengthlist__16c2_s_p9_0,
  111098. 1, -510275072, 1631393792, 4, 0,
  111099. _vq_quantlist__16c2_s_p9_0,
  111100. NULL,
  111101. &_vq_auxt__16c2_s_p9_0,
  111102. NULL,
  111103. 0
  111104. };
  111105. static long _vq_quantlist__16c2_s_p9_1[] = {
  111106. 8,
  111107. 7,
  111108. 9,
  111109. 6,
  111110. 10,
  111111. 5,
  111112. 11,
  111113. 4,
  111114. 12,
  111115. 3,
  111116. 13,
  111117. 2,
  111118. 14,
  111119. 1,
  111120. 15,
  111121. 0,
  111122. 16,
  111123. };
  111124. static long _vq_lengthlist__16c2_s_p9_1[] = {
  111125. 1, 5, 5, 9, 8, 7, 7, 7, 6,10,11,11,11,11,11,11,
  111126. 11, 8, 7, 6, 8, 8,10, 9,10,10,10, 9,11,10,10,10,
  111127. 10,10, 8, 6, 6, 8, 8, 9, 8, 9, 8, 9,10,10,10,10,
  111128. 10,10,10,10, 8,10, 9, 9, 9, 9,10,10,10,10,10,10,
  111129. 10,10,10,10,10, 8, 9, 9, 9,10,10, 9,10,10,10,10,
  111130. 10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,10,10,10,
  111131. 10,10,10,10,10,10,10,10, 9, 8, 8, 9, 9,10,10,10,
  111132. 10,10,10,10,10,10,10,10,10,10, 9,10, 9, 9,10,10,
  111133. 10,10,10,10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,
  111134. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  111135. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111136. 8,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111137. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111138. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111139. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111140. 10,10,10,10, 9,10, 9,10,10,10,10,10,10,10,10,10,
  111141. 10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,
  111142. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111143. 10,
  111144. };
  111145. static float _vq_quantthresh__16c2_s_p9_1[] = {
  111146. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -24.5,
  111147. 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5, 367.5,
  111148. };
  111149. static long _vq_quantmap__16c2_s_p9_1[] = {
  111150. 15, 13, 11, 9, 7, 5, 3, 1,
  111151. 0, 2, 4, 6, 8, 10, 12, 14,
  111152. 16,
  111153. };
  111154. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_1 = {
  111155. _vq_quantthresh__16c2_s_p9_1,
  111156. _vq_quantmap__16c2_s_p9_1,
  111157. 17,
  111158. 17
  111159. };
  111160. static static_codebook _16c2_s_p9_1 = {
  111161. 2, 289,
  111162. _vq_lengthlist__16c2_s_p9_1,
  111163. 1, -518488064, 1622704128, 5, 0,
  111164. _vq_quantlist__16c2_s_p9_1,
  111165. NULL,
  111166. &_vq_auxt__16c2_s_p9_1,
  111167. NULL,
  111168. 0
  111169. };
  111170. static long _vq_quantlist__16c2_s_p9_2[] = {
  111171. 13,
  111172. 12,
  111173. 14,
  111174. 11,
  111175. 15,
  111176. 10,
  111177. 16,
  111178. 9,
  111179. 17,
  111180. 8,
  111181. 18,
  111182. 7,
  111183. 19,
  111184. 6,
  111185. 20,
  111186. 5,
  111187. 21,
  111188. 4,
  111189. 22,
  111190. 3,
  111191. 23,
  111192. 2,
  111193. 24,
  111194. 1,
  111195. 25,
  111196. 0,
  111197. 26,
  111198. };
  111199. static long _vq_lengthlist__16c2_s_p9_2[] = {
  111200. 1, 4, 4, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  111201. 7, 7, 7, 7, 8, 7, 8, 7, 7, 4, 4,
  111202. };
  111203. static float _vq_quantthresh__16c2_s_p9_2[] = {
  111204. -12.5, -11.5, -10.5, -9.5, -8.5, -7.5, -6.5, -5.5,
  111205. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111206. 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5,
  111207. 11.5, 12.5,
  111208. };
  111209. static long _vq_quantmap__16c2_s_p9_2[] = {
  111210. 25, 23, 21, 19, 17, 15, 13, 11,
  111211. 9, 7, 5, 3, 1, 0, 2, 4,
  111212. 6, 8, 10, 12, 14, 16, 18, 20,
  111213. 22, 24, 26,
  111214. };
  111215. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_2 = {
  111216. _vq_quantthresh__16c2_s_p9_2,
  111217. _vq_quantmap__16c2_s_p9_2,
  111218. 27,
  111219. 27
  111220. };
  111221. static static_codebook _16c2_s_p9_2 = {
  111222. 1, 27,
  111223. _vq_lengthlist__16c2_s_p9_2,
  111224. 1, -528875520, 1611661312, 5, 0,
  111225. _vq_quantlist__16c2_s_p9_2,
  111226. NULL,
  111227. &_vq_auxt__16c2_s_p9_2,
  111228. NULL,
  111229. 0
  111230. };
  111231. static long _huff_lengthlist__16c2_s_short[] = {
  111232. 7,10,11,11,11,14,15,15,17,14, 8, 6, 7, 7, 8, 9,
  111233. 11,11,14,17, 9, 6, 6, 6, 7, 7,10,11,15,16, 9, 6,
  111234. 6, 4, 4, 5, 8, 9,12,16,10, 6, 6, 4, 4, 4, 6, 9,
  111235. 13,16,10, 7, 6, 5, 4, 3, 5, 7,13,16,11, 9, 8, 7,
  111236. 6, 5, 5, 6,12,15,10,10,10, 9, 7, 6, 6, 7,11,15,
  111237. 13,13,13,13,11,10,10, 9,12,16,16,16,16,14,16,15,
  111238. 15,12,14,14,
  111239. };
  111240. static static_codebook _huff_book__16c2_s_short = {
  111241. 2, 100,
  111242. _huff_lengthlist__16c2_s_short,
  111243. 0, 0, 0, 0, 0,
  111244. NULL,
  111245. NULL,
  111246. NULL,
  111247. NULL,
  111248. 0
  111249. };
  111250. static long _vq_quantlist__8c0_s_p1_0[] = {
  111251. 1,
  111252. 0,
  111253. 2,
  111254. };
  111255. static long _vq_lengthlist__8c0_s_p1_0[] = {
  111256. 1, 5, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  111257. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  111262. 0, 0, 0, 7, 8, 9, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  111267. 0, 0, 0, 0, 7, 9, 8, 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, 5, 8, 8, 0, 0, 0, 0,
  111302. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7,10, 9, 0, 0, 0,
  111307. 0, 0, 0, 8, 9,11, 0, 0, 0, 0, 0, 0, 9,11,11, 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, 7, 9,10, 0, 0,
  111312. 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  111348. 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,11, 0,
  111353. 0, 0, 0, 0, 0, 9,10,11, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  111358. 0, 0, 0, 0, 0, 0, 8,11, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111666. 0,
  111667. };
  111668. static float _vq_quantthresh__8c0_s_p1_0[] = {
  111669. -0.5, 0.5,
  111670. };
  111671. static long _vq_quantmap__8c0_s_p1_0[] = {
  111672. 1, 0, 2,
  111673. };
  111674. static encode_aux_threshmatch _vq_auxt__8c0_s_p1_0 = {
  111675. _vq_quantthresh__8c0_s_p1_0,
  111676. _vq_quantmap__8c0_s_p1_0,
  111677. 3,
  111678. 3
  111679. };
  111680. static static_codebook _8c0_s_p1_0 = {
  111681. 8, 6561,
  111682. _vq_lengthlist__8c0_s_p1_0,
  111683. 1, -535822336, 1611661312, 2, 0,
  111684. _vq_quantlist__8c0_s_p1_0,
  111685. NULL,
  111686. &_vq_auxt__8c0_s_p1_0,
  111687. NULL,
  111688. 0
  111689. };
  111690. static long _vq_quantlist__8c0_s_p2_0[] = {
  111691. 2,
  111692. 1,
  111693. 3,
  111694. 0,
  111695. 4,
  111696. };
  111697. static long _vq_lengthlist__8c0_s_p2_0[] = {
  111698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111737. 0,
  111738. };
  111739. static float _vq_quantthresh__8c0_s_p2_0[] = {
  111740. -1.5, -0.5, 0.5, 1.5,
  111741. };
  111742. static long _vq_quantmap__8c0_s_p2_0[] = {
  111743. 3, 1, 0, 2, 4,
  111744. };
  111745. static encode_aux_threshmatch _vq_auxt__8c0_s_p2_0 = {
  111746. _vq_quantthresh__8c0_s_p2_0,
  111747. _vq_quantmap__8c0_s_p2_0,
  111748. 5,
  111749. 5
  111750. };
  111751. static static_codebook _8c0_s_p2_0 = {
  111752. 4, 625,
  111753. _vq_lengthlist__8c0_s_p2_0,
  111754. 1, -533725184, 1611661312, 3, 0,
  111755. _vq_quantlist__8c0_s_p2_0,
  111756. NULL,
  111757. &_vq_auxt__8c0_s_p2_0,
  111758. NULL,
  111759. 0
  111760. };
  111761. static long _vq_quantlist__8c0_s_p3_0[] = {
  111762. 2,
  111763. 1,
  111764. 3,
  111765. 0,
  111766. 4,
  111767. };
  111768. static long _vq_lengthlist__8c0_s_p3_0[] = {
  111769. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 7, 7, 0, 0,
  111771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111772. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 8, 8,
  111774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111775. 0, 0, 0, 0, 6, 7, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  111776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111808. 0,
  111809. };
  111810. static float _vq_quantthresh__8c0_s_p3_0[] = {
  111811. -1.5, -0.5, 0.5, 1.5,
  111812. };
  111813. static long _vq_quantmap__8c0_s_p3_0[] = {
  111814. 3, 1, 0, 2, 4,
  111815. };
  111816. static encode_aux_threshmatch _vq_auxt__8c0_s_p3_0 = {
  111817. _vq_quantthresh__8c0_s_p3_0,
  111818. _vq_quantmap__8c0_s_p3_0,
  111819. 5,
  111820. 5
  111821. };
  111822. static static_codebook _8c0_s_p3_0 = {
  111823. 4, 625,
  111824. _vq_lengthlist__8c0_s_p3_0,
  111825. 1, -533725184, 1611661312, 3, 0,
  111826. _vq_quantlist__8c0_s_p3_0,
  111827. NULL,
  111828. &_vq_auxt__8c0_s_p3_0,
  111829. NULL,
  111830. 0
  111831. };
  111832. static long _vq_quantlist__8c0_s_p4_0[] = {
  111833. 4,
  111834. 3,
  111835. 5,
  111836. 2,
  111837. 6,
  111838. 1,
  111839. 7,
  111840. 0,
  111841. 8,
  111842. };
  111843. static long _vq_lengthlist__8c0_s_p4_0[] = {
  111844. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  111845. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  111846. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  111847. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  111848. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111849. 0,
  111850. };
  111851. static float _vq_quantthresh__8c0_s_p4_0[] = {
  111852. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  111853. };
  111854. static long _vq_quantmap__8c0_s_p4_0[] = {
  111855. 7, 5, 3, 1, 0, 2, 4, 6,
  111856. 8,
  111857. };
  111858. static encode_aux_threshmatch _vq_auxt__8c0_s_p4_0 = {
  111859. _vq_quantthresh__8c0_s_p4_0,
  111860. _vq_quantmap__8c0_s_p4_0,
  111861. 9,
  111862. 9
  111863. };
  111864. static static_codebook _8c0_s_p4_0 = {
  111865. 2, 81,
  111866. _vq_lengthlist__8c0_s_p4_0,
  111867. 1, -531628032, 1611661312, 4, 0,
  111868. _vq_quantlist__8c0_s_p4_0,
  111869. NULL,
  111870. &_vq_auxt__8c0_s_p4_0,
  111871. NULL,
  111872. 0
  111873. };
  111874. static long _vq_quantlist__8c0_s_p5_0[] = {
  111875. 4,
  111876. 3,
  111877. 5,
  111878. 2,
  111879. 6,
  111880. 1,
  111881. 7,
  111882. 0,
  111883. 8,
  111884. };
  111885. static long _vq_lengthlist__8c0_s_p5_0[] = {
  111886. 1, 3, 3, 5, 5, 7, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  111887. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 9, 0, 0, 0, 8, 8,
  111888. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8, 9, 9, 0, 0, 0,
  111889. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  111890. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  111891. 10,
  111892. };
  111893. static float _vq_quantthresh__8c0_s_p5_0[] = {
  111894. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  111895. };
  111896. static long _vq_quantmap__8c0_s_p5_0[] = {
  111897. 7, 5, 3, 1, 0, 2, 4, 6,
  111898. 8,
  111899. };
  111900. static encode_aux_threshmatch _vq_auxt__8c0_s_p5_0 = {
  111901. _vq_quantthresh__8c0_s_p5_0,
  111902. _vq_quantmap__8c0_s_p5_0,
  111903. 9,
  111904. 9
  111905. };
  111906. static static_codebook _8c0_s_p5_0 = {
  111907. 2, 81,
  111908. _vq_lengthlist__8c0_s_p5_0,
  111909. 1, -531628032, 1611661312, 4, 0,
  111910. _vq_quantlist__8c0_s_p5_0,
  111911. NULL,
  111912. &_vq_auxt__8c0_s_p5_0,
  111913. NULL,
  111914. 0
  111915. };
  111916. static long _vq_quantlist__8c0_s_p6_0[] = {
  111917. 8,
  111918. 7,
  111919. 9,
  111920. 6,
  111921. 10,
  111922. 5,
  111923. 11,
  111924. 4,
  111925. 12,
  111926. 3,
  111927. 13,
  111928. 2,
  111929. 14,
  111930. 1,
  111931. 15,
  111932. 0,
  111933. 16,
  111934. };
  111935. static long _vq_lengthlist__8c0_s_p6_0[] = {
  111936. 1, 3, 3, 6, 6, 8, 8, 9, 9, 8, 8,10, 9,10,10,11,
  111937. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  111938. 11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  111939. 11,12,11, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,10,10,
  111940. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,11,
  111941. 10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,10,
  111942. 11,11,11,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,
  111943. 10,11,11,12,12,13,13, 0, 0, 0,10,10,10,10,11,11,
  111944. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10, 9,10,
  111945. 11,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  111946. 10, 9,10,11,12,12,13,13,14,13, 0, 0, 0, 0, 0, 9,
  111947. 9, 9,10,10,10,11,11,13,12,13,13, 0, 0, 0, 0, 0,
  111948. 10,10,10,10,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  111949. 0, 0, 0,10,10,11,11,12,12,13,13,13,14, 0, 0, 0,
  111950. 0, 0, 0, 0,11,11,11,11,12,12,13,14,14,14, 0, 0,
  111951. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,14,13, 0,
  111952. 0, 0, 0, 0, 0, 0,11,11,12,12,13,13,14,14,14,14,
  111953. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  111954. 14,
  111955. };
  111956. static float _vq_quantthresh__8c0_s_p6_0[] = {
  111957. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  111958. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  111959. };
  111960. static long _vq_quantmap__8c0_s_p6_0[] = {
  111961. 15, 13, 11, 9, 7, 5, 3, 1,
  111962. 0, 2, 4, 6, 8, 10, 12, 14,
  111963. 16,
  111964. };
  111965. static encode_aux_threshmatch _vq_auxt__8c0_s_p6_0 = {
  111966. _vq_quantthresh__8c0_s_p6_0,
  111967. _vq_quantmap__8c0_s_p6_0,
  111968. 17,
  111969. 17
  111970. };
  111971. static static_codebook _8c0_s_p6_0 = {
  111972. 2, 289,
  111973. _vq_lengthlist__8c0_s_p6_0,
  111974. 1, -529530880, 1611661312, 5, 0,
  111975. _vq_quantlist__8c0_s_p6_0,
  111976. NULL,
  111977. &_vq_auxt__8c0_s_p6_0,
  111978. NULL,
  111979. 0
  111980. };
  111981. static long _vq_quantlist__8c0_s_p7_0[] = {
  111982. 1,
  111983. 0,
  111984. 2,
  111985. };
  111986. static long _vq_lengthlist__8c0_s_p7_0[] = {
  111987. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,11, 9,10,12,
  111988. 9,10, 4, 7, 7,10,10,10,11, 9, 9, 6,11,10,11,11,
  111989. 12,11,11,11, 6,10,10,11,11,12,11,10,10, 6, 9,10,
  111990. 11,11,11,11,10,10, 7,10,11,12,11,11,12,11,12, 6,
  111991. 9, 9,10, 9, 9,11,10,10, 6, 9, 9,10,10,10,11,10,
  111992. 10,
  111993. };
  111994. static float _vq_quantthresh__8c0_s_p7_0[] = {
  111995. -5.5, 5.5,
  111996. };
  111997. static long _vq_quantmap__8c0_s_p7_0[] = {
  111998. 1, 0, 2,
  111999. };
  112000. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_0 = {
  112001. _vq_quantthresh__8c0_s_p7_0,
  112002. _vq_quantmap__8c0_s_p7_0,
  112003. 3,
  112004. 3
  112005. };
  112006. static static_codebook _8c0_s_p7_0 = {
  112007. 4, 81,
  112008. _vq_lengthlist__8c0_s_p7_0,
  112009. 1, -529137664, 1618345984, 2, 0,
  112010. _vq_quantlist__8c0_s_p7_0,
  112011. NULL,
  112012. &_vq_auxt__8c0_s_p7_0,
  112013. NULL,
  112014. 0
  112015. };
  112016. static long _vq_quantlist__8c0_s_p7_1[] = {
  112017. 5,
  112018. 4,
  112019. 6,
  112020. 3,
  112021. 7,
  112022. 2,
  112023. 8,
  112024. 1,
  112025. 9,
  112026. 0,
  112027. 10,
  112028. };
  112029. static long _vq_lengthlist__8c0_s_p7_1[] = {
  112030. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10, 7, 7,
  112031. 8, 8, 9, 9, 9, 9,10,10, 9, 7, 7, 8, 8, 9, 9, 9,
  112032. 9,10,10,10, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10, 8,
  112033. 8, 9, 9, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9,10,
  112034. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,11,10,11,
  112035. 9, 9, 9, 9,10,10,10,10,11,11,11,10,10, 9, 9,10,
  112036. 10,10, 9,11,10,10,10,10,10,10, 9, 9,10,10,11,11,
  112037. 10,10,10, 9, 9, 9,10,10,10,
  112038. };
  112039. static float _vq_quantthresh__8c0_s_p7_1[] = {
  112040. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  112041. 3.5, 4.5,
  112042. };
  112043. static long _vq_quantmap__8c0_s_p7_1[] = {
  112044. 9, 7, 5, 3, 1, 0, 2, 4,
  112045. 6, 8, 10,
  112046. };
  112047. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_1 = {
  112048. _vq_quantthresh__8c0_s_p7_1,
  112049. _vq_quantmap__8c0_s_p7_1,
  112050. 11,
  112051. 11
  112052. };
  112053. static static_codebook _8c0_s_p7_1 = {
  112054. 2, 121,
  112055. _vq_lengthlist__8c0_s_p7_1,
  112056. 1, -531365888, 1611661312, 4, 0,
  112057. _vq_quantlist__8c0_s_p7_1,
  112058. NULL,
  112059. &_vq_auxt__8c0_s_p7_1,
  112060. NULL,
  112061. 0
  112062. };
  112063. static long _vq_quantlist__8c0_s_p8_0[] = {
  112064. 6,
  112065. 5,
  112066. 7,
  112067. 4,
  112068. 8,
  112069. 3,
  112070. 9,
  112071. 2,
  112072. 10,
  112073. 1,
  112074. 11,
  112075. 0,
  112076. 12,
  112077. };
  112078. static long _vq_lengthlist__8c0_s_p8_0[] = {
  112079. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 6, 6,
  112080. 7, 7, 8, 8, 7, 7, 8, 9,10,10, 7, 6, 6, 7, 7, 8,
  112081. 7, 7, 7, 9, 9,10,12, 0, 8, 8, 8, 8, 8, 9, 8, 8,
  112082. 9, 9,10,10, 0, 8, 8, 8, 8, 8, 9, 8, 9, 9, 9,11,
  112083. 10, 0, 0,13, 9, 8, 9, 9, 9, 9,10,10,11,11, 0,13,
  112084. 0, 9, 9, 9, 9, 9, 9,11,10,11,11, 0, 0, 0, 8, 9,
  112085. 10, 9,10,10,13,11,12,12, 0, 0, 0, 8, 9, 9, 9,10,
  112086. 10,13,12,12,13, 0, 0, 0,12, 0,10,10,12,11,10,11,
  112087. 12,12, 0, 0, 0,13,13,10,10,10,11,12, 0,13, 0, 0,
  112088. 0, 0, 0, 0,13,11, 0,12,12,12,13,12, 0, 0, 0, 0,
  112089. 0, 0,13,13,11,13,13,11,12,
  112090. };
  112091. static float _vq_quantthresh__8c0_s_p8_0[] = {
  112092. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  112093. 12.5, 17.5, 22.5, 27.5,
  112094. };
  112095. static long _vq_quantmap__8c0_s_p8_0[] = {
  112096. 11, 9, 7, 5, 3, 1, 0, 2,
  112097. 4, 6, 8, 10, 12,
  112098. };
  112099. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_0 = {
  112100. _vq_quantthresh__8c0_s_p8_0,
  112101. _vq_quantmap__8c0_s_p8_0,
  112102. 13,
  112103. 13
  112104. };
  112105. static static_codebook _8c0_s_p8_0 = {
  112106. 2, 169,
  112107. _vq_lengthlist__8c0_s_p8_0,
  112108. 1, -526516224, 1616117760, 4, 0,
  112109. _vq_quantlist__8c0_s_p8_0,
  112110. NULL,
  112111. &_vq_auxt__8c0_s_p8_0,
  112112. NULL,
  112113. 0
  112114. };
  112115. static long _vq_quantlist__8c0_s_p8_1[] = {
  112116. 2,
  112117. 1,
  112118. 3,
  112119. 0,
  112120. 4,
  112121. };
  112122. static long _vq_lengthlist__8c0_s_p8_1[] = {
  112123. 1, 3, 4, 5, 5, 7, 6, 6, 6, 5, 7, 7, 7, 6, 6, 7,
  112124. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  112125. };
  112126. static float _vq_quantthresh__8c0_s_p8_1[] = {
  112127. -1.5, -0.5, 0.5, 1.5,
  112128. };
  112129. static long _vq_quantmap__8c0_s_p8_1[] = {
  112130. 3, 1, 0, 2, 4,
  112131. };
  112132. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_1 = {
  112133. _vq_quantthresh__8c0_s_p8_1,
  112134. _vq_quantmap__8c0_s_p8_1,
  112135. 5,
  112136. 5
  112137. };
  112138. static static_codebook _8c0_s_p8_1 = {
  112139. 2, 25,
  112140. _vq_lengthlist__8c0_s_p8_1,
  112141. 1, -533725184, 1611661312, 3, 0,
  112142. _vq_quantlist__8c0_s_p8_1,
  112143. NULL,
  112144. &_vq_auxt__8c0_s_p8_1,
  112145. NULL,
  112146. 0
  112147. };
  112148. static long _vq_quantlist__8c0_s_p9_0[] = {
  112149. 1,
  112150. 0,
  112151. 2,
  112152. };
  112153. static long _vq_lengthlist__8c0_s_p9_0[] = {
  112154. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112155. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112156. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112157. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112158. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112159. 7,
  112160. };
  112161. static float _vq_quantthresh__8c0_s_p9_0[] = {
  112162. -157.5, 157.5,
  112163. };
  112164. static long _vq_quantmap__8c0_s_p9_0[] = {
  112165. 1, 0, 2,
  112166. };
  112167. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_0 = {
  112168. _vq_quantthresh__8c0_s_p9_0,
  112169. _vq_quantmap__8c0_s_p9_0,
  112170. 3,
  112171. 3
  112172. };
  112173. static static_codebook _8c0_s_p9_0 = {
  112174. 4, 81,
  112175. _vq_lengthlist__8c0_s_p9_0,
  112176. 1, -518803456, 1628680192, 2, 0,
  112177. _vq_quantlist__8c0_s_p9_0,
  112178. NULL,
  112179. &_vq_auxt__8c0_s_p9_0,
  112180. NULL,
  112181. 0
  112182. };
  112183. static long _vq_quantlist__8c0_s_p9_1[] = {
  112184. 7,
  112185. 6,
  112186. 8,
  112187. 5,
  112188. 9,
  112189. 4,
  112190. 10,
  112191. 3,
  112192. 11,
  112193. 2,
  112194. 12,
  112195. 1,
  112196. 13,
  112197. 0,
  112198. 14,
  112199. };
  112200. static long _vq_lengthlist__8c0_s_p9_1[] = {
  112201. 1, 4, 4, 5, 5,10, 8,11,11,11,11,11,11,11,11, 6,
  112202. 6, 6, 7, 6,11,10,11,11,11,11,11,11,11,11, 7, 5,
  112203. 6, 6, 6, 8, 7,11,11,11,11,11,11,11,11,11, 7, 8,
  112204. 8, 8, 9, 9,11,11,11,11,11,11,11,11,11, 9, 8, 7,
  112205. 8, 9,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112206. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112207. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112208. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112209. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112210. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112211. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112212. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112213. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112214. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112215. 11,
  112216. };
  112217. static float _vq_quantthresh__8c0_s_p9_1[] = {
  112218. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  112219. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  112220. };
  112221. static long _vq_quantmap__8c0_s_p9_1[] = {
  112222. 13, 11, 9, 7, 5, 3, 1, 0,
  112223. 2, 4, 6, 8, 10, 12, 14,
  112224. };
  112225. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_1 = {
  112226. _vq_quantthresh__8c0_s_p9_1,
  112227. _vq_quantmap__8c0_s_p9_1,
  112228. 15,
  112229. 15
  112230. };
  112231. static static_codebook _8c0_s_p9_1 = {
  112232. 2, 225,
  112233. _vq_lengthlist__8c0_s_p9_1,
  112234. 1, -520986624, 1620377600, 4, 0,
  112235. _vq_quantlist__8c0_s_p9_1,
  112236. NULL,
  112237. &_vq_auxt__8c0_s_p9_1,
  112238. NULL,
  112239. 0
  112240. };
  112241. static long _vq_quantlist__8c0_s_p9_2[] = {
  112242. 10,
  112243. 9,
  112244. 11,
  112245. 8,
  112246. 12,
  112247. 7,
  112248. 13,
  112249. 6,
  112250. 14,
  112251. 5,
  112252. 15,
  112253. 4,
  112254. 16,
  112255. 3,
  112256. 17,
  112257. 2,
  112258. 18,
  112259. 1,
  112260. 19,
  112261. 0,
  112262. 20,
  112263. };
  112264. static long _vq_lengthlist__8c0_s_p9_2[] = {
  112265. 1, 5, 5, 7, 7, 8, 7, 8, 8,10,10, 9, 9,10,10,10,
  112266. 11,11,10,12,11,12,12,12, 9, 8, 8, 8, 8, 8, 9,10,
  112267. 10,10,10,11,11,11,10,11,11,12,12,11,12, 8, 8, 7,
  112268. 7, 8, 9,10,10,10, 9,10,10, 9,10,10,11,11,11,11,
  112269. 11,11, 9, 9, 9, 9, 8, 9,10,10,11,10,10,11,11,12,
  112270. 10,10,12,12,11,11,10, 9, 9,10, 8, 9,10,10,10, 9,
  112271. 10,10,11,11,10,11,10,10,10,12,12,12, 9,10, 9,10,
  112272. 9, 9,10,10,11,11,11,11,10,10,10,11,12,11,12,11,
  112273. 12,10,11,10,11, 9,10, 9,10, 9,10,10, 9,10,10,11,
  112274. 10,11,11,11,11,12,11, 9,10,10,10,10,11,11,11,11,
  112275. 11,10,11,11,11,11,10,12,10,12,12,11,12,10,10,11,
  112276. 10, 9,11,10,11, 9,10,11,10,10,10,11,11,11,11,12,
  112277. 12,10, 9, 9,11,10, 9,12,11,10,12,12,11,11,11,11,
  112278. 10,11,11,12,11,10,12, 9,11,10,11,10,10,11,10,11,
  112279. 9,10,10,10,11,12,11,11,12,11,10,10,11,11, 9,10,
  112280. 10,12,10,11,10,10,10, 9,10,10,10,10, 9,10,10,11,
  112281. 11,11,11,12,11,10,10,10,10,11,11,10,11,11, 9,11,
  112282. 10,12,10,12,11,10,11,10,10,10,11,10,10,11,11,10,
  112283. 11,10,10,10,10,11,11,12,10,10,10,11,10,11,12,11,
  112284. 10,11,10,10,11,11,10,12,10, 9,10,10,11,11,11,10,
  112285. 12,10,10,11,11,11,10,10,11,10,10,10,11,10,11,10,
  112286. 12,11,11,10,10,10,12,10,10,11, 9,10,11,11,11,10,
  112287. 10,11,10,10, 9,11,11,12,12,11,12,11,11,11,11,11,
  112288. 11, 9,10,11,10,12,10,10,10,10,11,10,10,11,10,10,
  112289. 12,10,10,10,10,10, 9,12,10,10,10,10,12, 9,11,10,
  112290. 10,11,10,12,12,10,12,12,12,10,10,10,10, 9,10,11,
  112291. 10,10,12,10,10,12,11,10,11,10,10,12,11,10,12,10,
  112292. 10,11, 9,11,10, 9,10, 9,10,
  112293. };
  112294. static float _vq_quantthresh__8c0_s_p9_2[] = {
  112295. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  112296. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  112297. 6.5, 7.5, 8.5, 9.5,
  112298. };
  112299. static long _vq_quantmap__8c0_s_p9_2[] = {
  112300. 19, 17, 15, 13, 11, 9, 7, 5,
  112301. 3, 1, 0, 2, 4, 6, 8, 10,
  112302. 12, 14, 16, 18, 20,
  112303. };
  112304. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_2 = {
  112305. _vq_quantthresh__8c0_s_p9_2,
  112306. _vq_quantmap__8c0_s_p9_2,
  112307. 21,
  112308. 21
  112309. };
  112310. static static_codebook _8c0_s_p9_2 = {
  112311. 2, 441,
  112312. _vq_lengthlist__8c0_s_p9_2,
  112313. 1, -529268736, 1611661312, 5, 0,
  112314. _vq_quantlist__8c0_s_p9_2,
  112315. NULL,
  112316. &_vq_auxt__8c0_s_p9_2,
  112317. NULL,
  112318. 0
  112319. };
  112320. static long _huff_lengthlist__8c0_s_single[] = {
  112321. 4, 5,18, 7,10, 6, 7, 8, 9,10, 5, 2,18, 5, 7, 5,
  112322. 6, 7, 8,11,17,17,17,17,17,17,17,17,17,17, 7, 4,
  112323. 17, 6, 9, 6, 8,10,12,15,11, 7,17, 9, 6, 6, 7, 9,
  112324. 11,15, 6, 4,17, 6, 6, 4, 5, 8,11,16, 6, 6,17, 8,
  112325. 6, 5, 6, 9,13,16, 8, 9,17,11, 9, 8, 8,11,13,17,
  112326. 9,12,17,15,14,13,12,13,14,17,12,15,17,17,17,17,
  112327. 17,16,17,17,
  112328. };
  112329. static static_codebook _huff_book__8c0_s_single = {
  112330. 2, 100,
  112331. _huff_lengthlist__8c0_s_single,
  112332. 0, 0, 0, 0, 0,
  112333. NULL,
  112334. NULL,
  112335. NULL,
  112336. NULL,
  112337. 0
  112338. };
  112339. static long _vq_quantlist__8c1_s_p1_0[] = {
  112340. 1,
  112341. 0,
  112342. 2,
  112343. };
  112344. static long _vq_lengthlist__8c1_s_p1_0[] = {
  112345. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  112346. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  112351. 0, 0, 0, 7, 8, 9, 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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  112356. 0, 0, 0, 0, 7, 9, 8, 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, 5, 8, 8, 0, 0, 0, 0,
  112391. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  112396. 0, 0, 0, 8, 8,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  112401. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  112437. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  112442. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  112447. 0, 0, 0, 0, 0, 0, 8,10, 8, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112755. 0,
  112756. };
  112757. static float _vq_quantthresh__8c1_s_p1_0[] = {
  112758. -0.5, 0.5,
  112759. };
  112760. static long _vq_quantmap__8c1_s_p1_0[] = {
  112761. 1, 0, 2,
  112762. };
  112763. static encode_aux_threshmatch _vq_auxt__8c1_s_p1_0 = {
  112764. _vq_quantthresh__8c1_s_p1_0,
  112765. _vq_quantmap__8c1_s_p1_0,
  112766. 3,
  112767. 3
  112768. };
  112769. static static_codebook _8c1_s_p1_0 = {
  112770. 8, 6561,
  112771. _vq_lengthlist__8c1_s_p1_0,
  112772. 1, -535822336, 1611661312, 2, 0,
  112773. _vq_quantlist__8c1_s_p1_0,
  112774. NULL,
  112775. &_vq_auxt__8c1_s_p1_0,
  112776. NULL,
  112777. 0
  112778. };
  112779. static long _vq_quantlist__8c1_s_p2_0[] = {
  112780. 2,
  112781. 1,
  112782. 3,
  112783. 0,
  112784. 4,
  112785. };
  112786. static long _vq_lengthlist__8c1_s_p2_0[] = {
  112787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112826. 0,
  112827. };
  112828. static float _vq_quantthresh__8c1_s_p2_0[] = {
  112829. -1.5, -0.5, 0.5, 1.5,
  112830. };
  112831. static long _vq_quantmap__8c1_s_p2_0[] = {
  112832. 3, 1, 0, 2, 4,
  112833. };
  112834. static encode_aux_threshmatch _vq_auxt__8c1_s_p2_0 = {
  112835. _vq_quantthresh__8c1_s_p2_0,
  112836. _vq_quantmap__8c1_s_p2_0,
  112837. 5,
  112838. 5
  112839. };
  112840. static static_codebook _8c1_s_p2_0 = {
  112841. 4, 625,
  112842. _vq_lengthlist__8c1_s_p2_0,
  112843. 1, -533725184, 1611661312, 3, 0,
  112844. _vq_quantlist__8c1_s_p2_0,
  112845. NULL,
  112846. &_vq_auxt__8c1_s_p2_0,
  112847. NULL,
  112848. 0
  112849. };
  112850. static long _vq_quantlist__8c1_s_p3_0[] = {
  112851. 2,
  112852. 1,
  112853. 3,
  112854. 0,
  112855. 4,
  112856. };
  112857. static long _vq_lengthlist__8c1_s_p3_0[] = {
  112858. 2, 4, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  112860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112861. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 7, 7,
  112863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112864. 0, 0, 0, 0, 6, 6, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  112865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112897. 0,
  112898. };
  112899. static float _vq_quantthresh__8c1_s_p3_0[] = {
  112900. -1.5, -0.5, 0.5, 1.5,
  112901. };
  112902. static long _vq_quantmap__8c1_s_p3_0[] = {
  112903. 3, 1, 0, 2, 4,
  112904. };
  112905. static encode_aux_threshmatch _vq_auxt__8c1_s_p3_0 = {
  112906. _vq_quantthresh__8c1_s_p3_0,
  112907. _vq_quantmap__8c1_s_p3_0,
  112908. 5,
  112909. 5
  112910. };
  112911. static static_codebook _8c1_s_p3_0 = {
  112912. 4, 625,
  112913. _vq_lengthlist__8c1_s_p3_0,
  112914. 1, -533725184, 1611661312, 3, 0,
  112915. _vq_quantlist__8c1_s_p3_0,
  112916. NULL,
  112917. &_vq_auxt__8c1_s_p3_0,
  112918. NULL,
  112919. 0
  112920. };
  112921. static long _vq_quantlist__8c1_s_p4_0[] = {
  112922. 4,
  112923. 3,
  112924. 5,
  112925. 2,
  112926. 6,
  112927. 1,
  112928. 7,
  112929. 0,
  112930. 8,
  112931. };
  112932. static long _vq_lengthlist__8c1_s_p4_0[] = {
  112933. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  112934. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  112935. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  112936. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  112937. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112938. 0,
  112939. };
  112940. static float _vq_quantthresh__8c1_s_p4_0[] = {
  112941. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112942. };
  112943. static long _vq_quantmap__8c1_s_p4_0[] = {
  112944. 7, 5, 3, 1, 0, 2, 4, 6,
  112945. 8,
  112946. };
  112947. static encode_aux_threshmatch _vq_auxt__8c1_s_p4_0 = {
  112948. _vq_quantthresh__8c1_s_p4_0,
  112949. _vq_quantmap__8c1_s_p4_0,
  112950. 9,
  112951. 9
  112952. };
  112953. static static_codebook _8c1_s_p4_0 = {
  112954. 2, 81,
  112955. _vq_lengthlist__8c1_s_p4_0,
  112956. 1, -531628032, 1611661312, 4, 0,
  112957. _vq_quantlist__8c1_s_p4_0,
  112958. NULL,
  112959. &_vq_auxt__8c1_s_p4_0,
  112960. NULL,
  112961. 0
  112962. };
  112963. static long _vq_quantlist__8c1_s_p5_0[] = {
  112964. 4,
  112965. 3,
  112966. 5,
  112967. 2,
  112968. 6,
  112969. 1,
  112970. 7,
  112971. 0,
  112972. 8,
  112973. };
  112974. static long _vq_lengthlist__8c1_s_p5_0[] = {
  112975. 1, 3, 3, 4, 5, 6, 6, 8, 8, 0, 0, 0, 8, 8, 7, 7,
  112976. 9, 9, 0, 0, 0, 8, 8, 7, 7, 9, 9, 0, 0, 0, 9,10,
  112977. 8, 8, 9, 9, 0, 0, 0,10,10, 8, 8, 9, 9, 0, 0, 0,
  112978. 11,10, 8, 8,10,10, 0, 0, 0,11,11, 8, 8,10,10, 0,
  112979. 0, 0,12,12, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  112980. 10,
  112981. };
  112982. static float _vq_quantthresh__8c1_s_p5_0[] = {
  112983. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112984. };
  112985. static long _vq_quantmap__8c1_s_p5_0[] = {
  112986. 7, 5, 3, 1, 0, 2, 4, 6,
  112987. 8,
  112988. };
  112989. static encode_aux_threshmatch _vq_auxt__8c1_s_p5_0 = {
  112990. _vq_quantthresh__8c1_s_p5_0,
  112991. _vq_quantmap__8c1_s_p5_0,
  112992. 9,
  112993. 9
  112994. };
  112995. static static_codebook _8c1_s_p5_0 = {
  112996. 2, 81,
  112997. _vq_lengthlist__8c1_s_p5_0,
  112998. 1, -531628032, 1611661312, 4, 0,
  112999. _vq_quantlist__8c1_s_p5_0,
  113000. NULL,
  113001. &_vq_auxt__8c1_s_p5_0,
  113002. NULL,
  113003. 0
  113004. };
  113005. static long _vq_quantlist__8c1_s_p6_0[] = {
  113006. 8,
  113007. 7,
  113008. 9,
  113009. 6,
  113010. 10,
  113011. 5,
  113012. 11,
  113013. 4,
  113014. 12,
  113015. 3,
  113016. 13,
  113017. 2,
  113018. 14,
  113019. 1,
  113020. 15,
  113021. 0,
  113022. 16,
  113023. };
  113024. static long _vq_lengthlist__8c1_s_p6_0[] = {
  113025. 1, 3, 3, 5, 5, 8, 8, 8, 8, 9, 9,10,10,11,11,11,
  113026. 11, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11,
  113027. 12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113028. 11,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,11,
  113029. 12,12,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,
  113030. 11,12,12,12,12, 0, 0, 0,10,10, 9, 9,10,10,10,10,
  113031. 11,11,12,12,13,13, 0, 0, 0,10,10, 9, 9,10,10,10,
  113032. 10,11,11,12,12,13,13, 0, 0, 0,11,11, 9, 9,10,10,
  113033. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  113034. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  113035. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  113036. 9,10,10,11,11,12,11,12,12,13,13, 0, 0, 0, 0, 0,
  113037. 10,10,11,11,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  113038. 0, 0, 0,11,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  113039. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  113040. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,13, 0,
  113041. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  113042. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  113043. 14,
  113044. };
  113045. static float _vq_quantthresh__8c1_s_p6_0[] = {
  113046. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  113047. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  113048. };
  113049. static long _vq_quantmap__8c1_s_p6_0[] = {
  113050. 15, 13, 11, 9, 7, 5, 3, 1,
  113051. 0, 2, 4, 6, 8, 10, 12, 14,
  113052. 16,
  113053. };
  113054. static encode_aux_threshmatch _vq_auxt__8c1_s_p6_0 = {
  113055. _vq_quantthresh__8c1_s_p6_0,
  113056. _vq_quantmap__8c1_s_p6_0,
  113057. 17,
  113058. 17
  113059. };
  113060. static static_codebook _8c1_s_p6_0 = {
  113061. 2, 289,
  113062. _vq_lengthlist__8c1_s_p6_0,
  113063. 1, -529530880, 1611661312, 5, 0,
  113064. _vq_quantlist__8c1_s_p6_0,
  113065. NULL,
  113066. &_vq_auxt__8c1_s_p6_0,
  113067. NULL,
  113068. 0
  113069. };
  113070. static long _vq_quantlist__8c1_s_p7_0[] = {
  113071. 1,
  113072. 0,
  113073. 2,
  113074. };
  113075. static long _vq_lengthlist__8c1_s_p7_0[] = {
  113076. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  113077. 9, 9, 5, 7, 7,10, 9, 9,10, 9, 9, 6,10,10,10,10,
  113078. 10,11,10,10, 6, 9, 9,10, 9,10,11,10,10, 6, 9, 9,
  113079. 10, 9, 9,11, 9,10, 7,10,10,11,11,11,11,10,10, 6,
  113080. 9, 9,10,10,10,11, 9, 9, 6, 9, 9,10,10,10,10, 9,
  113081. 9,
  113082. };
  113083. static float _vq_quantthresh__8c1_s_p7_0[] = {
  113084. -5.5, 5.5,
  113085. };
  113086. static long _vq_quantmap__8c1_s_p7_0[] = {
  113087. 1, 0, 2,
  113088. };
  113089. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_0 = {
  113090. _vq_quantthresh__8c1_s_p7_0,
  113091. _vq_quantmap__8c1_s_p7_0,
  113092. 3,
  113093. 3
  113094. };
  113095. static static_codebook _8c1_s_p7_0 = {
  113096. 4, 81,
  113097. _vq_lengthlist__8c1_s_p7_0,
  113098. 1, -529137664, 1618345984, 2, 0,
  113099. _vq_quantlist__8c1_s_p7_0,
  113100. NULL,
  113101. &_vq_auxt__8c1_s_p7_0,
  113102. NULL,
  113103. 0
  113104. };
  113105. static long _vq_quantlist__8c1_s_p7_1[] = {
  113106. 5,
  113107. 4,
  113108. 6,
  113109. 3,
  113110. 7,
  113111. 2,
  113112. 8,
  113113. 1,
  113114. 9,
  113115. 0,
  113116. 10,
  113117. };
  113118. static long _vq_lengthlist__8c1_s_p7_1[] = {
  113119. 2, 3, 3, 5, 5, 7, 7, 7, 7, 7, 7,10,10, 9, 7, 7,
  113120. 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8,
  113121. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  113122. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  113123. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  113124. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  113125. 8, 8, 8,10,10,10,10,10, 8, 8, 8, 8, 8, 8,10,10,
  113126. 10,10,10, 8, 8, 8, 8, 8, 8,
  113127. };
  113128. static float _vq_quantthresh__8c1_s_p7_1[] = {
  113129. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  113130. 3.5, 4.5,
  113131. };
  113132. static long _vq_quantmap__8c1_s_p7_1[] = {
  113133. 9, 7, 5, 3, 1, 0, 2, 4,
  113134. 6, 8, 10,
  113135. };
  113136. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_1 = {
  113137. _vq_quantthresh__8c1_s_p7_1,
  113138. _vq_quantmap__8c1_s_p7_1,
  113139. 11,
  113140. 11
  113141. };
  113142. static static_codebook _8c1_s_p7_1 = {
  113143. 2, 121,
  113144. _vq_lengthlist__8c1_s_p7_1,
  113145. 1, -531365888, 1611661312, 4, 0,
  113146. _vq_quantlist__8c1_s_p7_1,
  113147. NULL,
  113148. &_vq_auxt__8c1_s_p7_1,
  113149. NULL,
  113150. 0
  113151. };
  113152. static long _vq_quantlist__8c1_s_p8_0[] = {
  113153. 6,
  113154. 5,
  113155. 7,
  113156. 4,
  113157. 8,
  113158. 3,
  113159. 9,
  113160. 2,
  113161. 10,
  113162. 1,
  113163. 11,
  113164. 0,
  113165. 12,
  113166. };
  113167. static long _vq_lengthlist__8c1_s_p8_0[] = {
  113168. 1, 4, 4, 6, 6, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5,
  113169. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  113170. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  113171. 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113172. 11, 0,12,12, 9, 9, 9, 9,10, 9,10,11,11,11, 0,13,
  113173. 12, 9, 8, 9, 9,10,10,11,11,12,11, 0, 0, 0, 9, 9,
  113174. 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10, 9, 9,10,
  113175. 10,11,11,12,12, 0, 0, 0,13,13,10,10,11,11,12,11,
  113176. 13,12, 0, 0, 0,14,14,10,10,11,10,11,11,12,12, 0,
  113177. 0, 0, 0, 0,12,12,11,11,12,12,13,13, 0, 0, 0, 0,
  113178. 0,12,12,11,10,12,11,13,12,
  113179. };
  113180. static float _vq_quantthresh__8c1_s_p8_0[] = {
  113181. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  113182. 12.5, 17.5, 22.5, 27.5,
  113183. };
  113184. static long _vq_quantmap__8c1_s_p8_0[] = {
  113185. 11, 9, 7, 5, 3, 1, 0, 2,
  113186. 4, 6, 8, 10, 12,
  113187. };
  113188. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_0 = {
  113189. _vq_quantthresh__8c1_s_p8_0,
  113190. _vq_quantmap__8c1_s_p8_0,
  113191. 13,
  113192. 13
  113193. };
  113194. static static_codebook _8c1_s_p8_0 = {
  113195. 2, 169,
  113196. _vq_lengthlist__8c1_s_p8_0,
  113197. 1, -526516224, 1616117760, 4, 0,
  113198. _vq_quantlist__8c1_s_p8_0,
  113199. NULL,
  113200. &_vq_auxt__8c1_s_p8_0,
  113201. NULL,
  113202. 0
  113203. };
  113204. static long _vq_quantlist__8c1_s_p8_1[] = {
  113205. 2,
  113206. 1,
  113207. 3,
  113208. 0,
  113209. 4,
  113210. };
  113211. static long _vq_lengthlist__8c1_s_p8_1[] = {
  113212. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  113213. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  113214. };
  113215. static float _vq_quantthresh__8c1_s_p8_1[] = {
  113216. -1.5, -0.5, 0.5, 1.5,
  113217. };
  113218. static long _vq_quantmap__8c1_s_p8_1[] = {
  113219. 3, 1, 0, 2, 4,
  113220. };
  113221. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_1 = {
  113222. _vq_quantthresh__8c1_s_p8_1,
  113223. _vq_quantmap__8c1_s_p8_1,
  113224. 5,
  113225. 5
  113226. };
  113227. static static_codebook _8c1_s_p8_1 = {
  113228. 2, 25,
  113229. _vq_lengthlist__8c1_s_p8_1,
  113230. 1, -533725184, 1611661312, 3, 0,
  113231. _vq_quantlist__8c1_s_p8_1,
  113232. NULL,
  113233. &_vq_auxt__8c1_s_p8_1,
  113234. NULL,
  113235. 0
  113236. };
  113237. static long _vq_quantlist__8c1_s_p9_0[] = {
  113238. 6,
  113239. 5,
  113240. 7,
  113241. 4,
  113242. 8,
  113243. 3,
  113244. 9,
  113245. 2,
  113246. 10,
  113247. 1,
  113248. 11,
  113249. 0,
  113250. 12,
  113251. };
  113252. static long _vq_lengthlist__8c1_s_p9_0[] = {
  113253. 1, 3, 3,10,10,10,10,10,10,10,10,10,10, 5, 6, 6,
  113254. 10,10,10,10,10,10,10,10,10,10, 6, 7, 8,10,10,10,
  113255. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113256. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113257. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113258. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113259. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113260. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113261. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113262. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113263. 10,10,10,10,10, 9, 9, 9, 9,
  113264. };
  113265. static float _vq_quantthresh__8c1_s_p9_0[] = {
  113266. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  113267. 787.5, 1102.5, 1417.5, 1732.5,
  113268. };
  113269. static long _vq_quantmap__8c1_s_p9_0[] = {
  113270. 11, 9, 7, 5, 3, 1, 0, 2,
  113271. 4, 6, 8, 10, 12,
  113272. };
  113273. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_0 = {
  113274. _vq_quantthresh__8c1_s_p9_0,
  113275. _vq_quantmap__8c1_s_p9_0,
  113276. 13,
  113277. 13
  113278. };
  113279. static static_codebook _8c1_s_p9_0 = {
  113280. 2, 169,
  113281. _vq_lengthlist__8c1_s_p9_0,
  113282. 1, -513964032, 1628680192, 4, 0,
  113283. _vq_quantlist__8c1_s_p9_0,
  113284. NULL,
  113285. &_vq_auxt__8c1_s_p9_0,
  113286. NULL,
  113287. 0
  113288. };
  113289. static long _vq_quantlist__8c1_s_p9_1[] = {
  113290. 7,
  113291. 6,
  113292. 8,
  113293. 5,
  113294. 9,
  113295. 4,
  113296. 10,
  113297. 3,
  113298. 11,
  113299. 2,
  113300. 12,
  113301. 1,
  113302. 13,
  113303. 0,
  113304. 14,
  113305. };
  113306. static long _vq_lengthlist__8c1_s_p9_1[] = {
  113307. 1, 4, 4, 5, 5, 7, 7, 9, 9,11,11,12,12,13,13, 6,
  113308. 5, 5, 6, 6, 9, 9,10,10,12,12,12,13,15,14, 6, 5,
  113309. 5, 7, 7, 9, 9,10,10,12,12,12,13,14,13,17, 7, 7,
  113310. 8, 8,10,10,11,11,12,13,13,13,13,13,17, 7, 7, 8,
  113311. 8,10,10,11,11,13,13,13,13,14,14,17,11,11, 9, 9,
  113312. 11,11,12,12,12,13,13,14,15,13,17,12,12, 9, 9,11,
  113313. 11,12,12,13,13,13,13,14,16,17,17,17,11,12,12,12,
  113314. 13,13,13,14,15,14,15,15,17,17,17,12,12,11,11,13,
  113315. 13,14,14,15,14,15,15,17,17,17,15,15,13,13,14,14,
  113316. 15,14,15,15,16,15,17,17,17,15,15,13,13,13,14,14,
  113317. 15,15,15,15,16,17,17,17,17,16,14,15,14,14,15,14,
  113318. 14,15,15,15,17,17,17,17,17,14,14,16,14,15,15,15,
  113319. 15,15,15,17,17,17,17,17,17,16,16,15,17,15,15,14,
  113320. 17,15,17,16,17,17,17,17,16,15,14,15,15,15,15,15,
  113321. 15,
  113322. };
  113323. static float _vq_quantthresh__8c1_s_p9_1[] = {
  113324. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  113325. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  113326. };
  113327. static long _vq_quantmap__8c1_s_p9_1[] = {
  113328. 13, 11, 9, 7, 5, 3, 1, 0,
  113329. 2, 4, 6, 8, 10, 12, 14,
  113330. };
  113331. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_1 = {
  113332. _vq_quantthresh__8c1_s_p9_1,
  113333. _vq_quantmap__8c1_s_p9_1,
  113334. 15,
  113335. 15
  113336. };
  113337. static static_codebook _8c1_s_p9_1 = {
  113338. 2, 225,
  113339. _vq_lengthlist__8c1_s_p9_1,
  113340. 1, -520986624, 1620377600, 4, 0,
  113341. _vq_quantlist__8c1_s_p9_1,
  113342. NULL,
  113343. &_vq_auxt__8c1_s_p9_1,
  113344. NULL,
  113345. 0
  113346. };
  113347. static long _vq_quantlist__8c1_s_p9_2[] = {
  113348. 10,
  113349. 9,
  113350. 11,
  113351. 8,
  113352. 12,
  113353. 7,
  113354. 13,
  113355. 6,
  113356. 14,
  113357. 5,
  113358. 15,
  113359. 4,
  113360. 16,
  113361. 3,
  113362. 17,
  113363. 2,
  113364. 18,
  113365. 1,
  113366. 19,
  113367. 0,
  113368. 20,
  113369. };
  113370. static long _vq_lengthlist__8c1_s_p9_2[] = {
  113371. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  113372. 9, 9, 9, 9, 9,11,11,12, 7, 7, 7, 7, 8, 8, 9, 9,
  113373. 9, 9,10,10,10,10,10,10,10,10,11,11,11, 7, 7, 7,
  113374. 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,11,
  113375. 11,12, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,
  113376. 10,10,10,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  113377. 9,10,10,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  113378. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,11,11,
  113379. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  113380. 10,10,10,11,12,11, 9, 9, 8, 9, 9, 9, 9, 9,10,10,
  113381. 10,10,10,10,10,10,10,10,11,11,11,11,11, 8, 8, 9,
  113382. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,11,12,11,
  113383. 12,11, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  113384. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  113385. 10,10,10,10,10,10,10,12,11,12,11,11, 9, 9, 9,10,
  113386. 10,10,10,10,10,10,10,10,10,10,10,10,12,11,11,11,
  113387. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113388. 11,11,11,12,11,11,12,11,10,10,10,10,10,10,10,10,
  113389. 10,10,10,10,11,10,11,11,11,11,11,11,11,10,10,10,
  113390. 10,10,10,10,10,10,10,10,10,10,10,11,11,12,11,12,
  113391. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113392. 11,11,12,11,12,11,11,11,11,10,10,10,10,10,10,10,
  113393. 10,10,10,10,10,11,11,12,11,11,12,11,11,12,10,10,
  113394. 11,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  113395. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,12,
  113396. 12,11,12,11,11,12,12,12,11,11,10,10,10,10,10,10,
  113397. 10,10,10,11,12,12,11,12,12,11,12,11,11,11,11,10,
  113398. 10,10,10,10,10,10,10,10,10,
  113399. };
  113400. static float _vq_quantthresh__8c1_s_p9_2[] = {
  113401. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  113402. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  113403. 6.5, 7.5, 8.5, 9.5,
  113404. };
  113405. static long _vq_quantmap__8c1_s_p9_2[] = {
  113406. 19, 17, 15, 13, 11, 9, 7, 5,
  113407. 3, 1, 0, 2, 4, 6, 8, 10,
  113408. 12, 14, 16, 18, 20,
  113409. };
  113410. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_2 = {
  113411. _vq_quantthresh__8c1_s_p9_2,
  113412. _vq_quantmap__8c1_s_p9_2,
  113413. 21,
  113414. 21
  113415. };
  113416. static static_codebook _8c1_s_p9_2 = {
  113417. 2, 441,
  113418. _vq_lengthlist__8c1_s_p9_2,
  113419. 1, -529268736, 1611661312, 5, 0,
  113420. _vq_quantlist__8c1_s_p9_2,
  113421. NULL,
  113422. &_vq_auxt__8c1_s_p9_2,
  113423. NULL,
  113424. 0
  113425. };
  113426. static long _huff_lengthlist__8c1_s_single[] = {
  113427. 4, 6,18, 8,11, 8, 8, 9, 9,10, 4, 4,18, 5, 9, 5,
  113428. 6, 7, 8,10,18,18,18,18,17,17,17,17,17,17, 7, 5,
  113429. 17, 6,11, 6, 7, 8, 9,12,12, 9,17,12, 8, 8, 9,10,
  113430. 10,13, 7, 5,17, 6, 8, 4, 5, 6, 8,10, 6, 5,17, 6,
  113431. 8, 5, 4, 5, 7, 9, 7, 7,17, 8, 9, 6, 5, 5, 6, 8,
  113432. 8, 8,17, 9,11, 8, 6, 6, 6, 7, 9,10,17,12,12,10,
  113433. 9, 7, 7, 8,
  113434. };
  113435. static static_codebook _huff_book__8c1_s_single = {
  113436. 2, 100,
  113437. _huff_lengthlist__8c1_s_single,
  113438. 0, 0, 0, 0, 0,
  113439. NULL,
  113440. NULL,
  113441. NULL,
  113442. NULL,
  113443. 0
  113444. };
  113445. static long _huff_lengthlist__44c2_s_long[] = {
  113446. 6, 6,12,10,10,10, 9,10,12,12, 6, 1,10, 5, 6, 6,
  113447. 7, 9,11,14,12, 9, 8,11, 7, 8, 9,11,13,15,10, 5,
  113448. 12, 7, 8, 7, 9,12,14,15,10, 6, 7, 8, 5, 6, 7, 9,
  113449. 12,14, 9, 6, 8, 7, 6, 6, 7, 9,12,12, 9, 7, 9, 9,
  113450. 7, 6, 6, 7,10,10,10, 9,10,11, 8, 7, 6, 6, 8,10,
  113451. 12,11,13,13,11,10, 8, 8, 8,10,11,13,15,15,14,13,
  113452. 10, 8, 8, 9,
  113453. };
  113454. static static_codebook _huff_book__44c2_s_long = {
  113455. 2, 100,
  113456. _huff_lengthlist__44c2_s_long,
  113457. 0, 0, 0, 0, 0,
  113458. NULL,
  113459. NULL,
  113460. NULL,
  113461. NULL,
  113462. 0
  113463. };
  113464. static long _vq_quantlist__44c2_s_p1_0[] = {
  113465. 1,
  113466. 0,
  113467. 2,
  113468. };
  113469. static long _vq_lengthlist__44c2_s_p1_0[] = {
  113470. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  113471. 0, 0, 5, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  113476. 0, 0, 0, 6, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  113481. 0, 0, 0, 0, 7, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0,
  113516. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  113521. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  113526. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  113562. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  113567. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  113572. 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113686. 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113694. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113880. 0,
  113881. };
  113882. static float _vq_quantthresh__44c2_s_p1_0[] = {
  113883. -0.5, 0.5,
  113884. };
  113885. static long _vq_quantmap__44c2_s_p1_0[] = {
  113886. 1, 0, 2,
  113887. };
  113888. static encode_aux_threshmatch _vq_auxt__44c2_s_p1_0 = {
  113889. _vq_quantthresh__44c2_s_p1_0,
  113890. _vq_quantmap__44c2_s_p1_0,
  113891. 3,
  113892. 3
  113893. };
  113894. static static_codebook _44c2_s_p1_0 = {
  113895. 8, 6561,
  113896. _vq_lengthlist__44c2_s_p1_0,
  113897. 1, -535822336, 1611661312, 2, 0,
  113898. _vq_quantlist__44c2_s_p1_0,
  113899. NULL,
  113900. &_vq_auxt__44c2_s_p1_0,
  113901. NULL,
  113902. 0
  113903. };
  113904. static long _vq_quantlist__44c2_s_p2_0[] = {
  113905. 2,
  113906. 1,
  113907. 3,
  113908. 0,
  113909. 4,
  113910. };
  113911. static long _vq_lengthlist__44c2_s_p2_0[] = {
  113912. 1, 4, 4, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0,
  113913. 8, 8, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  113914. 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  113915. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0,
  113916. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113921. 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,11,11, 0, 0,
  113922. 0,11,11, 0, 0, 0,12,11, 0, 0, 0, 0, 0, 0, 0, 7,
  113923. 8, 8, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0, 0,11,
  113924. 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113929. 0, 0, 0, 6, 8, 8, 0, 0, 0,11,11, 0, 0, 0,11,11,
  113930. 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0,
  113931. 0, 0,10,11, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0,
  113932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113937. 8, 9, 9, 0, 0, 0,11,12, 0, 0, 0,11,12, 0, 0, 0,
  113938. 12,11, 0, 0, 0, 0, 0, 0, 0, 8,10, 9, 0, 0, 0,12,
  113939. 11, 0, 0, 0,12,11, 0, 0, 0,11,12, 0, 0, 0, 0, 0,
  113940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113951. 0,
  113952. };
  113953. static float _vq_quantthresh__44c2_s_p2_0[] = {
  113954. -1.5, -0.5, 0.5, 1.5,
  113955. };
  113956. static long _vq_quantmap__44c2_s_p2_0[] = {
  113957. 3, 1, 0, 2, 4,
  113958. };
  113959. static encode_aux_threshmatch _vq_auxt__44c2_s_p2_0 = {
  113960. _vq_quantthresh__44c2_s_p2_0,
  113961. _vq_quantmap__44c2_s_p2_0,
  113962. 5,
  113963. 5
  113964. };
  113965. static static_codebook _44c2_s_p2_0 = {
  113966. 4, 625,
  113967. _vq_lengthlist__44c2_s_p2_0,
  113968. 1, -533725184, 1611661312, 3, 0,
  113969. _vq_quantlist__44c2_s_p2_0,
  113970. NULL,
  113971. &_vq_auxt__44c2_s_p2_0,
  113972. NULL,
  113973. 0
  113974. };
  113975. static long _vq_quantlist__44c2_s_p3_0[] = {
  113976. 2,
  113977. 1,
  113978. 3,
  113979. 0,
  113980. 4,
  113981. };
  113982. static long _vq_lengthlist__44c2_s_p3_0[] = {
  113983. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  113985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113986. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  113988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113989. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  113990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114022. 0,
  114023. };
  114024. static float _vq_quantthresh__44c2_s_p3_0[] = {
  114025. -1.5, -0.5, 0.5, 1.5,
  114026. };
  114027. static long _vq_quantmap__44c2_s_p3_0[] = {
  114028. 3, 1, 0, 2, 4,
  114029. };
  114030. static encode_aux_threshmatch _vq_auxt__44c2_s_p3_0 = {
  114031. _vq_quantthresh__44c2_s_p3_0,
  114032. _vq_quantmap__44c2_s_p3_0,
  114033. 5,
  114034. 5
  114035. };
  114036. static static_codebook _44c2_s_p3_0 = {
  114037. 4, 625,
  114038. _vq_lengthlist__44c2_s_p3_0,
  114039. 1, -533725184, 1611661312, 3, 0,
  114040. _vq_quantlist__44c2_s_p3_0,
  114041. NULL,
  114042. &_vq_auxt__44c2_s_p3_0,
  114043. NULL,
  114044. 0
  114045. };
  114046. static long _vq_quantlist__44c2_s_p4_0[] = {
  114047. 4,
  114048. 3,
  114049. 5,
  114050. 2,
  114051. 6,
  114052. 1,
  114053. 7,
  114054. 0,
  114055. 8,
  114056. };
  114057. static long _vq_lengthlist__44c2_s_p4_0[] = {
  114058. 1, 3, 3, 6, 6, 0, 0, 0, 0, 0, 6, 6, 6, 6, 0, 0,
  114059. 0, 0, 0, 6, 6, 6, 6, 0, 0, 0, 0, 0, 7, 7, 6, 6,
  114060. 0, 0, 0, 0, 0, 0, 0, 6, 7, 0, 0, 0, 0, 0, 0, 0,
  114061. 7, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  114062. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114063. 0,
  114064. };
  114065. static float _vq_quantthresh__44c2_s_p4_0[] = {
  114066. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114067. };
  114068. static long _vq_quantmap__44c2_s_p4_0[] = {
  114069. 7, 5, 3, 1, 0, 2, 4, 6,
  114070. 8,
  114071. };
  114072. static encode_aux_threshmatch _vq_auxt__44c2_s_p4_0 = {
  114073. _vq_quantthresh__44c2_s_p4_0,
  114074. _vq_quantmap__44c2_s_p4_0,
  114075. 9,
  114076. 9
  114077. };
  114078. static static_codebook _44c2_s_p4_0 = {
  114079. 2, 81,
  114080. _vq_lengthlist__44c2_s_p4_0,
  114081. 1, -531628032, 1611661312, 4, 0,
  114082. _vq_quantlist__44c2_s_p4_0,
  114083. NULL,
  114084. &_vq_auxt__44c2_s_p4_0,
  114085. NULL,
  114086. 0
  114087. };
  114088. static long _vq_quantlist__44c2_s_p5_0[] = {
  114089. 4,
  114090. 3,
  114091. 5,
  114092. 2,
  114093. 6,
  114094. 1,
  114095. 7,
  114096. 0,
  114097. 8,
  114098. };
  114099. static long _vq_lengthlist__44c2_s_p5_0[] = {
  114100. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 7, 7, 7, 7, 7, 7,
  114101. 9, 9, 0, 7, 7, 7, 7, 7, 7, 9, 9, 0, 8, 8, 7, 7,
  114102. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  114103. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  114104. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  114105. 11,
  114106. };
  114107. static float _vq_quantthresh__44c2_s_p5_0[] = {
  114108. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114109. };
  114110. static long _vq_quantmap__44c2_s_p5_0[] = {
  114111. 7, 5, 3, 1, 0, 2, 4, 6,
  114112. 8,
  114113. };
  114114. static encode_aux_threshmatch _vq_auxt__44c2_s_p5_0 = {
  114115. _vq_quantthresh__44c2_s_p5_0,
  114116. _vq_quantmap__44c2_s_p5_0,
  114117. 9,
  114118. 9
  114119. };
  114120. static static_codebook _44c2_s_p5_0 = {
  114121. 2, 81,
  114122. _vq_lengthlist__44c2_s_p5_0,
  114123. 1, -531628032, 1611661312, 4, 0,
  114124. _vq_quantlist__44c2_s_p5_0,
  114125. NULL,
  114126. &_vq_auxt__44c2_s_p5_0,
  114127. NULL,
  114128. 0
  114129. };
  114130. static long _vq_quantlist__44c2_s_p6_0[] = {
  114131. 8,
  114132. 7,
  114133. 9,
  114134. 6,
  114135. 10,
  114136. 5,
  114137. 11,
  114138. 4,
  114139. 12,
  114140. 3,
  114141. 13,
  114142. 2,
  114143. 14,
  114144. 1,
  114145. 15,
  114146. 0,
  114147. 16,
  114148. };
  114149. static long _vq_lengthlist__44c2_s_p6_0[] = {
  114150. 1, 4, 3, 6, 6, 8, 8, 9, 9, 9, 9, 9, 9,10,10,11,
  114151. 11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  114152. 12,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  114153. 11,11,12, 0, 8, 8, 7, 7, 9, 9,10,10, 9, 9,10,10,
  114154. 11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10, 9,10,
  114155. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  114156. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  114157. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  114158. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  114159. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  114160. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  114161. 9,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  114162. 10,10,10,10,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  114163. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  114164. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  114165. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  114166. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  114167. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  114168. 14,
  114169. };
  114170. static float _vq_quantthresh__44c2_s_p6_0[] = {
  114171. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114172. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114173. };
  114174. static long _vq_quantmap__44c2_s_p6_0[] = {
  114175. 15, 13, 11, 9, 7, 5, 3, 1,
  114176. 0, 2, 4, 6, 8, 10, 12, 14,
  114177. 16,
  114178. };
  114179. static encode_aux_threshmatch _vq_auxt__44c2_s_p6_0 = {
  114180. _vq_quantthresh__44c2_s_p6_0,
  114181. _vq_quantmap__44c2_s_p6_0,
  114182. 17,
  114183. 17
  114184. };
  114185. static static_codebook _44c2_s_p6_0 = {
  114186. 2, 289,
  114187. _vq_lengthlist__44c2_s_p6_0,
  114188. 1, -529530880, 1611661312, 5, 0,
  114189. _vq_quantlist__44c2_s_p6_0,
  114190. NULL,
  114191. &_vq_auxt__44c2_s_p6_0,
  114192. NULL,
  114193. 0
  114194. };
  114195. static long _vq_quantlist__44c2_s_p7_0[] = {
  114196. 1,
  114197. 0,
  114198. 2,
  114199. };
  114200. static long _vq_lengthlist__44c2_s_p7_0[] = {
  114201. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  114202. 9, 9, 4, 7, 7,10, 9, 9,10, 9, 9, 7,10,10,11,10,
  114203. 11,11,10,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  114204. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 6,
  114205. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,12,10,
  114206. 11,
  114207. };
  114208. static float _vq_quantthresh__44c2_s_p7_0[] = {
  114209. -5.5, 5.5,
  114210. };
  114211. static long _vq_quantmap__44c2_s_p7_0[] = {
  114212. 1, 0, 2,
  114213. };
  114214. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_0 = {
  114215. _vq_quantthresh__44c2_s_p7_0,
  114216. _vq_quantmap__44c2_s_p7_0,
  114217. 3,
  114218. 3
  114219. };
  114220. static static_codebook _44c2_s_p7_0 = {
  114221. 4, 81,
  114222. _vq_lengthlist__44c2_s_p7_0,
  114223. 1, -529137664, 1618345984, 2, 0,
  114224. _vq_quantlist__44c2_s_p7_0,
  114225. NULL,
  114226. &_vq_auxt__44c2_s_p7_0,
  114227. NULL,
  114228. 0
  114229. };
  114230. static long _vq_quantlist__44c2_s_p7_1[] = {
  114231. 5,
  114232. 4,
  114233. 6,
  114234. 3,
  114235. 7,
  114236. 2,
  114237. 8,
  114238. 1,
  114239. 9,
  114240. 0,
  114241. 10,
  114242. };
  114243. static long _vq_lengthlist__44c2_s_p7_1[] = {
  114244. 2, 3, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 7, 7, 6, 6,
  114245. 7, 7, 8, 8, 8, 8, 9, 6, 6, 6, 6, 7, 7, 8, 8, 8,
  114246. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  114247. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  114248. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  114249. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  114250. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  114251. 10,10,10, 8, 8, 8, 8, 8, 8,
  114252. };
  114253. static float _vq_quantthresh__44c2_s_p7_1[] = {
  114254. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  114255. 3.5, 4.5,
  114256. };
  114257. static long _vq_quantmap__44c2_s_p7_1[] = {
  114258. 9, 7, 5, 3, 1, 0, 2, 4,
  114259. 6, 8, 10,
  114260. };
  114261. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_1 = {
  114262. _vq_quantthresh__44c2_s_p7_1,
  114263. _vq_quantmap__44c2_s_p7_1,
  114264. 11,
  114265. 11
  114266. };
  114267. static static_codebook _44c2_s_p7_1 = {
  114268. 2, 121,
  114269. _vq_lengthlist__44c2_s_p7_1,
  114270. 1, -531365888, 1611661312, 4, 0,
  114271. _vq_quantlist__44c2_s_p7_1,
  114272. NULL,
  114273. &_vq_auxt__44c2_s_p7_1,
  114274. NULL,
  114275. 0
  114276. };
  114277. static long _vq_quantlist__44c2_s_p8_0[] = {
  114278. 6,
  114279. 5,
  114280. 7,
  114281. 4,
  114282. 8,
  114283. 3,
  114284. 9,
  114285. 2,
  114286. 10,
  114287. 1,
  114288. 11,
  114289. 0,
  114290. 12,
  114291. };
  114292. static long _vq_lengthlist__44c2_s_p8_0[] = {
  114293. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  114294. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  114295. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  114296. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  114297. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  114298. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  114299. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  114300. 11,12,12,12,12, 0, 0, 0,14,14,10,11,11,11,12,12,
  114301. 13,13, 0, 0, 0,14,14,11,10,11,11,13,12,13,13, 0,
  114302. 0, 0, 0, 0,12,12,11,12,13,12,14,14, 0, 0, 0, 0,
  114303. 0,12,12,12,12,13,12,14,14,
  114304. };
  114305. static float _vq_quantthresh__44c2_s_p8_0[] = {
  114306. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  114307. 12.5, 17.5, 22.5, 27.5,
  114308. };
  114309. static long _vq_quantmap__44c2_s_p8_0[] = {
  114310. 11, 9, 7, 5, 3, 1, 0, 2,
  114311. 4, 6, 8, 10, 12,
  114312. };
  114313. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_0 = {
  114314. _vq_quantthresh__44c2_s_p8_0,
  114315. _vq_quantmap__44c2_s_p8_0,
  114316. 13,
  114317. 13
  114318. };
  114319. static static_codebook _44c2_s_p8_0 = {
  114320. 2, 169,
  114321. _vq_lengthlist__44c2_s_p8_0,
  114322. 1, -526516224, 1616117760, 4, 0,
  114323. _vq_quantlist__44c2_s_p8_0,
  114324. NULL,
  114325. &_vq_auxt__44c2_s_p8_0,
  114326. NULL,
  114327. 0
  114328. };
  114329. static long _vq_quantlist__44c2_s_p8_1[] = {
  114330. 2,
  114331. 1,
  114332. 3,
  114333. 0,
  114334. 4,
  114335. };
  114336. static long _vq_lengthlist__44c2_s_p8_1[] = {
  114337. 2, 4, 4, 5, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  114338. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  114339. };
  114340. static float _vq_quantthresh__44c2_s_p8_1[] = {
  114341. -1.5, -0.5, 0.5, 1.5,
  114342. };
  114343. static long _vq_quantmap__44c2_s_p8_1[] = {
  114344. 3, 1, 0, 2, 4,
  114345. };
  114346. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_1 = {
  114347. _vq_quantthresh__44c2_s_p8_1,
  114348. _vq_quantmap__44c2_s_p8_1,
  114349. 5,
  114350. 5
  114351. };
  114352. static static_codebook _44c2_s_p8_1 = {
  114353. 2, 25,
  114354. _vq_lengthlist__44c2_s_p8_1,
  114355. 1, -533725184, 1611661312, 3, 0,
  114356. _vq_quantlist__44c2_s_p8_1,
  114357. NULL,
  114358. &_vq_auxt__44c2_s_p8_1,
  114359. NULL,
  114360. 0
  114361. };
  114362. static long _vq_quantlist__44c2_s_p9_0[] = {
  114363. 6,
  114364. 5,
  114365. 7,
  114366. 4,
  114367. 8,
  114368. 3,
  114369. 9,
  114370. 2,
  114371. 10,
  114372. 1,
  114373. 11,
  114374. 0,
  114375. 12,
  114376. };
  114377. static long _vq_lengthlist__44c2_s_p9_0[] = {
  114378. 1, 5, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  114379. 11,11,11,11,11,11,11,11,11,11, 2, 8, 7,11,11,11,
  114380. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114381. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  114382. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114383. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114384. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114385. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114386. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114387. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114388. 11,11,11,11,11,11,11,11,11,
  114389. };
  114390. static float _vq_quantthresh__44c2_s_p9_0[] = {
  114391. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  114392. 552.5, 773.5, 994.5, 1215.5,
  114393. };
  114394. static long _vq_quantmap__44c2_s_p9_0[] = {
  114395. 11, 9, 7, 5, 3, 1, 0, 2,
  114396. 4, 6, 8, 10, 12,
  114397. };
  114398. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_0 = {
  114399. _vq_quantthresh__44c2_s_p9_0,
  114400. _vq_quantmap__44c2_s_p9_0,
  114401. 13,
  114402. 13
  114403. };
  114404. static static_codebook _44c2_s_p9_0 = {
  114405. 2, 169,
  114406. _vq_lengthlist__44c2_s_p9_0,
  114407. 1, -514541568, 1627103232, 4, 0,
  114408. _vq_quantlist__44c2_s_p9_0,
  114409. NULL,
  114410. &_vq_auxt__44c2_s_p9_0,
  114411. NULL,
  114412. 0
  114413. };
  114414. static long _vq_quantlist__44c2_s_p9_1[] = {
  114415. 6,
  114416. 5,
  114417. 7,
  114418. 4,
  114419. 8,
  114420. 3,
  114421. 9,
  114422. 2,
  114423. 10,
  114424. 1,
  114425. 11,
  114426. 0,
  114427. 12,
  114428. };
  114429. static long _vq_lengthlist__44c2_s_p9_1[] = {
  114430. 1, 4, 4, 6, 6, 7, 6, 8, 8,10, 9,10,10, 6, 5, 5,
  114431. 7, 7, 8, 7,10, 9,11,11,12,13, 6, 5, 5, 7, 7, 8,
  114432. 8,10,10,11,11,13,13,18, 8, 8, 8, 8, 9, 9,10,10,
  114433. 12,12,12,13,18, 8, 8, 8, 8, 9, 9,10,10,12,12,13,
  114434. 13,18,11,11, 8, 8,10,10,11,11,12,11,13,12,18,11,
  114435. 11, 9, 7,10,10,11,11,11,12,12,13,17,17,17,10,10,
  114436. 11,11,12,12,12,10,12,12,17,17,17,11,10,11,10,13,
  114437. 12,11,12,12,12,17,17,17,15,14,11,11,12,11,13,10,
  114438. 13,12,17,17,17,14,14,12,10,11,11,13,13,13,13,17,
  114439. 17,16,17,16,13,13,12,10,13,10,14,13,17,16,17,16,
  114440. 17,13,12,12,10,13,11,14,14,
  114441. };
  114442. static float _vq_quantthresh__44c2_s_p9_1[] = {
  114443. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  114444. 42.5, 59.5, 76.5, 93.5,
  114445. };
  114446. static long _vq_quantmap__44c2_s_p9_1[] = {
  114447. 11, 9, 7, 5, 3, 1, 0, 2,
  114448. 4, 6, 8, 10, 12,
  114449. };
  114450. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_1 = {
  114451. _vq_quantthresh__44c2_s_p9_1,
  114452. _vq_quantmap__44c2_s_p9_1,
  114453. 13,
  114454. 13
  114455. };
  114456. static static_codebook _44c2_s_p9_1 = {
  114457. 2, 169,
  114458. _vq_lengthlist__44c2_s_p9_1,
  114459. 1, -522616832, 1620115456, 4, 0,
  114460. _vq_quantlist__44c2_s_p9_1,
  114461. NULL,
  114462. &_vq_auxt__44c2_s_p9_1,
  114463. NULL,
  114464. 0
  114465. };
  114466. static long _vq_quantlist__44c2_s_p9_2[] = {
  114467. 8,
  114468. 7,
  114469. 9,
  114470. 6,
  114471. 10,
  114472. 5,
  114473. 11,
  114474. 4,
  114475. 12,
  114476. 3,
  114477. 13,
  114478. 2,
  114479. 14,
  114480. 1,
  114481. 15,
  114482. 0,
  114483. 16,
  114484. };
  114485. static long _vq_lengthlist__44c2_s_p9_2[] = {
  114486. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  114487. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  114488. 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  114489. 9, 9, 9,10, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  114490. 9, 9, 9, 9,10,10,10, 8, 7, 8, 8, 8, 8, 9, 9, 9,
  114491. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  114492. 9, 9,10, 9, 9, 9,10,11,10, 8, 8, 8, 8, 9, 9, 9,
  114493. 9, 9, 9, 9,10,10,10,10,11,10, 8, 8, 9, 9, 9, 9,
  114494. 9, 9,10, 9, 9,10, 9,10,11,10,11,11,11, 8, 8, 9,
  114495. 9, 9, 9, 9, 9, 9, 9,10,10,11,11,11,11,11, 9, 9,
  114496. 9, 9, 9, 9,10, 9, 9, 9,10,10,11,11,11,11,11, 9,
  114497. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,11,11,11,11,11,
  114498. 9, 9, 9, 9,10,10, 9, 9, 9,10,10,10,11,11,11,11,
  114499. 11,11,11, 9, 9, 9,10, 9, 9,10,10,10,10,11,11,10,
  114500. 11,11,11,11,10, 9,10,10, 9, 9, 9, 9,10,10,11,10,
  114501. 11,11,11,11,11, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  114502. 10,11,11,11,11,11,10,10, 9, 9,10, 9,10,10,10,10,
  114503. 10,10,10,11,11,11,11,11,11, 9, 9,10, 9,10, 9,10,
  114504. 10,
  114505. };
  114506. static float _vq_quantthresh__44c2_s_p9_2[] = {
  114507. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114508. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114509. };
  114510. static long _vq_quantmap__44c2_s_p9_2[] = {
  114511. 15, 13, 11, 9, 7, 5, 3, 1,
  114512. 0, 2, 4, 6, 8, 10, 12, 14,
  114513. 16,
  114514. };
  114515. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_2 = {
  114516. _vq_quantthresh__44c2_s_p9_2,
  114517. _vq_quantmap__44c2_s_p9_2,
  114518. 17,
  114519. 17
  114520. };
  114521. static static_codebook _44c2_s_p9_2 = {
  114522. 2, 289,
  114523. _vq_lengthlist__44c2_s_p9_2,
  114524. 1, -529530880, 1611661312, 5, 0,
  114525. _vq_quantlist__44c2_s_p9_2,
  114526. NULL,
  114527. &_vq_auxt__44c2_s_p9_2,
  114528. NULL,
  114529. 0
  114530. };
  114531. static long _huff_lengthlist__44c2_s_short[] = {
  114532. 11, 9,13,12,12,11,12,12,13,15, 8, 2,11, 4, 8, 5,
  114533. 7,10,12,15,13, 7,10, 9, 8, 8,10,13,17,17,11, 4,
  114534. 12, 5, 9, 5, 8,11,14,16,12, 6, 8, 7, 6, 6, 8,11,
  114535. 13,16,11, 4, 9, 5, 6, 4, 6,10,13,16,11, 6,11, 7,
  114536. 7, 6, 7,10,13,15,13, 9,12, 9, 8, 6, 8,10,12,14,
  114537. 14,10,10, 8, 6, 5, 6, 9,11,13,15,11,11, 9, 6, 5,
  114538. 6, 8, 9,12,
  114539. };
  114540. static static_codebook _huff_book__44c2_s_short = {
  114541. 2, 100,
  114542. _huff_lengthlist__44c2_s_short,
  114543. 0, 0, 0, 0, 0,
  114544. NULL,
  114545. NULL,
  114546. NULL,
  114547. NULL,
  114548. 0
  114549. };
  114550. static long _huff_lengthlist__44c3_s_long[] = {
  114551. 5, 6,11,11,11,11,10,10,12,11, 5, 2,11, 5, 6, 6,
  114552. 7, 9,11,13,13,10, 7,11, 6, 7, 8, 9,10,12,11, 5,
  114553. 11, 6, 8, 7, 9,11,14,15,11, 6, 6, 8, 4, 5, 7, 8,
  114554. 10,13,10, 5, 7, 7, 5, 5, 6, 8,10,11,10, 7, 7, 8,
  114555. 6, 5, 5, 7, 9, 9,11, 8, 8,11, 8, 7, 6, 6, 7, 9,
  114556. 12,11,10,13, 9, 9, 7, 7, 7, 9,11,13,12,15,12,11,
  114557. 9, 8, 8, 8,
  114558. };
  114559. static static_codebook _huff_book__44c3_s_long = {
  114560. 2, 100,
  114561. _huff_lengthlist__44c3_s_long,
  114562. 0, 0, 0, 0, 0,
  114563. NULL,
  114564. NULL,
  114565. NULL,
  114566. NULL,
  114567. 0
  114568. };
  114569. static long _vq_quantlist__44c3_s_p1_0[] = {
  114570. 1,
  114571. 0,
  114572. 2,
  114573. };
  114574. static long _vq_lengthlist__44c3_s_p1_0[] = {
  114575. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  114576. 0, 0, 5, 6, 6, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  114581. 0, 0, 0, 6, 7, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  114586. 0, 0, 0, 0, 7, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0,
  114621. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  114626. 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  114631. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  114667. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  114672. 0, 0, 0, 0, 0, 7, 8, 9, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  114677. 0, 0, 0, 0, 0, 0, 8, 9, 8, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114791. 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114799. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114985. 0,
  114986. };
  114987. static float _vq_quantthresh__44c3_s_p1_0[] = {
  114988. -0.5, 0.5,
  114989. };
  114990. static long _vq_quantmap__44c3_s_p1_0[] = {
  114991. 1, 0, 2,
  114992. };
  114993. static encode_aux_threshmatch _vq_auxt__44c3_s_p1_0 = {
  114994. _vq_quantthresh__44c3_s_p1_0,
  114995. _vq_quantmap__44c3_s_p1_0,
  114996. 3,
  114997. 3
  114998. };
  114999. static static_codebook _44c3_s_p1_0 = {
  115000. 8, 6561,
  115001. _vq_lengthlist__44c3_s_p1_0,
  115002. 1, -535822336, 1611661312, 2, 0,
  115003. _vq_quantlist__44c3_s_p1_0,
  115004. NULL,
  115005. &_vq_auxt__44c3_s_p1_0,
  115006. NULL,
  115007. 0
  115008. };
  115009. static long _vq_quantlist__44c3_s_p2_0[] = {
  115010. 2,
  115011. 1,
  115012. 3,
  115013. 0,
  115014. 4,
  115015. };
  115016. static long _vq_lengthlist__44c3_s_p2_0[] = {
  115017. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  115018. 7, 8, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  115019. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  115020. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  115021. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115026. 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0,
  115027. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  115028. 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  115029. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115034. 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  115035. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  115036. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0,
  115037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115042. 8,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  115043. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  115044. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  115045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115056. 0,
  115057. };
  115058. static float _vq_quantthresh__44c3_s_p2_0[] = {
  115059. -1.5, -0.5, 0.5, 1.5,
  115060. };
  115061. static long _vq_quantmap__44c3_s_p2_0[] = {
  115062. 3, 1, 0, 2, 4,
  115063. };
  115064. static encode_aux_threshmatch _vq_auxt__44c3_s_p2_0 = {
  115065. _vq_quantthresh__44c3_s_p2_0,
  115066. _vq_quantmap__44c3_s_p2_0,
  115067. 5,
  115068. 5
  115069. };
  115070. static static_codebook _44c3_s_p2_0 = {
  115071. 4, 625,
  115072. _vq_lengthlist__44c3_s_p2_0,
  115073. 1, -533725184, 1611661312, 3, 0,
  115074. _vq_quantlist__44c3_s_p2_0,
  115075. NULL,
  115076. &_vq_auxt__44c3_s_p2_0,
  115077. NULL,
  115078. 0
  115079. };
  115080. static long _vq_quantlist__44c3_s_p3_0[] = {
  115081. 2,
  115082. 1,
  115083. 3,
  115084. 0,
  115085. 4,
  115086. };
  115087. static long _vq_lengthlist__44c3_s_p3_0[] = {
  115088. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  115090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115091. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  115093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115094. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  115095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115127. 0,
  115128. };
  115129. static float _vq_quantthresh__44c3_s_p3_0[] = {
  115130. -1.5, -0.5, 0.5, 1.5,
  115131. };
  115132. static long _vq_quantmap__44c3_s_p3_0[] = {
  115133. 3, 1, 0, 2, 4,
  115134. };
  115135. static encode_aux_threshmatch _vq_auxt__44c3_s_p3_0 = {
  115136. _vq_quantthresh__44c3_s_p3_0,
  115137. _vq_quantmap__44c3_s_p3_0,
  115138. 5,
  115139. 5
  115140. };
  115141. static static_codebook _44c3_s_p3_0 = {
  115142. 4, 625,
  115143. _vq_lengthlist__44c3_s_p3_0,
  115144. 1, -533725184, 1611661312, 3, 0,
  115145. _vq_quantlist__44c3_s_p3_0,
  115146. NULL,
  115147. &_vq_auxt__44c3_s_p3_0,
  115148. NULL,
  115149. 0
  115150. };
  115151. static long _vq_quantlist__44c3_s_p4_0[] = {
  115152. 4,
  115153. 3,
  115154. 5,
  115155. 2,
  115156. 6,
  115157. 1,
  115158. 7,
  115159. 0,
  115160. 8,
  115161. };
  115162. static long _vq_lengthlist__44c3_s_p4_0[] = {
  115163. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  115164. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  115165. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  115166. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  115167. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115168. 0,
  115169. };
  115170. static float _vq_quantthresh__44c3_s_p4_0[] = {
  115171. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115172. };
  115173. static long _vq_quantmap__44c3_s_p4_0[] = {
  115174. 7, 5, 3, 1, 0, 2, 4, 6,
  115175. 8,
  115176. };
  115177. static encode_aux_threshmatch _vq_auxt__44c3_s_p4_0 = {
  115178. _vq_quantthresh__44c3_s_p4_0,
  115179. _vq_quantmap__44c3_s_p4_0,
  115180. 9,
  115181. 9
  115182. };
  115183. static static_codebook _44c3_s_p4_0 = {
  115184. 2, 81,
  115185. _vq_lengthlist__44c3_s_p4_0,
  115186. 1, -531628032, 1611661312, 4, 0,
  115187. _vq_quantlist__44c3_s_p4_0,
  115188. NULL,
  115189. &_vq_auxt__44c3_s_p4_0,
  115190. NULL,
  115191. 0
  115192. };
  115193. static long _vq_quantlist__44c3_s_p5_0[] = {
  115194. 4,
  115195. 3,
  115196. 5,
  115197. 2,
  115198. 6,
  115199. 1,
  115200. 7,
  115201. 0,
  115202. 8,
  115203. };
  115204. static long _vq_lengthlist__44c3_s_p5_0[] = {
  115205. 1, 3, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 7, 8,
  115206. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  115207. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  115208. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  115209. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  115210. 11,
  115211. };
  115212. static float _vq_quantthresh__44c3_s_p5_0[] = {
  115213. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115214. };
  115215. static long _vq_quantmap__44c3_s_p5_0[] = {
  115216. 7, 5, 3, 1, 0, 2, 4, 6,
  115217. 8,
  115218. };
  115219. static encode_aux_threshmatch _vq_auxt__44c3_s_p5_0 = {
  115220. _vq_quantthresh__44c3_s_p5_0,
  115221. _vq_quantmap__44c3_s_p5_0,
  115222. 9,
  115223. 9
  115224. };
  115225. static static_codebook _44c3_s_p5_0 = {
  115226. 2, 81,
  115227. _vq_lengthlist__44c3_s_p5_0,
  115228. 1, -531628032, 1611661312, 4, 0,
  115229. _vq_quantlist__44c3_s_p5_0,
  115230. NULL,
  115231. &_vq_auxt__44c3_s_p5_0,
  115232. NULL,
  115233. 0
  115234. };
  115235. static long _vq_quantlist__44c3_s_p6_0[] = {
  115236. 8,
  115237. 7,
  115238. 9,
  115239. 6,
  115240. 10,
  115241. 5,
  115242. 11,
  115243. 4,
  115244. 12,
  115245. 3,
  115246. 13,
  115247. 2,
  115248. 14,
  115249. 1,
  115250. 15,
  115251. 0,
  115252. 16,
  115253. };
  115254. static long _vq_lengthlist__44c3_s_p6_0[] = {
  115255. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  115256. 10, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  115257. 11,11, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  115258. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  115259. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  115260. 10,11,11,11,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115261. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  115262. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  115263. 10,10,11,10,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  115264. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 8,
  115265. 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8,
  115266. 8, 9, 9,10,10,11,11,12,11,12,12, 0, 0, 0, 0, 0,
  115267. 9,10,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0,
  115268. 0, 0, 0,10,10,10,10,11,11,12,12,13,13, 0, 0, 0,
  115269. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  115270. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  115271. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13,
  115272. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  115273. 13,
  115274. };
  115275. static float _vq_quantthresh__44c3_s_p6_0[] = {
  115276. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115277. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115278. };
  115279. static long _vq_quantmap__44c3_s_p6_0[] = {
  115280. 15, 13, 11, 9, 7, 5, 3, 1,
  115281. 0, 2, 4, 6, 8, 10, 12, 14,
  115282. 16,
  115283. };
  115284. static encode_aux_threshmatch _vq_auxt__44c3_s_p6_0 = {
  115285. _vq_quantthresh__44c3_s_p6_0,
  115286. _vq_quantmap__44c3_s_p6_0,
  115287. 17,
  115288. 17
  115289. };
  115290. static static_codebook _44c3_s_p6_0 = {
  115291. 2, 289,
  115292. _vq_lengthlist__44c3_s_p6_0,
  115293. 1, -529530880, 1611661312, 5, 0,
  115294. _vq_quantlist__44c3_s_p6_0,
  115295. NULL,
  115296. &_vq_auxt__44c3_s_p6_0,
  115297. NULL,
  115298. 0
  115299. };
  115300. static long _vq_quantlist__44c3_s_p7_0[] = {
  115301. 1,
  115302. 0,
  115303. 2,
  115304. };
  115305. static long _vq_lengthlist__44c3_s_p7_0[] = {
  115306. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  115307. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  115308. 10,12,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  115309. 11,10,10,11,10,10, 7,11,11,11,11,11,12,11,11, 6,
  115310. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  115311. 10,
  115312. };
  115313. static float _vq_quantthresh__44c3_s_p7_0[] = {
  115314. -5.5, 5.5,
  115315. };
  115316. static long _vq_quantmap__44c3_s_p7_0[] = {
  115317. 1, 0, 2,
  115318. };
  115319. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_0 = {
  115320. _vq_quantthresh__44c3_s_p7_0,
  115321. _vq_quantmap__44c3_s_p7_0,
  115322. 3,
  115323. 3
  115324. };
  115325. static static_codebook _44c3_s_p7_0 = {
  115326. 4, 81,
  115327. _vq_lengthlist__44c3_s_p7_0,
  115328. 1, -529137664, 1618345984, 2, 0,
  115329. _vq_quantlist__44c3_s_p7_0,
  115330. NULL,
  115331. &_vq_auxt__44c3_s_p7_0,
  115332. NULL,
  115333. 0
  115334. };
  115335. static long _vq_quantlist__44c3_s_p7_1[] = {
  115336. 5,
  115337. 4,
  115338. 6,
  115339. 3,
  115340. 7,
  115341. 2,
  115342. 8,
  115343. 1,
  115344. 9,
  115345. 0,
  115346. 10,
  115347. };
  115348. static long _vq_lengthlist__44c3_s_p7_1[] = {
  115349. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  115350. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  115351. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  115352. 7, 8, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  115353. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  115354. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  115355. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  115356. 10,10,10, 8, 8, 8, 8, 8, 8,
  115357. };
  115358. static float _vq_quantthresh__44c3_s_p7_1[] = {
  115359. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  115360. 3.5, 4.5,
  115361. };
  115362. static long _vq_quantmap__44c3_s_p7_1[] = {
  115363. 9, 7, 5, 3, 1, 0, 2, 4,
  115364. 6, 8, 10,
  115365. };
  115366. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_1 = {
  115367. _vq_quantthresh__44c3_s_p7_1,
  115368. _vq_quantmap__44c3_s_p7_1,
  115369. 11,
  115370. 11
  115371. };
  115372. static static_codebook _44c3_s_p7_1 = {
  115373. 2, 121,
  115374. _vq_lengthlist__44c3_s_p7_1,
  115375. 1, -531365888, 1611661312, 4, 0,
  115376. _vq_quantlist__44c3_s_p7_1,
  115377. NULL,
  115378. &_vq_auxt__44c3_s_p7_1,
  115379. NULL,
  115380. 0
  115381. };
  115382. static long _vq_quantlist__44c3_s_p8_0[] = {
  115383. 6,
  115384. 5,
  115385. 7,
  115386. 4,
  115387. 8,
  115388. 3,
  115389. 9,
  115390. 2,
  115391. 10,
  115392. 1,
  115393. 11,
  115394. 0,
  115395. 12,
  115396. };
  115397. static long _vq_lengthlist__44c3_s_p8_0[] = {
  115398. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  115399. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  115400. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115401. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  115402. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,12, 0,13,
  115403. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  115404. 10,10,11,11,12,12,12,12, 0, 0, 0,10,10,10,10,11,
  115405. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  115406. 13,13, 0, 0, 0,14,14,11,11,11,11,12,12,13,13, 0,
  115407. 0, 0, 0, 0,12,12,12,12,13,13,14,13, 0, 0, 0, 0,
  115408. 0,13,13,12,12,13,12,14,13,
  115409. };
  115410. static float _vq_quantthresh__44c3_s_p8_0[] = {
  115411. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  115412. 12.5, 17.5, 22.5, 27.5,
  115413. };
  115414. static long _vq_quantmap__44c3_s_p8_0[] = {
  115415. 11, 9, 7, 5, 3, 1, 0, 2,
  115416. 4, 6, 8, 10, 12,
  115417. };
  115418. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_0 = {
  115419. _vq_quantthresh__44c3_s_p8_0,
  115420. _vq_quantmap__44c3_s_p8_0,
  115421. 13,
  115422. 13
  115423. };
  115424. static static_codebook _44c3_s_p8_0 = {
  115425. 2, 169,
  115426. _vq_lengthlist__44c3_s_p8_0,
  115427. 1, -526516224, 1616117760, 4, 0,
  115428. _vq_quantlist__44c3_s_p8_0,
  115429. NULL,
  115430. &_vq_auxt__44c3_s_p8_0,
  115431. NULL,
  115432. 0
  115433. };
  115434. static long _vq_quantlist__44c3_s_p8_1[] = {
  115435. 2,
  115436. 1,
  115437. 3,
  115438. 0,
  115439. 4,
  115440. };
  115441. static long _vq_lengthlist__44c3_s_p8_1[] = {
  115442. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  115443. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  115444. };
  115445. static float _vq_quantthresh__44c3_s_p8_1[] = {
  115446. -1.5, -0.5, 0.5, 1.5,
  115447. };
  115448. static long _vq_quantmap__44c3_s_p8_1[] = {
  115449. 3, 1, 0, 2, 4,
  115450. };
  115451. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_1 = {
  115452. _vq_quantthresh__44c3_s_p8_1,
  115453. _vq_quantmap__44c3_s_p8_1,
  115454. 5,
  115455. 5
  115456. };
  115457. static static_codebook _44c3_s_p8_1 = {
  115458. 2, 25,
  115459. _vq_lengthlist__44c3_s_p8_1,
  115460. 1, -533725184, 1611661312, 3, 0,
  115461. _vq_quantlist__44c3_s_p8_1,
  115462. NULL,
  115463. &_vq_auxt__44c3_s_p8_1,
  115464. NULL,
  115465. 0
  115466. };
  115467. static long _vq_quantlist__44c3_s_p9_0[] = {
  115468. 6,
  115469. 5,
  115470. 7,
  115471. 4,
  115472. 8,
  115473. 3,
  115474. 9,
  115475. 2,
  115476. 10,
  115477. 1,
  115478. 11,
  115479. 0,
  115480. 12,
  115481. };
  115482. static long _vq_lengthlist__44c3_s_p9_0[] = {
  115483. 1, 4, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  115484. 12,12,12,12,12,12,12,12,12,12, 2, 9, 7,12,12,12,
  115485. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115486. 12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,
  115487. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115488. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115489. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115490. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115491. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  115492. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  115493. 11,11,11,11,11,11,11,11,11,
  115494. };
  115495. static float _vq_quantthresh__44c3_s_p9_0[] = {
  115496. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  115497. 637.5, 892.5, 1147.5, 1402.5,
  115498. };
  115499. static long _vq_quantmap__44c3_s_p9_0[] = {
  115500. 11, 9, 7, 5, 3, 1, 0, 2,
  115501. 4, 6, 8, 10, 12,
  115502. };
  115503. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_0 = {
  115504. _vq_quantthresh__44c3_s_p9_0,
  115505. _vq_quantmap__44c3_s_p9_0,
  115506. 13,
  115507. 13
  115508. };
  115509. static static_codebook _44c3_s_p9_0 = {
  115510. 2, 169,
  115511. _vq_lengthlist__44c3_s_p9_0,
  115512. 1, -514332672, 1627381760, 4, 0,
  115513. _vq_quantlist__44c3_s_p9_0,
  115514. NULL,
  115515. &_vq_auxt__44c3_s_p9_0,
  115516. NULL,
  115517. 0
  115518. };
  115519. static long _vq_quantlist__44c3_s_p9_1[] = {
  115520. 7,
  115521. 6,
  115522. 8,
  115523. 5,
  115524. 9,
  115525. 4,
  115526. 10,
  115527. 3,
  115528. 11,
  115529. 2,
  115530. 12,
  115531. 1,
  115532. 13,
  115533. 0,
  115534. 14,
  115535. };
  115536. static long _vq_lengthlist__44c3_s_p9_1[] = {
  115537. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 9,10,10,10,10, 6,
  115538. 5, 5, 7, 7, 8, 8,10, 8,11,10,12,12,13,13, 6, 5,
  115539. 5, 7, 7, 8, 8,10, 9,11,11,12,12,13,12,18, 8, 8,
  115540. 8, 8, 9, 9,10, 9,11,10,12,12,13,13,18, 8, 8, 8,
  115541. 8, 9, 9,10,10,11,11,13,12,14,13,18,11,11, 9, 9,
  115542. 10,10,11,11,11,12,13,12,13,14,18,11,11, 9, 8,11,
  115543. 10,11,11,11,11,12,12,14,13,18,18,18,10,11,10,11,
  115544. 12,12,12,12,13,12,14,13,18,18,18,10,11,11, 9,12,
  115545. 11,12,12,12,13,13,13,18,18,17,14,14,11,11,12,12,
  115546. 13,12,14,12,14,13,18,18,18,14,14,11,10,12, 9,12,
  115547. 13,13,13,13,13,18,18,17,16,18,13,13,12,12,13,11,
  115548. 14,12,14,14,17,18,18,17,18,13,12,13,10,12,11,14,
  115549. 14,14,14,17,18,18,18,18,15,16,12,12,13,10,14,12,
  115550. 14,15,18,18,18,16,17,16,14,12,11,13,10,13,13,14,
  115551. 15,
  115552. };
  115553. static float _vq_quantthresh__44c3_s_p9_1[] = {
  115554. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  115555. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  115556. };
  115557. static long _vq_quantmap__44c3_s_p9_1[] = {
  115558. 13, 11, 9, 7, 5, 3, 1, 0,
  115559. 2, 4, 6, 8, 10, 12, 14,
  115560. };
  115561. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_1 = {
  115562. _vq_quantthresh__44c3_s_p9_1,
  115563. _vq_quantmap__44c3_s_p9_1,
  115564. 15,
  115565. 15
  115566. };
  115567. static static_codebook _44c3_s_p9_1 = {
  115568. 2, 225,
  115569. _vq_lengthlist__44c3_s_p9_1,
  115570. 1, -522338304, 1620115456, 4, 0,
  115571. _vq_quantlist__44c3_s_p9_1,
  115572. NULL,
  115573. &_vq_auxt__44c3_s_p9_1,
  115574. NULL,
  115575. 0
  115576. };
  115577. static long _vq_quantlist__44c3_s_p9_2[] = {
  115578. 8,
  115579. 7,
  115580. 9,
  115581. 6,
  115582. 10,
  115583. 5,
  115584. 11,
  115585. 4,
  115586. 12,
  115587. 3,
  115588. 13,
  115589. 2,
  115590. 14,
  115591. 1,
  115592. 15,
  115593. 0,
  115594. 16,
  115595. };
  115596. static long _vq_lengthlist__44c3_s_p9_2[] = {
  115597. 2, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  115598. 8,10, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 8, 9, 9, 9,
  115599. 9, 9,10, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  115600. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  115601. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  115602. 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  115603. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  115604. 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 9, 9, 9, 9, 9,
  115605. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 9, 9, 9,
  115606. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  115607. 9, 9, 9, 9,10,10, 9, 9,10, 9,11,10,11,11,11, 9,
  115608. 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,11,11,11,11,11,
  115609. 9, 9, 9, 9,10,10, 9, 9, 9, 9,10, 9,11,11,11,11,
  115610. 11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11,
  115611. 11,11,11,11,10, 9,10,10, 9,10, 9, 9,10, 9,11,10,
  115612. 10,11,11,11,11, 9,10, 9, 9, 9, 9,10,10,10,10,11,
  115613. 11,11,11,11,11,10,10,10, 9, 9,10, 9,10, 9,10,10,
  115614. 10,10,11,11,11,11,11,11,11, 9, 9, 9, 9, 9,10,10,
  115615. 10,
  115616. };
  115617. static float _vq_quantthresh__44c3_s_p9_2[] = {
  115618. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115619. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115620. };
  115621. static long _vq_quantmap__44c3_s_p9_2[] = {
  115622. 15, 13, 11, 9, 7, 5, 3, 1,
  115623. 0, 2, 4, 6, 8, 10, 12, 14,
  115624. 16,
  115625. };
  115626. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_2 = {
  115627. _vq_quantthresh__44c3_s_p9_2,
  115628. _vq_quantmap__44c3_s_p9_2,
  115629. 17,
  115630. 17
  115631. };
  115632. static static_codebook _44c3_s_p9_2 = {
  115633. 2, 289,
  115634. _vq_lengthlist__44c3_s_p9_2,
  115635. 1, -529530880, 1611661312, 5, 0,
  115636. _vq_quantlist__44c3_s_p9_2,
  115637. NULL,
  115638. &_vq_auxt__44c3_s_p9_2,
  115639. NULL,
  115640. 0
  115641. };
  115642. static long _huff_lengthlist__44c3_s_short[] = {
  115643. 10, 9,13,11,14,10,12,13,13,14, 7, 2,12, 5,10, 5,
  115644. 7,10,12,14,12, 6, 9, 8, 7, 7, 9,11,13,16,10, 4,
  115645. 12, 5,10, 6, 8,12,14,16,12, 6, 8, 7, 6, 5, 7,11,
  115646. 12,16,10, 4, 8, 5, 6, 4, 6, 9,13,16,10, 6,10, 7,
  115647. 7, 6, 7, 9,13,15,12, 9,11, 9, 8, 6, 7,10,12,14,
  115648. 14,11,10, 9, 6, 5, 6, 9,11,13,15,13,11,10, 6, 5,
  115649. 6, 8, 9,11,
  115650. };
  115651. static static_codebook _huff_book__44c3_s_short = {
  115652. 2, 100,
  115653. _huff_lengthlist__44c3_s_short,
  115654. 0, 0, 0, 0, 0,
  115655. NULL,
  115656. NULL,
  115657. NULL,
  115658. NULL,
  115659. 0
  115660. };
  115661. static long _huff_lengthlist__44c4_s_long[] = {
  115662. 4, 7,11,11,11,11,10,11,12,11, 5, 2,11, 5, 6, 6,
  115663. 7, 9,11,12,11, 9, 6,10, 6, 7, 8, 9,10,11,11, 5,
  115664. 11, 7, 8, 8, 9,11,13,14,11, 6, 5, 8, 4, 5, 7, 8,
  115665. 10,11,10, 6, 7, 7, 5, 5, 6, 8, 9,11,10, 7, 8, 9,
  115666. 6, 6, 6, 7, 8, 9,11, 9, 9,11, 7, 7, 6, 6, 7, 9,
  115667. 12,12,10,13, 9, 8, 7, 7, 7, 8,11,13,11,14,11,10,
  115668. 9, 8, 7, 7,
  115669. };
  115670. static static_codebook _huff_book__44c4_s_long = {
  115671. 2, 100,
  115672. _huff_lengthlist__44c4_s_long,
  115673. 0, 0, 0, 0, 0,
  115674. NULL,
  115675. NULL,
  115676. NULL,
  115677. NULL,
  115678. 0
  115679. };
  115680. static long _vq_quantlist__44c4_s_p1_0[] = {
  115681. 1,
  115682. 0,
  115683. 2,
  115684. };
  115685. static long _vq_lengthlist__44c4_s_p1_0[] = {
  115686. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  115687. 0, 0, 5, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  115692. 0, 0, 0, 6, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  115697. 0, 0, 0, 0, 7, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0,
  115732. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  115737. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  115742. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  115778. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  115783. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115788. 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115902. 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115910. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116096. 0,
  116097. };
  116098. static float _vq_quantthresh__44c4_s_p1_0[] = {
  116099. -0.5, 0.5,
  116100. };
  116101. static long _vq_quantmap__44c4_s_p1_0[] = {
  116102. 1, 0, 2,
  116103. };
  116104. static encode_aux_threshmatch _vq_auxt__44c4_s_p1_0 = {
  116105. _vq_quantthresh__44c4_s_p1_0,
  116106. _vq_quantmap__44c4_s_p1_0,
  116107. 3,
  116108. 3
  116109. };
  116110. static static_codebook _44c4_s_p1_0 = {
  116111. 8, 6561,
  116112. _vq_lengthlist__44c4_s_p1_0,
  116113. 1, -535822336, 1611661312, 2, 0,
  116114. _vq_quantlist__44c4_s_p1_0,
  116115. NULL,
  116116. &_vq_auxt__44c4_s_p1_0,
  116117. NULL,
  116118. 0
  116119. };
  116120. static long _vq_quantlist__44c4_s_p2_0[] = {
  116121. 2,
  116122. 1,
  116123. 3,
  116124. 0,
  116125. 4,
  116126. };
  116127. static long _vq_lengthlist__44c4_s_p2_0[] = {
  116128. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  116129. 7, 7, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  116130. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116131. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  116132. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116137. 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 7, 7, 0, 0,
  116138. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  116139. 7, 8, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  116140. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116145. 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  116146. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  116147. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0,
  116148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116153. 7,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  116154. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  116155. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116167. 0,
  116168. };
  116169. static float _vq_quantthresh__44c4_s_p2_0[] = {
  116170. -1.5, -0.5, 0.5, 1.5,
  116171. };
  116172. static long _vq_quantmap__44c4_s_p2_0[] = {
  116173. 3, 1, 0, 2, 4,
  116174. };
  116175. static encode_aux_threshmatch _vq_auxt__44c4_s_p2_0 = {
  116176. _vq_quantthresh__44c4_s_p2_0,
  116177. _vq_quantmap__44c4_s_p2_0,
  116178. 5,
  116179. 5
  116180. };
  116181. static static_codebook _44c4_s_p2_0 = {
  116182. 4, 625,
  116183. _vq_lengthlist__44c4_s_p2_0,
  116184. 1, -533725184, 1611661312, 3, 0,
  116185. _vq_quantlist__44c4_s_p2_0,
  116186. NULL,
  116187. &_vq_auxt__44c4_s_p2_0,
  116188. NULL,
  116189. 0
  116190. };
  116191. static long _vq_quantlist__44c4_s_p3_0[] = {
  116192. 2,
  116193. 1,
  116194. 3,
  116195. 0,
  116196. 4,
  116197. };
  116198. static long _vq_lengthlist__44c4_s_p3_0[] = {
  116199. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 4, 6, 6, 0, 0,
  116201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116202. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  116204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116205. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  116206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116238. 0,
  116239. };
  116240. static float _vq_quantthresh__44c4_s_p3_0[] = {
  116241. -1.5, -0.5, 0.5, 1.5,
  116242. };
  116243. static long _vq_quantmap__44c4_s_p3_0[] = {
  116244. 3, 1, 0, 2, 4,
  116245. };
  116246. static encode_aux_threshmatch _vq_auxt__44c4_s_p3_0 = {
  116247. _vq_quantthresh__44c4_s_p3_0,
  116248. _vq_quantmap__44c4_s_p3_0,
  116249. 5,
  116250. 5
  116251. };
  116252. static static_codebook _44c4_s_p3_0 = {
  116253. 4, 625,
  116254. _vq_lengthlist__44c4_s_p3_0,
  116255. 1, -533725184, 1611661312, 3, 0,
  116256. _vq_quantlist__44c4_s_p3_0,
  116257. NULL,
  116258. &_vq_auxt__44c4_s_p3_0,
  116259. NULL,
  116260. 0
  116261. };
  116262. static long _vq_quantlist__44c4_s_p4_0[] = {
  116263. 4,
  116264. 3,
  116265. 5,
  116266. 2,
  116267. 6,
  116268. 1,
  116269. 7,
  116270. 0,
  116271. 8,
  116272. };
  116273. static long _vq_lengthlist__44c4_s_p4_0[] = {
  116274. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  116275. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  116276. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  116277. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  116278. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116279. 0,
  116280. };
  116281. static float _vq_quantthresh__44c4_s_p4_0[] = {
  116282. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116283. };
  116284. static long _vq_quantmap__44c4_s_p4_0[] = {
  116285. 7, 5, 3, 1, 0, 2, 4, 6,
  116286. 8,
  116287. };
  116288. static encode_aux_threshmatch _vq_auxt__44c4_s_p4_0 = {
  116289. _vq_quantthresh__44c4_s_p4_0,
  116290. _vq_quantmap__44c4_s_p4_0,
  116291. 9,
  116292. 9
  116293. };
  116294. static static_codebook _44c4_s_p4_0 = {
  116295. 2, 81,
  116296. _vq_lengthlist__44c4_s_p4_0,
  116297. 1, -531628032, 1611661312, 4, 0,
  116298. _vq_quantlist__44c4_s_p4_0,
  116299. NULL,
  116300. &_vq_auxt__44c4_s_p4_0,
  116301. NULL,
  116302. 0
  116303. };
  116304. static long _vq_quantlist__44c4_s_p5_0[] = {
  116305. 4,
  116306. 3,
  116307. 5,
  116308. 2,
  116309. 6,
  116310. 1,
  116311. 7,
  116312. 0,
  116313. 8,
  116314. };
  116315. static long _vq_lengthlist__44c4_s_p5_0[] = {
  116316. 2, 3, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  116317. 9, 9, 0, 4, 5, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  116318. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10, 9, 0, 0, 0,
  116319. 9, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  116320. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,10,
  116321. 10,
  116322. };
  116323. static float _vq_quantthresh__44c4_s_p5_0[] = {
  116324. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116325. };
  116326. static long _vq_quantmap__44c4_s_p5_0[] = {
  116327. 7, 5, 3, 1, 0, 2, 4, 6,
  116328. 8,
  116329. };
  116330. static encode_aux_threshmatch _vq_auxt__44c4_s_p5_0 = {
  116331. _vq_quantthresh__44c4_s_p5_0,
  116332. _vq_quantmap__44c4_s_p5_0,
  116333. 9,
  116334. 9
  116335. };
  116336. static static_codebook _44c4_s_p5_0 = {
  116337. 2, 81,
  116338. _vq_lengthlist__44c4_s_p5_0,
  116339. 1, -531628032, 1611661312, 4, 0,
  116340. _vq_quantlist__44c4_s_p5_0,
  116341. NULL,
  116342. &_vq_auxt__44c4_s_p5_0,
  116343. NULL,
  116344. 0
  116345. };
  116346. static long _vq_quantlist__44c4_s_p6_0[] = {
  116347. 8,
  116348. 7,
  116349. 9,
  116350. 6,
  116351. 10,
  116352. 5,
  116353. 11,
  116354. 4,
  116355. 12,
  116356. 3,
  116357. 13,
  116358. 2,
  116359. 14,
  116360. 1,
  116361. 15,
  116362. 0,
  116363. 16,
  116364. };
  116365. static long _vq_lengthlist__44c4_s_p6_0[] = {
  116366. 2, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  116367. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  116368. 11,11, 0, 4, 4, 7, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  116369. 11,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  116370. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  116371. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116372. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  116373. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  116374. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  116375. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  116376. 9,10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9,
  116377. 9, 9, 9,10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0,
  116378. 10,10,10,10,11,11,11,11,12,12,13,12, 0, 0, 0, 0,
  116379. 0, 0, 0,10,10,11,11,11,11,12,12,12,12, 0, 0, 0,
  116380. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  116381. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  116382. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,13,13,
  116383. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,
  116384. 13,
  116385. };
  116386. static float _vq_quantthresh__44c4_s_p6_0[] = {
  116387. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  116388. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  116389. };
  116390. static long _vq_quantmap__44c4_s_p6_0[] = {
  116391. 15, 13, 11, 9, 7, 5, 3, 1,
  116392. 0, 2, 4, 6, 8, 10, 12, 14,
  116393. 16,
  116394. };
  116395. static encode_aux_threshmatch _vq_auxt__44c4_s_p6_0 = {
  116396. _vq_quantthresh__44c4_s_p6_0,
  116397. _vq_quantmap__44c4_s_p6_0,
  116398. 17,
  116399. 17
  116400. };
  116401. static static_codebook _44c4_s_p6_0 = {
  116402. 2, 289,
  116403. _vq_lengthlist__44c4_s_p6_0,
  116404. 1, -529530880, 1611661312, 5, 0,
  116405. _vq_quantlist__44c4_s_p6_0,
  116406. NULL,
  116407. &_vq_auxt__44c4_s_p6_0,
  116408. NULL,
  116409. 0
  116410. };
  116411. static long _vq_quantlist__44c4_s_p7_0[] = {
  116412. 1,
  116413. 0,
  116414. 2,
  116415. };
  116416. static long _vq_lengthlist__44c4_s_p7_0[] = {
  116417. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  116418. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  116419. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  116420. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  116421. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  116422. 10,
  116423. };
  116424. static float _vq_quantthresh__44c4_s_p7_0[] = {
  116425. -5.5, 5.5,
  116426. };
  116427. static long _vq_quantmap__44c4_s_p7_0[] = {
  116428. 1, 0, 2,
  116429. };
  116430. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_0 = {
  116431. _vq_quantthresh__44c4_s_p7_0,
  116432. _vq_quantmap__44c4_s_p7_0,
  116433. 3,
  116434. 3
  116435. };
  116436. static static_codebook _44c4_s_p7_0 = {
  116437. 4, 81,
  116438. _vq_lengthlist__44c4_s_p7_0,
  116439. 1, -529137664, 1618345984, 2, 0,
  116440. _vq_quantlist__44c4_s_p7_0,
  116441. NULL,
  116442. &_vq_auxt__44c4_s_p7_0,
  116443. NULL,
  116444. 0
  116445. };
  116446. static long _vq_quantlist__44c4_s_p7_1[] = {
  116447. 5,
  116448. 4,
  116449. 6,
  116450. 3,
  116451. 7,
  116452. 2,
  116453. 8,
  116454. 1,
  116455. 9,
  116456. 0,
  116457. 10,
  116458. };
  116459. static long _vq_lengthlist__44c4_s_p7_1[] = {
  116460. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  116461. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  116462. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  116463. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  116464. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  116465. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  116466. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  116467. 10,10,10, 8, 8, 8, 8, 9, 9,
  116468. };
  116469. static float _vq_quantthresh__44c4_s_p7_1[] = {
  116470. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  116471. 3.5, 4.5,
  116472. };
  116473. static long _vq_quantmap__44c4_s_p7_1[] = {
  116474. 9, 7, 5, 3, 1, 0, 2, 4,
  116475. 6, 8, 10,
  116476. };
  116477. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_1 = {
  116478. _vq_quantthresh__44c4_s_p7_1,
  116479. _vq_quantmap__44c4_s_p7_1,
  116480. 11,
  116481. 11
  116482. };
  116483. static static_codebook _44c4_s_p7_1 = {
  116484. 2, 121,
  116485. _vq_lengthlist__44c4_s_p7_1,
  116486. 1, -531365888, 1611661312, 4, 0,
  116487. _vq_quantlist__44c4_s_p7_1,
  116488. NULL,
  116489. &_vq_auxt__44c4_s_p7_1,
  116490. NULL,
  116491. 0
  116492. };
  116493. static long _vq_quantlist__44c4_s_p8_0[] = {
  116494. 6,
  116495. 5,
  116496. 7,
  116497. 4,
  116498. 8,
  116499. 3,
  116500. 9,
  116501. 2,
  116502. 10,
  116503. 1,
  116504. 11,
  116505. 0,
  116506. 12,
  116507. };
  116508. static long _vq_lengthlist__44c4_s_p8_0[] = {
  116509. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  116510. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  116511. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116512. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  116513. 11, 0,12,12, 9, 9, 9, 9,10,10,10,10,11,11, 0,13,
  116514. 13, 9, 9,10, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  116515. 10,10,10,10,11,11,12,12, 0, 0, 0,10,10,10,10,10,
  116516. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  116517. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,13, 0,
  116518. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  116519. 0,13,12,12,12,12,12,13,13,
  116520. };
  116521. static float _vq_quantthresh__44c4_s_p8_0[] = {
  116522. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  116523. 12.5, 17.5, 22.5, 27.5,
  116524. };
  116525. static long _vq_quantmap__44c4_s_p8_0[] = {
  116526. 11, 9, 7, 5, 3, 1, 0, 2,
  116527. 4, 6, 8, 10, 12,
  116528. };
  116529. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_0 = {
  116530. _vq_quantthresh__44c4_s_p8_0,
  116531. _vq_quantmap__44c4_s_p8_0,
  116532. 13,
  116533. 13
  116534. };
  116535. static static_codebook _44c4_s_p8_0 = {
  116536. 2, 169,
  116537. _vq_lengthlist__44c4_s_p8_0,
  116538. 1, -526516224, 1616117760, 4, 0,
  116539. _vq_quantlist__44c4_s_p8_0,
  116540. NULL,
  116541. &_vq_auxt__44c4_s_p8_0,
  116542. NULL,
  116543. 0
  116544. };
  116545. static long _vq_quantlist__44c4_s_p8_1[] = {
  116546. 2,
  116547. 1,
  116548. 3,
  116549. 0,
  116550. 4,
  116551. };
  116552. static long _vq_lengthlist__44c4_s_p8_1[] = {
  116553. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 5, 4, 5, 5, 6,
  116554. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  116555. };
  116556. static float _vq_quantthresh__44c4_s_p8_1[] = {
  116557. -1.5, -0.5, 0.5, 1.5,
  116558. };
  116559. static long _vq_quantmap__44c4_s_p8_1[] = {
  116560. 3, 1, 0, 2, 4,
  116561. };
  116562. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_1 = {
  116563. _vq_quantthresh__44c4_s_p8_1,
  116564. _vq_quantmap__44c4_s_p8_1,
  116565. 5,
  116566. 5
  116567. };
  116568. static static_codebook _44c4_s_p8_1 = {
  116569. 2, 25,
  116570. _vq_lengthlist__44c4_s_p8_1,
  116571. 1, -533725184, 1611661312, 3, 0,
  116572. _vq_quantlist__44c4_s_p8_1,
  116573. NULL,
  116574. &_vq_auxt__44c4_s_p8_1,
  116575. NULL,
  116576. 0
  116577. };
  116578. static long _vq_quantlist__44c4_s_p9_0[] = {
  116579. 6,
  116580. 5,
  116581. 7,
  116582. 4,
  116583. 8,
  116584. 3,
  116585. 9,
  116586. 2,
  116587. 10,
  116588. 1,
  116589. 11,
  116590. 0,
  116591. 12,
  116592. };
  116593. static long _vq_lengthlist__44c4_s_p9_0[] = {
  116594. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 4, 7, 7,
  116595. 12,12,12,12,12,12,12,12,12,12, 3, 8, 8,12,12,12,
  116596. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116597. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116598. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116599. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116600. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116601. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116602. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116603. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116604. 12,12,12,12,12,12,12,12,12,
  116605. };
  116606. static float _vq_quantthresh__44c4_s_p9_0[] = {
  116607. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  116608. 787.5, 1102.5, 1417.5, 1732.5,
  116609. };
  116610. static long _vq_quantmap__44c4_s_p9_0[] = {
  116611. 11, 9, 7, 5, 3, 1, 0, 2,
  116612. 4, 6, 8, 10, 12,
  116613. };
  116614. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_0 = {
  116615. _vq_quantthresh__44c4_s_p9_0,
  116616. _vq_quantmap__44c4_s_p9_0,
  116617. 13,
  116618. 13
  116619. };
  116620. static static_codebook _44c4_s_p9_0 = {
  116621. 2, 169,
  116622. _vq_lengthlist__44c4_s_p9_0,
  116623. 1, -513964032, 1628680192, 4, 0,
  116624. _vq_quantlist__44c4_s_p9_0,
  116625. NULL,
  116626. &_vq_auxt__44c4_s_p9_0,
  116627. NULL,
  116628. 0
  116629. };
  116630. static long _vq_quantlist__44c4_s_p9_1[] = {
  116631. 7,
  116632. 6,
  116633. 8,
  116634. 5,
  116635. 9,
  116636. 4,
  116637. 10,
  116638. 3,
  116639. 11,
  116640. 2,
  116641. 12,
  116642. 1,
  116643. 13,
  116644. 0,
  116645. 14,
  116646. };
  116647. static long _vq_lengthlist__44c4_s_p9_1[] = {
  116648. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,10,10, 6,
  116649. 5, 5, 7, 7, 9, 8,10, 9,11,10,12,12,13,13, 6, 5,
  116650. 5, 7, 7, 9, 9,10,10,11,11,12,12,12,13,19, 8, 8,
  116651. 8, 8, 9, 9,10,10,12,11,12,12,13,13,19, 8, 8, 8,
  116652. 8, 9, 9,11,11,12,12,13,13,13,13,19,12,12, 9, 9,
  116653. 11,11,11,11,12,11,13,12,13,13,18,12,12, 9, 9,11,
  116654. 10,11,11,12,12,12,13,13,14,19,18,18,11,11,11,11,
  116655. 12,12,13,12,13,13,14,14,16,18,18,11,11,11,10,12,
  116656. 11,13,13,13,13,13,14,17,18,18,14,15,11,12,12,13,
  116657. 13,13,13,14,14,14,18,18,18,15,15,12,10,13,10,13,
  116658. 13,13,13,13,14,18,17,18,17,18,12,13,12,13,13,13,
  116659. 14,14,16,14,18,17,18,18,17,13,12,13,10,12,12,14,
  116660. 14,14,14,17,18,18,18,18,14,15,12,12,13,12,14,14,
  116661. 15,15,18,18,18,17,18,15,14,12,11,12,12,14,14,14,
  116662. 15,
  116663. };
  116664. static float _vq_quantthresh__44c4_s_p9_1[] = {
  116665. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  116666. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  116667. };
  116668. static long _vq_quantmap__44c4_s_p9_1[] = {
  116669. 13, 11, 9, 7, 5, 3, 1, 0,
  116670. 2, 4, 6, 8, 10, 12, 14,
  116671. };
  116672. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_1 = {
  116673. _vq_quantthresh__44c4_s_p9_1,
  116674. _vq_quantmap__44c4_s_p9_1,
  116675. 15,
  116676. 15
  116677. };
  116678. static static_codebook _44c4_s_p9_1 = {
  116679. 2, 225,
  116680. _vq_lengthlist__44c4_s_p9_1,
  116681. 1, -520986624, 1620377600, 4, 0,
  116682. _vq_quantlist__44c4_s_p9_1,
  116683. NULL,
  116684. &_vq_auxt__44c4_s_p9_1,
  116685. NULL,
  116686. 0
  116687. };
  116688. static long _vq_quantlist__44c4_s_p9_2[] = {
  116689. 10,
  116690. 9,
  116691. 11,
  116692. 8,
  116693. 12,
  116694. 7,
  116695. 13,
  116696. 6,
  116697. 14,
  116698. 5,
  116699. 15,
  116700. 4,
  116701. 16,
  116702. 3,
  116703. 17,
  116704. 2,
  116705. 18,
  116706. 1,
  116707. 19,
  116708. 0,
  116709. 20,
  116710. };
  116711. static long _vq_lengthlist__44c4_s_p9_2[] = {
  116712. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  116713. 8, 9, 9, 9, 9,11, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  116714. 9, 9, 9, 9, 9, 9,10,10,10,10,11, 6, 6, 7, 7, 8,
  116715. 8, 8, 8, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  116716. 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  116717. 10,10,10,10,12,11,11, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  116718. 9,10,10,10,10,10,10,10,10,12,11,12, 8, 8, 8, 8,
  116719. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  116720. 11, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,
  116721. 10,10,10,11,11,12, 9, 9, 9, 9, 9, 9,10, 9,10,10,
  116722. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  116723. 9,10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,
  116724. 11,11, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  116725. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  116726. 10,10,10,10,10,10,10,11,11,11,12,12,10,10,10,10,
  116727. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,12,
  116728. 11,11,11, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  116729. 10,11,12,11,11,11,11,11,10,10,10,10,10,10,10,10,
  116730. 10,10,10,10,10,10,11,11,11,12,11,11,11,10,10,10,
  116731. 10,10,10,10,10,10,10,10,10,10,10,12,11,11,12,11,
  116732. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  116733. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  116734. 10,10,10,10,10,11,11,11,11,12,12,11,11,11,11,11,
  116735. 11,11,10,10,10,10,10,10,10,10,12,12,12,11,11,11,
  116736. 12,11,11,11,10,10,10,10,10,10,10,10,10,10,10,12,
  116737. 11,12,12,12,12,12,11,12,11,11,10,10,10,10,10,10,
  116738. 10,10,10,10,12,12,12,12,11,11,11,11,11,11,11,10,
  116739. 10,10,10,10,10,10,10,10,10,
  116740. };
  116741. static float _vq_quantthresh__44c4_s_p9_2[] = {
  116742. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  116743. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  116744. 6.5, 7.5, 8.5, 9.5,
  116745. };
  116746. static long _vq_quantmap__44c4_s_p9_2[] = {
  116747. 19, 17, 15, 13, 11, 9, 7, 5,
  116748. 3, 1, 0, 2, 4, 6, 8, 10,
  116749. 12, 14, 16, 18, 20,
  116750. };
  116751. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_2 = {
  116752. _vq_quantthresh__44c4_s_p9_2,
  116753. _vq_quantmap__44c4_s_p9_2,
  116754. 21,
  116755. 21
  116756. };
  116757. static static_codebook _44c4_s_p9_2 = {
  116758. 2, 441,
  116759. _vq_lengthlist__44c4_s_p9_2,
  116760. 1, -529268736, 1611661312, 5, 0,
  116761. _vq_quantlist__44c4_s_p9_2,
  116762. NULL,
  116763. &_vq_auxt__44c4_s_p9_2,
  116764. NULL,
  116765. 0
  116766. };
  116767. static long _huff_lengthlist__44c4_s_short[] = {
  116768. 4, 7,14,10,15,10,12,15,16,15, 4, 2,11, 5,10, 6,
  116769. 8,11,14,14,14,10, 7,11, 6, 8,10,11,13,15, 9, 4,
  116770. 11, 5, 9, 6, 9,12,14,15,14, 9, 6, 9, 4, 5, 7,10,
  116771. 12,13, 9, 5, 7, 6, 5, 5, 7,10,13,13,10, 8, 9, 8,
  116772. 7, 6, 8,10,14,14,13,11,10,10, 7, 7, 8,11,14,15,
  116773. 13,12, 9, 9, 6, 5, 7,10,14,17,15,13,11,10, 6, 6,
  116774. 7, 9,12,17,
  116775. };
  116776. static static_codebook _huff_book__44c4_s_short = {
  116777. 2, 100,
  116778. _huff_lengthlist__44c4_s_short,
  116779. 0, 0, 0, 0, 0,
  116780. NULL,
  116781. NULL,
  116782. NULL,
  116783. NULL,
  116784. 0
  116785. };
  116786. static long _huff_lengthlist__44c5_s_long[] = {
  116787. 3, 8, 9,13,10,12,12,12,12,12, 6, 4, 6, 8, 6, 8,
  116788. 10,10,11,12, 8, 5, 4,10, 4, 7, 8, 9,10,11,13, 8,
  116789. 10, 8, 9, 9,11,12,13,14,10, 6, 4, 9, 3, 5, 6, 8,
  116790. 10,11,11, 8, 6, 9, 5, 5, 6, 7, 9,11,12, 9, 7,11,
  116791. 6, 6, 6, 7, 8,10,12,11, 9,12, 7, 7, 6, 6, 7, 9,
  116792. 13,12,10,13, 9, 8, 7, 7, 7, 8,11,15,11,15,11,10,
  116793. 9, 8, 7, 7,
  116794. };
  116795. static static_codebook _huff_book__44c5_s_long = {
  116796. 2, 100,
  116797. _huff_lengthlist__44c5_s_long,
  116798. 0, 0, 0, 0, 0,
  116799. NULL,
  116800. NULL,
  116801. NULL,
  116802. NULL,
  116803. 0
  116804. };
  116805. static long _vq_quantlist__44c5_s_p1_0[] = {
  116806. 1,
  116807. 0,
  116808. 2,
  116809. };
  116810. static long _vq_lengthlist__44c5_s_p1_0[] = {
  116811. 2, 4, 4, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  116812. 0, 0, 4, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  116817. 0, 0, 0, 7, 8, 9, 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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  116822. 0, 0, 0, 0, 7, 9, 9, 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, 4, 7, 7, 0, 0, 0, 0,
  116857. 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  116862. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  116867. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  116903. 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  116908. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  116913. 0, 0, 0, 0, 0, 0, 9,11,10, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117027. 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117035. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117221. 0,
  117222. };
  117223. static float _vq_quantthresh__44c5_s_p1_0[] = {
  117224. -0.5, 0.5,
  117225. };
  117226. static long _vq_quantmap__44c5_s_p1_0[] = {
  117227. 1, 0, 2,
  117228. };
  117229. static encode_aux_threshmatch _vq_auxt__44c5_s_p1_0 = {
  117230. _vq_quantthresh__44c5_s_p1_0,
  117231. _vq_quantmap__44c5_s_p1_0,
  117232. 3,
  117233. 3
  117234. };
  117235. static static_codebook _44c5_s_p1_0 = {
  117236. 8, 6561,
  117237. _vq_lengthlist__44c5_s_p1_0,
  117238. 1, -535822336, 1611661312, 2, 0,
  117239. _vq_quantlist__44c5_s_p1_0,
  117240. NULL,
  117241. &_vq_auxt__44c5_s_p1_0,
  117242. NULL,
  117243. 0
  117244. };
  117245. static long _vq_quantlist__44c5_s_p2_0[] = {
  117246. 2,
  117247. 1,
  117248. 3,
  117249. 0,
  117250. 4,
  117251. };
  117252. static long _vq_lengthlist__44c5_s_p2_0[] = {
  117253. 2, 4, 4, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  117254. 8, 7, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  117255. 8, 0, 0, 0, 8, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  117256. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 7, 8, 0,
  117257. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117262. 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 8, 8, 0, 0,
  117263. 0, 8, 8, 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5,
  117264. 7, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,
  117265. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117270. 0, 0, 0, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8,
  117271. 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0,
  117272. 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,10, 0, 0,
  117273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117278. 8,10,10, 0, 0, 0,10,10, 0, 0, 0, 9,10, 0, 0, 0,
  117279. 11,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0,10,
  117280. 10, 0, 0, 0,10,10, 0, 0, 0,10,11, 0, 0, 0, 0, 0,
  117281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117292. 0,
  117293. };
  117294. static float _vq_quantthresh__44c5_s_p2_0[] = {
  117295. -1.5, -0.5, 0.5, 1.5,
  117296. };
  117297. static long _vq_quantmap__44c5_s_p2_0[] = {
  117298. 3, 1, 0, 2, 4,
  117299. };
  117300. static encode_aux_threshmatch _vq_auxt__44c5_s_p2_0 = {
  117301. _vq_quantthresh__44c5_s_p2_0,
  117302. _vq_quantmap__44c5_s_p2_0,
  117303. 5,
  117304. 5
  117305. };
  117306. static static_codebook _44c5_s_p2_0 = {
  117307. 4, 625,
  117308. _vq_lengthlist__44c5_s_p2_0,
  117309. 1, -533725184, 1611661312, 3, 0,
  117310. _vq_quantlist__44c5_s_p2_0,
  117311. NULL,
  117312. &_vq_auxt__44c5_s_p2_0,
  117313. NULL,
  117314. 0
  117315. };
  117316. static long _vq_quantlist__44c5_s_p3_0[] = {
  117317. 2,
  117318. 1,
  117319. 3,
  117320. 0,
  117321. 4,
  117322. };
  117323. static long _vq_lengthlist__44c5_s_p3_0[] = {
  117324. 2, 4, 3, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 6, 6, 0, 0,
  117326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117327. 0, 0, 3, 5, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  117329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117330. 0, 0, 0, 0, 5, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  117331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117363. 0,
  117364. };
  117365. static float _vq_quantthresh__44c5_s_p3_0[] = {
  117366. -1.5, -0.5, 0.5, 1.5,
  117367. };
  117368. static long _vq_quantmap__44c5_s_p3_0[] = {
  117369. 3, 1, 0, 2, 4,
  117370. };
  117371. static encode_aux_threshmatch _vq_auxt__44c5_s_p3_0 = {
  117372. _vq_quantthresh__44c5_s_p3_0,
  117373. _vq_quantmap__44c5_s_p3_0,
  117374. 5,
  117375. 5
  117376. };
  117377. static static_codebook _44c5_s_p3_0 = {
  117378. 4, 625,
  117379. _vq_lengthlist__44c5_s_p3_0,
  117380. 1, -533725184, 1611661312, 3, 0,
  117381. _vq_quantlist__44c5_s_p3_0,
  117382. NULL,
  117383. &_vq_auxt__44c5_s_p3_0,
  117384. NULL,
  117385. 0
  117386. };
  117387. static long _vq_quantlist__44c5_s_p4_0[] = {
  117388. 4,
  117389. 3,
  117390. 5,
  117391. 2,
  117392. 6,
  117393. 1,
  117394. 7,
  117395. 0,
  117396. 8,
  117397. };
  117398. static long _vq_lengthlist__44c5_s_p4_0[] = {
  117399. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  117400. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  117401. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  117402. 7, 7, 0, 0, 0, 0, 0, 0, 0, 8, 7, 0, 0, 0, 0, 0,
  117403. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117404. 0,
  117405. };
  117406. static float _vq_quantthresh__44c5_s_p4_0[] = {
  117407. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117408. };
  117409. static long _vq_quantmap__44c5_s_p4_0[] = {
  117410. 7, 5, 3, 1, 0, 2, 4, 6,
  117411. 8,
  117412. };
  117413. static encode_aux_threshmatch _vq_auxt__44c5_s_p4_0 = {
  117414. _vq_quantthresh__44c5_s_p4_0,
  117415. _vq_quantmap__44c5_s_p4_0,
  117416. 9,
  117417. 9
  117418. };
  117419. static static_codebook _44c5_s_p4_0 = {
  117420. 2, 81,
  117421. _vq_lengthlist__44c5_s_p4_0,
  117422. 1, -531628032, 1611661312, 4, 0,
  117423. _vq_quantlist__44c5_s_p4_0,
  117424. NULL,
  117425. &_vq_auxt__44c5_s_p4_0,
  117426. NULL,
  117427. 0
  117428. };
  117429. static long _vq_quantlist__44c5_s_p5_0[] = {
  117430. 4,
  117431. 3,
  117432. 5,
  117433. 2,
  117434. 6,
  117435. 1,
  117436. 7,
  117437. 0,
  117438. 8,
  117439. };
  117440. static long _vq_lengthlist__44c5_s_p5_0[] = {
  117441. 2, 4, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  117442. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  117443. 7, 7, 9, 9, 0, 0, 0, 7, 6, 7, 7, 9, 9, 0, 0, 0,
  117444. 8, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  117445. 0, 0, 9, 9, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  117446. 10,
  117447. };
  117448. static float _vq_quantthresh__44c5_s_p5_0[] = {
  117449. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117450. };
  117451. static long _vq_quantmap__44c5_s_p5_0[] = {
  117452. 7, 5, 3, 1, 0, 2, 4, 6,
  117453. 8,
  117454. };
  117455. static encode_aux_threshmatch _vq_auxt__44c5_s_p5_0 = {
  117456. _vq_quantthresh__44c5_s_p5_0,
  117457. _vq_quantmap__44c5_s_p5_0,
  117458. 9,
  117459. 9
  117460. };
  117461. static static_codebook _44c5_s_p5_0 = {
  117462. 2, 81,
  117463. _vq_lengthlist__44c5_s_p5_0,
  117464. 1, -531628032, 1611661312, 4, 0,
  117465. _vq_quantlist__44c5_s_p5_0,
  117466. NULL,
  117467. &_vq_auxt__44c5_s_p5_0,
  117468. NULL,
  117469. 0
  117470. };
  117471. static long _vq_quantlist__44c5_s_p6_0[] = {
  117472. 8,
  117473. 7,
  117474. 9,
  117475. 6,
  117476. 10,
  117477. 5,
  117478. 11,
  117479. 4,
  117480. 12,
  117481. 3,
  117482. 13,
  117483. 2,
  117484. 14,
  117485. 1,
  117486. 15,
  117487. 0,
  117488. 16,
  117489. };
  117490. static long _vq_lengthlist__44c5_s_p6_0[] = {
  117491. 2, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,11,
  117492. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  117493. 12,12, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  117494. 11,12,12, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  117495. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  117496. 10,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  117497. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 9,10,10,10,
  117498. 10,11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,
  117499. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  117500. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  117501. 10,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9,
  117502. 9, 9,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  117503. 10,10,10,10,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  117504. 0, 0, 0,10,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  117505. 0, 0, 0, 0,11,11,11,11,12,12,12,13,13,13, 0, 0,
  117506. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  117507. 0, 0, 0, 0, 0, 0,12,12,12,12,13,12,13,13,13,13,
  117508. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  117509. 13,
  117510. };
  117511. static float _vq_quantthresh__44c5_s_p6_0[] = {
  117512. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  117513. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  117514. };
  117515. static long _vq_quantmap__44c5_s_p6_0[] = {
  117516. 15, 13, 11, 9, 7, 5, 3, 1,
  117517. 0, 2, 4, 6, 8, 10, 12, 14,
  117518. 16,
  117519. };
  117520. static encode_aux_threshmatch _vq_auxt__44c5_s_p6_0 = {
  117521. _vq_quantthresh__44c5_s_p6_0,
  117522. _vq_quantmap__44c5_s_p6_0,
  117523. 17,
  117524. 17
  117525. };
  117526. static static_codebook _44c5_s_p6_0 = {
  117527. 2, 289,
  117528. _vq_lengthlist__44c5_s_p6_0,
  117529. 1, -529530880, 1611661312, 5, 0,
  117530. _vq_quantlist__44c5_s_p6_0,
  117531. NULL,
  117532. &_vq_auxt__44c5_s_p6_0,
  117533. NULL,
  117534. 0
  117535. };
  117536. static long _vq_quantlist__44c5_s_p7_0[] = {
  117537. 1,
  117538. 0,
  117539. 2,
  117540. };
  117541. static long _vq_lengthlist__44c5_s_p7_0[] = {
  117542. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  117543. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  117544. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  117545. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  117546. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  117547. 10,
  117548. };
  117549. static float _vq_quantthresh__44c5_s_p7_0[] = {
  117550. -5.5, 5.5,
  117551. };
  117552. static long _vq_quantmap__44c5_s_p7_0[] = {
  117553. 1, 0, 2,
  117554. };
  117555. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_0 = {
  117556. _vq_quantthresh__44c5_s_p7_0,
  117557. _vq_quantmap__44c5_s_p7_0,
  117558. 3,
  117559. 3
  117560. };
  117561. static static_codebook _44c5_s_p7_0 = {
  117562. 4, 81,
  117563. _vq_lengthlist__44c5_s_p7_0,
  117564. 1, -529137664, 1618345984, 2, 0,
  117565. _vq_quantlist__44c5_s_p7_0,
  117566. NULL,
  117567. &_vq_auxt__44c5_s_p7_0,
  117568. NULL,
  117569. 0
  117570. };
  117571. static long _vq_quantlist__44c5_s_p7_1[] = {
  117572. 5,
  117573. 4,
  117574. 6,
  117575. 3,
  117576. 7,
  117577. 2,
  117578. 8,
  117579. 1,
  117580. 9,
  117581. 0,
  117582. 10,
  117583. };
  117584. static long _vq_lengthlist__44c5_s_p7_1[] = {
  117585. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6,
  117586. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  117587. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  117588. 7, 8, 8, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  117589. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  117590. 8, 8, 8, 8, 8, 8, 8, 9,10,10,10,10,10, 8, 8, 8,
  117591. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  117592. 10,10,10, 8, 8, 8, 8, 8, 8,
  117593. };
  117594. static float _vq_quantthresh__44c5_s_p7_1[] = {
  117595. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  117596. 3.5, 4.5,
  117597. };
  117598. static long _vq_quantmap__44c5_s_p7_1[] = {
  117599. 9, 7, 5, 3, 1, 0, 2, 4,
  117600. 6, 8, 10,
  117601. };
  117602. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_1 = {
  117603. _vq_quantthresh__44c5_s_p7_1,
  117604. _vq_quantmap__44c5_s_p7_1,
  117605. 11,
  117606. 11
  117607. };
  117608. static static_codebook _44c5_s_p7_1 = {
  117609. 2, 121,
  117610. _vq_lengthlist__44c5_s_p7_1,
  117611. 1, -531365888, 1611661312, 4, 0,
  117612. _vq_quantlist__44c5_s_p7_1,
  117613. NULL,
  117614. &_vq_auxt__44c5_s_p7_1,
  117615. NULL,
  117616. 0
  117617. };
  117618. static long _vq_quantlist__44c5_s_p8_0[] = {
  117619. 6,
  117620. 5,
  117621. 7,
  117622. 4,
  117623. 8,
  117624. 3,
  117625. 9,
  117626. 2,
  117627. 10,
  117628. 1,
  117629. 11,
  117630. 0,
  117631. 12,
  117632. };
  117633. static long _vq_lengthlist__44c5_s_p8_0[] = {
  117634. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  117635. 7, 7, 8, 8, 8, 9,10,10,10,10, 7, 5, 5, 7, 7, 8,
  117636. 8, 9, 9,10,10,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  117637. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  117638. 11, 0,12,12, 9, 9, 9,10,10,10,10,10,11,11, 0,13,
  117639. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  117640. 10,10,10,10,11,11,11,11, 0, 0, 0,10,10,10,10,10,
  117641. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  117642. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,12, 0,
  117643. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  117644. 0,12,12,12,12,12,12,13,13,
  117645. };
  117646. static float _vq_quantthresh__44c5_s_p8_0[] = {
  117647. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  117648. 12.5, 17.5, 22.5, 27.5,
  117649. };
  117650. static long _vq_quantmap__44c5_s_p8_0[] = {
  117651. 11, 9, 7, 5, 3, 1, 0, 2,
  117652. 4, 6, 8, 10, 12,
  117653. };
  117654. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_0 = {
  117655. _vq_quantthresh__44c5_s_p8_0,
  117656. _vq_quantmap__44c5_s_p8_0,
  117657. 13,
  117658. 13
  117659. };
  117660. static static_codebook _44c5_s_p8_0 = {
  117661. 2, 169,
  117662. _vq_lengthlist__44c5_s_p8_0,
  117663. 1, -526516224, 1616117760, 4, 0,
  117664. _vq_quantlist__44c5_s_p8_0,
  117665. NULL,
  117666. &_vq_auxt__44c5_s_p8_0,
  117667. NULL,
  117668. 0
  117669. };
  117670. static long _vq_quantlist__44c5_s_p8_1[] = {
  117671. 2,
  117672. 1,
  117673. 3,
  117674. 0,
  117675. 4,
  117676. };
  117677. static long _vq_lengthlist__44c5_s_p8_1[] = {
  117678. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  117679. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  117680. };
  117681. static float _vq_quantthresh__44c5_s_p8_1[] = {
  117682. -1.5, -0.5, 0.5, 1.5,
  117683. };
  117684. static long _vq_quantmap__44c5_s_p8_1[] = {
  117685. 3, 1, 0, 2, 4,
  117686. };
  117687. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_1 = {
  117688. _vq_quantthresh__44c5_s_p8_1,
  117689. _vq_quantmap__44c5_s_p8_1,
  117690. 5,
  117691. 5
  117692. };
  117693. static static_codebook _44c5_s_p8_1 = {
  117694. 2, 25,
  117695. _vq_lengthlist__44c5_s_p8_1,
  117696. 1, -533725184, 1611661312, 3, 0,
  117697. _vq_quantlist__44c5_s_p8_1,
  117698. NULL,
  117699. &_vq_auxt__44c5_s_p8_1,
  117700. NULL,
  117701. 0
  117702. };
  117703. static long _vq_quantlist__44c5_s_p9_0[] = {
  117704. 7,
  117705. 6,
  117706. 8,
  117707. 5,
  117708. 9,
  117709. 4,
  117710. 10,
  117711. 3,
  117712. 11,
  117713. 2,
  117714. 12,
  117715. 1,
  117716. 13,
  117717. 0,
  117718. 14,
  117719. };
  117720. static long _vq_lengthlist__44c5_s_p9_0[] = {
  117721. 1, 3, 3,13,13,13,13,13,13,13,13,13,13,13,13, 4,
  117722. 7, 7,13,13,13,13,13,13,13,13,13,13,13,13, 3, 8,
  117723. 6,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117724. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117725. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117726. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117727. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117728. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117729. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117730. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117731. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117732. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117733. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117734. 13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,
  117735. 12,
  117736. };
  117737. static float _vq_quantthresh__44c5_s_p9_0[] = {
  117738. -2320.5, -1963.5, -1606.5, -1249.5, -892.5, -535.5, -178.5, 178.5,
  117739. 535.5, 892.5, 1249.5, 1606.5, 1963.5, 2320.5,
  117740. };
  117741. static long _vq_quantmap__44c5_s_p9_0[] = {
  117742. 13, 11, 9, 7, 5, 3, 1, 0,
  117743. 2, 4, 6, 8, 10, 12, 14,
  117744. };
  117745. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_0 = {
  117746. _vq_quantthresh__44c5_s_p9_0,
  117747. _vq_quantmap__44c5_s_p9_0,
  117748. 15,
  117749. 15
  117750. };
  117751. static static_codebook _44c5_s_p9_0 = {
  117752. 2, 225,
  117753. _vq_lengthlist__44c5_s_p9_0,
  117754. 1, -512522752, 1628852224, 4, 0,
  117755. _vq_quantlist__44c5_s_p9_0,
  117756. NULL,
  117757. &_vq_auxt__44c5_s_p9_0,
  117758. NULL,
  117759. 0
  117760. };
  117761. static long _vq_quantlist__44c5_s_p9_1[] = {
  117762. 8,
  117763. 7,
  117764. 9,
  117765. 6,
  117766. 10,
  117767. 5,
  117768. 11,
  117769. 4,
  117770. 12,
  117771. 3,
  117772. 13,
  117773. 2,
  117774. 14,
  117775. 1,
  117776. 15,
  117777. 0,
  117778. 16,
  117779. };
  117780. static long _vq_lengthlist__44c5_s_p9_1[] = {
  117781. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,11,10,11,
  117782. 11, 6, 5, 5, 7, 7, 8, 9,10,10,11,10,12,11,12,11,
  117783. 13,12, 6, 5, 5, 7, 7, 9, 9,10,10,11,11,12,12,13,
  117784. 12,13,13,18, 8, 8, 8, 8, 9, 9,10,11,11,11,12,11,
  117785. 13,11,13,12,18, 8, 8, 8, 8,10,10,11,11,12,12,13,
  117786. 13,13,13,13,14,18,12,12, 9, 9,11,11,11,11,12,12,
  117787. 13,12,13,12,13,13,20,13,12, 9, 9,11,11,11,11,12,
  117788. 12,13,13,13,14,14,13,20,18,19,11,12,11,11,12,12,
  117789. 13,13,13,13,13,13,14,13,18,19,19,12,11,11,11,12,
  117790. 12,13,12,13,13,13,14,14,13,18,17,19,14,15,12,12,
  117791. 12,13,13,13,14,14,14,14,14,14,19,19,19,16,15,12,
  117792. 11,13,12,14,14,14,13,13,14,14,14,19,18,19,18,19,
  117793. 13,13,13,13,14,14,14,13,14,14,14,14,18,17,19,19,
  117794. 19,13,13,13,11,13,11,13,14,14,14,14,14,19,17,17,
  117795. 18,18,16,16,13,13,13,13,14,13,15,15,14,14,19,19,
  117796. 17,17,18,16,16,13,11,14,10,13,12,14,14,14,14,19,
  117797. 19,19,19,19,18,17,13,14,13,11,14,13,14,14,15,15,
  117798. 19,19,19,17,19,18,18,14,13,12,11,14,11,15,15,15,
  117799. 15,
  117800. };
  117801. static float _vq_quantthresh__44c5_s_p9_1[] = {
  117802. -157.5, -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5,
  117803. 10.5, 31.5, 52.5, 73.5, 94.5, 115.5, 136.5, 157.5,
  117804. };
  117805. static long _vq_quantmap__44c5_s_p9_1[] = {
  117806. 15, 13, 11, 9, 7, 5, 3, 1,
  117807. 0, 2, 4, 6, 8, 10, 12, 14,
  117808. 16,
  117809. };
  117810. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_1 = {
  117811. _vq_quantthresh__44c5_s_p9_1,
  117812. _vq_quantmap__44c5_s_p9_1,
  117813. 17,
  117814. 17
  117815. };
  117816. static static_codebook _44c5_s_p9_1 = {
  117817. 2, 289,
  117818. _vq_lengthlist__44c5_s_p9_1,
  117819. 1, -520814592, 1620377600, 5, 0,
  117820. _vq_quantlist__44c5_s_p9_1,
  117821. NULL,
  117822. &_vq_auxt__44c5_s_p9_1,
  117823. NULL,
  117824. 0
  117825. };
  117826. static long _vq_quantlist__44c5_s_p9_2[] = {
  117827. 10,
  117828. 9,
  117829. 11,
  117830. 8,
  117831. 12,
  117832. 7,
  117833. 13,
  117834. 6,
  117835. 14,
  117836. 5,
  117837. 15,
  117838. 4,
  117839. 16,
  117840. 3,
  117841. 17,
  117842. 2,
  117843. 18,
  117844. 1,
  117845. 19,
  117846. 0,
  117847. 20,
  117848. };
  117849. static long _vq_lengthlist__44c5_s_p9_2[] = {
  117850. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  117851. 8, 8, 8, 8, 9,11, 5, 6, 7, 7, 8, 7, 8, 8, 8, 8,
  117852. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11, 5, 5, 7, 7, 7,
  117853. 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  117854. 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  117855. 9,10, 9,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  117856. 9, 9, 9,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  117857. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,11,11,
  117858. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  117859. 10,10,10,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  117860. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  117861. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,11,11,11,
  117862. 11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,
  117863. 10,10,11,11,11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,
  117864. 10,10,10,10,10,10,10,11,11,11,11,11, 9, 9,10, 9,
  117865. 10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,
  117866. 11,11,11, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  117867. 10,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  117868. 10,10,10,10,10,10,11,11,11,11,11,11,11,10,10,10,
  117869. 10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,
  117870. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  117871. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  117872. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  117873. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  117874. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,11,
  117875. 11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  117876. 10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,10,
  117877. 10,10,10,10,10,10,10,10,10,
  117878. };
  117879. static float _vq_quantthresh__44c5_s_p9_2[] = {
  117880. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  117881. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  117882. 6.5, 7.5, 8.5, 9.5,
  117883. };
  117884. static long _vq_quantmap__44c5_s_p9_2[] = {
  117885. 19, 17, 15, 13, 11, 9, 7, 5,
  117886. 3, 1, 0, 2, 4, 6, 8, 10,
  117887. 12, 14, 16, 18, 20,
  117888. };
  117889. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_2 = {
  117890. _vq_quantthresh__44c5_s_p9_2,
  117891. _vq_quantmap__44c5_s_p9_2,
  117892. 21,
  117893. 21
  117894. };
  117895. static static_codebook _44c5_s_p9_2 = {
  117896. 2, 441,
  117897. _vq_lengthlist__44c5_s_p9_2,
  117898. 1, -529268736, 1611661312, 5, 0,
  117899. _vq_quantlist__44c5_s_p9_2,
  117900. NULL,
  117901. &_vq_auxt__44c5_s_p9_2,
  117902. NULL,
  117903. 0
  117904. };
  117905. static long _huff_lengthlist__44c5_s_short[] = {
  117906. 5, 8,10,14,11,11,12,16,15,17, 5, 5, 7, 9, 7, 8,
  117907. 10,13,17,17, 7, 5, 5,10, 5, 7, 8,11,13,15,10, 8,
  117908. 10, 8, 8, 8,11,15,18,18, 8, 5, 5, 8, 3, 4, 6,10,
  117909. 14,16, 9, 7, 6, 7, 4, 3, 5, 9,14,18,10, 9, 8,10,
  117910. 6, 5, 6, 9,14,18,12,12,11,12, 8, 7, 8,11,14,18,
  117911. 14,13,12,10, 7, 5, 6, 9,14,18,14,14,13,10, 6, 5,
  117912. 6, 8,11,16,
  117913. };
  117914. static static_codebook _huff_book__44c5_s_short = {
  117915. 2, 100,
  117916. _huff_lengthlist__44c5_s_short,
  117917. 0, 0, 0, 0, 0,
  117918. NULL,
  117919. NULL,
  117920. NULL,
  117921. NULL,
  117922. 0
  117923. };
  117924. static long _huff_lengthlist__44c6_s_long[] = {
  117925. 3, 8,11,13,14,14,13,13,16,14, 6, 3, 4, 7, 9, 9,
  117926. 10,11,14,13,10, 4, 3, 5, 7, 7, 9,10,13,15,12, 7,
  117927. 4, 4, 6, 6, 8,10,13,15,12, 8, 6, 6, 6, 6, 8,10,
  117928. 13,14,11, 9, 7, 6, 6, 6, 7, 8,12,11,13,10, 9, 8,
  117929. 7, 6, 6, 7,11,11,13,11,10, 9, 9, 7, 7, 6,10,11,
  117930. 13,13,13,13,13,11, 9, 8,10,12,12,15,15,16,15,12,
  117931. 11,10,10,12,
  117932. };
  117933. static static_codebook _huff_book__44c6_s_long = {
  117934. 2, 100,
  117935. _huff_lengthlist__44c6_s_long,
  117936. 0, 0, 0, 0, 0,
  117937. NULL,
  117938. NULL,
  117939. NULL,
  117940. NULL,
  117941. 0
  117942. };
  117943. static long _vq_quantlist__44c6_s_p1_0[] = {
  117944. 1,
  117945. 0,
  117946. 2,
  117947. };
  117948. static long _vq_lengthlist__44c6_s_p1_0[] = {
  117949. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  117950. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  117951. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  117952. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  117953. 9, 9, 0, 8, 8, 0, 8, 8, 5, 9, 9, 0, 8, 8, 0, 8,
  117954. 8,
  117955. };
  117956. static float _vq_quantthresh__44c6_s_p1_0[] = {
  117957. -0.5, 0.5,
  117958. };
  117959. static long _vq_quantmap__44c6_s_p1_0[] = {
  117960. 1, 0, 2,
  117961. };
  117962. static encode_aux_threshmatch _vq_auxt__44c6_s_p1_0 = {
  117963. _vq_quantthresh__44c6_s_p1_0,
  117964. _vq_quantmap__44c6_s_p1_0,
  117965. 3,
  117966. 3
  117967. };
  117968. static static_codebook _44c6_s_p1_0 = {
  117969. 4, 81,
  117970. _vq_lengthlist__44c6_s_p1_0,
  117971. 1, -535822336, 1611661312, 2, 0,
  117972. _vq_quantlist__44c6_s_p1_0,
  117973. NULL,
  117974. &_vq_auxt__44c6_s_p1_0,
  117975. NULL,
  117976. 0
  117977. };
  117978. static long _vq_quantlist__44c6_s_p2_0[] = {
  117979. 2,
  117980. 1,
  117981. 3,
  117982. 0,
  117983. 4,
  117984. };
  117985. static long _vq_lengthlist__44c6_s_p2_0[] = {
  117986. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  117987. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  117988. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  117989. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  117990. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,11,
  117991. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  117992. 0, 0,14,13, 8, 9, 9,11,11, 0,11,11,12,12, 0,10,
  117993. 11,12,12, 0,14,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  117994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117995. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  117996. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  117997. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  117998. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  117999. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  118000. 13, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,12,12,
  118001. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  118002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118003. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  118004. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,11,
  118005. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,11,
  118006. 0, 0, 0,10,11, 8,10,10,12,12, 0,10,10,12,12, 0,
  118007. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,14,13, 8,10,
  118008. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  118009. 13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118011. 7,10,10,14,13, 0, 9, 9,13,12, 0, 9, 9,12,12, 0,
  118012. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  118013. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  118014. 12,12, 9,11,11,14,13, 0,11,10,14,13, 0,11,11,13,
  118015. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  118016. 0,10,11,13,14, 0,11,11,13,13, 0,12,12,13,13, 0,
  118017. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  118022. 11,11,14,14, 0,11,11,13,13, 0,11,10,13,13, 0,12,
  118023. 12,13,13, 0, 0, 0,13,13, 9,11,11,14,14, 0,11,11,
  118024. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  118025. 13,
  118026. };
  118027. static float _vq_quantthresh__44c6_s_p2_0[] = {
  118028. -1.5, -0.5, 0.5, 1.5,
  118029. };
  118030. static long _vq_quantmap__44c6_s_p2_0[] = {
  118031. 3, 1, 0, 2, 4,
  118032. };
  118033. static encode_aux_threshmatch _vq_auxt__44c6_s_p2_0 = {
  118034. _vq_quantthresh__44c6_s_p2_0,
  118035. _vq_quantmap__44c6_s_p2_0,
  118036. 5,
  118037. 5
  118038. };
  118039. static static_codebook _44c6_s_p2_0 = {
  118040. 4, 625,
  118041. _vq_lengthlist__44c6_s_p2_0,
  118042. 1, -533725184, 1611661312, 3, 0,
  118043. _vq_quantlist__44c6_s_p2_0,
  118044. NULL,
  118045. &_vq_auxt__44c6_s_p2_0,
  118046. NULL,
  118047. 0
  118048. };
  118049. static long _vq_quantlist__44c6_s_p3_0[] = {
  118050. 4,
  118051. 3,
  118052. 5,
  118053. 2,
  118054. 6,
  118055. 1,
  118056. 7,
  118057. 0,
  118058. 8,
  118059. };
  118060. static long _vq_lengthlist__44c6_s_p3_0[] = {
  118061. 2, 3, 4, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  118062. 9,10, 0, 4, 4, 6, 6, 7, 7,10, 9, 0, 5, 5, 7, 7,
  118063. 8, 8,10,10, 0, 0, 0, 7, 6, 8, 8,10,10, 0, 0, 0,
  118064. 7, 7, 9, 9,11,11, 0, 0, 0, 7, 7, 9, 9,11,11, 0,
  118065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118066. 0,
  118067. };
  118068. static float _vq_quantthresh__44c6_s_p3_0[] = {
  118069. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  118070. };
  118071. static long _vq_quantmap__44c6_s_p3_0[] = {
  118072. 7, 5, 3, 1, 0, 2, 4, 6,
  118073. 8,
  118074. };
  118075. static encode_aux_threshmatch _vq_auxt__44c6_s_p3_0 = {
  118076. _vq_quantthresh__44c6_s_p3_0,
  118077. _vq_quantmap__44c6_s_p3_0,
  118078. 9,
  118079. 9
  118080. };
  118081. static static_codebook _44c6_s_p3_0 = {
  118082. 2, 81,
  118083. _vq_lengthlist__44c6_s_p3_0,
  118084. 1, -531628032, 1611661312, 4, 0,
  118085. _vq_quantlist__44c6_s_p3_0,
  118086. NULL,
  118087. &_vq_auxt__44c6_s_p3_0,
  118088. NULL,
  118089. 0
  118090. };
  118091. static long _vq_quantlist__44c6_s_p4_0[] = {
  118092. 8,
  118093. 7,
  118094. 9,
  118095. 6,
  118096. 10,
  118097. 5,
  118098. 11,
  118099. 4,
  118100. 12,
  118101. 3,
  118102. 13,
  118103. 2,
  118104. 14,
  118105. 1,
  118106. 15,
  118107. 0,
  118108. 16,
  118109. };
  118110. static long _vq_lengthlist__44c6_s_p4_0[] = {
  118111. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,10,10,
  118112. 10, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  118113. 11,11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  118114. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  118115. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  118116. 10,11,11,11,11, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  118117. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,
  118118. 10,11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  118119. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  118120. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  118121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118129. 0,
  118130. };
  118131. static float _vq_quantthresh__44c6_s_p4_0[] = {
  118132. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118133. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118134. };
  118135. static long _vq_quantmap__44c6_s_p4_0[] = {
  118136. 15, 13, 11, 9, 7, 5, 3, 1,
  118137. 0, 2, 4, 6, 8, 10, 12, 14,
  118138. 16,
  118139. };
  118140. static encode_aux_threshmatch _vq_auxt__44c6_s_p4_0 = {
  118141. _vq_quantthresh__44c6_s_p4_0,
  118142. _vq_quantmap__44c6_s_p4_0,
  118143. 17,
  118144. 17
  118145. };
  118146. static static_codebook _44c6_s_p4_0 = {
  118147. 2, 289,
  118148. _vq_lengthlist__44c6_s_p4_0,
  118149. 1, -529530880, 1611661312, 5, 0,
  118150. _vq_quantlist__44c6_s_p4_0,
  118151. NULL,
  118152. &_vq_auxt__44c6_s_p4_0,
  118153. NULL,
  118154. 0
  118155. };
  118156. static long _vq_quantlist__44c6_s_p5_0[] = {
  118157. 1,
  118158. 0,
  118159. 2,
  118160. };
  118161. static long _vq_lengthlist__44c6_s_p5_0[] = {
  118162. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6, 9, 9,10,10,
  118163. 10, 9, 4, 6, 6, 9,10, 9,10, 9,10, 6, 9, 9,10,12,
  118164. 11,10,11,11, 7,10, 9,11,12,12,12,12,12, 7,10,10,
  118165. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  118166. 9,10,11,12,12,12,12,12, 7,10, 9,12,12,12,12,12,
  118167. 12,
  118168. };
  118169. static float _vq_quantthresh__44c6_s_p5_0[] = {
  118170. -5.5, 5.5,
  118171. };
  118172. static long _vq_quantmap__44c6_s_p5_0[] = {
  118173. 1, 0, 2,
  118174. };
  118175. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_0 = {
  118176. _vq_quantthresh__44c6_s_p5_0,
  118177. _vq_quantmap__44c6_s_p5_0,
  118178. 3,
  118179. 3
  118180. };
  118181. static static_codebook _44c6_s_p5_0 = {
  118182. 4, 81,
  118183. _vq_lengthlist__44c6_s_p5_0,
  118184. 1, -529137664, 1618345984, 2, 0,
  118185. _vq_quantlist__44c6_s_p5_0,
  118186. NULL,
  118187. &_vq_auxt__44c6_s_p5_0,
  118188. NULL,
  118189. 0
  118190. };
  118191. static long _vq_quantlist__44c6_s_p5_1[] = {
  118192. 5,
  118193. 4,
  118194. 6,
  118195. 3,
  118196. 7,
  118197. 2,
  118198. 8,
  118199. 1,
  118200. 9,
  118201. 0,
  118202. 10,
  118203. };
  118204. static long _vq_lengthlist__44c6_s_p5_1[] = {
  118205. 3, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  118206. 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6, 7, 7, 8, 8, 8,
  118207. 8,11, 6, 6, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  118208. 6, 7, 8, 8, 8, 8, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  118209. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 8,11,11,11,
  118210. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,10,10, 8, 8, 8,
  118211. 8, 8, 8,11,11,11,10,10, 8, 8, 8, 8, 8, 8,11,11,
  118212. 11,10,10, 7, 7, 8, 8, 8, 8,
  118213. };
  118214. static float _vq_quantthresh__44c6_s_p5_1[] = {
  118215. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118216. 3.5, 4.5,
  118217. };
  118218. static long _vq_quantmap__44c6_s_p5_1[] = {
  118219. 9, 7, 5, 3, 1, 0, 2, 4,
  118220. 6, 8, 10,
  118221. };
  118222. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_1 = {
  118223. _vq_quantthresh__44c6_s_p5_1,
  118224. _vq_quantmap__44c6_s_p5_1,
  118225. 11,
  118226. 11
  118227. };
  118228. static static_codebook _44c6_s_p5_1 = {
  118229. 2, 121,
  118230. _vq_lengthlist__44c6_s_p5_1,
  118231. 1, -531365888, 1611661312, 4, 0,
  118232. _vq_quantlist__44c6_s_p5_1,
  118233. NULL,
  118234. &_vq_auxt__44c6_s_p5_1,
  118235. NULL,
  118236. 0
  118237. };
  118238. static long _vq_quantlist__44c6_s_p6_0[] = {
  118239. 6,
  118240. 5,
  118241. 7,
  118242. 4,
  118243. 8,
  118244. 3,
  118245. 9,
  118246. 2,
  118247. 10,
  118248. 1,
  118249. 11,
  118250. 0,
  118251. 12,
  118252. };
  118253. static long _vq_lengthlist__44c6_s_p6_0[] = {
  118254. 1, 4, 4, 6, 6, 8, 8, 8, 8,10, 9,10,10, 6, 5, 5,
  118255. 7, 7, 9, 9, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 9,
  118256. 9,10, 9,11,10,11,11, 0, 6, 6, 7, 7, 9, 9,10,10,
  118257. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118258. 12, 0,11,11, 8, 8,10,10,11,11,12,12,12,12, 0,11,
  118259. 12, 9, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  118260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118264. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118265. };
  118266. static float _vq_quantthresh__44c6_s_p6_0[] = {
  118267. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  118268. 12.5, 17.5, 22.5, 27.5,
  118269. };
  118270. static long _vq_quantmap__44c6_s_p6_0[] = {
  118271. 11, 9, 7, 5, 3, 1, 0, 2,
  118272. 4, 6, 8, 10, 12,
  118273. };
  118274. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_0 = {
  118275. _vq_quantthresh__44c6_s_p6_0,
  118276. _vq_quantmap__44c6_s_p6_0,
  118277. 13,
  118278. 13
  118279. };
  118280. static static_codebook _44c6_s_p6_0 = {
  118281. 2, 169,
  118282. _vq_lengthlist__44c6_s_p6_0,
  118283. 1, -526516224, 1616117760, 4, 0,
  118284. _vq_quantlist__44c6_s_p6_0,
  118285. NULL,
  118286. &_vq_auxt__44c6_s_p6_0,
  118287. NULL,
  118288. 0
  118289. };
  118290. static long _vq_quantlist__44c6_s_p6_1[] = {
  118291. 2,
  118292. 1,
  118293. 3,
  118294. 0,
  118295. 4,
  118296. };
  118297. static long _vq_lengthlist__44c6_s_p6_1[] = {
  118298. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  118299. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  118300. };
  118301. static float _vq_quantthresh__44c6_s_p6_1[] = {
  118302. -1.5, -0.5, 0.5, 1.5,
  118303. };
  118304. static long _vq_quantmap__44c6_s_p6_1[] = {
  118305. 3, 1, 0, 2, 4,
  118306. };
  118307. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_1 = {
  118308. _vq_quantthresh__44c6_s_p6_1,
  118309. _vq_quantmap__44c6_s_p6_1,
  118310. 5,
  118311. 5
  118312. };
  118313. static static_codebook _44c6_s_p6_1 = {
  118314. 2, 25,
  118315. _vq_lengthlist__44c6_s_p6_1,
  118316. 1, -533725184, 1611661312, 3, 0,
  118317. _vq_quantlist__44c6_s_p6_1,
  118318. NULL,
  118319. &_vq_auxt__44c6_s_p6_1,
  118320. NULL,
  118321. 0
  118322. };
  118323. static long _vq_quantlist__44c6_s_p7_0[] = {
  118324. 6,
  118325. 5,
  118326. 7,
  118327. 4,
  118328. 8,
  118329. 3,
  118330. 9,
  118331. 2,
  118332. 10,
  118333. 1,
  118334. 11,
  118335. 0,
  118336. 12,
  118337. };
  118338. static long _vq_lengthlist__44c6_s_p7_0[] = {
  118339. 1, 4, 4, 6, 6, 8, 8, 8, 8,10,10,11,10, 6, 5, 5,
  118340. 7, 7, 8, 8, 9, 9,10,10,12,11, 6, 5, 5, 7, 7, 8,
  118341. 8, 9, 9,10,10,12,11,21, 7, 7, 7, 7, 9, 9,10,10,
  118342. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118343. 12,21,12,12, 9, 9,10,10,11,11,11,11,12,12,21,12,
  118344. 12, 9, 9,10,10,11,11,12,12,12,12,21,21,21,11,11,
  118345. 10,10,11,12,12,12,13,13,21,21,21,11,11,10,10,12,
  118346. 12,12,12,13,13,21,21,21,15,15,11,11,12,12,13,13,
  118347. 13,13,21,21,21,15,16,11,11,12,12,13,13,14,14,21,
  118348. 21,21,21,20,13,13,13,13,13,13,14,14,20,20,20,20,
  118349. 20,13,13,13,13,13,13,14,14,
  118350. };
  118351. static float _vq_quantthresh__44c6_s_p7_0[] = {
  118352. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  118353. 27.5, 38.5, 49.5, 60.5,
  118354. };
  118355. static long _vq_quantmap__44c6_s_p7_0[] = {
  118356. 11, 9, 7, 5, 3, 1, 0, 2,
  118357. 4, 6, 8, 10, 12,
  118358. };
  118359. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_0 = {
  118360. _vq_quantthresh__44c6_s_p7_0,
  118361. _vq_quantmap__44c6_s_p7_0,
  118362. 13,
  118363. 13
  118364. };
  118365. static static_codebook _44c6_s_p7_0 = {
  118366. 2, 169,
  118367. _vq_lengthlist__44c6_s_p7_0,
  118368. 1, -523206656, 1618345984, 4, 0,
  118369. _vq_quantlist__44c6_s_p7_0,
  118370. NULL,
  118371. &_vq_auxt__44c6_s_p7_0,
  118372. NULL,
  118373. 0
  118374. };
  118375. static long _vq_quantlist__44c6_s_p7_1[] = {
  118376. 5,
  118377. 4,
  118378. 6,
  118379. 3,
  118380. 7,
  118381. 2,
  118382. 8,
  118383. 1,
  118384. 9,
  118385. 0,
  118386. 10,
  118387. };
  118388. static long _vq_lengthlist__44c6_s_p7_1[] = {
  118389. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 9, 5, 5, 6, 6,
  118390. 7, 7, 7, 7, 8, 7, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7,
  118391. 7, 9, 6, 6, 7, 7, 7, 7, 8, 7, 7, 8, 9, 9, 9, 7,
  118392. 7, 7, 7, 7, 7, 7, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  118393. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  118394. 8, 8, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 8, 8, 8, 7,
  118395. 7, 8, 8, 9, 9, 9, 8, 8, 8, 8, 7, 7, 8, 8, 9, 9,
  118396. 9, 8, 8, 7, 7, 7, 7, 8, 8,
  118397. };
  118398. static float _vq_quantthresh__44c6_s_p7_1[] = {
  118399. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118400. 3.5, 4.5,
  118401. };
  118402. static long _vq_quantmap__44c6_s_p7_1[] = {
  118403. 9, 7, 5, 3, 1, 0, 2, 4,
  118404. 6, 8, 10,
  118405. };
  118406. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_1 = {
  118407. _vq_quantthresh__44c6_s_p7_1,
  118408. _vq_quantmap__44c6_s_p7_1,
  118409. 11,
  118410. 11
  118411. };
  118412. static static_codebook _44c6_s_p7_1 = {
  118413. 2, 121,
  118414. _vq_lengthlist__44c6_s_p7_1,
  118415. 1, -531365888, 1611661312, 4, 0,
  118416. _vq_quantlist__44c6_s_p7_1,
  118417. NULL,
  118418. &_vq_auxt__44c6_s_p7_1,
  118419. NULL,
  118420. 0
  118421. };
  118422. static long _vq_quantlist__44c6_s_p8_0[] = {
  118423. 7,
  118424. 6,
  118425. 8,
  118426. 5,
  118427. 9,
  118428. 4,
  118429. 10,
  118430. 3,
  118431. 11,
  118432. 2,
  118433. 12,
  118434. 1,
  118435. 13,
  118436. 0,
  118437. 14,
  118438. };
  118439. static long _vq_lengthlist__44c6_s_p8_0[] = {
  118440. 1, 4, 4, 7, 7, 8, 8, 7, 7, 8, 7, 9, 8,10, 9, 6,
  118441. 5, 5, 8, 8, 9, 9, 8, 8, 9, 9,11,10,11,10, 6, 5,
  118442. 5, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,11,18, 8, 8,
  118443. 9, 8,10,10, 9, 9,10,10,10,10,11,10,18, 8, 8, 9,
  118444. 9,10,10, 9, 9,10,10,11,11,12,12,18,12,13, 9,10,
  118445. 10,10, 9,10,10,10,11,11,12,11,18,13,13, 9, 9,10,
  118446. 10,10,10,10,10,11,11,12,12,18,18,18,10,10, 9, 9,
  118447. 11,11,11,11,11,12,12,12,18,18,18,10, 9,10, 9,11,
  118448. 10,11,11,11,11,13,12,18,18,18,14,13,10,10,11,11,
  118449. 12,12,12,12,12,12,18,18,18,14,13,10,10,11,10,12,
  118450. 12,12,12,12,12,18,18,18,18,18,12,12,11,11,12,12,
  118451. 13,13,13,14,18,18,18,18,18,12,12,11,11,12,11,13,
  118452. 13,14,13,18,18,18,18,18,16,16,11,12,12,13,13,13,
  118453. 14,13,18,18,18,18,18,16,15,12,11,12,11,13,11,15,
  118454. 14,
  118455. };
  118456. static float _vq_quantthresh__44c6_s_p8_0[] = {
  118457. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  118458. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  118459. };
  118460. static long _vq_quantmap__44c6_s_p8_0[] = {
  118461. 13, 11, 9, 7, 5, 3, 1, 0,
  118462. 2, 4, 6, 8, 10, 12, 14,
  118463. };
  118464. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_0 = {
  118465. _vq_quantthresh__44c6_s_p8_0,
  118466. _vq_quantmap__44c6_s_p8_0,
  118467. 15,
  118468. 15
  118469. };
  118470. static static_codebook _44c6_s_p8_0 = {
  118471. 2, 225,
  118472. _vq_lengthlist__44c6_s_p8_0,
  118473. 1, -520986624, 1620377600, 4, 0,
  118474. _vq_quantlist__44c6_s_p8_0,
  118475. NULL,
  118476. &_vq_auxt__44c6_s_p8_0,
  118477. NULL,
  118478. 0
  118479. };
  118480. static long _vq_quantlist__44c6_s_p8_1[] = {
  118481. 10,
  118482. 9,
  118483. 11,
  118484. 8,
  118485. 12,
  118486. 7,
  118487. 13,
  118488. 6,
  118489. 14,
  118490. 5,
  118491. 15,
  118492. 4,
  118493. 16,
  118494. 3,
  118495. 17,
  118496. 2,
  118497. 18,
  118498. 1,
  118499. 19,
  118500. 0,
  118501. 20,
  118502. };
  118503. static long _vq_lengthlist__44c6_s_p8_1[] = {
  118504. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  118505. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,
  118506. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  118507. 8, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10,
  118508. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118509. 9, 9, 9, 9,10,11,11, 8, 7, 8, 8, 8, 9, 9, 9, 9,
  118510. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8,
  118511. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,
  118512. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118513. 9, 9, 9,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118514. 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9, 9,
  118515. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,
  118516. 11,11, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9,10, 9, 9,
  118517. 10, 9,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,10,10,
  118518. 10,10, 9,10,10, 9,10,11,11,11,11,11, 9, 9, 9, 9,
  118519. 10,10,10, 9,10,10,10,10, 9,10,10, 9,11,11,11,11,
  118520. 11,11,11, 9, 9, 9, 9,10,10,10,10, 9,10,10,10,10,
  118521. 10,11,11,11,11,11,11,11,10, 9,10,10,10,10,10,10,
  118522. 10, 9,10, 9,10,10,11,11,11,11,11,11,11,10, 9,10,
  118523. 9,10,10, 9,10,10,10,10,10,10,10,11,11,11,11,11,
  118524. 11,11,10,10,10,10,10,10,10, 9,10,10,10,10,10, 9,
  118525. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  118526. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  118527. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  118528. 11,11,11,10,10,10,10,10,10,10,10,10, 9,10,10,11,
  118529. 11,11,11,11,11,11,11,11,10,10,10, 9,10,10,10,10,
  118530. 10,10,10,10,10,11,11,11,11,11,11,11,11,10,11, 9,
  118531. 10,10,10,10,10,10,10,10,10,
  118532. };
  118533. static float _vq_quantthresh__44c6_s_p8_1[] = {
  118534. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  118535. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  118536. 6.5, 7.5, 8.5, 9.5,
  118537. };
  118538. static long _vq_quantmap__44c6_s_p8_1[] = {
  118539. 19, 17, 15, 13, 11, 9, 7, 5,
  118540. 3, 1, 0, 2, 4, 6, 8, 10,
  118541. 12, 14, 16, 18, 20,
  118542. };
  118543. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_1 = {
  118544. _vq_quantthresh__44c6_s_p8_1,
  118545. _vq_quantmap__44c6_s_p8_1,
  118546. 21,
  118547. 21
  118548. };
  118549. static static_codebook _44c6_s_p8_1 = {
  118550. 2, 441,
  118551. _vq_lengthlist__44c6_s_p8_1,
  118552. 1, -529268736, 1611661312, 5, 0,
  118553. _vq_quantlist__44c6_s_p8_1,
  118554. NULL,
  118555. &_vq_auxt__44c6_s_p8_1,
  118556. NULL,
  118557. 0
  118558. };
  118559. static long _vq_quantlist__44c6_s_p9_0[] = {
  118560. 6,
  118561. 5,
  118562. 7,
  118563. 4,
  118564. 8,
  118565. 3,
  118566. 9,
  118567. 2,
  118568. 10,
  118569. 1,
  118570. 11,
  118571. 0,
  118572. 12,
  118573. };
  118574. static long _vq_lengthlist__44c6_s_p9_0[] = {
  118575. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 7, 7,
  118576. 11,11,11,11,11,11,11,11,11,11, 5, 8, 9,11,11,11,
  118577. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  118578. 11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,
  118579. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118580. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118581. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118582. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118583. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118584. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118585. 10,10,10,10,10,10,10,10,10,
  118586. };
  118587. static float _vq_quantthresh__44c6_s_p9_0[] = {
  118588. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  118589. 1592.5, 2229.5, 2866.5, 3503.5,
  118590. };
  118591. static long _vq_quantmap__44c6_s_p9_0[] = {
  118592. 11, 9, 7, 5, 3, 1, 0, 2,
  118593. 4, 6, 8, 10, 12,
  118594. };
  118595. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_0 = {
  118596. _vq_quantthresh__44c6_s_p9_0,
  118597. _vq_quantmap__44c6_s_p9_0,
  118598. 13,
  118599. 13
  118600. };
  118601. static static_codebook _44c6_s_p9_0 = {
  118602. 2, 169,
  118603. _vq_lengthlist__44c6_s_p9_0,
  118604. 1, -511845376, 1630791680, 4, 0,
  118605. _vq_quantlist__44c6_s_p9_0,
  118606. NULL,
  118607. &_vq_auxt__44c6_s_p9_0,
  118608. NULL,
  118609. 0
  118610. };
  118611. static long _vq_quantlist__44c6_s_p9_1[] = {
  118612. 6,
  118613. 5,
  118614. 7,
  118615. 4,
  118616. 8,
  118617. 3,
  118618. 9,
  118619. 2,
  118620. 10,
  118621. 1,
  118622. 11,
  118623. 0,
  118624. 12,
  118625. };
  118626. static long _vq_lengthlist__44c6_s_p9_1[] = {
  118627. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  118628. 8, 8, 8, 8, 8, 7, 9, 8,10,10, 5, 6, 6, 8, 8, 9,
  118629. 9, 8, 8,10,10,10,10,16, 9, 9, 9, 9, 9, 9, 9, 8,
  118630. 10, 9,11,11,16, 8, 9, 9, 9, 9, 9, 9, 9,10,10,11,
  118631. 11,16,13,13, 9, 9,10, 9, 9,10,11,11,11,12,16,13,
  118632. 14, 9, 8,10, 8, 9, 9,10,10,12,11,16,14,16, 9, 9,
  118633. 9, 9,11,11,12,11,12,11,16,16,16, 9, 7, 9, 6,11,
  118634. 11,11,10,11,11,16,16,16,11,12, 9,10,11,11,12,11,
  118635. 13,13,16,16,16,12,11,10, 7,12,10,12,12,12,12,16,
  118636. 16,15,16,16,10,11,10,11,13,13,14,12,16,16,16,15,
  118637. 15,12,10,11,11,13,11,12,13,
  118638. };
  118639. static float _vq_quantthresh__44c6_s_p9_1[] = {
  118640. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  118641. 122.5, 171.5, 220.5, 269.5,
  118642. };
  118643. static long _vq_quantmap__44c6_s_p9_1[] = {
  118644. 11, 9, 7, 5, 3, 1, 0, 2,
  118645. 4, 6, 8, 10, 12,
  118646. };
  118647. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_1 = {
  118648. _vq_quantthresh__44c6_s_p9_1,
  118649. _vq_quantmap__44c6_s_p9_1,
  118650. 13,
  118651. 13
  118652. };
  118653. static static_codebook _44c6_s_p9_1 = {
  118654. 2, 169,
  118655. _vq_lengthlist__44c6_s_p9_1,
  118656. 1, -518889472, 1622704128, 4, 0,
  118657. _vq_quantlist__44c6_s_p9_1,
  118658. NULL,
  118659. &_vq_auxt__44c6_s_p9_1,
  118660. NULL,
  118661. 0
  118662. };
  118663. static long _vq_quantlist__44c6_s_p9_2[] = {
  118664. 24,
  118665. 23,
  118666. 25,
  118667. 22,
  118668. 26,
  118669. 21,
  118670. 27,
  118671. 20,
  118672. 28,
  118673. 19,
  118674. 29,
  118675. 18,
  118676. 30,
  118677. 17,
  118678. 31,
  118679. 16,
  118680. 32,
  118681. 15,
  118682. 33,
  118683. 14,
  118684. 34,
  118685. 13,
  118686. 35,
  118687. 12,
  118688. 36,
  118689. 11,
  118690. 37,
  118691. 10,
  118692. 38,
  118693. 9,
  118694. 39,
  118695. 8,
  118696. 40,
  118697. 7,
  118698. 41,
  118699. 6,
  118700. 42,
  118701. 5,
  118702. 43,
  118703. 4,
  118704. 44,
  118705. 3,
  118706. 45,
  118707. 2,
  118708. 46,
  118709. 1,
  118710. 47,
  118711. 0,
  118712. 48,
  118713. };
  118714. static long _vq_lengthlist__44c6_s_p9_2[] = {
  118715. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  118716. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  118717. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  118718. 7,
  118719. };
  118720. static float _vq_quantthresh__44c6_s_p9_2[] = {
  118721. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  118722. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  118723. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118724. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118725. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  118726. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  118727. };
  118728. static long _vq_quantmap__44c6_s_p9_2[] = {
  118729. 47, 45, 43, 41, 39, 37, 35, 33,
  118730. 31, 29, 27, 25, 23, 21, 19, 17,
  118731. 15, 13, 11, 9, 7, 5, 3, 1,
  118732. 0, 2, 4, 6, 8, 10, 12, 14,
  118733. 16, 18, 20, 22, 24, 26, 28, 30,
  118734. 32, 34, 36, 38, 40, 42, 44, 46,
  118735. 48,
  118736. };
  118737. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_2 = {
  118738. _vq_quantthresh__44c6_s_p9_2,
  118739. _vq_quantmap__44c6_s_p9_2,
  118740. 49,
  118741. 49
  118742. };
  118743. static static_codebook _44c6_s_p9_2 = {
  118744. 1, 49,
  118745. _vq_lengthlist__44c6_s_p9_2,
  118746. 1, -526909440, 1611661312, 6, 0,
  118747. _vq_quantlist__44c6_s_p9_2,
  118748. NULL,
  118749. &_vq_auxt__44c6_s_p9_2,
  118750. NULL,
  118751. 0
  118752. };
  118753. static long _huff_lengthlist__44c6_s_short[] = {
  118754. 3, 9,11,11,13,14,19,17,17,19, 5, 4, 5, 8,10,10,
  118755. 13,16,18,19, 7, 4, 4, 5, 8, 9,12,14,17,19, 8, 6,
  118756. 5, 5, 7, 7,10,13,16,18,10, 8, 7, 6, 5, 5, 8,11,
  118757. 17,19,11, 9, 7, 7, 5, 4, 5, 8,17,19,13,11, 8, 7,
  118758. 7, 5, 5, 7,16,18,14,13, 8, 6, 6, 5, 5, 7,16,18,
  118759. 18,16,10, 8, 8, 7, 7, 9,16,18,18,18,12,10,10, 9,
  118760. 9,10,17,18,
  118761. };
  118762. static static_codebook _huff_book__44c6_s_short = {
  118763. 2, 100,
  118764. _huff_lengthlist__44c6_s_short,
  118765. 0, 0, 0, 0, 0,
  118766. NULL,
  118767. NULL,
  118768. NULL,
  118769. NULL,
  118770. 0
  118771. };
  118772. static long _huff_lengthlist__44c7_s_long[] = {
  118773. 3, 8,11,13,15,14,14,13,15,14, 6, 4, 5, 7, 9,10,
  118774. 11,11,14,13,10, 4, 3, 5, 7, 8, 9,10,13,13,12, 7,
  118775. 4, 4, 5, 6, 8, 9,12,14,13, 9, 6, 5, 5, 6, 8, 9,
  118776. 12,14,12, 9, 7, 6, 5, 5, 6, 8,11,11,12,11, 9, 8,
  118777. 7, 6, 6, 7,10,11,13,11,10, 9, 8, 7, 6, 6, 9,11,
  118778. 13,13,12,12,12,10, 9, 8, 9,11,12,14,15,15,14,12,
  118779. 11,10,10,12,
  118780. };
  118781. static static_codebook _huff_book__44c7_s_long = {
  118782. 2, 100,
  118783. _huff_lengthlist__44c7_s_long,
  118784. 0, 0, 0, 0, 0,
  118785. NULL,
  118786. NULL,
  118787. NULL,
  118788. NULL,
  118789. 0
  118790. };
  118791. static long _vq_quantlist__44c7_s_p1_0[] = {
  118792. 1,
  118793. 0,
  118794. 2,
  118795. };
  118796. static long _vq_lengthlist__44c7_s_p1_0[] = {
  118797. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  118798. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  118799. 0, 0, 0, 0, 5, 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  118800. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  118801. 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  118802. 8,
  118803. };
  118804. static float _vq_quantthresh__44c7_s_p1_0[] = {
  118805. -0.5, 0.5,
  118806. };
  118807. static long _vq_quantmap__44c7_s_p1_0[] = {
  118808. 1, 0, 2,
  118809. };
  118810. static encode_aux_threshmatch _vq_auxt__44c7_s_p1_0 = {
  118811. _vq_quantthresh__44c7_s_p1_0,
  118812. _vq_quantmap__44c7_s_p1_0,
  118813. 3,
  118814. 3
  118815. };
  118816. static static_codebook _44c7_s_p1_0 = {
  118817. 4, 81,
  118818. _vq_lengthlist__44c7_s_p1_0,
  118819. 1, -535822336, 1611661312, 2, 0,
  118820. _vq_quantlist__44c7_s_p1_0,
  118821. NULL,
  118822. &_vq_auxt__44c7_s_p1_0,
  118823. NULL,
  118824. 0
  118825. };
  118826. static long _vq_quantlist__44c7_s_p2_0[] = {
  118827. 2,
  118828. 1,
  118829. 3,
  118830. 0,
  118831. 4,
  118832. };
  118833. static long _vq_lengthlist__44c7_s_p2_0[] = {
  118834. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  118835. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  118836. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  118837. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  118838. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  118839. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  118840. 0, 0,14,13, 8, 9, 9,10,11, 0,11,11,12,12, 0,10,
  118841. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  118842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118843. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  118844. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  118845. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  118846. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  118847. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  118848. 13, 8, 9,10,12,12, 0,10,10,12,12, 0,10,10,11,12,
  118849. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  118850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118851. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  118852. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,10,
  118853. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,10,
  118854. 0, 0, 0,10,11, 9,10,10,12,12, 0,10,10,12,12, 0,
  118855. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,13,12, 9,10,
  118856. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  118857. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118859. 7,10,10,14,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  118860. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  118861. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  118862. 12,12, 9,11,11,14,13, 0,11,10,13,12, 0,11,11,13,
  118863. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  118864. 0,10,11,12,13, 0,11,11,13,13, 0,12,12,13,13, 0,
  118865. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  118870. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,12,
  118871. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  118872. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  118873. 13,
  118874. };
  118875. static float _vq_quantthresh__44c7_s_p2_0[] = {
  118876. -1.5, -0.5, 0.5, 1.5,
  118877. };
  118878. static long _vq_quantmap__44c7_s_p2_0[] = {
  118879. 3, 1, 0, 2, 4,
  118880. };
  118881. static encode_aux_threshmatch _vq_auxt__44c7_s_p2_0 = {
  118882. _vq_quantthresh__44c7_s_p2_0,
  118883. _vq_quantmap__44c7_s_p2_0,
  118884. 5,
  118885. 5
  118886. };
  118887. static static_codebook _44c7_s_p2_0 = {
  118888. 4, 625,
  118889. _vq_lengthlist__44c7_s_p2_0,
  118890. 1, -533725184, 1611661312, 3, 0,
  118891. _vq_quantlist__44c7_s_p2_0,
  118892. NULL,
  118893. &_vq_auxt__44c7_s_p2_0,
  118894. NULL,
  118895. 0
  118896. };
  118897. static long _vq_quantlist__44c7_s_p3_0[] = {
  118898. 4,
  118899. 3,
  118900. 5,
  118901. 2,
  118902. 6,
  118903. 1,
  118904. 7,
  118905. 0,
  118906. 8,
  118907. };
  118908. static long _vq_lengthlist__44c7_s_p3_0[] = {
  118909. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  118910. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  118911. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  118912. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  118913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118914. 0,
  118915. };
  118916. static float _vq_quantthresh__44c7_s_p3_0[] = {
  118917. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  118918. };
  118919. static long _vq_quantmap__44c7_s_p3_0[] = {
  118920. 7, 5, 3, 1, 0, 2, 4, 6,
  118921. 8,
  118922. };
  118923. static encode_aux_threshmatch _vq_auxt__44c7_s_p3_0 = {
  118924. _vq_quantthresh__44c7_s_p3_0,
  118925. _vq_quantmap__44c7_s_p3_0,
  118926. 9,
  118927. 9
  118928. };
  118929. static static_codebook _44c7_s_p3_0 = {
  118930. 2, 81,
  118931. _vq_lengthlist__44c7_s_p3_0,
  118932. 1, -531628032, 1611661312, 4, 0,
  118933. _vq_quantlist__44c7_s_p3_0,
  118934. NULL,
  118935. &_vq_auxt__44c7_s_p3_0,
  118936. NULL,
  118937. 0
  118938. };
  118939. static long _vq_quantlist__44c7_s_p4_0[] = {
  118940. 8,
  118941. 7,
  118942. 9,
  118943. 6,
  118944. 10,
  118945. 5,
  118946. 11,
  118947. 4,
  118948. 12,
  118949. 3,
  118950. 13,
  118951. 2,
  118952. 14,
  118953. 1,
  118954. 15,
  118955. 0,
  118956. 16,
  118957. };
  118958. static long _vq_lengthlist__44c7_s_p4_0[] = {
  118959. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  118960. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  118961. 12,12, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  118962. 11,12,12, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,
  118963. 11,12,12,12, 0, 0, 0, 6, 6, 8, 7, 9, 9, 9, 9,10,
  118964. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  118965. 11,11,12,12,13,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  118966. 10,11,11,12,12,12,13, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  118967. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  118968. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  118969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118977. 0,
  118978. };
  118979. static float _vq_quantthresh__44c7_s_p4_0[] = {
  118980. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118981. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118982. };
  118983. static long _vq_quantmap__44c7_s_p4_0[] = {
  118984. 15, 13, 11, 9, 7, 5, 3, 1,
  118985. 0, 2, 4, 6, 8, 10, 12, 14,
  118986. 16,
  118987. };
  118988. static encode_aux_threshmatch _vq_auxt__44c7_s_p4_0 = {
  118989. _vq_quantthresh__44c7_s_p4_0,
  118990. _vq_quantmap__44c7_s_p4_0,
  118991. 17,
  118992. 17
  118993. };
  118994. static static_codebook _44c7_s_p4_0 = {
  118995. 2, 289,
  118996. _vq_lengthlist__44c7_s_p4_0,
  118997. 1, -529530880, 1611661312, 5, 0,
  118998. _vq_quantlist__44c7_s_p4_0,
  118999. NULL,
  119000. &_vq_auxt__44c7_s_p4_0,
  119001. NULL,
  119002. 0
  119003. };
  119004. static long _vq_quantlist__44c7_s_p5_0[] = {
  119005. 1,
  119006. 0,
  119007. 2,
  119008. };
  119009. static long _vq_lengthlist__44c7_s_p5_0[] = {
  119010. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 7,10,10,10,10,
  119011. 10, 9, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  119012. 12,10,11,12, 7,10,10,11,12,12,12,12,12, 7,10,10,
  119013. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  119014. 10,10,12,12,12,12,11,12, 7,10,10,11,12,12,12,12,
  119015. 12,
  119016. };
  119017. static float _vq_quantthresh__44c7_s_p5_0[] = {
  119018. -5.5, 5.5,
  119019. };
  119020. static long _vq_quantmap__44c7_s_p5_0[] = {
  119021. 1, 0, 2,
  119022. };
  119023. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_0 = {
  119024. _vq_quantthresh__44c7_s_p5_0,
  119025. _vq_quantmap__44c7_s_p5_0,
  119026. 3,
  119027. 3
  119028. };
  119029. static static_codebook _44c7_s_p5_0 = {
  119030. 4, 81,
  119031. _vq_lengthlist__44c7_s_p5_0,
  119032. 1, -529137664, 1618345984, 2, 0,
  119033. _vq_quantlist__44c7_s_p5_0,
  119034. NULL,
  119035. &_vq_auxt__44c7_s_p5_0,
  119036. NULL,
  119037. 0
  119038. };
  119039. static long _vq_quantlist__44c7_s_p5_1[] = {
  119040. 5,
  119041. 4,
  119042. 6,
  119043. 3,
  119044. 7,
  119045. 2,
  119046. 8,
  119047. 1,
  119048. 9,
  119049. 0,
  119050. 10,
  119051. };
  119052. static long _vq_lengthlist__44c7_s_p5_1[] = {
  119053. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  119054. 7, 7, 8, 8, 9, 9,11, 4, 4, 6, 6, 7, 7, 8, 8, 9,
  119055. 9,12, 5, 5, 6, 6, 7, 7, 9, 9, 9, 9,12,12,12, 6,
  119056. 6, 7, 7, 9, 9, 9, 9,11,11,11, 7, 7, 7, 7, 8, 8,
  119057. 9, 9,11,11,11, 7, 7, 7, 7, 8, 8, 9, 9,11,11,11,
  119058. 7, 7, 8, 8, 8, 8, 9, 9,11,11,11,11,11, 8, 8, 8,
  119059. 8, 8, 9,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  119060. 11,11,11, 7, 7, 8, 8, 8, 8,
  119061. };
  119062. static float _vq_quantthresh__44c7_s_p5_1[] = {
  119063. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119064. 3.5, 4.5,
  119065. };
  119066. static long _vq_quantmap__44c7_s_p5_1[] = {
  119067. 9, 7, 5, 3, 1, 0, 2, 4,
  119068. 6, 8, 10,
  119069. };
  119070. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_1 = {
  119071. _vq_quantthresh__44c7_s_p5_1,
  119072. _vq_quantmap__44c7_s_p5_1,
  119073. 11,
  119074. 11
  119075. };
  119076. static static_codebook _44c7_s_p5_1 = {
  119077. 2, 121,
  119078. _vq_lengthlist__44c7_s_p5_1,
  119079. 1, -531365888, 1611661312, 4, 0,
  119080. _vq_quantlist__44c7_s_p5_1,
  119081. NULL,
  119082. &_vq_auxt__44c7_s_p5_1,
  119083. NULL,
  119084. 0
  119085. };
  119086. static long _vq_quantlist__44c7_s_p6_0[] = {
  119087. 6,
  119088. 5,
  119089. 7,
  119090. 4,
  119091. 8,
  119092. 3,
  119093. 9,
  119094. 2,
  119095. 10,
  119096. 1,
  119097. 11,
  119098. 0,
  119099. 12,
  119100. };
  119101. static long _vq_lengthlist__44c7_s_p6_0[] = {
  119102. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 8,10,10, 6, 5, 5,
  119103. 7, 7, 8, 8, 9, 9, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  119104. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 8, 9, 9,
  119105. 10,10,11,11, 0, 8, 8, 7, 7, 8, 9, 9, 9,10,10,11,
  119106. 11, 0,11,11, 9, 9,10,10,11,10,11,11,12,12, 0,12,
  119107. 12, 9, 9,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0,
  119108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119112. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119113. };
  119114. static float _vq_quantthresh__44c7_s_p6_0[] = {
  119115. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  119116. 12.5, 17.5, 22.5, 27.5,
  119117. };
  119118. static long _vq_quantmap__44c7_s_p6_0[] = {
  119119. 11, 9, 7, 5, 3, 1, 0, 2,
  119120. 4, 6, 8, 10, 12,
  119121. };
  119122. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_0 = {
  119123. _vq_quantthresh__44c7_s_p6_0,
  119124. _vq_quantmap__44c7_s_p6_0,
  119125. 13,
  119126. 13
  119127. };
  119128. static static_codebook _44c7_s_p6_0 = {
  119129. 2, 169,
  119130. _vq_lengthlist__44c7_s_p6_0,
  119131. 1, -526516224, 1616117760, 4, 0,
  119132. _vq_quantlist__44c7_s_p6_0,
  119133. NULL,
  119134. &_vq_auxt__44c7_s_p6_0,
  119135. NULL,
  119136. 0
  119137. };
  119138. static long _vq_quantlist__44c7_s_p6_1[] = {
  119139. 2,
  119140. 1,
  119141. 3,
  119142. 0,
  119143. 4,
  119144. };
  119145. static long _vq_lengthlist__44c7_s_p6_1[] = {
  119146. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  119147. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  119148. };
  119149. static float _vq_quantthresh__44c7_s_p6_1[] = {
  119150. -1.5, -0.5, 0.5, 1.5,
  119151. };
  119152. static long _vq_quantmap__44c7_s_p6_1[] = {
  119153. 3, 1, 0, 2, 4,
  119154. };
  119155. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_1 = {
  119156. _vq_quantthresh__44c7_s_p6_1,
  119157. _vq_quantmap__44c7_s_p6_1,
  119158. 5,
  119159. 5
  119160. };
  119161. static static_codebook _44c7_s_p6_1 = {
  119162. 2, 25,
  119163. _vq_lengthlist__44c7_s_p6_1,
  119164. 1, -533725184, 1611661312, 3, 0,
  119165. _vq_quantlist__44c7_s_p6_1,
  119166. NULL,
  119167. &_vq_auxt__44c7_s_p6_1,
  119168. NULL,
  119169. 0
  119170. };
  119171. static long _vq_quantlist__44c7_s_p7_0[] = {
  119172. 6,
  119173. 5,
  119174. 7,
  119175. 4,
  119176. 8,
  119177. 3,
  119178. 9,
  119179. 2,
  119180. 10,
  119181. 1,
  119182. 11,
  119183. 0,
  119184. 12,
  119185. };
  119186. static long _vq_lengthlist__44c7_s_p7_0[] = {
  119187. 1, 4, 4, 6, 6, 7, 8, 9, 9,10,10,12,11, 6, 5, 5,
  119188. 7, 7, 8, 8, 9,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  119189. 8,10,10,11,11,12,12,20, 7, 7, 7, 7, 8, 9,10,10,
  119190. 11,11,12,13,20, 7, 7, 7, 7, 9, 9,10,10,11,12,13,
  119191. 13,20,11,11, 8, 8, 9, 9,11,11,12,12,13,13,20,11,
  119192. 11, 8, 8, 9, 9,11,11,12,12,13,13,20,20,20,10,10,
  119193. 10,10,12,12,13,13,13,13,20,20,20,10,10,10,10,12,
  119194. 12,13,13,13,14,20,20,20,14,14,11,11,12,12,13,13,
  119195. 14,14,20,20,20,14,14,11,11,12,12,13,13,14,14,20,
  119196. 20,20,20,19,13,13,13,13,14,14,15,14,19,19,19,19,
  119197. 19,13,13,13,13,14,14,15,15,
  119198. };
  119199. static float _vq_quantthresh__44c7_s_p7_0[] = {
  119200. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  119201. 27.5, 38.5, 49.5, 60.5,
  119202. };
  119203. static long _vq_quantmap__44c7_s_p7_0[] = {
  119204. 11, 9, 7, 5, 3, 1, 0, 2,
  119205. 4, 6, 8, 10, 12,
  119206. };
  119207. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_0 = {
  119208. _vq_quantthresh__44c7_s_p7_0,
  119209. _vq_quantmap__44c7_s_p7_0,
  119210. 13,
  119211. 13
  119212. };
  119213. static static_codebook _44c7_s_p7_0 = {
  119214. 2, 169,
  119215. _vq_lengthlist__44c7_s_p7_0,
  119216. 1, -523206656, 1618345984, 4, 0,
  119217. _vq_quantlist__44c7_s_p7_0,
  119218. NULL,
  119219. &_vq_auxt__44c7_s_p7_0,
  119220. NULL,
  119221. 0
  119222. };
  119223. static long _vq_quantlist__44c7_s_p7_1[] = {
  119224. 5,
  119225. 4,
  119226. 6,
  119227. 3,
  119228. 7,
  119229. 2,
  119230. 8,
  119231. 1,
  119232. 9,
  119233. 0,
  119234. 10,
  119235. };
  119236. static long _vq_lengthlist__44c7_s_p7_1[] = {
  119237. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 7, 7,
  119238. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  119239. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  119240. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119241. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  119242. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  119243. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  119244. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119245. };
  119246. static float _vq_quantthresh__44c7_s_p7_1[] = {
  119247. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119248. 3.5, 4.5,
  119249. };
  119250. static long _vq_quantmap__44c7_s_p7_1[] = {
  119251. 9, 7, 5, 3, 1, 0, 2, 4,
  119252. 6, 8, 10,
  119253. };
  119254. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_1 = {
  119255. _vq_quantthresh__44c7_s_p7_1,
  119256. _vq_quantmap__44c7_s_p7_1,
  119257. 11,
  119258. 11
  119259. };
  119260. static static_codebook _44c7_s_p7_1 = {
  119261. 2, 121,
  119262. _vq_lengthlist__44c7_s_p7_1,
  119263. 1, -531365888, 1611661312, 4, 0,
  119264. _vq_quantlist__44c7_s_p7_1,
  119265. NULL,
  119266. &_vq_auxt__44c7_s_p7_1,
  119267. NULL,
  119268. 0
  119269. };
  119270. static long _vq_quantlist__44c7_s_p8_0[] = {
  119271. 7,
  119272. 6,
  119273. 8,
  119274. 5,
  119275. 9,
  119276. 4,
  119277. 10,
  119278. 3,
  119279. 11,
  119280. 2,
  119281. 12,
  119282. 1,
  119283. 13,
  119284. 0,
  119285. 14,
  119286. };
  119287. static long _vq_lengthlist__44c7_s_p8_0[] = {
  119288. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8, 9, 9,10,10, 6,
  119289. 5, 5, 7, 7, 9, 9, 8, 8,10, 9,11,10,12,11, 6, 5,
  119290. 5, 8, 7, 9, 9, 8, 8,10,10,11,11,12,11,19, 8, 8,
  119291. 8, 8,10,10, 9, 9,10,10,11,11,12,11,19, 8, 8, 8,
  119292. 8,10,10, 9, 9,10,10,11,11,12,12,19,12,12, 9, 9,
  119293. 10,10, 9,10,10,10,11,11,12,12,19,12,12, 9, 9,10,
  119294. 10,10,10,10,10,12,12,12,12,19,19,19, 9, 9, 9, 9,
  119295. 11,10,11,11,12,11,13,13,19,19,19, 9, 9, 9, 9,11,
  119296. 10,11,11,11,12,13,13,19,19,19,13,13,10,10,11,11,
  119297. 12,12,12,12,13,12,19,19,19,14,13,10,10,11,11,12,
  119298. 12,12,13,13,13,19,19,19,19,19,12,12,12,11,12,13,
  119299. 14,13,13,13,19,19,19,19,19,12,12,12,11,12,12,13,
  119300. 14,13,14,19,19,19,19,19,16,16,12,13,12,13,13,14,
  119301. 15,14,19,18,18,18,18,16,15,12,11,12,11,14,12,14,
  119302. 14,
  119303. };
  119304. static float _vq_quantthresh__44c7_s_p8_0[] = {
  119305. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  119306. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  119307. };
  119308. static long _vq_quantmap__44c7_s_p8_0[] = {
  119309. 13, 11, 9, 7, 5, 3, 1, 0,
  119310. 2, 4, 6, 8, 10, 12, 14,
  119311. };
  119312. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_0 = {
  119313. _vq_quantthresh__44c7_s_p8_0,
  119314. _vq_quantmap__44c7_s_p8_0,
  119315. 15,
  119316. 15
  119317. };
  119318. static static_codebook _44c7_s_p8_0 = {
  119319. 2, 225,
  119320. _vq_lengthlist__44c7_s_p8_0,
  119321. 1, -520986624, 1620377600, 4, 0,
  119322. _vq_quantlist__44c7_s_p8_0,
  119323. NULL,
  119324. &_vq_auxt__44c7_s_p8_0,
  119325. NULL,
  119326. 0
  119327. };
  119328. static long _vq_quantlist__44c7_s_p8_1[] = {
  119329. 10,
  119330. 9,
  119331. 11,
  119332. 8,
  119333. 12,
  119334. 7,
  119335. 13,
  119336. 6,
  119337. 14,
  119338. 5,
  119339. 15,
  119340. 4,
  119341. 16,
  119342. 3,
  119343. 17,
  119344. 2,
  119345. 18,
  119346. 1,
  119347. 19,
  119348. 0,
  119349. 20,
  119350. };
  119351. static long _vq_lengthlist__44c7_s_p8_1[] = {
  119352. 3, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  119353. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  119354. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  119355. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  119356. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119357. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  119358. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  119359. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  119360. 10, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119361. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119362. 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,10,10, 9, 9, 9,
  119363. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9, 9,10,11,10,
  119364. 11,10, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9, 9,
  119365. 9, 9,11,10,11,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,
  119366. 10, 9, 9,10, 9, 9,10,11,10,10,11,10, 9, 9, 9, 9,
  119367. 9,10,10, 9,10,10,10,10, 9,10,10,10,10,10,10,11,
  119368. 11,11,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  119369. 10,10,10,11,11,10,10,10,10,10,10,10,10,10,10,10,
  119370. 10, 9,10,10, 9,10,11,11,10,11,10,11,10, 9,10,10,
  119371. 9,10,10,10,10,10,10,10,10,10,10,11,11,11,11,10,
  119372. 11,11,10,10,10,10,10,10, 9,10, 9,10,10, 9,10, 9,
  119373. 10,10,10,11,10,11,10,11,11,10,10,10,10,10,10, 9,
  119374. 10,10,10,10,10,10,10,11,10,10,10,10,10,10,10,10,
  119375. 10,10,10,10,10,10,10,10,10,10,10,10,10,11,10,11,
  119376. 11,10,10,10,10, 9, 9,10,10, 9, 9,10, 9,10,10,10,
  119377. 10,11,11,10,10,10,10,10,10,10, 9, 9,10,10,10, 9,
  119378. 9,10,10,10,10,10,11,10,11,10,10,10,10,10,10, 9,
  119379. 10,10,10,10,10,10,10,10,10,
  119380. };
  119381. static float _vq_quantthresh__44c7_s_p8_1[] = {
  119382. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  119383. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  119384. 6.5, 7.5, 8.5, 9.5,
  119385. };
  119386. static long _vq_quantmap__44c7_s_p8_1[] = {
  119387. 19, 17, 15, 13, 11, 9, 7, 5,
  119388. 3, 1, 0, 2, 4, 6, 8, 10,
  119389. 12, 14, 16, 18, 20,
  119390. };
  119391. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_1 = {
  119392. _vq_quantthresh__44c7_s_p8_1,
  119393. _vq_quantmap__44c7_s_p8_1,
  119394. 21,
  119395. 21
  119396. };
  119397. static static_codebook _44c7_s_p8_1 = {
  119398. 2, 441,
  119399. _vq_lengthlist__44c7_s_p8_1,
  119400. 1, -529268736, 1611661312, 5, 0,
  119401. _vq_quantlist__44c7_s_p8_1,
  119402. NULL,
  119403. &_vq_auxt__44c7_s_p8_1,
  119404. NULL,
  119405. 0
  119406. };
  119407. static long _vq_quantlist__44c7_s_p9_0[] = {
  119408. 6,
  119409. 5,
  119410. 7,
  119411. 4,
  119412. 8,
  119413. 3,
  119414. 9,
  119415. 2,
  119416. 10,
  119417. 1,
  119418. 11,
  119419. 0,
  119420. 12,
  119421. };
  119422. static long _vq_lengthlist__44c7_s_p9_0[] = {
  119423. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 6, 6,
  119424. 11,11,11,11,11,11,11,11,11,11, 4, 7, 7,11,11,11,
  119425. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119426. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119427. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119428. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119429. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119430. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119431. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119432. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119433. 11,11,11,11,11,11,11,11,11,
  119434. };
  119435. static float _vq_quantthresh__44c7_s_p9_0[] = {
  119436. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  119437. 1592.5, 2229.5, 2866.5, 3503.5,
  119438. };
  119439. static long _vq_quantmap__44c7_s_p9_0[] = {
  119440. 11, 9, 7, 5, 3, 1, 0, 2,
  119441. 4, 6, 8, 10, 12,
  119442. };
  119443. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_0 = {
  119444. _vq_quantthresh__44c7_s_p9_0,
  119445. _vq_quantmap__44c7_s_p9_0,
  119446. 13,
  119447. 13
  119448. };
  119449. static static_codebook _44c7_s_p9_0 = {
  119450. 2, 169,
  119451. _vq_lengthlist__44c7_s_p9_0,
  119452. 1, -511845376, 1630791680, 4, 0,
  119453. _vq_quantlist__44c7_s_p9_0,
  119454. NULL,
  119455. &_vq_auxt__44c7_s_p9_0,
  119456. NULL,
  119457. 0
  119458. };
  119459. static long _vq_quantlist__44c7_s_p9_1[] = {
  119460. 6,
  119461. 5,
  119462. 7,
  119463. 4,
  119464. 8,
  119465. 3,
  119466. 9,
  119467. 2,
  119468. 10,
  119469. 1,
  119470. 11,
  119471. 0,
  119472. 12,
  119473. };
  119474. static long _vq_lengthlist__44c7_s_p9_1[] = {
  119475. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  119476. 8, 8, 9, 8, 8, 7, 9, 8,11,10, 5, 6, 6, 8, 8, 9,
  119477. 8, 8, 8,10, 9,11,11,16, 8, 8, 9, 8, 9, 9, 9, 8,
  119478. 10, 9,11,10,16, 8, 8, 9, 9,10,10, 9, 9,10,10,11,
  119479. 11,16,13,13, 9, 9,10,10, 9,10,11,11,12,11,16,13,
  119480. 13, 9, 8,10, 9,10,10,10,10,11,11,16,14,16, 8, 9,
  119481. 9, 9,11,10,11,11,12,11,16,16,16, 9, 7,10, 7,11,
  119482. 10,11,11,12,11,16,16,16,12,12, 9,10,11,11,12,11,
  119483. 12,12,16,16,16,12,10,10, 7,11, 8,12,11,12,12,16,
  119484. 16,15,16,16,11,12,10,10,12,11,12,12,16,16,16,15,
  119485. 15,11,11,10,10,12,12,12,12,
  119486. };
  119487. static float _vq_quantthresh__44c7_s_p9_1[] = {
  119488. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  119489. 122.5, 171.5, 220.5, 269.5,
  119490. };
  119491. static long _vq_quantmap__44c7_s_p9_1[] = {
  119492. 11, 9, 7, 5, 3, 1, 0, 2,
  119493. 4, 6, 8, 10, 12,
  119494. };
  119495. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_1 = {
  119496. _vq_quantthresh__44c7_s_p9_1,
  119497. _vq_quantmap__44c7_s_p9_1,
  119498. 13,
  119499. 13
  119500. };
  119501. static static_codebook _44c7_s_p9_1 = {
  119502. 2, 169,
  119503. _vq_lengthlist__44c7_s_p9_1,
  119504. 1, -518889472, 1622704128, 4, 0,
  119505. _vq_quantlist__44c7_s_p9_1,
  119506. NULL,
  119507. &_vq_auxt__44c7_s_p9_1,
  119508. NULL,
  119509. 0
  119510. };
  119511. static long _vq_quantlist__44c7_s_p9_2[] = {
  119512. 24,
  119513. 23,
  119514. 25,
  119515. 22,
  119516. 26,
  119517. 21,
  119518. 27,
  119519. 20,
  119520. 28,
  119521. 19,
  119522. 29,
  119523. 18,
  119524. 30,
  119525. 17,
  119526. 31,
  119527. 16,
  119528. 32,
  119529. 15,
  119530. 33,
  119531. 14,
  119532. 34,
  119533. 13,
  119534. 35,
  119535. 12,
  119536. 36,
  119537. 11,
  119538. 37,
  119539. 10,
  119540. 38,
  119541. 9,
  119542. 39,
  119543. 8,
  119544. 40,
  119545. 7,
  119546. 41,
  119547. 6,
  119548. 42,
  119549. 5,
  119550. 43,
  119551. 4,
  119552. 44,
  119553. 3,
  119554. 45,
  119555. 2,
  119556. 46,
  119557. 1,
  119558. 47,
  119559. 0,
  119560. 48,
  119561. };
  119562. static long _vq_lengthlist__44c7_s_p9_2[] = {
  119563. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  119564. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119565. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119566. 7,
  119567. };
  119568. static float _vq_quantthresh__44c7_s_p9_2[] = {
  119569. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  119570. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  119571. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119572. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119573. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  119574. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  119575. };
  119576. static long _vq_quantmap__44c7_s_p9_2[] = {
  119577. 47, 45, 43, 41, 39, 37, 35, 33,
  119578. 31, 29, 27, 25, 23, 21, 19, 17,
  119579. 15, 13, 11, 9, 7, 5, 3, 1,
  119580. 0, 2, 4, 6, 8, 10, 12, 14,
  119581. 16, 18, 20, 22, 24, 26, 28, 30,
  119582. 32, 34, 36, 38, 40, 42, 44, 46,
  119583. 48,
  119584. };
  119585. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_2 = {
  119586. _vq_quantthresh__44c7_s_p9_2,
  119587. _vq_quantmap__44c7_s_p9_2,
  119588. 49,
  119589. 49
  119590. };
  119591. static static_codebook _44c7_s_p9_2 = {
  119592. 1, 49,
  119593. _vq_lengthlist__44c7_s_p9_2,
  119594. 1, -526909440, 1611661312, 6, 0,
  119595. _vq_quantlist__44c7_s_p9_2,
  119596. NULL,
  119597. &_vq_auxt__44c7_s_p9_2,
  119598. NULL,
  119599. 0
  119600. };
  119601. static long _huff_lengthlist__44c7_s_short[] = {
  119602. 4,11,12,14,15,15,17,17,18,18, 5, 6, 6, 8, 9,10,
  119603. 13,17,18,19, 7, 5, 4, 6, 8, 9,11,15,19,19, 8, 6,
  119604. 5, 5, 6, 7,11,14,16,17, 9, 7, 7, 6, 7, 7,10,13,
  119605. 15,19,10, 8, 7, 6, 7, 6, 7, 9,14,16,12,10, 9, 7,
  119606. 7, 6, 4, 5,10,15,14,13,11, 7, 6, 6, 4, 2, 7,13,
  119607. 16,16,15, 9, 8, 8, 8, 6, 9,13,19,19,17,12,11,10,
  119608. 10, 9,11,14,
  119609. };
  119610. static static_codebook _huff_book__44c7_s_short = {
  119611. 2, 100,
  119612. _huff_lengthlist__44c7_s_short,
  119613. 0, 0, 0, 0, 0,
  119614. NULL,
  119615. NULL,
  119616. NULL,
  119617. NULL,
  119618. 0
  119619. };
  119620. static long _huff_lengthlist__44c8_s_long[] = {
  119621. 3, 8,12,13,14,14,14,13,14,14, 6, 4, 5, 8,10,10,
  119622. 11,11,14,13, 9, 5, 4, 5, 7, 8, 9,10,13,13,12, 7,
  119623. 5, 4, 5, 6, 8, 9,12,13,13, 9, 6, 5, 5, 5, 7, 9,
  119624. 11,14,12,10, 7, 6, 5, 4, 6, 7,10,11,12,11, 9, 8,
  119625. 7, 5, 5, 6,10,10,13,12,10, 9, 8, 6, 6, 5, 8,10,
  119626. 14,13,12,12,11,10, 9, 7, 8,10,12,13,14,14,13,12,
  119627. 11, 9, 9,10,
  119628. };
  119629. static static_codebook _huff_book__44c8_s_long = {
  119630. 2, 100,
  119631. _huff_lengthlist__44c8_s_long,
  119632. 0, 0, 0, 0, 0,
  119633. NULL,
  119634. NULL,
  119635. NULL,
  119636. NULL,
  119637. 0
  119638. };
  119639. static long _vq_quantlist__44c8_s_p1_0[] = {
  119640. 1,
  119641. 0,
  119642. 2,
  119643. };
  119644. static long _vq_lengthlist__44c8_s_p1_0[] = {
  119645. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 7, 7, 0, 9, 8, 0,
  119646. 9, 8, 6, 7, 7, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  119647. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  119648. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  119649. 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  119650. 8,
  119651. };
  119652. static float _vq_quantthresh__44c8_s_p1_0[] = {
  119653. -0.5, 0.5,
  119654. };
  119655. static long _vq_quantmap__44c8_s_p1_0[] = {
  119656. 1, 0, 2,
  119657. };
  119658. static encode_aux_threshmatch _vq_auxt__44c8_s_p1_0 = {
  119659. _vq_quantthresh__44c8_s_p1_0,
  119660. _vq_quantmap__44c8_s_p1_0,
  119661. 3,
  119662. 3
  119663. };
  119664. static static_codebook _44c8_s_p1_0 = {
  119665. 4, 81,
  119666. _vq_lengthlist__44c8_s_p1_0,
  119667. 1, -535822336, 1611661312, 2, 0,
  119668. _vq_quantlist__44c8_s_p1_0,
  119669. NULL,
  119670. &_vq_auxt__44c8_s_p1_0,
  119671. NULL,
  119672. 0
  119673. };
  119674. static long _vq_quantlist__44c8_s_p2_0[] = {
  119675. 2,
  119676. 1,
  119677. 3,
  119678. 0,
  119679. 4,
  119680. };
  119681. static long _vq_lengthlist__44c8_s_p2_0[] = {
  119682. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  119683. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  119684. 7,10, 9, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  119685. 11,11, 5, 7, 7, 9, 9, 0, 7, 8, 9,10, 0, 7, 8, 9,
  119686. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  119687. 0,11,10,12,11, 0,11,10,12,12, 0,13,13,14,14, 0,
  119688. 0, 0,14,13, 8, 9, 9,10,11, 0,10,11,12,12, 0,10,
  119689. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  119690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119691. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  119692. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,11,10, 5,
  119693. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  119694. 9,10,10, 0, 0, 0,10,10, 8,10, 9,12,12, 0,10,10,
  119695. 12,11, 0,10,10,12,12, 0,12,12,13,12, 0, 0, 0,13,
  119696. 12, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,11,12,
  119697. 0,12,12,13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0,
  119698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119699. 0, 0, 0, 6, 8, 7,11,10, 0, 7, 7,10,10, 0, 7, 7,
  119700. 10,10, 0, 9, 9,10,11, 0, 0, 0,10,10, 6, 7, 8,10,
  119701. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,10,10,
  119702. 0, 0, 0,10,10, 9,10, 9,12,12, 0,10,10,12,12, 0,
  119703. 10,10,12,11, 0,12,12,13,13, 0, 0, 0,13,12, 8, 9,
  119704. 10,12,12, 0,10,10,12,12, 0,10,10,11,12, 0,12,12,
  119705. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119707. 7,10,10,13,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  119708. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,13, 0, 9,
  119709. 9,12,12, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  119710. 12,12, 9,11,11,14,13, 0,10,10,13,12, 0,11,10,13,
  119711. 12, 0,12,12,13,12, 0, 0, 0,13,13, 9,11,11,13,14,
  119712. 0,10,11,12,13, 0,10,11,13,13, 0,12,12,12,13, 0,
  119713. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  119718. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,11,
  119719. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  119720. 13,13, 0,10,11,13,13, 0,12,12,13,13, 0, 0, 0,12,
  119721. 13,
  119722. };
  119723. static float _vq_quantthresh__44c8_s_p2_0[] = {
  119724. -1.5, -0.5, 0.5, 1.5,
  119725. };
  119726. static long _vq_quantmap__44c8_s_p2_0[] = {
  119727. 3, 1, 0, 2, 4,
  119728. };
  119729. static encode_aux_threshmatch _vq_auxt__44c8_s_p2_0 = {
  119730. _vq_quantthresh__44c8_s_p2_0,
  119731. _vq_quantmap__44c8_s_p2_0,
  119732. 5,
  119733. 5
  119734. };
  119735. static static_codebook _44c8_s_p2_0 = {
  119736. 4, 625,
  119737. _vq_lengthlist__44c8_s_p2_0,
  119738. 1, -533725184, 1611661312, 3, 0,
  119739. _vq_quantlist__44c8_s_p2_0,
  119740. NULL,
  119741. &_vq_auxt__44c8_s_p2_0,
  119742. NULL,
  119743. 0
  119744. };
  119745. static long _vq_quantlist__44c8_s_p3_0[] = {
  119746. 4,
  119747. 3,
  119748. 5,
  119749. 2,
  119750. 6,
  119751. 1,
  119752. 7,
  119753. 0,
  119754. 8,
  119755. };
  119756. static long _vq_lengthlist__44c8_s_p3_0[] = {
  119757. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  119758. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  119759. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  119760. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  119761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119762. 0,
  119763. };
  119764. static float _vq_quantthresh__44c8_s_p3_0[] = {
  119765. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  119766. };
  119767. static long _vq_quantmap__44c8_s_p3_0[] = {
  119768. 7, 5, 3, 1, 0, 2, 4, 6,
  119769. 8,
  119770. };
  119771. static encode_aux_threshmatch _vq_auxt__44c8_s_p3_0 = {
  119772. _vq_quantthresh__44c8_s_p3_0,
  119773. _vq_quantmap__44c8_s_p3_0,
  119774. 9,
  119775. 9
  119776. };
  119777. static static_codebook _44c8_s_p3_0 = {
  119778. 2, 81,
  119779. _vq_lengthlist__44c8_s_p3_0,
  119780. 1, -531628032, 1611661312, 4, 0,
  119781. _vq_quantlist__44c8_s_p3_0,
  119782. NULL,
  119783. &_vq_auxt__44c8_s_p3_0,
  119784. NULL,
  119785. 0
  119786. };
  119787. static long _vq_quantlist__44c8_s_p4_0[] = {
  119788. 8,
  119789. 7,
  119790. 9,
  119791. 6,
  119792. 10,
  119793. 5,
  119794. 11,
  119795. 4,
  119796. 12,
  119797. 3,
  119798. 13,
  119799. 2,
  119800. 14,
  119801. 1,
  119802. 15,
  119803. 0,
  119804. 16,
  119805. };
  119806. static long _vq_lengthlist__44c8_s_p4_0[] = {
  119807. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  119808. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 8,10,10,11,11,
  119809. 11,11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  119810. 11,11,11, 0, 6, 5, 6, 6, 7, 7, 9, 9, 9, 9,10,10,
  119811. 11,11,12,12, 0, 0, 0, 6, 6, 7, 7, 9, 9, 9, 9,10,
  119812. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  119813. 11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  119814. 10,11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  119815. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  119816. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  119817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119825. 0,
  119826. };
  119827. static float _vq_quantthresh__44c8_s_p4_0[] = {
  119828. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119829. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119830. };
  119831. static long _vq_quantmap__44c8_s_p4_0[] = {
  119832. 15, 13, 11, 9, 7, 5, 3, 1,
  119833. 0, 2, 4, 6, 8, 10, 12, 14,
  119834. 16,
  119835. };
  119836. static encode_aux_threshmatch _vq_auxt__44c8_s_p4_0 = {
  119837. _vq_quantthresh__44c8_s_p4_0,
  119838. _vq_quantmap__44c8_s_p4_0,
  119839. 17,
  119840. 17
  119841. };
  119842. static static_codebook _44c8_s_p4_0 = {
  119843. 2, 289,
  119844. _vq_lengthlist__44c8_s_p4_0,
  119845. 1, -529530880, 1611661312, 5, 0,
  119846. _vq_quantlist__44c8_s_p4_0,
  119847. NULL,
  119848. &_vq_auxt__44c8_s_p4_0,
  119849. NULL,
  119850. 0
  119851. };
  119852. static long _vq_quantlist__44c8_s_p5_0[] = {
  119853. 1,
  119854. 0,
  119855. 2,
  119856. };
  119857. static long _vq_lengthlist__44c8_s_p5_0[] = {
  119858. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6,10,10,10,10,
  119859. 10,10, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  119860. 11,10,11,11, 7,10,10,11,12,12,12,12,12, 7,10,10,
  119861. 11,12,12,12,12,12, 6,10,10,10,12,12,10,12,12, 7,
  119862. 10,10,11,12,12,12,12,12, 7,10,10,11,12,12,12,12,
  119863. 12,
  119864. };
  119865. static float _vq_quantthresh__44c8_s_p5_0[] = {
  119866. -5.5, 5.5,
  119867. };
  119868. static long _vq_quantmap__44c8_s_p5_0[] = {
  119869. 1, 0, 2,
  119870. };
  119871. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_0 = {
  119872. _vq_quantthresh__44c8_s_p5_0,
  119873. _vq_quantmap__44c8_s_p5_0,
  119874. 3,
  119875. 3
  119876. };
  119877. static static_codebook _44c8_s_p5_0 = {
  119878. 4, 81,
  119879. _vq_lengthlist__44c8_s_p5_0,
  119880. 1, -529137664, 1618345984, 2, 0,
  119881. _vq_quantlist__44c8_s_p5_0,
  119882. NULL,
  119883. &_vq_auxt__44c8_s_p5_0,
  119884. NULL,
  119885. 0
  119886. };
  119887. static long _vq_quantlist__44c8_s_p5_1[] = {
  119888. 5,
  119889. 4,
  119890. 6,
  119891. 3,
  119892. 7,
  119893. 2,
  119894. 8,
  119895. 1,
  119896. 9,
  119897. 0,
  119898. 10,
  119899. };
  119900. static long _vq_lengthlist__44c8_s_p5_1[] = {
  119901. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 5, 6, 6,
  119902. 7, 7, 8, 8, 8, 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  119903. 9,12, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,12,12,12, 6,
  119904. 6, 7, 7, 8, 8, 9, 9,11,11,11, 6, 6, 7, 7, 8, 8,
  119905. 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11,
  119906. 7, 7, 7, 8, 8, 8, 8, 8,11,11,11,11,11, 7, 7, 8,
  119907. 8, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 8, 8,11,11,
  119908. 11,11,11, 7, 7, 7, 7, 8, 8,
  119909. };
  119910. static float _vq_quantthresh__44c8_s_p5_1[] = {
  119911. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119912. 3.5, 4.5,
  119913. };
  119914. static long _vq_quantmap__44c8_s_p5_1[] = {
  119915. 9, 7, 5, 3, 1, 0, 2, 4,
  119916. 6, 8, 10,
  119917. };
  119918. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_1 = {
  119919. _vq_quantthresh__44c8_s_p5_1,
  119920. _vq_quantmap__44c8_s_p5_1,
  119921. 11,
  119922. 11
  119923. };
  119924. static static_codebook _44c8_s_p5_1 = {
  119925. 2, 121,
  119926. _vq_lengthlist__44c8_s_p5_1,
  119927. 1, -531365888, 1611661312, 4, 0,
  119928. _vq_quantlist__44c8_s_p5_1,
  119929. NULL,
  119930. &_vq_auxt__44c8_s_p5_1,
  119931. NULL,
  119932. 0
  119933. };
  119934. static long _vq_quantlist__44c8_s_p6_0[] = {
  119935. 6,
  119936. 5,
  119937. 7,
  119938. 4,
  119939. 8,
  119940. 3,
  119941. 9,
  119942. 2,
  119943. 10,
  119944. 1,
  119945. 11,
  119946. 0,
  119947. 12,
  119948. };
  119949. static long _vq_lengthlist__44c8_s_p6_0[] = {
  119950. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  119951. 7, 7, 8, 8, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 8,
  119952. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,
  119953. 10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,10,10,11,
  119954. 11, 0,11,11, 9, 9,10,10,11,11,11,11,12,12, 0,12,
  119955. 12, 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  119956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119960. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119961. };
  119962. static float _vq_quantthresh__44c8_s_p6_0[] = {
  119963. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  119964. 12.5, 17.5, 22.5, 27.5,
  119965. };
  119966. static long _vq_quantmap__44c8_s_p6_0[] = {
  119967. 11, 9, 7, 5, 3, 1, 0, 2,
  119968. 4, 6, 8, 10, 12,
  119969. };
  119970. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_0 = {
  119971. _vq_quantthresh__44c8_s_p6_0,
  119972. _vq_quantmap__44c8_s_p6_0,
  119973. 13,
  119974. 13
  119975. };
  119976. static static_codebook _44c8_s_p6_0 = {
  119977. 2, 169,
  119978. _vq_lengthlist__44c8_s_p6_0,
  119979. 1, -526516224, 1616117760, 4, 0,
  119980. _vq_quantlist__44c8_s_p6_0,
  119981. NULL,
  119982. &_vq_auxt__44c8_s_p6_0,
  119983. NULL,
  119984. 0
  119985. };
  119986. static long _vq_quantlist__44c8_s_p6_1[] = {
  119987. 2,
  119988. 1,
  119989. 3,
  119990. 0,
  119991. 4,
  119992. };
  119993. static long _vq_lengthlist__44c8_s_p6_1[] = {
  119994. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  119995. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  119996. };
  119997. static float _vq_quantthresh__44c8_s_p6_1[] = {
  119998. -1.5, -0.5, 0.5, 1.5,
  119999. };
  120000. static long _vq_quantmap__44c8_s_p6_1[] = {
  120001. 3, 1, 0, 2, 4,
  120002. };
  120003. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_1 = {
  120004. _vq_quantthresh__44c8_s_p6_1,
  120005. _vq_quantmap__44c8_s_p6_1,
  120006. 5,
  120007. 5
  120008. };
  120009. static static_codebook _44c8_s_p6_1 = {
  120010. 2, 25,
  120011. _vq_lengthlist__44c8_s_p6_1,
  120012. 1, -533725184, 1611661312, 3, 0,
  120013. _vq_quantlist__44c8_s_p6_1,
  120014. NULL,
  120015. &_vq_auxt__44c8_s_p6_1,
  120016. NULL,
  120017. 0
  120018. };
  120019. static long _vq_quantlist__44c8_s_p7_0[] = {
  120020. 6,
  120021. 5,
  120022. 7,
  120023. 4,
  120024. 8,
  120025. 3,
  120026. 9,
  120027. 2,
  120028. 10,
  120029. 1,
  120030. 11,
  120031. 0,
  120032. 12,
  120033. };
  120034. static long _vq_lengthlist__44c8_s_p7_0[] = {
  120035. 1, 4, 4, 6, 6, 8, 7, 9, 9,10,10,12,12, 6, 5, 5,
  120036. 7, 7, 8, 8,10,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  120037. 8,10,10,11,11,12,12,21, 7, 7, 7, 7, 8, 9,10,10,
  120038. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,12,12,13,
  120039. 13,21,11,11, 8, 8, 9, 9,11,11,12,12,13,13,21,11,
  120040. 11, 8, 8, 9, 9,11,11,12,12,13,13,21,21,21,10,10,
  120041. 10,10,11,11,12,13,13,13,21,21,21,10,10,10,10,11,
  120042. 11,13,13,14,13,21,21,21,13,13,11,11,12,12,13,13,
  120043. 14,14,21,21,21,14,14,11,11,12,12,13,13,14,14,21,
  120044. 21,21,21,20,13,13,13,12,14,14,16,15,20,20,20,20,
  120045. 20,13,13,13,13,14,13,15,15,
  120046. };
  120047. static float _vq_quantthresh__44c8_s_p7_0[] = {
  120048. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  120049. 27.5, 38.5, 49.5, 60.5,
  120050. };
  120051. static long _vq_quantmap__44c8_s_p7_0[] = {
  120052. 11, 9, 7, 5, 3, 1, 0, 2,
  120053. 4, 6, 8, 10, 12,
  120054. };
  120055. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_0 = {
  120056. _vq_quantthresh__44c8_s_p7_0,
  120057. _vq_quantmap__44c8_s_p7_0,
  120058. 13,
  120059. 13
  120060. };
  120061. static static_codebook _44c8_s_p7_0 = {
  120062. 2, 169,
  120063. _vq_lengthlist__44c8_s_p7_0,
  120064. 1, -523206656, 1618345984, 4, 0,
  120065. _vq_quantlist__44c8_s_p7_0,
  120066. NULL,
  120067. &_vq_auxt__44c8_s_p7_0,
  120068. NULL,
  120069. 0
  120070. };
  120071. static long _vq_quantlist__44c8_s_p7_1[] = {
  120072. 5,
  120073. 4,
  120074. 6,
  120075. 3,
  120076. 7,
  120077. 2,
  120078. 8,
  120079. 1,
  120080. 9,
  120081. 0,
  120082. 10,
  120083. };
  120084. static long _vq_lengthlist__44c8_s_p7_1[] = {
  120085. 4, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7,
  120086. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  120087. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  120088. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120089. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  120090. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  120091. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  120092. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120093. };
  120094. static float _vq_quantthresh__44c8_s_p7_1[] = {
  120095. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120096. 3.5, 4.5,
  120097. };
  120098. static long _vq_quantmap__44c8_s_p7_1[] = {
  120099. 9, 7, 5, 3, 1, 0, 2, 4,
  120100. 6, 8, 10,
  120101. };
  120102. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_1 = {
  120103. _vq_quantthresh__44c8_s_p7_1,
  120104. _vq_quantmap__44c8_s_p7_1,
  120105. 11,
  120106. 11
  120107. };
  120108. static static_codebook _44c8_s_p7_1 = {
  120109. 2, 121,
  120110. _vq_lengthlist__44c8_s_p7_1,
  120111. 1, -531365888, 1611661312, 4, 0,
  120112. _vq_quantlist__44c8_s_p7_1,
  120113. NULL,
  120114. &_vq_auxt__44c8_s_p7_1,
  120115. NULL,
  120116. 0
  120117. };
  120118. static long _vq_quantlist__44c8_s_p8_0[] = {
  120119. 7,
  120120. 6,
  120121. 8,
  120122. 5,
  120123. 9,
  120124. 4,
  120125. 10,
  120126. 3,
  120127. 11,
  120128. 2,
  120129. 12,
  120130. 1,
  120131. 13,
  120132. 0,
  120133. 14,
  120134. };
  120135. static long _vq_lengthlist__44c8_s_p8_0[] = {
  120136. 1, 4, 4, 7, 6, 8, 8, 8, 7, 9, 8,10,10,11,10, 6,
  120137. 5, 5, 7, 7, 9, 9, 8, 8,10,10,11,11,12,11, 6, 5,
  120138. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8,
  120139. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8, 8,
  120140. 8,10, 9, 9, 9,10,10,11,11,12,12,20,12,12, 9, 9,
  120141. 10,10,10,10,10,11,12,12,12,12,20,12,12, 9, 9,10,
  120142. 10,10,10,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,
  120143. 11,10,11,11,12,12,12,13,20,19,19, 9, 9, 9, 9,11,
  120144. 11,11,12,12,12,13,13,19,19,19,13,13,10,10,11,11,
  120145. 12,12,13,13,13,13,19,19,19,14,13,11,10,11,11,12,
  120146. 12,12,13,13,13,19,19,19,19,19,12,12,12,12,13,13,
  120147. 13,13,14,13,19,19,19,19,19,12,12,12,11,12,12,13,
  120148. 14,14,14,19,19,19,19,19,16,15,13,12,13,13,13,14,
  120149. 14,14,19,19,19,19,19,17,17,13,12,13,11,14,13,15,
  120150. 15,
  120151. };
  120152. static float _vq_quantthresh__44c8_s_p8_0[] = {
  120153. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  120154. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  120155. };
  120156. static long _vq_quantmap__44c8_s_p8_0[] = {
  120157. 13, 11, 9, 7, 5, 3, 1, 0,
  120158. 2, 4, 6, 8, 10, 12, 14,
  120159. };
  120160. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_0 = {
  120161. _vq_quantthresh__44c8_s_p8_0,
  120162. _vq_quantmap__44c8_s_p8_0,
  120163. 15,
  120164. 15
  120165. };
  120166. static static_codebook _44c8_s_p8_0 = {
  120167. 2, 225,
  120168. _vq_lengthlist__44c8_s_p8_0,
  120169. 1, -520986624, 1620377600, 4, 0,
  120170. _vq_quantlist__44c8_s_p8_0,
  120171. NULL,
  120172. &_vq_auxt__44c8_s_p8_0,
  120173. NULL,
  120174. 0
  120175. };
  120176. static long _vq_quantlist__44c8_s_p8_1[] = {
  120177. 10,
  120178. 9,
  120179. 11,
  120180. 8,
  120181. 12,
  120182. 7,
  120183. 13,
  120184. 6,
  120185. 14,
  120186. 5,
  120187. 15,
  120188. 4,
  120189. 16,
  120190. 3,
  120191. 17,
  120192. 2,
  120193. 18,
  120194. 1,
  120195. 19,
  120196. 0,
  120197. 20,
  120198. };
  120199. static long _vq_lengthlist__44c8_s_p8_1[] = {
  120200. 4, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  120201. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  120202. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  120203. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  120204. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120205. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  120206. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  120207. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  120208. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120209. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120210. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  120211. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  120212. 10,10, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9,
  120213. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120214. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  120215. 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,10,10,10,10,
  120216. 10,10,10, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  120217. 9,10,10,10,10,10,10,10, 9,10,10, 9,10,10,10,10,
  120218. 9,10, 9,10,10, 9,10,10,10,10,10,10,10, 9,10,10,
  120219. 10,10,10,10, 9, 9,10,10, 9,10,10,10,10,10,10,10,
  120220. 10,10,10,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9, 9,
  120221. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  120222. 10, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120223. 10,10,10,10, 9, 9,10, 9, 9, 9,10,10,10,10,10,10,
  120224. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,10,10,
  120225. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10, 9,
  120226. 9,10, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120227. 10, 9, 9,10,10, 9,10, 9, 9,
  120228. };
  120229. static float _vq_quantthresh__44c8_s_p8_1[] = {
  120230. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  120231. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  120232. 6.5, 7.5, 8.5, 9.5,
  120233. };
  120234. static long _vq_quantmap__44c8_s_p8_1[] = {
  120235. 19, 17, 15, 13, 11, 9, 7, 5,
  120236. 3, 1, 0, 2, 4, 6, 8, 10,
  120237. 12, 14, 16, 18, 20,
  120238. };
  120239. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_1 = {
  120240. _vq_quantthresh__44c8_s_p8_1,
  120241. _vq_quantmap__44c8_s_p8_1,
  120242. 21,
  120243. 21
  120244. };
  120245. static static_codebook _44c8_s_p8_1 = {
  120246. 2, 441,
  120247. _vq_lengthlist__44c8_s_p8_1,
  120248. 1, -529268736, 1611661312, 5, 0,
  120249. _vq_quantlist__44c8_s_p8_1,
  120250. NULL,
  120251. &_vq_auxt__44c8_s_p8_1,
  120252. NULL,
  120253. 0
  120254. };
  120255. static long _vq_quantlist__44c8_s_p9_0[] = {
  120256. 8,
  120257. 7,
  120258. 9,
  120259. 6,
  120260. 10,
  120261. 5,
  120262. 11,
  120263. 4,
  120264. 12,
  120265. 3,
  120266. 13,
  120267. 2,
  120268. 14,
  120269. 1,
  120270. 15,
  120271. 0,
  120272. 16,
  120273. };
  120274. static long _vq_lengthlist__44c8_s_p9_0[] = {
  120275. 1, 4, 3,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120276. 11, 4, 7, 7,11,11,11,11,11,11,11,11,11,11,11,11,
  120277. 11,11, 4, 8,11,11,11,11,11,11,11,11,11,11,11,11,
  120278. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120279. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120280. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120281. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120282. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120283. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120284. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120285. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120286. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120287. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120288. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120289. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120290. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120291. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120292. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120293. 10,
  120294. };
  120295. static float _vq_quantthresh__44c8_s_p9_0[] = {
  120296. -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5,
  120297. 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5, 6982.5,
  120298. };
  120299. static long _vq_quantmap__44c8_s_p9_0[] = {
  120300. 15, 13, 11, 9, 7, 5, 3, 1,
  120301. 0, 2, 4, 6, 8, 10, 12, 14,
  120302. 16,
  120303. };
  120304. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_0 = {
  120305. _vq_quantthresh__44c8_s_p9_0,
  120306. _vq_quantmap__44c8_s_p9_0,
  120307. 17,
  120308. 17
  120309. };
  120310. static static_codebook _44c8_s_p9_0 = {
  120311. 2, 289,
  120312. _vq_lengthlist__44c8_s_p9_0,
  120313. 1, -509798400, 1631393792, 5, 0,
  120314. _vq_quantlist__44c8_s_p9_0,
  120315. NULL,
  120316. &_vq_auxt__44c8_s_p9_0,
  120317. NULL,
  120318. 0
  120319. };
  120320. static long _vq_quantlist__44c8_s_p9_1[] = {
  120321. 9,
  120322. 8,
  120323. 10,
  120324. 7,
  120325. 11,
  120326. 6,
  120327. 12,
  120328. 5,
  120329. 13,
  120330. 4,
  120331. 14,
  120332. 3,
  120333. 15,
  120334. 2,
  120335. 16,
  120336. 1,
  120337. 17,
  120338. 0,
  120339. 18,
  120340. };
  120341. static long _vq_lengthlist__44c8_s_p9_1[] = {
  120342. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,10,10,
  120343. 10,11,11, 6, 6, 6, 8, 8, 9, 8, 8, 7,10, 8,11,10,
  120344. 12,11,12,12,13,13, 5, 5, 6, 8, 8, 9, 9, 8, 8,10,
  120345. 9,11,11,12,12,13,13,13,13,17, 8, 8, 9, 9, 9, 9,
  120346. 9, 9,10, 9,12,10,12,12,13,12,13,13,17, 9, 8, 9,
  120347. 9, 9, 9, 9, 9,10,10,12,12,12,12,13,13,13,13,17,
  120348. 13,13, 9, 9,10,10,10,10,11,11,12,11,13,12,13,13,
  120349. 14,15,17,13,13, 9, 8,10, 9,10,10,11,11,12,12,14,
  120350. 13,15,13,14,15,17,17,17, 9,10, 9,10,11,11,12,12,
  120351. 12,12,13,13,14,14,15,15,17,17,17, 9, 8, 9, 8,11,
  120352. 11,12,12,12,12,14,13,14,14,14,15,17,17,17,12,14,
  120353. 9,10,11,11,12,12,14,13,13,14,15,13,15,15,17,17,
  120354. 17,13,11,10, 8,11, 9,13,12,13,13,13,13,13,14,14,
  120355. 14,17,17,17,17,17,11,12,11,11,13,13,14,13,15,14,
  120356. 13,15,16,15,17,17,17,17,17,11,11,12, 8,13,12,14,
  120357. 13,17,14,15,14,15,14,17,17,17,17,17,15,15,12,12,
  120358. 12,12,13,14,14,14,15,14,17,14,17,17,17,17,17,16,
  120359. 17,12,12,13,12,13,13,14,14,14,14,14,14,17,17,17,
  120360. 17,17,17,17,14,14,13,12,13,13,15,15,14,13,15,17,
  120361. 17,17,17,17,17,17,17,13,14,13,13,13,13,14,15,15,
  120362. 15,14,15,17,17,17,17,17,17,17,16,15,13,14,13,13,
  120363. 14,14,15,14,14,16,17,17,17,17,17,17,17,16,16,13,
  120364. 14,13,13,14,14,15,14,15,14,
  120365. };
  120366. static float _vq_quantthresh__44c8_s_p9_1[] = {
  120367. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  120368. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  120369. 367.5, 416.5,
  120370. };
  120371. static long _vq_quantmap__44c8_s_p9_1[] = {
  120372. 17, 15, 13, 11, 9, 7, 5, 3,
  120373. 1, 0, 2, 4, 6, 8, 10, 12,
  120374. 14, 16, 18,
  120375. };
  120376. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_1 = {
  120377. _vq_quantthresh__44c8_s_p9_1,
  120378. _vq_quantmap__44c8_s_p9_1,
  120379. 19,
  120380. 19
  120381. };
  120382. static static_codebook _44c8_s_p9_1 = {
  120383. 2, 361,
  120384. _vq_lengthlist__44c8_s_p9_1,
  120385. 1, -518287360, 1622704128, 5, 0,
  120386. _vq_quantlist__44c8_s_p9_1,
  120387. NULL,
  120388. &_vq_auxt__44c8_s_p9_1,
  120389. NULL,
  120390. 0
  120391. };
  120392. static long _vq_quantlist__44c8_s_p9_2[] = {
  120393. 24,
  120394. 23,
  120395. 25,
  120396. 22,
  120397. 26,
  120398. 21,
  120399. 27,
  120400. 20,
  120401. 28,
  120402. 19,
  120403. 29,
  120404. 18,
  120405. 30,
  120406. 17,
  120407. 31,
  120408. 16,
  120409. 32,
  120410. 15,
  120411. 33,
  120412. 14,
  120413. 34,
  120414. 13,
  120415. 35,
  120416. 12,
  120417. 36,
  120418. 11,
  120419. 37,
  120420. 10,
  120421. 38,
  120422. 9,
  120423. 39,
  120424. 8,
  120425. 40,
  120426. 7,
  120427. 41,
  120428. 6,
  120429. 42,
  120430. 5,
  120431. 43,
  120432. 4,
  120433. 44,
  120434. 3,
  120435. 45,
  120436. 2,
  120437. 46,
  120438. 1,
  120439. 47,
  120440. 0,
  120441. 48,
  120442. };
  120443. static long _vq_lengthlist__44c8_s_p9_2[] = {
  120444. 2, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  120445. 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120446. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120447. 7,
  120448. };
  120449. static float _vq_quantthresh__44c8_s_p9_2[] = {
  120450. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  120451. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  120452. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120453. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120454. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  120455. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  120456. };
  120457. static long _vq_quantmap__44c8_s_p9_2[] = {
  120458. 47, 45, 43, 41, 39, 37, 35, 33,
  120459. 31, 29, 27, 25, 23, 21, 19, 17,
  120460. 15, 13, 11, 9, 7, 5, 3, 1,
  120461. 0, 2, 4, 6, 8, 10, 12, 14,
  120462. 16, 18, 20, 22, 24, 26, 28, 30,
  120463. 32, 34, 36, 38, 40, 42, 44, 46,
  120464. 48,
  120465. };
  120466. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_2 = {
  120467. _vq_quantthresh__44c8_s_p9_2,
  120468. _vq_quantmap__44c8_s_p9_2,
  120469. 49,
  120470. 49
  120471. };
  120472. static static_codebook _44c8_s_p9_2 = {
  120473. 1, 49,
  120474. _vq_lengthlist__44c8_s_p9_2,
  120475. 1, -526909440, 1611661312, 6, 0,
  120476. _vq_quantlist__44c8_s_p9_2,
  120477. NULL,
  120478. &_vq_auxt__44c8_s_p9_2,
  120479. NULL,
  120480. 0
  120481. };
  120482. static long _huff_lengthlist__44c8_s_short[] = {
  120483. 4,11,13,14,15,15,18,17,19,17, 5, 6, 8, 9,10,10,
  120484. 12,15,19,19, 6, 6, 6, 6, 8, 8,11,14,18,19, 8, 6,
  120485. 5, 4, 6, 7,10,13,16,17, 9, 7, 6, 5, 6, 7, 9,12,
  120486. 15,19,10, 8, 7, 6, 6, 6, 7, 9,13,15,12,10, 9, 8,
  120487. 7, 6, 4, 5,10,15,13,13,11, 8, 6, 6, 4, 2, 7,12,
  120488. 17,15,16,10, 8, 8, 7, 6, 9,12,19,18,17,13,11,10,
  120489. 10, 9,11,14,
  120490. };
  120491. static static_codebook _huff_book__44c8_s_short = {
  120492. 2, 100,
  120493. _huff_lengthlist__44c8_s_short,
  120494. 0, 0, 0, 0, 0,
  120495. NULL,
  120496. NULL,
  120497. NULL,
  120498. NULL,
  120499. 0
  120500. };
  120501. static long _huff_lengthlist__44c9_s_long[] = {
  120502. 3, 8,12,14,15,15,15,13,15,15, 6, 5, 8,10,12,12,
  120503. 13,12,14,13,10, 6, 5, 6, 8, 9,11,11,13,13,13, 8,
  120504. 5, 4, 5, 6, 8,10,11,13,14,10, 7, 5, 4, 5, 7, 9,
  120505. 11,12,13,11, 8, 6, 5, 4, 5, 7, 9,11,12,11,10, 8,
  120506. 7, 5, 4, 5, 9,10,13,13,11,10, 8, 6, 5, 4, 7, 9,
  120507. 15,14,13,12,10, 9, 8, 7, 8, 9,12,12,14,13,12,11,
  120508. 10, 9, 8, 9,
  120509. };
  120510. static static_codebook _huff_book__44c9_s_long = {
  120511. 2, 100,
  120512. _huff_lengthlist__44c9_s_long,
  120513. 0, 0, 0, 0, 0,
  120514. NULL,
  120515. NULL,
  120516. NULL,
  120517. NULL,
  120518. 0
  120519. };
  120520. static long _vq_quantlist__44c9_s_p1_0[] = {
  120521. 1,
  120522. 0,
  120523. 2,
  120524. };
  120525. static long _vq_lengthlist__44c9_s_p1_0[] = {
  120526. 1, 5, 5, 0, 5, 5, 0, 5, 5, 6, 8, 8, 0, 9, 8, 0,
  120527. 9, 8, 6, 8, 8, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  120528. 0, 0, 0, 0, 5, 8, 8, 0, 7, 7, 0, 8, 8, 5, 8, 8,
  120529. 0, 7, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  120530. 9, 8, 0, 8, 8, 0, 7, 7, 5, 8, 9, 0, 8, 8, 0, 7,
  120531. 7,
  120532. };
  120533. static float _vq_quantthresh__44c9_s_p1_0[] = {
  120534. -0.5, 0.5,
  120535. };
  120536. static long _vq_quantmap__44c9_s_p1_0[] = {
  120537. 1, 0, 2,
  120538. };
  120539. static encode_aux_threshmatch _vq_auxt__44c9_s_p1_0 = {
  120540. _vq_quantthresh__44c9_s_p1_0,
  120541. _vq_quantmap__44c9_s_p1_0,
  120542. 3,
  120543. 3
  120544. };
  120545. static static_codebook _44c9_s_p1_0 = {
  120546. 4, 81,
  120547. _vq_lengthlist__44c9_s_p1_0,
  120548. 1, -535822336, 1611661312, 2, 0,
  120549. _vq_quantlist__44c9_s_p1_0,
  120550. NULL,
  120551. &_vq_auxt__44c9_s_p1_0,
  120552. NULL,
  120553. 0
  120554. };
  120555. static long _vq_quantlist__44c9_s_p2_0[] = {
  120556. 2,
  120557. 1,
  120558. 3,
  120559. 0,
  120560. 4,
  120561. };
  120562. static long _vq_lengthlist__44c9_s_p2_0[] = {
  120563. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  120564. 7, 7, 9, 9, 0, 0, 0, 9, 9, 6, 7, 7, 9, 8, 0, 8,
  120565. 8, 9, 9, 0, 8, 7, 9, 9, 0, 9,10,10,10, 0, 0, 0,
  120566. 11,10, 6, 7, 7, 8, 9, 0, 8, 8, 9, 9, 0, 7, 8, 9,
  120567. 9, 0,10, 9,11,10, 0, 0, 0,10,10, 8, 9, 8,10,10,
  120568. 0,10,10,12,11, 0,10,10,11,11, 0,12,13,13,13, 0,
  120569. 0, 0,13,12, 8, 8, 9,10,10, 0,10,10,11,12, 0,10,
  120570. 10,11,11, 0,13,12,13,13, 0, 0, 0,13,13, 0, 0, 0,
  120571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120572. 0, 0, 0, 0, 0, 0, 6, 8, 7,10,10, 0, 7, 7,10, 9,
  120573. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,10,10, 6,
  120574. 7, 8,10,10, 0, 7, 7, 9,10, 0, 7, 7,10,10, 0, 9,
  120575. 9,10,10, 0, 0, 0,10,10, 8, 9, 9,11,11, 0,10,10,
  120576. 11,11, 0,10,10,11,11, 0,12,12,12,12, 0, 0, 0,12,
  120577. 12, 8, 9,10,11,11, 0, 9,10,11,11, 0,10,10,11,11,
  120578. 0,12,12,12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0,
  120579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120580. 0, 0, 0, 5, 8, 7,10,10, 0, 7, 7,10,10, 0, 7, 7,
  120581. 10, 9, 0, 9, 9,10,10, 0, 0, 0,10,10, 6, 7, 8,10,
  120582. 10, 0, 7, 7,10,10, 0, 7, 7, 9,10, 0, 9, 9,10,10,
  120583. 0, 0, 0,10,10, 8,10, 9,12,11, 0,10,10,12,11, 0,
  120584. 10, 9,11,11, 0,11,12,12,12, 0, 0, 0,12,12, 8, 9,
  120585. 10,11,12, 0,10,10,11,11, 0, 9,10,11,11, 0,12,11,
  120586. 12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120588. 7,10, 9,12,12, 0, 9, 9,12,11, 0, 9, 9,11,11, 0,
  120589. 10,10,12,11, 0, 0, 0,11,12, 7, 9,10,12,12, 0, 9,
  120590. 9,11,12, 0, 9, 9,11,11, 0,10,10,11,12, 0, 0, 0,
  120591. 11,11, 9,11,10,13,12, 0,10,10,12,12, 0,10,10,12,
  120592. 12, 0,11,11,12,12, 0, 0, 0,13,12, 9,10,11,12,13,
  120593. 0,10,10,12,12, 0,10,10,12,12, 0,11,12,12,12, 0,
  120594. 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  120599. 11,10,13,13, 0,10,10,12,12, 0,10,10,12,12, 0,11,
  120600. 12,12,12, 0, 0, 0,12,12, 9,10,11,13,13, 0,10,10,
  120601. 12,12, 0,10,10,12,12, 0,12,11,13,12, 0, 0, 0,12,
  120602. 12,
  120603. };
  120604. static float _vq_quantthresh__44c9_s_p2_0[] = {
  120605. -1.5, -0.5, 0.5, 1.5,
  120606. };
  120607. static long _vq_quantmap__44c9_s_p2_0[] = {
  120608. 3, 1, 0, 2, 4,
  120609. };
  120610. static encode_aux_threshmatch _vq_auxt__44c9_s_p2_0 = {
  120611. _vq_quantthresh__44c9_s_p2_0,
  120612. _vq_quantmap__44c9_s_p2_0,
  120613. 5,
  120614. 5
  120615. };
  120616. static static_codebook _44c9_s_p2_0 = {
  120617. 4, 625,
  120618. _vq_lengthlist__44c9_s_p2_0,
  120619. 1, -533725184, 1611661312, 3, 0,
  120620. _vq_quantlist__44c9_s_p2_0,
  120621. NULL,
  120622. &_vq_auxt__44c9_s_p2_0,
  120623. NULL,
  120624. 0
  120625. };
  120626. static long _vq_quantlist__44c9_s_p3_0[] = {
  120627. 4,
  120628. 3,
  120629. 5,
  120630. 2,
  120631. 6,
  120632. 1,
  120633. 7,
  120634. 0,
  120635. 8,
  120636. };
  120637. static long _vq_lengthlist__44c9_s_p3_0[] = {
  120638. 3, 4, 4, 5, 5, 6, 6, 8, 8, 0, 4, 4, 5, 5, 6, 7,
  120639. 8, 8, 0, 4, 4, 5, 5, 7, 7, 8, 8, 0, 5, 5, 6, 6,
  120640. 7, 7, 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0,
  120641. 7, 7, 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0,
  120642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120643. 0,
  120644. };
  120645. static float _vq_quantthresh__44c9_s_p3_0[] = {
  120646. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  120647. };
  120648. static long _vq_quantmap__44c9_s_p3_0[] = {
  120649. 7, 5, 3, 1, 0, 2, 4, 6,
  120650. 8,
  120651. };
  120652. static encode_aux_threshmatch _vq_auxt__44c9_s_p3_0 = {
  120653. _vq_quantthresh__44c9_s_p3_0,
  120654. _vq_quantmap__44c9_s_p3_0,
  120655. 9,
  120656. 9
  120657. };
  120658. static static_codebook _44c9_s_p3_0 = {
  120659. 2, 81,
  120660. _vq_lengthlist__44c9_s_p3_0,
  120661. 1, -531628032, 1611661312, 4, 0,
  120662. _vq_quantlist__44c9_s_p3_0,
  120663. NULL,
  120664. &_vq_auxt__44c9_s_p3_0,
  120665. NULL,
  120666. 0
  120667. };
  120668. static long _vq_quantlist__44c9_s_p4_0[] = {
  120669. 8,
  120670. 7,
  120671. 9,
  120672. 6,
  120673. 10,
  120674. 5,
  120675. 11,
  120676. 4,
  120677. 12,
  120678. 3,
  120679. 13,
  120680. 2,
  120681. 14,
  120682. 1,
  120683. 15,
  120684. 0,
  120685. 16,
  120686. };
  120687. static long _vq_lengthlist__44c9_s_p4_0[] = {
  120688. 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,10,
  120689. 10, 0, 5, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  120690. 11,11, 0, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  120691. 10,11,11, 0, 6, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,
  120692. 11,11,11,12, 0, 0, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,
  120693. 10,11,11,12,12, 0, 0, 0, 7, 7, 7, 7, 9, 9, 9, 9,
  120694. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 7, 8, 9, 9, 9,
  120695. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  120696. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  120697. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  120698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120706. 0,
  120707. };
  120708. static float _vq_quantthresh__44c9_s_p4_0[] = {
  120709. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120710. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120711. };
  120712. static long _vq_quantmap__44c9_s_p4_0[] = {
  120713. 15, 13, 11, 9, 7, 5, 3, 1,
  120714. 0, 2, 4, 6, 8, 10, 12, 14,
  120715. 16,
  120716. };
  120717. static encode_aux_threshmatch _vq_auxt__44c9_s_p4_0 = {
  120718. _vq_quantthresh__44c9_s_p4_0,
  120719. _vq_quantmap__44c9_s_p4_0,
  120720. 17,
  120721. 17
  120722. };
  120723. static static_codebook _44c9_s_p4_0 = {
  120724. 2, 289,
  120725. _vq_lengthlist__44c9_s_p4_0,
  120726. 1, -529530880, 1611661312, 5, 0,
  120727. _vq_quantlist__44c9_s_p4_0,
  120728. NULL,
  120729. &_vq_auxt__44c9_s_p4_0,
  120730. NULL,
  120731. 0
  120732. };
  120733. static long _vq_quantlist__44c9_s_p5_0[] = {
  120734. 1,
  120735. 0,
  120736. 2,
  120737. };
  120738. static long _vq_lengthlist__44c9_s_p5_0[] = {
  120739. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6, 9,10,10,10,
  120740. 10, 9, 4, 6, 7, 9,10,10,10, 9,10, 5, 9, 9, 9,11,
  120741. 11,10,11,11, 7,10, 9,11,12,11,12,12,12, 7, 9,10,
  120742. 11,11,12,12,12,12, 6,10,10,10,12,12,10,12,11, 7,
  120743. 10,10,11,12,12,11,12,12, 7,10,10,11,12,12,12,12,
  120744. 12,
  120745. };
  120746. static float _vq_quantthresh__44c9_s_p5_0[] = {
  120747. -5.5, 5.5,
  120748. };
  120749. static long _vq_quantmap__44c9_s_p5_0[] = {
  120750. 1, 0, 2,
  120751. };
  120752. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_0 = {
  120753. _vq_quantthresh__44c9_s_p5_0,
  120754. _vq_quantmap__44c9_s_p5_0,
  120755. 3,
  120756. 3
  120757. };
  120758. static static_codebook _44c9_s_p5_0 = {
  120759. 4, 81,
  120760. _vq_lengthlist__44c9_s_p5_0,
  120761. 1, -529137664, 1618345984, 2, 0,
  120762. _vq_quantlist__44c9_s_p5_0,
  120763. NULL,
  120764. &_vq_auxt__44c9_s_p5_0,
  120765. NULL,
  120766. 0
  120767. };
  120768. static long _vq_quantlist__44c9_s_p5_1[] = {
  120769. 5,
  120770. 4,
  120771. 6,
  120772. 3,
  120773. 7,
  120774. 2,
  120775. 8,
  120776. 1,
  120777. 9,
  120778. 0,
  120779. 10,
  120780. };
  120781. static long _vq_lengthlist__44c9_s_p5_1[] = {
  120782. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7,11, 5, 5, 6, 6,
  120783. 7, 7, 7, 7, 8, 8,11, 5, 5, 6, 6, 7, 7, 7, 7, 8,
  120784. 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11, 6,
  120785. 6, 7, 7, 7, 8, 8, 8,11,11,11, 6, 6, 7, 7, 7, 8,
  120786. 8, 8,11,11,11, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11,
  120787. 7, 7, 7, 7, 7, 7, 8, 8,11,11,11,10,10, 7, 7, 7,
  120788. 7, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 7, 7,11,11,
  120789. 11,11,11, 7, 7, 7, 7, 7, 7,
  120790. };
  120791. static float _vq_quantthresh__44c9_s_p5_1[] = {
  120792. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120793. 3.5, 4.5,
  120794. };
  120795. static long _vq_quantmap__44c9_s_p5_1[] = {
  120796. 9, 7, 5, 3, 1, 0, 2, 4,
  120797. 6, 8, 10,
  120798. };
  120799. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_1 = {
  120800. _vq_quantthresh__44c9_s_p5_1,
  120801. _vq_quantmap__44c9_s_p5_1,
  120802. 11,
  120803. 11
  120804. };
  120805. static static_codebook _44c9_s_p5_1 = {
  120806. 2, 121,
  120807. _vq_lengthlist__44c9_s_p5_1,
  120808. 1, -531365888, 1611661312, 4, 0,
  120809. _vq_quantlist__44c9_s_p5_1,
  120810. NULL,
  120811. &_vq_auxt__44c9_s_p5_1,
  120812. NULL,
  120813. 0
  120814. };
  120815. static long _vq_quantlist__44c9_s_p6_0[] = {
  120816. 6,
  120817. 5,
  120818. 7,
  120819. 4,
  120820. 8,
  120821. 3,
  120822. 9,
  120823. 2,
  120824. 10,
  120825. 1,
  120826. 11,
  120827. 0,
  120828. 12,
  120829. };
  120830. static long _vq_lengthlist__44c9_s_p6_0[] = {
  120831. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 5, 4, 4,
  120832. 6, 6, 8, 8, 9, 9, 9, 9,10,10, 6, 4, 4, 6, 6, 8,
  120833. 8, 9, 9, 9, 9,10,10, 0, 6, 6, 7, 7, 8, 8, 9, 9,
  120834. 10,10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  120835. 11, 0,10,10, 8, 8, 9, 9,10,10,11,11,12,12, 0,11,
  120836. 11, 8, 8, 9, 9,10,10,11,11,12,12, 0, 0, 0, 0, 0,
  120837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120841. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120842. };
  120843. static float _vq_quantthresh__44c9_s_p6_0[] = {
  120844. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  120845. 12.5, 17.5, 22.5, 27.5,
  120846. };
  120847. static long _vq_quantmap__44c9_s_p6_0[] = {
  120848. 11, 9, 7, 5, 3, 1, 0, 2,
  120849. 4, 6, 8, 10, 12,
  120850. };
  120851. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_0 = {
  120852. _vq_quantthresh__44c9_s_p6_0,
  120853. _vq_quantmap__44c9_s_p6_0,
  120854. 13,
  120855. 13
  120856. };
  120857. static static_codebook _44c9_s_p6_0 = {
  120858. 2, 169,
  120859. _vq_lengthlist__44c9_s_p6_0,
  120860. 1, -526516224, 1616117760, 4, 0,
  120861. _vq_quantlist__44c9_s_p6_0,
  120862. NULL,
  120863. &_vq_auxt__44c9_s_p6_0,
  120864. NULL,
  120865. 0
  120866. };
  120867. static long _vq_quantlist__44c9_s_p6_1[] = {
  120868. 2,
  120869. 1,
  120870. 3,
  120871. 0,
  120872. 4,
  120873. };
  120874. static long _vq_lengthlist__44c9_s_p6_1[] = {
  120875. 4, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5,
  120876. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  120877. };
  120878. static float _vq_quantthresh__44c9_s_p6_1[] = {
  120879. -1.5, -0.5, 0.5, 1.5,
  120880. };
  120881. static long _vq_quantmap__44c9_s_p6_1[] = {
  120882. 3, 1, 0, 2, 4,
  120883. };
  120884. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_1 = {
  120885. _vq_quantthresh__44c9_s_p6_1,
  120886. _vq_quantmap__44c9_s_p6_1,
  120887. 5,
  120888. 5
  120889. };
  120890. static static_codebook _44c9_s_p6_1 = {
  120891. 2, 25,
  120892. _vq_lengthlist__44c9_s_p6_1,
  120893. 1, -533725184, 1611661312, 3, 0,
  120894. _vq_quantlist__44c9_s_p6_1,
  120895. NULL,
  120896. &_vq_auxt__44c9_s_p6_1,
  120897. NULL,
  120898. 0
  120899. };
  120900. static long _vq_quantlist__44c9_s_p7_0[] = {
  120901. 6,
  120902. 5,
  120903. 7,
  120904. 4,
  120905. 8,
  120906. 3,
  120907. 9,
  120908. 2,
  120909. 10,
  120910. 1,
  120911. 11,
  120912. 0,
  120913. 12,
  120914. };
  120915. static long _vq_lengthlist__44c9_s_p7_0[] = {
  120916. 2, 4, 4, 6, 6, 7, 7, 8, 8,10,10,11,11, 6, 4, 4,
  120917. 6, 6, 8, 8, 9, 9,10,10,12,12, 6, 4, 5, 6, 6, 8,
  120918. 8, 9, 9,10,10,12,12,20, 6, 6, 6, 6, 8, 8, 9,10,
  120919. 11,11,12,12,20, 6, 6, 6, 6, 8, 8,10,10,11,11,12,
  120920. 12,20,10,10, 7, 7, 9, 9,10,10,11,11,12,12,20,11,
  120921. 11, 7, 7, 9, 9,10,10,11,11,12,12,20,20,20, 9, 9,
  120922. 9, 9,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,11,
  120923. 11,12,12,13,13,20,20,20,13,13,10,10,11,11,12,13,
  120924. 13,13,20,20,20,13,13,10,10,11,11,12,13,13,13,20,
  120925. 20,20,20,19,12,12,12,12,13,13,14,15,19,19,19,19,
  120926. 19,12,12,12,12,13,13,14,14,
  120927. };
  120928. static float _vq_quantthresh__44c9_s_p7_0[] = {
  120929. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  120930. 27.5, 38.5, 49.5, 60.5,
  120931. };
  120932. static long _vq_quantmap__44c9_s_p7_0[] = {
  120933. 11, 9, 7, 5, 3, 1, 0, 2,
  120934. 4, 6, 8, 10, 12,
  120935. };
  120936. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_0 = {
  120937. _vq_quantthresh__44c9_s_p7_0,
  120938. _vq_quantmap__44c9_s_p7_0,
  120939. 13,
  120940. 13
  120941. };
  120942. static static_codebook _44c9_s_p7_0 = {
  120943. 2, 169,
  120944. _vq_lengthlist__44c9_s_p7_0,
  120945. 1, -523206656, 1618345984, 4, 0,
  120946. _vq_quantlist__44c9_s_p7_0,
  120947. NULL,
  120948. &_vq_auxt__44c9_s_p7_0,
  120949. NULL,
  120950. 0
  120951. };
  120952. static long _vq_quantlist__44c9_s_p7_1[] = {
  120953. 5,
  120954. 4,
  120955. 6,
  120956. 3,
  120957. 7,
  120958. 2,
  120959. 8,
  120960. 1,
  120961. 9,
  120962. 0,
  120963. 10,
  120964. };
  120965. static long _vq_lengthlist__44c9_s_p7_1[] = {
  120966. 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6,
  120967. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  120968. 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 6,
  120969. 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120970. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  120971. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  120972. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  120973. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120974. };
  120975. static float _vq_quantthresh__44c9_s_p7_1[] = {
  120976. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120977. 3.5, 4.5,
  120978. };
  120979. static long _vq_quantmap__44c9_s_p7_1[] = {
  120980. 9, 7, 5, 3, 1, 0, 2, 4,
  120981. 6, 8, 10,
  120982. };
  120983. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_1 = {
  120984. _vq_quantthresh__44c9_s_p7_1,
  120985. _vq_quantmap__44c9_s_p7_1,
  120986. 11,
  120987. 11
  120988. };
  120989. static static_codebook _44c9_s_p7_1 = {
  120990. 2, 121,
  120991. _vq_lengthlist__44c9_s_p7_1,
  120992. 1, -531365888, 1611661312, 4, 0,
  120993. _vq_quantlist__44c9_s_p7_1,
  120994. NULL,
  120995. &_vq_auxt__44c9_s_p7_1,
  120996. NULL,
  120997. 0
  120998. };
  120999. static long _vq_quantlist__44c9_s_p8_0[] = {
  121000. 7,
  121001. 6,
  121002. 8,
  121003. 5,
  121004. 9,
  121005. 4,
  121006. 10,
  121007. 3,
  121008. 11,
  121009. 2,
  121010. 12,
  121011. 1,
  121012. 13,
  121013. 0,
  121014. 14,
  121015. };
  121016. static long _vq_lengthlist__44c9_s_p8_0[] = {
  121017. 1, 4, 4, 7, 6, 8, 8, 8, 8, 9, 9,10,10,11,10, 6,
  121018. 5, 5, 7, 7, 9, 9, 8, 9,10,10,11,11,12,12, 6, 5,
  121019. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,21, 7, 8,
  121020. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,21, 8, 8, 8,
  121021. 8, 9, 9, 9, 9,10,10,11,11,12,12,21,11,12, 9, 9,
  121022. 10,10,10,10,10,11,11,12,12,12,21,12,12, 9, 8,10,
  121023. 10,10,10,11,11,12,12,13,13,21,21,21, 9, 9, 9, 9,
  121024. 11,11,11,11,12,12,12,13,21,20,20, 9, 9, 9, 9,10,
  121025. 11,11,11,12,12,13,13,20,20,20,13,13,10,10,11,11,
  121026. 12,12,13,13,13,13,20,20,20,13,13,10,10,11,11,12,
  121027. 12,13,13,13,13,20,20,20,20,20,12,12,12,12,12,12,
  121028. 13,13,14,14,20,20,20,20,20,12,12,12,11,13,12,13,
  121029. 13,14,14,20,20,20,20,20,15,16,13,12,13,13,14,13,
  121030. 14,14,20,20,20,20,20,16,15,12,12,13,12,14,13,14,
  121031. 14,
  121032. };
  121033. static float _vq_quantthresh__44c9_s_p8_0[] = {
  121034. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  121035. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  121036. };
  121037. static long _vq_quantmap__44c9_s_p8_0[] = {
  121038. 13, 11, 9, 7, 5, 3, 1, 0,
  121039. 2, 4, 6, 8, 10, 12, 14,
  121040. };
  121041. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_0 = {
  121042. _vq_quantthresh__44c9_s_p8_0,
  121043. _vq_quantmap__44c9_s_p8_0,
  121044. 15,
  121045. 15
  121046. };
  121047. static static_codebook _44c9_s_p8_0 = {
  121048. 2, 225,
  121049. _vq_lengthlist__44c9_s_p8_0,
  121050. 1, -520986624, 1620377600, 4, 0,
  121051. _vq_quantlist__44c9_s_p8_0,
  121052. NULL,
  121053. &_vq_auxt__44c9_s_p8_0,
  121054. NULL,
  121055. 0
  121056. };
  121057. static long _vq_quantlist__44c9_s_p8_1[] = {
  121058. 10,
  121059. 9,
  121060. 11,
  121061. 8,
  121062. 12,
  121063. 7,
  121064. 13,
  121065. 6,
  121066. 14,
  121067. 5,
  121068. 15,
  121069. 4,
  121070. 16,
  121071. 3,
  121072. 17,
  121073. 2,
  121074. 18,
  121075. 1,
  121076. 19,
  121077. 0,
  121078. 20,
  121079. };
  121080. static long _vq_lengthlist__44c9_s_p8_1[] = {
  121081. 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  121082. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  121083. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  121084. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  121085. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121086. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  121087. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8,
  121088. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  121089. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121090. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121091. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  121092. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  121093. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121094. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121095. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  121096. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,
  121097. 10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,
  121098. 9,10,10,10,10,10,10,10, 9, 9, 9,10,10,10,10,10,
  121099. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10, 9, 9,10,
  121100. 9,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121101. 10,10,10,10, 9, 9,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  121102. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  121103. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  121104. 10,10, 9, 9,10, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121105. 10,10,10,10,10, 9, 9,10,10, 9, 9,10, 9, 9, 9,10,
  121106. 10,10,10,10,10,10,10,10,10,10, 9, 9,10, 9, 9, 9,
  121107. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9,
  121108. 9, 9, 9,10, 9, 9, 9, 9, 9,
  121109. };
  121110. static float _vq_quantthresh__44c9_s_p8_1[] = {
  121111. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  121112. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  121113. 6.5, 7.5, 8.5, 9.5,
  121114. };
  121115. static long _vq_quantmap__44c9_s_p8_1[] = {
  121116. 19, 17, 15, 13, 11, 9, 7, 5,
  121117. 3, 1, 0, 2, 4, 6, 8, 10,
  121118. 12, 14, 16, 18, 20,
  121119. };
  121120. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_1 = {
  121121. _vq_quantthresh__44c9_s_p8_1,
  121122. _vq_quantmap__44c9_s_p8_1,
  121123. 21,
  121124. 21
  121125. };
  121126. static static_codebook _44c9_s_p8_1 = {
  121127. 2, 441,
  121128. _vq_lengthlist__44c9_s_p8_1,
  121129. 1, -529268736, 1611661312, 5, 0,
  121130. _vq_quantlist__44c9_s_p8_1,
  121131. NULL,
  121132. &_vq_auxt__44c9_s_p8_1,
  121133. NULL,
  121134. 0
  121135. };
  121136. static long _vq_quantlist__44c9_s_p9_0[] = {
  121137. 9,
  121138. 8,
  121139. 10,
  121140. 7,
  121141. 11,
  121142. 6,
  121143. 12,
  121144. 5,
  121145. 13,
  121146. 4,
  121147. 14,
  121148. 3,
  121149. 15,
  121150. 2,
  121151. 16,
  121152. 1,
  121153. 17,
  121154. 0,
  121155. 18,
  121156. };
  121157. static long _vq_lengthlist__44c9_s_p9_0[] = {
  121158. 1, 4, 3,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121159. 12,12,12, 4, 5, 6,12,12,12,12,12,12,12,12,12,12,
  121160. 12,12,12,12,12,12, 4, 6, 6,12,12,12,12,12,12,12,
  121161. 12,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,
  121162. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121163. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121164. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121165. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121166. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121167. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121168. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121169. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121170. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121171. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121172. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121173. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121174. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  121175. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121176. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121177. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121178. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121179. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121180. 11,11,11,11,11,11,11,11,11,
  121181. };
  121182. static float _vq_quantthresh__44c9_s_p9_0[] = {
  121183. -7913.5, -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5,
  121184. -465.5, 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  121185. 6982.5, 7913.5,
  121186. };
  121187. static long _vq_quantmap__44c9_s_p9_0[] = {
  121188. 17, 15, 13, 11, 9, 7, 5, 3,
  121189. 1, 0, 2, 4, 6, 8, 10, 12,
  121190. 14, 16, 18,
  121191. };
  121192. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_0 = {
  121193. _vq_quantthresh__44c9_s_p9_0,
  121194. _vq_quantmap__44c9_s_p9_0,
  121195. 19,
  121196. 19
  121197. };
  121198. static static_codebook _44c9_s_p9_0 = {
  121199. 2, 361,
  121200. _vq_lengthlist__44c9_s_p9_0,
  121201. 1, -508535424, 1631393792, 5, 0,
  121202. _vq_quantlist__44c9_s_p9_0,
  121203. NULL,
  121204. &_vq_auxt__44c9_s_p9_0,
  121205. NULL,
  121206. 0
  121207. };
  121208. static long _vq_quantlist__44c9_s_p9_1[] = {
  121209. 9,
  121210. 8,
  121211. 10,
  121212. 7,
  121213. 11,
  121214. 6,
  121215. 12,
  121216. 5,
  121217. 13,
  121218. 4,
  121219. 14,
  121220. 3,
  121221. 15,
  121222. 2,
  121223. 16,
  121224. 1,
  121225. 17,
  121226. 0,
  121227. 18,
  121228. };
  121229. static long _vq_lengthlist__44c9_s_p9_1[] = {
  121230. 1, 4, 4, 7, 7, 7, 7, 8, 7, 9, 8, 9, 9,10,10,11,
  121231. 11,11,11, 6, 5, 5, 8, 8, 9, 9, 9, 8,10, 9,11,10,
  121232. 12,12,13,12,13,13, 5, 5, 5, 8, 8, 9, 9, 9, 9,10,
  121233. 10,11,11,12,12,13,12,13,13,17, 8, 8, 9, 9, 9, 9,
  121234. 9, 9,10,10,12,11,13,12,13,13,13,13,18, 8, 8, 9,
  121235. 9, 9, 9, 9, 9,11,11,12,12,13,13,13,13,13,13,17,
  121236. 13,12, 9, 9,10,10,10,10,11,11,12,12,12,13,13,13,
  121237. 14,14,18,13,12, 9, 9,10,10,10,10,11,11,12,12,13,
  121238. 13,13,14,14,14,17,18,18,10,10,10,10,11,11,11,12,
  121239. 12,12,14,13,14,13,13,14,18,18,18,10, 9,10, 9,11,
  121240. 11,12,12,12,12,13,13,15,14,14,14,18,18,16,13,14,
  121241. 10,11,11,11,12,13,13,13,13,14,13,13,14,14,18,18,
  121242. 18,14,12,11, 9,11,10,13,12,13,13,13,14,14,14,13,
  121243. 14,18,18,17,18,18,11,12,12,12,13,13,14,13,14,14,
  121244. 13,14,14,14,18,18,18,18,17,12,10,12, 9,13,11,13,
  121245. 14,14,14,14,14,15,14,18,18,17,17,18,14,15,12,13,
  121246. 13,13,14,13,14,14,15,14,15,14,18,17,18,18,18,15,
  121247. 15,12,10,14,10,14,14,13,13,14,14,14,14,18,16,18,
  121248. 18,18,18,17,14,14,13,14,14,13,13,14,14,14,15,15,
  121249. 18,18,18,18,17,17,17,14,14,14,12,14,13,14,14,15,
  121250. 14,15,14,18,18,18,18,18,18,18,17,16,13,13,13,14,
  121251. 14,14,14,15,16,15,18,18,18,18,18,18,18,17,17,13,
  121252. 13,13,13,14,13,14,15,15,15,
  121253. };
  121254. static float _vq_quantthresh__44c9_s_p9_1[] = {
  121255. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  121256. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  121257. 367.5, 416.5,
  121258. };
  121259. static long _vq_quantmap__44c9_s_p9_1[] = {
  121260. 17, 15, 13, 11, 9, 7, 5, 3,
  121261. 1, 0, 2, 4, 6, 8, 10, 12,
  121262. 14, 16, 18,
  121263. };
  121264. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_1 = {
  121265. _vq_quantthresh__44c9_s_p9_1,
  121266. _vq_quantmap__44c9_s_p9_1,
  121267. 19,
  121268. 19
  121269. };
  121270. static static_codebook _44c9_s_p9_1 = {
  121271. 2, 361,
  121272. _vq_lengthlist__44c9_s_p9_1,
  121273. 1, -518287360, 1622704128, 5, 0,
  121274. _vq_quantlist__44c9_s_p9_1,
  121275. NULL,
  121276. &_vq_auxt__44c9_s_p9_1,
  121277. NULL,
  121278. 0
  121279. };
  121280. static long _vq_quantlist__44c9_s_p9_2[] = {
  121281. 24,
  121282. 23,
  121283. 25,
  121284. 22,
  121285. 26,
  121286. 21,
  121287. 27,
  121288. 20,
  121289. 28,
  121290. 19,
  121291. 29,
  121292. 18,
  121293. 30,
  121294. 17,
  121295. 31,
  121296. 16,
  121297. 32,
  121298. 15,
  121299. 33,
  121300. 14,
  121301. 34,
  121302. 13,
  121303. 35,
  121304. 12,
  121305. 36,
  121306. 11,
  121307. 37,
  121308. 10,
  121309. 38,
  121310. 9,
  121311. 39,
  121312. 8,
  121313. 40,
  121314. 7,
  121315. 41,
  121316. 6,
  121317. 42,
  121318. 5,
  121319. 43,
  121320. 4,
  121321. 44,
  121322. 3,
  121323. 45,
  121324. 2,
  121325. 46,
  121326. 1,
  121327. 47,
  121328. 0,
  121329. 48,
  121330. };
  121331. static long _vq_lengthlist__44c9_s_p9_2[] = {
  121332. 2, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  121333. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  121334. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  121335. 7,
  121336. };
  121337. static float _vq_quantthresh__44c9_s_p9_2[] = {
  121338. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  121339. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  121340. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121341. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121342. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  121343. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  121344. };
  121345. static long _vq_quantmap__44c9_s_p9_2[] = {
  121346. 47, 45, 43, 41, 39, 37, 35, 33,
  121347. 31, 29, 27, 25, 23, 21, 19, 17,
  121348. 15, 13, 11, 9, 7, 5, 3, 1,
  121349. 0, 2, 4, 6, 8, 10, 12, 14,
  121350. 16, 18, 20, 22, 24, 26, 28, 30,
  121351. 32, 34, 36, 38, 40, 42, 44, 46,
  121352. 48,
  121353. };
  121354. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_2 = {
  121355. _vq_quantthresh__44c9_s_p9_2,
  121356. _vq_quantmap__44c9_s_p9_2,
  121357. 49,
  121358. 49
  121359. };
  121360. static static_codebook _44c9_s_p9_2 = {
  121361. 1, 49,
  121362. _vq_lengthlist__44c9_s_p9_2,
  121363. 1, -526909440, 1611661312, 6, 0,
  121364. _vq_quantlist__44c9_s_p9_2,
  121365. NULL,
  121366. &_vq_auxt__44c9_s_p9_2,
  121367. NULL,
  121368. 0
  121369. };
  121370. static long _huff_lengthlist__44c9_s_short[] = {
  121371. 5,13,18,16,17,17,19,18,19,19, 5, 7,10,11,12,12,
  121372. 13,16,17,18, 6, 6, 7, 7, 9, 9,10,14,17,19, 8, 7,
  121373. 6, 5, 6, 7, 9,12,19,17, 8, 7, 7, 6, 5, 6, 8,11,
  121374. 15,19, 9, 8, 7, 6, 5, 5, 6, 8,13,15,11,10, 8, 8,
  121375. 7, 5, 4, 4,10,14,12,13,11, 9, 7, 6, 4, 2, 6,12,
  121376. 18,16,16,13, 8, 7, 7, 5, 8,13,16,17,18,15,11, 9,
  121377. 9, 8,10,13,
  121378. };
  121379. static static_codebook _huff_book__44c9_s_short = {
  121380. 2, 100,
  121381. _huff_lengthlist__44c9_s_short,
  121382. 0, 0, 0, 0, 0,
  121383. NULL,
  121384. NULL,
  121385. NULL,
  121386. NULL,
  121387. 0
  121388. };
  121389. static long _huff_lengthlist__44c0_s_long[] = {
  121390. 5, 4, 8, 9, 8, 9,10,12,15, 4, 1, 5, 5, 6, 8,11,
  121391. 12,12, 8, 5, 8, 9, 9,11,13,12,12, 9, 5, 8, 5, 7,
  121392. 9,12,13,13, 8, 6, 8, 7, 7, 9,11,11,11, 9, 7, 9,
  121393. 7, 7, 7, 7,10,12,10,10,11, 9, 8, 7, 7, 9,11,11,
  121394. 12,13,12,11, 9, 8, 9,11,13,16,16,15,15,12,10,11,
  121395. 12,
  121396. };
  121397. static static_codebook _huff_book__44c0_s_long = {
  121398. 2, 81,
  121399. _huff_lengthlist__44c0_s_long,
  121400. 0, 0, 0, 0, 0,
  121401. NULL,
  121402. NULL,
  121403. NULL,
  121404. NULL,
  121405. 0
  121406. };
  121407. static long _vq_quantlist__44c0_s_p1_0[] = {
  121408. 1,
  121409. 0,
  121410. 2,
  121411. };
  121412. static long _vq_lengthlist__44c0_s_p1_0[] = {
  121413. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  121414. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  121419. 0, 0, 0, 7, 9, 9, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121424. 0, 0, 0, 0, 7, 9, 9, 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, 5, 7, 7, 0, 0, 0, 0,
  121459. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  121464. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,11,10, 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, 7, 9, 9, 0, 0,
  121469. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121505. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  121510. 0, 0, 0, 0, 0, 9, 9,11, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,11,
  121515. 0, 0, 0, 0, 0, 0, 9,11,10, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121823. 0,
  121824. };
  121825. static float _vq_quantthresh__44c0_s_p1_0[] = {
  121826. -0.5, 0.5,
  121827. };
  121828. static long _vq_quantmap__44c0_s_p1_0[] = {
  121829. 1, 0, 2,
  121830. };
  121831. static encode_aux_threshmatch _vq_auxt__44c0_s_p1_0 = {
  121832. _vq_quantthresh__44c0_s_p1_0,
  121833. _vq_quantmap__44c0_s_p1_0,
  121834. 3,
  121835. 3
  121836. };
  121837. static static_codebook _44c0_s_p1_0 = {
  121838. 8, 6561,
  121839. _vq_lengthlist__44c0_s_p1_0,
  121840. 1, -535822336, 1611661312, 2, 0,
  121841. _vq_quantlist__44c0_s_p1_0,
  121842. NULL,
  121843. &_vq_auxt__44c0_s_p1_0,
  121844. NULL,
  121845. 0
  121846. };
  121847. static long _vq_quantlist__44c0_s_p2_0[] = {
  121848. 2,
  121849. 1,
  121850. 3,
  121851. 0,
  121852. 4,
  121853. };
  121854. static long _vq_lengthlist__44c0_s_p2_0[] = {
  121855. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 6, 0, 0,
  121857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121858. 0, 0, 4, 5, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  121860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121861. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  121862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121894. 0,
  121895. };
  121896. static float _vq_quantthresh__44c0_s_p2_0[] = {
  121897. -1.5, -0.5, 0.5, 1.5,
  121898. };
  121899. static long _vq_quantmap__44c0_s_p2_0[] = {
  121900. 3, 1, 0, 2, 4,
  121901. };
  121902. static encode_aux_threshmatch _vq_auxt__44c0_s_p2_0 = {
  121903. _vq_quantthresh__44c0_s_p2_0,
  121904. _vq_quantmap__44c0_s_p2_0,
  121905. 5,
  121906. 5
  121907. };
  121908. static static_codebook _44c0_s_p2_0 = {
  121909. 4, 625,
  121910. _vq_lengthlist__44c0_s_p2_0,
  121911. 1, -533725184, 1611661312, 3, 0,
  121912. _vq_quantlist__44c0_s_p2_0,
  121913. NULL,
  121914. &_vq_auxt__44c0_s_p2_0,
  121915. NULL,
  121916. 0
  121917. };
  121918. static long _vq_quantlist__44c0_s_p3_0[] = {
  121919. 4,
  121920. 3,
  121921. 5,
  121922. 2,
  121923. 6,
  121924. 1,
  121925. 7,
  121926. 0,
  121927. 8,
  121928. };
  121929. static long _vq_lengthlist__44c0_s_p3_0[] = {
  121930. 1, 3, 2, 8, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  121931. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  121932. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  121933. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  121934. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121935. 0,
  121936. };
  121937. static float _vq_quantthresh__44c0_s_p3_0[] = {
  121938. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  121939. };
  121940. static long _vq_quantmap__44c0_s_p3_0[] = {
  121941. 7, 5, 3, 1, 0, 2, 4, 6,
  121942. 8,
  121943. };
  121944. static encode_aux_threshmatch _vq_auxt__44c0_s_p3_0 = {
  121945. _vq_quantthresh__44c0_s_p3_0,
  121946. _vq_quantmap__44c0_s_p3_0,
  121947. 9,
  121948. 9
  121949. };
  121950. static static_codebook _44c0_s_p3_0 = {
  121951. 2, 81,
  121952. _vq_lengthlist__44c0_s_p3_0,
  121953. 1, -531628032, 1611661312, 4, 0,
  121954. _vq_quantlist__44c0_s_p3_0,
  121955. NULL,
  121956. &_vq_auxt__44c0_s_p3_0,
  121957. NULL,
  121958. 0
  121959. };
  121960. static long _vq_quantlist__44c0_s_p4_0[] = {
  121961. 4,
  121962. 3,
  121963. 5,
  121964. 2,
  121965. 6,
  121966. 1,
  121967. 7,
  121968. 0,
  121969. 8,
  121970. };
  121971. static long _vq_lengthlist__44c0_s_p4_0[] = {
  121972. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  121973. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  121974. 7, 8, 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0,
  121975. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 9, 8, 8,10,10, 0,
  121976. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  121977. 10,
  121978. };
  121979. static float _vq_quantthresh__44c0_s_p4_0[] = {
  121980. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  121981. };
  121982. static long _vq_quantmap__44c0_s_p4_0[] = {
  121983. 7, 5, 3, 1, 0, 2, 4, 6,
  121984. 8,
  121985. };
  121986. static encode_aux_threshmatch _vq_auxt__44c0_s_p4_0 = {
  121987. _vq_quantthresh__44c0_s_p4_0,
  121988. _vq_quantmap__44c0_s_p4_0,
  121989. 9,
  121990. 9
  121991. };
  121992. static static_codebook _44c0_s_p4_0 = {
  121993. 2, 81,
  121994. _vq_lengthlist__44c0_s_p4_0,
  121995. 1, -531628032, 1611661312, 4, 0,
  121996. _vq_quantlist__44c0_s_p4_0,
  121997. NULL,
  121998. &_vq_auxt__44c0_s_p4_0,
  121999. NULL,
  122000. 0
  122001. };
  122002. static long _vq_quantlist__44c0_s_p5_0[] = {
  122003. 8,
  122004. 7,
  122005. 9,
  122006. 6,
  122007. 10,
  122008. 5,
  122009. 11,
  122010. 4,
  122011. 12,
  122012. 3,
  122013. 13,
  122014. 2,
  122015. 14,
  122016. 1,
  122017. 15,
  122018. 0,
  122019. 16,
  122020. };
  122021. static long _vq_lengthlist__44c0_s_p5_0[] = {
  122022. 1, 4, 3, 6, 6, 8, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  122023. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9, 9,10,10,10,
  122024. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  122025. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  122026. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  122027. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  122028. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  122029. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  122030. 10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  122031. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  122032. 10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  122033. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  122034. 10,10,11,11,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  122035. 0, 0, 0,11,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  122036. 0, 0, 0, 0,11,11,12,11,12,12,12,12,13,13, 0, 0,
  122037. 0, 0, 0, 0, 0,11,11,11,12,12,12,12,13,13,13, 0,
  122038. 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,13,14,14,
  122039. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  122040. 14,
  122041. };
  122042. static float _vq_quantthresh__44c0_s_p5_0[] = {
  122043. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122044. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122045. };
  122046. static long _vq_quantmap__44c0_s_p5_0[] = {
  122047. 15, 13, 11, 9, 7, 5, 3, 1,
  122048. 0, 2, 4, 6, 8, 10, 12, 14,
  122049. 16,
  122050. };
  122051. static encode_aux_threshmatch _vq_auxt__44c0_s_p5_0 = {
  122052. _vq_quantthresh__44c0_s_p5_0,
  122053. _vq_quantmap__44c0_s_p5_0,
  122054. 17,
  122055. 17
  122056. };
  122057. static static_codebook _44c0_s_p5_0 = {
  122058. 2, 289,
  122059. _vq_lengthlist__44c0_s_p5_0,
  122060. 1, -529530880, 1611661312, 5, 0,
  122061. _vq_quantlist__44c0_s_p5_0,
  122062. NULL,
  122063. &_vq_auxt__44c0_s_p5_0,
  122064. NULL,
  122065. 0
  122066. };
  122067. static long _vq_quantlist__44c0_s_p6_0[] = {
  122068. 1,
  122069. 0,
  122070. 2,
  122071. };
  122072. static long _vq_lengthlist__44c0_s_p6_0[] = {
  122073. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  122074. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  122075. 11,12,10,11, 6, 9, 9,11,10,11,11,10,10, 6, 9, 9,
  122076. 11,10,11,11,10,10, 7,11,10,12,11,11,11,11,11, 7,
  122077. 9, 9,10,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  122078. 10,
  122079. };
  122080. static float _vq_quantthresh__44c0_s_p6_0[] = {
  122081. -5.5, 5.5,
  122082. };
  122083. static long _vq_quantmap__44c0_s_p6_0[] = {
  122084. 1, 0, 2,
  122085. };
  122086. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_0 = {
  122087. _vq_quantthresh__44c0_s_p6_0,
  122088. _vq_quantmap__44c0_s_p6_0,
  122089. 3,
  122090. 3
  122091. };
  122092. static static_codebook _44c0_s_p6_0 = {
  122093. 4, 81,
  122094. _vq_lengthlist__44c0_s_p6_0,
  122095. 1, -529137664, 1618345984, 2, 0,
  122096. _vq_quantlist__44c0_s_p6_0,
  122097. NULL,
  122098. &_vq_auxt__44c0_s_p6_0,
  122099. NULL,
  122100. 0
  122101. };
  122102. static long _vq_quantlist__44c0_s_p6_1[] = {
  122103. 5,
  122104. 4,
  122105. 6,
  122106. 3,
  122107. 7,
  122108. 2,
  122109. 8,
  122110. 1,
  122111. 9,
  122112. 0,
  122113. 10,
  122114. };
  122115. static long _vq_lengthlist__44c0_s_p6_1[] = {
  122116. 2, 3, 3, 6, 6, 7, 7, 7, 7, 7, 8,10,10,10, 6, 6,
  122117. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  122118. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  122119. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  122120. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  122121. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  122122. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  122123. 10,10,10, 8, 8, 8, 8, 8, 8,
  122124. };
  122125. static float _vq_quantthresh__44c0_s_p6_1[] = {
  122126. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  122127. 3.5, 4.5,
  122128. };
  122129. static long _vq_quantmap__44c0_s_p6_1[] = {
  122130. 9, 7, 5, 3, 1, 0, 2, 4,
  122131. 6, 8, 10,
  122132. };
  122133. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_1 = {
  122134. _vq_quantthresh__44c0_s_p6_1,
  122135. _vq_quantmap__44c0_s_p6_1,
  122136. 11,
  122137. 11
  122138. };
  122139. static static_codebook _44c0_s_p6_1 = {
  122140. 2, 121,
  122141. _vq_lengthlist__44c0_s_p6_1,
  122142. 1, -531365888, 1611661312, 4, 0,
  122143. _vq_quantlist__44c0_s_p6_1,
  122144. NULL,
  122145. &_vq_auxt__44c0_s_p6_1,
  122146. NULL,
  122147. 0
  122148. };
  122149. static long _vq_quantlist__44c0_s_p7_0[] = {
  122150. 6,
  122151. 5,
  122152. 7,
  122153. 4,
  122154. 8,
  122155. 3,
  122156. 9,
  122157. 2,
  122158. 10,
  122159. 1,
  122160. 11,
  122161. 0,
  122162. 12,
  122163. };
  122164. static long _vq_lengthlist__44c0_s_p7_0[] = {
  122165. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  122166. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  122167. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  122168. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  122169. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  122170. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  122171. 10,10,11,11,11,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  122172. 11,11,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  122173. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  122174. 0, 0, 0, 0,11,11,11,11,13,12,13,13, 0, 0, 0, 0,
  122175. 0,12,12,11,11,12,12,13,13,
  122176. };
  122177. static float _vq_quantthresh__44c0_s_p7_0[] = {
  122178. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  122179. 12.5, 17.5, 22.5, 27.5,
  122180. };
  122181. static long _vq_quantmap__44c0_s_p7_0[] = {
  122182. 11, 9, 7, 5, 3, 1, 0, 2,
  122183. 4, 6, 8, 10, 12,
  122184. };
  122185. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_0 = {
  122186. _vq_quantthresh__44c0_s_p7_0,
  122187. _vq_quantmap__44c0_s_p7_0,
  122188. 13,
  122189. 13
  122190. };
  122191. static static_codebook _44c0_s_p7_0 = {
  122192. 2, 169,
  122193. _vq_lengthlist__44c0_s_p7_0,
  122194. 1, -526516224, 1616117760, 4, 0,
  122195. _vq_quantlist__44c0_s_p7_0,
  122196. NULL,
  122197. &_vq_auxt__44c0_s_p7_0,
  122198. NULL,
  122199. 0
  122200. };
  122201. static long _vq_quantlist__44c0_s_p7_1[] = {
  122202. 2,
  122203. 1,
  122204. 3,
  122205. 0,
  122206. 4,
  122207. };
  122208. static long _vq_lengthlist__44c0_s_p7_1[] = {
  122209. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  122210. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  122211. };
  122212. static float _vq_quantthresh__44c0_s_p7_1[] = {
  122213. -1.5, -0.5, 0.5, 1.5,
  122214. };
  122215. static long _vq_quantmap__44c0_s_p7_1[] = {
  122216. 3, 1, 0, 2, 4,
  122217. };
  122218. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_1 = {
  122219. _vq_quantthresh__44c0_s_p7_1,
  122220. _vq_quantmap__44c0_s_p7_1,
  122221. 5,
  122222. 5
  122223. };
  122224. static static_codebook _44c0_s_p7_1 = {
  122225. 2, 25,
  122226. _vq_lengthlist__44c0_s_p7_1,
  122227. 1, -533725184, 1611661312, 3, 0,
  122228. _vq_quantlist__44c0_s_p7_1,
  122229. NULL,
  122230. &_vq_auxt__44c0_s_p7_1,
  122231. NULL,
  122232. 0
  122233. };
  122234. static long _vq_quantlist__44c0_s_p8_0[] = {
  122235. 2,
  122236. 1,
  122237. 3,
  122238. 0,
  122239. 4,
  122240. };
  122241. static long _vq_lengthlist__44c0_s_p8_0[] = {
  122242. 1, 5, 5,10,10, 6, 9, 8,10,10, 6,10, 9,10,10,10,
  122243. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122244. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122245. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122246. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122247. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122248. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122249. 10,10,10,10,10,10,10,10,10,10,10,10,10, 8,10,10,
  122250. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122251. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122252. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122253. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122254. 10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,
  122255. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122256. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122257. 11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,
  122258. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122259. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122260. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122261. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122262. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122263. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122264. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122265. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122266. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122267. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122268. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122269. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122270. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122271. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122272. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122273. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122274. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122275. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122276. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122277. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122278. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122279. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122280. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122281. 11,
  122282. };
  122283. static float _vq_quantthresh__44c0_s_p8_0[] = {
  122284. -331.5, -110.5, 110.5, 331.5,
  122285. };
  122286. static long _vq_quantmap__44c0_s_p8_0[] = {
  122287. 3, 1, 0, 2, 4,
  122288. };
  122289. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_0 = {
  122290. _vq_quantthresh__44c0_s_p8_0,
  122291. _vq_quantmap__44c0_s_p8_0,
  122292. 5,
  122293. 5
  122294. };
  122295. static static_codebook _44c0_s_p8_0 = {
  122296. 4, 625,
  122297. _vq_lengthlist__44c0_s_p8_0,
  122298. 1, -518283264, 1627103232, 3, 0,
  122299. _vq_quantlist__44c0_s_p8_0,
  122300. NULL,
  122301. &_vq_auxt__44c0_s_p8_0,
  122302. NULL,
  122303. 0
  122304. };
  122305. static long _vq_quantlist__44c0_s_p8_1[] = {
  122306. 6,
  122307. 5,
  122308. 7,
  122309. 4,
  122310. 8,
  122311. 3,
  122312. 9,
  122313. 2,
  122314. 10,
  122315. 1,
  122316. 11,
  122317. 0,
  122318. 12,
  122319. };
  122320. static long _vq_lengthlist__44c0_s_p8_1[] = {
  122321. 1, 4, 4, 6, 6, 7, 7, 9, 9,11,12,13,12, 6, 5, 5,
  122322. 7, 7, 8, 8,10, 9,12,12,12,12, 6, 5, 5, 7, 7, 8,
  122323. 8,10, 9,12,11,11,13,16, 7, 7, 8, 8, 9, 9,10,10,
  122324. 12,12,13,12,16, 7, 7, 8, 7, 9, 9,10,10,11,12,12,
  122325. 13,16,10,10, 8, 8,10,10,11,12,12,12,13,13,16,11,
  122326. 10, 8, 7,11,10,11,11,12,11,13,13,16,16,16,10,10,
  122327. 10,10,11,11,13,12,13,13,16,16,16,11, 9,11, 9,15,
  122328. 13,12,13,13,13,16,16,16,15,13,11,11,12,13,12,12,
  122329. 14,13,16,16,16,14,13,11,11,13,12,14,13,13,13,16,
  122330. 16,16,16,16,13,13,13,12,14,13,14,14,16,16,16,16,
  122331. 16,13,13,12,12,14,14,15,13,
  122332. };
  122333. static float _vq_quantthresh__44c0_s_p8_1[] = {
  122334. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  122335. 42.5, 59.5, 76.5, 93.5,
  122336. };
  122337. static long _vq_quantmap__44c0_s_p8_1[] = {
  122338. 11, 9, 7, 5, 3, 1, 0, 2,
  122339. 4, 6, 8, 10, 12,
  122340. };
  122341. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_1 = {
  122342. _vq_quantthresh__44c0_s_p8_1,
  122343. _vq_quantmap__44c0_s_p8_1,
  122344. 13,
  122345. 13
  122346. };
  122347. static static_codebook _44c0_s_p8_1 = {
  122348. 2, 169,
  122349. _vq_lengthlist__44c0_s_p8_1,
  122350. 1, -522616832, 1620115456, 4, 0,
  122351. _vq_quantlist__44c0_s_p8_1,
  122352. NULL,
  122353. &_vq_auxt__44c0_s_p8_1,
  122354. NULL,
  122355. 0
  122356. };
  122357. static long _vq_quantlist__44c0_s_p8_2[] = {
  122358. 8,
  122359. 7,
  122360. 9,
  122361. 6,
  122362. 10,
  122363. 5,
  122364. 11,
  122365. 4,
  122366. 12,
  122367. 3,
  122368. 13,
  122369. 2,
  122370. 14,
  122371. 1,
  122372. 15,
  122373. 0,
  122374. 16,
  122375. };
  122376. static long _vq_lengthlist__44c0_s_p8_2[] = {
  122377. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  122378. 8,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  122379. 9, 9,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  122380. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  122381. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  122382. 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 8, 9, 9,
  122383. 9, 9, 9,10, 9,10,10,10,10, 7, 7, 8, 8, 9, 9, 9,
  122384. 9, 9, 9,10, 9,10,10,10,10,10, 8, 8, 8, 9, 9, 9,
  122385. 9, 9, 9, 9,10,10,10, 9,11,10,10,10,10, 8, 8, 9,
  122386. 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,11,11, 9, 9,
  122387. 9, 9, 9, 9, 9, 9,10, 9, 9,10,11,10,10,11,11, 9,
  122388. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  122389. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,10,11,
  122390. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  122391. 11,11,11,11, 9,10, 9,10, 9, 9, 9, 9,10, 9,10,11,
  122392. 10,11,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9,10,11,
  122393. 11,10,11,11,10,11,10,10,10, 9, 9, 9, 9,10, 9, 9,
  122394. 10,11,10,11,11,11,11,10,11,10,10, 9,10, 9, 9, 9,
  122395. 10,
  122396. };
  122397. static float _vq_quantthresh__44c0_s_p8_2[] = {
  122398. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122399. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122400. };
  122401. static long _vq_quantmap__44c0_s_p8_2[] = {
  122402. 15, 13, 11, 9, 7, 5, 3, 1,
  122403. 0, 2, 4, 6, 8, 10, 12, 14,
  122404. 16,
  122405. };
  122406. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_2 = {
  122407. _vq_quantthresh__44c0_s_p8_2,
  122408. _vq_quantmap__44c0_s_p8_2,
  122409. 17,
  122410. 17
  122411. };
  122412. static static_codebook _44c0_s_p8_2 = {
  122413. 2, 289,
  122414. _vq_lengthlist__44c0_s_p8_2,
  122415. 1, -529530880, 1611661312, 5, 0,
  122416. _vq_quantlist__44c0_s_p8_2,
  122417. NULL,
  122418. &_vq_auxt__44c0_s_p8_2,
  122419. NULL,
  122420. 0
  122421. };
  122422. static long _huff_lengthlist__44c0_s_short[] = {
  122423. 9, 8,12,11,12,13,14,14,16, 6, 1, 5, 6, 6, 9,12,
  122424. 14,17, 9, 4, 5, 9, 7, 9,13,15,16, 8, 5, 8, 6, 8,
  122425. 10,13,17,17, 9, 6, 7, 7, 8, 9,13,15,17,11, 8, 9,
  122426. 9, 9,10,12,16,16,13, 7, 8, 7, 7, 9,12,14,15,13,
  122427. 6, 7, 5, 5, 7,10,13,13,14, 7, 8, 5, 6, 7, 9,10,
  122428. 12,
  122429. };
  122430. static static_codebook _huff_book__44c0_s_short = {
  122431. 2, 81,
  122432. _huff_lengthlist__44c0_s_short,
  122433. 0, 0, 0, 0, 0,
  122434. NULL,
  122435. NULL,
  122436. NULL,
  122437. NULL,
  122438. 0
  122439. };
  122440. static long _huff_lengthlist__44c0_sm_long[] = {
  122441. 5, 4, 9,10, 9,10,11,12,13, 4, 1, 5, 7, 7, 9,11,
  122442. 12,14, 8, 5, 7, 9, 8,10,13,13,13,10, 7, 9, 4, 6,
  122443. 7,10,12,14, 9, 6, 7, 6, 6, 7,10,12,12, 9, 8, 9,
  122444. 7, 6, 7, 8,11,12,11,11,11, 9, 8, 7, 8,10,12,12,
  122445. 13,14,12,11, 9, 9, 9,12,12,17,17,15,16,12,10,11,
  122446. 13,
  122447. };
  122448. static static_codebook _huff_book__44c0_sm_long = {
  122449. 2, 81,
  122450. _huff_lengthlist__44c0_sm_long,
  122451. 0, 0, 0, 0, 0,
  122452. NULL,
  122453. NULL,
  122454. NULL,
  122455. NULL,
  122456. 0
  122457. };
  122458. static long _vq_quantlist__44c0_sm_p1_0[] = {
  122459. 1,
  122460. 0,
  122461. 2,
  122462. };
  122463. static long _vq_lengthlist__44c0_sm_p1_0[] = {
  122464. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  122465. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  122470. 0, 0, 0, 7, 8, 9, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  122475. 0, 0, 0, 0, 7, 9, 9, 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, 5, 8, 7, 0, 0, 0, 0,
  122510. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  122515. 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  122520. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  122556. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  122561. 0, 0, 0, 0, 0, 9, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  122566. 0, 0, 0, 0, 0, 0, 9,10,10, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122874. 0,
  122875. };
  122876. static float _vq_quantthresh__44c0_sm_p1_0[] = {
  122877. -0.5, 0.5,
  122878. };
  122879. static long _vq_quantmap__44c0_sm_p1_0[] = {
  122880. 1, 0, 2,
  122881. };
  122882. static encode_aux_threshmatch _vq_auxt__44c0_sm_p1_0 = {
  122883. _vq_quantthresh__44c0_sm_p1_0,
  122884. _vq_quantmap__44c0_sm_p1_0,
  122885. 3,
  122886. 3
  122887. };
  122888. static static_codebook _44c0_sm_p1_0 = {
  122889. 8, 6561,
  122890. _vq_lengthlist__44c0_sm_p1_0,
  122891. 1, -535822336, 1611661312, 2, 0,
  122892. _vq_quantlist__44c0_sm_p1_0,
  122893. NULL,
  122894. &_vq_auxt__44c0_sm_p1_0,
  122895. NULL,
  122896. 0
  122897. };
  122898. static long _vq_quantlist__44c0_sm_p2_0[] = {
  122899. 2,
  122900. 1,
  122901. 3,
  122902. 0,
  122903. 4,
  122904. };
  122905. static long _vq_lengthlist__44c0_sm_p2_0[] = {
  122906. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  122908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122909. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  122911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122912. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  122913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122945. 0,
  122946. };
  122947. static float _vq_quantthresh__44c0_sm_p2_0[] = {
  122948. -1.5, -0.5, 0.5, 1.5,
  122949. };
  122950. static long _vq_quantmap__44c0_sm_p2_0[] = {
  122951. 3, 1, 0, 2, 4,
  122952. };
  122953. static encode_aux_threshmatch _vq_auxt__44c0_sm_p2_0 = {
  122954. _vq_quantthresh__44c0_sm_p2_0,
  122955. _vq_quantmap__44c0_sm_p2_0,
  122956. 5,
  122957. 5
  122958. };
  122959. static static_codebook _44c0_sm_p2_0 = {
  122960. 4, 625,
  122961. _vq_lengthlist__44c0_sm_p2_0,
  122962. 1, -533725184, 1611661312, 3, 0,
  122963. _vq_quantlist__44c0_sm_p2_0,
  122964. NULL,
  122965. &_vq_auxt__44c0_sm_p2_0,
  122966. NULL,
  122967. 0
  122968. };
  122969. static long _vq_quantlist__44c0_sm_p3_0[] = {
  122970. 4,
  122971. 3,
  122972. 5,
  122973. 2,
  122974. 6,
  122975. 1,
  122976. 7,
  122977. 0,
  122978. 8,
  122979. };
  122980. static long _vq_lengthlist__44c0_sm_p3_0[] = {
  122981. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 4, 7, 7, 0, 0,
  122982. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  122983. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  122984. 9,10, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  122985. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122986. 0,
  122987. };
  122988. static float _vq_quantthresh__44c0_sm_p3_0[] = {
  122989. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122990. };
  122991. static long _vq_quantmap__44c0_sm_p3_0[] = {
  122992. 7, 5, 3, 1, 0, 2, 4, 6,
  122993. 8,
  122994. };
  122995. static encode_aux_threshmatch _vq_auxt__44c0_sm_p3_0 = {
  122996. _vq_quantthresh__44c0_sm_p3_0,
  122997. _vq_quantmap__44c0_sm_p3_0,
  122998. 9,
  122999. 9
  123000. };
  123001. static static_codebook _44c0_sm_p3_0 = {
  123002. 2, 81,
  123003. _vq_lengthlist__44c0_sm_p3_0,
  123004. 1, -531628032, 1611661312, 4, 0,
  123005. _vq_quantlist__44c0_sm_p3_0,
  123006. NULL,
  123007. &_vq_auxt__44c0_sm_p3_0,
  123008. NULL,
  123009. 0
  123010. };
  123011. static long _vq_quantlist__44c0_sm_p4_0[] = {
  123012. 4,
  123013. 3,
  123014. 5,
  123015. 2,
  123016. 6,
  123017. 1,
  123018. 7,
  123019. 0,
  123020. 8,
  123021. };
  123022. static long _vq_lengthlist__44c0_sm_p4_0[] = {
  123023. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  123024. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  123025. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  123026. 9, 9, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  123027. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  123028. 11,
  123029. };
  123030. static float _vq_quantthresh__44c0_sm_p4_0[] = {
  123031. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123032. };
  123033. static long _vq_quantmap__44c0_sm_p4_0[] = {
  123034. 7, 5, 3, 1, 0, 2, 4, 6,
  123035. 8,
  123036. };
  123037. static encode_aux_threshmatch _vq_auxt__44c0_sm_p4_0 = {
  123038. _vq_quantthresh__44c0_sm_p4_0,
  123039. _vq_quantmap__44c0_sm_p4_0,
  123040. 9,
  123041. 9
  123042. };
  123043. static static_codebook _44c0_sm_p4_0 = {
  123044. 2, 81,
  123045. _vq_lengthlist__44c0_sm_p4_0,
  123046. 1, -531628032, 1611661312, 4, 0,
  123047. _vq_quantlist__44c0_sm_p4_0,
  123048. NULL,
  123049. &_vq_auxt__44c0_sm_p4_0,
  123050. NULL,
  123051. 0
  123052. };
  123053. static long _vq_quantlist__44c0_sm_p5_0[] = {
  123054. 8,
  123055. 7,
  123056. 9,
  123057. 6,
  123058. 10,
  123059. 5,
  123060. 11,
  123061. 4,
  123062. 12,
  123063. 3,
  123064. 13,
  123065. 2,
  123066. 14,
  123067. 1,
  123068. 15,
  123069. 0,
  123070. 16,
  123071. };
  123072. static long _vq_lengthlist__44c0_sm_p5_0[] = {
  123073. 1, 4, 4, 6, 6, 8, 8, 8, 8, 8, 8, 9, 9,10,10,11,
  123074. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  123075. 11,11, 0, 5, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  123076. 11,11,11, 0, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  123077. 11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,
  123078. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  123079. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  123080. 10,11,11,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  123081. 10,10,11,11,12,12,12,13, 0, 0, 0, 0, 0, 9, 9,10,
  123082. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  123083. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  123084. 9,10,10,11,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  123085. 10,10,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0,
  123086. 0, 0, 0,10,10,11,11,12,12,12,13,13,13, 0, 0, 0,
  123087. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  123088. 0, 0, 0, 0, 0,11,11,12,11,12,12,13,13,13,13, 0,
  123089. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  123090. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  123091. 14,
  123092. };
  123093. static float _vq_quantthresh__44c0_sm_p5_0[] = {
  123094. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123095. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123096. };
  123097. static long _vq_quantmap__44c0_sm_p5_0[] = {
  123098. 15, 13, 11, 9, 7, 5, 3, 1,
  123099. 0, 2, 4, 6, 8, 10, 12, 14,
  123100. 16,
  123101. };
  123102. static encode_aux_threshmatch _vq_auxt__44c0_sm_p5_0 = {
  123103. _vq_quantthresh__44c0_sm_p5_0,
  123104. _vq_quantmap__44c0_sm_p5_0,
  123105. 17,
  123106. 17
  123107. };
  123108. static static_codebook _44c0_sm_p5_0 = {
  123109. 2, 289,
  123110. _vq_lengthlist__44c0_sm_p5_0,
  123111. 1, -529530880, 1611661312, 5, 0,
  123112. _vq_quantlist__44c0_sm_p5_0,
  123113. NULL,
  123114. &_vq_auxt__44c0_sm_p5_0,
  123115. NULL,
  123116. 0
  123117. };
  123118. static long _vq_quantlist__44c0_sm_p6_0[] = {
  123119. 1,
  123120. 0,
  123121. 2,
  123122. };
  123123. static long _vq_lengthlist__44c0_sm_p6_0[] = {
  123124. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  123125. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  123126. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  123127. 11,10,11,11,10,10, 7,11,10,11,11,11,11,11,11, 6,
  123128. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  123129. 11,
  123130. };
  123131. static float _vq_quantthresh__44c0_sm_p6_0[] = {
  123132. -5.5, 5.5,
  123133. };
  123134. static long _vq_quantmap__44c0_sm_p6_0[] = {
  123135. 1, 0, 2,
  123136. };
  123137. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_0 = {
  123138. _vq_quantthresh__44c0_sm_p6_0,
  123139. _vq_quantmap__44c0_sm_p6_0,
  123140. 3,
  123141. 3
  123142. };
  123143. static static_codebook _44c0_sm_p6_0 = {
  123144. 4, 81,
  123145. _vq_lengthlist__44c0_sm_p6_0,
  123146. 1, -529137664, 1618345984, 2, 0,
  123147. _vq_quantlist__44c0_sm_p6_0,
  123148. NULL,
  123149. &_vq_auxt__44c0_sm_p6_0,
  123150. NULL,
  123151. 0
  123152. };
  123153. static long _vq_quantlist__44c0_sm_p6_1[] = {
  123154. 5,
  123155. 4,
  123156. 6,
  123157. 3,
  123158. 7,
  123159. 2,
  123160. 8,
  123161. 1,
  123162. 9,
  123163. 0,
  123164. 10,
  123165. };
  123166. static long _vq_lengthlist__44c0_sm_p6_1[] = {
  123167. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 8, 9, 5, 5, 6, 6,
  123168. 7, 7, 8, 8, 8, 8, 9, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  123169. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  123170. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  123171. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  123172. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  123173. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  123174. 10,10,10, 8, 8, 8, 8, 8, 8,
  123175. };
  123176. static float _vq_quantthresh__44c0_sm_p6_1[] = {
  123177. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  123178. 3.5, 4.5,
  123179. };
  123180. static long _vq_quantmap__44c0_sm_p6_1[] = {
  123181. 9, 7, 5, 3, 1, 0, 2, 4,
  123182. 6, 8, 10,
  123183. };
  123184. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_1 = {
  123185. _vq_quantthresh__44c0_sm_p6_1,
  123186. _vq_quantmap__44c0_sm_p6_1,
  123187. 11,
  123188. 11
  123189. };
  123190. static static_codebook _44c0_sm_p6_1 = {
  123191. 2, 121,
  123192. _vq_lengthlist__44c0_sm_p6_1,
  123193. 1, -531365888, 1611661312, 4, 0,
  123194. _vq_quantlist__44c0_sm_p6_1,
  123195. NULL,
  123196. &_vq_auxt__44c0_sm_p6_1,
  123197. NULL,
  123198. 0
  123199. };
  123200. static long _vq_quantlist__44c0_sm_p7_0[] = {
  123201. 6,
  123202. 5,
  123203. 7,
  123204. 4,
  123205. 8,
  123206. 3,
  123207. 9,
  123208. 2,
  123209. 10,
  123210. 1,
  123211. 11,
  123212. 0,
  123213. 12,
  123214. };
  123215. static long _vq_lengthlist__44c0_sm_p7_0[] = {
  123216. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  123217. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  123218. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  123219. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  123220. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  123221. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0, 9,10,
  123222. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  123223. 11,12,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  123224. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  123225. 0, 0, 0, 0,11,12,11,11,13,12,13,13, 0, 0, 0, 0,
  123226. 0,12,12,11,11,13,12,14,14,
  123227. };
  123228. static float _vq_quantthresh__44c0_sm_p7_0[] = {
  123229. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  123230. 12.5, 17.5, 22.5, 27.5,
  123231. };
  123232. static long _vq_quantmap__44c0_sm_p7_0[] = {
  123233. 11, 9, 7, 5, 3, 1, 0, 2,
  123234. 4, 6, 8, 10, 12,
  123235. };
  123236. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_0 = {
  123237. _vq_quantthresh__44c0_sm_p7_0,
  123238. _vq_quantmap__44c0_sm_p7_0,
  123239. 13,
  123240. 13
  123241. };
  123242. static static_codebook _44c0_sm_p7_0 = {
  123243. 2, 169,
  123244. _vq_lengthlist__44c0_sm_p7_0,
  123245. 1, -526516224, 1616117760, 4, 0,
  123246. _vq_quantlist__44c0_sm_p7_0,
  123247. NULL,
  123248. &_vq_auxt__44c0_sm_p7_0,
  123249. NULL,
  123250. 0
  123251. };
  123252. static long _vq_quantlist__44c0_sm_p7_1[] = {
  123253. 2,
  123254. 1,
  123255. 3,
  123256. 0,
  123257. 4,
  123258. };
  123259. static long _vq_lengthlist__44c0_sm_p7_1[] = {
  123260. 2, 4, 4, 4, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  123261. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  123262. };
  123263. static float _vq_quantthresh__44c0_sm_p7_1[] = {
  123264. -1.5, -0.5, 0.5, 1.5,
  123265. };
  123266. static long _vq_quantmap__44c0_sm_p7_1[] = {
  123267. 3, 1, 0, 2, 4,
  123268. };
  123269. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_1 = {
  123270. _vq_quantthresh__44c0_sm_p7_1,
  123271. _vq_quantmap__44c0_sm_p7_1,
  123272. 5,
  123273. 5
  123274. };
  123275. static static_codebook _44c0_sm_p7_1 = {
  123276. 2, 25,
  123277. _vq_lengthlist__44c0_sm_p7_1,
  123278. 1, -533725184, 1611661312, 3, 0,
  123279. _vq_quantlist__44c0_sm_p7_1,
  123280. NULL,
  123281. &_vq_auxt__44c0_sm_p7_1,
  123282. NULL,
  123283. 0
  123284. };
  123285. static long _vq_quantlist__44c0_sm_p8_0[] = {
  123286. 4,
  123287. 3,
  123288. 5,
  123289. 2,
  123290. 6,
  123291. 1,
  123292. 7,
  123293. 0,
  123294. 8,
  123295. };
  123296. static long _vq_lengthlist__44c0_sm_p8_0[] = {
  123297. 1, 3, 3,11,11,11,11,11,11, 3, 7, 6,11,11,11,11,
  123298. 11,11, 4, 8, 7,11,11,11,11,11,11,11,11,11,11,11,
  123299. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123300. 11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123301. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123302. 12,
  123303. };
  123304. static float _vq_quantthresh__44c0_sm_p8_0[] = {
  123305. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  123306. };
  123307. static long _vq_quantmap__44c0_sm_p8_0[] = {
  123308. 7, 5, 3, 1, 0, 2, 4, 6,
  123309. 8,
  123310. };
  123311. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_0 = {
  123312. _vq_quantthresh__44c0_sm_p8_0,
  123313. _vq_quantmap__44c0_sm_p8_0,
  123314. 9,
  123315. 9
  123316. };
  123317. static static_codebook _44c0_sm_p8_0 = {
  123318. 2, 81,
  123319. _vq_lengthlist__44c0_sm_p8_0,
  123320. 1, -516186112, 1627103232, 4, 0,
  123321. _vq_quantlist__44c0_sm_p8_0,
  123322. NULL,
  123323. &_vq_auxt__44c0_sm_p8_0,
  123324. NULL,
  123325. 0
  123326. };
  123327. static long _vq_quantlist__44c0_sm_p8_1[] = {
  123328. 6,
  123329. 5,
  123330. 7,
  123331. 4,
  123332. 8,
  123333. 3,
  123334. 9,
  123335. 2,
  123336. 10,
  123337. 1,
  123338. 11,
  123339. 0,
  123340. 12,
  123341. };
  123342. static long _vq_lengthlist__44c0_sm_p8_1[] = {
  123343. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  123344. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  123345. 8,10,10,12,11,12,12,17, 7, 7, 8, 8, 9, 9,10,10,
  123346. 12,12,13,13,18, 7, 7, 8, 7, 9, 9,10,10,12,12,12,
  123347. 13,19,10,10, 8, 8,10,10,11,11,12,12,13,14,19,11,
  123348. 10, 8, 7,10,10,11,11,12,12,13,12,19,19,19,10,10,
  123349. 10,10,11,11,12,12,13,13,19,19,19,11, 9,11, 9,14,
  123350. 12,13,12,13,13,19,20,18,13,14,11,11,12,12,13,13,
  123351. 14,13,20,20,20,15,13,11,10,13,11,13,13,14,13,20,
  123352. 20,20,20,20,13,14,12,12,13,13,13,13,20,20,20,20,
  123353. 20,13,13,12,12,16,13,15,13,
  123354. };
  123355. static float _vq_quantthresh__44c0_sm_p8_1[] = {
  123356. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  123357. 42.5, 59.5, 76.5, 93.5,
  123358. };
  123359. static long _vq_quantmap__44c0_sm_p8_1[] = {
  123360. 11, 9, 7, 5, 3, 1, 0, 2,
  123361. 4, 6, 8, 10, 12,
  123362. };
  123363. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_1 = {
  123364. _vq_quantthresh__44c0_sm_p8_1,
  123365. _vq_quantmap__44c0_sm_p8_1,
  123366. 13,
  123367. 13
  123368. };
  123369. static static_codebook _44c0_sm_p8_1 = {
  123370. 2, 169,
  123371. _vq_lengthlist__44c0_sm_p8_1,
  123372. 1, -522616832, 1620115456, 4, 0,
  123373. _vq_quantlist__44c0_sm_p8_1,
  123374. NULL,
  123375. &_vq_auxt__44c0_sm_p8_1,
  123376. NULL,
  123377. 0
  123378. };
  123379. static long _vq_quantlist__44c0_sm_p8_2[] = {
  123380. 8,
  123381. 7,
  123382. 9,
  123383. 6,
  123384. 10,
  123385. 5,
  123386. 11,
  123387. 4,
  123388. 12,
  123389. 3,
  123390. 13,
  123391. 2,
  123392. 14,
  123393. 1,
  123394. 15,
  123395. 0,
  123396. 16,
  123397. };
  123398. static long _vq_lengthlist__44c0_sm_p8_2[] = {
  123399. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  123400. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  123401. 9, 9,10, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  123402. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  123403. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  123404. 9,10, 9, 9,10,10,10,11, 8, 8, 8, 8, 9, 9, 9, 9,
  123405. 9, 9, 9,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  123406. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  123407. 9, 9, 9, 9, 9, 9,10,10,10,10,10,11,11, 8, 8, 9,
  123408. 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,11,11,11, 9, 9,
  123409. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,10,11,11, 9,
  123410. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  123411. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,11,11,
  123412. 11,11,11, 9, 9,10, 9, 9, 9, 9, 9, 9, 9,10,11,10,
  123413. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  123414. 11,11,11,11,11, 9,10, 9, 9, 9, 9, 9, 9, 9, 9,11,
  123415. 11,10,11,11,11,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  123416. 10,11,10,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  123417. 9,
  123418. };
  123419. static float _vq_quantthresh__44c0_sm_p8_2[] = {
  123420. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123421. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123422. };
  123423. static long _vq_quantmap__44c0_sm_p8_2[] = {
  123424. 15, 13, 11, 9, 7, 5, 3, 1,
  123425. 0, 2, 4, 6, 8, 10, 12, 14,
  123426. 16,
  123427. };
  123428. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_2 = {
  123429. _vq_quantthresh__44c0_sm_p8_2,
  123430. _vq_quantmap__44c0_sm_p8_2,
  123431. 17,
  123432. 17
  123433. };
  123434. static static_codebook _44c0_sm_p8_2 = {
  123435. 2, 289,
  123436. _vq_lengthlist__44c0_sm_p8_2,
  123437. 1, -529530880, 1611661312, 5, 0,
  123438. _vq_quantlist__44c0_sm_p8_2,
  123439. NULL,
  123440. &_vq_auxt__44c0_sm_p8_2,
  123441. NULL,
  123442. 0
  123443. };
  123444. static long _huff_lengthlist__44c0_sm_short[] = {
  123445. 6, 6,12,13,13,14,16,17,17, 4, 2, 5, 8, 7, 9,12,
  123446. 15,15, 9, 4, 5, 9, 7, 9,12,16,18,11, 6, 7, 4, 6,
  123447. 8,11,14,18,10, 5, 6, 5, 5, 7,10,14,17,10, 5, 7,
  123448. 7, 6, 7,10,13,16,11, 5, 7, 7, 7, 8,10,12,15,13,
  123449. 6, 7, 5, 5, 7, 9,12,13,16, 8, 9, 6, 6, 7, 9,10,
  123450. 12,
  123451. };
  123452. static static_codebook _huff_book__44c0_sm_short = {
  123453. 2, 81,
  123454. _huff_lengthlist__44c0_sm_short,
  123455. 0, 0, 0, 0, 0,
  123456. NULL,
  123457. NULL,
  123458. NULL,
  123459. NULL,
  123460. 0
  123461. };
  123462. static long _huff_lengthlist__44c1_s_long[] = {
  123463. 5, 5, 9,10, 9, 9,10,11,12, 5, 1, 5, 6, 6, 7,10,
  123464. 12,14, 9, 5, 6, 8, 8,10,12,14,14,10, 5, 8, 5, 6,
  123465. 8,11,13,14, 9, 5, 7, 6, 6, 8,10,12,11, 9, 7, 9,
  123466. 7, 6, 6, 7,10,10,10, 9,12, 9, 8, 7, 7,10,12,11,
  123467. 11,13,12,10, 9, 8, 9,11,11,14,15,15,13,11, 9, 9,
  123468. 11,
  123469. };
  123470. static static_codebook _huff_book__44c1_s_long = {
  123471. 2, 81,
  123472. _huff_lengthlist__44c1_s_long,
  123473. 0, 0, 0, 0, 0,
  123474. NULL,
  123475. NULL,
  123476. NULL,
  123477. NULL,
  123478. 0
  123479. };
  123480. static long _vq_quantlist__44c1_s_p1_0[] = {
  123481. 1,
  123482. 0,
  123483. 2,
  123484. };
  123485. static long _vq_lengthlist__44c1_s_p1_0[] = {
  123486. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 6, 0, 0, 0, 0,
  123487. 0, 0, 5, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  123492. 0, 0, 0, 7, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123497. 0, 0, 0, 0, 7, 8, 8, 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, 4, 7, 7, 0, 0, 0, 0,
  123532. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  123537. 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  123542. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123578. 0, 0, 0, 0, 7, 8, 9, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8,10, 9, 0,
  123583. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  123588. 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123896. 0,
  123897. };
  123898. static float _vq_quantthresh__44c1_s_p1_0[] = {
  123899. -0.5, 0.5,
  123900. };
  123901. static long _vq_quantmap__44c1_s_p1_0[] = {
  123902. 1, 0, 2,
  123903. };
  123904. static encode_aux_threshmatch _vq_auxt__44c1_s_p1_0 = {
  123905. _vq_quantthresh__44c1_s_p1_0,
  123906. _vq_quantmap__44c1_s_p1_0,
  123907. 3,
  123908. 3
  123909. };
  123910. static static_codebook _44c1_s_p1_0 = {
  123911. 8, 6561,
  123912. _vq_lengthlist__44c1_s_p1_0,
  123913. 1, -535822336, 1611661312, 2, 0,
  123914. _vq_quantlist__44c1_s_p1_0,
  123915. NULL,
  123916. &_vq_auxt__44c1_s_p1_0,
  123917. NULL,
  123918. 0
  123919. };
  123920. static long _vq_quantlist__44c1_s_p2_0[] = {
  123921. 2,
  123922. 1,
  123923. 3,
  123924. 0,
  123925. 4,
  123926. };
  123927. static long _vq_lengthlist__44c1_s_p2_0[] = {
  123928. 2, 3, 4, 6, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  123930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123931. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  123933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123934. 0, 0, 0, 0, 6, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  123935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123967. 0,
  123968. };
  123969. static float _vq_quantthresh__44c1_s_p2_0[] = {
  123970. -1.5, -0.5, 0.5, 1.5,
  123971. };
  123972. static long _vq_quantmap__44c1_s_p2_0[] = {
  123973. 3, 1, 0, 2, 4,
  123974. };
  123975. static encode_aux_threshmatch _vq_auxt__44c1_s_p2_0 = {
  123976. _vq_quantthresh__44c1_s_p2_0,
  123977. _vq_quantmap__44c1_s_p2_0,
  123978. 5,
  123979. 5
  123980. };
  123981. static static_codebook _44c1_s_p2_0 = {
  123982. 4, 625,
  123983. _vq_lengthlist__44c1_s_p2_0,
  123984. 1, -533725184, 1611661312, 3, 0,
  123985. _vq_quantlist__44c1_s_p2_0,
  123986. NULL,
  123987. &_vq_auxt__44c1_s_p2_0,
  123988. NULL,
  123989. 0
  123990. };
  123991. static long _vq_quantlist__44c1_s_p3_0[] = {
  123992. 4,
  123993. 3,
  123994. 5,
  123995. 2,
  123996. 6,
  123997. 1,
  123998. 7,
  123999. 0,
  124000. 8,
  124001. };
  124002. static long _vq_lengthlist__44c1_s_p3_0[] = {
  124003. 1, 3, 2, 7, 7, 0, 0, 0, 0, 0,13,13, 6, 6, 0, 0,
  124004. 0, 0, 0,12, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  124005. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  124006. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  124007. 0, 0,11,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124008. 0,
  124009. };
  124010. static float _vq_quantthresh__44c1_s_p3_0[] = {
  124011. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124012. };
  124013. static long _vq_quantmap__44c1_s_p3_0[] = {
  124014. 7, 5, 3, 1, 0, 2, 4, 6,
  124015. 8,
  124016. };
  124017. static encode_aux_threshmatch _vq_auxt__44c1_s_p3_0 = {
  124018. _vq_quantthresh__44c1_s_p3_0,
  124019. _vq_quantmap__44c1_s_p3_0,
  124020. 9,
  124021. 9
  124022. };
  124023. static static_codebook _44c1_s_p3_0 = {
  124024. 2, 81,
  124025. _vq_lengthlist__44c1_s_p3_0,
  124026. 1, -531628032, 1611661312, 4, 0,
  124027. _vq_quantlist__44c1_s_p3_0,
  124028. NULL,
  124029. &_vq_auxt__44c1_s_p3_0,
  124030. NULL,
  124031. 0
  124032. };
  124033. static long _vq_quantlist__44c1_s_p4_0[] = {
  124034. 4,
  124035. 3,
  124036. 5,
  124037. 2,
  124038. 6,
  124039. 1,
  124040. 7,
  124041. 0,
  124042. 8,
  124043. };
  124044. static long _vq_lengthlist__44c1_s_p4_0[] = {
  124045. 1, 3, 3, 6, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  124046. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  124047. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  124048. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  124049. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  124050. 11,
  124051. };
  124052. static float _vq_quantthresh__44c1_s_p4_0[] = {
  124053. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124054. };
  124055. static long _vq_quantmap__44c1_s_p4_0[] = {
  124056. 7, 5, 3, 1, 0, 2, 4, 6,
  124057. 8,
  124058. };
  124059. static encode_aux_threshmatch _vq_auxt__44c1_s_p4_0 = {
  124060. _vq_quantthresh__44c1_s_p4_0,
  124061. _vq_quantmap__44c1_s_p4_0,
  124062. 9,
  124063. 9
  124064. };
  124065. static static_codebook _44c1_s_p4_0 = {
  124066. 2, 81,
  124067. _vq_lengthlist__44c1_s_p4_0,
  124068. 1, -531628032, 1611661312, 4, 0,
  124069. _vq_quantlist__44c1_s_p4_0,
  124070. NULL,
  124071. &_vq_auxt__44c1_s_p4_0,
  124072. NULL,
  124073. 0
  124074. };
  124075. static long _vq_quantlist__44c1_s_p5_0[] = {
  124076. 8,
  124077. 7,
  124078. 9,
  124079. 6,
  124080. 10,
  124081. 5,
  124082. 11,
  124083. 4,
  124084. 12,
  124085. 3,
  124086. 13,
  124087. 2,
  124088. 14,
  124089. 1,
  124090. 15,
  124091. 0,
  124092. 16,
  124093. };
  124094. static long _vq_lengthlist__44c1_s_p5_0[] = {
  124095. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  124096. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  124097. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  124098. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  124099. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  124100. 10,11,11,12,11, 0, 0, 0, 8, 8, 9, 9, 9,10,10,10,
  124101. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10, 9,10,
  124102. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  124103. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  124104. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  124105. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  124106. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  124107. 10,10,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  124108. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  124109. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13, 0, 0,
  124110. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  124111. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,14,14,
  124112. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  124113. 14,
  124114. };
  124115. static float _vq_quantthresh__44c1_s_p5_0[] = {
  124116. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124117. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124118. };
  124119. static long _vq_quantmap__44c1_s_p5_0[] = {
  124120. 15, 13, 11, 9, 7, 5, 3, 1,
  124121. 0, 2, 4, 6, 8, 10, 12, 14,
  124122. 16,
  124123. };
  124124. static encode_aux_threshmatch _vq_auxt__44c1_s_p5_0 = {
  124125. _vq_quantthresh__44c1_s_p5_0,
  124126. _vq_quantmap__44c1_s_p5_0,
  124127. 17,
  124128. 17
  124129. };
  124130. static static_codebook _44c1_s_p5_0 = {
  124131. 2, 289,
  124132. _vq_lengthlist__44c1_s_p5_0,
  124133. 1, -529530880, 1611661312, 5, 0,
  124134. _vq_quantlist__44c1_s_p5_0,
  124135. NULL,
  124136. &_vq_auxt__44c1_s_p5_0,
  124137. NULL,
  124138. 0
  124139. };
  124140. static long _vq_quantlist__44c1_s_p6_0[] = {
  124141. 1,
  124142. 0,
  124143. 2,
  124144. };
  124145. static long _vq_lengthlist__44c1_s_p6_0[] = {
  124146. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  124147. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 6,10,10,11,11,
  124148. 11,11,10,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  124149. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 7,
  124150. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,12,10,
  124151. 11,
  124152. };
  124153. static float _vq_quantthresh__44c1_s_p6_0[] = {
  124154. -5.5, 5.5,
  124155. };
  124156. static long _vq_quantmap__44c1_s_p6_0[] = {
  124157. 1, 0, 2,
  124158. };
  124159. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_0 = {
  124160. _vq_quantthresh__44c1_s_p6_0,
  124161. _vq_quantmap__44c1_s_p6_0,
  124162. 3,
  124163. 3
  124164. };
  124165. static static_codebook _44c1_s_p6_0 = {
  124166. 4, 81,
  124167. _vq_lengthlist__44c1_s_p6_0,
  124168. 1, -529137664, 1618345984, 2, 0,
  124169. _vq_quantlist__44c1_s_p6_0,
  124170. NULL,
  124171. &_vq_auxt__44c1_s_p6_0,
  124172. NULL,
  124173. 0
  124174. };
  124175. static long _vq_quantlist__44c1_s_p6_1[] = {
  124176. 5,
  124177. 4,
  124178. 6,
  124179. 3,
  124180. 7,
  124181. 2,
  124182. 8,
  124183. 1,
  124184. 9,
  124185. 0,
  124186. 10,
  124187. };
  124188. static long _vq_lengthlist__44c1_s_p6_1[] = {
  124189. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  124190. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  124191. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  124192. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  124193. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  124194. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  124195. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  124196. 10,10,10, 8, 8, 8, 8, 8, 8,
  124197. };
  124198. static float _vq_quantthresh__44c1_s_p6_1[] = {
  124199. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  124200. 3.5, 4.5,
  124201. };
  124202. static long _vq_quantmap__44c1_s_p6_1[] = {
  124203. 9, 7, 5, 3, 1, 0, 2, 4,
  124204. 6, 8, 10,
  124205. };
  124206. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_1 = {
  124207. _vq_quantthresh__44c1_s_p6_1,
  124208. _vq_quantmap__44c1_s_p6_1,
  124209. 11,
  124210. 11
  124211. };
  124212. static static_codebook _44c1_s_p6_1 = {
  124213. 2, 121,
  124214. _vq_lengthlist__44c1_s_p6_1,
  124215. 1, -531365888, 1611661312, 4, 0,
  124216. _vq_quantlist__44c1_s_p6_1,
  124217. NULL,
  124218. &_vq_auxt__44c1_s_p6_1,
  124219. NULL,
  124220. 0
  124221. };
  124222. static long _vq_quantlist__44c1_s_p7_0[] = {
  124223. 6,
  124224. 5,
  124225. 7,
  124226. 4,
  124227. 8,
  124228. 3,
  124229. 9,
  124230. 2,
  124231. 10,
  124232. 1,
  124233. 11,
  124234. 0,
  124235. 12,
  124236. };
  124237. static long _vq_lengthlist__44c1_s_p7_0[] = {
  124238. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 9, 7, 5, 6,
  124239. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  124240. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  124241. 10,10,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  124242. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,11, 0,13,
  124243. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  124244. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10,10, 9,11,
  124245. 11,12,11,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  124246. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  124247. 0, 0, 0, 0,11,12,11,11,12,12,14,13, 0, 0, 0, 0,
  124248. 0,12,11,11,11,13,10,14,13,
  124249. };
  124250. static float _vq_quantthresh__44c1_s_p7_0[] = {
  124251. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  124252. 12.5, 17.5, 22.5, 27.5,
  124253. };
  124254. static long _vq_quantmap__44c1_s_p7_0[] = {
  124255. 11, 9, 7, 5, 3, 1, 0, 2,
  124256. 4, 6, 8, 10, 12,
  124257. };
  124258. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_0 = {
  124259. _vq_quantthresh__44c1_s_p7_0,
  124260. _vq_quantmap__44c1_s_p7_0,
  124261. 13,
  124262. 13
  124263. };
  124264. static static_codebook _44c1_s_p7_0 = {
  124265. 2, 169,
  124266. _vq_lengthlist__44c1_s_p7_0,
  124267. 1, -526516224, 1616117760, 4, 0,
  124268. _vq_quantlist__44c1_s_p7_0,
  124269. NULL,
  124270. &_vq_auxt__44c1_s_p7_0,
  124271. NULL,
  124272. 0
  124273. };
  124274. static long _vq_quantlist__44c1_s_p7_1[] = {
  124275. 2,
  124276. 1,
  124277. 3,
  124278. 0,
  124279. 4,
  124280. };
  124281. static long _vq_lengthlist__44c1_s_p7_1[] = {
  124282. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  124283. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  124284. };
  124285. static float _vq_quantthresh__44c1_s_p7_1[] = {
  124286. -1.5, -0.5, 0.5, 1.5,
  124287. };
  124288. static long _vq_quantmap__44c1_s_p7_1[] = {
  124289. 3, 1, 0, 2, 4,
  124290. };
  124291. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_1 = {
  124292. _vq_quantthresh__44c1_s_p7_1,
  124293. _vq_quantmap__44c1_s_p7_1,
  124294. 5,
  124295. 5
  124296. };
  124297. static static_codebook _44c1_s_p7_1 = {
  124298. 2, 25,
  124299. _vq_lengthlist__44c1_s_p7_1,
  124300. 1, -533725184, 1611661312, 3, 0,
  124301. _vq_quantlist__44c1_s_p7_1,
  124302. NULL,
  124303. &_vq_auxt__44c1_s_p7_1,
  124304. NULL,
  124305. 0
  124306. };
  124307. static long _vq_quantlist__44c1_s_p8_0[] = {
  124308. 6,
  124309. 5,
  124310. 7,
  124311. 4,
  124312. 8,
  124313. 3,
  124314. 9,
  124315. 2,
  124316. 10,
  124317. 1,
  124318. 11,
  124319. 0,
  124320. 12,
  124321. };
  124322. static long _vq_lengthlist__44c1_s_p8_0[] = {
  124323. 1, 4, 3,10,10,10,10,10,10,10,10,10,10, 4, 8, 6,
  124324. 10,10,10,10,10,10,10,10,10,10, 4, 8, 7,10,10,10,
  124325. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124326. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124327. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124328. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124329. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124330. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124331. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124332. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124333. 10,10,10,10,10,10,10,10,10,
  124334. };
  124335. static float _vq_quantthresh__44c1_s_p8_0[] = {
  124336. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  124337. 552.5, 773.5, 994.5, 1215.5,
  124338. };
  124339. static long _vq_quantmap__44c1_s_p8_0[] = {
  124340. 11, 9, 7, 5, 3, 1, 0, 2,
  124341. 4, 6, 8, 10, 12,
  124342. };
  124343. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_0 = {
  124344. _vq_quantthresh__44c1_s_p8_0,
  124345. _vq_quantmap__44c1_s_p8_0,
  124346. 13,
  124347. 13
  124348. };
  124349. static static_codebook _44c1_s_p8_0 = {
  124350. 2, 169,
  124351. _vq_lengthlist__44c1_s_p8_0,
  124352. 1, -514541568, 1627103232, 4, 0,
  124353. _vq_quantlist__44c1_s_p8_0,
  124354. NULL,
  124355. &_vq_auxt__44c1_s_p8_0,
  124356. NULL,
  124357. 0
  124358. };
  124359. static long _vq_quantlist__44c1_s_p8_1[] = {
  124360. 6,
  124361. 5,
  124362. 7,
  124363. 4,
  124364. 8,
  124365. 3,
  124366. 9,
  124367. 2,
  124368. 10,
  124369. 1,
  124370. 11,
  124371. 0,
  124372. 12,
  124373. };
  124374. static long _vq_lengthlist__44c1_s_p8_1[] = {
  124375. 1, 4, 4, 6, 5, 7, 7, 9, 9,10,10,12,12, 6, 5, 5,
  124376. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  124377. 8,10,10,11,11,12,12,15, 7, 7, 8, 8, 9, 9,11,11,
  124378. 12,12,13,12,15, 8, 8, 8, 7, 9, 9,10,10,12,12,13,
  124379. 13,16,11,10, 8, 8,10,10,11,11,12,12,13,13,16,11,
  124380. 11, 9, 8,11,10,11,11,12,12,13,12,16,16,16,10,11,
  124381. 10,11,12,12,12,12,13,13,16,16,16,11, 9,11, 9,14,
  124382. 12,12,12,13,13,16,16,16,12,14,11,12,12,12,13,13,
  124383. 14,13,16,16,16,15,13,12,10,13,10,13,14,13,13,16,
  124384. 16,16,16,16,13,14,12,13,13,12,13,13,16,16,16,16,
  124385. 16,13,12,12,11,14,12,15,13,
  124386. };
  124387. static float _vq_quantthresh__44c1_s_p8_1[] = {
  124388. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  124389. 42.5, 59.5, 76.5, 93.5,
  124390. };
  124391. static long _vq_quantmap__44c1_s_p8_1[] = {
  124392. 11, 9, 7, 5, 3, 1, 0, 2,
  124393. 4, 6, 8, 10, 12,
  124394. };
  124395. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_1 = {
  124396. _vq_quantthresh__44c1_s_p8_1,
  124397. _vq_quantmap__44c1_s_p8_1,
  124398. 13,
  124399. 13
  124400. };
  124401. static static_codebook _44c1_s_p8_1 = {
  124402. 2, 169,
  124403. _vq_lengthlist__44c1_s_p8_1,
  124404. 1, -522616832, 1620115456, 4, 0,
  124405. _vq_quantlist__44c1_s_p8_1,
  124406. NULL,
  124407. &_vq_auxt__44c1_s_p8_1,
  124408. NULL,
  124409. 0
  124410. };
  124411. static long _vq_quantlist__44c1_s_p8_2[] = {
  124412. 8,
  124413. 7,
  124414. 9,
  124415. 6,
  124416. 10,
  124417. 5,
  124418. 11,
  124419. 4,
  124420. 12,
  124421. 3,
  124422. 13,
  124423. 2,
  124424. 14,
  124425. 1,
  124426. 15,
  124427. 0,
  124428. 16,
  124429. };
  124430. static long _vq_lengthlist__44c1_s_p8_2[] = {
  124431. 2, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  124432. 8,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  124433. 9, 9,10,10,10, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  124434. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  124435. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  124436. 9,10, 9, 9,10,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  124437. 9, 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  124438. 9, 9, 9, 9, 9,10,10,11,11,11, 8, 8, 9, 9, 9, 9,
  124439. 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11, 8, 8, 9,
  124440. 9, 9, 9,10, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  124441. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 9,
  124442. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  124443. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10,11,11,
  124444. 11,11,11, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,10,11,11,
  124445. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  124446. 11,11,11,11,11, 9,10, 9, 9, 9, 9,10, 9, 9, 9,11,
  124447. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  124448. 11,11,10,11,11,11,11,10,11, 9, 9, 9, 9, 9, 9, 9,
  124449. 9,
  124450. };
  124451. static float _vq_quantthresh__44c1_s_p8_2[] = {
  124452. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124453. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124454. };
  124455. static long _vq_quantmap__44c1_s_p8_2[] = {
  124456. 15, 13, 11, 9, 7, 5, 3, 1,
  124457. 0, 2, 4, 6, 8, 10, 12, 14,
  124458. 16,
  124459. };
  124460. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_2 = {
  124461. _vq_quantthresh__44c1_s_p8_2,
  124462. _vq_quantmap__44c1_s_p8_2,
  124463. 17,
  124464. 17
  124465. };
  124466. static static_codebook _44c1_s_p8_2 = {
  124467. 2, 289,
  124468. _vq_lengthlist__44c1_s_p8_2,
  124469. 1, -529530880, 1611661312, 5, 0,
  124470. _vq_quantlist__44c1_s_p8_2,
  124471. NULL,
  124472. &_vq_auxt__44c1_s_p8_2,
  124473. NULL,
  124474. 0
  124475. };
  124476. static long _huff_lengthlist__44c1_s_short[] = {
  124477. 6, 8,13,12,13,14,15,16,16, 4, 2, 4, 7, 6, 8,11,
  124478. 13,15,10, 4, 4, 8, 6, 8,11,14,17,11, 5, 6, 5, 6,
  124479. 8,12,14,17,11, 5, 5, 6, 5, 7,10,13,16,12, 6, 7,
  124480. 8, 7, 8,10,13,15,13, 8, 8, 7, 7, 8,10,12,15,15,
  124481. 7, 7, 5, 5, 7, 9,12,14,15, 8, 8, 6, 6, 7, 8,10,
  124482. 11,
  124483. };
  124484. static static_codebook _huff_book__44c1_s_short = {
  124485. 2, 81,
  124486. _huff_lengthlist__44c1_s_short,
  124487. 0, 0, 0, 0, 0,
  124488. NULL,
  124489. NULL,
  124490. NULL,
  124491. NULL,
  124492. 0
  124493. };
  124494. static long _huff_lengthlist__44c1_sm_long[] = {
  124495. 5, 4, 8,10, 9, 9,10,11,12, 4, 2, 5, 6, 6, 8,10,
  124496. 11,13, 8, 4, 6, 8, 7, 9,12,12,14,10, 6, 8, 4, 5,
  124497. 6, 9,11,12, 9, 5, 6, 5, 5, 6, 9,11,11, 9, 7, 9,
  124498. 6, 5, 5, 7,10,10,10, 9,11, 8, 7, 6, 7, 9,11,11,
  124499. 12,13,10,10, 9, 8, 9,11,11,15,15,12,13,11, 9,10,
  124500. 11,
  124501. };
  124502. static static_codebook _huff_book__44c1_sm_long = {
  124503. 2, 81,
  124504. _huff_lengthlist__44c1_sm_long,
  124505. 0, 0, 0, 0, 0,
  124506. NULL,
  124507. NULL,
  124508. NULL,
  124509. NULL,
  124510. 0
  124511. };
  124512. static long _vq_quantlist__44c1_sm_p1_0[] = {
  124513. 1,
  124514. 0,
  124515. 2,
  124516. };
  124517. static long _vq_lengthlist__44c1_sm_p1_0[] = {
  124518. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  124519. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  124524. 0, 0, 0, 7, 8, 9, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  124529. 0, 0, 0, 0, 7, 9, 9, 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, 5, 8, 7, 0, 0, 0, 0,
  124564. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  124569. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  124574. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  124610. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  124615. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  124620. 0, 0, 0, 0, 0, 0, 9,10, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124928. 0,
  124929. };
  124930. static float _vq_quantthresh__44c1_sm_p1_0[] = {
  124931. -0.5, 0.5,
  124932. };
  124933. static long _vq_quantmap__44c1_sm_p1_0[] = {
  124934. 1, 0, 2,
  124935. };
  124936. static encode_aux_threshmatch _vq_auxt__44c1_sm_p1_0 = {
  124937. _vq_quantthresh__44c1_sm_p1_0,
  124938. _vq_quantmap__44c1_sm_p1_0,
  124939. 3,
  124940. 3
  124941. };
  124942. static static_codebook _44c1_sm_p1_0 = {
  124943. 8, 6561,
  124944. _vq_lengthlist__44c1_sm_p1_0,
  124945. 1, -535822336, 1611661312, 2, 0,
  124946. _vq_quantlist__44c1_sm_p1_0,
  124947. NULL,
  124948. &_vq_auxt__44c1_sm_p1_0,
  124949. NULL,
  124950. 0
  124951. };
  124952. static long _vq_quantlist__44c1_sm_p2_0[] = {
  124953. 2,
  124954. 1,
  124955. 3,
  124956. 0,
  124957. 4,
  124958. };
  124959. static long _vq_lengthlist__44c1_sm_p2_0[] = {
  124960. 2, 3, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  124962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124963. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  124965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124966. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  124967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124999. 0,
  125000. };
  125001. static float _vq_quantthresh__44c1_sm_p2_0[] = {
  125002. -1.5, -0.5, 0.5, 1.5,
  125003. };
  125004. static long _vq_quantmap__44c1_sm_p2_0[] = {
  125005. 3, 1, 0, 2, 4,
  125006. };
  125007. static encode_aux_threshmatch _vq_auxt__44c1_sm_p2_0 = {
  125008. _vq_quantthresh__44c1_sm_p2_0,
  125009. _vq_quantmap__44c1_sm_p2_0,
  125010. 5,
  125011. 5
  125012. };
  125013. static static_codebook _44c1_sm_p2_0 = {
  125014. 4, 625,
  125015. _vq_lengthlist__44c1_sm_p2_0,
  125016. 1, -533725184, 1611661312, 3, 0,
  125017. _vq_quantlist__44c1_sm_p2_0,
  125018. NULL,
  125019. &_vq_auxt__44c1_sm_p2_0,
  125020. NULL,
  125021. 0
  125022. };
  125023. static long _vq_quantlist__44c1_sm_p3_0[] = {
  125024. 4,
  125025. 3,
  125026. 5,
  125027. 2,
  125028. 6,
  125029. 1,
  125030. 7,
  125031. 0,
  125032. 8,
  125033. };
  125034. static long _vq_lengthlist__44c1_sm_p3_0[] = {
  125035. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 5, 6, 6, 0, 0,
  125036. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 7, 7, 7, 7,
  125037. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  125038. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  125039. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125040. 0,
  125041. };
  125042. static float _vq_quantthresh__44c1_sm_p3_0[] = {
  125043. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125044. };
  125045. static long _vq_quantmap__44c1_sm_p3_0[] = {
  125046. 7, 5, 3, 1, 0, 2, 4, 6,
  125047. 8,
  125048. };
  125049. static encode_aux_threshmatch _vq_auxt__44c1_sm_p3_0 = {
  125050. _vq_quantthresh__44c1_sm_p3_0,
  125051. _vq_quantmap__44c1_sm_p3_0,
  125052. 9,
  125053. 9
  125054. };
  125055. static static_codebook _44c1_sm_p3_0 = {
  125056. 2, 81,
  125057. _vq_lengthlist__44c1_sm_p3_0,
  125058. 1, -531628032, 1611661312, 4, 0,
  125059. _vq_quantlist__44c1_sm_p3_0,
  125060. NULL,
  125061. &_vq_auxt__44c1_sm_p3_0,
  125062. NULL,
  125063. 0
  125064. };
  125065. static long _vq_quantlist__44c1_sm_p4_0[] = {
  125066. 4,
  125067. 3,
  125068. 5,
  125069. 2,
  125070. 6,
  125071. 1,
  125072. 7,
  125073. 0,
  125074. 8,
  125075. };
  125076. static long _vq_lengthlist__44c1_sm_p4_0[] = {
  125077. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7, 8, 8,
  125078. 9, 9, 0, 6, 6, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  125079. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  125080. 8, 8, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  125081. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  125082. 11,
  125083. };
  125084. static float _vq_quantthresh__44c1_sm_p4_0[] = {
  125085. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125086. };
  125087. static long _vq_quantmap__44c1_sm_p4_0[] = {
  125088. 7, 5, 3, 1, 0, 2, 4, 6,
  125089. 8,
  125090. };
  125091. static encode_aux_threshmatch _vq_auxt__44c1_sm_p4_0 = {
  125092. _vq_quantthresh__44c1_sm_p4_0,
  125093. _vq_quantmap__44c1_sm_p4_0,
  125094. 9,
  125095. 9
  125096. };
  125097. static static_codebook _44c1_sm_p4_0 = {
  125098. 2, 81,
  125099. _vq_lengthlist__44c1_sm_p4_0,
  125100. 1, -531628032, 1611661312, 4, 0,
  125101. _vq_quantlist__44c1_sm_p4_0,
  125102. NULL,
  125103. &_vq_auxt__44c1_sm_p4_0,
  125104. NULL,
  125105. 0
  125106. };
  125107. static long _vq_quantlist__44c1_sm_p5_0[] = {
  125108. 8,
  125109. 7,
  125110. 9,
  125111. 6,
  125112. 10,
  125113. 5,
  125114. 11,
  125115. 4,
  125116. 12,
  125117. 3,
  125118. 13,
  125119. 2,
  125120. 14,
  125121. 1,
  125122. 15,
  125123. 0,
  125124. 16,
  125125. };
  125126. static long _vq_lengthlist__44c1_sm_p5_0[] = {
  125127. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  125128. 11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  125129. 11,11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  125130. 10,11,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  125131. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  125132. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,10,
  125133. 10,11,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,
  125134. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  125135. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  125136. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  125137. 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  125138. 9, 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  125139. 9, 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  125140. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  125141. 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0, 0,
  125142. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  125143. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14,
  125144. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  125145. 14,
  125146. };
  125147. static float _vq_quantthresh__44c1_sm_p5_0[] = {
  125148. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125149. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125150. };
  125151. static long _vq_quantmap__44c1_sm_p5_0[] = {
  125152. 15, 13, 11, 9, 7, 5, 3, 1,
  125153. 0, 2, 4, 6, 8, 10, 12, 14,
  125154. 16,
  125155. };
  125156. static encode_aux_threshmatch _vq_auxt__44c1_sm_p5_0 = {
  125157. _vq_quantthresh__44c1_sm_p5_0,
  125158. _vq_quantmap__44c1_sm_p5_0,
  125159. 17,
  125160. 17
  125161. };
  125162. static static_codebook _44c1_sm_p5_0 = {
  125163. 2, 289,
  125164. _vq_lengthlist__44c1_sm_p5_0,
  125165. 1, -529530880, 1611661312, 5, 0,
  125166. _vq_quantlist__44c1_sm_p5_0,
  125167. NULL,
  125168. &_vq_auxt__44c1_sm_p5_0,
  125169. NULL,
  125170. 0
  125171. };
  125172. static long _vq_quantlist__44c1_sm_p6_0[] = {
  125173. 1,
  125174. 0,
  125175. 2,
  125176. };
  125177. static long _vq_lengthlist__44c1_sm_p6_0[] = {
  125178. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  125179. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  125180. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  125181. 11,10,11,11,10,10, 7,11,11,11,11,11,11,11,11, 6,
  125182. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,11,10,
  125183. 11,
  125184. };
  125185. static float _vq_quantthresh__44c1_sm_p6_0[] = {
  125186. -5.5, 5.5,
  125187. };
  125188. static long _vq_quantmap__44c1_sm_p6_0[] = {
  125189. 1, 0, 2,
  125190. };
  125191. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_0 = {
  125192. _vq_quantthresh__44c1_sm_p6_0,
  125193. _vq_quantmap__44c1_sm_p6_0,
  125194. 3,
  125195. 3
  125196. };
  125197. static static_codebook _44c1_sm_p6_0 = {
  125198. 4, 81,
  125199. _vq_lengthlist__44c1_sm_p6_0,
  125200. 1, -529137664, 1618345984, 2, 0,
  125201. _vq_quantlist__44c1_sm_p6_0,
  125202. NULL,
  125203. &_vq_auxt__44c1_sm_p6_0,
  125204. NULL,
  125205. 0
  125206. };
  125207. static long _vq_quantlist__44c1_sm_p6_1[] = {
  125208. 5,
  125209. 4,
  125210. 6,
  125211. 3,
  125212. 7,
  125213. 2,
  125214. 8,
  125215. 1,
  125216. 9,
  125217. 0,
  125218. 10,
  125219. };
  125220. static long _vq_lengthlist__44c1_sm_p6_1[] = {
  125221. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  125222. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  125223. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  125224. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  125225. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  125226. 8, 8, 8, 8, 8, 8, 9, 8,10,10,10,10,10, 8, 8, 8,
  125227. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  125228. 10,10,10, 8, 8, 8, 8, 8, 8,
  125229. };
  125230. static float _vq_quantthresh__44c1_sm_p6_1[] = {
  125231. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  125232. 3.5, 4.5,
  125233. };
  125234. static long _vq_quantmap__44c1_sm_p6_1[] = {
  125235. 9, 7, 5, 3, 1, 0, 2, 4,
  125236. 6, 8, 10,
  125237. };
  125238. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_1 = {
  125239. _vq_quantthresh__44c1_sm_p6_1,
  125240. _vq_quantmap__44c1_sm_p6_1,
  125241. 11,
  125242. 11
  125243. };
  125244. static static_codebook _44c1_sm_p6_1 = {
  125245. 2, 121,
  125246. _vq_lengthlist__44c1_sm_p6_1,
  125247. 1, -531365888, 1611661312, 4, 0,
  125248. _vq_quantlist__44c1_sm_p6_1,
  125249. NULL,
  125250. &_vq_auxt__44c1_sm_p6_1,
  125251. NULL,
  125252. 0
  125253. };
  125254. static long _vq_quantlist__44c1_sm_p7_0[] = {
  125255. 6,
  125256. 5,
  125257. 7,
  125258. 4,
  125259. 8,
  125260. 3,
  125261. 9,
  125262. 2,
  125263. 10,
  125264. 1,
  125265. 11,
  125266. 0,
  125267. 12,
  125268. };
  125269. static long _vq_lengthlist__44c1_sm_p7_0[] = {
  125270. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  125271. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  125272. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  125273. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  125274. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  125275. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0, 9,10,
  125276. 9,10,11,11,12,11,13,12, 0, 0, 0,10,10, 9, 9,11,
  125277. 11,12,12,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  125278. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  125279. 0, 0, 0, 0,11,12,11,11,12,13,14,13, 0, 0, 0, 0,
  125280. 0,12,12,11,11,13,12,14,13,
  125281. };
  125282. static float _vq_quantthresh__44c1_sm_p7_0[] = {
  125283. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  125284. 12.5, 17.5, 22.5, 27.5,
  125285. };
  125286. static long _vq_quantmap__44c1_sm_p7_0[] = {
  125287. 11, 9, 7, 5, 3, 1, 0, 2,
  125288. 4, 6, 8, 10, 12,
  125289. };
  125290. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_0 = {
  125291. _vq_quantthresh__44c1_sm_p7_0,
  125292. _vq_quantmap__44c1_sm_p7_0,
  125293. 13,
  125294. 13
  125295. };
  125296. static static_codebook _44c1_sm_p7_0 = {
  125297. 2, 169,
  125298. _vq_lengthlist__44c1_sm_p7_0,
  125299. 1, -526516224, 1616117760, 4, 0,
  125300. _vq_quantlist__44c1_sm_p7_0,
  125301. NULL,
  125302. &_vq_auxt__44c1_sm_p7_0,
  125303. NULL,
  125304. 0
  125305. };
  125306. static long _vq_quantlist__44c1_sm_p7_1[] = {
  125307. 2,
  125308. 1,
  125309. 3,
  125310. 0,
  125311. 4,
  125312. };
  125313. static long _vq_lengthlist__44c1_sm_p7_1[] = {
  125314. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  125315. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  125316. };
  125317. static float _vq_quantthresh__44c1_sm_p7_1[] = {
  125318. -1.5, -0.5, 0.5, 1.5,
  125319. };
  125320. static long _vq_quantmap__44c1_sm_p7_1[] = {
  125321. 3, 1, 0, 2, 4,
  125322. };
  125323. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_1 = {
  125324. _vq_quantthresh__44c1_sm_p7_1,
  125325. _vq_quantmap__44c1_sm_p7_1,
  125326. 5,
  125327. 5
  125328. };
  125329. static static_codebook _44c1_sm_p7_1 = {
  125330. 2, 25,
  125331. _vq_lengthlist__44c1_sm_p7_1,
  125332. 1, -533725184, 1611661312, 3, 0,
  125333. _vq_quantlist__44c1_sm_p7_1,
  125334. NULL,
  125335. &_vq_auxt__44c1_sm_p7_1,
  125336. NULL,
  125337. 0
  125338. };
  125339. static long _vq_quantlist__44c1_sm_p8_0[] = {
  125340. 6,
  125341. 5,
  125342. 7,
  125343. 4,
  125344. 8,
  125345. 3,
  125346. 9,
  125347. 2,
  125348. 10,
  125349. 1,
  125350. 11,
  125351. 0,
  125352. 12,
  125353. };
  125354. static long _vq_lengthlist__44c1_sm_p8_0[] = {
  125355. 1, 3, 3,13,13,13,13,13,13,13,13,13,13, 3, 6, 6,
  125356. 13,13,13,13,13,13,13,13,13,13, 4, 8, 7,13,13,13,
  125357. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125358. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125359. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125360. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125361. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125362. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125363. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125364. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125365. 13,13,13,13,13,13,13,13,13,
  125366. };
  125367. static float _vq_quantthresh__44c1_sm_p8_0[] = {
  125368. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  125369. 552.5, 773.5, 994.5, 1215.5,
  125370. };
  125371. static long _vq_quantmap__44c1_sm_p8_0[] = {
  125372. 11, 9, 7, 5, 3, 1, 0, 2,
  125373. 4, 6, 8, 10, 12,
  125374. };
  125375. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_0 = {
  125376. _vq_quantthresh__44c1_sm_p8_0,
  125377. _vq_quantmap__44c1_sm_p8_0,
  125378. 13,
  125379. 13
  125380. };
  125381. static static_codebook _44c1_sm_p8_0 = {
  125382. 2, 169,
  125383. _vq_lengthlist__44c1_sm_p8_0,
  125384. 1, -514541568, 1627103232, 4, 0,
  125385. _vq_quantlist__44c1_sm_p8_0,
  125386. NULL,
  125387. &_vq_auxt__44c1_sm_p8_0,
  125388. NULL,
  125389. 0
  125390. };
  125391. static long _vq_quantlist__44c1_sm_p8_1[] = {
  125392. 6,
  125393. 5,
  125394. 7,
  125395. 4,
  125396. 8,
  125397. 3,
  125398. 9,
  125399. 2,
  125400. 10,
  125401. 1,
  125402. 11,
  125403. 0,
  125404. 12,
  125405. };
  125406. static long _vq_lengthlist__44c1_sm_p8_1[] = {
  125407. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  125408. 7, 7, 8, 7,10,10,11,11,12,12, 6, 5, 5, 7, 7, 8,
  125409. 8,10,10,11,11,12,12,16, 7, 7, 8, 8, 9, 9,11,11,
  125410. 12,12,13,13,17, 7, 7, 8, 7, 9, 9,11,10,12,12,13,
  125411. 13,19,11,10, 8, 8,10,10,11,11,12,12,13,13,19,11,
  125412. 11, 9, 7,11,10,11,11,12,12,13,12,19,19,19,10,10,
  125413. 10,10,11,12,12,12,13,14,18,19,19,11, 9,11, 9,13,
  125414. 12,12,12,13,13,19,20,19,13,15,11,11,12,12,13,13,
  125415. 14,13,18,19,20,15,13,12,10,13,10,13,13,13,14,20,
  125416. 20,20,20,20,13,14,12,12,13,12,13,13,20,20,20,20,
  125417. 20,13,12,12,12,14,12,14,13,
  125418. };
  125419. static float _vq_quantthresh__44c1_sm_p8_1[] = {
  125420. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  125421. 42.5, 59.5, 76.5, 93.5,
  125422. };
  125423. static long _vq_quantmap__44c1_sm_p8_1[] = {
  125424. 11, 9, 7, 5, 3, 1, 0, 2,
  125425. 4, 6, 8, 10, 12,
  125426. };
  125427. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_1 = {
  125428. _vq_quantthresh__44c1_sm_p8_1,
  125429. _vq_quantmap__44c1_sm_p8_1,
  125430. 13,
  125431. 13
  125432. };
  125433. static static_codebook _44c1_sm_p8_1 = {
  125434. 2, 169,
  125435. _vq_lengthlist__44c1_sm_p8_1,
  125436. 1, -522616832, 1620115456, 4, 0,
  125437. _vq_quantlist__44c1_sm_p8_1,
  125438. NULL,
  125439. &_vq_auxt__44c1_sm_p8_1,
  125440. NULL,
  125441. 0
  125442. };
  125443. static long _vq_quantlist__44c1_sm_p8_2[] = {
  125444. 8,
  125445. 7,
  125446. 9,
  125447. 6,
  125448. 10,
  125449. 5,
  125450. 11,
  125451. 4,
  125452. 12,
  125453. 3,
  125454. 13,
  125455. 2,
  125456. 14,
  125457. 1,
  125458. 15,
  125459. 0,
  125460. 16,
  125461. };
  125462. static long _vq_lengthlist__44c1_sm_p8_2[] = {
  125463. 2, 5, 5, 6, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  125464. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  125465. 9, 9,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  125466. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  125467. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  125468. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  125469. 9, 9,10,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  125470. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  125471. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 8, 8, 9,
  125472. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  125473. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,11,11,11, 9,
  125474. 8, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,10,11,11,
  125475. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,11,
  125476. 11,11,11, 9, 9,10, 9, 9, 9, 9,10, 9,10,10,11,10,
  125477. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  125478. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,
  125479. 11,10,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  125480. 10,11,10,11,11,11,11,11,11, 9, 9,10, 9, 9, 9, 9,
  125481. 9,
  125482. };
  125483. static float _vq_quantthresh__44c1_sm_p8_2[] = {
  125484. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125485. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125486. };
  125487. static long _vq_quantmap__44c1_sm_p8_2[] = {
  125488. 15, 13, 11, 9, 7, 5, 3, 1,
  125489. 0, 2, 4, 6, 8, 10, 12, 14,
  125490. 16,
  125491. };
  125492. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_2 = {
  125493. _vq_quantthresh__44c1_sm_p8_2,
  125494. _vq_quantmap__44c1_sm_p8_2,
  125495. 17,
  125496. 17
  125497. };
  125498. static static_codebook _44c1_sm_p8_2 = {
  125499. 2, 289,
  125500. _vq_lengthlist__44c1_sm_p8_2,
  125501. 1, -529530880, 1611661312, 5, 0,
  125502. _vq_quantlist__44c1_sm_p8_2,
  125503. NULL,
  125504. &_vq_auxt__44c1_sm_p8_2,
  125505. NULL,
  125506. 0
  125507. };
  125508. static long _huff_lengthlist__44c1_sm_short[] = {
  125509. 4, 7,13,14,14,15,16,18,18, 4, 2, 5, 8, 7, 9,12,
  125510. 15,15,10, 4, 5,10, 6, 8,11,15,17,12, 5, 7, 5, 6,
  125511. 8,11,14,17,11, 5, 6, 6, 5, 6, 9,13,17,12, 6, 7,
  125512. 6, 5, 6, 8,12,14,14, 7, 8, 6, 6, 7, 9,11,14,14,
  125513. 8, 9, 6, 5, 6, 9,11,13,16,10,10, 7, 6, 7, 8,10,
  125514. 11,
  125515. };
  125516. static static_codebook _huff_book__44c1_sm_short = {
  125517. 2, 81,
  125518. _huff_lengthlist__44c1_sm_short,
  125519. 0, 0, 0, 0, 0,
  125520. NULL,
  125521. NULL,
  125522. NULL,
  125523. NULL,
  125524. 0
  125525. };
  125526. static long _huff_lengthlist__44cn1_s_long[] = {
  125527. 4, 4, 7, 8, 7, 8,10,12,17, 3, 1, 6, 6, 7, 8,10,
  125528. 12,15, 7, 6, 9, 9, 9,11,12,14,17, 8, 6, 9, 6, 7,
  125529. 9,11,13,17, 7, 6, 9, 7, 7, 8, 9,12,15, 8, 8,10,
  125530. 8, 7, 7, 7,10,14, 9,10,12,10, 8, 8, 8,10,14,11,
  125531. 13,15,13,12,11,11,12,16,17,18,18,19,20,18,16,16,
  125532. 20,
  125533. };
  125534. static static_codebook _huff_book__44cn1_s_long = {
  125535. 2, 81,
  125536. _huff_lengthlist__44cn1_s_long,
  125537. 0, 0, 0, 0, 0,
  125538. NULL,
  125539. NULL,
  125540. NULL,
  125541. NULL,
  125542. 0
  125543. };
  125544. static long _vq_quantlist__44cn1_s_p1_0[] = {
  125545. 1,
  125546. 0,
  125547. 2,
  125548. };
  125549. static long _vq_lengthlist__44cn1_s_p1_0[] = {
  125550. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  125551. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  125556. 0, 0, 0, 7, 9,10, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0,
  125561. 0, 0, 0, 0, 8,10, 9, 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, 5, 8, 8, 0, 0, 0, 0,
  125596. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9,10, 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, 7,10,10, 0, 0, 0,
  125601. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0,10,11,11, 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, 7,10,10, 0, 0,
  125606. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0,10,11,11,
  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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  125642. 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11, 0,
  125647. 0, 0, 0, 0, 0, 9, 9,11, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11,
  125652. 0, 0, 0, 0, 0, 0, 9,11, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125960. 0,
  125961. };
  125962. static float _vq_quantthresh__44cn1_s_p1_0[] = {
  125963. -0.5, 0.5,
  125964. };
  125965. static long _vq_quantmap__44cn1_s_p1_0[] = {
  125966. 1, 0, 2,
  125967. };
  125968. static encode_aux_threshmatch _vq_auxt__44cn1_s_p1_0 = {
  125969. _vq_quantthresh__44cn1_s_p1_0,
  125970. _vq_quantmap__44cn1_s_p1_0,
  125971. 3,
  125972. 3
  125973. };
  125974. static static_codebook _44cn1_s_p1_0 = {
  125975. 8, 6561,
  125976. _vq_lengthlist__44cn1_s_p1_0,
  125977. 1, -535822336, 1611661312, 2, 0,
  125978. _vq_quantlist__44cn1_s_p1_0,
  125979. NULL,
  125980. &_vq_auxt__44cn1_s_p1_0,
  125981. NULL,
  125982. 0
  125983. };
  125984. static long _vq_quantlist__44cn1_s_p2_0[] = {
  125985. 2,
  125986. 1,
  125987. 3,
  125988. 0,
  125989. 4,
  125990. };
  125991. static long _vq_lengthlist__44cn1_s_p2_0[] = {
  125992. 1, 4, 4, 7, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  125994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125995. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  125997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125998. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  125999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126031. 0,
  126032. };
  126033. static float _vq_quantthresh__44cn1_s_p2_0[] = {
  126034. -1.5, -0.5, 0.5, 1.5,
  126035. };
  126036. static long _vq_quantmap__44cn1_s_p2_0[] = {
  126037. 3, 1, 0, 2, 4,
  126038. };
  126039. static encode_aux_threshmatch _vq_auxt__44cn1_s_p2_0 = {
  126040. _vq_quantthresh__44cn1_s_p2_0,
  126041. _vq_quantmap__44cn1_s_p2_0,
  126042. 5,
  126043. 5
  126044. };
  126045. static static_codebook _44cn1_s_p2_0 = {
  126046. 4, 625,
  126047. _vq_lengthlist__44cn1_s_p2_0,
  126048. 1, -533725184, 1611661312, 3, 0,
  126049. _vq_quantlist__44cn1_s_p2_0,
  126050. NULL,
  126051. &_vq_auxt__44cn1_s_p2_0,
  126052. NULL,
  126053. 0
  126054. };
  126055. static long _vq_quantlist__44cn1_s_p3_0[] = {
  126056. 4,
  126057. 3,
  126058. 5,
  126059. 2,
  126060. 6,
  126061. 1,
  126062. 7,
  126063. 0,
  126064. 8,
  126065. };
  126066. static long _vq_lengthlist__44cn1_s_p3_0[] = {
  126067. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  126068. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  126069. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  126070. 9, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  126071. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126072. 0,
  126073. };
  126074. static float _vq_quantthresh__44cn1_s_p3_0[] = {
  126075. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126076. };
  126077. static long _vq_quantmap__44cn1_s_p3_0[] = {
  126078. 7, 5, 3, 1, 0, 2, 4, 6,
  126079. 8,
  126080. };
  126081. static encode_aux_threshmatch _vq_auxt__44cn1_s_p3_0 = {
  126082. _vq_quantthresh__44cn1_s_p3_0,
  126083. _vq_quantmap__44cn1_s_p3_0,
  126084. 9,
  126085. 9
  126086. };
  126087. static static_codebook _44cn1_s_p3_0 = {
  126088. 2, 81,
  126089. _vq_lengthlist__44cn1_s_p3_0,
  126090. 1, -531628032, 1611661312, 4, 0,
  126091. _vq_quantlist__44cn1_s_p3_0,
  126092. NULL,
  126093. &_vq_auxt__44cn1_s_p3_0,
  126094. NULL,
  126095. 0
  126096. };
  126097. static long _vq_quantlist__44cn1_s_p4_0[] = {
  126098. 4,
  126099. 3,
  126100. 5,
  126101. 2,
  126102. 6,
  126103. 1,
  126104. 7,
  126105. 0,
  126106. 8,
  126107. };
  126108. static long _vq_lengthlist__44cn1_s_p4_0[] = {
  126109. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  126110. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  126111. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  126112. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  126113. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  126114. 11,
  126115. };
  126116. static float _vq_quantthresh__44cn1_s_p4_0[] = {
  126117. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126118. };
  126119. static long _vq_quantmap__44cn1_s_p4_0[] = {
  126120. 7, 5, 3, 1, 0, 2, 4, 6,
  126121. 8,
  126122. };
  126123. static encode_aux_threshmatch _vq_auxt__44cn1_s_p4_0 = {
  126124. _vq_quantthresh__44cn1_s_p4_0,
  126125. _vq_quantmap__44cn1_s_p4_0,
  126126. 9,
  126127. 9
  126128. };
  126129. static static_codebook _44cn1_s_p4_0 = {
  126130. 2, 81,
  126131. _vq_lengthlist__44cn1_s_p4_0,
  126132. 1, -531628032, 1611661312, 4, 0,
  126133. _vq_quantlist__44cn1_s_p4_0,
  126134. NULL,
  126135. &_vq_auxt__44cn1_s_p4_0,
  126136. NULL,
  126137. 0
  126138. };
  126139. static long _vq_quantlist__44cn1_s_p5_0[] = {
  126140. 8,
  126141. 7,
  126142. 9,
  126143. 6,
  126144. 10,
  126145. 5,
  126146. 11,
  126147. 4,
  126148. 12,
  126149. 3,
  126150. 13,
  126151. 2,
  126152. 14,
  126153. 1,
  126154. 15,
  126155. 0,
  126156. 16,
  126157. };
  126158. static long _vq_lengthlist__44cn1_s_p5_0[] = {
  126159. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  126160. 10, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  126161. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  126162. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  126163. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  126164. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  126165. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  126166. 10,10,11,11,11,12,12, 0, 0, 0, 9, 9,10, 9,10,10,
  126167. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  126168. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  126169. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  126170. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  126171. 10,10,11,10,11,11,11,12,13,12,13,13, 0, 0, 0, 0,
  126172. 0, 0, 0,11,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  126173. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  126174. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  126175. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,13,13,14,14,
  126176. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,12,13,13,14,
  126177. 14,
  126178. };
  126179. static float _vq_quantthresh__44cn1_s_p5_0[] = {
  126180. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126181. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126182. };
  126183. static long _vq_quantmap__44cn1_s_p5_0[] = {
  126184. 15, 13, 11, 9, 7, 5, 3, 1,
  126185. 0, 2, 4, 6, 8, 10, 12, 14,
  126186. 16,
  126187. };
  126188. static encode_aux_threshmatch _vq_auxt__44cn1_s_p5_0 = {
  126189. _vq_quantthresh__44cn1_s_p5_0,
  126190. _vq_quantmap__44cn1_s_p5_0,
  126191. 17,
  126192. 17
  126193. };
  126194. static static_codebook _44cn1_s_p5_0 = {
  126195. 2, 289,
  126196. _vq_lengthlist__44cn1_s_p5_0,
  126197. 1, -529530880, 1611661312, 5, 0,
  126198. _vq_quantlist__44cn1_s_p5_0,
  126199. NULL,
  126200. &_vq_auxt__44cn1_s_p5_0,
  126201. NULL,
  126202. 0
  126203. };
  126204. static long _vq_quantlist__44cn1_s_p6_0[] = {
  126205. 1,
  126206. 0,
  126207. 2,
  126208. };
  126209. static long _vq_lengthlist__44cn1_s_p6_0[] = {
  126210. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 6, 6,10, 9, 9,11,
  126211. 9, 9, 4, 6, 6,10, 9, 9,10, 9, 9, 7,10,10,11,11,
  126212. 11,12,11,11, 7, 9, 9,11,11,10,11,10,10, 7, 9, 9,
  126213. 11,10,11,11,10,10, 7,10,10,11,11,11,12,11,11, 7,
  126214. 9, 9,11,10,10,11,10,10, 7, 9, 9,11,10,10,11,10,
  126215. 10,
  126216. };
  126217. static float _vq_quantthresh__44cn1_s_p6_0[] = {
  126218. -5.5, 5.5,
  126219. };
  126220. static long _vq_quantmap__44cn1_s_p6_0[] = {
  126221. 1, 0, 2,
  126222. };
  126223. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_0 = {
  126224. _vq_quantthresh__44cn1_s_p6_0,
  126225. _vq_quantmap__44cn1_s_p6_0,
  126226. 3,
  126227. 3
  126228. };
  126229. static static_codebook _44cn1_s_p6_0 = {
  126230. 4, 81,
  126231. _vq_lengthlist__44cn1_s_p6_0,
  126232. 1, -529137664, 1618345984, 2, 0,
  126233. _vq_quantlist__44cn1_s_p6_0,
  126234. NULL,
  126235. &_vq_auxt__44cn1_s_p6_0,
  126236. NULL,
  126237. 0
  126238. };
  126239. static long _vq_quantlist__44cn1_s_p6_1[] = {
  126240. 5,
  126241. 4,
  126242. 6,
  126243. 3,
  126244. 7,
  126245. 2,
  126246. 8,
  126247. 1,
  126248. 9,
  126249. 0,
  126250. 10,
  126251. };
  126252. static long _vq_lengthlist__44cn1_s_p6_1[] = {
  126253. 1, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 6,
  126254. 8, 8, 8, 8, 8, 8,10,10,10, 7, 6, 7, 7, 8, 8, 8,
  126255. 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  126256. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 9, 9,
  126257. 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,
  126258. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  126259. 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,
  126260. 10,10,10, 9, 9, 9, 9, 9, 9,
  126261. };
  126262. static float _vq_quantthresh__44cn1_s_p6_1[] = {
  126263. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  126264. 3.5, 4.5,
  126265. };
  126266. static long _vq_quantmap__44cn1_s_p6_1[] = {
  126267. 9, 7, 5, 3, 1, 0, 2, 4,
  126268. 6, 8, 10,
  126269. };
  126270. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_1 = {
  126271. _vq_quantthresh__44cn1_s_p6_1,
  126272. _vq_quantmap__44cn1_s_p6_1,
  126273. 11,
  126274. 11
  126275. };
  126276. static static_codebook _44cn1_s_p6_1 = {
  126277. 2, 121,
  126278. _vq_lengthlist__44cn1_s_p6_1,
  126279. 1, -531365888, 1611661312, 4, 0,
  126280. _vq_quantlist__44cn1_s_p6_1,
  126281. NULL,
  126282. &_vq_auxt__44cn1_s_p6_1,
  126283. NULL,
  126284. 0
  126285. };
  126286. static long _vq_quantlist__44cn1_s_p7_0[] = {
  126287. 6,
  126288. 5,
  126289. 7,
  126290. 4,
  126291. 8,
  126292. 3,
  126293. 9,
  126294. 2,
  126295. 10,
  126296. 1,
  126297. 11,
  126298. 0,
  126299. 12,
  126300. };
  126301. static long _vq_lengthlist__44cn1_s_p7_0[] = {
  126302. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  126303. 7, 7, 8, 8, 8, 8, 9, 9,11,11, 7, 5, 5, 7, 7, 8,
  126304. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  126305. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  126306. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,12, 0,13,
  126307. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  126308. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  126309. 11,12,12,13,12, 0, 0, 0,14,14,11,10,11,12,12,13,
  126310. 13,14, 0, 0, 0,15,15,11,11,12,11,12,12,14,13, 0,
  126311. 0, 0, 0, 0,12,12,12,12,13,13,14,14, 0, 0, 0, 0,
  126312. 0,13,13,12,12,13,13,13,14,
  126313. };
  126314. static float _vq_quantthresh__44cn1_s_p7_0[] = {
  126315. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  126316. 12.5, 17.5, 22.5, 27.5,
  126317. };
  126318. static long _vq_quantmap__44cn1_s_p7_0[] = {
  126319. 11, 9, 7, 5, 3, 1, 0, 2,
  126320. 4, 6, 8, 10, 12,
  126321. };
  126322. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_0 = {
  126323. _vq_quantthresh__44cn1_s_p7_0,
  126324. _vq_quantmap__44cn1_s_p7_0,
  126325. 13,
  126326. 13
  126327. };
  126328. static static_codebook _44cn1_s_p7_0 = {
  126329. 2, 169,
  126330. _vq_lengthlist__44cn1_s_p7_0,
  126331. 1, -526516224, 1616117760, 4, 0,
  126332. _vq_quantlist__44cn1_s_p7_0,
  126333. NULL,
  126334. &_vq_auxt__44cn1_s_p7_0,
  126335. NULL,
  126336. 0
  126337. };
  126338. static long _vq_quantlist__44cn1_s_p7_1[] = {
  126339. 2,
  126340. 1,
  126341. 3,
  126342. 0,
  126343. 4,
  126344. };
  126345. static long _vq_lengthlist__44cn1_s_p7_1[] = {
  126346. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  126347. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  126348. };
  126349. static float _vq_quantthresh__44cn1_s_p7_1[] = {
  126350. -1.5, -0.5, 0.5, 1.5,
  126351. };
  126352. static long _vq_quantmap__44cn1_s_p7_1[] = {
  126353. 3, 1, 0, 2, 4,
  126354. };
  126355. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_1 = {
  126356. _vq_quantthresh__44cn1_s_p7_1,
  126357. _vq_quantmap__44cn1_s_p7_1,
  126358. 5,
  126359. 5
  126360. };
  126361. static static_codebook _44cn1_s_p7_1 = {
  126362. 2, 25,
  126363. _vq_lengthlist__44cn1_s_p7_1,
  126364. 1, -533725184, 1611661312, 3, 0,
  126365. _vq_quantlist__44cn1_s_p7_1,
  126366. NULL,
  126367. &_vq_auxt__44cn1_s_p7_1,
  126368. NULL,
  126369. 0
  126370. };
  126371. static long _vq_quantlist__44cn1_s_p8_0[] = {
  126372. 2,
  126373. 1,
  126374. 3,
  126375. 0,
  126376. 4,
  126377. };
  126378. static long _vq_lengthlist__44cn1_s_p8_0[] = {
  126379. 1, 7, 7,11,11, 8,11,11,11,11, 4,11, 3,11,11,11,
  126380. 11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,
  126381. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126382. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  126383. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126384. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126385. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126386. 11,11,11,11,11,11,11,11,11,11,11,11,11, 7,11,11,
  126387. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126388. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  126389. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  126390. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126391. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126392. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126393. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126394. 11,11,11,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  126395. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126396. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126397. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126398. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126399. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126400. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126401. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126402. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126403. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126404. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126405. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126406. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126407. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126408. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126409. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126410. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126411. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126412. 11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,
  126413. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126414. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126415. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126416. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126417. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126418. 12,
  126419. };
  126420. static float _vq_quantthresh__44cn1_s_p8_0[] = {
  126421. -331.5, -110.5, 110.5, 331.5,
  126422. };
  126423. static long _vq_quantmap__44cn1_s_p8_0[] = {
  126424. 3, 1, 0, 2, 4,
  126425. };
  126426. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_0 = {
  126427. _vq_quantthresh__44cn1_s_p8_0,
  126428. _vq_quantmap__44cn1_s_p8_0,
  126429. 5,
  126430. 5
  126431. };
  126432. static static_codebook _44cn1_s_p8_0 = {
  126433. 4, 625,
  126434. _vq_lengthlist__44cn1_s_p8_0,
  126435. 1, -518283264, 1627103232, 3, 0,
  126436. _vq_quantlist__44cn1_s_p8_0,
  126437. NULL,
  126438. &_vq_auxt__44cn1_s_p8_0,
  126439. NULL,
  126440. 0
  126441. };
  126442. static long _vq_quantlist__44cn1_s_p8_1[] = {
  126443. 6,
  126444. 5,
  126445. 7,
  126446. 4,
  126447. 8,
  126448. 3,
  126449. 9,
  126450. 2,
  126451. 10,
  126452. 1,
  126453. 11,
  126454. 0,
  126455. 12,
  126456. };
  126457. static long _vq_lengthlist__44cn1_s_p8_1[] = {
  126458. 1, 4, 4, 6, 6, 8, 8, 9,10,10,11,11,11, 6, 5, 5,
  126459. 7, 7, 8, 8, 9,10, 9,11,11,12, 5, 5, 5, 7, 7, 8,
  126460. 9,10,10,12,12,14,13,15, 7, 7, 8, 8, 9,10,11,11,
  126461. 10,12,10,11,15, 7, 8, 8, 8, 9, 9,11,11,13,12,12,
  126462. 13,15,10,10, 8, 8,10,10,12,12,11,14,10,10,15,11,
  126463. 11, 8, 8,10,10,12,13,13,14,15,13,15,15,15,10,10,
  126464. 10,10,12,12,13,12,13,10,15,15,15,10,10,11,10,13,
  126465. 11,13,13,15,13,15,15,15,13,13,10,11,11,11,12,10,
  126466. 14,11,15,15,14,14,13,10,10,12,11,13,13,14,14,15,
  126467. 15,15,15,15,11,11,11,11,12,11,15,12,15,15,15,15,
  126468. 15,12,12,11,11,14,12,13,14,
  126469. };
  126470. static float _vq_quantthresh__44cn1_s_p8_1[] = {
  126471. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  126472. 42.5, 59.5, 76.5, 93.5,
  126473. };
  126474. static long _vq_quantmap__44cn1_s_p8_1[] = {
  126475. 11, 9, 7, 5, 3, 1, 0, 2,
  126476. 4, 6, 8, 10, 12,
  126477. };
  126478. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_1 = {
  126479. _vq_quantthresh__44cn1_s_p8_1,
  126480. _vq_quantmap__44cn1_s_p8_1,
  126481. 13,
  126482. 13
  126483. };
  126484. static static_codebook _44cn1_s_p8_1 = {
  126485. 2, 169,
  126486. _vq_lengthlist__44cn1_s_p8_1,
  126487. 1, -522616832, 1620115456, 4, 0,
  126488. _vq_quantlist__44cn1_s_p8_1,
  126489. NULL,
  126490. &_vq_auxt__44cn1_s_p8_1,
  126491. NULL,
  126492. 0
  126493. };
  126494. static long _vq_quantlist__44cn1_s_p8_2[] = {
  126495. 8,
  126496. 7,
  126497. 9,
  126498. 6,
  126499. 10,
  126500. 5,
  126501. 11,
  126502. 4,
  126503. 12,
  126504. 3,
  126505. 13,
  126506. 2,
  126507. 14,
  126508. 1,
  126509. 15,
  126510. 0,
  126511. 16,
  126512. };
  126513. static long _vq_lengthlist__44cn1_s_p8_2[] = {
  126514. 3, 4, 3, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  126515. 9,10,11,11, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  126516. 9, 9,10,10,10, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  126517. 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  126518. 9, 9,10, 9,10,11,10, 7, 6, 7, 7, 8, 8, 9, 9, 9,
  126519. 9, 9, 9, 9,10,10,10,11, 7, 7, 8, 8, 8, 8, 9, 9,
  126520. 9, 9, 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9,
  126521. 9, 9, 9, 9, 9, 9,10,11,11,11, 8, 8, 8, 8, 8, 8,
  126522. 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 8, 8, 8,
  126523. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,11, 9, 9,
  126524. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,10,11,11, 9,
  126525. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  126526. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,
  126527. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11,
  126528. 10,11,11,11, 9,10,10, 9, 9, 9, 9, 9, 9, 9,10,11,
  126529. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  126530. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  126531. 11,11,11,10,11,11,11,11,11, 9, 9, 9,10, 9, 9, 9,
  126532. 9,
  126533. };
  126534. static float _vq_quantthresh__44cn1_s_p8_2[] = {
  126535. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126536. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126537. };
  126538. static long _vq_quantmap__44cn1_s_p8_2[] = {
  126539. 15, 13, 11, 9, 7, 5, 3, 1,
  126540. 0, 2, 4, 6, 8, 10, 12, 14,
  126541. 16,
  126542. };
  126543. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_2 = {
  126544. _vq_quantthresh__44cn1_s_p8_2,
  126545. _vq_quantmap__44cn1_s_p8_2,
  126546. 17,
  126547. 17
  126548. };
  126549. static static_codebook _44cn1_s_p8_2 = {
  126550. 2, 289,
  126551. _vq_lengthlist__44cn1_s_p8_2,
  126552. 1, -529530880, 1611661312, 5, 0,
  126553. _vq_quantlist__44cn1_s_p8_2,
  126554. NULL,
  126555. &_vq_auxt__44cn1_s_p8_2,
  126556. NULL,
  126557. 0
  126558. };
  126559. static long _huff_lengthlist__44cn1_s_short[] = {
  126560. 10, 9,12,15,12,13,16,14,16, 7, 1, 5,14, 7,10,13,
  126561. 16,16, 9, 4, 6,16, 8,11,16,16,16,14, 4, 7,16, 9,
  126562. 12,14,16,16,10, 5, 7,14, 9,12,14,15,15,13, 8, 9,
  126563. 14,10,12,13,14,15,13, 9, 9, 7, 6, 8,11,12,12,14,
  126564. 8, 8, 5, 4, 5, 8,11,12,16,10,10, 6, 5, 6, 8, 9,
  126565. 10,
  126566. };
  126567. static static_codebook _huff_book__44cn1_s_short = {
  126568. 2, 81,
  126569. _huff_lengthlist__44cn1_s_short,
  126570. 0, 0, 0, 0, 0,
  126571. NULL,
  126572. NULL,
  126573. NULL,
  126574. NULL,
  126575. 0
  126576. };
  126577. static long _huff_lengthlist__44cn1_sm_long[] = {
  126578. 3, 3, 8, 8, 8, 8,10,12,14, 3, 2, 6, 7, 7, 8,10,
  126579. 12,16, 7, 6, 7, 9, 8,10,12,14,16, 8, 6, 8, 4, 5,
  126580. 7, 9,11,13, 7, 6, 8, 5, 6, 7, 9,11,14, 8, 8,10,
  126581. 7, 7, 6, 8,10,13, 9,11,12, 9, 9, 7, 8,10,12,10,
  126582. 13,15,11,11,10, 9,10,13,13,16,17,14,15,14,13,14,
  126583. 17,
  126584. };
  126585. static static_codebook _huff_book__44cn1_sm_long = {
  126586. 2, 81,
  126587. _huff_lengthlist__44cn1_sm_long,
  126588. 0, 0, 0, 0, 0,
  126589. NULL,
  126590. NULL,
  126591. NULL,
  126592. NULL,
  126593. 0
  126594. };
  126595. static long _vq_quantlist__44cn1_sm_p1_0[] = {
  126596. 1,
  126597. 0,
  126598. 2,
  126599. };
  126600. static long _vq_lengthlist__44cn1_sm_p1_0[] = {
  126601. 1, 4, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  126602. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  126607. 0, 0, 0, 7, 8, 9, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  126612. 0, 0, 0, 0, 8, 9, 9, 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, 5, 8, 8, 0, 0, 0, 0,
  126647. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7,10, 9, 0, 0, 0,
  126652. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  126657. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  126693. 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  126698. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10,
  126703. 0, 0, 0, 0, 0, 0, 9,10, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127011. 0,
  127012. };
  127013. static float _vq_quantthresh__44cn1_sm_p1_0[] = {
  127014. -0.5, 0.5,
  127015. };
  127016. static long _vq_quantmap__44cn1_sm_p1_0[] = {
  127017. 1, 0, 2,
  127018. };
  127019. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p1_0 = {
  127020. _vq_quantthresh__44cn1_sm_p1_0,
  127021. _vq_quantmap__44cn1_sm_p1_0,
  127022. 3,
  127023. 3
  127024. };
  127025. static static_codebook _44cn1_sm_p1_0 = {
  127026. 8, 6561,
  127027. _vq_lengthlist__44cn1_sm_p1_0,
  127028. 1, -535822336, 1611661312, 2, 0,
  127029. _vq_quantlist__44cn1_sm_p1_0,
  127030. NULL,
  127031. &_vq_auxt__44cn1_sm_p1_0,
  127032. NULL,
  127033. 0
  127034. };
  127035. static long _vq_quantlist__44cn1_sm_p2_0[] = {
  127036. 2,
  127037. 1,
  127038. 3,
  127039. 0,
  127040. 4,
  127041. };
  127042. static long _vq_lengthlist__44cn1_sm_p2_0[] = {
  127043. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  127045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127046. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  127048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127049. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  127050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127082. 0,
  127083. };
  127084. static float _vq_quantthresh__44cn1_sm_p2_0[] = {
  127085. -1.5, -0.5, 0.5, 1.5,
  127086. };
  127087. static long _vq_quantmap__44cn1_sm_p2_0[] = {
  127088. 3, 1, 0, 2, 4,
  127089. };
  127090. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p2_0 = {
  127091. _vq_quantthresh__44cn1_sm_p2_0,
  127092. _vq_quantmap__44cn1_sm_p2_0,
  127093. 5,
  127094. 5
  127095. };
  127096. static static_codebook _44cn1_sm_p2_0 = {
  127097. 4, 625,
  127098. _vq_lengthlist__44cn1_sm_p2_0,
  127099. 1, -533725184, 1611661312, 3, 0,
  127100. _vq_quantlist__44cn1_sm_p2_0,
  127101. NULL,
  127102. &_vq_auxt__44cn1_sm_p2_0,
  127103. NULL,
  127104. 0
  127105. };
  127106. static long _vq_quantlist__44cn1_sm_p3_0[] = {
  127107. 4,
  127108. 3,
  127109. 5,
  127110. 2,
  127111. 6,
  127112. 1,
  127113. 7,
  127114. 0,
  127115. 8,
  127116. };
  127117. static long _vq_lengthlist__44cn1_sm_p3_0[] = {
  127118. 1, 3, 4, 7, 7, 0, 0, 0, 0, 0, 4, 4, 7, 7, 0, 0,
  127119. 0, 0, 0, 4, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  127120. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  127121. 9, 9, 0, 0, 0, 0, 0, 0, 0,10, 9, 0, 0, 0, 0, 0,
  127122. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127123. 0,
  127124. };
  127125. static float _vq_quantthresh__44cn1_sm_p3_0[] = {
  127126. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127127. };
  127128. static long _vq_quantmap__44cn1_sm_p3_0[] = {
  127129. 7, 5, 3, 1, 0, 2, 4, 6,
  127130. 8,
  127131. };
  127132. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p3_0 = {
  127133. _vq_quantthresh__44cn1_sm_p3_0,
  127134. _vq_quantmap__44cn1_sm_p3_0,
  127135. 9,
  127136. 9
  127137. };
  127138. static static_codebook _44cn1_sm_p3_0 = {
  127139. 2, 81,
  127140. _vq_lengthlist__44cn1_sm_p3_0,
  127141. 1, -531628032, 1611661312, 4, 0,
  127142. _vq_quantlist__44cn1_sm_p3_0,
  127143. NULL,
  127144. &_vq_auxt__44cn1_sm_p3_0,
  127145. NULL,
  127146. 0
  127147. };
  127148. static long _vq_quantlist__44cn1_sm_p4_0[] = {
  127149. 4,
  127150. 3,
  127151. 5,
  127152. 2,
  127153. 6,
  127154. 1,
  127155. 7,
  127156. 0,
  127157. 8,
  127158. };
  127159. static long _vq_lengthlist__44cn1_sm_p4_0[] = {
  127160. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  127161. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  127162. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  127163. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  127164. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  127165. 11,
  127166. };
  127167. static float _vq_quantthresh__44cn1_sm_p4_0[] = {
  127168. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127169. };
  127170. static long _vq_quantmap__44cn1_sm_p4_0[] = {
  127171. 7, 5, 3, 1, 0, 2, 4, 6,
  127172. 8,
  127173. };
  127174. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p4_0 = {
  127175. _vq_quantthresh__44cn1_sm_p4_0,
  127176. _vq_quantmap__44cn1_sm_p4_0,
  127177. 9,
  127178. 9
  127179. };
  127180. static static_codebook _44cn1_sm_p4_0 = {
  127181. 2, 81,
  127182. _vq_lengthlist__44cn1_sm_p4_0,
  127183. 1, -531628032, 1611661312, 4, 0,
  127184. _vq_quantlist__44cn1_sm_p4_0,
  127185. NULL,
  127186. &_vq_auxt__44cn1_sm_p4_0,
  127187. NULL,
  127188. 0
  127189. };
  127190. static long _vq_quantlist__44cn1_sm_p5_0[] = {
  127191. 8,
  127192. 7,
  127193. 9,
  127194. 6,
  127195. 10,
  127196. 5,
  127197. 11,
  127198. 4,
  127199. 12,
  127200. 3,
  127201. 13,
  127202. 2,
  127203. 14,
  127204. 1,
  127205. 15,
  127206. 0,
  127207. 16,
  127208. };
  127209. static long _vq_lengthlist__44cn1_sm_p5_0[] = {
  127210. 1, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  127211. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  127212. 12,12, 0, 6, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  127213. 11,12,12, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  127214. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,11,
  127215. 11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  127216. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  127217. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  127218. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  127219. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  127220. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  127221. 9,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0, 0,
  127222. 10,10,11,11,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  127223. 0, 0, 0,11,11,11,11,12,12,13,13,14,14, 0, 0, 0,
  127224. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  127225. 0, 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0,
  127226. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,14,14,14,14,
  127227. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,14,14,
  127228. 14,
  127229. };
  127230. static float _vq_quantthresh__44cn1_sm_p5_0[] = {
  127231. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127232. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127233. };
  127234. static long _vq_quantmap__44cn1_sm_p5_0[] = {
  127235. 15, 13, 11, 9, 7, 5, 3, 1,
  127236. 0, 2, 4, 6, 8, 10, 12, 14,
  127237. 16,
  127238. };
  127239. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p5_0 = {
  127240. _vq_quantthresh__44cn1_sm_p5_0,
  127241. _vq_quantmap__44cn1_sm_p5_0,
  127242. 17,
  127243. 17
  127244. };
  127245. static static_codebook _44cn1_sm_p5_0 = {
  127246. 2, 289,
  127247. _vq_lengthlist__44cn1_sm_p5_0,
  127248. 1, -529530880, 1611661312, 5, 0,
  127249. _vq_quantlist__44cn1_sm_p5_0,
  127250. NULL,
  127251. &_vq_auxt__44cn1_sm_p5_0,
  127252. NULL,
  127253. 0
  127254. };
  127255. static long _vq_quantlist__44cn1_sm_p6_0[] = {
  127256. 1,
  127257. 0,
  127258. 2,
  127259. };
  127260. static long _vq_lengthlist__44cn1_sm_p6_0[] = {
  127261. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 6,10, 9, 9,11,
  127262. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  127263. 11,11,11,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  127264. 11,10,11,11,10,10, 7,11,11,11,11,11,12,11,11, 7,
  127265. 9, 9,11,10,10,12,10,10, 7, 9, 9,11,10,10,11,10,
  127266. 10,
  127267. };
  127268. static float _vq_quantthresh__44cn1_sm_p6_0[] = {
  127269. -5.5, 5.5,
  127270. };
  127271. static long _vq_quantmap__44cn1_sm_p6_0[] = {
  127272. 1, 0, 2,
  127273. };
  127274. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_0 = {
  127275. _vq_quantthresh__44cn1_sm_p6_0,
  127276. _vq_quantmap__44cn1_sm_p6_0,
  127277. 3,
  127278. 3
  127279. };
  127280. static static_codebook _44cn1_sm_p6_0 = {
  127281. 4, 81,
  127282. _vq_lengthlist__44cn1_sm_p6_0,
  127283. 1, -529137664, 1618345984, 2, 0,
  127284. _vq_quantlist__44cn1_sm_p6_0,
  127285. NULL,
  127286. &_vq_auxt__44cn1_sm_p6_0,
  127287. NULL,
  127288. 0
  127289. };
  127290. static long _vq_quantlist__44cn1_sm_p6_1[] = {
  127291. 5,
  127292. 4,
  127293. 6,
  127294. 3,
  127295. 7,
  127296. 2,
  127297. 8,
  127298. 1,
  127299. 9,
  127300. 0,
  127301. 10,
  127302. };
  127303. static long _vq_lengthlist__44cn1_sm_p6_1[] = {
  127304. 2, 4, 4, 5, 5, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  127305. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  127306. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  127307. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  127308. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  127309. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  127310. 8, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 8, 9,10,10,
  127311. 10,10,10, 8, 9, 8, 8, 9, 8,
  127312. };
  127313. static float _vq_quantthresh__44cn1_sm_p6_1[] = {
  127314. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  127315. 3.5, 4.5,
  127316. };
  127317. static long _vq_quantmap__44cn1_sm_p6_1[] = {
  127318. 9, 7, 5, 3, 1, 0, 2, 4,
  127319. 6, 8, 10,
  127320. };
  127321. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_1 = {
  127322. _vq_quantthresh__44cn1_sm_p6_1,
  127323. _vq_quantmap__44cn1_sm_p6_1,
  127324. 11,
  127325. 11
  127326. };
  127327. static static_codebook _44cn1_sm_p6_1 = {
  127328. 2, 121,
  127329. _vq_lengthlist__44cn1_sm_p6_1,
  127330. 1, -531365888, 1611661312, 4, 0,
  127331. _vq_quantlist__44cn1_sm_p6_1,
  127332. NULL,
  127333. &_vq_auxt__44cn1_sm_p6_1,
  127334. NULL,
  127335. 0
  127336. };
  127337. static long _vq_quantlist__44cn1_sm_p7_0[] = {
  127338. 6,
  127339. 5,
  127340. 7,
  127341. 4,
  127342. 8,
  127343. 3,
  127344. 9,
  127345. 2,
  127346. 10,
  127347. 1,
  127348. 11,
  127349. 0,
  127350. 12,
  127351. };
  127352. static long _vq_lengthlist__44cn1_sm_p7_0[] = {
  127353. 1, 4, 4, 6, 6, 7, 7, 7, 7, 9, 9,10,10, 7, 5, 5,
  127354. 7, 7, 8, 8, 8, 8,10, 9,11,10, 7, 5, 5, 7, 7, 8,
  127355. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  127356. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  127357. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,12,12, 0,13,
  127358. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10,
  127359. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  127360. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,13,
  127361. 13,13, 0, 0, 0,14,14,11,10,11,11,12,12,13,13, 0,
  127362. 0, 0, 0, 0,12,12,12,12,13,13,13,14, 0, 0, 0, 0,
  127363. 0,13,12,12,12,13,13,13,14,
  127364. };
  127365. static float _vq_quantthresh__44cn1_sm_p7_0[] = {
  127366. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  127367. 12.5, 17.5, 22.5, 27.5,
  127368. };
  127369. static long _vq_quantmap__44cn1_sm_p7_0[] = {
  127370. 11, 9, 7, 5, 3, 1, 0, 2,
  127371. 4, 6, 8, 10, 12,
  127372. };
  127373. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_0 = {
  127374. _vq_quantthresh__44cn1_sm_p7_0,
  127375. _vq_quantmap__44cn1_sm_p7_0,
  127376. 13,
  127377. 13
  127378. };
  127379. static static_codebook _44cn1_sm_p7_0 = {
  127380. 2, 169,
  127381. _vq_lengthlist__44cn1_sm_p7_0,
  127382. 1, -526516224, 1616117760, 4, 0,
  127383. _vq_quantlist__44cn1_sm_p7_0,
  127384. NULL,
  127385. &_vq_auxt__44cn1_sm_p7_0,
  127386. NULL,
  127387. 0
  127388. };
  127389. static long _vq_quantlist__44cn1_sm_p7_1[] = {
  127390. 2,
  127391. 1,
  127392. 3,
  127393. 0,
  127394. 4,
  127395. };
  127396. static long _vq_lengthlist__44cn1_sm_p7_1[] = {
  127397. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  127398. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  127399. };
  127400. static float _vq_quantthresh__44cn1_sm_p7_1[] = {
  127401. -1.5, -0.5, 0.5, 1.5,
  127402. };
  127403. static long _vq_quantmap__44cn1_sm_p7_1[] = {
  127404. 3, 1, 0, 2, 4,
  127405. };
  127406. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_1 = {
  127407. _vq_quantthresh__44cn1_sm_p7_1,
  127408. _vq_quantmap__44cn1_sm_p7_1,
  127409. 5,
  127410. 5
  127411. };
  127412. static static_codebook _44cn1_sm_p7_1 = {
  127413. 2, 25,
  127414. _vq_lengthlist__44cn1_sm_p7_1,
  127415. 1, -533725184, 1611661312, 3, 0,
  127416. _vq_quantlist__44cn1_sm_p7_1,
  127417. NULL,
  127418. &_vq_auxt__44cn1_sm_p7_1,
  127419. NULL,
  127420. 0
  127421. };
  127422. static long _vq_quantlist__44cn1_sm_p8_0[] = {
  127423. 4,
  127424. 3,
  127425. 5,
  127426. 2,
  127427. 6,
  127428. 1,
  127429. 7,
  127430. 0,
  127431. 8,
  127432. };
  127433. static long _vq_lengthlist__44cn1_sm_p8_0[] = {
  127434. 1, 4, 4,12,11,13,13,14,14, 4, 7, 7,11,13,14,14,
  127435. 14,14, 3, 8, 3,14,14,14,14,14,14,14,10,12,14,14,
  127436. 14,14,14,14,14,14, 5,14, 8,14,14,14,14,14,12,14,
  127437. 13,14,14,14,14,14,14,14,13,14,10,14,14,14,14,14,
  127438. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  127439. 14,
  127440. };
  127441. static float _vq_quantthresh__44cn1_sm_p8_0[] = {
  127442. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  127443. };
  127444. static long _vq_quantmap__44cn1_sm_p8_0[] = {
  127445. 7, 5, 3, 1, 0, 2, 4, 6,
  127446. 8,
  127447. };
  127448. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_0 = {
  127449. _vq_quantthresh__44cn1_sm_p8_0,
  127450. _vq_quantmap__44cn1_sm_p8_0,
  127451. 9,
  127452. 9
  127453. };
  127454. static static_codebook _44cn1_sm_p8_0 = {
  127455. 2, 81,
  127456. _vq_lengthlist__44cn1_sm_p8_0,
  127457. 1, -516186112, 1627103232, 4, 0,
  127458. _vq_quantlist__44cn1_sm_p8_0,
  127459. NULL,
  127460. &_vq_auxt__44cn1_sm_p8_0,
  127461. NULL,
  127462. 0
  127463. };
  127464. static long _vq_quantlist__44cn1_sm_p8_1[] = {
  127465. 6,
  127466. 5,
  127467. 7,
  127468. 4,
  127469. 8,
  127470. 3,
  127471. 9,
  127472. 2,
  127473. 10,
  127474. 1,
  127475. 11,
  127476. 0,
  127477. 12,
  127478. };
  127479. static long _vq_lengthlist__44cn1_sm_p8_1[] = {
  127480. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,11,11, 6, 5, 5,
  127481. 7, 7, 8, 8,10,10,10,11,11,11, 6, 5, 5, 7, 7, 8,
  127482. 8,10,10,11,12,12,12,14, 7, 7, 7, 8, 9, 9,11,11,
  127483. 11,12,11,12,17, 7, 7, 8, 7, 9, 9,11,11,12,12,12,
  127484. 12,14,11,11, 8, 8,10,10,11,12,12,13,11,12,14,11,
  127485. 11, 8, 8,10,10,11,12,12,13,13,12,14,15,14,10,10,
  127486. 10,10,11,12,12,12,12,11,14,13,16,10,10,10, 9,12,
  127487. 11,12,12,13,14,14,15,14,14,13,10,10,11,11,12,11,
  127488. 13,11,14,12,15,13,14,11,10,12,10,12,12,13,13,13,
  127489. 13,14,15,15,12,12,11,11,12,11,13,12,14,14,14,14,
  127490. 17,12,12,11,10,13,11,13,13,
  127491. };
  127492. static float _vq_quantthresh__44cn1_sm_p8_1[] = {
  127493. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  127494. 42.5, 59.5, 76.5, 93.5,
  127495. };
  127496. static long _vq_quantmap__44cn1_sm_p8_1[] = {
  127497. 11, 9, 7, 5, 3, 1, 0, 2,
  127498. 4, 6, 8, 10, 12,
  127499. };
  127500. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_1 = {
  127501. _vq_quantthresh__44cn1_sm_p8_1,
  127502. _vq_quantmap__44cn1_sm_p8_1,
  127503. 13,
  127504. 13
  127505. };
  127506. static static_codebook _44cn1_sm_p8_1 = {
  127507. 2, 169,
  127508. _vq_lengthlist__44cn1_sm_p8_1,
  127509. 1, -522616832, 1620115456, 4, 0,
  127510. _vq_quantlist__44cn1_sm_p8_1,
  127511. NULL,
  127512. &_vq_auxt__44cn1_sm_p8_1,
  127513. NULL,
  127514. 0
  127515. };
  127516. static long _vq_quantlist__44cn1_sm_p8_2[] = {
  127517. 8,
  127518. 7,
  127519. 9,
  127520. 6,
  127521. 10,
  127522. 5,
  127523. 11,
  127524. 4,
  127525. 12,
  127526. 3,
  127527. 13,
  127528. 2,
  127529. 14,
  127530. 1,
  127531. 15,
  127532. 0,
  127533. 16,
  127534. };
  127535. static long _vq_lengthlist__44cn1_sm_p8_2[] = {
  127536. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  127537. 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  127538. 9, 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  127539. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  127540. 9, 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,
  127541. 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9, 9,
  127542. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9,
  127543. 9, 9, 9, 9, 9, 9, 9,11,10,11, 8, 8, 8, 8, 8, 8,
  127544. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11, 8, 8, 8,
  127545. 8, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  127546. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,11,11, 9,
  127547. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,10,11,11,
  127548. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,
  127549. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,
  127550. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,11,10,
  127551. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  127552. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  127553. 10,11,11,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  127554. 9,
  127555. };
  127556. static float _vq_quantthresh__44cn1_sm_p8_2[] = {
  127557. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127558. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127559. };
  127560. static long _vq_quantmap__44cn1_sm_p8_2[] = {
  127561. 15, 13, 11, 9, 7, 5, 3, 1,
  127562. 0, 2, 4, 6, 8, 10, 12, 14,
  127563. 16,
  127564. };
  127565. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_2 = {
  127566. _vq_quantthresh__44cn1_sm_p8_2,
  127567. _vq_quantmap__44cn1_sm_p8_2,
  127568. 17,
  127569. 17
  127570. };
  127571. static static_codebook _44cn1_sm_p8_2 = {
  127572. 2, 289,
  127573. _vq_lengthlist__44cn1_sm_p8_2,
  127574. 1, -529530880, 1611661312, 5, 0,
  127575. _vq_quantlist__44cn1_sm_p8_2,
  127576. NULL,
  127577. &_vq_auxt__44cn1_sm_p8_2,
  127578. NULL,
  127579. 0
  127580. };
  127581. static long _huff_lengthlist__44cn1_sm_short[] = {
  127582. 5, 6,12,14,12,14,16,17,18, 4, 2, 5,11, 7,10,12,
  127583. 14,15, 9, 4, 5,11, 7,10,13,15,18,15, 6, 7, 5, 6,
  127584. 8,11,13,16,11, 5, 6, 5, 5, 6, 9,13,15,12, 5, 7,
  127585. 6, 5, 6, 9,12,14,12, 6, 7, 8, 6, 7, 9,12,13,14,
  127586. 8, 8, 7, 5, 5, 8,10,12,16, 9, 9, 8, 6, 6, 7, 9,
  127587. 9,
  127588. };
  127589. static static_codebook _huff_book__44cn1_sm_short = {
  127590. 2, 81,
  127591. _huff_lengthlist__44cn1_sm_short,
  127592. 0, 0, 0, 0, 0,
  127593. NULL,
  127594. NULL,
  127595. NULL,
  127596. NULL,
  127597. 0
  127598. };
  127599. /*** End of inlined file: res_books_stereo.h ***/
  127600. static vorbis_info_residue0 _residue_44_low={
  127601. 0,-1, -1, 9,-1,
  127602. {0},
  127603. {-1},
  127604. { .5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  127605. { .5, .5, .5, 999., 4.5, 8.5, 16.5, 32.5},
  127606. };
  127607. static vorbis_info_residue0 _residue_44_mid={
  127608. 0,-1, -1, 10,-1,
  127609. {0},
  127610. {-1},
  127611. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  127612. { .5, .5, 999., .5, 999., 4.5, 8.5, 16.5, 32.5},
  127613. };
  127614. static vorbis_info_residue0 _residue_44_high={
  127615. 0,-1, -1, 10,-1,
  127616. {0},
  127617. {-1},
  127618. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  127619. { .5, 1.5, 2.5, 3.5, 4.5, 8.5, 16.5, 71.5,157.5},
  127620. };
  127621. static static_bookblock _resbook_44s_n1={
  127622. {
  127623. {0},{0,0,&_44cn1_s_p1_0},{0,0,&_44cn1_s_p2_0},
  127624. {0,0,&_44cn1_s_p3_0},{0,0,&_44cn1_s_p4_0},{0,0,&_44cn1_s_p5_0},
  127625. {&_44cn1_s_p6_0,&_44cn1_s_p6_1},{&_44cn1_s_p7_0,&_44cn1_s_p7_1},
  127626. {&_44cn1_s_p8_0,&_44cn1_s_p8_1,&_44cn1_s_p8_2}
  127627. }
  127628. };
  127629. static static_bookblock _resbook_44sm_n1={
  127630. {
  127631. {0},{0,0,&_44cn1_sm_p1_0},{0,0,&_44cn1_sm_p2_0},
  127632. {0,0,&_44cn1_sm_p3_0},{0,0,&_44cn1_sm_p4_0},{0,0,&_44cn1_sm_p5_0},
  127633. {&_44cn1_sm_p6_0,&_44cn1_sm_p6_1},{&_44cn1_sm_p7_0,&_44cn1_sm_p7_1},
  127634. {&_44cn1_sm_p8_0,&_44cn1_sm_p8_1,&_44cn1_sm_p8_2}
  127635. }
  127636. };
  127637. static static_bookblock _resbook_44s_0={
  127638. {
  127639. {0},{0,0,&_44c0_s_p1_0},{0,0,&_44c0_s_p2_0},
  127640. {0,0,&_44c0_s_p3_0},{0,0,&_44c0_s_p4_0},{0,0,&_44c0_s_p5_0},
  127641. {&_44c0_s_p6_0,&_44c0_s_p6_1},{&_44c0_s_p7_0,&_44c0_s_p7_1},
  127642. {&_44c0_s_p8_0,&_44c0_s_p8_1,&_44c0_s_p8_2}
  127643. }
  127644. };
  127645. static static_bookblock _resbook_44sm_0={
  127646. {
  127647. {0},{0,0,&_44c0_sm_p1_0},{0,0,&_44c0_sm_p2_0},
  127648. {0,0,&_44c0_sm_p3_0},{0,0,&_44c0_sm_p4_0},{0,0,&_44c0_sm_p5_0},
  127649. {&_44c0_sm_p6_0,&_44c0_sm_p6_1},{&_44c0_sm_p7_0,&_44c0_sm_p7_1},
  127650. {&_44c0_sm_p8_0,&_44c0_sm_p8_1,&_44c0_sm_p8_2}
  127651. }
  127652. };
  127653. static static_bookblock _resbook_44s_1={
  127654. {
  127655. {0},{0,0,&_44c1_s_p1_0},{0,0,&_44c1_s_p2_0},
  127656. {0,0,&_44c1_s_p3_0},{0,0,&_44c1_s_p4_0},{0,0,&_44c1_s_p5_0},
  127657. {&_44c1_s_p6_0,&_44c1_s_p6_1},{&_44c1_s_p7_0,&_44c1_s_p7_1},
  127658. {&_44c1_s_p8_0,&_44c1_s_p8_1,&_44c1_s_p8_2}
  127659. }
  127660. };
  127661. static static_bookblock _resbook_44sm_1={
  127662. {
  127663. {0},{0,0,&_44c1_sm_p1_0},{0,0,&_44c1_sm_p2_0},
  127664. {0,0,&_44c1_sm_p3_0},{0,0,&_44c1_sm_p4_0},{0,0,&_44c1_sm_p5_0},
  127665. {&_44c1_sm_p6_0,&_44c1_sm_p6_1},{&_44c1_sm_p7_0,&_44c1_sm_p7_1},
  127666. {&_44c1_sm_p8_0,&_44c1_sm_p8_1,&_44c1_sm_p8_2}
  127667. }
  127668. };
  127669. static static_bookblock _resbook_44s_2={
  127670. {
  127671. {0},{0,0,&_44c2_s_p1_0},{0,0,&_44c2_s_p2_0},{0,0,&_44c2_s_p3_0},
  127672. {0,0,&_44c2_s_p4_0},{0,0,&_44c2_s_p5_0},{0,0,&_44c2_s_p6_0},
  127673. {&_44c2_s_p7_0,&_44c2_s_p7_1},{&_44c2_s_p8_0,&_44c2_s_p8_1},
  127674. {&_44c2_s_p9_0,&_44c2_s_p9_1,&_44c2_s_p9_2}
  127675. }
  127676. };
  127677. static static_bookblock _resbook_44s_3={
  127678. {
  127679. {0},{0,0,&_44c3_s_p1_0},{0,0,&_44c3_s_p2_0},{0,0,&_44c3_s_p3_0},
  127680. {0,0,&_44c3_s_p4_0},{0,0,&_44c3_s_p5_0},{0,0,&_44c3_s_p6_0},
  127681. {&_44c3_s_p7_0,&_44c3_s_p7_1},{&_44c3_s_p8_0,&_44c3_s_p8_1},
  127682. {&_44c3_s_p9_0,&_44c3_s_p9_1,&_44c3_s_p9_2}
  127683. }
  127684. };
  127685. static static_bookblock _resbook_44s_4={
  127686. {
  127687. {0},{0,0,&_44c4_s_p1_0},{0,0,&_44c4_s_p2_0},{0,0,&_44c4_s_p3_0},
  127688. {0,0,&_44c4_s_p4_0},{0,0,&_44c4_s_p5_0},{0,0,&_44c4_s_p6_0},
  127689. {&_44c4_s_p7_0,&_44c4_s_p7_1},{&_44c4_s_p8_0,&_44c4_s_p8_1},
  127690. {&_44c4_s_p9_0,&_44c4_s_p9_1,&_44c4_s_p9_2}
  127691. }
  127692. };
  127693. static static_bookblock _resbook_44s_5={
  127694. {
  127695. {0},{0,0,&_44c5_s_p1_0},{0,0,&_44c5_s_p2_0},{0,0,&_44c5_s_p3_0},
  127696. {0,0,&_44c5_s_p4_0},{0,0,&_44c5_s_p5_0},{0,0,&_44c5_s_p6_0},
  127697. {&_44c5_s_p7_0,&_44c5_s_p7_1},{&_44c5_s_p8_0,&_44c5_s_p8_1},
  127698. {&_44c5_s_p9_0,&_44c5_s_p9_1,&_44c5_s_p9_2}
  127699. }
  127700. };
  127701. static static_bookblock _resbook_44s_6={
  127702. {
  127703. {0},{0,0,&_44c6_s_p1_0},{0,0,&_44c6_s_p2_0},{0,0,&_44c6_s_p3_0},
  127704. {0,0,&_44c6_s_p4_0},
  127705. {&_44c6_s_p5_0,&_44c6_s_p5_1},
  127706. {&_44c6_s_p6_0,&_44c6_s_p6_1},
  127707. {&_44c6_s_p7_0,&_44c6_s_p7_1},
  127708. {&_44c6_s_p8_0,&_44c6_s_p8_1},
  127709. {&_44c6_s_p9_0,&_44c6_s_p9_1,&_44c6_s_p9_2}
  127710. }
  127711. };
  127712. static static_bookblock _resbook_44s_7={
  127713. {
  127714. {0},{0,0,&_44c7_s_p1_0},{0,0,&_44c7_s_p2_0},{0,0,&_44c7_s_p3_0},
  127715. {0,0,&_44c7_s_p4_0},
  127716. {&_44c7_s_p5_0,&_44c7_s_p5_1},
  127717. {&_44c7_s_p6_0,&_44c7_s_p6_1},
  127718. {&_44c7_s_p7_0,&_44c7_s_p7_1},
  127719. {&_44c7_s_p8_0,&_44c7_s_p8_1},
  127720. {&_44c7_s_p9_0,&_44c7_s_p9_1,&_44c7_s_p9_2}
  127721. }
  127722. };
  127723. static static_bookblock _resbook_44s_8={
  127724. {
  127725. {0},{0,0,&_44c8_s_p1_0},{0,0,&_44c8_s_p2_0},{0,0,&_44c8_s_p3_0},
  127726. {0,0,&_44c8_s_p4_0},
  127727. {&_44c8_s_p5_0,&_44c8_s_p5_1},
  127728. {&_44c8_s_p6_0,&_44c8_s_p6_1},
  127729. {&_44c8_s_p7_0,&_44c8_s_p7_1},
  127730. {&_44c8_s_p8_0,&_44c8_s_p8_1},
  127731. {&_44c8_s_p9_0,&_44c8_s_p9_1,&_44c8_s_p9_2}
  127732. }
  127733. };
  127734. static static_bookblock _resbook_44s_9={
  127735. {
  127736. {0},{0,0,&_44c9_s_p1_0},{0,0,&_44c9_s_p2_0},{0,0,&_44c9_s_p3_0},
  127737. {0,0,&_44c9_s_p4_0},
  127738. {&_44c9_s_p5_0,&_44c9_s_p5_1},
  127739. {&_44c9_s_p6_0,&_44c9_s_p6_1},
  127740. {&_44c9_s_p7_0,&_44c9_s_p7_1},
  127741. {&_44c9_s_p8_0,&_44c9_s_p8_1},
  127742. {&_44c9_s_p9_0,&_44c9_s_p9_1,&_44c9_s_p9_2}
  127743. }
  127744. };
  127745. static vorbis_residue_template _res_44s_n1[]={
  127746. {2,0, &_residue_44_low,
  127747. &_huff_book__44cn1_s_short,&_huff_book__44cn1_sm_short,
  127748. &_resbook_44s_n1,&_resbook_44sm_n1},
  127749. {2,0, &_residue_44_low,
  127750. &_huff_book__44cn1_s_long,&_huff_book__44cn1_sm_long,
  127751. &_resbook_44s_n1,&_resbook_44sm_n1}
  127752. };
  127753. static vorbis_residue_template _res_44s_0[]={
  127754. {2,0, &_residue_44_low,
  127755. &_huff_book__44c0_s_short,&_huff_book__44c0_sm_short,
  127756. &_resbook_44s_0,&_resbook_44sm_0},
  127757. {2,0, &_residue_44_low,
  127758. &_huff_book__44c0_s_long,&_huff_book__44c0_sm_long,
  127759. &_resbook_44s_0,&_resbook_44sm_0}
  127760. };
  127761. static vorbis_residue_template _res_44s_1[]={
  127762. {2,0, &_residue_44_low,
  127763. &_huff_book__44c1_s_short,&_huff_book__44c1_sm_short,
  127764. &_resbook_44s_1,&_resbook_44sm_1},
  127765. {2,0, &_residue_44_low,
  127766. &_huff_book__44c1_s_long,&_huff_book__44c1_sm_long,
  127767. &_resbook_44s_1,&_resbook_44sm_1}
  127768. };
  127769. static vorbis_residue_template _res_44s_2[]={
  127770. {2,0, &_residue_44_mid,
  127771. &_huff_book__44c2_s_short,&_huff_book__44c2_s_short,
  127772. &_resbook_44s_2,&_resbook_44s_2},
  127773. {2,0, &_residue_44_mid,
  127774. &_huff_book__44c2_s_long,&_huff_book__44c2_s_long,
  127775. &_resbook_44s_2,&_resbook_44s_2}
  127776. };
  127777. static vorbis_residue_template _res_44s_3[]={
  127778. {2,0, &_residue_44_mid,
  127779. &_huff_book__44c3_s_short,&_huff_book__44c3_s_short,
  127780. &_resbook_44s_3,&_resbook_44s_3},
  127781. {2,0, &_residue_44_mid,
  127782. &_huff_book__44c3_s_long,&_huff_book__44c3_s_long,
  127783. &_resbook_44s_3,&_resbook_44s_3}
  127784. };
  127785. static vorbis_residue_template _res_44s_4[]={
  127786. {2,0, &_residue_44_mid,
  127787. &_huff_book__44c4_s_short,&_huff_book__44c4_s_short,
  127788. &_resbook_44s_4,&_resbook_44s_4},
  127789. {2,0, &_residue_44_mid,
  127790. &_huff_book__44c4_s_long,&_huff_book__44c4_s_long,
  127791. &_resbook_44s_4,&_resbook_44s_4}
  127792. };
  127793. static vorbis_residue_template _res_44s_5[]={
  127794. {2,0, &_residue_44_mid,
  127795. &_huff_book__44c5_s_short,&_huff_book__44c5_s_short,
  127796. &_resbook_44s_5,&_resbook_44s_5},
  127797. {2,0, &_residue_44_mid,
  127798. &_huff_book__44c5_s_long,&_huff_book__44c5_s_long,
  127799. &_resbook_44s_5,&_resbook_44s_5}
  127800. };
  127801. static vorbis_residue_template _res_44s_6[]={
  127802. {2,0, &_residue_44_high,
  127803. &_huff_book__44c6_s_short,&_huff_book__44c6_s_short,
  127804. &_resbook_44s_6,&_resbook_44s_6},
  127805. {2,0, &_residue_44_high,
  127806. &_huff_book__44c6_s_long,&_huff_book__44c6_s_long,
  127807. &_resbook_44s_6,&_resbook_44s_6}
  127808. };
  127809. static vorbis_residue_template _res_44s_7[]={
  127810. {2,0, &_residue_44_high,
  127811. &_huff_book__44c7_s_short,&_huff_book__44c7_s_short,
  127812. &_resbook_44s_7,&_resbook_44s_7},
  127813. {2,0, &_residue_44_high,
  127814. &_huff_book__44c7_s_long,&_huff_book__44c7_s_long,
  127815. &_resbook_44s_7,&_resbook_44s_7}
  127816. };
  127817. static vorbis_residue_template _res_44s_8[]={
  127818. {2,0, &_residue_44_high,
  127819. &_huff_book__44c8_s_short,&_huff_book__44c8_s_short,
  127820. &_resbook_44s_8,&_resbook_44s_8},
  127821. {2,0, &_residue_44_high,
  127822. &_huff_book__44c8_s_long,&_huff_book__44c8_s_long,
  127823. &_resbook_44s_8,&_resbook_44s_8}
  127824. };
  127825. static vorbis_residue_template _res_44s_9[]={
  127826. {2,0, &_residue_44_high,
  127827. &_huff_book__44c9_s_short,&_huff_book__44c9_s_short,
  127828. &_resbook_44s_9,&_resbook_44s_9},
  127829. {2,0, &_residue_44_high,
  127830. &_huff_book__44c9_s_long,&_huff_book__44c9_s_long,
  127831. &_resbook_44s_9,&_resbook_44s_9}
  127832. };
  127833. static vorbis_mapping_template _mapres_template_44_stereo[]={
  127834. { _map_nominal, _res_44s_n1 }, /* -1 */
  127835. { _map_nominal, _res_44s_0 }, /* 0 */
  127836. { _map_nominal, _res_44s_1 }, /* 1 */
  127837. { _map_nominal, _res_44s_2 }, /* 2 */
  127838. { _map_nominal, _res_44s_3 }, /* 3 */
  127839. { _map_nominal, _res_44s_4 }, /* 4 */
  127840. { _map_nominal, _res_44s_5 }, /* 5 */
  127841. { _map_nominal, _res_44s_6 }, /* 6 */
  127842. { _map_nominal, _res_44s_7 }, /* 7 */
  127843. { _map_nominal, _res_44s_8 }, /* 8 */
  127844. { _map_nominal, _res_44s_9 }, /* 9 */
  127845. };
  127846. /*** End of inlined file: residue_44.h ***/
  127847. /*** Start of inlined file: psych_44.h ***/
  127848. static vorbis_info_psy_global _psy_global_44[5]={
  127849. {8, /* lines per eighth octave */
  127850. {20.f,14.f,12.f,12.f,12.f,12.f,12.f},
  127851. {-60.f,-30.f,-40.f,-40.f,-40.f,-40.f,-40.f}, 2,-75.f,
  127852. -6.f,
  127853. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127854. },
  127855. {8, /* lines per eighth octave */
  127856. {14.f,10.f,10.f,10.f,10.f,10.f,10.f},
  127857. {-40.f,-30.f,-25.f,-25.f,-25.f,-25.f,-25.f}, 2,-80.f,
  127858. -6.f,
  127859. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127860. },
  127861. {8, /* lines per eighth octave */
  127862. {12.f,10.f,10.f,10.f,10.f,10.f,10.f},
  127863. {-20.f,-20.f,-15.f,-15.f,-15.f,-15.f,-15.f}, 0,-80.f,
  127864. -6.f,
  127865. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127866. },
  127867. {8, /* lines per eighth octave */
  127868. {10.f,8.f,8.f,8.f,8.f,8.f,8.f},
  127869. {-20.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-80.f,
  127870. -6.f,
  127871. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127872. },
  127873. {8, /* lines per eighth octave */
  127874. {10.f,6.f,6.f,6.f,6.f,6.f,6.f},
  127875. {-15.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-85.f,
  127876. -6.f,
  127877. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127878. },
  127879. };
  127880. static compandblock _psy_compand_44[6]={
  127881. {{
  127882. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127883. 8, 9,10,11,12,13,14, 15, /* 15dB */
  127884. 16,17,18,19,20,21,22, 23, /* 23dB */
  127885. 24,25,26,27,28,29,30, 31, /* 31dB */
  127886. 32,33,34,35,36,37,38, 39, /* 39dB */
  127887. }},
  127888. {{
  127889. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  127890. 7, 7, 7, 7, 6, 6, 6, 7, /* 15dB */
  127891. 7, 8, 9,10,11,12,13, 14, /* 23dB */
  127892. 15,16,17,17,17,18,18, 19, /* 31dB */
  127893. 19,19,20,21,22,23,24, 25, /* 39dB */
  127894. }},
  127895. {{
  127896. 0, 1, 2, 3, 4, 5, 5, 5, /* 7dB */
  127897. 6, 6, 6, 5, 4, 4, 4, 4, /* 15dB */
  127898. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  127899. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  127900. 11,12,13,14,15,16,17, 18, /* 39dB */
  127901. }},
  127902. {{
  127903. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127904. 8, 9,10,11,12,13,14, 15, /* 15dB */
  127905. 16,17,18,19,20,21,22, 23, /* 23dB */
  127906. 24,25,26,27,28,29,30, 31, /* 31dB */
  127907. 32,33,34,35,36,37,38, 39, /* 39dB */
  127908. }},
  127909. {{
  127910. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127911. 8, 9,10,11,12,12,13, 13, /* 15dB */
  127912. 13,14,14,14,15,15,15, 15, /* 23dB */
  127913. 16,16,17,17,17,18,18, 19, /* 31dB */
  127914. 19,19,20,21,22,23,24, 25, /* 39dB */
  127915. }},
  127916. {{
  127917. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127918. 8, 8, 7, 6, 5, 4, 4, 4, /* 15dB */
  127919. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  127920. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  127921. 11,12,13,14,15,16,17, 18, /* 39dB */
  127922. }}
  127923. };
  127924. static vp_adjblock _vp_tonemask_adj_longblock[12]={
  127925. {{ -3, -8,-13,-15,-10,-10,-10,-10,-10,-10,-10, 0, 0, 0, 0, 0, 0}}, /* -1 */
  127926. {{ -4,-10,-14,-16,-15,-14,-13,-12,-12,-12,-11, -1, -1, -1, -1, -1, 0}}, /* 0 */
  127927. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, -1, -1, 0}}, /* 1 */
  127928. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -6, -3, -1, -1, -1, 0}}, /* 2 */
  127929. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, -1, -1, 0}}, /* 3 */
  127930. /* 4 */
  127931. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  127932. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  127933. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  127934. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  127935. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  127936. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  127937. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  127938. };
  127939. static vp_adjblock _vp_tonemask_adj_otherblock[12]={
  127940. {{ -3, -8,-13,-15,-10,-10, -9, -9, -9, -9, -9, 1, 1, 1, 1, 1, 1}}, /* -1 */
  127941. {{ -4,-10,-14,-16,-14,-13,-12,-12,-11,-11,-10, 0, 0, 0, 0, 0, 0}}, /* 0 */
  127942. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, 0, 0, 0}}, /* 1 */
  127943. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -5, -2, -1, 0, 0, 0}}, /* 2 */
  127944. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, 0, 0, 0}}, /* 3 */
  127945. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  127946. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  127947. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  127948. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  127949. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  127950. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  127951. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  127952. };
  127953. static noise3 _psy_noisebias_trans[12]={
  127954. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  127955. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  127956. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  127957. {{{-15,-15,-15,-15,-15,-12, -6, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  127958. {-30,-30,-30,-30,-26,-22,-20,-14, -8, -4, 0, 0, 0, 0, 2, 3, 6},
  127959. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -4, -4, -4, -2}}},
  127960. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  127961. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  127962. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  127963. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  127964. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  127965. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -7, -4}}},
  127966. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  127967. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  127968. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  127969. {{{-20,-20,-20,-20,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  127970. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  127971. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  127972. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  127973. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  127974. {-34,-34,-34,-34,-30,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -5}}},
  127975. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  127976. {-32,-32,-32,-32,-28,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  127977. {-34,-34,-34,-34,-30,-26,-26,-24,-22,-19,-19,-19,-19,-18,-17,-16,-12}}},
  127978. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  127979. {-32,-32,-32,-32,-28,-24,-24,-24,-18,-14,-12,-10,-10,-10, -8, -6, -2},
  127980. {-34,-34,-34,-34,-30,-26,-26,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  127981. {{{-24,-24,-24,-24,-22,-20,-15,-10, -8, -2, 0, 0, 0, 1, 2, 3, 7},
  127982. {-36,-36,-36,-36,-30,-30,-30,-24,-20,-16,-16,-16,-16,-14,-12,-10, -7},
  127983. {-36,-36,-36,-36,-34,-30,-28,-26,-24,-30,-30,-30,-30,-30,-30,-24,-20}}},
  127984. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  127985. {-38,-38,-38,-38,-36,-34,-34,-30,-24,-20,-20,-20,-20,-18,-16,-12,-10},
  127986. {-40,-40,-40,-40,-40,-40,-40,-38,-35,-35,-35,-35,-35,-35,-35,-35,-30}}},
  127987. {{{-30,-30,-30,-30,-30,-30,-30,-28,-20,-14,-14,-14,-14,-14,-14,-12,-10},
  127988. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-20},
  127989. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  127990. };
  127991. static noise3 _psy_noisebias_long[12]={
  127992. {{{-10,-10,-10,-10,-10, -4, 0, 0, 0, 6, 6, 6, 6, 10, 10, 12, 20},
  127993. {-20,-20,-20,-20,-20,-20,-10, -2, 0, 0, 0, 0, 0, 2, 4, 6, 15},
  127994. {-20,-20,-20,-20,-20,-20,-20,-10, -6, -6, -6, -6, -6, -4, -4, -4, -2}}},
  127995. {{{-10,-10,-10,-10,-10,-10, -8, 2, 2, 2, 4, 4, 5, 5, 5, 8, 10},
  127996. {-20,-20,-20,-20,-20,-20,-20,-14, -6, 0, 0, 0, 0, 0, 2, 3, 6},
  127997. {-20,-20,-20,-20,-20,-20,-20,-14, -8, -6, -6, -6, -6, -4, -4, -4, -2}}},
  127998. {{{-10,-10,-10,-10,-10,-10, -8, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  127999. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  128000. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  128001. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  128002. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  128003. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128004. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  128005. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  128006. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -5}}},
  128007. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128008. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  128009. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -7}}},
  128010. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128011. {-22,-22,-22,-22,-22,-22,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  128012. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -8}}},
  128013. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128014. {-24,-24,-24,-24,-24,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  128015. {-26,-26,-26,-26,-26,-26,-26,-18,-16,-15,-15,-15,-15,-13,-13,-12,-10}}},
  128016. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128017. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-10, -8, -8, -8, -8, -6, -4, 0},
  128018. {-26,-26,-26,-26,-26,-26,-26,-22,-20,-19,-19,-19,-19,-18,-17,-16,-12}}},
  128019. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 0, 0, 0, 0, 1, 2, 3, 7},
  128020. {-26,-26,-26,-26,-26,-26,-26,-20,-16,-12,-10,-10,-10,-10, -8, -6, -2},
  128021. {-28,-28,-28,-28,-28,-28,-28,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  128022. {{{-22,-22,-22,-22,-22,-22,-22,-18,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128023. {-26,-26,-26,-26,-26,-26,-26,-22,-18,-16,-16,-16,-16,-14,-12,-10, -7},
  128024. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128025. {{{-24,-24,-24,-24,-24,-24,-24,-24,-24,-18,-14,-14,-14,-14,-14,-12,-10},
  128026. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-20},
  128027. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128028. };
  128029. static noise3 _psy_noisebias_impulse[12]={
  128030. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128031. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128032. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128033. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 4, 8, 8, 8, 10, 12, 14, 20},
  128034. {-30,-30,-30,-30,-26,-22,-20,-14, -6, -2, 0, 0, 0, 0, 2, 3, 6},
  128035. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128036. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128037. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -4, -4, -2, -2, -2, -2, 2},
  128038. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8,-10,-10, -8, -8, -8, -6, -4}}},
  128039. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128040. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128041. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128042. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128043. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128044. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128045. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128046. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128047. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128048. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128049. {-32,-32,-32,-32,-28,-24,-22,-16,-10, -6, -8, -8, -6, -6, -6, -4, -2},
  128050. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-12,-12,-12,-12,-12,-10, -9, -5}}},
  128051. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128052. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-16,-16,-16,-16,-16,-14,-14,-12},
  128053. {-36,-36,-36,-36,-36,-34,-28,-24,-20,-20,-20,-20,-20,-20,-20,-18,-16}}},
  128054. {{{-22,-22,-22,-22,-22,-20,-14,-10, -6, 0, 0, 0, 0, 4, 4, 6, 11},
  128055. {-34,-34,-34,-34,-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-24,-22},
  128056. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128057. {{{-24,-24,-24,-24,-24,-22,-14,-10, -6, -1, -1, -1, -1, 3, 3, 5, 10},
  128058. {-34,-34,-34,-34,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-24},
  128059. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128060. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128061. {-36,-36,-36,-36,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26},
  128062. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128063. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-16,-16,-16,-16,-16,-14,-12},
  128064. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-26},
  128065. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128066. };
  128067. static noise3 _psy_noisebias_padding[12]={
  128068. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128069. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128070. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128071. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128072. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, 2, 3, 6, 6, 8, 10},
  128073. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -4, -4, -4, -4, -2, 0, 2}}},
  128074. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128075. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, 0, 0, 0, 2, 2, 4, 8},
  128076. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -6, -4, -2, 0}}},
  128077. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128078. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128079. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128080. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128081. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128082. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128083. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128084. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, -1, 0, 2, 6},
  128085. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128086. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128087. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -3, -3, -3, -3, -2, 0, 4},
  128088. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-10,-10,-10,-10,-10, -8, -5, -3}}},
  128089. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128090. {-34,-34,-34,-34,-30,-30,-24,-20,-14, -8, -4, -4, -4, -4, -3, -1, 4},
  128091. {-34,-34,-34,-34,-34,-30,-26,-20,-16,-13,-13,-13,-13,-13,-11, -8, -6}}},
  128092. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128093. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-10, -8, -6, -6, -6, -5, -3, 1},
  128094. {-34,-34,-34,-34,-32,-32,-28,-22,-18,-16,-16,-16,-16,-16,-14,-12,-10}}},
  128095. {{{-22,-22,-22,-22,-22,-20,-14,-10, -4, 0, 0, 0, 0, 3, 5, 5, 11},
  128096. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-12,-10, -8, -8, -8, -7, -5, -2},
  128097. {-36,-36,-36,-36,-36,-34,-28,-22,-20,-20,-20,-20,-20,-20,-20,-16,-14}}},
  128098. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -2, -2, -2, -2, 0, 2, 6},
  128099. {-36,-36,-36,-36,-34,-32,-32,-24,-16,-12,-12,-12,-12,-12,-10, -8, -5},
  128100. {-40,-40,-40,-40,-40,-40,-40,-32,-26,-24,-24,-24,-24,-24,-24,-20,-18}}},
  128101. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-12,-12,-12,-12,-12,-10, -8},
  128102. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-25,-25,-25,-25,-25,-25,-15},
  128103. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128104. };
  128105. static noiseguard _psy_noiseguards_44[4]={
  128106. {3,3,15},
  128107. {3,3,15},
  128108. {10,10,100},
  128109. {10,10,100},
  128110. };
  128111. static int _psy_tone_suppress[12]={
  128112. -20,-20,-20,-20,-20,-24,-30,-40,-40,-45,-45,-45,
  128113. };
  128114. static int _psy_tone_0dB[12]={
  128115. 90,90,95,95,95,95,105,105,105,105,105,105,
  128116. };
  128117. static int _psy_noise_suppress[12]={
  128118. -20,-20,-24,-24,-24,-24,-30,-40,-40,-45,-45,-45,
  128119. };
  128120. static vorbis_info_psy _psy_info_template={
  128121. -1,
  128122. -140.,-140.,
  128123. {0.f,0.f,0.f}, 0.,0., -40.f, {0.},
  128124. 1, -0.f, .5f, .5f, 0,0,0,
  128125. {{-1},{-1},{-1}},{-1},105.f,
  128126. 0,0,-1,-1,0.,
  128127. };
  128128. static int _psy_ath_floater[12]={
  128129. -100,-100,-100,-100,-100,-100,-105,-105,-105,-105,-110,-120,
  128130. };
  128131. static int _psy_ath_abs[12]={
  128132. -130,-130,-130,-130,-140,-140,-140,-140,-140,-140,-140,-150,
  128133. };
  128134. static adj_stereo _psy_stereo_modes_44[12]={
  128135. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 1, 0, 0, 0, 0},
  128136. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 5, 4, 3},
  128137. { 1, 2, 3, 4, 4, 4, 4, 4, 4, 5, 6, 7, 8, 8, 8},
  128138. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128139. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 1, 0, 0, 0, 0, 0},
  128140. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128141. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128142. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128143. {{ 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, 0, 0, 0, 0},
  128144. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128145. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128146. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128147. {{ 3, 3, 3, 3, 3, 3, 3, 2, 1, 1, 0, 0, 0, 0, 0},
  128148. { 8, 8, 6, 6, 5, 5, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128149. { 3, 4, 4, 5, 5, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128150. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128151. {{ 2, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
  128152. { 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128153. { 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 10, 10, 10, 10, 10},
  128154. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128155. {{ 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128156. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 2, 1, 0},
  128157. { 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 10, 10, 10, 10, 10},
  128158. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128159. {{ 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128160. { 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0},
  128161. { 6, 7, 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12},
  128162. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128163. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128164. { 3, 3, 3, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128165. { 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128166. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128167. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128168. { 3, 3, 3, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128169. { 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128170. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128171. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128172. { 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128173. { 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128174. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128175. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128176. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128177. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128178. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128179. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128180. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128181. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128182. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128183. };
  128184. static att3 _psy_tone_masteratt_44[12]={
  128185. {{ 35, 21, 9}, 0, 0}, /* -1 */
  128186. {{ 30, 20, 8}, -2, 1.25}, /* 0 */
  128187. /* 1 */
  128188. {{ 25, 12, 2}, 0, 0}, /* 1 */
  128189. /* 2 */
  128190. {{ 20, 9, -3}, 0, 0}, /* 2 */
  128191. {{ 20, 9, -4}, 0, 0}, /* 3 */
  128192. {{ 20, 9, -4}, 0, 0}, /* 4 */
  128193. {{ 20, 6, -6}, 0, 0}, /* 5 */
  128194. {{ 20, 3, -10}, 0, 0}, /* 6 */
  128195. {{ 18, 1, -14}, 0, 0}, /* 7 */
  128196. {{ 18, 0, -16}, 0, 0}, /* 8 */
  128197. {{ 18, -2, -16}, 0, 0}, /* 9 */
  128198. {{ 12, -2, -20}, 0, 0}, /* 10 */
  128199. };
  128200. static double _psy_lowpass_44[12]={
  128201. 13.9,15.1,15.8,16.5,17.2,18.9,20.1,48.,999.,999.,999.,999.
  128202. };
  128203. static int _noise_start_short_44[11]={
  128204. 32,16,16,16,32,9999,9999,9999,9999,9999,9999
  128205. };
  128206. static int _noise_start_long_44[11]={
  128207. 256,128,128,256,512,9999,9999,9999,9999,9999,9999
  128208. };
  128209. static int _noise_part_short_44[11]={
  128210. 8,8,8,8,8,8,8,8,8,8,8
  128211. };
  128212. static int _noise_part_long_44[11]={
  128213. 32,32,32,32,32,32,32,32,32,32,32
  128214. };
  128215. static double _noise_thresh_44[11]={
  128216. .2,.2,.2,.4,.6,9999.,9999.,9999.,9999.,9999.,9999.,
  128217. };
  128218. static double _noise_thresh_5only[2]={
  128219. .5,.5,
  128220. };
  128221. /*** End of inlined file: psych_44.h ***/
  128222. static double rate_mapping_44_stereo[12]={
  128223. 22500.,32000.,40000.,48000.,56000.,64000.,
  128224. 80000.,96000.,112000.,128000.,160000.,250001.
  128225. };
  128226. static double quality_mapping_44[12]={
  128227. -.1,.0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1.0
  128228. };
  128229. static int blocksize_short_44[11]={
  128230. 512,256,256,256,256,256,256,256,256,256,256
  128231. };
  128232. static int blocksize_long_44[11]={
  128233. 4096,2048,2048,2048,2048,2048,2048,2048,2048,2048,2048
  128234. };
  128235. static double _psy_compand_short_mapping[12]={
  128236. 0.5, 1., 1., 1.3, 1.6, 2., 2., 2., 2., 2., 2., 2.
  128237. };
  128238. static double _psy_compand_long_mapping[12]={
  128239. 3.5, 4., 4., 4.3, 4.6, 5., 5., 5., 5., 5., 5., 5.
  128240. };
  128241. static double _global_mapping_44[12]={
  128242. 0., 1., 1., 1.5, 2., 2., 2.5, 2.7, 3.0, 3.7, 4., 4.
  128243. };
  128244. static int _floor_short_mapping_44[11]={
  128245. 1,0,0,2,2,4,5,5,5,5,5
  128246. };
  128247. static int _floor_long_mapping_44[11]={
  128248. 8,7,7,7,7,7,7,7,7,7,7
  128249. };
  128250. ve_setup_data_template ve_setup_44_stereo={
  128251. 11,
  128252. rate_mapping_44_stereo,
  128253. quality_mapping_44,
  128254. 2,
  128255. 40000,
  128256. 50000,
  128257. blocksize_short_44,
  128258. blocksize_long_44,
  128259. _psy_tone_masteratt_44,
  128260. _psy_tone_0dB,
  128261. _psy_tone_suppress,
  128262. _vp_tonemask_adj_otherblock,
  128263. _vp_tonemask_adj_longblock,
  128264. _vp_tonemask_adj_otherblock,
  128265. _psy_noiseguards_44,
  128266. _psy_noisebias_impulse,
  128267. _psy_noisebias_padding,
  128268. _psy_noisebias_trans,
  128269. _psy_noisebias_long,
  128270. _psy_noise_suppress,
  128271. _psy_compand_44,
  128272. _psy_compand_short_mapping,
  128273. _psy_compand_long_mapping,
  128274. {_noise_start_short_44,_noise_start_long_44},
  128275. {_noise_part_short_44,_noise_part_long_44},
  128276. _noise_thresh_44,
  128277. _psy_ath_floater,
  128278. _psy_ath_abs,
  128279. _psy_lowpass_44,
  128280. _psy_global_44,
  128281. _global_mapping_44,
  128282. _psy_stereo_modes_44,
  128283. _floor_books,
  128284. _floor,
  128285. _floor_short_mapping_44,
  128286. _floor_long_mapping_44,
  128287. _mapres_template_44_stereo
  128288. };
  128289. /*** End of inlined file: setup_44.h ***/
  128290. /*** Start of inlined file: setup_44u.h ***/
  128291. /*** Start of inlined file: residue_44u.h ***/
  128292. /*** Start of inlined file: res_books_uncoupled.h ***/
  128293. static long _vq_quantlist__16u0__p1_0[] = {
  128294. 1,
  128295. 0,
  128296. 2,
  128297. };
  128298. static long _vq_lengthlist__16u0__p1_0[] = {
  128299. 1, 4, 4, 5, 7, 7, 5, 7, 8, 5, 8, 8, 8,10,10, 8,
  128300. 10,11, 5, 8, 8, 8,10,10, 8,10,10, 4, 9, 9, 9,12,
  128301. 11, 8,11,11, 8,12,11,10,12,14,10,13,13, 7,11,11,
  128302. 10,14,12,11,14,14, 4, 9, 9, 8,11,11, 9,11,12, 7,
  128303. 11,11,10,13,14,10,12,14, 8,11,12,10,14,14,10,13,
  128304. 12,
  128305. };
  128306. static float _vq_quantthresh__16u0__p1_0[] = {
  128307. -0.5, 0.5,
  128308. };
  128309. static long _vq_quantmap__16u0__p1_0[] = {
  128310. 1, 0, 2,
  128311. };
  128312. static encode_aux_threshmatch _vq_auxt__16u0__p1_0 = {
  128313. _vq_quantthresh__16u0__p1_0,
  128314. _vq_quantmap__16u0__p1_0,
  128315. 3,
  128316. 3
  128317. };
  128318. static static_codebook _16u0__p1_0 = {
  128319. 4, 81,
  128320. _vq_lengthlist__16u0__p1_0,
  128321. 1, -535822336, 1611661312, 2, 0,
  128322. _vq_quantlist__16u0__p1_0,
  128323. NULL,
  128324. &_vq_auxt__16u0__p1_0,
  128325. NULL,
  128326. 0
  128327. };
  128328. static long _vq_quantlist__16u0__p2_0[] = {
  128329. 1,
  128330. 0,
  128331. 2,
  128332. };
  128333. static long _vq_lengthlist__16u0__p2_0[] = {
  128334. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 9, 7,
  128335. 8, 9, 5, 7, 7, 7, 9, 8, 7, 9, 7, 4, 7, 7, 7, 9,
  128336. 9, 7, 8, 8, 6, 9, 8, 7, 8,11, 9,11,10, 6, 8, 9,
  128337. 8,11, 8, 9,10,11, 4, 7, 7, 7, 8, 8, 7, 9, 9, 6,
  128338. 9, 8, 9,11,10, 8, 8,11, 6, 8, 9, 9,10,11, 8,11,
  128339. 8,
  128340. };
  128341. static float _vq_quantthresh__16u0__p2_0[] = {
  128342. -0.5, 0.5,
  128343. };
  128344. static long _vq_quantmap__16u0__p2_0[] = {
  128345. 1, 0, 2,
  128346. };
  128347. static encode_aux_threshmatch _vq_auxt__16u0__p2_0 = {
  128348. _vq_quantthresh__16u0__p2_0,
  128349. _vq_quantmap__16u0__p2_0,
  128350. 3,
  128351. 3
  128352. };
  128353. static static_codebook _16u0__p2_0 = {
  128354. 4, 81,
  128355. _vq_lengthlist__16u0__p2_0,
  128356. 1, -535822336, 1611661312, 2, 0,
  128357. _vq_quantlist__16u0__p2_0,
  128358. NULL,
  128359. &_vq_auxt__16u0__p2_0,
  128360. NULL,
  128361. 0
  128362. };
  128363. static long _vq_quantlist__16u0__p3_0[] = {
  128364. 2,
  128365. 1,
  128366. 3,
  128367. 0,
  128368. 4,
  128369. };
  128370. static long _vq_lengthlist__16u0__p3_0[] = {
  128371. 1, 5, 5, 7, 7, 6, 7, 7, 8, 8, 6, 7, 8, 8, 8, 8,
  128372. 9, 9,11,11, 8, 9, 9,11,11, 6, 9, 8,10,10, 8,10,
  128373. 10,11,11, 8,10,10,11,11,10,11,10,13,12, 9,11,10,
  128374. 13,13, 6, 8, 9,10,10, 8,10,10,11,11, 8,10,10,11,
  128375. 11, 9,10,11,13,12,10,10,11,12,12, 8,11,11,14,13,
  128376. 10,12,11,15,13, 9,12,11,15,14,12,14,13,16,14,12,
  128377. 13,13,17,14, 8,11,11,13,14, 9,11,12,14,15,10,11,
  128378. 12,13,15,11,13,13,14,16,12,13,14,14,16, 5, 9, 9,
  128379. 11,11, 9,11,11,12,12, 8,11,11,12,12,11,12,12,15,
  128380. 14,10,12,12,15,15, 8,11,11,13,12,10,12,12,13,13,
  128381. 10,12,12,14,13,12,12,13,14,15,11,13,13,17,16, 7,
  128382. 11,11,13,13,10,12,12,14,13,10,12,12,13,14,12,13,
  128383. 12,15,14,11,13,13,15,14, 9,12,12,16,15,11,13,13,
  128384. 17,16,10,13,13,16,16,13,14,15,15,16,13,15,14,19,
  128385. 17, 9,12,12,14,16,11,13,13,15,16,10,13,13,17,16,
  128386. 13,14,13,17,15,12,15,15,16,17, 5, 9, 9,11,11, 8,
  128387. 11,11,13,12, 9,11,11,12,12,10,12,12,14,15,11,12,
  128388. 12,14,14, 7,11,10,13,12,10,12,12,14,13,10,11,12,
  128389. 13,13,11,13,13,15,16,12,12,13,15,15, 7,11,11,13,
  128390. 13,10,13,13,14,14,10,12,12,13,13,11,13,13,16,15,
  128391. 12,13,13,15,14, 9,12,12,15,15,10,13,13,17,16,11,
  128392. 12,13,15,15,12,15,14,18,18,13,14,14,16,17, 9,12,
  128393. 12,15,16,10,13,13,15,16,11,13,13,15,16,13,15,15,
  128394. 17,17,13,15,14,16,15, 7,11,11,15,16,10,13,12,16,
  128395. 17,10,12,13,15,17,15,16,16,18,17,13,15,15,17,18,
  128396. 8,12,12,16,16,11,13,14,17,18,11,13,13,18,16,15,
  128397. 17,16,17,19,14,15,15,17,16, 8,12,12,16,15,11,14,
  128398. 13,18,17,11,13,14,18,17,15,16,16,18,17,13,16,16,
  128399. 18,18,11,15,14,18,17,13,14,15,18, 0,12,15,15, 0,
  128400. 17,17,16,17,17,18,14,16,18,18, 0,11,14,14,17, 0,
  128401. 12,15,14,17,19,12,15,14,18, 0,15,18,16, 0,17,14,
  128402. 18,16,18, 0, 7,11,11,16,15,10,12,12,18,16,10,13,
  128403. 13,16,15,13,15,14,17,17,14,16,16,19,18, 8,12,12,
  128404. 16,16,11,13,13,18,16,11,13,14,17,16,14,15,15,19,
  128405. 18,15,16,16, 0,19, 8,12,12,16,17,11,13,13,17,17,
  128406. 11,14,13,17,17,13,15,15,17,19,15,17,17,19, 0,11,
  128407. 14,15,19,17,12,15,16,18,18,12,14,15,19,17,14,16,
  128408. 17, 0,18,16,16,19,17, 0,11,14,14,18,19,12,15,14,
  128409. 17,17,13,16,14,17,16,14,17,16,18,18,15,18,15, 0,
  128410. 18,
  128411. };
  128412. static float _vq_quantthresh__16u0__p3_0[] = {
  128413. -1.5, -0.5, 0.5, 1.5,
  128414. };
  128415. static long _vq_quantmap__16u0__p3_0[] = {
  128416. 3, 1, 0, 2, 4,
  128417. };
  128418. static encode_aux_threshmatch _vq_auxt__16u0__p3_0 = {
  128419. _vq_quantthresh__16u0__p3_0,
  128420. _vq_quantmap__16u0__p3_0,
  128421. 5,
  128422. 5
  128423. };
  128424. static static_codebook _16u0__p3_0 = {
  128425. 4, 625,
  128426. _vq_lengthlist__16u0__p3_0,
  128427. 1, -533725184, 1611661312, 3, 0,
  128428. _vq_quantlist__16u0__p3_0,
  128429. NULL,
  128430. &_vq_auxt__16u0__p3_0,
  128431. NULL,
  128432. 0
  128433. };
  128434. static long _vq_quantlist__16u0__p4_0[] = {
  128435. 2,
  128436. 1,
  128437. 3,
  128438. 0,
  128439. 4,
  128440. };
  128441. static long _vq_lengthlist__16u0__p4_0[] = {
  128442. 3, 5, 5, 8, 8, 6, 6, 6, 9, 9, 6, 6, 6, 9, 9, 9,
  128443. 10, 9,11,11, 9, 9, 9,11,11, 6, 7, 7,10,10, 7, 7,
  128444. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  128445. 11,12, 6, 7, 7,10,10, 7, 8, 7,10,10, 7, 8, 7,10,
  128446. 10,10,11,10,12,11,10,10,10,13,10, 9,10,10,12,12,
  128447. 10,11,10,14,12, 9,11,11,13,13,11,12,13,13,13,11,
  128448. 12,12,15,13, 9,10,10,12,13, 9,11,10,12,13,10,10,
  128449. 11,12,13,11,12,12,12,13,11,12,12,13,13, 5, 7, 7,
  128450. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  128451. 13,10,10,11,12,12, 6, 8, 8,11,10, 7, 8, 9,10,12,
  128452. 8, 9, 9,11,11,11,10,11,11,12,10,11,11,13,12, 7,
  128453. 8, 8,10,11, 8, 9, 8,11,10, 8, 9, 9,11,11,10,12,
  128454. 10,13,11,10,11,11,13,13,10,11,10,14,13,10,10,11,
  128455. 13,13,10,12,11,14,13,12,11,13,12,13,13,12,13,14,
  128456. 14,10,11,11,13,13,10,11,10,12,13,10,12,12,12,14,
  128457. 12,12,12,14,12,12,13,12,17,15, 5, 7, 7,10,10, 7,
  128458. 8, 8,10,10, 7, 8, 8,11,10,10,10,11,12,12,10,11,
  128459. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  128460. 10,11,11,11,11,12,12,10,10,11,12,13, 6, 8, 8,10,
  128461. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,12,12,13,13,
  128462. 11,11,10,13,11, 9,11,10,14,13,11,11,11,15,13,10,
  128463. 10,11,13,13,12,13,13,14,14,12,11,12,12,13,10,11,
  128464. 11,12,13,10,11,12,13,13,10,11,10,13,12,12,12,13,
  128465. 14, 0,12,13,11,13,11, 8,10,10,13,13,10,11,11,14,
  128466. 13,10,11,11,13,12,13,14,14,14,15,12,12,12,15,14,
  128467. 9,11,10,13,12,10,10,11,13,14,11,11,11,15,12,13,
  128468. 12,14,15,16,13,13,13,14,13, 9,11,11,12,12,10,12,
  128469. 11,13,13,10,11,11,13,14,13,13,13,15,15,13,13,14,
  128470. 17,15,11,12,12,14,14,10,11,12,13,15,12,13,13, 0,
  128471. 15,13,11,14,12,16,14,16,14, 0,15,11,12,12,14,16,
  128472. 11,13,12,16,15,12,13,13,14,15,12,14,12,15,13,15,
  128473. 14,14,16,16, 8,10,10,13,13,10,11,10,13,14,10,11,
  128474. 11,13,13,13,13,12,14,14,14,13,13,16,17, 9,10,10,
  128475. 12,14,10,12,11,14,13,10,11,12,13,14,12,12,12,15,
  128476. 15,13,13,13,14,14, 9,10,10,13,13,10,11,12,12,14,
  128477. 10,11,10,13,13,13,13,13,14,16,13,13,13,14,14,11,
  128478. 12,13,15,13,12,14,13,14,16,12,12,13,13,14,13,14,
  128479. 14,17,15,13,12,17,13,16,11,12,13,14,15,12,13,14,
  128480. 14,17,11,12,11,14,14,13,16,14,16, 0,14,15,11,15,
  128481. 11,
  128482. };
  128483. static float _vq_quantthresh__16u0__p4_0[] = {
  128484. -1.5, -0.5, 0.5, 1.5,
  128485. };
  128486. static long _vq_quantmap__16u0__p4_0[] = {
  128487. 3, 1, 0, 2, 4,
  128488. };
  128489. static encode_aux_threshmatch _vq_auxt__16u0__p4_0 = {
  128490. _vq_quantthresh__16u0__p4_0,
  128491. _vq_quantmap__16u0__p4_0,
  128492. 5,
  128493. 5
  128494. };
  128495. static static_codebook _16u0__p4_0 = {
  128496. 4, 625,
  128497. _vq_lengthlist__16u0__p4_0,
  128498. 1, -533725184, 1611661312, 3, 0,
  128499. _vq_quantlist__16u0__p4_0,
  128500. NULL,
  128501. &_vq_auxt__16u0__p4_0,
  128502. NULL,
  128503. 0
  128504. };
  128505. static long _vq_quantlist__16u0__p5_0[] = {
  128506. 4,
  128507. 3,
  128508. 5,
  128509. 2,
  128510. 6,
  128511. 1,
  128512. 7,
  128513. 0,
  128514. 8,
  128515. };
  128516. static long _vq_lengthlist__16u0__p5_0[] = {
  128517. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  128518. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  128519. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 7, 8, 8,
  128520. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  128521. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,10,11,11,12,
  128522. 12,
  128523. };
  128524. static float _vq_quantthresh__16u0__p5_0[] = {
  128525. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  128526. };
  128527. static long _vq_quantmap__16u0__p5_0[] = {
  128528. 7, 5, 3, 1, 0, 2, 4, 6,
  128529. 8,
  128530. };
  128531. static encode_aux_threshmatch _vq_auxt__16u0__p5_0 = {
  128532. _vq_quantthresh__16u0__p5_0,
  128533. _vq_quantmap__16u0__p5_0,
  128534. 9,
  128535. 9
  128536. };
  128537. static static_codebook _16u0__p5_0 = {
  128538. 2, 81,
  128539. _vq_lengthlist__16u0__p5_0,
  128540. 1, -531628032, 1611661312, 4, 0,
  128541. _vq_quantlist__16u0__p5_0,
  128542. NULL,
  128543. &_vq_auxt__16u0__p5_0,
  128544. NULL,
  128545. 0
  128546. };
  128547. static long _vq_quantlist__16u0__p6_0[] = {
  128548. 6,
  128549. 5,
  128550. 7,
  128551. 4,
  128552. 8,
  128553. 3,
  128554. 9,
  128555. 2,
  128556. 10,
  128557. 1,
  128558. 11,
  128559. 0,
  128560. 12,
  128561. };
  128562. static long _vq_lengthlist__16u0__p6_0[] = {
  128563. 1, 4, 4, 7, 7,10,10,12,12,13,13,18,17, 3, 6, 6,
  128564. 9, 9,11,11,13,13,14,14,18,17, 3, 6, 6, 9, 9,11,
  128565. 11,13,13,14,14,17,18, 7, 9, 9,11,11,13,13,14,14,
  128566. 15,15, 0, 0, 7, 9, 9,11,11,13,13,14,14,15,16,19,
  128567. 18,10,11,11,13,13,14,14,16,15,17,18, 0, 0,10,11,
  128568. 11,13,13,14,14,15,15,16,18, 0, 0,11,13,13,14,14,
  128569. 15,15,17,17, 0,19, 0, 0,11,13,13,14,14,14,15,16,
  128570. 18, 0,19, 0, 0,13,14,14,15,15,18,17,18,18, 0,19,
  128571. 0, 0,13,14,14,15,16,16,16,18,18,19, 0, 0, 0,16,
  128572. 17,17, 0,17,19,19, 0,19, 0, 0, 0, 0,16,19,16,17,
  128573. 18, 0,19, 0, 0, 0, 0, 0, 0,
  128574. };
  128575. static float _vq_quantthresh__16u0__p6_0[] = {
  128576. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  128577. 12.5, 17.5, 22.5, 27.5,
  128578. };
  128579. static long _vq_quantmap__16u0__p6_0[] = {
  128580. 11, 9, 7, 5, 3, 1, 0, 2,
  128581. 4, 6, 8, 10, 12,
  128582. };
  128583. static encode_aux_threshmatch _vq_auxt__16u0__p6_0 = {
  128584. _vq_quantthresh__16u0__p6_0,
  128585. _vq_quantmap__16u0__p6_0,
  128586. 13,
  128587. 13
  128588. };
  128589. static static_codebook _16u0__p6_0 = {
  128590. 2, 169,
  128591. _vq_lengthlist__16u0__p6_0,
  128592. 1, -526516224, 1616117760, 4, 0,
  128593. _vq_quantlist__16u0__p6_0,
  128594. NULL,
  128595. &_vq_auxt__16u0__p6_0,
  128596. NULL,
  128597. 0
  128598. };
  128599. static long _vq_quantlist__16u0__p6_1[] = {
  128600. 2,
  128601. 1,
  128602. 3,
  128603. 0,
  128604. 4,
  128605. };
  128606. static long _vq_lengthlist__16u0__p6_1[] = {
  128607. 1, 4, 5, 6, 6, 4, 6, 6, 6, 6, 4, 6, 6, 6, 6, 6,
  128608. 6, 6, 7, 7, 6, 6, 6, 7, 7,
  128609. };
  128610. static float _vq_quantthresh__16u0__p6_1[] = {
  128611. -1.5, -0.5, 0.5, 1.5,
  128612. };
  128613. static long _vq_quantmap__16u0__p6_1[] = {
  128614. 3, 1, 0, 2, 4,
  128615. };
  128616. static encode_aux_threshmatch _vq_auxt__16u0__p6_1 = {
  128617. _vq_quantthresh__16u0__p6_1,
  128618. _vq_quantmap__16u0__p6_1,
  128619. 5,
  128620. 5
  128621. };
  128622. static static_codebook _16u0__p6_1 = {
  128623. 2, 25,
  128624. _vq_lengthlist__16u0__p6_1,
  128625. 1, -533725184, 1611661312, 3, 0,
  128626. _vq_quantlist__16u0__p6_1,
  128627. NULL,
  128628. &_vq_auxt__16u0__p6_1,
  128629. NULL,
  128630. 0
  128631. };
  128632. static long _vq_quantlist__16u0__p7_0[] = {
  128633. 1,
  128634. 0,
  128635. 2,
  128636. };
  128637. static long _vq_lengthlist__16u0__p7_0[] = {
  128638. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  128639. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  128640. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128641. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128642. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128643. 7,
  128644. };
  128645. static float _vq_quantthresh__16u0__p7_0[] = {
  128646. -157.5, 157.5,
  128647. };
  128648. static long _vq_quantmap__16u0__p7_0[] = {
  128649. 1, 0, 2,
  128650. };
  128651. static encode_aux_threshmatch _vq_auxt__16u0__p7_0 = {
  128652. _vq_quantthresh__16u0__p7_0,
  128653. _vq_quantmap__16u0__p7_0,
  128654. 3,
  128655. 3
  128656. };
  128657. static static_codebook _16u0__p7_0 = {
  128658. 4, 81,
  128659. _vq_lengthlist__16u0__p7_0,
  128660. 1, -518803456, 1628680192, 2, 0,
  128661. _vq_quantlist__16u0__p7_0,
  128662. NULL,
  128663. &_vq_auxt__16u0__p7_0,
  128664. NULL,
  128665. 0
  128666. };
  128667. static long _vq_quantlist__16u0__p7_1[] = {
  128668. 7,
  128669. 6,
  128670. 8,
  128671. 5,
  128672. 9,
  128673. 4,
  128674. 10,
  128675. 3,
  128676. 11,
  128677. 2,
  128678. 12,
  128679. 1,
  128680. 13,
  128681. 0,
  128682. 14,
  128683. };
  128684. static long _vq_lengthlist__16u0__p7_1[] = {
  128685. 1, 5, 5, 6, 5, 9,10,11,11,10,10,10,10,10,10, 5,
  128686. 8, 8, 8,10,10,10,10,10,10,10,10,10,10,10, 5, 8,
  128687. 9, 9, 9,10,10,10,10,10,10,10,10,10,10, 5,10, 8,
  128688. 10,10,10,10,10,10,10,10,10,10,10,10, 4, 8, 9,10,
  128689. 10,10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,
  128690. 10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,
  128691. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128692. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128693. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128694. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128695. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128696. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128697. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128698. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128699. 10,
  128700. };
  128701. static float _vq_quantthresh__16u0__p7_1[] = {
  128702. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  128703. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  128704. };
  128705. static long _vq_quantmap__16u0__p7_1[] = {
  128706. 13, 11, 9, 7, 5, 3, 1, 0,
  128707. 2, 4, 6, 8, 10, 12, 14,
  128708. };
  128709. static encode_aux_threshmatch _vq_auxt__16u0__p7_1 = {
  128710. _vq_quantthresh__16u0__p7_1,
  128711. _vq_quantmap__16u0__p7_1,
  128712. 15,
  128713. 15
  128714. };
  128715. static static_codebook _16u0__p7_1 = {
  128716. 2, 225,
  128717. _vq_lengthlist__16u0__p7_1,
  128718. 1, -520986624, 1620377600, 4, 0,
  128719. _vq_quantlist__16u0__p7_1,
  128720. NULL,
  128721. &_vq_auxt__16u0__p7_1,
  128722. NULL,
  128723. 0
  128724. };
  128725. static long _vq_quantlist__16u0__p7_2[] = {
  128726. 10,
  128727. 9,
  128728. 11,
  128729. 8,
  128730. 12,
  128731. 7,
  128732. 13,
  128733. 6,
  128734. 14,
  128735. 5,
  128736. 15,
  128737. 4,
  128738. 16,
  128739. 3,
  128740. 17,
  128741. 2,
  128742. 18,
  128743. 1,
  128744. 19,
  128745. 0,
  128746. 20,
  128747. };
  128748. static long _vq_lengthlist__16u0__p7_2[] = {
  128749. 1, 6, 6, 7, 8, 7, 7,10, 9,10, 9,11,10, 9,11,10,
  128750. 9, 9, 9, 9,10, 6, 8, 7, 9, 9, 8, 8,10,10, 9,11,
  128751. 11,12,12,10, 9,11, 9,12,10, 9, 6, 9, 8, 9,12, 8,
  128752. 8,11, 9,11,11,12,11,12,12,10,11,11,10,10,11, 7,
  128753. 10, 9, 9, 9, 9, 9,10, 9,10, 9,10,10,12,10,10,10,
  128754. 11,12,10,10, 7, 9, 9, 9,10, 9, 9,10,10, 9, 9, 9,
  128755. 11,11,10,10,10,10, 9, 9,12, 7, 9,10, 9,11, 9,10,
  128756. 9,10,11,11,11,10,11,12, 9,12,11,10,10,10, 7, 9,
  128757. 9, 9, 9,10,12,10, 9,11,12,10,11,12,12,11, 9,10,
  128758. 11,10,11, 7, 9,10,10,11,10, 9,10,11,11,11,10,12,
  128759. 12,12,11,11,10,11,11,12, 8, 9,10,12,11,10,10,12,
  128760. 12,12,12,12,10,11,11, 9,11,10,12,11,11, 8, 9,10,
  128761. 10,11,12,11,11,10,10,10,12,12,12, 9,10,12,12,12,
  128762. 12,12, 8,10,11,10,10,12, 9,11,12,12,11,12,12,12,
  128763. 12,10,12,10,10,10,10, 8,12,11,11,11,10,10,11,12,
  128764. 12,12,12,11,12,12,12,11,11,11,12,10, 9,10,10,12,
  128765. 10,12,10,12,12,10,10,10,11,12,12,12,11,12,12,12,
  128766. 11,10,11,12,12,12,11,12,12,11,12,12,11,12,12,12,
  128767. 12,11,12,12,10,10,10,10,11,11,12,11,12,12,12,12,
  128768. 12,12,12,11,12,11,10,11,11,12,11,11, 9,10,10,10,
  128769. 12,10,10,11, 9,11,12,11,12,11,12,12,10,11,10,12,
  128770. 9, 9, 9,12,11,10,11,10,12,10,12,10,12,12,12,11,
  128771. 11,11,11,11,10, 9,10,10,11,10,11,11,12,11,10,11,
  128772. 12,12,12,11,11, 9,12,10,12, 9,10,12,10,10,11,10,
  128773. 11,11,12,11,10,11,10,11,11,11,11,12,11,11,10, 9,
  128774. 10,10,10, 9,11,11,10, 9,12,10,11,12,11,12,12,11,
  128775. 12,11,12,11,10,11,10,12,11,12,11,12,11,12,10,11,
  128776. 10,10,12,11,10,11,11,11,10,
  128777. };
  128778. static float _vq_quantthresh__16u0__p7_2[] = {
  128779. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  128780. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  128781. 6.5, 7.5, 8.5, 9.5,
  128782. };
  128783. static long _vq_quantmap__16u0__p7_2[] = {
  128784. 19, 17, 15, 13, 11, 9, 7, 5,
  128785. 3, 1, 0, 2, 4, 6, 8, 10,
  128786. 12, 14, 16, 18, 20,
  128787. };
  128788. static encode_aux_threshmatch _vq_auxt__16u0__p7_2 = {
  128789. _vq_quantthresh__16u0__p7_2,
  128790. _vq_quantmap__16u0__p7_2,
  128791. 21,
  128792. 21
  128793. };
  128794. static static_codebook _16u0__p7_2 = {
  128795. 2, 441,
  128796. _vq_lengthlist__16u0__p7_2,
  128797. 1, -529268736, 1611661312, 5, 0,
  128798. _vq_quantlist__16u0__p7_2,
  128799. NULL,
  128800. &_vq_auxt__16u0__p7_2,
  128801. NULL,
  128802. 0
  128803. };
  128804. static long _huff_lengthlist__16u0__single[] = {
  128805. 3, 5, 8, 7,14, 8, 9,19, 5, 2, 5, 5, 9, 6, 9,19,
  128806. 8, 4, 5, 7, 8, 9,13,19, 7, 4, 6, 5, 9, 6, 9,19,
  128807. 12, 8, 7, 9,10,11,13,19, 8, 5, 8, 6, 9, 6, 7,19,
  128808. 8, 8,10, 7, 7, 4, 5,19,12,17,19,15,18,13,11,18,
  128809. };
  128810. static static_codebook _huff_book__16u0__single = {
  128811. 2, 64,
  128812. _huff_lengthlist__16u0__single,
  128813. 0, 0, 0, 0, 0,
  128814. NULL,
  128815. NULL,
  128816. NULL,
  128817. NULL,
  128818. 0
  128819. };
  128820. static long _huff_lengthlist__16u1__long[] = {
  128821. 3, 6,10, 8,12, 8,14, 8,14,19, 5, 3, 5, 5, 7, 6,
  128822. 11, 7,16,19, 7, 5, 6, 7, 7, 9,11,12,19,19, 6, 4,
  128823. 7, 5, 7, 6,10, 7,18,18, 8, 6, 7, 7, 7, 7, 8, 9,
  128824. 18,18, 7, 5, 8, 5, 7, 5, 8, 6,18,18,12, 9,10, 9,
  128825. 9, 9, 8, 9,18,18, 8, 7,10, 6, 8, 5, 6, 4,11,18,
  128826. 11,15,16,12,11, 8, 8, 6, 9,18,14,18,18,18,16,16,
  128827. 16,13,16,18,
  128828. };
  128829. static static_codebook _huff_book__16u1__long = {
  128830. 2, 100,
  128831. _huff_lengthlist__16u1__long,
  128832. 0, 0, 0, 0, 0,
  128833. NULL,
  128834. NULL,
  128835. NULL,
  128836. NULL,
  128837. 0
  128838. };
  128839. static long _vq_quantlist__16u1__p1_0[] = {
  128840. 1,
  128841. 0,
  128842. 2,
  128843. };
  128844. static long _vq_lengthlist__16u1__p1_0[] = {
  128845. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 7, 7,10,10, 7,
  128846. 9,10, 5, 7, 8, 7,10, 9, 7,10,10, 5, 8, 8, 8,10,
  128847. 10, 8,10,10, 7,10,10,10,11,12,10,12,13, 7,10,10,
  128848. 9,13,11,10,12,13, 5, 8, 8, 8,10,10, 8,10,10, 7,
  128849. 10,10,10,12,12, 9,11,12, 7,10,11,10,12,12,10,13,
  128850. 11,
  128851. };
  128852. static float _vq_quantthresh__16u1__p1_0[] = {
  128853. -0.5, 0.5,
  128854. };
  128855. static long _vq_quantmap__16u1__p1_0[] = {
  128856. 1, 0, 2,
  128857. };
  128858. static encode_aux_threshmatch _vq_auxt__16u1__p1_0 = {
  128859. _vq_quantthresh__16u1__p1_0,
  128860. _vq_quantmap__16u1__p1_0,
  128861. 3,
  128862. 3
  128863. };
  128864. static static_codebook _16u1__p1_0 = {
  128865. 4, 81,
  128866. _vq_lengthlist__16u1__p1_0,
  128867. 1, -535822336, 1611661312, 2, 0,
  128868. _vq_quantlist__16u1__p1_0,
  128869. NULL,
  128870. &_vq_auxt__16u1__p1_0,
  128871. NULL,
  128872. 0
  128873. };
  128874. static long _vq_quantlist__16u1__p2_0[] = {
  128875. 1,
  128876. 0,
  128877. 2,
  128878. };
  128879. static long _vq_lengthlist__16u1__p2_0[] = {
  128880. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 7, 8, 6,
  128881. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 6, 8,
  128882. 8, 6, 8, 8, 6, 8, 8, 7, 7,10, 8, 9, 9, 6, 8, 8,
  128883. 7, 9, 8, 8, 9,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  128884. 8, 8, 8,10, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 7,10,
  128885. 8,
  128886. };
  128887. static float _vq_quantthresh__16u1__p2_0[] = {
  128888. -0.5, 0.5,
  128889. };
  128890. static long _vq_quantmap__16u1__p2_0[] = {
  128891. 1, 0, 2,
  128892. };
  128893. static encode_aux_threshmatch _vq_auxt__16u1__p2_0 = {
  128894. _vq_quantthresh__16u1__p2_0,
  128895. _vq_quantmap__16u1__p2_0,
  128896. 3,
  128897. 3
  128898. };
  128899. static static_codebook _16u1__p2_0 = {
  128900. 4, 81,
  128901. _vq_lengthlist__16u1__p2_0,
  128902. 1, -535822336, 1611661312, 2, 0,
  128903. _vq_quantlist__16u1__p2_0,
  128904. NULL,
  128905. &_vq_auxt__16u1__p2_0,
  128906. NULL,
  128907. 0
  128908. };
  128909. static long _vq_quantlist__16u1__p3_0[] = {
  128910. 2,
  128911. 1,
  128912. 3,
  128913. 0,
  128914. 4,
  128915. };
  128916. static long _vq_lengthlist__16u1__p3_0[] = {
  128917. 1, 5, 5, 8, 8, 6, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  128918. 10, 9,11,11, 9, 9,10,11,11, 6, 8, 8,10,10, 8, 9,
  128919. 10,11,11, 8, 9,10,11,11,10,11,11,12,13,10,11,11,
  128920. 13,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  128921. 11,10,11,11,13,13,10,11,11,13,12, 9,11,11,14,13,
  128922. 10,12,12,15,14,10,12,11,14,13,12,13,13,15,15,12,
  128923. 13,13,16,14, 9,11,11,13,14,10,11,12,14,14,10,12,
  128924. 12,14,15,12,13,13,14,15,12,13,14,15,16, 5, 8, 8,
  128925. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  128926. 14,11,12,12,14,14, 8,10,10,12,12, 9,11,12,12,13,
  128927. 10,12,12,13,13,12,12,13,14,15,11,13,13,15,15, 7,
  128928. 10,10,12,12, 9,12,11,13,12,10,11,12,13,13,12,13,
  128929. 12,15,14,11,12,13,15,15,10,12,12,15,14,11,13,13,
  128930. 16,15,11,13,13,16,15,14,13,14,15,16,13,15,15,17,
  128931. 17,10,12,12,14,15,11,12,12,15,15,11,13,13,15,16,
  128932. 13,15,13,16,15,13,15,15,16,17, 5, 8, 8,11,11, 8,
  128933. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  128934. 12,14,14, 7,10,10,12,12,10,12,12,14,13, 9,11,12,
  128935. 12,13,12,13,13,15,15,12,12,13,13,15, 7,10,10,12,
  128936. 13,10,11,12,13,13,10,12,11,13,13,11,13,13,15,15,
  128937. 12,13,12,15,14, 9,12,12,15,14,11,13,13,15,15,11,
  128938. 12,13,15,15,13,14,14,17,19,13,13,14,16,16,10,12,
  128939. 12,14,15,11,13,13,15,16,11,13,12,16,15,13,15,15,
  128940. 17,18,14,15,13,16,15, 8,11,11,15,14,10,12,12,16,
  128941. 15,10,12,12,16,16,14,15,15,18,17,13,14,15,16,18,
  128942. 9,12,12,15,15,11,12,14,16,17,11,13,13,16,15,15,
  128943. 15,15,17,18,14,15,16,17,17, 9,12,12,15,15,11,14,
  128944. 13,16,16,11,13,13,16,16,15,16,15,17,18,14,16,15,
  128945. 17,16,12,14,14,17,16,12,14,15,18,17,13,15,15,17,
  128946. 17,15,15,18,16,20,15,16,17,18,18,11,14,14,16,17,
  128947. 13,15,14,18,17,13,15,15,17,17,15,17,15,18,17,15,
  128948. 17,16,19,18, 8,11,11,14,15,10,12,12,15,15,10,12,
  128949. 12,16,16,13,14,14,17,16,14,15,15,17,17, 9,12,12,
  128950. 15,16,11,13,13,16,16,11,12,13,16,16,14,16,15,20,
  128951. 17,14,16,16,17,17, 9,12,12,15,16,11,13,13,16,17,
  128952. 11,13,13,17,16,14,15,15,17,18,15,15,15,18,18,11,
  128953. 14,14,17,16,13,15,15,17,17,13,14,14,18,17,15,16,
  128954. 16,18,19,15,15,17,17,19,11,14,14,16,17,13,15,14,
  128955. 17,19,13,15,14,18,17,15,17,16,18,18,15,17,15,18,
  128956. 16,
  128957. };
  128958. static float _vq_quantthresh__16u1__p3_0[] = {
  128959. -1.5, -0.5, 0.5, 1.5,
  128960. };
  128961. static long _vq_quantmap__16u1__p3_0[] = {
  128962. 3, 1, 0, 2, 4,
  128963. };
  128964. static encode_aux_threshmatch _vq_auxt__16u1__p3_0 = {
  128965. _vq_quantthresh__16u1__p3_0,
  128966. _vq_quantmap__16u1__p3_0,
  128967. 5,
  128968. 5
  128969. };
  128970. static static_codebook _16u1__p3_0 = {
  128971. 4, 625,
  128972. _vq_lengthlist__16u1__p3_0,
  128973. 1, -533725184, 1611661312, 3, 0,
  128974. _vq_quantlist__16u1__p3_0,
  128975. NULL,
  128976. &_vq_auxt__16u1__p3_0,
  128977. NULL,
  128978. 0
  128979. };
  128980. static long _vq_quantlist__16u1__p4_0[] = {
  128981. 2,
  128982. 1,
  128983. 3,
  128984. 0,
  128985. 4,
  128986. };
  128987. static long _vq_lengthlist__16u1__p4_0[] = {
  128988. 4, 5, 5, 8, 8, 6, 6, 7, 9, 9, 6, 6, 6, 9, 9, 9,
  128989. 10, 9,11,11, 9, 9,10,11,11, 6, 7, 7,10, 9, 7, 7,
  128990. 8, 9,10, 7, 7, 8,10,10,10,10,10,10,12, 9, 9,10,
  128991. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 7,10,
  128992. 10, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  128993. 10,10,10,12,12, 9,10,10,12,12,12,11,12,13,13,11,
  128994. 11,12,12,13, 9,10,10,11,12, 9,10,10,12,12,10,10,
  128995. 10,12,12,11,12,11,14,13,11,12,12,14,13, 5, 7, 7,
  128996. 10,10, 7, 8, 8,10,10, 7, 8, 7,10,10,10,10,10,12,
  128997. 12,10,10,10,12,12, 6, 8, 7,10,10, 7, 7, 9,10,11,
  128998. 8, 9, 9,11,10,10,10,11,11,13,10,10,11,12,13, 6,
  128999. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,10,11,10,11,
  129000. 10,13,11,10,11,10,12,12,10,11,10,12,11,10,10,10,
  129001. 12,13,10,11,11,13,12,11,11,13,11,14,12,12,13,14,
  129002. 14, 9,10,10,12,13,10,11,10,13,12,10,11,11,12,13,
  129003. 11,12,11,14,12,12,13,13,15,14, 5, 7, 7,10,10, 7,
  129004. 7, 8,10,10, 7, 8, 8,10,10,10,10,10,11,12,10,10,
  129005. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  129006. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 7, 8,10,
  129007. 10, 8, 8, 9,10,11, 7, 9, 7,11,10,10,11,11,13,12,
  129008. 11,11,10,13,11, 9,10,10,12,12,10,11,11,13,12,10,
  129009. 10,11,12,12,12,13,13,14,14,11,11,12,12,14,10,10,
  129010. 11,12,12,10,11,11,12,13,10,10,10,13,12,12,13,13,
  129011. 15,14,12,13,10,14,11, 8,10,10,12,12,10,11,10,13,
  129012. 13, 9,10,10,12,12,12,13,13,15,14,11,12,12,13,13,
  129013. 9,10,10,13,12,10,10,11,13,13,10,11,10,13,12,12,
  129014. 12,13,14,15,12,13,12,15,13, 9,10,10,12,13,10,11,
  129015. 10,13,12,10,10,11,12,13,12,14,12,15,13,12,12,13,
  129016. 14,15,11,12,11,14,13,11,11,12,14,15,12,13,12,15,
  129017. 14,13,11,15,11,16,13,14,14,16,15,11,12,12,14,14,
  129018. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,12,14,
  129019. 14,14,15,15, 8,10,10,12,12, 9,10,10,12,12,10,10,
  129020. 11,13,13,11,12,12,13,13,12,13,13,14,15, 9,10,10,
  129021. 13,12,10,11,11,13,12,10,10,11,13,13,12,13,12,15,
  129022. 14,12,12,13,13,16, 9, 9,10,12,13,10,10,11,12,13,
  129023. 10,11,10,13,13,12,12,13,13,15,13,13,12,15,13,11,
  129024. 12,12,14,14,12,13,12,15,14,11,11,12,13,14,14,14,
  129025. 14,16,15,13,12,15,12,16,11,11,12,13,14,12,13,13,
  129026. 14,15,10,12,11,14,13,14,15,14,16,16,13,14,11,15,
  129027. 11,
  129028. };
  129029. static float _vq_quantthresh__16u1__p4_0[] = {
  129030. -1.5, -0.5, 0.5, 1.5,
  129031. };
  129032. static long _vq_quantmap__16u1__p4_0[] = {
  129033. 3, 1, 0, 2, 4,
  129034. };
  129035. static encode_aux_threshmatch _vq_auxt__16u1__p4_0 = {
  129036. _vq_quantthresh__16u1__p4_0,
  129037. _vq_quantmap__16u1__p4_0,
  129038. 5,
  129039. 5
  129040. };
  129041. static static_codebook _16u1__p4_0 = {
  129042. 4, 625,
  129043. _vq_lengthlist__16u1__p4_0,
  129044. 1, -533725184, 1611661312, 3, 0,
  129045. _vq_quantlist__16u1__p4_0,
  129046. NULL,
  129047. &_vq_auxt__16u1__p4_0,
  129048. NULL,
  129049. 0
  129050. };
  129051. static long _vq_quantlist__16u1__p5_0[] = {
  129052. 4,
  129053. 3,
  129054. 5,
  129055. 2,
  129056. 6,
  129057. 1,
  129058. 7,
  129059. 0,
  129060. 8,
  129061. };
  129062. static long _vq_lengthlist__16u1__p5_0[] = {
  129063. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  129064. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  129065. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  129066. 10, 9,11,11,12,11, 7, 8, 8, 9, 9,11,11,12,12, 9,
  129067. 10,10,11,11,12,12,13,12, 9,10,10,11,11,12,12,12,
  129068. 13,
  129069. };
  129070. static float _vq_quantthresh__16u1__p5_0[] = {
  129071. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129072. };
  129073. static long _vq_quantmap__16u1__p5_0[] = {
  129074. 7, 5, 3, 1, 0, 2, 4, 6,
  129075. 8,
  129076. };
  129077. static encode_aux_threshmatch _vq_auxt__16u1__p5_0 = {
  129078. _vq_quantthresh__16u1__p5_0,
  129079. _vq_quantmap__16u1__p5_0,
  129080. 9,
  129081. 9
  129082. };
  129083. static static_codebook _16u1__p5_0 = {
  129084. 2, 81,
  129085. _vq_lengthlist__16u1__p5_0,
  129086. 1, -531628032, 1611661312, 4, 0,
  129087. _vq_quantlist__16u1__p5_0,
  129088. NULL,
  129089. &_vq_auxt__16u1__p5_0,
  129090. NULL,
  129091. 0
  129092. };
  129093. static long _vq_quantlist__16u1__p6_0[] = {
  129094. 4,
  129095. 3,
  129096. 5,
  129097. 2,
  129098. 6,
  129099. 1,
  129100. 7,
  129101. 0,
  129102. 8,
  129103. };
  129104. static long _vq_lengthlist__16u1__p6_0[] = {
  129105. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 4, 6, 6, 8, 8,
  129106. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  129107. 8, 8,10, 9, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  129108. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  129109. 9, 9,10,10,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  129110. 11,
  129111. };
  129112. static float _vq_quantthresh__16u1__p6_0[] = {
  129113. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129114. };
  129115. static long _vq_quantmap__16u1__p6_0[] = {
  129116. 7, 5, 3, 1, 0, 2, 4, 6,
  129117. 8,
  129118. };
  129119. static encode_aux_threshmatch _vq_auxt__16u1__p6_0 = {
  129120. _vq_quantthresh__16u1__p6_0,
  129121. _vq_quantmap__16u1__p6_0,
  129122. 9,
  129123. 9
  129124. };
  129125. static static_codebook _16u1__p6_0 = {
  129126. 2, 81,
  129127. _vq_lengthlist__16u1__p6_0,
  129128. 1, -531628032, 1611661312, 4, 0,
  129129. _vq_quantlist__16u1__p6_0,
  129130. NULL,
  129131. &_vq_auxt__16u1__p6_0,
  129132. NULL,
  129133. 0
  129134. };
  129135. static long _vq_quantlist__16u1__p7_0[] = {
  129136. 1,
  129137. 0,
  129138. 2,
  129139. };
  129140. static long _vq_lengthlist__16u1__p7_0[] = {
  129141. 1, 4, 4, 4, 8, 8, 4, 8, 8, 5,11, 9, 8,12,11, 8,
  129142. 12,11, 5,10,11, 8,11,12, 8,11,12, 4,11,11,11,14,
  129143. 13,10,13,13, 8,14,13,12,14,16,12,16,15, 8,14,14,
  129144. 13,16,14,12,15,16, 4,11,11,10,14,13,11,14,14, 8,
  129145. 15,14,12,15,15,12,14,16, 8,14,14,11,16,15,12,15,
  129146. 13,
  129147. };
  129148. static float _vq_quantthresh__16u1__p7_0[] = {
  129149. -5.5, 5.5,
  129150. };
  129151. static long _vq_quantmap__16u1__p7_0[] = {
  129152. 1, 0, 2,
  129153. };
  129154. static encode_aux_threshmatch _vq_auxt__16u1__p7_0 = {
  129155. _vq_quantthresh__16u1__p7_0,
  129156. _vq_quantmap__16u1__p7_0,
  129157. 3,
  129158. 3
  129159. };
  129160. static static_codebook _16u1__p7_0 = {
  129161. 4, 81,
  129162. _vq_lengthlist__16u1__p7_0,
  129163. 1, -529137664, 1618345984, 2, 0,
  129164. _vq_quantlist__16u1__p7_0,
  129165. NULL,
  129166. &_vq_auxt__16u1__p7_0,
  129167. NULL,
  129168. 0
  129169. };
  129170. static long _vq_quantlist__16u1__p7_1[] = {
  129171. 5,
  129172. 4,
  129173. 6,
  129174. 3,
  129175. 7,
  129176. 2,
  129177. 8,
  129178. 1,
  129179. 9,
  129180. 0,
  129181. 10,
  129182. };
  129183. static long _vq_lengthlist__16u1__p7_1[] = {
  129184. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 5, 7, 7,
  129185. 8, 8, 8, 8, 8, 8, 4, 5, 6, 7, 7, 8, 8, 8, 8, 8,
  129186. 8, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  129187. 8, 8, 8, 9, 9, 9, 9, 7, 8, 8, 8, 8, 9, 9, 9,10,
  129188. 9,10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10, 9, 8, 8, 8,
  129189. 9, 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,10,
  129190. 10,10,10, 8, 8, 8, 9, 9, 9,10,10,10,10,10, 8, 8,
  129191. 8, 9, 9,10,10,10,10,10,10,
  129192. };
  129193. static float _vq_quantthresh__16u1__p7_1[] = {
  129194. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129195. 3.5, 4.5,
  129196. };
  129197. static long _vq_quantmap__16u1__p7_1[] = {
  129198. 9, 7, 5, 3, 1, 0, 2, 4,
  129199. 6, 8, 10,
  129200. };
  129201. static encode_aux_threshmatch _vq_auxt__16u1__p7_1 = {
  129202. _vq_quantthresh__16u1__p7_1,
  129203. _vq_quantmap__16u1__p7_1,
  129204. 11,
  129205. 11
  129206. };
  129207. static static_codebook _16u1__p7_1 = {
  129208. 2, 121,
  129209. _vq_lengthlist__16u1__p7_1,
  129210. 1, -531365888, 1611661312, 4, 0,
  129211. _vq_quantlist__16u1__p7_1,
  129212. NULL,
  129213. &_vq_auxt__16u1__p7_1,
  129214. NULL,
  129215. 0
  129216. };
  129217. static long _vq_quantlist__16u1__p8_0[] = {
  129218. 5,
  129219. 4,
  129220. 6,
  129221. 3,
  129222. 7,
  129223. 2,
  129224. 8,
  129225. 1,
  129226. 9,
  129227. 0,
  129228. 10,
  129229. };
  129230. static long _vq_lengthlist__16u1__p8_0[] = {
  129231. 1, 4, 4, 5, 5, 8, 8,10,10,12,12, 4, 7, 7, 8, 8,
  129232. 9, 9,12,11,14,13, 4, 7, 7, 7, 8, 9,10,11,11,13,
  129233. 12, 5, 8, 8, 9, 9,11,11,12,13,15,14, 5, 7, 8, 9,
  129234. 9,11,11,13,13,17,15, 8, 9,10,11,11,12,13,17,14,
  129235. 17,16, 8,10, 9,11,11,12,12,13,15,15,17,10,11,11,
  129236. 12,13,14,15,15,16,16,17, 9,11,11,12,12,14,15,17,
  129237. 15,15,16,11,14,12,14,15,16,15,16,16,16,15,11,13,
  129238. 13,14,14,15,15,16,16,15,16,
  129239. };
  129240. static float _vq_quantthresh__16u1__p8_0[] = {
  129241. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  129242. 38.5, 49.5,
  129243. };
  129244. static long _vq_quantmap__16u1__p8_0[] = {
  129245. 9, 7, 5, 3, 1, 0, 2, 4,
  129246. 6, 8, 10,
  129247. };
  129248. static encode_aux_threshmatch _vq_auxt__16u1__p8_0 = {
  129249. _vq_quantthresh__16u1__p8_0,
  129250. _vq_quantmap__16u1__p8_0,
  129251. 11,
  129252. 11
  129253. };
  129254. static static_codebook _16u1__p8_0 = {
  129255. 2, 121,
  129256. _vq_lengthlist__16u1__p8_0,
  129257. 1, -524582912, 1618345984, 4, 0,
  129258. _vq_quantlist__16u1__p8_0,
  129259. NULL,
  129260. &_vq_auxt__16u1__p8_0,
  129261. NULL,
  129262. 0
  129263. };
  129264. static long _vq_quantlist__16u1__p8_1[] = {
  129265. 5,
  129266. 4,
  129267. 6,
  129268. 3,
  129269. 7,
  129270. 2,
  129271. 8,
  129272. 1,
  129273. 9,
  129274. 0,
  129275. 10,
  129276. };
  129277. static long _vq_lengthlist__16u1__p8_1[] = {
  129278. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7,
  129279. 8, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  129280. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 6, 7, 7, 7,
  129281. 7, 8, 8, 8, 8, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  129282. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  129283. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  129284. 9, 9, 9, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  129285. 8, 9, 9, 9, 9, 9, 9, 9, 9,
  129286. };
  129287. static float _vq_quantthresh__16u1__p8_1[] = {
  129288. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129289. 3.5, 4.5,
  129290. };
  129291. static long _vq_quantmap__16u1__p8_1[] = {
  129292. 9, 7, 5, 3, 1, 0, 2, 4,
  129293. 6, 8, 10,
  129294. };
  129295. static encode_aux_threshmatch _vq_auxt__16u1__p8_1 = {
  129296. _vq_quantthresh__16u1__p8_1,
  129297. _vq_quantmap__16u1__p8_1,
  129298. 11,
  129299. 11
  129300. };
  129301. static static_codebook _16u1__p8_1 = {
  129302. 2, 121,
  129303. _vq_lengthlist__16u1__p8_1,
  129304. 1, -531365888, 1611661312, 4, 0,
  129305. _vq_quantlist__16u1__p8_1,
  129306. NULL,
  129307. &_vq_auxt__16u1__p8_1,
  129308. NULL,
  129309. 0
  129310. };
  129311. static long _vq_quantlist__16u1__p9_0[] = {
  129312. 7,
  129313. 6,
  129314. 8,
  129315. 5,
  129316. 9,
  129317. 4,
  129318. 10,
  129319. 3,
  129320. 11,
  129321. 2,
  129322. 12,
  129323. 1,
  129324. 13,
  129325. 0,
  129326. 14,
  129327. };
  129328. static long _vq_lengthlist__16u1__p9_0[] = {
  129329. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129330. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129331. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129332. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129333. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129334. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129335. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129336. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129337. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129338. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129339. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129340. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129341. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129342. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129343. 8,
  129344. };
  129345. static float _vq_quantthresh__16u1__p9_0[] = {
  129346. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  129347. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  129348. };
  129349. static long _vq_quantmap__16u1__p9_0[] = {
  129350. 13, 11, 9, 7, 5, 3, 1, 0,
  129351. 2, 4, 6, 8, 10, 12, 14,
  129352. };
  129353. static encode_aux_threshmatch _vq_auxt__16u1__p9_0 = {
  129354. _vq_quantthresh__16u1__p9_0,
  129355. _vq_quantmap__16u1__p9_0,
  129356. 15,
  129357. 15
  129358. };
  129359. static static_codebook _16u1__p9_0 = {
  129360. 2, 225,
  129361. _vq_lengthlist__16u1__p9_0,
  129362. 1, -514071552, 1627381760, 4, 0,
  129363. _vq_quantlist__16u1__p9_0,
  129364. NULL,
  129365. &_vq_auxt__16u1__p9_0,
  129366. NULL,
  129367. 0
  129368. };
  129369. static long _vq_quantlist__16u1__p9_1[] = {
  129370. 7,
  129371. 6,
  129372. 8,
  129373. 5,
  129374. 9,
  129375. 4,
  129376. 10,
  129377. 3,
  129378. 11,
  129379. 2,
  129380. 12,
  129381. 1,
  129382. 13,
  129383. 0,
  129384. 14,
  129385. };
  129386. static long _vq_lengthlist__16u1__p9_1[] = {
  129387. 1, 6, 5, 9, 9,10,10, 6, 7, 9, 9,10,10,10,10, 5,
  129388. 10, 8,10, 8,10,10, 8, 8,10, 9,10,10,10,10, 5, 8,
  129389. 9,10,10,10,10, 8,10,10,10,10,10,10,10, 9,10,10,
  129390. 10,10,10,10, 9, 9,10,10,10,10,10,10, 9, 9, 8, 9,
  129391. 10,10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  129392. 10,10,10,10,10,10,10,10,10,10,10, 8,10,10,10,10,
  129393. 10,10,10,10,10,10,10,10,10, 6, 8, 8,10,10,10, 8,
  129394. 10,10,10,10,10,10,10,10, 5, 8, 8,10,10,10, 9, 9,
  129395. 10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,10,
  129396. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129397. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  129398. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129399. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129400. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129401. 9,
  129402. };
  129403. static float _vq_quantthresh__16u1__p9_1[] = {
  129404. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  129405. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  129406. };
  129407. static long _vq_quantmap__16u1__p9_1[] = {
  129408. 13, 11, 9, 7, 5, 3, 1, 0,
  129409. 2, 4, 6, 8, 10, 12, 14,
  129410. };
  129411. static encode_aux_threshmatch _vq_auxt__16u1__p9_1 = {
  129412. _vq_quantthresh__16u1__p9_1,
  129413. _vq_quantmap__16u1__p9_1,
  129414. 15,
  129415. 15
  129416. };
  129417. static static_codebook _16u1__p9_1 = {
  129418. 2, 225,
  129419. _vq_lengthlist__16u1__p9_1,
  129420. 1, -522338304, 1620115456, 4, 0,
  129421. _vq_quantlist__16u1__p9_1,
  129422. NULL,
  129423. &_vq_auxt__16u1__p9_1,
  129424. NULL,
  129425. 0
  129426. };
  129427. static long _vq_quantlist__16u1__p9_2[] = {
  129428. 8,
  129429. 7,
  129430. 9,
  129431. 6,
  129432. 10,
  129433. 5,
  129434. 11,
  129435. 4,
  129436. 12,
  129437. 3,
  129438. 13,
  129439. 2,
  129440. 14,
  129441. 1,
  129442. 15,
  129443. 0,
  129444. 16,
  129445. };
  129446. static long _vq_lengthlist__16u1__p9_2[] = {
  129447. 1, 6, 6, 7, 8, 8,11,10, 9, 9,11, 9,10, 9,11,11,
  129448. 9, 6, 7, 6,11, 8,11, 9,10,10,11, 9,11,10,10,10,
  129449. 11, 9, 5, 7, 7, 8, 8,10,11, 8, 8,11, 9, 9,10,11,
  129450. 9,10,11, 8, 9, 6, 8, 8, 9, 9,10,10,11,11,11, 9,
  129451. 11,10, 9,11, 8, 8, 8, 9, 8, 9,10,11, 9, 9,11,11,
  129452. 10, 9, 9,11,10, 8,11, 8, 9, 8,11, 9,10, 9,10,11,
  129453. 11,10,10, 9,10,10, 8, 8, 9,10,10,10, 9,11, 9,10,
  129454. 11,11,11,11,10, 9,11, 9, 9,11,11,10, 8,11,11,11,
  129455. 9,10,10,11,10,11,11, 9,11,10, 9,11,10,10,10,10,
  129456. 9,11,10,11,10, 9, 9,10,11, 9, 8,10,11,11,10,10,
  129457. 11, 9,11,10,11,11,10,11, 9, 9, 8,10, 8, 9,11, 9,
  129458. 8,10,10, 9,11,10,11,10,11, 9,11, 8,10,11,11,11,
  129459. 11,10,10,11,11,11,11,10,11,11,10, 9, 8,10,10, 9,
  129460. 11,10,11,11,11, 9, 9, 9,11,11,11,10,10, 9, 9,10,
  129461. 9,11,11,11,11, 8,10,11,10,11,11,10,11,11, 9, 9,
  129462. 9,10, 9,11, 9,11,11,11,11,11,10,11,11,10,11,10,
  129463. 11,11, 9,11,10,11,10, 9,10, 9,10,10,11,11,11,11,
  129464. 9,10, 9,10,11,11,10,11,11,11,11,11,11,10,11,11,
  129465. 10,
  129466. };
  129467. static float _vq_quantthresh__16u1__p9_2[] = {
  129468. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  129469. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  129470. };
  129471. static long _vq_quantmap__16u1__p9_2[] = {
  129472. 15, 13, 11, 9, 7, 5, 3, 1,
  129473. 0, 2, 4, 6, 8, 10, 12, 14,
  129474. 16,
  129475. };
  129476. static encode_aux_threshmatch _vq_auxt__16u1__p9_2 = {
  129477. _vq_quantthresh__16u1__p9_2,
  129478. _vq_quantmap__16u1__p9_2,
  129479. 17,
  129480. 17
  129481. };
  129482. static static_codebook _16u1__p9_2 = {
  129483. 2, 289,
  129484. _vq_lengthlist__16u1__p9_2,
  129485. 1, -529530880, 1611661312, 5, 0,
  129486. _vq_quantlist__16u1__p9_2,
  129487. NULL,
  129488. &_vq_auxt__16u1__p9_2,
  129489. NULL,
  129490. 0
  129491. };
  129492. static long _huff_lengthlist__16u1__short[] = {
  129493. 5, 7,10, 9,11,10,15,11,13,16, 6, 4, 6, 6, 7, 7,
  129494. 10, 9,12,16,10, 6, 5, 6, 6, 7,10,11,16,16, 9, 6,
  129495. 7, 6, 7, 7,10, 8,14,16,11, 6, 5, 4, 5, 6, 8, 9,
  129496. 15,16, 9, 6, 6, 5, 6, 6, 9, 8,14,16,12, 7, 6, 6,
  129497. 5, 6, 6, 7,13,16, 8, 6, 7, 6, 5, 5, 4, 4,11,16,
  129498. 9, 8, 9, 9, 7, 7, 6, 5,13,16,14,14,16,15,16,15,
  129499. 16,16,16,16,
  129500. };
  129501. static static_codebook _huff_book__16u1__short = {
  129502. 2, 100,
  129503. _huff_lengthlist__16u1__short,
  129504. 0, 0, 0, 0, 0,
  129505. NULL,
  129506. NULL,
  129507. NULL,
  129508. NULL,
  129509. 0
  129510. };
  129511. static long _huff_lengthlist__16u2__long[] = {
  129512. 5, 7,10,10,10,11,11,13,18,19, 6, 5, 5, 6, 7, 8,
  129513. 9,12,19,19, 8, 5, 4, 4, 6, 7, 9,13,19,19, 8, 5,
  129514. 4, 4, 5, 6, 8,12,17,19, 7, 5, 5, 4, 4, 5, 7,12,
  129515. 18,18, 8, 7, 7, 6, 5, 5, 6,10,18,18, 9, 9, 9, 8,
  129516. 6, 5, 6, 9,18,18,11,13,13,13, 8, 7, 7, 9,16,18,
  129517. 13,17,18,16,11, 9, 9, 9,17,18,15,18,18,18,15,13,
  129518. 13,14,18,18,
  129519. };
  129520. static static_codebook _huff_book__16u2__long = {
  129521. 2, 100,
  129522. _huff_lengthlist__16u2__long,
  129523. 0, 0, 0, 0, 0,
  129524. NULL,
  129525. NULL,
  129526. NULL,
  129527. NULL,
  129528. 0
  129529. };
  129530. static long _huff_lengthlist__16u2__short[] = {
  129531. 8,11,12,12,14,15,16,16,16,16, 9, 7, 7, 8, 9,11,
  129532. 13,14,16,16,13, 7, 6, 6, 7, 9,12,13,15,16,15, 7,
  129533. 6, 5, 4, 6,10,11,14,16,12, 8, 7, 4, 2, 4, 7,10,
  129534. 14,16,11, 9, 7, 5, 3, 4, 6, 9,14,16,11,10, 9, 7,
  129535. 5, 5, 6, 9,16,16,10,10, 9, 8, 6, 6, 7,10,16,16,
  129536. 11,11,11,10,10,10,11,14,16,16,16,14,14,13,14,16,
  129537. 16,16,16,16,
  129538. };
  129539. static static_codebook _huff_book__16u2__short = {
  129540. 2, 100,
  129541. _huff_lengthlist__16u2__short,
  129542. 0, 0, 0, 0, 0,
  129543. NULL,
  129544. NULL,
  129545. NULL,
  129546. NULL,
  129547. 0
  129548. };
  129549. static long _vq_quantlist__16u2_p1_0[] = {
  129550. 1,
  129551. 0,
  129552. 2,
  129553. };
  129554. static long _vq_lengthlist__16u2_p1_0[] = {
  129555. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  129556. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 8, 9,
  129557. 9, 7, 9, 9, 7, 9, 9, 9,10,10, 9,10,10, 7, 9, 9,
  129558. 9,10,10, 9,10,11, 5, 7, 8, 8, 9, 9, 8, 9, 9, 7,
  129559. 9, 9, 9,10,10, 9, 9,10, 7, 9, 9, 9,10,10, 9,11,
  129560. 10,
  129561. };
  129562. static float _vq_quantthresh__16u2_p1_0[] = {
  129563. -0.5, 0.5,
  129564. };
  129565. static long _vq_quantmap__16u2_p1_0[] = {
  129566. 1, 0, 2,
  129567. };
  129568. static encode_aux_threshmatch _vq_auxt__16u2_p1_0 = {
  129569. _vq_quantthresh__16u2_p1_0,
  129570. _vq_quantmap__16u2_p1_0,
  129571. 3,
  129572. 3
  129573. };
  129574. static static_codebook _16u2_p1_0 = {
  129575. 4, 81,
  129576. _vq_lengthlist__16u2_p1_0,
  129577. 1, -535822336, 1611661312, 2, 0,
  129578. _vq_quantlist__16u2_p1_0,
  129579. NULL,
  129580. &_vq_auxt__16u2_p1_0,
  129581. NULL,
  129582. 0
  129583. };
  129584. static long _vq_quantlist__16u2_p2_0[] = {
  129585. 2,
  129586. 1,
  129587. 3,
  129588. 0,
  129589. 4,
  129590. };
  129591. static long _vq_lengthlist__16u2_p2_0[] = {
  129592. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  129593. 10, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  129594. 8,10,10, 7, 8, 8,10,10,10,10,10,12,12, 9,10,10,
  129595. 11,12, 5, 7, 7, 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,
  129596. 10, 9,10,10,12,11,10,10,10,12,12, 9,10,10,12,12,
  129597. 10,11,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  129598. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,12,10,10,
  129599. 10,12,12,11,12,12,14,13,12,13,12,14,14, 5, 7, 7,
  129600. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  129601. 12,10,10,11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  129602. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,12,13, 7,
  129603. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  129604. 10,13,12,10,11,11,13,13, 9,11,10,13,13,10,11,11,
  129605. 13,13,10,11,11,13,13,12,12,13,13,15,12,12,13,14,
  129606. 15, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  129607. 11,13,11,14,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  129608. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  129609. 11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  129610. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  129611. 11, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,12,
  129612. 11,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  129613. 10,11,12,13,12,13,13,15,14,11,11,13,12,14,10,10,
  129614. 11,13,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  129615. 14,14,12,13,12,14,13, 8,10, 9,12,12, 9,11,10,13,
  129616. 13, 9,10,10,12,13,12,13,13,14,14,12,12,13,14,14,
  129617. 9,11,10,13,13,10,11,11,13,13,10,11,11,13,13,12,
  129618. 13,13,15,15,13,13,13,14,15, 9,10,10,12,13,10,11,
  129619. 10,13,12,10,11,11,13,13,12,13,12,15,14,13,13,13,
  129620. 14,15,11,12,12,15,14,12,12,13,15,15,12,13,13,15,
  129621. 14,14,13,15,14,16,13,14,15,16,16,11,12,12,14,14,
  129622. 11,12,12,15,14,12,13,13,15,15,13,14,13,16,14,14,
  129623. 14,14,16,16, 8, 9, 9,12,12, 9,10,10,13,12, 9,10,
  129624. 10,13,13,12,12,12,14,14,12,12,13,15,15, 9,10,10,
  129625. 13,12,10,11,11,13,13,10,10,11,13,14,12,13,13,15,
  129626. 15,12,12,13,14,15, 9,10,10,13,13,10,11,11,13,13,
  129627. 10,11,11,13,13,12,13,13,14,14,13,14,13,15,14,11,
  129628. 12,12,14,14,12,13,13,15,14,11,12,12,14,15,14,14,
  129629. 14,16,15,13,12,14,14,16,11,12,13,14,15,12,13,13,
  129630. 14,16,12,13,12,15,14,13,15,14,16,16,14,15,13,16,
  129631. 13,
  129632. };
  129633. static float _vq_quantthresh__16u2_p2_0[] = {
  129634. -1.5, -0.5, 0.5, 1.5,
  129635. };
  129636. static long _vq_quantmap__16u2_p2_0[] = {
  129637. 3, 1, 0, 2, 4,
  129638. };
  129639. static encode_aux_threshmatch _vq_auxt__16u2_p2_0 = {
  129640. _vq_quantthresh__16u2_p2_0,
  129641. _vq_quantmap__16u2_p2_0,
  129642. 5,
  129643. 5
  129644. };
  129645. static static_codebook _16u2_p2_0 = {
  129646. 4, 625,
  129647. _vq_lengthlist__16u2_p2_0,
  129648. 1, -533725184, 1611661312, 3, 0,
  129649. _vq_quantlist__16u2_p2_0,
  129650. NULL,
  129651. &_vq_auxt__16u2_p2_0,
  129652. NULL,
  129653. 0
  129654. };
  129655. static long _vq_quantlist__16u2_p3_0[] = {
  129656. 4,
  129657. 3,
  129658. 5,
  129659. 2,
  129660. 6,
  129661. 1,
  129662. 7,
  129663. 0,
  129664. 8,
  129665. };
  129666. static long _vq_lengthlist__16u2_p3_0[] = {
  129667. 2, 4, 4, 6, 6, 7, 7, 9, 9, 4, 5, 5, 6, 6, 8, 7,
  129668. 9, 9, 4, 5, 5, 6, 6, 7, 8, 9, 9, 6, 6, 6, 7, 7,
  129669. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  129670. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  129671. 9, 9,10, 9,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  129672. 11,
  129673. };
  129674. static float _vq_quantthresh__16u2_p3_0[] = {
  129675. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129676. };
  129677. static long _vq_quantmap__16u2_p3_0[] = {
  129678. 7, 5, 3, 1, 0, 2, 4, 6,
  129679. 8,
  129680. };
  129681. static encode_aux_threshmatch _vq_auxt__16u2_p3_0 = {
  129682. _vq_quantthresh__16u2_p3_0,
  129683. _vq_quantmap__16u2_p3_0,
  129684. 9,
  129685. 9
  129686. };
  129687. static static_codebook _16u2_p3_0 = {
  129688. 2, 81,
  129689. _vq_lengthlist__16u2_p3_0,
  129690. 1, -531628032, 1611661312, 4, 0,
  129691. _vq_quantlist__16u2_p3_0,
  129692. NULL,
  129693. &_vq_auxt__16u2_p3_0,
  129694. NULL,
  129695. 0
  129696. };
  129697. static long _vq_quantlist__16u2_p4_0[] = {
  129698. 8,
  129699. 7,
  129700. 9,
  129701. 6,
  129702. 10,
  129703. 5,
  129704. 11,
  129705. 4,
  129706. 12,
  129707. 3,
  129708. 13,
  129709. 2,
  129710. 14,
  129711. 1,
  129712. 15,
  129713. 0,
  129714. 16,
  129715. };
  129716. static long _vq_lengthlist__16u2_p4_0[] = {
  129717. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,11,
  129718. 11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  129719. 12,11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  129720. 11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  129721. 11,11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,
  129722. 10,11,11,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  129723. 11,11,12,12,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  129724. 10,11,11,11,12,12,12, 9, 9, 9, 9, 9, 9,10,10,10,
  129725. 10,10,11,11,12,12,13,13, 8, 9, 9, 9, 9,10, 9,10,
  129726. 10,10,10,11,11,12,12,13,13, 9, 9, 9, 9, 9,10,10,
  129727. 10,10,11,11,11,12,12,12,13,13, 9, 9, 9, 9, 9,10,
  129728. 10,10,10,11,11,12,11,12,12,13,13,10,10,10,10,10,
  129729. 11,11,11,11,11,12,12,12,12,13,13,14,10,10,10,10,
  129730. 10,11,11,11,11,12,11,12,12,13,12,13,13,11,11,11,
  129731. 11,11,12,12,12,12,12,12,13,13,13,13,14,14,11,11,
  129732. 11,11,11,12,12,12,12,12,12,13,12,13,13,14,14,11,
  129733. 12,12,12,12,12,12,13,13,13,13,13,13,14,14,14,14,
  129734. 11,12,12,12,12,12,12,13,13,13,13,14,13,14,14,14,
  129735. 14,
  129736. };
  129737. static float _vq_quantthresh__16u2_p4_0[] = {
  129738. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  129739. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  129740. };
  129741. static long _vq_quantmap__16u2_p4_0[] = {
  129742. 15, 13, 11, 9, 7, 5, 3, 1,
  129743. 0, 2, 4, 6, 8, 10, 12, 14,
  129744. 16,
  129745. };
  129746. static encode_aux_threshmatch _vq_auxt__16u2_p4_0 = {
  129747. _vq_quantthresh__16u2_p4_0,
  129748. _vq_quantmap__16u2_p4_0,
  129749. 17,
  129750. 17
  129751. };
  129752. static static_codebook _16u2_p4_0 = {
  129753. 2, 289,
  129754. _vq_lengthlist__16u2_p4_0,
  129755. 1, -529530880, 1611661312, 5, 0,
  129756. _vq_quantlist__16u2_p4_0,
  129757. NULL,
  129758. &_vq_auxt__16u2_p4_0,
  129759. NULL,
  129760. 0
  129761. };
  129762. static long _vq_quantlist__16u2_p5_0[] = {
  129763. 1,
  129764. 0,
  129765. 2,
  129766. };
  129767. static long _vq_lengthlist__16u2_p5_0[] = {
  129768. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10, 9, 7,
  129769. 10, 9, 5, 8, 9, 7, 9,10, 7, 9,10, 4, 9, 9, 9,11,
  129770. 11, 8,11,11, 7,11,11,10,10,13,10,14,13, 7,11,11,
  129771. 10,13,11,10,13,14, 5, 9, 9, 8,11,11, 9,11,11, 7,
  129772. 11,11,10,14,13,10,12,14, 7,11,11,10,13,13,10,13,
  129773. 10,
  129774. };
  129775. static float _vq_quantthresh__16u2_p5_0[] = {
  129776. -5.5, 5.5,
  129777. };
  129778. static long _vq_quantmap__16u2_p5_0[] = {
  129779. 1, 0, 2,
  129780. };
  129781. static encode_aux_threshmatch _vq_auxt__16u2_p5_0 = {
  129782. _vq_quantthresh__16u2_p5_0,
  129783. _vq_quantmap__16u2_p5_0,
  129784. 3,
  129785. 3
  129786. };
  129787. static static_codebook _16u2_p5_0 = {
  129788. 4, 81,
  129789. _vq_lengthlist__16u2_p5_0,
  129790. 1, -529137664, 1618345984, 2, 0,
  129791. _vq_quantlist__16u2_p5_0,
  129792. NULL,
  129793. &_vq_auxt__16u2_p5_0,
  129794. NULL,
  129795. 0
  129796. };
  129797. static long _vq_quantlist__16u2_p5_1[] = {
  129798. 5,
  129799. 4,
  129800. 6,
  129801. 3,
  129802. 7,
  129803. 2,
  129804. 8,
  129805. 1,
  129806. 9,
  129807. 0,
  129808. 10,
  129809. };
  129810. static long _vq_lengthlist__16u2_p5_1[] = {
  129811. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 5, 5, 5, 7, 7,
  129812. 7, 7, 8, 8, 8, 8, 5, 5, 6, 7, 7, 7, 7, 8, 8, 8,
  129813. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  129814. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  129815. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  129816. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  129817. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  129818. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  129819. };
  129820. static float _vq_quantthresh__16u2_p5_1[] = {
  129821. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129822. 3.5, 4.5,
  129823. };
  129824. static long _vq_quantmap__16u2_p5_1[] = {
  129825. 9, 7, 5, 3, 1, 0, 2, 4,
  129826. 6, 8, 10,
  129827. };
  129828. static encode_aux_threshmatch _vq_auxt__16u2_p5_1 = {
  129829. _vq_quantthresh__16u2_p5_1,
  129830. _vq_quantmap__16u2_p5_1,
  129831. 11,
  129832. 11
  129833. };
  129834. static static_codebook _16u2_p5_1 = {
  129835. 2, 121,
  129836. _vq_lengthlist__16u2_p5_1,
  129837. 1, -531365888, 1611661312, 4, 0,
  129838. _vq_quantlist__16u2_p5_1,
  129839. NULL,
  129840. &_vq_auxt__16u2_p5_1,
  129841. NULL,
  129842. 0
  129843. };
  129844. static long _vq_quantlist__16u2_p6_0[] = {
  129845. 6,
  129846. 5,
  129847. 7,
  129848. 4,
  129849. 8,
  129850. 3,
  129851. 9,
  129852. 2,
  129853. 10,
  129854. 1,
  129855. 11,
  129856. 0,
  129857. 12,
  129858. };
  129859. static long _vq_lengthlist__16u2_p6_0[] = {
  129860. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6,
  129861. 8, 8, 9, 9, 9, 9,10,10,12,11, 4, 6, 6, 8, 8, 9,
  129862. 9, 9, 9,10,10,11,12, 7, 8, 8, 9, 9,10,10,10,10,
  129863. 12,12,13,12, 7, 8, 8, 9, 9,10,10,10,10,11,12,12,
  129864. 12, 8, 9, 9,10,10,11,11,11,11,12,12,13,13, 8, 9,
  129865. 9,10,10,11,11,11,11,12,13,13,13, 8, 9, 9,10,10,
  129866. 11,11,12,12,13,13,14,14, 8, 9, 9,10,10,11,11,12,
  129867. 12,13,13,14,14, 9,10,10,11,12,13,12,13,14,14,14,
  129868. 14,14, 9,10,10,11,12,12,13,13,13,14,14,14,14,10,
  129869. 11,11,12,12,13,13,14,14,15,15,15,15,10,11,11,12,
  129870. 12,13,13,14,14,14,14,15,15,
  129871. };
  129872. static float _vq_quantthresh__16u2_p6_0[] = {
  129873. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  129874. 12.5, 17.5, 22.5, 27.5,
  129875. };
  129876. static long _vq_quantmap__16u2_p6_0[] = {
  129877. 11, 9, 7, 5, 3, 1, 0, 2,
  129878. 4, 6, 8, 10, 12,
  129879. };
  129880. static encode_aux_threshmatch _vq_auxt__16u2_p6_0 = {
  129881. _vq_quantthresh__16u2_p6_0,
  129882. _vq_quantmap__16u2_p6_0,
  129883. 13,
  129884. 13
  129885. };
  129886. static static_codebook _16u2_p6_0 = {
  129887. 2, 169,
  129888. _vq_lengthlist__16u2_p6_0,
  129889. 1, -526516224, 1616117760, 4, 0,
  129890. _vq_quantlist__16u2_p6_0,
  129891. NULL,
  129892. &_vq_auxt__16u2_p6_0,
  129893. NULL,
  129894. 0
  129895. };
  129896. static long _vq_quantlist__16u2_p6_1[] = {
  129897. 2,
  129898. 1,
  129899. 3,
  129900. 0,
  129901. 4,
  129902. };
  129903. static long _vq_lengthlist__16u2_p6_1[] = {
  129904. 2, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  129905. 5, 5, 6, 6, 5, 5, 5, 6, 6,
  129906. };
  129907. static float _vq_quantthresh__16u2_p6_1[] = {
  129908. -1.5, -0.5, 0.5, 1.5,
  129909. };
  129910. static long _vq_quantmap__16u2_p6_1[] = {
  129911. 3, 1, 0, 2, 4,
  129912. };
  129913. static encode_aux_threshmatch _vq_auxt__16u2_p6_1 = {
  129914. _vq_quantthresh__16u2_p6_1,
  129915. _vq_quantmap__16u2_p6_1,
  129916. 5,
  129917. 5
  129918. };
  129919. static static_codebook _16u2_p6_1 = {
  129920. 2, 25,
  129921. _vq_lengthlist__16u2_p6_1,
  129922. 1, -533725184, 1611661312, 3, 0,
  129923. _vq_quantlist__16u2_p6_1,
  129924. NULL,
  129925. &_vq_auxt__16u2_p6_1,
  129926. NULL,
  129927. 0
  129928. };
  129929. static long _vq_quantlist__16u2_p7_0[] = {
  129930. 6,
  129931. 5,
  129932. 7,
  129933. 4,
  129934. 8,
  129935. 3,
  129936. 9,
  129937. 2,
  129938. 10,
  129939. 1,
  129940. 11,
  129941. 0,
  129942. 12,
  129943. };
  129944. static long _vq_lengthlist__16u2_p7_0[] = {
  129945. 1, 4, 4, 7, 7, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 6,
  129946. 9, 9, 9, 9, 9, 9,10,10,11,11, 4, 6, 6, 8, 9, 9,
  129947. 9, 9, 9,10,11,12,11, 7, 8, 9,10,10,10,10,11,10,
  129948. 11,12,12,13, 7, 9, 9,10,10,10,10,10,10,11,12,13,
  129949. 13, 7, 9, 8,10,10,11,11,11,12,12,13,13,14, 7, 9,
  129950. 9,10,10,11,11,11,12,13,13,13,13, 8, 9, 9,10,11,
  129951. 11,12,12,12,13,13,13,13, 8, 9, 9,10,11,11,11,12,
  129952. 12,13,13,14,14, 9,10,10,12,11,12,13,13,13,14,13,
  129953. 13,13, 9,10,10,11,11,12,12,13,14,13,13,14,13,10,
  129954. 11,11,12,13,14,14,14,15,14,14,14,14,10,11,11,12,
  129955. 12,13,13,13,14,14,14,15,14,
  129956. };
  129957. static float _vq_quantthresh__16u2_p7_0[] = {
  129958. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  129959. 27.5, 38.5, 49.5, 60.5,
  129960. };
  129961. static long _vq_quantmap__16u2_p7_0[] = {
  129962. 11, 9, 7, 5, 3, 1, 0, 2,
  129963. 4, 6, 8, 10, 12,
  129964. };
  129965. static encode_aux_threshmatch _vq_auxt__16u2_p7_0 = {
  129966. _vq_quantthresh__16u2_p7_0,
  129967. _vq_quantmap__16u2_p7_0,
  129968. 13,
  129969. 13
  129970. };
  129971. static static_codebook _16u2_p7_0 = {
  129972. 2, 169,
  129973. _vq_lengthlist__16u2_p7_0,
  129974. 1, -523206656, 1618345984, 4, 0,
  129975. _vq_quantlist__16u2_p7_0,
  129976. NULL,
  129977. &_vq_auxt__16u2_p7_0,
  129978. NULL,
  129979. 0
  129980. };
  129981. static long _vq_quantlist__16u2_p7_1[] = {
  129982. 5,
  129983. 4,
  129984. 6,
  129985. 3,
  129986. 7,
  129987. 2,
  129988. 8,
  129989. 1,
  129990. 9,
  129991. 0,
  129992. 10,
  129993. };
  129994. static long _vq_lengthlist__16u2_p7_1[] = {
  129995. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  129996. 7, 7, 7, 7, 8, 8, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8,
  129997. 8, 6, 6, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 7, 7, 7,
  129998. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  129999. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  130000. 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8,
  130001. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  130002. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130003. };
  130004. static float _vq_quantthresh__16u2_p7_1[] = {
  130005. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  130006. 3.5, 4.5,
  130007. };
  130008. static long _vq_quantmap__16u2_p7_1[] = {
  130009. 9, 7, 5, 3, 1, 0, 2, 4,
  130010. 6, 8, 10,
  130011. };
  130012. static encode_aux_threshmatch _vq_auxt__16u2_p7_1 = {
  130013. _vq_quantthresh__16u2_p7_1,
  130014. _vq_quantmap__16u2_p7_1,
  130015. 11,
  130016. 11
  130017. };
  130018. static static_codebook _16u2_p7_1 = {
  130019. 2, 121,
  130020. _vq_lengthlist__16u2_p7_1,
  130021. 1, -531365888, 1611661312, 4, 0,
  130022. _vq_quantlist__16u2_p7_1,
  130023. NULL,
  130024. &_vq_auxt__16u2_p7_1,
  130025. NULL,
  130026. 0
  130027. };
  130028. static long _vq_quantlist__16u2_p8_0[] = {
  130029. 7,
  130030. 6,
  130031. 8,
  130032. 5,
  130033. 9,
  130034. 4,
  130035. 10,
  130036. 3,
  130037. 11,
  130038. 2,
  130039. 12,
  130040. 1,
  130041. 13,
  130042. 0,
  130043. 14,
  130044. };
  130045. static long _vq_lengthlist__16u2_p8_0[] = {
  130046. 1, 5, 5, 7, 7, 8, 8, 7, 7, 8, 8,10, 9,11,11, 4,
  130047. 6, 6, 8, 8,10, 9, 9, 8, 9, 9,10,10,12,14, 4, 6,
  130048. 7, 8, 9, 9,10, 9, 8, 9, 9,10,12,12,11, 7, 8, 8,
  130049. 10,10,10,10, 9, 9,10,10,11,13,13,12, 7, 8, 8, 9,
  130050. 11,11,10, 9, 9,11,10,12,11,11,14, 8, 9, 9,11,10,
  130051. 11,11,10,10,11,11,13,12,14,12, 8, 9, 9,11,12,11,
  130052. 11,10,10,12,11,12,12,12,14, 7, 8, 8, 9, 9,10,10,
  130053. 10,11,12,11,13,13,14,12, 7, 8, 9, 9, 9,10,10,11,
  130054. 11,11,12,12,14,14,14, 8,10, 9,10,11,11,11,11,14,
  130055. 12,12,13,14,14,13, 9, 9, 9,10,11,11,11,12,12,12,
  130056. 14,12,14,13,14,10,10,10,12,11,12,11,14,13,14,13,
  130057. 14,14,13,14, 9,10,10,11,12,11,13,12,13,13,14,14,
  130058. 14,13,14,10,13,13,12,12,11,12,14,13,14,13,14,12,
  130059. 14,13,10,11,11,12,11,12,12,14,14,14,13,14,14,14,
  130060. 14,
  130061. };
  130062. static float _vq_quantthresh__16u2_p8_0[] = {
  130063. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  130064. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  130065. };
  130066. static long _vq_quantmap__16u2_p8_0[] = {
  130067. 13, 11, 9, 7, 5, 3, 1, 0,
  130068. 2, 4, 6, 8, 10, 12, 14,
  130069. };
  130070. static encode_aux_threshmatch _vq_auxt__16u2_p8_0 = {
  130071. _vq_quantthresh__16u2_p8_0,
  130072. _vq_quantmap__16u2_p8_0,
  130073. 15,
  130074. 15
  130075. };
  130076. static static_codebook _16u2_p8_0 = {
  130077. 2, 225,
  130078. _vq_lengthlist__16u2_p8_0,
  130079. 1, -520986624, 1620377600, 4, 0,
  130080. _vq_quantlist__16u2_p8_0,
  130081. NULL,
  130082. &_vq_auxt__16u2_p8_0,
  130083. NULL,
  130084. 0
  130085. };
  130086. static long _vq_quantlist__16u2_p8_1[] = {
  130087. 10,
  130088. 9,
  130089. 11,
  130090. 8,
  130091. 12,
  130092. 7,
  130093. 13,
  130094. 6,
  130095. 14,
  130096. 5,
  130097. 15,
  130098. 4,
  130099. 16,
  130100. 3,
  130101. 17,
  130102. 2,
  130103. 18,
  130104. 1,
  130105. 19,
  130106. 0,
  130107. 20,
  130108. };
  130109. static long _vq_lengthlist__16u2_p8_1[] = {
  130110. 2, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,10, 9, 9,
  130111. 9,10,10,10,10, 5, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,
  130112. 10, 9,10,10,10,10,10,10,11,10, 5, 6, 6, 7, 7, 8,
  130113. 8, 8, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 7,
  130114. 7, 7, 8, 8, 9, 8, 9, 9,10, 9,10,10,10,10,10,10,
  130115. 11,10,11,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,10, 9,10,
  130116. 10,10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,
  130117. 10, 9,10,10,10,10,10,10,10,11,10,10,11,10, 8, 8,
  130118. 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,
  130119. 11,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  130120. 11,10,11,10,11,10,11,10, 8, 9, 9, 9, 9, 9,10,10,
  130121. 10,10,10,10,10,10,10,10,11,11,10,10,10, 9,10, 9,
  130122. 9,10,10,10,11,10,10,10,10,10,10,10,10,11,11,11,
  130123. 11,11, 9, 9, 9,10, 9,10,10,10,10,10,10,11,10,11,
  130124. 10,11,11,11,11,10,10, 9,10, 9,10,10,10,10,11,10,
  130125. 10,10,10,10,11,10,11,10,11,10,10,11, 9,10,10,10,
  130126. 10,10,10,10,10,10,11,10,10,11,11,10,11,11,11,11,
  130127. 11, 9, 9,10,10,10,10,10,11,10,10,11,10,10,11,10,
  130128. 10,11,11,11,11,11, 9,10,10,10,10,10,10,10,11,10,
  130129. 11,10,11,10,11,11,11,11,11,10,11,10,10,10,10,10,
  130130. 10,10,10,10,11,11,11,11,11,11,11,11,11,10,11,11,
  130131. 10,10,10,10,10,11,10,10,10,11,10,11,11,11,11,10,
  130132. 12,11,11,11,10,10,10,10,10,10,11,10,10,10,11,11,
  130133. 12,11,11,11,11,11,11,11,11,11,10,10,10,11,10,11,
  130134. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  130135. 10,10,11,10,11,10,10,11,11,11,11,11,11,11,11,11,
  130136. 11,11,11,10,10,10,10,10,10,10,11,11,10,11,11,10,
  130137. 11,11,10,11,11,11,10,11,11,
  130138. };
  130139. static float _vq_quantthresh__16u2_p8_1[] = {
  130140. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  130141. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  130142. 6.5, 7.5, 8.5, 9.5,
  130143. };
  130144. static long _vq_quantmap__16u2_p8_1[] = {
  130145. 19, 17, 15, 13, 11, 9, 7, 5,
  130146. 3, 1, 0, 2, 4, 6, 8, 10,
  130147. 12, 14, 16, 18, 20,
  130148. };
  130149. static encode_aux_threshmatch _vq_auxt__16u2_p8_1 = {
  130150. _vq_quantthresh__16u2_p8_1,
  130151. _vq_quantmap__16u2_p8_1,
  130152. 21,
  130153. 21
  130154. };
  130155. static static_codebook _16u2_p8_1 = {
  130156. 2, 441,
  130157. _vq_lengthlist__16u2_p8_1,
  130158. 1, -529268736, 1611661312, 5, 0,
  130159. _vq_quantlist__16u2_p8_1,
  130160. NULL,
  130161. &_vq_auxt__16u2_p8_1,
  130162. NULL,
  130163. 0
  130164. };
  130165. static long _vq_quantlist__16u2_p9_0[] = {
  130166. 5586,
  130167. 4655,
  130168. 6517,
  130169. 3724,
  130170. 7448,
  130171. 2793,
  130172. 8379,
  130173. 1862,
  130174. 9310,
  130175. 931,
  130176. 10241,
  130177. 0,
  130178. 11172,
  130179. 5521,
  130180. 5651,
  130181. };
  130182. static long _vq_lengthlist__16u2_p9_0[] = {
  130183. 1,10,10,10,10,10,10,10,10,10,10,10,10, 5, 4,10,
  130184. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130185. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130186. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130187. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130188. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130189. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130190. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130191. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130192. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130193. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130194. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130195. 10,10,10, 4,10,10,10,10,10,10,10,10,10,10,10,10,
  130196. 6, 6, 5,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 5,
  130197. 5,
  130198. };
  130199. static float _vq_quantthresh__16u2_p9_0[] = {
  130200. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -498, -32.5, 32.5,
  130201. 498, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5,
  130202. };
  130203. static long _vq_quantmap__16u2_p9_0[] = {
  130204. 11, 9, 7, 5, 3, 1, 13, 0,
  130205. 14, 2, 4, 6, 8, 10, 12,
  130206. };
  130207. static encode_aux_threshmatch _vq_auxt__16u2_p9_0 = {
  130208. _vq_quantthresh__16u2_p9_0,
  130209. _vq_quantmap__16u2_p9_0,
  130210. 15,
  130211. 15
  130212. };
  130213. static static_codebook _16u2_p9_0 = {
  130214. 2, 225,
  130215. _vq_lengthlist__16u2_p9_0,
  130216. 1, -510275072, 1611661312, 14, 0,
  130217. _vq_quantlist__16u2_p9_0,
  130218. NULL,
  130219. &_vq_auxt__16u2_p9_0,
  130220. NULL,
  130221. 0
  130222. };
  130223. static long _vq_quantlist__16u2_p9_1[] = {
  130224. 392,
  130225. 343,
  130226. 441,
  130227. 294,
  130228. 490,
  130229. 245,
  130230. 539,
  130231. 196,
  130232. 588,
  130233. 147,
  130234. 637,
  130235. 98,
  130236. 686,
  130237. 49,
  130238. 735,
  130239. 0,
  130240. 784,
  130241. 388,
  130242. 396,
  130243. };
  130244. static long _vq_lengthlist__16u2_p9_1[] = {
  130245. 1,12,10,12,10,12,10,12,11,12,12,12,12,12,12,12,
  130246. 12, 5, 5, 9,10,12,11,11,12,12,12,12,12,12,12,12,
  130247. 12,12,12,12,10, 9, 9,11, 9,11,11,12,11,12,12,12,
  130248. 12,12,12,12,12,12,12, 8, 8,10,11, 9,12,11,12,12,
  130249. 12,12,12,12,12,12,12,12,12,12, 9, 8,10,11,12,11,
  130250. 12,11,12,12,12,12,12,12,12,12,12,12,12, 8, 9,11,
  130251. 11,10,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130252. 9,10,11,12,11,12,11,12,12,12,12,12,12,12,12,12,
  130253. 12,12,12, 9, 9,11,12,12,12,12,12,12,12,12,12,12,
  130254. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130255. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130256. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130257. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130258. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130259. 12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,
  130260. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130261. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130262. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130263. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130264. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130265. 11,11,11, 5, 8, 9, 9, 8,11, 9,11,11,11,11,11,11,
  130266. 11,11,11,11, 5, 5, 4, 8, 8, 8, 8,10, 9,10,10,11,
  130267. 11,11,11,11,11,11,11, 5, 4,
  130268. };
  130269. static float _vq_quantthresh__16u2_p9_1[] = {
  130270. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -26.5,
  130271. -2, 2, 26.5, 73.5, 122.5, 171.5, 220.5, 269.5,
  130272. 318.5, 367.5,
  130273. };
  130274. static long _vq_quantmap__16u2_p9_1[] = {
  130275. 15, 13, 11, 9, 7, 5, 3, 1,
  130276. 17, 0, 18, 2, 4, 6, 8, 10,
  130277. 12, 14, 16,
  130278. };
  130279. static encode_aux_threshmatch _vq_auxt__16u2_p9_1 = {
  130280. _vq_quantthresh__16u2_p9_1,
  130281. _vq_quantmap__16u2_p9_1,
  130282. 19,
  130283. 19
  130284. };
  130285. static static_codebook _16u2_p9_1 = {
  130286. 2, 361,
  130287. _vq_lengthlist__16u2_p9_1,
  130288. 1, -518488064, 1611661312, 10, 0,
  130289. _vq_quantlist__16u2_p9_1,
  130290. NULL,
  130291. &_vq_auxt__16u2_p9_1,
  130292. NULL,
  130293. 0
  130294. };
  130295. static long _vq_quantlist__16u2_p9_2[] = {
  130296. 24,
  130297. 23,
  130298. 25,
  130299. 22,
  130300. 26,
  130301. 21,
  130302. 27,
  130303. 20,
  130304. 28,
  130305. 19,
  130306. 29,
  130307. 18,
  130308. 30,
  130309. 17,
  130310. 31,
  130311. 16,
  130312. 32,
  130313. 15,
  130314. 33,
  130315. 14,
  130316. 34,
  130317. 13,
  130318. 35,
  130319. 12,
  130320. 36,
  130321. 11,
  130322. 37,
  130323. 10,
  130324. 38,
  130325. 9,
  130326. 39,
  130327. 8,
  130328. 40,
  130329. 7,
  130330. 41,
  130331. 6,
  130332. 42,
  130333. 5,
  130334. 43,
  130335. 4,
  130336. 44,
  130337. 3,
  130338. 45,
  130339. 2,
  130340. 46,
  130341. 1,
  130342. 47,
  130343. 0,
  130344. 48,
  130345. };
  130346. static long _vq_lengthlist__16u2_p9_2[] = {
  130347. 1, 3, 3, 4, 7, 7, 7, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  130348. 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 9, 9, 8, 9, 9,
  130349. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,12,12,10,
  130350. 11,
  130351. };
  130352. static float _vq_quantthresh__16u2_p9_2[] = {
  130353. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  130354. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  130355. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  130356. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  130357. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  130358. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  130359. };
  130360. static long _vq_quantmap__16u2_p9_2[] = {
  130361. 47, 45, 43, 41, 39, 37, 35, 33,
  130362. 31, 29, 27, 25, 23, 21, 19, 17,
  130363. 15, 13, 11, 9, 7, 5, 3, 1,
  130364. 0, 2, 4, 6, 8, 10, 12, 14,
  130365. 16, 18, 20, 22, 24, 26, 28, 30,
  130366. 32, 34, 36, 38, 40, 42, 44, 46,
  130367. 48,
  130368. };
  130369. static encode_aux_threshmatch _vq_auxt__16u2_p9_2 = {
  130370. _vq_quantthresh__16u2_p9_2,
  130371. _vq_quantmap__16u2_p9_2,
  130372. 49,
  130373. 49
  130374. };
  130375. static static_codebook _16u2_p9_2 = {
  130376. 1, 49,
  130377. _vq_lengthlist__16u2_p9_2,
  130378. 1, -526909440, 1611661312, 6, 0,
  130379. _vq_quantlist__16u2_p9_2,
  130380. NULL,
  130381. &_vq_auxt__16u2_p9_2,
  130382. NULL,
  130383. 0
  130384. };
  130385. static long _vq_quantlist__8u0__p1_0[] = {
  130386. 1,
  130387. 0,
  130388. 2,
  130389. };
  130390. static long _vq_lengthlist__8u0__p1_0[] = {
  130391. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  130392. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 4, 9, 8, 8,11,
  130393. 11, 8,11,11, 7,11,11,10,11,13,10,13,13, 7,11,11,
  130394. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 8,11,11, 7,
  130395. 11,11, 9,13,13,10,12,13, 7,11,11,10,13,13,10,13,
  130396. 11,
  130397. };
  130398. static float _vq_quantthresh__8u0__p1_0[] = {
  130399. -0.5, 0.5,
  130400. };
  130401. static long _vq_quantmap__8u0__p1_0[] = {
  130402. 1, 0, 2,
  130403. };
  130404. static encode_aux_threshmatch _vq_auxt__8u0__p1_0 = {
  130405. _vq_quantthresh__8u0__p1_0,
  130406. _vq_quantmap__8u0__p1_0,
  130407. 3,
  130408. 3
  130409. };
  130410. static static_codebook _8u0__p1_0 = {
  130411. 4, 81,
  130412. _vq_lengthlist__8u0__p1_0,
  130413. 1, -535822336, 1611661312, 2, 0,
  130414. _vq_quantlist__8u0__p1_0,
  130415. NULL,
  130416. &_vq_auxt__8u0__p1_0,
  130417. NULL,
  130418. 0
  130419. };
  130420. static long _vq_quantlist__8u0__p2_0[] = {
  130421. 1,
  130422. 0,
  130423. 2,
  130424. };
  130425. static long _vq_lengthlist__8u0__p2_0[] = {
  130426. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 6, 7, 8, 6,
  130427. 7, 8, 5, 7, 7, 6, 8, 8, 7, 9, 7, 5, 7, 7, 7, 9,
  130428. 9, 7, 8, 8, 6, 9, 8, 7, 7,10, 8,10,10, 6, 8, 8,
  130429. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  130430. 8, 8, 8,10,10, 8, 8,10, 6, 8, 9, 8,10,10, 7,10,
  130431. 8,
  130432. };
  130433. static float _vq_quantthresh__8u0__p2_0[] = {
  130434. -0.5, 0.5,
  130435. };
  130436. static long _vq_quantmap__8u0__p2_0[] = {
  130437. 1, 0, 2,
  130438. };
  130439. static encode_aux_threshmatch _vq_auxt__8u0__p2_0 = {
  130440. _vq_quantthresh__8u0__p2_0,
  130441. _vq_quantmap__8u0__p2_0,
  130442. 3,
  130443. 3
  130444. };
  130445. static static_codebook _8u0__p2_0 = {
  130446. 4, 81,
  130447. _vq_lengthlist__8u0__p2_0,
  130448. 1, -535822336, 1611661312, 2, 0,
  130449. _vq_quantlist__8u0__p2_0,
  130450. NULL,
  130451. &_vq_auxt__8u0__p2_0,
  130452. NULL,
  130453. 0
  130454. };
  130455. static long _vq_quantlist__8u0__p3_0[] = {
  130456. 2,
  130457. 1,
  130458. 3,
  130459. 0,
  130460. 4,
  130461. };
  130462. static long _vq_lengthlist__8u0__p3_0[] = {
  130463. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  130464. 10, 9,11,11, 8, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  130465. 10,11,11, 8,10,10,11,11,10,11,11,12,12,10,11,11,
  130466. 12,13, 6, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  130467. 11, 9,10,11,12,12,10,11,11,12,12, 8,11,11,14,13,
  130468. 10,12,11,15,13,10,12,11,14,14,12,13,12,16,14,12,
  130469. 14,12,16,15, 8,11,11,13,14,10,11,12,13,15,10,11,
  130470. 12,13,15,11,12,13,14,15,12,12,14,14,16, 5, 8, 8,
  130471. 11,11, 9,11,11,12,12, 8,10,11,12,12,11,12,12,15,
  130472. 14,11,12,12,14,14, 7,11,10,13,12,10,11,12,13,14,
  130473. 10,12,12,14,13,12,13,13,14,15,12,13,13,15,15, 7,
  130474. 10,11,12,13,10,12,11,14,13,10,12,13,13,15,12,13,
  130475. 12,14,14,11,13,13,15,16, 9,12,12,15,14,11,13,13,
  130476. 15,16,11,13,13,16,16,13,14,15,15,15,12,14,15,17,
  130477. 16, 9,12,12,14,15,11,13,13,15,16,11,13,13,16,18,
  130478. 13,14,14,17,16,13,15,15,17,18, 5, 8, 9,11,11, 8,
  130479. 11,11,12,12, 8,10,11,12,12,11,12,12,14,14,11,12,
  130480. 12,14,15, 7,11,10,12,13,10,12,12,14,13,10,11,12,
  130481. 13,14,11,13,13,15,14,12,13,13,14,15, 7,10,11,13,
  130482. 13,10,12,12,13,14,10,12,12,13,13,11,13,13,16,16,
  130483. 12,13,13,15,14, 9,12,12,16,15,10,13,13,15,15,11,
  130484. 13,13,17,15,12,15,15,18,17,13,14,14,15,16, 9,12,
  130485. 12,15,15,11,13,13,15,16,11,13,13,15,15,12,15,15,
  130486. 16,16,13,15,14,17,15, 7,11,11,15,15,10,13,13,16,
  130487. 15,10,13,13,15,16,14,15,15,17,19,13,15,14,15,18,
  130488. 9,12,12,16,16,11,13,14,17,16,11,13,13,17,16,15,
  130489. 15,16,17,19,13,15,16, 0,18, 9,12,12,16,15,11,14,
  130490. 13,17,17,11,13,14,16,16,15,16,16,19,18,13,15,15,
  130491. 17,19,11,14,14,19,16,12,14,15, 0,18,12,16,15,18,
  130492. 17,15,15,18,16,19,14,15,17,19,19,11,14,14,18,19,
  130493. 13,15,14,19,19,12,16,15,18,17,15,17,15, 0,16,14,
  130494. 17,16,19, 0, 7,11,11,14,14,10,12,12,15,15,10,13,
  130495. 13,16,15,13,15,15,17, 0,14,15,15,16,19, 9,12,12,
  130496. 16,16,11,14,14,16,16,11,13,13,16,16,14,17,16,19,
  130497. 0,14,18,17,17,19, 9,12,12,15,16,11,13,13,15,17,
  130498. 12,14,13,19,16,13,15,15,17,19,15,17,16,17,19,11,
  130499. 14,14,19,16,12,15,15,19,17,13,14,15,17,19,14,16,
  130500. 17,19,19,16,15,16,17,19,11,15,14,16,16,12,15,15,
  130501. 19, 0,12,14,15,19,19,14,16,16, 0,18,15,19,14,18,
  130502. 16,
  130503. };
  130504. static float _vq_quantthresh__8u0__p3_0[] = {
  130505. -1.5, -0.5, 0.5, 1.5,
  130506. };
  130507. static long _vq_quantmap__8u0__p3_0[] = {
  130508. 3, 1, 0, 2, 4,
  130509. };
  130510. static encode_aux_threshmatch _vq_auxt__8u0__p3_0 = {
  130511. _vq_quantthresh__8u0__p3_0,
  130512. _vq_quantmap__8u0__p3_0,
  130513. 5,
  130514. 5
  130515. };
  130516. static static_codebook _8u0__p3_0 = {
  130517. 4, 625,
  130518. _vq_lengthlist__8u0__p3_0,
  130519. 1, -533725184, 1611661312, 3, 0,
  130520. _vq_quantlist__8u0__p3_0,
  130521. NULL,
  130522. &_vq_auxt__8u0__p3_0,
  130523. NULL,
  130524. 0
  130525. };
  130526. static long _vq_quantlist__8u0__p4_0[] = {
  130527. 2,
  130528. 1,
  130529. 3,
  130530. 0,
  130531. 4,
  130532. };
  130533. static long _vq_lengthlist__8u0__p4_0[] = {
  130534. 3, 5, 5, 8, 8, 5, 6, 7, 9, 9, 6, 7, 6, 9, 9, 9,
  130535. 9, 9,10,11, 9, 9, 9,11,10, 6, 7, 7,10,10, 7, 7,
  130536. 8,10,10, 7, 8, 8,10,10,10,10,10,10,11, 9,10,10,
  130537. 11,12, 6, 7, 7,10,10, 7, 8, 8,10,10, 7, 8, 7,10,
  130538. 10, 9,10,10,12,11,10,10,10,11,10, 9,10,10,12,11,
  130539. 10,10,10,13,11, 9,10,10,12,12,11,11,12,12,13,11,
  130540. 11,11,12,13, 9,10,10,12,12,10,10,11,12,12,10,10,
  130541. 11,12,12,11,11,11,13,13,11,12,12,13,13, 5, 7, 7,
  130542. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,11,12,
  130543. 12,10,11,10,12,12, 7, 8, 8,11,11, 7, 8, 9,10,11,
  130544. 8, 9, 9,11,11,11,10,11,10,12,10,11,11,12,13, 7,
  130545. 8, 8,10,11, 8, 9, 8,12,10, 8, 9, 9,11,12,10,11,
  130546. 10,13,11,10,11,11,13,12, 9,11,10,13,12,10,10,11,
  130547. 12,12,10,11,11,13,13,12,10,13,11,14,11,12,12,15,
  130548. 13, 9,11,11,13,13,10,11,11,13,12,10,11,11,12,14,
  130549. 12,13,11,14,12,12,12,12,14,14, 5, 7, 7,10,10, 7,
  130550. 8, 8,10,10, 7, 8, 8,11,10,10,11,11,12,12,10,11,
  130551. 10,12,12, 7, 8, 8,10,11, 8, 9, 9,12,11, 8, 8, 9,
  130552. 10,11,10,11,11,12,13,11,10,11,11,13, 6, 8, 8,10,
  130553. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,11,11,12,12,
  130554. 10,11,10,13,10, 9,11,10,13,12,10,12,11,13,13,10,
  130555. 10,11,12,13,11,12,13,15,14,11,11,13,12,13, 9,10,
  130556. 11,12,13,10,11,11,12,13,10,11,10,13,12,12,13,13,
  130557. 13,14,12,12,11,14,11, 8,10,10,12,13,10,11,11,13,
  130558. 13,10,11,10,13,13,12,13,14,15,14,12,12,12,14,13,
  130559. 9,10,10,13,12,10,10,12,13,13,10,11,11,15,12,12,
  130560. 12,13,15,14,12,13,13,15,13, 9,10,11,12,13,10,12,
  130561. 10,13,12,10,11,11,12,13,12,14,12,15,13,12,12,12,
  130562. 15,14,11,12,11,14,13,11,11,12,14,14,12,13,13,14,
  130563. 13,13,11,15,11,15,14,14,14,16,15,11,12,12,13,14,
  130564. 11,13,11,14,14,12,12,13,14,15,12,14,12,15,12,13,
  130565. 15,14,16,15, 8,10,10,12,12,10,10,10,12,13,10,11,
  130566. 11,13,13,12,12,12,13,14,13,13,13,15,15, 9,10,10,
  130567. 12,12,10,11,11,13,12,10,10,11,13,13,12,12,12,14,
  130568. 14,12,12,13,15,14, 9,10,10,13,12,10,10,12,12,13,
  130569. 10,11,10,13,13,12,13,13,14,14,12,13,12,14,13,11,
  130570. 12,12,14,13,12,13,12,14,14,10,12,12,14,14,14,14,
  130571. 14,16,14,13,12,14,12,15,10,12,12,14,15,12,13,13,
  130572. 14,16,11,12,11,15,14,13,14,14,14,15,13,14,11,14,
  130573. 12,
  130574. };
  130575. static float _vq_quantthresh__8u0__p4_0[] = {
  130576. -1.5, -0.5, 0.5, 1.5,
  130577. };
  130578. static long _vq_quantmap__8u0__p4_0[] = {
  130579. 3, 1, 0, 2, 4,
  130580. };
  130581. static encode_aux_threshmatch _vq_auxt__8u0__p4_0 = {
  130582. _vq_quantthresh__8u0__p4_0,
  130583. _vq_quantmap__8u0__p4_0,
  130584. 5,
  130585. 5
  130586. };
  130587. static static_codebook _8u0__p4_0 = {
  130588. 4, 625,
  130589. _vq_lengthlist__8u0__p4_0,
  130590. 1, -533725184, 1611661312, 3, 0,
  130591. _vq_quantlist__8u0__p4_0,
  130592. NULL,
  130593. &_vq_auxt__8u0__p4_0,
  130594. NULL,
  130595. 0
  130596. };
  130597. static long _vq_quantlist__8u0__p5_0[] = {
  130598. 4,
  130599. 3,
  130600. 5,
  130601. 2,
  130602. 6,
  130603. 1,
  130604. 7,
  130605. 0,
  130606. 8,
  130607. };
  130608. static long _vq_lengthlist__8u0__p5_0[] = {
  130609. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 7, 8, 8,
  130610. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 6, 8, 8, 9, 9,
  130611. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  130612. 9, 9,10,10,12,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  130613. 10,10,11,11,11,12,12,12, 9,10,10,11,11,12,12,12,
  130614. 12,
  130615. };
  130616. static float _vq_quantthresh__8u0__p5_0[] = {
  130617. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  130618. };
  130619. static long _vq_quantmap__8u0__p5_0[] = {
  130620. 7, 5, 3, 1, 0, 2, 4, 6,
  130621. 8,
  130622. };
  130623. static encode_aux_threshmatch _vq_auxt__8u0__p5_0 = {
  130624. _vq_quantthresh__8u0__p5_0,
  130625. _vq_quantmap__8u0__p5_0,
  130626. 9,
  130627. 9
  130628. };
  130629. static static_codebook _8u0__p5_0 = {
  130630. 2, 81,
  130631. _vq_lengthlist__8u0__p5_0,
  130632. 1, -531628032, 1611661312, 4, 0,
  130633. _vq_quantlist__8u0__p5_0,
  130634. NULL,
  130635. &_vq_auxt__8u0__p5_0,
  130636. NULL,
  130637. 0
  130638. };
  130639. static long _vq_quantlist__8u0__p6_0[] = {
  130640. 6,
  130641. 5,
  130642. 7,
  130643. 4,
  130644. 8,
  130645. 3,
  130646. 9,
  130647. 2,
  130648. 10,
  130649. 1,
  130650. 11,
  130651. 0,
  130652. 12,
  130653. };
  130654. static long _vq_lengthlist__8u0__p6_0[] = {
  130655. 1, 4, 4, 7, 7, 9, 9,11,11,12,12,16,16, 3, 6, 6,
  130656. 9, 9,11,11,12,12,13,14,18,16, 3, 6, 7, 9, 9,11,
  130657. 11,13,12,14,14,17,16, 7, 9, 9,11,11,12,12,14,14,
  130658. 14,14,17,16, 7, 9, 9,11,11,13,12,13,13,14,14,17,
  130659. 0, 9,11,11,12,13,14,14,14,13,15,14,17,17, 9,11,
  130660. 11,12,12,14,14,13,14,14,15, 0, 0,11,12,12,15,14,
  130661. 15,14,15,14,15,16,17, 0,11,12,13,13,13,14,14,15,
  130662. 14,15,15, 0, 0,12,14,14,15,15,14,16,15,15,17,16,
  130663. 0,18,13,14,14,15,14,15,14,15,16,17,16, 0, 0,17,
  130664. 17,18, 0,16,18,16, 0, 0, 0,17, 0, 0,16, 0, 0,16,
  130665. 16, 0,15, 0,17, 0, 0, 0, 0,
  130666. };
  130667. static float _vq_quantthresh__8u0__p6_0[] = {
  130668. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  130669. 12.5, 17.5, 22.5, 27.5,
  130670. };
  130671. static long _vq_quantmap__8u0__p6_0[] = {
  130672. 11, 9, 7, 5, 3, 1, 0, 2,
  130673. 4, 6, 8, 10, 12,
  130674. };
  130675. static encode_aux_threshmatch _vq_auxt__8u0__p6_0 = {
  130676. _vq_quantthresh__8u0__p6_0,
  130677. _vq_quantmap__8u0__p6_0,
  130678. 13,
  130679. 13
  130680. };
  130681. static static_codebook _8u0__p6_0 = {
  130682. 2, 169,
  130683. _vq_lengthlist__8u0__p6_0,
  130684. 1, -526516224, 1616117760, 4, 0,
  130685. _vq_quantlist__8u0__p6_0,
  130686. NULL,
  130687. &_vq_auxt__8u0__p6_0,
  130688. NULL,
  130689. 0
  130690. };
  130691. static long _vq_quantlist__8u0__p6_1[] = {
  130692. 2,
  130693. 1,
  130694. 3,
  130695. 0,
  130696. 4,
  130697. };
  130698. static long _vq_lengthlist__8u0__p6_1[] = {
  130699. 1, 4, 4, 6, 6, 4, 6, 5, 7, 7, 4, 5, 6, 7, 7, 6,
  130700. 7, 7, 7, 7, 6, 7, 7, 7, 7,
  130701. };
  130702. static float _vq_quantthresh__8u0__p6_1[] = {
  130703. -1.5, -0.5, 0.5, 1.5,
  130704. };
  130705. static long _vq_quantmap__8u0__p6_1[] = {
  130706. 3, 1, 0, 2, 4,
  130707. };
  130708. static encode_aux_threshmatch _vq_auxt__8u0__p6_1 = {
  130709. _vq_quantthresh__8u0__p6_1,
  130710. _vq_quantmap__8u0__p6_1,
  130711. 5,
  130712. 5
  130713. };
  130714. static static_codebook _8u0__p6_1 = {
  130715. 2, 25,
  130716. _vq_lengthlist__8u0__p6_1,
  130717. 1, -533725184, 1611661312, 3, 0,
  130718. _vq_quantlist__8u0__p6_1,
  130719. NULL,
  130720. &_vq_auxt__8u0__p6_1,
  130721. NULL,
  130722. 0
  130723. };
  130724. static long _vq_quantlist__8u0__p7_0[] = {
  130725. 1,
  130726. 0,
  130727. 2,
  130728. };
  130729. static long _vq_lengthlist__8u0__p7_0[] = {
  130730. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130731. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130732. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130733. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130734. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130735. 7,
  130736. };
  130737. static float _vq_quantthresh__8u0__p7_0[] = {
  130738. -157.5, 157.5,
  130739. };
  130740. static long _vq_quantmap__8u0__p7_0[] = {
  130741. 1, 0, 2,
  130742. };
  130743. static encode_aux_threshmatch _vq_auxt__8u0__p7_0 = {
  130744. _vq_quantthresh__8u0__p7_0,
  130745. _vq_quantmap__8u0__p7_0,
  130746. 3,
  130747. 3
  130748. };
  130749. static static_codebook _8u0__p7_0 = {
  130750. 4, 81,
  130751. _vq_lengthlist__8u0__p7_0,
  130752. 1, -518803456, 1628680192, 2, 0,
  130753. _vq_quantlist__8u0__p7_0,
  130754. NULL,
  130755. &_vq_auxt__8u0__p7_0,
  130756. NULL,
  130757. 0
  130758. };
  130759. static long _vq_quantlist__8u0__p7_1[] = {
  130760. 7,
  130761. 6,
  130762. 8,
  130763. 5,
  130764. 9,
  130765. 4,
  130766. 10,
  130767. 3,
  130768. 11,
  130769. 2,
  130770. 12,
  130771. 1,
  130772. 13,
  130773. 0,
  130774. 14,
  130775. };
  130776. static long _vq_lengthlist__8u0__p7_1[] = {
  130777. 1, 5, 5, 5, 5,10,10,11,11,11,11,11,11,11,11, 5,
  130778. 7, 6, 8, 8, 9,10,11,11,11,11,11,11,11,11, 6, 6,
  130779. 7, 9, 7,11,10,11,11,11,11,11,11,11,11, 5, 6, 6,
  130780. 11, 8,11,11,11,11,11,11,11,11,11,11, 5, 6, 6, 9,
  130781. 10,11,10,11,11,11,11,11,11,11,11, 7,10,10,11,11,
  130782. 11,11,11,11,11,11,11,11,11,11, 7,11, 8,11,11,11,
  130783. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130784. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130785. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130786. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130787. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130788. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130789. 11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,
  130790. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130791. 10,
  130792. };
  130793. static float _vq_quantthresh__8u0__p7_1[] = {
  130794. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  130795. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  130796. };
  130797. static long _vq_quantmap__8u0__p7_1[] = {
  130798. 13, 11, 9, 7, 5, 3, 1, 0,
  130799. 2, 4, 6, 8, 10, 12, 14,
  130800. };
  130801. static encode_aux_threshmatch _vq_auxt__8u0__p7_1 = {
  130802. _vq_quantthresh__8u0__p7_1,
  130803. _vq_quantmap__8u0__p7_1,
  130804. 15,
  130805. 15
  130806. };
  130807. static static_codebook _8u0__p7_1 = {
  130808. 2, 225,
  130809. _vq_lengthlist__8u0__p7_1,
  130810. 1, -520986624, 1620377600, 4, 0,
  130811. _vq_quantlist__8u0__p7_1,
  130812. NULL,
  130813. &_vq_auxt__8u0__p7_1,
  130814. NULL,
  130815. 0
  130816. };
  130817. static long _vq_quantlist__8u0__p7_2[] = {
  130818. 10,
  130819. 9,
  130820. 11,
  130821. 8,
  130822. 12,
  130823. 7,
  130824. 13,
  130825. 6,
  130826. 14,
  130827. 5,
  130828. 15,
  130829. 4,
  130830. 16,
  130831. 3,
  130832. 17,
  130833. 2,
  130834. 18,
  130835. 1,
  130836. 19,
  130837. 0,
  130838. 20,
  130839. };
  130840. static long _vq_lengthlist__8u0__p7_2[] = {
  130841. 1, 6, 5, 7, 7, 9, 9, 9, 9,10,12,12,10,11,11,10,
  130842. 11,11,11,10,11, 6, 8, 8, 9, 9,10,10, 9,10,11,11,
  130843. 10,11,11,11,11,10,11,11,11,11, 6, 7, 8, 9, 9, 9,
  130844. 10,11,10,11,12,11,10,11,11,11,11,11,11,12,10, 8,
  130845. 9, 9,10, 9,10,10, 9,10,10,10,10,10, 9,10,10,10,
  130846. 10, 9,10,10, 9, 9, 9, 9,10,10, 9, 9,10,10,11,10,
  130847. 9,12,10,11,10, 9,10,10,10, 8, 9, 9,10, 9,10, 9,
  130848. 9,10,10, 9,10, 9,11,10,10,10,10,10, 9,10, 8, 8,
  130849. 9, 9,10, 9,11, 9, 8, 9, 9,10,11,10,10,10,11,12,
  130850. 9, 9,11, 8, 9, 8,11,10,11,10,10, 9,11,10,10,10,
  130851. 10,10,10,10,11,11,11,11, 8, 9, 9, 9,10,10,10,11,
  130852. 11,12,11,12,11,10,10,10,12,11,11,11,10, 8,10, 9,
  130853. 11,10,10,11,12,10,11,12,11,11,12,11,12,12,10,11,
  130854. 11,10, 9, 9,10,11,12,10,10,10,11,10,11,11,10,12,
  130855. 12,10,11,10,11,12,10, 9,10,10,11,10,11,11,11,11,
  130856. 11,12,11,11,11, 9,11,10,11,10,11,10, 9, 9,10,11,
  130857. 11,11,10,10,11,12,12,11,12,11,11,11,12,12,12,12,
  130858. 11, 9,11,11,12,10,11,11,11,11,11,11,12,11,11,12,
  130859. 11,11,11,10,11,11, 9,11,10,11,11,11,10,10,10,11,
  130860. 11,11,12,10,11,10,11,11,11,11,12, 9,11,10,11,11,
  130861. 10,10,11,11, 9,11,11,12,10,10,10,10,10,11,11,10,
  130862. 9,10,11,11,12,11,10,10,12,11,11,12,11,12,11,11,
  130863. 10,10,11,11,10,12,11,10,11,10,11,10,10,10,11,11,
  130864. 10,10,11,11,11,11,10,10,10,12,11,11,11,11,10, 9,
  130865. 10,11,11,11,12,11,11,11,12,10,11,11,11, 9,10,11,
  130866. 11,11,11,11,11,10,10,11,11,12,11,10,11,12,11,10,
  130867. 10,11, 9,10,11,11,11,11,11,10,11,11,10,12,11,11,
  130868. 11,12,11,11,11,10,10,11,11,
  130869. };
  130870. static float _vq_quantthresh__8u0__p7_2[] = {
  130871. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  130872. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  130873. 6.5, 7.5, 8.5, 9.5,
  130874. };
  130875. static long _vq_quantmap__8u0__p7_2[] = {
  130876. 19, 17, 15, 13, 11, 9, 7, 5,
  130877. 3, 1, 0, 2, 4, 6, 8, 10,
  130878. 12, 14, 16, 18, 20,
  130879. };
  130880. static encode_aux_threshmatch _vq_auxt__8u0__p7_2 = {
  130881. _vq_quantthresh__8u0__p7_2,
  130882. _vq_quantmap__8u0__p7_2,
  130883. 21,
  130884. 21
  130885. };
  130886. static static_codebook _8u0__p7_2 = {
  130887. 2, 441,
  130888. _vq_lengthlist__8u0__p7_2,
  130889. 1, -529268736, 1611661312, 5, 0,
  130890. _vq_quantlist__8u0__p7_2,
  130891. NULL,
  130892. &_vq_auxt__8u0__p7_2,
  130893. NULL,
  130894. 0
  130895. };
  130896. static long _huff_lengthlist__8u0__single[] = {
  130897. 4, 7,11, 9,12, 8, 7,10, 6, 4, 5, 5, 7, 5, 6,16,
  130898. 9, 5, 5, 6, 7, 7, 9,16, 7, 4, 6, 5, 7, 5, 7,17,
  130899. 10, 7, 7, 8, 7, 7, 8,18, 7, 5, 6, 4, 5, 4, 5,15,
  130900. 7, 6, 7, 5, 6, 4, 5,15,12,13,18,12,17,11, 9,17,
  130901. };
  130902. static static_codebook _huff_book__8u0__single = {
  130903. 2, 64,
  130904. _huff_lengthlist__8u0__single,
  130905. 0, 0, 0, 0, 0,
  130906. NULL,
  130907. NULL,
  130908. NULL,
  130909. NULL,
  130910. 0
  130911. };
  130912. static long _vq_quantlist__8u1__p1_0[] = {
  130913. 1,
  130914. 0,
  130915. 2,
  130916. };
  130917. static long _vq_lengthlist__8u1__p1_0[] = {
  130918. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 7, 9,10, 7,
  130919. 9, 9, 5, 8, 8, 7,10, 9, 7, 9, 9, 5, 8, 8, 8,10,
  130920. 10, 8,10,10, 7,10,10, 9,10,12,10,12,12, 7,10,10,
  130921. 9,12,11,10,12,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  130922. 10,10,10,12,12, 9,11,12, 7,10,10,10,12,12, 9,12,
  130923. 10,
  130924. };
  130925. static float _vq_quantthresh__8u1__p1_0[] = {
  130926. -0.5, 0.5,
  130927. };
  130928. static long _vq_quantmap__8u1__p1_0[] = {
  130929. 1, 0, 2,
  130930. };
  130931. static encode_aux_threshmatch _vq_auxt__8u1__p1_0 = {
  130932. _vq_quantthresh__8u1__p1_0,
  130933. _vq_quantmap__8u1__p1_0,
  130934. 3,
  130935. 3
  130936. };
  130937. static static_codebook _8u1__p1_0 = {
  130938. 4, 81,
  130939. _vq_lengthlist__8u1__p1_0,
  130940. 1, -535822336, 1611661312, 2, 0,
  130941. _vq_quantlist__8u1__p1_0,
  130942. NULL,
  130943. &_vq_auxt__8u1__p1_0,
  130944. NULL,
  130945. 0
  130946. };
  130947. static long _vq_quantlist__8u1__p2_0[] = {
  130948. 1,
  130949. 0,
  130950. 2,
  130951. };
  130952. static long _vq_lengthlist__8u1__p2_0[] = {
  130953. 3, 4, 5, 5, 6, 6, 5, 6, 6, 5, 7, 6, 6, 7, 8, 6,
  130954. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 7, 8,
  130955. 8, 6, 7, 7, 6, 8, 7, 7, 7, 9, 8, 9, 9, 6, 7, 8,
  130956. 7, 9, 7, 8, 9, 9, 5, 6, 6, 6, 7, 7, 7, 8, 8, 6,
  130957. 8, 7, 8, 9, 9, 7, 7, 9, 6, 7, 8, 8, 9, 9, 7, 9,
  130958. 7,
  130959. };
  130960. static float _vq_quantthresh__8u1__p2_0[] = {
  130961. -0.5, 0.5,
  130962. };
  130963. static long _vq_quantmap__8u1__p2_0[] = {
  130964. 1, 0, 2,
  130965. };
  130966. static encode_aux_threshmatch _vq_auxt__8u1__p2_0 = {
  130967. _vq_quantthresh__8u1__p2_0,
  130968. _vq_quantmap__8u1__p2_0,
  130969. 3,
  130970. 3
  130971. };
  130972. static static_codebook _8u1__p2_0 = {
  130973. 4, 81,
  130974. _vq_lengthlist__8u1__p2_0,
  130975. 1, -535822336, 1611661312, 2, 0,
  130976. _vq_quantlist__8u1__p2_0,
  130977. NULL,
  130978. &_vq_auxt__8u1__p2_0,
  130979. NULL,
  130980. 0
  130981. };
  130982. static long _vq_quantlist__8u1__p3_0[] = {
  130983. 2,
  130984. 1,
  130985. 3,
  130986. 0,
  130987. 4,
  130988. };
  130989. static long _vq_lengthlist__8u1__p3_0[] = {
  130990. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  130991. 10, 9,11,11, 9, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  130992. 10,11,11, 8, 9,10,11,11,10,11,11,12,12,10,11,11,
  130993. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  130994. 11,10,11,11,12,12,10,11,11,12,12, 9,11,11,14,13,
  130995. 10,12,11,14,14,10,12,11,14,13,12,13,13,15,14,12,
  130996. 13,13,15,14, 8,11,11,13,14,10,11,12,13,15,10,11,
  130997. 12,14,14,12,13,13,14,15,12,13,13,14,15, 5, 8, 8,
  130998. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  130999. 13,11,12,12,13,14, 8,10,10,12,12, 9,11,12,13,14,
  131000. 10,12,12,13,13,12,12,13,14,14,11,13,13,15,15, 7,
  131001. 10,10,12,12, 9,12,11,14,12,10,11,12,13,14,12,13,
  131002. 12,14,14,12,13,13,15,16,10,12,12,15,14,11,12,13,
  131003. 15,15,11,13,13,15,16,14,14,15,15,16,13,14,15,17,
  131004. 15, 9,12,12,14,15,11,13,12,15,15,11,13,13,15,15,
  131005. 13,14,13,15,14,13,14,14,17, 0, 5, 8, 8,11,11, 8,
  131006. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  131007. 12,14,14, 7,10,10,12,12,10,12,12,13,13, 9,11,12,
  131008. 12,13,11,12,13,15,15,11,12,13,14,15, 8,10,10,12,
  131009. 12,10,12,11,13,13,10,12,11,13,13,11,13,13,15,14,
  131010. 12,13,12,15,13, 9,12,12,14,14,11,13,13,16,15,11,
  131011. 12,13,16,15,13,14,15,16,16,13,13,15,15,16,10,12,
  131012. 12,15,14,11,13,13,14,16,11,13,13,15,16,13,15,15,
  131013. 16,17,13,15,14,16,15, 8,11,11,14,15,10,12,12,15,
  131014. 15,10,12,12,15,16,14,15,15,16,17,13,14,14,16,16,
  131015. 9,12,12,15,15,11,13,14,15,17,11,13,13,15,16,14,
  131016. 15,16,19,17,13,15,15, 0,17, 9,12,12,15,15,11,14,
  131017. 13,16,15,11,13,13,15,16,15,15,15,18,17,13,15,15,
  131018. 17,17,11,15,14,18,16,12,14,15,17,17,12,15,15,18,
  131019. 18,15,15,16,15,19,14,16,16, 0, 0,11,14,14,16,17,
  131020. 12,15,14,18,17,12,15,15,18,18,15,17,15,18,16,14,
  131021. 16,16,18,18, 7,11,11,14,14,10,12,12,15,15,10,12,
  131022. 13,15,15,13,14,15,16,16,14,15,15,18,18, 9,12,12,
  131023. 15,15,11,13,13,16,15,11,12,13,16,16,14,15,15,17,
  131024. 16,15,16,16,17,17, 9,12,12,15,15,11,13,13,15,17,
  131025. 11,14,13,16,15,13,15,15,17,17,15,15,15,18,17,11,
  131026. 14,14,17,15,12,14,15,17,18,13,13,15,17,17,14,16,
  131027. 16,19,18,16,15,17,17, 0,11,14,14,17,17,12,15,15,
  131028. 18, 0,12,15,14,18,16,14,17,17,19, 0,16,18,15, 0,
  131029. 16,
  131030. };
  131031. static float _vq_quantthresh__8u1__p3_0[] = {
  131032. -1.5, -0.5, 0.5, 1.5,
  131033. };
  131034. static long _vq_quantmap__8u1__p3_0[] = {
  131035. 3, 1, 0, 2, 4,
  131036. };
  131037. static encode_aux_threshmatch _vq_auxt__8u1__p3_0 = {
  131038. _vq_quantthresh__8u1__p3_0,
  131039. _vq_quantmap__8u1__p3_0,
  131040. 5,
  131041. 5
  131042. };
  131043. static static_codebook _8u1__p3_0 = {
  131044. 4, 625,
  131045. _vq_lengthlist__8u1__p3_0,
  131046. 1, -533725184, 1611661312, 3, 0,
  131047. _vq_quantlist__8u1__p3_0,
  131048. NULL,
  131049. &_vq_auxt__8u1__p3_0,
  131050. NULL,
  131051. 0
  131052. };
  131053. static long _vq_quantlist__8u1__p4_0[] = {
  131054. 2,
  131055. 1,
  131056. 3,
  131057. 0,
  131058. 4,
  131059. };
  131060. static long _vq_lengthlist__8u1__p4_0[] = {
  131061. 4, 5, 5, 9, 9, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 9,
  131062. 9, 9,11,11, 9, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 7,
  131063. 8, 9,10, 7, 7, 8, 9,10, 9, 9,10,10,11, 9, 9,10,
  131064. 10,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 7,10,
  131065. 9, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  131066. 9,10,10,12,11, 9,10,10,12,12,11,11,12,12,13,11,
  131067. 11,12,12,13, 9, 9,10,12,11, 9,10,10,12,12,10,10,
  131068. 10,12,12,11,12,11,13,12,11,12,11,13,12, 6, 7, 7,
  131069. 9, 9, 7, 8, 8,10,10, 7, 8, 7,10, 9,10,10,10,12,
  131070. 12,10,10,10,12,11, 7, 8, 7,10,10, 7, 7, 9,10,11,
  131071. 8, 9, 9,11,10,10,10,11,10,12,10,10,11,12,12, 7,
  131072. 8, 8,10,10, 7, 9, 8,11,10, 8, 8, 9,11,11,10,11,
  131073. 10,12,11,10,11,11,12,12, 9,10,10,12,12, 9,10,10,
  131074. 12,12,10,11,11,13,12,11,10,12,10,14,12,12,12,13,
  131075. 14, 9,10,10,12,12, 9,11,10,12,12,10,11,11,12,12,
  131076. 11,12,11,14,12,12,12,12,14,14, 5, 7, 7, 9, 9, 7,
  131077. 7, 7, 9,10, 7, 8, 8,10,10,10,10,10,11,11,10,10,
  131078. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  131079. 10,11,10,10,10,11,12,10,10,11,11,13, 6, 7, 8,10,
  131080. 10, 8, 9, 9,10,10, 7, 9, 7,11,10,10,11,10,12,12,
  131081. 10,11,10,12,10, 9,10,10,12,12,10,11,11,13,12, 9,
  131082. 10,10,12,12,12,12,12,14,13,11,11,12,11,14, 9,10,
  131083. 10,11,12,10,11,11,12,13, 9,10,10,12,12,12,12,12,
  131084. 14,13,11,12,10,14,11, 9, 9,10,11,12, 9,10,10,12,
  131085. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,13,12,
  131086. 9,10, 9,12,12, 9,10,11,12,13,10,11,10,13,11,12,
  131087. 12,13,13,14,12,12,12,13,13, 9,10,10,12,12,10,11,
  131088. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,12,
  131089. 13,14,11,12,11,14,13,10,10,11,13,13,12,12,12,14,
  131090. 13,12,10,14,10,15,13,14,14,14,14,11,11,12,13,14,
  131091. 10,12,11,13,13,12,12,12,13,15,12,13,11,15,12,13,
  131092. 13,14,14,14, 9,10, 9,12,12, 9,10,10,12,12,10,10,
  131093. 10,12,12,11,11,12,12,13,12,12,12,14,14, 9,10,10,
  131094. 12,12,10,11,10,13,12,10,10,11,12,13,12,12,12,14,
  131095. 13,12,12,13,13,14, 9,10,10,12,13,10,10,11,11,12,
  131096. 9,11,10,13,12,12,12,12,13,14,12,13,12,14,13,11,
  131097. 12,11,13,13,12,13,12,14,13,10,11,12,13,13,13,13,
  131098. 13,14,15,12,11,14,12,14,11,11,12,12,13,12,12,12,
  131099. 13,14,10,12,10,14,13,13,13,13,14,15,12,14,11,15,
  131100. 10,
  131101. };
  131102. static float _vq_quantthresh__8u1__p4_0[] = {
  131103. -1.5, -0.5, 0.5, 1.5,
  131104. };
  131105. static long _vq_quantmap__8u1__p4_0[] = {
  131106. 3, 1, 0, 2, 4,
  131107. };
  131108. static encode_aux_threshmatch _vq_auxt__8u1__p4_0 = {
  131109. _vq_quantthresh__8u1__p4_0,
  131110. _vq_quantmap__8u1__p4_0,
  131111. 5,
  131112. 5
  131113. };
  131114. static static_codebook _8u1__p4_0 = {
  131115. 4, 625,
  131116. _vq_lengthlist__8u1__p4_0,
  131117. 1, -533725184, 1611661312, 3, 0,
  131118. _vq_quantlist__8u1__p4_0,
  131119. NULL,
  131120. &_vq_auxt__8u1__p4_0,
  131121. NULL,
  131122. 0
  131123. };
  131124. static long _vq_quantlist__8u1__p5_0[] = {
  131125. 4,
  131126. 3,
  131127. 5,
  131128. 2,
  131129. 6,
  131130. 1,
  131131. 7,
  131132. 0,
  131133. 8,
  131134. };
  131135. static long _vq_lengthlist__8u1__p5_0[] = {
  131136. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  131137. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  131138. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  131139. 9, 9,10,10,12,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  131140. 10,10,11,11,11,11,13,12, 9,10,10,11,11,12,12,12,
  131141. 13,
  131142. };
  131143. static float _vq_quantthresh__8u1__p5_0[] = {
  131144. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131145. };
  131146. static long _vq_quantmap__8u1__p5_0[] = {
  131147. 7, 5, 3, 1, 0, 2, 4, 6,
  131148. 8,
  131149. };
  131150. static encode_aux_threshmatch _vq_auxt__8u1__p5_0 = {
  131151. _vq_quantthresh__8u1__p5_0,
  131152. _vq_quantmap__8u1__p5_0,
  131153. 9,
  131154. 9
  131155. };
  131156. static static_codebook _8u1__p5_0 = {
  131157. 2, 81,
  131158. _vq_lengthlist__8u1__p5_0,
  131159. 1, -531628032, 1611661312, 4, 0,
  131160. _vq_quantlist__8u1__p5_0,
  131161. NULL,
  131162. &_vq_auxt__8u1__p5_0,
  131163. NULL,
  131164. 0
  131165. };
  131166. static long _vq_quantlist__8u1__p6_0[] = {
  131167. 4,
  131168. 3,
  131169. 5,
  131170. 2,
  131171. 6,
  131172. 1,
  131173. 7,
  131174. 0,
  131175. 8,
  131176. };
  131177. static long _vq_lengthlist__8u1__p6_0[] = {
  131178. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 5, 6, 6, 7, 7,
  131179. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  131180. 8, 8, 9, 9, 6, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  131181. 8, 8, 8, 9,10,10, 7, 7, 7, 8, 8, 9, 8,10,10, 9,
  131182. 9, 9, 9, 9,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131183. 10,
  131184. };
  131185. static float _vq_quantthresh__8u1__p6_0[] = {
  131186. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131187. };
  131188. static long _vq_quantmap__8u1__p6_0[] = {
  131189. 7, 5, 3, 1, 0, 2, 4, 6,
  131190. 8,
  131191. };
  131192. static encode_aux_threshmatch _vq_auxt__8u1__p6_0 = {
  131193. _vq_quantthresh__8u1__p6_0,
  131194. _vq_quantmap__8u1__p6_0,
  131195. 9,
  131196. 9
  131197. };
  131198. static static_codebook _8u1__p6_0 = {
  131199. 2, 81,
  131200. _vq_lengthlist__8u1__p6_0,
  131201. 1, -531628032, 1611661312, 4, 0,
  131202. _vq_quantlist__8u1__p6_0,
  131203. NULL,
  131204. &_vq_auxt__8u1__p6_0,
  131205. NULL,
  131206. 0
  131207. };
  131208. static long _vq_quantlist__8u1__p7_0[] = {
  131209. 1,
  131210. 0,
  131211. 2,
  131212. };
  131213. static long _vq_lengthlist__8u1__p7_0[] = {
  131214. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,10,10, 8,
  131215. 10,10, 5, 9, 9, 7,10,10, 8,10,10, 4,10,10, 9,12,
  131216. 12, 9,11,11, 7,12,11,10,11,13,10,13,13, 7,12,12,
  131217. 10,13,12,10,13,13, 4,10,10, 9,12,12, 9,12,12, 7,
  131218. 12,12,10,13,13,10,12,13, 7,11,12,10,13,13,10,13,
  131219. 11,
  131220. };
  131221. static float _vq_quantthresh__8u1__p7_0[] = {
  131222. -5.5, 5.5,
  131223. };
  131224. static long _vq_quantmap__8u1__p7_0[] = {
  131225. 1, 0, 2,
  131226. };
  131227. static encode_aux_threshmatch _vq_auxt__8u1__p7_0 = {
  131228. _vq_quantthresh__8u1__p7_0,
  131229. _vq_quantmap__8u1__p7_0,
  131230. 3,
  131231. 3
  131232. };
  131233. static static_codebook _8u1__p7_0 = {
  131234. 4, 81,
  131235. _vq_lengthlist__8u1__p7_0,
  131236. 1, -529137664, 1618345984, 2, 0,
  131237. _vq_quantlist__8u1__p7_0,
  131238. NULL,
  131239. &_vq_auxt__8u1__p7_0,
  131240. NULL,
  131241. 0
  131242. };
  131243. static long _vq_quantlist__8u1__p7_1[] = {
  131244. 5,
  131245. 4,
  131246. 6,
  131247. 3,
  131248. 7,
  131249. 2,
  131250. 8,
  131251. 1,
  131252. 9,
  131253. 0,
  131254. 10,
  131255. };
  131256. static long _vq_lengthlist__8u1__p7_1[] = {
  131257. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  131258. 8, 8, 9, 9, 9, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 9,
  131259. 9, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  131260. 8, 8, 8, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131261. 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  131262. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  131263. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  131264. 9, 9, 9, 9, 9,10,10,10,10,
  131265. };
  131266. static float _vq_quantthresh__8u1__p7_1[] = {
  131267. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131268. 3.5, 4.5,
  131269. };
  131270. static long _vq_quantmap__8u1__p7_1[] = {
  131271. 9, 7, 5, 3, 1, 0, 2, 4,
  131272. 6, 8, 10,
  131273. };
  131274. static encode_aux_threshmatch _vq_auxt__8u1__p7_1 = {
  131275. _vq_quantthresh__8u1__p7_1,
  131276. _vq_quantmap__8u1__p7_1,
  131277. 11,
  131278. 11
  131279. };
  131280. static static_codebook _8u1__p7_1 = {
  131281. 2, 121,
  131282. _vq_lengthlist__8u1__p7_1,
  131283. 1, -531365888, 1611661312, 4, 0,
  131284. _vq_quantlist__8u1__p7_1,
  131285. NULL,
  131286. &_vq_auxt__8u1__p7_1,
  131287. NULL,
  131288. 0
  131289. };
  131290. static long _vq_quantlist__8u1__p8_0[] = {
  131291. 5,
  131292. 4,
  131293. 6,
  131294. 3,
  131295. 7,
  131296. 2,
  131297. 8,
  131298. 1,
  131299. 9,
  131300. 0,
  131301. 10,
  131302. };
  131303. static long _vq_lengthlist__8u1__p8_0[] = {
  131304. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  131305. 9, 9,11,11,13,12, 4, 6, 6, 7, 7, 9, 9,11,11,12,
  131306. 12, 6, 7, 7, 9, 9,11,11,12,12,13,13, 6, 7, 7, 9,
  131307. 9,11,11,12,12,13,13, 8, 9, 9,11,11,12,12,13,13,
  131308. 14,14, 8, 9, 9,11,11,12,12,13,13,14,14, 9,11,11,
  131309. 12,12,13,13,14,14,15,15, 9,11,11,12,12,13,13,14,
  131310. 14,15,14,11,12,12,13,13,14,14,15,15,16,16,11,12,
  131311. 12,13,13,14,14,15,15,15,15,
  131312. };
  131313. static float _vq_quantthresh__8u1__p8_0[] = {
  131314. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  131315. 38.5, 49.5,
  131316. };
  131317. static long _vq_quantmap__8u1__p8_0[] = {
  131318. 9, 7, 5, 3, 1, 0, 2, 4,
  131319. 6, 8, 10,
  131320. };
  131321. static encode_aux_threshmatch _vq_auxt__8u1__p8_0 = {
  131322. _vq_quantthresh__8u1__p8_0,
  131323. _vq_quantmap__8u1__p8_0,
  131324. 11,
  131325. 11
  131326. };
  131327. static static_codebook _8u1__p8_0 = {
  131328. 2, 121,
  131329. _vq_lengthlist__8u1__p8_0,
  131330. 1, -524582912, 1618345984, 4, 0,
  131331. _vq_quantlist__8u1__p8_0,
  131332. NULL,
  131333. &_vq_auxt__8u1__p8_0,
  131334. NULL,
  131335. 0
  131336. };
  131337. static long _vq_quantlist__8u1__p8_1[] = {
  131338. 5,
  131339. 4,
  131340. 6,
  131341. 3,
  131342. 7,
  131343. 2,
  131344. 8,
  131345. 1,
  131346. 9,
  131347. 0,
  131348. 10,
  131349. };
  131350. static long _vq_lengthlist__8u1__p8_1[] = {
  131351. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 6, 6, 7, 7,
  131352. 7, 7, 8, 8, 8, 8, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  131353. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  131354. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  131355. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131356. 8, 8, 8, 8, 9, 8, 9, 9, 7, 8, 8, 8, 8, 8, 8, 9,
  131357. 8, 9, 9, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8,
  131358. 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131359. };
  131360. static float _vq_quantthresh__8u1__p8_1[] = {
  131361. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131362. 3.5, 4.5,
  131363. };
  131364. static long _vq_quantmap__8u1__p8_1[] = {
  131365. 9, 7, 5, 3, 1, 0, 2, 4,
  131366. 6, 8, 10,
  131367. };
  131368. static encode_aux_threshmatch _vq_auxt__8u1__p8_1 = {
  131369. _vq_quantthresh__8u1__p8_1,
  131370. _vq_quantmap__8u1__p8_1,
  131371. 11,
  131372. 11
  131373. };
  131374. static static_codebook _8u1__p8_1 = {
  131375. 2, 121,
  131376. _vq_lengthlist__8u1__p8_1,
  131377. 1, -531365888, 1611661312, 4, 0,
  131378. _vq_quantlist__8u1__p8_1,
  131379. NULL,
  131380. &_vq_auxt__8u1__p8_1,
  131381. NULL,
  131382. 0
  131383. };
  131384. static long _vq_quantlist__8u1__p9_0[] = {
  131385. 7,
  131386. 6,
  131387. 8,
  131388. 5,
  131389. 9,
  131390. 4,
  131391. 10,
  131392. 3,
  131393. 11,
  131394. 2,
  131395. 12,
  131396. 1,
  131397. 13,
  131398. 0,
  131399. 14,
  131400. };
  131401. static long _vq_lengthlist__8u1__p9_0[] = {
  131402. 1, 4, 4,11,11,11,11,11,11,11,11,11,11,11,11, 3,
  131403. 11, 8,11,11,11,11,11,11,11,11,11,11,11,11, 3, 9,
  131404. 9,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131405. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131406. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131407. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131408. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131409. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131410. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131411. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131412. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131413. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131414. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  131415. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131416. 10,
  131417. };
  131418. static float _vq_quantthresh__8u1__p9_0[] = {
  131419. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  131420. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  131421. };
  131422. static long _vq_quantmap__8u1__p9_0[] = {
  131423. 13, 11, 9, 7, 5, 3, 1, 0,
  131424. 2, 4, 6, 8, 10, 12, 14,
  131425. };
  131426. static encode_aux_threshmatch _vq_auxt__8u1__p9_0 = {
  131427. _vq_quantthresh__8u1__p9_0,
  131428. _vq_quantmap__8u1__p9_0,
  131429. 15,
  131430. 15
  131431. };
  131432. static static_codebook _8u1__p9_0 = {
  131433. 2, 225,
  131434. _vq_lengthlist__8u1__p9_0,
  131435. 1, -514071552, 1627381760, 4, 0,
  131436. _vq_quantlist__8u1__p9_0,
  131437. NULL,
  131438. &_vq_auxt__8u1__p9_0,
  131439. NULL,
  131440. 0
  131441. };
  131442. static long _vq_quantlist__8u1__p9_1[] = {
  131443. 7,
  131444. 6,
  131445. 8,
  131446. 5,
  131447. 9,
  131448. 4,
  131449. 10,
  131450. 3,
  131451. 11,
  131452. 2,
  131453. 12,
  131454. 1,
  131455. 13,
  131456. 0,
  131457. 14,
  131458. };
  131459. static long _vq_lengthlist__8u1__p9_1[] = {
  131460. 1, 4, 4, 7, 7, 9, 9, 7, 7, 8, 8,10,10,11,11, 4,
  131461. 7, 7, 9, 9,10,10, 8, 8,10,10,10,11,10,11, 4, 7,
  131462. 7, 9, 9,10,10, 8, 8,10, 9,11,11,11,11, 7, 9, 9,
  131463. 12,12,11,12,10,10,11,10,12,11,11,11, 7, 9, 9,11,
  131464. 11,13,12, 9, 9,11,10,11,11,12,11, 9,10,10,12,12,
  131465. 14,14,10,10,11,12,12,11,11,11, 9,10,11,11,13,14,
  131466. 13,10,11,11,11,12,11,12,12, 7, 8, 8,10, 9,11,10,
  131467. 11,12,12,11,12,14,12,13, 7, 8, 8, 9,10,10,11,12,
  131468. 12,12,11,12,12,12,13, 9, 9, 9,11,11,13,12,12,12,
  131469. 12,11,12,12,13,12, 8,10,10,11,10,11,12,12,12,12,
  131470. 12,12,14,12,12, 9,11,11,11,12,12,12,12,13,13,12,
  131471. 12,13,13,12,10,11,11,12,11,12,12,12,11,12,13,12,
  131472. 12,12,13,11,11,12,12,12,13,12,12,11,12,13,13,12,
  131473. 12,13,12,11,12,12,13,13,12,13,12,13,13,13,13,14,
  131474. 13,
  131475. };
  131476. static float _vq_quantthresh__8u1__p9_1[] = {
  131477. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  131478. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  131479. };
  131480. static long _vq_quantmap__8u1__p9_1[] = {
  131481. 13, 11, 9, 7, 5, 3, 1, 0,
  131482. 2, 4, 6, 8, 10, 12, 14,
  131483. };
  131484. static encode_aux_threshmatch _vq_auxt__8u1__p9_1 = {
  131485. _vq_quantthresh__8u1__p9_1,
  131486. _vq_quantmap__8u1__p9_1,
  131487. 15,
  131488. 15
  131489. };
  131490. static static_codebook _8u1__p9_1 = {
  131491. 2, 225,
  131492. _vq_lengthlist__8u1__p9_1,
  131493. 1, -522338304, 1620115456, 4, 0,
  131494. _vq_quantlist__8u1__p9_1,
  131495. NULL,
  131496. &_vq_auxt__8u1__p9_1,
  131497. NULL,
  131498. 0
  131499. };
  131500. static long _vq_quantlist__8u1__p9_2[] = {
  131501. 8,
  131502. 7,
  131503. 9,
  131504. 6,
  131505. 10,
  131506. 5,
  131507. 11,
  131508. 4,
  131509. 12,
  131510. 3,
  131511. 13,
  131512. 2,
  131513. 14,
  131514. 1,
  131515. 15,
  131516. 0,
  131517. 16,
  131518. };
  131519. static long _vq_lengthlist__8u1__p9_2[] = {
  131520. 2, 5, 4, 6, 6, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  131521. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  131522. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  131523. 9, 9, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  131524. 9,10,10, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  131525. 9, 9, 9,10,10, 8, 8, 8, 9, 9, 9, 9,10,10,10, 9,
  131526. 10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  131527. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,
  131528. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131529. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  131530. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  131531. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  131532. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  131533. 9,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  131534. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10,
  131535. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  131536. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131537. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131538. 10,
  131539. };
  131540. static float _vq_quantthresh__8u1__p9_2[] = {
  131541. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  131542. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  131543. };
  131544. static long _vq_quantmap__8u1__p9_2[] = {
  131545. 15, 13, 11, 9, 7, 5, 3, 1,
  131546. 0, 2, 4, 6, 8, 10, 12, 14,
  131547. 16,
  131548. };
  131549. static encode_aux_threshmatch _vq_auxt__8u1__p9_2 = {
  131550. _vq_quantthresh__8u1__p9_2,
  131551. _vq_quantmap__8u1__p9_2,
  131552. 17,
  131553. 17
  131554. };
  131555. static static_codebook _8u1__p9_2 = {
  131556. 2, 289,
  131557. _vq_lengthlist__8u1__p9_2,
  131558. 1, -529530880, 1611661312, 5, 0,
  131559. _vq_quantlist__8u1__p9_2,
  131560. NULL,
  131561. &_vq_auxt__8u1__p9_2,
  131562. NULL,
  131563. 0
  131564. };
  131565. static long _huff_lengthlist__8u1__single[] = {
  131566. 4, 7,13, 9,15, 9,16, 8,10,13, 7, 5, 8, 6, 9, 7,
  131567. 10, 7,10,11,11, 6, 7, 8, 8, 9, 9, 9,12,16, 8, 5,
  131568. 8, 6, 8, 6, 9, 7,10,12,11, 7, 7, 7, 6, 7, 7, 7,
  131569. 11,15, 7, 5, 8, 6, 7, 5, 7, 6, 9,13,13, 9, 9, 8,
  131570. 6, 6, 5, 5, 9,14, 8, 6, 8, 6, 6, 4, 5, 3, 5,13,
  131571. 9, 9,11, 8,10, 7, 8, 4, 5,12,11,16,17,15,17,12,
  131572. 13, 8, 8,15,
  131573. };
  131574. static static_codebook _huff_book__8u1__single = {
  131575. 2, 100,
  131576. _huff_lengthlist__8u1__single,
  131577. 0, 0, 0, 0, 0,
  131578. NULL,
  131579. NULL,
  131580. NULL,
  131581. NULL,
  131582. 0
  131583. };
  131584. static long _huff_lengthlist__44u0__long[] = {
  131585. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  131586. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  131587. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  131588. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  131589. };
  131590. static static_codebook _huff_book__44u0__long = {
  131591. 2, 64,
  131592. _huff_lengthlist__44u0__long,
  131593. 0, 0, 0, 0, 0,
  131594. NULL,
  131595. NULL,
  131596. NULL,
  131597. NULL,
  131598. 0
  131599. };
  131600. static long _vq_quantlist__44u0__p1_0[] = {
  131601. 1,
  131602. 0,
  131603. 2,
  131604. };
  131605. static long _vq_lengthlist__44u0__p1_0[] = {
  131606. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  131607. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  131608. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  131609. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  131610. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  131611. 13,
  131612. };
  131613. static float _vq_quantthresh__44u0__p1_0[] = {
  131614. -0.5, 0.5,
  131615. };
  131616. static long _vq_quantmap__44u0__p1_0[] = {
  131617. 1, 0, 2,
  131618. };
  131619. static encode_aux_threshmatch _vq_auxt__44u0__p1_0 = {
  131620. _vq_quantthresh__44u0__p1_0,
  131621. _vq_quantmap__44u0__p1_0,
  131622. 3,
  131623. 3
  131624. };
  131625. static static_codebook _44u0__p1_0 = {
  131626. 4, 81,
  131627. _vq_lengthlist__44u0__p1_0,
  131628. 1, -535822336, 1611661312, 2, 0,
  131629. _vq_quantlist__44u0__p1_0,
  131630. NULL,
  131631. &_vq_auxt__44u0__p1_0,
  131632. NULL,
  131633. 0
  131634. };
  131635. static long _vq_quantlist__44u0__p2_0[] = {
  131636. 1,
  131637. 0,
  131638. 2,
  131639. };
  131640. static long _vq_lengthlist__44u0__p2_0[] = {
  131641. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  131642. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  131643. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  131644. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  131645. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  131646. 9,
  131647. };
  131648. static float _vq_quantthresh__44u0__p2_0[] = {
  131649. -0.5, 0.5,
  131650. };
  131651. static long _vq_quantmap__44u0__p2_0[] = {
  131652. 1, 0, 2,
  131653. };
  131654. static encode_aux_threshmatch _vq_auxt__44u0__p2_0 = {
  131655. _vq_quantthresh__44u0__p2_0,
  131656. _vq_quantmap__44u0__p2_0,
  131657. 3,
  131658. 3
  131659. };
  131660. static static_codebook _44u0__p2_0 = {
  131661. 4, 81,
  131662. _vq_lengthlist__44u0__p2_0,
  131663. 1, -535822336, 1611661312, 2, 0,
  131664. _vq_quantlist__44u0__p2_0,
  131665. NULL,
  131666. &_vq_auxt__44u0__p2_0,
  131667. NULL,
  131668. 0
  131669. };
  131670. static long _vq_quantlist__44u0__p3_0[] = {
  131671. 2,
  131672. 1,
  131673. 3,
  131674. 0,
  131675. 4,
  131676. };
  131677. static long _vq_lengthlist__44u0__p3_0[] = {
  131678. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  131679. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  131680. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  131681. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  131682. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  131683. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  131684. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  131685. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  131686. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  131687. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  131688. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  131689. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  131690. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  131691. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  131692. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  131693. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  131694. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  131695. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  131696. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  131697. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  131698. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  131699. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  131700. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  131701. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  131702. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  131703. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  131704. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  131705. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  131706. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  131707. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  131708. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  131709. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  131710. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  131711. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  131712. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  131713. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  131714. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  131715. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  131716. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  131717. 19,
  131718. };
  131719. static float _vq_quantthresh__44u0__p3_0[] = {
  131720. -1.5, -0.5, 0.5, 1.5,
  131721. };
  131722. static long _vq_quantmap__44u0__p3_0[] = {
  131723. 3, 1, 0, 2, 4,
  131724. };
  131725. static encode_aux_threshmatch _vq_auxt__44u0__p3_0 = {
  131726. _vq_quantthresh__44u0__p3_0,
  131727. _vq_quantmap__44u0__p3_0,
  131728. 5,
  131729. 5
  131730. };
  131731. static static_codebook _44u0__p3_0 = {
  131732. 4, 625,
  131733. _vq_lengthlist__44u0__p3_0,
  131734. 1, -533725184, 1611661312, 3, 0,
  131735. _vq_quantlist__44u0__p3_0,
  131736. NULL,
  131737. &_vq_auxt__44u0__p3_0,
  131738. NULL,
  131739. 0
  131740. };
  131741. static long _vq_quantlist__44u0__p4_0[] = {
  131742. 2,
  131743. 1,
  131744. 3,
  131745. 0,
  131746. 4,
  131747. };
  131748. static long _vq_lengthlist__44u0__p4_0[] = {
  131749. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  131750. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  131751. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  131752. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  131753. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  131754. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  131755. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  131756. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  131757. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  131758. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  131759. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  131760. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  131761. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  131762. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  131763. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  131764. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  131765. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  131766. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  131767. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  131768. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  131769. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  131770. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  131771. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  131772. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  131773. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  131774. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  131775. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  131776. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  131777. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  131778. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  131779. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  131780. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  131781. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  131782. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  131783. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  131784. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  131785. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  131786. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  131787. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  131788. 12,
  131789. };
  131790. static float _vq_quantthresh__44u0__p4_0[] = {
  131791. -1.5, -0.5, 0.5, 1.5,
  131792. };
  131793. static long _vq_quantmap__44u0__p4_0[] = {
  131794. 3, 1, 0, 2, 4,
  131795. };
  131796. static encode_aux_threshmatch _vq_auxt__44u0__p4_0 = {
  131797. _vq_quantthresh__44u0__p4_0,
  131798. _vq_quantmap__44u0__p4_0,
  131799. 5,
  131800. 5
  131801. };
  131802. static static_codebook _44u0__p4_0 = {
  131803. 4, 625,
  131804. _vq_lengthlist__44u0__p4_0,
  131805. 1, -533725184, 1611661312, 3, 0,
  131806. _vq_quantlist__44u0__p4_0,
  131807. NULL,
  131808. &_vq_auxt__44u0__p4_0,
  131809. NULL,
  131810. 0
  131811. };
  131812. static long _vq_quantlist__44u0__p5_0[] = {
  131813. 4,
  131814. 3,
  131815. 5,
  131816. 2,
  131817. 6,
  131818. 1,
  131819. 7,
  131820. 0,
  131821. 8,
  131822. };
  131823. static long _vq_lengthlist__44u0__p5_0[] = {
  131824. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  131825. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  131826. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  131827. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  131828. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  131829. 12,
  131830. };
  131831. static float _vq_quantthresh__44u0__p5_0[] = {
  131832. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131833. };
  131834. static long _vq_quantmap__44u0__p5_0[] = {
  131835. 7, 5, 3, 1, 0, 2, 4, 6,
  131836. 8,
  131837. };
  131838. static encode_aux_threshmatch _vq_auxt__44u0__p5_0 = {
  131839. _vq_quantthresh__44u0__p5_0,
  131840. _vq_quantmap__44u0__p5_0,
  131841. 9,
  131842. 9
  131843. };
  131844. static static_codebook _44u0__p5_0 = {
  131845. 2, 81,
  131846. _vq_lengthlist__44u0__p5_0,
  131847. 1, -531628032, 1611661312, 4, 0,
  131848. _vq_quantlist__44u0__p5_0,
  131849. NULL,
  131850. &_vq_auxt__44u0__p5_0,
  131851. NULL,
  131852. 0
  131853. };
  131854. static long _vq_quantlist__44u0__p6_0[] = {
  131855. 6,
  131856. 5,
  131857. 7,
  131858. 4,
  131859. 8,
  131860. 3,
  131861. 9,
  131862. 2,
  131863. 10,
  131864. 1,
  131865. 11,
  131866. 0,
  131867. 12,
  131868. };
  131869. static long _vq_lengthlist__44u0__p6_0[] = {
  131870. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  131871. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  131872. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  131873. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  131874. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  131875. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  131876. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  131877. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  131878. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  131879. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  131880. 15,17,16,17,18,17,17,18, 0,
  131881. };
  131882. static float _vq_quantthresh__44u0__p6_0[] = {
  131883. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  131884. 12.5, 17.5, 22.5, 27.5,
  131885. };
  131886. static long _vq_quantmap__44u0__p6_0[] = {
  131887. 11, 9, 7, 5, 3, 1, 0, 2,
  131888. 4, 6, 8, 10, 12,
  131889. };
  131890. static encode_aux_threshmatch _vq_auxt__44u0__p6_0 = {
  131891. _vq_quantthresh__44u0__p6_0,
  131892. _vq_quantmap__44u0__p6_0,
  131893. 13,
  131894. 13
  131895. };
  131896. static static_codebook _44u0__p6_0 = {
  131897. 2, 169,
  131898. _vq_lengthlist__44u0__p6_0,
  131899. 1, -526516224, 1616117760, 4, 0,
  131900. _vq_quantlist__44u0__p6_0,
  131901. NULL,
  131902. &_vq_auxt__44u0__p6_0,
  131903. NULL,
  131904. 0
  131905. };
  131906. static long _vq_quantlist__44u0__p6_1[] = {
  131907. 2,
  131908. 1,
  131909. 3,
  131910. 0,
  131911. 4,
  131912. };
  131913. static long _vq_lengthlist__44u0__p6_1[] = {
  131914. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  131915. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  131916. };
  131917. static float _vq_quantthresh__44u0__p6_1[] = {
  131918. -1.5, -0.5, 0.5, 1.5,
  131919. };
  131920. static long _vq_quantmap__44u0__p6_1[] = {
  131921. 3, 1, 0, 2, 4,
  131922. };
  131923. static encode_aux_threshmatch _vq_auxt__44u0__p6_1 = {
  131924. _vq_quantthresh__44u0__p6_1,
  131925. _vq_quantmap__44u0__p6_1,
  131926. 5,
  131927. 5
  131928. };
  131929. static static_codebook _44u0__p6_1 = {
  131930. 2, 25,
  131931. _vq_lengthlist__44u0__p6_1,
  131932. 1, -533725184, 1611661312, 3, 0,
  131933. _vq_quantlist__44u0__p6_1,
  131934. NULL,
  131935. &_vq_auxt__44u0__p6_1,
  131936. NULL,
  131937. 0
  131938. };
  131939. static long _vq_quantlist__44u0__p7_0[] = {
  131940. 2,
  131941. 1,
  131942. 3,
  131943. 0,
  131944. 4,
  131945. };
  131946. static long _vq_lengthlist__44u0__p7_0[] = {
  131947. 1, 4, 4,11,11, 9,11,11,11,11,11,11,11,11,11,11,
  131948. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131949. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131950. 11,11, 9,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131951. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131952. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131953. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131954. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  131955. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131956. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131957. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131958. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131959. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131960. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131961. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131962. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131963. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131964. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131965. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131966. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131967. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131968. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131969. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131970. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131971. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131972. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131973. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131974. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131975. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131976. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131977. 11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,
  131978. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131979. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131980. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131981. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131982. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131983. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131984. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131985. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131986. 10,
  131987. };
  131988. static float _vq_quantthresh__44u0__p7_0[] = {
  131989. -253.5, -84.5, 84.5, 253.5,
  131990. };
  131991. static long _vq_quantmap__44u0__p7_0[] = {
  131992. 3, 1, 0, 2, 4,
  131993. };
  131994. static encode_aux_threshmatch _vq_auxt__44u0__p7_0 = {
  131995. _vq_quantthresh__44u0__p7_0,
  131996. _vq_quantmap__44u0__p7_0,
  131997. 5,
  131998. 5
  131999. };
  132000. static static_codebook _44u0__p7_0 = {
  132001. 4, 625,
  132002. _vq_lengthlist__44u0__p7_0,
  132003. 1, -518709248, 1626677248, 3, 0,
  132004. _vq_quantlist__44u0__p7_0,
  132005. NULL,
  132006. &_vq_auxt__44u0__p7_0,
  132007. NULL,
  132008. 0
  132009. };
  132010. static long _vq_quantlist__44u0__p7_1[] = {
  132011. 6,
  132012. 5,
  132013. 7,
  132014. 4,
  132015. 8,
  132016. 3,
  132017. 9,
  132018. 2,
  132019. 10,
  132020. 1,
  132021. 11,
  132022. 0,
  132023. 12,
  132024. };
  132025. static long _vq_lengthlist__44u0__p7_1[] = {
  132026. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  132027. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  132028. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  132029. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  132030. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  132031. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  132032. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  132033. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  132034. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  132035. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  132036. 15,15,15,15,15,15,15,15,15,
  132037. };
  132038. static float _vq_quantthresh__44u0__p7_1[] = {
  132039. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132040. 32.5, 45.5, 58.5, 71.5,
  132041. };
  132042. static long _vq_quantmap__44u0__p7_1[] = {
  132043. 11, 9, 7, 5, 3, 1, 0, 2,
  132044. 4, 6, 8, 10, 12,
  132045. };
  132046. static encode_aux_threshmatch _vq_auxt__44u0__p7_1 = {
  132047. _vq_quantthresh__44u0__p7_1,
  132048. _vq_quantmap__44u0__p7_1,
  132049. 13,
  132050. 13
  132051. };
  132052. static static_codebook _44u0__p7_1 = {
  132053. 2, 169,
  132054. _vq_lengthlist__44u0__p7_1,
  132055. 1, -523010048, 1618608128, 4, 0,
  132056. _vq_quantlist__44u0__p7_1,
  132057. NULL,
  132058. &_vq_auxt__44u0__p7_1,
  132059. NULL,
  132060. 0
  132061. };
  132062. static long _vq_quantlist__44u0__p7_2[] = {
  132063. 6,
  132064. 5,
  132065. 7,
  132066. 4,
  132067. 8,
  132068. 3,
  132069. 9,
  132070. 2,
  132071. 10,
  132072. 1,
  132073. 11,
  132074. 0,
  132075. 12,
  132076. };
  132077. static long _vq_lengthlist__44u0__p7_2[] = {
  132078. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  132079. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  132080. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  132081. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132082. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  132083. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  132084. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  132085. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132086. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132087. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  132088. 9, 9, 9,10, 9, 9,10,10, 9,
  132089. };
  132090. static float _vq_quantthresh__44u0__p7_2[] = {
  132091. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  132092. 2.5, 3.5, 4.5, 5.5,
  132093. };
  132094. static long _vq_quantmap__44u0__p7_2[] = {
  132095. 11, 9, 7, 5, 3, 1, 0, 2,
  132096. 4, 6, 8, 10, 12,
  132097. };
  132098. static encode_aux_threshmatch _vq_auxt__44u0__p7_2 = {
  132099. _vq_quantthresh__44u0__p7_2,
  132100. _vq_quantmap__44u0__p7_2,
  132101. 13,
  132102. 13
  132103. };
  132104. static static_codebook _44u0__p7_2 = {
  132105. 2, 169,
  132106. _vq_lengthlist__44u0__p7_2,
  132107. 1, -531103744, 1611661312, 4, 0,
  132108. _vq_quantlist__44u0__p7_2,
  132109. NULL,
  132110. &_vq_auxt__44u0__p7_2,
  132111. NULL,
  132112. 0
  132113. };
  132114. static long _huff_lengthlist__44u0__short[] = {
  132115. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  132116. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  132117. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  132118. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  132119. };
  132120. static static_codebook _huff_book__44u0__short = {
  132121. 2, 64,
  132122. _huff_lengthlist__44u0__short,
  132123. 0, 0, 0, 0, 0,
  132124. NULL,
  132125. NULL,
  132126. NULL,
  132127. NULL,
  132128. 0
  132129. };
  132130. static long _huff_lengthlist__44u1__long[] = {
  132131. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  132132. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  132133. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  132134. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  132135. };
  132136. static static_codebook _huff_book__44u1__long = {
  132137. 2, 64,
  132138. _huff_lengthlist__44u1__long,
  132139. 0, 0, 0, 0, 0,
  132140. NULL,
  132141. NULL,
  132142. NULL,
  132143. NULL,
  132144. 0
  132145. };
  132146. static long _vq_quantlist__44u1__p1_0[] = {
  132147. 1,
  132148. 0,
  132149. 2,
  132150. };
  132151. static long _vq_lengthlist__44u1__p1_0[] = {
  132152. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132153. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132154. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  132155. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  132156. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  132157. 13,
  132158. };
  132159. static float _vq_quantthresh__44u1__p1_0[] = {
  132160. -0.5, 0.5,
  132161. };
  132162. static long _vq_quantmap__44u1__p1_0[] = {
  132163. 1, 0, 2,
  132164. };
  132165. static encode_aux_threshmatch _vq_auxt__44u1__p1_0 = {
  132166. _vq_quantthresh__44u1__p1_0,
  132167. _vq_quantmap__44u1__p1_0,
  132168. 3,
  132169. 3
  132170. };
  132171. static static_codebook _44u1__p1_0 = {
  132172. 4, 81,
  132173. _vq_lengthlist__44u1__p1_0,
  132174. 1, -535822336, 1611661312, 2, 0,
  132175. _vq_quantlist__44u1__p1_0,
  132176. NULL,
  132177. &_vq_auxt__44u1__p1_0,
  132178. NULL,
  132179. 0
  132180. };
  132181. static long _vq_quantlist__44u1__p2_0[] = {
  132182. 1,
  132183. 0,
  132184. 2,
  132185. };
  132186. static long _vq_lengthlist__44u1__p2_0[] = {
  132187. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  132188. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  132189. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132190. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  132191. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132192. 9,
  132193. };
  132194. static float _vq_quantthresh__44u1__p2_0[] = {
  132195. -0.5, 0.5,
  132196. };
  132197. static long _vq_quantmap__44u1__p2_0[] = {
  132198. 1, 0, 2,
  132199. };
  132200. static encode_aux_threshmatch _vq_auxt__44u1__p2_0 = {
  132201. _vq_quantthresh__44u1__p2_0,
  132202. _vq_quantmap__44u1__p2_0,
  132203. 3,
  132204. 3
  132205. };
  132206. static static_codebook _44u1__p2_0 = {
  132207. 4, 81,
  132208. _vq_lengthlist__44u1__p2_0,
  132209. 1, -535822336, 1611661312, 2, 0,
  132210. _vq_quantlist__44u1__p2_0,
  132211. NULL,
  132212. &_vq_auxt__44u1__p2_0,
  132213. NULL,
  132214. 0
  132215. };
  132216. static long _vq_quantlist__44u1__p3_0[] = {
  132217. 2,
  132218. 1,
  132219. 3,
  132220. 0,
  132221. 4,
  132222. };
  132223. static long _vq_lengthlist__44u1__p3_0[] = {
  132224. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  132225. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  132226. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  132227. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  132228. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  132229. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  132230. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  132231. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  132232. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  132233. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  132234. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  132235. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  132236. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  132237. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  132238. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  132239. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  132240. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  132241. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  132242. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  132243. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  132244. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  132245. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  132246. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  132247. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  132248. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  132249. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  132250. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  132251. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  132252. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  132253. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  132254. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  132255. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  132256. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  132257. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  132258. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  132259. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  132260. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  132261. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  132262. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  132263. 19,
  132264. };
  132265. static float _vq_quantthresh__44u1__p3_0[] = {
  132266. -1.5, -0.5, 0.5, 1.5,
  132267. };
  132268. static long _vq_quantmap__44u1__p3_0[] = {
  132269. 3, 1, 0, 2, 4,
  132270. };
  132271. static encode_aux_threshmatch _vq_auxt__44u1__p3_0 = {
  132272. _vq_quantthresh__44u1__p3_0,
  132273. _vq_quantmap__44u1__p3_0,
  132274. 5,
  132275. 5
  132276. };
  132277. static static_codebook _44u1__p3_0 = {
  132278. 4, 625,
  132279. _vq_lengthlist__44u1__p3_0,
  132280. 1, -533725184, 1611661312, 3, 0,
  132281. _vq_quantlist__44u1__p3_0,
  132282. NULL,
  132283. &_vq_auxt__44u1__p3_0,
  132284. NULL,
  132285. 0
  132286. };
  132287. static long _vq_quantlist__44u1__p4_0[] = {
  132288. 2,
  132289. 1,
  132290. 3,
  132291. 0,
  132292. 4,
  132293. };
  132294. static long _vq_lengthlist__44u1__p4_0[] = {
  132295. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  132296. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  132297. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  132298. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  132299. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  132300. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  132301. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  132302. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  132303. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  132304. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  132305. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  132306. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132307. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  132308. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  132309. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  132310. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  132311. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  132312. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  132313. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  132314. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  132315. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  132316. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  132317. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  132318. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  132319. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  132320. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  132321. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  132322. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  132323. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  132324. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  132325. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  132326. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  132327. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  132328. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  132329. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  132330. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  132331. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  132332. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  132333. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  132334. 12,
  132335. };
  132336. static float _vq_quantthresh__44u1__p4_0[] = {
  132337. -1.5, -0.5, 0.5, 1.5,
  132338. };
  132339. static long _vq_quantmap__44u1__p4_0[] = {
  132340. 3, 1, 0, 2, 4,
  132341. };
  132342. static encode_aux_threshmatch _vq_auxt__44u1__p4_0 = {
  132343. _vq_quantthresh__44u1__p4_0,
  132344. _vq_quantmap__44u1__p4_0,
  132345. 5,
  132346. 5
  132347. };
  132348. static static_codebook _44u1__p4_0 = {
  132349. 4, 625,
  132350. _vq_lengthlist__44u1__p4_0,
  132351. 1, -533725184, 1611661312, 3, 0,
  132352. _vq_quantlist__44u1__p4_0,
  132353. NULL,
  132354. &_vq_auxt__44u1__p4_0,
  132355. NULL,
  132356. 0
  132357. };
  132358. static long _vq_quantlist__44u1__p5_0[] = {
  132359. 4,
  132360. 3,
  132361. 5,
  132362. 2,
  132363. 6,
  132364. 1,
  132365. 7,
  132366. 0,
  132367. 8,
  132368. };
  132369. static long _vq_lengthlist__44u1__p5_0[] = {
  132370. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  132371. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  132372. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  132373. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  132374. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  132375. 12,
  132376. };
  132377. static float _vq_quantthresh__44u1__p5_0[] = {
  132378. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132379. };
  132380. static long _vq_quantmap__44u1__p5_0[] = {
  132381. 7, 5, 3, 1, 0, 2, 4, 6,
  132382. 8,
  132383. };
  132384. static encode_aux_threshmatch _vq_auxt__44u1__p5_0 = {
  132385. _vq_quantthresh__44u1__p5_0,
  132386. _vq_quantmap__44u1__p5_0,
  132387. 9,
  132388. 9
  132389. };
  132390. static static_codebook _44u1__p5_0 = {
  132391. 2, 81,
  132392. _vq_lengthlist__44u1__p5_0,
  132393. 1, -531628032, 1611661312, 4, 0,
  132394. _vq_quantlist__44u1__p5_0,
  132395. NULL,
  132396. &_vq_auxt__44u1__p5_0,
  132397. NULL,
  132398. 0
  132399. };
  132400. static long _vq_quantlist__44u1__p6_0[] = {
  132401. 6,
  132402. 5,
  132403. 7,
  132404. 4,
  132405. 8,
  132406. 3,
  132407. 9,
  132408. 2,
  132409. 10,
  132410. 1,
  132411. 11,
  132412. 0,
  132413. 12,
  132414. };
  132415. static long _vq_lengthlist__44u1__p6_0[] = {
  132416. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  132417. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  132418. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  132419. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  132420. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  132421. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  132422. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  132423. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  132424. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  132425. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  132426. 15,17,16,17,18,17,17,18, 0,
  132427. };
  132428. static float _vq_quantthresh__44u1__p6_0[] = {
  132429. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132430. 12.5, 17.5, 22.5, 27.5,
  132431. };
  132432. static long _vq_quantmap__44u1__p6_0[] = {
  132433. 11, 9, 7, 5, 3, 1, 0, 2,
  132434. 4, 6, 8, 10, 12,
  132435. };
  132436. static encode_aux_threshmatch _vq_auxt__44u1__p6_0 = {
  132437. _vq_quantthresh__44u1__p6_0,
  132438. _vq_quantmap__44u1__p6_0,
  132439. 13,
  132440. 13
  132441. };
  132442. static static_codebook _44u1__p6_0 = {
  132443. 2, 169,
  132444. _vq_lengthlist__44u1__p6_0,
  132445. 1, -526516224, 1616117760, 4, 0,
  132446. _vq_quantlist__44u1__p6_0,
  132447. NULL,
  132448. &_vq_auxt__44u1__p6_0,
  132449. NULL,
  132450. 0
  132451. };
  132452. static long _vq_quantlist__44u1__p6_1[] = {
  132453. 2,
  132454. 1,
  132455. 3,
  132456. 0,
  132457. 4,
  132458. };
  132459. static long _vq_lengthlist__44u1__p6_1[] = {
  132460. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  132461. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  132462. };
  132463. static float _vq_quantthresh__44u1__p6_1[] = {
  132464. -1.5, -0.5, 0.5, 1.5,
  132465. };
  132466. static long _vq_quantmap__44u1__p6_1[] = {
  132467. 3, 1, 0, 2, 4,
  132468. };
  132469. static encode_aux_threshmatch _vq_auxt__44u1__p6_1 = {
  132470. _vq_quantthresh__44u1__p6_1,
  132471. _vq_quantmap__44u1__p6_1,
  132472. 5,
  132473. 5
  132474. };
  132475. static static_codebook _44u1__p6_1 = {
  132476. 2, 25,
  132477. _vq_lengthlist__44u1__p6_1,
  132478. 1, -533725184, 1611661312, 3, 0,
  132479. _vq_quantlist__44u1__p6_1,
  132480. NULL,
  132481. &_vq_auxt__44u1__p6_1,
  132482. NULL,
  132483. 0
  132484. };
  132485. static long _vq_quantlist__44u1__p7_0[] = {
  132486. 3,
  132487. 2,
  132488. 4,
  132489. 1,
  132490. 5,
  132491. 0,
  132492. 6,
  132493. };
  132494. static long _vq_lengthlist__44u1__p7_0[] = {
  132495. 1, 3, 2, 9, 9, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132496. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132497. 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  132498. 8,
  132499. };
  132500. static float _vq_quantthresh__44u1__p7_0[] = {
  132501. -422.5, -253.5, -84.5, 84.5, 253.5, 422.5,
  132502. };
  132503. static long _vq_quantmap__44u1__p7_0[] = {
  132504. 5, 3, 1, 0, 2, 4, 6,
  132505. };
  132506. static encode_aux_threshmatch _vq_auxt__44u1__p7_0 = {
  132507. _vq_quantthresh__44u1__p7_0,
  132508. _vq_quantmap__44u1__p7_0,
  132509. 7,
  132510. 7
  132511. };
  132512. static static_codebook _44u1__p7_0 = {
  132513. 2, 49,
  132514. _vq_lengthlist__44u1__p7_0,
  132515. 1, -518017024, 1626677248, 3, 0,
  132516. _vq_quantlist__44u1__p7_0,
  132517. NULL,
  132518. &_vq_auxt__44u1__p7_0,
  132519. NULL,
  132520. 0
  132521. };
  132522. static long _vq_quantlist__44u1__p7_1[] = {
  132523. 6,
  132524. 5,
  132525. 7,
  132526. 4,
  132527. 8,
  132528. 3,
  132529. 9,
  132530. 2,
  132531. 10,
  132532. 1,
  132533. 11,
  132534. 0,
  132535. 12,
  132536. };
  132537. static long _vq_lengthlist__44u1__p7_1[] = {
  132538. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  132539. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  132540. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  132541. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  132542. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  132543. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  132544. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  132545. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  132546. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  132547. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  132548. 15,15,15,15,15,15,15,15,15,
  132549. };
  132550. static float _vq_quantthresh__44u1__p7_1[] = {
  132551. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132552. 32.5, 45.5, 58.5, 71.5,
  132553. };
  132554. static long _vq_quantmap__44u1__p7_1[] = {
  132555. 11, 9, 7, 5, 3, 1, 0, 2,
  132556. 4, 6, 8, 10, 12,
  132557. };
  132558. static encode_aux_threshmatch _vq_auxt__44u1__p7_1 = {
  132559. _vq_quantthresh__44u1__p7_1,
  132560. _vq_quantmap__44u1__p7_1,
  132561. 13,
  132562. 13
  132563. };
  132564. static static_codebook _44u1__p7_1 = {
  132565. 2, 169,
  132566. _vq_lengthlist__44u1__p7_1,
  132567. 1, -523010048, 1618608128, 4, 0,
  132568. _vq_quantlist__44u1__p7_1,
  132569. NULL,
  132570. &_vq_auxt__44u1__p7_1,
  132571. NULL,
  132572. 0
  132573. };
  132574. static long _vq_quantlist__44u1__p7_2[] = {
  132575. 6,
  132576. 5,
  132577. 7,
  132578. 4,
  132579. 8,
  132580. 3,
  132581. 9,
  132582. 2,
  132583. 10,
  132584. 1,
  132585. 11,
  132586. 0,
  132587. 12,
  132588. };
  132589. static long _vq_lengthlist__44u1__p7_2[] = {
  132590. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  132591. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  132592. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  132593. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132594. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  132595. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  132596. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  132597. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132598. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132599. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  132600. 9, 9, 9,10, 9, 9,10,10, 9,
  132601. };
  132602. static float _vq_quantthresh__44u1__p7_2[] = {
  132603. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  132604. 2.5, 3.5, 4.5, 5.5,
  132605. };
  132606. static long _vq_quantmap__44u1__p7_2[] = {
  132607. 11, 9, 7, 5, 3, 1, 0, 2,
  132608. 4, 6, 8, 10, 12,
  132609. };
  132610. static encode_aux_threshmatch _vq_auxt__44u1__p7_2 = {
  132611. _vq_quantthresh__44u1__p7_2,
  132612. _vq_quantmap__44u1__p7_2,
  132613. 13,
  132614. 13
  132615. };
  132616. static static_codebook _44u1__p7_2 = {
  132617. 2, 169,
  132618. _vq_lengthlist__44u1__p7_2,
  132619. 1, -531103744, 1611661312, 4, 0,
  132620. _vq_quantlist__44u1__p7_2,
  132621. NULL,
  132622. &_vq_auxt__44u1__p7_2,
  132623. NULL,
  132624. 0
  132625. };
  132626. static long _huff_lengthlist__44u1__short[] = {
  132627. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  132628. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  132629. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  132630. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  132631. };
  132632. static static_codebook _huff_book__44u1__short = {
  132633. 2, 64,
  132634. _huff_lengthlist__44u1__short,
  132635. 0, 0, 0, 0, 0,
  132636. NULL,
  132637. NULL,
  132638. NULL,
  132639. NULL,
  132640. 0
  132641. };
  132642. static long _huff_lengthlist__44u2__long[] = {
  132643. 5, 9,14,12,15,13,10,13, 7, 4, 5, 6, 8, 7, 8,12,
  132644. 13, 4, 3, 5, 5, 6, 9,15,12, 6, 5, 6, 6, 6, 7,14,
  132645. 14, 7, 4, 6, 4, 6, 8,15,12, 6, 6, 5, 5, 5, 6,14,
  132646. 9, 7, 8, 6, 7, 5, 4,10,10,13,14,14,15,10, 6, 8,
  132647. };
  132648. static static_codebook _huff_book__44u2__long = {
  132649. 2, 64,
  132650. _huff_lengthlist__44u2__long,
  132651. 0, 0, 0, 0, 0,
  132652. NULL,
  132653. NULL,
  132654. NULL,
  132655. NULL,
  132656. 0
  132657. };
  132658. static long _vq_quantlist__44u2__p1_0[] = {
  132659. 1,
  132660. 0,
  132661. 2,
  132662. };
  132663. static long _vq_lengthlist__44u2__p1_0[] = {
  132664. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132665. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132666. 11, 8,11,11, 8,11,11,11,13,14,11,13,13, 7,11,11,
  132667. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 8,
  132668. 11,11,11,14,13,10,12,13, 8,11,11,11,13,13,11,13,
  132669. 13,
  132670. };
  132671. static float _vq_quantthresh__44u2__p1_0[] = {
  132672. -0.5, 0.5,
  132673. };
  132674. static long _vq_quantmap__44u2__p1_0[] = {
  132675. 1, 0, 2,
  132676. };
  132677. static encode_aux_threshmatch _vq_auxt__44u2__p1_0 = {
  132678. _vq_quantthresh__44u2__p1_0,
  132679. _vq_quantmap__44u2__p1_0,
  132680. 3,
  132681. 3
  132682. };
  132683. static static_codebook _44u2__p1_0 = {
  132684. 4, 81,
  132685. _vq_lengthlist__44u2__p1_0,
  132686. 1, -535822336, 1611661312, 2, 0,
  132687. _vq_quantlist__44u2__p1_0,
  132688. NULL,
  132689. &_vq_auxt__44u2__p1_0,
  132690. NULL,
  132691. 0
  132692. };
  132693. static long _vq_quantlist__44u2__p2_0[] = {
  132694. 1,
  132695. 0,
  132696. 2,
  132697. };
  132698. static long _vq_lengthlist__44u2__p2_0[] = {
  132699. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  132700. 8, 8, 5, 6, 6, 6, 8, 7, 7, 8, 8, 5, 6, 6, 7, 8,
  132701. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132702. 7,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  132703. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132704. 9,
  132705. };
  132706. static float _vq_quantthresh__44u2__p2_0[] = {
  132707. -0.5, 0.5,
  132708. };
  132709. static long _vq_quantmap__44u2__p2_0[] = {
  132710. 1, 0, 2,
  132711. };
  132712. static encode_aux_threshmatch _vq_auxt__44u2__p2_0 = {
  132713. _vq_quantthresh__44u2__p2_0,
  132714. _vq_quantmap__44u2__p2_0,
  132715. 3,
  132716. 3
  132717. };
  132718. static static_codebook _44u2__p2_0 = {
  132719. 4, 81,
  132720. _vq_lengthlist__44u2__p2_0,
  132721. 1, -535822336, 1611661312, 2, 0,
  132722. _vq_quantlist__44u2__p2_0,
  132723. NULL,
  132724. &_vq_auxt__44u2__p2_0,
  132725. NULL,
  132726. 0
  132727. };
  132728. static long _vq_quantlist__44u2__p3_0[] = {
  132729. 2,
  132730. 1,
  132731. 3,
  132732. 0,
  132733. 4,
  132734. };
  132735. static long _vq_lengthlist__44u2__p3_0[] = {
  132736. 2, 4, 4, 7, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  132737. 9, 9,12,11, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  132738. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  132739. 12,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  132740. 11, 9,11,10,13,13,10,11,11,13,13, 8,10,10,14,13,
  132741. 10,11,11,15,14, 9,11,11,15,14,13,14,13,16,14,12,
  132742. 13,13,15,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  132743. 11,14,15,12,13,13,15,15,12,13,14,15,16, 5, 7, 7,
  132744. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  132745. 13,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  132746. 9,11,11,13,13,12,13,12,14,14,11,12,13,15,15, 7,
  132747. 9, 9,12,12, 8,11,10,13,12, 9,11,11,13,13,11,13,
  132748. 12,15,13,11,13,13,15,16, 9,12,11,15,15,11,12,12,
  132749. 16,15,11,12,13,16,16,13,14,15,16,15,13,15,15,17,
  132750. 17, 9,11,11,14,15,10,12,12,15,15,11,13,12,15,16,
  132751. 13,15,14,16,16,13,15,15,17,19, 5, 7, 7,10,10, 7,
  132752. 9, 9,12,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  132753. 11,13,14, 7, 9, 9,12,12, 9,11,11,13,13, 9,10,11,
  132754. 12,13,11,13,12,16,15,11,12,12,14,15, 7, 9, 9,12,
  132755. 12, 9,11,11,13,13, 9,11,11,13,12,11,13,12,15,16,
  132756. 12,13,13,15,14, 9,11,11,15,14,11,13,12,16,15,10,
  132757. 11,12,15,15,13,14,14,18,17,13,14,14,15,17,10,11,
  132758. 11,14,15,11,13,12,15,17,11,13,12,15,16,13,15,14,
  132759. 18,17,14,15,15,16,18, 7,10,10,14,14,10,12,12,15,
  132760. 15,10,12,12,15,15,14,15,15,18,17,13,15,15,16,16,
  132761. 9,11,11,16,15,11,13,13,16,18,11,13,13,16,16,15,
  132762. 16,16, 0, 0,14,15,16,18,17, 9,11,11,15,15,10,13,
  132763. 12,17,16,11,12,13,16,17,14,15,16,19,19,14,15,15,
  132764. 0,20,12,14,14, 0, 0,13,14,16,19,18,13,15,16,20,
  132765. 17,16,18, 0, 0, 0,15,16,17,18,19,11,14,14, 0,19,
  132766. 12,15,14,17,17,13,15,15, 0, 0,16,17,15,20,19,15,
  132767. 17,16,19, 0, 8,10,10,14,15,10,12,11,15,15,10,11,
  132768. 12,16,15,13,14,14,19,17,14,15,15, 0, 0, 9,11,11,
  132769. 16,15,11,13,13,17,16,10,12,13,16,17,14,15,15,18,
  132770. 18,14,15,16,20,19, 9,12,12, 0,15,11,13,13,16,17,
  132771. 11,13,13,19,17,14,16,16,18,17,15,16,16,17,19,11,
  132772. 14,14,18,18,13,14,15, 0, 0,12,14,15,19,18,15,16,
  132773. 19, 0,19,15,16,19,19,17,12,14,14,16,19,13,15,15,
  132774. 0,17,13,15,14,18,18,15,16,15, 0,18,16,17,17, 0,
  132775. 0,
  132776. };
  132777. static float _vq_quantthresh__44u2__p3_0[] = {
  132778. -1.5, -0.5, 0.5, 1.5,
  132779. };
  132780. static long _vq_quantmap__44u2__p3_0[] = {
  132781. 3, 1, 0, 2, 4,
  132782. };
  132783. static encode_aux_threshmatch _vq_auxt__44u2__p3_0 = {
  132784. _vq_quantthresh__44u2__p3_0,
  132785. _vq_quantmap__44u2__p3_0,
  132786. 5,
  132787. 5
  132788. };
  132789. static static_codebook _44u2__p3_0 = {
  132790. 4, 625,
  132791. _vq_lengthlist__44u2__p3_0,
  132792. 1, -533725184, 1611661312, 3, 0,
  132793. _vq_quantlist__44u2__p3_0,
  132794. NULL,
  132795. &_vq_auxt__44u2__p3_0,
  132796. NULL,
  132797. 0
  132798. };
  132799. static long _vq_quantlist__44u2__p4_0[] = {
  132800. 2,
  132801. 1,
  132802. 3,
  132803. 0,
  132804. 4,
  132805. };
  132806. static long _vq_lengthlist__44u2__p4_0[] = {
  132807. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  132808. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  132809. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  132810. 11,12, 5, 7, 7, 9, 9, 6, 8, 7,10,10, 7, 8, 8,10,
  132811. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10,10,12,12,
  132812. 10,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  132813. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,13,10,10,
  132814. 10,12,13,11,12,12,14,13,12,12,12,14,13, 5, 7, 7,
  132815. 10, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  132816. 12,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  132817. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,13,13, 6,
  132818. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132819. 10,13,11,10,11,11,13,13, 9,10,10,13,13,10,11,11,
  132820. 13,13,10,11,11,14,13,12,11,13,12,15,12,13,13,15,
  132821. 15, 9,10,10,12,13,10,11,10,13,13,10,11,11,13,13,
  132822. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9,10, 7,
  132823. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  132824. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  132825. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  132826. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  132827. 10,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  132828. 10,11,13,13,12,13,13,15,15,12,11,13,12,14, 9,10,
  132829. 10,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  132830. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  132831. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  132832. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,12,13,
  132833. 13,14,14,16,12,13,13,15,14, 9,10,10,13,13,10,11,
  132834. 10,14,13,10,11,11,13,14,12,14,13,16,14,13,13,13,
  132835. 14,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  132836. 15,14,12,15,12,16,14,15,15,17,16,11,12,12,14,15,
  132837. 11,13,11,15,14,12,13,13,15,16,13,15,12,17,13,14,
  132838. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,13,13, 9,10,
  132839. 10,13,13,12,13,12,14,14,12,13,13,15,15, 9,10,10,
  132840. 13,13,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  132841. 14,12,12,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  132842. 10,11,11,14,13,13,13,13,15,15,13,14,13,16,14,11,
  132843. 12,12,14,14,12,13,13,16,15,11,12,13,14,15,14,15,
  132844. 15,16,16,14,13,15,13,17,11,12,12,14,15,12,13,13,
  132845. 15,16,11,13,12,15,15,14,15,14,16,16,14,15,12,17,
  132846. 13,
  132847. };
  132848. static float _vq_quantthresh__44u2__p4_0[] = {
  132849. -1.5, -0.5, 0.5, 1.5,
  132850. };
  132851. static long _vq_quantmap__44u2__p4_0[] = {
  132852. 3, 1, 0, 2, 4,
  132853. };
  132854. static encode_aux_threshmatch _vq_auxt__44u2__p4_0 = {
  132855. _vq_quantthresh__44u2__p4_0,
  132856. _vq_quantmap__44u2__p4_0,
  132857. 5,
  132858. 5
  132859. };
  132860. static static_codebook _44u2__p4_0 = {
  132861. 4, 625,
  132862. _vq_lengthlist__44u2__p4_0,
  132863. 1, -533725184, 1611661312, 3, 0,
  132864. _vq_quantlist__44u2__p4_0,
  132865. NULL,
  132866. &_vq_auxt__44u2__p4_0,
  132867. NULL,
  132868. 0
  132869. };
  132870. static long _vq_quantlist__44u2__p5_0[] = {
  132871. 4,
  132872. 3,
  132873. 5,
  132874. 2,
  132875. 6,
  132876. 1,
  132877. 7,
  132878. 0,
  132879. 8,
  132880. };
  132881. static long _vq_lengthlist__44u2__p5_0[] = {
  132882. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 8, 8, 8,
  132883. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  132884. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  132885. 9, 9,10,11,12,12, 8, 8, 8, 9, 9,10,10,12,12,10,
  132886. 10,10,11,11,12,12,13,13,10,10,10,11,11,12,12,13,
  132887. 13,
  132888. };
  132889. static float _vq_quantthresh__44u2__p5_0[] = {
  132890. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132891. };
  132892. static long _vq_quantmap__44u2__p5_0[] = {
  132893. 7, 5, 3, 1, 0, 2, 4, 6,
  132894. 8,
  132895. };
  132896. static encode_aux_threshmatch _vq_auxt__44u2__p5_0 = {
  132897. _vq_quantthresh__44u2__p5_0,
  132898. _vq_quantmap__44u2__p5_0,
  132899. 9,
  132900. 9
  132901. };
  132902. static static_codebook _44u2__p5_0 = {
  132903. 2, 81,
  132904. _vq_lengthlist__44u2__p5_0,
  132905. 1, -531628032, 1611661312, 4, 0,
  132906. _vq_quantlist__44u2__p5_0,
  132907. NULL,
  132908. &_vq_auxt__44u2__p5_0,
  132909. NULL,
  132910. 0
  132911. };
  132912. static long _vq_quantlist__44u2__p6_0[] = {
  132913. 6,
  132914. 5,
  132915. 7,
  132916. 4,
  132917. 8,
  132918. 3,
  132919. 9,
  132920. 2,
  132921. 10,
  132922. 1,
  132923. 11,
  132924. 0,
  132925. 12,
  132926. };
  132927. static long _vq_lengthlist__44u2__p6_0[] = {
  132928. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,14,13, 4, 6, 5,
  132929. 8, 8, 9, 9,11,10,12,11,15,14, 4, 5, 6, 8, 8, 9,
  132930. 9,11,11,11,11,14,14, 6, 8, 8,10, 9,11,11,11,11,
  132931. 12,12,15,15, 6, 8, 8, 9, 9,11,11,11,12,12,12,15,
  132932. 15, 8,10,10,11,11,11,11,12,12,13,13,15,16, 8,10,
  132933. 10,11,11,11,11,12,12,13,13,16,16,10,11,11,12,12,
  132934. 12,12,13,13,13,13,17,16,10,11,11,12,12,12,12,13,
  132935. 13,13,14,16,17,11,12,12,13,13,13,13,14,14,15,14,
  132936. 18,17,11,12,12,13,13,13,13,14,14,14,15,19,18,14,
  132937. 15,15,15,15,16,16,18,19,18,18, 0, 0,14,15,15,16,
  132938. 15,17,17,16,18,17,18, 0, 0,
  132939. };
  132940. static float _vq_quantthresh__44u2__p6_0[] = {
  132941. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132942. 12.5, 17.5, 22.5, 27.5,
  132943. };
  132944. static long _vq_quantmap__44u2__p6_0[] = {
  132945. 11, 9, 7, 5, 3, 1, 0, 2,
  132946. 4, 6, 8, 10, 12,
  132947. };
  132948. static encode_aux_threshmatch _vq_auxt__44u2__p6_0 = {
  132949. _vq_quantthresh__44u2__p6_0,
  132950. _vq_quantmap__44u2__p6_0,
  132951. 13,
  132952. 13
  132953. };
  132954. static static_codebook _44u2__p6_0 = {
  132955. 2, 169,
  132956. _vq_lengthlist__44u2__p6_0,
  132957. 1, -526516224, 1616117760, 4, 0,
  132958. _vq_quantlist__44u2__p6_0,
  132959. NULL,
  132960. &_vq_auxt__44u2__p6_0,
  132961. NULL,
  132962. 0
  132963. };
  132964. static long _vq_quantlist__44u2__p6_1[] = {
  132965. 2,
  132966. 1,
  132967. 3,
  132968. 0,
  132969. 4,
  132970. };
  132971. static long _vq_lengthlist__44u2__p6_1[] = {
  132972. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  132973. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  132974. };
  132975. static float _vq_quantthresh__44u2__p6_1[] = {
  132976. -1.5, -0.5, 0.5, 1.5,
  132977. };
  132978. static long _vq_quantmap__44u2__p6_1[] = {
  132979. 3, 1, 0, 2, 4,
  132980. };
  132981. static encode_aux_threshmatch _vq_auxt__44u2__p6_1 = {
  132982. _vq_quantthresh__44u2__p6_1,
  132983. _vq_quantmap__44u2__p6_1,
  132984. 5,
  132985. 5
  132986. };
  132987. static static_codebook _44u2__p6_1 = {
  132988. 2, 25,
  132989. _vq_lengthlist__44u2__p6_1,
  132990. 1, -533725184, 1611661312, 3, 0,
  132991. _vq_quantlist__44u2__p6_1,
  132992. NULL,
  132993. &_vq_auxt__44u2__p6_1,
  132994. NULL,
  132995. 0
  132996. };
  132997. static long _vq_quantlist__44u2__p7_0[] = {
  132998. 4,
  132999. 3,
  133000. 5,
  133001. 2,
  133002. 6,
  133003. 1,
  133004. 7,
  133005. 0,
  133006. 8,
  133007. };
  133008. static long _vq_lengthlist__44u2__p7_0[] = {
  133009. 1, 3, 2,12,12,12,12,12,12, 4,12,12,12,12,12,12,
  133010. 12,12, 5,12,12,12,12,12,12,12,12,12,12,11,11,11,
  133011. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133012. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133013. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133014. 11,
  133015. };
  133016. static float _vq_quantthresh__44u2__p7_0[] = {
  133017. -591.5, -422.5, -253.5, -84.5, 84.5, 253.5, 422.5, 591.5,
  133018. };
  133019. static long _vq_quantmap__44u2__p7_0[] = {
  133020. 7, 5, 3, 1, 0, 2, 4, 6,
  133021. 8,
  133022. };
  133023. static encode_aux_threshmatch _vq_auxt__44u2__p7_0 = {
  133024. _vq_quantthresh__44u2__p7_0,
  133025. _vq_quantmap__44u2__p7_0,
  133026. 9,
  133027. 9
  133028. };
  133029. static static_codebook _44u2__p7_0 = {
  133030. 2, 81,
  133031. _vq_lengthlist__44u2__p7_0,
  133032. 1, -516612096, 1626677248, 4, 0,
  133033. _vq_quantlist__44u2__p7_0,
  133034. NULL,
  133035. &_vq_auxt__44u2__p7_0,
  133036. NULL,
  133037. 0
  133038. };
  133039. static long _vq_quantlist__44u2__p7_1[] = {
  133040. 6,
  133041. 5,
  133042. 7,
  133043. 4,
  133044. 8,
  133045. 3,
  133046. 9,
  133047. 2,
  133048. 10,
  133049. 1,
  133050. 11,
  133051. 0,
  133052. 12,
  133053. };
  133054. static long _vq_lengthlist__44u2__p7_1[] = {
  133055. 1, 4, 4, 7, 6, 7, 6, 8, 7, 9, 7, 9, 8, 4, 7, 6,
  133056. 8, 8, 9, 8,10, 9,10,10,11,11, 4, 7, 7, 8, 8, 8,
  133057. 8, 9,10,11,11,11,11, 6, 8, 8,10,10,10,10,11,11,
  133058. 12,12,12,12, 7, 8, 8,10,10,10,10,11,11,12,12,13,
  133059. 13, 7, 9, 9,11,10,12,12,13,13,14,13,14,14, 7, 9,
  133060. 9,10,11,11,12,13,13,13,13,16,14, 9,10,10,12,12,
  133061. 13,13,14,14,15,16,15,16, 9,10,10,12,12,12,13,14,
  133062. 14,14,15,16,15,10,12,12,13,13,15,13,16,16,15,17,
  133063. 17,17,10,11,11,12,14,14,14,15,15,17,17,15,17,11,
  133064. 12,12,14,14,14,15,15,15,17,16,17,17,10,12,12,13,
  133065. 14,14,14,17,15,17,17,17,17,
  133066. };
  133067. static float _vq_quantthresh__44u2__p7_1[] = {
  133068. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  133069. 32.5, 45.5, 58.5, 71.5,
  133070. };
  133071. static long _vq_quantmap__44u2__p7_1[] = {
  133072. 11, 9, 7, 5, 3, 1, 0, 2,
  133073. 4, 6, 8, 10, 12,
  133074. };
  133075. static encode_aux_threshmatch _vq_auxt__44u2__p7_1 = {
  133076. _vq_quantthresh__44u2__p7_1,
  133077. _vq_quantmap__44u2__p7_1,
  133078. 13,
  133079. 13
  133080. };
  133081. static static_codebook _44u2__p7_1 = {
  133082. 2, 169,
  133083. _vq_lengthlist__44u2__p7_1,
  133084. 1, -523010048, 1618608128, 4, 0,
  133085. _vq_quantlist__44u2__p7_1,
  133086. NULL,
  133087. &_vq_auxt__44u2__p7_1,
  133088. NULL,
  133089. 0
  133090. };
  133091. static long _vq_quantlist__44u2__p7_2[] = {
  133092. 6,
  133093. 5,
  133094. 7,
  133095. 4,
  133096. 8,
  133097. 3,
  133098. 9,
  133099. 2,
  133100. 10,
  133101. 1,
  133102. 11,
  133103. 0,
  133104. 12,
  133105. };
  133106. static long _vq_lengthlist__44u2__p7_2[] = {
  133107. 2, 5, 5, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 5, 6, 6,
  133108. 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 5, 6, 6, 7, 7, 8,
  133109. 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7, 8, 8, 8, 8, 8,
  133110. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  133111. 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 7, 8,
  133112. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 9,
  133113. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  133114. 9, 9, 9, 9, 9, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133115. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8,
  133116. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9,
  133117. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133118. };
  133119. static float _vq_quantthresh__44u2__p7_2[] = {
  133120. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  133121. 2.5, 3.5, 4.5, 5.5,
  133122. };
  133123. static long _vq_quantmap__44u2__p7_2[] = {
  133124. 11, 9, 7, 5, 3, 1, 0, 2,
  133125. 4, 6, 8, 10, 12,
  133126. };
  133127. static encode_aux_threshmatch _vq_auxt__44u2__p7_2 = {
  133128. _vq_quantthresh__44u2__p7_2,
  133129. _vq_quantmap__44u2__p7_2,
  133130. 13,
  133131. 13
  133132. };
  133133. static static_codebook _44u2__p7_2 = {
  133134. 2, 169,
  133135. _vq_lengthlist__44u2__p7_2,
  133136. 1, -531103744, 1611661312, 4, 0,
  133137. _vq_quantlist__44u2__p7_2,
  133138. NULL,
  133139. &_vq_auxt__44u2__p7_2,
  133140. NULL,
  133141. 0
  133142. };
  133143. static long _huff_lengthlist__44u2__short[] = {
  133144. 13,15,17,17,15,15,12,17,11, 9, 7,10,10, 9,12,17,
  133145. 10, 6, 3, 6, 5, 7,10,17,15,10, 6, 9, 8, 9,11,17,
  133146. 15, 8, 4, 7, 3, 5, 9,16,16,10, 5, 8, 4, 5, 8,16,
  133147. 13,11, 5, 8, 3, 3, 5,14,13,12, 7,10, 5, 5, 7,14,
  133148. };
  133149. static static_codebook _huff_book__44u2__short = {
  133150. 2, 64,
  133151. _huff_lengthlist__44u2__short,
  133152. 0, 0, 0, 0, 0,
  133153. NULL,
  133154. NULL,
  133155. NULL,
  133156. NULL,
  133157. 0
  133158. };
  133159. static long _huff_lengthlist__44u3__long[] = {
  133160. 6, 9,13,12,14,11,10,13, 8, 4, 5, 7, 8, 7, 8,12,
  133161. 11, 4, 3, 5, 5, 7, 9,14,11, 6, 5, 6, 6, 6, 7,13,
  133162. 13, 7, 5, 6, 4, 5, 7,14,11, 7, 6, 6, 5, 5, 6,13,
  133163. 9, 7, 8, 6, 7, 5, 3, 9, 9,12,13,12,14,10, 6, 7,
  133164. };
  133165. static static_codebook _huff_book__44u3__long = {
  133166. 2, 64,
  133167. _huff_lengthlist__44u3__long,
  133168. 0, 0, 0, 0, 0,
  133169. NULL,
  133170. NULL,
  133171. NULL,
  133172. NULL,
  133173. 0
  133174. };
  133175. static long _vq_quantlist__44u3__p1_0[] = {
  133176. 1,
  133177. 0,
  133178. 2,
  133179. };
  133180. static long _vq_lengthlist__44u3__p1_0[] = {
  133181. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  133182. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133183. 11, 8,11,11, 8,11,11,11,13,14,11,14,14, 8,11,11,
  133184. 10,14,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  133185. 11,11,11,14,14,10,12,14, 8,11,11,11,14,14,11,14,
  133186. 13,
  133187. };
  133188. static float _vq_quantthresh__44u3__p1_0[] = {
  133189. -0.5, 0.5,
  133190. };
  133191. static long _vq_quantmap__44u3__p1_0[] = {
  133192. 1, 0, 2,
  133193. };
  133194. static encode_aux_threshmatch _vq_auxt__44u3__p1_0 = {
  133195. _vq_quantthresh__44u3__p1_0,
  133196. _vq_quantmap__44u3__p1_0,
  133197. 3,
  133198. 3
  133199. };
  133200. static static_codebook _44u3__p1_0 = {
  133201. 4, 81,
  133202. _vq_lengthlist__44u3__p1_0,
  133203. 1, -535822336, 1611661312, 2, 0,
  133204. _vq_quantlist__44u3__p1_0,
  133205. NULL,
  133206. &_vq_auxt__44u3__p1_0,
  133207. NULL,
  133208. 0
  133209. };
  133210. static long _vq_quantlist__44u3__p2_0[] = {
  133211. 1,
  133212. 0,
  133213. 2,
  133214. };
  133215. static long _vq_lengthlist__44u3__p2_0[] = {
  133216. 2, 5, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133217. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 7, 8,
  133218. 8, 6, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133219. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  133220. 8, 8, 8,10,10, 8, 8,10, 7, 8, 8, 8,10,10, 8,10,
  133221. 9,
  133222. };
  133223. static float _vq_quantthresh__44u3__p2_0[] = {
  133224. -0.5, 0.5,
  133225. };
  133226. static long _vq_quantmap__44u3__p2_0[] = {
  133227. 1, 0, 2,
  133228. };
  133229. static encode_aux_threshmatch _vq_auxt__44u3__p2_0 = {
  133230. _vq_quantthresh__44u3__p2_0,
  133231. _vq_quantmap__44u3__p2_0,
  133232. 3,
  133233. 3
  133234. };
  133235. static static_codebook _44u3__p2_0 = {
  133236. 4, 81,
  133237. _vq_lengthlist__44u3__p2_0,
  133238. 1, -535822336, 1611661312, 2, 0,
  133239. _vq_quantlist__44u3__p2_0,
  133240. NULL,
  133241. &_vq_auxt__44u3__p2_0,
  133242. NULL,
  133243. 0
  133244. };
  133245. static long _vq_quantlist__44u3__p3_0[] = {
  133246. 2,
  133247. 1,
  133248. 3,
  133249. 0,
  133250. 4,
  133251. };
  133252. static long _vq_lengthlist__44u3__p3_0[] = {
  133253. 2, 4, 4, 7, 7, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133254. 9, 9,12,12, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  133255. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  133256. 13,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  133257. 11, 9,11,10,13,13,10,11,11,14,13, 8,10,10,14,13,
  133258. 10,11,11,15,14, 9,11,11,14,14,13,14,13,16,16,12,
  133259. 13,13,15,15, 8,10,10,13,14, 9,11,11,14,14,10,11,
  133260. 11,14,15,12,13,13,15,15,13,14,14,15,16, 5, 7, 7,
  133261. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  133262. 14,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  133263. 9,11,11,13,13,12,12,13,15,15,11,12,13,15,16, 7,
  133264. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  133265. 12,15,13,11,13,13,15,16, 9,12,11,15,14,11,12,13,
  133266. 16,15,11,13,13,15,16,14,14,15,17,16,13,15,16, 0,
  133267. 17, 9,11,11,15,15,10,13,12,15,15,11,13,13,15,16,
  133268. 13,15,13,16,15,14,16,15, 0,19, 5, 7, 7,10,10, 7,
  133269. 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,14,10,11,
  133270. 12,14,14, 7, 9, 9,12,12, 9,11,11,14,13, 9,10,11,
  133271. 12,13,11,13,13,16,16,11,12,13,13,16, 7, 9, 9,12,
  133272. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,15,
  133273. 12,13,12,15,14, 9,11,11,15,14,11,13,12,16,16,10,
  133274. 12,12,15,15,13,15,15,17,19,13,14,15,16,17,10,12,
  133275. 12,15,15,11,13,13,16,16,11,13,13,15,16,13,15,15,
  133276. 0, 0,14,15,15,16,16, 8,10,10,14,14,10,12,12,15,
  133277. 15,10,12,11,15,16,14,15,15,19,20,13,14,14,18,16,
  133278. 9,11,11,15,15,11,13,13,17,16,11,13,13,16,16,15,
  133279. 17,17,20,20,14,15,16,17,20, 9,11,11,15,15,10,13,
  133280. 12,16,15,11,13,13,15,17,14,16,15,18, 0,14,16,15,
  133281. 18,20,12,14,14, 0, 0,14,14,16, 0, 0,13,16,15, 0,
  133282. 0,17,17,18, 0, 0,16,17,19,19, 0,12,14,14,18, 0,
  133283. 12,16,14, 0,17,13,15,15,18, 0,16,18,17, 0,17,16,
  133284. 18,17, 0, 0, 7,10,10,14,14,10,12,11,15,15,10,12,
  133285. 12,16,15,13,15,15,18, 0,14,15,15,17, 0, 9,11,11,
  133286. 15,15,11,13,13,16,16,11,12,13,16,16,14,15,16,17,
  133287. 17,14,16,16,16,18, 9,11,12,16,16,11,13,13,17,17,
  133288. 11,14,13,20,17,15,16,16,19, 0,15,16,17, 0,19,11,
  133289. 13,14,17,16,14,15,15,20,18,13,14,15,17,19,16,18,
  133290. 18, 0,20,16,16,19,17, 0,12,15,14,17, 0,14,15,15,
  133291. 18,19,13,16,15,19,20,15,18,18, 0,20,17, 0,16, 0,
  133292. 0,
  133293. };
  133294. static float _vq_quantthresh__44u3__p3_0[] = {
  133295. -1.5, -0.5, 0.5, 1.5,
  133296. };
  133297. static long _vq_quantmap__44u3__p3_0[] = {
  133298. 3, 1, 0, 2, 4,
  133299. };
  133300. static encode_aux_threshmatch _vq_auxt__44u3__p3_0 = {
  133301. _vq_quantthresh__44u3__p3_0,
  133302. _vq_quantmap__44u3__p3_0,
  133303. 5,
  133304. 5
  133305. };
  133306. static static_codebook _44u3__p3_0 = {
  133307. 4, 625,
  133308. _vq_lengthlist__44u3__p3_0,
  133309. 1, -533725184, 1611661312, 3, 0,
  133310. _vq_quantlist__44u3__p3_0,
  133311. NULL,
  133312. &_vq_auxt__44u3__p3_0,
  133313. NULL,
  133314. 0
  133315. };
  133316. static long _vq_quantlist__44u3__p4_0[] = {
  133317. 2,
  133318. 1,
  133319. 3,
  133320. 0,
  133321. 4,
  133322. };
  133323. static long _vq_lengthlist__44u3__p4_0[] = {
  133324. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133325. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133326. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  133327. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  133328. 10, 9,10, 9,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  133329. 9,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  133330. 12,12,13,14, 9, 9,10,12,12, 9,10,10,12,12, 9,10,
  133331. 10,12,13,11,12,11,14,13,12,12,12,14,13, 5, 7, 7,
  133332. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133333. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133334. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  133335. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133336. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  133337. 13,13,10,11,11,13,13,12,12,13,12,15,12,13,13,15,
  133338. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  133339. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  133340. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  133341. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133342. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133343. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  133344. 11,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133345. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  133346. 11,12,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  133347. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133348. 13, 9,10,10,13,13,12,13,13,15,14,12,12,12,14,13,
  133349. 9,10,10,13,12,10,11,11,13,13,10,11,11,14,12,13,
  133350. 13,14,14,16,12,13,13,15,15, 9,10,10,13,13,10,11,
  133351. 10,14,13,10,11,11,13,14,12,14,13,15,14,13,13,13,
  133352. 15,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  133353. 14,14,12,15,12,16,14,15,15,17,15,11,12,12,14,14,
  133354. 11,13,11,15,14,12,13,13,15,15,13,15,12,17,13,14,
  133355. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  133356. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  133357. 13,12,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  133358. 15,12,12,13,14,16, 9,10,10,13,13,10,11,11,13,14,
  133359. 10,11,11,14,13,12,13,13,14,15,13,14,13,16,14,11,
  133360. 12,12,14,14,12,13,13,15,14,11,12,13,14,15,14,15,
  133361. 15,16,16,13,13,15,13,16,11,12,12,14,15,12,13,13,
  133362. 14,15,11,13,12,15,14,14,15,15,16,16,14,15,12,16,
  133363. 13,
  133364. };
  133365. static float _vq_quantthresh__44u3__p4_0[] = {
  133366. -1.5, -0.5, 0.5, 1.5,
  133367. };
  133368. static long _vq_quantmap__44u3__p4_0[] = {
  133369. 3, 1, 0, 2, 4,
  133370. };
  133371. static encode_aux_threshmatch _vq_auxt__44u3__p4_0 = {
  133372. _vq_quantthresh__44u3__p4_0,
  133373. _vq_quantmap__44u3__p4_0,
  133374. 5,
  133375. 5
  133376. };
  133377. static static_codebook _44u3__p4_0 = {
  133378. 4, 625,
  133379. _vq_lengthlist__44u3__p4_0,
  133380. 1, -533725184, 1611661312, 3, 0,
  133381. _vq_quantlist__44u3__p4_0,
  133382. NULL,
  133383. &_vq_auxt__44u3__p4_0,
  133384. NULL,
  133385. 0
  133386. };
  133387. static long _vq_quantlist__44u3__p5_0[] = {
  133388. 4,
  133389. 3,
  133390. 5,
  133391. 2,
  133392. 6,
  133393. 1,
  133394. 7,
  133395. 0,
  133396. 8,
  133397. };
  133398. static long _vq_lengthlist__44u3__p5_0[] = {
  133399. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  133400. 10,10, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  133401. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,10, 7, 8, 8,
  133402. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  133403. 10,10,11,10,11,11,12,12, 9,10,10,10,10,11,11,12,
  133404. 12,
  133405. };
  133406. static float _vq_quantthresh__44u3__p5_0[] = {
  133407. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133408. };
  133409. static long _vq_quantmap__44u3__p5_0[] = {
  133410. 7, 5, 3, 1, 0, 2, 4, 6,
  133411. 8,
  133412. };
  133413. static encode_aux_threshmatch _vq_auxt__44u3__p5_0 = {
  133414. _vq_quantthresh__44u3__p5_0,
  133415. _vq_quantmap__44u3__p5_0,
  133416. 9,
  133417. 9
  133418. };
  133419. static static_codebook _44u3__p5_0 = {
  133420. 2, 81,
  133421. _vq_lengthlist__44u3__p5_0,
  133422. 1, -531628032, 1611661312, 4, 0,
  133423. _vq_quantlist__44u3__p5_0,
  133424. NULL,
  133425. &_vq_auxt__44u3__p5_0,
  133426. NULL,
  133427. 0
  133428. };
  133429. static long _vq_quantlist__44u3__p6_0[] = {
  133430. 6,
  133431. 5,
  133432. 7,
  133433. 4,
  133434. 8,
  133435. 3,
  133436. 9,
  133437. 2,
  133438. 10,
  133439. 1,
  133440. 11,
  133441. 0,
  133442. 12,
  133443. };
  133444. static long _vq_lengthlist__44u3__p6_0[] = {
  133445. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,13,14, 4, 6, 5,
  133446. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  133447. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  133448. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  133449. 15, 8, 9, 9,11,10,11,11,12,12,13,13,15,16, 8, 9,
  133450. 9,10,11,11,11,12,12,13,13,16,16,10,10,11,11,11,
  133451. 12,12,13,13,13,14,17,16, 9,10,11,12,11,12,12,13,
  133452. 13,13,13,16,18,11,12,11,12,12,13,13,13,14,15,14,
  133453. 17,17,11,11,12,12,12,13,13,13,14,14,15,18,17,14,
  133454. 15,15,15,15,16,16,17,17,19,18, 0,20,14,15,14,15,
  133455. 15,16,16,16,17,18,16,20,18,
  133456. };
  133457. static float _vq_quantthresh__44u3__p6_0[] = {
  133458. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133459. 12.5, 17.5, 22.5, 27.5,
  133460. };
  133461. static long _vq_quantmap__44u3__p6_0[] = {
  133462. 11, 9, 7, 5, 3, 1, 0, 2,
  133463. 4, 6, 8, 10, 12,
  133464. };
  133465. static encode_aux_threshmatch _vq_auxt__44u3__p6_0 = {
  133466. _vq_quantthresh__44u3__p6_0,
  133467. _vq_quantmap__44u3__p6_0,
  133468. 13,
  133469. 13
  133470. };
  133471. static static_codebook _44u3__p6_0 = {
  133472. 2, 169,
  133473. _vq_lengthlist__44u3__p6_0,
  133474. 1, -526516224, 1616117760, 4, 0,
  133475. _vq_quantlist__44u3__p6_0,
  133476. NULL,
  133477. &_vq_auxt__44u3__p6_0,
  133478. NULL,
  133479. 0
  133480. };
  133481. static long _vq_quantlist__44u3__p6_1[] = {
  133482. 2,
  133483. 1,
  133484. 3,
  133485. 0,
  133486. 4,
  133487. };
  133488. static long _vq_lengthlist__44u3__p6_1[] = {
  133489. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133490. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133491. };
  133492. static float _vq_quantthresh__44u3__p6_1[] = {
  133493. -1.5, -0.5, 0.5, 1.5,
  133494. };
  133495. static long _vq_quantmap__44u3__p6_1[] = {
  133496. 3, 1, 0, 2, 4,
  133497. };
  133498. static encode_aux_threshmatch _vq_auxt__44u3__p6_1 = {
  133499. _vq_quantthresh__44u3__p6_1,
  133500. _vq_quantmap__44u3__p6_1,
  133501. 5,
  133502. 5
  133503. };
  133504. static static_codebook _44u3__p6_1 = {
  133505. 2, 25,
  133506. _vq_lengthlist__44u3__p6_1,
  133507. 1, -533725184, 1611661312, 3, 0,
  133508. _vq_quantlist__44u3__p6_1,
  133509. NULL,
  133510. &_vq_auxt__44u3__p6_1,
  133511. NULL,
  133512. 0
  133513. };
  133514. static long _vq_quantlist__44u3__p7_0[] = {
  133515. 4,
  133516. 3,
  133517. 5,
  133518. 2,
  133519. 6,
  133520. 1,
  133521. 7,
  133522. 0,
  133523. 8,
  133524. };
  133525. static long _vq_lengthlist__44u3__p7_0[] = {
  133526. 1, 3, 3,10,10,10,10,10,10, 4,10,10,10,10,10,10,
  133527. 10,10, 4,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  133528. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133529. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133530. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133531. 9,
  133532. };
  133533. static float _vq_quantthresh__44u3__p7_0[] = {
  133534. -892.5, -637.5, -382.5, -127.5, 127.5, 382.5, 637.5, 892.5,
  133535. };
  133536. static long _vq_quantmap__44u3__p7_0[] = {
  133537. 7, 5, 3, 1, 0, 2, 4, 6,
  133538. 8,
  133539. };
  133540. static encode_aux_threshmatch _vq_auxt__44u3__p7_0 = {
  133541. _vq_quantthresh__44u3__p7_0,
  133542. _vq_quantmap__44u3__p7_0,
  133543. 9,
  133544. 9
  133545. };
  133546. static static_codebook _44u3__p7_0 = {
  133547. 2, 81,
  133548. _vq_lengthlist__44u3__p7_0,
  133549. 1, -515907584, 1627381760, 4, 0,
  133550. _vq_quantlist__44u3__p7_0,
  133551. NULL,
  133552. &_vq_auxt__44u3__p7_0,
  133553. NULL,
  133554. 0
  133555. };
  133556. static long _vq_quantlist__44u3__p7_1[] = {
  133557. 7,
  133558. 6,
  133559. 8,
  133560. 5,
  133561. 9,
  133562. 4,
  133563. 10,
  133564. 3,
  133565. 11,
  133566. 2,
  133567. 12,
  133568. 1,
  133569. 13,
  133570. 0,
  133571. 14,
  133572. };
  133573. static long _vq_lengthlist__44u3__p7_1[] = {
  133574. 1, 4, 4, 6, 6, 7, 6, 8, 7, 9, 8,10, 9,11,11, 4,
  133575. 7, 7, 8, 7, 9, 9,10,10,11,11,11,11,12,12, 4, 7,
  133576. 7, 7, 7, 9, 9,10,10,11,11,12,12,12,11, 6, 8, 8,
  133577. 9, 9,10,10,11,11,12,12,13,12,13,13, 6, 8, 8, 9,
  133578. 9,10,11,11,11,12,12,13,14,13,13, 8, 9, 9,11,11,
  133579. 12,12,12,13,14,13,14,14,14,15, 8, 9, 9,11,11,11,
  133580. 12,13,14,13,14,15,17,14,15, 9,10,10,12,12,13,13,
  133581. 13,14,15,15,15,16,16,16, 9,11,11,12,12,13,13,14,
  133582. 14,14,15,16,16,16,16,10,12,12,13,13,14,14,15,15,
  133583. 15,16,17,17,17,17,10,12,11,13,13,15,14,15,14,16,
  133584. 17,16,16,16,16,11,13,12,14,14,14,14,15,16,17,16,
  133585. 17,17,17,17,11,13,12,14,14,14,15,17,16,17,17,17,
  133586. 17,17,17,12,13,13,15,16,15,16,17,17,16,16,17,17,
  133587. 17,17,12,13,13,15,15,15,16,17,17,17,16,17,16,17,
  133588. 17,
  133589. };
  133590. static float _vq_quantthresh__44u3__p7_1[] = {
  133591. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  133592. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  133593. };
  133594. static long _vq_quantmap__44u3__p7_1[] = {
  133595. 13, 11, 9, 7, 5, 3, 1, 0,
  133596. 2, 4, 6, 8, 10, 12, 14,
  133597. };
  133598. static encode_aux_threshmatch _vq_auxt__44u3__p7_1 = {
  133599. _vq_quantthresh__44u3__p7_1,
  133600. _vq_quantmap__44u3__p7_1,
  133601. 15,
  133602. 15
  133603. };
  133604. static static_codebook _44u3__p7_1 = {
  133605. 2, 225,
  133606. _vq_lengthlist__44u3__p7_1,
  133607. 1, -522338304, 1620115456, 4, 0,
  133608. _vq_quantlist__44u3__p7_1,
  133609. NULL,
  133610. &_vq_auxt__44u3__p7_1,
  133611. NULL,
  133612. 0
  133613. };
  133614. static long _vq_quantlist__44u3__p7_2[] = {
  133615. 8,
  133616. 7,
  133617. 9,
  133618. 6,
  133619. 10,
  133620. 5,
  133621. 11,
  133622. 4,
  133623. 12,
  133624. 3,
  133625. 13,
  133626. 2,
  133627. 14,
  133628. 1,
  133629. 15,
  133630. 0,
  133631. 16,
  133632. };
  133633. static long _vq_lengthlist__44u3__p7_2[] = {
  133634. 2, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  133635. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133636. 10,10, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  133637. 9,10, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133638. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  133639. 9,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133640. 10,10,10,10,10,10, 7, 8, 8, 9, 8, 9, 9, 9, 9,10,
  133641. 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133642. 9,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9,10,
  133643. 9,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  133644. 9,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  133645. 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,
  133646. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10,
  133647. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  133648. 10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,10,
  133649. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,
  133650. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  133651. 9,10,10,10,10,10,10,10,10,10,10,10,11,11,11,10,
  133652. 11,
  133653. };
  133654. static float _vq_quantthresh__44u3__p7_2[] = {
  133655. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  133656. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  133657. };
  133658. static long _vq_quantmap__44u3__p7_2[] = {
  133659. 15, 13, 11, 9, 7, 5, 3, 1,
  133660. 0, 2, 4, 6, 8, 10, 12, 14,
  133661. 16,
  133662. };
  133663. static encode_aux_threshmatch _vq_auxt__44u3__p7_2 = {
  133664. _vq_quantthresh__44u3__p7_2,
  133665. _vq_quantmap__44u3__p7_2,
  133666. 17,
  133667. 17
  133668. };
  133669. static static_codebook _44u3__p7_2 = {
  133670. 2, 289,
  133671. _vq_lengthlist__44u3__p7_2,
  133672. 1, -529530880, 1611661312, 5, 0,
  133673. _vq_quantlist__44u3__p7_2,
  133674. NULL,
  133675. &_vq_auxt__44u3__p7_2,
  133676. NULL,
  133677. 0
  133678. };
  133679. static long _huff_lengthlist__44u3__short[] = {
  133680. 14,14,14,15,13,15,12,16,10, 8, 7, 9, 9, 8,12,16,
  133681. 10, 5, 4, 6, 5, 6, 9,16,14, 8, 6, 8, 7, 8,10,16,
  133682. 14, 7, 4, 6, 3, 5, 8,16,15, 9, 5, 7, 4, 4, 7,16,
  133683. 13,10, 6, 7, 4, 3, 4,13,13,12, 7, 9, 5, 5, 6,12,
  133684. };
  133685. static static_codebook _huff_book__44u3__short = {
  133686. 2, 64,
  133687. _huff_lengthlist__44u3__short,
  133688. 0, 0, 0, 0, 0,
  133689. NULL,
  133690. NULL,
  133691. NULL,
  133692. NULL,
  133693. 0
  133694. };
  133695. static long _huff_lengthlist__44u4__long[] = {
  133696. 3, 8,12,12,13,12,11,13, 5, 4, 6, 7, 8, 8, 9,13,
  133697. 9, 5, 4, 5, 5, 7, 9,13, 9, 6, 5, 6, 6, 7, 8,12,
  133698. 12, 7, 5, 6, 4, 5, 8,13,11, 7, 6, 6, 5, 5, 6,12,
  133699. 10, 8, 8, 7, 7, 5, 3, 8,10,12,13,12,12, 9, 6, 7,
  133700. };
  133701. static static_codebook _huff_book__44u4__long = {
  133702. 2, 64,
  133703. _huff_lengthlist__44u4__long,
  133704. 0, 0, 0, 0, 0,
  133705. NULL,
  133706. NULL,
  133707. NULL,
  133708. NULL,
  133709. 0
  133710. };
  133711. static long _vq_quantlist__44u4__p1_0[] = {
  133712. 1,
  133713. 0,
  133714. 2,
  133715. };
  133716. static long _vq_lengthlist__44u4__p1_0[] = {
  133717. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  133718. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133719. 11, 8,11,11, 8,11,11,11,13,14,11,15,14, 8,11,11,
  133720. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  133721. 11,11,11,15,14,10,12,14, 8,11,11,11,14,14,11,14,
  133722. 13,
  133723. };
  133724. static float _vq_quantthresh__44u4__p1_0[] = {
  133725. -0.5, 0.5,
  133726. };
  133727. static long _vq_quantmap__44u4__p1_0[] = {
  133728. 1, 0, 2,
  133729. };
  133730. static encode_aux_threshmatch _vq_auxt__44u4__p1_0 = {
  133731. _vq_quantthresh__44u4__p1_0,
  133732. _vq_quantmap__44u4__p1_0,
  133733. 3,
  133734. 3
  133735. };
  133736. static static_codebook _44u4__p1_0 = {
  133737. 4, 81,
  133738. _vq_lengthlist__44u4__p1_0,
  133739. 1, -535822336, 1611661312, 2, 0,
  133740. _vq_quantlist__44u4__p1_0,
  133741. NULL,
  133742. &_vq_auxt__44u4__p1_0,
  133743. NULL,
  133744. 0
  133745. };
  133746. static long _vq_quantlist__44u4__p2_0[] = {
  133747. 1,
  133748. 0,
  133749. 2,
  133750. };
  133751. static long _vq_lengthlist__44u4__p2_0[] = {
  133752. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133753. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 6, 8,
  133754. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133755. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 6, 8, 8, 6,
  133756. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  133757. 9,
  133758. };
  133759. static float _vq_quantthresh__44u4__p2_0[] = {
  133760. -0.5, 0.5,
  133761. };
  133762. static long _vq_quantmap__44u4__p2_0[] = {
  133763. 1, 0, 2,
  133764. };
  133765. static encode_aux_threshmatch _vq_auxt__44u4__p2_0 = {
  133766. _vq_quantthresh__44u4__p2_0,
  133767. _vq_quantmap__44u4__p2_0,
  133768. 3,
  133769. 3
  133770. };
  133771. static static_codebook _44u4__p2_0 = {
  133772. 4, 81,
  133773. _vq_lengthlist__44u4__p2_0,
  133774. 1, -535822336, 1611661312, 2, 0,
  133775. _vq_quantlist__44u4__p2_0,
  133776. NULL,
  133777. &_vq_auxt__44u4__p2_0,
  133778. NULL,
  133779. 0
  133780. };
  133781. static long _vq_quantlist__44u4__p3_0[] = {
  133782. 2,
  133783. 1,
  133784. 3,
  133785. 0,
  133786. 4,
  133787. };
  133788. static long _vq_lengthlist__44u4__p3_0[] = {
  133789. 2, 4, 4, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133790. 10, 9,12,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  133791. 9,11,11, 7, 9, 9,11,11,10,12,11,14,14, 9,10,11,
  133792. 13,14, 5, 7, 7,10,10, 7, 9, 9,11,11, 7, 9, 9,11,
  133793. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  133794. 10,12,12,15,14, 9,11,11,15,14,13,14,14,17,17,12,
  133795. 14,14,16,16, 8,10,10,14,14, 9,11,11,14,15,10,12,
  133796. 12,14,15,12,14,13,16,16,13,14,15,15,18, 4, 7, 7,
  133797. 10,10, 7, 9, 9,12,11, 7, 9, 9,11,12,10,12,11,15,
  133798. 14,10,11,12,14,15, 7, 9, 9,12,12, 9,11,12,13,13,
  133799. 9,11,12,13,13,12,13,13,15,16,11,13,13,15,16, 7,
  133800. 9, 9,12,12, 9,11,10,13,12, 9,11,12,13,14,11,13,
  133801. 12,16,14,12,13,13,15,16,10,12,12,16,15,11,13,13,
  133802. 17,16,11,13,13,17,16,14,15,15,17,17,14,16,16,18,
  133803. 20, 9,11,11,15,16,11,13,12,16,16,11,13,13,16,17,
  133804. 14,15,14,18,16,14,16,16,17,20, 5, 7, 7,10,10, 7,
  133805. 9, 9,12,11, 7, 9,10,11,12,10,12,11,15,15,10,12,
  133806. 12,14,14, 7, 9, 9,12,12, 9,12,11,14,13, 9,10,11,
  133807. 12,13,12,13,14,16,16,11,12,13,14,16, 7, 9, 9,12,
  133808. 12, 9,12,11,13,13, 9,12,11,13,13,11,13,13,16,16,
  133809. 12,13,13,16,15, 9,11,11,16,14,11,13,13,16,16,11,
  133810. 12,13,16,16,14,16,16,17,17,13,14,15,16,17,10,12,
  133811. 12,15,15,11,13,13,16,17,11,13,13,16,16,14,16,15,
  133812. 19,19,14,15,15,17,18, 8,10,10,14,14,10,12,12,15,
  133813. 15,10,12,12,16,16,14,16,15,20,19,13,15,15,17,16,
  133814. 9,12,12,16,16,11,13,13,16,18,11,14,13,16,17,16,
  133815. 17,16,20, 0,15,16,18,18,20, 9,11,11,15,15,11,14,
  133816. 12,17,16,11,13,13,17,17,15,17,15,20,20,14,16,16,
  133817. 17, 0,13,15,14,18,16,14,15,16, 0,18,14,16,16, 0,
  133818. 0,18,16, 0, 0,20,16,18,18, 0, 0,12,14,14,17,18,
  133819. 13,15,14,20,18,14,16,15,19,19,16,20,16, 0,18,16,
  133820. 19,17,19, 0, 8,10,10,14,14,10,12,12,16,15,10,12,
  133821. 12,16,16,13,15,15,18,17,14,16,16,19, 0, 9,11,11,
  133822. 16,15,11,14,13,18,17,11,12,13,17,18,14,17,16,18,
  133823. 18,15,16,17,18,18, 9,12,12,16,16,11,13,13,16,18,
  133824. 11,14,13,17,17,15,16,16,18,20,16,17,17,20,20,12,
  133825. 14,14,18,17,14,16,16, 0,19,13,14,15,18, 0,16, 0,
  133826. 0, 0, 0,16,16, 0,19,20,13,15,14, 0, 0,14,16,16,
  133827. 18,19,14,16,15, 0,20,16,20,18, 0,20,17,20,17, 0,
  133828. 0,
  133829. };
  133830. static float _vq_quantthresh__44u4__p3_0[] = {
  133831. -1.5, -0.5, 0.5, 1.5,
  133832. };
  133833. static long _vq_quantmap__44u4__p3_0[] = {
  133834. 3, 1, 0, 2, 4,
  133835. };
  133836. static encode_aux_threshmatch _vq_auxt__44u4__p3_0 = {
  133837. _vq_quantthresh__44u4__p3_0,
  133838. _vq_quantmap__44u4__p3_0,
  133839. 5,
  133840. 5
  133841. };
  133842. static static_codebook _44u4__p3_0 = {
  133843. 4, 625,
  133844. _vq_lengthlist__44u4__p3_0,
  133845. 1, -533725184, 1611661312, 3, 0,
  133846. _vq_quantlist__44u4__p3_0,
  133847. NULL,
  133848. &_vq_auxt__44u4__p3_0,
  133849. NULL,
  133850. 0
  133851. };
  133852. static long _vq_quantlist__44u4__p4_0[] = {
  133853. 2,
  133854. 1,
  133855. 3,
  133856. 0,
  133857. 4,
  133858. };
  133859. static long _vq_lengthlist__44u4__p4_0[] = {
  133860. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133861. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133862. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  133863. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  133864. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  133865. 9,10,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  133866. 12,12,13,14, 9, 9,10,12,12, 9,10,10,13,13, 9,10,
  133867. 10,12,13,11,12,12,14,13,11,12,12,14,14, 5, 7, 7,
  133868. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133869. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133870. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  133871. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133872. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  133873. 13,14,10,11,11,14,13,12,12,13,12,15,12,13,13,15,
  133874. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  133875. 12,13,11,15,13,13,13,13,15,15, 5, 7, 7, 9, 9, 7,
  133876. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  133877. 11,12,13, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133878. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133879. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  133880. 11,12,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133881. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  133882. 11,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  133883. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133884. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  133885. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,13,13,
  133886. 13,14,14,16,13,13,13,15,15, 9,10,10,13,13,10,11,
  133887. 10,14,13,10,11,11,13,14,12,14,13,16,14,12,13,13,
  133888. 14,15,11,12,12,15,14,11,12,13,14,15,12,13,13,16,
  133889. 15,14,12,15,12,16,14,15,15,16,16,11,12,12,14,14,
  133890. 11,13,12,15,14,12,13,13,15,16,13,15,13,17,13,14,
  133891. 15,15,16,17, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  133892. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  133893. 13,12,10,11,11,14,13,10,10,11,13,14,13,13,13,15,
  133894. 15,12,13,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  133895. 10,11,11,14,14,13,13,13,15,15,13,14,13,16,14,11,
  133896. 12,12,15,14,12,13,13,16,15,11,12,13,14,15,14,15,
  133897. 15,17,16,13,13,15,13,16,11,12,13,14,15,13,13,13,
  133898. 15,16,11,13,12,15,14,14,15,15,16,16,14,15,12,17,
  133899. 13,
  133900. };
  133901. static float _vq_quantthresh__44u4__p4_0[] = {
  133902. -1.5, -0.5, 0.5, 1.5,
  133903. };
  133904. static long _vq_quantmap__44u4__p4_0[] = {
  133905. 3, 1, 0, 2, 4,
  133906. };
  133907. static encode_aux_threshmatch _vq_auxt__44u4__p4_0 = {
  133908. _vq_quantthresh__44u4__p4_0,
  133909. _vq_quantmap__44u4__p4_0,
  133910. 5,
  133911. 5
  133912. };
  133913. static static_codebook _44u4__p4_0 = {
  133914. 4, 625,
  133915. _vq_lengthlist__44u4__p4_0,
  133916. 1, -533725184, 1611661312, 3, 0,
  133917. _vq_quantlist__44u4__p4_0,
  133918. NULL,
  133919. &_vq_auxt__44u4__p4_0,
  133920. NULL,
  133921. 0
  133922. };
  133923. static long _vq_quantlist__44u4__p5_0[] = {
  133924. 4,
  133925. 3,
  133926. 5,
  133927. 2,
  133928. 6,
  133929. 1,
  133930. 7,
  133931. 0,
  133932. 8,
  133933. };
  133934. static long _vq_lengthlist__44u4__p5_0[] = {
  133935. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  133936. 10, 9, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  133937. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,11, 7, 8, 8,
  133938. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  133939. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  133940. 12,
  133941. };
  133942. static float _vq_quantthresh__44u4__p5_0[] = {
  133943. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133944. };
  133945. static long _vq_quantmap__44u4__p5_0[] = {
  133946. 7, 5, 3, 1, 0, 2, 4, 6,
  133947. 8,
  133948. };
  133949. static encode_aux_threshmatch _vq_auxt__44u4__p5_0 = {
  133950. _vq_quantthresh__44u4__p5_0,
  133951. _vq_quantmap__44u4__p5_0,
  133952. 9,
  133953. 9
  133954. };
  133955. static static_codebook _44u4__p5_0 = {
  133956. 2, 81,
  133957. _vq_lengthlist__44u4__p5_0,
  133958. 1, -531628032, 1611661312, 4, 0,
  133959. _vq_quantlist__44u4__p5_0,
  133960. NULL,
  133961. &_vq_auxt__44u4__p5_0,
  133962. NULL,
  133963. 0
  133964. };
  133965. static long _vq_quantlist__44u4__p6_0[] = {
  133966. 6,
  133967. 5,
  133968. 7,
  133969. 4,
  133970. 8,
  133971. 3,
  133972. 9,
  133973. 2,
  133974. 10,
  133975. 1,
  133976. 11,
  133977. 0,
  133978. 12,
  133979. };
  133980. static long _vq_lengthlist__44u4__p6_0[] = {
  133981. 1, 4, 4, 6, 6, 8, 8, 9, 9,11,10,13,13, 4, 6, 5,
  133982. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  133983. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  133984. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  133985. 15, 8, 9, 9,11,10,11,11,12,12,13,13,16,16, 8, 9,
  133986. 9,10,10,11,11,12,12,13,13,16,16,10,10,10,12,11,
  133987. 12,12,13,13,14,14,16,16,10,10,10,11,12,12,12,13,
  133988. 13,13,14,16,17,11,12,11,12,12,13,13,14,14,15,14,
  133989. 18,17,11,11,12,12,12,13,13,14,14,14,15,19,18,14,
  133990. 15,14,15,15,17,16,17,17,17,17,21, 0,14,15,15,16,
  133991. 16,16,16,17,17,18,17,20,21,
  133992. };
  133993. static float _vq_quantthresh__44u4__p6_0[] = {
  133994. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133995. 12.5, 17.5, 22.5, 27.5,
  133996. };
  133997. static long _vq_quantmap__44u4__p6_0[] = {
  133998. 11, 9, 7, 5, 3, 1, 0, 2,
  133999. 4, 6, 8, 10, 12,
  134000. };
  134001. static encode_aux_threshmatch _vq_auxt__44u4__p6_0 = {
  134002. _vq_quantthresh__44u4__p6_0,
  134003. _vq_quantmap__44u4__p6_0,
  134004. 13,
  134005. 13
  134006. };
  134007. static static_codebook _44u4__p6_0 = {
  134008. 2, 169,
  134009. _vq_lengthlist__44u4__p6_0,
  134010. 1, -526516224, 1616117760, 4, 0,
  134011. _vq_quantlist__44u4__p6_0,
  134012. NULL,
  134013. &_vq_auxt__44u4__p6_0,
  134014. NULL,
  134015. 0
  134016. };
  134017. static long _vq_quantlist__44u4__p6_1[] = {
  134018. 2,
  134019. 1,
  134020. 3,
  134021. 0,
  134022. 4,
  134023. };
  134024. static long _vq_lengthlist__44u4__p6_1[] = {
  134025. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  134026. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  134027. };
  134028. static float _vq_quantthresh__44u4__p6_1[] = {
  134029. -1.5, -0.5, 0.5, 1.5,
  134030. };
  134031. static long _vq_quantmap__44u4__p6_1[] = {
  134032. 3, 1, 0, 2, 4,
  134033. };
  134034. static encode_aux_threshmatch _vq_auxt__44u4__p6_1 = {
  134035. _vq_quantthresh__44u4__p6_1,
  134036. _vq_quantmap__44u4__p6_1,
  134037. 5,
  134038. 5
  134039. };
  134040. static static_codebook _44u4__p6_1 = {
  134041. 2, 25,
  134042. _vq_lengthlist__44u4__p6_1,
  134043. 1, -533725184, 1611661312, 3, 0,
  134044. _vq_quantlist__44u4__p6_1,
  134045. NULL,
  134046. &_vq_auxt__44u4__p6_1,
  134047. NULL,
  134048. 0
  134049. };
  134050. static long _vq_quantlist__44u4__p7_0[] = {
  134051. 6,
  134052. 5,
  134053. 7,
  134054. 4,
  134055. 8,
  134056. 3,
  134057. 9,
  134058. 2,
  134059. 10,
  134060. 1,
  134061. 11,
  134062. 0,
  134063. 12,
  134064. };
  134065. static long _vq_lengthlist__44u4__p7_0[] = {
  134066. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 3,12,11,
  134067. 12,12,12,12,12,12,12,12,12,12, 4,11,10,12,12,12,
  134068. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134069. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134070. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134071. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134072. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134073. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134074. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134075. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134076. 11,11,11,11,11,11,11,11,11,
  134077. };
  134078. static float _vq_quantthresh__44u4__p7_0[] = {
  134079. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  134080. 637.5, 892.5, 1147.5, 1402.5,
  134081. };
  134082. static long _vq_quantmap__44u4__p7_0[] = {
  134083. 11, 9, 7, 5, 3, 1, 0, 2,
  134084. 4, 6, 8, 10, 12,
  134085. };
  134086. static encode_aux_threshmatch _vq_auxt__44u4__p7_0 = {
  134087. _vq_quantthresh__44u4__p7_0,
  134088. _vq_quantmap__44u4__p7_0,
  134089. 13,
  134090. 13
  134091. };
  134092. static static_codebook _44u4__p7_0 = {
  134093. 2, 169,
  134094. _vq_lengthlist__44u4__p7_0,
  134095. 1, -514332672, 1627381760, 4, 0,
  134096. _vq_quantlist__44u4__p7_0,
  134097. NULL,
  134098. &_vq_auxt__44u4__p7_0,
  134099. NULL,
  134100. 0
  134101. };
  134102. static long _vq_quantlist__44u4__p7_1[] = {
  134103. 7,
  134104. 6,
  134105. 8,
  134106. 5,
  134107. 9,
  134108. 4,
  134109. 10,
  134110. 3,
  134111. 11,
  134112. 2,
  134113. 12,
  134114. 1,
  134115. 13,
  134116. 0,
  134117. 14,
  134118. };
  134119. static long _vq_lengthlist__44u4__p7_1[] = {
  134120. 1, 4, 4, 6, 6, 7, 7, 9, 8,10, 8,10, 9,11,11, 4,
  134121. 7, 6, 8, 7, 9, 9,10,10,11,10,11,10,12,10, 4, 6,
  134122. 7, 8, 8, 9, 9,10,10,11,11,11,11,12,12, 6, 8, 8,
  134123. 10, 9,11,10,12,11,12,12,12,12,13,13, 6, 8, 8,10,
  134124. 10,10,11,11,11,12,12,13,12,13,13, 8, 9, 9,11,11,
  134125. 12,11,12,12,13,13,13,13,13,13, 8, 9, 9,11,11,11,
  134126. 12,12,12,13,13,13,13,13,13, 9,10,10,12,11,13,13,
  134127. 13,13,14,13,13,14,14,14, 9,10,11,11,12,12,13,13,
  134128. 13,13,13,14,15,14,14,10,11,11,12,12,13,13,14,14,
  134129. 14,14,14,15,16,16,10,11,11,12,13,13,13,13,15,14,
  134130. 14,15,16,15,16,10,12,12,13,13,14,14,14,15,15,15,
  134131. 15,15,15,16,11,12,12,13,13,14,14,14,15,15,15,16,
  134132. 15,17,16,11,12,12,13,13,13,15,15,14,16,16,16,16,
  134133. 16,17,11,12,12,13,13,14,14,15,14,15,15,17,17,16,
  134134. 16,
  134135. };
  134136. static float _vq_quantthresh__44u4__p7_1[] = {
  134137. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134138. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134139. };
  134140. static long _vq_quantmap__44u4__p7_1[] = {
  134141. 13, 11, 9, 7, 5, 3, 1, 0,
  134142. 2, 4, 6, 8, 10, 12, 14,
  134143. };
  134144. static encode_aux_threshmatch _vq_auxt__44u4__p7_1 = {
  134145. _vq_quantthresh__44u4__p7_1,
  134146. _vq_quantmap__44u4__p7_1,
  134147. 15,
  134148. 15
  134149. };
  134150. static static_codebook _44u4__p7_1 = {
  134151. 2, 225,
  134152. _vq_lengthlist__44u4__p7_1,
  134153. 1, -522338304, 1620115456, 4, 0,
  134154. _vq_quantlist__44u4__p7_1,
  134155. NULL,
  134156. &_vq_auxt__44u4__p7_1,
  134157. NULL,
  134158. 0
  134159. };
  134160. static long _vq_quantlist__44u4__p7_2[] = {
  134161. 8,
  134162. 7,
  134163. 9,
  134164. 6,
  134165. 10,
  134166. 5,
  134167. 11,
  134168. 4,
  134169. 12,
  134170. 3,
  134171. 13,
  134172. 2,
  134173. 14,
  134174. 1,
  134175. 15,
  134176. 0,
  134177. 16,
  134178. };
  134179. static long _vq_lengthlist__44u4__p7_2[] = {
  134180. 2, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134181. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134182. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134183. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134184. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  134185. 9,10, 9,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134186. 10,10,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134187. 9,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134188. 10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  134189. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,
  134190. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  134191. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  134192. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  134193. 10,10,10,10,10,10,10,10,10,11,10,10,10, 9, 9, 9,
  134194. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  134195. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  134196. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  134197. 9,10, 9,10,10,10,10,10,10,10,10,10,10,11,10,10,
  134198. 10,
  134199. };
  134200. static float _vq_quantthresh__44u4__p7_2[] = {
  134201. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134202. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134203. };
  134204. static long _vq_quantmap__44u4__p7_2[] = {
  134205. 15, 13, 11, 9, 7, 5, 3, 1,
  134206. 0, 2, 4, 6, 8, 10, 12, 14,
  134207. 16,
  134208. };
  134209. static encode_aux_threshmatch _vq_auxt__44u4__p7_2 = {
  134210. _vq_quantthresh__44u4__p7_2,
  134211. _vq_quantmap__44u4__p7_2,
  134212. 17,
  134213. 17
  134214. };
  134215. static static_codebook _44u4__p7_2 = {
  134216. 2, 289,
  134217. _vq_lengthlist__44u4__p7_2,
  134218. 1, -529530880, 1611661312, 5, 0,
  134219. _vq_quantlist__44u4__p7_2,
  134220. NULL,
  134221. &_vq_auxt__44u4__p7_2,
  134222. NULL,
  134223. 0
  134224. };
  134225. static long _huff_lengthlist__44u4__short[] = {
  134226. 14,17,15,17,16,14,13,16,10, 7, 7,10,13,10,15,16,
  134227. 9, 4, 4, 6, 5, 7, 9,16,12, 8, 7, 8, 8, 8,11,16,
  134228. 14, 7, 4, 6, 3, 5, 8,15,13, 8, 5, 7, 4, 5, 7,16,
  134229. 12, 9, 6, 8, 3, 3, 5,16,14,13, 7,10, 5, 5, 7,15,
  134230. };
  134231. static static_codebook _huff_book__44u4__short = {
  134232. 2, 64,
  134233. _huff_lengthlist__44u4__short,
  134234. 0, 0, 0, 0, 0,
  134235. NULL,
  134236. NULL,
  134237. NULL,
  134238. NULL,
  134239. 0
  134240. };
  134241. static long _huff_lengthlist__44u5__long[] = {
  134242. 3, 8,13,12,14,12,16,11,13,14, 5, 4, 5, 6, 7, 8,
  134243. 10, 9,12,15,10, 5, 5, 5, 6, 8, 9, 9,13,15,10, 5,
  134244. 5, 6, 6, 7, 8, 8,11,13,12, 7, 5, 6, 4, 6, 7, 7,
  134245. 11,14,11, 7, 7, 6, 6, 6, 7, 6,10,14,14, 9, 8, 8,
  134246. 6, 7, 7, 7,11,16,11, 8, 8, 7, 6, 6, 7, 4, 7,12,
  134247. 10,10,12,10,10, 9,10, 5, 6, 9,10,12,15,13,14,14,
  134248. 14, 8, 7, 8,
  134249. };
  134250. static static_codebook _huff_book__44u5__long = {
  134251. 2, 100,
  134252. _huff_lengthlist__44u5__long,
  134253. 0, 0, 0, 0, 0,
  134254. NULL,
  134255. NULL,
  134256. NULL,
  134257. NULL,
  134258. 0
  134259. };
  134260. static long _vq_quantlist__44u5__p1_0[] = {
  134261. 1,
  134262. 0,
  134263. 2,
  134264. };
  134265. static long _vq_lengthlist__44u5__p1_0[] = {
  134266. 1, 4, 4, 5, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  134267. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  134268. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  134269. 10,13,11,10,13,13, 4, 8, 8, 8,11,10, 8,10,10, 7,
  134270. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  134271. 12,
  134272. };
  134273. static float _vq_quantthresh__44u5__p1_0[] = {
  134274. -0.5, 0.5,
  134275. };
  134276. static long _vq_quantmap__44u5__p1_0[] = {
  134277. 1, 0, 2,
  134278. };
  134279. static encode_aux_threshmatch _vq_auxt__44u5__p1_0 = {
  134280. _vq_quantthresh__44u5__p1_0,
  134281. _vq_quantmap__44u5__p1_0,
  134282. 3,
  134283. 3
  134284. };
  134285. static static_codebook _44u5__p1_0 = {
  134286. 4, 81,
  134287. _vq_lengthlist__44u5__p1_0,
  134288. 1, -535822336, 1611661312, 2, 0,
  134289. _vq_quantlist__44u5__p1_0,
  134290. NULL,
  134291. &_vq_auxt__44u5__p1_0,
  134292. NULL,
  134293. 0
  134294. };
  134295. static long _vq_quantlist__44u5__p2_0[] = {
  134296. 1,
  134297. 0,
  134298. 2,
  134299. };
  134300. static long _vq_lengthlist__44u5__p2_0[] = {
  134301. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  134302. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  134303. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  134304. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  134305. 8, 7, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  134306. 9,
  134307. };
  134308. static float _vq_quantthresh__44u5__p2_0[] = {
  134309. -0.5, 0.5,
  134310. };
  134311. static long _vq_quantmap__44u5__p2_0[] = {
  134312. 1, 0, 2,
  134313. };
  134314. static encode_aux_threshmatch _vq_auxt__44u5__p2_0 = {
  134315. _vq_quantthresh__44u5__p2_0,
  134316. _vq_quantmap__44u5__p2_0,
  134317. 3,
  134318. 3
  134319. };
  134320. static static_codebook _44u5__p2_0 = {
  134321. 4, 81,
  134322. _vq_lengthlist__44u5__p2_0,
  134323. 1, -535822336, 1611661312, 2, 0,
  134324. _vq_quantlist__44u5__p2_0,
  134325. NULL,
  134326. &_vq_auxt__44u5__p2_0,
  134327. NULL,
  134328. 0
  134329. };
  134330. static long _vq_quantlist__44u5__p3_0[] = {
  134331. 2,
  134332. 1,
  134333. 3,
  134334. 0,
  134335. 4,
  134336. };
  134337. static long _vq_lengthlist__44u5__p3_0[] = {
  134338. 2, 4, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  134339. 10, 9,13,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  134340. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  134341. 13,14, 5, 7, 7, 9,10, 7, 9, 8,11,11, 7, 9, 9,11,
  134342. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,13,13,
  134343. 10,11,11,15,14, 9,11,11,14,14,13,14,14,17,16,12,
  134344. 13,13,15,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  134345. 11,14,15,12,14,13,16,16,13,15,14,15,17, 5, 7, 7,
  134346. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,
  134347. 14,10,11,12,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  134348. 9,11,11,13,13,12,13,13,15,16,11,12,13,15,16, 6,
  134349. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,14,11,13,
  134350. 12,16,14,11,13,13,16,17,10,12,11,15,15,11,13,13,
  134351. 16,16,11,13,13,17,16,14,15,15,17,17,14,16,16,17,
  134352. 18, 9,11,11,14,15,10,12,12,15,15,11,13,13,16,17,
  134353. 13,15,13,17,15,14,15,16,18, 0, 5, 7, 7,10,10, 7,
  134354. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  134355. 12,14,15, 6, 9, 9,12,11, 9,11,11,13,13, 8,10,11,
  134356. 12,13,11,13,13,16,15,11,12,13,14,15, 7, 9, 9,11,
  134357. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,16,
  134358. 11,13,13,15,14, 9,11,11,15,14,11,13,13,17,15,10,
  134359. 12,12,15,15,14,16,16,17,17,13,13,15,15,17,10,11,
  134360. 12,15,15,11,13,13,16,16,11,13,13,15,15,14,15,15,
  134361. 18,18,14,15,15,17,17, 8,10,10,13,13,10,12,11,15,
  134362. 15,10,11,12,15,15,14,15,15,18,18,13,14,14,18,18,
  134363. 9,11,11,15,16,11,13,13,17,17,11,13,13,16,16,15,
  134364. 15,16,17, 0,14,15,17, 0, 0, 9,11,11,15,15,10,13,
  134365. 12,18,16,11,13,13,15,16,14,16,15,20,20,14,15,16,
  134366. 17, 0,13,14,14,20,16,14,15,16,19,18,14,15,15,19,
  134367. 0,18,16, 0,20,20,16,18,18, 0, 0,12,14,14,18,18,
  134368. 13,15,14,18,16,14,15,16,18,20,16,19,16, 0,17,17,
  134369. 18,18,19, 0, 8,10,10,14,14,10,11,11,14,15,10,11,
  134370. 12,15,15,13,15,14,19,17,13,15,15,17, 0, 9,11,11,
  134371. 16,15,11,13,13,16,16,10,12,13,15,17,14,16,16,18,
  134372. 18,14,15,15,18, 0, 9,11,11,15,15,11,13,13,16,17,
  134373. 11,13,13,18,17,14,18,16,18,18,15,17,17,18, 0,12,
  134374. 14,14,18,18,14,15,15,20, 0,13,14,15,17, 0,16,18,
  134375. 17, 0, 0,16,16, 0,17,20,12,14,14,18,18,14,16,15,
  134376. 0,18,14,16,15,18, 0,16,19,17, 0, 0,17,18,16, 0,
  134377. 0,
  134378. };
  134379. static float _vq_quantthresh__44u5__p3_0[] = {
  134380. -1.5, -0.5, 0.5, 1.5,
  134381. };
  134382. static long _vq_quantmap__44u5__p3_0[] = {
  134383. 3, 1, 0, 2, 4,
  134384. };
  134385. static encode_aux_threshmatch _vq_auxt__44u5__p3_0 = {
  134386. _vq_quantthresh__44u5__p3_0,
  134387. _vq_quantmap__44u5__p3_0,
  134388. 5,
  134389. 5
  134390. };
  134391. static static_codebook _44u5__p3_0 = {
  134392. 4, 625,
  134393. _vq_lengthlist__44u5__p3_0,
  134394. 1, -533725184, 1611661312, 3, 0,
  134395. _vq_quantlist__44u5__p3_0,
  134396. NULL,
  134397. &_vq_auxt__44u5__p3_0,
  134398. NULL,
  134399. 0
  134400. };
  134401. static long _vq_quantlist__44u5__p4_0[] = {
  134402. 2,
  134403. 1,
  134404. 3,
  134405. 0,
  134406. 4,
  134407. };
  134408. static long _vq_lengthlist__44u5__p4_0[] = {
  134409. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  134410. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  134411. 8,10,10, 6, 7, 8, 9,10, 9,10,10,11,12, 9, 9,10,
  134412. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  134413. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,12,11,
  134414. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  134415. 11,12,13,14, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134416. 10,12,12,11,12,11,14,13,11,12,12,13,13, 5, 7, 7,
  134417. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  134418. 12, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,10,11,
  134419. 8, 9, 9,11,11,10,10,11,11,13,10,11,11,12,13, 6,
  134420. 7, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  134421. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  134422. 12,13,10,11,11,13,13,12,11,13,12,15,12,13,13,14,
  134423. 15, 9,10,10,12,12, 9,11,10,13,12,10,11,11,13,13,
  134424. 11,13,11,14,12,12,13,13,14,15, 5, 7, 7, 9, 9, 7,
  134425. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  134426. 10,12,12, 6, 8, 7,10,10, 8, 9, 9,11,11, 7, 8, 9,
  134427. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  134428. 10, 8, 9, 9,11,11, 8, 9, 8,11,10,10,11,11,13,12,
  134429. 10,11,10,13,11, 9,10,10,12,12,10,11,11,13,12, 9,
  134430. 10,10,12,13,12,13,13,14,15,11,11,13,12,14, 9,10,
  134431. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,13,13,
  134432. 14,14,12,13,11,14,12, 8, 9, 9,12,12, 9,10,10,12,
  134433. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,14,13,
  134434. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  134435. 12,13,14,15,12,13,13,15,14, 9,10,10,12,12,10,11,
  134436. 10,13,12,10,11,11,12,13,12,13,12,15,13,12,13,13,
  134437. 14,15,11,12,12,14,13,11,12,12,14,15,12,13,13,15,
  134438. 14,13,12,14,12,16,13,14,14,15,15,11,11,12,14,14,
  134439. 11,12,11,14,13,12,13,13,14,15,13,14,12,16,12,14,
  134440. 14,15,16,16, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134441. 10,12,13,11,12,12,13,13,12,12,13,14,14, 9,10,10,
  134442. 12,12,10,11,10,13,12,10,10,11,12,13,12,13,13,15,
  134443. 14,12,12,13,13,15, 9,10,10,12,13,10,11,11,12,13,
  134444. 10,11,11,13,13,12,13,13,14,15,12,13,12,15,14,11,
  134445. 12,11,14,13,12,13,13,15,14,11,11,12,13,14,14,15,
  134446. 14,16,15,13,12,14,13,16,11,12,12,13,14,12,13,13,
  134447. 14,15,11,12,11,14,14,14,14,14,15,16,13,15,12,16,
  134448. 12,
  134449. };
  134450. static float _vq_quantthresh__44u5__p4_0[] = {
  134451. -1.5, -0.5, 0.5, 1.5,
  134452. };
  134453. static long _vq_quantmap__44u5__p4_0[] = {
  134454. 3, 1, 0, 2, 4,
  134455. };
  134456. static encode_aux_threshmatch _vq_auxt__44u5__p4_0 = {
  134457. _vq_quantthresh__44u5__p4_0,
  134458. _vq_quantmap__44u5__p4_0,
  134459. 5,
  134460. 5
  134461. };
  134462. static static_codebook _44u5__p4_0 = {
  134463. 4, 625,
  134464. _vq_lengthlist__44u5__p4_0,
  134465. 1, -533725184, 1611661312, 3, 0,
  134466. _vq_quantlist__44u5__p4_0,
  134467. NULL,
  134468. &_vq_auxt__44u5__p4_0,
  134469. NULL,
  134470. 0
  134471. };
  134472. static long _vq_quantlist__44u5__p5_0[] = {
  134473. 4,
  134474. 3,
  134475. 5,
  134476. 2,
  134477. 6,
  134478. 1,
  134479. 7,
  134480. 0,
  134481. 8,
  134482. };
  134483. static long _vq_lengthlist__44u5__p5_0[] = {
  134484. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  134485. 11,10, 3, 5, 5, 7, 8, 8, 8,10,11, 6, 8, 7,10, 9,
  134486. 10,10,11,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  134487. 10,10,11,11,13,12, 8, 8, 9, 9,10,11,11,12,13,10,
  134488. 11,10,12,11,13,12,14,14,10,10,11,11,12,12,13,14,
  134489. 14,
  134490. };
  134491. static float _vq_quantthresh__44u5__p5_0[] = {
  134492. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134493. };
  134494. static long _vq_quantmap__44u5__p5_0[] = {
  134495. 7, 5, 3, 1, 0, 2, 4, 6,
  134496. 8,
  134497. };
  134498. static encode_aux_threshmatch _vq_auxt__44u5__p5_0 = {
  134499. _vq_quantthresh__44u5__p5_0,
  134500. _vq_quantmap__44u5__p5_0,
  134501. 9,
  134502. 9
  134503. };
  134504. static static_codebook _44u5__p5_0 = {
  134505. 2, 81,
  134506. _vq_lengthlist__44u5__p5_0,
  134507. 1, -531628032, 1611661312, 4, 0,
  134508. _vq_quantlist__44u5__p5_0,
  134509. NULL,
  134510. &_vq_auxt__44u5__p5_0,
  134511. NULL,
  134512. 0
  134513. };
  134514. static long _vq_quantlist__44u5__p6_0[] = {
  134515. 4,
  134516. 3,
  134517. 5,
  134518. 2,
  134519. 6,
  134520. 1,
  134521. 7,
  134522. 0,
  134523. 8,
  134524. };
  134525. static long _vq_lengthlist__44u5__p6_0[] = {
  134526. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  134527. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  134528. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  134529. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  134530. 9, 9,10,10,11,10,11,11, 9, 9, 9,10,10,11,10,11,
  134531. 11,
  134532. };
  134533. static float _vq_quantthresh__44u5__p6_0[] = {
  134534. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134535. };
  134536. static long _vq_quantmap__44u5__p6_0[] = {
  134537. 7, 5, 3, 1, 0, 2, 4, 6,
  134538. 8,
  134539. };
  134540. static encode_aux_threshmatch _vq_auxt__44u5__p6_0 = {
  134541. _vq_quantthresh__44u5__p6_0,
  134542. _vq_quantmap__44u5__p6_0,
  134543. 9,
  134544. 9
  134545. };
  134546. static static_codebook _44u5__p6_0 = {
  134547. 2, 81,
  134548. _vq_lengthlist__44u5__p6_0,
  134549. 1, -531628032, 1611661312, 4, 0,
  134550. _vq_quantlist__44u5__p6_0,
  134551. NULL,
  134552. &_vq_auxt__44u5__p6_0,
  134553. NULL,
  134554. 0
  134555. };
  134556. static long _vq_quantlist__44u5__p7_0[] = {
  134557. 1,
  134558. 0,
  134559. 2,
  134560. };
  134561. static long _vq_lengthlist__44u5__p7_0[] = {
  134562. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,11,10, 7,
  134563. 11,10, 5, 9, 9, 7,10,10, 8,10,11, 4, 9, 9, 9,12,
  134564. 12, 9,12,12, 8,12,12,11,12,12,10,12,13, 7,12,12,
  134565. 11,12,12,10,12,13, 4, 9, 9, 9,12,12, 9,12,12, 7,
  134566. 12,11,10,13,13,11,12,12, 7,12,12,10,13,13,11,12,
  134567. 12,
  134568. };
  134569. static float _vq_quantthresh__44u5__p7_0[] = {
  134570. -5.5, 5.5,
  134571. };
  134572. static long _vq_quantmap__44u5__p7_0[] = {
  134573. 1, 0, 2,
  134574. };
  134575. static encode_aux_threshmatch _vq_auxt__44u5__p7_0 = {
  134576. _vq_quantthresh__44u5__p7_0,
  134577. _vq_quantmap__44u5__p7_0,
  134578. 3,
  134579. 3
  134580. };
  134581. static static_codebook _44u5__p7_0 = {
  134582. 4, 81,
  134583. _vq_lengthlist__44u5__p7_0,
  134584. 1, -529137664, 1618345984, 2, 0,
  134585. _vq_quantlist__44u5__p7_0,
  134586. NULL,
  134587. &_vq_auxt__44u5__p7_0,
  134588. NULL,
  134589. 0
  134590. };
  134591. static long _vq_quantlist__44u5__p7_1[] = {
  134592. 5,
  134593. 4,
  134594. 6,
  134595. 3,
  134596. 7,
  134597. 2,
  134598. 8,
  134599. 1,
  134600. 9,
  134601. 0,
  134602. 10,
  134603. };
  134604. static long _vq_lengthlist__44u5__p7_1[] = {
  134605. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  134606. 8, 8, 9, 8, 8, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 8,
  134607. 9, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  134608. 8, 9, 9, 9, 9, 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  134609. 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  134610. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  134611. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  134612. 9, 9, 9, 9, 9,10,10,10,10,
  134613. };
  134614. static float _vq_quantthresh__44u5__p7_1[] = {
  134615. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  134616. 3.5, 4.5,
  134617. };
  134618. static long _vq_quantmap__44u5__p7_1[] = {
  134619. 9, 7, 5, 3, 1, 0, 2, 4,
  134620. 6, 8, 10,
  134621. };
  134622. static encode_aux_threshmatch _vq_auxt__44u5__p7_1 = {
  134623. _vq_quantthresh__44u5__p7_1,
  134624. _vq_quantmap__44u5__p7_1,
  134625. 11,
  134626. 11
  134627. };
  134628. static static_codebook _44u5__p7_1 = {
  134629. 2, 121,
  134630. _vq_lengthlist__44u5__p7_1,
  134631. 1, -531365888, 1611661312, 4, 0,
  134632. _vq_quantlist__44u5__p7_1,
  134633. NULL,
  134634. &_vq_auxt__44u5__p7_1,
  134635. NULL,
  134636. 0
  134637. };
  134638. static long _vq_quantlist__44u5__p8_0[] = {
  134639. 5,
  134640. 4,
  134641. 6,
  134642. 3,
  134643. 7,
  134644. 2,
  134645. 8,
  134646. 1,
  134647. 9,
  134648. 0,
  134649. 10,
  134650. };
  134651. static long _vq_lengthlist__44u5__p8_0[] = {
  134652. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  134653. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  134654. 11, 6, 8, 7, 9, 9,10,10,11,11,13,12, 6, 8, 8, 9,
  134655. 9,10,10,11,11,12,13, 8, 9, 9,10,10,12,12,13,12,
  134656. 14,13, 8, 9, 9,10,10,12,12,13,13,14,14, 9,11,11,
  134657. 12,12,13,13,14,14,15,14, 9,11,11,12,12,13,13,14,
  134658. 14,15,14,11,12,12,13,13,14,14,15,14,15,14,11,11,
  134659. 12,13,13,14,14,14,14,15,15,
  134660. };
  134661. static float _vq_quantthresh__44u5__p8_0[] = {
  134662. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  134663. 38.5, 49.5,
  134664. };
  134665. static long _vq_quantmap__44u5__p8_0[] = {
  134666. 9, 7, 5, 3, 1, 0, 2, 4,
  134667. 6, 8, 10,
  134668. };
  134669. static encode_aux_threshmatch _vq_auxt__44u5__p8_0 = {
  134670. _vq_quantthresh__44u5__p8_0,
  134671. _vq_quantmap__44u5__p8_0,
  134672. 11,
  134673. 11
  134674. };
  134675. static static_codebook _44u5__p8_0 = {
  134676. 2, 121,
  134677. _vq_lengthlist__44u5__p8_0,
  134678. 1, -524582912, 1618345984, 4, 0,
  134679. _vq_quantlist__44u5__p8_0,
  134680. NULL,
  134681. &_vq_auxt__44u5__p8_0,
  134682. NULL,
  134683. 0
  134684. };
  134685. static long _vq_quantlist__44u5__p8_1[] = {
  134686. 5,
  134687. 4,
  134688. 6,
  134689. 3,
  134690. 7,
  134691. 2,
  134692. 8,
  134693. 1,
  134694. 9,
  134695. 0,
  134696. 10,
  134697. };
  134698. static long _vq_lengthlist__44u5__p8_1[] = {
  134699. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 6,
  134700. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  134701. 8, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 6, 6, 7, 7,
  134702. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  134703. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8,
  134704. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  134705. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  134706. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  134707. };
  134708. static float _vq_quantthresh__44u5__p8_1[] = {
  134709. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  134710. 3.5, 4.5,
  134711. };
  134712. static long _vq_quantmap__44u5__p8_1[] = {
  134713. 9, 7, 5, 3, 1, 0, 2, 4,
  134714. 6, 8, 10,
  134715. };
  134716. static encode_aux_threshmatch _vq_auxt__44u5__p8_1 = {
  134717. _vq_quantthresh__44u5__p8_1,
  134718. _vq_quantmap__44u5__p8_1,
  134719. 11,
  134720. 11
  134721. };
  134722. static static_codebook _44u5__p8_1 = {
  134723. 2, 121,
  134724. _vq_lengthlist__44u5__p8_1,
  134725. 1, -531365888, 1611661312, 4, 0,
  134726. _vq_quantlist__44u5__p8_1,
  134727. NULL,
  134728. &_vq_auxt__44u5__p8_1,
  134729. NULL,
  134730. 0
  134731. };
  134732. static long _vq_quantlist__44u5__p9_0[] = {
  134733. 6,
  134734. 5,
  134735. 7,
  134736. 4,
  134737. 8,
  134738. 3,
  134739. 9,
  134740. 2,
  134741. 10,
  134742. 1,
  134743. 11,
  134744. 0,
  134745. 12,
  134746. };
  134747. static long _vq_lengthlist__44u5__p9_0[] = {
  134748. 1, 3, 2,12,10,13,13,13,13,13,13,13,13, 4, 9, 9,
  134749. 13,13,13,13,13,13,13,13,13,13, 5,10, 9,13,13,13,
  134750. 13,13,13,13,13,13,13,12,13,13,13,13,13,13,13,13,
  134751. 13,13,13,13,11,13,13,13,13,13,13,13,13,13,13,13,
  134752. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134753. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134754. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134755. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134756. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,
  134757. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134758. 12,12,12,12,12,12,12,12,12,
  134759. };
  134760. static float _vq_quantthresh__44u5__p9_0[] = {
  134761. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  134762. 637.5, 892.5, 1147.5, 1402.5,
  134763. };
  134764. static long _vq_quantmap__44u5__p9_0[] = {
  134765. 11, 9, 7, 5, 3, 1, 0, 2,
  134766. 4, 6, 8, 10, 12,
  134767. };
  134768. static encode_aux_threshmatch _vq_auxt__44u5__p9_0 = {
  134769. _vq_quantthresh__44u5__p9_0,
  134770. _vq_quantmap__44u5__p9_0,
  134771. 13,
  134772. 13
  134773. };
  134774. static static_codebook _44u5__p9_0 = {
  134775. 2, 169,
  134776. _vq_lengthlist__44u5__p9_0,
  134777. 1, -514332672, 1627381760, 4, 0,
  134778. _vq_quantlist__44u5__p9_0,
  134779. NULL,
  134780. &_vq_auxt__44u5__p9_0,
  134781. NULL,
  134782. 0
  134783. };
  134784. static long _vq_quantlist__44u5__p9_1[] = {
  134785. 7,
  134786. 6,
  134787. 8,
  134788. 5,
  134789. 9,
  134790. 4,
  134791. 10,
  134792. 3,
  134793. 11,
  134794. 2,
  134795. 12,
  134796. 1,
  134797. 13,
  134798. 0,
  134799. 14,
  134800. };
  134801. static long _vq_lengthlist__44u5__p9_1[] = {
  134802. 1, 4, 4, 7, 7, 8, 8, 8, 7, 8, 7, 9, 8, 9, 9, 4,
  134803. 7, 6, 9, 8,10,10, 9, 8, 9, 9, 9, 9, 9, 8, 5, 6,
  134804. 6, 8, 9,10,10, 9, 9, 9,10,10,10,10,11, 7, 8, 8,
  134805. 10,10,11,11,10,10,11,11,11,12,11,11, 7, 8, 8,10,
  134806. 10,11,11,10,10,11,11,12,11,11,11, 8, 9, 9,11,11,
  134807. 12,12,11,11,12,11,12,12,12,12, 8, 9,10,11,11,12,
  134808. 12,11,11,12,12,12,12,12,12, 8, 9, 9,10,10,12,11,
  134809. 12,12,12,12,12,12,12,13, 8, 9, 9,11,11,11,11,12,
  134810. 12,12,12,13,12,13,13, 9,10,10,11,11,12,12,12,13,
  134811. 12,13,13,13,14,13, 9,10,10,11,11,12,12,12,13,13,
  134812. 12,13,13,14,13, 9,11,10,12,11,13,12,12,13,13,13,
  134813. 13,13,13,14, 9,10,10,12,12,12,12,12,13,13,13,13,
  134814. 13,14,14,10,11,11,12,12,12,13,13,13,14,14,13,14,
  134815. 14,14,10,11,11,12,12,12,12,13,12,13,14,13,14,14,
  134816. 14,
  134817. };
  134818. static float _vq_quantthresh__44u5__p9_1[] = {
  134819. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134820. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134821. };
  134822. static long _vq_quantmap__44u5__p9_1[] = {
  134823. 13, 11, 9, 7, 5, 3, 1, 0,
  134824. 2, 4, 6, 8, 10, 12, 14,
  134825. };
  134826. static encode_aux_threshmatch _vq_auxt__44u5__p9_1 = {
  134827. _vq_quantthresh__44u5__p9_1,
  134828. _vq_quantmap__44u5__p9_1,
  134829. 15,
  134830. 15
  134831. };
  134832. static static_codebook _44u5__p9_1 = {
  134833. 2, 225,
  134834. _vq_lengthlist__44u5__p9_1,
  134835. 1, -522338304, 1620115456, 4, 0,
  134836. _vq_quantlist__44u5__p9_1,
  134837. NULL,
  134838. &_vq_auxt__44u5__p9_1,
  134839. NULL,
  134840. 0
  134841. };
  134842. static long _vq_quantlist__44u5__p9_2[] = {
  134843. 8,
  134844. 7,
  134845. 9,
  134846. 6,
  134847. 10,
  134848. 5,
  134849. 11,
  134850. 4,
  134851. 12,
  134852. 3,
  134853. 13,
  134854. 2,
  134855. 14,
  134856. 1,
  134857. 15,
  134858. 0,
  134859. 16,
  134860. };
  134861. static long _vq_lengthlist__44u5__p9_2[] = {
  134862. 2, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134863. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134864. 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  134865. 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134866. 9, 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  134867. 9, 9, 9, 9, 9, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  134868. 9,10, 9,10,10,10, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  134869. 9, 9,10, 9,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  134870. 9,10, 9,10,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  134871. 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,10, 9,
  134872. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,
  134873. 9,10, 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  134874. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  134875. 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  134876. 9,10,10, 9,10,10,10,10,10,10,10,10,10,10, 9, 9,
  134877. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  134878. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  134879. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,
  134880. 10,
  134881. };
  134882. static float _vq_quantthresh__44u5__p9_2[] = {
  134883. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134884. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134885. };
  134886. static long _vq_quantmap__44u5__p9_2[] = {
  134887. 15, 13, 11, 9, 7, 5, 3, 1,
  134888. 0, 2, 4, 6, 8, 10, 12, 14,
  134889. 16,
  134890. };
  134891. static encode_aux_threshmatch _vq_auxt__44u5__p9_2 = {
  134892. _vq_quantthresh__44u5__p9_2,
  134893. _vq_quantmap__44u5__p9_2,
  134894. 17,
  134895. 17
  134896. };
  134897. static static_codebook _44u5__p9_2 = {
  134898. 2, 289,
  134899. _vq_lengthlist__44u5__p9_2,
  134900. 1, -529530880, 1611661312, 5, 0,
  134901. _vq_quantlist__44u5__p9_2,
  134902. NULL,
  134903. &_vq_auxt__44u5__p9_2,
  134904. NULL,
  134905. 0
  134906. };
  134907. static long _huff_lengthlist__44u5__short[] = {
  134908. 4,10,17,13,17,13,17,17,17,17, 3, 6, 8, 9,11, 9,
  134909. 15,12,16,17, 6, 5, 5, 7, 7, 8,10,11,17,17, 7, 8,
  134910. 7, 9, 9,10,13,13,17,17, 8, 6, 5, 7, 4, 7, 5, 8,
  134911. 14,17, 9, 9, 8, 9, 7, 9, 8,10,16,17,12,10, 7, 8,
  134912. 4, 7, 4, 7,16,17,12,11, 9,10, 6, 9, 5, 7,14,17,
  134913. 14,13,10,15, 4, 8, 3, 5,14,17,17,14,11,15, 6,10,
  134914. 6, 8,15,17,
  134915. };
  134916. static static_codebook _huff_book__44u5__short = {
  134917. 2, 100,
  134918. _huff_lengthlist__44u5__short,
  134919. 0, 0, 0, 0, 0,
  134920. NULL,
  134921. NULL,
  134922. NULL,
  134923. NULL,
  134924. 0
  134925. };
  134926. static long _huff_lengthlist__44u6__long[] = {
  134927. 3, 9,14,13,14,13,16,12,13,14, 5, 4, 6, 6, 8, 9,
  134928. 11,10,12,15,10, 5, 5, 6, 6, 8,10,10,13,16,10, 6,
  134929. 6, 6, 6, 8, 9, 9,12,14,13, 7, 6, 6, 4, 6, 6, 7,
  134930. 11,14,10, 7, 7, 7, 6, 6, 6, 7,10,13,15,10, 9, 8,
  134931. 5, 6, 5, 6,10,14,10, 9, 8, 8, 6, 6, 5, 4, 6,11,
  134932. 11,11,12,11,10, 9, 9, 5, 5, 9,10,12,15,13,13,13,
  134933. 13, 8, 7, 7,
  134934. };
  134935. static static_codebook _huff_book__44u6__long = {
  134936. 2, 100,
  134937. _huff_lengthlist__44u6__long,
  134938. 0, 0, 0, 0, 0,
  134939. NULL,
  134940. NULL,
  134941. NULL,
  134942. NULL,
  134943. 0
  134944. };
  134945. static long _vq_quantlist__44u6__p1_0[] = {
  134946. 1,
  134947. 0,
  134948. 2,
  134949. };
  134950. static long _vq_lengthlist__44u6__p1_0[] = {
  134951. 1, 4, 4, 4, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  134952. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  134953. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  134954. 10,13,11,10,13,13, 5, 8, 8, 8,11,10, 8,10,10, 7,
  134955. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  134956. 12,
  134957. };
  134958. static float _vq_quantthresh__44u6__p1_0[] = {
  134959. -0.5, 0.5,
  134960. };
  134961. static long _vq_quantmap__44u6__p1_0[] = {
  134962. 1, 0, 2,
  134963. };
  134964. static encode_aux_threshmatch _vq_auxt__44u6__p1_0 = {
  134965. _vq_quantthresh__44u6__p1_0,
  134966. _vq_quantmap__44u6__p1_0,
  134967. 3,
  134968. 3
  134969. };
  134970. static static_codebook _44u6__p1_0 = {
  134971. 4, 81,
  134972. _vq_lengthlist__44u6__p1_0,
  134973. 1, -535822336, 1611661312, 2, 0,
  134974. _vq_quantlist__44u6__p1_0,
  134975. NULL,
  134976. &_vq_auxt__44u6__p1_0,
  134977. NULL,
  134978. 0
  134979. };
  134980. static long _vq_quantlist__44u6__p2_0[] = {
  134981. 1,
  134982. 0,
  134983. 2,
  134984. };
  134985. static long _vq_lengthlist__44u6__p2_0[] = {
  134986. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  134987. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  134988. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 7, 7,
  134989. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  134990. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  134991. 9,
  134992. };
  134993. static float _vq_quantthresh__44u6__p2_0[] = {
  134994. -0.5, 0.5,
  134995. };
  134996. static long _vq_quantmap__44u6__p2_0[] = {
  134997. 1, 0, 2,
  134998. };
  134999. static encode_aux_threshmatch _vq_auxt__44u6__p2_0 = {
  135000. _vq_quantthresh__44u6__p2_0,
  135001. _vq_quantmap__44u6__p2_0,
  135002. 3,
  135003. 3
  135004. };
  135005. static static_codebook _44u6__p2_0 = {
  135006. 4, 81,
  135007. _vq_lengthlist__44u6__p2_0,
  135008. 1, -535822336, 1611661312, 2, 0,
  135009. _vq_quantlist__44u6__p2_0,
  135010. NULL,
  135011. &_vq_auxt__44u6__p2_0,
  135012. NULL,
  135013. 0
  135014. };
  135015. static long _vq_quantlist__44u6__p3_0[] = {
  135016. 2,
  135017. 1,
  135018. 3,
  135019. 0,
  135020. 4,
  135021. };
  135022. static long _vq_lengthlist__44u6__p3_0[] = {
  135023. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  135024. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  135025. 9,11,11, 7, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  135026. 13,14, 5, 7, 7, 9,10, 6, 9, 8,11,11, 7, 9, 9,11,
  135027. 11, 9,11,10,14,13,10,11,11,14,13, 8,10,10,13,13,
  135028. 10,11,11,15,15, 9,11,11,14,14,13,14,14,17,16,12,
  135029. 13,14,16,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  135030. 12,14,15,12,14,13,16,15,13,14,14,15,17, 5, 7, 7,
  135031. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,
  135032. 14,10,11,11,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  135033. 9,11,11,13,13,11,13,13,14,15,11,12,13,15,16, 6,
  135034. 9, 9,11,12, 8,11,10,13,12, 9,11,11,13,14,11,13,
  135035. 12,16,14,11,13,13,15,16,10,12,11,14,15,11,13,13,
  135036. 15,17,11,13,13,17,16,15,15,16,17,16,14,15,16,18,
  135037. 0, 9,11,11,14,15,10,12,12,16,15,11,13,13,16,16,
  135038. 13,15,14,18,15,14,16,16, 0, 0, 5, 7, 7,10,10, 7,
  135039. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  135040. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  135041. 12,13,11,13,13,16,15,11,12,13,14,16, 7, 9, 9,11,
  135042. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,16,15,
  135043. 11,13,12,15,15, 9,11,11,15,14,11,13,13,17,16,10,
  135044. 12,13,15,16,14,16,16, 0,18,14,14,15,15,17,10,11,
  135045. 12,15,15,11,13,13,16,16,11,13,13,16,16,14,16,16,
  135046. 19,17,14,15,15,17,17, 8,10,10,14,14,10,12,11,15,
  135047. 15,10,11,12,16,15,14,15,15,18,20,13,14,16,17,18,
  135048. 9,11,11,15,16,11,13,13,17,17,11,13,13,17,16,15,
  135049. 16,16, 0, 0,15,16,16, 0, 0, 9,11,11,15,15,10,13,
  135050. 12,17,15,11,13,13,17,16,15,17,15,20,19,15,16,16,
  135051. 19, 0,13,15,14, 0,17,14,15,16, 0,20,15,16,16, 0,
  135052. 19,17,18, 0, 0, 0,16,17,18, 0, 0,12,14,14,19,18,
  135053. 13,15,14, 0,17,14,15,16,19,19,16,18,16, 0,19,19,
  135054. 20,17,20, 0, 8,10,10,13,14,10,11,11,15,15,10,12,
  135055. 12,15,16,14,15,14,19,16,14,15,15, 0,18, 9,11,11,
  135056. 16,15,11,13,13, 0,16,11,12,13,16,17,14,16,17, 0,
  135057. 19,15,16,16,18, 0, 9,11,11,15,16,11,13,13,16,16,
  135058. 11,14,13,18,17,15,16,16,18,20,15,17,19, 0, 0,12,
  135059. 14,14,17,17,14,16,15, 0, 0,13,14,15,19, 0,16,18,
  135060. 20, 0, 0,16,16,18,18, 0,12,14,14,17,20,14,16,16,
  135061. 19, 0,14,16,14, 0,20,16,20,17, 0, 0,17, 0,15, 0,
  135062. 19,
  135063. };
  135064. static float _vq_quantthresh__44u6__p3_0[] = {
  135065. -1.5, -0.5, 0.5, 1.5,
  135066. };
  135067. static long _vq_quantmap__44u6__p3_0[] = {
  135068. 3, 1, 0, 2, 4,
  135069. };
  135070. static encode_aux_threshmatch _vq_auxt__44u6__p3_0 = {
  135071. _vq_quantthresh__44u6__p3_0,
  135072. _vq_quantmap__44u6__p3_0,
  135073. 5,
  135074. 5
  135075. };
  135076. static static_codebook _44u6__p3_0 = {
  135077. 4, 625,
  135078. _vq_lengthlist__44u6__p3_0,
  135079. 1, -533725184, 1611661312, 3, 0,
  135080. _vq_quantlist__44u6__p3_0,
  135081. NULL,
  135082. &_vq_auxt__44u6__p3_0,
  135083. NULL,
  135084. 0
  135085. };
  135086. static long _vq_quantlist__44u6__p4_0[] = {
  135087. 2,
  135088. 1,
  135089. 3,
  135090. 0,
  135091. 4,
  135092. };
  135093. static long _vq_lengthlist__44u6__p4_0[] = {
  135094. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  135095. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  135096. 8,10,10, 7, 7, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  135097. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 8,10,
  135098. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  135099. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,13,11,
  135100. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135101. 10,12,12,11,12,11,13,12,11,12,12,13,13, 5, 7, 7,
  135102. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  135103. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  135104. 8, 9, 9,11,11,10,10,11,12,13,10,10,11,12,12, 6,
  135105. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  135106. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  135107. 13,13,10,11,11,12,13,12,12,12,13,14,12,12,13,14,
  135108. 14, 9,10,10,12,12, 9,10,10,13,12,10,11,11,13,13,
  135109. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  135110. 8, 7,10,10, 7, 8, 8,10,10, 9,10,10,12,11, 9,10,
  135111. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  135112. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  135113. 10, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,10,13,12,
  135114. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,12, 9,
  135115. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  135116. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,12,12,
  135117. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  135118. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,14,
  135119. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  135120. 12,13,14,15,12,12,13,14,14, 9,10,10,12,12, 9,11,
  135121. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,13,
  135122. 14,15,11,12,12,14,13,11,12,12,14,14,12,13,13,14,
  135123. 14,13,13,14,14,16,13,14,14,15,15,11,12,11,13,13,
  135124. 11,12,11,14,13,12,12,13,14,15,12,14,12,15,12,13,
  135125. 14,15,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135126. 10,12,12,11,12,12,14,13,11,12,12,13,13, 9,10,10,
  135127. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  135128. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  135129. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  135130. 11,11,13,13,12,13,12,14,14,11,11,12,13,14,14,14,
  135131. 14,16,15,12,12,14,12,15,11,12,12,13,14,12,13,13,
  135132. 14,15,11,12,12,14,14,13,14,14,16,16,13,14,13,16,
  135133. 13,
  135134. };
  135135. static float _vq_quantthresh__44u6__p4_0[] = {
  135136. -1.5, -0.5, 0.5, 1.5,
  135137. };
  135138. static long _vq_quantmap__44u6__p4_0[] = {
  135139. 3, 1, 0, 2, 4,
  135140. };
  135141. static encode_aux_threshmatch _vq_auxt__44u6__p4_0 = {
  135142. _vq_quantthresh__44u6__p4_0,
  135143. _vq_quantmap__44u6__p4_0,
  135144. 5,
  135145. 5
  135146. };
  135147. static static_codebook _44u6__p4_0 = {
  135148. 4, 625,
  135149. _vq_lengthlist__44u6__p4_0,
  135150. 1, -533725184, 1611661312, 3, 0,
  135151. _vq_quantlist__44u6__p4_0,
  135152. NULL,
  135153. &_vq_auxt__44u6__p4_0,
  135154. NULL,
  135155. 0
  135156. };
  135157. static long _vq_quantlist__44u6__p5_0[] = {
  135158. 4,
  135159. 3,
  135160. 5,
  135161. 2,
  135162. 6,
  135163. 1,
  135164. 7,
  135165. 0,
  135166. 8,
  135167. };
  135168. static long _vq_lengthlist__44u6__p5_0[] = {
  135169. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  135170. 11,11, 3, 5, 5, 7, 8, 8, 8,11,11, 6, 8, 7, 9, 9,
  135171. 10, 9,12,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  135172. 10, 9,12,11,13,13, 8, 8, 9, 9,10,11,12,13,13,10,
  135173. 11,11,12,12,13,13,14,14,10,10,11,11,12,13,13,14,
  135174. 14,
  135175. };
  135176. static float _vq_quantthresh__44u6__p5_0[] = {
  135177. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135178. };
  135179. static long _vq_quantmap__44u6__p5_0[] = {
  135180. 7, 5, 3, 1, 0, 2, 4, 6,
  135181. 8,
  135182. };
  135183. static encode_aux_threshmatch _vq_auxt__44u6__p5_0 = {
  135184. _vq_quantthresh__44u6__p5_0,
  135185. _vq_quantmap__44u6__p5_0,
  135186. 9,
  135187. 9
  135188. };
  135189. static static_codebook _44u6__p5_0 = {
  135190. 2, 81,
  135191. _vq_lengthlist__44u6__p5_0,
  135192. 1, -531628032, 1611661312, 4, 0,
  135193. _vq_quantlist__44u6__p5_0,
  135194. NULL,
  135195. &_vq_auxt__44u6__p5_0,
  135196. NULL,
  135197. 0
  135198. };
  135199. static long _vq_quantlist__44u6__p6_0[] = {
  135200. 4,
  135201. 3,
  135202. 5,
  135203. 2,
  135204. 6,
  135205. 1,
  135206. 7,
  135207. 0,
  135208. 8,
  135209. };
  135210. static long _vq_lengthlist__44u6__p6_0[] = {
  135211. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  135212. 9, 9, 4, 4, 5, 6, 6, 7, 8, 9, 9, 5, 6, 6, 7, 7,
  135213. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  135214. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,10,11, 9,
  135215. 9, 9,10,10,11,11,12,11, 9, 9, 9,10,10,11,11,11,
  135216. 12,
  135217. };
  135218. static float _vq_quantthresh__44u6__p6_0[] = {
  135219. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135220. };
  135221. static long _vq_quantmap__44u6__p6_0[] = {
  135222. 7, 5, 3, 1, 0, 2, 4, 6,
  135223. 8,
  135224. };
  135225. static encode_aux_threshmatch _vq_auxt__44u6__p6_0 = {
  135226. _vq_quantthresh__44u6__p6_0,
  135227. _vq_quantmap__44u6__p6_0,
  135228. 9,
  135229. 9
  135230. };
  135231. static static_codebook _44u6__p6_0 = {
  135232. 2, 81,
  135233. _vq_lengthlist__44u6__p6_0,
  135234. 1, -531628032, 1611661312, 4, 0,
  135235. _vq_quantlist__44u6__p6_0,
  135236. NULL,
  135237. &_vq_auxt__44u6__p6_0,
  135238. NULL,
  135239. 0
  135240. };
  135241. static long _vq_quantlist__44u6__p7_0[] = {
  135242. 1,
  135243. 0,
  135244. 2,
  135245. };
  135246. static long _vq_lengthlist__44u6__p7_0[] = {
  135247. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10,10, 8,
  135248. 10,10, 5, 8, 9, 7,10,10, 7,10, 9, 4, 8, 8, 9,11,
  135249. 11, 8,11,11, 7,11,11,10,10,13,10,13,13, 7,11,11,
  135250. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 9,11,11, 7,
  135251. 11,11,10,13,13,10,12,13, 7,11,11,10,13,13, 9,13,
  135252. 10,
  135253. };
  135254. static float _vq_quantthresh__44u6__p7_0[] = {
  135255. -5.5, 5.5,
  135256. };
  135257. static long _vq_quantmap__44u6__p7_0[] = {
  135258. 1, 0, 2,
  135259. };
  135260. static encode_aux_threshmatch _vq_auxt__44u6__p7_0 = {
  135261. _vq_quantthresh__44u6__p7_0,
  135262. _vq_quantmap__44u6__p7_0,
  135263. 3,
  135264. 3
  135265. };
  135266. static static_codebook _44u6__p7_0 = {
  135267. 4, 81,
  135268. _vq_lengthlist__44u6__p7_0,
  135269. 1, -529137664, 1618345984, 2, 0,
  135270. _vq_quantlist__44u6__p7_0,
  135271. NULL,
  135272. &_vq_auxt__44u6__p7_0,
  135273. NULL,
  135274. 0
  135275. };
  135276. static long _vq_quantlist__44u6__p7_1[] = {
  135277. 5,
  135278. 4,
  135279. 6,
  135280. 3,
  135281. 7,
  135282. 2,
  135283. 8,
  135284. 1,
  135285. 9,
  135286. 0,
  135287. 10,
  135288. };
  135289. static long _vq_lengthlist__44u6__p7_1[] = {
  135290. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 6,
  135291. 8, 8, 8, 8, 8, 8, 4, 5, 5, 6, 7, 8, 8, 8, 8, 8,
  135292. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  135293. 7, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 9, 9,
  135294. 9, 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  135295. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  135296. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  135297. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135298. };
  135299. static float _vq_quantthresh__44u6__p7_1[] = {
  135300. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135301. 3.5, 4.5,
  135302. };
  135303. static long _vq_quantmap__44u6__p7_1[] = {
  135304. 9, 7, 5, 3, 1, 0, 2, 4,
  135305. 6, 8, 10,
  135306. };
  135307. static encode_aux_threshmatch _vq_auxt__44u6__p7_1 = {
  135308. _vq_quantthresh__44u6__p7_1,
  135309. _vq_quantmap__44u6__p7_1,
  135310. 11,
  135311. 11
  135312. };
  135313. static static_codebook _44u6__p7_1 = {
  135314. 2, 121,
  135315. _vq_lengthlist__44u6__p7_1,
  135316. 1, -531365888, 1611661312, 4, 0,
  135317. _vq_quantlist__44u6__p7_1,
  135318. NULL,
  135319. &_vq_auxt__44u6__p7_1,
  135320. NULL,
  135321. 0
  135322. };
  135323. static long _vq_quantlist__44u6__p8_0[] = {
  135324. 5,
  135325. 4,
  135326. 6,
  135327. 3,
  135328. 7,
  135329. 2,
  135330. 8,
  135331. 1,
  135332. 9,
  135333. 0,
  135334. 10,
  135335. };
  135336. static long _vq_lengthlist__44u6__p8_0[] = {
  135337. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  135338. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  135339. 11, 6, 8, 8, 9, 9,10,10,11,11,12,12, 6, 8, 8, 9,
  135340. 9,10,10,11,11,12,12, 8, 9, 9,10,10,11,11,12,12,
  135341. 13,13, 8, 9, 9,10,10,11,11,12,12,13,13,10,10,10,
  135342. 11,11,13,13,13,13,15,14, 9,10,10,12,11,12,13,13,
  135343. 13,14,15,11,12,12,13,13,13,13,15,14,15,15,11,11,
  135344. 12,13,13,14,14,14,15,15,15,
  135345. };
  135346. static float _vq_quantthresh__44u6__p8_0[] = {
  135347. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  135348. 38.5, 49.5,
  135349. };
  135350. static long _vq_quantmap__44u6__p8_0[] = {
  135351. 9, 7, 5, 3, 1, 0, 2, 4,
  135352. 6, 8, 10,
  135353. };
  135354. static encode_aux_threshmatch _vq_auxt__44u6__p8_0 = {
  135355. _vq_quantthresh__44u6__p8_0,
  135356. _vq_quantmap__44u6__p8_0,
  135357. 11,
  135358. 11
  135359. };
  135360. static static_codebook _44u6__p8_0 = {
  135361. 2, 121,
  135362. _vq_lengthlist__44u6__p8_0,
  135363. 1, -524582912, 1618345984, 4, 0,
  135364. _vq_quantlist__44u6__p8_0,
  135365. NULL,
  135366. &_vq_auxt__44u6__p8_0,
  135367. NULL,
  135368. 0
  135369. };
  135370. static long _vq_quantlist__44u6__p8_1[] = {
  135371. 5,
  135372. 4,
  135373. 6,
  135374. 3,
  135375. 7,
  135376. 2,
  135377. 8,
  135378. 1,
  135379. 9,
  135380. 0,
  135381. 10,
  135382. };
  135383. static long _vq_lengthlist__44u6__p8_1[] = {
  135384. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 7,
  135385. 7, 7, 8, 7, 8, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7, 8,
  135386. 8, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 6, 7, 7,
  135387. 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  135388. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  135389. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  135390. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  135391. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135392. };
  135393. static float _vq_quantthresh__44u6__p8_1[] = {
  135394. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135395. 3.5, 4.5,
  135396. };
  135397. static long _vq_quantmap__44u6__p8_1[] = {
  135398. 9, 7, 5, 3, 1, 0, 2, 4,
  135399. 6, 8, 10,
  135400. };
  135401. static encode_aux_threshmatch _vq_auxt__44u6__p8_1 = {
  135402. _vq_quantthresh__44u6__p8_1,
  135403. _vq_quantmap__44u6__p8_1,
  135404. 11,
  135405. 11
  135406. };
  135407. static static_codebook _44u6__p8_1 = {
  135408. 2, 121,
  135409. _vq_lengthlist__44u6__p8_1,
  135410. 1, -531365888, 1611661312, 4, 0,
  135411. _vq_quantlist__44u6__p8_1,
  135412. NULL,
  135413. &_vq_auxt__44u6__p8_1,
  135414. NULL,
  135415. 0
  135416. };
  135417. static long _vq_quantlist__44u6__p9_0[] = {
  135418. 7,
  135419. 6,
  135420. 8,
  135421. 5,
  135422. 9,
  135423. 4,
  135424. 10,
  135425. 3,
  135426. 11,
  135427. 2,
  135428. 12,
  135429. 1,
  135430. 13,
  135431. 0,
  135432. 14,
  135433. };
  135434. static long _vq_lengthlist__44u6__p9_0[] = {
  135435. 1, 3, 2, 9, 8,15,15,15,15,15,15,15,15,15,15, 4,
  135436. 8, 9,13,14,14,14,14,14,14,14,14,14,14,14, 5, 8,
  135437. 9,14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,
  135438. 14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,14,
  135439. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135440. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135441. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135442. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135443. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135444. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135445. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135446. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135447. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135448. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135449. 14,
  135450. };
  135451. static float _vq_quantthresh__44u6__p9_0[] = {
  135452. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  135453. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  135454. };
  135455. static long _vq_quantmap__44u6__p9_0[] = {
  135456. 13, 11, 9, 7, 5, 3, 1, 0,
  135457. 2, 4, 6, 8, 10, 12, 14,
  135458. };
  135459. static encode_aux_threshmatch _vq_auxt__44u6__p9_0 = {
  135460. _vq_quantthresh__44u6__p9_0,
  135461. _vq_quantmap__44u6__p9_0,
  135462. 15,
  135463. 15
  135464. };
  135465. static static_codebook _44u6__p9_0 = {
  135466. 2, 225,
  135467. _vq_lengthlist__44u6__p9_0,
  135468. 1, -514071552, 1627381760, 4, 0,
  135469. _vq_quantlist__44u6__p9_0,
  135470. NULL,
  135471. &_vq_auxt__44u6__p9_0,
  135472. NULL,
  135473. 0
  135474. };
  135475. static long _vq_quantlist__44u6__p9_1[] = {
  135476. 7,
  135477. 6,
  135478. 8,
  135479. 5,
  135480. 9,
  135481. 4,
  135482. 10,
  135483. 3,
  135484. 11,
  135485. 2,
  135486. 12,
  135487. 1,
  135488. 13,
  135489. 0,
  135490. 14,
  135491. };
  135492. static long _vq_lengthlist__44u6__p9_1[] = {
  135493. 1, 4, 4, 7, 7, 8, 9, 8, 8, 9, 8, 9, 8, 9, 9, 4,
  135494. 7, 6, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 4, 7,
  135495. 6, 9, 9,10,10, 9, 9,10,10,10,10,11,11, 7, 9, 8,
  135496. 10,10,11,11,10,10,11,11,11,11,11,11, 7, 8, 9,10,
  135497. 10,11,11,10,10,11,11,11,11,11,12, 8,10,10,11,11,
  135498. 12,12,11,11,12,12,12,12,13,12, 8,10,10,11,11,12,
  135499. 11,11,11,11,12,12,12,12,13, 8, 9, 9,11,10,11,11,
  135500. 12,12,12,12,13,12,13,12, 8, 9, 9,11,11,11,11,12,
  135501. 12,12,12,12,13,13,13, 9,10,10,11,12,12,12,12,12,
  135502. 13,13,13,13,13,13, 9,10,10,11,11,12,12,12,12,13,
  135503. 13,13,13,14,13,10,10,10,12,11,12,12,13,13,13,13,
  135504. 13,13,13,13,10,10,11,11,11,12,12,13,13,13,13,13,
  135505. 13,13,13,10,11,11,12,12,13,12,12,13,13,13,13,13,
  135506. 13,14,10,11,11,12,12,13,12,13,13,13,14,13,13,14,
  135507. 13,
  135508. };
  135509. static float _vq_quantthresh__44u6__p9_1[] = {
  135510. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  135511. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  135512. };
  135513. static long _vq_quantmap__44u6__p9_1[] = {
  135514. 13, 11, 9, 7, 5, 3, 1, 0,
  135515. 2, 4, 6, 8, 10, 12, 14,
  135516. };
  135517. static encode_aux_threshmatch _vq_auxt__44u6__p9_1 = {
  135518. _vq_quantthresh__44u6__p9_1,
  135519. _vq_quantmap__44u6__p9_1,
  135520. 15,
  135521. 15
  135522. };
  135523. static static_codebook _44u6__p9_1 = {
  135524. 2, 225,
  135525. _vq_lengthlist__44u6__p9_1,
  135526. 1, -522338304, 1620115456, 4, 0,
  135527. _vq_quantlist__44u6__p9_1,
  135528. NULL,
  135529. &_vq_auxt__44u6__p9_1,
  135530. NULL,
  135531. 0
  135532. };
  135533. static long _vq_quantlist__44u6__p9_2[] = {
  135534. 8,
  135535. 7,
  135536. 9,
  135537. 6,
  135538. 10,
  135539. 5,
  135540. 11,
  135541. 4,
  135542. 12,
  135543. 3,
  135544. 13,
  135545. 2,
  135546. 14,
  135547. 1,
  135548. 15,
  135549. 0,
  135550. 16,
  135551. };
  135552. static long _vq_lengthlist__44u6__p9_2[] = {
  135553. 3, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 8, 8, 9, 9,
  135554. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  135555. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  135556. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135557. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135558. 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135559. 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135560. 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135561. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  135562. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9, 9,
  135563. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 8, 9, 9, 9, 9, 9,
  135564. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  135565. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9, 9, 9, 9, 9,
  135566. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,
  135567. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9, 9,
  135568. 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9,10, 9,
  135569. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9,10,10,
  135570. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10, 9, 9,
  135571. 10,
  135572. };
  135573. static float _vq_quantthresh__44u6__p9_2[] = {
  135574. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  135575. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  135576. };
  135577. static long _vq_quantmap__44u6__p9_2[] = {
  135578. 15, 13, 11, 9, 7, 5, 3, 1,
  135579. 0, 2, 4, 6, 8, 10, 12, 14,
  135580. 16,
  135581. };
  135582. static encode_aux_threshmatch _vq_auxt__44u6__p9_2 = {
  135583. _vq_quantthresh__44u6__p9_2,
  135584. _vq_quantmap__44u6__p9_2,
  135585. 17,
  135586. 17
  135587. };
  135588. static static_codebook _44u6__p9_2 = {
  135589. 2, 289,
  135590. _vq_lengthlist__44u6__p9_2,
  135591. 1, -529530880, 1611661312, 5, 0,
  135592. _vq_quantlist__44u6__p9_2,
  135593. NULL,
  135594. &_vq_auxt__44u6__p9_2,
  135595. NULL,
  135596. 0
  135597. };
  135598. static long _huff_lengthlist__44u6__short[] = {
  135599. 4,11,16,13,17,13,17,16,17,17, 4, 7, 9, 9,13,10,
  135600. 16,12,16,17, 7, 6, 5, 7, 8, 9,12,12,16,17, 6, 9,
  135601. 7, 9,10,10,15,15,17,17, 6, 7, 5, 7, 5, 7, 7,10,
  135602. 16,17, 7, 9, 8, 9, 8,10,11,11,15,17, 7, 7, 7, 8,
  135603. 5, 8, 8, 9,15,17, 8, 7, 9, 9, 7, 8, 7, 2, 7,15,
  135604. 14,13,13,15, 5,10, 4, 3, 6,17,17,15,13,17, 7,11,
  135605. 7, 6, 9,16,
  135606. };
  135607. static static_codebook _huff_book__44u6__short = {
  135608. 2, 100,
  135609. _huff_lengthlist__44u6__short,
  135610. 0, 0, 0, 0, 0,
  135611. NULL,
  135612. NULL,
  135613. NULL,
  135614. NULL,
  135615. 0
  135616. };
  135617. static long _huff_lengthlist__44u7__long[] = {
  135618. 3, 9,14,13,15,14,16,13,13,14, 5, 5, 7, 7, 8, 9,
  135619. 11,10,12,15,10, 6, 5, 6, 6, 9,10,10,13,16,10, 6,
  135620. 6, 6, 6, 8, 9, 9,12,15,14, 7, 6, 6, 5, 6, 6, 8,
  135621. 12,15,10, 8, 7, 7, 6, 7, 7, 7,11,13,14,10, 9, 8,
  135622. 5, 6, 4, 5, 9,12,10, 9, 9, 8, 6, 6, 5, 3, 6,11,
  135623. 12,11,12,12,10, 9, 8, 5, 5, 8,10,11,15,13,13,13,
  135624. 12, 8, 6, 7,
  135625. };
  135626. static static_codebook _huff_book__44u7__long = {
  135627. 2, 100,
  135628. _huff_lengthlist__44u7__long,
  135629. 0, 0, 0, 0, 0,
  135630. NULL,
  135631. NULL,
  135632. NULL,
  135633. NULL,
  135634. 0
  135635. };
  135636. static long _vq_quantlist__44u7__p1_0[] = {
  135637. 1,
  135638. 0,
  135639. 2,
  135640. };
  135641. static long _vq_lengthlist__44u7__p1_0[] = {
  135642. 1, 4, 4, 4, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  135643. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 5, 8, 8, 8,11,
  135644. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  135645. 10,13,12,10,13,13, 5, 8, 8, 8,11,10, 8,10,11, 7,
  135646. 10,10,10,13,13,10,12,13, 8,11,11,10,13,13,10,13,
  135647. 12,
  135648. };
  135649. static float _vq_quantthresh__44u7__p1_0[] = {
  135650. -0.5, 0.5,
  135651. };
  135652. static long _vq_quantmap__44u7__p1_0[] = {
  135653. 1, 0, 2,
  135654. };
  135655. static encode_aux_threshmatch _vq_auxt__44u7__p1_0 = {
  135656. _vq_quantthresh__44u7__p1_0,
  135657. _vq_quantmap__44u7__p1_0,
  135658. 3,
  135659. 3
  135660. };
  135661. static static_codebook _44u7__p1_0 = {
  135662. 4, 81,
  135663. _vq_lengthlist__44u7__p1_0,
  135664. 1, -535822336, 1611661312, 2, 0,
  135665. _vq_quantlist__44u7__p1_0,
  135666. NULL,
  135667. &_vq_auxt__44u7__p1_0,
  135668. NULL,
  135669. 0
  135670. };
  135671. static long _vq_quantlist__44u7__p2_0[] = {
  135672. 1,
  135673. 0,
  135674. 2,
  135675. };
  135676. static long _vq_lengthlist__44u7__p2_0[] = {
  135677. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  135678. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  135679. 7, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  135680. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  135681. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  135682. 9,
  135683. };
  135684. static float _vq_quantthresh__44u7__p2_0[] = {
  135685. -0.5, 0.5,
  135686. };
  135687. static long _vq_quantmap__44u7__p2_0[] = {
  135688. 1, 0, 2,
  135689. };
  135690. static encode_aux_threshmatch _vq_auxt__44u7__p2_0 = {
  135691. _vq_quantthresh__44u7__p2_0,
  135692. _vq_quantmap__44u7__p2_0,
  135693. 3,
  135694. 3
  135695. };
  135696. static static_codebook _44u7__p2_0 = {
  135697. 4, 81,
  135698. _vq_lengthlist__44u7__p2_0,
  135699. 1, -535822336, 1611661312, 2, 0,
  135700. _vq_quantlist__44u7__p2_0,
  135701. NULL,
  135702. &_vq_auxt__44u7__p2_0,
  135703. NULL,
  135704. 0
  135705. };
  135706. static long _vq_quantlist__44u7__p3_0[] = {
  135707. 2,
  135708. 1,
  135709. 3,
  135710. 0,
  135711. 4,
  135712. };
  135713. static long _vq_lengthlist__44u7__p3_0[] = {
  135714. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  135715. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  135716. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  135717. 13,14, 5, 7, 7, 9, 9, 7, 9, 8,11,11, 7, 9, 9,11,
  135718. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  135719. 10,11,12,15,14, 9,11,11,15,14,13,14,14,16,16,12,
  135720. 13,14,17,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  135721. 12,14,15,12,14,13,16,16,13,14,15,15,17, 5, 7, 7,
  135722. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,15,
  135723. 14,10,11,12,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  135724. 9,11,11,13,13,11,13,13,14,17,11,13,13,15,16, 6,
  135725. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  135726. 12,16,14,11,13,13,16,16,10,12,12,15,15,11,13,13,
  135727. 16,16,11,13,13,16,15,14,16,17,17,19,14,16,16,18,
  135728. 0, 9,11,11,14,15,10,13,12,16,15,11,13,13,16,16,
  135729. 14,15,14, 0,16,14,16,16,18, 0, 5, 7, 7,10,10, 7,
  135730. 9, 9,12,11, 7, 9, 9,11,12,10,11,11,15,14,10,11,
  135731. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  135732. 12,13,11,13,13,17,15,11,12,13,14,15, 7, 9, 9,11,
  135733. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,12,16,16,
  135734. 11,13,13,15,14, 9,11,11,14,15,11,13,13,16,15,10,
  135735. 12,13,16,16,15,16,16, 0, 0,14,13,15,16,18,10,11,
  135736. 11,15,15,11,13,14,16,18,11,13,13,16,15,15,16,16,
  135737. 19, 0,14,15,15,16,16, 8,10,10,13,13,10,12,11,16,
  135738. 15,10,11,11,16,15,13,15,16,18, 0,13,14,15,17,17,
  135739. 9,11,11,15,15,11,13,13,16,18,11,13,13,16,17,15,
  135740. 16,16, 0, 0,15,18,16, 0,17, 9,11,11,15,15,11,13,
  135741. 12,17,15,11,13,14,16,17,15,18,15, 0,17,15,16,16,
  135742. 18,19,13,15,14, 0,18,14,16,16,19,18,14,16,15,19,
  135743. 19,16,18,19, 0, 0,16,17, 0, 0, 0,12,14,14,17,17,
  135744. 13,16,14, 0,18,14,16,15,18, 0,16,18,16,19,17,18,
  135745. 19,17, 0, 0, 8,10,10,14,14, 9,12,11,15,15,10,11,
  135746. 12,15,17,13,15,15,18,16,14,16,15,18,17, 9,11,11,
  135747. 16,15,11,13,13, 0,16,11,12,13,16,15,15,16,16, 0,
  135748. 17,15,15,16,18,17, 9,12,11,15,17,11,13,13,16,16,
  135749. 11,14,13,16,16,15,15,16,18,19,16,18,16, 0, 0,12,
  135750. 14,14, 0,16,14,16,16, 0,18,13,14,15,16, 0,17,16,
  135751. 18, 0, 0,16,16,17,19, 0,13,14,14,17, 0,14,17,16,
  135752. 0,19,14,15,15,18,19,17,16,18, 0, 0,15,19,16, 0,
  135753. 0,
  135754. };
  135755. static float _vq_quantthresh__44u7__p3_0[] = {
  135756. -1.5, -0.5, 0.5, 1.5,
  135757. };
  135758. static long _vq_quantmap__44u7__p3_0[] = {
  135759. 3, 1, 0, 2, 4,
  135760. };
  135761. static encode_aux_threshmatch _vq_auxt__44u7__p3_0 = {
  135762. _vq_quantthresh__44u7__p3_0,
  135763. _vq_quantmap__44u7__p3_0,
  135764. 5,
  135765. 5
  135766. };
  135767. static static_codebook _44u7__p3_0 = {
  135768. 4, 625,
  135769. _vq_lengthlist__44u7__p3_0,
  135770. 1, -533725184, 1611661312, 3, 0,
  135771. _vq_quantlist__44u7__p3_0,
  135772. NULL,
  135773. &_vq_auxt__44u7__p3_0,
  135774. NULL,
  135775. 0
  135776. };
  135777. static long _vq_quantlist__44u7__p4_0[] = {
  135778. 2,
  135779. 1,
  135780. 3,
  135781. 0,
  135782. 4,
  135783. };
  135784. static long _vq_lengthlist__44u7__p4_0[] = {
  135785. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  135786. 9, 9,11,11, 8, 9, 9,10,11, 6, 7, 7, 9, 9, 7, 8,
  135787. 8,10,10, 6, 7, 8, 9,10, 9,10,10,12,12, 9, 9,10,
  135788. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  135789. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  135790. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  135791. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,11, 9,10,
  135792. 10,12,12,11,12,11,13,13,11,12,12,13,13, 6, 7, 7,
  135793. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  135794. 11, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  135795. 8, 9, 9,11,11,10,11,11,12,12,10,10,11,12,13, 6,
  135796. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  135797. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  135798. 13,13,10,11,11,13,12,12,12,13,13,14,12,12,13,14,
  135799. 14, 9,10,10,12,12, 9,10,10,12,12,10,11,11,13,13,
  135800. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  135801. 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,11, 9,10,
  135802. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  135803. 10,11,10,11,11,13,12,10,10,11,11,13, 7, 8, 8,10,
  135804. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,10,13,12,
  135805. 10,11,11,12,12, 9,10,10,12,12,10,11,11,13,12, 9,
  135806. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  135807. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,12,
  135808. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  135809. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,13,
  135810. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  135811. 13,13,14,14,12,12,13,14,14, 9,10,10,12,12, 9,11,
  135812. 10,13,12,10,10,11,12,13,11,13,12,14,13,12,12,13,
  135813. 14,14,11,12,12,13,13,11,12,13,14,14,12,13,13,14,
  135814. 14,13,13,14,14,16,13,14,14,16,16,11,11,11,13,13,
  135815. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,13,14,
  135816. 14,14,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135817. 10,12,12,11,12,12,14,13,11,12,12,13,14, 9,10,10,
  135818. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  135819. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,12,13,
  135820. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  135821. 12,12,13,13,12,13,12,14,14,11,11,12,13,14,13,15,
  135822. 14,16,15,13,12,14,13,16,11,12,12,13,13,12,13,13,
  135823. 14,14,12,12,12,14,14,13,14,14,15,15,13,14,13,16,
  135824. 14,
  135825. };
  135826. static float _vq_quantthresh__44u7__p4_0[] = {
  135827. -1.5, -0.5, 0.5, 1.5,
  135828. };
  135829. static long _vq_quantmap__44u7__p4_0[] = {
  135830. 3, 1, 0, 2, 4,
  135831. };
  135832. static encode_aux_threshmatch _vq_auxt__44u7__p4_0 = {
  135833. _vq_quantthresh__44u7__p4_0,
  135834. _vq_quantmap__44u7__p4_0,
  135835. 5,
  135836. 5
  135837. };
  135838. static static_codebook _44u7__p4_0 = {
  135839. 4, 625,
  135840. _vq_lengthlist__44u7__p4_0,
  135841. 1, -533725184, 1611661312, 3, 0,
  135842. _vq_quantlist__44u7__p4_0,
  135843. NULL,
  135844. &_vq_auxt__44u7__p4_0,
  135845. NULL,
  135846. 0
  135847. };
  135848. static long _vq_quantlist__44u7__p5_0[] = {
  135849. 4,
  135850. 3,
  135851. 5,
  135852. 2,
  135853. 6,
  135854. 1,
  135855. 7,
  135856. 0,
  135857. 8,
  135858. };
  135859. static long _vq_lengthlist__44u7__p5_0[] = {
  135860. 2, 3, 3, 6, 6, 7, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  135861. 11,11, 3, 5, 5, 7, 7, 8, 9,11,11, 6, 8, 7, 9, 9,
  135862. 10,10,12,12, 6, 7, 8, 9,10,10,10,12,12, 8, 8, 8,
  135863. 10,10,12,11,13,13, 8, 8, 9,10,10,11,11,13,13,10,
  135864. 11,11,12,12,13,13,14,14,10,11,11,12,12,13,13,14,
  135865. 14,
  135866. };
  135867. static float _vq_quantthresh__44u7__p5_0[] = {
  135868. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135869. };
  135870. static long _vq_quantmap__44u7__p5_0[] = {
  135871. 7, 5, 3, 1, 0, 2, 4, 6,
  135872. 8,
  135873. };
  135874. static encode_aux_threshmatch _vq_auxt__44u7__p5_0 = {
  135875. _vq_quantthresh__44u7__p5_0,
  135876. _vq_quantmap__44u7__p5_0,
  135877. 9,
  135878. 9
  135879. };
  135880. static static_codebook _44u7__p5_0 = {
  135881. 2, 81,
  135882. _vq_lengthlist__44u7__p5_0,
  135883. 1, -531628032, 1611661312, 4, 0,
  135884. _vq_quantlist__44u7__p5_0,
  135885. NULL,
  135886. &_vq_auxt__44u7__p5_0,
  135887. NULL,
  135888. 0
  135889. };
  135890. static long _vq_quantlist__44u7__p6_0[] = {
  135891. 4,
  135892. 3,
  135893. 5,
  135894. 2,
  135895. 6,
  135896. 1,
  135897. 7,
  135898. 0,
  135899. 8,
  135900. };
  135901. static long _vq_lengthlist__44u7__p6_0[] = {
  135902. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 8, 7,
  135903. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  135904. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  135905. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,11,11, 9,
  135906. 9, 9,10,10,11,10,12,11, 9, 9, 9,10,10,11,11,11,
  135907. 12,
  135908. };
  135909. static float _vq_quantthresh__44u7__p6_0[] = {
  135910. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135911. };
  135912. static long _vq_quantmap__44u7__p6_0[] = {
  135913. 7, 5, 3, 1, 0, 2, 4, 6,
  135914. 8,
  135915. };
  135916. static encode_aux_threshmatch _vq_auxt__44u7__p6_0 = {
  135917. _vq_quantthresh__44u7__p6_0,
  135918. _vq_quantmap__44u7__p6_0,
  135919. 9,
  135920. 9
  135921. };
  135922. static static_codebook _44u7__p6_0 = {
  135923. 2, 81,
  135924. _vq_lengthlist__44u7__p6_0,
  135925. 1, -531628032, 1611661312, 4, 0,
  135926. _vq_quantlist__44u7__p6_0,
  135927. NULL,
  135928. &_vq_auxt__44u7__p6_0,
  135929. NULL,
  135930. 0
  135931. };
  135932. static long _vq_quantlist__44u7__p7_0[] = {
  135933. 1,
  135934. 0,
  135935. 2,
  135936. };
  135937. static long _vq_lengthlist__44u7__p7_0[] = {
  135938. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 8, 9, 9, 7,
  135939. 10,10, 5, 8, 9, 7, 9,10, 8, 9, 9, 4, 9, 9, 9,11,
  135940. 10, 8,10,10, 7,11,10,10,10,12,10,12,12, 7,10,10,
  135941. 10,12,11,10,12,12, 5, 9, 9, 8,10,10, 9,11,11, 7,
  135942. 11,10,10,12,12,10,11,12, 7,10,11,10,12,12,10,12,
  135943. 10,
  135944. };
  135945. static float _vq_quantthresh__44u7__p7_0[] = {
  135946. -5.5, 5.5,
  135947. };
  135948. static long _vq_quantmap__44u7__p7_0[] = {
  135949. 1, 0, 2,
  135950. };
  135951. static encode_aux_threshmatch _vq_auxt__44u7__p7_0 = {
  135952. _vq_quantthresh__44u7__p7_0,
  135953. _vq_quantmap__44u7__p7_0,
  135954. 3,
  135955. 3
  135956. };
  135957. static static_codebook _44u7__p7_0 = {
  135958. 4, 81,
  135959. _vq_lengthlist__44u7__p7_0,
  135960. 1, -529137664, 1618345984, 2, 0,
  135961. _vq_quantlist__44u7__p7_0,
  135962. NULL,
  135963. &_vq_auxt__44u7__p7_0,
  135964. NULL,
  135965. 0
  135966. };
  135967. static long _vq_quantlist__44u7__p7_1[] = {
  135968. 5,
  135969. 4,
  135970. 6,
  135971. 3,
  135972. 7,
  135973. 2,
  135974. 8,
  135975. 1,
  135976. 9,
  135977. 0,
  135978. 10,
  135979. };
  135980. static long _vq_lengthlist__44u7__p7_1[] = {
  135981. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6,
  135982. 8, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6, 7, 8, 8, 8, 8,
  135983. 8, 6, 7, 6, 7, 7, 8, 8, 9, 9, 9, 9, 6, 6, 7, 7,
  135984. 7, 8, 8, 9, 9, 9, 9, 7, 8, 7, 8, 8, 9, 9, 9, 9,
  135985. 9, 9, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  135986. 9, 9, 9, 9,10, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  135987. 9, 9,10, 8, 8, 8, 9, 9, 9, 9,10, 9,10,10, 8, 8,
  135988. 8, 9, 9, 9, 9, 9,10,10,10,
  135989. };
  135990. static float _vq_quantthresh__44u7__p7_1[] = {
  135991. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135992. 3.5, 4.5,
  135993. };
  135994. static long _vq_quantmap__44u7__p7_1[] = {
  135995. 9, 7, 5, 3, 1, 0, 2, 4,
  135996. 6, 8, 10,
  135997. };
  135998. static encode_aux_threshmatch _vq_auxt__44u7__p7_1 = {
  135999. _vq_quantthresh__44u7__p7_1,
  136000. _vq_quantmap__44u7__p7_1,
  136001. 11,
  136002. 11
  136003. };
  136004. static static_codebook _44u7__p7_1 = {
  136005. 2, 121,
  136006. _vq_lengthlist__44u7__p7_1,
  136007. 1, -531365888, 1611661312, 4, 0,
  136008. _vq_quantlist__44u7__p7_1,
  136009. NULL,
  136010. &_vq_auxt__44u7__p7_1,
  136011. NULL,
  136012. 0
  136013. };
  136014. static long _vq_quantlist__44u7__p8_0[] = {
  136015. 5,
  136016. 4,
  136017. 6,
  136018. 3,
  136019. 7,
  136020. 2,
  136021. 8,
  136022. 1,
  136023. 9,
  136024. 0,
  136025. 10,
  136026. };
  136027. static long _vq_lengthlist__44u7__p8_0[] = {
  136028. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  136029. 9, 9,11,10,12,12, 5, 6, 5, 7, 7, 9, 9,10,11,12,
  136030. 12, 6, 7, 7, 8, 8,10,10,11,11,13,13, 6, 7, 7, 8,
  136031. 8,10,10,11,12,13,13, 8, 9, 9,10,10,11,11,12,12,
  136032. 14,14, 8, 9, 9,10,10,11,11,12,12,14,14,10,10,10,
  136033. 11,11,13,12,14,14,15,15,10,10,10,12,12,13,13,14,
  136034. 14,15,15,11,12,12,13,13,14,14,15,14,16,15,11,12,
  136035. 12,13,13,14,14,15,15,15,16,
  136036. };
  136037. static float _vq_quantthresh__44u7__p8_0[] = {
  136038. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  136039. 38.5, 49.5,
  136040. };
  136041. static long _vq_quantmap__44u7__p8_0[] = {
  136042. 9, 7, 5, 3, 1, 0, 2, 4,
  136043. 6, 8, 10,
  136044. };
  136045. static encode_aux_threshmatch _vq_auxt__44u7__p8_0 = {
  136046. _vq_quantthresh__44u7__p8_0,
  136047. _vq_quantmap__44u7__p8_0,
  136048. 11,
  136049. 11
  136050. };
  136051. static static_codebook _44u7__p8_0 = {
  136052. 2, 121,
  136053. _vq_lengthlist__44u7__p8_0,
  136054. 1, -524582912, 1618345984, 4, 0,
  136055. _vq_quantlist__44u7__p8_0,
  136056. NULL,
  136057. &_vq_auxt__44u7__p8_0,
  136058. NULL,
  136059. 0
  136060. };
  136061. static long _vq_quantlist__44u7__p8_1[] = {
  136062. 5,
  136063. 4,
  136064. 6,
  136065. 3,
  136066. 7,
  136067. 2,
  136068. 8,
  136069. 1,
  136070. 9,
  136071. 0,
  136072. 10,
  136073. };
  136074. static long _vq_lengthlist__44u7__p8_1[] = {
  136075. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  136076. 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  136077. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  136078. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  136079. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  136080. 7, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  136081. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  136082. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  136083. };
  136084. static float _vq_quantthresh__44u7__p8_1[] = {
  136085. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136086. 3.5, 4.5,
  136087. };
  136088. static long _vq_quantmap__44u7__p8_1[] = {
  136089. 9, 7, 5, 3, 1, 0, 2, 4,
  136090. 6, 8, 10,
  136091. };
  136092. static encode_aux_threshmatch _vq_auxt__44u7__p8_1 = {
  136093. _vq_quantthresh__44u7__p8_1,
  136094. _vq_quantmap__44u7__p8_1,
  136095. 11,
  136096. 11
  136097. };
  136098. static static_codebook _44u7__p8_1 = {
  136099. 2, 121,
  136100. _vq_lengthlist__44u7__p8_1,
  136101. 1, -531365888, 1611661312, 4, 0,
  136102. _vq_quantlist__44u7__p8_1,
  136103. NULL,
  136104. &_vq_auxt__44u7__p8_1,
  136105. NULL,
  136106. 0
  136107. };
  136108. static long _vq_quantlist__44u7__p9_0[] = {
  136109. 5,
  136110. 4,
  136111. 6,
  136112. 3,
  136113. 7,
  136114. 2,
  136115. 8,
  136116. 1,
  136117. 9,
  136118. 0,
  136119. 10,
  136120. };
  136121. static long _vq_lengthlist__44u7__p9_0[] = {
  136122. 1, 3, 3,10,10,10,10,10,10,10,10, 4,10,10,10,10,
  136123. 10,10,10,10,10,10, 4,10,10,10,10,10,10,10,10,10,
  136124. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136125. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136126. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136127. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136128. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  136129. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136130. };
  136131. static float _vq_quantthresh__44u7__p9_0[] = {
  136132. -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5, 1592.5,
  136133. 2229.5, 2866.5,
  136134. };
  136135. static long _vq_quantmap__44u7__p9_0[] = {
  136136. 9, 7, 5, 3, 1, 0, 2, 4,
  136137. 6, 8, 10,
  136138. };
  136139. static encode_aux_threshmatch _vq_auxt__44u7__p9_0 = {
  136140. _vq_quantthresh__44u7__p9_0,
  136141. _vq_quantmap__44u7__p9_0,
  136142. 11,
  136143. 11
  136144. };
  136145. static static_codebook _44u7__p9_0 = {
  136146. 2, 121,
  136147. _vq_lengthlist__44u7__p9_0,
  136148. 1, -512171520, 1630791680, 4, 0,
  136149. _vq_quantlist__44u7__p9_0,
  136150. NULL,
  136151. &_vq_auxt__44u7__p9_0,
  136152. NULL,
  136153. 0
  136154. };
  136155. static long _vq_quantlist__44u7__p9_1[] = {
  136156. 6,
  136157. 5,
  136158. 7,
  136159. 4,
  136160. 8,
  136161. 3,
  136162. 9,
  136163. 2,
  136164. 10,
  136165. 1,
  136166. 11,
  136167. 0,
  136168. 12,
  136169. };
  136170. static long _vq_lengthlist__44u7__p9_1[] = {
  136171. 1, 4, 4, 6, 5, 8, 6, 9, 8,10, 9,11,10, 4, 6, 6,
  136172. 8, 8, 9, 9,11,10,11,11,11,11, 4, 6, 6, 8, 8,10,
  136173. 9,11,11,11,11,11,12, 6, 8, 8,10,10,11,11,12,12,
  136174. 13,12,13,13, 6, 8, 8,10,10,11,11,12,12,12,13,14,
  136175. 13, 8,10,10,11,11,12,13,14,14,14,14,15,15, 8,10,
  136176. 10,11,12,12,13,13,14,14,14,14,15, 9,11,11,13,13,
  136177. 14,14,15,14,16,15,17,15, 9,11,11,12,13,14,14,15,
  136178. 14,15,15,15,16,10,12,12,13,14,15,15,15,15,16,17,
  136179. 16,17,10,13,12,13,14,14,16,16,16,16,15,16,17,11,
  136180. 13,13,14,15,14,17,15,16,17,17,17,17,11,13,13,14,
  136181. 15,15,15,15,17,17,16,17,16,
  136182. };
  136183. static float _vq_quantthresh__44u7__p9_1[] = {
  136184. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  136185. 122.5, 171.5, 220.5, 269.5,
  136186. };
  136187. static long _vq_quantmap__44u7__p9_1[] = {
  136188. 11, 9, 7, 5, 3, 1, 0, 2,
  136189. 4, 6, 8, 10, 12,
  136190. };
  136191. static encode_aux_threshmatch _vq_auxt__44u7__p9_1 = {
  136192. _vq_quantthresh__44u7__p9_1,
  136193. _vq_quantmap__44u7__p9_1,
  136194. 13,
  136195. 13
  136196. };
  136197. static static_codebook _44u7__p9_1 = {
  136198. 2, 169,
  136199. _vq_lengthlist__44u7__p9_1,
  136200. 1, -518889472, 1622704128, 4, 0,
  136201. _vq_quantlist__44u7__p9_1,
  136202. NULL,
  136203. &_vq_auxt__44u7__p9_1,
  136204. NULL,
  136205. 0
  136206. };
  136207. static long _vq_quantlist__44u7__p9_2[] = {
  136208. 24,
  136209. 23,
  136210. 25,
  136211. 22,
  136212. 26,
  136213. 21,
  136214. 27,
  136215. 20,
  136216. 28,
  136217. 19,
  136218. 29,
  136219. 18,
  136220. 30,
  136221. 17,
  136222. 31,
  136223. 16,
  136224. 32,
  136225. 15,
  136226. 33,
  136227. 14,
  136228. 34,
  136229. 13,
  136230. 35,
  136231. 12,
  136232. 36,
  136233. 11,
  136234. 37,
  136235. 10,
  136236. 38,
  136237. 9,
  136238. 39,
  136239. 8,
  136240. 40,
  136241. 7,
  136242. 41,
  136243. 6,
  136244. 42,
  136245. 5,
  136246. 43,
  136247. 4,
  136248. 44,
  136249. 3,
  136250. 45,
  136251. 2,
  136252. 46,
  136253. 1,
  136254. 47,
  136255. 0,
  136256. 48,
  136257. };
  136258. static long _vq_lengthlist__44u7__p9_2[] = {
  136259. 2, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  136260. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  136261. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  136262. 8,
  136263. };
  136264. static float _vq_quantthresh__44u7__p9_2[] = {
  136265. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  136266. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  136267. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136268. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136269. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  136270. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  136271. };
  136272. static long _vq_quantmap__44u7__p9_2[] = {
  136273. 47, 45, 43, 41, 39, 37, 35, 33,
  136274. 31, 29, 27, 25, 23, 21, 19, 17,
  136275. 15, 13, 11, 9, 7, 5, 3, 1,
  136276. 0, 2, 4, 6, 8, 10, 12, 14,
  136277. 16, 18, 20, 22, 24, 26, 28, 30,
  136278. 32, 34, 36, 38, 40, 42, 44, 46,
  136279. 48,
  136280. };
  136281. static encode_aux_threshmatch _vq_auxt__44u7__p9_2 = {
  136282. _vq_quantthresh__44u7__p9_2,
  136283. _vq_quantmap__44u7__p9_2,
  136284. 49,
  136285. 49
  136286. };
  136287. static static_codebook _44u7__p9_2 = {
  136288. 1, 49,
  136289. _vq_lengthlist__44u7__p9_2,
  136290. 1, -526909440, 1611661312, 6, 0,
  136291. _vq_quantlist__44u7__p9_2,
  136292. NULL,
  136293. &_vq_auxt__44u7__p9_2,
  136294. NULL,
  136295. 0
  136296. };
  136297. static long _huff_lengthlist__44u7__short[] = {
  136298. 5,12,17,16,16,17,17,17,17,17, 4, 7,11,11,12, 9,
  136299. 17,10,17,17, 7, 7, 8, 9, 7, 9,11,10,15,17, 7, 9,
  136300. 10,11,10,12,14,12,16,17, 7, 8, 5, 7, 4, 7, 7, 8,
  136301. 16,16, 6,10, 9,10, 7,10,11,11,16,17, 6, 8, 8, 9,
  136302. 5, 7, 5, 8,16,17, 5, 5, 8, 7, 6, 7, 7, 6, 6,14,
  136303. 12,10,12,11, 7,11, 4, 4, 2, 7,17,15,15,15, 8,15,
  136304. 6, 8, 5, 9,
  136305. };
  136306. static static_codebook _huff_book__44u7__short = {
  136307. 2, 100,
  136308. _huff_lengthlist__44u7__short,
  136309. 0, 0, 0, 0, 0,
  136310. NULL,
  136311. NULL,
  136312. NULL,
  136313. NULL,
  136314. 0
  136315. };
  136316. static long _huff_lengthlist__44u8__long[] = {
  136317. 3, 9,13,14,14,15,14,14,15,15, 5, 4, 6, 8,10,12,
  136318. 12,14,15,15, 9, 5, 4, 5, 8,10,11,13,16,16,10, 7,
  136319. 4, 3, 5, 7, 9,11,13,13,10, 9, 7, 4, 4, 6, 8,10,
  136320. 12,14,13,11, 9, 6, 5, 5, 6, 8,12,14,13,11,10, 8,
  136321. 7, 6, 6, 7,10,14,13,11,12,10, 8, 7, 6, 6, 9,13,
  136322. 12,11,14,12,11, 9, 8, 7, 9,11,11,12,14,13,14,11,
  136323. 10, 8, 8, 9,
  136324. };
  136325. static static_codebook _huff_book__44u8__long = {
  136326. 2, 100,
  136327. _huff_lengthlist__44u8__long,
  136328. 0, 0, 0, 0, 0,
  136329. NULL,
  136330. NULL,
  136331. NULL,
  136332. NULL,
  136333. 0
  136334. };
  136335. static long _huff_lengthlist__44u8__short[] = {
  136336. 6,14,18,18,17,17,17,17,17,17, 4, 7, 9, 9,10,13,
  136337. 15,17,17,17, 6, 7, 5, 6, 8,11,16,17,16,17, 5, 7,
  136338. 5, 4, 6,10,14,17,17,17, 6, 6, 6, 5, 7,10,13,16,
  136339. 17,17, 7, 6, 7, 7, 7, 8, 7,10,15,16,12, 9, 9, 6,
  136340. 6, 5, 3, 5,11,15,14,14,13, 5, 5, 7, 3, 4, 8,15,
  136341. 17,17,13, 7, 7,10, 6, 6,10,15,17,17,16,10,11,14,
  136342. 10,10,15,17,
  136343. };
  136344. static static_codebook _huff_book__44u8__short = {
  136345. 2, 100,
  136346. _huff_lengthlist__44u8__short,
  136347. 0, 0, 0, 0, 0,
  136348. NULL,
  136349. NULL,
  136350. NULL,
  136351. NULL,
  136352. 0
  136353. };
  136354. static long _vq_quantlist__44u8_p1_0[] = {
  136355. 1,
  136356. 0,
  136357. 2,
  136358. };
  136359. static long _vq_lengthlist__44u8_p1_0[] = {
  136360. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 8, 9, 9, 7,
  136361. 9, 9, 5, 7, 7, 7, 9, 9, 8, 9, 9, 5, 7, 7, 7, 9,
  136362. 9, 7, 9, 9, 7, 9, 9, 9,10,11, 9,11,10, 7, 9, 9,
  136363. 9,11,10, 9,10,11, 5, 7, 7, 7, 9, 9, 7, 9, 9, 7,
  136364. 9, 9, 9,11,10, 9,10,10, 8, 9, 9, 9,11,11, 9,11,
  136365. 10,
  136366. };
  136367. static float _vq_quantthresh__44u8_p1_0[] = {
  136368. -0.5, 0.5,
  136369. };
  136370. static long _vq_quantmap__44u8_p1_0[] = {
  136371. 1, 0, 2,
  136372. };
  136373. static encode_aux_threshmatch _vq_auxt__44u8_p1_0 = {
  136374. _vq_quantthresh__44u8_p1_0,
  136375. _vq_quantmap__44u8_p1_0,
  136376. 3,
  136377. 3
  136378. };
  136379. static static_codebook _44u8_p1_0 = {
  136380. 4, 81,
  136381. _vq_lengthlist__44u8_p1_0,
  136382. 1, -535822336, 1611661312, 2, 0,
  136383. _vq_quantlist__44u8_p1_0,
  136384. NULL,
  136385. &_vq_auxt__44u8_p1_0,
  136386. NULL,
  136387. 0
  136388. };
  136389. static long _vq_quantlist__44u8_p2_0[] = {
  136390. 2,
  136391. 1,
  136392. 3,
  136393. 0,
  136394. 4,
  136395. };
  136396. static long _vq_lengthlist__44u8_p2_0[] = {
  136397. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  136398. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  136399. 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,10,
  136400. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  136401. 10, 9,10, 9,12,11, 9,10,10,12,12, 8, 9, 9,12,11,
  136402. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,14,11,
  136403. 11,12,13,14, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136404. 10,12,12,11,12,11,13,13,11,12,12,14,14, 5, 7, 7,
  136405. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  136406. 12, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  136407. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,12,13, 6,
  136408. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  136409. 10,13,12,10,11,11,13,13, 9,10,10,12,12,10,11,11,
  136410. 13,13,10,11,11,13,13,12,12,13,13,14,12,13,13,14,
  136411. 14, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  136412. 11,13,12,14,13,12,13,13,14,14, 5, 7, 7, 9, 9, 7,
  136413. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  136414. 10,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  136415. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  136416. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  136417. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  136418. 10,11,12,13,12,13,13,14,14,12,12,13,13,14, 9,10,
  136419. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,13,
  136420. 15,14,12,13,13,14,13, 8, 9, 9,11,11, 9,10,10,12,
  136421. 12, 9,10,10,12,12,12,12,12,14,13,11,12,12,14,14,
  136422. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  136423. 13,13,14,15,12,13,13,14,15, 9,10,10,12,12,10,11,
  136424. 10,13,12,10,11,11,13,13,12,13,12,15,14,12,13,13,
  136425. 14,15,11,12,12,14,14,12,13,13,14,14,12,13,13,15,
  136426. 14,14,14,14,14,16,14,14,15,16,16,11,12,12,14,14,
  136427. 11,12,12,14,14,12,13,13,14,15,13,14,13,16,14,14,
  136428. 14,14,16,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136429. 10,12,12,11,12,12,14,13,11,12,12,14,14, 9,10,10,
  136430. 12,12,10,11,11,13,13,10,10,11,12,13,12,13,13,15,
  136431. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  136432. 10,11,11,13,13,12,13,13,14,14,12,13,13,15,14,11,
  136433. 12,12,14,13,12,13,13,15,14,11,12,12,13,14,14,15,
  136434. 14,16,15,13,13,14,13,16,11,12,12,14,14,12,13,13,
  136435. 14,15,12,13,12,15,14,14,14,14,16,15,14,15,13,16,
  136436. 14,
  136437. };
  136438. static float _vq_quantthresh__44u8_p2_0[] = {
  136439. -1.5, -0.5, 0.5, 1.5,
  136440. };
  136441. static long _vq_quantmap__44u8_p2_0[] = {
  136442. 3, 1, 0, 2, 4,
  136443. };
  136444. static encode_aux_threshmatch _vq_auxt__44u8_p2_0 = {
  136445. _vq_quantthresh__44u8_p2_0,
  136446. _vq_quantmap__44u8_p2_0,
  136447. 5,
  136448. 5
  136449. };
  136450. static static_codebook _44u8_p2_0 = {
  136451. 4, 625,
  136452. _vq_lengthlist__44u8_p2_0,
  136453. 1, -533725184, 1611661312, 3, 0,
  136454. _vq_quantlist__44u8_p2_0,
  136455. NULL,
  136456. &_vq_auxt__44u8_p2_0,
  136457. NULL,
  136458. 0
  136459. };
  136460. static long _vq_quantlist__44u8_p3_0[] = {
  136461. 4,
  136462. 3,
  136463. 5,
  136464. 2,
  136465. 6,
  136466. 1,
  136467. 7,
  136468. 0,
  136469. 8,
  136470. };
  136471. static long _vq_lengthlist__44u8_p3_0[] = {
  136472. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  136473. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  136474. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  136475. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  136476. 9, 9,10,10,11,10,12,11, 9, 9, 9, 9,10,11,11,11,
  136477. 12,
  136478. };
  136479. static float _vq_quantthresh__44u8_p3_0[] = {
  136480. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136481. };
  136482. static long _vq_quantmap__44u8_p3_0[] = {
  136483. 7, 5, 3, 1, 0, 2, 4, 6,
  136484. 8,
  136485. };
  136486. static encode_aux_threshmatch _vq_auxt__44u8_p3_0 = {
  136487. _vq_quantthresh__44u8_p3_0,
  136488. _vq_quantmap__44u8_p3_0,
  136489. 9,
  136490. 9
  136491. };
  136492. static static_codebook _44u8_p3_0 = {
  136493. 2, 81,
  136494. _vq_lengthlist__44u8_p3_0,
  136495. 1, -531628032, 1611661312, 4, 0,
  136496. _vq_quantlist__44u8_p3_0,
  136497. NULL,
  136498. &_vq_auxt__44u8_p3_0,
  136499. NULL,
  136500. 0
  136501. };
  136502. static long _vq_quantlist__44u8_p4_0[] = {
  136503. 8,
  136504. 7,
  136505. 9,
  136506. 6,
  136507. 10,
  136508. 5,
  136509. 11,
  136510. 4,
  136511. 12,
  136512. 3,
  136513. 13,
  136514. 2,
  136515. 14,
  136516. 1,
  136517. 15,
  136518. 0,
  136519. 16,
  136520. };
  136521. static long _vq_lengthlist__44u8_p4_0[] = {
  136522. 4, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,11,11,11,
  136523. 11, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  136524. 12,12, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  136525. 11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  136526. 11,11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,
  136527. 10,11,11,12,12, 7, 7, 7, 8, 8, 9, 8,10, 9,10, 9,
  136528. 11,10,12,11,13,12, 7, 7, 7, 8, 8, 8, 9, 9,10, 9,
  136529. 10,10,11,11,12,12,13, 8, 8, 8, 9, 9, 9, 9,10,10,
  136530. 11,10,11,11,12,12,13,13, 8, 8, 8, 9, 9, 9,10,10,
  136531. 10,10,11,11,11,12,12,12,13, 8, 9, 9, 9, 9,10, 9,
  136532. 11,10,11,11,12,11,13,12,13,13, 8, 9, 9, 9, 9, 9,
  136533. 10,10,11,11,11,11,12,12,13,13,13,10,10,10,10,10,
  136534. 11,10,11,11,12,11,13,12,13,13,14,13,10,10,10,10,
  136535. 10,10,11,11,11,11,12,12,13,13,13,13,14,11,11,11,
  136536. 11,11,12,11,12,12,13,12,13,13,14,13,14,14,11,11,
  136537. 11,11,11,11,12,12,12,12,13,13,13,13,14,14,14,11,
  136538. 12,12,12,12,13,12,13,12,13,13,14,13,14,14,14,14,
  136539. 11,12,12,12,12,12,12,13,13,13,13,13,14,14,14,14,
  136540. 14,
  136541. };
  136542. static float _vq_quantthresh__44u8_p4_0[] = {
  136543. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136544. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136545. };
  136546. static long _vq_quantmap__44u8_p4_0[] = {
  136547. 15, 13, 11, 9, 7, 5, 3, 1,
  136548. 0, 2, 4, 6, 8, 10, 12, 14,
  136549. 16,
  136550. };
  136551. static encode_aux_threshmatch _vq_auxt__44u8_p4_0 = {
  136552. _vq_quantthresh__44u8_p4_0,
  136553. _vq_quantmap__44u8_p4_0,
  136554. 17,
  136555. 17
  136556. };
  136557. static static_codebook _44u8_p4_0 = {
  136558. 2, 289,
  136559. _vq_lengthlist__44u8_p4_0,
  136560. 1, -529530880, 1611661312, 5, 0,
  136561. _vq_quantlist__44u8_p4_0,
  136562. NULL,
  136563. &_vq_auxt__44u8_p4_0,
  136564. NULL,
  136565. 0
  136566. };
  136567. static long _vq_quantlist__44u8_p5_0[] = {
  136568. 1,
  136569. 0,
  136570. 2,
  136571. };
  136572. static long _vq_lengthlist__44u8_p5_0[] = {
  136573. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  136574. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  136575. 10, 8,10,10, 7,10,10, 9,10,12, 9,12,11, 7,10,10,
  136576. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  136577. 10,10, 9,11,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  136578. 10,
  136579. };
  136580. static float _vq_quantthresh__44u8_p5_0[] = {
  136581. -5.5, 5.5,
  136582. };
  136583. static long _vq_quantmap__44u8_p5_0[] = {
  136584. 1, 0, 2,
  136585. };
  136586. static encode_aux_threshmatch _vq_auxt__44u8_p5_0 = {
  136587. _vq_quantthresh__44u8_p5_0,
  136588. _vq_quantmap__44u8_p5_0,
  136589. 3,
  136590. 3
  136591. };
  136592. static static_codebook _44u8_p5_0 = {
  136593. 4, 81,
  136594. _vq_lengthlist__44u8_p5_0,
  136595. 1, -529137664, 1618345984, 2, 0,
  136596. _vq_quantlist__44u8_p5_0,
  136597. NULL,
  136598. &_vq_auxt__44u8_p5_0,
  136599. NULL,
  136600. 0
  136601. };
  136602. static long _vq_quantlist__44u8_p5_1[] = {
  136603. 5,
  136604. 4,
  136605. 6,
  136606. 3,
  136607. 7,
  136608. 2,
  136609. 8,
  136610. 1,
  136611. 9,
  136612. 0,
  136613. 10,
  136614. };
  136615. static long _vq_lengthlist__44u8_p5_1[] = {
  136616. 4, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 5, 5, 6, 6,
  136617. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8,
  136618. 8, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 6, 6, 6, 7,
  136619. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  136620. 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 7, 8, 7,
  136621. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  136622. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 8, 8,
  136623. 8, 8, 8, 8, 8, 8, 8, 9, 9,
  136624. };
  136625. static float _vq_quantthresh__44u8_p5_1[] = {
  136626. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136627. 3.5, 4.5,
  136628. };
  136629. static long _vq_quantmap__44u8_p5_1[] = {
  136630. 9, 7, 5, 3, 1, 0, 2, 4,
  136631. 6, 8, 10,
  136632. };
  136633. static encode_aux_threshmatch _vq_auxt__44u8_p5_1 = {
  136634. _vq_quantthresh__44u8_p5_1,
  136635. _vq_quantmap__44u8_p5_1,
  136636. 11,
  136637. 11
  136638. };
  136639. static static_codebook _44u8_p5_1 = {
  136640. 2, 121,
  136641. _vq_lengthlist__44u8_p5_1,
  136642. 1, -531365888, 1611661312, 4, 0,
  136643. _vq_quantlist__44u8_p5_1,
  136644. NULL,
  136645. &_vq_auxt__44u8_p5_1,
  136646. NULL,
  136647. 0
  136648. };
  136649. static long _vq_quantlist__44u8_p6_0[] = {
  136650. 6,
  136651. 5,
  136652. 7,
  136653. 4,
  136654. 8,
  136655. 3,
  136656. 9,
  136657. 2,
  136658. 10,
  136659. 1,
  136660. 11,
  136661. 0,
  136662. 12,
  136663. };
  136664. static long _vq_lengthlist__44u8_p6_0[] = {
  136665. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  136666. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7, 8,
  136667. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 7, 8, 8, 8, 8, 9,
  136668. 9,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 8,10, 9,11,
  136669. 10, 7, 8, 8, 8, 8, 8, 9, 9, 9,10,10,11,11, 7, 8,
  136670. 8, 8, 8, 9, 8, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  136671. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  136672. 9,10,10,11,11, 9, 9, 9, 9,10,10,10,10,10,10,11,
  136673. 11,12, 9, 9, 9,10, 9,10,10,10,10,11,10,12,11,10,
  136674. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  136675. 11,11,11,11,11,12,11,12,12,
  136676. };
  136677. static float _vq_quantthresh__44u8_p6_0[] = {
  136678. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  136679. 12.5, 17.5, 22.5, 27.5,
  136680. };
  136681. static long _vq_quantmap__44u8_p6_0[] = {
  136682. 11, 9, 7, 5, 3, 1, 0, 2,
  136683. 4, 6, 8, 10, 12,
  136684. };
  136685. static encode_aux_threshmatch _vq_auxt__44u8_p6_0 = {
  136686. _vq_quantthresh__44u8_p6_0,
  136687. _vq_quantmap__44u8_p6_0,
  136688. 13,
  136689. 13
  136690. };
  136691. static static_codebook _44u8_p6_0 = {
  136692. 2, 169,
  136693. _vq_lengthlist__44u8_p6_0,
  136694. 1, -526516224, 1616117760, 4, 0,
  136695. _vq_quantlist__44u8_p6_0,
  136696. NULL,
  136697. &_vq_auxt__44u8_p6_0,
  136698. NULL,
  136699. 0
  136700. };
  136701. static long _vq_quantlist__44u8_p6_1[] = {
  136702. 2,
  136703. 1,
  136704. 3,
  136705. 0,
  136706. 4,
  136707. };
  136708. static long _vq_lengthlist__44u8_p6_1[] = {
  136709. 3, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  136710. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  136711. };
  136712. static float _vq_quantthresh__44u8_p6_1[] = {
  136713. -1.5, -0.5, 0.5, 1.5,
  136714. };
  136715. static long _vq_quantmap__44u8_p6_1[] = {
  136716. 3, 1, 0, 2, 4,
  136717. };
  136718. static encode_aux_threshmatch _vq_auxt__44u8_p6_1 = {
  136719. _vq_quantthresh__44u8_p6_1,
  136720. _vq_quantmap__44u8_p6_1,
  136721. 5,
  136722. 5
  136723. };
  136724. static static_codebook _44u8_p6_1 = {
  136725. 2, 25,
  136726. _vq_lengthlist__44u8_p6_1,
  136727. 1, -533725184, 1611661312, 3, 0,
  136728. _vq_quantlist__44u8_p6_1,
  136729. NULL,
  136730. &_vq_auxt__44u8_p6_1,
  136731. NULL,
  136732. 0
  136733. };
  136734. static long _vq_quantlist__44u8_p7_0[] = {
  136735. 6,
  136736. 5,
  136737. 7,
  136738. 4,
  136739. 8,
  136740. 3,
  136741. 9,
  136742. 2,
  136743. 10,
  136744. 1,
  136745. 11,
  136746. 0,
  136747. 12,
  136748. };
  136749. static long _vq_lengthlist__44u8_p7_0[] = {
  136750. 1, 4, 5, 6, 6, 7, 7, 8, 8,10,10,11,11, 5, 6, 6,
  136751. 7, 7, 8, 8, 9, 9,11,10,12,11, 5, 6, 6, 7, 7, 8,
  136752. 8, 9, 9,10,11,11,12, 6, 7, 7, 8, 8, 9, 9,10,10,
  136753. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,12,13,
  136754. 12, 7, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  136755. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  136756. 11,11,12,12,13,13,14,14, 9, 9, 9,10,10,11,11,12,
  136757. 12,13,13,14,14,10,11,11,12,11,13,12,13,13,14,14,
  136758. 15,15,10,11,11,11,12,12,13,13,14,14,14,15,15,11,
  136759. 12,12,13,13,14,13,15,14,15,15,16,15,11,11,12,13,
  136760. 13,13,14,14,14,15,15,15,16,
  136761. };
  136762. static float _vq_quantthresh__44u8_p7_0[] = {
  136763. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  136764. 27.5, 38.5, 49.5, 60.5,
  136765. };
  136766. static long _vq_quantmap__44u8_p7_0[] = {
  136767. 11, 9, 7, 5, 3, 1, 0, 2,
  136768. 4, 6, 8, 10, 12,
  136769. };
  136770. static encode_aux_threshmatch _vq_auxt__44u8_p7_0 = {
  136771. _vq_quantthresh__44u8_p7_0,
  136772. _vq_quantmap__44u8_p7_0,
  136773. 13,
  136774. 13
  136775. };
  136776. static static_codebook _44u8_p7_0 = {
  136777. 2, 169,
  136778. _vq_lengthlist__44u8_p7_0,
  136779. 1, -523206656, 1618345984, 4, 0,
  136780. _vq_quantlist__44u8_p7_0,
  136781. NULL,
  136782. &_vq_auxt__44u8_p7_0,
  136783. NULL,
  136784. 0
  136785. };
  136786. static long _vq_quantlist__44u8_p7_1[] = {
  136787. 5,
  136788. 4,
  136789. 6,
  136790. 3,
  136791. 7,
  136792. 2,
  136793. 8,
  136794. 1,
  136795. 9,
  136796. 0,
  136797. 10,
  136798. };
  136799. static long _vq_lengthlist__44u8_p7_1[] = {
  136800. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  136801. 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  136802. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  136803. 7, 7, 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8,
  136804. 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 7, 7, 7,
  136805. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  136806. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  136807. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  136808. };
  136809. static float _vq_quantthresh__44u8_p7_1[] = {
  136810. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136811. 3.5, 4.5,
  136812. };
  136813. static long _vq_quantmap__44u8_p7_1[] = {
  136814. 9, 7, 5, 3, 1, 0, 2, 4,
  136815. 6, 8, 10,
  136816. };
  136817. static encode_aux_threshmatch _vq_auxt__44u8_p7_1 = {
  136818. _vq_quantthresh__44u8_p7_1,
  136819. _vq_quantmap__44u8_p7_1,
  136820. 11,
  136821. 11
  136822. };
  136823. static static_codebook _44u8_p7_1 = {
  136824. 2, 121,
  136825. _vq_lengthlist__44u8_p7_1,
  136826. 1, -531365888, 1611661312, 4, 0,
  136827. _vq_quantlist__44u8_p7_1,
  136828. NULL,
  136829. &_vq_auxt__44u8_p7_1,
  136830. NULL,
  136831. 0
  136832. };
  136833. static long _vq_quantlist__44u8_p8_0[] = {
  136834. 7,
  136835. 6,
  136836. 8,
  136837. 5,
  136838. 9,
  136839. 4,
  136840. 10,
  136841. 3,
  136842. 11,
  136843. 2,
  136844. 12,
  136845. 1,
  136846. 13,
  136847. 0,
  136848. 14,
  136849. };
  136850. static long _vq_lengthlist__44u8_p8_0[] = {
  136851. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8,10, 9,11,10, 4,
  136852. 6, 6, 8, 8,10, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  136853. 6, 8, 8,10,10, 9, 9,10,10,11,11,11,12, 7, 8, 8,
  136854. 10,10,11,11,11,10,12,11,12,12,13,11, 7, 8, 8,10,
  136855. 10,11,11,10,10,11,11,12,12,13,13, 8,10,10,11,11,
  136856. 12,11,12,11,13,12,13,12,14,13, 8,10, 9,11,11,12,
  136857. 12,12,12,12,12,13,13,14,13, 8, 9, 9,11,10,12,11,
  136858. 13,12,13,13,14,13,14,13, 8, 9, 9,10,11,12,12,12,
  136859. 12,13,13,14,15,14,14, 9,10,10,12,11,13,12,13,13,
  136860. 14,13,14,14,14,14, 9,10,10,12,12,12,12,13,13,14,
  136861. 14,14,15,14,14,10,11,11,13,12,13,12,14,14,14,14,
  136862. 14,14,15,15,10,11,11,12,12,13,13,14,14,14,15,15,
  136863. 14,16,15,11,12,12,13,12,14,14,14,13,15,14,15,15,
  136864. 15,17,11,12,12,13,13,14,14,14,15,15,14,15,15,14,
  136865. 17,
  136866. };
  136867. static float _vq_quantthresh__44u8_p8_0[] = {
  136868. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  136869. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  136870. };
  136871. static long _vq_quantmap__44u8_p8_0[] = {
  136872. 13, 11, 9, 7, 5, 3, 1, 0,
  136873. 2, 4, 6, 8, 10, 12, 14,
  136874. };
  136875. static encode_aux_threshmatch _vq_auxt__44u8_p8_0 = {
  136876. _vq_quantthresh__44u8_p8_0,
  136877. _vq_quantmap__44u8_p8_0,
  136878. 15,
  136879. 15
  136880. };
  136881. static static_codebook _44u8_p8_0 = {
  136882. 2, 225,
  136883. _vq_lengthlist__44u8_p8_0,
  136884. 1, -520986624, 1620377600, 4, 0,
  136885. _vq_quantlist__44u8_p8_0,
  136886. NULL,
  136887. &_vq_auxt__44u8_p8_0,
  136888. NULL,
  136889. 0
  136890. };
  136891. static long _vq_quantlist__44u8_p8_1[] = {
  136892. 10,
  136893. 9,
  136894. 11,
  136895. 8,
  136896. 12,
  136897. 7,
  136898. 13,
  136899. 6,
  136900. 14,
  136901. 5,
  136902. 15,
  136903. 4,
  136904. 16,
  136905. 3,
  136906. 17,
  136907. 2,
  136908. 18,
  136909. 1,
  136910. 19,
  136911. 0,
  136912. 20,
  136913. };
  136914. static long _vq_lengthlist__44u8_p8_1[] = {
  136915. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  136916. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  136917. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 5, 6, 6, 7, 7, 8,
  136918. 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  136919. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136920. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  136921. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  136922. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10, 8, 8,
  136923. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  136924. 10, 9,10, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,
  136925. 10,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9,
  136926. 9, 9, 9, 9, 9, 9,10,10,10,10, 9,10,10, 9, 9, 9,
  136927. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  136928. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  136929. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,
  136930. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  136931. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  136932. 10, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  136933. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  136934. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  136935. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136936. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  136937. 10,10,10,10,10, 9, 9, 9,10, 9,10,10,10,10,10,10,
  136938. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  136939. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  136940. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  136941. 10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,10,
  136942. 10,10,10,10,10,10,10,10,10,
  136943. };
  136944. static float _vq_quantthresh__44u8_p8_1[] = {
  136945. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  136946. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  136947. 6.5, 7.5, 8.5, 9.5,
  136948. };
  136949. static long _vq_quantmap__44u8_p8_1[] = {
  136950. 19, 17, 15, 13, 11, 9, 7, 5,
  136951. 3, 1, 0, 2, 4, 6, 8, 10,
  136952. 12, 14, 16, 18, 20,
  136953. };
  136954. static encode_aux_threshmatch _vq_auxt__44u8_p8_1 = {
  136955. _vq_quantthresh__44u8_p8_1,
  136956. _vq_quantmap__44u8_p8_1,
  136957. 21,
  136958. 21
  136959. };
  136960. static static_codebook _44u8_p8_1 = {
  136961. 2, 441,
  136962. _vq_lengthlist__44u8_p8_1,
  136963. 1, -529268736, 1611661312, 5, 0,
  136964. _vq_quantlist__44u8_p8_1,
  136965. NULL,
  136966. &_vq_auxt__44u8_p8_1,
  136967. NULL,
  136968. 0
  136969. };
  136970. static long _vq_quantlist__44u8_p9_0[] = {
  136971. 4,
  136972. 3,
  136973. 5,
  136974. 2,
  136975. 6,
  136976. 1,
  136977. 7,
  136978. 0,
  136979. 8,
  136980. };
  136981. static long _vq_lengthlist__44u8_p9_0[] = {
  136982. 1, 3, 3, 9, 9, 9, 9, 9, 9, 4, 9, 9, 9, 9, 9, 9,
  136983. 9, 9, 5, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136984. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136985. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136986. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  136987. 8,
  136988. };
  136989. static float _vq_quantthresh__44u8_p9_0[] = {
  136990. -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5, 2327.5, 3258.5,
  136991. };
  136992. static long _vq_quantmap__44u8_p9_0[] = {
  136993. 7, 5, 3, 1, 0, 2, 4, 6,
  136994. 8,
  136995. };
  136996. static encode_aux_threshmatch _vq_auxt__44u8_p9_0 = {
  136997. _vq_quantthresh__44u8_p9_0,
  136998. _vq_quantmap__44u8_p9_0,
  136999. 9,
  137000. 9
  137001. };
  137002. static static_codebook _44u8_p9_0 = {
  137003. 2, 81,
  137004. _vq_lengthlist__44u8_p9_0,
  137005. 1, -511895552, 1631393792, 4, 0,
  137006. _vq_quantlist__44u8_p9_0,
  137007. NULL,
  137008. &_vq_auxt__44u8_p9_0,
  137009. NULL,
  137010. 0
  137011. };
  137012. static long _vq_quantlist__44u8_p9_1[] = {
  137013. 9,
  137014. 8,
  137015. 10,
  137016. 7,
  137017. 11,
  137018. 6,
  137019. 12,
  137020. 5,
  137021. 13,
  137022. 4,
  137023. 14,
  137024. 3,
  137025. 15,
  137026. 2,
  137027. 16,
  137028. 1,
  137029. 17,
  137030. 0,
  137031. 18,
  137032. };
  137033. static long _vq_lengthlist__44u8_p9_1[] = {
  137034. 1, 4, 4, 7, 7, 8, 7, 8, 6, 9, 7,10, 8,11,10,11,
  137035. 11,11,11, 4, 7, 6, 9, 9,10, 9, 9, 9,10,10,11,10,
  137036. 11,10,11,11,13,11, 4, 7, 7, 9, 9, 9, 9, 9, 9,10,
  137037. 10,11,10,11,11,11,12,11,12, 7, 9, 8,11,11,11,11,
  137038. 10,10,11,11,12,12,12,12,12,12,14,13, 7, 8, 9,10,
  137039. 11,11,11,10,10,11,11,11,11,12,12,14,12,13,14, 8,
  137040. 9, 9,11,11,11,11,11,11,12,12,14,12,15,14,14,14,
  137041. 15,14, 8, 9, 9,11,11,11,11,12,11,12,12,13,13,13,
  137042. 13,13,13,14,14, 8, 9, 9,11,10,12,11,12,12,13,13,
  137043. 13,13,15,14,14,14,16,16, 8, 9, 9,10,11,11,12,12,
  137044. 12,13,13,13,14,14,14,15,16,15,15, 9,10,10,11,12,
  137045. 12,13,13,13,14,14,16,14,14,16,16,16,16,15, 9,10,
  137046. 10,11,11,12,13,13,14,15,14,16,14,15,16,16,16,16,
  137047. 15,10,11,11,12,13,13,14,15,15,15,15,15,16,15,16,
  137048. 15,16,15,15,10,11,11,13,13,14,13,13,15,14,15,15,
  137049. 16,15,15,15,16,15,16,10,12,12,14,14,14,14,14,16,
  137050. 16,15,15,15,16,16,16,16,16,16,11,12,12,14,14,14,
  137051. 14,15,15,16,15,16,15,16,15,16,16,16,16,12,12,13,
  137052. 14,14,15,16,16,16,16,16,16,15,16,16,16,16,16,16,
  137053. 12,13,13,14,14,14,14,15,16,15,16,16,16,16,16,16,
  137054. 16,16,16,12,13,14,14,14,16,15,16,15,16,16,16,16,
  137055. 16,16,16,16,16,16,12,14,13,14,15,15,15,16,15,16,
  137056. 16,15,16,16,16,16,16,16,16,
  137057. };
  137058. static float _vq_quantthresh__44u8_p9_1[] = {
  137059. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  137060. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  137061. 367.5, 416.5,
  137062. };
  137063. static long _vq_quantmap__44u8_p9_1[] = {
  137064. 17, 15, 13, 11, 9, 7, 5, 3,
  137065. 1, 0, 2, 4, 6, 8, 10, 12,
  137066. 14, 16, 18,
  137067. };
  137068. static encode_aux_threshmatch _vq_auxt__44u8_p9_1 = {
  137069. _vq_quantthresh__44u8_p9_1,
  137070. _vq_quantmap__44u8_p9_1,
  137071. 19,
  137072. 19
  137073. };
  137074. static static_codebook _44u8_p9_1 = {
  137075. 2, 361,
  137076. _vq_lengthlist__44u8_p9_1,
  137077. 1, -518287360, 1622704128, 5, 0,
  137078. _vq_quantlist__44u8_p9_1,
  137079. NULL,
  137080. &_vq_auxt__44u8_p9_1,
  137081. NULL,
  137082. 0
  137083. };
  137084. static long _vq_quantlist__44u8_p9_2[] = {
  137085. 24,
  137086. 23,
  137087. 25,
  137088. 22,
  137089. 26,
  137090. 21,
  137091. 27,
  137092. 20,
  137093. 28,
  137094. 19,
  137095. 29,
  137096. 18,
  137097. 30,
  137098. 17,
  137099. 31,
  137100. 16,
  137101. 32,
  137102. 15,
  137103. 33,
  137104. 14,
  137105. 34,
  137106. 13,
  137107. 35,
  137108. 12,
  137109. 36,
  137110. 11,
  137111. 37,
  137112. 10,
  137113. 38,
  137114. 9,
  137115. 39,
  137116. 8,
  137117. 40,
  137118. 7,
  137119. 41,
  137120. 6,
  137121. 42,
  137122. 5,
  137123. 43,
  137124. 4,
  137125. 44,
  137126. 3,
  137127. 45,
  137128. 2,
  137129. 46,
  137130. 1,
  137131. 47,
  137132. 0,
  137133. 48,
  137134. };
  137135. static long _vq_lengthlist__44u8_p9_2[] = {
  137136. 2, 3, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  137137. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137138. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137139. 7,
  137140. };
  137141. static float _vq_quantthresh__44u8_p9_2[] = {
  137142. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  137143. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  137144. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137145. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137146. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  137147. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  137148. };
  137149. static long _vq_quantmap__44u8_p9_2[] = {
  137150. 47, 45, 43, 41, 39, 37, 35, 33,
  137151. 31, 29, 27, 25, 23, 21, 19, 17,
  137152. 15, 13, 11, 9, 7, 5, 3, 1,
  137153. 0, 2, 4, 6, 8, 10, 12, 14,
  137154. 16, 18, 20, 22, 24, 26, 28, 30,
  137155. 32, 34, 36, 38, 40, 42, 44, 46,
  137156. 48,
  137157. };
  137158. static encode_aux_threshmatch _vq_auxt__44u8_p9_2 = {
  137159. _vq_quantthresh__44u8_p9_2,
  137160. _vq_quantmap__44u8_p9_2,
  137161. 49,
  137162. 49
  137163. };
  137164. static static_codebook _44u8_p9_2 = {
  137165. 1, 49,
  137166. _vq_lengthlist__44u8_p9_2,
  137167. 1, -526909440, 1611661312, 6, 0,
  137168. _vq_quantlist__44u8_p9_2,
  137169. NULL,
  137170. &_vq_auxt__44u8_p9_2,
  137171. NULL,
  137172. 0
  137173. };
  137174. static long _huff_lengthlist__44u9__long[] = {
  137175. 3, 9,13,13,14,15,14,14,15,15, 5, 5, 9,10,12,12,
  137176. 13,14,16,15,10, 6, 6, 6, 8,11,12,13,16,15,11, 7,
  137177. 5, 3, 5, 8,10,12,15,15,10,10, 7, 4, 3, 5, 8,10,
  137178. 12,12,12,12, 9, 7, 5, 4, 6, 8,10,13,13,12,11, 9,
  137179. 7, 5, 5, 6, 9,12,14,12,12,10, 8, 6, 6, 6, 7,11,
  137180. 13,12,14,13,10, 8, 7, 7, 7,10,11,11,12,13,12,11,
  137181. 10, 8, 8, 9,
  137182. };
  137183. static static_codebook _huff_book__44u9__long = {
  137184. 2, 100,
  137185. _huff_lengthlist__44u9__long,
  137186. 0, 0, 0, 0, 0,
  137187. NULL,
  137188. NULL,
  137189. NULL,
  137190. NULL,
  137191. 0
  137192. };
  137193. static long _huff_lengthlist__44u9__short[] = {
  137194. 9,16,18,18,17,17,17,17,17,17, 5, 8,11,12,11,12,
  137195. 17,17,16,16, 6, 6, 8, 8, 9,10,14,15,16,16, 6, 7,
  137196. 7, 4, 6, 9,13,16,16,16, 6, 6, 7, 4, 5, 8,11,15,
  137197. 17,16, 7, 6, 7, 6, 6, 8, 9,10,14,16,11, 8, 8, 7,
  137198. 6, 6, 3, 4,10,15,14,12,12,10, 5, 6, 3, 3, 8,13,
  137199. 15,17,15,11, 6, 8, 6, 6, 9,14,17,15,15,12, 8,10,
  137200. 9, 9,12,15,
  137201. };
  137202. static static_codebook _huff_book__44u9__short = {
  137203. 2, 100,
  137204. _huff_lengthlist__44u9__short,
  137205. 0, 0, 0, 0, 0,
  137206. NULL,
  137207. NULL,
  137208. NULL,
  137209. NULL,
  137210. 0
  137211. };
  137212. static long _vq_quantlist__44u9_p1_0[] = {
  137213. 1,
  137214. 0,
  137215. 2,
  137216. };
  137217. static long _vq_lengthlist__44u9_p1_0[] = {
  137218. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  137219. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 7, 9,
  137220. 9, 7, 9, 9, 8, 9, 9, 9,10,11, 9,11,11, 7, 9, 9,
  137221. 9,11,10, 9,11,11, 5, 7, 7, 7, 9, 9, 8, 9,10, 7,
  137222. 9, 9, 9,11,11, 9,10,11, 7, 9,10, 9,11,11, 9,11,
  137223. 10,
  137224. };
  137225. static float _vq_quantthresh__44u9_p1_0[] = {
  137226. -0.5, 0.5,
  137227. };
  137228. static long _vq_quantmap__44u9_p1_0[] = {
  137229. 1, 0, 2,
  137230. };
  137231. static encode_aux_threshmatch _vq_auxt__44u9_p1_0 = {
  137232. _vq_quantthresh__44u9_p1_0,
  137233. _vq_quantmap__44u9_p1_0,
  137234. 3,
  137235. 3
  137236. };
  137237. static static_codebook _44u9_p1_0 = {
  137238. 4, 81,
  137239. _vq_lengthlist__44u9_p1_0,
  137240. 1, -535822336, 1611661312, 2, 0,
  137241. _vq_quantlist__44u9_p1_0,
  137242. NULL,
  137243. &_vq_auxt__44u9_p1_0,
  137244. NULL,
  137245. 0
  137246. };
  137247. static long _vq_quantlist__44u9_p2_0[] = {
  137248. 2,
  137249. 1,
  137250. 3,
  137251. 0,
  137252. 4,
  137253. };
  137254. static long _vq_lengthlist__44u9_p2_0[] = {
  137255. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  137256. 9, 9,11,10, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  137257. 8,10,10, 7, 8, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  137258. 11,11, 6, 7, 7, 9, 9, 7, 8, 8,10, 9, 7, 8, 8,10,
  137259. 10, 9,10, 9,11,11, 9,10,10,11,11, 8, 9, 9,11,11,
  137260. 9,10,10,12,11, 9,10,10,11,12,11,11,11,13,13,11,
  137261. 11,11,12,13, 8, 9, 9,11,11, 9,10,10,11,11, 9,10,
  137262. 10,12,11,11,12,11,13,12,11,11,12,13,13, 6, 7, 7,
  137263. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  137264. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  137265. 8, 9, 9,10,10,10,11,11,12,12,10,10,11,12,12, 7,
  137266. 8, 8,10,10, 8, 9, 8,10,10, 8, 9, 9,10,10,10,11,
  137267. 10,12,11,10,10,11,12,12, 9,10,10,11,12,10,11,11,
  137268. 12,12,10,11,10,12,12,12,12,12,13,13,11,12,12,13,
  137269. 13, 9,10,10,11,11, 9,10,10,12,12,10,11,11,12,13,
  137270. 11,12,11,13,12,12,12,12,13,14, 6, 7, 7, 9, 9, 7,
  137271. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,11,11, 9,10,
  137272. 10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,10, 8, 8, 9,
  137273. 10,10,10,11,10,12,12,10,10,11,11,12, 7, 8, 8,10,
  137274. 10, 8, 9, 9,10,10, 8, 9, 9,10,10,10,11,10,12,12,
  137275. 10,11,10,12,12, 9,10,10,12,11,10,11,11,12,12, 9,
  137276. 10,10,12,12,12,12,12,13,13,11,11,12,12,14, 9,10,
  137277. 10,11,12,10,11,11,12,12,10,11,11,12,12,11,12,12,
  137278. 14,14,12,12,12,13,13, 8, 9, 9,11,11, 9,10,10,12,
  137279. 11, 9,10,10,12,12,11,12,11,13,13,11,11,12,13,13,
  137280. 9,10,10,12,12,10,11,11,12,12,10,11,11,12,12,12,
  137281. 12,12,14,14,12,12,12,13,13, 9,10,10,12,11,10,11,
  137282. 10,12,12,10,11,11,12,12,11,12,12,14,13,12,12,12,
  137283. 13,14,11,12,11,13,13,11,12,12,13,13,12,12,12,14,
  137284. 14,13,13,13,13,15,13,13,14,15,15,11,11,11,13,13,
  137285. 11,12,11,13,13,11,12,12,13,13,12,13,12,15,13,13,
  137286. 13,14,14,15, 8, 9, 9,11,11, 9,10,10,11,12, 9,10,
  137287. 10,11,12,11,12,11,13,13,11,12,12,13,13, 9,10,10,
  137288. 11,12,10,11,10,12,12,10,10,11,12,13,12,12,12,14,
  137289. 13,11,12,12,13,14, 9,10,10,12,12,10,11,11,12,12,
  137290. 10,11,11,12,12,12,12,12,14,13,12,12,12,14,13,11,
  137291. 11,11,13,13,11,12,12,14,13,11,11,12,13,13,13,13,
  137292. 13,15,14,12,12,13,13,15,11,12,12,13,13,12,12,12,
  137293. 13,14,11,12,12,13,13,13,13,14,14,15,13,13,13,14,
  137294. 14,
  137295. };
  137296. static float _vq_quantthresh__44u9_p2_0[] = {
  137297. -1.5, -0.5, 0.5, 1.5,
  137298. };
  137299. static long _vq_quantmap__44u9_p2_0[] = {
  137300. 3, 1, 0, 2, 4,
  137301. };
  137302. static encode_aux_threshmatch _vq_auxt__44u9_p2_0 = {
  137303. _vq_quantthresh__44u9_p2_0,
  137304. _vq_quantmap__44u9_p2_0,
  137305. 5,
  137306. 5
  137307. };
  137308. static static_codebook _44u9_p2_0 = {
  137309. 4, 625,
  137310. _vq_lengthlist__44u9_p2_0,
  137311. 1, -533725184, 1611661312, 3, 0,
  137312. _vq_quantlist__44u9_p2_0,
  137313. NULL,
  137314. &_vq_auxt__44u9_p2_0,
  137315. NULL,
  137316. 0
  137317. };
  137318. static long _vq_quantlist__44u9_p3_0[] = {
  137319. 4,
  137320. 3,
  137321. 5,
  137322. 2,
  137323. 6,
  137324. 1,
  137325. 7,
  137326. 0,
  137327. 8,
  137328. };
  137329. static long _vq_lengthlist__44u9_p3_0[] = {
  137330. 3, 4, 4, 5, 5, 7, 7, 8, 8, 4, 5, 5, 6, 6, 7, 7,
  137331. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  137332. 8, 8, 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  137333. 8, 8, 9, 9,10,10, 7, 7, 7, 8, 8, 9, 9,10,10, 8,
  137334. 9, 9,10, 9,10,10,11,11, 8, 9, 9, 9,10,10,10,11,
  137335. 11,
  137336. };
  137337. static float _vq_quantthresh__44u9_p3_0[] = {
  137338. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  137339. };
  137340. static long _vq_quantmap__44u9_p3_0[] = {
  137341. 7, 5, 3, 1, 0, 2, 4, 6,
  137342. 8,
  137343. };
  137344. static encode_aux_threshmatch _vq_auxt__44u9_p3_0 = {
  137345. _vq_quantthresh__44u9_p3_0,
  137346. _vq_quantmap__44u9_p3_0,
  137347. 9,
  137348. 9
  137349. };
  137350. static static_codebook _44u9_p3_0 = {
  137351. 2, 81,
  137352. _vq_lengthlist__44u9_p3_0,
  137353. 1, -531628032, 1611661312, 4, 0,
  137354. _vq_quantlist__44u9_p3_0,
  137355. NULL,
  137356. &_vq_auxt__44u9_p3_0,
  137357. NULL,
  137358. 0
  137359. };
  137360. static long _vq_quantlist__44u9_p4_0[] = {
  137361. 8,
  137362. 7,
  137363. 9,
  137364. 6,
  137365. 10,
  137366. 5,
  137367. 11,
  137368. 4,
  137369. 12,
  137370. 3,
  137371. 13,
  137372. 2,
  137373. 14,
  137374. 1,
  137375. 15,
  137376. 0,
  137377. 16,
  137378. };
  137379. static long _vq_lengthlist__44u9_p4_0[] = {
  137380. 4, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  137381. 11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  137382. 11,11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  137383. 10,11,11, 6, 6, 6, 7, 6, 7, 7, 8, 8, 9, 9,10,10,
  137384. 11,11,12,11, 6, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9,10,
  137385. 10,11,11,11,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,
  137386. 10,10,11,11,12,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  137387. 9,10,10,11,11,12,12, 8, 8, 8, 8, 8, 9, 8,10, 9,
  137388. 10,10,11,10,12,11,13,12, 8, 8, 8, 8, 8, 9, 9, 9,
  137389. 10,10,10,10,11,11,12,12,12, 8, 8, 8, 9, 9, 9, 9,
  137390. 10,10,11,10,12,11,12,12,13,12, 8, 8, 8, 9, 9, 9,
  137391. 9,10,10,10,11,11,11,12,12,12,13, 9, 9, 9,10,10,
  137392. 10,10,11,10,11,11,12,11,13,12,13,13, 9, 9,10,10,
  137393. 10,10,10,10,11,11,11,11,12,12,13,13,13,10,11,10,
  137394. 11,11,11,11,12,11,12,12,13,12,13,13,14,13,10,10,
  137395. 10,11,11,11,11,11,12,12,12,12,13,13,13,13,14,11,
  137396. 11,11,12,11,12,12,12,12,13,13,13,13,14,13,14,14,
  137397. 11,11,11,11,12,12,12,12,12,12,13,13,13,13,14,14,
  137398. 14,
  137399. };
  137400. static float _vq_quantthresh__44u9_p4_0[] = {
  137401. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137402. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137403. };
  137404. static long _vq_quantmap__44u9_p4_0[] = {
  137405. 15, 13, 11, 9, 7, 5, 3, 1,
  137406. 0, 2, 4, 6, 8, 10, 12, 14,
  137407. 16,
  137408. };
  137409. static encode_aux_threshmatch _vq_auxt__44u9_p4_0 = {
  137410. _vq_quantthresh__44u9_p4_0,
  137411. _vq_quantmap__44u9_p4_0,
  137412. 17,
  137413. 17
  137414. };
  137415. static static_codebook _44u9_p4_0 = {
  137416. 2, 289,
  137417. _vq_lengthlist__44u9_p4_0,
  137418. 1, -529530880, 1611661312, 5, 0,
  137419. _vq_quantlist__44u9_p4_0,
  137420. NULL,
  137421. &_vq_auxt__44u9_p4_0,
  137422. NULL,
  137423. 0
  137424. };
  137425. static long _vq_quantlist__44u9_p5_0[] = {
  137426. 1,
  137427. 0,
  137428. 2,
  137429. };
  137430. static long _vq_lengthlist__44u9_p5_0[] = {
  137431. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  137432. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  137433. 10, 8,10,10, 7,10,10, 9,10,12, 9,11,11, 7,10,10,
  137434. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  137435. 10,10, 9,12,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  137436. 10,
  137437. };
  137438. static float _vq_quantthresh__44u9_p5_0[] = {
  137439. -5.5, 5.5,
  137440. };
  137441. static long _vq_quantmap__44u9_p5_0[] = {
  137442. 1, 0, 2,
  137443. };
  137444. static encode_aux_threshmatch _vq_auxt__44u9_p5_0 = {
  137445. _vq_quantthresh__44u9_p5_0,
  137446. _vq_quantmap__44u9_p5_0,
  137447. 3,
  137448. 3
  137449. };
  137450. static static_codebook _44u9_p5_0 = {
  137451. 4, 81,
  137452. _vq_lengthlist__44u9_p5_0,
  137453. 1, -529137664, 1618345984, 2, 0,
  137454. _vq_quantlist__44u9_p5_0,
  137455. NULL,
  137456. &_vq_auxt__44u9_p5_0,
  137457. NULL,
  137458. 0
  137459. };
  137460. static long _vq_quantlist__44u9_p5_1[] = {
  137461. 5,
  137462. 4,
  137463. 6,
  137464. 3,
  137465. 7,
  137466. 2,
  137467. 8,
  137468. 1,
  137469. 9,
  137470. 0,
  137471. 10,
  137472. };
  137473. static long _vq_lengthlist__44u9_p5_1[] = {
  137474. 5, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 6,
  137475. 7, 7, 7, 7, 8, 7, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  137476. 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 6, 6, 6, 7,
  137477. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  137478. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  137479. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  137480. 8, 8, 8, 7, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  137481. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  137482. };
  137483. static float _vq_quantthresh__44u9_p5_1[] = {
  137484. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137485. 3.5, 4.5,
  137486. };
  137487. static long _vq_quantmap__44u9_p5_1[] = {
  137488. 9, 7, 5, 3, 1, 0, 2, 4,
  137489. 6, 8, 10,
  137490. };
  137491. static encode_aux_threshmatch _vq_auxt__44u9_p5_1 = {
  137492. _vq_quantthresh__44u9_p5_1,
  137493. _vq_quantmap__44u9_p5_1,
  137494. 11,
  137495. 11
  137496. };
  137497. static static_codebook _44u9_p5_1 = {
  137498. 2, 121,
  137499. _vq_lengthlist__44u9_p5_1,
  137500. 1, -531365888, 1611661312, 4, 0,
  137501. _vq_quantlist__44u9_p5_1,
  137502. NULL,
  137503. &_vq_auxt__44u9_p5_1,
  137504. NULL,
  137505. 0
  137506. };
  137507. static long _vq_quantlist__44u9_p6_0[] = {
  137508. 6,
  137509. 5,
  137510. 7,
  137511. 4,
  137512. 8,
  137513. 3,
  137514. 9,
  137515. 2,
  137516. 10,
  137517. 1,
  137518. 11,
  137519. 0,
  137520. 12,
  137521. };
  137522. static long _vq_lengthlist__44u9_p6_0[] = {
  137523. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  137524. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 5, 6, 7, 7, 8,
  137525. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137526. 10,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  137527. 10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 7, 8,
  137528. 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  137529. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  137530. 9,10,10,11,11, 9, 9, 9,10,10,10,10,10,11,11,11,
  137531. 11,12, 9, 9, 9,10,10,10,10,10,10,11,10,12,11,10,
  137532. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  137533. 10,11,11,11,11,12,11,12,12,
  137534. };
  137535. static float _vq_quantthresh__44u9_p6_0[] = {
  137536. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  137537. 12.5, 17.5, 22.5, 27.5,
  137538. };
  137539. static long _vq_quantmap__44u9_p6_0[] = {
  137540. 11, 9, 7, 5, 3, 1, 0, 2,
  137541. 4, 6, 8, 10, 12,
  137542. };
  137543. static encode_aux_threshmatch _vq_auxt__44u9_p6_0 = {
  137544. _vq_quantthresh__44u9_p6_0,
  137545. _vq_quantmap__44u9_p6_0,
  137546. 13,
  137547. 13
  137548. };
  137549. static static_codebook _44u9_p6_0 = {
  137550. 2, 169,
  137551. _vq_lengthlist__44u9_p6_0,
  137552. 1, -526516224, 1616117760, 4, 0,
  137553. _vq_quantlist__44u9_p6_0,
  137554. NULL,
  137555. &_vq_auxt__44u9_p6_0,
  137556. NULL,
  137557. 0
  137558. };
  137559. static long _vq_quantlist__44u9_p6_1[] = {
  137560. 2,
  137561. 1,
  137562. 3,
  137563. 0,
  137564. 4,
  137565. };
  137566. static long _vq_lengthlist__44u9_p6_1[] = {
  137567. 4, 4, 4, 5, 5, 4, 5, 4, 5, 5, 4, 4, 5, 5, 5, 5,
  137568. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  137569. };
  137570. static float _vq_quantthresh__44u9_p6_1[] = {
  137571. -1.5, -0.5, 0.5, 1.5,
  137572. };
  137573. static long _vq_quantmap__44u9_p6_1[] = {
  137574. 3, 1, 0, 2, 4,
  137575. };
  137576. static encode_aux_threshmatch _vq_auxt__44u9_p6_1 = {
  137577. _vq_quantthresh__44u9_p6_1,
  137578. _vq_quantmap__44u9_p6_1,
  137579. 5,
  137580. 5
  137581. };
  137582. static static_codebook _44u9_p6_1 = {
  137583. 2, 25,
  137584. _vq_lengthlist__44u9_p6_1,
  137585. 1, -533725184, 1611661312, 3, 0,
  137586. _vq_quantlist__44u9_p6_1,
  137587. NULL,
  137588. &_vq_auxt__44u9_p6_1,
  137589. NULL,
  137590. 0
  137591. };
  137592. static long _vq_quantlist__44u9_p7_0[] = {
  137593. 6,
  137594. 5,
  137595. 7,
  137596. 4,
  137597. 8,
  137598. 3,
  137599. 9,
  137600. 2,
  137601. 10,
  137602. 1,
  137603. 11,
  137604. 0,
  137605. 12,
  137606. };
  137607. static long _vq_lengthlist__44u9_p7_0[] = {
  137608. 1, 4, 5, 6, 6, 7, 7, 8, 9,10,10,11,11, 5, 6, 6,
  137609. 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 6, 6, 7, 7, 8,
  137610. 8, 9, 9,10,10,11,11, 6, 7, 7, 8, 8, 9, 9,10,10,
  137611. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,12,
  137612. 12, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  137613. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  137614. 11,11,12,12,13,13,13,13, 9, 9, 9,10,10,11,11,12,
  137615. 12,13,13,14,14,10,10,10,11,11,12,12,13,13,14,13,
  137616. 15,14,10,10,10,11,11,12,12,13,13,14,14,14,14,11,
  137617. 11,12,12,12,13,13,14,14,14,14,15,15,11,11,12,12,
  137618. 12,13,13,14,14,14,15,15,15,
  137619. };
  137620. static float _vq_quantthresh__44u9_p7_0[] = {
  137621. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  137622. 27.5, 38.5, 49.5, 60.5,
  137623. };
  137624. static long _vq_quantmap__44u9_p7_0[] = {
  137625. 11, 9, 7, 5, 3, 1, 0, 2,
  137626. 4, 6, 8, 10, 12,
  137627. };
  137628. static encode_aux_threshmatch _vq_auxt__44u9_p7_0 = {
  137629. _vq_quantthresh__44u9_p7_0,
  137630. _vq_quantmap__44u9_p7_0,
  137631. 13,
  137632. 13
  137633. };
  137634. static static_codebook _44u9_p7_0 = {
  137635. 2, 169,
  137636. _vq_lengthlist__44u9_p7_0,
  137637. 1, -523206656, 1618345984, 4, 0,
  137638. _vq_quantlist__44u9_p7_0,
  137639. NULL,
  137640. &_vq_auxt__44u9_p7_0,
  137641. NULL,
  137642. 0
  137643. };
  137644. static long _vq_quantlist__44u9_p7_1[] = {
  137645. 5,
  137646. 4,
  137647. 6,
  137648. 3,
  137649. 7,
  137650. 2,
  137651. 8,
  137652. 1,
  137653. 9,
  137654. 0,
  137655. 10,
  137656. };
  137657. static long _vq_lengthlist__44u9_p7_1[] = {
  137658. 5, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7,
  137659. 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  137660. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7,
  137661. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137662. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137663. 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137664. 7, 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 7, 8, 8, 7, 7,
  137665. 7, 7, 7, 7, 7, 8, 8, 8, 8,
  137666. };
  137667. static float _vq_quantthresh__44u9_p7_1[] = {
  137668. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137669. 3.5, 4.5,
  137670. };
  137671. static long _vq_quantmap__44u9_p7_1[] = {
  137672. 9, 7, 5, 3, 1, 0, 2, 4,
  137673. 6, 8, 10,
  137674. };
  137675. static encode_aux_threshmatch _vq_auxt__44u9_p7_1 = {
  137676. _vq_quantthresh__44u9_p7_1,
  137677. _vq_quantmap__44u9_p7_1,
  137678. 11,
  137679. 11
  137680. };
  137681. static static_codebook _44u9_p7_1 = {
  137682. 2, 121,
  137683. _vq_lengthlist__44u9_p7_1,
  137684. 1, -531365888, 1611661312, 4, 0,
  137685. _vq_quantlist__44u9_p7_1,
  137686. NULL,
  137687. &_vq_auxt__44u9_p7_1,
  137688. NULL,
  137689. 0
  137690. };
  137691. static long _vq_quantlist__44u9_p8_0[] = {
  137692. 7,
  137693. 6,
  137694. 8,
  137695. 5,
  137696. 9,
  137697. 4,
  137698. 10,
  137699. 3,
  137700. 11,
  137701. 2,
  137702. 12,
  137703. 1,
  137704. 13,
  137705. 0,
  137706. 14,
  137707. };
  137708. static long _vq_lengthlist__44u9_p8_0[] = {
  137709. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,11,10, 4,
  137710. 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  137711. 6, 8, 8, 9,10, 9, 9,10,10,11,11,12,12, 7, 8, 8,
  137712. 10,10,11,11,10,10,11,11,12,12,13,12, 7, 8, 8,10,
  137713. 10,11,11,10,10,11,11,12,12,12,13, 8,10, 9,11,11,
  137714. 12,12,11,11,12,12,13,13,14,13, 8, 9, 9,11,11,12,
  137715. 12,11,12,12,12,13,13,14,13, 8, 9, 9,10,10,12,11,
  137716. 13,12,13,13,14,13,15,14, 8, 9, 9,10,10,11,12,12,
  137717. 12,13,13,13,14,14,14, 9,10,10,12,11,13,12,13,13,
  137718. 14,13,14,14,14,15, 9,10,10,11,12,12,12,13,13,14,
  137719. 14,14,15,15,15,10,11,11,12,12,13,13,14,14,14,14,
  137720. 15,14,16,15,10,11,11,12,12,13,13,13,14,14,14,14,
  137721. 14,15,16,11,12,12,13,13,14,13,14,14,15,14,15,16,
  137722. 16,16,11,12,12,13,13,14,13,14,14,15,15,15,16,15,
  137723. 15,
  137724. };
  137725. static float _vq_quantthresh__44u9_p8_0[] = {
  137726. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  137727. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  137728. };
  137729. static long _vq_quantmap__44u9_p8_0[] = {
  137730. 13, 11, 9, 7, 5, 3, 1, 0,
  137731. 2, 4, 6, 8, 10, 12, 14,
  137732. };
  137733. static encode_aux_threshmatch _vq_auxt__44u9_p8_0 = {
  137734. _vq_quantthresh__44u9_p8_0,
  137735. _vq_quantmap__44u9_p8_0,
  137736. 15,
  137737. 15
  137738. };
  137739. static static_codebook _44u9_p8_0 = {
  137740. 2, 225,
  137741. _vq_lengthlist__44u9_p8_0,
  137742. 1, -520986624, 1620377600, 4, 0,
  137743. _vq_quantlist__44u9_p8_0,
  137744. NULL,
  137745. &_vq_auxt__44u9_p8_0,
  137746. NULL,
  137747. 0
  137748. };
  137749. static long _vq_quantlist__44u9_p8_1[] = {
  137750. 10,
  137751. 9,
  137752. 11,
  137753. 8,
  137754. 12,
  137755. 7,
  137756. 13,
  137757. 6,
  137758. 14,
  137759. 5,
  137760. 15,
  137761. 4,
  137762. 16,
  137763. 3,
  137764. 17,
  137765. 2,
  137766. 18,
  137767. 1,
  137768. 19,
  137769. 0,
  137770. 20,
  137771. };
  137772. static long _vq_lengthlist__44u9_p8_1[] = {
  137773. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  137774. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137775. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8,
  137776. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  137777. 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  137778. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  137779. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  137780. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10, 8, 8,
  137781. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137782. 9,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137783. 10, 9,10, 9,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  137784. 9, 9, 9, 9, 9,10,10, 9,10,10,10,10,10, 9, 9, 9,
  137785. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137786. 10,10, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  137787. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137788. 9, 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  137789. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137790. 10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137791. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  137792. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  137793. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137794. 9, 9, 9, 9,10, 9, 9,10,10,10,10,10,10,10,10,10,
  137795. 10,10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,
  137796. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,10,
  137797. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  137798. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  137799. 10,10,10,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137800. 10,10,10,10,10,10,10,10,10,
  137801. };
  137802. static float _vq_quantthresh__44u9_p8_1[] = {
  137803. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  137804. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  137805. 6.5, 7.5, 8.5, 9.5,
  137806. };
  137807. static long _vq_quantmap__44u9_p8_1[] = {
  137808. 19, 17, 15, 13, 11, 9, 7, 5,
  137809. 3, 1, 0, 2, 4, 6, 8, 10,
  137810. 12, 14, 16, 18, 20,
  137811. };
  137812. static encode_aux_threshmatch _vq_auxt__44u9_p8_1 = {
  137813. _vq_quantthresh__44u9_p8_1,
  137814. _vq_quantmap__44u9_p8_1,
  137815. 21,
  137816. 21
  137817. };
  137818. static static_codebook _44u9_p8_1 = {
  137819. 2, 441,
  137820. _vq_lengthlist__44u9_p8_1,
  137821. 1, -529268736, 1611661312, 5, 0,
  137822. _vq_quantlist__44u9_p8_1,
  137823. NULL,
  137824. &_vq_auxt__44u9_p8_1,
  137825. NULL,
  137826. 0
  137827. };
  137828. static long _vq_quantlist__44u9_p9_0[] = {
  137829. 7,
  137830. 6,
  137831. 8,
  137832. 5,
  137833. 9,
  137834. 4,
  137835. 10,
  137836. 3,
  137837. 11,
  137838. 2,
  137839. 12,
  137840. 1,
  137841. 13,
  137842. 0,
  137843. 14,
  137844. };
  137845. static long _vq_lengthlist__44u9_p9_0[] = {
  137846. 1, 3, 3,11,11,11,11,11,11,11,11,11,11,11,11, 4,
  137847. 10,11,11,11,11,11,11,11,11,11,11,11,11,11, 4,10,
  137848. 10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137849. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137850. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137851. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137852. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137853. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137854. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137855. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137856. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137857. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137858. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137859. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137860. 10,
  137861. };
  137862. static float _vq_quantthresh__44u9_p9_0[] = {
  137863. -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5,
  137864. 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  137865. };
  137866. static long _vq_quantmap__44u9_p9_0[] = {
  137867. 13, 11, 9, 7, 5, 3, 1, 0,
  137868. 2, 4, 6, 8, 10, 12, 14,
  137869. };
  137870. static encode_aux_threshmatch _vq_auxt__44u9_p9_0 = {
  137871. _vq_quantthresh__44u9_p9_0,
  137872. _vq_quantmap__44u9_p9_0,
  137873. 15,
  137874. 15
  137875. };
  137876. static static_codebook _44u9_p9_0 = {
  137877. 2, 225,
  137878. _vq_lengthlist__44u9_p9_0,
  137879. 1, -510036736, 1631393792, 4, 0,
  137880. _vq_quantlist__44u9_p9_0,
  137881. NULL,
  137882. &_vq_auxt__44u9_p9_0,
  137883. NULL,
  137884. 0
  137885. };
  137886. static long _vq_quantlist__44u9_p9_1[] = {
  137887. 9,
  137888. 8,
  137889. 10,
  137890. 7,
  137891. 11,
  137892. 6,
  137893. 12,
  137894. 5,
  137895. 13,
  137896. 4,
  137897. 14,
  137898. 3,
  137899. 15,
  137900. 2,
  137901. 16,
  137902. 1,
  137903. 17,
  137904. 0,
  137905. 18,
  137906. };
  137907. static long _vq_lengthlist__44u9_p9_1[] = {
  137908. 1, 4, 4, 7, 7, 8, 7, 8, 7, 9, 8,10, 9,10,10,11,
  137909. 11,12,12, 4, 7, 6, 9, 9,10, 9, 9, 8,10,10,11,10,
  137910. 12,10,13,12,13,12, 4, 6, 6, 9, 9, 9, 9, 9, 9,10,
  137911. 10,11,11,11,12,12,12,12,12, 7, 9, 8,11,10,10,10,
  137912. 11,10,11,11,12,12,13,12,13,13,13,13, 7, 8, 9,10,
  137913. 10,11,11,10,10,11,11,11,12,13,13,13,13,14,14, 8,
  137914. 9, 9,11,11,12,11,12,12,13,12,12,13,13,14,15,14,
  137915. 14,14, 8, 9, 9,10,11,11,11,12,12,13,12,13,13,14,
  137916. 14,14,15,14,16, 8, 9, 9,11,10,12,12,12,12,15,13,
  137917. 13,13,17,14,15,15,15,14, 8, 9, 9,10,11,11,12,13,
  137918. 12,13,13,13,14,15,14,14,14,16,15, 9,11,10,12,12,
  137919. 13,13,13,13,14,14,16,15,14,14,14,15,15,17, 9,10,
  137920. 10,11,11,13,13,13,14,14,13,15,14,15,14,15,16,15,
  137921. 16,10,11,11,12,12,13,14,15,14,15,14,14,15,17,16,
  137922. 15,15,17,17,10,12,11,13,12,14,14,13,14,15,15,15,
  137923. 15,16,17,17,15,17,16,11,12,12,14,13,15,14,15,16,
  137924. 17,15,17,15,17,15,15,16,17,15,11,11,12,14,14,14,
  137925. 14,14,15,15,16,15,17,17,17,16,17,16,15,12,12,13,
  137926. 14,14,14,15,14,15,15,16,16,17,16,17,15,17,17,16,
  137927. 12,14,12,14,14,15,15,15,14,14,16,16,16,15,16,16,
  137928. 15,17,15,12,13,13,14,15,14,15,17,15,17,16,17,17,
  137929. 17,16,17,16,17,17,12,13,13,14,16,15,15,15,16,15,
  137930. 17,17,15,17,15,17,16,16,17,
  137931. };
  137932. static float _vq_quantthresh__44u9_p9_1[] = {
  137933. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  137934. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  137935. 367.5, 416.5,
  137936. };
  137937. static long _vq_quantmap__44u9_p9_1[] = {
  137938. 17, 15, 13, 11, 9, 7, 5, 3,
  137939. 1, 0, 2, 4, 6, 8, 10, 12,
  137940. 14, 16, 18,
  137941. };
  137942. static encode_aux_threshmatch _vq_auxt__44u9_p9_1 = {
  137943. _vq_quantthresh__44u9_p9_1,
  137944. _vq_quantmap__44u9_p9_1,
  137945. 19,
  137946. 19
  137947. };
  137948. static static_codebook _44u9_p9_1 = {
  137949. 2, 361,
  137950. _vq_lengthlist__44u9_p9_1,
  137951. 1, -518287360, 1622704128, 5, 0,
  137952. _vq_quantlist__44u9_p9_1,
  137953. NULL,
  137954. &_vq_auxt__44u9_p9_1,
  137955. NULL,
  137956. 0
  137957. };
  137958. static long _vq_quantlist__44u9_p9_2[] = {
  137959. 24,
  137960. 23,
  137961. 25,
  137962. 22,
  137963. 26,
  137964. 21,
  137965. 27,
  137966. 20,
  137967. 28,
  137968. 19,
  137969. 29,
  137970. 18,
  137971. 30,
  137972. 17,
  137973. 31,
  137974. 16,
  137975. 32,
  137976. 15,
  137977. 33,
  137978. 14,
  137979. 34,
  137980. 13,
  137981. 35,
  137982. 12,
  137983. 36,
  137984. 11,
  137985. 37,
  137986. 10,
  137987. 38,
  137988. 9,
  137989. 39,
  137990. 8,
  137991. 40,
  137992. 7,
  137993. 41,
  137994. 6,
  137995. 42,
  137996. 5,
  137997. 43,
  137998. 4,
  137999. 44,
  138000. 3,
  138001. 45,
  138002. 2,
  138003. 46,
  138004. 1,
  138005. 47,
  138006. 0,
  138007. 48,
  138008. };
  138009. static long _vq_lengthlist__44u9_p9_2[] = {
  138010. 2, 4, 4, 5, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  138011. 6, 6, 6, 7, 6, 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138012. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138013. 7,
  138014. };
  138015. static float _vq_quantthresh__44u9_p9_2[] = {
  138016. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  138017. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  138018. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  138019. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  138020. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  138021. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  138022. };
  138023. static long _vq_quantmap__44u9_p9_2[] = {
  138024. 47, 45, 43, 41, 39, 37, 35, 33,
  138025. 31, 29, 27, 25, 23, 21, 19, 17,
  138026. 15, 13, 11, 9, 7, 5, 3, 1,
  138027. 0, 2, 4, 6, 8, 10, 12, 14,
  138028. 16, 18, 20, 22, 24, 26, 28, 30,
  138029. 32, 34, 36, 38, 40, 42, 44, 46,
  138030. 48,
  138031. };
  138032. static encode_aux_threshmatch _vq_auxt__44u9_p9_2 = {
  138033. _vq_quantthresh__44u9_p9_2,
  138034. _vq_quantmap__44u9_p9_2,
  138035. 49,
  138036. 49
  138037. };
  138038. static static_codebook _44u9_p9_2 = {
  138039. 1, 49,
  138040. _vq_lengthlist__44u9_p9_2,
  138041. 1, -526909440, 1611661312, 6, 0,
  138042. _vq_quantlist__44u9_p9_2,
  138043. NULL,
  138044. &_vq_auxt__44u9_p9_2,
  138045. NULL,
  138046. 0
  138047. };
  138048. static long _huff_lengthlist__44un1__long[] = {
  138049. 5, 6,12, 9,14, 9, 9,19, 6, 1, 5, 5, 8, 7, 9,19,
  138050. 12, 4, 4, 7, 7, 9,11,18, 9, 5, 6, 6, 8, 7, 8,17,
  138051. 14, 8, 7, 8, 8,10,12,18, 9, 6, 8, 6, 8, 6, 8,18,
  138052. 9, 8,11, 8,11, 7, 5,15,16,18,18,18,17,15,11,18,
  138053. };
  138054. static static_codebook _huff_book__44un1__long = {
  138055. 2, 64,
  138056. _huff_lengthlist__44un1__long,
  138057. 0, 0, 0, 0, 0,
  138058. NULL,
  138059. NULL,
  138060. NULL,
  138061. NULL,
  138062. 0
  138063. };
  138064. static long _vq_quantlist__44un1__p1_0[] = {
  138065. 1,
  138066. 0,
  138067. 2,
  138068. };
  138069. static long _vq_lengthlist__44un1__p1_0[] = {
  138070. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  138071. 10,11, 5, 8, 8, 8,11,10, 8,11,10, 4, 9, 9, 8,11,
  138072. 11, 8,11,11, 8,12,11,10,12,14,11,13,13, 7,11,11,
  138073. 10,13,11,11,13,14, 4, 8, 9, 8,11,11, 8,11,12, 7,
  138074. 11,11,11,14,13,10,11,13, 8,11,12,11,13,13,10,14,
  138075. 12,
  138076. };
  138077. static float _vq_quantthresh__44un1__p1_0[] = {
  138078. -0.5, 0.5,
  138079. };
  138080. static long _vq_quantmap__44un1__p1_0[] = {
  138081. 1, 0, 2,
  138082. };
  138083. static encode_aux_threshmatch _vq_auxt__44un1__p1_0 = {
  138084. _vq_quantthresh__44un1__p1_0,
  138085. _vq_quantmap__44un1__p1_0,
  138086. 3,
  138087. 3
  138088. };
  138089. static static_codebook _44un1__p1_0 = {
  138090. 4, 81,
  138091. _vq_lengthlist__44un1__p1_0,
  138092. 1, -535822336, 1611661312, 2, 0,
  138093. _vq_quantlist__44un1__p1_0,
  138094. NULL,
  138095. &_vq_auxt__44un1__p1_0,
  138096. NULL,
  138097. 0
  138098. };
  138099. static long _vq_quantlist__44un1__p2_0[] = {
  138100. 1,
  138101. 0,
  138102. 2,
  138103. };
  138104. static long _vq_lengthlist__44un1__p2_0[] = {
  138105. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  138106. 7, 9, 5, 7, 7, 6, 8, 7, 7, 9, 8, 4, 7, 7, 7, 9,
  138107. 8, 7, 8, 8, 7, 9, 8, 8, 8,10, 9,10,10, 6, 8, 8,
  138108. 7,10, 8, 9,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  138109. 8, 8, 9,10,10, 7, 8,10, 6, 8, 9, 9,10,10, 8,10,
  138110. 8,
  138111. };
  138112. static float _vq_quantthresh__44un1__p2_0[] = {
  138113. -0.5, 0.5,
  138114. };
  138115. static long _vq_quantmap__44un1__p2_0[] = {
  138116. 1, 0, 2,
  138117. };
  138118. static encode_aux_threshmatch _vq_auxt__44un1__p2_0 = {
  138119. _vq_quantthresh__44un1__p2_0,
  138120. _vq_quantmap__44un1__p2_0,
  138121. 3,
  138122. 3
  138123. };
  138124. static static_codebook _44un1__p2_0 = {
  138125. 4, 81,
  138126. _vq_lengthlist__44un1__p2_0,
  138127. 1, -535822336, 1611661312, 2, 0,
  138128. _vq_quantlist__44un1__p2_0,
  138129. NULL,
  138130. &_vq_auxt__44un1__p2_0,
  138131. NULL,
  138132. 0
  138133. };
  138134. static long _vq_quantlist__44un1__p3_0[] = {
  138135. 2,
  138136. 1,
  138137. 3,
  138138. 0,
  138139. 4,
  138140. };
  138141. static long _vq_lengthlist__44un1__p3_0[] = {
  138142. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  138143. 10, 9,12,12, 9, 9,10,11,12, 6, 8, 8,10,10, 8,10,
  138144. 10,11,11, 8, 9,10,11,11,10,11,11,13,13,10,11,11,
  138145. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10,10,11,
  138146. 11,10,11,11,13,12,10,11,11,13,12, 9,11,11,15,13,
  138147. 10,12,11,15,13,10,11,11,15,14,12,14,13,16,15,12,
  138148. 13,13,17,16, 9,11,11,13,15,10,11,12,14,15,10,11,
  138149. 12,14,15,12,13,13,15,16,12,13,13,16,16, 5, 8, 8,
  138150. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  138151. 14,11,12,12,14,14, 8,11,10,13,12,10,11,12,12,13,
  138152. 10,12,12,13,13,12,12,13,13,15,11,12,13,15,14, 7,
  138153. 10,10,12,12, 9,12,11,13,12,10,12,12,13,14,12,13,
  138154. 12,15,13,11,13,12,14,15,10,12,12,16,14,11,12,12,
  138155. 16,15,11,13,12,17,16,13,13,15,15,17,13,15,15,20,
  138156. 17,10,12,12,14,16,11,12,12,15,15,11,13,13,15,18,
  138157. 13,14,13,15,15,13,15,14,16,16, 5, 8, 8,11,11, 8,
  138158. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  138159. 12,14,15, 7,10,10,13,12,10,12,12,14,13, 9,10,12,
  138160. 12,13,11,13,13,15,15,11,12,13,13,15, 8,10,10,12,
  138161. 13,10,12,12,13,13,10,12,11,13,13,11,13,12,15,15,
  138162. 12,13,12,15,13,10,12,12,16,14,11,12,12,16,15,10,
  138163. 12,12,16,14,14,15,14,18,16,13,13,14,15,16,10,12,
  138164. 12,14,16,11,13,13,16,16,11,13,12,14,16,13,15,15,
  138165. 18,18,13,15,13,16,14, 8,11,11,16,16,10,13,13,17,
  138166. 16,10,12,12,16,15,14,16,15,20,17,13,14,14,17,17,
  138167. 9,12,12,16,16,11,13,14,16,17,11,13,13,16,16,15,
  138168. 15,19,18, 0,14,15,15,18,18, 9,12,12,17,16,11,13,
  138169. 12,17,16,11,12,13,15,17,15,16,15, 0,19,14,15,14,
  138170. 19,18,12,14,14, 0,16,13,14,14,19,18,13,15,16,17,
  138171. 16,15,15,17,18, 0,14,16,16,19, 0,12,14,14,16,18,
  138172. 13,15,13,17,18,13,15,14,17,18,15,18,14,18,18,16,
  138173. 17,16, 0,17, 8,11,11,15,15,10,12,12,16,16,10,13,
  138174. 13,16,16,13,15,14,17,17,14,15,17,17,18, 9,12,12,
  138175. 16,15,11,13,13,16,16,11,12,13,17,17,14,14,15,17,
  138176. 17,14,15,16, 0,18, 9,12,12,16,17,11,13,13,16,17,
  138177. 11,14,13,18,17,14,16,14,17,17,15,17,17,18,18,12,
  138178. 14,14, 0,16,13,15,15,19, 0,12,13,15, 0, 0,14,17,
  138179. 16,19, 0,16,15,18,18, 0,12,14,14,17, 0,13,14,14,
  138180. 17, 0,13,15,14, 0,18,15,16,16, 0,18,15,18,15, 0,
  138181. 17,
  138182. };
  138183. static float _vq_quantthresh__44un1__p3_0[] = {
  138184. -1.5, -0.5, 0.5, 1.5,
  138185. };
  138186. static long _vq_quantmap__44un1__p3_0[] = {
  138187. 3, 1, 0, 2, 4,
  138188. };
  138189. static encode_aux_threshmatch _vq_auxt__44un1__p3_0 = {
  138190. _vq_quantthresh__44un1__p3_0,
  138191. _vq_quantmap__44un1__p3_0,
  138192. 5,
  138193. 5
  138194. };
  138195. static static_codebook _44un1__p3_0 = {
  138196. 4, 625,
  138197. _vq_lengthlist__44un1__p3_0,
  138198. 1, -533725184, 1611661312, 3, 0,
  138199. _vq_quantlist__44un1__p3_0,
  138200. NULL,
  138201. &_vq_auxt__44un1__p3_0,
  138202. NULL,
  138203. 0
  138204. };
  138205. static long _vq_quantlist__44un1__p4_0[] = {
  138206. 2,
  138207. 1,
  138208. 3,
  138209. 0,
  138210. 4,
  138211. };
  138212. static long _vq_lengthlist__44un1__p4_0[] = {
  138213. 3, 5, 5, 9, 9, 5, 6, 6,10, 9, 5, 6, 6, 9,10,10,
  138214. 10,10,12,11, 9,10,10,12,12, 5, 7, 7,10,10, 7, 7,
  138215. 8,10,11, 7, 7, 8,10,11,10,10,11,11,13,10,10,11,
  138216. 11,13, 6, 7, 7,10,10, 7, 8, 7,11,10, 7, 8, 7,10,
  138217. 10,10,11, 9,13,11,10,11,10,13,11,10,10,10,14,13,
  138218. 10,11,11,14,13,10,10,11,13,14,12,12,13,15,15,12,
  138219. 12,13,13,14,10,10,10,12,13,10,11,10,13,13,10,11,
  138220. 11,13,13,12,13,12,14,13,12,13,13,14,13, 5, 7, 7,
  138221. 10,10, 7, 8, 8,11,10, 7, 8, 8,10,10,11,11,11,13,
  138222. 13,10,11,11,12,12, 7, 8, 8,11,11, 7, 8, 9,10,12,
  138223. 8, 9, 9,11,11,11,10,12,11,14,11,11,12,13,13, 6,
  138224. 8, 8,10,11, 7, 9, 7,12,10, 8, 9,10,11,12,10,12,
  138225. 10,14,11,11,12,11,13,13,10,11,11,14,14,10,10,11,
  138226. 13,14,11,12,12,15,13,12,11,14,12,16,12,13,14,15,
  138227. 16,10,10,11,13,14,10,11,10,14,12,11,12,12,13,14,
  138228. 12,13,11,15,12,14,14,14,15,15, 5, 7, 7,10,10, 7,
  138229. 8, 8,10,10, 7, 8, 8,10,11,10,11,10,12,12,10,11,
  138230. 11,12,13, 6, 8, 8,11,11, 8, 9, 9,12,11, 7, 7, 9,
  138231. 10,12,11,11,11,12,13,11,10,12,11,15, 7, 8, 8,11,
  138232. 11, 8, 9, 9,11,11, 7, 9, 8,12,10,11,12,11,13,12,
  138233. 11,12,10,15,11,10,11,10,14,12,11,12,11,14,13,10,
  138234. 10,11,13,14,13,13,13,17,15,12,11,14,12,15,10,10,
  138235. 11,13,14,11,12,12,14,14,10,11,10,14,13,13,14,13,
  138236. 16,17,12,14,11,16,12, 9,10,10,14,13,10,11,10,14,
  138237. 14,10,11,11,13,13,13,14,14,16,15,12,13,13,14,14,
  138238. 9,11,10,14,13,10,10,12,13,14,11,12,11,14,13,13,
  138239. 14,14,14,15,13,14,14,15,15, 9,10,11,13,14,10,11,
  138240. 10,15,13,11,11,12,12,15,13,14,12,15,14,13,13,14,
  138241. 14,15,12,13,12,16,14,11,11,12,15,14,13,15,13,16,
  138242. 14,13,12,15,12,17,15,16,15,16,16,12,12,13,13,15,
  138243. 11,13,11,15,14,13,13,14,15,17,13,14,12, 0,13,14,
  138244. 15,14,15, 0, 9,10,10,13,13,10,11,11,13,13,10,11,
  138245. 11,13,13,12,13,12,14,14,13,14,14,15,17, 9,10,10,
  138246. 13,13,11,12,11,15,12,10,10,11,13,16,13,14,13,15,
  138247. 14,13,13,14,15,16,10,10,11,13,14,11,11,12,13,14,
  138248. 10,12,11,14,14,13,13,13,14,15,13,15,13,16,15,12,
  138249. 13,12,15,13,12,15,13,15,15,11,11,13,14,15,15,15,
  138250. 15,15,17,13,12,14,13,17,12,12,14,14,15,13,13,14,
  138251. 14,16,11,13,11,16,15,14,16,16,17, 0,14,13,11,16,
  138252. 12,
  138253. };
  138254. static float _vq_quantthresh__44un1__p4_0[] = {
  138255. -1.5, -0.5, 0.5, 1.5,
  138256. };
  138257. static long _vq_quantmap__44un1__p4_0[] = {
  138258. 3, 1, 0, 2, 4,
  138259. };
  138260. static encode_aux_threshmatch _vq_auxt__44un1__p4_0 = {
  138261. _vq_quantthresh__44un1__p4_0,
  138262. _vq_quantmap__44un1__p4_0,
  138263. 5,
  138264. 5
  138265. };
  138266. static static_codebook _44un1__p4_0 = {
  138267. 4, 625,
  138268. _vq_lengthlist__44un1__p4_0,
  138269. 1, -533725184, 1611661312, 3, 0,
  138270. _vq_quantlist__44un1__p4_0,
  138271. NULL,
  138272. &_vq_auxt__44un1__p4_0,
  138273. NULL,
  138274. 0
  138275. };
  138276. static long _vq_quantlist__44un1__p5_0[] = {
  138277. 4,
  138278. 3,
  138279. 5,
  138280. 2,
  138281. 6,
  138282. 1,
  138283. 7,
  138284. 0,
  138285. 8,
  138286. };
  138287. static long _vq_lengthlist__44un1__p5_0[] = {
  138288. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  138289. 10, 9, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 7, 9, 9,
  138290. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 8, 8, 8,
  138291. 9, 9,10,10,11,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  138292. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  138293. 12,
  138294. };
  138295. static float _vq_quantthresh__44un1__p5_0[] = {
  138296. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  138297. };
  138298. static long _vq_quantmap__44un1__p5_0[] = {
  138299. 7, 5, 3, 1, 0, 2, 4, 6,
  138300. 8,
  138301. };
  138302. static encode_aux_threshmatch _vq_auxt__44un1__p5_0 = {
  138303. _vq_quantthresh__44un1__p5_0,
  138304. _vq_quantmap__44un1__p5_0,
  138305. 9,
  138306. 9
  138307. };
  138308. static static_codebook _44un1__p5_0 = {
  138309. 2, 81,
  138310. _vq_lengthlist__44un1__p5_0,
  138311. 1, -531628032, 1611661312, 4, 0,
  138312. _vq_quantlist__44un1__p5_0,
  138313. NULL,
  138314. &_vq_auxt__44un1__p5_0,
  138315. NULL,
  138316. 0
  138317. };
  138318. static long _vq_quantlist__44un1__p6_0[] = {
  138319. 6,
  138320. 5,
  138321. 7,
  138322. 4,
  138323. 8,
  138324. 3,
  138325. 9,
  138326. 2,
  138327. 10,
  138328. 1,
  138329. 11,
  138330. 0,
  138331. 12,
  138332. };
  138333. static long _vq_lengthlist__44un1__p6_0[] = {
  138334. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,15,15, 4, 5, 5,
  138335. 8, 8, 9, 9,11,11,12,12,16,16, 4, 5, 6, 8, 8, 9,
  138336. 9,11,11,12,12,14,14, 7, 8, 8, 9, 9,10,10,11,12,
  138337. 13,13,16,17, 7, 8, 8, 9, 9,10,10,12,12,12,13,15,
  138338. 15, 9,10,10,10,10,11,11,12,12,13,13,15,16, 9, 9,
  138339. 9,10,10,11,11,13,12,13,13,17,17,10,11,11,11,12,
  138340. 12,12,13,13,14,15, 0,18,10,11,11,12,12,12,13,14,
  138341. 13,14,14,17,16,11,12,12,13,13,14,14,14,14,15,16,
  138342. 17,16,11,12,12,13,13,14,14,14,14,15,15,17,17,14,
  138343. 15,15,16,16,16,17,17,16, 0,17, 0,18,14,15,15,16,
  138344. 16, 0,15,18,18, 0,16, 0, 0,
  138345. };
  138346. static float _vq_quantthresh__44un1__p6_0[] = {
  138347. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  138348. 12.5, 17.5, 22.5, 27.5,
  138349. };
  138350. static long _vq_quantmap__44un1__p6_0[] = {
  138351. 11, 9, 7, 5, 3, 1, 0, 2,
  138352. 4, 6, 8, 10, 12,
  138353. };
  138354. static encode_aux_threshmatch _vq_auxt__44un1__p6_0 = {
  138355. _vq_quantthresh__44un1__p6_0,
  138356. _vq_quantmap__44un1__p6_0,
  138357. 13,
  138358. 13
  138359. };
  138360. static static_codebook _44un1__p6_0 = {
  138361. 2, 169,
  138362. _vq_lengthlist__44un1__p6_0,
  138363. 1, -526516224, 1616117760, 4, 0,
  138364. _vq_quantlist__44un1__p6_0,
  138365. NULL,
  138366. &_vq_auxt__44un1__p6_0,
  138367. NULL,
  138368. 0
  138369. };
  138370. static long _vq_quantlist__44un1__p6_1[] = {
  138371. 2,
  138372. 1,
  138373. 3,
  138374. 0,
  138375. 4,
  138376. };
  138377. static long _vq_lengthlist__44un1__p6_1[] = {
  138378. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 6, 5, 5,
  138379. 6, 5, 6, 6, 5, 6, 6, 6, 6,
  138380. };
  138381. static float _vq_quantthresh__44un1__p6_1[] = {
  138382. -1.5, -0.5, 0.5, 1.5,
  138383. };
  138384. static long _vq_quantmap__44un1__p6_1[] = {
  138385. 3, 1, 0, 2, 4,
  138386. };
  138387. static encode_aux_threshmatch _vq_auxt__44un1__p6_1 = {
  138388. _vq_quantthresh__44un1__p6_1,
  138389. _vq_quantmap__44un1__p6_1,
  138390. 5,
  138391. 5
  138392. };
  138393. static static_codebook _44un1__p6_1 = {
  138394. 2, 25,
  138395. _vq_lengthlist__44un1__p6_1,
  138396. 1, -533725184, 1611661312, 3, 0,
  138397. _vq_quantlist__44un1__p6_1,
  138398. NULL,
  138399. &_vq_auxt__44un1__p6_1,
  138400. NULL,
  138401. 0
  138402. };
  138403. static long _vq_quantlist__44un1__p7_0[] = {
  138404. 2,
  138405. 1,
  138406. 3,
  138407. 0,
  138408. 4,
  138409. };
  138410. static long _vq_lengthlist__44un1__p7_0[] = {
  138411. 1, 5, 3,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  138412. 11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,
  138413. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138414. 11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138415. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138416. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138417. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138418. 11,11,11,11,11,11,11,11,11,11,11,11,11, 8,11,11,
  138419. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138420. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138421. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  138422. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138423. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138424. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138425. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138426. 11,11,11,11,11,11,11,11,11,11, 7,11,11,11,11,11,
  138427. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138428. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  138429. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138430. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138431. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138432. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138433. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138434. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138435. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138436. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138437. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138438. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138439. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138440. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138441. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138442. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138443. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138444. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138445. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138446. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138447. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138448. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138449. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138450. 10,
  138451. };
  138452. static float _vq_quantthresh__44un1__p7_0[] = {
  138453. -253.5, -84.5, 84.5, 253.5,
  138454. };
  138455. static long _vq_quantmap__44un1__p7_0[] = {
  138456. 3, 1, 0, 2, 4,
  138457. };
  138458. static encode_aux_threshmatch _vq_auxt__44un1__p7_0 = {
  138459. _vq_quantthresh__44un1__p7_0,
  138460. _vq_quantmap__44un1__p7_0,
  138461. 5,
  138462. 5
  138463. };
  138464. static static_codebook _44un1__p7_0 = {
  138465. 4, 625,
  138466. _vq_lengthlist__44un1__p7_0,
  138467. 1, -518709248, 1626677248, 3, 0,
  138468. _vq_quantlist__44un1__p7_0,
  138469. NULL,
  138470. &_vq_auxt__44un1__p7_0,
  138471. NULL,
  138472. 0
  138473. };
  138474. static long _vq_quantlist__44un1__p7_1[] = {
  138475. 6,
  138476. 5,
  138477. 7,
  138478. 4,
  138479. 8,
  138480. 3,
  138481. 9,
  138482. 2,
  138483. 10,
  138484. 1,
  138485. 11,
  138486. 0,
  138487. 12,
  138488. };
  138489. static long _vq_lengthlist__44un1__p7_1[] = {
  138490. 1, 4, 4, 6, 6, 6, 6, 9, 8, 9, 8, 8, 8, 5, 7, 7,
  138491. 7, 7, 8, 8, 8,10, 8,10, 8, 9, 5, 7, 7, 8, 7, 7,
  138492. 8,10,10,11,10,12,11, 7, 8, 8, 9, 9, 9,10,11,11,
  138493. 11,11,11,11, 7, 8, 8, 8, 9, 9, 9,10,10,10,11,11,
  138494. 12, 7, 8, 8, 9, 9,10,11,11,12,11,12,11,11, 7, 8,
  138495. 8, 9, 9,10,10,11,11,11,12,12,11, 8,10,10,10,10,
  138496. 11,11,14,11,12,12,12,13, 9,10,10,10,10,12,11,14,
  138497. 11,14,11,12,13,10,11,11,11,11,13,11,14,14,13,13,
  138498. 13,14,11,11,11,12,11,12,12,12,13,14,14,13,14,12,
  138499. 11,12,12,12,12,13,13,13,14,13,14,14,11,12,12,14,
  138500. 12,13,13,12,13,13,14,14,14,
  138501. };
  138502. static float _vq_quantthresh__44un1__p7_1[] = {
  138503. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  138504. 32.5, 45.5, 58.5, 71.5,
  138505. };
  138506. static long _vq_quantmap__44un1__p7_1[] = {
  138507. 11, 9, 7, 5, 3, 1, 0, 2,
  138508. 4, 6, 8, 10, 12,
  138509. };
  138510. static encode_aux_threshmatch _vq_auxt__44un1__p7_1 = {
  138511. _vq_quantthresh__44un1__p7_1,
  138512. _vq_quantmap__44un1__p7_1,
  138513. 13,
  138514. 13
  138515. };
  138516. static static_codebook _44un1__p7_1 = {
  138517. 2, 169,
  138518. _vq_lengthlist__44un1__p7_1,
  138519. 1, -523010048, 1618608128, 4, 0,
  138520. _vq_quantlist__44un1__p7_1,
  138521. NULL,
  138522. &_vq_auxt__44un1__p7_1,
  138523. NULL,
  138524. 0
  138525. };
  138526. static long _vq_quantlist__44un1__p7_2[] = {
  138527. 6,
  138528. 5,
  138529. 7,
  138530. 4,
  138531. 8,
  138532. 3,
  138533. 9,
  138534. 2,
  138535. 10,
  138536. 1,
  138537. 11,
  138538. 0,
  138539. 12,
  138540. };
  138541. static long _vq_lengthlist__44un1__p7_2[] = {
  138542. 3, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9, 9, 8, 4, 5, 5,
  138543. 6, 6, 8, 8, 9, 8, 9, 9, 9, 9, 4, 5, 5, 7, 6, 8,
  138544. 8, 8, 8, 9, 8, 9, 8, 6, 7, 7, 7, 8, 8, 8, 9, 9,
  138545. 9, 9, 9, 9, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  138546. 9, 7, 8, 8, 8, 8, 9, 8, 9, 9,10, 9, 9,10, 7, 8,
  138547. 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 8, 9, 9, 9, 9,
  138548. 9, 9, 9, 9,10,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9,
  138549. 9, 9, 9,10,10, 9, 9, 9,10, 9, 9,10, 9, 9,10,10,
  138550. 10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10, 9,
  138551. 9, 9,10, 9, 9,10,10, 9,10,10,10,10, 9, 9, 9,10,
  138552. 9, 9, 9,10,10,10,10,10,10,
  138553. };
  138554. static float _vq_quantthresh__44un1__p7_2[] = {
  138555. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  138556. 2.5, 3.5, 4.5, 5.5,
  138557. };
  138558. static long _vq_quantmap__44un1__p7_2[] = {
  138559. 11, 9, 7, 5, 3, 1, 0, 2,
  138560. 4, 6, 8, 10, 12,
  138561. };
  138562. static encode_aux_threshmatch _vq_auxt__44un1__p7_2 = {
  138563. _vq_quantthresh__44un1__p7_2,
  138564. _vq_quantmap__44un1__p7_2,
  138565. 13,
  138566. 13
  138567. };
  138568. static static_codebook _44un1__p7_2 = {
  138569. 2, 169,
  138570. _vq_lengthlist__44un1__p7_2,
  138571. 1, -531103744, 1611661312, 4, 0,
  138572. _vq_quantlist__44un1__p7_2,
  138573. NULL,
  138574. &_vq_auxt__44un1__p7_2,
  138575. NULL,
  138576. 0
  138577. };
  138578. static long _huff_lengthlist__44un1__short[] = {
  138579. 12,12,14,12,14,14,14,14,12, 6, 6, 8, 9, 9,11,14,
  138580. 12, 4, 2, 6, 6, 7,11,14,13, 6, 5, 7, 8, 9,11,14,
  138581. 13, 8, 5, 8, 6, 8,12,14,12, 7, 7, 8, 8, 8,10,14,
  138582. 12, 6, 3, 4, 4, 4, 7,14,11, 7, 4, 6, 6, 6, 8,14,
  138583. };
  138584. static static_codebook _huff_book__44un1__short = {
  138585. 2, 64,
  138586. _huff_lengthlist__44un1__short,
  138587. 0, 0, 0, 0, 0,
  138588. NULL,
  138589. NULL,
  138590. NULL,
  138591. NULL,
  138592. 0
  138593. };
  138594. /*** End of inlined file: res_books_uncoupled.h ***/
  138595. static vorbis_info_residue0 _residue_44_low_un={
  138596. 0,-1, -1, 8,-1,
  138597. {0},
  138598. {-1},
  138599. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 28.5},
  138600. { -1, 25, -1, 45, -1, -1, -1}
  138601. };
  138602. static vorbis_info_residue0 _residue_44_mid_un={
  138603. 0,-1, -1, 10,-1,
  138604. {0},
  138605. {-1},
  138606. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 4.5, 16.5, 60.5},
  138607. { -1, 30, -1, 50, -1, 80, -1, -1, -1}
  138608. };
  138609. static vorbis_info_residue0 _residue_44_hi_un={
  138610. 0,-1, -1, 10,-1,
  138611. {0},
  138612. {-1},
  138613. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  138614. { -1, -1, -1, -1, -1, -1, -1, -1, -1}
  138615. };
  138616. static vorbis_info_mapping0 _map_nominal_u[2]={
  138617. {1, {0,0}, {0}, {0}, 0,{0},{0}},
  138618. {1, {0,0}, {1}, {1}, 0,{0},{0}}
  138619. };
  138620. static static_bookblock _resbook_44u_n1={
  138621. {
  138622. {0},
  138623. {0,0,&_44un1__p1_0},
  138624. {0,0,&_44un1__p2_0},
  138625. {0,0,&_44un1__p3_0},
  138626. {0,0,&_44un1__p4_0},
  138627. {0,0,&_44un1__p5_0},
  138628. {&_44un1__p6_0,&_44un1__p6_1},
  138629. {&_44un1__p7_0,&_44un1__p7_1,&_44un1__p7_2}
  138630. }
  138631. };
  138632. static static_bookblock _resbook_44u_0={
  138633. {
  138634. {0},
  138635. {0,0,&_44u0__p1_0},
  138636. {0,0,&_44u0__p2_0},
  138637. {0,0,&_44u0__p3_0},
  138638. {0,0,&_44u0__p4_0},
  138639. {0,0,&_44u0__p5_0},
  138640. {&_44u0__p6_0,&_44u0__p6_1},
  138641. {&_44u0__p7_0,&_44u0__p7_1,&_44u0__p7_2}
  138642. }
  138643. };
  138644. static static_bookblock _resbook_44u_1={
  138645. {
  138646. {0},
  138647. {0,0,&_44u1__p1_0},
  138648. {0,0,&_44u1__p2_0},
  138649. {0,0,&_44u1__p3_0},
  138650. {0,0,&_44u1__p4_0},
  138651. {0,0,&_44u1__p5_0},
  138652. {&_44u1__p6_0,&_44u1__p6_1},
  138653. {&_44u1__p7_0,&_44u1__p7_1,&_44u1__p7_2}
  138654. }
  138655. };
  138656. static static_bookblock _resbook_44u_2={
  138657. {
  138658. {0},
  138659. {0,0,&_44u2__p1_0},
  138660. {0,0,&_44u2__p2_0},
  138661. {0,0,&_44u2__p3_0},
  138662. {0,0,&_44u2__p4_0},
  138663. {0,0,&_44u2__p5_0},
  138664. {&_44u2__p6_0,&_44u2__p6_1},
  138665. {&_44u2__p7_0,&_44u2__p7_1,&_44u2__p7_2}
  138666. }
  138667. };
  138668. static static_bookblock _resbook_44u_3={
  138669. {
  138670. {0},
  138671. {0,0,&_44u3__p1_0},
  138672. {0,0,&_44u3__p2_0},
  138673. {0,0,&_44u3__p3_0},
  138674. {0,0,&_44u3__p4_0},
  138675. {0,0,&_44u3__p5_0},
  138676. {&_44u3__p6_0,&_44u3__p6_1},
  138677. {&_44u3__p7_0,&_44u3__p7_1,&_44u3__p7_2}
  138678. }
  138679. };
  138680. static static_bookblock _resbook_44u_4={
  138681. {
  138682. {0},
  138683. {0,0,&_44u4__p1_0},
  138684. {0,0,&_44u4__p2_0},
  138685. {0,0,&_44u4__p3_0},
  138686. {0,0,&_44u4__p4_0},
  138687. {0,0,&_44u4__p5_0},
  138688. {&_44u4__p6_0,&_44u4__p6_1},
  138689. {&_44u4__p7_0,&_44u4__p7_1,&_44u4__p7_2}
  138690. }
  138691. };
  138692. static static_bookblock _resbook_44u_5={
  138693. {
  138694. {0},
  138695. {0,0,&_44u5__p1_0},
  138696. {0,0,&_44u5__p2_0},
  138697. {0,0,&_44u5__p3_0},
  138698. {0,0,&_44u5__p4_0},
  138699. {0,0,&_44u5__p5_0},
  138700. {0,0,&_44u5__p6_0},
  138701. {&_44u5__p7_0,&_44u5__p7_1},
  138702. {&_44u5__p8_0,&_44u5__p8_1},
  138703. {&_44u5__p9_0,&_44u5__p9_1,&_44u5__p9_2}
  138704. }
  138705. };
  138706. static static_bookblock _resbook_44u_6={
  138707. {
  138708. {0},
  138709. {0,0,&_44u6__p1_0},
  138710. {0,0,&_44u6__p2_0},
  138711. {0,0,&_44u6__p3_0},
  138712. {0,0,&_44u6__p4_0},
  138713. {0,0,&_44u6__p5_0},
  138714. {0,0,&_44u6__p6_0},
  138715. {&_44u6__p7_0,&_44u6__p7_1},
  138716. {&_44u6__p8_0,&_44u6__p8_1},
  138717. {&_44u6__p9_0,&_44u6__p9_1,&_44u6__p9_2}
  138718. }
  138719. };
  138720. static static_bookblock _resbook_44u_7={
  138721. {
  138722. {0},
  138723. {0,0,&_44u7__p1_0},
  138724. {0,0,&_44u7__p2_0},
  138725. {0,0,&_44u7__p3_0},
  138726. {0,0,&_44u7__p4_0},
  138727. {0,0,&_44u7__p5_0},
  138728. {0,0,&_44u7__p6_0},
  138729. {&_44u7__p7_0,&_44u7__p7_1},
  138730. {&_44u7__p8_0,&_44u7__p8_1},
  138731. {&_44u7__p9_0,&_44u7__p9_1,&_44u7__p9_2}
  138732. }
  138733. };
  138734. static static_bookblock _resbook_44u_8={
  138735. {
  138736. {0},
  138737. {0,0,&_44u8_p1_0},
  138738. {0,0,&_44u8_p2_0},
  138739. {0,0,&_44u8_p3_0},
  138740. {0,0,&_44u8_p4_0},
  138741. {&_44u8_p5_0,&_44u8_p5_1},
  138742. {&_44u8_p6_0,&_44u8_p6_1},
  138743. {&_44u8_p7_0,&_44u8_p7_1},
  138744. {&_44u8_p8_0,&_44u8_p8_1},
  138745. {&_44u8_p9_0,&_44u8_p9_1,&_44u8_p9_2}
  138746. }
  138747. };
  138748. static static_bookblock _resbook_44u_9={
  138749. {
  138750. {0},
  138751. {0,0,&_44u9_p1_0},
  138752. {0,0,&_44u9_p2_0},
  138753. {0,0,&_44u9_p3_0},
  138754. {0,0,&_44u9_p4_0},
  138755. {&_44u9_p5_0,&_44u9_p5_1},
  138756. {&_44u9_p6_0,&_44u9_p6_1},
  138757. {&_44u9_p7_0,&_44u9_p7_1},
  138758. {&_44u9_p8_0,&_44u9_p8_1},
  138759. {&_44u9_p9_0,&_44u9_p9_1,&_44u9_p9_2}
  138760. }
  138761. };
  138762. static vorbis_residue_template _res_44u_n1[]={
  138763. {1,0, &_residue_44_low_un,
  138764. &_huff_book__44un1__short,&_huff_book__44un1__short,
  138765. &_resbook_44u_n1,&_resbook_44u_n1},
  138766. {1,0, &_residue_44_low_un,
  138767. &_huff_book__44un1__long,&_huff_book__44un1__long,
  138768. &_resbook_44u_n1,&_resbook_44u_n1}
  138769. };
  138770. static vorbis_residue_template _res_44u_0[]={
  138771. {1,0, &_residue_44_low_un,
  138772. &_huff_book__44u0__short,&_huff_book__44u0__short,
  138773. &_resbook_44u_0,&_resbook_44u_0},
  138774. {1,0, &_residue_44_low_un,
  138775. &_huff_book__44u0__long,&_huff_book__44u0__long,
  138776. &_resbook_44u_0,&_resbook_44u_0}
  138777. };
  138778. static vorbis_residue_template _res_44u_1[]={
  138779. {1,0, &_residue_44_low_un,
  138780. &_huff_book__44u1__short,&_huff_book__44u1__short,
  138781. &_resbook_44u_1,&_resbook_44u_1},
  138782. {1,0, &_residue_44_low_un,
  138783. &_huff_book__44u1__long,&_huff_book__44u1__long,
  138784. &_resbook_44u_1,&_resbook_44u_1}
  138785. };
  138786. static vorbis_residue_template _res_44u_2[]={
  138787. {1,0, &_residue_44_low_un,
  138788. &_huff_book__44u2__short,&_huff_book__44u2__short,
  138789. &_resbook_44u_2,&_resbook_44u_2},
  138790. {1,0, &_residue_44_low_un,
  138791. &_huff_book__44u2__long,&_huff_book__44u2__long,
  138792. &_resbook_44u_2,&_resbook_44u_2}
  138793. };
  138794. static vorbis_residue_template _res_44u_3[]={
  138795. {1,0, &_residue_44_low_un,
  138796. &_huff_book__44u3__short,&_huff_book__44u3__short,
  138797. &_resbook_44u_3,&_resbook_44u_3},
  138798. {1,0, &_residue_44_low_un,
  138799. &_huff_book__44u3__long,&_huff_book__44u3__long,
  138800. &_resbook_44u_3,&_resbook_44u_3}
  138801. };
  138802. static vorbis_residue_template _res_44u_4[]={
  138803. {1,0, &_residue_44_low_un,
  138804. &_huff_book__44u4__short,&_huff_book__44u4__short,
  138805. &_resbook_44u_4,&_resbook_44u_4},
  138806. {1,0, &_residue_44_low_un,
  138807. &_huff_book__44u4__long,&_huff_book__44u4__long,
  138808. &_resbook_44u_4,&_resbook_44u_4}
  138809. };
  138810. static vorbis_residue_template _res_44u_5[]={
  138811. {1,0, &_residue_44_mid_un,
  138812. &_huff_book__44u5__short,&_huff_book__44u5__short,
  138813. &_resbook_44u_5,&_resbook_44u_5},
  138814. {1,0, &_residue_44_mid_un,
  138815. &_huff_book__44u5__long,&_huff_book__44u5__long,
  138816. &_resbook_44u_5,&_resbook_44u_5}
  138817. };
  138818. static vorbis_residue_template _res_44u_6[]={
  138819. {1,0, &_residue_44_mid_un,
  138820. &_huff_book__44u6__short,&_huff_book__44u6__short,
  138821. &_resbook_44u_6,&_resbook_44u_6},
  138822. {1,0, &_residue_44_mid_un,
  138823. &_huff_book__44u6__long,&_huff_book__44u6__long,
  138824. &_resbook_44u_6,&_resbook_44u_6}
  138825. };
  138826. static vorbis_residue_template _res_44u_7[]={
  138827. {1,0, &_residue_44_mid_un,
  138828. &_huff_book__44u7__short,&_huff_book__44u7__short,
  138829. &_resbook_44u_7,&_resbook_44u_7},
  138830. {1,0, &_residue_44_mid_un,
  138831. &_huff_book__44u7__long,&_huff_book__44u7__long,
  138832. &_resbook_44u_7,&_resbook_44u_7}
  138833. };
  138834. static vorbis_residue_template _res_44u_8[]={
  138835. {1,0, &_residue_44_hi_un,
  138836. &_huff_book__44u8__short,&_huff_book__44u8__short,
  138837. &_resbook_44u_8,&_resbook_44u_8},
  138838. {1,0, &_residue_44_hi_un,
  138839. &_huff_book__44u8__long,&_huff_book__44u8__long,
  138840. &_resbook_44u_8,&_resbook_44u_8}
  138841. };
  138842. static vorbis_residue_template _res_44u_9[]={
  138843. {1,0, &_residue_44_hi_un,
  138844. &_huff_book__44u9__short,&_huff_book__44u9__short,
  138845. &_resbook_44u_9,&_resbook_44u_9},
  138846. {1,0, &_residue_44_hi_un,
  138847. &_huff_book__44u9__long,&_huff_book__44u9__long,
  138848. &_resbook_44u_9,&_resbook_44u_9}
  138849. };
  138850. static vorbis_mapping_template _mapres_template_44_uncoupled[]={
  138851. { _map_nominal_u, _res_44u_n1 }, /* -1 */
  138852. { _map_nominal_u, _res_44u_0 }, /* 0 */
  138853. { _map_nominal_u, _res_44u_1 }, /* 1 */
  138854. { _map_nominal_u, _res_44u_2 }, /* 2 */
  138855. { _map_nominal_u, _res_44u_3 }, /* 3 */
  138856. { _map_nominal_u, _res_44u_4 }, /* 4 */
  138857. { _map_nominal_u, _res_44u_5 }, /* 5 */
  138858. { _map_nominal_u, _res_44u_6 }, /* 6 */
  138859. { _map_nominal_u, _res_44u_7 }, /* 7 */
  138860. { _map_nominal_u, _res_44u_8 }, /* 8 */
  138861. { _map_nominal_u, _res_44u_9 }, /* 9 */
  138862. };
  138863. /*** End of inlined file: residue_44u.h ***/
  138864. static double rate_mapping_44_un[12]={
  138865. 32000.,48000.,60000.,70000.,80000.,86000.,
  138866. 96000.,110000.,120000.,140000.,160000.,240001.
  138867. };
  138868. ve_setup_data_template ve_setup_44_uncoupled={
  138869. 11,
  138870. rate_mapping_44_un,
  138871. quality_mapping_44,
  138872. -1,
  138873. 40000,
  138874. 50000,
  138875. blocksize_short_44,
  138876. blocksize_long_44,
  138877. _psy_tone_masteratt_44,
  138878. _psy_tone_0dB,
  138879. _psy_tone_suppress,
  138880. _vp_tonemask_adj_otherblock,
  138881. _vp_tonemask_adj_longblock,
  138882. _vp_tonemask_adj_otherblock,
  138883. _psy_noiseguards_44,
  138884. _psy_noisebias_impulse,
  138885. _psy_noisebias_padding,
  138886. _psy_noisebias_trans,
  138887. _psy_noisebias_long,
  138888. _psy_noise_suppress,
  138889. _psy_compand_44,
  138890. _psy_compand_short_mapping,
  138891. _psy_compand_long_mapping,
  138892. {_noise_start_short_44,_noise_start_long_44},
  138893. {_noise_part_short_44,_noise_part_long_44},
  138894. _noise_thresh_44,
  138895. _psy_ath_floater,
  138896. _psy_ath_abs,
  138897. _psy_lowpass_44,
  138898. _psy_global_44,
  138899. _global_mapping_44,
  138900. NULL,
  138901. _floor_books,
  138902. _floor,
  138903. _floor_short_mapping_44,
  138904. _floor_long_mapping_44,
  138905. _mapres_template_44_uncoupled
  138906. };
  138907. /*** End of inlined file: setup_44u.h ***/
  138908. /*** Start of inlined file: setup_32.h ***/
  138909. static double rate_mapping_32[12]={
  138910. 18000.,28000.,35000.,45000.,56000.,60000.,
  138911. 75000.,90000.,100000.,115000.,150000.,190000.,
  138912. };
  138913. static double rate_mapping_32_un[12]={
  138914. 30000.,42000.,52000.,64000.,72000.,78000.,
  138915. 86000.,92000.,110000.,120000.,140000.,190000.,
  138916. };
  138917. static double _psy_lowpass_32[12]={
  138918. 12.3,13.,13.,14.,15.,99.,99.,99.,99.,99.,99.,99.
  138919. };
  138920. ve_setup_data_template ve_setup_32_stereo={
  138921. 11,
  138922. rate_mapping_32,
  138923. quality_mapping_44,
  138924. 2,
  138925. 26000,
  138926. 40000,
  138927. blocksize_short_44,
  138928. blocksize_long_44,
  138929. _psy_tone_masteratt_44,
  138930. _psy_tone_0dB,
  138931. _psy_tone_suppress,
  138932. _vp_tonemask_adj_otherblock,
  138933. _vp_tonemask_adj_longblock,
  138934. _vp_tonemask_adj_otherblock,
  138935. _psy_noiseguards_44,
  138936. _psy_noisebias_impulse,
  138937. _psy_noisebias_padding,
  138938. _psy_noisebias_trans,
  138939. _psy_noisebias_long,
  138940. _psy_noise_suppress,
  138941. _psy_compand_44,
  138942. _psy_compand_short_mapping,
  138943. _psy_compand_long_mapping,
  138944. {_noise_start_short_44,_noise_start_long_44},
  138945. {_noise_part_short_44,_noise_part_long_44},
  138946. _noise_thresh_44,
  138947. _psy_ath_floater,
  138948. _psy_ath_abs,
  138949. _psy_lowpass_32,
  138950. _psy_global_44,
  138951. _global_mapping_44,
  138952. _psy_stereo_modes_44,
  138953. _floor_books,
  138954. _floor,
  138955. _floor_short_mapping_44,
  138956. _floor_long_mapping_44,
  138957. _mapres_template_44_stereo
  138958. };
  138959. ve_setup_data_template ve_setup_32_uncoupled={
  138960. 11,
  138961. rate_mapping_32_un,
  138962. quality_mapping_44,
  138963. -1,
  138964. 26000,
  138965. 40000,
  138966. blocksize_short_44,
  138967. blocksize_long_44,
  138968. _psy_tone_masteratt_44,
  138969. _psy_tone_0dB,
  138970. _psy_tone_suppress,
  138971. _vp_tonemask_adj_otherblock,
  138972. _vp_tonemask_adj_longblock,
  138973. _vp_tonemask_adj_otherblock,
  138974. _psy_noiseguards_44,
  138975. _psy_noisebias_impulse,
  138976. _psy_noisebias_padding,
  138977. _psy_noisebias_trans,
  138978. _psy_noisebias_long,
  138979. _psy_noise_suppress,
  138980. _psy_compand_44,
  138981. _psy_compand_short_mapping,
  138982. _psy_compand_long_mapping,
  138983. {_noise_start_short_44,_noise_start_long_44},
  138984. {_noise_part_short_44,_noise_part_long_44},
  138985. _noise_thresh_44,
  138986. _psy_ath_floater,
  138987. _psy_ath_abs,
  138988. _psy_lowpass_32,
  138989. _psy_global_44,
  138990. _global_mapping_44,
  138991. NULL,
  138992. _floor_books,
  138993. _floor,
  138994. _floor_short_mapping_44,
  138995. _floor_long_mapping_44,
  138996. _mapres_template_44_uncoupled
  138997. };
  138998. /*** End of inlined file: setup_32.h ***/
  138999. /*** Start of inlined file: setup_8.h ***/
  139000. /*** Start of inlined file: psych_8.h ***/
  139001. static att3 _psy_tone_masteratt_8[3]={
  139002. {{ 32, 25, 12}, 0, 0}, /* 0 */
  139003. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139004. {{ 20, 0, -14}, 0, 0}, /* 0 */
  139005. };
  139006. static vp_adjblock _vp_tonemask_adj_8[3]={
  139007. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  139008. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  139009. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 1 */
  139010. };
  139011. static noise3 _psy_noisebias_8[3]={
  139012. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  139013. {-10,-10,-10,-10, -5, -5, -5, 0, 0, 4, 4, 4, 4, 4, 99, 99, 99},
  139014. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139015. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  139016. {-10,-10,-10,-10,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139017. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139018. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139019. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139020. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139021. };
  139022. static adj_stereo _psy_stereo_modes_8[3]={
  139023. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139024. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139025. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139026. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139027. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139028. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139029. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139030. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139031. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139032. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139033. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139034. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139035. };
  139036. static noiseguard _psy_noiseguards_8[2]={
  139037. {10,10,-1},
  139038. {10,10,-1},
  139039. };
  139040. static compandblock _psy_compand_8[2]={
  139041. {{
  139042. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  139043. 8, 8, 9, 9,10,10,11, 11, /* 15dB */
  139044. 12,12,13,13,14,14,15, 15, /* 23dB */
  139045. 16,16,17,17,17,18,18, 19, /* 31dB */
  139046. 19,19,20,21,22,23,24, 25, /* 39dB */
  139047. }},
  139048. {{
  139049. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  139050. 7, 7, 6, 6, 5, 5, 4, 4, /* 15dB */
  139051. 3, 3, 3, 4, 5, 6, 7, 8, /* 23dB */
  139052. 9,10,11,12,13,14,15, 16, /* 31dB */
  139053. 17,18,19,20,21,22,23, 24, /* 39dB */
  139054. }},
  139055. };
  139056. static double _psy_lowpass_8[3]={3.,4.,4.};
  139057. static int _noise_start_8[2]={
  139058. 64,64,
  139059. };
  139060. static int _noise_part_8[2]={
  139061. 8,8,
  139062. };
  139063. static int _psy_ath_floater_8[3]={
  139064. -100,-100,-105,
  139065. };
  139066. static int _psy_ath_abs_8[3]={
  139067. -130,-130,-140,
  139068. };
  139069. /*** End of inlined file: psych_8.h ***/
  139070. /*** Start of inlined file: residue_8.h ***/
  139071. static static_bookblock _resbook_8s_0={
  139072. {
  139073. {0},{0,0,&_8c0_s_p1_0},{0,0,&_8c0_s_p2_0},{0,0,&_8c0_s_p3_0},
  139074. {0,0,&_8c0_s_p4_0},{0,0,&_8c0_s_p5_0},{0,0,&_8c0_s_p6_0},
  139075. {&_8c0_s_p7_0,&_8c0_s_p7_1},{&_8c0_s_p8_0,&_8c0_s_p8_1},
  139076. {&_8c0_s_p9_0,&_8c0_s_p9_1,&_8c0_s_p9_2}
  139077. }
  139078. };
  139079. static static_bookblock _resbook_8s_1={
  139080. {
  139081. {0},{0,0,&_8c1_s_p1_0},{0,0,&_8c1_s_p2_0},{0,0,&_8c1_s_p3_0},
  139082. {0,0,&_8c1_s_p4_0},{0,0,&_8c1_s_p5_0},{0,0,&_8c1_s_p6_0},
  139083. {&_8c1_s_p7_0,&_8c1_s_p7_1},{&_8c1_s_p8_0,&_8c1_s_p8_1},
  139084. {&_8c1_s_p9_0,&_8c1_s_p9_1,&_8c1_s_p9_2}
  139085. }
  139086. };
  139087. static vorbis_residue_template _res_8s_0[]={
  139088. {2,0, &_residue_44_mid,
  139089. &_huff_book__8c0_s_single,&_huff_book__8c0_s_single,
  139090. &_resbook_8s_0,&_resbook_8s_0},
  139091. };
  139092. static vorbis_residue_template _res_8s_1[]={
  139093. {2,0, &_residue_44_mid,
  139094. &_huff_book__8c1_s_single,&_huff_book__8c1_s_single,
  139095. &_resbook_8s_1,&_resbook_8s_1},
  139096. };
  139097. static vorbis_mapping_template _mapres_template_8_stereo[2]={
  139098. { _map_nominal, _res_8s_0 }, /* 0 */
  139099. { _map_nominal, _res_8s_1 }, /* 1 */
  139100. };
  139101. static static_bookblock _resbook_8u_0={
  139102. {
  139103. {0},
  139104. {0,0,&_8u0__p1_0},
  139105. {0,0,&_8u0__p2_0},
  139106. {0,0,&_8u0__p3_0},
  139107. {0,0,&_8u0__p4_0},
  139108. {0,0,&_8u0__p5_0},
  139109. {&_8u0__p6_0,&_8u0__p6_1},
  139110. {&_8u0__p7_0,&_8u0__p7_1,&_8u0__p7_2}
  139111. }
  139112. };
  139113. static static_bookblock _resbook_8u_1={
  139114. {
  139115. {0},
  139116. {0,0,&_8u1__p1_0},
  139117. {0,0,&_8u1__p2_0},
  139118. {0,0,&_8u1__p3_0},
  139119. {0,0,&_8u1__p4_0},
  139120. {0,0,&_8u1__p5_0},
  139121. {0,0,&_8u1__p6_0},
  139122. {&_8u1__p7_0,&_8u1__p7_1},
  139123. {&_8u1__p8_0,&_8u1__p8_1},
  139124. {&_8u1__p9_0,&_8u1__p9_1,&_8u1__p9_2}
  139125. }
  139126. };
  139127. static vorbis_residue_template _res_8u_0[]={
  139128. {1,0, &_residue_44_low_un,
  139129. &_huff_book__8u0__single,&_huff_book__8u0__single,
  139130. &_resbook_8u_0,&_resbook_8u_0},
  139131. };
  139132. static vorbis_residue_template _res_8u_1[]={
  139133. {1,0, &_residue_44_mid_un,
  139134. &_huff_book__8u1__single,&_huff_book__8u1__single,
  139135. &_resbook_8u_1,&_resbook_8u_1},
  139136. };
  139137. static vorbis_mapping_template _mapres_template_8_uncoupled[2]={
  139138. { _map_nominal_u, _res_8u_0 }, /* 0 */
  139139. { _map_nominal_u, _res_8u_1 }, /* 1 */
  139140. };
  139141. /*** End of inlined file: residue_8.h ***/
  139142. static int blocksize_8[2]={
  139143. 512,512
  139144. };
  139145. static int _floor_mapping_8[2]={
  139146. 6,6,
  139147. };
  139148. static double rate_mapping_8[3]={
  139149. 6000.,9000.,32000.,
  139150. };
  139151. static double rate_mapping_8_uncoupled[3]={
  139152. 8000.,14000.,42000.,
  139153. };
  139154. static double quality_mapping_8[3]={
  139155. -.1,.0,1.
  139156. };
  139157. static double _psy_compand_8_mapping[3]={ 0., 1., 1.};
  139158. static double _global_mapping_8[3]={ 1., 2., 3. };
  139159. ve_setup_data_template ve_setup_8_stereo={
  139160. 2,
  139161. rate_mapping_8,
  139162. quality_mapping_8,
  139163. 2,
  139164. 8000,
  139165. 9000,
  139166. blocksize_8,
  139167. blocksize_8,
  139168. _psy_tone_masteratt_8,
  139169. _psy_tone_0dB,
  139170. _psy_tone_suppress,
  139171. _vp_tonemask_adj_8,
  139172. NULL,
  139173. _vp_tonemask_adj_8,
  139174. _psy_noiseguards_8,
  139175. _psy_noisebias_8,
  139176. _psy_noisebias_8,
  139177. NULL,
  139178. NULL,
  139179. _psy_noise_suppress,
  139180. _psy_compand_8,
  139181. _psy_compand_8_mapping,
  139182. NULL,
  139183. {_noise_start_8,_noise_start_8},
  139184. {_noise_part_8,_noise_part_8},
  139185. _noise_thresh_5only,
  139186. _psy_ath_floater_8,
  139187. _psy_ath_abs_8,
  139188. _psy_lowpass_8,
  139189. _psy_global_44,
  139190. _global_mapping_8,
  139191. _psy_stereo_modes_8,
  139192. _floor_books,
  139193. _floor,
  139194. _floor_mapping_8,
  139195. NULL,
  139196. _mapres_template_8_stereo
  139197. };
  139198. ve_setup_data_template ve_setup_8_uncoupled={
  139199. 2,
  139200. rate_mapping_8_uncoupled,
  139201. quality_mapping_8,
  139202. -1,
  139203. 8000,
  139204. 9000,
  139205. blocksize_8,
  139206. blocksize_8,
  139207. _psy_tone_masteratt_8,
  139208. _psy_tone_0dB,
  139209. _psy_tone_suppress,
  139210. _vp_tonemask_adj_8,
  139211. NULL,
  139212. _vp_tonemask_adj_8,
  139213. _psy_noiseguards_8,
  139214. _psy_noisebias_8,
  139215. _psy_noisebias_8,
  139216. NULL,
  139217. NULL,
  139218. _psy_noise_suppress,
  139219. _psy_compand_8,
  139220. _psy_compand_8_mapping,
  139221. NULL,
  139222. {_noise_start_8,_noise_start_8},
  139223. {_noise_part_8,_noise_part_8},
  139224. _noise_thresh_5only,
  139225. _psy_ath_floater_8,
  139226. _psy_ath_abs_8,
  139227. _psy_lowpass_8,
  139228. _psy_global_44,
  139229. _global_mapping_8,
  139230. _psy_stereo_modes_8,
  139231. _floor_books,
  139232. _floor,
  139233. _floor_mapping_8,
  139234. NULL,
  139235. _mapres_template_8_uncoupled
  139236. };
  139237. /*** End of inlined file: setup_8.h ***/
  139238. /*** Start of inlined file: setup_11.h ***/
  139239. /*** Start of inlined file: psych_11.h ***/
  139240. static double _psy_lowpass_11[3]={4.5,5.5,30.,};
  139241. static att3 _psy_tone_masteratt_11[3]={
  139242. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139243. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139244. {{ 20, 0, -14}, 0, 0}, /* 0 */
  139245. };
  139246. static vp_adjblock _vp_tonemask_adj_11[3]={
  139247. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 2, 0,99,99,99}}, /* 0 */
  139248. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 5, 0, 0,99,99,99}}, /* 1 */
  139249. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 2 */
  139250. };
  139251. static noise3 _psy_noisebias_11[3]={
  139252. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139253. {-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 4, 5, 5, 10, 99, 99, 99},
  139254. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139255. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139256. {-15,-15,-15,-15,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139257. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139258. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139259. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139260. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139261. };
  139262. static double _noise_thresh_11[3]={ .3,.5,.5 };
  139263. /*** End of inlined file: psych_11.h ***/
  139264. static int blocksize_11[2]={
  139265. 512,512
  139266. };
  139267. static int _floor_mapping_11[2]={
  139268. 6,6,
  139269. };
  139270. static double rate_mapping_11[3]={
  139271. 8000.,13000.,44000.,
  139272. };
  139273. static double rate_mapping_11_uncoupled[3]={
  139274. 12000.,20000.,50000.,
  139275. };
  139276. static double quality_mapping_11[3]={
  139277. -.1,.0,1.
  139278. };
  139279. ve_setup_data_template ve_setup_11_stereo={
  139280. 2,
  139281. rate_mapping_11,
  139282. quality_mapping_11,
  139283. 2,
  139284. 9000,
  139285. 15000,
  139286. blocksize_11,
  139287. blocksize_11,
  139288. _psy_tone_masteratt_11,
  139289. _psy_tone_0dB,
  139290. _psy_tone_suppress,
  139291. _vp_tonemask_adj_11,
  139292. NULL,
  139293. _vp_tonemask_adj_11,
  139294. _psy_noiseguards_8,
  139295. _psy_noisebias_11,
  139296. _psy_noisebias_11,
  139297. NULL,
  139298. NULL,
  139299. _psy_noise_suppress,
  139300. _psy_compand_8,
  139301. _psy_compand_8_mapping,
  139302. NULL,
  139303. {_noise_start_8,_noise_start_8},
  139304. {_noise_part_8,_noise_part_8},
  139305. _noise_thresh_11,
  139306. _psy_ath_floater_8,
  139307. _psy_ath_abs_8,
  139308. _psy_lowpass_11,
  139309. _psy_global_44,
  139310. _global_mapping_8,
  139311. _psy_stereo_modes_8,
  139312. _floor_books,
  139313. _floor,
  139314. _floor_mapping_11,
  139315. NULL,
  139316. _mapres_template_8_stereo
  139317. };
  139318. ve_setup_data_template ve_setup_11_uncoupled={
  139319. 2,
  139320. rate_mapping_11_uncoupled,
  139321. quality_mapping_11,
  139322. -1,
  139323. 9000,
  139324. 15000,
  139325. blocksize_11,
  139326. blocksize_11,
  139327. _psy_tone_masteratt_11,
  139328. _psy_tone_0dB,
  139329. _psy_tone_suppress,
  139330. _vp_tonemask_adj_11,
  139331. NULL,
  139332. _vp_tonemask_adj_11,
  139333. _psy_noiseguards_8,
  139334. _psy_noisebias_11,
  139335. _psy_noisebias_11,
  139336. NULL,
  139337. NULL,
  139338. _psy_noise_suppress,
  139339. _psy_compand_8,
  139340. _psy_compand_8_mapping,
  139341. NULL,
  139342. {_noise_start_8,_noise_start_8},
  139343. {_noise_part_8,_noise_part_8},
  139344. _noise_thresh_11,
  139345. _psy_ath_floater_8,
  139346. _psy_ath_abs_8,
  139347. _psy_lowpass_11,
  139348. _psy_global_44,
  139349. _global_mapping_8,
  139350. _psy_stereo_modes_8,
  139351. _floor_books,
  139352. _floor,
  139353. _floor_mapping_11,
  139354. NULL,
  139355. _mapres_template_8_uncoupled
  139356. };
  139357. /*** End of inlined file: setup_11.h ***/
  139358. /*** Start of inlined file: setup_16.h ***/
  139359. /*** Start of inlined file: psych_16.h ***/
  139360. static adj_stereo _psy_stereo_modes_16[4]={
  139361. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139362. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139363. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 4, 4},
  139364. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139365. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139366. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139367. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4},
  139368. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139369. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139370. { 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139371. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139372. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139373. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139374. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139375. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
  139376. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139377. };
  139378. static double _psy_lowpass_16[4]={6.5,8,30.,99.};
  139379. static att3 _psy_tone_masteratt_16[4]={
  139380. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139381. {{ 25, 22, 12}, 0, 0}, /* 0 */
  139382. {{ 20, 12, 0}, 0, 0}, /* 0 */
  139383. {{ 15, 0, -14}, 0, 0}, /* 0 */
  139384. };
  139385. static vp_adjblock _vp_tonemask_adj_16[4]={
  139386. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 0 */
  139387. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 1 */
  139388. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139389. {{-30,-30,-30,-30,-30,-26,-20,-10, -5, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139390. };
  139391. static noise3 _psy_noisebias_16_short[4]={
  139392. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139393. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139394. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139395. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139396. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 4, 5, 6, 8, 8, 15},
  139397. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139398. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139399. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10, -8, 0, 0, 0, 0, 2, 5},
  139400. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139401. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139402. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139403. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139404. };
  139405. static noise3 _psy_noisebias_16_impulse[4]={
  139406. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139407. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139408. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139409. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 4, 4, 4, 5, 5, 6, 8, 15},
  139410. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 0, 0, 0, 0, 4, 10},
  139411. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139412. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 0, 0, 0, 0, 0, 0, 4, 10},
  139413. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10,-10,-10,-10,-10,-10, -7, -5},
  139414. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139415. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139416. {-30,-30,-30,-30,-26,-22,-20,-18,-18,-18,-20,-20,-20,-20,-20,-20,-16},
  139417. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139418. };
  139419. static noise3 _psy_noisebias_16[4]={
  139420. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 8, 8, 10, 10, 10, 14, 20},
  139421. {-10,-10,-10,-10,-10, -5, -2, -2, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139422. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139423. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139424. {-15,-15,-15,-15,-15,-10, -5, -5, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139425. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139426. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139427. {-20,-20,-20,-20,-16,-12,-20,-10, -5, -5, 0, 0, 0, 0, 0, 2, 5},
  139428. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139429. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139430. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139431. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139432. };
  139433. static double _noise_thresh_16[4]={ .3,.5,.5,.5 };
  139434. static int _noise_start_16[3]={ 256,256,9999 };
  139435. static int _noise_part_16[4]={ 8,8,8,8 };
  139436. static int _psy_ath_floater_16[4]={
  139437. -100,-100,-100,-105,
  139438. };
  139439. static int _psy_ath_abs_16[4]={
  139440. -130,-130,-130,-140,
  139441. };
  139442. /*** End of inlined file: psych_16.h ***/
  139443. /*** Start of inlined file: residue_16.h ***/
  139444. static static_bookblock _resbook_16s_0={
  139445. {
  139446. {0},
  139447. {0,0,&_16c0_s_p1_0},
  139448. {0,0,&_16c0_s_p2_0},
  139449. {0,0,&_16c0_s_p3_0},
  139450. {0,0,&_16c0_s_p4_0},
  139451. {0,0,&_16c0_s_p5_0},
  139452. {0,0,&_16c0_s_p6_0},
  139453. {&_16c0_s_p7_0,&_16c0_s_p7_1},
  139454. {&_16c0_s_p8_0,&_16c0_s_p8_1},
  139455. {&_16c0_s_p9_0,&_16c0_s_p9_1,&_16c0_s_p9_2}
  139456. }
  139457. };
  139458. static static_bookblock _resbook_16s_1={
  139459. {
  139460. {0},
  139461. {0,0,&_16c1_s_p1_0},
  139462. {0,0,&_16c1_s_p2_0},
  139463. {0,0,&_16c1_s_p3_0},
  139464. {0,0,&_16c1_s_p4_0},
  139465. {0,0,&_16c1_s_p5_0},
  139466. {0,0,&_16c1_s_p6_0},
  139467. {&_16c1_s_p7_0,&_16c1_s_p7_1},
  139468. {&_16c1_s_p8_0,&_16c1_s_p8_1},
  139469. {&_16c1_s_p9_0,&_16c1_s_p9_1,&_16c1_s_p9_2}
  139470. }
  139471. };
  139472. static static_bookblock _resbook_16s_2={
  139473. {
  139474. {0},
  139475. {0,0,&_16c2_s_p1_0},
  139476. {0,0,&_16c2_s_p2_0},
  139477. {0,0,&_16c2_s_p3_0},
  139478. {0,0,&_16c2_s_p4_0},
  139479. {&_16c2_s_p5_0,&_16c2_s_p5_1},
  139480. {&_16c2_s_p6_0,&_16c2_s_p6_1},
  139481. {&_16c2_s_p7_0,&_16c2_s_p7_1},
  139482. {&_16c2_s_p8_0,&_16c2_s_p8_1},
  139483. {&_16c2_s_p9_0,&_16c2_s_p9_1,&_16c2_s_p9_2}
  139484. }
  139485. };
  139486. static vorbis_residue_template _res_16s_0[]={
  139487. {2,0, &_residue_44_mid,
  139488. &_huff_book__16c0_s_single,&_huff_book__16c0_s_single,
  139489. &_resbook_16s_0,&_resbook_16s_0},
  139490. };
  139491. static vorbis_residue_template _res_16s_1[]={
  139492. {2,0, &_residue_44_mid,
  139493. &_huff_book__16c1_s_short,&_huff_book__16c1_s_short,
  139494. &_resbook_16s_1,&_resbook_16s_1},
  139495. {2,0, &_residue_44_mid,
  139496. &_huff_book__16c1_s_long,&_huff_book__16c1_s_long,
  139497. &_resbook_16s_1,&_resbook_16s_1}
  139498. };
  139499. static vorbis_residue_template _res_16s_2[]={
  139500. {2,0, &_residue_44_high,
  139501. &_huff_book__16c2_s_short,&_huff_book__16c2_s_short,
  139502. &_resbook_16s_2,&_resbook_16s_2},
  139503. {2,0, &_residue_44_high,
  139504. &_huff_book__16c2_s_long,&_huff_book__16c2_s_long,
  139505. &_resbook_16s_2,&_resbook_16s_2}
  139506. };
  139507. static vorbis_mapping_template _mapres_template_16_stereo[3]={
  139508. { _map_nominal, _res_16s_0 }, /* 0 */
  139509. { _map_nominal, _res_16s_1 }, /* 1 */
  139510. { _map_nominal, _res_16s_2 }, /* 2 */
  139511. };
  139512. static static_bookblock _resbook_16u_0={
  139513. {
  139514. {0},
  139515. {0,0,&_16u0__p1_0},
  139516. {0,0,&_16u0__p2_0},
  139517. {0,0,&_16u0__p3_0},
  139518. {0,0,&_16u0__p4_0},
  139519. {0,0,&_16u0__p5_0},
  139520. {&_16u0__p6_0,&_16u0__p6_1},
  139521. {&_16u0__p7_0,&_16u0__p7_1,&_16u0__p7_2}
  139522. }
  139523. };
  139524. static static_bookblock _resbook_16u_1={
  139525. {
  139526. {0},
  139527. {0,0,&_16u1__p1_0},
  139528. {0,0,&_16u1__p2_0},
  139529. {0,0,&_16u1__p3_0},
  139530. {0,0,&_16u1__p4_0},
  139531. {0,0,&_16u1__p5_0},
  139532. {0,0,&_16u1__p6_0},
  139533. {&_16u1__p7_0,&_16u1__p7_1},
  139534. {&_16u1__p8_0,&_16u1__p8_1},
  139535. {&_16u1__p9_0,&_16u1__p9_1,&_16u1__p9_2}
  139536. }
  139537. };
  139538. static static_bookblock _resbook_16u_2={
  139539. {
  139540. {0},
  139541. {0,0,&_16u2_p1_0},
  139542. {0,0,&_16u2_p2_0},
  139543. {0,0,&_16u2_p3_0},
  139544. {0,0,&_16u2_p4_0},
  139545. {&_16u2_p5_0,&_16u2_p5_1},
  139546. {&_16u2_p6_0,&_16u2_p6_1},
  139547. {&_16u2_p7_0,&_16u2_p7_1},
  139548. {&_16u2_p8_0,&_16u2_p8_1},
  139549. {&_16u2_p9_0,&_16u2_p9_1,&_16u2_p9_2}
  139550. }
  139551. };
  139552. static vorbis_residue_template _res_16u_0[]={
  139553. {1,0, &_residue_44_low_un,
  139554. &_huff_book__16u0__single,&_huff_book__16u0__single,
  139555. &_resbook_16u_0,&_resbook_16u_0},
  139556. };
  139557. static vorbis_residue_template _res_16u_1[]={
  139558. {1,0, &_residue_44_mid_un,
  139559. &_huff_book__16u1__short,&_huff_book__16u1__short,
  139560. &_resbook_16u_1,&_resbook_16u_1},
  139561. {1,0, &_residue_44_mid_un,
  139562. &_huff_book__16u1__long,&_huff_book__16u1__long,
  139563. &_resbook_16u_1,&_resbook_16u_1}
  139564. };
  139565. static vorbis_residue_template _res_16u_2[]={
  139566. {1,0, &_residue_44_hi_un,
  139567. &_huff_book__16u2__short,&_huff_book__16u2__short,
  139568. &_resbook_16u_2,&_resbook_16u_2},
  139569. {1,0, &_residue_44_hi_un,
  139570. &_huff_book__16u2__long,&_huff_book__16u2__long,
  139571. &_resbook_16u_2,&_resbook_16u_2}
  139572. };
  139573. static vorbis_mapping_template _mapres_template_16_uncoupled[3]={
  139574. { _map_nominal_u, _res_16u_0 }, /* 0 */
  139575. { _map_nominal_u, _res_16u_1 }, /* 1 */
  139576. { _map_nominal_u, _res_16u_2 }, /* 2 */
  139577. };
  139578. /*** End of inlined file: residue_16.h ***/
  139579. static int blocksize_16_short[3]={
  139580. 1024,512,512
  139581. };
  139582. static int blocksize_16_long[3]={
  139583. 1024,1024,1024
  139584. };
  139585. static int _floor_mapping_16_short[3]={
  139586. 9,3,3
  139587. };
  139588. static int _floor_mapping_16[3]={
  139589. 9,9,9
  139590. };
  139591. static double rate_mapping_16[4]={
  139592. 12000.,20000.,44000.,86000.
  139593. };
  139594. static double rate_mapping_16_uncoupled[4]={
  139595. 16000.,28000.,64000.,100000.
  139596. };
  139597. static double _global_mapping_16[4]={ 1., 2., 3., 4. };
  139598. static double quality_mapping_16[4]={ -.1,.05,.5,1. };
  139599. static double _psy_compand_16_mapping[4]={ 0., .8, 1., 1.};
  139600. ve_setup_data_template ve_setup_16_stereo={
  139601. 3,
  139602. rate_mapping_16,
  139603. quality_mapping_16,
  139604. 2,
  139605. 15000,
  139606. 19000,
  139607. blocksize_16_short,
  139608. blocksize_16_long,
  139609. _psy_tone_masteratt_16,
  139610. _psy_tone_0dB,
  139611. _psy_tone_suppress,
  139612. _vp_tonemask_adj_16,
  139613. _vp_tonemask_adj_16,
  139614. _vp_tonemask_adj_16,
  139615. _psy_noiseguards_8,
  139616. _psy_noisebias_16_impulse,
  139617. _psy_noisebias_16_short,
  139618. _psy_noisebias_16_short,
  139619. _psy_noisebias_16,
  139620. _psy_noise_suppress,
  139621. _psy_compand_8,
  139622. _psy_compand_16_mapping,
  139623. _psy_compand_16_mapping,
  139624. {_noise_start_16,_noise_start_16},
  139625. { _noise_part_16, _noise_part_16},
  139626. _noise_thresh_16,
  139627. _psy_ath_floater_16,
  139628. _psy_ath_abs_16,
  139629. _psy_lowpass_16,
  139630. _psy_global_44,
  139631. _global_mapping_16,
  139632. _psy_stereo_modes_16,
  139633. _floor_books,
  139634. _floor,
  139635. _floor_mapping_16_short,
  139636. _floor_mapping_16,
  139637. _mapres_template_16_stereo
  139638. };
  139639. ve_setup_data_template ve_setup_16_uncoupled={
  139640. 3,
  139641. rate_mapping_16_uncoupled,
  139642. quality_mapping_16,
  139643. -1,
  139644. 15000,
  139645. 19000,
  139646. blocksize_16_short,
  139647. blocksize_16_long,
  139648. _psy_tone_masteratt_16,
  139649. _psy_tone_0dB,
  139650. _psy_tone_suppress,
  139651. _vp_tonemask_adj_16,
  139652. _vp_tonemask_adj_16,
  139653. _vp_tonemask_adj_16,
  139654. _psy_noiseguards_8,
  139655. _psy_noisebias_16_impulse,
  139656. _psy_noisebias_16_short,
  139657. _psy_noisebias_16_short,
  139658. _psy_noisebias_16,
  139659. _psy_noise_suppress,
  139660. _psy_compand_8,
  139661. _psy_compand_16_mapping,
  139662. _psy_compand_16_mapping,
  139663. {_noise_start_16,_noise_start_16},
  139664. { _noise_part_16, _noise_part_16},
  139665. _noise_thresh_16,
  139666. _psy_ath_floater_16,
  139667. _psy_ath_abs_16,
  139668. _psy_lowpass_16,
  139669. _psy_global_44,
  139670. _global_mapping_16,
  139671. _psy_stereo_modes_16,
  139672. _floor_books,
  139673. _floor,
  139674. _floor_mapping_16_short,
  139675. _floor_mapping_16,
  139676. _mapres_template_16_uncoupled
  139677. };
  139678. /*** End of inlined file: setup_16.h ***/
  139679. /*** Start of inlined file: setup_22.h ***/
  139680. static double rate_mapping_22[4]={
  139681. 15000.,20000.,44000.,86000.
  139682. };
  139683. static double rate_mapping_22_uncoupled[4]={
  139684. 16000.,28000.,50000.,90000.
  139685. };
  139686. static double _psy_lowpass_22[4]={9.5,11.,30.,99.};
  139687. ve_setup_data_template ve_setup_22_stereo={
  139688. 3,
  139689. rate_mapping_22,
  139690. quality_mapping_16,
  139691. 2,
  139692. 19000,
  139693. 26000,
  139694. blocksize_16_short,
  139695. blocksize_16_long,
  139696. _psy_tone_masteratt_16,
  139697. _psy_tone_0dB,
  139698. _psy_tone_suppress,
  139699. _vp_tonemask_adj_16,
  139700. _vp_tonemask_adj_16,
  139701. _vp_tonemask_adj_16,
  139702. _psy_noiseguards_8,
  139703. _psy_noisebias_16_impulse,
  139704. _psy_noisebias_16_short,
  139705. _psy_noisebias_16_short,
  139706. _psy_noisebias_16,
  139707. _psy_noise_suppress,
  139708. _psy_compand_8,
  139709. _psy_compand_8_mapping,
  139710. _psy_compand_8_mapping,
  139711. {_noise_start_16,_noise_start_16},
  139712. { _noise_part_16, _noise_part_16},
  139713. _noise_thresh_16,
  139714. _psy_ath_floater_16,
  139715. _psy_ath_abs_16,
  139716. _psy_lowpass_22,
  139717. _psy_global_44,
  139718. _global_mapping_16,
  139719. _psy_stereo_modes_16,
  139720. _floor_books,
  139721. _floor,
  139722. _floor_mapping_16_short,
  139723. _floor_mapping_16,
  139724. _mapres_template_16_stereo
  139725. };
  139726. ve_setup_data_template ve_setup_22_uncoupled={
  139727. 3,
  139728. rate_mapping_22_uncoupled,
  139729. quality_mapping_16,
  139730. -1,
  139731. 19000,
  139732. 26000,
  139733. blocksize_16_short,
  139734. blocksize_16_long,
  139735. _psy_tone_masteratt_16,
  139736. _psy_tone_0dB,
  139737. _psy_tone_suppress,
  139738. _vp_tonemask_adj_16,
  139739. _vp_tonemask_adj_16,
  139740. _vp_tonemask_adj_16,
  139741. _psy_noiseguards_8,
  139742. _psy_noisebias_16_impulse,
  139743. _psy_noisebias_16_short,
  139744. _psy_noisebias_16_short,
  139745. _psy_noisebias_16,
  139746. _psy_noise_suppress,
  139747. _psy_compand_8,
  139748. _psy_compand_8_mapping,
  139749. _psy_compand_8_mapping,
  139750. {_noise_start_16,_noise_start_16},
  139751. { _noise_part_16, _noise_part_16},
  139752. _noise_thresh_16,
  139753. _psy_ath_floater_16,
  139754. _psy_ath_abs_16,
  139755. _psy_lowpass_22,
  139756. _psy_global_44,
  139757. _global_mapping_16,
  139758. _psy_stereo_modes_16,
  139759. _floor_books,
  139760. _floor,
  139761. _floor_mapping_16_short,
  139762. _floor_mapping_16,
  139763. _mapres_template_16_uncoupled
  139764. };
  139765. /*** End of inlined file: setup_22.h ***/
  139766. /*** Start of inlined file: setup_X.h ***/
  139767. static double rate_mapping_X[12]={
  139768. -1.,-1.,-1.,-1.,-1.,-1.,
  139769. -1.,-1.,-1.,-1.,-1.,-1.
  139770. };
  139771. ve_setup_data_template ve_setup_X_stereo={
  139772. 11,
  139773. rate_mapping_X,
  139774. quality_mapping_44,
  139775. 2,
  139776. 50000,
  139777. 200000,
  139778. blocksize_short_44,
  139779. blocksize_long_44,
  139780. _psy_tone_masteratt_44,
  139781. _psy_tone_0dB,
  139782. _psy_tone_suppress,
  139783. _vp_tonemask_adj_otherblock,
  139784. _vp_tonemask_adj_longblock,
  139785. _vp_tonemask_adj_otherblock,
  139786. _psy_noiseguards_44,
  139787. _psy_noisebias_impulse,
  139788. _psy_noisebias_padding,
  139789. _psy_noisebias_trans,
  139790. _psy_noisebias_long,
  139791. _psy_noise_suppress,
  139792. _psy_compand_44,
  139793. _psy_compand_short_mapping,
  139794. _psy_compand_long_mapping,
  139795. {_noise_start_short_44,_noise_start_long_44},
  139796. {_noise_part_short_44,_noise_part_long_44},
  139797. _noise_thresh_44,
  139798. _psy_ath_floater,
  139799. _psy_ath_abs,
  139800. _psy_lowpass_44,
  139801. _psy_global_44,
  139802. _global_mapping_44,
  139803. _psy_stereo_modes_44,
  139804. _floor_books,
  139805. _floor,
  139806. _floor_short_mapping_44,
  139807. _floor_long_mapping_44,
  139808. _mapres_template_44_stereo
  139809. };
  139810. ve_setup_data_template ve_setup_X_uncoupled={
  139811. 11,
  139812. rate_mapping_X,
  139813. quality_mapping_44,
  139814. -1,
  139815. 50000,
  139816. 200000,
  139817. blocksize_short_44,
  139818. blocksize_long_44,
  139819. _psy_tone_masteratt_44,
  139820. _psy_tone_0dB,
  139821. _psy_tone_suppress,
  139822. _vp_tonemask_adj_otherblock,
  139823. _vp_tonemask_adj_longblock,
  139824. _vp_tonemask_adj_otherblock,
  139825. _psy_noiseguards_44,
  139826. _psy_noisebias_impulse,
  139827. _psy_noisebias_padding,
  139828. _psy_noisebias_trans,
  139829. _psy_noisebias_long,
  139830. _psy_noise_suppress,
  139831. _psy_compand_44,
  139832. _psy_compand_short_mapping,
  139833. _psy_compand_long_mapping,
  139834. {_noise_start_short_44,_noise_start_long_44},
  139835. {_noise_part_short_44,_noise_part_long_44},
  139836. _noise_thresh_44,
  139837. _psy_ath_floater,
  139838. _psy_ath_abs,
  139839. _psy_lowpass_44,
  139840. _psy_global_44,
  139841. _global_mapping_44,
  139842. NULL,
  139843. _floor_books,
  139844. _floor,
  139845. _floor_short_mapping_44,
  139846. _floor_long_mapping_44,
  139847. _mapres_template_44_uncoupled
  139848. };
  139849. ve_setup_data_template ve_setup_XX_stereo={
  139850. 2,
  139851. rate_mapping_X,
  139852. quality_mapping_8,
  139853. 2,
  139854. 0,
  139855. 8000,
  139856. blocksize_8,
  139857. blocksize_8,
  139858. _psy_tone_masteratt_8,
  139859. _psy_tone_0dB,
  139860. _psy_tone_suppress,
  139861. _vp_tonemask_adj_8,
  139862. NULL,
  139863. _vp_tonemask_adj_8,
  139864. _psy_noiseguards_8,
  139865. _psy_noisebias_8,
  139866. _psy_noisebias_8,
  139867. NULL,
  139868. NULL,
  139869. _psy_noise_suppress,
  139870. _psy_compand_8,
  139871. _psy_compand_8_mapping,
  139872. NULL,
  139873. {_noise_start_8,_noise_start_8},
  139874. {_noise_part_8,_noise_part_8},
  139875. _noise_thresh_5only,
  139876. _psy_ath_floater_8,
  139877. _psy_ath_abs_8,
  139878. _psy_lowpass_8,
  139879. _psy_global_44,
  139880. _global_mapping_8,
  139881. _psy_stereo_modes_8,
  139882. _floor_books,
  139883. _floor,
  139884. _floor_mapping_8,
  139885. NULL,
  139886. _mapres_template_8_stereo
  139887. };
  139888. ve_setup_data_template ve_setup_XX_uncoupled={
  139889. 2,
  139890. rate_mapping_X,
  139891. quality_mapping_8,
  139892. -1,
  139893. 0,
  139894. 8000,
  139895. blocksize_8,
  139896. blocksize_8,
  139897. _psy_tone_masteratt_8,
  139898. _psy_tone_0dB,
  139899. _psy_tone_suppress,
  139900. _vp_tonemask_adj_8,
  139901. NULL,
  139902. _vp_tonemask_adj_8,
  139903. _psy_noiseguards_8,
  139904. _psy_noisebias_8,
  139905. _psy_noisebias_8,
  139906. NULL,
  139907. NULL,
  139908. _psy_noise_suppress,
  139909. _psy_compand_8,
  139910. _psy_compand_8_mapping,
  139911. NULL,
  139912. {_noise_start_8,_noise_start_8},
  139913. {_noise_part_8,_noise_part_8},
  139914. _noise_thresh_5only,
  139915. _psy_ath_floater_8,
  139916. _psy_ath_abs_8,
  139917. _psy_lowpass_8,
  139918. _psy_global_44,
  139919. _global_mapping_8,
  139920. _psy_stereo_modes_8,
  139921. _floor_books,
  139922. _floor,
  139923. _floor_mapping_8,
  139924. NULL,
  139925. _mapres_template_8_uncoupled
  139926. };
  139927. /*** End of inlined file: setup_X.h ***/
  139928. static ve_setup_data_template *setup_list[]={
  139929. &ve_setup_44_stereo,
  139930. &ve_setup_44_uncoupled,
  139931. &ve_setup_32_stereo,
  139932. &ve_setup_32_uncoupled,
  139933. &ve_setup_22_stereo,
  139934. &ve_setup_22_uncoupled,
  139935. &ve_setup_16_stereo,
  139936. &ve_setup_16_uncoupled,
  139937. &ve_setup_11_stereo,
  139938. &ve_setup_11_uncoupled,
  139939. &ve_setup_8_stereo,
  139940. &ve_setup_8_uncoupled,
  139941. &ve_setup_X_stereo,
  139942. &ve_setup_X_uncoupled,
  139943. &ve_setup_XX_stereo,
  139944. &ve_setup_XX_uncoupled,
  139945. 0
  139946. };
  139947. static int vorbis_encode_toplevel_setup(vorbis_info *vi,int ch,long rate){
  139948. if(vi && vi->codec_setup){
  139949. vi->version=0;
  139950. vi->channels=ch;
  139951. vi->rate=rate;
  139952. return(0);
  139953. }
  139954. return(OV_EINVAL);
  139955. }
  139956. static void vorbis_encode_floor_setup(vorbis_info *vi,double s,int block,
  139957. static_codebook ***books,
  139958. vorbis_info_floor1 *in,
  139959. int *x){
  139960. int i,k,is=s;
  139961. vorbis_info_floor1 *f=(vorbis_info_floor1*) _ogg_calloc(1,sizeof(*f));
  139962. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139963. memcpy(f,in+x[is],sizeof(*f));
  139964. f->n=ci->blocksizes[block]>>1;
  139965. {
  139966. int partitions=f->partitions;
  139967. int maxclass=-1;
  139968. int maxbook=-1;
  139969. for(i=0;i<partitions;i++)
  139970. if(f->partitionclass[i]>maxclass)maxclass=f->partitionclass[i];
  139971. for(i=0;i<=maxclass;i++){
  139972. if(f->class_book[i]>maxbook)maxbook=f->class_book[i];
  139973. f->class_book[i]+=ci->books;
  139974. for(k=0;k<(1<<f->class_subs[i]);k++){
  139975. if(f->class_subbook[i][k]>maxbook)maxbook=f->class_subbook[i][k];
  139976. if(f->class_subbook[i][k]>=0)f->class_subbook[i][k]+=ci->books;
  139977. }
  139978. }
  139979. for(i=0;i<=maxbook;i++)
  139980. ci->book_param[ci->books++]=books[x[is]][i];
  139981. }
  139982. ci->floor_type[ci->floors]=1;
  139983. ci->floor_param[ci->floors]=f;
  139984. ci->floors++;
  139985. return;
  139986. }
  139987. static void vorbis_encode_global_psych_setup(vorbis_info *vi,double s,
  139988. vorbis_info_psy_global *in,
  139989. double *x){
  139990. int i,is=s;
  139991. double ds=s-is;
  139992. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139993. vorbis_info_psy_global *g=&ci->psy_g_param;
  139994. memcpy(g,in+(int)x[is],sizeof(*g));
  139995. ds=x[is]*(1.-ds)+x[is+1]*ds;
  139996. is=(int)ds;
  139997. ds-=is;
  139998. if(ds==0 && is>0){
  139999. is--;
  140000. ds=1.;
  140001. }
  140002. for(i=0;i<4;i++){
  140003. g->preecho_thresh[i]=in[is].preecho_thresh[i]*(1.-ds)+in[is+1].preecho_thresh[i]*ds;
  140004. g->postecho_thresh[i]=in[is].postecho_thresh[i]*(1.-ds)+in[is+1].postecho_thresh[i]*ds;
  140005. }
  140006. g->ampmax_att_per_sec=ci->hi.amplitude_track_dBpersec;
  140007. return;
  140008. }
  140009. static void vorbis_encode_global_stereo(vorbis_info *vi,
  140010. highlevel_encode_setup *hi,
  140011. adj_stereo *p){
  140012. float s=hi->stereo_point_setting;
  140013. int i,is=s;
  140014. double ds=s-is;
  140015. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140016. vorbis_info_psy_global *g=&ci->psy_g_param;
  140017. if(p){
  140018. memcpy(g->coupling_prepointamp,p[is].pre,sizeof(*p[is].pre)*PACKETBLOBS);
  140019. memcpy(g->coupling_postpointamp,p[is].post,sizeof(*p[is].post)*PACKETBLOBS);
  140020. if(hi->managed){
  140021. for(i=0;i<PACKETBLOBS;i++){
  140022. float kHz=p[is].kHz[i]*(1.-ds)+p[is+1].kHz[i]*ds;
  140023. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140024. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140025. g->coupling_pkHz[i]=kHz;
  140026. kHz=p[is].lowpasskHz[i]*(1.-ds)+p[is+1].lowpasskHz[i]*ds;
  140027. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140028. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140029. }
  140030. }else{
  140031. float kHz=p[is].kHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].kHz[PACKETBLOBS/2]*ds;
  140032. for(i=0;i<PACKETBLOBS;i++){
  140033. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140034. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140035. g->coupling_pkHz[i]=kHz;
  140036. }
  140037. kHz=p[is].lowpasskHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].lowpasskHz[PACKETBLOBS/2]*ds;
  140038. for(i=0;i<PACKETBLOBS;i++){
  140039. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140040. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140041. }
  140042. }
  140043. }else{
  140044. for(i=0;i<PACKETBLOBS;i++){
  140045. g->sliding_lowpass[0][i]=ci->blocksizes[0];
  140046. g->sliding_lowpass[1][i]=ci->blocksizes[1];
  140047. }
  140048. }
  140049. return;
  140050. }
  140051. static void vorbis_encode_psyset_setup(vorbis_info *vi,double s,
  140052. int *nn_start,
  140053. int *nn_partition,
  140054. double *nn_thresh,
  140055. int block){
  140056. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140057. vorbis_info_psy *p=ci->psy_param[block];
  140058. highlevel_encode_setup *hi=&ci->hi;
  140059. int is=s;
  140060. if(block>=ci->psys)
  140061. ci->psys=block+1;
  140062. if(!p){
  140063. p=(vorbis_info_psy*)_ogg_calloc(1,sizeof(*p));
  140064. ci->psy_param[block]=p;
  140065. }
  140066. memcpy(p,&_psy_info_template,sizeof(*p));
  140067. p->blockflag=block>>1;
  140068. if(hi->noise_normalize_p){
  140069. p->normal_channel_p=1;
  140070. p->normal_point_p=1;
  140071. p->normal_start=nn_start[is];
  140072. p->normal_partition=nn_partition[is];
  140073. p->normal_thresh=nn_thresh[is];
  140074. }
  140075. return;
  140076. }
  140077. static void vorbis_encode_tonemask_setup(vorbis_info *vi,double s,int block,
  140078. att3 *att,
  140079. int *max,
  140080. vp_adjblock *in){
  140081. int i,is=s;
  140082. double ds=s-is;
  140083. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140084. vorbis_info_psy *p=ci->psy_param[block];
  140085. p->tone_masteratt[0]=att[is].att[0]*(1.-ds)+att[is+1].att[0]*ds;
  140086. p->tone_masteratt[1]=att[is].att[1]*(1.-ds)+att[is+1].att[1]*ds;
  140087. p->tone_masteratt[2]=att[is].att[2]*(1.-ds)+att[is+1].att[2]*ds;
  140088. p->tone_centerboost=att[is].boost*(1.-ds)+att[is+1].boost*ds;
  140089. p->tone_decay=att[is].decay*(1.-ds)+att[is+1].decay*ds;
  140090. p->max_curve_dB=max[is]*(1.-ds)+max[is+1]*ds;
  140091. for(i=0;i<P_BANDS;i++)
  140092. p->toneatt[i]=in[is].block[i]*(1.-ds)+in[is+1].block[i]*ds;
  140093. return;
  140094. }
  140095. static void vorbis_encode_compand_setup(vorbis_info *vi,double s,int block,
  140096. compandblock *in, double *x){
  140097. int i,is=s;
  140098. double ds=s-is;
  140099. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140100. vorbis_info_psy *p=ci->psy_param[block];
  140101. ds=x[is]*(1.-ds)+x[is+1]*ds;
  140102. is=(int)ds;
  140103. ds-=is;
  140104. if(ds==0 && is>0){
  140105. is--;
  140106. ds=1.;
  140107. }
  140108. for(i=0;i<NOISE_COMPAND_LEVELS;i++)
  140109. p->noisecompand[i]=in[is].data[i]*(1.-ds)+in[is+1].data[i]*ds;
  140110. return;
  140111. }
  140112. static void vorbis_encode_peak_setup(vorbis_info *vi,double s,int block,
  140113. int *suppress){
  140114. int is=s;
  140115. double ds=s-is;
  140116. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140117. vorbis_info_psy *p=ci->psy_param[block];
  140118. p->tone_abs_limit=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140119. return;
  140120. }
  140121. static void vorbis_encode_noisebias_setup(vorbis_info *vi,double s,int block,
  140122. int *suppress,
  140123. noise3 *in,
  140124. noiseguard *guard,
  140125. double userbias){
  140126. int i,is=s,j;
  140127. double ds=s-is;
  140128. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140129. vorbis_info_psy *p=ci->psy_param[block];
  140130. p->noisemaxsupp=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140131. p->noisewindowlomin=guard[block].lo;
  140132. p->noisewindowhimin=guard[block].hi;
  140133. p->noisewindowfixed=guard[block].fixed;
  140134. for(j=0;j<P_NOISECURVES;j++)
  140135. for(i=0;i<P_BANDS;i++)
  140136. p->noiseoff[j][i]=in[is].data[j][i]*(1.-ds)+in[is+1].data[j][i]*ds;
  140137. for(j=0;j<P_NOISECURVES;j++){
  140138. float min=p->noiseoff[j][0]+6; /* the lowest it can go */
  140139. for(i=0;i<P_BANDS;i++){
  140140. p->noiseoff[j][i]+=userbias;
  140141. if(p->noiseoff[j][i]<min)p->noiseoff[j][i]=min;
  140142. }
  140143. }
  140144. return;
  140145. }
  140146. static void vorbis_encode_ath_setup(vorbis_info *vi,int block){
  140147. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140148. vorbis_info_psy *p=ci->psy_param[block];
  140149. p->ath_adjatt=ci->hi.ath_floating_dB;
  140150. p->ath_maxatt=ci->hi.ath_absolute_dB;
  140151. return;
  140152. }
  140153. static int book_dup_or_new(codec_setup_info *ci,static_codebook *book){
  140154. int i;
  140155. for(i=0;i<ci->books;i++)
  140156. if(ci->book_param[i]==book)return(i);
  140157. return(ci->books++);
  140158. }
  140159. static void vorbis_encode_blocksize_setup(vorbis_info *vi,double s,
  140160. int *shortb,int *longb){
  140161. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140162. int is=s;
  140163. int blockshort=shortb[is];
  140164. int blocklong=longb[is];
  140165. ci->blocksizes[0]=blockshort;
  140166. ci->blocksizes[1]=blocklong;
  140167. }
  140168. static void vorbis_encode_residue_setup(vorbis_info *vi,
  140169. int number, int block,
  140170. vorbis_residue_template *res){
  140171. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140172. int i,n;
  140173. vorbis_info_residue0 *r=(vorbis_info_residue0*)(ci->residue_param[number]=
  140174. (vorbis_info_residue0*)_ogg_malloc(sizeof(*r)));
  140175. memcpy(r,res->res,sizeof(*r));
  140176. if(ci->residues<=number)ci->residues=number+1;
  140177. switch(ci->blocksizes[block]){
  140178. case 64:case 128:case 256:
  140179. r->grouping=16;
  140180. break;
  140181. default:
  140182. r->grouping=32;
  140183. break;
  140184. }
  140185. ci->residue_type[number]=res->res_type;
  140186. n=r->end=ci->blocksizes[block]>>1;
  140187. if(res->res_type==2)
  140188. n=r->end*=vi->channels;
  140189. {
  140190. int booklist=0,k;
  140191. if(ci->hi.managed){
  140192. for(i=0;i<r->partitions;i++)
  140193. for(k=0;k<3;k++)
  140194. if(res->books_base_managed->books[i][k])
  140195. r->secondstages[i]|=(1<<k);
  140196. r->groupbook=book_dup_or_new(ci,res->book_aux_managed);
  140197. ci->book_param[r->groupbook]=res->book_aux_managed;
  140198. for(i=0;i<r->partitions;i++){
  140199. for(k=0;k<3;k++){
  140200. if(res->books_base_managed->books[i][k]){
  140201. int bookid=book_dup_or_new(ci,res->books_base_managed->books[i][k]);
  140202. r->booklist[booklist++]=bookid;
  140203. ci->book_param[bookid]=res->books_base_managed->books[i][k];
  140204. }
  140205. }
  140206. }
  140207. }else{
  140208. for(i=0;i<r->partitions;i++)
  140209. for(k=0;k<3;k++)
  140210. if(res->books_base->books[i][k])
  140211. r->secondstages[i]|=(1<<k);
  140212. r->groupbook=book_dup_or_new(ci,res->book_aux);
  140213. ci->book_param[r->groupbook]=res->book_aux;
  140214. for(i=0;i<r->partitions;i++){
  140215. for(k=0;k<3;k++){
  140216. if(res->books_base->books[i][k]){
  140217. int bookid=book_dup_or_new(ci,res->books_base->books[i][k]);
  140218. r->booklist[booklist++]=bookid;
  140219. ci->book_param[bookid]=res->books_base->books[i][k];
  140220. }
  140221. }
  140222. }
  140223. }
  140224. }
  140225. {
  140226. double freq=ci->hi.lowpass_kHz*1000.;
  140227. vorbis_info_floor1 *f=(vorbis_info_floor1*)ci->floor_param[block]; /* by convention */
  140228. double nyq=vi->rate/2.;
  140229. long blocksize=ci->blocksizes[block]>>1;
  140230. if(freq>nyq)freq=nyq;
  140231. f->n=freq/nyq*blocksize;
  140232. if(res->limit_type){
  140233. if(ci->hi.managed)
  140234. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS-1]*1000.;
  140235. else
  140236. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS/2]*1000.;
  140237. if(freq>nyq)freq=nyq;
  140238. }
  140239. if(ci->residue_type[block]==2)
  140240. r->end=(int)((freq/nyq*blocksize*2)/r->grouping+.9)* /* round up only if we're well past */
  140241. r->grouping;
  140242. else
  140243. r->end=(int)((freq/nyq*blocksize)/r->grouping+.9)* /* round up only if we're well past */
  140244. r->grouping;
  140245. }
  140246. }
  140247. static void vorbis_encode_map_n_res_setup(vorbis_info *vi,double s,
  140248. vorbis_mapping_template *maps){
  140249. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140250. int i,j,is=s,modes=2;
  140251. vorbis_info_mapping0 *map=maps[is].map;
  140252. vorbis_info_mode *mode=_mode_template;
  140253. vorbis_residue_template *res=maps[is].res;
  140254. if(ci->blocksizes[0]==ci->blocksizes[1])modes=1;
  140255. for(i=0;i<modes;i++){
  140256. ci->map_param[i]=_ogg_calloc(1,sizeof(*map));
  140257. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*mode));
  140258. memcpy(ci->mode_param[i],mode+i,sizeof(*_mode_template));
  140259. if(i>=ci->modes)ci->modes=i+1;
  140260. ci->map_type[i]=0;
  140261. memcpy(ci->map_param[i],map+i,sizeof(*map));
  140262. if(i>=ci->maps)ci->maps=i+1;
  140263. for(j=0;j<map[i].submaps;j++)
  140264. vorbis_encode_residue_setup(vi,map[i].residuesubmap[j],i
  140265. ,res+map[i].residuesubmap[j]);
  140266. }
  140267. }
  140268. static double setting_to_approx_bitrate(vorbis_info *vi){
  140269. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140270. highlevel_encode_setup *hi=&ci->hi;
  140271. ve_setup_data_template *setup=(ve_setup_data_template *)hi->setup;
  140272. int is=hi->base_setting;
  140273. double ds=hi->base_setting-is;
  140274. int ch=vi->channels;
  140275. double *r=setup->rate_mapping;
  140276. if(r==NULL)
  140277. return(-1);
  140278. return((r[is]*(1.-ds)+r[is+1]*ds)*ch);
  140279. }
  140280. static void get_setup_template(vorbis_info *vi,
  140281. long ch,long srate,
  140282. double req,int q_or_bitrate){
  140283. int i=0,j;
  140284. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140285. highlevel_encode_setup *hi=&ci->hi;
  140286. if(q_or_bitrate)req/=ch;
  140287. while(setup_list[i]){
  140288. if(setup_list[i]->coupling_restriction==-1 ||
  140289. setup_list[i]->coupling_restriction==ch){
  140290. if(srate>=setup_list[i]->samplerate_min_restriction &&
  140291. srate<=setup_list[i]->samplerate_max_restriction){
  140292. int mappings=setup_list[i]->mappings;
  140293. double *map=(q_or_bitrate?
  140294. setup_list[i]->rate_mapping:
  140295. setup_list[i]->quality_mapping);
  140296. if(req<map[0]){++i;continue;}
  140297. if(req>map[setup_list[i]->mappings]){++i;continue;}
  140298. for(j=0;j<mappings;j++)
  140299. if(req>=map[j] && req<map[j+1])break;
  140300. hi->setup=setup_list[i];
  140301. if(j==mappings)
  140302. hi->base_setting=j-.001;
  140303. else{
  140304. float low=map[j];
  140305. float high=map[j+1];
  140306. float del=(req-low)/(high-low);
  140307. hi->base_setting=j+del;
  140308. }
  140309. return;
  140310. }
  140311. }
  140312. i++;
  140313. }
  140314. hi->setup=NULL;
  140315. }
  140316. int vorbis_encode_setup_init(vorbis_info *vi){
  140317. int i0=0,singleblock=0;
  140318. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140319. ve_setup_data_template *setup=NULL;
  140320. highlevel_encode_setup *hi=&ci->hi;
  140321. if(ci==NULL)return(OV_EINVAL);
  140322. if(!hi->impulse_block_p)i0=1;
  140323. if(hi->ath_floating_dB>-80)hi->ath_floating_dB=-80;
  140324. if(hi->ath_floating_dB<-200)hi->ath_floating_dB=-200;
  140325. if(hi->amplitude_track_dBpersec>0.)hi->amplitude_track_dBpersec=0.;
  140326. if(hi->amplitude_track_dBpersec<-99999.)hi->amplitude_track_dBpersec=-99999.;
  140327. setup=(ve_setup_data_template *)hi->setup;
  140328. if(setup==NULL)return(OV_EINVAL);
  140329. hi->set_in_stone=1;
  140330. vorbis_encode_blocksize_setup(vi,hi->base_setting,
  140331. setup->blocksize_short,
  140332. setup->blocksize_long);
  140333. if(ci->blocksizes[0]==ci->blocksizes[1])singleblock=1;
  140334. vorbis_encode_floor_setup(vi,hi->short_setting,0,
  140335. setup->floor_books,
  140336. setup->floor_params,
  140337. setup->floor_short_mapping);
  140338. if(!singleblock)
  140339. vorbis_encode_floor_setup(vi,hi->long_setting,1,
  140340. setup->floor_books,
  140341. setup->floor_params,
  140342. setup->floor_long_mapping);
  140343. vorbis_encode_global_psych_setup(vi,hi->trigger_setting,
  140344. setup->global_params,
  140345. setup->global_mapping);
  140346. vorbis_encode_global_stereo(vi,hi,setup->stereo_modes);
  140347. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140348. setup->psy_noise_normal_start[0],
  140349. setup->psy_noise_normal_partition[0],
  140350. setup->psy_noise_normal_thresh,
  140351. 0);
  140352. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140353. setup->psy_noise_normal_start[0],
  140354. setup->psy_noise_normal_partition[0],
  140355. setup->psy_noise_normal_thresh,
  140356. 1);
  140357. if(!singleblock){
  140358. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140359. setup->psy_noise_normal_start[1],
  140360. setup->psy_noise_normal_partition[1],
  140361. setup->psy_noise_normal_thresh,
  140362. 2);
  140363. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140364. setup->psy_noise_normal_start[1],
  140365. setup->psy_noise_normal_partition[1],
  140366. setup->psy_noise_normal_thresh,
  140367. 3);
  140368. }
  140369. vorbis_encode_tonemask_setup(vi,hi->block[i0].tone_mask_setting,0,
  140370. setup->psy_tone_masteratt,
  140371. setup->psy_tone_0dB,
  140372. setup->psy_tone_adj_impulse);
  140373. vorbis_encode_tonemask_setup(vi,hi->block[1].tone_mask_setting,1,
  140374. setup->psy_tone_masteratt,
  140375. setup->psy_tone_0dB,
  140376. setup->psy_tone_adj_other);
  140377. if(!singleblock){
  140378. vorbis_encode_tonemask_setup(vi,hi->block[2].tone_mask_setting,2,
  140379. setup->psy_tone_masteratt,
  140380. setup->psy_tone_0dB,
  140381. setup->psy_tone_adj_other);
  140382. vorbis_encode_tonemask_setup(vi,hi->block[3].tone_mask_setting,3,
  140383. setup->psy_tone_masteratt,
  140384. setup->psy_tone_0dB,
  140385. setup->psy_tone_adj_long);
  140386. }
  140387. vorbis_encode_compand_setup(vi,hi->block[i0].noise_compand_setting,0,
  140388. setup->psy_noise_compand,
  140389. setup->psy_noise_compand_short_mapping);
  140390. vorbis_encode_compand_setup(vi,hi->block[1].noise_compand_setting,1,
  140391. setup->psy_noise_compand,
  140392. setup->psy_noise_compand_short_mapping);
  140393. if(!singleblock){
  140394. vorbis_encode_compand_setup(vi,hi->block[2].noise_compand_setting,2,
  140395. setup->psy_noise_compand,
  140396. setup->psy_noise_compand_long_mapping);
  140397. vorbis_encode_compand_setup(vi,hi->block[3].noise_compand_setting,3,
  140398. setup->psy_noise_compand,
  140399. setup->psy_noise_compand_long_mapping);
  140400. }
  140401. vorbis_encode_peak_setup(vi,hi->block[i0].tone_peaklimit_setting,0,
  140402. setup->psy_tone_dBsuppress);
  140403. vorbis_encode_peak_setup(vi,hi->block[1].tone_peaklimit_setting,1,
  140404. setup->psy_tone_dBsuppress);
  140405. if(!singleblock){
  140406. vorbis_encode_peak_setup(vi,hi->block[2].tone_peaklimit_setting,2,
  140407. setup->psy_tone_dBsuppress);
  140408. vorbis_encode_peak_setup(vi,hi->block[3].tone_peaklimit_setting,3,
  140409. setup->psy_tone_dBsuppress);
  140410. }
  140411. vorbis_encode_noisebias_setup(vi,hi->block[i0].noise_bias_setting,0,
  140412. setup->psy_noise_dBsuppress,
  140413. setup->psy_noise_bias_impulse,
  140414. setup->psy_noiseguards,
  140415. (i0==0?hi->impulse_noisetune:0.));
  140416. vorbis_encode_noisebias_setup(vi,hi->block[1].noise_bias_setting,1,
  140417. setup->psy_noise_dBsuppress,
  140418. setup->psy_noise_bias_padding,
  140419. setup->psy_noiseguards,0.);
  140420. if(!singleblock){
  140421. vorbis_encode_noisebias_setup(vi,hi->block[2].noise_bias_setting,2,
  140422. setup->psy_noise_dBsuppress,
  140423. setup->psy_noise_bias_trans,
  140424. setup->psy_noiseguards,0.);
  140425. vorbis_encode_noisebias_setup(vi,hi->block[3].noise_bias_setting,3,
  140426. setup->psy_noise_dBsuppress,
  140427. setup->psy_noise_bias_long,
  140428. setup->psy_noiseguards,0.);
  140429. }
  140430. vorbis_encode_ath_setup(vi,0);
  140431. vorbis_encode_ath_setup(vi,1);
  140432. if(!singleblock){
  140433. vorbis_encode_ath_setup(vi,2);
  140434. vorbis_encode_ath_setup(vi,3);
  140435. }
  140436. vorbis_encode_map_n_res_setup(vi,hi->base_setting,setup->maps);
  140437. if(hi->bitrate_av>0)
  140438. vi->bitrate_nominal=hi->bitrate_av;
  140439. else{
  140440. vi->bitrate_nominal=setting_to_approx_bitrate(vi);
  140441. }
  140442. vi->bitrate_lower=hi->bitrate_min;
  140443. vi->bitrate_upper=hi->bitrate_max;
  140444. if(hi->bitrate_av)
  140445. vi->bitrate_window=(double)hi->bitrate_reservoir/hi->bitrate_av;
  140446. else
  140447. vi->bitrate_window=0.;
  140448. if(hi->managed){
  140449. ci->bi.avg_rate=hi->bitrate_av;
  140450. ci->bi.min_rate=hi->bitrate_min;
  140451. ci->bi.max_rate=hi->bitrate_max;
  140452. ci->bi.reservoir_bits=hi->bitrate_reservoir;
  140453. ci->bi.reservoir_bias=
  140454. hi->bitrate_reservoir_bias;
  140455. ci->bi.slew_damp=hi->bitrate_av_damp;
  140456. }
  140457. return(0);
  140458. }
  140459. static int vorbis_encode_setup_setting(vorbis_info *vi,
  140460. long channels,
  140461. long rate){
  140462. int ret=0,i,is;
  140463. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140464. highlevel_encode_setup *hi=&ci->hi;
  140465. ve_setup_data_template *setup=(ve_setup_data_template*) hi->setup;
  140466. double ds;
  140467. ret=vorbis_encode_toplevel_setup(vi,channels,rate);
  140468. if(ret)return(ret);
  140469. is=hi->base_setting;
  140470. ds=hi->base_setting-is;
  140471. hi->short_setting=hi->base_setting;
  140472. hi->long_setting=hi->base_setting;
  140473. hi->managed=0;
  140474. hi->impulse_block_p=1;
  140475. hi->noise_normalize_p=1;
  140476. hi->stereo_point_setting=hi->base_setting;
  140477. hi->lowpass_kHz=
  140478. setup->psy_lowpass[is]*(1.-ds)+setup->psy_lowpass[is+1]*ds;
  140479. hi->ath_floating_dB=setup->psy_ath_float[is]*(1.-ds)+
  140480. setup->psy_ath_float[is+1]*ds;
  140481. hi->ath_absolute_dB=setup->psy_ath_abs[is]*(1.-ds)+
  140482. setup->psy_ath_abs[is+1]*ds;
  140483. hi->amplitude_track_dBpersec=-6.;
  140484. hi->trigger_setting=hi->base_setting;
  140485. for(i=0;i<4;i++){
  140486. hi->block[i].tone_mask_setting=hi->base_setting;
  140487. hi->block[i].tone_peaklimit_setting=hi->base_setting;
  140488. hi->block[i].noise_bias_setting=hi->base_setting;
  140489. hi->block[i].noise_compand_setting=hi->base_setting;
  140490. }
  140491. return(ret);
  140492. }
  140493. int vorbis_encode_setup_vbr(vorbis_info *vi,
  140494. long channels,
  140495. long rate,
  140496. float quality){
  140497. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140498. highlevel_encode_setup *hi=&ci->hi;
  140499. quality+=.0000001;
  140500. if(quality>=1.)quality=.9999;
  140501. get_setup_template(vi,channels,rate,quality,0);
  140502. if(!hi->setup)return OV_EIMPL;
  140503. return vorbis_encode_setup_setting(vi,channels,rate);
  140504. }
  140505. int vorbis_encode_init_vbr(vorbis_info *vi,
  140506. long channels,
  140507. long rate,
  140508. float base_quality /* 0. to 1. */
  140509. ){
  140510. int ret=0;
  140511. ret=vorbis_encode_setup_vbr(vi,channels,rate,base_quality);
  140512. if(ret){
  140513. vorbis_info_clear(vi);
  140514. return ret;
  140515. }
  140516. ret=vorbis_encode_setup_init(vi);
  140517. if(ret)
  140518. vorbis_info_clear(vi);
  140519. return(ret);
  140520. }
  140521. int vorbis_encode_setup_managed(vorbis_info *vi,
  140522. long channels,
  140523. long rate,
  140524. long max_bitrate,
  140525. long nominal_bitrate,
  140526. long min_bitrate){
  140527. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140528. highlevel_encode_setup *hi=&ci->hi;
  140529. double tnominal=nominal_bitrate;
  140530. int ret=0;
  140531. if(nominal_bitrate<=0.){
  140532. if(max_bitrate>0.){
  140533. if(min_bitrate>0.)
  140534. nominal_bitrate=(max_bitrate+min_bitrate)*.5;
  140535. else
  140536. nominal_bitrate=max_bitrate*.875;
  140537. }else{
  140538. if(min_bitrate>0.){
  140539. nominal_bitrate=min_bitrate;
  140540. }else{
  140541. return(OV_EINVAL);
  140542. }
  140543. }
  140544. }
  140545. get_setup_template(vi,channels,rate,nominal_bitrate,1);
  140546. if(!hi->setup)return OV_EIMPL;
  140547. ret=vorbis_encode_setup_setting(vi,channels,rate);
  140548. if(ret){
  140549. vorbis_info_clear(vi);
  140550. return ret;
  140551. }
  140552. hi->managed=1;
  140553. hi->bitrate_min=min_bitrate;
  140554. hi->bitrate_max=max_bitrate;
  140555. hi->bitrate_av=tnominal;
  140556. hi->bitrate_av_damp=1.5f; /* full range in no less than 1.5 second */
  140557. hi->bitrate_reservoir=nominal_bitrate*2;
  140558. hi->bitrate_reservoir_bias=.1; /* bias toward hoarding bits */
  140559. return(ret);
  140560. }
  140561. int vorbis_encode_init(vorbis_info *vi,
  140562. long channels,
  140563. long rate,
  140564. long max_bitrate,
  140565. long nominal_bitrate,
  140566. long min_bitrate){
  140567. int ret=vorbis_encode_setup_managed(vi,channels,rate,
  140568. max_bitrate,
  140569. nominal_bitrate,
  140570. min_bitrate);
  140571. if(ret){
  140572. vorbis_info_clear(vi);
  140573. return(ret);
  140574. }
  140575. ret=vorbis_encode_setup_init(vi);
  140576. if(ret)
  140577. vorbis_info_clear(vi);
  140578. return(ret);
  140579. }
  140580. int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg){
  140581. if(vi){
  140582. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140583. highlevel_encode_setup *hi=&ci->hi;
  140584. int setp=(number&0xf); /* a read request has a low nibble of 0 */
  140585. if(setp && hi->set_in_stone)return(OV_EINVAL);
  140586. switch(number){
  140587. case OV_ECTL_RATEMANAGE_GET:
  140588. {
  140589. struct ovectl_ratemanage_arg *ai=
  140590. (struct ovectl_ratemanage_arg *)arg;
  140591. ai->management_active=hi->managed;
  140592. ai->bitrate_hard_window=ai->bitrate_av_window=
  140593. (double)hi->bitrate_reservoir/vi->rate;
  140594. ai->bitrate_av_window_center=1.;
  140595. ai->bitrate_hard_min=hi->bitrate_min;
  140596. ai->bitrate_hard_max=hi->bitrate_max;
  140597. ai->bitrate_av_lo=hi->bitrate_av;
  140598. ai->bitrate_av_hi=hi->bitrate_av;
  140599. }
  140600. return(0);
  140601. case OV_ECTL_RATEMANAGE_SET:
  140602. {
  140603. struct ovectl_ratemanage_arg *ai=
  140604. (struct ovectl_ratemanage_arg *)arg;
  140605. if(ai==NULL){
  140606. hi->managed=0;
  140607. }else{
  140608. hi->managed=ai->management_active;
  140609. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_AVG,arg);
  140610. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_HARD,arg);
  140611. }
  140612. }
  140613. return 0;
  140614. case OV_ECTL_RATEMANAGE_AVG:
  140615. {
  140616. struct ovectl_ratemanage_arg *ai=
  140617. (struct ovectl_ratemanage_arg *)arg;
  140618. if(ai==NULL){
  140619. hi->bitrate_av=0;
  140620. }else{
  140621. hi->bitrate_av=(ai->bitrate_av_lo+ai->bitrate_av_hi)*.5;
  140622. }
  140623. }
  140624. return(0);
  140625. case OV_ECTL_RATEMANAGE_HARD:
  140626. {
  140627. struct ovectl_ratemanage_arg *ai=
  140628. (struct ovectl_ratemanage_arg *)arg;
  140629. if(ai==NULL){
  140630. hi->bitrate_min=0;
  140631. hi->bitrate_max=0;
  140632. }else{
  140633. hi->bitrate_min=ai->bitrate_hard_min;
  140634. hi->bitrate_max=ai->bitrate_hard_max;
  140635. hi->bitrate_reservoir=ai->bitrate_hard_window*
  140636. (hi->bitrate_max+hi->bitrate_min)*.5;
  140637. }
  140638. if(hi->bitrate_reservoir<128.)
  140639. hi->bitrate_reservoir=128.;
  140640. }
  140641. return(0);
  140642. case OV_ECTL_RATEMANAGE2_GET:
  140643. {
  140644. struct ovectl_ratemanage2_arg *ai=
  140645. (struct ovectl_ratemanage2_arg *)arg;
  140646. if(ai==NULL)return OV_EINVAL;
  140647. ai->management_active=hi->managed;
  140648. ai->bitrate_limit_min_kbps=hi->bitrate_min/1000;
  140649. ai->bitrate_limit_max_kbps=hi->bitrate_max/1000;
  140650. ai->bitrate_average_kbps=hi->bitrate_av/1000;
  140651. ai->bitrate_average_damping=hi->bitrate_av_damp;
  140652. ai->bitrate_limit_reservoir_bits=hi->bitrate_reservoir;
  140653. ai->bitrate_limit_reservoir_bias=hi->bitrate_reservoir_bias;
  140654. }
  140655. return (0);
  140656. case OV_ECTL_RATEMANAGE2_SET:
  140657. {
  140658. struct ovectl_ratemanage2_arg *ai=
  140659. (struct ovectl_ratemanage2_arg *)arg;
  140660. if(ai==NULL){
  140661. hi->managed=0;
  140662. }else{
  140663. if(ai->bitrate_limit_min_kbps>0 &&
  140664. ai->bitrate_average_kbps>0 &&
  140665. ai->bitrate_limit_min_kbps>ai->bitrate_average_kbps)
  140666. return OV_EINVAL;
  140667. if(ai->bitrate_limit_max_kbps>0 &&
  140668. ai->bitrate_average_kbps>0 &&
  140669. ai->bitrate_limit_max_kbps<ai->bitrate_average_kbps)
  140670. return OV_EINVAL;
  140671. if(ai->bitrate_limit_min_kbps>0 &&
  140672. ai->bitrate_limit_max_kbps>0 &&
  140673. ai->bitrate_limit_min_kbps>ai->bitrate_limit_max_kbps)
  140674. return OV_EINVAL;
  140675. if(ai->bitrate_average_damping <= 0.)
  140676. return OV_EINVAL;
  140677. if(ai->bitrate_limit_reservoir_bits < 0)
  140678. return OV_EINVAL;
  140679. if(ai->bitrate_limit_reservoir_bias < 0.)
  140680. return OV_EINVAL;
  140681. if(ai->bitrate_limit_reservoir_bias > 1.)
  140682. return OV_EINVAL;
  140683. hi->managed=ai->management_active;
  140684. hi->bitrate_min=ai->bitrate_limit_min_kbps * 1000;
  140685. hi->bitrate_max=ai->bitrate_limit_max_kbps * 1000;
  140686. hi->bitrate_av=ai->bitrate_average_kbps * 1000;
  140687. hi->bitrate_av_damp=ai->bitrate_average_damping;
  140688. hi->bitrate_reservoir=ai->bitrate_limit_reservoir_bits;
  140689. hi->bitrate_reservoir_bias=ai->bitrate_limit_reservoir_bias;
  140690. }
  140691. }
  140692. return 0;
  140693. case OV_ECTL_LOWPASS_GET:
  140694. {
  140695. double *farg=(double *)arg;
  140696. *farg=hi->lowpass_kHz;
  140697. }
  140698. return(0);
  140699. case OV_ECTL_LOWPASS_SET:
  140700. {
  140701. double *farg=(double *)arg;
  140702. hi->lowpass_kHz=*farg;
  140703. if(hi->lowpass_kHz<2.)hi->lowpass_kHz=2.;
  140704. if(hi->lowpass_kHz>99.)hi->lowpass_kHz=99.;
  140705. }
  140706. return(0);
  140707. case OV_ECTL_IBLOCK_GET:
  140708. {
  140709. double *farg=(double *)arg;
  140710. *farg=hi->impulse_noisetune;
  140711. }
  140712. return(0);
  140713. case OV_ECTL_IBLOCK_SET:
  140714. {
  140715. double *farg=(double *)arg;
  140716. hi->impulse_noisetune=*farg;
  140717. if(hi->impulse_noisetune>0.)hi->impulse_noisetune=0.;
  140718. if(hi->impulse_noisetune<-15.)hi->impulse_noisetune=-15.;
  140719. }
  140720. return(0);
  140721. }
  140722. return(OV_EIMPL);
  140723. }
  140724. return(OV_EINVAL);
  140725. }
  140726. #endif
  140727. /*** End of inlined file: vorbisenc.c ***/
  140728. /*** Start of inlined file: vorbisfile.c ***/
  140729. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  140730. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  140731. // tasks..
  140732. #if JUCE_MSVC
  140733. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  140734. #endif
  140735. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  140736. #if JUCE_USE_OGGVORBIS
  140737. #include <stdlib.h>
  140738. #include <stdio.h>
  140739. #include <errno.h>
  140740. #include <string.h>
  140741. #include <math.h>
  140742. #define CHUNKSIZE 8500 /* a shade over 8k; anyone using pages well
  140743. over 8k gets what they deserve */
  140744. static long _get_data(OggVorbis_File *vf){
  140745. errno=0;
  140746. if(vf->datasource){
  140747. char *buffer=ogg_sync_buffer(&vf->oy,CHUNKSIZE);
  140748. long bytes=(vf->callbacks.read_func)(buffer,1,CHUNKSIZE,vf->datasource);
  140749. if(bytes>0)ogg_sync_wrote(&vf->oy,bytes);
  140750. if(bytes==0 && errno)return(-1);
  140751. return(bytes);
  140752. }else
  140753. return(0);
  140754. }
  140755. static void _seek_helper(OggVorbis_File *vf,ogg_int64_t offset){
  140756. if(vf->datasource){
  140757. (vf->callbacks.seek_func)(vf->datasource, offset, SEEK_SET);
  140758. vf->offset=offset;
  140759. ogg_sync_reset(&vf->oy);
  140760. }else{
  140761. return;
  140762. }
  140763. }
  140764. static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og,
  140765. ogg_int64_t boundary){
  140766. if(boundary>0)boundary+=vf->offset;
  140767. while(1){
  140768. long more;
  140769. if(boundary>0 && vf->offset>=boundary)return(OV_FALSE);
  140770. more=ogg_sync_pageseek(&vf->oy,og);
  140771. if(more<0){
  140772. vf->offset-=more;
  140773. }else{
  140774. if(more==0){
  140775. if(!boundary)return(OV_FALSE);
  140776. {
  140777. long ret=_get_data(vf);
  140778. if(ret==0)return(OV_EOF);
  140779. if(ret<0)return(OV_EREAD);
  140780. }
  140781. }else{
  140782. ogg_int64_t ret=vf->offset;
  140783. vf->offset+=more;
  140784. return(ret);
  140785. }
  140786. }
  140787. }
  140788. }
  140789. static ogg_int64_t _get_prev_page(OggVorbis_File *vf,ogg_page *og){
  140790. ogg_int64_t begin=vf->offset;
  140791. ogg_int64_t end=begin;
  140792. ogg_int64_t ret;
  140793. ogg_int64_t offset=-1;
  140794. while(offset==-1){
  140795. begin-=CHUNKSIZE;
  140796. if(begin<0)
  140797. begin=0;
  140798. _seek_helper(vf,begin);
  140799. while(vf->offset<end){
  140800. ret=_get_next_page(vf,og,end-vf->offset);
  140801. if(ret==OV_EREAD)return(OV_EREAD);
  140802. if(ret<0){
  140803. break;
  140804. }else{
  140805. offset=ret;
  140806. }
  140807. }
  140808. }
  140809. _seek_helper(vf,offset);
  140810. ret=_get_next_page(vf,og,CHUNKSIZE);
  140811. if(ret<0)
  140812. return(OV_EFAULT);
  140813. return(offset);
  140814. }
  140815. static int _bisect_forward_serialno(OggVorbis_File *vf,
  140816. ogg_int64_t begin,
  140817. ogg_int64_t searched,
  140818. ogg_int64_t end,
  140819. long currentno,
  140820. long m){
  140821. ogg_int64_t endsearched=end;
  140822. ogg_int64_t next=end;
  140823. ogg_page og;
  140824. ogg_int64_t ret;
  140825. while(searched<endsearched){
  140826. ogg_int64_t bisect;
  140827. if(endsearched-searched<CHUNKSIZE){
  140828. bisect=searched;
  140829. }else{
  140830. bisect=(searched+endsearched)/2;
  140831. }
  140832. _seek_helper(vf,bisect);
  140833. ret=_get_next_page(vf,&og,-1);
  140834. if(ret==OV_EREAD)return(OV_EREAD);
  140835. if(ret<0 || ogg_page_serialno(&og)!=currentno){
  140836. endsearched=bisect;
  140837. if(ret>=0)next=ret;
  140838. }else{
  140839. searched=ret+og.header_len+og.body_len;
  140840. }
  140841. }
  140842. _seek_helper(vf,next);
  140843. ret=_get_next_page(vf,&og,-1);
  140844. if(ret==OV_EREAD)return(OV_EREAD);
  140845. if(searched>=end || ret<0){
  140846. vf->links=m+1;
  140847. vf->offsets=(ogg_int64_t*)_ogg_malloc((vf->links+1)*sizeof(*vf->offsets));
  140848. vf->serialnos=(long*)_ogg_malloc(vf->links*sizeof(*vf->serialnos));
  140849. vf->offsets[m+1]=searched;
  140850. }else{
  140851. ret=_bisect_forward_serialno(vf,next,vf->offset,
  140852. end,ogg_page_serialno(&og),m+1);
  140853. if(ret==OV_EREAD)return(OV_EREAD);
  140854. }
  140855. vf->offsets[m]=begin;
  140856. vf->serialnos[m]=currentno;
  140857. return(0);
  140858. }
  140859. static int _fetch_headers(OggVorbis_File *vf,vorbis_info *vi,vorbis_comment *vc,
  140860. long *serialno,ogg_page *og_ptr){
  140861. ogg_page og;
  140862. ogg_packet op;
  140863. int i,ret;
  140864. if(!og_ptr){
  140865. ogg_int64_t llret=_get_next_page(vf,&og,CHUNKSIZE);
  140866. if(llret==OV_EREAD)return(OV_EREAD);
  140867. if(llret<0)return OV_ENOTVORBIS;
  140868. og_ptr=&og;
  140869. }
  140870. ogg_stream_reset_serialno(&vf->os,ogg_page_serialno(og_ptr));
  140871. if(serialno)*serialno=vf->os.serialno;
  140872. vf->ready_state=STREAMSET;
  140873. vorbis_info_init(vi);
  140874. vorbis_comment_init(vc);
  140875. i=0;
  140876. while(i<3){
  140877. ogg_stream_pagein(&vf->os,og_ptr);
  140878. while(i<3){
  140879. int result=ogg_stream_packetout(&vf->os,&op);
  140880. if(result==0)break;
  140881. if(result==-1){
  140882. ret=OV_EBADHEADER;
  140883. goto bail_header;
  140884. }
  140885. if((ret=vorbis_synthesis_headerin(vi,vc,&op))){
  140886. goto bail_header;
  140887. }
  140888. i++;
  140889. }
  140890. if(i<3)
  140891. if(_get_next_page(vf,og_ptr,CHUNKSIZE)<0){
  140892. ret=OV_EBADHEADER;
  140893. goto bail_header;
  140894. }
  140895. }
  140896. return 0;
  140897. bail_header:
  140898. vorbis_info_clear(vi);
  140899. vorbis_comment_clear(vc);
  140900. vf->ready_state=OPENED;
  140901. return ret;
  140902. }
  140903. static void _prefetch_all_headers(OggVorbis_File *vf, ogg_int64_t dataoffset){
  140904. ogg_page og;
  140905. int i;
  140906. ogg_int64_t ret;
  140907. vf->vi=(vorbis_info*) _ogg_realloc(vf->vi,vf->links*sizeof(*vf->vi));
  140908. vf->vc=(vorbis_comment*) _ogg_realloc(vf->vc,vf->links*sizeof(*vf->vc));
  140909. vf->dataoffsets=(ogg_int64_t*) _ogg_malloc(vf->links*sizeof(*vf->dataoffsets));
  140910. vf->pcmlengths=(ogg_int64_t*) _ogg_malloc(vf->links*2*sizeof(*vf->pcmlengths));
  140911. for(i=0;i<vf->links;i++){
  140912. if(i==0){
  140913. vf->dataoffsets[i]=dataoffset;
  140914. _seek_helper(vf,dataoffset);
  140915. }else{
  140916. _seek_helper(vf,vf->offsets[i]);
  140917. if(_fetch_headers(vf,vf->vi+i,vf->vc+i,NULL,NULL)<0){
  140918. vf->dataoffsets[i]=-1;
  140919. }else{
  140920. vf->dataoffsets[i]=vf->offset;
  140921. }
  140922. }
  140923. if(vf->dataoffsets[i]!=-1){
  140924. ogg_int64_t accumulated=0;
  140925. long lastblock=-1;
  140926. int result;
  140927. ogg_stream_reset_serialno(&vf->os,vf->serialnos[i]);
  140928. while(1){
  140929. ogg_packet op;
  140930. ret=_get_next_page(vf,&og,-1);
  140931. if(ret<0)
  140932. break;
  140933. if(ogg_page_serialno(&og)!=vf->serialnos[i])
  140934. break;
  140935. ogg_stream_pagein(&vf->os,&og);
  140936. while((result=ogg_stream_packetout(&vf->os,&op))){
  140937. if(result>0){ /* ignore holes */
  140938. long thisblock=vorbis_packet_blocksize(vf->vi+i,&op);
  140939. if(lastblock!=-1)
  140940. accumulated+=(lastblock+thisblock)>>2;
  140941. lastblock=thisblock;
  140942. }
  140943. }
  140944. if(ogg_page_granulepos(&og)!=-1){
  140945. accumulated= ogg_page_granulepos(&og)-accumulated;
  140946. break;
  140947. }
  140948. }
  140949. if(accumulated<0)accumulated=0;
  140950. vf->pcmlengths[i*2]=accumulated;
  140951. }
  140952. {
  140953. ogg_int64_t end=vf->offsets[i+1];
  140954. _seek_helper(vf,end);
  140955. while(1){
  140956. ret=_get_prev_page(vf,&og);
  140957. if(ret<0){
  140958. vorbis_info_clear(vf->vi+i);
  140959. vorbis_comment_clear(vf->vc+i);
  140960. break;
  140961. }
  140962. if(ogg_page_granulepos(&og)!=-1){
  140963. vf->pcmlengths[i*2+1]=ogg_page_granulepos(&og)-vf->pcmlengths[i*2];
  140964. break;
  140965. }
  140966. vf->offset=ret;
  140967. }
  140968. }
  140969. }
  140970. }
  140971. static int _make_decode_ready(OggVorbis_File *vf){
  140972. if(vf->ready_state>STREAMSET)return 0;
  140973. if(vf->ready_state<STREAMSET)return OV_EFAULT;
  140974. if(vf->seekable){
  140975. if(vorbis_synthesis_init(&vf->vd,vf->vi+vf->current_link))
  140976. return OV_EBADLINK;
  140977. }else{
  140978. if(vorbis_synthesis_init(&vf->vd,vf->vi))
  140979. return OV_EBADLINK;
  140980. }
  140981. vorbis_block_init(&vf->vd,&vf->vb);
  140982. vf->ready_state=INITSET;
  140983. vf->bittrack=0.f;
  140984. vf->samptrack=0.f;
  140985. return 0;
  140986. }
  140987. static int _open_seekable2(OggVorbis_File *vf){
  140988. long serialno=vf->current_serialno;
  140989. ogg_int64_t dataoffset=vf->offset, end;
  140990. ogg_page og;
  140991. (vf->callbacks.seek_func)(vf->datasource,0,SEEK_END);
  140992. vf->offset=vf->end=(vf->callbacks.tell_func)(vf->datasource);
  140993. end=_get_prev_page(vf,&og);
  140994. if(end<0)return(end);
  140995. if(ogg_page_serialno(&og)!=serialno){
  140996. if(_bisect_forward_serialno(vf,0,0,end+1,serialno,0)<0)return(OV_EREAD);
  140997. }else{
  140998. if(_bisect_forward_serialno(vf,0,end,end+1,serialno,0))return(OV_EREAD);
  140999. }
  141000. _prefetch_all_headers(vf,dataoffset);
  141001. return(ov_raw_seek(vf,0));
  141002. }
  141003. static void _decode_clear(OggVorbis_File *vf){
  141004. vorbis_dsp_clear(&vf->vd);
  141005. vorbis_block_clear(&vf->vb);
  141006. vf->ready_state=OPENED;
  141007. }
  141008. static int _fetch_and_process_packet(OggVorbis_File *vf,
  141009. ogg_packet *op_in,
  141010. int readp,
  141011. int spanp){
  141012. ogg_page og;
  141013. while(1){
  141014. if(vf->ready_state==INITSET){
  141015. while(1) {
  141016. ogg_packet op;
  141017. ogg_packet *op_ptr=(op_in?op_in:&op);
  141018. int result=ogg_stream_packetout(&vf->os,op_ptr);
  141019. ogg_int64_t granulepos;
  141020. op_in=NULL;
  141021. if(result==-1)return(OV_HOLE); /* hole in the data. */
  141022. if(result>0){
  141023. granulepos=op_ptr->granulepos;
  141024. if(!vorbis_synthesis(&vf->vb,op_ptr)){ /* lazy check for lazy
  141025. header handling. The
  141026. header packets aren't
  141027. audio, so if/when we
  141028. submit them,
  141029. vorbis_synthesis will
  141030. reject them */
  141031. {
  141032. int oldsamples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141033. if(oldsamples)return(OV_EFAULT);
  141034. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  141035. vf->samptrack+=vorbis_synthesis_pcmout(&vf->vd,NULL)-oldsamples;
  141036. vf->bittrack+=op_ptr->bytes*8;
  141037. }
  141038. if(granulepos!=-1 && !op_ptr->e_o_s){
  141039. int link=(vf->seekable?vf->current_link:0);
  141040. int i,samples;
  141041. if(vf->seekable && link>0)
  141042. granulepos-=vf->pcmlengths[link*2];
  141043. if(granulepos<0)granulepos=0; /* actually, this
  141044. shouldn't be possible
  141045. here unless the stream
  141046. is very broken */
  141047. samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141048. granulepos-=samples;
  141049. for(i=0;i<link;i++)
  141050. granulepos+=vf->pcmlengths[i*2+1];
  141051. vf->pcm_offset=granulepos;
  141052. }
  141053. return(1);
  141054. }
  141055. }
  141056. else
  141057. break;
  141058. }
  141059. }
  141060. if(vf->ready_state>=OPENED){
  141061. ogg_int64_t ret;
  141062. if(!readp)return(0);
  141063. if((ret=_get_next_page(vf,&og,-1))<0){
  141064. return(OV_EOF); /* eof.
  141065. leave unitialized */
  141066. }
  141067. vf->bittrack+=og.header_len*8;
  141068. if(vf->ready_state==INITSET){
  141069. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141070. if(!spanp)
  141071. return(OV_EOF);
  141072. _decode_clear(vf);
  141073. if(!vf->seekable){
  141074. vorbis_info_clear(vf->vi);
  141075. vorbis_comment_clear(vf->vc);
  141076. }
  141077. }
  141078. }
  141079. }
  141080. if(vf->ready_state!=INITSET){
  141081. int link;
  141082. if(vf->ready_state<STREAMSET){
  141083. if(vf->seekable){
  141084. vf->current_serialno=ogg_page_serialno(&og);
  141085. for(link=0;link<vf->links;link++)
  141086. if(vf->serialnos[link]==vf->current_serialno)break;
  141087. if(link==vf->links)return(OV_EBADLINK); /* sign of a bogus
  141088. stream. error out,
  141089. leave machine
  141090. uninitialized */
  141091. vf->current_link=link;
  141092. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141093. vf->ready_state=STREAMSET;
  141094. }else{
  141095. int ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,&og);
  141096. if(ret)return(ret);
  141097. vf->current_link++;
  141098. link=0;
  141099. }
  141100. }
  141101. {
  141102. int ret=_make_decode_ready(vf);
  141103. if(ret<0)return ret;
  141104. }
  141105. }
  141106. ogg_stream_pagein(&vf->os,&og);
  141107. }
  141108. }
  141109. static int _fseek64_wrap(FILE *f,ogg_int64_t off,int whence){
  141110. if(f==NULL)return(-1);
  141111. return fseek(f,off,whence);
  141112. }
  141113. static int _ov_open1(void *f,OggVorbis_File *vf,char *initial,
  141114. long ibytes, ov_callbacks callbacks){
  141115. int offsettest=(f?callbacks.seek_func(f,0,SEEK_CUR):-1);
  141116. int ret;
  141117. memset(vf,0,sizeof(*vf));
  141118. vf->datasource=f;
  141119. vf->callbacks = callbacks;
  141120. ogg_sync_init(&vf->oy);
  141121. if(initial){
  141122. char *buffer=ogg_sync_buffer(&vf->oy,ibytes);
  141123. memcpy(buffer,initial,ibytes);
  141124. ogg_sync_wrote(&vf->oy,ibytes);
  141125. }
  141126. if(offsettest!=-1)vf->seekable=1;
  141127. vf->links=1;
  141128. vf->vi=(vorbis_info*) _ogg_calloc(vf->links,sizeof(*vf->vi));
  141129. vf->vc=(vorbis_comment*) _ogg_calloc(vf->links,sizeof(*vf->vc));
  141130. ogg_stream_init(&vf->os,-1); /* fill in the serialno later */
  141131. if((ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,NULL))<0){
  141132. vf->datasource=NULL;
  141133. ov_clear(vf);
  141134. }else
  141135. vf->ready_state=PARTOPEN;
  141136. return(ret);
  141137. }
  141138. static int _ov_open2(OggVorbis_File *vf){
  141139. if(vf->ready_state != PARTOPEN) return OV_EINVAL;
  141140. vf->ready_state=OPENED;
  141141. if(vf->seekable){
  141142. int ret=_open_seekable2(vf);
  141143. if(ret){
  141144. vf->datasource=NULL;
  141145. ov_clear(vf);
  141146. }
  141147. return(ret);
  141148. }else
  141149. vf->ready_state=STREAMSET;
  141150. return 0;
  141151. }
  141152. int ov_clear(OggVorbis_File *vf){
  141153. if(vf){
  141154. vorbis_block_clear(&vf->vb);
  141155. vorbis_dsp_clear(&vf->vd);
  141156. ogg_stream_clear(&vf->os);
  141157. if(vf->vi && vf->links){
  141158. int i;
  141159. for(i=0;i<vf->links;i++){
  141160. vorbis_info_clear(vf->vi+i);
  141161. vorbis_comment_clear(vf->vc+i);
  141162. }
  141163. _ogg_free(vf->vi);
  141164. _ogg_free(vf->vc);
  141165. }
  141166. if(vf->dataoffsets)_ogg_free(vf->dataoffsets);
  141167. if(vf->pcmlengths)_ogg_free(vf->pcmlengths);
  141168. if(vf->serialnos)_ogg_free(vf->serialnos);
  141169. if(vf->offsets)_ogg_free(vf->offsets);
  141170. ogg_sync_clear(&vf->oy);
  141171. if(vf->datasource)(vf->callbacks.close_func)(vf->datasource);
  141172. memset(vf,0,sizeof(*vf));
  141173. }
  141174. #ifdef DEBUG_LEAKS
  141175. _VDBG_dump();
  141176. #endif
  141177. return(0);
  141178. }
  141179. int ov_open_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141180. ov_callbacks callbacks){
  141181. int ret=_ov_open1(f,vf,initial,ibytes,callbacks);
  141182. if(ret)return ret;
  141183. return _ov_open2(vf);
  141184. }
  141185. int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141186. ov_callbacks callbacks = {
  141187. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141188. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141189. (int (*)(void *)) fclose,
  141190. (long (*)(void *)) ftell
  141191. };
  141192. return ov_open_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141193. }
  141194. int ov_halfrate(OggVorbis_File *vf,int flag){
  141195. int i;
  141196. if(vf->vi==NULL)return OV_EINVAL;
  141197. if(!vf->seekable)return OV_EINVAL;
  141198. if(vf->ready_state>=STREAMSET)
  141199. _decode_clear(vf); /* clear out stream state; later on libvorbis
  141200. will be able to swap this on the fly, but
  141201. for now dumping the decode machine is needed
  141202. to reinit the MDCT lookups. 1.1 libvorbis
  141203. is planned to be able to switch on the fly */
  141204. for(i=0;i<vf->links;i++){
  141205. if(vorbis_synthesis_halfrate(vf->vi+i,flag)){
  141206. ov_halfrate(vf,0);
  141207. return OV_EINVAL;
  141208. }
  141209. }
  141210. return 0;
  141211. }
  141212. int ov_halfrate_p(OggVorbis_File *vf){
  141213. if(vf->vi==NULL)return OV_EINVAL;
  141214. return vorbis_synthesis_halfrate_p(vf->vi);
  141215. }
  141216. int ov_test_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141217. ov_callbacks callbacks)
  141218. {
  141219. return _ov_open1(f,vf,initial,ibytes,callbacks);
  141220. }
  141221. int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141222. ov_callbacks callbacks = {
  141223. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141224. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141225. (int (*)(void *)) fclose,
  141226. (long (*)(void *)) ftell
  141227. };
  141228. return ov_test_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141229. }
  141230. int ov_test_open(OggVorbis_File *vf){
  141231. if(vf->ready_state!=PARTOPEN)return(OV_EINVAL);
  141232. return _ov_open2(vf);
  141233. }
  141234. long ov_streams(OggVorbis_File *vf){
  141235. return vf->links;
  141236. }
  141237. long ov_seekable(OggVorbis_File *vf){
  141238. return vf->seekable;
  141239. }
  141240. long ov_bitrate(OggVorbis_File *vf,int i){
  141241. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141242. if(i>=vf->links)return(OV_EINVAL);
  141243. if(!vf->seekable && i!=0)return(ov_bitrate(vf,0));
  141244. if(i<0){
  141245. ogg_int64_t bits=0;
  141246. int i;
  141247. float br;
  141248. for(i=0;i<vf->links;i++)
  141249. bits+=(vf->offsets[i+1]-vf->dataoffsets[i])*8;
  141250. br = bits/ov_time_total(vf,-1);
  141251. return(rint(br));
  141252. }else{
  141253. if(vf->seekable){
  141254. return(rint((vf->offsets[i+1]-vf->dataoffsets[i])*8/ov_time_total(vf,i)));
  141255. }else{
  141256. if(vf->vi[i].bitrate_nominal>0){
  141257. return vf->vi[i].bitrate_nominal;
  141258. }else{
  141259. if(vf->vi[i].bitrate_upper>0){
  141260. if(vf->vi[i].bitrate_lower>0){
  141261. return (vf->vi[i].bitrate_upper+vf->vi[i].bitrate_lower)/2;
  141262. }else{
  141263. return vf->vi[i].bitrate_upper;
  141264. }
  141265. }
  141266. return(OV_FALSE);
  141267. }
  141268. }
  141269. }
  141270. }
  141271. long ov_bitrate_instant(OggVorbis_File *vf){
  141272. int link=(vf->seekable?vf->current_link:0);
  141273. long ret;
  141274. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141275. if(vf->samptrack==0)return(OV_FALSE);
  141276. ret=vf->bittrack/vf->samptrack*vf->vi[link].rate+.5;
  141277. vf->bittrack=0.f;
  141278. vf->samptrack=0.f;
  141279. return(ret);
  141280. }
  141281. long ov_serialnumber(OggVorbis_File *vf,int i){
  141282. if(i>=vf->links)return(ov_serialnumber(vf,vf->links-1));
  141283. if(!vf->seekable && i>=0)return(ov_serialnumber(vf,-1));
  141284. if(i<0){
  141285. return(vf->current_serialno);
  141286. }else{
  141287. return(vf->serialnos[i]);
  141288. }
  141289. }
  141290. ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){
  141291. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141292. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141293. if(i<0){
  141294. ogg_int64_t acc=0;
  141295. int i;
  141296. for(i=0;i<vf->links;i++)
  141297. acc+=ov_raw_total(vf,i);
  141298. return(acc);
  141299. }else{
  141300. return(vf->offsets[i+1]-vf->offsets[i]);
  141301. }
  141302. }
  141303. ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i){
  141304. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141305. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141306. if(i<0){
  141307. ogg_int64_t acc=0;
  141308. int i;
  141309. for(i=0;i<vf->links;i++)
  141310. acc+=ov_pcm_total(vf,i);
  141311. return(acc);
  141312. }else{
  141313. return(vf->pcmlengths[i*2+1]);
  141314. }
  141315. }
  141316. double ov_time_total(OggVorbis_File *vf,int i){
  141317. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141318. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141319. if(i<0){
  141320. double acc=0;
  141321. int i;
  141322. for(i=0;i<vf->links;i++)
  141323. acc+=ov_time_total(vf,i);
  141324. return(acc);
  141325. }else{
  141326. return((double)(vf->pcmlengths[i*2+1])/vf->vi[i].rate);
  141327. }
  141328. }
  141329. int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141330. ogg_stream_state work_os;
  141331. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141332. if(!vf->seekable)
  141333. return(OV_ENOSEEK); /* don't dump machine if we can't seek */
  141334. if(pos<0 || pos>vf->end)return(OV_EINVAL);
  141335. vf->pcm_offset=-1;
  141336. ogg_stream_reset_serialno(&vf->os,
  141337. vf->current_serialno); /* must set serialno */
  141338. vorbis_synthesis_restart(&vf->vd);
  141339. _seek_helper(vf,pos);
  141340. {
  141341. ogg_page og;
  141342. ogg_packet op;
  141343. int lastblock=0;
  141344. int accblock=0;
  141345. int thisblock;
  141346. int eosflag;
  141347. ogg_stream_init(&work_os,vf->current_serialno); /* get the memory ready */
  141348. ogg_stream_reset(&work_os); /* eliminate the spurious OV_HOLE
  141349. return from not necessarily
  141350. starting from the beginning */
  141351. while(1){
  141352. if(vf->ready_state>=STREAMSET){
  141353. int result=ogg_stream_packetout(&work_os,&op);
  141354. if(result>0){
  141355. if(vf->vi[vf->current_link].codec_setup){
  141356. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141357. if(thisblock<0){
  141358. ogg_stream_packetout(&vf->os,NULL);
  141359. thisblock=0;
  141360. }else{
  141361. if(eosflag)
  141362. ogg_stream_packetout(&vf->os,NULL);
  141363. else
  141364. if(lastblock)accblock+=(lastblock+thisblock)>>2;
  141365. }
  141366. if(op.granulepos!=-1){
  141367. int i,link=vf->current_link;
  141368. ogg_int64_t granulepos=op.granulepos-vf->pcmlengths[link*2];
  141369. if(granulepos<0)granulepos=0;
  141370. for(i=0;i<link;i++)
  141371. granulepos+=vf->pcmlengths[i*2+1];
  141372. vf->pcm_offset=granulepos-accblock;
  141373. break;
  141374. }
  141375. lastblock=thisblock;
  141376. continue;
  141377. }else
  141378. ogg_stream_packetout(&vf->os,NULL);
  141379. }
  141380. }
  141381. if(!lastblock){
  141382. if(_get_next_page(vf,&og,-1)<0){
  141383. vf->pcm_offset=ov_pcm_total(vf,-1);
  141384. break;
  141385. }
  141386. }else{
  141387. vf->pcm_offset=-1;
  141388. break;
  141389. }
  141390. if(vf->ready_state>=STREAMSET)
  141391. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141392. _decode_clear(vf); /* clear out stream state */
  141393. ogg_stream_clear(&work_os);
  141394. }
  141395. if(vf->ready_state<STREAMSET){
  141396. int link;
  141397. vf->current_serialno=ogg_page_serialno(&og);
  141398. for(link=0;link<vf->links;link++)
  141399. if(vf->serialnos[link]==vf->current_serialno)break;
  141400. if(link==vf->links)goto seek_error; /* sign of a bogus stream.
  141401. error out, leave
  141402. machine uninitialized */
  141403. vf->current_link=link;
  141404. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141405. ogg_stream_reset_serialno(&work_os,vf->current_serialno);
  141406. vf->ready_state=STREAMSET;
  141407. }
  141408. ogg_stream_pagein(&vf->os,&og);
  141409. ogg_stream_pagein(&work_os,&og);
  141410. eosflag=ogg_page_eos(&og);
  141411. }
  141412. }
  141413. ogg_stream_clear(&work_os);
  141414. vf->bittrack=0.f;
  141415. vf->samptrack=0.f;
  141416. return(0);
  141417. seek_error:
  141418. vf->pcm_offset=-1;
  141419. ogg_stream_clear(&work_os);
  141420. _decode_clear(vf);
  141421. return OV_EBADLINK;
  141422. }
  141423. int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
  141424. int link=-1;
  141425. ogg_int64_t result=0;
  141426. ogg_int64_t total=ov_pcm_total(vf,-1);
  141427. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141428. if(!vf->seekable)return(OV_ENOSEEK);
  141429. if(pos<0 || pos>total)return(OV_EINVAL);
  141430. for(link=vf->links-1;link>=0;link--){
  141431. total-=vf->pcmlengths[link*2+1];
  141432. if(pos>=total)break;
  141433. }
  141434. {
  141435. ogg_int64_t end=vf->offsets[link+1];
  141436. ogg_int64_t begin=vf->offsets[link];
  141437. ogg_int64_t begintime = vf->pcmlengths[link*2];
  141438. ogg_int64_t endtime = vf->pcmlengths[link*2+1]+begintime;
  141439. ogg_int64_t target=pos-total+begintime;
  141440. ogg_int64_t best=begin;
  141441. ogg_page og;
  141442. while(begin<end){
  141443. ogg_int64_t bisect;
  141444. if(end-begin<CHUNKSIZE){
  141445. bisect=begin;
  141446. }else{
  141447. bisect=begin +
  141448. (target-begintime)*(end-begin)/(endtime-begintime) - CHUNKSIZE;
  141449. if(bisect<=begin)
  141450. bisect=begin+1;
  141451. }
  141452. _seek_helper(vf,bisect);
  141453. while(begin<end){
  141454. result=_get_next_page(vf,&og,end-vf->offset);
  141455. if(result==OV_EREAD) goto seek_error;
  141456. if(result<0){
  141457. if(bisect<=begin+1)
  141458. end=begin; /* found it */
  141459. else{
  141460. if(bisect==0) goto seek_error;
  141461. bisect-=CHUNKSIZE;
  141462. if(bisect<=begin)bisect=begin+1;
  141463. _seek_helper(vf,bisect);
  141464. }
  141465. }else{
  141466. ogg_int64_t granulepos=ogg_page_granulepos(&og);
  141467. if(granulepos==-1)continue;
  141468. if(granulepos<target){
  141469. best=result; /* raw offset of packet with granulepos */
  141470. begin=vf->offset; /* raw offset of next page */
  141471. begintime=granulepos;
  141472. if(target-begintime>44100)break;
  141473. bisect=begin; /* *not* begin + 1 */
  141474. }else{
  141475. if(bisect<=begin+1)
  141476. end=begin; /* found it */
  141477. else{
  141478. if(end==vf->offset){ /* we're pretty close - we'd be stuck in */
  141479. end=result;
  141480. bisect-=CHUNKSIZE; /* an endless loop otherwise. */
  141481. if(bisect<=begin)bisect=begin+1;
  141482. _seek_helper(vf,bisect);
  141483. }else{
  141484. end=result;
  141485. endtime=granulepos;
  141486. break;
  141487. }
  141488. }
  141489. }
  141490. }
  141491. }
  141492. }
  141493. {
  141494. ogg_page og;
  141495. ogg_packet op;
  141496. _seek_helper(vf,best);
  141497. vf->pcm_offset=-1;
  141498. if(_get_next_page(vf,&og,-1)<0)return(OV_EOF); /* shouldn't happen */
  141499. if(link!=vf->current_link){
  141500. _decode_clear(vf);
  141501. vf->current_link=link;
  141502. vf->current_serialno=ogg_page_serialno(&og);
  141503. vf->ready_state=STREAMSET;
  141504. }else{
  141505. vorbis_synthesis_restart(&vf->vd);
  141506. }
  141507. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141508. ogg_stream_pagein(&vf->os,&og);
  141509. while(1){
  141510. result=ogg_stream_packetpeek(&vf->os,&op);
  141511. if(result==0){
  141512. _seek_helper(vf,best);
  141513. while(1){
  141514. result=_get_prev_page(vf,&og);
  141515. if(result<0) goto seek_error;
  141516. if(ogg_page_granulepos(&og)>-1 ||
  141517. !ogg_page_continued(&og)){
  141518. return ov_raw_seek(vf,result);
  141519. }
  141520. vf->offset=result;
  141521. }
  141522. }
  141523. if(result<0){
  141524. result = OV_EBADPACKET;
  141525. goto seek_error;
  141526. }
  141527. if(op.granulepos!=-1){
  141528. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  141529. if(vf->pcm_offset<0)vf->pcm_offset=0;
  141530. vf->pcm_offset+=total;
  141531. break;
  141532. }else
  141533. result=ogg_stream_packetout(&vf->os,NULL);
  141534. }
  141535. }
  141536. }
  141537. if(vf->pcm_offset>pos || pos>ov_pcm_total(vf,-1)){
  141538. result=OV_EFAULT;
  141539. goto seek_error;
  141540. }
  141541. vf->bittrack=0.f;
  141542. vf->samptrack=0.f;
  141543. return(0);
  141544. seek_error:
  141545. vf->pcm_offset=-1;
  141546. _decode_clear(vf);
  141547. return (int)result;
  141548. }
  141549. int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141550. int thisblock,lastblock=0;
  141551. int ret=ov_pcm_seek_page(vf,pos);
  141552. if(ret<0)return(ret);
  141553. if((ret=_make_decode_ready(vf)))return ret;
  141554. while(1){
  141555. ogg_packet op;
  141556. ogg_page og;
  141557. int ret=ogg_stream_packetpeek(&vf->os,&op);
  141558. if(ret>0){
  141559. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141560. if(thisblock<0){
  141561. ogg_stream_packetout(&vf->os,NULL);
  141562. continue; /* non audio packet */
  141563. }
  141564. if(lastblock)vf->pcm_offset+=(lastblock+thisblock)>>2;
  141565. if(vf->pcm_offset+((thisblock+
  141566. vorbis_info_blocksize(vf->vi,1))>>2)>=pos)break;
  141567. ogg_stream_packetout(&vf->os,NULL);
  141568. vorbis_synthesis_trackonly(&vf->vb,&op); /* set up a vb with
  141569. only tracking, no
  141570. pcm_decode */
  141571. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  141572. if(op.granulepos>-1){
  141573. int i;
  141574. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  141575. if(vf->pcm_offset<0)vf->pcm_offset=0;
  141576. for(i=0;i<vf->current_link;i++)
  141577. vf->pcm_offset+=vf->pcmlengths[i*2+1];
  141578. }
  141579. lastblock=thisblock;
  141580. }else{
  141581. if(ret<0 && ret!=OV_HOLE)break;
  141582. if(_get_next_page(vf,&og,-1)<0)break;
  141583. if(vf->current_serialno!=ogg_page_serialno(&og))_decode_clear(vf);
  141584. if(vf->ready_state<STREAMSET){
  141585. int link;
  141586. vf->current_serialno=ogg_page_serialno(&og);
  141587. for(link=0;link<vf->links;link++)
  141588. if(vf->serialnos[link]==vf->current_serialno)break;
  141589. if(link==vf->links)return(OV_EBADLINK);
  141590. vf->current_link=link;
  141591. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141592. vf->ready_state=STREAMSET;
  141593. ret=_make_decode_ready(vf);
  141594. if(ret)return ret;
  141595. lastblock=0;
  141596. }
  141597. ogg_stream_pagein(&vf->os,&og);
  141598. }
  141599. }
  141600. vf->bittrack=0.f;
  141601. vf->samptrack=0.f;
  141602. while(vf->pcm_offset<pos){
  141603. ogg_int64_t target=pos-vf->pcm_offset;
  141604. long samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141605. if(samples>target)samples=target;
  141606. vorbis_synthesis_read(&vf->vd,samples);
  141607. vf->pcm_offset+=samples;
  141608. if(samples<target)
  141609. if(_fetch_and_process_packet(vf,NULL,1,1)<=0)
  141610. vf->pcm_offset=ov_pcm_total(vf,-1); /* eof */
  141611. }
  141612. return 0;
  141613. }
  141614. int ov_time_seek(OggVorbis_File *vf,double seconds){
  141615. int link=-1;
  141616. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  141617. double time_total=ov_time_total(vf,-1);
  141618. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141619. if(!vf->seekable)return(OV_ENOSEEK);
  141620. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  141621. for(link=vf->links-1;link>=0;link--){
  141622. pcm_total-=vf->pcmlengths[link*2+1];
  141623. time_total-=ov_time_total(vf,link);
  141624. if(seconds>=time_total)break;
  141625. }
  141626. {
  141627. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  141628. return(ov_pcm_seek(vf,target));
  141629. }
  141630. }
  141631. int ov_time_seek_page(OggVorbis_File *vf,double seconds){
  141632. int link=-1;
  141633. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  141634. double time_total=ov_time_total(vf,-1);
  141635. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141636. if(!vf->seekable)return(OV_ENOSEEK);
  141637. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  141638. for(link=vf->links-1;link>=0;link--){
  141639. pcm_total-=vf->pcmlengths[link*2+1];
  141640. time_total-=ov_time_total(vf,link);
  141641. if(seconds>=time_total)break;
  141642. }
  141643. {
  141644. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  141645. return(ov_pcm_seek_page(vf,target));
  141646. }
  141647. }
  141648. ogg_int64_t ov_raw_tell(OggVorbis_File *vf){
  141649. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141650. return(vf->offset);
  141651. }
  141652. ogg_int64_t ov_pcm_tell(OggVorbis_File *vf){
  141653. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141654. return(vf->pcm_offset);
  141655. }
  141656. double ov_time_tell(OggVorbis_File *vf){
  141657. int link=0;
  141658. ogg_int64_t pcm_total=0;
  141659. double time_total=0.f;
  141660. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141661. if(vf->seekable){
  141662. pcm_total=ov_pcm_total(vf,-1);
  141663. time_total=ov_time_total(vf,-1);
  141664. for(link=vf->links-1;link>=0;link--){
  141665. pcm_total-=vf->pcmlengths[link*2+1];
  141666. time_total-=ov_time_total(vf,link);
  141667. if(vf->pcm_offset>=pcm_total)break;
  141668. }
  141669. }
  141670. return((double)time_total+(double)(vf->pcm_offset-pcm_total)/vf->vi[link].rate);
  141671. }
  141672. vorbis_info *ov_info(OggVorbis_File *vf,int link){
  141673. if(vf->seekable){
  141674. if(link<0)
  141675. if(vf->ready_state>=STREAMSET)
  141676. return vf->vi+vf->current_link;
  141677. else
  141678. return vf->vi;
  141679. else
  141680. if(link>=vf->links)
  141681. return NULL;
  141682. else
  141683. return vf->vi+link;
  141684. }else{
  141685. return vf->vi;
  141686. }
  141687. }
  141688. vorbis_comment *ov_comment(OggVorbis_File *vf,int link){
  141689. if(vf->seekable){
  141690. if(link<0)
  141691. if(vf->ready_state>=STREAMSET)
  141692. return vf->vc+vf->current_link;
  141693. else
  141694. return vf->vc;
  141695. else
  141696. if(link>=vf->links)
  141697. return NULL;
  141698. else
  141699. return vf->vc+link;
  141700. }else{
  141701. return vf->vc;
  141702. }
  141703. }
  141704. static int host_is_big_endian() {
  141705. ogg_int32_t pattern = 0xfeedface; /* deadbeef */
  141706. unsigned char *bytewise = (unsigned char *)&pattern;
  141707. if (bytewise[0] == 0xfe) return 1;
  141708. return 0;
  141709. }
  141710. long ov_read(OggVorbis_File *vf,char *buffer,int length,
  141711. int bigendianp,int word,int sgned,int *bitstream){
  141712. int i,j;
  141713. int host_endian = host_is_big_endian();
  141714. float **pcm;
  141715. long samples;
  141716. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141717. while(1){
  141718. if(vf->ready_state==INITSET){
  141719. samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  141720. if(samples)break;
  141721. }
  141722. {
  141723. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  141724. if(ret==OV_EOF)
  141725. return(0);
  141726. if(ret<=0)
  141727. return(ret);
  141728. }
  141729. }
  141730. if(samples>0){
  141731. long channels=ov_info(vf,-1)->channels;
  141732. long bytespersample=word * channels;
  141733. vorbis_fpu_control fpu;
  141734. (void) fpu; // (to avoid a warning about it being unused)
  141735. if(samples>length/bytespersample)samples=length/bytespersample;
  141736. if(samples <= 0)
  141737. return OV_EINVAL;
  141738. {
  141739. int val;
  141740. if(word==1){
  141741. int off=(sgned?0:128);
  141742. vorbis_fpu_setround(&fpu);
  141743. for(j=0;j<samples;j++)
  141744. for(i=0;i<channels;i++){
  141745. val=vorbis_ftoi(pcm[i][j]*128.f);
  141746. if(val>127)val=127;
  141747. else if(val<-128)val=-128;
  141748. *buffer++=val+off;
  141749. }
  141750. vorbis_fpu_restore(fpu);
  141751. }else{
  141752. int off=(sgned?0:32768);
  141753. if(host_endian==bigendianp){
  141754. if(sgned){
  141755. vorbis_fpu_setround(&fpu);
  141756. for(i=0;i<channels;i++) { /* It's faster in this order */
  141757. float *src=pcm[i];
  141758. short *dest=((short *)buffer)+i;
  141759. for(j=0;j<samples;j++) {
  141760. val=vorbis_ftoi(src[j]*32768.f);
  141761. if(val>32767)val=32767;
  141762. else if(val<-32768)val=-32768;
  141763. *dest=val;
  141764. dest+=channels;
  141765. }
  141766. }
  141767. vorbis_fpu_restore(fpu);
  141768. }else{
  141769. vorbis_fpu_setround(&fpu);
  141770. for(i=0;i<channels;i++) {
  141771. float *src=pcm[i];
  141772. short *dest=((short *)buffer)+i;
  141773. for(j=0;j<samples;j++) {
  141774. val=vorbis_ftoi(src[j]*32768.f);
  141775. if(val>32767)val=32767;
  141776. else if(val<-32768)val=-32768;
  141777. *dest=val+off;
  141778. dest+=channels;
  141779. }
  141780. }
  141781. vorbis_fpu_restore(fpu);
  141782. }
  141783. }else if(bigendianp){
  141784. vorbis_fpu_setround(&fpu);
  141785. for(j=0;j<samples;j++)
  141786. for(i=0;i<channels;i++){
  141787. val=vorbis_ftoi(pcm[i][j]*32768.f);
  141788. if(val>32767)val=32767;
  141789. else if(val<-32768)val=-32768;
  141790. val+=off;
  141791. *buffer++=(val>>8);
  141792. *buffer++=(val&0xff);
  141793. }
  141794. vorbis_fpu_restore(fpu);
  141795. }else{
  141796. int val;
  141797. vorbis_fpu_setround(&fpu);
  141798. for(j=0;j<samples;j++)
  141799. for(i=0;i<channels;i++){
  141800. val=vorbis_ftoi(pcm[i][j]*32768.f);
  141801. if(val>32767)val=32767;
  141802. else if(val<-32768)val=-32768;
  141803. val+=off;
  141804. *buffer++=(val&0xff);
  141805. *buffer++=(val>>8);
  141806. }
  141807. vorbis_fpu_restore(fpu);
  141808. }
  141809. }
  141810. }
  141811. vorbis_synthesis_read(&vf->vd,samples);
  141812. vf->pcm_offset+=samples;
  141813. if(bitstream)*bitstream=vf->current_link;
  141814. return(samples*bytespersample);
  141815. }else{
  141816. return(samples);
  141817. }
  141818. }
  141819. long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int length,
  141820. int *bitstream){
  141821. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141822. while(1){
  141823. if(vf->ready_state==INITSET){
  141824. float **pcm;
  141825. long samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  141826. if(samples){
  141827. if(pcm_channels)*pcm_channels=pcm;
  141828. if(samples>length)samples=length;
  141829. vorbis_synthesis_read(&vf->vd,samples);
  141830. vf->pcm_offset+=samples;
  141831. if(bitstream)*bitstream=vf->current_link;
  141832. return samples;
  141833. }
  141834. }
  141835. {
  141836. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  141837. if(ret==OV_EOF)return(0);
  141838. if(ret<=0)return(ret);
  141839. }
  141840. }
  141841. }
  141842. extern float *vorbis_window(vorbis_dsp_state *v,int W);
  141843. extern void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,
  141844. ogg_int64_t off);
  141845. static void _ov_splice(float **pcm,float **lappcm,
  141846. int n1, int n2,
  141847. int ch1, int ch2,
  141848. float *w1, float *w2){
  141849. int i,j;
  141850. float *w=w1;
  141851. int n=n1;
  141852. if(n1>n2){
  141853. n=n2;
  141854. w=w2;
  141855. }
  141856. for(j=0;j<ch1 && j<ch2;j++){
  141857. float *s=lappcm[j];
  141858. float *d=pcm[j];
  141859. for(i=0;i<n;i++){
  141860. float wd=w[i]*w[i];
  141861. float ws=1.-wd;
  141862. d[i]=d[i]*wd + s[i]*ws;
  141863. }
  141864. }
  141865. for(;j<ch2;j++){
  141866. float *d=pcm[j];
  141867. for(i=0;i<n;i++){
  141868. float wd=w[i]*w[i];
  141869. d[i]=d[i]*wd;
  141870. }
  141871. }
  141872. }
  141873. static int _ov_initset(OggVorbis_File *vf){
  141874. while(1){
  141875. if(vf->ready_state==INITSET)break;
  141876. {
  141877. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  141878. if(ret<0 && ret!=OV_HOLE)return(ret);
  141879. }
  141880. }
  141881. return 0;
  141882. }
  141883. static int _ov_initprime(OggVorbis_File *vf){
  141884. vorbis_dsp_state *vd=&vf->vd;
  141885. while(1){
  141886. if(vf->ready_state==INITSET)
  141887. if(vorbis_synthesis_pcmout(vd,NULL))break;
  141888. {
  141889. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  141890. if(ret<0 && ret!=OV_HOLE)return(ret);
  141891. }
  141892. }
  141893. return 0;
  141894. }
  141895. static void _ov_getlap(OggVorbis_File *vf,vorbis_info *vi,vorbis_dsp_state *vd,
  141896. float **lappcm,int lapsize){
  141897. int lapcount=0,i;
  141898. float **pcm;
  141899. while(lapcount<lapsize){
  141900. int samples=vorbis_synthesis_pcmout(vd,&pcm);
  141901. if(samples){
  141902. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  141903. for(i=0;i<vi->channels;i++)
  141904. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  141905. lapcount+=samples;
  141906. vorbis_synthesis_read(vd,samples);
  141907. }else{
  141908. int ret=_fetch_and_process_packet(vf,NULL,1,0); /* do *not* span */
  141909. if(ret==OV_EOF)break;
  141910. }
  141911. }
  141912. if(lapcount<lapsize){
  141913. int samples=vorbis_synthesis_lapout(&vf->vd,&pcm);
  141914. if(samples==0){
  141915. for(i=0;i<vi->channels;i++)
  141916. memset(lappcm[i]+lapcount,0,sizeof(**pcm)*lapsize-lapcount);
  141917. lapcount=lapsize;
  141918. }else{
  141919. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  141920. for(i=0;i<vi->channels;i++)
  141921. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  141922. lapcount+=samples;
  141923. }
  141924. }
  141925. }
  141926. int ov_crosslap(OggVorbis_File *vf1, OggVorbis_File *vf2){
  141927. vorbis_info *vi1,*vi2;
  141928. float **lappcm;
  141929. float **pcm;
  141930. float *w1,*w2;
  141931. int n1,n2,i,ret,hs1,hs2;
  141932. if(vf1==vf2)return(0); /* degenerate case */
  141933. if(vf1->ready_state<OPENED)return(OV_EINVAL);
  141934. if(vf2->ready_state<OPENED)return(OV_EINVAL);
  141935. ret=_ov_initset(vf1);
  141936. if(ret)return(ret);
  141937. ret=_ov_initprime(vf2);
  141938. if(ret)return(ret);
  141939. vi1=ov_info(vf1,-1);
  141940. vi2=ov_info(vf2,-1);
  141941. hs1=ov_halfrate_p(vf1);
  141942. hs2=ov_halfrate_p(vf2);
  141943. lappcm=(float**) alloca(sizeof(*lappcm)*vi1->channels);
  141944. n1=vorbis_info_blocksize(vi1,0)>>(1+hs1);
  141945. n2=vorbis_info_blocksize(vi2,0)>>(1+hs2);
  141946. w1=vorbis_window(&vf1->vd,0);
  141947. w2=vorbis_window(&vf2->vd,0);
  141948. for(i=0;i<vi1->channels;i++)
  141949. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  141950. _ov_getlap(vf1,vi1,&vf1->vd,lappcm,n1);
  141951. vorbis_synthesis_lapout(&vf2->vd,&pcm);
  141952. _analysis_output_always("pcmL",0,pcm[0],n1*2,0,0,0);
  141953. _analysis_output_always("pcmR",0,pcm[1],n1*2,0,0,0);
  141954. _ov_splice(pcm,lappcm,n1,n2,vi1->channels,vi2->channels,w1,w2);
  141955. return(0);
  141956. }
  141957. static int _ov_64_seek_lap(OggVorbis_File *vf,ogg_int64_t pos,
  141958. int (*localseek)(OggVorbis_File *,ogg_int64_t)){
  141959. vorbis_info *vi;
  141960. float **lappcm;
  141961. float **pcm;
  141962. float *w1,*w2;
  141963. int n1,n2,ch1,ch2,hs;
  141964. int i,ret;
  141965. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141966. ret=_ov_initset(vf);
  141967. if(ret)return(ret);
  141968. vi=ov_info(vf,-1);
  141969. hs=ov_halfrate_p(vf);
  141970. ch1=vi->channels;
  141971. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  141972. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  141973. persistent; even if the decode state
  141974. from this link gets dumped, this
  141975. window array continues to exist */
  141976. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  141977. for(i=0;i<ch1;i++)
  141978. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  141979. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  141980. ret=localseek(vf,pos);
  141981. if(ret)return ret;
  141982. ret=_ov_initprime(vf);
  141983. if(ret)return(ret);
  141984. vi=ov_info(vf,-1);
  141985. ch2=vi->channels;
  141986. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  141987. w2=vorbis_window(&vf->vd,0);
  141988. vorbis_synthesis_lapout(&vf->vd,&pcm);
  141989. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  141990. return(0);
  141991. }
  141992. int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  141993. return _ov_64_seek_lap(vf,pos,ov_raw_seek);
  141994. }
  141995. int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  141996. return _ov_64_seek_lap(vf,pos,ov_pcm_seek);
  141997. }
  141998. int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos){
  141999. return _ov_64_seek_lap(vf,pos,ov_pcm_seek_page);
  142000. }
  142001. static int _ov_d_seek_lap(OggVorbis_File *vf,double pos,
  142002. int (*localseek)(OggVorbis_File *,double)){
  142003. vorbis_info *vi;
  142004. float **lappcm;
  142005. float **pcm;
  142006. float *w1,*w2;
  142007. int n1,n2,ch1,ch2,hs;
  142008. int i,ret;
  142009. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142010. ret=_ov_initset(vf);
  142011. if(ret)return(ret);
  142012. vi=ov_info(vf,-1);
  142013. hs=ov_halfrate_p(vf);
  142014. ch1=vi->channels;
  142015. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  142016. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  142017. persistent; even if the decode state
  142018. from this link gets dumped, this
  142019. window array continues to exist */
  142020. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  142021. for(i=0;i<ch1;i++)
  142022. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142023. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  142024. ret=localseek(vf,pos);
  142025. if(ret)return ret;
  142026. ret=_ov_initprime(vf);
  142027. if(ret)return(ret);
  142028. vi=ov_info(vf,-1);
  142029. ch2=vi->channels;
  142030. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  142031. w2=vorbis_window(&vf->vd,0);
  142032. vorbis_synthesis_lapout(&vf->vd,&pcm);
  142033. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  142034. return(0);
  142035. }
  142036. int ov_time_seek_lap(OggVorbis_File *vf,double pos){
  142037. return _ov_d_seek_lap(vf,pos,ov_time_seek);
  142038. }
  142039. int ov_time_seek_page_lap(OggVorbis_File *vf,double pos){
  142040. return _ov_d_seek_lap(vf,pos,ov_time_seek_page);
  142041. }
  142042. #endif
  142043. /*** End of inlined file: vorbisfile.c ***/
  142044. /*** Start of inlined file: window.c ***/
  142045. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  142046. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  142047. // tasks..
  142048. #if JUCE_MSVC
  142049. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  142050. #endif
  142051. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  142052. #if JUCE_USE_OGGVORBIS
  142053. #include <stdlib.h>
  142054. #include <math.h>
  142055. static float vwin64[32] = {
  142056. 0.0009460463F, 0.0085006468F, 0.0235352254F, 0.0458950567F,
  142057. 0.0753351908F, 0.1115073077F, 0.1539457973F, 0.2020557475F,
  142058. 0.2551056759F, 0.3122276645F, 0.3724270287F, 0.4346027792F,
  142059. 0.4975789974F, 0.5601459521F, 0.6211085051F, 0.6793382689F,
  142060. 0.7338252629F, 0.7837245849F, 0.8283939355F, 0.8674186656F,
  142061. 0.9006222429F, 0.9280614787F, 0.9500073081F, 0.9669131782F,
  142062. 0.9793740220F, 0.9880792941F, 0.9937636139F, 0.9971582668F,
  142063. 0.9989462667F, 0.9997230082F, 0.9999638688F, 0.9999995525F,
  142064. };
  142065. static float vwin128[64] = {
  142066. 0.0002365472F, 0.0021280687F, 0.0059065254F, 0.0115626550F,
  142067. 0.0190823442F, 0.0284463735F, 0.0396300935F, 0.0526030430F,
  142068. 0.0673285281F, 0.0837631763F, 0.1018564887F, 0.1215504095F,
  142069. 0.1427789367F, 0.1654677960F, 0.1895342001F, 0.2148867160F,
  142070. 0.2414252576F, 0.2690412240F, 0.2976177952F, 0.3270303960F,
  142071. 0.3571473350F, 0.3878306189F, 0.4189369387F, 0.4503188188F,
  142072. 0.4818259135F, 0.5133064334F, 0.5446086751F, 0.5755826278F,
  142073. 0.6060816248F, 0.6359640047F, 0.6650947483F, 0.6933470543F,
  142074. 0.7206038179F, 0.7467589810F, 0.7717187213F, 0.7954024542F,
  142075. 0.8177436264F, 0.8386902831F, 0.8582053981F, 0.8762669622F,
  142076. 0.8928678298F, 0.9080153310F, 0.9217306608F, 0.9340480615F,
  142077. 0.9450138200F, 0.9546851041F, 0.9631286621F, 0.9704194171F,
  142078. 0.9766389810F, 0.9818741197F, 0.9862151938F, 0.9897546035F,
  142079. 0.9925852598F, 0.9947991032F, 0.9964856900F, 0.9977308602F,
  142080. 0.9986155015F, 0.9992144193F, 0.9995953200F, 0.9998179155F,
  142081. 0.9999331503F, 0.9999825563F, 0.9999977357F, 0.9999999720F,
  142082. };
  142083. static float vwin256[128] = {
  142084. 0.0000591390F, 0.0005321979F, 0.0014780301F, 0.0028960636F,
  142085. 0.0047854363F, 0.0071449926F, 0.0099732775F, 0.0132685298F,
  142086. 0.0170286741F, 0.0212513119F, 0.0259337111F, 0.0310727950F,
  142087. 0.0366651302F, 0.0427069140F, 0.0491939614F, 0.0561216907F,
  142088. 0.0634851102F, 0.0712788035F, 0.0794969160F, 0.0881331402F,
  142089. 0.0971807028F, 0.1066323515F, 0.1164803426F, 0.1267164297F,
  142090. 0.1373318534F, 0.1483173323F, 0.1596630553F, 0.1713586755F,
  142091. 0.1833933062F, 0.1957555184F, 0.2084333404F, 0.2214142599F,
  142092. 0.2346852280F, 0.2482326664F, 0.2620424757F, 0.2761000481F,
  142093. 0.2903902813F, 0.3048975959F, 0.3196059553F, 0.3344988887F,
  142094. 0.3495595160F, 0.3647705766F, 0.3801144597F, 0.3955732382F,
  142095. 0.4111287047F, 0.4267624093F, 0.4424557009F, 0.4581897696F,
  142096. 0.4739456913F, 0.4897044744F, 0.5054471075F, 0.5211546088F,
  142097. 0.5368080763F, 0.5523887395F, 0.5678780103F, 0.5832575361F,
  142098. 0.5985092508F, 0.6136154277F, 0.6285587300F, 0.6433222619F,
  142099. 0.6578896175F, 0.6722449294F, 0.6863729144F, 0.7002589187F,
  142100. 0.7138889597F, 0.7272497662F, 0.7403288154F, 0.7531143679F,
  142101. 0.7655954985F, 0.7777621249F, 0.7896050322F, 0.8011158947F,
  142102. 0.8122872932F, 0.8231127294F, 0.8335866365F, 0.8437043850F,
  142103. 0.8534622861F, 0.8628575905F, 0.8718884835F, 0.8805540765F,
  142104. 0.8888543947F, 0.8967903616F, 0.9043637797F, 0.9115773078F,
  142105. 0.9184344360F, 0.9249394562F, 0.9310974312F, 0.9369141608F,
  142106. 0.9423961446F, 0.9475505439F, 0.9523851406F, 0.9569082947F,
  142107. 0.9611289005F, 0.9650563408F, 0.9687004405F, 0.9720714191F,
  142108. 0.9751798427F, 0.9780365753F, 0.9806527301F, 0.9830396204F,
  142109. 0.9852087111F, 0.9871715701F, 0.9889398207F, 0.9905250941F,
  142110. 0.9919389832F, 0.9931929973F, 0.9942985174F, 0.9952667537F,
  142111. 0.9961087037F, 0.9968351119F, 0.9974564312F, 0.9979827858F,
  142112. 0.9984239359F, 0.9987892441F, 0.9990876435F, 0.9993276081F,
  142113. 0.9995171241F, 0.9996636648F, 0.9997741654F, 0.9998550016F,
  142114. 0.9999119692F, 0.9999502656F, 0.9999744742F, 0.9999885497F,
  142115. 0.9999958064F, 0.9999989077F, 0.9999998584F, 0.9999999983F,
  142116. };
  142117. static float vwin512[256] = {
  142118. 0.0000147849F, 0.0001330607F, 0.0003695946F, 0.0007243509F,
  142119. 0.0011972759F, 0.0017882983F, 0.0024973285F, 0.0033242588F,
  142120. 0.0042689632F, 0.0053312973F, 0.0065110982F, 0.0078081841F,
  142121. 0.0092223540F, 0.0107533880F, 0.0124010466F, 0.0141650703F,
  142122. 0.0160451800F, 0.0180410758F, 0.0201524373F, 0.0223789233F,
  142123. 0.0247201710F, 0.0271757958F, 0.0297453914F, 0.0324285286F,
  142124. 0.0352247556F, 0.0381335972F, 0.0411545545F, 0.0442871045F,
  142125. 0.0475306997F, 0.0508847676F, 0.0543487103F, 0.0579219038F,
  142126. 0.0616036982F, 0.0653934164F, 0.0692903546F, 0.0732937809F,
  142127. 0.0774029356F, 0.0816170305F, 0.0859352485F, 0.0903567428F,
  142128. 0.0948806375F, 0.0995060259F, 0.1042319712F, 0.1090575056F,
  142129. 0.1139816300F, 0.1190033137F, 0.1241214941F, 0.1293350764F,
  142130. 0.1346429333F, 0.1400439046F, 0.1455367974F, 0.1511203852F,
  142131. 0.1567934083F, 0.1625545735F, 0.1684025537F, 0.1743359881F,
  142132. 0.1803534820F, 0.1864536069F, 0.1926349000F, 0.1988958650F,
  142133. 0.2052349715F, 0.2116506555F, 0.2181413191F, 0.2247053313F,
  142134. 0.2313410275F, 0.2380467105F, 0.2448206500F, 0.2516610835F,
  142135. 0.2585662164F, 0.2655342226F, 0.2725632448F, 0.2796513950F,
  142136. 0.2867967551F, 0.2939973773F, 0.3012512852F, 0.3085564739F,
  142137. 0.3159109111F, 0.3233125375F, 0.3307592680F, 0.3382489922F,
  142138. 0.3457795756F, 0.3533488602F, 0.3609546657F, 0.3685947904F,
  142139. 0.3762670121F, 0.3839690896F, 0.3916987634F, 0.3994537572F,
  142140. 0.4072317788F, 0.4150305215F, 0.4228476653F, 0.4306808783F,
  142141. 0.4385278181F, 0.4463861329F, 0.4542534630F, 0.4621274424F,
  142142. 0.4700057001F, 0.4778858615F, 0.4857655502F, 0.4936423891F,
  142143. 0.5015140023F, 0.5093780165F, 0.5172320626F, 0.5250737772F,
  142144. 0.5329008043F, 0.5407107971F, 0.5485014192F, 0.5562703465F,
  142145. 0.5640152688F, 0.5717338914F, 0.5794239366F, 0.5870831457F,
  142146. 0.5947092801F, 0.6023001235F, 0.6098534829F, 0.6173671907F,
  142147. 0.6248391059F, 0.6322671161F, 0.6396491384F, 0.6469831217F,
  142148. 0.6542670475F, 0.6614989319F, 0.6686768267F, 0.6757988210F,
  142149. 0.6828630426F, 0.6898676592F, 0.6968108799F, 0.7036909564F,
  142150. 0.7105061843F, 0.7172549043F, 0.7239355032F, 0.7305464154F,
  142151. 0.7370861235F, 0.7435531598F, 0.7499461068F, 0.7562635986F,
  142152. 0.7625043214F, 0.7686670148F, 0.7747504721F, 0.7807535410F,
  142153. 0.7866751247F, 0.7925141825F, 0.7982697296F, 0.8039408387F,
  142154. 0.8095266395F, 0.8150263196F, 0.8204391248F, 0.8257643590F,
  142155. 0.8310013848F, 0.8361496236F, 0.8412085555F, 0.8461777194F,
  142156. 0.8510567129F, 0.8558451924F, 0.8605428730F, 0.8651495278F,
  142157. 0.8696649882F, 0.8740891432F, 0.8784219392F, 0.8826633797F,
  142158. 0.8868135244F, 0.8908724888F, 0.8948404441F, 0.8987176157F,
  142159. 0.9025042831F, 0.9062007791F, 0.9098074886F, 0.9133248482F,
  142160. 0.9167533451F, 0.9200935163F, 0.9233459472F, 0.9265112712F,
  142161. 0.9295901680F, 0.9325833632F, 0.9354916263F, 0.9383157705F,
  142162. 0.9410566504F, 0.9437151618F, 0.9462922398F, 0.9487888576F,
  142163. 0.9512060252F, 0.9535447882F, 0.9558062262F, 0.9579914516F,
  142164. 0.9601016078F, 0.9621378683F, 0.9641014348F, 0.9659935361F,
  142165. 0.9678154261F, 0.9695683830F, 0.9712537071F, 0.9728727198F,
  142166. 0.9744267618F, 0.9759171916F, 0.9773453842F, 0.9787127293F,
  142167. 0.9800206298F, 0.9812705006F, 0.9824637665F, 0.9836018613F,
  142168. 0.9846862258F, 0.9857183066F, 0.9866995544F, 0.9876314227F,
  142169. 0.9885153662F, 0.9893528393F, 0.9901452948F, 0.9908941823F,
  142170. 0.9916009470F, 0.9922670279F, 0.9928938570F, 0.9934828574F,
  142171. 0.9940354423F, 0.9945530133F, 0.9950369595F, 0.9954886562F,
  142172. 0.9959094633F, 0.9963007242F, 0.9966637649F, 0.9969998925F,
  142173. 0.9973103939F, 0.9975965351F, 0.9978595598F, 0.9981006885F,
  142174. 0.9983211172F, 0.9985220166F, 0.9987045311F, 0.9988697776F,
  142175. 0.9990188449F, 0.9991527924F, 0.9992726499F, 0.9993794157F,
  142176. 0.9994740570F, 0.9995575079F, 0.9996306699F, 0.9996944099F,
  142177. 0.9997495605F, 0.9997969190F, 0.9998372465F, 0.9998712678F,
  142178. 0.9998996704F, 0.9999231041F, 0.9999421807F, 0.9999574732F,
  142179. 0.9999695157F, 0.9999788026F, 0.9999857885F, 0.9999908879F,
  142180. 0.9999944746F, 0.9999968817F, 0.9999984010F, 0.9999992833F,
  142181. 0.9999997377F, 0.9999999317F, 0.9999999911F, 0.9999999999F,
  142182. };
  142183. static float vwin1024[512] = {
  142184. 0.0000036962F, 0.0000332659F, 0.0000924041F, 0.0001811086F,
  142185. 0.0002993761F, 0.0004472021F, 0.0006245811F, 0.0008315063F,
  142186. 0.0010679699F, 0.0013339631F, 0.0016294757F, 0.0019544965F,
  142187. 0.0023090133F, 0.0026930125F, 0.0031064797F, 0.0035493989F,
  142188. 0.0040217533F, 0.0045235250F, 0.0050546946F, 0.0056152418F,
  142189. 0.0062051451F, 0.0068243817F, 0.0074729278F, 0.0081507582F,
  142190. 0.0088578466F, 0.0095941655F, 0.0103596863F, 0.0111543789F,
  142191. 0.0119782122F, 0.0128311538F, 0.0137131701F, 0.0146242260F,
  142192. 0.0155642855F, 0.0165333111F, 0.0175312640F, 0.0185581042F,
  142193. 0.0196137903F, 0.0206982797F, 0.0218115284F, 0.0229534910F,
  142194. 0.0241241208F, 0.0253233698F, 0.0265511886F, 0.0278075263F,
  142195. 0.0290923308F, 0.0304055484F, 0.0317471241F, 0.0331170013F,
  142196. 0.0345151222F, 0.0359414274F, 0.0373958560F, 0.0388783456F,
  142197. 0.0403888325F, 0.0419272511F, 0.0434935347F, 0.0450876148F,
  142198. 0.0467094213F, 0.0483588828F, 0.0500359261F, 0.0517404765F,
  142199. 0.0534724575F, 0.0552317913F, 0.0570183983F, 0.0588321971F,
  142200. 0.0606731048F, 0.0625410369F, 0.0644359070F, 0.0663576272F,
  142201. 0.0683061077F, 0.0702812571F, 0.0722829821F, 0.0743111878F,
  142202. 0.0763657775F, 0.0784466526F, 0.0805537129F, 0.0826868561F,
  142203. 0.0848459782F, 0.0870309736F, 0.0892417345F, 0.0914781514F,
  142204. 0.0937401128F, 0.0960275056F, 0.0983402145F, 0.1006781223F,
  142205. 0.1030411101F, 0.1054290568F, 0.1078418397F, 0.1102793336F,
  142206. 0.1127414119F, 0.1152279457F, 0.1177388042F, 0.1202738544F,
  142207. 0.1228329618F, 0.1254159892F, 0.1280227980F, 0.1306532471F,
  142208. 0.1333071937F, 0.1359844927F, 0.1386849970F, 0.1414085575F,
  142209. 0.1441550230F, 0.1469242403F, 0.1497160539F, 0.1525303063F,
  142210. 0.1553668381F, 0.1582254875F, 0.1611060909F, 0.1640084822F,
  142211. 0.1669324936F, 0.1698779549F, 0.1728446939F, 0.1758325362F,
  142212. 0.1788413055F, 0.1818708232F, 0.1849209084F, 0.1879913785F,
  142213. 0.1910820485F, 0.1941927312F, 0.1973232376F, 0.2004733764F,
  142214. 0.2036429541F, 0.2068317752F, 0.2100396421F, 0.2132663552F,
  142215. 0.2165117125F, 0.2197755102F, 0.2230575422F, 0.2263576007F,
  142216. 0.2296754753F, 0.2330109540F, 0.2363638225F, 0.2397338646F,
  142217. 0.2431208619F, 0.2465245941F, 0.2499448389F, 0.2533813719F,
  142218. 0.2568339669F, 0.2603023956F, 0.2637864277F, 0.2672858312F,
  142219. 0.2708003718F, 0.2743298135F, 0.2778739186F, 0.2814324472F,
  142220. 0.2850051576F, 0.2885918065F, 0.2921921485F, 0.2958059366F,
  142221. 0.2994329219F, 0.3030728538F, 0.3067254799F, 0.3103905462F,
  142222. 0.3140677969F, 0.3177569747F, 0.3214578205F, 0.3251700736F,
  142223. 0.3288934718F, 0.3326277513F, 0.3363726468F, 0.3401278914F,
  142224. 0.3438932168F, 0.3476683533F, 0.3514530297F, 0.3552469734F,
  142225. 0.3590499106F, 0.3628615659F, 0.3666816630F, 0.3705099239F,
  142226. 0.3743460698F, 0.3781898204F, 0.3820408945F, 0.3858990095F,
  142227. 0.3897638820F, 0.3936352274F, 0.3975127601F, 0.4013961936F,
  142228. 0.4052852405F, 0.4091796123F, 0.4130790198F, 0.4169831732F,
  142229. 0.4208917815F, 0.4248045534F, 0.4287211965F, 0.4326414181F,
  142230. 0.4365649248F, 0.4404914225F, 0.4444206167F, 0.4483522125F,
  142231. 0.4522859146F, 0.4562214270F, 0.4601584538F, 0.4640966984F,
  142232. 0.4680358644F, 0.4719756548F, 0.4759157726F, 0.4798559209F,
  142233. 0.4837958024F, 0.4877351199F, 0.4916735765F, 0.4956108751F,
  142234. 0.4995467188F, 0.5034808109F, 0.5074128550F, 0.5113425550F,
  142235. 0.5152696149F, 0.5191937395F, 0.5231146336F, 0.5270320028F,
  142236. 0.5309455530F, 0.5348549910F, 0.5387600239F, 0.5426603597F,
  142237. 0.5465557070F, 0.5504457754F, 0.5543302752F, 0.5582089175F,
  142238. 0.5620814145F, 0.5659474793F, 0.5698068262F, 0.5736591704F,
  142239. 0.5775042283F, 0.5813417176F, 0.5851713571F, 0.5889928670F,
  142240. 0.5928059689F, 0.5966103856F, 0.6004058415F, 0.6041920626F,
  142241. 0.6079687761F, 0.6117357113F, 0.6154925986F, 0.6192391705F,
  142242. 0.6229751612F, 0.6267003064F, 0.6304143441F, 0.6341170137F,
  142243. 0.6378080569F, 0.6414872173F, 0.6451542405F, 0.6488088741F,
  142244. 0.6524508681F, 0.6560799742F, 0.6596959469F, 0.6632985424F,
  142245. 0.6668875197F, 0.6704626398F, 0.6740236662F, 0.6775703649F,
  142246. 0.6811025043F, 0.6846198554F, 0.6881221916F, 0.6916092892F,
  142247. 0.6950809269F, 0.6985368861F, 0.7019769510F, 0.7054009085F,
  142248. 0.7088085484F, 0.7121996632F, 0.7155740484F, 0.7189315023F,
  142249. 0.7222718263F, 0.7255948245F, 0.7289003043F, 0.7321880760F,
  142250. 0.7354579530F, 0.7387097518F, 0.7419432921F, 0.7451583966F,
  142251. 0.7483548915F, 0.7515326059F, 0.7546913723F, 0.7578310265F,
  142252. 0.7609514077F, 0.7640523581F, 0.7671337237F, 0.7701953535F,
  142253. 0.7732371001F, 0.7762588195F, 0.7792603711F, 0.7822416178F,
  142254. 0.7852024259F, 0.7881426654F, 0.7910622097F, 0.7939609356F,
  142255. 0.7968387237F, 0.7996954579F, 0.8025310261F, 0.8053453193F,
  142256. 0.8081382324F, 0.8109096638F, 0.8136595156F, 0.8163876936F,
  142257. 0.8190941071F, 0.8217786690F, 0.8244412960F, 0.8270819086F,
  142258. 0.8297004305F, 0.8322967896F, 0.8348709171F, 0.8374227481F,
  142259. 0.8399522213F, 0.8424592789F, 0.8449438672F, 0.8474059356F,
  142260. 0.8498454378F, 0.8522623306F, 0.8546565748F, 0.8570281348F,
  142261. 0.8593769787F, 0.8617030779F, 0.8640064080F, 0.8662869477F,
  142262. 0.8685446796F, 0.8707795899F, 0.8729916682F, 0.8751809079F,
  142263. 0.8773473059F, 0.8794908626F, 0.8816115819F, 0.8837094713F,
  142264. 0.8857845418F, 0.8878368079F, 0.8898662874F, 0.8918730019F,
  142265. 0.8938569760F, 0.8958182380F, 0.8977568194F, 0.8996727552F,
  142266. 0.9015660837F, 0.9034368465F, 0.9052850885F, 0.9071108577F,
  142267. 0.9089142057F, 0.9106951869F, 0.9124538591F, 0.9141902832F,
  142268. 0.9159045233F, 0.9175966464F, 0.9192667228F, 0.9209148257F,
  142269. 0.9225410313F, 0.9241454187F, 0.9257280701F, 0.9272890704F,
  142270. 0.9288285075F, 0.9303464720F, 0.9318430576F, 0.9333183603F,
  142271. 0.9347724792F, 0.9362055158F, 0.9376175745F, 0.9390087622F,
  142272. 0.9403791881F, 0.9417289644F, 0.9430582055F, 0.9443670283F,
  142273. 0.9456555521F, 0.9469238986F, 0.9481721917F, 0.9494005577F,
  142274. 0.9506091252F, 0.9517980248F, 0.9529673894F, 0.9541173540F,
  142275. 0.9552480557F, 0.9563596334F, 0.9574522282F, 0.9585259830F,
  142276. 0.9595810428F, 0.9606175542F, 0.9616356656F, 0.9626355274F,
  142277. 0.9636172915F, 0.9645811114F, 0.9655271425F, 0.9664555414F,
  142278. 0.9673664664F, 0.9682600774F, 0.9691365355F, 0.9699960034F,
  142279. 0.9708386448F, 0.9716646250F, 0.9724741103F, 0.9732672685F,
  142280. 0.9740442683F, 0.9748052795F, 0.9755504729F, 0.9762800205F,
  142281. 0.9769940950F, 0.9776928703F, 0.9783765210F, 0.9790452223F,
  142282. 0.9796991504F, 0.9803384823F, 0.9809633954F, 0.9815740679F,
  142283. 0.9821706784F, 0.9827534063F, 0.9833224312F, 0.9838779332F,
  142284. 0.9844200928F, 0.9849490910F, 0.9854651087F, 0.9859683274F,
  142285. 0.9864589286F, 0.9869370940F, 0.9874030054F, 0.9878568447F,
  142286. 0.9882987937F, 0.9887290343F, 0.9891477481F, 0.9895551169F,
  142287. 0.9899513220F, 0.9903365446F, 0.9907109658F, 0.9910747662F,
  142288. 0.9914281260F, 0.9917712252F, 0.9921042433F, 0.9924273593F,
  142289. 0.9927407516F, 0.9930445982F, 0.9933390763F, 0.9936243626F,
  142290. 0.9939006331F, 0.9941680631F, 0.9944268269F, 0.9946770982F,
  142291. 0.9949190498F, 0.9951528537F, 0.9953786808F, 0.9955967011F,
  142292. 0.9958070836F, 0.9960099963F, 0.9962056061F, 0.9963940787F,
  142293. 0.9965755786F, 0.9967502693F, 0.9969183129F, 0.9970798704F,
  142294. 0.9972351013F, 0.9973841640F, 0.9975272151F, 0.9976644103F,
  142295. 0.9977959036F, 0.9979218476F, 0.9980423932F, 0.9981576901F,
  142296. 0.9982678862F, 0.9983731278F, 0.9984735596F, 0.9985693247F,
  142297. 0.9986605645F, 0.9987474186F, 0.9988300248F, 0.9989085193F,
  142298. 0.9989830364F, 0.9990537085F, 0.9991206662F, 0.9991840382F,
  142299. 0.9992439513F, 0.9993005303F, 0.9993538982F, 0.9994041757F,
  142300. 0.9994514817F, 0.9994959330F, 0.9995376444F, 0.9995767286F,
  142301. 0.9996132960F, 0.9996474550F, 0.9996793121F, 0.9997089710F,
  142302. 0.9997365339F, 0.9997621003F, 0.9997857677F, 0.9998076311F,
  142303. 0.9998277836F, 0.9998463156F, 0.9998633155F, 0.9998788692F,
  142304. 0.9998930603F, 0.9999059701F, 0.9999176774F, 0.9999282586F,
  142305. 0.9999377880F, 0.9999463370F, 0.9999539749F, 0.9999607685F,
  142306. 0.9999667820F, 0.9999720773F, 0.9999767136F, 0.9999807479F,
  142307. 0.9999842344F, 0.9999872249F, 0.9999897688F, 0.9999919127F,
  142308. 0.9999937009F, 0.9999951749F, 0.9999963738F, 0.9999973342F,
  142309. 0.9999980900F, 0.9999986724F, 0.9999991103F, 0.9999994297F,
  142310. 0.9999996543F, 0.9999998049F, 0.9999999000F, 0.9999999552F,
  142311. 0.9999999836F, 0.9999999957F, 0.9999999994F, 1.0000000000F,
  142312. };
  142313. static float vwin2048[1024] = {
  142314. 0.0000009241F, 0.0000083165F, 0.0000231014F, 0.0000452785F,
  142315. 0.0000748476F, 0.0001118085F, 0.0001561608F, 0.0002079041F,
  142316. 0.0002670379F, 0.0003335617F, 0.0004074748F, 0.0004887765F,
  142317. 0.0005774661F, 0.0006735427F, 0.0007770054F, 0.0008878533F,
  142318. 0.0010060853F, 0.0011317002F, 0.0012646969F, 0.0014050742F,
  142319. 0.0015528307F, 0.0017079650F, 0.0018704756F, 0.0020403610F,
  142320. 0.0022176196F, 0.0024022497F, 0.0025942495F, 0.0027936173F,
  142321. 0.0030003511F, 0.0032144490F, 0.0034359088F, 0.0036647286F,
  142322. 0.0039009061F, 0.0041444391F, 0.0043953253F, 0.0046535621F,
  142323. 0.0049191472F, 0.0051920781F, 0.0054723520F, 0.0057599664F,
  142324. 0.0060549184F, 0.0063572052F, 0.0066668239F, 0.0069837715F,
  142325. 0.0073080449F, 0.0076396410F, 0.0079785566F, 0.0083247884F,
  142326. 0.0086783330F, 0.0090391871F, 0.0094073470F, 0.0097828092F,
  142327. 0.0101655700F, 0.0105556258F, 0.0109529726F, 0.0113576065F,
  142328. 0.0117695237F, 0.0121887200F, 0.0126151913F, 0.0130489335F,
  142329. 0.0134899422F, 0.0139382130F, 0.0143937415F, 0.0148565233F,
  142330. 0.0153265536F, 0.0158038279F, 0.0162883413F, 0.0167800889F,
  142331. 0.0172790660F, 0.0177852675F, 0.0182986882F, 0.0188193231F,
  142332. 0.0193471668F, 0.0198822141F, 0.0204244594F, 0.0209738974F,
  142333. 0.0215305225F, 0.0220943289F, 0.0226653109F, 0.0232434627F,
  142334. 0.0238287784F, 0.0244212519F, 0.0250208772F, 0.0256276481F,
  142335. 0.0262415582F, 0.0268626014F, 0.0274907711F, 0.0281260608F,
  142336. 0.0287684638F, 0.0294179736F, 0.0300745833F, 0.0307382859F,
  142337. 0.0314090747F, 0.0320869424F, 0.0327718819F, 0.0334638860F,
  142338. 0.0341629474F, 0.0348690586F, 0.0355822122F, 0.0363024004F,
  142339. 0.0370296157F, 0.0377638502F, 0.0385050960F, 0.0392533451F,
  142340. 0.0400085896F, 0.0407708211F, 0.0415400315F, 0.0423162123F,
  142341. 0.0430993552F, 0.0438894515F, 0.0446864926F, 0.0454904698F,
  142342. 0.0463013742F, 0.0471191969F, 0.0479439288F, 0.0487755607F,
  142343. 0.0496140836F, 0.0504594879F, 0.0513117642F, 0.0521709031F,
  142344. 0.0530368949F, 0.0539097297F, 0.0547893979F, 0.0556758894F,
  142345. 0.0565691941F, 0.0574693019F, 0.0583762026F, 0.0592898858F,
  142346. 0.0602103410F, 0.0611375576F, 0.0620715250F, 0.0630122324F,
  142347. 0.0639596688F, 0.0649138234F, 0.0658746848F, 0.0668422421F,
  142348. 0.0678164838F, 0.0687973985F, 0.0697849746F, 0.0707792005F,
  142349. 0.0717800645F, 0.0727875547F, 0.0738016591F, 0.0748223656F,
  142350. 0.0758496620F, 0.0768835359F, 0.0779239751F, 0.0789709668F,
  142351. 0.0800244985F, 0.0810845574F, 0.0821511306F, 0.0832242052F,
  142352. 0.0843037679F, 0.0853898056F, 0.0864823050F, 0.0875812525F,
  142353. 0.0886866347F, 0.0897984378F, 0.0909166480F, 0.0920412513F,
  142354. 0.0931722338F, 0.0943095813F, 0.0954532795F, 0.0966033140F,
  142355. 0.0977596702F, 0.0989223336F, 0.1000912894F, 0.1012665227F,
  142356. 0.1024480185F, 0.1036357616F, 0.1048297369F, 0.1060299290F,
  142357. 0.1072363224F, 0.1084489014F, 0.1096676504F, 0.1108925534F,
  142358. 0.1121235946F, 0.1133607577F, 0.1146040267F, 0.1158533850F,
  142359. 0.1171088163F, 0.1183703040F, 0.1196378312F, 0.1209113812F,
  142360. 0.1221909370F, 0.1234764815F, 0.1247679974F, 0.1260654674F,
  142361. 0.1273688740F, 0.1286781995F, 0.1299934263F, 0.1313145365F,
  142362. 0.1326415121F, 0.1339743349F, 0.1353129866F, 0.1366574490F,
  142363. 0.1380077035F, 0.1393637315F, 0.1407255141F, 0.1420930325F,
  142364. 0.1434662677F, 0.1448452004F, 0.1462298115F, 0.1476200814F,
  142365. 0.1490159906F, 0.1504175195F, 0.1518246482F, 0.1532373569F,
  142366. 0.1546556253F, 0.1560794333F, 0.1575087606F, 0.1589435866F,
  142367. 0.1603838909F, 0.1618296526F, 0.1632808509F, 0.1647374648F,
  142368. 0.1661994731F, 0.1676668546F, 0.1691395880F, 0.1706176516F,
  142369. 0.1721010238F, 0.1735896829F, 0.1750836068F, 0.1765827736F,
  142370. 0.1780871610F, 0.1795967468F, 0.1811115084F, 0.1826314234F,
  142371. 0.1841564689F, 0.1856866221F, 0.1872218600F, 0.1887621595F,
  142372. 0.1903074974F, 0.1918578503F, 0.1934131947F, 0.1949735068F,
  142373. 0.1965387630F, 0.1981089393F, 0.1996840117F, 0.2012639560F,
  142374. 0.2028487479F, 0.2044383630F, 0.2060327766F, 0.2076319642F,
  142375. 0.2092359007F, 0.2108445614F, 0.2124579211F, 0.2140759545F,
  142376. 0.2156986364F, 0.2173259411F, 0.2189578432F, 0.2205943168F,
  142377. 0.2222353361F, 0.2238808751F, 0.2255309076F, 0.2271854073F,
  142378. 0.2288443480F, 0.2305077030F, 0.2321754457F, 0.2338475493F,
  142379. 0.2355239869F, 0.2372047315F, 0.2388897560F, 0.2405790329F,
  142380. 0.2422725350F, 0.2439702347F, 0.2456721043F, 0.2473781159F,
  142381. 0.2490882418F, 0.2508024539F, 0.2525207240F, 0.2542430237F,
  142382. 0.2559693248F, 0.2576995986F, 0.2594338166F, 0.2611719498F,
  142383. 0.2629139695F, 0.2646598466F, 0.2664095520F, 0.2681630564F,
  142384. 0.2699203304F, 0.2716813445F, 0.2734460691F, 0.2752144744F,
  142385. 0.2769865307F, 0.2787622079F, 0.2805414760F, 0.2823243047F,
  142386. 0.2841106637F, 0.2859005227F, 0.2876938509F, 0.2894906179F,
  142387. 0.2912907928F, 0.2930943447F, 0.2949012426F, 0.2967114554F,
  142388. 0.2985249520F, 0.3003417009F, 0.3021616708F, 0.3039848301F,
  142389. 0.3058111471F, 0.3076405901F, 0.3094731273F, 0.3113087266F,
  142390. 0.3131473560F, 0.3149889833F, 0.3168335762F, 0.3186811024F,
  142391. 0.3205315294F, 0.3223848245F, 0.3242409552F, 0.3260998886F,
  142392. 0.3279615918F, 0.3298260319F, 0.3316931758F, 0.3335629903F,
  142393. 0.3354354423F, 0.3373104982F, 0.3391881247F, 0.3410682882F,
  142394. 0.3429509551F, 0.3448360917F, 0.3467236642F, 0.3486136387F,
  142395. 0.3505059811F, 0.3524006575F, 0.3542976336F, 0.3561968753F,
  142396. 0.3580983482F, 0.3600020179F, 0.3619078499F, 0.3638158096F,
  142397. 0.3657258625F, 0.3676379737F, 0.3695521086F, 0.3714682321F,
  142398. 0.3733863094F, 0.3753063055F, 0.3772281852F, 0.3791519134F,
  142399. 0.3810774548F, 0.3830047742F, 0.3849338362F, 0.3868646053F,
  142400. 0.3887970459F, 0.3907311227F, 0.3926667998F, 0.3946040417F,
  142401. 0.3965428125F, 0.3984830765F, 0.4004247978F, 0.4023679403F,
  142402. 0.4043124683F, 0.4062583455F, 0.4082055359F, 0.4101540034F,
  142403. 0.4121037117F, 0.4140546246F, 0.4160067058F, 0.4179599190F,
  142404. 0.4199142277F, 0.4218695956F, 0.4238259861F, 0.4257833627F,
  142405. 0.4277416888F, 0.4297009279F, 0.4316610433F, 0.4336219983F,
  142406. 0.4355837562F, 0.4375462803F, 0.4395095337F, 0.4414734797F,
  142407. 0.4434380815F, 0.4454033021F, 0.4473691046F, 0.4493354521F,
  142408. 0.4513023078F, 0.4532696345F, 0.4552373954F, 0.4572055533F,
  142409. 0.4591740713F, 0.4611429123F, 0.4631120393F, 0.4650814151F,
  142410. 0.4670510028F, 0.4690207650F, 0.4709906649F, 0.4729606651F,
  142411. 0.4749307287F, 0.4769008185F, 0.4788708972F, 0.4808409279F,
  142412. 0.4828108732F, 0.4847806962F, 0.4867503597F, 0.4887198264F,
  142413. 0.4906890593F, 0.4926580213F, 0.4946266753F, 0.4965949840F,
  142414. 0.4985629105F, 0.5005304176F, 0.5024974683F, 0.5044640255F,
  142415. 0.5064300522F, 0.5083955114F, 0.5103603659F, 0.5123245790F,
  142416. 0.5142881136F, 0.5162509328F, 0.5182129997F, 0.5201742774F,
  142417. 0.5221347290F, 0.5240943178F, 0.5260530070F, 0.5280107598F,
  142418. 0.5299675395F, 0.5319233095F, 0.5338780330F, 0.5358316736F,
  142419. 0.5377841946F, 0.5397355596F, 0.5416857320F, 0.5436346755F,
  142420. 0.5455823538F, 0.5475287304F, 0.5494737691F, 0.5514174337F,
  142421. 0.5533596881F, 0.5553004962F, 0.5572398218F, 0.5591776291F,
  142422. 0.5611138821F, 0.5630485449F, 0.5649815818F, 0.5669129570F,
  142423. 0.5688426349F, 0.5707705799F, 0.5726967564F, 0.5746211290F,
  142424. 0.5765436624F, 0.5784643212F, 0.5803830702F, 0.5822998743F,
  142425. 0.5842146984F, 0.5861275076F, 0.5880382669F, 0.5899469416F,
  142426. 0.5918534968F, 0.5937578981F, 0.5956601107F, 0.5975601004F,
  142427. 0.5994578326F, 0.6013532732F, 0.6032463880F, 0.6051371429F,
  142428. 0.6070255039F, 0.6089114372F, 0.6107949090F, 0.6126758856F,
  142429. 0.6145543334F, 0.6164302191F, 0.6183035092F, 0.6201741706F,
  142430. 0.6220421700F, 0.6239074745F, 0.6257700513F, 0.6276298674F,
  142431. 0.6294868903F, 0.6313410873F, 0.6331924262F, 0.6350408745F,
  142432. 0.6368864001F, 0.6387289710F, 0.6405685552F, 0.6424051209F,
  142433. 0.6442386364F, 0.6460690702F, 0.6478963910F, 0.6497205673F,
  142434. 0.6515415682F, 0.6533593625F, 0.6551739194F, 0.6569852082F,
  142435. 0.6587931984F, 0.6605978593F, 0.6623991609F, 0.6641970728F,
  142436. 0.6659915652F, 0.6677826081F, 0.6695701718F, 0.6713542268F,
  142437. 0.6731347437F, 0.6749116932F, 0.6766850461F, 0.6784547736F,
  142438. 0.6802208469F, 0.6819832374F, 0.6837419164F, 0.6854968559F,
  142439. 0.6872480275F, 0.6889954034F, 0.6907389556F, 0.6924786566F,
  142440. 0.6942144788F, 0.6959463950F, 0.6976743780F, 0.6993984008F,
  142441. 0.7011184365F, 0.7028344587F, 0.7045464407F, 0.7062543564F,
  142442. 0.7079581796F, 0.7096578844F, 0.7113534450F, 0.7130448359F,
  142443. 0.7147320316F, 0.7164150070F, 0.7180937371F, 0.7197681970F,
  142444. 0.7214383620F, 0.7231042077F, 0.7247657098F, 0.7264228443F,
  142445. 0.7280755871F, 0.7297239147F, 0.7313678035F, 0.7330072301F,
  142446. 0.7346421715F, 0.7362726046F, 0.7378985069F, 0.7395198556F,
  142447. 0.7411366285F, 0.7427488034F, 0.7443563584F, 0.7459592717F,
  142448. 0.7475575218F, 0.7491510873F, 0.7507399471F, 0.7523240803F,
  142449. 0.7539034661F, 0.7554780839F, 0.7570479136F, 0.7586129349F,
  142450. 0.7601731279F, 0.7617284730F, 0.7632789506F, 0.7648245416F,
  142451. 0.7663652267F, 0.7679009872F, 0.7694318044F, 0.7709576599F,
  142452. 0.7724785354F, 0.7739944130F, 0.7755052749F, 0.7770111035F,
  142453. 0.7785118815F, 0.7800075916F, 0.7814982170F, 0.7829837410F,
  142454. 0.7844641472F, 0.7859394191F, 0.7874095408F, 0.7888744965F,
  142455. 0.7903342706F, 0.7917888476F, 0.7932382124F, 0.7946823501F,
  142456. 0.7961212460F, 0.7975548855F, 0.7989832544F, 0.8004063386F,
  142457. 0.8018241244F, 0.8032365981F, 0.8046437463F, 0.8060455560F,
  142458. 0.8074420141F, 0.8088331080F, 0.8102188253F, 0.8115991536F,
  142459. 0.8129740810F, 0.8143435957F, 0.8157076861F, 0.8170663409F,
  142460. 0.8184195489F, 0.8197672994F, 0.8211095817F, 0.8224463853F,
  142461. 0.8237777001F, 0.8251035161F, 0.8264238235F, 0.8277386129F,
  142462. 0.8290478750F, 0.8303516008F, 0.8316497814F, 0.8329424083F,
  142463. 0.8342294731F, 0.8355109677F, 0.8367868841F, 0.8380572148F,
  142464. 0.8393219523F, 0.8405810893F, 0.8418346190F, 0.8430825345F,
  142465. 0.8443248294F, 0.8455614974F, 0.8467925323F, 0.8480179285F,
  142466. 0.8492376802F, 0.8504517822F, 0.8516602292F, 0.8528630164F,
  142467. 0.8540601391F, 0.8552515928F, 0.8564373733F, 0.8576174766F,
  142468. 0.8587918990F, 0.8599606368F, 0.8611236868F, 0.8622810460F,
  142469. 0.8634327113F, 0.8645786802F, 0.8657189504F, 0.8668535195F,
  142470. 0.8679823857F, 0.8691055472F, 0.8702230025F, 0.8713347503F,
  142471. 0.8724407896F, 0.8735411194F, 0.8746357394F, 0.8757246489F,
  142472. 0.8768078479F, 0.8778853364F, 0.8789571146F, 0.8800231832F,
  142473. 0.8810835427F, 0.8821381942F, 0.8831871387F, 0.8842303777F,
  142474. 0.8852679127F, 0.8862997456F, 0.8873258784F, 0.8883463132F,
  142475. 0.8893610527F, 0.8903700994F, 0.8913734562F, 0.8923711263F,
  142476. 0.8933631129F, 0.8943494196F, 0.8953300500F, 0.8963050083F,
  142477. 0.8972742985F, 0.8982379249F, 0.8991958922F, 0.9001482052F,
  142478. 0.9010948688F, 0.9020358883F, 0.9029712690F, 0.9039010165F,
  142479. 0.9048251367F, 0.9057436357F, 0.9066565195F, 0.9075637946F,
  142480. 0.9084654678F, 0.9093615456F, 0.9102520353F, 0.9111369440F,
  142481. 0.9120162792F, 0.9128900484F, 0.9137582595F, 0.9146209204F,
  142482. 0.9154780394F, 0.9163296248F, 0.9171756853F, 0.9180162296F,
  142483. 0.9188512667F, 0.9196808057F, 0.9205048559F, 0.9213234270F,
  142484. 0.9221365285F, 0.9229441704F, 0.9237463629F, 0.9245431160F,
  142485. 0.9253344404F, 0.9261203465F, 0.9269008453F, 0.9276759477F,
  142486. 0.9284456648F, 0.9292100080F, 0.9299689889F, 0.9307226190F,
  142487. 0.9314709103F, 0.9322138747F, 0.9329515245F, 0.9336838721F,
  142488. 0.9344109300F, 0.9351327108F, 0.9358492275F, 0.9365604931F,
  142489. 0.9372665208F, 0.9379673239F, 0.9386629160F, 0.9393533107F,
  142490. 0.9400385220F, 0.9407185637F, 0.9413934501F, 0.9420631954F,
  142491. 0.9427278141F, 0.9433873208F, 0.9440417304F, 0.9446910576F,
  142492. 0.9453353176F, 0.9459745255F, 0.9466086968F, 0.9472378469F,
  142493. 0.9478619915F, 0.9484811463F, 0.9490953274F, 0.9497045506F,
  142494. 0.9503088323F, 0.9509081888F, 0.9515026365F, 0.9520921921F,
  142495. 0.9526768723F, 0.9532566940F, 0.9538316742F, 0.9544018300F,
  142496. 0.9549671786F, 0.9555277375F, 0.9560835241F, 0.9566345562F,
  142497. 0.9571808513F, 0.9577224275F, 0.9582593027F, 0.9587914949F,
  142498. 0.9593190225F, 0.9598419038F, 0.9603601571F, 0.9608738012F,
  142499. 0.9613828546F, 0.9618873361F, 0.9623872646F, 0.9628826591F,
  142500. 0.9633735388F, 0.9638599227F, 0.9643418303F, 0.9648192808F,
  142501. 0.9652922939F, 0.9657608890F, 0.9662250860F, 0.9666849046F,
  142502. 0.9671403646F, 0.9675914861F, 0.9680382891F, 0.9684807937F,
  142503. 0.9689190202F, 0.9693529890F, 0.9697827203F, 0.9702082347F,
  142504. 0.9706295529F, 0.9710466953F, 0.9714596828F, 0.9718685362F,
  142505. 0.9722732762F, 0.9726739240F, 0.9730705005F, 0.9734630267F,
  142506. 0.9738515239F, 0.9742360134F, 0.9746165163F, 0.9749930540F,
  142507. 0.9753656481F, 0.9757343198F, 0.9760990909F, 0.9764599829F,
  142508. 0.9768170175F, 0.9771702164F, 0.9775196013F, 0.9778651941F,
  142509. 0.9782070167F, 0.9785450909F, 0.9788794388F, 0.9792100824F,
  142510. 0.9795370437F, 0.9798603449F, 0.9801800080F, 0.9804960554F,
  142511. 0.9808085092F, 0.9811173916F, 0.9814227251F, 0.9817245318F,
  142512. 0.9820228343F, 0.9823176549F, 0.9826090160F, 0.9828969402F,
  142513. 0.9831814498F, 0.9834625674F, 0.9837403156F, 0.9840147169F,
  142514. 0.9842857939F, 0.9845535692F, 0.9848180654F, 0.9850793052F,
  142515. 0.9853373113F, 0.9855921062F, 0.9858437127F, 0.9860921535F,
  142516. 0.9863374512F, 0.9865796287F, 0.9868187085F, 0.9870547136F,
  142517. 0.9872876664F, 0.9875175899F, 0.9877445067F, 0.9879684396F,
  142518. 0.9881894112F, 0.9884074444F, 0.9886225619F, 0.9888347863F,
  142519. 0.9890441404F, 0.9892506468F, 0.9894543284F, 0.9896552077F,
  142520. 0.9898533074F, 0.9900486502F, 0.9902412587F, 0.9904311555F,
  142521. 0.9906183633F, 0.9908029045F, 0.9909848019F, 0.9911640779F,
  142522. 0.9913407550F, 0.9915148557F, 0.9916864025F, 0.9918554179F,
  142523. 0.9920219241F, 0.9921859437F, 0.9923474989F, 0.9925066120F,
  142524. 0.9926633054F, 0.9928176012F, 0.9929695218F, 0.9931190891F,
  142525. 0.9932663254F, 0.9934112527F, 0.9935538932F, 0.9936942686F,
  142526. 0.9938324012F, 0.9939683126F, 0.9941020248F, 0.9942335597F,
  142527. 0.9943629388F, 0.9944901841F, 0.9946153170F, 0.9947383593F,
  142528. 0.9948593325F, 0.9949782579F, 0.9950951572F, 0.9952100516F,
  142529. 0.9953229625F, 0.9954339111F, 0.9955429186F, 0.9956500062F,
  142530. 0.9957551948F, 0.9958585056F, 0.9959599593F, 0.9960595769F,
  142531. 0.9961573792F, 0.9962533869F, 0.9963476206F, 0.9964401009F,
  142532. 0.9965308483F, 0.9966198833F, 0.9967072261F, 0.9967928971F,
  142533. 0.9968769164F, 0.9969593041F, 0.9970400804F, 0.9971192651F,
  142534. 0.9971968781F, 0.9972729391F, 0.9973474680F, 0.9974204842F,
  142535. 0.9974920074F, 0.9975620569F, 0.9976306521F, 0.9976978122F,
  142536. 0.9977635565F, 0.9978279039F, 0.9978908736F, 0.9979524842F,
  142537. 0.9980127547F, 0.9980717037F, 0.9981293499F, 0.9981857116F,
  142538. 0.9982408073F, 0.9982946554F, 0.9983472739F, 0.9983986810F,
  142539. 0.9984488947F, 0.9984979328F, 0.9985458132F, 0.9985925534F,
  142540. 0.9986381711F, 0.9986826838F, 0.9987261086F, 0.9987684630F,
  142541. 0.9988097640F, 0.9988500286F, 0.9988892738F, 0.9989275163F,
  142542. 0.9989647727F, 0.9990010597F, 0.9990363938F, 0.9990707911F,
  142543. 0.9991042679F, 0.9991368404F, 0.9991685244F, 0.9991993358F,
  142544. 0.9992292905F, 0.9992584038F, 0.9992866914F, 0.9993141686F,
  142545. 0.9993408506F, 0.9993667526F, 0.9993918895F, 0.9994162761F,
  142546. 0.9994399273F, 0.9994628576F, 0.9994850815F, 0.9995066133F,
  142547. 0.9995274672F, 0.9995476574F, 0.9995671978F, 0.9995861021F,
  142548. 0.9996043841F, 0.9996220573F, 0.9996391352F, 0.9996556310F,
  142549. 0.9996715579F, 0.9996869288F, 0.9997017568F, 0.9997160543F,
  142550. 0.9997298342F, 0.9997431088F, 0.9997558905F, 0.9997681914F,
  142551. 0.9997800236F, 0.9997913990F, 0.9998023292F, 0.9998128261F,
  142552. 0.9998229009F, 0.9998325650F, 0.9998418296F, 0.9998507058F,
  142553. 0.9998592044F, 0.9998673362F, 0.9998751117F, 0.9998825415F,
  142554. 0.9998896358F, 0.9998964047F, 0.9999028584F, 0.9999090066F,
  142555. 0.9999148590F, 0.9999204253F, 0.9999257148F, 0.9999307368F,
  142556. 0.9999355003F, 0.9999400144F, 0.9999442878F, 0.9999483293F,
  142557. 0.9999521472F, 0.9999557499F, 0.9999591457F, 0.9999623426F,
  142558. 0.9999653483F, 0.9999681708F, 0.9999708175F, 0.9999732959F,
  142559. 0.9999756132F, 0.9999777765F, 0.9999797928F, 0.9999816688F,
  142560. 0.9999834113F, 0.9999850266F, 0.9999865211F, 0.9999879009F,
  142561. 0.9999891721F, 0.9999903405F, 0.9999914118F, 0.9999923914F,
  142562. 0.9999932849F, 0.9999940972F, 0.9999948336F, 0.9999954989F,
  142563. 0.9999960978F, 0.9999966349F, 0.9999971146F, 0.9999975411F,
  142564. 0.9999979185F, 0.9999982507F, 0.9999985414F, 0.9999987944F,
  142565. 0.9999990129F, 0.9999992003F, 0.9999993596F, 0.9999994939F,
  142566. 0.9999996059F, 0.9999996981F, 0.9999997732F, 0.9999998333F,
  142567. 0.9999998805F, 0.9999999170F, 0.9999999444F, 0.9999999643F,
  142568. 0.9999999784F, 0.9999999878F, 0.9999999937F, 0.9999999972F,
  142569. 0.9999999990F, 0.9999999997F, 1.0000000000F, 1.0000000000F,
  142570. };
  142571. static float vwin4096[2048] = {
  142572. 0.0000002310F, 0.0000020791F, 0.0000057754F, 0.0000113197F,
  142573. 0.0000187121F, 0.0000279526F, 0.0000390412F, 0.0000519777F,
  142574. 0.0000667623F, 0.0000833949F, 0.0001018753F, 0.0001222036F,
  142575. 0.0001443798F, 0.0001684037F, 0.0001942754F, 0.0002219947F,
  142576. 0.0002515616F, 0.0002829761F, 0.0003162380F, 0.0003513472F,
  142577. 0.0003883038F, 0.0004271076F, 0.0004677584F, 0.0005102563F,
  142578. 0.0005546011F, 0.0006007928F, 0.0006488311F, 0.0006987160F,
  142579. 0.0007504474F, 0.0008040251F, 0.0008594490F, 0.0009167191F,
  142580. 0.0009758351F, 0.0010367969F, 0.0010996044F, 0.0011642574F,
  142581. 0.0012307558F, 0.0012990994F, 0.0013692880F, 0.0014413216F,
  142582. 0.0015151998F, 0.0015909226F, 0.0016684898F, 0.0017479011F,
  142583. 0.0018291565F, 0.0019122556F, 0.0019971983F, 0.0020839845F,
  142584. 0.0021726138F, 0.0022630861F, 0.0023554012F, 0.0024495588F,
  142585. 0.0025455588F, 0.0026434008F, 0.0027430847F, 0.0028446103F,
  142586. 0.0029479772F, 0.0030531853F, 0.0031602342F, 0.0032691238F,
  142587. 0.0033798538F, 0.0034924239F, 0.0036068338F, 0.0037230833F,
  142588. 0.0038411721F, 0.0039610999F, 0.0040828664F, 0.0042064714F,
  142589. 0.0043319145F, 0.0044591954F, 0.0045883139F, 0.0047192696F,
  142590. 0.0048520622F, 0.0049866914F, 0.0051231569F, 0.0052614583F,
  142591. 0.0054015953F, 0.0055435676F, 0.0056873748F, 0.0058330166F,
  142592. 0.0059804926F, 0.0061298026F, 0.0062809460F, 0.0064339226F,
  142593. 0.0065887320F, 0.0067453738F, 0.0069038476F, 0.0070641531F,
  142594. 0.0072262899F, 0.0073902575F, 0.0075560556F, 0.0077236838F,
  142595. 0.0078931417F, 0.0080644288F, 0.0082375447F, 0.0084124891F,
  142596. 0.0085892615F, 0.0087678614F, 0.0089482885F, 0.0091305422F,
  142597. 0.0093146223F, 0.0095005281F, 0.0096882592F, 0.0098778153F,
  142598. 0.0100691958F, 0.0102624002F, 0.0104574281F, 0.0106542791F,
  142599. 0.0108529525F, 0.0110534480F, 0.0112557651F, 0.0114599032F,
  142600. 0.0116658618F, 0.0118736405F, 0.0120832387F, 0.0122946560F,
  142601. 0.0125078917F, 0.0127229454F, 0.0129398166F, 0.0131585046F,
  142602. 0.0133790090F, 0.0136013292F, 0.0138254647F, 0.0140514149F,
  142603. 0.0142791792F, 0.0145087572F, 0.0147401481F, 0.0149733515F,
  142604. 0.0152083667F, 0.0154451932F, 0.0156838304F, 0.0159242777F,
  142605. 0.0161665345F, 0.0164106001F, 0.0166564741F, 0.0169041557F,
  142606. 0.0171536443F, 0.0174049393F, 0.0176580401F, 0.0179129461F,
  142607. 0.0181696565F, 0.0184281708F, 0.0186884883F, 0.0189506084F,
  142608. 0.0192145303F, 0.0194802535F, 0.0197477772F, 0.0200171008F,
  142609. 0.0202882236F, 0.0205611449F, 0.0208358639F, 0.0211123801F,
  142610. 0.0213906927F, 0.0216708011F, 0.0219527043F, 0.0222364019F,
  142611. 0.0225218930F, 0.0228091769F, 0.0230982529F, 0.0233891203F,
  142612. 0.0236817782F, 0.0239762259F, 0.0242724628F, 0.0245704880F,
  142613. 0.0248703007F, 0.0251719002F, 0.0254752858F, 0.0257804565F,
  142614. 0.0260874117F, 0.0263961506F, 0.0267066722F, 0.0270189760F,
  142615. 0.0273330609F, 0.0276489263F, 0.0279665712F, 0.0282859949F,
  142616. 0.0286071966F, 0.0289301753F, 0.0292549303F, 0.0295814607F,
  142617. 0.0299097656F, 0.0302398442F, 0.0305716957F, 0.0309053191F,
  142618. 0.0312407135F, 0.0315778782F, 0.0319168122F, 0.0322575145F,
  142619. 0.0325999844F, 0.0329442209F, 0.0332902231F, 0.0336379900F,
  142620. 0.0339875208F, 0.0343388146F, 0.0346918703F, 0.0350466871F,
  142621. 0.0354032640F, 0.0357616000F, 0.0361216943F, 0.0364835458F,
  142622. 0.0368471535F, 0.0372125166F, 0.0375796339F, 0.0379485046F,
  142623. 0.0383191276F, 0.0386915020F, 0.0390656267F, 0.0394415008F,
  142624. 0.0398191231F, 0.0401984927F, 0.0405796086F, 0.0409624698F,
  142625. 0.0413470751F, 0.0417334235F, 0.0421215141F, 0.0425113457F,
  142626. 0.0429029172F, 0.0432962277F, 0.0436912760F, 0.0440880610F,
  142627. 0.0444865817F, 0.0448868370F, 0.0452888257F, 0.0456925468F,
  142628. 0.0460979992F, 0.0465051816F, 0.0469140931F, 0.0473247325F,
  142629. 0.0477370986F, 0.0481511902F, 0.0485670064F, 0.0489845458F,
  142630. 0.0494038074F, 0.0498247899F, 0.0502474922F, 0.0506719131F,
  142631. 0.0510980514F, 0.0515259060F, 0.0519554756F, 0.0523867590F,
  142632. 0.0528197550F, 0.0532544624F, 0.0536908800F, 0.0541290066F,
  142633. 0.0545688408F, 0.0550103815F, 0.0554536274F, 0.0558985772F,
  142634. 0.0563452297F, 0.0567935837F, 0.0572436377F, 0.0576953907F,
  142635. 0.0581488412F, 0.0586039880F, 0.0590608297F, 0.0595193651F,
  142636. 0.0599795929F, 0.0604415117F, 0.0609051202F, 0.0613704170F,
  142637. 0.0618374009F, 0.0623060704F, 0.0627764243F, 0.0632484611F,
  142638. 0.0637221795F, 0.0641975781F, 0.0646746555F, 0.0651534104F,
  142639. 0.0656338413F, 0.0661159469F, 0.0665997257F, 0.0670851763F,
  142640. 0.0675722973F, 0.0680610873F, 0.0685515448F, 0.0690436684F,
  142641. 0.0695374567F, 0.0700329081F, 0.0705300213F, 0.0710287947F,
  142642. 0.0715292269F, 0.0720313163F, 0.0725350616F, 0.0730404612F,
  142643. 0.0735475136F, 0.0740562172F, 0.0745665707F, 0.0750785723F,
  142644. 0.0755922207F, 0.0761075143F, 0.0766244515F, 0.0771430307F,
  142645. 0.0776632505F, 0.0781851092F, 0.0787086052F, 0.0792337371F,
  142646. 0.0797605032F, 0.0802889018F, 0.0808189315F, 0.0813505905F,
  142647. 0.0818838773F, 0.0824187903F, 0.0829553277F, 0.0834934881F,
  142648. 0.0840332697F, 0.0845746708F, 0.0851176899F, 0.0856623252F,
  142649. 0.0862085751F, 0.0867564379F, 0.0873059119F, 0.0878569954F,
  142650. 0.0884096867F, 0.0889639840F, 0.0895198858F, 0.0900773902F,
  142651. 0.0906364955F, 0.0911972000F, 0.0917595019F, 0.0923233995F,
  142652. 0.0928888909F, 0.0934559745F, 0.0940246485F, 0.0945949110F,
  142653. 0.0951667604F, 0.0957401946F, 0.0963152121F, 0.0968918109F,
  142654. 0.0974699893F, 0.0980497454F, 0.0986310773F, 0.0992139832F,
  142655. 0.0997984614F, 0.1003845098F, 0.1009721267F, 0.1015613101F,
  142656. 0.1021520582F, 0.1027443692F, 0.1033382410F, 0.1039336718F,
  142657. 0.1045306597F, 0.1051292027F, 0.1057292990F, 0.1063309466F,
  142658. 0.1069341435F, 0.1075388878F, 0.1081451776F, 0.1087530108F,
  142659. 0.1093623856F, 0.1099732998F, 0.1105857516F, 0.1111997389F,
  142660. 0.1118152597F, 0.1124323121F, 0.1130508939F, 0.1136710032F,
  142661. 0.1142926379F, 0.1149157960F, 0.1155404755F, 0.1161666742F,
  142662. 0.1167943901F, 0.1174236211F, 0.1180543652F, 0.1186866202F,
  142663. 0.1193203841F, 0.1199556548F, 0.1205924300F, 0.1212307078F,
  142664. 0.1218704860F, 0.1225117624F, 0.1231545349F, 0.1237988013F,
  142665. 0.1244445596F, 0.1250918074F, 0.1257405427F, 0.1263907632F,
  142666. 0.1270424667F, 0.1276956512F, 0.1283503142F, 0.1290064537F,
  142667. 0.1296640674F, 0.1303231530F, 0.1309837084F, 0.1316457312F,
  142668. 0.1323092193F, 0.1329741703F, 0.1336405820F, 0.1343084520F,
  142669. 0.1349777782F, 0.1356485582F, 0.1363207897F, 0.1369944704F,
  142670. 0.1376695979F, 0.1383461700F, 0.1390241842F, 0.1397036384F,
  142671. 0.1403845300F, 0.1410668567F, 0.1417506162F, 0.1424358061F,
  142672. 0.1431224240F, 0.1438104674F, 0.1444999341F, 0.1451908216F,
  142673. 0.1458831274F, 0.1465768492F, 0.1472719844F, 0.1479685308F,
  142674. 0.1486664857F, 0.1493658468F, 0.1500666115F, 0.1507687775F,
  142675. 0.1514723422F, 0.1521773031F, 0.1528836577F, 0.1535914035F,
  142676. 0.1543005380F, 0.1550110587F, 0.1557229631F, 0.1564362485F,
  142677. 0.1571509124F, 0.1578669524F, 0.1585843657F, 0.1593031499F,
  142678. 0.1600233024F, 0.1607448205F, 0.1614677017F, 0.1621919433F,
  142679. 0.1629175428F, 0.1636444975F, 0.1643728047F, 0.1651024619F,
  142680. 0.1658334665F, 0.1665658156F, 0.1672995067F, 0.1680345371F,
  142681. 0.1687709041F, 0.1695086050F, 0.1702476372F, 0.1709879978F,
  142682. 0.1717296843F, 0.1724726938F, 0.1732170237F, 0.1739626711F,
  142683. 0.1747096335F, 0.1754579079F, 0.1762074916F, 0.1769583819F,
  142684. 0.1777105760F, 0.1784640710F, 0.1792188642F, 0.1799749529F,
  142685. 0.1807323340F, 0.1814910049F, 0.1822509628F, 0.1830122046F,
  142686. 0.1837747277F, 0.1845385292F, 0.1853036062F, 0.1860699558F,
  142687. 0.1868375751F, 0.1876064613F, 0.1883766114F, 0.1891480226F,
  142688. 0.1899206919F, 0.1906946164F, 0.1914697932F, 0.1922462194F,
  142689. 0.1930238919F, 0.1938028079F, 0.1945829643F, 0.1953643583F,
  142690. 0.1961469868F, 0.1969308468F, 0.1977159353F, 0.1985022494F,
  142691. 0.1992897859F, 0.2000785420F, 0.2008685145F, 0.2016597005F,
  142692. 0.2024520968F, 0.2032457005F, 0.2040405084F, 0.2048365175F,
  142693. 0.2056337247F, 0.2064321269F, 0.2072317211F, 0.2080325041F,
  142694. 0.2088344727F, 0.2096376240F, 0.2104419547F, 0.2112474618F,
  142695. 0.2120541420F, 0.2128619923F, 0.2136710094F, 0.2144811902F,
  142696. 0.2152925315F, 0.2161050301F, 0.2169186829F, 0.2177334866F,
  142697. 0.2185494381F, 0.2193665340F, 0.2201847712F, 0.2210041465F,
  142698. 0.2218246565F, 0.2226462981F, 0.2234690680F, 0.2242929629F,
  142699. 0.2251179796F, 0.2259441147F, 0.2267713650F, 0.2275997272F,
  142700. 0.2284291979F, 0.2292597739F, 0.2300914518F, 0.2309242283F,
  142701. 0.2317581001F, 0.2325930638F, 0.2334291160F, 0.2342662534F,
  142702. 0.2351044727F, 0.2359437703F, 0.2367841431F, 0.2376255875F,
  142703. 0.2384681001F, 0.2393116776F, 0.2401563165F, 0.2410020134F,
  142704. 0.2418487649F, 0.2426965675F, 0.2435454178F, 0.2443953122F,
  142705. 0.2452462474F, 0.2460982199F, 0.2469512262F, 0.2478052628F,
  142706. 0.2486603262F, 0.2495164129F, 0.2503735194F, 0.2512316421F,
  142707. 0.2520907776F, 0.2529509222F, 0.2538120726F, 0.2546742250F,
  142708. 0.2555373760F, 0.2564015219F, 0.2572666593F, 0.2581327845F,
  142709. 0.2589998939F, 0.2598679840F, 0.2607370510F, 0.2616070916F,
  142710. 0.2624781019F, 0.2633500783F, 0.2642230173F, 0.2650969152F,
  142711. 0.2659717684F, 0.2668475731F, 0.2677243257F, 0.2686020226F,
  142712. 0.2694806601F, 0.2703602344F, 0.2712407419F, 0.2721221789F,
  142713. 0.2730045417F, 0.2738878265F, 0.2747720297F, 0.2756571474F,
  142714. 0.2765431760F, 0.2774301117F, 0.2783179508F, 0.2792066895F,
  142715. 0.2800963240F, 0.2809868505F, 0.2818782654F, 0.2827705647F,
  142716. 0.2836637447F, 0.2845578016F, 0.2854527315F, 0.2863485307F,
  142717. 0.2872451953F, 0.2881427215F, 0.2890411055F, 0.2899403433F,
  142718. 0.2908404312F, 0.2917413654F, 0.2926431418F, 0.2935457567F,
  142719. 0.2944492061F, 0.2953534863F, 0.2962585932F, 0.2971645230F,
  142720. 0.2980712717F, 0.2989788356F, 0.2998872105F, 0.3007963927F,
  142721. 0.3017063781F, 0.3026171629F, 0.3035287430F, 0.3044411145F,
  142722. 0.3053542736F, 0.3062682161F, 0.3071829381F, 0.3080984356F,
  142723. 0.3090147047F, 0.3099317413F, 0.3108495414F, 0.3117681011F,
  142724. 0.3126874163F, 0.3136074830F, 0.3145282972F, 0.3154498548F,
  142725. 0.3163721517F, 0.3172951841F, 0.3182189477F, 0.3191434385F,
  142726. 0.3200686525F, 0.3209945856F, 0.3219212336F, 0.3228485927F,
  142727. 0.3237766585F, 0.3247054271F, 0.3256348943F, 0.3265650560F,
  142728. 0.3274959081F, 0.3284274465F, 0.3293596671F, 0.3302925657F,
  142729. 0.3312261382F, 0.3321603804F, 0.3330952882F, 0.3340308574F,
  142730. 0.3349670838F, 0.3359039634F, 0.3368414919F, 0.3377796651F,
  142731. 0.3387184789F, 0.3396579290F, 0.3405980113F, 0.3415387216F,
  142732. 0.3424800556F, 0.3434220091F, 0.3443645779F, 0.3453077578F,
  142733. 0.3462515446F, 0.3471959340F, 0.3481409217F, 0.3490865036F,
  142734. 0.3500326754F, 0.3509794328F, 0.3519267715F, 0.3528746873F,
  142735. 0.3538231759F, 0.3547722330F, 0.3557218544F, 0.3566720357F,
  142736. 0.3576227727F, 0.3585740610F, 0.3595258964F, 0.3604782745F,
  142737. 0.3614311910F, 0.3623846417F, 0.3633386221F, 0.3642931280F,
  142738. 0.3652481549F, 0.3662036987F, 0.3671597548F, 0.3681163191F,
  142739. 0.3690733870F, 0.3700309544F, 0.3709890167F, 0.3719475696F,
  142740. 0.3729066089F, 0.3738661299F, 0.3748261285F, 0.3757866002F,
  142741. 0.3767475406F, 0.3777089453F, 0.3786708100F, 0.3796331302F,
  142742. 0.3805959014F, 0.3815591194F, 0.3825227796F, 0.3834868777F,
  142743. 0.3844514093F, 0.3854163698F, 0.3863817549F, 0.3873475601F,
  142744. 0.3883137810F, 0.3892804131F, 0.3902474521F, 0.3912148933F,
  142745. 0.3921827325F, 0.3931509650F, 0.3941195865F, 0.3950885925F,
  142746. 0.3960579785F, 0.3970277400F, 0.3979978725F, 0.3989683716F,
  142747. 0.3999392328F, 0.4009104516F, 0.4018820234F, 0.4028539438F,
  142748. 0.4038262084F, 0.4047988125F, 0.4057717516F, 0.4067450214F,
  142749. 0.4077186172F, 0.4086925345F, 0.4096667688F, 0.4106413155F,
  142750. 0.4116161703F, 0.4125913284F, 0.4135667854F, 0.4145425368F,
  142751. 0.4155185780F, 0.4164949044F, 0.4174715116F, 0.4184483949F,
  142752. 0.4194255498F, 0.4204029718F, 0.4213806563F, 0.4223585987F,
  142753. 0.4233367946F, 0.4243152392F, 0.4252939281F, 0.4262728566F,
  142754. 0.4272520202F, 0.4282314144F, 0.4292110345F, 0.4301908760F,
  142755. 0.4311709343F, 0.4321512047F, 0.4331316828F, 0.4341123639F,
  142756. 0.4350932435F, 0.4360743168F, 0.4370555794F, 0.4380370267F,
  142757. 0.4390186540F, 0.4400004567F, 0.4409824303F, 0.4419645701F,
  142758. 0.4429468716F, 0.4439293300F, 0.4449119409F, 0.4458946996F,
  142759. 0.4468776014F, 0.4478606418F, 0.4488438162F, 0.4498271199F,
  142760. 0.4508105483F, 0.4517940967F, 0.4527777607F, 0.4537615355F,
  142761. 0.4547454165F, 0.4557293991F, 0.4567134786F, 0.4576976505F,
  142762. 0.4586819101F, 0.4596662527F, 0.4606506738F, 0.4616351687F,
  142763. 0.4626197328F, 0.4636043614F, 0.4645890499F, 0.4655737936F,
  142764. 0.4665585880F, 0.4675434284F, 0.4685283101F, 0.4695132286F,
  142765. 0.4704981791F, 0.4714831570F, 0.4724681577F, 0.4734531766F,
  142766. 0.4744382089F, 0.4754232501F, 0.4764082956F, 0.4773933406F,
  142767. 0.4783783806F, 0.4793634108F, 0.4803484267F, 0.4813334237F,
  142768. 0.4823183969F, 0.4833033419F, 0.4842882540F, 0.4852731285F,
  142769. 0.4862579608F, 0.4872427462F, 0.4882274802F, 0.4892121580F,
  142770. 0.4901967751F, 0.4911813267F, 0.4921658083F, 0.4931502151F,
  142771. 0.4941345427F, 0.4951187863F, 0.4961029412F, 0.4970870029F,
  142772. 0.4980709667F, 0.4990548280F, 0.5000385822F, 0.5010222245F,
  142773. 0.5020057505F, 0.5029891553F, 0.5039724345F, 0.5049555834F,
  142774. 0.5059385973F, 0.5069214716F, 0.5079042018F, 0.5088867831F,
  142775. 0.5098692110F, 0.5108514808F, 0.5118335879F, 0.5128155277F,
  142776. 0.5137972956F, 0.5147788869F, 0.5157602971F, 0.5167415215F,
  142777. 0.5177225555F, 0.5187033945F, 0.5196840339F, 0.5206644692F,
  142778. 0.5216446956F, 0.5226247086F, 0.5236045035F, 0.5245840759F,
  142779. 0.5255634211F, 0.5265425344F, 0.5275214114F, 0.5285000474F,
  142780. 0.5294784378F, 0.5304565781F, 0.5314344637F, 0.5324120899F,
  142781. 0.5333894522F, 0.5343665461F, 0.5353433670F, 0.5363199102F,
  142782. 0.5372961713F, 0.5382721457F, 0.5392478287F, 0.5402232159F,
  142783. 0.5411983027F, 0.5421730845F, 0.5431475569F, 0.5441217151F,
  142784. 0.5450955548F, 0.5460690714F, 0.5470422602F, 0.5480151169F,
  142785. 0.5489876368F, 0.5499598155F, 0.5509316484F, 0.5519031310F,
  142786. 0.5528742587F, 0.5538450271F, 0.5548154317F, 0.5557854680F,
  142787. 0.5567551314F, 0.5577244174F, 0.5586933216F, 0.5596618395F,
  142788. 0.5606299665F, 0.5615976983F, 0.5625650302F, 0.5635319580F,
  142789. 0.5644984770F, 0.5654645828F, 0.5664302709F, 0.5673955370F,
  142790. 0.5683603765F, 0.5693247850F, 0.5702887580F, 0.5712522912F,
  142791. 0.5722153800F, 0.5731780200F, 0.5741402069F, 0.5751019362F,
  142792. 0.5760632034F, 0.5770240042F, 0.5779843341F, 0.5789441889F,
  142793. 0.5799035639F, 0.5808624549F, 0.5818208575F, 0.5827787673F,
  142794. 0.5837361800F, 0.5846930910F, 0.5856494961F, 0.5866053910F,
  142795. 0.5875607712F, 0.5885156324F, 0.5894699703F, 0.5904237804F,
  142796. 0.5913770586F, 0.5923298004F, 0.5932820016F, 0.5942336578F,
  142797. 0.5951847646F, 0.5961353179F, 0.5970853132F, 0.5980347464F,
  142798. 0.5989836131F, 0.5999319090F, 0.6008796298F, 0.6018267713F,
  142799. 0.6027733292F, 0.6037192993F, 0.6046646773F, 0.6056094589F,
  142800. 0.6065536400F, 0.6074972162F, 0.6084401833F, 0.6093825372F,
  142801. 0.6103242736F, 0.6112653884F, 0.6122058772F, 0.6131457359F,
  142802. 0.6140849604F, 0.6150235464F, 0.6159614897F, 0.6168987862F,
  142803. 0.6178354318F, 0.6187714223F, 0.6197067535F, 0.6206414213F,
  142804. 0.6215754215F, 0.6225087501F, 0.6234414028F, 0.6243733757F,
  142805. 0.6253046646F, 0.6262352654F, 0.6271651739F, 0.6280943862F,
  142806. 0.6290228982F, 0.6299507057F, 0.6308778048F, 0.6318041913F,
  142807. 0.6327298612F, 0.6336548105F, 0.6345790352F, 0.6355025312F,
  142808. 0.6364252945F, 0.6373473211F, 0.6382686070F, 0.6391891483F,
  142809. 0.6401089409F, 0.6410279808F, 0.6419462642F, 0.6428637869F,
  142810. 0.6437805452F, 0.6446965350F, 0.6456117524F, 0.6465261935F,
  142811. 0.6474398544F, 0.6483527311F, 0.6492648197F, 0.6501761165F,
  142812. 0.6510866174F, 0.6519963186F, 0.6529052162F, 0.6538133064F,
  142813. 0.6547205854F, 0.6556270492F, 0.6565326941F, 0.6574375162F,
  142814. 0.6583415117F, 0.6592446769F, 0.6601470079F, 0.6610485009F,
  142815. 0.6619491521F, 0.6628489578F, 0.6637479143F, 0.6646460177F,
  142816. 0.6655432643F, 0.6664396505F, 0.6673351724F, 0.6682298264F,
  142817. 0.6691236087F, 0.6700165157F, 0.6709085436F, 0.6717996889F,
  142818. 0.6726899478F, 0.6735793167F, 0.6744677918F, 0.6753553697F,
  142819. 0.6762420466F, 0.6771278190F, 0.6780126832F, 0.6788966357F,
  142820. 0.6797796728F, 0.6806617909F, 0.6815429866F, 0.6824232562F,
  142821. 0.6833025961F, 0.6841810030F, 0.6850584731F, 0.6859350031F,
  142822. 0.6868105894F, 0.6876852284F, 0.6885589168F, 0.6894316510F,
  142823. 0.6903034275F, 0.6911742430F, 0.6920440939F, 0.6929129769F,
  142824. 0.6937808884F, 0.6946478251F, 0.6955137837F, 0.6963787606F,
  142825. 0.6972427525F, 0.6981057560F, 0.6989677678F, 0.6998287845F,
  142826. 0.7006888028F, 0.7015478194F, 0.7024058309F, 0.7032628340F,
  142827. 0.7041188254F, 0.7049738019F, 0.7058277601F, 0.7066806969F,
  142828. 0.7075326089F, 0.7083834929F, 0.7092333457F, 0.7100821640F,
  142829. 0.7109299447F, 0.7117766846F, 0.7126223804F, 0.7134670291F,
  142830. 0.7143106273F, 0.7151531721F, 0.7159946602F, 0.7168350885F,
  142831. 0.7176744539F, 0.7185127534F, 0.7193499837F, 0.7201861418F,
  142832. 0.7210212247F, 0.7218552293F, 0.7226881526F, 0.7235199914F,
  142833. 0.7243507428F, 0.7251804039F, 0.7260089715F, 0.7268364426F,
  142834. 0.7276628144F, 0.7284880839F, 0.7293122481F, 0.7301353040F,
  142835. 0.7309572487F, 0.7317780794F, 0.7325977930F, 0.7334163868F,
  142836. 0.7342338579F, 0.7350502033F, 0.7358654202F, 0.7366795059F,
  142837. 0.7374924573F, 0.7383042718F, 0.7391149465F, 0.7399244787F,
  142838. 0.7407328655F, 0.7415401041F, 0.7423461920F, 0.7431511261F,
  142839. 0.7439549040F, 0.7447575227F, 0.7455589797F, 0.7463592723F,
  142840. 0.7471583976F, 0.7479563532F, 0.7487531363F, 0.7495487443F,
  142841. 0.7503431745F, 0.7511364244F, 0.7519284913F, 0.7527193726F,
  142842. 0.7535090658F, 0.7542975683F, 0.7550848776F, 0.7558709910F,
  142843. 0.7566559062F, 0.7574396205F, 0.7582221314F, 0.7590034366F,
  142844. 0.7597835334F, 0.7605624194F, 0.7613400923F, 0.7621165495F,
  142845. 0.7628917886F, 0.7636658072F, 0.7644386030F, 0.7652101735F,
  142846. 0.7659805164F, 0.7667496292F, 0.7675175098F, 0.7682841556F,
  142847. 0.7690495645F, 0.7698137341F, 0.7705766622F, 0.7713383463F,
  142848. 0.7720987844F, 0.7728579741F, 0.7736159132F, 0.7743725994F,
  142849. 0.7751280306F, 0.7758822046F, 0.7766351192F, 0.7773867722F,
  142850. 0.7781371614F, 0.7788862848F, 0.7796341401F, 0.7803807253F,
  142851. 0.7811260383F, 0.7818700769F, 0.7826128392F, 0.7833543230F,
  142852. 0.7840945263F, 0.7848334471F, 0.7855710833F, 0.7863074330F,
  142853. 0.7870424941F, 0.7877762647F, 0.7885087428F, 0.7892399264F,
  142854. 0.7899698137F, 0.7906984026F, 0.7914256914F, 0.7921516780F,
  142855. 0.7928763607F, 0.7935997375F, 0.7943218065F, 0.7950425661F,
  142856. 0.7957620142F, 0.7964801492F, 0.7971969692F, 0.7979124724F,
  142857. 0.7986266570F, 0.7993395214F, 0.8000510638F, 0.8007612823F,
  142858. 0.8014701754F, 0.8021777413F, 0.8028839784F, 0.8035888849F,
  142859. 0.8042924592F, 0.8049946997F, 0.8056956048F, 0.8063951727F,
  142860. 0.8070934020F, 0.8077902910F, 0.8084858381F, 0.8091800419F,
  142861. 0.8098729007F, 0.8105644130F, 0.8112545774F, 0.8119433922F,
  142862. 0.8126308561F, 0.8133169676F, 0.8140017251F, 0.8146851272F,
  142863. 0.8153671726F, 0.8160478598F, 0.8167271874F, 0.8174051539F,
  142864. 0.8180817582F, 0.8187569986F, 0.8194308741F, 0.8201033831F,
  142865. 0.8207745244F, 0.8214442966F, 0.8221126986F, 0.8227797290F,
  142866. 0.8234453865F, 0.8241096700F, 0.8247725781F, 0.8254341097F,
  142867. 0.8260942636F, 0.8267530385F, 0.8274104334F, 0.8280664470F,
  142868. 0.8287210782F, 0.8293743259F, 0.8300261889F, 0.8306766662F,
  142869. 0.8313257566F, 0.8319734591F, 0.8326197727F, 0.8332646963F,
  142870. 0.8339082288F, 0.8345503692F, 0.8351911167F, 0.8358304700F,
  142871. 0.8364684284F, 0.8371049907F, 0.8377401562F, 0.8383739238F,
  142872. 0.8390062927F, 0.8396372618F, 0.8402668305F, 0.8408949977F,
  142873. 0.8415217626F, 0.8421471245F, 0.8427710823F, 0.8433936354F,
  142874. 0.8440147830F, 0.8446345242F, 0.8452528582F, 0.8458697844F,
  142875. 0.8464853020F, 0.8470994102F, 0.8477121084F, 0.8483233958F,
  142876. 0.8489332718F, 0.8495417356F, 0.8501487866F, 0.8507544243F,
  142877. 0.8513586479F, 0.8519614568F, 0.8525628505F, 0.8531628283F,
  142878. 0.8537613897F, 0.8543585341F, 0.8549542611F, 0.8555485699F,
  142879. 0.8561414603F, 0.8567329315F, 0.8573229832F, 0.8579116149F,
  142880. 0.8584988262F, 0.8590846165F, 0.8596689855F, 0.8602519327F,
  142881. 0.8608334577F, 0.8614135603F, 0.8619922399F, 0.8625694962F,
  142882. 0.8631453289F, 0.8637197377F, 0.8642927222F, 0.8648642821F,
  142883. 0.8654344172F, 0.8660031272F, 0.8665704118F, 0.8671362708F,
  142884. 0.8677007039F, 0.8682637109F, 0.8688252917F, 0.8693854460F,
  142885. 0.8699441737F, 0.8705014745F, 0.8710573485F, 0.8716117953F,
  142886. 0.8721648150F, 0.8727164073F, 0.8732665723F, 0.8738153098F,
  142887. 0.8743626197F, 0.8749085021F, 0.8754529569F, 0.8759959840F,
  142888. 0.8765375835F, 0.8770777553F, 0.8776164996F, 0.8781538162F,
  142889. 0.8786897054F, 0.8792241670F, 0.8797572013F, 0.8802888082F,
  142890. 0.8808189880F, 0.8813477407F, 0.8818750664F, 0.8824009653F,
  142891. 0.8829254375F, 0.8834484833F, 0.8839701028F, 0.8844902961F,
  142892. 0.8850090636F, 0.8855264054F, 0.8860423218F, 0.8865568131F,
  142893. 0.8870698794F, 0.8875815212F, 0.8880917386F, 0.8886005319F,
  142894. 0.8891079016F, 0.8896138479F, 0.8901183712F, 0.8906214719F,
  142895. 0.8911231503F, 0.8916234067F, 0.8921222417F, 0.8926196556F,
  142896. 0.8931156489F, 0.8936102219F, 0.8941033752F, 0.8945951092F,
  142897. 0.8950854244F, 0.8955743212F, 0.8960618003F, 0.8965478621F,
  142898. 0.8970325071F, 0.8975157359F, 0.8979975490F, 0.8984779471F,
  142899. 0.8989569307F, 0.8994345004F, 0.8999106568F, 0.9003854005F,
  142900. 0.9008587323F, 0.9013306526F, 0.9018011623F, 0.9022702619F,
  142901. 0.9027379521F, 0.9032042337F, 0.9036691074F, 0.9041325739F,
  142902. 0.9045946339F, 0.9050552882F, 0.9055145376F, 0.9059723828F,
  142903. 0.9064288246F, 0.9068838638F, 0.9073375013F, 0.9077897379F,
  142904. 0.9082405743F, 0.9086900115F, 0.9091380503F, 0.9095846917F,
  142905. 0.9100299364F, 0.9104737854F, 0.9109162397F, 0.9113573001F,
  142906. 0.9117969675F, 0.9122352430F, 0.9126721275F, 0.9131076219F,
  142907. 0.9135417273F, 0.9139744447F, 0.9144057750F, 0.9148357194F,
  142908. 0.9152642787F, 0.9156914542F, 0.9161172468F, 0.9165416576F,
  142909. 0.9169646877F, 0.9173863382F, 0.9178066102F, 0.9182255048F,
  142910. 0.9186430232F, 0.9190591665F, 0.9194739359F, 0.9198873324F,
  142911. 0.9202993574F, 0.9207100120F, 0.9211192973F, 0.9215272147F,
  142912. 0.9219337653F, 0.9223389504F, 0.9227427713F, 0.9231452290F,
  142913. 0.9235463251F, 0.9239460607F, 0.9243444371F, 0.9247414557F,
  142914. 0.9251371177F, 0.9255314245F, 0.9259243774F, 0.9263159778F,
  142915. 0.9267062270F, 0.9270951264F, 0.9274826774F, 0.9278688814F,
  142916. 0.9282537398F, 0.9286372540F, 0.9290194254F, 0.9294002555F,
  142917. 0.9297797458F, 0.9301578976F, 0.9305347125F, 0.9309101919F,
  142918. 0.9312843373F, 0.9316571503F, 0.9320286323F, 0.9323987849F,
  142919. 0.9327676097F, 0.9331351080F, 0.9335012816F, 0.9338661320F,
  142920. 0.9342296607F, 0.9345918694F, 0.9349527596F, 0.9353123330F,
  142921. 0.9356705911F, 0.9360275357F, 0.9363831683F, 0.9367374905F,
  142922. 0.9370905042F, 0.9374422108F, 0.9377926122F, 0.9381417099F,
  142923. 0.9384895057F, 0.9388360014F, 0.9391811985F, 0.9395250989F,
  142924. 0.9398677043F, 0.9402090165F, 0.9405490371F, 0.9408877680F,
  142925. 0.9412252110F, 0.9415613678F, 0.9418962402F, 0.9422298301F,
  142926. 0.9425621392F, 0.9428931695F, 0.9432229226F, 0.9435514005F,
  142927. 0.9438786050F, 0.9442045381F, 0.9445292014F, 0.9448525971F,
  142928. 0.9451747268F, 0.9454955926F, 0.9458151963F, 0.9461335399F,
  142929. 0.9464506253F, 0.9467664545F, 0.9470810293F, 0.9473943517F,
  142930. 0.9477064238F, 0.9480172474F, 0.9483268246F, 0.9486351573F,
  142931. 0.9489422475F, 0.9492480973F, 0.9495527087F, 0.9498560837F,
  142932. 0.9501582243F, 0.9504591325F, 0.9507588105F, 0.9510572603F,
  142933. 0.9513544839F, 0.9516504834F, 0.9519452609F, 0.9522388186F,
  142934. 0.9525311584F, 0.9528222826F, 0.9531121932F, 0.9534008923F,
  142935. 0.9536883821F, 0.9539746647F, 0.9542597424F, 0.9545436171F,
  142936. 0.9548262912F, 0.9551077667F, 0.9553880459F, 0.9556671309F,
  142937. 0.9559450239F, 0.9562217272F, 0.9564972429F, 0.9567715733F,
  142938. 0.9570447206F, 0.9573166871F, 0.9575874749F, 0.9578570863F,
  142939. 0.9581255236F, 0.9583927890F, 0.9586588849F, 0.9589238134F,
  142940. 0.9591875769F, 0.9594501777F, 0.9597116180F, 0.9599719003F,
  142941. 0.9602310267F, 0.9604889995F, 0.9607458213F, 0.9610014942F,
  142942. 0.9612560206F, 0.9615094028F, 0.9617616433F, 0.9620127443F,
  142943. 0.9622627083F, 0.9625115376F, 0.9627592345F, 0.9630058016F,
  142944. 0.9632512411F, 0.9634955555F, 0.9637387471F, 0.9639808185F,
  142945. 0.9642217720F, 0.9644616100F, 0.9647003349F, 0.9649379493F,
  142946. 0.9651744556F, 0.9654098561F, 0.9656441534F, 0.9658773499F,
  142947. 0.9661094480F, 0.9663404504F, 0.9665703593F, 0.9667991774F,
  142948. 0.9670269071F, 0.9672535509F, 0.9674791114F, 0.9677035909F,
  142949. 0.9679269921F, 0.9681493174F, 0.9683705694F, 0.9685907506F,
  142950. 0.9688098636F, 0.9690279108F, 0.9692448948F, 0.9694608182F,
  142951. 0.9696756836F, 0.9698894934F, 0.9701022503F, 0.9703139569F,
  142952. 0.9705246156F, 0.9707342291F, 0.9709428000F, 0.9711503309F,
  142953. 0.9713568243F, 0.9715622829F, 0.9717667093F, 0.9719701060F,
  142954. 0.9721724757F, 0.9723738210F, 0.9725741446F, 0.9727734490F,
  142955. 0.9729717369F, 0.9731690109F, 0.9733652737F, 0.9735605279F,
  142956. 0.9737547762F, 0.9739480212F, 0.9741402656F, 0.9743315120F,
  142957. 0.9745217631F, 0.9747110216F, 0.9748992901F, 0.9750865714F,
  142958. 0.9752728681F, 0.9754581829F, 0.9756425184F, 0.9758258775F,
  142959. 0.9760082627F, 0.9761896768F, 0.9763701224F, 0.9765496024F,
  142960. 0.9767281193F, 0.9769056760F, 0.9770822751F, 0.9772579193F,
  142961. 0.9774326114F, 0.9776063542F, 0.9777791502F, 0.9779510023F,
  142962. 0.9781219133F, 0.9782918858F, 0.9784609226F, 0.9786290264F,
  142963. 0.9787962000F, 0.9789624461F, 0.9791277676F, 0.9792921671F,
  142964. 0.9794556474F, 0.9796182113F, 0.9797798615F, 0.9799406009F,
  142965. 0.9801004321F, 0.9802593580F, 0.9804173813F, 0.9805745049F,
  142966. 0.9807307314F, 0.9808860637F, 0.9810405046F, 0.9811940568F,
  142967. 0.9813467232F, 0.9814985065F, 0.9816494095F, 0.9817994351F,
  142968. 0.9819485860F, 0.9820968650F, 0.9822442750F, 0.9823908186F,
  142969. 0.9825364988F, 0.9826813184F, 0.9828252801F, 0.9829683868F,
  142970. 0.9831106413F, 0.9832520463F, 0.9833926048F, 0.9835323195F,
  142971. 0.9836711932F, 0.9838092288F, 0.9839464291F, 0.9840827969F,
  142972. 0.9842183351F, 0.9843530464F, 0.9844869337F, 0.9846199998F,
  142973. 0.9847522475F, 0.9848836798F, 0.9850142993F, 0.9851441090F,
  142974. 0.9852731117F, 0.9854013101F, 0.9855287073F, 0.9856553058F,
  142975. 0.9857811087F, 0.9859061188F, 0.9860303388F, 0.9861537717F,
  142976. 0.9862764202F, 0.9863982872F, 0.9865193756F, 0.9866396882F,
  142977. 0.9867592277F, 0.9868779972F, 0.9869959993F, 0.9871132370F,
  142978. 0.9872297131F, 0.9873454304F, 0.9874603918F, 0.9875746001F,
  142979. 0.9876880581F, 0.9878007688F, 0.9879127348F, 0.9880239592F,
  142980. 0.9881344447F, 0.9882441941F, 0.9883532104F, 0.9884614962F,
  142981. 0.9885690546F, 0.9886758883F, 0.9887820001F, 0.9888873930F,
  142982. 0.9889920697F, 0.9890960331F, 0.9891992859F, 0.9893018312F,
  142983. 0.9894036716F, 0.9895048100F, 0.9896052493F, 0.9897049923F,
  142984. 0.9898040418F, 0.9899024006F, 0.9900000717F, 0.9900970577F,
  142985. 0.9901933616F, 0.9902889862F, 0.9903839343F, 0.9904782087F,
  142986. 0.9905718122F, 0.9906647477F, 0.9907570180F, 0.9908486259F,
  142987. 0.9909395742F, 0.9910298658F, 0.9911195034F, 0.9912084899F,
  142988. 0.9912968281F, 0.9913845208F, 0.9914715708F, 0.9915579810F,
  142989. 0.9916437540F, 0.9917288928F, 0.9918134001F, 0.9918972788F,
  142990. 0.9919805316F, 0.9920631613F, 0.9921451707F, 0.9922265626F,
  142991. 0.9923073399F, 0.9923875052F, 0.9924670615F, 0.9925460114F,
  142992. 0.9926243577F, 0.9927021033F, 0.9927792508F, 0.9928558032F,
  142993. 0.9929317631F, 0.9930071333F, 0.9930819167F, 0.9931561158F,
  142994. 0.9932297337F, 0.9933027728F, 0.9933752362F, 0.9934471264F,
  142995. 0.9935184462F, 0.9935891985F, 0.9936593859F, 0.9937290112F,
  142996. 0.9937980771F, 0.9938665864F, 0.9939345418F, 0.9940019460F,
  142997. 0.9940688018F, 0.9941351118F, 0.9942008789F, 0.9942661057F,
  142998. 0.9943307950F, 0.9943949494F, 0.9944585717F, 0.9945216645F,
  142999. 0.9945842307F, 0.9946462728F, 0.9947077936F, 0.9947687957F,
  143000. 0.9948292820F, 0.9948892550F, 0.9949487174F, 0.9950076719F,
  143001. 0.9950661212F, 0.9951240679F, 0.9951815148F, 0.9952384645F,
  143002. 0.9952949196F, 0.9953508828F, 0.9954063568F, 0.9954613442F,
  143003. 0.9955158476F, 0.9955698697F, 0.9956234132F, 0.9956764806F,
  143004. 0.9957290746F, 0.9957811978F, 0.9958328528F, 0.9958840423F,
  143005. 0.9959347688F, 0.9959850351F, 0.9960348435F, 0.9960841969F,
  143006. 0.9961330977F, 0.9961815486F, 0.9962295521F, 0.9962771108F,
  143007. 0.9963242274F, 0.9963709043F, 0.9964171441F, 0.9964629494F,
  143008. 0.9965083228F, 0.9965532668F, 0.9965977840F, 0.9966418768F,
  143009. 0.9966855479F, 0.9967287998F, 0.9967716350F, 0.9968140559F,
  143010. 0.9968560653F, 0.9968976655F, 0.9969388591F, 0.9969796485F,
  143011. 0.9970200363F, 0.9970600250F, 0.9970996170F, 0.9971388149F,
  143012. 0.9971776211F, 0.9972160380F, 0.9972540683F, 0.9972917142F,
  143013. 0.9973289783F, 0.9973658631F, 0.9974023709F, 0.9974385042F,
  143014. 0.9974742655F, 0.9975096571F, 0.9975446816F, 0.9975793413F,
  143015. 0.9976136386F, 0.9976475759F, 0.9976811557F, 0.9977143803F,
  143016. 0.9977472521F, 0.9977797736F, 0.9978119470F, 0.9978437748F,
  143017. 0.9978752593F, 0.9979064029F, 0.9979372079F, 0.9979676768F,
  143018. 0.9979978117F, 0.9980276151F, 0.9980570893F, 0.9980862367F,
  143019. 0.9981150595F, 0.9981435600F, 0.9981717406F, 0.9981996035F,
  143020. 0.9982271511F, 0.9982543856F, 0.9982813093F, 0.9983079246F,
  143021. 0.9983342336F, 0.9983602386F, 0.9983859418F, 0.9984113456F,
  143022. 0.9984364522F, 0.9984612638F, 0.9984857825F, 0.9985100108F,
  143023. 0.9985339507F, 0.9985576044F, 0.9985809743F, 0.9986040624F,
  143024. 0.9986268710F, 0.9986494022F, 0.9986716583F, 0.9986936413F,
  143025. 0.9987153535F, 0.9987367969F, 0.9987579738F, 0.9987788864F,
  143026. 0.9987995366F, 0.9988199267F, 0.9988400587F, 0.9988599348F,
  143027. 0.9988795572F, 0.9988989278F, 0.9989180487F, 0.9989369222F,
  143028. 0.9989555501F, 0.9989739347F, 0.9989920780F, 0.9990099820F,
  143029. 0.9990276487F, 0.9990450803F, 0.9990622787F, 0.9990792460F,
  143030. 0.9990959841F, 0.9991124952F, 0.9991287812F, 0.9991448440F,
  143031. 0.9991606858F, 0.9991763084F, 0.9991917139F, 0.9992069042F,
  143032. 0.9992218813F, 0.9992366471F, 0.9992512035F, 0.9992655525F,
  143033. 0.9992796961F, 0.9992936361F, 0.9993073744F, 0.9993209131F,
  143034. 0.9993342538F, 0.9993473987F, 0.9993603494F, 0.9993731080F,
  143035. 0.9993856762F, 0.9993980559F, 0.9994102490F, 0.9994222573F,
  143036. 0.9994340827F, 0.9994457269F, 0.9994571918F, 0.9994684793F,
  143037. 0.9994795910F, 0.9994905288F, 0.9995012945F, 0.9995118898F,
  143038. 0.9995223165F, 0.9995325765F, 0.9995426713F, 0.9995526029F,
  143039. 0.9995623728F, 0.9995719829F, 0.9995814349F, 0.9995907304F,
  143040. 0.9995998712F, 0.9996088590F, 0.9996176954F, 0.9996263821F,
  143041. 0.9996349208F, 0.9996433132F, 0.9996515609F, 0.9996596656F,
  143042. 0.9996676288F, 0.9996754522F, 0.9996831375F, 0.9996906862F,
  143043. 0.9996981000F, 0.9997053804F, 0.9997125290F, 0.9997195474F,
  143044. 0.9997264371F, 0.9997331998F, 0.9997398369F, 0.9997463500F,
  143045. 0.9997527406F, 0.9997590103F, 0.9997651606F, 0.9997711930F,
  143046. 0.9997771089F, 0.9997829098F, 0.9997885973F, 0.9997941728F,
  143047. 0.9997996378F, 0.9998049936F, 0.9998102419F, 0.9998153839F,
  143048. 0.9998204211F, 0.9998253550F, 0.9998301868F, 0.9998349182F,
  143049. 0.9998395503F, 0.9998440847F, 0.9998485226F, 0.9998528654F,
  143050. 0.9998571146F, 0.9998612713F, 0.9998653370F, 0.9998693130F,
  143051. 0.9998732007F, 0.9998770012F, 0.9998807159F, 0.9998843461F,
  143052. 0.9998878931F, 0.9998913581F, 0.9998947424F, 0.9998980473F,
  143053. 0.9999012740F, 0.9999044237F, 0.9999074976F, 0.9999104971F,
  143054. 0.9999134231F, 0.9999162771F, 0.9999190601F, 0.9999217733F,
  143055. 0.9999244179F, 0.9999269950F, 0.9999295058F, 0.9999319515F,
  143056. 0.9999343332F, 0.9999366519F, 0.9999389088F, 0.9999411050F,
  143057. 0.9999432416F, 0.9999453196F, 0.9999473402F, 0.9999493044F,
  143058. 0.9999512132F, 0.9999530677F, 0.9999548690F, 0.9999566180F,
  143059. 0.9999583157F, 0.9999599633F, 0.9999615616F, 0.9999631116F,
  143060. 0.9999646144F, 0.9999660709F, 0.9999674820F, 0.9999688487F,
  143061. 0.9999701719F, 0.9999714526F, 0.9999726917F, 0.9999738900F,
  143062. 0.9999750486F, 0.9999761682F, 0.9999772497F, 0.9999782941F,
  143063. 0.9999793021F, 0.9999802747F, 0.9999812126F, 0.9999821167F,
  143064. 0.9999829878F, 0.9999838268F, 0.9999846343F, 0.9999854113F,
  143065. 0.9999861584F, 0.9999868765F, 0.9999875664F, 0.9999882287F,
  143066. 0.9999888642F, 0.9999894736F, 0.9999900577F, 0.9999906172F,
  143067. 0.9999911528F, 0.9999916651F, 0.9999921548F, 0.9999926227F,
  143068. 0.9999930693F, 0.9999934954F, 0.9999939015F, 0.9999942883F,
  143069. 0.9999946564F, 0.9999950064F, 0.9999953390F, 0.9999956547F,
  143070. 0.9999959541F, 0.9999962377F, 0.9999965062F, 0.9999967601F,
  143071. 0.9999969998F, 0.9999972260F, 0.9999974392F, 0.9999976399F,
  143072. 0.9999978285F, 0.9999980056F, 0.9999981716F, 0.9999983271F,
  143073. 0.9999984724F, 0.9999986081F, 0.9999987345F, 0.9999988521F,
  143074. 0.9999989613F, 0.9999990625F, 0.9999991562F, 0.9999992426F,
  143075. 0.9999993223F, 0.9999993954F, 0.9999994625F, 0.9999995239F,
  143076. 0.9999995798F, 0.9999996307F, 0.9999996768F, 0.9999997184F,
  143077. 0.9999997559F, 0.9999997895F, 0.9999998195F, 0.9999998462F,
  143078. 0.9999998698F, 0.9999998906F, 0.9999999088F, 0.9999999246F,
  143079. 0.9999999383F, 0.9999999500F, 0.9999999600F, 0.9999999684F,
  143080. 0.9999999754F, 0.9999999811F, 0.9999999858F, 0.9999999896F,
  143081. 0.9999999925F, 0.9999999948F, 0.9999999965F, 0.9999999978F,
  143082. 0.9999999986F, 0.9999999992F, 0.9999999996F, 0.9999999998F,
  143083. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  143084. };
  143085. static float vwin8192[4096] = {
  143086. 0.0000000578F, 0.0000005198F, 0.0000014438F, 0.0000028299F,
  143087. 0.0000046780F, 0.0000069882F, 0.0000097604F, 0.0000129945F,
  143088. 0.0000166908F, 0.0000208490F, 0.0000254692F, 0.0000305515F,
  143089. 0.0000360958F, 0.0000421021F, 0.0000485704F, 0.0000555006F,
  143090. 0.0000628929F, 0.0000707472F, 0.0000790635F, 0.0000878417F,
  143091. 0.0000970820F, 0.0001067842F, 0.0001169483F, 0.0001275744F,
  143092. 0.0001386625F, 0.0001502126F, 0.0001622245F, 0.0001746984F,
  143093. 0.0001876343F, 0.0002010320F, 0.0002148917F, 0.0002292132F,
  143094. 0.0002439967F, 0.0002592421F, 0.0002749493F, 0.0002911184F,
  143095. 0.0003077493F, 0.0003248421F, 0.0003423967F, 0.0003604132F,
  143096. 0.0003788915F, 0.0003978316F, 0.0004172335F, 0.0004370971F,
  143097. 0.0004574226F, 0.0004782098F, 0.0004994587F, 0.0005211694F,
  143098. 0.0005433418F, 0.0005659759F, 0.0005890717F, 0.0006126292F,
  143099. 0.0006366484F, 0.0006611292F, 0.0006860716F, 0.0007114757F,
  143100. 0.0007373414F, 0.0007636687F, 0.0007904576F, 0.0008177080F,
  143101. 0.0008454200F, 0.0008735935F, 0.0009022285F, 0.0009313250F,
  143102. 0.0009608830F, 0.0009909025F, 0.0010213834F, 0.0010523257F,
  143103. 0.0010837295F, 0.0011155946F, 0.0011479211F, 0.0011807090F,
  143104. 0.0012139582F, 0.0012476687F, 0.0012818405F, 0.0013164736F,
  143105. 0.0013515679F, 0.0013871235F, 0.0014231402F, 0.0014596182F,
  143106. 0.0014965573F, 0.0015339576F, 0.0015718190F, 0.0016101415F,
  143107. 0.0016489251F, 0.0016881698F, 0.0017278754F, 0.0017680421F,
  143108. 0.0018086698F, 0.0018497584F, 0.0018913080F, 0.0019333185F,
  143109. 0.0019757898F, 0.0020187221F, 0.0020621151F, 0.0021059690F,
  143110. 0.0021502837F, 0.0021950591F, 0.0022402953F, 0.0022859921F,
  143111. 0.0023321497F, 0.0023787679F, 0.0024258467F, 0.0024733861F,
  143112. 0.0025213861F, 0.0025698466F, 0.0026187676F, 0.0026681491F,
  143113. 0.0027179911F, 0.0027682935F, 0.0028190562F, 0.0028702794F,
  143114. 0.0029219628F, 0.0029741066F, 0.0030267107F, 0.0030797749F,
  143115. 0.0031332994F, 0.0031872841F, 0.0032417289F, 0.0032966338F,
  143116. 0.0033519988F, 0.0034078238F, 0.0034641089F, 0.0035208539F,
  143117. 0.0035780589F, 0.0036357237F, 0.0036938485F, 0.0037524331F,
  143118. 0.0038114775F, 0.0038709817F, 0.0039309456F, 0.0039913692F,
  143119. 0.0040522524F, 0.0041135953F, 0.0041753978F, 0.0042376599F,
  143120. 0.0043003814F, 0.0043635624F, 0.0044272029F, 0.0044913028F,
  143121. 0.0045558620F, 0.0046208806F, 0.0046863585F, 0.0047522955F,
  143122. 0.0048186919F, 0.0048855473F, 0.0049528619F, 0.0050206356F,
  143123. 0.0050888684F, 0.0051575601F, 0.0052267108F, 0.0052963204F,
  143124. 0.0053663890F, 0.0054369163F, 0.0055079025F, 0.0055793474F,
  143125. 0.0056512510F, 0.0057236133F, 0.0057964342F, 0.0058697137F,
  143126. 0.0059434517F, 0.0060176482F, 0.0060923032F, 0.0061674166F,
  143127. 0.0062429883F, 0.0063190183F, 0.0063955066F, 0.0064724532F,
  143128. 0.0065498579F, 0.0066277207F, 0.0067060416F, 0.0067848205F,
  143129. 0.0068640575F, 0.0069437523F, 0.0070239051F, 0.0071045157F,
  143130. 0.0071855840F, 0.0072671102F, 0.0073490940F, 0.0074315355F,
  143131. 0.0075144345F, 0.0075977911F, 0.0076816052F, 0.0077658768F,
  143132. 0.0078506057F, 0.0079357920F, 0.0080214355F, 0.0081075363F,
  143133. 0.0081940943F, 0.0082811094F, 0.0083685816F, 0.0084565108F,
  143134. 0.0085448970F, 0.0086337401F, 0.0087230401F, 0.0088127969F,
  143135. 0.0089030104F, 0.0089936807F, 0.0090848076F, 0.0091763911F,
  143136. 0.0092684311F, 0.0093609276F, 0.0094538805F, 0.0095472898F,
  143137. 0.0096411554F, 0.0097354772F, 0.0098302552F, 0.0099254894F,
  143138. 0.0100211796F, 0.0101173259F, 0.0102139281F, 0.0103109863F,
  143139. 0.0104085002F, 0.0105064700F, 0.0106048955F, 0.0107037766F,
  143140. 0.0108031133F, 0.0109029056F, 0.0110031534F, 0.0111038565F,
  143141. 0.0112050151F, 0.0113066289F, 0.0114086980F, 0.0115112222F,
  143142. 0.0116142015F, 0.0117176359F, 0.0118215252F, 0.0119258695F,
  143143. 0.0120306686F, 0.0121359225F, 0.0122416312F, 0.0123477944F,
  143144. 0.0124544123F, 0.0125614847F, 0.0126690116F, 0.0127769928F,
  143145. 0.0128854284F, 0.0129943182F, 0.0131036623F, 0.0132134604F,
  143146. 0.0133237126F, 0.0134344188F, 0.0135455790F, 0.0136571929F,
  143147. 0.0137692607F, 0.0138817821F, 0.0139947572F, 0.0141081859F,
  143148. 0.0142220681F, 0.0143364037F, 0.0144511927F, 0.0145664350F,
  143149. 0.0146821304F, 0.0147982791F, 0.0149148808F, 0.0150319355F,
  143150. 0.0151494431F, 0.0152674036F, 0.0153858168F, 0.0155046828F,
  143151. 0.0156240014F, 0.0157437726F, 0.0158639962F, 0.0159846723F,
  143152. 0.0161058007F, 0.0162273814F, 0.0163494142F, 0.0164718991F,
  143153. 0.0165948361F, 0.0167182250F, 0.0168420658F, 0.0169663584F,
  143154. 0.0170911027F, 0.0172162987F, 0.0173419462F, 0.0174680452F,
  143155. 0.0175945956F, 0.0177215974F, 0.0178490504F, 0.0179769545F,
  143156. 0.0181053098F, 0.0182341160F, 0.0183633732F, 0.0184930812F,
  143157. 0.0186232399F, 0.0187538494F, 0.0188849094F, 0.0190164200F,
  143158. 0.0191483809F, 0.0192807923F, 0.0194136539F, 0.0195469656F,
  143159. 0.0196807275F, 0.0198149394F, 0.0199496012F, 0.0200847128F,
  143160. 0.0202202742F, 0.0203562853F, 0.0204927460F, 0.0206296561F,
  143161. 0.0207670157F, 0.0209048245F, 0.0210430826F, 0.0211817899F,
  143162. 0.0213209462F, 0.0214605515F, 0.0216006057F, 0.0217411086F,
  143163. 0.0218820603F, 0.0220234605F, 0.0221653093F, 0.0223076066F,
  143164. 0.0224503521F, 0.0225935459F, 0.0227371879F, 0.0228812779F,
  143165. 0.0230258160F, 0.0231708018F, 0.0233162355F, 0.0234621169F,
  143166. 0.0236084459F, 0.0237552224F, 0.0239024462F, 0.0240501175F,
  143167. 0.0241982359F, 0.0243468015F, 0.0244958141F, 0.0246452736F,
  143168. 0.0247951800F, 0.0249455331F, 0.0250963329F, 0.0252475792F,
  143169. 0.0253992720F, 0.0255514111F, 0.0257039965F, 0.0258570281F,
  143170. 0.0260105057F, 0.0261644293F, 0.0263187987F, 0.0264736139F,
  143171. 0.0266288747F, 0.0267845811F, 0.0269407330F, 0.0270973302F,
  143172. 0.0272543727F, 0.0274118604F, 0.0275697930F, 0.0277281707F,
  143173. 0.0278869932F, 0.0280462604F, 0.0282059723F, 0.0283661287F,
  143174. 0.0285267295F, 0.0286877747F, 0.0288492641F, 0.0290111976F,
  143175. 0.0291735751F, 0.0293363965F, 0.0294996617F, 0.0296633706F,
  143176. 0.0298275231F, 0.0299921190F, 0.0301571583F, 0.0303226409F,
  143177. 0.0304885667F, 0.0306549354F, 0.0308217472F, 0.0309890017F,
  143178. 0.0311566989F, 0.0313248388F, 0.0314934211F, 0.0316624459F,
  143179. 0.0318319128F, 0.0320018220F, 0.0321721732F, 0.0323429663F,
  143180. 0.0325142013F, 0.0326858779F, 0.0328579962F, 0.0330305559F,
  143181. 0.0332035570F, 0.0333769994F, 0.0335508829F, 0.0337252074F,
  143182. 0.0338999728F, 0.0340751790F, 0.0342508259F, 0.0344269134F,
  143183. 0.0346034412F, 0.0347804094F, 0.0349578178F, 0.0351356663F,
  143184. 0.0353139548F, 0.0354926831F, 0.0356718511F, 0.0358514588F,
  143185. 0.0360315059F, 0.0362119924F, 0.0363929182F, 0.0365742831F,
  143186. 0.0367560870F, 0.0369383297F, 0.0371210113F, 0.0373041315F,
  143187. 0.0374876902F, 0.0376716873F, 0.0378561226F, 0.0380409961F,
  143188. 0.0382263077F, 0.0384120571F, 0.0385982443F, 0.0387848691F,
  143189. 0.0389719315F, 0.0391594313F, 0.0393473683F, 0.0395357425F,
  143190. 0.0397245537F, 0.0399138017F, 0.0401034866F, 0.0402936080F,
  143191. 0.0404841660F, 0.0406751603F, 0.0408665909F, 0.0410584576F,
  143192. 0.0412507603F, 0.0414434988F, 0.0416366731F, 0.0418302829F,
  143193. 0.0420243282F, 0.0422188088F, 0.0424137246F, 0.0426090755F,
  143194. 0.0428048613F, 0.0430010819F, 0.0431977371F, 0.0433948269F,
  143195. 0.0435923511F, 0.0437903095F, 0.0439887020F, 0.0441875285F,
  143196. 0.0443867889F, 0.0445864830F, 0.0447866106F, 0.0449871717F,
  143197. 0.0451881661F, 0.0453895936F, 0.0455914542F, 0.0457937477F,
  143198. 0.0459964738F, 0.0461996326F, 0.0464032239F, 0.0466072475F,
  143199. 0.0468117032F, 0.0470165910F, 0.0472219107F, 0.0474276622F,
  143200. 0.0476338452F, 0.0478404597F, 0.0480475056F, 0.0482549827F,
  143201. 0.0484628907F, 0.0486712297F, 0.0488799994F, 0.0490891998F,
  143202. 0.0492988306F, 0.0495088917F, 0.0497193830F, 0.0499303043F,
  143203. 0.0501416554F, 0.0503534363F, 0.0505656468F, 0.0507782867F,
  143204. 0.0509913559F, 0.0512048542F, 0.0514187815F, 0.0516331376F,
  143205. 0.0518479225F, 0.0520631358F, 0.0522787775F, 0.0524948475F,
  143206. 0.0527113455F, 0.0529282715F, 0.0531456252F, 0.0533634066F,
  143207. 0.0535816154F, 0.0538002515F, 0.0540193148F, 0.0542388051F,
  143208. 0.0544587222F, 0.0546790660F, 0.0548998364F, 0.0551210331F,
  143209. 0.0553426561F, 0.0555647051F, 0.0557871801F, 0.0560100807F,
  143210. 0.0562334070F, 0.0564571587F, 0.0566813357F, 0.0569059378F,
  143211. 0.0571309649F, 0.0573564168F, 0.0575822933F, 0.0578085942F,
  143212. 0.0580353195F, 0.0582624689F, 0.0584900423F, 0.0587180396F,
  143213. 0.0589464605F, 0.0591753049F, 0.0594045726F, 0.0596342635F,
  143214. 0.0598643774F, 0.0600949141F, 0.0603258735F, 0.0605572555F,
  143215. 0.0607890597F, 0.0610212862F, 0.0612539346F, 0.0614870049F,
  143216. 0.0617204968F, 0.0619544103F, 0.0621887451F, 0.0624235010F,
  143217. 0.0626586780F, 0.0628942758F, 0.0631302942F, 0.0633667331F,
  143218. 0.0636035923F, 0.0638408717F, 0.0640785710F, 0.0643166901F,
  143219. 0.0645552288F, 0.0647941870F, 0.0650335645F, 0.0652733610F,
  143220. 0.0655135765F, 0.0657542108F, 0.0659952636F, 0.0662367348F,
  143221. 0.0664786242F, 0.0667209316F, 0.0669636570F, 0.0672068000F,
  143222. 0.0674503605F, 0.0676943384F, 0.0679387334F, 0.0681835454F,
  143223. 0.0684287742F, 0.0686744196F, 0.0689204814F, 0.0691669595F,
  143224. 0.0694138536F, 0.0696611637F, 0.0699088894F, 0.0701570307F,
  143225. 0.0704055873F, 0.0706545590F, 0.0709039458F, 0.0711537473F,
  143226. 0.0714039634F, 0.0716545939F, 0.0719056387F, 0.0721570975F,
  143227. 0.0724089702F, 0.0726612565F, 0.0729139563F, 0.0731670694F,
  143228. 0.0734205956F, 0.0736745347F, 0.0739288866F, 0.0741836510F,
  143229. 0.0744388277F, 0.0746944166F, 0.0749504175F, 0.0752068301F,
  143230. 0.0754636543F, 0.0757208899F, 0.0759785367F, 0.0762365946F,
  143231. 0.0764950632F, 0.0767539424F, 0.0770132320F, 0.0772729319F,
  143232. 0.0775330418F, 0.0777935616F, 0.0780544909F, 0.0783158298F,
  143233. 0.0785775778F, 0.0788397349F, 0.0791023009F, 0.0793652755F,
  143234. 0.0796286585F, 0.0798924498F, 0.0801566492F, 0.0804212564F,
  143235. 0.0806862712F, 0.0809516935F, 0.0812175231F, 0.0814837597F,
  143236. 0.0817504031F, 0.0820174532F, 0.0822849097F, 0.0825527724F,
  143237. 0.0828210412F, 0.0830897158F, 0.0833587960F, 0.0836282816F,
  143238. 0.0838981724F, 0.0841684682F, 0.0844391688F, 0.0847102740F,
  143239. 0.0849817835F, 0.0852536973F, 0.0855260150F, 0.0857987364F,
  143240. 0.0860718614F, 0.0863453897F, 0.0866193211F, 0.0868936554F,
  143241. 0.0871683924F, 0.0874435319F, 0.0877190737F, 0.0879950175F,
  143242. 0.0882713632F, 0.0885481105F, 0.0888252592F, 0.0891028091F,
  143243. 0.0893807600F, 0.0896591117F, 0.0899378639F, 0.0902170165F,
  143244. 0.0904965692F, 0.0907765218F, 0.0910568740F, 0.0913376258F,
  143245. 0.0916187767F, 0.0919003268F, 0.0921822756F, 0.0924646230F,
  143246. 0.0927473687F, 0.0930305126F, 0.0933140545F, 0.0935979940F,
  143247. 0.0938823310F, 0.0941670653F, 0.0944521966F, 0.0947377247F,
  143248. 0.0950236494F, 0.0953099704F, 0.0955966876F, 0.0958838007F,
  143249. 0.0961713094F, 0.0964592136F, 0.0967475131F, 0.0970362075F,
  143250. 0.0973252967F, 0.0976147805F, 0.0979046585F, 0.0981949307F,
  143251. 0.0984855967F, 0.0987766563F, 0.0990681093F, 0.0993599555F,
  143252. 0.0996521945F, 0.0999448263F, 0.1002378506F, 0.1005312671F,
  143253. 0.1008250755F, 0.1011192757F, 0.1014138675F, 0.1017088505F,
  143254. 0.1020042246F, 0.1022999895F, 0.1025961450F, 0.1028926909F,
  143255. 0.1031896268F, 0.1034869526F, 0.1037846680F, 0.1040827729F,
  143256. 0.1043812668F, 0.1046801497F, 0.1049794213F, 0.1052790813F,
  143257. 0.1055791294F, 0.1058795656F, 0.1061803894F, 0.1064816006F,
  143258. 0.1067831991F, 0.1070851846F, 0.1073875568F, 0.1076903155F,
  143259. 0.1079934604F, 0.1082969913F, 0.1086009079F, 0.1089052101F,
  143260. 0.1092098975F, 0.1095149699F, 0.1098204270F, 0.1101262687F,
  143261. 0.1104324946F, 0.1107391045F, 0.1110460982F, 0.1113534754F,
  143262. 0.1116612359F, 0.1119693793F, 0.1122779055F, 0.1125868142F,
  143263. 0.1128961052F, 0.1132057781F, 0.1135158328F, 0.1138262690F,
  143264. 0.1141370863F, 0.1144482847F, 0.1147598638F, 0.1150718233F,
  143265. 0.1153841631F, 0.1156968828F, 0.1160099822F, 0.1163234610F,
  143266. 0.1166373190F, 0.1169515559F, 0.1172661714F, 0.1175811654F,
  143267. 0.1178965374F, 0.1182122874F, 0.1185284149F, 0.1188449198F,
  143268. 0.1191618018F, 0.1194790606F, 0.1197966960F, 0.1201147076F,
  143269. 0.1204330953F, 0.1207518587F, 0.1210709976F, 0.1213905118F,
  143270. 0.1217104009F, 0.1220306647F, 0.1223513029F, 0.1226723153F,
  143271. 0.1229937016F, 0.1233154615F, 0.1236375948F, 0.1239601011F,
  143272. 0.1242829803F, 0.1246062319F, 0.1249298559F, 0.1252538518F,
  143273. 0.1255782195F, 0.1259029586F, 0.1262280689F, 0.1265535501F,
  143274. 0.1268794019F, 0.1272056241F, 0.1275322163F, 0.1278591784F,
  143275. 0.1281865099F, 0.1285142108F, 0.1288422805F, 0.1291707190F,
  143276. 0.1294995259F, 0.1298287009F, 0.1301582437F, 0.1304881542F,
  143277. 0.1308184319F, 0.1311490766F, 0.1314800881F, 0.1318114660F,
  143278. 0.1321432100F, 0.1324753200F, 0.1328077955F, 0.1331406364F,
  143279. 0.1334738422F, 0.1338074129F, 0.1341413479F, 0.1344756472F,
  143280. 0.1348103103F, 0.1351453370F, 0.1354807270F, 0.1358164801F,
  143281. 0.1361525959F, 0.1364890741F, 0.1368259145F, 0.1371631167F,
  143282. 0.1375006805F, 0.1378386056F, 0.1381768917F, 0.1385155384F,
  143283. 0.1388545456F, 0.1391939129F, 0.1395336400F, 0.1398737266F,
  143284. 0.1402141724F, 0.1405549772F, 0.1408961406F, 0.1412376623F,
  143285. 0.1415795421F, 0.1419217797F, 0.1422643746F, 0.1426073268F,
  143286. 0.1429506358F, 0.1432943013F, 0.1436383231F, 0.1439827008F,
  143287. 0.1443274342F, 0.1446725229F, 0.1450179667F, 0.1453637652F,
  143288. 0.1457099181F, 0.1460564252F, 0.1464032861F, 0.1467505006F,
  143289. 0.1470980682F, 0.1474459888F, 0.1477942620F, 0.1481428875F,
  143290. 0.1484918651F, 0.1488411942F, 0.1491908748F, 0.1495409065F,
  143291. 0.1498912889F, 0.1502420218F, 0.1505931048F, 0.1509445376F,
  143292. 0.1512963200F, 0.1516484516F, 0.1520009321F, 0.1523537612F,
  143293. 0.1527069385F, 0.1530604638F, 0.1534143368F, 0.1537685571F,
  143294. 0.1541231244F, 0.1544780384F, 0.1548332987F, 0.1551889052F,
  143295. 0.1555448574F, 0.1559011550F, 0.1562577978F, 0.1566147853F,
  143296. 0.1569721173F, 0.1573297935F, 0.1576878135F, 0.1580461771F,
  143297. 0.1584048838F, 0.1587639334F, 0.1591233255F, 0.1594830599F,
  143298. 0.1598431361F, 0.1602035540F, 0.1605643131F, 0.1609254131F,
  143299. 0.1612868537F, 0.1616486346F, 0.1620107555F, 0.1623732160F,
  143300. 0.1627360158F, 0.1630991545F, 0.1634626319F, 0.1638264476F,
  143301. 0.1641906013F, 0.1645550926F, 0.1649199212F, 0.1652850869F,
  143302. 0.1656505892F, 0.1660164278F, 0.1663826024F, 0.1667491127F,
  143303. 0.1671159583F, 0.1674831388F, 0.1678506541F, 0.1682185036F,
  143304. 0.1685866872F, 0.1689552044F, 0.1693240549F, 0.1696932384F,
  143305. 0.1700627545F, 0.1704326029F, 0.1708027833F, 0.1711732952F,
  143306. 0.1715441385F, 0.1719153127F, 0.1722868175F, 0.1726586526F,
  143307. 0.1730308176F, 0.1734033121F, 0.1737761359F, 0.1741492886F,
  143308. 0.1745227698F, 0.1748965792F, 0.1752707164F, 0.1756451812F,
  143309. 0.1760199731F, 0.1763950918F, 0.1767705370F, 0.1771463083F,
  143310. 0.1775224054F, 0.1778988279F, 0.1782755754F, 0.1786526477F,
  143311. 0.1790300444F, 0.1794077651F, 0.1797858094F, 0.1801641771F,
  143312. 0.1805428677F, 0.1809218810F, 0.1813012165F, 0.1816808739F,
  143313. 0.1820608528F, 0.1824411530F, 0.1828217739F, 0.1832027154F,
  143314. 0.1835839770F, 0.1839655584F, 0.1843474592F, 0.1847296790F,
  143315. 0.1851122175F, 0.1854950744F, 0.1858782492F, 0.1862617417F,
  143316. 0.1866455514F, 0.1870296780F, 0.1874141211F, 0.1877988804F,
  143317. 0.1881839555F, 0.1885693461F, 0.1889550517F, 0.1893410721F,
  143318. 0.1897274068F, 0.1901140555F, 0.1905010178F, 0.1908882933F,
  143319. 0.1912758818F, 0.1916637828F, 0.1920519959F, 0.1924405208F,
  143320. 0.1928293571F, 0.1932185044F, 0.1936079625F, 0.1939977308F,
  143321. 0.1943878091F, 0.1947781969F, 0.1951688939F, 0.1955598998F,
  143322. 0.1959512141F, 0.1963428364F, 0.1967347665F, 0.1971270038F,
  143323. 0.1975195482F, 0.1979123990F, 0.1983055561F, 0.1986990190F,
  143324. 0.1990927873F, 0.1994868607F, 0.1998812388F, 0.2002759212F,
  143325. 0.2006709075F, 0.2010661974F, 0.2014617904F, 0.2018576862F,
  143326. 0.2022538844F, 0.2026503847F, 0.2030471865F, 0.2034442897F,
  143327. 0.2038416937F, 0.2042393982F, 0.2046374028F, 0.2050357071F,
  143328. 0.2054343107F, 0.2058332133F, 0.2062324145F, 0.2066319138F,
  143329. 0.2070317110F, 0.2074318055F, 0.2078321970F, 0.2082328852F,
  143330. 0.2086338696F, 0.2090351498F, 0.2094367255F, 0.2098385962F,
  143331. 0.2102407617F, 0.2106432213F, 0.2110459749F, 0.2114490220F,
  143332. 0.2118523621F, 0.2122559950F, 0.2126599202F, 0.2130641373F,
  143333. 0.2134686459F, 0.2138734456F, 0.2142785361F, 0.2146839168F,
  143334. 0.2150895875F, 0.2154955478F, 0.2159017972F, 0.2163083353F,
  143335. 0.2167151617F, 0.2171222761F, 0.2175296780F, 0.2179373670F,
  143336. 0.2183453428F, 0.2187536049F, 0.2191621529F, 0.2195709864F,
  143337. 0.2199801051F, 0.2203895085F, 0.2207991961F, 0.2212091677F,
  143338. 0.2216194228F, 0.2220299610F, 0.2224407818F, 0.2228518850F,
  143339. 0.2232632699F, 0.2236749364F, 0.2240868839F, 0.2244991121F,
  143340. 0.2249116204F, 0.2253244086F, 0.2257374763F, 0.2261508229F,
  143341. 0.2265644481F, 0.2269783514F, 0.2273925326F, 0.2278069911F,
  143342. 0.2282217265F, 0.2286367384F, 0.2290520265F, 0.2294675902F,
  143343. 0.2298834292F, 0.2302995431F, 0.2307159314F, 0.2311325937F,
  143344. 0.2315495297F, 0.2319667388F, 0.2323842207F, 0.2328019749F,
  143345. 0.2332200011F, 0.2336382988F, 0.2340568675F, 0.2344757070F,
  143346. 0.2348948166F, 0.2353141961F, 0.2357338450F, 0.2361537629F,
  143347. 0.2365739493F, 0.2369944038F, 0.2374151261F, 0.2378361156F,
  143348. 0.2382573720F, 0.2386788948F, 0.2391006836F, 0.2395227380F,
  143349. 0.2399450575F, 0.2403676417F, 0.2407904902F, 0.2412136026F,
  143350. 0.2416369783F, 0.2420606171F, 0.2424845185F, 0.2429086820F,
  143351. 0.2433331072F, 0.2437577936F, 0.2441827409F, 0.2446079486F,
  143352. 0.2450334163F, 0.2454591435F, 0.2458851298F, 0.2463113747F,
  143353. 0.2467378779F, 0.2471646389F, 0.2475916573F, 0.2480189325F,
  143354. 0.2484464643F, 0.2488742521F, 0.2493022955F, 0.2497305940F,
  143355. 0.2501591473F, 0.2505879549F, 0.2510170163F, 0.2514463311F,
  143356. 0.2518758989F, 0.2523057193F, 0.2527357916F, 0.2531661157F,
  143357. 0.2535966909F, 0.2540275169F, 0.2544585931F, 0.2548899193F,
  143358. 0.2553214948F, 0.2557533193F, 0.2561853924F, 0.2566177135F,
  143359. 0.2570502822F, 0.2574830981F, 0.2579161608F, 0.2583494697F,
  143360. 0.2587830245F, 0.2592168246F, 0.2596508697F, 0.2600851593F,
  143361. 0.2605196929F, 0.2609544701F, 0.2613894904F, 0.2618247534F,
  143362. 0.2622602586F, 0.2626960055F, 0.2631319938F, 0.2635682230F,
  143363. 0.2640046925F, 0.2644414021F, 0.2648783511F, 0.2653155391F,
  143364. 0.2657529657F, 0.2661906305F, 0.2666285329F, 0.2670666725F,
  143365. 0.2675050489F, 0.2679436616F, 0.2683825101F, 0.2688215940F,
  143366. 0.2692609127F, 0.2697004660F, 0.2701402532F, 0.2705802739F,
  143367. 0.2710205278F, 0.2714610142F, 0.2719017327F, 0.2723426830F,
  143368. 0.2727838644F, 0.2732252766F, 0.2736669191F, 0.2741087914F,
  143369. 0.2745508930F, 0.2749932235F, 0.2754357824F, 0.2758785693F,
  143370. 0.2763215837F, 0.2767648251F, 0.2772082930F, 0.2776519870F,
  143371. 0.2780959066F, 0.2785400513F, 0.2789844207F, 0.2794290143F,
  143372. 0.2798738316F, 0.2803188722F, 0.2807641355F, 0.2812096211F,
  143373. 0.2816553286F, 0.2821012574F, 0.2825474071F, 0.2829937773F,
  143374. 0.2834403673F, 0.2838871768F, 0.2843342053F, 0.2847814523F,
  143375. 0.2852289174F, 0.2856765999F, 0.2861244996F, 0.2865726159F,
  143376. 0.2870209482F, 0.2874694962F, 0.2879182594F, 0.2883672372F,
  143377. 0.2888164293F, 0.2892658350F, 0.2897154540F, 0.2901652858F,
  143378. 0.2906153298F, 0.2910655856F, 0.2915160527F, 0.2919667306F,
  143379. 0.2924176189F, 0.2928687171F, 0.2933200246F, 0.2937715409F,
  143380. 0.2942232657F, 0.2946751984F, 0.2951273386F, 0.2955796856F,
  143381. 0.2960322391F, 0.2964849986F, 0.2969379636F, 0.2973911335F,
  143382. 0.2978445080F, 0.2982980864F, 0.2987518684F, 0.2992058534F,
  143383. 0.2996600409F, 0.3001144305F, 0.3005690217F, 0.3010238139F,
  143384. 0.3014788067F, 0.3019339995F, 0.3023893920F, 0.3028449835F,
  143385. 0.3033007736F, 0.3037567618F, 0.3042129477F, 0.3046693306F,
  143386. 0.3051259102F, 0.3055826859F, 0.3060396572F, 0.3064968236F,
  143387. 0.3069541847F, 0.3074117399F, 0.3078694887F, 0.3083274307F,
  143388. 0.3087855653F, 0.3092438920F, 0.3097024104F, 0.3101611199F,
  143389. 0.3106200200F, 0.3110791103F, 0.3115383902F, 0.3119978592F,
  143390. 0.3124575169F, 0.3129173627F, 0.3133773961F, 0.3138376166F,
  143391. 0.3142980238F, 0.3147586170F, 0.3152193959F, 0.3156803598F,
  143392. 0.3161415084F, 0.3166028410F, 0.3170643573F, 0.3175260566F,
  143393. 0.3179879384F, 0.3184500023F, 0.3189122478F, 0.3193746743F,
  143394. 0.3198372814F, 0.3203000685F, 0.3207630351F, 0.3212261807F,
  143395. 0.3216895048F, 0.3221530069F, 0.3226166865F, 0.3230805430F,
  143396. 0.3235445760F, 0.3240087849F, 0.3244731693F, 0.3249377285F,
  143397. 0.3254024622F, 0.3258673698F, 0.3263324507F, 0.3267977045F,
  143398. 0.3272631306F, 0.3277287286F, 0.3281944978F, 0.3286604379F,
  143399. 0.3291265482F, 0.3295928284F, 0.3300592777F, 0.3305258958F,
  143400. 0.3309926821F, 0.3314596361F, 0.3319267573F, 0.3323940451F,
  143401. 0.3328614990F, 0.3333291186F, 0.3337969033F, 0.3342648525F,
  143402. 0.3347329658F, 0.3352012427F, 0.3356696825F, 0.3361382849F,
  143403. 0.3366070492F, 0.3370759749F, 0.3375450616F, 0.3380143087F,
  143404. 0.3384837156F, 0.3389532819F, 0.3394230071F, 0.3398928905F,
  143405. 0.3403629317F, 0.3408331302F, 0.3413034854F, 0.3417739967F,
  143406. 0.3422446638F, 0.3427154860F, 0.3431864628F, 0.3436575938F,
  143407. 0.3441288782F, 0.3446003158F, 0.3450719058F, 0.3455436478F,
  143408. 0.3460155412F, 0.3464875856F, 0.3469597804F, 0.3474321250F,
  143409. 0.3479046189F, 0.3483772617F, 0.3488500527F, 0.3493229914F,
  143410. 0.3497960774F, 0.3502693100F, 0.3507426887F, 0.3512162131F,
  143411. 0.3516898825F, 0.3521636965F, 0.3526376545F, 0.3531117559F,
  143412. 0.3535860003F, 0.3540603870F, 0.3545349157F, 0.3550095856F,
  143413. 0.3554843964F, 0.3559593474F, 0.3564344381F, 0.3569096680F,
  143414. 0.3573850366F, 0.3578605432F, 0.3583361875F, 0.3588119687F,
  143415. 0.3592878865F, 0.3597639402F, 0.3602401293F, 0.3607164533F,
  143416. 0.3611929117F, 0.3616695038F, 0.3621462292F, 0.3626230873F,
  143417. 0.3631000776F, 0.3635771995F, 0.3640544525F, 0.3645318360F,
  143418. 0.3650093496F, 0.3654869926F, 0.3659647645F, 0.3664426648F,
  143419. 0.3669206930F, 0.3673988484F, 0.3678771306F, 0.3683555390F,
  143420. 0.3688340731F, 0.3693127322F, 0.3697915160F, 0.3702704237F,
  143421. 0.3707494549F, 0.3712286091F, 0.3717078857F, 0.3721872840F,
  143422. 0.3726668037F, 0.3731464441F, 0.3736262047F, 0.3741060850F,
  143423. 0.3745860843F, 0.3750662023F, 0.3755464382F, 0.3760267915F,
  143424. 0.3765072618F, 0.3769878484F, 0.3774685509F, 0.3779493686F,
  143425. 0.3784303010F, 0.3789113475F, 0.3793925076F, 0.3798737809F,
  143426. 0.3803551666F, 0.3808366642F, 0.3813182733F, 0.3817999932F,
  143427. 0.3822818234F, 0.3827637633F, 0.3832458124F, 0.3837279702F,
  143428. 0.3842102360F, 0.3846926093F, 0.3851750897F, 0.3856576764F,
  143429. 0.3861403690F, 0.3866231670F, 0.3871060696F, 0.3875890765F,
  143430. 0.3880721870F, 0.3885554007F, 0.3890387168F, 0.3895221349F,
  143431. 0.3900056544F, 0.3904892748F, 0.3909729955F, 0.3914568160F,
  143432. 0.3919407356F, 0.3924247539F, 0.3929088702F, 0.3933930841F,
  143433. 0.3938773949F, 0.3943618021F, 0.3948463052F, 0.3953309035F,
  143434. 0.3958155966F, 0.3963003838F, 0.3967852646F, 0.3972702385F,
  143435. 0.3977553048F, 0.3982404631F, 0.3987257127F, 0.3992110531F,
  143436. 0.3996964838F, 0.4001820041F, 0.4006676136F, 0.4011533116F,
  143437. 0.4016390976F, 0.4021249710F, 0.4026109313F, 0.4030969779F,
  143438. 0.4035831102F, 0.4040693277F, 0.4045556299F, 0.4050420160F,
  143439. 0.4055284857F, 0.4060150383F, 0.4065016732F, 0.4069883899F,
  143440. 0.4074751879F, 0.4079620665F, 0.4084490252F, 0.4089360635F,
  143441. 0.4094231807F, 0.4099103763F, 0.4103976498F, 0.4108850005F,
  143442. 0.4113724280F, 0.4118599315F, 0.4123475107F, 0.4128351648F,
  143443. 0.4133228934F, 0.4138106959F, 0.4142985716F, 0.4147865201F,
  143444. 0.4152745408F, 0.4157626330F, 0.4162507963F, 0.4167390301F,
  143445. 0.4172273337F, 0.4177157067F, 0.4182041484F, 0.4186926583F,
  143446. 0.4191812359F, 0.4196698805F, 0.4201585915F, 0.4206473685F,
  143447. 0.4211362108F, 0.4216251179F, 0.4221140892F, 0.4226031241F,
  143448. 0.4230922221F, 0.4235813826F, 0.4240706050F, 0.4245598887F,
  143449. 0.4250492332F, 0.4255386379F, 0.4260281022F, 0.4265176256F,
  143450. 0.4270072075F, 0.4274968473F, 0.4279865445F, 0.4284762984F,
  143451. 0.4289661086F, 0.4294559743F, 0.4299458951F, 0.4304358704F,
  143452. 0.4309258996F, 0.4314159822F, 0.4319061175F, 0.4323963050F,
  143453. 0.4328865441F, 0.4333768342F, 0.4338671749F, 0.4343575654F,
  143454. 0.4348480052F, 0.4353384938F, 0.4358290306F, 0.4363196149F,
  143455. 0.4368102463F, 0.4373009241F, 0.4377916478F, 0.4382824168F,
  143456. 0.4387732305F, 0.4392640884F, 0.4397549899F, 0.4402459343F,
  143457. 0.4407369212F, 0.4412279499F, 0.4417190198F, 0.4422101305F,
  143458. 0.4427012813F, 0.4431924717F, 0.4436837010F, 0.4441749686F,
  143459. 0.4446662742F, 0.4451576169F, 0.4456489963F, 0.4461404118F,
  143460. 0.4466318628F, 0.4471233487F, 0.4476148690F, 0.4481064230F,
  143461. 0.4485980103F, 0.4490896302F, 0.4495812821F, 0.4500729654F,
  143462. 0.4505646797F, 0.4510564243F, 0.4515481986F, 0.4520400021F,
  143463. 0.4525318341F, 0.4530236942F, 0.4535155816F, 0.4540074959F,
  143464. 0.4544994365F, 0.4549914028F, 0.4554833941F, 0.4559754100F,
  143465. 0.4564674499F, 0.4569595131F, 0.4574515991F, 0.4579437074F,
  143466. 0.4584358372F, 0.4589279881F, 0.4594201595F, 0.4599123508F,
  143467. 0.4604045615F, 0.4608967908F, 0.4613890383F, 0.4618813034F,
  143468. 0.4623735855F, 0.4628658841F, 0.4633581984F, 0.4638505281F,
  143469. 0.4643428724F, 0.4648352308F, 0.4653276028F, 0.4658199877F,
  143470. 0.4663123849F, 0.4668047940F, 0.4672972143F, 0.4677896451F,
  143471. 0.4682820861F, 0.4687745365F, 0.4692669958F, 0.4697594634F,
  143472. 0.4702519387F, 0.4707444211F, 0.4712369102F, 0.4717294052F,
  143473. 0.4722219056F, 0.4727144109F, 0.4732069204F, 0.4736994336F,
  143474. 0.4741919498F, 0.4746844686F, 0.4751769893F, 0.4756695113F,
  143475. 0.4761620341F, 0.4766545571F, 0.4771470797F, 0.4776396013F,
  143476. 0.4781321213F, 0.4786246392F, 0.4791171544F, 0.4796096663F,
  143477. 0.4801021744F, 0.4805946779F, 0.4810871765F, 0.4815796694F,
  143478. 0.4820721561F, 0.4825646360F, 0.4830571086F, 0.4835495732F,
  143479. 0.4840420293F, 0.4845344763F, 0.4850269136F, 0.4855193407F,
  143480. 0.4860117569F, 0.4865041617F, 0.4869965545F, 0.4874889347F,
  143481. 0.4879813018F, 0.4884736551F, 0.4889659941F, 0.4894583182F,
  143482. 0.4899506268F, 0.4904429193F, 0.4909351952F, 0.4914274538F,
  143483. 0.4919196947F, 0.4924119172F, 0.4929041207F, 0.4933963046F,
  143484. 0.4938884685F, 0.4943806116F, 0.4948727335F, 0.4953648335F,
  143485. 0.4958569110F, 0.4963489656F, 0.4968409965F, 0.4973330032F,
  143486. 0.4978249852F, 0.4983169419F, 0.4988088726F, 0.4993007768F,
  143487. 0.4997926539F, 0.5002845034F, 0.5007763247F, 0.5012681171F,
  143488. 0.5017598801F, 0.5022516132F, 0.5027433157F, 0.5032349871F,
  143489. 0.5037266268F, 0.5042182341F, 0.5047098086F, 0.5052013497F,
  143490. 0.5056928567F, 0.5061843292F, 0.5066757664F, 0.5071671679F,
  143491. 0.5076585330F, 0.5081498613F, 0.5086411520F, 0.5091324047F,
  143492. 0.5096236187F, 0.5101147934F, 0.5106059284F, 0.5110970230F,
  143493. 0.5115880766F, 0.5120790887F, 0.5125700587F, 0.5130609860F,
  143494. 0.5135518700F, 0.5140427102F, 0.5145335059F, 0.5150242566F,
  143495. 0.5155149618F, 0.5160056208F, 0.5164962331F, 0.5169867980F,
  143496. 0.5174773151F, 0.5179677837F, 0.5184582033F, 0.5189485733F,
  143497. 0.5194388931F, 0.5199291621F, 0.5204193798F, 0.5209095455F,
  143498. 0.5213996588F, 0.5218897190F, 0.5223797256F, 0.5228696779F,
  143499. 0.5233595755F, 0.5238494177F, 0.5243392039F, 0.5248289337F,
  143500. 0.5253186063F, 0.5258082213F, 0.5262977781F, 0.5267872760F,
  143501. 0.5272767146F, 0.5277660932F, 0.5282554112F, 0.5287446682F,
  143502. 0.5292338635F, 0.5297229965F, 0.5302120667F, 0.5307010736F,
  143503. 0.5311900164F, 0.5316788947F, 0.5321677079F, 0.5326564554F,
  143504. 0.5331451366F, 0.5336337511F, 0.5341222981F, 0.5346107771F,
  143505. 0.5350991876F, 0.5355875290F, 0.5360758007F, 0.5365640021F,
  143506. 0.5370521327F, 0.5375401920F, 0.5380281792F, 0.5385160939F,
  143507. 0.5390039355F, 0.5394917034F, 0.5399793971F, 0.5404670159F,
  143508. 0.5409545594F, 0.5414420269F, 0.5419294179F, 0.5424167318F,
  143509. 0.5429039680F, 0.5433911261F, 0.5438782053F, 0.5443652051F,
  143510. 0.5448521250F, 0.5453389644F, 0.5458257228F, 0.5463123995F,
  143511. 0.5467989940F, 0.5472855057F, 0.5477719341F, 0.5482582786F,
  143512. 0.5487445387F, 0.5492307137F, 0.5497168031F, 0.5502028063F,
  143513. 0.5506887228F, 0.5511745520F, 0.5516602934F, 0.5521459463F,
  143514. 0.5526315103F, 0.5531169847F, 0.5536023690F, 0.5540876626F,
  143515. 0.5545728649F, 0.5550579755F, 0.5555429937F, 0.5560279189F,
  143516. 0.5565127507F, 0.5569974884F, 0.5574821315F, 0.5579666794F,
  143517. 0.5584511316F, 0.5589354875F, 0.5594197465F, 0.5599039080F,
  143518. 0.5603879716F, 0.5608719367F, 0.5613558026F, 0.5618395689F,
  143519. 0.5623232350F, 0.5628068002F, 0.5632902642F, 0.5637736262F,
  143520. 0.5642568858F, 0.5647400423F, 0.5652230953F, 0.5657060442F,
  143521. 0.5661888883F, 0.5666716272F, 0.5671542603F, 0.5676367870F,
  143522. 0.5681192069F, 0.5686015192F, 0.5690837235F, 0.5695658192F,
  143523. 0.5700478058F, 0.5705296827F, 0.5710114494F, 0.5714931052F,
  143524. 0.5719746497F, 0.5724560822F, 0.5729374023F, 0.5734186094F,
  143525. 0.5738997029F, 0.5743806823F, 0.5748615470F, 0.5753422965F,
  143526. 0.5758229301F, 0.5763034475F, 0.5767838480F, 0.5772641310F,
  143527. 0.5777442960F, 0.5782243426F, 0.5787042700F, 0.5791840778F,
  143528. 0.5796637654F, 0.5801433322F, 0.5806227778F, 0.5811021016F,
  143529. 0.5815813029F, 0.5820603814F, 0.5825393363F, 0.5830181673F,
  143530. 0.5834968737F, 0.5839754549F, 0.5844539105F, 0.5849322399F,
  143531. 0.5854104425F, 0.5858885179F, 0.5863664653F, 0.5868442844F,
  143532. 0.5873219746F, 0.5877995353F, 0.5882769660F, 0.5887542661F,
  143533. 0.5892314351F, 0.5897084724F, 0.5901853776F, 0.5906621500F,
  143534. 0.5911387892F, 0.5916152945F, 0.5920916655F, 0.5925679016F,
  143535. 0.5930440022F, 0.5935199669F, 0.5939957950F, 0.5944714861F,
  143536. 0.5949470396F, 0.5954224550F, 0.5958977317F, 0.5963728692F,
  143537. 0.5968478669F, 0.5973227244F, 0.5977974411F, 0.5982720163F,
  143538. 0.5987464497F, 0.5992207407F, 0.5996948887F, 0.6001688932F,
  143539. 0.6006427537F, 0.6011164696F, 0.6015900405F, 0.6020634657F,
  143540. 0.6025367447F, 0.6030098770F, 0.6034828621F, 0.6039556995F,
  143541. 0.6044283885F, 0.6049009288F, 0.6053733196F, 0.6058455606F,
  143542. 0.6063176512F, 0.6067895909F, 0.6072613790F, 0.6077330152F,
  143543. 0.6082044989F, 0.6086758295F, 0.6091470065F, 0.6096180294F,
  143544. 0.6100888977F, 0.6105596108F, 0.6110301682F, 0.6115005694F,
  143545. 0.6119708139F, 0.6124409011F, 0.6129108305F, 0.6133806017F,
  143546. 0.6138502139F, 0.6143196669F, 0.6147889599F, 0.6152580926F,
  143547. 0.6157270643F, 0.6161958746F, 0.6166645230F, 0.6171330088F,
  143548. 0.6176013317F, 0.6180694910F, 0.6185374863F, 0.6190053171F,
  143549. 0.6194729827F, 0.6199404828F, 0.6204078167F, 0.6208749841F,
  143550. 0.6213419842F, 0.6218088168F, 0.6222754811F, 0.6227419768F,
  143551. 0.6232083032F, 0.6236744600F, 0.6241404465F, 0.6246062622F,
  143552. 0.6250719067F, 0.6255373795F, 0.6260026799F, 0.6264678076F,
  143553. 0.6269327619F, 0.6273975425F, 0.6278621487F, 0.6283265800F,
  143554. 0.6287908361F, 0.6292549163F, 0.6297188201F, 0.6301825471F,
  143555. 0.6306460966F, 0.6311094683F, 0.6315726617F, 0.6320356761F,
  143556. 0.6324985111F, 0.6329611662F, 0.6334236410F, 0.6338859348F,
  143557. 0.6343480472F, 0.6348099777F, 0.6352717257F, 0.6357332909F,
  143558. 0.6361946726F, 0.6366558704F, 0.6371168837F, 0.6375777122F,
  143559. 0.6380383552F, 0.6384988123F, 0.6389590830F, 0.6394191668F,
  143560. 0.6398790631F, 0.6403387716F, 0.6407982916F, 0.6412576228F,
  143561. 0.6417167645F, 0.6421757163F, 0.6426344778F, 0.6430930483F,
  143562. 0.6435514275F, 0.6440096149F, 0.6444676098F, 0.6449254119F,
  143563. 0.6453830207F, 0.6458404356F, 0.6462976562F, 0.6467546820F,
  143564. 0.6472115125F, 0.6476681472F, 0.6481245856F, 0.6485808273F,
  143565. 0.6490368717F, 0.6494927183F, 0.6499483667F, 0.6504038164F,
  143566. 0.6508590670F, 0.6513141178F, 0.6517689684F, 0.6522236185F,
  143567. 0.6526780673F, 0.6531323146F, 0.6535863598F, 0.6540402024F,
  143568. 0.6544938419F, 0.6549472779F, 0.6554005099F, 0.6558535373F,
  143569. 0.6563063598F, 0.6567589769F, 0.6572113880F, 0.6576635927F,
  143570. 0.6581155906F, 0.6585673810F, 0.6590189637F, 0.6594703380F,
  143571. 0.6599215035F, 0.6603724598F, 0.6608232064F, 0.6612737427F,
  143572. 0.6617240684F, 0.6621741829F, 0.6626240859F, 0.6630737767F,
  143573. 0.6635232550F, 0.6639725202F, 0.6644215720F, 0.6648704098F,
  143574. 0.6653190332F, 0.6657674417F, 0.6662156348F, 0.6666636121F,
  143575. 0.6671113731F, 0.6675589174F, 0.6680062445F, 0.6684533538F,
  143576. 0.6689002450F, 0.6693469177F, 0.6697933712F, 0.6702396052F,
  143577. 0.6706856193F, 0.6711314129F, 0.6715769855F, 0.6720223369F,
  143578. 0.6724674664F, 0.6729123736F, 0.6733570581F, 0.6738015194F,
  143579. 0.6742457570F, 0.6746897706F, 0.6751335596F, 0.6755771236F,
  143580. 0.6760204621F, 0.6764635747F, 0.6769064609F, 0.6773491204F,
  143581. 0.6777915525F, 0.6782337570F, 0.6786757332F, 0.6791174809F,
  143582. 0.6795589995F, 0.6800002886F, 0.6804413477F, 0.6808821765F,
  143583. 0.6813227743F, 0.6817631409F, 0.6822032758F, 0.6826431785F,
  143584. 0.6830828485F, 0.6835222855F, 0.6839614890F, 0.6844004585F,
  143585. 0.6848391936F, 0.6852776939F, 0.6857159589F, 0.6861539883F,
  143586. 0.6865917815F, 0.6870293381F, 0.6874666576F, 0.6879037398F,
  143587. 0.6883405840F, 0.6887771899F, 0.6892135571F, 0.6896496850F,
  143588. 0.6900855733F, 0.6905212216F, 0.6909566294F, 0.6913917963F,
  143589. 0.6918267218F, 0.6922614055F, 0.6926958471F, 0.6931300459F,
  143590. 0.6935640018F, 0.6939977141F, 0.6944311825F, 0.6948644066F,
  143591. 0.6952973859F, 0.6957301200F, 0.6961626085F, 0.6965948510F,
  143592. 0.6970268470F, 0.6974585961F, 0.6978900980F, 0.6983213521F,
  143593. 0.6987523580F, 0.6991831154F, 0.6996136238F, 0.7000438828F,
  143594. 0.7004738921F, 0.7009036510F, 0.7013331594F, 0.7017624166F,
  143595. 0.7021914224F, 0.7026201763F, 0.7030486779F, 0.7034769268F,
  143596. 0.7039049226F, 0.7043326648F, 0.7047601531F, 0.7051873870F,
  143597. 0.7056143662F, 0.7060410902F, 0.7064675586F, 0.7068937711F,
  143598. 0.7073197271F, 0.7077454264F, 0.7081708684F, 0.7085960529F,
  143599. 0.7090209793F, 0.7094456474F, 0.7098700566F, 0.7102942066F,
  143600. 0.7107180970F, 0.7111417274F, 0.7115650974F, 0.7119882066F,
  143601. 0.7124110545F, 0.7128336409F, 0.7132559653F, 0.7136780272F,
  143602. 0.7140998264F, 0.7145213624F, 0.7149426348F, 0.7153636433F,
  143603. 0.7157843874F, 0.7162048668F, 0.7166250810F, 0.7170450296F,
  143604. 0.7174647124F, 0.7178841289F, 0.7183032786F, 0.7187221613F,
  143605. 0.7191407765F, 0.7195591239F, 0.7199772030F, 0.7203950135F,
  143606. 0.7208125550F, 0.7212298271F, 0.7216468294F, 0.7220635616F,
  143607. 0.7224800233F, 0.7228962140F, 0.7233121335F, 0.7237277813F,
  143608. 0.7241431571F, 0.7245582604F, 0.7249730910F, 0.7253876484F,
  143609. 0.7258019322F, 0.7262159422F, 0.7266296778F, 0.7270431388F,
  143610. 0.7274563247F, 0.7278692353F, 0.7282818700F, 0.7286942287F,
  143611. 0.7291063108F, 0.7295181160F, 0.7299296440F, 0.7303408944F,
  143612. 0.7307518669F, 0.7311625609F, 0.7315729763F, 0.7319831126F,
  143613. 0.7323929695F, 0.7328025466F, 0.7332118435F, 0.7336208600F,
  143614. 0.7340295955F, 0.7344380499F, 0.7348462226F, 0.7352541134F,
  143615. 0.7356617220F, 0.7360690478F, 0.7364760907F, 0.7368828502F,
  143616. 0.7372893259F, 0.7376955176F, 0.7381014249F, 0.7385070475F,
  143617. 0.7389123849F, 0.7393174368F, 0.7397222029F, 0.7401266829F,
  143618. 0.7405308763F, 0.7409347829F, 0.7413384023F, 0.7417417341F,
  143619. 0.7421447780F, 0.7425475338F, 0.7429500009F, 0.7433521791F,
  143620. 0.7437540681F, 0.7441556674F, 0.7445569769F, 0.7449579960F,
  143621. 0.7453587245F, 0.7457591621F, 0.7461593084F, 0.7465591631F,
  143622. 0.7469587259F, 0.7473579963F, 0.7477569741F, 0.7481556590F,
  143623. 0.7485540506F, 0.7489521486F, 0.7493499526F, 0.7497474623F,
  143624. 0.7501446775F, 0.7505415977F, 0.7509382227F, 0.7513345521F,
  143625. 0.7517305856F, 0.7521263229F, 0.7525217636F, 0.7529169074F,
  143626. 0.7533117541F, 0.7537063032F, 0.7541005545F, 0.7544945076F,
  143627. 0.7548881623F, 0.7552815182F, 0.7556745749F, 0.7560673323F,
  143628. 0.7564597899F, 0.7568519474F, 0.7572438046F, 0.7576353611F,
  143629. 0.7580266166F, 0.7584175708F, 0.7588082235F, 0.7591985741F,
  143630. 0.7595886226F, 0.7599783685F, 0.7603678116F, 0.7607569515F,
  143631. 0.7611457879F, 0.7615343206F, 0.7619225493F, 0.7623104735F,
  143632. 0.7626980931F, 0.7630854078F, 0.7634724171F, 0.7638591209F,
  143633. 0.7642455188F, 0.7646316106F, 0.7650173959F, 0.7654028744F,
  143634. 0.7657880459F, 0.7661729100F, 0.7665574664F, 0.7669417150F,
  143635. 0.7673256553F, 0.7677092871F, 0.7680926100F, 0.7684756239F,
  143636. 0.7688583284F, 0.7692407232F, 0.7696228080F, 0.7700045826F,
  143637. 0.7703860467F, 0.7707671999F, 0.7711480420F, 0.7715285728F,
  143638. 0.7719087918F, 0.7722886989F, 0.7726682938F, 0.7730475762F,
  143639. 0.7734265458F, 0.7738052023F, 0.7741835454F, 0.7745615750F,
  143640. 0.7749392906F, 0.7753166921F, 0.7756937791F, 0.7760705514F,
  143641. 0.7764470087F, 0.7768231508F, 0.7771989773F, 0.7775744880F,
  143642. 0.7779496827F, 0.7783245610F, 0.7786991227F, 0.7790733676F,
  143643. 0.7794472953F, 0.7798209056F, 0.7801941982F, 0.7805671729F,
  143644. 0.7809398294F, 0.7813121675F, 0.7816841869F, 0.7820558873F,
  143645. 0.7824272684F, 0.7827983301F, 0.7831690720F, 0.7835394940F,
  143646. 0.7839095957F, 0.7842793768F, 0.7846488373F, 0.7850179767F,
  143647. 0.7853867948F, 0.7857552914F, 0.7861234663F, 0.7864913191F,
  143648. 0.7868588497F, 0.7872260578F, 0.7875929431F, 0.7879595055F,
  143649. 0.7883257445F, 0.7886916601F, 0.7890572520F, 0.7894225198F,
  143650. 0.7897874635F, 0.7901520827F, 0.7905163772F, 0.7908803468F,
  143651. 0.7912439912F, 0.7916073102F, 0.7919703035F, 0.7923329710F,
  143652. 0.7926953124F, 0.7930573274F, 0.7934190158F, 0.7937803774F,
  143653. 0.7941414120F, 0.7945021193F, 0.7948624991F, 0.7952225511F,
  143654. 0.7955822752F, 0.7959416711F, 0.7963007387F, 0.7966594775F,
  143655. 0.7970178875F, 0.7973759685F, 0.7977337201F, 0.7980911422F,
  143656. 0.7984482346F, 0.7988049970F, 0.7991614292F, 0.7995175310F,
  143657. 0.7998733022F, 0.8002287426F, 0.8005838519F, 0.8009386299F,
  143658. 0.8012930765F, 0.8016471914F, 0.8020009744F, 0.8023544253F,
  143659. 0.8027075438F, 0.8030603298F, 0.8034127831F, 0.8037649035F,
  143660. 0.8041166906F, 0.8044681445F, 0.8048192647F, 0.8051700512F,
  143661. 0.8055205038F, 0.8058706222F, 0.8062204062F, 0.8065698556F,
  143662. 0.8069189702F, 0.8072677499F, 0.8076161944F, 0.8079643036F,
  143663. 0.8083120772F, 0.8086595151F, 0.8090066170F, 0.8093533827F,
  143664. 0.8096998122F, 0.8100459051F, 0.8103916613F, 0.8107370806F,
  143665. 0.8110821628F, 0.8114269077F, 0.8117713151F, 0.8121153849F,
  143666. 0.8124591169F, 0.8128025108F, 0.8131455666F, 0.8134882839F,
  143667. 0.8138306627F, 0.8141727027F, 0.8145144038F, 0.8148557658F,
  143668. 0.8151967886F, 0.8155374718F, 0.8158778154F, 0.8162178192F,
  143669. 0.8165574830F, 0.8168968067F, 0.8172357900F, 0.8175744328F,
  143670. 0.8179127349F, 0.8182506962F, 0.8185883164F, 0.8189255955F,
  143671. 0.8192625332F, 0.8195991295F, 0.8199353840F, 0.8202712967F,
  143672. 0.8206068673F, 0.8209420958F, 0.8212769820F, 0.8216115256F,
  143673. 0.8219457266F, 0.8222795848F, 0.8226131000F, 0.8229462721F,
  143674. 0.8232791009F, 0.8236115863F, 0.8239437280F, 0.8242755260F,
  143675. 0.8246069801F, 0.8249380901F, 0.8252688559F, 0.8255992774F,
  143676. 0.8259293544F, 0.8262590867F, 0.8265884741F, 0.8269175167F,
  143677. 0.8272462141F, 0.8275745663F, 0.8279025732F, 0.8282302344F,
  143678. 0.8285575501F, 0.8288845199F, 0.8292111437F, 0.8295374215F,
  143679. 0.8298633530F, 0.8301889382F, 0.8305141768F, 0.8308390688F,
  143680. 0.8311636141F, 0.8314878124F, 0.8318116637F, 0.8321351678F,
  143681. 0.8324583246F, 0.8327811340F, 0.8331035957F, 0.8334257098F,
  143682. 0.8337474761F, 0.8340688944F, 0.8343899647F, 0.8347106867F,
  143683. 0.8350310605F, 0.8353510857F, 0.8356707624F, 0.8359900904F,
  143684. 0.8363090696F, 0.8366276999F, 0.8369459811F, 0.8372639131F,
  143685. 0.8375814958F, 0.8378987292F, 0.8382156130F, 0.8385321472F,
  143686. 0.8388483316F, 0.8391641662F, 0.8394796508F, 0.8397947853F,
  143687. 0.8401095697F, 0.8404240037F, 0.8407380873F, 0.8410518204F,
  143688. 0.8413652029F, 0.8416782347F, 0.8419909156F, 0.8423032456F,
  143689. 0.8426152245F, 0.8429268523F, 0.8432381289F, 0.8435490541F,
  143690. 0.8438596279F, 0.8441698502F, 0.8444797208F, 0.8447892396F,
  143691. 0.8450984067F, 0.8454072218F, 0.8457156849F, 0.8460237959F,
  143692. 0.8463315547F, 0.8466389612F, 0.8469460154F, 0.8472527170F,
  143693. 0.8475590661F, 0.8478650625F, 0.8481707063F, 0.8484759971F,
  143694. 0.8487809351F, 0.8490855201F, 0.8493897521F, 0.8496936308F,
  143695. 0.8499971564F, 0.8503003286F, 0.8506031474F, 0.8509056128F,
  143696. 0.8512077246F, 0.8515094828F, 0.8518108872F, 0.8521119379F,
  143697. 0.8524126348F, 0.8527129777F, 0.8530129666F, 0.8533126015F,
  143698. 0.8536118822F, 0.8539108087F, 0.8542093809F, 0.8545075988F,
  143699. 0.8548054623F, 0.8551029712F, 0.8554001257F, 0.8556969255F,
  143700. 0.8559933707F, 0.8562894611F, 0.8565851968F, 0.8568805775F,
  143701. 0.8571756034F, 0.8574702743F, 0.8577645902F, 0.8580585509F,
  143702. 0.8583521566F, 0.8586454070F, 0.8589383021F, 0.8592308420F,
  143703. 0.8595230265F, 0.8598148556F, 0.8601063292F, 0.8603974473F,
  143704. 0.8606882098F, 0.8609786167F, 0.8612686680F, 0.8615583636F,
  143705. 0.8618477034F, 0.8621366874F, 0.8624253156F, 0.8627135878F,
  143706. 0.8630015042F, 0.8632890646F, 0.8635762690F, 0.8638631173F,
  143707. 0.8641496096F, 0.8644357457F, 0.8647215257F, 0.8650069495F,
  143708. 0.8652920171F, 0.8655767283F, 0.8658610833F, 0.8661450820F,
  143709. 0.8664287243F, 0.8667120102F, 0.8669949397F, 0.8672775127F,
  143710. 0.8675597293F, 0.8678415894F, 0.8681230929F, 0.8684042398F,
  143711. 0.8686850302F, 0.8689654640F, 0.8692455412F, 0.8695252617F,
  143712. 0.8698046255F, 0.8700836327F, 0.8703622831F, 0.8706405768F,
  143713. 0.8709185138F, 0.8711960940F, 0.8714733174F, 0.8717501840F,
  143714. 0.8720266939F, 0.8723028469F, 0.8725786430F, 0.8728540824F,
  143715. 0.8731291648F, 0.8734038905F, 0.8736782592F, 0.8739522711F,
  143716. 0.8742259261F, 0.8744992242F, 0.8747721653F, 0.8750447496F,
  143717. 0.8753169770F, 0.8755888475F, 0.8758603611F, 0.8761315177F,
  143718. 0.8764023175F, 0.8766727603F, 0.8769428462F, 0.8772125752F,
  143719. 0.8774819474F, 0.8777509626F, 0.8780196209F, 0.8782879224F,
  143720. 0.8785558669F, 0.8788234546F, 0.8790906854F, 0.8793575594F,
  143721. 0.8796240765F, 0.8798902368F, 0.8801560403F, 0.8804214870F,
  143722. 0.8806865768F, 0.8809513099F, 0.8812156863F, 0.8814797059F,
  143723. 0.8817433687F, 0.8820066749F, 0.8822696243F, 0.8825322171F,
  143724. 0.8827944532F, 0.8830563327F, 0.8833178556F, 0.8835790219F,
  143725. 0.8838398316F, 0.8841002848F, 0.8843603815F, 0.8846201217F,
  143726. 0.8848795054F, 0.8851385327F, 0.8853972036F, 0.8856555182F,
  143727. 0.8859134764F, 0.8861710783F, 0.8864283239F, 0.8866852133F,
  143728. 0.8869417464F, 0.8871979234F, 0.8874537443F, 0.8877092090F,
  143729. 0.8879643177F, 0.8882190704F, 0.8884734671F, 0.8887275078F,
  143730. 0.8889811927F, 0.8892345216F, 0.8894874948F, 0.8897401122F,
  143731. 0.8899923738F, 0.8902442798F, 0.8904958301F, 0.8907470248F,
  143732. 0.8909978640F, 0.8912483477F, 0.8914984759F, 0.8917482487F,
  143733. 0.8919976662F, 0.8922467284F, 0.8924954353F, 0.8927437871F,
  143734. 0.8929917837F, 0.8932394252F, 0.8934867118F, 0.8937336433F,
  143735. 0.8939802199F, 0.8942264417F, 0.8944723087F, 0.8947178210F,
  143736. 0.8949629785F, 0.8952077815F, 0.8954522299F, 0.8956963239F,
  143737. 0.8959400634F, 0.8961834486F, 0.8964264795F, 0.8966691561F,
  143738. 0.8969114786F, 0.8971534470F, 0.8973950614F, 0.8976363219F,
  143739. 0.8978772284F, 0.8981177812F, 0.8983579802F, 0.8985978256F,
  143740. 0.8988373174F, 0.8990764556F, 0.8993152405F, 0.8995536720F,
  143741. 0.8997917502F, 0.9000294751F, 0.9002668470F, 0.9005038658F,
  143742. 0.9007405317F, 0.9009768446F, 0.9012128048F, 0.9014484123F,
  143743. 0.9016836671F, 0.9019185693F, 0.9021531191F, 0.9023873165F,
  143744. 0.9026211616F, 0.9028546546F, 0.9030877954F, 0.9033205841F,
  143745. 0.9035530210F, 0.9037851059F, 0.9040168392F, 0.9042482207F,
  143746. 0.9044792507F, 0.9047099293F, 0.9049402564F, 0.9051702323F,
  143747. 0.9053998569F, 0.9056291305F, 0.9058580531F, 0.9060866248F,
  143748. 0.9063148457F, 0.9065427159F, 0.9067702355F, 0.9069974046F,
  143749. 0.9072242233F, 0.9074506917F, 0.9076768100F, 0.9079025782F,
  143750. 0.9081279964F, 0.9083530647F, 0.9085777833F, 0.9088021523F,
  143751. 0.9090261717F, 0.9092498417F, 0.9094731623F, 0.9096961338F,
  143752. 0.9099187561F, 0.9101410295F, 0.9103629540F, 0.9105845297F,
  143753. 0.9108057568F, 0.9110266354F, 0.9112471656F, 0.9114673475F,
  143754. 0.9116871812F, 0.9119066668F, 0.9121258046F, 0.9123445945F,
  143755. 0.9125630367F, 0.9127811314F, 0.9129988786F, 0.9132162785F,
  143756. 0.9134333312F, 0.9136500368F, 0.9138663954F, 0.9140824073F,
  143757. 0.9142980724F, 0.9145133910F, 0.9147283632F, 0.9149429890F,
  143758. 0.9151572687F, 0.9153712023F, 0.9155847900F, 0.9157980319F,
  143759. 0.9160109282F, 0.9162234790F, 0.9164356844F, 0.9166475445F,
  143760. 0.9168590595F, 0.9170702296F, 0.9172810548F, 0.9174915354F,
  143761. 0.9177016714F, 0.9179114629F, 0.9181209102F, 0.9183300134F,
  143762. 0.9185387726F, 0.9187471879F, 0.9189552595F, 0.9191629876F,
  143763. 0.9193703723F, 0.9195774136F, 0.9197841119F, 0.9199904672F,
  143764. 0.9201964797F, 0.9204021495F, 0.9206074767F, 0.9208124616F,
  143765. 0.9210171043F, 0.9212214049F, 0.9214253636F, 0.9216289805F,
  143766. 0.9218322558F, 0.9220351896F, 0.9222377821F, 0.9224400335F,
  143767. 0.9226419439F, 0.9228435134F, 0.9230447423F, 0.9232456307F,
  143768. 0.9234461787F, 0.9236463865F, 0.9238462543F, 0.9240457822F,
  143769. 0.9242449704F, 0.9244438190F, 0.9246423282F, 0.9248404983F,
  143770. 0.9250383293F, 0.9252358214F, 0.9254329747F, 0.9256297896F,
  143771. 0.9258262660F, 0.9260224042F, 0.9262182044F, 0.9264136667F,
  143772. 0.9266087913F, 0.9268035783F, 0.9269980280F, 0.9271921405F,
  143773. 0.9273859160F, 0.9275793546F, 0.9277724566F, 0.9279652221F,
  143774. 0.9281576513F, 0.9283497443F, 0.9285415014F, 0.9287329227F,
  143775. 0.9289240084F, 0.9291147586F, 0.9293051737F, 0.9294952536F,
  143776. 0.9296849987F, 0.9298744091F, 0.9300634850F, 0.9302522266F,
  143777. 0.9304406340F, 0.9306287074F, 0.9308164471F, 0.9310038532F,
  143778. 0.9311909259F, 0.9313776654F, 0.9315640719F, 0.9317501455F,
  143779. 0.9319358865F, 0.9321212951F, 0.9323063713F, 0.9324911155F,
  143780. 0.9326755279F, 0.9328596085F, 0.9330433577F, 0.9332267756F,
  143781. 0.9334098623F, 0.9335926182F, 0.9337750434F, 0.9339571380F,
  143782. 0.9341389023F, 0.9343203366F, 0.9345014409F, 0.9346822155F,
  143783. 0.9348626606F, 0.9350427763F, 0.9352225630F, 0.9354020207F,
  143784. 0.9355811498F, 0.9357599503F, 0.9359384226F, 0.9361165667F,
  143785. 0.9362943830F, 0.9364718716F, 0.9366490327F, 0.9368258666F,
  143786. 0.9370023733F, 0.9371785533F, 0.9373544066F, 0.9375299335F,
  143787. 0.9377051341F, 0.9378800087F, 0.9380545576F, 0.9382287809F,
  143788. 0.9384026787F, 0.9385762515F, 0.9387494993F, 0.9389224223F,
  143789. 0.9390950209F, 0.9392672951F, 0.9394392453F, 0.9396108716F,
  143790. 0.9397821743F, 0.9399531536F, 0.9401238096F, 0.9402941427F,
  143791. 0.9404641530F, 0.9406338407F, 0.9408032061F, 0.9409722495F,
  143792. 0.9411409709F, 0.9413093707F, 0.9414774491F, 0.9416452062F,
  143793. 0.9418126424F, 0.9419797579F, 0.9421465528F, 0.9423130274F,
  143794. 0.9424791819F, 0.9426450166F, 0.9428105317F, 0.9429757274F,
  143795. 0.9431406039F, 0.9433051616F, 0.9434694005F, 0.9436333209F,
  143796. 0.9437969232F, 0.9439602074F, 0.9441231739F, 0.9442858229F,
  143797. 0.9444481545F, 0.9446101691F, 0.9447718669F, 0.9449332481F,
  143798. 0.9450943129F, 0.9452550617F, 0.9454154945F, 0.9455756118F,
  143799. 0.9457354136F, 0.9458949003F, 0.9460540721F, 0.9462129292F,
  143800. 0.9463714719F, 0.9465297003F, 0.9466876149F, 0.9468452157F,
  143801. 0.9470025031F, 0.9471594772F, 0.9473161384F, 0.9474724869F,
  143802. 0.9476285229F, 0.9477842466F, 0.9479396584F, 0.9480947585F,
  143803. 0.9482495470F, 0.9484040243F, 0.9485581906F, 0.9487120462F,
  143804. 0.9488655913F, 0.9490188262F, 0.9491717511F, 0.9493243662F,
  143805. 0.9494766718F, 0.9496286683F, 0.9497803557F, 0.9499317345F,
  143806. 0.9500828047F, 0.9502335668F, 0.9503840209F, 0.9505341673F,
  143807. 0.9506840062F, 0.9508335380F, 0.9509827629F, 0.9511316810F,
  143808. 0.9512802928F, 0.9514285984F, 0.9515765982F, 0.9517242923F,
  143809. 0.9518716810F, 0.9520187646F, 0.9521655434F, 0.9523120176F,
  143810. 0.9524581875F, 0.9526040534F, 0.9527496154F, 0.9528948739F,
  143811. 0.9530398292F, 0.9531844814F, 0.9533288310F, 0.9534728780F,
  143812. 0.9536166229F, 0.9537600659F, 0.9539032071F, 0.9540460470F,
  143813. 0.9541885858F, 0.9543308237F, 0.9544727611F, 0.9546143981F,
  143814. 0.9547557351F, 0.9548967723F, 0.9550375100F, 0.9551779485F,
  143815. 0.9553180881F, 0.9554579290F, 0.9555974714F, 0.9557367158F,
  143816. 0.9558756623F, 0.9560143112F, 0.9561526628F, 0.9562907174F,
  143817. 0.9564284752F, 0.9565659366F, 0.9567031017F, 0.9568399710F,
  143818. 0.9569765446F, 0.9571128229F, 0.9572488061F, 0.9573844944F,
  143819. 0.9575198883F, 0.9576549879F, 0.9577897936F, 0.9579243056F,
  143820. 0.9580585242F, 0.9581924497F, 0.9583260824F, 0.9584594226F,
  143821. 0.9585924705F, 0.9587252264F, 0.9588576906F, 0.9589898634F,
  143822. 0.9591217452F, 0.9592533360F, 0.9593846364F, 0.9595156465F,
  143823. 0.9596463666F, 0.9597767971F, 0.9599069382F, 0.9600367901F,
  143824. 0.9601663533F, 0.9602956279F, 0.9604246143F, 0.9605533128F,
  143825. 0.9606817236F, 0.9608098471F, 0.9609376835F, 0.9610652332F,
  143826. 0.9611924963F, 0.9613194733F, 0.9614461644F, 0.9615725699F,
  143827. 0.9616986901F, 0.9618245253F, 0.9619500757F, 0.9620753418F,
  143828. 0.9622003238F, 0.9623250219F, 0.9624494365F, 0.9625735679F,
  143829. 0.9626974163F, 0.9628209821F, 0.9629442656F, 0.9630672671F,
  143830. 0.9631899868F, 0.9633124251F, 0.9634345822F, 0.9635564585F,
  143831. 0.9636780543F, 0.9637993699F, 0.9639204056F, 0.9640411616F,
  143832. 0.9641616383F, 0.9642818359F, 0.9644017549F, 0.9645213955F,
  143833. 0.9646407579F, 0.9647598426F, 0.9648786497F, 0.9649971797F,
  143834. 0.9651154328F, 0.9652334092F, 0.9653511095F, 0.9654685337F,
  143835. 0.9655856823F, 0.9657025556F, 0.9658191538F, 0.9659354773F,
  143836. 0.9660515263F, 0.9661673013F, 0.9662828024F, 0.9663980300F,
  143837. 0.9665129845F, 0.9666276660F, 0.9667420750F, 0.9668562118F,
  143838. 0.9669700766F, 0.9670836698F, 0.9671969917F, 0.9673100425F,
  143839. 0.9674228227F, 0.9675353325F, 0.9676475722F, 0.9677595422F,
  143840. 0.9678712428F, 0.9679826742F, 0.9680938368F, 0.9682047309F,
  143841. 0.9683153569F, 0.9684257150F, 0.9685358056F, 0.9686456289F,
  143842. 0.9687551853F, 0.9688644752F, 0.9689734987F, 0.9690822564F,
  143843. 0.9691907483F, 0.9692989750F, 0.9694069367F, 0.9695146337F,
  143844. 0.9696220663F, 0.9697292349F, 0.9698361398F, 0.9699427813F,
  143845. 0.9700491597F, 0.9701552754F, 0.9702611286F, 0.9703667197F,
  143846. 0.9704720490F, 0.9705771169F, 0.9706819236F, 0.9707864695F,
  143847. 0.9708907549F, 0.9709947802F, 0.9710985456F, 0.9712020514F,
  143848. 0.9713052981F, 0.9714082859F, 0.9715110151F, 0.9716134862F,
  143849. 0.9717156993F, 0.9718176549F, 0.9719193532F, 0.9720207946F,
  143850. 0.9721219794F, 0.9722229080F, 0.9723235806F, 0.9724239976F,
  143851. 0.9725241593F, 0.9726240661F, 0.9727237183F, 0.9728231161F,
  143852. 0.9729222601F, 0.9730211503F, 0.9731197873F, 0.9732181713F,
  143853. 0.9733163027F, 0.9734141817F, 0.9735118088F, 0.9736091842F,
  143854. 0.9737063083F, 0.9738031814F, 0.9738998039F, 0.9739961760F,
  143855. 0.9740922981F, 0.9741881706F, 0.9742837938F, 0.9743791680F,
  143856. 0.9744742935F, 0.9745691707F, 0.9746637999F, 0.9747581814F,
  143857. 0.9748523157F, 0.9749462029F, 0.9750398435F, 0.9751332378F,
  143858. 0.9752263861F, 0.9753192887F, 0.9754119461F, 0.9755043585F,
  143859. 0.9755965262F, 0.9756884496F, 0.9757801291F, 0.9758715650F,
  143860. 0.9759627575F, 0.9760537071F, 0.9761444141F, 0.9762348789F,
  143861. 0.9763251016F, 0.9764150828F, 0.9765048228F, 0.9765943218F,
  143862. 0.9766835802F, 0.9767725984F, 0.9768613767F, 0.9769499154F,
  143863. 0.9770382149F, 0.9771262755F, 0.9772140976F, 0.9773016815F,
  143864. 0.9773890275F, 0.9774761360F, 0.9775630073F, 0.9776496418F,
  143865. 0.9777360398F, 0.9778222016F, 0.9779081277F, 0.9779938182F,
  143866. 0.9780792736F, 0.9781644943F, 0.9782494805F, 0.9783342326F,
  143867. 0.9784187509F, 0.9785030359F, 0.9785870877F, 0.9786709069F,
  143868. 0.9787544936F, 0.9788378484F, 0.9789209714F, 0.9790038631F,
  143869. 0.9790865238F, 0.9791689538F, 0.9792511535F, 0.9793331232F,
  143870. 0.9794148633F, 0.9794963742F, 0.9795776561F, 0.9796587094F,
  143871. 0.9797395345F, 0.9798201316F, 0.9799005013F, 0.9799806437F,
  143872. 0.9800605593F, 0.9801402483F, 0.9802197112F, 0.9802989483F,
  143873. 0.9803779600F, 0.9804567465F, 0.9805353082F, 0.9806136455F,
  143874. 0.9806917587F, 0.9807696482F, 0.9808473143F, 0.9809247574F,
  143875. 0.9810019778F, 0.9810789759F, 0.9811557519F, 0.9812323064F,
  143876. 0.9813086395F, 0.9813847517F, 0.9814606433F, 0.9815363147F,
  143877. 0.9816117662F, 0.9816869981F, 0.9817620108F, 0.9818368047F,
  143878. 0.9819113801F, 0.9819857374F, 0.9820598769F, 0.9821337989F,
  143879. 0.9822075038F, 0.9822809920F, 0.9823542638F, 0.9824273195F,
  143880. 0.9825001596F, 0.9825727843F, 0.9826451940F, 0.9827173891F,
  143881. 0.9827893700F, 0.9828611368F, 0.9829326901F, 0.9830040302F,
  143882. 0.9830751574F, 0.9831460720F, 0.9832167745F, 0.9832872652F,
  143883. 0.9833575444F, 0.9834276124F, 0.9834974697F, 0.9835671166F,
  143884. 0.9836365535F, 0.9837057806F, 0.9837747983F, 0.9838436071F,
  143885. 0.9839122072F, 0.9839805990F, 0.9840487829F, 0.9841167591F,
  143886. 0.9841845282F, 0.9842520903F, 0.9843194459F, 0.9843865953F,
  143887. 0.9844535389F, 0.9845202771F, 0.9845868101F, 0.9846531383F,
  143888. 0.9847192622F, 0.9847851820F, 0.9848508980F, 0.9849164108F,
  143889. 0.9849817205F, 0.9850468276F, 0.9851117324F, 0.9851764352F,
  143890. 0.9852409365F, 0.9853052366F, 0.9853693358F, 0.9854332344F,
  143891. 0.9854969330F, 0.9855604317F, 0.9856237309F, 0.9856868310F,
  143892. 0.9857497325F, 0.9858124355F, 0.9858749404F, 0.9859372477F,
  143893. 0.9859993577F, 0.9860612707F, 0.9861229871F, 0.9861845072F,
  143894. 0.9862458315F, 0.9863069601F, 0.9863678936F, 0.9864286322F,
  143895. 0.9864891764F, 0.9865495264F, 0.9866096826F, 0.9866696454F,
  143896. 0.9867294152F, 0.9867889922F, 0.9868483769F, 0.9869075695F,
  143897. 0.9869665706F, 0.9870253803F, 0.9870839991F, 0.9871424273F,
  143898. 0.9872006653F, 0.9872587135F, 0.9873165721F, 0.9873742415F,
  143899. 0.9874317222F, 0.9874890144F, 0.9875461185F, 0.9876030348F,
  143900. 0.9876597638F, 0.9877163057F, 0.9877726610F, 0.9878288300F,
  143901. 0.9878848130F, 0.9879406104F, 0.9879962225F, 0.9880516497F,
  143902. 0.9881068924F, 0.9881619509F, 0.9882168256F, 0.9882715168F,
  143903. 0.9883260249F, 0.9883803502F, 0.9884344931F, 0.9884884539F,
  143904. 0.9885422331F, 0.9885958309F, 0.9886492477F, 0.9887024838F,
  143905. 0.9887555397F, 0.9888084157F, 0.9888611120F, 0.9889136292F,
  143906. 0.9889659675F, 0.9890181273F, 0.9890701089F, 0.9891219128F,
  143907. 0.9891735392F, 0.9892249885F, 0.9892762610F, 0.9893273572F,
  143908. 0.9893782774F, 0.9894290219F, 0.9894795911F, 0.9895299853F,
  143909. 0.9895802049F, 0.9896302502F, 0.9896801217F, 0.9897298196F,
  143910. 0.9897793443F, 0.9898286961F, 0.9898778755F, 0.9899268828F,
  143911. 0.9899757183F, 0.9900243823F, 0.9900728753F, 0.9901211976F,
  143912. 0.9901693495F, 0.9902173314F, 0.9902651436F, 0.9903127865F,
  143913. 0.9903602605F, 0.9904075659F, 0.9904547031F, 0.9905016723F,
  143914. 0.9905484740F, 0.9905951086F, 0.9906415763F, 0.9906878775F,
  143915. 0.9907340126F, 0.9907799819F, 0.9908257858F, 0.9908714247F,
  143916. 0.9909168988F, 0.9909622086F, 0.9910073543F, 0.9910523364F,
  143917. 0.9910971552F, 0.9911418110F, 0.9911863042F, 0.9912306351F,
  143918. 0.9912748042F, 0.9913188117F, 0.9913626580F, 0.9914063435F,
  143919. 0.9914498684F, 0.9914932333F, 0.9915364383F, 0.9915794839F,
  143920. 0.9916223703F, 0.9916650981F, 0.9917076674F, 0.9917500787F,
  143921. 0.9917923323F, 0.9918344286F, 0.9918763679F, 0.9919181505F,
  143922. 0.9919597769F, 0.9920012473F, 0.9920425621F, 0.9920837217F,
  143923. 0.9921247263F, 0.9921655765F, 0.9922062724F, 0.9922468145F,
  143924. 0.9922872030F, 0.9923274385F, 0.9923675211F, 0.9924074513F,
  143925. 0.9924472294F, 0.9924868557F, 0.9925263306F, 0.9925656544F,
  143926. 0.9926048275F, 0.9926438503F, 0.9926827230F, 0.9927214461F,
  143927. 0.9927600199F, 0.9927984446F, 0.9928367208F, 0.9928748486F,
  143928. 0.9929128285F, 0.9929506608F, 0.9929883459F, 0.9930258841F,
  143929. 0.9930632757F, 0.9931005211F, 0.9931376207F, 0.9931745747F,
  143930. 0.9932113836F, 0.9932480476F, 0.9932845671F, 0.9933209425F,
  143931. 0.9933571742F, 0.9933932623F, 0.9934292074F, 0.9934650097F,
  143932. 0.9935006696F, 0.9935361874F, 0.9935715635F, 0.9936067982F,
  143933. 0.9936418919F, 0.9936768448F, 0.9937116574F, 0.9937463300F,
  143934. 0.9937808629F, 0.9938152565F, 0.9938495111F, 0.9938836271F,
  143935. 0.9939176047F, 0.9939514444F, 0.9939851465F, 0.9940187112F,
  143936. 0.9940521391F, 0.9940854303F, 0.9941185853F, 0.9941516044F,
  143937. 0.9941844879F, 0.9942172361F, 0.9942498495F, 0.9942823283F,
  143938. 0.9943146729F, 0.9943468836F, 0.9943789608F, 0.9944109047F,
  143939. 0.9944427158F, 0.9944743944F, 0.9945059408F, 0.9945373553F,
  143940. 0.9945686384F, 0.9945997902F, 0.9946308112F, 0.9946617017F,
  143941. 0.9946924621F, 0.9947230926F, 0.9947535937F, 0.9947839656F,
  143942. 0.9948142086F, 0.9948443232F, 0.9948743097F, 0.9949041683F,
  143943. 0.9949338995F, 0.9949635035F, 0.9949929807F, 0.9950223315F,
  143944. 0.9950515561F, 0.9950806549F, 0.9951096282F, 0.9951384764F,
  143945. 0.9951671998F, 0.9951957987F, 0.9952242735F, 0.9952526245F,
  143946. 0.9952808520F, 0.9953089564F, 0.9953369380F, 0.9953647971F,
  143947. 0.9953925340F, 0.9954201491F, 0.9954476428F, 0.9954750153F,
  143948. 0.9955022670F, 0.9955293981F, 0.9955564092F, 0.9955833003F,
  143949. 0.9956100720F, 0.9956367245F, 0.9956632582F, 0.9956896733F,
  143950. 0.9957159703F, 0.9957421494F, 0.9957682110F, 0.9957941553F,
  143951. 0.9958199828F, 0.9958456937F, 0.9958712884F, 0.9958967672F,
  143952. 0.9959221305F, 0.9959473784F, 0.9959725115F, 0.9959975300F,
  143953. 0.9960224342F, 0.9960472244F, 0.9960719011F, 0.9960964644F,
  143954. 0.9961209148F, 0.9961452525F, 0.9961694779F, 0.9961935913F,
  143955. 0.9962175930F, 0.9962414834F, 0.9962652627F, 0.9962889313F,
  143956. 0.9963124895F, 0.9963359377F, 0.9963592761F, 0.9963825051F,
  143957. 0.9964056250F, 0.9964286361F, 0.9964515387F, 0.9964743332F,
  143958. 0.9964970198F, 0.9965195990F, 0.9965420709F, 0.9965644360F,
  143959. 0.9965866946F, 0.9966088469F, 0.9966308932F, 0.9966528340F,
  143960. 0.9966746695F, 0.9966964001F, 0.9967180260F, 0.9967395475F,
  143961. 0.9967609651F, 0.9967822789F, 0.9968034894F, 0.9968245968F,
  143962. 0.9968456014F, 0.9968665036F, 0.9968873037F, 0.9969080019F,
  143963. 0.9969285987F, 0.9969490942F, 0.9969694889F, 0.9969897830F,
  143964. 0.9970099769F, 0.9970300708F, 0.9970500651F, 0.9970699601F,
  143965. 0.9970897561F, 0.9971094533F, 0.9971290522F, 0.9971485531F,
  143966. 0.9971679561F, 0.9971872617F, 0.9972064702F, 0.9972255818F,
  143967. 0.9972445968F, 0.9972635157F, 0.9972823386F, 0.9973010659F,
  143968. 0.9973196980F, 0.9973382350F, 0.9973566773F, 0.9973750253F,
  143969. 0.9973932791F, 0.9974114392F, 0.9974295059F, 0.9974474793F,
  143970. 0.9974653599F, 0.9974831480F, 0.9975008438F, 0.9975184476F,
  143971. 0.9975359598F, 0.9975533806F, 0.9975707104F, 0.9975879495F,
  143972. 0.9976050981F, 0.9976221566F, 0.9976391252F, 0.9976560043F,
  143973. 0.9976727941F, 0.9976894950F, 0.9977061073F, 0.9977226312F,
  143974. 0.9977390671F, 0.9977554152F, 0.9977716759F, 0.9977878495F,
  143975. 0.9978039361F, 0.9978199363F, 0.9978358501F, 0.9978516780F,
  143976. 0.9978674202F, 0.9978830771F, 0.9978986488F, 0.9979141358F,
  143977. 0.9979295383F, 0.9979448566F, 0.9979600909F, 0.9979752417F,
  143978. 0.9979903091F, 0.9980052936F, 0.9980201952F, 0.9980350145F,
  143979. 0.9980497515F, 0.9980644067F, 0.9980789804F, 0.9980934727F,
  143980. 0.9981078841F, 0.9981222147F, 0.9981364649F, 0.9981506350F,
  143981. 0.9981647253F, 0.9981787360F, 0.9981926674F, 0.9982065199F,
  143982. 0.9982202936F, 0.9982339890F, 0.9982476062F, 0.9982611456F,
  143983. 0.9982746074F, 0.9982879920F, 0.9983012996F, 0.9983145304F,
  143984. 0.9983276849F, 0.9983407632F, 0.9983537657F, 0.9983666926F,
  143985. 0.9983795442F, 0.9983923208F, 0.9984050226F, 0.9984176501F,
  143986. 0.9984302033F, 0.9984426827F, 0.9984550884F, 0.9984674208F,
  143987. 0.9984796802F, 0.9984918667F, 0.9985039808F, 0.9985160227F,
  143988. 0.9985279926F, 0.9985398909F, 0.9985517177F, 0.9985634734F,
  143989. 0.9985751583F, 0.9985867727F, 0.9985983167F, 0.9986097907F,
  143990. 0.9986211949F, 0.9986325297F, 0.9986437953F, 0.9986549919F,
  143991. 0.9986661199F, 0.9986771795F, 0.9986881710F, 0.9986990946F,
  143992. 0.9987099507F, 0.9987207394F, 0.9987314611F, 0.9987421161F,
  143993. 0.9987527045F, 0.9987632267F, 0.9987736829F, 0.9987840734F,
  143994. 0.9987943985F, 0.9988046584F, 0.9988148534F, 0.9988249838F,
  143995. 0.9988350498F, 0.9988450516F, 0.9988549897F, 0.9988648641F,
  143996. 0.9988746753F, 0.9988844233F, 0.9988941086F, 0.9989037313F,
  143997. 0.9989132918F, 0.9989227902F, 0.9989322269F, 0.9989416021F,
  143998. 0.9989509160F, 0.9989601690F, 0.9989693613F, 0.9989784931F,
  143999. 0.9989875647F, 0.9989965763F, 0.9990055283F, 0.9990144208F,
  144000. 0.9990232541F, 0.9990320286F, 0.9990407443F, 0.9990494016F,
  144001. 0.9990580008F, 0.9990665421F, 0.9990750257F, 0.9990834519F,
  144002. 0.9990918209F, 0.9991001331F, 0.9991083886F, 0.9991165877F,
  144003. 0.9991247307F, 0.9991328177F, 0.9991408491F, 0.9991488251F,
  144004. 0.9991567460F, 0.9991646119F, 0.9991724232F, 0.9991801801F,
  144005. 0.9991878828F, 0.9991955316F, 0.9992031267F, 0.9992106684F,
  144006. 0.9992181569F, 0.9992255925F, 0.9992329753F, 0.9992403057F,
  144007. 0.9992475839F, 0.9992548101F, 0.9992619846F, 0.9992691076F,
  144008. 0.9992761793F, 0.9992832001F, 0.9992901701F, 0.9992970895F,
  144009. 0.9993039587F, 0.9993107777F, 0.9993175470F, 0.9993242667F,
  144010. 0.9993309371F, 0.9993375583F, 0.9993441307F, 0.9993506545F,
  144011. 0.9993571298F, 0.9993635570F, 0.9993699362F, 0.9993762678F,
  144012. 0.9993825519F, 0.9993887887F, 0.9993949785F, 0.9994011216F,
  144013. 0.9994072181F, 0.9994132683F, 0.9994192725F, 0.9994252307F,
  144014. 0.9994311434F, 0.9994370107F, 0.9994428327F, 0.9994486099F,
  144015. 0.9994543423F, 0.9994600303F, 0.9994656739F, 0.9994712736F,
  144016. 0.9994768294F, 0.9994823417F, 0.9994878105F, 0.9994932363F,
  144017. 0.9994986191F, 0.9995039592F, 0.9995092568F, 0.9995145122F,
  144018. 0.9995197256F, 0.9995248971F, 0.9995300270F, 0.9995351156F,
  144019. 0.9995401630F, 0.9995451695F, 0.9995501352F, 0.9995550604F,
  144020. 0.9995599454F, 0.9995647903F, 0.9995695953F, 0.9995743607F,
  144021. 0.9995790866F, 0.9995837734F, 0.9995884211F, 0.9995930300F,
  144022. 0.9995976004F, 0.9996021324F, 0.9996066263F, 0.9996110822F,
  144023. 0.9996155004F, 0.9996198810F, 0.9996242244F, 0.9996285306F,
  144024. 0.9996327999F, 0.9996370326F, 0.9996412287F, 0.9996453886F,
  144025. 0.9996495125F, 0.9996536004F, 0.9996576527F, 0.9996616696F,
  144026. 0.9996656512F, 0.9996695977F, 0.9996735094F, 0.9996773865F,
  144027. 0.9996812291F, 0.9996850374F, 0.9996888118F, 0.9996925523F,
  144028. 0.9996962591F, 0.9996999325F, 0.9997035727F, 0.9997071798F,
  144029. 0.9997107541F, 0.9997142957F, 0.9997178049F, 0.9997212818F,
  144030. 0.9997247266F, 0.9997281396F, 0.9997315209F, 0.9997348708F,
  144031. 0.9997381893F, 0.9997414767F, 0.9997447333F, 0.9997479591F,
  144032. 0.9997511544F, 0.9997543194F, 0.9997574542F, 0.9997605591F,
  144033. 0.9997636342F, 0.9997666797F, 0.9997696958F, 0.9997726828F,
  144034. 0.9997756407F, 0.9997785698F, 0.9997814703F, 0.9997843423F,
  144035. 0.9997871860F, 0.9997900016F, 0.9997927894F, 0.9997955494F,
  144036. 0.9997982818F, 0.9998009869F, 0.9998036648F, 0.9998063157F,
  144037. 0.9998089398F, 0.9998115373F, 0.9998141082F, 0.9998166529F,
  144038. 0.9998191715F, 0.9998216642F, 0.9998241311F, 0.9998265724F,
  144039. 0.9998289884F, 0.9998313790F, 0.9998337447F, 0.9998360854F,
  144040. 0.9998384015F, 0.9998406930F, 0.9998429602F, 0.9998452031F,
  144041. 0.9998474221F, 0.9998496171F, 0.9998517885F, 0.9998539364F,
  144042. 0.9998560610F, 0.9998581624F, 0.9998602407F, 0.9998622962F,
  144043. 0.9998643291F, 0.9998663394F, 0.9998683274F, 0.9998702932F,
  144044. 0.9998722370F, 0.9998741589F, 0.9998760591F, 0.9998779378F,
  144045. 0.9998797952F, 0.9998816313F, 0.9998834464F, 0.9998852406F,
  144046. 0.9998870141F, 0.9998887670F, 0.9998904995F, 0.9998922117F,
  144047. 0.9998939039F, 0.9998955761F, 0.9998972285F, 0.9998988613F,
  144048. 0.9999004746F, 0.9999020686F, 0.9999036434F, 0.9999051992F,
  144049. 0.9999067362F, 0.9999082544F, 0.9999097541F, 0.9999112354F,
  144050. 0.9999126984F, 0.9999141433F, 0.9999155703F, 0.9999169794F,
  144051. 0.9999183709F, 0.9999197449F, 0.9999211014F, 0.9999224408F,
  144052. 0.9999237631F, 0.9999250684F, 0.9999263570F, 0.9999276289F,
  144053. 0.9999288843F, 0.9999301233F, 0.9999313461F, 0.9999325529F,
  144054. 0.9999337437F, 0.9999349187F, 0.9999360780F, 0.9999372218F,
  144055. 0.9999383503F, 0.9999394635F, 0.9999405616F, 0.9999416447F,
  144056. 0.9999427129F, 0.9999437665F, 0.9999448055F, 0.9999458301F,
  144057. 0.9999468404F, 0.9999478365F, 0.9999488185F, 0.9999497867F,
  144058. 0.9999507411F, 0.9999516819F, 0.9999526091F, 0.9999535230F,
  144059. 0.9999544236F, 0.9999553111F, 0.9999561856F, 0.9999570472F,
  144060. 0.9999578960F, 0.9999587323F, 0.9999595560F, 0.9999603674F,
  144061. 0.9999611666F, 0.9999619536F, 0.9999627286F, 0.9999634917F,
  144062. 0.9999642431F, 0.9999649828F, 0.9999657110F, 0.9999664278F,
  144063. 0.9999671334F, 0.9999678278F, 0.9999685111F, 0.9999691835F,
  144064. 0.9999698451F, 0.9999704960F, 0.9999711364F, 0.9999717662F,
  144065. 0.9999723858F, 0.9999729950F, 0.9999735942F, 0.9999741834F,
  144066. 0.9999747626F, 0.9999753321F, 0.9999758919F, 0.9999764421F,
  144067. 0.9999769828F, 0.9999775143F, 0.9999780364F, 0.9999785495F,
  144068. 0.9999790535F, 0.9999795485F, 0.9999800348F, 0.9999805124F,
  144069. 0.9999809813F, 0.9999814417F, 0.9999818938F, 0.9999823375F,
  144070. 0.9999827731F, 0.9999832005F, 0.9999836200F, 0.9999840316F,
  144071. 0.9999844353F, 0.9999848314F, 0.9999852199F, 0.9999856008F,
  144072. 0.9999859744F, 0.9999863407F, 0.9999866997F, 0.9999870516F,
  144073. 0.9999873965F, 0.9999877345F, 0.9999880656F, 0.9999883900F,
  144074. 0.9999887078F, 0.9999890190F, 0.9999893237F, 0.9999896220F,
  144075. 0.9999899140F, 0.9999901999F, 0.9999904796F, 0.9999907533F,
  144076. 0.9999910211F, 0.9999912830F, 0.9999915391F, 0.9999917896F,
  144077. 0.9999920345F, 0.9999922738F, 0.9999925077F, 0.9999927363F,
  144078. 0.9999929596F, 0.9999931777F, 0.9999933907F, 0.9999935987F,
  144079. 0.9999938018F, 0.9999940000F, 0.9999941934F, 0.9999943820F,
  144080. 0.9999945661F, 0.9999947456F, 0.9999949206F, 0.9999950912F,
  144081. 0.9999952575F, 0.9999954195F, 0.9999955773F, 0.9999957311F,
  144082. 0.9999958807F, 0.9999960265F, 0.9999961683F, 0.9999963063F,
  144083. 0.9999964405F, 0.9999965710F, 0.9999966979F, 0.9999968213F,
  144084. 0.9999969412F, 0.9999970576F, 0.9999971707F, 0.9999972805F,
  144085. 0.9999973871F, 0.9999974905F, 0.9999975909F, 0.9999976881F,
  144086. 0.9999977824F, 0.9999978738F, 0.9999979624F, 0.9999980481F,
  144087. 0.9999981311F, 0.9999982115F, 0.9999982892F, 0.9999983644F,
  144088. 0.9999984370F, 0.9999985072F, 0.9999985750F, 0.9999986405F,
  144089. 0.9999987037F, 0.9999987647F, 0.9999988235F, 0.9999988802F,
  144090. 0.9999989348F, 0.9999989873F, 0.9999990379F, 0.9999990866F,
  144091. 0.9999991334F, 0.9999991784F, 0.9999992217F, 0.9999992632F,
  144092. 0.9999993030F, 0.9999993411F, 0.9999993777F, 0.9999994128F,
  144093. 0.9999994463F, 0.9999994784F, 0.9999995091F, 0.9999995384F,
  144094. 0.9999995663F, 0.9999995930F, 0.9999996184F, 0.9999996426F,
  144095. 0.9999996657F, 0.9999996876F, 0.9999997084F, 0.9999997282F,
  144096. 0.9999997469F, 0.9999997647F, 0.9999997815F, 0.9999997973F,
  144097. 0.9999998123F, 0.9999998265F, 0.9999998398F, 0.9999998524F,
  144098. 0.9999998642F, 0.9999998753F, 0.9999998857F, 0.9999998954F,
  144099. 0.9999999045F, 0.9999999130F, 0.9999999209F, 0.9999999282F,
  144100. 0.9999999351F, 0.9999999414F, 0.9999999472F, 0.9999999526F,
  144101. 0.9999999576F, 0.9999999622F, 0.9999999664F, 0.9999999702F,
  144102. 0.9999999737F, 0.9999999769F, 0.9999999798F, 0.9999999824F,
  144103. 0.9999999847F, 0.9999999868F, 0.9999999887F, 0.9999999904F,
  144104. 0.9999999919F, 0.9999999932F, 0.9999999943F, 0.9999999953F,
  144105. 0.9999999961F, 0.9999999969F, 0.9999999975F, 0.9999999980F,
  144106. 0.9999999985F, 0.9999999988F, 0.9999999991F, 0.9999999993F,
  144107. 0.9999999995F, 0.9999999997F, 0.9999999998F, 0.9999999999F,
  144108. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144109. 1.0000000000F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144110. };
  144111. static float *vwin[8] = {
  144112. vwin64,
  144113. vwin128,
  144114. vwin256,
  144115. vwin512,
  144116. vwin1024,
  144117. vwin2048,
  144118. vwin4096,
  144119. vwin8192,
  144120. };
  144121. float *_vorbis_window_get(int n){
  144122. return vwin[n];
  144123. }
  144124. void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  144125. int lW,int W,int nW){
  144126. lW=(W?lW:0);
  144127. nW=(W?nW:0);
  144128. {
  144129. float *windowLW=vwin[winno[lW]];
  144130. float *windowNW=vwin[winno[nW]];
  144131. long n=blocksizes[W];
  144132. long ln=blocksizes[lW];
  144133. long rn=blocksizes[nW];
  144134. long leftbegin=n/4-ln/4;
  144135. long leftend=leftbegin+ln/2;
  144136. long rightbegin=n/2+n/4-rn/4;
  144137. long rightend=rightbegin+rn/2;
  144138. int i,p;
  144139. for(i=0;i<leftbegin;i++)
  144140. d[i]=0.f;
  144141. for(p=0;i<leftend;i++,p++)
  144142. d[i]*=windowLW[p];
  144143. for(i=rightbegin,p=rn/2-1;i<rightend;i++,p--)
  144144. d[i]*=windowNW[p];
  144145. for(;i<n;i++)
  144146. d[i]=0.f;
  144147. }
  144148. }
  144149. #endif
  144150. /*** End of inlined file: window.c ***/
  144151. #else
  144152. #include <vorbis/vorbisenc.h>
  144153. #include <vorbis/codec.h>
  144154. #include <vorbis/vorbisfile.h>
  144155. #endif
  144156. }
  144157. #undef max
  144158. #undef min
  144159. BEGIN_JUCE_NAMESPACE
  144160. static const char* const oggFormatName = "Ogg-Vorbis file";
  144161. static const juce_wchar* const oggExtensions[] = { T(".ogg"), 0 };
  144162. class OggReader : public AudioFormatReader
  144163. {
  144164. OggVorbisNamespace::OggVorbis_File ovFile;
  144165. OggVorbisNamespace::ov_callbacks callbacks;
  144166. AudioSampleBuffer reservoir;
  144167. int reservoirStart, samplesInReservoir;
  144168. public:
  144169. OggReader (InputStream* const inp)
  144170. : AudioFormatReader (inp, TRANS (oggFormatName)),
  144171. reservoir (2, 4096),
  144172. reservoirStart (0),
  144173. samplesInReservoir (0)
  144174. {
  144175. using namespace OggVorbisNamespace;
  144176. sampleRate = 0;
  144177. usesFloatingPointData = true;
  144178. callbacks.read_func = &oggReadCallback;
  144179. callbacks.seek_func = &oggSeekCallback;
  144180. callbacks.close_func = &oggCloseCallback;
  144181. callbacks.tell_func = &oggTellCallback;
  144182. const int err = ov_open_callbacks (input, &ovFile, 0, 0, callbacks);
  144183. if (err == 0)
  144184. {
  144185. vorbis_info* info = ov_info (&ovFile, -1);
  144186. lengthInSamples = (uint32) ov_pcm_total (&ovFile, -1);
  144187. numChannels = info->channels;
  144188. bitsPerSample = 16;
  144189. sampleRate = info->rate;
  144190. reservoir.setSize (numChannels,
  144191. (int) jmin (lengthInSamples, (int64) reservoir.getNumSamples()));
  144192. }
  144193. }
  144194. ~OggReader()
  144195. {
  144196. OggVorbisNamespace::ov_clear (&ovFile);
  144197. }
  144198. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  144199. int64 startSampleInFile, int numSamples)
  144200. {
  144201. while (numSamples > 0)
  144202. {
  144203. const int numAvailable = reservoirStart + samplesInReservoir - startSampleInFile;
  144204. if (startSampleInFile >= reservoirStart && numAvailable > 0)
  144205. {
  144206. // got a few samples overlapping, so use them before seeking..
  144207. const int numToUse = jmin (numSamples, numAvailable);
  144208. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  144209. if (destSamples[i] != 0)
  144210. memcpy (destSamples[i] + startOffsetInDestBuffer,
  144211. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  144212. sizeof (float) * numToUse);
  144213. startSampleInFile += numToUse;
  144214. numSamples -= numToUse;
  144215. startOffsetInDestBuffer += numToUse;
  144216. if (numSamples == 0)
  144217. break;
  144218. }
  144219. if (startSampleInFile < reservoirStart
  144220. || startSampleInFile + numSamples > reservoirStart + samplesInReservoir)
  144221. {
  144222. // buffer miss, so refill the reservoir
  144223. int bitStream = 0;
  144224. reservoirStart = jmax (0, (int) startSampleInFile);
  144225. samplesInReservoir = reservoir.getNumSamples();
  144226. if (reservoirStart != (int) OggVorbisNamespace::ov_pcm_tell (&ovFile))
  144227. OggVorbisNamespace::ov_pcm_seek (&ovFile, reservoirStart);
  144228. int offset = 0;
  144229. int numToRead = samplesInReservoir;
  144230. while (numToRead > 0)
  144231. {
  144232. float** dataIn = 0;
  144233. const int samps = OggVorbisNamespace::ov_read_float (&ovFile, &dataIn, numToRead, &bitStream);
  144234. if (samps <= 0)
  144235. break;
  144236. jassert (samps <= numToRead);
  144237. for (int i = jmin ((int) numChannels, reservoir.getNumChannels()); --i >= 0;)
  144238. {
  144239. memcpy (reservoir.getSampleData (i, offset),
  144240. dataIn[i],
  144241. sizeof (float) * samps);
  144242. }
  144243. numToRead -= samps;
  144244. offset += samps;
  144245. }
  144246. if (numToRead > 0)
  144247. reservoir.clear (offset, numToRead);
  144248. }
  144249. }
  144250. if (numSamples > 0)
  144251. {
  144252. for (int i = numDestChannels; --i >= 0;)
  144253. if (destSamples[i] != 0)
  144254. zeromem (destSamples[i] + startOffsetInDestBuffer,
  144255. sizeof (int) * numSamples);
  144256. }
  144257. return true;
  144258. }
  144259. static size_t oggReadCallback (void* ptr, size_t size, size_t nmemb, void* datasource)
  144260. {
  144261. return (size_t) (((InputStream*) datasource)->read (ptr, (int) (size * nmemb)) / size);
  144262. }
  144263. static int oggSeekCallback (void* datasource, OggVorbisNamespace::ogg_int64_t offset, int whence)
  144264. {
  144265. InputStream* const in = (InputStream*) datasource;
  144266. if (whence == SEEK_CUR)
  144267. offset += in->getPosition();
  144268. else if (whence == SEEK_END)
  144269. offset += in->getTotalLength();
  144270. in->setPosition (offset);
  144271. return 0;
  144272. }
  144273. static int oggCloseCallback (void*)
  144274. {
  144275. return 0;
  144276. }
  144277. static long oggTellCallback (void* datasource)
  144278. {
  144279. return (long) ((InputStream*) datasource)->getPosition();
  144280. }
  144281. juce_UseDebuggingNewOperator
  144282. };
  144283. class OggWriter : public AudioFormatWriter
  144284. {
  144285. OggVorbisNamespace::ogg_stream_state os;
  144286. OggVorbisNamespace::ogg_page og;
  144287. OggVorbisNamespace::ogg_packet op;
  144288. OggVorbisNamespace::vorbis_info vi;
  144289. OggVorbisNamespace::vorbis_comment vc;
  144290. OggVorbisNamespace::vorbis_dsp_state vd;
  144291. OggVorbisNamespace::vorbis_block vb;
  144292. public:
  144293. bool ok;
  144294. OggWriter (OutputStream* const out,
  144295. const double sampleRate,
  144296. const int numChannels,
  144297. const int bitsPerSample,
  144298. const int qualityIndex)
  144299. : AudioFormatWriter (out, TRANS (oggFormatName),
  144300. sampleRate,
  144301. numChannels,
  144302. bitsPerSample)
  144303. {
  144304. using namespace OggVorbisNamespace;
  144305. ok = false;
  144306. vorbis_info_init (&vi);
  144307. if (vorbis_encode_init_vbr (&vi,
  144308. numChannels,
  144309. (int) sampleRate,
  144310. jlimit (0.0f, 1.0f, qualityIndex * 0.5f)) == 0)
  144311. {
  144312. vorbis_comment_init (&vc);
  144313. if (JUCEApplication::getInstance() != 0)
  144314. vorbis_comment_add_tag (&vc, "ENCODER", const_cast <char*> (JUCEApplication::getInstance()->getApplicationName().toUTF8()));
  144315. vorbis_analysis_init (&vd, &vi);
  144316. vorbis_block_init (&vd, &vb);
  144317. ogg_stream_init (&os, Random::getSystemRandom().nextInt());
  144318. ogg_packet header;
  144319. ogg_packet header_comm;
  144320. ogg_packet header_code;
  144321. vorbis_analysis_headerout (&vd, &vc, &header, &header_comm, &header_code);
  144322. ogg_stream_packetin (&os, &header);
  144323. ogg_stream_packetin (&os, &header_comm);
  144324. ogg_stream_packetin (&os, &header_code);
  144325. for (;;)
  144326. {
  144327. if (ogg_stream_flush (&os, &og) == 0)
  144328. break;
  144329. output->write (og.header, og.header_len);
  144330. output->write (og.body, og.body_len);
  144331. }
  144332. ok = true;
  144333. }
  144334. }
  144335. ~OggWriter()
  144336. {
  144337. using namespace OggVorbisNamespace;
  144338. if (ok)
  144339. {
  144340. // write a zero-length packet to show ogg that we're finished..
  144341. write (0, 0);
  144342. ogg_stream_clear (&os);
  144343. vorbis_block_clear (&vb);
  144344. vorbis_dsp_clear (&vd);
  144345. vorbis_comment_clear (&vc);
  144346. vorbis_info_clear (&vi);
  144347. output->flush();
  144348. }
  144349. else
  144350. {
  144351. vorbis_info_clear (&vi);
  144352. output = 0; // to stop the base class deleting this, as it needs to be returned
  144353. // to the caller of createWriter()
  144354. }
  144355. }
  144356. bool write (const int** samplesToWrite, int numSamples)
  144357. {
  144358. using namespace OggVorbisNamespace;
  144359. if (! ok)
  144360. return false;
  144361. if (numSamples > 0)
  144362. {
  144363. const double gain = 1.0 / 0x80000000u;
  144364. float** const vorbisBuffer = vorbis_analysis_buffer (&vd, numSamples);
  144365. for (int i = numChannels; --i >= 0;)
  144366. {
  144367. float* const dst = vorbisBuffer[i];
  144368. const int* const src = samplesToWrite [i];
  144369. if (src != 0 && dst != 0)
  144370. {
  144371. for (int j = 0; j < numSamples; ++j)
  144372. dst[j] = (float) (src[j] * gain);
  144373. }
  144374. }
  144375. }
  144376. vorbis_analysis_wrote (&vd, numSamples);
  144377. while (vorbis_analysis_blockout (&vd, &vb) == 1)
  144378. {
  144379. vorbis_analysis (&vb, 0);
  144380. vorbis_bitrate_addblock (&vb);
  144381. while (vorbis_bitrate_flushpacket (&vd, &op))
  144382. {
  144383. ogg_stream_packetin (&os, &op);
  144384. for (;;)
  144385. {
  144386. if (ogg_stream_pageout (&os, &og) == 0)
  144387. break;
  144388. output->write (og.header, og.header_len);
  144389. output->write (og.body, og.body_len);
  144390. if (ogg_page_eos (&og))
  144391. break;
  144392. }
  144393. }
  144394. }
  144395. return true;
  144396. }
  144397. juce_UseDebuggingNewOperator
  144398. };
  144399. OggVorbisAudioFormat::OggVorbisAudioFormat()
  144400. : AudioFormat (TRANS (oggFormatName), (const juce_wchar**) oggExtensions)
  144401. {
  144402. }
  144403. OggVorbisAudioFormat::~OggVorbisAudioFormat()
  144404. {
  144405. }
  144406. const Array <int> OggVorbisAudioFormat::getPossibleSampleRates()
  144407. {
  144408. const int rates[] = { 22050, 32000, 44100, 48000, 0 };
  144409. return Array <int> (rates);
  144410. }
  144411. const Array <int> OggVorbisAudioFormat::getPossibleBitDepths()
  144412. {
  144413. Array <int> depths;
  144414. depths.add (32);
  144415. return depths;
  144416. }
  144417. bool OggVorbisAudioFormat::canDoStereo()
  144418. {
  144419. return true;
  144420. }
  144421. bool OggVorbisAudioFormat::canDoMono()
  144422. {
  144423. return true;
  144424. }
  144425. AudioFormatReader* OggVorbisAudioFormat::createReaderFor (InputStream* in,
  144426. const bool deleteStreamIfOpeningFails)
  144427. {
  144428. ScopedPointer <OggReader> r (new OggReader (in));
  144429. if (r->sampleRate != 0)
  144430. return r.release();
  144431. if (! deleteStreamIfOpeningFails)
  144432. r->input = 0;
  144433. return 0;
  144434. }
  144435. AudioFormatWriter* OggVorbisAudioFormat::createWriterFor (OutputStream* out,
  144436. double sampleRate,
  144437. unsigned int numChannels,
  144438. int bitsPerSample,
  144439. const StringPairArray& /*metadataValues*/,
  144440. int qualityOptionIndex)
  144441. {
  144442. ScopedPointer <OggWriter> w (new OggWriter (out,
  144443. sampleRate,
  144444. numChannels,
  144445. bitsPerSample,
  144446. qualityOptionIndex));
  144447. return w->ok ? w.release() : 0;
  144448. }
  144449. bool OggVorbisAudioFormat::isCompressed()
  144450. {
  144451. return true;
  144452. }
  144453. const StringArray OggVorbisAudioFormat::getQualityOptions()
  144454. {
  144455. StringArray s;
  144456. s.add ("Low Quality");
  144457. s.add ("Medium Quality");
  144458. s.add ("High Quality");
  144459. return s;
  144460. }
  144461. int OggVorbisAudioFormat::estimateOggFileQuality (const File& source)
  144462. {
  144463. FileInputStream* const in = source.createInputStream();
  144464. if (in != 0)
  144465. {
  144466. ScopedPointer <AudioFormatReader> r (createReaderFor (in, true));
  144467. if (r != 0)
  144468. {
  144469. const int64 numSamps = r->lengthInSamples;
  144470. r = 0;
  144471. const int64 fileNumSamps = source.getSize() / 4;
  144472. const double ratio = numSamps / (double) fileNumSamps;
  144473. if (ratio > 12.0)
  144474. return 0;
  144475. else if (ratio > 6.0)
  144476. return 1;
  144477. else
  144478. return 2;
  144479. }
  144480. }
  144481. return 1;
  144482. }
  144483. END_JUCE_NAMESPACE
  144484. #endif
  144485. /*** End of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  144486. #endif
  144487. #if JUCE_BUILD_CORE && ! JUCE_ONLY_BUILD_CORE_LIBRARY // do these in the core section to help balance the sizes
  144488. /*** Start of inlined file: juce_JPEGLoader.cpp ***/
  144489. #if JUCE_MSVC
  144490. #pragma warning (push)
  144491. #endif
  144492. namespace jpeglibNamespace
  144493. {
  144494. #if JUCE_INCLUDE_JPEGLIB_CODE
  144495. #if JUCE_MINGW
  144496. typedef unsigned char boolean;
  144497. #endif
  144498. extern "C"
  144499. {
  144500. #define JPEG_INTERNALS
  144501. #undef FAR
  144502. /*** Start of inlined file: jpeglib.h ***/
  144503. #ifndef JPEGLIB_H
  144504. #define JPEGLIB_H
  144505. #ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */
  144506. /*** Start of inlined file: jconfig.h ***/
  144507. // disable all the warnings under MSVC
  144508. #ifdef _MSC_VER
  144509. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  144510. #endif
  144511. #ifdef __BORLANDC__
  144512. #pragma warn -8057
  144513. #pragma warn -8019
  144514. #pragma warn -8004
  144515. #pragma warn -8008
  144516. #endif
  144517. #define HAVE_PROTOTYPES
  144518. #define HAVE_UNSIGNED_CHAR
  144519. #define HAVE_UNSIGNED_SHORT
  144520. #undef CHAR_IS_UNSIGNED
  144521. #define HAVE_STDDEF_H
  144522. #define HAVE_STDLIB_H
  144523. #undef NEED_BSD_STRINGS
  144524. #undef NEED_SYS_TYPES_H
  144525. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  144526. #undef NEED_SHORT_EXTERNAL_NAMES
  144527. #undef INCOMPLETE_TYPES_BROKEN
  144528. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  144529. typedef unsigned char boolean;
  144530. #endif
  144531. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  144532. #ifdef JPEG_INTERNALS
  144533. #undef RIGHT_SHIFT_IS_UNSIGNED
  144534. #endif /* JPEG_INTERNALS */
  144535. #ifdef JPEG_CJPEG_DJPEG
  144536. #define BMP_SUPPORTED /* BMP image file format */
  144537. #define GIF_SUPPORTED /* GIF image file format */
  144538. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  144539. #undef RLE_SUPPORTED /* Utah RLE image file format */
  144540. #define TARGA_SUPPORTED /* Targa image file format */
  144541. #define TWO_FILE_COMMANDLINE /* optional */
  144542. #define USE_SETMODE /* Microsoft has setmode() */
  144543. #undef NEED_SIGNAL_CATCHER
  144544. #undef DONT_USE_B_MODE
  144545. #undef PROGRESS_REPORT /* optional */
  144546. #endif /* JPEG_CJPEG_DJPEG */
  144547. /*** End of inlined file: jconfig.h ***/
  144548. /* widely used configuration options */
  144549. #endif
  144550. /*** Start of inlined file: jmorecfg.h ***/
  144551. #define BITS_IN_JSAMPLE 8 /* use 8 or 12 */
  144552. #define MAX_COMPONENTS 10 /* maximum number of image components */
  144553. #if BITS_IN_JSAMPLE == 8
  144554. #ifdef HAVE_UNSIGNED_CHAR
  144555. typedef unsigned char JSAMPLE;
  144556. #define GETJSAMPLE(value) ((int) (value))
  144557. #else /* not HAVE_UNSIGNED_CHAR */
  144558. typedef char JSAMPLE;
  144559. #ifdef CHAR_IS_UNSIGNED
  144560. #define GETJSAMPLE(value) ((int) (value))
  144561. #else
  144562. #define GETJSAMPLE(value) ((int) (value) & 0xFF)
  144563. #endif /* CHAR_IS_UNSIGNED */
  144564. #endif /* HAVE_UNSIGNED_CHAR */
  144565. #define MAXJSAMPLE 255
  144566. #define CENTERJSAMPLE 128
  144567. #endif /* BITS_IN_JSAMPLE == 8 */
  144568. #if BITS_IN_JSAMPLE == 12
  144569. typedef short JSAMPLE;
  144570. #define GETJSAMPLE(value) ((int) (value))
  144571. #define MAXJSAMPLE 4095
  144572. #define CENTERJSAMPLE 2048
  144573. #endif /* BITS_IN_JSAMPLE == 12 */
  144574. typedef short JCOEF;
  144575. #ifdef HAVE_UNSIGNED_CHAR
  144576. typedef unsigned char JOCTET;
  144577. #define GETJOCTET(value) (value)
  144578. #else /* not HAVE_UNSIGNED_CHAR */
  144579. typedef char JOCTET;
  144580. #ifdef CHAR_IS_UNSIGNED
  144581. #define GETJOCTET(value) (value)
  144582. #else
  144583. #define GETJOCTET(value) ((value) & 0xFF)
  144584. #endif /* CHAR_IS_UNSIGNED */
  144585. #endif /* HAVE_UNSIGNED_CHAR */
  144586. #ifdef HAVE_UNSIGNED_CHAR
  144587. typedef unsigned char UINT8;
  144588. #else /* not HAVE_UNSIGNED_CHAR */
  144589. #ifdef CHAR_IS_UNSIGNED
  144590. typedef char UINT8;
  144591. #else /* not CHAR_IS_UNSIGNED */
  144592. typedef short UINT8;
  144593. #endif /* CHAR_IS_UNSIGNED */
  144594. #endif /* HAVE_UNSIGNED_CHAR */
  144595. #ifdef HAVE_UNSIGNED_SHORT
  144596. typedef unsigned short UINT16;
  144597. #else /* not HAVE_UNSIGNED_SHORT */
  144598. typedef unsigned int UINT16;
  144599. #endif /* HAVE_UNSIGNED_SHORT */
  144600. #ifndef XMD_H /* X11/xmd.h correctly defines INT16 */
  144601. typedef short INT16;
  144602. #endif
  144603. #ifndef XMD_H /* X11/xmd.h correctly defines INT32 */
  144604. typedef long INT32;
  144605. #endif
  144606. typedef unsigned int JDIMENSION;
  144607. #define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */
  144608. #define METHODDEF(type) static type
  144609. #define LOCAL(type) static type
  144610. #define GLOBAL(type) type
  144611. #define EXTERN(type) extern type
  144612. #ifdef HAVE_PROTOTYPES
  144613. #define JMETHOD(type,methodname,arglist) type (*methodname) arglist
  144614. #else
  144615. #define JMETHOD(type,methodname,arglist) type (*methodname) ()
  144616. #endif
  144617. #ifdef NEED_FAR_POINTERS
  144618. #define FAR far
  144619. #else
  144620. #define FAR
  144621. #endif
  144622. #ifndef HAVE_BOOLEAN
  144623. typedef int boolean;
  144624. #endif
  144625. #ifndef FALSE /* in case these macros already exist */
  144626. #define FALSE 0 /* values of boolean */
  144627. #endif
  144628. #ifndef TRUE
  144629. #define TRUE 1
  144630. #endif
  144631. #ifdef JPEG_INTERNALS
  144632. #define JPEG_INTERNAL_OPTIONS
  144633. #endif
  144634. #ifdef JPEG_INTERNAL_OPTIONS
  144635. #define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */
  144636. #define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */
  144637. #define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */
  144638. #undef C_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  144639. #define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  144640. #define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  144641. #define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
  144642. #define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */
  144643. #undef D_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  144644. #define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  144645. #define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  144646. #define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
  144647. #define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
  144648. #define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
  144649. #undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */
  144650. #define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */
  144651. #define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */
  144652. #define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */
  144653. #define RGB_RED 0 /* Offset of Red in an RGB scanline element */
  144654. #define RGB_GREEN 1 /* Offset of Green */
  144655. #define RGB_BLUE 2 /* Offset of Blue */
  144656. #define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */
  144657. #ifndef INLINE
  144658. #ifdef __GNUC__ /* for instance, GNU C knows about inline */
  144659. #define INLINE __inline__
  144660. #endif
  144661. #ifndef INLINE
  144662. #define INLINE /* default is to define it as empty */
  144663. #endif
  144664. #endif
  144665. #ifndef MULTIPLIER
  144666. #define MULTIPLIER int /* type for fastest integer multiply */
  144667. #endif
  144668. #ifndef FAST_FLOAT
  144669. #ifdef HAVE_PROTOTYPES
  144670. #define FAST_FLOAT float
  144671. #else
  144672. #define FAST_FLOAT double
  144673. #endif
  144674. #endif
  144675. #endif /* JPEG_INTERNAL_OPTIONS */
  144676. /*** End of inlined file: jmorecfg.h ***/
  144677. /* seldom changed options */
  144678. #define JPEG_LIB_VERSION 62 /* Version 6b */
  144679. #define DCTSIZE 8 /* The basic DCT block is 8x8 samples */
  144680. #define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */
  144681. #define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */
  144682. #define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */
  144683. #define NUM_ARITH_TBLS 16 /* Arith-coding tables are numbered 0..15 */
  144684. #define MAX_COMPS_IN_SCAN 4 /* JPEG limit on # of components in one scan */
  144685. #define MAX_SAMP_FACTOR 4 /* JPEG limit on sampling factors */
  144686. #define C_MAX_BLOCKS_IN_MCU 10 /* compressor's limit on blocks per MCU */
  144687. #ifndef D_MAX_BLOCKS_IN_MCU
  144688. #define D_MAX_BLOCKS_IN_MCU 10 /* decompressor's limit on blocks per MCU */
  144689. #endif
  144690. typedef JSAMPLE FAR *JSAMPROW; /* ptr to one image row of pixel samples. */
  144691. typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */
  144692. typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */
  144693. typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */
  144694. typedef JBLOCK FAR *JBLOCKROW; /* pointer to one row of coefficient blocks */
  144695. typedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */
  144696. typedef JBLOCKARRAY *JBLOCKIMAGE; /* a 3-D array of coefficient blocks */
  144697. typedef JCOEF FAR *JCOEFPTR; /* useful in a couple of places */
  144698. typedef struct {
  144699. UINT16 quantval[DCTSIZE2]; /* quantization step for each coefficient */
  144700. boolean sent_table; /* TRUE when table has been output */
  144701. } JQUANT_TBL;
  144702. typedef struct {
  144703. UINT8 bits[17]; /* bits[k] = # of symbols with codes of */
  144704. UINT8 huffval[256]; /* The symbols, in order of incr code length */
  144705. boolean sent_table; /* TRUE when table has been output */
  144706. } JHUFF_TBL;
  144707. typedef struct {
  144708. int component_id; /* identifier for this component (0..255) */
  144709. int component_index; /* its index in SOF or cinfo->comp_info[] */
  144710. int h_samp_factor; /* horizontal sampling factor (1..4) */
  144711. int v_samp_factor; /* vertical sampling factor (1..4) */
  144712. int quant_tbl_no; /* quantization table selector (0..3) */
  144713. int dc_tbl_no; /* DC entropy table selector (0..3) */
  144714. int ac_tbl_no; /* AC entropy table selector (0..3) */
  144715. JDIMENSION width_in_blocks;
  144716. JDIMENSION height_in_blocks;
  144717. int DCT_scaled_size;
  144718. JDIMENSION downsampled_width; /* actual width in samples */
  144719. JDIMENSION downsampled_height; /* actual height in samples */
  144720. boolean component_needed; /* do we need the value of this component? */
  144721. int MCU_width; /* number of blocks per MCU, horizontally */
  144722. int MCU_height; /* number of blocks per MCU, vertically */
  144723. int MCU_blocks; /* MCU_width * MCU_height */
  144724. int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_scaled_size */
  144725. int last_col_width; /* # of non-dummy blocks across in last MCU */
  144726. int last_row_height; /* # of non-dummy blocks down in last MCU */
  144727. JQUANT_TBL * quant_table;
  144728. void * dct_table;
  144729. } jpeg_component_info;
  144730. typedef struct {
  144731. int comps_in_scan; /* number of components encoded in this scan */
  144732. int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */
  144733. int Ss, Se; /* progressive JPEG spectral selection parms */
  144734. int Ah, Al; /* progressive JPEG successive approx. parms */
  144735. } jpeg_scan_info;
  144736. typedef struct jpeg_marker_struct FAR * jpeg_saved_marker_ptr;
  144737. struct jpeg_marker_struct {
  144738. jpeg_saved_marker_ptr next; /* next in list, or NULL */
  144739. UINT8 marker; /* marker code: JPEG_COM, or JPEG_APP0+n */
  144740. unsigned int original_length; /* # bytes of data in the file */
  144741. unsigned int data_length; /* # bytes of data saved at data[] */
  144742. JOCTET FAR * data; /* the data contained in the marker */
  144743. };
  144744. typedef enum {
  144745. JCS_UNKNOWN, /* error/unspecified */
  144746. JCS_GRAYSCALE, /* monochrome */
  144747. JCS_RGB, /* red/green/blue */
  144748. JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */
  144749. JCS_CMYK, /* C/M/Y/K */
  144750. JCS_YCCK /* Y/Cb/Cr/K */
  144751. } J_COLOR_SPACE;
  144752. typedef enum {
  144753. JDCT_ISLOW, /* slow but accurate integer algorithm */
  144754. JDCT_IFAST, /* faster, less accurate integer method */
  144755. JDCT_FLOAT /* floating-point: accurate, fast on fast HW */
  144756. } J_DCT_METHOD;
  144757. #ifndef JDCT_DEFAULT /* may be overridden in jconfig.h */
  144758. #define JDCT_DEFAULT JDCT_ISLOW
  144759. #endif
  144760. #ifndef JDCT_FASTEST /* may be overridden in jconfig.h */
  144761. #define JDCT_FASTEST JDCT_IFAST
  144762. #endif
  144763. typedef enum {
  144764. JDITHER_NONE, /* no dithering */
  144765. JDITHER_ORDERED, /* simple ordered dither */
  144766. JDITHER_FS /* Floyd-Steinberg error diffusion dither */
  144767. } J_DITHER_MODE;
  144768. #define jpeg_common_fields \
  144769. struct jpeg_error_mgr * err; /* Error handler module */\
  144770. struct jpeg_memory_mgr * mem; /* Memory manager module */\
  144771. struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\
  144772. void * client_data; /* Available for use by application */\
  144773. boolean is_decompressor; /* So common code can tell which is which */\
  144774. int global_state /* For checking call sequence validity */
  144775. struct jpeg_common_struct {
  144776. jpeg_common_fields; /* Fields common to both master struct types */
  144777. };
  144778. typedef struct jpeg_common_struct * j_common_ptr;
  144779. typedef struct jpeg_compress_struct * j_compress_ptr;
  144780. typedef struct jpeg_decompress_struct * j_decompress_ptr;
  144781. struct jpeg_compress_struct {
  144782. jpeg_common_fields; /* Fields shared with jpeg_decompress_struct */
  144783. struct jpeg_destination_mgr * dest;
  144784. JDIMENSION image_width; /* input image width */
  144785. JDIMENSION image_height; /* input image height */
  144786. int input_components; /* # of color components in input image */
  144787. J_COLOR_SPACE in_color_space; /* colorspace of input image */
  144788. double input_gamma; /* image gamma of input image */
  144789. int data_precision; /* bits of precision in image data */
  144790. int num_components; /* # of color components in JPEG image */
  144791. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  144792. jpeg_component_info * comp_info;
  144793. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  144794. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144795. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144796. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  144797. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  144798. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  144799. int num_scans; /* # of entries in scan_info array */
  144800. const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */
  144801. boolean raw_data_in; /* TRUE=caller supplies downsampled data */
  144802. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  144803. boolean optimize_coding; /* TRUE=optimize entropy encoding parms */
  144804. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  144805. int smoothing_factor; /* 1..100, or 0 for no input smoothing */
  144806. J_DCT_METHOD dct_method; /* DCT algorithm selector */
  144807. unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */
  144808. int restart_in_rows; /* if > 0, MCU rows per restart interval */
  144809. boolean write_JFIF_header; /* should a JFIF marker be written? */
  144810. UINT8 JFIF_major_version; /* What to write for the JFIF version number */
  144811. UINT8 JFIF_minor_version;
  144812. UINT8 density_unit; /* JFIF code for pixel size units */
  144813. UINT16 X_density; /* Horizontal pixel density */
  144814. UINT16 Y_density; /* Vertical pixel density */
  144815. boolean write_Adobe_marker; /* should an Adobe marker be written? */
  144816. JDIMENSION next_scanline; /* 0 .. image_height-1 */
  144817. boolean progressive_mode; /* TRUE if scan script uses progressive mode */
  144818. int max_h_samp_factor; /* largest h_samp_factor */
  144819. int max_v_samp_factor; /* largest v_samp_factor */
  144820. JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */
  144821. int comps_in_scan; /* # of JPEG components in this scan */
  144822. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  144823. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  144824. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  144825. int blocks_in_MCU; /* # of DCT blocks per MCU */
  144826. int MCU_membership[C_MAX_BLOCKS_IN_MCU];
  144827. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  144828. struct jpeg_comp_master * master;
  144829. struct jpeg_c_main_controller * main;
  144830. struct jpeg_c_prep_controller * prep;
  144831. struct jpeg_c_coef_controller * coef;
  144832. struct jpeg_marker_writer * marker;
  144833. struct jpeg_color_converter * cconvert;
  144834. struct jpeg_downsampler * downsample;
  144835. struct jpeg_forward_dct * fdct;
  144836. struct jpeg_entropy_encoder * entropy;
  144837. jpeg_scan_info * script_space; /* workspace for jpeg_simple_progression */
  144838. int script_space_size;
  144839. };
  144840. struct jpeg_decompress_struct {
  144841. jpeg_common_fields; /* Fields shared with jpeg_compress_struct */
  144842. struct jpeg_source_mgr * src;
  144843. JDIMENSION image_width; /* nominal image width (from SOF marker) */
  144844. JDIMENSION image_height; /* nominal image height */
  144845. int num_components; /* # of color components in JPEG image */
  144846. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  144847. J_COLOR_SPACE out_color_space; /* colorspace for output */
  144848. unsigned int scale_num, scale_denom; /* fraction by which to scale image */
  144849. double output_gamma; /* image gamma wanted in output */
  144850. boolean buffered_image; /* TRUE=multiple output passes */
  144851. boolean raw_data_out; /* TRUE=downsampled data wanted */
  144852. J_DCT_METHOD dct_method; /* IDCT algorithm selector */
  144853. boolean do_fancy_upsampling; /* TRUE=apply fancy upsampling */
  144854. boolean do_block_smoothing; /* TRUE=apply interblock smoothing */
  144855. boolean quantize_colors; /* TRUE=colormapped output wanted */
  144856. J_DITHER_MODE dither_mode; /* type of color dithering to use */
  144857. boolean two_pass_quantize; /* TRUE=use two-pass color quantization */
  144858. int desired_number_of_colors; /* max # colors to use in created colormap */
  144859. boolean enable_1pass_quant; /* enable future use of 1-pass quantizer */
  144860. boolean enable_external_quant;/* enable future use of external colormap */
  144861. boolean enable_2pass_quant; /* enable future use of 2-pass quantizer */
  144862. JDIMENSION output_width; /* scaled image width */
  144863. JDIMENSION output_height; /* scaled image height */
  144864. int out_color_components; /* # of color components in out_color_space */
  144865. int output_components; /* # of color components returned */
  144866. int rec_outbuf_height; /* min recommended height of scanline buffer */
  144867. int actual_number_of_colors; /* number of entries in use */
  144868. JSAMPARRAY colormap; /* The color map as a 2-D pixel array */
  144869. JDIMENSION output_scanline; /* 0 .. output_height-1 */
  144870. int input_scan_number; /* Number of SOS markers seen so far */
  144871. JDIMENSION input_iMCU_row; /* Number of iMCU rows completed */
  144872. int output_scan_number; /* Nominal scan number being displayed */
  144873. JDIMENSION output_iMCU_row; /* Number of iMCU rows read */
  144874. int (*coef_bits)[DCTSIZE2]; /* -1 or current Al value for each coef */
  144875. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  144876. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144877. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144878. int data_precision; /* bits of precision in image data */
  144879. jpeg_component_info * comp_info;
  144880. boolean progressive_mode; /* TRUE if SOFn specifies progressive mode */
  144881. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  144882. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  144883. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  144884. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  144885. unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */
  144886. boolean saw_JFIF_marker; /* TRUE iff a JFIF APP0 marker was found */
  144887. UINT8 JFIF_major_version; /* JFIF version number */
  144888. UINT8 JFIF_minor_version;
  144889. UINT8 density_unit; /* JFIF code for pixel size units */
  144890. UINT16 X_density; /* Horizontal pixel density */
  144891. UINT16 Y_density; /* Vertical pixel density */
  144892. boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */
  144893. UINT8 Adobe_transform; /* Color transform code from Adobe marker */
  144894. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  144895. jpeg_saved_marker_ptr marker_list; /* Head of list of saved markers */
  144896. int max_h_samp_factor; /* largest h_samp_factor */
  144897. int max_v_samp_factor; /* largest v_samp_factor */
  144898. int min_DCT_scaled_size; /* smallest DCT_scaled_size of any component */
  144899. JDIMENSION total_iMCU_rows; /* # of iMCU rows in image */
  144900. JSAMPLE * sample_range_limit; /* table for fast range-limiting */
  144901. int comps_in_scan; /* # of JPEG components in this scan */
  144902. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  144903. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  144904. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  144905. int blocks_in_MCU; /* # of DCT blocks per MCU */
  144906. int MCU_membership[D_MAX_BLOCKS_IN_MCU];
  144907. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  144908. int unread_marker;
  144909. struct jpeg_decomp_master * master;
  144910. struct jpeg_d_main_controller * main;
  144911. struct jpeg_d_coef_controller * coef;
  144912. struct jpeg_d_post_controller * post;
  144913. struct jpeg_input_controller * inputctl;
  144914. struct jpeg_marker_reader * marker;
  144915. struct jpeg_entropy_decoder * entropy;
  144916. struct jpeg_inverse_dct * idct;
  144917. struct jpeg_upsampler * upsample;
  144918. struct jpeg_color_deconverter * cconvert;
  144919. struct jpeg_color_quantizer * cquantize;
  144920. };
  144921. struct jpeg_error_mgr {
  144922. JMETHOD(void, error_exit, (j_common_ptr cinfo));
  144923. JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));
  144924. JMETHOD(void, output_message, (j_common_ptr cinfo));
  144925. JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer));
  144926. #define JMSG_LENGTH_MAX 200 /* recommended size of format_message buffer */
  144927. JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo));
  144928. int msg_code;
  144929. #define JMSG_STR_PARM_MAX 80
  144930. union {
  144931. int i[8];
  144932. char s[JMSG_STR_PARM_MAX];
  144933. } msg_parm;
  144934. int trace_level; /* max msg_level that will be displayed */
  144935. long num_warnings; /* number of corrupt-data warnings */
  144936. const char * const * jpeg_message_table; /* Library errors */
  144937. int last_jpeg_message; /* Table contains strings 0..last_jpeg_message */
  144938. const char * const * addon_message_table; /* Non-library errors */
  144939. int first_addon_message; /* code for first string in addon table */
  144940. int last_addon_message; /* code for last string in addon table */
  144941. };
  144942. struct jpeg_progress_mgr {
  144943. JMETHOD(void, progress_monitor, (j_common_ptr cinfo));
  144944. long pass_counter; /* work units completed in this pass */
  144945. long pass_limit; /* total number of work units in this pass */
  144946. int completed_passes; /* passes completed so far */
  144947. int total_passes; /* total number of passes expected */
  144948. };
  144949. struct jpeg_destination_mgr {
  144950. JOCTET * next_output_byte; /* => next byte to write in buffer */
  144951. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  144952. JMETHOD(void, init_destination, (j_compress_ptr cinfo));
  144953. JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo));
  144954. JMETHOD(void, term_destination, (j_compress_ptr cinfo));
  144955. };
  144956. struct jpeg_source_mgr {
  144957. const JOCTET * next_input_byte; /* => next byte to read from buffer */
  144958. size_t bytes_in_buffer; /* # of bytes remaining in buffer */
  144959. JMETHOD(void, init_source, (j_decompress_ptr cinfo));
  144960. JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo));
  144961. JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes));
  144962. JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo, int desired));
  144963. JMETHOD(void, term_source, (j_decompress_ptr cinfo));
  144964. };
  144965. #define JPOOL_PERMANENT 0 /* lasts until master record is destroyed */
  144966. #define JPOOL_IMAGE 1 /* lasts until done with image/datastream */
  144967. #define JPOOL_NUMPOOLS 2
  144968. typedef struct jvirt_sarray_control * jvirt_sarray_ptr;
  144969. typedef struct jvirt_barray_control * jvirt_barray_ptr;
  144970. struct jpeg_memory_mgr {
  144971. JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id,
  144972. size_t sizeofobject));
  144973. JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id,
  144974. size_t sizeofobject));
  144975. JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id,
  144976. JDIMENSION samplesperrow,
  144977. JDIMENSION numrows));
  144978. JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id,
  144979. JDIMENSION blocksperrow,
  144980. JDIMENSION numrows));
  144981. JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo,
  144982. int pool_id,
  144983. boolean pre_zero,
  144984. JDIMENSION samplesperrow,
  144985. JDIMENSION numrows,
  144986. JDIMENSION maxaccess));
  144987. JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo,
  144988. int pool_id,
  144989. boolean pre_zero,
  144990. JDIMENSION blocksperrow,
  144991. JDIMENSION numrows,
  144992. JDIMENSION maxaccess));
  144993. JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo));
  144994. JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo,
  144995. jvirt_sarray_ptr ptr,
  144996. JDIMENSION start_row,
  144997. JDIMENSION num_rows,
  144998. boolean writable));
  144999. JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo,
  145000. jvirt_barray_ptr ptr,
  145001. JDIMENSION start_row,
  145002. JDIMENSION num_rows,
  145003. boolean writable));
  145004. JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id));
  145005. JMETHOD(void, self_destruct, (j_common_ptr cinfo));
  145006. long max_memory_to_use;
  145007. long max_alloc_chunk;
  145008. };
  145009. typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
  145010. #ifdef HAVE_PROTOTYPES
  145011. #define JPP(arglist) arglist
  145012. #else
  145013. #define JPP(arglist) ()
  145014. #endif
  145015. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145016. #define jpeg_std_error jStdError
  145017. #define jpeg_CreateCompress jCreaCompress
  145018. #define jpeg_CreateDecompress jCreaDecompress
  145019. #define jpeg_destroy_compress jDestCompress
  145020. #define jpeg_destroy_decompress jDestDecompress
  145021. #define jpeg_stdio_dest jStdDest
  145022. #define jpeg_stdio_src jStdSrc
  145023. #define jpeg_set_defaults jSetDefaults
  145024. #define jpeg_set_colorspace jSetColorspace
  145025. #define jpeg_default_colorspace jDefColorspace
  145026. #define jpeg_set_quality jSetQuality
  145027. #define jpeg_set_linear_quality jSetLQuality
  145028. #define jpeg_add_quant_table jAddQuantTable
  145029. #define jpeg_quality_scaling jQualityScaling
  145030. #define jpeg_simple_progression jSimProgress
  145031. #define jpeg_suppress_tables jSuppressTables
  145032. #define jpeg_alloc_quant_table jAlcQTable
  145033. #define jpeg_alloc_huff_table jAlcHTable
  145034. #define jpeg_start_compress jStrtCompress
  145035. #define jpeg_write_scanlines jWrtScanlines
  145036. #define jpeg_finish_compress jFinCompress
  145037. #define jpeg_write_raw_data jWrtRawData
  145038. #define jpeg_write_marker jWrtMarker
  145039. #define jpeg_write_m_header jWrtMHeader
  145040. #define jpeg_write_m_byte jWrtMByte
  145041. #define jpeg_write_tables jWrtTables
  145042. #define jpeg_read_header jReadHeader
  145043. #define jpeg_start_decompress jStrtDecompress
  145044. #define jpeg_read_scanlines jReadScanlines
  145045. #define jpeg_finish_decompress jFinDecompress
  145046. #define jpeg_read_raw_data jReadRawData
  145047. #define jpeg_has_multiple_scans jHasMultScn
  145048. #define jpeg_start_output jStrtOutput
  145049. #define jpeg_finish_output jFinOutput
  145050. #define jpeg_input_complete jInComplete
  145051. #define jpeg_new_colormap jNewCMap
  145052. #define jpeg_consume_input jConsumeInput
  145053. #define jpeg_calc_output_dimensions jCalcDimensions
  145054. #define jpeg_save_markers jSaveMarkers
  145055. #define jpeg_set_marker_processor jSetMarker
  145056. #define jpeg_read_coefficients jReadCoefs
  145057. #define jpeg_write_coefficients jWrtCoefs
  145058. #define jpeg_copy_critical_parameters jCopyCrit
  145059. #define jpeg_abort_compress jAbrtCompress
  145060. #define jpeg_abort_decompress jAbrtDecompress
  145061. #define jpeg_abort jAbort
  145062. #define jpeg_destroy jDestroy
  145063. #define jpeg_resync_to_restart jResyncRestart
  145064. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145065. EXTERN(struct jpeg_error_mgr *) jpeg_std_error
  145066. JPP((struct jpeg_error_mgr * err));
  145067. #define jpeg_create_compress(cinfo) \
  145068. jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \
  145069. (size_t) sizeof(struct jpeg_compress_struct))
  145070. #define jpeg_create_decompress(cinfo) \
  145071. jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
  145072. (size_t) sizeof(struct jpeg_decompress_struct))
  145073. EXTERN(void) jpeg_CreateCompress JPP((j_compress_ptr cinfo,
  145074. int version, size_t structsize));
  145075. EXTERN(void) jpeg_CreateDecompress JPP((j_decompress_ptr cinfo,
  145076. int version, size_t structsize));
  145077. EXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo));
  145078. EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo));
  145079. EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));
  145080. EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
  145081. EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo));
  145082. EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo,
  145083. J_COLOR_SPACE colorspace));
  145084. EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo));
  145085. EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality,
  145086. boolean force_baseline));
  145087. EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo,
  145088. int scale_factor,
  145089. boolean force_baseline));
  145090. EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl,
  145091. const unsigned int *basic_table,
  145092. int scale_factor,
  145093. boolean force_baseline));
  145094. EXTERN(int) jpeg_quality_scaling JPP((int quality));
  145095. EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo));
  145096. EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo,
  145097. boolean suppress));
  145098. EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo));
  145099. EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo));
  145100. EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo,
  145101. boolean write_all_tables));
  145102. EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo,
  145103. JSAMPARRAY scanlines,
  145104. JDIMENSION num_lines));
  145105. EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo));
  145106. EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo,
  145107. JSAMPIMAGE data,
  145108. JDIMENSION num_lines));
  145109. EXTERN(void) jpeg_write_marker
  145110. JPP((j_compress_ptr cinfo, int marker,
  145111. const JOCTET * dataptr, unsigned int datalen));
  145112. EXTERN(void) jpeg_write_m_header
  145113. JPP((j_compress_ptr cinfo, int marker, unsigned int datalen));
  145114. EXTERN(void) jpeg_write_m_byte
  145115. JPP((j_compress_ptr cinfo, int val));
  145116. EXTERN(void) jpeg_write_tables JPP((j_compress_ptr cinfo));
  145117. EXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo,
  145118. boolean require_image));
  145119. #define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */
  145120. #define JPEG_HEADER_OK 1 /* Found valid image datastream */
  145121. #define JPEG_HEADER_TABLES_ONLY 2 /* Found valid table-specs-only datastream */
  145122. EXTERN(boolean) jpeg_start_decompress JPP((j_decompress_ptr cinfo));
  145123. EXTERN(JDIMENSION) jpeg_read_scanlines JPP((j_decompress_ptr cinfo,
  145124. JSAMPARRAY scanlines,
  145125. JDIMENSION max_lines));
  145126. EXTERN(boolean) jpeg_finish_decompress JPP((j_decompress_ptr cinfo));
  145127. EXTERN(JDIMENSION) jpeg_read_raw_data JPP((j_decompress_ptr cinfo,
  145128. JSAMPIMAGE data,
  145129. JDIMENSION max_lines));
  145130. EXTERN(boolean) jpeg_has_multiple_scans JPP((j_decompress_ptr cinfo));
  145131. EXTERN(boolean) jpeg_start_output JPP((j_decompress_ptr cinfo,
  145132. int scan_number));
  145133. EXTERN(boolean) jpeg_finish_output JPP((j_decompress_ptr cinfo));
  145134. EXTERN(boolean) jpeg_input_complete JPP((j_decompress_ptr cinfo));
  145135. EXTERN(void) jpeg_new_colormap JPP((j_decompress_ptr cinfo));
  145136. EXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo));
  145137. #define JPEG_REACHED_SOS 1 /* Reached start of new scan */
  145138. #define JPEG_REACHED_EOI 2 /* Reached end of image */
  145139. #define JPEG_ROW_COMPLETED 3 /* Completed one iMCU row */
  145140. #define JPEG_SCAN_COMPLETED 4 /* Completed last iMCU row of a scan */
  145141. EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo));
  145142. EXTERN(void) jpeg_save_markers
  145143. JPP((j_decompress_ptr cinfo, int marker_code,
  145144. unsigned int length_limit));
  145145. EXTERN(void) jpeg_set_marker_processor
  145146. JPP((j_decompress_ptr cinfo, int marker_code,
  145147. jpeg_marker_parser_method routine));
  145148. EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients JPP((j_decompress_ptr cinfo));
  145149. EXTERN(void) jpeg_write_coefficients JPP((j_compress_ptr cinfo,
  145150. jvirt_barray_ptr * coef_arrays));
  145151. EXTERN(void) jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo,
  145152. j_compress_ptr dstinfo));
  145153. EXTERN(void) jpeg_abort_compress JPP((j_compress_ptr cinfo));
  145154. EXTERN(void) jpeg_abort_decompress JPP((j_decompress_ptr cinfo));
  145155. EXTERN(void) jpeg_abort JPP((j_common_ptr cinfo));
  145156. EXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo));
  145157. EXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo,
  145158. int desired));
  145159. #define JPEG_RST0 0xD0 /* RST0 marker code */
  145160. #define JPEG_EOI 0xD9 /* EOI marker code */
  145161. #define JPEG_APP0 0xE0 /* APP0 marker code */
  145162. #define JPEG_COM 0xFE /* COM marker code */
  145163. #ifdef INCOMPLETE_TYPES_BROKEN
  145164. #ifndef JPEG_INTERNALS /* will be defined in jpegint.h */
  145165. struct jvirt_sarray_control { long dummy; };
  145166. struct jvirt_barray_control { long dummy; };
  145167. struct jpeg_comp_master { long dummy; };
  145168. struct jpeg_c_main_controller { long dummy; };
  145169. struct jpeg_c_prep_controller { long dummy; };
  145170. struct jpeg_c_coef_controller { long dummy; };
  145171. struct jpeg_marker_writer { long dummy; };
  145172. struct jpeg_color_converter { long dummy; };
  145173. struct jpeg_downsampler { long dummy; };
  145174. struct jpeg_forward_dct { long dummy; };
  145175. struct jpeg_entropy_encoder { long dummy; };
  145176. struct jpeg_decomp_master { long dummy; };
  145177. struct jpeg_d_main_controller { long dummy; };
  145178. struct jpeg_d_coef_controller { long dummy; };
  145179. struct jpeg_d_post_controller { long dummy; };
  145180. struct jpeg_input_controller { long dummy; };
  145181. struct jpeg_marker_reader { long dummy; };
  145182. struct jpeg_entropy_decoder { long dummy; };
  145183. struct jpeg_inverse_dct { long dummy; };
  145184. struct jpeg_upsampler { long dummy; };
  145185. struct jpeg_color_deconverter { long dummy; };
  145186. struct jpeg_color_quantizer { long dummy; };
  145187. #endif /* JPEG_INTERNALS */
  145188. #endif /* INCOMPLETE_TYPES_BROKEN */
  145189. #ifdef JPEG_INTERNALS
  145190. /*** Start of inlined file: jpegint.h ***/
  145191. typedef enum { /* Operating modes for buffer controllers */
  145192. JBUF_PASS_THRU, /* Plain stripwise operation */
  145193. JBUF_SAVE_SOURCE, /* Run source subobject only, save output */
  145194. JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */
  145195. JBUF_SAVE_AND_PASS /* Run both subobjects, save output */
  145196. } J_BUF_MODE;
  145197. #define CSTATE_START 100 /* after create_compress */
  145198. #define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */
  145199. #define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */
  145200. #define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */
  145201. #define DSTATE_START 200 /* after create_decompress */
  145202. #define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */
  145203. #define DSTATE_READY 202 /* found SOS, ready for start_decompress */
  145204. #define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/
  145205. #define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */
  145206. #define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */
  145207. #define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */
  145208. #define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */
  145209. #define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */
  145210. #define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */
  145211. #define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */
  145212. struct jpeg_comp_master {
  145213. JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo));
  145214. JMETHOD(void, pass_startup, (j_compress_ptr cinfo));
  145215. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145216. boolean call_pass_startup; /* True if pass_startup must be called */
  145217. boolean is_last_pass; /* True during last pass */
  145218. };
  145219. struct jpeg_c_main_controller {
  145220. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145221. JMETHOD(void, process_data, (j_compress_ptr cinfo,
  145222. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  145223. JDIMENSION in_rows_avail));
  145224. };
  145225. struct jpeg_c_prep_controller {
  145226. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145227. JMETHOD(void, pre_process_data, (j_compress_ptr cinfo,
  145228. JSAMPARRAY input_buf,
  145229. JDIMENSION *in_row_ctr,
  145230. JDIMENSION in_rows_avail,
  145231. JSAMPIMAGE output_buf,
  145232. JDIMENSION *out_row_group_ctr,
  145233. JDIMENSION out_row_groups_avail));
  145234. };
  145235. struct jpeg_c_coef_controller {
  145236. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145237. JMETHOD(boolean, compress_data, (j_compress_ptr cinfo,
  145238. JSAMPIMAGE input_buf));
  145239. };
  145240. struct jpeg_color_converter {
  145241. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145242. JMETHOD(void, color_convert, (j_compress_ptr cinfo,
  145243. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  145244. JDIMENSION output_row, int num_rows));
  145245. };
  145246. struct jpeg_downsampler {
  145247. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145248. JMETHOD(void, downsample, (j_compress_ptr cinfo,
  145249. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  145250. JSAMPIMAGE output_buf,
  145251. JDIMENSION out_row_group_index));
  145252. boolean need_context_rows; /* TRUE if need rows above & below */
  145253. };
  145254. struct jpeg_forward_dct {
  145255. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145256. JMETHOD(void, forward_DCT, (j_compress_ptr cinfo,
  145257. jpeg_component_info * compptr,
  145258. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  145259. JDIMENSION start_row, JDIMENSION start_col,
  145260. JDIMENSION num_blocks));
  145261. };
  145262. struct jpeg_entropy_encoder {
  145263. JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics));
  145264. JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data));
  145265. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145266. };
  145267. struct jpeg_marker_writer {
  145268. JMETHOD(void, write_file_header, (j_compress_ptr cinfo));
  145269. JMETHOD(void, write_frame_header, (j_compress_ptr cinfo));
  145270. JMETHOD(void, write_scan_header, (j_compress_ptr cinfo));
  145271. JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo));
  145272. JMETHOD(void, write_tables_only, (j_compress_ptr cinfo));
  145273. JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker,
  145274. unsigned int datalen));
  145275. JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val));
  145276. };
  145277. struct jpeg_decomp_master {
  145278. JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo));
  145279. JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo));
  145280. boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */
  145281. };
  145282. struct jpeg_input_controller {
  145283. JMETHOD(int, consume_input, (j_decompress_ptr cinfo));
  145284. JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo));
  145285. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145286. JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo));
  145287. boolean has_multiple_scans; /* True if file has multiple scans */
  145288. boolean eoi_reached; /* True when EOI has been consumed */
  145289. };
  145290. struct jpeg_d_main_controller {
  145291. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145292. JMETHOD(void, process_data, (j_decompress_ptr cinfo,
  145293. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  145294. JDIMENSION out_rows_avail));
  145295. };
  145296. struct jpeg_d_coef_controller {
  145297. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145298. JMETHOD(int, consume_data, (j_decompress_ptr cinfo));
  145299. JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo));
  145300. JMETHOD(int, decompress_data, (j_decompress_ptr cinfo,
  145301. JSAMPIMAGE output_buf));
  145302. jvirt_barray_ptr *coef_arrays;
  145303. };
  145304. struct jpeg_d_post_controller {
  145305. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145306. JMETHOD(void, post_process_data, (j_decompress_ptr cinfo,
  145307. JSAMPIMAGE input_buf,
  145308. JDIMENSION *in_row_group_ctr,
  145309. JDIMENSION in_row_groups_avail,
  145310. JSAMPARRAY output_buf,
  145311. JDIMENSION *out_row_ctr,
  145312. JDIMENSION out_rows_avail));
  145313. };
  145314. struct jpeg_marker_reader {
  145315. JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo));
  145316. JMETHOD(int, read_markers, (j_decompress_ptr cinfo));
  145317. jpeg_marker_parser_method read_restart_marker;
  145318. boolean saw_SOI; /* found SOI? */
  145319. boolean saw_SOF; /* found SOF? */
  145320. int next_restart_num; /* next restart number expected (0-7) */
  145321. unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */
  145322. };
  145323. struct jpeg_entropy_decoder {
  145324. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145325. JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo,
  145326. JBLOCKROW *MCU_data));
  145327. boolean insufficient_data; /* set TRUE after emitting warning */
  145328. };
  145329. typedef JMETHOD(void, inverse_DCT_method_ptr,
  145330. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  145331. JCOEFPTR coef_block,
  145332. JSAMPARRAY output_buf, JDIMENSION output_col));
  145333. struct jpeg_inverse_dct {
  145334. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145335. inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
  145336. };
  145337. struct jpeg_upsampler {
  145338. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145339. JMETHOD(void, upsample, (j_decompress_ptr cinfo,
  145340. JSAMPIMAGE input_buf,
  145341. JDIMENSION *in_row_group_ctr,
  145342. JDIMENSION in_row_groups_avail,
  145343. JSAMPARRAY output_buf,
  145344. JDIMENSION *out_row_ctr,
  145345. JDIMENSION out_rows_avail));
  145346. boolean need_context_rows; /* TRUE if need rows above & below */
  145347. };
  145348. struct jpeg_color_deconverter {
  145349. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145350. JMETHOD(void, color_convert, (j_decompress_ptr cinfo,
  145351. JSAMPIMAGE input_buf, JDIMENSION input_row,
  145352. JSAMPARRAY output_buf, int num_rows));
  145353. };
  145354. struct jpeg_color_quantizer {
  145355. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan));
  145356. JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,
  145357. JSAMPARRAY input_buf, JSAMPARRAY output_buf,
  145358. int num_rows));
  145359. JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
  145360. JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));
  145361. };
  145362. #undef MAX
  145363. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  145364. #undef MIN
  145365. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  145366. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  145367. #define SHIFT_TEMPS INT32 shift_temp;
  145368. #define RIGHT_SHIFT(x,shft) \
  145369. ((shift_temp = (x)) < 0 ? \
  145370. (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
  145371. (shift_temp >> (shft)))
  145372. #else
  145373. #define SHIFT_TEMPS
  145374. #define RIGHT_SHIFT(x,shft) ((x) >> (shft))
  145375. #endif
  145376. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145377. #define jinit_compress_master jICompress
  145378. #define jinit_c_master_control jICMaster
  145379. #define jinit_c_main_controller jICMainC
  145380. #define jinit_c_prep_controller jICPrepC
  145381. #define jinit_c_coef_controller jICCoefC
  145382. #define jinit_color_converter jICColor
  145383. #define jinit_downsampler jIDownsampler
  145384. #define jinit_forward_dct jIFDCT
  145385. #define jinit_huff_encoder jIHEncoder
  145386. #define jinit_phuff_encoder jIPHEncoder
  145387. #define jinit_marker_writer jIMWriter
  145388. #define jinit_master_decompress jIDMaster
  145389. #define jinit_d_main_controller jIDMainC
  145390. #define jinit_d_coef_controller jIDCoefC
  145391. #define jinit_d_post_controller jIDPostC
  145392. #define jinit_input_controller jIInCtlr
  145393. #define jinit_marker_reader jIMReader
  145394. #define jinit_huff_decoder jIHDecoder
  145395. #define jinit_phuff_decoder jIPHDecoder
  145396. #define jinit_inverse_dct jIIDCT
  145397. #define jinit_upsampler jIUpsampler
  145398. #define jinit_color_deconverter jIDColor
  145399. #define jinit_1pass_quantizer jI1Quant
  145400. #define jinit_2pass_quantizer jI2Quant
  145401. #define jinit_merged_upsampler jIMUpsampler
  145402. #define jinit_memory_mgr jIMemMgr
  145403. #define jdiv_round_up jDivRound
  145404. #define jround_up jRound
  145405. #define jcopy_sample_rows jCopySamples
  145406. #define jcopy_block_row jCopyBlocks
  145407. #define jzero_far jZeroFar
  145408. #define jpeg_zigzag_order jZIGTable
  145409. #define jpeg_natural_order jZAGTable
  145410. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145411. EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
  145412. EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
  145413. boolean transcode_only));
  145414. EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo,
  145415. boolean need_full_buffer));
  145416. EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo,
  145417. boolean need_full_buffer));
  145418. EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo,
  145419. boolean need_full_buffer));
  145420. EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo));
  145421. EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo));
  145422. EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo));
  145423. EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo));
  145424. EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo));
  145425. EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo));
  145426. EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo));
  145427. EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo,
  145428. boolean need_full_buffer));
  145429. EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo,
  145430. boolean need_full_buffer));
  145431. EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo,
  145432. boolean need_full_buffer));
  145433. EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo));
  145434. EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo));
  145435. EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo));
  145436. EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo));
  145437. EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo));
  145438. EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo));
  145439. EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo));
  145440. EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo));
  145441. EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo));
  145442. EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo));
  145443. EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
  145444. EXTERN(long) jdiv_round_up JPP((long a, long b));
  145445. EXTERN(long) jround_up JPP((long a, long b));
  145446. EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row,
  145447. JSAMPARRAY output_array, int dest_row,
  145448. int num_rows, JDIMENSION num_cols));
  145449. EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
  145450. JDIMENSION num_blocks));
  145451. EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
  145452. #if 0 /* This table is not actually needed in v6a */
  145453. extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
  145454. #endif
  145455. extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
  145456. #ifdef INCOMPLETE_TYPES_BROKEN
  145457. #ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */
  145458. struct jvirt_sarray_control { long dummy; };
  145459. struct jvirt_barray_control { long dummy; };
  145460. #endif
  145461. #endif /* INCOMPLETE_TYPES_BROKEN */
  145462. /*** End of inlined file: jpegint.h ***/
  145463. /* fetch private declarations */
  145464. /*** Start of inlined file: jerror.h ***/
  145465. #ifndef JMESSAGE
  145466. #ifndef JERROR_H
  145467. #define JMAKE_ENUM_LIST
  145468. #else
  145469. #define JMESSAGE(code,string)
  145470. #endif /* JERROR_H */
  145471. #endif /* JMESSAGE */
  145472. #ifdef JMAKE_ENUM_LIST
  145473. typedef enum {
  145474. #define JMESSAGE(code,string) code ,
  145475. #endif /* JMAKE_ENUM_LIST */
  145476. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  145477. JMESSAGE(JERR_ARITH_NOTIMPL,
  145478. "Sorry, there are legal restrictions on arithmetic coding")
  145479. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  145480. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  145481. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  145482. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  145483. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  145484. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  145485. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  145486. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  145487. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  145488. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  145489. JMESSAGE(JERR_BAD_LIB_VERSION,
  145490. "Wrong JPEG library version: library is %d, caller expects %d")
  145491. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  145492. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  145493. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  145494. JMESSAGE(JERR_BAD_PROGRESSION,
  145495. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  145496. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  145497. "Invalid progressive parameters at scan script entry %d")
  145498. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  145499. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  145500. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  145501. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  145502. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  145503. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  145504. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  145505. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  145506. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  145507. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  145508. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  145509. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  145510. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  145511. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  145512. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  145513. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  145514. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  145515. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  145516. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  145517. JMESSAGE(JERR_FILE_READ, "Input file read error")
  145518. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  145519. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  145520. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  145521. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  145522. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  145523. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  145524. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  145525. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  145526. "Cannot transcode due to multiple use of quantization table %d")
  145527. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  145528. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  145529. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  145530. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  145531. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  145532. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  145533. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  145534. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  145535. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  145536. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  145537. JMESSAGE(JERR_QUANT_COMPONENTS,
  145538. "Cannot quantize more than %d color components")
  145539. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  145540. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  145541. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  145542. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  145543. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  145544. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  145545. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  145546. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  145547. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  145548. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  145549. JMESSAGE(JERR_TFILE_WRITE,
  145550. "Write failed on temporary file --- out of disk space?")
  145551. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  145552. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  145553. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  145554. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  145555. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  145556. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  145557. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  145558. JMESSAGE(JMSG_VERSION, JVERSION)
  145559. JMESSAGE(JTRC_16BIT_TABLES,
  145560. "Caution: quantization tables are too coarse for baseline JPEG")
  145561. JMESSAGE(JTRC_ADOBE,
  145562. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  145563. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  145564. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  145565. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  145566. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  145567. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  145568. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  145569. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  145570. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  145571. JMESSAGE(JTRC_EOI, "End Of Image")
  145572. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  145573. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  145574. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  145575. "Warning: thumbnail image size does not match data length %u")
  145576. JMESSAGE(JTRC_JFIF_EXTENSION,
  145577. "JFIF extension marker: type 0x%02x, length %u")
  145578. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  145579. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  145580. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  145581. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  145582. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  145583. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  145584. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  145585. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  145586. JMESSAGE(JTRC_RST, "RST%d")
  145587. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  145588. "Smoothing not supported with nonstandard sampling ratios")
  145589. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  145590. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  145591. JMESSAGE(JTRC_SOI, "Start of Image")
  145592. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  145593. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  145594. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  145595. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  145596. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  145597. JMESSAGE(JTRC_THUMB_JPEG,
  145598. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  145599. JMESSAGE(JTRC_THUMB_PALETTE,
  145600. "JFIF extension marker: palette thumbnail image, length %u")
  145601. JMESSAGE(JTRC_THUMB_RGB,
  145602. "JFIF extension marker: RGB thumbnail image, length %u")
  145603. JMESSAGE(JTRC_UNKNOWN_IDS,
  145604. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  145605. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  145606. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  145607. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  145608. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  145609. "Inconsistent progression sequence for component %d coefficient %d")
  145610. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  145611. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  145612. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  145613. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  145614. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  145615. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  145616. JMESSAGE(JWRN_MUST_RESYNC,
  145617. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  145618. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  145619. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  145620. #ifdef JMAKE_ENUM_LIST
  145621. JMSG_LASTMSGCODE
  145622. } J_MESSAGE_CODE;
  145623. #undef JMAKE_ENUM_LIST
  145624. #endif /* JMAKE_ENUM_LIST */
  145625. #undef JMESSAGE
  145626. #ifndef JERROR_H
  145627. #define JERROR_H
  145628. #define ERREXIT(cinfo,code) \
  145629. ((cinfo)->err->msg_code = (code), \
  145630. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145631. #define ERREXIT1(cinfo,code,p1) \
  145632. ((cinfo)->err->msg_code = (code), \
  145633. (cinfo)->err->msg_parm.i[0] = (p1), \
  145634. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145635. #define ERREXIT2(cinfo,code,p1,p2) \
  145636. ((cinfo)->err->msg_code = (code), \
  145637. (cinfo)->err->msg_parm.i[0] = (p1), \
  145638. (cinfo)->err->msg_parm.i[1] = (p2), \
  145639. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145640. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  145641. ((cinfo)->err->msg_code = (code), \
  145642. (cinfo)->err->msg_parm.i[0] = (p1), \
  145643. (cinfo)->err->msg_parm.i[1] = (p2), \
  145644. (cinfo)->err->msg_parm.i[2] = (p3), \
  145645. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145646. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  145647. ((cinfo)->err->msg_code = (code), \
  145648. (cinfo)->err->msg_parm.i[0] = (p1), \
  145649. (cinfo)->err->msg_parm.i[1] = (p2), \
  145650. (cinfo)->err->msg_parm.i[2] = (p3), \
  145651. (cinfo)->err->msg_parm.i[3] = (p4), \
  145652. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145653. #define ERREXITS(cinfo,code,str) \
  145654. ((cinfo)->err->msg_code = (code), \
  145655. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  145656. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145657. #define MAKESTMT(stuff) do { stuff } while (0)
  145658. #define WARNMS(cinfo,code) \
  145659. ((cinfo)->err->msg_code = (code), \
  145660. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145661. #define WARNMS1(cinfo,code,p1) \
  145662. ((cinfo)->err->msg_code = (code), \
  145663. (cinfo)->err->msg_parm.i[0] = (p1), \
  145664. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145665. #define WARNMS2(cinfo,code,p1,p2) \
  145666. ((cinfo)->err->msg_code = (code), \
  145667. (cinfo)->err->msg_parm.i[0] = (p1), \
  145668. (cinfo)->err->msg_parm.i[1] = (p2), \
  145669. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145670. #define TRACEMS(cinfo,lvl,code) \
  145671. ((cinfo)->err->msg_code = (code), \
  145672. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145673. #define TRACEMS1(cinfo,lvl,code,p1) \
  145674. ((cinfo)->err->msg_code = (code), \
  145675. (cinfo)->err->msg_parm.i[0] = (p1), \
  145676. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145677. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  145678. ((cinfo)->err->msg_code = (code), \
  145679. (cinfo)->err->msg_parm.i[0] = (p1), \
  145680. (cinfo)->err->msg_parm.i[1] = (p2), \
  145681. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145682. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  145683. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145684. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  145685. (cinfo)->err->msg_code = (code); \
  145686. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145687. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  145688. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145689. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145690. (cinfo)->err->msg_code = (code); \
  145691. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145692. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  145693. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145694. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145695. _mp[4] = (p5); \
  145696. (cinfo)->err->msg_code = (code); \
  145697. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145698. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  145699. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145700. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145701. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  145702. (cinfo)->err->msg_code = (code); \
  145703. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145704. #define TRACEMSS(cinfo,lvl,code,str) \
  145705. ((cinfo)->err->msg_code = (code), \
  145706. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  145707. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145708. #endif /* JERROR_H */
  145709. /*** End of inlined file: jerror.h ***/
  145710. /* fetch error codes too */
  145711. #endif
  145712. #endif /* JPEGLIB_H */
  145713. /*** End of inlined file: jpeglib.h ***/
  145714. /*** Start of inlined file: jcapimin.c ***/
  145715. #define JPEG_INTERNALS
  145716. /*** Start of inlined file: jinclude.h ***/
  145717. #ifndef __jinclude_h__
  145718. #define __jinclude_h__
  145719. /*** Start of inlined file: jconfig.h ***/
  145720. // disable all the warnings under MSVC
  145721. #ifdef _MSC_VER
  145722. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  145723. #endif
  145724. #ifdef __BORLANDC__
  145725. #pragma warn -8057
  145726. #pragma warn -8019
  145727. #pragma warn -8004
  145728. #pragma warn -8008
  145729. #endif
  145730. #define HAVE_PROTOTYPES
  145731. #define HAVE_UNSIGNED_CHAR
  145732. #define HAVE_UNSIGNED_SHORT
  145733. #undef CHAR_IS_UNSIGNED
  145734. #define HAVE_STDDEF_H
  145735. #define HAVE_STDLIB_H
  145736. #undef NEED_BSD_STRINGS
  145737. #undef NEED_SYS_TYPES_H
  145738. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  145739. #undef NEED_SHORT_EXTERNAL_NAMES
  145740. #undef INCOMPLETE_TYPES_BROKEN
  145741. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  145742. typedef unsigned char boolean;
  145743. #endif
  145744. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  145745. #ifdef JPEG_INTERNALS
  145746. #undef RIGHT_SHIFT_IS_UNSIGNED
  145747. #endif /* JPEG_INTERNALS */
  145748. #ifdef JPEG_CJPEG_DJPEG
  145749. #define BMP_SUPPORTED /* BMP image file format */
  145750. #define GIF_SUPPORTED /* GIF image file format */
  145751. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  145752. #undef RLE_SUPPORTED /* Utah RLE image file format */
  145753. #define TARGA_SUPPORTED /* Targa image file format */
  145754. #define TWO_FILE_COMMANDLINE /* optional */
  145755. #define USE_SETMODE /* Microsoft has setmode() */
  145756. #undef NEED_SIGNAL_CATCHER
  145757. #undef DONT_USE_B_MODE
  145758. #undef PROGRESS_REPORT /* optional */
  145759. #endif /* JPEG_CJPEG_DJPEG */
  145760. /*** End of inlined file: jconfig.h ***/
  145761. /* auto configuration options */
  145762. #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */
  145763. #ifdef HAVE_STDDEF_H
  145764. #include <stddef.h>
  145765. #endif
  145766. #ifdef HAVE_STDLIB_H
  145767. #include <stdlib.h>
  145768. #endif
  145769. #ifdef NEED_SYS_TYPES_H
  145770. #include <sys/types.h>
  145771. #endif
  145772. #include <stdio.h>
  145773. #ifdef NEED_BSD_STRINGS
  145774. #include <strings.h>
  145775. #define MEMZERO(target,size) bzero((void *)(target), (size_t)(size))
  145776. #define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size))
  145777. #else /* not BSD, assume ANSI/SysV string lib */
  145778. #include <string.h>
  145779. #define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size))
  145780. #define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size))
  145781. #endif
  145782. #define SIZEOF(object) ((size_t) sizeof(object))
  145783. #define JFREAD(file,buf,sizeofbuf) \
  145784. ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  145785. #define JFWRITE(file,buf,sizeofbuf) \
  145786. ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  145787. typedef enum { /* JPEG marker codes */
  145788. M_SOF0 = 0xc0,
  145789. M_SOF1 = 0xc1,
  145790. M_SOF2 = 0xc2,
  145791. M_SOF3 = 0xc3,
  145792. M_SOF5 = 0xc5,
  145793. M_SOF6 = 0xc6,
  145794. M_SOF7 = 0xc7,
  145795. M_JPG = 0xc8,
  145796. M_SOF9 = 0xc9,
  145797. M_SOF10 = 0xca,
  145798. M_SOF11 = 0xcb,
  145799. M_SOF13 = 0xcd,
  145800. M_SOF14 = 0xce,
  145801. M_SOF15 = 0xcf,
  145802. M_DHT = 0xc4,
  145803. M_DAC = 0xcc,
  145804. M_RST0 = 0xd0,
  145805. M_RST1 = 0xd1,
  145806. M_RST2 = 0xd2,
  145807. M_RST3 = 0xd3,
  145808. M_RST4 = 0xd4,
  145809. M_RST5 = 0xd5,
  145810. M_RST6 = 0xd6,
  145811. M_RST7 = 0xd7,
  145812. M_SOI = 0xd8,
  145813. M_EOI = 0xd9,
  145814. M_SOS = 0xda,
  145815. M_DQT = 0xdb,
  145816. M_DNL = 0xdc,
  145817. M_DRI = 0xdd,
  145818. M_DHP = 0xde,
  145819. M_EXP = 0xdf,
  145820. M_APP0 = 0xe0,
  145821. M_APP1 = 0xe1,
  145822. M_APP2 = 0xe2,
  145823. M_APP3 = 0xe3,
  145824. M_APP4 = 0xe4,
  145825. M_APP5 = 0xe5,
  145826. M_APP6 = 0xe6,
  145827. M_APP7 = 0xe7,
  145828. M_APP8 = 0xe8,
  145829. M_APP9 = 0xe9,
  145830. M_APP10 = 0xea,
  145831. M_APP11 = 0xeb,
  145832. M_APP12 = 0xec,
  145833. M_APP13 = 0xed,
  145834. M_APP14 = 0xee,
  145835. M_APP15 = 0xef,
  145836. M_JPG0 = 0xf0,
  145837. M_JPG13 = 0xfd,
  145838. M_COM = 0xfe,
  145839. M_TEM = 0x01,
  145840. M_ERROR = 0x100
  145841. } JPEG_MARKER;
  145842. #ifdef AVOID_TABLES
  145843. #define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x))
  145844. #else
  145845. #define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
  145846. static const int extend_test[16] = /* entry n is 2**(n-1) */
  145847. { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
  145848. 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
  145849. static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
  145850. { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
  145851. ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
  145852. ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
  145853. ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
  145854. #endif /* AVOID_TABLES */
  145855. #endif
  145856. /*** End of inlined file: jinclude.h ***/
  145857. GLOBAL(void)
  145858. jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
  145859. {
  145860. int i;
  145861. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  145862. if (version != JPEG_LIB_VERSION)
  145863. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  145864. if (structsize != SIZEOF(struct jpeg_compress_struct))
  145865. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  145866. (int) SIZEOF(struct jpeg_compress_struct), (int) structsize);
  145867. {
  145868. struct jpeg_error_mgr * err = cinfo->err;
  145869. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  145870. MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));
  145871. cinfo->err = err;
  145872. cinfo->client_data = client_data;
  145873. }
  145874. cinfo->is_decompressor = FALSE;
  145875. jinit_memory_mgr((j_common_ptr) cinfo);
  145876. cinfo->progress = NULL;
  145877. cinfo->dest = NULL;
  145878. cinfo->comp_info = NULL;
  145879. for (i = 0; i < NUM_QUANT_TBLS; i++)
  145880. cinfo->quant_tbl_ptrs[i] = NULL;
  145881. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  145882. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  145883. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  145884. }
  145885. cinfo->script_space = NULL;
  145886. cinfo->input_gamma = 1.0; /* in case application forgets */
  145887. cinfo->global_state = CSTATE_START;
  145888. }
  145889. GLOBAL(void)
  145890. jpeg_destroy_compress (j_compress_ptr cinfo)
  145891. {
  145892. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  145893. }
  145894. GLOBAL(void)
  145895. jpeg_abort_compress (j_compress_ptr cinfo)
  145896. {
  145897. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  145898. }
  145899. GLOBAL(void)
  145900. jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
  145901. {
  145902. int i;
  145903. JQUANT_TBL * qtbl;
  145904. JHUFF_TBL * htbl;
  145905. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  145906. if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
  145907. qtbl->sent_table = suppress;
  145908. }
  145909. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  145910. if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
  145911. htbl->sent_table = suppress;
  145912. if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
  145913. htbl->sent_table = suppress;
  145914. }
  145915. }
  145916. GLOBAL(void)
  145917. jpeg_finish_compress (j_compress_ptr cinfo)
  145918. {
  145919. JDIMENSION iMCU_row;
  145920. if (cinfo->global_state == CSTATE_SCANNING ||
  145921. cinfo->global_state == CSTATE_RAW_OK) {
  145922. if (cinfo->next_scanline < cinfo->image_height)
  145923. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  145924. (*cinfo->master->finish_pass) (cinfo);
  145925. } else if (cinfo->global_state != CSTATE_WRCOEFS)
  145926. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145927. while (! cinfo->master->is_last_pass) {
  145928. (*cinfo->master->prepare_for_pass) (cinfo);
  145929. for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
  145930. if (cinfo->progress != NULL) {
  145931. cinfo->progress->pass_counter = (long) iMCU_row;
  145932. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
  145933. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  145934. }
  145935. if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
  145936. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  145937. }
  145938. (*cinfo->master->finish_pass) (cinfo);
  145939. }
  145940. (*cinfo->marker->write_file_trailer) (cinfo);
  145941. (*cinfo->dest->term_destination) (cinfo);
  145942. jpeg_abort((j_common_ptr) cinfo);
  145943. }
  145944. GLOBAL(void)
  145945. jpeg_write_marker (j_compress_ptr cinfo, int marker,
  145946. const JOCTET *dataptr, unsigned int datalen)
  145947. {
  145948. JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val));
  145949. if (cinfo->next_scanline != 0 ||
  145950. (cinfo->global_state != CSTATE_SCANNING &&
  145951. cinfo->global_state != CSTATE_RAW_OK &&
  145952. cinfo->global_state != CSTATE_WRCOEFS))
  145953. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145954. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  145955. write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
  145956. while (datalen--) {
  145957. (*write_marker_byte) (cinfo, *dataptr);
  145958. dataptr++;
  145959. }
  145960. }
  145961. GLOBAL(void)
  145962. jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  145963. {
  145964. if (cinfo->next_scanline != 0 ||
  145965. (cinfo->global_state != CSTATE_SCANNING &&
  145966. cinfo->global_state != CSTATE_RAW_OK &&
  145967. cinfo->global_state != CSTATE_WRCOEFS))
  145968. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145969. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  145970. }
  145971. GLOBAL(void)
  145972. jpeg_write_m_byte (j_compress_ptr cinfo, int val)
  145973. {
  145974. (*cinfo->marker->write_marker_byte) (cinfo, val);
  145975. }
  145976. GLOBAL(void)
  145977. jpeg_write_tables (j_compress_ptr cinfo)
  145978. {
  145979. if (cinfo->global_state != CSTATE_START)
  145980. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145981. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  145982. (*cinfo->dest->init_destination) (cinfo);
  145983. jinit_marker_writer(cinfo);
  145984. (*cinfo->marker->write_tables_only) (cinfo);
  145985. (*cinfo->dest->term_destination) (cinfo);
  145986. }
  145987. /*** End of inlined file: jcapimin.c ***/
  145988. /*** Start of inlined file: jcapistd.c ***/
  145989. #define JPEG_INTERNALS
  145990. GLOBAL(void)
  145991. jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
  145992. {
  145993. if (cinfo->global_state != CSTATE_START)
  145994. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145995. if (write_all_tables)
  145996. jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
  145997. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  145998. (*cinfo->dest->init_destination) (cinfo);
  145999. jinit_compress_master(cinfo);
  146000. (*cinfo->master->prepare_for_pass) (cinfo);
  146001. cinfo->next_scanline = 0;
  146002. cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
  146003. }
  146004. GLOBAL(JDIMENSION)
  146005. jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
  146006. JDIMENSION num_lines)
  146007. {
  146008. JDIMENSION row_ctr, rows_left;
  146009. if (cinfo->global_state != CSTATE_SCANNING)
  146010. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146011. if (cinfo->next_scanline >= cinfo->image_height)
  146012. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  146013. if (cinfo->progress != NULL) {
  146014. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  146015. cinfo->progress->pass_limit = (long) cinfo->image_height;
  146016. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146017. }
  146018. if (cinfo->master->call_pass_startup)
  146019. (*cinfo->master->pass_startup) (cinfo);
  146020. rows_left = cinfo->image_height - cinfo->next_scanline;
  146021. if (num_lines > rows_left)
  146022. num_lines = rows_left;
  146023. row_ctr = 0;
  146024. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
  146025. cinfo->next_scanline += row_ctr;
  146026. return row_ctr;
  146027. }
  146028. GLOBAL(JDIMENSION)
  146029. jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
  146030. JDIMENSION num_lines)
  146031. {
  146032. JDIMENSION lines_per_iMCU_row;
  146033. if (cinfo->global_state != CSTATE_RAW_OK)
  146034. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146035. if (cinfo->next_scanline >= cinfo->image_height) {
  146036. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  146037. return 0;
  146038. }
  146039. if (cinfo->progress != NULL) {
  146040. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  146041. cinfo->progress->pass_limit = (long) cinfo->image_height;
  146042. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146043. }
  146044. if (cinfo->master->call_pass_startup)
  146045. (*cinfo->master->pass_startup) (cinfo);
  146046. lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
  146047. if (num_lines < lines_per_iMCU_row)
  146048. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  146049. if (! (*cinfo->coef->compress_data) (cinfo, data)) {
  146050. return 0;
  146051. }
  146052. cinfo->next_scanline += lines_per_iMCU_row;
  146053. return lines_per_iMCU_row;
  146054. }
  146055. /*** End of inlined file: jcapistd.c ***/
  146056. /*** Start of inlined file: jccoefct.c ***/
  146057. #define JPEG_INTERNALS
  146058. #ifdef ENTROPY_OPT_SUPPORTED
  146059. #define FULL_COEF_BUFFER_SUPPORTED
  146060. #else
  146061. #ifdef C_MULTISCAN_FILES_SUPPORTED
  146062. #define FULL_COEF_BUFFER_SUPPORTED
  146063. #endif
  146064. #endif
  146065. typedef struct {
  146066. struct jpeg_c_coef_controller pub; /* public fields */
  146067. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  146068. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  146069. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  146070. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  146071. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  146072. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  146073. } my_coef_controller;
  146074. typedef my_coef_controller * my_coef_ptr;
  146075. METHODDEF(boolean) compress_data
  146076. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146077. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146078. METHODDEF(boolean) compress_first_pass
  146079. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146080. METHODDEF(boolean) compress_output
  146081. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146082. #endif
  146083. LOCAL(void)
  146084. start_iMCU_row (j_compress_ptr cinfo)
  146085. {
  146086. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146087. if (cinfo->comps_in_scan > 1) {
  146088. coef->MCU_rows_per_iMCU_row = 1;
  146089. } else {
  146090. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  146091. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  146092. else
  146093. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  146094. }
  146095. coef->mcu_ctr = 0;
  146096. coef->MCU_vert_offset = 0;
  146097. }
  146098. METHODDEF(void)
  146099. start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  146100. {
  146101. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146102. coef->iMCU_row_num = 0;
  146103. start_iMCU_row(cinfo);
  146104. switch (pass_mode) {
  146105. case JBUF_PASS_THRU:
  146106. if (coef->whole_image[0] != NULL)
  146107. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146108. coef->pub.compress_data = compress_data;
  146109. break;
  146110. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146111. case JBUF_SAVE_AND_PASS:
  146112. if (coef->whole_image[0] == NULL)
  146113. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146114. coef->pub.compress_data = compress_first_pass;
  146115. break;
  146116. case JBUF_CRANK_DEST:
  146117. if (coef->whole_image[0] == NULL)
  146118. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146119. coef->pub.compress_data = compress_output;
  146120. break;
  146121. #endif
  146122. default:
  146123. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146124. break;
  146125. }
  146126. }
  146127. METHODDEF(boolean)
  146128. compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146129. {
  146130. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146131. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146132. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  146133. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146134. int blkn, bi, ci, yindex, yoffset, blockcnt;
  146135. JDIMENSION ypos, xpos;
  146136. jpeg_component_info *compptr;
  146137. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146138. yoffset++) {
  146139. for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;
  146140. MCU_col_num++) {
  146141. blkn = 0;
  146142. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146143. compptr = cinfo->cur_comp_info[ci];
  146144. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  146145. : compptr->last_col_width;
  146146. xpos = MCU_col_num * compptr->MCU_sample_width;
  146147. ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */
  146148. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146149. if (coef->iMCU_row_num < last_iMCU_row ||
  146150. yoffset+yindex < compptr->last_row_height) {
  146151. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146152. input_buf[compptr->component_index],
  146153. coef->MCU_buffer[blkn],
  146154. ypos, xpos, (JDIMENSION) blockcnt);
  146155. if (blockcnt < compptr->MCU_width) {
  146156. jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt],
  146157. (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
  146158. for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
  146159. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
  146160. }
  146161. }
  146162. } else {
  146163. jzero_far((void FAR *) coef->MCU_buffer[blkn],
  146164. compptr->MCU_width * SIZEOF(JBLOCK));
  146165. for (bi = 0; bi < compptr->MCU_width; bi++) {
  146166. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
  146167. }
  146168. }
  146169. blkn += compptr->MCU_width;
  146170. ypos += DCTSIZE;
  146171. }
  146172. }
  146173. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146174. coef->MCU_vert_offset = yoffset;
  146175. coef->mcu_ctr = MCU_col_num;
  146176. return FALSE;
  146177. }
  146178. }
  146179. coef->mcu_ctr = 0;
  146180. }
  146181. coef->iMCU_row_num++;
  146182. start_iMCU_row(cinfo);
  146183. return TRUE;
  146184. }
  146185. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146186. METHODDEF(boolean)
  146187. compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146188. {
  146189. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146190. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146191. JDIMENSION blocks_across, MCUs_across, MCUindex;
  146192. int bi, ci, h_samp_factor, block_row, block_rows, ndummy;
  146193. JCOEF lastDC;
  146194. jpeg_component_info *compptr;
  146195. JBLOCKARRAY buffer;
  146196. JBLOCKROW thisblockrow, lastblockrow;
  146197. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146198. ci++, compptr++) {
  146199. buffer = (*cinfo->mem->access_virt_barray)
  146200. ((j_common_ptr) cinfo, coef->whole_image[ci],
  146201. coef->iMCU_row_num * compptr->v_samp_factor,
  146202. (JDIMENSION) compptr->v_samp_factor, TRUE);
  146203. if (coef->iMCU_row_num < last_iMCU_row)
  146204. block_rows = compptr->v_samp_factor;
  146205. else {
  146206. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  146207. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  146208. }
  146209. blocks_across = compptr->width_in_blocks;
  146210. h_samp_factor = compptr->h_samp_factor;
  146211. ndummy = (int) (blocks_across % h_samp_factor);
  146212. if (ndummy > 0)
  146213. ndummy = h_samp_factor - ndummy;
  146214. for (block_row = 0; block_row < block_rows; block_row++) {
  146215. thisblockrow = buffer[block_row];
  146216. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146217. input_buf[ci], thisblockrow,
  146218. (JDIMENSION) (block_row * DCTSIZE),
  146219. (JDIMENSION) 0, blocks_across);
  146220. if (ndummy > 0) {
  146221. thisblockrow += blocks_across; /* => first dummy block */
  146222. jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
  146223. lastDC = thisblockrow[-1][0];
  146224. for (bi = 0; bi < ndummy; bi++) {
  146225. thisblockrow[bi][0] = lastDC;
  146226. }
  146227. }
  146228. }
  146229. if (coef->iMCU_row_num == last_iMCU_row) {
  146230. blocks_across += ndummy; /* include lower right corner */
  146231. MCUs_across = blocks_across / h_samp_factor;
  146232. for (block_row = block_rows; block_row < compptr->v_samp_factor;
  146233. block_row++) {
  146234. thisblockrow = buffer[block_row];
  146235. lastblockrow = buffer[block_row-1];
  146236. jzero_far((void FAR *) thisblockrow,
  146237. (size_t) (blocks_across * SIZEOF(JBLOCK)));
  146238. for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
  146239. lastDC = lastblockrow[h_samp_factor-1][0];
  146240. for (bi = 0; bi < h_samp_factor; bi++) {
  146241. thisblockrow[bi][0] = lastDC;
  146242. }
  146243. thisblockrow += h_samp_factor; /* advance to next MCU in row */
  146244. lastblockrow += h_samp_factor;
  146245. }
  146246. }
  146247. }
  146248. }
  146249. return compress_output(cinfo, input_buf);
  146250. }
  146251. METHODDEF(boolean)
  146252. compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146253. {
  146254. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146255. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146256. int blkn, ci, xindex, yindex, yoffset;
  146257. JDIMENSION start_col;
  146258. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  146259. JBLOCKROW buffer_ptr;
  146260. jpeg_component_info *compptr;
  146261. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146262. compptr = cinfo->cur_comp_info[ci];
  146263. buffer[ci] = (*cinfo->mem->access_virt_barray)
  146264. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  146265. coef->iMCU_row_num * compptr->v_samp_factor,
  146266. (JDIMENSION) compptr->v_samp_factor, FALSE);
  146267. }
  146268. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146269. yoffset++) {
  146270. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  146271. MCU_col_num++) {
  146272. blkn = 0; /* index of current DCT block within MCU */
  146273. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146274. compptr = cinfo->cur_comp_info[ci];
  146275. start_col = MCU_col_num * compptr->MCU_width;
  146276. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146277. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  146278. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  146279. coef->MCU_buffer[blkn++] = buffer_ptr++;
  146280. }
  146281. }
  146282. }
  146283. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146284. coef->MCU_vert_offset = yoffset;
  146285. coef->mcu_ctr = MCU_col_num;
  146286. return FALSE;
  146287. }
  146288. }
  146289. coef->mcu_ctr = 0;
  146290. }
  146291. coef->iMCU_row_num++;
  146292. start_iMCU_row(cinfo);
  146293. return TRUE;
  146294. }
  146295. #endif /* FULL_COEF_BUFFER_SUPPORTED */
  146296. GLOBAL(void)
  146297. jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  146298. {
  146299. my_coef_ptr coef;
  146300. coef = (my_coef_ptr)
  146301. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146302. SIZEOF(my_coef_controller));
  146303. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  146304. coef->pub.start_pass = start_pass_coef;
  146305. if (need_full_buffer) {
  146306. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146307. int ci;
  146308. jpeg_component_info *compptr;
  146309. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146310. ci++, compptr++) {
  146311. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  146312. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  146313. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  146314. (long) compptr->h_samp_factor),
  146315. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  146316. (long) compptr->v_samp_factor),
  146317. (JDIMENSION) compptr->v_samp_factor);
  146318. }
  146319. #else
  146320. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146321. #endif
  146322. } else {
  146323. JBLOCKROW buffer;
  146324. int i;
  146325. buffer = (JBLOCKROW)
  146326. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146327. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  146328. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  146329. coef->MCU_buffer[i] = buffer + i;
  146330. }
  146331. coef->whole_image[0] = NULL; /* flag for no virtual arrays */
  146332. }
  146333. }
  146334. /*** End of inlined file: jccoefct.c ***/
  146335. /*** Start of inlined file: jccolor.c ***/
  146336. #define JPEG_INTERNALS
  146337. typedef struct {
  146338. struct jpeg_color_converter pub; /* public fields */
  146339. INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */
  146340. } my_color_converter;
  146341. typedef my_color_converter * my_cconvert_ptr;
  146342. #define SCALEBITS 16 /* speediest right-shift on some machines */
  146343. #define CBCR_OFFSET ((INT32) CENTERJSAMPLE << SCALEBITS)
  146344. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  146345. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  146346. #define R_Y_OFF 0 /* offset to R => Y section */
  146347. #define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
  146348. #define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
  146349. #define R_CB_OFF (3*(MAXJSAMPLE+1))
  146350. #define G_CB_OFF (4*(MAXJSAMPLE+1))
  146351. #define B_CB_OFF (5*(MAXJSAMPLE+1))
  146352. #define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */
  146353. #define G_CR_OFF (6*(MAXJSAMPLE+1))
  146354. #define B_CR_OFF (7*(MAXJSAMPLE+1))
  146355. #define TABLE_SIZE (8*(MAXJSAMPLE+1))
  146356. METHODDEF(void)
  146357. rgb_ycc_start (j_compress_ptr cinfo)
  146358. {
  146359. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146360. INT32 * rgb_ycc_tab;
  146361. INT32 i;
  146362. cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
  146363. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146364. (TABLE_SIZE * SIZEOF(INT32)));
  146365. for (i = 0; i <= MAXJSAMPLE; i++) {
  146366. rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i;
  146367. rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i;
  146368. rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
  146369. rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i;
  146370. rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i;
  146371. rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1;
  146372. rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i;
  146373. rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i;
  146374. }
  146375. }
  146376. METHODDEF(void)
  146377. rgb_ycc_convert (j_compress_ptr cinfo,
  146378. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146379. JDIMENSION output_row, int num_rows)
  146380. {
  146381. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146382. register int r, g, b;
  146383. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146384. register JSAMPROW inptr;
  146385. register JSAMPROW outptr0, outptr1, outptr2;
  146386. register JDIMENSION col;
  146387. JDIMENSION num_cols = cinfo->image_width;
  146388. while (--num_rows >= 0) {
  146389. inptr = *input_buf++;
  146390. outptr0 = output_buf[0][output_row];
  146391. outptr1 = output_buf[1][output_row];
  146392. outptr2 = output_buf[2][output_row];
  146393. output_row++;
  146394. for (col = 0; col < num_cols; col++) {
  146395. r = GETJSAMPLE(inptr[RGB_RED]);
  146396. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146397. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146398. inptr += RGB_PIXELSIZE;
  146399. outptr0[col] = (JSAMPLE)
  146400. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146401. >> SCALEBITS);
  146402. outptr1[col] = (JSAMPLE)
  146403. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146404. >> SCALEBITS);
  146405. outptr2[col] = (JSAMPLE)
  146406. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146407. >> SCALEBITS);
  146408. }
  146409. }
  146410. }
  146411. METHODDEF(void)
  146412. rgb_gray_convert (j_compress_ptr cinfo,
  146413. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146414. JDIMENSION output_row, int num_rows)
  146415. {
  146416. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146417. register int r, g, b;
  146418. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146419. register JSAMPROW inptr;
  146420. register JSAMPROW outptr;
  146421. register JDIMENSION col;
  146422. JDIMENSION num_cols = cinfo->image_width;
  146423. while (--num_rows >= 0) {
  146424. inptr = *input_buf++;
  146425. outptr = output_buf[0][output_row];
  146426. output_row++;
  146427. for (col = 0; col < num_cols; col++) {
  146428. r = GETJSAMPLE(inptr[RGB_RED]);
  146429. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146430. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146431. inptr += RGB_PIXELSIZE;
  146432. outptr[col] = (JSAMPLE)
  146433. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146434. >> SCALEBITS);
  146435. }
  146436. }
  146437. }
  146438. METHODDEF(void)
  146439. cmyk_ycck_convert (j_compress_ptr cinfo,
  146440. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146441. JDIMENSION output_row, int num_rows)
  146442. {
  146443. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146444. register int r, g, b;
  146445. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146446. register JSAMPROW inptr;
  146447. register JSAMPROW outptr0, outptr1, outptr2, outptr3;
  146448. register JDIMENSION col;
  146449. JDIMENSION num_cols = cinfo->image_width;
  146450. while (--num_rows >= 0) {
  146451. inptr = *input_buf++;
  146452. outptr0 = output_buf[0][output_row];
  146453. outptr1 = output_buf[1][output_row];
  146454. outptr2 = output_buf[2][output_row];
  146455. outptr3 = output_buf[3][output_row];
  146456. output_row++;
  146457. for (col = 0; col < num_cols; col++) {
  146458. r = MAXJSAMPLE - GETJSAMPLE(inptr[0]);
  146459. g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);
  146460. b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
  146461. outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */
  146462. inptr += 4;
  146463. outptr0[col] = (JSAMPLE)
  146464. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146465. >> SCALEBITS);
  146466. outptr1[col] = (JSAMPLE)
  146467. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146468. >> SCALEBITS);
  146469. outptr2[col] = (JSAMPLE)
  146470. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146471. >> SCALEBITS);
  146472. }
  146473. }
  146474. }
  146475. METHODDEF(void)
  146476. grayscale_convert (j_compress_ptr cinfo,
  146477. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146478. JDIMENSION output_row, int num_rows)
  146479. {
  146480. register JSAMPROW inptr;
  146481. register JSAMPROW outptr;
  146482. register JDIMENSION col;
  146483. JDIMENSION num_cols = cinfo->image_width;
  146484. int instride = cinfo->input_components;
  146485. while (--num_rows >= 0) {
  146486. inptr = *input_buf++;
  146487. outptr = output_buf[0][output_row];
  146488. output_row++;
  146489. for (col = 0; col < num_cols; col++) {
  146490. outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */
  146491. inptr += instride;
  146492. }
  146493. }
  146494. }
  146495. METHODDEF(void)
  146496. null_convert (j_compress_ptr cinfo,
  146497. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146498. JDIMENSION output_row, int num_rows)
  146499. {
  146500. register JSAMPROW inptr;
  146501. register JSAMPROW outptr;
  146502. register JDIMENSION col;
  146503. register int ci;
  146504. int nc = cinfo->num_components;
  146505. JDIMENSION num_cols = cinfo->image_width;
  146506. while (--num_rows >= 0) {
  146507. for (ci = 0; ci < nc; ci++) {
  146508. inptr = *input_buf;
  146509. outptr = output_buf[ci][output_row];
  146510. for (col = 0; col < num_cols; col++) {
  146511. outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
  146512. inptr += nc;
  146513. }
  146514. }
  146515. input_buf++;
  146516. output_row++;
  146517. }
  146518. }
  146519. METHODDEF(void)
  146520. null_method (j_compress_ptr cinfo)
  146521. {
  146522. }
  146523. GLOBAL(void)
  146524. jinit_color_converter (j_compress_ptr cinfo)
  146525. {
  146526. my_cconvert_ptr cconvert;
  146527. cconvert = (my_cconvert_ptr)
  146528. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146529. SIZEOF(my_color_converter));
  146530. cinfo->cconvert = (struct jpeg_color_converter *) cconvert;
  146531. cconvert->pub.start_pass = null_method;
  146532. switch (cinfo->in_color_space) {
  146533. case JCS_GRAYSCALE:
  146534. if (cinfo->input_components != 1)
  146535. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146536. break;
  146537. case JCS_RGB:
  146538. #if RGB_PIXELSIZE != 3
  146539. if (cinfo->input_components != RGB_PIXELSIZE)
  146540. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146541. break;
  146542. #endif /* else share code with YCbCr */
  146543. case JCS_YCbCr:
  146544. if (cinfo->input_components != 3)
  146545. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146546. break;
  146547. case JCS_CMYK:
  146548. case JCS_YCCK:
  146549. if (cinfo->input_components != 4)
  146550. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146551. break;
  146552. default: /* JCS_UNKNOWN can be anything */
  146553. if (cinfo->input_components < 1)
  146554. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146555. break;
  146556. }
  146557. switch (cinfo->jpeg_color_space) {
  146558. case JCS_GRAYSCALE:
  146559. if (cinfo->num_components != 1)
  146560. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146561. if (cinfo->in_color_space == JCS_GRAYSCALE)
  146562. cconvert->pub.color_convert = grayscale_convert;
  146563. else if (cinfo->in_color_space == JCS_RGB) {
  146564. cconvert->pub.start_pass = rgb_ycc_start;
  146565. cconvert->pub.color_convert = rgb_gray_convert;
  146566. } else if (cinfo->in_color_space == JCS_YCbCr)
  146567. cconvert->pub.color_convert = grayscale_convert;
  146568. else
  146569. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146570. break;
  146571. case JCS_RGB:
  146572. if (cinfo->num_components != 3)
  146573. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146574. if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3)
  146575. cconvert->pub.color_convert = null_convert;
  146576. else
  146577. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146578. break;
  146579. case JCS_YCbCr:
  146580. if (cinfo->num_components != 3)
  146581. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146582. if (cinfo->in_color_space == JCS_RGB) {
  146583. cconvert->pub.start_pass = rgb_ycc_start;
  146584. cconvert->pub.color_convert = rgb_ycc_convert;
  146585. } else if (cinfo->in_color_space == JCS_YCbCr)
  146586. cconvert->pub.color_convert = null_convert;
  146587. else
  146588. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146589. break;
  146590. case JCS_CMYK:
  146591. if (cinfo->num_components != 4)
  146592. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146593. if (cinfo->in_color_space == JCS_CMYK)
  146594. cconvert->pub.color_convert = null_convert;
  146595. else
  146596. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146597. break;
  146598. case JCS_YCCK:
  146599. if (cinfo->num_components != 4)
  146600. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146601. if (cinfo->in_color_space == JCS_CMYK) {
  146602. cconvert->pub.start_pass = rgb_ycc_start;
  146603. cconvert->pub.color_convert = cmyk_ycck_convert;
  146604. } else if (cinfo->in_color_space == JCS_YCCK)
  146605. cconvert->pub.color_convert = null_convert;
  146606. else
  146607. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146608. break;
  146609. default: /* allow null conversion of JCS_UNKNOWN */
  146610. if (cinfo->jpeg_color_space != cinfo->in_color_space ||
  146611. cinfo->num_components != cinfo->input_components)
  146612. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146613. cconvert->pub.color_convert = null_convert;
  146614. break;
  146615. }
  146616. }
  146617. /*** End of inlined file: jccolor.c ***/
  146618. #undef FIX
  146619. /*** Start of inlined file: jcdctmgr.c ***/
  146620. #define JPEG_INTERNALS
  146621. /*** Start of inlined file: jdct.h ***/
  146622. #ifndef __jdct_h__
  146623. #define __jdct_h__
  146624. #if BITS_IN_JSAMPLE == 8
  146625. typedef int DCTELEM; /* 16 or 32 bits is fine */
  146626. #else
  146627. typedef INT32 DCTELEM; /* must have 32 bits */
  146628. #endif
  146629. typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data));
  146630. typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data));
  146631. typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */
  146632. #if BITS_IN_JSAMPLE == 8
  146633. typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */
  146634. #define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */
  146635. #else
  146636. typedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */
  146637. #define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */
  146638. #endif
  146639. typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
  146640. #define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE)
  146641. #define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */
  146642. #ifdef NEED_SHORT_EXTERNAL_NAMES
  146643. #define jpeg_fdct_islow jFDislow
  146644. #define jpeg_fdct_ifast jFDifast
  146645. #define jpeg_fdct_float jFDfloat
  146646. #define jpeg_idct_islow jRDislow
  146647. #define jpeg_idct_ifast jRDifast
  146648. #define jpeg_idct_float jRDfloat
  146649. #define jpeg_idct_4x4 jRD4x4
  146650. #define jpeg_idct_2x2 jRD2x2
  146651. #define jpeg_idct_1x1 jRD1x1
  146652. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  146653. EXTERN(void) jpeg_fdct_islow JPP((DCTELEM * data));
  146654. EXTERN(void) jpeg_fdct_ifast JPP((DCTELEM * data));
  146655. EXTERN(void) jpeg_fdct_float JPP((FAST_FLOAT * data));
  146656. EXTERN(void) jpeg_idct_islow
  146657. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146658. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146659. EXTERN(void) jpeg_idct_ifast
  146660. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146661. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146662. EXTERN(void) jpeg_idct_float
  146663. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146664. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146665. EXTERN(void) jpeg_idct_4x4
  146666. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146667. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146668. EXTERN(void) jpeg_idct_2x2
  146669. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146670. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146671. EXTERN(void) jpeg_idct_1x1
  146672. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146673. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146674. #define ONE ((INT32) 1)
  146675. #define CONST_SCALE (ONE << CONST_BITS)
  146676. #define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5))
  146677. #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
  146678. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  146679. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const)))
  146680. #endif
  146681. #ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */
  146682. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (const)))
  146683. #endif
  146684. #ifndef MULTIPLY16C16 /* default definition */
  146685. #define MULTIPLY16C16(var,const) ((var) * (const))
  146686. #endif
  146687. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  146688. #define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2)))
  146689. #endif
  146690. #ifndef MULTIPLY16V16 /* default definition */
  146691. #define MULTIPLY16V16(var1,var2) ((var1) * (var2))
  146692. #endif
  146693. #endif
  146694. /*** End of inlined file: jdct.h ***/
  146695. /* Private declarations for DCT subsystem */
  146696. typedef struct {
  146697. struct jpeg_forward_dct pub; /* public fields */
  146698. forward_DCT_method_ptr do_dct;
  146699. DCTELEM * divisors[NUM_QUANT_TBLS];
  146700. #ifdef DCT_FLOAT_SUPPORTED
  146701. float_DCT_method_ptr do_float_dct;
  146702. FAST_FLOAT * float_divisors[NUM_QUANT_TBLS];
  146703. #endif
  146704. } my_fdct_controller;
  146705. typedef my_fdct_controller * my_fdct_ptr;
  146706. METHODDEF(void)
  146707. start_pass_fdctmgr (j_compress_ptr cinfo)
  146708. {
  146709. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146710. int ci, qtblno, i;
  146711. jpeg_component_info *compptr;
  146712. JQUANT_TBL * qtbl;
  146713. DCTELEM * dtbl;
  146714. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146715. ci++, compptr++) {
  146716. qtblno = compptr->quant_tbl_no;
  146717. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  146718. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  146719. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  146720. qtbl = cinfo->quant_tbl_ptrs[qtblno];
  146721. switch (cinfo->dct_method) {
  146722. #ifdef DCT_ISLOW_SUPPORTED
  146723. case JDCT_ISLOW:
  146724. if (fdct->divisors[qtblno] == NULL) {
  146725. fdct->divisors[qtblno] = (DCTELEM *)
  146726. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146727. DCTSIZE2 * SIZEOF(DCTELEM));
  146728. }
  146729. dtbl = fdct->divisors[qtblno];
  146730. for (i = 0; i < DCTSIZE2; i++) {
  146731. dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
  146732. }
  146733. break;
  146734. #endif
  146735. #ifdef DCT_IFAST_SUPPORTED
  146736. case JDCT_IFAST:
  146737. {
  146738. #define CONST_BITS 14
  146739. static const INT16 aanscales[DCTSIZE2] = {
  146740. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  146741. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  146742. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  146743. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  146744. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  146745. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  146746. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  146747. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  146748. };
  146749. SHIFT_TEMPS
  146750. if (fdct->divisors[qtblno] == NULL) {
  146751. fdct->divisors[qtblno] = (DCTELEM *)
  146752. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146753. DCTSIZE2 * SIZEOF(DCTELEM));
  146754. }
  146755. dtbl = fdct->divisors[qtblno];
  146756. for (i = 0; i < DCTSIZE2; i++) {
  146757. dtbl[i] = (DCTELEM)
  146758. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  146759. (INT32) aanscales[i]),
  146760. CONST_BITS-3);
  146761. }
  146762. }
  146763. break;
  146764. #endif
  146765. #ifdef DCT_FLOAT_SUPPORTED
  146766. case JDCT_FLOAT:
  146767. {
  146768. FAST_FLOAT * fdtbl;
  146769. int row, col;
  146770. static const double aanscalefactor[DCTSIZE] = {
  146771. 1.0, 1.387039845, 1.306562965, 1.175875602,
  146772. 1.0, 0.785694958, 0.541196100, 0.275899379
  146773. };
  146774. if (fdct->float_divisors[qtblno] == NULL) {
  146775. fdct->float_divisors[qtblno] = (FAST_FLOAT *)
  146776. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146777. DCTSIZE2 * SIZEOF(FAST_FLOAT));
  146778. }
  146779. fdtbl = fdct->float_divisors[qtblno];
  146780. i = 0;
  146781. for (row = 0; row < DCTSIZE; row++) {
  146782. for (col = 0; col < DCTSIZE; col++) {
  146783. fdtbl[i] = (FAST_FLOAT)
  146784. (1.0 / (((double) qtbl->quantval[i] *
  146785. aanscalefactor[row] * aanscalefactor[col] * 8.0)));
  146786. i++;
  146787. }
  146788. }
  146789. }
  146790. break;
  146791. #endif
  146792. default:
  146793. ERREXIT(cinfo, JERR_NOT_COMPILED);
  146794. break;
  146795. }
  146796. }
  146797. }
  146798. METHODDEF(void)
  146799. forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
  146800. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  146801. JDIMENSION start_row, JDIMENSION start_col,
  146802. JDIMENSION num_blocks)
  146803. {
  146804. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146805. forward_DCT_method_ptr do_dct = fdct->do_dct;
  146806. DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no];
  146807. DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  146808. JDIMENSION bi;
  146809. sample_data += start_row; /* fold in the vertical offset once */
  146810. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  146811. { register DCTELEM *workspaceptr;
  146812. register JSAMPROW elemptr;
  146813. register int elemr;
  146814. workspaceptr = workspace;
  146815. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  146816. elemptr = sample_data[elemr] + start_col;
  146817. #if DCTSIZE == 8 /* unroll the inner loop */
  146818. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146819. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146820. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146821. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146822. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146823. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146824. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146825. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146826. #else
  146827. { register int elemc;
  146828. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  146829. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146830. }
  146831. }
  146832. #endif
  146833. }
  146834. }
  146835. (*do_dct) (workspace);
  146836. { register DCTELEM temp, qval;
  146837. register int i;
  146838. register JCOEFPTR output_ptr = coef_blocks[bi];
  146839. for (i = 0; i < DCTSIZE2; i++) {
  146840. qval = divisors[i];
  146841. temp = workspace[i];
  146842. #ifdef FAST_DIVIDE
  146843. #define DIVIDE_BY(a,b) a /= b
  146844. #else
  146845. #define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0
  146846. #endif
  146847. if (temp < 0) {
  146848. temp = -temp;
  146849. temp += qval>>1; /* for rounding */
  146850. DIVIDE_BY(temp, qval);
  146851. temp = -temp;
  146852. } else {
  146853. temp += qval>>1; /* for rounding */
  146854. DIVIDE_BY(temp, qval);
  146855. }
  146856. output_ptr[i] = (JCOEF) temp;
  146857. }
  146858. }
  146859. }
  146860. }
  146861. #ifdef DCT_FLOAT_SUPPORTED
  146862. METHODDEF(void)
  146863. forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
  146864. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  146865. JDIMENSION start_row, JDIMENSION start_col,
  146866. JDIMENSION num_blocks)
  146867. {
  146868. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146869. float_DCT_method_ptr do_dct = fdct->do_float_dct;
  146870. FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no];
  146871. FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  146872. JDIMENSION bi;
  146873. sample_data += start_row; /* fold in the vertical offset once */
  146874. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  146875. { register FAST_FLOAT *workspaceptr;
  146876. register JSAMPROW elemptr;
  146877. register int elemr;
  146878. workspaceptr = workspace;
  146879. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  146880. elemptr = sample_data[elemr] + start_col;
  146881. #if DCTSIZE == 8 /* unroll the inner loop */
  146882. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146883. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146884. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146885. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146886. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146887. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146888. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146889. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146890. #else
  146891. { register int elemc;
  146892. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  146893. *workspaceptr++ = (FAST_FLOAT)
  146894. (GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146895. }
  146896. }
  146897. #endif
  146898. }
  146899. }
  146900. (*do_dct) (workspace);
  146901. { register FAST_FLOAT temp;
  146902. register int i;
  146903. register JCOEFPTR output_ptr = coef_blocks[bi];
  146904. for (i = 0; i < DCTSIZE2; i++) {
  146905. temp = workspace[i] * divisors[i];
  146906. output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);
  146907. }
  146908. }
  146909. }
  146910. }
  146911. #endif /* DCT_FLOAT_SUPPORTED */
  146912. GLOBAL(void)
  146913. jinit_forward_dct (j_compress_ptr cinfo)
  146914. {
  146915. my_fdct_ptr fdct;
  146916. int i;
  146917. fdct = (my_fdct_ptr)
  146918. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146919. SIZEOF(my_fdct_controller));
  146920. cinfo->fdct = (struct jpeg_forward_dct *) fdct;
  146921. fdct->pub.start_pass = start_pass_fdctmgr;
  146922. switch (cinfo->dct_method) {
  146923. #ifdef DCT_ISLOW_SUPPORTED
  146924. case JDCT_ISLOW:
  146925. fdct->pub.forward_DCT = forward_DCT;
  146926. fdct->do_dct = jpeg_fdct_islow;
  146927. break;
  146928. #endif
  146929. #ifdef DCT_IFAST_SUPPORTED
  146930. case JDCT_IFAST:
  146931. fdct->pub.forward_DCT = forward_DCT;
  146932. fdct->do_dct = jpeg_fdct_ifast;
  146933. break;
  146934. #endif
  146935. #ifdef DCT_FLOAT_SUPPORTED
  146936. case JDCT_FLOAT:
  146937. fdct->pub.forward_DCT = forward_DCT_float;
  146938. fdct->do_float_dct = jpeg_fdct_float;
  146939. break;
  146940. #endif
  146941. default:
  146942. ERREXIT(cinfo, JERR_NOT_COMPILED);
  146943. break;
  146944. }
  146945. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  146946. fdct->divisors[i] = NULL;
  146947. #ifdef DCT_FLOAT_SUPPORTED
  146948. fdct->float_divisors[i] = NULL;
  146949. #endif
  146950. }
  146951. }
  146952. /*** End of inlined file: jcdctmgr.c ***/
  146953. #undef CONST_BITS
  146954. /*** Start of inlined file: jchuff.c ***/
  146955. #define JPEG_INTERNALS
  146956. /*** Start of inlined file: jchuff.h ***/
  146957. #ifndef _jchuff_h_
  146958. #define _jchuff_h_
  146959. #if BITS_IN_JSAMPLE == 8
  146960. #define MAX_COEF_BITS 10
  146961. #else
  146962. #define MAX_COEF_BITS 14
  146963. #endif
  146964. typedef struct {
  146965. unsigned int ehufco[256]; /* code for each symbol */
  146966. char ehufsi[256]; /* length of code for each symbol */
  146967. } c_derived_tbl;
  146968. #ifdef NEED_SHORT_EXTERNAL_NAMES
  146969. #define jpeg_make_c_derived_tbl jMkCDerived
  146970. #define jpeg_gen_optimal_table jGenOptTbl
  146971. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  146972. EXTERN(void) jpeg_make_c_derived_tbl
  146973. JPP((j_compress_ptr cinfo, boolean isDC, int tblno,
  146974. c_derived_tbl ** pdtbl));
  146975. EXTERN(void) jpeg_gen_optimal_table
  146976. JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[]));
  146977. #endif
  146978. /*** End of inlined file: jchuff.h ***/
  146979. /* Declarations shared with jcphuff.c */
  146980. typedef struct {
  146981. INT32 put_buffer; /* current bit-accumulation buffer */
  146982. int put_bits; /* # of bits now in it */
  146983. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  146984. } savable_state;
  146985. #ifndef NO_STRUCT_ASSIGN
  146986. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  146987. #else
  146988. #if MAX_COMPS_IN_SCAN == 4
  146989. #define ASSIGN_STATE(dest,src) \
  146990. ((dest).put_buffer = (src).put_buffer, \
  146991. (dest).put_bits = (src).put_bits, \
  146992. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  146993. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  146994. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  146995. (dest).last_dc_val[3] = (src).last_dc_val[3])
  146996. #endif
  146997. #endif
  146998. typedef struct {
  146999. struct jpeg_entropy_encoder pub; /* public fields */
  147000. savable_state saved; /* Bit buffer & DC state at start of MCU */
  147001. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  147002. int next_restart_num; /* next restart number to write (0-7) */
  147003. c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  147004. c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  147005. #ifdef ENTROPY_OPT_SUPPORTED /* Statistics tables for optimization */
  147006. long * dc_count_ptrs[NUM_HUFF_TBLS];
  147007. long * ac_count_ptrs[NUM_HUFF_TBLS];
  147008. #endif
  147009. } huff_entropy_encoder;
  147010. typedef huff_entropy_encoder * huff_entropy_ptr;
  147011. typedef struct {
  147012. JOCTET * next_output_byte; /* => next byte to write in buffer */
  147013. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  147014. savable_state cur; /* Current bit buffer & DC state */
  147015. j_compress_ptr cinfo; /* dump_buffer needs access to this */
  147016. } working_state;
  147017. METHODDEF(boolean) encode_mcu_huff JPP((j_compress_ptr cinfo,
  147018. JBLOCKROW *MCU_data));
  147019. METHODDEF(void) finish_pass_huff JPP((j_compress_ptr cinfo));
  147020. #ifdef ENTROPY_OPT_SUPPORTED
  147021. METHODDEF(boolean) encode_mcu_gather JPP((j_compress_ptr cinfo,
  147022. JBLOCKROW *MCU_data));
  147023. METHODDEF(void) finish_pass_gather JPP((j_compress_ptr cinfo));
  147024. #endif
  147025. METHODDEF(void)
  147026. start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
  147027. {
  147028. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147029. int ci, dctbl, actbl;
  147030. jpeg_component_info * compptr;
  147031. if (gather_statistics) {
  147032. #ifdef ENTROPY_OPT_SUPPORTED
  147033. entropy->pub.encode_mcu = encode_mcu_gather;
  147034. entropy->pub.finish_pass = finish_pass_gather;
  147035. #else
  147036. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147037. #endif
  147038. } else {
  147039. entropy->pub.encode_mcu = encode_mcu_huff;
  147040. entropy->pub.finish_pass = finish_pass_huff;
  147041. }
  147042. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147043. compptr = cinfo->cur_comp_info[ci];
  147044. dctbl = compptr->dc_tbl_no;
  147045. actbl = compptr->ac_tbl_no;
  147046. if (gather_statistics) {
  147047. #ifdef ENTROPY_OPT_SUPPORTED
  147048. if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS)
  147049. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
  147050. if (actbl < 0 || actbl >= NUM_HUFF_TBLS)
  147051. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
  147052. if (entropy->dc_count_ptrs[dctbl] == NULL)
  147053. entropy->dc_count_ptrs[dctbl] = (long *)
  147054. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147055. 257 * SIZEOF(long));
  147056. MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * SIZEOF(long));
  147057. if (entropy->ac_count_ptrs[actbl] == NULL)
  147058. entropy->ac_count_ptrs[actbl] = (long *)
  147059. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147060. 257 * SIZEOF(long));
  147061. MEMZERO(entropy->ac_count_ptrs[actbl], 257 * SIZEOF(long));
  147062. #endif
  147063. } else {
  147064. jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl,
  147065. & entropy->dc_derived_tbls[dctbl]);
  147066. jpeg_make_c_derived_tbl(cinfo, FALSE, actbl,
  147067. & entropy->ac_derived_tbls[actbl]);
  147068. }
  147069. entropy->saved.last_dc_val[ci] = 0;
  147070. }
  147071. entropy->saved.put_buffer = 0;
  147072. entropy->saved.put_bits = 0;
  147073. entropy->restarts_to_go = cinfo->restart_interval;
  147074. entropy->next_restart_num = 0;
  147075. }
  147076. GLOBAL(void)
  147077. jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
  147078. c_derived_tbl ** pdtbl)
  147079. {
  147080. JHUFF_TBL *htbl;
  147081. c_derived_tbl *dtbl;
  147082. int p, i, l, lastp, si, maxsymbol;
  147083. char huffsize[257];
  147084. unsigned int huffcode[257];
  147085. unsigned int code;
  147086. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  147087. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147088. htbl =
  147089. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  147090. if (htbl == NULL)
  147091. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147092. if (*pdtbl == NULL)
  147093. *pdtbl = (c_derived_tbl *)
  147094. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147095. SIZEOF(c_derived_tbl));
  147096. dtbl = *pdtbl;
  147097. p = 0;
  147098. for (l = 1; l <= 16; l++) {
  147099. i = (int) htbl->bits[l];
  147100. if (i < 0 || p + i > 256) /* protect against table overrun */
  147101. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147102. while (i--)
  147103. huffsize[p++] = (char) l;
  147104. }
  147105. huffsize[p] = 0;
  147106. lastp = p;
  147107. code = 0;
  147108. si = huffsize[0];
  147109. p = 0;
  147110. while (huffsize[p]) {
  147111. while (((int) huffsize[p]) == si) {
  147112. huffcode[p++] = code;
  147113. code++;
  147114. }
  147115. if (((INT32) code) >= (((INT32) 1) << si))
  147116. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147117. code <<= 1;
  147118. si++;
  147119. }
  147120. MEMZERO(dtbl->ehufsi, SIZEOF(dtbl->ehufsi));
  147121. maxsymbol = isDC ? 15 : 255;
  147122. for (p = 0; p < lastp; p++) {
  147123. i = htbl->huffval[p];
  147124. if (i < 0 || i > maxsymbol || dtbl->ehufsi[i])
  147125. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147126. dtbl->ehufco[i] = huffcode[p];
  147127. dtbl->ehufsi[i] = huffsize[p];
  147128. }
  147129. }
  147130. #define emit_byte(state,val,action) \
  147131. { *(state)->next_output_byte++ = (JOCTET) (val); \
  147132. if (--(state)->free_in_buffer == 0) \
  147133. if (! dump_buffer(state)) \
  147134. { action; } }
  147135. LOCAL(boolean)
  147136. dump_buffer (working_state * state)
  147137. {
  147138. struct jpeg_destination_mgr * dest = state->cinfo->dest;
  147139. if (! (*dest->empty_output_buffer) (state->cinfo))
  147140. return FALSE;
  147141. state->next_output_byte = dest->next_output_byte;
  147142. state->free_in_buffer = dest->free_in_buffer;
  147143. return TRUE;
  147144. }
  147145. INLINE
  147146. LOCAL(boolean)
  147147. emit_bits (working_state * state, unsigned int code, int size)
  147148. {
  147149. register INT32 put_buffer = (INT32) code;
  147150. register int put_bits = state->cur.put_bits;
  147151. if (size == 0)
  147152. ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
  147153. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  147154. put_bits += size; /* new number of bits in buffer */
  147155. put_buffer <<= 24 - put_bits; /* align incoming bits */
  147156. put_buffer |= state->cur.put_buffer; /* and merge with old buffer contents */
  147157. while (put_bits >= 8) {
  147158. int c = (int) ((put_buffer >> 16) & 0xFF);
  147159. emit_byte(state, c, return FALSE);
  147160. if (c == 0xFF) { /* need to stuff a zero byte? */
  147161. emit_byte(state, 0, return FALSE);
  147162. }
  147163. put_buffer <<= 8;
  147164. put_bits -= 8;
  147165. }
  147166. state->cur.put_buffer = put_buffer; /* update state variables */
  147167. state->cur.put_bits = put_bits;
  147168. return TRUE;
  147169. }
  147170. LOCAL(boolean)
  147171. flush_bits (working_state * state)
  147172. {
  147173. if (! emit_bits(state, 0x7F, 7)) /* fill any partial byte with ones */
  147174. return FALSE;
  147175. state->cur.put_buffer = 0; /* and reset bit-buffer to empty */
  147176. state->cur.put_bits = 0;
  147177. return TRUE;
  147178. }
  147179. LOCAL(boolean)
  147180. encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
  147181. c_derived_tbl *dctbl, c_derived_tbl *actbl)
  147182. {
  147183. register int temp, temp2;
  147184. register int nbits;
  147185. register int k, r, i;
  147186. temp = temp2 = block[0] - last_dc_val;
  147187. if (temp < 0) {
  147188. temp = -temp; /* temp is abs value of input */
  147189. temp2--;
  147190. }
  147191. nbits = 0;
  147192. while (temp) {
  147193. nbits++;
  147194. temp >>= 1;
  147195. }
  147196. if (nbits > MAX_COEF_BITS+1)
  147197. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147198. if (! emit_bits(state, dctbl->ehufco[nbits], dctbl->ehufsi[nbits]))
  147199. return FALSE;
  147200. if (nbits) /* emit_bits rejects calls with size 0 */
  147201. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147202. return FALSE;
  147203. r = 0; /* r = run length of zeros */
  147204. for (k = 1; k < DCTSIZE2; k++) {
  147205. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147206. r++;
  147207. } else {
  147208. while (r > 15) {
  147209. if (! emit_bits(state, actbl->ehufco[0xF0], actbl->ehufsi[0xF0]))
  147210. return FALSE;
  147211. r -= 16;
  147212. }
  147213. temp2 = temp;
  147214. if (temp < 0) {
  147215. temp = -temp; /* temp is abs value of input */
  147216. temp2--;
  147217. }
  147218. nbits = 1; /* there must be at least one 1 bit */
  147219. while ((temp >>= 1))
  147220. nbits++;
  147221. if (nbits > MAX_COEF_BITS)
  147222. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147223. i = (r << 4) + nbits;
  147224. if (! emit_bits(state, actbl->ehufco[i], actbl->ehufsi[i]))
  147225. return FALSE;
  147226. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147227. return FALSE;
  147228. r = 0;
  147229. }
  147230. }
  147231. if (r > 0)
  147232. if (! emit_bits(state, actbl->ehufco[0], actbl->ehufsi[0]))
  147233. return FALSE;
  147234. return TRUE;
  147235. }
  147236. LOCAL(boolean)
  147237. emit_restart (working_state * state, int restart_num)
  147238. {
  147239. int ci;
  147240. if (! flush_bits(state))
  147241. return FALSE;
  147242. emit_byte(state, 0xFF, return FALSE);
  147243. emit_byte(state, JPEG_RST0 + restart_num, return FALSE);
  147244. for (ci = 0; ci < state->cinfo->comps_in_scan; ci++)
  147245. state->cur.last_dc_val[ci] = 0;
  147246. return TRUE;
  147247. }
  147248. METHODDEF(boolean)
  147249. encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147250. {
  147251. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147252. working_state state;
  147253. int blkn, ci;
  147254. jpeg_component_info * compptr;
  147255. state.next_output_byte = cinfo->dest->next_output_byte;
  147256. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147257. ASSIGN_STATE(state.cur, entropy->saved);
  147258. state.cinfo = cinfo;
  147259. if (cinfo->restart_interval) {
  147260. if (entropy->restarts_to_go == 0)
  147261. if (! emit_restart(&state, entropy->next_restart_num))
  147262. return FALSE;
  147263. }
  147264. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147265. ci = cinfo->MCU_membership[blkn];
  147266. compptr = cinfo->cur_comp_info[ci];
  147267. if (! encode_one_block(&state,
  147268. MCU_data[blkn][0], state.cur.last_dc_val[ci],
  147269. entropy->dc_derived_tbls[compptr->dc_tbl_no],
  147270. entropy->ac_derived_tbls[compptr->ac_tbl_no]))
  147271. return FALSE;
  147272. state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
  147273. }
  147274. cinfo->dest->next_output_byte = state.next_output_byte;
  147275. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147276. ASSIGN_STATE(entropy->saved, state.cur);
  147277. if (cinfo->restart_interval) {
  147278. if (entropy->restarts_to_go == 0) {
  147279. entropy->restarts_to_go = cinfo->restart_interval;
  147280. entropy->next_restart_num++;
  147281. entropy->next_restart_num &= 7;
  147282. }
  147283. entropy->restarts_to_go--;
  147284. }
  147285. return TRUE;
  147286. }
  147287. METHODDEF(void)
  147288. finish_pass_huff (j_compress_ptr cinfo)
  147289. {
  147290. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147291. working_state state;
  147292. state.next_output_byte = cinfo->dest->next_output_byte;
  147293. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147294. ASSIGN_STATE(state.cur, entropy->saved);
  147295. state.cinfo = cinfo;
  147296. if (! flush_bits(&state))
  147297. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  147298. cinfo->dest->next_output_byte = state.next_output_byte;
  147299. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147300. ASSIGN_STATE(entropy->saved, state.cur);
  147301. }
  147302. #ifdef ENTROPY_OPT_SUPPORTED
  147303. LOCAL(void)
  147304. htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
  147305. long dc_counts[], long ac_counts[])
  147306. {
  147307. register int temp;
  147308. register int nbits;
  147309. register int k, r;
  147310. temp = block[0] - last_dc_val;
  147311. if (temp < 0)
  147312. temp = -temp;
  147313. nbits = 0;
  147314. while (temp) {
  147315. nbits++;
  147316. temp >>= 1;
  147317. }
  147318. if (nbits > MAX_COEF_BITS+1)
  147319. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147320. dc_counts[nbits]++;
  147321. r = 0; /* r = run length of zeros */
  147322. for (k = 1; k < DCTSIZE2; k++) {
  147323. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147324. r++;
  147325. } else {
  147326. while (r > 15) {
  147327. ac_counts[0xF0]++;
  147328. r -= 16;
  147329. }
  147330. if (temp < 0)
  147331. temp = -temp;
  147332. nbits = 1; /* there must be at least one 1 bit */
  147333. while ((temp >>= 1))
  147334. nbits++;
  147335. if (nbits > MAX_COEF_BITS)
  147336. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147337. ac_counts[(r << 4) + nbits]++;
  147338. r = 0;
  147339. }
  147340. }
  147341. if (r > 0)
  147342. ac_counts[0]++;
  147343. }
  147344. METHODDEF(boolean)
  147345. encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147346. {
  147347. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147348. int blkn, ci;
  147349. jpeg_component_info * compptr;
  147350. if (cinfo->restart_interval) {
  147351. if (entropy->restarts_to_go == 0) {
  147352. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  147353. entropy->saved.last_dc_val[ci] = 0;
  147354. entropy->restarts_to_go = cinfo->restart_interval;
  147355. }
  147356. entropy->restarts_to_go--;
  147357. }
  147358. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147359. ci = cinfo->MCU_membership[blkn];
  147360. compptr = cinfo->cur_comp_info[ci];
  147361. htest_one_block(cinfo, MCU_data[blkn][0], entropy->saved.last_dc_val[ci],
  147362. entropy->dc_count_ptrs[compptr->dc_tbl_no],
  147363. entropy->ac_count_ptrs[compptr->ac_tbl_no]);
  147364. entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0];
  147365. }
  147366. return TRUE;
  147367. }
  147368. GLOBAL(void)
  147369. jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
  147370. {
  147371. #define MAX_CLEN 32 /* assumed maximum initial code length */
  147372. UINT8 bits[MAX_CLEN+1]; /* bits[k] = # of symbols with code length k */
  147373. int codesize[257]; /* codesize[k] = code length of symbol k */
  147374. int others[257]; /* next symbol in current branch of tree */
  147375. int c1, c2;
  147376. int p, i, j;
  147377. long v;
  147378. MEMZERO(bits, SIZEOF(bits));
  147379. MEMZERO(codesize, SIZEOF(codesize));
  147380. for (i = 0; i < 257; i++)
  147381. others[i] = -1; /* init links to empty */
  147382. freq[256] = 1; /* make sure 256 has a nonzero count */
  147383. for (;;) {
  147384. c1 = -1;
  147385. v = 1000000000L;
  147386. for (i = 0; i <= 256; i++) {
  147387. if (freq[i] && freq[i] <= v) {
  147388. v = freq[i];
  147389. c1 = i;
  147390. }
  147391. }
  147392. c2 = -1;
  147393. v = 1000000000L;
  147394. for (i = 0; i <= 256; i++) {
  147395. if (freq[i] && freq[i] <= v && i != c1) {
  147396. v = freq[i];
  147397. c2 = i;
  147398. }
  147399. }
  147400. if (c2 < 0)
  147401. break;
  147402. freq[c1] += freq[c2];
  147403. freq[c2] = 0;
  147404. codesize[c1]++;
  147405. while (others[c1] >= 0) {
  147406. c1 = others[c1];
  147407. codesize[c1]++;
  147408. }
  147409. others[c1] = c2; /* chain c2 onto c1's tree branch */
  147410. codesize[c2]++;
  147411. while (others[c2] >= 0) {
  147412. c2 = others[c2];
  147413. codesize[c2]++;
  147414. }
  147415. }
  147416. for (i = 0; i <= 256; i++) {
  147417. if (codesize[i]) {
  147418. if (codesize[i] > MAX_CLEN)
  147419. ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
  147420. bits[codesize[i]]++;
  147421. }
  147422. }
  147423. for (i = MAX_CLEN; i > 16; i--) {
  147424. while (bits[i] > 0) {
  147425. j = i - 2; /* find length of new prefix to be used */
  147426. while (bits[j] == 0)
  147427. j--;
  147428. bits[i] -= 2; /* remove two symbols */
  147429. bits[i-1]++; /* one goes in this length */
  147430. bits[j+1] += 2; /* two new symbols in this length */
  147431. bits[j]--; /* symbol of this length is now a prefix */
  147432. }
  147433. }
  147434. while (bits[i] == 0) /* find largest codelength still in use */
  147435. i--;
  147436. bits[i]--;
  147437. MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
  147438. p = 0;
  147439. for (i = 1; i <= MAX_CLEN; i++) {
  147440. for (j = 0; j <= 255; j++) {
  147441. if (codesize[j] == i) {
  147442. htbl->huffval[p] = (UINT8) j;
  147443. p++;
  147444. }
  147445. }
  147446. }
  147447. htbl->sent_table = FALSE;
  147448. }
  147449. METHODDEF(void)
  147450. finish_pass_gather (j_compress_ptr cinfo)
  147451. {
  147452. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147453. int ci, dctbl, actbl;
  147454. jpeg_component_info * compptr;
  147455. JHUFF_TBL **htblptr;
  147456. boolean did_dc[NUM_HUFF_TBLS];
  147457. boolean did_ac[NUM_HUFF_TBLS];
  147458. MEMZERO(did_dc, SIZEOF(did_dc));
  147459. MEMZERO(did_ac, SIZEOF(did_ac));
  147460. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147461. compptr = cinfo->cur_comp_info[ci];
  147462. dctbl = compptr->dc_tbl_no;
  147463. actbl = compptr->ac_tbl_no;
  147464. if (! did_dc[dctbl]) {
  147465. htblptr = & cinfo->dc_huff_tbl_ptrs[dctbl];
  147466. if (*htblptr == NULL)
  147467. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147468. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->dc_count_ptrs[dctbl]);
  147469. did_dc[dctbl] = TRUE;
  147470. }
  147471. if (! did_ac[actbl]) {
  147472. htblptr = & cinfo->ac_huff_tbl_ptrs[actbl];
  147473. if (*htblptr == NULL)
  147474. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147475. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->ac_count_ptrs[actbl]);
  147476. did_ac[actbl] = TRUE;
  147477. }
  147478. }
  147479. }
  147480. #endif /* ENTROPY_OPT_SUPPORTED */
  147481. GLOBAL(void)
  147482. jinit_huff_encoder (j_compress_ptr cinfo)
  147483. {
  147484. huff_entropy_ptr entropy;
  147485. int i;
  147486. entropy = (huff_entropy_ptr)
  147487. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147488. SIZEOF(huff_entropy_encoder));
  147489. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  147490. entropy->pub.start_pass = start_pass_huff;
  147491. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  147492. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  147493. #ifdef ENTROPY_OPT_SUPPORTED
  147494. entropy->dc_count_ptrs[i] = entropy->ac_count_ptrs[i] = NULL;
  147495. #endif
  147496. }
  147497. }
  147498. /*** End of inlined file: jchuff.c ***/
  147499. #undef emit_byte
  147500. /*** Start of inlined file: jcinit.c ***/
  147501. #define JPEG_INTERNALS
  147502. GLOBAL(void)
  147503. jinit_compress_master (j_compress_ptr cinfo)
  147504. {
  147505. jinit_c_master_control(cinfo, FALSE /* full compression */);
  147506. if (! cinfo->raw_data_in) {
  147507. jinit_color_converter(cinfo);
  147508. jinit_downsampler(cinfo);
  147509. jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
  147510. }
  147511. jinit_forward_dct(cinfo);
  147512. if (cinfo->arith_code) {
  147513. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  147514. } else {
  147515. if (cinfo->progressive_mode) {
  147516. #ifdef C_PROGRESSIVE_SUPPORTED
  147517. jinit_phuff_encoder(cinfo);
  147518. #else
  147519. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147520. #endif
  147521. } else
  147522. jinit_huff_encoder(cinfo);
  147523. }
  147524. jinit_c_coef_controller(cinfo,
  147525. (boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding));
  147526. jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
  147527. jinit_marker_writer(cinfo);
  147528. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  147529. (*cinfo->marker->write_file_header) (cinfo);
  147530. }
  147531. /*** End of inlined file: jcinit.c ***/
  147532. /*** Start of inlined file: jcmainct.c ***/
  147533. #define JPEG_INTERNALS
  147534. #undef FULL_MAIN_BUFFER_SUPPORTED
  147535. typedef struct {
  147536. struct jpeg_c_main_controller pub; /* public fields */
  147537. JDIMENSION cur_iMCU_row; /* number of current iMCU row */
  147538. JDIMENSION rowgroup_ctr; /* counts row groups received in iMCU row */
  147539. boolean suspended; /* remember if we suspended output */
  147540. J_BUF_MODE pass_mode; /* current operating mode */
  147541. JSAMPARRAY buffer[MAX_COMPONENTS];
  147542. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147543. jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
  147544. #endif
  147545. } my_main_controller;
  147546. typedef my_main_controller * my_main_ptr;
  147547. METHODDEF(void) process_data_simple_main
  147548. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  147549. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  147550. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147551. METHODDEF(void) process_data_buffer_main
  147552. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  147553. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  147554. #endif
  147555. METHODDEF(void)
  147556. start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  147557. {
  147558. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  147559. if (cinfo->raw_data_in)
  147560. return;
  147561. main_->cur_iMCU_row = 0; /* initialize counters */
  147562. main_->rowgroup_ctr = 0;
  147563. main_->suspended = FALSE;
  147564. main_->pass_mode = pass_mode; /* save mode for use by process_data */
  147565. switch (pass_mode) {
  147566. case JBUF_PASS_THRU:
  147567. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147568. if (main_->whole_image[0] != NULL)
  147569. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147570. #endif
  147571. main_->pub.process_data = process_data_simple_main;
  147572. break;
  147573. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147574. case JBUF_SAVE_SOURCE:
  147575. case JBUF_CRANK_DEST:
  147576. case JBUF_SAVE_AND_PASS:
  147577. if (main_->whole_image[0] == NULL)
  147578. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147579. main_->pub.process_data = process_data_buffer_main;
  147580. break;
  147581. #endif
  147582. default:
  147583. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147584. break;
  147585. }
  147586. }
  147587. METHODDEF(void)
  147588. process_data_simple_main (j_compress_ptr cinfo,
  147589. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  147590. JDIMENSION in_rows_avail)
  147591. {
  147592. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  147593. while (main_->cur_iMCU_row < cinfo->total_iMCU_rows) {
  147594. if (main_->rowgroup_ctr < DCTSIZE)
  147595. (*cinfo->prep->pre_process_data) (cinfo,
  147596. input_buf, in_row_ctr, in_rows_avail,
  147597. main_->buffer, &main_->rowgroup_ctr,
  147598. (JDIMENSION) DCTSIZE);
  147599. if (main_->rowgroup_ctr != DCTSIZE)
  147600. return;
  147601. if (! (*cinfo->coef->compress_data) (cinfo, main_->buffer)) {
  147602. if (! main_->suspended) {
  147603. (*in_row_ctr)--;
  147604. main_->suspended = TRUE;
  147605. }
  147606. return;
  147607. }
  147608. if (main_->suspended) {
  147609. (*in_row_ctr)++;
  147610. main_->suspended = FALSE;
  147611. }
  147612. main_->rowgroup_ctr = 0;
  147613. main_->cur_iMCU_row++;
  147614. }
  147615. }
  147616. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147617. METHODDEF(void)
  147618. process_data_buffer_main (j_compress_ptr cinfo,
  147619. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  147620. JDIMENSION in_rows_avail)
  147621. {
  147622. my_main_ptr main = (my_main_ptr) cinfo->main;
  147623. int ci;
  147624. jpeg_component_info *compptr;
  147625. boolean writing = (main->pass_mode != JBUF_CRANK_DEST);
  147626. while (main->cur_iMCU_row < cinfo->total_iMCU_rows) {
  147627. if (main->rowgroup_ctr == 0) {
  147628. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147629. ci++, compptr++) {
  147630. main->buffer[ci] = (*cinfo->mem->access_virt_sarray)
  147631. ((j_common_ptr) cinfo, main->whole_image[ci],
  147632. main->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE),
  147633. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing);
  147634. }
  147635. if (! writing) {
  147636. *in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
  147637. main->rowgroup_ctr = DCTSIZE;
  147638. }
  147639. }
  147640. if (writing) {
  147641. (*cinfo->prep->pre_process_data) (cinfo,
  147642. input_buf, in_row_ctr, in_rows_avail,
  147643. main->buffer, &main->rowgroup_ctr,
  147644. (JDIMENSION) DCTSIZE);
  147645. if (main->rowgroup_ctr < DCTSIZE)
  147646. return;
  147647. }
  147648. if (main->pass_mode != JBUF_SAVE_SOURCE) {
  147649. if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
  147650. if (! main->suspended) {
  147651. (*in_row_ctr)--;
  147652. main->suspended = TRUE;
  147653. }
  147654. return;
  147655. }
  147656. if (main->suspended) {
  147657. (*in_row_ctr)++;
  147658. main->suspended = FALSE;
  147659. }
  147660. }
  147661. main->rowgroup_ctr = 0;
  147662. main->cur_iMCU_row++;
  147663. }
  147664. }
  147665. #endif /* FULL_MAIN_BUFFER_SUPPORTED */
  147666. GLOBAL(void)
  147667. jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  147668. {
  147669. my_main_ptr main_;
  147670. int ci;
  147671. jpeg_component_info *compptr;
  147672. main_ = (my_main_ptr)
  147673. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147674. SIZEOF(my_main_controller));
  147675. cinfo->main = (struct jpeg_c_main_controller *) main_;
  147676. main_->pub.start_pass = start_pass_main;
  147677. if (cinfo->raw_data_in)
  147678. return;
  147679. if (need_full_buffer) {
  147680. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147681. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147682. ci++, compptr++) {
  147683. main->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
  147684. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  147685. compptr->width_in_blocks * DCTSIZE,
  147686. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  147687. (long) compptr->v_samp_factor) * DCTSIZE,
  147688. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  147689. }
  147690. #else
  147691. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147692. #endif
  147693. } else {
  147694. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147695. main_->whole_image[0] = NULL; /* flag for no virtual arrays */
  147696. #endif
  147697. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147698. ci++, compptr++) {
  147699. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  147700. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147701. compptr->width_in_blocks * DCTSIZE,
  147702. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  147703. }
  147704. }
  147705. }
  147706. /*** End of inlined file: jcmainct.c ***/
  147707. /*** Start of inlined file: jcmarker.c ***/
  147708. #define JPEG_INTERNALS
  147709. typedef struct {
  147710. struct jpeg_marker_writer pub; /* public fields */
  147711. unsigned int last_restart_interval; /* last DRI value emitted; 0 after SOI */
  147712. } my_marker_writer;
  147713. typedef my_marker_writer * my_marker_ptr;
  147714. LOCAL(void)
  147715. emit_byte (j_compress_ptr cinfo, int val)
  147716. {
  147717. struct jpeg_destination_mgr * dest = cinfo->dest;
  147718. *(dest->next_output_byte)++ = (JOCTET) val;
  147719. if (--dest->free_in_buffer == 0) {
  147720. if (! (*dest->empty_output_buffer) (cinfo))
  147721. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  147722. }
  147723. }
  147724. LOCAL(void)
  147725. emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
  147726. {
  147727. emit_byte(cinfo, 0xFF);
  147728. emit_byte(cinfo, (int) mark);
  147729. }
  147730. LOCAL(void)
  147731. emit_2bytes (j_compress_ptr cinfo, int value)
  147732. {
  147733. emit_byte(cinfo, (value >> 8) & 0xFF);
  147734. emit_byte(cinfo, value & 0xFF);
  147735. }
  147736. LOCAL(int)
  147737. emit_dqt (j_compress_ptr cinfo, int index)
  147738. {
  147739. JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];
  147740. int prec;
  147741. int i;
  147742. if (qtbl == NULL)
  147743. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);
  147744. prec = 0;
  147745. for (i = 0; i < DCTSIZE2; i++) {
  147746. if (qtbl->quantval[i] > 255)
  147747. prec = 1;
  147748. }
  147749. if (! qtbl->sent_table) {
  147750. emit_marker(cinfo, M_DQT);
  147751. emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
  147752. emit_byte(cinfo, index + (prec<<4));
  147753. for (i = 0; i < DCTSIZE2; i++) {
  147754. unsigned int qval = qtbl->quantval[jpeg_natural_order[i]];
  147755. if (prec)
  147756. emit_byte(cinfo, (int) (qval >> 8));
  147757. emit_byte(cinfo, (int) (qval & 0xFF));
  147758. }
  147759. qtbl->sent_table = TRUE;
  147760. }
  147761. return prec;
  147762. }
  147763. LOCAL(void)
  147764. emit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
  147765. {
  147766. JHUFF_TBL * htbl;
  147767. int length, i;
  147768. if (is_ac) {
  147769. htbl = cinfo->ac_huff_tbl_ptrs[index];
  147770. index += 0x10; /* output index has AC bit set */
  147771. } else {
  147772. htbl = cinfo->dc_huff_tbl_ptrs[index];
  147773. }
  147774. if (htbl == NULL)
  147775. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);
  147776. if (! htbl->sent_table) {
  147777. emit_marker(cinfo, M_DHT);
  147778. length = 0;
  147779. for (i = 1; i <= 16; i++)
  147780. length += htbl->bits[i];
  147781. emit_2bytes(cinfo, length + 2 + 1 + 16);
  147782. emit_byte(cinfo, index);
  147783. for (i = 1; i <= 16; i++)
  147784. emit_byte(cinfo, htbl->bits[i]);
  147785. for (i = 0; i < length; i++)
  147786. emit_byte(cinfo, htbl->huffval[i]);
  147787. htbl->sent_table = TRUE;
  147788. }
  147789. }
  147790. LOCAL(void)
  147791. emit_dac (j_compress_ptr cinfo)
  147792. {
  147793. #ifdef C_ARITH_CODING_SUPPORTED
  147794. char dc_in_use[NUM_ARITH_TBLS];
  147795. char ac_in_use[NUM_ARITH_TBLS];
  147796. int length, i;
  147797. jpeg_component_info *compptr;
  147798. for (i = 0; i < NUM_ARITH_TBLS; i++)
  147799. dc_in_use[i] = ac_in_use[i] = 0;
  147800. for (i = 0; i < cinfo->comps_in_scan; i++) {
  147801. compptr = cinfo->cur_comp_info[i];
  147802. dc_in_use[compptr->dc_tbl_no] = 1;
  147803. ac_in_use[compptr->ac_tbl_no] = 1;
  147804. }
  147805. length = 0;
  147806. for (i = 0; i < NUM_ARITH_TBLS; i++)
  147807. length += dc_in_use[i] + ac_in_use[i];
  147808. emit_marker(cinfo, M_DAC);
  147809. emit_2bytes(cinfo, length*2 + 2);
  147810. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  147811. if (dc_in_use[i]) {
  147812. emit_byte(cinfo, i);
  147813. emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
  147814. }
  147815. if (ac_in_use[i]) {
  147816. emit_byte(cinfo, i + 0x10);
  147817. emit_byte(cinfo, cinfo->arith_ac_K[i]);
  147818. }
  147819. }
  147820. #endif /* C_ARITH_CODING_SUPPORTED */
  147821. }
  147822. LOCAL(void)
  147823. emit_dri (j_compress_ptr cinfo)
  147824. {
  147825. emit_marker(cinfo, M_DRI);
  147826. emit_2bytes(cinfo, 4); /* fixed length */
  147827. emit_2bytes(cinfo, (int) cinfo->restart_interval);
  147828. }
  147829. LOCAL(void)
  147830. emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
  147831. {
  147832. int ci;
  147833. jpeg_component_info *compptr;
  147834. emit_marker(cinfo, code);
  147835. emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
  147836. if ((long) cinfo->image_height > 65535L ||
  147837. (long) cinfo->image_width > 65535L)
  147838. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
  147839. emit_byte(cinfo, cinfo->data_precision);
  147840. emit_2bytes(cinfo, (int) cinfo->image_height);
  147841. emit_2bytes(cinfo, (int) cinfo->image_width);
  147842. emit_byte(cinfo, cinfo->num_components);
  147843. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147844. ci++, compptr++) {
  147845. emit_byte(cinfo, compptr->component_id);
  147846. emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
  147847. emit_byte(cinfo, compptr->quant_tbl_no);
  147848. }
  147849. }
  147850. LOCAL(void)
  147851. emit_sos (j_compress_ptr cinfo)
  147852. {
  147853. int i, td, ta;
  147854. jpeg_component_info *compptr;
  147855. emit_marker(cinfo, M_SOS);
  147856. emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
  147857. emit_byte(cinfo, cinfo->comps_in_scan);
  147858. for (i = 0; i < cinfo->comps_in_scan; i++) {
  147859. compptr = cinfo->cur_comp_info[i];
  147860. emit_byte(cinfo, compptr->component_id);
  147861. td = compptr->dc_tbl_no;
  147862. ta = compptr->ac_tbl_no;
  147863. if (cinfo->progressive_mode) {
  147864. if (cinfo->Ss == 0) {
  147865. ta = 0; /* DC scan */
  147866. if (cinfo->Ah != 0 && !cinfo->arith_code)
  147867. td = 0; /* no DC table either */
  147868. } else {
  147869. td = 0; /* AC scan */
  147870. }
  147871. }
  147872. emit_byte(cinfo, (td << 4) + ta);
  147873. }
  147874. emit_byte(cinfo, cinfo->Ss);
  147875. emit_byte(cinfo, cinfo->Se);
  147876. emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al);
  147877. }
  147878. LOCAL(void)
  147879. emit_jfif_app0 (j_compress_ptr cinfo)
  147880. {
  147881. emit_marker(cinfo, M_APP0);
  147882. emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
  147883. emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */
  147884. emit_byte(cinfo, 0x46);
  147885. emit_byte(cinfo, 0x49);
  147886. emit_byte(cinfo, 0x46);
  147887. emit_byte(cinfo, 0);
  147888. emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */
  147889. emit_byte(cinfo, cinfo->JFIF_minor_version);
  147890. emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
  147891. emit_2bytes(cinfo, (int) cinfo->X_density);
  147892. emit_2bytes(cinfo, (int) cinfo->Y_density);
  147893. emit_byte(cinfo, 0); /* No thumbnail image */
  147894. emit_byte(cinfo, 0);
  147895. }
  147896. LOCAL(void)
  147897. emit_adobe_app14 (j_compress_ptr cinfo)
  147898. {
  147899. emit_marker(cinfo, M_APP14);
  147900. emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */
  147901. emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */
  147902. emit_byte(cinfo, 0x64);
  147903. emit_byte(cinfo, 0x6F);
  147904. emit_byte(cinfo, 0x62);
  147905. emit_byte(cinfo, 0x65);
  147906. emit_2bytes(cinfo, 100); /* Version */
  147907. emit_2bytes(cinfo, 0); /* Flags0 */
  147908. emit_2bytes(cinfo, 0); /* Flags1 */
  147909. switch (cinfo->jpeg_color_space) {
  147910. case JCS_YCbCr:
  147911. emit_byte(cinfo, 1); /* Color transform = 1 */
  147912. break;
  147913. case JCS_YCCK:
  147914. emit_byte(cinfo, 2); /* Color transform = 2 */
  147915. break;
  147916. default:
  147917. emit_byte(cinfo, 0); /* Color transform = 0 */
  147918. break;
  147919. }
  147920. }
  147921. METHODDEF(void)
  147922. write_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  147923. {
  147924. if (datalen > (unsigned int) 65533) /* safety check */
  147925. ERREXIT(cinfo, JERR_BAD_LENGTH);
  147926. emit_marker(cinfo, (JPEG_MARKER) marker);
  147927. emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */
  147928. }
  147929. METHODDEF(void)
  147930. write_marker_byte (j_compress_ptr cinfo, int val)
  147931. {
  147932. emit_byte(cinfo, val);
  147933. }
  147934. METHODDEF(void)
  147935. write_file_header (j_compress_ptr cinfo)
  147936. {
  147937. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  147938. emit_marker(cinfo, M_SOI); /* first the SOI */
  147939. marker->last_restart_interval = 0;
  147940. if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */
  147941. emit_jfif_app0(cinfo);
  147942. if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
  147943. emit_adobe_app14(cinfo);
  147944. }
  147945. METHODDEF(void)
  147946. write_frame_header (j_compress_ptr cinfo)
  147947. {
  147948. int ci, prec;
  147949. boolean is_baseline;
  147950. jpeg_component_info *compptr;
  147951. prec = 0;
  147952. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147953. ci++, compptr++) {
  147954. prec += emit_dqt(cinfo, compptr->quant_tbl_no);
  147955. }
  147956. if (cinfo->arith_code || cinfo->progressive_mode ||
  147957. cinfo->data_precision != 8) {
  147958. is_baseline = FALSE;
  147959. } else {
  147960. is_baseline = TRUE;
  147961. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147962. ci++, compptr++) {
  147963. if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
  147964. is_baseline = FALSE;
  147965. }
  147966. if (prec && is_baseline) {
  147967. is_baseline = FALSE;
  147968. TRACEMS(cinfo, 0, JTRC_16BIT_TABLES);
  147969. }
  147970. }
  147971. if (cinfo->arith_code) {
  147972. emit_sof(cinfo, M_SOF9); /* SOF code for arithmetic coding */
  147973. } else {
  147974. if (cinfo->progressive_mode)
  147975. emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */
  147976. else if (is_baseline)
  147977. emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */
  147978. else
  147979. emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */
  147980. }
  147981. }
  147982. METHODDEF(void)
  147983. write_scan_header (j_compress_ptr cinfo)
  147984. {
  147985. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  147986. int i;
  147987. jpeg_component_info *compptr;
  147988. if (cinfo->arith_code) {
  147989. emit_dac(cinfo);
  147990. } else {
  147991. for (i = 0; i < cinfo->comps_in_scan; i++) {
  147992. compptr = cinfo->cur_comp_info[i];
  147993. if (cinfo->progressive_mode) {
  147994. if (cinfo->Ss == 0) {
  147995. if (cinfo->Ah == 0) /* DC needs no table for refinement scan */
  147996. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  147997. } else {
  147998. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  147999. }
  148000. } else {
  148001. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  148002. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  148003. }
  148004. }
  148005. }
  148006. if (cinfo->restart_interval != marker->last_restart_interval) {
  148007. emit_dri(cinfo);
  148008. marker->last_restart_interval = cinfo->restart_interval;
  148009. }
  148010. emit_sos(cinfo);
  148011. }
  148012. METHODDEF(void)
  148013. write_file_trailer (j_compress_ptr cinfo)
  148014. {
  148015. emit_marker(cinfo, M_EOI);
  148016. }
  148017. METHODDEF(void)
  148018. write_tables_only (j_compress_ptr cinfo)
  148019. {
  148020. int i;
  148021. emit_marker(cinfo, M_SOI);
  148022. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  148023. if (cinfo->quant_tbl_ptrs[i] != NULL)
  148024. (void) emit_dqt(cinfo, i);
  148025. }
  148026. if (! cinfo->arith_code) {
  148027. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  148028. if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
  148029. emit_dht(cinfo, i, FALSE);
  148030. if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
  148031. emit_dht(cinfo, i, TRUE);
  148032. }
  148033. }
  148034. emit_marker(cinfo, M_EOI);
  148035. }
  148036. GLOBAL(void)
  148037. jinit_marker_writer (j_compress_ptr cinfo)
  148038. {
  148039. my_marker_ptr marker;
  148040. marker = (my_marker_ptr)
  148041. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148042. SIZEOF(my_marker_writer));
  148043. cinfo->marker = (struct jpeg_marker_writer *) marker;
  148044. marker->pub.write_file_header = write_file_header;
  148045. marker->pub.write_frame_header = write_frame_header;
  148046. marker->pub.write_scan_header = write_scan_header;
  148047. marker->pub.write_file_trailer = write_file_trailer;
  148048. marker->pub.write_tables_only = write_tables_only;
  148049. marker->pub.write_marker_header = write_marker_header;
  148050. marker->pub.write_marker_byte = write_marker_byte;
  148051. marker->last_restart_interval = 0;
  148052. }
  148053. /*** End of inlined file: jcmarker.c ***/
  148054. /*** Start of inlined file: jcmaster.c ***/
  148055. #define JPEG_INTERNALS
  148056. typedef enum {
  148057. main_pass, /* input data, also do first output step */
  148058. huff_opt_pass, /* Huffman code optimization pass */
  148059. output_pass /* data output pass */
  148060. } c_pass_type;
  148061. typedef struct {
  148062. struct jpeg_comp_master pub; /* public fields */
  148063. c_pass_type pass_type; /* the type of the current pass */
  148064. int pass_number; /* # of passes completed */
  148065. int total_passes; /* total # of passes needed */
  148066. int scan_number; /* current index in scan_info[] */
  148067. } my_comp_master;
  148068. typedef my_comp_master * my_master_ptr;
  148069. LOCAL(void)
  148070. initial_setup (j_compress_ptr cinfo)
  148071. {
  148072. int ci;
  148073. jpeg_component_info *compptr;
  148074. long samplesperrow;
  148075. JDIMENSION jd_samplesperrow;
  148076. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  148077. || cinfo->num_components <= 0 || cinfo->input_components <= 0)
  148078. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  148079. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  148080. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  148081. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  148082. samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
  148083. jd_samplesperrow = (JDIMENSION) samplesperrow;
  148084. if ((long) jd_samplesperrow != samplesperrow)
  148085. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  148086. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  148087. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  148088. if (cinfo->num_components > MAX_COMPONENTS)
  148089. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148090. MAX_COMPONENTS);
  148091. cinfo->max_h_samp_factor = 1;
  148092. cinfo->max_v_samp_factor = 1;
  148093. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148094. ci++, compptr++) {
  148095. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  148096. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  148097. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  148098. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  148099. compptr->h_samp_factor);
  148100. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  148101. compptr->v_samp_factor);
  148102. }
  148103. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148104. ci++, compptr++) {
  148105. compptr->component_index = ci;
  148106. compptr->DCT_scaled_size = DCTSIZE;
  148107. compptr->width_in_blocks = (JDIMENSION)
  148108. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148109. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  148110. compptr->height_in_blocks = (JDIMENSION)
  148111. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148112. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  148113. compptr->downsampled_width = (JDIMENSION)
  148114. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148115. (long) cinfo->max_h_samp_factor);
  148116. compptr->downsampled_height = (JDIMENSION)
  148117. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148118. (long) cinfo->max_v_samp_factor);
  148119. compptr->component_needed = TRUE;
  148120. }
  148121. cinfo->total_iMCU_rows = (JDIMENSION)
  148122. jdiv_round_up((long) cinfo->image_height,
  148123. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148124. }
  148125. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148126. LOCAL(void)
  148127. validate_script (j_compress_ptr cinfo)
  148128. {
  148129. const jpeg_scan_info * scanptr;
  148130. int scanno, ncomps, ci, coefi, thisi;
  148131. int Ss, Se, Ah, Al;
  148132. boolean component_sent[MAX_COMPONENTS];
  148133. #ifdef C_PROGRESSIVE_SUPPORTED
  148134. int * last_bitpos_ptr;
  148135. int last_bitpos[MAX_COMPONENTS][DCTSIZE2];
  148136. #endif
  148137. if (cinfo->num_scans <= 0)
  148138. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0);
  148139. scanptr = cinfo->scan_info;
  148140. if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) {
  148141. #ifdef C_PROGRESSIVE_SUPPORTED
  148142. cinfo->progressive_mode = TRUE;
  148143. last_bitpos_ptr = & last_bitpos[0][0];
  148144. for (ci = 0; ci < cinfo->num_components; ci++)
  148145. for (coefi = 0; coefi < DCTSIZE2; coefi++)
  148146. *last_bitpos_ptr++ = -1;
  148147. #else
  148148. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148149. #endif
  148150. } else {
  148151. cinfo->progressive_mode = FALSE;
  148152. for (ci = 0; ci < cinfo->num_components; ci++)
  148153. component_sent[ci] = FALSE;
  148154. }
  148155. for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) {
  148156. ncomps = scanptr->comps_in_scan;
  148157. if (ncomps <= 0 || ncomps > MAX_COMPS_IN_SCAN)
  148158. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN);
  148159. for (ci = 0; ci < ncomps; ci++) {
  148160. thisi = scanptr->component_index[ci];
  148161. if (thisi < 0 || thisi >= cinfo->num_components)
  148162. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148163. if (ci > 0 && thisi <= scanptr->component_index[ci-1])
  148164. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148165. }
  148166. Ss = scanptr->Ss;
  148167. Se = scanptr->Se;
  148168. Ah = scanptr->Ah;
  148169. Al = scanptr->Al;
  148170. if (cinfo->progressive_mode) {
  148171. #ifdef C_PROGRESSIVE_SUPPORTED
  148172. #if BITS_IN_JSAMPLE == 8
  148173. #define MAX_AH_AL 10
  148174. #else
  148175. #define MAX_AH_AL 13
  148176. #endif
  148177. if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
  148178. Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)
  148179. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148180. if (Ss == 0) {
  148181. if (Se != 0) /* DC and AC together not OK */
  148182. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148183. } else {
  148184. if (ncomps != 1) /* AC scans must be for only one component */
  148185. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148186. }
  148187. for (ci = 0; ci < ncomps; ci++) {
  148188. last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0];
  148189. if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */
  148190. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148191. for (coefi = Ss; coefi <= Se; coefi++) {
  148192. if (last_bitpos_ptr[coefi] < 0) {
  148193. if (Ah != 0)
  148194. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148195. } else {
  148196. if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)
  148197. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148198. }
  148199. last_bitpos_ptr[coefi] = Al;
  148200. }
  148201. }
  148202. #endif
  148203. } else {
  148204. if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0)
  148205. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148206. for (ci = 0; ci < ncomps; ci++) {
  148207. thisi = scanptr->component_index[ci];
  148208. if (component_sent[thisi])
  148209. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148210. component_sent[thisi] = TRUE;
  148211. }
  148212. }
  148213. }
  148214. if (cinfo->progressive_mode) {
  148215. #ifdef C_PROGRESSIVE_SUPPORTED
  148216. for (ci = 0; ci < cinfo->num_components; ci++) {
  148217. if (last_bitpos[ci][0] < 0)
  148218. ERREXIT(cinfo, JERR_MISSING_DATA);
  148219. }
  148220. #endif
  148221. } else {
  148222. for (ci = 0; ci < cinfo->num_components; ci++) {
  148223. if (! component_sent[ci])
  148224. ERREXIT(cinfo, JERR_MISSING_DATA);
  148225. }
  148226. }
  148227. }
  148228. #endif /* C_MULTISCAN_FILES_SUPPORTED */
  148229. LOCAL(void)
  148230. select_scan_parameters (j_compress_ptr cinfo)
  148231. {
  148232. int ci;
  148233. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148234. if (cinfo->scan_info != NULL) {
  148235. my_master_ptr master = (my_master_ptr) cinfo->master;
  148236. const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number;
  148237. cinfo->comps_in_scan = scanptr->comps_in_scan;
  148238. for (ci = 0; ci < scanptr->comps_in_scan; ci++) {
  148239. cinfo->cur_comp_info[ci] =
  148240. &cinfo->comp_info[scanptr->component_index[ci]];
  148241. }
  148242. cinfo->Ss = scanptr->Ss;
  148243. cinfo->Se = scanptr->Se;
  148244. cinfo->Ah = scanptr->Ah;
  148245. cinfo->Al = scanptr->Al;
  148246. }
  148247. else
  148248. #endif
  148249. {
  148250. if (cinfo->num_components > MAX_COMPS_IN_SCAN)
  148251. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148252. MAX_COMPS_IN_SCAN);
  148253. cinfo->comps_in_scan = cinfo->num_components;
  148254. for (ci = 0; ci < cinfo->num_components; ci++) {
  148255. cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
  148256. }
  148257. cinfo->Ss = 0;
  148258. cinfo->Se = DCTSIZE2-1;
  148259. cinfo->Ah = 0;
  148260. cinfo->Al = 0;
  148261. }
  148262. }
  148263. LOCAL(void)
  148264. per_scan_setup (j_compress_ptr cinfo)
  148265. {
  148266. int ci, mcublks, tmp;
  148267. jpeg_component_info *compptr;
  148268. if (cinfo->comps_in_scan == 1) {
  148269. compptr = cinfo->cur_comp_info[0];
  148270. cinfo->MCUs_per_row = compptr->width_in_blocks;
  148271. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  148272. compptr->MCU_width = 1;
  148273. compptr->MCU_height = 1;
  148274. compptr->MCU_blocks = 1;
  148275. compptr->MCU_sample_width = DCTSIZE;
  148276. compptr->last_col_width = 1;
  148277. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  148278. if (tmp == 0) tmp = compptr->v_samp_factor;
  148279. compptr->last_row_height = tmp;
  148280. cinfo->blocks_in_MCU = 1;
  148281. cinfo->MCU_membership[0] = 0;
  148282. } else {
  148283. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  148284. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  148285. MAX_COMPS_IN_SCAN);
  148286. cinfo->MCUs_per_row = (JDIMENSION)
  148287. jdiv_round_up((long) cinfo->image_width,
  148288. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  148289. cinfo->MCU_rows_in_scan = (JDIMENSION)
  148290. jdiv_round_up((long) cinfo->image_height,
  148291. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148292. cinfo->blocks_in_MCU = 0;
  148293. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  148294. compptr = cinfo->cur_comp_info[ci];
  148295. compptr->MCU_width = compptr->h_samp_factor;
  148296. compptr->MCU_height = compptr->v_samp_factor;
  148297. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  148298. compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;
  148299. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  148300. if (tmp == 0) tmp = compptr->MCU_width;
  148301. compptr->last_col_width = tmp;
  148302. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  148303. if (tmp == 0) tmp = compptr->MCU_height;
  148304. compptr->last_row_height = tmp;
  148305. mcublks = compptr->MCU_blocks;
  148306. if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)
  148307. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  148308. while (mcublks-- > 0) {
  148309. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  148310. }
  148311. }
  148312. }
  148313. if (cinfo->restart_in_rows > 0) {
  148314. long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;
  148315. cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);
  148316. }
  148317. }
  148318. METHODDEF(void)
  148319. prepare_for_pass (j_compress_ptr cinfo)
  148320. {
  148321. my_master_ptr master = (my_master_ptr) cinfo->master;
  148322. switch (master->pass_type) {
  148323. case main_pass:
  148324. select_scan_parameters(cinfo);
  148325. per_scan_setup(cinfo);
  148326. if (! cinfo->raw_data_in) {
  148327. (*cinfo->cconvert->start_pass) (cinfo);
  148328. (*cinfo->downsample->start_pass) (cinfo);
  148329. (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU);
  148330. }
  148331. (*cinfo->fdct->start_pass) (cinfo);
  148332. (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
  148333. (*cinfo->coef->start_pass) (cinfo,
  148334. (master->total_passes > 1 ?
  148335. JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  148336. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  148337. if (cinfo->optimize_coding) {
  148338. master->pub.call_pass_startup = FALSE;
  148339. } else {
  148340. master->pub.call_pass_startup = TRUE;
  148341. }
  148342. break;
  148343. #ifdef ENTROPY_OPT_SUPPORTED
  148344. case huff_opt_pass:
  148345. select_scan_parameters(cinfo);
  148346. per_scan_setup(cinfo);
  148347. if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) {
  148348. (*cinfo->entropy->start_pass) (cinfo, TRUE);
  148349. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148350. master->pub.call_pass_startup = FALSE;
  148351. break;
  148352. }
  148353. master->pass_type = output_pass;
  148354. master->pass_number++;
  148355. #endif
  148356. case output_pass:
  148357. if (! cinfo->optimize_coding) {
  148358. select_scan_parameters(cinfo);
  148359. per_scan_setup(cinfo);
  148360. }
  148361. (*cinfo->entropy->start_pass) (cinfo, FALSE);
  148362. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148363. if (master->scan_number == 0)
  148364. (*cinfo->marker->write_frame_header) (cinfo);
  148365. (*cinfo->marker->write_scan_header) (cinfo);
  148366. master->pub.call_pass_startup = FALSE;
  148367. break;
  148368. default:
  148369. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148370. }
  148371. master->pub.is_last_pass = (master->pass_number == master->total_passes-1);
  148372. if (cinfo->progress != NULL) {
  148373. cinfo->progress->completed_passes = master->pass_number;
  148374. cinfo->progress->total_passes = master->total_passes;
  148375. }
  148376. }
  148377. METHODDEF(void)
  148378. pass_startup (j_compress_ptr cinfo)
  148379. {
  148380. cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */
  148381. (*cinfo->marker->write_frame_header) (cinfo);
  148382. (*cinfo->marker->write_scan_header) (cinfo);
  148383. }
  148384. METHODDEF(void)
  148385. finish_pass_master (j_compress_ptr cinfo)
  148386. {
  148387. my_master_ptr master = (my_master_ptr) cinfo->master;
  148388. (*cinfo->entropy->finish_pass) (cinfo);
  148389. switch (master->pass_type) {
  148390. case main_pass:
  148391. master->pass_type = output_pass;
  148392. if (! cinfo->optimize_coding)
  148393. master->scan_number++;
  148394. break;
  148395. case huff_opt_pass:
  148396. master->pass_type = output_pass;
  148397. break;
  148398. case output_pass:
  148399. if (cinfo->optimize_coding)
  148400. master->pass_type = huff_opt_pass;
  148401. master->scan_number++;
  148402. break;
  148403. }
  148404. master->pass_number++;
  148405. }
  148406. GLOBAL(void)
  148407. jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
  148408. {
  148409. my_master_ptr master;
  148410. master = (my_master_ptr)
  148411. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148412. SIZEOF(my_comp_master));
  148413. cinfo->master = (struct jpeg_comp_master *) master;
  148414. master->pub.prepare_for_pass = prepare_for_pass;
  148415. master->pub.pass_startup = pass_startup;
  148416. master->pub.finish_pass = finish_pass_master;
  148417. master->pub.is_last_pass = FALSE;
  148418. initial_setup(cinfo);
  148419. if (cinfo->scan_info != NULL) {
  148420. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148421. validate_script(cinfo);
  148422. #else
  148423. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148424. #endif
  148425. } else {
  148426. cinfo->progressive_mode = FALSE;
  148427. cinfo->num_scans = 1;
  148428. }
  148429. if (cinfo->progressive_mode) /* TEMPORARY HACK ??? */
  148430. cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */
  148431. if (transcode_only) {
  148432. if (cinfo->optimize_coding)
  148433. master->pass_type = huff_opt_pass;
  148434. else
  148435. master->pass_type = output_pass;
  148436. } else {
  148437. master->pass_type = main_pass;
  148438. }
  148439. master->scan_number = 0;
  148440. master->pass_number = 0;
  148441. if (cinfo->optimize_coding)
  148442. master->total_passes = cinfo->num_scans * 2;
  148443. else
  148444. master->total_passes = cinfo->num_scans;
  148445. }
  148446. /*** End of inlined file: jcmaster.c ***/
  148447. /*** Start of inlined file: jcomapi.c ***/
  148448. #define JPEG_INTERNALS
  148449. GLOBAL(void)
  148450. jpeg_abort (j_common_ptr cinfo)
  148451. {
  148452. int pool;
  148453. if (cinfo->mem == NULL)
  148454. return;
  148455. for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
  148456. (*cinfo->mem->free_pool) (cinfo, pool);
  148457. }
  148458. if (cinfo->is_decompressor) {
  148459. cinfo->global_state = DSTATE_START;
  148460. ((j_decompress_ptr) cinfo)->marker_list = NULL;
  148461. } else {
  148462. cinfo->global_state = CSTATE_START;
  148463. }
  148464. }
  148465. GLOBAL(void)
  148466. jpeg_destroy (j_common_ptr cinfo)
  148467. {
  148468. if (cinfo->mem != NULL)
  148469. (*cinfo->mem->self_destruct) (cinfo);
  148470. cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */
  148471. cinfo->global_state = 0; /* mark it destroyed */
  148472. }
  148473. GLOBAL(JQUANT_TBL *)
  148474. jpeg_alloc_quant_table (j_common_ptr cinfo)
  148475. {
  148476. JQUANT_TBL *tbl;
  148477. tbl = (JQUANT_TBL *)
  148478. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
  148479. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148480. return tbl;
  148481. }
  148482. GLOBAL(JHUFF_TBL *)
  148483. jpeg_alloc_huff_table (j_common_ptr cinfo)
  148484. {
  148485. JHUFF_TBL *tbl;
  148486. tbl = (JHUFF_TBL *)
  148487. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
  148488. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148489. return tbl;
  148490. }
  148491. /*** End of inlined file: jcomapi.c ***/
  148492. /*** Start of inlined file: jcparam.c ***/
  148493. #define JPEG_INTERNALS
  148494. GLOBAL(void)
  148495. jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
  148496. const unsigned int *basic_table,
  148497. int scale_factor, boolean force_baseline)
  148498. {
  148499. JQUANT_TBL ** qtblptr;
  148500. int i;
  148501. long temp;
  148502. if (cinfo->global_state != CSTATE_START)
  148503. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148504. if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS)
  148505. ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl);
  148506. qtblptr = & cinfo->quant_tbl_ptrs[which_tbl];
  148507. if (*qtblptr == NULL)
  148508. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  148509. for (i = 0; i < DCTSIZE2; i++) {
  148510. temp = ((long) basic_table[i] * scale_factor + 50L) / 100L;
  148511. if (temp <= 0L) temp = 1L;
  148512. if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */
  148513. if (force_baseline && temp > 255L)
  148514. temp = 255L; /* limit to baseline range if requested */
  148515. (*qtblptr)->quantval[i] = (UINT16) temp;
  148516. }
  148517. (*qtblptr)->sent_table = FALSE;
  148518. }
  148519. GLOBAL(void)
  148520. jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
  148521. boolean force_baseline)
  148522. {
  148523. static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
  148524. 16, 11, 10, 16, 24, 40, 51, 61,
  148525. 12, 12, 14, 19, 26, 58, 60, 55,
  148526. 14, 13, 16, 24, 40, 57, 69, 56,
  148527. 14, 17, 22, 29, 51, 87, 80, 62,
  148528. 18, 22, 37, 56, 68, 109, 103, 77,
  148529. 24, 35, 55, 64, 81, 104, 113, 92,
  148530. 49, 64, 78, 87, 103, 121, 120, 101,
  148531. 72, 92, 95, 98, 112, 100, 103, 99
  148532. };
  148533. static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
  148534. 17, 18, 24, 47, 99, 99, 99, 99,
  148535. 18, 21, 26, 66, 99, 99, 99, 99,
  148536. 24, 26, 56, 99, 99, 99, 99, 99,
  148537. 47, 66, 99, 99, 99, 99, 99, 99,
  148538. 99, 99, 99, 99, 99, 99, 99, 99,
  148539. 99, 99, 99, 99, 99, 99, 99, 99,
  148540. 99, 99, 99, 99, 99, 99, 99, 99,
  148541. 99, 99, 99, 99, 99, 99, 99, 99
  148542. };
  148543. jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
  148544. scale_factor, force_baseline);
  148545. jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
  148546. scale_factor, force_baseline);
  148547. }
  148548. GLOBAL(int)
  148549. jpeg_quality_scaling (int quality)
  148550. {
  148551. if (quality <= 0) quality = 1;
  148552. if (quality > 100) quality = 100;
  148553. if (quality < 50)
  148554. quality = 5000 / quality;
  148555. else
  148556. quality = 200 - quality*2;
  148557. return quality;
  148558. }
  148559. GLOBAL(void)
  148560. jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
  148561. {
  148562. quality = jpeg_quality_scaling(quality);
  148563. jpeg_set_linear_quality(cinfo, quality, force_baseline);
  148564. }
  148565. LOCAL(void)
  148566. add_huff_table (j_compress_ptr cinfo,
  148567. JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
  148568. {
  148569. int nsymbols, len;
  148570. if (*htblptr == NULL)
  148571. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  148572. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  148573. nsymbols = 0;
  148574. for (len = 1; len <= 16; len++)
  148575. nsymbols += bits[len];
  148576. if (nsymbols < 1 || nsymbols > 256)
  148577. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  148578. MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8));
  148579. (*htblptr)->sent_table = FALSE;
  148580. }
  148581. LOCAL(void)
  148582. std_huff_tables (j_compress_ptr cinfo)
  148583. {
  148584. static const UINT8 bits_dc_luminance[17] =
  148585. { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
  148586. static const UINT8 val_dc_luminance[] =
  148587. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  148588. static const UINT8 bits_dc_chrominance[17] =
  148589. { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
  148590. static const UINT8 val_dc_chrominance[] =
  148591. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  148592. static const UINT8 bits_ac_luminance[17] =
  148593. { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
  148594. static const UINT8 val_ac_luminance[] =
  148595. { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
  148596. 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
  148597. 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
  148598. 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
  148599. 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
  148600. 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
  148601. 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
  148602. 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
  148603. 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
  148604. 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
  148605. 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
  148606. 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
  148607. 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
  148608. 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  148609. 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
  148610. 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
  148611. 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
  148612. 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
  148613. 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
  148614. 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  148615. 0xf9, 0xfa };
  148616. static const UINT8 bits_ac_chrominance[17] =
  148617. { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
  148618. static const UINT8 val_ac_chrominance[] =
  148619. { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
  148620. 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
  148621. 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
  148622. 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
  148623. 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
  148624. 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
  148625. 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
  148626. 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
  148627. 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
  148628. 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
  148629. 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
  148630. 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  148631. 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
  148632. 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
  148633. 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
  148634. 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
  148635. 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
  148636. 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
  148637. 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
  148638. 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  148639. 0xf9, 0xfa };
  148640. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[0],
  148641. bits_dc_luminance, val_dc_luminance);
  148642. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[0],
  148643. bits_ac_luminance, val_ac_luminance);
  148644. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[1],
  148645. bits_dc_chrominance, val_dc_chrominance);
  148646. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[1],
  148647. bits_ac_chrominance, val_ac_chrominance);
  148648. }
  148649. GLOBAL(void)
  148650. jpeg_set_defaults (j_compress_ptr cinfo)
  148651. {
  148652. int i;
  148653. if (cinfo->global_state != CSTATE_START)
  148654. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148655. if (cinfo->comp_info == NULL)
  148656. cinfo->comp_info = (jpeg_component_info *)
  148657. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  148658. MAX_COMPONENTS * SIZEOF(jpeg_component_info));
  148659. cinfo->data_precision = BITS_IN_JSAMPLE;
  148660. jpeg_set_quality(cinfo, 75, TRUE);
  148661. std_huff_tables(cinfo);
  148662. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  148663. cinfo->arith_dc_L[i] = 0;
  148664. cinfo->arith_dc_U[i] = 1;
  148665. cinfo->arith_ac_K[i] = 5;
  148666. }
  148667. cinfo->scan_info = NULL;
  148668. cinfo->num_scans = 0;
  148669. cinfo->raw_data_in = FALSE;
  148670. cinfo->arith_code = FALSE;
  148671. cinfo->optimize_coding = FALSE;
  148672. if (cinfo->data_precision > 8)
  148673. cinfo->optimize_coding = TRUE;
  148674. cinfo->CCIR601_sampling = FALSE;
  148675. cinfo->smoothing_factor = 0;
  148676. cinfo->dct_method = JDCT_DEFAULT;
  148677. cinfo->restart_interval = 0;
  148678. cinfo->restart_in_rows = 0;
  148679. cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */
  148680. cinfo->JFIF_minor_version = 1;
  148681. cinfo->density_unit = 0; /* Pixel size is unknown by default */
  148682. cinfo->X_density = 1; /* Pixel aspect ratio is square by default */
  148683. cinfo->Y_density = 1;
  148684. jpeg_default_colorspace(cinfo);
  148685. }
  148686. GLOBAL(void)
  148687. jpeg_default_colorspace (j_compress_ptr cinfo)
  148688. {
  148689. switch (cinfo->in_color_space) {
  148690. case JCS_GRAYSCALE:
  148691. jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
  148692. break;
  148693. case JCS_RGB:
  148694. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  148695. break;
  148696. case JCS_YCbCr:
  148697. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  148698. break;
  148699. case JCS_CMYK:
  148700. jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */
  148701. break;
  148702. case JCS_YCCK:
  148703. jpeg_set_colorspace(cinfo, JCS_YCCK);
  148704. break;
  148705. case JCS_UNKNOWN:
  148706. jpeg_set_colorspace(cinfo, JCS_UNKNOWN);
  148707. break;
  148708. default:
  148709. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  148710. }
  148711. }
  148712. GLOBAL(void)
  148713. jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
  148714. {
  148715. jpeg_component_info * compptr;
  148716. int ci;
  148717. #define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl) \
  148718. (compptr = &cinfo->comp_info[index], \
  148719. compptr->component_id = (id), \
  148720. compptr->h_samp_factor = (hsamp), \
  148721. compptr->v_samp_factor = (vsamp), \
  148722. compptr->quant_tbl_no = (quant), \
  148723. compptr->dc_tbl_no = (dctbl), \
  148724. compptr->ac_tbl_no = (actbl) )
  148725. if (cinfo->global_state != CSTATE_START)
  148726. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148727. cinfo->jpeg_color_space = colorspace;
  148728. cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */
  148729. cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */
  148730. switch (colorspace) {
  148731. case JCS_GRAYSCALE:
  148732. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  148733. cinfo->num_components = 1;
  148734. SET_COMP(0, 1, 1,1, 0, 0,0);
  148735. break;
  148736. case JCS_RGB:
  148737. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
  148738. cinfo->num_components = 3;
  148739. SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);
  148740. SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
  148741. SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
  148742. break;
  148743. case JCS_YCbCr:
  148744. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  148745. cinfo->num_components = 3;
  148746. SET_COMP(0, 1, 2,2, 0, 0,0);
  148747. SET_COMP(1, 2, 1,1, 1, 1,1);
  148748. SET_COMP(2, 3, 1,1, 1, 1,1);
  148749. break;
  148750. case JCS_CMYK:
  148751. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */
  148752. cinfo->num_components = 4;
  148753. SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0);
  148754. SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0);
  148755. SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0);
  148756. SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0);
  148757. break;
  148758. case JCS_YCCK:
  148759. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
  148760. cinfo->num_components = 4;
  148761. SET_COMP(0, 1, 2,2, 0, 0,0);
  148762. SET_COMP(1, 2, 1,1, 1, 1,1);
  148763. SET_COMP(2, 3, 1,1, 1, 1,1);
  148764. SET_COMP(3, 4, 2,2, 0, 0,0);
  148765. break;
  148766. case JCS_UNKNOWN:
  148767. cinfo->num_components = cinfo->input_components;
  148768. if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)
  148769. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148770. MAX_COMPONENTS);
  148771. for (ci = 0; ci < cinfo->num_components; ci++) {
  148772. SET_COMP(ci, ci, 1,1, 0, 0,0);
  148773. }
  148774. break;
  148775. default:
  148776. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  148777. }
  148778. }
  148779. #ifdef C_PROGRESSIVE_SUPPORTED
  148780. LOCAL(jpeg_scan_info *)
  148781. fill_a_scan (jpeg_scan_info * scanptr, int ci,
  148782. int Ss, int Se, int Ah, int Al)
  148783. {
  148784. scanptr->comps_in_scan = 1;
  148785. scanptr->component_index[0] = ci;
  148786. scanptr->Ss = Ss;
  148787. scanptr->Se = Se;
  148788. scanptr->Ah = Ah;
  148789. scanptr->Al = Al;
  148790. scanptr++;
  148791. return scanptr;
  148792. }
  148793. LOCAL(jpeg_scan_info *)
  148794. fill_scans (jpeg_scan_info * scanptr, int ncomps,
  148795. int Ss, int Se, int Ah, int Al)
  148796. {
  148797. int ci;
  148798. for (ci = 0; ci < ncomps; ci++) {
  148799. scanptr->comps_in_scan = 1;
  148800. scanptr->component_index[0] = ci;
  148801. scanptr->Ss = Ss;
  148802. scanptr->Se = Se;
  148803. scanptr->Ah = Ah;
  148804. scanptr->Al = Al;
  148805. scanptr++;
  148806. }
  148807. return scanptr;
  148808. }
  148809. LOCAL(jpeg_scan_info *)
  148810. fill_dc_scans (jpeg_scan_info * scanptr, int ncomps, int Ah, int Al)
  148811. {
  148812. int ci;
  148813. if (ncomps <= MAX_COMPS_IN_SCAN) {
  148814. scanptr->comps_in_scan = ncomps;
  148815. for (ci = 0; ci < ncomps; ci++)
  148816. scanptr->component_index[ci] = ci;
  148817. scanptr->Ss = scanptr->Se = 0;
  148818. scanptr->Ah = Ah;
  148819. scanptr->Al = Al;
  148820. scanptr++;
  148821. } else {
  148822. scanptr = fill_scans(scanptr, ncomps, 0, 0, Ah, Al);
  148823. }
  148824. return scanptr;
  148825. }
  148826. GLOBAL(void)
  148827. jpeg_simple_progression (j_compress_ptr cinfo)
  148828. {
  148829. int ncomps = cinfo->num_components;
  148830. int nscans;
  148831. jpeg_scan_info * scanptr;
  148832. if (cinfo->global_state != CSTATE_START)
  148833. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148834. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  148835. nscans = 10;
  148836. } else {
  148837. if (ncomps > MAX_COMPS_IN_SCAN)
  148838. nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */
  148839. else
  148840. nscans = 2 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */
  148841. }
  148842. if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
  148843. cinfo->script_space_size = MAX(nscans, 10);
  148844. cinfo->script_space = (jpeg_scan_info *)
  148845. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  148846. cinfo->script_space_size * SIZEOF(jpeg_scan_info));
  148847. }
  148848. scanptr = cinfo->script_space;
  148849. cinfo->scan_info = scanptr;
  148850. cinfo->num_scans = nscans;
  148851. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  148852. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  148853. scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2);
  148854. scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1);
  148855. scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1);
  148856. scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2);
  148857. scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);
  148858. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  148859. scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0);
  148860. scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0);
  148861. scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);
  148862. } else {
  148863. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  148864. scanptr = fill_scans(scanptr, ncomps, 1, 5, 0, 2);
  148865. scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2);
  148866. scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);
  148867. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  148868. scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
  148869. }
  148870. }
  148871. #endif /* C_PROGRESSIVE_SUPPORTED */
  148872. /*** End of inlined file: jcparam.c ***/
  148873. /*** Start of inlined file: jcphuff.c ***/
  148874. #define JPEG_INTERNALS
  148875. #ifdef C_PROGRESSIVE_SUPPORTED
  148876. typedef struct {
  148877. struct jpeg_entropy_encoder pub; /* public fields */
  148878. boolean gather_statistics;
  148879. JOCTET * next_output_byte; /* => next byte to write in buffer */
  148880. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  148881. INT32 put_buffer; /* current bit-accumulation buffer */
  148882. int put_bits; /* # of bits now in it */
  148883. j_compress_ptr cinfo; /* link to cinfo (needed for dump_buffer) */
  148884. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  148885. int ac_tbl_no; /* the table number of the single component */
  148886. unsigned int EOBRUN; /* run length of EOBs */
  148887. unsigned int BE; /* # of buffered correction bits before MCU */
  148888. char * bit_buffer; /* buffer for correction bits (1 per char) */
  148889. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  148890. int next_restart_num; /* next restart number to write (0-7) */
  148891. c_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  148892. long * count_ptrs[NUM_HUFF_TBLS];
  148893. } phuff_entropy_encoder;
  148894. typedef phuff_entropy_encoder * phuff_entropy_ptr;
  148895. #define MAX_CORR_BITS 1000 /* Max # of correction bits I can buffer */
  148896. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  148897. #define ISHIFT_TEMPS int ishift_temp;
  148898. #define IRIGHT_SHIFT(x,shft) \
  148899. ((ishift_temp = (x)) < 0 ? \
  148900. (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \
  148901. (ishift_temp >> (shft)))
  148902. #else
  148903. #define ISHIFT_TEMPS
  148904. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  148905. #endif
  148906. METHODDEF(boolean) encode_mcu_DC_first JPP((j_compress_ptr cinfo,
  148907. JBLOCKROW *MCU_data));
  148908. METHODDEF(boolean) encode_mcu_AC_first JPP((j_compress_ptr cinfo,
  148909. JBLOCKROW *MCU_data));
  148910. METHODDEF(boolean) encode_mcu_DC_refine JPP((j_compress_ptr cinfo,
  148911. JBLOCKROW *MCU_data));
  148912. METHODDEF(boolean) encode_mcu_AC_refine JPP((j_compress_ptr cinfo,
  148913. JBLOCKROW *MCU_data));
  148914. METHODDEF(void) finish_pass_phuff JPP((j_compress_ptr cinfo));
  148915. METHODDEF(void) finish_pass_gather_phuff JPP((j_compress_ptr cinfo));
  148916. METHODDEF(void)
  148917. start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
  148918. {
  148919. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  148920. boolean is_DC_band;
  148921. int ci, tbl;
  148922. jpeg_component_info * compptr;
  148923. entropy->cinfo = cinfo;
  148924. entropy->gather_statistics = gather_statistics;
  148925. is_DC_band = (cinfo->Ss == 0);
  148926. if (cinfo->Ah == 0) {
  148927. if (is_DC_band)
  148928. entropy->pub.encode_mcu = encode_mcu_DC_first;
  148929. else
  148930. entropy->pub.encode_mcu = encode_mcu_AC_first;
  148931. } else {
  148932. if (is_DC_band)
  148933. entropy->pub.encode_mcu = encode_mcu_DC_refine;
  148934. else {
  148935. entropy->pub.encode_mcu = encode_mcu_AC_refine;
  148936. if (entropy->bit_buffer == NULL)
  148937. entropy->bit_buffer = (char *)
  148938. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148939. MAX_CORR_BITS * SIZEOF(char));
  148940. }
  148941. }
  148942. if (gather_statistics)
  148943. entropy->pub.finish_pass = finish_pass_gather_phuff;
  148944. else
  148945. entropy->pub.finish_pass = finish_pass_phuff;
  148946. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  148947. compptr = cinfo->cur_comp_info[ci];
  148948. entropy->last_dc_val[ci] = 0;
  148949. if (is_DC_band) {
  148950. if (cinfo->Ah != 0) /* DC refinement needs no table */
  148951. continue;
  148952. tbl = compptr->dc_tbl_no;
  148953. } else {
  148954. entropy->ac_tbl_no = tbl = compptr->ac_tbl_no;
  148955. }
  148956. if (gather_statistics) {
  148957. if (tbl < 0 || tbl >= NUM_HUFF_TBLS)
  148958. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
  148959. if (entropy->count_ptrs[tbl] == NULL)
  148960. entropy->count_ptrs[tbl] = (long *)
  148961. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148962. 257 * SIZEOF(long));
  148963. MEMZERO(entropy->count_ptrs[tbl], 257 * SIZEOF(long));
  148964. } else {
  148965. jpeg_make_c_derived_tbl(cinfo, is_DC_band, tbl,
  148966. & entropy->derived_tbls[tbl]);
  148967. }
  148968. }
  148969. entropy->EOBRUN = 0;
  148970. entropy->BE = 0;
  148971. entropy->put_buffer = 0;
  148972. entropy->put_bits = 0;
  148973. entropy->restarts_to_go = cinfo->restart_interval;
  148974. entropy->next_restart_num = 0;
  148975. }
  148976. #define emit_byte(entropy,val) \
  148977. { *(entropy)->next_output_byte++ = (JOCTET) (val); \
  148978. if (--(entropy)->free_in_buffer == 0) \
  148979. dump_buffer_p(entropy); }
  148980. LOCAL(void)
  148981. dump_buffer_p (phuff_entropy_ptr entropy)
  148982. {
  148983. struct jpeg_destination_mgr * dest = entropy->cinfo->dest;
  148984. if (! (*dest->empty_output_buffer) (entropy->cinfo))
  148985. ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND);
  148986. entropy->next_output_byte = dest->next_output_byte;
  148987. entropy->free_in_buffer = dest->free_in_buffer;
  148988. }
  148989. INLINE
  148990. LOCAL(void)
  148991. emit_bits_p (phuff_entropy_ptr entropy, unsigned int code, int size)
  148992. {
  148993. register INT32 put_buffer = (INT32) code;
  148994. register int put_bits = entropy->put_bits;
  148995. if (size == 0)
  148996. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  148997. if (entropy->gather_statistics)
  148998. return; /* do nothing if we're only getting stats */
  148999. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  149000. put_bits += size; /* new number of bits in buffer */
  149001. put_buffer <<= 24 - put_bits; /* align incoming bits */
  149002. put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */
  149003. while (put_bits >= 8) {
  149004. int c = (int) ((put_buffer >> 16) & 0xFF);
  149005. emit_byte(entropy, c);
  149006. if (c == 0xFF) { /* need to stuff a zero byte? */
  149007. emit_byte(entropy, 0);
  149008. }
  149009. put_buffer <<= 8;
  149010. put_bits -= 8;
  149011. }
  149012. entropy->put_buffer = put_buffer; /* update variables */
  149013. entropy->put_bits = put_bits;
  149014. }
  149015. LOCAL(void)
  149016. flush_bits_p (phuff_entropy_ptr entropy)
  149017. {
  149018. emit_bits_p(entropy, 0x7F, 7); /* fill any partial byte with ones */
  149019. entropy->put_buffer = 0; /* and reset bit-buffer to empty */
  149020. entropy->put_bits = 0;
  149021. }
  149022. INLINE
  149023. LOCAL(void)
  149024. emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol)
  149025. {
  149026. if (entropy->gather_statistics)
  149027. entropy->count_ptrs[tbl_no][symbol]++;
  149028. else {
  149029. c_derived_tbl * tbl = entropy->derived_tbls[tbl_no];
  149030. emit_bits_p(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]);
  149031. }
  149032. }
  149033. LOCAL(void)
  149034. emit_buffered_bits (phuff_entropy_ptr entropy, char * bufstart,
  149035. unsigned int nbits)
  149036. {
  149037. if (entropy->gather_statistics)
  149038. return; /* no real work */
  149039. while (nbits > 0) {
  149040. emit_bits_p(entropy, (unsigned int) (*bufstart), 1);
  149041. bufstart++;
  149042. nbits--;
  149043. }
  149044. }
  149045. LOCAL(void)
  149046. emit_eobrun (phuff_entropy_ptr entropy)
  149047. {
  149048. register int temp, nbits;
  149049. if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */
  149050. temp = entropy->EOBRUN;
  149051. nbits = 0;
  149052. while ((temp >>= 1))
  149053. nbits++;
  149054. if (nbits > 14)
  149055. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  149056. emit_symbol(entropy, entropy->ac_tbl_no, nbits << 4);
  149057. if (nbits)
  149058. emit_bits_p(entropy, entropy->EOBRUN, nbits);
  149059. entropy->EOBRUN = 0;
  149060. emit_buffered_bits(entropy, entropy->bit_buffer, entropy->BE);
  149061. entropy->BE = 0;
  149062. }
  149063. }
  149064. LOCAL(void)
  149065. emit_restart_p (phuff_entropy_ptr entropy, int restart_num)
  149066. {
  149067. int ci;
  149068. emit_eobrun(entropy);
  149069. if (! entropy->gather_statistics) {
  149070. flush_bits_p(entropy);
  149071. emit_byte(entropy, 0xFF);
  149072. emit_byte(entropy, JPEG_RST0 + restart_num);
  149073. }
  149074. if (entropy->cinfo->Ss == 0) {
  149075. for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++)
  149076. entropy->last_dc_val[ci] = 0;
  149077. } else {
  149078. entropy->EOBRUN = 0;
  149079. entropy->BE = 0;
  149080. }
  149081. }
  149082. METHODDEF(boolean)
  149083. encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149084. {
  149085. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149086. register int temp, temp2;
  149087. register int nbits;
  149088. int blkn, ci;
  149089. int Al = cinfo->Al;
  149090. JBLOCKROW block;
  149091. jpeg_component_info * compptr;
  149092. ISHIFT_TEMPS
  149093. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149094. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149095. if (cinfo->restart_interval)
  149096. if (entropy->restarts_to_go == 0)
  149097. emit_restart_p(entropy, entropy->next_restart_num);
  149098. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149099. block = MCU_data[blkn];
  149100. ci = cinfo->MCU_membership[blkn];
  149101. compptr = cinfo->cur_comp_info[ci];
  149102. temp2 = IRIGHT_SHIFT((int) ((*block)[0]), Al);
  149103. temp = temp2 - entropy->last_dc_val[ci];
  149104. entropy->last_dc_val[ci] = temp2;
  149105. temp2 = temp;
  149106. if (temp < 0) {
  149107. temp = -temp; /* temp is abs value of input */
  149108. temp2--;
  149109. }
  149110. nbits = 0;
  149111. while (temp) {
  149112. nbits++;
  149113. temp >>= 1;
  149114. }
  149115. if (nbits > MAX_COEF_BITS+1)
  149116. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149117. emit_symbol(entropy, compptr->dc_tbl_no, nbits);
  149118. if (nbits) /* emit_bits rejects calls with size 0 */
  149119. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149120. }
  149121. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149122. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149123. if (cinfo->restart_interval) {
  149124. if (entropy->restarts_to_go == 0) {
  149125. entropy->restarts_to_go = cinfo->restart_interval;
  149126. entropy->next_restart_num++;
  149127. entropy->next_restart_num &= 7;
  149128. }
  149129. entropy->restarts_to_go--;
  149130. }
  149131. return TRUE;
  149132. }
  149133. METHODDEF(boolean)
  149134. encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149135. {
  149136. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149137. register int temp, temp2;
  149138. register int nbits;
  149139. register int r, k;
  149140. int Se = cinfo->Se;
  149141. int Al = cinfo->Al;
  149142. JBLOCKROW block;
  149143. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149144. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149145. if (cinfo->restart_interval)
  149146. if (entropy->restarts_to_go == 0)
  149147. emit_restart_p(entropy, entropy->next_restart_num);
  149148. block = MCU_data[0];
  149149. r = 0; /* r = run length of zeros */
  149150. for (k = cinfo->Ss; k <= Se; k++) {
  149151. if ((temp = (*block)[jpeg_natural_order[k]]) == 0) {
  149152. r++;
  149153. continue;
  149154. }
  149155. if (temp < 0) {
  149156. temp = -temp; /* temp is abs value of input */
  149157. temp >>= Al; /* apply the point transform */
  149158. temp2 = ~temp;
  149159. } else {
  149160. temp >>= Al; /* apply the point transform */
  149161. temp2 = temp;
  149162. }
  149163. if (temp == 0) {
  149164. r++;
  149165. continue;
  149166. }
  149167. if (entropy->EOBRUN > 0)
  149168. emit_eobrun(entropy);
  149169. while (r > 15) {
  149170. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149171. r -= 16;
  149172. }
  149173. nbits = 1; /* there must be at least one 1 bit */
  149174. while ((temp >>= 1))
  149175. nbits++;
  149176. if (nbits > MAX_COEF_BITS)
  149177. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149178. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + nbits);
  149179. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149180. r = 0; /* reset zero run length */
  149181. }
  149182. if (r > 0) { /* If there are trailing zeroes, */
  149183. entropy->EOBRUN++; /* count an EOB */
  149184. if (entropy->EOBRUN == 0x7FFF)
  149185. emit_eobrun(entropy); /* force it out to avoid overflow */
  149186. }
  149187. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149188. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149189. if (cinfo->restart_interval) {
  149190. if (entropy->restarts_to_go == 0) {
  149191. entropy->restarts_to_go = cinfo->restart_interval;
  149192. entropy->next_restart_num++;
  149193. entropy->next_restart_num &= 7;
  149194. }
  149195. entropy->restarts_to_go--;
  149196. }
  149197. return TRUE;
  149198. }
  149199. METHODDEF(boolean)
  149200. encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149201. {
  149202. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149203. register int temp;
  149204. int blkn;
  149205. int Al = cinfo->Al;
  149206. JBLOCKROW block;
  149207. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149208. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149209. if (cinfo->restart_interval)
  149210. if (entropy->restarts_to_go == 0)
  149211. emit_restart_p(entropy, entropy->next_restart_num);
  149212. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149213. block = MCU_data[blkn];
  149214. temp = (*block)[0];
  149215. emit_bits_p(entropy, (unsigned int) (temp >> Al), 1);
  149216. }
  149217. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149218. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149219. if (cinfo->restart_interval) {
  149220. if (entropy->restarts_to_go == 0) {
  149221. entropy->restarts_to_go = cinfo->restart_interval;
  149222. entropy->next_restart_num++;
  149223. entropy->next_restart_num &= 7;
  149224. }
  149225. entropy->restarts_to_go--;
  149226. }
  149227. return TRUE;
  149228. }
  149229. METHODDEF(boolean)
  149230. encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149231. {
  149232. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149233. register int temp;
  149234. register int r, k;
  149235. int EOB;
  149236. char *BR_buffer;
  149237. unsigned int BR;
  149238. int Se = cinfo->Se;
  149239. int Al = cinfo->Al;
  149240. JBLOCKROW block;
  149241. int absvalues[DCTSIZE2];
  149242. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149243. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149244. if (cinfo->restart_interval)
  149245. if (entropy->restarts_to_go == 0)
  149246. emit_restart_p(entropy, entropy->next_restart_num);
  149247. block = MCU_data[0];
  149248. EOB = 0;
  149249. for (k = cinfo->Ss; k <= Se; k++) {
  149250. temp = (*block)[jpeg_natural_order[k]];
  149251. if (temp < 0)
  149252. temp = -temp; /* temp is abs value of input */
  149253. temp >>= Al; /* apply the point transform */
  149254. absvalues[k] = temp; /* save abs value for main pass */
  149255. if (temp == 1)
  149256. EOB = k; /* EOB = index of last newly-nonzero coef */
  149257. }
  149258. r = 0; /* r = run length of zeros */
  149259. BR = 0; /* BR = count of buffered bits added now */
  149260. BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */
  149261. for (k = cinfo->Ss; k <= Se; k++) {
  149262. if ((temp = absvalues[k]) == 0) {
  149263. r++;
  149264. continue;
  149265. }
  149266. while (r > 15 && k <= EOB) {
  149267. emit_eobrun(entropy);
  149268. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149269. r -= 16;
  149270. emit_buffered_bits(entropy, BR_buffer, BR);
  149271. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149272. BR = 0;
  149273. }
  149274. if (temp > 1) {
  149275. BR_buffer[BR++] = (char) (temp & 1);
  149276. continue;
  149277. }
  149278. emit_eobrun(entropy);
  149279. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1);
  149280. temp = ((*block)[jpeg_natural_order[k]] < 0) ? 0 : 1;
  149281. emit_bits_p(entropy, (unsigned int) temp, 1);
  149282. emit_buffered_bits(entropy, BR_buffer, BR);
  149283. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149284. BR = 0;
  149285. r = 0; /* reset zero run length */
  149286. }
  149287. if (r > 0 || BR > 0) { /* If there are trailing zeroes, */
  149288. entropy->EOBRUN++; /* count an EOB */
  149289. entropy->BE += BR; /* concat my correction bits to older ones */
  149290. if (entropy->EOBRUN == 0x7FFF || entropy->BE > (MAX_CORR_BITS-DCTSIZE2+1))
  149291. emit_eobrun(entropy);
  149292. }
  149293. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149294. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149295. if (cinfo->restart_interval) {
  149296. if (entropy->restarts_to_go == 0) {
  149297. entropy->restarts_to_go = cinfo->restart_interval;
  149298. entropy->next_restart_num++;
  149299. entropy->next_restart_num &= 7;
  149300. }
  149301. entropy->restarts_to_go--;
  149302. }
  149303. return TRUE;
  149304. }
  149305. METHODDEF(void)
  149306. finish_pass_phuff (j_compress_ptr cinfo)
  149307. {
  149308. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149309. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149310. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149311. emit_eobrun(entropy);
  149312. flush_bits_p(entropy);
  149313. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149314. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149315. }
  149316. METHODDEF(void)
  149317. finish_pass_gather_phuff (j_compress_ptr cinfo)
  149318. {
  149319. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149320. boolean is_DC_band;
  149321. int ci, tbl;
  149322. jpeg_component_info * compptr;
  149323. JHUFF_TBL **htblptr;
  149324. boolean did[NUM_HUFF_TBLS];
  149325. emit_eobrun(entropy);
  149326. is_DC_band = (cinfo->Ss == 0);
  149327. MEMZERO(did, SIZEOF(did));
  149328. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149329. compptr = cinfo->cur_comp_info[ci];
  149330. if (is_DC_band) {
  149331. if (cinfo->Ah != 0) /* DC refinement needs no table */
  149332. continue;
  149333. tbl = compptr->dc_tbl_no;
  149334. } else {
  149335. tbl = compptr->ac_tbl_no;
  149336. }
  149337. if (! did[tbl]) {
  149338. if (is_DC_band)
  149339. htblptr = & cinfo->dc_huff_tbl_ptrs[tbl];
  149340. else
  149341. htblptr = & cinfo->ac_huff_tbl_ptrs[tbl];
  149342. if (*htblptr == NULL)
  149343. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  149344. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[tbl]);
  149345. did[tbl] = TRUE;
  149346. }
  149347. }
  149348. }
  149349. GLOBAL(void)
  149350. jinit_phuff_encoder (j_compress_ptr cinfo)
  149351. {
  149352. phuff_entropy_ptr entropy;
  149353. int i;
  149354. entropy = (phuff_entropy_ptr)
  149355. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149356. SIZEOF(phuff_entropy_encoder));
  149357. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  149358. entropy->pub.start_pass = start_pass_phuff;
  149359. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  149360. entropy->derived_tbls[i] = NULL;
  149361. entropy->count_ptrs[i] = NULL;
  149362. }
  149363. entropy->bit_buffer = NULL; /* needed only in AC refinement scan */
  149364. }
  149365. #endif /* C_PROGRESSIVE_SUPPORTED */
  149366. /*** End of inlined file: jcphuff.c ***/
  149367. /*** Start of inlined file: jcprepct.c ***/
  149368. #define JPEG_INTERNALS
  149369. #ifdef INPUT_SMOOTHING_SUPPORTED
  149370. #define CONTEXT_ROWS_SUPPORTED
  149371. #endif
  149372. typedef struct {
  149373. struct jpeg_c_prep_controller pub; /* public fields */
  149374. JSAMPARRAY color_buf[MAX_COMPONENTS];
  149375. JDIMENSION rows_to_go; /* counts rows remaining in source image */
  149376. int next_buf_row; /* index of next row to store in color_buf */
  149377. #ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */
  149378. int this_row_group; /* starting row index of group to process */
  149379. int next_buf_stop; /* downsample when we reach this index */
  149380. #endif
  149381. } my_prep_controller;
  149382. typedef my_prep_controller * my_prep_ptr;
  149383. METHODDEF(void)
  149384. start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  149385. {
  149386. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149387. if (pass_mode != JBUF_PASS_THRU)
  149388. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149389. prep->rows_to_go = cinfo->image_height;
  149390. prep->next_buf_row = 0;
  149391. #ifdef CONTEXT_ROWS_SUPPORTED
  149392. prep->this_row_group = 0;
  149393. prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
  149394. #endif
  149395. }
  149396. LOCAL(void)
  149397. expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
  149398. int input_rows, int output_rows)
  149399. {
  149400. register int row;
  149401. for (row = input_rows; row < output_rows; row++) {
  149402. jcopy_sample_rows(image_data, input_rows-1, image_data, row,
  149403. 1, num_cols);
  149404. }
  149405. }
  149406. METHODDEF(void)
  149407. pre_process_data (j_compress_ptr cinfo,
  149408. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149409. JDIMENSION in_rows_avail,
  149410. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149411. JDIMENSION out_row_groups_avail)
  149412. {
  149413. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149414. int numrows, ci;
  149415. JDIMENSION inrows;
  149416. jpeg_component_info * compptr;
  149417. while (*in_row_ctr < in_rows_avail &&
  149418. *out_row_group_ctr < out_row_groups_avail) {
  149419. inrows = in_rows_avail - *in_row_ctr;
  149420. numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
  149421. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149422. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149423. prep->color_buf,
  149424. (JDIMENSION) prep->next_buf_row,
  149425. numrows);
  149426. *in_row_ctr += numrows;
  149427. prep->next_buf_row += numrows;
  149428. prep->rows_to_go -= numrows;
  149429. if (prep->rows_to_go == 0 &&
  149430. prep->next_buf_row < cinfo->max_v_samp_factor) {
  149431. for (ci = 0; ci < cinfo->num_components; ci++) {
  149432. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149433. prep->next_buf_row, cinfo->max_v_samp_factor);
  149434. }
  149435. prep->next_buf_row = cinfo->max_v_samp_factor;
  149436. }
  149437. if (prep->next_buf_row == cinfo->max_v_samp_factor) {
  149438. (*cinfo->downsample->downsample) (cinfo,
  149439. prep->color_buf, (JDIMENSION) 0,
  149440. output_buf, *out_row_group_ctr);
  149441. prep->next_buf_row = 0;
  149442. (*out_row_group_ctr)++;
  149443. }
  149444. if (prep->rows_to_go == 0 &&
  149445. *out_row_group_ctr < out_row_groups_avail) {
  149446. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149447. ci++, compptr++) {
  149448. expand_bottom_edge(output_buf[ci],
  149449. compptr->width_in_blocks * DCTSIZE,
  149450. (int) (*out_row_group_ctr * compptr->v_samp_factor),
  149451. (int) (out_row_groups_avail * compptr->v_samp_factor));
  149452. }
  149453. *out_row_group_ctr = out_row_groups_avail;
  149454. break; /* can exit outer loop without test */
  149455. }
  149456. }
  149457. }
  149458. #ifdef CONTEXT_ROWS_SUPPORTED
  149459. METHODDEF(void)
  149460. pre_process_context (j_compress_ptr cinfo,
  149461. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149462. JDIMENSION in_rows_avail,
  149463. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149464. JDIMENSION out_row_groups_avail)
  149465. {
  149466. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149467. int numrows, ci;
  149468. int buf_height = cinfo->max_v_samp_factor * 3;
  149469. JDIMENSION inrows;
  149470. while (*out_row_group_ctr < out_row_groups_avail) {
  149471. if (*in_row_ctr < in_rows_avail) {
  149472. inrows = in_rows_avail - *in_row_ctr;
  149473. numrows = prep->next_buf_stop - prep->next_buf_row;
  149474. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149475. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149476. prep->color_buf,
  149477. (JDIMENSION) prep->next_buf_row,
  149478. numrows);
  149479. if (prep->rows_to_go == cinfo->image_height) {
  149480. for (ci = 0; ci < cinfo->num_components; ci++) {
  149481. int row;
  149482. for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
  149483. jcopy_sample_rows(prep->color_buf[ci], 0,
  149484. prep->color_buf[ci], -row,
  149485. 1, cinfo->image_width);
  149486. }
  149487. }
  149488. }
  149489. *in_row_ctr += numrows;
  149490. prep->next_buf_row += numrows;
  149491. prep->rows_to_go -= numrows;
  149492. } else {
  149493. if (prep->rows_to_go != 0)
  149494. break;
  149495. if (prep->next_buf_row < prep->next_buf_stop) {
  149496. for (ci = 0; ci < cinfo->num_components; ci++) {
  149497. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149498. prep->next_buf_row, prep->next_buf_stop);
  149499. }
  149500. prep->next_buf_row = prep->next_buf_stop;
  149501. }
  149502. }
  149503. if (prep->next_buf_row == prep->next_buf_stop) {
  149504. (*cinfo->downsample->downsample) (cinfo,
  149505. prep->color_buf,
  149506. (JDIMENSION) prep->this_row_group,
  149507. output_buf, *out_row_group_ctr);
  149508. (*out_row_group_ctr)++;
  149509. prep->this_row_group += cinfo->max_v_samp_factor;
  149510. if (prep->this_row_group >= buf_height)
  149511. prep->this_row_group = 0;
  149512. if (prep->next_buf_row >= buf_height)
  149513. prep->next_buf_row = 0;
  149514. prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
  149515. }
  149516. }
  149517. }
  149518. LOCAL(void)
  149519. create_context_buffer (j_compress_ptr cinfo)
  149520. {
  149521. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149522. int rgroup_height = cinfo->max_v_samp_factor;
  149523. int ci, i;
  149524. jpeg_component_info * compptr;
  149525. JSAMPARRAY true_buffer, fake_buffer;
  149526. fake_buffer = (JSAMPARRAY)
  149527. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149528. (cinfo->num_components * 5 * rgroup_height) *
  149529. SIZEOF(JSAMPROW));
  149530. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149531. ci++, compptr++) {
  149532. true_buffer = (*cinfo->mem->alloc_sarray)
  149533. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149534. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  149535. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  149536. (JDIMENSION) (3 * rgroup_height));
  149537. MEMCOPY(fake_buffer + rgroup_height, true_buffer,
  149538. 3 * rgroup_height * SIZEOF(JSAMPROW));
  149539. for (i = 0; i < rgroup_height; i++) {
  149540. fake_buffer[i] = true_buffer[2 * rgroup_height + i];
  149541. fake_buffer[4 * rgroup_height + i] = true_buffer[i];
  149542. }
  149543. prep->color_buf[ci] = fake_buffer + rgroup_height;
  149544. fake_buffer += 5 * rgroup_height; /* point to space for next component */
  149545. }
  149546. }
  149547. #endif /* CONTEXT_ROWS_SUPPORTED */
  149548. GLOBAL(void)
  149549. jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  149550. {
  149551. my_prep_ptr prep;
  149552. int ci;
  149553. jpeg_component_info * compptr;
  149554. if (need_full_buffer) /* safety check */
  149555. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149556. prep = (my_prep_ptr)
  149557. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149558. SIZEOF(my_prep_controller));
  149559. cinfo->prep = (struct jpeg_c_prep_controller *) prep;
  149560. prep->pub.start_pass = start_pass_prep;
  149561. if (cinfo->downsample->need_context_rows) {
  149562. #ifdef CONTEXT_ROWS_SUPPORTED
  149563. prep->pub.pre_process_data = pre_process_context;
  149564. create_context_buffer(cinfo);
  149565. #else
  149566. ERREXIT(cinfo, JERR_NOT_COMPILED);
  149567. #endif
  149568. } else {
  149569. prep->pub.pre_process_data = pre_process_data;
  149570. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149571. ci++, compptr++) {
  149572. prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  149573. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149574. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  149575. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  149576. (JDIMENSION) cinfo->max_v_samp_factor);
  149577. }
  149578. }
  149579. }
  149580. /*** End of inlined file: jcprepct.c ***/
  149581. /*** Start of inlined file: jcsample.c ***/
  149582. #define JPEG_INTERNALS
  149583. typedef JMETHOD(void, downsample1_ptr,
  149584. (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149585. JSAMPARRAY input_data, JSAMPARRAY output_data));
  149586. typedef struct {
  149587. struct jpeg_downsampler pub; /* public fields */
  149588. downsample1_ptr methods[MAX_COMPONENTS];
  149589. } my_downsampler;
  149590. typedef my_downsampler * my_downsample_ptr;
  149591. METHODDEF(void)
  149592. start_pass_downsample (j_compress_ptr cinfo)
  149593. {
  149594. }
  149595. LOCAL(void)
  149596. expand_right_edge (JSAMPARRAY image_data, int num_rows,
  149597. JDIMENSION input_cols, JDIMENSION output_cols)
  149598. {
  149599. register JSAMPROW ptr;
  149600. register JSAMPLE pixval;
  149601. register int count;
  149602. int row;
  149603. int numcols = (int) (output_cols - input_cols);
  149604. if (numcols > 0) {
  149605. for (row = 0; row < num_rows; row++) {
  149606. ptr = image_data[row] + input_cols;
  149607. pixval = ptr[-1]; /* don't need GETJSAMPLE() here */
  149608. for (count = numcols; count > 0; count--)
  149609. *ptr++ = pixval;
  149610. }
  149611. }
  149612. }
  149613. METHODDEF(void)
  149614. sep_downsample (j_compress_ptr cinfo,
  149615. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  149616. JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
  149617. {
  149618. my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
  149619. int ci;
  149620. jpeg_component_info * compptr;
  149621. JSAMPARRAY in_ptr, out_ptr;
  149622. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149623. ci++, compptr++) {
  149624. in_ptr = input_buf[ci] + in_row_index;
  149625. out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
  149626. (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
  149627. }
  149628. }
  149629. METHODDEF(void)
  149630. int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149631. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149632. {
  149633. int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
  149634. JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */
  149635. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149636. JSAMPROW inptr, outptr;
  149637. INT32 outvalue;
  149638. h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
  149639. v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
  149640. numpix = h_expand * v_expand;
  149641. numpix2 = numpix/2;
  149642. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149643. cinfo->image_width, output_cols * h_expand);
  149644. inrow = 0;
  149645. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149646. outptr = output_data[outrow];
  149647. for (outcol = 0, outcol_h = 0; outcol < output_cols;
  149648. outcol++, outcol_h += h_expand) {
  149649. outvalue = 0;
  149650. for (v = 0; v < v_expand; v++) {
  149651. inptr = input_data[inrow+v] + outcol_h;
  149652. for (h = 0; h < h_expand; h++) {
  149653. outvalue += (INT32) GETJSAMPLE(*inptr++);
  149654. }
  149655. }
  149656. *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
  149657. }
  149658. inrow += v_expand;
  149659. }
  149660. }
  149661. METHODDEF(void)
  149662. fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149663. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149664. {
  149665. jcopy_sample_rows(input_data, 0, output_data, 0,
  149666. cinfo->max_v_samp_factor, cinfo->image_width);
  149667. expand_right_edge(output_data, cinfo->max_v_samp_factor,
  149668. cinfo->image_width, compptr->width_in_blocks * DCTSIZE);
  149669. }
  149670. METHODDEF(void)
  149671. h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149672. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149673. {
  149674. int outrow;
  149675. JDIMENSION outcol;
  149676. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149677. register JSAMPROW inptr, outptr;
  149678. register int bias;
  149679. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149680. cinfo->image_width, output_cols * 2);
  149681. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149682. outptr = output_data[outrow];
  149683. inptr = input_data[outrow];
  149684. bias = 0; /* bias = 0,1,0,1,... for successive samples */
  149685. for (outcol = 0; outcol < output_cols; outcol++) {
  149686. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])
  149687. + bias) >> 1);
  149688. bias ^= 1; /* 0=>1, 1=>0 */
  149689. inptr += 2;
  149690. }
  149691. }
  149692. }
  149693. METHODDEF(void)
  149694. h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149695. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149696. {
  149697. int inrow, outrow;
  149698. JDIMENSION outcol;
  149699. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149700. register JSAMPROW inptr0, inptr1, outptr;
  149701. register int bias;
  149702. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149703. cinfo->image_width, output_cols * 2);
  149704. inrow = 0;
  149705. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149706. outptr = output_data[outrow];
  149707. inptr0 = input_data[inrow];
  149708. inptr1 = input_data[inrow+1];
  149709. bias = 1; /* bias = 1,2,1,2,... for successive samples */
  149710. for (outcol = 0; outcol < output_cols; outcol++) {
  149711. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149712. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
  149713. + bias) >> 2);
  149714. bias ^= 3; /* 1=>2, 2=>1 */
  149715. inptr0 += 2; inptr1 += 2;
  149716. }
  149717. inrow += 2;
  149718. }
  149719. }
  149720. #ifdef INPUT_SMOOTHING_SUPPORTED
  149721. METHODDEF(void)
  149722. h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149723. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149724. {
  149725. int inrow, outrow;
  149726. JDIMENSION colctr;
  149727. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149728. register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
  149729. INT32 membersum, neighsum, memberscale, neighscale;
  149730. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  149731. cinfo->image_width, output_cols * 2);
  149732. memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */
  149733. neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */
  149734. inrow = 0;
  149735. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149736. outptr = output_data[outrow];
  149737. inptr0 = input_data[inrow];
  149738. inptr1 = input_data[inrow+1];
  149739. above_ptr = input_data[inrow-1];
  149740. below_ptr = input_data[inrow+2];
  149741. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149742. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149743. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149744. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149745. GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
  149746. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
  149747. neighsum += neighsum;
  149748. neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +
  149749. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
  149750. membersum = membersum * memberscale + neighsum * neighscale;
  149751. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149752. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  149753. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  149754. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149755. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149756. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149757. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149758. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
  149759. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
  149760. neighsum += neighsum;
  149761. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +
  149762. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
  149763. membersum = membersum * memberscale + neighsum * neighscale;
  149764. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149765. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  149766. }
  149767. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149768. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149769. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149770. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149771. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
  149772. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
  149773. neighsum += neighsum;
  149774. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +
  149775. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
  149776. membersum = membersum * memberscale + neighsum * neighscale;
  149777. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  149778. inrow += 2;
  149779. }
  149780. }
  149781. METHODDEF(void)
  149782. fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
  149783. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149784. {
  149785. int outrow;
  149786. JDIMENSION colctr;
  149787. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149788. register JSAMPROW inptr, above_ptr, below_ptr, outptr;
  149789. INT32 membersum, neighsum, memberscale, neighscale;
  149790. int colsum, lastcolsum, nextcolsum;
  149791. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  149792. cinfo->image_width, output_cols);
  149793. memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
  149794. neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
  149795. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149796. outptr = output_data[outrow];
  149797. inptr = input_data[outrow];
  149798. above_ptr = input_data[outrow-1];
  149799. below_ptr = input_data[outrow+1];
  149800. colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
  149801. GETJSAMPLE(*inptr);
  149802. membersum = GETJSAMPLE(*inptr++);
  149803. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  149804. GETJSAMPLE(*inptr);
  149805. neighsum = colsum + (colsum - membersum) + nextcolsum;
  149806. membersum = membersum * memberscale + neighsum * neighscale;
  149807. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149808. lastcolsum = colsum; colsum = nextcolsum;
  149809. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  149810. membersum = GETJSAMPLE(*inptr++);
  149811. above_ptr++; below_ptr++;
  149812. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  149813. GETJSAMPLE(*inptr);
  149814. neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
  149815. membersum = membersum * memberscale + neighsum * neighscale;
  149816. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149817. lastcolsum = colsum; colsum = nextcolsum;
  149818. }
  149819. membersum = GETJSAMPLE(*inptr);
  149820. neighsum = lastcolsum + (colsum - membersum) + colsum;
  149821. membersum = membersum * memberscale + neighsum * neighscale;
  149822. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  149823. }
  149824. }
  149825. #endif /* INPUT_SMOOTHING_SUPPORTED */
  149826. GLOBAL(void)
  149827. jinit_downsampler (j_compress_ptr cinfo)
  149828. {
  149829. my_downsample_ptr downsample;
  149830. int ci;
  149831. jpeg_component_info * compptr;
  149832. boolean smoothok = TRUE;
  149833. downsample = (my_downsample_ptr)
  149834. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149835. SIZEOF(my_downsampler));
  149836. cinfo->downsample = (struct jpeg_downsampler *) downsample;
  149837. downsample->pub.start_pass = start_pass_downsample;
  149838. downsample->pub.downsample = sep_downsample;
  149839. downsample->pub.need_context_rows = FALSE;
  149840. if (cinfo->CCIR601_sampling)
  149841. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  149842. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149843. ci++, compptr++) {
  149844. if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
  149845. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  149846. #ifdef INPUT_SMOOTHING_SUPPORTED
  149847. if (cinfo->smoothing_factor) {
  149848. downsample->methods[ci] = fullsize_smooth_downsample;
  149849. downsample->pub.need_context_rows = TRUE;
  149850. } else
  149851. #endif
  149852. downsample->methods[ci] = fullsize_downsample;
  149853. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  149854. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  149855. smoothok = FALSE;
  149856. downsample->methods[ci] = h2v1_downsample;
  149857. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  149858. compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
  149859. #ifdef INPUT_SMOOTHING_SUPPORTED
  149860. if (cinfo->smoothing_factor) {
  149861. downsample->methods[ci] = h2v2_smooth_downsample;
  149862. downsample->pub.need_context_rows = TRUE;
  149863. } else
  149864. #endif
  149865. downsample->methods[ci] = h2v2_downsample;
  149866. } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
  149867. (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
  149868. smoothok = FALSE;
  149869. downsample->methods[ci] = int_downsample;
  149870. } else
  149871. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  149872. }
  149873. #ifdef INPUT_SMOOTHING_SUPPORTED
  149874. if (cinfo->smoothing_factor && !smoothok)
  149875. TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
  149876. #endif
  149877. }
  149878. /*** End of inlined file: jcsample.c ***/
  149879. /*** Start of inlined file: jctrans.c ***/
  149880. #define JPEG_INTERNALS
  149881. LOCAL(void) transencode_master_selection
  149882. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  149883. LOCAL(void) transencode_coef_controller
  149884. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  149885. GLOBAL(void)
  149886. jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)
  149887. {
  149888. if (cinfo->global_state != CSTATE_START)
  149889. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149890. jpeg_suppress_tables(cinfo, FALSE);
  149891. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  149892. (*cinfo->dest->init_destination) (cinfo);
  149893. transencode_master_selection(cinfo, coef_arrays);
  149894. cinfo->next_scanline = 0; /* so jpeg_write_marker works */
  149895. cinfo->global_state = CSTATE_WRCOEFS;
  149896. }
  149897. GLOBAL(void)
  149898. jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
  149899. j_compress_ptr dstinfo)
  149900. {
  149901. JQUANT_TBL ** qtblptr;
  149902. jpeg_component_info *incomp, *outcomp;
  149903. JQUANT_TBL *c_quant, *slot_quant;
  149904. int tblno, ci, coefi;
  149905. if (dstinfo->global_state != CSTATE_START)
  149906. ERREXIT1(dstinfo, JERR_BAD_STATE, dstinfo->global_state);
  149907. dstinfo->image_width = srcinfo->image_width;
  149908. dstinfo->image_height = srcinfo->image_height;
  149909. dstinfo->input_components = srcinfo->num_components;
  149910. dstinfo->in_color_space = srcinfo->jpeg_color_space;
  149911. jpeg_set_defaults(dstinfo);
  149912. jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space);
  149913. dstinfo->data_precision = srcinfo->data_precision;
  149914. dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling;
  149915. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  149916. if (srcinfo->quant_tbl_ptrs[tblno] != NULL) {
  149917. qtblptr = & dstinfo->quant_tbl_ptrs[tblno];
  149918. if (*qtblptr == NULL)
  149919. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo);
  149920. MEMCOPY((*qtblptr)->quantval,
  149921. srcinfo->quant_tbl_ptrs[tblno]->quantval,
  149922. SIZEOF((*qtblptr)->quantval));
  149923. (*qtblptr)->sent_table = FALSE;
  149924. }
  149925. }
  149926. dstinfo->num_components = srcinfo->num_components;
  149927. if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS)
  149928. ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components,
  149929. MAX_COMPONENTS);
  149930. for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info;
  149931. ci < dstinfo->num_components; ci++, incomp++, outcomp++) {
  149932. outcomp->component_id = incomp->component_id;
  149933. outcomp->h_samp_factor = incomp->h_samp_factor;
  149934. outcomp->v_samp_factor = incomp->v_samp_factor;
  149935. outcomp->quant_tbl_no = incomp->quant_tbl_no;
  149936. tblno = outcomp->quant_tbl_no;
  149937. if (tblno < 0 || tblno >= NUM_QUANT_TBLS ||
  149938. srcinfo->quant_tbl_ptrs[tblno] == NULL)
  149939. ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno);
  149940. slot_quant = srcinfo->quant_tbl_ptrs[tblno];
  149941. c_quant = incomp->quant_table;
  149942. if (c_quant != NULL) {
  149943. for (coefi = 0; coefi < DCTSIZE2; coefi++) {
  149944. if (c_quant->quantval[coefi] != slot_quant->quantval[coefi])
  149945. ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);
  149946. }
  149947. }
  149948. }
  149949. if (srcinfo->saw_JFIF_marker) {
  149950. if (srcinfo->JFIF_major_version == 1) {
  149951. dstinfo->JFIF_major_version = srcinfo->JFIF_major_version;
  149952. dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version;
  149953. }
  149954. dstinfo->density_unit = srcinfo->density_unit;
  149955. dstinfo->X_density = srcinfo->X_density;
  149956. dstinfo->Y_density = srcinfo->Y_density;
  149957. }
  149958. }
  149959. LOCAL(void)
  149960. transencode_master_selection (j_compress_ptr cinfo,
  149961. jvirt_barray_ptr * coef_arrays)
  149962. {
  149963. cinfo->input_components = 1;
  149964. jinit_c_master_control(cinfo, TRUE /* transcode only */);
  149965. if (cinfo->arith_code) {
  149966. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  149967. } else {
  149968. if (cinfo->progressive_mode) {
  149969. #ifdef C_PROGRESSIVE_SUPPORTED
  149970. jinit_phuff_encoder(cinfo);
  149971. #else
  149972. ERREXIT(cinfo, JERR_NOT_COMPILED);
  149973. #endif
  149974. } else
  149975. jinit_huff_encoder(cinfo);
  149976. }
  149977. transencode_coef_controller(cinfo, coef_arrays);
  149978. jinit_marker_writer(cinfo);
  149979. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  149980. (*cinfo->marker->write_file_header) (cinfo);
  149981. }
  149982. typedef struct {
  149983. struct jpeg_c_coef_controller pub; /* public fields */
  149984. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  149985. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  149986. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  149987. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  149988. jvirt_barray_ptr * whole_image;
  149989. JBLOCKROW dummy_buffer[C_MAX_BLOCKS_IN_MCU];
  149990. } my_coef_controller2;
  149991. typedef my_coef_controller2 * my_coef_ptr2;
  149992. LOCAL(void)
  149993. start_iMCU_row2 (j_compress_ptr cinfo)
  149994. {
  149995. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  149996. if (cinfo->comps_in_scan > 1) {
  149997. coef->MCU_rows_per_iMCU_row = 1;
  149998. } else {
  149999. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  150000. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  150001. else
  150002. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  150003. }
  150004. coef->mcu_ctr = 0;
  150005. coef->MCU_vert_offset = 0;
  150006. }
  150007. METHODDEF(void)
  150008. start_pass_coef2 (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  150009. {
  150010. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150011. if (pass_mode != JBUF_CRANK_DEST)
  150012. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  150013. coef->iMCU_row_num = 0;
  150014. start_iMCU_row2(cinfo);
  150015. }
  150016. METHODDEF(boolean)
  150017. compress_output2 (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  150018. {
  150019. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150020. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150021. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  150022. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150023. int blkn, ci, xindex, yindex, yoffset, blockcnt;
  150024. JDIMENSION start_col;
  150025. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  150026. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  150027. JBLOCKROW buffer_ptr;
  150028. jpeg_component_info *compptr;
  150029. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150030. compptr = cinfo->cur_comp_info[ci];
  150031. buffer[ci] = (*cinfo->mem->access_virt_barray)
  150032. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  150033. coef->iMCU_row_num * compptr->v_samp_factor,
  150034. (JDIMENSION) compptr->v_samp_factor, FALSE);
  150035. }
  150036. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150037. yoffset++) {
  150038. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  150039. MCU_col_num++) {
  150040. blkn = 0; /* index of current DCT block within MCU */
  150041. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150042. compptr = cinfo->cur_comp_info[ci];
  150043. start_col = MCU_col_num * compptr->MCU_width;
  150044. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  150045. : compptr->last_col_width;
  150046. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150047. if (coef->iMCU_row_num < last_iMCU_row ||
  150048. yindex+yoffset < compptr->last_row_height) {
  150049. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  150050. for (xindex = 0; xindex < blockcnt; xindex++)
  150051. MCU_buffer[blkn++] = buffer_ptr++;
  150052. } else {
  150053. xindex = 0;
  150054. }
  150055. for (; xindex < compptr->MCU_width; xindex++) {
  150056. MCU_buffer[blkn] = coef->dummy_buffer[blkn];
  150057. MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0];
  150058. blkn++;
  150059. }
  150060. }
  150061. }
  150062. if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) {
  150063. coef->MCU_vert_offset = yoffset;
  150064. coef->mcu_ctr = MCU_col_num;
  150065. return FALSE;
  150066. }
  150067. }
  150068. coef->mcu_ctr = 0;
  150069. }
  150070. coef->iMCU_row_num++;
  150071. start_iMCU_row2(cinfo);
  150072. return TRUE;
  150073. }
  150074. LOCAL(void)
  150075. transencode_coef_controller (j_compress_ptr cinfo,
  150076. jvirt_barray_ptr * coef_arrays)
  150077. {
  150078. my_coef_ptr2 coef;
  150079. JBLOCKROW buffer;
  150080. int i;
  150081. coef = (my_coef_ptr2)
  150082. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150083. SIZEOF(my_coef_controller2));
  150084. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  150085. coef->pub.start_pass = start_pass_coef2;
  150086. coef->pub.compress_data = compress_output2;
  150087. coef->whole_image = coef_arrays;
  150088. buffer = (JBLOCKROW)
  150089. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150090. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150091. jzero_far((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150092. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  150093. coef->dummy_buffer[i] = buffer + i;
  150094. }
  150095. }
  150096. /*** End of inlined file: jctrans.c ***/
  150097. /*** Start of inlined file: jdapistd.c ***/
  150098. #define JPEG_INTERNALS
  150099. LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo));
  150100. GLOBAL(boolean)
  150101. jpeg_start_decompress (j_decompress_ptr cinfo)
  150102. {
  150103. if (cinfo->global_state == DSTATE_READY) {
  150104. jinit_master_decompress(cinfo);
  150105. if (cinfo->buffered_image) {
  150106. cinfo->global_state = DSTATE_BUFIMAGE;
  150107. return TRUE;
  150108. }
  150109. cinfo->global_state = DSTATE_PRELOAD;
  150110. }
  150111. if (cinfo->global_state == DSTATE_PRELOAD) {
  150112. if (cinfo->inputctl->has_multiple_scans) {
  150113. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150114. for (;;) {
  150115. int retcode;
  150116. if (cinfo->progress != NULL)
  150117. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150118. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150119. if (retcode == JPEG_SUSPENDED)
  150120. return FALSE;
  150121. if (retcode == JPEG_REACHED_EOI)
  150122. break;
  150123. if (cinfo->progress != NULL &&
  150124. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  150125. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  150126. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  150127. }
  150128. }
  150129. }
  150130. #else
  150131. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150132. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150133. }
  150134. cinfo->output_scan_number = cinfo->input_scan_number;
  150135. } else if (cinfo->global_state != DSTATE_PRESCAN)
  150136. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150137. return output_pass_setup(cinfo);
  150138. }
  150139. LOCAL(boolean)
  150140. output_pass_setup (j_decompress_ptr cinfo)
  150141. {
  150142. if (cinfo->global_state != DSTATE_PRESCAN) {
  150143. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150144. cinfo->output_scanline = 0;
  150145. cinfo->global_state = DSTATE_PRESCAN;
  150146. }
  150147. while (cinfo->master->is_dummy_pass) {
  150148. #ifdef QUANT_2PASS_SUPPORTED
  150149. while (cinfo->output_scanline < cinfo->output_height) {
  150150. JDIMENSION last_scanline;
  150151. if (cinfo->progress != NULL) {
  150152. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150153. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150154. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150155. }
  150156. last_scanline = cinfo->output_scanline;
  150157. (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL,
  150158. &cinfo->output_scanline, (JDIMENSION) 0);
  150159. if (cinfo->output_scanline == last_scanline)
  150160. return FALSE; /* No progress made, must suspend */
  150161. }
  150162. (*cinfo->master->finish_output_pass) (cinfo);
  150163. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150164. cinfo->output_scanline = 0;
  150165. #else
  150166. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150167. #endif /* QUANT_2PASS_SUPPORTED */
  150168. }
  150169. cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
  150170. return TRUE;
  150171. }
  150172. GLOBAL(JDIMENSION)
  150173. jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
  150174. JDIMENSION max_lines)
  150175. {
  150176. JDIMENSION row_ctr;
  150177. if (cinfo->global_state != DSTATE_SCANNING)
  150178. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150179. if (cinfo->output_scanline >= cinfo->output_height) {
  150180. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150181. return 0;
  150182. }
  150183. if (cinfo->progress != NULL) {
  150184. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150185. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150186. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150187. }
  150188. row_ctr = 0;
  150189. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);
  150190. cinfo->output_scanline += row_ctr;
  150191. return row_ctr;
  150192. }
  150193. GLOBAL(JDIMENSION)
  150194. jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
  150195. JDIMENSION max_lines)
  150196. {
  150197. JDIMENSION lines_per_iMCU_row;
  150198. if (cinfo->global_state != DSTATE_RAW_OK)
  150199. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150200. if (cinfo->output_scanline >= cinfo->output_height) {
  150201. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150202. return 0;
  150203. }
  150204. if (cinfo->progress != NULL) {
  150205. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150206. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150207. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150208. }
  150209. lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size;
  150210. if (max_lines < lines_per_iMCU_row)
  150211. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  150212. if (! (*cinfo->coef->decompress_data) (cinfo, data))
  150213. return 0; /* suspension forced, can do nothing more */
  150214. cinfo->output_scanline += lines_per_iMCU_row;
  150215. return lines_per_iMCU_row;
  150216. }
  150217. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150218. GLOBAL(boolean)
  150219. jpeg_start_output (j_decompress_ptr cinfo, int scan_number)
  150220. {
  150221. if (cinfo->global_state != DSTATE_BUFIMAGE &&
  150222. cinfo->global_state != DSTATE_PRESCAN)
  150223. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150224. if (scan_number <= 0)
  150225. scan_number = 1;
  150226. if (cinfo->inputctl->eoi_reached &&
  150227. scan_number > cinfo->input_scan_number)
  150228. scan_number = cinfo->input_scan_number;
  150229. cinfo->output_scan_number = scan_number;
  150230. return output_pass_setup(cinfo);
  150231. }
  150232. GLOBAL(boolean)
  150233. jpeg_finish_output (j_decompress_ptr cinfo)
  150234. {
  150235. if ((cinfo->global_state == DSTATE_SCANNING ||
  150236. cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
  150237. (*cinfo->master->finish_output_pass) (cinfo);
  150238. cinfo->global_state = DSTATE_BUFPOST;
  150239. } else if (cinfo->global_state != DSTATE_BUFPOST) {
  150240. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150241. }
  150242. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  150243. ! cinfo->inputctl->eoi_reached) {
  150244. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150245. return FALSE; /* Suspend, come back later */
  150246. }
  150247. cinfo->global_state = DSTATE_BUFIMAGE;
  150248. return TRUE;
  150249. }
  150250. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150251. /*** End of inlined file: jdapistd.c ***/
  150252. /*** Start of inlined file: jdapimin.c ***/
  150253. #define JPEG_INTERNALS
  150254. GLOBAL(void)
  150255. jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
  150256. {
  150257. int i;
  150258. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  150259. if (version != JPEG_LIB_VERSION)
  150260. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  150261. if (structsize != SIZEOF(struct jpeg_decompress_struct))
  150262. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  150263. (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
  150264. {
  150265. struct jpeg_error_mgr * err = cinfo->err;
  150266. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  150267. MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct));
  150268. cinfo->err = err;
  150269. cinfo->client_data = client_data;
  150270. }
  150271. cinfo->is_decompressor = TRUE;
  150272. jinit_memory_mgr((j_common_ptr) cinfo);
  150273. cinfo->progress = NULL;
  150274. cinfo->src = NULL;
  150275. for (i = 0; i < NUM_QUANT_TBLS; i++)
  150276. cinfo->quant_tbl_ptrs[i] = NULL;
  150277. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  150278. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  150279. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  150280. }
  150281. cinfo->marker_list = NULL;
  150282. jinit_marker_reader(cinfo);
  150283. jinit_input_controller(cinfo);
  150284. cinfo->global_state = DSTATE_START;
  150285. }
  150286. GLOBAL(void)
  150287. jpeg_destroy_decompress (j_decompress_ptr cinfo)
  150288. {
  150289. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  150290. }
  150291. GLOBAL(void)
  150292. jpeg_abort_decompress (j_decompress_ptr cinfo)
  150293. {
  150294. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  150295. }
  150296. LOCAL(void)
  150297. default_decompress_parms (j_decompress_ptr cinfo)
  150298. {
  150299. switch (cinfo->num_components) {
  150300. case 1:
  150301. cinfo->jpeg_color_space = JCS_GRAYSCALE;
  150302. cinfo->out_color_space = JCS_GRAYSCALE;
  150303. break;
  150304. case 3:
  150305. if (cinfo->saw_JFIF_marker) {
  150306. cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */
  150307. } else if (cinfo->saw_Adobe_marker) {
  150308. switch (cinfo->Adobe_transform) {
  150309. case 0:
  150310. cinfo->jpeg_color_space = JCS_RGB;
  150311. break;
  150312. case 1:
  150313. cinfo->jpeg_color_space = JCS_YCbCr;
  150314. break;
  150315. default:
  150316. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150317. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150318. break;
  150319. }
  150320. } else {
  150321. int cid0 = cinfo->comp_info[0].component_id;
  150322. int cid1 = cinfo->comp_info[1].component_id;
  150323. int cid2 = cinfo->comp_info[2].component_id;
  150324. if (cid0 == 1 && cid1 == 2 && cid2 == 3)
  150325. cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
  150326. else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
  150327. cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
  150328. else {
  150329. TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
  150330. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150331. }
  150332. }
  150333. cinfo->out_color_space = JCS_RGB;
  150334. break;
  150335. case 4:
  150336. if (cinfo->saw_Adobe_marker) {
  150337. switch (cinfo->Adobe_transform) {
  150338. case 0:
  150339. cinfo->jpeg_color_space = JCS_CMYK;
  150340. break;
  150341. case 2:
  150342. cinfo->jpeg_color_space = JCS_YCCK;
  150343. break;
  150344. default:
  150345. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150346. cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
  150347. break;
  150348. }
  150349. } else {
  150350. cinfo->jpeg_color_space = JCS_CMYK;
  150351. }
  150352. cinfo->out_color_space = JCS_CMYK;
  150353. break;
  150354. default:
  150355. cinfo->jpeg_color_space = JCS_UNKNOWN;
  150356. cinfo->out_color_space = JCS_UNKNOWN;
  150357. break;
  150358. }
  150359. cinfo->scale_num = 1; /* 1:1 scaling */
  150360. cinfo->scale_denom = 1;
  150361. cinfo->output_gamma = 1.0;
  150362. cinfo->buffered_image = FALSE;
  150363. cinfo->raw_data_out = FALSE;
  150364. cinfo->dct_method = JDCT_DEFAULT;
  150365. cinfo->do_fancy_upsampling = TRUE;
  150366. cinfo->do_block_smoothing = TRUE;
  150367. cinfo->quantize_colors = FALSE;
  150368. cinfo->dither_mode = JDITHER_FS;
  150369. #ifdef QUANT_2PASS_SUPPORTED
  150370. cinfo->two_pass_quantize = TRUE;
  150371. #else
  150372. cinfo->two_pass_quantize = FALSE;
  150373. #endif
  150374. cinfo->desired_number_of_colors = 256;
  150375. cinfo->colormap = NULL;
  150376. cinfo->enable_1pass_quant = FALSE;
  150377. cinfo->enable_external_quant = FALSE;
  150378. cinfo->enable_2pass_quant = FALSE;
  150379. }
  150380. GLOBAL(int)
  150381. jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
  150382. {
  150383. int retcode;
  150384. if (cinfo->global_state != DSTATE_START &&
  150385. cinfo->global_state != DSTATE_INHEADER)
  150386. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150387. retcode = jpeg_consume_input(cinfo);
  150388. switch (retcode) {
  150389. case JPEG_REACHED_SOS:
  150390. retcode = JPEG_HEADER_OK;
  150391. break;
  150392. case JPEG_REACHED_EOI:
  150393. if (require_image) /* Complain if application wanted an image */
  150394. ERREXIT(cinfo, JERR_NO_IMAGE);
  150395. jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */
  150396. retcode = JPEG_HEADER_TABLES_ONLY;
  150397. break;
  150398. case JPEG_SUSPENDED:
  150399. break;
  150400. }
  150401. return retcode;
  150402. }
  150403. GLOBAL(int)
  150404. jpeg_consume_input (j_decompress_ptr cinfo)
  150405. {
  150406. int retcode = JPEG_SUSPENDED;
  150407. switch (cinfo->global_state) {
  150408. case DSTATE_START:
  150409. (*cinfo->inputctl->reset_input_controller) (cinfo);
  150410. (*cinfo->src->init_source) (cinfo);
  150411. cinfo->global_state = DSTATE_INHEADER;
  150412. case DSTATE_INHEADER:
  150413. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150414. if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */
  150415. default_decompress_parms(cinfo);
  150416. cinfo->global_state = DSTATE_READY;
  150417. }
  150418. break;
  150419. case DSTATE_READY:
  150420. retcode = JPEG_REACHED_SOS;
  150421. break;
  150422. case DSTATE_PRELOAD:
  150423. case DSTATE_PRESCAN:
  150424. case DSTATE_SCANNING:
  150425. case DSTATE_RAW_OK:
  150426. case DSTATE_BUFIMAGE:
  150427. case DSTATE_BUFPOST:
  150428. case DSTATE_STOPPING:
  150429. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150430. break;
  150431. default:
  150432. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150433. }
  150434. return retcode;
  150435. }
  150436. GLOBAL(boolean)
  150437. jpeg_input_complete (j_decompress_ptr cinfo)
  150438. {
  150439. if (cinfo->global_state < DSTATE_START ||
  150440. cinfo->global_state > DSTATE_STOPPING)
  150441. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150442. return cinfo->inputctl->eoi_reached;
  150443. }
  150444. GLOBAL(boolean)
  150445. jpeg_has_multiple_scans (j_decompress_ptr cinfo)
  150446. {
  150447. if (cinfo->global_state < DSTATE_READY ||
  150448. cinfo->global_state > DSTATE_STOPPING)
  150449. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150450. return cinfo->inputctl->has_multiple_scans;
  150451. }
  150452. GLOBAL(boolean)
  150453. jpeg_finish_decompress (j_decompress_ptr cinfo)
  150454. {
  150455. if ((cinfo->global_state == DSTATE_SCANNING ||
  150456. cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) {
  150457. if (cinfo->output_scanline < cinfo->output_height)
  150458. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  150459. (*cinfo->master->finish_output_pass) (cinfo);
  150460. cinfo->global_state = DSTATE_STOPPING;
  150461. } else if (cinfo->global_state == DSTATE_BUFIMAGE) {
  150462. cinfo->global_state = DSTATE_STOPPING;
  150463. } else if (cinfo->global_state != DSTATE_STOPPING) {
  150464. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150465. }
  150466. while (! cinfo->inputctl->eoi_reached) {
  150467. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150468. return FALSE; /* Suspend, come back later */
  150469. }
  150470. (*cinfo->src->term_source) (cinfo);
  150471. jpeg_abort((j_common_ptr) cinfo);
  150472. return TRUE;
  150473. }
  150474. /*** End of inlined file: jdapimin.c ***/
  150475. /*** Start of inlined file: jdatasrc.c ***/
  150476. /*** Start of inlined file: jerror.h ***/
  150477. #ifndef JMESSAGE
  150478. #ifndef JERROR_H
  150479. #define JMAKE_ENUM_LIST
  150480. #else
  150481. #define JMESSAGE(code,string)
  150482. #endif /* JERROR_H */
  150483. #endif /* JMESSAGE */
  150484. #ifdef JMAKE_ENUM_LIST
  150485. typedef enum {
  150486. #define JMESSAGE(code,string) code ,
  150487. #endif /* JMAKE_ENUM_LIST */
  150488. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  150489. JMESSAGE(JERR_ARITH_NOTIMPL,
  150490. "Sorry, there are legal restrictions on arithmetic coding")
  150491. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  150492. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  150493. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  150494. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  150495. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  150496. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  150497. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  150498. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  150499. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  150500. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  150501. JMESSAGE(JERR_BAD_LIB_VERSION,
  150502. "Wrong JPEG library version: library is %d, caller expects %d")
  150503. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  150504. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  150505. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  150506. JMESSAGE(JERR_BAD_PROGRESSION,
  150507. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  150508. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  150509. "Invalid progressive parameters at scan script entry %d")
  150510. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  150511. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  150512. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  150513. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  150514. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  150515. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  150516. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  150517. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  150518. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  150519. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  150520. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  150521. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  150522. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  150523. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  150524. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  150525. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  150526. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  150527. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  150528. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  150529. JMESSAGE(JERR_FILE_READ, "Input file read error")
  150530. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  150531. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  150532. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  150533. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  150534. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  150535. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  150536. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  150537. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  150538. "Cannot transcode due to multiple use of quantization table %d")
  150539. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  150540. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  150541. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  150542. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  150543. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  150544. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  150545. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  150546. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  150547. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  150548. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  150549. JMESSAGE(JERR_QUANT_COMPONENTS,
  150550. "Cannot quantize more than %d color components")
  150551. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  150552. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  150553. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  150554. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  150555. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  150556. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  150557. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  150558. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  150559. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  150560. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  150561. JMESSAGE(JERR_TFILE_WRITE,
  150562. "Write failed on temporary file --- out of disk space?")
  150563. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  150564. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  150565. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  150566. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  150567. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  150568. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  150569. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  150570. JMESSAGE(JMSG_VERSION, JVERSION)
  150571. JMESSAGE(JTRC_16BIT_TABLES,
  150572. "Caution: quantization tables are too coarse for baseline JPEG")
  150573. JMESSAGE(JTRC_ADOBE,
  150574. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  150575. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  150576. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  150577. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  150578. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  150579. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  150580. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  150581. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  150582. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  150583. JMESSAGE(JTRC_EOI, "End Of Image")
  150584. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  150585. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  150586. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  150587. "Warning: thumbnail image size does not match data length %u")
  150588. JMESSAGE(JTRC_JFIF_EXTENSION,
  150589. "JFIF extension marker: type 0x%02x, length %u")
  150590. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  150591. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  150592. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  150593. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  150594. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  150595. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  150596. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  150597. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  150598. JMESSAGE(JTRC_RST, "RST%d")
  150599. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  150600. "Smoothing not supported with nonstandard sampling ratios")
  150601. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  150602. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  150603. JMESSAGE(JTRC_SOI, "Start of Image")
  150604. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  150605. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  150606. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  150607. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  150608. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  150609. JMESSAGE(JTRC_THUMB_JPEG,
  150610. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  150611. JMESSAGE(JTRC_THUMB_PALETTE,
  150612. "JFIF extension marker: palette thumbnail image, length %u")
  150613. JMESSAGE(JTRC_THUMB_RGB,
  150614. "JFIF extension marker: RGB thumbnail image, length %u")
  150615. JMESSAGE(JTRC_UNKNOWN_IDS,
  150616. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  150617. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  150618. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  150619. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  150620. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  150621. "Inconsistent progression sequence for component %d coefficient %d")
  150622. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  150623. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  150624. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  150625. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  150626. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  150627. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  150628. JMESSAGE(JWRN_MUST_RESYNC,
  150629. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  150630. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  150631. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  150632. #ifdef JMAKE_ENUM_LIST
  150633. JMSG_LASTMSGCODE
  150634. } J_MESSAGE_CODE;
  150635. #undef JMAKE_ENUM_LIST
  150636. #endif /* JMAKE_ENUM_LIST */
  150637. #undef JMESSAGE
  150638. #ifndef JERROR_H
  150639. #define JERROR_H
  150640. #define ERREXIT(cinfo,code) \
  150641. ((cinfo)->err->msg_code = (code), \
  150642. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150643. #define ERREXIT1(cinfo,code,p1) \
  150644. ((cinfo)->err->msg_code = (code), \
  150645. (cinfo)->err->msg_parm.i[0] = (p1), \
  150646. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150647. #define ERREXIT2(cinfo,code,p1,p2) \
  150648. ((cinfo)->err->msg_code = (code), \
  150649. (cinfo)->err->msg_parm.i[0] = (p1), \
  150650. (cinfo)->err->msg_parm.i[1] = (p2), \
  150651. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150652. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  150653. ((cinfo)->err->msg_code = (code), \
  150654. (cinfo)->err->msg_parm.i[0] = (p1), \
  150655. (cinfo)->err->msg_parm.i[1] = (p2), \
  150656. (cinfo)->err->msg_parm.i[2] = (p3), \
  150657. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150658. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  150659. ((cinfo)->err->msg_code = (code), \
  150660. (cinfo)->err->msg_parm.i[0] = (p1), \
  150661. (cinfo)->err->msg_parm.i[1] = (p2), \
  150662. (cinfo)->err->msg_parm.i[2] = (p3), \
  150663. (cinfo)->err->msg_parm.i[3] = (p4), \
  150664. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150665. #define ERREXITS(cinfo,code,str) \
  150666. ((cinfo)->err->msg_code = (code), \
  150667. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  150668. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150669. #define MAKESTMT(stuff) do { stuff } while (0)
  150670. #define WARNMS(cinfo,code) \
  150671. ((cinfo)->err->msg_code = (code), \
  150672. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150673. #define WARNMS1(cinfo,code,p1) \
  150674. ((cinfo)->err->msg_code = (code), \
  150675. (cinfo)->err->msg_parm.i[0] = (p1), \
  150676. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150677. #define WARNMS2(cinfo,code,p1,p2) \
  150678. ((cinfo)->err->msg_code = (code), \
  150679. (cinfo)->err->msg_parm.i[0] = (p1), \
  150680. (cinfo)->err->msg_parm.i[1] = (p2), \
  150681. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150682. #define TRACEMS(cinfo,lvl,code) \
  150683. ((cinfo)->err->msg_code = (code), \
  150684. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150685. #define TRACEMS1(cinfo,lvl,code,p1) \
  150686. ((cinfo)->err->msg_code = (code), \
  150687. (cinfo)->err->msg_parm.i[0] = (p1), \
  150688. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150689. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  150690. ((cinfo)->err->msg_code = (code), \
  150691. (cinfo)->err->msg_parm.i[0] = (p1), \
  150692. (cinfo)->err->msg_parm.i[1] = (p2), \
  150693. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150694. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  150695. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150696. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  150697. (cinfo)->err->msg_code = (code); \
  150698. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150699. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  150700. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150701. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150702. (cinfo)->err->msg_code = (code); \
  150703. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150704. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  150705. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150706. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150707. _mp[4] = (p5); \
  150708. (cinfo)->err->msg_code = (code); \
  150709. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150710. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  150711. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150712. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150713. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  150714. (cinfo)->err->msg_code = (code); \
  150715. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150716. #define TRACEMSS(cinfo,lvl,code,str) \
  150717. ((cinfo)->err->msg_code = (code), \
  150718. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  150719. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150720. #endif /* JERROR_H */
  150721. /*** End of inlined file: jerror.h ***/
  150722. typedef struct {
  150723. struct jpeg_source_mgr pub; /* public fields */
  150724. FILE * infile; /* source stream */
  150725. JOCTET * buffer; /* start of buffer */
  150726. boolean start_of_file; /* have we gotten any data yet? */
  150727. } my_source_mgr;
  150728. typedef my_source_mgr * my_src_ptr;
  150729. #define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */
  150730. METHODDEF(void)
  150731. init_source (j_decompress_ptr cinfo)
  150732. {
  150733. my_src_ptr src = (my_src_ptr) cinfo->src;
  150734. src->start_of_file = TRUE;
  150735. }
  150736. METHODDEF(boolean)
  150737. fill_input_buffer (j_decompress_ptr cinfo)
  150738. {
  150739. my_src_ptr src = (my_src_ptr) cinfo->src;
  150740. size_t nbytes;
  150741. nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);
  150742. if (nbytes <= 0) {
  150743. if (src->start_of_file) /* Treat empty input file as fatal error */
  150744. ERREXIT(cinfo, JERR_INPUT_EMPTY);
  150745. WARNMS(cinfo, JWRN_JPEG_EOF);
  150746. src->buffer[0] = (JOCTET) 0xFF;
  150747. src->buffer[1] = (JOCTET) JPEG_EOI;
  150748. nbytes = 2;
  150749. }
  150750. src->pub.next_input_byte = src->buffer;
  150751. src->pub.bytes_in_buffer = nbytes;
  150752. src->start_of_file = FALSE;
  150753. return TRUE;
  150754. }
  150755. METHODDEF(void)
  150756. skip_input_data (j_decompress_ptr cinfo, long num_bytes)
  150757. {
  150758. my_src_ptr src = (my_src_ptr) cinfo->src;
  150759. if (num_bytes > 0) {
  150760. while (num_bytes > (long) src->pub.bytes_in_buffer) {
  150761. num_bytes -= (long) src->pub.bytes_in_buffer;
  150762. (void) fill_input_buffer(cinfo);
  150763. }
  150764. src->pub.next_input_byte += (size_t) num_bytes;
  150765. src->pub.bytes_in_buffer -= (size_t) num_bytes;
  150766. }
  150767. }
  150768. METHODDEF(void)
  150769. term_source (j_decompress_ptr cinfo)
  150770. {
  150771. }
  150772. GLOBAL(void)
  150773. jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
  150774. {
  150775. my_src_ptr src;
  150776. if (cinfo->src == NULL) { /* first time for this JPEG object? */
  150777. cinfo->src = (struct jpeg_source_mgr *)
  150778. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  150779. SIZEOF(my_source_mgr));
  150780. src = (my_src_ptr) cinfo->src;
  150781. src->buffer = (JOCTET *)
  150782. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  150783. INPUT_BUF_SIZE * SIZEOF(JOCTET));
  150784. }
  150785. src = (my_src_ptr) cinfo->src;
  150786. src->pub.init_source = init_source;
  150787. src->pub.fill_input_buffer = fill_input_buffer;
  150788. src->pub.skip_input_data = skip_input_data;
  150789. src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
  150790. src->pub.term_source = term_source;
  150791. src->infile = infile;
  150792. src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
  150793. src->pub.next_input_byte = NULL; /* until buffer loaded */
  150794. }
  150795. /*** End of inlined file: jdatasrc.c ***/
  150796. /*** Start of inlined file: jdcoefct.c ***/
  150797. #define JPEG_INTERNALS
  150798. #ifndef D_PROGRESSIVE_SUPPORTED
  150799. #undef BLOCK_SMOOTHING_SUPPORTED
  150800. #endif
  150801. typedef struct {
  150802. struct jpeg_d_coef_controller pub; /* public fields */
  150803. JDIMENSION MCU_ctr; /* counts MCUs processed in current row */
  150804. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  150805. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  150806. JBLOCKROW MCU_buffer[D_MAX_BLOCKS_IN_MCU];
  150807. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150808. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  150809. #endif
  150810. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150811. int * coef_bits_latch;
  150812. #define SAVED_COEFS 6 /* we save coef_bits[0..5] */
  150813. #endif
  150814. } my_coef_controller3;
  150815. typedef my_coef_controller3 * my_coef_ptr3;
  150816. METHODDEF(int) decompress_onepass
  150817. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150818. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150819. METHODDEF(int) decompress_data
  150820. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150821. #endif
  150822. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150823. LOCAL(boolean) smoothing_ok JPP((j_decompress_ptr cinfo));
  150824. METHODDEF(int) decompress_smooth_data
  150825. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150826. #endif
  150827. LOCAL(void)
  150828. start_iMCU_row3 (j_decompress_ptr cinfo)
  150829. {
  150830. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150831. if (cinfo->comps_in_scan > 1) {
  150832. coef->MCU_rows_per_iMCU_row = 1;
  150833. } else {
  150834. if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
  150835. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  150836. else
  150837. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  150838. }
  150839. coef->MCU_ctr = 0;
  150840. coef->MCU_vert_offset = 0;
  150841. }
  150842. METHODDEF(void)
  150843. start_input_pass (j_decompress_ptr cinfo)
  150844. {
  150845. cinfo->input_iMCU_row = 0;
  150846. start_iMCU_row3(cinfo);
  150847. }
  150848. METHODDEF(void)
  150849. start_output_pass (j_decompress_ptr cinfo)
  150850. {
  150851. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150852. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150853. if (coef->pub.coef_arrays != NULL) {
  150854. if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
  150855. coef->pub.decompress_data = decompress_smooth_data;
  150856. else
  150857. coef->pub.decompress_data = decompress_data;
  150858. }
  150859. #endif
  150860. cinfo->output_iMCU_row = 0;
  150861. }
  150862. METHODDEF(int)
  150863. decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  150864. {
  150865. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150866. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150867. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  150868. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150869. int blkn, ci, xindex, yindex, yoffset, useful_width;
  150870. JSAMPARRAY output_ptr;
  150871. JDIMENSION start_col, output_col;
  150872. jpeg_component_info *compptr;
  150873. inverse_DCT_method_ptr inverse_DCT;
  150874. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150875. yoffset++) {
  150876. for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
  150877. MCU_col_num++) {
  150878. jzero_far((void FAR *) coef->MCU_buffer[0],
  150879. (size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK)));
  150880. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  150881. coef->MCU_vert_offset = yoffset;
  150882. coef->MCU_ctr = MCU_col_num;
  150883. return JPEG_SUSPENDED;
  150884. }
  150885. blkn = 0; /* index of current DCT block within MCU */
  150886. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150887. compptr = cinfo->cur_comp_info[ci];
  150888. if (! compptr->component_needed) {
  150889. blkn += compptr->MCU_blocks;
  150890. continue;
  150891. }
  150892. inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
  150893. useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  150894. : compptr->last_col_width;
  150895. output_ptr = output_buf[compptr->component_index] +
  150896. yoffset * compptr->DCT_scaled_size;
  150897. start_col = MCU_col_num * compptr->MCU_sample_width;
  150898. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150899. if (cinfo->input_iMCU_row < last_iMCU_row ||
  150900. yoffset+yindex < compptr->last_row_height) {
  150901. output_col = start_col;
  150902. for (xindex = 0; xindex < useful_width; xindex++) {
  150903. (*inverse_DCT) (cinfo, compptr,
  150904. (JCOEFPTR) coef->MCU_buffer[blkn+xindex],
  150905. output_ptr, output_col);
  150906. output_col += compptr->DCT_scaled_size;
  150907. }
  150908. }
  150909. blkn += compptr->MCU_width;
  150910. output_ptr += compptr->DCT_scaled_size;
  150911. }
  150912. }
  150913. }
  150914. coef->MCU_ctr = 0;
  150915. }
  150916. cinfo->output_iMCU_row++;
  150917. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  150918. start_iMCU_row3(cinfo);
  150919. return JPEG_ROW_COMPLETED;
  150920. }
  150921. (*cinfo->inputctl->finish_input_pass) (cinfo);
  150922. return JPEG_SCAN_COMPLETED;
  150923. }
  150924. METHODDEF(int)
  150925. dummy_consume_data (j_decompress_ptr cinfo)
  150926. {
  150927. return JPEG_SUSPENDED; /* Always indicate nothing was done */
  150928. }
  150929. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150930. METHODDEF(int)
  150931. consume_data (j_decompress_ptr cinfo)
  150932. {
  150933. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150934. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150935. int blkn, ci, xindex, yindex, yoffset;
  150936. JDIMENSION start_col;
  150937. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  150938. JBLOCKROW buffer_ptr;
  150939. jpeg_component_info *compptr;
  150940. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150941. compptr = cinfo->cur_comp_info[ci];
  150942. buffer[ci] = (*cinfo->mem->access_virt_barray)
  150943. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  150944. cinfo->input_iMCU_row * compptr->v_samp_factor,
  150945. (JDIMENSION) compptr->v_samp_factor, TRUE);
  150946. }
  150947. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150948. yoffset++) {
  150949. for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
  150950. MCU_col_num++) {
  150951. blkn = 0; /* index of current DCT block within MCU */
  150952. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150953. compptr = cinfo->cur_comp_info[ci];
  150954. start_col = MCU_col_num * compptr->MCU_width;
  150955. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150956. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  150957. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  150958. coef->MCU_buffer[blkn++] = buffer_ptr++;
  150959. }
  150960. }
  150961. }
  150962. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  150963. coef->MCU_vert_offset = yoffset;
  150964. coef->MCU_ctr = MCU_col_num;
  150965. return JPEG_SUSPENDED;
  150966. }
  150967. }
  150968. coef->MCU_ctr = 0;
  150969. }
  150970. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  150971. start_iMCU_row3(cinfo);
  150972. return JPEG_ROW_COMPLETED;
  150973. }
  150974. (*cinfo->inputctl->finish_input_pass) (cinfo);
  150975. return JPEG_SCAN_COMPLETED;
  150976. }
  150977. METHODDEF(int)
  150978. decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  150979. {
  150980. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150981. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150982. JDIMENSION block_num;
  150983. int ci, block_row, block_rows;
  150984. JBLOCKARRAY buffer;
  150985. JBLOCKROW buffer_ptr;
  150986. JSAMPARRAY output_ptr;
  150987. JDIMENSION output_col;
  150988. jpeg_component_info *compptr;
  150989. inverse_DCT_method_ptr inverse_DCT;
  150990. while (cinfo->input_scan_number < cinfo->output_scan_number ||
  150991. (cinfo->input_scan_number == cinfo->output_scan_number &&
  150992. cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
  150993. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  150994. return JPEG_SUSPENDED;
  150995. }
  150996. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150997. ci++, compptr++) {
  150998. if (! compptr->component_needed)
  150999. continue;
  151000. buffer = (*cinfo->mem->access_virt_barray)
  151001. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151002. cinfo->output_iMCU_row * compptr->v_samp_factor,
  151003. (JDIMENSION) compptr->v_samp_factor, FALSE);
  151004. if (cinfo->output_iMCU_row < last_iMCU_row)
  151005. block_rows = compptr->v_samp_factor;
  151006. else {
  151007. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151008. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  151009. }
  151010. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151011. output_ptr = output_buf[ci];
  151012. for (block_row = 0; block_row < block_rows; block_row++) {
  151013. buffer_ptr = buffer[block_row];
  151014. output_col = 0;
  151015. for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) {
  151016. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
  151017. output_ptr, output_col);
  151018. buffer_ptr++;
  151019. output_col += compptr->DCT_scaled_size;
  151020. }
  151021. output_ptr += compptr->DCT_scaled_size;
  151022. }
  151023. }
  151024. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151025. return JPEG_ROW_COMPLETED;
  151026. return JPEG_SCAN_COMPLETED;
  151027. }
  151028. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  151029. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151030. #define Q01_POS 1
  151031. #define Q10_POS 8
  151032. #define Q20_POS 16
  151033. #define Q11_POS 9
  151034. #define Q02_POS 2
  151035. LOCAL(boolean)
  151036. smoothing_ok (j_decompress_ptr cinfo)
  151037. {
  151038. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151039. boolean smoothing_useful = FALSE;
  151040. int ci, coefi;
  151041. jpeg_component_info *compptr;
  151042. JQUANT_TBL * qtable;
  151043. int * coef_bits;
  151044. int * coef_bits_latch;
  151045. if (! cinfo->progressive_mode || cinfo->coef_bits == NULL)
  151046. return FALSE;
  151047. if (coef->coef_bits_latch == NULL)
  151048. coef->coef_bits_latch = (int *)
  151049. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151050. cinfo->num_components *
  151051. (SAVED_COEFS * SIZEOF(int)));
  151052. coef_bits_latch = coef->coef_bits_latch;
  151053. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151054. ci++, compptr++) {
  151055. if ((qtable = compptr->quant_table) == NULL)
  151056. return FALSE;
  151057. if (qtable->quantval[0] == 0 ||
  151058. qtable->quantval[Q01_POS] == 0 ||
  151059. qtable->quantval[Q10_POS] == 0 ||
  151060. qtable->quantval[Q20_POS] == 0 ||
  151061. qtable->quantval[Q11_POS] == 0 ||
  151062. qtable->quantval[Q02_POS] == 0)
  151063. return FALSE;
  151064. coef_bits = cinfo->coef_bits[ci];
  151065. if (coef_bits[0] < 0)
  151066. return FALSE;
  151067. for (coefi = 1; coefi <= 5; coefi++) {
  151068. coef_bits_latch[coefi] = coef_bits[coefi];
  151069. if (coef_bits[coefi] != 0)
  151070. smoothing_useful = TRUE;
  151071. }
  151072. coef_bits_latch += SAVED_COEFS;
  151073. }
  151074. return smoothing_useful;
  151075. }
  151076. METHODDEF(int)
  151077. decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151078. {
  151079. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151080. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151081. JDIMENSION block_num, last_block_column;
  151082. int ci, block_row, block_rows, access_rows;
  151083. JBLOCKARRAY buffer;
  151084. JBLOCKROW buffer_ptr, prev_block_row, next_block_row;
  151085. JSAMPARRAY output_ptr;
  151086. JDIMENSION output_col;
  151087. jpeg_component_info *compptr;
  151088. inverse_DCT_method_ptr inverse_DCT;
  151089. boolean first_row, last_row;
  151090. JBLOCK workspace;
  151091. int *coef_bits;
  151092. JQUANT_TBL *quanttbl;
  151093. INT32 Q00,Q01,Q02,Q10,Q11,Q20, num;
  151094. int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9;
  151095. int Al, pred;
  151096. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  151097. ! cinfo->inputctl->eoi_reached) {
  151098. if (cinfo->input_scan_number == cinfo->output_scan_number) {
  151099. JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0;
  151100. if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta)
  151101. break;
  151102. }
  151103. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  151104. return JPEG_SUSPENDED;
  151105. }
  151106. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151107. ci++, compptr++) {
  151108. if (! compptr->component_needed)
  151109. continue;
  151110. if (cinfo->output_iMCU_row < last_iMCU_row) {
  151111. block_rows = compptr->v_samp_factor;
  151112. access_rows = block_rows * 2; /* this and next iMCU row */
  151113. last_row = FALSE;
  151114. } else {
  151115. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151116. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  151117. access_rows = block_rows; /* this iMCU row only */
  151118. last_row = TRUE;
  151119. }
  151120. if (cinfo->output_iMCU_row > 0) {
  151121. access_rows += compptr->v_samp_factor; /* prior iMCU row too */
  151122. buffer = (*cinfo->mem->access_virt_barray)
  151123. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151124. (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
  151125. (JDIMENSION) access_rows, FALSE);
  151126. buffer += compptr->v_samp_factor; /* point to current iMCU row */
  151127. first_row = FALSE;
  151128. } else {
  151129. buffer = (*cinfo->mem->access_virt_barray)
  151130. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151131. (JDIMENSION) 0, (JDIMENSION) access_rows, FALSE);
  151132. first_row = TRUE;
  151133. }
  151134. coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
  151135. quanttbl = compptr->quant_table;
  151136. Q00 = quanttbl->quantval[0];
  151137. Q01 = quanttbl->quantval[Q01_POS];
  151138. Q10 = quanttbl->quantval[Q10_POS];
  151139. Q20 = quanttbl->quantval[Q20_POS];
  151140. Q11 = quanttbl->quantval[Q11_POS];
  151141. Q02 = quanttbl->quantval[Q02_POS];
  151142. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151143. output_ptr = output_buf[ci];
  151144. for (block_row = 0; block_row < block_rows; block_row++) {
  151145. buffer_ptr = buffer[block_row];
  151146. if (first_row && block_row == 0)
  151147. prev_block_row = buffer_ptr;
  151148. else
  151149. prev_block_row = buffer[block_row-1];
  151150. if (last_row && block_row == block_rows-1)
  151151. next_block_row = buffer_ptr;
  151152. else
  151153. next_block_row = buffer[block_row+1];
  151154. DC1 = DC2 = DC3 = (int) prev_block_row[0][0];
  151155. DC4 = DC5 = DC6 = (int) buffer_ptr[0][0];
  151156. DC7 = DC8 = DC9 = (int) next_block_row[0][0];
  151157. output_col = 0;
  151158. last_block_column = compptr->width_in_blocks - 1;
  151159. for (block_num = 0; block_num <= last_block_column; block_num++) {
  151160. jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1);
  151161. if (block_num < last_block_column) {
  151162. DC3 = (int) prev_block_row[1][0];
  151163. DC6 = (int) buffer_ptr[1][0];
  151164. DC9 = (int) next_block_row[1][0];
  151165. }
  151166. if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) {
  151167. num = 36 * Q00 * (DC4 - DC6);
  151168. if (num >= 0) {
  151169. pred = (int) (((Q01<<7) + num) / (Q01<<8));
  151170. if (Al > 0 && pred >= (1<<Al))
  151171. pred = (1<<Al)-1;
  151172. } else {
  151173. pred = (int) (((Q01<<7) - num) / (Q01<<8));
  151174. if (Al > 0 && pred >= (1<<Al))
  151175. pred = (1<<Al)-1;
  151176. pred = -pred;
  151177. }
  151178. workspace[1] = (JCOEF) pred;
  151179. }
  151180. if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) {
  151181. num = 36 * Q00 * (DC2 - DC8);
  151182. if (num >= 0) {
  151183. pred = (int) (((Q10<<7) + num) / (Q10<<8));
  151184. if (Al > 0 && pred >= (1<<Al))
  151185. pred = (1<<Al)-1;
  151186. } else {
  151187. pred = (int) (((Q10<<7) - num) / (Q10<<8));
  151188. if (Al > 0 && pred >= (1<<Al))
  151189. pred = (1<<Al)-1;
  151190. pred = -pred;
  151191. }
  151192. workspace[8] = (JCOEF) pred;
  151193. }
  151194. if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) {
  151195. num = 9 * Q00 * (DC2 + DC8 - 2*DC5);
  151196. if (num >= 0) {
  151197. pred = (int) (((Q20<<7) + num) / (Q20<<8));
  151198. if (Al > 0 && pred >= (1<<Al))
  151199. pred = (1<<Al)-1;
  151200. } else {
  151201. pred = (int) (((Q20<<7) - num) / (Q20<<8));
  151202. if (Al > 0 && pred >= (1<<Al))
  151203. pred = (1<<Al)-1;
  151204. pred = -pred;
  151205. }
  151206. workspace[16] = (JCOEF) pred;
  151207. }
  151208. if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) {
  151209. num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
  151210. if (num >= 0) {
  151211. pred = (int) (((Q11<<7) + num) / (Q11<<8));
  151212. if (Al > 0 && pred >= (1<<Al))
  151213. pred = (1<<Al)-1;
  151214. } else {
  151215. pred = (int) (((Q11<<7) - num) / (Q11<<8));
  151216. if (Al > 0 && pred >= (1<<Al))
  151217. pred = (1<<Al)-1;
  151218. pred = -pred;
  151219. }
  151220. workspace[9] = (JCOEF) pred;
  151221. }
  151222. if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) {
  151223. num = 9 * Q00 * (DC4 + DC6 - 2*DC5);
  151224. if (num >= 0) {
  151225. pred = (int) (((Q02<<7) + num) / (Q02<<8));
  151226. if (Al > 0 && pred >= (1<<Al))
  151227. pred = (1<<Al)-1;
  151228. } else {
  151229. pred = (int) (((Q02<<7) - num) / (Q02<<8));
  151230. if (Al > 0 && pred >= (1<<Al))
  151231. pred = (1<<Al)-1;
  151232. pred = -pred;
  151233. }
  151234. workspace[2] = (JCOEF) pred;
  151235. }
  151236. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace,
  151237. output_ptr, output_col);
  151238. DC1 = DC2; DC2 = DC3;
  151239. DC4 = DC5; DC5 = DC6;
  151240. DC7 = DC8; DC8 = DC9;
  151241. buffer_ptr++, prev_block_row++, next_block_row++;
  151242. output_col += compptr->DCT_scaled_size;
  151243. }
  151244. output_ptr += compptr->DCT_scaled_size;
  151245. }
  151246. }
  151247. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151248. return JPEG_ROW_COMPLETED;
  151249. return JPEG_SCAN_COMPLETED;
  151250. }
  151251. #endif /* BLOCK_SMOOTHING_SUPPORTED */
  151252. GLOBAL(void)
  151253. jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  151254. {
  151255. my_coef_ptr3 coef;
  151256. coef = (my_coef_ptr3)
  151257. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151258. SIZEOF(my_coef_controller3));
  151259. cinfo->coef = (struct jpeg_d_coef_controller *) coef;
  151260. coef->pub.start_input_pass = start_input_pass;
  151261. coef->pub.start_output_pass = start_output_pass;
  151262. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151263. coef->coef_bits_latch = NULL;
  151264. #endif
  151265. if (need_full_buffer) {
  151266. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151267. int ci, access_rows;
  151268. jpeg_component_info *compptr;
  151269. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151270. ci++, compptr++) {
  151271. access_rows = compptr->v_samp_factor;
  151272. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151273. if (cinfo->progressive_mode)
  151274. access_rows *= 3;
  151275. #endif
  151276. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  151277. ((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE,
  151278. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  151279. (long) compptr->h_samp_factor),
  151280. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  151281. (long) compptr->v_samp_factor),
  151282. (JDIMENSION) access_rows);
  151283. }
  151284. coef->pub.consume_data = consume_data;
  151285. coef->pub.decompress_data = decompress_data;
  151286. coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
  151287. #else
  151288. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151289. #endif
  151290. } else {
  151291. JBLOCKROW buffer;
  151292. int i;
  151293. buffer = (JBLOCKROW)
  151294. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151295. D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  151296. for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
  151297. coef->MCU_buffer[i] = buffer + i;
  151298. }
  151299. coef->pub.consume_data = dummy_consume_data;
  151300. coef->pub.decompress_data = decompress_onepass;
  151301. coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
  151302. }
  151303. }
  151304. /*** End of inlined file: jdcoefct.c ***/
  151305. #undef FIX
  151306. /*** Start of inlined file: jdcolor.c ***/
  151307. #define JPEG_INTERNALS
  151308. typedef struct {
  151309. struct jpeg_color_deconverter pub; /* public fields */
  151310. int * Cr_r_tab; /* => table for Cr to R conversion */
  151311. int * Cb_b_tab; /* => table for Cb to B conversion */
  151312. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  151313. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  151314. } my_color_deconverter2;
  151315. typedef my_color_deconverter2 * my_cconvert_ptr2;
  151316. #define SCALEBITS 16 /* speediest right-shift on some machines */
  151317. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  151318. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  151319. LOCAL(void)
  151320. build_ycc_rgb_table (j_decompress_ptr cinfo)
  151321. {
  151322. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151323. int i;
  151324. INT32 x;
  151325. SHIFT_TEMPS
  151326. cconvert->Cr_r_tab = (int *)
  151327. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151328. (MAXJSAMPLE+1) * SIZEOF(int));
  151329. cconvert->Cb_b_tab = (int *)
  151330. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151331. (MAXJSAMPLE+1) * SIZEOF(int));
  151332. cconvert->Cr_g_tab = (INT32 *)
  151333. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151334. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151335. cconvert->Cb_g_tab = (INT32 *)
  151336. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151337. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151338. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  151339. cconvert->Cr_r_tab[i] = (int)
  151340. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  151341. cconvert->Cb_b_tab[i] = (int)
  151342. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  151343. cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  151344. cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  151345. }
  151346. }
  151347. METHODDEF(void)
  151348. ycc_rgb_convert (j_decompress_ptr cinfo,
  151349. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151350. JSAMPARRAY output_buf, int num_rows)
  151351. {
  151352. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151353. register int y, cb, cr;
  151354. register JSAMPROW outptr;
  151355. register JSAMPROW inptr0, inptr1, inptr2;
  151356. register JDIMENSION col;
  151357. JDIMENSION num_cols = cinfo->output_width;
  151358. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151359. register int * Crrtab = cconvert->Cr_r_tab;
  151360. register int * Cbbtab = cconvert->Cb_b_tab;
  151361. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151362. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151363. SHIFT_TEMPS
  151364. while (--num_rows >= 0) {
  151365. inptr0 = input_buf[0][input_row];
  151366. inptr1 = input_buf[1][input_row];
  151367. inptr2 = input_buf[2][input_row];
  151368. input_row++;
  151369. outptr = *output_buf++;
  151370. for (col = 0; col < num_cols; col++) {
  151371. y = GETJSAMPLE(inptr0[col]);
  151372. cb = GETJSAMPLE(inptr1[col]);
  151373. cr = GETJSAMPLE(inptr2[col]);
  151374. outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
  151375. outptr[RGB_GREEN] = range_limit[y +
  151376. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151377. SCALEBITS))];
  151378. outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
  151379. outptr += RGB_PIXELSIZE;
  151380. }
  151381. }
  151382. }
  151383. METHODDEF(void)
  151384. null_convert2 (j_decompress_ptr cinfo,
  151385. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151386. JSAMPARRAY output_buf, int num_rows)
  151387. {
  151388. register JSAMPROW inptr, outptr;
  151389. register JDIMENSION count;
  151390. register int num_components = cinfo->num_components;
  151391. JDIMENSION num_cols = cinfo->output_width;
  151392. int ci;
  151393. while (--num_rows >= 0) {
  151394. for (ci = 0; ci < num_components; ci++) {
  151395. inptr = input_buf[ci][input_row];
  151396. outptr = output_buf[0] + ci;
  151397. for (count = num_cols; count > 0; count--) {
  151398. *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
  151399. outptr += num_components;
  151400. }
  151401. }
  151402. input_row++;
  151403. output_buf++;
  151404. }
  151405. }
  151406. METHODDEF(void)
  151407. grayscale_convert2 (j_decompress_ptr cinfo,
  151408. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151409. JSAMPARRAY output_buf, int num_rows)
  151410. {
  151411. jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0,
  151412. num_rows, cinfo->output_width);
  151413. }
  151414. METHODDEF(void)
  151415. gray_rgb_convert (j_decompress_ptr cinfo,
  151416. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151417. JSAMPARRAY output_buf, int num_rows)
  151418. {
  151419. register JSAMPROW inptr, outptr;
  151420. register JDIMENSION col;
  151421. JDIMENSION num_cols = cinfo->output_width;
  151422. while (--num_rows >= 0) {
  151423. inptr = input_buf[0][input_row++];
  151424. outptr = *output_buf++;
  151425. for (col = 0; col < num_cols; col++) {
  151426. outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
  151427. outptr += RGB_PIXELSIZE;
  151428. }
  151429. }
  151430. }
  151431. METHODDEF(void)
  151432. ycck_cmyk_convert (j_decompress_ptr cinfo,
  151433. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151434. JSAMPARRAY output_buf, int num_rows)
  151435. {
  151436. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151437. register int y, cb, cr;
  151438. register JSAMPROW outptr;
  151439. register JSAMPROW inptr0, inptr1, inptr2, inptr3;
  151440. register JDIMENSION col;
  151441. JDIMENSION num_cols = cinfo->output_width;
  151442. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151443. register int * Crrtab = cconvert->Cr_r_tab;
  151444. register int * Cbbtab = cconvert->Cb_b_tab;
  151445. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151446. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151447. SHIFT_TEMPS
  151448. while (--num_rows >= 0) {
  151449. inptr0 = input_buf[0][input_row];
  151450. inptr1 = input_buf[1][input_row];
  151451. inptr2 = input_buf[2][input_row];
  151452. inptr3 = input_buf[3][input_row];
  151453. input_row++;
  151454. outptr = *output_buf++;
  151455. for (col = 0; col < num_cols; col++) {
  151456. y = GETJSAMPLE(inptr0[col]);
  151457. cb = GETJSAMPLE(inptr1[col]);
  151458. cr = GETJSAMPLE(inptr2[col]);
  151459. outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
  151460. outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
  151461. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151462. SCALEBITS)))];
  151463. outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
  151464. outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */
  151465. outptr += 4;
  151466. }
  151467. }
  151468. }
  151469. METHODDEF(void)
  151470. start_pass_dcolor (j_decompress_ptr cinfo)
  151471. {
  151472. }
  151473. GLOBAL(void)
  151474. jinit_color_deconverter (j_decompress_ptr cinfo)
  151475. {
  151476. my_cconvert_ptr2 cconvert;
  151477. int ci;
  151478. cconvert = (my_cconvert_ptr2)
  151479. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151480. SIZEOF(my_color_deconverter2));
  151481. cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert;
  151482. cconvert->pub.start_pass = start_pass_dcolor;
  151483. switch (cinfo->jpeg_color_space) {
  151484. case JCS_GRAYSCALE:
  151485. if (cinfo->num_components != 1)
  151486. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151487. break;
  151488. case JCS_RGB:
  151489. case JCS_YCbCr:
  151490. if (cinfo->num_components != 3)
  151491. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151492. break;
  151493. case JCS_CMYK:
  151494. case JCS_YCCK:
  151495. if (cinfo->num_components != 4)
  151496. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151497. break;
  151498. default: /* JCS_UNKNOWN can be anything */
  151499. if (cinfo->num_components < 1)
  151500. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151501. break;
  151502. }
  151503. switch (cinfo->out_color_space) {
  151504. case JCS_GRAYSCALE:
  151505. cinfo->out_color_components = 1;
  151506. if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
  151507. cinfo->jpeg_color_space == JCS_YCbCr) {
  151508. cconvert->pub.color_convert = grayscale_convert2;
  151509. for (ci = 1; ci < cinfo->num_components; ci++)
  151510. cinfo->comp_info[ci].component_needed = FALSE;
  151511. } else
  151512. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151513. break;
  151514. case JCS_RGB:
  151515. cinfo->out_color_components = RGB_PIXELSIZE;
  151516. if (cinfo->jpeg_color_space == JCS_YCbCr) {
  151517. cconvert->pub.color_convert = ycc_rgb_convert;
  151518. build_ycc_rgb_table(cinfo);
  151519. } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
  151520. cconvert->pub.color_convert = gray_rgb_convert;
  151521. } else if (cinfo->jpeg_color_space == JCS_RGB && RGB_PIXELSIZE == 3) {
  151522. cconvert->pub.color_convert = null_convert2;
  151523. } else
  151524. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151525. break;
  151526. case JCS_CMYK:
  151527. cinfo->out_color_components = 4;
  151528. if (cinfo->jpeg_color_space == JCS_YCCK) {
  151529. cconvert->pub.color_convert = ycck_cmyk_convert;
  151530. build_ycc_rgb_table(cinfo);
  151531. } else if (cinfo->jpeg_color_space == JCS_CMYK) {
  151532. cconvert->pub.color_convert = null_convert2;
  151533. } else
  151534. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151535. break;
  151536. default:
  151537. if (cinfo->out_color_space == cinfo->jpeg_color_space) {
  151538. cinfo->out_color_components = cinfo->num_components;
  151539. cconvert->pub.color_convert = null_convert2;
  151540. } else /* unsupported non-null conversion */
  151541. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151542. break;
  151543. }
  151544. if (cinfo->quantize_colors)
  151545. cinfo->output_components = 1; /* single colormapped output component */
  151546. else
  151547. cinfo->output_components = cinfo->out_color_components;
  151548. }
  151549. /*** End of inlined file: jdcolor.c ***/
  151550. #undef FIX
  151551. /*** Start of inlined file: jddctmgr.c ***/
  151552. #define JPEG_INTERNALS
  151553. typedef struct {
  151554. struct jpeg_inverse_dct pub; /* public fields */
  151555. int cur_method[MAX_COMPONENTS];
  151556. } my_idct_controller;
  151557. typedef my_idct_controller * my_idct_ptr;
  151558. typedef union {
  151559. ISLOW_MULT_TYPE islow_array[DCTSIZE2];
  151560. #ifdef DCT_IFAST_SUPPORTED
  151561. IFAST_MULT_TYPE ifast_array[DCTSIZE2];
  151562. #endif
  151563. #ifdef DCT_FLOAT_SUPPORTED
  151564. FLOAT_MULT_TYPE float_array[DCTSIZE2];
  151565. #endif
  151566. } multiplier_table;
  151567. #ifdef DCT_ISLOW_SUPPORTED
  151568. #define PROVIDE_ISLOW_TABLES
  151569. #else
  151570. #ifdef IDCT_SCALING_SUPPORTED
  151571. #define PROVIDE_ISLOW_TABLES
  151572. #endif
  151573. #endif
  151574. METHODDEF(void)
  151575. start_pass (j_decompress_ptr cinfo)
  151576. {
  151577. my_idct_ptr idct = (my_idct_ptr) cinfo->idct;
  151578. int ci, i;
  151579. jpeg_component_info *compptr;
  151580. int method = 0;
  151581. inverse_DCT_method_ptr method_ptr = NULL;
  151582. JQUANT_TBL * qtbl;
  151583. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151584. ci++, compptr++) {
  151585. switch (compptr->DCT_scaled_size) {
  151586. #ifdef IDCT_SCALING_SUPPORTED
  151587. case 1:
  151588. method_ptr = jpeg_idct_1x1;
  151589. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151590. break;
  151591. case 2:
  151592. method_ptr = jpeg_idct_2x2;
  151593. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151594. break;
  151595. case 4:
  151596. method_ptr = jpeg_idct_4x4;
  151597. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151598. break;
  151599. #endif
  151600. case DCTSIZE:
  151601. switch (cinfo->dct_method) {
  151602. #ifdef DCT_ISLOW_SUPPORTED
  151603. case JDCT_ISLOW:
  151604. method_ptr = jpeg_idct_islow;
  151605. method = JDCT_ISLOW;
  151606. break;
  151607. #endif
  151608. #ifdef DCT_IFAST_SUPPORTED
  151609. case JDCT_IFAST:
  151610. method_ptr = jpeg_idct_ifast;
  151611. method = JDCT_IFAST;
  151612. break;
  151613. #endif
  151614. #ifdef DCT_FLOAT_SUPPORTED
  151615. case JDCT_FLOAT:
  151616. method_ptr = jpeg_idct_float;
  151617. method = JDCT_FLOAT;
  151618. break;
  151619. #endif
  151620. default:
  151621. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151622. break;
  151623. }
  151624. break;
  151625. default:
  151626. ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->DCT_scaled_size);
  151627. break;
  151628. }
  151629. idct->pub.inverse_DCT[ci] = method_ptr;
  151630. if (! compptr->component_needed || idct->cur_method[ci] == method)
  151631. continue;
  151632. qtbl = compptr->quant_table;
  151633. if (qtbl == NULL) /* happens if no data yet for component */
  151634. continue;
  151635. idct->cur_method[ci] = method;
  151636. switch (method) {
  151637. #ifdef PROVIDE_ISLOW_TABLES
  151638. case JDCT_ISLOW:
  151639. {
  151640. ISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table;
  151641. for (i = 0; i < DCTSIZE2; i++) {
  151642. ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i];
  151643. }
  151644. }
  151645. break;
  151646. #endif
  151647. #ifdef DCT_IFAST_SUPPORTED
  151648. case JDCT_IFAST:
  151649. {
  151650. IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table;
  151651. #define CONST_BITS 14
  151652. static const INT16 aanscales[DCTSIZE2] = {
  151653. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  151654. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  151655. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  151656. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  151657. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  151658. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  151659. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  151660. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  151661. };
  151662. SHIFT_TEMPS
  151663. for (i = 0; i < DCTSIZE2; i++) {
  151664. ifmtbl[i] = (IFAST_MULT_TYPE)
  151665. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  151666. (INT32) aanscales[i]),
  151667. CONST_BITS-IFAST_SCALE_BITS);
  151668. }
  151669. }
  151670. break;
  151671. #endif
  151672. #ifdef DCT_FLOAT_SUPPORTED
  151673. case JDCT_FLOAT:
  151674. {
  151675. FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table;
  151676. int row, col;
  151677. static const double aanscalefactor[DCTSIZE] = {
  151678. 1.0, 1.387039845, 1.306562965, 1.175875602,
  151679. 1.0, 0.785694958, 0.541196100, 0.275899379
  151680. };
  151681. i = 0;
  151682. for (row = 0; row < DCTSIZE; row++) {
  151683. for (col = 0; col < DCTSIZE; col++) {
  151684. fmtbl[i] = (FLOAT_MULT_TYPE)
  151685. ((double) qtbl->quantval[i] *
  151686. aanscalefactor[row] * aanscalefactor[col]);
  151687. i++;
  151688. }
  151689. }
  151690. }
  151691. break;
  151692. #endif
  151693. default:
  151694. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151695. break;
  151696. }
  151697. }
  151698. }
  151699. GLOBAL(void)
  151700. jinit_inverse_dct (j_decompress_ptr cinfo)
  151701. {
  151702. my_idct_ptr idct;
  151703. int ci;
  151704. jpeg_component_info *compptr;
  151705. idct = (my_idct_ptr)
  151706. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151707. SIZEOF(my_idct_controller));
  151708. cinfo->idct = (struct jpeg_inverse_dct *) idct;
  151709. idct->pub.start_pass = start_pass;
  151710. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151711. ci++, compptr++) {
  151712. compptr->dct_table =
  151713. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151714. SIZEOF(multiplier_table));
  151715. MEMZERO(compptr->dct_table, SIZEOF(multiplier_table));
  151716. idct->cur_method[ci] = -1;
  151717. }
  151718. }
  151719. /*** End of inlined file: jddctmgr.c ***/
  151720. #undef CONST_BITS
  151721. #undef ASSIGN_STATE
  151722. /*** Start of inlined file: jdhuff.c ***/
  151723. #define JPEG_INTERNALS
  151724. /*** Start of inlined file: jdhuff.h ***/
  151725. #ifndef __jdhuff_h__
  151726. #define __jdhuff_h__
  151727. #ifdef NEED_SHORT_EXTERNAL_NAMES
  151728. #define jpeg_make_d_derived_tbl jMkDDerived
  151729. #define jpeg_fill_bit_buffer jFilBitBuf
  151730. #define jpeg_huff_decode jHufDecode
  151731. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  151732. #define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */
  151733. typedef struct {
  151734. INT32 maxcode[18]; /* largest code of length k (-1 if none) */
  151735. INT32 valoffset[17]; /* huffval[] offset for codes of length k */
  151736. JHUFF_TBL *pub;
  151737. int look_nbits[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */
  151738. UINT8 look_sym[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */
  151739. } d_derived_tbl;
  151740. EXTERN(void) jpeg_make_d_derived_tbl
  151741. JPP((j_decompress_ptr cinfo, boolean isDC, int tblno,
  151742. d_derived_tbl ** pdtbl));
  151743. typedef INT32 bit_buf_type; /* type of bit-extraction buffer */
  151744. #define BIT_BUF_SIZE 32 /* size of buffer in bits */
  151745. typedef struct { /* Bitreading state saved across MCUs */
  151746. bit_buf_type get_buffer; /* current bit-extraction buffer */
  151747. int bits_left; /* # of unused bits in it */
  151748. } bitread_perm_state;
  151749. typedef struct { /* Bitreading working state within an MCU */
  151750. const JOCTET * next_input_byte; /* => next byte to read from source */
  151751. size_t bytes_in_buffer; /* # of bytes remaining in source buffer */
  151752. bit_buf_type get_buffer; /* current bit-extraction buffer */
  151753. int bits_left; /* # of unused bits in it */
  151754. j_decompress_ptr cinfo; /* back link to decompress master record */
  151755. } bitread_working_state;
  151756. #define BITREAD_STATE_VARS \
  151757. register bit_buf_type get_buffer; \
  151758. register int bits_left; \
  151759. bitread_working_state br_state
  151760. #define BITREAD_LOAD_STATE(cinfop,permstate) \
  151761. br_state.cinfo = cinfop; \
  151762. br_state.next_input_byte = cinfop->src->next_input_byte; \
  151763. br_state.bytes_in_buffer = cinfop->src->bytes_in_buffer; \
  151764. get_buffer = permstate.get_buffer; \
  151765. bits_left = permstate.bits_left;
  151766. #define BITREAD_SAVE_STATE(cinfop,permstate) \
  151767. cinfop->src->next_input_byte = br_state.next_input_byte; \
  151768. cinfop->src->bytes_in_buffer = br_state.bytes_in_buffer; \
  151769. permstate.get_buffer = get_buffer; \
  151770. permstate.bits_left = bits_left
  151771. #define CHECK_BIT_BUFFER(state,nbits,action) \
  151772. { if (bits_left < (nbits)) { \
  151773. if (! jpeg_fill_bit_buffer(&(state),get_buffer,bits_left,nbits)) \
  151774. { action; } \
  151775. get_buffer = (state).get_buffer; bits_left = (state).bits_left; } }
  151776. #define GET_BITS(nbits) \
  151777. (((int) (get_buffer >> (bits_left -= (nbits)))) & ((1<<(nbits))-1))
  151778. #define PEEK_BITS(nbits) \
  151779. (((int) (get_buffer >> (bits_left - (nbits)))) & ((1<<(nbits))-1))
  151780. #define DROP_BITS(nbits) \
  151781. (bits_left -= (nbits))
  151782. EXTERN(boolean) jpeg_fill_bit_buffer
  151783. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  151784. register int bits_left, int nbits));
  151785. #define HUFF_DECODE(result,state,htbl,failaction,slowlabel) \
  151786. { register int nb, look; \
  151787. if (bits_left < HUFF_LOOKAHEAD) { \
  151788. if (! jpeg_fill_bit_buffer(&state,get_buffer,bits_left, 0)) {failaction;} \
  151789. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  151790. if (bits_left < HUFF_LOOKAHEAD) { \
  151791. nb = 1; goto slowlabel; \
  151792. } \
  151793. } \
  151794. look = PEEK_BITS(HUFF_LOOKAHEAD); \
  151795. if ((nb = htbl->look_nbits[look]) != 0) { \
  151796. DROP_BITS(nb); \
  151797. result = htbl->look_sym[look]; \
  151798. } else { \
  151799. nb = HUFF_LOOKAHEAD+1; \
  151800. slowlabel: \
  151801. if ((result=jpeg_huff_decode(&state,get_buffer,bits_left,htbl,nb)) < 0) \
  151802. { failaction; } \
  151803. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  151804. } \
  151805. }
  151806. EXTERN(int) jpeg_huff_decode
  151807. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  151808. register int bits_left, d_derived_tbl * htbl, int min_bits));
  151809. #endif
  151810. /*** End of inlined file: jdhuff.h ***/
  151811. /* Declarations shared with jdphuff.c */
  151812. typedef struct {
  151813. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  151814. } savable_state2;
  151815. #ifndef NO_STRUCT_ASSIGN
  151816. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  151817. #else
  151818. #if MAX_COMPS_IN_SCAN == 4
  151819. #define ASSIGN_STATE(dest,src) \
  151820. ((dest).last_dc_val[0] = (src).last_dc_val[0], \
  151821. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  151822. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  151823. (dest).last_dc_val[3] = (src).last_dc_val[3])
  151824. #endif
  151825. #endif
  151826. typedef struct {
  151827. struct jpeg_entropy_decoder pub; /* public fields */
  151828. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  151829. savable_state2 saved; /* Other state at start of MCU */
  151830. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  151831. d_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  151832. d_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  151833. d_derived_tbl * dc_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  151834. d_derived_tbl * ac_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  151835. boolean dc_needed[D_MAX_BLOCKS_IN_MCU];
  151836. boolean ac_needed[D_MAX_BLOCKS_IN_MCU];
  151837. } huff_entropy_decoder2;
  151838. typedef huff_entropy_decoder2 * huff_entropy_ptr2;
  151839. METHODDEF(void)
  151840. start_pass_huff_decoder (j_decompress_ptr cinfo)
  151841. {
  151842. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  151843. int ci, blkn, dctbl, actbl;
  151844. jpeg_component_info * compptr;
  151845. if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2-1 ||
  151846. cinfo->Ah != 0 || cinfo->Al != 0)
  151847. WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
  151848. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151849. compptr = cinfo->cur_comp_info[ci];
  151850. dctbl = compptr->dc_tbl_no;
  151851. actbl = compptr->ac_tbl_no;
  151852. jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl,
  151853. & entropy->dc_derived_tbls[dctbl]);
  151854. jpeg_make_d_derived_tbl(cinfo, FALSE, actbl,
  151855. & entropy->ac_derived_tbls[actbl]);
  151856. entropy->saved.last_dc_val[ci] = 0;
  151857. }
  151858. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  151859. ci = cinfo->MCU_membership[blkn];
  151860. compptr = cinfo->cur_comp_info[ci];
  151861. entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no];
  151862. entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no];
  151863. if (compptr->component_needed) {
  151864. entropy->dc_needed[blkn] = TRUE;
  151865. entropy->ac_needed[blkn] = (compptr->DCT_scaled_size > 1);
  151866. } else {
  151867. entropy->dc_needed[blkn] = entropy->ac_needed[blkn] = FALSE;
  151868. }
  151869. }
  151870. entropy->bitstate.bits_left = 0;
  151871. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  151872. entropy->pub.insufficient_data = FALSE;
  151873. entropy->restarts_to_go = cinfo->restart_interval;
  151874. }
  151875. GLOBAL(void)
  151876. jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
  151877. d_derived_tbl ** pdtbl)
  151878. {
  151879. JHUFF_TBL *htbl;
  151880. d_derived_tbl *dtbl;
  151881. int p, i, l, si, numsymbols;
  151882. int lookbits, ctr;
  151883. char huffsize[257];
  151884. unsigned int huffcode[257];
  151885. unsigned int code;
  151886. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  151887. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  151888. htbl =
  151889. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  151890. if (htbl == NULL)
  151891. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  151892. if (*pdtbl == NULL)
  151893. *pdtbl = (d_derived_tbl *)
  151894. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151895. SIZEOF(d_derived_tbl));
  151896. dtbl = *pdtbl;
  151897. dtbl->pub = htbl; /* fill in back link */
  151898. p = 0;
  151899. for (l = 1; l <= 16; l++) {
  151900. i = (int) htbl->bits[l];
  151901. if (i < 0 || p + i > 256) /* protect against table overrun */
  151902. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  151903. while (i--)
  151904. huffsize[p++] = (char) l;
  151905. }
  151906. huffsize[p] = 0;
  151907. numsymbols = p;
  151908. code = 0;
  151909. si = huffsize[0];
  151910. p = 0;
  151911. while (huffsize[p]) {
  151912. while (((int) huffsize[p]) == si) {
  151913. huffcode[p++] = code;
  151914. code++;
  151915. }
  151916. if (((INT32) code) >= (((INT32) 1) << si))
  151917. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  151918. code <<= 1;
  151919. si++;
  151920. }
  151921. p = 0;
  151922. for (l = 1; l <= 16; l++) {
  151923. if (htbl->bits[l]) {
  151924. dtbl->valoffset[l] = (INT32) p - (INT32) huffcode[p];
  151925. p += htbl->bits[l];
  151926. dtbl->maxcode[l] = huffcode[p-1]; /* maximum code of length l */
  151927. } else {
  151928. dtbl->maxcode[l] = -1; /* -1 if no codes of this length */
  151929. }
  151930. }
  151931. dtbl->maxcode[17] = 0xFFFFFL; /* ensures jpeg_huff_decode terminates */
  151932. MEMZERO(dtbl->look_nbits, SIZEOF(dtbl->look_nbits));
  151933. p = 0;
  151934. for (l = 1; l <= HUFF_LOOKAHEAD; l++) {
  151935. for (i = 1; i <= (int) htbl->bits[l]; i++, p++) {
  151936. lookbits = huffcode[p] << (HUFF_LOOKAHEAD-l);
  151937. for (ctr = 1 << (HUFF_LOOKAHEAD-l); ctr > 0; ctr--) {
  151938. dtbl->look_nbits[lookbits] = l;
  151939. dtbl->look_sym[lookbits] = htbl->huffval[p];
  151940. lookbits++;
  151941. }
  151942. }
  151943. }
  151944. if (isDC) {
  151945. for (i = 0; i < numsymbols; i++) {
  151946. int sym = htbl->huffval[i];
  151947. if (sym < 0 || sym > 15)
  151948. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  151949. }
  151950. }
  151951. }
  151952. #ifdef SLOW_SHIFT_32
  151953. #define MIN_GET_BITS 15 /* minimum allowable value */
  151954. #else
  151955. #define MIN_GET_BITS (BIT_BUF_SIZE-7)
  151956. #endif
  151957. GLOBAL(boolean)
  151958. jpeg_fill_bit_buffer (bitread_working_state * state,
  151959. register bit_buf_type get_buffer, register int bits_left,
  151960. int nbits)
  151961. {
  151962. register const JOCTET * next_input_byte = state->next_input_byte;
  151963. register size_t bytes_in_buffer = state->bytes_in_buffer;
  151964. j_decompress_ptr cinfo = state->cinfo;
  151965. if (cinfo->unread_marker == 0) { /* cannot advance past a marker */
  151966. while (bits_left < MIN_GET_BITS) {
  151967. register int c;
  151968. if (bytes_in_buffer == 0) {
  151969. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  151970. return FALSE;
  151971. next_input_byte = cinfo->src->next_input_byte;
  151972. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  151973. }
  151974. bytes_in_buffer--;
  151975. c = GETJOCTET(*next_input_byte++);
  151976. if (c == 0xFF) {
  151977. do {
  151978. if (bytes_in_buffer == 0) {
  151979. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  151980. return FALSE;
  151981. next_input_byte = cinfo->src->next_input_byte;
  151982. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  151983. }
  151984. bytes_in_buffer--;
  151985. c = GETJOCTET(*next_input_byte++);
  151986. } while (c == 0xFF);
  151987. if (c == 0) {
  151988. c = 0xFF;
  151989. } else {
  151990. cinfo->unread_marker = c;
  151991. goto no_more_bytes;
  151992. }
  151993. }
  151994. get_buffer = (get_buffer << 8) | c;
  151995. bits_left += 8;
  151996. } /* end while */
  151997. } else {
  151998. no_more_bytes:
  151999. if (nbits > bits_left) {
  152000. if (! cinfo->entropy->insufficient_data) {
  152001. WARNMS(cinfo, JWRN_HIT_MARKER);
  152002. cinfo->entropy->insufficient_data = TRUE;
  152003. }
  152004. get_buffer <<= MIN_GET_BITS - bits_left;
  152005. bits_left = MIN_GET_BITS;
  152006. }
  152007. }
  152008. state->next_input_byte = next_input_byte;
  152009. state->bytes_in_buffer = bytes_in_buffer;
  152010. state->get_buffer = get_buffer;
  152011. state->bits_left = bits_left;
  152012. return TRUE;
  152013. }
  152014. GLOBAL(int)
  152015. jpeg_huff_decode (bitread_working_state * state,
  152016. register bit_buf_type get_buffer, register int bits_left,
  152017. d_derived_tbl * htbl, int min_bits)
  152018. {
  152019. register int l = min_bits;
  152020. register INT32 code;
  152021. CHECK_BIT_BUFFER(*state, l, return -1);
  152022. code = GET_BITS(l);
  152023. while (code > htbl->maxcode[l]) {
  152024. code <<= 1;
  152025. CHECK_BIT_BUFFER(*state, 1, return -1);
  152026. code |= GET_BITS(1);
  152027. l++;
  152028. }
  152029. state->get_buffer = get_buffer;
  152030. state->bits_left = bits_left;
  152031. if (l > 16) {
  152032. WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE);
  152033. return 0; /* fake a zero as the safest result */
  152034. }
  152035. return htbl->pub->huffval[ (int) (code + htbl->valoffset[l]) ];
  152036. }
  152037. LOCAL(boolean)
  152038. process_restart (j_decompress_ptr cinfo)
  152039. {
  152040. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152041. int ci;
  152042. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  152043. entropy->bitstate.bits_left = 0;
  152044. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  152045. return FALSE;
  152046. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  152047. entropy->saved.last_dc_val[ci] = 0;
  152048. entropy->restarts_to_go = cinfo->restart_interval;
  152049. if (cinfo->unread_marker == 0)
  152050. entropy->pub.insufficient_data = FALSE;
  152051. return TRUE;
  152052. }
  152053. METHODDEF(boolean)
  152054. decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  152055. {
  152056. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152057. int blkn;
  152058. BITREAD_STATE_VARS;
  152059. savable_state2 state;
  152060. if (cinfo->restart_interval) {
  152061. if (entropy->restarts_to_go == 0)
  152062. if (! process_restart(cinfo))
  152063. return FALSE;
  152064. }
  152065. if (! entropy->pub.insufficient_data) {
  152066. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  152067. ASSIGN_STATE(state, entropy->saved);
  152068. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  152069. JBLOCKROW block = MCU_data[blkn];
  152070. d_derived_tbl * dctbl = entropy->dc_cur_tbls[blkn];
  152071. d_derived_tbl * actbl = entropy->ac_cur_tbls[blkn];
  152072. register int s, k, r;
  152073. HUFF_DECODE(s, br_state, dctbl, return FALSE, label1);
  152074. if (s) {
  152075. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152076. r = GET_BITS(s);
  152077. s = HUFF_EXTEND(r, s);
  152078. }
  152079. if (entropy->dc_needed[blkn]) {
  152080. int ci = cinfo->MCU_membership[blkn];
  152081. s += state.last_dc_val[ci];
  152082. state.last_dc_val[ci] = s;
  152083. (*block)[0] = (JCOEF) s;
  152084. }
  152085. if (entropy->ac_needed[blkn]) {
  152086. for (k = 1; k < DCTSIZE2; k++) {
  152087. HUFF_DECODE(s, br_state, actbl, return FALSE, label2);
  152088. r = s >> 4;
  152089. s &= 15;
  152090. if (s) {
  152091. k += r;
  152092. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152093. r = GET_BITS(s);
  152094. s = HUFF_EXTEND(r, s);
  152095. (*block)[jpeg_natural_order[k]] = (JCOEF) s;
  152096. } else {
  152097. if (r != 15)
  152098. break;
  152099. k += 15;
  152100. }
  152101. }
  152102. } else {
  152103. for (k = 1; k < DCTSIZE2; k++) {
  152104. HUFF_DECODE(s, br_state, actbl, return FALSE, label3);
  152105. r = s >> 4;
  152106. s &= 15;
  152107. if (s) {
  152108. k += r;
  152109. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152110. DROP_BITS(s);
  152111. } else {
  152112. if (r != 15)
  152113. break;
  152114. k += 15;
  152115. }
  152116. }
  152117. }
  152118. }
  152119. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  152120. ASSIGN_STATE(entropy->saved, state);
  152121. }
  152122. entropy->restarts_to_go--;
  152123. return TRUE;
  152124. }
  152125. GLOBAL(void)
  152126. jinit_huff_decoder (j_decompress_ptr cinfo)
  152127. {
  152128. huff_entropy_ptr2 entropy;
  152129. int i;
  152130. entropy = (huff_entropy_ptr2)
  152131. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152132. SIZEOF(huff_entropy_decoder2));
  152133. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  152134. entropy->pub.start_pass = start_pass_huff_decoder;
  152135. entropy->pub.decode_mcu = decode_mcu;
  152136. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  152137. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  152138. }
  152139. }
  152140. /*** End of inlined file: jdhuff.c ***/
  152141. /*** Start of inlined file: jdinput.c ***/
  152142. #define JPEG_INTERNALS
  152143. typedef struct {
  152144. struct jpeg_input_controller pub; /* public fields */
  152145. boolean inheaders; /* TRUE until first SOS is reached */
  152146. } my_input_controller;
  152147. typedef my_input_controller * my_inputctl_ptr;
  152148. METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo));
  152149. LOCAL(void)
  152150. initial_setup2 (j_decompress_ptr cinfo)
  152151. {
  152152. int ci;
  152153. jpeg_component_info *compptr;
  152154. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  152155. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  152156. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  152157. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  152158. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  152159. if (cinfo->num_components > MAX_COMPONENTS)
  152160. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  152161. MAX_COMPONENTS);
  152162. cinfo->max_h_samp_factor = 1;
  152163. cinfo->max_v_samp_factor = 1;
  152164. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152165. ci++, compptr++) {
  152166. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  152167. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  152168. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  152169. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  152170. compptr->h_samp_factor);
  152171. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  152172. compptr->v_samp_factor);
  152173. }
  152174. cinfo->min_DCT_scaled_size = DCTSIZE;
  152175. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152176. ci++, compptr++) {
  152177. compptr->DCT_scaled_size = DCTSIZE;
  152178. compptr->width_in_blocks = (JDIMENSION)
  152179. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152180. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  152181. compptr->height_in_blocks = (JDIMENSION)
  152182. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152183. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  152184. compptr->downsampled_width = (JDIMENSION)
  152185. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152186. (long) cinfo->max_h_samp_factor);
  152187. compptr->downsampled_height = (JDIMENSION)
  152188. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152189. (long) cinfo->max_v_samp_factor);
  152190. compptr->component_needed = TRUE;
  152191. compptr->quant_table = NULL;
  152192. }
  152193. cinfo->total_iMCU_rows = (JDIMENSION)
  152194. jdiv_round_up((long) cinfo->image_height,
  152195. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152196. if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode)
  152197. cinfo->inputctl->has_multiple_scans = TRUE;
  152198. else
  152199. cinfo->inputctl->has_multiple_scans = FALSE;
  152200. }
  152201. LOCAL(void)
  152202. per_scan_setup2 (j_decompress_ptr cinfo)
  152203. {
  152204. int ci, mcublks, tmp;
  152205. jpeg_component_info *compptr;
  152206. if (cinfo->comps_in_scan == 1) {
  152207. compptr = cinfo->cur_comp_info[0];
  152208. cinfo->MCUs_per_row = compptr->width_in_blocks;
  152209. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  152210. compptr->MCU_width = 1;
  152211. compptr->MCU_height = 1;
  152212. compptr->MCU_blocks = 1;
  152213. compptr->MCU_sample_width = compptr->DCT_scaled_size;
  152214. compptr->last_col_width = 1;
  152215. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  152216. if (tmp == 0) tmp = compptr->v_samp_factor;
  152217. compptr->last_row_height = tmp;
  152218. cinfo->blocks_in_MCU = 1;
  152219. cinfo->MCU_membership[0] = 0;
  152220. } else {
  152221. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  152222. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  152223. MAX_COMPS_IN_SCAN);
  152224. cinfo->MCUs_per_row = (JDIMENSION)
  152225. jdiv_round_up((long) cinfo->image_width,
  152226. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  152227. cinfo->MCU_rows_in_scan = (JDIMENSION)
  152228. jdiv_round_up((long) cinfo->image_height,
  152229. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152230. cinfo->blocks_in_MCU = 0;
  152231. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152232. compptr = cinfo->cur_comp_info[ci];
  152233. compptr->MCU_width = compptr->h_samp_factor;
  152234. compptr->MCU_height = compptr->v_samp_factor;
  152235. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  152236. compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_scaled_size;
  152237. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  152238. if (tmp == 0) tmp = compptr->MCU_width;
  152239. compptr->last_col_width = tmp;
  152240. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  152241. if (tmp == 0) tmp = compptr->MCU_height;
  152242. compptr->last_row_height = tmp;
  152243. mcublks = compptr->MCU_blocks;
  152244. if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU)
  152245. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  152246. while (mcublks-- > 0) {
  152247. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  152248. }
  152249. }
  152250. }
  152251. }
  152252. LOCAL(void)
  152253. latch_quant_tables (j_decompress_ptr cinfo)
  152254. {
  152255. int ci, qtblno;
  152256. jpeg_component_info *compptr;
  152257. JQUANT_TBL * qtbl;
  152258. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152259. compptr = cinfo->cur_comp_info[ci];
  152260. if (compptr->quant_table != NULL)
  152261. continue;
  152262. qtblno = compptr->quant_tbl_no;
  152263. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  152264. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  152265. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  152266. qtbl = (JQUANT_TBL *)
  152267. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152268. SIZEOF(JQUANT_TBL));
  152269. MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL));
  152270. compptr->quant_table = qtbl;
  152271. }
  152272. }
  152273. METHODDEF(void)
  152274. start_input_pass2 (j_decompress_ptr cinfo)
  152275. {
  152276. per_scan_setup2(cinfo);
  152277. latch_quant_tables(cinfo);
  152278. (*cinfo->entropy->start_pass) (cinfo);
  152279. (*cinfo->coef->start_input_pass) (cinfo);
  152280. cinfo->inputctl->consume_input = cinfo->coef->consume_data;
  152281. }
  152282. METHODDEF(void)
  152283. finish_input_pass (j_decompress_ptr cinfo)
  152284. {
  152285. cinfo->inputctl->consume_input = consume_markers;
  152286. }
  152287. METHODDEF(int)
  152288. consume_markers (j_decompress_ptr cinfo)
  152289. {
  152290. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152291. int val;
  152292. if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */
  152293. return JPEG_REACHED_EOI;
  152294. val = (*cinfo->marker->read_markers) (cinfo);
  152295. switch (val) {
  152296. case JPEG_REACHED_SOS: /* Found SOS */
  152297. if (inputctl->inheaders) { /* 1st SOS */
  152298. initial_setup2(cinfo);
  152299. inputctl->inheaders = FALSE;
  152300. } else { /* 2nd or later SOS marker */
  152301. if (! inputctl->pub.has_multiple_scans)
  152302. ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */
  152303. start_input_pass2(cinfo);
  152304. }
  152305. break;
  152306. case JPEG_REACHED_EOI: /* Found EOI */
  152307. inputctl->pub.eoi_reached = TRUE;
  152308. if (inputctl->inheaders) { /* Tables-only datastream, apparently */
  152309. if (cinfo->marker->saw_SOF)
  152310. ERREXIT(cinfo, JERR_SOF_NO_SOS);
  152311. } else {
  152312. if (cinfo->output_scan_number > cinfo->input_scan_number)
  152313. cinfo->output_scan_number = cinfo->input_scan_number;
  152314. }
  152315. break;
  152316. case JPEG_SUSPENDED:
  152317. break;
  152318. }
  152319. return val;
  152320. }
  152321. METHODDEF(void)
  152322. reset_input_controller (j_decompress_ptr cinfo)
  152323. {
  152324. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152325. inputctl->pub.consume_input = consume_markers;
  152326. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152327. inputctl->pub.eoi_reached = FALSE;
  152328. inputctl->inheaders = TRUE;
  152329. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  152330. (*cinfo->marker->reset_marker_reader) (cinfo);
  152331. cinfo->coef_bits = NULL;
  152332. }
  152333. GLOBAL(void)
  152334. jinit_input_controller (j_decompress_ptr cinfo)
  152335. {
  152336. my_inputctl_ptr inputctl;
  152337. inputctl = (my_inputctl_ptr)
  152338. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  152339. SIZEOF(my_input_controller));
  152340. cinfo->inputctl = (struct jpeg_input_controller *) inputctl;
  152341. inputctl->pub.consume_input = consume_markers;
  152342. inputctl->pub.reset_input_controller = reset_input_controller;
  152343. inputctl->pub.start_input_pass = start_input_pass2;
  152344. inputctl->pub.finish_input_pass = finish_input_pass;
  152345. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152346. inputctl->pub.eoi_reached = FALSE;
  152347. inputctl->inheaders = TRUE;
  152348. }
  152349. /*** End of inlined file: jdinput.c ***/
  152350. /*** Start of inlined file: jdmainct.c ***/
  152351. #define JPEG_INTERNALS
  152352. typedef struct {
  152353. struct jpeg_d_main_controller pub; /* public fields */
  152354. JSAMPARRAY buffer[MAX_COMPONENTS];
  152355. boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
  152356. JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */
  152357. JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
  152358. int whichptr; /* indicates which pointer set is now in use */
  152359. int context_state; /* process_data state machine status */
  152360. JDIMENSION rowgroups_avail; /* row groups available to postprocessor */
  152361. JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */
  152362. } my_main_controller4;
  152363. typedef my_main_controller4 * my_main_ptr4;
  152364. #define CTX_PREPARE_FOR_IMCU 0 /* need to prepare for MCU row */
  152365. #define CTX_PROCESS_IMCU 1 /* feeding iMCU to postprocessor */
  152366. #define CTX_POSTPONED_ROW 2 /* feeding postponed row group */
  152367. METHODDEF(void) process_data_simple_main2
  152368. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152369. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152370. METHODDEF(void) process_data_context_main
  152371. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152372. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152373. #ifdef QUANT_2PASS_SUPPORTED
  152374. METHODDEF(void) process_data_crank_post
  152375. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152376. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152377. #endif
  152378. LOCAL(void)
  152379. alloc_funny_pointers (j_decompress_ptr cinfo)
  152380. {
  152381. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152382. int ci, rgroup;
  152383. int M = cinfo->min_DCT_scaled_size;
  152384. jpeg_component_info *compptr;
  152385. JSAMPARRAY xbuf;
  152386. main_->xbuffer[0] = (JSAMPIMAGE)
  152387. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152388. cinfo->num_components * 2 * SIZEOF(JSAMPARRAY));
  152389. main_->xbuffer[1] = main_->xbuffer[0] + cinfo->num_components;
  152390. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152391. ci++, compptr++) {
  152392. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152393. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152394. xbuf = (JSAMPARRAY)
  152395. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152396. 2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
  152397. xbuf += rgroup; /* want one row group at negative offsets */
  152398. main_->xbuffer[0][ci] = xbuf;
  152399. xbuf += rgroup * (M + 4);
  152400. main_->xbuffer[1][ci] = xbuf;
  152401. }
  152402. }
  152403. LOCAL(void)
  152404. make_funny_pointers (j_decompress_ptr cinfo)
  152405. {
  152406. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152407. int ci, i, rgroup;
  152408. int M = cinfo->min_DCT_scaled_size;
  152409. jpeg_component_info *compptr;
  152410. JSAMPARRAY buf, xbuf0, xbuf1;
  152411. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152412. ci++, compptr++) {
  152413. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152414. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152415. xbuf0 = main_->xbuffer[0][ci];
  152416. xbuf1 = main_->xbuffer[1][ci];
  152417. buf = main_->buffer[ci];
  152418. for (i = 0; i < rgroup * (M + 2); i++) {
  152419. xbuf0[i] = xbuf1[i] = buf[i];
  152420. }
  152421. for (i = 0; i < rgroup * 2; i++) {
  152422. xbuf1[rgroup*(M-2) + i] = buf[rgroup*M + i];
  152423. xbuf1[rgroup*M + i] = buf[rgroup*(M-2) + i];
  152424. }
  152425. for (i = 0; i < rgroup; i++) {
  152426. xbuf0[i - rgroup] = xbuf0[0];
  152427. }
  152428. }
  152429. }
  152430. LOCAL(void)
  152431. set_wraparound_pointers (j_decompress_ptr cinfo)
  152432. {
  152433. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152434. int ci, i, rgroup;
  152435. int M = cinfo->min_DCT_scaled_size;
  152436. jpeg_component_info *compptr;
  152437. JSAMPARRAY xbuf0, xbuf1;
  152438. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152439. ci++, compptr++) {
  152440. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152441. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152442. xbuf0 = main_->xbuffer[0][ci];
  152443. xbuf1 = main_->xbuffer[1][ci];
  152444. for (i = 0; i < rgroup; i++) {
  152445. xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i];
  152446. xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i];
  152447. xbuf0[rgroup*(M+2) + i] = xbuf0[i];
  152448. xbuf1[rgroup*(M+2) + i] = xbuf1[i];
  152449. }
  152450. }
  152451. }
  152452. LOCAL(void)
  152453. set_bottom_pointers (j_decompress_ptr cinfo)
  152454. {
  152455. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152456. int ci, i, rgroup, iMCUheight, rows_left;
  152457. jpeg_component_info *compptr;
  152458. JSAMPARRAY xbuf;
  152459. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152460. ci++, compptr++) {
  152461. iMCUheight = compptr->v_samp_factor * compptr->DCT_scaled_size;
  152462. rgroup = iMCUheight / cinfo->min_DCT_scaled_size;
  152463. rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight);
  152464. if (rows_left == 0) rows_left = iMCUheight;
  152465. if (ci == 0) {
  152466. main_->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1);
  152467. }
  152468. xbuf = main_->xbuffer[main_->whichptr][ci];
  152469. for (i = 0; i < rgroup * 2; i++) {
  152470. xbuf[rows_left + i] = xbuf[rows_left-1];
  152471. }
  152472. }
  152473. }
  152474. METHODDEF(void)
  152475. start_pass_main2 (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  152476. {
  152477. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152478. switch (pass_mode) {
  152479. case JBUF_PASS_THRU:
  152480. if (cinfo->upsample->need_context_rows) {
  152481. main_->pub.process_data = process_data_context_main;
  152482. make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
  152483. main_->whichptr = 0; /* Read first iMCU row into xbuffer[0] */
  152484. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152485. main_->iMCU_row_ctr = 0;
  152486. } else {
  152487. main_->pub.process_data = process_data_simple_main2;
  152488. }
  152489. main_->buffer_full = FALSE; /* Mark buffer empty */
  152490. main_->rowgroup_ctr = 0;
  152491. break;
  152492. #ifdef QUANT_2PASS_SUPPORTED
  152493. case JBUF_CRANK_DEST:
  152494. main_->pub.process_data = process_data_crank_post;
  152495. break;
  152496. #endif
  152497. default:
  152498. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152499. break;
  152500. }
  152501. }
  152502. METHODDEF(void)
  152503. process_data_simple_main2 (j_decompress_ptr cinfo,
  152504. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152505. JDIMENSION out_rows_avail)
  152506. {
  152507. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152508. JDIMENSION rowgroups_avail;
  152509. if (! main_->buffer_full) {
  152510. if (! (*cinfo->coef->decompress_data) (cinfo, main_->buffer))
  152511. return; /* suspension forced, can do nothing more */
  152512. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  152513. }
  152514. rowgroups_avail = (JDIMENSION) cinfo->min_DCT_scaled_size;
  152515. (*cinfo->post->post_process_data) (cinfo, main_->buffer,
  152516. &main_->rowgroup_ctr, rowgroups_avail,
  152517. output_buf, out_row_ctr, out_rows_avail);
  152518. if (main_->rowgroup_ctr >= rowgroups_avail) {
  152519. main_->buffer_full = FALSE;
  152520. main_->rowgroup_ctr = 0;
  152521. }
  152522. }
  152523. METHODDEF(void)
  152524. process_data_context_main (j_decompress_ptr cinfo,
  152525. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152526. JDIMENSION out_rows_avail)
  152527. {
  152528. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152529. if (! main_->buffer_full) {
  152530. if (! (*cinfo->coef->decompress_data) (cinfo,
  152531. main_->xbuffer[main_->whichptr]))
  152532. return; /* suspension forced, can do nothing more */
  152533. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  152534. main_->iMCU_row_ctr++; /* count rows received */
  152535. }
  152536. switch (main_->context_state) {
  152537. case CTX_POSTPONED_ROW:
  152538. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  152539. &main_->rowgroup_ctr, main_->rowgroups_avail,
  152540. output_buf, out_row_ctr, out_rows_avail);
  152541. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  152542. return; /* Need to suspend */
  152543. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152544. if (*out_row_ctr >= out_rows_avail)
  152545. return; /* Postprocessor exactly filled output buf */
  152546. case CTX_PREPARE_FOR_IMCU:
  152547. main_->rowgroup_ctr = 0;
  152548. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size - 1);
  152549. if (main_->iMCU_row_ctr == cinfo->total_iMCU_rows)
  152550. set_bottom_pointers(cinfo);
  152551. main_->context_state = CTX_PROCESS_IMCU;
  152552. case CTX_PROCESS_IMCU:
  152553. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  152554. &main_->rowgroup_ctr, main_->rowgroups_avail,
  152555. output_buf, out_row_ctr, out_rows_avail);
  152556. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  152557. return; /* Need to suspend */
  152558. if (main_->iMCU_row_ctr == 1)
  152559. set_wraparound_pointers(cinfo);
  152560. main_->whichptr ^= 1; /* 0=>1 or 1=>0 */
  152561. main_->buffer_full = FALSE;
  152562. main_->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_scaled_size + 1);
  152563. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size + 2);
  152564. main_->context_state = CTX_POSTPONED_ROW;
  152565. }
  152566. }
  152567. #ifdef QUANT_2PASS_SUPPORTED
  152568. METHODDEF(void)
  152569. process_data_crank_post (j_decompress_ptr cinfo,
  152570. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152571. JDIMENSION out_rows_avail)
  152572. {
  152573. (*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL,
  152574. (JDIMENSION *) NULL, (JDIMENSION) 0,
  152575. output_buf, out_row_ctr, out_rows_avail);
  152576. }
  152577. #endif /* QUANT_2PASS_SUPPORTED */
  152578. GLOBAL(void)
  152579. jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  152580. {
  152581. my_main_ptr4 main_;
  152582. int ci, rgroup, ngroups;
  152583. jpeg_component_info *compptr;
  152584. main_ = (my_main_ptr4)
  152585. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152586. SIZEOF(my_main_controller4));
  152587. cinfo->main = (struct jpeg_d_main_controller *) main_;
  152588. main_->pub.start_pass = start_pass_main2;
  152589. if (need_full_buffer) /* shouldn't happen */
  152590. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152591. if (cinfo->upsample->need_context_rows) {
  152592. if (cinfo->min_DCT_scaled_size < 2) /* unsupported, see comments above */
  152593. ERREXIT(cinfo, JERR_NOTIMPL);
  152594. alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
  152595. ngroups = cinfo->min_DCT_scaled_size + 2;
  152596. } else {
  152597. ngroups = cinfo->min_DCT_scaled_size;
  152598. }
  152599. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152600. ci++, compptr++) {
  152601. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152602. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152603. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  152604. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152605. compptr->width_in_blocks * compptr->DCT_scaled_size,
  152606. (JDIMENSION) (rgroup * ngroups));
  152607. }
  152608. }
  152609. /*** End of inlined file: jdmainct.c ***/
  152610. /*** Start of inlined file: jdmarker.c ***/
  152611. #define JPEG_INTERNALS
  152612. typedef struct {
  152613. struct jpeg_marker_reader pub; /* public fields */
  152614. jpeg_marker_parser_method process_COM;
  152615. jpeg_marker_parser_method process_APPn[16];
  152616. unsigned int length_limit_COM;
  152617. unsigned int length_limit_APPn[16];
  152618. jpeg_saved_marker_ptr cur_marker; /* NULL if not processing a marker */
  152619. unsigned int bytes_read; /* data bytes read so far in marker */
  152620. } my_marker_reader;
  152621. typedef my_marker_reader * my_marker_ptr2;
  152622. #define INPUT_VARS(cinfo) \
  152623. struct jpeg_source_mgr * datasrc = (cinfo)->src; \
  152624. const JOCTET * next_input_byte = datasrc->next_input_byte; \
  152625. size_t bytes_in_buffer = datasrc->bytes_in_buffer
  152626. #define INPUT_SYNC(cinfo) \
  152627. ( datasrc->next_input_byte = next_input_byte, \
  152628. datasrc->bytes_in_buffer = bytes_in_buffer )
  152629. #define INPUT_RELOAD(cinfo) \
  152630. ( next_input_byte = datasrc->next_input_byte, \
  152631. bytes_in_buffer = datasrc->bytes_in_buffer )
  152632. #define MAKE_BYTE_AVAIL(cinfo,action) \
  152633. if (bytes_in_buffer == 0) { \
  152634. if (! (*datasrc->fill_input_buffer) (cinfo)) \
  152635. { action; } \
  152636. INPUT_RELOAD(cinfo); \
  152637. }
  152638. #define INPUT_BYTE(cinfo,V,action) \
  152639. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  152640. bytes_in_buffer--; \
  152641. V = GETJOCTET(*next_input_byte++); )
  152642. #define INPUT_2BYTES(cinfo,V,action) \
  152643. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  152644. bytes_in_buffer--; \
  152645. V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \
  152646. MAKE_BYTE_AVAIL(cinfo,action); \
  152647. bytes_in_buffer--; \
  152648. V += GETJOCTET(*next_input_byte++); )
  152649. LOCAL(boolean)
  152650. get_soi (j_decompress_ptr cinfo)
  152651. {
  152652. int i;
  152653. TRACEMS(cinfo, 1, JTRC_SOI);
  152654. if (cinfo->marker->saw_SOI)
  152655. ERREXIT(cinfo, JERR_SOI_DUPLICATE);
  152656. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  152657. cinfo->arith_dc_L[i] = 0;
  152658. cinfo->arith_dc_U[i] = 1;
  152659. cinfo->arith_ac_K[i] = 5;
  152660. }
  152661. cinfo->restart_interval = 0;
  152662. cinfo->jpeg_color_space = JCS_UNKNOWN;
  152663. cinfo->CCIR601_sampling = FALSE; /* Assume non-CCIR sampling??? */
  152664. cinfo->saw_JFIF_marker = FALSE;
  152665. cinfo->JFIF_major_version = 1; /* set default JFIF APP0 values */
  152666. cinfo->JFIF_minor_version = 1;
  152667. cinfo->density_unit = 0;
  152668. cinfo->X_density = 1;
  152669. cinfo->Y_density = 1;
  152670. cinfo->saw_Adobe_marker = FALSE;
  152671. cinfo->Adobe_transform = 0;
  152672. cinfo->marker->saw_SOI = TRUE;
  152673. return TRUE;
  152674. }
  152675. LOCAL(boolean)
  152676. get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
  152677. {
  152678. INT32 length;
  152679. int c, ci;
  152680. jpeg_component_info * compptr;
  152681. INPUT_VARS(cinfo);
  152682. cinfo->progressive_mode = is_prog;
  152683. cinfo->arith_code = is_arith;
  152684. INPUT_2BYTES(cinfo, length, return FALSE);
  152685. INPUT_BYTE(cinfo, cinfo->data_precision, return FALSE);
  152686. INPUT_2BYTES(cinfo, cinfo->image_height, return FALSE);
  152687. INPUT_2BYTES(cinfo, cinfo->image_width, return FALSE);
  152688. INPUT_BYTE(cinfo, cinfo->num_components, return FALSE);
  152689. length -= 8;
  152690. TRACEMS4(cinfo, 1, JTRC_SOF, cinfo->unread_marker,
  152691. (int) cinfo->image_width, (int) cinfo->image_height,
  152692. cinfo->num_components);
  152693. if (cinfo->marker->saw_SOF)
  152694. ERREXIT(cinfo, JERR_SOF_DUPLICATE);
  152695. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  152696. || cinfo->num_components <= 0)
  152697. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  152698. if (length != (cinfo->num_components * 3))
  152699. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152700. if (cinfo->comp_info == NULL) /* do only once, even if suspend */
  152701. cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small)
  152702. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152703. cinfo->num_components * SIZEOF(jpeg_component_info));
  152704. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152705. ci++, compptr++) {
  152706. compptr->component_index = ci;
  152707. INPUT_BYTE(cinfo, compptr->component_id, return FALSE);
  152708. INPUT_BYTE(cinfo, c, return FALSE);
  152709. compptr->h_samp_factor = (c >> 4) & 15;
  152710. compptr->v_samp_factor = (c ) & 15;
  152711. INPUT_BYTE(cinfo, compptr->quant_tbl_no, return FALSE);
  152712. TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT,
  152713. compptr->component_id, compptr->h_samp_factor,
  152714. compptr->v_samp_factor, compptr->quant_tbl_no);
  152715. }
  152716. cinfo->marker->saw_SOF = TRUE;
  152717. INPUT_SYNC(cinfo);
  152718. return TRUE;
  152719. }
  152720. LOCAL(boolean)
  152721. get_sos (j_decompress_ptr cinfo)
  152722. {
  152723. INT32 length;
  152724. int i, ci, n, c, cc;
  152725. jpeg_component_info * compptr;
  152726. INPUT_VARS(cinfo);
  152727. if (! cinfo->marker->saw_SOF)
  152728. ERREXIT(cinfo, JERR_SOS_NO_SOF);
  152729. INPUT_2BYTES(cinfo, length, return FALSE);
  152730. INPUT_BYTE(cinfo, n, return FALSE); /* Number of components */
  152731. TRACEMS1(cinfo, 1, JTRC_SOS, n);
  152732. if (length != (n * 2 + 6) || n < 1 || n > MAX_COMPS_IN_SCAN)
  152733. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152734. cinfo->comps_in_scan = n;
  152735. for (i = 0; i < n; i++) {
  152736. INPUT_BYTE(cinfo, cc, return FALSE);
  152737. INPUT_BYTE(cinfo, c, return FALSE);
  152738. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152739. ci++, compptr++) {
  152740. if (cc == compptr->component_id)
  152741. goto id_found;
  152742. }
  152743. ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc);
  152744. id_found:
  152745. cinfo->cur_comp_info[i] = compptr;
  152746. compptr->dc_tbl_no = (c >> 4) & 15;
  152747. compptr->ac_tbl_no = (c ) & 15;
  152748. TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc,
  152749. compptr->dc_tbl_no, compptr->ac_tbl_no);
  152750. }
  152751. INPUT_BYTE(cinfo, c, return FALSE);
  152752. cinfo->Ss = c;
  152753. INPUT_BYTE(cinfo, c, return FALSE);
  152754. cinfo->Se = c;
  152755. INPUT_BYTE(cinfo, c, return FALSE);
  152756. cinfo->Ah = (c >> 4) & 15;
  152757. cinfo->Al = (c ) & 15;
  152758. TRACEMS4(cinfo, 1, JTRC_SOS_PARAMS, cinfo->Ss, cinfo->Se,
  152759. cinfo->Ah, cinfo->Al);
  152760. cinfo->marker->next_restart_num = 0;
  152761. cinfo->input_scan_number++;
  152762. INPUT_SYNC(cinfo);
  152763. return TRUE;
  152764. }
  152765. #ifdef D_ARITH_CODING_SUPPORTED
  152766. LOCAL(boolean)
  152767. get_dac (j_decompress_ptr cinfo)
  152768. {
  152769. INT32 length;
  152770. int index, val;
  152771. INPUT_VARS(cinfo);
  152772. INPUT_2BYTES(cinfo, length, return FALSE);
  152773. length -= 2;
  152774. while (length > 0) {
  152775. INPUT_BYTE(cinfo, index, return FALSE);
  152776. INPUT_BYTE(cinfo, val, return FALSE);
  152777. length -= 2;
  152778. TRACEMS2(cinfo, 1, JTRC_DAC, index, val);
  152779. if (index < 0 || index >= (2*NUM_ARITH_TBLS))
  152780. ERREXIT1(cinfo, JERR_DAC_INDEX, index);
  152781. if (index >= NUM_ARITH_TBLS) { /* define AC table */
  152782. cinfo->arith_ac_K[index-NUM_ARITH_TBLS] = (UINT8) val;
  152783. } else { /* define DC table */
  152784. cinfo->arith_dc_L[index] = (UINT8) (val & 0x0F);
  152785. cinfo->arith_dc_U[index] = (UINT8) (val >> 4);
  152786. if (cinfo->arith_dc_L[index] > cinfo->arith_dc_U[index])
  152787. ERREXIT1(cinfo, JERR_DAC_VALUE, val);
  152788. }
  152789. }
  152790. if (length != 0)
  152791. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152792. INPUT_SYNC(cinfo);
  152793. return TRUE;
  152794. }
  152795. #else /* ! D_ARITH_CODING_SUPPORTED */
  152796. #define get_dac(cinfo) skip_variable(cinfo)
  152797. #endif /* D_ARITH_CODING_SUPPORTED */
  152798. LOCAL(boolean)
  152799. get_dht (j_decompress_ptr cinfo)
  152800. {
  152801. INT32 length;
  152802. UINT8 bits[17];
  152803. UINT8 huffval[256];
  152804. int i, index, count;
  152805. JHUFF_TBL **htblptr;
  152806. INPUT_VARS(cinfo);
  152807. INPUT_2BYTES(cinfo, length, return FALSE);
  152808. length -= 2;
  152809. while (length > 16) {
  152810. INPUT_BYTE(cinfo, index, return FALSE);
  152811. TRACEMS1(cinfo, 1, JTRC_DHT, index);
  152812. bits[0] = 0;
  152813. count = 0;
  152814. for (i = 1; i <= 16; i++) {
  152815. INPUT_BYTE(cinfo, bits[i], return FALSE);
  152816. count += bits[i];
  152817. }
  152818. length -= 1 + 16;
  152819. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  152820. bits[1], bits[2], bits[3], bits[4],
  152821. bits[5], bits[6], bits[7], bits[8]);
  152822. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  152823. bits[9], bits[10], bits[11], bits[12],
  152824. bits[13], bits[14], bits[15], bits[16]);
  152825. if (count > 256 || ((INT32) count) > length)
  152826. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152827. for (i = 0; i < count; i++)
  152828. INPUT_BYTE(cinfo, huffval[i], return FALSE);
  152829. length -= count;
  152830. if (index & 0x10) { /* AC table definition */
  152831. index -= 0x10;
  152832. htblptr = &cinfo->ac_huff_tbl_ptrs[index];
  152833. } else { /* DC table definition */
  152834. htblptr = &cinfo->dc_huff_tbl_ptrs[index];
  152835. }
  152836. if (index < 0 || index >= NUM_HUFF_TBLS)
  152837. ERREXIT1(cinfo, JERR_DHT_INDEX, index);
  152838. if (*htblptr == NULL)
  152839. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  152840. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  152841. MEMCOPY((*htblptr)->huffval, huffval, SIZEOF((*htblptr)->huffval));
  152842. }
  152843. if (length != 0)
  152844. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152845. INPUT_SYNC(cinfo);
  152846. return TRUE;
  152847. }
  152848. LOCAL(boolean)
  152849. get_dqt (j_decompress_ptr cinfo)
  152850. {
  152851. INT32 length;
  152852. int n, i, prec;
  152853. unsigned int tmp;
  152854. JQUANT_TBL *quant_ptr;
  152855. INPUT_VARS(cinfo);
  152856. INPUT_2BYTES(cinfo, length, return FALSE);
  152857. length -= 2;
  152858. while (length > 0) {
  152859. INPUT_BYTE(cinfo, n, return FALSE);
  152860. prec = n >> 4;
  152861. n &= 0x0F;
  152862. TRACEMS2(cinfo, 1, JTRC_DQT, n, prec);
  152863. if (n >= NUM_QUANT_TBLS)
  152864. ERREXIT1(cinfo, JERR_DQT_INDEX, n);
  152865. if (cinfo->quant_tbl_ptrs[n] == NULL)
  152866. cinfo->quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  152867. quant_ptr = cinfo->quant_tbl_ptrs[n];
  152868. for (i = 0; i < DCTSIZE2; i++) {
  152869. if (prec)
  152870. INPUT_2BYTES(cinfo, tmp, return FALSE);
  152871. else
  152872. INPUT_BYTE(cinfo, tmp, return FALSE);
  152873. quant_ptr->quantval[jpeg_natural_order[i]] = (UINT16) tmp;
  152874. }
  152875. if (cinfo->err->trace_level >= 2) {
  152876. for (i = 0; i < DCTSIZE2; i += 8) {
  152877. TRACEMS8(cinfo, 2, JTRC_QUANTVALS,
  152878. quant_ptr->quantval[i], quant_ptr->quantval[i+1],
  152879. quant_ptr->quantval[i+2], quant_ptr->quantval[i+3],
  152880. quant_ptr->quantval[i+4], quant_ptr->quantval[i+5],
  152881. quant_ptr->quantval[i+6], quant_ptr->quantval[i+7]);
  152882. }
  152883. }
  152884. length -= DCTSIZE2+1;
  152885. if (prec) length -= DCTSIZE2;
  152886. }
  152887. if (length != 0)
  152888. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152889. INPUT_SYNC(cinfo);
  152890. return TRUE;
  152891. }
  152892. LOCAL(boolean)
  152893. get_dri (j_decompress_ptr cinfo)
  152894. {
  152895. INT32 length;
  152896. unsigned int tmp;
  152897. INPUT_VARS(cinfo);
  152898. INPUT_2BYTES(cinfo, length, return FALSE);
  152899. if (length != 4)
  152900. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152901. INPUT_2BYTES(cinfo, tmp, return FALSE);
  152902. TRACEMS1(cinfo, 1, JTRC_DRI, tmp);
  152903. cinfo->restart_interval = tmp;
  152904. INPUT_SYNC(cinfo);
  152905. return TRUE;
  152906. }
  152907. #define APP0_DATA_LEN 14 /* Length of interesting data in APP0 */
  152908. #define APP14_DATA_LEN 12 /* Length of interesting data in APP14 */
  152909. #define APPN_DATA_LEN 14 /* Must be the largest of the above!! */
  152910. LOCAL(void)
  152911. examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
  152912. unsigned int datalen, INT32 remaining)
  152913. {
  152914. INT32 totallen = (INT32) datalen + remaining;
  152915. if (datalen >= APP0_DATA_LEN &&
  152916. GETJOCTET(data[0]) == 0x4A &&
  152917. GETJOCTET(data[1]) == 0x46 &&
  152918. GETJOCTET(data[2]) == 0x49 &&
  152919. GETJOCTET(data[3]) == 0x46 &&
  152920. GETJOCTET(data[4]) == 0) {
  152921. cinfo->saw_JFIF_marker = TRUE;
  152922. cinfo->JFIF_major_version = GETJOCTET(data[5]);
  152923. cinfo->JFIF_minor_version = GETJOCTET(data[6]);
  152924. cinfo->density_unit = GETJOCTET(data[7]);
  152925. cinfo->X_density = (GETJOCTET(data[8]) << 8) + GETJOCTET(data[9]);
  152926. cinfo->Y_density = (GETJOCTET(data[10]) << 8) + GETJOCTET(data[11]);
  152927. if (cinfo->JFIF_major_version != 1)
  152928. WARNMS2(cinfo, JWRN_JFIF_MAJOR,
  152929. cinfo->JFIF_major_version, cinfo->JFIF_minor_version);
  152930. TRACEMS5(cinfo, 1, JTRC_JFIF,
  152931. cinfo->JFIF_major_version, cinfo->JFIF_minor_version,
  152932. cinfo->X_density, cinfo->Y_density, cinfo->density_unit);
  152933. if (GETJOCTET(data[12]) | GETJOCTET(data[13]))
  152934. TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL,
  152935. GETJOCTET(data[12]), GETJOCTET(data[13]));
  152936. totallen -= APP0_DATA_LEN;
  152937. if (totallen !=
  152938. ((INT32)GETJOCTET(data[12]) * (INT32)GETJOCTET(data[13]) * (INT32) 3))
  152939. TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) totallen);
  152940. } else if (datalen >= 6 &&
  152941. GETJOCTET(data[0]) == 0x4A &&
  152942. GETJOCTET(data[1]) == 0x46 &&
  152943. GETJOCTET(data[2]) == 0x58 &&
  152944. GETJOCTET(data[3]) == 0x58 &&
  152945. GETJOCTET(data[4]) == 0) {
  152946. switch (GETJOCTET(data[5])) {
  152947. case 0x10:
  152948. TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, (int) totallen);
  152949. break;
  152950. case 0x11:
  152951. TRACEMS1(cinfo, 1, JTRC_THUMB_PALETTE, (int) totallen);
  152952. break;
  152953. case 0x13:
  152954. TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, (int) totallen);
  152955. break;
  152956. default:
  152957. TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION,
  152958. GETJOCTET(data[5]), (int) totallen);
  152959. break;
  152960. }
  152961. } else {
  152962. TRACEMS1(cinfo, 1, JTRC_APP0, (int) totallen);
  152963. }
  152964. }
  152965. LOCAL(void)
  152966. examine_app14 (j_decompress_ptr cinfo, JOCTET FAR * data,
  152967. unsigned int datalen, INT32 remaining)
  152968. {
  152969. unsigned int version, flags0, flags1, transform;
  152970. if (datalen >= APP14_DATA_LEN &&
  152971. GETJOCTET(data[0]) == 0x41 &&
  152972. GETJOCTET(data[1]) == 0x64 &&
  152973. GETJOCTET(data[2]) == 0x6F &&
  152974. GETJOCTET(data[3]) == 0x62 &&
  152975. GETJOCTET(data[4]) == 0x65) {
  152976. version = (GETJOCTET(data[5]) << 8) + GETJOCTET(data[6]);
  152977. flags0 = (GETJOCTET(data[7]) << 8) + GETJOCTET(data[8]);
  152978. flags1 = (GETJOCTET(data[9]) << 8) + GETJOCTET(data[10]);
  152979. transform = GETJOCTET(data[11]);
  152980. TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform);
  152981. cinfo->saw_Adobe_marker = TRUE;
  152982. cinfo->Adobe_transform = (UINT8) transform;
  152983. } else {
  152984. TRACEMS1(cinfo, 1, JTRC_APP14, (int) (datalen + remaining));
  152985. }
  152986. }
  152987. METHODDEF(boolean)
  152988. get_interesting_appn (j_decompress_ptr cinfo)
  152989. {
  152990. INT32 length;
  152991. JOCTET b[APPN_DATA_LEN];
  152992. unsigned int i, numtoread;
  152993. INPUT_VARS(cinfo);
  152994. INPUT_2BYTES(cinfo, length, return FALSE);
  152995. length -= 2;
  152996. if (length >= APPN_DATA_LEN)
  152997. numtoread = APPN_DATA_LEN;
  152998. else if (length > 0)
  152999. numtoread = (unsigned int) length;
  153000. else
  153001. numtoread = 0;
  153002. for (i = 0; i < numtoread; i++)
  153003. INPUT_BYTE(cinfo, b[i], return FALSE);
  153004. length -= numtoread;
  153005. switch (cinfo->unread_marker) {
  153006. case M_APP0:
  153007. examine_app0(cinfo, (JOCTET FAR *) b, numtoread, length);
  153008. break;
  153009. case M_APP14:
  153010. examine_app14(cinfo, (JOCTET FAR *) b, numtoread, length);
  153011. break;
  153012. default:
  153013. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153014. break;
  153015. }
  153016. INPUT_SYNC(cinfo);
  153017. if (length > 0)
  153018. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153019. return TRUE;
  153020. }
  153021. #ifdef SAVE_MARKERS_SUPPORTED
  153022. METHODDEF(boolean)
  153023. save_marker (j_decompress_ptr cinfo)
  153024. {
  153025. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153026. jpeg_saved_marker_ptr cur_marker = marker->cur_marker;
  153027. unsigned int bytes_read, data_length;
  153028. JOCTET FAR * data;
  153029. INT32 length = 0;
  153030. INPUT_VARS(cinfo);
  153031. if (cur_marker == NULL) {
  153032. INPUT_2BYTES(cinfo, length, return FALSE);
  153033. length -= 2;
  153034. if (length >= 0) { /* watch out for bogus length word */
  153035. unsigned int limit;
  153036. if (cinfo->unread_marker == (int) M_COM)
  153037. limit = marker->length_limit_COM;
  153038. else
  153039. limit = marker->length_limit_APPn[cinfo->unread_marker - (int) M_APP0];
  153040. if ((unsigned int) length < limit)
  153041. limit = (unsigned int) length;
  153042. cur_marker = (jpeg_saved_marker_ptr)
  153043. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153044. SIZEOF(struct jpeg_marker_struct) + limit);
  153045. cur_marker->next = NULL;
  153046. cur_marker->marker = (UINT8) cinfo->unread_marker;
  153047. cur_marker->original_length = (unsigned int) length;
  153048. cur_marker->data_length = limit;
  153049. data = cur_marker->data = (JOCTET FAR *) (cur_marker + 1);
  153050. marker->cur_marker = cur_marker;
  153051. marker->bytes_read = 0;
  153052. bytes_read = 0;
  153053. data_length = limit;
  153054. } else {
  153055. bytes_read = data_length = 0;
  153056. data = NULL;
  153057. }
  153058. } else {
  153059. bytes_read = marker->bytes_read;
  153060. data_length = cur_marker->data_length;
  153061. data = cur_marker->data + bytes_read;
  153062. }
  153063. while (bytes_read < data_length) {
  153064. INPUT_SYNC(cinfo); /* move the restart point to here */
  153065. marker->bytes_read = bytes_read;
  153066. MAKE_BYTE_AVAIL(cinfo, return FALSE);
  153067. while (bytes_read < data_length && bytes_in_buffer > 0) {
  153068. *data++ = *next_input_byte++;
  153069. bytes_in_buffer--;
  153070. bytes_read++;
  153071. }
  153072. }
  153073. if (cur_marker != NULL) { /* will be NULL if bogus length word */
  153074. if (cinfo->marker_list == NULL) {
  153075. cinfo->marker_list = cur_marker;
  153076. } else {
  153077. jpeg_saved_marker_ptr prev = cinfo->marker_list;
  153078. while (prev->next != NULL)
  153079. prev = prev->next;
  153080. prev->next = cur_marker;
  153081. }
  153082. data = cur_marker->data;
  153083. length = cur_marker->original_length - data_length;
  153084. }
  153085. marker->cur_marker = NULL;
  153086. switch (cinfo->unread_marker) {
  153087. case M_APP0:
  153088. examine_app0(cinfo, data, data_length, length);
  153089. break;
  153090. case M_APP14:
  153091. examine_app14(cinfo, data, data_length, length);
  153092. break;
  153093. default:
  153094. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker,
  153095. (int) (data_length + length));
  153096. break;
  153097. }
  153098. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153099. if (length > 0)
  153100. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153101. return TRUE;
  153102. }
  153103. #endif /* SAVE_MARKERS_SUPPORTED */
  153104. METHODDEF(boolean)
  153105. skip_variable (j_decompress_ptr cinfo)
  153106. {
  153107. INT32 length;
  153108. INPUT_VARS(cinfo);
  153109. INPUT_2BYTES(cinfo, length, return FALSE);
  153110. length -= 2;
  153111. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, (int) length);
  153112. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153113. if (length > 0)
  153114. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153115. return TRUE;
  153116. }
  153117. LOCAL(boolean)
  153118. next_marker (j_decompress_ptr cinfo)
  153119. {
  153120. int c;
  153121. INPUT_VARS(cinfo);
  153122. for (;;) {
  153123. INPUT_BYTE(cinfo, c, return FALSE);
  153124. while (c != 0xFF) {
  153125. cinfo->marker->discarded_bytes++;
  153126. INPUT_SYNC(cinfo);
  153127. INPUT_BYTE(cinfo, c, return FALSE);
  153128. }
  153129. do {
  153130. INPUT_BYTE(cinfo, c, return FALSE);
  153131. } while (c == 0xFF);
  153132. if (c != 0)
  153133. break; /* found a valid marker, exit loop */
  153134. cinfo->marker->discarded_bytes += 2;
  153135. INPUT_SYNC(cinfo);
  153136. }
  153137. if (cinfo->marker->discarded_bytes != 0) {
  153138. WARNMS2(cinfo, JWRN_EXTRANEOUS_DATA, cinfo->marker->discarded_bytes, c);
  153139. cinfo->marker->discarded_bytes = 0;
  153140. }
  153141. cinfo->unread_marker = c;
  153142. INPUT_SYNC(cinfo);
  153143. return TRUE;
  153144. }
  153145. LOCAL(boolean)
  153146. first_marker (j_decompress_ptr cinfo)
  153147. {
  153148. int c, c2;
  153149. INPUT_VARS(cinfo);
  153150. INPUT_BYTE(cinfo, c, return FALSE);
  153151. INPUT_BYTE(cinfo, c2, return FALSE);
  153152. if (c != 0xFF || c2 != (int) M_SOI)
  153153. ERREXIT2(cinfo, JERR_NO_SOI, c, c2);
  153154. cinfo->unread_marker = c2;
  153155. INPUT_SYNC(cinfo);
  153156. return TRUE;
  153157. }
  153158. METHODDEF(int)
  153159. read_markers (j_decompress_ptr cinfo)
  153160. {
  153161. for (;;) {
  153162. if (cinfo->unread_marker == 0) {
  153163. if (! cinfo->marker->saw_SOI) {
  153164. if (! first_marker(cinfo))
  153165. return JPEG_SUSPENDED;
  153166. } else {
  153167. if (! next_marker(cinfo))
  153168. return JPEG_SUSPENDED;
  153169. }
  153170. }
  153171. switch (cinfo->unread_marker) {
  153172. case M_SOI:
  153173. if (! get_soi(cinfo))
  153174. return JPEG_SUSPENDED;
  153175. break;
  153176. case M_SOF0: /* Baseline */
  153177. case M_SOF1: /* Extended sequential, Huffman */
  153178. if (! get_sof(cinfo, FALSE, FALSE))
  153179. return JPEG_SUSPENDED;
  153180. break;
  153181. case M_SOF2: /* Progressive, Huffman */
  153182. if (! get_sof(cinfo, TRUE, FALSE))
  153183. return JPEG_SUSPENDED;
  153184. break;
  153185. case M_SOF9: /* Extended sequential, arithmetic */
  153186. if (! get_sof(cinfo, FALSE, TRUE))
  153187. return JPEG_SUSPENDED;
  153188. break;
  153189. case M_SOF10: /* Progressive, arithmetic */
  153190. if (! get_sof(cinfo, TRUE, TRUE))
  153191. return JPEG_SUSPENDED;
  153192. break;
  153193. case M_SOF3: /* Lossless, Huffman */
  153194. case M_SOF5: /* Differential sequential, Huffman */
  153195. case M_SOF6: /* Differential progressive, Huffman */
  153196. case M_SOF7: /* Differential lossless, Huffman */
  153197. case M_JPG: /* Reserved for JPEG extensions */
  153198. case M_SOF11: /* Lossless, arithmetic */
  153199. case M_SOF13: /* Differential sequential, arithmetic */
  153200. case M_SOF14: /* Differential progressive, arithmetic */
  153201. case M_SOF15: /* Differential lossless, arithmetic */
  153202. ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo->unread_marker);
  153203. break;
  153204. case M_SOS:
  153205. if (! get_sos(cinfo))
  153206. return JPEG_SUSPENDED;
  153207. cinfo->unread_marker = 0; /* processed the marker */
  153208. return JPEG_REACHED_SOS;
  153209. case M_EOI:
  153210. TRACEMS(cinfo, 1, JTRC_EOI);
  153211. cinfo->unread_marker = 0; /* processed the marker */
  153212. return JPEG_REACHED_EOI;
  153213. case M_DAC:
  153214. if (! get_dac(cinfo))
  153215. return JPEG_SUSPENDED;
  153216. break;
  153217. case M_DHT:
  153218. if (! get_dht(cinfo))
  153219. return JPEG_SUSPENDED;
  153220. break;
  153221. case M_DQT:
  153222. if (! get_dqt(cinfo))
  153223. return JPEG_SUSPENDED;
  153224. break;
  153225. case M_DRI:
  153226. if (! get_dri(cinfo))
  153227. return JPEG_SUSPENDED;
  153228. break;
  153229. case M_APP0:
  153230. case M_APP1:
  153231. case M_APP2:
  153232. case M_APP3:
  153233. case M_APP4:
  153234. case M_APP5:
  153235. case M_APP6:
  153236. case M_APP7:
  153237. case M_APP8:
  153238. case M_APP9:
  153239. case M_APP10:
  153240. case M_APP11:
  153241. case M_APP12:
  153242. case M_APP13:
  153243. case M_APP14:
  153244. case M_APP15:
  153245. if (! (*((my_marker_ptr2) cinfo->marker)->process_APPn[
  153246. cinfo->unread_marker - (int) M_APP0]) (cinfo))
  153247. return JPEG_SUSPENDED;
  153248. break;
  153249. case M_COM:
  153250. if (! (*((my_marker_ptr2) cinfo->marker)->process_COM) (cinfo))
  153251. return JPEG_SUSPENDED;
  153252. break;
  153253. case M_RST0: /* these are all parameterless */
  153254. case M_RST1:
  153255. case M_RST2:
  153256. case M_RST3:
  153257. case M_RST4:
  153258. case M_RST5:
  153259. case M_RST6:
  153260. case M_RST7:
  153261. case M_TEM:
  153262. TRACEMS1(cinfo, 1, JTRC_PARMLESS_MARKER, cinfo->unread_marker);
  153263. break;
  153264. case M_DNL: /* Ignore DNL ... perhaps the wrong thing */
  153265. if (! skip_variable(cinfo))
  153266. return JPEG_SUSPENDED;
  153267. break;
  153268. default: /* must be DHP, EXP, JPGn, or RESn */
  153269. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153270. break;
  153271. }
  153272. cinfo->unread_marker = 0;
  153273. } /* end loop */
  153274. }
  153275. METHODDEF(boolean)
  153276. read_restart_marker (j_decompress_ptr cinfo)
  153277. {
  153278. if (cinfo->unread_marker == 0) {
  153279. if (! next_marker(cinfo))
  153280. return FALSE;
  153281. }
  153282. if (cinfo->unread_marker ==
  153283. ((int) M_RST0 + cinfo->marker->next_restart_num)) {
  153284. TRACEMS1(cinfo, 3, JTRC_RST, cinfo->marker->next_restart_num);
  153285. cinfo->unread_marker = 0;
  153286. } else {
  153287. if (! (*cinfo->src->resync_to_restart) (cinfo,
  153288. cinfo->marker->next_restart_num))
  153289. return FALSE;
  153290. }
  153291. cinfo->marker->next_restart_num = (cinfo->marker->next_restart_num + 1) & 7;
  153292. return TRUE;
  153293. }
  153294. GLOBAL(boolean)
  153295. jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
  153296. {
  153297. int marker = cinfo->unread_marker;
  153298. int action = 1;
  153299. WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired);
  153300. for (;;) {
  153301. if (marker < (int) M_SOF0)
  153302. action = 2; /* invalid marker */
  153303. else if (marker < (int) M_RST0 || marker > (int) M_RST7)
  153304. action = 3; /* valid non-restart marker */
  153305. else {
  153306. if (marker == ((int) M_RST0 + ((desired+1) & 7)) ||
  153307. marker == ((int) M_RST0 + ((desired+2) & 7)))
  153308. action = 3; /* one of the next two expected restarts */
  153309. else if (marker == ((int) M_RST0 + ((desired-1) & 7)) ||
  153310. marker == ((int) M_RST0 + ((desired-2) & 7)))
  153311. action = 2; /* a prior restart, so advance */
  153312. else
  153313. action = 1; /* desired restart or too far away */
  153314. }
  153315. TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action);
  153316. switch (action) {
  153317. case 1:
  153318. cinfo->unread_marker = 0;
  153319. return TRUE;
  153320. case 2:
  153321. if (! next_marker(cinfo))
  153322. return FALSE;
  153323. marker = cinfo->unread_marker;
  153324. break;
  153325. case 3:
  153326. return TRUE;
  153327. }
  153328. } /* end loop */
  153329. }
  153330. METHODDEF(void)
  153331. reset_marker_reader (j_decompress_ptr cinfo)
  153332. {
  153333. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153334. cinfo->comp_info = NULL; /* until allocated by get_sof */
  153335. cinfo->input_scan_number = 0; /* no SOS seen yet */
  153336. cinfo->unread_marker = 0; /* no pending marker */
  153337. marker->pub.saw_SOI = FALSE; /* set internal state too */
  153338. marker->pub.saw_SOF = FALSE;
  153339. marker->pub.discarded_bytes = 0;
  153340. marker->cur_marker = NULL;
  153341. }
  153342. GLOBAL(void)
  153343. jinit_marker_reader (j_decompress_ptr cinfo)
  153344. {
  153345. my_marker_ptr2 marker;
  153346. int i;
  153347. marker = (my_marker_ptr2)
  153348. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  153349. SIZEOF(my_marker_reader));
  153350. cinfo->marker = (struct jpeg_marker_reader *) marker;
  153351. marker->pub.reset_marker_reader = reset_marker_reader;
  153352. marker->pub.read_markers = read_markers;
  153353. marker->pub.read_restart_marker = read_restart_marker;
  153354. marker->process_COM = skip_variable;
  153355. marker->length_limit_COM = 0;
  153356. for (i = 0; i < 16; i++) {
  153357. marker->process_APPn[i] = skip_variable;
  153358. marker->length_limit_APPn[i] = 0;
  153359. }
  153360. marker->process_APPn[0] = get_interesting_appn;
  153361. marker->process_APPn[14] = get_interesting_appn;
  153362. reset_marker_reader(cinfo);
  153363. }
  153364. #ifdef SAVE_MARKERS_SUPPORTED
  153365. GLOBAL(void)
  153366. jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
  153367. unsigned int length_limit)
  153368. {
  153369. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153370. long maxlength;
  153371. jpeg_marker_parser_method processor;
  153372. maxlength = cinfo->mem->max_alloc_chunk - SIZEOF(struct jpeg_marker_struct);
  153373. if (((long) length_limit) > maxlength)
  153374. length_limit = (unsigned int) maxlength;
  153375. if (length_limit) {
  153376. processor = save_marker;
  153377. if (marker_code == (int) M_APP0 && length_limit < APP0_DATA_LEN)
  153378. length_limit = APP0_DATA_LEN;
  153379. else if (marker_code == (int) M_APP14 && length_limit < APP14_DATA_LEN)
  153380. length_limit = APP14_DATA_LEN;
  153381. } else {
  153382. processor = skip_variable;
  153383. if (marker_code == (int) M_APP0 || marker_code == (int) M_APP14)
  153384. processor = get_interesting_appn;
  153385. }
  153386. if (marker_code == (int) M_COM) {
  153387. marker->process_COM = processor;
  153388. marker->length_limit_COM = length_limit;
  153389. } else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15) {
  153390. marker->process_APPn[marker_code - (int) M_APP0] = processor;
  153391. marker->length_limit_APPn[marker_code - (int) M_APP0] = length_limit;
  153392. } else
  153393. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153394. }
  153395. #endif /* SAVE_MARKERS_SUPPORTED */
  153396. GLOBAL(void)
  153397. jpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code,
  153398. jpeg_marker_parser_method routine)
  153399. {
  153400. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153401. if (marker_code == (int) M_COM)
  153402. marker->process_COM = routine;
  153403. else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15)
  153404. marker->process_APPn[marker_code - (int) M_APP0] = routine;
  153405. else
  153406. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153407. }
  153408. /*** End of inlined file: jdmarker.c ***/
  153409. /*** Start of inlined file: jdmaster.c ***/
  153410. #define JPEG_INTERNALS
  153411. typedef struct {
  153412. struct jpeg_decomp_master pub; /* public fields */
  153413. int pass_number; /* # of passes completed */
  153414. boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */
  153415. struct jpeg_color_quantizer * quantizer_1pass;
  153416. struct jpeg_color_quantizer * quantizer_2pass;
  153417. } my_decomp_master;
  153418. typedef my_decomp_master * my_master_ptr6;
  153419. LOCAL(boolean)
  153420. use_merged_upsample (j_decompress_ptr cinfo)
  153421. {
  153422. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153423. if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling)
  153424. return FALSE;
  153425. if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 ||
  153426. cinfo->out_color_space != JCS_RGB ||
  153427. cinfo->out_color_components != RGB_PIXELSIZE)
  153428. return FALSE;
  153429. if (cinfo->comp_info[0].h_samp_factor != 2 ||
  153430. cinfo->comp_info[1].h_samp_factor != 1 ||
  153431. cinfo->comp_info[2].h_samp_factor != 1 ||
  153432. cinfo->comp_info[0].v_samp_factor > 2 ||
  153433. cinfo->comp_info[1].v_samp_factor != 1 ||
  153434. cinfo->comp_info[2].v_samp_factor != 1)
  153435. return FALSE;
  153436. if (cinfo->comp_info[0].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153437. cinfo->comp_info[1].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153438. cinfo->comp_info[2].DCT_scaled_size != cinfo->min_DCT_scaled_size)
  153439. return FALSE;
  153440. return TRUE; /* by golly, it'll work... */
  153441. #else
  153442. return FALSE;
  153443. #endif
  153444. }
  153445. GLOBAL(void)
  153446. jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
  153447. {
  153448. #ifdef IDCT_SCALING_SUPPORTED
  153449. int ci;
  153450. jpeg_component_info *compptr;
  153451. #endif
  153452. if (cinfo->global_state != DSTATE_READY)
  153453. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  153454. #ifdef IDCT_SCALING_SUPPORTED
  153455. if (cinfo->scale_num * 8 <= cinfo->scale_denom) {
  153456. cinfo->output_width = (JDIMENSION)
  153457. jdiv_round_up((long) cinfo->image_width, 8L);
  153458. cinfo->output_height = (JDIMENSION)
  153459. jdiv_round_up((long) cinfo->image_height, 8L);
  153460. cinfo->min_DCT_scaled_size = 1;
  153461. } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
  153462. cinfo->output_width = (JDIMENSION)
  153463. jdiv_round_up((long) cinfo->image_width, 4L);
  153464. cinfo->output_height = (JDIMENSION)
  153465. jdiv_round_up((long) cinfo->image_height, 4L);
  153466. cinfo->min_DCT_scaled_size = 2;
  153467. } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
  153468. cinfo->output_width = (JDIMENSION)
  153469. jdiv_round_up((long) cinfo->image_width, 2L);
  153470. cinfo->output_height = (JDIMENSION)
  153471. jdiv_round_up((long) cinfo->image_height, 2L);
  153472. cinfo->min_DCT_scaled_size = 4;
  153473. } else {
  153474. cinfo->output_width = cinfo->image_width;
  153475. cinfo->output_height = cinfo->image_height;
  153476. cinfo->min_DCT_scaled_size = DCTSIZE;
  153477. }
  153478. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153479. ci++, compptr++) {
  153480. int ssize = cinfo->min_DCT_scaled_size;
  153481. while (ssize < DCTSIZE &&
  153482. (compptr->h_samp_factor * ssize * 2 <=
  153483. cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) &&
  153484. (compptr->v_samp_factor * ssize * 2 <=
  153485. cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) {
  153486. ssize = ssize * 2;
  153487. }
  153488. compptr->DCT_scaled_size = ssize;
  153489. }
  153490. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153491. ci++, compptr++) {
  153492. compptr->downsampled_width = (JDIMENSION)
  153493. jdiv_round_up((long) cinfo->image_width *
  153494. (long) (compptr->h_samp_factor * compptr->DCT_scaled_size),
  153495. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  153496. compptr->downsampled_height = (JDIMENSION)
  153497. jdiv_round_up((long) cinfo->image_height *
  153498. (long) (compptr->v_samp_factor * compptr->DCT_scaled_size),
  153499. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  153500. }
  153501. #else /* !IDCT_SCALING_SUPPORTED */
  153502. cinfo->output_width = cinfo->image_width;
  153503. cinfo->output_height = cinfo->image_height;
  153504. #endif /* IDCT_SCALING_SUPPORTED */
  153505. switch (cinfo->out_color_space) {
  153506. case JCS_GRAYSCALE:
  153507. cinfo->out_color_components = 1;
  153508. break;
  153509. case JCS_RGB:
  153510. #if RGB_PIXELSIZE != 3
  153511. cinfo->out_color_components = RGB_PIXELSIZE;
  153512. break;
  153513. #endif /* else share code with YCbCr */
  153514. case JCS_YCbCr:
  153515. cinfo->out_color_components = 3;
  153516. break;
  153517. case JCS_CMYK:
  153518. case JCS_YCCK:
  153519. cinfo->out_color_components = 4;
  153520. break;
  153521. default: /* else must be same colorspace as in file */
  153522. cinfo->out_color_components = cinfo->num_components;
  153523. break;
  153524. }
  153525. cinfo->output_components = (cinfo->quantize_colors ? 1 :
  153526. cinfo->out_color_components);
  153527. if (use_merged_upsample(cinfo))
  153528. cinfo->rec_outbuf_height = cinfo->max_v_samp_factor;
  153529. else
  153530. cinfo->rec_outbuf_height = 1;
  153531. }
  153532. LOCAL(void)
  153533. prepare_range_limit_table (j_decompress_ptr cinfo)
  153534. {
  153535. JSAMPLE * table;
  153536. int i;
  153537. table = (JSAMPLE *)
  153538. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153539. (5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  153540. table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */
  153541. cinfo->sample_range_limit = table;
  153542. MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));
  153543. for (i = 0; i <= MAXJSAMPLE; i++)
  153544. table[i] = (JSAMPLE) i;
  153545. table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
  153546. for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++)
  153547. table[i] = MAXJSAMPLE;
  153548. MEMZERO(table + (2 * (MAXJSAMPLE+1)),
  153549. (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  153550. MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE),
  153551. cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE));
  153552. }
  153553. LOCAL(void)
  153554. master_selection (j_decompress_ptr cinfo)
  153555. {
  153556. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153557. boolean use_c_buffer;
  153558. long samplesperrow;
  153559. JDIMENSION jd_samplesperrow;
  153560. jpeg_calc_output_dimensions(cinfo);
  153561. prepare_range_limit_table(cinfo);
  153562. samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components;
  153563. jd_samplesperrow = (JDIMENSION) samplesperrow;
  153564. if ((long) jd_samplesperrow != samplesperrow)
  153565. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  153566. master->pass_number = 0;
  153567. master->using_merged_upsample = use_merged_upsample(cinfo);
  153568. master->quantizer_1pass = NULL;
  153569. master->quantizer_2pass = NULL;
  153570. if (! cinfo->quantize_colors || ! cinfo->buffered_image) {
  153571. cinfo->enable_1pass_quant = FALSE;
  153572. cinfo->enable_external_quant = FALSE;
  153573. cinfo->enable_2pass_quant = FALSE;
  153574. }
  153575. if (cinfo->quantize_colors) {
  153576. if (cinfo->raw_data_out)
  153577. ERREXIT(cinfo, JERR_NOTIMPL);
  153578. if (cinfo->out_color_components != 3) {
  153579. cinfo->enable_1pass_quant = TRUE;
  153580. cinfo->enable_external_quant = FALSE;
  153581. cinfo->enable_2pass_quant = FALSE;
  153582. cinfo->colormap = NULL;
  153583. } else if (cinfo->colormap != NULL) {
  153584. cinfo->enable_external_quant = TRUE;
  153585. } else if (cinfo->two_pass_quantize) {
  153586. cinfo->enable_2pass_quant = TRUE;
  153587. } else {
  153588. cinfo->enable_1pass_quant = TRUE;
  153589. }
  153590. if (cinfo->enable_1pass_quant) {
  153591. #ifdef QUANT_1PASS_SUPPORTED
  153592. jinit_1pass_quantizer(cinfo);
  153593. master->quantizer_1pass = cinfo->cquantize;
  153594. #else
  153595. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153596. #endif
  153597. }
  153598. if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) {
  153599. #ifdef QUANT_2PASS_SUPPORTED
  153600. jinit_2pass_quantizer(cinfo);
  153601. master->quantizer_2pass = cinfo->cquantize;
  153602. #else
  153603. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153604. #endif
  153605. }
  153606. }
  153607. if (! cinfo->raw_data_out) {
  153608. if (master->using_merged_upsample) {
  153609. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153610. jinit_merged_upsampler(cinfo); /* does color conversion too */
  153611. #else
  153612. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153613. #endif
  153614. } else {
  153615. jinit_color_deconverter(cinfo);
  153616. jinit_upsampler(cinfo);
  153617. }
  153618. jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
  153619. }
  153620. jinit_inverse_dct(cinfo);
  153621. if (cinfo->arith_code) {
  153622. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  153623. } else {
  153624. if (cinfo->progressive_mode) {
  153625. #ifdef D_PROGRESSIVE_SUPPORTED
  153626. jinit_phuff_decoder(cinfo);
  153627. #else
  153628. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153629. #endif
  153630. } else
  153631. jinit_huff_decoder(cinfo);
  153632. }
  153633. use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image;
  153634. jinit_d_coef_controller(cinfo, use_c_buffer);
  153635. if (! cinfo->raw_data_out)
  153636. jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
  153637. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  153638. (*cinfo->inputctl->start_input_pass) (cinfo);
  153639. #ifdef D_MULTISCAN_FILES_SUPPORTED
  153640. if (cinfo->progress != NULL && ! cinfo->buffered_image &&
  153641. cinfo->inputctl->has_multiple_scans) {
  153642. int nscans;
  153643. if (cinfo->progressive_mode) {
  153644. nscans = 2 + 3 * cinfo->num_components;
  153645. } else {
  153646. nscans = cinfo->num_components;
  153647. }
  153648. cinfo->progress->pass_counter = 0L;
  153649. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  153650. cinfo->progress->completed_passes = 0;
  153651. cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2);
  153652. master->pass_number++;
  153653. }
  153654. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  153655. }
  153656. METHODDEF(void)
  153657. prepare_for_output_pass (j_decompress_ptr cinfo)
  153658. {
  153659. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153660. if (master->pub.is_dummy_pass) {
  153661. #ifdef QUANT_2PASS_SUPPORTED
  153662. master->pub.is_dummy_pass = FALSE;
  153663. (*cinfo->cquantize->start_pass) (cinfo, FALSE);
  153664. (*cinfo->post->start_pass) (cinfo, JBUF_CRANK_DEST);
  153665. (*cinfo->main->start_pass) (cinfo, JBUF_CRANK_DEST);
  153666. #else
  153667. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153668. #endif /* QUANT_2PASS_SUPPORTED */
  153669. } else {
  153670. if (cinfo->quantize_colors && cinfo->colormap == NULL) {
  153671. if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) {
  153672. cinfo->cquantize = master->quantizer_2pass;
  153673. master->pub.is_dummy_pass = TRUE;
  153674. } else if (cinfo->enable_1pass_quant) {
  153675. cinfo->cquantize = master->quantizer_1pass;
  153676. } else {
  153677. ERREXIT(cinfo, JERR_MODE_CHANGE);
  153678. }
  153679. }
  153680. (*cinfo->idct->start_pass) (cinfo);
  153681. (*cinfo->coef->start_output_pass) (cinfo);
  153682. if (! cinfo->raw_data_out) {
  153683. if (! master->using_merged_upsample)
  153684. (*cinfo->cconvert->start_pass) (cinfo);
  153685. (*cinfo->upsample->start_pass) (cinfo);
  153686. if (cinfo->quantize_colors)
  153687. (*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass);
  153688. (*cinfo->post->start_pass) (cinfo,
  153689. (master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  153690. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  153691. }
  153692. }
  153693. if (cinfo->progress != NULL) {
  153694. cinfo->progress->completed_passes = master->pass_number;
  153695. cinfo->progress->total_passes = master->pass_number +
  153696. (master->pub.is_dummy_pass ? 2 : 1);
  153697. if (cinfo->buffered_image && ! cinfo->inputctl->eoi_reached) {
  153698. cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1);
  153699. }
  153700. }
  153701. }
  153702. METHODDEF(void)
  153703. finish_output_pass (j_decompress_ptr cinfo)
  153704. {
  153705. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153706. if (cinfo->quantize_colors)
  153707. (*cinfo->cquantize->finish_pass) (cinfo);
  153708. master->pass_number++;
  153709. }
  153710. #ifdef D_MULTISCAN_FILES_SUPPORTED
  153711. GLOBAL(void)
  153712. jpeg_new_colormap (j_decompress_ptr cinfo)
  153713. {
  153714. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153715. if (cinfo->global_state != DSTATE_BUFIMAGE)
  153716. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  153717. if (cinfo->quantize_colors && cinfo->enable_external_quant &&
  153718. cinfo->colormap != NULL) {
  153719. cinfo->cquantize = master->quantizer_2pass;
  153720. (*cinfo->cquantize->new_color_map) (cinfo);
  153721. master->pub.is_dummy_pass = FALSE; /* just in case */
  153722. } else
  153723. ERREXIT(cinfo, JERR_MODE_CHANGE);
  153724. }
  153725. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  153726. GLOBAL(void)
  153727. jinit_master_decompress (j_decompress_ptr cinfo)
  153728. {
  153729. my_master_ptr6 master;
  153730. master = (my_master_ptr6)
  153731. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153732. SIZEOF(my_decomp_master));
  153733. cinfo->master = (struct jpeg_decomp_master *) master;
  153734. master->pub.prepare_for_output_pass = prepare_for_output_pass;
  153735. master->pub.finish_output_pass = finish_output_pass;
  153736. master->pub.is_dummy_pass = FALSE;
  153737. master_selection(cinfo);
  153738. }
  153739. /*** End of inlined file: jdmaster.c ***/
  153740. #undef FIX
  153741. /*** Start of inlined file: jdmerge.c ***/
  153742. #define JPEG_INTERNALS
  153743. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153744. typedef struct {
  153745. struct jpeg_upsampler pub; /* public fields */
  153746. JMETHOD(void, upmethod, (j_decompress_ptr cinfo,
  153747. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153748. JSAMPARRAY output_buf));
  153749. int * Cr_r_tab; /* => table for Cr to R conversion */
  153750. int * Cb_b_tab; /* => table for Cb to B conversion */
  153751. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  153752. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  153753. JSAMPROW spare_row;
  153754. boolean spare_full; /* T if spare buffer is occupied */
  153755. JDIMENSION out_row_width; /* samples per output row */
  153756. JDIMENSION rows_to_go; /* counts rows remaining in image */
  153757. } my_upsampler;
  153758. typedef my_upsampler * my_upsample_ptr;
  153759. #define SCALEBITS 16 /* speediest right-shift on some machines */
  153760. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  153761. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  153762. LOCAL(void)
  153763. build_ycc_rgb_table2 (j_decompress_ptr cinfo)
  153764. {
  153765. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153766. int i;
  153767. INT32 x;
  153768. SHIFT_TEMPS
  153769. upsample->Cr_r_tab = (int *)
  153770. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153771. (MAXJSAMPLE+1) * SIZEOF(int));
  153772. upsample->Cb_b_tab = (int *)
  153773. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153774. (MAXJSAMPLE+1) * SIZEOF(int));
  153775. upsample->Cr_g_tab = (INT32 *)
  153776. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153777. (MAXJSAMPLE+1) * SIZEOF(INT32));
  153778. upsample->Cb_g_tab = (INT32 *)
  153779. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153780. (MAXJSAMPLE+1) * SIZEOF(INT32));
  153781. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  153782. upsample->Cr_r_tab[i] = (int)
  153783. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  153784. upsample->Cb_b_tab[i] = (int)
  153785. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  153786. upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  153787. upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  153788. }
  153789. }
  153790. METHODDEF(void)
  153791. start_pass_merged_upsample (j_decompress_ptr cinfo)
  153792. {
  153793. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153794. upsample->spare_full = FALSE;
  153795. upsample->rows_to_go = cinfo->output_height;
  153796. }
  153797. METHODDEF(void)
  153798. merged_2v_upsample (j_decompress_ptr cinfo,
  153799. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  153800. JDIMENSION in_row_groups_avail,
  153801. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153802. JDIMENSION out_rows_avail)
  153803. {
  153804. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153805. JSAMPROW work_ptrs[2];
  153806. JDIMENSION num_rows; /* number of rows returned to caller */
  153807. if (upsample->spare_full) {
  153808. jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
  153809. 1, upsample->out_row_width);
  153810. num_rows = 1;
  153811. upsample->spare_full = FALSE;
  153812. } else {
  153813. num_rows = 2;
  153814. if (num_rows > upsample->rows_to_go)
  153815. num_rows = upsample->rows_to_go;
  153816. out_rows_avail -= *out_row_ctr;
  153817. if (num_rows > out_rows_avail)
  153818. num_rows = out_rows_avail;
  153819. work_ptrs[0] = output_buf[*out_row_ctr];
  153820. if (num_rows > 1) {
  153821. work_ptrs[1] = output_buf[*out_row_ctr + 1];
  153822. } else {
  153823. work_ptrs[1] = upsample->spare_row;
  153824. upsample->spare_full = TRUE;
  153825. }
  153826. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs);
  153827. }
  153828. *out_row_ctr += num_rows;
  153829. upsample->rows_to_go -= num_rows;
  153830. if (! upsample->spare_full)
  153831. (*in_row_group_ctr)++;
  153832. }
  153833. METHODDEF(void)
  153834. merged_1v_upsample (j_decompress_ptr cinfo,
  153835. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  153836. JDIMENSION in_row_groups_avail,
  153837. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153838. JDIMENSION out_rows_avail)
  153839. {
  153840. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153841. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
  153842. output_buf + *out_row_ctr);
  153843. (*out_row_ctr)++;
  153844. (*in_row_group_ctr)++;
  153845. }
  153846. METHODDEF(void)
  153847. h2v1_merged_upsample (j_decompress_ptr cinfo,
  153848. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153849. JSAMPARRAY output_buf)
  153850. {
  153851. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153852. register int y, cred, cgreen, cblue;
  153853. int cb, cr;
  153854. register JSAMPROW outptr;
  153855. JSAMPROW inptr0, inptr1, inptr2;
  153856. JDIMENSION col;
  153857. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  153858. int * Crrtab = upsample->Cr_r_tab;
  153859. int * Cbbtab = upsample->Cb_b_tab;
  153860. INT32 * Crgtab = upsample->Cr_g_tab;
  153861. INT32 * Cbgtab = upsample->Cb_g_tab;
  153862. SHIFT_TEMPS
  153863. inptr0 = input_buf[0][in_row_group_ctr];
  153864. inptr1 = input_buf[1][in_row_group_ctr];
  153865. inptr2 = input_buf[2][in_row_group_ctr];
  153866. outptr = output_buf[0];
  153867. for (col = cinfo->output_width >> 1; col > 0; col--) {
  153868. cb = GETJSAMPLE(*inptr1++);
  153869. cr = GETJSAMPLE(*inptr2++);
  153870. cred = Crrtab[cr];
  153871. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153872. cblue = Cbbtab[cb];
  153873. y = GETJSAMPLE(*inptr0++);
  153874. outptr[RGB_RED] = range_limit[y + cred];
  153875. outptr[RGB_GREEN] = range_limit[y + cgreen];
  153876. outptr[RGB_BLUE] = range_limit[y + cblue];
  153877. outptr += RGB_PIXELSIZE;
  153878. y = GETJSAMPLE(*inptr0++);
  153879. outptr[RGB_RED] = range_limit[y + cred];
  153880. outptr[RGB_GREEN] = range_limit[y + cgreen];
  153881. outptr[RGB_BLUE] = range_limit[y + cblue];
  153882. outptr += RGB_PIXELSIZE;
  153883. }
  153884. if (cinfo->output_width & 1) {
  153885. cb = GETJSAMPLE(*inptr1);
  153886. cr = GETJSAMPLE(*inptr2);
  153887. cred = Crrtab[cr];
  153888. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153889. cblue = Cbbtab[cb];
  153890. y = GETJSAMPLE(*inptr0);
  153891. outptr[RGB_RED] = range_limit[y + cred];
  153892. outptr[RGB_GREEN] = range_limit[y + cgreen];
  153893. outptr[RGB_BLUE] = range_limit[y + cblue];
  153894. }
  153895. }
  153896. METHODDEF(void)
  153897. h2v2_merged_upsample (j_decompress_ptr cinfo,
  153898. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153899. JSAMPARRAY output_buf)
  153900. {
  153901. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153902. register int y, cred, cgreen, cblue;
  153903. int cb, cr;
  153904. register JSAMPROW outptr0, outptr1;
  153905. JSAMPROW inptr00, inptr01, inptr1, inptr2;
  153906. JDIMENSION col;
  153907. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  153908. int * Crrtab = upsample->Cr_r_tab;
  153909. int * Cbbtab = upsample->Cb_b_tab;
  153910. INT32 * Crgtab = upsample->Cr_g_tab;
  153911. INT32 * Cbgtab = upsample->Cb_g_tab;
  153912. SHIFT_TEMPS
  153913. inptr00 = input_buf[0][in_row_group_ctr*2];
  153914. inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
  153915. inptr1 = input_buf[1][in_row_group_ctr];
  153916. inptr2 = input_buf[2][in_row_group_ctr];
  153917. outptr0 = output_buf[0];
  153918. outptr1 = output_buf[1];
  153919. for (col = cinfo->output_width >> 1; col > 0; col--) {
  153920. cb = GETJSAMPLE(*inptr1++);
  153921. cr = GETJSAMPLE(*inptr2++);
  153922. cred = Crrtab[cr];
  153923. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153924. cblue = Cbbtab[cb];
  153925. y = GETJSAMPLE(*inptr00++);
  153926. outptr0[RGB_RED] = range_limit[y + cred];
  153927. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  153928. outptr0[RGB_BLUE] = range_limit[y + cblue];
  153929. outptr0 += RGB_PIXELSIZE;
  153930. y = GETJSAMPLE(*inptr00++);
  153931. outptr0[RGB_RED] = range_limit[y + cred];
  153932. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  153933. outptr0[RGB_BLUE] = range_limit[y + cblue];
  153934. outptr0 += RGB_PIXELSIZE;
  153935. y = GETJSAMPLE(*inptr01++);
  153936. outptr1[RGB_RED] = range_limit[y + cred];
  153937. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  153938. outptr1[RGB_BLUE] = range_limit[y + cblue];
  153939. outptr1 += RGB_PIXELSIZE;
  153940. y = GETJSAMPLE(*inptr01++);
  153941. outptr1[RGB_RED] = range_limit[y + cred];
  153942. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  153943. outptr1[RGB_BLUE] = range_limit[y + cblue];
  153944. outptr1 += RGB_PIXELSIZE;
  153945. }
  153946. if (cinfo->output_width & 1) {
  153947. cb = GETJSAMPLE(*inptr1);
  153948. cr = GETJSAMPLE(*inptr2);
  153949. cred = Crrtab[cr];
  153950. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153951. cblue = Cbbtab[cb];
  153952. y = GETJSAMPLE(*inptr00);
  153953. outptr0[RGB_RED] = range_limit[y + cred];
  153954. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  153955. outptr0[RGB_BLUE] = range_limit[y + cblue];
  153956. y = GETJSAMPLE(*inptr01);
  153957. outptr1[RGB_RED] = range_limit[y + cred];
  153958. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  153959. outptr1[RGB_BLUE] = range_limit[y + cblue];
  153960. }
  153961. }
  153962. GLOBAL(void)
  153963. jinit_merged_upsampler (j_decompress_ptr cinfo)
  153964. {
  153965. my_upsample_ptr upsample;
  153966. upsample = (my_upsample_ptr)
  153967. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153968. SIZEOF(my_upsampler));
  153969. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  153970. upsample->pub.start_pass = start_pass_merged_upsample;
  153971. upsample->pub.need_context_rows = FALSE;
  153972. upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
  153973. if (cinfo->max_v_samp_factor == 2) {
  153974. upsample->pub.upsample = merged_2v_upsample;
  153975. upsample->upmethod = h2v2_merged_upsample;
  153976. upsample->spare_row = (JSAMPROW)
  153977. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153978. (size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
  153979. } else {
  153980. upsample->pub.upsample = merged_1v_upsample;
  153981. upsample->upmethod = h2v1_merged_upsample;
  153982. upsample->spare_row = NULL;
  153983. }
  153984. build_ycc_rgb_table2(cinfo);
  153985. }
  153986. #endif /* UPSAMPLE_MERGING_SUPPORTED */
  153987. /*** End of inlined file: jdmerge.c ***/
  153988. #undef ASSIGN_STATE
  153989. /*** Start of inlined file: jdphuff.c ***/
  153990. #define JPEG_INTERNALS
  153991. #ifdef D_PROGRESSIVE_SUPPORTED
  153992. typedef struct {
  153993. unsigned int EOBRUN; /* remaining EOBs in EOBRUN */
  153994. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  153995. } savable_state3;
  153996. #ifndef NO_STRUCT_ASSIGN
  153997. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  153998. #else
  153999. #if MAX_COMPS_IN_SCAN == 4
  154000. #define ASSIGN_STATE(dest,src) \
  154001. ((dest).EOBRUN = (src).EOBRUN, \
  154002. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  154003. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  154004. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  154005. (dest).last_dc_val[3] = (src).last_dc_val[3])
  154006. #endif
  154007. #endif
  154008. typedef struct {
  154009. struct jpeg_entropy_decoder pub; /* public fields */
  154010. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  154011. savable_state3 saved; /* Other state at start of MCU */
  154012. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  154013. d_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  154014. d_derived_tbl * ac_derived_tbl; /* active table during an AC scan */
  154015. } phuff_entropy_decoder;
  154016. typedef phuff_entropy_decoder * phuff_entropy_ptr2;
  154017. METHODDEF(boolean) decode_mcu_DC_first JPP((j_decompress_ptr cinfo,
  154018. JBLOCKROW *MCU_data));
  154019. METHODDEF(boolean) decode_mcu_AC_first JPP((j_decompress_ptr cinfo,
  154020. JBLOCKROW *MCU_data));
  154021. METHODDEF(boolean) decode_mcu_DC_refine JPP((j_decompress_ptr cinfo,
  154022. JBLOCKROW *MCU_data));
  154023. METHODDEF(boolean) decode_mcu_AC_refine JPP((j_decompress_ptr cinfo,
  154024. JBLOCKROW *MCU_data));
  154025. METHODDEF(void)
  154026. start_pass_phuff_decoder (j_decompress_ptr cinfo)
  154027. {
  154028. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154029. boolean is_DC_band, bad;
  154030. int ci, coefi, tbl;
  154031. int *coef_bit_ptr;
  154032. jpeg_component_info * compptr;
  154033. is_DC_band = (cinfo->Ss == 0);
  154034. bad = FALSE;
  154035. if (is_DC_band) {
  154036. if (cinfo->Se != 0)
  154037. bad = TRUE;
  154038. } else {
  154039. if (cinfo->Ss > cinfo->Se || cinfo->Se >= DCTSIZE2)
  154040. bad = TRUE;
  154041. if (cinfo->comps_in_scan != 1)
  154042. bad = TRUE;
  154043. }
  154044. if (cinfo->Ah != 0) {
  154045. if (cinfo->Al != cinfo->Ah-1)
  154046. bad = TRUE;
  154047. }
  154048. if (cinfo->Al > 13) /* need not check for < 0 */
  154049. bad = TRUE;
  154050. if (bad)
  154051. ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
  154052. cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
  154053. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154054. int cindex = cinfo->cur_comp_info[ci]->component_index;
  154055. coef_bit_ptr = & cinfo->coef_bits[cindex][0];
  154056. if (!is_DC_band && coef_bit_ptr[0] < 0) /* AC without prior DC scan */
  154057. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
  154058. for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
  154059. int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
  154060. if (cinfo->Ah != expected)
  154061. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
  154062. coef_bit_ptr[coefi] = cinfo->Al;
  154063. }
  154064. }
  154065. if (cinfo->Ah == 0) {
  154066. if (is_DC_band)
  154067. entropy->pub.decode_mcu = decode_mcu_DC_first;
  154068. else
  154069. entropy->pub.decode_mcu = decode_mcu_AC_first;
  154070. } else {
  154071. if (is_DC_band)
  154072. entropy->pub.decode_mcu = decode_mcu_DC_refine;
  154073. else
  154074. entropy->pub.decode_mcu = decode_mcu_AC_refine;
  154075. }
  154076. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154077. compptr = cinfo->cur_comp_info[ci];
  154078. if (is_DC_band) {
  154079. if (cinfo->Ah == 0) { /* DC refinement needs no table */
  154080. tbl = compptr->dc_tbl_no;
  154081. jpeg_make_d_derived_tbl(cinfo, TRUE, tbl,
  154082. & entropy->derived_tbls[tbl]);
  154083. }
  154084. } else {
  154085. tbl = compptr->ac_tbl_no;
  154086. jpeg_make_d_derived_tbl(cinfo, FALSE, tbl,
  154087. & entropy->derived_tbls[tbl]);
  154088. entropy->ac_derived_tbl = entropy->derived_tbls[tbl];
  154089. }
  154090. entropy->saved.last_dc_val[ci] = 0;
  154091. }
  154092. entropy->bitstate.bits_left = 0;
  154093. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  154094. entropy->pub.insufficient_data = FALSE;
  154095. entropy->saved.EOBRUN = 0;
  154096. entropy->restarts_to_go = cinfo->restart_interval;
  154097. }
  154098. LOCAL(boolean)
  154099. process_restartp (j_decompress_ptr cinfo)
  154100. {
  154101. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154102. int ci;
  154103. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  154104. entropy->bitstate.bits_left = 0;
  154105. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  154106. return FALSE;
  154107. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  154108. entropy->saved.last_dc_val[ci] = 0;
  154109. entropy->saved.EOBRUN = 0;
  154110. entropy->restarts_to_go = cinfo->restart_interval;
  154111. if (cinfo->unread_marker == 0)
  154112. entropy->pub.insufficient_data = FALSE;
  154113. return TRUE;
  154114. }
  154115. METHODDEF(boolean)
  154116. decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154117. {
  154118. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154119. int Al = cinfo->Al;
  154120. register int s, r;
  154121. int blkn, ci;
  154122. JBLOCKROW block;
  154123. BITREAD_STATE_VARS;
  154124. savable_state3 state;
  154125. d_derived_tbl * tbl;
  154126. jpeg_component_info * compptr;
  154127. if (cinfo->restart_interval) {
  154128. if (entropy->restarts_to_go == 0)
  154129. if (! process_restartp(cinfo))
  154130. return FALSE;
  154131. }
  154132. if (! entropy->pub.insufficient_data) {
  154133. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154134. ASSIGN_STATE(state, entropy->saved);
  154135. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154136. block = MCU_data[blkn];
  154137. ci = cinfo->MCU_membership[blkn];
  154138. compptr = cinfo->cur_comp_info[ci];
  154139. tbl = entropy->derived_tbls[compptr->dc_tbl_no];
  154140. HUFF_DECODE(s, br_state, tbl, return FALSE, label1);
  154141. if (s) {
  154142. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154143. r = GET_BITS(s);
  154144. s = HUFF_EXTEND(r, s);
  154145. }
  154146. s += state.last_dc_val[ci];
  154147. state.last_dc_val[ci] = s;
  154148. (*block)[0] = (JCOEF) (s << Al);
  154149. }
  154150. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154151. ASSIGN_STATE(entropy->saved, state);
  154152. }
  154153. entropy->restarts_to_go--;
  154154. return TRUE;
  154155. }
  154156. METHODDEF(boolean)
  154157. decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154158. {
  154159. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154160. int Se = cinfo->Se;
  154161. int Al = cinfo->Al;
  154162. register int s, k, r;
  154163. unsigned int EOBRUN;
  154164. JBLOCKROW block;
  154165. BITREAD_STATE_VARS;
  154166. d_derived_tbl * tbl;
  154167. if (cinfo->restart_interval) {
  154168. if (entropy->restarts_to_go == 0)
  154169. if (! process_restartp(cinfo))
  154170. return FALSE;
  154171. }
  154172. if (! entropy->pub.insufficient_data) {
  154173. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154174. if (EOBRUN > 0) /* if it's a band of zeroes... */
  154175. EOBRUN--; /* ...process it now (we do nothing) */
  154176. else {
  154177. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154178. block = MCU_data[0];
  154179. tbl = entropy->ac_derived_tbl;
  154180. for (k = cinfo->Ss; k <= Se; k++) {
  154181. HUFF_DECODE(s, br_state, tbl, return FALSE, label2);
  154182. r = s >> 4;
  154183. s &= 15;
  154184. if (s) {
  154185. k += r;
  154186. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154187. r = GET_BITS(s);
  154188. s = HUFF_EXTEND(r, s);
  154189. (*block)[jpeg_natural_order[k]] = (JCOEF) (s << Al);
  154190. } else {
  154191. if (r == 15) { /* ZRL */
  154192. k += 15; /* skip 15 zeroes in band */
  154193. } else { /* EOBr, run length is 2^r + appended bits */
  154194. EOBRUN = 1 << r;
  154195. if (r) { /* EOBr, r > 0 */
  154196. CHECK_BIT_BUFFER(br_state, r, return FALSE);
  154197. r = GET_BITS(r);
  154198. EOBRUN += r;
  154199. }
  154200. EOBRUN--; /* this band is processed at this moment */
  154201. break; /* force end-of-band */
  154202. }
  154203. }
  154204. }
  154205. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154206. }
  154207. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154208. }
  154209. entropy->restarts_to_go--;
  154210. return TRUE;
  154211. }
  154212. METHODDEF(boolean)
  154213. decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154214. {
  154215. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154216. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154217. int blkn;
  154218. JBLOCKROW block;
  154219. BITREAD_STATE_VARS;
  154220. if (cinfo->restart_interval) {
  154221. if (entropy->restarts_to_go == 0)
  154222. if (! process_restartp(cinfo))
  154223. return FALSE;
  154224. }
  154225. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154226. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154227. block = MCU_data[blkn];
  154228. CHECK_BIT_BUFFER(br_state, 1, return FALSE);
  154229. if (GET_BITS(1))
  154230. (*block)[0] |= p1;
  154231. }
  154232. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154233. entropy->restarts_to_go--;
  154234. return TRUE;
  154235. }
  154236. METHODDEF(boolean)
  154237. decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154238. {
  154239. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154240. int Se = cinfo->Se;
  154241. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154242. int m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
  154243. register int s, k, r;
  154244. unsigned int EOBRUN;
  154245. JBLOCKROW block;
  154246. JCOEFPTR thiscoef;
  154247. BITREAD_STATE_VARS;
  154248. d_derived_tbl * tbl;
  154249. int num_newnz;
  154250. int newnz_pos[DCTSIZE2];
  154251. if (cinfo->restart_interval) {
  154252. if (entropy->restarts_to_go == 0)
  154253. if (! process_restartp(cinfo))
  154254. return FALSE;
  154255. }
  154256. if (! entropy->pub.insufficient_data) {
  154257. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154258. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154259. block = MCU_data[0];
  154260. tbl = entropy->ac_derived_tbl;
  154261. num_newnz = 0;
  154262. k = cinfo->Ss;
  154263. if (EOBRUN == 0) {
  154264. for (; k <= Se; k++) {
  154265. HUFF_DECODE(s, br_state, tbl, goto undoit, label3);
  154266. r = s >> 4;
  154267. s &= 15;
  154268. if (s) {
  154269. if (s != 1) /* size of new coef should always be 1 */
  154270. WARNMS(cinfo, JWRN_HUFF_BAD_CODE);
  154271. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154272. if (GET_BITS(1))
  154273. s = p1; /* newly nonzero coef is positive */
  154274. else
  154275. s = m1; /* newly nonzero coef is negative */
  154276. } else {
  154277. if (r != 15) {
  154278. EOBRUN = 1 << r; /* EOBr, run length is 2^r + appended bits */
  154279. if (r) {
  154280. CHECK_BIT_BUFFER(br_state, r, goto undoit);
  154281. r = GET_BITS(r);
  154282. EOBRUN += r;
  154283. }
  154284. break; /* rest of block is handled by EOB logic */
  154285. }
  154286. }
  154287. do {
  154288. thiscoef = *block + jpeg_natural_order[k];
  154289. if (*thiscoef != 0) {
  154290. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154291. if (GET_BITS(1)) {
  154292. if ((*thiscoef & p1) == 0) { /* do nothing if already set it */
  154293. if (*thiscoef >= 0)
  154294. *thiscoef += p1;
  154295. else
  154296. *thiscoef += m1;
  154297. }
  154298. }
  154299. } else {
  154300. if (--r < 0)
  154301. break; /* reached target zero coefficient */
  154302. }
  154303. k++;
  154304. } while (k <= Se);
  154305. if (s) {
  154306. int pos = jpeg_natural_order[k];
  154307. (*block)[pos] = (JCOEF) s;
  154308. newnz_pos[num_newnz++] = pos;
  154309. }
  154310. }
  154311. }
  154312. if (EOBRUN > 0) {
  154313. for (; k <= Se; k++) {
  154314. thiscoef = *block + jpeg_natural_order[k];
  154315. if (*thiscoef != 0) {
  154316. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154317. if (GET_BITS(1)) {
  154318. if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */
  154319. if (*thiscoef >= 0)
  154320. *thiscoef += p1;
  154321. else
  154322. *thiscoef += m1;
  154323. }
  154324. }
  154325. }
  154326. }
  154327. EOBRUN--;
  154328. }
  154329. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154330. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154331. }
  154332. entropy->restarts_to_go--;
  154333. return TRUE;
  154334. undoit:
  154335. while (num_newnz > 0)
  154336. (*block)[newnz_pos[--num_newnz]] = 0;
  154337. return FALSE;
  154338. }
  154339. GLOBAL(void)
  154340. jinit_phuff_decoder (j_decompress_ptr cinfo)
  154341. {
  154342. phuff_entropy_ptr2 entropy;
  154343. int *coef_bit_ptr;
  154344. int ci, i;
  154345. entropy = (phuff_entropy_ptr2)
  154346. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154347. SIZEOF(phuff_entropy_decoder));
  154348. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  154349. entropy->pub.start_pass = start_pass_phuff_decoder;
  154350. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  154351. entropy->derived_tbls[i] = NULL;
  154352. }
  154353. cinfo->coef_bits = (int (*)[DCTSIZE2])
  154354. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154355. cinfo->num_components*DCTSIZE2*SIZEOF(int));
  154356. coef_bit_ptr = & cinfo->coef_bits[0][0];
  154357. for (ci = 0; ci < cinfo->num_components; ci++)
  154358. for (i = 0; i < DCTSIZE2; i++)
  154359. *coef_bit_ptr++ = -1;
  154360. }
  154361. #endif /* D_PROGRESSIVE_SUPPORTED */
  154362. /*** End of inlined file: jdphuff.c ***/
  154363. /*** Start of inlined file: jdpostct.c ***/
  154364. #define JPEG_INTERNALS
  154365. typedef struct {
  154366. struct jpeg_d_post_controller pub; /* public fields */
  154367. jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */
  154368. JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */
  154369. JDIMENSION strip_height; /* buffer size in rows */
  154370. JDIMENSION starting_row; /* row # of first row in current strip */
  154371. JDIMENSION next_row; /* index of next row to fill/empty in strip */
  154372. } my_post_controller;
  154373. typedef my_post_controller * my_post_ptr;
  154374. METHODDEF(void) post_process_1pass
  154375. JPP((j_decompress_ptr cinfo,
  154376. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154377. JDIMENSION in_row_groups_avail,
  154378. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154379. JDIMENSION out_rows_avail));
  154380. #ifdef QUANT_2PASS_SUPPORTED
  154381. METHODDEF(void) post_process_prepass
  154382. JPP((j_decompress_ptr cinfo,
  154383. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154384. JDIMENSION in_row_groups_avail,
  154385. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154386. JDIMENSION out_rows_avail));
  154387. METHODDEF(void) post_process_2pass
  154388. JPP((j_decompress_ptr cinfo,
  154389. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154390. JDIMENSION in_row_groups_avail,
  154391. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154392. JDIMENSION out_rows_avail));
  154393. #endif
  154394. METHODDEF(void)
  154395. start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  154396. {
  154397. my_post_ptr post = (my_post_ptr) cinfo->post;
  154398. switch (pass_mode) {
  154399. case JBUF_PASS_THRU:
  154400. if (cinfo->quantize_colors) {
  154401. post->pub.post_process_data = post_process_1pass;
  154402. if (post->buffer == NULL) {
  154403. post->buffer = (*cinfo->mem->access_virt_sarray)
  154404. ((j_common_ptr) cinfo, post->whole_image,
  154405. (JDIMENSION) 0, post->strip_height, TRUE);
  154406. }
  154407. } else {
  154408. post->pub.post_process_data = cinfo->upsample->upsample;
  154409. }
  154410. break;
  154411. #ifdef QUANT_2PASS_SUPPORTED
  154412. case JBUF_SAVE_AND_PASS:
  154413. if (post->whole_image == NULL)
  154414. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154415. post->pub.post_process_data = post_process_prepass;
  154416. break;
  154417. case JBUF_CRANK_DEST:
  154418. if (post->whole_image == NULL)
  154419. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154420. post->pub.post_process_data = post_process_2pass;
  154421. break;
  154422. #endif /* QUANT_2PASS_SUPPORTED */
  154423. default:
  154424. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154425. break;
  154426. }
  154427. post->starting_row = post->next_row = 0;
  154428. }
  154429. METHODDEF(void)
  154430. post_process_1pass (j_decompress_ptr cinfo,
  154431. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154432. JDIMENSION in_row_groups_avail,
  154433. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154434. JDIMENSION out_rows_avail)
  154435. {
  154436. my_post_ptr post = (my_post_ptr) cinfo->post;
  154437. JDIMENSION num_rows, max_rows;
  154438. max_rows = out_rows_avail - *out_row_ctr;
  154439. if (max_rows > post->strip_height)
  154440. max_rows = post->strip_height;
  154441. num_rows = 0;
  154442. (*cinfo->upsample->upsample) (cinfo,
  154443. input_buf, in_row_group_ctr, in_row_groups_avail,
  154444. post->buffer, &num_rows, max_rows);
  154445. (*cinfo->cquantize->color_quantize) (cinfo,
  154446. post->buffer, output_buf + *out_row_ctr, (int) num_rows);
  154447. *out_row_ctr += num_rows;
  154448. }
  154449. #ifdef QUANT_2PASS_SUPPORTED
  154450. METHODDEF(void)
  154451. post_process_prepass (j_decompress_ptr cinfo,
  154452. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154453. JDIMENSION in_row_groups_avail,
  154454. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154455. JDIMENSION out_rows_avail)
  154456. {
  154457. my_post_ptr post = (my_post_ptr) cinfo->post;
  154458. JDIMENSION old_next_row, num_rows;
  154459. if (post->next_row == 0) {
  154460. post->buffer = (*cinfo->mem->access_virt_sarray)
  154461. ((j_common_ptr) cinfo, post->whole_image,
  154462. post->starting_row, post->strip_height, TRUE);
  154463. }
  154464. old_next_row = post->next_row;
  154465. (*cinfo->upsample->upsample) (cinfo,
  154466. input_buf, in_row_group_ctr, in_row_groups_avail,
  154467. post->buffer, &post->next_row, post->strip_height);
  154468. if (post->next_row > old_next_row) {
  154469. num_rows = post->next_row - old_next_row;
  154470. (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row,
  154471. (JSAMPARRAY) NULL, (int) num_rows);
  154472. *out_row_ctr += num_rows;
  154473. }
  154474. if (post->next_row >= post->strip_height) {
  154475. post->starting_row += post->strip_height;
  154476. post->next_row = 0;
  154477. }
  154478. }
  154479. METHODDEF(void)
  154480. post_process_2pass (j_decompress_ptr cinfo,
  154481. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154482. JDIMENSION in_row_groups_avail,
  154483. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154484. JDIMENSION out_rows_avail)
  154485. {
  154486. my_post_ptr post = (my_post_ptr) cinfo->post;
  154487. JDIMENSION num_rows, max_rows;
  154488. if (post->next_row == 0) {
  154489. post->buffer = (*cinfo->mem->access_virt_sarray)
  154490. ((j_common_ptr) cinfo, post->whole_image,
  154491. post->starting_row, post->strip_height, FALSE);
  154492. }
  154493. num_rows = post->strip_height - post->next_row; /* available in strip */
  154494. max_rows = out_rows_avail - *out_row_ctr; /* available in output area */
  154495. if (num_rows > max_rows)
  154496. num_rows = max_rows;
  154497. max_rows = cinfo->output_height - post->starting_row;
  154498. if (num_rows > max_rows)
  154499. num_rows = max_rows;
  154500. (*cinfo->cquantize->color_quantize) (cinfo,
  154501. post->buffer + post->next_row, output_buf + *out_row_ctr,
  154502. (int) num_rows);
  154503. *out_row_ctr += num_rows;
  154504. post->next_row += num_rows;
  154505. if (post->next_row >= post->strip_height) {
  154506. post->starting_row += post->strip_height;
  154507. post->next_row = 0;
  154508. }
  154509. }
  154510. #endif /* QUANT_2PASS_SUPPORTED */
  154511. GLOBAL(void)
  154512. jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  154513. {
  154514. my_post_ptr post;
  154515. post = (my_post_ptr)
  154516. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154517. SIZEOF(my_post_controller));
  154518. cinfo->post = (struct jpeg_d_post_controller *) post;
  154519. post->pub.start_pass = start_pass_dpost;
  154520. post->whole_image = NULL; /* flag for no virtual arrays */
  154521. post->buffer = NULL; /* flag for no strip buffer */
  154522. if (cinfo->quantize_colors) {
  154523. post->strip_height = (JDIMENSION) cinfo->max_v_samp_factor;
  154524. if (need_full_buffer) {
  154525. #ifdef QUANT_2PASS_SUPPORTED
  154526. post->whole_image = (*cinfo->mem->request_virt_sarray)
  154527. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  154528. cinfo->output_width * cinfo->out_color_components,
  154529. (JDIMENSION) jround_up((long) cinfo->output_height,
  154530. (long) post->strip_height),
  154531. post->strip_height);
  154532. #else
  154533. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154534. #endif /* QUANT_2PASS_SUPPORTED */
  154535. } else {
  154536. post->buffer = (*cinfo->mem->alloc_sarray)
  154537. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154538. cinfo->output_width * cinfo->out_color_components,
  154539. post->strip_height);
  154540. }
  154541. }
  154542. }
  154543. /*** End of inlined file: jdpostct.c ***/
  154544. #undef FIX
  154545. /*** Start of inlined file: jdsample.c ***/
  154546. #define JPEG_INTERNALS
  154547. typedef JMETHOD(void, upsample1_ptr,
  154548. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154549. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
  154550. typedef struct {
  154551. struct jpeg_upsampler pub; /* public fields */
  154552. JSAMPARRAY color_buf[MAX_COMPONENTS];
  154553. upsample1_ptr methods[MAX_COMPONENTS];
  154554. int next_row_out; /* counts rows emitted from color_buf */
  154555. JDIMENSION rows_to_go; /* counts rows remaining in image */
  154556. int rowgroup_height[MAX_COMPONENTS];
  154557. UINT8 h_expand[MAX_COMPONENTS];
  154558. UINT8 v_expand[MAX_COMPONENTS];
  154559. } my_upsampler2;
  154560. typedef my_upsampler2 * my_upsample_ptr2;
  154561. METHODDEF(void)
  154562. start_pass_upsample (j_decompress_ptr cinfo)
  154563. {
  154564. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154565. upsample->next_row_out = cinfo->max_v_samp_factor;
  154566. upsample->rows_to_go = cinfo->output_height;
  154567. }
  154568. METHODDEF(void)
  154569. sep_upsample (j_decompress_ptr cinfo,
  154570. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154571. JDIMENSION in_row_groups_avail,
  154572. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154573. JDIMENSION out_rows_avail)
  154574. {
  154575. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154576. int ci;
  154577. jpeg_component_info * compptr;
  154578. JDIMENSION num_rows;
  154579. if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
  154580. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  154581. ci++, compptr++) {
  154582. (*upsample->methods[ci]) (cinfo, compptr,
  154583. input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
  154584. upsample->color_buf + ci);
  154585. }
  154586. upsample->next_row_out = 0;
  154587. }
  154588. num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out);
  154589. if (num_rows > upsample->rows_to_go)
  154590. num_rows = upsample->rows_to_go;
  154591. out_rows_avail -= *out_row_ctr;
  154592. if (num_rows > out_rows_avail)
  154593. num_rows = out_rows_avail;
  154594. (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,
  154595. (JDIMENSION) upsample->next_row_out,
  154596. output_buf + *out_row_ctr,
  154597. (int) num_rows);
  154598. *out_row_ctr += num_rows;
  154599. upsample->rows_to_go -= num_rows;
  154600. upsample->next_row_out += num_rows;
  154601. if (upsample->next_row_out >= cinfo->max_v_samp_factor)
  154602. (*in_row_group_ctr)++;
  154603. }
  154604. METHODDEF(void)
  154605. fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154606. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154607. {
  154608. *output_data_ptr = input_data;
  154609. }
  154610. METHODDEF(void)
  154611. noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154612. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154613. {
  154614. *output_data_ptr = NULL; /* safety check */
  154615. }
  154616. METHODDEF(void)
  154617. int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154618. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154619. {
  154620. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154621. JSAMPARRAY output_data = *output_data_ptr;
  154622. register JSAMPROW inptr, outptr;
  154623. register JSAMPLE invalue;
  154624. register int h;
  154625. JSAMPROW outend;
  154626. int h_expand, v_expand;
  154627. int inrow, outrow;
  154628. h_expand = upsample->h_expand[compptr->component_index];
  154629. v_expand = upsample->v_expand[compptr->component_index];
  154630. inrow = outrow = 0;
  154631. while (outrow < cinfo->max_v_samp_factor) {
  154632. inptr = input_data[inrow];
  154633. outptr = output_data[outrow];
  154634. outend = outptr + cinfo->output_width;
  154635. while (outptr < outend) {
  154636. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154637. for (h = h_expand; h > 0; h--) {
  154638. *outptr++ = invalue;
  154639. }
  154640. }
  154641. if (v_expand > 1) {
  154642. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  154643. v_expand-1, cinfo->output_width);
  154644. }
  154645. inrow++;
  154646. outrow += v_expand;
  154647. }
  154648. }
  154649. METHODDEF(void)
  154650. h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154651. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154652. {
  154653. JSAMPARRAY output_data = *output_data_ptr;
  154654. register JSAMPROW inptr, outptr;
  154655. register JSAMPLE invalue;
  154656. JSAMPROW outend;
  154657. int inrow;
  154658. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  154659. inptr = input_data[inrow];
  154660. outptr = output_data[inrow];
  154661. outend = outptr + cinfo->output_width;
  154662. while (outptr < outend) {
  154663. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154664. *outptr++ = invalue;
  154665. *outptr++ = invalue;
  154666. }
  154667. }
  154668. }
  154669. METHODDEF(void)
  154670. h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154671. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154672. {
  154673. JSAMPARRAY output_data = *output_data_ptr;
  154674. register JSAMPROW inptr, outptr;
  154675. register JSAMPLE invalue;
  154676. JSAMPROW outend;
  154677. int inrow, outrow;
  154678. inrow = outrow = 0;
  154679. while (outrow < cinfo->max_v_samp_factor) {
  154680. inptr = input_data[inrow];
  154681. outptr = output_data[outrow];
  154682. outend = outptr + cinfo->output_width;
  154683. while (outptr < outend) {
  154684. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154685. *outptr++ = invalue;
  154686. *outptr++ = invalue;
  154687. }
  154688. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  154689. 1, cinfo->output_width);
  154690. inrow++;
  154691. outrow += 2;
  154692. }
  154693. }
  154694. METHODDEF(void)
  154695. h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154696. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154697. {
  154698. JSAMPARRAY output_data = *output_data_ptr;
  154699. register JSAMPROW inptr, outptr;
  154700. register int invalue;
  154701. register JDIMENSION colctr;
  154702. int inrow;
  154703. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  154704. inptr = input_data[inrow];
  154705. outptr = output_data[inrow];
  154706. invalue = GETJSAMPLE(*inptr++);
  154707. *outptr++ = (JSAMPLE) invalue;
  154708. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2);
  154709. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  154710. invalue = GETJSAMPLE(*inptr++) * 3;
  154711. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2);
  154712. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(*inptr) + 2) >> 2);
  154713. }
  154714. invalue = GETJSAMPLE(*inptr);
  154715. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2);
  154716. *outptr++ = (JSAMPLE) invalue;
  154717. }
  154718. }
  154719. METHODDEF(void)
  154720. h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154721. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154722. {
  154723. JSAMPARRAY output_data = *output_data_ptr;
  154724. register JSAMPROW inptr0, inptr1, outptr;
  154725. #if BITS_IN_JSAMPLE == 8
  154726. register int thiscolsum, lastcolsum, nextcolsum;
  154727. #else
  154728. register INT32 thiscolsum, lastcolsum, nextcolsum;
  154729. #endif
  154730. register JDIMENSION colctr;
  154731. int inrow, outrow, v;
  154732. inrow = outrow = 0;
  154733. while (outrow < cinfo->max_v_samp_factor) {
  154734. for (v = 0; v < 2; v++) {
  154735. inptr0 = input_data[inrow];
  154736. if (v == 0) /* next nearest is row above */
  154737. inptr1 = input_data[inrow-1];
  154738. else /* next nearest is row below */
  154739. inptr1 = input_data[inrow+1];
  154740. outptr = output_data[outrow++];
  154741. thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154742. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154743. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 8) >> 4);
  154744. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  154745. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  154746. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  154747. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154748. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  154749. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  154750. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  154751. }
  154752. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  154753. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 7) >> 4);
  154754. }
  154755. inrow++;
  154756. }
  154757. }
  154758. GLOBAL(void)
  154759. jinit_upsampler (j_decompress_ptr cinfo)
  154760. {
  154761. my_upsample_ptr2 upsample;
  154762. int ci;
  154763. jpeg_component_info * compptr;
  154764. boolean need_buffer, do_fancy;
  154765. int h_in_group, v_in_group, h_out_group, v_out_group;
  154766. upsample = (my_upsample_ptr2)
  154767. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154768. SIZEOF(my_upsampler2));
  154769. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  154770. upsample->pub.start_pass = start_pass_upsample;
  154771. upsample->pub.upsample = sep_upsample;
  154772. upsample->pub.need_context_rows = FALSE; /* until we find out differently */
  154773. if (cinfo->CCIR601_sampling) /* this isn't supported */
  154774. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  154775. do_fancy = cinfo->do_fancy_upsampling && cinfo->min_DCT_scaled_size > 1;
  154776. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  154777. ci++, compptr++) {
  154778. h_in_group = (compptr->h_samp_factor * compptr->DCT_scaled_size) /
  154779. cinfo->min_DCT_scaled_size;
  154780. v_in_group = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  154781. cinfo->min_DCT_scaled_size;
  154782. h_out_group = cinfo->max_h_samp_factor;
  154783. v_out_group = cinfo->max_v_samp_factor;
  154784. upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
  154785. need_buffer = TRUE;
  154786. if (! compptr->component_needed) {
  154787. upsample->methods[ci] = noop_upsample;
  154788. need_buffer = FALSE;
  154789. } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
  154790. upsample->methods[ci] = fullsize_upsample;
  154791. need_buffer = FALSE;
  154792. } else if (h_in_group * 2 == h_out_group &&
  154793. v_in_group == v_out_group) {
  154794. if (do_fancy && compptr->downsampled_width > 2)
  154795. upsample->methods[ci] = h2v1_fancy_upsample;
  154796. else
  154797. upsample->methods[ci] = h2v1_upsample;
  154798. } else if (h_in_group * 2 == h_out_group &&
  154799. v_in_group * 2 == v_out_group) {
  154800. if (do_fancy && compptr->downsampled_width > 2) {
  154801. upsample->methods[ci] = h2v2_fancy_upsample;
  154802. upsample->pub.need_context_rows = TRUE;
  154803. } else
  154804. upsample->methods[ci] = h2v2_upsample;
  154805. } else if ((h_out_group % h_in_group) == 0 &&
  154806. (v_out_group % v_in_group) == 0) {
  154807. upsample->methods[ci] = int_upsample;
  154808. upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
  154809. upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);
  154810. } else
  154811. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  154812. if (need_buffer) {
  154813. upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  154814. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154815. (JDIMENSION) jround_up((long) cinfo->output_width,
  154816. (long) cinfo->max_h_samp_factor),
  154817. (JDIMENSION) cinfo->max_v_samp_factor);
  154818. }
  154819. }
  154820. }
  154821. /*** End of inlined file: jdsample.c ***/
  154822. /*** Start of inlined file: jdtrans.c ***/
  154823. #define JPEG_INTERNALS
  154824. LOCAL(void) transdecode_master_selection JPP((j_decompress_ptr cinfo));
  154825. GLOBAL(jvirt_barray_ptr *)
  154826. jpeg_read_coefficients (j_decompress_ptr cinfo)
  154827. {
  154828. if (cinfo->global_state == DSTATE_READY) {
  154829. transdecode_master_selection(cinfo);
  154830. cinfo->global_state = DSTATE_RDCOEFS;
  154831. }
  154832. if (cinfo->global_state == DSTATE_RDCOEFS) {
  154833. for (;;) {
  154834. int retcode;
  154835. if (cinfo->progress != NULL)
  154836. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  154837. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  154838. if (retcode == JPEG_SUSPENDED)
  154839. return NULL;
  154840. if (retcode == JPEG_REACHED_EOI)
  154841. break;
  154842. if (cinfo->progress != NULL &&
  154843. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  154844. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  154845. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  154846. }
  154847. }
  154848. }
  154849. cinfo->global_state = DSTATE_STOPPING;
  154850. }
  154851. if ((cinfo->global_state == DSTATE_STOPPING ||
  154852. cinfo->global_state == DSTATE_BUFIMAGE) && cinfo->buffered_image) {
  154853. return cinfo->coef->coef_arrays;
  154854. }
  154855. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  154856. return NULL; /* keep compiler happy */
  154857. }
  154858. LOCAL(void)
  154859. transdecode_master_selection (j_decompress_ptr cinfo)
  154860. {
  154861. cinfo->buffered_image = TRUE;
  154862. if (cinfo->arith_code) {
  154863. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  154864. } else {
  154865. if (cinfo->progressive_mode) {
  154866. #ifdef D_PROGRESSIVE_SUPPORTED
  154867. jinit_phuff_decoder(cinfo);
  154868. #else
  154869. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154870. #endif
  154871. } else
  154872. jinit_huff_decoder(cinfo);
  154873. }
  154874. jinit_d_coef_controller(cinfo, TRUE);
  154875. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  154876. (*cinfo->inputctl->start_input_pass) (cinfo);
  154877. if (cinfo->progress != NULL) {
  154878. int nscans;
  154879. if (cinfo->progressive_mode) {
  154880. nscans = 2 + 3 * cinfo->num_components;
  154881. } else if (cinfo->inputctl->has_multiple_scans) {
  154882. nscans = cinfo->num_components;
  154883. } else {
  154884. nscans = 1;
  154885. }
  154886. cinfo->progress->pass_counter = 0L;
  154887. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  154888. cinfo->progress->completed_passes = 0;
  154889. cinfo->progress->total_passes = 1;
  154890. }
  154891. }
  154892. /*** End of inlined file: jdtrans.c ***/
  154893. /*** Start of inlined file: jfdctflt.c ***/
  154894. #define JPEG_INTERNALS
  154895. #ifdef DCT_FLOAT_SUPPORTED
  154896. #if DCTSIZE != 8
  154897. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  154898. #endif
  154899. GLOBAL(void)
  154900. jpeg_fdct_float (FAST_FLOAT * data)
  154901. {
  154902. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  154903. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  154904. FAST_FLOAT z1, z2, z3, z4, z5, z11, z13;
  154905. FAST_FLOAT *dataptr;
  154906. int ctr;
  154907. dataptr = data;
  154908. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  154909. tmp0 = dataptr[0] + dataptr[7];
  154910. tmp7 = dataptr[0] - dataptr[7];
  154911. tmp1 = dataptr[1] + dataptr[6];
  154912. tmp6 = dataptr[1] - dataptr[6];
  154913. tmp2 = dataptr[2] + dataptr[5];
  154914. tmp5 = dataptr[2] - dataptr[5];
  154915. tmp3 = dataptr[3] + dataptr[4];
  154916. tmp4 = dataptr[3] - dataptr[4];
  154917. tmp10 = tmp0 + tmp3; /* phase 2 */
  154918. tmp13 = tmp0 - tmp3;
  154919. tmp11 = tmp1 + tmp2;
  154920. tmp12 = tmp1 - tmp2;
  154921. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  154922. dataptr[4] = tmp10 - tmp11;
  154923. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  154924. dataptr[2] = tmp13 + z1; /* phase 5 */
  154925. dataptr[6] = tmp13 - z1;
  154926. tmp10 = tmp4 + tmp5; /* phase 2 */
  154927. tmp11 = tmp5 + tmp6;
  154928. tmp12 = tmp6 + tmp7;
  154929. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  154930. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  154931. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  154932. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  154933. z11 = tmp7 + z3; /* phase 5 */
  154934. z13 = tmp7 - z3;
  154935. dataptr[5] = z13 + z2; /* phase 6 */
  154936. dataptr[3] = z13 - z2;
  154937. dataptr[1] = z11 + z4;
  154938. dataptr[7] = z11 - z4;
  154939. dataptr += DCTSIZE; /* advance pointer to next row */
  154940. }
  154941. dataptr = data;
  154942. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  154943. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  154944. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  154945. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  154946. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  154947. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  154948. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  154949. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  154950. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  154951. tmp10 = tmp0 + tmp3; /* phase 2 */
  154952. tmp13 = tmp0 - tmp3;
  154953. tmp11 = tmp1 + tmp2;
  154954. tmp12 = tmp1 - tmp2;
  154955. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  154956. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  154957. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  154958. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  154959. dataptr[DCTSIZE*6] = tmp13 - z1;
  154960. tmp10 = tmp4 + tmp5; /* phase 2 */
  154961. tmp11 = tmp5 + tmp6;
  154962. tmp12 = tmp6 + tmp7;
  154963. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  154964. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  154965. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  154966. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  154967. z11 = tmp7 + z3; /* phase 5 */
  154968. z13 = tmp7 - z3;
  154969. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  154970. dataptr[DCTSIZE*3] = z13 - z2;
  154971. dataptr[DCTSIZE*1] = z11 + z4;
  154972. dataptr[DCTSIZE*7] = z11 - z4;
  154973. dataptr++; /* advance pointer to next column */
  154974. }
  154975. }
  154976. #endif /* DCT_FLOAT_SUPPORTED */
  154977. /*** End of inlined file: jfdctflt.c ***/
  154978. /*** Start of inlined file: jfdctint.c ***/
  154979. #define JPEG_INTERNALS
  154980. #ifdef DCT_ISLOW_SUPPORTED
  154981. #if DCTSIZE != 8
  154982. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  154983. #endif
  154984. #if BITS_IN_JSAMPLE == 8
  154985. #define CONST_BITS 13
  154986. #define PASS1_BITS 2
  154987. #else
  154988. #define CONST_BITS 13
  154989. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  154990. #endif
  154991. #if CONST_BITS == 13
  154992. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  154993. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  154994. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  154995. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  154996. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  154997. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  154998. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  154999. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155000. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  155001. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  155002. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155003. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  155004. #else
  155005. #define FIX_0_298631336 FIX(0.298631336)
  155006. #define FIX_0_390180644 FIX(0.390180644)
  155007. #define FIX_0_541196100 FIX(0.541196100)
  155008. #define FIX_0_765366865 FIX(0.765366865)
  155009. #define FIX_0_899976223 FIX(0.899976223)
  155010. #define FIX_1_175875602 FIX(1.175875602)
  155011. #define FIX_1_501321110 FIX(1.501321110)
  155012. #define FIX_1_847759065 FIX(1.847759065)
  155013. #define FIX_1_961570560 FIX(1.961570560)
  155014. #define FIX_2_053119869 FIX(2.053119869)
  155015. #define FIX_2_562915447 FIX(2.562915447)
  155016. #define FIX_3_072711026 FIX(3.072711026)
  155017. #endif
  155018. #if BITS_IN_JSAMPLE == 8
  155019. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155020. #else
  155021. #define MULTIPLY(var,const) ((var) * (const))
  155022. #endif
  155023. GLOBAL(void)
  155024. jpeg_fdct_islow (DCTELEM * data)
  155025. {
  155026. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155027. INT32 tmp10, tmp11, tmp12, tmp13;
  155028. INT32 z1, z2, z3, z4, z5;
  155029. DCTELEM *dataptr;
  155030. int ctr;
  155031. SHIFT_TEMPS
  155032. dataptr = data;
  155033. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155034. tmp0 = dataptr[0] + dataptr[7];
  155035. tmp7 = dataptr[0] - dataptr[7];
  155036. tmp1 = dataptr[1] + dataptr[6];
  155037. tmp6 = dataptr[1] - dataptr[6];
  155038. tmp2 = dataptr[2] + dataptr[5];
  155039. tmp5 = dataptr[2] - dataptr[5];
  155040. tmp3 = dataptr[3] + dataptr[4];
  155041. tmp4 = dataptr[3] - dataptr[4];
  155042. tmp10 = tmp0 + tmp3;
  155043. tmp13 = tmp0 - tmp3;
  155044. tmp11 = tmp1 + tmp2;
  155045. tmp12 = tmp1 - tmp2;
  155046. dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS);
  155047. dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
  155048. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155049. dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155050. CONST_BITS-PASS1_BITS);
  155051. dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155052. CONST_BITS-PASS1_BITS);
  155053. z1 = tmp4 + tmp7;
  155054. z2 = tmp5 + tmp6;
  155055. z3 = tmp4 + tmp6;
  155056. z4 = tmp5 + tmp7;
  155057. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155058. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155059. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155060. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155061. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155062. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155063. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155064. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155065. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155066. z3 += z5;
  155067. z4 += z5;
  155068. dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS);
  155069. dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS);
  155070. dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS);
  155071. dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS);
  155072. dataptr += DCTSIZE; /* advance pointer to next row */
  155073. }
  155074. dataptr = data;
  155075. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155076. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155077. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155078. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155079. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155080. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155081. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155082. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155083. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155084. tmp10 = tmp0 + tmp3;
  155085. tmp13 = tmp0 - tmp3;
  155086. tmp11 = tmp1 + tmp2;
  155087. tmp12 = tmp1 - tmp2;
  155088. dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
  155089. dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
  155090. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155091. dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155092. CONST_BITS+PASS1_BITS);
  155093. dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155094. CONST_BITS+PASS1_BITS);
  155095. z1 = tmp4 + tmp7;
  155096. z2 = tmp5 + tmp6;
  155097. z3 = tmp4 + tmp6;
  155098. z4 = tmp5 + tmp7;
  155099. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155100. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155101. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155102. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155103. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155104. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155105. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155106. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155107. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155108. z3 += z5;
  155109. z4 += z5;
  155110. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3,
  155111. CONST_BITS+PASS1_BITS);
  155112. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4,
  155113. CONST_BITS+PASS1_BITS);
  155114. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3,
  155115. CONST_BITS+PASS1_BITS);
  155116. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4,
  155117. CONST_BITS+PASS1_BITS);
  155118. dataptr++; /* advance pointer to next column */
  155119. }
  155120. }
  155121. #endif /* DCT_ISLOW_SUPPORTED */
  155122. /*** End of inlined file: jfdctint.c ***/
  155123. #undef CONST_BITS
  155124. #undef MULTIPLY
  155125. #undef FIX_0_541196100
  155126. /*** Start of inlined file: jfdctfst.c ***/
  155127. #define JPEG_INTERNALS
  155128. #ifdef DCT_IFAST_SUPPORTED
  155129. #if DCTSIZE != 8
  155130. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155131. #endif
  155132. #define CONST_BITS 8
  155133. #if CONST_BITS == 8
  155134. #define FIX_0_382683433 ((INT32) 98) /* FIX(0.382683433) */
  155135. #define FIX_0_541196100 ((INT32) 139) /* FIX(0.541196100) */
  155136. #define FIX_0_707106781 ((INT32) 181) /* FIX(0.707106781) */
  155137. #define FIX_1_306562965 ((INT32) 334) /* FIX(1.306562965) */
  155138. #else
  155139. #define FIX_0_382683433 FIX(0.382683433)
  155140. #define FIX_0_541196100 FIX(0.541196100)
  155141. #define FIX_0_707106781 FIX(0.707106781)
  155142. #define FIX_1_306562965 FIX(1.306562965)
  155143. #endif
  155144. #ifndef USE_ACCURATE_ROUNDING
  155145. #undef DESCALE
  155146. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155147. #endif
  155148. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155149. GLOBAL(void)
  155150. jpeg_fdct_ifast (DCTELEM * data)
  155151. {
  155152. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155153. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155154. DCTELEM z1, z2, z3, z4, z5, z11, z13;
  155155. DCTELEM *dataptr;
  155156. int ctr;
  155157. SHIFT_TEMPS
  155158. dataptr = data;
  155159. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155160. tmp0 = dataptr[0] + dataptr[7];
  155161. tmp7 = dataptr[0] - dataptr[7];
  155162. tmp1 = dataptr[1] + dataptr[6];
  155163. tmp6 = dataptr[1] - dataptr[6];
  155164. tmp2 = dataptr[2] + dataptr[5];
  155165. tmp5 = dataptr[2] - dataptr[5];
  155166. tmp3 = dataptr[3] + dataptr[4];
  155167. tmp4 = dataptr[3] - dataptr[4];
  155168. tmp10 = tmp0 + tmp3; /* phase 2 */
  155169. tmp13 = tmp0 - tmp3;
  155170. tmp11 = tmp1 + tmp2;
  155171. tmp12 = tmp1 - tmp2;
  155172. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  155173. dataptr[4] = tmp10 - tmp11;
  155174. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155175. dataptr[2] = tmp13 + z1; /* phase 5 */
  155176. dataptr[6] = tmp13 - z1;
  155177. tmp10 = tmp4 + tmp5; /* phase 2 */
  155178. tmp11 = tmp5 + tmp6;
  155179. tmp12 = tmp6 + tmp7;
  155180. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155181. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155182. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155183. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155184. z11 = tmp7 + z3; /* phase 5 */
  155185. z13 = tmp7 - z3;
  155186. dataptr[5] = z13 + z2; /* phase 6 */
  155187. dataptr[3] = z13 - z2;
  155188. dataptr[1] = z11 + z4;
  155189. dataptr[7] = z11 - z4;
  155190. dataptr += DCTSIZE; /* advance pointer to next row */
  155191. }
  155192. dataptr = data;
  155193. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155194. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155195. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155196. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155197. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155198. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155199. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155200. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155201. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155202. tmp10 = tmp0 + tmp3; /* phase 2 */
  155203. tmp13 = tmp0 - tmp3;
  155204. tmp11 = tmp1 + tmp2;
  155205. tmp12 = tmp1 - tmp2;
  155206. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  155207. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  155208. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155209. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  155210. dataptr[DCTSIZE*6] = tmp13 - z1;
  155211. tmp10 = tmp4 + tmp5; /* phase 2 */
  155212. tmp11 = tmp5 + tmp6;
  155213. tmp12 = tmp6 + tmp7;
  155214. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155215. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155216. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155217. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155218. z11 = tmp7 + z3; /* phase 5 */
  155219. z13 = tmp7 - z3;
  155220. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  155221. dataptr[DCTSIZE*3] = z13 - z2;
  155222. dataptr[DCTSIZE*1] = z11 + z4;
  155223. dataptr[DCTSIZE*7] = z11 - z4;
  155224. dataptr++; /* advance pointer to next column */
  155225. }
  155226. }
  155227. #endif /* DCT_IFAST_SUPPORTED */
  155228. /*** End of inlined file: jfdctfst.c ***/
  155229. #undef FIX_0_541196100
  155230. /*** Start of inlined file: jidctflt.c ***/
  155231. #define JPEG_INTERNALS
  155232. #ifdef DCT_FLOAT_SUPPORTED
  155233. #if DCTSIZE != 8
  155234. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155235. #endif
  155236. #define DEQUANTIZE(coef,quantval) (((FAST_FLOAT) (coef)) * (quantval))
  155237. GLOBAL(void)
  155238. jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155239. JCOEFPTR coef_block,
  155240. JSAMPARRAY output_buf, JDIMENSION output_col)
  155241. {
  155242. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155243. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  155244. FAST_FLOAT z5, z10, z11, z12, z13;
  155245. JCOEFPTR inptr;
  155246. FLOAT_MULT_TYPE * quantptr;
  155247. FAST_FLOAT * wsptr;
  155248. JSAMPROW outptr;
  155249. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155250. int ctr;
  155251. FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */
  155252. SHIFT_TEMPS
  155253. inptr = coef_block;
  155254. quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table;
  155255. wsptr = workspace;
  155256. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155257. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155258. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155259. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155260. inptr[DCTSIZE*7] == 0) {
  155261. FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155262. wsptr[DCTSIZE*0] = dcval;
  155263. wsptr[DCTSIZE*1] = dcval;
  155264. wsptr[DCTSIZE*2] = dcval;
  155265. wsptr[DCTSIZE*3] = dcval;
  155266. wsptr[DCTSIZE*4] = dcval;
  155267. wsptr[DCTSIZE*5] = dcval;
  155268. wsptr[DCTSIZE*6] = dcval;
  155269. wsptr[DCTSIZE*7] = dcval;
  155270. inptr++; /* advance pointers to next column */
  155271. quantptr++;
  155272. wsptr++;
  155273. continue;
  155274. }
  155275. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155276. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155277. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155278. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155279. tmp10 = tmp0 + tmp2; /* phase 3 */
  155280. tmp11 = tmp0 - tmp2;
  155281. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155282. tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */
  155283. tmp0 = tmp10 + tmp13; /* phase 2 */
  155284. tmp3 = tmp10 - tmp13;
  155285. tmp1 = tmp11 + tmp12;
  155286. tmp2 = tmp11 - tmp12;
  155287. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155288. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155289. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155290. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155291. z13 = tmp6 + tmp5; /* phase 6 */
  155292. z10 = tmp6 - tmp5;
  155293. z11 = tmp4 + tmp7;
  155294. z12 = tmp4 - tmp7;
  155295. tmp7 = z11 + z13; /* phase 5 */
  155296. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */
  155297. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155298. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155299. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155300. tmp6 = tmp12 - tmp7; /* phase 2 */
  155301. tmp5 = tmp11 - tmp6;
  155302. tmp4 = tmp10 + tmp5;
  155303. wsptr[DCTSIZE*0] = tmp0 + tmp7;
  155304. wsptr[DCTSIZE*7] = tmp0 - tmp7;
  155305. wsptr[DCTSIZE*1] = tmp1 + tmp6;
  155306. wsptr[DCTSIZE*6] = tmp1 - tmp6;
  155307. wsptr[DCTSIZE*2] = tmp2 + tmp5;
  155308. wsptr[DCTSIZE*5] = tmp2 - tmp5;
  155309. wsptr[DCTSIZE*4] = tmp3 + tmp4;
  155310. wsptr[DCTSIZE*3] = tmp3 - tmp4;
  155311. inptr++; /* advance pointers to next column */
  155312. quantptr++;
  155313. wsptr++;
  155314. }
  155315. wsptr = workspace;
  155316. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155317. outptr = output_buf[ctr] + output_col;
  155318. tmp10 = wsptr[0] + wsptr[4];
  155319. tmp11 = wsptr[0] - wsptr[4];
  155320. tmp13 = wsptr[2] + wsptr[6];
  155321. tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT) 1.414213562) - tmp13;
  155322. tmp0 = tmp10 + tmp13;
  155323. tmp3 = tmp10 - tmp13;
  155324. tmp1 = tmp11 + tmp12;
  155325. tmp2 = tmp11 - tmp12;
  155326. z13 = wsptr[5] + wsptr[3];
  155327. z10 = wsptr[5] - wsptr[3];
  155328. z11 = wsptr[1] + wsptr[7];
  155329. z12 = wsptr[1] - wsptr[7];
  155330. tmp7 = z11 + z13;
  155331. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562);
  155332. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155333. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155334. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155335. tmp6 = tmp12 - tmp7;
  155336. tmp5 = tmp11 - tmp6;
  155337. tmp4 = tmp10 + tmp5;
  155338. outptr[0] = range_limit[(int) DESCALE((INT32) (tmp0 + tmp7), 3)
  155339. & RANGE_MASK];
  155340. outptr[7] = range_limit[(int) DESCALE((INT32) (tmp0 - tmp7), 3)
  155341. & RANGE_MASK];
  155342. outptr[1] = range_limit[(int) DESCALE((INT32) (tmp1 + tmp6), 3)
  155343. & RANGE_MASK];
  155344. outptr[6] = range_limit[(int) DESCALE((INT32) (tmp1 - tmp6), 3)
  155345. & RANGE_MASK];
  155346. outptr[2] = range_limit[(int) DESCALE((INT32) (tmp2 + tmp5), 3)
  155347. & RANGE_MASK];
  155348. outptr[5] = range_limit[(int) DESCALE((INT32) (tmp2 - tmp5), 3)
  155349. & RANGE_MASK];
  155350. outptr[4] = range_limit[(int) DESCALE((INT32) (tmp3 + tmp4), 3)
  155351. & RANGE_MASK];
  155352. outptr[3] = range_limit[(int) DESCALE((INT32) (tmp3 - tmp4), 3)
  155353. & RANGE_MASK];
  155354. wsptr += DCTSIZE; /* advance pointer to next row */
  155355. }
  155356. }
  155357. #endif /* DCT_FLOAT_SUPPORTED */
  155358. /*** End of inlined file: jidctflt.c ***/
  155359. #undef CONST_BITS
  155360. #undef FIX_1_847759065
  155361. #undef MULTIPLY
  155362. #undef DEQUANTIZE
  155363. #undef DESCALE
  155364. /*** Start of inlined file: jidctfst.c ***/
  155365. #define JPEG_INTERNALS
  155366. #ifdef DCT_IFAST_SUPPORTED
  155367. #if DCTSIZE != 8
  155368. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155369. #endif
  155370. #if BITS_IN_JSAMPLE == 8
  155371. #define CONST_BITS 8
  155372. #define PASS1_BITS 2
  155373. #else
  155374. #define CONST_BITS 8
  155375. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155376. #endif
  155377. #if CONST_BITS == 8
  155378. #define FIX_1_082392200 ((INT32) 277) /* FIX(1.082392200) */
  155379. #define FIX_1_414213562 ((INT32) 362) /* FIX(1.414213562) */
  155380. #define FIX_1_847759065 ((INT32) 473) /* FIX(1.847759065) */
  155381. #define FIX_2_613125930 ((INT32) 669) /* FIX(2.613125930) */
  155382. #else
  155383. #define FIX_1_082392200 FIX(1.082392200)
  155384. #define FIX_1_414213562 FIX(1.414213562)
  155385. #define FIX_1_847759065 FIX(1.847759065)
  155386. #define FIX_2_613125930 FIX(2.613125930)
  155387. #endif
  155388. #ifndef USE_ACCURATE_ROUNDING
  155389. #undef DESCALE
  155390. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155391. #endif
  155392. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155393. #if BITS_IN_JSAMPLE == 8
  155394. #define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval))
  155395. #else
  155396. #define DEQUANTIZE(coef,quantval) \
  155397. DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS)
  155398. #endif
  155399. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  155400. #define ISHIFT_TEMPS DCTELEM ishift_temp;
  155401. #if BITS_IN_JSAMPLE == 8
  155402. #define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */
  155403. #else
  155404. #define DCTELEMBITS 32 /* DCTELEM must be 32 bits */
  155405. #endif
  155406. #define IRIGHT_SHIFT(x,shft) \
  155407. ((ishift_temp = (x)) < 0 ? \
  155408. (ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \
  155409. (ishift_temp >> (shft)))
  155410. #else
  155411. #define ISHIFT_TEMPS
  155412. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  155413. #endif
  155414. #ifdef USE_ACCURATE_ROUNDING
  155415. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n))
  155416. #else
  155417. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT(x, n))
  155418. #endif
  155419. GLOBAL(void)
  155420. jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155421. JCOEFPTR coef_block,
  155422. JSAMPARRAY output_buf, JDIMENSION output_col)
  155423. {
  155424. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155425. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155426. DCTELEM z5, z10, z11, z12, z13;
  155427. JCOEFPTR inptr;
  155428. IFAST_MULT_TYPE * quantptr;
  155429. int * wsptr;
  155430. JSAMPROW outptr;
  155431. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155432. int ctr;
  155433. int workspace[DCTSIZE2]; /* buffers data between passes */
  155434. SHIFT_TEMPS /* for DESCALE */
  155435. ISHIFT_TEMPS /* for IDESCALE */
  155436. inptr = coef_block;
  155437. quantptr = (IFAST_MULT_TYPE *) compptr->dct_table;
  155438. wsptr = workspace;
  155439. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155440. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155441. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155442. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155443. inptr[DCTSIZE*7] == 0) {
  155444. int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155445. wsptr[DCTSIZE*0] = dcval;
  155446. wsptr[DCTSIZE*1] = dcval;
  155447. wsptr[DCTSIZE*2] = dcval;
  155448. wsptr[DCTSIZE*3] = dcval;
  155449. wsptr[DCTSIZE*4] = dcval;
  155450. wsptr[DCTSIZE*5] = dcval;
  155451. wsptr[DCTSIZE*6] = dcval;
  155452. wsptr[DCTSIZE*7] = dcval;
  155453. inptr++; /* advance pointers to next column */
  155454. quantptr++;
  155455. wsptr++;
  155456. continue;
  155457. }
  155458. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155459. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155460. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155461. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155462. tmp10 = tmp0 + tmp2; /* phase 3 */
  155463. tmp11 = tmp0 - tmp2;
  155464. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155465. tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */
  155466. tmp0 = tmp10 + tmp13; /* phase 2 */
  155467. tmp3 = tmp10 - tmp13;
  155468. tmp1 = tmp11 + tmp12;
  155469. tmp2 = tmp11 - tmp12;
  155470. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155471. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155472. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155473. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155474. z13 = tmp6 + tmp5; /* phase 6 */
  155475. z10 = tmp6 - tmp5;
  155476. z11 = tmp4 + tmp7;
  155477. z12 = tmp4 - tmp7;
  155478. tmp7 = z11 + z13; /* phase 5 */
  155479. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155480. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155481. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155482. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155483. tmp6 = tmp12 - tmp7; /* phase 2 */
  155484. tmp5 = tmp11 - tmp6;
  155485. tmp4 = tmp10 + tmp5;
  155486. wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7);
  155487. wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7);
  155488. wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6);
  155489. wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6);
  155490. wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5);
  155491. wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5);
  155492. wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4);
  155493. wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4);
  155494. inptr++; /* advance pointers to next column */
  155495. quantptr++;
  155496. wsptr++;
  155497. }
  155498. wsptr = workspace;
  155499. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155500. outptr = output_buf[ctr] + output_col;
  155501. #ifndef NO_ZERO_ROW_TEST
  155502. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  155503. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155504. JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3)
  155505. & RANGE_MASK];
  155506. outptr[0] = dcval;
  155507. outptr[1] = dcval;
  155508. outptr[2] = dcval;
  155509. outptr[3] = dcval;
  155510. outptr[4] = dcval;
  155511. outptr[5] = dcval;
  155512. outptr[6] = dcval;
  155513. outptr[7] = dcval;
  155514. wsptr += DCTSIZE; /* advance pointer to next row */
  155515. continue;
  155516. }
  155517. #endif
  155518. tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]);
  155519. tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]);
  155520. tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]);
  155521. tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562)
  155522. - tmp13;
  155523. tmp0 = tmp10 + tmp13;
  155524. tmp3 = tmp10 - tmp13;
  155525. tmp1 = tmp11 + tmp12;
  155526. tmp2 = tmp11 - tmp12;
  155527. z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3];
  155528. z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3];
  155529. z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7];
  155530. z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7];
  155531. tmp7 = z11 + z13; /* phase 5 */
  155532. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155533. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155534. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155535. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155536. tmp6 = tmp12 - tmp7; /* phase 2 */
  155537. tmp5 = tmp11 - tmp6;
  155538. tmp4 = tmp10 + tmp5;
  155539. outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
  155540. & RANGE_MASK];
  155541. outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
  155542. & RANGE_MASK];
  155543. outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
  155544. & RANGE_MASK];
  155545. outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
  155546. & RANGE_MASK];
  155547. outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
  155548. & RANGE_MASK];
  155549. outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
  155550. & RANGE_MASK];
  155551. outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
  155552. & RANGE_MASK];
  155553. outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
  155554. & RANGE_MASK];
  155555. wsptr += DCTSIZE; /* advance pointer to next row */
  155556. }
  155557. }
  155558. #endif /* DCT_IFAST_SUPPORTED */
  155559. /*** End of inlined file: jidctfst.c ***/
  155560. #undef CONST_BITS
  155561. #undef FIX_1_847759065
  155562. #undef MULTIPLY
  155563. #undef DEQUANTIZE
  155564. /*** Start of inlined file: jidctint.c ***/
  155565. #define JPEG_INTERNALS
  155566. #ifdef DCT_ISLOW_SUPPORTED
  155567. #if DCTSIZE != 8
  155568. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155569. #endif
  155570. #if BITS_IN_JSAMPLE == 8
  155571. #define CONST_BITS 13
  155572. #define PASS1_BITS 2
  155573. #else
  155574. #define CONST_BITS 13
  155575. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155576. #endif
  155577. #if CONST_BITS == 13
  155578. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  155579. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  155580. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  155581. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155582. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155583. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  155584. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  155585. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155586. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  155587. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  155588. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155589. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  155590. #else
  155591. #define FIX_0_298631336 FIX(0.298631336)
  155592. #define FIX_0_390180644 FIX(0.390180644)
  155593. #define FIX_0_541196100 FIX(0.541196100)
  155594. #define FIX_0_765366865 FIX(0.765366865)
  155595. #define FIX_0_899976223 FIX(0.899976223)
  155596. #define FIX_1_175875602 FIX(1.175875602)
  155597. #define FIX_1_501321110 FIX(1.501321110)
  155598. #define FIX_1_847759065 FIX(1.847759065)
  155599. #define FIX_1_961570560 FIX(1.961570560)
  155600. #define FIX_2_053119869 FIX(2.053119869)
  155601. #define FIX_2_562915447 FIX(2.562915447)
  155602. #define FIX_3_072711026 FIX(3.072711026)
  155603. #endif
  155604. #if BITS_IN_JSAMPLE == 8
  155605. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155606. #else
  155607. #define MULTIPLY(var,const) ((var) * (const))
  155608. #endif
  155609. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  155610. GLOBAL(void)
  155611. jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155612. JCOEFPTR coef_block,
  155613. JSAMPARRAY output_buf, JDIMENSION output_col)
  155614. {
  155615. INT32 tmp0, tmp1, tmp2, tmp3;
  155616. INT32 tmp10, tmp11, tmp12, tmp13;
  155617. INT32 z1, z2, z3, z4, z5;
  155618. JCOEFPTR inptr;
  155619. ISLOW_MULT_TYPE * quantptr;
  155620. int * wsptr;
  155621. JSAMPROW outptr;
  155622. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155623. int ctr;
  155624. int workspace[DCTSIZE2]; /* buffers data between passes */
  155625. SHIFT_TEMPS
  155626. inptr = coef_block;
  155627. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155628. wsptr = workspace;
  155629. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155630. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155631. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155632. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155633. inptr[DCTSIZE*7] == 0) {
  155634. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  155635. wsptr[DCTSIZE*0] = dcval;
  155636. wsptr[DCTSIZE*1] = dcval;
  155637. wsptr[DCTSIZE*2] = dcval;
  155638. wsptr[DCTSIZE*3] = dcval;
  155639. wsptr[DCTSIZE*4] = dcval;
  155640. wsptr[DCTSIZE*5] = dcval;
  155641. wsptr[DCTSIZE*6] = dcval;
  155642. wsptr[DCTSIZE*7] = dcval;
  155643. inptr++; /* advance pointers to next column */
  155644. quantptr++;
  155645. wsptr++;
  155646. continue;
  155647. }
  155648. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155649. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155650. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  155651. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  155652. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  155653. z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155654. z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155655. tmp0 = (z2 + z3) << CONST_BITS;
  155656. tmp1 = (z2 - z3) << CONST_BITS;
  155657. tmp10 = tmp0 + tmp3;
  155658. tmp13 = tmp0 - tmp3;
  155659. tmp11 = tmp1 + tmp2;
  155660. tmp12 = tmp1 - tmp2;
  155661. tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155662. tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155663. tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155664. tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155665. z1 = tmp0 + tmp3;
  155666. z2 = tmp1 + tmp2;
  155667. z3 = tmp0 + tmp2;
  155668. z4 = tmp1 + tmp3;
  155669. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155670. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155671. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155672. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155673. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155674. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155675. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155676. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155677. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155678. z3 += z5;
  155679. z4 += z5;
  155680. tmp0 += z1 + z3;
  155681. tmp1 += z2 + z4;
  155682. tmp2 += z2 + z3;
  155683. tmp3 += z1 + z4;
  155684. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
  155685. wsptr[DCTSIZE*7] = (int) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
  155686. wsptr[DCTSIZE*1] = (int) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
  155687. wsptr[DCTSIZE*6] = (int) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
  155688. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
  155689. wsptr[DCTSIZE*5] = (int) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
  155690. wsptr[DCTSIZE*3] = (int) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
  155691. wsptr[DCTSIZE*4] = (int) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
  155692. inptr++; /* advance pointers to next column */
  155693. quantptr++;
  155694. wsptr++;
  155695. }
  155696. wsptr = workspace;
  155697. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155698. outptr = output_buf[ctr] + output_col;
  155699. #ifndef NO_ZERO_ROW_TEST
  155700. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  155701. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155702. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  155703. & RANGE_MASK];
  155704. outptr[0] = dcval;
  155705. outptr[1] = dcval;
  155706. outptr[2] = dcval;
  155707. outptr[3] = dcval;
  155708. outptr[4] = dcval;
  155709. outptr[5] = dcval;
  155710. outptr[6] = dcval;
  155711. outptr[7] = dcval;
  155712. wsptr += DCTSIZE; /* advance pointer to next row */
  155713. continue;
  155714. }
  155715. #endif
  155716. z2 = (INT32) wsptr[2];
  155717. z3 = (INT32) wsptr[6];
  155718. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  155719. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  155720. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  155721. tmp0 = ((INT32) wsptr[0] + (INT32) wsptr[4]) << CONST_BITS;
  155722. tmp1 = ((INT32) wsptr[0] - (INT32) wsptr[4]) << CONST_BITS;
  155723. tmp10 = tmp0 + tmp3;
  155724. tmp13 = tmp0 - tmp3;
  155725. tmp11 = tmp1 + tmp2;
  155726. tmp12 = tmp1 - tmp2;
  155727. tmp0 = (INT32) wsptr[7];
  155728. tmp1 = (INT32) wsptr[5];
  155729. tmp2 = (INT32) wsptr[3];
  155730. tmp3 = (INT32) wsptr[1];
  155731. z1 = tmp0 + tmp3;
  155732. z2 = tmp1 + tmp2;
  155733. z3 = tmp0 + tmp2;
  155734. z4 = tmp1 + tmp3;
  155735. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155736. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155737. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155738. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155739. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155740. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155741. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155742. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155743. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155744. z3 += z5;
  155745. z4 += z5;
  155746. tmp0 += z1 + z3;
  155747. tmp1 += z2 + z4;
  155748. tmp2 += z2 + z3;
  155749. tmp3 += z1 + z4;
  155750. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp3,
  155751. CONST_BITS+PASS1_BITS+3)
  155752. & RANGE_MASK];
  155753. outptr[7] = range_limit[(int) DESCALE(tmp10 - tmp3,
  155754. CONST_BITS+PASS1_BITS+3)
  155755. & RANGE_MASK];
  155756. outptr[1] = range_limit[(int) DESCALE(tmp11 + tmp2,
  155757. CONST_BITS+PASS1_BITS+3)
  155758. & RANGE_MASK];
  155759. outptr[6] = range_limit[(int) DESCALE(tmp11 - tmp2,
  155760. CONST_BITS+PASS1_BITS+3)
  155761. & RANGE_MASK];
  155762. outptr[2] = range_limit[(int) DESCALE(tmp12 + tmp1,
  155763. CONST_BITS+PASS1_BITS+3)
  155764. & RANGE_MASK];
  155765. outptr[5] = range_limit[(int) DESCALE(tmp12 - tmp1,
  155766. CONST_BITS+PASS1_BITS+3)
  155767. & RANGE_MASK];
  155768. outptr[3] = range_limit[(int) DESCALE(tmp13 + tmp0,
  155769. CONST_BITS+PASS1_BITS+3)
  155770. & RANGE_MASK];
  155771. outptr[4] = range_limit[(int) DESCALE(tmp13 - tmp0,
  155772. CONST_BITS+PASS1_BITS+3)
  155773. & RANGE_MASK];
  155774. wsptr += DCTSIZE; /* advance pointer to next row */
  155775. }
  155776. }
  155777. #endif /* DCT_ISLOW_SUPPORTED */
  155778. /*** End of inlined file: jidctint.c ***/
  155779. /*** Start of inlined file: jidctred.c ***/
  155780. #define JPEG_INTERNALS
  155781. #ifdef IDCT_SCALING_SUPPORTED
  155782. #if DCTSIZE != 8
  155783. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155784. #endif
  155785. #if BITS_IN_JSAMPLE == 8
  155786. #define CONST_BITS 13
  155787. #define PASS1_BITS 2
  155788. #else
  155789. #define CONST_BITS 13
  155790. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155791. #endif
  155792. #if CONST_BITS == 13
  155793. #define FIX_0_211164243 ((INT32) 1730) /* FIX(0.211164243) */
  155794. #define FIX_0_509795579 ((INT32) 4176) /* FIX(0.509795579) */
  155795. #define FIX_0_601344887 ((INT32) 4926) /* FIX(0.601344887) */
  155796. #define FIX_0_720959822 ((INT32) 5906) /* FIX(0.720959822) */
  155797. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155798. #define FIX_0_850430095 ((INT32) 6967) /* FIX(0.850430095) */
  155799. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155800. #define FIX_1_061594337 ((INT32) 8697) /* FIX(1.061594337) */
  155801. #define FIX_1_272758580 ((INT32) 10426) /* FIX(1.272758580) */
  155802. #define FIX_1_451774981 ((INT32) 11893) /* FIX(1.451774981) */
  155803. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155804. #define FIX_2_172734803 ((INT32) 17799) /* FIX(2.172734803) */
  155805. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155806. #define FIX_3_624509785 ((INT32) 29692) /* FIX(3.624509785) */
  155807. #else
  155808. #define FIX_0_211164243 FIX(0.211164243)
  155809. #define FIX_0_509795579 FIX(0.509795579)
  155810. #define FIX_0_601344887 FIX(0.601344887)
  155811. #define FIX_0_720959822 FIX(0.720959822)
  155812. #define FIX_0_765366865 FIX(0.765366865)
  155813. #define FIX_0_850430095 FIX(0.850430095)
  155814. #define FIX_0_899976223 FIX(0.899976223)
  155815. #define FIX_1_061594337 FIX(1.061594337)
  155816. #define FIX_1_272758580 FIX(1.272758580)
  155817. #define FIX_1_451774981 FIX(1.451774981)
  155818. #define FIX_1_847759065 FIX(1.847759065)
  155819. #define FIX_2_172734803 FIX(2.172734803)
  155820. #define FIX_2_562915447 FIX(2.562915447)
  155821. #define FIX_3_624509785 FIX(3.624509785)
  155822. #endif
  155823. #if BITS_IN_JSAMPLE == 8
  155824. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155825. #else
  155826. #define MULTIPLY(var,const) ((var) * (const))
  155827. #endif
  155828. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  155829. GLOBAL(void)
  155830. jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155831. JCOEFPTR coef_block,
  155832. JSAMPARRAY output_buf, JDIMENSION output_col)
  155833. {
  155834. INT32 tmp0, tmp2, tmp10, tmp12;
  155835. INT32 z1, z2, z3, z4;
  155836. JCOEFPTR inptr;
  155837. ISLOW_MULT_TYPE * quantptr;
  155838. int * wsptr;
  155839. JSAMPROW outptr;
  155840. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155841. int ctr;
  155842. int workspace[DCTSIZE*4]; /* buffers data between passes */
  155843. SHIFT_TEMPS
  155844. inptr = coef_block;
  155845. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155846. wsptr = workspace;
  155847. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  155848. if (ctr == DCTSIZE-4)
  155849. continue;
  155850. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155851. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*5] == 0 &&
  155852. inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) {
  155853. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  155854. wsptr[DCTSIZE*0] = dcval;
  155855. wsptr[DCTSIZE*1] = dcval;
  155856. wsptr[DCTSIZE*2] = dcval;
  155857. wsptr[DCTSIZE*3] = dcval;
  155858. continue;
  155859. }
  155860. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155861. tmp0 <<= (CONST_BITS+1);
  155862. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155863. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155864. tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865);
  155865. tmp10 = tmp0 + tmp2;
  155866. tmp12 = tmp0 - tmp2;
  155867. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155868. z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155869. z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155870. z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155871. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  155872. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  155873. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  155874. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  155875. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  155876. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  155877. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  155878. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  155879. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1);
  155880. wsptr[DCTSIZE*3] = (int) DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1);
  155881. wsptr[DCTSIZE*1] = (int) DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1);
  155882. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1);
  155883. }
  155884. wsptr = workspace;
  155885. for (ctr = 0; ctr < 4; ctr++) {
  155886. outptr = output_buf[ctr] + output_col;
  155887. #ifndef NO_ZERO_ROW_TEST
  155888. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 &&
  155889. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155890. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  155891. & RANGE_MASK];
  155892. outptr[0] = dcval;
  155893. outptr[1] = dcval;
  155894. outptr[2] = dcval;
  155895. outptr[3] = dcval;
  155896. wsptr += DCTSIZE; /* advance pointer to next row */
  155897. continue;
  155898. }
  155899. #endif
  155900. tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1);
  155901. tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065)
  155902. + MULTIPLY((INT32) wsptr[6], - FIX_0_765366865);
  155903. tmp10 = tmp0 + tmp2;
  155904. tmp12 = tmp0 - tmp2;
  155905. z1 = (INT32) wsptr[7];
  155906. z2 = (INT32) wsptr[5];
  155907. z3 = (INT32) wsptr[3];
  155908. z4 = (INT32) wsptr[1];
  155909. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  155910. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  155911. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  155912. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  155913. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  155914. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  155915. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  155916. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  155917. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2,
  155918. CONST_BITS+PASS1_BITS+3+1)
  155919. & RANGE_MASK];
  155920. outptr[3] = range_limit[(int) DESCALE(tmp10 - tmp2,
  155921. CONST_BITS+PASS1_BITS+3+1)
  155922. & RANGE_MASK];
  155923. outptr[1] = range_limit[(int) DESCALE(tmp12 + tmp0,
  155924. CONST_BITS+PASS1_BITS+3+1)
  155925. & RANGE_MASK];
  155926. outptr[2] = range_limit[(int) DESCALE(tmp12 - tmp0,
  155927. CONST_BITS+PASS1_BITS+3+1)
  155928. & RANGE_MASK];
  155929. wsptr += DCTSIZE; /* advance pointer to next row */
  155930. }
  155931. }
  155932. GLOBAL(void)
  155933. jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155934. JCOEFPTR coef_block,
  155935. JSAMPARRAY output_buf, JDIMENSION output_col)
  155936. {
  155937. INT32 tmp0, tmp10, z1;
  155938. JCOEFPTR inptr;
  155939. ISLOW_MULT_TYPE * quantptr;
  155940. int * wsptr;
  155941. JSAMPROW outptr;
  155942. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155943. int ctr;
  155944. int workspace[DCTSIZE*2]; /* buffers data between passes */
  155945. SHIFT_TEMPS
  155946. inptr = coef_block;
  155947. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155948. wsptr = workspace;
  155949. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  155950. if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6)
  155951. continue;
  155952. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*3] == 0 &&
  155953. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*7] == 0) {
  155954. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  155955. wsptr[DCTSIZE*0] = dcval;
  155956. wsptr[DCTSIZE*1] = dcval;
  155957. continue;
  155958. }
  155959. z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155960. tmp10 = z1 << (CONST_BITS+2);
  155961. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155962. tmp0 = MULTIPLY(z1, - FIX_0_720959822); /* sqrt(2) * (c7-c5+c3-c1) */
  155963. z1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155964. tmp0 += MULTIPLY(z1, FIX_0_850430095); /* sqrt(2) * (-c1+c3+c5+c7) */
  155965. z1 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155966. tmp0 += MULTIPLY(z1, - FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */
  155967. z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155968. tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  155969. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2);
  155970. wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2);
  155971. }
  155972. wsptr = workspace;
  155973. for (ctr = 0; ctr < 2; ctr++) {
  155974. outptr = output_buf[ctr] + output_col;
  155975. #ifndef NO_ZERO_ROW_TEST
  155976. if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) {
  155977. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  155978. & RANGE_MASK];
  155979. outptr[0] = dcval;
  155980. outptr[1] = dcval;
  155981. wsptr += DCTSIZE; /* advance pointer to next row */
  155982. continue;
  155983. }
  155984. #endif
  155985. tmp10 = ((INT32) wsptr[0]) << (CONST_BITS+2);
  155986. tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */
  155987. + MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */
  155988. + MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */
  155989. + MULTIPLY((INT32) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  155990. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0,
  155991. CONST_BITS+PASS1_BITS+3+2)
  155992. & RANGE_MASK];
  155993. outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0,
  155994. CONST_BITS+PASS1_BITS+3+2)
  155995. & RANGE_MASK];
  155996. wsptr += DCTSIZE; /* advance pointer to next row */
  155997. }
  155998. }
  155999. GLOBAL(void)
  156000. jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156001. JCOEFPTR coef_block,
  156002. JSAMPARRAY output_buf, JDIMENSION output_col)
  156003. {
  156004. int dcval;
  156005. ISLOW_MULT_TYPE * quantptr;
  156006. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156007. SHIFT_TEMPS
  156008. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156009. dcval = DEQUANTIZE(coef_block[0], quantptr[0]);
  156010. dcval = (int) DESCALE((INT32) dcval, 3);
  156011. output_buf[0][output_col] = range_limit[dcval & RANGE_MASK];
  156012. }
  156013. #endif /* IDCT_SCALING_SUPPORTED */
  156014. /*** End of inlined file: jidctred.c ***/
  156015. /*** Start of inlined file: jmemmgr.c ***/
  156016. #define JPEG_INTERNALS
  156017. #define AM_MEMORY_MANAGER /* we define jvirt_Xarray_control structs */
  156018. /*** Start of inlined file: jmemsys.h ***/
  156019. #ifndef __jmemsys_h__
  156020. #define __jmemsys_h__
  156021. #ifdef NEED_SHORT_EXTERNAL_NAMES
  156022. #define jpeg_get_small jGetSmall
  156023. #define jpeg_free_small jFreeSmall
  156024. #define jpeg_get_large jGetLarge
  156025. #define jpeg_free_large jFreeLarge
  156026. #define jpeg_mem_available jMemAvail
  156027. #define jpeg_open_backing_store jOpenBackStore
  156028. #define jpeg_mem_init jMemInit
  156029. #define jpeg_mem_term jMemTerm
  156030. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  156031. EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject));
  156032. EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object,
  156033. size_t sizeofobject));
  156034. EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo,
  156035. size_t sizeofobject));
  156036. EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
  156037. size_t sizeofobject));
  156038. #ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */
  156039. #define MAX_ALLOC_CHUNK 1000000000L
  156040. #endif
  156041. EXTERN(long) jpeg_mem_available JPP((j_common_ptr cinfo,
  156042. long min_bytes_needed,
  156043. long max_bytes_needed,
  156044. long already_allocated));
  156045. #define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */
  156046. #ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */
  156047. typedef unsigned short XMSH; /* type of extended-memory handles */
  156048. typedef unsigned short EMSH; /* type of expanded-memory handles */
  156049. typedef union {
  156050. short file_handle; /* DOS file handle if it's a temp file */
  156051. XMSH xms_handle; /* handle if it's a chunk of XMS */
  156052. EMSH ems_handle; /* handle if it's a chunk of EMS */
  156053. } handle_union;
  156054. #endif /* USE_MSDOS_MEMMGR */
  156055. #ifdef USE_MAC_MEMMGR /* Mac-specific junk */
  156056. #include <Files.h>
  156057. #endif /* USE_MAC_MEMMGR */
  156058. //typedef struct backing_store_struct * backing_store_ptr;
  156059. typedef struct backing_store_struct {
  156060. JMETHOD(void, read_backing_store, (j_common_ptr cinfo,
  156061. struct backing_store_struct *info,
  156062. void FAR * buffer_address,
  156063. long file_offset, long byte_count));
  156064. JMETHOD(void, write_backing_store, (j_common_ptr cinfo,
  156065. struct backing_store_struct *info,
  156066. void FAR * buffer_address,
  156067. long file_offset, long byte_count));
  156068. JMETHOD(void, close_backing_store, (j_common_ptr cinfo,
  156069. struct backing_store_struct *info));
  156070. #ifdef USE_MSDOS_MEMMGR
  156071. handle_union handle; /* reference to backing-store storage object */
  156072. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156073. #else
  156074. #ifdef USE_MAC_MEMMGR
  156075. short temp_file; /* file reference number to temp file */
  156076. FSSpec tempSpec; /* the FSSpec for the temp file */
  156077. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156078. #else
  156079. FILE * temp_file; /* stdio reference to temp file */
  156080. char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */
  156081. #endif
  156082. #endif
  156083. } backing_store_info;
  156084. EXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo,
  156085. struct backing_store_struct *info,
  156086. long total_bytes_needed));
  156087. EXTERN(long) jpeg_mem_init JPP((j_common_ptr cinfo));
  156088. EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo));
  156089. #endif
  156090. /*** End of inlined file: jmemsys.h ***/
  156091. /* import the system-dependent declarations */
  156092. #ifndef NO_GETENV
  156093. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare getenv() */
  156094. extern char * getenv JPP((const char * name));
  156095. #endif
  156096. #endif
  156097. #ifndef ALIGN_TYPE /* so can override from jconfig.h */
  156098. #define ALIGN_TYPE double
  156099. #endif
  156100. typedef union small_pool_struct * small_pool_ptr;
  156101. typedef union small_pool_struct {
  156102. struct {
  156103. small_pool_ptr next; /* next in list of pools */
  156104. size_t bytes_used; /* how many bytes already used within pool */
  156105. size_t bytes_left; /* bytes still available in this pool */
  156106. } hdr;
  156107. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156108. } small_pool_hdr;
  156109. typedef union large_pool_struct FAR * large_pool_ptr;
  156110. typedef union large_pool_struct {
  156111. struct {
  156112. large_pool_ptr next; /* next in list of pools */
  156113. size_t bytes_used; /* how many bytes already used within pool */
  156114. size_t bytes_left; /* bytes still available in this pool */
  156115. } hdr;
  156116. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156117. } large_pool_hdr;
  156118. typedef struct {
  156119. struct jpeg_memory_mgr pub; /* public fields */
  156120. small_pool_ptr small_list[JPOOL_NUMPOOLS];
  156121. large_pool_ptr large_list[JPOOL_NUMPOOLS];
  156122. jvirt_sarray_ptr virt_sarray_list;
  156123. jvirt_barray_ptr virt_barray_list;
  156124. long total_space_allocated;
  156125. JDIMENSION last_rowsperchunk; /* from most recent alloc_sarray/barray */
  156126. } my_memory_mgr;
  156127. typedef my_memory_mgr * my_mem_ptr;
  156128. struct jvirt_sarray_control {
  156129. JSAMPARRAY mem_buffer; /* => the in-memory buffer */
  156130. JDIMENSION rows_in_array; /* total virtual array height */
  156131. JDIMENSION samplesperrow; /* width of array (and of memory buffer) */
  156132. JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */
  156133. JDIMENSION rows_in_mem; /* height of memory buffer */
  156134. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156135. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156136. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156137. boolean pre_zero; /* pre-zero mode requested? */
  156138. boolean dirty; /* do current buffer contents need written? */
  156139. boolean b_s_open; /* is backing-store data valid? */
  156140. jvirt_sarray_ptr next; /* link to next virtual sarray control block */
  156141. backing_store_info b_s_info; /* System-dependent control info */
  156142. };
  156143. struct jvirt_barray_control {
  156144. JBLOCKARRAY mem_buffer; /* => the in-memory buffer */
  156145. JDIMENSION rows_in_array; /* total virtual array height */
  156146. JDIMENSION blocksperrow; /* width of array (and of memory buffer) */
  156147. JDIMENSION maxaccess; /* max rows accessed by access_virt_barray */
  156148. JDIMENSION rows_in_mem; /* height of memory buffer */
  156149. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156150. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156151. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156152. boolean pre_zero; /* pre-zero mode requested? */
  156153. boolean dirty; /* do current buffer contents need written? */
  156154. boolean b_s_open; /* is backing-store data valid? */
  156155. jvirt_barray_ptr next; /* link to next virtual barray control block */
  156156. backing_store_info b_s_info; /* System-dependent control info */
  156157. };
  156158. #ifdef MEM_STATS /* optional extra stuff for statistics */
  156159. LOCAL(void)
  156160. print_mem_stats (j_common_ptr cinfo, int pool_id)
  156161. {
  156162. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156163. small_pool_ptr shdr_ptr;
  156164. large_pool_ptr lhdr_ptr;
  156165. fprintf(stderr, "Freeing pool %d, total space = %ld\n",
  156166. pool_id, mem->total_space_allocated);
  156167. for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;
  156168. lhdr_ptr = lhdr_ptr->hdr.next) {
  156169. fprintf(stderr, " Large chunk used %ld\n",
  156170. (long) lhdr_ptr->hdr.bytes_used);
  156171. }
  156172. for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL;
  156173. shdr_ptr = shdr_ptr->hdr.next) {
  156174. fprintf(stderr, " Small chunk used %ld free %ld\n",
  156175. (long) shdr_ptr->hdr.bytes_used,
  156176. (long) shdr_ptr->hdr.bytes_left);
  156177. }
  156178. }
  156179. #endif /* MEM_STATS */
  156180. LOCAL(void)
  156181. out_of_memory (j_common_ptr cinfo, int which)
  156182. {
  156183. #ifdef MEM_STATS
  156184. cinfo->err->trace_level = 2; /* force self_destruct to report stats */
  156185. #endif
  156186. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which);
  156187. }
  156188. static const size_t first_pool_slop[JPOOL_NUMPOOLS] =
  156189. {
  156190. 1600, /* first PERMANENT pool */
  156191. 16000 /* first IMAGE pool */
  156192. };
  156193. static const size_t extra_pool_slop[JPOOL_NUMPOOLS] =
  156194. {
  156195. 0, /* additional PERMANENT pools */
  156196. 5000 /* additional IMAGE pools */
  156197. };
  156198. #define MIN_SLOP 50 /* greater than 0 to avoid futile looping */
  156199. METHODDEF(void *)
  156200. alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156201. {
  156202. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156203. small_pool_ptr hdr_ptr, prev_hdr_ptr;
  156204. char * data_ptr;
  156205. size_t odd_bytes, min_request, slop;
  156206. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(small_pool_hdr)))
  156207. out_of_memory(cinfo, 1); /* request exceeds malloc's ability */
  156208. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156209. if (odd_bytes > 0)
  156210. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156211. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156212. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156213. prev_hdr_ptr = NULL;
  156214. hdr_ptr = mem->small_list[pool_id];
  156215. while (hdr_ptr != NULL) {
  156216. if (hdr_ptr->hdr.bytes_left >= sizeofobject)
  156217. break; /* found pool with enough space */
  156218. prev_hdr_ptr = hdr_ptr;
  156219. hdr_ptr = hdr_ptr->hdr.next;
  156220. }
  156221. if (hdr_ptr == NULL) {
  156222. min_request = sizeofobject + SIZEOF(small_pool_hdr);
  156223. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156224. slop = first_pool_slop[pool_id];
  156225. else
  156226. slop = extra_pool_slop[pool_id];
  156227. if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request))
  156228. slop = (size_t) (MAX_ALLOC_CHUNK-min_request);
  156229. for (;;) {
  156230. hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop);
  156231. if (hdr_ptr != NULL)
  156232. break;
  156233. slop /= 2;
  156234. if (slop < MIN_SLOP) /* give up when it gets real small */
  156235. out_of_memory(cinfo, 2); /* jpeg_get_small failed */
  156236. }
  156237. mem->total_space_allocated += min_request + slop;
  156238. hdr_ptr->hdr.next = NULL;
  156239. hdr_ptr->hdr.bytes_used = 0;
  156240. hdr_ptr->hdr.bytes_left = sizeofobject + slop;
  156241. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156242. mem->small_list[pool_id] = hdr_ptr;
  156243. else
  156244. prev_hdr_ptr->hdr.next = hdr_ptr;
  156245. }
  156246. data_ptr = (char *) (hdr_ptr + 1); /* point to first data byte in pool */
  156247. data_ptr += hdr_ptr->hdr.bytes_used; /* point to place for object */
  156248. hdr_ptr->hdr.bytes_used += sizeofobject;
  156249. hdr_ptr->hdr.bytes_left -= sizeofobject;
  156250. return (void *) data_ptr;
  156251. }
  156252. METHODDEF(void FAR *)
  156253. alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156254. {
  156255. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156256. large_pool_ptr hdr_ptr;
  156257. size_t odd_bytes;
  156258. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)))
  156259. out_of_memory(cinfo, 3); /* request exceeds malloc's ability */
  156260. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156261. if (odd_bytes > 0)
  156262. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156263. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156264. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156265. hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject +
  156266. SIZEOF(large_pool_hdr));
  156267. if (hdr_ptr == NULL)
  156268. out_of_memory(cinfo, 4); /* jpeg_get_large failed */
  156269. mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr);
  156270. hdr_ptr->hdr.next = mem->large_list[pool_id];
  156271. hdr_ptr->hdr.bytes_used = sizeofobject;
  156272. hdr_ptr->hdr.bytes_left = 0;
  156273. mem->large_list[pool_id] = hdr_ptr;
  156274. return (void FAR *) (hdr_ptr + 1); /* point to first data byte in pool */
  156275. }
  156276. METHODDEF(JSAMPARRAY)
  156277. alloc_sarray (j_common_ptr cinfo, int pool_id,
  156278. JDIMENSION samplesperrow, JDIMENSION numrows)
  156279. {
  156280. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156281. JSAMPARRAY result;
  156282. JSAMPROW workspace;
  156283. JDIMENSION rowsperchunk, currow, i;
  156284. long ltemp;
  156285. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156286. ((long) samplesperrow * SIZEOF(JSAMPLE));
  156287. if (ltemp <= 0)
  156288. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156289. if (ltemp < (long) numrows)
  156290. rowsperchunk = (JDIMENSION) ltemp;
  156291. else
  156292. rowsperchunk = numrows;
  156293. mem->last_rowsperchunk = rowsperchunk;
  156294. result = (JSAMPARRAY) alloc_small(cinfo, pool_id,
  156295. (size_t) (numrows * SIZEOF(JSAMPROW)));
  156296. currow = 0;
  156297. while (currow < numrows) {
  156298. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156299. workspace = (JSAMPROW) alloc_large(cinfo, pool_id,
  156300. (size_t) ((size_t) rowsperchunk * (size_t) samplesperrow
  156301. * SIZEOF(JSAMPLE)));
  156302. for (i = rowsperchunk; i > 0; i--) {
  156303. result[currow++] = workspace;
  156304. workspace += samplesperrow;
  156305. }
  156306. }
  156307. return result;
  156308. }
  156309. METHODDEF(JBLOCKARRAY)
  156310. alloc_barray (j_common_ptr cinfo, int pool_id,
  156311. JDIMENSION blocksperrow, JDIMENSION numrows)
  156312. {
  156313. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156314. JBLOCKARRAY result;
  156315. JBLOCKROW workspace;
  156316. JDIMENSION rowsperchunk, currow, i;
  156317. long ltemp;
  156318. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156319. ((long) blocksperrow * SIZEOF(JBLOCK));
  156320. if (ltemp <= 0)
  156321. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156322. if (ltemp < (long) numrows)
  156323. rowsperchunk = (JDIMENSION) ltemp;
  156324. else
  156325. rowsperchunk = numrows;
  156326. mem->last_rowsperchunk = rowsperchunk;
  156327. result = (JBLOCKARRAY) alloc_small(cinfo, pool_id,
  156328. (size_t) (numrows * SIZEOF(JBLOCKROW)));
  156329. currow = 0;
  156330. while (currow < numrows) {
  156331. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156332. workspace = (JBLOCKROW) alloc_large(cinfo, pool_id,
  156333. (size_t) ((size_t) rowsperchunk * (size_t) blocksperrow
  156334. * SIZEOF(JBLOCK)));
  156335. for (i = rowsperchunk; i > 0; i--) {
  156336. result[currow++] = workspace;
  156337. workspace += blocksperrow;
  156338. }
  156339. }
  156340. return result;
  156341. }
  156342. METHODDEF(jvirt_sarray_ptr)
  156343. request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156344. JDIMENSION samplesperrow, JDIMENSION numrows,
  156345. JDIMENSION maxaccess)
  156346. {
  156347. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156348. jvirt_sarray_ptr result;
  156349. if (pool_id != JPOOL_IMAGE)
  156350. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156351. result = (jvirt_sarray_ptr) alloc_small(cinfo, pool_id,
  156352. SIZEOF(struct jvirt_sarray_control));
  156353. result->mem_buffer = NULL; /* marks array not yet realized */
  156354. result->rows_in_array = numrows;
  156355. result->samplesperrow = samplesperrow;
  156356. result->maxaccess = maxaccess;
  156357. result->pre_zero = pre_zero;
  156358. result->b_s_open = FALSE; /* no associated backing-store object */
  156359. result->next = mem->virt_sarray_list; /* add to list of virtual arrays */
  156360. mem->virt_sarray_list = result;
  156361. return result;
  156362. }
  156363. METHODDEF(jvirt_barray_ptr)
  156364. request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156365. JDIMENSION blocksperrow, JDIMENSION numrows,
  156366. JDIMENSION maxaccess)
  156367. {
  156368. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156369. jvirt_barray_ptr result;
  156370. if (pool_id != JPOOL_IMAGE)
  156371. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156372. result = (jvirt_barray_ptr) alloc_small(cinfo, pool_id,
  156373. SIZEOF(struct jvirt_barray_control));
  156374. result->mem_buffer = NULL; /* marks array not yet realized */
  156375. result->rows_in_array = numrows;
  156376. result->blocksperrow = blocksperrow;
  156377. result->maxaccess = maxaccess;
  156378. result->pre_zero = pre_zero;
  156379. result->b_s_open = FALSE; /* no associated backing-store object */
  156380. result->next = mem->virt_barray_list; /* add to list of virtual arrays */
  156381. mem->virt_barray_list = result;
  156382. return result;
  156383. }
  156384. METHODDEF(void)
  156385. realize_virt_arrays (j_common_ptr cinfo)
  156386. {
  156387. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156388. long space_per_minheight, maximum_space, avail_mem;
  156389. long minheights, max_minheights;
  156390. jvirt_sarray_ptr sptr;
  156391. jvirt_barray_ptr bptr;
  156392. space_per_minheight = 0;
  156393. maximum_space = 0;
  156394. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156395. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156396. space_per_minheight += (long) sptr->maxaccess *
  156397. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156398. maximum_space += (long) sptr->rows_in_array *
  156399. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156400. }
  156401. }
  156402. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156403. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156404. space_per_minheight += (long) bptr->maxaccess *
  156405. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156406. maximum_space += (long) bptr->rows_in_array *
  156407. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156408. }
  156409. }
  156410. if (space_per_minheight <= 0)
  156411. return; /* no unrealized arrays, no work */
  156412. avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space,
  156413. mem->total_space_allocated);
  156414. if (avail_mem >= maximum_space)
  156415. max_minheights = 1000000000L;
  156416. else {
  156417. max_minheights = avail_mem / space_per_minheight;
  156418. if (max_minheights <= 0)
  156419. max_minheights = 1;
  156420. }
  156421. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156422. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156423. minheights = ((long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L;
  156424. if (minheights <= max_minheights) {
  156425. sptr->rows_in_mem = sptr->rows_in_array;
  156426. } else {
  156427. sptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess);
  156428. jpeg_open_backing_store(cinfo, & sptr->b_s_info,
  156429. (long) sptr->rows_in_array *
  156430. (long) sptr->samplesperrow *
  156431. (long) SIZEOF(JSAMPLE));
  156432. sptr->b_s_open = TRUE;
  156433. }
  156434. sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE,
  156435. sptr->samplesperrow, sptr->rows_in_mem);
  156436. sptr->rowsperchunk = mem->last_rowsperchunk;
  156437. sptr->cur_start_row = 0;
  156438. sptr->first_undef_row = 0;
  156439. sptr->dirty = FALSE;
  156440. }
  156441. }
  156442. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156443. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156444. minheights = ((long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L;
  156445. if (minheights <= max_minheights) {
  156446. bptr->rows_in_mem = bptr->rows_in_array;
  156447. } else {
  156448. bptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess);
  156449. jpeg_open_backing_store(cinfo, & bptr->b_s_info,
  156450. (long) bptr->rows_in_array *
  156451. (long) bptr->blocksperrow *
  156452. (long) SIZEOF(JBLOCK));
  156453. bptr->b_s_open = TRUE;
  156454. }
  156455. bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE,
  156456. bptr->blocksperrow, bptr->rows_in_mem);
  156457. bptr->rowsperchunk = mem->last_rowsperchunk;
  156458. bptr->cur_start_row = 0;
  156459. bptr->first_undef_row = 0;
  156460. bptr->dirty = FALSE;
  156461. }
  156462. }
  156463. }
  156464. LOCAL(void)
  156465. do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
  156466. {
  156467. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156468. bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156469. file_offset = ptr->cur_start_row * bytesperrow;
  156470. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156471. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156472. thisrow = (long) ptr->cur_start_row + i;
  156473. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156474. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156475. if (rows <= 0) /* this chunk might be past end of file! */
  156476. break;
  156477. byte_count = rows * bytesperrow;
  156478. if (writing)
  156479. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156480. (void FAR *) ptr->mem_buffer[i],
  156481. file_offset, byte_count);
  156482. else
  156483. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156484. (void FAR *) ptr->mem_buffer[i],
  156485. file_offset, byte_count);
  156486. file_offset += byte_count;
  156487. }
  156488. }
  156489. LOCAL(void)
  156490. do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
  156491. {
  156492. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156493. bytesperrow = (long) ptr->blocksperrow * SIZEOF(JBLOCK);
  156494. file_offset = ptr->cur_start_row * bytesperrow;
  156495. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156496. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156497. thisrow = (long) ptr->cur_start_row + i;
  156498. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156499. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156500. if (rows <= 0) /* this chunk might be past end of file! */
  156501. break;
  156502. byte_count = rows * bytesperrow;
  156503. if (writing)
  156504. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156505. (void FAR *) ptr->mem_buffer[i],
  156506. file_offset, byte_count);
  156507. else
  156508. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156509. (void FAR *) ptr->mem_buffer[i],
  156510. file_offset, byte_count);
  156511. file_offset += byte_count;
  156512. }
  156513. }
  156514. METHODDEF(JSAMPARRAY)
  156515. access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
  156516. JDIMENSION start_row, JDIMENSION num_rows,
  156517. boolean writable)
  156518. {
  156519. JDIMENSION end_row = start_row + num_rows;
  156520. JDIMENSION undef_row;
  156521. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  156522. ptr->mem_buffer == NULL)
  156523. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156524. if (start_row < ptr->cur_start_row ||
  156525. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  156526. if (! ptr->b_s_open)
  156527. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  156528. if (ptr->dirty) {
  156529. do_sarray_io(cinfo, ptr, TRUE);
  156530. ptr->dirty = FALSE;
  156531. }
  156532. if (start_row > ptr->cur_start_row) {
  156533. ptr->cur_start_row = start_row;
  156534. } else {
  156535. long ltemp;
  156536. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  156537. if (ltemp < 0)
  156538. ltemp = 0; /* don't fall off front end of file */
  156539. ptr->cur_start_row = (JDIMENSION) ltemp;
  156540. }
  156541. do_sarray_io(cinfo, ptr, FALSE);
  156542. }
  156543. if (ptr->first_undef_row < end_row) {
  156544. if (ptr->first_undef_row < start_row) {
  156545. if (writable) /* writer skipped over a section of array */
  156546. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156547. undef_row = start_row; /* but reader is allowed to read ahead */
  156548. } else {
  156549. undef_row = ptr->first_undef_row;
  156550. }
  156551. if (writable)
  156552. ptr->first_undef_row = end_row;
  156553. if (ptr->pre_zero) {
  156554. size_t bytesperrow = (size_t) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156555. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  156556. end_row -= ptr->cur_start_row;
  156557. while (undef_row < end_row) {
  156558. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  156559. undef_row++;
  156560. }
  156561. } else {
  156562. if (! writable) /* reader looking at undefined data */
  156563. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156564. }
  156565. }
  156566. if (writable)
  156567. ptr->dirty = TRUE;
  156568. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  156569. }
  156570. METHODDEF(JBLOCKARRAY)
  156571. access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
  156572. JDIMENSION start_row, JDIMENSION num_rows,
  156573. boolean writable)
  156574. {
  156575. JDIMENSION end_row = start_row + num_rows;
  156576. JDIMENSION undef_row;
  156577. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  156578. ptr->mem_buffer == NULL)
  156579. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156580. if (start_row < ptr->cur_start_row ||
  156581. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  156582. if (! ptr->b_s_open)
  156583. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  156584. if (ptr->dirty) {
  156585. do_barray_io(cinfo, ptr, TRUE);
  156586. ptr->dirty = FALSE;
  156587. }
  156588. if (start_row > ptr->cur_start_row) {
  156589. ptr->cur_start_row = start_row;
  156590. } else {
  156591. long ltemp;
  156592. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  156593. if (ltemp < 0)
  156594. ltemp = 0; /* don't fall off front end of file */
  156595. ptr->cur_start_row = (JDIMENSION) ltemp;
  156596. }
  156597. do_barray_io(cinfo, ptr, FALSE);
  156598. }
  156599. if (ptr->first_undef_row < end_row) {
  156600. if (ptr->first_undef_row < start_row) {
  156601. if (writable) /* writer skipped over a section of array */
  156602. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156603. undef_row = start_row; /* but reader is allowed to read ahead */
  156604. } else {
  156605. undef_row = ptr->first_undef_row;
  156606. }
  156607. if (writable)
  156608. ptr->first_undef_row = end_row;
  156609. if (ptr->pre_zero) {
  156610. size_t bytesperrow = (size_t) ptr->blocksperrow * SIZEOF(JBLOCK);
  156611. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  156612. end_row -= ptr->cur_start_row;
  156613. while (undef_row < end_row) {
  156614. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  156615. undef_row++;
  156616. }
  156617. } else {
  156618. if (! writable) /* reader looking at undefined data */
  156619. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156620. }
  156621. }
  156622. if (writable)
  156623. ptr->dirty = TRUE;
  156624. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  156625. }
  156626. METHODDEF(void)
  156627. free_pool (j_common_ptr cinfo, int pool_id)
  156628. {
  156629. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156630. small_pool_ptr shdr_ptr;
  156631. large_pool_ptr lhdr_ptr;
  156632. size_t space_freed;
  156633. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156634. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156635. #ifdef MEM_STATS
  156636. if (cinfo->err->trace_level > 1)
  156637. print_mem_stats(cinfo, pool_id); /* print pool's memory usage statistics */
  156638. #endif
  156639. if (pool_id == JPOOL_IMAGE) {
  156640. jvirt_sarray_ptr sptr;
  156641. jvirt_barray_ptr bptr;
  156642. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156643. if (sptr->b_s_open) { /* there may be no backing store */
  156644. sptr->b_s_open = FALSE; /* prevent recursive close if error */
  156645. (*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info);
  156646. }
  156647. }
  156648. mem->virt_sarray_list = NULL;
  156649. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156650. if (bptr->b_s_open) { /* there may be no backing store */
  156651. bptr->b_s_open = FALSE; /* prevent recursive close if error */
  156652. (*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info);
  156653. }
  156654. }
  156655. mem->virt_barray_list = NULL;
  156656. }
  156657. lhdr_ptr = mem->large_list[pool_id];
  156658. mem->large_list[pool_id] = NULL;
  156659. while (lhdr_ptr != NULL) {
  156660. large_pool_ptr next_lhdr_ptr = lhdr_ptr->hdr.next;
  156661. space_freed = lhdr_ptr->hdr.bytes_used +
  156662. lhdr_ptr->hdr.bytes_left +
  156663. SIZEOF(large_pool_hdr);
  156664. jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed);
  156665. mem->total_space_allocated -= space_freed;
  156666. lhdr_ptr = next_lhdr_ptr;
  156667. }
  156668. shdr_ptr = mem->small_list[pool_id];
  156669. mem->small_list[pool_id] = NULL;
  156670. while (shdr_ptr != NULL) {
  156671. small_pool_ptr next_shdr_ptr = shdr_ptr->hdr.next;
  156672. space_freed = shdr_ptr->hdr.bytes_used +
  156673. shdr_ptr->hdr.bytes_left +
  156674. SIZEOF(small_pool_hdr);
  156675. jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed);
  156676. mem->total_space_allocated -= space_freed;
  156677. shdr_ptr = next_shdr_ptr;
  156678. }
  156679. }
  156680. METHODDEF(void)
  156681. self_destruct (j_common_ptr cinfo)
  156682. {
  156683. int pool;
  156684. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  156685. free_pool(cinfo, pool);
  156686. }
  156687. jpeg_free_small(cinfo, (void *) cinfo->mem, SIZEOF(my_memory_mgr));
  156688. cinfo->mem = NULL; /* ensures I will be called only once */
  156689. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  156690. }
  156691. GLOBAL(void)
  156692. jinit_memory_mgr (j_common_ptr cinfo)
  156693. {
  156694. my_mem_ptr mem;
  156695. long max_to_use;
  156696. int pool;
  156697. size_t test_mac;
  156698. cinfo->mem = NULL; /* for safety if init fails */
  156699. if ((SIZEOF(ALIGN_TYPE) & (SIZEOF(ALIGN_TYPE)-1)) != 0)
  156700. ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);
  156701. test_mac = (size_t) MAX_ALLOC_CHUNK;
  156702. if ((long) test_mac != MAX_ALLOC_CHUNK ||
  156703. (MAX_ALLOC_CHUNK % SIZEOF(ALIGN_TYPE)) != 0)
  156704. ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
  156705. max_to_use = jpeg_mem_init(cinfo); /* system-dependent initialization */
  156706. mem = (my_mem_ptr) jpeg_get_small(cinfo, SIZEOF(my_memory_mgr));
  156707. if (mem == NULL) {
  156708. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  156709. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
  156710. }
  156711. mem->pub.alloc_small = alloc_small;
  156712. mem->pub.alloc_large = alloc_large;
  156713. mem->pub.alloc_sarray = alloc_sarray;
  156714. mem->pub.alloc_barray = alloc_barray;
  156715. mem->pub.request_virt_sarray = request_virt_sarray;
  156716. mem->pub.request_virt_barray = request_virt_barray;
  156717. mem->pub.realize_virt_arrays = realize_virt_arrays;
  156718. mem->pub.access_virt_sarray = access_virt_sarray;
  156719. mem->pub.access_virt_barray = access_virt_barray;
  156720. mem->pub.free_pool = free_pool;
  156721. mem->pub.self_destruct = self_destruct;
  156722. mem->pub.max_alloc_chunk = MAX_ALLOC_CHUNK;
  156723. mem->pub.max_memory_to_use = max_to_use;
  156724. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  156725. mem->small_list[pool] = NULL;
  156726. mem->large_list[pool] = NULL;
  156727. }
  156728. mem->virt_sarray_list = NULL;
  156729. mem->virt_barray_list = NULL;
  156730. mem->total_space_allocated = SIZEOF(my_memory_mgr);
  156731. cinfo->mem = & mem->pub;
  156732. #ifndef NO_GETENV
  156733. { char * memenv;
  156734. if ((memenv = getenv("JPEGMEM")) != NULL) {
  156735. char ch = 'x';
  156736. if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) {
  156737. if (ch == 'm' || ch == 'M')
  156738. max_to_use *= 1000L;
  156739. mem->pub.max_memory_to_use = max_to_use * 1000L;
  156740. }
  156741. }
  156742. }
  156743. #endif
  156744. }
  156745. /*** End of inlined file: jmemmgr.c ***/
  156746. /*** Start of inlined file: jmemnobs.c ***/
  156747. #define JPEG_INTERNALS
  156748. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
  156749. extern void * malloc JPP((size_t size));
  156750. extern void free JPP((void *ptr));
  156751. #endif
  156752. GLOBAL(void *)
  156753. jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
  156754. {
  156755. return (void *) malloc(sizeofobject);
  156756. }
  156757. GLOBAL(void)
  156758. jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
  156759. {
  156760. free(object);
  156761. }
  156762. GLOBAL(void FAR *)
  156763. jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
  156764. {
  156765. return (void FAR *) malloc(sizeofobject);
  156766. }
  156767. GLOBAL(void)
  156768. jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
  156769. {
  156770. free(object);
  156771. }
  156772. GLOBAL(long)
  156773. jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
  156774. long max_bytes_needed, long already_allocated)
  156775. {
  156776. return max_bytes_needed;
  156777. }
  156778. GLOBAL(void)
  156779. jpeg_open_backing_store (j_common_ptr cinfo, struct backing_store_struct *info,
  156780. long total_bytes_needed)
  156781. {
  156782. ERREXIT(cinfo, JERR_NO_BACKING_STORE);
  156783. }
  156784. GLOBAL(long)
  156785. jpeg_mem_init (j_common_ptr cinfo)
  156786. {
  156787. return 0; /* just set max_memory_to_use to 0 */
  156788. }
  156789. GLOBAL(void)
  156790. jpeg_mem_term (j_common_ptr cinfo)
  156791. {
  156792. }
  156793. /*** End of inlined file: jmemnobs.c ***/
  156794. /*** Start of inlined file: jquant1.c ***/
  156795. #define JPEG_INTERNALS
  156796. #ifdef QUANT_1PASS_SUPPORTED
  156797. #define ODITHER_SIZE 16 /* dimension of dither matrix */
  156798. #define ODITHER_CELLS (ODITHER_SIZE*ODITHER_SIZE) /* # cells in matrix */
  156799. #define ODITHER_MASK (ODITHER_SIZE-1) /* mask for wrapping around counters */
  156800. typedef int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE];
  156801. typedef int (*ODITHER_MATRIX_PTR)[ODITHER_SIZE];
  156802. static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = {
  156803. { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 },
  156804. { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 },
  156805. { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 },
  156806. { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 },
  156807. { 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 },
  156808. { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 },
  156809. { 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 },
  156810. { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 },
  156811. { 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 },
  156812. { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 },
  156813. { 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 },
  156814. { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 },
  156815. { 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 },
  156816. { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 },
  156817. { 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 },
  156818. { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 }
  156819. };
  156820. #if BITS_IN_JSAMPLE == 8
  156821. typedef INT16 FSERROR; /* 16 bits should be enough */
  156822. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  156823. #else
  156824. typedef INT32 FSERROR; /* may need more than 16 bits */
  156825. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  156826. #endif
  156827. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  156828. #define MAX_Q_COMPS 4 /* max components I can handle */
  156829. typedef struct {
  156830. struct jpeg_color_quantizer pub; /* public fields */
  156831. JSAMPARRAY sv_colormap; /* The color map as a 2-D pixel array */
  156832. int sv_actual; /* number of entries in use */
  156833. JSAMPARRAY colorindex; /* Precomputed mapping for speed */
  156834. boolean is_padded; /* is the colorindex padded for odither? */
  156835. int Ncolors[MAX_Q_COMPS]; /* # of values alloced to each component */
  156836. int row_index; /* cur row's vertical index in dither matrix */
  156837. ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]; /* one dither array per component */
  156838. FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */
  156839. boolean on_odd_row; /* flag to remember which row we are on */
  156840. } my_cquantizer;
  156841. typedef my_cquantizer * my_cquantize_ptr;
  156842. LOCAL(int)
  156843. select_ncolors (j_decompress_ptr cinfo, int Ncolors[])
  156844. {
  156845. int nc = cinfo->out_color_components; /* number of color components */
  156846. int max_colors = cinfo->desired_number_of_colors;
  156847. int total_colors, iroot, i, j;
  156848. boolean changed;
  156849. long temp;
  156850. static const int RGB_order[3] = { RGB_GREEN, RGB_RED, RGB_BLUE };
  156851. iroot = 1;
  156852. do {
  156853. iroot++;
  156854. temp = iroot; /* set temp = iroot ** nc */
  156855. for (i = 1; i < nc; i++)
  156856. temp *= iroot;
  156857. } while (temp <= (long) max_colors); /* repeat till iroot exceeds root */
  156858. iroot--; /* now iroot = floor(root) */
  156859. if (iroot < 2)
  156860. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, (int) temp);
  156861. total_colors = 1;
  156862. for (i = 0; i < nc; i++) {
  156863. Ncolors[i] = iroot;
  156864. total_colors *= iroot;
  156865. }
  156866. do {
  156867. changed = FALSE;
  156868. for (i = 0; i < nc; i++) {
  156869. j = (cinfo->out_color_space == JCS_RGB ? RGB_order[i] : i);
  156870. temp = total_colors / Ncolors[j];
  156871. temp *= Ncolors[j]+1; /* done in long arith to avoid oflo */
  156872. if (temp > (long) max_colors)
  156873. break; /* won't fit, done with this pass */
  156874. Ncolors[j]++; /* OK, apply the increment */
  156875. total_colors = (int) temp;
  156876. changed = TRUE;
  156877. }
  156878. } while (changed);
  156879. return total_colors;
  156880. }
  156881. LOCAL(int)
  156882. output_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  156883. {
  156884. return (int) (((INT32) j * MAXJSAMPLE + maxj/2) / maxj);
  156885. }
  156886. LOCAL(int)
  156887. largest_input_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  156888. {
  156889. return (int) (((INT32) (2*j + 1) * MAXJSAMPLE + maxj) / (2*maxj));
  156890. }
  156891. LOCAL(void)
  156892. create_colormap (j_decompress_ptr cinfo)
  156893. {
  156894. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156895. JSAMPARRAY colormap; /* Created colormap */
  156896. int total_colors; /* Number of distinct output colors */
  156897. int i,j,k, nci, blksize, blkdist, ptr, val;
  156898. total_colors = select_ncolors(cinfo, cquantize->Ncolors);
  156899. if (cinfo->out_color_components == 3)
  156900. TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS,
  156901. total_colors, cquantize->Ncolors[0],
  156902. cquantize->Ncolors[1], cquantize->Ncolors[2]);
  156903. else
  156904. TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors);
  156905. colormap = (*cinfo->mem->alloc_sarray)
  156906. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  156907. (JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components);
  156908. blkdist = total_colors;
  156909. for (i = 0; i < cinfo->out_color_components; i++) {
  156910. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  156911. blksize = blkdist / nci;
  156912. for (j = 0; j < nci; j++) {
  156913. val = output_value(cinfo, i, j, nci-1);
  156914. for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) {
  156915. for (k = 0; k < blksize; k++)
  156916. colormap[i][ptr+k] = (JSAMPLE) val;
  156917. }
  156918. }
  156919. blkdist = blksize; /* blksize of this color is blkdist of next */
  156920. }
  156921. cquantize->sv_colormap = colormap;
  156922. cquantize->sv_actual = total_colors;
  156923. }
  156924. LOCAL(void)
  156925. create_colorindex (j_decompress_ptr cinfo)
  156926. {
  156927. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156928. JSAMPROW indexptr;
  156929. int i,j,k, nci, blksize, val, pad;
  156930. if (cinfo->dither_mode == JDITHER_ORDERED) {
  156931. pad = MAXJSAMPLE*2;
  156932. cquantize->is_padded = TRUE;
  156933. } else {
  156934. pad = 0;
  156935. cquantize->is_padded = FALSE;
  156936. }
  156937. cquantize->colorindex = (*cinfo->mem->alloc_sarray)
  156938. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  156939. (JDIMENSION) (MAXJSAMPLE+1 + pad),
  156940. (JDIMENSION) cinfo->out_color_components);
  156941. blksize = cquantize->sv_actual;
  156942. for (i = 0; i < cinfo->out_color_components; i++) {
  156943. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  156944. blksize = blksize / nci;
  156945. if (pad)
  156946. cquantize->colorindex[i] += MAXJSAMPLE;
  156947. indexptr = cquantize->colorindex[i];
  156948. val = 0;
  156949. k = largest_input_value(cinfo, i, 0, nci-1);
  156950. for (j = 0; j <= MAXJSAMPLE; j++) {
  156951. while (j > k) /* advance val if past boundary */
  156952. k = largest_input_value(cinfo, i, ++val, nci-1);
  156953. indexptr[j] = (JSAMPLE) (val * blksize);
  156954. }
  156955. if (pad)
  156956. for (j = 1; j <= MAXJSAMPLE; j++) {
  156957. indexptr[-j] = indexptr[0];
  156958. indexptr[MAXJSAMPLE+j] = indexptr[MAXJSAMPLE];
  156959. }
  156960. }
  156961. }
  156962. LOCAL(ODITHER_MATRIX_PTR)
  156963. make_odither_array (j_decompress_ptr cinfo, int ncolors)
  156964. {
  156965. ODITHER_MATRIX_PTR odither;
  156966. int j,k;
  156967. INT32 num,den;
  156968. odither = (ODITHER_MATRIX_PTR)
  156969. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  156970. SIZEOF(ODITHER_MATRIX));
  156971. den = 2 * ODITHER_CELLS * ((INT32) (ncolors - 1));
  156972. for (j = 0; j < ODITHER_SIZE; j++) {
  156973. for (k = 0; k < ODITHER_SIZE; k++) {
  156974. num = ((INT32) (ODITHER_CELLS-1 - 2*((int)base_dither_matrix[j][k])))
  156975. * MAXJSAMPLE;
  156976. odither[j][k] = (int) (num<0 ? -((-num)/den) : num/den);
  156977. }
  156978. }
  156979. return odither;
  156980. }
  156981. LOCAL(void)
  156982. create_odither_tables (j_decompress_ptr cinfo)
  156983. {
  156984. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156985. ODITHER_MATRIX_PTR odither;
  156986. int i, j, nci;
  156987. for (i = 0; i < cinfo->out_color_components; i++) {
  156988. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  156989. odither = NULL; /* search for matching prior component */
  156990. for (j = 0; j < i; j++) {
  156991. if (nci == cquantize->Ncolors[j]) {
  156992. odither = cquantize->odither[j];
  156993. break;
  156994. }
  156995. }
  156996. if (odither == NULL) /* need a new table? */
  156997. odither = make_odither_array(cinfo, nci);
  156998. cquantize->odither[i] = odither;
  156999. }
  157000. }
  157001. METHODDEF(void)
  157002. color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157003. JSAMPARRAY output_buf, int num_rows)
  157004. {
  157005. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157006. JSAMPARRAY colorindex = cquantize->colorindex;
  157007. register int pixcode, ci;
  157008. register JSAMPROW ptrin, ptrout;
  157009. int row;
  157010. JDIMENSION col;
  157011. JDIMENSION width = cinfo->output_width;
  157012. register int nc = cinfo->out_color_components;
  157013. for (row = 0; row < num_rows; row++) {
  157014. ptrin = input_buf[row];
  157015. ptrout = output_buf[row];
  157016. for (col = width; col > 0; col--) {
  157017. pixcode = 0;
  157018. for (ci = 0; ci < nc; ci++) {
  157019. pixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]);
  157020. }
  157021. *ptrout++ = (JSAMPLE) pixcode;
  157022. }
  157023. }
  157024. }
  157025. METHODDEF(void)
  157026. color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157027. JSAMPARRAY output_buf, int num_rows)
  157028. {
  157029. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157030. register int pixcode;
  157031. register JSAMPROW ptrin, ptrout;
  157032. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157033. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157034. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157035. int row;
  157036. JDIMENSION col;
  157037. JDIMENSION width = cinfo->output_width;
  157038. for (row = 0; row < num_rows; row++) {
  157039. ptrin = input_buf[row];
  157040. ptrout = output_buf[row];
  157041. for (col = width; col > 0; col--) {
  157042. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*ptrin++)]);
  157043. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*ptrin++)]);
  157044. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*ptrin++)]);
  157045. *ptrout++ = (JSAMPLE) pixcode;
  157046. }
  157047. }
  157048. }
  157049. METHODDEF(void)
  157050. quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157051. JSAMPARRAY output_buf, int num_rows)
  157052. {
  157053. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157054. register JSAMPROW input_ptr;
  157055. register JSAMPROW output_ptr;
  157056. JSAMPROW colorindex_ci;
  157057. int * dither; /* points to active row of dither matrix */
  157058. int row_index, col_index; /* current indexes into dither matrix */
  157059. int nc = cinfo->out_color_components;
  157060. int ci;
  157061. int row;
  157062. JDIMENSION col;
  157063. JDIMENSION width = cinfo->output_width;
  157064. for (row = 0; row < num_rows; row++) {
  157065. jzero_far((void FAR *) output_buf[row],
  157066. (size_t) (width * SIZEOF(JSAMPLE)));
  157067. row_index = cquantize->row_index;
  157068. for (ci = 0; ci < nc; ci++) {
  157069. input_ptr = input_buf[row] + ci;
  157070. output_ptr = output_buf[row];
  157071. colorindex_ci = cquantize->colorindex[ci];
  157072. dither = cquantize->odither[ci][row_index];
  157073. col_index = 0;
  157074. for (col = width; col > 0; col--) {
  157075. *output_ptr += colorindex_ci[GETJSAMPLE(*input_ptr)+dither[col_index]];
  157076. input_ptr += nc;
  157077. output_ptr++;
  157078. col_index = (col_index + 1) & ODITHER_MASK;
  157079. }
  157080. }
  157081. row_index = (row_index + 1) & ODITHER_MASK;
  157082. cquantize->row_index = row_index;
  157083. }
  157084. }
  157085. METHODDEF(void)
  157086. quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157087. JSAMPARRAY output_buf, int num_rows)
  157088. {
  157089. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157090. register int pixcode;
  157091. register JSAMPROW input_ptr;
  157092. register JSAMPROW output_ptr;
  157093. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157094. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157095. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157096. int * dither0; /* points to active row of dither matrix */
  157097. int * dither1;
  157098. int * dither2;
  157099. int row_index, col_index; /* current indexes into dither matrix */
  157100. int row;
  157101. JDIMENSION col;
  157102. JDIMENSION width = cinfo->output_width;
  157103. for (row = 0; row < num_rows; row++) {
  157104. row_index = cquantize->row_index;
  157105. input_ptr = input_buf[row];
  157106. output_ptr = output_buf[row];
  157107. dither0 = cquantize->odither[0][row_index];
  157108. dither1 = cquantize->odither[1][row_index];
  157109. dither2 = cquantize->odither[2][row_index];
  157110. col_index = 0;
  157111. for (col = width; col > 0; col--) {
  157112. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) +
  157113. dither0[col_index]]);
  157114. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) +
  157115. dither1[col_index]]);
  157116. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) +
  157117. dither2[col_index]]);
  157118. *output_ptr++ = (JSAMPLE) pixcode;
  157119. col_index = (col_index + 1) & ODITHER_MASK;
  157120. }
  157121. row_index = (row_index + 1) & ODITHER_MASK;
  157122. cquantize->row_index = row_index;
  157123. }
  157124. }
  157125. METHODDEF(void)
  157126. quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157127. JSAMPARRAY output_buf, int num_rows)
  157128. {
  157129. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157130. register LOCFSERROR cur; /* current error or pixel value */
  157131. LOCFSERROR belowerr; /* error for pixel below cur */
  157132. LOCFSERROR bpreverr; /* error for below/prev col */
  157133. LOCFSERROR bnexterr; /* error for below/next col */
  157134. LOCFSERROR delta;
  157135. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  157136. register JSAMPROW input_ptr;
  157137. register JSAMPROW output_ptr;
  157138. JSAMPROW colorindex_ci;
  157139. JSAMPROW colormap_ci;
  157140. int pixcode;
  157141. int nc = cinfo->out_color_components;
  157142. int dir; /* 1 for left-to-right, -1 for right-to-left */
  157143. int dirnc; /* dir * nc */
  157144. int ci;
  157145. int row;
  157146. JDIMENSION col;
  157147. JDIMENSION width = cinfo->output_width;
  157148. JSAMPLE *range_limit = cinfo->sample_range_limit;
  157149. SHIFT_TEMPS
  157150. for (row = 0; row < num_rows; row++) {
  157151. jzero_far((void FAR *) output_buf[row],
  157152. (size_t) (width * SIZEOF(JSAMPLE)));
  157153. for (ci = 0; ci < nc; ci++) {
  157154. input_ptr = input_buf[row] + ci;
  157155. output_ptr = output_buf[row];
  157156. if (cquantize->on_odd_row) {
  157157. input_ptr += (width-1) * nc; /* so point to rightmost pixel */
  157158. output_ptr += width-1;
  157159. dir = -1;
  157160. dirnc = -nc;
  157161. errorptr = cquantize->fserrors[ci] + (width+1); /* => entry after last column */
  157162. } else {
  157163. dir = 1;
  157164. dirnc = nc;
  157165. errorptr = cquantize->fserrors[ci]; /* => entry before first column */
  157166. }
  157167. colorindex_ci = cquantize->colorindex[ci];
  157168. colormap_ci = cquantize->sv_colormap[ci];
  157169. cur = 0;
  157170. belowerr = bpreverr = 0;
  157171. for (col = width; col > 0; col--) {
  157172. cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4);
  157173. cur += GETJSAMPLE(*input_ptr);
  157174. cur = GETJSAMPLE(range_limit[cur]);
  157175. pixcode = GETJSAMPLE(colorindex_ci[cur]);
  157176. *output_ptr += (JSAMPLE) pixcode;
  157177. cur -= GETJSAMPLE(colormap_ci[pixcode]);
  157178. bnexterr = cur;
  157179. delta = cur * 2;
  157180. cur += delta; /* form error * 3 */
  157181. errorptr[0] = (FSERROR) (bpreverr + cur);
  157182. cur += delta; /* form error * 5 */
  157183. bpreverr = belowerr + cur;
  157184. belowerr = bnexterr;
  157185. cur += delta; /* form error * 7 */
  157186. input_ptr += dirnc; /* advance input ptr to next column */
  157187. output_ptr += dir; /* advance output ptr to next column */
  157188. errorptr += dir; /* advance errorptr to current column */
  157189. }
  157190. errorptr[0] = (FSERROR) bpreverr; /* unload prev err into array */
  157191. }
  157192. cquantize->on_odd_row = (cquantize->on_odd_row ? FALSE : TRUE);
  157193. }
  157194. }
  157195. LOCAL(void)
  157196. alloc_fs_workspace (j_decompress_ptr cinfo)
  157197. {
  157198. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157199. size_t arraysize;
  157200. int i;
  157201. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157202. for (i = 0; i < cinfo->out_color_components; i++) {
  157203. cquantize->fserrors[i] = (FSERRPTR)
  157204. (*cinfo->mem->alloc_large)((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  157205. }
  157206. }
  157207. METHODDEF(void)
  157208. start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  157209. {
  157210. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157211. size_t arraysize;
  157212. int i;
  157213. cinfo->colormap = cquantize->sv_colormap;
  157214. cinfo->actual_number_of_colors = cquantize->sv_actual;
  157215. switch (cinfo->dither_mode) {
  157216. case JDITHER_NONE:
  157217. if (cinfo->out_color_components == 3)
  157218. cquantize->pub.color_quantize = color_quantize3;
  157219. else
  157220. cquantize->pub.color_quantize = color_quantize;
  157221. break;
  157222. case JDITHER_ORDERED:
  157223. if (cinfo->out_color_components == 3)
  157224. cquantize->pub.color_quantize = quantize3_ord_dither;
  157225. else
  157226. cquantize->pub.color_quantize = quantize_ord_dither;
  157227. cquantize->row_index = 0; /* initialize state for ordered dither */
  157228. if (! cquantize->is_padded)
  157229. create_colorindex(cinfo);
  157230. if (cquantize->odither[0] == NULL)
  157231. create_odither_tables(cinfo);
  157232. break;
  157233. case JDITHER_FS:
  157234. cquantize->pub.color_quantize = quantize_fs_dither;
  157235. cquantize->on_odd_row = FALSE; /* initialize state for F-S dither */
  157236. if (cquantize->fserrors[0] == NULL)
  157237. alloc_fs_workspace(cinfo);
  157238. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157239. for (i = 0; i < cinfo->out_color_components; i++)
  157240. jzero_far((void FAR *) cquantize->fserrors[i], arraysize);
  157241. break;
  157242. default:
  157243. ERREXIT(cinfo, JERR_NOT_COMPILED);
  157244. break;
  157245. }
  157246. }
  157247. METHODDEF(void)
  157248. finish_pass_1_quant (j_decompress_ptr cinfo)
  157249. {
  157250. }
  157251. METHODDEF(void)
  157252. new_color_map_1_quant (j_decompress_ptr cinfo)
  157253. {
  157254. ERREXIT(cinfo, JERR_MODE_CHANGE);
  157255. }
  157256. GLOBAL(void)
  157257. jinit_1pass_quantizer (j_decompress_ptr cinfo)
  157258. {
  157259. my_cquantize_ptr cquantize;
  157260. cquantize = (my_cquantize_ptr)
  157261. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157262. SIZEOF(my_cquantizer));
  157263. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  157264. cquantize->pub.start_pass = start_pass_1_quant;
  157265. cquantize->pub.finish_pass = finish_pass_1_quant;
  157266. cquantize->pub.new_color_map = new_color_map_1_quant;
  157267. cquantize->fserrors[0] = NULL; /* Flag FS workspace not allocated */
  157268. cquantize->odither[0] = NULL; /* Also flag odither arrays not allocated */
  157269. if (cinfo->out_color_components > MAX_Q_COMPS)
  157270. ERREXIT1(cinfo, JERR_QUANT_COMPONENTS, MAX_Q_COMPS);
  157271. if (cinfo->desired_number_of_colors > (MAXJSAMPLE+1))
  157272. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXJSAMPLE+1);
  157273. create_colormap(cinfo);
  157274. create_colorindex(cinfo);
  157275. if (cinfo->dither_mode == JDITHER_FS)
  157276. alloc_fs_workspace(cinfo);
  157277. }
  157278. #endif /* QUANT_1PASS_SUPPORTED */
  157279. /*** End of inlined file: jquant1.c ***/
  157280. /*** Start of inlined file: jquant2.c ***/
  157281. #define JPEG_INTERNALS
  157282. #ifdef QUANT_2PASS_SUPPORTED
  157283. #define R_SCALE 2 /* scale R distances by this much */
  157284. #define G_SCALE 3 /* scale G distances by this much */
  157285. #define B_SCALE 1 /* and B by this much */
  157286. #if RGB_RED == 0
  157287. #define C0_SCALE R_SCALE
  157288. #endif
  157289. #if RGB_BLUE == 0
  157290. #define C0_SCALE B_SCALE
  157291. #endif
  157292. #if RGB_GREEN == 1
  157293. #define C1_SCALE G_SCALE
  157294. #endif
  157295. #if RGB_RED == 2
  157296. #define C2_SCALE R_SCALE
  157297. #endif
  157298. #if RGB_BLUE == 2
  157299. #define C2_SCALE B_SCALE
  157300. #endif
  157301. #define MAXNUMCOLORS (MAXJSAMPLE+1) /* maximum size of colormap */
  157302. #define HIST_C0_BITS 5 /* bits of precision in R/B histogram */
  157303. #define HIST_C1_BITS 6 /* bits of precision in G histogram */
  157304. #define HIST_C2_BITS 5 /* bits of precision in B/R histogram */
  157305. #define HIST_C0_ELEMS (1<<HIST_C0_BITS)
  157306. #define HIST_C1_ELEMS (1<<HIST_C1_BITS)
  157307. #define HIST_C2_ELEMS (1<<HIST_C2_BITS)
  157308. #define C0_SHIFT (BITS_IN_JSAMPLE-HIST_C0_BITS)
  157309. #define C1_SHIFT (BITS_IN_JSAMPLE-HIST_C1_BITS)
  157310. #define C2_SHIFT (BITS_IN_JSAMPLE-HIST_C2_BITS)
  157311. typedef UINT16 histcell; /* histogram cell; prefer an unsigned type */
  157312. typedef histcell FAR * histptr; /* for pointers to histogram cells */
  157313. typedef histcell hist1d[HIST_C2_ELEMS]; /* typedefs for the array */
  157314. typedef hist1d FAR * hist2d; /* type for the 2nd-level pointers */
  157315. typedef hist2d * hist3d; /* type for top-level pointer */
  157316. #if BITS_IN_JSAMPLE == 8
  157317. typedef INT16 FSERROR; /* 16 bits should be enough */
  157318. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  157319. #else
  157320. typedef INT32 FSERROR; /* may need more than 16 bits */
  157321. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  157322. #endif
  157323. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  157324. typedef struct {
  157325. struct jpeg_color_quantizer pub; /* public fields */
  157326. JSAMPARRAY sv_colormap; /* colormap allocated at init time */
  157327. int desired; /* desired # of colors = size of colormap */
  157328. hist3d histogram; /* pointer to the histogram */
  157329. boolean needs_zeroed; /* TRUE if next pass must zero histogram */
  157330. FSERRPTR fserrors; /* accumulated errors */
  157331. boolean on_odd_row; /* flag to remember which row we are on */
  157332. int * error_limiter; /* table for clamping the applied error */
  157333. } my_cquantizer2;
  157334. typedef my_cquantizer2 * my_cquantize_ptr2;
  157335. METHODDEF(void)
  157336. prescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157337. JSAMPARRAY output_buf, int num_rows)
  157338. {
  157339. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157340. register JSAMPROW ptr;
  157341. register histptr histp;
  157342. register hist3d histogram = cquantize->histogram;
  157343. int row;
  157344. JDIMENSION col;
  157345. JDIMENSION width = cinfo->output_width;
  157346. for (row = 0; row < num_rows; row++) {
  157347. ptr = input_buf[row];
  157348. for (col = width; col > 0; col--) {
  157349. histp = & histogram[GETJSAMPLE(ptr[0]) >> C0_SHIFT]
  157350. [GETJSAMPLE(ptr[1]) >> C1_SHIFT]
  157351. [GETJSAMPLE(ptr[2]) >> C2_SHIFT];
  157352. if (++(*histp) <= 0)
  157353. (*histp)--;
  157354. ptr += 3;
  157355. }
  157356. }
  157357. }
  157358. typedef struct {
  157359. int c0min, c0max;
  157360. int c1min, c1max;
  157361. int c2min, c2max;
  157362. INT32 volume;
  157363. long colorcount;
  157364. } box;
  157365. typedef box * boxptr;
  157366. LOCAL(boxptr)
  157367. find_biggest_color_pop (boxptr boxlist, int numboxes)
  157368. {
  157369. register boxptr boxp;
  157370. register int i;
  157371. register long maxc = 0;
  157372. boxptr which = NULL;
  157373. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157374. if (boxp->colorcount > maxc && boxp->volume > 0) {
  157375. which = boxp;
  157376. maxc = boxp->colorcount;
  157377. }
  157378. }
  157379. return which;
  157380. }
  157381. LOCAL(boxptr)
  157382. find_biggest_volume (boxptr boxlist, int numboxes)
  157383. {
  157384. register boxptr boxp;
  157385. register int i;
  157386. register INT32 maxv = 0;
  157387. boxptr which = NULL;
  157388. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157389. if (boxp->volume > maxv) {
  157390. which = boxp;
  157391. maxv = boxp->volume;
  157392. }
  157393. }
  157394. return which;
  157395. }
  157396. LOCAL(void)
  157397. update_box (j_decompress_ptr cinfo, boxptr boxp)
  157398. {
  157399. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157400. hist3d histogram = cquantize->histogram;
  157401. histptr histp;
  157402. int c0,c1,c2;
  157403. int c0min,c0max,c1min,c1max,c2min,c2max;
  157404. INT32 dist0,dist1,dist2;
  157405. long ccount;
  157406. c0min = boxp->c0min; c0max = boxp->c0max;
  157407. c1min = boxp->c1min; c1max = boxp->c1max;
  157408. c2min = boxp->c2min; c2max = boxp->c2max;
  157409. if (c0max > c0min)
  157410. for (c0 = c0min; c0 <= c0max; c0++)
  157411. for (c1 = c1min; c1 <= c1max; c1++) {
  157412. histp = & histogram[c0][c1][c2min];
  157413. for (c2 = c2min; c2 <= c2max; c2++)
  157414. if (*histp++ != 0) {
  157415. boxp->c0min = c0min = c0;
  157416. goto have_c0min;
  157417. }
  157418. }
  157419. have_c0min:
  157420. if (c0max > c0min)
  157421. for (c0 = c0max; c0 >= c0min; c0--)
  157422. for (c1 = c1min; c1 <= c1max; c1++) {
  157423. histp = & histogram[c0][c1][c2min];
  157424. for (c2 = c2min; c2 <= c2max; c2++)
  157425. if (*histp++ != 0) {
  157426. boxp->c0max = c0max = c0;
  157427. goto have_c0max;
  157428. }
  157429. }
  157430. have_c0max:
  157431. if (c1max > c1min)
  157432. for (c1 = c1min; c1 <= c1max; c1++)
  157433. for (c0 = c0min; c0 <= c0max; c0++) {
  157434. histp = & histogram[c0][c1][c2min];
  157435. for (c2 = c2min; c2 <= c2max; c2++)
  157436. if (*histp++ != 0) {
  157437. boxp->c1min = c1min = c1;
  157438. goto have_c1min;
  157439. }
  157440. }
  157441. have_c1min:
  157442. if (c1max > c1min)
  157443. for (c1 = c1max; c1 >= c1min; c1--)
  157444. for (c0 = c0min; c0 <= c0max; c0++) {
  157445. histp = & histogram[c0][c1][c2min];
  157446. for (c2 = c2min; c2 <= c2max; c2++)
  157447. if (*histp++ != 0) {
  157448. boxp->c1max = c1max = c1;
  157449. goto have_c1max;
  157450. }
  157451. }
  157452. have_c1max:
  157453. if (c2max > c2min)
  157454. for (c2 = c2min; c2 <= c2max; c2++)
  157455. for (c0 = c0min; c0 <= c0max; c0++) {
  157456. histp = & histogram[c0][c1min][c2];
  157457. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157458. if (*histp != 0) {
  157459. boxp->c2min = c2min = c2;
  157460. goto have_c2min;
  157461. }
  157462. }
  157463. have_c2min:
  157464. if (c2max > c2min)
  157465. for (c2 = c2max; c2 >= c2min; c2--)
  157466. for (c0 = c0min; c0 <= c0max; c0++) {
  157467. histp = & histogram[c0][c1min][c2];
  157468. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157469. if (*histp != 0) {
  157470. boxp->c2max = c2max = c2;
  157471. goto have_c2max;
  157472. }
  157473. }
  157474. have_c2max:
  157475. dist0 = ((c0max - c0min) << C0_SHIFT) * C0_SCALE;
  157476. dist1 = ((c1max - c1min) << C1_SHIFT) * C1_SCALE;
  157477. dist2 = ((c2max - c2min) << C2_SHIFT) * C2_SCALE;
  157478. boxp->volume = dist0*dist0 + dist1*dist1 + dist2*dist2;
  157479. ccount = 0;
  157480. for (c0 = c0min; c0 <= c0max; c0++)
  157481. for (c1 = c1min; c1 <= c1max; c1++) {
  157482. histp = & histogram[c0][c1][c2min];
  157483. for (c2 = c2min; c2 <= c2max; c2++, histp++)
  157484. if (*histp != 0) {
  157485. ccount++;
  157486. }
  157487. }
  157488. boxp->colorcount = ccount;
  157489. }
  157490. LOCAL(int)
  157491. median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes,
  157492. int desired_colors)
  157493. {
  157494. int n,lb;
  157495. int c0,c1,c2,cmax;
  157496. register boxptr b1,b2;
  157497. while (numboxes < desired_colors) {
  157498. if (numboxes*2 <= desired_colors) {
  157499. b1 = find_biggest_color_pop(boxlist, numboxes);
  157500. } else {
  157501. b1 = find_biggest_volume(boxlist, numboxes);
  157502. }
  157503. if (b1 == NULL) /* no splittable boxes left! */
  157504. break;
  157505. b2 = &boxlist[numboxes]; /* where new box will go */
  157506. b2->c0max = b1->c0max; b2->c1max = b1->c1max; b2->c2max = b1->c2max;
  157507. b2->c0min = b1->c0min; b2->c1min = b1->c1min; b2->c2min = b1->c2min;
  157508. c0 = ((b1->c0max - b1->c0min) << C0_SHIFT) * C0_SCALE;
  157509. c1 = ((b1->c1max - b1->c1min) << C1_SHIFT) * C1_SCALE;
  157510. c2 = ((b1->c2max - b1->c2min) << C2_SHIFT) * C2_SCALE;
  157511. #if RGB_RED == 0
  157512. cmax = c1; n = 1;
  157513. if (c0 > cmax) { cmax = c0; n = 0; }
  157514. if (c2 > cmax) { n = 2; }
  157515. #else
  157516. cmax = c1; n = 1;
  157517. if (c2 > cmax) { cmax = c2; n = 2; }
  157518. if (c0 > cmax) { n = 0; }
  157519. #endif
  157520. switch (n) {
  157521. case 0:
  157522. lb = (b1->c0max + b1->c0min) / 2;
  157523. b1->c0max = lb;
  157524. b2->c0min = lb+1;
  157525. break;
  157526. case 1:
  157527. lb = (b1->c1max + b1->c1min) / 2;
  157528. b1->c1max = lb;
  157529. b2->c1min = lb+1;
  157530. break;
  157531. case 2:
  157532. lb = (b1->c2max + b1->c2min) / 2;
  157533. b1->c2max = lb;
  157534. b2->c2min = lb+1;
  157535. break;
  157536. }
  157537. update_box(cinfo, b1);
  157538. update_box(cinfo, b2);
  157539. numboxes++;
  157540. }
  157541. return numboxes;
  157542. }
  157543. LOCAL(void)
  157544. compute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor)
  157545. {
  157546. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157547. hist3d histogram = cquantize->histogram;
  157548. histptr histp;
  157549. int c0,c1,c2;
  157550. int c0min,c0max,c1min,c1max,c2min,c2max;
  157551. long count;
  157552. long total = 0;
  157553. long c0total = 0;
  157554. long c1total = 0;
  157555. long c2total = 0;
  157556. c0min = boxp->c0min; c0max = boxp->c0max;
  157557. c1min = boxp->c1min; c1max = boxp->c1max;
  157558. c2min = boxp->c2min; c2max = boxp->c2max;
  157559. for (c0 = c0min; c0 <= c0max; c0++)
  157560. for (c1 = c1min; c1 <= c1max; c1++) {
  157561. histp = & histogram[c0][c1][c2min];
  157562. for (c2 = c2min; c2 <= c2max; c2++) {
  157563. if ((count = *histp++) != 0) {
  157564. total += count;
  157565. c0total += ((c0 << C0_SHIFT) + ((1<<C0_SHIFT)>>1)) * count;
  157566. c1total += ((c1 << C1_SHIFT) + ((1<<C1_SHIFT)>>1)) * count;
  157567. c2total += ((c2 << C2_SHIFT) + ((1<<C2_SHIFT)>>1)) * count;
  157568. }
  157569. }
  157570. }
  157571. cinfo->colormap[0][icolor] = (JSAMPLE) ((c0total + (total>>1)) / total);
  157572. cinfo->colormap[1][icolor] = (JSAMPLE) ((c1total + (total>>1)) / total);
  157573. cinfo->colormap[2][icolor] = (JSAMPLE) ((c2total + (total>>1)) / total);
  157574. }
  157575. LOCAL(void)
  157576. select_colors (j_decompress_ptr cinfo, int desired_colors)
  157577. {
  157578. boxptr boxlist;
  157579. int numboxes;
  157580. int i;
  157581. boxlist = (boxptr) (*cinfo->mem->alloc_small)
  157582. ((j_common_ptr) cinfo, JPOOL_IMAGE, desired_colors * SIZEOF(box));
  157583. numboxes = 1;
  157584. boxlist[0].c0min = 0;
  157585. boxlist[0].c0max = MAXJSAMPLE >> C0_SHIFT;
  157586. boxlist[0].c1min = 0;
  157587. boxlist[0].c1max = MAXJSAMPLE >> C1_SHIFT;
  157588. boxlist[0].c2min = 0;
  157589. boxlist[0].c2max = MAXJSAMPLE >> C2_SHIFT;
  157590. update_box(cinfo, & boxlist[0]);
  157591. numboxes = median_cut(cinfo, boxlist, numboxes, desired_colors);
  157592. for (i = 0; i < numboxes; i++)
  157593. compute_color(cinfo, & boxlist[i], i);
  157594. cinfo->actual_number_of_colors = numboxes;
  157595. TRACEMS1(cinfo, 1, JTRC_QUANT_SELECTED, numboxes);
  157596. }
  157597. #define BOX_C0_LOG (HIST_C0_BITS-3)
  157598. #define BOX_C1_LOG (HIST_C1_BITS-3)
  157599. #define BOX_C2_LOG (HIST_C2_BITS-3)
  157600. #define BOX_C0_ELEMS (1<<BOX_C0_LOG) /* # of hist cells in update box */
  157601. #define BOX_C1_ELEMS (1<<BOX_C1_LOG)
  157602. #define BOX_C2_ELEMS (1<<BOX_C2_LOG)
  157603. #define BOX_C0_SHIFT (C0_SHIFT + BOX_C0_LOG)
  157604. #define BOX_C1_SHIFT (C1_SHIFT + BOX_C1_LOG)
  157605. #define BOX_C2_SHIFT (C2_SHIFT + BOX_C2_LOG)
  157606. LOCAL(int)
  157607. find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  157608. JSAMPLE colorlist[])
  157609. {
  157610. int numcolors = cinfo->actual_number_of_colors;
  157611. int maxc0, maxc1, maxc2;
  157612. int centerc0, centerc1, centerc2;
  157613. int i, x, ncolors;
  157614. INT32 minmaxdist, min_dist, max_dist, tdist;
  157615. INT32 mindist[MAXNUMCOLORS]; /* min distance to colormap entry i */
  157616. maxc0 = minc0 + ((1 << BOX_C0_SHIFT) - (1 << C0_SHIFT));
  157617. centerc0 = (minc0 + maxc0) >> 1;
  157618. maxc1 = minc1 + ((1 << BOX_C1_SHIFT) - (1 << C1_SHIFT));
  157619. centerc1 = (minc1 + maxc1) >> 1;
  157620. maxc2 = minc2 + ((1 << BOX_C2_SHIFT) - (1 << C2_SHIFT));
  157621. centerc2 = (minc2 + maxc2) >> 1;
  157622. minmaxdist = 0x7FFFFFFFL;
  157623. for (i = 0; i < numcolors; i++) {
  157624. x = GETJSAMPLE(cinfo->colormap[0][i]);
  157625. if (x < minc0) {
  157626. tdist = (x - minc0) * C0_SCALE;
  157627. min_dist = tdist*tdist;
  157628. tdist = (x - maxc0) * C0_SCALE;
  157629. max_dist = tdist*tdist;
  157630. } else if (x > maxc0) {
  157631. tdist = (x - maxc0) * C0_SCALE;
  157632. min_dist = tdist*tdist;
  157633. tdist = (x - minc0) * C0_SCALE;
  157634. max_dist = tdist*tdist;
  157635. } else {
  157636. min_dist = 0;
  157637. if (x <= centerc0) {
  157638. tdist = (x - maxc0) * C0_SCALE;
  157639. max_dist = tdist*tdist;
  157640. } else {
  157641. tdist = (x - minc0) * C0_SCALE;
  157642. max_dist = tdist*tdist;
  157643. }
  157644. }
  157645. x = GETJSAMPLE(cinfo->colormap[1][i]);
  157646. if (x < minc1) {
  157647. tdist = (x - minc1) * C1_SCALE;
  157648. min_dist += tdist*tdist;
  157649. tdist = (x - maxc1) * C1_SCALE;
  157650. max_dist += tdist*tdist;
  157651. } else if (x > maxc1) {
  157652. tdist = (x - maxc1) * C1_SCALE;
  157653. min_dist += tdist*tdist;
  157654. tdist = (x - minc1) * C1_SCALE;
  157655. max_dist += tdist*tdist;
  157656. } else {
  157657. if (x <= centerc1) {
  157658. tdist = (x - maxc1) * C1_SCALE;
  157659. max_dist += tdist*tdist;
  157660. } else {
  157661. tdist = (x - minc1) * C1_SCALE;
  157662. max_dist += tdist*tdist;
  157663. }
  157664. }
  157665. x = GETJSAMPLE(cinfo->colormap[2][i]);
  157666. if (x < minc2) {
  157667. tdist = (x - minc2) * C2_SCALE;
  157668. min_dist += tdist*tdist;
  157669. tdist = (x - maxc2) * C2_SCALE;
  157670. max_dist += tdist*tdist;
  157671. } else if (x > maxc2) {
  157672. tdist = (x - maxc2) * C2_SCALE;
  157673. min_dist += tdist*tdist;
  157674. tdist = (x - minc2) * C2_SCALE;
  157675. max_dist += tdist*tdist;
  157676. } else {
  157677. if (x <= centerc2) {
  157678. tdist = (x - maxc2) * C2_SCALE;
  157679. max_dist += tdist*tdist;
  157680. } else {
  157681. tdist = (x - minc2) * C2_SCALE;
  157682. max_dist += tdist*tdist;
  157683. }
  157684. }
  157685. mindist[i] = min_dist; /* save away the results */
  157686. if (max_dist < minmaxdist)
  157687. minmaxdist = max_dist;
  157688. }
  157689. ncolors = 0;
  157690. for (i = 0; i < numcolors; i++) {
  157691. if (mindist[i] <= minmaxdist)
  157692. colorlist[ncolors++] = (JSAMPLE) i;
  157693. }
  157694. return ncolors;
  157695. }
  157696. LOCAL(void)
  157697. find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  157698. int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
  157699. {
  157700. int ic0, ic1, ic2;
  157701. int i, icolor;
  157702. register INT32 * bptr; /* pointer into bestdist[] array */
  157703. JSAMPLE * cptr; /* pointer into bestcolor[] array */
  157704. INT32 dist0, dist1; /* initial distance values */
  157705. register INT32 dist2; /* current distance in inner loop */
  157706. INT32 xx0, xx1; /* distance increments */
  157707. register INT32 xx2;
  157708. INT32 inc0, inc1, inc2; /* initial values for increments */
  157709. INT32 bestdist[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  157710. bptr = bestdist;
  157711. for (i = BOX_C0_ELEMS*BOX_C1_ELEMS*BOX_C2_ELEMS-1; i >= 0; i--)
  157712. *bptr++ = 0x7FFFFFFFL;
  157713. #define STEP_C0 ((1 << C0_SHIFT) * C0_SCALE)
  157714. #define STEP_C1 ((1 << C1_SHIFT) * C1_SCALE)
  157715. #define STEP_C2 ((1 << C2_SHIFT) * C2_SCALE)
  157716. for (i = 0; i < numcolors; i++) {
  157717. icolor = GETJSAMPLE(colorlist[i]);
  157718. inc0 = (minc0 - GETJSAMPLE(cinfo->colormap[0][icolor])) * C0_SCALE;
  157719. dist0 = inc0*inc0;
  157720. inc1 = (minc1 - GETJSAMPLE(cinfo->colormap[1][icolor])) * C1_SCALE;
  157721. dist0 += inc1*inc1;
  157722. inc2 = (minc2 - GETJSAMPLE(cinfo->colormap[2][icolor])) * C2_SCALE;
  157723. dist0 += inc2*inc2;
  157724. inc0 = inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0;
  157725. inc1 = inc1 * (2 * STEP_C1) + STEP_C1 * STEP_C1;
  157726. inc2 = inc2 * (2 * STEP_C2) + STEP_C2 * STEP_C2;
  157727. bptr = bestdist;
  157728. cptr = bestcolor;
  157729. xx0 = inc0;
  157730. for (ic0 = BOX_C0_ELEMS-1; ic0 >= 0; ic0--) {
  157731. dist1 = dist0;
  157732. xx1 = inc1;
  157733. for (ic1 = BOX_C1_ELEMS-1; ic1 >= 0; ic1--) {
  157734. dist2 = dist1;
  157735. xx2 = inc2;
  157736. for (ic2 = BOX_C2_ELEMS-1; ic2 >= 0; ic2--) {
  157737. if (dist2 < *bptr) {
  157738. *bptr = dist2;
  157739. *cptr = (JSAMPLE) icolor;
  157740. }
  157741. dist2 += xx2;
  157742. xx2 += 2 * STEP_C2 * STEP_C2;
  157743. bptr++;
  157744. cptr++;
  157745. }
  157746. dist1 += xx1;
  157747. xx1 += 2 * STEP_C1 * STEP_C1;
  157748. }
  157749. dist0 += xx0;
  157750. xx0 += 2 * STEP_C0 * STEP_C0;
  157751. }
  157752. }
  157753. }
  157754. LOCAL(void)
  157755. fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
  157756. {
  157757. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157758. hist3d histogram = cquantize->histogram;
  157759. int minc0, minc1, minc2; /* lower left corner of update box */
  157760. int ic0, ic1, ic2;
  157761. register JSAMPLE * cptr; /* pointer into bestcolor[] array */
  157762. register histptr cachep; /* pointer into main cache array */
  157763. JSAMPLE colorlist[MAXNUMCOLORS];
  157764. int numcolors; /* number of candidate colors */
  157765. JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  157766. c0 >>= BOX_C0_LOG;
  157767. c1 >>= BOX_C1_LOG;
  157768. c2 >>= BOX_C2_LOG;
  157769. minc0 = (c0 << BOX_C0_SHIFT) + ((1 << C0_SHIFT) >> 1);
  157770. minc1 = (c1 << BOX_C1_SHIFT) + ((1 << C1_SHIFT) >> 1);
  157771. minc2 = (c2 << BOX_C2_SHIFT) + ((1 << C2_SHIFT) >> 1);
  157772. numcolors = find_nearby_colors(cinfo, minc0, minc1, minc2, colorlist);
  157773. find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist,
  157774. bestcolor);
  157775. c0 <<= BOX_C0_LOG; /* convert ID back to base cell indexes */
  157776. c1 <<= BOX_C1_LOG;
  157777. c2 <<= BOX_C2_LOG;
  157778. cptr = bestcolor;
  157779. for (ic0 = 0; ic0 < BOX_C0_ELEMS; ic0++) {
  157780. for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) {
  157781. cachep = & histogram[c0+ic0][c1+ic1][c2];
  157782. for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) {
  157783. *cachep++ = (histcell) (GETJSAMPLE(*cptr++) + 1);
  157784. }
  157785. }
  157786. }
  157787. }
  157788. METHODDEF(void)
  157789. pass2_no_dither (j_decompress_ptr cinfo,
  157790. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  157791. {
  157792. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157793. hist3d histogram = cquantize->histogram;
  157794. register JSAMPROW inptr, outptr;
  157795. register histptr cachep;
  157796. register int c0, c1, c2;
  157797. int row;
  157798. JDIMENSION col;
  157799. JDIMENSION width = cinfo->output_width;
  157800. for (row = 0; row < num_rows; row++) {
  157801. inptr = input_buf[row];
  157802. outptr = output_buf[row];
  157803. for (col = width; col > 0; col--) {
  157804. c0 = GETJSAMPLE(*inptr++) >> C0_SHIFT;
  157805. c1 = GETJSAMPLE(*inptr++) >> C1_SHIFT;
  157806. c2 = GETJSAMPLE(*inptr++) >> C2_SHIFT;
  157807. cachep = & histogram[c0][c1][c2];
  157808. if (*cachep == 0)
  157809. fill_inverse_cmap(cinfo, c0,c1,c2);
  157810. *outptr++ = (JSAMPLE) (*cachep - 1);
  157811. }
  157812. }
  157813. }
  157814. METHODDEF(void)
  157815. pass2_fs_dither (j_decompress_ptr cinfo,
  157816. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  157817. {
  157818. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157819. hist3d histogram = cquantize->histogram;
  157820. register LOCFSERROR cur0, cur1, cur2; /* current error or pixel value */
  157821. LOCFSERROR belowerr0, belowerr1, belowerr2; /* error for pixel below cur */
  157822. LOCFSERROR bpreverr0, bpreverr1, bpreverr2; /* error for below/prev col */
  157823. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  157824. JSAMPROW inptr; /* => current input pixel */
  157825. JSAMPROW outptr; /* => current output pixel */
  157826. histptr cachep;
  157827. int dir; /* +1 or -1 depending on direction */
  157828. int dir3; /* 3*dir, for advancing inptr & errorptr */
  157829. int row;
  157830. JDIMENSION col;
  157831. JDIMENSION width = cinfo->output_width;
  157832. JSAMPLE *range_limit = cinfo->sample_range_limit;
  157833. int *error_limit = cquantize->error_limiter;
  157834. JSAMPROW colormap0 = cinfo->colormap[0];
  157835. JSAMPROW colormap1 = cinfo->colormap[1];
  157836. JSAMPROW colormap2 = cinfo->colormap[2];
  157837. SHIFT_TEMPS
  157838. for (row = 0; row < num_rows; row++) {
  157839. inptr = input_buf[row];
  157840. outptr = output_buf[row];
  157841. if (cquantize->on_odd_row) {
  157842. inptr += (width-1) * 3; /* so point to rightmost pixel */
  157843. outptr += width-1;
  157844. dir = -1;
  157845. dir3 = -3;
  157846. errorptr = cquantize->fserrors + (width+1)*3; /* => entry after last column */
  157847. cquantize->on_odd_row = FALSE; /* flip for next time */
  157848. } else {
  157849. dir = 1;
  157850. dir3 = 3;
  157851. errorptr = cquantize->fserrors; /* => entry before first real column */
  157852. cquantize->on_odd_row = TRUE; /* flip for next time */
  157853. }
  157854. cur0 = cur1 = cur2 = 0;
  157855. belowerr0 = belowerr1 = belowerr2 = 0;
  157856. bpreverr0 = bpreverr1 = bpreverr2 = 0;
  157857. for (col = width; col > 0; col--) {
  157858. cur0 = RIGHT_SHIFT(cur0 + errorptr[dir3+0] + 8, 4);
  157859. cur1 = RIGHT_SHIFT(cur1 + errorptr[dir3+1] + 8, 4);
  157860. cur2 = RIGHT_SHIFT(cur2 + errorptr[dir3+2] + 8, 4);
  157861. cur0 = error_limit[cur0];
  157862. cur1 = error_limit[cur1];
  157863. cur2 = error_limit[cur2];
  157864. cur0 += GETJSAMPLE(inptr[0]);
  157865. cur1 += GETJSAMPLE(inptr[1]);
  157866. cur2 += GETJSAMPLE(inptr[2]);
  157867. cur0 = GETJSAMPLE(range_limit[cur0]);
  157868. cur1 = GETJSAMPLE(range_limit[cur1]);
  157869. cur2 = GETJSAMPLE(range_limit[cur2]);
  157870. cachep = & histogram[cur0>>C0_SHIFT][cur1>>C1_SHIFT][cur2>>C2_SHIFT];
  157871. if (*cachep == 0)
  157872. fill_inverse_cmap(cinfo, cur0>>C0_SHIFT,cur1>>C1_SHIFT,cur2>>C2_SHIFT);
  157873. { register int pixcode = *cachep - 1;
  157874. *outptr = (JSAMPLE) pixcode;
  157875. cur0 -= GETJSAMPLE(colormap0[pixcode]);
  157876. cur1 -= GETJSAMPLE(colormap1[pixcode]);
  157877. cur2 -= GETJSAMPLE(colormap2[pixcode]);
  157878. }
  157879. { register LOCFSERROR bnexterr, delta;
  157880. bnexterr = cur0; /* Process component 0 */
  157881. delta = cur0 * 2;
  157882. cur0 += delta; /* form error * 3 */
  157883. errorptr[0] = (FSERROR) (bpreverr0 + cur0);
  157884. cur0 += delta; /* form error * 5 */
  157885. bpreverr0 = belowerr0 + cur0;
  157886. belowerr0 = bnexterr;
  157887. cur0 += delta; /* form error * 7 */
  157888. bnexterr = cur1; /* Process component 1 */
  157889. delta = cur1 * 2;
  157890. cur1 += delta; /* form error * 3 */
  157891. errorptr[1] = (FSERROR) (bpreverr1 + cur1);
  157892. cur1 += delta; /* form error * 5 */
  157893. bpreverr1 = belowerr1 + cur1;
  157894. belowerr1 = bnexterr;
  157895. cur1 += delta; /* form error * 7 */
  157896. bnexterr = cur2; /* Process component 2 */
  157897. delta = cur2 * 2;
  157898. cur2 += delta; /* form error * 3 */
  157899. errorptr[2] = (FSERROR) (bpreverr2 + cur2);
  157900. cur2 += delta; /* form error * 5 */
  157901. bpreverr2 = belowerr2 + cur2;
  157902. belowerr2 = bnexterr;
  157903. cur2 += delta; /* form error * 7 */
  157904. }
  157905. inptr += dir3; /* Advance pixel pointers to next column */
  157906. outptr += dir;
  157907. errorptr += dir3; /* advance errorptr to current column */
  157908. }
  157909. errorptr[0] = (FSERROR) bpreverr0; /* unload prev errs into array */
  157910. errorptr[1] = (FSERROR) bpreverr1;
  157911. errorptr[2] = (FSERROR) bpreverr2;
  157912. }
  157913. }
  157914. LOCAL(void)
  157915. init_error_limit (j_decompress_ptr cinfo)
  157916. {
  157917. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157918. int * table;
  157919. int in, out;
  157920. table = (int *) (*cinfo->mem->alloc_small)
  157921. ((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE*2+1) * SIZEOF(int));
  157922. table += MAXJSAMPLE; /* so can index -MAXJSAMPLE .. +MAXJSAMPLE */
  157923. cquantize->error_limiter = table;
  157924. #define STEPSIZE ((MAXJSAMPLE+1)/16)
  157925. out = 0;
  157926. for (in = 0; in < STEPSIZE; in++, out++) {
  157927. table[in] = out; table[-in] = -out;
  157928. }
  157929. for (; in < STEPSIZE*3; in++, out += (in&1) ? 0 : 1) {
  157930. table[in] = out; table[-in] = -out;
  157931. }
  157932. for (; in <= MAXJSAMPLE; in++) {
  157933. table[in] = out; table[-in] = -out;
  157934. }
  157935. #undef STEPSIZE
  157936. }
  157937. METHODDEF(void)
  157938. finish_pass1 (j_decompress_ptr cinfo)
  157939. {
  157940. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157941. cinfo->colormap = cquantize->sv_colormap;
  157942. select_colors(cinfo, cquantize->desired);
  157943. cquantize->needs_zeroed = TRUE;
  157944. }
  157945. METHODDEF(void)
  157946. finish_pass2 (j_decompress_ptr cinfo)
  157947. {
  157948. }
  157949. METHODDEF(void)
  157950. start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  157951. {
  157952. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157953. hist3d histogram = cquantize->histogram;
  157954. int i;
  157955. if (cinfo->dither_mode != JDITHER_NONE)
  157956. cinfo->dither_mode = JDITHER_FS;
  157957. if (is_pre_scan) {
  157958. cquantize->pub.color_quantize = prescan_quantize;
  157959. cquantize->pub.finish_pass = finish_pass1;
  157960. cquantize->needs_zeroed = TRUE; /* Always zero histogram */
  157961. } else {
  157962. if (cinfo->dither_mode == JDITHER_FS)
  157963. cquantize->pub.color_quantize = pass2_fs_dither;
  157964. else
  157965. cquantize->pub.color_quantize = pass2_no_dither;
  157966. cquantize->pub.finish_pass = finish_pass2;
  157967. i = cinfo->actual_number_of_colors;
  157968. if (i < 1)
  157969. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 1);
  157970. if (i > MAXNUMCOLORS)
  157971. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  157972. if (cinfo->dither_mode == JDITHER_FS) {
  157973. size_t arraysize = (size_t) ((cinfo->output_width + 2) *
  157974. (3 * SIZEOF(FSERROR)));
  157975. if (cquantize->fserrors == NULL)
  157976. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  157977. ((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  157978. jzero_far((void FAR *) cquantize->fserrors, arraysize);
  157979. if (cquantize->error_limiter == NULL)
  157980. init_error_limit(cinfo);
  157981. cquantize->on_odd_row = FALSE;
  157982. }
  157983. }
  157984. if (cquantize->needs_zeroed) {
  157985. for (i = 0; i < HIST_C0_ELEMS; i++) {
  157986. jzero_far((void FAR *) histogram[i],
  157987. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  157988. }
  157989. cquantize->needs_zeroed = FALSE;
  157990. }
  157991. }
  157992. METHODDEF(void)
  157993. new_color_map_2_quant (j_decompress_ptr cinfo)
  157994. {
  157995. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157996. cquantize->needs_zeroed = TRUE;
  157997. }
  157998. GLOBAL(void)
  157999. jinit_2pass_quantizer (j_decompress_ptr cinfo)
  158000. {
  158001. my_cquantize_ptr2 cquantize;
  158002. int i;
  158003. cquantize = (my_cquantize_ptr2)
  158004. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158005. SIZEOF(my_cquantizer2));
  158006. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  158007. cquantize->pub.start_pass = start_pass_2_quant;
  158008. cquantize->pub.new_color_map = new_color_map_2_quant;
  158009. cquantize->fserrors = NULL; /* flag optional arrays not allocated */
  158010. cquantize->error_limiter = NULL;
  158011. if (cinfo->out_color_components != 3)
  158012. ERREXIT(cinfo, JERR_NOTIMPL);
  158013. cquantize->histogram = (hist3d) (*cinfo->mem->alloc_small)
  158014. ((j_common_ptr) cinfo, JPOOL_IMAGE, HIST_C0_ELEMS * SIZEOF(hist2d));
  158015. for (i = 0; i < HIST_C0_ELEMS; i++) {
  158016. cquantize->histogram[i] = (hist2d) (*cinfo->mem->alloc_large)
  158017. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158018. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  158019. }
  158020. cquantize->needs_zeroed = TRUE; /* histogram is garbage now */
  158021. if (cinfo->enable_2pass_quant) {
  158022. int desired = cinfo->desired_number_of_colors;
  158023. if (desired < 8)
  158024. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 8);
  158025. if (desired > MAXNUMCOLORS)
  158026. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  158027. cquantize->sv_colormap = (*cinfo->mem->alloc_sarray)
  158028. ((j_common_ptr) cinfo,JPOOL_IMAGE, (JDIMENSION) desired, (JDIMENSION) 3);
  158029. cquantize->desired = desired;
  158030. } else
  158031. cquantize->sv_colormap = NULL;
  158032. if (cinfo->dither_mode != JDITHER_NONE)
  158033. cinfo->dither_mode = JDITHER_FS;
  158034. if (cinfo->dither_mode == JDITHER_FS) {
  158035. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  158036. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158037. (size_t) ((cinfo->output_width + 2) * (3 * SIZEOF(FSERROR))));
  158038. init_error_limit(cinfo);
  158039. }
  158040. }
  158041. #endif /* QUANT_2PASS_SUPPORTED */
  158042. /*** End of inlined file: jquant2.c ***/
  158043. /*** Start of inlined file: jutils.c ***/
  158044. #define JPEG_INTERNALS
  158045. #if 0 /* This table is not actually needed in v6a */
  158046. const int jpeg_zigzag_order[DCTSIZE2] = {
  158047. 0, 1, 5, 6, 14, 15, 27, 28,
  158048. 2, 4, 7, 13, 16, 26, 29, 42,
  158049. 3, 8, 12, 17, 25, 30, 41, 43,
  158050. 9, 11, 18, 24, 31, 40, 44, 53,
  158051. 10, 19, 23, 32, 39, 45, 52, 54,
  158052. 20, 22, 33, 38, 46, 51, 55, 60,
  158053. 21, 34, 37, 47, 50, 56, 59, 61,
  158054. 35, 36, 48, 49, 57, 58, 62, 63
  158055. };
  158056. #endif
  158057. const int jpeg_natural_order[DCTSIZE2+16] = {
  158058. 0, 1, 8, 16, 9, 2, 3, 10,
  158059. 17, 24, 32, 25, 18, 11, 4, 5,
  158060. 12, 19, 26, 33, 40, 48, 41, 34,
  158061. 27, 20, 13, 6, 7, 14, 21, 28,
  158062. 35, 42, 49, 56, 57, 50, 43, 36,
  158063. 29, 22, 15, 23, 30, 37, 44, 51,
  158064. 58, 59, 52, 45, 38, 31, 39, 46,
  158065. 53, 60, 61, 54, 47, 55, 62, 63,
  158066. 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
  158067. 63, 63, 63, 63, 63, 63, 63, 63
  158068. };
  158069. GLOBAL(long)
  158070. jdiv_round_up (long a, long b)
  158071. {
  158072. return (a + b - 1L) / b;
  158073. }
  158074. GLOBAL(long)
  158075. jround_up (long a, long b)
  158076. {
  158077. a += b - 1L;
  158078. return a - (a % b);
  158079. }
  158080. #ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */
  158081. #define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size)
  158082. #define FMEMZERO(target,size) MEMZERO(target,size)
  158083. #else /* 80x86 case, define if we can */
  158084. #ifdef USE_FMEM
  158085. #define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
  158086. #define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
  158087. #endif
  158088. #endif
  158089. GLOBAL(void)
  158090. jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
  158091. JSAMPARRAY output_array, int dest_row,
  158092. int num_rows, JDIMENSION num_cols)
  158093. {
  158094. register JSAMPROW inptr, outptr;
  158095. #ifdef FMEMCOPY
  158096. register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
  158097. #else
  158098. register JDIMENSION count;
  158099. #endif
  158100. register int row;
  158101. input_array += source_row;
  158102. output_array += dest_row;
  158103. for (row = num_rows; row > 0; row--) {
  158104. inptr = *input_array++;
  158105. outptr = *output_array++;
  158106. #ifdef FMEMCOPY
  158107. FMEMCOPY(outptr, inptr, count);
  158108. #else
  158109. for (count = num_cols; count > 0; count--)
  158110. *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */
  158111. #endif
  158112. }
  158113. }
  158114. GLOBAL(void)
  158115. jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
  158116. JDIMENSION num_blocks)
  158117. {
  158118. #ifdef FMEMCOPY
  158119. FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
  158120. #else
  158121. register JCOEFPTR inptr, outptr;
  158122. register long count;
  158123. inptr = (JCOEFPTR) input_row;
  158124. outptr = (JCOEFPTR) output_row;
  158125. for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) {
  158126. *outptr++ = *inptr++;
  158127. }
  158128. #endif
  158129. }
  158130. GLOBAL(void)
  158131. jzero_far (void FAR * target, size_t bytestozero)
  158132. {
  158133. #ifdef FMEMZERO
  158134. FMEMZERO(target, bytestozero);
  158135. #else
  158136. register char FAR * ptr = (char FAR *) target;
  158137. register size_t count;
  158138. for (count = bytestozero; count > 0; count--) {
  158139. *ptr++ = 0;
  158140. }
  158141. #endif
  158142. }
  158143. /*** End of inlined file: jutils.c ***/
  158144. /*** Start of inlined file: transupp.c ***/
  158145. #define JPEG_INTERNALS
  158146. /*** Start of inlined file: transupp.h ***/
  158147. #ifndef TRANSFORMS_SUPPORTED
  158148. #define TRANSFORMS_SUPPORTED 1 /* 0 disables transform code */
  158149. #endif
  158150. #ifdef NEED_SHORT_EXTERNAL_NAMES
  158151. #define jtransform_request_workspace jTrRequest
  158152. #define jtransform_adjust_parameters jTrAdjust
  158153. #define jtransform_execute_transformation jTrExec
  158154. #define jcopy_markers_setup jCMrkSetup
  158155. #define jcopy_markers_execute jCMrkExec
  158156. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  158157. typedef enum {
  158158. JXFORM_NONE, /* no transformation */
  158159. JXFORM_FLIP_H, /* horizontal flip */
  158160. JXFORM_FLIP_V, /* vertical flip */
  158161. JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */
  158162. JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */
  158163. JXFORM_ROT_90, /* 90-degree clockwise rotation */
  158164. JXFORM_ROT_180, /* 180-degree rotation */
  158165. JXFORM_ROT_270 /* 270-degree clockwise (or 90 ccw) */
  158166. } JXFORM_CODE;
  158167. typedef struct {
  158168. JXFORM_CODE transform; /* image transform operator */
  158169. boolean trim; /* if TRUE, trim partial MCUs as needed */
  158170. boolean force_grayscale; /* if TRUE, convert color image to grayscale */
  158171. int num_components; /* # of components in workspace */
  158172. jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */
  158173. } jpeg_transform_info;
  158174. #if TRANSFORMS_SUPPORTED
  158175. EXTERN(void) jtransform_request_workspace
  158176. JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info));
  158177. EXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters
  158178. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158179. jvirt_barray_ptr *src_coef_arrays,
  158180. jpeg_transform_info *info));
  158181. EXTERN(void) jtransform_execute_transformation
  158182. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158183. jvirt_barray_ptr *src_coef_arrays,
  158184. jpeg_transform_info *info));
  158185. #endif /* TRANSFORMS_SUPPORTED */
  158186. typedef enum {
  158187. JCOPYOPT_NONE, /* copy no optional markers */
  158188. JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */
  158189. JCOPYOPT_ALL /* copy all optional markers */
  158190. } JCOPY_OPTION;
  158191. #define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */
  158192. EXTERN(void) jcopy_markers_setup
  158193. JPP((j_decompress_ptr srcinfo, JCOPY_OPTION option));
  158194. EXTERN(void) jcopy_markers_execute
  158195. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158196. JCOPY_OPTION option));
  158197. /*** End of inlined file: transupp.h ***/
  158198. /* My own external interface */
  158199. #if TRANSFORMS_SUPPORTED
  158200. LOCAL(void)
  158201. do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158202. jvirt_barray_ptr *src_coef_arrays)
  158203. {
  158204. JDIMENSION MCU_cols, comp_width, blk_x, blk_y;
  158205. int ci, k, offset_y;
  158206. JBLOCKARRAY buffer;
  158207. JCOEFPTR ptr1, ptr2;
  158208. JCOEF temp1, temp2;
  158209. jpeg_component_info *compptr;
  158210. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158211. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158212. compptr = dstinfo->comp_info + ci;
  158213. comp_width = MCU_cols * compptr->h_samp_factor;
  158214. for (blk_y = 0; blk_y < compptr->height_in_blocks;
  158215. blk_y += compptr->v_samp_factor) {
  158216. buffer = (*srcinfo->mem->access_virt_barray)
  158217. ((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y,
  158218. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158219. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158220. for (blk_x = 0; blk_x * 2 < comp_width; blk_x++) {
  158221. ptr1 = buffer[offset_y][blk_x];
  158222. ptr2 = buffer[offset_y][comp_width - blk_x - 1];
  158223. for (k = 0; k < DCTSIZE2; k += 2) {
  158224. temp1 = *ptr1; /* swap even column */
  158225. temp2 = *ptr2;
  158226. *ptr1++ = temp2;
  158227. *ptr2++ = temp1;
  158228. temp1 = *ptr1; /* swap odd column with sign change */
  158229. temp2 = *ptr2;
  158230. *ptr1++ = -temp2;
  158231. *ptr2++ = -temp1;
  158232. }
  158233. }
  158234. }
  158235. }
  158236. }
  158237. }
  158238. LOCAL(void)
  158239. do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158240. jvirt_barray_ptr *src_coef_arrays,
  158241. jvirt_barray_ptr *dst_coef_arrays)
  158242. {
  158243. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158244. int ci, i, j, offset_y;
  158245. JBLOCKARRAY src_buffer, dst_buffer;
  158246. JBLOCKROW src_row_ptr, dst_row_ptr;
  158247. JCOEFPTR src_ptr, dst_ptr;
  158248. jpeg_component_info *compptr;
  158249. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158250. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158251. compptr = dstinfo->comp_info + ci;
  158252. comp_height = MCU_rows * compptr->v_samp_factor;
  158253. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158254. dst_blk_y += compptr->v_samp_factor) {
  158255. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158256. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158257. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158258. if (dst_blk_y < comp_height) {
  158259. src_buffer = (*srcinfo->mem->access_virt_barray)
  158260. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158261. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158262. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158263. } else {
  158264. src_buffer = (*srcinfo->mem->access_virt_barray)
  158265. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158266. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158267. }
  158268. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158269. if (dst_blk_y < comp_height) {
  158270. dst_row_ptr = dst_buffer[offset_y];
  158271. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158272. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158273. dst_blk_x++) {
  158274. dst_ptr = dst_row_ptr[dst_blk_x];
  158275. src_ptr = src_row_ptr[dst_blk_x];
  158276. for (i = 0; i < DCTSIZE; i += 2) {
  158277. for (j = 0; j < DCTSIZE; j++)
  158278. *dst_ptr++ = *src_ptr++;
  158279. for (j = 0; j < DCTSIZE; j++)
  158280. *dst_ptr++ = - *src_ptr++;
  158281. }
  158282. }
  158283. } else {
  158284. jcopy_block_row(src_buffer[offset_y], dst_buffer[offset_y],
  158285. compptr->width_in_blocks);
  158286. }
  158287. }
  158288. }
  158289. }
  158290. }
  158291. LOCAL(void)
  158292. do_transpose (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158293. jvirt_barray_ptr *src_coef_arrays,
  158294. jvirt_barray_ptr *dst_coef_arrays)
  158295. {
  158296. JDIMENSION dst_blk_x, dst_blk_y;
  158297. int ci, i, j, offset_x, offset_y;
  158298. JBLOCKARRAY src_buffer, dst_buffer;
  158299. JCOEFPTR src_ptr, dst_ptr;
  158300. jpeg_component_info *compptr;
  158301. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158302. compptr = dstinfo->comp_info + ci;
  158303. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158304. dst_blk_y += compptr->v_samp_factor) {
  158305. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158306. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158307. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158308. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158309. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158310. dst_blk_x += compptr->h_samp_factor) {
  158311. src_buffer = (*srcinfo->mem->access_virt_barray)
  158312. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158313. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158314. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158315. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158316. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158317. for (i = 0; i < DCTSIZE; i++)
  158318. for (j = 0; j < DCTSIZE; j++)
  158319. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158320. }
  158321. }
  158322. }
  158323. }
  158324. }
  158325. }
  158326. LOCAL(void)
  158327. do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158328. jvirt_barray_ptr *src_coef_arrays,
  158329. jvirt_barray_ptr *dst_coef_arrays)
  158330. {
  158331. JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y;
  158332. int ci, i, j, offset_x, offset_y;
  158333. JBLOCKARRAY src_buffer, dst_buffer;
  158334. JCOEFPTR src_ptr, dst_ptr;
  158335. jpeg_component_info *compptr;
  158336. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158337. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158338. compptr = dstinfo->comp_info + ci;
  158339. comp_width = MCU_cols * compptr->h_samp_factor;
  158340. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158341. dst_blk_y += compptr->v_samp_factor) {
  158342. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158343. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158344. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158345. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158346. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158347. dst_blk_x += compptr->h_samp_factor) {
  158348. src_buffer = (*srcinfo->mem->access_virt_barray)
  158349. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158350. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158351. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158352. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158353. if (dst_blk_x < comp_width) {
  158354. dst_ptr = dst_buffer[offset_y]
  158355. [comp_width - dst_blk_x - offset_x - 1];
  158356. for (i = 0; i < DCTSIZE; i++) {
  158357. for (j = 0; j < DCTSIZE; j++)
  158358. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158359. i++;
  158360. for (j = 0; j < DCTSIZE; j++)
  158361. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158362. }
  158363. } else {
  158364. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158365. for (i = 0; i < DCTSIZE; i++)
  158366. for (j = 0; j < DCTSIZE; j++)
  158367. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158368. }
  158369. }
  158370. }
  158371. }
  158372. }
  158373. }
  158374. }
  158375. LOCAL(void)
  158376. do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158377. jvirt_barray_ptr *src_coef_arrays,
  158378. jvirt_barray_ptr *dst_coef_arrays)
  158379. {
  158380. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158381. int ci, i, j, offset_x, offset_y;
  158382. JBLOCKARRAY src_buffer, dst_buffer;
  158383. JCOEFPTR src_ptr, dst_ptr;
  158384. jpeg_component_info *compptr;
  158385. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158386. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158387. compptr = dstinfo->comp_info + ci;
  158388. comp_height = MCU_rows * compptr->v_samp_factor;
  158389. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158390. dst_blk_y += compptr->v_samp_factor) {
  158391. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158392. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158393. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158394. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158395. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158396. dst_blk_x += compptr->h_samp_factor) {
  158397. src_buffer = (*srcinfo->mem->access_virt_barray)
  158398. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158399. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158400. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158401. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158402. if (dst_blk_y < comp_height) {
  158403. src_ptr = src_buffer[offset_x]
  158404. [comp_height - dst_blk_y - offset_y - 1];
  158405. for (i = 0; i < DCTSIZE; i++) {
  158406. for (j = 0; j < DCTSIZE; j++) {
  158407. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158408. j++;
  158409. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158410. }
  158411. }
  158412. } else {
  158413. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158414. for (i = 0; i < DCTSIZE; i++)
  158415. for (j = 0; j < DCTSIZE; j++)
  158416. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158417. }
  158418. }
  158419. }
  158420. }
  158421. }
  158422. }
  158423. }
  158424. LOCAL(void)
  158425. do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158426. jvirt_barray_ptr *src_coef_arrays,
  158427. jvirt_barray_ptr *dst_coef_arrays)
  158428. {
  158429. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158430. int ci, i, j, offset_y;
  158431. JBLOCKARRAY src_buffer, dst_buffer;
  158432. JBLOCKROW src_row_ptr, dst_row_ptr;
  158433. JCOEFPTR src_ptr, dst_ptr;
  158434. jpeg_component_info *compptr;
  158435. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158436. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158437. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158438. compptr = dstinfo->comp_info + ci;
  158439. comp_width = MCU_cols * compptr->h_samp_factor;
  158440. comp_height = MCU_rows * compptr->v_samp_factor;
  158441. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158442. dst_blk_y += compptr->v_samp_factor) {
  158443. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158444. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158445. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158446. if (dst_blk_y < comp_height) {
  158447. src_buffer = (*srcinfo->mem->access_virt_barray)
  158448. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158449. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158450. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158451. } else {
  158452. src_buffer = (*srcinfo->mem->access_virt_barray)
  158453. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158454. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158455. }
  158456. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158457. if (dst_blk_y < comp_height) {
  158458. dst_row_ptr = dst_buffer[offset_y];
  158459. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158460. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158461. dst_ptr = dst_row_ptr[dst_blk_x];
  158462. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158463. for (i = 0; i < DCTSIZE; i += 2) {
  158464. for (j = 0; j < DCTSIZE; j += 2) {
  158465. *dst_ptr++ = *src_ptr++;
  158466. *dst_ptr++ = - *src_ptr++;
  158467. }
  158468. for (j = 0; j < DCTSIZE; j += 2) {
  158469. *dst_ptr++ = - *src_ptr++;
  158470. *dst_ptr++ = *src_ptr++;
  158471. }
  158472. }
  158473. }
  158474. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158475. dst_ptr = dst_row_ptr[dst_blk_x];
  158476. src_ptr = src_row_ptr[dst_blk_x];
  158477. for (i = 0; i < DCTSIZE; i += 2) {
  158478. for (j = 0; j < DCTSIZE; j++)
  158479. *dst_ptr++ = *src_ptr++;
  158480. for (j = 0; j < DCTSIZE; j++)
  158481. *dst_ptr++ = - *src_ptr++;
  158482. }
  158483. }
  158484. } else {
  158485. dst_row_ptr = dst_buffer[offset_y];
  158486. src_row_ptr = src_buffer[offset_y];
  158487. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158488. dst_ptr = dst_row_ptr[dst_blk_x];
  158489. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158490. for (i = 0; i < DCTSIZE2; i += 2) {
  158491. *dst_ptr++ = *src_ptr++;
  158492. *dst_ptr++ = - *src_ptr++;
  158493. }
  158494. }
  158495. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158496. dst_ptr = dst_row_ptr[dst_blk_x];
  158497. src_ptr = src_row_ptr[dst_blk_x];
  158498. for (i = 0; i < DCTSIZE2; i++)
  158499. *dst_ptr++ = *src_ptr++;
  158500. }
  158501. }
  158502. }
  158503. }
  158504. }
  158505. }
  158506. LOCAL(void)
  158507. do_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158508. jvirt_barray_ptr *src_coef_arrays,
  158509. jvirt_barray_ptr *dst_coef_arrays)
  158510. {
  158511. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158512. int ci, i, j, offset_x, offset_y;
  158513. JBLOCKARRAY src_buffer, dst_buffer;
  158514. JCOEFPTR src_ptr, dst_ptr;
  158515. jpeg_component_info *compptr;
  158516. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158517. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158518. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158519. compptr = dstinfo->comp_info + ci;
  158520. comp_width = MCU_cols * compptr->h_samp_factor;
  158521. comp_height = MCU_rows * compptr->v_samp_factor;
  158522. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158523. dst_blk_y += compptr->v_samp_factor) {
  158524. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158525. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158526. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158527. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158528. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158529. dst_blk_x += compptr->h_samp_factor) {
  158530. src_buffer = (*srcinfo->mem->access_virt_barray)
  158531. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158532. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158533. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158534. if (dst_blk_y < comp_height) {
  158535. src_ptr = src_buffer[offset_x]
  158536. [comp_height - dst_blk_y - offset_y - 1];
  158537. if (dst_blk_x < comp_width) {
  158538. dst_ptr = dst_buffer[offset_y]
  158539. [comp_width - dst_blk_x - offset_x - 1];
  158540. for (i = 0; i < DCTSIZE; i++) {
  158541. for (j = 0; j < DCTSIZE; j++) {
  158542. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158543. j++;
  158544. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158545. }
  158546. i++;
  158547. for (j = 0; j < DCTSIZE; j++) {
  158548. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158549. j++;
  158550. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158551. }
  158552. }
  158553. } else {
  158554. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158555. for (i = 0; i < DCTSIZE; i++) {
  158556. for (j = 0; j < DCTSIZE; j++) {
  158557. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158558. j++;
  158559. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158560. }
  158561. }
  158562. }
  158563. } else {
  158564. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158565. if (dst_blk_x < comp_width) {
  158566. dst_ptr = dst_buffer[offset_y]
  158567. [comp_width - dst_blk_x - offset_x - 1];
  158568. for (i = 0; i < DCTSIZE; i++) {
  158569. for (j = 0; j < DCTSIZE; j++)
  158570. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158571. i++;
  158572. for (j = 0; j < DCTSIZE; j++)
  158573. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158574. }
  158575. } else {
  158576. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158577. for (i = 0; i < DCTSIZE; i++)
  158578. for (j = 0; j < DCTSIZE; j++)
  158579. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158580. }
  158581. }
  158582. }
  158583. }
  158584. }
  158585. }
  158586. }
  158587. }
  158588. GLOBAL(void)
  158589. jtransform_request_workspace (j_decompress_ptr srcinfo,
  158590. jpeg_transform_info *info)
  158591. {
  158592. jvirt_barray_ptr *coef_arrays = NULL;
  158593. jpeg_component_info *compptr;
  158594. int ci;
  158595. if (info->force_grayscale &&
  158596. srcinfo->jpeg_color_space == JCS_YCbCr &&
  158597. srcinfo->num_components == 3) {
  158598. info->num_components = 1;
  158599. } else {
  158600. info->num_components = srcinfo->num_components;
  158601. }
  158602. switch (info->transform) {
  158603. case JXFORM_NONE:
  158604. case JXFORM_FLIP_H:
  158605. break;
  158606. case JXFORM_FLIP_V:
  158607. case JXFORM_ROT_180:
  158608. coef_arrays = (jvirt_barray_ptr *)
  158609. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  158610. SIZEOF(jvirt_barray_ptr) * info->num_components);
  158611. for (ci = 0; ci < info->num_components; ci++) {
  158612. compptr = srcinfo->comp_info + ci;
  158613. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  158614. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  158615. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  158616. (long) compptr->h_samp_factor),
  158617. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  158618. (long) compptr->v_samp_factor),
  158619. (JDIMENSION) compptr->v_samp_factor);
  158620. }
  158621. break;
  158622. case JXFORM_TRANSPOSE:
  158623. case JXFORM_TRANSVERSE:
  158624. case JXFORM_ROT_90:
  158625. case JXFORM_ROT_270:
  158626. coef_arrays = (jvirt_barray_ptr *)
  158627. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  158628. SIZEOF(jvirt_barray_ptr) * info->num_components);
  158629. for (ci = 0; ci < info->num_components; ci++) {
  158630. compptr = srcinfo->comp_info + ci;
  158631. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  158632. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  158633. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  158634. (long) compptr->v_samp_factor),
  158635. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  158636. (long) compptr->h_samp_factor),
  158637. (JDIMENSION) compptr->h_samp_factor);
  158638. }
  158639. break;
  158640. }
  158641. info->workspace_coef_arrays = coef_arrays;
  158642. }
  158643. LOCAL(void)
  158644. transpose_critical_parameters (j_compress_ptr dstinfo)
  158645. {
  158646. int tblno, i, j, ci, itemp;
  158647. jpeg_component_info *compptr;
  158648. JQUANT_TBL *qtblptr;
  158649. JDIMENSION dtemp;
  158650. UINT16 qtemp;
  158651. dtemp = dstinfo->image_width;
  158652. dstinfo->image_width = dstinfo->image_height;
  158653. dstinfo->image_height = dtemp;
  158654. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158655. compptr = dstinfo->comp_info + ci;
  158656. itemp = compptr->h_samp_factor;
  158657. compptr->h_samp_factor = compptr->v_samp_factor;
  158658. compptr->v_samp_factor = itemp;
  158659. }
  158660. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  158661. qtblptr = dstinfo->quant_tbl_ptrs[tblno];
  158662. if (qtblptr != NULL) {
  158663. for (i = 0; i < DCTSIZE; i++) {
  158664. for (j = 0; j < i; j++) {
  158665. qtemp = qtblptr->quantval[i*DCTSIZE+j];
  158666. qtblptr->quantval[i*DCTSIZE+j] = qtblptr->quantval[j*DCTSIZE+i];
  158667. qtblptr->quantval[j*DCTSIZE+i] = qtemp;
  158668. }
  158669. }
  158670. }
  158671. }
  158672. }
  158673. LOCAL(void)
  158674. trim_right_edge (j_compress_ptr dstinfo)
  158675. {
  158676. int ci, max_h_samp_factor;
  158677. JDIMENSION MCU_cols;
  158678. max_h_samp_factor = 1;
  158679. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158680. int h_samp_factor = dstinfo->comp_info[ci].h_samp_factor;
  158681. max_h_samp_factor = MAX(max_h_samp_factor, h_samp_factor);
  158682. }
  158683. MCU_cols = dstinfo->image_width / (max_h_samp_factor * DCTSIZE);
  158684. if (MCU_cols > 0) /* can't trim to 0 pixels */
  158685. dstinfo->image_width = MCU_cols * (max_h_samp_factor * DCTSIZE);
  158686. }
  158687. LOCAL(void)
  158688. trim_bottom_edge (j_compress_ptr dstinfo)
  158689. {
  158690. int ci, max_v_samp_factor;
  158691. JDIMENSION MCU_rows;
  158692. max_v_samp_factor = 1;
  158693. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158694. int v_samp_factor = dstinfo->comp_info[ci].v_samp_factor;
  158695. max_v_samp_factor = MAX(max_v_samp_factor, v_samp_factor);
  158696. }
  158697. MCU_rows = dstinfo->image_height / (max_v_samp_factor * DCTSIZE);
  158698. if (MCU_rows > 0) /* can't trim to 0 pixels */
  158699. dstinfo->image_height = MCU_rows * (max_v_samp_factor * DCTSIZE);
  158700. }
  158701. GLOBAL(jvirt_barray_ptr *)
  158702. jtransform_adjust_parameters (j_decompress_ptr srcinfo,
  158703. j_compress_ptr dstinfo,
  158704. jvirt_barray_ptr *src_coef_arrays,
  158705. jpeg_transform_info *info)
  158706. {
  158707. if (info->force_grayscale) {
  158708. if ((dstinfo->jpeg_color_space == JCS_YCbCr &&
  158709. dstinfo->num_components == 3) ||
  158710. (dstinfo->jpeg_color_space == JCS_GRAYSCALE &&
  158711. dstinfo->num_components == 1)) {
  158712. int sv_quant_tbl_no = dstinfo->comp_info[0].quant_tbl_no;
  158713. jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE);
  158714. dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no;
  158715. } else {
  158716. ERREXIT(dstinfo, JERR_CONVERSION_NOTIMPL);
  158717. }
  158718. }
  158719. switch (info->transform) {
  158720. case JXFORM_NONE:
  158721. break;
  158722. case JXFORM_FLIP_H:
  158723. if (info->trim)
  158724. trim_right_edge(dstinfo);
  158725. break;
  158726. case JXFORM_FLIP_V:
  158727. if (info->trim)
  158728. trim_bottom_edge(dstinfo);
  158729. break;
  158730. case JXFORM_TRANSPOSE:
  158731. transpose_critical_parameters(dstinfo);
  158732. break;
  158733. case JXFORM_TRANSVERSE:
  158734. transpose_critical_parameters(dstinfo);
  158735. if (info->trim) {
  158736. trim_right_edge(dstinfo);
  158737. trim_bottom_edge(dstinfo);
  158738. }
  158739. break;
  158740. case JXFORM_ROT_90:
  158741. transpose_critical_parameters(dstinfo);
  158742. if (info->trim)
  158743. trim_right_edge(dstinfo);
  158744. break;
  158745. case JXFORM_ROT_180:
  158746. if (info->trim) {
  158747. trim_right_edge(dstinfo);
  158748. trim_bottom_edge(dstinfo);
  158749. }
  158750. break;
  158751. case JXFORM_ROT_270:
  158752. transpose_critical_parameters(dstinfo);
  158753. if (info->trim)
  158754. trim_bottom_edge(dstinfo);
  158755. break;
  158756. }
  158757. if (info->workspace_coef_arrays != NULL)
  158758. return info->workspace_coef_arrays;
  158759. return src_coef_arrays;
  158760. }
  158761. GLOBAL(void)
  158762. jtransform_execute_transformation (j_decompress_ptr srcinfo,
  158763. j_compress_ptr dstinfo,
  158764. jvirt_barray_ptr *src_coef_arrays,
  158765. jpeg_transform_info *info)
  158766. {
  158767. jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays;
  158768. switch (info->transform) {
  158769. case JXFORM_NONE:
  158770. break;
  158771. case JXFORM_FLIP_H:
  158772. do_flip_h(srcinfo, dstinfo, src_coef_arrays);
  158773. break;
  158774. case JXFORM_FLIP_V:
  158775. do_flip_v(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158776. break;
  158777. case JXFORM_TRANSPOSE:
  158778. do_transpose(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158779. break;
  158780. case JXFORM_TRANSVERSE:
  158781. do_transverse(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158782. break;
  158783. case JXFORM_ROT_90:
  158784. do_rot_90(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158785. break;
  158786. case JXFORM_ROT_180:
  158787. do_rot_180(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158788. break;
  158789. case JXFORM_ROT_270:
  158790. do_rot_270(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158791. break;
  158792. }
  158793. }
  158794. #endif /* TRANSFORMS_SUPPORTED */
  158795. GLOBAL(void)
  158796. jcopy_markers_setup (j_decompress_ptr srcinfo, JCOPY_OPTION option)
  158797. {
  158798. #ifdef SAVE_MARKERS_SUPPORTED
  158799. int m;
  158800. if (option != JCOPYOPT_NONE) {
  158801. jpeg_save_markers(srcinfo, JPEG_COM, 0xFFFF);
  158802. }
  158803. if (option == JCOPYOPT_ALL) {
  158804. for (m = 0; m < 16; m++)
  158805. jpeg_save_markers(srcinfo, JPEG_APP0 + m, 0xFFFF);
  158806. }
  158807. #endif /* SAVE_MARKERS_SUPPORTED */
  158808. }
  158809. GLOBAL(void)
  158810. jcopy_markers_execute (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158811. JCOPY_OPTION option)
  158812. {
  158813. jpeg_saved_marker_ptr marker;
  158814. for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) {
  158815. if (dstinfo->write_JFIF_header &&
  158816. marker->marker == JPEG_APP0 &&
  158817. marker->data_length >= 5 &&
  158818. GETJOCTET(marker->data[0]) == 0x4A &&
  158819. GETJOCTET(marker->data[1]) == 0x46 &&
  158820. GETJOCTET(marker->data[2]) == 0x49 &&
  158821. GETJOCTET(marker->data[3]) == 0x46 &&
  158822. GETJOCTET(marker->data[4]) == 0)
  158823. continue; /* reject duplicate JFIF */
  158824. if (dstinfo->write_Adobe_marker &&
  158825. marker->marker == JPEG_APP0+14 &&
  158826. marker->data_length >= 5 &&
  158827. GETJOCTET(marker->data[0]) == 0x41 &&
  158828. GETJOCTET(marker->data[1]) == 0x64 &&
  158829. GETJOCTET(marker->data[2]) == 0x6F &&
  158830. GETJOCTET(marker->data[3]) == 0x62 &&
  158831. GETJOCTET(marker->data[4]) == 0x65)
  158832. continue; /* reject duplicate Adobe */
  158833. #ifdef NEED_FAR_POINTERS
  158834. {
  158835. unsigned int i;
  158836. jpeg_write_m_header(dstinfo, marker->marker, marker->data_length);
  158837. for (i = 0; i < marker->data_length; i++)
  158838. jpeg_write_m_byte(dstinfo, marker->data[i]);
  158839. }
  158840. #else
  158841. jpeg_write_marker(dstinfo, marker->marker,
  158842. marker->data, marker->data_length);
  158843. #endif
  158844. }
  158845. }
  158846. /*** End of inlined file: transupp.c ***/
  158847. }
  158848. #else
  158849. #define JPEG_INTERNALS
  158850. #undef FAR
  158851. #include <jpeglib.h>
  158852. #endif
  158853. }
  158854. #undef max
  158855. #undef min
  158856. #if JUCE_MSVC
  158857. #pragma warning (pop)
  158858. #endif
  158859. BEGIN_JUCE_NAMESPACE
  158860. namespace JPEGHelpers
  158861. {
  158862. using namespace jpeglibNamespace;
  158863. #if ! JUCE_MSVC
  158864. using jpeglibNamespace::boolean;
  158865. #endif
  158866. struct JPEGDecodingFailure {};
  158867. static void fatalErrorHandler (j_common_ptr)
  158868. {
  158869. throw JPEGDecodingFailure();
  158870. }
  158871. static void silentErrorCallback1 (j_common_ptr) {}
  158872. static void silentErrorCallback2 (j_common_ptr, int) {}
  158873. static void silentErrorCallback3 (j_common_ptr, char*) {}
  158874. static void setupSilentErrorHandler (struct jpeg_error_mgr& err)
  158875. {
  158876. zerostruct (err);
  158877. err.error_exit = fatalErrorHandler;
  158878. err.emit_message = silentErrorCallback2;
  158879. err.output_message = silentErrorCallback1;
  158880. err.format_message = silentErrorCallback3;
  158881. err.reset_error_mgr = silentErrorCallback1;
  158882. }
  158883. static void dummyCallback1 (j_decompress_ptr)
  158884. {
  158885. }
  158886. static void jpegSkip (j_decompress_ptr decompStruct, long num)
  158887. {
  158888. decompStruct->src->next_input_byte += num;
  158889. num = jmin (num, (long) decompStruct->src->bytes_in_buffer);
  158890. decompStruct->src->bytes_in_buffer -= num;
  158891. }
  158892. static boolean jpegFill (j_decompress_ptr)
  158893. {
  158894. return 0;
  158895. }
  158896. static const int jpegBufferSize = 512;
  158897. struct JuceJpegDest : public jpeg_destination_mgr
  158898. {
  158899. OutputStream* output;
  158900. char* buffer;
  158901. };
  158902. static void jpegWriteInit (j_compress_ptr)
  158903. {
  158904. }
  158905. static void jpegWriteTerminate (j_compress_ptr cinfo)
  158906. {
  158907. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  158908. const size_t numToWrite = jpegBufferSize - dest->free_in_buffer;
  158909. dest->output->write (dest->buffer, (int) numToWrite);
  158910. }
  158911. static boolean jpegWriteFlush (j_compress_ptr cinfo)
  158912. {
  158913. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  158914. const int numToWrite = jpegBufferSize;
  158915. dest->next_output_byte = (JOCTET*) dest->buffer;
  158916. dest->free_in_buffer = jpegBufferSize;
  158917. return dest->output->write (dest->buffer, numToWrite);
  158918. }
  158919. }
  158920. Image* juce_loadJPEGImageFromStream (InputStream& in)
  158921. {
  158922. using namespace jpeglibNamespace;
  158923. using namespace JPEGHelpers;
  158924. MemoryBlock mb;
  158925. in.readIntoMemoryBlock (mb);
  158926. Image* image = 0;
  158927. if (mb.getSize() > 16)
  158928. {
  158929. struct jpeg_decompress_struct jpegDecompStruct;
  158930. struct jpeg_error_mgr jerr;
  158931. setupSilentErrorHandler (jerr);
  158932. jpegDecompStruct.err = &jerr;
  158933. jpeg_create_decompress (&jpegDecompStruct);
  158934. jpegDecompStruct.src = (jpeg_source_mgr*)(jpegDecompStruct.mem->alloc_small)
  158935. ((j_common_ptr)(&jpegDecompStruct), JPOOL_PERMANENT, sizeof (jpeg_source_mgr));
  158936. jpegDecompStruct.src->init_source = dummyCallback1;
  158937. jpegDecompStruct.src->fill_input_buffer = jpegFill;
  158938. jpegDecompStruct.src->skip_input_data = jpegSkip;
  158939. jpegDecompStruct.src->resync_to_restart = jpeg_resync_to_restart;
  158940. jpegDecompStruct.src->term_source = dummyCallback1;
  158941. jpegDecompStruct.src->next_input_byte = (const unsigned char*) mb.getData();
  158942. jpegDecompStruct.src->bytes_in_buffer = mb.getSize();
  158943. try
  158944. {
  158945. jpeg_read_header (&jpegDecompStruct, TRUE);
  158946. jpeg_calc_output_dimensions (&jpegDecompStruct);
  158947. const int width = jpegDecompStruct.output_width;
  158948. const int height = jpegDecompStruct.output_height;
  158949. jpegDecompStruct.out_color_space = JCS_RGB;
  158950. JSAMPARRAY buffer
  158951. = (*jpegDecompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegDecompStruct,
  158952. JPOOL_IMAGE,
  158953. width * 3, 1);
  158954. if (jpeg_start_decompress (&jpegDecompStruct))
  158955. {
  158956. image = Image::createNativeImage (Image::RGB, width, height, false);
  158957. const bool hasAlphaChan = image->hasAlphaChannel();
  158958. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  158959. for (int y = 0; y < height; ++y)
  158960. {
  158961. jpeg_read_scanlines (&jpegDecompStruct, buffer, 1);
  158962. const uint8* src = *buffer;
  158963. uint8* dest = destData.getLinePointer (y);
  158964. if (hasAlphaChan)
  158965. {
  158966. for (int i = width; --i >= 0;)
  158967. {
  158968. ((PixelARGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  158969. ((PixelARGB*) dest)->premultiply();
  158970. dest += destData.pixelStride;
  158971. src += 3;
  158972. }
  158973. }
  158974. else
  158975. {
  158976. for (int i = width; --i >= 0;)
  158977. {
  158978. ((PixelRGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  158979. dest += destData.pixelStride;
  158980. src += 3;
  158981. }
  158982. }
  158983. }
  158984. jpeg_finish_decompress (&jpegDecompStruct);
  158985. in.setPosition (((char*) jpegDecompStruct.src->next_input_byte) - (char*) mb.getData());
  158986. }
  158987. jpeg_destroy_decompress (&jpegDecompStruct);
  158988. }
  158989. catch (...)
  158990. {}
  158991. }
  158992. return image;
  158993. }
  158994. bool juce_writeJPEGImageToStream (const Image& image,
  158995. OutputStream& out,
  158996. float quality)
  158997. {
  158998. using namespace jpeglibNamespace;
  158999. using namespace JPEGHelpers;
  159000. if (image.hasAlphaChannel())
  159001. {
  159002. // this method could fill the background in white and still save the image..
  159003. jassertfalse
  159004. return true;
  159005. }
  159006. struct jpeg_compress_struct jpegCompStruct;
  159007. struct jpeg_error_mgr jerr;
  159008. setupSilentErrorHandler (jerr);
  159009. jpegCompStruct.err = &jerr;
  159010. jpeg_create_compress (&jpegCompStruct);
  159011. JuceJpegDest dest;
  159012. jpegCompStruct.dest = &dest;
  159013. dest.output = &out;
  159014. HeapBlock <char> tempBuffer (jpegBufferSize);
  159015. dest.buffer = (char*) tempBuffer;
  159016. dest.next_output_byte = (JOCTET*) dest.buffer;
  159017. dest.free_in_buffer = jpegBufferSize;
  159018. dest.init_destination = jpegWriteInit;
  159019. dest.empty_output_buffer = jpegWriteFlush;
  159020. dest.term_destination = jpegWriteTerminate;
  159021. jpegCompStruct.image_width = image.getWidth();
  159022. jpegCompStruct.image_height = image.getHeight();
  159023. jpegCompStruct.input_components = 3;
  159024. jpegCompStruct.in_color_space = JCS_RGB;
  159025. jpegCompStruct.write_JFIF_header = 1;
  159026. jpegCompStruct.X_density = 72;
  159027. jpegCompStruct.Y_density = 72;
  159028. jpeg_set_defaults (&jpegCompStruct);
  159029. jpegCompStruct.dct_method = JDCT_FLOAT;
  159030. jpegCompStruct.optimize_coding = 1;
  159031. //jpegCompStruct.smoothing_factor = 10;
  159032. if (quality < 0.0f)
  159033. quality = 0.85f;
  159034. jpeg_set_quality (&jpegCompStruct, jlimit (0, 100, roundToInt (quality * 100.0f)), TRUE);
  159035. jpeg_start_compress (&jpegCompStruct, TRUE);
  159036. const int strideBytes = jpegCompStruct.image_width * jpegCompStruct.input_components;
  159037. JSAMPARRAY buffer = (*jpegCompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegCompStruct,
  159038. JPOOL_IMAGE, strideBytes, 1);
  159039. const Image::BitmapData srcData (image, 0, 0, jpegCompStruct.image_width, jpegCompStruct.image_height);
  159040. while (jpegCompStruct.next_scanline < jpegCompStruct.image_height)
  159041. {
  159042. const uint8* src = srcData.getLinePointer (jpegCompStruct.next_scanline);
  159043. uint8* dst = *buffer;
  159044. for (int i = jpegCompStruct.image_width; --i >= 0;)
  159045. {
  159046. *dst++ = ((const PixelRGB*) src)->getRed();
  159047. *dst++ = ((const PixelRGB*) src)->getGreen();
  159048. *dst++ = ((const PixelRGB*) src)->getBlue();
  159049. src += srcData.pixelStride;
  159050. }
  159051. jpeg_write_scanlines (&jpegCompStruct, buffer, 1);
  159052. }
  159053. jpeg_finish_compress (&jpegCompStruct);
  159054. jpeg_destroy_compress (&jpegCompStruct);
  159055. out.flush();
  159056. return true;
  159057. }
  159058. END_JUCE_NAMESPACE
  159059. /*** End of inlined file: juce_JPEGLoader.cpp ***/
  159060. /*** Start of inlined file: juce_PNGLoader.cpp ***/
  159061. #ifdef _MSC_VER
  159062. #pragma warning (push)
  159063. #pragma warning (disable: 4390 4611)
  159064. #endif
  159065. namespace zlibNamespace
  159066. {
  159067. #if JUCE_INCLUDE_ZLIB_CODE
  159068. #undef OS_CODE
  159069. #undef fdopen
  159070. #undef OS_CODE
  159071. #else
  159072. #include <zlib.h>
  159073. #endif
  159074. }
  159075. namespace pnglibNamespace
  159076. {
  159077. using namespace zlibNamespace;
  159078. #if JUCE_INCLUDE_PNGLIB_CODE
  159079. #if _MSC_VER != 1310
  159080. using ::calloc; // (causes conflict in VS.NET 2003)
  159081. using ::malloc;
  159082. using ::free;
  159083. #endif
  159084. extern "C"
  159085. {
  159086. using ::abs;
  159087. #define PNG_INTERNAL
  159088. #define NO_DUMMY_DECL
  159089. #define PNG_SETJMP_NOT_SUPPORTED
  159090. /*** Start of inlined file: png.h ***/
  159091. #ifndef PNG_H
  159092. #define PNG_H
  159093. #define PNG_LIBPNG_VER_STRING "1.2.21"
  159094. #define PNG_HEADER_VERSION_STRING \
  159095. " libpng version 1.2.21 - October 4, 2007\n"
  159096. #define PNG_LIBPNG_VER_SONUM 0
  159097. #define PNG_LIBPNG_VER_DLLNUM 13
  159098. #define PNG_LIBPNG_VER_MAJOR 1
  159099. #define PNG_LIBPNG_VER_MINOR 2
  159100. #define PNG_LIBPNG_VER_RELEASE 21
  159101. #define PNG_LIBPNG_VER_BUILD 0
  159102. #define PNG_LIBPNG_BUILD_ALPHA 1
  159103. #define PNG_LIBPNG_BUILD_BETA 2
  159104. #define PNG_LIBPNG_BUILD_RC 3
  159105. #define PNG_LIBPNG_BUILD_STABLE 4
  159106. #define PNG_LIBPNG_BUILD_RELEASE_STATUS_MASK 7
  159107. #define PNG_LIBPNG_BUILD_PATCH 8 /* Can be OR'ed with
  159108. PNG_LIBPNG_BUILD_STABLE only */
  159109. #define PNG_LIBPNG_BUILD_PRIVATE 16 /* Cannot be OR'ed with
  159110. PNG_LIBPNG_BUILD_SPECIAL */
  159111. #define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with
  159112. PNG_LIBPNG_BUILD_PRIVATE */
  159113. #define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_STABLE
  159114. #define PNG_LIBPNG_VER 10221 /* 1.2.21 */
  159115. #ifndef PNG_VERSION_INFO_ONLY
  159116. #endif
  159117. /*** Start of inlined file: pngconf.h ***/
  159118. #ifndef PNGCONF_H
  159119. #define PNGCONF_H
  159120. #define PNG_1_2_X
  159121. // These are some Juce config settings that should remove any unnecessary code bloat..
  159122. #define PNG_NO_STDIO 1
  159123. #define PNG_DEBUG 0
  159124. #define PNG_NO_WARNINGS 1
  159125. #define PNG_NO_ERROR_TEXT 1
  159126. #define PNG_NO_ERROR_NUMBERS 1
  159127. #define PNG_NO_USER_MEM 1
  159128. #define PNG_NO_READ_iCCP 1
  159129. #define PNG_NO_READ_UNKNOWN_CHUNKS 1
  159130. #define PNG_NO_READ_USER_CHUNKS 1
  159131. #define PNG_NO_READ_iTXt 1
  159132. #define PNG_NO_READ_sCAL 1
  159133. #define PNG_NO_READ_sPLT 1
  159134. #define png_error(a, b) png_err(a)
  159135. #define png_warning(a, b)
  159136. #define png_chunk_error(a, b) png_err(a)
  159137. #define png_chunk_warning(a, b)
  159138. #ifdef PNG_USER_CONFIG
  159139. # ifndef PNG_USER_PRIVATEBUILD
  159140. # define PNG_USER_PRIVATEBUILD
  159141. # endif
  159142. #include "pngusr.h"
  159143. #endif
  159144. #ifdef PNG_CONFIGURE_LIBPNG
  159145. #ifdef HAVE_CONFIG_H
  159146. #include "config.h"
  159147. #endif
  159148. #endif
  159149. #ifdef __STDC__
  159150. #ifdef SPECIALBUILD
  159151. # pragma message("PNG_LIBPNG_SPECIALBUILD (and deprecated SPECIALBUILD)\
  159152. are now LIBPNG reserved macros. Use PNG_USER_PRIVATEBUILD instead.")
  159153. #endif
  159154. #ifdef PRIVATEBUILD
  159155. # pragma message("PRIVATEBUILD is deprecated.\
  159156. Use PNG_USER_PRIVATEBUILD instead.")
  159157. # define PNG_USER_PRIVATEBUILD PRIVATEBUILD
  159158. #endif
  159159. #endif /* __STDC__ */
  159160. #ifndef PNG_VERSION_INFO_ONLY
  159161. # define PNG_WARN_UNINITIALIZED_ROW 1
  159162. #ifndef PNG_ZBUF_SIZE
  159163. # define PNG_ZBUF_SIZE 8192
  159164. #endif
  159165. #ifndef PNG_NO_READ_SUPPORTED
  159166. # define PNG_READ_SUPPORTED
  159167. #endif
  159168. #ifndef PNG_NO_WRITE_SUPPORTED
  159169. # define PNG_WRITE_SUPPORTED
  159170. #endif
  159171. #if !defined(PNG_1_0_X) && !defined(PNG_NO_MNG_FEATURES)
  159172. # ifndef PNG_MNG_FEATURES_SUPPORTED
  159173. # define PNG_MNG_FEATURES_SUPPORTED
  159174. # endif
  159175. #endif
  159176. #ifndef PNG_NO_FLOATING_POINT_SUPPORTED
  159177. # ifndef PNG_FLOATING_POINT_SUPPORTED
  159178. # define PNG_FLOATING_POINT_SUPPORTED
  159179. # endif
  159180. #endif
  159181. #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
  159182. # define PNG_MAX_MALLOC_64K
  159183. #endif
  159184. #if defined(__CYGWIN__)
  159185. # if defined(ALL_STATIC)
  159186. # if defined(PNG_BUILD_DLL)
  159187. # undef PNG_BUILD_DLL
  159188. # endif
  159189. # if defined(PNG_USE_DLL)
  159190. # undef PNG_USE_DLL
  159191. # endif
  159192. # if defined(PNG_DLL)
  159193. # undef PNG_DLL
  159194. # endif
  159195. # if !defined(PNG_STATIC)
  159196. # define PNG_STATIC
  159197. # endif
  159198. # else
  159199. # if defined (PNG_BUILD_DLL)
  159200. # if defined(PNG_STATIC)
  159201. # undef PNG_STATIC
  159202. # endif
  159203. # if defined(PNG_USE_DLL)
  159204. # undef PNG_USE_DLL
  159205. # endif
  159206. # if !defined(PNG_DLL)
  159207. # define PNG_DLL
  159208. # endif
  159209. # else
  159210. # if defined(PNG_STATIC)
  159211. # if defined(PNG_USE_DLL)
  159212. # undef PNG_USE_DLL
  159213. # endif
  159214. # if defined(PNG_DLL)
  159215. # undef PNG_DLL
  159216. # endif
  159217. # else
  159218. # if !defined(PNG_USE_DLL)
  159219. # define PNG_USE_DLL
  159220. # endif
  159221. # if !defined(PNG_DLL)
  159222. # define PNG_DLL
  159223. # endif
  159224. # endif
  159225. # endif
  159226. # endif
  159227. #endif
  159228. #if defined(_WIN32_WCE)
  159229. # include <windows.h>
  159230. # define PNG_NO_CONSOLE_IO
  159231. # ifdef PNG_DEBUG
  159232. # undef PNG_DEBUG
  159233. # endif
  159234. #endif
  159235. #ifdef PNG_BUILD_DLL
  159236. # ifndef PNG_CONSOLE_IO_SUPPORTED
  159237. # ifndef PNG_NO_CONSOLE_IO
  159238. # define PNG_NO_CONSOLE_IO
  159239. # endif
  159240. # endif
  159241. #endif
  159242. # ifdef PNG_NO_STDIO
  159243. # ifndef PNG_NO_CONSOLE_IO
  159244. # define PNG_NO_CONSOLE_IO
  159245. # endif
  159246. # ifdef PNG_DEBUG
  159247. # if (PNG_DEBUG > 0)
  159248. # include <stdio.h>
  159249. # endif
  159250. # endif
  159251. # else
  159252. # if !defined(_WIN32_WCE)
  159253. # include <stdio.h>
  159254. # endif
  159255. # endif
  159256. #ifndef PNGARG
  159257. #ifdef OF /* zlib prototype munger */
  159258. # define PNGARG(arglist) OF(arglist)
  159259. #else
  159260. #ifdef _NO_PROTO
  159261. # define PNGARG(arglist) ()
  159262. # ifndef PNG_TYPECAST_NULL
  159263. # define PNG_TYPECAST_NULL
  159264. # endif
  159265. #else
  159266. # define PNGARG(arglist) arglist
  159267. #endif /* _NO_PROTO */
  159268. #endif /* OF */
  159269. #endif /* PNGARG */
  159270. #ifndef MACOS
  159271. # if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
  159272. defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
  159273. # define MACOS
  159274. # endif
  159275. #endif
  159276. #if !defined(MACOS) && !defined(RISCOS) && !defined(_WIN32_WCE)
  159277. # include <sys/types.h>
  159278. #endif
  159279. #if !defined(PNG_SETJMP_NOT_SUPPORTED) && !defined(PNG_NO_SETJMP_SUPPORTED)
  159280. # define PNG_SETJMP_SUPPORTED
  159281. #endif
  159282. #ifdef PNG_SETJMP_SUPPORTED
  159283. # ifdef __linux__
  159284. # ifdef _BSD_SOURCE
  159285. # define PNG_SAVE_BSD_SOURCE
  159286. # undef _BSD_SOURCE
  159287. # endif
  159288. # ifdef _SETJMP_H
  159289. __png.h__ already includes setjmp.h;
  159290. __dont__ include it again.;
  159291. # endif
  159292. # endif /* __linux__ */
  159293. # include <setjmp.h>
  159294. # ifdef __linux__
  159295. # ifdef PNG_SAVE_BSD_SOURCE
  159296. # define _BSD_SOURCE
  159297. # undef PNG_SAVE_BSD_SOURCE
  159298. # endif
  159299. # endif /* __linux__ */
  159300. #endif /* PNG_SETJMP_SUPPORTED */
  159301. #ifdef BSD
  159302. #if ! JUCE_MAC
  159303. # include <strings.h>
  159304. #endif
  159305. #else
  159306. # include <string.h>
  159307. #endif
  159308. #ifdef PNG_INTERNAL
  159309. #include <stdlib.h>
  159310. #define PNG_EXTERN
  159311. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  159312. # if defined(MACOS)
  159313. # if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
  159314. # include <fp.h>
  159315. # endif
  159316. # else
  159317. # include <math.h>
  159318. # endif
  159319. # if defined(_AMIGA) && defined(__SASC) && defined(_M68881)
  159320. # include <m68881.h>
  159321. # endif
  159322. #endif
  159323. #if (defined(__MWERKS__) && defined(WIN32)) || defined(__STDC__)
  159324. # define PNG_ALWAYS_EXTERN
  159325. #endif
  159326. #if defined(__TURBOC__) && defined(__MSDOS__)
  159327. # include <mem.h>
  159328. # include <alloc.h>
  159329. #endif
  159330. #if defined(_MSC_VER) && (defined(WIN32) || defined(_Windows) || \
  159331. defined(_WINDOWS) || defined(_WIN32) || defined(__WIN32__))
  159332. # include <malloc.h>
  159333. #endif
  159334. #ifndef PNG_DITHER_RED_BITS
  159335. # define PNG_DITHER_RED_BITS 5
  159336. #endif
  159337. #ifndef PNG_DITHER_GREEN_BITS
  159338. # define PNG_DITHER_GREEN_BITS 5
  159339. #endif
  159340. #ifndef PNG_DITHER_BLUE_BITS
  159341. # define PNG_DITHER_BLUE_BITS 5
  159342. #endif
  159343. #ifndef PNG_MAX_GAMMA_8
  159344. # define PNG_MAX_GAMMA_8 11
  159345. #endif
  159346. #ifndef PNG_GAMMA_THRESHOLD
  159347. # define PNG_GAMMA_THRESHOLD 0.05
  159348. #endif
  159349. #endif /* PNG_INTERNAL */
  159350. #ifndef PNG_NO_CONST
  159351. # define PNG_CONST const
  159352. #else
  159353. # define PNG_CONST
  159354. #endif
  159355. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159356. # ifndef PNG_NO_iTXt_SUPPORTED
  159357. # define PNG_NO_iTXt_SUPPORTED
  159358. # endif
  159359. # ifndef PNG_NO_READ_iTXt
  159360. # define PNG_NO_READ_iTXt
  159361. # endif
  159362. # ifndef PNG_NO_WRITE_iTXt
  159363. # define PNG_NO_WRITE_iTXt
  159364. # endif
  159365. #endif
  159366. #if !defined(PNG_NO_iTXt_SUPPORTED)
  159367. # if !defined(PNG_READ_iTXt_SUPPORTED) && !defined(PNG_NO_READ_iTXt)
  159368. # define PNG_READ_iTXt
  159369. # endif
  159370. # if !defined(PNG_WRITE_iTXt_SUPPORTED) && !defined(PNG_NO_WRITE_iTXt)
  159371. # define PNG_WRITE_iTXt
  159372. # endif
  159373. #endif
  159374. #ifdef PNG_LEGACY_SUPPORTED
  159375. # define PNG_NO_FREE_ME
  159376. # define PNG_NO_READ_UNKNOWN_CHUNKS
  159377. # define PNG_NO_WRITE_UNKNOWN_CHUNKS
  159378. # define PNG_NO_READ_USER_CHUNKS
  159379. # define PNG_NO_READ_iCCP
  159380. # define PNG_NO_WRITE_iCCP
  159381. # define PNG_NO_READ_iTXt
  159382. # define PNG_NO_WRITE_iTXt
  159383. # define PNG_NO_READ_sCAL
  159384. # define PNG_NO_WRITE_sCAL
  159385. # define PNG_NO_READ_sPLT
  159386. # define PNG_NO_WRITE_sPLT
  159387. # define PNG_NO_INFO_IMAGE
  159388. # define PNG_NO_READ_RGB_TO_GRAY
  159389. # define PNG_NO_READ_USER_TRANSFORM
  159390. # define PNG_NO_WRITE_USER_TRANSFORM
  159391. # define PNG_NO_USER_MEM
  159392. # define PNG_NO_READ_EMPTY_PLTE
  159393. # define PNG_NO_MNG_FEATURES
  159394. # define PNG_NO_FIXED_POINT_SUPPORTED
  159395. #endif
  159396. #if !defined(PNG_FLOATING_POINT_SUPPORTED) || \
  159397. !defined(PNG_NO_FIXED_POINT_SUPPORTED)
  159398. # define PNG_FIXED_POINT_SUPPORTED
  159399. #endif
  159400. #ifndef PNG_NO_FREE_ME
  159401. # define PNG_FREE_ME_SUPPORTED
  159402. #endif
  159403. #if defined(PNG_READ_SUPPORTED)
  159404. #if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \
  159405. !defined(PNG_NO_READ_TRANSFORMS)
  159406. # define PNG_READ_TRANSFORMS_SUPPORTED
  159407. #endif
  159408. #ifdef PNG_READ_TRANSFORMS_SUPPORTED
  159409. # ifndef PNG_NO_READ_EXPAND
  159410. # define PNG_READ_EXPAND_SUPPORTED
  159411. # endif
  159412. # ifndef PNG_NO_READ_SHIFT
  159413. # define PNG_READ_SHIFT_SUPPORTED
  159414. # endif
  159415. # ifndef PNG_NO_READ_PACK
  159416. # define PNG_READ_PACK_SUPPORTED
  159417. # endif
  159418. # ifndef PNG_NO_READ_BGR
  159419. # define PNG_READ_BGR_SUPPORTED
  159420. # endif
  159421. # ifndef PNG_NO_READ_SWAP
  159422. # define PNG_READ_SWAP_SUPPORTED
  159423. # endif
  159424. # ifndef PNG_NO_READ_PACKSWAP
  159425. # define PNG_READ_PACKSWAP_SUPPORTED
  159426. # endif
  159427. # ifndef PNG_NO_READ_INVERT
  159428. # define PNG_READ_INVERT_SUPPORTED
  159429. # endif
  159430. # ifndef PNG_NO_READ_DITHER
  159431. # define PNG_READ_DITHER_SUPPORTED
  159432. # endif
  159433. # ifndef PNG_NO_READ_BACKGROUND
  159434. # define PNG_READ_BACKGROUND_SUPPORTED
  159435. # endif
  159436. # ifndef PNG_NO_READ_16_TO_8
  159437. # define PNG_READ_16_TO_8_SUPPORTED
  159438. # endif
  159439. # ifndef PNG_NO_READ_FILLER
  159440. # define PNG_READ_FILLER_SUPPORTED
  159441. # endif
  159442. # ifndef PNG_NO_READ_GAMMA
  159443. # define PNG_READ_GAMMA_SUPPORTED
  159444. # endif
  159445. # ifndef PNG_NO_READ_GRAY_TO_RGB
  159446. # define PNG_READ_GRAY_TO_RGB_SUPPORTED
  159447. # endif
  159448. # ifndef PNG_NO_READ_SWAP_ALPHA
  159449. # define PNG_READ_SWAP_ALPHA_SUPPORTED
  159450. # endif
  159451. # ifndef PNG_NO_READ_INVERT_ALPHA
  159452. # define PNG_READ_INVERT_ALPHA_SUPPORTED
  159453. # endif
  159454. # ifndef PNG_NO_READ_STRIP_ALPHA
  159455. # define PNG_READ_STRIP_ALPHA_SUPPORTED
  159456. # endif
  159457. # ifndef PNG_NO_READ_USER_TRANSFORM
  159458. # define PNG_READ_USER_TRANSFORM_SUPPORTED
  159459. # endif
  159460. # ifndef PNG_NO_READ_RGB_TO_GRAY
  159461. # define PNG_READ_RGB_TO_GRAY_SUPPORTED
  159462. # endif
  159463. #endif /* PNG_READ_TRANSFORMS_SUPPORTED */
  159464. #if !defined(PNG_NO_PROGRESSIVE_READ) && \
  159465. !defined(PNG_PROGRESSIVE_READ_SUPPORTED) /* if you don't do progressive */
  159466. # define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */
  159467. #endif /* about interlacing capability! You'll */
  159468. #define PNG_READ_INTERLACING_SUPPORTED /* required in PNG-compliant decoders */
  159469. #ifndef PNG_NO_READ_COMPOSITE_NODIV
  159470. # ifndef PNG_NO_READ_COMPOSITED_NODIV /* libpng-1.0.x misspelling */
  159471. # define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel, SGI */
  159472. # endif
  159473. #endif
  159474. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159475. #ifndef PNG_NO_READ_EMPTY_PLTE
  159476. # define PNG_READ_EMPTY_PLTE_SUPPORTED
  159477. #endif
  159478. #endif
  159479. #endif /* PNG_READ_SUPPORTED */
  159480. #if defined(PNG_WRITE_SUPPORTED)
  159481. # if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \
  159482. !defined(PNG_NO_WRITE_TRANSFORMS)
  159483. # define PNG_WRITE_TRANSFORMS_SUPPORTED
  159484. #endif
  159485. #ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
  159486. # ifndef PNG_NO_WRITE_SHIFT
  159487. # define PNG_WRITE_SHIFT_SUPPORTED
  159488. # endif
  159489. # ifndef PNG_NO_WRITE_PACK
  159490. # define PNG_WRITE_PACK_SUPPORTED
  159491. # endif
  159492. # ifndef PNG_NO_WRITE_BGR
  159493. # define PNG_WRITE_BGR_SUPPORTED
  159494. # endif
  159495. # ifndef PNG_NO_WRITE_SWAP
  159496. # define PNG_WRITE_SWAP_SUPPORTED
  159497. # endif
  159498. # ifndef PNG_NO_WRITE_PACKSWAP
  159499. # define PNG_WRITE_PACKSWAP_SUPPORTED
  159500. # endif
  159501. # ifndef PNG_NO_WRITE_INVERT
  159502. # define PNG_WRITE_INVERT_SUPPORTED
  159503. # endif
  159504. # ifndef PNG_NO_WRITE_FILLER
  159505. # define PNG_WRITE_FILLER_SUPPORTED /* same as WRITE_STRIP_ALPHA */
  159506. # endif
  159507. # ifndef PNG_NO_WRITE_SWAP_ALPHA
  159508. # define PNG_WRITE_SWAP_ALPHA_SUPPORTED
  159509. # endif
  159510. # ifndef PNG_NO_WRITE_INVERT_ALPHA
  159511. # define PNG_WRITE_INVERT_ALPHA_SUPPORTED
  159512. # endif
  159513. # ifndef PNG_NO_WRITE_USER_TRANSFORM
  159514. # define PNG_WRITE_USER_TRANSFORM_SUPPORTED
  159515. # endif
  159516. #endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
  159517. #if !defined(PNG_NO_WRITE_INTERLACING_SUPPORTED) && \
  159518. !defined(PNG_WRITE_INTERLACING_SUPPORTED)
  159519. #define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant
  159520. encoders, but can cause trouble
  159521. if left undefined */
  159522. #endif
  159523. #if !defined(PNG_NO_WRITE_WEIGHTED_FILTER) && \
  159524. !defined(PNG_WRITE_WEIGHTED_FILTER) && \
  159525. defined(PNG_FLOATING_POINT_SUPPORTED)
  159526. # define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
  159527. #endif
  159528. #ifndef PNG_NO_WRITE_FLUSH
  159529. # define PNG_WRITE_FLUSH_SUPPORTED
  159530. #endif
  159531. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159532. #ifndef PNG_NO_WRITE_EMPTY_PLTE
  159533. # define PNG_WRITE_EMPTY_PLTE_SUPPORTED
  159534. #endif
  159535. #endif
  159536. #endif /* PNG_WRITE_SUPPORTED */
  159537. #ifndef PNG_1_0_X
  159538. # ifndef PNG_NO_ERROR_NUMBERS
  159539. # define PNG_ERROR_NUMBERS_SUPPORTED
  159540. # endif
  159541. #endif /* PNG_1_0_X */
  159542. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  159543. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  159544. # ifndef PNG_NO_USER_TRANSFORM_PTR
  159545. # define PNG_USER_TRANSFORM_PTR_SUPPORTED
  159546. # endif
  159547. #endif
  159548. #ifndef PNG_NO_STDIO
  159549. # define PNG_TIME_RFC1123_SUPPORTED
  159550. #endif
  159551. #if !defined(PNG_NO_EASY_ACCESS) && !defined(PNG_EASY_ACCESS_SUPPORTED)
  159552. # define PNG_EASY_ACCESS_SUPPORTED
  159553. #endif
  159554. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_OPTIMIZED_CODE)
  159555. # ifndef PNG_OPTIMIZED_CODE_SUPPORTED
  159556. # define PNG_OPTIMIZED_CODE_SUPPORTED
  159557. # endif
  159558. #endif
  159559. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_ASSEMBLER_CODE)
  159560. # ifndef PNG_ASSEMBLER_CODE_SUPPORTED
  159561. # define PNG_ASSEMBLER_CODE_SUPPORTED
  159562. # endif
  159563. # if defined(__GNUC__) && defined(__x86_64__) && (__GNUC__ < 4)
  159564. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159565. # define PNG_NO_MMX_CODE
  159566. # endif
  159567. # endif
  159568. # if defined(__APPLE__)
  159569. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159570. # define PNG_NO_MMX_CODE
  159571. # endif
  159572. # endif
  159573. # if (defined(__MWERKS__) && ((__MWERKS__ < 0x0900) || macintosh))
  159574. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159575. # define PNG_NO_MMX_CODE
  159576. # endif
  159577. # endif
  159578. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159579. # define PNG_MMX_CODE_SUPPORTED
  159580. # endif
  159581. #endif
  159582. #if !defined(PNG_1_0_X)
  159583. #if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED)
  159584. # define PNG_USER_MEM_SUPPORTED
  159585. #endif
  159586. #endif /* PNG_1_0_X */
  159587. #if !defined(PNG_1_0_X)
  159588. #ifndef PNG_SET_USER_LIMITS_SUPPORTED
  159589. #if !defined(PNG_NO_SET_USER_LIMITS) && !defined(PNG_SET_USER_LIMITS_SUPPORTED)
  159590. # define PNG_SET_USER_LIMITS_SUPPORTED
  159591. #endif
  159592. #endif
  159593. #endif /* PNG_1_0_X */
  159594. #ifndef PNG_USER_WIDTH_MAX
  159595. # define PNG_USER_WIDTH_MAX 1000000L
  159596. #endif
  159597. #ifndef PNG_USER_HEIGHT_MAX
  159598. # define PNG_USER_HEIGHT_MAX 1000000L
  159599. #endif
  159600. #if defined(PNG_READ_SUPPORTED) && \
  159601. !defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  159602. !defined(PNG_NO_READ_ANCILLARY_CHUNKS)
  159603. # define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  159604. #endif
  159605. #if defined(PNG_WRITE_SUPPORTED) && \
  159606. !defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  159607. !defined(PNG_NO_WRITE_ANCILLARY_CHUNKS)
  159608. # define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  159609. #endif
  159610. #ifdef PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  159611. #ifdef PNG_NO_READ_TEXT
  159612. # define PNG_NO_READ_iTXt
  159613. # define PNG_NO_READ_tEXt
  159614. # define PNG_NO_READ_zTXt
  159615. #endif
  159616. #ifndef PNG_NO_READ_bKGD
  159617. # define PNG_READ_bKGD_SUPPORTED
  159618. # define PNG_bKGD_SUPPORTED
  159619. #endif
  159620. #ifndef PNG_NO_READ_cHRM
  159621. # define PNG_READ_cHRM_SUPPORTED
  159622. # define PNG_cHRM_SUPPORTED
  159623. #endif
  159624. #ifndef PNG_NO_READ_gAMA
  159625. # define PNG_READ_gAMA_SUPPORTED
  159626. # define PNG_gAMA_SUPPORTED
  159627. #endif
  159628. #ifndef PNG_NO_READ_hIST
  159629. # define PNG_READ_hIST_SUPPORTED
  159630. # define PNG_hIST_SUPPORTED
  159631. #endif
  159632. #ifndef PNG_NO_READ_iCCP
  159633. # define PNG_READ_iCCP_SUPPORTED
  159634. # define PNG_iCCP_SUPPORTED
  159635. #endif
  159636. #ifndef PNG_NO_READ_iTXt
  159637. # ifndef PNG_READ_iTXt_SUPPORTED
  159638. # define PNG_READ_iTXt_SUPPORTED
  159639. # endif
  159640. # ifndef PNG_iTXt_SUPPORTED
  159641. # define PNG_iTXt_SUPPORTED
  159642. # endif
  159643. #endif
  159644. #ifndef PNG_NO_READ_oFFs
  159645. # define PNG_READ_oFFs_SUPPORTED
  159646. # define PNG_oFFs_SUPPORTED
  159647. #endif
  159648. #ifndef PNG_NO_READ_pCAL
  159649. # define PNG_READ_pCAL_SUPPORTED
  159650. # define PNG_pCAL_SUPPORTED
  159651. #endif
  159652. #ifndef PNG_NO_READ_sCAL
  159653. # define PNG_READ_sCAL_SUPPORTED
  159654. # define PNG_sCAL_SUPPORTED
  159655. #endif
  159656. #ifndef PNG_NO_READ_pHYs
  159657. # define PNG_READ_pHYs_SUPPORTED
  159658. # define PNG_pHYs_SUPPORTED
  159659. #endif
  159660. #ifndef PNG_NO_READ_sBIT
  159661. # define PNG_READ_sBIT_SUPPORTED
  159662. # define PNG_sBIT_SUPPORTED
  159663. #endif
  159664. #ifndef PNG_NO_READ_sPLT
  159665. # define PNG_READ_sPLT_SUPPORTED
  159666. # define PNG_sPLT_SUPPORTED
  159667. #endif
  159668. #ifndef PNG_NO_READ_sRGB
  159669. # define PNG_READ_sRGB_SUPPORTED
  159670. # define PNG_sRGB_SUPPORTED
  159671. #endif
  159672. #ifndef PNG_NO_READ_tEXt
  159673. # define PNG_READ_tEXt_SUPPORTED
  159674. # define PNG_tEXt_SUPPORTED
  159675. #endif
  159676. #ifndef PNG_NO_READ_tIME
  159677. # define PNG_READ_tIME_SUPPORTED
  159678. # define PNG_tIME_SUPPORTED
  159679. #endif
  159680. #ifndef PNG_NO_READ_tRNS
  159681. # define PNG_READ_tRNS_SUPPORTED
  159682. # define PNG_tRNS_SUPPORTED
  159683. #endif
  159684. #ifndef PNG_NO_READ_zTXt
  159685. # define PNG_READ_zTXt_SUPPORTED
  159686. # define PNG_zTXt_SUPPORTED
  159687. #endif
  159688. #ifndef PNG_NO_READ_UNKNOWN_CHUNKS
  159689. # define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
  159690. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  159691. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  159692. # endif
  159693. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  159694. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159695. # endif
  159696. #endif
  159697. #if !defined(PNG_NO_READ_USER_CHUNKS) && \
  159698. defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  159699. # define PNG_READ_USER_CHUNKS_SUPPORTED
  159700. # define PNG_USER_CHUNKS_SUPPORTED
  159701. # ifdef PNG_NO_READ_UNKNOWN_CHUNKS
  159702. # undef PNG_NO_READ_UNKNOWN_CHUNKS
  159703. # endif
  159704. # ifdef PNG_NO_HANDLE_AS_UNKNOWN
  159705. # undef PNG_NO_HANDLE_AS_UNKNOWN
  159706. # endif
  159707. #endif
  159708. #ifndef PNG_NO_READ_OPT_PLTE
  159709. # define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */
  159710. #endif /* optional PLTE chunk in RGB and RGBA images */
  159711. #if defined(PNG_READ_iTXt_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) || \
  159712. defined(PNG_READ_zTXt_SUPPORTED)
  159713. # define PNG_READ_TEXT_SUPPORTED
  159714. # define PNG_TEXT_SUPPORTED
  159715. #endif
  159716. #endif /* PNG_READ_ANCILLARY_CHUNKS_SUPPORTED */
  159717. #ifdef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  159718. #ifdef PNG_NO_WRITE_TEXT
  159719. # define PNG_NO_WRITE_iTXt
  159720. # define PNG_NO_WRITE_tEXt
  159721. # define PNG_NO_WRITE_zTXt
  159722. #endif
  159723. #ifndef PNG_NO_WRITE_bKGD
  159724. # define PNG_WRITE_bKGD_SUPPORTED
  159725. # ifndef PNG_bKGD_SUPPORTED
  159726. # define PNG_bKGD_SUPPORTED
  159727. # endif
  159728. #endif
  159729. #ifndef PNG_NO_WRITE_cHRM
  159730. # define PNG_WRITE_cHRM_SUPPORTED
  159731. # ifndef PNG_cHRM_SUPPORTED
  159732. # define PNG_cHRM_SUPPORTED
  159733. # endif
  159734. #endif
  159735. #ifndef PNG_NO_WRITE_gAMA
  159736. # define PNG_WRITE_gAMA_SUPPORTED
  159737. # ifndef PNG_gAMA_SUPPORTED
  159738. # define PNG_gAMA_SUPPORTED
  159739. # endif
  159740. #endif
  159741. #ifndef PNG_NO_WRITE_hIST
  159742. # define PNG_WRITE_hIST_SUPPORTED
  159743. # ifndef PNG_hIST_SUPPORTED
  159744. # define PNG_hIST_SUPPORTED
  159745. # endif
  159746. #endif
  159747. #ifndef PNG_NO_WRITE_iCCP
  159748. # define PNG_WRITE_iCCP_SUPPORTED
  159749. # ifndef PNG_iCCP_SUPPORTED
  159750. # define PNG_iCCP_SUPPORTED
  159751. # endif
  159752. #endif
  159753. #ifndef PNG_NO_WRITE_iTXt
  159754. # ifndef PNG_WRITE_iTXt_SUPPORTED
  159755. # define PNG_WRITE_iTXt_SUPPORTED
  159756. # endif
  159757. # ifndef PNG_iTXt_SUPPORTED
  159758. # define PNG_iTXt_SUPPORTED
  159759. # endif
  159760. #endif
  159761. #ifndef PNG_NO_WRITE_oFFs
  159762. # define PNG_WRITE_oFFs_SUPPORTED
  159763. # ifndef PNG_oFFs_SUPPORTED
  159764. # define PNG_oFFs_SUPPORTED
  159765. # endif
  159766. #endif
  159767. #ifndef PNG_NO_WRITE_pCAL
  159768. # define PNG_WRITE_pCAL_SUPPORTED
  159769. # ifndef PNG_pCAL_SUPPORTED
  159770. # define PNG_pCAL_SUPPORTED
  159771. # endif
  159772. #endif
  159773. #ifndef PNG_NO_WRITE_sCAL
  159774. # define PNG_WRITE_sCAL_SUPPORTED
  159775. # ifndef PNG_sCAL_SUPPORTED
  159776. # define PNG_sCAL_SUPPORTED
  159777. # endif
  159778. #endif
  159779. #ifndef PNG_NO_WRITE_pHYs
  159780. # define PNG_WRITE_pHYs_SUPPORTED
  159781. # ifndef PNG_pHYs_SUPPORTED
  159782. # define PNG_pHYs_SUPPORTED
  159783. # endif
  159784. #endif
  159785. #ifndef PNG_NO_WRITE_sBIT
  159786. # define PNG_WRITE_sBIT_SUPPORTED
  159787. # ifndef PNG_sBIT_SUPPORTED
  159788. # define PNG_sBIT_SUPPORTED
  159789. # endif
  159790. #endif
  159791. #ifndef PNG_NO_WRITE_sPLT
  159792. # define PNG_WRITE_sPLT_SUPPORTED
  159793. # ifndef PNG_sPLT_SUPPORTED
  159794. # define PNG_sPLT_SUPPORTED
  159795. # endif
  159796. #endif
  159797. #ifndef PNG_NO_WRITE_sRGB
  159798. # define PNG_WRITE_sRGB_SUPPORTED
  159799. # ifndef PNG_sRGB_SUPPORTED
  159800. # define PNG_sRGB_SUPPORTED
  159801. # endif
  159802. #endif
  159803. #ifndef PNG_NO_WRITE_tEXt
  159804. # define PNG_WRITE_tEXt_SUPPORTED
  159805. # ifndef PNG_tEXt_SUPPORTED
  159806. # define PNG_tEXt_SUPPORTED
  159807. # endif
  159808. #endif
  159809. #ifndef PNG_NO_WRITE_tIME
  159810. # define PNG_WRITE_tIME_SUPPORTED
  159811. # ifndef PNG_tIME_SUPPORTED
  159812. # define PNG_tIME_SUPPORTED
  159813. # endif
  159814. #endif
  159815. #ifndef PNG_NO_WRITE_tRNS
  159816. # define PNG_WRITE_tRNS_SUPPORTED
  159817. # ifndef PNG_tRNS_SUPPORTED
  159818. # define PNG_tRNS_SUPPORTED
  159819. # endif
  159820. #endif
  159821. #ifndef PNG_NO_WRITE_zTXt
  159822. # define PNG_WRITE_zTXt_SUPPORTED
  159823. # ifndef PNG_zTXt_SUPPORTED
  159824. # define PNG_zTXt_SUPPORTED
  159825. # endif
  159826. #endif
  159827. #ifndef PNG_NO_WRITE_UNKNOWN_CHUNKS
  159828. # define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
  159829. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  159830. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  159831. # endif
  159832. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  159833. # ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159834. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159835. # endif
  159836. # endif
  159837. #endif
  159838. #if defined(PNG_WRITE_iTXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
  159839. defined(PNG_WRITE_zTXt_SUPPORTED)
  159840. # define PNG_WRITE_TEXT_SUPPORTED
  159841. # ifndef PNG_TEXT_SUPPORTED
  159842. # define PNG_TEXT_SUPPORTED
  159843. # endif
  159844. #endif
  159845. #endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */
  159846. #ifndef PNG_NO_INFO_IMAGE
  159847. # define PNG_INFO_IMAGE_SUPPORTED
  159848. #endif
  159849. #if defined(PNG_tIME_SUPPORTED)
  159850. # if !defined(_WIN32_WCE)
  159851. # include <time.h>
  159852. # endif
  159853. #endif
  159854. typedef unsigned long png_uint_32;
  159855. typedef long png_int_32;
  159856. typedef unsigned short png_uint_16;
  159857. typedef short png_int_16;
  159858. typedef unsigned char png_byte;
  159859. #ifdef PNG_SIZE_T
  159860. typedef PNG_SIZE_T png_size_t;
  159861. # define png_sizeof(x) png_convert_size(sizeof (x))
  159862. #else
  159863. typedef size_t png_size_t;
  159864. # define png_sizeof(x) sizeof (x)
  159865. #endif
  159866. #ifdef __BORLANDC__
  159867. # if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
  159868. # define LDATA 1
  159869. # else
  159870. # define LDATA 0
  159871. # endif
  159872. # if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__)
  159873. # define PNG_MAX_MALLOC_64K
  159874. # if (LDATA != 1)
  159875. # ifndef FAR
  159876. # define FAR __far
  159877. # endif
  159878. # define USE_FAR_KEYWORD
  159879. # endif /* LDATA != 1 */
  159880. # endif /* __WIN32__, __FLAT__, __CYGWIN__ */
  159881. #endif /* __BORLANDC__ */
  159882. #if defined(FAR)
  159883. # if defined(M_I86MM)
  159884. # define USE_FAR_KEYWORD
  159885. # define FARDATA FAR
  159886. # include <dos.h>
  159887. # endif
  159888. #endif
  159889. #ifndef FAR
  159890. # define FAR
  159891. #endif
  159892. #ifndef FARDATA
  159893. # define FARDATA
  159894. #endif
  159895. typedef png_int_32 png_fixed_point;
  159896. typedef void FAR * png_voidp;
  159897. typedef png_byte FAR * png_bytep;
  159898. typedef png_uint_32 FAR * png_uint_32p;
  159899. typedef png_int_32 FAR * png_int_32p;
  159900. typedef png_uint_16 FAR * png_uint_16p;
  159901. typedef png_int_16 FAR * png_int_16p;
  159902. typedef PNG_CONST char FAR * png_const_charp;
  159903. typedef char FAR * png_charp;
  159904. typedef png_fixed_point FAR * png_fixed_point_p;
  159905. #ifndef PNG_NO_STDIO
  159906. #if defined(_WIN32_WCE)
  159907. typedef HANDLE png_FILE_p;
  159908. #else
  159909. typedef FILE * png_FILE_p;
  159910. #endif
  159911. #endif
  159912. #ifdef PNG_FLOATING_POINT_SUPPORTED
  159913. typedef double FAR * png_doublep;
  159914. #endif
  159915. typedef png_byte FAR * FAR * png_bytepp;
  159916. typedef png_uint_32 FAR * FAR * png_uint_32pp;
  159917. typedef png_int_32 FAR * FAR * png_int_32pp;
  159918. typedef png_uint_16 FAR * FAR * png_uint_16pp;
  159919. typedef png_int_16 FAR * FAR * png_int_16pp;
  159920. typedef PNG_CONST char FAR * FAR * png_const_charpp;
  159921. typedef char FAR * FAR * png_charpp;
  159922. typedef png_fixed_point FAR * FAR * png_fixed_point_pp;
  159923. #ifdef PNG_FLOATING_POINT_SUPPORTED
  159924. typedef double FAR * FAR * png_doublepp;
  159925. #endif
  159926. typedef char FAR * FAR * FAR * png_charppp;
  159927. #if 0
  159928. typedef charf * png_zcharp;
  159929. typedef charf * FAR * png_zcharpp;
  159930. typedef z_stream FAR * png_zstreamp;
  159931. #endif /* (PNG_1_0_X) || defined(PNG_1_2_X) */
  159932. #if !defined(PNG_DLL) && (defined(PNG_BUILD_DLL) || defined(PNG_USE_DLL))
  159933. # define PNG_DLL
  159934. #endif
  159935. #if defined(__CYGWIN__)
  159936. # if !defined(PNG_STATIC)
  159937. # if defined(PNG_USE_GLOBAL_ARRAYS)
  159938. # undef PNG_USE_GLOBAL_ARRAYS
  159939. # endif
  159940. # if !defined(PNG_USE_LOCAL_ARRAYS)
  159941. # define PNG_USE_LOCAL_ARRAYS
  159942. # endif
  159943. # else
  159944. # if defined(PNG_USE_LOCAL_ARRAYS) || defined(PNG_NO_GLOBAL_ARRAYS)
  159945. # if defined(PNG_USE_GLOBAL_ARRAYS)
  159946. # undef PNG_USE_GLOBAL_ARRAYS
  159947. # endif
  159948. # endif
  159949. # endif
  159950. # if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  159951. # define PNG_USE_LOCAL_ARRAYS
  159952. # endif
  159953. #endif
  159954. #if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  159955. # if defined(PNG_NO_GLOBAL_ARRAYS) || \
  159956. (defined(__GNUC__) && defined(PNG_DLL)) || defined(_MSC_VER)
  159957. # define PNG_USE_LOCAL_ARRAYS
  159958. # else
  159959. # define PNG_USE_GLOBAL_ARRAYS
  159960. # endif
  159961. #endif
  159962. #if defined(__CYGWIN__)
  159963. # undef PNGAPI
  159964. # define PNGAPI __cdecl
  159965. # undef PNG_IMPEXP
  159966. # define PNG_IMPEXP
  159967. #endif
  159968. #if defined(__MINGW32__) && !defined(PNG_MODULEDEF)
  159969. # ifndef PNG_NO_MODULEDEF
  159970. # define PNG_NO_MODULEDEF
  159971. # endif
  159972. #endif
  159973. #if !defined(PNG_IMPEXP) && defined(PNG_BUILD_DLL) && !defined(PNG_NO_MODULEDEF)
  159974. # define PNG_IMPEXP
  159975. #endif
  159976. #if defined(PNG_DLL) || defined(_DLL) || defined(__DLL__ ) || \
  159977. (( defined(_Windows) || defined(_WINDOWS) || \
  159978. defined(WIN32) || defined(_WIN32) || defined(__WIN32__) ))
  159979. # ifndef PNGAPI
  159980. # if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800))
  159981. # define PNGAPI __cdecl
  159982. # else
  159983. # define PNGAPI _cdecl
  159984. # endif
  159985. # endif
  159986. # if !defined(PNG_IMPEXP) && (!defined(PNG_DLL) || \
  159987. 0 /* WINCOMPILER_WITH_NO_SUPPORT_FOR_DECLIMPEXP */)
  159988. # define PNG_IMPEXP
  159989. # endif
  159990. # if !defined(PNG_IMPEXP)
  159991. # define PNG_EXPORT_TYPE1(type,symbol) PNG_IMPEXP type PNGAPI symbol
  159992. # define PNG_EXPORT_TYPE2(type,symbol) type PNG_IMPEXP PNGAPI symbol
  159993. # if defined(_MSC_VER) || defined(__BORLANDC__)
  159994. # if (_MSC_VER >= 800) || (__BORLANDC__ >= 0x500)
  159995. # define PNG_EXPORT PNG_EXPORT_TYPE1
  159996. # else
  159997. # define PNG_EXPORT PNG_EXPORT_TYPE2
  159998. # if defined(PNG_BUILD_DLL)
  159999. # define PNG_IMPEXP __export
  160000. # else
  160001. # define PNG_IMPEXP /*__import */ /* doesn't exist AFAIK in
  160002. VC++ */
  160003. # endif /* Exists in Borland C++ for
  160004. C++ classes (== huge) */
  160005. # endif
  160006. # endif
  160007. # if !defined(PNG_IMPEXP)
  160008. # if defined(PNG_BUILD_DLL)
  160009. # define PNG_IMPEXP __declspec(dllexport)
  160010. # else
  160011. # define PNG_IMPEXP __declspec(dllimport)
  160012. # endif
  160013. # endif
  160014. # endif /* PNG_IMPEXP */
  160015. #else /* !(DLL || non-cygwin WINDOWS) */
  160016. # if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
  160017. # ifndef PNGAPI
  160018. # define PNGAPI _System
  160019. # endif
  160020. # else
  160021. # if 0 /* ... other platforms, with other meanings */
  160022. # endif
  160023. # endif
  160024. #endif
  160025. #ifndef PNGAPI
  160026. # define PNGAPI
  160027. #endif
  160028. #ifndef PNG_IMPEXP
  160029. # define PNG_IMPEXP
  160030. #endif
  160031. #ifdef PNG_BUILDSYMS
  160032. # ifndef PNG_EXPORT
  160033. # define PNG_EXPORT(type,symbol) PNG_FUNCTION_EXPORT symbol END
  160034. # endif
  160035. # ifdef PNG_USE_GLOBAL_ARRAYS
  160036. # ifndef PNG_EXPORT_VAR
  160037. # define PNG_EXPORT_VAR(type) PNG_DATA_EXPORT
  160038. # endif
  160039. # endif
  160040. #endif
  160041. #ifndef PNG_EXPORT
  160042. # define PNG_EXPORT(type,symbol) PNG_IMPEXP type PNGAPI symbol
  160043. #endif
  160044. #ifdef PNG_USE_GLOBAL_ARRAYS
  160045. # ifndef PNG_EXPORT_VAR
  160046. # define PNG_EXPORT_VAR(type) extern PNG_IMPEXP type
  160047. # endif
  160048. #endif
  160049. #ifndef PNG_ABORT
  160050. # define PNG_ABORT() abort()
  160051. #endif
  160052. #ifdef PNG_SETJMP_SUPPORTED
  160053. # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
  160054. #else
  160055. # define png_jmpbuf(png_ptr) \
  160056. (LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED)
  160057. #endif
  160058. #if defined(USE_FAR_KEYWORD) /* memory model independent fns */
  160059. # define CHECK 1
  160060. # define NOCHECK 0
  160061. # define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
  160062. # define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
  160063. # define png_snprintf _fsnprintf /* Added to v 1.2.19 */
  160064. # define png_strcpy _fstrcpy
  160065. # define png_strncpy _fstrncpy /* Added to v 1.2.6 */
  160066. # define png_strlen _fstrlen
  160067. # define png_memcmp _fmemcmp /* SJT: added */
  160068. # define png_memcpy _fmemcpy
  160069. # define png_memset _fmemset
  160070. #else /* use the usual functions */
  160071. # define CVT_PTR(ptr) (ptr)
  160072. # define CVT_PTR_NOCHECK(ptr) (ptr)
  160073. # ifndef PNG_NO_SNPRINTF
  160074. # ifdef _MSC_VER
  160075. # define png_snprintf _snprintf /* Added to v 1.2.19 */
  160076. # define png_snprintf2 _snprintf
  160077. # define png_snprintf6 _snprintf
  160078. # else
  160079. # define png_snprintf snprintf /* Added to v 1.2.19 */
  160080. # define png_snprintf2 snprintf
  160081. # define png_snprintf6 snprintf
  160082. # endif
  160083. # else
  160084. # define png_snprintf(s1,n,fmt,x1) sprintf(s1,fmt,x1)
  160085. # define png_snprintf2(s1,n,fmt,x1,x2) sprintf(s1,fmt,x1,x2)
  160086. # define png_snprintf6(s1,n,fmt,x1,x2,x3,x4,x5,x6) \
  160087. sprintf(s1,fmt,x1,x2,x3,x4,x5,x6)
  160088. # endif
  160089. # define png_strcpy strcpy
  160090. # define png_strncpy strncpy /* Added to v 1.2.6 */
  160091. # define png_strlen strlen
  160092. # define png_memcmp memcmp /* SJT: added */
  160093. # define png_memcpy memcpy
  160094. # define png_memset memset
  160095. #endif
  160096. #if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K)
  160097. # undef PNG_ZBUF_SIZE
  160098. # define PNG_ZBUF_SIZE 65536L
  160099. #endif
  160100. #endif /* PNG_VERSION_INFO_ONLY */
  160101. #endif /* PNGCONF_H */
  160102. /*** End of inlined file: pngconf.h ***/
  160103. #ifdef _MSC_VER
  160104. #pragma warning (disable: 4996 4100)
  160105. #endif
  160106. #if defined(PNG_USER_PRIVATEBUILD)
  160107. # define PNG_LIBPNG_BUILD_TYPE \
  160108. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_PRIVATE)
  160109. #else
  160110. # if defined(PNG_LIBPNG_SPECIALBUILD)
  160111. # define PNG_LIBPNG_BUILD_TYPE \
  160112. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_SPECIAL)
  160113. # else
  160114. # define PNG_LIBPNG_BUILD_TYPE (PNG_LIBPNG_BUILD_BASE_TYPE)
  160115. # endif
  160116. #endif
  160117. #ifndef PNG_VERSION_INFO_ONLY
  160118. #ifdef __cplusplus
  160119. extern "C" {
  160120. #endif /* __cplusplus */
  160121. #ifndef PNG_NO_TYPECAST_NULL
  160122. #define int_p_NULL (int *)NULL
  160123. #define png_bytep_NULL (png_bytep)NULL
  160124. #define png_bytepp_NULL (png_bytepp)NULL
  160125. #define png_doublep_NULL (png_doublep)NULL
  160126. #define png_error_ptr_NULL (png_error_ptr)NULL
  160127. #define png_flush_ptr_NULL (png_flush_ptr)NULL
  160128. #define png_free_ptr_NULL (png_free_ptr)NULL
  160129. #define png_infopp_NULL (png_infopp)NULL
  160130. #define png_malloc_ptr_NULL (png_malloc_ptr)NULL
  160131. #define png_read_status_ptr_NULL (png_read_status_ptr)NULL
  160132. #define png_rw_ptr_NULL (png_rw_ptr)NULL
  160133. #define png_structp_NULL (png_structp)NULL
  160134. #define png_uint_16p_NULL (png_uint_16p)NULL
  160135. #define png_voidp_NULL (png_voidp)NULL
  160136. #define png_write_status_ptr_NULL (png_write_status_ptr)NULL
  160137. #else
  160138. #define int_p_NULL NULL
  160139. #define png_bytep_NULL NULL
  160140. #define png_bytepp_NULL NULL
  160141. #define png_doublep_NULL NULL
  160142. #define png_error_ptr_NULL NULL
  160143. #define png_flush_ptr_NULL NULL
  160144. #define png_free_ptr_NULL NULL
  160145. #define png_infopp_NULL NULL
  160146. #define png_malloc_ptr_NULL NULL
  160147. #define png_read_status_ptr_NULL NULL
  160148. #define png_rw_ptr_NULL NULL
  160149. #define png_structp_NULL NULL
  160150. #define png_uint_16p_NULL NULL
  160151. #define png_voidp_NULL NULL
  160152. #define png_write_status_ptr_NULL NULL
  160153. #endif
  160154. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  160155. #ifdef PNG_USE_GLOBAL_ARRAYS
  160156. PNG_EXPORT_VAR (PNG_CONST char) png_libpng_ver[18];
  160157. #else
  160158. #define png_libpng_ver png_get_header_ver(NULL)
  160159. #endif
  160160. #ifdef PNG_USE_GLOBAL_ARRAYS
  160161. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_start[7];
  160162. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_inc[7];
  160163. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_ystart[7];
  160164. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_yinc[7];
  160165. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_mask[7];
  160166. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_dsp_mask[7];
  160167. #endif
  160168. #endif /* PNG_NO_EXTERN */
  160169. typedef struct png_color_struct
  160170. {
  160171. png_byte red;
  160172. png_byte green;
  160173. png_byte blue;
  160174. } png_color;
  160175. typedef png_color FAR * png_colorp;
  160176. typedef png_color FAR * FAR * png_colorpp;
  160177. typedef struct png_color_16_struct
  160178. {
  160179. png_byte index; /* used for palette files */
  160180. png_uint_16 red; /* for use in red green blue files */
  160181. png_uint_16 green;
  160182. png_uint_16 blue;
  160183. png_uint_16 gray; /* for use in grayscale files */
  160184. } png_color_16;
  160185. typedef png_color_16 FAR * png_color_16p;
  160186. typedef png_color_16 FAR * FAR * png_color_16pp;
  160187. typedef struct png_color_8_struct
  160188. {
  160189. png_byte red; /* for use in red green blue files */
  160190. png_byte green;
  160191. png_byte blue;
  160192. png_byte gray; /* for use in grayscale files */
  160193. png_byte alpha; /* for alpha channel files */
  160194. } png_color_8;
  160195. typedef png_color_8 FAR * png_color_8p;
  160196. typedef png_color_8 FAR * FAR * png_color_8pp;
  160197. typedef struct png_sPLT_entry_struct
  160198. {
  160199. png_uint_16 red;
  160200. png_uint_16 green;
  160201. png_uint_16 blue;
  160202. png_uint_16 alpha;
  160203. png_uint_16 frequency;
  160204. } png_sPLT_entry;
  160205. typedef png_sPLT_entry FAR * png_sPLT_entryp;
  160206. typedef png_sPLT_entry FAR * FAR * png_sPLT_entrypp;
  160207. typedef struct png_sPLT_struct
  160208. {
  160209. png_charp name; /* palette name */
  160210. png_byte depth; /* depth of palette samples */
  160211. png_sPLT_entryp entries; /* palette entries */
  160212. png_int_32 nentries; /* number of palette entries */
  160213. } png_sPLT_t;
  160214. typedef png_sPLT_t FAR * png_sPLT_tp;
  160215. typedef png_sPLT_t FAR * FAR * png_sPLT_tpp;
  160216. #ifdef PNG_TEXT_SUPPORTED
  160217. typedef struct png_text_struct
  160218. {
  160219. int compression; /* compression value:
  160220. -1: tEXt, none
  160221. 0: zTXt, deflate
  160222. 1: iTXt, none
  160223. 2: iTXt, deflate */
  160224. png_charp key; /* keyword, 1-79 character description of "text" */
  160225. png_charp text; /* comment, may be an empty string (ie "")
  160226. or a NULL pointer */
  160227. png_size_t text_length; /* length of the text string */
  160228. #ifdef PNG_iTXt_SUPPORTED
  160229. png_size_t itxt_length; /* length of the itxt string */
  160230. png_charp lang; /* language code, 0-79 characters
  160231. or a NULL pointer */
  160232. png_charp lang_key; /* keyword translated UTF-8 string, 0 or more
  160233. chars or a NULL pointer */
  160234. #endif
  160235. } png_text;
  160236. typedef png_text FAR * png_textp;
  160237. typedef png_text FAR * FAR * png_textpp;
  160238. #endif
  160239. #define PNG_TEXT_COMPRESSION_NONE_WR -3
  160240. #define PNG_TEXT_COMPRESSION_zTXt_WR -2
  160241. #define PNG_TEXT_COMPRESSION_NONE -1
  160242. #define PNG_TEXT_COMPRESSION_zTXt 0
  160243. #define PNG_ITXT_COMPRESSION_NONE 1
  160244. #define PNG_ITXT_COMPRESSION_zTXt 2
  160245. #define PNG_TEXT_COMPRESSION_LAST 3 /* Not a valid value */
  160246. typedef struct png_time_struct
  160247. {
  160248. png_uint_16 year; /* full year, as in, 1995 */
  160249. png_byte month; /* month of year, 1 - 12 */
  160250. png_byte day; /* day of month, 1 - 31 */
  160251. png_byte hour; /* hour of day, 0 - 23 */
  160252. png_byte minute; /* minute of hour, 0 - 59 */
  160253. png_byte second; /* second of minute, 0 - 60 (for leap seconds) */
  160254. } png_time;
  160255. typedef png_time FAR * png_timep;
  160256. typedef png_time FAR * FAR * png_timepp;
  160257. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160258. typedef struct png_unknown_chunk_t
  160259. {
  160260. png_byte name[5];
  160261. png_byte *data;
  160262. png_size_t size;
  160263. png_byte location; /* mode of operation at read time */
  160264. }
  160265. png_unknown_chunk;
  160266. typedef png_unknown_chunk FAR * png_unknown_chunkp;
  160267. typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp;
  160268. #endif
  160269. typedef struct png_info_struct
  160270. {
  160271. png_uint_32 width; /* width of image in pixels (from IHDR) */
  160272. png_uint_32 height; /* height of image in pixels (from IHDR) */
  160273. png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
  160274. png_uint_32 rowbytes; /* bytes needed to hold an untransformed row */
  160275. png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
  160276. png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
  160277. png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
  160278. png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
  160279. png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */
  160280. png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
  160281. png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
  160282. png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160283. png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */
  160284. png_byte pixel_depth; /* number of bits per pixel */
  160285. png_byte spare_byte; /* to align the data, and for future use */
  160286. png_byte signature[8]; /* magic bytes read by libpng from start of file */
  160287. #if defined(PNG_gAMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  160288. float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
  160289. #endif
  160290. #if defined(PNG_sRGB_SUPPORTED)
  160291. png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
  160292. #endif
  160293. #if defined(PNG_TEXT_SUPPORTED)
  160294. int num_text; /* number of comments read/to write */
  160295. int max_text; /* current size of text array */
  160296. png_textp text; /* array of comments read/to write */
  160297. #endif /* PNG_TEXT_SUPPORTED */
  160298. #if defined(PNG_tIME_SUPPORTED)
  160299. png_time mod_time;
  160300. #endif
  160301. #if defined(PNG_sBIT_SUPPORTED)
  160302. png_color_8 sig_bit; /* significant bits in color channels */
  160303. #endif
  160304. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \
  160305. defined(PNG_READ_BACKGROUND_SUPPORTED)
  160306. png_bytep trans; /* transparent values for paletted image */
  160307. png_color_16 trans_values; /* transparent color for non-palette image */
  160308. #endif
  160309. #if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160310. png_color_16 background;
  160311. #endif
  160312. #if defined(PNG_oFFs_SUPPORTED)
  160313. png_int_32 x_offset; /* x offset on page */
  160314. png_int_32 y_offset; /* y offset on page */
  160315. png_byte offset_unit_type; /* offset units type */
  160316. #endif
  160317. #if defined(PNG_pHYs_SUPPORTED)
  160318. png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
  160319. png_uint_32 y_pixels_per_unit; /* vertical pixel density */
  160320. png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
  160321. #endif
  160322. #if defined(PNG_hIST_SUPPORTED)
  160323. png_uint_16p hist;
  160324. #endif
  160325. #ifdef PNG_cHRM_SUPPORTED
  160326. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160327. float x_white;
  160328. float y_white;
  160329. float x_red;
  160330. float y_red;
  160331. float x_green;
  160332. float y_green;
  160333. float x_blue;
  160334. float y_blue;
  160335. #endif
  160336. #endif
  160337. #if defined(PNG_pCAL_SUPPORTED)
  160338. png_charp pcal_purpose; /* pCAL chunk description string */
  160339. png_int_32 pcal_X0; /* minimum value */
  160340. png_int_32 pcal_X1; /* maximum value */
  160341. png_charp pcal_units; /* Latin-1 string giving physical units */
  160342. png_charpp pcal_params; /* ASCII strings containing parameter values */
  160343. png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */
  160344. png_byte pcal_nparams; /* number of parameters given in pcal_params */
  160345. #endif
  160346. #ifdef PNG_FREE_ME_SUPPORTED
  160347. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  160348. #endif
  160349. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160350. png_unknown_chunkp unknown_chunks;
  160351. png_size_t unknown_chunks_num;
  160352. #endif
  160353. #if defined(PNG_iCCP_SUPPORTED)
  160354. png_charp iccp_name; /* profile name */
  160355. png_charp iccp_profile; /* International Color Consortium profile data */
  160356. png_uint_32 iccp_proflen; /* ICC profile data length */
  160357. png_byte iccp_compression; /* Always zero */
  160358. #endif
  160359. #if defined(PNG_sPLT_SUPPORTED)
  160360. png_sPLT_tp splt_palettes;
  160361. png_uint_32 splt_palettes_num;
  160362. #endif
  160363. #if defined(PNG_sCAL_SUPPORTED)
  160364. png_byte scal_unit; /* unit of physical scale */
  160365. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160366. double scal_pixel_width; /* width of one pixel */
  160367. double scal_pixel_height; /* height of one pixel */
  160368. #endif
  160369. #ifdef PNG_FIXED_POINT_SUPPORTED
  160370. png_charp scal_s_width; /* string containing height */
  160371. png_charp scal_s_height; /* string containing width */
  160372. #endif
  160373. #endif
  160374. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  160375. png_bytepp row_pointers; /* the image bits */
  160376. #endif
  160377. #if defined(PNG_FIXED_POINT_SUPPORTED) && defined(PNG_gAMA_SUPPORTED)
  160378. png_fixed_point int_gamma; /* gamma of image, if (valid & PNG_INFO_gAMA) */
  160379. #endif
  160380. #if defined(PNG_cHRM_SUPPORTED) && defined(PNG_FIXED_POINT_SUPPORTED)
  160381. png_fixed_point int_x_white;
  160382. png_fixed_point int_y_white;
  160383. png_fixed_point int_x_red;
  160384. png_fixed_point int_y_red;
  160385. png_fixed_point int_x_green;
  160386. png_fixed_point int_y_green;
  160387. png_fixed_point int_x_blue;
  160388. png_fixed_point int_y_blue;
  160389. #endif
  160390. } png_info;
  160391. typedef png_info FAR * png_infop;
  160392. typedef png_info FAR * FAR * png_infopp;
  160393. #define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL)
  160394. #define PNG_UINT_32_MAX ((png_uint_32)(-1))
  160395. #define PNG_SIZE_MAX ((png_size_t)(-1))
  160396. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160397. #define PNG_MAX_UINT PNG_UINT_31_MAX
  160398. #endif
  160399. #define PNG_COLOR_MASK_PALETTE 1
  160400. #define PNG_COLOR_MASK_COLOR 2
  160401. #define PNG_COLOR_MASK_ALPHA 4
  160402. #define PNG_COLOR_TYPE_GRAY 0
  160403. #define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)
  160404. #define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR)
  160405. #define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)
  160406. #define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)
  160407. #define PNG_COLOR_TYPE_RGBA PNG_COLOR_TYPE_RGB_ALPHA
  160408. #define PNG_COLOR_TYPE_GA PNG_COLOR_TYPE_GRAY_ALPHA
  160409. #define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */
  160410. #define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE
  160411. #define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */
  160412. #define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */
  160413. #define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE
  160414. #define PNG_INTERLACE_NONE 0 /* Non-interlaced image */
  160415. #define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */
  160416. #define PNG_INTERLACE_LAST 2 /* Not a valid value */
  160417. #define PNG_OFFSET_PIXEL 0 /* Offset in pixels */
  160418. #define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */
  160419. #define PNG_OFFSET_LAST 2 /* Not a valid value */
  160420. #define PNG_EQUATION_LINEAR 0 /* Linear transformation */
  160421. #define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */
  160422. #define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */
  160423. #define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */
  160424. #define PNG_EQUATION_LAST 4 /* Not a valid value */
  160425. #define PNG_SCALE_UNKNOWN 0 /* unknown unit (image scale) */
  160426. #define PNG_SCALE_METER 1 /* meters per pixel */
  160427. #define PNG_SCALE_RADIAN 2 /* radians per pixel */
  160428. #define PNG_SCALE_LAST 3 /* Not a valid value */
  160429. #define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */
  160430. #define PNG_RESOLUTION_METER 1 /* pixels/meter */
  160431. #define PNG_RESOLUTION_LAST 2 /* Not a valid value */
  160432. #define PNG_sRGB_INTENT_PERCEPTUAL 0
  160433. #define PNG_sRGB_INTENT_RELATIVE 1
  160434. #define PNG_sRGB_INTENT_SATURATION 2
  160435. #define PNG_sRGB_INTENT_ABSOLUTE 3
  160436. #define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */
  160437. #define PNG_KEYWORD_MAX_LENGTH 79
  160438. #define PNG_MAX_PALETTE_LENGTH 256
  160439. #define PNG_INFO_gAMA 0x0001
  160440. #define PNG_INFO_sBIT 0x0002
  160441. #define PNG_INFO_cHRM 0x0004
  160442. #define PNG_INFO_PLTE 0x0008
  160443. #define PNG_INFO_tRNS 0x0010
  160444. #define PNG_INFO_bKGD 0x0020
  160445. #define PNG_INFO_hIST 0x0040
  160446. #define PNG_INFO_pHYs 0x0080
  160447. #define PNG_INFO_oFFs 0x0100
  160448. #define PNG_INFO_tIME 0x0200
  160449. #define PNG_INFO_pCAL 0x0400
  160450. #define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */
  160451. #define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */
  160452. #define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */
  160453. #define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */
  160454. #define PNG_INFO_IDAT 0x8000L /* ESR, 1.0.6 */
  160455. typedef struct png_row_info_struct
  160456. {
  160457. png_uint_32 width; /* width of row */
  160458. png_uint_32 rowbytes; /* number of bytes in row */
  160459. png_byte color_type; /* color type of row */
  160460. png_byte bit_depth; /* bit depth of row */
  160461. png_byte channels; /* number of channels (1, 2, 3, or 4) */
  160462. png_byte pixel_depth; /* bits per pixel (depth * channels) */
  160463. } png_row_info;
  160464. typedef png_row_info FAR * png_row_infop;
  160465. typedef png_row_info FAR * FAR * png_row_infopp;
  160466. typedef struct png_struct_def png_struct;
  160467. typedef png_struct FAR * png_structp;
  160468. typedef void (PNGAPI *png_error_ptr) PNGARG((png_structp, png_const_charp));
  160469. typedef void (PNGAPI *png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t));
  160470. typedef void (PNGAPI *png_flush_ptr) PNGARG((png_structp));
  160471. typedef void (PNGAPI *png_read_status_ptr) PNGARG((png_structp, png_uint_32,
  160472. int));
  160473. typedef void (PNGAPI *png_write_status_ptr) PNGARG((png_structp, png_uint_32,
  160474. int));
  160475. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160476. typedef void (PNGAPI *png_progressive_info_ptr) PNGARG((png_structp, png_infop));
  160477. typedef void (PNGAPI *png_progressive_end_ptr) PNGARG((png_structp, png_infop));
  160478. typedef void (PNGAPI *png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
  160479. png_uint_32, int));
  160480. #endif
  160481. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160482. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  160483. defined(PNG_LEGACY_SUPPORTED)
  160484. typedef void (PNGAPI *png_user_transform_ptr) PNGARG((png_structp,
  160485. png_row_infop, png_bytep));
  160486. #endif
  160487. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  160488. typedef int (PNGAPI *png_user_chunk_ptr) PNGARG((png_structp, png_unknown_chunkp));
  160489. #endif
  160490. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160491. typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp));
  160492. #endif
  160493. #define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */
  160494. #define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */
  160495. #define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */
  160496. #define PNG_TRANSFORM_PACKING 0x0004 /* read and write */
  160497. #define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */
  160498. #define PNG_TRANSFORM_EXPAND 0x0010 /* read only */
  160499. #define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */
  160500. #define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */
  160501. #define PNG_TRANSFORM_BGR 0x0080 /* read and write */
  160502. #define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */
  160503. #define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */
  160504. #define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */
  160505. #define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* WRITE only */
  160506. #define PNG_FLAG_MNG_EMPTY_PLTE 0x01
  160507. #define PNG_FLAG_MNG_FILTER_64 0x04
  160508. #define PNG_ALL_MNG_FEATURES 0x05
  160509. typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t));
  160510. typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
  160511. struct png_struct_def
  160512. {
  160513. #ifdef PNG_SETJMP_SUPPORTED
  160514. jmp_buf jmpbuf; /* used in png_error */
  160515. #endif
  160516. png_error_ptr error_fn; /* function for printing errors and aborting */
  160517. png_error_ptr warning_fn; /* function for printing warnings */
  160518. png_voidp error_ptr; /* user supplied struct for error functions */
  160519. png_rw_ptr write_data_fn; /* function for writing output data */
  160520. png_rw_ptr read_data_fn; /* function for reading input data */
  160521. png_voidp io_ptr; /* ptr to application struct for I/O functions */
  160522. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  160523. png_user_transform_ptr read_user_transform_fn; /* user read transform */
  160524. #endif
  160525. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160526. png_user_transform_ptr write_user_transform_fn; /* user write transform */
  160527. #endif
  160528. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  160529. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160530. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160531. png_voidp user_transform_ptr; /* user supplied struct for user transform */
  160532. png_byte user_transform_depth; /* bit depth of user transformed pixels */
  160533. png_byte user_transform_channels; /* channels in user transformed pixels */
  160534. #endif
  160535. #endif
  160536. png_uint_32 mode; /* tells us where we are in the PNG file */
  160537. png_uint_32 flags; /* flags indicating various things to libpng */
  160538. png_uint_32 transformations; /* which transformations to perform */
  160539. z_stream zstream; /* pointer to decompression structure (below) */
  160540. png_bytep zbuf; /* buffer for zlib */
  160541. png_size_t zbuf_size; /* size of zbuf */
  160542. int zlib_level; /* holds zlib compression level */
  160543. int zlib_method; /* holds zlib compression method */
  160544. int zlib_window_bits; /* holds zlib compression window bits */
  160545. int zlib_mem_level; /* holds zlib compression memory level */
  160546. int zlib_strategy; /* holds zlib compression strategy */
  160547. png_uint_32 width; /* width of image in pixels */
  160548. png_uint_32 height; /* height of image in pixels */
  160549. png_uint_32 num_rows; /* number of rows in current pass */
  160550. png_uint_32 usr_width; /* width of row at start of write */
  160551. png_uint_32 rowbytes; /* size of row in bytes */
  160552. png_uint_32 irowbytes; /* size of current interlaced row in bytes */
  160553. png_uint_32 iwidth; /* width of current interlaced row in pixels */
  160554. png_uint_32 row_number; /* current row in interlace pass */
  160555. png_bytep prev_row; /* buffer to save previous (unfiltered) row */
  160556. png_bytep row_buf; /* buffer to save current (unfiltered) row */
  160557. png_bytep sub_row; /* buffer to save "sub" row when filtering */
  160558. png_bytep up_row; /* buffer to save "up" row when filtering */
  160559. png_bytep avg_row; /* buffer to save "avg" row when filtering */
  160560. png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
  160561. png_row_info row_info; /* used for transformation routines */
  160562. png_uint_32 idat_size; /* current IDAT size for read */
  160563. png_uint_32 crc; /* current chunk CRC value */
  160564. png_colorp palette; /* palette from the input file */
  160565. png_uint_16 num_palette; /* number of color entries in palette */
  160566. png_uint_16 num_trans; /* number of transparency values */
  160567. png_byte chunk_name[5]; /* null-terminated name of current chunk */
  160568. png_byte compression; /* file compression type (always 0) */
  160569. png_byte filter; /* file filter type (always 0) */
  160570. png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160571. png_byte pass; /* current interlace pass (0 - 6) */
  160572. png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
  160573. png_byte color_type; /* color type of file */
  160574. png_byte bit_depth; /* bit depth of file */
  160575. png_byte usr_bit_depth; /* bit depth of users row */
  160576. png_byte pixel_depth; /* number of bits per pixel */
  160577. png_byte channels; /* number of channels in file */
  160578. png_byte usr_channels; /* channels at start of write */
  160579. png_byte sig_bytes; /* magic bytes read/written from start of file */
  160580. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  160581. #ifdef PNG_LEGACY_SUPPORTED
  160582. png_byte filler; /* filler byte for pixel expansion */
  160583. #else
  160584. png_uint_16 filler; /* filler bytes for pixel expansion */
  160585. #endif
  160586. #endif
  160587. #if defined(PNG_bKGD_SUPPORTED)
  160588. png_byte background_gamma_type;
  160589. # ifdef PNG_FLOATING_POINT_SUPPORTED
  160590. float background_gamma;
  160591. # endif
  160592. png_color_16 background; /* background color in screen gamma space */
  160593. #if defined(PNG_READ_GAMMA_SUPPORTED)
  160594. png_color_16 background_1; /* background normalized to gamma 1.0 */
  160595. #endif
  160596. #endif /* PNG_bKGD_SUPPORTED */
  160597. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  160598. png_flush_ptr output_flush_fn;/* Function for flushing output */
  160599. png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
  160600. png_uint_32 flush_rows; /* number of rows written since last flush */
  160601. #endif
  160602. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160603. int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
  160604. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160605. float gamma; /* file gamma value */
  160606. float screen_gamma; /* screen gamma value (display_exponent) */
  160607. #endif
  160608. #endif
  160609. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160610. png_bytep gamma_table; /* gamma table for 8-bit depth files */
  160611. png_bytep gamma_from_1; /* converts from 1.0 to screen */
  160612. png_bytep gamma_to_1; /* converts from file to 1.0 */
  160613. png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
  160614. png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
  160615. png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
  160616. #endif
  160617. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
  160618. png_color_8 sig_bit; /* significant bits in each available channel */
  160619. #endif
  160620. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  160621. png_color_8 shift; /* shift for significant bit tranformation */
  160622. #endif
  160623. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
  160624. || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160625. png_bytep trans; /* transparency values for paletted files */
  160626. png_color_16 trans_values; /* transparency values for non-paletted files */
  160627. #endif
  160628. png_read_status_ptr read_row_fn; /* called after each row is decoded */
  160629. png_write_status_ptr write_row_fn; /* called after each row is encoded */
  160630. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160631. png_progressive_info_ptr info_fn; /* called after header data fully read */
  160632. png_progressive_row_ptr row_fn; /* called after each prog. row is decoded */
  160633. png_progressive_end_ptr end_fn; /* called after image is complete */
  160634. png_bytep save_buffer_ptr; /* current location in save_buffer */
  160635. png_bytep save_buffer; /* buffer for previously read data */
  160636. png_bytep current_buffer_ptr; /* current location in current_buffer */
  160637. png_bytep current_buffer; /* buffer for recently used data */
  160638. png_uint_32 push_length; /* size of current input chunk */
  160639. png_uint_32 skip_length; /* bytes to skip in input data */
  160640. png_size_t save_buffer_size; /* amount of data now in save_buffer */
  160641. png_size_t save_buffer_max; /* total size of save_buffer */
  160642. png_size_t buffer_size; /* total amount of available input data */
  160643. png_size_t current_buffer_size; /* amount of data now in current_buffer */
  160644. int process_mode; /* what push library is currently doing */
  160645. int cur_palette; /* current push library palette index */
  160646. # if defined(PNG_TEXT_SUPPORTED)
  160647. png_size_t current_text_size; /* current size of text input data */
  160648. png_size_t current_text_left; /* how much text left to read in input */
  160649. png_charp current_text; /* current text chunk buffer */
  160650. png_charp current_text_ptr; /* current location in current_text */
  160651. # endif /* PNG_TEXT_SUPPORTED */
  160652. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  160653. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  160654. png_bytepp offset_table_ptr;
  160655. png_bytep offset_table;
  160656. png_uint_16 offset_table_number;
  160657. png_uint_16 offset_table_count;
  160658. png_uint_16 offset_table_count_free;
  160659. #endif
  160660. #if defined(PNG_READ_DITHER_SUPPORTED)
  160661. png_bytep palette_lookup; /* lookup table for dithering */
  160662. png_bytep dither_index; /* index translation for palette files */
  160663. #endif
  160664. #if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_hIST_SUPPORTED)
  160665. png_uint_16p hist; /* histogram */
  160666. #endif
  160667. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  160668. png_byte heuristic_method; /* heuristic for row filter selection */
  160669. png_byte num_prev_filters; /* number of weights for previous rows */
  160670. png_bytep prev_filters; /* filter type(s) of previous row(s) */
  160671. png_uint_16p filter_weights; /* weight(s) for previous line(s) */
  160672. png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
  160673. png_uint_16p filter_costs; /* relative filter calculation cost */
  160674. png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
  160675. #endif
  160676. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  160677. png_charp time_buffer; /* String to hold RFC 1123 time text */
  160678. #endif
  160679. #ifdef PNG_FREE_ME_SUPPORTED
  160680. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  160681. #endif
  160682. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  160683. png_voidp user_chunk_ptr;
  160684. png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
  160685. #endif
  160686. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160687. int num_chunk_list;
  160688. png_bytep chunk_list;
  160689. #endif
  160690. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  160691. png_byte rgb_to_gray_status;
  160692. png_uint_16 rgb_to_gray_red_coeff;
  160693. png_uint_16 rgb_to_gray_green_coeff;
  160694. png_uint_16 rgb_to_gray_blue_coeff;
  160695. #endif
  160696. #if defined(PNG_MNG_FEATURES_SUPPORTED) || \
  160697. defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  160698. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  160699. #ifdef PNG_1_0_X
  160700. png_byte mng_features_permitted;
  160701. #else
  160702. png_uint_32 mng_features_permitted;
  160703. #endif /* PNG_1_0_X */
  160704. #endif
  160705. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160706. png_fixed_point int_gamma;
  160707. #endif
  160708. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  160709. png_byte filter_type;
  160710. #endif
  160711. #if defined(PNG_1_0_X)
  160712. png_uint_32 row_buf_size;
  160713. #endif
  160714. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  160715. # if !defined(PNG_1_0_X)
  160716. # if defined(PNG_MMX_CODE_SUPPORTED)
  160717. png_byte mmx_bitdepth_threshold;
  160718. png_uint_32 mmx_rowbytes_threshold;
  160719. # endif
  160720. png_uint_32 asm_flags;
  160721. # endif
  160722. #endif
  160723. #ifdef PNG_USER_MEM_SUPPORTED
  160724. png_voidp mem_ptr; /* user supplied struct for mem functions */
  160725. png_malloc_ptr malloc_fn; /* function for allocating memory */
  160726. png_free_ptr free_fn; /* function for freeing memory */
  160727. #endif
  160728. png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
  160729. #if defined(PNG_READ_DITHER_SUPPORTED)
  160730. png_bytep dither_sort; /* working sort array */
  160731. png_bytep index_to_palette; /* where the original index currently is */
  160732. png_bytep palette_to_index; /* which original index points to this */
  160733. #endif
  160734. png_byte compression_type;
  160735. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  160736. png_uint_32 user_width_max;
  160737. png_uint_32 user_height_max;
  160738. #endif
  160739. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160740. png_unknown_chunk unknown_chunk;
  160741. #endif
  160742. };
  160743. typedef png_structp version_1_2_21;
  160744. typedef png_struct FAR * FAR * png_structpp;
  160745. extern PNG_EXPORT(png_uint_32,png_access_version_number) PNGARG((void));
  160746. extern PNG_EXPORT(void,png_set_sig_bytes) PNGARG((png_structp png_ptr,
  160747. int num_bytes));
  160748. extern PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start,
  160749. png_size_t num_to_check));
  160750. extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num));
  160751. extern PNG_EXPORT(png_structp,png_create_read_struct)
  160752. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160753. png_error_ptr error_fn, png_error_ptr warn_fn));
  160754. extern PNG_EXPORT(png_structp,png_create_write_struct)
  160755. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160756. png_error_ptr error_fn, png_error_ptr warn_fn));
  160757. #ifdef PNG_WRITE_SUPPORTED
  160758. extern PNG_EXPORT(png_uint_32,png_get_compression_buffer_size)
  160759. PNGARG((png_structp png_ptr));
  160760. #endif
  160761. #ifdef PNG_WRITE_SUPPORTED
  160762. extern PNG_EXPORT(void,png_set_compression_buffer_size)
  160763. PNGARG((png_structp png_ptr, png_uint_32 size));
  160764. #endif
  160765. extern PNG_EXPORT(int,png_reset_zstream) PNGARG((png_structp png_ptr));
  160766. #ifdef PNG_USER_MEM_SUPPORTED
  160767. extern PNG_EXPORT(png_structp,png_create_read_struct_2)
  160768. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160769. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  160770. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  160771. extern PNG_EXPORT(png_structp,png_create_write_struct_2)
  160772. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160773. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  160774. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  160775. #endif
  160776. extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr,
  160777. png_bytep chunk_name, png_bytep data, png_size_t length));
  160778. extern PNG_EXPORT(void,png_write_chunk_start) PNGARG((png_structp png_ptr,
  160779. png_bytep chunk_name, png_uint_32 length));
  160780. extern PNG_EXPORT(void,png_write_chunk_data) PNGARG((png_structp png_ptr,
  160781. png_bytep data, png_size_t length));
  160782. extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr));
  160783. extern PNG_EXPORT(png_infop,png_create_info_struct)
  160784. PNGARG((png_structp png_ptr));
  160785. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160786. extern PNG_EXPORT(void,png_info_init) PNGARG((png_infop info_ptr));
  160787. #undef png_info_init
  160788. #define png_info_init(info_ptr) png_info_init_3(&info_ptr,\
  160789. png_sizeof(png_info));
  160790. #endif
  160791. extern PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr,
  160792. png_size_t png_info_struct_size));
  160793. extern PNG_EXPORT(void,png_write_info_before_PLTE) PNGARG((png_structp png_ptr,
  160794. png_infop info_ptr));
  160795. extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr,
  160796. png_infop info_ptr));
  160797. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160798. extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr,
  160799. png_infop info_ptr));
  160800. #endif
  160801. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  160802. extern PNG_EXPORT(png_charp,png_convert_to_rfc1123)
  160803. PNGARG((png_structp png_ptr, png_timep ptime));
  160804. #endif
  160805. #if !defined(_WIN32_WCE)
  160806. #if defined(PNG_WRITE_tIME_SUPPORTED)
  160807. extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime,
  160808. struct tm FAR * ttime));
  160809. extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime,
  160810. time_t ttime));
  160811. #endif /* PNG_WRITE_tIME_SUPPORTED */
  160812. #endif /* _WIN32_WCE */
  160813. #if defined(PNG_READ_EXPAND_SUPPORTED)
  160814. extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr));
  160815. #if !defined(PNG_1_0_X)
  160816. extern PNG_EXPORT(void,png_set_expand_gray_1_2_4_to_8) PNGARG((png_structp
  160817. png_ptr));
  160818. #endif
  160819. extern PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr));
  160820. extern PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr));
  160821. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160822. extern PNG_EXPORT(void,png_set_gray_1_2_4_to_8) PNGARG((png_structp png_ptr));
  160823. #endif
  160824. #endif
  160825. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  160826. extern PNG_EXPORT(void,png_set_bgr) PNGARG((png_structp png_ptr));
  160827. #endif
  160828. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  160829. extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr));
  160830. #endif
  160831. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  160832. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160833. extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr,
  160834. int error_action, double red, double green ));
  160835. #endif
  160836. extern PNG_EXPORT(void,png_set_rgb_to_gray_fixed) PNGARG((png_structp png_ptr,
  160837. int error_action, png_fixed_point red, png_fixed_point green ));
  160838. extern PNG_EXPORT(png_byte,png_get_rgb_to_gray_status) PNGARG((png_structp
  160839. png_ptr));
  160840. #endif
  160841. extern PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth,
  160842. png_colorp palette));
  160843. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  160844. extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr));
  160845. #endif
  160846. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  160847. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  160848. extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr));
  160849. #endif
  160850. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  160851. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  160852. extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr));
  160853. #endif
  160854. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  160855. extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr,
  160856. png_uint_32 filler, int flags));
  160857. #define PNG_FILLER_BEFORE 0
  160858. #define PNG_FILLER_AFTER 1
  160859. #if !defined(PNG_1_0_X)
  160860. extern PNG_EXPORT(void,png_set_add_alpha) PNGARG((png_structp png_ptr,
  160861. png_uint_32 filler, int flags));
  160862. #endif
  160863. #endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */
  160864. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  160865. extern PNG_EXPORT(void,png_set_swap) PNGARG((png_structp png_ptr));
  160866. #endif
  160867. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  160868. extern PNG_EXPORT(void,png_set_packing) PNGARG((png_structp png_ptr));
  160869. #endif
  160870. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  160871. extern PNG_EXPORT(void,png_set_packswap) PNGARG((png_structp png_ptr));
  160872. #endif
  160873. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  160874. extern PNG_EXPORT(void,png_set_shift) PNGARG((png_structp png_ptr,
  160875. png_color_8p true_bits));
  160876. #endif
  160877. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  160878. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  160879. extern PNG_EXPORT(int,png_set_interlace_handling) PNGARG((png_structp png_ptr));
  160880. #endif
  160881. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  160882. extern PNG_EXPORT(void,png_set_invert_mono) PNGARG((png_structp png_ptr));
  160883. #endif
  160884. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  160885. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160886. extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr,
  160887. png_color_16p background_color, int background_gamma_code,
  160888. int need_expand, double background_gamma));
  160889. #endif
  160890. #define PNG_BACKGROUND_GAMMA_UNKNOWN 0
  160891. #define PNG_BACKGROUND_GAMMA_SCREEN 1
  160892. #define PNG_BACKGROUND_GAMMA_FILE 2
  160893. #define PNG_BACKGROUND_GAMMA_UNIQUE 3
  160894. #endif
  160895. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  160896. extern PNG_EXPORT(void,png_set_strip_16) PNGARG((png_structp png_ptr));
  160897. #endif
  160898. #if defined(PNG_READ_DITHER_SUPPORTED)
  160899. extern PNG_EXPORT(void,png_set_dither) PNGARG((png_structp png_ptr,
  160900. png_colorp palette, int num_palette, int maximum_colors,
  160901. png_uint_16p histogram, int full_dither));
  160902. #endif
  160903. #if defined(PNG_READ_GAMMA_SUPPORTED)
  160904. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160905. extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
  160906. double screen_gamma, double default_file_gamma));
  160907. #endif
  160908. #endif
  160909. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160910. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  160911. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  160912. extern PNG_EXPORT(void,png_permit_empty_plte) PNGARG((png_structp png_ptr,
  160913. int empty_plte_permitted));
  160914. #endif
  160915. #endif
  160916. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  160917. extern PNG_EXPORT(void,png_set_flush) PNGARG((png_structp png_ptr, int nrows));
  160918. extern PNG_EXPORT(void,png_write_flush) PNGARG((png_structp png_ptr));
  160919. #endif
  160920. extern PNG_EXPORT(void,png_start_read_image) PNGARG((png_structp png_ptr));
  160921. extern PNG_EXPORT(void,png_read_update_info) PNGARG((png_structp png_ptr,
  160922. png_infop info_ptr));
  160923. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160924. extern PNG_EXPORT(void,png_read_rows) PNGARG((png_structp png_ptr,
  160925. png_bytepp row, png_bytepp display_row, png_uint_32 num_rows));
  160926. #endif
  160927. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160928. extern PNG_EXPORT(void,png_read_row) PNGARG((png_structp png_ptr,
  160929. png_bytep row,
  160930. png_bytep display_row));
  160931. #endif
  160932. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160933. extern PNG_EXPORT(void,png_read_image) PNGARG((png_structp png_ptr,
  160934. png_bytepp image));
  160935. #endif
  160936. extern PNG_EXPORT(void,png_write_row) PNGARG((png_structp png_ptr,
  160937. png_bytep row));
  160938. extern PNG_EXPORT(void,png_write_rows) PNGARG((png_structp png_ptr,
  160939. png_bytepp row, png_uint_32 num_rows));
  160940. extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr,
  160941. png_bytepp image));
  160942. extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr,
  160943. png_infop info_ptr));
  160944. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160945. extern PNG_EXPORT(void,png_read_end) PNGARG((png_structp png_ptr,
  160946. png_infop info_ptr));
  160947. #endif
  160948. extern PNG_EXPORT(void,png_destroy_info_struct) PNGARG((png_structp png_ptr,
  160949. png_infopp info_ptr_ptr));
  160950. extern PNG_EXPORT(void,png_destroy_read_struct) PNGARG((png_structpp
  160951. png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr));
  160952. extern void png_read_destroy PNGARG((png_structp png_ptr, png_infop info_ptr,
  160953. png_infop end_info_ptr));
  160954. extern PNG_EXPORT(void,png_destroy_write_struct)
  160955. PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr));
  160956. extern void png_write_destroy PNGARG((png_structp png_ptr));
  160957. extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr,
  160958. int crit_action, int ancil_action));
  160959. #define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */
  160960. #define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */
  160961. #define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */
  160962. #define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */
  160963. #define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */
  160964. #define PNG_CRC_NO_CHANGE 5 /* use current value use current value */
  160965. extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method,
  160966. int filters));
  160967. #define PNG_NO_FILTERS 0x00
  160968. #define PNG_FILTER_NONE 0x08
  160969. #define PNG_FILTER_SUB 0x10
  160970. #define PNG_FILTER_UP 0x20
  160971. #define PNG_FILTER_AVG 0x40
  160972. #define PNG_FILTER_PAETH 0x80
  160973. #define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \
  160974. PNG_FILTER_AVG | PNG_FILTER_PAETH)
  160975. #define PNG_FILTER_VALUE_NONE 0
  160976. #define PNG_FILTER_VALUE_SUB 1
  160977. #define PNG_FILTER_VALUE_UP 2
  160978. #define PNG_FILTER_VALUE_AVG 3
  160979. #define PNG_FILTER_VALUE_PAETH 4
  160980. #define PNG_FILTER_VALUE_LAST 5
  160981. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* EXPERIMENTAL */
  160982. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160983. extern PNG_EXPORT(void,png_set_filter_heuristics) PNGARG((png_structp png_ptr,
  160984. int heuristic_method, int num_weights, png_doublep filter_weights,
  160985. png_doublep filter_costs));
  160986. #endif
  160987. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  160988. #define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */
  160989. #define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */
  160990. #define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */
  160991. #define PNG_FILTER_HEURISTIC_LAST 3 /* Not a valid value */
  160992. extern PNG_EXPORT(void,png_set_compression_level) PNGARG((png_structp png_ptr,
  160993. int level));
  160994. extern PNG_EXPORT(void,png_set_compression_mem_level)
  160995. PNGARG((png_structp png_ptr, int mem_level));
  160996. extern PNG_EXPORT(void,png_set_compression_strategy)
  160997. PNGARG((png_structp png_ptr, int strategy));
  160998. extern PNG_EXPORT(void,png_set_compression_window_bits)
  160999. PNGARG((png_structp png_ptr, int window_bits));
  161000. extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr,
  161001. int method));
  161002. #if !defined(PNG_NO_STDIO)
  161003. extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, png_FILE_p fp));
  161004. #endif
  161005. extern PNG_EXPORT(void,png_set_error_fn) PNGARG((png_structp png_ptr,
  161006. png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn));
  161007. extern PNG_EXPORT(png_voidp,png_get_error_ptr) PNGARG((png_structp png_ptr));
  161008. extern PNG_EXPORT(void,png_set_write_fn) PNGARG((png_structp png_ptr,
  161009. png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn));
  161010. extern PNG_EXPORT(void,png_set_read_fn) PNGARG((png_structp png_ptr,
  161011. png_voidp io_ptr, png_rw_ptr read_data_fn));
  161012. extern PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((png_structp png_ptr));
  161013. extern PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr,
  161014. png_read_status_ptr read_row_fn));
  161015. extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr,
  161016. png_write_status_ptr write_row_fn));
  161017. #ifdef PNG_USER_MEM_SUPPORTED
  161018. extern PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr,
  161019. png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161020. extern PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_structp png_ptr));
  161021. #endif
  161022. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161023. defined(PNG_LEGACY_SUPPORTED)
  161024. extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp
  161025. png_ptr, png_user_transform_ptr read_user_transform_fn));
  161026. #endif
  161027. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161028. defined(PNG_LEGACY_SUPPORTED)
  161029. extern PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp
  161030. png_ptr, png_user_transform_ptr write_user_transform_fn));
  161031. #endif
  161032. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161033. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161034. defined(PNG_LEGACY_SUPPORTED)
  161035. extern PNG_EXPORT(void,png_set_user_transform_info) PNGARG((png_structp
  161036. png_ptr, png_voidp user_transform_ptr, int user_transform_depth,
  161037. int user_transform_channels));
  161038. extern PNG_EXPORT(png_voidp,png_get_user_transform_ptr)
  161039. PNGARG((png_structp png_ptr));
  161040. #endif
  161041. #ifdef PNG_USER_CHUNKS_SUPPORTED
  161042. extern PNG_EXPORT(void,png_set_read_user_chunk_fn) PNGARG((png_structp png_ptr,
  161043. png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn));
  161044. extern PNG_EXPORT(png_voidp,png_get_user_chunk_ptr) PNGARG((png_structp
  161045. png_ptr));
  161046. #endif
  161047. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161048. extern PNG_EXPORT(void,png_set_progressive_read_fn) PNGARG((png_structp png_ptr,
  161049. png_voidp progressive_ptr,
  161050. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  161051. png_progressive_end_ptr end_fn));
  161052. extern PNG_EXPORT(png_voidp,png_get_progressive_ptr)
  161053. PNGARG((png_structp png_ptr));
  161054. extern PNG_EXPORT(void,png_process_data) PNGARG((png_structp png_ptr,
  161055. png_infop info_ptr, png_bytep buffer, png_size_t buffer_size));
  161056. extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr,
  161057. png_bytep old_row, png_bytep new_row));
  161058. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  161059. extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr,
  161060. png_uint_32 size));
  161061. #if defined(PNG_1_0_X)
  161062. # define png_malloc_warn png_malloc
  161063. #else
  161064. extern PNG_EXPORT(png_voidp,png_malloc_warn) PNGARG((png_structp png_ptr,
  161065. png_uint_32 size));
  161066. #endif
  161067. extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
  161068. #if defined(PNG_1_0_X)
  161069. extern PNG_EXPORT(voidpf,png_zalloc) PNGARG((voidpf png_ptr, uInt items,
  161070. uInt size));
  161071. extern PNG_EXPORT(void,png_zfree) PNGARG((voidpf png_ptr, voidpf ptr));
  161072. #endif
  161073. extern PNG_EXPORT(void,png_free_data) PNGARG((png_structp png_ptr,
  161074. png_infop info_ptr, png_uint_32 free_me, int num));
  161075. #ifdef PNG_FREE_ME_SUPPORTED
  161076. extern PNG_EXPORT(void,png_data_freer) PNGARG((png_structp png_ptr,
  161077. png_infop info_ptr, int freer, png_uint_32 mask));
  161078. #endif
  161079. #define PNG_DESTROY_WILL_FREE_DATA 1
  161080. #define PNG_SET_WILL_FREE_DATA 1
  161081. #define PNG_USER_WILL_FREE_DATA 2
  161082. #define PNG_FREE_HIST 0x0008
  161083. #define PNG_FREE_ICCP 0x0010
  161084. #define PNG_FREE_SPLT 0x0020
  161085. #define PNG_FREE_ROWS 0x0040
  161086. #define PNG_FREE_PCAL 0x0080
  161087. #define PNG_FREE_SCAL 0x0100
  161088. #define PNG_FREE_UNKN 0x0200
  161089. #define PNG_FREE_LIST 0x0400
  161090. #define PNG_FREE_PLTE 0x1000
  161091. #define PNG_FREE_TRNS 0x2000
  161092. #define PNG_FREE_TEXT 0x4000
  161093. #define PNG_FREE_ALL 0x7fff
  161094. #define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */
  161095. #ifdef PNG_USER_MEM_SUPPORTED
  161096. extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr,
  161097. png_uint_32 size));
  161098. extern PNG_EXPORT(void,png_free_default) PNGARG((png_structp png_ptr,
  161099. png_voidp ptr));
  161100. #endif
  161101. extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr,
  161102. png_voidp s1, png_voidp s2, png_uint_32 size));
  161103. extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr,
  161104. png_voidp s1, int value, png_uint_32 size));
  161105. #if defined(USE_FAR_KEYWORD) /* memory model conversion function */
  161106. extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,
  161107. int check));
  161108. #endif /* USE_FAR_KEYWORD */
  161109. #ifndef PNG_NO_ERROR_TEXT
  161110. extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr,
  161111. png_const_charp error_message));
  161112. extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr,
  161113. png_const_charp error_message));
  161114. #else
  161115. extern PNG_EXPORT(void,png_err) PNGARG((png_structp png_ptr));
  161116. #endif
  161117. #ifndef PNG_NO_WARNINGS
  161118. extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr,
  161119. png_const_charp warning_message));
  161120. #ifdef PNG_READ_SUPPORTED
  161121. extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr,
  161122. png_const_charp warning_message));
  161123. #endif /* PNG_READ_SUPPORTED */
  161124. #endif /* PNG_NO_WARNINGS */
  161125. extern PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_structp png_ptr,
  161126. png_infop info_ptr, png_uint_32 flag));
  161127. extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr,
  161128. png_infop info_ptr));
  161129. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161130. extern PNG_EXPORT(png_bytepp,png_get_rows) PNGARG((png_structp png_ptr,
  161131. png_infop info_ptr));
  161132. extern PNG_EXPORT(void,png_set_rows) PNGARG((png_structp png_ptr,
  161133. png_infop info_ptr, png_bytepp row_pointers));
  161134. #endif
  161135. extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr,
  161136. png_infop info_ptr));
  161137. #ifdef PNG_EASY_ACCESS_SUPPORTED
  161138. extern PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_structp
  161139. png_ptr, png_infop info_ptr));
  161140. extern PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_structp
  161141. png_ptr, png_infop info_ptr));
  161142. extern PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_structp
  161143. png_ptr, png_infop info_ptr));
  161144. extern PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_structp
  161145. png_ptr, png_infop info_ptr));
  161146. extern PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_structp
  161147. png_ptr, png_infop info_ptr));
  161148. extern PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_structp
  161149. png_ptr, png_infop info_ptr));
  161150. extern PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_structp
  161151. png_ptr, png_infop info_ptr));
  161152. extern PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_structp
  161153. png_ptr, png_infop info_ptr));
  161154. extern PNG_EXPORT(png_uint_32, png_get_x_pixels_per_meter) PNGARG((png_structp
  161155. png_ptr, png_infop info_ptr));
  161156. extern PNG_EXPORT(png_uint_32, png_get_y_pixels_per_meter) PNGARG((png_structp
  161157. png_ptr, png_infop info_ptr));
  161158. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161159. extern PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_structp
  161160. png_ptr, png_infop info_ptr));
  161161. #endif
  161162. extern PNG_EXPORT(png_int_32, png_get_x_offset_pixels) PNGARG((png_structp
  161163. png_ptr, png_infop info_ptr));
  161164. extern PNG_EXPORT(png_int_32, png_get_y_offset_pixels) PNGARG((png_structp
  161165. png_ptr, png_infop info_ptr));
  161166. extern PNG_EXPORT(png_int_32, png_get_x_offset_microns) PNGARG((png_structp
  161167. png_ptr, png_infop info_ptr));
  161168. extern PNG_EXPORT(png_int_32, png_get_y_offset_microns) PNGARG((png_structp
  161169. png_ptr, png_infop info_ptr));
  161170. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  161171. extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr,
  161172. png_infop info_ptr));
  161173. #if defined(PNG_bKGD_SUPPORTED)
  161174. extern PNG_EXPORT(png_uint_32,png_get_bKGD) PNGARG((png_structp png_ptr,
  161175. png_infop info_ptr, png_color_16p *background));
  161176. #endif
  161177. #if defined(PNG_bKGD_SUPPORTED)
  161178. extern PNG_EXPORT(void,png_set_bKGD) PNGARG((png_structp png_ptr,
  161179. png_infop info_ptr, png_color_16p background));
  161180. #endif
  161181. #if defined(PNG_cHRM_SUPPORTED)
  161182. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161183. extern PNG_EXPORT(png_uint_32,png_get_cHRM) PNGARG((png_structp png_ptr,
  161184. png_infop info_ptr, double *white_x, double *white_y, double *red_x,
  161185. double *red_y, double *green_x, double *green_y, double *blue_x,
  161186. double *blue_y));
  161187. #endif
  161188. #ifdef PNG_FIXED_POINT_SUPPORTED
  161189. extern PNG_EXPORT(png_uint_32,png_get_cHRM_fixed) PNGARG((png_structp png_ptr,
  161190. png_infop info_ptr, png_fixed_point *int_white_x, png_fixed_point
  161191. *int_white_y, png_fixed_point *int_red_x, png_fixed_point *int_red_y,
  161192. png_fixed_point *int_green_x, png_fixed_point *int_green_y, png_fixed_point
  161193. *int_blue_x, png_fixed_point *int_blue_y));
  161194. #endif
  161195. #endif
  161196. #if defined(PNG_cHRM_SUPPORTED)
  161197. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161198. extern PNG_EXPORT(void,png_set_cHRM) PNGARG((png_structp png_ptr,
  161199. png_infop info_ptr, double white_x, double white_y, double red_x,
  161200. double red_y, double green_x, double green_y, double blue_x, double blue_y));
  161201. #endif
  161202. #ifdef PNG_FIXED_POINT_SUPPORTED
  161203. extern PNG_EXPORT(void,png_set_cHRM_fixed) PNGARG((png_structp png_ptr,
  161204. png_infop info_ptr, png_fixed_point int_white_x, png_fixed_point int_white_y,
  161205. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  161206. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  161207. png_fixed_point int_blue_y));
  161208. #endif
  161209. #endif
  161210. #if defined(PNG_gAMA_SUPPORTED)
  161211. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161212. extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr,
  161213. png_infop info_ptr, double *file_gamma));
  161214. #endif
  161215. extern PNG_EXPORT(png_uint_32,png_get_gAMA_fixed) PNGARG((png_structp png_ptr,
  161216. png_infop info_ptr, png_fixed_point *int_file_gamma));
  161217. #endif
  161218. #if defined(PNG_gAMA_SUPPORTED)
  161219. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161220. extern PNG_EXPORT(void,png_set_gAMA) PNGARG((png_structp png_ptr,
  161221. png_infop info_ptr, double file_gamma));
  161222. #endif
  161223. extern PNG_EXPORT(void,png_set_gAMA_fixed) PNGARG((png_structp png_ptr,
  161224. png_infop info_ptr, png_fixed_point int_file_gamma));
  161225. #endif
  161226. #if defined(PNG_hIST_SUPPORTED)
  161227. extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr,
  161228. png_infop info_ptr, png_uint_16p *hist));
  161229. #endif
  161230. #if defined(PNG_hIST_SUPPORTED)
  161231. extern PNG_EXPORT(void,png_set_hIST) PNGARG((png_structp png_ptr,
  161232. png_infop info_ptr, png_uint_16p hist));
  161233. #endif
  161234. extern PNG_EXPORT(png_uint_32,png_get_IHDR) PNGARG((png_structp png_ptr,
  161235. png_infop info_ptr, png_uint_32 *width, png_uint_32 *height,
  161236. int *bit_depth, int *color_type, int *interlace_method,
  161237. int *compression_method, int *filter_method));
  161238. extern PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr,
  161239. png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth,
  161240. int color_type, int interlace_method, int compression_method,
  161241. int filter_method));
  161242. #if defined(PNG_oFFs_SUPPORTED)
  161243. extern PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_structp png_ptr,
  161244. png_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y,
  161245. int *unit_type));
  161246. #endif
  161247. #if defined(PNG_oFFs_SUPPORTED)
  161248. extern PNG_EXPORT(void,png_set_oFFs) PNGARG((png_structp png_ptr,
  161249. png_infop info_ptr, png_int_32 offset_x, png_int_32 offset_y,
  161250. int unit_type));
  161251. #endif
  161252. #if defined(PNG_pCAL_SUPPORTED)
  161253. extern PNG_EXPORT(png_uint_32,png_get_pCAL) PNGARG((png_structp png_ptr,
  161254. png_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1,
  161255. int *type, int *nparams, png_charp *units, png_charpp *params));
  161256. #endif
  161257. #if defined(PNG_pCAL_SUPPORTED)
  161258. extern PNG_EXPORT(void,png_set_pCAL) PNGARG((png_structp png_ptr,
  161259. png_infop info_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1,
  161260. int type, int nparams, png_charp units, png_charpp params));
  161261. #endif
  161262. #if defined(PNG_pHYs_SUPPORTED)
  161263. extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr,
  161264. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  161265. #endif
  161266. #if defined(PNG_pHYs_SUPPORTED)
  161267. extern PNG_EXPORT(void,png_set_pHYs) PNGARG((png_structp png_ptr,
  161268. png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type));
  161269. #endif
  161270. extern PNG_EXPORT(png_uint_32,png_get_PLTE) PNGARG((png_structp png_ptr,
  161271. png_infop info_ptr, png_colorp *palette, int *num_palette));
  161272. extern PNG_EXPORT(void,png_set_PLTE) PNGARG((png_structp png_ptr,
  161273. png_infop info_ptr, png_colorp palette, int num_palette));
  161274. #if defined(PNG_sBIT_SUPPORTED)
  161275. extern PNG_EXPORT(png_uint_32,png_get_sBIT) PNGARG((png_structp png_ptr,
  161276. png_infop info_ptr, png_color_8p *sig_bit));
  161277. #endif
  161278. #if defined(PNG_sBIT_SUPPORTED)
  161279. extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr,
  161280. png_infop info_ptr, png_color_8p sig_bit));
  161281. #endif
  161282. #if defined(PNG_sRGB_SUPPORTED)
  161283. extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr,
  161284. png_infop info_ptr, int *intent));
  161285. #endif
  161286. #if defined(PNG_sRGB_SUPPORTED)
  161287. extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr,
  161288. png_infop info_ptr, int intent));
  161289. extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
  161290. png_infop info_ptr, int intent));
  161291. #endif
  161292. #if defined(PNG_iCCP_SUPPORTED)
  161293. extern PNG_EXPORT(png_uint_32,png_get_iCCP) PNGARG((png_structp png_ptr,
  161294. png_infop info_ptr, png_charpp name, int *compression_type,
  161295. png_charpp profile, png_uint_32 *proflen));
  161296. #endif
  161297. #if defined(PNG_iCCP_SUPPORTED)
  161298. extern PNG_EXPORT(void,png_set_iCCP) PNGARG((png_structp png_ptr,
  161299. png_infop info_ptr, png_charp name, int compression_type,
  161300. png_charp profile, png_uint_32 proflen));
  161301. #endif
  161302. #if defined(PNG_sPLT_SUPPORTED)
  161303. extern PNG_EXPORT(png_uint_32,png_get_sPLT) PNGARG((png_structp png_ptr,
  161304. png_infop info_ptr, png_sPLT_tpp entries));
  161305. #endif
  161306. #if defined(PNG_sPLT_SUPPORTED)
  161307. extern PNG_EXPORT(void,png_set_sPLT) PNGARG((png_structp png_ptr,
  161308. png_infop info_ptr, png_sPLT_tp entries, int nentries));
  161309. #endif
  161310. #if defined(PNG_TEXT_SUPPORTED)
  161311. extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr,
  161312. png_infop info_ptr, png_textp *text_ptr, int *num_text));
  161313. #endif
  161314. #if defined(PNG_TEXT_SUPPORTED)
  161315. extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr,
  161316. png_infop info_ptr, png_textp text_ptr, int num_text));
  161317. #endif
  161318. #if defined(PNG_tIME_SUPPORTED)
  161319. extern PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_structp png_ptr,
  161320. png_infop info_ptr, png_timep *mod_time));
  161321. #endif
  161322. #if defined(PNG_tIME_SUPPORTED)
  161323. extern PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr,
  161324. png_infop info_ptr, png_timep mod_time));
  161325. #endif
  161326. #if defined(PNG_tRNS_SUPPORTED)
  161327. extern PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_structp png_ptr,
  161328. png_infop info_ptr, png_bytep *trans, int *num_trans,
  161329. png_color_16p *trans_values));
  161330. #endif
  161331. #if defined(PNG_tRNS_SUPPORTED)
  161332. extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
  161333. png_infop info_ptr, png_bytep trans, int num_trans,
  161334. png_color_16p trans_values));
  161335. #endif
  161336. #if defined(PNG_tRNS_SUPPORTED)
  161337. #endif
  161338. #if defined(PNG_sCAL_SUPPORTED)
  161339. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161340. extern PNG_EXPORT(png_uint_32,png_get_sCAL) PNGARG((png_structp png_ptr,
  161341. png_infop info_ptr, int *unit, double *width, double *height));
  161342. #else
  161343. #ifdef PNG_FIXED_POINT_SUPPORTED
  161344. extern PNG_EXPORT(png_uint_32,png_get_sCAL_s) PNGARG((png_structp png_ptr,
  161345. png_infop info_ptr, int *unit, png_charpp swidth, png_charpp sheight));
  161346. #endif
  161347. #endif
  161348. #endif /* PNG_sCAL_SUPPORTED */
  161349. #if defined(PNG_sCAL_SUPPORTED)
  161350. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161351. extern PNG_EXPORT(void,png_set_sCAL) PNGARG((png_structp png_ptr,
  161352. png_infop info_ptr, int unit, double width, double height));
  161353. #else
  161354. #ifdef PNG_FIXED_POINT_SUPPORTED
  161355. extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr,
  161356. png_infop info_ptr, int unit, png_charp swidth, png_charp sheight));
  161357. #endif
  161358. #endif
  161359. #endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
  161360. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161361. extern PNG_EXPORT(void, png_set_keep_unknown_chunks) PNGARG((png_structp
  161362. png_ptr, int keep, png_bytep chunk_list, int num_chunks));
  161363. extern PNG_EXPORT(void, png_set_unknown_chunks) PNGARG((png_structp png_ptr,
  161364. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns));
  161365. extern PNG_EXPORT(void, png_set_unknown_chunk_location)
  161366. PNGARG((png_structp png_ptr, png_infop info_ptr, int chunk, int location));
  161367. extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp
  161368. png_ptr, png_infop info_ptr, png_unknown_chunkpp entries));
  161369. #endif
  161370. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  161371. PNG_EXPORT(int,png_handle_as_unknown) PNGARG((png_structp png_ptr, png_bytep
  161372. chunk_name));
  161373. #endif
  161374. extern PNG_EXPORT(void, png_set_invalid) PNGARG((png_structp png_ptr,
  161375. png_infop info_ptr, int mask));
  161376. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161377. extern PNG_EXPORT(void, png_read_png) PNGARG((png_structp png_ptr,
  161378. png_infop info_ptr,
  161379. int transforms,
  161380. png_voidp params));
  161381. extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr,
  161382. png_infop info_ptr,
  161383. int transforms,
  161384. png_voidp params));
  161385. #endif
  161386. #ifdef PNG_DEBUG
  161387. #if (PNG_DEBUG > 0)
  161388. #if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER)
  161389. #include <crtdbg.h>
  161390. #if (PNG_DEBUG > 1)
  161391. #define png_debug(l,m) _RPT0(_CRT_WARN,m)
  161392. #define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m,p1)
  161393. #define png_debug2(l,m,p1,p2) _RPT2(_CRT_WARN,m,p1,p2)
  161394. #endif
  161395. #else /* PNG_DEBUG_FILE || !_MSC_VER */
  161396. #ifndef PNG_DEBUG_FILE
  161397. #define PNG_DEBUG_FILE stderr
  161398. #endif /* PNG_DEBUG_FILE */
  161399. #if (PNG_DEBUG > 1)
  161400. #define png_debug(l,m) \
  161401. { \
  161402. int num_tabs=l; \
  161403. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161404. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \
  161405. }
  161406. #define png_debug1(l,m,p1) \
  161407. { \
  161408. int num_tabs=l; \
  161409. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161410. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \
  161411. }
  161412. #define png_debug2(l,m,p1,p2) \
  161413. { \
  161414. int num_tabs=l; \
  161415. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161416. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \
  161417. }
  161418. #endif /* (PNG_DEBUG > 1) */
  161419. #endif /* _MSC_VER */
  161420. #endif /* (PNG_DEBUG > 0) */
  161421. #endif /* PNG_DEBUG */
  161422. #ifndef png_debug
  161423. #define png_debug(l, m)
  161424. #endif
  161425. #ifndef png_debug1
  161426. #define png_debug1(l, m, p1)
  161427. #endif
  161428. #ifndef png_debug2
  161429. #define png_debug2(l, m, p1, p2)
  161430. #endif
  161431. extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr));
  161432. extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr));
  161433. extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr));
  161434. extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr));
  161435. #ifdef PNG_MNG_FEATURES_SUPPORTED
  161436. extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp
  161437. png_ptr, png_uint_32 mng_features_permitted));
  161438. #endif
  161439. #define PNG_HANDLE_CHUNK_AS_DEFAULT 0
  161440. #define PNG_HANDLE_CHUNK_NEVER 1
  161441. #define PNG_HANDLE_CHUNK_IF_SAFE 2
  161442. #define PNG_HANDLE_CHUNK_ALWAYS 3
  161443. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  161444. #if defined(PNG_MMX_CODE_SUPPORTED)
  161445. #define PNG_ASM_FLAG_MMX_SUPPORT_COMPILED 0x01 /* not user-settable */
  161446. #define PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU 0x02 /* not user-settable */
  161447. #define PNG_ASM_FLAG_MMX_READ_COMBINE_ROW 0x04
  161448. #define PNG_ASM_FLAG_MMX_READ_INTERLACE 0x08
  161449. #define PNG_ASM_FLAG_MMX_READ_FILTER_SUB 0x10
  161450. #define PNG_ASM_FLAG_MMX_READ_FILTER_UP 0x20
  161451. #define PNG_ASM_FLAG_MMX_READ_FILTER_AVG 0x40
  161452. #define PNG_ASM_FLAG_MMX_READ_FILTER_PAETH 0x80
  161453. #define PNG_ASM_FLAGS_INITIALIZED 0x80000000 /* not user-settable */
  161454. #define PNG_MMX_READ_FLAGS ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
  161455. | PNG_ASM_FLAG_MMX_READ_INTERLACE \
  161456. | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
  161457. | PNG_ASM_FLAG_MMX_READ_FILTER_UP \
  161458. | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
  161459. | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH )
  161460. #define PNG_MMX_WRITE_FLAGS ( 0 )
  161461. #define PNG_MMX_FLAGS ( PNG_ASM_FLAG_MMX_SUPPORT_COMPILED \
  161462. | PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU \
  161463. | PNG_MMX_READ_FLAGS \
  161464. | PNG_MMX_WRITE_FLAGS )
  161465. #define PNG_SELECT_READ 1
  161466. #define PNG_SELECT_WRITE 2
  161467. #endif /* PNG_MMX_CODE_SUPPORTED */
  161468. #if !defined(PNG_1_0_X)
  161469. extern PNG_EXPORT(png_uint_32,png_get_mmx_flagmask)
  161470. PNGARG((int flag_select, int *compilerID));
  161471. extern PNG_EXPORT(png_uint_32,png_get_asm_flagmask)
  161472. PNGARG((int flag_select));
  161473. extern PNG_EXPORT(png_uint_32,png_get_asm_flags)
  161474. PNGARG((png_structp png_ptr));
  161475. extern PNG_EXPORT(png_byte,png_get_mmx_bitdepth_threshold)
  161476. PNGARG((png_structp png_ptr));
  161477. extern PNG_EXPORT(png_uint_32,png_get_mmx_rowbytes_threshold)
  161478. PNGARG((png_structp png_ptr));
  161479. extern PNG_EXPORT(void,png_set_asm_flags)
  161480. PNGARG((png_structp png_ptr, png_uint_32 asm_flags));
  161481. extern PNG_EXPORT(void,png_set_mmx_thresholds)
  161482. PNGARG((png_structp png_ptr, png_byte mmx_bitdepth_threshold,
  161483. png_uint_32 mmx_rowbytes_threshold));
  161484. #endif /* PNG_1_0_X */
  161485. #if !defined(PNG_1_0_X)
  161486. extern PNG_EXPORT(int,png_mmx_support) PNGARG((void));
  161487. #endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
  161488. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  161489. extern PNG_EXPORT(void,png_set_strip_error_numbers) PNGARG((png_structp
  161490. png_ptr, png_uint_32 strip_mode));
  161491. #endif
  161492. #endif /* PNG_1_0_X */
  161493. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  161494. extern PNG_EXPORT(void,png_set_user_limits) PNGARG((png_structp
  161495. png_ptr, png_uint_32 user_width_max, png_uint_32 user_height_max));
  161496. extern PNG_EXPORT(png_uint_32,png_get_user_width_max) PNGARG((png_structp
  161497. png_ptr));
  161498. extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
  161499. png_ptr));
  161500. #endif
  161501. #ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
  161502. # define png_composite(composite, fg, alpha, bg) \
  161503. { png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) * (png_uint_16)(alpha) \
  161504. + (png_uint_16)(bg)*(png_uint_16)(255 - \
  161505. (png_uint_16)(alpha)) + (png_uint_16)128); \
  161506. (composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
  161507. # define png_composite_16(composite, fg, alpha, bg) \
  161508. { png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) * (png_uint_32)(alpha) \
  161509. + (png_uint_32)(bg)*(png_uint_32)(65535L - \
  161510. (png_uint_32)(alpha)) + (png_uint_32)32768L); \
  161511. (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
  161512. #else /* standard method using integer division */
  161513. # define png_composite(composite, fg, alpha, bg) \
  161514. (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
  161515. (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
  161516. (png_uint_16)127) / 255)
  161517. # define png_composite_16(composite, fg, alpha, bg) \
  161518. (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
  161519. (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \
  161520. (png_uint_32)32767) / (png_uint_32)65535L)
  161521. #endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */
  161522. #if defined(PNG_READ_BIG_ENDIAN_SUPPORTED)
  161523. # define png_get_uint_32(buf) ( *((png_uint_32p) (buf)))
  161524. # define png_get_uint_16(buf) ( *((png_uint_16p) (buf)))
  161525. # define png_get_int_32(buf) ( *((png_int_32p) (buf)))
  161526. #else
  161527. extern PNG_EXPORT(png_uint_32,png_get_uint_32) PNGARG((png_bytep buf));
  161528. extern PNG_EXPORT(png_uint_16,png_get_uint_16) PNGARG((png_bytep buf));
  161529. extern PNG_EXPORT(png_int_32,png_get_int_32) PNGARG((png_bytep buf));
  161530. #endif /* !PNG_READ_BIG_ENDIAN_SUPPORTED */
  161531. extern PNG_EXPORT(png_uint_32,png_get_uint_31)
  161532. PNGARG((png_structp png_ptr, png_bytep buf));
  161533. extern PNG_EXPORT(void,png_save_uint_32)
  161534. PNGARG((png_bytep buf, png_uint_32 i));
  161535. extern PNG_EXPORT(void,png_save_int_32)
  161536. PNGARG((png_bytep buf, png_int_32 i));
  161537. extern PNG_EXPORT(void,png_save_uint_16)
  161538. PNGARG((png_bytep buf, unsigned int i));
  161539. #define PNG_HAVE_IHDR 0x01
  161540. #define PNG_HAVE_PLTE 0x02
  161541. #define PNG_HAVE_IDAT 0x04
  161542. #define PNG_AFTER_IDAT 0x08 /* Have complete zlib datastream */
  161543. #define PNG_HAVE_IEND 0x10
  161544. #if defined(PNG_INTERNAL)
  161545. #define PNG_HAVE_gAMA 0x20
  161546. #define PNG_HAVE_cHRM 0x40
  161547. #define PNG_HAVE_sRGB 0x80
  161548. #define PNG_HAVE_CHUNK_HEADER 0x100
  161549. #define PNG_WROTE_tIME 0x200
  161550. #define PNG_WROTE_INFO_BEFORE_PLTE 0x400
  161551. #define PNG_BACKGROUND_IS_GRAY 0x800
  161552. #define PNG_HAVE_PNG_SIGNATURE 0x1000
  161553. #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
  161554. #define PNG_BGR 0x0001
  161555. #define PNG_INTERLACE 0x0002
  161556. #define PNG_PACK 0x0004
  161557. #define PNG_SHIFT 0x0008
  161558. #define PNG_SWAP_BYTES 0x0010
  161559. #define PNG_INVERT_MONO 0x0020
  161560. #define PNG_DITHER 0x0040
  161561. #define PNG_BACKGROUND 0x0080
  161562. #define PNG_BACKGROUND_EXPAND 0x0100
  161563. #define PNG_16_TO_8 0x0400
  161564. #define PNG_RGBA 0x0800
  161565. #define PNG_EXPAND 0x1000
  161566. #define PNG_GAMMA 0x2000
  161567. #define PNG_GRAY_TO_RGB 0x4000
  161568. #define PNG_FILLER 0x8000L
  161569. #define PNG_PACKSWAP 0x10000L
  161570. #define PNG_SWAP_ALPHA 0x20000L
  161571. #define PNG_STRIP_ALPHA 0x40000L
  161572. #define PNG_INVERT_ALPHA 0x80000L
  161573. #define PNG_USER_TRANSFORM 0x100000L
  161574. #define PNG_RGB_TO_GRAY_ERR 0x200000L
  161575. #define PNG_RGB_TO_GRAY_WARN 0x400000L
  161576. #define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */
  161577. #define PNG_ADD_ALPHA 0x1000000L /* Added to libpng-1.2.7 */
  161578. #define PNG_EXPAND_tRNS 0x2000000L /* Added to libpng-1.2.9 */
  161579. #define PNG_STRUCT_PNG 0x0001
  161580. #define PNG_STRUCT_INFO 0x0002
  161581. #define PNG_WEIGHT_SHIFT 8
  161582. #define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT))
  161583. #define PNG_COST_SHIFT 3
  161584. #define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT))
  161585. #define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001
  161586. #define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002
  161587. #define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004
  161588. #define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008
  161589. #define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010
  161590. #define PNG_FLAG_ZLIB_FINISHED 0x0020
  161591. #define PNG_FLAG_ROW_INIT 0x0040
  161592. #define PNG_FLAG_FILLER_AFTER 0x0080
  161593. #define PNG_FLAG_CRC_ANCILLARY_USE 0x0100
  161594. #define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200
  161595. #define PNG_FLAG_CRC_CRITICAL_USE 0x0400
  161596. #define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800
  161597. #define PNG_FLAG_FREE_PLTE 0x1000
  161598. #define PNG_FLAG_FREE_TRNS 0x2000
  161599. #define PNG_FLAG_FREE_HIST 0x4000
  161600. #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000L
  161601. #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000L
  161602. #define PNG_FLAG_LIBRARY_MISMATCH 0x20000L
  161603. #define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000L
  161604. #define PNG_FLAG_STRIP_ERROR_TEXT 0x80000L
  161605. #define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000L
  161606. #define PNG_FLAG_ADD_ALPHA 0x200000L /* Added to libpng-1.2.8 */
  161607. #define PNG_FLAG_STRIP_ALPHA 0x400000L /* Added to libpng-1.2.8 */
  161608. #define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
  161609. PNG_FLAG_CRC_ANCILLARY_NOWARN)
  161610. #define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \
  161611. PNG_FLAG_CRC_CRITICAL_IGNORE)
  161612. #define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \
  161613. PNG_FLAG_CRC_CRITICAL_MASK)
  161614. #define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \
  161615. abs((int)((c1).green) - (int)((c2).green)) + \
  161616. abs((int)((c1).blue) - (int)((c2).blue)))
  161617. #define PNG_ROWBYTES(pixel_bits, width) \
  161618. ((pixel_bits) >= 8 ? \
  161619. ((width) * (((png_uint_32)(pixel_bits)) >> 3)) : \
  161620. (( ((width) * ((png_uint_32)(pixel_bits))) + 7) >> 3) )
  161621. #define PNG_OUT_OF_RANGE(value, ideal, delta) \
  161622. ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) )
  161623. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  161624. #ifdef PNG_USE_GLOBAL_ARRAYS
  161625. PNG_EXPORT_VAR (PNG_CONST png_byte FARDATA) png_sig[8];
  161626. #else
  161627. #endif
  161628. #endif /* PNG_NO_EXTERN */
  161629. #define PNG_IHDR png_byte png_IHDR[5] = { 73, 72, 68, 82, '\0'}
  161630. #define PNG_IDAT png_byte png_IDAT[5] = { 73, 68, 65, 84, '\0'}
  161631. #define PNG_IEND png_byte png_IEND[5] = { 73, 69, 78, 68, '\0'}
  161632. #define PNG_PLTE png_byte png_PLTE[5] = { 80, 76, 84, 69, '\0'}
  161633. #define PNG_bKGD png_byte png_bKGD[5] = { 98, 75, 71, 68, '\0'}
  161634. #define PNG_cHRM png_byte png_cHRM[5] = { 99, 72, 82, 77, '\0'}
  161635. #define PNG_gAMA png_byte png_gAMA[5] = {103, 65, 77, 65, '\0'}
  161636. #define PNG_hIST png_byte png_hIST[5] = {104, 73, 83, 84, '\0'}
  161637. #define PNG_iCCP png_byte png_iCCP[5] = {105, 67, 67, 80, '\0'}
  161638. #define PNG_iTXt png_byte png_iTXt[5] = {105, 84, 88, 116, '\0'}
  161639. #define PNG_oFFs png_byte png_oFFs[5] = {111, 70, 70, 115, '\0'}
  161640. #define PNG_pCAL png_byte png_pCAL[5] = {112, 67, 65, 76, '\0'}
  161641. #define PNG_sCAL png_byte png_sCAL[5] = {115, 67, 65, 76, '\0'}
  161642. #define PNG_pHYs png_byte png_pHYs[5] = {112, 72, 89, 115, '\0'}
  161643. #define PNG_sBIT png_byte png_sBIT[5] = {115, 66, 73, 84, '\0'}
  161644. #define PNG_sPLT png_byte png_sPLT[5] = {115, 80, 76, 84, '\0'}
  161645. #define PNG_sRGB png_byte png_sRGB[5] = {115, 82, 71, 66, '\0'}
  161646. #define PNG_tEXt png_byte png_tEXt[5] = {116, 69, 88, 116, '\0'}
  161647. #define PNG_tIME png_byte png_tIME[5] = {116, 73, 77, 69, '\0'}
  161648. #define PNG_tRNS png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'}
  161649. #define PNG_zTXt png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'}
  161650. #ifdef PNG_USE_GLOBAL_ARRAYS
  161651. PNG_EXPORT_VAR (png_byte FARDATA) png_IHDR[5];
  161652. PNG_EXPORT_VAR (png_byte FARDATA) png_IDAT[5];
  161653. PNG_EXPORT_VAR (png_byte FARDATA) png_IEND[5];
  161654. PNG_EXPORT_VAR (png_byte FARDATA) png_PLTE[5];
  161655. PNG_EXPORT_VAR (png_byte FARDATA) png_bKGD[5];
  161656. PNG_EXPORT_VAR (png_byte FARDATA) png_cHRM[5];
  161657. PNG_EXPORT_VAR (png_byte FARDATA) png_gAMA[5];
  161658. PNG_EXPORT_VAR (png_byte FARDATA) png_hIST[5];
  161659. PNG_EXPORT_VAR (png_byte FARDATA) png_iCCP[5];
  161660. PNG_EXPORT_VAR (png_byte FARDATA) png_iTXt[5];
  161661. PNG_EXPORT_VAR (png_byte FARDATA) png_oFFs[5];
  161662. PNG_EXPORT_VAR (png_byte FARDATA) png_pCAL[5];
  161663. PNG_EXPORT_VAR (png_byte FARDATA) png_sCAL[5];
  161664. PNG_EXPORT_VAR (png_byte FARDATA) png_pHYs[5];
  161665. PNG_EXPORT_VAR (png_byte FARDATA) png_sBIT[5];
  161666. PNG_EXPORT_VAR (png_byte FARDATA) png_sPLT[5];
  161667. PNG_EXPORT_VAR (png_byte FARDATA) png_sRGB[5];
  161668. PNG_EXPORT_VAR (png_byte FARDATA) png_tEXt[5];
  161669. PNG_EXPORT_VAR (png_byte FARDATA) png_tIME[5];
  161670. PNG_EXPORT_VAR (png_byte FARDATA) png_tRNS[5];
  161671. PNG_EXPORT_VAR (png_byte FARDATA) png_zTXt[5];
  161672. #endif /* PNG_USE_GLOBAL_ARRAYS */
  161673. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161674. extern PNG_EXPORT(void,png_read_init) PNGARG((png_structp png_ptr));
  161675. #undef png_read_init
  161676. #define png_read_init(png_ptr) png_read_init_3(&png_ptr, \
  161677. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  161678. #endif
  161679. extern PNG_EXPORT(void,png_read_init_3) PNGARG((png_structpp ptr_ptr,
  161680. png_const_charp user_png_ver, png_size_t png_struct_size));
  161681. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161682. extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr,
  161683. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  161684. png_info_size));
  161685. #endif
  161686. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161687. extern PNG_EXPORT(void,png_write_init) PNGARG((png_structp png_ptr));
  161688. #undef png_write_init
  161689. #define png_write_init(png_ptr) png_write_init_3(&png_ptr, \
  161690. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  161691. #endif
  161692. extern PNG_EXPORT(void,png_write_init_3) PNGARG((png_structpp ptr_ptr,
  161693. png_const_charp user_png_ver, png_size_t png_struct_size));
  161694. extern PNG_EXPORT(void,png_write_init_2) PNGARG((png_structp png_ptr,
  161695. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  161696. png_info_size));
  161697. PNG_EXTERN png_voidp png_create_struct PNGARG((int type));
  161698. PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
  161699. PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr
  161700. malloc_fn, png_voidp mem_ptr));
  161701. PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr,
  161702. png_free_ptr free_fn, png_voidp mem_ptr));
  161703. PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
  161704. png_infop info_ptr));
  161705. #ifndef PNG_1_0_X
  161706. PNG_EXTERN voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, uInt size));
  161707. PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
  161708. #ifdef PNG_SIZE_T
  161709. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  161710. #endif
  161711. PNG_EXTERN void PNGAPI png_default_read_data PNGARG((png_structp png_ptr,
  161712. png_bytep data, png_size_t length));
  161713. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161714. PNG_EXTERN void PNGAPI png_push_fill_buffer PNGARG((png_structp png_ptr,
  161715. png_bytep buffer, png_size_t length));
  161716. #endif
  161717. PNG_EXTERN void PNGAPI png_default_write_data PNGARG((png_structp png_ptr,
  161718. png_bytep data, png_size_t length));
  161719. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161720. #if !defined(PNG_NO_STDIO)
  161721. PNG_EXTERN void PNGAPI png_default_flush PNGARG((png_structp png_ptr));
  161722. #endif
  161723. #endif
  161724. #else /* PNG_1_0_X */
  161725. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161726. PNG_EXTERN void png_push_fill_buffer PNGARG((png_structp png_ptr,
  161727. png_bytep buffer, png_size_t length));
  161728. #endif
  161729. #endif /* PNG_1_0_X */
  161730. PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
  161731. PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, png_bytep data,
  161732. png_size_t length));
  161733. PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data,
  161734. png_size_t length));
  161735. PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
  161736. png_size_t length));
  161737. #if defined(PNG_zTXt_SUPPORTED) || defined(PNG_iTXt_SUPPORTED) || \
  161738. defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED)
  161739. PNG_EXTERN png_charp png_decompress_chunk PNGARG((png_structp png_ptr,
  161740. int comp_type, png_charp chunkdata, png_size_t chunklength,
  161741. png_size_t prefix_length, png_size_t *data_length));
  161742. #endif
  161743. PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip));
  161744. PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr));
  161745. PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr,
  161746. png_size_t length));
  161747. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161748. PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
  161749. #endif
  161750. PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr));
  161751. PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
  161752. png_uint_32 height,
  161753. int bit_depth, int color_type, int compression_method, int filter_method,
  161754. int interlace_method));
  161755. PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, png_colorp palette,
  161756. png_uint_32 num_pal));
  161757. PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data,
  161758. png_size_t length));
  161759. PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr));
  161760. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  161761. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161762. PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma));
  161763. #endif
  161764. #ifdef PNG_FIXED_POINT_SUPPORTED
  161765. PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr, png_fixed_point
  161766. file_gamma));
  161767. #endif
  161768. #endif
  161769. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  161770. PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, png_color_8p sbit,
  161771. int color_type));
  161772. #endif
  161773. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  161774. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161775. PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
  161776. double white_x, double white_y,
  161777. double red_x, double red_y, double green_x, double green_y,
  161778. double blue_x, double blue_y));
  161779. #endif
  161780. #ifdef PNG_FIXED_POINT_SUPPORTED
  161781. PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr,
  161782. png_fixed_point int_white_x, png_fixed_point int_white_y,
  161783. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  161784. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  161785. png_fixed_point int_blue_y));
  161786. #endif
  161787. #endif
  161788. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  161789. PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
  161790. int intent));
  161791. #endif
  161792. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  161793. PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr,
  161794. png_charp name, int compression_type,
  161795. png_charp profile, int proflen));
  161796. #endif
  161797. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  161798. PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr,
  161799. png_sPLT_tp palette));
  161800. #endif
  161801. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  161802. PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans,
  161803. png_color_16p values, int number, int color_type));
  161804. #endif
  161805. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  161806. PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
  161807. png_color_16p values, int color_type));
  161808. #endif
  161809. #if defined(PNG_WRITE_hIST_SUPPORTED)
  161810. PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist,
  161811. int num_hist));
  161812. #endif
  161813. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  161814. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  161815. PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
  161816. png_charp key, png_charpp new_key));
  161817. #endif
  161818. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  161819. PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_charp key,
  161820. png_charp text, png_size_t text_len));
  161821. #endif
  161822. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  161823. PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_charp key,
  161824. png_charp text, png_size_t text_len, int compression));
  161825. #endif
  161826. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  161827. PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr,
  161828. int compression, png_charp key, png_charp lang, png_charp lang_key,
  161829. png_charp text));
  161830. #endif
  161831. #if defined(PNG_TEXT_SUPPORTED) /* Added at version 1.0.14 and 1.2.4 */
  161832. PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr,
  161833. png_infop info_ptr, png_textp text_ptr, int num_text));
  161834. #endif
  161835. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  161836. PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr,
  161837. png_int_32 x_offset, png_int_32 y_offset, int unit_type));
  161838. #endif
  161839. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  161840. PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose,
  161841. png_int_32 X0, png_int_32 X1, int type, int nparams,
  161842. png_charp units, png_charpp params));
  161843. #endif
  161844. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  161845. PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr,
  161846. png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit,
  161847. int unit_type));
  161848. #endif
  161849. #if defined(PNG_WRITE_tIME_SUPPORTED)
  161850. PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr,
  161851. png_timep mod_time));
  161852. #endif
  161853. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  161854. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  161855. PNG_EXTERN void png_write_sCAL PNGARG((png_structp png_ptr,
  161856. int unit, double width, double height));
  161857. #else
  161858. #ifdef PNG_FIXED_POINT_SUPPORTED
  161859. PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr,
  161860. int unit, png_charp width, png_charp height));
  161861. #endif
  161862. #endif
  161863. #endif
  161864. PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
  161865. PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
  161866. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161867. PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr));
  161868. #endif
  161869. PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
  161870. int mask));
  161871. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  161872. PNG_EXTERN void png_do_read_interlace PNGARG((png_structp png_ptr));
  161873. #endif
  161874. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  161875. PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info,
  161876. png_bytep row, int pass));
  161877. #endif
  161878. PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr,
  161879. png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter));
  161880. PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr,
  161881. png_row_infop row_info));
  161882. PNG_EXTERN void png_write_filtered_row PNGARG((png_structp png_ptr,
  161883. png_bytep filtered_row));
  161884. PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr));
  161885. PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr));
  161886. PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
  161887. png_infop info_ptr));
  161888. #if defined(PNG_READ_FILLER_SUPPORTED)
  161889. PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
  161890. png_bytep row, png_uint_32 filler, png_uint_32 flags));
  161891. #endif
  161892. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  161893. PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info,
  161894. png_bytep row));
  161895. #endif
  161896. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  161897. PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
  161898. png_bytep row));
  161899. #endif
  161900. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  161901. PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
  161902. png_bytep row));
  161903. #endif
  161904. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  161905. PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
  161906. png_bytep row));
  161907. #endif
  161908. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  161909. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  161910. PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info,
  161911. png_bytep row, png_uint_32 flags));
  161912. #endif
  161913. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  161914. PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, png_bytep row));
  161915. #endif
  161916. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  161917. PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, png_bytep row));
  161918. #endif
  161919. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  161920. PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, png_row_infop
  161921. row_info, png_bytep row));
  161922. #endif
  161923. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  161924. PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info,
  161925. png_bytep row));
  161926. #endif
  161927. #if defined(PNG_READ_PACK_SUPPORTED)
  161928. PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, png_bytep row));
  161929. #endif
  161930. #if defined(PNG_READ_SHIFT_SUPPORTED)
  161931. PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, png_bytep row,
  161932. png_color_8p sig_bits));
  161933. #endif
  161934. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  161935. PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, png_bytep row));
  161936. #endif
  161937. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  161938. PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, png_bytep row));
  161939. #endif
  161940. #if defined(PNG_READ_DITHER_SUPPORTED)
  161941. PNG_EXTERN void png_do_dither PNGARG((png_row_infop row_info,
  161942. png_bytep row, png_bytep palette_lookup, png_bytep dither_lookup));
  161943. # if defined(PNG_CORRECT_PALETTE_SUPPORTED)
  161944. PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr,
  161945. png_colorp palette, int num_palette));
  161946. # endif
  161947. #endif
  161948. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  161949. PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, png_bytep row));
  161950. #endif
  161951. #if defined(PNG_WRITE_PACK_SUPPORTED)
  161952. PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info,
  161953. png_bytep row, png_uint_32 bit_depth));
  161954. #endif
  161955. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  161956. PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, png_bytep row,
  161957. png_color_8p bit_depth));
  161958. #endif
  161959. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  161960. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161961. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  161962. png_color_16p trans_values, png_color_16p background,
  161963. png_color_16p background_1,
  161964. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  161965. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  161966. png_uint_16pp gamma_16_to_1, int gamma_shift));
  161967. #else
  161968. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  161969. png_color_16p trans_values, png_color_16p background));
  161970. #endif
  161971. #endif
  161972. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161973. PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, png_bytep row,
  161974. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  161975. int gamma_shift));
  161976. #endif
  161977. #if defined(PNG_READ_EXPAND_SUPPORTED)
  161978. PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info,
  161979. png_bytep row, png_colorp palette, png_bytep trans, int num_trans));
  161980. PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
  161981. png_bytep row, png_color_16p trans_value));
  161982. #endif
  161983. PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr,
  161984. png_uint_32 length));
  161985. PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr,
  161986. png_uint_32 length));
  161987. PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr,
  161988. png_uint_32 length));
  161989. #if defined(PNG_READ_bKGD_SUPPORTED)
  161990. PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr,
  161991. png_uint_32 length));
  161992. #endif
  161993. #if defined(PNG_READ_cHRM_SUPPORTED)
  161994. PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr,
  161995. png_uint_32 length));
  161996. #endif
  161997. #if defined(PNG_READ_gAMA_SUPPORTED)
  161998. PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr,
  161999. png_uint_32 length));
  162000. #endif
  162001. #if defined(PNG_READ_hIST_SUPPORTED)
  162002. PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr,
  162003. png_uint_32 length));
  162004. #endif
  162005. #if defined(PNG_READ_iCCP_SUPPORTED)
  162006. extern void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr,
  162007. png_uint_32 length));
  162008. #endif /* PNG_READ_iCCP_SUPPORTED */
  162009. #if defined(PNG_READ_iTXt_SUPPORTED)
  162010. PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162011. png_uint_32 length));
  162012. #endif
  162013. #if defined(PNG_READ_oFFs_SUPPORTED)
  162014. PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr,
  162015. png_uint_32 length));
  162016. #endif
  162017. #if defined(PNG_READ_pCAL_SUPPORTED)
  162018. PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  162019. png_uint_32 length));
  162020. #endif
  162021. #if defined(PNG_READ_pHYs_SUPPORTED)
  162022. PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr,
  162023. png_uint_32 length));
  162024. #endif
  162025. #if defined(PNG_READ_sBIT_SUPPORTED)
  162026. PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr,
  162027. png_uint_32 length));
  162028. #endif
  162029. #if defined(PNG_READ_sCAL_SUPPORTED)
  162030. PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  162031. png_uint_32 length));
  162032. #endif
  162033. #if defined(PNG_READ_sPLT_SUPPORTED)
  162034. extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr,
  162035. png_uint_32 length));
  162036. #endif /* PNG_READ_sPLT_SUPPORTED */
  162037. #if defined(PNG_READ_sRGB_SUPPORTED)
  162038. PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
  162039. png_uint_32 length));
  162040. #endif
  162041. #if defined(PNG_READ_tEXt_SUPPORTED)
  162042. PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162043. png_uint_32 length));
  162044. #endif
  162045. #if defined(PNG_READ_tIME_SUPPORTED)
  162046. PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr,
  162047. png_uint_32 length));
  162048. #endif
  162049. #if defined(PNG_READ_tRNS_SUPPORTED)
  162050. PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
  162051. png_uint_32 length));
  162052. #endif
  162053. #if defined(PNG_READ_zTXt_SUPPORTED)
  162054. PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162055. png_uint_32 length));
  162056. #endif
  162057. PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
  162058. png_infop info_ptr, png_uint_32 length));
  162059. PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr,
  162060. png_bytep chunk_name));
  162061. PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr));
  162062. PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr));
  162063. PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr));
  162064. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162065. PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr,
  162066. png_infop info_ptr));
  162067. PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr,
  162068. png_infop info_ptr));
  162069. PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr));
  162070. PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr,
  162071. png_uint_32 length));
  162072. PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr));
  162073. PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr));
  162074. PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr,
  162075. png_bytep buffer, png_size_t buffer_length));
  162076. PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr));
  162077. PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr,
  162078. png_bytep buffer, png_size_t buffer_length));
  162079. PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr));
  162080. PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr,
  162081. png_infop info_ptr, png_uint_32 length));
  162082. PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr,
  162083. png_infop info_ptr));
  162084. PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr,
  162085. png_infop info_ptr));
  162086. PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row));
  162087. PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr,
  162088. png_infop info_ptr));
  162089. PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr,
  162090. png_infop info_ptr));
  162091. PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr));
  162092. #if defined(PNG_READ_tEXt_SUPPORTED)
  162093. PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr,
  162094. png_infop info_ptr, png_uint_32 length));
  162095. PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr,
  162096. png_infop info_ptr));
  162097. #endif
  162098. #if defined(PNG_READ_zTXt_SUPPORTED)
  162099. PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr,
  162100. png_infop info_ptr, png_uint_32 length));
  162101. PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr,
  162102. png_infop info_ptr));
  162103. #endif
  162104. #if defined(PNG_READ_iTXt_SUPPORTED)
  162105. PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr,
  162106. png_infop info_ptr, png_uint_32 length));
  162107. PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr,
  162108. png_infop info_ptr));
  162109. #endif
  162110. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  162111. #ifdef PNG_MNG_FEATURES_SUPPORTED
  162112. PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info,
  162113. png_bytep row));
  162114. PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info,
  162115. png_bytep row));
  162116. #endif
  162117. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  162118. #if defined(PNG_MMX_CODE_SUPPORTED)
  162119. /* PRIVATE */
  162120. PNG_EXTERN void png_init_mmx_flags PNGARG((png_structp png_ptr));
  162121. #endif
  162122. #endif
  162123. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  162124. PNG_EXTERN png_uint_32 png_get_pixels_per_inch PNGARG((png_structp png_ptr,
  162125. png_infop info_ptr));
  162126. PNG_EXTERN png_uint_32 png_get_x_pixels_per_inch PNGARG((png_structp png_ptr,
  162127. png_infop info_ptr));
  162128. PNG_EXTERN png_uint_32 png_get_y_pixels_per_inch PNGARG((png_structp png_ptr,
  162129. png_infop info_ptr));
  162130. PNG_EXTERN float png_get_x_offset_inches PNGARG((png_structp png_ptr,
  162131. png_infop info_ptr));
  162132. PNG_EXTERN float png_get_y_offset_inches PNGARG((png_structp png_ptr,
  162133. png_infop info_ptr));
  162134. #if defined(PNG_pHYs_SUPPORTED)
  162135. PNG_EXTERN png_uint_32 png_get_pHYs_dpi PNGARG((png_structp png_ptr,
  162136. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  162137. #endif /* PNG_pHYs_SUPPORTED */
  162138. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  162139. #endif /* PNG_INTERNAL */
  162140. #ifdef __cplusplus
  162141. }
  162142. #endif
  162143. #endif /* PNG_VERSION_INFO_ONLY */
  162144. #endif /* PNG_H */
  162145. /*** End of inlined file: png.h ***/
  162146. #define PNG_NO_EXTERN
  162147. /*** Start of inlined file: png.c ***/
  162148. #define PNG_INTERNAL
  162149. #define PNG_NO_EXTERN
  162150. typedef version_1_2_21 Your_png_h_is_not_version_1_2_21;
  162151. #ifdef PNG_USE_GLOBAL_ARRAYS
  162152. PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING;
  162153. #ifdef PNG_READ_SUPPORTED
  162154. PNG_CONST png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162155. #endif /* PNG_READ_SUPPORTED */
  162156. PNG_IHDR;
  162157. PNG_IDAT;
  162158. PNG_IEND;
  162159. PNG_PLTE;
  162160. PNG_bKGD;
  162161. PNG_cHRM;
  162162. PNG_gAMA;
  162163. PNG_hIST;
  162164. PNG_iCCP;
  162165. PNG_iTXt;
  162166. PNG_oFFs;
  162167. PNG_pCAL;
  162168. PNG_sCAL;
  162169. PNG_pHYs;
  162170. PNG_sBIT;
  162171. PNG_sPLT;
  162172. PNG_sRGB;
  162173. PNG_tEXt;
  162174. PNG_tIME;
  162175. PNG_tRNS;
  162176. PNG_zTXt;
  162177. #ifdef PNG_READ_SUPPORTED
  162178. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  162179. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  162180. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  162181. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  162182. PNG_CONST int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  162183. PNG_CONST int FARDATA png_pass_dsp_mask[]
  162184. = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  162185. #endif /* PNG_READ_SUPPORTED */
  162186. #endif /* PNG_USE_GLOBAL_ARRAYS */
  162187. #ifdef PNG_READ_SUPPORTED
  162188. void PNGAPI
  162189. png_set_sig_bytes(png_structp png_ptr, int num_bytes)
  162190. {
  162191. if(png_ptr == NULL) return;
  162192. png_debug(1, "in png_set_sig_bytes\n");
  162193. if (num_bytes > 8)
  162194. png_error(png_ptr, "Too many bytes for PNG signature.");
  162195. png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
  162196. }
  162197. int PNGAPI
  162198. png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
  162199. {
  162200. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162201. if (num_to_check > 8)
  162202. num_to_check = 8;
  162203. else if (num_to_check < 1)
  162204. return (-1);
  162205. if (start > 7)
  162206. return (-1);
  162207. if (start + num_to_check > 8)
  162208. num_to_check = 8 - start;
  162209. return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
  162210. }
  162211. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162212. int PNGAPI
  162213. png_check_sig(png_bytep sig, int num)
  162214. {
  162215. return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
  162216. }
  162217. #endif
  162218. #endif /* PNG_READ_SUPPORTED */
  162219. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162220. #ifdef PNG_1_0_X
  162221. voidpf PNGAPI
  162222. #else
  162223. voidpf /* private */
  162224. #endif
  162225. png_zalloc(voidpf png_ptr, uInt items, uInt size)
  162226. {
  162227. png_voidp ptr;
  162228. png_structp p=(png_structp)png_ptr;
  162229. png_uint_32 save_flags=p->flags;
  162230. png_uint_32 num_bytes;
  162231. if(png_ptr == NULL) return (NULL);
  162232. if (items > PNG_UINT_32_MAX/size)
  162233. {
  162234. png_warning (p, "Potential overflow in png_zalloc()");
  162235. return (NULL);
  162236. }
  162237. num_bytes = (png_uint_32)items * size;
  162238. p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  162239. ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
  162240. p->flags=save_flags;
  162241. #if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO)
  162242. if (ptr == NULL)
  162243. return ((voidpf)ptr);
  162244. if (num_bytes > (png_uint_32)0x8000L)
  162245. {
  162246. png_memset(ptr, 0, (png_size_t)0x8000L);
  162247. png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
  162248. (png_size_t)(num_bytes - (png_uint_32)0x8000L));
  162249. }
  162250. else
  162251. {
  162252. png_memset(ptr, 0, (png_size_t)num_bytes);
  162253. }
  162254. #endif
  162255. return ((voidpf)ptr);
  162256. }
  162257. #ifdef PNG_1_0_X
  162258. void PNGAPI
  162259. #else
  162260. void /* private */
  162261. #endif
  162262. png_zfree(voidpf png_ptr, voidpf ptr)
  162263. {
  162264. png_free((png_structp)png_ptr, (png_voidp)ptr);
  162265. }
  162266. void /* PRIVATE */
  162267. png_reset_crc(png_structp png_ptr)
  162268. {
  162269. png_ptr->crc = crc32(0, Z_NULL, 0);
  162270. }
  162271. void /* PRIVATE */
  162272. png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
  162273. {
  162274. int need_crc = 1;
  162275. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  162276. {
  162277. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  162278. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  162279. need_crc = 0;
  162280. }
  162281. else /* critical */
  162282. {
  162283. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  162284. need_crc = 0;
  162285. }
  162286. if (need_crc)
  162287. png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length);
  162288. }
  162289. png_infop PNGAPI
  162290. png_create_info_struct(png_structp png_ptr)
  162291. {
  162292. png_infop info_ptr;
  162293. png_debug(1, "in png_create_info_struct\n");
  162294. if(png_ptr == NULL) return (NULL);
  162295. #ifdef PNG_USER_MEM_SUPPORTED
  162296. info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
  162297. png_ptr->malloc_fn, png_ptr->mem_ptr);
  162298. #else
  162299. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162300. #endif
  162301. if (info_ptr != NULL)
  162302. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162303. return (info_ptr);
  162304. }
  162305. void PNGAPI
  162306. png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
  162307. {
  162308. png_infop info_ptr = NULL;
  162309. if(png_ptr == NULL) return;
  162310. png_debug(1, "in png_destroy_info_struct\n");
  162311. if (info_ptr_ptr != NULL)
  162312. info_ptr = *info_ptr_ptr;
  162313. if (info_ptr != NULL)
  162314. {
  162315. png_info_destroy(png_ptr, info_ptr);
  162316. #ifdef PNG_USER_MEM_SUPPORTED
  162317. png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn,
  162318. png_ptr->mem_ptr);
  162319. #else
  162320. png_destroy_struct((png_voidp)info_ptr);
  162321. #endif
  162322. *info_ptr_ptr = NULL;
  162323. }
  162324. }
  162325. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162326. #undef png_info_init
  162327. void PNGAPI
  162328. png_info_init(png_infop info_ptr)
  162329. {
  162330. png_info_init_3(&info_ptr, 0);
  162331. }
  162332. #endif
  162333. void PNGAPI
  162334. png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
  162335. {
  162336. png_infop info_ptr = *ptr_ptr;
  162337. if(info_ptr == NULL) return;
  162338. png_debug(1, "in png_info_init_3\n");
  162339. if(png_sizeof(png_info) > png_info_struct_size)
  162340. {
  162341. png_destroy_struct(info_ptr);
  162342. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162343. *ptr_ptr = info_ptr;
  162344. }
  162345. png_memset(info_ptr, 0, png_sizeof (png_info));
  162346. }
  162347. #ifdef PNG_FREE_ME_SUPPORTED
  162348. void PNGAPI
  162349. png_data_freer(png_structp png_ptr, png_infop info_ptr,
  162350. int freer, png_uint_32 mask)
  162351. {
  162352. png_debug(1, "in png_data_freer\n");
  162353. if (png_ptr == NULL || info_ptr == NULL)
  162354. return;
  162355. if(freer == PNG_DESTROY_WILL_FREE_DATA)
  162356. info_ptr->free_me |= mask;
  162357. else if(freer == PNG_USER_WILL_FREE_DATA)
  162358. info_ptr->free_me &= ~mask;
  162359. else
  162360. png_warning(png_ptr,
  162361. "Unknown freer parameter in png_data_freer.");
  162362. }
  162363. #endif
  162364. void PNGAPI
  162365. png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
  162366. int num)
  162367. {
  162368. png_debug(1, "in png_free_data\n");
  162369. if (png_ptr == NULL || info_ptr == NULL)
  162370. return;
  162371. #if defined(PNG_TEXT_SUPPORTED)
  162372. #ifdef PNG_FREE_ME_SUPPORTED
  162373. if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
  162374. #else
  162375. if (mask & PNG_FREE_TEXT)
  162376. #endif
  162377. {
  162378. if (num != -1)
  162379. {
  162380. if (info_ptr->text && info_ptr->text[num].key)
  162381. {
  162382. png_free(png_ptr, info_ptr->text[num].key);
  162383. info_ptr->text[num].key = NULL;
  162384. }
  162385. }
  162386. else
  162387. {
  162388. int i;
  162389. for (i = 0; i < info_ptr->num_text; i++)
  162390. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
  162391. png_free(png_ptr, info_ptr->text);
  162392. info_ptr->text = NULL;
  162393. info_ptr->num_text=0;
  162394. }
  162395. }
  162396. #endif
  162397. #if defined(PNG_tRNS_SUPPORTED)
  162398. #ifdef PNG_FREE_ME_SUPPORTED
  162399. if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
  162400. #else
  162401. if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
  162402. #endif
  162403. {
  162404. png_free(png_ptr, info_ptr->trans);
  162405. info_ptr->valid &= ~PNG_INFO_tRNS;
  162406. #ifndef PNG_FREE_ME_SUPPORTED
  162407. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  162408. #endif
  162409. info_ptr->trans = NULL;
  162410. }
  162411. #endif
  162412. #if defined(PNG_sCAL_SUPPORTED)
  162413. #ifdef PNG_FREE_ME_SUPPORTED
  162414. if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
  162415. #else
  162416. if (mask & PNG_FREE_SCAL)
  162417. #endif
  162418. {
  162419. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  162420. png_free(png_ptr, info_ptr->scal_s_width);
  162421. png_free(png_ptr, info_ptr->scal_s_height);
  162422. info_ptr->scal_s_width = NULL;
  162423. info_ptr->scal_s_height = NULL;
  162424. #endif
  162425. info_ptr->valid &= ~PNG_INFO_sCAL;
  162426. }
  162427. #endif
  162428. #if defined(PNG_pCAL_SUPPORTED)
  162429. #ifdef PNG_FREE_ME_SUPPORTED
  162430. if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
  162431. #else
  162432. if (mask & PNG_FREE_PCAL)
  162433. #endif
  162434. {
  162435. png_free(png_ptr, info_ptr->pcal_purpose);
  162436. png_free(png_ptr, info_ptr->pcal_units);
  162437. info_ptr->pcal_purpose = NULL;
  162438. info_ptr->pcal_units = NULL;
  162439. if (info_ptr->pcal_params != NULL)
  162440. {
  162441. int i;
  162442. for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
  162443. {
  162444. png_free(png_ptr, info_ptr->pcal_params[i]);
  162445. info_ptr->pcal_params[i]=NULL;
  162446. }
  162447. png_free(png_ptr, info_ptr->pcal_params);
  162448. info_ptr->pcal_params = NULL;
  162449. }
  162450. info_ptr->valid &= ~PNG_INFO_pCAL;
  162451. }
  162452. #endif
  162453. #if defined(PNG_iCCP_SUPPORTED)
  162454. #ifdef PNG_FREE_ME_SUPPORTED
  162455. if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
  162456. #else
  162457. if (mask & PNG_FREE_ICCP)
  162458. #endif
  162459. {
  162460. png_free(png_ptr, info_ptr->iccp_name);
  162461. png_free(png_ptr, info_ptr->iccp_profile);
  162462. info_ptr->iccp_name = NULL;
  162463. info_ptr->iccp_profile = NULL;
  162464. info_ptr->valid &= ~PNG_INFO_iCCP;
  162465. }
  162466. #endif
  162467. #if defined(PNG_sPLT_SUPPORTED)
  162468. #ifdef PNG_FREE_ME_SUPPORTED
  162469. if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
  162470. #else
  162471. if (mask & PNG_FREE_SPLT)
  162472. #endif
  162473. {
  162474. if (num != -1)
  162475. {
  162476. if(info_ptr->splt_palettes)
  162477. {
  162478. png_free(png_ptr, info_ptr->splt_palettes[num].name);
  162479. png_free(png_ptr, info_ptr->splt_palettes[num].entries);
  162480. info_ptr->splt_palettes[num].name = NULL;
  162481. info_ptr->splt_palettes[num].entries = NULL;
  162482. }
  162483. }
  162484. else
  162485. {
  162486. if(info_ptr->splt_palettes_num)
  162487. {
  162488. int i;
  162489. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  162490. png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
  162491. png_free(png_ptr, info_ptr->splt_palettes);
  162492. info_ptr->splt_palettes = NULL;
  162493. info_ptr->splt_palettes_num = 0;
  162494. }
  162495. info_ptr->valid &= ~PNG_INFO_sPLT;
  162496. }
  162497. }
  162498. #endif
  162499. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162500. if(png_ptr->unknown_chunk.data)
  162501. {
  162502. png_free(png_ptr, png_ptr->unknown_chunk.data);
  162503. png_ptr->unknown_chunk.data = NULL;
  162504. }
  162505. #ifdef PNG_FREE_ME_SUPPORTED
  162506. if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
  162507. #else
  162508. if (mask & PNG_FREE_UNKN)
  162509. #endif
  162510. {
  162511. if (num != -1)
  162512. {
  162513. if(info_ptr->unknown_chunks)
  162514. {
  162515. png_free(png_ptr, info_ptr->unknown_chunks[num].data);
  162516. info_ptr->unknown_chunks[num].data = NULL;
  162517. }
  162518. }
  162519. else
  162520. {
  162521. int i;
  162522. if(info_ptr->unknown_chunks_num)
  162523. {
  162524. for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
  162525. png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
  162526. png_free(png_ptr, info_ptr->unknown_chunks);
  162527. info_ptr->unknown_chunks = NULL;
  162528. info_ptr->unknown_chunks_num = 0;
  162529. }
  162530. }
  162531. }
  162532. #endif
  162533. #if defined(PNG_hIST_SUPPORTED)
  162534. #ifdef PNG_FREE_ME_SUPPORTED
  162535. if ((mask & PNG_FREE_HIST) & info_ptr->free_me)
  162536. #else
  162537. if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
  162538. #endif
  162539. {
  162540. png_free(png_ptr, info_ptr->hist);
  162541. info_ptr->hist = NULL;
  162542. info_ptr->valid &= ~PNG_INFO_hIST;
  162543. #ifndef PNG_FREE_ME_SUPPORTED
  162544. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  162545. #endif
  162546. }
  162547. #endif
  162548. #ifdef PNG_FREE_ME_SUPPORTED
  162549. if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
  162550. #else
  162551. if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
  162552. #endif
  162553. {
  162554. png_zfree(png_ptr, info_ptr->palette);
  162555. info_ptr->palette = NULL;
  162556. info_ptr->valid &= ~PNG_INFO_PLTE;
  162557. #ifndef PNG_FREE_ME_SUPPORTED
  162558. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  162559. #endif
  162560. info_ptr->num_palette = 0;
  162561. }
  162562. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  162563. #ifdef PNG_FREE_ME_SUPPORTED
  162564. if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
  162565. #else
  162566. if (mask & PNG_FREE_ROWS)
  162567. #endif
  162568. {
  162569. if(info_ptr->row_pointers)
  162570. {
  162571. int row;
  162572. for (row = 0; row < (int)info_ptr->height; row++)
  162573. {
  162574. png_free(png_ptr, info_ptr->row_pointers[row]);
  162575. info_ptr->row_pointers[row]=NULL;
  162576. }
  162577. png_free(png_ptr, info_ptr->row_pointers);
  162578. info_ptr->row_pointers=NULL;
  162579. }
  162580. info_ptr->valid &= ~PNG_INFO_IDAT;
  162581. }
  162582. #endif
  162583. #ifdef PNG_FREE_ME_SUPPORTED
  162584. if(num == -1)
  162585. info_ptr->free_me &= ~mask;
  162586. else
  162587. info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
  162588. #endif
  162589. }
  162590. void /* PRIVATE */
  162591. png_info_destroy(png_structp png_ptr, png_infop info_ptr)
  162592. {
  162593. png_debug(1, "in png_info_destroy\n");
  162594. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  162595. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162596. if (png_ptr->num_chunk_list)
  162597. {
  162598. png_free(png_ptr, png_ptr->chunk_list);
  162599. png_ptr->chunk_list=NULL;
  162600. png_ptr->num_chunk_list=0;
  162601. }
  162602. #endif
  162603. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162604. }
  162605. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162606. png_voidp PNGAPI
  162607. png_get_io_ptr(png_structp png_ptr)
  162608. {
  162609. if(png_ptr == NULL) return (NULL);
  162610. return (png_ptr->io_ptr);
  162611. }
  162612. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162613. #if !defined(PNG_NO_STDIO)
  162614. void PNGAPI
  162615. png_init_io(png_structp png_ptr, png_FILE_p fp)
  162616. {
  162617. png_debug(1, "in png_init_io\n");
  162618. if(png_ptr == NULL) return;
  162619. png_ptr->io_ptr = (png_voidp)fp;
  162620. }
  162621. #endif
  162622. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  162623. png_charp PNGAPI
  162624. png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
  162625. {
  162626. static PNG_CONST char short_months[12][4] =
  162627. {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
  162628. "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  162629. if(png_ptr == NULL) return (NULL);
  162630. if (png_ptr->time_buffer == NULL)
  162631. {
  162632. png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
  162633. png_sizeof(char)));
  162634. }
  162635. #if defined(_WIN32_WCE)
  162636. {
  162637. wchar_t time_buf[29];
  162638. wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
  162639. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162640. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162641. ptime->second % 61);
  162642. WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,
  162643. NULL, NULL);
  162644. }
  162645. #else
  162646. #ifdef USE_FAR_KEYWORD
  162647. {
  162648. char near_time_buf[29];
  162649. png_snprintf6(near_time_buf,29,"%d %s %d %02d:%02d:%02d +0000",
  162650. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162651. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162652. ptime->second % 61);
  162653. png_memcpy(png_ptr->time_buffer, near_time_buf,
  162654. 29*png_sizeof(char));
  162655. }
  162656. #else
  162657. png_snprintf6(png_ptr->time_buffer,29,"%d %s %d %02d:%02d:%02d +0000",
  162658. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162659. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162660. ptime->second % 61);
  162661. #endif
  162662. #endif /* _WIN32_WCE */
  162663. return ((png_charp)png_ptr->time_buffer);
  162664. }
  162665. #endif /* PNG_TIME_RFC1123_SUPPORTED */
  162666. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162667. png_charp PNGAPI
  162668. png_get_copyright(png_structp png_ptr)
  162669. {
  162670. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162671. return ((png_charp) "\n libpng version 1.2.21 - October 4, 2007\n\
  162672. Copyright (c) 1998-2007 Glenn Randers-Pehrson\n\
  162673. Copyright (c) 1996-1997 Andreas Dilger\n\
  162674. Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
  162675. }
  162676. png_charp PNGAPI
  162677. png_get_libpng_ver(png_structp png_ptr)
  162678. {
  162679. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162680. return ((png_charp) PNG_LIBPNG_VER_STRING);
  162681. }
  162682. png_charp PNGAPI
  162683. png_get_header_ver(png_structp png_ptr)
  162684. {
  162685. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162686. return ((png_charp) PNG_LIBPNG_VER_STRING);
  162687. }
  162688. png_charp PNGAPI
  162689. png_get_header_version(png_structp png_ptr)
  162690. {
  162691. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162692. return ((png_charp) PNG_HEADER_VERSION_STRING
  162693. #ifndef PNG_READ_SUPPORTED
  162694. " (NO READ SUPPORT)"
  162695. #endif
  162696. "\n");
  162697. }
  162698. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162699. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  162700. int PNGAPI
  162701. png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
  162702. {
  162703. int i;
  162704. png_bytep p;
  162705. if(png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list<=0)
  162706. return 0;
  162707. p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5;
  162708. for (i = png_ptr->num_chunk_list; i; i--, p-=5)
  162709. if (!png_memcmp(chunk_name, p, 4))
  162710. return ((int)*(p+4));
  162711. return 0;
  162712. }
  162713. #endif
  162714. int PNGAPI
  162715. png_reset_zstream(png_structp png_ptr)
  162716. {
  162717. if (png_ptr == NULL) return Z_STREAM_ERROR;
  162718. return (inflateReset(&png_ptr->zstream));
  162719. }
  162720. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162721. png_uint_32 PNGAPI
  162722. png_access_version_number(void)
  162723. {
  162724. return((png_uint_32) PNG_LIBPNG_VER);
  162725. }
  162726. #if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  162727. #if !defined(PNG_1_0_X)
  162728. int PNGAPI
  162729. png_mmx_support(void)
  162730. {
  162731. return -1;
  162732. }
  162733. #endif /* PNG_1_0_X */
  162734. #endif /* PNG_READ_SUPPORTED && PNG_ASSEMBLER_CODE_SUPPORTED */
  162735. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162736. #ifdef PNG_SIZE_T
  162737. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  162738. png_size_t PNGAPI
  162739. png_convert_size(size_t size)
  162740. {
  162741. if (size > (png_size_t)-1)
  162742. PNG_ABORT(); /* We haven't got access to png_ptr, so no png_error() */
  162743. return ((png_size_t)size);
  162744. }
  162745. #endif /* PNG_SIZE_T */
  162746. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162747. /*** End of inlined file: png.c ***/
  162748. /*** Start of inlined file: pngerror.c ***/
  162749. #define PNG_INTERNAL
  162750. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162751. static void /* PRIVATE */
  162752. png_default_error PNGARG((png_structp png_ptr,
  162753. png_const_charp error_message));
  162754. #ifndef PNG_NO_WARNINGS
  162755. static void /* PRIVATE */
  162756. png_default_warning PNGARG((png_structp png_ptr,
  162757. png_const_charp warning_message));
  162758. #endif /* PNG_NO_WARNINGS */
  162759. #ifndef PNG_NO_ERROR_TEXT
  162760. void PNGAPI
  162761. png_error(png_structp png_ptr, png_const_charp error_message)
  162762. {
  162763. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162764. char msg[16];
  162765. if (png_ptr != NULL)
  162766. {
  162767. if (png_ptr->flags&
  162768. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  162769. {
  162770. if (*error_message == '#')
  162771. {
  162772. int offset;
  162773. for (offset=1; offset<15; offset++)
  162774. if (*(error_message+offset) == ' ')
  162775. break;
  162776. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  162777. {
  162778. int i;
  162779. for (i=0; i<offset-1; i++)
  162780. msg[i]=error_message[i+1];
  162781. msg[i]='\0';
  162782. error_message=msg;
  162783. }
  162784. else
  162785. error_message+=offset;
  162786. }
  162787. else
  162788. {
  162789. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  162790. {
  162791. msg[0]='0';
  162792. msg[1]='\0';
  162793. error_message=msg;
  162794. }
  162795. }
  162796. }
  162797. }
  162798. #endif
  162799. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  162800. (*(png_ptr->error_fn))(png_ptr, error_message);
  162801. png_default_error(png_ptr, error_message);
  162802. }
  162803. #else
  162804. void PNGAPI
  162805. png_err(png_structp png_ptr)
  162806. {
  162807. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  162808. (*(png_ptr->error_fn))(png_ptr, '\0');
  162809. png_default_error(png_ptr, '\0');
  162810. }
  162811. #endif /* PNG_NO_ERROR_TEXT */
  162812. #ifndef PNG_NO_WARNINGS
  162813. void PNGAPI
  162814. png_warning(png_structp png_ptr, png_const_charp warning_message)
  162815. {
  162816. int offset = 0;
  162817. if (png_ptr != NULL)
  162818. {
  162819. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162820. if (png_ptr->flags&
  162821. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  162822. #endif
  162823. {
  162824. if (*warning_message == '#')
  162825. {
  162826. for (offset=1; offset<15; offset++)
  162827. if (*(warning_message+offset) == ' ')
  162828. break;
  162829. }
  162830. }
  162831. if (png_ptr != NULL && png_ptr->warning_fn != NULL)
  162832. (*(png_ptr->warning_fn))(png_ptr, warning_message+offset);
  162833. }
  162834. else
  162835. png_default_warning(png_ptr, warning_message+offset);
  162836. }
  162837. #endif /* PNG_NO_WARNINGS */
  162838. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  162839. #if !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT)
  162840. static void /* PRIVATE */
  162841. png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
  162842. error_message)
  162843. {
  162844. int iout = 0, iin = 0;
  162845. while (iin < 4)
  162846. {
  162847. int c = png_ptr->chunk_name[iin++];
  162848. if (isnonalpha(c))
  162849. {
  162850. buffer[iout++] = '[';
  162851. buffer[iout++] = png_digit[(c & 0xf0) >> 4];
  162852. buffer[iout++] = png_digit[c & 0x0f];
  162853. buffer[iout++] = ']';
  162854. }
  162855. else
  162856. {
  162857. buffer[iout++] = (png_byte)c;
  162858. }
  162859. }
  162860. if (error_message == NULL)
  162861. buffer[iout] = 0;
  162862. else
  162863. {
  162864. buffer[iout++] = ':';
  162865. buffer[iout++] = ' ';
  162866. png_strncpy(buffer+iout, error_message, 63);
  162867. buffer[iout+63] = 0;
  162868. }
  162869. }
  162870. #ifdef PNG_READ_SUPPORTED
  162871. void PNGAPI
  162872. png_chunk_error(png_structp png_ptr, png_const_charp error_message)
  162873. {
  162874. char msg[18+64];
  162875. if (png_ptr == NULL)
  162876. png_error(png_ptr, error_message);
  162877. else
  162878. {
  162879. png_format_buffer(png_ptr, msg, error_message);
  162880. png_error(png_ptr, msg);
  162881. }
  162882. }
  162883. #endif /* PNG_READ_SUPPORTED */
  162884. #endif /* !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT) */
  162885. #ifndef PNG_NO_WARNINGS
  162886. void PNGAPI
  162887. png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
  162888. {
  162889. char msg[18+64];
  162890. if (png_ptr == NULL)
  162891. png_warning(png_ptr, warning_message);
  162892. else
  162893. {
  162894. png_format_buffer(png_ptr, msg, warning_message);
  162895. png_warning(png_ptr, msg);
  162896. }
  162897. }
  162898. #endif /* PNG_NO_WARNINGS */
  162899. static void /* PRIVATE */
  162900. png_default_error(png_structp png_ptr, png_const_charp error_message)
  162901. {
  162902. #ifndef PNG_NO_CONSOLE_IO
  162903. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162904. if (*error_message == '#')
  162905. {
  162906. int offset;
  162907. char error_number[16];
  162908. for (offset=0; offset<15; offset++)
  162909. {
  162910. error_number[offset] = *(error_message+offset+1);
  162911. if (*(error_message+offset) == ' ')
  162912. break;
  162913. }
  162914. if((offset > 1) && (offset < 15))
  162915. {
  162916. error_number[offset-1]='\0';
  162917. fprintf(stderr, "libpng error no. %s: %s\n", error_number,
  162918. error_message+offset);
  162919. }
  162920. else
  162921. fprintf(stderr, "libpng error: %s, offset=%d\n", error_message,offset);
  162922. }
  162923. else
  162924. #endif
  162925. fprintf(stderr, "libpng error: %s\n", error_message);
  162926. #endif
  162927. #ifdef PNG_SETJMP_SUPPORTED
  162928. if (png_ptr)
  162929. {
  162930. # ifdef USE_FAR_KEYWORD
  162931. {
  162932. jmp_buf jmpbuf;
  162933. png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf));
  162934. longjmp(jmpbuf, 1);
  162935. }
  162936. # else
  162937. longjmp(png_ptr->jmpbuf, 1);
  162938. # endif
  162939. }
  162940. #else
  162941. PNG_ABORT();
  162942. #endif
  162943. #ifdef PNG_NO_CONSOLE_IO
  162944. error_message = error_message; /* make compiler happy */
  162945. #endif
  162946. }
  162947. #ifndef PNG_NO_WARNINGS
  162948. static void /* PRIVATE */
  162949. png_default_warning(png_structp png_ptr, png_const_charp warning_message)
  162950. {
  162951. #ifndef PNG_NO_CONSOLE_IO
  162952. # ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162953. if (*warning_message == '#')
  162954. {
  162955. int offset;
  162956. char warning_number[16];
  162957. for (offset=0; offset<15; offset++)
  162958. {
  162959. warning_number[offset]=*(warning_message+offset+1);
  162960. if (*(warning_message+offset) == ' ')
  162961. break;
  162962. }
  162963. if((offset > 1) && (offset < 15))
  162964. {
  162965. warning_number[offset-1]='\0';
  162966. fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
  162967. warning_message+offset);
  162968. }
  162969. else
  162970. fprintf(stderr, "libpng warning: %s\n", warning_message);
  162971. }
  162972. else
  162973. # endif
  162974. fprintf(stderr, "libpng warning: %s\n", warning_message);
  162975. #else
  162976. warning_message = warning_message; /* make compiler happy */
  162977. #endif
  162978. png_ptr = png_ptr; /* make compiler happy */
  162979. }
  162980. #endif /* PNG_NO_WARNINGS */
  162981. void PNGAPI
  162982. png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
  162983. png_error_ptr error_fn, png_error_ptr warning_fn)
  162984. {
  162985. if (png_ptr == NULL)
  162986. return;
  162987. png_ptr->error_ptr = error_ptr;
  162988. png_ptr->error_fn = error_fn;
  162989. png_ptr->warning_fn = warning_fn;
  162990. }
  162991. png_voidp PNGAPI
  162992. png_get_error_ptr(png_structp png_ptr)
  162993. {
  162994. if (png_ptr == NULL)
  162995. return NULL;
  162996. return ((png_voidp)png_ptr->error_ptr);
  162997. }
  162998. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162999. void PNGAPI
  163000. png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
  163001. {
  163002. if(png_ptr != NULL)
  163003. {
  163004. png_ptr->flags &=
  163005. ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
  163006. }
  163007. }
  163008. #endif
  163009. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  163010. /*** End of inlined file: pngerror.c ***/
  163011. /*** Start of inlined file: pngget.c ***/
  163012. #define PNG_INTERNAL
  163013. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163014. png_uint_32 PNGAPI
  163015. png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
  163016. {
  163017. if (png_ptr != NULL && info_ptr != NULL)
  163018. return(info_ptr->valid & flag);
  163019. else
  163020. return(0);
  163021. }
  163022. png_uint_32 PNGAPI
  163023. png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
  163024. {
  163025. if (png_ptr != NULL && info_ptr != NULL)
  163026. return(info_ptr->rowbytes);
  163027. else
  163028. return(0);
  163029. }
  163030. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  163031. png_bytepp PNGAPI
  163032. png_get_rows(png_structp png_ptr, png_infop info_ptr)
  163033. {
  163034. if (png_ptr != NULL && info_ptr != NULL)
  163035. return(info_ptr->row_pointers);
  163036. else
  163037. return(0);
  163038. }
  163039. #endif
  163040. #ifdef PNG_EASY_ACCESS_SUPPORTED
  163041. png_uint_32 PNGAPI
  163042. png_get_image_width(png_structp png_ptr, png_infop info_ptr)
  163043. {
  163044. if (png_ptr != NULL && info_ptr != NULL)
  163045. {
  163046. return info_ptr->width;
  163047. }
  163048. return (0);
  163049. }
  163050. png_uint_32 PNGAPI
  163051. png_get_image_height(png_structp png_ptr, png_infop info_ptr)
  163052. {
  163053. if (png_ptr != NULL && info_ptr != NULL)
  163054. {
  163055. return info_ptr->height;
  163056. }
  163057. return (0);
  163058. }
  163059. png_byte PNGAPI
  163060. png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
  163061. {
  163062. if (png_ptr != NULL && info_ptr != NULL)
  163063. {
  163064. return info_ptr->bit_depth;
  163065. }
  163066. return (0);
  163067. }
  163068. png_byte PNGAPI
  163069. png_get_color_type(png_structp png_ptr, png_infop info_ptr)
  163070. {
  163071. if (png_ptr != NULL && info_ptr != NULL)
  163072. {
  163073. return info_ptr->color_type;
  163074. }
  163075. return (0);
  163076. }
  163077. png_byte PNGAPI
  163078. png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
  163079. {
  163080. if (png_ptr != NULL && info_ptr != NULL)
  163081. {
  163082. return info_ptr->filter_type;
  163083. }
  163084. return (0);
  163085. }
  163086. png_byte PNGAPI
  163087. png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
  163088. {
  163089. if (png_ptr != NULL && info_ptr != NULL)
  163090. {
  163091. return info_ptr->interlace_type;
  163092. }
  163093. return (0);
  163094. }
  163095. png_byte PNGAPI
  163096. png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
  163097. {
  163098. if (png_ptr != NULL && info_ptr != NULL)
  163099. {
  163100. return info_ptr->compression_type;
  163101. }
  163102. return (0);
  163103. }
  163104. png_uint_32 PNGAPI
  163105. png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163106. {
  163107. if (png_ptr != NULL && info_ptr != NULL)
  163108. #if defined(PNG_pHYs_SUPPORTED)
  163109. if (info_ptr->valid & PNG_INFO_pHYs)
  163110. {
  163111. png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
  163112. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163113. return (0);
  163114. else return (info_ptr->x_pixels_per_unit);
  163115. }
  163116. #else
  163117. return (0);
  163118. #endif
  163119. return (0);
  163120. }
  163121. png_uint_32 PNGAPI
  163122. png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163123. {
  163124. if (png_ptr != NULL && info_ptr != NULL)
  163125. #if defined(PNG_pHYs_SUPPORTED)
  163126. if (info_ptr->valid & PNG_INFO_pHYs)
  163127. {
  163128. png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
  163129. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163130. return (0);
  163131. else return (info_ptr->y_pixels_per_unit);
  163132. }
  163133. #else
  163134. return (0);
  163135. #endif
  163136. return (0);
  163137. }
  163138. png_uint_32 PNGAPI
  163139. png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163140. {
  163141. if (png_ptr != NULL && info_ptr != NULL)
  163142. #if defined(PNG_pHYs_SUPPORTED)
  163143. if (info_ptr->valid & PNG_INFO_pHYs)
  163144. {
  163145. png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
  163146. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
  163147. info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
  163148. return (0);
  163149. else return (info_ptr->x_pixels_per_unit);
  163150. }
  163151. #else
  163152. return (0);
  163153. #endif
  163154. return (0);
  163155. }
  163156. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163157. float PNGAPI
  163158. png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
  163159. {
  163160. if (png_ptr != NULL && info_ptr != NULL)
  163161. #if defined(PNG_pHYs_SUPPORTED)
  163162. if (info_ptr->valid & PNG_INFO_pHYs)
  163163. {
  163164. png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
  163165. if (info_ptr->x_pixels_per_unit == 0)
  163166. return ((float)0.0);
  163167. else
  163168. return ((float)((float)info_ptr->y_pixels_per_unit
  163169. /(float)info_ptr->x_pixels_per_unit));
  163170. }
  163171. #else
  163172. return (0.0);
  163173. #endif
  163174. return ((float)0.0);
  163175. }
  163176. #endif
  163177. png_int_32 PNGAPI
  163178. png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163179. {
  163180. if (png_ptr != NULL && info_ptr != NULL)
  163181. #if defined(PNG_oFFs_SUPPORTED)
  163182. if (info_ptr->valid & PNG_INFO_oFFs)
  163183. {
  163184. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163185. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163186. return (0);
  163187. else return (info_ptr->x_offset);
  163188. }
  163189. #else
  163190. return (0);
  163191. #endif
  163192. return (0);
  163193. }
  163194. png_int_32 PNGAPI
  163195. png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163196. {
  163197. if (png_ptr != NULL && info_ptr != NULL)
  163198. #if defined(PNG_oFFs_SUPPORTED)
  163199. if (info_ptr->valid & PNG_INFO_oFFs)
  163200. {
  163201. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163202. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163203. return (0);
  163204. else return (info_ptr->y_offset);
  163205. }
  163206. #else
  163207. return (0);
  163208. #endif
  163209. return (0);
  163210. }
  163211. png_int_32 PNGAPI
  163212. png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163213. {
  163214. if (png_ptr != NULL && info_ptr != NULL)
  163215. #if defined(PNG_oFFs_SUPPORTED)
  163216. if (info_ptr->valid & PNG_INFO_oFFs)
  163217. {
  163218. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163219. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163220. return (0);
  163221. else return (info_ptr->x_offset);
  163222. }
  163223. #else
  163224. return (0);
  163225. #endif
  163226. return (0);
  163227. }
  163228. png_int_32 PNGAPI
  163229. png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163230. {
  163231. if (png_ptr != NULL && info_ptr != NULL)
  163232. #if defined(PNG_oFFs_SUPPORTED)
  163233. if (info_ptr->valid & PNG_INFO_oFFs)
  163234. {
  163235. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163236. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163237. return (0);
  163238. else return (info_ptr->y_offset);
  163239. }
  163240. #else
  163241. return (0);
  163242. #endif
  163243. return (0);
  163244. }
  163245. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  163246. png_uint_32 PNGAPI
  163247. png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163248. {
  163249. return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
  163250. *.0254 +.5));
  163251. }
  163252. png_uint_32 PNGAPI
  163253. png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163254. {
  163255. return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
  163256. *.0254 +.5));
  163257. }
  163258. png_uint_32 PNGAPI
  163259. png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163260. {
  163261. return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
  163262. *.0254 +.5));
  163263. }
  163264. float PNGAPI
  163265. png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163266. {
  163267. return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
  163268. *.00003937);
  163269. }
  163270. float PNGAPI
  163271. png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163272. {
  163273. return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
  163274. *.00003937);
  163275. }
  163276. #if defined(PNG_pHYs_SUPPORTED)
  163277. png_uint_32 PNGAPI
  163278. png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
  163279. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  163280. {
  163281. png_uint_32 retval = 0;
  163282. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  163283. {
  163284. png_debug1(1, "in %s retrieval function\n", "pHYs");
  163285. if (res_x != NULL)
  163286. {
  163287. *res_x = info_ptr->x_pixels_per_unit;
  163288. retval |= PNG_INFO_pHYs;
  163289. }
  163290. if (res_y != NULL)
  163291. {
  163292. *res_y = info_ptr->y_pixels_per_unit;
  163293. retval |= PNG_INFO_pHYs;
  163294. }
  163295. if (unit_type != NULL)
  163296. {
  163297. *unit_type = (int)info_ptr->phys_unit_type;
  163298. retval |= PNG_INFO_pHYs;
  163299. if(*unit_type == 1)
  163300. {
  163301. if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
  163302. if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
  163303. }
  163304. }
  163305. }
  163306. return (retval);
  163307. }
  163308. #endif /* PNG_pHYs_SUPPORTED */
  163309. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  163310. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  163311. png_byte PNGAPI
  163312. png_get_channels(png_structp png_ptr, png_infop info_ptr)
  163313. {
  163314. if (png_ptr != NULL && info_ptr != NULL)
  163315. return(info_ptr->channels);
  163316. else
  163317. return (0);
  163318. }
  163319. png_bytep PNGAPI
  163320. png_get_signature(png_structp png_ptr, png_infop info_ptr)
  163321. {
  163322. if (png_ptr != NULL && info_ptr != NULL)
  163323. return(info_ptr->signature);
  163324. else
  163325. return (NULL);
  163326. }
  163327. #if defined(PNG_bKGD_SUPPORTED)
  163328. png_uint_32 PNGAPI
  163329. png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
  163330. png_color_16p *background)
  163331. {
  163332. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
  163333. && background != NULL)
  163334. {
  163335. png_debug1(1, "in %s retrieval function\n", "bKGD");
  163336. *background = &(info_ptr->background);
  163337. return (PNG_INFO_bKGD);
  163338. }
  163339. return (0);
  163340. }
  163341. #endif
  163342. #if defined(PNG_cHRM_SUPPORTED)
  163343. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163344. png_uint_32 PNGAPI
  163345. png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
  163346. double *white_x, double *white_y, double *red_x, double *red_y,
  163347. double *green_x, double *green_y, double *blue_x, double *blue_y)
  163348. {
  163349. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163350. {
  163351. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163352. if (white_x != NULL)
  163353. *white_x = (double)info_ptr->x_white;
  163354. if (white_y != NULL)
  163355. *white_y = (double)info_ptr->y_white;
  163356. if (red_x != NULL)
  163357. *red_x = (double)info_ptr->x_red;
  163358. if (red_y != NULL)
  163359. *red_y = (double)info_ptr->y_red;
  163360. if (green_x != NULL)
  163361. *green_x = (double)info_ptr->x_green;
  163362. if (green_y != NULL)
  163363. *green_y = (double)info_ptr->y_green;
  163364. if (blue_x != NULL)
  163365. *blue_x = (double)info_ptr->x_blue;
  163366. if (blue_y != NULL)
  163367. *blue_y = (double)info_ptr->y_blue;
  163368. return (PNG_INFO_cHRM);
  163369. }
  163370. return (0);
  163371. }
  163372. #endif
  163373. #ifdef PNG_FIXED_POINT_SUPPORTED
  163374. png_uint_32 PNGAPI
  163375. png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  163376. png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
  163377. png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
  163378. png_fixed_point *blue_x, png_fixed_point *blue_y)
  163379. {
  163380. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163381. {
  163382. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163383. if (white_x != NULL)
  163384. *white_x = info_ptr->int_x_white;
  163385. if (white_y != NULL)
  163386. *white_y = info_ptr->int_y_white;
  163387. if (red_x != NULL)
  163388. *red_x = info_ptr->int_x_red;
  163389. if (red_y != NULL)
  163390. *red_y = info_ptr->int_y_red;
  163391. if (green_x != NULL)
  163392. *green_x = info_ptr->int_x_green;
  163393. if (green_y != NULL)
  163394. *green_y = info_ptr->int_y_green;
  163395. if (blue_x != NULL)
  163396. *blue_x = info_ptr->int_x_blue;
  163397. if (blue_y != NULL)
  163398. *blue_y = info_ptr->int_y_blue;
  163399. return (PNG_INFO_cHRM);
  163400. }
  163401. return (0);
  163402. }
  163403. #endif
  163404. #endif
  163405. #if defined(PNG_gAMA_SUPPORTED)
  163406. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163407. png_uint_32 PNGAPI
  163408. png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
  163409. {
  163410. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163411. && file_gamma != NULL)
  163412. {
  163413. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163414. *file_gamma = (double)info_ptr->gamma;
  163415. return (PNG_INFO_gAMA);
  163416. }
  163417. return (0);
  163418. }
  163419. #endif
  163420. #ifdef PNG_FIXED_POINT_SUPPORTED
  163421. png_uint_32 PNGAPI
  163422. png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
  163423. png_fixed_point *int_file_gamma)
  163424. {
  163425. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163426. && int_file_gamma != NULL)
  163427. {
  163428. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163429. *int_file_gamma = info_ptr->int_gamma;
  163430. return (PNG_INFO_gAMA);
  163431. }
  163432. return (0);
  163433. }
  163434. #endif
  163435. #endif
  163436. #if defined(PNG_sRGB_SUPPORTED)
  163437. png_uint_32 PNGAPI
  163438. png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
  163439. {
  163440. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
  163441. && file_srgb_intent != NULL)
  163442. {
  163443. png_debug1(1, "in %s retrieval function\n", "sRGB");
  163444. *file_srgb_intent = (int)info_ptr->srgb_intent;
  163445. return (PNG_INFO_sRGB);
  163446. }
  163447. return (0);
  163448. }
  163449. #endif
  163450. #if defined(PNG_iCCP_SUPPORTED)
  163451. png_uint_32 PNGAPI
  163452. png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
  163453. png_charpp name, int *compression_type,
  163454. png_charpp profile, png_uint_32 *proflen)
  163455. {
  163456. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
  163457. && name != NULL && profile != NULL && proflen != NULL)
  163458. {
  163459. png_debug1(1, "in %s retrieval function\n", "iCCP");
  163460. *name = info_ptr->iccp_name;
  163461. *profile = info_ptr->iccp_profile;
  163462. *proflen = (int)info_ptr->iccp_proflen;
  163463. *compression_type = (int)info_ptr->iccp_compression;
  163464. return (PNG_INFO_iCCP);
  163465. }
  163466. return (0);
  163467. }
  163468. #endif
  163469. #if defined(PNG_sPLT_SUPPORTED)
  163470. png_uint_32 PNGAPI
  163471. png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
  163472. png_sPLT_tpp spalettes)
  163473. {
  163474. if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
  163475. {
  163476. *spalettes = info_ptr->splt_palettes;
  163477. return ((png_uint_32)info_ptr->splt_palettes_num);
  163478. }
  163479. return (0);
  163480. }
  163481. #endif
  163482. #if defined(PNG_hIST_SUPPORTED)
  163483. png_uint_32 PNGAPI
  163484. png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
  163485. {
  163486. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
  163487. && hist != NULL)
  163488. {
  163489. png_debug1(1, "in %s retrieval function\n", "hIST");
  163490. *hist = info_ptr->hist;
  163491. return (PNG_INFO_hIST);
  163492. }
  163493. return (0);
  163494. }
  163495. #endif
  163496. png_uint_32 PNGAPI
  163497. png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
  163498. png_uint_32 *width, png_uint_32 *height, int *bit_depth,
  163499. int *color_type, int *interlace_type, int *compression_type,
  163500. int *filter_type)
  163501. {
  163502. if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
  163503. bit_depth != NULL && color_type != NULL)
  163504. {
  163505. png_debug1(1, "in %s retrieval function\n", "IHDR");
  163506. *width = info_ptr->width;
  163507. *height = info_ptr->height;
  163508. *bit_depth = info_ptr->bit_depth;
  163509. if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
  163510. png_error(png_ptr, "Invalid bit depth");
  163511. *color_type = info_ptr->color_type;
  163512. if (info_ptr->color_type > 6)
  163513. png_error(png_ptr, "Invalid color type");
  163514. if (compression_type != NULL)
  163515. *compression_type = info_ptr->compression_type;
  163516. if (filter_type != NULL)
  163517. *filter_type = info_ptr->filter_type;
  163518. if (interlace_type != NULL)
  163519. *interlace_type = info_ptr->interlace_type;
  163520. if (*width == 0 || *width > PNG_UINT_31_MAX)
  163521. png_error(png_ptr, "Invalid image width");
  163522. if (*height == 0 || *height > PNG_UINT_31_MAX)
  163523. png_error(png_ptr, "Invalid image height");
  163524. if (info_ptr->width > (PNG_UINT_32_MAX
  163525. >> 3) /* 8-byte RGBA pixels */
  163526. - 64 /* bigrowbuf hack */
  163527. - 1 /* filter byte */
  163528. - 7*8 /* rounding of width to multiple of 8 pixels */
  163529. - 8) /* extra max_pixel_depth pad */
  163530. {
  163531. png_warning(png_ptr,
  163532. "Width too large for libpng to process image data.");
  163533. }
  163534. return (1);
  163535. }
  163536. return (0);
  163537. }
  163538. #if defined(PNG_oFFs_SUPPORTED)
  163539. png_uint_32 PNGAPI
  163540. png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
  163541. png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
  163542. {
  163543. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
  163544. && offset_x != NULL && offset_y != NULL && unit_type != NULL)
  163545. {
  163546. png_debug1(1, "in %s retrieval function\n", "oFFs");
  163547. *offset_x = info_ptr->x_offset;
  163548. *offset_y = info_ptr->y_offset;
  163549. *unit_type = (int)info_ptr->offset_unit_type;
  163550. return (PNG_INFO_oFFs);
  163551. }
  163552. return (0);
  163553. }
  163554. #endif
  163555. #if defined(PNG_pCAL_SUPPORTED)
  163556. png_uint_32 PNGAPI
  163557. png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
  163558. png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
  163559. png_charp *units, png_charpp *params)
  163560. {
  163561. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
  163562. && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
  163563. nparams != NULL && units != NULL && params != NULL)
  163564. {
  163565. png_debug1(1, "in %s retrieval function\n", "pCAL");
  163566. *purpose = info_ptr->pcal_purpose;
  163567. *X0 = info_ptr->pcal_X0;
  163568. *X1 = info_ptr->pcal_X1;
  163569. *type = (int)info_ptr->pcal_type;
  163570. *nparams = (int)info_ptr->pcal_nparams;
  163571. *units = info_ptr->pcal_units;
  163572. *params = info_ptr->pcal_params;
  163573. return (PNG_INFO_pCAL);
  163574. }
  163575. return (0);
  163576. }
  163577. #endif
  163578. #if defined(PNG_sCAL_SUPPORTED)
  163579. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163580. png_uint_32 PNGAPI
  163581. png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
  163582. int *unit, double *width, double *height)
  163583. {
  163584. if (png_ptr != NULL && info_ptr != NULL &&
  163585. (info_ptr->valid & PNG_INFO_sCAL))
  163586. {
  163587. *unit = info_ptr->scal_unit;
  163588. *width = info_ptr->scal_pixel_width;
  163589. *height = info_ptr->scal_pixel_height;
  163590. return (PNG_INFO_sCAL);
  163591. }
  163592. return(0);
  163593. }
  163594. #else
  163595. #ifdef PNG_FIXED_POINT_SUPPORTED
  163596. png_uint_32 PNGAPI
  163597. png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  163598. int *unit, png_charpp width, png_charpp height)
  163599. {
  163600. if (png_ptr != NULL && info_ptr != NULL &&
  163601. (info_ptr->valid & PNG_INFO_sCAL))
  163602. {
  163603. *unit = info_ptr->scal_unit;
  163604. *width = info_ptr->scal_s_width;
  163605. *height = info_ptr->scal_s_height;
  163606. return (PNG_INFO_sCAL);
  163607. }
  163608. return(0);
  163609. }
  163610. #endif
  163611. #endif
  163612. #endif
  163613. #if defined(PNG_pHYs_SUPPORTED)
  163614. png_uint_32 PNGAPI
  163615. png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
  163616. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  163617. {
  163618. png_uint_32 retval = 0;
  163619. if (png_ptr != NULL && info_ptr != NULL &&
  163620. (info_ptr->valid & PNG_INFO_pHYs))
  163621. {
  163622. png_debug1(1, "in %s retrieval function\n", "pHYs");
  163623. if (res_x != NULL)
  163624. {
  163625. *res_x = info_ptr->x_pixels_per_unit;
  163626. retval |= PNG_INFO_pHYs;
  163627. }
  163628. if (res_y != NULL)
  163629. {
  163630. *res_y = info_ptr->y_pixels_per_unit;
  163631. retval |= PNG_INFO_pHYs;
  163632. }
  163633. if (unit_type != NULL)
  163634. {
  163635. *unit_type = (int)info_ptr->phys_unit_type;
  163636. retval |= PNG_INFO_pHYs;
  163637. }
  163638. }
  163639. return (retval);
  163640. }
  163641. #endif
  163642. png_uint_32 PNGAPI
  163643. png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
  163644. int *num_palette)
  163645. {
  163646. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
  163647. && palette != NULL)
  163648. {
  163649. png_debug1(1, "in %s retrieval function\n", "PLTE");
  163650. *palette = info_ptr->palette;
  163651. *num_palette = info_ptr->num_palette;
  163652. png_debug1(3, "num_palette = %d\n", *num_palette);
  163653. return (PNG_INFO_PLTE);
  163654. }
  163655. return (0);
  163656. }
  163657. #if defined(PNG_sBIT_SUPPORTED)
  163658. png_uint_32 PNGAPI
  163659. png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
  163660. {
  163661. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
  163662. && sig_bit != NULL)
  163663. {
  163664. png_debug1(1, "in %s retrieval function\n", "sBIT");
  163665. *sig_bit = &(info_ptr->sig_bit);
  163666. return (PNG_INFO_sBIT);
  163667. }
  163668. return (0);
  163669. }
  163670. #endif
  163671. #if defined(PNG_TEXT_SUPPORTED)
  163672. png_uint_32 PNGAPI
  163673. png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
  163674. int *num_text)
  163675. {
  163676. if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
  163677. {
  163678. png_debug1(1, "in %s retrieval function\n",
  163679. (png_ptr->chunk_name[0] == '\0' ? "text"
  163680. : (png_const_charp)png_ptr->chunk_name));
  163681. if (text_ptr != NULL)
  163682. *text_ptr = info_ptr->text;
  163683. if (num_text != NULL)
  163684. *num_text = info_ptr->num_text;
  163685. return ((png_uint_32)info_ptr->num_text);
  163686. }
  163687. if (num_text != NULL)
  163688. *num_text = 0;
  163689. return(0);
  163690. }
  163691. #endif
  163692. #if defined(PNG_tIME_SUPPORTED)
  163693. png_uint_32 PNGAPI
  163694. png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
  163695. {
  163696. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
  163697. && mod_time != NULL)
  163698. {
  163699. png_debug1(1, "in %s retrieval function\n", "tIME");
  163700. *mod_time = &(info_ptr->mod_time);
  163701. return (PNG_INFO_tIME);
  163702. }
  163703. return (0);
  163704. }
  163705. #endif
  163706. #if defined(PNG_tRNS_SUPPORTED)
  163707. png_uint_32 PNGAPI
  163708. png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
  163709. png_bytep *trans, int *num_trans, png_color_16p *trans_values)
  163710. {
  163711. png_uint_32 retval = 0;
  163712. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  163713. {
  163714. png_debug1(1, "in %s retrieval function\n", "tRNS");
  163715. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  163716. {
  163717. if (trans != NULL)
  163718. {
  163719. *trans = info_ptr->trans;
  163720. retval |= PNG_INFO_tRNS;
  163721. }
  163722. if (trans_values != NULL)
  163723. *trans_values = &(info_ptr->trans_values);
  163724. }
  163725. else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
  163726. {
  163727. if (trans_values != NULL)
  163728. {
  163729. *trans_values = &(info_ptr->trans_values);
  163730. retval |= PNG_INFO_tRNS;
  163731. }
  163732. if(trans != NULL)
  163733. *trans = NULL;
  163734. }
  163735. if(num_trans != NULL)
  163736. {
  163737. *num_trans = info_ptr->num_trans;
  163738. retval |= PNG_INFO_tRNS;
  163739. }
  163740. }
  163741. return (retval);
  163742. }
  163743. #endif
  163744. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  163745. png_uint_32 PNGAPI
  163746. png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
  163747. png_unknown_chunkpp unknowns)
  163748. {
  163749. if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
  163750. {
  163751. *unknowns = info_ptr->unknown_chunks;
  163752. return ((png_uint_32)info_ptr->unknown_chunks_num);
  163753. }
  163754. return (0);
  163755. }
  163756. #endif
  163757. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  163758. png_byte PNGAPI
  163759. png_get_rgb_to_gray_status (png_structp png_ptr)
  163760. {
  163761. return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
  163762. }
  163763. #endif
  163764. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  163765. png_voidp PNGAPI
  163766. png_get_user_chunk_ptr(png_structp png_ptr)
  163767. {
  163768. return (png_ptr? png_ptr->user_chunk_ptr : NULL);
  163769. }
  163770. #endif
  163771. #ifdef PNG_WRITE_SUPPORTED
  163772. png_uint_32 PNGAPI
  163773. png_get_compression_buffer_size(png_structp png_ptr)
  163774. {
  163775. return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L);
  163776. }
  163777. #endif
  163778. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  163779. #ifndef PNG_1_0_X
  163780. png_uint_32 PNGAPI
  163781. png_get_asm_flags (png_structp png_ptr)
  163782. {
  163783. return (png_ptr? 0L: 0L);
  163784. }
  163785. png_uint_32 PNGAPI
  163786. png_get_asm_flagmask (int flag_select)
  163787. {
  163788. flag_select=flag_select;
  163789. return 0L;
  163790. }
  163791. png_uint_32 PNGAPI
  163792. png_get_mmx_flagmask (int flag_select, int *compilerID)
  163793. {
  163794. flag_select=flag_select;
  163795. *compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */
  163796. return 0L;
  163797. }
  163798. png_byte PNGAPI
  163799. png_get_mmx_bitdepth_threshold (png_structp png_ptr)
  163800. {
  163801. return (png_ptr? 0: 0);
  163802. }
  163803. png_uint_32 PNGAPI
  163804. png_get_mmx_rowbytes_threshold (png_structp png_ptr)
  163805. {
  163806. return (png_ptr? 0L: 0L);
  163807. }
  163808. #endif /* ?PNG_1_0_X */
  163809. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  163810. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  163811. png_uint_32 PNGAPI
  163812. png_get_user_width_max (png_structp png_ptr)
  163813. {
  163814. return (png_ptr? png_ptr->user_width_max : 0);
  163815. }
  163816. png_uint_32 PNGAPI
  163817. png_get_user_height_max (png_structp png_ptr)
  163818. {
  163819. return (png_ptr? png_ptr->user_height_max : 0);
  163820. }
  163821. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  163822. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  163823. /*** End of inlined file: pngget.c ***/
  163824. /*** Start of inlined file: pngmem.c ***/
  163825. #define PNG_INTERNAL
  163826. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163827. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  163828. png_voidp /* PRIVATE */
  163829. png_create_struct(int type)
  163830. {
  163831. #ifdef PNG_USER_MEM_SUPPORTED
  163832. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  163833. }
  163834. png_voidp /* PRIVATE */
  163835. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  163836. {
  163837. #endif /* PNG_USER_MEM_SUPPORTED */
  163838. png_size_t size;
  163839. png_voidp struct_ptr;
  163840. if (type == PNG_STRUCT_INFO)
  163841. size = png_sizeof(png_info);
  163842. else if (type == PNG_STRUCT_PNG)
  163843. size = png_sizeof(png_struct);
  163844. else
  163845. return (png_get_copyright(NULL));
  163846. #ifdef PNG_USER_MEM_SUPPORTED
  163847. if(malloc_fn != NULL)
  163848. {
  163849. png_struct dummy_struct;
  163850. png_structp png_ptr = &dummy_struct;
  163851. png_ptr->mem_ptr=mem_ptr;
  163852. struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size);
  163853. }
  163854. else
  163855. #endif /* PNG_USER_MEM_SUPPORTED */
  163856. struct_ptr = (png_voidp)farmalloc(size);
  163857. if (struct_ptr != NULL)
  163858. png_memset(struct_ptr, 0, size);
  163859. return (struct_ptr);
  163860. }
  163861. void /* PRIVATE */
  163862. png_destroy_struct(png_voidp struct_ptr)
  163863. {
  163864. #ifdef PNG_USER_MEM_SUPPORTED
  163865. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  163866. }
  163867. void /* PRIVATE */
  163868. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  163869. png_voidp mem_ptr)
  163870. {
  163871. #endif
  163872. if (struct_ptr != NULL)
  163873. {
  163874. #ifdef PNG_USER_MEM_SUPPORTED
  163875. if(free_fn != NULL)
  163876. {
  163877. png_struct dummy_struct;
  163878. png_structp png_ptr = &dummy_struct;
  163879. png_ptr->mem_ptr=mem_ptr;
  163880. (*(free_fn))(png_ptr, struct_ptr);
  163881. return;
  163882. }
  163883. #endif /* PNG_USER_MEM_SUPPORTED */
  163884. farfree (struct_ptr);
  163885. }
  163886. }
  163887. png_voidp PNGAPI
  163888. png_malloc(png_structp png_ptr, png_uint_32 size)
  163889. {
  163890. png_voidp ret;
  163891. if (png_ptr == NULL || size == 0)
  163892. return (NULL);
  163893. #ifdef PNG_USER_MEM_SUPPORTED
  163894. if(png_ptr->malloc_fn != NULL)
  163895. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  163896. else
  163897. ret = (png_malloc_default(png_ptr, size));
  163898. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163899. png_error(png_ptr, "Out of memory!");
  163900. return (ret);
  163901. }
  163902. png_voidp PNGAPI
  163903. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  163904. {
  163905. png_voidp ret;
  163906. #endif /* PNG_USER_MEM_SUPPORTED */
  163907. if (png_ptr == NULL || size == 0)
  163908. return (NULL);
  163909. #ifdef PNG_MAX_MALLOC_64K
  163910. if (size > (png_uint_32)65536L)
  163911. {
  163912. png_warning(png_ptr, "Cannot Allocate > 64K");
  163913. ret = NULL;
  163914. }
  163915. else
  163916. #endif
  163917. if (size != (size_t)size)
  163918. ret = NULL;
  163919. else if (size == (png_uint_32)65536L)
  163920. {
  163921. if (png_ptr->offset_table == NULL)
  163922. {
  163923. ret = farmalloc(size);
  163924. if (ret == NULL || ((png_size_t)ret & 0xffff))
  163925. {
  163926. int num_blocks;
  163927. png_uint_32 total_size;
  163928. png_bytep table;
  163929. int i;
  163930. png_byte huge * hptr;
  163931. if (ret != NULL)
  163932. {
  163933. farfree(ret);
  163934. ret = NULL;
  163935. }
  163936. if(png_ptr->zlib_window_bits > 14)
  163937. num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
  163938. else
  163939. num_blocks = 1;
  163940. if (png_ptr->zlib_mem_level >= 7)
  163941. num_blocks += (int)(1 << (png_ptr->zlib_mem_level - 7));
  163942. else
  163943. num_blocks++;
  163944. total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16;
  163945. table = farmalloc(total_size);
  163946. if (table == NULL)
  163947. {
  163948. #ifndef PNG_USER_MEM_SUPPORTED
  163949. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163950. png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */
  163951. else
  163952. png_warning(png_ptr, "Out Of Memory.");
  163953. #endif
  163954. return (NULL);
  163955. }
  163956. if ((png_size_t)table & 0xfff0)
  163957. {
  163958. #ifndef PNG_USER_MEM_SUPPORTED
  163959. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163960. png_error(png_ptr,
  163961. "Farmalloc didn't return normalized pointer");
  163962. else
  163963. png_warning(png_ptr,
  163964. "Farmalloc didn't return normalized pointer");
  163965. #endif
  163966. return (NULL);
  163967. }
  163968. png_ptr->offset_table = table;
  163969. png_ptr->offset_table_ptr = farmalloc(num_blocks *
  163970. png_sizeof (png_bytep));
  163971. if (png_ptr->offset_table_ptr == NULL)
  163972. {
  163973. #ifndef PNG_USER_MEM_SUPPORTED
  163974. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163975. png_error(png_ptr, "Out Of memory."); /* Note "O" and "M" */
  163976. else
  163977. png_warning(png_ptr, "Out Of memory.");
  163978. #endif
  163979. return (NULL);
  163980. }
  163981. hptr = (png_byte huge *)table;
  163982. if ((png_size_t)hptr & 0xf)
  163983. {
  163984. hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
  163985. hptr = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */
  163986. }
  163987. for (i = 0; i < num_blocks; i++)
  163988. {
  163989. png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
  163990. hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */
  163991. }
  163992. png_ptr->offset_table_number = num_blocks;
  163993. png_ptr->offset_table_count = 0;
  163994. png_ptr->offset_table_count_free = 0;
  163995. }
  163996. }
  163997. if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
  163998. {
  163999. #ifndef PNG_USER_MEM_SUPPORTED
  164000. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164001. png_error(png_ptr, "Out of Memory."); /* Note "o" and "M" */
  164002. else
  164003. png_warning(png_ptr, "Out of Memory.");
  164004. #endif
  164005. return (NULL);
  164006. }
  164007. ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
  164008. }
  164009. else
  164010. ret = farmalloc(size);
  164011. #ifndef PNG_USER_MEM_SUPPORTED
  164012. if (ret == NULL)
  164013. {
  164014. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164015. png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */
  164016. else
  164017. png_warning(png_ptr, "Out of memory."); /* Note "o" and "m" */
  164018. }
  164019. #endif
  164020. return (ret);
  164021. }
  164022. void PNGAPI
  164023. png_free(png_structp png_ptr, png_voidp ptr)
  164024. {
  164025. if (png_ptr == NULL || ptr == NULL)
  164026. return;
  164027. #ifdef PNG_USER_MEM_SUPPORTED
  164028. if (png_ptr->free_fn != NULL)
  164029. {
  164030. (*(png_ptr->free_fn))(png_ptr, ptr);
  164031. return;
  164032. }
  164033. else png_free_default(png_ptr, ptr);
  164034. }
  164035. void PNGAPI
  164036. png_free_default(png_structp png_ptr, png_voidp ptr)
  164037. {
  164038. #endif /* PNG_USER_MEM_SUPPORTED */
  164039. if(png_ptr == NULL) return;
  164040. if (png_ptr->offset_table != NULL)
  164041. {
  164042. int i;
  164043. for (i = 0; i < png_ptr->offset_table_count; i++)
  164044. {
  164045. if (ptr == png_ptr->offset_table_ptr[i])
  164046. {
  164047. ptr = NULL;
  164048. png_ptr->offset_table_count_free++;
  164049. break;
  164050. }
  164051. }
  164052. if (png_ptr->offset_table_count_free == png_ptr->offset_table_count)
  164053. {
  164054. farfree(png_ptr->offset_table);
  164055. farfree(png_ptr->offset_table_ptr);
  164056. png_ptr->offset_table = NULL;
  164057. png_ptr->offset_table_ptr = NULL;
  164058. }
  164059. }
  164060. if (ptr != NULL)
  164061. {
  164062. farfree(ptr);
  164063. }
  164064. }
  164065. #else /* Not the Borland DOS special memory handler */
  164066. png_voidp /* PRIVATE */
  164067. png_create_struct(int type)
  164068. {
  164069. #ifdef PNG_USER_MEM_SUPPORTED
  164070. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  164071. }
  164072. png_voidp /* PRIVATE */
  164073. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  164074. {
  164075. #endif /* PNG_USER_MEM_SUPPORTED */
  164076. png_size_t size;
  164077. png_voidp struct_ptr;
  164078. if (type == PNG_STRUCT_INFO)
  164079. size = png_sizeof(png_info);
  164080. else if (type == PNG_STRUCT_PNG)
  164081. size = png_sizeof(png_struct);
  164082. else
  164083. return (NULL);
  164084. #ifdef PNG_USER_MEM_SUPPORTED
  164085. if(malloc_fn != NULL)
  164086. {
  164087. png_struct dummy_struct;
  164088. png_structp png_ptr = &dummy_struct;
  164089. png_ptr->mem_ptr=mem_ptr;
  164090. struct_ptr = (*(malloc_fn))(png_ptr, size);
  164091. if (struct_ptr != NULL)
  164092. png_memset(struct_ptr, 0, size);
  164093. return (struct_ptr);
  164094. }
  164095. #endif /* PNG_USER_MEM_SUPPORTED */
  164096. #if defined(__TURBOC__) && !defined(__FLAT__)
  164097. struct_ptr = (png_voidp)farmalloc(size);
  164098. #else
  164099. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164100. struct_ptr = (png_voidp)halloc(size,1);
  164101. # else
  164102. struct_ptr = (png_voidp)malloc(size);
  164103. # endif
  164104. #endif
  164105. if (struct_ptr != NULL)
  164106. png_memset(struct_ptr, 0, size);
  164107. return (struct_ptr);
  164108. }
  164109. void /* PRIVATE */
  164110. png_destroy_struct(png_voidp struct_ptr)
  164111. {
  164112. #ifdef PNG_USER_MEM_SUPPORTED
  164113. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  164114. }
  164115. void /* PRIVATE */
  164116. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  164117. png_voidp mem_ptr)
  164118. {
  164119. #endif /* PNG_USER_MEM_SUPPORTED */
  164120. if (struct_ptr != NULL)
  164121. {
  164122. #ifdef PNG_USER_MEM_SUPPORTED
  164123. if(free_fn != NULL)
  164124. {
  164125. png_struct dummy_struct;
  164126. png_structp png_ptr = &dummy_struct;
  164127. png_ptr->mem_ptr=mem_ptr;
  164128. (*(free_fn))(png_ptr, struct_ptr);
  164129. return;
  164130. }
  164131. #endif /* PNG_USER_MEM_SUPPORTED */
  164132. #if defined(__TURBOC__) && !defined(__FLAT__)
  164133. farfree(struct_ptr);
  164134. #else
  164135. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164136. hfree(struct_ptr);
  164137. # else
  164138. free(struct_ptr);
  164139. # endif
  164140. #endif
  164141. }
  164142. }
  164143. png_voidp PNGAPI
  164144. png_malloc(png_structp png_ptr, png_uint_32 size)
  164145. {
  164146. png_voidp ret;
  164147. #ifdef PNG_USER_MEM_SUPPORTED
  164148. if (png_ptr == NULL || size == 0)
  164149. return (NULL);
  164150. if(png_ptr->malloc_fn != NULL)
  164151. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  164152. else
  164153. ret = (png_malloc_default(png_ptr, size));
  164154. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164155. png_error(png_ptr, "Out of Memory!");
  164156. return (ret);
  164157. }
  164158. png_voidp PNGAPI
  164159. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  164160. {
  164161. png_voidp ret;
  164162. #endif /* PNG_USER_MEM_SUPPORTED */
  164163. if (png_ptr == NULL || size == 0)
  164164. return (NULL);
  164165. #ifdef PNG_MAX_MALLOC_64K
  164166. if (size > (png_uint_32)65536L)
  164167. {
  164168. #ifndef PNG_USER_MEM_SUPPORTED
  164169. if(png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164170. png_error(png_ptr, "Cannot Allocate > 64K");
  164171. else
  164172. #endif
  164173. return NULL;
  164174. }
  164175. #endif
  164176. #if defined(__TURBOC__) && !defined(__FLAT__)
  164177. if (size != (unsigned long)size)
  164178. ret = NULL;
  164179. else
  164180. ret = farmalloc(size);
  164181. #else
  164182. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164183. if (size != (unsigned long)size)
  164184. ret = NULL;
  164185. else
  164186. ret = halloc(size, 1);
  164187. # else
  164188. if (size != (size_t)size)
  164189. ret = NULL;
  164190. else
  164191. ret = malloc((size_t)size);
  164192. # endif
  164193. #endif
  164194. #ifndef PNG_USER_MEM_SUPPORTED
  164195. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164196. png_error(png_ptr, "Out of Memory");
  164197. #endif
  164198. return (ret);
  164199. }
  164200. void PNGAPI
  164201. png_free(png_structp png_ptr, png_voidp ptr)
  164202. {
  164203. if (png_ptr == NULL || ptr == NULL)
  164204. return;
  164205. #ifdef PNG_USER_MEM_SUPPORTED
  164206. if (png_ptr->free_fn != NULL)
  164207. {
  164208. (*(png_ptr->free_fn))(png_ptr, ptr);
  164209. return;
  164210. }
  164211. else png_free_default(png_ptr, ptr);
  164212. }
  164213. void PNGAPI
  164214. png_free_default(png_structp png_ptr, png_voidp ptr)
  164215. {
  164216. if (png_ptr == NULL || ptr == NULL)
  164217. return;
  164218. #endif /* PNG_USER_MEM_SUPPORTED */
  164219. #if defined(__TURBOC__) && !defined(__FLAT__)
  164220. farfree(ptr);
  164221. #else
  164222. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164223. hfree(ptr);
  164224. # else
  164225. free(ptr);
  164226. # endif
  164227. #endif
  164228. }
  164229. #endif /* Not Borland DOS special memory handler */
  164230. #if defined(PNG_1_0_X)
  164231. # define png_malloc_warn png_malloc
  164232. #else
  164233. png_voidp PNGAPI
  164234. png_malloc_warn(png_structp png_ptr, png_uint_32 size)
  164235. {
  164236. png_voidp ptr;
  164237. png_uint_32 save_flags;
  164238. if(png_ptr == NULL) return (NULL);
  164239. save_flags=png_ptr->flags;
  164240. png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  164241. ptr = (png_voidp)png_malloc((png_structp)png_ptr, size);
  164242. png_ptr->flags=save_flags;
  164243. return(ptr);
  164244. }
  164245. #endif
  164246. png_voidp PNGAPI
  164247. png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
  164248. png_uint_32 length)
  164249. {
  164250. png_size_t size;
  164251. size = (png_size_t)length;
  164252. if ((png_uint_32)size != length)
  164253. png_error(png_ptr,"Overflow in png_memcpy_check.");
  164254. return(png_memcpy (s1, s2, size));
  164255. }
  164256. png_voidp PNGAPI
  164257. png_memset_check (png_structp png_ptr, png_voidp s1, int value,
  164258. png_uint_32 length)
  164259. {
  164260. png_size_t size;
  164261. size = (png_size_t)length;
  164262. if ((png_uint_32)size != length)
  164263. png_error(png_ptr,"Overflow in png_memset_check.");
  164264. return (png_memset (s1, value, size));
  164265. }
  164266. #ifdef PNG_USER_MEM_SUPPORTED
  164267. void PNGAPI
  164268. png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
  164269. malloc_fn, png_free_ptr free_fn)
  164270. {
  164271. if(png_ptr != NULL) {
  164272. png_ptr->mem_ptr = mem_ptr;
  164273. png_ptr->malloc_fn = malloc_fn;
  164274. png_ptr->free_fn = free_fn;
  164275. }
  164276. }
  164277. png_voidp PNGAPI
  164278. png_get_mem_ptr(png_structp png_ptr)
  164279. {
  164280. if(png_ptr == NULL) return (NULL);
  164281. return ((png_voidp)png_ptr->mem_ptr);
  164282. }
  164283. #endif /* PNG_USER_MEM_SUPPORTED */
  164284. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  164285. /*** End of inlined file: pngmem.c ***/
  164286. /*** Start of inlined file: pngread.c ***/
  164287. #define PNG_INTERNAL
  164288. #if defined(PNG_READ_SUPPORTED)
  164289. png_structp PNGAPI
  164290. png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  164291. png_error_ptr error_fn, png_error_ptr warn_fn)
  164292. {
  164293. #ifdef PNG_USER_MEM_SUPPORTED
  164294. return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
  164295. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  164296. }
  164297. png_structp PNGAPI
  164298. png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  164299. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  164300. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  164301. {
  164302. #endif /* PNG_USER_MEM_SUPPORTED */
  164303. png_structp png_ptr;
  164304. #ifdef PNG_SETJMP_SUPPORTED
  164305. #ifdef USE_FAR_KEYWORD
  164306. jmp_buf jmpbuf;
  164307. #endif
  164308. #endif
  164309. int i;
  164310. png_debug(1, "in png_create_read_struct\n");
  164311. #ifdef PNG_USER_MEM_SUPPORTED
  164312. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  164313. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  164314. #else
  164315. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164316. #endif
  164317. if (png_ptr == NULL)
  164318. return (NULL);
  164319. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164320. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164321. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164322. #endif
  164323. #ifdef PNG_SETJMP_SUPPORTED
  164324. #ifdef USE_FAR_KEYWORD
  164325. if (setjmp(jmpbuf))
  164326. #else
  164327. if (setjmp(png_ptr->jmpbuf))
  164328. #endif
  164329. {
  164330. png_free(png_ptr, png_ptr->zbuf);
  164331. png_ptr->zbuf=NULL;
  164332. #ifdef PNG_USER_MEM_SUPPORTED
  164333. png_destroy_struct_2((png_voidp)png_ptr,
  164334. (png_free_ptr)free_fn, (png_voidp)mem_ptr);
  164335. #else
  164336. png_destroy_struct((png_voidp)png_ptr);
  164337. #endif
  164338. return (NULL);
  164339. }
  164340. #ifdef USE_FAR_KEYWORD
  164341. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164342. #endif
  164343. #endif
  164344. #ifdef PNG_USER_MEM_SUPPORTED
  164345. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  164346. #endif
  164347. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  164348. i=0;
  164349. do
  164350. {
  164351. if(user_png_ver[i] != png_libpng_ver[i])
  164352. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164353. } while (png_libpng_ver[i++]);
  164354. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  164355. {
  164356. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  164357. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  164358. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  164359. {
  164360. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164361. char msg[80];
  164362. if (user_png_ver)
  164363. {
  164364. png_snprintf(msg, 80,
  164365. "Application was compiled with png.h from libpng-%.20s",
  164366. user_png_ver);
  164367. png_warning(png_ptr, msg);
  164368. }
  164369. png_snprintf(msg, 80,
  164370. "Application is running with png.c from libpng-%.20s",
  164371. png_libpng_ver);
  164372. png_warning(png_ptr, msg);
  164373. #endif
  164374. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164375. png_ptr->flags=0;
  164376. #endif
  164377. png_error(png_ptr,
  164378. "Incompatible libpng version in application and library");
  164379. }
  164380. }
  164381. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164382. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164383. (png_uint_32)png_ptr->zbuf_size);
  164384. png_ptr->zstream.zalloc = png_zalloc;
  164385. png_ptr->zstream.zfree = png_zfree;
  164386. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164387. switch (inflateInit(&png_ptr->zstream))
  164388. {
  164389. case Z_OK: /* Do nothing */ break;
  164390. case Z_MEM_ERROR:
  164391. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break;
  164392. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break;
  164393. default: png_error(png_ptr, "Unknown zlib error");
  164394. }
  164395. png_ptr->zstream.next_out = png_ptr->zbuf;
  164396. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164397. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164398. #ifdef PNG_SETJMP_SUPPORTED
  164399. #ifdef USE_FAR_KEYWORD
  164400. if (setjmp(jmpbuf))
  164401. PNG_ABORT();
  164402. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164403. #else
  164404. if (setjmp(png_ptr->jmpbuf))
  164405. PNG_ABORT();
  164406. #endif
  164407. #endif
  164408. return (png_ptr);
  164409. }
  164410. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  164411. #undef png_read_init
  164412. void PNGAPI
  164413. png_read_init(png_structp png_ptr)
  164414. {
  164415. png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  164416. }
  164417. void PNGAPI
  164418. png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  164419. png_size_t png_struct_size, png_size_t png_info_size)
  164420. {
  164421. if(png_ptr == NULL) return;
  164422. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164423. if(png_sizeof(png_struct) > png_struct_size ||
  164424. png_sizeof(png_info) > png_info_size)
  164425. {
  164426. char msg[80];
  164427. png_ptr->warning_fn=NULL;
  164428. if (user_png_ver)
  164429. {
  164430. png_snprintf(msg, 80,
  164431. "Application was compiled with png.h from libpng-%.20s",
  164432. user_png_ver);
  164433. png_warning(png_ptr, msg);
  164434. }
  164435. png_snprintf(msg, 80,
  164436. "Application is running with png.c from libpng-%.20s",
  164437. png_libpng_ver);
  164438. png_warning(png_ptr, msg);
  164439. }
  164440. #endif
  164441. if(png_sizeof(png_struct) > png_struct_size)
  164442. {
  164443. png_ptr->error_fn=NULL;
  164444. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164445. png_ptr->flags=0;
  164446. #endif
  164447. png_error(png_ptr,
  164448. "The png struct allocated by the application for reading is too small.");
  164449. }
  164450. if(png_sizeof(png_info) > png_info_size)
  164451. {
  164452. png_ptr->error_fn=NULL;
  164453. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164454. png_ptr->flags=0;
  164455. #endif
  164456. png_error(png_ptr,
  164457. "The info struct allocated by application for reading is too small.");
  164458. }
  164459. png_read_init_3(&png_ptr, user_png_ver, png_struct_size);
  164460. }
  164461. #endif /* PNG_1_0_X || PNG_1_2_X */
  164462. void PNGAPI
  164463. png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  164464. png_size_t png_struct_size)
  164465. {
  164466. #ifdef PNG_SETJMP_SUPPORTED
  164467. jmp_buf tmp_jmp; /* to save current jump buffer */
  164468. #endif
  164469. int i=0;
  164470. png_structp png_ptr=*ptr_ptr;
  164471. if(png_ptr == NULL) return;
  164472. do
  164473. {
  164474. if(user_png_ver[i] != png_libpng_ver[i])
  164475. {
  164476. #ifdef PNG_LEGACY_SUPPORTED
  164477. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164478. #else
  164479. png_ptr->warning_fn=NULL;
  164480. png_warning(png_ptr,
  164481. "Application uses deprecated png_read_init() and should be recompiled.");
  164482. break;
  164483. #endif
  164484. }
  164485. } while (png_libpng_ver[i++]);
  164486. png_debug(1, "in png_read_init_3\n");
  164487. #ifdef PNG_SETJMP_SUPPORTED
  164488. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  164489. #endif
  164490. if(png_sizeof(png_struct) > png_struct_size)
  164491. {
  164492. png_destroy_struct(png_ptr);
  164493. *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164494. png_ptr = *ptr_ptr;
  164495. }
  164496. png_memset(png_ptr, 0, png_sizeof (png_struct));
  164497. #ifdef PNG_SETJMP_SUPPORTED
  164498. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  164499. #endif
  164500. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164501. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164502. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164503. #endif
  164504. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164505. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164506. (png_uint_32)png_ptr->zbuf_size);
  164507. png_ptr->zstream.zalloc = png_zalloc;
  164508. png_ptr->zstream.zfree = png_zfree;
  164509. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164510. switch (inflateInit(&png_ptr->zstream))
  164511. {
  164512. case Z_OK: /* Do nothing */ break;
  164513. case Z_MEM_ERROR:
  164514. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break;
  164515. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break;
  164516. default: png_error(png_ptr, "Unknown zlib error");
  164517. }
  164518. png_ptr->zstream.next_out = png_ptr->zbuf;
  164519. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164520. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164521. }
  164522. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164523. void PNGAPI
  164524. png_read_info(png_structp png_ptr, png_infop info_ptr)
  164525. {
  164526. if(png_ptr == NULL) return;
  164527. png_debug(1, "in png_read_info\n");
  164528. if (png_ptr->sig_bytes < 8)
  164529. {
  164530. png_size_t num_checked = png_ptr->sig_bytes,
  164531. num_to_check = 8 - num_checked;
  164532. png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
  164533. png_ptr->sig_bytes = 8;
  164534. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  164535. {
  164536. if (num_checked < 4 &&
  164537. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  164538. png_error(png_ptr, "Not a PNG file");
  164539. else
  164540. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  164541. }
  164542. if (num_checked < 3)
  164543. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  164544. }
  164545. for(;;)
  164546. {
  164547. #ifdef PNG_USE_LOCAL_ARRAYS
  164548. PNG_CONST PNG_IHDR;
  164549. PNG_CONST PNG_IDAT;
  164550. PNG_CONST PNG_IEND;
  164551. PNG_CONST PNG_PLTE;
  164552. #if defined(PNG_READ_bKGD_SUPPORTED)
  164553. PNG_CONST PNG_bKGD;
  164554. #endif
  164555. #if defined(PNG_READ_cHRM_SUPPORTED)
  164556. PNG_CONST PNG_cHRM;
  164557. #endif
  164558. #if defined(PNG_READ_gAMA_SUPPORTED)
  164559. PNG_CONST PNG_gAMA;
  164560. #endif
  164561. #if defined(PNG_READ_hIST_SUPPORTED)
  164562. PNG_CONST PNG_hIST;
  164563. #endif
  164564. #if defined(PNG_READ_iCCP_SUPPORTED)
  164565. PNG_CONST PNG_iCCP;
  164566. #endif
  164567. #if defined(PNG_READ_iTXt_SUPPORTED)
  164568. PNG_CONST PNG_iTXt;
  164569. #endif
  164570. #if defined(PNG_READ_oFFs_SUPPORTED)
  164571. PNG_CONST PNG_oFFs;
  164572. #endif
  164573. #if defined(PNG_READ_pCAL_SUPPORTED)
  164574. PNG_CONST PNG_pCAL;
  164575. #endif
  164576. #if defined(PNG_READ_pHYs_SUPPORTED)
  164577. PNG_CONST PNG_pHYs;
  164578. #endif
  164579. #if defined(PNG_READ_sBIT_SUPPORTED)
  164580. PNG_CONST PNG_sBIT;
  164581. #endif
  164582. #if defined(PNG_READ_sCAL_SUPPORTED)
  164583. PNG_CONST PNG_sCAL;
  164584. #endif
  164585. #if defined(PNG_READ_sPLT_SUPPORTED)
  164586. PNG_CONST PNG_sPLT;
  164587. #endif
  164588. #if defined(PNG_READ_sRGB_SUPPORTED)
  164589. PNG_CONST PNG_sRGB;
  164590. #endif
  164591. #if defined(PNG_READ_tEXt_SUPPORTED)
  164592. PNG_CONST PNG_tEXt;
  164593. #endif
  164594. #if defined(PNG_READ_tIME_SUPPORTED)
  164595. PNG_CONST PNG_tIME;
  164596. #endif
  164597. #if defined(PNG_READ_tRNS_SUPPORTED)
  164598. PNG_CONST PNG_tRNS;
  164599. #endif
  164600. #if defined(PNG_READ_zTXt_SUPPORTED)
  164601. PNG_CONST PNG_zTXt;
  164602. #endif
  164603. #endif /* PNG_USE_LOCAL_ARRAYS */
  164604. png_byte chunk_length[4];
  164605. png_uint_32 length;
  164606. png_read_data(png_ptr, chunk_length, 4);
  164607. length = png_get_uint_31(png_ptr,chunk_length);
  164608. png_reset_crc(png_ptr);
  164609. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  164610. png_debug2(0, "Reading %s chunk, length=%lu.\n", png_ptr->chunk_name,
  164611. length);
  164612. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164613. if(png_ptr->mode & PNG_AFTER_IDAT)
  164614. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  164615. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  164616. png_handle_IHDR(png_ptr, info_ptr, length);
  164617. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  164618. png_handle_IEND(png_ptr, info_ptr, length);
  164619. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  164620. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  164621. {
  164622. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164623. png_ptr->mode |= PNG_HAVE_IDAT;
  164624. png_handle_unknown(png_ptr, info_ptr, length);
  164625. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  164626. png_ptr->mode |= PNG_HAVE_PLTE;
  164627. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164628. {
  164629. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  164630. png_error(png_ptr, "Missing IHDR before IDAT");
  164631. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  164632. !(png_ptr->mode & PNG_HAVE_PLTE))
  164633. png_error(png_ptr, "Missing PLTE before IDAT");
  164634. break;
  164635. }
  164636. }
  164637. #endif
  164638. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  164639. png_handle_PLTE(png_ptr, info_ptr, length);
  164640. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164641. {
  164642. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  164643. png_error(png_ptr, "Missing IHDR before IDAT");
  164644. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  164645. !(png_ptr->mode & PNG_HAVE_PLTE))
  164646. png_error(png_ptr, "Missing PLTE before IDAT");
  164647. png_ptr->idat_size = length;
  164648. png_ptr->mode |= PNG_HAVE_IDAT;
  164649. break;
  164650. }
  164651. #if defined(PNG_READ_bKGD_SUPPORTED)
  164652. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  164653. png_handle_bKGD(png_ptr, info_ptr, length);
  164654. #endif
  164655. #if defined(PNG_READ_cHRM_SUPPORTED)
  164656. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  164657. png_handle_cHRM(png_ptr, info_ptr, length);
  164658. #endif
  164659. #if defined(PNG_READ_gAMA_SUPPORTED)
  164660. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  164661. png_handle_gAMA(png_ptr, info_ptr, length);
  164662. #endif
  164663. #if defined(PNG_READ_hIST_SUPPORTED)
  164664. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  164665. png_handle_hIST(png_ptr, info_ptr, length);
  164666. #endif
  164667. #if defined(PNG_READ_oFFs_SUPPORTED)
  164668. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  164669. png_handle_oFFs(png_ptr, info_ptr, length);
  164670. #endif
  164671. #if defined(PNG_READ_pCAL_SUPPORTED)
  164672. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  164673. png_handle_pCAL(png_ptr, info_ptr, length);
  164674. #endif
  164675. #if defined(PNG_READ_sCAL_SUPPORTED)
  164676. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  164677. png_handle_sCAL(png_ptr, info_ptr, length);
  164678. #endif
  164679. #if defined(PNG_READ_pHYs_SUPPORTED)
  164680. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  164681. png_handle_pHYs(png_ptr, info_ptr, length);
  164682. #endif
  164683. #if defined(PNG_READ_sBIT_SUPPORTED)
  164684. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  164685. png_handle_sBIT(png_ptr, info_ptr, length);
  164686. #endif
  164687. #if defined(PNG_READ_sRGB_SUPPORTED)
  164688. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  164689. png_handle_sRGB(png_ptr, info_ptr, length);
  164690. #endif
  164691. #if defined(PNG_READ_iCCP_SUPPORTED)
  164692. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  164693. png_handle_iCCP(png_ptr, info_ptr, length);
  164694. #endif
  164695. #if defined(PNG_READ_sPLT_SUPPORTED)
  164696. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  164697. png_handle_sPLT(png_ptr, info_ptr, length);
  164698. #endif
  164699. #if defined(PNG_READ_tEXt_SUPPORTED)
  164700. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  164701. png_handle_tEXt(png_ptr, info_ptr, length);
  164702. #endif
  164703. #if defined(PNG_READ_tIME_SUPPORTED)
  164704. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  164705. png_handle_tIME(png_ptr, info_ptr, length);
  164706. #endif
  164707. #if defined(PNG_READ_tRNS_SUPPORTED)
  164708. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  164709. png_handle_tRNS(png_ptr, info_ptr, length);
  164710. #endif
  164711. #if defined(PNG_READ_zTXt_SUPPORTED)
  164712. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  164713. png_handle_zTXt(png_ptr, info_ptr, length);
  164714. #endif
  164715. #if defined(PNG_READ_iTXt_SUPPORTED)
  164716. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  164717. png_handle_iTXt(png_ptr, info_ptr, length);
  164718. #endif
  164719. else
  164720. png_handle_unknown(png_ptr, info_ptr, length);
  164721. }
  164722. }
  164723. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164724. void PNGAPI
  164725. png_read_update_info(png_structp png_ptr, png_infop info_ptr)
  164726. {
  164727. png_debug(1, "in png_read_update_info\n");
  164728. if(png_ptr == NULL) return;
  164729. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164730. png_read_start_row(png_ptr);
  164731. else
  164732. png_warning(png_ptr,
  164733. "Ignoring extra png_read_update_info() call; row buffer not reallocated");
  164734. png_read_transform_info(png_ptr, info_ptr);
  164735. }
  164736. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164737. void PNGAPI
  164738. png_start_read_image(png_structp png_ptr)
  164739. {
  164740. png_debug(1, "in png_start_read_image\n");
  164741. if(png_ptr == NULL) return;
  164742. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164743. png_read_start_row(png_ptr);
  164744. }
  164745. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164746. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164747. void PNGAPI
  164748. png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
  164749. {
  164750. #ifdef PNG_USE_LOCAL_ARRAYS
  164751. PNG_CONST PNG_IDAT;
  164752. PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
  164753. 0xff};
  164754. PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  164755. #endif
  164756. int ret;
  164757. if(png_ptr == NULL) return;
  164758. png_debug2(1, "in png_read_row (row %lu, pass %d)\n",
  164759. png_ptr->row_number, png_ptr->pass);
  164760. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164761. png_read_start_row(png_ptr);
  164762. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  164763. {
  164764. #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
  164765. if (png_ptr->transformations & PNG_INVERT_MONO)
  164766. png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined.");
  164767. #endif
  164768. #if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
  164769. if (png_ptr->transformations & PNG_FILLER)
  164770. png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined.");
  164771. #endif
  164772. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
  164773. if (png_ptr->transformations & PNG_PACKSWAP)
  164774. png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined.");
  164775. #endif
  164776. #if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
  164777. if (png_ptr->transformations & PNG_PACK)
  164778. png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined.");
  164779. #endif
  164780. #if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
  164781. if (png_ptr->transformations & PNG_SHIFT)
  164782. png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined.");
  164783. #endif
  164784. #if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
  164785. if (png_ptr->transformations & PNG_BGR)
  164786. png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined.");
  164787. #endif
  164788. #if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
  164789. if (png_ptr->transformations & PNG_SWAP_BYTES)
  164790. png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined.");
  164791. #endif
  164792. }
  164793. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  164794. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  164795. {
  164796. switch (png_ptr->pass)
  164797. {
  164798. case 0:
  164799. if (png_ptr->row_number & 0x07)
  164800. {
  164801. if (dsp_row != NULL)
  164802. png_combine_row(png_ptr, dsp_row,
  164803. png_pass_dsp_mask[png_ptr->pass]);
  164804. png_read_finish_row(png_ptr);
  164805. return;
  164806. }
  164807. break;
  164808. case 1:
  164809. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  164810. {
  164811. if (dsp_row != NULL)
  164812. png_combine_row(png_ptr, dsp_row,
  164813. png_pass_dsp_mask[png_ptr->pass]);
  164814. png_read_finish_row(png_ptr);
  164815. return;
  164816. }
  164817. break;
  164818. case 2:
  164819. if ((png_ptr->row_number & 0x07) != 4)
  164820. {
  164821. if (dsp_row != NULL && (png_ptr->row_number & 4))
  164822. png_combine_row(png_ptr, dsp_row,
  164823. png_pass_dsp_mask[png_ptr->pass]);
  164824. png_read_finish_row(png_ptr);
  164825. return;
  164826. }
  164827. break;
  164828. case 3:
  164829. if ((png_ptr->row_number & 3) || png_ptr->width < 3)
  164830. {
  164831. if (dsp_row != NULL)
  164832. png_combine_row(png_ptr, dsp_row,
  164833. png_pass_dsp_mask[png_ptr->pass]);
  164834. png_read_finish_row(png_ptr);
  164835. return;
  164836. }
  164837. break;
  164838. case 4:
  164839. if ((png_ptr->row_number & 3) != 2)
  164840. {
  164841. if (dsp_row != NULL && (png_ptr->row_number & 2))
  164842. png_combine_row(png_ptr, dsp_row,
  164843. png_pass_dsp_mask[png_ptr->pass]);
  164844. png_read_finish_row(png_ptr);
  164845. return;
  164846. }
  164847. break;
  164848. case 5:
  164849. if ((png_ptr->row_number & 1) || png_ptr->width < 2)
  164850. {
  164851. if (dsp_row != NULL)
  164852. png_combine_row(png_ptr, dsp_row,
  164853. png_pass_dsp_mask[png_ptr->pass]);
  164854. png_read_finish_row(png_ptr);
  164855. return;
  164856. }
  164857. break;
  164858. case 6:
  164859. if (!(png_ptr->row_number & 1))
  164860. {
  164861. png_read_finish_row(png_ptr);
  164862. return;
  164863. }
  164864. break;
  164865. }
  164866. }
  164867. #endif
  164868. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  164869. png_error(png_ptr, "Invalid attempt to read row data");
  164870. png_ptr->zstream.next_out = png_ptr->row_buf;
  164871. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  164872. do
  164873. {
  164874. if (!(png_ptr->zstream.avail_in))
  164875. {
  164876. while (!png_ptr->idat_size)
  164877. {
  164878. png_byte chunk_length[4];
  164879. png_crc_finish(png_ptr, 0);
  164880. png_read_data(png_ptr, chunk_length, 4);
  164881. png_ptr->idat_size = png_get_uint_31(png_ptr,chunk_length);
  164882. png_reset_crc(png_ptr);
  164883. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  164884. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164885. png_error(png_ptr, "Not enough image data");
  164886. }
  164887. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  164888. png_ptr->zstream.next_in = png_ptr->zbuf;
  164889. if (png_ptr->zbuf_size > png_ptr->idat_size)
  164890. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  164891. png_crc_read(png_ptr, png_ptr->zbuf,
  164892. (png_size_t)png_ptr->zstream.avail_in);
  164893. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  164894. }
  164895. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  164896. if (ret == Z_STREAM_END)
  164897. {
  164898. if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in ||
  164899. png_ptr->idat_size)
  164900. png_error(png_ptr, "Extra compressed data");
  164901. png_ptr->mode |= PNG_AFTER_IDAT;
  164902. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  164903. break;
  164904. }
  164905. if (ret != Z_OK)
  164906. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  164907. "Decompression error");
  164908. } while (png_ptr->zstream.avail_out);
  164909. png_ptr->row_info.color_type = png_ptr->color_type;
  164910. png_ptr->row_info.width = png_ptr->iwidth;
  164911. png_ptr->row_info.channels = png_ptr->channels;
  164912. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  164913. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  164914. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  164915. png_ptr->row_info.width);
  164916. if(png_ptr->row_buf[0])
  164917. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  164918. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  164919. (int)(png_ptr->row_buf[0]));
  164920. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  164921. png_ptr->rowbytes + 1);
  164922. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  164923. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  164924. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  164925. {
  164926. png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  164927. }
  164928. #endif
  164929. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  164930. png_do_read_transformations(png_ptr);
  164931. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  164932. if (png_ptr->interlaced &&
  164933. (png_ptr->transformations & PNG_INTERLACE))
  164934. {
  164935. if (png_ptr->pass < 6)
  164936. png_do_read_interlace(png_ptr);
  164937. if (dsp_row != NULL)
  164938. png_combine_row(png_ptr, dsp_row,
  164939. png_pass_dsp_mask[png_ptr->pass]);
  164940. if (row != NULL)
  164941. png_combine_row(png_ptr, row,
  164942. png_pass_mask[png_ptr->pass]);
  164943. }
  164944. else
  164945. #endif
  164946. {
  164947. if (row != NULL)
  164948. png_combine_row(png_ptr, row, 0xff);
  164949. if (dsp_row != NULL)
  164950. png_combine_row(png_ptr, dsp_row, 0xff);
  164951. }
  164952. png_read_finish_row(png_ptr);
  164953. if (png_ptr->read_row_fn != NULL)
  164954. (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  164955. }
  164956. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164957. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164958. void PNGAPI
  164959. png_read_rows(png_structp png_ptr, png_bytepp row,
  164960. png_bytepp display_row, png_uint_32 num_rows)
  164961. {
  164962. png_uint_32 i;
  164963. png_bytepp rp;
  164964. png_bytepp dp;
  164965. png_debug(1, "in png_read_rows\n");
  164966. if(png_ptr == NULL) return;
  164967. rp = row;
  164968. dp = display_row;
  164969. if (rp != NULL && dp != NULL)
  164970. for (i = 0; i < num_rows; i++)
  164971. {
  164972. png_bytep rptr = *rp++;
  164973. png_bytep dptr = *dp++;
  164974. png_read_row(png_ptr, rptr, dptr);
  164975. }
  164976. else if(rp != NULL)
  164977. for (i = 0; i < num_rows; i++)
  164978. {
  164979. png_bytep rptr = *rp;
  164980. png_read_row(png_ptr, rptr, png_bytep_NULL);
  164981. rp++;
  164982. }
  164983. else if(dp != NULL)
  164984. for (i = 0; i < num_rows; i++)
  164985. {
  164986. png_bytep dptr = *dp;
  164987. png_read_row(png_ptr, png_bytep_NULL, dptr);
  164988. dp++;
  164989. }
  164990. }
  164991. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164992. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164993. void PNGAPI
  164994. png_read_image(png_structp png_ptr, png_bytepp image)
  164995. {
  164996. png_uint_32 i,image_height;
  164997. int pass, j;
  164998. png_bytepp rp;
  164999. png_debug(1, "in png_read_image\n");
  165000. if(png_ptr == NULL) return;
  165001. #ifdef PNG_READ_INTERLACING_SUPPORTED
  165002. pass = png_set_interlace_handling(png_ptr);
  165003. #else
  165004. if (png_ptr->interlaced)
  165005. png_error(png_ptr,
  165006. "Cannot read interlaced image -- interlace handler disabled.");
  165007. pass = 1;
  165008. #endif
  165009. image_height=png_ptr->height;
  165010. png_ptr->num_rows = image_height; /* Make sure this is set correctly */
  165011. for (j = 0; j < pass; j++)
  165012. {
  165013. rp = image;
  165014. for (i = 0; i < image_height; i++)
  165015. {
  165016. png_read_row(png_ptr, *rp, png_bytep_NULL);
  165017. rp++;
  165018. }
  165019. }
  165020. }
  165021. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165022. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165023. void PNGAPI
  165024. png_read_end(png_structp png_ptr, png_infop info_ptr)
  165025. {
  165026. png_byte chunk_length[4];
  165027. png_uint_32 length;
  165028. png_debug(1, "in png_read_end\n");
  165029. if(png_ptr == NULL) return;
  165030. png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
  165031. do
  165032. {
  165033. #ifdef PNG_USE_LOCAL_ARRAYS
  165034. PNG_CONST PNG_IHDR;
  165035. PNG_CONST PNG_IDAT;
  165036. PNG_CONST PNG_IEND;
  165037. PNG_CONST PNG_PLTE;
  165038. #if defined(PNG_READ_bKGD_SUPPORTED)
  165039. PNG_CONST PNG_bKGD;
  165040. #endif
  165041. #if defined(PNG_READ_cHRM_SUPPORTED)
  165042. PNG_CONST PNG_cHRM;
  165043. #endif
  165044. #if defined(PNG_READ_gAMA_SUPPORTED)
  165045. PNG_CONST PNG_gAMA;
  165046. #endif
  165047. #if defined(PNG_READ_hIST_SUPPORTED)
  165048. PNG_CONST PNG_hIST;
  165049. #endif
  165050. #if defined(PNG_READ_iCCP_SUPPORTED)
  165051. PNG_CONST PNG_iCCP;
  165052. #endif
  165053. #if defined(PNG_READ_iTXt_SUPPORTED)
  165054. PNG_CONST PNG_iTXt;
  165055. #endif
  165056. #if defined(PNG_READ_oFFs_SUPPORTED)
  165057. PNG_CONST PNG_oFFs;
  165058. #endif
  165059. #if defined(PNG_READ_pCAL_SUPPORTED)
  165060. PNG_CONST PNG_pCAL;
  165061. #endif
  165062. #if defined(PNG_READ_pHYs_SUPPORTED)
  165063. PNG_CONST PNG_pHYs;
  165064. #endif
  165065. #if defined(PNG_READ_sBIT_SUPPORTED)
  165066. PNG_CONST PNG_sBIT;
  165067. #endif
  165068. #if defined(PNG_READ_sCAL_SUPPORTED)
  165069. PNG_CONST PNG_sCAL;
  165070. #endif
  165071. #if defined(PNG_READ_sPLT_SUPPORTED)
  165072. PNG_CONST PNG_sPLT;
  165073. #endif
  165074. #if defined(PNG_READ_sRGB_SUPPORTED)
  165075. PNG_CONST PNG_sRGB;
  165076. #endif
  165077. #if defined(PNG_READ_tEXt_SUPPORTED)
  165078. PNG_CONST PNG_tEXt;
  165079. #endif
  165080. #if defined(PNG_READ_tIME_SUPPORTED)
  165081. PNG_CONST PNG_tIME;
  165082. #endif
  165083. #if defined(PNG_READ_tRNS_SUPPORTED)
  165084. PNG_CONST PNG_tRNS;
  165085. #endif
  165086. #if defined(PNG_READ_zTXt_SUPPORTED)
  165087. PNG_CONST PNG_zTXt;
  165088. #endif
  165089. #endif /* PNG_USE_LOCAL_ARRAYS */
  165090. png_read_data(png_ptr, chunk_length, 4);
  165091. length = png_get_uint_31(png_ptr,chunk_length);
  165092. png_reset_crc(png_ptr);
  165093. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165094. png_debug1(0, "Reading %s chunk.\n", png_ptr->chunk_name);
  165095. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165096. png_handle_IHDR(png_ptr, info_ptr, length);
  165097. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165098. png_handle_IEND(png_ptr, info_ptr, length);
  165099. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165100. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165101. {
  165102. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165103. {
  165104. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165105. png_error(png_ptr, "Too many IDAT's found");
  165106. }
  165107. png_handle_unknown(png_ptr, info_ptr, length);
  165108. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165109. png_ptr->mode |= PNG_HAVE_PLTE;
  165110. }
  165111. #endif
  165112. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165113. {
  165114. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165115. png_error(png_ptr, "Too many IDAT's found");
  165116. png_crc_finish(png_ptr, length);
  165117. }
  165118. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165119. png_handle_PLTE(png_ptr, info_ptr, length);
  165120. #if defined(PNG_READ_bKGD_SUPPORTED)
  165121. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165122. png_handle_bKGD(png_ptr, info_ptr, length);
  165123. #endif
  165124. #if defined(PNG_READ_cHRM_SUPPORTED)
  165125. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165126. png_handle_cHRM(png_ptr, info_ptr, length);
  165127. #endif
  165128. #if defined(PNG_READ_gAMA_SUPPORTED)
  165129. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165130. png_handle_gAMA(png_ptr, info_ptr, length);
  165131. #endif
  165132. #if defined(PNG_READ_hIST_SUPPORTED)
  165133. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165134. png_handle_hIST(png_ptr, info_ptr, length);
  165135. #endif
  165136. #if defined(PNG_READ_oFFs_SUPPORTED)
  165137. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165138. png_handle_oFFs(png_ptr, info_ptr, length);
  165139. #endif
  165140. #if defined(PNG_READ_pCAL_SUPPORTED)
  165141. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165142. png_handle_pCAL(png_ptr, info_ptr, length);
  165143. #endif
  165144. #if defined(PNG_READ_sCAL_SUPPORTED)
  165145. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165146. png_handle_sCAL(png_ptr, info_ptr, length);
  165147. #endif
  165148. #if defined(PNG_READ_pHYs_SUPPORTED)
  165149. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165150. png_handle_pHYs(png_ptr, info_ptr, length);
  165151. #endif
  165152. #if defined(PNG_READ_sBIT_SUPPORTED)
  165153. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165154. png_handle_sBIT(png_ptr, info_ptr, length);
  165155. #endif
  165156. #if defined(PNG_READ_sRGB_SUPPORTED)
  165157. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165158. png_handle_sRGB(png_ptr, info_ptr, length);
  165159. #endif
  165160. #if defined(PNG_READ_iCCP_SUPPORTED)
  165161. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165162. png_handle_iCCP(png_ptr, info_ptr, length);
  165163. #endif
  165164. #if defined(PNG_READ_sPLT_SUPPORTED)
  165165. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165166. png_handle_sPLT(png_ptr, info_ptr, length);
  165167. #endif
  165168. #if defined(PNG_READ_tEXt_SUPPORTED)
  165169. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165170. png_handle_tEXt(png_ptr, info_ptr, length);
  165171. #endif
  165172. #if defined(PNG_READ_tIME_SUPPORTED)
  165173. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165174. png_handle_tIME(png_ptr, info_ptr, length);
  165175. #endif
  165176. #if defined(PNG_READ_tRNS_SUPPORTED)
  165177. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165178. png_handle_tRNS(png_ptr, info_ptr, length);
  165179. #endif
  165180. #if defined(PNG_READ_zTXt_SUPPORTED)
  165181. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165182. png_handle_zTXt(png_ptr, info_ptr, length);
  165183. #endif
  165184. #if defined(PNG_READ_iTXt_SUPPORTED)
  165185. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165186. png_handle_iTXt(png_ptr, info_ptr, length);
  165187. #endif
  165188. else
  165189. png_handle_unknown(png_ptr, info_ptr, length);
  165190. } while (!(png_ptr->mode & PNG_HAVE_IEND));
  165191. }
  165192. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165193. void PNGAPI
  165194. png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
  165195. png_infopp end_info_ptr_ptr)
  165196. {
  165197. png_structp png_ptr = NULL;
  165198. png_infop info_ptr = NULL, end_info_ptr = NULL;
  165199. #ifdef PNG_USER_MEM_SUPPORTED
  165200. png_free_ptr free_fn;
  165201. png_voidp mem_ptr;
  165202. #endif
  165203. png_debug(1, "in png_destroy_read_struct\n");
  165204. if (png_ptr_ptr != NULL)
  165205. png_ptr = *png_ptr_ptr;
  165206. if (info_ptr_ptr != NULL)
  165207. info_ptr = *info_ptr_ptr;
  165208. if (end_info_ptr_ptr != NULL)
  165209. end_info_ptr = *end_info_ptr_ptr;
  165210. #ifdef PNG_USER_MEM_SUPPORTED
  165211. free_fn = png_ptr->free_fn;
  165212. mem_ptr = png_ptr->mem_ptr;
  165213. #endif
  165214. png_read_destroy(png_ptr, info_ptr, end_info_ptr);
  165215. if (info_ptr != NULL)
  165216. {
  165217. #if defined(PNG_TEXT_SUPPORTED)
  165218. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
  165219. #endif
  165220. #ifdef PNG_USER_MEM_SUPPORTED
  165221. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  165222. (png_voidp)mem_ptr);
  165223. #else
  165224. png_destroy_struct((png_voidp)info_ptr);
  165225. #endif
  165226. *info_ptr_ptr = NULL;
  165227. }
  165228. if (end_info_ptr != NULL)
  165229. {
  165230. #if defined(PNG_READ_TEXT_SUPPORTED)
  165231. png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
  165232. #endif
  165233. #ifdef PNG_USER_MEM_SUPPORTED
  165234. png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn,
  165235. (png_voidp)mem_ptr);
  165236. #else
  165237. png_destroy_struct((png_voidp)end_info_ptr);
  165238. #endif
  165239. *end_info_ptr_ptr = NULL;
  165240. }
  165241. if (png_ptr != NULL)
  165242. {
  165243. #ifdef PNG_USER_MEM_SUPPORTED
  165244. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  165245. (png_voidp)mem_ptr);
  165246. #else
  165247. png_destroy_struct((png_voidp)png_ptr);
  165248. #endif
  165249. *png_ptr_ptr = NULL;
  165250. }
  165251. }
  165252. void /* PRIVATE */
  165253. png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
  165254. {
  165255. #ifdef PNG_SETJMP_SUPPORTED
  165256. jmp_buf tmp_jmp;
  165257. #endif
  165258. png_error_ptr error_fn;
  165259. png_error_ptr warning_fn;
  165260. png_voidp error_ptr;
  165261. #ifdef PNG_USER_MEM_SUPPORTED
  165262. png_free_ptr free_fn;
  165263. #endif
  165264. png_debug(1, "in png_read_destroy\n");
  165265. if (info_ptr != NULL)
  165266. png_info_destroy(png_ptr, info_ptr);
  165267. if (end_info_ptr != NULL)
  165268. png_info_destroy(png_ptr, end_info_ptr);
  165269. png_free(png_ptr, png_ptr->zbuf);
  165270. png_free(png_ptr, png_ptr->big_row_buf);
  165271. png_free(png_ptr, png_ptr->prev_row);
  165272. #if defined(PNG_READ_DITHER_SUPPORTED)
  165273. png_free(png_ptr, png_ptr->palette_lookup);
  165274. png_free(png_ptr, png_ptr->dither_index);
  165275. #endif
  165276. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165277. png_free(png_ptr, png_ptr->gamma_table);
  165278. #endif
  165279. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165280. png_free(png_ptr, png_ptr->gamma_from_1);
  165281. png_free(png_ptr, png_ptr->gamma_to_1);
  165282. #endif
  165283. #ifdef PNG_FREE_ME_SUPPORTED
  165284. if (png_ptr->free_me & PNG_FREE_PLTE)
  165285. png_zfree(png_ptr, png_ptr->palette);
  165286. png_ptr->free_me &= ~PNG_FREE_PLTE;
  165287. #else
  165288. if (png_ptr->flags & PNG_FLAG_FREE_PLTE)
  165289. png_zfree(png_ptr, png_ptr->palette);
  165290. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  165291. #endif
  165292. #if defined(PNG_tRNS_SUPPORTED) || \
  165293. defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  165294. #ifdef PNG_FREE_ME_SUPPORTED
  165295. if (png_ptr->free_me & PNG_FREE_TRNS)
  165296. png_free(png_ptr, png_ptr->trans);
  165297. png_ptr->free_me &= ~PNG_FREE_TRNS;
  165298. #else
  165299. if (png_ptr->flags & PNG_FLAG_FREE_TRNS)
  165300. png_free(png_ptr, png_ptr->trans);
  165301. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  165302. #endif
  165303. #endif
  165304. #if defined(PNG_READ_hIST_SUPPORTED)
  165305. #ifdef PNG_FREE_ME_SUPPORTED
  165306. if (png_ptr->free_me & PNG_FREE_HIST)
  165307. png_free(png_ptr, png_ptr->hist);
  165308. png_ptr->free_me &= ~PNG_FREE_HIST;
  165309. #else
  165310. if (png_ptr->flags & PNG_FLAG_FREE_HIST)
  165311. png_free(png_ptr, png_ptr->hist);
  165312. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  165313. #endif
  165314. #endif
  165315. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165316. if (png_ptr->gamma_16_table != NULL)
  165317. {
  165318. int i;
  165319. int istop = (1 << (8 - png_ptr->gamma_shift));
  165320. for (i = 0; i < istop; i++)
  165321. {
  165322. png_free(png_ptr, png_ptr->gamma_16_table[i]);
  165323. }
  165324. png_free(png_ptr, png_ptr->gamma_16_table);
  165325. }
  165326. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165327. if (png_ptr->gamma_16_from_1 != NULL)
  165328. {
  165329. int i;
  165330. int istop = (1 << (8 - png_ptr->gamma_shift));
  165331. for (i = 0; i < istop; i++)
  165332. {
  165333. png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
  165334. }
  165335. png_free(png_ptr, png_ptr->gamma_16_from_1);
  165336. }
  165337. if (png_ptr->gamma_16_to_1 != NULL)
  165338. {
  165339. int i;
  165340. int istop = (1 << (8 - png_ptr->gamma_shift));
  165341. for (i = 0; i < istop; i++)
  165342. {
  165343. png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
  165344. }
  165345. png_free(png_ptr, png_ptr->gamma_16_to_1);
  165346. }
  165347. #endif
  165348. #endif
  165349. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  165350. png_free(png_ptr, png_ptr->time_buffer);
  165351. #endif
  165352. inflateEnd(&png_ptr->zstream);
  165353. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165354. png_free(png_ptr, png_ptr->save_buffer);
  165355. #endif
  165356. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165357. #ifdef PNG_TEXT_SUPPORTED
  165358. png_free(png_ptr, png_ptr->current_text);
  165359. #endif /* PNG_TEXT_SUPPORTED */
  165360. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  165361. #ifdef PNG_SETJMP_SUPPORTED
  165362. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  165363. #endif
  165364. error_fn = png_ptr->error_fn;
  165365. warning_fn = png_ptr->warning_fn;
  165366. error_ptr = png_ptr->error_ptr;
  165367. #ifdef PNG_USER_MEM_SUPPORTED
  165368. free_fn = png_ptr->free_fn;
  165369. #endif
  165370. png_memset(png_ptr, 0, png_sizeof (png_struct));
  165371. png_ptr->error_fn = error_fn;
  165372. png_ptr->warning_fn = warning_fn;
  165373. png_ptr->error_ptr = error_ptr;
  165374. #ifdef PNG_USER_MEM_SUPPORTED
  165375. png_ptr->free_fn = free_fn;
  165376. #endif
  165377. #ifdef PNG_SETJMP_SUPPORTED
  165378. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  165379. #endif
  165380. }
  165381. void PNGAPI
  165382. png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
  165383. {
  165384. if(png_ptr == NULL) return;
  165385. png_ptr->read_row_fn = read_row_fn;
  165386. }
  165387. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165388. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  165389. void PNGAPI
  165390. png_read_png(png_structp png_ptr, png_infop info_ptr,
  165391. int transforms,
  165392. voidp params)
  165393. {
  165394. int row;
  165395. if(png_ptr == NULL) return;
  165396. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  165397. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  165398. png_set_invert_alpha(png_ptr);
  165399. #endif
  165400. png_read_info(png_ptr, info_ptr);
  165401. if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
  165402. png_error(png_ptr,"Image is too high to process with png_read_png()");
  165403. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  165404. if (transforms & PNG_TRANSFORM_STRIP_16)
  165405. png_set_strip_16(png_ptr);
  165406. #endif
  165407. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  165408. if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
  165409. png_set_strip_alpha(png_ptr);
  165410. #endif
  165411. #if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
  165412. if (transforms & PNG_TRANSFORM_PACKING)
  165413. png_set_packing(png_ptr);
  165414. #endif
  165415. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  165416. if (transforms & PNG_TRANSFORM_PACKSWAP)
  165417. png_set_packswap(png_ptr);
  165418. #endif
  165419. #if defined(PNG_READ_EXPAND_SUPPORTED)
  165420. if (transforms & PNG_TRANSFORM_EXPAND)
  165421. if ((png_ptr->bit_depth < 8) ||
  165422. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
  165423. (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
  165424. png_set_expand(png_ptr);
  165425. #endif
  165426. #if defined(PNG_READ_INVERT_SUPPORTED)
  165427. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  165428. png_set_invert_mono(png_ptr);
  165429. #endif
  165430. #if defined(PNG_READ_SHIFT_SUPPORTED)
  165431. if ((transforms & PNG_TRANSFORM_SHIFT)
  165432. && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
  165433. {
  165434. png_color_8p sig_bit;
  165435. png_get_sBIT(png_ptr, info_ptr, &sig_bit);
  165436. png_set_shift(png_ptr, sig_bit);
  165437. }
  165438. #endif
  165439. #if defined(PNG_READ_BGR_SUPPORTED)
  165440. if (transforms & PNG_TRANSFORM_BGR)
  165441. png_set_bgr(png_ptr);
  165442. #endif
  165443. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  165444. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  165445. png_set_swap_alpha(png_ptr);
  165446. #endif
  165447. #if defined(PNG_READ_SWAP_SUPPORTED)
  165448. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  165449. png_set_swap(png_ptr);
  165450. #endif
  165451. png_read_update_info(png_ptr, info_ptr);
  165452. #ifdef PNG_FREE_ME_SUPPORTED
  165453. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  165454. #endif
  165455. if(info_ptr->row_pointers == NULL)
  165456. {
  165457. info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
  165458. info_ptr->height * png_sizeof(png_bytep));
  165459. #ifdef PNG_FREE_ME_SUPPORTED
  165460. info_ptr->free_me |= PNG_FREE_ROWS;
  165461. #endif
  165462. for (row = 0; row < (int)info_ptr->height; row++)
  165463. {
  165464. info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
  165465. png_get_rowbytes(png_ptr, info_ptr));
  165466. }
  165467. }
  165468. png_read_image(png_ptr, info_ptr->row_pointers);
  165469. info_ptr->valid |= PNG_INFO_IDAT;
  165470. png_read_end(png_ptr, info_ptr);
  165471. transforms = transforms; /* quiet compiler warnings */
  165472. params = params;
  165473. }
  165474. #endif /* PNG_INFO_IMAGE_SUPPORTED */
  165475. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165476. #endif /* PNG_READ_SUPPORTED */
  165477. /*** End of inlined file: pngread.c ***/
  165478. /*** Start of inlined file: pngpread.c ***/
  165479. #define PNG_INTERNAL
  165480. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165481. #define PNG_READ_SIG_MODE 0
  165482. #define PNG_READ_CHUNK_MODE 1
  165483. #define PNG_READ_IDAT_MODE 2
  165484. #define PNG_SKIP_MODE 3
  165485. #define PNG_READ_tEXt_MODE 4
  165486. #define PNG_READ_zTXt_MODE 5
  165487. #define PNG_READ_DONE_MODE 6
  165488. #define PNG_READ_iTXt_MODE 7
  165489. #define PNG_ERROR_MODE 8
  165490. void PNGAPI
  165491. png_process_data(png_structp png_ptr, png_infop info_ptr,
  165492. png_bytep buffer, png_size_t buffer_size)
  165493. {
  165494. if(png_ptr == NULL) return;
  165495. png_push_restore_buffer(png_ptr, buffer, buffer_size);
  165496. while (png_ptr->buffer_size)
  165497. {
  165498. png_process_some_data(png_ptr, info_ptr);
  165499. }
  165500. }
  165501. void /* PRIVATE */
  165502. png_process_some_data(png_structp png_ptr, png_infop info_ptr)
  165503. {
  165504. if(png_ptr == NULL) return;
  165505. switch (png_ptr->process_mode)
  165506. {
  165507. case PNG_READ_SIG_MODE:
  165508. {
  165509. png_push_read_sig(png_ptr, info_ptr);
  165510. break;
  165511. }
  165512. case PNG_READ_CHUNK_MODE:
  165513. {
  165514. png_push_read_chunk(png_ptr, info_ptr);
  165515. break;
  165516. }
  165517. case PNG_READ_IDAT_MODE:
  165518. {
  165519. png_push_read_IDAT(png_ptr);
  165520. break;
  165521. }
  165522. #if defined(PNG_READ_tEXt_SUPPORTED)
  165523. case PNG_READ_tEXt_MODE:
  165524. {
  165525. png_push_read_tEXt(png_ptr, info_ptr);
  165526. break;
  165527. }
  165528. #endif
  165529. #if defined(PNG_READ_zTXt_SUPPORTED)
  165530. case PNG_READ_zTXt_MODE:
  165531. {
  165532. png_push_read_zTXt(png_ptr, info_ptr);
  165533. break;
  165534. }
  165535. #endif
  165536. #if defined(PNG_READ_iTXt_SUPPORTED)
  165537. case PNG_READ_iTXt_MODE:
  165538. {
  165539. png_push_read_iTXt(png_ptr, info_ptr);
  165540. break;
  165541. }
  165542. #endif
  165543. case PNG_SKIP_MODE:
  165544. {
  165545. png_push_crc_finish(png_ptr);
  165546. break;
  165547. }
  165548. default:
  165549. {
  165550. png_ptr->buffer_size = 0;
  165551. break;
  165552. }
  165553. }
  165554. }
  165555. void /* PRIVATE */
  165556. png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
  165557. {
  165558. png_size_t num_checked = png_ptr->sig_bytes,
  165559. num_to_check = 8 - num_checked;
  165560. if (png_ptr->buffer_size < num_to_check)
  165561. {
  165562. num_to_check = png_ptr->buffer_size;
  165563. }
  165564. png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]),
  165565. num_to_check);
  165566. png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes+num_to_check);
  165567. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  165568. {
  165569. if (num_checked < 4 &&
  165570. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  165571. png_error(png_ptr, "Not a PNG file");
  165572. else
  165573. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  165574. }
  165575. else
  165576. {
  165577. if (png_ptr->sig_bytes >= 8)
  165578. {
  165579. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  165580. }
  165581. }
  165582. }
  165583. void /* PRIVATE */
  165584. png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
  165585. {
  165586. #ifdef PNG_USE_LOCAL_ARRAYS
  165587. PNG_CONST PNG_IHDR;
  165588. PNG_CONST PNG_IDAT;
  165589. PNG_CONST PNG_IEND;
  165590. PNG_CONST PNG_PLTE;
  165591. #if defined(PNG_READ_bKGD_SUPPORTED)
  165592. PNG_CONST PNG_bKGD;
  165593. #endif
  165594. #if defined(PNG_READ_cHRM_SUPPORTED)
  165595. PNG_CONST PNG_cHRM;
  165596. #endif
  165597. #if defined(PNG_READ_gAMA_SUPPORTED)
  165598. PNG_CONST PNG_gAMA;
  165599. #endif
  165600. #if defined(PNG_READ_hIST_SUPPORTED)
  165601. PNG_CONST PNG_hIST;
  165602. #endif
  165603. #if defined(PNG_READ_iCCP_SUPPORTED)
  165604. PNG_CONST PNG_iCCP;
  165605. #endif
  165606. #if defined(PNG_READ_iTXt_SUPPORTED)
  165607. PNG_CONST PNG_iTXt;
  165608. #endif
  165609. #if defined(PNG_READ_oFFs_SUPPORTED)
  165610. PNG_CONST PNG_oFFs;
  165611. #endif
  165612. #if defined(PNG_READ_pCAL_SUPPORTED)
  165613. PNG_CONST PNG_pCAL;
  165614. #endif
  165615. #if defined(PNG_READ_pHYs_SUPPORTED)
  165616. PNG_CONST PNG_pHYs;
  165617. #endif
  165618. #if defined(PNG_READ_sBIT_SUPPORTED)
  165619. PNG_CONST PNG_sBIT;
  165620. #endif
  165621. #if defined(PNG_READ_sCAL_SUPPORTED)
  165622. PNG_CONST PNG_sCAL;
  165623. #endif
  165624. #if defined(PNG_READ_sRGB_SUPPORTED)
  165625. PNG_CONST PNG_sRGB;
  165626. #endif
  165627. #if defined(PNG_READ_sPLT_SUPPORTED)
  165628. PNG_CONST PNG_sPLT;
  165629. #endif
  165630. #if defined(PNG_READ_tEXt_SUPPORTED)
  165631. PNG_CONST PNG_tEXt;
  165632. #endif
  165633. #if defined(PNG_READ_tIME_SUPPORTED)
  165634. PNG_CONST PNG_tIME;
  165635. #endif
  165636. #if defined(PNG_READ_tRNS_SUPPORTED)
  165637. PNG_CONST PNG_tRNS;
  165638. #endif
  165639. #if defined(PNG_READ_zTXt_SUPPORTED)
  165640. PNG_CONST PNG_zTXt;
  165641. #endif
  165642. #endif /* PNG_USE_LOCAL_ARRAYS */
  165643. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  165644. {
  165645. png_byte chunk_length[4];
  165646. if (png_ptr->buffer_size < 8)
  165647. {
  165648. png_push_save_buffer(png_ptr);
  165649. return;
  165650. }
  165651. png_push_fill_buffer(png_ptr, chunk_length, 4);
  165652. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  165653. png_reset_crc(png_ptr);
  165654. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165655. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  165656. }
  165657. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165658. if(png_ptr->mode & PNG_AFTER_IDAT)
  165659. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  165660. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 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_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);
  165668. }
  165669. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165670. {
  165671. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165672. {
  165673. png_push_save_buffer(png_ptr);
  165674. return;
  165675. }
  165676. png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length);
  165677. png_ptr->process_mode = PNG_READ_DONE_MODE;
  165678. png_push_have_end(png_ptr, info_ptr);
  165679. }
  165680. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165681. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165682. {
  165683. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165684. {
  165685. png_push_save_buffer(png_ptr);
  165686. return;
  165687. }
  165688. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165689. png_ptr->mode |= PNG_HAVE_IDAT;
  165690. png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  165691. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165692. png_ptr->mode |= PNG_HAVE_PLTE;
  165693. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165694. {
  165695. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165696. png_error(png_ptr, "Missing IHDR before IDAT");
  165697. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165698. !(png_ptr->mode & PNG_HAVE_PLTE))
  165699. png_error(png_ptr, "Missing PLTE before IDAT");
  165700. }
  165701. }
  165702. #endif
  165703. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165704. {
  165705. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165706. {
  165707. png_push_save_buffer(png_ptr);
  165708. return;
  165709. }
  165710. png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
  165711. }
  165712. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165713. {
  165714. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165715. png_error(png_ptr, "Missing IHDR before IDAT");
  165716. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165717. !(png_ptr->mode & PNG_HAVE_PLTE))
  165718. png_error(png_ptr, "Missing PLTE before IDAT");
  165719. if (png_ptr->mode & PNG_HAVE_IDAT)
  165720. {
  165721. if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165722. if (png_ptr->push_length == 0)
  165723. return;
  165724. if (png_ptr->mode & PNG_AFTER_IDAT)
  165725. png_error(png_ptr, "Too many IDAT's found");
  165726. }
  165727. png_ptr->idat_size = png_ptr->push_length;
  165728. png_ptr->mode |= PNG_HAVE_IDAT;
  165729. png_ptr->process_mode = PNG_READ_IDAT_MODE;
  165730. png_push_have_info(png_ptr, info_ptr);
  165731. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  165732. png_ptr->zstream.next_out = png_ptr->row_buf;
  165733. return;
  165734. }
  165735. #if defined(PNG_READ_gAMA_SUPPORTED)
  165736. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165737. {
  165738. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165739. {
  165740. png_push_save_buffer(png_ptr);
  165741. return;
  165742. }
  165743. png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length);
  165744. }
  165745. #endif
  165746. #if defined(PNG_READ_sBIT_SUPPORTED)
  165747. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165748. {
  165749. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165750. {
  165751. png_push_save_buffer(png_ptr);
  165752. return;
  165753. }
  165754. png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length);
  165755. }
  165756. #endif
  165757. #if defined(PNG_READ_cHRM_SUPPORTED)
  165758. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165759. {
  165760. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165761. {
  165762. png_push_save_buffer(png_ptr);
  165763. return;
  165764. }
  165765. png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length);
  165766. }
  165767. #endif
  165768. #if defined(PNG_READ_sRGB_SUPPORTED)
  165769. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165770. {
  165771. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165772. {
  165773. png_push_save_buffer(png_ptr);
  165774. return;
  165775. }
  165776. png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);
  165777. }
  165778. #endif
  165779. #if defined(PNG_READ_iCCP_SUPPORTED)
  165780. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165781. {
  165782. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165783. {
  165784. png_push_save_buffer(png_ptr);
  165785. return;
  165786. }
  165787. png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length);
  165788. }
  165789. #endif
  165790. #if defined(PNG_READ_sPLT_SUPPORTED)
  165791. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165792. {
  165793. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165794. {
  165795. png_push_save_buffer(png_ptr);
  165796. return;
  165797. }
  165798. png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length);
  165799. }
  165800. #endif
  165801. #if defined(PNG_READ_tRNS_SUPPORTED)
  165802. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165803. {
  165804. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165805. {
  165806. png_push_save_buffer(png_ptr);
  165807. return;
  165808. }
  165809. png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length);
  165810. }
  165811. #endif
  165812. #if defined(PNG_READ_bKGD_SUPPORTED)
  165813. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165814. {
  165815. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165816. {
  165817. png_push_save_buffer(png_ptr);
  165818. return;
  165819. }
  165820. png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length);
  165821. }
  165822. #endif
  165823. #if defined(PNG_READ_hIST_SUPPORTED)
  165824. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165825. {
  165826. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165827. {
  165828. png_push_save_buffer(png_ptr);
  165829. return;
  165830. }
  165831. png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length);
  165832. }
  165833. #endif
  165834. #if defined(PNG_READ_pHYs_SUPPORTED)
  165835. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165836. {
  165837. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165838. {
  165839. png_push_save_buffer(png_ptr);
  165840. return;
  165841. }
  165842. png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length);
  165843. }
  165844. #endif
  165845. #if defined(PNG_READ_oFFs_SUPPORTED)
  165846. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165847. {
  165848. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165849. {
  165850. png_push_save_buffer(png_ptr);
  165851. return;
  165852. }
  165853. png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length);
  165854. }
  165855. #endif
  165856. #if defined(PNG_READ_pCAL_SUPPORTED)
  165857. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165858. {
  165859. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165860. {
  165861. png_push_save_buffer(png_ptr);
  165862. return;
  165863. }
  165864. png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length);
  165865. }
  165866. #endif
  165867. #if defined(PNG_READ_sCAL_SUPPORTED)
  165868. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165869. {
  165870. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165871. {
  165872. png_push_save_buffer(png_ptr);
  165873. return;
  165874. }
  165875. png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length);
  165876. }
  165877. #endif
  165878. #if defined(PNG_READ_tIME_SUPPORTED)
  165879. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165880. {
  165881. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165882. {
  165883. png_push_save_buffer(png_ptr);
  165884. return;
  165885. }
  165886. png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length);
  165887. }
  165888. #endif
  165889. #if defined(PNG_READ_tEXt_SUPPORTED)
  165890. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165891. {
  165892. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165893. {
  165894. png_push_save_buffer(png_ptr);
  165895. return;
  165896. }
  165897. png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
  165898. }
  165899. #endif
  165900. #if defined(PNG_READ_zTXt_SUPPORTED)
  165901. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165902. {
  165903. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165904. {
  165905. png_push_save_buffer(png_ptr);
  165906. return;
  165907. }
  165908. png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
  165909. }
  165910. #endif
  165911. #if defined(PNG_READ_iTXt_SUPPORTED)
  165912. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165913. {
  165914. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165915. {
  165916. png_push_save_buffer(png_ptr);
  165917. return;
  165918. }
  165919. png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
  165920. }
  165921. #endif
  165922. else
  165923. {
  165924. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165925. {
  165926. png_push_save_buffer(png_ptr);
  165927. return;
  165928. }
  165929. png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  165930. }
  165931. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  165932. }
  165933. void /* PRIVATE */
  165934. png_push_crc_skip(png_structp png_ptr, png_uint_32 skip)
  165935. {
  165936. png_ptr->process_mode = PNG_SKIP_MODE;
  165937. png_ptr->skip_length = skip;
  165938. }
  165939. void /* PRIVATE */
  165940. png_push_crc_finish(png_structp png_ptr)
  165941. {
  165942. if (png_ptr->skip_length && png_ptr->save_buffer_size)
  165943. {
  165944. png_size_t save_size;
  165945. if (png_ptr->skip_length < (png_uint_32)png_ptr->save_buffer_size)
  165946. save_size = (png_size_t)png_ptr->skip_length;
  165947. else
  165948. save_size = png_ptr->save_buffer_size;
  165949. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  165950. png_ptr->skip_length -= save_size;
  165951. png_ptr->buffer_size -= save_size;
  165952. png_ptr->save_buffer_size -= save_size;
  165953. png_ptr->save_buffer_ptr += save_size;
  165954. }
  165955. if (png_ptr->skip_length && png_ptr->current_buffer_size)
  165956. {
  165957. png_size_t save_size;
  165958. if (png_ptr->skip_length < (png_uint_32)png_ptr->current_buffer_size)
  165959. save_size = (png_size_t)png_ptr->skip_length;
  165960. else
  165961. save_size = png_ptr->current_buffer_size;
  165962. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  165963. png_ptr->skip_length -= save_size;
  165964. png_ptr->buffer_size -= save_size;
  165965. png_ptr->current_buffer_size -= save_size;
  165966. png_ptr->current_buffer_ptr += save_size;
  165967. }
  165968. if (!png_ptr->skip_length)
  165969. {
  165970. if (png_ptr->buffer_size < 4)
  165971. {
  165972. png_push_save_buffer(png_ptr);
  165973. return;
  165974. }
  165975. png_crc_finish(png_ptr, 0);
  165976. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  165977. }
  165978. }
  165979. void PNGAPI
  165980. png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
  165981. {
  165982. png_bytep ptr;
  165983. if(png_ptr == NULL) return;
  165984. ptr = buffer;
  165985. if (png_ptr->save_buffer_size)
  165986. {
  165987. png_size_t save_size;
  165988. if (length < png_ptr->save_buffer_size)
  165989. save_size = length;
  165990. else
  165991. save_size = png_ptr->save_buffer_size;
  165992. png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
  165993. length -= save_size;
  165994. ptr += save_size;
  165995. png_ptr->buffer_size -= save_size;
  165996. png_ptr->save_buffer_size -= save_size;
  165997. png_ptr->save_buffer_ptr += save_size;
  165998. }
  165999. if (length && png_ptr->current_buffer_size)
  166000. {
  166001. png_size_t save_size;
  166002. if (length < png_ptr->current_buffer_size)
  166003. save_size = length;
  166004. else
  166005. save_size = png_ptr->current_buffer_size;
  166006. png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
  166007. png_ptr->buffer_size -= save_size;
  166008. png_ptr->current_buffer_size -= save_size;
  166009. png_ptr->current_buffer_ptr += save_size;
  166010. }
  166011. }
  166012. void /* PRIVATE */
  166013. png_push_save_buffer(png_structp png_ptr)
  166014. {
  166015. if (png_ptr->save_buffer_size)
  166016. {
  166017. if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
  166018. {
  166019. png_size_t i,istop;
  166020. png_bytep sp;
  166021. png_bytep dp;
  166022. istop = png_ptr->save_buffer_size;
  166023. for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer;
  166024. i < istop; i++, sp++, dp++)
  166025. {
  166026. *dp = *sp;
  166027. }
  166028. }
  166029. }
  166030. if (png_ptr->save_buffer_size + png_ptr->current_buffer_size >
  166031. png_ptr->save_buffer_max)
  166032. {
  166033. png_size_t new_max;
  166034. png_bytep old_buffer;
  166035. if (png_ptr->save_buffer_size > PNG_SIZE_MAX -
  166036. (png_ptr->current_buffer_size + 256))
  166037. {
  166038. png_error(png_ptr, "Potential overflow of save_buffer");
  166039. }
  166040. new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
  166041. old_buffer = png_ptr->save_buffer;
  166042. png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr,
  166043. (png_uint_32)new_max);
  166044. png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
  166045. png_free(png_ptr, old_buffer);
  166046. png_ptr->save_buffer_max = new_max;
  166047. }
  166048. if (png_ptr->current_buffer_size)
  166049. {
  166050. png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
  166051. png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);
  166052. png_ptr->save_buffer_size += png_ptr->current_buffer_size;
  166053. png_ptr->current_buffer_size = 0;
  166054. }
  166055. png_ptr->save_buffer_ptr = png_ptr->save_buffer;
  166056. png_ptr->buffer_size = 0;
  166057. }
  166058. void /* PRIVATE */
  166059. png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
  166060. png_size_t buffer_length)
  166061. {
  166062. png_ptr->current_buffer = buffer;
  166063. png_ptr->current_buffer_size = buffer_length;
  166064. png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size;
  166065. png_ptr->current_buffer_ptr = png_ptr->current_buffer;
  166066. }
  166067. void /* PRIVATE */
  166068. png_push_read_IDAT(png_structp png_ptr)
  166069. {
  166070. #ifdef PNG_USE_LOCAL_ARRAYS
  166071. PNG_CONST PNG_IDAT;
  166072. #endif
  166073. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  166074. {
  166075. png_byte chunk_length[4];
  166076. if (png_ptr->buffer_size < 8)
  166077. {
  166078. png_push_save_buffer(png_ptr);
  166079. return;
  166080. }
  166081. png_push_fill_buffer(png_ptr, chunk_length, 4);
  166082. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  166083. png_reset_crc(png_ptr);
  166084. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  166085. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  166086. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166087. {
  166088. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166089. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166090. png_error(png_ptr, "Not enough compressed data");
  166091. return;
  166092. }
  166093. png_ptr->idat_size = png_ptr->push_length;
  166094. }
  166095. if (png_ptr->idat_size && png_ptr->save_buffer_size)
  166096. {
  166097. png_size_t save_size;
  166098. if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size)
  166099. {
  166100. save_size = (png_size_t)png_ptr->idat_size;
  166101. if((png_uint_32)save_size != png_ptr->idat_size)
  166102. png_error(png_ptr, "save_size overflowed in pngpread");
  166103. }
  166104. else
  166105. save_size = png_ptr->save_buffer_size;
  166106. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166107. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166108. png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166109. png_ptr->idat_size -= save_size;
  166110. png_ptr->buffer_size -= save_size;
  166111. png_ptr->save_buffer_size -= save_size;
  166112. png_ptr->save_buffer_ptr += save_size;
  166113. }
  166114. if (png_ptr->idat_size && png_ptr->current_buffer_size)
  166115. {
  166116. png_size_t save_size;
  166117. if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size)
  166118. {
  166119. save_size = (png_size_t)png_ptr->idat_size;
  166120. if((png_uint_32)save_size != png_ptr->idat_size)
  166121. png_error(png_ptr, "save_size overflowed in pngpread");
  166122. }
  166123. else
  166124. save_size = png_ptr->current_buffer_size;
  166125. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166126. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166127. png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166128. png_ptr->idat_size -= save_size;
  166129. png_ptr->buffer_size -= save_size;
  166130. png_ptr->current_buffer_size -= save_size;
  166131. png_ptr->current_buffer_ptr += save_size;
  166132. }
  166133. if (!png_ptr->idat_size)
  166134. {
  166135. if (png_ptr->buffer_size < 4)
  166136. {
  166137. png_push_save_buffer(png_ptr);
  166138. return;
  166139. }
  166140. png_crc_finish(png_ptr, 0);
  166141. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  166142. png_ptr->mode |= PNG_AFTER_IDAT;
  166143. }
  166144. }
  166145. void /* PRIVATE */
  166146. png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
  166147. png_size_t buffer_length)
  166148. {
  166149. int ret;
  166150. if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length)
  166151. png_error(png_ptr, "Extra compression data");
  166152. png_ptr->zstream.next_in = buffer;
  166153. png_ptr->zstream.avail_in = (uInt)buffer_length;
  166154. for(;;)
  166155. {
  166156. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166157. if (ret != Z_OK)
  166158. {
  166159. if (ret == Z_STREAM_END)
  166160. {
  166161. if (png_ptr->zstream.avail_in)
  166162. png_error(png_ptr, "Extra compressed data");
  166163. if (!(png_ptr->zstream.avail_out))
  166164. {
  166165. png_push_process_row(png_ptr);
  166166. }
  166167. png_ptr->mode |= PNG_AFTER_IDAT;
  166168. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166169. break;
  166170. }
  166171. else if (ret == Z_BUF_ERROR)
  166172. break;
  166173. else
  166174. png_error(png_ptr, "Decompression Error");
  166175. }
  166176. if (!(png_ptr->zstream.avail_out))
  166177. {
  166178. if ((
  166179. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166180. png_ptr->interlaced && png_ptr->pass > 6) ||
  166181. (!png_ptr->interlaced &&
  166182. #endif
  166183. png_ptr->row_number == png_ptr->num_rows))
  166184. {
  166185. if (png_ptr->zstream.avail_in)
  166186. {
  166187. png_warning(png_ptr, "Too much data in IDAT chunks");
  166188. }
  166189. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166190. break;
  166191. }
  166192. png_push_process_row(png_ptr);
  166193. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  166194. png_ptr->zstream.next_out = png_ptr->row_buf;
  166195. }
  166196. else
  166197. break;
  166198. }
  166199. }
  166200. void /* PRIVATE */
  166201. png_push_process_row(png_structp png_ptr)
  166202. {
  166203. png_ptr->row_info.color_type = png_ptr->color_type;
  166204. png_ptr->row_info.width = png_ptr->iwidth;
  166205. png_ptr->row_info.channels = png_ptr->channels;
  166206. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  166207. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  166208. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  166209. png_ptr->row_info.width);
  166210. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  166211. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  166212. (int)(png_ptr->row_buf[0]));
  166213. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  166214. png_ptr->rowbytes + 1);
  166215. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  166216. png_do_read_transformations(png_ptr);
  166217. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166218. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  166219. {
  166220. if (png_ptr->pass < 6)
  166221. png_do_read_interlace(png_ptr);
  166222. switch (png_ptr->pass)
  166223. {
  166224. case 0:
  166225. {
  166226. int i;
  166227. for (i = 0; i < 8 && png_ptr->pass == 0; i++)
  166228. {
  166229. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166230. png_read_push_finish_row(png_ptr); /* updates png_ptr->pass */
  166231. }
  166232. if (png_ptr->pass == 2) /* pass 1 might be empty */
  166233. {
  166234. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166235. {
  166236. png_push_have_row(png_ptr, png_bytep_NULL);
  166237. png_read_push_finish_row(png_ptr);
  166238. }
  166239. }
  166240. if (png_ptr->pass == 4 && png_ptr->height <= 4)
  166241. {
  166242. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166243. {
  166244. png_push_have_row(png_ptr, png_bytep_NULL);
  166245. png_read_push_finish_row(png_ptr);
  166246. }
  166247. }
  166248. if (png_ptr->pass == 6 && png_ptr->height <= 4)
  166249. {
  166250. png_push_have_row(png_ptr, png_bytep_NULL);
  166251. png_read_push_finish_row(png_ptr);
  166252. }
  166253. break;
  166254. }
  166255. case 1:
  166256. {
  166257. int i;
  166258. for (i = 0; i < 8 && png_ptr->pass == 1; i++)
  166259. {
  166260. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166261. png_read_push_finish_row(png_ptr);
  166262. }
  166263. if (png_ptr->pass == 2) /* skip top 4 generated rows */
  166264. {
  166265. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166266. {
  166267. png_push_have_row(png_ptr, png_bytep_NULL);
  166268. png_read_push_finish_row(png_ptr);
  166269. }
  166270. }
  166271. break;
  166272. }
  166273. case 2:
  166274. {
  166275. int i;
  166276. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166277. {
  166278. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166279. png_read_push_finish_row(png_ptr);
  166280. }
  166281. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166282. {
  166283. png_push_have_row(png_ptr, png_bytep_NULL);
  166284. png_read_push_finish_row(png_ptr);
  166285. }
  166286. if (png_ptr->pass == 4) /* pass 3 might be empty */
  166287. {
  166288. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166289. {
  166290. png_push_have_row(png_ptr, png_bytep_NULL);
  166291. png_read_push_finish_row(png_ptr);
  166292. }
  166293. }
  166294. break;
  166295. }
  166296. case 3:
  166297. {
  166298. int i;
  166299. for (i = 0; i < 4 && png_ptr->pass == 3; i++)
  166300. {
  166301. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166302. png_read_push_finish_row(png_ptr);
  166303. }
  166304. if (png_ptr->pass == 4) /* skip top two generated rows */
  166305. {
  166306. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166307. {
  166308. png_push_have_row(png_ptr, png_bytep_NULL);
  166309. png_read_push_finish_row(png_ptr);
  166310. }
  166311. }
  166312. break;
  166313. }
  166314. case 4:
  166315. {
  166316. int i;
  166317. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166318. {
  166319. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166320. png_read_push_finish_row(png_ptr);
  166321. }
  166322. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166323. {
  166324. png_push_have_row(png_ptr, png_bytep_NULL);
  166325. png_read_push_finish_row(png_ptr);
  166326. }
  166327. if (png_ptr->pass == 6) /* pass 5 might be empty */
  166328. {
  166329. png_push_have_row(png_ptr, png_bytep_NULL);
  166330. png_read_push_finish_row(png_ptr);
  166331. }
  166332. break;
  166333. }
  166334. case 5:
  166335. {
  166336. int i;
  166337. for (i = 0; i < 2 && png_ptr->pass == 5; i++)
  166338. {
  166339. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166340. png_read_push_finish_row(png_ptr);
  166341. }
  166342. if (png_ptr->pass == 6) /* skip top generated row */
  166343. {
  166344. png_push_have_row(png_ptr, png_bytep_NULL);
  166345. png_read_push_finish_row(png_ptr);
  166346. }
  166347. break;
  166348. }
  166349. case 6:
  166350. {
  166351. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166352. png_read_push_finish_row(png_ptr);
  166353. if (png_ptr->pass != 6)
  166354. break;
  166355. png_push_have_row(png_ptr, png_bytep_NULL);
  166356. png_read_push_finish_row(png_ptr);
  166357. }
  166358. }
  166359. }
  166360. else
  166361. #endif
  166362. {
  166363. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166364. png_read_push_finish_row(png_ptr);
  166365. }
  166366. }
  166367. void /* PRIVATE */
  166368. png_read_push_finish_row(png_structp png_ptr)
  166369. {
  166370. #ifdef PNG_USE_LOCAL_ARRAYS
  166371. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  166372. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  166373. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  166374. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  166375. #endif
  166376. png_ptr->row_number++;
  166377. if (png_ptr->row_number < png_ptr->num_rows)
  166378. return;
  166379. if (png_ptr->interlaced)
  166380. {
  166381. png_ptr->row_number = 0;
  166382. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  166383. png_ptr->rowbytes + 1);
  166384. do
  166385. {
  166386. png_ptr->pass++;
  166387. if ((png_ptr->pass == 1 && png_ptr->width < 5) ||
  166388. (png_ptr->pass == 3 && png_ptr->width < 3) ||
  166389. (png_ptr->pass == 5 && png_ptr->width < 2))
  166390. png_ptr->pass++;
  166391. if (png_ptr->pass > 7)
  166392. png_ptr->pass--;
  166393. if (png_ptr->pass >= 7)
  166394. break;
  166395. png_ptr->iwidth = (png_ptr->width +
  166396. png_pass_inc[png_ptr->pass] - 1 -
  166397. png_pass_start[png_ptr->pass]) /
  166398. png_pass_inc[png_ptr->pass];
  166399. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  166400. png_ptr->iwidth) + 1;
  166401. if (png_ptr->transformations & PNG_INTERLACE)
  166402. break;
  166403. png_ptr->num_rows = (png_ptr->height +
  166404. png_pass_yinc[png_ptr->pass] - 1 -
  166405. png_pass_ystart[png_ptr->pass]) /
  166406. png_pass_yinc[png_ptr->pass];
  166407. } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
  166408. }
  166409. }
  166410. #if defined(PNG_READ_tEXt_SUPPORTED)
  166411. void /* PRIVATE */
  166412. png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166413. length)
  166414. {
  166415. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166416. {
  166417. png_error(png_ptr, "Out of place tEXt");
  166418. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166419. }
  166420. #ifdef PNG_MAX_MALLOC_64K
  166421. png_ptr->skip_length = 0; /* This may not be necessary */
  166422. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  166423. {
  166424. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  166425. png_ptr->skip_length = length - (png_uint_32)65535L;
  166426. length = (png_uint_32)65535L;
  166427. }
  166428. #endif
  166429. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166430. (png_uint_32)(length+1));
  166431. png_ptr->current_text[length] = '\0';
  166432. png_ptr->current_text_ptr = png_ptr->current_text;
  166433. png_ptr->current_text_size = (png_size_t)length;
  166434. png_ptr->current_text_left = (png_size_t)length;
  166435. png_ptr->process_mode = PNG_READ_tEXt_MODE;
  166436. }
  166437. void /* PRIVATE */
  166438. png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
  166439. {
  166440. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166441. {
  166442. png_size_t text_size;
  166443. if (png_ptr->buffer_size < png_ptr->current_text_left)
  166444. text_size = png_ptr->buffer_size;
  166445. else
  166446. text_size = png_ptr->current_text_left;
  166447. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166448. png_ptr->current_text_left -= text_size;
  166449. png_ptr->current_text_ptr += text_size;
  166450. }
  166451. if (!(png_ptr->current_text_left))
  166452. {
  166453. png_textp text_ptr;
  166454. png_charp text;
  166455. png_charp key;
  166456. int ret;
  166457. if (png_ptr->buffer_size < 4)
  166458. {
  166459. png_push_save_buffer(png_ptr);
  166460. return;
  166461. }
  166462. png_push_crc_finish(png_ptr);
  166463. #if defined(PNG_MAX_MALLOC_64K)
  166464. if (png_ptr->skip_length)
  166465. return;
  166466. #endif
  166467. key = png_ptr->current_text;
  166468. for (text = key; *text; text++)
  166469. ;
  166470. if (text < key + png_ptr->current_text_size)
  166471. text++;
  166472. text_ptr = (png_textp)png_malloc(png_ptr,
  166473. (png_uint_32)png_sizeof(png_text));
  166474. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  166475. text_ptr->key = key;
  166476. #ifdef PNG_iTXt_SUPPORTED
  166477. text_ptr->lang = NULL;
  166478. text_ptr->lang_key = NULL;
  166479. #endif
  166480. text_ptr->text = text;
  166481. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166482. png_free(png_ptr, key);
  166483. png_free(png_ptr, text_ptr);
  166484. png_ptr->current_text = NULL;
  166485. if (ret)
  166486. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  166487. }
  166488. }
  166489. #endif
  166490. #if defined(PNG_READ_zTXt_SUPPORTED)
  166491. void /* PRIVATE */
  166492. png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166493. length)
  166494. {
  166495. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166496. {
  166497. png_error(png_ptr, "Out of place zTXt");
  166498. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166499. }
  166500. #ifdef PNG_MAX_MALLOC_64K
  166501. if (length > (png_uint_32)65535L)
  166502. {
  166503. png_warning(png_ptr, "zTXt chunk too large to fit in memory");
  166504. png_push_crc_skip(png_ptr, length);
  166505. return;
  166506. }
  166507. #endif
  166508. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166509. (png_uint_32)(length+1));
  166510. png_ptr->current_text[length] = '\0';
  166511. png_ptr->current_text_ptr = png_ptr->current_text;
  166512. png_ptr->current_text_size = (png_size_t)length;
  166513. png_ptr->current_text_left = (png_size_t)length;
  166514. png_ptr->process_mode = PNG_READ_zTXt_MODE;
  166515. }
  166516. void /* PRIVATE */
  166517. png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
  166518. {
  166519. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166520. {
  166521. png_size_t text_size;
  166522. if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left)
  166523. text_size = png_ptr->buffer_size;
  166524. else
  166525. text_size = png_ptr->current_text_left;
  166526. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166527. png_ptr->current_text_left -= text_size;
  166528. png_ptr->current_text_ptr += text_size;
  166529. }
  166530. if (!(png_ptr->current_text_left))
  166531. {
  166532. png_textp text_ptr;
  166533. png_charp text;
  166534. png_charp key;
  166535. int ret;
  166536. png_size_t text_size, key_size;
  166537. if (png_ptr->buffer_size < 4)
  166538. {
  166539. png_push_save_buffer(png_ptr);
  166540. return;
  166541. }
  166542. png_push_crc_finish(png_ptr);
  166543. key = png_ptr->current_text;
  166544. for (text = key; *text; text++)
  166545. ;
  166546. if (text >= key + png_ptr->current_text_size)
  166547. {
  166548. png_ptr->current_text = NULL;
  166549. png_free(png_ptr, key);
  166550. return;
  166551. }
  166552. text++;
  166553. if (*text != PNG_TEXT_COMPRESSION_zTXt) /* check compression byte */
  166554. {
  166555. png_ptr->current_text = NULL;
  166556. png_free(png_ptr, key);
  166557. return;
  166558. }
  166559. text++;
  166560. png_ptr->zstream.next_in = (png_bytep )text;
  166561. png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size -
  166562. (text - key));
  166563. png_ptr->zstream.next_out = png_ptr->zbuf;
  166564. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  166565. key_size = text - key;
  166566. text_size = 0;
  166567. text = NULL;
  166568. ret = Z_STREAM_END;
  166569. while (png_ptr->zstream.avail_in)
  166570. {
  166571. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166572. if (ret != Z_OK && ret != Z_STREAM_END)
  166573. {
  166574. inflateReset(&png_ptr->zstream);
  166575. png_ptr->zstream.avail_in = 0;
  166576. png_ptr->current_text = NULL;
  166577. png_free(png_ptr, key);
  166578. png_free(png_ptr, text);
  166579. return;
  166580. }
  166581. if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END)
  166582. {
  166583. if (text == NULL)
  166584. {
  166585. text = (png_charp)png_malloc(png_ptr,
  166586. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  166587. + key_size + 1));
  166588. png_memcpy(text + key_size, png_ptr->zbuf,
  166589. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  166590. png_memcpy(text, key, key_size);
  166591. text_size = key_size + png_ptr->zbuf_size -
  166592. png_ptr->zstream.avail_out;
  166593. *(text + text_size) = '\0';
  166594. }
  166595. else
  166596. {
  166597. png_charp tmp;
  166598. tmp = text;
  166599. text = (png_charp)png_malloc(png_ptr, text_size +
  166600. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  166601. + 1));
  166602. png_memcpy(text, tmp, text_size);
  166603. png_free(png_ptr, tmp);
  166604. png_memcpy(text + text_size, png_ptr->zbuf,
  166605. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  166606. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  166607. *(text + text_size) = '\0';
  166608. }
  166609. if (ret != Z_STREAM_END)
  166610. {
  166611. png_ptr->zstream.next_out = png_ptr->zbuf;
  166612. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  166613. }
  166614. }
  166615. else
  166616. {
  166617. break;
  166618. }
  166619. if (ret == Z_STREAM_END)
  166620. break;
  166621. }
  166622. inflateReset(&png_ptr->zstream);
  166623. png_ptr->zstream.avail_in = 0;
  166624. if (ret != Z_STREAM_END)
  166625. {
  166626. png_ptr->current_text = NULL;
  166627. png_free(png_ptr, key);
  166628. png_free(png_ptr, text);
  166629. return;
  166630. }
  166631. png_ptr->current_text = NULL;
  166632. png_free(png_ptr, key);
  166633. key = text;
  166634. text += key_size;
  166635. text_ptr = (png_textp)png_malloc(png_ptr,
  166636. (png_uint_32)png_sizeof(png_text));
  166637. text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
  166638. text_ptr->key = key;
  166639. #ifdef PNG_iTXt_SUPPORTED
  166640. text_ptr->lang = NULL;
  166641. text_ptr->lang_key = NULL;
  166642. #endif
  166643. text_ptr->text = text;
  166644. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166645. png_free(png_ptr, key);
  166646. png_free(png_ptr, text_ptr);
  166647. if (ret)
  166648. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  166649. }
  166650. }
  166651. #endif
  166652. #if defined(PNG_READ_iTXt_SUPPORTED)
  166653. void /* PRIVATE */
  166654. png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166655. length)
  166656. {
  166657. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166658. {
  166659. png_error(png_ptr, "Out of place iTXt");
  166660. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166661. }
  166662. #ifdef PNG_MAX_MALLOC_64K
  166663. png_ptr->skip_length = 0; /* This may not be necessary */
  166664. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  166665. {
  166666. png_warning(png_ptr, "iTXt chunk too large to fit in memory");
  166667. png_ptr->skip_length = length - (png_uint_32)65535L;
  166668. length = (png_uint_32)65535L;
  166669. }
  166670. #endif
  166671. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166672. (png_uint_32)(length+1));
  166673. png_ptr->current_text[length] = '\0';
  166674. png_ptr->current_text_ptr = png_ptr->current_text;
  166675. png_ptr->current_text_size = (png_size_t)length;
  166676. png_ptr->current_text_left = (png_size_t)length;
  166677. png_ptr->process_mode = PNG_READ_iTXt_MODE;
  166678. }
  166679. void /* PRIVATE */
  166680. png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
  166681. {
  166682. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166683. {
  166684. png_size_t text_size;
  166685. if (png_ptr->buffer_size < png_ptr->current_text_left)
  166686. text_size = png_ptr->buffer_size;
  166687. else
  166688. text_size = png_ptr->current_text_left;
  166689. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166690. png_ptr->current_text_left -= text_size;
  166691. png_ptr->current_text_ptr += text_size;
  166692. }
  166693. if (!(png_ptr->current_text_left))
  166694. {
  166695. png_textp text_ptr;
  166696. png_charp key;
  166697. int comp_flag;
  166698. png_charp lang;
  166699. png_charp lang_key;
  166700. png_charp text;
  166701. int ret;
  166702. if (png_ptr->buffer_size < 4)
  166703. {
  166704. png_push_save_buffer(png_ptr);
  166705. return;
  166706. }
  166707. png_push_crc_finish(png_ptr);
  166708. #if defined(PNG_MAX_MALLOC_64K)
  166709. if (png_ptr->skip_length)
  166710. return;
  166711. #endif
  166712. key = png_ptr->current_text;
  166713. for (lang = key; *lang; lang++)
  166714. ;
  166715. if (lang < key + png_ptr->current_text_size - 3)
  166716. lang++;
  166717. comp_flag = *lang++;
  166718. lang++; /* skip comp_type, always zero */
  166719. for (lang_key = lang; *lang_key; lang_key++)
  166720. ;
  166721. lang_key++; /* skip NUL separator */
  166722. text=lang_key;
  166723. if (lang_key < key + png_ptr->current_text_size - 1)
  166724. {
  166725. for (; *text; text++)
  166726. ;
  166727. }
  166728. if (text < key + png_ptr->current_text_size)
  166729. text++;
  166730. text_ptr = (png_textp)png_malloc(png_ptr,
  166731. (png_uint_32)png_sizeof(png_text));
  166732. text_ptr->compression = comp_flag + 2;
  166733. text_ptr->key = key;
  166734. text_ptr->lang = lang;
  166735. text_ptr->lang_key = lang_key;
  166736. text_ptr->text = text;
  166737. text_ptr->text_length = 0;
  166738. text_ptr->itxt_length = png_strlen(text);
  166739. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166740. png_ptr->current_text = NULL;
  166741. png_free(png_ptr, text_ptr);
  166742. if (ret)
  166743. png_warning(png_ptr, "Insufficient memory to store iTXt chunk.");
  166744. }
  166745. }
  166746. #endif
  166747. void /* PRIVATE */
  166748. png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166749. length)
  166750. {
  166751. png_uint_32 skip=0;
  166752. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  166753. if (!(png_ptr->chunk_name[0] & 0x20))
  166754. {
  166755. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  166756. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  166757. PNG_HANDLE_CHUNK_ALWAYS
  166758. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  166759. && png_ptr->read_user_chunk_fn == NULL
  166760. #endif
  166761. )
  166762. #endif
  166763. png_chunk_error(png_ptr, "unknown critical chunk");
  166764. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166765. }
  166766. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  166767. if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
  166768. {
  166769. #ifdef PNG_MAX_MALLOC_64K
  166770. if (length > (png_uint_32)65535L)
  166771. {
  166772. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  166773. skip = length - (png_uint_32)65535L;
  166774. length = (png_uint_32)65535L;
  166775. }
  166776. #endif
  166777. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  166778. (png_charp)png_ptr->chunk_name, 5);
  166779. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  166780. png_ptr->unknown_chunk.size = (png_size_t)length;
  166781. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  166782. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  166783. if(png_ptr->read_user_chunk_fn != NULL)
  166784. {
  166785. int ret;
  166786. ret = (*(png_ptr->read_user_chunk_fn))
  166787. (png_ptr, &png_ptr->unknown_chunk);
  166788. if (ret < 0)
  166789. png_chunk_error(png_ptr, "error in user chunk");
  166790. if (ret == 0)
  166791. {
  166792. if (!(png_ptr->chunk_name[0] & 0x20))
  166793. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  166794. PNG_HANDLE_CHUNK_ALWAYS)
  166795. png_chunk_error(png_ptr, "unknown critical chunk");
  166796. png_set_unknown_chunks(png_ptr, info_ptr,
  166797. &png_ptr->unknown_chunk, 1);
  166798. }
  166799. }
  166800. #else
  166801. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  166802. #endif
  166803. png_free(png_ptr, png_ptr->unknown_chunk.data);
  166804. png_ptr->unknown_chunk.data = NULL;
  166805. }
  166806. else
  166807. #endif
  166808. skip=length;
  166809. png_push_crc_skip(png_ptr, skip);
  166810. }
  166811. void /* PRIVATE */
  166812. png_push_have_info(png_structp png_ptr, png_infop info_ptr)
  166813. {
  166814. if (png_ptr->info_fn != NULL)
  166815. (*(png_ptr->info_fn))(png_ptr, info_ptr);
  166816. }
  166817. void /* PRIVATE */
  166818. png_push_have_end(png_structp png_ptr, png_infop info_ptr)
  166819. {
  166820. if (png_ptr->end_fn != NULL)
  166821. (*(png_ptr->end_fn))(png_ptr, info_ptr);
  166822. }
  166823. void /* PRIVATE */
  166824. png_push_have_row(png_structp png_ptr, png_bytep row)
  166825. {
  166826. if (png_ptr->row_fn != NULL)
  166827. (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
  166828. (int)png_ptr->pass);
  166829. }
  166830. void PNGAPI
  166831. png_progressive_combine_row (png_structp png_ptr,
  166832. png_bytep old_row, png_bytep new_row)
  166833. {
  166834. #ifdef PNG_USE_LOCAL_ARRAYS
  166835. PNG_CONST int FARDATA png_pass_dsp_mask[7] =
  166836. {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  166837. #endif
  166838. if(png_ptr == NULL) return;
  166839. if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */
  166840. png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
  166841. }
  166842. void PNGAPI
  166843. png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr,
  166844. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  166845. png_progressive_end_ptr end_fn)
  166846. {
  166847. if(png_ptr == NULL) return;
  166848. png_ptr->info_fn = info_fn;
  166849. png_ptr->row_fn = row_fn;
  166850. png_ptr->end_fn = end_fn;
  166851. png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
  166852. }
  166853. png_voidp PNGAPI
  166854. png_get_progressive_ptr(png_structp png_ptr)
  166855. {
  166856. if(png_ptr == NULL) return (NULL);
  166857. return png_ptr->io_ptr;
  166858. }
  166859. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  166860. /*** End of inlined file: pngpread.c ***/
  166861. /*** Start of inlined file: pngrio.c ***/
  166862. #define PNG_INTERNAL
  166863. #if defined(PNG_READ_SUPPORTED)
  166864. void /* PRIVATE */
  166865. png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  166866. {
  166867. png_debug1(4,"reading %d bytes\n", (int)length);
  166868. if (png_ptr->read_data_fn != NULL)
  166869. (*(png_ptr->read_data_fn))(png_ptr, data, length);
  166870. else
  166871. png_error(png_ptr, "Call to NULL read function");
  166872. }
  166873. #if !defined(PNG_NO_STDIO)
  166874. #ifndef USE_FAR_KEYWORD
  166875. void PNGAPI
  166876. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  166877. {
  166878. png_size_t check;
  166879. if(png_ptr == NULL) return;
  166880. #if defined(_WIN32_WCE)
  166881. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  166882. check = 0;
  166883. #else
  166884. check = (png_size_t)fread(data, (png_size_t)1, length,
  166885. (png_FILE_p)png_ptr->io_ptr);
  166886. #endif
  166887. if (check != length)
  166888. png_error(png_ptr, "Read Error");
  166889. }
  166890. #else
  166891. #define NEAR_BUF_SIZE 1024
  166892. #define MIN(a,b) (a <= b ? a : b)
  166893. static void PNGAPI
  166894. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  166895. {
  166896. int check;
  166897. png_byte *n_data;
  166898. png_FILE_p io_ptr;
  166899. if(png_ptr == NULL) return;
  166900. n_data = (png_byte *)CVT_PTR_NOCHECK(data);
  166901. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  166902. if ((png_bytep)n_data == data)
  166903. {
  166904. #if defined(_WIN32_WCE)
  166905. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  166906. check = 0;
  166907. #else
  166908. check = fread(n_data, 1, length, io_ptr);
  166909. #endif
  166910. }
  166911. else
  166912. {
  166913. png_byte buf[NEAR_BUF_SIZE];
  166914. png_size_t read, remaining, err;
  166915. check = 0;
  166916. remaining = length;
  166917. do
  166918. {
  166919. read = MIN(NEAR_BUF_SIZE, remaining);
  166920. #if defined(_WIN32_WCE)
  166921. if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) )
  166922. err = 0;
  166923. #else
  166924. err = fread(buf, (png_size_t)1, read, io_ptr);
  166925. #endif
  166926. png_memcpy(data, buf, read); /* copy far buffer to near buffer */
  166927. if(err != read)
  166928. break;
  166929. else
  166930. check += err;
  166931. data += read;
  166932. remaining -= read;
  166933. }
  166934. while (remaining != 0);
  166935. }
  166936. if ((png_uint_32)check != (png_uint_32)length)
  166937. png_error(png_ptr, "read Error");
  166938. }
  166939. #endif
  166940. #endif
  166941. void PNGAPI
  166942. png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
  166943. png_rw_ptr read_data_fn)
  166944. {
  166945. if(png_ptr == NULL) return;
  166946. png_ptr->io_ptr = io_ptr;
  166947. #if !defined(PNG_NO_STDIO)
  166948. if (read_data_fn != NULL)
  166949. png_ptr->read_data_fn = read_data_fn;
  166950. else
  166951. png_ptr->read_data_fn = png_default_read_data;
  166952. #else
  166953. png_ptr->read_data_fn = read_data_fn;
  166954. #endif
  166955. if (png_ptr->write_data_fn != NULL)
  166956. {
  166957. png_ptr->write_data_fn = NULL;
  166958. png_warning(png_ptr,
  166959. "It's an error to set both read_data_fn and write_data_fn in the ");
  166960. png_warning(png_ptr,
  166961. "same structure. Resetting write_data_fn to NULL.");
  166962. }
  166963. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  166964. png_ptr->output_flush_fn = NULL;
  166965. #endif
  166966. }
  166967. #endif /* PNG_READ_SUPPORTED */
  166968. /*** End of inlined file: pngrio.c ***/
  166969. /*** Start of inlined file: pngrtran.c ***/
  166970. #define PNG_INTERNAL
  166971. #if defined(PNG_READ_SUPPORTED)
  166972. void PNGAPI
  166973. png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
  166974. {
  166975. png_debug(1, "in png_set_crc_action\n");
  166976. if(png_ptr == NULL) return;
  166977. switch (crit_action)
  166978. {
  166979. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  166980. break;
  166981. case PNG_CRC_WARN_USE: /* warn/use data */
  166982. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  166983. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;
  166984. break;
  166985. case PNG_CRC_QUIET_USE: /* quiet/use data */
  166986. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  166987. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |
  166988. PNG_FLAG_CRC_CRITICAL_IGNORE;
  166989. break;
  166990. case PNG_CRC_WARN_DISCARD: /* not a valid action for critical data */
  166991. png_warning(png_ptr, "Can't discard critical data on CRC error.");
  166992. case PNG_CRC_ERROR_QUIT: /* error/quit */
  166993. case PNG_CRC_DEFAULT:
  166994. default:
  166995. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  166996. break;
  166997. }
  166998. switch (ancil_action)
  166999. {
  167000. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  167001. break;
  167002. case PNG_CRC_WARN_USE: /* warn/use data */
  167003. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167004. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE;
  167005. break;
  167006. case PNG_CRC_QUIET_USE: /* quiet/use data */
  167007. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167008. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE |
  167009. PNG_FLAG_CRC_ANCILLARY_NOWARN;
  167010. break;
  167011. case PNG_CRC_ERROR_QUIT: /* error/quit */
  167012. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167013. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN;
  167014. break;
  167015. case PNG_CRC_WARN_DISCARD: /* warn/discard data */
  167016. case PNG_CRC_DEFAULT:
  167017. default:
  167018. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167019. break;
  167020. }
  167021. }
  167022. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  167023. defined(PNG_FLOATING_POINT_SUPPORTED)
  167024. void PNGAPI
  167025. png_set_background(png_structp png_ptr,
  167026. png_color_16p background_color, int background_gamma_code,
  167027. int need_expand, double background_gamma)
  167028. {
  167029. png_debug(1, "in png_set_background\n");
  167030. if(png_ptr == NULL) return;
  167031. if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN)
  167032. {
  167033. png_warning(png_ptr, "Application must supply a known background gamma");
  167034. return;
  167035. }
  167036. png_ptr->transformations |= PNG_BACKGROUND;
  167037. png_memcpy(&(png_ptr->background), background_color,
  167038. png_sizeof(png_color_16));
  167039. png_ptr->background_gamma = (float)background_gamma;
  167040. png_ptr->background_gamma_type = (png_byte)(background_gamma_code);
  167041. png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0);
  167042. }
  167043. #endif
  167044. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  167045. void PNGAPI
  167046. png_set_strip_16(png_structp png_ptr)
  167047. {
  167048. png_debug(1, "in png_set_strip_16\n");
  167049. if(png_ptr == NULL) return;
  167050. png_ptr->transformations |= PNG_16_TO_8;
  167051. }
  167052. #endif
  167053. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  167054. void PNGAPI
  167055. png_set_strip_alpha(png_structp png_ptr)
  167056. {
  167057. png_debug(1, "in png_set_strip_alpha\n");
  167058. if(png_ptr == NULL) return;
  167059. png_ptr->flags |= PNG_FLAG_STRIP_ALPHA;
  167060. }
  167061. #endif
  167062. #if defined(PNG_READ_DITHER_SUPPORTED)
  167063. typedef struct png_dsort_struct
  167064. {
  167065. struct png_dsort_struct FAR * next;
  167066. png_byte left;
  167067. png_byte right;
  167068. } png_dsort;
  167069. typedef png_dsort FAR * png_dsortp;
  167070. typedef png_dsort FAR * FAR * png_dsortpp;
  167071. void PNGAPI
  167072. png_set_dither(png_structp png_ptr, png_colorp palette,
  167073. int num_palette, int maximum_colors, png_uint_16p histogram,
  167074. int full_dither)
  167075. {
  167076. png_debug(1, "in png_set_dither\n");
  167077. if(png_ptr == NULL) return;
  167078. png_ptr->transformations |= PNG_DITHER;
  167079. if (!full_dither)
  167080. {
  167081. int i;
  167082. png_ptr->dither_index = (png_bytep)png_malloc(png_ptr,
  167083. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167084. for (i = 0; i < num_palette; i++)
  167085. png_ptr->dither_index[i] = (png_byte)i;
  167086. }
  167087. if (num_palette > maximum_colors)
  167088. {
  167089. if (histogram != NULL)
  167090. {
  167091. int i;
  167092. png_ptr->dither_sort = (png_bytep)png_malloc(png_ptr,
  167093. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167094. for (i = 0; i < num_palette; i++)
  167095. png_ptr->dither_sort[i] = (png_byte)i;
  167096. for (i = num_palette - 1; i >= maximum_colors; i--)
  167097. {
  167098. int done; /* to stop early if the list is pre-sorted */
  167099. int j;
  167100. done = 1;
  167101. for (j = 0; j < i; j++)
  167102. {
  167103. if (histogram[png_ptr->dither_sort[j]]
  167104. < histogram[png_ptr->dither_sort[j + 1]])
  167105. {
  167106. png_byte t;
  167107. t = png_ptr->dither_sort[j];
  167108. png_ptr->dither_sort[j] = png_ptr->dither_sort[j + 1];
  167109. png_ptr->dither_sort[j + 1] = t;
  167110. done = 0;
  167111. }
  167112. }
  167113. if (done)
  167114. break;
  167115. }
  167116. if (full_dither)
  167117. {
  167118. int j = num_palette;
  167119. for (i = 0; i < maximum_colors; i++)
  167120. {
  167121. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167122. {
  167123. do
  167124. j--;
  167125. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167126. palette[i] = palette[j];
  167127. }
  167128. }
  167129. }
  167130. else
  167131. {
  167132. int j = num_palette;
  167133. for (i = 0; i < maximum_colors; i++)
  167134. {
  167135. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167136. {
  167137. png_color tmp_color;
  167138. do
  167139. j--;
  167140. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167141. tmp_color = palette[j];
  167142. palette[j] = palette[i];
  167143. palette[i] = tmp_color;
  167144. png_ptr->dither_index[j] = (png_byte)i;
  167145. png_ptr->dither_index[i] = (png_byte)j;
  167146. }
  167147. }
  167148. for (i = 0; i < num_palette; i++)
  167149. {
  167150. if ((int)png_ptr->dither_index[i] >= maximum_colors)
  167151. {
  167152. int min_d, k, min_k, d_index;
  167153. d_index = png_ptr->dither_index[i];
  167154. min_d = PNG_COLOR_DIST(palette[d_index], palette[0]);
  167155. for (k = 1, min_k = 0; k < maximum_colors; k++)
  167156. {
  167157. int d;
  167158. d = PNG_COLOR_DIST(palette[d_index], palette[k]);
  167159. if (d < min_d)
  167160. {
  167161. min_d = d;
  167162. min_k = k;
  167163. }
  167164. }
  167165. png_ptr->dither_index[i] = (png_byte)min_k;
  167166. }
  167167. }
  167168. }
  167169. png_free(png_ptr, png_ptr->dither_sort);
  167170. png_ptr->dither_sort=NULL;
  167171. }
  167172. else
  167173. {
  167174. int i;
  167175. int max_d;
  167176. int num_new_palette;
  167177. png_dsortp t;
  167178. png_dsortpp hash;
  167179. t=NULL;
  167180. png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
  167181. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167182. png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
  167183. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167184. for (i = 0; i < num_palette; i++)
  167185. {
  167186. png_ptr->index_to_palette[i] = (png_byte)i;
  167187. png_ptr->palette_to_index[i] = (png_byte)i;
  167188. }
  167189. hash = (png_dsortpp)png_malloc(png_ptr, (png_uint_32)(769 *
  167190. png_sizeof (png_dsortp)));
  167191. for (i = 0; i < 769; i++)
  167192. hash[i] = NULL;
  167193. num_new_palette = num_palette;
  167194. max_d = 96;
  167195. while (num_new_palette > maximum_colors)
  167196. {
  167197. for (i = 0; i < num_new_palette - 1; i++)
  167198. {
  167199. int j;
  167200. for (j = i + 1; j < num_new_palette; j++)
  167201. {
  167202. int d;
  167203. d = PNG_COLOR_DIST(palette[i], palette[j]);
  167204. if (d <= max_d)
  167205. {
  167206. t = (png_dsortp)png_malloc_warn(png_ptr,
  167207. (png_uint_32)(png_sizeof(png_dsort)));
  167208. if (t == NULL)
  167209. break;
  167210. t->next = hash[d];
  167211. t->left = (png_byte)i;
  167212. t->right = (png_byte)j;
  167213. hash[d] = t;
  167214. }
  167215. }
  167216. if (t == NULL)
  167217. break;
  167218. }
  167219. if (t != NULL)
  167220. for (i = 0; i <= max_d; i++)
  167221. {
  167222. if (hash[i] != NULL)
  167223. {
  167224. png_dsortp p;
  167225. for (p = hash[i]; p; p = p->next)
  167226. {
  167227. if ((int)png_ptr->index_to_palette[p->left]
  167228. < num_new_palette &&
  167229. (int)png_ptr->index_to_palette[p->right]
  167230. < num_new_palette)
  167231. {
  167232. int j, next_j;
  167233. if (num_new_palette & 0x01)
  167234. {
  167235. j = p->left;
  167236. next_j = p->right;
  167237. }
  167238. else
  167239. {
  167240. j = p->right;
  167241. next_j = p->left;
  167242. }
  167243. num_new_palette--;
  167244. palette[png_ptr->index_to_palette[j]]
  167245. = palette[num_new_palette];
  167246. if (!full_dither)
  167247. {
  167248. int k;
  167249. for (k = 0; k < num_palette; k++)
  167250. {
  167251. if (png_ptr->dither_index[k] ==
  167252. png_ptr->index_to_palette[j])
  167253. png_ptr->dither_index[k] =
  167254. png_ptr->index_to_palette[next_j];
  167255. if ((int)png_ptr->dither_index[k] ==
  167256. num_new_palette)
  167257. png_ptr->dither_index[k] =
  167258. png_ptr->index_to_palette[j];
  167259. }
  167260. }
  167261. png_ptr->index_to_palette[png_ptr->palette_to_index
  167262. [num_new_palette]] = png_ptr->index_to_palette[j];
  167263. png_ptr->palette_to_index[png_ptr->index_to_palette[j]]
  167264. = png_ptr->palette_to_index[num_new_palette];
  167265. png_ptr->index_to_palette[j] = (png_byte)num_new_palette;
  167266. png_ptr->palette_to_index[num_new_palette] = (png_byte)j;
  167267. }
  167268. if (num_new_palette <= maximum_colors)
  167269. break;
  167270. }
  167271. if (num_new_palette <= maximum_colors)
  167272. break;
  167273. }
  167274. }
  167275. for (i = 0; i < 769; i++)
  167276. {
  167277. if (hash[i] != NULL)
  167278. {
  167279. png_dsortp p = hash[i];
  167280. while (p)
  167281. {
  167282. t = p->next;
  167283. png_free(png_ptr, p);
  167284. p = t;
  167285. }
  167286. }
  167287. hash[i] = 0;
  167288. }
  167289. max_d += 96;
  167290. }
  167291. png_free(png_ptr, hash);
  167292. png_free(png_ptr, png_ptr->palette_to_index);
  167293. png_free(png_ptr, png_ptr->index_to_palette);
  167294. png_ptr->palette_to_index=NULL;
  167295. png_ptr->index_to_palette=NULL;
  167296. }
  167297. num_palette = maximum_colors;
  167298. }
  167299. if (png_ptr->palette == NULL)
  167300. {
  167301. png_ptr->palette = palette;
  167302. }
  167303. png_ptr->num_palette = (png_uint_16)num_palette;
  167304. if (full_dither)
  167305. {
  167306. int i;
  167307. png_bytep distance;
  167308. int total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS +
  167309. PNG_DITHER_BLUE_BITS;
  167310. int num_red = (1 << PNG_DITHER_RED_BITS);
  167311. int num_green = (1 << PNG_DITHER_GREEN_BITS);
  167312. int num_blue = (1 << PNG_DITHER_BLUE_BITS);
  167313. png_size_t num_entries = ((png_size_t)1 << total_bits);
  167314. png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr,
  167315. (png_uint_32)(num_entries * png_sizeof (png_byte)));
  167316. png_memset(png_ptr->palette_lookup, 0, num_entries *
  167317. png_sizeof (png_byte));
  167318. distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *
  167319. png_sizeof(png_byte)));
  167320. png_memset(distance, 0xff, num_entries * png_sizeof(png_byte));
  167321. for (i = 0; i < num_palette; i++)
  167322. {
  167323. int ir, ig, ib;
  167324. int r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS));
  167325. int g = (palette[i].green >> (8 - PNG_DITHER_GREEN_BITS));
  167326. int b = (palette[i].blue >> (8 - PNG_DITHER_BLUE_BITS));
  167327. for (ir = 0; ir < num_red; ir++)
  167328. {
  167329. int dr = ((ir > r) ? ir - r : r - ir);
  167330. int index_r = (ir << (PNG_DITHER_BLUE_BITS + PNG_DITHER_GREEN_BITS));
  167331. for (ig = 0; ig < num_green; ig++)
  167332. {
  167333. int dg = ((ig > g) ? ig - g : g - ig);
  167334. int dt = dr + dg;
  167335. int dm = ((dr > dg) ? dr : dg);
  167336. int index_g = index_r | (ig << PNG_DITHER_BLUE_BITS);
  167337. for (ib = 0; ib < num_blue; ib++)
  167338. {
  167339. int d_index = index_g | ib;
  167340. int db = ((ib > b) ? ib - b : b - ib);
  167341. int dmax = ((dm > db) ? dm : db);
  167342. int d = dmax + dt + db;
  167343. if (d < (int)distance[d_index])
  167344. {
  167345. distance[d_index] = (png_byte)d;
  167346. png_ptr->palette_lookup[d_index] = (png_byte)i;
  167347. }
  167348. }
  167349. }
  167350. }
  167351. }
  167352. png_free(png_ptr, distance);
  167353. }
  167354. }
  167355. #endif
  167356. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  167357. void PNGAPI
  167358. png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
  167359. {
  167360. png_debug(1, "in png_set_gamma\n");
  167361. if(png_ptr == NULL) return;
  167362. if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) ||
  167363. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) ||
  167364. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
  167365. png_ptr->transformations |= PNG_GAMMA;
  167366. png_ptr->gamma = (float)file_gamma;
  167367. png_ptr->screen_gamma = (float)scrn_gamma;
  167368. }
  167369. #endif
  167370. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167371. void PNGAPI
  167372. png_set_expand(png_structp png_ptr)
  167373. {
  167374. png_debug(1, "in png_set_expand\n");
  167375. if(png_ptr == NULL) return;
  167376. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167377. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167378. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167379. #endif
  167380. }
  167381. void PNGAPI
  167382. png_set_palette_to_rgb(png_structp png_ptr)
  167383. {
  167384. png_debug(1, "in png_set_palette_to_rgb\n");
  167385. if(png_ptr == NULL) return;
  167386. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167387. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167388. png_ptr->flags &= !(PNG_FLAG_ROW_INIT);
  167389. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167390. #endif
  167391. }
  167392. #if !defined(PNG_1_0_X)
  167393. void PNGAPI
  167394. png_set_expand_gray_1_2_4_to_8(png_structp png_ptr)
  167395. {
  167396. png_debug(1, "in png_set_expand_gray_1_2_4_to_8\n");
  167397. if(png_ptr == NULL) return;
  167398. png_ptr->transformations |= PNG_EXPAND;
  167399. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167400. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167401. #endif
  167402. }
  167403. #endif
  167404. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  167405. void PNGAPI
  167406. png_set_gray_1_2_4_to_8(png_structp png_ptr)
  167407. {
  167408. png_debug(1, "in png_set_gray_1_2_4_to_8\n");
  167409. if(png_ptr == NULL) return;
  167410. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167411. }
  167412. #endif
  167413. void PNGAPI
  167414. png_set_tRNS_to_alpha(png_structp png_ptr)
  167415. {
  167416. png_debug(1, "in png_set_tRNS_to_alpha\n");
  167417. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167418. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167419. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167420. #endif
  167421. }
  167422. #endif /* defined(PNG_READ_EXPAND_SUPPORTED) */
  167423. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167424. void PNGAPI
  167425. png_set_gray_to_rgb(png_structp png_ptr)
  167426. {
  167427. png_debug(1, "in png_set_gray_to_rgb\n");
  167428. png_ptr->transformations |= PNG_GRAY_TO_RGB;
  167429. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167430. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167431. #endif
  167432. }
  167433. #endif
  167434. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167435. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  167436. void PNGAPI
  167437. png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
  167438. double green)
  167439. {
  167440. int red_fixed = (int)((float)red*100000.0 + 0.5);
  167441. int green_fixed = (int)((float)green*100000.0 + 0.5);
  167442. if(png_ptr == NULL) return;
  167443. png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed);
  167444. }
  167445. #endif
  167446. void PNGAPI
  167447. png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
  167448. png_fixed_point red, png_fixed_point green)
  167449. {
  167450. png_debug(1, "in png_set_rgb_to_gray\n");
  167451. if(png_ptr == NULL) return;
  167452. switch(error_action)
  167453. {
  167454. case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY;
  167455. break;
  167456. case 2: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
  167457. break;
  167458. case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
  167459. }
  167460. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167461. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167462. png_ptr->transformations |= PNG_EXPAND;
  167463. #else
  167464. {
  167465. png_warning(png_ptr, "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED.");
  167466. png_ptr->transformations &= ~PNG_RGB_TO_GRAY;
  167467. }
  167468. #endif
  167469. {
  167470. png_uint_16 red_int, green_int;
  167471. if(red < 0 || green < 0)
  167472. {
  167473. red_int = 6968; /* .212671 * 32768 + .5 */
  167474. green_int = 23434; /* .715160 * 32768 + .5 */
  167475. }
  167476. else if(red + green < 100000L)
  167477. {
  167478. red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
  167479. green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
  167480. }
  167481. else
  167482. {
  167483. png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients");
  167484. red_int = 6968;
  167485. green_int = 23434;
  167486. }
  167487. png_ptr->rgb_to_gray_red_coeff = red_int;
  167488. png_ptr->rgb_to_gray_green_coeff = green_int;
  167489. png_ptr->rgb_to_gray_blue_coeff = (png_uint_16)(32768-red_int-green_int);
  167490. }
  167491. }
  167492. #endif
  167493. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  167494. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  167495. defined(PNG_LEGACY_SUPPORTED)
  167496. void PNGAPI
  167497. png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  167498. read_user_transform_fn)
  167499. {
  167500. png_debug(1, "in png_set_read_user_transform_fn\n");
  167501. if(png_ptr == NULL) return;
  167502. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  167503. png_ptr->transformations |= PNG_USER_TRANSFORM;
  167504. png_ptr->read_user_transform_fn = read_user_transform_fn;
  167505. #endif
  167506. #ifdef PNG_LEGACY_SUPPORTED
  167507. if(read_user_transform_fn)
  167508. png_warning(png_ptr,
  167509. "This version of libpng does not support user transforms");
  167510. #endif
  167511. }
  167512. #endif
  167513. void /* PRIVATE */
  167514. png_init_read_transformations(png_structp png_ptr)
  167515. {
  167516. png_debug(1, "in png_init_read_transformations\n");
  167517. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  167518. if(png_ptr != NULL)
  167519. #endif
  167520. {
  167521. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || defined(PNG_READ_SHIFT_SUPPORTED) \
  167522. || defined(PNG_READ_GAMMA_SUPPORTED)
  167523. int color_type = png_ptr->color_type;
  167524. #endif
  167525. #if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
  167526. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167527. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167528. !(color_type & PNG_COLOR_MASK_COLOR))
  167529. {
  167530. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  167531. } else if ((png_ptr->transformations & PNG_BACKGROUND) &&
  167532. !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167533. (png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  167534. png_ptr->background.red == png_ptr->background.green &&
  167535. png_ptr->background.red == png_ptr->background.blue)
  167536. {
  167537. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  167538. png_ptr->background.gray = png_ptr->background.red;
  167539. }
  167540. #endif
  167541. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167542. (png_ptr->transformations & PNG_EXPAND))
  167543. {
  167544. if (!(color_type & PNG_COLOR_MASK_COLOR)) /* i.e., GRAY or GRAY_ALPHA */
  167545. {
  167546. switch (png_ptr->bit_depth)
  167547. {
  167548. case 1:
  167549. png_ptr->background.gray *= (png_uint_16)0xff;
  167550. png_ptr->background.red = png_ptr->background.green
  167551. = png_ptr->background.blue = png_ptr->background.gray;
  167552. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167553. {
  167554. png_ptr->trans_values.gray *= (png_uint_16)0xff;
  167555. png_ptr->trans_values.red = png_ptr->trans_values.green
  167556. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167557. }
  167558. break;
  167559. case 2:
  167560. png_ptr->background.gray *= (png_uint_16)0x55;
  167561. png_ptr->background.red = png_ptr->background.green
  167562. = png_ptr->background.blue = png_ptr->background.gray;
  167563. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167564. {
  167565. png_ptr->trans_values.gray *= (png_uint_16)0x55;
  167566. png_ptr->trans_values.red = png_ptr->trans_values.green
  167567. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167568. }
  167569. break;
  167570. case 4:
  167571. png_ptr->background.gray *= (png_uint_16)0x11;
  167572. png_ptr->background.red = png_ptr->background.green
  167573. = png_ptr->background.blue = png_ptr->background.gray;
  167574. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167575. {
  167576. png_ptr->trans_values.gray *= (png_uint_16)0x11;
  167577. png_ptr->trans_values.red = png_ptr->trans_values.green
  167578. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167579. }
  167580. break;
  167581. case 8:
  167582. case 16:
  167583. png_ptr->background.red = png_ptr->background.green
  167584. = png_ptr->background.blue = png_ptr->background.gray;
  167585. break;
  167586. }
  167587. }
  167588. else if (color_type == PNG_COLOR_TYPE_PALETTE)
  167589. {
  167590. png_ptr->background.red =
  167591. png_ptr->palette[png_ptr->background.index].red;
  167592. png_ptr->background.green =
  167593. png_ptr->palette[png_ptr->background.index].green;
  167594. png_ptr->background.blue =
  167595. png_ptr->palette[png_ptr->background.index].blue;
  167596. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  167597. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  167598. {
  167599. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167600. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167601. #endif
  167602. {
  167603. int i,istop;
  167604. istop=(int)png_ptr->num_trans;
  167605. for (i=0; i<istop; i++)
  167606. png_ptr->trans[i] = (png_byte)(255 - png_ptr->trans[i]);
  167607. }
  167608. }
  167609. #endif
  167610. }
  167611. }
  167612. #endif
  167613. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  167614. png_ptr->background_1 = png_ptr->background;
  167615. #endif
  167616. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  167617. if ((color_type == PNG_COLOR_TYPE_PALETTE && png_ptr->num_trans != 0)
  167618. && (fabs(png_ptr->screen_gamma * png_ptr->gamma - 1.0)
  167619. < PNG_GAMMA_THRESHOLD))
  167620. {
  167621. int i,k;
  167622. k=0;
  167623. for (i=0; i<png_ptr->num_trans; i++)
  167624. {
  167625. if (png_ptr->trans[i] != 0 && png_ptr->trans[i] != 0xff)
  167626. k=1; /* partial transparency is present */
  167627. }
  167628. if (k == 0)
  167629. png_ptr->transformations &= (~PNG_GAMMA);
  167630. }
  167631. if ((png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY)) &&
  167632. png_ptr->gamma != 0.0)
  167633. {
  167634. png_build_gamma_table(png_ptr);
  167635. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167636. if (png_ptr->transformations & PNG_BACKGROUND)
  167637. {
  167638. if (color_type == PNG_COLOR_TYPE_PALETTE)
  167639. {
  167640. png_color back, back_1;
  167641. png_colorp palette = png_ptr->palette;
  167642. int num_palette = png_ptr->num_palette;
  167643. int i;
  167644. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  167645. {
  167646. back.red = png_ptr->gamma_table[png_ptr->background.red];
  167647. back.green = png_ptr->gamma_table[png_ptr->background.green];
  167648. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  167649. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  167650. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  167651. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  167652. }
  167653. else
  167654. {
  167655. double g, gs;
  167656. switch (png_ptr->background_gamma_type)
  167657. {
  167658. case PNG_BACKGROUND_GAMMA_SCREEN:
  167659. g = (png_ptr->screen_gamma);
  167660. gs = 1.0;
  167661. break;
  167662. case PNG_BACKGROUND_GAMMA_FILE:
  167663. g = 1.0 / (png_ptr->gamma);
  167664. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  167665. break;
  167666. case PNG_BACKGROUND_GAMMA_UNIQUE:
  167667. g = 1.0 / (png_ptr->background_gamma);
  167668. gs = 1.0 / (png_ptr->background_gamma *
  167669. png_ptr->screen_gamma);
  167670. break;
  167671. default:
  167672. g = 1.0; /* back_1 */
  167673. gs = 1.0; /* back */
  167674. }
  167675. if ( fabs(gs - 1.0) < PNG_GAMMA_THRESHOLD)
  167676. {
  167677. back.red = (png_byte)png_ptr->background.red;
  167678. back.green = (png_byte)png_ptr->background.green;
  167679. back.blue = (png_byte)png_ptr->background.blue;
  167680. }
  167681. else
  167682. {
  167683. back.red = (png_byte)(pow(
  167684. (double)png_ptr->background.red/255, gs) * 255.0 + .5);
  167685. back.green = (png_byte)(pow(
  167686. (double)png_ptr->background.green/255, gs) * 255.0 + .5);
  167687. back.blue = (png_byte)(pow(
  167688. (double)png_ptr->background.blue/255, gs) * 255.0 + .5);
  167689. }
  167690. back_1.red = (png_byte)(pow(
  167691. (double)png_ptr->background.red/255, g) * 255.0 + .5);
  167692. back_1.green = (png_byte)(pow(
  167693. (double)png_ptr->background.green/255, g) * 255.0 + .5);
  167694. back_1.blue = (png_byte)(pow(
  167695. (double)png_ptr->background.blue/255, g) * 255.0 + .5);
  167696. }
  167697. for (i = 0; i < num_palette; i++)
  167698. {
  167699. if (i < (int)png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  167700. {
  167701. if (png_ptr->trans[i] == 0)
  167702. {
  167703. palette[i] = back;
  167704. }
  167705. else /* if (png_ptr->trans[i] != 0xff) */
  167706. {
  167707. png_byte v, w;
  167708. v = png_ptr->gamma_to_1[palette[i].red];
  167709. png_composite(w, v, png_ptr->trans[i], back_1.red);
  167710. palette[i].red = png_ptr->gamma_from_1[w];
  167711. v = png_ptr->gamma_to_1[palette[i].green];
  167712. png_composite(w, v, png_ptr->trans[i], back_1.green);
  167713. palette[i].green = png_ptr->gamma_from_1[w];
  167714. v = png_ptr->gamma_to_1[palette[i].blue];
  167715. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  167716. palette[i].blue = png_ptr->gamma_from_1[w];
  167717. }
  167718. }
  167719. else
  167720. {
  167721. palette[i].red = png_ptr->gamma_table[palette[i].red];
  167722. palette[i].green = png_ptr->gamma_table[palette[i].green];
  167723. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  167724. }
  167725. }
  167726. }
  167727. else
  167728. {
  167729. double m = (double)(((png_uint_32)1 << png_ptr->bit_depth) - 1);
  167730. double g = 1.0;
  167731. double gs = 1.0;
  167732. switch (png_ptr->background_gamma_type)
  167733. {
  167734. case PNG_BACKGROUND_GAMMA_SCREEN:
  167735. g = (png_ptr->screen_gamma);
  167736. gs = 1.0;
  167737. break;
  167738. case PNG_BACKGROUND_GAMMA_FILE:
  167739. g = 1.0 / (png_ptr->gamma);
  167740. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  167741. break;
  167742. case PNG_BACKGROUND_GAMMA_UNIQUE:
  167743. g = 1.0 / (png_ptr->background_gamma);
  167744. gs = 1.0 / (png_ptr->background_gamma *
  167745. png_ptr->screen_gamma);
  167746. break;
  167747. }
  167748. png_ptr->background_1.gray = (png_uint_16)(pow(
  167749. (double)png_ptr->background.gray / m, g) * m + .5);
  167750. png_ptr->background.gray = (png_uint_16)(pow(
  167751. (double)png_ptr->background.gray / m, gs) * m + .5);
  167752. if ((png_ptr->background.red != png_ptr->background.green) ||
  167753. (png_ptr->background.red != png_ptr->background.blue) ||
  167754. (png_ptr->background.red != png_ptr->background.gray))
  167755. {
  167756. png_ptr->background_1.red = (png_uint_16)(pow(
  167757. (double)png_ptr->background.red / m, g) * m + .5);
  167758. png_ptr->background_1.green = (png_uint_16)(pow(
  167759. (double)png_ptr->background.green / m, g) * m + .5);
  167760. png_ptr->background_1.blue = (png_uint_16)(pow(
  167761. (double)png_ptr->background.blue / m, g) * m + .5);
  167762. png_ptr->background.red = (png_uint_16)(pow(
  167763. (double)png_ptr->background.red / m, gs) * m + .5);
  167764. png_ptr->background.green = (png_uint_16)(pow(
  167765. (double)png_ptr->background.green / m, gs) * m + .5);
  167766. png_ptr->background.blue = (png_uint_16)(pow(
  167767. (double)png_ptr->background.blue / m, gs) * m + .5);
  167768. }
  167769. else
  167770. {
  167771. png_ptr->background_1.red = png_ptr->background_1.green
  167772. = png_ptr->background_1.blue = png_ptr->background_1.gray;
  167773. png_ptr->background.red = png_ptr->background.green
  167774. = png_ptr->background.blue = png_ptr->background.gray;
  167775. }
  167776. }
  167777. }
  167778. else
  167779. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  167780. if (color_type == PNG_COLOR_TYPE_PALETTE)
  167781. {
  167782. png_colorp palette = png_ptr->palette;
  167783. int num_palette = png_ptr->num_palette;
  167784. int i;
  167785. for (i = 0; i < num_palette; i++)
  167786. {
  167787. palette[i].red = png_ptr->gamma_table[palette[i].red];
  167788. palette[i].green = png_ptr->gamma_table[palette[i].green];
  167789. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  167790. }
  167791. }
  167792. }
  167793. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167794. else
  167795. #endif
  167796. #endif /* PNG_READ_GAMMA_SUPPORTED && PNG_FLOATING_POINT_SUPPORTED */
  167797. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167798. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  167799. (color_type == PNG_COLOR_TYPE_PALETTE))
  167800. {
  167801. int i;
  167802. int istop = (int)png_ptr->num_trans;
  167803. png_color back;
  167804. png_colorp palette = png_ptr->palette;
  167805. back.red = (png_byte)png_ptr->background.red;
  167806. back.green = (png_byte)png_ptr->background.green;
  167807. back.blue = (png_byte)png_ptr->background.blue;
  167808. for (i = 0; i < istop; i++)
  167809. {
  167810. if (png_ptr->trans[i] == 0)
  167811. {
  167812. palette[i] = back;
  167813. }
  167814. else if (png_ptr->trans[i] != 0xff)
  167815. {
  167816. png_composite(palette[i].red, palette[i].red,
  167817. png_ptr->trans[i], back.red);
  167818. png_composite(palette[i].green, palette[i].green,
  167819. png_ptr->trans[i], back.green);
  167820. png_composite(palette[i].blue, palette[i].blue,
  167821. png_ptr->trans[i], back.blue);
  167822. }
  167823. }
  167824. }
  167825. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  167826. #if defined(PNG_READ_SHIFT_SUPPORTED)
  167827. if ((png_ptr->transformations & PNG_SHIFT) &&
  167828. (color_type == PNG_COLOR_TYPE_PALETTE))
  167829. {
  167830. png_uint_16 i;
  167831. png_uint_16 istop = png_ptr->num_palette;
  167832. int sr = 8 - png_ptr->sig_bit.red;
  167833. int sg = 8 - png_ptr->sig_bit.green;
  167834. int sb = 8 - png_ptr->sig_bit.blue;
  167835. if (sr < 0 || sr > 8)
  167836. sr = 0;
  167837. if (sg < 0 || sg > 8)
  167838. sg = 0;
  167839. if (sb < 0 || sb > 8)
  167840. sb = 0;
  167841. for (i = 0; i < istop; i++)
  167842. {
  167843. png_ptr->palette[i].red >>= sr;
  167844. png_ptr->palette[i].green >>= sg;
  167845. png_ptr->palette[i].blue >>= sb;
  167846. }
  167847. }
  167848. #endif /* PNG_READ_SHIFT_SUPPORTED */
  167849. }
  167850. #if !defined(PNG_READ_GAMMA_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) \
  167851. && !defined(PNG_READ_BACKGROUND_SUPPORTED)
  167852. if(png_ptr)
  167853. return;
  167854. #endif
  167855. }
  167856. void /* PRIVATE */
  167857. png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
  167858. {
  167859. png_debug(1, "in png_read_transform_info\n");
  167860. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167861. if (png_ptr->transformations & PNG_EXPAND)
  167862. {
  167863. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167864. {
  167865. if (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND_tRNS))
  167866. info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  167867. else
  167868. info_ptr->color_type = PNG_COLOR_TYPE_RGB;
  167869. info_ptr->bit_depth = 8;
  167870. info_ptr->num_trans = 0;
  167871. }
  167872. else
  167873. {
  167874. if (png_ptr->num_trans)
  167875. {
  167876. if (png_ptr->transformations & PNG_EXPAND_tRNS)
  167877. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  167878. else
  167879. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  167880. }
  167881. if (info_ptr->bit_depth < 8)
  167882. info_ptr->bit_depth = 8;
  167883. info_ptr->num_trans = 0;
  167884. }
  167885. }
  167886. #endif
  167887. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167888. if (png_ptr->transformations & PNG_BACKGROUND)
  167889. {
  167890. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  167891. info_ptr->num_trans = 0;
  167892. info_ptr->background = png_ptr->background;
  167893. }
  167894. #endif
  167895. #if defined(PNG_READ_GAMMA_SUPPORTED)
  167896. if (png_ptr->transformations & PNG_GAMMA)
  167897. {
  167898. #ifdef PNG_FLOATING_POINT_SUPPORTED
  167899. info_ptr->gamma = png_ptr->gamma;
  167900. #endif
  167901. #ifdef PNG_FIXED_POINT_SUPPORTED
  167902. info_ptr->int_gamma = png_ptr->int_gamma;
  167903. #endif
  167904. }
  167905. #endif
  167906. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  167907. if ((png_ptr->transformations & PNG_16_TO_8) && (info_ptr->bit_depth == 16))
  167908. info_ptr->bit_depth = 8;
  167909. #endif
  167910. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167911. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  167912. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  167913. #endif
  167914. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167915. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  167916. info_ptr->color_type &= ~PNG_COLOR_MASK_COLOR;
  167917. #endif
  167918. #if defined(PNG_READ_DITHER_SUPPORTED)
  167919. if (png_ptr->transformations & PNG_DITHER)
  167920. {
  167921. if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  167922. (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&
  167923. png_ptr->palette_lookup && info_ptr->bit_depth == 8)
  167924. {
  167925. info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
  167926. }
  167927. }
  167928. #endif
  167929. #if defined(PNG_READ_PACK_SUPPORTED)
  167930. if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8))
  167931. info_ptr->bit_depth = 8;
  167932. #endif
  167933. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167934. info_ptr->channels = 1;
  167935. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  167936. info_ptr->channels = 3;
  167937. else
  167938. info_ptr->channels = 1;
  167939. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  167940. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  167941. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  167942. #endif
  167943. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  167944. info_ptr->channels++;
  167945. #if defined(PNG_READ_FILLER_SUPPORTED)
  167946. if ((png_ptr->transformations & PNG_FILLER) &&
  167947. ((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  167948. (info_ptr->color_type == PNG_COLOR_TYPE_GRAY)))
  167949. {
  167950. info_ptr->channels++;
  167951. #if !defined(PNG_1_0_X)
  167952. if (png_ptr->transformations & PNG_ADD_ALPHA)
  167953. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  167954. #endif
  167955. }
  167956. #endif
  167957. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \
  167958. defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  167959. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  167960. {
  167961. if(info_ptr->bit_depth < png_ptr->user_transform_depth)
  167962. info_ptr->bit_depth = png_ptr->user_transform_depth;
  167963. if(info_ptr->channels < png_ptr->user_transform_channels)
  167964. info_ptr->channels = png_ptr->user_transform_channels;
  167965. }
  167966. #endif
  167967. info_ptr->pixel_depth = (png_byte)(info_ptr->channels *
  167968. info_ptr->bit_depth);
  167969. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,info_ptr->width);
  167970. #if !defined(PNG_READ_EXPAND_SUPPORTED)
  167971. if(png_ptr)
  167972. return;
  167973. #endif
  167974. }
  167975. void /* PRIVATE */
  167976. png_do_read_transformations(png_structp png_ptr)
  167977. {
  167978. png_debug(1, "in png_do_read_transformations\n");
  167979. if (png_ptr->row_buf == NULL)
  167980. {
  167981. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  167982. char msg[50];
  167983. png_snprintf2(msg, 50,
  167984. "NULL row buffer for row %ld, pass %d", png_ptr->row_number,
  167985. png_ptr->pass);
  167986. png_error(png_ptr, msg);
  167987. #else
  167988. png_error(png_ptr, "NULL row buffer");
  167989. #endif
  167990. }
  167991. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167992. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  167993. #if (PNG_WARN_UNINITIALIZED_ROW==1)
  167994. png_error(png_ptr, "Uninitialized row");
  167995. #else
  167996. png_warning(png_ptr, "Uninitialized row");
  167997. #endif
  167998. #endif
  167999. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168000. if (png_ptr->transformations & PNG_EXPAND)
  168001. {
  168002. if (png_ptr->row_info.color_type == PNG_COLOR_TYPE_PALETTE)
  168003. {
  168004. png_do_expand_palette(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168005. png_ptr->palette, png_ptr->trans, png_ptr->num_trans);
  168006. }
  168007. else
  168008. {
  168009. if (png_ptr->num_trans &&
  168010. (png_ptr->transformations & PNG_EXPAND_tRNS))
  168011. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168012. &(png_ptr->trans_values));
  168013. else
  168014. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168015. NULL);
  168016. }
  168017. }
  168018. #endif
  168019. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  168020. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  168021. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168022. PNG_FLAG_FILLER_AFTER | (png_ptr->flags & PNG_FLAG_STRIP_ALPHA));
  168023. #endif
  168024. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168025. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  168026. {
  168027. int rgb_error =
  168028. png_do_rgb_to_gray(png_ptr, &(png_ptr->row_info), png_ptr->row_buf + 1);
  168029. if(rgb_error)
  168030. {
  168031. png_ptr->rgb_to_gray_status=1;
  168032. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168033. PNG_RGB_TO_GRAY_WARN)
  168034. png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168035. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168036. PNG_RGB_TO_GRAY_ERR)
  168037. png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168038. }
  168039. }
  168040. #endif
  168041. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168042. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168043. !(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168044. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168045. #endif
  168046. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168047. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  168048. ((png_ptr->num_trans != 0 ) ||
  168049. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA)))
  168050. png_do_background(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168051. &(png_ptr->trans_values), &(png_ptr->background)
  168052. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168053. , &(png_ptr->background_1),
  168054. png_ptr->gamma_table, png_ptr->gamma_from_1,
  168055. png_ptr->gamma_to_1, png_ptr->gamma_16_table,
  168056. png_ptr->gamma_16_from_1, png_ptr->gamma_16_to_1,
  168057. png_ptr->gamma_shift
  168058. #endif
  168059. );
  168060. #endif
  168061. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168062. if ((png_ptr->transformations & PNG_GAMMA) &&
  168063. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168064. !((png_ptr->transformations & PNG_BACKGROUND) &&
  168065. ((png_ptr->num_trans != 0) ||
  168066. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
  168067. #endif
  168068. (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
  168069. png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168070. png_ptr->gamma_table, png_ptr->gamma_16_table,
  168071. png_ptr->gamma_shift);
  168072. #endif
  168073. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168074. if (png_ptr->transformations & PNG_16_TO_8)
  168075. png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168076. #endif
  168077. #if defined(PNG_READ_DITHER_SUPPORTED)
  168078. if (png_ptr->transformations & PNG_DITHER)
  168079. {
  168080. png_do_dither((png_row_infop)&(png_ptr->row_info), png_ptr->row_buf + 1,
  168081. png_ptr->palette_lookup, png_ptr->dither_index);
  168082. if(png_ptr->row_info.rowbytes == (png_uint_32)0)
  168083. png_error(png_ptr, "png_do_dither returned rowbytes=0");
  168084. }
  168085. #endif
  168086. #if defined(PNG_READ_INVERT_SUPPORTED)
  168087. if (png_ptr->transformations & PNG_INVERT_MONO)
  168088. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168089. #endif
  168090. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168091. if (png_ptr->transformations & PNG_SHIFT)
  168092. png_do_unshift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168093. &(png_ptr->shift));
  168094. #endif
  168095. #if defined(PNG_READ_PACK_SUPPORTED)
  168096. if (png_ptr->transformations & PNG_PACK)
  168097. png_do_unpack(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168098. #endif
  168099. #if defined(PNG_READ_BGR_SUPPORTED)
  168100. if (png_ptr->transformations & PNG_BGR)
  168101. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168102. #endif
  168103. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  168104. if (png_ptr->transformations & PNG_PACKSWAP)
  168105. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168106. #endif
  168107. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168108. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168109. (png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168110. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168111. #endif
  168112. #if defined(PNG_READ_FILLER_SUPPORTED)
  168113. if (png_ptr->transformations & PNG_FILLER)
  168114. png_do_read_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168115. (png_uint_32)png_ptr->filler, png_ptr->flags);
  168116. #endif
  168117. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168118. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  168119. png_do_read_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168120. #endif
  168121. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168122. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  168123. png_do_read_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168124. #endif
  168125. #if defined(PNG_READ_SWAP_SUPPORTED)
  168126. if (png_ptr->transformations & PNG_SWAP_BYTES)
  168127. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168128. #endif
  168129. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  168130. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  168131. {
  168132. if(png_ptr->read_user_transform_fn != NULL)
  168133. (*(png_ptr->read_user_transform_fn)) /* user read transform function */
  168134. (png_ptr, /* png_ptr */
  168135. &(png_ptr->row_info), /* row_info: */
  168136. png_ptr->row_buf + 1); /* start of pixel data for row */
  168137. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  168138. if(png_ptr->user_transform_depth)
  168139. png_ptr->row_info.bit_depth = png_ptr->user_transform_depth;
  168140. if(png_ptr->user_transform_channels)
  168141. png_ptr->row_info.channels = png_ptr->user_transform_channels;
  168142. #endif
  168143. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  168144. png_ptr->row_info.channels);
  168145. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  168146. png_ptr->row_info.width);
  168147. }
  168148. #endif
  168149. }
  168150. #if defined(PNG_READ_PACK_SUPPORTED)
  168151. void /* PRIVATE */
  168152. png_do_unpack(png_row_infop row_info, png_bytep row)
  168153. {
  168154. png_debug(1, "in png_do_unpack\n");
  168155. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168156. if (row != NULL && row_info != NULL && row_info->bit_depth < 8)
  168157. #else
  168158. if (row_info->bit_depth < 8)
  168159. #endif
  168160. {
  168161. png_uint_32 i;
  168162. png_uint_32 row_width=row_info->width;
  168163. switch (row_info->bit_depth)
  168164. {
  168165. case 1:
  168166. {
  168167. png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
  168168. png_bytep dp = row + (png_size_t)row_width - 1;
  168169. png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07);
  168170. for (i = 0; i < row_width; i++)
  168171. {
  168172. *dp = (png_byte)((*sp >> shift) & 0x01);
  168173. if (shift == 7)
  168174. {
  168175. shift = 0;
  168176. sp--;
  168177. }
  168178. else
  168179. shift++;
  168180. dp--;
  168181. }
  168182. break;
  168183. }
  168184. case 2:
  168185. {
  168186. png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
  168187. png_bytep dp = row + (png_size_t)row_width - 1;
  168188. png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  168189. for (i = 0; i < row_width; i++)
  168190. {
  168191. *dp = (png_byte)((*sp >> shift) & 0x03);
  168192. if (shift == 6)
  168193. {
  168194. shift = 0;
  168195. sp--;
  168196. }
  168197. else
  168198. shift += 2;
  168199. dp--;
  168200. }
  168201. break;
  168202. }
  168203. case 4:
  168204. {
  168205. png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
  168206. png_bytep dp = row + (png_size_t)row_width - 1;
  168207. png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  168208. for (i = 0; i < row_width; i++)
  168209. {
  168210. *dp = (png_byte)((*sp >> shift) & 0x0f);
  168211. if (shift == 4)
  168212. {
  168213. shift = 0;
  168214. sp--;
  168215. }
  168216. else
  168217. shift = 4;
  168218. dp--;
  168219. }
  168220. break;
  168221. }
  168222. }
  168223. row_info->bit_depth = 8;
  168224. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168225. row_info->rowbytes = row_width * row_info->channels;
  168226. }
  168227. }
  168228. #endif
  168229. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168230. void /* PRIVATE */
  168231. png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
  168232. {
  168233. png_debug(1, "in png_do_unshift\n");
  168234. if (
  168235. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168236. row != NULL && row_info != NULL && sig_bits != NULL &&
  168237. #endif
  168238. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  168239. {
  168240. int shift[4];
  168241. int channels = 0;
  168242. int c;
  168243. png_uint_16 value = 0;
  168244. png_uint_32 row_width = row_info->width;
  168245. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  168246. {
  168247. shift[channels++] = row_info->bit_depth - sig_bits->red;
  168248. shift[channels++] = row_info->bit_depth - sig_bits->green;
  168249. shift[channels++] = row_info->bit_depth - sig_bits->blue;
  168250. }
  168251. else
  168252. {
  168253. shift[channels++] = row_info->bit_depth - sig_bits->gray;
  168254. }
  168255. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  168256. {
  168257. shift[channels++] = row_info->bit_depth - sig_bits->alpha;
  168258. }
  168259. for (c = 0; c < channels; c++)
  168260. {
  168261. if (shift[c] <= 0)
  168262. shift[c] = 0;
  168263. else
  168264. value = 1;
  168265. }
  168266. if (!value)
  168267. return;
  168268. switch (row_info->bit_depth)
  168269. {
  168270. case 2:
  168271. {
  168272. png_bytep bp;
  168273. png_uint_32 i;
  168274. png_uint_32 istop = row_info->rowbytes;
  168275. for (bp = row, i = 0; i < istop; i++)
  168276. {
  168277. *bp >>= 1;
  168278. *bp++ &= 0x55;
  168279. }
  168280. break;
  168281. }
  168282. case 4:
  168283. {
  168284. png_bytep bp = row;
  168285. png_uint_32 i;
  168286. png_uint_32 istop = row_info->rowbytes;
  168287. png_byte mask = (png_byte)((((int)0xf0 >> shift[0]) & (int)0xf0) |
  168288. (png_byte)((int)0xf >> shift[0]));
  168289. for (i = 0; i < istop; i++)
  168290. {
  168291. *bp >>= shift[0];
  168292. *bp++ &= mask;
  168293. }
  168294. break;
  168295. }
  168296. case 8:
  168297. {
  168298. png_bytep bp = row;
  168299. png_uint_32 i;
  168300. png_uint_32 istop = row_width * channels;
  168301. for (i = 0; i < istop; i++)
  168302. {
  168303. *bp++ >>= shift[i%channels];
  168304. }
  168305. break;
  168306. }
  168307. case 16:
  168308. {
  168309. png_bytep bp = row;
  168310. png_uint_32 i;
  168311. png_uint_32 istop = channels * row_width;
  168312. for (i = 0; i < istop; i++)
  168313. {
  168314. value = (png_uint_16)((*bp << 8) + *(bp + 1));
  168315. value >>= shift[i%channels];
  168316. *bp++ = (png_byte)(value >> 8);
  168317. *bp++ = (png_byte)(value & 0xff);
  168318. }
  168319. break;
  168320. }
  168321. }
  168322. }
  168323. }
  168324. #endif
  168325. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168326. void /* PRIVATE */
  168327. png_do_chop(png_row_infop row_info, png_bytep row)
  168328. {
  168329. png_debug(1, "in png_do_chop\n");
  168330. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168331. if (row != NULL && row_info != NULL && row_info->bit_depth == 16)
  168332. #else
  168333. if (row_info->bit_depth == 16)
  168334. #endif
  168335. {
  168336. png_bytep sp = row;
  168337. png_bytep dp = row;
  168338. png_uint_32 i;
  168339. png_uint_32 istop = row_info->width * row_info->channels;
  168340. for (i = 0; i<istop; i++, sp += 2, dp++)
  168341. {
  168342. #if defined(PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED)
  168343. *dp = *sp + ((((int)(*(sp + 1)) - *sp) > 128) ? 1 : 0);
  168344. #else
  168345. *dp = *sp;
  168346. #endif
  168347. }
  168348. row_info->bit_depth = 8;
  168349. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168350. row_info->rowbytes = row_info->width * row_info->channels;
  168351. }
  168352. }
  168353. #endif
  168354. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168355. void /* PRIVATE */
  168356. png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
  168357. {
  168358. png_debug(1, "in png_do_read_swap_alpha\n");
  168359. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168360. if (row != NULL && row_info != NULL)
  168361. #endif
  168362. {
  168363. png_uint_32 row_width = row_info->width;
  168364. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168365. {
  168366. if (row_info->bit_depth == 8)
  168367. {
  168368. png_bytep sp = row + row_info->rowbytes;
  168369. png_bytep dp = sp;
  168370. png_byte save;
  168371. png_uint_32 i;
  168372. for (i = 0; i < row_width; i++)
  168373. {
  168374. save = *(--sp);
  168375. *(--dp) = *(--sp);
  168376. *(--dp) = *(--sp);
  168377. *(--dp) = *(--sp);
  168378. *(--dp) = save;
  168379. }
  168380. }
  168381. else
  168382. {
  168383. png_bytep sp = row + row_info->rowbytes;
  168384. png_bytep dp = sp;
  168385. png_byte save[2];
  168386. png_uint_32 i;
  168387. for (i = 0; i < row_width; i++)
  168388. {
  168389. save[0] = *(--sp);
  168390. save[1] = *(--sp);
  168391. *(--dp) = *(--sp);
  168392. *(--dp) = *(--sp);
  168393. *(--dp) = *(--sp);
  168394. *(--dp) = *(--sp);
  168395. *(--dp) = *(--sp);
  168396. *(--dp) = *(--sp);
  168397. *(--dp) = save[0];
  168398. *(--dp) = save[1];
  168399. }
  168400. }
  168401. }
  168402. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168403. {
  168404. if (row_info->bit_depth == 8)
  168405. {
  168406. png_bytep sp = row + row_info->rowbytes;
  168407. png_bytep dp = sp;
  168408. png_byte save;
  168409. png_uint_32 i;
  168410. for (i = 0; i < row_width; i++)
  168411. {
  168412. save = *(--sp);
  168413. *(--dp) = *(--sp);
  168414. *(--dp) = save;
  168415. }
  168416. }
  168417. else
  168418. {
  168419. png_bytep sp = row + row_info->rowbytes;
  168420. png_bytep dp = sp;
  168421. png_byte save[2];
  168422. png_uint_32 i;
  168423. for (i = 0; i < row_width; i++)
  168424. {
  168425. save[0] = *(--sp);
  168426. save[1] = *(--sp);
  168427. *(--dp) = *(--sp);
  168428. *(--dp) = *(--sp);
  168429. *(--dp) = save[0];
  168430. *(--dp) = save[1];
  168431. }
  168432. }
  168433. }
  168434. }
  168435. }
  168436. #endif
  168437. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168438. void /* PRIVATE */
  168439. png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
  168440. {
  168441. png_debug(1, "in png_do_read_invert_alpha\n");
  168442. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168443. if (row != NULL && row_info != NULL)
  168444. #endif
  168445. {
  168446. png_uint_32 row_width = row_info->width;
  168447. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168448. {
  168449. if (row_info->bit_depth == 8)
  168450. {
  168451. png_bytep sp = row + row_info->rowbytes;
  168452. png_bytep dp = sp;
  168453. png_uint_32 i;
  168454. for (i = 0; i < row_width; i++)
  168455. {
  168456. *(--dp) = (png_byte)(255 - *(--sp));
  168457. sp-=3;
  168458. dp=sp;
  168459. }
  168460. }
  168461. else
  168462. {
  168463. png_bytep sp = row + row_info->rowbytes;
  168464. png_bytep dp = sp;
  168465. png_uint_32 i;
  168466. for (i = 0; i < row_width; i++)
  168467. {
  168468. *(--dp) = (png_byte)(255 - *(--sp));
  168469. *(--dp) = (png_byte)(255 - *(--sp));
  168470. sp-=6;
  168471. dp=sp;
  168472. }
  168473. }
  168474. }
  168475. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168476. {
  168477. if (row_info->bit_depth == 8)
  168478. {
  168479. png_bytep sp = row + row_info->rowbytes;
  168480. png_bytep dp = sp;
  168481. png_uint_32 i;
  168482. for (i = 0; i < row_width; i++)
  168483. {
  168484. *(--dp) = (png_byte)(255 - *(--sp));
  168485. *(--dp) = *(--sp);
  168486. }
  168487. }
  168488. else
  168489. {
  168490. png_bytep sp = row + row_info->rowbytes;
  168491. png_bytep dp = sp;
  168492. png_uint_32 i;
  168493. for (i = 0; i < row_width; i++)
  168494. {
  168495. *(--dp) = (png_byte)(255 - *(--sp));
  168496. *(--dp) = (png_byte)(255 - *(--sp));
  168497. sp-=2;
  168498. dp=sp;
  168499. }
  168500. }
  168501. }
  168502. }
  168503. }
  168504. #endif
  168505. #if defined(PNG_READ_FILLER_SUPPORTED)
  168506. void /* PRIVATE */
  168507. png_do_read_filler(png_row_infop row_info, png_bytep row,
  168508. png_uint_32 filler, png_uint_32 flags)
  168509. {
  168510. png_uint_32 i;
  168511. png_uint_32 row_width = row_info->width;
  168512. png_byte hi_filler = (png_byte)((filler>>8) & 0xff);
  168513. png_byte lo_filler = (png_byte)(filler & 0xff);
  168514. png_debug(1, "in png_do_read_filler\n");
  168515. if (
  168516. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168517. row != NULL && row_info != NULL &&
  168518. #endif
  168519. row_info->color_type == PNG_COLOR_TYPE_GRAY)
  168520. {
  168521. if(row_info->bit_depth == 8)
  168522. {
  168523. if (flags & PNG_FLAG_FILLER_AFTER)
  168524. {
  168525. png_bytep sp = row + (png_size_t)row_width;
  168526. png_bytep dp = sp + (png_size_t)row_width;
  168527. for (i = 1; i < row_width; i++)
  168528. {
  168529. *(--dp) = lo_filler;
  168530. *(--dp) = *(--sp);
  168531. }
  168532. *(--dp) = lo_filler;
  168533. row_info->channels = 2;
  168534. row_info->pixel_depth = 16;
  168535. row_info->rowbytes = row_width * 2;
  168536. }
  168537. else
  168538. {
  168539. png_bytep sp = row + (png_size_t)row_width;
  168540. png_bytep dp = sp + (png_size_t)row_width;
  168541. for (i = 0; i < row_width; i++)
  168542. {
  168543. *(--dp) = *(--sp);
  168544. *(--dp) = lo_filler;
  168545. }
  168546. row_info->channels = 2;
  168547. row_info->pixel_depth = 16;
  168548. row_info->rowbytes = row_width * 2;
  168549. }
  168550. }
  168551. else if(row_info->bit_depth == 16)
  168552. {
  168553. if (flags & PNG_FLAG_FILLER_AFTER)
  168554. {
  168555. png_bytep sp = row + (png_size_t)row_width * 2;
  168556. png_bytep dp = sp + (png_size_t)row_width * 2;
  168557. for (i = 1; i < row_width; i++)
  168558. {
  168559. *(--dp) = hi_filler;
  168560. *(--dp) = lo_filler;
  168561. *(--dp) = *(--sp);
  168562. *(--dp) = *(--sp);
  168563. }
  168564. *(--dp) = hi_filler;
  168565. *(--dp) = lo_filler;
  168566. row_info->channels = 2;
  168567. row_info->pixel_depth = 32;
  168568. row_info->rowbytes = row_width * 4;
  168569. }
  168570. else
  168571. {
  168572. png_bytep sp = row + (png_size_t)row_width * 2;
  168573. png_bytep dp = sp + (png_size_t)row_width * 2;
  168574. for (i = 0; i < row_width; i++)
  168575. {
  168576. *(--dp) = *(--sp);
  168577. *(--dp) = *(--sp);
  168578. *(--dp) = hi_filler;
  168579. *(--dp) = lo_filler;
  168580. }
  168581. row_info->channels = 2;
  168582. row_info->pixel_depth = 32;
  168583. row_info->rowbytes = row_width * 4;
  168584. }
  168585. }
  168586. } /* COLOR_TYPE == GRAY */
  168587. else if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  168588. {
  168589. if(row_info->bit_depth == 8)
  168590. {
  168591. if (flags & PNG_FLAG_FILLER_AFTER)
  168592. {
  168593. png_bytep sp = row + (png_size_t)row_width * 3;
  168594. png_bytep dp = sp + (png_size_t)row_width;
  168595. for (i = 1; i < row_width; i++)
  168596. {
  168597. *(--dp) = lo_filler;
  168598. *(--dp) = *(--sp);
  168599. *(--dp) = *(--sp);
  168600. *(--dp) = *(--sp);
  168601. }
  168602. *(--dp) = lo_filler;
  168603. row_info->channels = 4;
  168604. row_info->pixel_depth = 32;
  168605. row_info->rowbytes = row_width * 4;
  168606. }
  168607. else
  168608. {
  168609. png_bytep sp = row + (png_size_t)row_width * 3;
  168610. png_bytep dp = sp + (png_size_t)row_width;
  168611. for (i = 0; i < row_width; i++)
  168612. {
  168613. *(--dp) = *(--sp);
  168614. *(--dp) = *(--sp);
  168615. *(--dp) = *(--sp);
  168616. *(--dp) = lo_filler;
  168617. }
  168618. row_info->channels = 4;
  168619. row_info->pixel_depth = 32;
  168620. row_info->rowbytes = row_width * 4;
  168621. }
  168622. }
  168623. else if(row_info->bit_depth == 16)
  168624. {
  168625. if (flags & PNG_FLAG_FILLER_AFTER)
  168626. {
  168627. png_bytep sp = row + (png_size_t)row_width * 6;
  168628. png_bytep dp = sp + (png_size_t)row_width * 2;
  168629. for (i = 1; i < row_width; i++)
  168630. {
  168631. *(--dp) = hi_filler;
  168632. *(--dp) = lo_filler;
  168633. *(--dp) = *(--sp);
  168634. *(--dp) = *(--sp);
  168635. *(--dp) = *(--sp);
  168636. *(--dp) = *(--sp);
  168637. *(--dp) = *(--sp);
  168638. *(--dp) = *(--sp);
  168639. }
  168640. *(--dp) = hi_filler;
  168641. *(--dp) = lo_filler;
  168642. row_info->channels = 4;
  168643. row_info->pixel_depth = 64;
  168644. row_info->rowbytes = row_width * 8;
  168645. }
  168646. else
  168647. {
  168648. png_bytep sp = row + (png_size_t)row_width * 6;
  168649. png_bytep dp = sp + (png_size_t)row_width * 2;
  168650. for (i = 0; i < row_width; i++)
  168651. {
  168652. *(--dp) = *(--sp);
  168653. *(--dp) = *(--sp);
  168654. *(--dp) = *(--sp);
  168655. *(--dp) = *(--sp);
  168656. *(--dp) = *(--sp);
  168657. *(--dp) = *(--sp);
  168658. *(--dp) = hi_filler;
  168659. *(--dp) = lo_filler;
  168660. }
  168661. row_info->channels = 4;
  168662. row_info->pixel_depth = 64;
  168663. row_info->rowbytes = row_width * 8;
  168664. }
  168665. }
  168666. } /* COLOR_TYPE == RGB */
  168667. }
  168668. #endif
  168669. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168670. void /* PRIVATE */
  168671. png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
  168672. {
  168673. png_uint_32 i;
  168674. png_uint_32 row_width = row_info->width;
  168675. png_debug(1, "in png_do_gray_to_rgb\n");
  168676. if (row_info->bit_depth >= 8 &&
  168677. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168678. row != NULL && row_info != NULL &&
  168679. #endif
  168680. !(row_info->color_type & PNG_COLOR_MASK_COLOR))
  168681. {
  168682. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  168683. {
  168684. if (row_info->bit_depth == 8)
  168685. {
  168686. png_bytep sp = row + (png_size_t)row_width - 1;
  168687. png_bytep dp = sp + (png_size_t)row_width * 2;
  168688. for (i = 0; i < row_width; i++)
  168689. {
  168690. *(dp--) = *sp;
  168691. *(dp--) = *sp;
  168692. *(dp--) = *(sp--);
  168693. }
  168694. }
  168695. else
  168696. {
  168697. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  168698. png_bytep dp = sp + (png_size_t)row_width * 4;
  168699. for (i = 0; i < row_width; i++)
  168700. {
  168701. *(dp--) = *sp;
  168702. *(dp--) = *(sp - 1);
  168703. *(dp--) = *sp;
  168704. *(dp--) = *(sp - 1);
  168705. *(dp--) = *(sp--);
  168706. *(dp--) = *(sp--);
  168707. }
  168708. }
  168709. }
  168710. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168711. {
  168712. if (row_info->bit_depth == 8)
  168713. {
  168714. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  168715. png_bytep dp = sp + (png_size_t)row_width * 2;
  168716. for (i = 0; i < row_width; i++)
  168717. {
  168718. *(dp--) = *(sp--);
  168719. *(dp--) = *sp;
  168720. *(dp--) = *sp;
  168721. *(dp--) = *(sp--);
  168722. }
  168723. }
  168724. else
  168725. {
  168726. png_bytep sp = row + (png_size_t)row_width * 4 - 1;
  168727. png_bytep dp = sp + (png_size_t)row_width * 4;
  168728. for (i = 0; i < row_width; i++)
  168729. {
  168730. *(dp--) = *(sp--);
  168731. *(dp--) = *(sp--);
  168732. *(dp--) = *sp;
  168733. *(dp--) = *(sp - 1);
  168734. *(dp--) = *sp;
  168735. *(dp--) = *(sp - 1);
  168736. *(dp--) = *(sp--);
  168737. *(dp--) = *(sp--);
  168738. }
  168739. }
  168740. }
  168741. row_info->channels += (png_byte)2;
  168742. row_info->color_type |= PNG_COLOR_MASK_COLOR;
  168743. row_info->pixel_depth = (png_byte)(row_info->channels *
  168744. row_info->bit_depth);
  168745. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  168746. }
  168747. }
  168748. #endif
  168749. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168750. int /* PRIVATE */
  168751. png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
  168752. {
  168753. png_uint_32 i;
  168754. png_uint_32 row_width = row_info->width;
  168755. int rgb_error = 0;
  168756. png_debug(1, "in png_do_rgb_to_gray\n");
  168757. if (
  168758. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168759. row != NULL && row_info != NULL &&
  168760. #endif
  168761. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  168762. {
  168763. png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
  168764. png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
  168765. png_uint_32 bc = png_ptr->rgb_to_gray_blue_coeff;
  168766. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  168767. {
  168768. if (row_info->bit_depth == 8)
  168769. {
  168770. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168771. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  168772. {
  168773. png_bytep sp = row;
  168774. png_bytep dp = row;
  168775. for (i = 0; i < row_width; i++)
  168776. {
  168777. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  168778. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  168779. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  168780. if(red != green || red != blue)
  168781. {
  168782. rgb_error |= 1;
  168783. *(dp++) = png_ptr->gamma_from_1[
  168784. (rc*red+gc*green+bc*blue)>>15];
  168785. }
  168786. else
  168787. *(dp++) = *(sp-1);
  168788. }
  168789. }
  168790. else
  168791. #endif
  168792. {
  168793. png_bytep sp = row;
  168794. png_bytep dp = row;
  168795. for (i = 0; i < row_width; i++)
  168796. {
  168797. png_byte red = *(sp++);
  168798. png_byte green = *(sp++);
  168799. png_byte blue = *(sp++);
  168800. if(red != green || red != blue)
  168801. {
  168802. rgb_error |= 1;
  168803. *(dp++) = (png_byte)((rc*red+gc*green+bc*blue)>>15);
  168804. }
  168805. else
  168806. *(dp++) = *(sp-1);
  168807. }
  168808. }
  168809. }
  168810. else /* RGB bit_depth == 16 */
  168811. {
  168812. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168813. if (png_ptr->gamma_16_to_1 != NULL &&
  168814. png_ptr->gamma_16_from_1 != NULL)
  168815. {
  168816. png_bytep sp = row;
  168817. png_bytep dp = row;
  168818. for (i = 0; i < row_width; i++)
  168819. {
  168820. png_uint_16 red, green, blue, w;
  168821. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168822. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168823. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168824. if(red == green && red == blue)
  168825. w = red;
  168826. else
  168827. {
  168828. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  168829. png_ptr->gamma_shift][red>>8];
  168830. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  168831. png_ptr->gamma_shift][green>>8];
  168832. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  168833. png_ptr->gamma_shift][blue>>8];
  168834. png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1
  168835. + bc*blue_1)>>15);
  168836. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  168837. png_ptr->gamma_shift][gray16 >> 8];
  168838. rgb_error |= 1;
  168839. }
  168840. *(dp++) = (png_byte)((w>>8) & 0xff);
  168841. *(dp++) = (png_byte)(w & 0xff);
  168842. }
  168843. }
  168844. else
  168845. #endif
  168846. {
  168847. png_bytep sp = row;
  168848. png_bytep dp = row;
  168849. for (i = 0; i < row_width; i++)
  168850. {
  168851. png_uint_16 red, green, blue, gray16;
  168852. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168853. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168854. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168855. if(red != green || red != blue)
  168856. rgb_error |= 1;
  168857. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  168858. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  168859. *(dp++) = (png_byte)(gray16 & 0xff);
  168860. }
  168861. }
  168862. }
  168863. }
  168864. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168865. {
  168866. if (row_info->bit_depth == 8)
  168867. {
  168868. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168869. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  168870. {
  168871. png_bytep sp = row;
  168872. png_bytep dp = row;
  168873. for (i = 0; i < row_width; i++)
  168874. {
  168875. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  168876. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  168877. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  168878. if(red != green || red != blue)
  168879. rgb_error |= 1;
  168880. *(dp++) = png_ptr->gamma_from_1
  168881. [(rc*red + gc*green + bc*blue)>>15];
  168882. *(dp++) = *(sp++); /* alpha */
  168883. }
  168884. }
  168885. else
  168886. #endif
  168887. {
  168888. png_bytep sp = row;
  168889. png_bytep dp = row;
  168890. for (i = 0; i < row_width; i++)
  168891. {
  168892. png_byte red = *(sp++);
  168893. png_byte green = *(sp++);
  168894. png_byte blue = *(sp++);
  168895. if(red != green || red != blue)
  168896. rgb_error |= 1;
  168897. *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15);
  168898. *(dp++) = *(sp++); /* alpha */
  168899. }
  168900. }
  168901. }
  168902. else /* RGBA bit_depth == 16 */
  168903. {
  168904. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168905. if (png_ptr->gamma_16_to_1 != NULL &&
  168906. png_ptr->gamma_16_from_1 != NULL)
  168907. {
  168908. png_bytep sp = row;
  168909. png_bytep dp = row;
  168910. for (i = 0; i < row_width; i++)
  168911. {
  168912. png_uint_16 red, green, blue, w;
  168913. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168914. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168915. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168916. if(red == green && red == blue)
  168917. w = red;
  168918. else
  168919. {
  168920. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  168921. png_ptr->gamma_shift][red>>8];
  168922. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  168923. png_ptr->gamma_shift][green>>8];
  168924. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  168925. png_ptr->gamma_shift][blue>>8];
  168926. png_uint_16 gray16 = (png_uint_16)((rc * red_1
  168927. + gc * green_1 + bc * blue_1)>>15);
  168928. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  168929. png_ptr->gamma_shift][gray16 >> 8];
  168930. rgb_error |= 1;
  168931. }
  168932. *(dp++) = (png_byte)((w>>8) & 0xff);
  168933. *(dp++) = (png_byte)(w & 0xff);
  168934. *(dp++) = *(sp++); /* alpha */
  168935. *(dp++) = *(sp++);
  168936. }
  168937. }
  168938. else
  168939. #endif
  168940. {
  168941. png_bytep sp = row;
  168942. png_bytep dp = row;
  168943. for (i = 0; i < row_width; i++)
  168944. {
  168945. png_uint_16 red, green, blue, gray16;
  168946. red = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  168947. green = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  168948. blue = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  168949. if(red != green || red != blue)
  168950. rgb_error |= 1;
  168951. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  168952. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  168953. *(dp++) = (png_byte)(gray16 & 0xff);
  168954. *(dp++) = *(sp++); /* alpha */
  168955. *(dp++) = *(sp++);
  168956. }
  168957. }
  168958. }
  168959. }
  168960. row_info->channels -= (png_byte)2;
  168961. row_info->color_type &= ~PNG_COLOR_MASK_COLOR;
  168962. row_info->pixel_depth = (png_byte)(row_info->channels *
  168963. row_info->bit_depth);
  168964. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  168965. }
  168966. return rgb_error;
  168967. }
  168968. #endif
  168969. void PNGAPI
  168970. png_build_grayscale_palette(int bit_depth, png_colorp palette)
  168971. {
  168972. int num_palette;
  168973. int color_inc;
  168974. int i;
  168975. int v;
  168976. png_debug(1, "in png_do_build_grayscale_palette\n");
  168977. if (palette == NULL)
  168978. return;
  168979. switch (bit_depth)
  168980. {
  168981. case 1:
  168982. num_palette = 2;
  168983. color_inc = 0xff;
  168984. break;
  168985. case 2:
  168986. num_palette = 4;
  168987. color_inc = 0x55;
  168988. break;
  168989. case 4:
  168990. num_palette = 16;
  168991. color_inc = 0x11;
  168992. break;
  168993. case 8:
  168994. num_palette = 256;
  168995. color_inc = 1;
  168996. break;
  168997. default:
  168998. num_palette = 0;
  168999. color_inc = 0;
  169000. break;
  169001. }
  169002. for (i = 0, v = 0; i < num_palette; i++, v += color_inc)
  169003. {
  169004. palette[i].red = (png_byte)v;
  169005. palette[i].green = (png_byte)v;
  169006. palette[i].blue = (png_byte)v;
  169007. }
  169008. }
  169009. #if defined(PNG_READ_DITHER_SUPPORTED) && defined(PNG_CORRECT_PALETTE_SUPPORTED)
  169010. void /* PRIVATE */
  169011. png_correct_palette(png_structp png_ptr, png_colorp palette,
  169012. int num_palette)
  169013. {
  169014. png_debug(1, "in png_correct_palette\n");
  169015. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  169016. defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  169017. if (png_ptr->transformations & (PNG_GAMMA | PNG_BACKGROUND))
  169018. {
  169019. png_color back, back_1;
  169020. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  169021. {
  169022. back.red = png_ptr->gamma_table[png_ptr->background.red];
  169023. back.green = png_ptr->gamma_table[png_ptr->background.green];
  169024. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  169025. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  169026. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  169027. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  169028. }
  169029. else
  169030. {
  169031. double g;
  169032. g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma);
  169033. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_SCREEN ||
  169034. fabs(g - 1.0) < PNG_GAMMA_THRESHOLD)
  169035. {
  169036. back.red = png_ptr->background.red;
  169037. back.green = png_ptr->background.green;
  169038. back.blue = png_ptr->background.blue;
  169039. }
  169040. else
  169041. {
  169042. back.red =
  169043. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169044. 255.0 + 0.5);
  169045. back.green =
  169046. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169047. 255.0 + 0.5);
  169048. back.blue =
  169049. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169050. 255.0 + 0.5);
  169051. }
  169052. g = 1.0 / png_ptr->background_gamma;
  169053. back_1.red =
  169054. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169055. 255.0 + 0.5);
  169056. back_1.green =
  169057. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169058. 255.0 + 0.5);
  169059. back_1.blue =
  169060. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169061. 255.0 + 0.5);
  169062. }
  169063. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169064. {
  169065. png_uint_32 i;
  169066. for (i = 0; i < (png_uint_32)num_palette; i++)
  169067. {
  169068. if (i < png_ptr->num_trans && png_ptr->trans[i] == 0)
  169069. {
  169070. palette[i] = back;
  169071. }
  169072. else if (i < png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  169073. {
  169074. png_byte v, w;
  169075. v = png_ptr->gamma_to_1[png_ptr->palette[i].red];
  169076. png_composite(w, v, png_ptr->trans[i], back_1.red);
  169077. palette[i].red = png_ptr->gamma_from_1[w];
  169078. v = png_ptr->gamma_to_1[png_ptr->palette[i].green];
  169079. png_composite(w, v, png_ptr->trans[i], back_1.green);
  169080. palette[i].green = png_ptr->gamma_from_1[w];
  169081. v = png_ptr->gamma_to_1[png_ptr->palette[i].blue];
  169082. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  169083. palette[i].blue = png_ptr->gamma_from_1[w];
  169084. }
  169085. else
  169086. {
  169087. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169088. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169089. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169090. }
  169091. }
  169092. }
  169093. else
  169094. {
  169095. int i;
  169096. for (i = 0; i < num_palette; i++)
  169097. {
  169098. if (palette[i].red == (png_byte)png_ptr->trans_values.gray)
  169099. {
  169100. palette[i] = back;
  169101. }
  169102. else
  169103. {
  169104. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169105. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169106. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169107. }
  169108. }
  169109. }
  169110. }
  169111. else
  169112. #endif
  169113. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169114. if (png_ptr->transformations & PNG_GAMMA)
  169115. {
  169116. int i;
  169117. for (i = 0; i < num_palette; i++)
  169118. {
  169119. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169120. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169121. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169122. }
  169123. }
  169124. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169125. else
  169126. #endif
  169127. #endif
  169128. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169129. if (png_ptr->transformations & PNG_BACKGROUND)
  169130. {
  169131. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169132. {
  169133. png_color back;
  169134. back.red = (png_byte)png_ptr->background.red;
  169135. back.green = (png_byte)png_ptr->background.green;
  169136. back.blue = (png_byte)png_ptr->background.blue;
  169137. for (i = 0; i < (int)png_ptr->num_trans; i++)
  169138. {
  169139. if (png_ptr->trans[i] == 0)
  169140. {
  169141. palette[i].red = back.red;
  169142. palette[i].green = back.green;
  169143. palette[i].blue = back.blue;
  169144. }
  169145. else if (png_ptr->trans[i] != 0xff)
  169146. {
  169147. png_composite(palette[i].red, png_ptr->palette[i].red,
  169148. png_ptr->trans[i], back.red);
  169149. png_composite(palette[i].green, png_ptr->palette[i].green,
  169150. png_ptr->trans[i], back.green);
  169151. png_composite(palette[i].blue, png_ptr->palette[i].blue,
  169152. png_ptr->trans[i], back.blue);
  169153. }
  169154. }
  169155. }
  169156. else /* assume grayscale palette (what else could it be?) */
  169157. {
  169158. int i;
  169159. for (i = 0; i < num_palette; i++)
  169160. {
  169161. if (i == (png_byte)png_ptr->trans_values.gray)
  169162. {
  169163. palette[i].red = (png_byte)png_ptr->background.red;
  169164. palette[i].green = (png_byte)png_ptr->background.green;
  169165. palette[i].blue = (png_byte)png_ptr->background.blue;
  169166. }
  169167. }
  169168. }
  169169. }
  169170. #endif
  169171. }
  169172. #endif
  169173. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169174. void /* PRIVATE */
  169175. png_do_background(png_row_infop row_info, png_bytep row,
  169176. png_color_16p trans_values, png_color_16p background
  169177. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169178. , png_color_16p background_1,
  169179. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  169180. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  169181. png_uint_16pp gamma_16_to_1, int gamma_shift
  169182. #endif
  169183. )
  169184. {
  169185. png_bytep sp, dp;
  169186. png_uint_32 i;
  169187. png_uint_32 row_width=row_info->width;
  169188. int shift;
  169189. png_debug(1, "in png_do_background\n");
  169190. if (background != NULL &&
  169191. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169192. row != NULL && row_info != NULL &&
  169193. #endif
  169194. (!(row_info->color_type & PNG_COLOR_MASK_ALPHA) ||
  169195. (row_info->color_type != PNG_COLOR_TYPE_PALETTE && trans_values)))
  169196. {
  169197. switch (row_info->color_type)
  169198. {
  169199. case PNG_COLOR_TYPE_GRAY:
  169200. {
  169201. switch (row_info->bit_depth)
  169202. {
  169203. case 1:
  169204. {
  169205. sp = row;
  169206. shift = 7;
  169207. for (i = 0; i < row_width; i++)
  169208. {
  169209. if ((png_uint_16)((*sp >> shift) & 0x01)
  169210. == trans_values->gray)
  169211. {
  169212. *sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  169213. *sp |= (png_byte)(background->gray << shift);
  169214. }
  169215. if (!shift)
  169216. {
  169217. shift = 7;
  169218. sp++;
  169219. }
  169220. else
  169221. shift--;
  169222. }
  169223. break;
  169224. }
  169225. case 2:
  169226. {
  169227. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169228. if (gamma_table != NULL)
  169229. {
  169230. sp = row;
  169231. shift = 6;
  169232. for (i = 0; i < row_width; i++)
  169233. {
  169234. if ((png_uint_16)((*sp >> shift) & 0x03)
  169235. == trans_values->gray)
  169236. {
  169237. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169238. *sp |= (png_byte)(background->gray << shift);
  169239. }
  169240. else
  169241. {
  169242. png_byte p = (png_byte)((*sp >> shift) & 0x03);
  169243. png_byte g = (png_byte)((gamma_table [p | (p << 2) |
  169244. (p << 4) | (p << 6)] >> 6) & 0x03);
  169245. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169246. *sp |= (png_byte)(g << shift);
  169247. }
  169248. if (!shift)
  169249. {
  169250. shift = 6;
  169251. sp++;
  169252. }
  169253. else
  169254. shift -= 2;
  169255. }
  169256. }
  169257. else
  169258. #endif
  169259. {
  169260. sp = row;
  169261. shift = 6;
  169262. for (i = 0; i < row_width; i++)
  169263. {
  169264. if ((png_uint_16)((*sp >> shift) & 0x03)
  169265. == trans_values->gray)
  169266. {
  169267. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169268. *sp |= (png_byte)(background->gray << shift);
  169269. }
  169270. if (!shift)
  169271. {
  169272. shift = 6;
  169273. sp++;
  169274. }
  169275. else
  169276. shift -= 2;
  169277. }
  169278. }
  169279. break;
  169280. }
  169281. case 4:
  169282. {
  169283. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169284. if (gamma_table != NULL)
  169285. {
  169286. sp = row;
  169287. shift = 4;
  169288. for (i = 0; i < row_width; i++)
  169289. {
  169290. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169291. == trans_values->gray)
  169292. {
  169293. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169294. *sp |= (png_byte)(background->gray << shift);
  169295. }
  169296. else
  169297. {
  169298. png_byte p = (png_byte)((*sp >> shift) & 0x0f);
  169299. png_byte g = (png_byte)((gamma_table[p |
  169300. (p << 4)] >> 4) & 0x0f);
  169301. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169302. *sp |= (png_byte)(g << shift);
  169303. }
  169304. if (!shift)
  169305. {
  169306. shift = 4;
  169307. sp++;
  169308. }
  169309. else
  169310. shift -= 4;
  169311. }
  169312. }
  169313. else
  169314. #endif
  169315. {
  169316. sp = row;
  169317. shift = 4;
  169318. for (i = 0; i < row_width; i++)
  169319. {
  169320. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169321. == trans_values->gray)
  169322. {
  169323. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169324. *sp |= (png_byte)(background->gray << shift);
  169325. }
  169326. if (!shift)
  169327. {
  169328. shift = 4;
  169329. sp++;
  169330. }
  169331. else
  169332. shift -= 4;
  169333. }
  169334. }
  169335. break;
  169336. }
  169337. case 8:
  169338. {
  169339. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169340. if (gamma_table != NULL)
  169341. {
  169342. sp = row;
  169343. for (i = 0; i < row_width; i++, sp++)
  169344. {
  169345. if (*sp == trans_values->gray)
  169346. {
  169347. *sp = (png_byte)background->gray;
  169348. }
  169349. else
  169350. {
  169351. *sp = gamma_table[*sp];
  169352. }
  169353. }
  169354. }
  169355. else
  169356. #endif
  169357. {
  169358. sp = row;
  169359. for (i = 0; i < row_width; i++, sp++)
  169360. {
  169361. if (*sp == trans_values->gray)
  169362. {
  169363. *sp = (png_byte)background->gray;
  169364. }
  169365. }
  169366. }
  169367. break;
  169368. }
  169369. case 16:
  169370. {
  169371. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169372. if (gamma_16 != NULL)
  169373. {
  169374. sp = row;
  169375. for (i = 0; i < row_width; i++, sp += 2)
  169376. {
  169377. png_uint_16 v;
  169378. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169379. if (v == trans_values->gray)
  169380. {
  169381. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169382. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169383. }
  169384. else
  169385. {
  169386. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169387. *sp = (png_byte)((v >> 8) & 0xff);
  169388. *(sp + 1) = (png_byte)(v & 0xff);
  169389. }
  169390. }
  169391. }
  169392. else
  169393. #endif
  169394. {
  169395. sp = row;
  169396. for (i = 0; i < row_width; i++, sp += 2)
  169397. {
  169398. png_uint_16 v;
  169399. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169400. if (v == trans_values->gray)
  169401. {
  169402. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169403. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169404. }
  169405. }
  169406. }
  169407. break;
  169408. }
  169409. }
  169410. break;
  169411. }
  169412. case PNG_COLOR_TYPE_RGB:
  169413. {
  169414. if (row_info->bit_depth == 8)
  169415. {
  169416. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169417. if (gamma_table != NULL)
  169418. {
  169419. sp = row;
  169420. for (i = 0; i < row_width; i++, sp += 3)
  169421. {
  169422. if (*sp == trans_values->red &&
  169423. *(sp + 1) == trans_values->green &&
  169424. *(sp + 2) == trans_values->blue)
  169425. {
  169426. *sp = (png_byte)background->red;
  169427. *(sp + 1) = (png_byte)background->green;
  169428. *(sp + 2) = (png_byte)background->blue;
  169429. }
  169430. else
  169431. {
  169432. *sp = gamma_table[*sp];
  169433. *(sp + 1) = gamma_table[*(sp + 1)];
  169434. *(sp + 2) = gamma_table[*(sp + 2)];
  169435. }
  169436. }
  169437. }
  169438. else
  169439. #endif
  169440. {
  169441. sp = row;
  169442. for (i = 0; i < row_width; i++, sp += 3)
  169443. {
  169444. if (*sp == trans_values->red &&
  169445. *(sp + 1) == trans_values->green &&
  169446. *(sp + 2) == trans_values->blue)
  169447. {
  169448. *sp = (png_byte)background->red;
  169449. *(sp + 1) = (png_byte)background->green;
  169450. *(sp + 2) = (png_byte)background->blue;
  169451. }
  169452. }
  169453. }
  169454. }
  169455. else /* if (row_info->bit_depth == 16) */
  169456. {
  169457. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169458. if (gamma_16 != NULL)
  169459. {
  169460. sp = row;
  169461. for (i = 0; i < row_width; i++, sp += 6)
  169462. {
  169463. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169464. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169465. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169466. if (r == trans_values->red && g == trans_values->green &&
  169467. b == trans_values->blue)
  169468. {
  169469. *sp = (png_byte)((background->red >> 8) & 0xff);
  169470. *(sp + 1) = (png_byte)(background->red & 0xff);
  169471. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169472. *(sp + 3) = (png_byte)(background->green & 0xff);
  169473. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169474. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169475. }
  169476. else
  169477. {
  169478. png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169479. *sp = (png_byte)((v >> 8) & 0xff);
  169480. *(sp + 1) = (png_byte)(v & 0xff);
  169481. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169482. *(sp + 2) = (png_byte)((v >> 8) & 0xff);
  169483. *(sp + 3) = (png_byte)(v & 0xff);
  169484. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169485. *(sp + 4) = (png_byte)((v >> 8) & 0xff);
  169486. *(sp + 5) = (png_byte)(v & 0xff);
  169487. }
  169488. }
  169489. }
  169490. else
  169491. #endif
  169492. {
  169493. sp = row;
  169494. for (i = 0; i < row_width; i++, sp += 6)
  169495. {
  169496. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp+1));
  169497. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169498. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169499. if (r == trans_values->red && g == trans_values->green &&
  169500. b == trans_values->blue)
  169501. {
  169502. *sp = (png_byte)((background->red >> 8) & 0xff);
  169503. *(sp + 1) = (png_byte)(background->red & 0xff);
  169504. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169505. *(sp + 3) = (png_byte)(background->green & 0xff);
  169506. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169507. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169508. }
  169509. }
  169510. }
  169511. }
  169512. break;
  169513. }
  169514. case PNG_COLOR_TYPE_GRAY_ALPHA:
  169515. {
  169516. if (row_info->bit_depth == 8)
  169517. {
  169518. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169519. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  169520. gamma_table != NULL)
  169521. {
  169522. sp = row;
  169523. dp = row;
  169524. for (i = 0; i < row_width; i++, sp += 2, dp++)
  169525. {
  169526. png_uint_16 a = *(sp + 1);
  169527. if (a == 0xff)
  169528. {
  169529. *dp = gamma_table[*sp];
  169530. }
  169531. else if (a == 0)
  169532. {
  169533. *dp = (png_byte)background->gray;
  169534. }
  169535. else
  169536. {
  169537. png_byte v, w;
  169538. v = gamma_to_1[*sp];
  169539. png_composite(w, v, a, background_1->gray);
  169540. *dp = gamma_from_1[w];
  169541. }
  169542. }
  169543. }
  169544. else
  169545. #endif
  169546. {
  169547. sp = row;
  169548. dp = row;
  169549. for (i = 0; i < row_width; i++, sp += 2, dp++)
  169550. {
  169551. png_byte a = *(sp + 1);
  169552. if (a == 0xff)
  169553. {
  169554. *dp = *sp;
  169555. }
  169556. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169557. else if (a == 0)
  169558. {
  169559. *dp = (png_byte)background->gray;
  169560. }
  169561. else
  169562. {
  169563. png_composite(*dp, *sp, a, background_1->gray);
  169564. }
  169565. #else
  169566. *dp = (png_byte)background->gray;
  169567. #endif
  169568. }
  169569. }
  169570. }
  169571. else /* if (png_ptr->bit_depth == 16) */
  169572. {
  169573. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169574. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  169575. gamma_16_to_1 != NULL)
  169576. {
  169577. sp = row;
  169578. dp = row;
  169579. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  169580. {
  169581. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169582. if (a == (png_uint_16)0xffff)
  169583. {
  169584. png_uint_16 v;
  169585. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169586. *dp = (png_byte)((v >> 8) & 0xff);
  169587. *(dp + 1) = (png_byte)(v & 0xff);
  169588. }
  169589. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169590. else if (a == 0)
  169591. #else
  169592. else
  169593. #endif
  169594. {
  169595. *dp = (png_byte)((background->gray >> 8) & 0xff);
  169596. *(dp + 1) = (png_byte)(background->gray & 0xff);
  169597. }
  169598. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169599. else
  169600. {
  169601. png_uint_16 g, v, w;
  169602. g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  169603. png_composite_16(v, g, a, background_1->gray);
  169604. w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8];
  169605. *dp = (png_byte)((w >> 8) & 0xff);
  169606. *(dp + 1) = (png_byte)(w & 0xff);
  169607. }
  169608. #endif
  169609. }
  169610. }
  169611. else
  169612. #endif
  169613. {
  169614. sp = row;
  169615. dp = row;
  169616. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  169617. {
  169618. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169619. if (a == (png_uint_16)0xffff)
  169620. {
  169621. png_memcpy(dp, sp, 2);
  169622. }
  169623. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169624. else if (a == 0)
  169625. #else
  169626. else
  169627. #endif
  169628. {
  169629. *dp = (png_byte)((background->gray >> 8) & 0xff);
  169630. *(dp + 1) = (png_byte)(background->gray & 0xff);
  169631. }
  169632. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169633. else
  169634. {
  169635. png_uint_16 g, v;
  169636. g = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169637. png_composite_16(v, g, a, background_1->gray);
  169638. *dp = (png_byte)((v >> 8) & 0xff);
  169639. *(dp + 1) = (png_byte)(v & 0xff);
  169640. }
  169641. #endif
  169642. }
  169643. }
  169644. }
  169645. break;
  169646. }
  169647. case PNG_COLOR_TYPE_RGB_ALPHA:
  169648. {
  169649. if (row_info->bit_depth == 8)
  169650. {
  169651. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169652. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  169653. gamma_table != NULL)
  169654. {
  169655. sp = row;
  169656. dp = row;
  169657. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  169658. {
  169659. png_byte a = *(sp + 3);
  169660. if (a == 0xff)
  169661. {
  169662. *dp = gamma_table[*sp];
  169663. *(dp + 1) = gamma_table[*(sp + 1)];
  169664. *(dp + 2) = gamma_table[*(sp + 2)];
  169665. }
  169666. else if (a == 0)
  169667. {
  169668. *dp = (png_byte)background->red;
  169669. *(dp + 1) = (png_byte)background->green;
  169670. *(dp + 2) = (png_byte)background->blue;
  169671. }
  169672. else
  169673. {
  169674. png_byte v, w;
  169675. v = gamma_to_1[*sp];
  169676. png_composite(w, v, a, background_1->red);
  169677. *dp = gamma_from_1[w];
  169678. v = gamma_to_1[*(sp + 1)];
  169679. png_composite(w, v, a, background_1->green);
  169680. *(dp + 1) = gamma_from_1[w];
  169681. v = gamma_to_1[*(sp + 2)];
  169682. png_composite(w, v, a, background_1->blue);
  169683. *(dp + 2) = gamma_from_1[w];
  169684. }
  169685. }
  169686. }
  169687. else
  169688. #endif
  169689. {
  169690. sp = row;
  169691. dp = row;
  169692. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  169693. {
  169694. png_byte a = *(sp + 3);
  169695. if (a == 0xff)
  169696. {
  169697. *dp = *sp;
  169698. *(dp + 1) = *(sp + 1);
  169699. *(dp + 2) = *(sp + 2);
  169700. }
  169701. else if (a == 0)
  169702. {
  169703. *dp = (png_byte)background->red;
  169704. *(dp + 1) = (png_byte)background->green;
  169705. *(dp + 2) = (png_byte)background->blue;
  169706. }
  169707. else
  169708. {
  169709. png_composite(*dp, *sp, a, background->red);
  169710. png_composite(*(dp + 1), *(sp + 1), a,
  169711. background->green);
  169712. png_composite(*(dp + 2), *(sp + 2), a,
  169713. background->blue);
  169714. }
  169715. }
  169716. }
  169717. }
  169718. else /* if (row_info->bit_depth == 16) */
  169719. {
  169720. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169721. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  169722. gamma_16_to_1 != NULL)
  169723. {
  169724. sp = row;
  169725. dp = row;
  169726. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  169727. {
  169728. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  169729. << 8) + (png_uint_16)(*(sp + 7)));
  169730. if (a == (png_uint_16)0xffff)
  169731. {
  169732. png_uint_16 v;
  169733. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169734. *dp = (png_byte)((v >> 8) & 0xff);
  169735. *(dp + 1) = (png_byte)(v & 0xff);
  169736. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169737. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  169738. *(dp + 3) = (png_byte)(v & 0xff);
  169739. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169740. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  169741. *(dp + 5) = (png_byte)(v & 0xff);
  169742. }
  169743. else if (a == 0)
  169744. {
  169745. *dp = (png_byte)((background->red >> 8) & 0xff);
  169746. *(dp + 1) = (png_byte)(background->red & 0xff);
  169747. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169748. *(dp + 3) = (png_byte)(background->green & 0xff);
  169749. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169750. *(dp + 5) = (png_byte)(background->blue & 0xff);
  169751. }
  169752. else
  169753. {
  169754. png_uint_16 v, w, x;
  169755. v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  169756. png_composite_16(w, v, a, background_1->red);
  169757. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  169758. *dp = (png_byte)((x >> 8) & 0xff);
  169759. *(dp + 1) = (png_byte)(x & 0xff);
  169760. v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169761. png_composite_16(w, v, a, background_1->green);
  169762. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  169763. *(dp + 2) = (png_byte)((x >> 8) & 0xff);
  169764. *(dp + 3) = (png_byte)(x & 0xff);
  169765. v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169766. png_composite_16(w, v, a, background_1->blue);
  169767. x = gamma_16_from_1[(w & 0xff) >> gamma_shift][w >> 8];
  169768. *(dp + 4) = (png_byte)((x >> 8) & 0xff);
  169769. *(dp + 5) = (png_byte)(x & 0xff);
  169770. }
  169771. }
  169772. }
  169773. else
  169774. #endif
  169775. {
  169776. sp = row;
  169777. dp = row;
  169778. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  169779. {
  169780. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  169781. << 8) + (png_uint_16)(*(sp + 7)));
  169782. if (a == (png_uint_16)0xffff)
  169783. {
  169784. png_memcpy(dp, sp, 6);
  169785. }
  169786. else if (a == 0)
  169787. {
  169788. *dp = (png_byte)((background->red >> 8) & 0xff);
  169789. *(dp + 1) = (png_byte)(background->red & 0xff);
  169790. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169791. *(dp + 3) = (png_byte)(background->green & 0xff);
  169792. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169793. *(dp + 5) = (png_byte)(background->blue & 0xff);
  169794. }
  169795. else
  169796. {
  169797. png_uint_16 v;
  169798. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169799. png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
  169800. + *(sp + 3));
  169801. png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
  169802. + *(sp + 5));
  169803. png_composite_16(v, r, a, background->red);
  169804. *dp = (png_byte)((v >> 8) & 0xff);
  169805. *(dp + 1) = (png_byte)(v & 0xff);
  169806. png_composite_16(v, g, a, background->green);
  169807. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  169808. *(dp + 3) = (png_byte)(v & 0xff);
  169809. png_composite_16(v, b, a, background->blue);
  169810. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  169811. *(dp + 5) = (png_byte)(v & 0xff);
  169812. }
  169813. }
  169814. }
  169815. }
  169816. break;
  169817. }
  169818. }
  169819. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  169820. {
  169821. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  169822. row_info->channels--;
  169823. row_info->pixel_depth = (png_byte)(row_info->channels *
  169824. row_info->bit_depth);
  169825. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169826. }
  169827. }
  169828. }
  169829. #endif
  169830. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169831. void /* PRIVATE */
  169832. png_do_gamma(png_row_infop row_info, png_bytep row,
  169833. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  169834. int gamma_shift)
  169835. {
  169836. png_bytep sp;
  169837. png_uint_32 i;
  169838. png_uint_32 row_width=row_info->width;
  169839. png_debug(1, "in png_do_gamma\n");
  169840. if (
  169841. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169842. row != NULL && row_info != NULL &&
  169843. #endif
  169844. ((row_info->bit_depth <= 8 && gamma_table != NULL) ||
  169845. (row_info->bit_depth == 16 && gamma_16_table != NULL)))
  169846. {
  169847. switch (row_info->color_type)
  169848. {
  169849. case PNG_COLOR_TYPE_RGB:
  169850. {
  169851. if (row_info->bit_depth == 8)
  169852. {
  169853. sp = row;
  169854. for (i = 0; i < row_width; i++)
  169855. {
  169856. *sp = gamma_table[*sp];
  169857. sp++;
  169858. *sp = gamma_table[*sp];
  169859. sp++;
  169860. *sp = gamma_table[*sp];
  169861. sp++;
  169862. }
  169863. }
  169864. else /* if (row_info->bit_depth == 16) */
  169865. {
  169866. sp = row;
  169867. for (i = 0; i < row_width; i++)
  169868. {
  169869. png_uint_16 v;
  169870. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169871. *sp = (png_byte)((v >> 8) & 0xff);
  169872. *(sp + 1) = (png_byte)(v & 0xff);
  169873. sp += 2;
  169874. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169875. *sp = (png_byte)((v >> 8) & 0xff);
  169876. *(sp + 1) = (png_byte)(v & 0xff);
  169877. sp += 2;
  169878. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169879. *sp = (png_byte)((v >> 8) & 0xff);
  169880. *(sp + 1) = (png_byte)(v & 0xff);
  169881. sp += 2;
  169882. }
  169883. }
  169884. break;
  169885. }
  169886. case PNG_COLOR_TYPE_RGB_ALPHA:
  169887. {
  169888. if (row_info->bit_depth == 8)
  169889. {
  169890. sp = row;
  169891. for (i = 0; i < row_width; i++)
  169892. {
  169893. *sp = gamma_table[*sp];
  169894. sp++;
  169895. *sp = gamma_table[*sp];
  169896. sp++;
  169897. *sp = gamma_table[*sp];
  169898. sp++;
  169899. sp++;
  169900. }
  169901. }
  169902. else /* if (row_info->bit_depth == 16) */
  169903. {
  169904. sp = row;
  169905. for (i = 0; i < row_width; i++)
  169906. {
  169907. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169908. *sp = (png_byte)((v >> 8) & 0xff);
  169909. *(sp + 1) = (png_byte)(v & 0xff);
  169910. sp += 2;
  169911. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169912. *sp = (png_byte)((v >> 8) & 0xff);
  169913. *(sp + 1) = (png_byte)(v & 0xff);
  169914. sp += 2;
  169915. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169916. *sp = (png_byte)((v >> 8) & 0xff);
  169917. *(sp + 1) = (png_byte)(v & 0xff);
  169918. sp += 4;
  169919. }
  169920. }
  169921. break;
  169922. }
  169923. case PNG_COLOR_TYPE_GRAY_ALPHA:
  169924. {
  169925. if (row_info->bit_depth == 8)
  169926. {
  169927. sp = row;
  169928. for (i = 0; i < row_width; i++)
  169929. {
  169930. *sp = gamma_table[*sp];
  169931. sp += 2;
  169932. }
  169933. }
  169934. else /* if (row_info->bit_depth == 16) */
  169935. {
  169936. sp = row;
  169937. for (i = 0; i < row_width; i++)
  169938. {
  169939. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169940. *sp = (png_byte)((v >> 8) & 0xff);
  169941. *(sp + 1) = (png_byte)(v & 0xff);
  169942. sp += 4;
  169943. }
  169944. }
  169945. break;
  169946. }
  169947. case PNG_COLOR_TYPE_GRAY:
  169948. {
  169949. if (row_info->bit_depth == 2)
  169950. {
  169951. sp = row;
  169952. for (i = 0; i < row_width; i += 4)
  169953. {
  169954. int a = *sp & 0xc0;
  169955. int b = *sp & 0x30;
  169956. int c = *sp & 0x0c;
  169957. int d = *sp & 0x03;
  169958. *sp = (png_byte)(
  169959. ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)|
  169960. ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)|
  169961. ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)|
  169962. ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) ));
  169963. sp++;
  169964. }
  169965. }
  169966. if (row_info->bit_depth == 4)
  169967. {
  169968. sp = row;
  169969. for (i = 0; i < row_width; i += 2)
  169970. {
  169971. int msb = *sp & 0xf0;
  169972. int lsb = *sp & 0x0f;
  169973. *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0)
  169974. | (((int)gamma_table[(lsb << 4) | lsb]) >> 4));
  169975. sp++;
  169976. }
  169977. }
  169978. else if (row_info->bit_depth == 8)
  169979. {
  169980. sp = row;
  169981. for (i = 0; i < row_width; i++)
  169982. {
  169983. *sp = gamma_table[*sp];
  169984. sp++;
  169985. }
  169986. }
  169987. else if (row_info->bit_depth == 16)
  169988. {
  169989. sp = row;
  169990. for (i = 0; i < row_width; i++)
  169991. {
  169992. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169993. *sp = (png_byte)((v >> 8) & 0xff);
  169994. *(sp + 1) = (png_byte)(v & 0xff);
  169995. sp += 2;
  169996. }
  169997. }
  169998. break;
  169999. }
  170000. }
  170001. }
  170002. }
  170003. #endif
  170004. #if defined(PNG_READ_EXPAND_SUPPORTED)
  170005. void /* PRIVATE */
  170006. png_do_expand_palette(png_row_infop row_info, png_bytep row,
  170007. png_colorp palette, png_bytep trans, int num_trans)
  170008. {
  170009. int shift, value;
  170010. png_bytep sp, dp;
  170011. png_uint_32 i;
  170012. png_uint_32 row_width=row_info->width;
  170013. png_debug(1, "in png_do_expand_palette\n");
  170014. if (
  170015. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170016. row != NULL && row_info != NULL &&
  170017. #endif
  170018. row_info->color_type == PNG_COLOR_TYPE_PALETTE)
  170019. {
  170020. if (row_info->bit_depth < 8)
  170021. {
  170022. switch (row_info->bit_depth)
  170023. {
  170024. case 1:
  170025. {
  170026. sp = row + (png_size_t)((row_width - 1) >> 3);
  170027. dp = row + (png_size_t)row_width - 1;
  170028. shift = 7 - (int)((row_width + 7) & 0x07);
  170029. for (i = 0; i < row_width; i++)
  170030. {
  170031. if ((*sp >> shift) & 0x01)
  170032. *dp = 1;
  170033. else
  170034. *dp = 0;
  170035. if (shift == 7)
  170036. {
  170037. shift = 0;
  170038. sp--;
  170039. }
  170040. else
  170041. shift++;
  170042. dp--;
  170043. }
  170044. break;
  170045. }
  170046. case 2:
  170047. {
  170048. sp = row + (png_size_t)((row_width - 1) >> 2);
  170049. dp = row + (png_size_t)row_width - 1;
  170050. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170051. for (i = 0; i < row_width; i++)
  170052. {
  170053. value = (*sp >> shift) & 0x03;
  170054. *dp = (png_byte)value;
  170055. if (shift == 6)
  170056. {
  170057. shift = 0;
  170058. sp--;
  170059. }
  170060. else
  170061. shift += 2;
  170062. dp--;
  170063. }
  170064. break;
  170065. }
  170066. case 4:
  170067. {
  170068. sp = row + (png_size_t)((row_width - 1) >> 1);
  170069. dp = row + (png_size_t)row_width - 1;
  170070. shift = (int)((row_width & 0x01) << 2);
  170071. for (i = 0; i < row_width; i++)
  170072. {
  170073. value = (*sp >> shift) & 0x0f;
  170074. *dp = (png_byte)value;
  170075. if (shift == 4)
  170076. {
  170077. shift = 0;
  170078. sp--;
  170079. }
  170080. else
  170081. shift += 4;
  170082. dp--;
  170083. }
  170084. break;
  170085. }
  170086. }
  170087. row_info->bit_depth = 8;
  170088. row_info->pixel_depth = 8;
  170089. row_info->rowbytes = row_width;
  170090. }
  170091. switch (row_info->bit_depth)
  170092. {
  170093. case 8:
  170094. {
  170095. if (trans != NULL)
  170096. {
  170097. sp = row + (png_size_t)row_width - 1;
  170098. dp = row + (png_size_t)(row_width << 2) - 1;
  170099. for (i = 0; i < row_width; i++)
  170100. {
  170101. if ((int)(*sp) >= num_trans)
  170102. *dp-- = 0xff;
  170103. else
  170104. *dp-- = trans[*sp];
  170105. *dp-- = palette[*sp].blue;
  170106. *dp-- = palette[*sp].green;
  170107. *dp-- = palette[*sp].red;
  170108. sp--;
  170109. }
  170110. row_info->bit_depth = 8;
  170111. row_info->pixel_depth = 32;
  170112. row_info->rowbytes = row_width * 4;
  170113. row_info->color_type = 6;
  170114. row_info->channels = 4;
  170115. }
  170116. else
  170117. {
  170118. sp = row + (png_size_t)row_width - 1;
  170119. dp = row + (png_size_t)(row_width * 3) - 1;
  170120. for (i = 0; i < row_width; i++)
  170121. {
  170122. *dp-- = palette[*sp].blue;
  170123. *dp-- = palette[*sp].green;
  170124. *dp-- = palette[*sp].red;
  170125. sp--;
  170126. }
  170127. row_info->bit_depth = 8;
  170128. row_info->pixel_depth = 24;
  170129. row_info->rowbytes = row_width * 3;
  170130. row_info->color_type = 2;
  170131. row_info->channels = 3;
  170132. }
  170133. break;
  170134. }
  170135. }
  170136. }
  170137. }
  170138. void /* PRIVATE */
  170139. png_do_expand(png_row_infop row_info, png_bytep row,
  170140. png_color_16p trans_value)
  170141. {
  170142. int shift, value;
  170143. png_bytep sp, dp;
  170144. png_uint_32 i;
  170145. png_uint_32 row_width=row_info->width;
  170146. png_debug(1, "in png_do_expand\n");
  170147. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170148. if (row != NULL && row_info != NULL)
  170149. #endif
  170150. {
  170151. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  170152. {
  170153. png_uint_16 gray = (png_uint_16)(trans_value ? trans_value->gray : 0);
  170154. if (row_info->bit_depth < 8)
  170155. {
  170156. switch (row_info->bit_depth)
  170157. {
  170158. case 1:
  170159. {
  170160. gray = (png_uint_16)((gray&0x01)*0xff);
  170161. sp = row + (png_size_t)((row_width - 1) >> 3);
  170162. dp = row + (png_size_t)row_width - 1;
  170163. shift = 7 - (int)((row_width + 7) & 0x07);
  170164. for (i = 0; i < row_width; i++)
  170165. {
  170166. if ((*sp >> shift) & 0x01)
  170167. *dp = 0xff;
  170168. else
  170169. *dp = 0;
  170170. if (shift == 7)
  170171. {
  170172. shift = 0;
  170173. sp--;
  170174. }
  170175. else
  170176. shift++;
  170177. dp--;
  170178. }
  170179. break;
  170180. }
  170181. case 2:
  170182. {
  170183. gray = (png_uint_16)((gray&0x03)*0x55);
  170184. sp = row + (png_size_t)((row_width - 1) >> 2);
  170185. dp = row + (png_size_t)row_width - 1;
  170186. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170187. for (i = 0; i < row_width; i++)
  170188. {
  170189. value = (*sp >> shift) & 0x03;
  170190. *dp = (png_byte)(value | (value << 2) | (value << 4) |
  170191. (value << 6));
  170192. if (shift == 6)
  170193. {
  170194. shift = 0;
  170195. sp--;
  170196. }
  170197. else
  170198. shift += 2;
  170199. dp--;
  170200. }
  170201. break;
  170202. }
  170203. case 4:
  170204. {
  170205. gray = (png_uint_16)((gray&0x0f)*0x11);
  170206. sp = row + (png_size_t)((row_width - 1) >> 1);
  170207. dp = row + (png_size_t)row_width - 1;
  170208. shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  170209. for (i = 0; i < row_width; i++)
  170210. {
  170211. value = (*sp >> shift) & 0x0f;
  170212. *dp = (png_byte)(value | (value << 4));
  170213. if (shift == 4)
  170214. {
  170215. shift = 0;
  170216. sp--;
  170217. }
  170218. else
  170219. shift = 4;
  170220. dp--;
  170221. }
  170222. break;
  170223. }
  170224. }
  170225. row_info->bit_depth = 8;
  170226. row_info->pixel_depth = 8;
  170227. row_info->rowbytes = row_width;
  170228. }
  170229. if (trans_value != NULL)
  170230. {
  170231. if (row_info->bit_depth == 8)
  170232. {
  170233. gray = gray & 0xff;
  170234. sp = row + (png_size_t)row_width - 1;
  170235. dp = row + (png_size_t)(row_width << 1) - 1;
  170236. for (i = 0; i < row_width; i++)
  170237. {
  170238. if (*sp == gray)
  170239. *dp-- = 0;
  170240. else
  170241. *dp-- = 0xff;
  170242. *dp-- = *sp--;
  170243. }
  170244. }
  170245. else if (row_info->bit_depth == 16)
  170246. {
  170247. png_byte gray_high = (gray >> 8) & 0xff;
  170248. png_byte gray_low = gray & 0xff;
  170249. sp = row + row_info->rowbytes - 1;
  170250. dp = row + (row_info->rowbytes << 1) - 1;
  170251. for (i = 0; i < row_width; i++)
  170252. {
  170253. if (*(sp-1) == gray_high && *(sp) == gray_low)
  170254. {
  170255. *dp-- = 0;
  170256. *dp-- = 0;
  170257. }
  170258. else
  170259. {
  170260. *dp-- = 0xff;
  170261. *dp-- = 0xff;
  170262. }
  170263. *dp-- = *sp--;
  170264. *dp-- = *sp--;
  170265. }
  170266. }
  170267. row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
  170268. row_info->channels = 2;
  170269. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
  170270. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  170271. row_width);
  170272. }
  170273. }
  170274. else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_value)
  170275. {
  170276. if (row_info->bit_depth == 8)
  170277. {
  170278. png_byte red = trans_value->red & 0xff;
  170279. png_byte green = trans_value->green & 0xff;
  170280. png_byte blue = trans_value->blue & 0xff;
  170281. sp = row + (png_size_t)row_info->rowbytes - 1;
  170282. dp = row + (png_size_t)(row_width << 2) - 1;
  170283. for (i = 0; i < row_width; i++)
  170284. {
  170285. if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue)
  170286. *dp-- = 0;
  170287. else
  170288. *dp-- = 0xff;
  170289. *dp-- = *sp--;
  170290. *dp-- = *sp--;
  170291. *dp-- = *sp--;
  170292. }
  170293. }
  170294. else if (row_info->bit_depth == 16)
  170295. {
  170296. png_byte red_high = (trans_value->red >> 8) & 0xff;
  170297. png_byte green_high = (trans_value->green >> 8) & 0xff;
  170298. png_byte blue_high = (trans_value->blue >> 8) & 0xff;
  170299. png_byte red_low = trans_value->red & 0xff;
  170300. png_byte green_low = trans_value->green & 0xff;
  170301. png_byte blue_low = trans_value->blue & 0xff;
  170302. sp = row + row_info->rowbytes - 1;
  170303. dp = row + (png_size_t)(row_width << 3) - 1;
  170304. for (i = 0; i < row_width; i++)
  170305. {
  170306. if (*(sp - 5) == red_high &&
  170307. *(sp - 4) == red_low &&
  170308. *(sp - 3) == green_high &&
  170309. *(sp - 2) == green_low &&
  170310. *(sp - 1) == blue_high &&
  170311. *(sp ) == blue_low)
  170312. {
  170313. *dp-- = 0;
  170314. *dp-- = 0;
  170315. }
  170316. else
  170317. {
  170318. *dp-- = 0xff;
  170319. *dp-- = 0xff;
  170320. }
  170321. *dp-- = *sp--;
  170322. *dp-- = *sp--;
  170323. *dp-- = *sp--;
  170324. *dp-- = *sp--;
  170325. *dp-- = *sp--;
  170326. *dp-- = *sp--;
  170327. }
  170328. }
  170329. row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  170330. row_info->channels = 4;
  170331. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
  170332. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170333. }
  170334. }
  170335. }
  170336. #endif
  170337. #if defined(PNG_READ_DITHER_SUPPORTED)
  170338. void /* PRIVATE */
  170339. png_do_dither(png_row_infop row_info, png_bytep row,
  170340. png_bytep palette_lookup, png_bytep dither_lookup)
  170341. {
  170342. png_bytep sp, dp;
  170343. png_uint_32 i;
  170344. png_uint_32 row_width=row_info->width;
  170345. png_debug(1, "in png_do_dither\n");
  170346. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170347. if (row != NULL && row_info != NULL)
  170348. #endif
  170349. {
  170350. if (row_info->color_type == PNG_COLOR_TYPE_RGB &&
  170351. palette_lookup && row_info->bit_depth == 8)
  170352. {
  170353. int r, g, b, p;
  170354. sp = row;
  170355. dp = row;
  170356. for (i = 0; i < row_width; i++)
  170357. {
  170358. r = *sp++;
  170359. g = *sp++;
  170360. b = *sp++;
  170361. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170362. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170363. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170364. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170365. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170366. (PNG_DITHER_BLUE_BITS)) |
  170367. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170368. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170369. *dp++ = palette_lookup[p];
  170370. }
  170371. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170372. row_info->channels = 1;
  170373. row_info->pixel_depth = row_info->bit_depth;
  170374. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170375. }
  170376. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  170377. palette_lookup != NULL && row_info->bit_depth == 8)
  170378. {
  170379. int r, g, b, p;
  170380. sp = row;
  170381. dp = row;
  170382. for (i = 0; i < row_width; i++)
  170383. {
  170384. r = *sp++;
  170385. g = *sp++;
  170386. b = *sp++;
  170387. sp++;
  170388. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170389. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170390. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170391. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170392. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170393. (PNG_DITHER_BLUE_BITS)) |
  170394. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170395. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170396. *dp++ = palette_lookup[p];
  170397. }
  170398. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170399. row_info->channels = 1;
  170400. row_info->pixel_depth = row_info->bit_depth;
  170401. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170402. }
  170403. else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
  170404. dither_lookup && row_info->bit_depth == 8)
  170405. {
  170406. sp = row;
  170407. for (i = 0; i < row_width; i++, sp++)
  170408. {
  170409. *sp = dither_lookup[*sp];
  170410. }
  170411. }
  170412. }
  170413. }
  170414. #endif
  170415. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170416. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170417. static PNG_CONST int png_gamma_shift[] =
  170418. {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0, 0x00};
  170419. void /* PRIVATE */
  170420. png_build_gamma_table(png_structp png_ptr)
  170421. {
  170422. png_debug(1, "in png_build_gamma_table\n");
  170423. if (png_ptr->bit_depth <= 8)
  170424. {
  170425. int i;
  170426. double g;
  170427. if (png_ptr->screen_gamma > .000001)
  170428. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170429. else
  170430. g = 1.0;
  170431. png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr,
  170432. (png_uint_32)256);
  170433. for (i = 0; i < 256; i++)
  170434. {
  170435. png_ptr->gamma_table[i] = (png_byte)(pow((double)i / 255.0,
  170436. g) * 255.0 + .5);
  170437. }
  170438. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170439. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170440. if (png_ptr->transformations & ((PNG_BACKGROUND) | PNG_RGB_TO_GRAY))
  170441. {
  170442. g = 1.0 / (png_ptr->gamma);
  170443. png_ptr->gamma_to_1 = (png_bytep)png_malloc(png_ptr,
  170444. (png_uint_32)256);
  170445. for (i = 0; i < 256; i++)
  170446. {
  170447. png_ptr->gamma_to_1[i] = (png_byte)(pow((double)i / 255.0,
  170448. g) * 255.0 + .5);
  170449. }
  170450. png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr,
  170451. (png_uint_32)256);
  170452. if(png_ptr->screen_gamma > 0.000001)
  170453. g = 1.0 / png_ptr->screen_gamma;
  170454. else
  170455. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170456. for (i = 0; i < 256; i++)
  170457. {
  170458. png_ptr->gamma_from_1[i] = (png_byte)(pow((double)i / 255.0,
  170459. g) * 255.0 + .5);
  170460. }
  170461. }
  170462. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170463. }
  170464. else
  170465. {
  170466. double g;
  170467. int i, j, shift, num;
  170468. int sig_bit;
  170469. png_uint_32 ig;
  170470. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  170471. {
  170472. sig_bit = (int)png_ptr->sig_bit.red;
  170473. if ((int)png_ptr->sig_bit.green > sig_bit)
  170474. sig_bit = png_ptr->sig_bit.green;
  170475. if ((int)png_ptr->sig_bit.blue > sig_bit)
  170476. sig_bit = png_ptr->sig_bit.blue;
  170477. }
  170478. else
  170479. {
  170480. sig_bit = (int)png_ptr->sig_bit.gray;
  170481. }
  170482. if (sig_bit > 0)
  170483. shift = 16 - sig_bit;
  170484. else
  170485. shift = 0;
  170486. if (png_ptr->transformations & PNG_16_TO_8)
  170487. {
  170488. if (shift < (16 - PNG_MAX_GAMMA_8))
  170489. shift = (16 - PNG_MAX_GAMMA_8);
  170490. }
  170491. if (shift > 8)
  170492. shift = 8;
  170493. if (shift < 0)
  170494. shift = 0;
  170495. png_ptr->gamma_shift = (png_byte)shift;
  170496. num = (1 << (8 - shift));
  170497. if (png_ptr->screen_gamma > .000001)
  170498. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170499. else
  170500. g = 1.0;
  170501. png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr,
  170502. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170503. if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND))
  170504. {
  170505. double fin, fout;
  170506. png_uint_32 last, max;
  170507. for (i = 0; i < num; i++)
  170508. {
  170509. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170510. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170511. }
  170512. g = 1.0 / g;
  170513. last = 0;
  170514. for (i = 0; i < 256; i++)
  170515. {
  170516. fout = ((double)i + 0.5) / 256.0;
  170517. fin = pow(fout, g);
  170518. max = (png_uint_32)(fin * (double)((png_uint_32)num << 8));
  170519. while (last <= max)
  170520. {
  170521. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  170522. [(int)(last >> (8 - shift))] = (png_uint_16)(
  170523. (png_uint_16)i | ((png_uint_16)i << 8));
  170524. last++;
  170525. }
  170526. }
  170527. while (last < ((png_uint_32)num << 8))
  170528. {
  170529. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  170530. [(int)(last >> (8 - shift))] = (png_uint_16)65535L;
  170531. last++;
  170532. }
  170533. }
  170534. else
  170535. {
  170536. for (i = 0; i < num; i++)
  170537. {
  170538. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170539. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170540. ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4);
  170541. for (j = 0; j < 256; j++)
  170542. {
  170543. png_ptr->gamma_16_table[i][j] =
  170544. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170545. 65535.0, g) * 65535.0 + .5);
  170546. }
  170547. }
  170548. }
  170549. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170550. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170551. if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY))
  170552. {
  170553. g = 1.0 / (png_ptr->gamma);
  170554. png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr,
  170555. (png_uint_32)(num * png_sizeof (png_uint_16p )));
  170556. for (i = 0; i < num; i++)
  170557. {
  170558. png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr,
  170559. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170560. ig = (((png_uint_32)i *
  170561. (png_uint_32)png_gamma_shift[shift]) >> 4);
  170562. for (j = 0; j < 256; j++)
  170563. {
  170564. png_ptr->gamma_16_to_1[i][j] =
  170565. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170566. 65535.0, g) * 65535.0 + .5);
  170567. }
  170568. }
  170569. if(png_ptr->screen_gamma > 0.000001)
  170570. g = 1.0 / png_ptr->screen_gamma;
  170571. else
  170572. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170573. png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr,
  170574. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170575. for (i = 0; i < num; i++)
  170576. {
  170577. png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr,
  170578. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170579. ig = (((png_uint_32)i *
  170580. (png_uint_32)png_gamma_shift[shift]) >> 4);
  170581. for (j = 0; j < 256; j++)
  170582. {
  170583. png_ptr->gamma_16_from_1[i][j] =
  170584. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170585. 65535.0, g) * 65535.0 + .5);
  170586. }
  170587. }
  170588. }
  170589. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170590. }
  170591. }
  170592. #endif
  170593. #endif
  170594. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  170595. void /* PRIVATE */
  170596. png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
  170597. {
  170598. png_debug(1, "in png_do_read_intrapixel\n");
  170599. if (
  170600. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170601. row != NULL && row_info != NULL &&
  170602. #endif
  170603. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  170604. {
  170605. int bytes_per_pixel;
  170606. png_uint_32 row_width = row_info->width;
  170607. if (row_info->bit_depth == 8)
  170608. {
  170609. png_bytep rp;
  170610. png_uint_32 i;
  170611. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  170612. bytes_per_pixel = 3;
  170613. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  170614. bytes_per_pixel = 4;
  170615. else
  170616. return;
  170617. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  170618. {
  170619. *(rp) = (png_byte)((256 + *rp + *(rp+1))&0xff);
  170620. *(rp+2) = (png_byte)((256 + *(rp+2) + *(rp+1))&0xff);
  170621. }
  170622. }
  170623. else if (row_info->bit_depth == 16)
  170624. {
  170625. png_bytep rp;
  170626. png_uint_32 i;
  170627. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  170628. bytes_per_pixel = 6;
  170629. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  170630. bytes_per_pixel = 8;
  170631. else
  170632. return;
  170633. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  170634. {
  170635. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  170636. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  170637. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  170638. png_uint_32 red = (png_uint_32)((s0+s1+65536L) & 0xffffL);
  170639. png_uint_32 blue = (png_uint_32)((s2+s1+65536L) & 0xffffL);
  170640. *(rp ) = (png_byte)((red >> 8) & 0xff);
  170641. *(rp+1) = (png_byte)(red & 0xff);
  170642. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  170643. *(rp+5) = (png_byte)(blue & 0xff);
  170644. }
  170645. }
  170646. }
  170647. }
  170648. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  170649. #endif /* PNG_READ_SUPPORTED */
  170650. /*** End of inlined file: pngrtran.c ***/
  170651. /*** Start of inlined file: pngrutil.c ***/
  170652. #define PNG_INTERNAL
  170653. #if defined(PNG_READ_SUPPORTED)
  170654. #if defined(_WIN32_WCE) && (_WIN32_WCE<0x500)
  170655. # define WIN32_WCE_OLD
  170656. #endif
  170657. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170658. # if defined(WIN32_WCE_OLD)
  170659. __inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr, char **endptr)
  170660. {
  170661. double result = 0;
  170662. int len;
  170663. wchar_t *str, *end;
  170664. len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0);
  170665. str = (wchar_t *)png_malloc(png_ptr, len * sizeof(wchar_t));
  170666. if ( NULL != str )
  170667. {
  170668. MultiByteToWideChar(CP_ACP, 0, nptr, -1, str, len);
  170669. result = wcstod(str, &end);
  170670. len = WideCharToMultiByte(CP_ACP, 0, end, -1, NULL, 0, NULL, NULL);
  170671. *endptr = (char *)nptr + (png_strlen(nptr) - len + 1);
  170672. png_free(png_ptr, str);
  170673. }
  170674. return result;
  170675. }
  170676. # else
  170677. # define png_strtod(p,a,b) strtod(a,b)
  170678. # endif
  170679. #endif
  170680. png_uint_32 PNGAPI
  170681. png_get_uint_31(png_structp png_ptr, png_bytep buf)
  170682. {
  170683. png_uint_32 i = png_get_uint_32(buf);
  170684. if (i > PNG_UINT_31_MAX)
  170685. png_error(png_ptr, "PNG unsigned integer out of range.");
  170686. return (i);
  170687. }
  170688. #ifndef PNG_READ_BIG_ENDIAN_SUPPORTED
  170689. png_uint_32 PNGAPI
  170690. png_get_uint_32(png_bytep buf)
  170691. {
  170692. png_uint_32 i = ((png_uint_32)(*buf) << 24) +
  170693. ((png_uint_32)(*(buf + 1)) << 16) +
  170694. ((png_uint_32)(*(buf + 2)) << 8) +
  170695. (png_uint_32)(*(buf + 3));
  170696. return (i);
  170697. }
  170698. png_int_32 PNGAPI
  170699. png_get_int_32(png_bytep buf)
  170700. {
  170701. png_int_32 i = ((png_int_32)(*buf) << 24) +
  170702. ((png_int_32)(*(buf + 1)) << 16) +
  170703. ((png_int_32)(*(buf + 2)) << 8) +
  170704. (png_int_32)(*(buf + 3));
  170705. return (i);
  170706. }
  170707. png_uint_16 PNGAPI
  170708. png_get_uint_16(png_bytep buf)
  170709. {
  170710. png_uint_16 i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
  170711. (png_uint_16)(*(buf + 1)));
  170712. return (i);
  170713. }
  170714. #endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */
  170715. void /* PRIVATE */
  170716. png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
  170717. {
  170718. if(png_ptr == NULL) return;
  170719. png_read_data(png_ptr, buf, length);
  170720. png_calculate_crc(png_ptr, buf, length);
  170721. }
  170722. int /* PRIVATE */
  170723. png_crc_finish(png_structp png_ptr, png_uint_32 skip)
  170724. {
  170725. png_size_t i;
  170726. png_size_t istop = png_ptr->zbuf_size;
  170727. for (i = (png_size_t)skip; i > istop; i -= istop)
  170728. {
  170729. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  170730. }
  170731. if (i)
  170732. {
  170733. png_crc_read(png_ptr, png_ptr->zbuf, i);
  170734. }
  170735. if (png_crc_error(png_ptr))
  170736. {
  170737. if (((png_ptr->chunk_name[0] & 0x20) && /* Ancillary */
  170738. !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) ||
  170739. (!(png_ptr->chunk_name[0] & 0x20) && /* Critical */
  170740. (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE)))
  170741. {
  170742. png_chunk_warning(png_ptr, "CRC error");
  170743. }
  170744. else
  170745. {
  170746. png_chunk_error(png_ptr, "CRC error");
  170747. }
  170748. return (1);
  170749. }
  170750. return (0);
  170751. }
  170752. int /* PRIVATE */
  170753. png_crc_error(png_structp png_ptr)
  170754. {
  170755. png_byte crc_bytes[4];
  170756. png_uint_32 crc;
  170757. int need_crc = 1;
  170758. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  170759. {
  170760. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  170761. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  170762. need_crc = 0;
  170763. }
  170764. else /* critical */
  170765. {
  170766. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  170767. need_crc = 0;
  170768. }
  170769. png_read_data(png_ptr, crc_bytes, 4);
  170770. if (need_crc)
  170771. {
  170772. crc = png_get_uint_32(crc_bytes);
  170773. return ((int)(crc != png_ptr->crc));
  170774. }
  170775. else
  170776. return (0);
  170777. }
  170778. #if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) || \
  170779. defined(PNG_READ_iCCP_SUPPORTED)
  170780. png_charp /* PRIVATE */
  170781. png_decompress_chunk(png_structp png_ptr, int comp_type,
  170782. png_charp chunkdata, png_size_t chunklength,
  170783. png_size_t prefix_size, png_size_t *newlength)
  170784. {
  170785. static PNG_CONST char msg[] = "Error decoding compressed text";
  170786. png_charp text;
  170787. png_size_t text_size;
  170788. if (comp_type == PNG_COMPRESSION_TYPE_BASE)
  170789. {
  170790. int ret = Z_OK;
  170791. png_ptr->zstream.next_in = (png_bytep)(chunkdata + prefix_size);
  170792. png_ptr->zstream.avail_in = (uInt)(chunklength - prefix_size);
  170793. png_ptr->zstream.next_out = png_ptr->zbuf;
  170794. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  170795. text_size = 0;
  170796. text = NULL;
  170797. while (png_ptr->zstream.avail_in)
  170798. {
  170799. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  170800. if (ret != Z_OK && ret != Z_STREAM_END)
  170801. {
  170802. if (png_ptr->zstream.msg != NULL)
  170803. png_warning(png_ptr, png_ptr->zstream.msg);
  170804. else
  170805. png_warning(png_ptr, msg);
  170806. inflateReset(&png_ptr->zstream);
  170807. png_ptr->zstream.avail_in = 0;
  170808. if (text == NULL)
  170809. {
  170810. text_size = prefix_size + png_sizeof(msg) + 1;
  170811. text = (png_charp)png_malloc_warn(png_ptr, text_size);
  170812. if (text == NULL)
  170813. {
  170814. png_free(png_ptr,chunkdata);
  170815. png_error(png_ptr,"Not enough memory to decompress chunk");
  170816. }
  170817. png_memcpy(text, chunkdata, prefix_size);
  170818. }
  170819. text[text_size - 1] = 0x00;
  170820. text_size = (png_size_t)(chunklength - (text - chunkdata) - 1);
  170821. text_size = png_sizeof(msg) > text_size ? text_size :
  170822. png_sizeof(msg);
  170823. png_memcpy(text + prefix_size, msg, text_size + 1);
  170824. break;
  170825. }
  170826. if (!png_ptr->zstream.avail_out || ret == Z_STREAM_END)
  170827. {
  170828. if (text == NULL)
  170829. {
  170830. text_size = prefix_size +
  170831. png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  170832. text = (png_charp)png_malloc_warn(png_ptr, text_size + 1);
  170833. if (text == NULL)
  170834. {
  170835. png_free(png_ptr,chunkdata);
  170836. png_error(png_ptr,"Not enough memory to decompress chunk.");
  170837. }
  170838. png_memcpy(text + prefix_size, png_ptr->zbuf,
  170839. text_size - prefix_size);
  170840. png_memcpy(text, chunkdata, prefix_size);
  170841. *(text + text_size) = 0x00;
  170842. }
  170843. else
  170844. {
  170845. png_charp tmp;
  170846. tmp = text;
  170847. text = (png_charp)png_malloc_warn(png_ptr,
  170848. (png_uint_32)(text_size +
  170849. png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1));
  170850. if (text == NULL)
  170851. {
  170852. png_free(png_ptr, tmp);
  170853. png_free(png_ptr, chunkdata);
  170854. png_error(png_ptr,"Not enough memory to decompress chunk..");
  170855. }
  170856. png_memcpy(text, tmp, text_size);
  170857. png_free(png_ptr, tmp);
  170858. png_memcpy(text + text_size, png_ptr->zbuf,
  170859. (png_ptr->zbuf_size - png_ptr->zstream.avail_out));
  170860. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  170861. *(text + text_size) = 0x00;
  170862. }
  170863. if (ret == Z_STREAM_END)
  170864. break;
  170865. else
  170866. {
  170867. png_ptr->zstream.next_out = png_ptr->zbuf;
  170868. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  170869. }
  170870. }
  170871. }
  170872. if (ret != Z_STREAM_END)
  170873. {
  170874. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  170875. char umsg[52];
  170876. if (ret == Z_BUF_ERROR)
  170877. png_snprintf(umsg, 52,
  170878. "Buffer error in compressed datastream in %s chunk",
  170879. png_ptr->chunk_name);
  170880. else if (ret == Z_DATA_ERROR)
  170881. png_snprintf(umsg, 52,
  170882. "Data error in compressed datastream in %s chunk",
  170883. png_ptr->chunk_name);
  170884. else
  170885. png_snprintf(umsg, 52,
  170886. "Incomplete compressed datastream in %s chunk",
  170887. png_ptr->chunk_name);
  170888. png_warning(png_ptr, umsg);
  170889. #else
  170890. png_warning(png_ptr,
  170891. "Incomplete compressed datastream in chunk other than IDAT");
  170892. #endif
  170893. text_size=prefix_size;
  170894. if (text == NULL)
  170895. {
  170896. text = (png_charp)png_malloc_warn(png_ptr, text_size+1);
  170897. if (text == NULL)
  170898. {
  170899. png_free(png_ptr, chunkdata);
  170900. png_error(png_ptr,"Not enough memory for text.");
  170901. }
  170902. png_memcpy(text, chunkdata, prefix_size);
  170903. }
  170904. *(text + text_size) = 0x00;
  170905. }
  170906. inflateReset(&png_ptr->zstream);
  170907. png_ptr->zstream.avail_in = 0;
  170908. png_free(png_ptr, chunkdata);
  170909. chunkdata = text;
  170910. *newlength=text_size;
  170911. }
  170912. else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */
  170913. {
  170914. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  170915. char umsg[50];
  170916. png_snprintf(umsg, 50,
  170917. "Unknown zTXt compression type %d", comp_type);
  170918. png_warning(png_ptr, umsg);
  170919. #else
  170920. png_warning(png_ptr, "Unknown zTXt compression type");
  170921. #endif
  170922. *(chunkdata + prefix_size) = 0x00;
  170923. *newlength=prefix_size;
  170924. }
  170925. return chunkdata;
  170926. }
  170927. #endif
  170928. void /* PRIVATE */
  170929. png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  170930. {
  170931. png_byte buf[13];
  170932. png_uint_32 width, height;
  170933. int bit_depth, color_type, compression_type, filter_type;
  170934. int interlace_type;
  170935. png_debug(1, "in png_handle_IHDR\n");
  170936. if (png_ptr->mode & PNG_HAVE_IHDR)
  170937. png_error(png_ptr, "Out of place IHDR");
  170938. if (length != 13)
  170939. png_error(png_ptr, "Invalid IHDR chunk");
  170940. png_ptr->mode |= PNG_HAVE_IHDR;
  170941. png_crc_read(png_ptr, buf, 13);
  170942. png_crc_finish(png_ptr, 0);
  170943. width = png_get_uint_31(png_ptr, buf);
  170944. height = png_get_uint_31(png_ptr, buf + 4);
  170945. bit_depth = buf[8];
  170946. color_type = buf[9];
  170947. compression_type = buf[10];
  170948. filter_type = buf[11];
  170949. interlace_type = buf[12];
  170950. png_ptr->width = width;
  170951. png_ptr->height = height;
  170952. png_ptr->bit_depth = (png_byte)bit_depth;
  170953. png_ptr->interlaced = (png_byte)interlace_type;
  170954. png_ptr->color_type = (png_byte)color_type;
  170955. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  170956. png_ptr->filter_type = (png_byte)filter_type;
  170957. #endif
  170958. png_ptr->compression_type = (png_byte)compression_type;
  170959. switch (png_ptr->color_type)
  170960. {
  170961. case PNG_COLOR_TYPE_GRAY:
  170962. case PNG_COLOR_TYPE_PALETTE:
  170963. png_ptr->channels = 1;
  170964. break;
  170965. case PNG_COLOR_TYPE_RGB:
  170966. png_ptr->channels = 3;
  170967. break;
  170968. case PNG_COLOR_TYPE_GRAY_ALPHA:
  170969. png_ptr->channels = 2;
  170970. break;
  170971. case PNG_COLOR_TYPE_RGB_ALPHA:
  170972. png_ptr->channels = 4;
  170973. break;
  170974. }
  170975. png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth *
  170976. png_ptr->channels);
  170977. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width);
  170978. png_debug1(3,"bit_depth = %d\n", png_ptr->bit_depth);
  170979. png_debug1(3,"channels = %d\n", png_ptr->channels);
  170980. png_debug1(3,"rowbytes = %lu\n", png_ptr->rowbytes);
  170981. png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
  170982. color_type, interlace_type, compression_type, filter_type);
  170983. }
  170984. void /* PRIVATE */
  170985. png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  170986. {
  170987. png_color palette[PNG_MAX_PALETTE_LENGTH];
  170988. int num, i;
  170989. #ifndef PNG_NO_POINTER_INDEXING
  170990. png_colorp pal_ptr;
  170991. #endif
  170992. png_debug(1, "in png_handle_PLTE\n");
  170993. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  170994. png_error(png_ptr, "Missing IHDR before PLTE");
  170995. else if (png_ptr->mode & PNG_HAVE_IDAT)
  170996. {
  170997. png_warning(png_ptr, "Invalid PLTE after IDAT");
  170998. png_crc_finish(png_ptr, length);
  170999. return;
  171000. }
  171001. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171002. png_error(png_ptr, "Duplicate PLTE chunk");
  171003. png_ptr->mode |= PNG_HAVE_PLTE;
  171004. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  171005. {
  171006. png_warning(png_ptr,
  171007. "Ignoring PLTE chunk in grayscale PNG");
  171008. png_crc_finish(png_ptr, length);
  171009. return;
  171010. }
  171011. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171012. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  171013. {
  171014. png_crc_finish(png_ptr, length);
  171015. return;
  171016. }
  171017. #endif
  171018. if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3)
  171019. {
  171020. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  171021. {
  171022. png_warning(png_ptr, "Invalid palette chunk");
  171023. png_crc_finish(png_ptr, length);
  171024. return;
  171025. }
  171026. else
  171027. {
  171028. png_error(png_ptr, "Invalid palette chunk");
  171029. }
  171030. }
  171031. num = (int)length / 3;
  171032. #ifndef PNG_NO_POINTER_INDEXING
  171033. for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++)
  171034. {
  171035. png_byte buf[3];
  171036. png_crc_read(png_ptr, buf, 3);
  171037. pal_ptr->red = buf[0];
  171038. pal_ptr->green = buf[1];
  171039. pal_ptr->blue = buf[2];
  171040. }
  171041. #else
  171042. for (i = 0; i < num; i++)
  171043. {
  171044. png_byte buf[3];
  171045. png_crc_read(png_ptr, buf, 3);
  171046. palette[i].red = buf[0];
  171047. palette[i].green = buf[1];
  171048. palette[i].blue = buf[2];
  171049. }
  171050. #endif
  171051. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171052. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171053. #endif
  171054. {
  171055. png_crc_finish(png_ptr, 0);
  171056. }
  171057. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171058. else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */
  171059. {
  171060. if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE))
  171061. {
  171062. if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)
  171063. {
  171064. png_chunk_error(png_ptr, "CRC error");
  171065. }
  171066. else
  171067. {
  171068. png_chunk_warning(png_ptr, "CRC error");
  171069. return;
  171070. }
  171071. }
  171072. else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN))
  171073. {
  171074. png_chunk_warning(png_ptr, "CRC error");
  171075. }
  171076. }
  171077. #endif
  171078. png_set_PLTE(png_ptr, info_ptr, palette, num);
  171079. #if defined(PNG_READ_tRNS_SUPPORTED)
  171080. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171081. {
  171082. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  171083. {
  171084. if (png_ptr->num_trans > (png_uint_16)num)
  171085. {
  171086. png_warning(png_ptr, "Truncating incorrect tRNS chunk length");
  171087. png_ptr->num_trans = (png_uint_16)num;
  171088. }
  171089. if (info_ptr->num_trans > (png_uint_16)num)
  171090. {
  171091. png_warning(png_ptr, "Truncating incorrect info tRNS chunk length");
  171092. info_ptr->num_trans = (png_uint_16)num;
  171093. }
  171094. }
  171095. }
  171096. #endif
  171097. }
  171098. void /* PRIVATE */
  171099. png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171100. {
  171101. png_debug(1, "in png_handle_IEND\n");
  171102. if (!(png_ptr->mode & PNG_HAVE_IHDR) || !(png_ptr->mode & PNG_HAVE_IDAT))
  171103. {
  171104. png_error(png_ptr, "No image in file");
  171105. }
  171106. png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND);
  171107. if (length != 0)
  171108. {
  171109. png_warning(png_ptr, "Incorrect IEND chunk length");
  171110. }
  171111. png_crc_finish(png_ptr, length);
  171112. info_ptr =info_ptr; /* quiet compiler warnings about unused info_ptr */
  171113. }
  171114. #if defined(PNG_READ_gAMA_SUPPORTED)
  171115. void /* PRIVATE */
  171116. png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171117. {
  171118. png_fixed_point igamma;
  171119. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171120. float file_gamma;
  171121. #endif
  171122. png_byte buf[4];
  171123. png_debug(1, "in png_handle_gAMA\n");
  171124. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171125. png_error(png_ptr, "Missing IHDR before gAMA");
  171126. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171127. {
  171128. png_warning(png_ptr, "Invalid gAMA after IDAT");
  171129. png_crc_finish(png_ptr, length);
  171130. return;
  171131. }
  171132. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171133. png_warning(png_ptr, "Out of place gAMA chunk");
  171134. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  171135. #if defined(PNG_READ_sRGB_SUPPORTED)
  171136. && !(info_ptr->valid & PNG_INFO_sRGB)
  171137. #endif
  171138. )
  171139. {
  171140. png_warning(png_ptr, "Duplicate gAMA chunk");
  171141. png_crc_finish(png_ptr, length);
  171142. return;
  171143. }
  171144. if (length != 4)
  171145. {
  171146. png_warning(png_ptr, "Incorrect gAMA chunk length");
  171147. png_crc_finish(png_ptr, length);
  171148. return;
  171149. }
  171150. png_crc_read(png_ptr, buf, 4);
  171151. if (png_crc_finish(png_ptr, 0))
  171152. return;
  171153. igamma = (png_fixed_point)png_get_uint_32(buf);
  171154. if (igamma == 0)
  171155. {
  171156. png_warning(png_ptr,
  171157. "Ignoring gAMA chunk with gamma=0");
  171158. return;
  171159. }
  171160. #if defined(PNG_READ_sRGB_SUPPORTED)
  171161. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171162. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171163. {
  171164. png_warning(png_ptr,
  171165. "Ignoring incorrect gAMA value when sRGB is also present");
  171166. #ifndef PNG_NO_CONSOLE_IO
  171167. fprintf(stderr, "gamma = (%d/100000)\n", (int)igamma);
  171168. #endif
  171169. return;
  171170. }
  171171. #endif /* PNG_READ_sRGB_SUPPORTED */
  171172. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171173. file_gamma = (float)igamma / (float)100000.0;
  171174. # ifdef PNG_READ_GAMMA_SUPPORTED
  171175. png_ptr->gamma = file_gamma;
  171176. # endif
  171177. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  171178. #endif
  171179. #ifdef PNG_FIXED_POINT_SUPPORTED
  171180. png_set_gAMA_fixed(png_ptr, info_ptr, igamma);
  171181. #endif
  171182. }
  171183. #endif
  171184. #if defined(PNG_READ_sBIT_SUPPORTED)
  171185. void /* PRIVATE */
  171186. png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171187. {
  171188. png_size_t truelen;
  171189. png_byte buf[4];
  171190. png_debug(1, "in png_handle_sBIT\n");
  171191. buf[0] = buf[1] = buf[2] = buf[3] = 0;
  171192. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171193. png_error(png_ptr, "Missing IHDR before sBIT");
  171194. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171195. {
  171196. png_warning(png_ptr, "Invalid sBIT after IDAT");
  171197. png_crc_finish(png_ptr, length);
  171198. return;
  171199. }
  171200. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171201. {
  171202. png_warning(png_ptr, "Out of place sBIT chunk");
  171203. }
  171204. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT))
  171205. {
  171206. png_warning(png_ptr, "Duplicate sBIT chunk");
  171207. png_crc_finish(png_ptr, length);
  171208. return;
  171209. }
  171210. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171211. truelen = 3;
  171212. else
  171213. truelen = (png_size_t)png_ptr->channels;
  171214. if (length != truelen || length > 4)
  171215. {
  171216. png_warning(png_ptr, "Incorrect sBIT chunk length");
  171217. png_crc_finish(png_ptr, length);
  171218. return;
  171219. }
  171220. png_crc_read(png_ptr, buf, truelen);
  171221. if (png_crc_finish(png_ptr, 0))
  171222. return;
  171223. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  171224. {
  171225. png_ptr->sig_bit.red = buf[0];
  171226. png_ptr->sig_bit.green = buf[1];
  171227. png_ptr->sig_bit.blue = buf[2];
  171228. png_ptr->sig_bit.alpha = buf[3];
  171229. }
  171230. else
  171231. {
  171232. png_ptr->sig_bit.gray = buf[0];
  171233. png_ptr->sig_bit.red = buf[0];
  171234. png_ptr->sig_bit.green = buf[0];
  171235. png_ptr->sig_bit.blue = buf[0];
  171236. png_ptr->sig_bit.alpha = buf[1];
  171237. }
  171238. png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));
  171239. }
  171240. #endif
  171241. #if defined(PNG_READ_cHRM_SUPPORTED)
  171242. void /* PRIVATE */
  171243. png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171244. {
  171245. png_byte buf[4];
  171246. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171247. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  171248. #endif
  171249. png_fixed_point int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171250. int_y_green, int_x_blue, int_y_blue;
  171251. png_uint_32 uint_x, uint_y;
  171252. png_debug(1, "in png_handle_cHRM\n");
  171253. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171254. png_error(png_ptr, "Missing IHDR before cHRM");
  171255. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171256. {
  171257. png_warning(png_ptr, "Invalid cHRM after IDAT");
  171258. png_crc_finish(png_ptr, length);
  171259. return;
  171260. }
  171261. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171262. png_warning(png_ptr, "Missing PLTE before cHRM");
  171263. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)
  171264. #if defined(PNG_READ_sRGB_SUPPORTED)
  171265. && !(info_ptr->valid & PNG_INFO_sRGB)
  171266. #endif
  171267. )
  171268. {
  171269. png_warning(png_ptr, "Duplicate cHRM chunk");
  171270. png_crc_finish(png_ptr, length);
  171271. return;
  171272. }
  171273. if (length != 32)
  171274. {
  171275. png_warning(png_ptr, "Incorrect cHRM chunk length");
  171276. png_crc_finish(png_ptr, length);
  171277. return;
  171278. }
  171279. png_crc_read(png_ptr, buf, 4);
  171280. uint_x = png_get_uint_32(buf);
  171281. png_crc_read(png_ptr, buf, 4);
  171282. uint_y = png_get_uint_32(buf);
  171283. if (uint_x > 80000L || uint_y > 80000L ||
  171284. uint_x + uint_y > 100000L)
  171285. {
  171286. png_warning(png_ptr, "Invalid cHRM white point");
  171287. png_crc_finish(png_ptr, 24);
  171288. return;
  171289. }
  171290. int_x_white = (png_fixed_point)uint_x;
  171291. int_y_white = (png_fixed_point)uint_y;
  171292. png_crc_read(png_ptr, buf, 4);
  171293. uint_x = png_get_uint_32(buf);
  171294. png_crc_read(png_ptr, buf, 4);
  171295. uint_y = png_get_uint_32(buf);
  171296. if (uint_x + uint_y > 100000L)
  171297. {
  171298. png_warning(png_ptr, "Invalid cHRM red point");
  171299. png_crc_finish(png_ptr, 16);
  171300. return;
  171301. }
  171302. int_x_red = (png_fixed_point)uint_x;
  171303. int_y_red = (png_fixed_point)uint_y;
  171304. png_crc_read(png_ptr, buf, 4);
  171305. uint_x = png_get_uint_32(buf);
  171306. png_crc_read(png_ptr, buf, 4);
  171307. uint_y = png_get_uint_32(buf);
  171308. if (uint_x + uint_y > 100000L)
  171309. {
  171310. png_warning(png_ptr, "Invalid cHRM green point");
  171311. png_crc_finish(png_ptr, 8);
  171312. return;
  171313. }
  171314. int_x_green = (png_fixed_point)uint_x;
  171315. int_y_green = (png_fixed_point)uint_y;
  171316. png_crc_read(png_ptr, buf, 4);
  171317. uint_x = png_get_uint_32(buf);
  171318. png_crc_read(png_ptr, buf, 4);
  171319. uint_y = png_get_uint_32(buf);
  171320. if (uint_x + uint_y > 100000L)
  171321. {
  171322. png_warning(png_ptr, "Invalid cHRM blue point");
  171323. png_crc_finish(png_ptr, 0);
  171324. return;
  171325. }
  171326. int_x_blue = (png_fixed_point)uint_x;
  171327. int_y_blue = (png_fixed_point)uint_y;
  171328. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171329. white_x = (float)int_x_white / (float)100000.0;
  171330. white_y = (float)int_y_white / (float)100000.0;
  171331. red_x = (float)int_x_red / (float)100000.0;
  171332. red_y = (float)int_y_red / (float)100000.0;
  171333. green_x = (float)int_x_green / (float)100000.0;
  171334. green_y = (float)int_y_green / (float)100000.0;
  171335. blue_x = (float)int_x_blue / (float)100000.0;
  171336. blue_y = (float)int_y_blue / (float)100000.0;
  171337. #endif
  171338. #if defined(PNG_READ_sRGB_SUPPORTED)
  171339. if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB))
  171340. {
  171341. if (PNG_OUT_OF_RANGE(int_x_white, 31270, 1000) ||
  171342. PNG_OUT_OF_RANGE(int_y_white, 32900, 1000) ||
  171343. PNG_OUT_OF_RANGE(int_x_red, 64000L, 1000) ||
  171344. PNG_OUT_OF_RANGE(int_y_red, 33000, 1000) ||
  171345. PNG_OUT_OF_RANGE(int_x_green, 30000, 1000) ||
  171346. PNG_OUT_OF_RANGE(int_y_green, 60000L, 1000) ||
  171347. PNG_OUT_OF_RANGE(int_x_blue, 15000, 1000) ||
  171348. PNG_OUT_OF_RANGE(int_y_blue, 6000, 1000))
  171349. {
  171350. png_warning(png_ptr,
  171351. "Ignoring incorrect cHRM value when sRGB is also present");
  171352. #ifndef PNG_NO_CONSOLE_IO
  171353. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171354. fprintf(stderr,"wx=%f, wy=%f, rx=%f, ry=%f\n",
  171355. white_x, white_y, red_x, red_y);
  171356. fprintf(stderr,"gx=%f, gy=%f, bx=%f, by=%f\n",
  171357. green_x, green_y, blue_x, blue_y);
  171358. #else
  171359. fprintf(stderr,"wx=%ld, wy=%ld, rx=%ld, ry=%ld\n",
  171360. int_x_white, int_y_white, int_x_red, int_y_red);
  171361. fprintf(stderr,"gx=%ld, gy=%ld, bx=%ld, by=%ld\n",
  171362. int_x_green, int_y_green, int_x_blue, int_y_blue);
  171363. #endif
  171364. #endif /* PNG_NO_CONSOLE_IO */
  171365. }
  171366. png_crc_finish(png_ptr, 0);
  171367. return;
  171368. }
  171369. #endif /* PNG_READ_sRGB_SUPPORTED */
  171370. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171371. png_set_cHRM(png_ptr, info_ptr,
  171372. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  171373. #endif
  171374. #ifdef PNG_FIXED_POINT_SUPPORTED
  171375. png_set_cHRM_fixed(png_ptr, info_ptr,
  171376. int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171377. int_y_green, int_x_blue, int_y_blue);
  171378. #endif
  171379. if (png_crc_finish(png_ptr, 0))
  171380. return;
  171381. }
  171382. #endif
  171383. #if defined(PNG_READ_sRGB_SUPPORTED)
  171384. void /* PRIVATE */
  171385. png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171386. {
  171387. int intent;
  171388. png_byte buf[1];
  171389. png_debug(1, "in png_handle_sRGB\n");
  171390. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171391. png_error(png_ptr, "Missing IHDR before sRGB");
  171392. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171393. {
  171394. png_warning(png_ptr, "Invalid sRGB after IDAT");
  171395. png_crc_finish(png_ptr, length);
  171396. return;
  171397. }
  171398. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171399. png_warning(png_ptr, "Out of place sRGB chunk");
  171400. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171401. {
  171402. png_warning(png_ptr, "Duplicate sRGB chunk");
  171403. png_crc_finish(png_ptr, length);
  171404. return;
  171405. }
  171406. if (length != 1)
  171407. {
  171408. png_warning(png_ptr, "Incorrect sRGB chunk length");
  171409. png_crc_finish(png_ptr, length);
  171410. return;
  171411. }
  171412. png_crc_read(png_ptr, buf, 1);
  171413. if (png_crc_finish(png_ptr, 0))
  171414. return;
  171415. intent = buf[0];
  171416. if (intent >= PNG_sRGB_INTENT_LAST)
  171417. {
  171418. png_warning(png_ptr, "Unknown sRGB intent");
  171419. return;
  171420. }
  171421. #if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  171422. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA))
  171423. {
  171424. png_fixed_point igamma;
  171425. #ifdef PNG_FIXED_POINT_SUPPORTED
  171426. igamma=info_ptr->int_gamma;
  171427. #else
  171428. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171429. igamma=(png_fixed_point)(info_ptr->gamma * 100000.);
  171430. # endif
  171431. #endif
  171432. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171433. {
  171434. png_warning(png_ptr,
  171435. "Ignoring incorrect gAMA value when sRGB is also present");
  171436. #ifndef PNG_NO_CONSOLE_IO
  171437. # ifdef PNG_FIXED_POINT_SUPPORTED
  171438. fprintf(stderr,"incorrect gamma=(%d/100000)\n",(int)png_ptr->int_gamma);
  171439. # else
  171440. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171441. fprintf(stderr,"incorrect gamma=%f\n",png_ptr->gamma);
  171442. # endif
  171443. # endif
  171444. #endif
  171445. }
  171446. }
  171447. #endif /* PNG_READ_gAMA_SUPPORTED */
  171448. #ifdef PNG_READ_cHRM_SUPPORTED
  171449. #ifdef PNG_FIXED_POINT_SUPPORTED
  171450. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  171451. if (PNG_OUT_OF_RANGE(info_ptr->int_x_white, 31270, 1000) ||
  171452. PNG_OUT_OF_RANGE(info_ptr->int_y_white, 32900, 1000) ||
  171453. PNG_OUT_OF_RANGE(info_ptr->int_x_red, 64000L, 1000) ||
  171454. PNG_OUT_OF_RANGE(info_ptr->int_y_red, 33000, 1000) ||
  171455. PNG_OUT_OF_RANGE(info_ptr->int_x_green, 30000, 1000) ||
  171456. PNG_OUT_OF_RANGE(info_ptr->int_y_green, 60000L, 1000) ||
  171457. PNG_OUT_OF_RANGE(info_ptr->int_x_blue, 15000, 1000) ||
  171458. PNG_OUT_OF_RANGE(info_ptr->int_y_blue, 6000, 1000))
  171459. {
  171460. png_warning(png_ptr,
  171461. "Ignoring incorrect cHRM value when sRGB is also present");
  171462. }
  171463. #endif /* PNG_FIXED_POINT_SUPPORTED */
  171464. #endif /* PNG_READ_cHRM_SUPPORTED */
  171465. png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent);
  171466. }
  171467. #endif /* PNG_READ_sRGB_SUPPORTED */
  171468. #if defined(PNG_READ_iCCP_SUPPORTED)
  171469. void /* PRIVATE */
  171470. png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171471. {
  171472. png_charp chunkdata;
  171473. png_byte compression_type;
  171474. png_bytep pC;
  171475. png_charp profile;
  171476. png_uint_32 skip = 0;
  171477. png_uint_32 profile_size, profile_length;
  171478. png_size_t slength, prefix_length, data_length;
  171479. png_debug(1, "in png_handle_iCCP\n");
  171480. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171481. png_error(png_ptr, "Missing IHDR before iCCP");
  171482. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171483. {
  171484. png_warning(png_ptr, "Invalid iCCP after IDAT");
  171485. png_crc_finish(png_ptr, length);
  171486. return;
  171487. }
  171488. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171489. png_warning(png_ptr, "Out of place iCCP chunk");
  171490. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP))
  171491. {
  171492. png_warning(png_ptr, "Duplicate iCCP chunk");
  171493. png_crc_finish(png_ptr, length);
  171494. return;
  171495. }
  171496. #ifdef PNG_MAX_MALLOC_64K
  171497. if (length > (png_uint_32)65535L)
  171498. {
  171499. png_warning(png_ptr, "iCCP chunk too large to fit in memory");
  171500. skip = length - (png_uint_32)65535L;
  171501. length = (png_uint_32)65535L;
  171502. }
  171503. #endif
  171504. chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
  171505. slength = (png_size_t)length;
  171506. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171507. if (png_crc_finish(png_ptr, skip))
  171508. {
  171509. png_free(png_ptr, chunkdata);
  171510. return;
  171511. }
  171512. chunkdata[slength] = 0x00;
  171513. for (profile = chunkdata; *profile; profile++)
  171514. ;
  171515. ++profile;
  171516. if ( profile >= chunkdata + slength - 1)
  171517. {
  171518. png_free(png_ptr, chunkdata);
  171519. png_warning(png_ptr, "Malformed iCCP chunk");
  171520. return;
  171521. }
  171522. compression_type = *profile++;
  171523. if (compression_type)
  171524. {
  171525. png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk");
  171526. compression_type=0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.8
  171527. wrote nonzero) */
  171528. }
  171529. prefix_length = profile - chunkdata;
  171530. chunkdata = png_decompress_chunk(png_ptr, compression_type, chunkdata,
  171531. slength, prefix_length, &data_length);
  171532. profile_length = data_length - prefix_length;
  171533. if ( prefix_length > data_length || profile_length < 4)
  171534. {
  171535. png_free(png_ptr, chunkdata);
  171536. png_warning(png_ptr, "Profile size field missing from iCCP chunk");
  171537. return;
  171538. }
  171539. pC = (png_bytep)(chunkdata+prefix_length);
  171540. profile_size = ((*(pC ))<<24) |
  171541. ((*(pC+1))<<16) |
  171542. ((*(pC+2))<< 8) |
  171543. ((*(pC+3)) );
  171544. if(profile_size < profile_length)
  171545. profile_length = profile_size;
  171546. if(profile_size > profile_length)
  171547. {
  171548. png_free(png_ptr, chunkdata);
  171549. png_warning(png_ptr, "Ignoring truncated iCCP profile.");
  171550. return;
  171551. }
  171552. png_set_iCCP(png_ptr, info_ptr, chunkdata, compression_type,
  171553. chunkdata + prefix_length, profile_length);
  171554. png_free(png_ptr, chunkdata);
  171555. }
  171556. #endif /* PNG_READ_iCCP_SUPPORTED */
  171557. #if defined(PNG_READ_sPLT_SUPPORTED)
  171558. void /* PRIVATE */
  171559. png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171560. {
  171561. png_bytep chunkdata;
  171562. png_bytep entry_start;
  171563. png_sPLT_t new_palette;
  171564. #ifdef PNG_NO_POINTER_INDEXING
  171565. png_sPLT_entryp pp;
  171566. #endif
  171567. int data_length, entry_size, i;
  171568. png_uint_32 skip = 0;
  171569. png_size_t slength;
  171570. png_debug(1, "in png_handle_sPLT\n");
  171571. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171572. png_error(png_ptr, "Missing IHDR before sPLT");
  171573. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171574. {
  171575. png_warning(png_ptr, "Invalid sPLT after IDAT");
  171576. png_crc_finish(png_ptr, length);
  171577. return;
  171578. }
  171579. #ifdef PNG_MAX_MALLOC_64K
  171580. if (length > (png_uint_32)65535L)
  171581. {
  171582. png_warning(png_ptr, "sPLT chunk too large to fit in memory");
  171583. skip = length - (png_uint_32)65535L;
  171584. length = (png_uint_32)65535L;
  171585. }
  171586. #endif
  171587. chunkdata = (png_bytep)png_malloc(png_ptr, length + 1);
  171588. slength = (png_size_t)length;
  171589. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171590. if (png_crc_finish(png_ptr, skip))
  171591. {
  171592. png_free(png_ptr, chunkdata);
  171593. return;
  171594. }
  171595. chunkdata[slength] = 0x00;
  171596. for (entry_start = chunkdata; *entry_start; entry_start++)
  171597. ;
  171598. ++entry_start;
  171599. if (entry_start > chunkdata + slength - 2)
  171600. {
  171601. png_free(png_ptr, chunkdata);
  171602. png_warning(png_ptr, "malformed sPLT chunk");
  171603. return;
  171604. }
  171605. new_palette.depth = *entry_start++;
  171606. entry_size = (new_palette.depth == 8 ? 6 : 10);
  171607. data_length = (slength - (entry_start - chunkdata));
  171608. if (data_length % entry_size)
  171609. {
  171610. png_free(png_ptr, chunkdata);
  171611. png_warning(png_ptr, "sPLT chunk has bad length");
  171612. return;
  171613. }
  171614. new_palette.nentries = (png_int_32) ( data_length / entry_size);
  171615. if ((png_uint_32) new_palette.nentries > (png_uint_32) (PNG_SIZE_MAX /
  171616. png_sizeof(png_sPLT_entry)))
  171617. {
  171618. png_warning(png_ptr, "sPLT chunk too long");
  171619. return;
  171620. }
  171621. new_palette.entries = (png_sPLT_entryp)png_malloc_warn(
  171622. png_ptr, new_palette.nentries * png_sizeof(png_sPLT_entry));
  171623. if (new_palette.entries == NULL)
  171624. {
  171625. png_warning(png_ptr, "sPLT chunk requires too much memory");
  171626. return;
  171627. }
  171628. #ifndef PNG_NO_POINTER_INDEXING
  171629. for (i = 0; i < new_palette.nentries; i++)
  171630. {
  171631. png_sPLT_entryp pp = new_palette.entries + i;
  171632. if (new_palette.depth == 8)
  171633. {
  171634. pp->red = *entry_start++;
  171635. pp->green = *entry_start++;
  171636. pp->blue = *entry_start++;
  171637. pp->alpha = *entry_start++;
  171638. }
  171639. else
  171640. {
  171641. pp->red = png_get_uint_16(entry_start); entry_start += 2;
  171642. pp->green = png_get_uint_16(entry_start); entry_start += 2;
  171643. pp->blue = png_get_uint_16(entry_start); entry_start += 2;
  171644. pp->alpha = png_get_uint_16(entry_start); entry_start += 2;
  171645. }
  171646. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  171647. }
  171648. #else
  171649. pp = new_palette.entries;
  171650. for (i = 0; i < new_palette.nentries; i++)
  171651. {
  171652. if (new_palette.depth == 8)
  171653. {
  171654. pp[i].red = *entry_start++;
  171655. pp[i].green = *entry_start++;
  171656. pp[i].blue = *entry_start++;
  171657. pp[i].alpha = *entry_start++;
  171658. }
  171659. else
  171660. {
  171661. pp[i].red = png_get_uint_16(entry_start); entry_start += 2;
  171662. pp[i].green = png_get_uint_16(entry_start); entry_start += 2;
  171663. pp[i].blue = png_get_uint_16(entry_start); entry_start += 2;
  171664. pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2;
  171665. }
  171666. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  171667. }
  171668. #endif
  171669. new_palette.name = (png_charp)chunkdata;
  171670. png_set_sPLT(png_ptr, info_ptr, &new_palette, 1);
  171671. png_free(png_ptr, chunkdata);
  171672. png_free(png_ptr, new_palette.entries);
  171673. }
  171674. #endif /* PNG_READ_sPLT_SUPPORTED */
  171675. #if defined(PNG_READ_tRNS_SUPPORTED)
  171676. void /* PRIVATE */
  171677. png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171678. {
  171679. png_byte readbuf[PNG_MAX_PALETTE_LENGTH];
  171680. int bit_mask;
  171681. png_debug(1, "in png_handle_tRNS\n");
  171682. bit_mask = (1 << png_ptr->bit_depth) - 1;
  171683. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171684. png_error(png_ptr, "Missing IHDR before tRNS");
  171685. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171686. {
  171687. png_warning(png_ptr, "Invalid tRNS after IDAT");
  171688. png_crc_finish(png_ptr, length);
  171689. return;
  171690. }
  171691. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  171692. {
  171693. png_warning(png_ptr, "Duplicate tRNS chunk");
  171694. png_crc_finish(png_ptr, length);
  171695. return;
  171696. }
  171697. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  171698. {
  171699. png_byte buf[2];
  171700. if (length != 2)
  171701. {
  171702. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171703. png_crc_finish(png_ptr, length);
  171704. return;
  171705. }
  171706. png_crc_read(png_ptr, buf, 2);
  171707. png_ptr->num_trans = 1;
  171708. png_ptr->trans_values.gray = png_get_uint_16(buf) & bit_mask;
  171709. }
  171710. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  171711. {
  171712. png_byte buf[6];
  171713. if (length != 6)
  171714. {
  171715. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171716. png_crc_finish(png_ptr, length);
  171717. return;
  171718. }
  171719. png_crc_read(png_ptr, buf, (png_size_t)length);
  171720. png_ptr->num_trans = 1;
  171721. png_ptr->trans_values.red = png_get_uint_16(buf) & bit_mask;
  171722. png_ptr->trans_values.green = png_get_uint_16(buf + 2) & bit_mask;
  171723. png_ptr->trans_values.blue = png_get_uint_16(buf + 4) & bit_mask;
  171724. }
  171725. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171726. {
  171727. if (!(png_ptr->mode & PNG_HAVE_PLTE))
  171728. {
  171729. png_warning(png_ptr, "Missing PLTE before tRNS");
  171730. }
  171731. if (length > (png_uint_32)png_ptr->num_palette ||
  171732. length > PNG_MAX_PALETTE_LENGTH)
  171733. {
  171734. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171735. png_crc_finish(png_ptr, length);
  171736. return;
  171737. }
  171738. if (length == 0)
  171739. {
  171740. png_warning(png_ptr, "Zero length tRNS chunk");
  171741. png_crc_finish(png_ptr, length);
  171742. return;
  171743. }
  171744. png_crc_read(png_ptr, readbuf, (png_size_t)length);
  171745. png_ptr->num_trans = (png_uint_16)length;
  171746. }
  171747. else
  171748. {
  171749. png_warning(png_ptr, "tRNS chunk not allowed with alpha channel");
  171750. png_crc_finish(png_ptr, length);
  171751. return;
  171752. }
  171753. if (png_crc_finish(png_ptr, 0))
  171754. {
  171755. png_ptr->num_trans = 0;
  171756. return;
  171757. }
  171758. png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
  171759. &(png_ptr->trans_values));
  171760. }
  171761. #endif
  171762. #if defined(PNG_READ_bKGD_SUPPORTED)
  171763. void /* PRIVATE */
  171764. png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171765. {
  171766. png_size_t truelen;
  171767. png_byte buf[6];
  171768. png_debug(1, "in png_handle_bKGD\n");
  171769. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171770. png_error(png_ptr, "Missing IHDR before bKGD");
  171771. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171772. {
  171773. png_warning(png_ptr, "Invalid bKGD after IDAT");
  171774. png_crc_finish(png_ptr, length);
  171775. return;
  171776. }
  171777. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  171778. !(png_ptr->mode & PNG_HAVE_PLTE))
  171779. {
  171780. png_warning(png_ptr, "Missing PLTE before bKGD");
  171781. png_crc_finish(png_ptr, length);
  171782. return;
  171783. }
  171784. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD))
  171785. {
  171786. png_warning(png_ptr, "Duplicate bKGD chunk");
  171787. png_crc_finish(png_ptr, length);
  171788. return;
  171789. }
  171790. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171791. truelen = 1;
  171792. else if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  171793. truelen = 6;
  171794. else
  171795. truelen = 2;
  171796. if (length != truelen)
  171797. {
  171798. png_warning(png_ptr, "Incorrect bKGD chunk length");
  171799. png_crc_finish(png_ptr, length);
  171800. return;
  171801. }
  171802. png_crc_read(png_ptr, buf, truelen);
  171803. if (png_crc_finish(png_ptr, 0))
  171804. return;
  171805. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171806. {
  171807. png_ptr->background.index = buf[0];
  171808. if(info_ptr->num_palette)
  171809. {
  171810. if(buf[0] > info_ptr->num_palette)
  171811. {
  171812. png_warning(png_ptr, "Incorrect bKGD chunk index value");
  171813. return;
  171814. }
  171815. png_ptr->background.red =
  171816. (png_uint_16)png_ptr->palette[buf[0]].red;
  171817. png_ptr->background.green =
  171818. (png_uint_16)png_ptr->palette[buf[0]].green;
  171819. png_ptr->background.blue =
  171820. (png_uint_16)png_ptr->palette[buf[0]].blue;
  171821. }
  171822. }
  171823. else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */
  171824. {
  171825. png_ptr->background.red =
  171826. png_ptr->background.green =
  171827. png_ptr->background.blue =
  171828. png_ptr->background.gray = png_get_uint_16(buf);
  171829. }
  171830. else
  171831. {
  171832. png_ptr->background.red = png_get_uint_16(buf);
  171833. png_ptr->background.green = png_get_uint_16(buf + 2);
  171834. png_ptr->background.blue = png_get_uint_16(buf + 4);
  171835. }
  171836. png_set_bKGD(png_ptr, info_ptr, &(png_ptr->background));
  171837. }
  171838. #endif
  171839. #if defined(PNG_READ_hIST_SUPPORTED)
  171840. void /* PRIVATE */
  171841. png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171842. {
  171843. unsigned int num, i;
  171844. png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH];
  171845. png_debug(1, "in png_handle_hIST\n");
  171846. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171847. png_error(png_ptr, "Missing IHDR before hIST");
  171848. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171849. {
  171850. png_warning(png_ptr, "Invalid hIST after IDAT");
  171851. png_crc_finish(png_ptr, length);
  171852. return;
  171853. }
  171854. else if (!(png_ptr->mode & PNG_HAVE_PLTE))
  171855. {
  171856. png_warning(png_ptr, "Missing PLTE before hIST");
  171857. png_crc_finish(png_ptr, length);
  171858. return;
  171859. }
  171860. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST))
  171861. {
  171862. png_warning(png_ptr, "Duplicate hIST chunk");
  171863. png_crc_finish(png_ptr, length);
  171864. return;
  171865. }
  171866. num = length / 2 ;
  171867. if (num != (unsigned int) png_ptr->num_palette || num >
  171868. (unsigned int) PNG_MAX_PALETTE_LENGTH)
  171869. {
  171870. png_warning(png_ptr, "Incorrect hIST chunk length");
  171871. png_crc_finish(png_ptr, length);
  171872. return;
  171873. }
  171874. for (i = 0; i < num; i++)
  171875. {
  171876. png_byte buf[2];
  171877. png_crc_read(png_ptr, buf, 2);
  171878. readbuf[i] = png_get_uint_16(buf);
  171879. }
  171880. if (png_crc_finish(png_ptr, 0))
  171881. return;
  171882. png_set_hIST(png_ptr, info_ptr, readbuf);
  171883. }
  171884. #endif
  171885. #if defined(PNG_READ_pHYs_SUPPORTED)
  171886. void /* PRIVATE */
  171887. png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171888. {
  171889. png_byte buf[9];
  171890. png_uint_32 res_x, res_y;
  171891. int unit_type;
  171892. png_debug(1, "in png_handle_pHYs\n");
  171893. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171894. png_error(png_ptr, "Missing IHDR before pHYs");
  171895. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171896. {
  171897. png_warning(png_ptr, "Invalid pHYs after IDAT");
  171898. png_crc_finish(png_ptr, length);
  171899. return;
  171900. }
  171901. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  171902. {
  171903. png_warning(png_ptr, "Duplicate pHYs chunk");
  171904. png_crc_finish(png_ptr, length);
  171905. return;
  171906. }
  171907. if (length != 9)
  171908. {
  171909. png_warning(png_ptr, "Incorrect pHYs chunk length");
  171910. png_crc_finish(png_ptr, length);
  171911. return;
  171912. }
  171913. png_crc_read(png_ptr, buf, 9);
  171914. if (png_crc_finish(png_ptr, 0))
  171915. return;
  171916. res_x = png_get_uint_32(buf);
  171917. res_y = png_get_uint_32(buf + 4);
  171918. unit_type = buf[8];
  171919. png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
  171920. }
  171921. #endif
  171922. #if defined(PNG_READ_oFFs_SUPPORTED)
  171923. void /* PRIVATE */
  171924. png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171925. {
  171926. png_byte buf[9];
  171927. png_int_32 offset_x, offset_y;
  171928. int unit_type;
  171929. png_debug(1, "in png_handle_oFFs\n");
  171930. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171931. png_error(png_ptr, "Missing IHDR before oFFs");
  171932. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171933. {
  171934. png_warning(png_ptr, "Invalid oFFs after IDAT");
  171935. png_crc_finish(png_ptr, length);
  171936. return;
  171937. }
  171938. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
  171939. {
  171940. png_warning(png_ptr, "Duplicate oFFs chunk");
  171941. png_crc_finish(png_ptr, length);
  171942. return;
  171943. }
  171944. if (length != 9)
  171945. {
  171946. png_warning(png_ptr, "Incorrect oFFs chunk length");
  171947. png_crc_finish(png_ptr, length);
  171948. return;
  171949. }
  171950. png_crc_read(png_ptr, buf, 9);
  171951. if (png_crc_finish(png_ptr, 0))
  171952. return;
  171953. offset_x = png_get_int_32(buf);
  171954. offset_y = png_get_int_32(buf + 4);
  171955. unit_type = buf[8];
  171956. png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type);
  171957. }
  171958. #endif
  171959. #if defined(PNG_READ_pCAL_SUPPORTED)
  171960. void /* PRIVATE */
  171961. png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171962. {
  171963. png_charp purpose;
  171964. png_int_32 X0, X1;
  171965. png_byte type, nparams;
  171966. png_charp buf, units, endptr;
  171967. png_charpp params;
  171968. png_size_t slength;
  171969. int i;
  171970. png_debug(1, "in png_handle_pCAL\n");
  171971. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171972. png_error(png_ptr, "Missing IHDR before pCAL");
  171973. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171974. {
  171975. png_warning(png_ptr, "Invalid pCAL after IDAT");
  171976. png_crc_finish(png_ptr, length);
  171977. return;
  171978. }
  171979. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL))
  171980. {
  171981. png_warning(png_ptr, "Duplicate pCAL chunk");
  171982. png_crc_finish(png_ptr, length);
  171983. return;
  171984. }
  171985. png_debug1(2, "Allocating and reading pCAL chunk data (%lu bytes)\n",
  171986. length + 1);
  171987. purpose = (png_charp)png_malloc_warn(png_ptr, length + 1);
  171988. if (purpose == NULL)
  171989. {
  171990. png_warning(png_ptr, "No memory for pCAL purpose.");
  171991. return;
  171992. }
  171993. slength = (png_size_t)length;
  171994. png_crc_read(png_ptr, (png_bytep)purpose, slength);
  171995. if (png_crc_finish(png_ptr, 0))
  171996. {
  171997. png_free(png_ptr, purpose);
  171998. return;
  171999. }
  172000. purpose[slength] = 0x00; /* null terminate the last string */
  172001. png_debug(3, "Finding end of pCAL purpose string\n");
  172002. for (buf = purpose; *buf; buf++)
  172003. ;
  172004. endptr = purpose + slength;
  172005. if (endptr <= buf + 12)
  172006. {
  172007. png_warning(png_ptr, "Invalid pCAL data");
  172008. png_free(png_ptr, purpose);
  172009. return;
  172010. }
  172011. png_debug(3, "Reading pCAL X0, X1, type, nparams, and units\n");
  172012. X0 = png_get_int_32((png_bytep)buf+1);
  172013. X1 = png_get_int_32((png_bytep)buf+5);
  172014. type = buf[9];
  172015. nparams = buf[10];
  172016. units = buf + 11;
  172017. png_debug(3, "Checking pCAL equation type and number of parameters\n");
  172018. if ((type == PNG_EQUATION_LINEAR && nparams != 2) ||
  172019. (type == PNG_EQUATION_BASE_E && nparams != 3) ||
  172020. (type == PNG_EQUATION_ARBITRARY && nparams != 3) ||
  172021. (type == PNG_EQUATION_HYPERBOLIC && nparams != 4))
  172022. {
  172023. png_warning(png_ptr, "Invalid pCAL parameters for equation type");
  172024. png_free(png_ptr, purpose);
  172025. return;
  172026. }
  172027. else if (type >= PNG_EQUATION_LAST)
  172028. {
  172029. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  172030. }
  172031. for (buf = units; *buf; buf++)
  172032. ;
  172033. png_debug(3, "Allocating pCAL parameters array\n");
  172034. params = (png_charpp)png_malloc_warn(png_ptr, (png_uint_32)(nparams
  172035. *png_sizeof(png_charp))) ;
  172036. if (params == NULL)
  172037. {
  172038. png_free(png_ptr, purpose);
  172039. png_warning(png_ptr, "No memory for pCAL params.");
  172040. return;
  172041. }
  172042. for (i = 0; i < (int)nparams; i++)
  172043. {
  172044. buf++; /* Skip the null string terminator from previous parameter. */
  172045. png_debug1(3, "Reading pCAL parameter %d\n", i);
  172046. for (params[i] = buf; buf <= endptr && *buf != 0x00; buf++)
  172047. ;
  172048. if (buf > endptr)
  172049. {
  172050. png_warning(png_ptr, "Invalid pCAL data");
  172051. png_free(png_ptr, purpose);
  172052. png_free(png_ptr, params);
  172053. return;
  172054. }
  172055. }
  172056. png_set_pCAL(png_ptr, info_ptr, purpose, X0, X1, type, nparams,
  172057. units, params);
  172058. png_free(png_ptr, purpose);
  172059. png_free(png_ptr, params);
  172060. }
  172061. #endif
  172062. #if defined(PNG_READ_sCAL_SUPPORTED)
  172063. void /* PRIVATE */
  172064. png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172065. {
  172066. png_charp buffer, ep;
  172067. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172068. double width, height;
  172069. png_charp vp;
  172070. #else
  172071. #ifdef PNG_FIXED_POINT_SUPPORTED
  172072. png_charp swidth, sheight;
  172073. #endif
  172074. #endif
  172075. png_size_t slength;
  172076. png_debug(1, "in png_handle_sCAL\n");
  172077. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172078. png_error(png_ptr, "Missing IHDR before sCAL");
  172079. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172080. {
  172081. png_warning(png_ptr, "Invalid sCAL after IDAT");
  172082. png_crc_finish(png_ptr, length);
  172083. return;
  172084. }
  172085. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL))
  172086. {
  172087. png_warning(png_ptr, "Duplicate sCAL chunk");
  172088. png_crc_finish(png_ptr, length);
  172089. return;
  172090. }
  172091. png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)\n",
  172092. length + 1);
  172093. buffer = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172094. if (buffer == NULL)
  172095. {
  172096. png_warning(png_ptr, "Out of memory while processing sCAL chunk");
  172097. return;
  172098. }
  172099. slength = (png_size_t)length;
  172100. png_crc_read(png_ptr, (png_bytep)buffer, slength);
  172101. if (png_crc_finish(png_ptr, 0))
  172102. {
  172103. png_free(png_ptr, buffer);
  172104. return;
  172105. }
  172106. buffer[slength] = 0x00; /* null terminate the last string */
  172107. ep = buffer + 1; /* skip unit byte */
  172108. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172109. width = png_strtod(png_ptr, ep, &vp);
  172110. if (*vp)
  172111. {
  172112. png_warning(png_ptr, "malformed width string in sCAL chunk");
  172113. return;
  172114. }
  172115. #else
  172116. #ifdef PNG_FIXED_POINT_SUPPORTED
  172117. swidth = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172118. if (swidth == NULL)
  172119. {
  172120. png_warning(png_ptr, "Out of memory while processing sCAL chunk width");
  172121. return;
  172122. }
  172123. png_memcpy(swidth, ep, (png_size_t)png_strlen(ep));
  172124. #endif
  172125. #endif
  172126. for (ep = buffer; *ep; ep++)
  172127. ;
  172128. ep++;
  172129. if (buffer + slength < ep)
  172130. {
  172131. png_warning(png_ptr, "Truncated sCAL chunk");
  172132. #if defined(PNG_FIXED_POINT_SUPPORTED) && \
  172133. !defined(PNG_FLOATING_POINT_SUPPORTED)
  172134. png_free(png_ptr, swidth);
  172135. #endif
  172136. png_free(png_ptr, buffer);
  172137. return;
  172138. }
  172139. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172140. height = png_strtod(png_ptr, ep, &vp);
  172141. if (*vp)
  172142. {
  172143. png_warning(png_ptr, "malformed height string in sCAL chunk");
  172144. return;
  172145. }
  172146. #else
  172147. #ifdef PNG_FIXED_POINT_SUPPORTED
  172148. sheight = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172149. if (swidth == NULL)
  172150. {
  172151. png_warning(png_ptr, "Out of memory while processing sCAL chunk height");
  172152. return;
  172153. }
  172154. png_memcpy(sheight, ep, (png_size_t)png_strlen(ep));
  172155. #endif
  172156. #endif
  172157. if (buffer + slength < ep
  172158. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172159. || width <= 0. || height <= 0.
  172160. #endif
  172161. )
  172162. {
  172163. png_warning(png_ptr, "Invalid sCAL data");
  172164. png_free(png_ptr, buffer);
  172165. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172166. png_free(png_ptr, swidth);
  172167. png_free(png_ptr, sheight);
  172168. #endif
  172169. return;
  172170. }
  172171. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172172. png_set_sCAL(png_ptr, info_ptr, buffer[0], width, height);
  172173. #else
  172174. #ifdef PNG_FIXED_POINT_SUPPORTED
  172175. png_set_sCAL_s(png_ptr, info_ptr, buffer[0], swidth, sheight);
  172176. #endif
  172177. #endif
  172178. png_free(png_ptr, buffer);
  172179. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172180. png_free(png_ptr, swidth);
  172181. png_free(png_ptr, sheight);
  172182. #endif
  172183. }
  172184. #endif
  172185. #if defined(PNG_READ_tIME_SUPPORTED)
  172186. void /* PRIVATE */
  172187. png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172188. {
  172189. png_byte buf[7];
  172190. png_time mod_time;
  172191. png_debug(1, "in png_handle_tIME\n");
  172192. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172193. png_error(png_ptr, "Out of place tIME chunk");
  172194. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME))
  172195. {
  172196. png_warning(png_ptr, "Duplicate tIME chunk");
  172197. png_crc_finish(png_ptr, length);
  172198. return;
  172199. }
  172200. if (png_ptr->mode & PNG_HAVE_IDAT)
  172201. png_ptr->mode |= PNG_AFTER_IDAT;
  172202. if (length != 7)
  172203. {
  172204. png_warning(png_ptr, "Incorrect tIME chunk length");
  172205. png_crc_finish(png_ptr, length);
  172206. return;
  172207. }
  172208. png_crc_read(png_ptr, buf, 7);
  172209. if (png_crc_finish(png_ptr, 0))
  172210. return;
  172211. mod_time.second = buf[6];
  172212. mod_time.minute = buf[5];
  172213. mod_time.hour = buf[4];
  172214. mod_time.day = buf[3];
  172215. mod_time.month = buf[2];
  172216. mod_time.year = png_get_uint_16(buf);
  172217. png_set_tIME(png_ptr, info_ptr, &mod_time);
  172218. }
  172219. #endif
  172220. #if defined(PNG_READ_tEXt_SUPPORTED)
  172221. void /* PRIVATE */
  172222. png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172223. {
  172224. png_textp text_ptr;
  172225. png_charp key;
  172226. png_charp text;
  172227. png_uint_32 skip = 0;
  172228. png_size_t slength;
  172229. int ret;
  172230. png_debug(1, "in png_handle_tEXt\n");
  172231. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172232. png_error(png_ptr, "Missing IHDR before tEXt");
  172233. if (png_ptr->mode & PNG_HAVE_IDAT)
  172234. png_ptr->mode |= PNG_AFTER_IDAT;
  172235. #ifdef PNG_MAX_MALLOC_64K
  172236. if (length > (png_uint_32)65535L)
  172237. {
  172238. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  172239. skip = length - (png_uint_32)65535L;
  172240. length = (png_uint_32)65535L;
  172241. }
  172242. #endif
  172243. key = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172244. if (key == NULL)
  172245. {
  172246. png_warning(png_ptr, "No memory to process text chunk.");
  172247. return;
  172248. }
  172249. slength = (png_size_t)length;
  172250. png_crc_read(png_ptr, (png_bytep)key, slength);
  172251. if (png_crc_finish(png_ptr, skip))
  172252. {
  172253. png_free(png_ptr, key);
  172254. return;
  172255. }
  172256. key[slength] = 0x00;
  172257. for (text = key; *text; text++)
  172258. ;
  172259. if (text != key + slength)
  172260. text++;
  172261. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172262. (png_uint_32)png_sizeof(png_text));
  172263. if (text_ptr == NULL)
  172264. {
  172265. png_warning(png_ptr, "Not enough memory to process text chunk.");
  172266. png_free(png_ptr, key);
  172267. return;
  172268. }
  172269. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  172270. text_ptr->key = key;
  172271. #ifdef PNG_iTXt_SUPPORTED
  172272. text_ptr->lang = NULL;
  172273. text_ptr->lang_key = NULL;
  172274. text_ptr->itxt_length = 0;
  172275. #endif
  172276. text_ptr->text = text;
  172277. text_ptr->text_length = png_strlen(text);
  172278. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172279. png_free(png_ptr, key);
  172280. png_free(png_ptr, text_ptr);
  172281. if (ret)
  172282. png_warning(png_ptr, "Insufficient memory to process text chunk.");
  172283. }
  172284. #endif
  172285. #if defined(PNG_READ_zTXt_SUPPORTED)
  172286. void /* PRIVATE */
  172287. png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172288. {
  172289. png_textp text_ptr;
  172290. png_charp chunkdata;
  172291. png_charp text;
  172292. int comp_type;
  172293. int ret;
  172294. png_size_t slength, prefix_len, data_len;
  172295. png_debug(1, "in png_handle_zTXt\n");
  172296. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172297. png_error(png_ptr, "Missing IHDR before zTXt");
  172298. if (png_ptr->mode & PNG_HAVE_IDAT)
  172299. png_ptr->mode |= PNG_AFTER_IDAT;
  172300. #ifdef PNG_MAX_MALLOC_64K
  172301. if (length > (png_uint_32)65535L)
  172302. {
  172303. png_warning(png_ptr,"zTXt chunk too large to fit in memory");
  172304. png_crc_finish(png_ptr, length);
  172305. return;
  172306. }
  172307. #endif
  172308. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172309. if (chunkdata == NULL)
  172310. {
  172311. png_warning(png_ptr,"Out of memory processing zTXt chunk.");
  172312. return;
  172313. }
  172314. slength = (png_size_t)length;
  172315. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172316. if (png_crc_finish(png_ptr, 0))
  172317. {
  172318. png_free(png_ptr, chunkdata);
  172319. return;
  172320. }
  172321. chunkdata[slength] = 0x00;
  172322. for (text = chunkdata; *text; text++)
  172323. ;
  172324. if (text >= chunkdata + slength - 2)
  172325. {
  172326. png_warning(png_ptr, "Truncated zTXt chunk");
  172327. png_free(png_ptr, chunkdata);
  172328. return;
  172329. }
  172330. else
  172331. {
  172332. comp_type = *(++text);
  172333. if (comp_type != PNG_TEXT_COMPRESSION_zTXt)
  172334. {
  172335. png_warning(png_ptr, "Unknown compression type in zTXt chunk");
  172336. comp_type = PNG_TEXT_COMPRESSION_zTXt;
  172337. }
  172338. text++; /* skip the compression_method byte */
  172339. }
  172340. prefix_len = text - chunkdata;
  172341. chunkdata = (png_charp)png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172342. (png_size_t)length, prefix_len, &data_len);
  172343. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172344. (png_uint_32)png_sizeof(png_text));
  172345. if (text_ptr == NULL)
  172346. {
  172347. png_warning(png_ptr,"Not enough memory to process zTXt chunk.");
  172348. png_free(png_ptr, chunkdata);
  172349. return;
  172350. }
  172351. text_ptr->compression = comp_type;
  172352. text_ptr->key = chunkdata;
  172353. #ifdef PNG_iTXt_SUPPORTED
  172354. text_ptr->lang = NULL;
  172355. text_ptr->lang_key = NULL;
  172356. text_ptr->itxt_length = 0;
  172357. #endif
  172358. text_ptr->text = chunkdata + prefix_len;
  172359. text_ptr->text_length = data_len;
  172360. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172361. png_free(png_ptr, text_ptr);
  172362. png_free(png_ptr, chunkdata);
  172363. if (ret)
  172364. png_error(png_ptr, "Insufficient memory to store zTXt chunk.");
  172365. }
  172366. #endif
  172367. #if defined(PNG_READ_iTXt_SUPPORTED)
  172368. void /* PRIVATE */
  172369. png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172370. {
  172371. png_textp text_ptr;
  172372. png_charp chunkdata;
  172373. png_charp key, lang, text, lang_key;
  172374. int comp_flag;
  172375. int comp_type = 0;
  172376. int ret;
  172377. png_size_t slength, prefix_len, data_len;
  172378. png_debug(1, "in png_handle_iTXt\n");
  172379. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172380. png_error(png_ptr, "Missing IHDR before iTXt");
  172381. if (png_ptr->mode & PNG_HAVE_IDAT)
  172382. png_ptr->mode |= PNG_AFTER_IDAT;
  172383. #ifdef PNG_MAX_MALLOC_64K
  172384. if (length > (png_uint_32)65535L)
  172385. {
  172386. png_warning(png_ptr,"iTXt chunk too large to fit in memory");
  172387. png_crc_finish(png_ptr, length);
  172388. return;
  172389. }
  172390. #endif
  172391. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172392. if (chunkdata == NULL)
  172393. {
  172394. png_warning(png_ptr, "No memory to process iTXt chunk.");
  172395. return;
  172396. }
  172397. slength = (png_size_t)length;
  172398. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172399. if (png_crc_finish(png_ptr, 0))
  172400. {
  172401. png_free(png_ptr, chunkdata);
  172402. return;
  172403. }
  172404. chunkdata[slength] = 0x00;
  172405. for (lang = chunkdata; *lang; lang++)
  172406. ;
  172407. lang++; /* skip NUL separator */
  172408. if (lang >= chunkdata + slength - 3)
  172409. {
  172410. png_warning(png_ptr, "Truncated iTXt chunk");
  172411. png_free(png_ptr, chunkdata);
  172412. return;
  172413. }
  172414. else
  172415. {
  172416. comp_flag = *lang++;
  172417. comp_type = *lang++;
  172418. }
  172419. for (lang_key = lang; *lang_key; lang_key++)
  172420. ;
  172421. lang_key++; /* skip NUL separator */
  172422. if (lang_key >= chunkdata + slength)
  172423. {
  172424. png_warning(png_ptr, "Truncated iTXt chunk");
  172425. png_free(png_ptr, chunkdata);
  172426. return;
  172427. }
  172428. for (text = lang_key; *text; text++)
  172429. ;
  172430. text++; /* skip NUL separator */
  172431. if (text >= chunkdata + slength)
  172432. {
  172433. png_warning(png_ptr, "Malformed iTXt chunk");
  172434. png_free(png_ptr, chunkdata);
  172435. return;
  172436. }
  172437. prefix_len = text - chunkdata;
  172438. key=chunkdata;
  172439. if (comp_flag)
  172440. chunkdata = png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172441. (size_t)length, prefix_len, &data_len);
  172442. else
  172443. data_len=png_strlen(chunkdata + prefix_len);
  172444. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172445. (png_uint_32)png_sizeof(png_text));
  172446. if (text_ptr == NULL)
  172447. {
  172448. png_warning(png_ptr,"Not enough memory to process iTXt chunk.");
  172449. png_free(png_ptr, chunkdata);
  172450. return;
  172451. }
  172452. text_ptr->compression = (int)comp_flag + 1;
  172453. text_ptr->lang_key = chunkdata+(lang_key-key);
  172454. text_ptr->lang = chunkdata+(lang-key);
  172455. text_ptr->itxt_length = data_len;
  172456. text_ptr->text_length = 0;
  172457. text_ptr->key = chunkdata;
  172458. text_ptr->text = chunkdata + prefix_len;
  172459. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172460. png_free(png_ptr, text_ptr);
  172461. png_free(png_ptr, chunkdata);
  172462. if (ret)
  172463. png_error(png_ptr, "Insufficient memory to store iTXt chunk.");
  172464. }
  172465. #endif
  172466. void /* PRIVATE */
  172467. png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172468. {
  172469. png_uint_32 skip = 0;
  172470. png_debug(1, "in png_handle_unknown\n");
  172471. if (png_ptr->mode & PNG_HAVE_IDAT)
  172472. {
  172473. #ifdef PNG_USE_LOCAL_ARRAYS
  172474. PNG_CONST PNG_IDAT;
  172475. #endif
  172476. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* not an IDAT */
  172477. png_ptr->mode |= PNG_AFTER_IDAT;
  172478. }
  172479. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  172480. if (!(png_ptr->chunk_name[0] & 0x20))
  172481. {
  172482. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172483. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172484. PNG_HANDLE_CHUNK_ALWAYS
  172485. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172486. && png_ptr->read_user_chunk_fn == NULL
  172487. #endif
  172488. )
  172489. #endif
  172490. png_chunk_error(png_ptr, "unknown critical chunk");
  172491. }
  172492. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172493. if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) ||
  172494. (png_ptr->read_user_chunk_fn != NULL))
  172495. {
  172496. #ifdef PNG_MAX_MALLOC_64K
  172497. if (length > (png_uint_32)65535L)
  172498. {
  172499. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  172500. skip = length - (png_uint_32)65535L;
  172501. length = (png_uint_32)65535L;
  172502. }
  172503. #endif
  172504. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  172505. (png_charp)png_ptr->chunk_name, 5);
  172506. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  172507. png_ptr->unknown_chunk.size = (png_size_t)length;
  172508. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  172509. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172510. if(png_ptr->read_user_chunk_fn != NULL)
  172511. {
  172512. int ret;
  172513. ret = (*(png_ptr->read_user_chunk_fn))
  172514. (png_ptr, &png_ptr->unknown_chunk);
  172515. if (ret < 0)
  172516. png_chunk_error(png_ptr, "error in user chunk");
  172517. if (ret == 0)
  172518. {
  172519. if (!(png_ptr->chunk_name[0] & 0x20))
  172520. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172521. PNG_HANDLE_CHUNK_ALWAYS)
  172522. png_chunk_error(png_ptr, "unknown critical chunk");
  172523. png_set_unknown_chunks(png_ptr, info_ptr,
  172524. &png_ptr->unknown_chunk, 1);
  172525. }
  172526. }
  172527. #else
  172528. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  172529. #endif
  172530. png_free(png_ptr, png_ptr->unknown_chunk.data);
  172531. png_ptr->unknown_chunk.data = NULL;
  172532. }
  172533. else
  172534. #endif
  172535. skip = length;
  172536. png_crc_finish(png_ptr, skip);
  172537. #if !defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172538. info_ptr = info_ptr; /* quiet compiler warnings about unused info_ptr */
  172539. #endif
  172540. }
  172541. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  172542. void /* PRIVATE */
  172543. png_check_chunk_name(png_structp png_ptr, png_bytep chunk_name)
  172544. {
  172545. png_debug(1, "in png_check_chunk_name\n");
  172546. if (isnonalpha(chunk_name[0]) || isnonalpha(chunk_name[1]) ||
  172547. isnonalpha(chunk_name[2]) || isnonalpha(chunk_name[3]))
  172548. {
  172549. png_chunk_error(png_ptr, "invalid chunk type");
  172550. }
  172551. }
  172552. void /* PRIVATE */
  172553. png_combine_row(png_structp png_ptr, png_bytep row, int mask)
  172554. {
  172555. png_debug(1,"in png_combine_row\n");
  172556. if (mask == 0xff)
  172557. {
  172558. png_memcpy(row, png_ptr->row_buf + 1,
  172559. PNG_ROWBYTES(png_ptr->row_info.pixel_depth, png_ptr->width));
  172560. }
  172561. else
  172562. {
  172563. switch (png_ptr->row_info.pixel_depth)
  172564. {
  172565. case 1:
  172566. {
  172567. png_bytep sp = png_ptr->row_buf + 1;
  172568. png_bytep dp = row;
  172569. int s_inc, s_start, s_end;
  172570. int m = 0x80;
  172571. int shift;
  172572. png_uint_32 i;
  172573. png_uint_32 row_width = png_ptr->width;
  172574. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172575. if (png_ptr->transformations & PNG_PACKSWAP)
  172576. {
  172577. s_start = 0;
  172578. s_end = 7;
  172579. s_inc = 1;
  172580. }
  172581. else
  172582. #endif
  172583. {
  172584. s_start = 7;
  172585. s_end = 0;
  172586. s_inc = -1;
  172587. }
  172588. shift = s_start;
  172589. for (i = 0; i < row_width; i++)
  172590. {
  172591. if (m & mask)
  172592. {
  172593. int value;
  172594. value = (*sp >> shift) & 0x01;
  172595. *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  172596. *dp |= (png_byte)(value << shift);
  172597. }
  172598. if (shift == s_end)
  172599. {
  172600. shift = s_start;
  172601. sp++;
  172602. dp++;
  172603. }
  172604. else
  172605. shift += s_inc;
  172606. if (m == 1)
  172607. m = 0x80;
  172608. else
  172609. m >>= 1;
  172610. }
  172611. break;
  172612. }
  172613. case 2:
  172614. {
  172615. png_bytep sp = png_ptr->row_buf + 1;
  172616. png_bytep dp = row;
  172617. int s_start, s_end, s_inc;
  172618. int m = 0x80;
  172619. int shift;
  172620. png_uint_32 i;
  172621. png_uint_32 row_width = png_ptr->width;
  172622. int value;
  172623. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172624. if (png_ptr->transformations & PNG_PACKSWAP)
  172625. {
  172626. s_start = 0;
  172627. s_end = 6;
  172628. s_inc = 2;
  172629. }
  172630. else
  172631. #endif
  172632. {
  172633. s_start = 6;
  172634. s_end = 0;
  172635. s_inc = -2;
  172636. }
  172637. shift = s_start;
  172638. for (i = 0; i < row_width; i++)
  172639. {
  172640. if (m & mask)
  172641. {
  172642. value = (*sp >> shift) & 0x03;
  172643. *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  172644. *dp |= (png_byte)(value << shift);
  172645. }
  172646. if (shift == s_end)
  172647. {
  172648. shift = s_start;
  172649. sp++;
  172650. dp++;
  172651. }
  172652. else
  172653. shift += s_inc;
  172654. if (m == 1)
  172655. m = 0x80;
  172656. else
  172657. m >>= 1;
  172658. }
  172659. break;
  172660. }
  172661. case 4:
  172662. {
  172663. png_bytep sp = png_ptr->row_buf + 1;
  172664. png_bytep dp = row;
  172665. int s_start, s_end, s_inc;
  172666. int m = 0x80;
  172667. int shift;
  172668. png_uint_32 i;
  172669. png_uint_32 row_width = png_ptr->width;
  172670. int value;
  172671. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172672. if (png_ptr->transformations & PNG_PACKSWAP)
  172673. {
  172674. s_start = 0;
  172675. s_end = 4;
  172676. s_inc = 4;
  172677. }
  172678. else
  172679. #endif
  172680. {
  172681. s_start = 4;
  172682. s_end = 0;
  172683. s_inc = -4;
  172684. }
  172685. shift = s_start;
  172686. for (i = 0; i < row_width; i++)
  172687. {
  172688. if (m & mask)
  172689. {
  172690. value = (*sp >> shift) & 0xf;
  172691. *dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  172692. *dp |= (png_byte)(value << shift);
  172693. }
  172694. if (shift == s_end)
  172695. {
  172696. shift = s_start;
  172697. sp++;
  172698. dp++;
  172699. }
  172700. else
  172701. shift += s_inc;
  172702. if (m == 1)
  172703. m = 0x80;
  172704. else
  172705. m >>= 1;
  172706. }
  172707. break;
  172708. }
  172709. default:
  172710. {
  172711. png_bytep sp = png_ptr->row_buf + 1;
  172712. png_bytep dp = row;
  172713. png_size_t pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
  172714. png_uint_32 i;
  172715. png_uint_32 row_width = png_ptr->width;
  172716. png_byte m = 0x80;
  172717. for (i = 0; i < row_width; i++)
  172718. {
  172719. if (m & mask)
  172720. {
  172721. png_memcpy(dp, sp, pixel_bytes);
  172722. }
  172723. sp += pixel_bytes;
  172724. dp += pixel_bytes;
  172725. if (m == 1)
  172726. m = 0x80;
  172727. else
  172728. m >>= 1;
  172729. }
  172730. break;
  172731. }
  172732. }
  172733. }
  172734. }
  172735. #ifdef PNG_READ_INTERLACING_SUPPORTED
  172736. void /* PRIVATE */
  172737. png_do_read_interlace(png_structp png_ptr)
  172738. {
  172739. png_row_infop row_info = &(png_ptr->row_info);
  172740. png_bytep row = png_ptr->row_buf + 1;
  172741. int pass = png_ptr->pass;
  172742. png_uint_32 transformations = png_ptr->transformations;
  172743. #ifdef PNG_USE_LOCAL_ARRAYS
  172744. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  172745. #endif
  172746. png_debug(1,"in png_do_read_interlace\n");
  172747. if (row != NULL && row_info != NULL)
  172748. {
  172749. png_uint_32 final_width;
  172750. final_width = row_info->width * png_pass_inc[pass];
  172751. switch (row_info->pixel_depth)
  172752. {
  172753. case 1:
  172754. {
  172755. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);
  172756. png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);
  172757. int sshift, dshift;
  172758. int s_start, s_end, s_inc;
  172759. int jstop = png_pass_inc[pass];
  172760. png_byte v;
  172761. png_uint_32 i;
  172762. int j;
  172763. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172764. if (transformations & PNG_PACKSWAP)
  172765. {
  172766. sshift = (int)((row_info->width + 7) & 0x07);
  172767. dshift = (int)((final_width + 7) & 0x07);
  172768. s_start = 7;
  172769. s_end = 0;
  172770. s_inc = -1;
  172771. }
  172772. else
  172773. #endif
  172774. {
  172775. sshift = 7 - (int)((row_info->width + 7) & 0x07);
  172776. dshift = 7 - (int)((final_width + 7) & 0x07);
  172777. s_start = 0;
  172778. s_end = 7;
  172779. s_inc = 1;
  172780. }
  172781. for (i = 0; i < row_info->width; i++)
  172782. {
  172783. v = (png_byte)((*sp >> sshift) & 0x01);
  172784. for (j = 0; j < jstop; j++)
  172785. {
  172786. *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
  172787. *dp |= (png_byte)(v << dshift);
  172788. if (dshift == s_end)
  172789. {
  172790. dshift = s_start;
  172791. dp--;
  172792. }
  172793. else
  172794. dshift += s_inc;
  172795. }
  172796. if (sshift == s_end)
  172797. {
  172798. sshift = s_start;
  172799. sp--;
  172800. }
  172801. else
  172802. sshift += s_inc;
  172803. }
  172804. break;
  172805. }
  172806. case 2:
  172807. {
  172808. png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
  172809. png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
  172810. int sshift, dshift;
  172811. int s_start, s_end, s_inc;
  172812. int jstop = png_pass_inc[pass];
  172813. png_uint_32 i;
  172814. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172815. if (transformations & PNG_PACKSWAP)
  172816. {
  172817. sshift = (int)(((row_info->width + 3) & 0x03) << 1);
  172818. dshift = (int)(((final_width + 3) & 0x03) << 1);
  172819. s_start = 6;
  172820. s_end = 0;
  172821. s_inc = -2;
  172822. }
  172823. else
  172824. #endif
  172825. {
  172826. sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1);
  172827. dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1);
  172828. s_start = 0;
  172829. s_end = 6;
  172830. s_inc = 2;
  172831. }
  172832. for (i = 0; i < row_info->width; i++)
  172833. {
  172834. png_byte v;
  172835. int j;
  172836. v = (png_byte)((*sp >> sshift) & 0x03);
  172837. for (j = 0; j < jstop; j++)
  172838. {
  172839. *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
  172840. *dp |= (png_byte)(v << dshift);
  172841. if (dshift == s_end)
  172842. {
  172843. dshift = s_start;
  172844. dp--;
  172845. }
  172846. else
  172847. dshift += s_inc;
  172848. }
  172849. if (sshift == s_end)
  172850. {
  172851. sshift = s_start;
  172852. sp--;
  172853. }
  172854. else
  172855. sshift += s_inc;
  172856. }
  172857. break;
  172858. }
  172859. case 4:
  172860. {
  172861. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);
  172862. png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);
  172863. int sshift, dshift;
  172864. int s_start, s_end, s_inc;
  172865. png_uint_32 i;
  172866. int jstop = png_pass_inc[pass];
  172867. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172868. if (transformations & PNG_PACKSWAP)
  172869. {
  172870. sshift = (int)(((row_info->width + 1) & 0x01) << 2);
  172871. dshift = (int)(((final_width + 1) & 0x01) << 2);
  172872. s_start = 4;
  172873. s_end = 0;
  172874. s_inc = -4;
  172875. }
  172876. else
  172877. #endif
  172878. {
  172879. sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2);
  172880. dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2);
  172881. s_start = 0;
  172882. s_end = 4;
  172883. s_inc = 4;
  172884. }
  172885. for (i = 0; i < row_info->width; i++)
  172886. {
  172887. png_byte v = (png_byte)((*sp >> sshift) & 0xf);
  172888. int j;
  172889. for (j = 0; j < jstop; j++)
  172890. {
  172891. *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
  172892. *dp |= (png_byte)(v << dshift);
  172893. if (dshift == s_end)
  172894. {
  172895. dshift = s_start;
  172896. dp--;
  172897. }
  172898. else
  172899. dshift += s_inc;
  172900. }
  172901. if (sshift == s_end)
  172902. {
  172903. sshift = s_start;
  172904. sp--;
  172905. }
  172906. else
  172907. sshift += s_inc;
  172908. }
  172909. break;
  172910. }
  172911. default:
  172912. {
  172913. png_size_t pixel_bytes = (row_info->pixel_depth >> 3);
  172914. png_bytep sp = row + (png_size_t)(row_info->width - 1) * pixel_bytes;
  172915. png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
  172916. int jstop = png_pass_inc[pass];
  172917. png_uint_32 i;
  172918. for (i = 0; i < row_info->width; i++)
  172919. {
  172920. png_byte v[8];
  172921. int j;
  172922. png_memcpy(v, sp, pixel_bytes);
  172923. for (j = 0; j < jstop; j++)
  172924. {
  172925. png_memcpy(dp, v, pixel_bytes);
  172926. dp -= pixel_bytes;
  172927. }
  172928. sp -= pixel_bytes;
  172929. }
  172930. break;
  172931. }
  172932. }
  172933. row_info->width = final_width;
  172934. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,final_width);
  172935. }
  172936. #if !defined(PNG_READ_PACKSWAP_SUPPORTED)
  172937. transformations = transformations; /* silence compiler warning */
  172938. #endif
  172939. }
  172940. #endif /* PNG_READ_INTERLACING_SUPPORTED */
  172941. void /* PRIVATE */
  172942. png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
  172943. png_bytep prev_row, int filter)
  172944. {
  172945. png_debug(1, "in png_read_filter_row\n");
  172946. png_debug2(2,"row = %lu, filter = %d\n", png_ptr->row_number, filter);
  172947. switch (filter)
  172948. {
  172949. case PNG_FILTER_VALUE_NONE:
  172950. break;
  172951. case PNG_FILTER_VALUE_SUB:
  172952. {
  172953. png_uint_32 i;
  172954. png_uint_32 istop = row_info->rowbytes;
  172955. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  172956. png_bytep rp = row + bpp;
  172957. png_bytep lp = row;
  172958. for (i = bpp; i < istop; i++)
  172959. {
  172960. *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff);
  172961. rp++;
  172962. }
  172963. break;
  172964. }
  172965. case PNG_FILTER_VALUE_UP:
  172966. {
  172967. png_uint_32 i;
  172968. png_uint_32 istop = row_info->rowbytes;
  172969. png_bytep rp = row;
  172970. png_bytep pp = prev_row;
  172971. for (i = 0; i < istop; i++)
  172972. {
  172973. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  172974. rp++;
  172975. }
  172976. break;
  172977. }
  172978. case PNG_FILTER_VALUE_AVG:
  172979. {
  172980. png_uint_32 i;
  172981. png_bytep rp = row;
  172982. png_bytep pp = prev_row;
  172983. png_bytep lp = row;
  172984. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  172985. png_uint_32 istop = row_info->rowbytes - bpp;
  172986. for (i = 0; i < bpp; i++)
  172987. {
  172988. *rp = (png_byte)(((int)(*rp) +
  172989. ((int)(*pp++) / 2 )) & 0xff);
  172990. rp++;
  172991. }
  172992. for (i = 0; i < istop; i++)
  172993. {
  172994. *rp = (png_byte)(((int)(*rp) +
  172995. (int)(*pp++ + *lp++) / 2 ) & 0xff);
  172996. rp++;
  172997. }
  172998. break;
  172999. }
  173000. case PNG_FILTER_VALUE_PAETH:
  173001. {
  173002. png_uint_32 i;
  173003. png_bytep rp = row;
  173004. png_bytep pp = prev_row;
  173005. png_bytep lp = row;
  173006. png_bytep cp = prev_row;
  173007. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173008. png_uint_32 istop=row_info->rowbytes - bpp;
  173009. for (i = 0; i < bpp; i++)
  173010. {
  173011. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  173012. rp++;
  173013. }
  173014. for (i = 0; i < istop; i++) /* use leftover rp,pp */
  173015. {
  173016. int a, b, c, pa, pb, pc, p;
  173017. a = *lp++;
  173018. b = *pp++;
  173019. c = *cp++;
  173020. p = b - c;
  173021. pc = a - c;
  173022. #ifdef PNG_USE_ABS
  173023. pa = abs(p);
  173024. pb = abs(pc);
  173025. pc = abs(p + pc);
  173026. #else
  173027. pa = p < 0 ? -p : p;
  173028. pb = pc < 0 ? -pc : pc;
  173029. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  173030. #endif
  173031. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  173032. *rp = (png_byte)(((int)(*rp) + p) & 0xff);
  173033. rp++;
  173034. }
  173035. break;
  173036. }
  173037. default:
  173038. png_warning(png_ptr, "Ignoring bad adaptive filter type");
  173039. *row=0;
  173040. break;
  173041. }
  173042. }
  173043. void /* PRIVATE */
  173044. png_read_finish_row(png_structp png_ptr)
  173045. {
  173046. #ifdef PNG_USE_LOCAL_ARRAYS
  173047. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173048. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173049. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173050. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173051. #endif
  173052. png_debug(1, "in png_read_finish_row\n");
  173053. png_ptr->row_number++;
  173054. if (png_ptr->row_number < png_ptr->num_rows)
  173055. return;
  173056. if (png_ptr->interlaced)
  173057. {
  173058. png_ptr->row_number = 0;
  173059. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  173060. png_ptr->rowbytes + 1);
  173061. do
  173062. {
  173063. png_ptr->pass++;
  173064. if (png_ptr->pass >= 7)
  173065. break;
  173066. png_ptr->iwidth = (png_ptr->width +
  173067. png_pass_inc[png_ptr->pass] - 1 -
  173068. png_pass_start[png_ptr->pass]) /
  173069. png_pass_inc[png_ptr->pass];
  173070. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  173071. png_ptr->iwidth) + 1;
  173072. if (!(png_ptr->transformations & PNG_INTERLACE))
  173073. {
  173074. png_ptr->num_rows = (png_ptr->height +
  173075. png_pass_yinc[png_ptr->pass] - 1 -
  173076. png_pass_ystart[png_ptr->pass]) /
  173077. png_pass_yinc[png_ptr->pass];
  173078. if (!(png_ptr->num_rows))
  173079. continue;
  173080. }
  173081. else /* if (png_ptr->transformations & PNG_INTERLACE) */
  173082. break;
  173083. } while (png_ptr->iwidth == 0);
  173084. if (png_ptr->pass < 7)
  173085. return;
  173086. }
  173087. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  173088. {
  173089. #ifdef PNG_USE_LOCAL_ARRAYS
  173090. PNG_CONST PNG_IDAT;
  173091. #endif
  173092. char extra;
  173093. int ret;
  173094. png_ptr->zstream.next_out = (Bytef *)&extra;
  173095. png_ptr->zstream.avail_out = (uInt)1;
  173096. for(;;)
  173097. {
  173098. if (!(png_ptr->zstream.avail_in))
  173099. {
  173100. while (!png_ptr->idat_size)
  173101. {
  173102. png_byte chunk_length[4];
  173103. png_crc_finish(png_ptr, 0);
  173104. png_read_data(png_ptr, chunk_length, 4);
  173105. png_ptr->idat_size = png_get_uint_31(png_ptr, chunk_length);
  173106. png_reset_crc(png_ptr);
  173107. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  173108. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  173109. png_error(png_ptr, "Not enough image data");
  173110. }
  173111. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  173112. png_ptr->zstream.next_in = png_ptr->zbuf;
  173113. if (png_ptr->zbuf_size > png_ptr->idat_size)
  173114. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  173115. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream.avail_in);
  173116. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  173117. }
  173118. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  173119. if (ret == Z_STREAM_END)
  173120. {
  173121. if (!(png_ptr->zstream.avail_out) || png_ptr->zstream.avail_in ||
  173122. png_ptr->idat_size)
  173123. png_warning(png_ptr, "Extra compressed data");
  173124. png_ptr->mode |= PNG_AFTER_IDAT;
  173125. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173126. break;
  173127. }
  173128. if (ret != Z_OK)
  173129. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  173130. "Decompression Error");
  173131. if (!(png_ptr->zstream.avail_out))
  173132. {
  173133. png_warning(png_ptr, "Extra compressed data.");
  173134. png_ptr->mode |= PNG_AFTER_IDAT;
  173135. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173136. break;
  173137. }
  173138. }
  173139. png_ptr->zstream.avail_out = 0;
  173140. }
  173141. if (png_ptr->idat_size || png_ptr->zstream.avail_in)
  173142. png_warning(png_ptr, "Extra compression data");
  173143. inflateReset(&png_ptr->zstream);
  173144. png_ptr->mode |= PNG_AFTER_IDAT;
  173145. }
  173146. void /* PRIVATE */
  173147. png_read_start_row(png_structp png_ptr)
  173148. {
  173149. #ifdef PNG_USE_LOCAL_ARRAYS
  173150. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173151. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173152. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173153. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173154. #endif
  173155. int max_pixel_depth;
  173156. png_uint_32 row_bytes;
  173157. png_debug(1, "in png_read_start_row\n");
  173158. png_ptr->zstream.avail_in = 0;
  173159. png_init_read_transformations(png_ptr);
  173160. if (png_ptr->interlaced)
  173161. {
  173162. if (!(png_ptr->transformations & PNG_INTERLACE))
  173163. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  173164. png_pass_ystart[0]) / png_pass_yinc[0];
  173165. else
  173166. png_ptr->num_rows = png_ptr->height;
  173167. png_ptr->iwidth = (png_ptr->width +
  173168. png_pass_inc[png_ptr->pass] - 1 -
  173169. png_pass_start[png_ptr->pass]) /
  173170. png_pass_inc[png_ptr->pass];
  173171. row_bytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->iwidth) + 1;
  173172. png_ptr->irowbytes = (png_size_t)row_bytes;
  173173. if((png_uint_32)png_ptr->irowbytes != row_bytes)
  173174. png_error(png_ptr, "Rowbytes overflow in png_read_start_row");
  173175. }
  173176. else
  173177. {
  173178. png_ptr->num_rows = png_ptr->height;
  173179. png_ptr->iwidth = png_ptr->width;
  173180. png_ptr->irowbytes = png_ptr->rowbytes + 1;
  173181. }
  173182. max_pixel_depth = png_ptr->pixel_depth;
  173183. #if defined(PNG_READ_PACK_SUPPORTED)
  173184. if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8)
  173185. max_pixel_depth = 8;
  173186. #endif
  173187. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173188. if (png_ptr->transformations & PNG_EXPAND)
  173189. {
  173190. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173191. {
  173192. if (png_ptr->num_trans)
  173193. max_pixel_depth = 32;
  173194. else
  173195. max_pixel_depth = 24;
  173196. }
  173197. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173198. {
  173199. if (max_pixel_depth < 8)
  173200. max_pixel_depth = 8;
  173201. if (png_ptr->num_trans)
  173202. max_pixel_depth *= 2;
  173203. }
  173204. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173205. {
  173206. if (png_ptr->num_trans)
  173207. {
  173208. max_pixel_depth *= 4;
  173209. max_pixel_depth /= 3;
  173210. }
  173211. }
  173212. }
  173213. #endif
  173214. #if defined(PNG_READ_FILLER_SUPPORTED)
  173215. if (png_ptr->transformations & (PNG_FILLER))
  173216. {
  173217. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173218. max_pixel_depth = 32;
  173219. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173220. {
  173221. if (max_pixel_depth <= 8)
  173222. max_pixel_depth = 16;
  173223. else
  173224. max_pixel_depth = 32;
  173225. }
  173226. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173227. {
  173228. if (max_pixel_depth <= 32)
  173229. max_pixel_depth = 32;
  173230. else
  173231. max_pixel_depth = 64;
  173232. }
  173233. }
  173234. #endif
  173235. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  173236. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  173237. {
  173238. if (
  173239. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173240. (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
  173241. #endif
  173242. #if defined(PNG_READ_FILLER_SUPPORTED)
  173243. (png_ptr->transformations & (PNG_FILLER)) ||
  173244. #endif
  173245. png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  173246. {
  173247. if (max_pixel_depth <= 16)
  173248. max_pixel_depth = 32;
  173249. else
  173250. max_pixel_depth = 64;
  173251. }
  173252. else
  173253. {
  173254. if (max_pixel_depth <= 8)
  173255. {
  173256. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173257. max_pixel_depth = 32;
  173258. else
  173259. max_pixel_depth = 24;
  173260. }
  173261. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173262. max_pixel_depth = 64;
  173263. else
  173264. max_pixel_depth = 48;
  173265. }
  173266. }
  173267. #endif
  173268. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \
  173269. defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  173270. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  173271. {
  173272. int user_pixel_depth=png_ptr->user_transform_depth*
  173273. png_ptr->user_transform_channels;
  173274. if(user_pixel_depth > max_pixel_depth)
  173275. max_pixel_depth=user_pixel_depth;
  173276. }
  173277. #endif
  173278. row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
  173279. row_bytes = PNG_ROWBYTES(max_pixel_depth,row_bytes) +
  173280. 1 + ((max_pixel_depth + 7) >> 3);
  173281. #ifdef PNG_MAX_MALLOC_64K
  173282. if (row_bytes > (png_uint_32)65536L)
  173283. png_error(png_ptr, "This image requires a row greater than 64KB");
  173284. #endif
  173285. png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64);
  173286. png_ptr->row_buf = png_ptr->big_row_buf+32;
  173287. #ifdef PNG_MAX_MALLOC_64K
  173288. if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L)
  173289. png_error(png_ptr, "This image requires a row greater than 64KB");
  173290. #endif
  173291. if ((png_uint_32)png_ptr->rowbytes > (png_uint_32)(PNG_SIZE_MAX - 1))
  173292. png_error(png_ptr, "Row has too many bytes to allocate in memory.");
  173293. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)(
  173294. png_ptr->rowbytes + 1));
  173295. png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
  173296. png_debug1(3, "width = %lu,\n", png_ptr->width);
  173297. png_debug1(3, "height = %lu,\n", png_ptr->height);
  173298. png_debug1(3, "iwidth = %lu,\n", png_ptr->iwidth);
  173299. png_debug1(3, "num_rows = %lu\n", png_ptr->num_rows);
  173300. png_debug1(3, "rowbytes = %lu,\n", png_ptr->rowbytes);
  173301. png_debug1(3, "irowbytes = %lu,\n", png_ptr->irowbytes);
  173302. png_ptr->flags |= PNG_FLAG_ROW_INIT;
  173303. }
  173304. #endif /* PNG_READ_SUPPORTED */
  173305. /*** End of inlined file: pngrutil.c ***/
  173306. /*** Start of inlined file: pngset.c ***/
  173307. #define PNG_INTERNAL
  173308. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  173309. #if defined(PNG_bKGD_SUPPORTED)
  173310. void PNGAPI
  173311. png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
  173312. {
  173313. png_debug1(1, "in %s storage function\n", "bKGD");
  173314. if (png_ptr == NULL || info_ptr == NULL)
  173315. return;
  173316. png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));
  173317. info_ptr->valid |= PNG_INFO_bKGD;
  173318. }
  173319. #endif
  173320. #if defined(PNG_cHRM_SUPPORTED)
  173321. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173322. void PNGAPI
  173323. png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
  173324. double white_x, double white_y, double red_x, double red_y,
  173325. double green_x, double green_y, double blue_x, double blue_y)
  173326. {
  173327. png_debug1(1, "in %s storage function\n", "cHRM");
  173328. if (png_ptr == NULL || info_ptr == NULL)
  173329. return;
  173330. if (white_x < 0.0 || white_y < 0.0 ||
  173331. red_x < 0.0 || red_y < 0.0 ||
  173332. green_x < 0.0 || green_y < 0.0 ||
  173333. blue_x < 0.0 || blue_y < 0.0)
  173334. {
  173335. png_warning(png_ptr,
  173336. "Ignoring attempt to set negative chromaticity value");
  173337. return;
  173338. }
  173339. if (white_x > 21474.83 || white_y > 21474.83 ||
  173340. red_x > 21474.83 || red_y > 21474.83 ||
  173341. green_x > 21474.83 || green_y > 21474.83 ||
  173342. blue_x > 21474.83 || blue_y > 21474.83)
  173343. {
  173344. png_warning(png_ptr,
  173345. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173346. return;
  173347. }
  173348. info_ptr->x_white = (float)white_x;
  173349. info_ptr->y_white = (float)white_y;
  173350. info_ptr->x_red = (float)red_x;
  173351. info_ptr->y_red = (float)red_y;
  173352. info_ptr->x_green = (float)green_x;
  173353. info_ptr->y_green = (float)green_y;
  173354. info_ptr->x_blue = (float)blue_x;
  173355. info_ptr->y_blue = (float)blue_y;
  173356. #ifdef PNG_FIXED_POINT_SUPPORTED
  173357. info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5);
  173358. info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5);
  173359. info_ptr->int_x_red = (png_fixed_point)( red_x*100000.+0.5);
  173360. info_ptr->int_y_red = (png_fixed_point)( red_y*100000.+0.5);
  173361. info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5);
  173362. info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5);
  173363. info_ptr->int_x_blue = (png_fixed_point)( blue_x*100000.+0.5);
  173364. info_ptr->int_y_blue = (png_fixed_point)( blue_y*100000.+0.5);
  173365. #endif
  173366. info_ptr->valid |= PNG_INFO_cHRM;
  173367. }
  173368. #endif
  173369. #ifdef PNG_FIXED_POINT_SUPPORTED
  173370. void PNGAPI
  173371. png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  173372. png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
  173373. png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
  173374. png_fixed_point blue_x, png_fixed_point blue_y)
  173375. {
  173376. png_debug1(1, "in %s storage function\n", "cHRM");
  173377. if (png_ptr == NULL || info_ptr == NULL)
  173378. return;
  173379. if (white_x < 0 || white_y < 0 ||
  173380. red_x < 0 || red_y < 0 ||
  173381. green_x < 0 || green_y < 0 ||
  173382. blue_x < 0 || blue_y < 0)
  173383. {
  173384. png_warning(png_ptr,
  173385. "Ignoring attempt to set negative chromaticity value");
  173386. return;
  173387. }
  173388. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173389. if (white_x > (double) PNG_UINT_31_MAX ||
  173390. white_y > (double) PNG_UINT_31_MAX ||
  173391. red_x > (double) PNG_UINT_31_MAX ||
  173392. red_y > (double) PNG_UINT_31_MAX ||
  173393. green_x > (double) PNG_UINT_31_MAX ||
  173394. green_y > (double) PNG_UINT_31_MAX ||
  173395. blue_x > (double) PNG_UINT_31_MAX ||
  173396. blue_y > (double) PNG_UINT_31_MAX)
  173397. #else
  173398. if (white_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173399. white_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173400. red_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173401. red_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173402. green_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173403. green_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173404. blue_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173405. blue_y > (png_fixed_point) PNG_UINT_31_MAX/100000L)
  173406. #endif
  173407. {
  173408. png_warning(png_ptr,
  173409. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173410. return;
  173411. }
  173412. info_ptr->int_x_white = white_x;
  173413. info_ptr->int_y_white = white_y;
  173414. info_ptr->int_x_red = red_x;
  173415. info_ptr->int_y_red = red_y;
  173416. info_ptr->int_x_green = green_x;
  173417. info_ptr->int_y_green = green_y;
  173418. info_ptr->int_x_blue = blue_x;
  173419. info_ptr->int_y_blue = blue_y;
  173420. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173421. info_ptr->x_white = (float)(white_x/100000.);
  173422. info_ptr->y_white = (float)(white_y/100000.);
  173423. info_ptr->x_red = (float)( red_x/100000.);
  173424. info_ptr->y_red = (float)( red_y/100000.);
  173425. info_ptr->x_green = (float)(green_x/100000.);
  173426. info_ptr->y_green = (float)(green_y/100000.);
  173427. info_ptr->x_blue = (float)( blue_x/100000.);
  173428. info_ptr->y_blue = (float)( blue_y/100000.);
  173429. #endif
  173430. info_ptr->valid |= PNG_INFO_cHRM;
  173431. }
  173432. #endif
  173433. #endif
  173434. #if defined(PNG_gAMA_SUPPORTED)
  173435. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173436. void PNGAPI
  173437. png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
  173438. {
  173439. double gamma;
  173440. png_debug1(1, "in %s storage function\n", "gAMA");
  173441. if (png_ptr == NULL || info_ptr == NULL)
  173442. return;
  173443. if (file_gamma > 21474.83)
  173444. {
  173445. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173446. gamma=21474.83;
  173447. }
  173448. else
  173449. gamma=file_gamma;
  173450. info_ptr->gamma = (float)gamma;
  173451. #ifdef PNG_FIXED_POINT_SUPPORTED
  173452. info_ptr->int_gamma = (int)(gamma*100000.+.5);
  173453. #endif
  173454. info_ptr->valid |= PNG_INFO_gAMA;
  173455. if(gamma == 0.0)
  173456. png_warning(png_ptr, "Setting gamma=0");
  173457. }
  173458. #endif
  173459. void PNGAPI
  173460. png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
  173461. int_gamma)
  173462. {
  173463. png_fixed_point gamma;
  173464. png_debug1(1, "in %s storage function\n", "gAMA");
  173465. if (png_ptr == NULL || info_ptr == NULL)
  173466. return;
  173467. if (int_gamma > (png_fixed_point) PNG_UINT_31_MAX)
  173468. {
  173469. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173470. gamma=PNG_UINT_31_MAX;
  173471. }
  173472. else
  173473. {
  173474. if (int_gamma < 0)
  173475. {
  173476. png_warning(png_ptr, "Setting negative gamma to zero");
  173477. gamma=0;
  173478. }
  173479. else
  173480. gamma=int_gamma;
  173481. }
  173482. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173483. info_ptr->gamma = (float)(gamma/100000.);
  173484. #endif
  173485. #ifdef PNG_FIXED_POINT_SUPPORTED
  173486. info_ptr->int_gamma = gamma;
  173487. #endif
  173488. info_ptr->valid |= PNG_INFO_gAMA;
  173489. if(gamma == 0)
  173490. png_warning(png_ptr, "Setting gamma=0");
  173491. }
  173492. #endif
  173493. #if defined(PNG_hIST_SUPPORTED)
  173494. void PNGAPI
  173495. png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
  173496. {
  173497. int i;
  173498. png_debug1(1, "in %s storage function\n", "hIST");
  173499. if (png_ptr == NULL || info_ptr == NULL)
  173500. return;
  173501. if (info_ptr->num_palette == 0 || info_ptr->num_palette
  173502. > PNG_MAX_PALETTE_LENGTH)
  173503. {
  173504. png_warning(png_ptr,
  173505. "Invalid palette size, hIST allocation skipped.");
  173506. return;
  173507. }
  173508. #ifdef PNG_FREE_ME_SUPPORTED
  173509. png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
  173510. #endif
  173511. png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
  173512. (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof (png_uint_16)));
  173513. if (png_ptr->hist == NULL)
  173514. {
  173515. png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
  173516. return;
  173517. }
  173518. for (i = 0; i < info_ptr->num_palette; i++)
  173519. png_ptr->hist[i] = hist[i];
  173520. info_ptr->hist = png_ptr->hist;
  173521. info_ptr->valid |= PNG_INFO_hIST;
  173522. #ifdef PNG_FREE_ME_SUPPORTED
  173523. info_ptr->free_me |= PNG_FREE_HIST;
  173524. #else
  173525. png_ptr->flags |= PNG_FLAG_FREE_HIST;
  173526. #endif
  173527. }
  173528. #endif
  173529. void PNGAPI
  173530. png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
  173531. png_uint_32 width, png_uint_32 height, int bit_depth,
  173532. int color_type, int interlace_type, int compression_type,
  173533. int filter_type)
  173534. {
  173535. png_debug1(1, "in %s storage function\n", "IHDR");
  173536. if (png_ptr == NULL || info_ptr == NULL)
  173537. return;
  173538. if (width == 0 || height == 0)
  173539. png_error(png_ptr, "Image width or height is zero in IHDR");
  173540. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  173541. if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)
  173542. png_error(png_ptr, "image size exceeds user limits in IHDR");
  173543. #else
  173544. if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)
  173545. png_error(png_ptr, "image size exceeds user limits in IHDR");
  173546. #endif
  173547. if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)
  173548. png_error(png_ptr, "Invalid image size in IHDR");
  173549. if ( width > (PNG_UINT_32_MAX
  173550. >> 3) /* 8-byte RGBA pixels */
  173551. - 64 /* bigrowbuf hack */
  173552. - 1 /* filter byte */
  173553. - 7*8 /* rounding of width to multiple of 8 pixels */
  173554. - 8) /* extra max_pixel_depth pad */
  173555. png_warning(png_ptr, "Width is too large for libpng to process pixels");
  173556. if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
  173557. bit_depth != 8 && bit_depth != 16)
  173558. png_error(png_ptr, "Invalid bit depth in IHDR");
  173559. if (color_type < 0 || color_type == 1 ||
  173560. color_type == 5 || color_type > 6)
  173561. png_error(png_ptr, "Invalid color type in IHDR");
  173562. if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
  173563. ((color_type == PNG_COLOR_TYPE_RGB ||
  173564. color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
  173565. color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
  173566. png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
  173567. if (interlace_type >= PNG_INTERLACE_LAST)
  173568. png_error(png_ptr, "Unknown interlace method in IHDR");
  173569. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  173570. png_error(png_ptr, "Unknown compression method in IHDR");
  173571. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  173572. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
  173573. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  173574. if(filter_type != PNG_FILTER_TYPE_BASE)
  173575. {
  173576. if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  173577. (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
  173578. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  173579. (color_type == PNG_COLOR_TYPE_RGB ||
  173580. color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
  173581. png_error(png_ptr, "Unknown filter method in IHDR");
  173582. if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
  173583. png_warning(png_ptr, "Invalid filter method in IHDR");
  173584. }
  173585. #else
  173586. if(filter_type != PNG_FILTER_TYPE_BASE)
  173587. png_error(png_ptr, "Unknown filter method in IHDR");
  173588. #endif
  173589. info_ptr->width = width;
  173590. info_ptr->height = height;
  173591. info_ptr->bit_depth = (png_byte)bit_depth;
  173592. info_ptr->color_type =(png_byte) color_type;
  173593. info_ptr->compression_type = (png_byte)compression_type;
  173594. info_ptr->filter_type = (png_byte)filter_type;
  173595. info_ptr->interlace_type = (png_byte)interlace_type;
  173596. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173597. info_ptr->channels = 1;
  173598. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  173599. info_ptr->channels = 3;
  173600. else
  173601. info_ptr->channels = 1;
  173602. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  173603. info_ptr->channels++;
  173604. info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
  173605. if (width > (PNG_UINT_32_MAX
  173606. >> 3) /* 8-byte RGBA pixels */
  173607. - 64 /* bigrowbuf hack */
  173608. - 1 /* filter byte */
  173609. - 7*8 /* rounding of width to multiple of 8 pixels */
  173610. - 8) /* extra max_pixel_depth pad */
  173611. info_ptr->rowbytes = (png_size_t)0;
  173612. else
  173613. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,width);
  173614. }
  173615. #if defined(PNG_oFFs_SUPPORTED)
  173616. void PNGAPI
  173617. png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
  173618. png_int_32 offset_x, png_int_32 offset_y, int unit_type)
  173619. {
  173620. png_debug1(1, "in %s storage function\n", "oFFs");
  173621. if (png_ptr == NULL || info_ptr == NULL)
  173622. return;
  173623. info_ptr->x_offset = offset_x;
  173624. info_ptr->y_offset = offset_y;
  173625. info_ptr->offset_unit_type = (png_byte)unit_type;
  173626. info_ptr->valid |= PNG_INFO_oFFs;
  173627. }
  173628. #endif
  173629. #if defined(PNG_pCAL_SUPPORTED)
  173630. void PNGAPI
  173631. png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
  173632. png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
  173633. png_charp units, png_charpp params)
  173634. {
  173635. png_uint_32 length;
  173636. int i;
  173637. png_debug1(1, "in %s storage function\n", "pCAL");
  173638. if (png_ptr == NULL || info_ptr == NULL)
  173639. return;
  173640. length = png_strlen(purpose) + 1;
  173641. png_debug1(3, "allocating purpose for info (%lu bytes)\n", length);
  173642. info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
  173643. if (info_ptr->pcal_purpose == NULL)
  173644. {
  173645. png_warning(png_ptr, "Insufficient memory for pCAL purpose.");
  173646. return;
  173647. }
  173648. png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
  173649. png_debug(3, "storing X0, X1, type, and nparams in info\n");
  173650. info_ptr->pcal_X0 = X0;
  173651. info_ptr->pcal_X1 = X1;
  173652. info_ptr->pcal_type = (png_byte)type;
  173653. info_ptr->pcal_nparams = (png_byte)nparams;
  173654. length = png_strlen(units) + 1;
  173655. png_debug1(3, "allocating units for info (%lu bytes)\n", length);
  173656. info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
  173657. if (info_ptr->pcal_units == NULL)
  173658. {
  173659. png_warning(png_ptr, "Insufficient memory for pCAL units.");
  173660. return;
  173661. }
  173662. png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
  173663. info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
  173664. (png_uint_32)((nparams + 1) * png_sizeof(png_charp)));
  173665. if (info_ptr->pcal_params == NULL)
  173666. {
  173667. png_warning(png_ptr, "Insufficient memory for pCAL params.");
  173668. return;
  173669. }
  173670. info_ptr->pcal_params[nparams] = NULL;
  173671. for (i = 0; i < nparams; i++)
  173672. {
  173673. length = png_strlen(params[i]) + 1;
  173674. png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i, length);
  173675. info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
  173676. if (info_ptr->pcal_params[i] == NULL)
  173677. {
  173678. png_warning(png_ptr, "Insufficient memory for pCAL parameter.");
  173679. return;
  173680. }
  173681. png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
  173682. }
  173683. info_ptr->valid |= PNG_INFO_pCAL;
  173684. #ifdef PNG_FREE_ME_SUPPORTED
  173685. info_ptr->free_me |= PNG_FREE_PCAL;
  173686. #endif
  173687. }
  173688. #endif
  173689. #if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
  173690. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173691. void PNGAPI
  173692. png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
  173693. int unit, double width, double height)
  173694. {
  173695. png_debug1(1, "in %s storage function\n", "sCAL");
  173696. if (png_ptr == NULL || info_ptr == NULL)
  173697. return;
  173698. info_ptr->scal_unit = (png_byte)unit;
  173699. info_ptr->scal_pixel_width = width;
  173700. info_ptr->scal_pixel_height = height;
  173701. info_ptr->valid |= PNG_INFO_sCAL;
  173702. }
  173703. #else
  173704. #ifdef PNG_FIXED_POINT_SUPPORTED
  173705. void PNGAPI
  173706. png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  173707. int unit, png_charp swidth, png_charp sheight)
  173708. {
  173709. png_uint_32 length;
  173710. png_debug1(1, "in %s storage function\n", "sCAL");
  173711. if (png_ptr == NULL || info_ptr == NULL)
  173712. return;
  173713. info_ptr->scal_unit = (png_byte)unit;
  173714. length = png_strlen(swidth) + 1;
  173715. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  173716. info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
  173717. if (info_ptr->scal_s_width == NULL)
  173718. {
  173719. png_warning(png_ptr,
  173720. "Memory allocation failed while processing sCAL.");
  173721. }
  173722. png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length);
  173723. length = png_strlen(sheight) + 1;
  173724. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  173725. info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
  173726. if (info_ptr->scal_s_height == NULL)
  173727. {
  173728. png_free (png_ptr, info_ptr->scal_s_width);
  173729. png_warning(png_ptr,
  173730. "Memory allocation failed while processing sCAL.");
  173731. }
  173732. png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
  173733. info_ptr->valid |= PNG_INFO_sCAL;
  173734. #ifdef PNG_FREE_ME_SUPPORTED
  173735. info_ptr->free_me |= PNG_FREE_SCAL;
  173736. #endif
  173737. }
  173738. #endif
  173739. #endif
  173740. #endif
  173741. #if defined(PNG_pHYs_SUPPORTED)
  173742. void PNGAPI
  173743. png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
  173744. png_uint_32 res_x, png_uint_32 res_y, int unit_type)
  173745. {
  173746. png_debug1(1, "in %s storage function\n", "pHYs");
  173747. if (png_ptr == NULL || info_ptr == NULL)
  173748. return;
  173749. info_ptr->x_pixels_per_unit = res_x;
  173750. info_ptr->y_pixels_per_unit = res_y;
  173751. info_ptr->phys_unit_type = (png_byte)unit_type;
  173752. info_ptr->valid |= PNG_INFO_pHYs;
  173753. }
  173754. #endif
  173755. void PNGAPI
  173756. png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
  173757. png_colorp palette, int num_palette)
  173758. {
  173759. png_debug1(1, "in %s storage function\n", "PLTE");
  173760. if (png_ptr == NULL || info_ptr == NULL)
  173761. return;
  173762. if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
  173763. {
  173764. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173765. png_error(png_ptr, "Invalid palette length");
  173766. else
  173767. {
  173768. png_warning(png_ptr, "Invalid palette length");
  173769. return;
  173770. }
  173771. }
  173772. #ifdef PNG_FREE_ME_SUPPORTED
  173773. png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
  173774. #endif
  173775. png_ptr->palette = (png_colorp)png_malloc(png_ptr,
  173776. PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
  173777. png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
  173778. png_sizeof(png_color));
  173779. png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof (png_color));
  173780. info_ptr->palette = png_ptr->palette;
  173781. info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
  173782. #ifdef PNG_FREE_ME_SUPPORTED
  173783. info_ptr->free_me |= PNG_FREE_PLTE;
  173784. #else
  173785. png_ptr->flags |= PNG_FLAG_FREE_PLTE;
  173786. #endif
  173787. info_ptr->valid |= PNG_INFO_PLTE;
  173788. }
  173789. #if defined(PNG_sBIT_SUPPORTED)
  173790. void PNGAPI
  173791. png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
  173792. png_color_8p sig_bit)
  173793. {
  173794. png_debug1(1, "in %s storage function\n", "sBIT");
  173795. if (png_ptr == NULL || info_ptr == NULL)
  173796. return;
  173797. png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof (png_color_8));
  173798. info_ptr->valid |= PNG_INFO_sBIT;
  173799. }
  173800. #endif
  173801. #if defined(PNG_sRGB_SUPPORTED)
  173802. void PNGAPI
  173803. png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
  173804. {
  173805. png_debug1(1, "in %s storage function\n", "sRGB");
  173806. if (png_ptr == NULL || info_ptr == NULL)
  173807. return;
  173808. info_ptr->srgb_intent = (png_byte)intent;
  173809. info_ptr->valid |= PNG_INFO_sRGB;
  173810. }
  173811. void PNGAPI
  173812. png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
  173813. int intent)
  173814. {
  173815. #if defined(PNG_gAMA_SUPPORTED)
  173816. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173817. float file_gamma;
  173818. #endif
  173819. #ifdef PNG_FIXED_POINT_SUPPORTED
  173820. png_fixed_point int_file_gamma;
  173821. #endif
  173822. #endif
  173823. #if defined(PNG_cHRM_SUPPORTED)
  173824. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173825. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  173826. #endif
  173827. #ifdef PNG_FIXED_POINT_SUPPORTED
  173828. png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
  173829. int_green_y, int_blue_x, int_blue_y;
  173830. #endif
  173831. #endif
  173832. png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM");
  173833. if (png_ptr == NULL || info_ptr == NULL)
  173834. return;
  173835. png_set_sRGB(png_ptr, info_ptr, intent);
  173836. #if defined(PNG_gAMA_SUPPORTED)
  173837. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173838. file_gamma = (float).45455;
  173839. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  173840. #endif
  173841. #ifdef PNG_FIXED_POINT_SUPPORTED
  173842. int_file_gamma = 45455L;
  173843. png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
  173844. #endif
  173845. #endif
  173846. #if defined(PNG_cHRM_SUPPORTED)
  173847. #ifdef PNG_FIXED_POINT_SUPPORTED
  173848. int_white_x = 31270L;
  173849. int_white_y = 32900L;
  173850. int_red_x = 64000L;
  173851. int_red_y = 33000L;
  173852. int_green_x = 30000L;
  173853. int_green_y = 60000L;
  173854. int_blue_x = 15000L;
  173855. int_blue_y = 6000L;
  173856. png_set_cHRM_fixed(png_ptr, info_ptr,
  173857. int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, int_green_y,
  173858. int_blue_x, int_blue_y);
  173859. #endif
  173860. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173861. white_x = (float).3127;
  173862. white_y = (float).3290;
  173863. red_x = (float).64;
  173864. red_y = (float).33;
  173865. green_x = (float).30;
  173866. green_y = (float).60;
  173867. blue_x = (float).15;
  173868. blue_y = (float).06;
  173869. png_set_cHRM(png_ptr, info_ptr,
  173870. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  173871. #endif
  173872. #endif
  173873. }
  173874. #endif
  173875. #if defined(PNG_iCCP_SUPPORTED)
  173876. void PNGAPI
  173877. png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
  173878. png_charp name, int compression_type,
  173879. png_charp profile, png_uint_32 proflen)
  173880. {
  173881. png_charp new_iccp_name;
  173882. png_charp new_iccp_profile;
  173883. png_debug1(1, "in %s storage function\n", "iCCP");
  173884. if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
  173885. return;
  173886. new_iccp_name = (png_charp)png_malloc_warn(png_ptr, png_strlen(name)+1);
  173887. if (new_iccp_name == NULL)
  173888. {
  173889. png_warning(png_ptr, "Insufficient memory to process iCCP chunk.");
  173890. return;
  173891. }
  173892. png_strncpy(new_iccp_name, name, png_strlen(name)+1);
  173893. new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
  173894. if (new_iccp_profile == NULL)
  173895. {
  173896. png_free (png_ptr, new_iccp_name);
  173897. png_warning(png_ptr, "Insufficient memory to process iCCP profile.");
  173898. return;
  173899. }
  173900. png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
  173901. png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
  173902. info_ptr->iccp_proflen = proflen;
  173903. info_ptr->iccp_name = new_iccp_name;
  173904. info_ptr->iccp_profile = new_iccp_profile;
  173905. info_ptr->iccp_compression = (png_byte)compression_type;
  173906. #ifdef PNG_FREE_ME_SUPPORTED
  173907. info_ptr->free_me |= PNG_FREE_ICCP;
  173908. #endif
  173909. info_ptr->valid |= PNG_INFO_iCCP;
  173910. }
  173911. #endif
  173912. #if defined(PNG_TEXT_SUPPORTED)
  173913. void PNGAPI
  173914. png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  173915. int num_text)
  173916. {
  173917. int ret;
  173918. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
  173919. if (ret)
  173920. png_error(png_ptr, "Insufficient memory to store text");
  173921. }
  173922. int /* PRIVATE */
  173923. png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  173924. int num_text)
  173925. {
  173926. int i;
  173927. png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ?
  173928. "text" : (png_const_charp)png_ptr->chunk_name));
  173929. if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
  173930. return(0);
  173931. if (info_ptr->num_text + num_text > info_ptr->max_text)
  173932. {
  173933. if (info_ptr->text != NULL)
  173934. {
  173935. png_textp old_text;
  173936. int old_max;
  173937. old_max = info_ptr->max_text;
  173938. info_ptr->max_text = info_ptr->num_text + num_text + 8;
  173939. old_text = info_ptr->text;
  173940. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  173941. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  173942. if (info_ptr->text == NULL)
  173943. {
  173944. png_free(png_ptr, old_text);
  173945. return(1);
  173946. }
  173947. png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
  173948. png_sizeof(png_text)));
  173949. png_free(png_ptr, old_text);
  173950. }
  173951. else
  173952. {
  173953. info_ptr->max_text = num_text + 8;
  173954. info_ptr->num_text = 0;
  173955. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  173956. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  173957. if (info_ptr->text == NULL)
  173958. return(1);
  173959. #ifdef PNG_FREE_ME_SUPPORTED
  173960. info_ptr->free_me |= PNG_FREE_TEXT;
  173961. #endif
  173962. }
  173963. png_debug1(3, "allocated %d entries for info_ptr->text\n",
  173964. info_ptr->max_text);
  173965. }
  173966. for (i = 0; i < num_text; i++)
  173967. {
  173968. png_size_t text_length,key_len;
  173969. png_size_t lang_len,lang_key_len;
  173970. png_textp textp = &(info_ptr->text[info_ptr->num_text]);
  173971. if (text_ptr[i].key == NULL)
  173972. continue;
  173973. key_len = png_strlen(text_ptr[i].key);
  173974. if(text_ptr[i].compression <= 0)
  173975. {
  173976. lang_len = 0;
  173977. lang_key_len = 0;
  173978. }
  173979. else
  173980. #ifdef PNG_iTXt_SUPPORTED
  173981. {
  173982. if (text_ptr[i].lang != NULL)
  173983. lang_len = png_strlen(text_ptr[i].lang);
  173984. else
  173985. lang_len = 0;
  173986. if (text_ptr[i].lang_key != NULL)
  173987. lang_key_len = png_strlen(text_ptr[i].lang_key);
  173988. else
  173989. lang_key_len = 0;
  173990. }
  173991. #else
  173992. {
  173993. png_warning(png_ptr, "iTXt chunk not supported.");
  173994. continue;
  173995. }
  173996. #endif
  173997. if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
  173998. {
  173999. text_length = 0;
  174000. #ifdef PNG_iTXt_SUPPORTED
  174001. if(text_ptr[i].compression > 0)
  174002. textp->compression = PNG_ITXT_COMPRESSION_NONE;
  174003. else
  174004. #endif
  174005. textp->compression = PNG_TEXT_COMPRESSION_NONE;
  174006. }
  174007. else
  174008. {
  174009. text_length = png_strlen(text_ptr[i].text);
  174010. textp->compression = text_ptr[i].compression;
  174011. }
  174012. textp->key = (png_charp)png_malloc_warn(png_ptr,
  174013. (png_uint_32)(key_len + text_length + lang_len + lang_key_len + 4));
  174014. if (textp->key == NULL)
  174015. return(1);
  174016. png_debug2(2, "Allocated %lu bytes at %x in png_set_text\n",
  174017. (png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4),
  174018. (int)textp->key);
  174019. png_memcpy(textp->key, text_ptr[i].key,
  174020. (png_size_t)(key_len));
  174021. *(textp->key+key_len) = '\0';
  174022. #ifdef PNG_iTXt_SUPPORTED
  174023. if (text_ptr[i].compression > 0)
  174024. {
  174025. textp->lang=textp->key + key_len + 1;
  174026. png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
  174027. *(textp->lang+lang_len) = '\0';
  174028. textp->lang_key=textp->lang + lang_len + 1;
  174029. png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
  174030. *(textp->lang_key+lang_key_len) = '\0';
  174031. textp->text=textp->lang_key + lang_key_len + 1;
  174032. }
  174033. else
  174034. #endif
  174035. {
  174036. #ifdef PNG_iTXt_SUPPORTED
  174037. textp->lang=NULL;
  174038. textp->lang_key=NULL;
  174039. #endif
  174040. textp->text=textp->key + key_len + 1;
  174041. }
  174042. if(text_length)
  174043. png_memcpy(textp->text, text_ptr[i].text,
  174044. (png_size_t)(text_length));
  174045. *(textp->text+text_length) = '\0';
  174046. #ifdef PNG_iTXt_SUPPORTED
  174047. if(textp->compression > 0)
  174048. {
  174049. textp->text_length = 0;
  174050. textp->itxt_length = text_length;
  174051. }
  174052. else
  174053. #endif
  174054. {
  174055. textp->text_length = text_length;
  174056. #ifdef PNG_iTXt_SUPPORTED
  174057. textp->itxt_length = 0;
  174058. #endif
  174059. }
  174060. info_ptr->num_text++;
  174061. png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
  174062. }
  174063. return(0);
  174064. }
  174065. #endif
  174066. #if defined(PNG_tIME_SUPPORTED)
  174067. void PNGAPI
  174068. png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
  174069. {
  174070. png_debug1(1, "in %s storage function\n", "tIME");
  174071. if (png_ptr == NULL || info_ptr == NULL ||
  174072. (png_ptr->mode & PNG_WROTE_tIME))
  174073. return;
  174074. png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof (png_time));
  174075. info_ptr->valid |= PNG_INFO_tIME;
  174076. }
  174077. #endif
  174078. #if defined(PNG_tRNS_SUPPORTED)
  174079. void PNGAPI
  174080. png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
  174081. png_bytep trans, int num_trans, png_color_16p trans_values)
  174082. {
  174083. png_debug1(1, "in %s storage function\n", "tRNS");
  174084. if (png_ptr == NULL || info_ptr == NULL)
  174085. return;
  174086. if (trans != NULL)
  174087. {
  174088. #ifdef PNG_FREE_ME_SUPPORTED
  174089. png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
  174090. #endif
  174091. png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
  174092. (png_uint_32)PNG_MAX_PALETTE_LENGTH);
  174093. if (num_trans <= PNG_MAX_PALETTE_LENGTH)
  174094. png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
  174095. #ifdef PNG_FREE_ME_SUPPORTED
  174096. info_ptr->free_me |= PNG_FREE_TRNS;
  174097. #else
  174098. png_ptr->flags |= PNG_FLAG_FREE_TRNS;
  174099. #endif
  174100. }
  174101. if (trans_values != NULL)
  174102. {
  174103. png_memcpy(&(info_ptr->trans_values), trans_values,
  174104. png_sizeof(png_color_16));
  174105. if (num_trans == 0)
  174106. num_trans = 1;
  174107. }
  174108. info_ptr->num_trans = (png_uint_16)num_trans;
  174109. info_ptr->valid |= PNG_INFO_tRNS;
  174110. }
  174111. #endif
  174112. #if defined(PNG_sPLT_SUPPORTED)
  174113. void PNGAPI
  174114. png_set_sPLT(png_structp png_ptr,
  174115. png_infop info_ptr, png_sPLT_tp entries, int nentries)
  174116. {
  174117. png_sPLT_tp np;
  174118. int i;
  174119. if (png_ptr == NULL || info_ptr == NULL)
  174120. return;
  174121. np = (png_sPLT_tp)png_malloc_warn(png_ptr,
  174122. (info_ptr->splt_palettes_num + nentries) * png_sizeof(png_sPLT_t));
  174123. if (np == NULL)
  174124. {
  174125. png_warning(png_ptr, "No memory for sPLT palettes.");
  174126. return;
  174127. }
  174128. png_memcpy(np, info_ptr->splt_palettes,
  174129. info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
  174130. png_free(png_ptr, info_ptr->splt_palettes);
  174131. info_ptr->splt_palettes=NULL;
  174132. for (i = 0; i < nentries; i++)
  174133. {
  174134. png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
  174135. png_sPLT_tp from = entries + i;
  174136. to->name = (png_charp)png_malloc_warn(png_ptr,
  174137. png_strlen(from->name) + 1);
  174138. if (to->name == NULL)
  174139. {
  174140. png_warning(png_ptr,
  174141. "Out of memory while processing sPLT chunk");
  174142. }
  174143. png_strncpy(to->name, from->name, png_strlen(from->name)+1);
  174144. to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
  174145. from->nentries * png_sizeof(png_sPLT_entry));
  174146. png_memcpy(to->entries, from->entries,
  174147. from->nentries * png_sizeof(png_sPLT_entry));
  174148. if (to->entries == NULL)
  174149. {
  174150. png_warning(png_ptr,
  174151. "Out of memory while processing sPLT chunk");
  174152. png_free(png_ptr,to->name);
  174153. to->name = NULL;
  174154. }
  174155. to->nentries = from->nentries;
  174156. to->depth = from->depth;
  174157. }
  174158. info_ptr->splt_palettes = np;
  174159. info_ptr->splt_palettes_num += nentries;
  174160. info_ptr->valid |= PNG_INFO_sPLT;
  174161. #ifdef PNG_FREE_ME_SUPPORTED
  174162. info_ptr->free_me |= PNG_FREE_SPLT;
  174163. #endif
  174164. }
  174165. #endif /* PNG_sPLT_SUPPORTED */
  174166. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174167. void PNGAPI
  174168. png_set_unknown_chunks(png_structp png_ptr,
  174169. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
  174170. {
  174171. png_unknown_chunkp np;
  174172. int i;
  174173. if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
  174174. return;
  174175. np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
  174176. (info_ptr->unknown_chunks_num + num_unknowns) *
  174177. png_sizeof(png_unknown_chunk));
  174178. if (np == NULL)
  174179. {
  174180. png_warning(png_ptr,
  174181. "Out of memory while processing unknown chunk.");
  174182. return;
  174183. }
  174184. png_memcpy(np, info_ptr->unknown_chunks,
  174185. info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
  174186. png_free(png_ptr, info_ptr->unknown_chunks);
  174187. info_ptr->unknown_chunks=NULL;
  174188. for (i = 0; i < num_unknowns; i++)
  174189. {
  174190. png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
  174191. png_unknown_chunkp from = unknowns + i;
  174192. png_strncpy((png_charp)to->name, (png_charp)from->name, 5);
  174193. to->data = (png_bytep)png_malloc_warn(png_ptr, from->size);
  174194. if (to->data == NULL)
  174195. {
  174196. png_warning(png_ptr,
  174197. "Out of memory while processing unknown chunk.");
  174198. }
  174199. else
  174200. {
  174201. png_memcpy(to->data, from->data, from->size);
  174202. to->size = from->size;
  174203. to->location = (png_byte)(png_ptr->mode & 0xff);
  174204. }
  174205. }
  174206. info_ptr->unknown_chunks = np;
  174207. info_ptr->unknown_chunks_num += num_unknowns;
  174208. #ifdef PNG_FREE_ME_SUPPORTED
  174209. info_ptr->free_me |= PNG_FREE_UNKN;
  174210. #endif
  174211. }
  174212. void PNGAPI
  174213. png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
  174214. int chunk, int location)
  174215. {
  174216. if(png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
  174217. (int)info_ptr->unknown_chunks_num)
  174218. info_ptr->unknown_chunks[chunk].location = (png_byte)location;
  174219. }
  174220. #endif
  174221. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  174222. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  174223. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  174224. void PNGAPI
  174225. png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
  174226. {
  174227. png_debug(1, "in png_permit_empty_plte, DEPRECATED.\n");
  174228. if (png_ptr == NULL)
  174229. return;
  174230. png_ptr->mng_features_permitted = (png_byte)
  174231. ((png_ptr->mng_features_permitted & (~(PNG_FLAG_MNG_EMPTY_PLTE))) |
  174232. ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE)));
  174233. }
  174234. #endif
  174235. #endif
  174236. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  174237. png_uint_32 PNGAPI
  174238. png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
  174239. {
  174240. png_debug(1, "in png_permit_mng_features\n");
  174241. if (png_ptr == NULL)
  174242. return (png_uint_32)0;
  174243. png_ptr->mng_features_permitted =
  174244. (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
  174245. return (png_uint_32)png_ptr->mng_features_permitted;
  174246. }
  174247. #endif
  174248. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174249. void PNGAPI
  174250. png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
  174251. chunk_list, int num_chunks)
  174252. {
  174253. png_bytep new_list, p;
  174254. int i, old_num_chunks;
  174255. if (png_ptr == NULL)
  174256. return;
  174257. if (num_chunks == 0)
  174258. {
  174259. if(keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
  174260. png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174261. else
  174262. png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174263. if(keep == PNG_HANDLE_CHUNK_ALWAYS)
  174264. png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174265. else
  174266. png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174267. return;
  174268. }
  174269. if (chunk_list == NULL)
  174270. return;
  174271. old_num_chunks=png_ptr->num_chunk_list;
  174272. new_list=(png_bytep)png_malloc(png_ptr,
  174273. (png_uint_32)(5*(num_chunks+old_num_chunks)));
  174274. if(png_ptr->chunk_list != NULL)
  174275. {
  174276. png_memcpy(new_list, png_ptr->chunk_list,
  174277. (png_size_t)(5*old_num_chunks));
  174278. png_free(png_ptr, png_ptr->chunk_list);
  174279. png_ptr->chunk_list=NULL;
  174280. }
  174281. png_memcpy(new_list+5*old_num_chunks, chunk_list,
  174282. (png_size_t)(5*num_chunks));
  174283. for (p=new_list+5*old_num_chunks+4, i=0; i<num_chunks; i++, p+=5)
  174284. *p=(png_byte)keep;
  174285. png_ptr->num_chunk_list=old_num_chunks+num_chunks;
  174286. png_ptr->chunk_list=new_list;
  174287. #ifdef PNG_FREE_ME_SUPPORTED
  174288. png_ptr->free_me |= PNG_FREE_LIST;
  174289. #endif
  174290. }
  174291. #endif
  174292. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  174293. void PNGAPI
  174294. png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
  174295. png_user_chunk_ptr read_user_chunk_fn)
  174296. {
  174297. png_debug(1, "in png_set_read_user_chunk_fn\n");
  174298. if (png_ptr == NULL)
  174299. return;
  174300. png_ptr->read_user_chunk_fn = read_user_chunk_fn;
  174301. png_ptr->user_chunk_ptr = user_chunk_ptr;
  174302. }
  174303. #endif
  174304. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  174305. void PNGAPI
  174306. png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
  174307. {
  174308. png_debug1(1, "in %s storage function\n", "rows");
  174309. if (png_ptr == NULL || info_ptr == NULL)
  174310. return;
  174311. if(info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
  174312. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  174313. info_ptr->row_pointers = row_pointers;
  174314. if(row_pointers)
  174315. info_ptr->valid |= PNG_INFO_IDAT;
  174316. }
  174317. #endif
  174318. #ifdef PNG_WRITE_SUPPORTED
  174319. void PNGAPI
  174320. png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
  174321. {
  174322. if (png_ptr == NULL)
  174323. return;
  174324. if(png_ptr->zbuf)
  174325. png_free(png_ptr, png_ptr->zbuf);
  174326. png_ptr->zbuf_size = (png_size_t)size;
  174327. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
  174328. png_ptr->zstream.next_out = png_ptr->zbuf;
  174329. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  174330. }
  174331. #endif
  174332. void PNGAPI
  174333. png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
  174334. {
  174335. if (png_ptr && info_ptr)
  174336. info_ptr->valid &= ~(mask);
  174337. }
  174338. #ifndef PNG_1_0_X
  174339. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  174340. void PNGAPI
  174341. png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
  174342. {
  174343. if (png_ptr != NULL)
  174344. png_ptr->asm_flags = 0;
  174345. }
  174346. void PNGAPI
  174347. png_set_mmx_thresholds (png_structp png_ptr,
  174348. png_byte mmx_bitdepth_threshold,
  174349. png_uint_32 mmx_rowbytes_threshold)
  174350. {
  174351. if (png_ptr == NULL)
  174352. return;
  174353. }
  174354. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  174355. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  174356. void PNGAPI
  174357. png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
  174358. png_uint_32 user_height_max)
  174359. {
  174360. if(png_ptr == NULL) return;
  174361. png_ptr->user_width_max = user_width_max;
  174362. png_ptr->user_height_max = user_height_max;
  174363. }
  174364. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  174365. #endif /* ?PNG_1_0_X */
  174366. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  174367. /*** End of inlined file: pngset.c ***/
  174368. /*** Start of inlined file: pngtrans.c ***/
  174369. #define PNG_INTERNAL
  174370. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  174371. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  174372. void PNGAPI
  174373. png_set_bgr(png_structp png_ptr)
  174374. {
  174375. png_debug(1, "in png_set_bgr\n");
  174376. if(png_ptr == NULL) return;
  174377. png_ptr->transformations |= PNG_BGR;
  174378. }
  174379. #endif
  174380. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174381. void PNGAPI
  174382. png_set_swap(png_structp png_ptr)
  174383. {
  174384. png_debug(1, "in png_set_swap\n");
  174385. if(png_ptr == NULL) return;
  174386. if (png_ptr->bit_depth == 16)
  174387. png_ptr->transformations |= PNG_SWAP_BYTES;
  174388. }
  174389. #endif
  174390. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  174391. void PNGAPI
  174392. png_set_packing(png_structp png_ptr)
  174393. {
  174394. png_debug(1, "in png_set_packing\n");
  174395. if(png_ptr == NULL) return;
  174396. if (png_ptr->bit_depth < 8)
  174397. {
  174398. png_ptr->transformations |= PNG_PACK;
  174399. png_ptr->usr_bit_depth = 8;
  174400. }
  174401. }
  174402. #endif
  174403. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174404. void PNGAPI
  174405. png_set_packswap(png_structp png_ptr)
  174406. {
  174407. png_debug(1, "in png_set_packswap\n");
  174408. if(png_ptr == NULL) return;
  174409. if (png_ptr->bit_depth < 8)
  174410. png_ptr->transformations |= PNG_PACKSWAP;
  174411. }
  174412. #endif
  174413. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  174414. void PNGAPI
  174415. png_set_shift(png_structp png_ptr, png_color_8p true_bits)
  174416. {
  174417. png_debug(1, "in png_set_shift\n");
  174418. if(png_ptr == NULL) return;
  174419. png_ptr->transformations |= PNG_SHIFT;
  174420. png_ptr->shift = *true_bits;
  174421. }
  174422. #endif
  174423. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  174424. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  174425. int PNGAPI
  174426. png_set_interlace_handling(png_structp png_ptr)
  174427. {
  174428. png_debug(1, "in png_set_interlace handling\n");
  174429. if (png_ptr && png_ptr->interlaced)
  174430. {
  174431. png_ptr->transformations |= PNG_INTERLACE;
  174432. return (7);
  174433. }
  174434. return (1);
  174435. }
  174436. #endif
  174437. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  174438. void PNGAPI
  174439. png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174440. {
  174441. png_debug(1, "in png_set_filler\n");
  174442. if(png_ptr == NULL) return;
  174443. png_ptr->transformations |= PNG_FILLER;
  174444. png_ptr->filler = (png_byte)filler;
  174445. if (filler_loc == PNG_FILLER_AFTER)
  174446. png_ptr->flags |= PNG_FLAG_FILLER_AFTER;
  174447. else
  174448. png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER;
  174449. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  174450. {
  174451. png_ptr->usr_channels = 4;
  174452. }
  174453. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8)
  174454. {
  174455. png_ptr->usr_channels = 2;
  174456. }
  174457. }
  174458. #if !defined(PNG_1_0_X)
  174459. void PNGAPI
  174460. png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174461. {
  174462. png_debug(1, "in png_set_add_alpha\n");
  174463. if(png_ptr == NULL) return;
  174464. png_set_filler(png_ptr, filler, filler_loc);
  174465. png_ptr->transformations |= PNG_ADD_ALPHA;
  174466. }
  174467. #endif
  174468. #endif
  174469. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  174470. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  174471. void PNGAPI
  174472. png_set_swap_alpha(png_structp png_ptr)
  174473. {
  174474. png_debug(1, "in png_set_swap_alpha\n");
  174475. if(png_ptr == NULL) return;
  174476. png_ptr->transformations |= PNG_SWAP_ALPHA;
  174477. }
  174478. #endif
  174479. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  174480. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  174481. void PNGAPI
  174482. png_set_invert_alpha(png_structp png_ptr)
  174483. {
  174484. png_debug(1, "in png_set_invert_alpha\n");
  174485. if(png_ptr == NULL) return;
  174486. png_ptr->transformations |= PNG_INVERT_ALPHA;
  174487. }
  174488. #endif
  174489. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  174490. void PNGAPI
  174491. png_set_invert_mono(png_structp png_ptr)
  174492. {
  174493. png_debug(1, "in png_set_invert_mono\n");
  174494. if(png_ptr == NULL) return;
  174495. png_ptr->transformations |= PNG_INVERT_MONO;
  174496. }
  174497. void /* PRIVATE */
  174498. png_do_invert(png_row_infop row_info, png_bytep row)
  174499. {
  174500. png_debug(1, "in png_do_invert\n");
  174501. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174502. if (row == NULL || row_info == NULL)
  174503. return;
  174504. #endif
  174505. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  174506. {
  174507. png_bytep rp = row;
  174508. png_uint_32 i;
  174509. png_uint_32 istop = row_info->rowbytes;
  174510. for (i = 0; i < istop; i++)
  174511. {
  174512. *rp = (png_byte)(~(*rp));
  174513. rp++;
  174514. }
  174515. }
  174516. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174517. row_info->bit_depth == 8)
  174518. {
  174519. png_bytep rp = row;
  174520. png_uint_32 i;
  174521. png_uint_32 istop = row_info->rowbytes;
  174522. for (i = 0; i < istop; i+=2)
  174523. {
  174524. *rp = (png_byte)(~(*rp));
  174525. rp+=2;
  174526. }
  174527. }
  174528. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174529. row_info->bit_depth == 16)
  174530. {
  174531. png_bytep rp = row;
  174532. png_uint_32 i;
  174533. png_uint_32 istop = row_info->rowbytes;
  174534. for (i = 0; i < istop; i+=4)
  174535. {
  174536. *rp = (png_byte)(~(*rp));
  174537. *(rp+1) = (png_byte)(~(*(rp+1)));
  174538. rp+=4;
  174539. }
  174540. }
  174541. }
  174542. #endif
  174543. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174544. void /* PRIVATE */
  174545. png_do_swap(png_row_infop row_info, png_bytep row)
  174546. {
  174547. png_debug(1, "in png_do_swap\n");
  174548. if (
  174549. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174550. row != NULL && row_info != NULL &&
  174551. #endif
  174552. row_info->bit_depth == 16)
  174553. {
  174554. png_bytep rp = row;
  174555. png_uint_32 i;
  174556. png_uint_32 istop= row_info->width * row_info->channels;
  174557. for (i = 0; i < istop; i++, rp += 2)
  174558. {
  174559. png_byte t = *rp;
  174560. *rp = *(rp + 1);
  174561. *(rp + 1) = t;
  174562. }
  174563. }
  174564. }
  174565. #endif
  174566. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174567. static PNG_CONST png_byte onebppswaptable[256] = {
  174568. 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
  174569. 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
  174570. 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
  174571. 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
  174572. 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
  174573. 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
  174574. 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
  174575. 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
  174576. 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
  174577. 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
  174578. 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
  174579. 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
  174580. 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
  174581. 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
  174582. 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
  174583. 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
  174584. 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
  174585. 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
  174586. 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
  174587. 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
  174588. 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
  174589. 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
  174590. 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
  174591. 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
  174592. 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
  174593. 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
  174594. 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
  174595. 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
  174596. 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
  174597. 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
  174598. 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
  174599. 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
  174600. };
  174601. static PNG_CONST png_byte twobppswaptable[256] = {
  174602. 0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,
  174603. 0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,
  174604. 0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,
  174605. 0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4,
  174606. 0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8,
  174607. 0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8,
  174608. 0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC,
  174609. 0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC,
  174610. 0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1,
  174611. 0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1,
  174612. 0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5,
  174613. 0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5,
  174614. 0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9,
  174615. 0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9,
  174616. 0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD,
  174617. 0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD,
  174618. 0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2,
  174619. 0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2,
  174620. 0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6,
  174621. 0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6,
  174622. 0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA,
  174623. 0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA,
  174624. 0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE,
  174625. 0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE,
  174626. 0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3,
  174627. 0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3,
  174628. 0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7,
  174629. 0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7,
  174630. 0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB,
  174631. 0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB,
  174632. 0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF,
  174633. 0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
  174634. };
  174635. static PNG_CONST png_byte fourbppswaptable[256] = {
  174636. 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
  174637. 0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,
  174638. 0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,
  174639. 0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1,
  174640. 0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,
  174641. 0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2,
  174642. 0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73,
  174643. 0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3,
  174644. 0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74,
  174645. 0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4,
  174646. 0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75,
  174647. 0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5,
  174648. 0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76,
  174649. 0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6,
  174650. 0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77,
  174651. 0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7,
  174652. 0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,
  174653. 0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8,
  174654. 0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79,
  174655. 0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9,
  174656. 0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A,
  174657. 0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA,
  174658. 0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B,
  174659. 0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB,
  174660. 0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C,
  174661. 0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC,
  174662. 0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D,
  174663. 0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD,
  174664. 0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E,
  174665. 0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE,
  174666. 0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F,
  174667. 0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF
  174668. };
  174669. void /* PRIVATE */
  174670. png_do_packswap(png_row_infop row_info, png_bytep row)
  174671. {
  174672. png_debug(1, "in png_do_packswap\n");
  174673. if (
  174674. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174675. row != NULL && row_info != NULL &&
  174676. #endif
  174677. row_info->bit_depth < 8)
  174678. {
  174679. png_bytep rp, end, table;
  174680. end = row + row_info->rowbytes;
  174681. if (row_info->bit_depth == 1)
  174682. table = (png_bytep)onebppswaptable;
  174683. else if (row_info->bit_depth == 2)
  174684. table = (png_bytep)twobppswaptable;
  174685. else if (row_info->bit_depth == 4)
  174686. table = (png_bytep)fourbppswaptable;
  174687. else
  174688. return;
  174689. for (rp = row; rp < end; rp++)
  174690. *rp = table[*rp];
  174691. }
  174692. }
  174693. #endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */
  174694. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  174695. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  174696. void /* PRIVATE */
  174697. png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
  174698. {
  174699. png_debug(1, "in png_do_strip_filler\n");
  174700. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174701. if (row != NULL && row_info != NULL)
  174702. #endif
  174703. {
  174704. png_bytep sp=row;
  174705. png_bytep dp=row;
  174706. png_uint_32 row_width=row_info->width;
  174707. png_uint_32 i;
  174708. if ((row_info->color_type == PNG_COLOR_TYPE_RGB ||
  174709. (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  174710. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  174711. row_info->channels == 4)
  174712. {
  174713. if (row_info->bit_depth == 8)
  174714. {
  174715. if (flags & PNG_FLAG_FILLER_AFTER)
  174716. {
  174717. dp+=3; sp+=4;
  174718. for (i = 1; i < row_width; i++)
  174719. {
  174720. *dp++ = *sp++;
  174721. *dp++ = *sp++;
  174722. *dp++ = *sp++;
  174723. sp++;
  174724. }
  174725. }
  174726. else
  174727. {
  174728. for (i = 0; i < row_width; i++)
  174729. {
  174730. sp++;
  174731. *dp++ = *sp++;
  174732. *dp++ = *sp++;
  174733. *dp++ = *sp++;
  174734. }
  174735. }
  174736. row_info->pixel_depth = 24;
  174737. row_info->rowbytes = row_width * 3;
  174738. }
  174739. else /* if (row_info->bit_depth == 16) */
  174740. {
  174741. if (flags & PNG_FLAG_FILLER_AFTER)
  174742. {
  174743. sp += 8; dp += 6;
  174744. for (i = 1; i < row_width; i++)
  174745. {
  174746. *dp++ = *sp++;
  174747. *dp++ = *sp++;
  174748. *dp++ = *sp++;
  174749. *dp++ = *sp++;
  174750. *dp++ = *sp++;
  174751. *dp++ = *sp++;
  174752. sp += 2;
  174753. }
  174754. }
  174755. else
  174756. {
  174757. for (i = 0; i < row_width; i++)
  174758. {
  174759. sp+=2;
  174760. *dp++ = *sp++;
  174761. *dp++ = *sp++;
  174762. *dp++ = *sp++;
  174763. *dp++ = *sp++;
  174764. *dp++ = *sp++;
  174765. *dp++ = *sp++;
  174766. }
  174767. }
  174768. row_info->pixel_depth = 48;
  174769. row_info->rowbytes = row_width * 6;
  174770. }
  174771. row_info->channels = 3;
  174772. }
  174773. else if ((row_info->color_type == PNG_COLOR_TYPE_GRAY ||
  174774. (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174775. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  174776. row_info->channels == 2)
  174777. {
  174778. if (row_info->bit_depth == 8)
  174779. {
  174780. if (flags & PNG_FLAG_FILLER_AFTER)
  174781. {
  174782. for (i = 0; i < row_width; i++)
  174783. {
  174784. *dp++ = *sp++;
  174785. sp++;
  174786. }
  174787. }
  174788. else
  174789. {
  174790. for (i = 0; i < row_width; i++)
  174791. {
  174792. sp++;
  174793. *dp++ = *sp++;
  174794. }
  174795. }
  174796. row_info->pixel_depth = 8;
  174797. row_info->rowbytes = row_width;
  174798. }
  174799. else /* if (row_info->bit_depth == 16) */
  174800. {
  174801. if (flags & PNG_FLAG_FILLER_AFTER)
  174802. {
  174803. sp += 4; dp += 2;
  174804. for (i = 1; i < row_width; i++)
  174805. {
  174806. *dp++ = *sp++;
  174807. *dp++ = *sp++;
  174808. sp += 2;
  174809. }
  174810. }
  174811. else
  174812. {
  174813. for (i = 0; i < row_width; i++)
  174814. {
  174815. sp += 2;
  174816. *dp++ = *sp++;
  174817. *dp++ = *sp++;
  174818. }
  174819. }
  174820. row_info->pixel_depth = 16;
  174821. row_info->rowbytes = row_width * 2;
  174822. }
  174823. row_info->channels = 1;
  174824. }
  174825. if (flags & PNG_FLAG_STRIP_ALPHA)
  174826. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  174827. }
  174828. }
  174829. #endif
  174830. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  174831. void /* PRIVATE */
  174832. png_do_bgr(png_row_infop row_info, png_bytep row)
  174833. {
  174834. png_debug(1, "in png_do_bgr\n");
  174835. if (
  174836. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174837. row != NULL && row_info != NULL &&
  174838. #endif
  174839. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  174840. {
  174841. png_uint_32 row_width = row_info->width;
  174842. if (row_info->bit_depth == 8)
  174843. {
  174844. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  174845. {
  174846. png_bytep rp;
  174847. png_uint_32 i;
  174848. for (i = 0, rp = row; i < row_width; i++, rp += 3)
  174849. {
  174850. png_byte save = *rp;
  174851. *rp = *(rp + 2);
  174852. *(rp + 2) = save;
  174853. }
  174854. }
  174855. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  174856. {
  174857. png_bytep rp;
  174858. png_uint_32 i;
  174859. for (i = 0, rp = row; i < row_width; i++, rp += 4)
  174860. {
  174861. png_byte save = *rp;
  174862. *rp = *(rp + 2);
  174863. *(rp + 2) = save;
  174864. }
  174865. }
  174866. }
  174867. else if (row_info->bit_depth == 16)
  174868. {
  174869. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  174870. {
  174871. png_bytep rp;
  174872. png_uint_32 i;
  174873. for (i = 0, rp = row; i < row_width; i++, rp += 6)
  174874. {
  174875. png_byte save = *rp;
  174876. *rp = *(rp + 4);
  174877. *(rp + 4) = save;
  174878. save = *(rp + 1);
  174879. *(rp + 1) = *(rp + 5);
  174880. *(rp + 5) = save;
  174881. }
  174882. }
  174883. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  174884. {
  174885. png_bytep rp;
  174886. png_uint_32 i;
  174887. for (i = 0, rp = row; i < row_width; i++, rp += 8)
  174888. {
  174889. png_byte save = *rp;
  174890. *rp = *(rp + 4);
  174891. *(rp + 4) = save;
  174892. save = *(rp + 1);
  174893. *(rp + 1) = *(rp + 5);
  174894. *(rp + 5) = save;
  174895. }
  174896. }
  174897. }
  174898. }
  174899. }
  174900. #endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */
  174901. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  174902. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  174903. defined(PNG_LEGACY_SUPPORTED)
  174904. void PNGAPI
  174905. png_set_user_transform_info(png_structp png_ptr, png_voidp
  174906. user_transform_ptr, int user_transform_depth, int user_transform_channels)
  174907. {
  174908. png_debug(1, "in png_set_user_transform_info\n");
  174909. if(png_ptr == NULL) return;
  174910. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  174911. png_ptr->user_transform_ptr = user_transform_ptr;
  174912. png_ptr->user_transform_depth = (png_byte)user_transform_depth;
  174913. png_ptr->user_transform_channels = (png_byte)user_transform_channels;
  174914. #else
  174915. if(user_transform_ptr || user_transform_depth || user_transform_channels)
  174916. png_warning(png_ptr,
  174917. "This version of libpng does not support user transform info");
  174918. #endif
  174919. }
  174920. #endif
  174921. png_voidp PNGAPI
  174922. png_get_user_transform_ptr(png_structp png_ptr)
  174923. {
  174924. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  174925. if (png_ptr == NULL) return (NULL);
  174926. return ((png_voidp)png_ptr->user_transform_ptr);
  174927. #else
  174928. return (NULL);
  174929. #endif
  174930. }
  174931. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  174932. /*** End of inlined file: pngtrans.c ***/
  174933. /*** Start of inlined file: pngwio.c ***/
  174934. #define PNG_INTERNAL
  174935. #ifdef PNG_WRITE_SUPPORTED
  174936. void /* PRIVATE */
  174937. png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  174938. {
  174939. if (png_ptr->write_data_fn != NULL )
  174940. (*(png_ptr->write_data_fn))(png_ptr, data, length);
  174941. else
  174942. png_error(png_ptr, "Call to NULL write function");
  174943. }
  174944. #if !defined(PNG_NO_STDIO)
  174945. #ifndef USE_FAR_KEYWORD
  174946. void PNGAPI
  174947. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  174948. {
  174949. png_uint_32 check;
  174950. if(png_ptr == NULL) return;
  174951. #if defined(_WIN32_WCE)
  174952. if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  174953. check = 0;
  174954. #else
  174955. check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
  174956. #endif
  174957. if (check != length)
  174958. png_error(png_ptr, "Write Error");
  174959. }
  174960. #else
  174961. #define NEAR_BUF_SIZE 1024
  174962. #define MIN(a,b) (a <= b ? a : b)
  174963. void PNGAPI
  174964. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  174965. {
  174966. png_uint_32 check;
  174967. png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
  174968. png_FILE_p io_ptr;
  174969. if(png_ptr == NULL) return;
  174970. near_data = (png_byte *)CVT_PTR_NOCHECK(data);
  174971. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  174972. if ((png_bytep)near_data == data)
  174973. {
  174974. #if defined(_WIN32_WCE)
  174975. if ( !WriteFile(io_ptr, near_data, length, &check, NULL) )
  174976. check = 0;
  174977. #else
  174978. check = fwrite(near_data, 1, length, io_ptr);
  174979. #endif
  174980. }
  174981. else
  174982. {
  174983. png_byte buf[NEAR_BUF_SIZE];
  174984. png_size_t written, remaining, err;
  174985. check = 0;
  174986. remaining = length;
  174987. do
  174988. {
  174989. written = MIN(NEAR_BUF_SIZE, remaining);
  174990. png_memcpy(buf, data, written); /* copy far buffer to near buffer */
  174991. #if defined(_WIN32_WCE)
  174992. if ( !WriteFile(io_ptr, buf, written, &err, NULL) )
  174993. err = 0;
  174994. #else
  174995. err = fwrite(buf, 1, written, io_ptr);
  174996. #endif
  174997. if (err != written)
  174998. break;
  174999. else
  175000. check += err;
  175001. data += written;
  175002. remaining -= written;
  175003. }
  175004. while (remaining != 0);
  175005. }
  175006. if (check != length)
  175007. png_error(png_ptr, "Write Error");
  175008. }
  175009. #endif
  175010. #endif
  175011. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175012. void /* PRIVATE */
  175013. png_flush(png_structp png_ptr)
  175014. {
  175015. if (png_ptr->output_flush_fn != NULL)
  175016. (*(png_ptr->output_flush_fn))(png_ptr);
  175017. }
  175018. #if !defined(PNG_NO_STDIO)
  175019. void PNGAPI
  175020. png_default_flush(png_structp png_ptr)
  175021. {
  175022. #if !defined(_WIN32_WCE)
  175023. png_FILE_p io_ptr;
  175024. #endif
  175025. if(png_ptr == NULL) return;
  175026. #if !defined(_WIN32_WCE)
  175027. io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
  175028. if (io_ptr != NULL)
  175029. fflush(io_ptr);
  175030. #endif
  175031. }
  175032. #endif
  175033. #endif
  175034. void PNGAPI
  175035. png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
  175036. png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
  175037. {
  175038. if(png_ptr == NULL) return;
  175039. png_ptr->io_ptr = io_ptr;
  175040. #if !defined(PNG_NO_STDIO)
  175041. if (write_data_fn != NULL)
  175042. png_ptr->write_data_fn = write_data_fn;
  175043. else
  175044. png_ptr->write_data_fn = png_default_write_data;
  175045. #else
  175046. png_ptr->write_data_fn = write_data_fn;
  175047. #endif
  175048. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175049. #if !defined(PNG_NO_STDIO)
  175050. if (output_flush_fn != NULL)
  175051. png_ptr->output_flush_fn = output_flush_fn;
  175052. else
  175053. png_ptr->output_flush_fn = png_default_flush;
  175054. #else
  175055. png_ptr->output_flush_fn = output_flush_fn;
  175056. #endif
  175057. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  175058. if (png_ptr->read_data_fn != NULL)
  175059. {
  175060. png_ptr->read_data_fn = NULL;
  175061. png_warning(png_ptr,
  175062. "Attempted to set both read_data_fn and write_data_fn in");
  175063. png_warning(png_ptr,
  175064. "the same structure. Resetting read_data_fn to NULL.");
  175065. }
  175066. }
  175067. #if defined(USE_FAR_KEYWORD)
  175068. #if defined(_MSC_VER)
  175069. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  175070. {
  175071. void *near_ptr;
  175072. void FAR *far_ptr;
  175073. FP_OFF(near_ptr) = FP_OFF(ptr);
  175074. far_ptr = (void FAR *)near_ptr;
  175075. if(check != 0)
  175076. if(FP_SEG(ptr) != FP_SEG(far_ptr))
  175077. png_error(png_ptr,"segment lost in conversion");
  175078. return(near_ptr);
  175079. }
  175080. # else
  175081. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  175082. {
  175083. void *near_ptr;
  175084. void FAR *far_ptr;
  175085. near_ptr = (void FAR *)ptr;
  175086. far_ptr = (void FAR *)near_ptr;
  175087. if(check != 0)
  175088. if(far_ptr != ptr)
  175089. png_error(png_ptr,"segment lost in conversion");
  175090. return(near_ptr);
  175091. }
  175092. # endif
  175093. # endif
  175094. #endif /* PNG_WRITE_SUPPORTED */
  175095. /*** End of inlined file: pngwio.c ***/
  175096. /*** Start of inlined file: pngwrite.c ***/
  175097. #define PNG_INTERNAL
  175098. #ifdef PNG_WRITE_SUPPORTED
  175099. void PNGAPI
  175100. png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
  175101. {
  175102. png_debug(1, "in png_write_info_before_PLTE\n");
  175103. if (png_ptr == NULL || info_ptr == NULL)
  175104. return;
  175105. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  175106. {
  175107. png_write_sig(png_ptr); /* write PNG signature */
  175108. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175109. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted))
  175110. {
  175111. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  175112. png_ptr->mng_features_permitted=0;
  175113. }
  175114. #endif
  175115. png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
  175116. info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
  175117. info_ptr->filter_type,
  175118. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175119. info_ptr->interlace_type);
  175120. #else
  175121. 0);
  175122. #endif
  175123. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  175124. if (info_ptr->valid & PNG_INFO_gAMA)
  175125. {
  175126. # ifdef PNG_FLOATING_POINT_SUPPORTED
  175127. png_write_gAMA(png_ptr, info_ptr->gamma);
  175128. #else
  175129. #ifdef PNG_FIXED_POINT_SUPPORTED
  175130. png_write_gAMA_fixed(png_ptr, info_ptr->int_gamma);
  175131. # endif
  175132. #endif
  175133. }
  175134. #endif
  175135. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  175136. if (info_ptr->valid & PNG_INFO_sRGB)
  175137. png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
  175138. #endif
  175139. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  175140. if (info_ptr->valid & PNG_INFO_iCCP)
  175141. png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE,
  175142. info_ptr->iccp_profile, (int)info_ptr->iccp_proflen);
  175143. #endif
  175144. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  175145. if (info_ptr->valid & PNG_INFO_sBIT)
  175146. png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
  175147. #endif
  175148. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  175149. if (info_ptr->valid & PNG_INFO_cHRM)
  175150. {
  175151. #ifdef PNG_FLOATING_POINT_SUPPORTED
  175152. png_write_cHRM(png_ptr,
  175153. info_ptr->x_white, info_ptr->y_white,
  175154. info_ptr->x_red, info_ptr->y_red,
  175155. info_ptr->x_green, info_ptr->y_green,
  175156. info_ptr->x_blue, info_ptr->y_blue);
  175157. #else
  175158. # ifdef PNG_FIXED_POINT_SUPPORTED
  175159. png_write_cHRM_fixed(png_ptr,
  175160. info_ptr->int_x_white, info_ptr->int_y_white,
  175161. info_ptr->int_x_red, info_ptr->int_y_red,
  175162. info_ptr->int_x_green, info_ptr->int_y_green,
  175163. info_ptr->int_x_blue, info_ptr->int_y_blue);
  175164. # endif
  175165. #endif
  175166. }
  175167. #endif
  175168. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175169. if (info_ptr->unknown_chunks_num)
  175170. {
  175171. png_unknown_chunk *up;
  175172. png_debug(5, "writing extra chunks\n");
  175173. for (up = info_ptr->unknown_chunks;
  175174. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175175. up++)
  175176. {
  175177. int keep=png_handle_as_unknown(png_ptr, up->name);
  175178. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175179. up->location && !(up->location & PNG_HAVE_PLTE) &&
  175180. !(up->location & PNG_HAVE_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. png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE;
  175190. }
  175191. }
  175192. void PNGAPI
  175193. png_write_info(png_structp png_ptr, png_infop info_ptr)
  175194. {
  175195. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  175196. int i;
  175197. #endif
  175198. png_debug(1, "in png_write_info\n");
  175199. if (png_ptr == NULL || info_ptr == NULL)
  175200. return;
  175201. png_write_info_before_PLTE(png_ptr, info_ptr);
  175202. if (info_ptr->valid & PNG_INFO_PLTE)
  175203. png_write_PLTE(png_ptr, info_ptr->palette,
  175204. (png_uint_32)info_ptr->num_palette);
  175205. else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175206. png_error(png_ptr, "Valid palette required for paletted images");
  175207. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  175208. if (info_ptr->valid & PNG_INFO_tRNS)
  175209. {
  175210. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  175211. if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
  175212. info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175213. {
  175214. int j;
  175215. for (j=0; j<(int)info_ptr->num_trans; j++)
  175216. info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]);
  175217. }
  175218. #endif
  175219. png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values),
  175220. info_ptr->num_trans, info_ptr->color_type);
  175221. }
  175222. #endif
  175223. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  175224. if (info_ptr->valid & PNG_INFO_bKGD)
  175225. png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
  175226. #endif
  175227. #if defined(PNG_WRITE_hIST_SUPPORTED)
  175228. if (info_ptr->valid & PNG_INFO_hIST)
  175229. png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
  175230. #endif
  175231. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  175232. if (info_ptr->valid & PNG_INFO_oFFs)
  175233. png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,
  175234. info_ptr->offset_unit_type);
  175235. #endif
  175236. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  175237. if (info_ptr->valid & PNG_INFO_pCAL)
  175238. png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,
  175239. info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
  175240. info_ptr->pcal_units, info_ptr->pcal_params);
  175241. #endif
  175242. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  175243. if (info_ptr->valid & PNG_INFO_sCAL)
  175244. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  175245. png_write_sCAL(png_ptr, (int)info_ptr->scal_unit,
  175246. info_ptr->scal_pixel_width, info_ptr->scal_pixel_height);
  175247. #else
  175248. #ifdef PNG_FIXED_POINT_SUPPORTED
  175249. png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit,
  175250. info_ptr->scal_s_width, info_ptr->scal_s_height);
  175251. #else
  175252. png_warning(png_ptr,
  175253. "png_write_sCAL not supported; sCAL chunk not written.");
  175254. #endif
  175255. #endif
  175256. #endif
  175257. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  175258. if (info_ptr->valid & PNG_INFO_pHYs)
  175259. png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
  175260. info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);
  175261. #endif
  175262. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175263. if (info_ptr->valid & PNG_INFO_tIME)
  175264. {
  175265. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175266. png_ptr->mode |= PNG_WROTE_tIME;
  175267. }
  175268. #endif
  175269. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  175270. if (info_ptr->valid & PNG_INFO_sPLT)
  175271. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  175272. png_write_sPLT(png_ptr, info_ptr->splt_palettes + i);
  175273. #endif
  175274. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175275. for (i = 0; i < info_ptr->num_text; i++)
  175276. {
  175277. png_debug2(2, "Writing header text chunk %d, type %d\n", i,
  175278. info_ptr->text[i].compression);
  175279. if (info_ptr->text[i].compression > 0)
  175280. {
  175281. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175282. png_write_iTXt(png_ptr,
  175283. info_ptr->text[i].compression,
  175284. info_ptr->text[i].key,
  175285. info_ptr->text[i].lang,
  175286. info_ptr->text[i].lang_key,
  175287. info_ptr->text[i].text);
  175288. #else
  175289. png_warning(png_ptr, "Unable to write international text");
  175290. #endif
  175291. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175292. }
  175293. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt)
  175294. {
  175295. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175296. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175297. info_ptr->text[i].text, 0,
  175298. info_ptr->text[i].compression);
  175299. #else
  175300. png_warning(png_ptr, "Unable to write compressed text");
  175301. #endif
  175302. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175303. }
  175304. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175305. {
  175306. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175307. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175308. info_ptr->text[i].text,
  175309. 0);
  175310. #else
  175311. png_warning(png_ptr, "Unable to write uncompressed text");
  175312. #endif
  175313. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175314. }
  175315. }
  175316. #endif
  175317. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175318. if (info_ptr->unknown_chunks_num)
  175319. {
  175320. png_unknown_chunk *up;
  175321. png_debug(5, "writing extra chunks\n");
  175322. for (up = info_ptr->unknown_chunks;
  175323. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175324. up++)
  175325. {
  175326. int keep=png_handle_as_unknown(png_ptr, up->name);
  175327. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175328. up->location && (up->location & PNG_HAVE_PLTE) &&
  175329. !(up->location & PNG_HAVE_IDAT) &&
  175330. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175331. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175332. {
  175333. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175334. }
  175335. }
  175336. }
  175337. #endif
  175338. }
  175339. void PNGAPI
  175340. png_write_end(png_structp png_ptr, png_infop info_ptr)
  175341. {
  175342. png_debug(1, "in png_write_end\n");
  175343. if (png_ptr == NULL)
  175344. return;
  175345. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  175346. png_error(png_ptr, "No IDATs written into file");
  175347. if (info_ptr != NULL)
  175348. {
  175349. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175350. int i; /* local index variable */
  175351. #endif
  175352. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175353. if ((info_ptr->valid & PNG_INFO_tIME) &&
  175354. !(png_ptr->mode & PNG_WROTE_tIME))
  175355. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175356. #endif
  175357. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175358. for (i = 0; i < info_ptr->num_text; i++)
  175359. {
  175360. png_debug2(2, "Writing trailer text chunk %d, type %d\n", i,
  175361. info_ptr->text[i].compression);
  175362. if (info_ptr->text[i].compression > 0)
  175363. {
  175364. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175365. png_write_iTXt(png_ptr,
  175366. info_ptr->text[i].compression,
  175367. info_ptr->text[i].key,
  175368. info_ptr->text[i].lang,
  175369. info_ptr->text[i].lang_key,
  175370. info_ptr->text[i].text);
  175371. #else
  175372. png_warning(png_ptr, "Unable to write international text");
  175373. #endif
  175374. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175375. }
  175376. else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
  175377. {
  175378. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175379. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175380. info_ptr->text[i].text, 0,
  175381. info_ptr->text[i].compression);
  175382. #else
  175383. png_warning(png_ptr, "Unable to write compressed text");
  175384. #endif
  175385. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175386. }
  175387. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175388. {
  175389. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175390. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175391. info_ptr->text[i].text, 0);
  175392. #else
  175393. png_warning(png_ptr, "Unable to write uncompressed text");
  175394. #endif
  175395. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175396. }
  175397. }
  175398. #endif
  175399. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175400. if (info_ptr->unknown_chunks_num)
  175401. {
  175402. png_unknown_chunk *up;
  175403. png_debug(5, "writing extra chunks\n");
  175404. for (up = info_ptr->unknown_chunks;
  175405. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175406. up++)
  175407. {
  175408. int keep=png_handle_as_unknown(png_ptr, up->name);
  175409. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175410. up->location && (up->location & PNG_AFTER_IDAT) &&
  175411. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175412. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175413. {
  175414. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175415. }
  175416. }
  175417. }
  175418. #endif
  175419. }
  175420. png_ptr->mode |= PNG_AFTER_IDAT;
  175421. png_write_IEND(png_ptr);
  175422. }
  175423. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175424. #if !defined(_WIN32_WCE)
  175425. void PNGAPI
  175426. png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
  175427. {
  175428. png_debug(1, "in png_convert_from_struct_tm\n");
  175429. ptime->year = (png_uint_16)(1900 + ttime->tm_year);
  175430. ptime->month = (png_byte)(ttime->tm_mon + 1);
  175431. ptime->day = (png_byte)ttime->tm_mday;
  175432. ptime->hour = (png_byte)ttime->tm_hour;
  175433. ptime->minute = (png_byte)ttime->tm_min;
  175434. ptime->second = (png_byte)ttime->tm_sec;
  175435. }
  175436. void PNGAPI
  175437. png_convert_from_time_t(png_timep ptime, time_t ttime)
  175438. {
  175439. struct tm *tbuf;
  175440. png_debug(1, "in png_convert_from_time_t\n");
  175441. tbuf = gmtime(&ttime);
  175442. png_convert_from_struct_tm(ptime, tbuf);
  175443. }
  175444. #endif
  175445. #endif
  175446. png_structp PNGAPI
  175447. png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  175448. png_error_ptr error_fn, png_error_ptr warn_fn)
  175449. {
  175450. #ifdef PNG_USER_MEM_SUPPORTED
  175451. return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn,
  175452. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  175453. }
  175454. png_structp PNGAPI
  175455. png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  175456. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  175457. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  175458. {
  175459. #endif /* PNG_USER_MEM_SUPPORTED */
  175460. png_structp png_ptr;
  175461. #ifdef PNG_SETJMP_SUPPORTED
  175462. #ifdef USE_FAR_KEYWORD
  175463. jmp_buf jmpbuf;
  175464. #endif
  175465. #endif
  175466. int i;
  175467. png_debug(1, "in png_create_write_struct\n");
  175468. #ifdef PNG_USER_MEM_SUPPORTED
  175469. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  175470. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  175471. #else
  175472. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  175473. #endif /* PNG_USER_MEM_SUPPORTED */
  175474. if (png_ptr == NULL)
  175475. return (NULL);
  175476. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175477. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  175478. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  175479. #endif
  175480. #ifdef PNG_SETJMP_SUPPORTED
  175481. #ifdef USE_FAR_KEYWORD
  175482. if (setjmp(jmpbuf))
  175483. #else
  175484. if (setjmp(png_ptr->jmpbuf))
  175485. #endif
  175486. {
  175487. png_free(png_ptr, png_ptr->zbuf);
  175488. png_ptr->zbuf=NULL;
  175489. png_destroy_struct(png_ptr);
  175490. return (NULL);
  175491. }
  175492. #ifdef USE_FAR_KEYWORD
  175493. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175494. #endif
  175495. #endif
  175496. #ifdef PNG_USER_MEM_SUPPORTED
  175497. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  175498. #endif /* PNG_USER_MEM_SUPPORTED */
  175499. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  175500. i=0;
  175501. do
  175502. {
  175503. if(user_png_ver[i] != png_libpng_ver[i])
  175504. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  175505. } while (png_libpng_ver[i++]);
  175506. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  175507. {
  175508. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  175509. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  175510. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  175511. {
  175512. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175513. char msg[80];
  175514. if (user_png_ver)
  175515. {
  175516. png_snprintf(msg, 80,
  175517. "Application was compiled with png.h from libpng-%.20s",
  175518. user_png_ver);
  175519. png_warning(png_ptr, msg);
  175520. }
  175521. png_snprintf(msg, 80,
  175522. "Application is running with png.c from libpng-%.20s",
  175523. png_libpng_ver);
  175524. png_warning(png_ptr, msg);
  175525. #endif
  175526. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175527. png_ptr->flags=0;
  175528. #endif
  175529. png_error(png_ptr,
  175530. "Incompatible libpng version in application and library");
  175531. }
  175532. }
  175533. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  175534. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  175535. (png_uint_32)png_ptr->zbuf_size);
  175536. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  175537. png_flush_ptr_NULL);
  175538. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175539. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  175540. 1, png_doublep_NULL, png_doublep_NULL);
  175541. #endif
  175542. #ifdef PNG_SETJMP_SUPPORTED
  175543. #ifdef USE_FAR_KEYWORD
  175544. if (setjmp(jmpbuf))
  175545. PNG_ABORT();
  175546. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175547. #else
  175548. if (setjmp(png_ptr->jmpbuf))
  175549. PNG_ABORT();
  175550. #endif
  175551. #endif
  175552. return (png_ptr);
  175553. }
  175554. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  175555. #undef png_write_init
  175556. void PNGAPI
  175557. png_write_init(png_structp png_ptr)
  175558. {
  175559. png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  175560. }
  175561. void PNGAPI
  175562. png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  175563. png_size_t png_struct_size, png_size_t png_info_size)
  175564. {
  175565. if(png_ptr == NULL) return;
  175566. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175567. if(png_sizeof(png_struct) > png_struct_size ||
  175568. png_sizeof(png_info) > png_info_size)
  175569. {
  175570. char msg[80];
  175571. png_ptr->warning_fn=NULL;
  175572. if (user_png_ver)
  175573. {
  175574. png_snprintf(msg, 80,
  175575. "Application was compiled with png.h from libpng-%.20s",
  175576. user_png_ver);
  175577. png_warning(png_ptr, msg);
  175578. }
  175579. png_snprintf(msg, 80,
  175580. "Application is running with png.c from libpng-%.20s",
  175581. png_libpng_ver);
  175582. png_warning(png_ptr, msg);
  175583. }
  175584. #endif
  175585. if(png_sizeof(png_struct) > png_struct_size)
  175586. {
  175587. png_ptr->error_fn=NULL;
  175588. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175589. png_ptr->flags=0;
  175590. #endif
  175591. png_error(png_ptr,
  175592. "The png struct allocated by the application for writing is too small.");
  175593. }
  175594. if(png_sizeof(png_info) > png_info_size)
  175595. {
  175596. png_ptr->error_fn=NULL;
  175597. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175598. png_ptr->flags=0;
  175599. #endif
  175600. png_error(png_ptr,
  175601. "The info struct allocated by the application for writing is too small.");
  175602. }
  175603. png_write_init_3(&png_ptr, user_png_ver, png_struct_size);
  175604. }
  175605. #endif /* PNG_1_0_X || PNG_1_2_X */
  175606. void PNGAPI
  175607. png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  175608. png_size_t png_struct_size)
  175609. {
  175610. png_structp png_ptr=*ptr_ptr;
  175611. #ifdef PNG_SETJMP_SUPPORTED
  175612. jmp_buf tmp_jmp; /* to save current jump buffer */
  175613. #endif
  175614. int i = 0;
  175615. if (png_ptr == NULL)
  175616. return;
  175617. do
  175618. {
  175619. if (user_png_ver[i] != png_libpng_ver[i])
  175620. {
  175621. #ifdef PNG_LEGACY_SUPPORTED
  175622. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  175623. #else
  175624. png_ptr->warning_fn=NULL;
  175625. png_warning(png_ptr,
  175626. "Application uses deprecated png_write_init() and should be recompiled.");
  175627. break;
  175628. #endif
  175629. }
  175630. } while (png_libpng_ver[i++]);
  175631. png_debug(1, "in png_write_init_3\n");
  175632. #ifdef PNG_SETJMP_SUPPORTED
  175633. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  175634. #endif
  175635. if (png_sizeof(png_struct) > png_struct_size)
  175636. {
  175637. png_destroy_struct(png_ptr);
  175638. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  175639. *ptr_ptr = png_ptr;
  175640. }
  175641. png_memset(png_ptr, 0, png_sizeof (png_struct));
  175642. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175643. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  175644. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  175645. #endif
  175646. #ifdef PNG_SETJMP_SUPPORTED
  175647. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  175648. #endif
  175649. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  175650. png_flush_ptr_NULL);
  175651. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  175652. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  175653. (png_uint_32)png_ptr->zbuf_size);
  175654. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175655. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  175656. 1, png_doublep_NULL, png_doublep_NULL);
  175657. #endif
  175658. }
  175659. void PNGAPI
  175660. png_write_rows(png_structp png_ptr, png_bytepp row,
  175661. png_uint_32 num_rows)
  175662. {
  175663. png_uint_32 i; /* row counter */
  175664. png_bytepp rp; /* row pointer */
  175665. png_debug(1, "in png_write_rows\n");
  175666. if (png_ptr == NULL)
  175667. return;
  175668. for (i = 0, rp = row; i < num_rows; i++, rp++)
  175669. {
  175670. png_write_row(png_ptr, *rp);
  175671. }
  175672. }
  175673. void PNGAPI
  175674. png_write_image(png_structp png_ptr, png_bytepp image)
  175675. {
  175676. png_uint_32 i; /* row index */
  175677. int pass, num_pass; /* pass variables */
  175678. png_bytepp rp; /* points to current row */
  175679. if (png_ptr == NULL)
  175680. return;
  175681. png_debug(1, "in png_write_image\n");
  175682. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175683. num_pass = png_set_interlace_handling(png_ptr);
  175684. #else
  175685. num_pass = 1;
  175686. #endif
  175687. for (pass = 0; pass < num_pass; pass++)
  175688. {
  175689. for (i = 0, rp = image; i < png_ptr->height; i++, rp++)
  175690. {
  175691. png_write_row(png_ptr, *rp);
  175692. }
  175693. }
  175694. }
  175695. void PNGAPI
  175696. png_write_row(png_structp png_ptr, png_bytep row)
  175697. {
  175698. if (png_ptr == NULL)
  175699. return;
  175700. png_debug2(1, "in png_write_row (row %ld, pass %d)\n",
  175701. png_ptr->row_number, png_ptr->pass);
  175702. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  175703. {
  175704. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  175705. png_error(png_ptr,
  175706. "png_write_info was never called before png_write_row.");
  175707. #if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
  175708. if (png_ptr->transformations & PNG_INVERT_MONO)
  175709. png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined.");
  175710. #endif
  175711. #if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)
  175712. if (png_ptr->transformations & PNG_FILLER)
  175713. png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined.");
  175714. #endif
  175715. #if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED)
  175716. if (png_ptr->transformations & PNG_PACKSWAP)
  175717. png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined.");
  175718. #endif
  175719. #if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)
  175720. if (png_ptr->transformations & PNG_PACK)
  175721. png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined.");
  175722. #endif
  175723. #if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)
  175724. if (png_ptr->transformations & PNG_SHIFT)
  175725. png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined.");
  175726. #endif
  175727. #if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)
  175728. if (png_ptr->transformations & PNG_BGR)
  175729. png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined.");
  175730. #endif
  175731. #if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)
  175732. if (png_ptr->transformations & PNG_SWAP_BYTES)
  175733. png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined.");
  175734. #endif
  175735. png_write_start_row(png_ptr);
  175736. }
  175737. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175738. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  175739. {
  175740. switch (png_ptr->pass)
  175741. {
  175742. case 0:
  175743. if (png_ptr->row_number & 0x07)
  175744. {
  175745. png_write_finish_row(png_ptr);
  175746. return;
  175747. }
  175748. break;
  175749. case 1:
  175750. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  175751. {
  175752. png_write_finish_row(png_ptr);
  175753. return;
  175754. }
  175755. break;
  175756. case 2:
  175757. if ((png_ptr->row_number & 0x07) != 4)
  175758. {
  175759. png_write_finish_row(png_ptr);
  175760. return;
  175761. }
  175762. break;
  175763. case 3:
  175764. if ((png_ptr->row_number & 0x03) || png_ptr->width < 3)
  175765. {
  175766. png_write_finish_row(png_ptr);
  175767. return;
  175768. }
  175769. break;
  175770. case 4:
  175771. if ((png_ptr->row_number & 0x03) != 2)
  175772. {
  175773. png_write_finish_row(png_ptr);
  175774. return;
  175775. }
  175776. break;
  175777. case 5:
  175778. if ((png_ptr->row_number & 0x01) || png_ptr->width < 2)
  175779. {
  175780. png_write_finish_row(png_ptr);
  175781. return;
  175782. }
  175783. break;
  175784. case 6:
  175785. if (!(png_ptr->row_number & 0x01))
  175786. {
  175787. png_write_finish_row(png_ptr);
  175788. return;
  175789. }
  175790. break;
  175791. }
  175792. }
  175793. #endif
  175794. png_ptr->row_info.color_type = png_ptr->color_type;
  175795. png_ptr->row_info.width = png_ptr->usr_width;
  175796. png_ptr->row_info.channels = png_ptr->usr_channels;
  175797. png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth;
  175798. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  175799. png_ptr->row_info.channels);
  175800. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  175801. png_ptr->row_info.width);
  175802. png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type);
  175803. png_debug1(3, "row_info->width = %lu\n", png_ptr->row_info.width);
  175804. png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels);
  175805. png_debug1(3, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth);
  175806. png_debug1(3, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth);
  175807. png_debug1(3, "row_info->rowbytes = %lu\n", png_ptr->row_info.rowbytes);
  175808. png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row,
  175809. png_ptr->row_info.rowbytes);
  175810. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175811. if (png_ptr->interlaced && png_ptr->pass < 6 &&
  175812. (png_ptr->transformations & PNG_INTERLACE))
  175813. {
  175814. png_do_write_interlace(&(png_ptr->row_info),
  175815. png_ptr->row_buf + 1, png_ptr->pass);
  175816. if (!(png_ptr->row_info.width))
  175817. {
  175818. png_write_finish_row(png_ptr);
  175819. return;
  175820. }
  175821. }
  175822. #endif
  175823. if (png_ptr->transformations)
  175824. png_do_write_transformations(png_ptr);
  175825. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175826. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  175827. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  175828. {
  175829. png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  175830. }
  175831. #endif
  175832. png_write_find_filter(png_ptr, &(png_ptr->row_info));
  175833. if (png_ptr->write_row_fn != NULL)
  175834. (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  175835. }
  175836. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175837. void PNGAPI
  175838. png_set_flush(png_structp png_ptr, int nrows)
  175839. {
  175840. png_debug(1, "in png_set_flush\n");
  175841. if (png_ptr == NULL)
  175842. return;
  175843. png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);
  175844. }
  175845. void PNGAPI
  175846. png_write_flush(png_structp png_ptr)
  175847. {
  175848. int wrote_IDAT;
  175849. png_debug(1, "in png_write_flush\n");
  175850. if (png_ptr == NULL)
  175851. return;
  175852. if (png_ptr->row_number >= png_ptr->num_rows)
  175853. return;
  175854. do
  175855. {
  175856. int ret;
  175857. ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH);
  175858. wrote_IDAT = 0;
  175859. if (ret != Z_OK)
  175860. {
  175861. if (png_ptr->zstream.msg != NULL)
  175862. png_error(png_ptr, png_ptr->zstream.msg);
  175863. else
  175864. png_error(png_ptr, "zlib error");
  175865. }
  175866. if (!(png_ptr->zstream.avail_out))
  175867. {
  175868. png_write_IDAT(png_ptr, png_ptr->zbuf,
  175869. png_ptr->zbuf_size);
  175870. png_ptr->zstream.next_out = png_ptr->zbuf;
  175871. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  175872. wrote_IDAT = 1;
  175873. }
  175874. } while(wrote_IDAT == 1);
  175875. if (png_ptr->zbuf_size != png_ptr->zstream.avail_out)
  175876. {
  175877. png_write_IDAT(png_ptr, png_ptr->zbuf,
  175878. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  175879. png_ptr->zstream.next_out = png_ptr->zbuf;
  175880. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  175881. }
  175882. png_ptr->flush_rows = 0;
  175883. png_flush(png_ptr);
  175884. }
  175885. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  175886. void PNGAPI
  175887. png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
  175888. {
  175889. png_structp png_ptr = NULL;
  175890. png_infop info_ptr = NULL;
  175891. #ifdef PNG_USER_MEM_SUPPORTED
  175892. png_free_ptr free_fn = NULL;
  175893. png_voidp mem_ptr = NULL;
  175894. #endif
  175895. png_debug(1, "in png_destroy_write_struct\n");
  175896. if (png_ptr_ptr != NULL)
  175897. {
  175898. png_ptr = *png_ptr_ptr;
  175899. #ifdef PNG_USER_MEM_SUPPORTED
  175900. free_fn = png_ptr->free_fn;
  175901. mem_ptr = png_ptr->mem_ptr;
  175902. #endif
  175903. }
  175904. if (info_ptr_ptr != NULL)
  175905. info_ptr = *info_ptr_ptr;
  175906. if (info_ptr != NULL)
  175907. {
  175908. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  175909. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  175910. if (png_ptr->num_chunk_list)
  175911. {
  175912. png_free(png_ptr, png_ptr->chunk_list);
  175913. png_ptr->chunk_list=NULL;
  175914. png_ptr->num_chunk_list=0;
  175915. }
  175916. #endif
  175917. #ifdef PNG_USER_MEM_SUPPORTED
  175918. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  175919. (png_voidp)mem_ptr);
  175920. #else
  175921. png_destroy_struct((png_voidp)info_ptr);
  175922. #endif
  175923. *info_ptr_ptr = NULL;
  175924. }
  175925. if (png_ptr != NULL)
  175926. {
  175927. png_write_destroy(png_ptr);
  175928. #ifdef PNG_USER_MEM_SUPPORTED
  175929. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  175930. (png_voidp)mem_ptr);
  175931. #else
  175932. png_destroy_struct((png_voidp)png_ptr);
  175933. #endif
  175934. *png_ptr_ptr = NULL;
  175935. }
  175936. }
  175937. void /* PRIVATE */
  175938. png_write_destroy(png_structp png_ptr)
  175939. {
  175940. #ifdef PNG_SETJMP_SUPPORTED
  175941. jmp_buf tmp_jmp; /* save jump buffer */
  175942. #endif
  175943. png_error_ptr error_fn;
  175944. png_error_ptr warning_fn;
  175945. png_voidp error_ptr;
  175946. #ifdef PNG_USER_MEM_SUPPORTED
  175947. png_free_ptr free_fn;
  175948. #endif
  175949. png_debug(1, "in png_write_destroy\n");
  175950. deflateEnd(&png_ptr->zstream);
  175951. png_free(png_ptr, png_ptr->zbuf);
  175952. png_free(png_ptr, png_ptr->row_buf);
  175953. png_free(png_ptr, png_ptr->prev_row);
  175954. png_free(png_ptr, png_ptr->sub_row);
  175955. png_free(png_ptr, png_ptr->up_row);
  175956. png_free(png_ptr, png_ptr->avg_row);
  175957. png_free(png_ptr, png_ptr->paeth_row);
  175958. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  175959. png_free(png_ptr, png_ptr->time_buffer);
  175960. #endif
  175961. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175962. png_free(png_ptr, png_ptr->prev_filters);
  175963. png_free(png_ptr, png_ptr->filter_weights);
  175964. png_free(png_ptr, png_ptr->inv_filter_weights);
  175965. png_free(png_ptr, png_ptr->filter_costs);
  175966. png_free(png_ptr, png_ptr->inv_filter_costs);
  175967. #endif
  175968. #ifdef PNG_SETJMP_SUPPORTED
  175969. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  175970. #endif
  175971. error_fn = png_ptr->error_fn;
  175972. warning_fn = png_ptr->warning_fn;
  175973. error_ptr = png_ptr->error_ptr;
  175974. #ifdef PNG_USER_MEM_SUPPORTED
  175975. free_fn = png_ptr->free_fn;
  175976. #endif
  175977. png_memset(png_ptr, 0, png_sizeof (png_struct));
  175978. png_ptr->error_fn = error_fn;
  175979. png_ptr->warning_fn = warning_fn;
  175980. png_ptr->error_ptr = error_ptr;
  175981. #ifdef PNG_USER_MEM_SUPPORTED
  175982. png_ptr->free_fn = free_fn;
  175983. #endif
  175984. #ifdef PNG_SETJMP_SUPPORTED
  175985. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  175986. #endif
  175987. }
  175988. void PNGAPI
  175989. png_set_filter(png_structp png_ptr, int method, int filters)
  175990. {
  175991. png_debug(1, "in png_set_filter\n");
  175992. if (png_ptr == NULL)
  175993. return;
  175994. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175995. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  175996. (method == PNG_INTRAPIXEL_DIFFERENCING))
  175997. method = PNG_FILTER_TYPE_BASE;
  175998. #endif
  175999. if (method == PNG_FILTER_TYPE_BASE)
  176000. {
  176001. switch (filters & (PNG_ALL_FILTERS | 0x07))
  176002. {
  176003. #ifndef PNG_NO_WRITE_FILTER
  176004. case 5:
  176005. case 6:
  176006. case 7: png_warning(png_ptr, "Unknown row filter for method 0");
  176007. #endif /* PNG_NO_WRITE_FILTER */
  176008. case PNG_FILTER_VALUE_NONE:
  176009. png_ptr->do_filter=PNG_FILTER_NONE; break;
  176010. #ifndef PNG_NO_WRITE_FILTER
  176011. case PNG_FILTER_VALUE_SUB:
  176012. png_ptr->do_filter=PNG_FILTER_SUB; break;
  176013. case PNG_FILTER_VALUE_UP:
  176014. png_ptr->do_filter=PNG_FILTER_UP; break;
  176015. case PNG_FILTER_VALUE_AVG:
  176016. png_ptr->do_filter=PNG_FILTER_AVG; break;
  176017. case PNG_FILTER_VALUE_PAETH:
  176018. png_ptr->do_filter=PNG_FILTER_PAETH; break;
  176019. default: png_ptr->do_filter = (png_byte)filters; break;
  176020. #else
  176021. default: png_warning(png_ptr, "Unknown row filter for method 0");
  176022. #endif /* PNG_NO_WRITE_FILTER */
  176023. }
  176024. if (png_ptr->row_buf != NULL)
  176025. {
  176026. #ifndef PNG_NO_WRITE_FILTER
  176027. if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
  176028. {
  176029. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  176030. (png_ptr->rowbytes + 1));
  176031. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  176032. }
  176033. if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL)
  176034. {
  176035. if (png_ptr->prev_row == NULL)
  176036. {
  176037. png_warning(png_ptr, "Can't add Up filter after starting");
  176038. png_ptr->do_filter &= ~PNG_FILTER_UP;
  176039. }
  176040. else
  176041. {
  176042. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  176043. (png_ptr->rowbytes + 1));
  176044. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  176045. }
  176046. }
  176047. if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL)
  176048. {
  176049. if (png_ptr->prev_row == NULL)
  176050. {
  176051. png_warning(png_ptr, "Can't add Average filter after starting");
  176052. png_ptr->do_filter &= ~PNG_FILTER_AVG;
  176053. }
  176054. else
  176055. {
  176056. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  176057. (png_ptr->rowbytes + 1));
  176058. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  176059. }
  176060. }
  176061. if ((png_ptr->do_filter & PNG_FILTER_PAETH) &&
  176062. png_ptr->paeth_row == NULL)
  176063. {
  176064. if (png_ptr->prev_row == NULL)
  176065. {
  176066. png_warning(png_ptr, "Can't add Paeth filter after starting");
  176067. png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH);
  176068. }
  176069. else
  176070. {
  176071. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  176072. (png_ptr->rowbytes + 1));
  176073. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  176074. }
  176075. }
  176076. if (png_ptr->do_filter == PNG_NO_FILTERS)
  176077. #endif /* PNG_NO_WRITE_FILTER */
  176078. png_ptr->do_filter = PNG_FILTER_NONE;
  176079. }
  176080. }
  176081. else
  176082. png_error(png_ptr, "Unknown custom filter method");
  176083. }
  176084. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* GRR 970116 */
  176085. void PNGAPI
  176086. png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
  176087. int num_weights, png_doublep filter_weights,
  176088. png_doublep filter_costs)
  176089. {
  176090. int i;
  176091. png_debug(1, "in png_set_filter_heuristics\n");
  176092. if (png_ptr == NULL)
  176093. return;
  176094. if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST)
  176095. {
  176096. png_warning(png_ptr, "Unknown filter heuristic method");
  176097. return;
  176098. }
  176099. if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT)
  176100. {
  176101. heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED;
  176102. }
  176103. if (num_weights < 0 || filter_weights == NULL ||
  176104. heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED)
  176105. {
  176106. num_weights = 0;
  176107. }
  176108. png_ptr->num_prev_filters = (png_byte)num_weights;
  176109. png_ptr->heuristic_method = (png_byte)heuristic_method;
  176110. if (num_weights > 0)
  176111. {
  176112. if (png_ptr->prev_filters == NULL)
  176113. {
  176114. png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr,
  176115. (png_uint_32)(png_sizeof(png_byte) * num_weights));
  176116. for (i = 0; i < num_weights; i++)
  176117. {
  176118. png_ptr->prev_filters[i] = 255;
  176119. }
  176120. }
  176121. if (png_ptr->filter_weights == NULL)
  176122. {
  176123. png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176124. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176125. png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176126. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176127. for (i = 0; i < num_weights; i++)
  176128. {
  176129. png_ptr->inv_filter_weights[i] =
  176130. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176131. }
  176132. }
  176133. for (i = 0; i < num_weights; i++)
  176134. {
  176135. if (filter_weights[i] < 0.0)
  176136. {
  176137. png_ptr->inv_filter_weights[i] =
  176138. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176139. }
  176140. else
  176141. {
  176142. png_ptr->inv_filter_weights[i] =
  176143. (png_uint_16)((double)PNG_WEIGHT_FACTOR*filter_weights[i]+0.5);
  176144. png_ptr->filter_weights[i] =
  176145. (png_uint_16)((double)PNG_WEIGHT_FACTOR/filter_weights[i]+0.5);
  176146. }
  176147. }
  176148. }
  176149. if (png_ptr->filter_costs == NULL)
  176150. {
  176151. png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176152. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176153. png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176154. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176155. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176156. {
  176157. png_ptr->inv_filter_costs[i] =
  176158. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176159. }
  176160. }
  176161. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176162. {
  176163. if (filter_costs == NULL || filter_costs[i] < 0.0)
  176164. {
  176165. png_ptr->inv_filter_costs[i] =
  176166. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176167. }
  176168. else if (filter_costs[i] >= 1.0)
  176169. {
  176170. png_ptr->inv_filter_costs[i] =
  176171. (png_uint_16)((double)PNG_COST_FACTOR / filter_costs[i] + 0.5);
  176172. png_ptr->filter_costs[i] =
  176173. (png_uint_16)((double)PNG_COST_FACTOR * filter_costs[i] + 0.5);
  176174. }
  176175. }
  176176. }
  176177. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  176178. void PNGAPI
  176179. png_set_compression_level(png_structp png_ptr, int level)
  176180. {
  176181. png_debug(1, "in png_set_compression_level\n");
  176182. if (png_ptr == NULL)
  176183. return;
  176184. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL;
  176185. png_ptr->zlib_level = level;
  176186. }
  176187. void PNGAPI
  176188. png_set_compression_mem_level(png_structp png_ptr, int mem_level)
  176189. {
  176190. png_debug(1, "in png_set_compression_mem_level\n");
  176191. if (png_ptr == NULL)
  176192. return;
  176193. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL;
  176194. png_ptr->zlib_mem_level = mem_level;
  176195. }
  176196. void PNGAPI
  176197. png_set_compression_strategy(png_structp png_ptr, int strategy)
  176198. {
  176199. png_debug(1, "in png_set_compression_strategy\n");
  176200. if (png_ptr == NULL)
  176201. return;
  176202. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY;
  176203. png_ptr->zlib_strategy = strategy;
  176204. }
  176205. void PNGAPI
  176206. png_set_compression_window_bits(png_structp png_ptr, int window_bits)
  176207. {
  176208. if (png_ptr == NULL)
  176209. return;
  176210. if (window_bits > 15)
  176211. png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
  176212. else if (window_bits < 8)
  176213. png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
  176214. #ifndef WBITS_8_OK
  176215. if (window_bits == 8)
  176216. {
  176217. png_warning(png_ptr, "Compression window is being reset to 512");
  176218. window_bits=9;
  176219. }
  176220. #endif
  176221. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS;
  176222. png_ptr->zlib_window_bits = window_bits;
  176223. }
  176224. void PNGAPI
  176225. png_set_compression_method(png_structp png_ptr, int method)
  176226. {
  176227. png_debug(1, "in png_set_compression_method\n");
  176228. if (png_ptr == NULL)
  176229. return;
  176230. if (method != 8)
  176231. png_warning(png_ptr, "Only compression method 8 is supported by PNG");
  176232. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD;
  176233. png_ptr->zlib_method = method;
  176234. }
  176235. void PNGAPI
  176236. png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn)
  176237. {
  176238. if (png_ptr == NULL)
  176239. return;
  176240. png_ptr->write_row_fn = write_row_fn;
  176241. }
  176242. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176243. void PNGAPI
  176244. png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  176245. write_user_transform_fn)
  176246. {
  176247. png_debug(1, "in png_set_write_user_transform_fn\n");
  176248. if (png_ptr == NULL)
  176249. return;
  176250. png_ptr->transformations |= PNG_USER_TRANSFORM;
  176251. png_ptr->write_user_transform_fn = write_user_transform_fn;
  176252. }
  176253. #endif
  176254. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  176255. void PNGAPI
  176256. png_write_png(png_structp png_ptr, png_infop info_ptr,
  176257. int transforms, voidp params)
  176258. {
  176259. if (png_ptr == NULL || info_ptr == NULL)
  176260. return;
  176261. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176262. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  176263. png_set_invert_alpha(png_ptr);
  176264. #endif
  176265. png_write_info(png_ptr, info_ptr);
  176266. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176267. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  176268. png_set_invert_mono(png_ptr);
  176269. #endif
  176270. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176271. if ((transforms & PNG_TRANSFORM_SHIFT)
  176272. && (info_ptr->valid & PNG_INFO_sBIT))
  176273. png_set_shift(png_ptr, &info_ptr->sig_bit);
  176274. #endif
  176275. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176276. if (transforms & PNG_TRANSFORM_PACKING)
  176277. png_set_packing(png_ptr);
  176278. #endif
  176279. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176280. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  176281. png_set_swap_alpha(png_ptr);
  176282. #endif
  176283. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176284. if (transforms & PNG_TRANSFORM_STRIP_FILLER)
  176285. png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
  176286. #endif
  176287. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176288. if (transforms & PNG_TRANSFORM_BGR)
  176289. png_set_bgr(png_ptr);
  176290. #endif
  176291. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176292. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  176293. png_set_swap(png_ptr);
  176294. #endif
  176295. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176296. if (transforms & PNG_TRANSFORM_PACKSWAP)
  176297. png_set_packswap(png_ptr);
  176298. #endif
  176299. if (info_ptr->valid & PNG_INFO_IDAT)
  176300. png_write_image(png_ptr, info_ptr->row_pointers);
  176301. png_write_end(png_ptr, info_ptr);
  176302. transforms = transforms; /* quiet compiler warnings */
  176303. params = params;
  176304. }
  176305. #endif
  176306. #endif /* PNG_WRITE_SUPPORTED */
  176307. /*** End of inlined file: pngwrite.c ***/
  176308. /*** Start of inlined file: pngwtran.c ***/
  176309. #define PNG_INTERNAL
  176310. #ifdef PNG_WRITE_SUPPORTED
  176311. void /* PRIVATE */
  176312. png_do_write_transformations(png_structp png_ptr)
  176313. {
  176314. png_debug(1, "in png_do_write_transformations\n");
  176315. if (png_ptr == NULL)
  176316. return;
  176317. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176318. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  176319. if(png_ptr->write_user_transform_fn != NULL)
  176320. (*(png_ptr->write_user_transform_fn)) /* user write transform function */
  176321. (png_ptr, /* png_ptr */
  176322. &(png_ptr->row_info), /* row_info: */
  176323. png_ptr->row_buf + 1); /* start of pixel data for row */
  176324. #endif
  176325. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176326. if (png_ptr->transformations & PNG_FILLER)
  176327. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176328. png_ptr->flags);
  176329. #endif
  176330. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176331. if (png_ptr->transformations & PNG_PACKSWAP)
  176332. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176333. #endif
  176334. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176335. if (png_ptr->transformations & PNG_PACK)
  176336. png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176337. (png_uint_32)png_ptr->bit_depth);
  176338. #endif
  176339. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176340. if (png_ptr->transformations & PNG_SWAP_BYTES)
  176341. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176342. #endif
  176343. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176344. if (png_ptr->transformations & PNG_SHIFT)
  176345. png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176346. &(png_ptr->shift));
  176347. #endif
  176348. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176349. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  176350. png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176351. #endif
  176352. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176353. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  176354. png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176355. #endif
  176356. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176357. if (png_ptr->transformations & PNG_BGR)
  176358. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176359. #endif
  176360. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176361. if (png_ptr->transformations & PNG_INVERT_MONO)
  176362. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176363. #endif
  176364. }
  176365. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176366. void /* PRIVATE */
  176367. png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
  176368. {
  176369. png_debug(1, "in png_do_pack\n");
  176370. if (row_info->bit_depth == 8 &&
  176371. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176372. row != NULL && row_info != NULL &&
  176373. #endif
  176374. row_info->channels == 1)
  176375. {
  176376. switch ((int)bit_depth)
  176377. {
  176378. case 1:
  176379. {
  176380. png_bytep sp, dp;
  176381. int mask, v;
  176382. png_uint_32 i;
  176383. png_uint_32 row_width = row_info->width;
  176384. sp = row;
  176385. dp = row;
  176386. mask = 0x80;
  176387. v = 0;
  176388. for (i = 0; i < row_width; i++)
  176389. {
  176390. if (*sp != 0)
  176391. v |= mask;
  176392. sp++;
  176393. if (mask > 1)
  176394. mask >>= 1;
  176395. else
  176396. {
  176397. mask = 0x80;
  176398. *dp = (png_byte)v;
  176399. dp++;
  176400. v = 0;
  176401. }
  176402. }
  176403. if (mask != 0x80)
  176404. *dp = (png_byte)v;
  176405. break;
  176406. }
  176407. case 2:
  176408. {
  176409. png_bytep sp, dp;
  176410. int shift, v;
  176411. png_uint_32 i;
  176412. png_uint_32 row_width = row_info->width;
  176413. sp = row;
  176414. dp = row;
  176415. shift = 6;
  176416. v = 0;
  176417. for (i = 0; i < row_width; i++)
  176418. {
  176419. png_byte value;
  176420. value = (png_byte)(*sp & 0x03);
  176421. v |= (value << shift);
  176422. if (shift == 0)
  176423. {
  176424. shift = 6;
  176425. *dp = (png_byte)v;
  176426. dp++;
  176427. v = 0;
  176428. }
  176429. else
  176430. shift -= 2;
  176431. sp++;
  176432. }
  176433. if (shift != 6)
  176434. *dp = (png_byte)v;
  176435. break;
  176436. }
  176437. case 4:
  176438. {
  176439. png_bytep sp, dp;
  176440. int shift, v;
  176441. png_uint_32 i;
  176442. png_uint_32 row_width = row_info->width;
  176443. sp = row;
  176444. dp = row;
  176445. shift = 4;
  176446. v = 0;
  176447. for (i = 0; i < row_width; i++)
  176448. {
  176449. png_byte value;
  176450. value = (png_byte)(*sp & 0x0f);
  176451. v |= (value << shift);
  176452. if (shift == 0)
  176453. {
  176454. shift = 4;
  176455. *dp = (png_byte)v;
  176456. dp++;
  176457. v = 0;
  176458. }
  176459. else
  176460. shift -= 4;
  176461. sp++;
  176462. }
  176463. if (shift != 4)
  176464. *dp = (png_byte)v;
  176465. break;
  176466. }
  176467. }
  176468. row_info->bit_depth = (png_byte)bit_depth;
  176469. row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels);
  176470. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  176471. row_info->width);
  176472. }
  176473. }
  176474. #endif
  176475. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176476. void /* PRIVATE */
  176477. png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
  176478. {
  176479. png_debug(1, "in png_do_shift\n");
  176480. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176481. if (row != NULL && row_info != NULL &&
  176482. #else
  176483. if (
  176484. #endif
  176485. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  176486. {
  176487. int shift_start[4], shift_dec[4];
  176488. int channels = 0;
  176489. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  176490. {
  176491. shift_start[channels] = row_info->bit_depth - bit_depth->red;
  176492. shift_dec[channels] = bit_depth->red;
  176493. channels++;
  176494. shift_start[channels] = row_info->bit_depth - bit_depth->green;
  176495. shift_dec[channels] = bit_depth->green;
  176496. channels++;
  176497. shift_start[channels] = row_info->bit_depth - bit_depth->blue;
  176498. shift_dec[channels] = bit_depth->blue;
  176499. channels++;
  176500. }
  176501. else
  176502. {
  176503. shift_start[channels] = row_info->bit_depth - bit_depth->gray;
  176504. shift_dec[channels] = bit_depth->gray;
  176505. channels++;
  176506. }
  176507. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  176508. {
  176509. shift_start[channels] = row_info->bit_depth - bit_depth->alpha;
  176510. shift_dec[channels] = bit_depth->alpha;
  176511. channels++;
  176512. }
  176513. if (row_info->bit_depth < 8)
  176514. {
  176515. png_bytep bp = row;
  176516. png_uint_32 i;
  176517. png_byte mask;
  176518. png_uint_32 row_bytes = row_info->rowbytes;
  176519. if (bit_depth->gray == 1 && row_info->bit_depth == 2)
  176520. mask = 0x55;
  176521. else if (row_info->bit_depth == 4 && bit_depth->gray == 3)
  176522. mask = 0x11;
  176523. else
  176524. mask = 0xff;
  176525. for (i = 0; i < row_bytes; i++, bp++)
  176526. {
  176527. png_uint_16 v;
  176528. int j;
  176529. v = *bp;
  176530. *bp = 0;
  176531. for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0])
  176532. {
  176533. if (j > 0)
  176534. *bp |= (png_byte)((v << j) & 0xff);
  176535. else
  176536. *bp |= (png_byte)((v >> (-j)) & mask);
  176537. }
  176538. }
  176539. }
  176540. else if (row_info->bit_depth == 8)
  176541. {
  176542. png_bytep bp = row;
  176543. png_uint_32 i;
  176544. png_uint_32 istop = channels * row_info->width;
  176545. for (i = 0; i < istop; i++, bp++)
  176546. {
  176547. png_uint_16 v;
  176548. int j;
  176549. int c = (int)(i%channels);
  176550. v = *bp;
  176551. *bp = 0;
  176552. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  176553. {
  176554. if (j > 0)
  176555. *bp |= (png_byte)((v << j) & 0xff);
  176556. else
  176557. *bp |= (png_byte)((v >> (-j)) & 0xff);
  176558. }
  176559. }
  176560. }
  176561. else
  176562. {
  176563. png_bytep bp;
  176564. png_uint_32 i;
  176565. png_uint_32 istop = channels * row_info->width;
  176566. for (bp = row, i = 0; i < istop; i++)
  176567. {
  176568. int c = (int)(i%channels);
  176569. png_uint_16 value, v;
  176570. int j;
  176571. v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1));
  176572. value = 0;
  176573. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  176574. {
  176575. if (j > 0)
  176576. value |= (png_uint_16)((v << j) & (png_uint_16)0xffff);
  176577. else
  176578. value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff);
  176579. }
  176580. *bp++ = (png_byte)(value >> 8);
  176581. *bp++ = (png_byte)(value & 0xff);
  176582. }
  176583. }
  176584. }
  176585. }
  176586. #endif
  176587. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176588. void /* PRIVATE */
  176589. png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
  176590. {
  176591. png_debug(1, "in png_do_write_swap_alpha\n");
  176592. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176593. if (row != NULL && row_info != NULL)
  176594. #endif
  176595. {
  176596. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176597. {
  176598. if (row_info->bit_depth == 8)
  176599. {
  176600. png_bytep sp, dp;
  176601. png_uint_32 i;
  176602. png_uint_32 row_width = row_info->width;
  176603. for (i = 0, sp = dp = row; i < row_width; i++)
  176604. {
  176605. png_byte save = *(sp++);
  176606. *(dp++) = *(sp++);
  176607. *(dp++) = *(sp++);
  176608. *(dp++) = *(sp++);
  176609. *(dp++) = save;
  176610. }
  176611. }
  176612. else
  176613. {
  176614. png_bytep sp, dp;
  176615. png_uint_32 i;
  176616. png_uint_32 row_width = row_info->width;
  176617. for (i = 0, sp = dp = row; i < row_width; i++)
  176618. {
  176619. png_byte save[2];
  176620. save[0] = *(sp++);
  176621. save[1] = *(sp++);
  176622. *(dp++) = *(sp++);
  176623. *(dp++) = *(sp++);
  176624. *(dp++) = *(sp++);
  176625. *(dp++) = *(sp++);
  176626. *(dp++) = *(sp++);
  176627. *(dp++) = *(sp++);
  176628. *(dp++) = save[0];
  176629. *(dp++) = save[1];
  176630. }
  176631. }
  176632. }
  176633. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  176634. {
  176635. if (row_info->bit_depth == 8)
  176636. {
  176637. png_bytep sp, dp;
  176638. png_uint_32 i;
  176639. png_uint_32 row_width = row_info->width;
  176640. for (i = 0, sp = dp = row; i < row_width; i++)
  176641. {
  176642. png_byte save = *(sp++);
  176643. *(dp++) = *(sp++);
  176644. *(dp++) = save;
  176645. }
  176646. }
  176647. else
  176648. {
  176649. png_bytep sp, dp;
  176650. png_uint_32 i;
  176651. png_uint_32 row_width = row_info->width;
  176652. for (i = 0, sp = dp = row; i < row_width; i++)
  176653. {
  176654. png_byte save[2];
  176655. save[0] = *(sp++);
  176656. save[1] = *(sp++);
  176657. *(dp++) = *(sp++);
  176658. *(dp++) = *(sp++);
  176659. *(dp++) = save[0];
  176660. *(dp++) = save[1];
  176661. }
  176662. }
  176663. }
  176664. }
  176665. }
  176666. #endif
  176667. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176668. void /* PRIVATE */
  176669. png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
  176670. {
  176671. png_debug(1, "in png_do_write_invert_alpha\n");
  176672. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176673. if (row != NULL && row_info != NULL)
  176674. #endif
  176675. {
  176676. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176677. {
  176678. if (row_info->bit_depth == 8)
  176679. {
  176680. png_bytep sp, dp;
  176681. png_uint_32 i;
  176682. png_uint_32 row_width = row_info->width;
  176683. for (i = 0, sp = dp = row; i < row_width; i++)
  176684. {
  176685. sp+=3; dp = sp;
  176686. *(dp++) = (png_byte)(255 - *(sp++));
  176687. }
  176688. }
  176689. else
  176690. {
  176691. png_bytep sp, dp;
  176692. png_uint_32 i;
  176693. png_uint_32 row_width = row_info->width;
  176694. for (i = 0, sp = dp = row; i < row_width; i++)
  176695. {
  176696. sp+=6; dp = sp;
  176697. *(dp++) = (png_byte)(255 - *(sp++));
  176698. *(dp++) = (png_byte)(255 - *(sp++));
  176699. }
  176700. }
  176701. }
  176702. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  176703. {
  176704. if (row_info->bit_depth == 8)
  176705. {
  176706. png_bytep sp, dp;
  176707. png_uint_32 i;
  176708. png_uint_32 row_width = row_info->width;
  176709. for (i = 0, sp = dp = row; i < row_width; i++)
  176710. {
  176711. *(dp++) = *(sp++);
  176712. *(dp++) = (png_byte)(255 - *(sp++));
  176713. }
  176714. }
  176715. else
  176716. {
  176717. png_bytep sp, dp;
  176718. png_uint_32 i;
  176719. png_uint_32 row_width = row_info->width;
  176720. for (i = 0, sp = dp = row; i < row_width; i++)
  176721. {
  176722. sp+=2; dp = sp;
  176723. *(dp++) = (png_byte)(255 - *(sp++));
  176724. *(dp++) = (png_byte)(255 - *(sp++));
  176725. }
  176726. }
  176727. }
  176728. }
  176729. }
  176730. #endif
  176731. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176732. void /* PRIVATE */
  176733. png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
  176734. {
  176735. png_debug(1, "in png_do_write_intrapixel\n");
  176736. if (
  176737. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176738. row != NULL && row_info != NULL &&
  176739. #endif
  176740. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  176741. {
  176742. int bytes_per_pixel;
  176743. png_uint_32 row_width = row_info->width;
  176744. if (row_info->bit_depth == 8)
  176745. {
  176746. png_bytep rp;
  176747. png_uint_32 i;
  176748. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  176749. bytes_per_pixel = 3;
  176750. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176751. bytes_per_pixel = 4;
  176752. else
  176753. return;
  176754. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  176755. {
  176756. *(rp) = (png_byte)((*rp - *(rp+1))&0xff);
  176757. *(rp+2) = (png_byte)((*(rp+2) - *(rp+1))&0xff);
  176758. }
  176759. }
  176760. else if (row_info->bit_depth == 16)
  176761. {
  176762. png_bytep rp;
  176763. png_uint_32 i;
  176764. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  176765. bytes_per_pixel = 6;
  176766. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176767. bytes_per_pixel = 8;
  176768. else
  176769. return;
  176770. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  176771. {
  176772. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  176773. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  176774. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  176775. png_uint_32 red = (png_uint_32)((s0-s1) & 0xffffL);
  176776. png_uint_32 blue = (png_uint_32)((s2-s1) & 0xffffL);
  176777. *(rp ) = (png_byte)((red >> 8) & 0xff);
  176778. *(rp+1) = (png_byte)(red & 0xff);
  176779. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  176780. *(rp+5) = (png_byte)(blue & 0xff);
  176781. }
  176782. }
  176783. }
  176784. }
  176785. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  176786. #endif /* PNG_WRITE_SUPPORTED */
  176787. /*** End of inlined file: pngwtran.c ***/
  176788. /*** Start of inlined file: pngwutil.c ***/
  176789. #define PNG_INTERNAL
  176790. #ifdef PNG_WRITE_SUPPORTED
  176791. void PNGAPI
  176792. png_save_uint_32(png_bytep buf, png_uint_32 i)
  176793. {
  176794. buf[0] = (png_byte)((i >> 24) & 0xff);
  176795. buf[1] = (png_byte)((i >> 16) & 0xff);
  176796. buf[2] = (png_byte)((i >> 8) & 0xff);
  176797. buf[3] = (png_byte)(i & 0xff);
  176798. }
  176799. void PNGAPI
  176800. png_save_int_32(png_bytep buf, png_int_32 i)
  176801. {
  176802. buf[0] = (png_byte)((i >> 24) & 0xff);
  176803. buf[1] = (png_byte)((i >> 16) & 0xff);
  176804. buf[2] = (png_byte)((i >> 8) & 0xff);
  176805. buf[3] = (png_byte)(i & 0xff);
  176806. }
  176807. void PNGAPI
  176808. png_save_uint_16(png_bytep buf, unsigned int i)
  176809. {
  176810. buf[0] = (png_byte)((i >> 8) & 0xff);
  176811. buf[1] = (png_byte)(i & 0xff);
  176812. }
  176813. void PNGAPI
  176814. png_write_chunk(png_structp png_ptr, png_bytep chunk_name,
  176815. png_bytep data, png_size_t length)
  176816. {
  176817. if(png_ptr == NULL) return;
  176818. png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length);
  176819. png_write_chunk_data(png_ptr, data, length);
  176820. png_write_chunk_end(png_ptr);
  176821. }
  176822. void PNGAPI
  176823. png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
  176824. png_uint_32 length)
  176825. {
  176826. png_byte buf[4];
  176827. png_debug2(0, "Writing %s chunk (%lu bytes)\n", chunk_name, length);
  176828. if(png_ptr == NULL) return;
  176829. png_save_uint_32(buf, length);
  176830. png_write_data(png_ptr, buf, (png_size_t)4);
  176831. png_write_data(png_ptr, chunk_name, (png_size_t)4);
  176832. png_reset_crc(png_ptr);
  176833. png_calculate_crc(png_ptr, chunk_name, (png_size_t)4);
  176834. }
  176835. void PNGAPI
  176836. png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length)
  176837. {
  176838. if(png_ptr == NULL) return;
  176839. if (data != NULL && length > 0)
  176840. {
  176841. png_calculate_crc(png_ptr, data, length);
  176842. png_write_data(png_ptr, data, length);
  176843. }
  176844. }
  176845. void PNGAPI
  176846. png_write_chunk_end(png_structp png_ptr)
  176847. {
  176848. png_byte buf[4];
  176849. if(png_ptr == NULL) return;
  176850. png_save_uint_32(buf, png_ptr->crc);
  176851. png_write_data(png_ptr, buf, (png_size_t)4);
  176852. }
  176853. void /* PRIVATE */
  176854. png_write_sig(png_structp png_ptr)
  176855. {
  176856. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  176857. png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
  176858. (png_size_t)8 - png_ptr->sig_bytes);
  176859. if(png_ptr->sig_bytes < 3)
  176860. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  176861. }
  176862. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED)
  176863. typedef struct
  176864. {
  176865. char *input; /* the uncompressed input data */
  176866. int input_len; /* its length */
  176867. int num_output_ptr; /* number of output pointers used */
  176868. int max_output_ptr; /* size of output_ptr */
  176869. png_charpp output_ptr; /* array of pointers to output */
  176870. } compression_state;
  176871. static int /* PRIVATE */
  176872. png_text_compress(png_structp png_ptr,
  176873. png_charp text, png_size_t text_len, int compression,
  176874. compression_state *comp)
  176875. {
  176876. int ret;
  176877. comp->num_output_ptr = 0;
  176878. comp->max_output_ptr = 0;
  176879. comp->output_ptr = NULL;
  176880. comp->input = NULL;
  176881. comp->input_len = 0;
  176882. if (compression == PNG_TEXT_COMPRESSION_NONE)
  176883. {
  176884. comp->input = text;
  176885. comp->input_len = text_len;
  176886. return((int)text_len);
  176887. }
  176888. if (compression >= PNG_TEXT_COMPRESSION_LAST)
  176889. {
  176890. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  176891. char msg[50];
  176892. png_snprintf(msg, 50, "Unknown compression type %d", compression);
  176893. png_warning(png_ptr, msg);
  176894. #else
  176895. png_warning(png_ptr, "Unknown compression type");
  176896. #endif
  176897. }
  176898. png_ptr->zstream.avail_in = (uInt)text_len;
  176899. png_ptr->zstream.next_in = (Bytef *)text;
  176900. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176901. png_ptr->zstream.next_out = (Bytef *)png_ptr->zbuf;
  176902. do
  176903. {
  176904. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  176905. if (ret != Z_OK)
  176906. {
  176907. if (png_ptr->zstream.msg != NULL)
  176908. png_error(png_ptr, png_ptr->zstream.msg);
  176909. else
  176910. png_error(png_ptr, "zlib error");
  176911. }
  176912. if (!(png_ptr->zstream.avail_out))
  176913. {
  176914. if (comp->num_output_ptr >= comp->max_output_ptr)
  176915. {
  176916. int old_max;
  176917. old_max = comp->max_output_ptr;
  176918. comp->max_output_ptr = comp->num_output_ptr + 4;
  176919. if (comp->output_ptr != NULL)
  176920. {
  176921. png_charpp old_ptr;
  176922. old_ptr = comp->output_ptr;
  176923. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176924. (png_uint_32)(comp->max_output_ptr *
  176925. png_sizeof (png_charpp)));
  176926. png_memcpy(comp->output_ptr, old_ptr, old_max
  176927. * png_sizeof (png_charp));
  176928. png_free(png_ptr, old_ptr);
  176929. }
  176930. else
  176931. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176932. (png_uint_32)(comp->max_output_ptr *
  176933. png_sizeof (png_charp)));
  176934. }
  176935. comp->output_ptr[comp->num_output_ptr] = (png_charp)png_malloc(png_ptr,
  176936. (png_uint_32)png_ptr->zbuf_size);
  176937. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  176938. png_ptr->zbuf_size);
  176939. comp->num_output_ptr++;
  176940. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176941. png_ptr->zstream.next_out = png_ptr->zbuf;
  176942. }
  176943. } while (png_ptr->zstream.avail_in);
  176944. do
  176945. {
  176946. ret = deflate(&png_ptr->zstream, Z_FINISH);
  176947. if (ret == Z_OK)
  176948. {
  176949. if (!(png_ptr->zstream.avail_out))
  176950. {
  176951. if (comp->num_output_ptr >= comp->max_output_ptr)
  176952. {
  176953. int old_max;
  176954. old_max = comp->max_output_ptr;
  176955. comp->max_output_ptr = comp->num_output_ptr + 4;
  176956. if (comp->output_ptr != NULL)
  176957. {
  176958. png_charpp old_ptr;
  176959. old_ptr = comp->output_ptr;
  176960. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176961. (png_uint_32)(comp->max_output_ptr *
  176962. png_sizeof (png_charpp)));
  176963. png_memcpy(comp->output_ptr, old_ptr,
  176964. old_max * png_sizeof (png_charp));
  176965. png_free(png_ptr, old_ptr);
  176966. }
  176967. else
  176968. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176969. (png_uint_32)(comp->max_output_ptr *
  176970. png_sizeof (png_charp)));
  176971. }
  176972. comp->output_ptr[comp->num_output_ptr] =
  176973. (png_charp)png_malloc(png_ptr, (png_uint_32)png_ptr->zbuf_size);
  176974. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  176975. png_ptr->zbuf_size);
  176976. comp->num_output_ptr++;
  176977. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176978. png_ptr->zstream.next_out = png_ptr->zbuf;
  176979. }
  176980. }
  176981. else if (ret != Z_STREAM_END)
  176982. {
  176983. if (png_ptr->zstream.msg != NULL)
  176984. png_error(png_ptr, png_ptr->zstream.msg);
  176985. else
  176986. png_error(png_ptr, "zlib error");
  176987. }
  176988. } while (ret != Z_STREAM_END);
  176989. text_len = png_ptr->zbuf_size * comp->num_output_ptr;
  176990. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  176991. text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out;
  176992. return((int)text_len);
  176993. }
  176994. static void /* PRIVATE */
  176995. png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
  176996. {
  176997. int i;
  176998. if (comp->input)
  176999. {
  177000. png_write_chunk_data(png_ptr, (png_bytep)comp->input,
  177001. (png_size_t)comp->input_len);
  177002. return;
  177003. }
  177004. for (i = 0; i < comp->num_output_ptr; i++)
  177005. {
  177006. png_write_chunk_data(png_ptr,(png_bytep)comp->output_ptr[i],
  177007. png_ptr->zbuf_size);
  177008. png_free(png_ptr, comp->output_ptr[i]);
  177009. comp->output_ptr[i]=NULL;
  177010. }
  177011. if (comp->max_output_ptr != 0)
  177012. png_free(png_ptr, comp->output_ptr);
  177013. comp->output_ptr=NULL;
  177014. if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size)
  177015. png_write_chunk_data(png_ptr, png_ptr->zbuf,
  177016. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  177017. deflateReset(&png_ptr->zstream);
  177018. png_ptr->zstream.data_type = Z_BINARY;
  177019. }
  177020. #endif
  177021. void /* PRIVATE */
  177022. png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
  177023. int bit_depth, int color_type, int compression_type, int filter_type,
  177024. int interlace_type)
  177025. {
  177026. #ifdef PNG_USE_LOCAL_ARRAYS
  177027. PNG_IHDR;
  177028. #endif
  177029. png_byte buf[13]; /* buffer to store the IHDR info */
  177030. png_debug(1, "in png_write_IHDR\n");
  177031. switch (color_type)
  177032. {
  177033. case PNG_COLOR_TYPE_GRAY:
  177034. switch (bit_depth)
  177035. {
  177036. case 1:
  177037. case 2:
  177038. case 4:
  177039. case 8:
  177040. case 16: png_ptr->channels = 1; break;
  177041. default: png_error(png_ptr,"Invalid bit depth for grayscale image");
  177042. }
  177043. break;
  177044. case PNG_COLOR_TYPE_RGB:
  177045. if (bit_depth != 8 && bit_depth != 16)
  177046. png_error(png_ptr, "Invalid bit depth for RGB image");
  177047. png_ptr->channels = 3;
  177048. break;
  177049. case PNG_COLOR_TYPE_PALETTE:
  177050. switch (bit_depth)
  177051. {
  177052. case 1:
  177053. case 2:
  177054. case 4:
  177055. case 8: png_ptr->channels = 1; break;
  177056. default: png_error(png_ptr, "Invalid bit depth for paletted image");
  177057. }
  177058. break;
  177059. case PNG_COLOR_TYPE_GRAY_ALPHA:
  177060. if (bit_depth != 8 && bit_depth != 16)
  177061. png_error(png_ptr, "Invalid bit depth for grayscale+alpha image");
  177062. png_ptr->channels = 2;
  177063. break;
  177064. case PNG_COLOR_TYPE_RGB_ALPHA:
  177065. if (bit_depth != 8 && bit_depth != 16)
  177066. png_error(png_ptr, "Invalid bit depth for RGBA image");
  177067. png_ptr->channels = 4;
  177068. break;
  177069. default:
  177070. png_error(png_ptr, "Invalid image color type specified");
  177071. }
  177072. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177073. {
  177074. png_warning(png_ptr, "Invalid compression type specified");
  177075. compression_type = PNG_COMPRESSION_TYPE_BASE;
  177076. }
  177077. if (
  177078. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177079. !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  177080. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  177081. (color_type == PNG_COLOR_TYPE_RGB ||
  177082. color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
  177083. (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) &&
  177084. #endif
  177085. filter_type != PNG_FILTER_TYPE_BASE)
  177086. {
  177087. png_warning(png_ptr, "Invalid filter type specified");
  177088. filter_type = PNG_FILTER_TYPE_BASE;
  177089. }
  177090. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  177091. if (interlace_type != PNG_INTERLACE_NONE &&
  177092. interlace_type != PNG_INTERLACE_ADAM7)
  177093. {
  177094. png_warning(png_ptr, "Invalid interlace type specified");
  177095. interlace_type = PNG_INTERLACE_ADAM7;
  177096. }
  177097. #else
  177098. interlace_type=PNG_INTERLACE_NONE;
  177099. #endif
  177100. png_ptr->bit_depth = (png_byte)bit_depth;
  177101. png_ptr->color_type = (png_byte)color_type;
  177102. png_ptr->interlaced = (png_byte)interlace_type;
  177103. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177104. png_ptr->filter_type = (png_byte)filter_type;
  177105. #endif
  177106. png_ptr->compression_type = (png_byte)compression_type;
  177107. png_ptr->width = width;
  177108. png_ptr->height = height;
  177109. png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels);
  177110. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);
  177111. png_ptr->usr_width = png_ptr->width;
  177112. png_ptr->usr_bit_depth = png_ptr->bit_depth;
  177113. png_ptr->usr_channels = png_ptr->channels;
  177114. png_save_uint_32(buf, width);
  177115. png_save_uint_32(buf + 4, height);
  177116. buf[8] = (png_byte)bit_depth;
  177117. buf[9] = (png_byte)color_type;
  177118. buf[10] = (png_byte)compression_type;
  177119. buf[11] = (png_byte)filter_type;
  177120. buf[12] = (png_byte)interlace_type;
  177121. png_write_chunk(png_ptr, png_IHDR, buf, (png_size_t)13);
  177122. png_ptr->zstream.zalloc = png_zalloc;
  177123. png_ptr->zstream.zfree = png_zfree;
  177124. png_ptr->zstream.opaque = (voidpf)png_ptr;
  177125. if (!(png_ptr->do_filter))
  177126. {
  177127. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
  177128. png_ptr->bit_depth < 8)
  177129. png_ptr->do_filter = PNG_FILTER_NONE;
  177130. else
  177131. png_ptr->do_filter = PNG_ALL_FILTERS;
  177132. }
  177133. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY))
  177134. {
  177135. if (png_ptr->do_filter != PNG_FILTER_NONE)
  177136. png_ptr->zlib_strategy = Z_FILTERED;
  177137. else
  177138. png_ptr->zlib_strategy = Z_DEFAULT_STRATEGY;
  177139. }
  177140. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_LEVEL))
  177141. png_ptr->zlib_level = Z_DEFAULT_COMPRESSION;
  177142. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL))
  177143. png_ptr->zlib_mem_level = 8;
  177144. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS))
  177145. png_ptr->zlib_window_bits = 15;
  177146. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD))
  177147. png_ptr->zlib_method = 8;
  177148. if (deflateInit2(&png_ptr->zstream, png_ptr->zlib_level,
  177149. png_ptr->zlib_method, png_ptr->zlib_window_bits,
  177150. png_ptr->zlib_mem_level, png_ptr->zlib_strategy) != Z_OK)
  177151. png_error(png_ptr, "zlib failed to initialize compressor");
  177152. png_ptr->zstream.next_out = png_ptr->zbuf;
  177153. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177154. png_ptr->zstream.data_type = Z_BINARY;
  177155. png_ptr->mode = PNG_HAVE_IHDR;
  177156. }
  177157. void /* PRIVATE */
  177158. png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
  177159. {
  177160. #ifdef PNG_USE_LOCAL_ARRAYS
  177161. PNG_PLTE;
  177162. #endif
  177163. png_uint_32 i;
  177164. png_colorp pal_ptr;
  177165. png_byte buf[3];
  177166. png_debug(1, "in png_write_PLTE\n");
  177167. if ((
  177168. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177169. !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&
  177170. #endif
  177171. num_pal == 0) || num_pal > 256)
  177172. {
  177173. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  177174. {
  177175. png_error(png_ptr, "Invalid number of colors in palette");
  177176. }
  177177. else
  177178. {
  177179. png_warning(png_ptr, "Invalid number of colors in palette");
  177180. return;
  177181. }
  177182. }
  177183. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  177184. {
  177185. png_warning(png_ptr,
  177186. "Ignoring request to write a PLTE chunk in grayscale PNG");
  177187. return;
  177188. }
  177189. png_ptr->num_palette = (png_uint_16)num_pal;
  177190. png_debug1(3, "num_palette = %d\n", png_ptr->num_palette);
  177191. png_write_chunk_start(png_ptr, png_PLTE, num_pal * 3);
  177192. #ifndef PNG_NO_POINTER_INDEXING
  177193. for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
  177194. {
  177195. buf[0] = pal_ptr->red;
  177196. buf[1] = pal_ptr->green;
  177197. buf[2] = pal_ptr->blue;
  177198. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177199. }
  177200. #else
  177201. pal_ptr=palette;
  177202. for (i = 0; i < num_pal; i++)
  177203. {
  177204. buf[0] = pal_ptr[i].red;
  177205. buf[1] = pal_ptr[i].green;
  177206. buf[2] = pal_ptr[i].blue;
  177207. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177208. }
  177209. #endif
  177210. png_write_chunk_end(png_ptr);
  177211. png_ptr->mode |= PNG_HAVE_PLTE;
  177212. }
  177213. void /* PRIVATE */
  177214. png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
  177215. {
  177216. #ifdef PNG_USE_LOCAL_ARRAYS
  177217. PNG_IDAT;
  177218. #endif
  177219. png_debug(1, "in png_write_IDAT\n");
  177220. if (!(png_ptr->mode & PNG_HAVE_IDAT) &&
  177221. png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE)
  177222. {
  177223. unsigned int z_cmf = data[0]; /* zlib compression method and flags */
  177224. if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70)
  177225. {
  177226. if (length >= 2 &&
  177227. png_ptr->height < 16384 && png_ptr->width < 16384)
  177228. {
  177229. png_uint_32 uncompressed_idat_size = png_ptr->height *
  177230. ((png_ptr->width *
  177231. png_ptr->channels * png_ptr->bit_depth + 15) >> 3);
  177232. unsigned int z_cinfo = z_cmf >> 4;
  177233. unsigned int half_z_window_size = 1 << (z_cinfo + 7);
  177234. while (uncompressed_idat_size <= half_z_window_size &&
  177235. half_z_window_size >= 256)
  177236. {
  177237. z_cinfo--;
  177238. half_z_window_size >>= 1;
  177239. }
  177240. z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4);
  177241. if (data[0] != (png_byte)z_cmf)
  177242. {
  177243. data[0] = (png_byte)z_cmf;
  177244. data[1] &= 0xe0;
  177245. data[1] += (png_byte)(0x1f - ((z_cmf << 8) + data[1]) % 0x1f);
  177246. }
  177247. }
  177248. }
  177249. else
  177250. png_error(png_ptr,
  177251. "Invalid zlib compression method or flags in IDAT");
  177252. }
  177253. png_write_chunk(png_ptr, png_IDAT, data, length);
  177254. png_ptr->mode |= PNG_HAVE_IDAT;
  177255. }
  177256. void /* PRIVATE */
  177257. png_write_IEND(png_structp png_ptr)
  177258. {
  177259. #ifdef PNG_USE_LOCAL_ARRAYS
  177260. PNG_IEND;
  177261. #endif
  177262. png_debug(1, "in png_write_IEND\n");
  177263. png_write_chunk(png_ptr, png_IEND, png_bytep_NULL,
  177264. (png_size_t)0);
  177265. png_ptr->mode |= PNG_HAVE_IEND;
  177266. }
  177267. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  177268. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177269. void /* PRIVATE */
  177270. png_write_gAMA(png_structp png_ptr, double file_gamma)
  177271. {
  177272. #ifdef PNG_USE_LOCAL_ARRAYS
  177273. PNG_gAMA;
  177274. #endif
  177275. png_uint_32 igamma;
  177276. png_byte buf[4];
  177277. png_debug(1, "in png_write_gAMA\n");
  177278. igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5);
  177279. png_save_uint_32(buf, igamma);
  177280. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177281. }
  177282. #endif
  177283. #ifdef PNG_FIXED_POINT_SUPPORTED
  177284. void /* PRIVATE */
  177285. png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma)
  177286. {
  177287. #ifdef PNG_USE_LOCAL_ARRAYS
  177288. PNG_gAMA;
  177289. #endif
  177290. png_byte buf[4];
  177291. png_debug(1, "in png_write_gAMA\n");
  177292. png_save_uint_32(buf, (png_uint_32)file_gamma);
  177293. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177294. }
  177295. #endif
  177296. #endif
  177297. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  177298. void /* PRIVATE */
  177299. png_write_sRGB(png_structp png_ptr, int srgb_intent)
  177300. {
  177301. #ifdef PNG_USE_LOCAL_ARRAYS
  177302. PNG_sRGB;
  177303. #endif
  177304. png_byte buf[1];
  177305. png_debug(1, "in png_write_sRGB\n");
  177306. if(srgb_intent >= PNG_sRGB_INTENT_LAST)
  177307. png_warning(png_ptr,
  177308. "Invalid sRGB rendering intent specified");
  177309. buf[0]=(png_byte)srgb_intent;
  177310. png_write_chunk(png_ptr, png_sRGB, buf, (png_size_t)1);
  177311. }
  177312. #endif
  177313. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  177314. void /* PRIVATE */
  177315. png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
  177316. png_charp profile, int profile_len)
  177317. {
  177318. #ifdef PNG_USE_LOCAL_ARRAYS
  177319. PNG_iCCP;
  177320. #endif
  177321. png_size_t name_len;
  177322. png_charp new_name;
  177323. compression_state comp;
  177324. int embedded_profile_len = 0;
  177325. png_debug(1, "in png_write_iCCP\n");
  177326. comp.num_output_ptr = 0;
  177327. comp.max_output_ptr = 0;
  177328. comp.output_ptr = NULL;
  177329. comp.input = NULL;
  177330. comp.input_len = 0;
  177331. if (name == NULL || (name_len = png_check_keyword(png_ptr, name,
  177332. &new_name)) == 0)
  177333. {
  177334. png_warning(png_ptr, "Empty keyword in iCCP chunk");
  177335. return;
  177336. }
  177337. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177338. png_warning(png_ptr, "Unknown compression type in iCCP chunk");
  177339. if (profile == NULL)
  177340. profile_len = 0;
  177341. if (profile_len > 3)
  177342. embedded_profile_len =
  177343. ((*( (png_bytep)profile ))<<24) |
  177344. ((*( (png_bytep)profile+1))<<16) |
  177345. ((*( (png_bytep)profile+2))<< 8) |
  177346. ((*( (png_bytep)profile+3)) );
  177347. if (profile_len < embedded_profile_len)
  177348. {
  177349. png_warning(png_ptr,
  177350. "Embedded profile length too large in iCCP chunk");
  177351. return;
  177352. }
  177353. if (profile_len > embedded_profile_len)
  177354. {
  177355. png_warning(png_ptr,
  177356. "Truncating profile to actual length in iCCP chunk");
  177357. profile_len = embedded_profile_len;
  177358. }
  177359. if (profile_len)
  177360. profile_len = png_text_compress(png_ptr, profile, (png_size_t)profile_len,
  177361. PNG_COMPRESSION_TYPE_BASE, &comp);
  177362. png_write_chunk_start(png_ptr, png_iCCP,
  177363. (png_uint_32)name_len+profile_len+2);
  177364. new_name[name_len+1]=0x00;
  177365. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 2);
  177366. if (profile_len)
  177367. png_write_compressed_data_out(png_ptr, &comp);
  177368. png_write_chunk_end(png_ptr);
  177369. png_free(png_ptr, new_name);
  177370. }
  177371. #endif
  177372. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  177373. void /* PRIVATE */
  177374. png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
  177375. {
  177376. #ifdef PNG_USE_LOCAL_ARRAYS
  177377. PNG_sPLT;
  177378. #endif
  177379. png_size_t name_len;
  177380. png_charp new_name;
  177381. png_byte entrybuf[10];
  177382. int entry_size = (spalette->depth == 8 ? 6 : 10);
  177383. int palette_size = entry_size * spalette->nentries;
  177384. png_sPLT_entryp ep;
  177385. #ifdef PNG_NO_POINTER_INDEXING
  177386. int i;
  177387. #endif
  177388. png_debug(1, "in png_write_sPLT\n");
  177389. if (spalette->name == NULL || (name_len = png_check_keyword(png_ptr,
  177390. spalette->name, &new_name))==0)
  177391. {
  177392. png_warning(png_ptr, "Empty keyword in sPLT chunk");
  177393. return;
  177394. }
  177395. png_write_chunk_start(png_ptr, png_sPLT,
  177396. (png_uint_32)(name_len + 2 + palette_size));
  177397. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 1);
  177398. png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, 1);
  177399. #ifndef PNG_NO_POINTER_INDEXING
  177400. for (ep = spalette->entries; ep<spalette->entries+spalette->nentries; ep++)
  177401. {
  177402. if (spalette->depth == 8)
  177403. {
  177404. entrybuf[0] = (png_byte)ep->red;
  177405. entrybuf[1] = (png_byte)ep->green;
  177406. entrybuf[2] = (png_byte)ep->blue;
  177407. entrybuf[3] = (png_byte)ep->alpha;
  177408. png_save_uint_16(entrybuf + 4, ep->frequency);
  177409. }
  177410. else
  177411. {
  177412. png_save_uint_16(entrybuf + 0, ep->red);
  177413. png_save_uint_16(entrybuf + 2, ep->green);
  177414. png_save_uint_16(entrybuf + 4, ep->blue);
  177415. png_save_uint_16(entrybuf + 6, ep->alpha);
  177416. png_save_uint_16(entrybuf + 8, ep->frequency);
  177417. }
  177418. png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
  177419. }
  177420. #else
  177421. ep=spalette->entries;
  177422. for (i=0; i>spalette->nentries; i++)
  177423. {
  177424. if (spalette->depth == 8)
  177425. {
  177426. entrybuf[0] = (png_byte)ep[i].red;
  177427. entrybuf[1] = (png_byte)ep[i].green;
  177428. entrybuf[2] = (png_byte)ep[i].blue;
  177429. entrybuf[3] = (png_byte)ep[i].alpha;
  177430. png_save_uint_16(entrybuf + 4, ep[i].frequency);
  177431. }
  177432. else
  177433. {
  177434. png_save_uint_16(entrybuf + 0, ep[i].red);
  177435. png_save_uint_16(entrybuf + 2, ep[i].green);
  177436. png_save_uint_16(entrybuf + 4, ep[i].blue);
  177437. png_save_uint_16(entrybuf + 6, ep[i].alpha);
  177438. png_save_uint_16(entrybuf + 8, ep[i].frequency);
  177439. }
  177440. png_write_chunk_data(png_ptr, entrybuf, entry_size);
  177441. }
  177442. #endif
  177443. png_write_chunk_end(png_ptr);
  177444. png_free(png_ptr, new_name);
  177445. }
  177446. #endif
  177447. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  177448. void /* PRIVATE */
  177449. png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
  177450. {
  177451. #ifdef PNG_USE_LOCAL_ARRAYS
  177452. PNG_sBIT;
  177453. #endif
  177454. png_byte buf[4];
  177455. png_size_t size;
  177456. png_debug(1, "in png_write_sBIT\n");
  177457. if (color_type & PNG_COLOR_MASK_COLOR)
  177458. {
  177459. png_byte maxbits;
  177460. maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 :
  177461. png_ptr->usr_bit_depth);
  177462. if (sbit->red == 0 || sbit->red > maxbits ||
  177463. sbit->green == 0 || sbit->green > maxbits ||
  177464. sbit->blue == 0 || sbit->blue > maxbits)
  177465. {
  177466. png_warning(png_ptr, "Invalid sBIT depth specified");
  177467. return;
  177468. }
  177469. buf[0] = sbit->red;
  177470. buf[1] = sbit->green;
  177471. buf[2] = sbit->blue;
  177472. size = 3;
  177473. }
  177474. else
  177475. {
  177476. if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth)
  177477. {
  177478. png_warning(png_ptr, "Invalid sBIT depth specified");
  177479. return;
  177480. }
  177481. buf[0] = sbit->gray;
  177482. size = 1;
  177483. }
  177484. if (color_type & PNG_COLOR_MASK_ALPHA)
  177485. {
  177486. if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth)
  177487. {
  177488. png_warning(png_ptr, "Invalid sBIT depth specified");
  177489. return;
  177490. }
  177491. buf[size++] = sbit->alpha;
  177492. }
  177493. png_write_chunk(png_ptr, png_sBIT, buf, size);
  177494. }
  177495. #endif
  177496. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  177497. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177498. void /* PRIVATE */
  177499. png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
  177500. double red_x, double red_y, double green_x, double green_y,
  177501. double blue_x, double blue_y)
  177502. {
  177503. #ifdef PNG_USE_LOCAL_ARRAYS
  177504. PNG_cHRM;
  177505. #endif
  177506. png_byte buf[32];
  177507. png_uint_32 itemp;
  177508. png_debug(1, "in png_write_cHRM\n");
  177509. if (white_x < 0 || white_x > 0.8 || white_y < 0 || white_y > 0.8 ||
  177510. white_x + white_y > 1.0)
  177511. {
  177512. png_warning(png_ptr, "Invalid cHRM white point specified");
  177513. #if !defined(PNG_NO_CONSOLE_IO)
  177514. fprintf(stderr,"white_x=%f, white_y=%f\n",white_x, white_y);
  177515. #endif
  177516. return;
  177517. }
  177518. itemp = (png_uint_32)(white_x * 100000.0 + 0.5);
  177519. png_save_uint_32(buf, itemp);
  177520. itemp = (png_uint_32)(white_y * 100000.0 + 0.5);
  177521. png_save_uint_32(buf + 4, itemp);
  177522. if (red_x < 0 || red_y < 0 || red_x + red_y > 1.0)
  177523. {
  177524. png_warning(png_ptr, "Invalid cHRM red point specified");
  177525. return;
  177526. }
  177527. itemp = (png_uint_32)(red_x * 100000.0 + 0.5);
  177528. png_save_uint_32(buf + 8, itemp);
  177529. itemp = (png_uint_32)(red_y * 100000.0 + 0.5);
  177530. png_save_uint_32(buf + 12, itemp);
  177531. if (green_x < 0 || green_y < 0 || green_x + green_y > 1.0)
  177532. {
  177533. png_warning(png_ptr, "Invalid cHRM green point specified");
  177534. return;
  177535. }
  177536. itemp = (png_uint_32)(green_x * 100000.0 + 0.5);
  177537. png_save_uint_32(buf + 16, itemp);
  177538. itemp = (png_uint_32)(green_y * 100000.0 + 0.5);
  177539. png_save_uint_32(buf + 20, itemp);
  177540. if (blue_x < 0 || blue_y < 0 || blue_x + blue_y > 1.0)
  177541. {
  177542. png_warning(png_ptr, "Invalid cHRM blue point specified");
  177543. return;
  177544. }
  177545. itemp = (png_uint_32)(blue_x * 100000.0 + 0.5);
  177546. png_save_uint_32(buf + 24, itemp);
  177547. itemp = (png_uint_32)(blue_y * 100000.0 + 0.5);
  177548. png_save_uint_32(buf + 28, itemp);
  177549. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  177550. }
  177551. #endif
  177552. #ifdef PNG_FIXED_POINT_SUPPORTED
  177553. void /* PRIVATE */
  177554. png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
  177555. png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y,
  177556. png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x,
  177557. png_fixed_point blue_y)
  177558. {
  177559. #ifdef PNG_USE_LOCAL_ARRAYS
  177560. PNG_cHRM;
  177561. #endif
  177562. png_byte buf[32];
  177563. png_debug(1, "in png_write_cHRM\n");
  177564. if (white_x > 80000L || white_y > 80000L || white_x + white_y > 100000L)
  177565. {
  177566. png_warning(png_ptr, "Invalid fixed cHRM white point specified");
  177567. #if !defined(PNG_NO_CONSOLE_IO)
  177568. fprintf(stderr,"white_x=%ld, white_y=%ld\n",white_x, white_y);
  177569. #endif
  177570. return;
  177571. }
  177572. png_save_uint_32(buf, (png_uint_32)white_x);
  177573. png_save_uint_32(buf + 4, (png_uint_32)white_y);
  177574. if (red_x + red_y > 100000L)
  177575. {
  177576. png_warning(png_ptr, "Invalid cHRM fixed red point specified");
  177577. return;
  177578. }
  177579. png_save_uint_32(buf + 8, (png_uint_32)red_x);
  177580. png_save_uint_32(buf + 12, (png_uint_32)red_y);
  177581. if (green_x + green_y > 100000L)
  177582. {
  177583. png_warning(png_ptr, "Invalid fixed cHRM green point specified");
  177584. return;
  177585. }
  177586. png_save_uint_32(buf + 16, (png_uint_32)green_x);
  177587. png_save_uint_32(buf + 20, (png_uint_32)green_y);
  177588. if (blue_x + blue_y > 100000L)
  177589. {
  177590. png_warning(png_ptr, "Invalid fixed cHRM blue point specified");
  177591. return;
  177592. }
  177593. png_save_uint_32(buf + 24, (png_uint_32)blue_x);
  177594. png_save_uint_32(buf + 28, (png_uint_32)blue_y);
  177595. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  177596. }
  177597. #endif
  177598. #endif
  177599. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  177600. void /* PRIVATE */
  177601. png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
  177602. int num_trans, int color_type)
  177603. {
  177604. #ifdef PNG_USE_LOCAL_ARRAYS
  177605. PNG_tRNS;
  177606. #endif
  177607. png_byte buf[6];
  177608. png_debug(1, "in png_write_tRNS\n");
  177609. if (color_type == PNG_COLOR_TYPE_PALETTE)
  177610. {
  177611. if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)
  177612. {
  177613. png_warning(png_ptr,"Invalid number of transparent colors specified");
  177614. return;
  177615. }
  177616. png_write_chunk(png_ptr, png_tRNS, trans, (png_size_t)num_trans);
  177617. }
  177618. else if (color_type == PNG_COLOR_TYPE_GRAY)
  177619. {
  177620. if(tran->gray >= (1 << png_ptr->bit_depth))
  177621. {
  177622. png_warning(png_ptr,
  177623. "Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
  177624. return;
  177625. }
  177626. png_save_uint_16(buf, tran->gray);
  177627. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)2);
  177628. }
  177629. else if (color_type == PNG_COLOR_TYPE_RGB)
  177630. {
  177631. png_save_uint_16(buf, tran->red);
  177632. png_save_uint_16(buf + 2, tran->green);
  177633. png_save_uint_16(buf + 4, tran->blue);
  177634. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  177635. {
  177636. png_warning(png_ptr,
  177637. "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
  177638. return;
  177639. }
  177640. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)6);
  177641. }
  177642. else
  177643. {
  177644. png_warning(png_ptr, "Can't write tRNS with an alpha channel");
  177645. }
  177646. }
  177647. #endif
  177648. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  177649. void /* PRIVATE */
  177650. png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
  177651. {
  177652. #ifdef PNG_USE_LOCAL_ARRAYS
  177653. PNG_bKGD;
  177654. #endif
  177655. png_byte buf[6];
  177656. png_debug(1, "in png_write_bKGD\n");
  177657. if (color_type == PNG_COLOR_TYPE_PALETTE)
  177658. {
  177659. if (
  177660. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177661. (png_ptr->num_palette ||
  177662. (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) &&
  177663. #endif
  177664. back->index > png_ptr->num_palette)
  177665. {
  177666. png_warning(png_ptr, "Invalid background palette index");
  177667. return;
  177668. }
  177669. buf[0] = back->index;
  177670. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)1);
  177671. }
  177672. else if (color_type & PNG_COLOR_MASK_COLOR)
  177673. {
  177674. png_save_uint_16(buf, back->red);
  177675. png_save_uint_16(buf + 2, back->green);
  177676. png_save_uint_16(buf + 4, back->blue);
  177677. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  177678. {
  177679. png_warning(png_ptr,
  177680. "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
  177681. return;
  177682. }
  177683. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)6);
  177684. }
  177685. else
  177686. {
  177687. if(back->gray >= (1 << png_ptr->bit_depth))
  177688. {
  177689. png_warning(png_ptr,
  177690. "Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
  177691. return;
  177692. }
  177693. png_save_uint_16(buf, back->gray);
  177694. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)2);
  177695. }
  177696. }
  177697. #endif
  177698. #if defined(PNG_WRITE_hIST_SUPPORTED)
  177699. void /* PRIVATE */
  177700. png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
  177701. {
  177702. #ifdef PNG_USE_LOCAL_ARRAYS
  177703. PNG_hIST;
  177704. #endif
  177705. int i;
  177706. png_byte buf[3];
  177707. png_debug(1, "in png_write_hIST\n");
  177708. if (num_hist > (int)png_ptr->num_palette)
  177709. {
  177710. png_debug2(3, "num_hist = %d, num_palette = %d\n", num_hist,
  177711. png_ptr->num_palette);
  177712. png_warning(png_ptr, "Invalid number of histogram entries specified");
  177713. return;
  177714. }
  177715. png_write_chunk_start(png_ptr, png_hIST, (png_uint_32)(num_hist * 2));
  177716. for (i = 0; i < num_hist; i++)
  177717. {
  177718. png_save_uint_16(buf, hist[i]);
  177719. png_write_chunk_data(png_ptr, buf, (png_size_t)2);
  177720. }
  177721. png_write_chunk_end(png_ptr);
  177722. }
  177723. #endif
  177724. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  177725. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  177726. png_size_t /* PRIVATE */
  177727. png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
  177728. {
  177729. png_size_t key_len;
  177730. png_charp kp, dp;
  177731. int kflag;
  177732. int kwarn=0;
  177733. png_debug(1, "in png_check_keyword\n");
  177734. *new_key = NULL;
  177735. if (key == NULL || (key_len = png_strlen(key)) == 0)
  177736. {
  177737. png_warning(png_ptr, "zero length keyword");
  177738. return ((png_size_t)0);
  177739. }
  177740. png_debug1(2, "Keyword to be checked is '%s'\n", key);
  177741. *new_key = (png_charp)png_malloc_warn(png_ptr, (png_uint_32)(key_len + 2));
  177742. if (*new_key == NULL)
  177743. {
  177744. png_warning(png_ptr, "Out of memory while procesing keyword");
  177745. return ((png_size_t)0);
  177746. }
  177747. for (kp = key, dp = *new_key; *kp != '\0'; kp++, dp++)
  177748. {
  177749. if ((png_byte)*kp < 0x20 ||
  177750. ((png_byte)*kp > 0x7E && (png_byte)*kp < 0xA1))
  177751. {
  177752. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  177753. char msg[40];
  177754. png_snprintf(msg, 40,
  177755. "invalid keyword character 0x%02X", (png_byte)*kp);
  177756. png_warning(png_ptr, msg);
  177757. #else
  177758. png_warning(png_ptr, "invalid character in keyword");
  177759. #endif
  177760. *dp = ' ';
  177761. }
  177762. else
  177763. {
  177764. *dp = *kp;
  177765. }
  177766. }
  177767. *dp = '\0';
  177768. kp = *new_key + key_len - 1;
  177769. if (*kp == ' ')
  177770. {
  177771. png_warning(png_ptr, "trailing spaces removed from keyword");
  177772. while (*kp == ' ')
  177773. {
  177774. *(kp--) = '\0';
  177775. key_len--;
  177776. }
  177777. }
  177778. kp = *new_key;
  177779. if (*kp == ' ')
  177780. {
  177781. png_warning(png_ptr, "leading spaces removed from keyword");
  177782. while (*kp == ' ')
  177783. {
  177784. kp++;
  177785. key_len--;
  177786. }
  177787. }
  177788. png_debug1(2, "Checking for multiple internal spaces in '%s'\n", kp);
  177789. for (kflag = 0, dp = *new_key; *kp != '\0'; kp++)
  177790. {
  177791. if (*kp == ' ' && kflag == 0)
  177792. {
  177793. *(dp++) = *kp;
  177794. kflag = 1;
  177795. }
  177796. else if (*kp == ' ')
  177797. {
  177798. key_len--;
  177799. kwarn=1;
  177800. }
  177801. else
  177802. {
  177803. *(dp++) = *kp;
  177804. kflag = 0;
  177805. }
  177806. }
  177807. *dp = '\0';
  177808. if(kwarn)
  177809. png_warning(png_ptr, "extra interior spaces removed from keyword");
  177810. if (key_len == 0)
  177811. {
  177812. png_free(png_ptr, *new_key);
  177813. *new_key=NULL;
  177814. png_warning(png_ptr, "Zero length keyword");
  177815. }
  177816. if (key_len > 79)
  177817. {
  177818. png_warning(png_ptr, "keyword length must be 1 - 79 characters");
  177819. new_key[79] = '\0';
  177820. key_len = 79;
  177821. }
  177822. return (key_len);
  177823. }
  177824. #endif
  177825. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  177826. void /* PRIVATE */
  177827. png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
  177828. png_size_t text_len)
  177829. {
  177830. #ifdef PNG_USE_LOCAL_ARRAYS
  177831. PNG_tEXt;
  177832. #endif
  177833. png_size_t key_len;
  177834. png_charp new_key;
  177835. png_debug(1, "in png_write_tEXt\n");
  177836. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  177837. {
  177838. png_warning(png_ptr, "Empty keyword in tEXt chunk");
  177839. return;
  177840. }
  177841. if (text == NULL || *text == '\0')
  177842. text_len = 0;
  177843. else
  177844. text_len = png_strlen(text);
  177845. png_write_chunk_start(png_ptr, png_tEXt, (png_uint_32)key_len+text_len+1);
  177846. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  177847. if (text_len)
  177848. png_write_chunk_data(png_ptr, (png_bytep)text, text_len);
  177849. png_write_chunk_end(png_ptr);
  177850. png_free(png_ptr, new_key);
  177851. }
  177852. #endif
  177853. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  177854. void /* PRIVATE */
  177855. png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
  177856. png_size_t text_len, int compression)
  177857. {
  177858. #ifdef PNG_USE_LOCAL_ARRAYS
  177859. PNG_zTXt;
  177860. #endif
  177861. png_size_t key_len;
  177862. char buf[1];
  177863. png_charp new_key;
  177864. compression_state comp;
  177865. png_debug(1, "in png_write_zTXt\n");
  177866. comp.num_output_ptr = 0;
  177867. comp.max_output_ptr = 0;
  177868. comp.output_ptr = NULL;
  177869. comp.input = NULL;
  177870. comp.input_len = 0;
  177871. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  177872. {
  177873. png_warning(png_ptr, "Empty keyword in zTXt chunk");
  177874. return;
  177875. }
  177876. if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE)
  177877. {
  177878. png_write_tEXt(png_ptr, new_key, text, (png_size_t)0);
  177879. png_free(png_ptr, new_key);
  177880. return;
  177881. }
  177882. text_len = png_strlen(text);
  177883. text_len = png_text_compress(png_ptr, text, text_len, compression,
  177884. &comp);
  177885. png_write_chunk_start(png_ptr, png_zTXt, (png_uint_32)
  177886. (key_len+text_len+2));
  177887. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  177888. png_free(png_ptr, new_key);
  177889. buf[0] = (png_byte)compression;
  177890. png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1);
  177891. png_write_compressed_data_out(png_ptr, &comp);
  177892. png_write_chunk_end(png_ptr);
  177893. }
  177894. #endif
  177895. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  177896. void /* PRIVATE */
  177897. png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
  177898. png_charp lang, png_charp lang_key, png_charp text)
  177899. {
  177900. #ifdef PNG_USE_LOCAL_ARRAYS
  177901. PNG_iTXt;
  177902. #endif
  177903. png_size_t lang_len, key_len, lang_key_len, text_len;
  177904. png_charp new_lang, new_key;
  177905. png_byte cbuf[2];
  177906. compression_state comp;
  177907. png_debug(1, "in png_write_iTXt\n");
  177908. comp.num_output_ptr = 0;
  177909. comp.max_output_ptr = 0;
  177910. comp.output_ptr = NULL;
  177911. comp.input = NULL;
  177912. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  177913. {
  177914. png_warning(png_ptr, "Empty keyword in iTXt chunk");
  177915. return;
  177916. }
  177917. if (lang == NULL || (lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0)
  177918. {
  177919. png_warning(png_ptr, "Empty language field in iTXt chunk");
  177920. new_lang = NULL;
  177921. lang_len = 0;
  177922. }
  177923. if (lang_key == NULL)
  177924. lang_key_len = 0;
  177925. else
  177926. lang_key_len = png_strlen(lang_key);
  177927. if (text == NULL)
  177928. text_len = 0;
  177929. else
  177930. text_len = png_strlen(text);
  177931. text_len = png_text_compress(png_ptr, text, text_len, compression-2,
  177932. &comp);
  177933. png_write_chunk_start(png_ptr, png_iTXt,
  177934. (png_uint_32)(
  177935. 5 /* comp byte, comp flag, terminators for key, lang and lang_key */
  177936. + key_len
  177937. + lang_len
  177938. + lang_key_len
  177939. + text_len));
  177940. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  177941. if (compression == PNG_ITXT_COMPRESSION_NONE || \
  177942. compression == PNG_TEXT_COMPRESSION_NONE)
  177943. cbuf[0] = 0;
  177944. else /* compression == PNG_ITXT_COMPRESSION_zTXt */
  177945. cbuf[0] = 1;
  177946. cbuf[1] = 0;
  177947. png_write_chunk_data(png_ptr, cbuf, 2);
  177948. cbuf[0] = 0;
  177949. png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf), lang_len + 1);
  177950. png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf), lang_key_len + 1);
  177951. png_write_compressed_data_out(png_ptr, &comp);
  177952. png_write_chunk_end(png_ptr);
  177953. png_free(png_ptr, new_key);
  177954. if (new_lang)
  177955. png_free(png_ptr, new_lang);
  177956. }
  177957. #endif
  177958. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  177959. void /* PRIVATE */
  177960. png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
  177961. int unit_type)
  177962. {
  177963. #ifdef PNG_USE_LOCAL_ARRAYS
  177964. PNG_oFFs;
  177965. #endif
  177966. png_byte buf[9];
  177967. png_debug(1, "in png_write_oFFs\n");
  177968. if (unit_type >= PNG_OFFSET_LAST)
  177969. png_warning(png_ptr, "Unrecognized unit type for oFFs chunk");
  177970. png_save_int_32(buf, x_offset);
  177971. png_save_int_32(buf + 4, y_offset);
  177972. buf[8] = (png_byte)unit_type;
  177973. png_write_chunk(png_ptr, png_oFFs, buf, (png_size_t)9);
  177974. }
  177975. #endif
  177976. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  177977. void /* PRIVATE */
  177978. png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
  177979. png_int_32 X1, int type, int nparams, png_charp units, png_charpp params)
  177980. {
  177981. #ifdef PNG_USE_LOCAL_ARRAYS
  177982. PNG_pCAL;
  177983. #endif
  177984. png_size_t purpose_len, units_len, total_len;
  177985. png_uint_32p params_len;
  177986. png_byte buf[10];
  177987. png_charp new_purpose;
  177988. int i;
  177989. png_debug1(1, "in png_write_pCAL (%d parameters)\n", nparams);
  177990. if (type >= PNG_EQUATION_LAST)
  177991. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  177992. purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1;
  177993. png_debug1(3, "pCAL purpose length = %d\n", (int)purpose_len);
  177994. units_len = png_strlen(units) + (nparams == 0 ? 0 : 1);
  177995. png_debug1(3, "pCAL units length = %d\n", (int)units_len);
  177996. total_len = purpose_len + units_len + 10;
  177997. params_len = (png_uint_32p)png_malloc(png_ptr, (png_uint_32)(nparams
  177998. *png_sizeof(png_uint_32)));
  177999. for (i = 0; i < nparams; i++)
  178000. {
  178001. params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
  178002. png_debug2(3, "pCAL parameter %d length = %lu\n", i, params_len[i]);
  178003. total_len += (png_size_t)params_len[i];
  178004. }
  178005. png_debug1(3, "pCAL total length = %d\n", (int)total_len);
  178006. png_write_chunk_start(png_ptr, png_pCAL, (png_uint_32)total_len);
  178007. png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len);
  178008. png_save_int_32(buf, X0);
  178009. png_save_int_32(buf + 4, X1);
  178010. buf[8] = (png_byte)type;
  178011. buf[9] = (png_byte)nparams;
  178012. png_write_chunk_data(png_ptr, buf, (png_size_t)10);
  178013. png_write_chunk_data(png_ptr, (png_bytep)units, (png_size_t)units_len);
  178014. png_free(png_ptr, new_purpose);
  178015. for (i = 0; i < nparams; i++)
  178016. {
  178017. png_write_chunk_data(png_ptr, (png_bytep)params[i],
  178018. (png_size_t)params_len[i]);
  178019. }
  178020. png_free(png_ptr, params_len);
  178021. png_write_chunk_end(png_ptr);
  178022. }
  178023. #endif
  178024. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  178025. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  178026. void /* PRIVATE */
  178027. png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
  178028. {
  178029. #ifdef PNG_USE_LOCAL_ARRAYS
  178030. PNG_sCAL;
  178031. #endif
  178032. char buf[64];
  178033. png_size_t total_len;
  178034. png_debug(1, "in png_write_sCAL\n");
  178035. buf[0] = (char)unit;
  178036. #if defined(_WIN32_WCE)
  178037. {
  178038. wchar_t wc_buf[32];
  178039. size_t wc_len;
  178040. swprintf(wc_buf, TEXT("%12.12e"), width);
  178041. wc_len = wcslen(wc_buf);
  178042. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + 1, wc_len, NULL, NULL);
  178043. total_len = wc_len + 2;
  178044. swprintf(wc_buf, TEXT("%12.12e"), height);
  178045. wc_len = wcslen(wc_buf);
  178046. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + total_len, wc_len,
  178047. NULL, NULL);
  178048. total_len += wc_len;
  178049. }
  178050. #else
  178051. png_snprintf(buf + 1, 63, "%12.12e", width);
  178052. total_len = 1 + png_strlen(buf + 1) + 1;
  178053. png_snprintf(buf + total_len, 64-total_len, "%12.12e", height);
  178054. total_len += png_strlen(buf + total_len);
  178055. #endif
  178056. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178057. png_write_chunk(png_ptr, png_sCAL, (png_bytep)buf, total_len);
  178058. }
  178059. #else
  178060. #ifdef PNG_FIXED_POINT_SUPPORTED
  178061. void /* PRIVATE */
  178062. png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width,
  178063. png_charp height)
  178064. {
  178065. #ifdef PNG_USE_LOCAL_ARRAYS
  178066. PNG_sCAL;
  178067. #endif
  178068. png_byte buf[64];
  178069. png_size_t wlen, hlen, total_len;
  178070. png_debug(1, "in png_write_sCAL_s\n");
  178071. wlen = png_strlen(width);
  178072. hlen = png_strlen(height);
  178073. total_len = wlen + hlen + 2;
  178074. if (total_len > 64)
  178075. {
  178076. png_warning(png_ptr, "Can't write sCAL (buffer too small)");
  178077. return;
  178078. }
  178079. buf[0] = (png_byte)unit;
  178080. png_memcpy(buf + 1, width, wlen + 1); /* append the '\0' here */
  178081. png_memcpy(buf + wlen + 2, height, hlen); /* do NOT append the '\0' here */
  178082. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178083. png_write_chunk(png_ptr, png_sCAL, buf, total_len);
  178084. }
  178085. #endif
  178086. #endif
  178087. #endif
  178088. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  178089. void /* PRIVATE */
  178090. png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
  178091. png_uint_32 y_pixels_per_unit,
  178092. int unit_type)
  178093. {
  178094. #ifdef PNG_USE_LOCAL_ARRAYS
  178095. PNG_pHYs;
  178096. #endif
  178097. png_byte buf[9];
  178098. png_debug(1, "in png_write_pHYs\n");
  178099. if (unit_type >= PNG_RESOLUTION_LAST)
  178100. png_warning(png_ptr, "Unrecognized unit type for pHYs chunk");
  178101. png_save_uint_32(buf, x_pixels_per_unit);
  178102. png_save_uint_32(buf + 4, y_pixels_per_unit);
  178103. buf[8] = (png_byte)unit_type;
  178104. png_write_chunk(png_ptr, png_pHYs, buf, (png_size_t)9);
  178105. }
  178106. #endif
  178107. #if defined(PNG_WRITE_tIME_SUPPORTED)
  178108. void /* PRIVATE */
  178109. png_write_tIME(png_structp png_ptr, png_timep mod_time)
  178110. {
  178111. #ifdef PNG_USE_LOCAL_ARRAYS
  178112. PNG_tIME;
  178113. #endif
  178114. png_byte buf[7];
  178115. png_debug(1, "in png_write_tIME\n");
  178116. if (mod_time->month > 12 || mod_time->month < 1 ||
  178117. mod_time->day > 31 || mod_time->day < 1 ||
  178118. mod_time->hour > 23 || mod_time->second > 60)
  178119. {
  178120. png_warning(png_ptr, "Invalid time specified for tIME chunk");
  178121. return;
  178122. }
  178123. png_save_uint_16(buf, mod_time->year);
  178124. buf[2] = mod_time->month;
  178125. buf[3] = mod_time->day;
  178126. buf[4] = mod_time->hour;
  178127. buf[5] = mod_time->minute;
  178128. buf[6] = mod_time->second;
  178129. png_write_chunk(png_ptr, png_tIME, buf, (png_size_t)7);
  178130. }
  178131. #endif
  178132. void /* PRIVATE */
  178133. png_write_start_row(png_structp png_ptr)
  178134. {
  178135. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178136. #ifdef PNG_USE_LOCAL_ARRAYS
  178137. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178138. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178139. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178140. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178141. #endif
  178142. #endif
  178143. png_size_t buf_size;
  178144. png_debug(1, "in png_write_start_row\n");
  178145. buf_size = (png_size_t)(PNG_ROWBYTES(
  178146. png_ptr->usr_channels*png_ptr->usr_bit_depth,png_ptr->width)+1);
  178147. png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178148. png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
  178149. #ifndef PNG_NO_WRITE_FILTERING
  178150. if (png_ptr->do_filter & PNG_FILTER_SUB)
  178151. {
  178152. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  178153. (png_ptr->rowbytes + 1));
  178154. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  178155. }
  178156. if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
  178157. {
  178158. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178159. png_memset(png_ptr->prev_row, 0, buf_size);
  178160. if (png_ptr->do_filter & PNG_FILTER_UP)
  178161. {
  178162. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  178163. (png_ptr->rowbytes + 1));
  178164. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  178165. }
  178166. if (png_ptr->do_filter & PNG_FILTER_AVG)
  178167. {
  178168. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  178169. (png_ptr->rowbytes + 1));
  178170. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  178171. }
  178172. if (png_ptr->do_filter & PNG_FILTER_PAETH)
  178173. {
  178174. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  178175. (png_ptr->rowbytes + 1));
  178176. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  178177. }
  178178. #endif /* PNG_NO_WRITE_FILTERING */
  178179. }
  178180. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178181. if (png_ptr->interlaced)
  178182. {
  178183. if (!(png_ptr->transformations & PNG_INTERLACE))
  178184. {
  178185. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  178186. png_pass_ystart[0]) / png_pass_yinc[0];
  178187. png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 -
  178188. png_pass_start[0]) / png_pass_inc[0];
  178189. }
  178190. else
  178191. {
  178192. png_ptr->num_rows = png_ptr->height;
  178193. png_ptr->usr_width = png_ptr->width;
  178194. }
  178195. }
  178196. else
  178197. #endif
  178198. {
  178199. png_ptr->num_rows = png_ptr->height;
  178200. png_ptr->usr_width = png_ptr->width;
  178201. }
  178202. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178203. png_ptr->zstream.next_out = png_ptr->zbuf;
  178204. }
  178205. void /* PRIVATE */
  178206. png_write_finish_row(png_structp png_ptr)
  178207. {
  178208. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178209. #ifdef PNG_USE_LOCAL_ARRAYS
  178210. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178211. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178212. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178213. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178214. #endif
  178215. #endif
  178216. int ret;
  178217. png_debug(1, "in png_write_finish_row\n");
  178218. png_ptr->row_number++;
  178219. if (png_ptr->row_number < png_ptr->num_rows)
  178220. return;
  178221. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178222. if (png_ptr->interlaced)
  178223. {
  178224. png_ptr->row_number = 0;
  178225. if (png_ptr->transformations & PNG_INTERLACE)
  178226. {
  178227. png_ptr->pass++;
  178228. }
  178229. else
  178230. {
  178231. do
  178232. {
  178233. png_ptr->pass++;
  178234. if (png_ptr->pass >= 7)
  178235. break;
  178236. png_ptr->usr_width = (png_ptr->width +
  178237. png_pass_inc[png_ptr->pass] - 1 -
  178238. png_pass_start[png_ptr->pass]) /
  178239. png_pass_inc[png_ptr->pass];
  178240. png_ptr->num_rows = (png_ptr->height +
  178241. png_pass_yinc[png_ptr->pass] - 1 -
  178242. png_pass_ystart[png_ptr->pass]) /
  178243. png_pass_yinc[png_ptr->pass];
  178244. if (png_ptr->transformations & PNG_INTERLACE)
  178245. break;
  178246. } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);
  178247. }
  178248. if (png_ptr->pass < 7)
  178249. {
  178250. if (png_ptr->prev_row != NULL)
  178251. png_memset(png_ptr->prev_row, 0,
  178252. (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*
  178253. png_ptr->usr_bit_depth,png_ptr->width))+1);
  178254. return;
  178255. }
  178256. }
  178257. #endif
  178258. do
  178259. {
  178260. ret = deflate(&png_ptr->zstream, Z_FINISH);
  178261. if (ret == Z_OK)
  178262. {
  178263. if (!(png_ptr->zstream.avail_out))
  178264. {
  178265. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  178266. png_ptr->zstream.next_out = png_ptr->zbuf;
  178267. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178268. }
  178269. }
  178270. else if (ret != Z_STREAM_END)
  178271. {
  178272. if (png_ptr->zstream.msg != NULL)
  178273. png_error(png_ptr, png_ptr->zstream.msg);
  178274. else
  178275. png_error(png_ptr, "zlib error");
  178276. }
  178277. } while (ret != Z_STREAM_END);
  178278. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  178279. {
  178280. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size -
  178281. png_ptr->zstream.avail_out);
  178282. }
  178283. deflateReset(&png_ptr->zstream);
  178284. png_ptr->zstream.data_type = Z_BINARY;
  178285. }
  178286. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  178287. void /* PRIVATE */
  178288. png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
  178289. {
  178290. #ifdef PNG_USE_LOCAL_ARRAYS
  178291. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178292. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178293. #endif
  178294. png_debug(1, "in png_do_write_interlace\n");
  178295. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  178296. if (row != NULL && row_info != NULL && pass < 6)
  178297. #else
  178298. if (pass < 6)
  178299. #endif
  178300. {
  178301. switch (row_info->pixel_depth)
  178302. {
  178303. case 1:
  178304. {
  178305. png_bytep sp;
  178306. png_bytep dp;
  178307. int shift;
  178308. int d;
  178309. int value;
  178310. png_uint_32 i;
  178311. png_uint_32 row_width = row_info->width;
  178312. dp = row;
  178313. d = 0;
  178314. shift = 7;
  178315. for (i = png_pass_start[pass]; i < row_width;
  178316. i += png_pass_inc[pass])
  178317. {
  178318. sp = row + (png_size_t)(i >> 3);
  178319. value = (int)(*sp >> (7 - (int)(i & 0x07))) & 0x01;
  178320. d |= (value << shift);
  178321. if (shift == 0)
  178322. {
  178323. shift = 7;
  178324. *dp++ = (png_byte)d;
  178325. d = 0;
  178326. }
  178327. else
  178328. shift--;
  178329. }
  178330. if (shift != 7)
  178331. *dp = (png_byte)d;
  178332. break;
  178333. }
  178334. case 2:
  178335. {
  178336. png_bytep sp;
  178337. png_bytep dp;
  178338. int shift;
  178339. int d;
  178340. int value;
  178341. png_uint_32 i;
  178342. png_uint_32 row_width = row_info->width;
  178343. dp = row;
  178344. shift = 6;
  178345. d = 0;
  178346. for (i = png_pass_start[pass]; i < row_width;
  178347. i += png_pass_inc[pass])
  178348. {
  178349. sp = row + (png_size_t)(i >> 2);
  178350. value = (*sp >> ((3 - (int)(i & 0x03)) << 1)) & 0x03;
  178351. d |= (value << shift);
  178352. if (shift == 0)
  178353. {
  178354. shift = 6;
  178355. *dp++ = (png_byte)d;
  178356. d = 0;
  178357. }
  178358. else
  178359. shift -= 2;
  178360. }
  178361. if (shift != 6)
  178362. *dp = (png_byte)d;
  178363. break;
  178364. }
  178365. case 4:
  178366. {
  178367. png_bytep sp;
  178368. png_bytep dp;
  178369. int shift;
  178370. int d;
  178371. int value;
  178372. png_uint_32 i;
  178373. png_uint_32 row_width = row_info->width;
  178374. dp = row;
  178375. shift = 4;
  178376. d = 0;
  178377. for (i = png_pass_start[pass]; i < row_width;
  178378. i += png_pass_inc[pass])
  178379. {
  178380. sp = row + (png_size_t)(i >> 1);
  178381. value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f;
  178382. d |= (value << shift);
  178383. if (shift == 0)
  178384. {
  178385. shift = 4;
  178386. *dp++ = (png_byte)d;
  178387. d = 0;
  178388. }
  178389. else
  178390. shift -= 4;
  178391. }
  178392. if (shift != 4)
  178393. *dp = (png_byte)d;
  178394. break;
  178395. }
  178396. default:
  178397. {
  178398. png_bytep sp;
  178399. png_bytep dp;
  178400. png_uint_32 i;
  178401. png_uint_32 row_width = row_info->width;
  178402. png_size_t pixel_bytes;
  178403. dp = row;
  178404. pixel_bytes = (row_info->pixel_depth >> 3);
  178405. for (i = png_pass_start[pass]; i < row_width;
  178406. i += png_pass_inc[pass])
  178407. {
  178408. sp = row + (png_size_t)i * pixel_bytes;
  178409. if (dp != sp)
  178410. png_memcpy(dp, sp, pixel_bytes);
  178411. dp += pixel_bytes;
  178412. }
  178413. break;
  178414. }
  178415. }
  178416. row_info->width = (row_info->width +
  178417. png_pass_inc[pass] - 1 -
  178418. png_pass_start[pass]) /
  178419. png_pass_inc[pass];
  178420. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  178421. row_info->width);
  178422. }
  178423. }
  178424. #endif
  178425. #define PNG_MAXSUM (((png_uint_32)(-1)) >> 1)
  178426. #define PNG_HISHIFT 10
  178427. #define PNG_LOMASK ((png_uint_32)0xffffL)
  178428. #define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT))
  178429. void /* PRIVATE */
  178430. png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
  178431. {
  178432. png_bytep best_row;
  178433. #ifndef PNG_NO_WRITE_FILTER
  178434. png_bytep prev_row, row_buf;
  178435. png_uint_32 mins, bpp;
  178436. png_byte filter_to_do = png_ptr->do_filter;
  178437. png_uint_32 row_bytes = row_info->rowbytes;
  178438. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178439. int num_p_filters = (int)png_ptr->num_prev_filters;
  178440. #endif
  178441. png_debug(1, "in png_write_find_filter\n");
  178442. bpp = (row_info->pixel_depth + 7) >> 3;
  178443. prev_row = png_ptr->prev_row;
  178444. #endif
  178445. best_row = png_ptr->row_buf;
  178446. #ifndef PNG_NO_WRITE_FILTER
  178447. row_buf = best_row;
  178448. mins = PNG_MAXSUM;
  178449. if ((filter_to_do & PNG_FILTER_NONE) &&
  178450. filter_to_do != PNG_FILTER_NONE)
  178451. {
  178452. png_bytep rp;
  178453. png_uint_32 sum = 0;
  178454. png_uint_32 i;
  178455. int v;
  178456. for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
  178457. {
  178458. v = *rp;
  178459. sum += (v < 128) ? v : 256 - v;
  178460. }
  178461. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178462. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178463. {
  178464. png_uint_32 sumhi, sumlo;
  178465. int j;
  178466. sumlo = sum & PNG_LOMASK;
  178467. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */
  178468. for (j = 0; j < num_p_filters; j++)
  178469. {
  178470. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  178471. {
  178472. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178473. PNG_WEIGHT_SHIFT;
  178474. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178475. PNG_WEIGHT_SHIFT;
  178476. }
  178477. }
  178478. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178479. PNG_COST_SHIFT;
  178480. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178481. PNG_COST_SHIFT;
  178482. if (sumhi > PNG_HIMASK)
  178483. sum = PNG_MAXSUM;
  178484. else
  178485. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178486. }
  178487. #endif
  178488. mins = sum;
  178489. }
  178490. if (filter_to_do == PNG_FILTER_SUB)
  178491. {
  178492. png_bytep rp, lp, dp;
  178493. png_uint_32 i;
  178494. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178495. i++, rp++, dp++)
  178496. {
  178497. *dp = *rp;
  178498. }
  178499. for (lp = row_buf + 1; i < row_bytes;
  178500. i++, rp++, lp++, dp++)
  178501. {
  178502. *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178503. }
  178504. best_row = png_ptr->sub_row;
  178505. }
  178506. else if (filter_to_do & PNG_FILTER_SUB)
  178507. {
  178508. png_bytep rp, dp, lp;
  178509. png_uint_32 sum = 0, lmins = mins;
  178510. png_uint_32 i;
  178511. int v;
  178512. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178513. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178514. {
  178515. int j;
  178516. png_uint_32 lmhi, lmlo;
  178517. lmlo = lmins & PNG_LOMASK;
  178518. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178519. for (j = 0; j < num_p_filters; j++)
  178520. {
  178521. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  178522. {
  178523. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178524. PNG_WEIGHT_SHIFT;
  178525. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178526. PNG_WEIGHT_SHIFT;
  178527. }
  178528. }
  178529. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178530. PNG_COST_SHIFT;
  178531. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178532. PNG_COST_SHIFT;
  178533. if (lmhi > PNG_HIMASK)
  178534. lmins = PNG_MAXSUM;
  178535. else
  178536. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178537. }
  178538. #endif
  178539. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178540. i++, rp++, dp++)
  178541. {
  178542. v = *dp = *rp;
  178543. sum += (v < 128) ? v : 256 - v;
  178544. }
  178545. for (lp = row_buf + 1; i < row_bytes;
  178546. i++, rp++, lp++, dp++)
  178547. {
  178548. v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178549. sum += (v < 128) ? v : 256 - v;
  178550. if (sum > lmins) /* We are already worse, don't continue. */
  178551. break;
  178552. }
  178553. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178554. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178555. {
  178556. int j;
  178557. png_uint_32 sumhi, sumlo;
  178558. sumlo = sum & PNG_LOMASK;
  178559. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178560. for (j = 0; j < num_p_filters; j++)
  178561. {
  178562. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  178563. {
  178564. sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >>
  178565. PNG_WEIGHT_SHIFT;
  178566. sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >>
  178567. PNG_WEIGHT_SHIFT;
  178568. }
  178569. }
  178570. sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178571. PNG_COST_SHIFT;
  178572. sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178573. PNG_COST_SHIFT;
  178574. if (sumhi > PNG_HIMASK)
  178575. sum = PNG_MAXSUM;
  178576. else
  178577. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178578. }
  178579. #endif
  178580. if (sum < mins)
  178581. {
  178582. mins = sum;
  178583. best_row = png_ptr->sub_row;
  178584. }
  178585. }
  178586. if (filter_to_do == PNG_FILTER_UP)
  178587. {
  178588. png_bytep rp, dp, pp;
  178589. png_uint_32 i;
  178590. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  178591. pp = prev_row + 1; i < row_bytes;
  178592. i++, rp++, pp++, dp++)
  178593. {
  178594. *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
  178595. }
  178596. best_row = png_ptr->up_row;
  178597. }
  178598. else if (filter_to_do & PNG_FILTER_UP)
  178599. {
  178600. png_bytep rp, dp, pp;
  178601. png_uint_32 sum = 0, lmins = mins;
  178602. png_uint_32 i;
  178603. int v;
  178604. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178605. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178606. {
  178607. int j;
  178608. png_uint_32 lmhi, lmlo;
  178609. lmlo = lmins & PNG_LOMASK;
  178610. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178611. for (j = 0; j < num_p_filters; j++)
  178612. {
  178613. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  178614. {
  178615. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178616. PNG_WEIGHT_SHIFT;
  178617. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178618. PNG_WEIGHT_SHIFT;
  178619. }
  178620. }
  178621. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  178622. PNG_COST_SHIFT;
  178623. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  178624. PNG_COST_SHIFT;
  178625. if (lmhi > PNG_HIMASK)
  178626. lmins = PNG_MAXSUM;
  178627. else
  178628. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178629. }
  178630. #endif
  178631. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  178632. pp = prev_row + 1; i < row_bytes; i++)
  178633. {
  178634. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178635. sum += (v < 128) ? v : 256 - v;
  178636. if (sum > lmins) /* We are already worse, don't continue. */
  178637. break;
  178638. }
  178639. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178640. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178641. {
  178642. int j;
  178643. png_uint_32 sumhi, sumlo;
  178644. sumlo = sum & PNG_LOMASK;
  178645. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178646. for (j = 0; j < num_p_filters; j++)
  178647. {
  178648. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  178649. {
  178650. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178651. PNG_WEIGHT_SHIFT;
  178652. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178653. PNG_WEIGHT_SHIFT;
  178654. }
  178655. }
  178656. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  178657. PNG_COST_SHIFT;
  178658. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  178659. PNG_COST_SHIFT;
  178660. if (sumhi > PNG_HIMASK)
  178661. sum = PNG_MAXSUM;
  178662. else
  178663. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178664. }
  178665. #endif
  178666. if (sum < mins)
  178667. {
  178668. mins = sum;
  178669. best_row = png_ptr->up_row;
  178670. }
  178671. }
  178672. if (filter_to_do == PNG_FILTER_AVG)
  178673. {
  178674. png_bytep rp, dp, pp, lp;
  178675. png_uint_32 i;
  178676. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  178677. pp = prev_row + 1; i < bpp; i++)
  178678. {
  178679. *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  178680. }
  178681. for (lp = row_buf + 1; i < row_bytes; i++)
  178682. {
  178683. *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))
  178684. & 0xff);
  178685. }
  178686. best_row = png_ptr->avg_row;
  178687. }
  178688. else if (filter_to_do & PNG_FILTER_AVG)
  178689. {
  178690. png_bytep rp, dp, pp, lp;
  178691. png_uint_32 sum = 0, lmins = mins;
  178692. png_uint_32 i;
  178693. int v;
  178694. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178695. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178696. {
  178697. int j;
  178698. png_uint_32 lmhi, lmlo;
  178699. lmlo = lmins & PNG_LOMASK;
  178700. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178701. for (j = 0; j < num_p_filters; j++)
  178702. {
  178703. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG)
  178704. {
  178705. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178706. PNG_WEIGHT_SHIFT;
  178707. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178708. PNG_WEIGHT_SHIFT;
  178709. }
  178710. }
  178711. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178712. PNG_COST_SHIFT;
  178713. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178714. PNG_COST_SHIFT;
  178715. if (lmhi > PNG_HIMASK)
  178716. lmins = PNG_MAXSUM;
  178717. else
  178718. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178719. }
  178720. #endif
  178721. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  178722. pp = prev_row + 1; i < bpp; i++)
  178723. {
  178724. v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  178725. sum += (v < 128) ? v : 256 - v;
  178726. }
  178727. for (lp = row_buf + 1; i < row_bytes; i++)
  178728. {
  178729. v = *dp++ =
  178730. (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff);
  178731. sum += (v < 128) ? v : 256 - v;
  178732. if (sum > lmins) /* We are already worse, don't continue. */
  178733. break;
  178734. }
  178735. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178736. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178737. {
  178738. int j;
  178739. png_uint_32 sumhi, sumlo;
  178740. sumlo = sum & PNG_LOMASK;
  178741. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178742. for (j = 0; j < num_p_filters; j++)
  178743. {
  178744. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  178745. {
  178746. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178747. PNG_WEIGHT_SHIFT;
  178748. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178749. PNG_WEIGHT_SHIFT;
  178750. }
  178751. }
  178752. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178753. PNG_COST_SHIFT;
  178754. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178755. PNG_COST_SHIFT;
  178756. if (sumhi > PNG_HIMASK)
  178757. sum = PNG_MAXSUM;
  178758. else
  178759. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178760. }
  178761. #endif
  178762. if (sum < mins)
  178763. {
  178764. mins = sum;
  178765. best_row = png_ptr->avg_row;
  178766. }
  178767. }
  178768. if (filter_to_do == PNG_FILTER_PAETH)
  178769. {
  178770. png_bytep rp, dp, pp, cp, lp;
  178771. png_uint_32 i;
  178772. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  178773. pp = prev_row + 1; i < bpp; i++)
  178774. {
  178775. *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178776. }
  178777. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  178778. {
  178779. int a, b, c, pa, pb, pc, p;
  178780. b = *pp++;
  178781. c = *cp++;
  178782. a = *lp++;
  178783. p = b - c;
  178784. pc = a - c;
  178785. #ifdef PNG_USE_ABS
  178786. pa = abs(p);
  178787. pb = abs(pc);
  178788. pc = abs(p + pc);
  178789. #else
  178790. pa = p < 0 ? -p : p;
  178791. pb = pc < 0 ? -pc : pc;
  178792. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  178793. #endif
  178794. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  178795. *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  178796. }
  178797. best_row = png_ptr->paeth_row;
  178798. }
  178799. else if (filter_to_do & PNG_FILTER_PAETH)
  178800. {
  178801. png_bytep rp, dp, pp, cp, lp;
  178802. png_uint_32 sum = 0, lmins = mins;
  178803. png_uint_32 i;
  178804. int v;
  178805. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178806. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178807. {
  178808. int j;
  178809. png_uint_32 lmhi, lmlo;
  178810. lmlo = lmins & PNG_LOMASK;
  178811. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178812. for (j = 0; j < num_p_filters; j++)
  178813. {
  178814. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  178815. {
  178816. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178817. PNG_WEIGHT_SHIFT;
  178818. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178819. PNG_WEIGHT_SHIFT;
  178820. }
  178821. }
  178822. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178823. PNG_COST_SHIFT;
  178824. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178825. PNG_COST_SHIFT;
  178826. if (lmhi > PNG_HIMASK)
  178827. lmins = PNG_MAXSUM;
  178828. else
  178829. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178830. }
  178831. #endif
  178832. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  178833. pp = prev_row + 1; i < bpp; i++)
  178834. {
  178835. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178836. sum += (v < 128) ? v : 256 - v;
  178837. }
  178838. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  178839. {
  178840. int a, b, c, pa, pb, pc, p;
  178841. b = *pp++;
  178842. c = *cp++;
  178843. a = *lp++;
  178844. #ifndef PNG_SLOW_PAETH
  178845. p = b - c;
  178846. pc = a - c;
  178847. #ifdef PNG_USE_ABS
  178848. pa = abs(p);
  178849. pb = abs(pc);
  178850. pc = abs(p + pc);
  178851. #else
  178852. pa = p < 0 ? -p : p;
  178853. pb = pc < 0 ? -pc : pc;
  178854. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  178855. #endif
  178856. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  178857. #else /* PNG_SLOW_PAETH */
  178858. p = a + b - c;
  178859. pa = abs(p - a);
  178860. pb = abs(p - b);
  178861. pc = abs(p - c);
  178862. if (pa <= pb && pa <= pc)
  178863. p = a;
  178864. else if (pb <= pc)
  178865. p = b;
  178866. else
  178867. p = c;
  178868. #endif /* PNG_SLOW_PAETH */
  178869. v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  178870. sum += (v < 128) ? v : 256 - v;
  178871. if (sum > lmins) /* We are already worse, don't continue. */
  178872. break;
  178873. }
  178874. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178875. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178876. {
  178877. int j;
  178878. png_uint_32 sumhi, sumlo;
  178879. sumlo = sum & PNG_LOMASK;
  178880. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178881. for (j = 0; j < num_p_filters; j++)
  178882. {
  178883. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  178884. {
  178885. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178886. PNG_WEIGHT_SHIFT;
  178887. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178888. PNG_WEIGHT_SHIFT;
  178889. }
  178890. }
  178891. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178892. PNG_COST_SHIFT;
  178893. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178894. PNG_COST_SHIFT;
  178895. if (sumhi > PNG_HIMASK)
  178896. sum = PNG_MAXSUM;
  178897. else
  178898. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178899. }
  178900. #endif
  178901. if (sum < mins)
  178902. {
  178903. best_row = png_ptr->paeth_row;
  178904. }
  178905. }
  178906. #endif /* PNG_NO_WRITE_FILTER */
  178907. png_write_filtered_row(png_ptr, best_row);
  178908. #ifndef PNG_NO_WRITE_FILTER
  178909. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178910. if (png_ptr->num_prev_filters > 0)
  178911. {
  178912. int j;
  178913. for (j = 1; j < num_p_filters; j++)
  178914. {
  178915. png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1];
  178916. }
  178917. png_ptr->prev_filters[j] = best_row[0];
  178918. }
  178919. #endif
  178920. #endif /* PNG_NO_WRITE_FILTER */
  178921. }
  178922. void /* PRIVATE */
  178923. png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
  178924. {
  178925. png_debug(1, "in png_write_filtered_row\n");
  178926. png_debug1(2, "filter = %d\n", filtered_row[0]);
  178927. png_ptr->zstream.next_in = filtered_row;
  178928. png_ptr->zstream.avail_in = (uInt)png_ptr->row_info.rowbytes + 1;
  178929. do
  178930. {
  178931. int ret; /* return of zlib */
  178932. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  178933. if (ret != Z_OK)
  178934. {
  178935. if (png_ptr->zstream.msg != NULL)
  178936. png_error(png_ptr, png_ptr->zstream.msg);
  178937. else
  178938. png_error(png_ptr, "zlib error");
  178939. }
  178940. if (!(png_ptr->zstream.avail_out))
  178941. {
  178942. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  178943. png_ptr->zstream.next_out = png_ptr->zbuf;
  178944. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178945. }
  178946. } while (png_ptr->zstream.avail_in);
  178947. if (png_ptr->prev_row != NULL)
  178948. {
  178949. png_bytep tptr;
  178950. tptr = png_ptr->prev_row;
  178951. png_ptr->prev_row = png_ptr->row_buf;
  178952. png_ptr->row_buf = tptr;
  178953. }
  178954. png_write_finish_row(png_ptr);
  178955. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  178956. png_ptr->flush_rows++;
  178957. if (png_ptr->flush_dist > 0 &&
  178958. png_ptr->flush_rows >= png_ptr->flush_dist)
  178959. {
  178960. png_write_flush(png_ptr);
  178961. }
  178962. #endif
  178963. }
  178964. #endif /* PNG_WRITE_SUPPORTED */
  178965. /*** End of inlined file: pngwutil.c ***/
  178966. }
  178967. #else
  178968. #define PNG_INTERNAL
  178969. #define PNG_SETJMP_NOT_SUPPORTED
  178970. #include <png.h>
  178971. #include <pngconf.h>
  178972. #endif
  178973. }
  178974. #undef max
  178975. #undef min
  178976. #ifdef _MSC_VER
  178977. #pragma warning (pop)
  178978. #endif
  178979. BEGIN_JUCE_NAMESPACE
  178980. using ::calloc;
  178981. using ::malloc;
  178982. using ::free;
  178983. namespace PNGHelpers
  178984. {
  178985. using namespace pnglibNamespace;
  178986. static void readCallback (png_structp png, png_bytep data, png_size_t length)
  178987. {
  178988. static_cast<InputStream*> (png->io_ptr)->read (data, (int) length);
  178989. }
  178990. static void writeDataCallback (png_structp png, png_bytep data, png_size_t length)
  178991. {
  178992. static_cast<OutputStream*> (png->io_ptr)->write (data, (int) length);
  178993. }
  178994. struct PNGErrorStruct {};
  178995. static void errorCallback (png_structp, png_const_charp)
  178996. {
  178997. throw PNGErrorStruct();
  178998. }
  178999. }
  179000. Image* juce_loadPNGImageFromStream (InputStream& in)
  179001. {
  179002. using namespace pnglibNamespace;
  179003. Image* image = 0;
  179004. png_structp pngReadStruct;
  179005. png_infop pngInfoStruct;
  179006. pngReadStruct = png_create_read_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  179007. if (pngReadStruct != 0)
  179008. {
  179009. pngInfoStruct = png_create_info_struct (pngReadStruct);
  179010. if (pngInfoStruct == 0)
  179011. {
  179012. png_destroy_read_struct (&pngReadStruct, 0, 0);
  179013. return 0;
  179014. }
  179015. png_set_error_fn (pngReadStruct, 0, PNGHelpers::errorCallback, PNGHelpers::errorCallback );
  179016. // read the header..
  179017. png_set_read_fn (pngReadStruct, &in, PNGHelpers::readCallback);
  179018. png_uint_32 width, height;
  179019. int bitDepth, colorType, interlaceType;
  179020. png_read_info (pngReadStruct, pngInfoStruct);
  179021. png_get_IHDR (pngReadStruct, pngInfoStruct,
  179022. &width, &height,
  179023. &bitDepth, &colorType,
  179024. &interlaceType, 0, 0);
  179025. if (bitDepth == 16)
  179026. png_set_strip_16 (pngReadStruct);
  179027. if (colorType == PNG_COLOR_TYPE_PALETTE)
  179028. png_set_expand (pngReadStruct);
  179029. if (bitDepth < 8)
  179030. png_set_expand (pngReadStruct);
  179031. if (png_get_valid (pngReadStruct, pngInfoStruct, PNG_INFO_tRNS))
  179032. png_set_expand (pngReadStruct);
  179033. if (colorType == PNG_COLOR_TYPE_GRAY || colorType == PNG_COLOR_TYPE_GRAY_ALPHA)
  179034. png_set_gray_to_rgb (pngReadStruct);
  179035. png_set_add_alpha (pngReadStruct, 0xff, PNG_FILLER_AFTER);
  179036. bool hasAlphaChan = (colorType & PNG_COLOR_MASK_ALPHA) != 0
  179037. || pngInfoStruct->num_trans > 0;
  179038. // Load the image into a temp buffer in the pnglib format..
  179039. HeapBlock <uint8> tempBuffer (height * (width << 2));
  179040. {
  179041. HeapBlock <png_bytep> rows (height);
  179042. for (int y = (int) height; --y >= 0;)
  179043. rows[y] = (png_bytep) (tempBuffer + (width << 2) * y);
  179044. png_read_image (pngReadStruct, rows);
  179045. png_read_end (pngReadStruct, pngInfoStruct);
  179046. }
  179047. png_destroy_read_struct (&pngReadStruct, &pngInfoStruct, 0);
  179048. // now convert the data to a juce image format..
  179049. image = Image::createNativeImage (hasAlphaChan ? Image::ARGB : Image::RGB,
  179050. (int) width, (int) height, hasAlphaChan);
  179051. hasAlphaChan = image->hasAlphaChannel(); // (the native image creator may not give back what we expect)
  179052. const Image::BitmapData destData (*image, 0, 0, (int) width, (int) height, true);
  179053. uint8* srcRow = tempBuffer;
  179054. uint8* destRow = destData.data;
  179055. for (int y = 0; y < (int) height; ++y)
  179056. {
  179057. const uint8* src = srcRow;
  179058. srcRow += (width << 2);
  179059. uint8* dest = destRow;
  179060. destRow += destData.lineStride;
  179061. if (hasAlphaChan)
  179062. {
  179063. for (int i = (int) width; --i >= 0;)
  179064. {
  179065. ((PixelARGB*) dest)->setARGB (src[3], src[0], src[1], src[2]);
  179066. ((PixelARGB*) dest)->premultiply();
  179067. dest += destData.pixelStride;
  179068. src += 4;
  179069. }
  179070. }
  179071. else
  179072. {
  179073. for (int i = (int) width; --i >= 0;)
  179074. {
  179075. ((PixelRGB*) dest)->setARGB (0, src[0], src[1], src[2]);
  179076. dest += destData.pixelStride;
  179077. src += 4;
  179078. }
  179079. }
  179080. }
  179081. }
  179082. return image;
  179083. }
  179084. bool juce_writePNGImageToStream (const Image& image, OutputStream& out)
  179085. {
  179086. using namespace pnglibNamespace;
  179087. const int width = image.getWidth();
  179088. const int height = image.getHeight();
  179089. png_structp pngWriteStruct = png_create_write_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  179090. if (pngWriteStruct == 0)
  179091. return false;
  179092. png_infop pngInfoStruct = png_create_info_struct (pngWriteStruct);
  179093. if (pngInfoStruct == 0)
  179094. {
  179095. png_destroy_write_struct (&pngWriteStruct, (png_infopp) 0);
  179096. return false;
  179097. }
  179098. png_set_write_fn (pngWriteStruct, &out, PNGHelpers::writeDataCallback, 0);
  179099. png_set_IHDR (pngWriteStruct, pngInfoStruct, width, height, 8,
  179100. image.hasAlphaChannel() ? PNG_COLOR_TYPE_RGB_ALPHA
  179101. : PNG_COLOR_TYPE_RGB,
  179102. PNG_INTERLACE_NONE,
  179103. PNG_COMPRESSION_TYPE_BASE,
  179104. PNG_FILTER_TYPE_BASE);
  179105. HeapBlock <png_byte> rowData (width * 4);
  179106. png_color_8 sig_bit;
  179107. sig_bit.red = 8;
  179108. sig_bit.green = 8;
  179109. sig_bit.blue = 8;
  179110. sig_bit.alpha = 8;
  179111. png_set_sBIT (pngWriteStruct, pngInfoStruct, &sig_bit);
  179112. png_write_info (pngWriteStruct, pngInfoStruct);
  179113. png_set_shift (pngWriteStruct, &sig_bit);
  179114. png_set_packing (pngWriteStruct);
  179115. const Image::BitmapData srcData (image, 0, 0, width, height);
  179116. for (int y = 0; y < height; ++y)
  179117. {
  179118. uint8* dst = (uint8*) rowData;
  179119. const uint8* src = srcData.getLinePointer (y);
  179120. if (image.hasAlphaChannel())
  179121. {
  179122. for (int i = width; --i >= 0;)
  179123. {
  179124. PixelARGB p (*(const PixelARGB*) src);
  179125. p.unpremultiply();
  179126. *dst++ = p.getRed();
  179127. *dst++ = p.getGreen();
  179128. *dst++ = p.getBlue();
  179129. *dst++ = p.getAlpha();
  179130. src += srcData.pixelStride;
  179131. }
  179132. }
  179133. else
  179134. {
  179135. for (int i = width; --i >= 0;)
  179136. {
  179137. *dst++ = ((const PixelRGB*) src)->getRed();
  179138. *dst++ = ((const PixelRGB*) src)->getGreen();
  179139. *dst++ = ((const PixelRGB*) src)->getBlue();
  179140. src += srcData.pixelStride;
  179141. }
  179142. }
  179143. png_write_rows (pngWriteStruct, &rowData, 1);
  179144. }
  179145. png_write_end (pngWriteStruct, pngInfoStruct);
  179146. png_destroy_write_struct (&pngWriteStruct, &pngInfoStruct);
  179147. out.flush();
  179148. return true;
  179149. }
  179150. END_JUCE_NAMESPACE
  179151. /*** End of inlined file: juce_PNGLoader.cpp ***/
  179152. #endif
  179153. //==============================================================================
  179154. #if JUCE_BUILD_NATIVE
  179155. #if JUCE_WINDOWS
  179156. /*** Start of inlined file: juce_win32_NativeCode.cpp ***/
  179157. #if JUCE_WINDOWS
  179158. BEGIN_JUCE_NAMESPACE
  179159. #define JUCE_INCLUDED_FILE 1
  179160. // Now include the actual code files..
  179161. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179162. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179163. // compiled on its own).
  179164. #if JUCE_INCLUDED_FILE
  179165. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179166. #ifndef __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179167. #define __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179168. #ifndef DOXYGEN
  179169. // use with DynamicLibraryLoader to simplify importing functions
  179170. //
  179171. // functionName: function to import
  179172. // localFunctionName: name you want to use to actually call it (must be different)
  179173. // returnType: the return type
  179174. // object: the DynamicLibraryLoader to use
  179175. // params: list of params (bracketed)
  179176. //
  179177. #define DynamicLibraryImport(functionName, localFunctionName, returnType, object, params) \
  179178. typedef returnType (WINAPI *type##localFunctionName) params; \
  179179. type##localFunctionName localFunctionName \
  179180. = (type##localFunctionName)object.findProcAddress (#functionName);
  179181. // loads and unloads a DLL automatically
  179182. class JUCE_API DynamicLibraryLoader
  179183. {
  179184. public:
  179185. DynamicLibraryLoader (const String& name);
  179186. ~DynamicLibraryLoader();
  179187. void* findProcAddress (const String& functionName);
  179188. private:
  179189. void* libHandle;
  179190. };
  179191. #endif
  179192. #endif // __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179193. /*** End of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179194. DynamicLibraryLoader::DynamicLibraryLoader (const String& name)
  179195. {
  179196. libHandle = LoadLibrary (name);
  179197. }
  179198. DynamicLibraryLoader::~DynamicLibraryLoader()
  179199. {
  179200. FreeLibrary ((HMODULE) libHandle);
  179201. }
  179202. void* DynamicLibraryLoader::findProcAddress (const String& functionName)
  179203. {
  179204. return (void*) GetProcAddress ((HMODULE) libHandle, functionName.toCString());
  179205. }
  179206. #endif
  179207. /*** End of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179208. /*** Start of inlined file: juce_win32_SystemStats.cpp ***/
  179209. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179210. // compiled on its own).
  179211. #if JUCE_INCLUDED_FILE
  179212. extern void juce_initialiseThreadEvents();
  179213. void Logger::outputDebugString (const String& text) throw()
  179214. {
  179215. OutputDebugString (text + "\n");
  179216. }
  179217. static int64 hiResTicksPerSecond;
  179218. static double hiResTicksScaleFactor;
  179219. #if JUCE_USE_INTRINSICS
  179220. // CPU info functions using intrinsics...
  179221. #pragma intrinsic (__cpuid)
  179222. #pragma intrinsic (__rdtsc)
  179223. const String SystemStats::getCpuVendor() throw()
  179224. {
  179225. int info [4];
  179226. __cpuid (info, 0);
  179227. char v [12];
  179228. memcpy (v, info + 1, 4);
  179229. memcpy (v + 4, info + 3, 4);
  179230. memcpy (v + 8, info + 2, 4);
  179231. return String (v, 12);
  179232. }
  179233. #else
  179234. // CPU info functions using old fashioned inline asm...
  179235. static void juce_getCpuVendor (char* const v)
  179236. {
  179237. int vendor[4];
  179238. zeromem (vendor, 16);
  179239. #ifdef JUCE_64BIT
  179240. #else
  179241. #ifndef __MINGW32__
  179242. __try
  179243. #endif
  179244. {
  179245. #if JUCE_GCC
  179246. unsigned int dummy = 0;
  179247. __asm__ ("cpuid" : "=a" (dummy), "=b" (vendor[0]), "=c" (vendor[2]),"=d" (vendor[1]) : "a" (0));
  179248. #else
  179249. __asm
  179250. {
  179251. mov eax, 0
  179252. cpuid
  179253. mov [vendor], ebx
  179254. mov [vendor + 4], edx
  179255. mov [vendor + 8], ecx
  179256. }
  179257. #endif
  179258. }
  179259. #ifndef __MINGW32__
  179260. __except (EXCEPTION_EXECUTE_HANDLER)
  179261. {
  179262. *v = 0;
  179263. }
  179264. #endif
  179265. #endif
  179266. memcpy (v, vendor, 16);
  179267. }
  179268. const String SystemStats::getCpuVendor() throw()
  179269. {
  179270. char v [16];
  179271. juce_getCpuVendor (v);
  179272. return String (v, 16);
  179273. }
  179274. #endif
  179275. struct CPUFlags
  179276. {
  179277. bool hasMMX : 1;
  179278. bool hasSSE : 1;
  179279. bool hasSSE2 : 1;
  179280. bool has3DNow : 1;
  179281. };
  179282. static CPUFlags cpuFlags;
  179283. bool SystemStats::hasMMX() throw()
  179284. {
  179285. return cpuFlags.hasMMX;
  179286. }
  179287. bool SystemStats::hasSSE() throw()
  179288. {
  179289. return cpuFlags.hasSSE;
  179290. }
  179291. bool SystemStats::hasSSE2() throw()
  179292. {
  179293. return cpuFlags.hasSSE2;
  179294. }
  179295. bool SystemStats::has3DNow() throw()
  179296. {
  179297. return cpuFlags.has3DNow;
  179298. }
  179299. void SystemStats::initialiseStats() throw()
  179300. {
  179301. juce_initialiseThreadEvents();
  179302. cpuFlags.hasMMX = IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE) != 0;
  179303. cpuFlags.hasSSE = IsProcessorFeaturePresent (PF_XMMI_INSTRUCTIONS_AVAILABLE) != 0;
  179304. cpuFlags.hasSSE2 = IsProcessorFeaturePresent (PF_XMMI64_INSTRUCTIONS_AVAILABLE) != 0;
  179305. #ifdef PF_AMD3D_INSTRUCTIONS_AVAILABLE
  179306. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_AMD3D_INSTRUCTIONS_AVAILABLE) != 0;
  179307. #else
  179308. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE) != 0;
  179309. #endif
  179310. LARGE_INTEGER f;
  179311. QueryPerformanceFrequency (&f);
  179312. hiResTicksPerSecond = f.QuadPart;
  179313. hiResTicksScaleFactor = 1000.0 / hiResTicksPerSecond;
  179314. String s (SystemStats::getJUCEVersion());
  179315. #ifdef JUCE_DEBUG
  179316. const MMRESULT res = timeBeginPeriod (1);
  179317. jassert (res == TIMERR_NOERROR);
  179318. #else
  179319. timeBeginPeriod (1);
  179320. #endif
  179321. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  179322. _CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  179323. #endif
  179324. }
  179325. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  179326. {
  179327. OSVERSIONINFO info;
  179328. info.dwOSVersionInfoSize = sizeof (info);
  179329. GetVersionEx (&info);
  179330. if (info.dwPlatformId == VER_PLATFORM_WIN32_NT)
  179331. {
  179332. switch (info.dwMajorVersion)
  179333. {
  179334. case 5: return (info.dwMinorVersion == 0) ? Win2000 : WinXP;
  179335. case 6: return (info.dwMinorVersion == 0) ? WinVista : Windows7;
  179336. default: jassertfalse; break; // !! not a supported OS!
  179337. }
  179338. }
  179339. else if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
  179340. {
  179341. jassert (info.dwMinorVersion != 0); // !! still running on Windows 95??
  179342. return Win98;
  179343. }
  179344. return UnknownOS;
  179345. }
  179346. const String SystemStats::getOperatingSystemName() throw()
  179347. {
  179348. const char* name = "Unknown OS";
  179349. switch (getOperatingSystemType())
  179350. {
  179351. case Windows7: name = "Windows 7"; break;
  179352. case WinVista: name = "Windows Vista"; break;
  179353. case WinXP: name = "Windows XP"; break;
  179354. case Win2000: name = "Windows 2000"; break;
  179355. case Win98: name = "Windows 98"; break;
  179356. default: jassertfalse; break; // !! new type of OS?
  179357. }
  179358. return name;
  179359. }
  179360. bool SystemStats::isOperatingSystem64Bit() throw()
  179361. {
  179362. #ifdef _WIN64
  179363. return true;
  179364. #else
  179365. typedef BOOL (WINAPI* LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
  179366. LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress (GetModuleHandle (L"kernel32"), "IsWow64Process");
  179367. BOOL isWow64 = FALSE;
  179368. return (fnIsWow64Process != 0)
  179369. && fnIsWow64Process (GetCurrentProcess(), &isWow64)
  179370. && (isWow64 != FALSE);
  179371. #endif
  179372. }
  179373. int SystemStats::getMemorySizeInMegabytes() throw()
  179374. {
  179375. MEMORYSTATUSEX mem;
  179376. mem.dwLength = sizeof (mem);
  179377. GlobalMemoryStatusEx (&mem);
  179378. return (int) (mem.ullTotalPhys / (1024 * 1024)) + 1;
  179379. }
  179380. int SystemStats::getNumCpus() throw()
  179381. {
  179382. SYSTEM_INFO systemInfo;
  179383. GetSystemInfo (&systemInfo);
  179384. return systemInfo.dwNumberOfProcessors;
  179385. }
  179386. uint32 juce_millisecondsSinceStartup() throw()
  179387. {
  179388. return (uint32) GetTickCount();
  179389. }
  179390. int64 Time::getHighResolutionTicks() throw()
  179391. {
  179392. LARGE_INTEGER ticks;
  179393. QueryPerformanceCounter (&ticks);
  179394. const int64 mainCounterAsHiResTicks = (GetTickCount() * hiResTicksPerSecond) / 1000;
  179395. const int64 newOffset = mainCounterAsHiResTicks - ticks.QuadPart;
  179396. // fix for a very obscure PCI hardware bug that can make the counter
  179397. // sometimes jump forwards by a few seconds..
  179398. static int64 hiResTicksOffset = 0;
  179399. const int64 offsetDrift = abs64 (newOffset - hiResTicksOffset);
  179400. if (offsetDrift > (hiResTicksPerSecond >> 1))
  179401. hiResTicksOffset = newOffset;
  179402. return ticks.QuadPart + hiResTicksOffset;
  179403. }
  179404. double Time::getMillisecondCounterHiRes() throw()
  179405. {
  179406. return getHighResolutionTicks() * hiResTicksScaleFactor;
  179407. }
  179408. int64 Time::getHighResolutionTicksPerSecond() throw()
  179409. {
  179410. return hiResTicksPerSecond;
  179411. }
  179412. int64 SystemStats::getClockCycleCounter() throw()
  179413. {
  179414. #if JUCE_USE_INTRINSICS
  179415. // MS intrinsics version...
  179416. return __rdtsc();
  179417. #elif JUCE_GCC
  179418. // GNU inline asm version...
  179419. unsigned int hi = 0, lo = 0;
  179420. __asm__ __volatile__ (
  179421. "xor %%eax, %%eax \n\
  179422. xor %%edx, %%edx \n\
  179423. rdtsc \n\
  179424. movl %%eax, %[lo] \n\
  179425. movl %%edx, %[hi]"
  179426. :
  179427. : [hi] "m" (hi),
  179428. [lo] "m" (lo)
  179429. : "cc", "eax", "ebx", "ecx", "edx", "memory");
  179430. return (int64) ((((uint64) hi) << 32) | lo);
  179431. #else
  179432. // MSVC inline asm version...
  179433. unsigned int hi = 0, lo = 0;
  179434. __asm
  179435. {
  179436. xor eax, eax
  179437. xor edx, edx
  179438. rdtsc
  179439. mov lo, eax
  179440. mov hi, edx
  179441. }
  179442. return (int64) ((((uint64) hi) << 32) | lo);
  179443. #endif
  179444. }
  179445. int SystemStats::getCpuSpeedInMegaherz() throw()
  179446. {
  179447. const int64 cycles = SystemStats::getClockCycleCounter();
  179448. const uint32 millis = Time::getMillisecondCounter();
  179449. int lastResult = 0;
  179450. for (;;)
  179451. {
  179452. int n = 1000000;
  179453. while (--n > 0) {}
  179454. const uint32 millisElapsed = Time::getMillisecondCounter() - millis;
  179455. const int64 cyclesNow = SystemStats::getClockCycleCounter();
  179456. if (millisElapsed > 80)
  179457. {
  179458. const int newResult = (int) (((cyclesNow - cycles) / millisElapsed) / 1000);
  179459. if (millisElapsed > 500 || (lastResult == newResult && newResult > 100))
  179460. return newResult;
  179461. lastResult = newResult;
  179462. }
  179463. }
  179464. }
  179465. bool Time::setSystemTimeToThisTime() const throw()
  179466. {
  179467. SYSTEMTIME st;
  179468. st.wDayOfWeek = 0;
  179469. st.wYear = (WORD) getYear();
  179470. st.wMonth = (WORD) (getMonth() + 1);
  179471. st.wDay = (WORD) getDayOfMonth();
  179472. st.wHour = (WORD) getHours();
  179473. st.wMinute = (WORD) getMinutes();
  179474. st.wSecond = (WORD) getSeconds();
  179475. st.wMilliseconds = (WORD) (millisSinceEpoch % 1000);
  179476. // do this twice because of daylight saving conversion problems - the
  179477. // first one sets it up, the second one kicks it in.
  179478. return SetLocalTime (&st) != 0
  179479. && SetLocalTime (&st) != 0;
  179480. }
  179481. int SystemStats::getPageSize() throw()
  179482. {
  179483. SYSTEM_INFO systemInfo;
  179484. GetSystemInfo (&systemInfo);
  179485. return systemInfo.dwPageSize;
  179486. }
  179487. const String SystemStats::getLogonName()
  179488. {
  179489. TCHAR text [256];
  179490. DWORD len = numElementsInArray (text) - 2;
  179491. zerostruct (text);
  179492. GetUserName (text, &len);
  179493. return String (text, len);
  179494. }
  179495. const String SystemStats::getFullUserName()
  179496. {
  179497. return getLogonName();
  179498. }
  179499. #endif
  179500. /*** End of inlined file: juce_win32_SystemStats.cpp ***/
  179501. /*** Start of inlined file: juce_win32_Threads.cpp ***/
  179502. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179503. // compiled on its own).
  179504. #if JUCE_INCLUDED_FILE
  179505. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179506. extern HWND juce_messageWindowHandle;
  179507. #endif
  179508. #if ! JUCE_USE_INTRINSICS
  179509. // In newer compilers, the inline versions of these are used (in juce_Atomic.h), but in
  179510. // older ones we have to actually call the ops as win32 functions..
  179511. void Atomic::increment (int32& variable) { InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179512. int32 Atomic::incrementAndReturn (int32& variable) { return InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179513. void Atomic::decrement (int32& variable) { InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179514. int32 Atomic::decrementAndReturn (int32& variable) { return InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179515. int32 Atomic::compareAndExchange (int32& destination, int32 newValue, int32 oldValue)
  179516. { return InterlockedCompareExchange (reinterpret_cast <volatile long*> (&destination), newValue, oldValue); }
  179517. #endif
  179518. void* Atomic::swapPointers (void* volatile* value1, void* volatile value2) { return InterlockedExchangePointer (value1, value2); }
  179519. CriticalSection::CriticalSection() throw()
  179520. {
  179521. // (just to check the MS haven't changed this structure and broken things...)
  179522. #if _MSC_VER >= 1400
  179523. static_jassert (sizeof (CRITICAL_SECTION) <= sizeof (internal));
  179524. #else
  179525. static_jassert (sizeof (CRITICAL_SECTION) <= 24);
  179526. #endif
  179527. InitializeCriticalSection ((CRITICAL_SECTION*) internal);
  179528. }
  179529. CriticalSection::~CriticalSection() throw()
  179530. {
  179531. DeleteCriticalSection ((CRITICAL_SECTION*) internal);
  179532. }
  179533. void CriticalSection::enter() const throw()
  179534. {
  179535. EnterCriticalSection ((CRITICAL_SECTION*) internal);
  179536. }
  179537. bool CriticalSection::tryEnter() const throw()
  179538. {
  179539. return TryEnterCriticalSection ((CRITICAL_SECTION*) internal) != FALSE;
  179540. }
  179541. void CriticalSection::exit() const throw()
  179542. {
  179543. LeaveCriticalSection ((CRITICAL_SECTION*) internal);
  179544. }
  179545. WaitableEvent::WaitableEvent() throw()
  179546. : internal (CreateEvent (0, FALSE, FALSE, 0))
  179547. {
  179548. }
  179549. WaitableEvent::~WaitableEvent() throw()
  179550. {
  179551. CloseHandle (internal);
  179552. }
  179553. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  179554. {
  179555. return WaitForSingleObject (internal, timeOutMillisecs) == WAIT_OBJECT_0;
  179556. }
  179557. void WaitableEvent::signal() const throw()
  179558. {
  179559. SetEvent (internal);
  179560. }
  179561. void WaitableEvent::reset() const throw()
  179562. {
  179563. ResetEvent (internal);
  179564. }
  179565. void JUCE_API juce_threadEntryPoint (void*);
  179566. static unsigned int __stdcall threadEntryProc (void* userData)
  179567. {
  179568. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179569. AttachThreadInput (GetWindowThreadProcessId (juce_messageWindowHandle, 0),
  179570. GetCurrentThreadId(), TRUE);
  179571. #endif
  179572. juce_threadEntryPoint (userData);
  179573. _endthreadex (0);
  179574. return 0;
  179575. }
  179576. void juce_CloseThreadHandle (void* handle)
  179577. {
  179578. CloseHandle ((HANDLE) handle);
  179579. }
  179580. void* juce_createThread (void* userData)
  179581. {
  179582. unsigned int threadId;
  179583. return (void*) _beginthreadex (0, 0,
  179584. &threadEntryProc,
  179585. userData,
  179586. 0, &threadId);
  179587. }
  179588. void juce_killThread (void* handle)
  179589. {
  179590. if (handle != 0)
  179591. {
  179592. #ifdef JUCE_DEBUG
  179593. OutputDebugString (_T("** Warning - Forced thread termination **\n"));
  179594. #endif
  179595. TerminateThread (handle, 0);
  179596. }
  179597. }
  179598. void juce_setCurrentThreadName (const String& name)
  179599. {
  179600. #if defined (JUCE_DEBUG) && JUCE_MSVC
  179601. struct
  179602. {
  179603. DWORD dwType;
  179604. LPCSTR szName;
  179605. DWORD dwThreadID;
  179606. DWORD dwFlags;
  179607. } info;
  179608. info.dwType = 0x1000;
  179609. info.szName = name.toCString();
  179610. info.dwThreadID = GetCurrentThreadId();
  179611. info.dwFlags = 0;
  179612. __try
  179613. {
  179614. RaiseException (0x406d1388 /*MS_VC_EXCEPTION*/, 0, sizeof (info) / sizeof (ULONG_PTR), (ULONG_PTR*) &info);
  179615. }
  179616. __except (EXCEPTION_CONTINUE_EXECUTION)
  179617. {}
  179618. #else
  179619. (void) name;
  179620. #endif
  179621. }
  179622. Thread::ThreadID Thread::getCurrentThreadId()
  179623. {
  179624. return (ThreadID) (pointer_sized_int) GetCurrentThreadId();
  179625. }
  179626. // priority 1 to 10 where 5=normal, 1=low
  179627. bool juce_setThreadPriority (void* threadHandle, int priority)
  179628. {
  179629. int pri = THREAD_PRIORITY_TIME_CRITICAL;
  179630. if (priority < 1)
  179631. pri = THREAD_PRIORITY_IDLE;
  179632. else if (priority < 2)
  179633. pri = THREAD_PRIORITY_LOWEST;
  179634. else if (priority < 5)
  179635. pri = THREAD_PRIORITY_BELOW_NORMAL;
  179636. else if (priority < 7)
  179637. pri = THREAD_PRIORITY_NORMAL;
  179638. else if (priority < 9)
  179639. pri = THREAD_PRIORITY_ABOVE_NORMAL;
  179640. else if (priority < 10)
  179641. pri = THREAD_PRIORITY_HIGHEST;
  179642. if (threadHandle == 0)
  179643. threadHandle = GetCurrentThread();
  179644. return SetThreadPriority (threadHandle, pri) != FALSE;
  179645. }
  179646. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  179647. {
  179648. SetThreadAffinityMask (GetCurrentThread(), affinityMask);
  179649. }
  179650. static HANDLE sleepEvent = 0;
  179651. void juce_initialiseThreadEvents()
  179652. {
  179653. if (sleepEvent == 0)
  179654. #ifdef JUCE_DEBUG
  179655. sleepEvent = CreateEvent (0, 0, 0, _T("Juce Sleep Event"));
  179656. #else
  179657. sleepEvent = CreateEvent (0, 0, 0, 0);
  179658. #endif
  179659. }
  179660. void Thread::yield()
  179661. {
  179662. Sleep (0);
  179663. }
  179664. void JUCE_CALLTYPE Thread::sleep (const int millisecs)
  179665. {
  179666. if (millisecs >= 10)
  179667. {
  179668. Sleep (millisecs);
  179669. }
  179670. else
  179671. {
  179672. jassert (sleepEvent != 0);
  179673. // unlike Sleep() this is guaranteed to return to the current thread after
  179674. // the time expires, so we'll use this for short waits, which are more likely
  179675. // to need to be accurate
  179676. WaitForSingleObject (sleepEvent, millisecs);
  179677. }
  179678. }
  179679. static int lastProcessPriority = -1;
  179680. // called by WindowDriver because Windows does wierd things to process priority
  179681. // when you swap apps, and this forces an update when the app is brought to the front.
  179682. void juce_repeatLastProcessPriority()
  179683. {
  179684. if (lastProcessPriority >= 0) // (avoid changing this if it's not been explicitly set by the app..)
  179685. {
  179686. DWORD p;
  179687. switch (lastProcessPriority)
  179688. {
  179689. case Process::LowPriority: p = IDLE_PRIORITY_CLASS; break;
  179690. case Process::NormalPriority: p = NORMAL_PRIORITY_CLASS; break;
  179691. case Process::HighPriority: p = HIGH_PRIORITY_CLASS; break;
  179692. case Process::RealtimePriority: p = REALTIME_PRIORITY_CLASS; break;
  179693. default: jassertfalse; return; // bad priority value
  179694. }
  179695. SetPriorityClass (GetCurrentProcess(), p);
  179696. }
  179697. }
  179698. void Process::setPriority (ProcessPriority prior)
  179699. {
  179700. if (lastProcessPriority != (int) prior)
  179701. {
  179702. lastProcessPriority = (int) prior;
  179703. juce_repeatLastProcessPriority();
  179704. }
  179705. }
  179706. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  179707. {
  179708. return IsDebuggerPresent() != FALSE;
  179709. }
  179710. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  179711. {
  179712. return juce_isRunningUnderDebugger();
  179713. }
  179714. void Process::raisePrivilege()
  179715. {
  179716. jassertfalse // xxx not implemented
  179717. }
  179718. void Process::lowerPrivilege()
  179719. {
  179720. jassertfalse // xxx not implemented
  179721. }
  179722. void Process::terminate()
  179723. {
  179724. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  179725. _CrtDumpMemoryLeaks();
  179726. #endif
  179727. // bullet in the head in case there's a problem shutting down..
  179728. ExitProcess (0);
  179729. }
  179730. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  179731. {
  179732. void* result = 0;
  179733. JUCE_TRY
  179734. {
  179735. result = (void*) LoadLibrary (name);
  179736. }
  179737. JUCE_CATCH_ALL
  179738. return result;
  179739. }
  179740. void PlatformUtilities::freeDynamicLibrary (void* h)
  179741. {
  179742. JUCE_TRY
  179743. {
  179744. if (h != 0)
  179745. FreeLibrary ((HMODULE) h);
  179746. }
  179747. JUCE_CATCH_ALL
  179748. }
  179749. void* PlatformUtilities::getProcedureEntryPoint (void* h, const String& name)
  179750. {
  179751. return (h != 0) ? (void*) GetProcAddress ((HMODULE) h, name.toCString()) : 0;
  179752. }
  179753. InterProcessLock::InterProcessLock (const String& name_)
  179754. : internal (0),
  179755. name (name_),
  179756. reentrancyLevel (0)
  179757. {
  179758. }
  179759. InterProcessLock::~InterProcessLock()
  179760. {
  179761. exit();
  179762. }
  179763. bool InterProcessLock::enter (const int timeOutMillisecs)
  179764. {
  179765. if (reentrancyLevel++ == 0)
  179766. {
  179767. internal = CreateMutex (0, TRUE, "Global\\" + name);
  179768. if (internal != 0 && GetLastError() == ERROR_ALREADY_EXISTS)
  179769. {
  179770. if (timeOutMillisecs == 0
  179771. || WaitForSingleObject (internal, (timeOutMillisecs < 0) ? INFINITE : timeOutMillisecs)
  179772. == WAIT_TIMEOUT)
  179773. {
  179774. ReleaseMutex (internal);
  179775. CloseHandle (internal);
  179776. internal = 0;
  179777. }
  179778. }
  179779. }
  179780. return (internal != 0);
  179781. }
  179782. void InterProcessLock::exit()
  179783. {
  179784. if (--reentrancyLevel == 0 && internal != 0)
  179785. {
  179786. ReleaseMutex (internal);
  179787. CloseHandle (internal);
  179788. internal = 0;
  179789. }
  179790. }
  179791. #endif
  179792. /*** End of inlined file: juce_win32_Threads.cpp ***/
  179793. /*** Start of inlined file: juce_win32_Files.cpp ***/
  179794. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179795. // compiled on its own).
  179796. #if JUCE_INCLUDED_FILE
  179797. #ifndef CSIDL_MYMUSIC
  179798. #define CSIDL_MYMUSIC 0x000d
  179799. #endif
  179800. #ifndef CSIDL_MYVIDEO
  179801. #define CSIDL_MYVIDEO 0x000e
  179802. #endif
  179803. #ifndef INVALID_FILE_ATTRIBUTES
  179804. #define INVALID_FILE_ATTRIBUTES ((DWORD) -1)
  179805. #endif
  179806. const juce_wchar File::separator = '\\';
  179807. const juce_wchar* File::separatorString = T("\\");
  179808. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  179809. {
  179810. if (fileName.isEmpty())
  179811. return false;
  179812. const DWORD attr = GetFileAttributes (fileName);
  179813. return dontCountDirectories ? ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0)
  179814. : (attr != INVALID_FILE_ATTRIBUTES);
  179815. }
  179816. bool juce_isDirectory (const String& fileName)
  179817. {
  179818. const DWORD attr = GetFileAttributes (fileName);
  179819. return ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) && (attr != INVALID_FILE_ATTRIBUTES);
  179820. }
  179821. bool juce_canWriteToFile (const String& fileName)
  179822. {
  179823. const DWORD attr = GetFileAttributes (fileName);
  179824. return (attr & FILE_ATTRIBUTE_READONLY) == 0;
  179825. }
  179826. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  179827. {
  179828. DWORD attr = GetFileAttributes (fileName);
  179829. if (attr == INVALID_FILE_ATTRIBUTES)
  179830. return false;
  179831. if (isReadOnly != juce_canWriteToFile (fileName))
  179832. return true;
  179833. if (isReadOnly)
  179834. attr |= FILE_ATTRIBUTE_READONLY;
  179835. else
  179836. attr &= ~FILE_ATTRIBUTE_READONLY;
  179837. return SetFileAttributes (fileName, attr) != FALSE;
  179838. }
  179839. bool File::isHidden() const
  179840. {
  179841. return (GetFileAttributes (getFullPathName()) & FILE_ATTRIBUTE_HIDDEN) != 0;
  179842. }
  179843. bool juce_deleteFile (const String& fileName)
  179844. {
  179845. if (juce_isDirectory (fileName))
  179846. return RemoveDirectory (fileName) != 0;
  179847. return DeleteFile (fileName) != 0;
  179848. }
  179849. bool File::moveToTrash() const
  179850. {
  179851. if (! exists())
  179852. return true;
  179853. SHFILEOPSTRUCT fos;
  179854. zerostruct (fos);
  179855. // The string we pass in must be double null terminated..
  179856. String doubleNullTermPath (getFullPathName() + " ");
  179857. TCHAR* const p = const_cast <TCHAR*> (static_cast <const TCHAR*> (doubleNullTermPath));
  179858. p [getFullPathName().length()] = 0;
  179859. fos.wFunc = FO_DELETE;
  179860. fos.pFrom = p;
  179861. fos.fFlags = FOF_ALLOWUNDO | FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION
  179862. | FOF_NOCONFIRMMKDIR | FOF_RENAMEONCOLLISION;
  179863. return SHFileOperation (&fos) == 0;
  179864. }
  179865. bool juce_moveFile (const String& source, const String& dest)
  179866. {
  179867. return MoveFile (source, dest) != 0;
  179868. }
  179869. bool juce_copyFile (const String& source, const String& dest)
  179870. {
  179871. return CopyFile (source, dest, false) != 0;
  179872. }
  179873. void juce_createDirectory (const String& fileName)
  179874. {
  179875. if (! juce_fileExists (fileName, true))
  179876. CreateDirectory (fileName, 0);
  179877. }
  179878. // return 0 if not possible
  179879. void* juce_fileOpen (const String& fileName, bool forWriting)
  179880. {
  179881. HANDLE h;
  179882. if (forWriting)
  179883. {
  179884. h = CreateFile (fileName, GENERIC_WRITE, FILE_SHARE_READ, 0,
  179885. OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
  179886. if (h != INVALID_HANDLE_VALUE)
  179887. SetFilePointer (h, 0, 0, FILE_END);
  179888. else
  179889. h = 0;
  179890. }
  179891. else
  179892. {
  179893. h = CreateFile (fileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
  179894. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 0);
  179895. if (h == INVALID_HANDLE_VALUE)
  179896. h = 0;
  179897. }
  179898. return (void*) h;
  179899. }
  179900. void juce_fileClose (void* handle)
  179901. {
  179902. CloseHandle (handle);
  179903. }
  179904. int juce_fileRead (void* handle, void* buffer, int size)
  179905. {
  179906. DWORD num = 0;
  179907. ReadFile ((HANDLE) handle, buffer, size, &num, 0);
  179908. return (int) num;
  179909. }
  179910. int juce_fileWrite (void* handle, const void* buffer, int size)
  179911. {
  179912. DWORD num;
  179913. WriteFile ((HANDLE) handle, buffer, size, &num, 0);
  179914. return (int) num;
  179915. }
  179916. int64 juce_fileSetPosition (void* handle, int64 pos)
  179917. {
  179918. LARGE_INTEGER li;
  179919. li.QuadPart = pos;
  179920. li.LowPart = SetFilePointer ((HANDLE) handle, li.LowPart, &li.HighPart, FILE_BEGIN); // (returns -1 if it fails)
  179921. return li.QuadPart;
  179922. }
  179923. int64 juce_fileGetPosition (void* handle)
  179924. {
  179925. LARGE_INTEGER li;
  179926. li.QuadPart = 0;
  179927. li.LowPart = SetFilePointer ((HANDLE) handle, 0, &li.HighPart, FILE_CURRENT); // (returns -1 if it fails)
  179928. return jmax ((int64) 0, li.QuadPart);
  179929. }
  179930. void juce_fileFlush (void* handle)
  179931. {
  179932. FlushFileBuffers ((HANDLE) handle);
  179933. }
  179934. int64 juce_getFileSize (const String& fileName)
  179935. {
  179936. WIN32_FILE_ATTRIBUTE_DATA attributes;
  179937. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  179938. return (((int64) attributes.nFileSizeHigh) << 32) | attributes.nFileSizeLow;
  179939. return 0;
  179940. }
  179941. static int64 fileTimeToTime (const FILETIME* const ft)
  179942. {
  179943. static_jassert (sizeof (ULARGE_INTEGER) == sizeof (FILETIME)); // tell me if this fails!
  179944. return (reinterpret_cast<const ULARGE_INTEGER*> (ft)->QuadPart - literal64bit (116444736000000000)) / 10000;
  179945. }
  179946. static void timeToFileTime (const int64 time, FILETIME* const ft)
  179947. {
  179948. reinterpret_cast<ULARGE_INTEGER*> (ft)->QuadPart = time * 10000 + literal64bit (116444736000000000);
  179949. }
  179950. void juce_getFileTimes (const String& fileName,
  179951. int64& modificationTime,
  179952. int64& accessTime,
  179953. int64& creationTime)
  179954. {
  179955. WIN32_FILE_ATTRIBUTE_DATA attributes;
  179956. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  179957. {
  179958. modificationTime = fileTimeToTime (&attributes.ftLastWriteTime);
  179959. creationTime = fileTimeToTime (&attributes.ftCreationTime);
  179960. accessTime = fileTimeToTime (&attributes.ftLastAccessTime);
  179961. }
  179962. else
  179963. {
  179964. creationTime = accessTime = modificationTime = 0;
  179965. }
  179966. }
  179967. bool juce_setFileTimes (const String& fileName,
  179968. int64 modificationTime,
  179969. int64 accessTime,
  179970. int64 creationTime)
  179971. {
  179972. void* const h = juce_fileOpen (fileName, true);
  179973. bool ok = false;
  179974. if (h != 0)
  179975. {
  179976. FILETIME m, a, c;
  179977. timeToFileTime (modificationTime, &m);
  179978. timeToFileTime (accessTime, &a);
  179979. timeToFileTime (creationTime, &c);
  179980. ok = SetFileTime ((HANDLE) h,
  179981. creationTime > 0 ? &c : 0,
  179982. accessTime > 0 ? &a : 0,
  179983. modificationTime > 0 ? &m : 0) != 0;
  179984. juce_fileClose (h);
  179985. }
  179986. return ok;
  179987. }
  179988. // return '\0' separated list of strings
  179989. const StringArray juce_getFileSystemRoots()
  179990. {
  179991. TCHAR buffer [2048];
  179992. buffer[0] = 0;
  179993. buffer[1] = 0;
  179994. GetLogicalDriveStrings (2048, buffer);
  179995. const TCHAR* n = buffer;
  179996. StringArray roots;
  179997. while (*n != 0)
  179998. {
  179999. roots.add (String (n));
  180000. while (*n++ != 0)
  180001. {}
  180002. }
  180003. roots.sort (true);
  180004. return roots;
  180005. }
  180006. static const String getDriveFromPath (const String& path)
  180007. {
  180008. if (path.isNotEmpty() && path[1] == ':')
  180009. return path.substring (0, 2) + '\\';
  180010. return path;
  180011. }
  180012. const String juce_getVolumeLabel (const String& filenameOnVolume,
  180013. int& volumeSerialNumber)
  180014. {
  180015. TCHAR dest[64];
  180016. DWORD serialNum;
  180017. if (! GetVolumeInformation (getDriveFromPath (filenameOnVolume), dest,
  180018. numElementsInArray (dest), &serialNum, 0, 0, 0, 0))
  180019. {
  180020. dest[0] = 0;
  180021. serialNum = 0;
  180022. }
  180023. volumeSerialNumber = serialNum;
  180024. return dest;
  180025. }
  180026. static int64 getDiskSpaceInfo (const String& path, const bool total)
  180027. {
  180028. ULARGE_INTEGER spc, tot, totFree;
  180029. if (GetDiskFreeSpaceEx (getDriveFromPath (path), &spc, &tot, &totFree))
  180030. return total ? (int64) tot.QuadPart
  180031. : (int64) spc.QuadPart;
  180032. return 0;
  180033. }
  180034. int64 File::getBytesFreeOnVolume() const
  180035. {
  180036. return getDiskSpaceInfo (getFullPathName(), false);
  180037. }
  180038. int64 File::getVolumeTotalSize() const
  180039. {
  180040. return getDiskSpaceInfo (getFullPathName(), true);
  180041. }
  180042. static unsigned int getWindowsDriveType (const String& path)
  180043. {
  180044. return GetDriveType (getDriveFromPath (path));
  180045. }
  180046. bool File::isOnCDRomDrive() const
  180047. {
  180048. return getWindowsDriveType (getFullPathName()) == DRIVE_CDROM;
  180049. }
  180050. bool File::isOnHardDisk() const
  180051. {
  180052. if (fullPath.isEmpty())
  180053. return false;
  180054. const unsigned int n = getWindowsDriveType (getFullPathName());
  180055. if (fullPath.toLowerCase()[0] <= 'b' && fullPath[1] == ':')
  180056. return n != DRIVE_REMOVABLE;
  180057. else
  180058. return n != DRIVE_CDROM && n != DRIVE_REMOTE;
  180059. }
  180060. bool File::isOnRemovableDrive() const
  180061. {
  180062. if (fullPath.isEmpty())
  180063. return false;
  180064. const unsigned int n = getWindowsDriveType (getFullPathName());
  180065. return n == DRIVE_CDROM
  180066. || n == DRIVE_REMOTE
  180067. || n == DRIVE_REMOVABLE
  180068. || n == DRIVE_RAMDISK;
  180069. }
  180070. static const File juce_getSpecialFolderPath (int type)
  180071. {
  180072. WCHAR path [MAX_PATH + 256];
  180073. if (SHGetSpecialFolderPath (0, path, type, FALSE))
  180074. return File (String (path));
  180075. return File::nonexistent;
  180076. }
  180077. const File JUCE_CALLTYPE File::getSpecialLocation (const SpecialLocationType type)
  180078. {
  180079. int csidlType = 0;
  180080. switch (type)
  180081. {
  180082. case userHomeDirectory: csidlType = CSIDL_PROFILE; break;
  180083. case userDocumentsDirectory: csidlType = CSIDL_PERSONAL; break;
  180084. case userDesktopDirectory: csidlType = CSIDL_DESKTOP; break;
  180085. case userApplicationDataDirectory: csidlType = CSIDL_APPDATA; break;
  180086. case commonApplicationDataDirectory: csidlType = CSIDL_COMMON_APPDATA; break;
  180087. case globalApplicationsDirectory: csidlType = CSIDL_PROGRAM_FILES; break;
  180088. case userMusicDirectory: csidlType = CSIDL_MYMUSIC; break;
  180089. case userMoviesDirectory: csidlType = CSIDL_MYVIDEO; break;
  180090. case tempDirectory:
  180091. {
  180092. WCHAR dest [2048];
  180093. dest[0] = 0;
  180094. GetTempPath (numElementsInArray (dest), dest);
  180095. return File (String (dest));
  180096. }
  180097. case invokedExecutableFile:
  180098. case currentExecutableFile:
  180099. case currentApplicationFile:
  180100. {
  180101. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  180102. WCHAR dest [MAX_PATH + 256];
  180103. dest[0] = 0;
  180104. GetModuleFileName (moduleHandle, dest, numElementsInArray (dest));
  180105. return File (String (dest));
  180106. }
  180107. break;
  180108. default:
  180109. jassertfalse // unknown type?
  180110. return File::nonexistent;
  180111. }
  180112. return juce_getSpecialFolderPath (csidlType);
  180113. }
  180114. const File File::getCurrentWorkingDirectory()
  180115. {
  180116. WCHAR dest [MAX_PATH + 256];
  180117. dest[0] = 0;
  180118. GetCurrentDirectory (numElementsInArray (dest), dest);
  180119. return File (String (dest));
  180120. }
  180121. bool File::setAsCurrentWorkingDirectory() const
  180122. {
  180123. return SetCurrentDirectory (getFullPathName()) != FALSE;
  180124. }
  180125. const String File::getVersion() const
  180126. {
  180127. String result;
  180128. DWORD handle = 0;
  180129. DWORD bufferSize = GetFileVersionInfoSize (getFullPathName(), &handle);
  180130. HeapBlock<char> buffer;
  180131. buffer.calloc (bufferSize);
  180132. if (GetFileVersionInfo (getFullPathName(), 0, bufferSize, buffer))
  180133. {
  180134. VS_FIXEDFILEINFO* vffi;
  180135. UINT len = 0;
  180136. if (VerQueryValue (buffer, (LPTSTR) _T("\\"), (LPVOID*) &vffi, &len))
  180137. {
  180138. result << (int) HIWORD (vffi->dwFileVersionMS) << '.'
  180139. << (int) LOWORD (vffi->dwFileVersionMS) << '.'
  180140. << (int) HIWORD (vffi->dwFileVersionLS) << '.'
  180141. << (int) LOWORD (vffi->dwFileVersionLS);
  180142. }
  180143. }
  180144. return result;
  180145. }
  180146. const File File::getLinkedTarget() const
  180147. {
  180148. File result (*this);
  180149. String p (getFullPathName());
  180150. if (! exists())
  180151. p += ".lnk";
  180152. else if (getFileExtension() != ".lnk")
  180153. return result;
  180154. ComSmartPtr <IShellLink> shellLink;
  180155. if (SUCCEEDED (shellLink.CoCreateInstance (CLSID_ShellLink, CLSCTX_INPROC_SERVER)))
  180156. {
  180157. ComSmartPtr <IPersistFile> persistFile;
  180158. if (SUCCEEDED (shellLink->QueryInterface (IID_IPersistFile, (LPVOID*) &persistFile)))
  180159. {
  180160. if (SUCCEEDED (persistFile->Load ((const WCHAR*) p, STGM_READ))
  180161. && SUCCEEDED (shellLink->Resolve (0, SLR_ANY_MATCH | SLR_NO_UI)))
  180162. {
  180163. WIN32_FIND_DATA winFindData;
  180164. WCHAR resolvedPath [MAX_PATH];
  180165. if (SUCCEEDED (shellLink->GetPath (resolvedPath, MAX_PATH, &winFindData, SLGP_UNCPRIORITY)))
  180166. result = File (resolvedPath);
  180167. }
  180168. }
  180169. }
  180170. return result;
  180171. }
  180172. template <class FindDataType>
  180173. static void getFindFileInfo (FindDataType& findData,
  180174. String& filename, bool* const isDir, bool* const isHidden,
  180175. int64* const fileSize, Time* const modTime, Time* const creationTime,
  180176. bool* const isReadOnly)
  180177. {
  180178. filename = findData.cFileName;
  180179. if (isDir != 0)
  180180. *isDir = ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
  180181. if (isHidden != 0)
  180182. *isHidden = ((findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0);
  180183. if (fileSize != 0)
  180184. *fileSize = findData.nFileSizeLow + (((int64) findData.nFileSizeHigh) << 32);
  180185. if (modTime != 0)
  180186. *modTime = fileTimeToTime (&findData.ftLastWriteTime);
  180187. if (creationTime != 0)
  180188. *creationTime = fileTimeToTime (&findData.ftCreationTime);
  180189. if (isReadOnly != 0)
  180190. *isReadOnly = ((findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);
  180191. }
  180192. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResult,
  180193. bool* isDir, bool* isHidden, int64* fileSize,
  180194. Time* modTime, Time* creationTime, bool* isReadOnly)
  180195. {
  180196. String wc (directory);
  180197. if (! wc.endsWithChar (File::separator))
  180198. wc += File::separator;
  180199. wc += wildCard;
  180200. WIN32_FIND_DATA findData;
  180201. HANDLE h = FindFirstFile (wc, &findData);
  180202. if (h != INVALID_HANDLE_VALUE)
  180203. {
  180204. getFindFileInfo (findData, firstResult, isDir, isHidden, fileSize,
  180205. modTime, creationTime, isReadOnly);
  180206. return h;
  180207. }
  180208. firstResult = String::empty;
  180209. return 0;
  180210. }
  180211. bool juce_findFileNext (void* handle, String& resultFile,
  180212. bool* isDir, bool* isHidden, int64* fileSize,
  180213. Time* modTime, Time* creationTime, bool* isReadOnly)
  180214. {
  180215. WIN32_FIND_DATA findData;
  180216. if (handle != 0 && FindNextFile ((HANDLE) handle, &findData) != 0)
  180217. {
  180218. getFindFileInfo (findData, resultFile, isDir, isHidden, fileSize,
  180219. modTime, creationTime, isReadOnly);
  180220. return true;
  180221. }
  180222. resultFile = String::empty;
  180223. return false;
  180224. }
  180225. void juce_findFileClose (void* handle)
  180226. {
  180227. FindClose (handle);
  180228. }
  180229. bool juce_launchFile (const String& fileName, const String& parameters)
  180230. {
  180231. HINSTANCE hInstance = 0;
  180232. JUCE_TRY
  180233. {
  180234. hInstance = ShellExecute (0, 0, fileName, parameters, 0, SW_SHOWDEFAULT);
  180235. }
  180236. JUCE_CATCH_ALL
  180237. return hInstance > (HINSTANCE) 32;
  180238. }
  180239. void File::revealToUser() const
  180240. {
  180241. if (isDirectory())
  180242. startAsProcess();
  180243. else if (getParentDirectory().exists())
  180244. getParentDirectory().startAsProcess();
  180245. }
  180246. class NamedPipeInternal
  180247. {
  180248. public:
  180249. NamedPipeInternal (const String& file, const bool isPipe_)
  180250. : pipeH (0),
  180251. cancelEvent (0),
  180252. connected (false),
  180253. isPipe (isPipe_)
  180254. {
  180255. cancelEvent = CreateEvent (0, FALSE, FALSE, 0);
  180256. pipeH = isPipe ? CreateNamedPipe (file, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, 0,
  180257. PIPE_UNLIMITED_INSTANCES, 4096, 4096, 0, 0)
  180258. : CreateFile (file, GENERIC_READ | GENERIC_WRITE, 0, 0,
  180259. OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
  180260. }
  180261. ~NamedPipeInternal()
  180262. {
  180263. disconnectPipe();
  180264. if (pipeH != 0)
  180265. CloseHandle (pipeH);
  180266. CloseHandle (cancelEvent);
  180267. }
  180268. bool connect (const int timeOutMs)
  180269. {
  180270. if (! isPipe)
  180271. return true;
  180272. if (! connected)
  180273. {
  180274. OVERLAPPED over;
  180275. zerostruct (over);
  180276. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180277. if (ConnectNamedPipe (pipeH, &over))
  180278. {
  180279. connected = false; // yes, you read that right. In overlapped mode it should always return 0.
  180280. }
  180281. else
  180282. {
  180283. const int err = GetLastError();
  180284. if (err == ERROR_IO_PENDING || err == ERROR_PIPE_LISTENING)
  180285. {
  180286. HANDLE handles[] = { over.hEvent, cancelEvent };
  180287. if (WaitForMultipleObjects (2, handles, FALSE,
  180288. timeOutMs >= 0 ? timeOutMs : INFINITE) == WAIT_OBJECT_0)
  180289. connected = true;
  180290. }
  180291. else if (err == ERROR_PIPE_CONNECTED)
  180292. {
  180293. connected = true;
  180294. }
  180295. }
  180296. CloseHandle (over.hEvent);
  180297. }
  180298. return connected;
  180299. }
  180300. void disconnectPipe()
  180301. {
  180302. if (connected)
  180303. {
  180304. DisconnectNamedPipe (pipeH);
  180305. connected = false;
  180306. }
  180307. }
  180308. HANDLE pipeH;
  180309. HANDLE cancelEvent;
  180310. bool connected, isPipe;
  180311. };
  180312. void NamedPipe::close()
  180313. {
  180314. cancelPendingReads();
  180315. const ScopedLock sl (lock);
  180316. delete static_cast<NamedPipeInternal*> (internal);
  180317. internal = 0;
  180318. }
  180319. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  180320. {
  180321. close();
  180322. ScopedPointer<NamedPipeInternal> intern (new NamedPipeInternal ("\\\\.\\pipe\\" + pipeName, createPipe));
  180323. if (intern->pipeH != INVALID_HANDLE_VALUE)
  180324. {
  180325. internal = intern.release();
  180326. return true;
  180327. }
  180328. return false;
  180329. }
  180330. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int timeOutMilliseconds)
  180331. {
  180332. const ScopedLock sl (lock);
  180333. int bytesRead = -1;
  180334. bool waitAgain = true;
  180335. while (waitAgain && internal != 0)
  180336. {
  180337. NamedPipeInternal* const intern = static_cast<NamedPipeInternal*> (internal);
  180338. waitAgain = false;
  180339. if (! intern->connect (timeOutMilliseconds))
  180340. break;
  180341. if (maxBytesToRead <= 0)
  180342. return 0;
  180343. OVERLAPPED over;
  180344. zerostruct (over);
  180345. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180346. unsigned long numRead;
  180347. if (ReadFile (intern->pipeH, destBuffer, maxBytesToRead, &numRead, &over))
  180348. {
  180349. bytesRead = (int) numRead;
  180350. }
  180351. else if (GetLastError() == ERROR_IO_PENDING)
  180352. {
  180353. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180354. DWORD waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180355. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180356. : INFINITE);
  180357. if (waitResult != WAIT_OBJECT_0)
  180358. {
  180359. // if the operation timed out, let's cancel it...
  180360. CancelIo (intern->pipeH);
  180361. WaitForSingleObject (over.hEvent, INFINITE); // makes sure cancel is complete
  180362. }
  180363. if (GetOverlappedResult (intern->pipeH, &over, &numRead, FALSE))
  180364. {
  180365. bytesRead = (int) numRead;
  180366. }
  180367. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->isPipe)
  180368. {
  180369. intern->disconnectPipe();
  180370. waitAgain = true;
  180371. }
  180372. }
  180373. else
  180374. {
  180375. waitAgain = internal != 0;
  180376. Sleep (5);
  180377. }
  180378. CloseHandle (over.hEvent);
  180379. }
  180380. return bytesRead;
  180381. }
  180382. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  180383. {
  180384. int bytesWritten = -1;
  180385. NamedPipeInternal* const intern = static_cast<NamedPipeInternal*> (internal);
  180386. if (intern != 0 && intern->connect (timeOutMilliseconds))
  180387. {
  180388. if (numBytesToWrite <= 0)
  180389. return 0;
  180390. OVERLAPPED over;
  180391. zerostruct (over);
  180392. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180393. unsigned long numWritten;
  180394. if (WriteFile (intern->pipeH, sourceBuffer, numBytesToWrite, &numWritten, &over))
  180395. {
  180396. bytesWritten = (int) numWritten;
  180397. }
  180398. else if (GetLastError() == ERROR_IO_PENDING)
  180399. {
  180400. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180401. DWORD waitResult;
  180402. waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180403. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180404. : INFINITE);
  180405. if (waitResult != WAIT_OBJECT_0)
  180406. {
  180407. CancelIo (intern->pipeH);
  180408. WaitForSingleObject (over.hEvent, INFINITE);
  180409. }
  180410. if (GetOverlappedResult (intern->pipeH, &over, &numWritten, FALSE))
  180411. {
  180412. bytesWritten = (int) numWritten;
  180413. }
  180414. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->isPipe)
  180415. {
  180416. intern->disconnectPipe();
  180417. }
  180418. }
  180419. CloseHandle (over.hEvent);
  180420. }
  180421. return bytesWritten;
  180422. }
  180423. void NamedPipe::cancelPendingReads()
  180424. {
  180425. if (internal != 0)
  180426. SetEvent (static_cast<NamedPipeInternal*> (internal)->cancelEvent);
  180427. }
  180428. #endif
  180429. /*** End of inlined file: juce_win32_Files.cpp ***/
  180430. /*** Start of inlined file: juce_win32_Network.cpp ***/
  180431. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180432. // compiled on its own).
  180433. #if JUCE_INCLUDED_FILE
  180434. #ifndef INTERNET_FLAG_NEED_FILE
  180435. #define INTERNET_FLAG_NEED_FILE 0x00000010
  180436. #endif
  180437. #ifndef INTERNET_OPTION_DISABLE_AUTODIAL
  180438. #define INTERNET_OPTION_DISABLE_AUTODIAL 70
  180439. #endif
  180440. bool juce_isOnLine()
  180441. {
  180442. DWORD connectionType;
  180443. return InternetGetConnectedState (&connectionType, 0) != 0
  180444. || (connectionType & (INTERNET_CONNECTION_LAN | INTERNET_CONNECTION_PROXY)) != 0;
  180445. }
  180446. struct ConnectionAndRequestStruct
  180447. {
  180448. HINTERNET connection, request;
  180449. };
  180450. static HINTERNET sessionHandle = 0;
  180451. #ifndef WORKAROUND_TIMEOUT_BUG
  180452. //#define WORKAROUND_TIMEOUT_BUG 1
  180453. #endif
  180454. #if WORKAROUND_TIMEOUT_BUG
  180455. // Required because of a Microsoft bug in setting a timeout
  180456. class InternetConnectThread : public Thread
  180457. {
  180458. public:
  180459. InternetConnectThread (URL_COMPONENTS& uc_, HINTERNET& connection_, const bool isFtp_)
  180460. : Thread ("Internet"), uc (uc_), connection (connection_), isFtp (isFtp_)
  180461. {
  180462. startThread();
  180463. }
  180464. ~InternetConnectThread()
  180465. {
  180466. stopThread (60000);
  180467. }
  180468. void run()
  180469. {
  180470. connection = InternetConnect (sessionHandle, uc.lpszHostName,
  180471. uc.nPort, _T(""), _T(""),
  180472. isFtp ? INTERNET_SERVICE_FTP
  180473. : INTERNET_SERVICE_HTTP,
  180474. 0, 0);
  180475. notify();
  180476. }
  180477. juce_UseDebuggingNewOperator
  180478. private:
  180479. URL_COMPONENTS& uc;
  180480. HINTERNET& connection;
  180481. const bool isFtp;
  180482. InternetConnectThread (const InternetConnectThread&);
  180483. InternetConnectThread& operator= (const InternetConnectThread&);
  180484. };
  180485. #endif
  180486. void* juce_openInternetFile (const String& url,
  180487. const String& headers,
  180488. const MemoryBlock& postData,
  180489. const bool isPost,
  180490. URL::OpenStreamProgressCallback* callback,
  180491. void* callbackContext,
  180492. int timeOutMs)
  180493. {
  180494. if (sessionHandle == 0)
  180495. sessionHandle = InternetOpen (_T("juce"),
  180496. INTERNET_OPEN_TYPE_PRECONFIG,
  180497. 0, 0, 0);
  180498. if (sessionHandle != 0)
  180499. {
  180500. // break up the url..
  180501. TCHAR file[1024], server[1024];
  180502. URL_COMPONENTS uc;
  180503. zerostruct (uc);
  180504. uc.dwStructSize = sizeof (uc);
  180505. uc.dwUrlPathLength = sizeof (file);
  180506. uc.dwHostNameLength = sizeof (server);
  180507. uc.lpszUrlPath = file;
  180508. uc.lpszHostName = server;
  180509. if (InternetCrackUrl (url, 0, 0, &uc))
  180510. {
  180511. int disable = 1;
  180512. InternetSetOption (sessionHandle, INTERNET_OPTION_DISABLE_AUTODIAL, &disable, sizeof (disable));
  180513. if (timeOutMs == 0)
  180514. timeOutMs = 30000;
  180515. else if (timeOutMs < 0)
  180516. timeOutMs = -1;
  180517. InternetSetOption (sessionHandle, INTERNET_OPTION_CONNECT_TIMEOUT, &timeOutMs, sizeof (timeOutMs));
  180518. const bool isFtp = url.startsWithIgnoreCase (T("ftp:"));
  180519. #if WORKAROUND_TIMEOUT_BUG
  180520. HINTERNET connection = 0;
  180521. {
  180522. InternetConnectThread connectThread (uc, connection, isFtp);
  180523. connectThread.wait (timeOutMs);
  180524. if (connection == 0)
  180525. {
  180526. InternetCloseHandle (sessionHandle);
  180527. sessionHandle = 0;
  180528. }
  180529. }
  180530. #else
  180531. HINTERNET connection = InternetConnect (sessionHandle,
  180532. uc.lpszHostName,
  180533. uc.nPort,
  180534. _T(""), _T(""),
  180535. isFtp ? INTERNET_SERVICE_FTP
  180536. : INTERNET_SERVICE_HTTP,
  180537. 0, 0);
  180538. #endif
  180539. if (connection != 0)
  180540. {
  180541. if (isFtp)
  180542. {
  180543. HINTERNET request = FtpOpenFile (connection,
  180544. uc.lpszUrlPath,
  180545. GENERIC_READ,
  180546. FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_NEED_FILE,
  180547. 0);
  180548. ConnectionAndRequestStruct* const result = new ConnectionAndRequestStruct();
  180549. result->connection = connection;
  180550. result->request = request;
  180551. return result;
  180552. }
  180553. else
  180554. {
  180555. const TCHAR* mimeTypes[] = { _T("*/*"), 0 };
  180556. DWORD flags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE;
  180557. if (url.startsWithIgnoreCase (T("https:")))
  180558. flags |= INTERNET_FLAG_SECURE; // (this flag only seems necessary if the OS is running IE6 -
  180559. // IE7 seems to automatically work out when it's https)
  180560. HINTERNET request = HttpOpenRequest (connection,
  180561. isPost ? _T("POST")
  180562. : _T("GET"),
  180563. uc.lpszUrlPath,
  180564. 0, 0, mimeTypes, flags, 0);
  180565. if (request != 0)
  180566. {
  180567. INTERNET_BUFFERS buffers;
  180568. zerostruct (buffers);
  180569. buffers.dwStructSize = sizeof (INTERNET_BUFFERS);
  180570. buffers.lpcszHeader = (LPCTSTR) headers;
  180571. buffers.dwHeadersLength = headers.length();
  180572. buffers.dwBufferTotal = (DWORD) postData.getSize();
  180573. ConnectionAndRequestStruct* result = 0;
  180574. if (HttpSendRequestEx (request, &buffers, 0, HSR_INITIATE, 0))
  180575. {
  180576. int bytesSent = 0;
  180577. for (;;)
  180578. {
  180579. const int bytesToDo = jmin (1024, (int) postData.getSize() - bytesSent);
  180580. DWORD bytesDone = 0;
  180581. if (bytesToDo > 0
  180582. && ! InternetWriteFile (request,
  180583. ((const char*) postData.getData()) + bytesSent,
  180584. bytesToDo, &bytesDone))
  180585. {
  180586. break;
  180587. }
  180588. if (bytesToDo == 0 || (int) bytesDone < bytesToDo)
  180589. {
  180590. result = new ConnectionAndRequestStruct();
  180591. result->connection = connection;
  180592. result->request = request;
  180593. HttpEndRequest (request, 0, 0, 0);
  180594. return result;
  180595. }
  180596. bytesSent += bytesDone;
  180597. if (callback != 0 && ! callback (callbackContext, bytesSent, postData.getSize()))
  180598. break;
  180599. }
  180600. }
  180601. InternetCloseHandle (request);
  180602. }
  180603. InternetCloseHandle (connection);
  180604. }
  180605. }
  180606. }
  180607. }
  180608. return 0;
  180609. }
  180610. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  180611. {
  180612. DWORD bytesRead = 0;
  180613. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  180614. if (crs != 0)
  180615. InternetReadFile (crs->request,
  180616. buffer, bytesToRead,
  180617. &bytesRead);
  180618. return bytesRead;
  180619. }
  180620. int juce_seekInInternetFile (void* handle, int newPosition)
  180621. {
  180622. if (handle != 0)
  180623. {
  180624. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  180625. return InternetSetFilePointer (crs->request,
  180626. newPosition, 0,
  180627. FILE_BEGIN, 0);
  180628. }
  180629. else
  180630. {
  180631. return -1;
  180632. }
  180633. }
  180634. int64 juce_getInternetFileContentLength (void* handle)
  180635. {
  180636. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  180637. if (crs != 0)
  180638. {
  180639. DWORD index = 0;
  180640. DWORD result = 0;
  180641. DWORD size = sizeof (result);
  180642. if (HttpQueryInfo (crs->request,
  180643. HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
  180644. &result,
  180645. &size,
  180646. &index))
  180647. {
  180648. return (int64) result;
  180649. }
  180650. }
  180651. return -1;
  180652. }
  180653. void juce_closeInternetFile (void* handle)
  180654. {
  180655. if (handle != 0)
  180656. {
  180657. ConnectionAndRequestStruct* const crs = (ConnectionAndRequestStruct*) handle;
  180658. InternetCloseHandle (crs->request);
  180659. InternetCloseHandle (crs->connection);
  180660. delete crs;
  180661. }
  180662. }
  180663. static int getMACAddressViaGetAdaptersInfo (int64* addresses, int maxNum, const bool littleEndian) throw()
  180664. {
  180665. int numFound = 0;
  180666. DynamicLibraryLoader dll ("iphlpapi.dll");
  180667. DynamicLibraryImport (GetAdaptersInfo, getAdaptersInfo, DWORD, dll, (PIP_ADAPTER_INFO, PULONG))
  180668. if (getAdaptersInfo != 0)
  180669. {
  180670. ULONG len = sizeof (IP_ADAPTER_INFO);
  180671. MemoryBlock mb;
  180672. PIP_ADAPTER_INFO adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  180673. if (getAdaptersInfo (adapterInfo, &len) == ERROR_BUFFER_OVERFLOW)
  180674. {
  180675. mb.setSize (len);
  180676. adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  180677. }
  180678. if (getAdaptersInfo (adapterInfo, &len) == NO_ERROR)
  180679. {
  180680. PIP_ADAPTER_INFO adapter = adapterInfo;
  180681. while (adapter != 0)
  180682. {
  180683. int64 mac = 0;
  180684. for (unsigned int i = 0; i < adapter->AddressLength; ++i)
  180685. mac = (mac << 8) | adapter->Address[i];
  180686. if (littleEndian)
  180687. mac = (int64) ByteOrder::swap ((uint64) mac);
  180688. if (numFound < maxNum && mac != 0)
  180689. addresses [numFound++] = mac;
  180690. adapter = adapter->Next;
  180691. }
  180692. }
  180693. }
  180694. return numFound;
  180695. }
  180696. struct ASTAT
  180697. {
  180698. ADAPTER_STATUS adapt;
  180699. NAME_BUFFER NameBuff [30];
  180700. };
  180701. static int getMACAddressesViaNetBios (int64* addresses, int maxNum, const bool littleEndian) throw()
  180702. {
  180703. int numFound = 0;
  180704. DynamicLibraryLoader dll ("netapi32.dll");
  180705. DynamicLibraryImport (Netbios, NetbiosCall, UCHAR, dll, (PNCB))
  180706. if (NetbiosCall != 0)
  180707. {
  180708. NCB ncb;
  180709. zerostruct (ncb);
  180710. ASTAT astat;
  180711. zerostruct (astat);
  180712. LANA_ENUM enums;
  180713. zerostruct (enums);
  180714. ncb.ncb_command = NCBENUM;
  180715. ncb.ncb_buffer = (unsigned char*) &enums;
  180716. ncb.ncb_length = sizeof (LANA_ENUM);
  180717. NetbiosCall (&ncb);
  180718. for (int i = 0; i < enums.length; ++i)
  180719. {
  180720. zerostruct (ncb);
  180721. ncb.ncb_command = NCBRESET;
  180722. ncb.ncb_lana_num = enums.lana[i];
  180723. if (NetbiosCall (&ncb) == 0)
  180724. {
  180725. zerostruct (ncb);
  180726. memcpy (ncb.ncb_callname, "* ", NCBNAMSZ);
  180727. ncb.ncb_command = NCBASTAT;
  180728. ncb.ncb_lana_num = enums.lana[i];
  180729. ncb.ncb_buffer = (unsigned char*) &astat;
  180730. ncb.ncb_length = sizeof (ASTAT);
  180731. if (NetbiosCall (&ncb) == 0)
  180732. {
  180733. if (astat.adapt.adapter_type == 0xfe)
  180734. {
  180735. uint64 mac = 0;
  180736. for (int i = 6; --i >= 0;)
  180737. mac = (mac << 8) | astat.adapt.adapter_address [littleEndian ? i : (5 - i)];
  180738. if (numFound < maxNum && mac != 0)
  180739. addresses [numFound++] = mac;
  180740. }
  180741. }
  180742. }
  180743. }
  180744. }
  180745. return numFound;
  180746. }
  180747. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
  180748. {
  180749. int numFound = getMACAddressViaGetAdaptersInfo (addresses, maxNum, littleEndian);
  180750. if (numFound == 0)
  180751. numFound = getMACAddressesViaNetBios (addresses, maxNum, littleEndian);
  180752. return numFound;
  180753. }
  180754. typedef ULONG (WINAPI *MAPISendMailType) (LHANDLE, ULONG, lpMapiMessage, ::FLAGS, ULONG);
  180755. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  180756. const String& emailSubject,
  180757. const String& bodyText,
  180758. const StringArray& filesToAttach)
  180759. {
  180760. HMODULE h = LoadLibraryA ("MAPI32.dll");
  180761. MAPISendMailType mapiSendMail = (MAPISendMailType) GetProcAddress (h, "MAPISendMail");
  180762. bool ok = false;
  180763. if (mapiSendMail != 0)
  180764. {
  180765. MapiMessage message;
  180766. zerostruct (message);
  180767. message.lpszSubject = (LPSTR) emailSubject.toCString();
  180768. message.lpszNoteText = (LPSTR) bodyText.toCString();
  180769. MapiRecipDesc recip;
  180770. zerostruct (recip);
  180771. recip.ulRecipClass = MAPI_TO;
  180772. String targetEmailAddress_ (targetEmailAddress);
  180773. if (targetEmailAddress_.isEmpty())
  180774. targetEmailAddress_ = " "; // (Windows Mail can't deal with a blank address)
  180775. recip.lpszName = (LPSTR) targetEmailAddress_.toCString();
  180776. message.nRecipCount = 1;
  180777. message.lpRecips = &recip;
  180778. MemoryBlock mb (sizeof (MapiFileDesc) * filesToAttach.size());
  180779. mb.fillWith (0);
  180780. MapiFileDesc* files = (MapiFileDesc*) mb.getData();
  180781. message.nFileCount = filesToAttach.size();
  180782. message.lpFiles = files;
  180783. for (int i = 0; i < filesToAttach.size(); ++i)
  180784. {
  180785. files[i].nPosition = (ULONG) -1;
  180786. files[i].lpszPathName = (LPSTR) filesToAttach[i].toCString();
  180787. }
  180788. ok = (mapiSendMail (0, 0, &message, MAPI_DIALOG | MAPI_LOGON_UI, 0) == SUCCESS_SUCCESS);
  180789. }
  180790. FreeLibrary (h);
  180791. return ok;
  180792. }
  180793. #endif
  180794. /*** End of inlined file: juce_win32_Network.cpp ***/
  180795. /*** Start of inlined file: juce_win32_PlatformUtils.cpp ***/
  180796. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180797. // compiled on its own).
  180798. #if JUCE_INCLUDED_FILE
  180799. static HKEY findKeyForPath (String name,
  180800. const bool createForWriting,
  180801. String& valueName)
  180802. {
  180803. HKEY rootKey = 0;
  180804. if (name.startsWithIgnoreCase (T("HKEY_CURRENT_USER\\")))
  180805. rootKey = HKEY_CURRENT_USER;
  180806. else if (name.startsWithIgnoreCase (T("HKEY_LOCAL_MACHINE\\")))
  180807. rootKey = HKEY_LOCAL_MACHINE;
  180808. else if (name.startsWithIgnoreCase (T("HKEY_CLASSES_ROOT\\")))
  180809. rootKey = HKEY_CLASSES_ROOT;
  180810. if (rootKey != 0)
  180811. {
  180812. name = name.substring (name.indexOfChar ('\\') + 1);
  180813. const int lastSlash = name.lastIndexOfChar ('\\');
  180814. valueName = name.substring (lastSlash + 1);
  180815. name = name.substring (0, lastSlash);
  180816. HKEY key;
  180817. DWORD result;
  180818. if (createForWriting)
  180819. {
  180820. if (RegCreateKeyEx (rootKey, name, 0, 0, REG_OPTION_NON_VOLATILE,
  180821. (KEY_WRITE | KEY_QUERY_VALUE), 0, &key, &result) == ERROR_SUCCESS)
  180822. return key;
  180823. }
  180824. else
  180825. {
  180826. if (RegOpenKeyEx (rootKey, name, 0, KEY_READ, &key) == ERROR_SUCCESS)
  180827. return key;
  180828. }
  180829. }
  180830. return 0;
  180831. }
  180832. const String PlatformUtilities::getRegistryValue (const String& regValuePath,
  180833. const String& defaultValue)
  180834. {
  180835. String valueName, result (defaultValue);
  180836. HKEY k = findKeyForPath (regValuePath, false, valueName);
  180837. if (k != 0)
  180838. {
  180839. WCHAR buffer [2048];
  180840. unsigned long bufferSize = sizeof (buffer);
  180841. DWORD type = REG_SZ;
  180842. if (RegQueryValueEx (k, valueName, 0, &type, (LPBYTE) buffer, &bufferSize) == ERROR_SUCCESS)
  180843. {
  180844. if (type == REG_SZ)
  180845. result = buffer;
  180846. else if (type == REG_DWORD)
  180847. result = String ((int) *(DWORD*) buffer);
  180848. }
  180849. RegCloseKey (k);
  180850. }
  180851. return result;
  180852. }
  180853. void PlatformUtilities::setRegistryValue (const String& regValuePath,
  180854. const String& value)
  180855. {
  180856. String valueName;
  180857. HKEY k = findKeyForPath (regValuePath, true, valueName);
  180858. if (k != 0)
  180859. {
  180860. RegSetValueEx (k, valueName, 0, REG_SZ,
  180861. (const BYTE*) (const WCHAR*) value,
  180862. sizeof (WCHAR) * (value.length() + 1));
  180863. RegCloseKey (k);
  180864. }
  180865. }
  180866. bool PlatformUtilities::registryValueExists (const String& regValuePath)
  180867. {
  180868. bool exists = false;
  180869. String valueName;
  180870. HKEY k = findKeyForPath (regValuePath, false, valueName);
  180871. if (k != 0)
  180872. {
  180873. unsigned char buffer [2048];
  180874. unsigned long bufferSize = sizeof (buffer);
  180875. DWORD type = 0;
  180876. if (RegQueryValueEx (k, valueName, 0, &type, buffer, &bufferSize) == ERROR_SUCCESS)
  180877. exists = true;
  180878. RegCloseKey (k);
  180879. }
  180880. return exists;
  180881. }
  180882. void PlatformUtilities::deleteRegistryValue (const String& regValuePath)
  180883. {
  180884. String valueName;
  180885. HKEY k = findKeyForPath (regValuePath, true, valueName);
  180886. if (k != 0)
  180887. {
  180888. RegDeleteValue (k, valueName);
  180889. RegCloseKey (k);
  180890. }
  180891. }
  180892. void PlatformUtilities::deleteRegistryKey (const String& regKeyPath)
  180893. {
  180894. String valueName;
  180895. HKEY k = findKeyForPath (regKeyPath, true, valueName);
  180896. if (k != 0)
  180897. {
  180898. RegDeleteKey (k, valueName);
  180899. RegCloseKey (k);
  180900. }
  180901. }
  180902. void PlatformUtilities::registerFileAssociation (const String& fileExtension,
  180903. const String& symbolicDescription,
  180904. const String& fullDescription,
  180905. const File& targetExecutable,
  180906. int iconResourceNumber)
  180907. {
  180908. setRegistryValue ("HKEY_CLASSES_ROOT\\" + fileExtension + "\\", symbolicDescription);
  180909. const String key ("HKEY_CLASSES_ROOT\\" + symbolicDescription);
  180910. if (iconResourceNumber != 0)
  180911. setRegistryValue (key + "\\DefaultIcon\\",
  180912. targetExecutable.getFullPathName() + "," + String (-iconResourceNumber));
  180913. setRegistryValue (key + "\\", fullDescription);
  180914. setRegistryValue (key + "\\shell\\open\\command\\",
  180915. targetExecutable.getFullPathName() + " %1");
  180916. }
  180917. bool juce_IsRunningInWine()
  180918. {
  180919. HKEY key;
  180920. if (RegOpenKeyEx (HKEY_CURRENT_USER, _T("Software\\Wine"), 0, KEY_READ, &key) == ERROR_SUCCESS)
  180921. {
  180922. RegCloseKey (key);
  180923. return true;
  180924. }
  180925. return false;
  180926. }
  180927. const String JUCE_CALLTYPE PlatformUtilities::getCurrentCommandLineParams() throw()
  180928. {
  180929. String s (::GetCommandLineW());
  180930. StringArray tokens;
  180931. tokens.addTokens (s, true); // tokenise so that we can remove the initial filename argument
  180932. return tokens.joinIntoString (" ", 1);
  180933. }
  180934. static void* currentModuleHandle = 0;
  180935. void* PlatformUtilities::getCurrentModuleInstanceHandle() throw()
  180936. {
  180937. if (currentModuleHandle == 0)
  180938. currentModuleHandle = GetModuleHandle (0);
  180939. return currentModuleHandle;
  180940. }
  180941. void PlatformUtilities::setCurrentModuleInstanceHandle (void* const newHandle) throw()
  180942. {
  180943. currentModuleHandle = newHandle;
  180944. }
  180945. void PlatformUtilities::fpuReset()
  180946. {
  180947. #if JUCE_MSVC
  180948. _clearfp();
  180949. #endif
  180950. }
  180951. void PlatformUtilities::beep()
  180952. {
  180953. MessageBeep (MB_OK);
  180954. }
  180955. #endif
  180956. /*** End of inlined file: juce_win32_PlatformUtils.cpp ***/
  180957. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  180958. /*** Start of inlined file: juce_win32_Messaging.cpp ***/
  180959. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180960. // compiled on its own).
  180961. #if JUCE_INCLUDED_FILE
  180962. static const unsigned int specialId = WM_APP + 0x4400;
  180963. static const unsigned int broadcastId = WM_APP + 0x4403;
  180964. static const unsigned int specialCallbackId = WM_APP + 0x4402;
  180965. static const TCHAR* const messageWindowName = _T("JUCEWindow");
  180966. HWND juce_messageWindowHandle = 0;
  180967. extern long improbableWindowNumber; // defined in windowing.cpp
  180968. #ifndef WM_APPCOMMAND
  180969. #define WM_APPCOMMAND 0x0319
  180970. #endif
  180971. static LRESULT CALLBACK juce_MessageWndProc (HWND h,
  180972. const UINT message,
  180973. const WPARAM wParam,
  180974. const LPARAM lParam) throw()
  180975. {
  180976. JUCE_TRY
  180977. {
  180978. if (h == juce_messageWindowHandle)
  180979. {
  180980. if (message == specialCallbackId)
  180981. {
  180982. MessageCallbackFunction* const func = (MessageCallbackFunction*) wParam;
  180983. return (LRESULT) (*func) ((void*) lParam);
  180984. }
  180985. else if (message == specialId)
  180986. {
  180987. // these are trapped early in the dispatch call, but must also be checked
  180988. // here in case there are windows modal dialog boxes doing their own
  180989. // dispatch loop and not calling our version
  180990. MessageManager::getInstance()->deliverMessage ((void*) lParam);
  180991. return 0;
  180992. }
  180993. else if (message == broadcastId)
  180994. {
  180995. const ScopedPointer <String> messageString ((String*) lParam);
  180996. MessageManager::getInstance()->deliverBroadcastMessage (*messageString);
  180997. return 0;
  180998. }
  180999. else if (message == WM_COPYDATA && ((const COPYDATASTRUCT*) lParam)->dwData == broadcastId)
  181000. {
  181001. const String messageString ((const juce_wchar*) ((const COPYDATASTRUCT*) lParam)->lpData,
  181002. ((const COPYDATASTRUCT*) lParam)->cbData / sizeof (juce_wchar));
  181003. PostMessage (juce_messageWindowHandle, broadcastId, 0, (LPARAM) new String (messageString));
  181004. return 0;
  181005. }
  181006. }
  181007. }
  181008. JUCE_CATCH_EXCEPTION
  181009. return DefWindowProc (h, message, wParam, lParam);
  181010. }
  181011. static bool isEventBlockedByModalComps (MSG& m)
  181012. {
  181013. if (Component::getNumCurrentlyModalComponents() == 0
  181014. || GetWindowLong (m.hwnd, GWLP_USERDATA) == improbableWindowNumber)
  181015. return false;
  181016. switch (m.message)
  181017. {
  181018. case WM_MOUSEMOVE:
  181019. case WM_NCMOUSEMOVE:
  181020. case 0x020A: /* WM_MOUSEWHEEL */
  181021. case 0x020E: /* WM_MOUSEHWHEEL */
  181022. case WM_KEYUP:
  181023. case WM_SYSKEYUP:
  181024. case WM_CHAR:
  181025. case WM_APPCOMMAND:
  181026. case WM_LBUTTONUP:
  181027. case WM_MBUTTONUP:
  181028. case WM_RBUTTONUP:
  181029. case WM_MOUSEACTIVATE:
  181030. case WM_NCMOUSEHOVER:
  181031. case WM_MOUSEHOVER:
  181032. return true;
  181033. case WM_NCLBUTTONDOWN:
  181034. case WM_NCLBUTTONDBLCLK:
  181035. case WM_NCRBUTTONDOWN:
  181036. case WM_NCRBUTTONDBLCLK:
  181037. case WM_NCMBUTTONDOWN:
  181038. case WM_NCMBUTTONDBLCLK:
  181039. case WM_LBUTTONDOWN:
  181040. case WM_LBUTTONDBLCLK:
  181041. case WM_MBUTTONDOWN:
  181042. case WM_MBUTTONDBLCLK:
  181043. case WM_RBUTTONDOWN:
  181044. case WM_RBUTTONDBLCLK:
  181045. case WM_KEYDOWN:
  181046. case WM_SYSKEYDOWN:
  181047. {
  181048. Component* const modal = Component::getCurrentlyModalComponent (0);
  181049. if (modal != 0)
  181050. modal->inputAttemptWhenModal();
  181051. return true;
  181052. }
  181053. default:
  181054. break;
  181055. }
  181056. return false;
  181057. }
  181058. bool juce_dispatchNextMessageOnSystemQueue (const bool returnIfNoPendingMessages)
  181059. {
  181060. MSG m;
  181061. if (returnIfNoPendingMessages && ! PeekMessage (&m, (HWND) 0, 0, 0, 0))
  181062. return false;
  181063. if (GetMessage (&m, (HWND) 0, 0, 0) >= 0)
  181064. {
  181065. if (m.message == specialId && m.hwnd == juce_messageWindowHandle)
  181066. {
  181067. MessageManager::getInstance()->deliverMessage ((void*) m.lParam);
  181068. }
  181069. else if (m.message == WM_QUIT)
  181070. {
  181071. if (JUCEApplication::getInstance())
  181072. JUCEApplication::getInstance()->systemRequestedQuit();
  181073. }
  181074. else if (! isEventBlockedByModalComps (m))
  181075. {
  181076. if ((m.message == WM_LBUTTONDOWN || m.message == WM_RBUTTONDOWN)
  181077. && GetWindowLong (m.hwnd, GWLP_USERDATA) != improbableWindowNumber)
  181078. {
  181079. // if it's someone else's window being clicked on, and the focus is
  181080. // currently on a juce window, pass the kb focus over..
  181081. HWND currentFocus = GetFocus();
  181082. if (currentFocus == 0 || GetWindowLong (currentFocus, GWLP_USERDATA) == improbableWindowNumber)
  181083. SetFocus (m.hwnd);
  181084. }
  181085. TranslateMessage (&m);
  181086. DispatchMessage (&m);
  181087. }
  181088. }
  181089. return true;
  181090. }
  181091. bool juce_postMessageToSystemQueue (void* message)
  181092. {
  181093. return PostMessage (juce_messageWindowHandle, specialId, 0, (LPARAM) message) != 0;
  181094. }
  181095. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  181096. void* userData)
  181097. {
  181098. if (MessageManager::getInstance()->isThisTheMessageThread())
  181099. {
  181100. return (*callback) (userData);
  181101. }
  181102. else
  181103. {
  181104. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  181105. // deadlock because the message manager is blocked from running, and can't
  181106. // call your function..
  181107. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  181108. return (void*) SendMessage (juce_messageWindowHandle,
  181109. specialCallbackId,
  181110. (WPARAM) callback,
  181111. (LPARAM) userData);
  181112. }
  181113. }
  181114. static BOOL CALLBACK BroadcastEnumWindowProc (HWND hwnd, LPARAM lParam)
  181115. {
  181116. if (hwnd != juce_messageWindowHandle)
  181117. (reinterpret_cast <VoidArray*> (lParam))->add ((void*) hwnd);
  181118. return TRUE;
  181119. }
  181120. void MessageManager::broadcastMessage (const String& value) throw()
  181121. {
  181122. VoidArray windows;
  181123. EnumWindows (&BroadcastEnumWindowProc, (LPARAM) &windows);
  181124. const String localCopy (value);
  181125. COPYDATASTRUCT data;
  181126. data.dwData = broadcastId;
  181127. data.cbData = (localCopy.length() + 1) * sizeof (juce_wchar);
  181128. data.lpData = (void*) (const juce_wchar*) localCopy;
  181129. for (int i = windows.size(); --i >= 0;)
  181130. {
  181131. HWND hwnd = (HWND) windows.getUnchecked(i);
  181132. TCHAR windowName [64]; // no need to read longer strings than this
  181133. GetWindowText (hwnd, windowName, 64);
  181134. windowName [63] = 0;
  181135. if (String (windowName) == String (messageWindowName))
  181136. {
  181137. DWORD_PTR result;
  181138. SendMessageTimeout (hwnd, WM_COPYDATA,
  181139. (WPARAM) juce_messageWindowHandle,
  181140. (LPARAM) &data,
  181141. SMTO_BLOCK | SMTO_ABORTIFHUNG,
  181142. 8000,
  181143. &result);
  181144. }
  181145. }
  181146. }
  181147. static const String getMessageWindowClassName()
  181148. {
  181149. // this name has to be different for each app/dll instance because otherwise
  181150. // poor old Win32 can get a bit confused (even despite it not being a process-global
  181151. // window class).
  181152. static int number = 0;
  181153. if (number == 0)
  181154. number = 0x7fffffff & (int) Time::getHighResolutionTicks();
  181155. return "JUCEcs_" + String (number);
  181156. }
  181157. void MessageManager::doPlatformSpecificInitialisation()
  181158. {
  181159. OleInitialize (0);
  181160. const String className (getMessageWindowClassName());
  181161. HMODULE hmod = (HMODULE) PlatformUtilities::getCurrentModuleInstanceHandle();
  181162. WNDCLASSEX wc;
  181163. zerostruct (wc);
  181164. wc.cbSize = sizeof (wc);
  181165. wc.lpfnWndProc = (WNDPROC) juce_MessageWndProc;
  181166. wc.cbWndExtra = 4;
  181167. wc.hInstance = hmod;
  181168. wc.lpszClassName = className;
  181169. RegisterClassEx (&wc);
  181170. juce_messageWindowHandle = CreateWindow (wc.lpszClassName,
  181171. messageWindowName,
  181172. 0, 0, 0, 0, 0, 0, 0,
  181173. hmod, 0);
  181174. }
  181175. void MessageManager::doPlatformSpecificShutdown()
  181176. {
  181177. DestroyWindow (juce_messageWindowHandle);
  181178. UnregisterClass (getMessageWindowClassName(), 0);
  181179. OleUninitialize();
  181180. }
  181181. #endif
  181182. /*** End of inlined file: juce_win32_Messaging.cpp ***/
  181183. /*** Start of inlined file: juce_win32_Windowing.cpp ***/
  181184. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181185. // compiled on its own).
  181186. #if JUCE_INCLUDED_FILE
  181187. #undef GetSystemMetrics // multimon overrides this for some reason and causes a mess..
  181188. // these are in the windows SDK, but need to be repeated here for GCC..
  181189. #ifndef GET_APPCOMMAND_LPARAM
  181190. #define FAPPCOMMAND_MASK 0xF000
  181191. #define GET_APPCOMMAND_LPARAM(lParam) ((short) (HIWORD (lParam) & ~FAPPCOMMAND_MASK))
  181192. #define APPCOMMAND_MEDIA_NEXTTRACK 11
  181193. #define APPCOMMAND_MEDIA_PREVIOUSTRACK 12
  181194. #define APPCOMMAND_MEDIA_STOP 13
  181195. #define APPCOMMAND_MEDIA_PLAY_PAUSE 14
  181196. #define WM_APPCOMMAND 0x0319
  181197. #endif
  181198. extern void juce_repeatLastProcessPriority(); // in juce_win32_Threads.cpp
  181199. extern void juce_CheckCurrentlyFocusedTopLevelWindow(); // in juce_TopLevelWindow.cpp
  181200. extern bool juce_IsRunningInWine();
  181201. #ifndef ULW_ALPHA
  181202. #define ULW_ALPHA 0x00000002
  181203. #endif
  181204. #ifndef AC_SRC_ALPHA
  181205. #define AC_SRC_ALPHA 0x01
  181206. #endif
  181207. static HPALETTE palette = 0;
  181208. static bool createPaletteIfNeeded = true;
  181209. static bool shouldDeactivateTitleBar = true;
  181210. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw();
  181211. #define WM_TRAYNOTIFY WM_USER + 100
  181212. using ::abs;
  181213. typedef BOOL (WINAPI* UpdateLayeredWinFunc) (HWND, HDC, POINT*, SIZE*, HDC, POINT*, COLORREF, BLENDFUNCTION*, DWORD);
  181214. static UpdateLayeredWinFunc updateLayeredWindow = 0;
  181215. bool Desktop::canUseSemiTransparentWindows() throw()
  181216. {
  181217. if (updateLayeredWindow == 0)
  181218. {
  181219. if (! juce_IsRunningInWine())
  181220. {
  181221. HMODULE user32Mod = GetModuleHandle (_T("user32.dll"));
  181222. updateLayeredWindow = (UpdateLayeredWinFunc) GetProcAddress (user32Mod, "UpdateLayeredWindow");
  181223. }
  181224. }
  181225. return updateLayeredWindow != 0;
  181226. }
  181227. const int extendedKeyModifier = 0x10000;
  181228. const int KeyPress::spaceKey = VK_SPACE;
  181229. const int KeyPress::returnKey = VK_RETURN;
  181230. const int KeyPress::escapeKey = VK_ESCAPE;
  181231. const int KeyPress::backspaceKey = VK_BACK;
  181232. const int KeyPress::deleteKey = VK_DELETE | extendedKeyModifier;
  181233. const int KeyPress::insertKey = VK_INSERT | extendedKeyModifier;
  181234. const int KeyPress::tabKey = VK_TAB;
  181235. const int KeyPress::leftKey = VK_LEFT | extendedKeyModifier;
  181236. const int KeyPress::rightKey = VK_RIGHT | extendedKeyModifier;
  181237. const int KeyPress::upKey = VK_UP | extendedKeyModifier;
  181238. const int KeyPress::downKey = VK_DOWN | extendedKeyModifier;
  181239. const int KeyPress::homeKey = VK_HOME | extendedKeyModifier;
  181240. const int KeyPress::endKey = VK_END | extendedKeyModifier;
  181241. const int KeyPress::pageUpKey = VK_PRIOR | extendedKeyModifier;
  181242. const int KeyPress::pageDownKey = VK_NEXT | extendedKeyModifier;
  181243. const int KeyPress::F1Key = VK_F1 | extendedKeyModifier;
  181244. const int KeyPress::F2Key = VK_F2 | extendedKeyModifier;
  181245. const int KeyPress::F3Key = VK_F3 | extendedKeyModifier;
  181246. const int KeyPress::F4Key = VK_F4 | extendedKeyModifier;
  181247. const int KeyPress::F5Key = VK_F5 | extendedKeyModifier;
  181248. const int KeyPress::F6Key = VK_F6 | extendedKeyModifier;
  181249. const int KeyPress::F7Key = VK_F7 | extendedKeyModifier;
  181250. const int KeyPress::F8Key = VK_F8 | extendedKeyModifier;
  181251. const int KeyPress::F9Key = VK_F9 | extendedKeyModifier;
  181252. const int KeyPress::F10Key = VK_F10 | extendedKeyModifier;
  181253. const int KeyPress::F11Key = VK_F11 | extendedKeyModifier;
  181254. const int KeyPress::F12Key = VK_F12 | extendedKeyModifier;
  181255. const int KeyPress::F13Key = VK_F13 | extendedKeyModifier;
  181256. const int KeyPress::F14Key = VK_F14 | extendedKeyModifier;
  181257. const int KeyPress::F15Key = VK_F15 | extendedKeyModifier;
  181258. const int KeyPress::F16Key = VK_F16 | extendedKeyModifier;
  181259. const int KeyPress::numberPad0 = VK_NUMPAD0 | extendedKeyModifier;
  181260. const int KeyPress::numberPad1 = VK_NUMPAD1 | extendedKeyModifier;
  181261. const int KeyPress::numberPad2 = VK_NUMPAD2 | extendedKeyModifier;
  181262. const int KeyPress::numberPad3 = VK_NUMPAD3 | extendedKeyModifier;
  181263. const int KeyPress::numberPad4 = VK_NUMPAD4 | extendedKeyModifier;
  181264. const int KeyPress::numberPad5 = VK_NUMPAD5 | extendedKeyModifier;
  181265. const int KeyPress::numberPad6 = VK_NUMPAD6 | extendedKeyModifier;
  181266. const int KeyPress::numberPad7 = VK_NUMPAD7 | extendedKeyModifier;
  181267. const int KeyPress::numberPad8 = VK_NUMPAD8 | extendedKeyModifier;
  181268. const int KeyPress::numberPad9 = VK_NUMPAD9 | extendedKeyModifier;
  181269. const int KeyPress::numberPadAdd = VK_ADD | extendedKeyModifier;
  181270. const int KeyPress::numberPadSubtract = VK_SUBTRACT | extendedKeyModifier;
  181271. const int KeyPress::numberPadMultiply = VK_MULTIPLY | extendedKeyModifier;
  181272. const int KeyPress::numberPadDivide = VK_DIVIDE | extendedKeyModifier;
  181273. const int KeyPress::numberPadSeparator = VK_SEPARATOR | extendedKeyModifier;
  181274. const int KeyPress::numberPadDecimalPoint = VK_DECIMAL | extendedKeyModifier;
  181275. const int KeyPress::numberPadEquals = 0x92 /*VK_OEM_NEC_EQUAL*/ | extendedKeyModifier;
  181276. const int KeyPress::numberPadDelete = VK_DELETE | extendedKeyModifier;
  181277. const int KeyPress::playKey = 0x30000;
  181278. const int KeyPress::stopKey = 0x30001;
  181279. const int KeyPress::fastForwardKey = 0x30002;
  181280. const int KeyPress::rewindKey = 0x30003;
  181281. class WindowsBitmapImage : public Image
  181282. {
  181283. public:
  181284. HBITMAP hBitmap;
  181285. BITMAPV4HEADER bitmapInfo;
  181286. HDC hdc;
  181287. unsigned char* bitmapData;
  181288. WindowsBitmapImage (const PixelFormat format_,
  181289. const int w, const int h, const bool clearImage)
  181290. : Image (format_, w, h)
  181291. {
  181292. jassert (format_ == RGB || format_ == ARGB);
  181293. pixelStride = (format_ == RGB) ? 3 : 4;
  181294. zerostruct (bitmapInfo);
  181295. bitmapInfo.bV4Size = sizeof (BITMAPV4HEADER);
  181296. bitmapInfo.bV4Width = w;
  181297. bitmapInfo.bV4Height = h;
  181298. bitmapInfo.bV4Planes = 1;
  181299. bitmapInfo.bV4CSType = 1;
  181300. bitmapInfo.bV4BitCount = (unsigned short) (pixelStride * 8);
  181301. if (format_ == ARGB)
  181302. {
  181303. bitmapInfo.bV4AlphaMask = 0xff000000;
  181304. bitmapInfo.bV4RedMask = 0xff0000;
  181305. bitmapInfo.bV4GreenMask = 0xff00;
  181306. bitmapInfo.bV4BlueMask = 0xff;
  181307. bitmapInfo.bV4V4Compression = BI_BITFIELDS;
  181308. }
  181309. else
  181310. {
  181311. bitmapInfo.bV4V4Compression = BI_RGB;
  181312. }
  181313. lineStride = -((w * pixelStride + 3) & ~3);
  181314. HDC dc = GetDC (0);
  181315. hdc = CreateCompatibleDC (dc);
  181316. ReleaseDC (0, dc);
  181317. SetMapMode (hdc, MM_TEXT);
  181318. hBitmap = CreateDIBSection (hdc,
  181319. (BITMAPINFO*) &(bitmapInfo),
  181320. DIB_RGB_COLORS,
  181321. (void**) &bitmapData,
  181322. 0, 0);
  181323. SelectObject (hdc, hBitmap);
  181324. if (format_ == ARGB && clearImage)
  181325. zeromem (bitmapData, abs (h * lineStride));
  181326. imageData = bitmapData - (lineStride * (h - 1));
  181327. }
  181328. ~WindowsBitmapImage()
  181329. {
  181330. DeleteDC (hdc);
  181331. DeleteObject (hBitmap);
  181332. }
  181333. void blitToWindow (HWND hwnd, HDC dc, const bool transparent,
  181334. const int x, const int y,
  181335. const RectangleList& maskedRegion) throw()
  181336. {
  181337. static HDRAWDIB hdd = 0;
  181338. static bool needToCreateDrawDib = true;
  181339. if (needToCreateDrawDib)
  181340. {
  181341. needToCreateDrawDib = false;
  181342. HDC dc = GetDC (0);
  181343. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181344. ReleaseDC (0, dc);
  181345. // only open if we're not palettised
  181346. if (n > 8)
  181347. hdd = DrawDibOpen();
  181348. }
  181349. if (createPaletteIfNeeded)
  181350. {
  181351. HDC dc = GetDC (0);
  181352. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181353. ReleaseDC (0, dc);
  181354. if (n <= 8)
  181355. palette = CreateHalftonePalette (dc);
  181356. createPaletteIfNeeded = false;
  181357. }
  181358. if (palette != 0)
  181359. {
  181360. SelectPalette (dc, palette, FALSE);
  181361. RealizePalette (dc);
  181362. SetStretchBltMode (dc, HALFTONE);
  181363. }
  181364. SetMapMode (dc, MM_TEXT);
  181365. if (transparent)
  181366. {
  181367. POINT p, pos;
  181368. SIZE size;
  181369. RECT windowBounds;
  181370. GetWindowRect (hwnd, &windowBounds);
  181371. p.x = -x;
  181372. p.y = -y;
  181373. pos.x = windowBounds.left;
  181374. pos.y = windowBounds.top;
  181375. size.cx = windowBounds.right - windowBounds.left;
  181376. size.cy = windowBounds.bottom - windowBounds.top;
  181377. BLENDFUNCTION bf;
  181378. bf.AlphaFormat = AC_SRC_ALPHA;
  181379. bf.BlendFlags = 0;
  181380. bf.BlendOp = AC_SRC_OVER;
  181381. bf.SourceConstantAlpha = 0xff;
  181382. if (! maskedRegion.isEmpty())
  181383. {
  181384. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181385. {
  181386. const Rectangle<int>& r = *i.getRectangle();
  181387. ExcludeClipRect (hdc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181388. }
  181389. }
  181390. updateLayeredWindow (hwnd, 0, &pos, &size, hdc, &p, 0, &bf, ULW_ALPHA);
  181391. }
  181392. else
  181393. {
  181394. int savedDC = 0;
  181395. if (! maskedRegion.isEmpty())
  181396. {
  181397. savedDC = SaveDC (dc);
  181398. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181399. {
  181400. const Rectangle<int>& r = *i.getRectangle();
  181401. ExcludeClipRect (dc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181402. }
  181403. }
  181404. const int w = getWidth();
  181405. const int h = getHeight();
  181406. if (hdd == 0)
  181407. {
  181408. StretchDIBits (dc,
  181409. x, y, w, h,
  181410. 0, 0, w, h,
  181411. bitmapData, (const BITMAPINFO*) &bitmapInfo,
  181412. DIB_RGB_COLORS, SRCCOPY);
  181413. }
  181414. else
  181415. {
  181416. DrawDibDraw (hdd, dc, x, y, -1, -1,
  181417. (BITMAPINFOHEADER*) &bitmapInfo, bitmapData,
  181418. 0, 0, w, h, 0);
  181419. }
  181420. if (! maskedRegion.isEmpty())
  181421. RestoreDC (dc, savedDC);
  181422. }
  181423. }
  181424. juce_UseDebuggingNewOperator
  181425. private:
  181426. WindowsBitmapImage (const WindowsBitmapImage&);
  181427. WindowsBitmapImage& operator= (const WindowsBitmapImage&);
  181428. };
  181429. long improbableWindowNumber = 0xf965aa01; // also referenced by messaging.cpp
  181430. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  181431. {
  181432. SHORT k = (SHORT) keyCode;
  181433. if ((keyCode & extendedKeyModifier) == 0
  181434. && (k >= (SHORT) 'a' && k <= (SHORT) 'z'))
  181435. k += (SHORT) 'A' - (SHORT) 'a';
  181436. const SHORT translatedValues[] = { (SHORT) ',', VK_OEM_COMMA,
  181437. (SHORT) '+', VK_OEM_PLUS,
  181438. (SHORT) '-', VK_OEM_MINUS,
  181439. (SHORT) '.', VK_OEM_PERIOD,
  181440. (SHORT) ';', VK_OEM_1,
  181441. (SHORT) ':', VK_OEM_1,
  181442. (SHORT) '/', VK_OEM_2,
  181443. (SHORT) '?', VK_OEM_2,
  181444. (SHORT) '[', VK_OEM_4,
  181445. (SHORT) ']', VK_OEM_6 };
  181446. for (int i = 0; i < numElementsInArray (translatedValues); i += 2)
  181447. if (k == translatedValues [i])
  181448. k = translatedValues [i + 1];
  181449. return (GetKeyState (k) & 0x8000) != 0;
  181450. }
  181451. static void* callFunctionIfNotLocked (MessageCallbackFunction* callback, void* userData)
  181452. {
  181453. if (MessageManager::getInstance()->currentThreadHasLockedMessageManager())
  181454. return callback (userData);
  181455. else
  181456. return MessageManager::getInstance()->callFunctionOnMessageThread (callback, userData);
  181457. }
  181458. class Win32ComponentPeer : public ComponentPeer
  181459. {
  181460. public:
  181461. Win32ComponentPeer (Component* const component,
  181462. const int windowStyleFlags)
  181463. : ComponentPeer (component, windowStyleFlags),
  181464. dontRepaint (false),
  181465. fullScreen (false),
  181466. isDragging (false),
  181467. isMouseOver (false),
  181468. hasCreatedCaret (false),
  181469. currentWindowIcon (0),
  181470. taskBarIcon (0),
  181471. dropTarget (0)
  181472. {
  181473. callFunctionIfNotLocked (&createWindowCallback, (void*) this);
  181474. setTitle (component->getName());
  181475. if ((windowStyleFlags & windowHasDropShadow) != 0
  181476. && Desktop::canUseSemiTransparentWindows())
  181477. {
  181478. shadower = component->getLookAndFeel().createDropShadowerForComponent (component);
  181479. if (shadower != 0)
  181480. shadower->setOwner (component);
  181481. }
  181482. else
  181483. {
  181484. shadower = 0;
  181485. }
  181486. }
  181487. ~Win32ComponentPeer()
  181488. {
  181489. setTaskBarIcon (0);
  181490. deleteAndZero (shadower);
  181491. // do this before the next bit to avoid messages arriving for this window
  181492. // before it's destroyed
  181493. SetWindowLongPtr (hwnd, GWLP_USERDATA, 0);
  181494. callFunctionIfNotLocked (&destroyWindowCallback, (void*) hwnd);
  181495. if (currentWindowIcon != 0)
  181496. DestroyIcon (currentWindowIcon);
  181497. if (dropTarget != 0)
  181498. {
  181499. dropTarget->Release();
  181500. dropTarget = 0;
  181501. }
  181502. }
  181503. void* getNativeHandle() const
  181504. {
  181505. return (void*) hwnd;
  181506. }
  181507. void setVisible (bool shouldBeVisible)
  181508. {
  181509. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  181510. if (shouldBeVisible)
  181511. InvalidateRect (hwnd, 0, 0);
  181512. else
  181513. lastPaintTime = 0;
  181514. }
  181515. void setTitle (const String& title)
  181516. {
  181517. SetWindowText (hwnd, title);
  181518. }
  181519. void setPosition (int x, int y)
  181520. {
  181521. offsetWithinParent (x, y);
  181522. SetWindowPos (hwnd, 0,
  181523. x - windowBorder.getLeft(),
  181524. y - windowBorder.getTop(),
  181525. 0, 0,
  181526. SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181527. }
  181528. void repaintNowIfTransparent()
  181529. {
  181530. if (isTransparent() && lastPaintTime > 0 && Time::getMillisecondCounter() > lastPaintTime + 30)
  181531. handlePaintMessage();
  181532. }
  181533. void updateBorderSize()
  181534. {
  181535. WINDOWINFO info;
  181536. info.cbSize = sizeof (info);
  181537. if (GetWindowInfo (hwnd, &info))
  181538. {
  181539. windowBorder = BorderSize (info.rcClient.top - info.rcWindow.top,
  181540. info.rcClient.left - info.rcWindow.left,
  181541. info.rcWindow.bottom - info.rcClient.bottom,
  181542. info.rcWindow.right - info.rcClient.right);
  181543. }
  181544. }
  181545. void setSize (int w, int h)
  181546. {
  181547. SetWindowPos (hwnd, 0, 0, 0,
  181548. w + windowBorder.getLeftAndRight(),
  181549. h + windowBorder.getTopAndBottom(),
  181550. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181551. updateBorderSize();
  181552. repaintNowIfTransparent();
  181553. }
  181554. void setBounds (int x, int y, int w, int h, bool isNowFullScreen)
  181555. {
  181556. fullScreen = isNowFullScreen;
  181557. offsetWithinParent (x, y);
  181558. SetWindowPos (hwnd, 0,
  181559. x - windowBorder.getLeft(),
  181560. y - windowBorder.getTop(),
  181561. w + windowBorder.getLeftAndRight(),
  181562. h + windowBorder.getTopAndBottom(),
  181563. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181564. updateBorderSize();
  181565. repaintNowIfTransparent();
  181566. }
  181567. const Rectangle<int> getBounds() const
  181568. {
  181569. RECT r;
  181570. GetWindowRect (hwnd, &r);
  181571. Rectangle<int> bounds (r.left, r.top, r.right - r.left, r.bottom - r.top);
  181572. HWND parentH = GetParent (hwnd);
  181573. if (parentH != 0)
  181574. {
  181575. GetWindowRect (parentH, &r);
  181576. bounds.translate (-r.left, -r.top);
  181577. }
  181578. return windowBorder.subtractedFrom (bounds);
  181579. }
  181580. const Point<int> getScreenPosition() const
  181581. {
  181582. RECT r;
  181583. GetWindowRect (hwnd, &r);
  181584. return Point<int> (r.left + windowBorder.getLeft(),
  181585. r.top + windowBorder.getTop());
  181586. }
  181587. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  181588. {
  181589. return relativePosition + getScreenPosition();
  181590. }
  181591. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  181592. {
  181593. return screenPosition - getScreenPosition();
  181594. }
  181595. void setMinimised (bool shouldBeMinimised)
  181596. {
  181597. if (shouldBeMinimised != isMinimised())
  181598. ShowWindow (hwnd, shouldBeMinimised ? SW_MINIMIZE : SW_SHOWNORMAL);
  181599. }
  181600. bool isMinimised() const
  181601. {
  181602. WINDOWPLACEMENT wp;
  181603. wp.length = sizeof (WINDOWPLACEMENT);
  181604. GetWindowPlacement (hwnd, &wp);
  181605. return wp.showCmd == SW_SHOWMINIMIZED;
  181606. }
  181607. void setFullScreen (bool shouldBeFullScreen)
  181608. {
  181609. setMinimised (false);
  181610. if (fullScreen != shouldBeFullScreen)
  181611. {
  181612. fullScreen = shouldBeFullScreen;
  181613. const Component::SafePointer<Component> deletionChecker (component);
  181614. if (! fullScreen)
  181615. {
  181616. const Rectangle<int> boundsCopy (lastNonFullscreenBounds);
  181617. if (hasTitleBar())
  181618. ShowWindow (hwnd, SW_SHOWNORMAL);
  181619. if (! boundsCopy.isEmpty())
  181620. {
  181621. setBounds (boundsCopy.getX(),
  181622. boundsCopy.getY(),
  181623. boundsCopy.getWidth(),
  181624. boundsCopy.getHeight(),
  181625. false);
  181626. }
  181627. }
  181628. else
  181629. {
  181630. if (hasTitleBar())
  181631. ShowWindow (hwnd, SW_SHOWMAXIMIZED);
  181632. else
  181633. SendMessageW (hwnd, WM_SETTINGCHANGE, 0, 0);
  181634. }
  181635. if (deletionChecker != 0)
  181636. handleMovedOrResized();
  181637. }
  181638. }
  181639. bool isFullScreen() const
  181640. {
  181641. if (! hasTitleBar())
  181642. return fullScreen;
  181643. WINDOWPLACEMENT wp;
  181644. wp.length = sizeof (wp);
  181645. GetWindowPlacement (hwnd, &wp);
  181646. return wp.showCmd == SW_SHOWMAXIMIZED;
  181647. }
  181648. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const
  181649. {
  181650. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  181651. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  181652. return false;
  181653. RECT r;
  181654. GetWindowRect (hwnd, &r);
  181655. POINT p;
  181656. p.x = position.getX() + r.left + windowBorder.getLeft();
  181657. p.y = position.getY() + r.top + windowBorder.getTop();
  181658. HWND w = WindowFromPoint (p);
  181659. return w == hwnd || (trueIfInAChildWindow && (IsChild (hwnd, w) != 0));
  181660. }
  181661. const BorderSize getFrameSize() const
  181662. {
  181663. return windowBorder;
  181664. }
  181665. bool setAlwaysOnTop (bool alwaysOnTop)
  181666. {
  181667. const bool oldDeactivate = shouldDeactivateTitleBar;
  181668. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181669. SetWindowPos (hwnd, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,
  181670. 0, 0, 0, 0,
  181671. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181672. shouldDeactivateTitleBar = oldDeactivate;
  181673. if (shadower != 0)
  181674. shadower->componentBroughtToFront (*component);
  181675. return true;
  181676. }
  181677. void toFront (bool makeActive)
  181678. {
  181679. setMinimised (false);
  181680. const bool oldDeactivate = shouldDeactivateTitleBar;
  181681. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181682. callFunctionIfNotLocked (makeActive ? &toFrontCallback1
  181683. : &toFrontCallback2,
  181684. (void*) hwnd);
  181685. shouldDeactivateTitleBar = oldDeactivate;
  181686. if (! makeActive)
  181687. {
  181688. // in this case a broughttofront call won't have occured, so do it now..
  181689. handleBroughtToFront();
  181690. }
  181691. }
  181692. void toBehind (ComponentPeer* other)
  181693. {
  181694. Win32ComponentPeer* const otherPeer = dynamic_cast <Win32ComponentPeer*> (other);
  181695. jassert (otherPeer != 0); // wrong type of window?
  181696. if (otherPeer != 0)
  181697. {
  181698. setMinimised (false);
  181699. // must be careful not to try to put a topmost window behind a normal one, or win32
  181700. // promotes the normal one to be topmost!
  181701. if (getComponent()->isAlwaysOnTop() == otherPeer->getComponent()->isAlwaysOnTop())
  181702. SetWindowPos (hwnd, otherPeer->hwnd, 0, 0, 0, 0,
  181703. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181704. else if (otherPeer->getComponent()->isAlwaysOnTop())
  181705. SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
  181706. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181707. }
  181708. }
  181709. bool isFocused() const
  181710. {
  181711. return callFunctionIfNotLocked (&getFocusCallback, 0) == (void*) hwnd;
  181712. }
  181713. void grabFocus()
  181714. {
  181715. const bool oldDeactivate = shouldDeactivateTitleBar;
  181716. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181717. callFunctionIfNotLocked (&setFocusCallback, (void*) hwnd);
  181718. shouldDeactivateTitleBar = oldDeactivate;
  181719. }
  181720. void textInputRequired (const Point<int>&)
  181721. {
  181722. if (! hasCreatedCaret)
  181723. {
  181724. hasCreatedCaret = true;
  181725. CreateCaret (hwnd, (HBITMAP) 1, 0, 0);
  181726. }
  181727. ShowCaret (hwnd);
  181728. SetCaretPos (0, 0);
  181729. }
  181730. void repaint (int x, int y, int w, int h)
  181731. {
  181732. const RECT r = { x, y, x + w, y + h };
  181733. InvalidateRect (hwnd, &r, FALSE);
  181734. }
  181735. void performAnyPendingRepaintsNow()
  181736. {
  181737. MSG m;
  181738. if (component->isVisible() && PeekMessage (&m, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
  181739. DispatchMessage (&m);
  181740. }
  181741. static Win32ComponentPeer* getOwnerOfWindow (HWND h) throw()
  181742. {
  181743. if (h != 0 && GetWindowLongPtr (h, GWLP_USERDATA) == improbableWindowNumber)
  181744. return (Win32ComponentPeer*) (pointer_sized_int) GetWindowLongPtr (h, 8);
  181745. return 0;
  181746. }
  181747. void setTaskBarIcon (const Image* const image)
  181748. {
  181749. if (image != 0)
  181750. {
  181751. HICON hicon = createHICONFromImage (*image, TRUE, 0, 0);
  181752. if (taskBarIcon == 0)
  181753. {
  181754. taskBarIcon = new NOTIFYICONDATA();
  181755. taskBarIcon->cbSize = sizeof (NOTIFYICONDATA);
  181756. taskBarIcon->hWnd = (HWND) hwnd;
  181757. taskBarIcon->uID = (int) (pointer_sized_int) hwnd;
  181758. taskBarIcon->uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
  181759. taskBarIcon->uCallbackMessage = WM_TRAYNOTIFY;
  181760. taskBarIcon->hIcon = hicon;
  181761. taskBarIcon->szTip[0] = 0;
  181762. Shell_NotifyIcon (NIM_ADD, taskBarIcon);
  181763. }
  181764. else
  181765. {
  181766. HICON oldIcon = taskBarIcon->hIcon;
  181767. taskBarIcon->hIcon = hicon;
  181768. taskBarIcon->uFlags = NIF_ICON;
  181769. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  181770. DestroyIcon (oldIcon);
  181771. }
  181772. DestroyIcon (hicon);
  181773. }
  181774. else if (taskBarIcon != 0)
  181775. {
  181776. taskBarIcon->uFlags = 0;
  181777. Shell_NotifyIcon (NIM_DELETE, taskBarIcon);
  181778. DestroyIcon (taskBarIcon->hIcon);
  181779. deleteAndZero (taskBarIcon);
  181780. }
  181781. }
  181782. void setTaskBarIconToolTip (const String& toolTip) const
  181783. {
  181784. if (taskBarIcon != 0)
  181785. {
  181786. taskBarIcon->uFlags = NIF_TIP;
  181787. toolTip.copyToUnicode (taskBarIcon->szTip, sizeof (taskBarIcon->szTip) - 1);
  181788. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  181789. }
  181790. }
  181791. bool isInside (HWND h) const
  181792. {
  181793. return GetAncestor (hwnd, GA_ROOT) == h;
  181794. }
  181795. static void updateKeyModifiers() throw()
  181796. {
  181797. int keyMods = 0;
  181798. if (GetKeyState (VK_SHIFT) & 0x8000) keyMods |= ModifierKeys::shiftModifier;
  181799. if (GetKeyState (VK_CONTROL) & 0x8000) keyMods |= ModifierKeys::ctrlModifier;
  181800. if (GetKeyState (VK_MENU) & 0x8000) keyMods |= ModifierKeys::altModifier;
  181801. if (GetKeyState (VK_RMENU) & 0x8000) keyMods &= ~(ModifierKeys::ctrlModifier | ModifierKeys::altModifier);
  181802. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  181803. }
  181804. static void updateModifiersFromWParam (const WPARAM wParam)
  181805. {
  181806. int mouseMods = 0;
  181807. if (wParam & MK_LBUTTON) mouseMods |= ModifierKeys::leftButtonModifier;
  181808. if (wParam & MK_RBUTTON) mouseMods |= ModifierKeys::rightButtonModifier;
  181809. if (wParam & MK_MBUTTON) mouseMods |= ModifierKeys::middleButtonModifier;
  181810. currentModifiers = currentModifiers.withoutMouseButtons().withFlags (mouseMods);
  181811. updateKeyModifiers();
  181812. }
  181813. static int64 getMouseEventTime()
  181814. {
  181815. static int64 eventTimeOffset = 0;
  181816. static DWORD lastMessageTime = 0;
  181817. const DWORD thisMessageTime = GetMessageTime();
  181818. if (thisMessageTime < lastMessageTime || lastMessageTime == 0)
  181819. {
  181820. lastMessageTime = thisMessageTime;
  181821. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  181822. }
  181823. return eventTimeOffset + thisMessageTime;
  181824. }
  181825. juce_UseDebuggingNewOperator
  181826. bool dontRepaint;
  181827. static ModifierKeys currentModifiers;
  181828. static ModifierKeys modifiersAtLastCallback;
  181829. private:
  181830. HWND hwnd;
  181831. DropShadower* shadower;
  181832. bool fullScreen, isDragging, isMouseOver, hasCreatedCaret;
  181833. BorderSize windowBorder;
  181834. HICON currentWindowIcon;
  181835. NOTIFYICONDATA* taskBarIcon;
  181836. IDropTarget* dropTarget;
  181837. class TemporaryImage : public Timer
  181838. {
  181839. public:
  181840. TemporaryImage()
  181841. : image (0)
  181842. {
  181843. }
  181844. ~TemporaryImage()
  181845. {
  181846. delete image;
  181847. }
  181848. WindowsBitmapImage* getImage (const bool transparent, const int w, const int h) throw()
  181849. {
  181850. const Image::PixelFormat format = transparent ? Image::ARGB : Image::RGB;
  181851. if (image == 0 || image->getWidth() < w || image->getHeight() < h || image->getFormat() != format)
  181852. {
  181853. delete image;
  181854. image = new WindowsBitmapImage (format, (w + 31) & ~31, (h + 31) & ~31, false);
  181855. }
  181856. startTimer (3000);
  181857. return image;
  181858. }
  181859. void timerCallback()
  181860. {
  181861. stopTimer();
  181862. deleteAndZero (image);
  181863. }
  181864. private:
  181865. WindowsBitmapImage* image;
  181866. TemporaryImage (const TemporaryImage&);
  181867. TemporaryImage& operator= (const TemporaryImage&);
  181868. };
  181869. TemporaryImage offscreenImageGenerator;
  181870. class WindowClassHolder : public DeletedAtShutdown
  181871. {
  181872. public:
  181873. WindowClassHolder()
  181874. : windowClassName ("JUCE_")
  181875. {
  181876. // this name has to be different for each app/dll instance because otherwise
  181877. // poor old Win32 can get a bit confused (even despite it not being a process-global
  181878. // window class).
  181879. windowClassName << (int) (Time::currentTimeMillis() & 0x7fffffff);
  181880. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  181881. TCHAR moduleFile [1024];
  181882. moduleFile[0] = 0;
  181883. GetModuleFileName (moduleHandle, moduleFile, 1024);
  181884. WORD iconNum = 0;
  181885. WNDCLASSEX wcex;
  181886. wcex.cbSize = sizeof (wcex);
  181887. wcex.style = CS_OWNDC;
  181888. wcex.lpfnWndProc = (WNDPROC) windowProc;
  181889. wcex.lpszClassName = windowClassName;
  181890. wcex.cbClsExtra = 0;
  181891. wcex.cbWndExtra = 32;
  181892. wcex.hInstance = moduleHandle;
  181893. wcex.hIcon = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  181894. iconNum = 1;
  181895. wcex.hIconSm = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  181896. wcex.hCursor = 0;
  181897. wcex.hbrBackground = 0;
  181898. wcex.lpszMenuName = 0;
  181899. RegisterClassEx (&wcex);
  181900. }
  181901. ~WindowClassHolder()
  181902. {
  181903. if (ComponentPeer::getNumPeers() == 0)
  181904. UnregisterClass (windowClassName, (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle());
  181905. clearSingletonInstance();
  181906. }
  181907. String windowClassName;
  181908. juce_DeclareSingleton_SingleThreaded_Minimal (WindowClassHolder);
  181909. };
  181910. static void* createWindowCallback (void* userData)
  181911. {
  181912. ((Win32ComponentPeer*) userData)->createWindow();
  181913. return 0;
  181914. }
  181915. void createWindow()
  181916. {
  181917. DWORD exstyle = WS_EX_ACCEPTFILES;
  181918. DWORD type = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
  181919. if (hasTitleBar())
  181920. {
  181921. type |= WS_OVERLAPPED;
  181922. exstyle |= WS_EX_APPWINDOW;
  181923. if ((styleFlags & windowHasCloseButton) != 0)
  181924. {
  181925. type |= WS_SYSMENU;
  181926. }
  181927. else
  181928. {
  181929. // annoyingly, windows won't let you have a min/max button without a close button
  181930. jassert ((styleFlags & (windowHasMinimiseButton | windowHasMaximiseButton)) == 0);
  181931. }
  181932. if ((styleFlags & windowIsResizable) != 0)
  181933. type |= WS_THICKFRAME;
  181934. }
  181935. else
  181936. {
  181937. type |= WS_POPUP | WS_SYSMENU;
  181938. if ((styleFlags & windowAppearsOnTaskbar) == 0)
  181939. exstyle |= WS_EX_TOOLWINDOW;
  181940. else
  181941. exstyle |= WS_EX_APPWINDOW;
  181942. }
  181943. if ((styleFlags & windowHasMinimiseButton) != 0)
  181944. type |= WS_MINIMIZEBOX;
  181945. if ((styleFlags & windowHasMaximiseButton) != 0)
  181946. type |= WS_MAXIMIZEBOX;
  181947. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  181948. exstyle |= WS_EX_TRANSPARENT;
  181949. if ((styleFlags & windowIsSemiTransparent) != 0
  181950. && Desktop::canUseSemiTransparentWindows())
  181951. exstyle |= WS_EX_LAYERED;
  181952. hwnd = CreateWindowEx (exstyle, WindowClassHolder::getInstance()->windowClassName, L"", type, 0, 0, 0, 0, 0, 0, 0, 0);
  181953. if (hwnd != 0)
  181954. {
  181955. SetWindowLongPtr (hwnd, 0, 0);
  181956. SetWindowLongPtr (hwnd, 8, (LONG_PTR) this);
  181957. SetWindowLongPtr (hwnd, GWLP_USERDATA, improbableWindowNumber);
  181958. if (dropTarget == 0)
  181959. dropTarget = new JuceDropTarget (this);
  181960. RegisterDragDrop (hwnd, dropTarget);
  181961. updateBorderSize();
  181962. // Calling this function here is (for some reason) necessary to make Windows
  181963. // correctly enable the menu items that we specify in the wm_initmenu message.
  181964. GetSystemMenu (hwnd, false);
  181965. }
  181966. else
  181967. {
  181968. jassertfalse
  181969. }
  181970. }
  181971. static void* destroyWindowCallback (void* handle)
  181972. {
  181973. RevokeDragDrop ((HWND) handle);
  181974. DestroyWindow ((HWND) handle);
  181975. return 0;
  181976. }
  181977. static void* toFrontCallback1 (void* h)
  181978. {
  181979. SetForegroundWindow ((HWND) h);
  181980. return 0;
  181981. }
  181982. static void* toFrontCallback2 (void* h)
  181983. {
  181984. SetWindowPos ((HWND) h, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181985. return 0;
  181986. }
  181987. static void* setFocusCallback (void* h)
  181988. {
  181989. SetFocus ((HWND) h);
  181990. return 0;
  181991. }
  181992. static void* getFocusCallback (void*)
  181993. {
  181994. return (void*) GetFocus();
  181995. }
  181996. void offsetWithinParent (int& x, int& y) const
  181997. {
  181998. if (isTransparent())
  181999. {
  182000. HWND parentHwnd = GetParent (hwnd);
  182001. if (parentHwnd != 0)
  182002. {
  182003. RECT parentRect;
  182004. GetWindowRect (parentHwnd, &parentRect);
  182005. x += parentRect.left;
  182006. y += parentRect.top;
  182007. }
  182008. }
  182009. }
  182010. bool isTransparent() const
  182011. {
  182012. return (GetWindowLong (hwnd, GWL_EXSTYLE) & WS_EX_LAYERED) != 0;
  182013. }
  182014. inline bool hasTitleBar() const throw() { return (styleFlags & windowHasTitleBar) != 0; }
  182015. void setIcon (const Image& newIcon)
  182016. {
  182017. HICON hicon = createHICONFromImage (newIcon, TRUE, 0, 0);
  182018. if (hicon != 0)
  182019. {
  182020. SendMessage (hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
  182021. SendMessage (hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
  182022. if (currentWindowIcon != 0)
  182023. DestroyIcon (currentWindowIcon);
  182024. currentWindowIcon = hicon;
  182025. }
  182026. }
  182027. void handlePaintMessage()
  182028. {
  182029. HRGN rgn = CreateRectRgn (0, 0, 0, 0);
  182030. const int regionType = GetUpdateRgn (hwnd, rgn, false);
  182031. PAINTSTRUCT paintStruct;
  182032. HDC dc = BeginPaint (hwnd, &paintStruct); // Note this can immediately generate a WM_NCPAINT
  182033. // message and become re-entrant, but that's OK
  182034. // if something in a paint handler calls, e.g. a message box, this can become reentrant and
  182035. // corrupt the image it's using to paint into, so do a check here.
  182036. static bool reentrant = false;
  182037. if (reentrant)
  182038. {
  182039. DeleteObject (rgn);
  182040. EndPaint (hwnd, &paintStruct);
  182041. return;
  182042. }
  182043. reentrant = true;
  182044. // this is the rectangle to update..
  182045. int x = paintStruct.rcPaint.left;
  182046. int y = paintStruct.rcPaint.top;
  182047. int w = paintStruct.rcPaint.right - x;
  182048. int h = paintStruct.rcPaint.bottom - y;
  182049. const bool transparent = isTransparent();
  182050. if (transparent)
  182051. {
  182052. // it's not possible to have a transparent window with a title bar at the moment!
  182053. jassert (! hasTitleBar());
  182054. RECT r;
  182055. GetWindowRect (hwnd, &r);
  182056. x = y = 0;
  182057. w = r.right - r.left;
  182058. h = r.bottom - r.top;
  182059. }
  182060. if (w > 0 && h > 0)
  182061. {
  182062. clearMaskedRegion();
  182063. WindowsBitmapImage* const offscreenImage = offscreenImageGenerator.getImage (transparent, w, h);
  182064. RectangleList contextClip;
  182065. bool needToPaintAll = true;
  182066. if (regionType == COMPLEXREGION && ! transparent)
  182067. {
  182068. HRGN clipRgn = CreateRectRgnIndirect (&paintStruct.rcPaint);
  182069. CombineRgn (rgn, rgn, clipRgn, RGN_AND);
  182070. DeleteObject (clipRgn);
  182071. char rgnData [8192];
  182072. const DWORD res = GetRegionData (rgn, sizeof (rgnData), (RGNDATA*) rgnData);
  182073. if (res > 0 && res <= sizeof (rgnData))
  182074. {
  182075. const RGNDATAHEADER* const hdr = &(((const RGNDATA*) rgnData)->rdh);
  182076. if (hdr->iType == RDH_RECTANGLES
  182077. && hdr->rcBound.right - hdr->rcBound.left >= w
  182078. && hdr->rcBound.bottom - hdr->rcBound.top >= h)
  182079. {
  182080. needToPaintAll = false;
  182081. const RECT* rects = (const RECT*) (rgnData + sizeof (RGNDATAHEADER));
  182082. int num = ((RGNDATA*) rgnData)->rdh.nCount;
  182083. while (--num >= 0)
  182084. {
  182085. // (need to move this one pixel to the left because of a win32 bug)
  182086. const int cx = jmax (x, (int) rects->left - 1);
  182087. const int cy = rects->top;
  182088. const int cw = rects->right - cx;
  182089. const int ch = rects->bottom - rects->top;
  182090. if (cx + cw - x <= w && cy + ch - y <= h)
  182091. {
  182092. contextClip.addWithoutMerging (Rectangle<int> (cx - x, cy - y, cw, ch));
  182093. }
  182094. else
  182095. {
  182096. needToPaintAll = true;
  182097. break;
  182098. }
  182099. ++rects;
  182100. }
  182101. }
  182102. }
  182103. }
  182104. if (needToPaintAll)
  182105. {
  182106. contextClip.clear();
  182107. contextClip.addWithoutMerging (Rectangle<int> (0, 0, w, h));
  182108. }
  182109. if (transparent)
  182110. {
  182111. RectangleList::Iterator i (contextClip);
  182112. while (i.next())
  182113. {
  182114. const Rectangle<int>& r = *i.getRectangle();
  182115. offscreenImage->clear (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  182116. }
  182117. }
  182118. // if the component's not opaque, this won't draw properly unless the platform can support this
  182119. jassert (Desktop::canUseSemiTransparentWindows() || component->isOpaque());
  182120. updateCurrentModifiers();
  182121. LowLevelGraphicsSoftwareRenderer context (*offscreenImage);
  182122. context.clipToRectangleList (contextClip);
  182123. context.setOrigin (-x, -y);
  182124. handlePaint (context);
  182125. if (! dontRepaint)
  182126. offscreenImage->blitToWindow (hwnd, dc, transparent, x, y, maskedRegion);
  182127. }
  182128. DeleteObject (rgn);
  182129. EndPaint (hwnd, &paintStruct);
  182130. reentrant = false;
  182131. #ifndef JUCE_GCC //xxx should add this fn for gcc..
  182132. _fpreset(); // because some graphics cards can unmask FP exceptions
  182133. #endif
  182134. lastPaintTime = Time::getMillisecondCounter();
  182135. }
  182136. void doMouseEvent (const Point<int>& position)
  182137. {
  182138. handleMouseEvent (0, position, currentModifiers, getMouseEventTime());
  182139. }
  182140. void doMouseMove (const Point<int>& position)
  182141. {
  182142. if (! isMouseOver)
  182143. {
  182144. isMouseOver = true;
  182145. updateKeyModifiers();
  182146. TRACKMOUSEEVENT tme;
  182147. tme.cbSize = sizeof (tme);
  182148. tme.dwFlags = TME_LEAVE;
  182149. tme.hwndTrack = hwnd;
  182150. tme.dwHoverTime = 0;
  182151. if (! TrackMouseEvent (&tme))
  182152. jassertfalse;
  182153. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  182154. }
  182155. else if (! isDragging)
  182156. {
  182157. if (! contains (position, false))
  182158. return;
  182159. }
  182160. // (Throttling the incoming queue of mouse-events seems to still be required in XP..)
  182161. static uint32 lastMouseTime = 0;
  182162. const uint32 now = Time::getMillisecondCounter();
  182163. const int maxMouseMovesPerSecond = 60;
  182164. if (now > lastMouseTime + 1000 / maxMouseMovesPerSecond)
  182165. {
  182166. lastMouseTime = now;
  182167. doMouseEvent (position);
  182168. }
  182169. }
  182170. void doMouseDown (const Point<int>& position, const WPARAM wParam)
  182171. {
  182172. if (GetCapture() != hwnd)
  182173. SetCapture (hwnd);
  182174. doMouseMove (position);
  182175. updateModifiersFromWParam (wParam);
  182176. isDragging = true;
  182177. doMouseEvent (position);
  182178. }
  182179. void doMouseUp (const Point<int>& position, const WPARAM wParam)
  182180. {
  182181. updateModifiersFromWParam (wParam);
  182182. isDragging = false;
  182183. // release the mouse capture if the user has released all buttons
  182184. if ((wParam & (MK_LBUTTON | MK_RBUTTON | MK_MBUTTON)) == 0 && hwnd == GetCapture())
  182185. ReleaseCapture();
  182186. doMouseEvent (position);
  182187. }
  182188. void doCaptureChanged()
  182189. {
  182190. if (isDragging)
  182191. doMouseUp (getCurrentMousePos(), (WPARAM) 0);
  182192. }
  182193. void doMouseExit()
  182194. {
  182195. isMouseOver = false;
  182196. doMouseEvent (getCurrentMousePos());
  182197. }
  182198. void doMouseWheel (const Point<int>& position, const WPARAM wParam, const bool isVertical)
  182199. {
  182200. updateKeyModifiers();
  182201. const float amount = jlimit (-1000.0f, 1000.0f, 0.75f * (short) HIWORD (wParam));
  182202. handleMouseWheel (0, position, getMouseEventTime(),
  182203. isVertical ? 0.0f : amount,
  182204. isVertical ? amount : 0.0f);
  182205. }
  182206. void sendModifierKeyChangeIfNeeded()
  182207. {
  182208. if (modifiersAtLastCallback != currentModifiers)
  182209. {
  182210. modifiersAtLastCallback = currentModifiers;
  182211. handleModifierKeysChange();
  182212. }
  182213. }
  182214. bool doKeyUp (const WPARAM key)
  182215. {
  182216. updateKeyModifiers();
  182217. switch (key)
  182218. {
  182219. case VK_SHIFT:
  182220. case VK_CONTROL:
  182221. case VK_MENU:
  182222. case VK_CAPITAL:
  182223. case VK_LWIN:
  182224. case VK_RWIN:
  182225. case VK_APPS:
  182226. case VK_NUMLOCK:
  182227. case VK_SCROLL:
  182228. case VK_LSHIFT:
  182229. case VK_RSHIFT:
  182230. case VK_LCONTROL:
  182231. case VK_LMENU:
  182232. case VK_RCONTROL:
  182233. case VK_RMENU:
  182234. sendModifierKeyChangeIfNeeded();
  182235. }
  182236. return handleKeyUpOrDown (false)
  182237. || Component::getCurrentlyModalComponent() != 0;
  182238. }
  182239. bool doKeyDown (const WPARAM key)
  182240. {
  182241. updateKeyModifiers();
  182242. bool used = false;
  182243. switch (key)
  182244. {
  182245. case VK_SHIFT:
  182246. case VK_LSHIFT:
  182247. case VK_RSHIFT:
  182248. case VK_CONTROL:
  182249. case VK_LCONTROL:
  182250. case VK_RCONTROL:
  182251. case VK_MENU:
  182252. case VK_LMENU:
  182253. case VK_RMENU:
  182254. case VK_LWIN:
  182255. case VK_RWIN:
  182256. case VK_CAPITAL:
  182257. case VK_NUMLOCK:
  182258. case VK_SCROLL:
  182259. case VK_APPS:
  182260. sendModifierKeyChangeIfNeeded();
  182261. break;
  182262. case VK_LEFT:
  182263. case VK_RIGHT:
  182264. case VK_UP:
  182265. case VK_DOWN:
  182266. case VK_PRIOR:
  182267. case VK_NEXT:
  182268. case VK_HOME:
  182269. case VK_END:
  182270. case VK_DELETE:
  182271. case VK_INSERT:
  182272. case VK_F1:
  182273. case VK_F2:
  182274. case VK_F3:
  182275. case VK_F4:
  182276. case VK_F5:
  182277. case VK_F6:
  182278. case VK_F7:
  182279. case VK_F8:
  182280. case VK_F9:
  182281. case VK_F10:
  182282. case VK_F11:
  182283. case VK_F12:
  182284. case VK_F13:
  182285. case VK_F14:
  182286. case VK_F15:
  182287. case VK_F16:
  182288. used = handleKeyUpOrDown (true);
  182289. used = handleKeyPress (extendedKeyModifier | (int) key, 0) || used;
  182290. break;
  182291. case VK_ADD:
  182292. case VK_SUBTRACT:
  182293. case VK_MULTIPLY:
  182294. case VK_DIVIDE:
  182295. case VK_SEPARATOR:
  182296. case VK_DECIMAL:
  182297. used = handleKeyUpOrDown (true);
  182298. break;
  182299. default:
  182300. used = handleKeyUpOrDown (true);
  182301. {
  182302. MSG msg;
  182303. if (! PeekMessage (&msg, hwnd, WM_CHAR, WM_DEADCHAR, PM_NOREMOVE))
  182304. {
  182305. // if there isn't a WM_CHAR or WM_DEADCHAR message pending, we need to
  182306. // manually generate the key-press event that matches this key-down.
  182307. const UINT keyChar = MapVirtualKey (key, 2);
  182308. used = handleKeyPress ((int) LOWORD (keyChar), 0) || used;
  182309. }
  182310. }
  182311. break;
  182312. }
  182313. if (Component::getCurrentlyModalComponent() != 0)
  182314. used = true;
  182315. return used;
  182316. }
  182317. bool doKeyChar (int key, const LPARAM flags)
  182318. {
  182319. updateKeyModifiers();
  182320. juce_wchar textChar = (juce_wchar) key;
  182321. const int virtualScanCode = (flags >> 16) & 0xff;
  182322. if (key >= '0' && key <= '9')
  182323. {
  182324. switch (virtualScanCode) // check for a numeric keypad scan-code
  182325. {
  182326. case 0x52:
  182327. case 0x4f:
  182328. case 0x50:
  182329. case 0x51:
  182330. case 0x4b:
  182331. case 0x4c:
  182332. case 0x4d:
  182333. case 0x47:
  182334. case 0x48:
  182335. case 0x49:
  182336. key = (key - '0') + KeyPress::numberPad0;
  182337. break;
  182338. default:
  182339. break;
  182340. }
  182341. }
  182342. else
  182343. {
  182344. // convert the scan code to an unmodified character code..
  182345. const UINT virtualKey = MapVirtualKey (virtualScanCode, 1);
  182346. UINT keyChar = MapVirtualKey (virtualKey, 2);
  182347. keyChar = LOWORD (keyChar);
  182348. if (keyChar != 0)
  182349. key = (int) keyChar;
  182350. // avoid sending junk text characters for some control-key combinations
  182351. if (textChar < ' ' && currentModifiers.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::altModifier))
  182352. textChar = 0;
  182353. }
  182354. return handleKeyPress (key, textChar);
  182355. }
  182356. bool doAppCommand (const LPARAM lParam)
  182357. {
  182358. int key = 0;
  182359. switch (GET_APPCOMMAND_LPARAM (lParam))
  182360. {
  182361. case APPCOMMAND_MEDIA_PLAY_PAUSE:
  182362. key = KeyPress::playKey;
  182363. break;
  182364. case APPCOMMAND_MEDIA_STOP:
  182365. key = KeyPress::stopKey;
  182366. break;
  182367. case APPCOMMAND_MEDIA_NEXTTRACK:
  182368. key = KeyPress::fastForwardKey;
  182369. break;
  182370. case APPCOMMAND_MEDIA_PREVIOUSTRACK:
  182371. key = KeyPress::rewindKey;
  182372. break;
  182373. }
  182374. if (key != 0)
  182375. {
  182376. updateKeyModifiers();
  182377. if (hwnd == GetActiveWindow())
  182378. {
  182379. handleKeyPress (key, 0);
  182380. return true;
  182381. }
  182382. }
  182383. return false;
  182384. }
  182385. class JuceDropTarget : public IDropTarget
  182386. {
  182387. public:
  182388. JuceDropTarget (Win32ComponentPeer* const owner_)
  182389. : owner (owner_),
  182390. refCount (1)
  182391. {
  182392. }
  182393. virtual ~JuceDropTarget()
  182394. {
  182395. jassert (refCount == 0);
  182396. }
  182397. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  182398. {
  182399. if (id == IID_IUnknown || id == IID_IDropTarget)
  182400. {
  182401. AddRef();
  182402. *result = this;
  182403. return S_OK;
  182404. }
  182405. *result = 0;
  182406. return E_NOINTERFACE;
  182407. }
  182408. ULONG __stdcall AddRef() { return ++refCount; }
  182409. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  182410. HRESULT __stdcall DragEnter (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182411. {
  182412. updateFileList (pDataObject);
  182413. owner->handleFileDragMove (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182414. *pdwEffect = DROPEFFECT_COPY;
  182415. return S_OK;
  182416. }
  182417. HRESULT __stdcall DragLeave()
  182418. {
  182419. owner->handleFileDragExit (files);
  182420. return S_OK;
  182421. }
  182422. HRESULT __stdcall DragOver (DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182423. {
  182424. owner->handleFileDragMove (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182425. *pdwEffect = DROPEFFECT_COPY;
  182426. return S_OK;
  182427. }
  182428. HRESULT __stdcall Drop (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182429. {
  182430. updateFileList (pDataObject);
  182431. owner->handleFileDragDrop (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182432. *pdwEffect = DROPEFFECT_COPY;
  182433. return S_OK;
  182434. }
  182435. private:
  182436. Win32ComponentPeer* const owner;
  182437. int refCount;
  182438. StringArray files;
  182439. void updateFileList (IDataObject* const pDataObject)
  182440. {
  182441. files.clear();
  182442. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  182443. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  182444. if (pDataObject->GetData (&format, &medium) == S_OK)
  182445. {
  182446. const SIZE_T totalLen = GlobalSize (medium.hGlobal);
  182447. const LPDROPFILES pDropFiles = (const LPDROPFILES) GlobalLock (medium.hGlobal);
  182448. unsigned int i = 0;
  182449. if (pDropFiles->fWide)
  182450. {
  182451. const WCHAR* const fname = (WCHAR*) (((const char*) pDropFiles) + sizeof (DROPFILES));
  182452. for (;;)
  182453. {
  182454. unsigned int len = 0;
  182455. while (i + len < totalLen && fname [i + len] != 0)
  182456. ++len;
  182457. if (len == 0)
  182458. break;
  182459. files.add (String (fname + i, len));
  182460. i += len + 1;
  182461. }
  182462. }
  182463. else
  182464. {
  182465. const char* const fname = ((const char*) pDropFiles) + sizeof (DROPFILES);
  182466. for (;;)
  182467. {
  182468. unsigned int len = 0;
  182469. while (i + len < totalLen && fname [i + len] != 0)
  182470. ++len;
  182471. if (len == 0)
  182472. break;
  182473. files.add (String (fname + i, len));
  182474. i += len + 1;
  182475. }
  182476. }
  182477. GlobalUnlock (medium.hGlobal);
  182478. }
  182479. }
  182480. JuceDropTarget (const JuceDropTarget&);
  182481. JuceDropTarget& operator= (const JuceDropTarget&);
  182482. };
  182483. void doSettingChange()
  182484. {
  182485. Desktop::getInstance().refreshMonitorSizes();
  182486. if (fullScreen && ! isMinimised())
  182487. {
  182488. const Rectangle<int> r (component->getParentMonitorArea());
  182489. SetWindowPos (hwnd, 0,
  182490. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  182491. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOSENDCHANGING);
  182492. }
  182493. }
  182494. public:
  182495. static LRESULT CALLBACK windowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  182496. {
  182497. Win32ComponentPeer* const peer = getOwnerOfWindow (h);
  182498. if (peer != 0)
  182499. return peer->peerWindowProc (h, message, wParam, lParam);
  182500. return DefWindowProcW (h, message, wParam, lParam);
  182501. }
  182502. private:
  182503. static const Point<int> getPointFromLParam (LPARAM lParam) throw()
  182504. {
  182505. return Point<int> (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam));
  182506. }
  182507. const Point<int> getCurrentMousePos() throw()
  182508. {
  182509. RECT wr;
  182510. GetWindowRect (hwnd, &wr);
  182511. const DWORD mp = GetMessagePos();
  182512. return Point<int> (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(),
  182513. GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop());
  182514. }
  182515. LRESULT peerWindowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  182516. {
  182517. if (isValidPeer (this))
  182518. {
  182519. switch (message)
  182520. {
  182521. case WM_NCHITTEST:
  182522. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  182523. return HTTRANSPARENT;
  182524. if (hasTitleBar())
  182525. break;
  182526. return HTCLIENT;
  182527. case WM_PAINT:
  182528. handlePaintMessage();
  182529. return 0;
  182530. case WM_NCPAINT:
  182531. if (wParam != 1)
  182532. handlePaintMessage();
  182533. if (hasTitleBar())
  182534. break;
  182535. return 0;
  182536. case WM_ERASEBKGND:
  182537. case WM_NCCALCSIZE:
  182538. if (hasTitleBar())
  182539. break;
  182540. return 1;
  182541. case WM_MOUSEMOVE:
  182542. doMouseMove (getPointFromLParam (lParam));
  182543. return 0;
  182544. case WM_MOUSELEAVE:
  182545. doMouseExit();
  182546. return 0;
  182547. case WM_LBUTTONDOWN:
  182548. case WM_MBUTTONDOWN:
  182549. case WM_RBUTTONDOWN:
  182550. doMouseDown (getPointFromLParam (lParam), wParam);
  182551. return 0;
  182552. case WM_LBUTTONUP:
  182553. case WM_MBUTTONUP:
  182554. case WM_RBUTTONUP:
  182555. doMouseUp (getPointFromLParam (lParam), wParam);
  182556. return 0;
  182557. case WM_CAPTURECHANGED:
  182558. doCaptureChanged();
  182559. return 0;
  182560. case WM_NCMOUSEMOVE:
  182561. if (hasTitleBar())
  182562. break;
  182563. return 0;
  182564. case 0x020A: /* WM_MOUSEWHEEL */
  182565. doMouseWheel (getCurrentMousePos(), wParam, true);
  182566. return 0;
  182567. case 0x020E: /* WM_MOUSEHWHEEL */
  182568. doMouseWheel (getCurrentMousePos(), wParam, false);
  182569. return 0;
  182570. case WM_WINDOWPOSCHANGING:
  182571. if ((styleFlags & (windowHasTitleBar | windowIsResizable)) == (windowHasTitleBar | windowIsResizable))
  182572. {
  182573. WINDOWPOS* const wp = (WINDOWPOS*) lParam;
  182574. if ((wp->flags & (SWP_NOMOVE | SWP_NOSIZE)) != (SWP_NOMOVE | SWP_NOSIZE))
  182575. {
  182576. if (constrainer != 0)
  182577. {
  182578. const Rectangle<int> current (component->getX() - windowBorder.getLeft(),
  182579. component->getY() - windowBorder.getTop(),
  182580. component->getWidth() + windowBorder.getLeftAndRight(),
  182581. component->getHeight() + windowBorder.getTopAndBottom());
  182582. Rectangle<int> pos (wp->x, wp->y, wp->cx, wp->cy);
  182583. constrainer->checkBounds (pos, current,
  182584. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  182585. pos.getY() != current.getY() && pos.getBottom() == current.getBottom(),
  182586. pos.getX() != current.getX() && pos.getRight() == current.getRight(),
  182587. pos.getY() == current.getY() && pos.getBottom() != current.getBottom(),
  182588. pos.getX() == current.getX() && pos.getRight() != current.getRight());
  182589. wp->x = pos.getX();
  182590. wp->y = pos.getY();
  182591. wp->cx = pos.getWidth();
  182592. wp->cy = pos.getHeight();
  182593. }
  182594. }
  182595. }
  182596. return 0;
  182597. case WM_WINDOWPOSCHANGED:
  182598. handleMovedOrResized();
  182599. if (dontRepaint)
  182600. break; // needed for non-accelerated openGL windows to draw themselves correctly..
  182601. return 0;
  182602. case WM_KEYDOWN:
  182603. case WM_SYSKEYDOWN:
  182604. if (doKeyDown (wParam))
  182605. return 0;
  182606. break;
  182607. case WM_KEYUP:
  182608. case WM_SYSKEYUP:
  182609. if (doKeyUp (wParam))
  182610. return 0;
  182611. break;
  182612. case WM_CHAR:
  182613. if (doKeyChar ((int) wParam, lParam))
  182614. return 0;
  182615. break;
  182616. case WM_APPCOMMAND:
  182617. if (doAppCommand (lParam))
  182618. return TRUE;
  182619. break;
  182620. case WM_SETFOCUS:
  182621. updateKeyModifiers();
  182622. handleFocusGain();
  182623. break;
  182624. case WM_KILLFOCUS:
  182625. if (hasCreatedCaret)
  182626. {
  182627. hasCreatedCaret = false;
  182628. DestroyCaret();
  182629. }
  182630. handleFocusLoss();
  182631. break;
  182632. case WM_ACTIVATEAPP:
  182633. // Windows does weird things to process priority when you swap apps,
  182634. // so this forces an update when the app is brought to the front
  182635. if (wParam != FALSE)
  182636. juce_repeatLastProcessPriority();
  182637. else
  182638. Desktop::getInstance().setKioskModeComponent (0); // turn kiosk mode off if we lose focus
  182639. juce_CheckCurrentlyFocusedTopLevelWindow();
  182640. modifiersAtLastCallback = -1;
  182641. return 0;
  182642. case WM_ACTIVATE:
  182643. if (LOWORD (wParam) == WA_ACTIVE || LOWORD (wParam) == WA_CLICKACTIVE)
  182644. {
  182645. modifiersAtLastCallback = -1;
  182646. updateKeyModifiers();
  182647. if (isMinimised())
  182648. {
  182649. component->repaint();
  182650. handleMovedOrResized();
  182651. if (! ComponentPeer::isValidPeer (this))
  182652. return 0;
  182653. }
  182654. if (LOWORD (wParam) == WA_CLICKACTIVE
  182655. && component->isCurrentlyBlockedByAnotherModalComponent())
  182656. {
  182657. const Point<int> mousePos (component->getMouseXYRelative());
  182658. Component* const underMouse = component->getComponentAt (mousePos.getX(), mousePos.getY());
  182659. if (underMouse != 0 && underMouse->isCurrentlyBlockedByAnotherModalComponent())
  182660. Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  182661. return 0;
  182662. }
  182663. handleBroughtToFront();
  182664. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182665. Component::getCurrentlyModalComponent()->toFront (true);
  182666. return 0;
  182667. }
  182668. break;
  182669. case WM_NCACTIVATE:
  182670. // while a temporary window is being shown, prevent Windows from deactivating the
  182671. // title bars of our main windows.
  182672. if (wParam == 0 && ! shouldDeactivateTitleBar)
  182673. wParam = TRUE; // change this and let it get passed to the DefWindowProc.
  182674. break;
  182675. case WM_MOUSEACTIVATE:
  182676. if (! component->getMouseClickGrabsKeyboardFocus())
  182677. return MA_NOACTIVATE;
  182678. break;
  182679. case WM_SHOWWINDOW:
  182680. if (wParam != 0)
  182681. handleBroughtToFront();
  182682. break;
  182683. case WM_CLOSE:
  182684. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  182685. handleUserClosingWindow();
  182686. return 0;
  182687. case WM_QUERYENDSESSION:
  182688. if (JUCEApplication::getInstance() != 0)
  182689. {
  182690. JUCEApplication::getInstance()->systemRequestedQuit();
  182691. return MessageManager::getInstance()->hasStopMessageBeenSent();
  182692. }
  182693. return TRUE;
  182694. case WM_TRAYNOTIFY:
  182695. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182696. {
  182697. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN
  182698. || lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  182699. {
  182700. Component* const current = Component::getCurrentlyModalComponent();
  182701. if (current != 0)
  182702. current->inputAttemptWhenModal();
  182703. }
  182704. }
  182705. else
  182706. {
  182707. ModifierKeys eventMods (ModifierKeys::getCurrentModifiersRealtime());
  182708. if (lParam == WM_LBUTTONDOWN || lParam == WM_LBUTTONDBLCLK)
  182709. eventMods = eventMods.withFlags (ModifierKeys::leftButtonModifier);
  182710. else if (lParam == WM_RBUTTONDOWN || lParam == WM_RBUTTONDBLCLK)
  182711. eventMods = eventMods.withFlags (ModifierKeys::rightButtonModifier);
  182712. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  182713. eventMods = eventMods.withoutMouseButtons();
  182714. const MouseEvent e (Desktop::getInstance().getMainMouseSource(),
  182715. Point<int>(), eventMods, component, getMouseEventTime(),
  182716. Point<int>(), getMouseEventTime(), 1, false);
  182717. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN)
  182718. {
  182719. SetFocus (hwnd);
  182720. SetForegroundWindow (hwnd);
  182721. component->mouseDown (e);
  182722. }
  182723. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  182724. {
  182725. component->mouseUp (e);
  182726. }
  182727. else if (lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  182728. {
  182729. component->mouseDoubleClick (e);
  182730. }
  182731. else if (lParam == WM_MOUSEMOVE)
  182732. {
  182733. component->mouseMove (e);
  182734. }
  182735. }
  182736. break;
  182737. case WM_SYNCPAINT:
  182738. return 0;
  182739. case WM_PALETTECHANGED:
  182740. InvalidateRect (h, 0, 0);
  182741. break;
  182742. case WM_DISPLAYCHANGE:
  182743. InvalidateRect (h, 0, 0);
  182744. createPaletteIfNeeded = true;
  182745. // intentional fall-through...
  182746. case WM_SETTINGCHANGE: // note the fall-through in the previous case!
  182747. doSettingChange();
  182748. break;
  182749. case WM_INITMENU:
  182750. if (! hasTitleBar())
  182751. {
  182752. if (isFullScreen())
  182753. {
  182754. EnableMenuItem ((HMENU) wParam, SC_RESTORE, MF_BYCOMMAND | MF_ENABLED);
  182755. EnableMenuItem ((HMENU) wParam, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
  182756. }
  182757. else if (! isMinimised())
  182758. {
  182759. EnableMenuItem ((HMENU) wParam, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
  182760. }
  182761. }
  182762. break;
  182763. case WM_SYSCOMMAND:
  182764. switch (wParam & 0xfff0)
  182765. {
  182766. case SC_CLOSE:
  182767. if (sendInputAttemptWhenModalMessage())
  182768. return 0;
  182769. if (hasTitleBar())
  182770. {
  182771. PostMessage (h, WM_CLOSE, 0, 0);
  182772. return 0;
  182773. }
  182774. break;
  182775. case SC_KEYMENU:
  182776. // (NB mustn't call sendInputAttemptWhenModalMessage() here because of very
  182777. // obscure situations that can arise if a modal loop is started from an alt-key
  182778. // keypress).
  182779. if (hasTitleBar() && h == GetCapture())
  182780. ReleaseCapture();
  182781. break;
  182782. case SC_MAXIMIZE:
  182783. if (sendInputAttemptWhenModalMessage())
  182784. return 0;
  182785. setFullScreen (true);
  182786. return 0;
  182787. case SC_MINIMIZE:
  182788. if (sendInputAttemptWhenModalMessage())
  182789. return 0;
  182790. if (! hasTitleBar())
  182791. {
  182792. setMinimised (true);
  182793. return 0;
  182794. }
  182795. break;
  182796. case SC_RESTORE:
  182797. if (sendInputAttemptWhenModalMessage())
  182798. return 0;
  182799. if (hasTitleBar())
  182800. {
  182801. if (isFullScreen())
  182802. {
  182803. setFullScreen (false);
  182804. return 0;
  182805. }
  182806. }
  182807. else
  182808. {
  182809. if (isMinimised())
  182810. setMinimised (false);
  182811. else if (isFullScreen())
  182812. setFullScreen (false);
  182813. return 0;
  182814. }
  182815. break;
  182816. }
  182817. break;
  182818. case WM_NCLBUTTONDOWN:
  182819. case WM_NCRBUTTONDOWN:
  182820. case WM_NCMBUTTONDOWN:
  182821. sendInputAttemptWhenModalMessage();
  182822. break;
  182823. //case WM_IME_STARTCOMPOSITION;
  182824. // return 0;
  182825. case WM_GETDLGCODE:
  182826. return DLGC_WANTALLKEYS;
  182827. default:
  182828. break;
  182829. }
  182830. }
  182831. return DefWindowProcW (h, message, wParam, lParam);
  182832. }
  182833. bool sendInputAttemptWhenModalMessage()
  182834. {
  182835. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182836. {
  182837. Component* const current = Component::getCurrentlyModalComponent();
  182838. if (current != 0)
  182839. current->inputAttemptWhenModal();
  182840. return true;
  182841. }
  182842. return false;
  182843. }
  182844. Win32ComponentPeer (const Win32ComponentPeer&);
  182845. Win32ComponentPeer& operator= (const Win32ComponentPeer&);
  182846. };
  182847. ModifierKeys Win32ComponentPeer::currentModifiers;
  182848. ModifierKeys Win32ComponentPeer::modifiersAtLastCallback;
  182849. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  182850. {
  182851. return new Win32ComponentPeer (this, styleFlags);
  182852. }
  182853. juce_ImplementSingleton_SingleThreaded (Win32ComponentPeer::WindowClassHolder);
  182854. void ModifierKeys::updateCurrentModifiers() throw()
  182855. {
  182856. currentModifiers = Win32ComponentPeer::currentModifiers;
  182857. }
  182858. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  182859. {
  182860. Win32ComponentPeer::updateKeyModifiers();
  182861. int keyMods = 0;
  182862. if ((GetKeyState (VK_LBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::leftButtonModifier;
  182863. if ((GetKeyState (VK_RBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::rightButtonModifier;
  182864. if ((GetKeyState (VK_MBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::middleButtonModifier;
  182865. Win32ComponentPeer::currentModifiers
  182866. = Win32ComponentPeer::currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  182867. return Win32ComponentPeer::currentModifiers;
  182868. }
  182869. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  182870. {
  182871. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  182872. if (wp != 0)
  182873. wp->setTaskBarIcon (&newImage);
  182874. }
  182875. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  182876. {
  182877. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  182878. if (wp != 0)
  182879. wp->setTaskBarIconToolTip (tooltip);
  182880. }
  182881. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw()
  182882. {
  182883. DWORD val = GetWindowLong (h, styleType);
  182884. if (bitIsSet)
  182885. val |= feature;
  182886. else
  182887. val &= ~feature;
  182888. SetWindowLongPtr (h, styleType, val);
  182889. SetWindowPos (h, 0, 0, 0, 0, 0,
  182890. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER
  182891. | SWP_NOOWNERZORDER | SWP_FRAMECHANGED | SWP_NOSENDCHANGING);
  182892. }
  182893. bool Process::isForegroundProcess()
  182894. {
  182895. HWND fg = GetForegroundWindow();
  182896. if (fg == 0)
  182897. return true;
  182898. // when running as a plugin in IE8, the browser UI runs in a different process to the plugin, so
  182899. // process ID isn't a reliable way to check if the foreground window belongs to us - instead, we
  182900. // have to see if any of our windows are children of the foreground window
  182901. fg = GetAncestor (fg, GA_ROOT);
  182902. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  182903. {
  182904. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (ComponentPeer::getPeer (i));
  182905. if (wp != 0 && wp->isInside (fg))
  182906. return true;
  182907. }
  182908. return false;
  182909. }
  182910. bool AlertWindow::showNativeDialogBox (const String& title,
  182911. const String& bodyText,
  182912. bool isOkCancel)
  182913. {
  182914. return MessageBox (0, bodyText, title,
  182915. MB_SETFOREGROUND | (isOkCancel ? MB_OKCANCEL
  182916. : MB_OK)) == IDOK;
  182917. }
  182918. void Desktop::createMouseInputSources()
  182919. {
  182920. mouseSources.add (new MouseInputSource (0, true));
  182921. }
  182922. const Point<int> Desktop::getMousePosition()
  182923. {
  182924. POINT mousePos;
  182925. GetCursorPos (&mousePos);
  182926. return Point<int> (mousePos.x, mousePos.y);
  182927. }
  182928. void Desktop::setMousePosition (const Point<int>& newPosition)
  182929. {
  182930. SetCursorPos (newPosition.getX(), newPosition.getY());
  182931. }
  182932. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  182933. {
  182934. return new Image (format, imageWidth, imageHeight, clearImage);
  182935. }
  182936. class ScreenSaverDefeater : public Timer,
  182937. public DeletedAtShutdown
  182938. {
  182939. public:
  182940. ScreenSaverDefeater() throw()
  182941. {
  182942. startTimer (10000);
  182943. timerCallback();
  182944. }
  182945. ~ScreenSaverDefeater() {}
  182946. void timerCallback()
  182947. {
  182948. if (Process::isForegroundProcess())
  182949. {
  182950. // simulate a shift key getting pressed..
  182951. INPUT input[2];
  182952. input[0].type = INPUT_KEYBOARD;
  182953. input[0].ki.wVk = VK_SHIFT;
  182954. input[0].ki.dwFlags = 0;
  182955. input[0].ki.dwExtraInfo = 0;
  182956. input[1].type = INPUT_KEYBOARD;
  182957. input[1].ki.wVk = VK_SHIFT;
  182958. input[1].ki.dwFlags = KEYEVENTF_KEYUP;
  182959. input[1].ki.dwExtraInfo = 0;
  182960. SendInput (2, input, sizeof (INPUT));
  182961. }
  182962. }
  182963. };
  182964. static ScreenSaverDefeater* screenSaverDefeater = 0;
  182965. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  182966. {
  182967. if (isEnabled)
  182968. {
  182969. deleteAndZero (screenSaverDefeater);
  182970. }
  182971. else if (screenSaverDefeater == 0)
  182972. {
  182973. screenSaverDefeater = new ScreenSaverDefeater();
  182974. }
  182975. }
  182976. bool Desktop::isScreenSaverEnabled() throw()
  182977. {
  182978. return screenSaverDefeater == 0;
  182979. }
  182980. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool /*allowMenusAndBars*/)
  182981. {
  182982. if (enableOrDisable)
  182983. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  182984. }
  182985. static BOOL CALLBACK enumMonitorsProc (HMONITOR, HDC, LPRECT r, LPARAM userInfo)
  182986. {
  182987. Array <Rectangle<int> >* const monitorCoords = (Array <Rectangle<int> >*) userInfo;
  182988. monitorCoords->add (Rectangle<int> (r->left, r->top, r->right - r->left, r->bottom - r->top));
  182989. return TRUE;
  182990. }
  182991. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  182992. {
  182993. EnumDisplayMonitors (0, 0, &enumMonitorsProc, (LPARAM) &monitorCoords);
  182994. // make sure the first in the list is the main monitor
  182995. for (int i = 1; i < monitorCoords.size(); ++i)
  182996. if (monitorCoords[i].getX() == 0 && monitorCoords[i].getY() == 0)
  182997. monitorCoords.swap (i, 0);
  182998. if (monitorCoords.size() == 0)
  182999. {
  183000. RECT r;
  183001. GetWindowRect (GetDesktopWindow(), &r);
  183002. monitorCoords.add (Rectangle<int> (r.left, r.top, r.right - r.left, r.bottom - r.top));
  183003. }
  183004. if (clipToWorkArea)
  183005. {
  183006. // clip the main monitor to the active non-taskbar area
  183007. RECT r;
  183008. SystemParametersInfo (SPI_GETWORKAREA, 0, &r, 0);
  183009. Rectangle<int>& screen = monitorCoords.getReference (0);
  183010. screen.setPosition (jmax (screen.getX(), (int) r.left),
  183011. jmax (screen.getY(), (int) r.top));
  183012. screen.setSize (jmin (screen.getRight(), (int) r.right) - screen.getX(),
  183013. jmin (screen.getBottom(), (int) r.bottom) - screen.getY());
  183014. }
  183015. }
  183016. static Image* createImageFromHBITMAP (HBITMAP bitmap) throw()
  183017. {
  183018. Image* im = 0;
  183019. if (bitmap != 0)
  183020. {
  183021. BITMAP bm;
  183022. if (GetObject (bitmap, sizeof (BITMAP), &bm)
  183023. && bm.bmWidth > 0 && bm.bmHeight > 0)
  183024. {
  183025. HDC tempDC = GetDC (0);
  183026. HDC dc = CreateCompatibleDC (tempDC);
  183027. ReleaseDC (0, tempDC);
  183028. SelectObject (dc, bitmap);
  183029. im = new Image (Image::ARGB, bm.bmWidth, bm.bmHeight, true);
  183030. for (int y = bm.bmHeight; --y >= 0;)
  183031. {
  183032. for (int x = bm.bmWidth; --x >= 0;)
  183033. {
  183034. COLORREF col = GetPixel (dc, x, y);
  183035. im->setPixelAt (x, y, Colour ((uint8) GetRValue (col),
  183036. (uint8) GetGValue (col),
  183037. (uint8) GetBValue (col)));
  183038. }
  183039. }
  183040. DeleteDC (dc);
  183041. }
  183042. }
  183043. return im;
  183044. }
  183045. static Image* createImageFromHICON (HICON icon) throw()
  183046. {
  183047. ICONINFO info;
  183048. if (GetIconInfo (icon, &info))
  183049. {
  183050. Image* const mask = createImageFromHBITMAP (info.hbmMask);
  183051. if (mask == 0)
  183052. return 0;
  183053. Image* const image = createImageFromHBITMAP (info.hbmColor);
  183054. if (image == 0)
  183055. return mask;
  183056. for (int y = image->getHeight(); --y >= 0;)
  183057. {
  183058. for (int x = image->getWidth(); --x >= 0;)
  183059. {
  183060. const float brightness = mask->getPixelAt (x, y).getBrightness();
  183061. if (brightness > 0.0f)
  183062. image->multiplyAlphaAt (x, y, 1.0f - brightness);
  183063. }
  183064. }
  183065. delete mask;
  183066. return image;
  183067. }
  183068. return 0;
  183069. }
  183070. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw()
  183071. {
  183072. HBITMAP mask = CreateBitmap (image.getWidth(), image.getHeight(), 1, 1, 0);
  183073. ICONINFO info;
  183074. info.fIcon = isIcon;
  183075. info.xHotspot = hotspotX;
  183076. info.yHotspot = hotspotY;
  183077. info.hbmMask = mask;
  183078. HICON hi = 0;
  183079. if (SystemStats::getOperatingSystemType() >= SystemStats::WinXP)
  183080. {
  183081. WindowsBitmapImage bitmap (Image::ARGB, image.getWidth(), image.getHeight(), true);
  183082. Graphics g (bitmap);
  183083. g.drawImageAt (&image, 0, 0);
  183084. info.hbmColor = bitmap.hBitmap;
  183085. hi = CreateIconIndirect (&info);
  183086. }
  183087. else
  183088. {
  183089. HBITMAP colour = CreateCompatibleBitmap (GetDC (0), image.getWidth(), image.getHeight());
  183090. HDC colDC = CreateCompatibleDC (GetDC (0));
  183091. HDC alphaDC = CreateCompatibleDC (GetDC (0));
  183092. SelectObject (colDC, colour);
  183093. SelectObject (alphaDC, mask);
  183094. for (int y = image.getHeight(); --y >= 0;)
  183095. {
  183096. for (int x = image.getWidth(); --x >= 0;)
  183097. {
  183098. const Colour c (image.getPixelAt (x, y));
  183099. SetPixel (colDC, x, y, COLORREF (c.getRed() | (c.getGreen() << 8) | (c.getBlue() << 16)));
  183100. SetPixel (alphaDC, x, y, COLORREF (0xffffff - (c.getAlpha() | (c.getAlpha() << 8) | (c.getAlpha() << 16))));
  183101. }
  183102. }
  183103. DeleteDC (colDC);
  183104. DeleteDC (alphaDC);
  183105. info.hbmColor = colour;
  183106. hi = CreateIconIndirect (&info);
  183107. DeleteObject (colour);
  183108. }
  183109. DeleteObject (mask);
  183110. return hi;
  183111. }
  183112. Image* juce_createIconForFile (const File& file)
  183113. {
  183114. Image* image = 0;
  183115. WCHAR filename [1024];
  183116. file.getFullPathName().copyToUnicode (filename, 1023);
  183117. WORD iconNum = 0;
  183118. HICON icon = ExtractAssociatedIcon ((HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle(),
  183119. filename, &iconNum);
  183120. if (icon != 0)
  183121. {
  183122. image = createImageFromHICON (icon);
  183123. DestroyIcon (icon);
  183124. }
  183125. return image;
  183126. }
  183127. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  183128. {
  183129. const int maxW = GetSystemMetrics (SM_CXCURSOR);
  183130. const int maxH = GetSystemMetrics (SM_CYCURSOR);
  183131. const Image* im = &image;
  183132. Image* newIm = 0;
  183133. if (image.getWidth() > maxW || image.getHeight() > maxH)
  183134. {
  183135. im = newIm = image.createCopy (maxW, maxH);
  183136. hotspotX = (hotspotX * maxW) / image.getWidth();
  183137. hotspotY = (hotspotY * maxH) / image.getHeight();
  183138. }
  183139. void* cursorH = 0;
  183140. const SystemStats::OperatingSystemType os = SystemStats::getOperatingSystemType();
  183141. if (os == SystemStats::WinXP)
  183142. {
  183143. cursorH = (void*) createHICONFromImage (*im, FALSE, hotspotX, hotspotY);
  183144. }
  183145. else
  183146. {
  183147. const int stride = (maxW + 7) >> 3;
  183148. HeapBlock <uint8> andPlane, xorPlane;
  183149. andPlane.calloc (stride * maxH);
  183150. xorPlane.calloc (stride * maxH);
  183151. int index = 0;
  183152. for (int y = 0; y < maxH; ++y)
  183153. {
  183154. for (int x = 0; x < maxW; ++x)
  183155. {
  183156. const unsigned char bit = (unsigned char) (1 << (7 - (x & 7)));
  183157. const Colour pixelColour (im->getPixelAt (x, y));
  183158. if (pixelColour.getAlpha() < 127)
  183159. andPlane [index + (x >> 3)] |= bit;
  183160. else if (pixelColour.getBrightness() >= 0.5f)
  183161. xorPlane [index + (x >> 3)] |= bit;
  183162. }
  183163. index += stride;
  183164. }
  183165. cursorH = CreateCursor (0, hotspotX, hotspotY, maxW, maxH, andPlane, xorPlane);
  183166. }
  183167. delete newIm;
  183168. return cursorH;
  183169. }
  183170. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  183171. {
  183172. if (cursorHandle != 0 && ! isStandard)
  183173. DestroyCursor ((HCURSOR) cursorHandle);
  183174. }
  183175. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  183176. {
  183177. LPCTSTR cursorName = IDC_ARROW;
  183178. switch (type)
  183179. {
  183180. case MouseCursor::NormalCursor:
  183181. cursorName = IDC_ARROW;
  183182. break;
  183183. case MouseCursor::NoCursor:
  183184. return 0;
  183185. case MouseCursor::DraggingHandCursor:
  183186. {
  183187. static void* dragHandCursor = 0;
  183188. if (dragHandCursor == 0)
  183189. {
  183190. static const unsigned char dragHandData[] =
  183191. { 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,
  183192. 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,
  183193. 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 };
  183194. const ScopedPointer <Image> image (ImageFileFormat::loadFrom ((const char*) dragHandData, sizeof (dragHandData)));
  183195. dragHandCursor = juce_createMouseCursorFromImage (*image, 8, 7);
  183196. }
  183197. return dragHandCursor;
  183198. }
  183199. case MouseCursor::WaitCursor:
  183200. cursorName = IDC_WAIT;
  183201. break;
  183202. case MouseCursor::IBeamCursor:
  183203. cursorName = IDC_IBEAM;
  183204. break;
  183205. case MouseCursor::PointingHandCursor:
  183206. cursorName = MAKEINTRESOURCE(32649);
  183207. break;
  183208. case MouseCursor::LeftRightResizeCursor:
  183209. case MouseCursor::LeftEdgeResizeCursor:
  183210. case MouseCursor::RightEdgeResizeCursor:
  183211. cursorName = IDC_SIZEWE;
  183212. break;
  183213. case MouseCursor::UpDownResizeCursor:
  183214. case MouseCursor::TopEdgeResizeCursor:
  183215. case MouseCursor::BottomEdgeResizeCursor:
  183216. cursorName = IDC_SIZENS;
  183217. break;
  183218. case MouseCursor::TopLeftCornerResizeCursor:
  183219. case MouseCursor::BottomRightCornerResizeCursor:
  183220. cursorName = IDC_SIZENWSE;
  183221. break;
  183222. case MouseCursor::TopRightCornerResizeCursor:
  183223. case MouseCursor::BottomLeftCornerResizeCursor:
  183224. cursorName = IDC_SIZENESW;
  183225. break;
  183226. case MouseCursor::UpDownLeftRightResizeCursor:
  183227. cursorName = IDC_SIZEALL;
  183228. break;
  183229. case MouseCursor::CrosshairCursor:
  183230. cursorName = IDC_CROSS;
  183231. break;
  183232. case MouseCursor::CopyingCursor:
  183233. // can't seem to find one of these in the win32 list..
  183234. break;
  183235. }
  183236. HCURSOR cursorH = LoadCursor (0, cursorName);
  183237. if (cursorH == 0)
  183238. cursorH = LoadCursor (0, IDC_ARROW);
  183239. return (void*) cursorH;
  183240. }
  183241. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  183242. {
  183243. SetCursor ((HCURSOR) getHandle());
  183244. }
  183245. void MouseCursor::showInAllWindows() const throw()
  183246. {
  183247. showInWindow (0);
  183248. }
  183249. class JuceDropSource : public IDropSource
  183250. {
  183251. int refCount;
  183252. public:
  183253. JuceDropSource()
  183254. : refCount (1)
  183255. {
  183256. }
  183257. virtual ~JuceDropSource()
  183258. {
  183259. jassert (refCount == 0);
  183260. }
  183261. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183262. {
  183263. if (id == IID_IUnknown || id == IID_IDropSource)
  183264. {
  183265. AddRef();
  183266. *result = this;
  183267. return S_OK;
  183268. }
  183269. *result = 0;
  183270. return E_NOINTERFACE;
  183271. }
  183272. ULONG __stdcall AddRef() { return ++refCount; }
  183273. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183274. HRESULT __stdcall QueryContinueDrag (BOOL escapePressed, DWORD keys)
  183275. {
  183276. if (escapePressed)
  183277. return DRAGDROP_S_CANCEL;
  183278. if ((keys & (MK_LBUTTON | MK_RBUTTON)) == 0)
  183279. return DRAGDROP_S_DROP;
  183280. return S_OK;
  183281. }
  183282. HRESULT __stdcall GiveFeedback (DWORD)
  183283. {
  183284. return DRAGDROP_S_USEDEFAULTCURSORS;
  183285. }
  183286. };
  183287. class JuceEnumFormatEtc : public IEnumFORMATETC
  183288. {
  183289. public:
  183290. JuceEnumFormatEtc (const FORMATETC* const format_)
  183291. : refCount (1),
  183292. format (format_),
  183293. index (0)
  183294. {
  183295. }
  183296. virtual ~JuceEnumFormatEtc()
  183297. {
  183298. jassert (refCount == 0);
  183299. }
  183300. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183301. {
  183302. if (id == IID_IUnknown || id == IID_IEnumFORMATETC)
  183303. {
  183304. AddRef();
  183305. *result = this;
  183306. return S_OK;
  183307. }
  183308. *result = 0;
  183309. return E_NOINTERFACE;
  183310. }
  183311. ULONG __stdcall AddRef() { return ++refCount; }
  183312. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183313. HRESULT __stdcall Clone (IEnumFORMATETC** result)
  183314. {
  183315. if (result == 0)
  183316. return E_POINTER;
  183317. JuceEnumFormatEtc* const newOne = new JuceEnumFormatEtc (format);
  183318. newOne->index = index;
  183319. *result = newOne;
  183320. return S_OK;
  183321. }
  183322. HRESULT __stdcall Next (ULONG celt, LPFORMATETC lpFormatEtc, ULONG* pceltFetched)
  183323. {
  183324. if (pceltFetched != 0)
  183325. *pceltFetched = 0;
  183326. else if (celt != 1)
  183327. return S_FALSE;
  183328. if (index == 0 && celt > 0 && lpFormatEtc != 0)
  183329. {
  183330. copyFormatEtc (lpFormatEtc [0], *format);
  183331. ++index;
  183332. if (pceltFetched != 0)
  183333. *pceltFetched = 1;
  183334. return S_OK;
  183335. }
  183336. return S_FALSE;
  183337. }
  183338. HRESULT __stdcall Skip (ULONG celt)
  183339. {
  183340. if (index + (int) celt >= 1)
  183341. return S_FALSE;
  183342. index += celt;
  183343. return S_OK;
  183344. }
  183345. HRESULT __stdcall Reset()
  183346. {
  183347. index = 0;
  183348. return S_OK;
  183349. }
  183350. private:
  183351. int refCount;
  183352. const FORMATETC* const format;
  183353. int index;
  183354. static void copyFormatEtc (FORMATETC& dest, const FORMATETC& source)
  183355. {
  183356. dest = source;
  183357. if (source.ptd != 0)
  183358. {
  183359. dest.ptd = (DVTARGETDEVICE*) CoTaskMemAlloc (sizeof (DVTARGETDEVICE));
  183360. *(dest.ptd) = *(source.ptd);
  183361. }
  183362. }
  183363. JuceEnumFormatEtc (const JuceEnumFormatEtc&);
  183364. JuceEnumFormatEtc& operator= (const JuceEnumFormatEtc&);
  183365. };
  183366. class JuceDataObject : public IDataObject
  183367. {
  183368. JuceDropSource* const dropSource;
  183369. const FORMATETC* const format;
  183370. const STGMEDIUM* const medium;
  183371. int refCount;
  183372. JuceDataObject (const JuceDataObject&);
  183373. JuceDataObject& operator= (const JuceDataObject&);
  183374. public:
  183375. JuceDataObject (JuceDropSource* const dropSource_,
  183376. const FORMATETC* const format_,
  183377. const STGMEDIUM* const medium_)
  183378. : dropSource (dropSource_),
  183379. format (format_),
  183380. medium (medium_),
  183381. refCount (1)
  183382. {
  183383. }
  183384. virtual ~JuceDataObject()
  183385. {
  183386. jassert (refCount == 0);
  183387. }
  183388. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183389. {
  183390. if (id == IID_IUnknown || id == IID_IDataObject)
  183391. {
  183392. AddRef();
  183393. *result = this;
  183394. return S_OK;
  183395. }
  183396. *result = 0;
  183397. return E_NOINTERFACE;
  183398. }
  183399. ULONG __stdcall AddRef() { return ++refCount; }
  183400. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183401. HRESULT __stdcall GetData (FORMATETC __RPC_FAR* pFormatEtc, STGMEDIUM __RPC_FAR* pMedium)
  183402. {
  183403. if ((pFormatEtc->tymed & format->tymed) != 0
  183404. && pFormatEtc->cfFormat == format->cfFormat
  183405. && pFormatEtc->dwAspect == format->dwAspect)
  183406. {
  183407. pMedium->tymed = format->tymed;
  183408. pMedium->pUnkForRelease = 0;
  183409. if (format->tymed == TYMED_HGLOBAL)
  183410. {
  183411. const SIZE_T len = GlobalSize (medium->hGlobal);
  183412. void* const src = GlobalLock (medium->hGlobal);
  183413. void* const dst = GlobalAlloc (GMEM_FIXED, len);
  183414. memcpy (dst, src, len);
  183415. GlobalUnlock (medium->hGlobal);
  183416. pMedium->hGlobal = dst;
  183417. return S_OK;
  183418. }
  183419. }
  183420. return DV_E_FORMATETC;
  183421. }
  183422. HRESULT __stdcall QueryGetData (FORMATETC __RPC_FAR* f)
  183423. {
  183424. if (f == 0)
  183425. return E_INVALIDARG;
  183426. if (f->tymed == format->tymed
  183427. && f->cfFormat == format->cfFormat
  183428. && f->dwAspect == format->dwAspect)
  183429. return S_OK;
  183430. return DV_E_FORMATETC;
  183431. }
  183432. HRESULT __stdcall GetCanonicalFormatEtc (FORMATETC __RPC_FAR*, FORMATETC __RPC_FAR* pFormatEtcOut)
  183433. {
  183434. pFormatEtcOut->ptd = 0;
  183435. return E_NOTIMPL;
  183436. }
  183437. HRESULT __stdcall EnumFormatEtc (DWORD direction, IEnumFORMATETC __RPC_FAR *__RPC_FAR *result)
  183438. {
  183439. if (result == 0)
  183440. return E_POINTER;
  183441. if (direction == DATADIR_GET)
  183442. {
  183443. *result = new JuceEnumFormatEtc (format);
  183444. return S_OK;
  183445. }
  183446. *result = 0;
  183447. return E_NOTIMPL;
  183448. }
  183449. HRESULT __stdcall GetDataHere (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*) { return DATA_E_FORMATETC; }
  183450. HRESULT __stdcall SetData (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*, BOOL) { return E_NOTIMPL; }
  183451. HRESULT __stdcall DAdvise (FORMATETC __RPC_FAR*, DWORD, IAdviseSink __RPC_FAR*, DWORD __RPC_FAR*) { return OLE_E_ADVISENOTSUPPORTED; }
  183452. HRESULT __stdcall DUnadvise (DWORD) { return E_NOTIMPL; }
  183453. HRESULT __stdcall EnumDAdvise (IEnumSTATDATA __RPC_FAR *__RPC_FAR *) { return OLE_E_ADVISENOTSUPPORTED; }
  183454. };
  183455. static HDROP createHDrop (const StringArray& fileNames) throw()
  183456. {
  183457. int totalChars = 0;
  183458. for (int i = fileNames.size(); --i >= 0;)
  183459. totalChars += fileNames[i].length() + 1;
  183460. HDROP hDrop = (HDROP) GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT,
  183461. sizeof (DROPFILES)
  183462. + sizeof (WCHAR) * (totalChars + 2));
  183463. if (hDrop != 0)
  183464. {
  183465. LPDROPFILES pDropFiles = (LPDROPFILES) GlobalLock (hDrop);
  183466. pDropFiles->pFiles = sizeof (DROPFILES);
  183467. pDropFiles->fWide = true;
  183468. WCHAR* fname = (WCHAR*) (((char*) pDropFiles) + sizeof (DROPFILES));
  183469. for (int i = 0; i < fileNames.size(); ++i)
  183470. {
  183471. fileNames[i].copyToUnicode (fname, 2048);
  183472. fname += fileNames[i].length() + 1;
  183473. }
  183474. *fname = 0;
  183475. GlobalUnlock (hDrop);
  183476. }
  183477. return hDrop;
  183478. }
  183479. static bool performDragDrop (FORMATETC* const format, STGMEDIUM* const medium, const DWORD whatToDo) throw()
  183480. {
  183481. JuceDropSource* const source = new JuceDropSource();
  183482. JuceDataObject* const data = new JuceDataObject (source, format, medium);
  183483. DWORD effect;
  183484. const HRESULT res = DoDragDrop (data, source, whatToDo, &effect);
  183485. data->Release();
  183486. source->Release();
  183487. return res == DRAGDROP_S_DROP;
  183488. }
  183489. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMove)
  183490. {
  183491. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183492. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183493. medium.hGlobal = createHDrop (files);
  183494. return performDragDrop (&format, &medium, canMove ? (DROPEFFECT_COPY | DROPEFFECT_MOVE)
  183495. : DROPEFFECT_COPY);
  183496. }
  183497. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  183498. {
  183499. FORMATETC format = { CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183500. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183501. const int numChars = text.length();
  183502. medium.hGlobal = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, (numChars + 2) * sizeof (WCHAR));
  183503. char* d = (char*) GlobalLock (medium.hGlobal);
  183504. text.copyToUnicode ((WCHAR*) d, numChars + 1);
  183505. format.cfFormat = CF_UNICODETEXT;
  183506. GlobalUnlock (medium.hGlobal);
  183507. return performDragDrop (&format, &medium, DROPEFFECT_COPY | DROPEFFECT_MOVE);
  183508. }
  183509. #endif
  183510. /*** End of inlined file: juce_win32_Windowing.cpp ***/
  183511. /*** Start of inlined file: juce_win32_Fonts.cpp ***/
  183512. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  183513. // compiled on its own).
  183514. #if JUCE_INCLUDED_FILE
  183515. static int CALLBACK wfontEnum2 (ENUMLOGFONTEXW* lpelfe,
  183516. NEWTEXTMETRICEXW*,
  183517. int type,
  183518. LPARAM lParam)
  183519. {
  183520. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  183521. {
  183522. const String fontName (lpelfe->elfLogFont.lfFaceName);
  183523. ((StringArray*) lParam)->addIfNotAlreadyThere (fontName.removeCharacters (T("@")));
  183524. }
  183525. return 1;
  183526. }
  183527. static int CALLBACK wfontEnum1 (ENUMLOGFONTEXW* lpelfe,
  183528. NEWTEXTMETRICEXW*,
  183529. int type,
  183530. LPARAM lParam)
  183531. {
  183532. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  183533. {
  183534. LOGFONTW lf;
  183535. zerostruct (lf);
  183536. lf.lfWeight = FW_DONTCARE;
  183537. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183538. lf.lfQuality = DEFAULT_QUALITY;
  183539. lf.lfCharSet = DEFAULT_CHARSET;
  183540. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183541. lf.lfPitchAndFamily = FF_DONTCARE;
  183542. const String fontName (lpelfe->elfLogFont.lfFaceName);
  183543. fontName.copyToUnicode (lf.lfFaceName, LF_FACESIZE - 1);
  183544. HDC dc = CreateCompatibleDC (0);
  183545. EnumFontFamiliesEx (dc, &lf,
  183546. (FONTENUMPROCW) &wfontEnum2,
  183547. lParam, 0);
  183548. DeleteDC (dc);
  183549. }
  183550. return 1;
  183551. }
  183552. const StringArray Font::findAllTypefaceNames()
  183553. {
  183554. StringArray results;
  183555. HDC dc = CreateCompatibleDC (0);
  183556. {
  183557. LOGFONTW lf;
  183558. zerostruct (lf);
  183559. lf.lfWeight = FW_DONTCARE;
  183560. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183561. lf.lfQuality = DEFAULT_QUALITY;
  183562. lf.lfCharSet = DEFAULT_CHARSET;
  183563. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183564. lf.lfPitchAndFamily = FF_DONTCARE;
  183565. lf.lfFaceName[0] = 0;
  183566. EnumFontFamiliesEx (dc, &lf,
  183567. (FONTENUMPROCW) &wfontEnum1,
  183568. (LPARAM) &results, 0);
  183569. }
  183570. DeleteDC (dc);
  183571. results.sort (true);
  183572. return results;
  183573. }
  183574. extern bool juce_IsRunningInWine();
  183575. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed)
  183576. {
  183577. if (juce_IsRunningInWine())
  183578. {
  183579. // If we're running in Wine, then use fonts that might be available on Linux..
  183580. defaultSans = "Bitstream Vera Sans";
  183581. defaultSerif = "Bitstream Vera Serif";
  183582. defaultFixed = "Bitstream Vera Sans Mono";
  183583. }
  183584. else
  183585. {
  183586. defaultSans = "Verdana";
  183587. defaultSerif = "Times";
  183588. defaultFixed = "Lucida Console";
  183589. }
  183590. }
  183591. class FontDCHolder : private DeletedAtShutdown
  183592. {
  183593. public:
  183594. FontDCHolder() throw()
  183595. : dc (0), numKPs (0), size (0),
  183596. bold (false), italic (false)
  183597. {
  183598. }
  183599. ~FontDCHolder() throw()
  183600. {
  183601. if (dc != 0)
  183602. {
  183603. DeleteDC (dc);
  183604. DeleteObject (fontH);
  183605. }
  183606. clearSingletonInstance();
  183607. }
  183608. juce_DeclareSingleton_SingleThreaded_Minimal (FontDCHolder);
  183609. HDC loadFont (const String& fontName_, const bool bold_, const bool italic_, const int size_) throw()
  183610. {
  183611. if (fontName != fontName_ || bold != bold_ || italic != italic_ || size != size_)
  183612. {
  183613. fontName = fontName_;
  183614. bold = bold_;
  183615. italic = italic_;
  183616. size = size_;
  183617. if (dc != 0)
  183618. {
  183619. DeleteDC (dc);
  183620. DeleteObject (fontH);
  183621. kps.free();
  183622. }
  183623. fontH = 0;
  183624. dc = CreateCompatibleDC (0);
  183625. SetMapperFlags (dc, 0);
  183626. SetMapMode (dc, MM_TEXT);
  183627. LOGFONTW lfw;
  183628. zerostruct (lfw);
  183629. lfw.lfCharSet = DEFAULT_CHARSET;
  183630. lfw.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183631. lfw.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183632. lfw.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
  183633. lfw.lfQuality = PROOF_QUALITY;
  183634. lfw.lfItalic = (BYTE) (italic ? TRUE : FALSE);
  183635. lfw.lfWeight = bold ? FW_BOLD : FW_NORMAL;
  183636. fontName.copyToUnicode (lfw.lfFaceName, LF_FACESIZE - 1);
  183637. lfw.lfHeight = size > 0 ? size : -256;
  183638. HFONT standardSizedFont = CreateFontIndirect (&lfw);
  183639. if (standardSizedFont != 0)
  183640. {
  183641. if (SelectObject (dc, standardSizedFont) != 0)
  183642. {
  183643. fontH = standardSizedFont;
  183644. if (size == 0)
  183645. {
  183646. OUTLINETEXTMETRIC otm;
  183647. if (GetOutlineTextMetrics (dc, sizeof (otm), &otm) != 0)
  183648. {
  183649. lfw.lfHeight = -(int) otm.otmEMSquare;
  183650. fontH = CreateFontIndirect (&lfw);
  183651. SelectObject (dc, fontH);
  183652. DeleteObject (standardSizedFont);
  183653. }
  183654. }
  183655. }
  183656. else
  183657. {
  183658. jassertfalse
  183659. }
  183660. }
  183661. else
  183662. {
  183663. jassertfalse
  183664. }
  183665. }
  183666. return dc;
  183667. }
  183668. KERNINGPAIR* getKerningPairs (int& numKPs_) throw()
  183669. {
  183670. if (kps == 0)
  183671. {
  183672. numKPs = GetKerningPairs (dc, 0, 0);
  183673. kps.calloc (numKPs);
  183674. GetKerningPairs (dc, numKPs, kps);
  183675. }
  183676. numKPs_ = numKPs;
  183677. return kps;
  183678. }
  183679. private:
  183680. HFONT fontH;
  183681. HDC dc;
  183682. String fontName;
  183683. HeapBlock <KERNINGPAIR> kps;
  183684. int numKPs, size;
  183685. bool bold, italic;
  183686. FontDCHolder (const FontDCHolder&);
  183687. FontDCHolder& operator= (const FontDCHolder&);
  183688. };
  183689. juce_ImplementSingleton_SingleThreaded (FontDCHolder);
  183690. class WindowsTypeface : public CustomTypeface
  183691. {
  183692. public:
  183693. WindowsTypeface (const Font& font)
  183694. {
  183695. HDC dc = FontDCHolder::getInstance()->loadFont (font.getTypefaceName(),
  183696. font.isBold(), font.isItalic(), 0);
  183697. TEXTMETRIC tm;
  183698. tm.tmAscent = tm.tmHeight = 1;
  183699. tm.tmDefaultChar = 0;
  183700. GetTextMetrics (dc, &tm);
  183701. setCharacteristics (font.getTypefaceName(),
  183702. tm.tmAscent / (float) tm.tmHeight,
  183703. font.isBold(), font.isItalic(),
  183704. tm.tmDefaultChar);
  183705. }
  183706. bool loadGlyphIfPossible (juce_wchar character)
  183707. {
  183708. HDC dc = FontDCHolder::getInstance()->loadFont (name, isBold, isItalic, 0);
  183709. GLYPHMETRICS gm;
  183710. {
  183711. const WCHAR charToTest[] = { (WCHAR) character, 0 };
  183712. WORD index = 0;
  183713. if (GetGlyphIndices (dc, charToTest, 1, &index, GGI_MARK_NONEXISTING_GLYPHS) != GDI_ERROR
  183714. && index == 0xffff)
  183715. {
  183716. return false;
  183717. }
  183718. }
  183719. Path glyphPath;
  183720. TEXTMETRIC tm;
  183721. if (! GetTextMetrics (dc, &tm))
  183722. {
  183723. addGlyph (character, glyphPath, 0);
  183724. return true;
  183725. }
  183726. const float height = (float) tm.tmHeight;
  183727. static const MAT2 identityMatrix = { { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 1 } };
  183728. const int bufSize = GetGlyphOutline (dc, character, GGO_NATIVE,
  183729. &gm, 0, 0, &identityMatrix);
  183730. if (bufSize > 0)
  183731. {
  183732. HeapBlock<char> data (bufSize);
  183733. GetGlyphOutline (dc, character, GGO_NATIVE, &gm,
  183734. bufSize, data, &identityMatrix);
  183735. const TTPOLYGONHEADER* pheader = reinterpret_cast<TTPOLYGONHEADER*> (data.getData());
  183736. const float scaleX = 1.0f / height;
  183737. const float scaleY = -1.0f / height;
  183738. while ((char*) pheader < data + bufSize)
  183739. {
  183740. float x = scaleX * pheader->pfxStart.x.value;
  183741. float y = scaleY * pheader->pfxStart.y.value;
  183742. glyphPath.startNewSubPath (x, y);
  183743. const TTPOLYCURVE* curve = (const TTPOLYCURVE*) ((const char*) pheader + sizeof (TTPOLYGONHEADER));
  183744. const char* const curveEnd = ((const char*) pheader) + pheader->cb;
  183745. while ((const char*) curve < curveEnd)
  183746. {
  183747. if (curve->wType == TT_PRIM_LINE)
  183748. {
  183749. for (int i = 0; i < curve->cpfx; ++i)
  183750. {
  183751. x = scaleX * curve->apfx[i].x.value;
  183752. y = scaleY * curve->apfx[i].y.value;
  183753. glyphPath.lineTo (x, y);
  183754. }
  183755. }
  183756. else if (curve->wType == TT_PRIM_QSPLINE)
  183757. {
  183758. for (int i = 0; i < curve->cpfx - 1; ++i)
  183759. {
  183760. const float x2 = scaleX * curve->apfx[i].x.value;
  183761. const float y2 = scaleY * curve->apfx[i].y.value;
  183762. float x3, y3;
  183763. if (i < curve->cpfx - 2)
  183764. {
  183765. x3 = 0.5f * (x2 + scaleX * curve->apfx[i + 1].x.value);
  183766. y3 = 0.5f * (y2 + scaleY * curve->apfx[i + 1].y.value);
  183767. }
  183768. else
  183769. {
  183770. x3 = scaleX * curve->apfx[i + 1].x.value;
  183771. y3 = scaleY * curve->apfx[i + 1].y.value;
  183772. }
  183773. glyphPath.quadraticTo (x2, y2, x3, y3);
  183774. x = x3;
  183775. y = y3;
  183776. }
  183777. }
  183778. curve = (const TTPOLYCURVE*) &(curve->apfx [curve->cpfx]);
  183779. }
  183780. pheader = (const TTPOLYGONHEADER*) curve;
  183781. glyphPath.closeSubPath();
  183782. }
  183783. }
  183784. addGlyph (character, glyphPath, gm.gmCellIncX / height);
  183785. int numKPs;
  183786. const KERNINGPAIR* const kps = FontDCHolder::getInstance()->getKerningPairs (numKPs);
  183787. for (int i = 0; i < numKPs; ++i)
  183788. {
  183789. if (kps[i].wFirst == character)
  183790. addKerningPair (kps[i].wFirst, kps[i].wSecond,
  183791. kps[i].iKernAmount / height);
  183792. }
  183793. return true;
  183794. }
  183795. };
  183796. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  183797. {
  183798. return new WindowsTypeface (font);
  183799. }
  183800. #endif
  183801. /*** End of inlined file: juce_win32_Fonts.cpp ***/
  183802. /*** Start of inlined file: juce_win32_FileChooser.cpp ***/
  183803. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  183804. // compiled on its own).
  183805. #if JUCE_INCLUDED_FILE
  183806. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw();
  183807. namespace FileChooserHelpers
  183808. {
  183809. static const void* defaultDirPath = 0;
  183810. static String returnedString; // need this to get non-existent pathnames from the directory chooser
  183811. static Component* currentExtraFileWin = 0;
  183812. static bool areThereAnyAlwaysOnTopWindows()
  183813. {
  183814. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  183815. {
  183816. Component* c = Desktop::getInstance().getComponent (i);
  183817. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  183818. return true;
  183819. }
  183820. return false;
  183821. }
  183822. static int CALLBACK browseCallbackProc (HWND hWnd, UINT msg, LPARAM lParam, LPARAM /*lpData*/)
  183823. {
  183824. if (msg == BFFM_INITIALIZED)
  183825. SendMessage (hWnd, BFFM_SETSELECTIONW, TRUE, (LPARAM) defaultDirPath);
  183826. else if (msg == BFFM_VALIDATEFAILEDW)
  183827. returnedString = (LPCWSTR) lParam;
  183828. else if (msg == BFFM_VALIDATEFAILEDA)
  183829. returnedString = (const char*) lParam;
  183830. return 0;
  183831. }
  183832. static UINT_PTR CALLBACK openCallback (HWND hdlg, UINT uiMsg, WPARAM /*wParam*/, LPARAM lParam)
  183833. {
  183834. if (currentExtraFileWin != 0)
  183835. {
  183836. if (uiMsg == WM_INITDIALOG)
  183837. {
  183838. HWND dialogH = GetParent (hdlg);
  183839. jassert (dialogH != 0);
  183840. if (dialogH == 0)
  183841. dialogH = hdlg;
  183842. RECT r, cr;
  183843. GetWindowRect (dialogH, &r);
  183844. GetClientRect (dialogH, &cr);
  183845. SetWindowPos (dialogH, 0,
  183846. r.left, r.top,
  183847. currentExtraFileWin->getWidth() + jmax (150, (int) (r.right - r.left)),
  183848. jmax (150, (int) (r.bottom - r.top)),
  183849. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  183850. currentExtraFileWin->setBounds (cr.right, cr.top, currentExtraFileWin->getWidth(), cr.bottom - cr.top);
  183851. currentExtraFileWin->getChildComponent(0)->setBounds (0, 0, currentExtraFileWin->getWidth(), currentExtraFileWin->getHeight());
  183852. SetParent ((HWND) currentExtraFileWin->getWindowHandle(), (HWND) dialogH);
  183853. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_CHILD, (dialogH != 0));
  183854. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_POPUP, (dialogH == 0));
  183855. }
  183856. else if (uiMsg == WM_NOTIFY)
  183857. {
  183858. LPOFNOTIFY ofn = (LPOFNOTIFY) lParam;
  183859. if (ofn->hdr.code == CDN_SELCHANGE)
  183860. {
  183861. FilePreviewComponent* comp = (FilePreviewComponent*) currentExtraFileWin->getChildComponent(0);
  183862. if (comp != 0)
  183863. {
  183864. TCHAR path [MAX_PATH * 2];
  183865. path[0] = 0;
  183866. CommDlg_OpenSave_GetFilePath (GetParent (hdlg), (LPARAM) &path, MAX_PATH);
  183867. const String fn ((const WCHAR*) path);
  183868. comp->selectedFileChanged (File (fn));
  183869. }
  183870. }
  183871. }
  183872. }
  183873. return 0;
  183874. }
  183875. class FPComponentHolder : public Component
  183876. {
  183877. public:
  183878. FPComponentHolder()
  183879. {
  183880. setVisible (true);
  183881. setOpaque (true);
  183882. }
  183883. ~FPComponentHolder()
  183884. {
  183885. }
  183886. void paint (Graphics& g)
  183887. {
  183888. g.fillAll (Colours::lightgrey);
  183889. }
  183890. private:
  183891. FPComponentHolder (const FPComponentHolder&);
  183892. FPComponentHolder& operator= (const FPComponentHolder&);
  183893. };
  183894. }
  183895. void FileChooser::showPlatformDialog (Array<File>& results,
  183896. const String& title,
  183897. const File& currentFileOrDirectory,
  183898. const String& filter,
  183899. bool selectsDirectory,
  183900. bool /*selectsFiles*/,
  183901. bool isSaveDialogue,
  183902. bool warnAboutOverwritingExistingFiles,
  183903. bool selectMultipleFiles,
  183904. FilePreviewComponent* extraInfoComponent)
  183905. {
  183906. using namespace FileChooserHelpers;
  183907. const int numCharsAvailable = 32768;
  183908. MemoryBlock filenameSpace ((numCharsAvailable + 1) * sizeof (WCHAR), true);
  183909. WCHAR* const fname = (WCHAR*) filenameSpace.getData();
  183910. int fnameIdx = 0;
  183911. JUCE_TRY
  183912. {
  183913. // use a modal window as the parent for this dialog box
  183914. // to block input from other app windows
  183915. const Rectangle<int> mainMon (Desktop::getInstance().getMainMonitorArea());
  183916. Component w (String::empty);
  183917. w.setBounds (mainMon.getX() + mainMon.getWidth() / 4,
  183918. mainMon.getY() + mainMon.getHeight() / 4,
  183919. 0, 0);
  183920. w.setOpaque (true);
  183921. w.setAlwaysOnTop (areThereAnyAlwaysOnTopWindows());
  183922. w.addToDesktop (0);
  183923. if (extraInfoComponent == 0)
  183924. w.enterModalState();
  183925. String initialDir;
  183926. if (currentFileOrDirectory.isDirectory())
  183927. {
  183928. initialDir = currentFileOrDirectory.getFullPathName();
  183929. }
  183930. else
  183931. {
  183932. currentFileOrDirectory.getFileName().copyToUnicode (fname, numCharsAvailable);
  183933. initialDir = currentFileOrDirectory.getParentDirectory().getFullPathName();
  183934. }
  183935. if (currentExtraFileWin->isValidComponent())
  183936. {
  183937. jassertfalse
  183938. return;
  183939. }
  183940. if (selectsDirectory)
  183941. {
  183942. LPITEMIDLIST list = 0;
  183943. filenameSpace.fillWith (0);
  183944. {
  183945. BROWSEINFO bi;
  183946. zerostruct (bi);
  183947. bi.hwndOwner = (HWND) w.getWindowHandle();
  183948. bi.pszDisplayName = fname;
  183949. bi.lpszTitle = title;
  183950. bi.lpfn = browseCallbackProc;
  183951. #ifdef BIF_USENEWUI
  183952. bi.ulFlags = BIF_USENEWUI | BIF_VALIDATE;
  183953. #else
  183954. bi.ulFlags = 0x50;
  183955. #endif
  183956. defaultDirPath = (const WCHAR*) initialDir;
  183957. list = SHBrowseForFolder (&bi);
  183958. if (! SHGetPathFromIDListW (list, fname))
  183959. {
  183960. fname[0] = 0;
  183961. returnedString = String::empty;
  183962. }
  183963. }
  183964. LPMALLOC al;
  183965. if (list != 0 && SUCCEEDED (SHGetMalloc (&al)))
  183966. al->Free (list);
  183967. defaultDirPath = 0;
  183968. if (returnedString.isNotEmpty())
  183969. {
  183970. const String stringFName (fname);
  183971. results.add (File (stringFName).getSiblingFile (returnedString));
  183972. returnedString = String::empty;
  183973. return;
  183974. }
  183975. }
  183976. else
  183977. {
  183978. DWORD flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
  183979. if (warnAboutOverwritingExistingFiles)
  183980. flags |= OFN_OVERWRITEPROMPT;
  183981. if (selectMultipleFiles)
  183982. flags |= OFN_ALLOWMULTISELECT;
  183983. if (extraInfoComponent != 0)
  183984. {
  183985. flags |= OFN_ENABLEHOOK;
  183986. currentExtraFileWin = new FPComponentHolder();
  183987. currentExtraFileWin->addAndMakeVisible (extraInfoComponent);
  183988. currentExtraFileWin->setSize (jlimit (20, 800, extraInfoComponent->getWidth()),
  183989. extraInfoComponent->getHeight());
  183990. currentExtraFileWin->addToDesktop (0);
  183991. currentExtraFileWin->enterModalState();
  183992. }
  183993. {
  183994. WCHAR filters [1024];
  183995. zeromem (filters, sizeof (filters));
  183996. filter.copyToUnicode (filters, 1024);
  183997. filter.copyToUnicode (filters + filter.length() + 1,
  183998. 1022 - filter.length());
  183999. OPENFILENAMEW of;
  184000. zerostruct (of);
  184001. #ifdef OPENFILENAME_SIZE_VERSION_400W
  184002. of.lStructSize = OPENFILENAME_SIZE_VERSION_400W;
  184003. #else
  184004. of.lStructSize = sizeof (of);
  184005. #endif
  184006. of.hwndOwner = (HWND) w.getWindowHandle();
  184007. of.lpstrFilter = filters;
  184008. of.nFilterIndex = 1;
  184009. of.lpstrFile = fname;
  184010. of.nMaxFile = numCharsAvailable;
  184011. of.lpstrInitialDir = initialDir;
  184012. of.lpstrTitle = title;
  184013. of.Flags = flags;
  184014. if (extraInfoComponent != 0)
  184015. of.lpfnHook = &openCallback;
  184016. if (isSaveDialogue)
  184017. {
  184018. if (! GetSaveFileName (&of))
  184019. fname[0] = 0;
  184020. else
  184021. fnameIdx = of.nFileOffset;
  184022. }
  184023. else
  184024. {
  184025. if (! GetOpenFileName (&of))
  184026. fname[0] = 0;
  184027. else
  184028. fnameIdx = of.nFileOffset;
  184029. }
  184030. }
  184031. }
  184032. }
  184033. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  184034. catch (...)
  184035. {
  184036. fname[0] = 0;
  184037. }
  184038. #endif
  184039. deleteAndZero (currentExtraFileWin);
  184040. const WCHAR* const files = fname;
  184041. if (selectMultipleFiles && fnameIdx > 0 && files [fnameIdx - 1] == 0)
  184042. {
  184043. const WCHAR* filename = files + fnameIdx;
  184044. while (*filename != 0)
  184045. {
  184046. const String filepath (String (files) + "\\" + String (filename));
  184047. results.add (File (filepath));
  184048. filename += CharacterFunctions::length (filename) + 1;
  184049. }
  184050. }
  184051. else if (files[0] != 0)
  184052. {
  184053. results.add (File (files));
  184054. }
  184055. }
  184056. #endif
  184057. /*** End of inlined file: juce_win32_FileChooser.cpp ***/
  184058. /*** Start of inlined file: juce_win32_Misc.cpp ***/
  184059. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184060. // compiled on its own).
  184061. #if JUCE_INCLUDED_FILE
  184062. void SystemClipboard::copyTextToClipboard (const String& text)
  184063. {
  184064. if (OpenClipboard (0) != 0)
  184065. {
  184066. if (EmptyClipboard() != 0)
  184067. {
  184068. const int len = text.length();
  184069. if (len > 0)
  184070. {
  184071. HGLOBAL bufH = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE,
  184072. (len + 1) * sizeof (wchar_t));
  184073. if (bufH != 0)
  184074. {
  184075. WCHAR* const data = (WCHAR*) GlobalLock (bufH);
  184076. text.copyToUnicode (data, len);
  184077. GlobalUnlock (bufH);
  184078. SetClipboardData (CF_UNICODETEXT, bufH);
  184079. }
  184080. }
  184081. }
  184082. CloseClipboard();
  184083. }
  184084. }
  184085. const String SystemClipboard::getTextFromClipboard()
  184086. {
  184087. String result;
  184088. if (OpenClipboard (0) != 0)
  184089. {
  184090. HANDLE bufH = GetClipboardData (CF_UNICODETEXT);
  184091. if (bufH != 0)
  184092. {
  184093. const wchar_t* const data = (const wchar_t*) GlobalLock (bufH);
  184094. if (data != 0)
  184095. {
  184096. result = String (data, (int) (GlobalSize (bufH) / sizeof (tchar)));
  184097. GlobalUnlock (bufH);
  184098. }
  184099. }
  184100. CloseClipboard();
  184101. }
  184102. return result;
  184103. }
  184104. #endif
  184105. /*** End of inlined file: juce_win32_Misc.cpp ***/
  184106. /*** Start of inlined file: juce_win32_ActiveXComponent.cpp ***/
  184107. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184108. // compiled on its own).
  184109. #if JUCE_INCLUDED_FILE
  184110. namespace ActiveXHelpers
  184111. {
  184112. class JuceIStorage : public IStorage
  184113. {
  184114. int refCount;
  184115. public:
  184116. JuceIStorage() : refCount (1) {}
  184117. virtual ~JuceIStorage()
  184118. {
  184119. jassert (refCount == 0);
  184120. }
  184121. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184122. {
  184123. if (id == IID_IUnknown || id == IID_IStorage)
  184124. {
  184125. AddRef();
  184126. *result = this;
  184127. return S_OK;
  184128. }
  184129. *result = 0;
  184130. return E_NOINTERFACE;
  184131. }
  184132. ULONG __stdcall AddRef() { return ++refCount; }
  184133. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184134. HRESULT __stdcall CreateStream (const WCHAR*, DWORD, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184135. HRESULT __stdcall OpenStream (const WCHAR*, void*, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184136. HRESULT __stdcall CreateStorage (const WCHAR*, DWORD, DWORD, DWORD, IStorage**) { return E_NOTIMPL; }
  184137. HRESULT __stdcall OpenStorage (const WCHAR*, IStorage*, DWORD, SNB, DWORD, IStorage**) { return E_NOTIMPL; }
  184138. HRESULT __stdcall CopyTo (DWORD, IID const*, SNB, IStorage*) { return E_NOTIMPL; }
  184139. HRESULT __stdcall MoveElementTo (const OLECHAR*,IStorage*, const OLECHAR*, DWORD) { return E_NOTIMPL; }
  184140. HRESULT __stdcall Commit (DWORD) { return E_NOTIMPL; }
  184141. HRESULT __stdcall Revert() { return E_NOTIMPL; }
  184142. HRESULT __stdcall EnumElements (DWORD, void*, DWORD, IEnumSTATSTG**) { return E_NOTIMPL; }
  184143. HRESULT __stdcall DestroyElement (const OLECHAR*) { return E_NOTIMPL; }
  184144. HRESULT __stdcall RenameElement (const WCHAR*, const WCHAR*) { return E_NOTIMPL; }
  184145. HRESULT __stdcall SetElementTimes (const WCHAR*, FILETIME const*, FILETIME const*, FILETIME const*) { return E_NOTIMPL; }
  184146. HRESULT __stdcall SetClass (REFCLSID) { return S_OK; }
  184147. HRESULT __stdcall SetStateBits (DWORD, DWORD) { return E_NOTIMPL; }
  184148. HRESULT __stdcall Stat (STATSTG*, DWORD) { return E_NOTIMPL; }
  184149. juce_UseDebuggingNewOperator
  184150. };
  184151. class JuceOleInPlaceFrame : public IOleInPlaceFrame
  184152. {
  184153. int refCount;
  184154. HWND window;
  184155. public:
  184156. JuceOleInPlaceFrame (HWND window_)
  184157. : refCount (1),
  184158. window (window_)
  184159. {
  184160. }
  184161. virtual ~JuceOleInPlaceFrame()
  184162. {
  184163. jassert (refCount == 0);
  184164. }
  184165. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184166. {
  184167. if (id == IID_IUnknown || id == IID_IOleInPlaceFrame)
  184168. {
  184169. AddRef();
  184170. *result = this;
  184171. return S_OK;
  184172. }
  184173. *result = 0;
  184174. return E_NOINTERFACE;
  184175. }
  184176. ULONG __stdcall AddRef() { return ++refCount; }
  184177. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184178. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184179. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184180. HRESULT __stdcall GetBorder (LPRECT) { return E_NOTIMPL; }
  184181. HRESULT __stdcall RequestBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184182. HRESULT __stdcall SetBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184183. HRESULT __stdcall SetActiveObject (IOleInPlaceActiveObject*, LPCOLESTR) { return S_OK; }
  184184. HRESULT __stdcall InsertMenus (HMENU, LPOLEMENUGROUPWIDTHS) { return E_NOTIMPL; }
  184185. HRESULT __stdcall SetMenu (HMENU, HOLEMENU, HWND) { return S_OK; }
  184186. HRESULT __stdcall RemoveMenus (HMENU) { return E_NOTIMPL; }
  184187. HRESULT __stdcall SetStatusText (LPCOLESTR) { return S_OK; }
  184188. HRESULT __stdcall EnableModeless (BOOL) { return S_OK; }
  184189. HRESULT __stdcall TranslateAccelerator(LPMSG, WORD) { return E_NOTIMPL; }
  184190. juce_UseDebuggingNewOperator
  184191. };
  184192. class JuceIOleInPlaceSite : public IOleInPlaceSite
  184193. {
  184194. int refCount;
  184195. HWND window;
  184196. JuceOleInPlaceFrame* frame;
  184197. public:
  184198. JuceIOleInPlaceSite (HWND window_)
  184199. : refCount (1),
  184200. window (window_)
  184201. {
  184202. frame = new JuceOleInPlaceFrame (window);
  184203. }
  184204. virtual ~JuceIOleInPlaceSite()
  184205. {
  184206. jassert (refCount == 0);
  184207. frame->Release();
  184208. }
  184209. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184210. {
  184211. if (id == IID_IUnknown || id == IID_IOleInPlaceSite)
  184212. {
  184213. AddRef();
  184214. *result = this;
  184215. return S_OK;
  184216. }
  184217. *result = 0;
  184218. return E_NOINTERFACE;
  184219. }
  184220. ULONG __stdcall AddRef() { return ++refCount; }
  184221. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184222. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184223. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184224. HRESULT __stdcall CanInPlaceActivate() { return S_OK; }
  184225. HRESULT __stdcall OnInPlaceActivate() { return S_OK; }
  184226. HRESULT __stdcall OnUIActivate() { return S_OK; }
  184227. HRESULT __stdcall GetWindowContext (LPOLEINPLACEFRAME* lplpFrame, LPOLEINPLACEUIWINDOW* lplpDoc, LPRECT, LPRECT, LPOLEINPLACEFRAMEINFO lpFrameInfo)
  184228. {
  184229. // frame->AddRef(); // MS docs are unclear about whether this is needed, but it seems to lead to a memory leak..
  184230. *lplpFrame = frame;
  184231. *lplpDoc = 0;
  184232. lpFrameInfo->fMDIApp = FALSE;
  184233. lpFrameInfo->hwndFrame = window;
  184234. lpFrameInfo->haccel = 0;
  184235. lpFrameInfo->cAccelEntries = 0;
  184236. return S_OK;
  184237. }
  184238. HRESULT __stdcall Scroll (SIZE) { return E_NOTIMPL; }
  184239. HRESULT __stdcall OnUIDeactivate (BOOL) { return S_OK; }
  184240. HRESULT __stdcall OnInPlaceDeactivate() { return S_OK; }
  184241. HRESULT __stdcall DiscardUndoState() { return E_NOTIMPL; }
  184242. HRESULT __stdcall DeactivateAndUndo() { return E_NOTIMPL; }
  184243. HRESULT __stdcall OnPosRectChange (LPCRECT) { return S_OK; }
  184244. juce_UseDebuggingNewOperator
  184245. };
  184246. class JuceIOleClientSite : public IOleClientSite
  184247. {
  184248. int refCount;
  184249. JuceIOleInPlaceSite* inplaceSite;
  184250. public:
  184251. JuceIOleClientSite (HWND window)
  184252. : refCount (1)
  184253. {
  184254. inplaceSite = new JuceIOleInPlaceSite (window);
  184255. }
  184256. virtual ~JuceIOleClientSite()
  184257. {
  184258. jassert (refCount == 0);
  184259. inplaceSite->Release();
  184260. }
  184261. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184262. {
  184263. if (id == IID_IUnknown || id == IID_IOleClientSite)
  184264. {
  184265. AddRef();
  184266. *result = this;
  184267. return S_OK;
  184268. }
  184269. else if (id == IID_IOleInPlaceSite)
  184270. {
  184271. inplaceSite->AddRef();
  184272. *result = inplaceSite;
  184273. return S_OK;
  184274. }
  184275. *result = 0;
  184276. return E_NOINTERFACE;
  184277. }
  184278. ULONG __stdcall AddRef() { return ++refCount; }
  184279. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184280. HRESULT __stdcall SaveObject() { return E_NOTIMPL; }
  184281. HRESULT __stdcall GetMoniker (DWORD, DWORD, IMoniker**) { return E_NOTIMPL; }
  184282. HRESULT __stdcall GetContainer (LPOLECONTAINER* ppContainer) { *ppContainer = 0; return E_NOINTERFACE; }
  184283. HRESULT __stdcall ShowObject() { return S_OK; }
  184284. HRESULT __stdcall OnShowWindow (BOOL) { return E_NOTIMPL; }
  184285. HRESULT __stdcall RequestNewObjectLayout() { return E_NOTIMPL; }
  184286. juce_UseDebuggingNewOperator
  184287. };
  184288. static VoidArray activeXComps;
  184289. static HWND getHWND (const ActiveXControlComponent* const component)
  184290. {
  184291. HWND hwnd = 0;
  184292. const IID iid = IID_IOleWindow;
  184293. IOleWindow* const window = (IOleWindow*) component->queryInterface (&iid);
  184294. if (window != 0)
  184295. {
  184296. window->GetWindow (&hwnd);
  184297. window->Release();
  184298. }
  184299. return hwnd;
  184300. }
  184301. static void offerActiveXMouseEventToPeer (ComponentPeer* const peer, HWND hwnd, UINT message, LPARAM lParam)
  184302. {
  184303. RECT activeXRect, peerRect;
  184304. GetWindowRect (hwnd, &activeXRect);
  184305. GetWindowRect ((HWND) peer->getNativeHandle(), &peerRect);
  184306. const Point<int> mousePos (GET_X_LPARAM (lParam) + activeXRect.left - peerRect.left,
  184307. GET_Y_LPARAM (lParam) + activeXRect.top - peerRect.top);
  184308. const int64 mouseEventTime = Win32ComponentPeer::getMouseEventTime();
  184309. ModifierKeys::getCurrentModifiersRealtime(); // to update the mouse button flags
  184310. switch (message)
  184311. {
  184312. case WM_MOUSEMOVE:
  184313. case WM_LBUTTONDOWN:
  184314. case WM_MBUTTONDOWN:
  184315. case WM_RBUTTONDOWN:
  184316. case WM_LBUTTONUP:
  184317. case WM_MBUTTONUP:
  184318. case WM_RBUTTONUP:
  184319. peer->handleMouseEvent (0, mousePos, Win32ComponentPeer::currentModifiers, mouseEventTime);
  184320. break;
  184321. default:
  184322. break;
  184323. }
  184324. }
  184325. }
  184326. class ActiveXControlComponent::ActiveXControlData : public ComponentMovementWatcher
  184327. {
  184328. ActiveXControlComponent* const owner;
  184329. bool wasShowing;
  184330. public:
  184331. HWND controlHWND;
  184332. IStorage* storage;
  184333. IOleClientSite* clientSite;
  184334. IOleObject* control;
  184335. ActiveXControlData (HWND hwnd,
  184336. ActiveXControlComponent* const owner_)
  184337. : ComponentMovementWatcher (owner_),
  184338. owner (owner_),
  184339. wasShowing (owner_ != 0 && owner_->isShowing()),
  184340. controlHWND (0),
  184341. storage (new ActiveXHelpers::JuceIStorage()),
  184342. clientSite (new ActiveXHelpers::JuceIOleClientSite (hwnd)),
  184343. control (0)
  184344. {
  184345. }
  184346. ~ActiveXControlData()
  184347. {
  184348. if (control != 0)
  184349. {
  184350. control->Close (OLECLOSE_NOSAVE);
  184351. control->Release();
  184352. }
  184353. clientSite->Release();
  184354. storage->Release();
  184355. }
  184356. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  184357. {
  184358. Component* const topComp = owner->getTopLevelComponent();
  184359. if (topComp->getPeer() != 0)
  184360. {
  184361. const Point<int> pos (owner->relativePositionToOtherComponent (topComp, Point<int>()));
  184362. owner->setControlBounds (Rectangle<int> (pos.getX(), pos.getY(), owner->getWidth(), owner->getHeight()));
  184363. }
  184364. }
  184365. void componentPeerChanged()
  184366. {
  184367. const bool isShowingNow = owner->isShowing();
  184368. if (wasShowing != isShowingNow)
  184369. {
  184370. wasShowing = isShowingNow;
  184371. owner->setControlVisible (isShowingNow);
  184372. }
  184373. componentMovedOrResized (true, true);
  184374. }
  184375. void componentVisibilityChanged (Component&)
  184376. {
  184377. componentPeerChanged();
  184378. }
  184379. static bool doesWindowMatch (const ActiveXControlComponent* const ax, HWND hwnd)
  184380. {
  184381. return ((ActiveXControlData*) ax->control) != 0
  184382. && ((ActiveXControlData*) ax->control)->controlHWND == hwnd;
  184383. }
  184384. // intercepts events going to an activeX control, so we can sneakily use the mouse events
  184385. static LRESULT CALLBACK activeXHookWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  184386. {
  184387. for (int i = ActiveXHelpers::activeXComps.size(); --i >= 0;)
  184388. {
  184389. const ActiveXControlComponent* const ax = (const ActiveXControlComponent*) ActiveXHelpers::activeXComps.getUnchecked(i);
  184390. if (doesWindowMatch (ax, hwnd))
  184391. {
  184392. switch (message)
  184393. {
  184394. case WM_MOUSEMOVE:
  184395. case WM_LBUTTONDOWN:
  184396. case WM_MBUTTONDOWN:
  184397. case WM_RBUTTONDOWN:
  184398. case WM_LBUTTONUP:
  184399. case WM_MBUTTONUP:
  184400. case WM_RBUTTONUP:
  184401. case WM_LBUTTONDBLCLK:
  184402. case WM_MBUTTONDBLCLK:
  184403. case WM_RBUTTONDBLCLK:
  184404. if (ax->isShowing())
  184405. {
  184406. ComponentPeer* const peer = ax->getPeer();
  184407. if (peer != 0)
  184408. {
  184409. ActiveXHelpers::offerActiveXMouseEventToPeer (peer, hwnd, message, lParam);
  184410. if (! ax->areMouseEventsAllowed())
  184411. return 0;
  184412. }
  184413. }
  184414. break;
  184415. default:
  184416. break;
  184417. }
  184418. return CallWindowProc ((WNDPROC) (ax->originalWndProc), hwnd, message, wParam, lParam);
  184419. }
  184420. }
  184421. return DefWindowProc (hwnd, message, wParam, lParam);
  184422. }
  184423. };
  184424. ActiveXControlComponent::ActiveXControlComponent()
  184425. : originalWndProc (0),
  184426. control (0),
  184427. mouseEventsAllowed (true)
  184428. {
  184429. ActiveXHelpers::activeXComps.add (this);
  184430. }
  184431. ActiveXControlComponent::~ActiveXControlComponent()
  184432. {
  184433. deleteControl();
  184434. ActiveXHelpers::activeXComps.removeValue (this);
  184435. }
  184436. void ActiveXControlComponent::paint (Graphics& g)
  184437. {
  184438. if (control == 0)
  184439. g.fillAll (Colours::lightgrey);
  184440. }
  184441. bool ActiveXControlComponent::createControl (const void* controlIID)
  184442. {
  184443. deleteControl();
  184444. ComponentPeer* const peer = getPeer();
  184445. // the component must have already been added to a real window when you call this!
  184446. jassert (dynamic_cast <Win32ComponentPeer*> (peer) != 0);
  184447. if (dynamic_cast <Win32ComponentPeer*> (peer) != 0)
  184448. {
  184449. const Point<int> pos (relativePositionToOtherComponent (getTopLevelComponent(), Point<int>()));
  184450. HWND hwnd = (HWND) peer->getNativeHandle();
  184451. ScopedPointer <ActiveXControlData> info (new ActiveXControlData (hwnd, this));
  184452. HRESULT hr;
  184453. if ((hr = OleCreate (*(const IID*) controlIID, IID_IOleObject, 1 /*OLERENDER_DRAW*/, 0,
  184454. info->clientSite, info->storage,
  184455. (void**) &(info->control))) == S_OK)
  184456. {
  184457. info->control->SetHostNames (L"Juce", 0);
  184458. if (OleSetContainedObject (info->control, TRUE) == S_OK)
  184459. {
  184460. RECT rect;
  184461. rect.left = pos.getX();
  184462. rect.top = pos.getY();
  184463. rect.right = pos.getX() + getWidth();
  184464. rect.bottom = pos.getY() + getHeight();
  184465. if (info->control->DoVerb (OLEIVERB_SHOW, 0, info->clientSite, 0, hwnd, &rect) == S_OK)
  184466. {
  184467. control = info.release();
  184468. setControlBounds (Rectangle<int> (pos.getX(), pos.getY(), getWidth(), getHeight()));
  184469. ((ActiveXControlData*) control)->controlHWND = ActiveXHelpers::getHWND (this);
  184470. if (((ActiveXControlData*) control)->controlHWND != 0)
  184471. {
  184472. originalWndProc = (void*) (pointer_sized_int) GetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC);
  184473. SetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC, (LONG_PTR) ActiveXControlData::activeXHookWndProc);
  184474. }
  184475. return true;
  184476. }
  184477. }
  184478. }
  184479. }
  184480. return false;
  184481. }
  184482. void ActiveXControlComponent::deleteControl()
  184483. {
  184484. ActiveXControlData* const info = (ActiveXControlData*) control;
  184485. if (info != 0)
  184486. {
  184487. delete info;
  184488. control = 0;
  184489. originalWndProc = 0;
  184490. }
  184491. }
  184492. void* ActiveXControlComponent::queryInterface (const void* iid) const
  184493. {
  184494. ActiveXControlData* const info = (ActiveXControlData*) control;
  184495. void* result = 0;
  184496. if (info != 0 && info->control != 0
  184497. && info->control->QueryInterface (*(const IID*) iid, &result) == S_OK)
  184498. return result;
  184499. return 0;
  184500. }
  184501. void ActiveXControlComponent::setControlBounds (const Rectangle<int>& newBounds) const
  184502. {
  184503. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  184504. if (hwnd != 0)
  184505. MoveWindow (hwnd, newBounds.getX(), newBounds.getY(), newBounds.getWidth(), newBounds.getHeight(), TRUE);
  184506. }
  184507. void ActiveXControlComponent::setControlVisible (const bool shouldBeVisible) const
  184508. {
  184509. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  184510. if (hwnd != 0)
  184511. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  184512. }
  184513. void ActiveXControlComponent::setMouseEventsAllowed (const bool eventsCanReachControl)
  184514. {
  184515. mouseEventsAllowed = eventsCanReachControl;
  184516. }
  184517. #endif
  184518. /*** End of inlined file: juce_win32_ActiveXComponent.cpp ***/
  184519. /*** Start of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  184520. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184521. // compiled on its own).
  184522. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  184523. using namespace QTOLibrary;
  184524. using namespace QTOControlLib;
  184525. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  184526. static bool isQTAvailable = false;
  184527. class QuickTimeMovieComponent::Pimpl
  184528. {
  184529. public:
  184530. Pimpl() : dataHandle (0)
  184531. {
  184532. }
  184533. ~Pimpl()
  184534. {
  184535. clearHandle();
  184536. }
  184537. void clearHandle()
  184538. {
  184539. if (dataHandle != 0)
  184540. {
  184541. DisposeHandle (dataHandle);
  184542. dataHandle = 0;
  184543. }
  184544. }
  184545. IQTControlPtr qtControl;
  184546. IQTMoviePtr qtMovie;
  184547. Handle dataHandle;
  184548. };
  184549. QuickTimeMovieComponent::QuickTimeMovieComponent()
  184550. : movieLoaded (false),
  184551. controllerVisible (true)
  184552. {
  184553. pimpl = new Pimpl();
  184554. setMouseEventsAllowed (false);
  184555. }
  184556. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  184557. {
  184558. closeMovie();
  184559. pimpl->qtControl = 0;
  184560. deleteControl();
  184561. pimpl = 0;
  184562. }
  184563. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  184564. {
  184565. if (! isQTAvailable)
  184566. isQTAvailable = (InitializeQTML (0) == noErr) && (EnterMovies() == noErr);
  184567. return isQTAvailable;
  184568. }
  184569. void QuickTimeMovieComponent::createControlIfNeeded()
  184570. {
  184571. if (isShowing() && ! isControlCreated())
  184572. {
  184573. const IID qtIID = __uuidof (QTControl);
  184574. if (createControl (&qtIID))
  184575. {
  184576. const IID qtInterfaceIID = __uuidof (IQTControl);
  184577. pimpl->qtControl = (IQTControl*) queryInterface (&qtInterfaceIID);
  184578. if (pimpl->qtControl != 0)
  184579. {
  184580. pimpl->qtControl->Release(); // it has one ref too many at this point
  184581. pimpl->qtControl->QuickTimeInitialize();
  184582. pimpl->qtControl->PutSizing (qtMovieFitsControl);
  184583. if (movieFile != File::nonexistent)
  184584. loadMovie (movieFile, controllerVisible);
  184585. }
  184586. }
  184587. }
  184588. }
  184589. bool QuickTimeMovieComponent::isControlCreated() const
  184590. {
  184591. return isControlOpen();
  184592. }
  184593. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  184594. const bool isControllerVisible)
  184595. {
  184596. const ScopedPointer<InputStream> movieStreamDeleter (movieStream);
  184597. movieFile = File::nonexistent;
  184598. movieLoaded = false;
  184599. pimpl->qtMovie = 0;
  184600. controllerVisible = isControllerVisible;
  184601. createControlIfNeeded();
  184602. if (isControlCreated())
  184603. {
  184604. if (pimpl->qtControl != 0)
  184605. {
  184606. pimpl->qtControl->Put_MovieHandle (0);
  184607. pimpl->clearHandle();
  184608. Movie movie;
  184609. if (juce_OpenQuickTimeMovieFromStream (movieStream, movie, pimpl->dataHandle))
  184610. {
  184611. pimpl->qtControl->Put_MovieHandle ((long) (pointer_sized_int) movie);
  184612. pimpl->qtMovie = pimpl->qtControl->GetMovie();
  184613. if (pimpl->qtMovie != 0)
  184614. pimpl->qtMovie->PutMovieControllerType (isControllerVisible ? qtMovieControllerTypeStandard
  184615. : qtMovieControllerTypeNone);
  184616. }
  184617. if (movie == 0)
  184618. pimpl->clearHandle();
  184619. }
  184620. movieLoaded = (pimpl->qtMovie != 0);
  184621. }
  184622. else
  184623. {
  184624. // You're trying to open a movie when the control hasn't yet been created, probably because
  184625. // you've not yet added this component to a Window and made the whole component hierarchy visible.
  184626. jassertfalse
  184627. }
  184628. return movieLoaded;
  184629. }
  184630. void QuickTimeMovieComponent::closeMovie()
  184631. {
  184632. stop();
  184633. movieFile = File::nonexistent;
  184634. movieLoaded = false;
  184635. pimpl->qtMovie = 0;
  184636. if (pimpl->qtControl != 0)
  184637. pimpl->qtControl->Put_MovieHandle (0);
  184638. pimpl->clearHandle();
  184639. }
  184640. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  184641. {
  184642. return movieFile;
  184643. }
  184644. bool QuickTimeMovieComponent::isMovieOpen() const
  184645. {
  184646. return movieLoaded;
  184647. }
  184648. double QuickTimeMovieComponent::getMovieDuration() const
  184649. {
  184650. if (pimpl->qtMovie != 0)
  184651. return pimpl->qtMovie->GetDuration() / (double) pimpl->qtMovie->GetTimeScale();
  184652. return 0.0;
  184653. }
  184654. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  184655. {
  184656. if (pimpl->qtMovie != 0)
  184657. {
  184658. struct QTRECT r = pimpl->qtMovie->GetNaturalRect();
  184659. width = r.right - r.left;
  184660. height = r.bottom - r.top;
  184661. }
  184662. else
  184663. {
  184664. width = height = 0;
  184665. }
  184666. }
  184667. void QuickTimeMovieComponent::play()
  184668. {
  184669. if (pimpl->qtMovie != 0)
  184670. pimpl->qtMovie->Play();
  184671. }
  184672. void QuickTimeMovieComponent::stop()
  184673. {
  184674. if (pimpl->qtMovie != 0)
  184675. pimpl->qtMovie->Stop();
  184676. }
  184677. bool QuickTimeMovieComponent::isPlaying() const
  184678. {
  184679. return pimpl->qtMovie != 0 && pimpl->qtMovie->GetRate() != 0.0f;
  184680. }
  184681. void QuickTimeMovieComponent::setPosition (const double seconds)
  184682. {
  184683. if (pimpl->qtMovie != 0)
  184684. pimpl->qtMovie->PutTime ((long) (seconds * pimpl->qtMovie->GetTimeScale()));
  184685. }
  184686. double QuickTimeMovieComponent::getPosition() const
  184687. {
  184688. if (pimpl->qtMovie != 0)
  184689. return pimpl->qtMovie->GetTime() / (double) pimpl->qtMovie->GetTimeScale();
  184690. return 0.0;
  184691. }
  184692. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  184693. {
  184694. if (pimpl->qtMovie != 0)
  184695. pimpl->qtMovie->PutRate (newSpeed);
  184696. }
  184697. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  184698. {
  184699. if (pimpl->qtMovie != 0)
  184700. {
  184701. pimpl->qtMovie->PutAudioVolume (newVolume);
  184702. pimpl->qtMovie->PutAudioMute (newVolume <= 0);
  184703. }
  184704. }
  184705. float QuickTimeMovieComponent::getMovieVolume() const
  184706. {
  184707. if (pimpl->qtMovie != 0)
  184708. return pimpl->qtMovie->GetAudioVolume();
  184709. return 0.0f;
  184710. }
  184711. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  184712. {
  184713. if (pimpl->qtMovie != 0)
  184714. pimpl->qtMovie->PutLoop (shouldLoop);
  184715. }
  184716. bool QuickTimeMovieComponent::isLooping() const
  184717. {
  184718. return pimpl->qtMovie != 0 && pimpl->qtMovie->GetLoop();
  184719. }
  184720. bool QuickTimeMovieComponent::isControllerVisible() const
  184721. {
  184722. return controllerVisible;
  184723. }
  184724. void QuickTimeMovieComponent::parentHierarchyChanged()
  184725. {
  184726. createControlIfNeeded();
  184727. QTCompBaseClass::parentHierarchyChanged();
  184728. }
  184729. void QuickTimeMovieComponent::visibilityChanged()
  184730. {
  184731. createControlIfNeeded();
  184732. QTCompBaseClass::visibilityChanged();
  184733. }
  184734. void QuickTimeMovieComponent::paint (Graphics& g)
  184735. {
  184736. if (! isControlCreated())
  184737. g.fillAll (Colours::black);
  184738. }
  184739. static Handle createHandleDataRef (Handle dataHandle, const char* fileName)
  184740. {
  184741. Handle dataRef = 0;
  184742. OSStatus err = PtrToHand (&dataHandle, &dataRef, sizeof (Handle));
  184743. if (err == noErr)
  184744. {
  184745. Str255 suffix;
  184746. CharacterFunctions::copy ((char*) suffix, fileName, 128);
  184747. StringPtr name = suffix;
  184748. err = PtrAndHand (name, dataRef, name[0] + 1);
  184749. if (err == noErr)
  184750. {
  184751. long atoms[3];
  184752. atoms[0] = EndianU32_NtoB (3 * sizeof (long));
  184753. atoms[1] = EndianU32_NtoB (kDataRefExtensionMacOSFileType);
  184754. atoms[2] = EndianU32_NtoB (MovieFileType);
  184755. err = PtrAndHand (atoms, dataRef, 3 * sizeof (long));
  184756. if (err == noErr)
  184757. return dataRef;
  184758. }
  184759. DisposeHandle (dataRef);
  184760. }
  184761. return 0;
  184762. }
  184763. static CFStringRef juceStringToCFString (const String& s)
  184764. {
  184765. const int len = s.length();
  184766. const juce_wchar* const t = (const juce_wchar*) s;
  184767. HeapBlock <UniChar> temp (len + 2);
  184768. for (int i = 0; i <= len; ++i)
  184769. temp[i] = t[i];
  184770. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  184771. }
  184772. static bool openMovie (QTNewMoviePropertyElement* props, int prop, Movie& movie)
  184773. {
  184774. Boolean trueBool = true;
  184775. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  184776. props[prop].propID = kQTMovieInstantiationPropertyID_DontResolveDataRefs;
  184777. props[prop].propValueSize = sizeof (trueBool);
  184778. props[prop].propValueAddress = &trueBool;
  184779. ++prop;
  184780. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  184781. props[prop].propID = kQTMovieInstantiationPropertyID_AsyncOK;
  184782. props[prop].propValueSize = sizeof (trueBool);
  184783. props[prop].propValueAddress = &trueBool;
  184784. ++prop;
  184785. Boolean isActive = true;
  184786. props[prop].propClass = kQTPropertyClass_NewMovieProperty;
  184787. props[prop].propID = kQTNewMoviePropertyID_Active;
  184788. props[prop].propValueSize = sizeof (isActive);
  184789. props[prop].propValueAddress = &isActive;
  184790. ++prop;
  184791. MacSetPort (0);
  184792. jassert (prop <= 5);
  184793. OSStatus err = NewMovieFromProperties (prop, props, 0, 0, &movie);
  184794. return err == noErr;
  184795. }
  184796. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle)
  184797. {
  184798. if (input == 0)
  184799. return false;
  184800. dataHandle = 0;
  184801. bool ok = false;
  184802. QTNewMoviePropertyElement props[5];
  184803. zeromem (props, sizeof (props));
  184804. int prop = 0;
  184805. DataReferenceRecord dr;
  184806. props[prop].propClass = kQTPropertyClass_DataLocation;
  184807. props[prop].propID = kQTDataLocationPropertyID_DataReference;
  184808. props[prop].propValueSize = sizeof (dr);
  184809. props[prop].propValueAddress = (void*) &dr;
  184810. ++prop;
  184811. FileInputStream* const fin = dynamic_cast <FileInputStream*> (input);
  184812. if (fin != 0)
  184813. {
  184814. CFStringRef filePath = juceStringToCFString (fin->getFile().getFullPathName());
  184815. QTNewDataReferenceFromFullPathCFString (filePath, (QTPathStyle) kQTNativeDefaultPathStyle, 0,
  184816. &dr.dataRef, &dr.dataRefType);
  184817. ok = openMovie (props, prop, movie);
  184818. DisposeHandle (dr.dataRef);
  184819. CFRelease (filePath);
  184820. }
  184821. else
  184822. {
  184823. // sanity-check because this currently needs to load the whole stream into memory..
  184824. jassert (input->getTotalLength() < 50 * 1024 * 1024);
  184825. dataHandle = NewHandle ((Size) input->getTotalLength());
  184826. HLock (dataHandle);
  184827. // read the entire stream into memory - this is a pain, but can't get it to work
  184828. // properly using a custom callback to supply the data.
  184829. input->read (*dataHandle, (int) input->getTotalLength());
  184830. HUnlock (dataHandle);
  184831. // different types to get QT to try. (We should really be a bit smarter here by
  184832. // working out in advance which one the stream contains, rather than just trying
  184833. // each one)
  184834. const char* const suffixesToTry[] = { "\04.mov", "\04.mp3",
  184835. "\04.avi", "\04.m4a" };
  184836. for (int i = 0; i < numElementsInArray (suffixesToTry) && ! ok; ++i)
  184837. {
  184838. dr.dataRef = createHandleDataRef (dataHandle, suffixesToTry [i]);
  184839. dr.dataRefType = HandleDataHandlerSubType;
  184840. ok = openMovie (props, prop, movie);
  184841. DisposeHandle (dr.dataRef);
  184842. }
  184843. }
  184844. return ok;
  184845. }
  184846. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  184847. const bool isControllerVisible)
  184848. {
  184849. const bool ok = loadMovie (static_cast <InputStream*> (movieFile_.createInputStream()), isControllerVisible);
  184850. movieFile = movieFile_;
  184851. return ok;
  184852. }
  184853. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  184854. const bool isControllerVisible)
  184855. {
  184856. return loadMovie (static_cast <InputStream*> (movieURL.createInputStream (false)), isControllerVisible);
  184857. }
  184858. void QuickTimeMovieComponent::goToStart()
  184859. {
  184860. setPosition (0.0);
  184861. }
  184862. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  184863. const RectanglePlacement& placement)
  184864. {
  184865. int normalWidth, normalHeight;
  184866. getMovieNormalSize (normalWidth, normalHeight);
  184867. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  184868. {
  184869. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  184870. placement.applyTo (x, y, w, h,
  184871. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  184872. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  184873. if (w > 0 && h > 0)
  184874. {
  184875. setBounds (roundToInt (x), roundToInt (y),
  184876. roundToInt (w), roundToInt (h));
  184877. }
  184878. }
  184879. else
  184880. {
  184881. setBounds (spaceToFitWithin);
  184882. }
  184883. }
  184884. #endif
  184885. /*** End of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  184886. /*** Start of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  184887. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184888. // compiled on its own).
  184889. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  184890. class WebBrowserComponentInternal : public ActiveXControlComponent
  184891. {
  184892. public:
  184893. WebBrowserComponentInternal()
  184894. : browser (0),
  184895. connectionPoint (0),
  184896. adviseCookie (0)
  184897. {
  184898. }
  184899. ~WebBrowserComponentInternal()
  184900. {
  184901. if (connectionPoint != 0)
  184902. connectionPoint->Unadvise (adviseCookie);
  184903. if (browser != 0)
  184904. browser->Release();
  184905. }
  184906. void createBrowser()
  184907. {
  184908. createControl (&CLSID_WebBrowser);
  184909. browser = (IWebBrowser2*) queryInterface (&IID_IWebBrowser2);
  184910. IConnectionPointContainer* connectionPointContainer = (IConnectionPointContainer*) queryInterface (&IID_IConnectionPointContainer);
  184911. if (connectionPointContainer != 0)
  184912. {
  184913. connectionPointContainer->FindConnectionPoint (DIID_DWebBrowserEvents2,
  184914. &connectionPoint);
  184915. if (connectionPoint != 0)
  184916. {
  184917. WebBrowserComponent* const owner = dynamic_cast <WebBrowserComponent*> (getParentComponent());
  184918. jassert (owner != 0);
  184919. EventHandler* handler = new EventHandler (owner);
  184920. connectionPoint->Advise (handler, &adviseCookie);
  184921. }
  184922. }
  184923. }
  184924. void goToURL (const String& url,
  184925. const StringArray* headers,
  184926. const MemoryBlock* postData)
  184927. {
  184928. if (browser != 0)
  184929. {
  184930. LPSAFEARRAY sa = 0;
  184931. VARIANT flags, frame, postDataVar, headersVar; // (_variant_t isn't available in all compilers)
  184932. VariantInit (&flags);
  184933. VariantInit (&frame);
  184934. VariantInit (&postDataVar);
  184935. VariantInit (&headersVar);
  184936. if (headers != 0)
  184937. {
  184938. V_VT (&headersVar) = VT_BSTR;
  184939. V_BSTR (&headersVar) = SysAllocString ((const tchar*) headers->joinIntoString ("\r\n"));
  184940. }
  184941. if (postData != 0 && postData->getSize() > 0)
  184942. {
  184943. LPSAFEARRAY sa = SafeArrayCreateVector (VT_UI1, 0, postData->getSize());
  184944. if (sa != 0)
  184945. {
  184946. void* data = 0;
  184947. SafeArrayAccessData (sa, &data);
  184948. jassert (data != 0);
  184949. if (data != 0)
  184950. {
  184951. postData->copyTo (data, 0, postData->getSize());
  184952. SafeArrayUnaccessData (sa);
  184953. VARIANT postDataVar2;
  184954. VariantInit (&postDataVar2);
  184955. V_VT (&postDataVar2) = VT_ARRAY | VT_UI1;
  184956. V_ARRAY (&postDataVar2) = sa;
  184957. postDataVar = postDataVar2;
  184958. }
  184959. }
  184960. }
  184961. browser->Navigate ((BSTR) (const OLECHAR*) url,
  184962. &flags, &frame,
  184963. &postDataVar, &headersVar);
  184964. if (sa != 0)
  184965. SafeArrayDestroy (sa);
  184966. VariantClear (&flags);
  184967. VariantClear (&frame);
  184968. VariantClear (&postDataVar);
  184969. VariantClear (&headersVar);
  184970. }
  184971. }
  184972. IWebBrowser2* browser;
  184973. juce_UseDebuggingNewOperator
  184974. private:
  184975. IConnectionPoint* connectionPoint;
  184976. DWORD adviseCookie;
  184977. class EventHandler : public IDispatch,
  184978. public ComponentMovementWatcher
  184979. {
  184980. public:
  184981. EventHandler (WebBrowserComponent* owner_)
  184982. : ComponentMovementWatcher (owner_),
  184983. owner (owner_),
  184984. refCount (0)
  184985. {
  184986. }
  184987. ~EventHandler()
  184988. {
  184989. }
  184990. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184991. {
  184992. if (id == IID_IUnknown || id == IID_IDispatch || id == DIID_DWebBrowserEvents2)
  184993. {
  184994. AddRef();
  184995. *result = this;
  184996. return S_OK;
  184997. }
  184998. *result = 0;
  184999. return E_NOINTERFACE;
  185000. }
  185001. ULONG __stdcall AddRef() { return ++refCount; }
  185002. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  185003. HRESULT __stdcall GetTypeInfoCount (UINT __RPC_FAR*) { return E_NOTIMPL; }
  185004. HRESULT __stdcall GetTypeInfo (UINT, LCID, ITypeInfo __RPC_FAR *__RPC_FAR*) { return E_NOTIMPL; }
  185005. HRESULT __stdcall GetIDsOfNames (REFIID, LPOLESTR __RPC_FAR*, UINT, LCID, DISPID __RPC_FAR*) { return E_NOTIMPL; }
  185006. HRESULT __stdcall Invoke (DISPID dispIdMember, REFIID /*riid*/, LCID /*lcid*/,
  185007. WORD /*wFlags*/, DISPPARAMS __RPC_FAR* pDispParams,
  185008. VARIANT __RPC_FAR* /*pVarResult*/, EXCEPINFO __RPC_FAR* /*pExcepInfo*/,
  185009. UINT __RPC_FAR* /*puArgErr*/)
  185010. {
  185011. switch (dispIdMember)
  185012. {
  185013. case DISPID_BEFORENAVIGATE2:
  185014. {
  185015. VARIANT* const vurl = pDispParams->rgvarg[5].pvarVal;
  185016. String url;
  185017. if ((vurl->vt & VT_BYREF) != 0)
  185018. url = *vurl->pbstrVal;
  185019. else
  185020. url = vurl->bstrVal;
  185021. *pDispParams->rgvarg->pboolVal
  185022. = owner->pageAboutToLoad (url) ? VARIANT_FALSE
  185023. : VARIANT_TRUE;
  185024. return S_OK;
  185025. }
  185026. default:
  185027. break;
  185028. }
  185029. return E_NOTIMPL;
  185030. }
  185031. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/) {}
  185032. void componentPeerChanged() {}
  185033. void componentVisibilityChanged (Component&)
  185034. {
  185035. owner->visibilityChanged();
  185036. }
  185037. juce_UseDebuggingNewOperator
  185038. private:
  185039. WebBrowserComponent* const owner;
  185040. int refCount;
  185041. EventHandler (const EventHandler&);
  185042. EventHandler& operator= (const EventHandler&);
  185043. };
  185044. };
  185045. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  185046. : browser (0),
  185047. blankPageShown (false),
  185048. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  185049. {
  185050. setOpaque (true);
  185051. addAndMakeVisible (browser = new WebBrowserComponentInternal());
  185052. }
  185053. WebBrowserComponent::~WebBrowserComponent()
  185054. {
  185055. delete browser;
  185056. }
  185057. void WebBrowserComponent::goToURL (const String& url,
  185058. const StringArray* headers,
  185059. const MemoryBlock* postData)
  185060. {
  185061. lastURL = url;
  185062. lastHeaders.clear();
  185063. if (headers != 0)
  185064. lastHeaders = *headers;
  185065. lastPostData.setSize (0);
  185066. if (postData != 0)
  185067. lastPostData = *postData;
  185068. blankPageShown = false;
  185069. browser->goToURL (url, headers, postData);
  185070. }
  185071. void WebBrowserComponent::stop()
  185072. {
  185073. if (browser->browser != 0)
  185074. browser->browser->Stop();
  185075. }
  185076. void WebBrowserComponent::goBack()
  185077. {
  185078. lastURL = String::empty;
  185079. blankPageShown = false;
  185080. if (browser->browser != 0)
  185081. browser->browser->GoBack();
  185082. }
  185083. void WebBrowserComponent::goForward()
  185084. {
  185085. lastURL = String::empty;
  185086. if (browser->browser != 0)
  185087. browser->browser->GoForward();
  185088. }
  185089. void WebBrowserComponent::refresh()
  185090. {
  185091. if (browser->browser != 0)
  185092. browser->browser->Refresh();
  185093. }
  185094. void WebBrowserComponent::paint (Graphics& g)
  185095. {
  185096. if (browser->browser == 0)
  185097. g.fillAll (Colours::white);
  185098. }
  185099. void WebBrowserComponent::checkWindowAssociation()
  185100. {
  185101. if (isShowing())
  185102. {
  185103. if (browser->browser == 0 && getPeer() != 0)
  185104. {
  185105. browser->createBrowser();
  185106. reloadLastURL();
  185107. }
  185108. else
  185109. {
  185110. if (blankPageShown)
  185111. goBack();
  185112. }
  185113. }
  185114. else
  185115. {
  185116. if (browser != 0 && unloadPageWhenBrowserIsHidden && ! blankPageShown)
  185117. {
  185118. // when the component becomes invisible, some stuff like flash
  185119. // carries on playing audio, so we need to force it onto a blank
  185120. // page to avoid this..
  185121. blankPageShown = true;
  185122. browser->goToURL ("about:blank", 0, 0);
  185123. }
  185124. }
  185125. }
  185126. void WebBrowserComponent::reloadLastURL()
  185127. {
  185128. if (lastURL.isNotEmpty())
  185129. {
  185130. goToURL (lastURL, &lastHeaders, &lastPostData);
  185131. lastURL = String::empty;
  185132. }
  185133. }
  185134. void WebBrowserComponent::parentHierarchyChanged()
  185135. {
  185136. checkWindowAssociation();
  185137. }
  185138. void WebBrowserComponent::resized()
  185139. {
  185140. browser->setSize (getWidth(), getHeight());
  185141. }
  185142. void WebBrowserComponent::visibilityChanged()
  185143. {
  185144. checkWindowAssociation();
  185145. }
  185146. bool WebBrowserComponent::pageAboutToLoad (const String&)
  185147. {
  185148. return true;
  185149. }
  185150. #endif
  185151. /*** End of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  185152. /*** Start of inlined file: juce_win32_OpenGLComponent.cpp ***/
  185153. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185154. // compiled on its own).
  185155. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  185156. #define WGL_EXT_FUNCTION_INIT(extType, extFunc) \
  185157. ((extFunc = (extType) wglGetProcAddress (#extFunc)) != 0)
  185158. typedef const char* (WINAPI* PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
  185159. typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
  185160. typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int* piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
  185161. typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval);
  185162. typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC) (void);
  185163. #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
  185164. #define WGL_DRAW_TO_WINDOW_ARB 0x2001
  185165. #define WGL_ACCELERATION_ARB 0x2003
  185166. #define WGL_SWAP_METHOD_ARB 0x2007
  185167. #define WGL_SUPPORT_OPENGL_ARB 0x2010
  185168. #define WGL_PIXEL_TYPE_ARB 0x2013
  185169. #define WGL_DOUBLE_BUFFER_ARB 0x2011
  185170. #define WGL_COLOR_BITS_ARB 0x2014
  185171. #define WGL_RED_BITS_ARB 0x2015
  185172. #define WGL_GREEN_BITS_ARB 0x2017
  185173. #define WGL_BLUE_BITS_ARB 0x2019
  185174. #define WGL_ALPHA_BITS_ARB 0x201B
  185175. #define WGL_DEPTH_BITS_ARB 0x2022
  185176. #define WGL_STENCIL_BITS_ARB 0x2023
  185177. #define WGL_FULL_ACCELERATION_ARB 0x2027
  185178. #define WGL_ACCUM_RED_BITS_ARB 0x201E
  185179. #define WGL_ACCUM_GREEN_BITS_ARB 0x201F
  185180. #define WGL_ACCUM_BLUE_BITS_ARB 0x2020
  185181. #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
  185182. #define WGL_STEREO_ARB 0x2012
  185183. #define WGL_SAMPLE_BUFFERS_ARB 0x2041
  185184. #define WGL_SAMPLES_ARB 0x2042
  185185. #define WGL_TYPE_RGBA_ARB 0x202B
  185186. static void getWglExtensions (HDC dc, StringArray& result) throw()
  185187. {
  185188. PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = 0;
  185189. if (WGL_EXT_FUNCTION_INIT (PFNWGLGETEXTENSIONSSTRINGARBPROC, wglGetExtensionsStringARB))
  185190. result.addTokens (String (wglGetExtensionsStringARB (dc)), false);
  185191. else
  185192. jassertfalse // If this fails, it may be because you didn't activate the openGL context
  185193. }
  185194. class WindowedGLContext : public OpenGLContext
  185195. {
  185196. public:
  185197. WindowedGLContext (Component* const component_,
  185198. HGLRC contextToShareWith,
  185199. const OpenGLPixelFormat& pixelFormat)
  185200. : renderContext (0),
  185201. nativeWindow (0),
  185202. dc (0),
  185203. component (component_)
  185204. {
  185205. jassert (component != 0);
  185206. createNativeWindow();
  185207. // Use a default pixel format that should be supported everywhere
  185208. PIXELFORMATDESCRIPTOR pfd;
  185209. zerostruct (pfd);
  185210. pfd.nSize = sizeof (pfd);
  185211. pfd.nVersion = 1;
  185212. pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
  185213. pfd.iPixelType = PFD_TYPE_RGBA;
  185214. pfd.cColorBits = 24;
  185215. pfd.cDepthBits = 16;
  185216. const int format = ChoosePixelFormat (dc, &pfd);
  185217. if (format != 0)
  185218. SetPixelFormat (dc, format, &pfd);
  185219. renderContext = wglCreateContext (dc);
  185220. makeActive();
  185221. setPixelFormat (pixelFormat);
  185222. if (contextToShareWith != 0 && renderContext != 0)
  185223. wglShareLists (contextToShareWith, renderContext);
  185224. }
  185225. ~WindowedGLContext()
  185226. {
  185227. makeInactive();
  185228. wglDeleteContext (renderContext);
  185229. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185230. delete nativeWindow;
  185231. }
  185232. bool makeActive() const throw()
  185233. {
  185234. jassert (renderContext != 0);
  185235. return wglMakeCurrent (dc, renderContext) != 0;
  185236. }
  185237. bool makeInactive() const throw()
  185238. {
  185239. return (! isActive()) || (wglMakeCurrent (0, 0) != 0);
  185240. }
  185241. bool isActive() const throw()
  185242. {
  185243. return wglGetCurrentContext() == renderContext;
  185244. }
  185245. const OpenGLPixelFormat getPixelFormat() const
  185246. {
  185247. OpenGLPixelFormat pf;
  185248. makeActive();
  185249. StringArray availableExtensions;
  185250. getWglExtensions (dc, availableExtensions);
  185251. fillInPixelFormatDetails (GetPixelFormat (dc), pf, availableExtensions);
  185252. return pf;
  185253. }
  185254. void* getRawContext() const throw()
  185255. {
  185256. return renderContext;
  185257. }
  185258. bool setPixelFormat (const OpenGLPixelFormat& pixelFormat)
  185259. {
  185260. makeActive();
  185261. PIXELFORMATDESCRIPTOR pfd;
  185262. zerostruct (pfd);
  185263. pfd.nSize = sizeof (pfd);
  185264. pfd.nVersion = 1;
  185265. pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
  185266. pfd.iPixelType = PFD_TYPE_RGBA;
  185267. pfd.iLayerType = PFD_MAIN_PLANE;
  185268. pfd.cColorBits = (BYTE) (pixelFormat.redBits + pixelFormat.greenBits + pixelFormat.blueBits);
  185269. pfd.cRedBits = (BYTE) pixelFormat.redBits;
  185270. pfd.cGreenBits = (BYTE) pixelFormat.greenBits;
  185271. pfd.cBlueBits = (BYTE) pixelFormat.blueBits;
  185272. pfd.cAlphaBits = (BYTE) pixelFormat.alphaBits;
  185273. pfd.cDepthBits = (BYTE) pixelFormat.depthBufferBits;
  185274. pfd.cStencilBits = (BYTE) pixelFormat.stencilBufferBits;
  185275. pfd.cAccumBits = (BYTE) (pixelFormat.accumulationBufferRedBits + pixelFormat.accumulationBufferGreenBits
  185276. + pixelFormat.accumulationBufferBlueBits + pixelFormat.accumulationBufferAlphaBits);
  185277. pfd.cAccumRedBits = (BYTE) pixelFormat.accumulationBufferRedBits;
  185278. pfd.cAccumGreenBits = (BYTE) pixelFormat.accumulationBufferGreenBits;
  185279. pfd.cAccumBlueBits = (BYTE) pixelFormat.accumulationBufferBlueBits;
  185280. pfd.cAccumAlphaBits = (BYTE) pixelFormat.accumulationBufferAlphaBits;
  185281. int format = 0;
  185282. PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = 0;
  185283. StringArray availableExtensions;
  185284. getWglExtensions (dc, availableExtensions);
  185285. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  185286. && WGL_EXT_FUNCTION_INIT (PFNWGLCHOOSEPIXELFORMATARBPROC, wglChoosePixelFormatARB))
  185287. {
  185288. int attributes[64];
  185289. int n = 0;
  185290. attributes[n++] = WGL_DRAW_TO_WINDOW_ARB;
  185291. attributes[n++] = GL_TRUE;
  185292. attributes[n++] = WGL_SUPPORT_OPENGL_ARB;
  185293. attributes[n++] = GL_TRUE;
  185294. attributes[n++] = WGL_ACCELERATION_ARB;
  185295. attributes[n++] = WGL_FULL_ACCELERATION_ARB;
  185296. attributes[n++] = WGL_DOUBLE_BUFFER_ARB;
  185297. attributes[n++] = GL_TRUE;
  185298. attributes[n++] = WGL_PIXEL_TYPE_ARB;
  185299. attributes[n++] = WGL_TYPE_RGBA_ARB;
  185300. attributes[n++] = WGL_COLOR_BITS_ARB;
  185301. attributes[n++] = pfd.cColorBits;
  185302. attributes[n++] = WGL_RED_BITS_ARB;
  185303. attributes[n++] = pixelFormat.redBits;
  185304. attributes[n++] = WGL_GREEN_BITS_ARB;
  185305. attributes[n++] = pixelFormat.greenBits;
  185306. attributes[n++] = WGL_BLUE_BITS_ARB;
  185307. attributes[n++] = pixelFormat.blueBits;
  185308. attributes[n++] = WGL_ALPHA_BITS_ARB;
  185309. attributes[n++] = pixelFormat.alphaBits;
  185310. attributes[n++] = WGL_DEPTH_BITS_ARB;
  185311. attributes[n++] = pixelFormat.depthBufferBits;
  185312. if (pixelFormat.stencilBufferBits > 0)
  185313. {
  185314. attributes[n++] = WGL_STENCIL_BITS_ARB;
  185315. attributes[n++] = pixelFormat.stencilBufferBits;
  185316. }
  185317. attributes[n++] = WGL_ACCUM_RED_BITS_ARB;
  185318. attributes[n++] = pixelFormat.accumulationBufferRedBits;
  185319. attributes[n++] = WGL_ACCUM_GREEN_BITS_ARB;
  185320. attributes[n++] = pixelFormat.accumulationBufferGreenBits;
  185321. attributes[n++] = WGL_ACCUM_BLUE_BITS_ARB;
  185322. attributes[n++] = pixelFormat.accumulationBufferBlueBits;
  185323. attributes[n++] = WGL_ACCUM_ALPHA_BITS_ARB;
  185324. attributes[n++] = pixelFormat.accumulationBufferAlphaBits;
  185325. if (availableExtensions.contains ("WGL_ARB_multisample")
  185326. && pixelFormat.fullSceneAntiAliasingNumSamples > 0)
  185327. {
  185328. attributes[n++] = WGL_SAMPLE_BUFFERS_ARB;
  185329. attributes[n++] = 1;
  185330. attributes[n++] = WGL_SAMPLES_ARB;
  185331. attributes[n++] = pixelFormat.fullSceneAntiAliasingNumSamples;
  185332. }
  185333. attributes[n++] = 0;
  185334. UINT formatsCount;
  185335. const BOOL ok = wglChoosePixelFormatARB (dc, attributes, 0, 1, &format, &formatsCount);
  185336. (void) ok;
  185337. jassert (ok);
  185338. }
  185339. else
  185340. {
  185341. format = ChoosePixelFormat (dc, &pfd);
  185342. }
  185343. if (format != 0)
  185344. {
  185345. makeInactive();
  185346. // win32 can't change the pixel format of a window, so need to delete the
  185347. // old one and create a new one..
  185348. jassert (nativeWindow != 0);
  185349. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185350. delete nativeWindow;
  185351. createNativeWindow();
  185352. if (SetPixelFormat (dc, format, &pfd))
  185353. {
  185354. wglDeleteContext (renderContext);
  185355. renderContext = wglCreateContext (dc);
  185356. jassert (renderContext != 0);
  185357. return renderContext != 0;
  185358. }
  185359. }
  185360. return false;
  185361. }
  185362. void updateWindowPosition (int x, int y, int w, int h, int)
  185363. {
  185364. SetWindowPos ((HWND) nativeWindow->getNativeHandle(), 0,
  185365. x, y, w, h,
  185366. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  185367. }
  185368. void repaint()
  185369. {
  185370. const Rectangle<int> bounds (nativeWindow->getBounds());
  185371. nativeWindow->repaint (0, 0, bounds.getWidth(), bounds.getHeight());
  185372. }
  185373. void swapBuffers()
  185374. {
  185375. SwapBuffers (dc);
  185376. }
  185377. bool setSwapInterval (const int numFramesPerSwap)
  185378. {
  185379. makeActive();
  185380. StringArray availableExtensions;
  185381. getWglExtensions (dc, availableExtensions);
  185382. PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = 0;
  185383. return availableExtensions.contains ("WGL_EXT_swap_control")
  185384. && WGL_EXT_FUNCTION_INIT (PFNWGLSWAPINTERVALEXTPROC, wglSwapIntervalEXT)
  185385. && wglSwapIntervalEXT (numFramesPerSwap) != FALSE;
  185386. }
  185387. int getSwapInterval() const
  185388. {
  185389. makeActive();
  185390. StringArray availableExtensions;
  185391. getWglExtensions (dc, availableExtensions);
  185392. PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT = 0;
  185393. if (availableExtensions.contains ("WGL_EXT_swap_control")
  185394. && WGL_EXT_FUNCTION_INIT (PFNWGLGETSWAPINTERVALEXTPROC, wglGetSwapIntervalEXT))
  185395. return wglGetSwapIntervalEXT();
  185396. return 0;
  185397. }
  185398. void findAlternativeOpenGLPixelFormats (OwnedArray <OpenGLPixelFormat>& results)
  185399. {
  185400. jassert (isActive());
  185401. StringArray availableExtensions;
  185402. getWglExtensions (dc, availableExtensions);
  185403. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  185404. int numTypes = 0;
  185405. if (availableExtensions.contains("WGL_ARB_pixel_format")
  185406. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  185407. {
  185408. int attributes = WGL_NUMBER_PIXEL_FORMATS_ARB;
  185409. if (! wglGetPixelFormatAttribivARB (dc, 1, 0, 1, &attributes, &numTypes))
  185410. jassertfalse
  185411. }
  185412. else
  185413. {
  185414. numTypes = DescribePixelFormat (dc, 0, 0, 0);
  185415. }
  185416. OpenGLPixelFormat pf;
  185417. for (int i = 0; i < numTypes; ++i)
  185418. {
  185419. if (fillInPixelFormatDetails (i + 1, pf, availableExtensions))
  185420. {
  185421. bool alreadyListed = false;
  185422. for (int j = results.size(); --j >= 0;)
  185423. if (pf == *results.getUnchecked(j))
  185424. alreadyListed = true;
  185425. if (! alreadyListed)
  185426. results.add (new OpenGLPixelFormat (pf));
  185427. }
  185428. }
  185429. }
  185430. void* getNativeWindowHandle() const
  185431. {
  185432. return nativeWindow != 0 ? nativeWindow->getNativeHandle() : 0;
  185433. }
  185434. juce_UseDebuggingNewOperator
  185435. HGLRC renderContext;
  185436. private:
  185437. Win32ComponentPeer* nativeWindow;
  185438. Component* const component;
  185439. HDC dc;
  185440. void createNativeWindow()
  185441. {
  185442. nativeWindow = new Win32ComponentPeer (component, 0);
  185443. nativeWindow->dontRepaint = true;
  185444. nativeWindow->setVisible (true);
  185445. HWND hwnd = (HWND) nativeWindow->getNativeHandle();
  185446. Win32ComponentPeer* const peer = dynamic_cast <Win32ComponentPeer*> (component->getTopLevelComponent()->getPeer());
  185447. if (peer != 0)
  185448. {
  185449. SetParent (hwnd, (HWND) peer->getNativeHandle());
  185450. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_CHILD, true);
  185451. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_POPUP, false);
  185452. }
  185453. dc = GetDC (hwnd);
  185454. }
  185455. bool fillInPixelFormatDetails (const int pixelFormatIndex,
  185456. OpenGLPixelFormat& result,
  185457. const StringArray& availableExtensions) const throw()
  185458. {
  185459. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  185460. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  185461. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  185462. {
  185463. int attributes[32];
  185464. int numAttributes = 0;
  185465. attributes[numAttributes++] = WGL_DRAW_TO_WINDOW_ARB;
  185466. attributes[numAttributes++] = WGL_SUPPORT_OPENGL_ARB;
  185467. attributes[numAttributes++] = WGL_ACCELERATION_ARB;
  185468. attributes[numAttributes++] = WGL_DOUBLE_BUFFER_ARB;
  185469. attributes[numAttributes++] = WGL_PIXEL_TYPE_ARB;
  185470. attributes[numAttributes++] = WGL_RED_BITS_ARB;
  185471. attributes[numAttributes++] = WGL_GREEN_BITS_ARB;
  185472. attributes[numAttributes++] = WGL_BLUE_BITS_ARB;
  185473. attributes[numAttributes++] = WGL_ALPHA_BITS_ARB;
  185474. attributes[numAttributes++] = WGL_DEPTH_BITS_ARB;
  185475. attributes[numAttributes++] = WGL_STENCIL_BITS_ARB;
  185476. attributes[numAttributes++] = WGL_ACCUM_RED_BITS_ARB;
  185477. attributes[numAttributes++] = WGL_ACCUM_GREEN_BITS_ARB;
  185478. attributes[numAttributes++] = WGL_ACCUM_BLUE_BITS_ARB;
  185479. attributes[numAttributes++] = WGL_ACCUM_ALPHA_BITS_ARB;
  185480. if (availableExtensions.contains ("WGL_ARB_multisample"))
  185481. attributes[numAttributes++] = WGL_SAMPLES_ARB;
  185482. int values[32];
  185483. zeromem (values, sizeof (values));
  185484. if (wglGetPixelFormatAttribivARB (dc, pixelFormatIndex, 0, numAttributes, attributes, values))
  185485. {
  185486. int n = 0;
  185487. bool isValidFormat = (values[n++] == GL_TRUE); // WGL_DRAW_TO_WINDOW_ARB
  185488. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_SUPPORT_OPENGL_ARB
  185489. isValidFormat = (values[n++] == WGL_FULL_ACCELERATION_ARB) && isValidFormat; // WGL_ACCELERATION_ARB
  185490. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_DOUBLE_BUFFER_ARB:
  185491. isValidFormat = (values[n++] == WGL_TYPE_RGBA_ARB) && isValidFormat; // WGL_PIXEL_TYPE_ARB
  185492. result.redBits = values[n++]; // WGL_RED_BITS_ARB
  185493. result.greenBits = values[n++]; // WGL_GREEN_BITS_ARB
  185494. result.blueBits = values[n++]; // WGL_BLUE_BITS_ARB
  185495. result.alphaBits = values[n++]; // WGL_ALPHA_BITS_ARB
  185496. result.depthBufferBits = values[n++]; // WGL_DEPTH_BITS_ARB
  185497. result.stencilBufferBits = values[n++]; // WGL_STENCIL_BITS_ARB
  185498. result.accumulationBufferRedBits = values[n++]; // WGL_ACCUM_RED_BITS_ARB
  185499. result.accumulationBufferGreenBits = values[n++]; // WGL_ACCUM_GREEN_BITS_ARB
  185500. result.accumulationBufferBlueBits = values[n++]; // WGL_ACCUM_BLUE_BITS_ARB
  185501. result.accumulationBufferAlphaBits = values[n++]; // WGL_ACCUM_ALPHA_BITS_ARB
  185502. result.fullSceneAntiAliasingNumSamples = (uint8) values[n++]; // WGL_SAMPLES_ARB
  185503. return isValidFormat;
  185504. }
  185505. else
  185506. {
  185507. jassertfalse
  185508. }
  185509. }
  185510. else
  185511. {
  185512. PIXELFORMATDESCRIPTOR pfd;
  185513. if (DescribePixelFormat (dc, pixelFormatIndex, sizeof (pfd), &pfd))
  185514. {
  185515. result.redBits = pfd.cRedBits;
  185516. result.greenBits = pfd.cGreenBits;
  185517. result.blueBits = pfd.cBlueBits;
  185518. result.alphaBits = pfd.cAlphaBits;
  185519. result.depthBufferBits = pfd.cDepthBits;
  185520. result.stencilBufferBits = pfd.cStencilBits;
  185521. result.accumulationBufferRedBits = pfd.cAccumRedBits;
  185522. result.accumulationBufferGreenBits = pfd.cAccumGreenBits;
  185523. result.accumulationBufferBlueBits = pfd.cAccumBlueBits;
  185524. result.accumulationBufferAlphaBits = pfd.cAccumAlphaBits;
  185525. result.fullSceneAntiAliasingNumSamples = 0;
  185526. return true;
  185527. }
  185528. else
  185529. {
  185530. jassertfalse
  185531. }
  185532. }
  185533. return false;
  185534. }
  185535. WindowedGLContext (const WindowedGLContext&);
  185536. WindowedGLContext& operator= (const WindowedGLContext&);
  185537. };
  185538. OpenGLContext* OpenGLComponent::createContext()
  185539. {
  185540. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this,
  185541. contextToShareListsWith != 0 ? (HGLRC) contextToShareListsWith->getRawContext() : 0,
  185542. preferredPixelFormat));
  185543. return (c->renderContext != 0) ? c.release() : 0;
  185544. }
  185545. void* OpenGLComponent::getNativeWindowHandle() const
  185546. {
  185547. return context != 0 ? static_cast<WindowedGLContext*> (static_cast<OpenGLContext*> (context))->getNativeWindowHandle() : 0;
  185548. }
  185549. void juce_glViewport (const int w, const int h)
  185550. {
  185551. glViewport (0, 0, w, h);
  185552. }
  185553. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  185554. OwnedArray <OpenGLPixelFormat>& results)
  185555. {
  185556. Component tempComp;
  185557. {
  185558. WindowedGLContext wc (component, 0, OpenGLPixelFormat (8, 8, 16, 0));
  185559. wc.makeActive();
  185560. wc.findAlternativeOpenGLPixelFormats (results);
  185561. }
  185562. }
  185563. #endif
  185564. /*** End of inlined file: juce_win32_OpenGLComponent.cpp ***/
  185565. /*** Start of inlined file: juce_win32_AudioCDReader.cpp ***/
  185566. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185567. // compiled on its own).
  185568. #if JUCE_INCLUDED_FILE
  185569. #if JUCE_USE_CDREADER
  185570. namespace CDReaderHelpers
  185571. {
  185572. //***************************************************************************
  185573. // %%% TARGET STATUS VALUES %%%
  185574. //***************************************************************************
  185575. #define STATUS_GOOD 0x00 // Status Good
  185576. #define STATUS_CHKCOND 0x02 // Check Condition
  185577. #define STATUS_CONDMET 0x04 // Condition Met
  185578. #define STATUS_BUSY 0x08 // Busy
  185579. #define STATUS_INTERM 0x10 // Intermediate
  185580. #define STATUS_INTCDMET 0x14 // Intermediate-condition met
  185581. #define STATUS_RESCONF 0x18 // Reservation conflict
  185582. #define STATUS_COMTERM 0x22 // Command Terminated
  185583. #define STATUS_QFULL 0x28 // Queue full
  185584. //***************************************************************************
  185585. // %%% SCSI MISCELLANEOUS EQUATES %%%
  185586. //***************************************************************************
  185587. #define MAXLUN 7 // Maximum Logical Unit Id
  185588. #define MAXTARG 7 // Maximum Target Id
  185589. #define MAX_SCSI_LUNS 64 // Maximum Number of SCSI LUNs
  185590. #define MAX_NUM_HA 8 // Maximum Number of SCSI HA's
  185591. //***************************************************************************
  185592. // %%% Commands for all Device Types %%%
  185593. //***************************************************************************
  185594. #define SCSI_CHANGE_DEF 0x40 // Change Definition (Optional)
  185595. #define SCSI_COMPARE 0x39 // Compare (O)
  185596. #define SCSI_COPY 0x18 // Copy (O)
  185597. #define SCSI_COP_VERIFY 0x3A // Copy and Verify (O)
  185598. #define SCSI_INQUIRY 0x12 // Inquiry (MANDATORY)
  185599. #define SCSI_LOG_SELECT 0x4C // Log Select (O)
  185600. #define SCSI_LOG_SENSE 0x4D // Log Sense (O)
  185601. #define SCSI_MODE_SEL6 0x15 // Mode Select 6-byte (Device Specific)
  185602. #define SCSI_MODE_SEL10 0x55 // Mode Select 10-byte (Device Specific)
  185603. #define SCSI_MODE_SEN6 0x1A // Mode Sense 6-byte (Device Specific)
  185604. #define SCSI_MODE_SEN10 0x5A // Mode Sense 10-byte (Device Specific)
  185605. #define SCSI_READ_BUFF 0x3C // Read Buffer (O)
  185606. #define SCSI_REQ_SENSE 0x03 // Request Sense (MANDATORY)
  185607. #define SCSI_SEND_DIAG 0x1D // Send Diagnostic (O)
  185608. #define SCSI_TST_U_RDY 0x00 // Test Unit Ready (MANDATORY)
  185609. #define SCSI_WRITE_BUFF 0x3B // Write Buffer (O)
  185610. //***************************************************************************
  185611. // %%% Commands Unique to Direct Access Devices %%%
  185612. //***************************************************************************
  185613. #define SCSI_COMPARE 0x39 // Compare (O)
  185614. #define SCSI_FORMAT 0x04 // Format Unit (MANDATORY)
  185615. #define SCSI_LCK_UN_CAC 0x36 // Lock Unlock Cache (O)
  185616. #define SCSI_PREFETCH 0x34 // Prefetch (O)
  185617. #define SCSI_MED_REMOVL 0x1E // Prevent/Allow medium Removal (O)
  185618. #define SCSI_READ6 0x08 // Read 6-byte (MANDATORY)
  185619. #define SCSI_READ10 0x28 // Read 10-byte (MANDATORY)
  185620. #define SCSI_RD_CAPAC 0x25 // Read Capacity (MANDATORY)
  185621. #define SCSI_RD_DEFECT 0x37 // Read Defect Data (O)
  185622. #define SCSI_READ_LONG 0x3E // Read Long (O)
  185623. #define SCSI_REASS_BLK 0x07 // Reassign Blocks (O)
  185624. #define SCSI_RCV_DIAG 0x1C // Receive Diagnostic Results (O)
  185625. #define SCSI_RELEASE 0x17 // Release Unit (MANDATORY)
  185626. #define SCSI_REZERO 0x01 // Rezero Unit (O)
  185627. #define SCSI_SRCH_DAT_E 0x31 // Search Data Equal (O)
  185628. #define SCSI_SRCH_DAT_H 0x30 // Search Data High (O)
  185629. #define SCSI_SRCH_DAT_L 0x32 // Search Data Low (O)
  185630. #define SCSI_SEEK6 0x0B // Seek 6-Byte (O)
  185631. #define SCSI_SEEK10 0x2B // Seek 10-Byte (O)
  185632. #define SCSI_SEND_DIAG 0x1D // Send Diagnostics (MANDATORY)
  185633. #define SCSI_SET_LIMIT 0x33 // Set Limits (O)
  185634. #define SCSI_START_STP 0x1B // Start/Stop Unit (O)
  185635. #define SCSI_SYNC_CACHE 0x35 // Synchronize Cache (O)
  185636. #define SCSI_VERIFY 0x2F // Verify (O)
  185637. #define SCSI_WRITE6 0x0A // Write 6-Byte (MANDATORY)
  185638. #define SCSI_WRITE10 0x2A // Write 10-Byte (MANDATORY)
  185639. #define SCSI_WRT_VERIFY 0x2E // Write and Verify (O)
  185640. #define SCSI_WRITE_LONG 0x3F // Write Long (O)
  185641. #define SCSI_WRITE_SAME 0x41 // Write Same (O)
  185642. //***************************************************************************
  185643. // %%% Commands Unique to Sequential Access Devices %%%
  185644. //***************************************************************************
  185645. #define SCSI_ERASE 0x19 // Erase (MANDATORY)
  185646. #define SCSI_LOAD_UN 0x1b // Load/Unload (O)
  185647. #define SCSI_LOCATE 0x2B // Locate (O)
  185648. #define SCSI_RD_BLK_LIM 0x05 // Read Block Limits (MANDATORY)
  185649. #define SCSI_READ_POS 0x34 // Read Position (O)
  185650. #define SCSI_READ_REV 0x0F // Read Reverse (O)
  185651. #define SCSI_REC_BF_DAT 0x14 // Recover Buffer Data (O)
  185652. #define SCSI_RESERVE 0x16 // Reserve Unit (MANDATORY)
  185653. #define SCSI_REWIND 0x01 // Rewind (MANDATORY)
  185654. #define SCSI_SPACE 0x11 // Space (MANDATORY)
  185655. #define SCSI_VERIFY_T 0x13 // Verify (Tape) (O)
  185656. #define SCSI_WRT_FILE 0x10 // Write Filemarks (MANDATORY)
  185657. //***************************************************************************
  185658. // %%% Commands Unique to Printer Devices %%%
  185659. //***************************************************************************
  185660. #define SCSI_PRINT 0x0A // Print (MANDATORY)
  185661. #define SCSI_SLEW_PNT 0x0B // Slew and Print (O)
  185662. #define SCSI_STOP_PNT 0x1B // Stop Print (O)
  185663. #define SCSI_SYNC_BUFF 0x10 // Synchronize Buffer (O)
  185664. //***************************************************************************
  185665. // %%% Commands Unique to Processor Devices %%%
  185666. //***************************************************************************
  185667. #define SCSI_RECEIVE 0x08 // Receive (O)
  185668. #define SCSI_SEND 0x0A // Send (O)
  185669. //***************************************************************************
  185670. // %%% Commands Unique to Write-Once Devices %%%
  185671. //***************************************************************************
  185672. #define SCSI_MEDIUM_SCN 0x38 // Medium Scan (O)
  185673. #define SCSI_SRCHDATE10 0x31 // Search Data Equal 10-Byte (O)
  185674. #define SCSI_SRCHDATE12 0xB1 // Search Data Equal 12-Byte (O)
  185675. #define SCSI_SRCHDATH10 0x30 // Search Data High 10-Byte (O)
  185676. #define SCSI_SRCHDATH12 0xB0 // Search Data High 12-Byte (O)
  185677. #define SCSI_SRCHDATL10 0x32 // Search Data Low 10-Byte (O)
  185678. #define SCSI_SRCHDATL12 0xB2 // Search Data Low 12-Byte (O)
  185679. #define SCSI_SET_LIM_10 0x33 // Set Limits 10-Byte (O)
  185680. #define SCSI_SET_LIM_12 0xB3 // Set Limits 10-Byte (O)
  185681. #define SCSI_VERIFY10 0x2F // Verify 10-Byte (O)
  185682. #define SCSI_VERIFY12 0xAF // Verify 12-Byte (O)
  185683. #define SCSI_WRITE12 0xAA // Write 12-Byte (O)
  185684. #define SCSI_WRT_VER10 0x2E // Write and Verify 10-Byte (O)
  185685. #define SCSI_WRT_VER12 0xAE // Write and Verify 12-Byte (O)
  185686. //***************************************************************************
  185687. // %%% Commands Unique to CD-ROM Devices %%%
  185688. //***************************************************************************
  185689. #define SCSI_PLAYAUD_10 0x45 // Play Audio 10-Byte (O)
  185690. #define SCSI_PLAYAUD_12 0xA5 // Play Audio 12-Byte 12-Byte (O)
  185691. #define SCSI_PLAYAUDMSF 0x47 // Play Audio MSF (O)
  185692. #define SCSI_PLAYA_TKIN 0x48 // Play Audio Track/Index (O)
  185693. #define SCSI_PLYTKREL10 0x49 // Play Track Relative 10-Byte (O)
  185694. #define SCSI_PLYTKREL12 0xA9 // Play Track Relative 12-Byte (O)
  185695. #define SCSI_READCDCAP 0x25 // Read CD-ROM Capacity (MANDATORY)
  185696. #define SCSI_READHEADER 0x44 // Read Header (O)
  185697. #define SCSI_SUBCHANNEL 0x42 // Read Subchannel (O)
  185698. #define SCSI_READ_TOC 0x43 // Read TOC (O)
  185699. //***************************************************************************
  185700. // %%% Commands Unique to Scanner Devices %%%
  185701. //***************************************************************************
  185702. #define SCSI_GETDBSTAT 0x34 // Get Data Buffer Status (O)
  185703. #define SCSI_GETWINDOW 0x25 // Get Window (O)
  185704. #define SCSI_OBJECTPOS 0x31 // Object Postion (O)
  185705. #define SCSI_SCAN 0x1B // Scan (O)
  185706. #define SCSI_SETWINDOW 0x24 // Set Window (MANDATORY)
  185707. //***************************************************************************
  185708. // %%% Commands Unique to Optical Memory Devices %%%
  185709. //***************************************************************************
  185710. #define SCSI_UpdateBlk 0x3D // Update Block (O)
  185711. //***************************************************************************
  185712. // %%% Commands Unique to Medium Changer Devices %%%
  185713. //***************************************************************************
  185714. #define SCSI_EXCHMEDIUM 0xA6 // Exchange Medium (O)
  185715. #define SCSI_INITELSTAT 0x07 // Initialize Element Status (O)
  185716. #define SCSI_POSTOELEM 0x2B // Position to Element (O)
  185717. #define SCSI_REQ_VE_ADD 0xB5 // Request Volume Element Address (O)
  185718. #define SCSI_SENDVOLTAG 0xB6 // Send Volume Tag (O)
  185719. //***************************************************************************
  185720. // %%% Commands Unique to Communication Devices %%%
  185721. //***************************************************************************
  185722. #define SCSI_GET_MSG_6 0x08 // Get Message 6-Byte (MANDATORY)
  185723. #define SCSI_GET_MSG_10 0x28 // Get Message 10-Byte (O)
  185724. #define SCSI_GET_MSG_12 0xA8 // Get Message 12-Byte (O)
  185725. #define SCSI_SND_MSG_6 0x0A // Send Message 6-Byte (MANDATORY)
  185726. #define SCSI_SND_MSG_10 0x2A // Send Message 10-Byte (O)
  185727. #define SCSI_SND_MSG_12 0xAA // Send Message 12-Byte (O)
  185728. //***************************************************************************
  185729. // %%% Request Sense Data Format %%%
  185730. //***************************************************************************
  185731. typedef struct {
  185732. BYTE ErrorCode; // Error Code (70H or 71H)
  185733. BYTE SegmentNum; // Number of current segment descriptor
  185734. BYTE SenseKey; // Sense Key(See bit definitions too)
  185735. BYTE InfoByte0; // Information MSB
  185736. BYTE InfoByte1; // Information MID
  185737. BYTE InfoByte2; // Information MID
  185738. BYTE InfoByte3; // Information LSB
  185739. BYTE AddSenLen; // Additional Sense Length
  185740. BYTE ComSpecInf0; // Command Specific Information MSB
  185741. BYTE ComSpecInf1; // Command Specific Information MID
  185742. BYTE ComSpecInf2; // Command Specific Information MID
  185743. BYTE ComSpecInf3; // Command Specific Information LSB
  185744. BYTE AddSenseCode; // Additional Sense Code
  185745. BYTE AddSenQual; // Additional Sense Code Qualifier
  185746. BYTE FieldRepUCode; // Field Replaceable Unit Code
  185747. BYTE SenKeySpec15; // Sense Key Specific 15th byte
  185748. BYTE SenKeySpec16; // Sense Key Specific 16th byte
  185749. BYTE SenKeySpec17; // Sense Key Specific 17th byte
  185750. BYTE AddSenseBytes; // Additional Sense Bytes
  185751. } SENSE_DATA_FMT;
  185752. //***************************************************************************
  185753. // %%% REQUEST SENSE ERROR CODE %%%
  185754. //***************************************************************************
  185755. #define SERROR_CURRENT 0x70 // Current Errors
  185756. #define SERROR_DEFERED 0x71 // Deferred Errors
  185757. //***************************************************************************
  185758. // %%% REQUEST SENSE BIT DEFINITIONS %%%
  185759. //***************************************************************************
  185760. #define SENSE_VALID 0x80 // Byte 0 Bit 7
  185761. #define SENSE_FILEMRK 0x80 // Byte 2 Bit 7
  185762. #define SENSE_EOM 0x40 // Byte 2 Bit 6
  185763. #define SENSE_ILI 0x20 // Byte 2 Bit 5
  185764. //***************************************************************************
  185765. // %%% REQUEST SENSE SENSE KEY DEFINITIONS %%%
  185766. //***************************************************************************
  185767. #define KEY_NOSENSE 0x00 // No Sense
  185768. #define KEY_RECERROR 0x01 // Recovered Error
  185769. #define KEY_NOTREADY 0x02 // Not Ready
  185770. #define KEY_MEDIUMERR 0x03 // Medium Error
  185771. #define KEY_HARDERROR 0x04 // Hardware Error
  185772. #define KEY_ILLGLREQ 0x05 // Illegal Request
  185773. #define KEY_UNITATT 0x06 // Unit Attention
  185774. #define KEY_DATAPROT 0x07 // Data Protect
  185775. #define KEY_BLANKCHK 0x08 // Blank Check
  185776. #define KEY_VENDSPEC 0x09 // Vendor Specific
  185777. #define KEY_COPYABORT 0x0A // Copy Abort
  185778. #define KEY_EQUAL 0x0C // Equal (Search)
  185779. #define KEY_VOLOVRFLW 0x0D // Volume Overflow
  185780. #define KEY_MISCOMP 0x0E // Miscompare (Search)
  185781. #define KEY_RESERVED 0x0F // Reserved
  185782. //***************************************************************************
  185783. // %%% PERIPHERAL DEVICE TYPE DEFINITIONS %%%
  185784. //***************************************************************************
  185785. #define DTYPE_DASD 0x00 // Disk Device
  185786. #define DTYPE_SEQD 0x01 // Tape Device
  185787. #define DTYPE_PRNT 0x02 // Printer
  185788. #define DTYPE_PROC 0x03 // Processor
  185789. #define DTYPE_WORM 0x04 // Write-once read-multiple
  185790. #define DTYPE_CROM 0x05 // CD-ROM device
  185791. #define DTYPE_SCAN 0x06 // Scanner device
  185792. #define DTYPE_OPTI 0x07 // Optical memory device
  185793. #define DTYPE_JUKE 0x08 // Medium Changer device
  185794. #define DTYPE_COMM 0x09 // Communications device
  185795. #define DTYPE_RESL 0x0A // Reserved (low)
  185796. #define DTYPE_RESH 0x1E // Reserved (high)
  185797. #define DTYPE_UNKNOWN 0x1F // Unknown or no device type
  185798. //***************************************************************************
  185799. // %%% ANSI APPROVED VERSION DEFINITIONS %%%
  185800. //***************************************************************************
  185801. #define ANSI_MAYBE 0x0 // Device may or may not be ANSI approved stand
  185802. #define ANSI_SCSI1 0x1 // Device complies to ANSI X3.131-1986 (SCSI-1)
  185803. #define ANSI_SCSI2 0x2 // Device complies to SCSI-2
  185804. #define ANSI_RESLO 0x3 // Reserved (low)
  185805. #define ANSI_RESHI 0x7 // Reserved (high)
  185806. typedef struct
  185807. {
  185808. USHORT Length;
  185809. UCHAR ScsiStatus;
  185810. UCHAR PathId;
  185811. UCHAR TargetId;
  185812. UCHAR Lun;
  185813. UCHAR CdbLength;
  185814. UCHAR SenseInfoLength;
  185815. UCHAR DataIn;
  185816. ULONG DataTransferLength;
  185817. ULONG TimeOutValue;
  185818. ULONG DataBufferOffset;
  185819. ULONG SenseInfoOffset;
  185820. UCHAR Cdb[16];
  185821. } SCSI_PASS_THROUGH, *PSCSI_PASS_THROUGH;
  185822. typedef struct
  185823. {
  185824. USHORT Length;
  185825. UCHAR ScsiStatus;
  185826. UCHAR PathId;
  185827. UCHAR TargetId;
  185828. UCHAR Lun;
  185829. UCHAR CdbLength;
  185830. UCHAR SenseInfoLength;
  185831. UCHAR DataIn;
  185832. ULONG DataTransferLength;
  185833. ULONG TimeOutValue;
  185834. PVOID DataBuffer;
  185835. ULONG SenseInfoOffset;
  185836. UCHAR Cdb[16];
  185837. } SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT;
  185838. typedef struct
  185839. {
  185840. SCSI_PASS_THROUGH_DIRECT spt;
  185841. ULONG Filler;
  185842. UCHAR ucSenseBuf[32];
  185843. } SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, *PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER;
  185844. typedef struct
  185845. {
  185846. ULONG Length;
  185847. UCHAR PortNumber;
  185848. UCHAR PathId;
  185849. UCHAR TargetId;
  185850. UCHAR Lun;
  185851. } SCSI_ADDRESS, *PSCSI_ADDRESS;
  185852. #define METHOD_BUFFERED 0
  185853. #define METHOD_IN_DIRECT 1
  185854. #define METHOD_OUT_DIRECT 2
  185855. #define METHOD_NEITHER 3
  185856. #define FILE_ANY_ACCESS 0
  185857. #ifndef FILE_READ_ACCESS
  185858. #define FILE_READ_ACCESS (0x0001)
  185859. #endif
  185860. #ifndef FILE_WRITE_ACCESS
  185861. #define FILE_WRITE_ACCESS (0x0002)
  185862. #endif
  185863. #define IOCTL_SCSI_BASE 0x00000004
  185864. #define SCSI_IOCTL_DATA_OUT 0
  185865. #define SCSI_IOCTL_DATA_IN 1
  185866. #define SCSI_IOCTL_DATA_UNSPECIFIED 2
  185867. #define CTL_CODE2( DevType, Function, Method, Access ) ( \
  185868. ((DevType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
  185869. )
  185870. #define IOCTL_SCSI_PASS_THROUGH CTL_CODE2( IOCTL_SCSI_BASE, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  185871. #define IOCTL_SCSI_GET_CAPABILITIES CTL_CODE2( IOCTL_SCSI_BASE, 0x0404, METHOD_BUFFERED, FILE_ANY_ACCESS)
  185872. #define IOCTL_SCSI_PASS_THROUGH_DIRECT CTL_CODE2( IOCTL_SCSI_BASE, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  185873. #define IOCTL_SCSI_GET_ADDRESS CTL_CODE2( IOCTL_SCSI_BASE, 0x0406, METHOD_BUFFERED, FILE_ANY_ACCESS )
  185874. #define SENSE_LEN 14
  185875. #define SRB_DIR_SCSI 0x00
  185876. #define SRB_POSTING 0x01
  185877. #define SRB_ENABLE_RESIDUAL_COUNT 0x04
  185878. #define SRB_DIR_IN 0x08
  185879. #define SRB_DIR_OUT 0x10
  185880. #define SRB_EVENT_NOTIFY 0x40
  185881. #define RESIDUAL_COUNT_SUPPORTED 0x02
  185882. #define MAX_SRB_TIMEOUT 1080001u
  185883. #define DEFAULT_SRB_TIMEOUT 1080001u
  185884. #define SC_HA_INQUIRY 0x00
  185885. #define SC_GET_DEV_TYPE 0x01
  185886. #define SC_EXEC_SCSI_CMD 0x02
  185887. #define SC_ABORT_SRB 0x03
  185888. #define SC_RESET_DEV 0x04
  185889. #define SC_SET_HA_PARMS 0x05
  185890. #define SC_GET_DISK_INFO 0x06
  185891. #define SC_RESCAN_SCSI_BUS 0x07
  185892. #define SC_GETSET_TIMEOUTS 0x08
  185893. #define SS_PENDING 0x00
  185894. #define SS_COMP 0x01
  185895. #define SS_ABORTED 0x02
  185896. #define SS_ABORT_FAIL 0x03
  185897. #define SS_ERR 0x04
  185898. #define SS_INVALID_CMD 0x80
  185899. #define SS_INVALID_HA 0x81
  185900. #define SS_NO_DEVICE 0x82
  185901. #define SS_INVALID_SRB 0xE0
  185902. #define SS_OLD_MANAGER 0xE1
  185903. #define SS_BUFFER_ALIGN 0xE1
  185904. #define SS_ILLEGAL_MODE 0xE2
  185905. #define SS_NO_ASPI 0xE3
  185906. #define SS_FAILED_INIT 0xE4
  185907. #define SS_ASPI_IS_BUSY 0xE5
  185908. #define SS_BUFFER_TO_BIG 0xE6
  185909. #define SS_BUFFER_TOO_BIG 0xE6
  185910. #define SS_MISMATCHED_COMPONENTS 0xE7
  185911. #define SS_NO_ADAPTERS 0xE8
  185912. #define SS_INSUFFICIENT_RESOURCES 0xE9
  185913. #define SS_ASPI_IS_SHUTDOWN 0xEA
  185914. #define SS_BAD_INSTALL 0xEB
  185915. #define HASTAT_OK 0x00
  185916. #define HASTAT_SEL_TO 0x11
  185917. #define HASTAT_DO_DU 0x12
  185918. #define HASTAT_BUS_FREE 0x13
  185919. #define HASTAT_PHASE_ERR 0x14
  185920. #define HASTAT_TIMEOUT 0x09
  185921. #define HASTAT_COMMAND_TIMEOUT 0x0B
  185922. #define HASTAT_MESSAGE_REJECT 0x0D
  185923. #define HASTAT_BUS_RESET 0x0E
  185924. #define HASTAT_PARITY_ERROR 0x0F
  185925. #define HASTAT_REQUEST_SENSE_FAILED 0x10
  185926. #define PACKED
  185927. #pragma pack(1)
  185928. typedef struct
  185929. {
  185930. BYTE SRB_Cmd;
  185931. BYTE SRB_Status;
  185932. BYTE SRB_HaID;
  185933. BYTE SRB_Flags;
  185934. DWORD SRB_Hdr_Rsvd;
  185935. BYTE HA_Count;
  185936. BYTE HA_SCSI_ID;
  185937. BYTE HA_ManagerId[16];
  185938. BYTE HA_Identifier[16];
  185939. BYTE HA_Unique[16];
  185940. WORD HA_Rsvd1;
  185941. BYTE pad[20];
  185942. } PACKED SRB_HAInquiry, *PSRB_HAInquiry, FAR *LPSRB_HAInquiry;
  185943. typedef struct
  185944. {
  185945. BYTE SRB_Cmd;
  185946. BYTE SRB_Status;
  185947. BYTE SRB_HaID;
  185948. BYTE SRB_Flags;
  185949. DWORD SRB_Hdr_Rsvd;
  185950. BYTE SRB_Target;
  185951. BYTE SRB_Lun;
  185952. BYTE SRB_DeviceType;
  185953. BYTE SRB_Rsvd1;
  185954. BYTE pad[68];
  185955. } PACKED SRB_GDEVBlock, *PSRB_GDEVBlock, FAR *LPSRB_GDEVBlock;
  185956. typedef struct
  185957. {
  185958. BYTE SRB_Cmd;
  185959. BYTE SRB_Status;
  185960. BYTE SRB_HaID;
  185961. BYTE SRB_Flags;
  185962. DWORD SRB_Hdr_Rsvd;
  185963. BYTE SRB_Target;
  185964. BYTE SRB_Lun;
  185965. WORD SRB_Rsvd1;
  185966. DWORD SRB_BufLen;
  185967. BYTE FAR *SRB_BufPointer;
  185968. BYTE SRB_SenseLen;
  185969. BYTE SRB_CDBLen;
  185970. BYTE SRB_HaStat;
  185971. BYTE SRB_TargStat;
  185972. VOID FAR *SRB_PostProc;
  185973. BYTE SRB_Rsvd2[20];
  185974. BYTE CDBByte[16];
  185975. BYTE SenseArea[SENSE_LEN+2];
  185976. } PACKED SRB_ExecSCSICmd, *PSRB_ExecSCSICmd, FAR *LPSRB_ExecSCSICmd;
  185977. typedef struct
  185978. {
  185979. BYTE SRB_Cmd;
  185980. BYTE SRB_Status;
  185981. BYTE SRB_HaId;
  185982. BYTE SRB_Flags;
  185983. DWORD SRB_Hdr_Rsvd;
  185984. } PACKED SRB, *PSRB, FAR *LPSRB;
  185985. #pragma pack()
  185986. struct CDDeviceInfo
  185987. {
  185988. char vendor[9];
  185989. char productId[17];
  185990. char rev[5];
  185991. char vendorSpec[21];
  185992. BYTE ha;
  185993. BYTE tgt;
  185994. BYTE lun;
  185995. char scsiDriveLetter; // will be 0 if not using scsi
  185996. };
  185997. class CDReadBuffer
  185998. {
  185999. public:
  186000. int startFrame;
  186001. int numFrames;
  186002. int dataStartOffset;
  186003. int dataLength;
  186004. BYTE* buffer;
  186005. int bufferSize;
  186006. int index;
  186007. bool wantsIndex;
  186008. CDReadBuffer (const int numberOfFrames)
  186009. : startFrame (0),
  186010. numFrames (0),
  186011. dataStartOffset (0),
  186012. dataLength (0),
  186013. index (0),
  186014. wantsIndex (false)
  186015. {
  186016. bufferSize = 2352 * numberOfFrames;
  186017. buffer = (BYTE*) juce_malloc (bufferSize);
  186018. }
  186019. ~CDReadBuffer()
  186020. {
  186021. juce_free (buffer);
  186022. }
  186023. bool isZero() const
  186024. {
  186025. BYTE* p = buffer + dataStartOffset;
  186026. for (int i = dataLength; --i >= 0;)
  186027. if (*p++ != 0)
  186028. return false;
  186029. return true;
  186030. }
  186031. };
  186032. class CDDeviceHandle;
  186033. class CDController
  186034. {
  186035. public:
  186036. CDController();
  186037. virtual ~CDController();
  186038. virtual bool read (CDReadBuffer* t) = 0;
  186039. virtual void shutDown();
  186040. bool readAudio (CDReadBuffer* t, CDReadBuffer* overlapBuffer = 0);
  186041. int getLastIndex();
  186042. public:
  186043. bool initialised;
  186044. CDDeviceHandle* deviceInfo;
  186045. int framesToCheck, framesOverlap;
  186046. void prepare (SRB_ExecSCSICmd& s);
  186047. void perform (SRB_ExecSCSICmd& s);
  186048. void setPaused (bool paused);
  186049. };
  186050. #pragma pack(1)
  186051. struct TOCTRACK
  186052. {
  186053. BYTE rsvd;
  186054. BYTE ADR;
  186055. BYTE trackNumber;
  186056. BYTE rsvd2;
  186057. BYTE addr[4];
  186058. };
  186059. struct TOC
  186060. {
  186061. WORD tocLen;
  186062. BYTE firstTrack;
  186063. BYTE lastTrack;
  186064. TOCTRACK tracks[100];
  186065. };
  186066. #pragma pack()
  186067. enum
  186068. {
  186069. READTYPE_ANY = 0,
  186070. READTYPE_ATAPI1 = 1,
  186071. READTYPE_ATAPI2 = 2,
  186072. READTYPE_READ6 = 3,
  186073. READTYPE_READ10 = 4,
  186074. READTYPE_READ_D8 = 5,
  186075. READTYPE_READ_D4 = 6,
  186076. READTYPE_READ_D4_1 = 7,
  186077. READTYPE_READ10_2 = 8
  186078. };
  186079. class CDDeviceHandle
  186080. {
  186081. public:
  186082. CDDeviceHandle (const CDDeviceInfo* const device)
  186083. : scsiHandle (0),
  186084. readType (READTYPE_ANY),
  186085. controller (0)
  186086. {
  186087. memcpy (&info, device, sizeof (info));
  186088. }
  186089. ~CDDeviceHandle()
  186090. {
  186091. if (controller != 0)
  186092. {
  186093. controller->shutDown();
  186094. controller = 0;
  186095. }
  186096. if (scsiHandle != 0)
  186097. CloseHandle (scsiHandle);
  186098. }
  186099. bool readTOC (TOC* lpToc, bool useMSF);
  186100. bool readAudio (CDReadBuffer* buffer, CDReadBuffer* overlapBuffer = 0);
  186101. void openDrawer (bool shouldBeOpen);
  186102. CDDeviceInfo info;
  186103. HANDLE scsiHandle;
  186104. BYTE readType;
  186105. private:
  186106. ScopedPointer<CDController> controller;
  186107. bool testController (const int readType,
  186108. CDController* const newController,
  186109. CDReadBuffer* const bufferToUse);
  186110. };
  186111. DWORD (*fGetASPI32SupportInfo)(void);
  186112. DWORD (*fSendASPI32Command)(LPSRB);
  186113. static HINSTANCE winAspiLib = 0;
  186114. static bool usingScsi = false;
  186115. static bool initialised = false;
  186116. static bool InitialiseCDRipper()
  186117. {
  186118. if (! initialised)
  186119. {
  186120. initialised = true;
  186121. OSVERSIONINFO info;
  186122. info.dwOSVersionInfoSize = sizeof (info);
  186123. GetVersionEx (&info);
  186124. usingScsi = (info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4);
  186125. if (! usingScsi)
  186126. {
  186127. fGetASPI32SupportInfo = 0;
  186128. fSendASPI32Command = 0;
  186129. winAspiLib = LoadLibrary (_T("WNASPI32.DLL"));
  186130. if (winAspiLib != 0)
  186131. {
  186132. fGetASPI32SupportInfo = (DWORD(*)(void)) GetProcAddress (winAspiLib, "GetASPI32SupportInfo");
  186133. fSendASPI32Command = (DWORD(*)(LPSRB)) GetProcAddress (winAspiLib, "SendASPI32Command");
  186134. if (fGetASPI32SupportInfo == 0 || fSendASPI32Command == 0)
  186135. return false;
  186136. }
  186137. else
  186138. {
  186139. usingScsi = true;
  186140. }
  186141. }
  186142. }
  186143. return true;
  186144. }
  186145. static void DeinitialiseCDRipper()
  186146. {
  186147. if (winAspiLib != 0)
  186148. {
  186149. fGetASPI32SupportInfo = 0;
  186150. fSendASPI32Command = 0;
  186151. FreeLibrary (winAspiLib);
  186152. winAspiLib = 0;
  186153. }
  186154. initialised = false;
  186155. }
  186156. static HANDLE CreateSCSIDeviceHandle (char driveLetter)
  186157. {
  186158. TCHAR devicePath[] = { '\\', '\\', '.', '\\', driveLetter, ':', 0, 0 };
  186159. OSVERSIONINFO info;
  186160. info.dwOSVersionInfoSize = sizeof (info);
  186161. GetVersionEx (&info);
  186162. DWORD flags = GENERIC_READ;
  186163. if ((info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4))
  186164. flags = GENERIC_READ | GENERIC_WRITE;
  186165. HANDLE h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186166. if (h == INVALID_HANDLE_VALUE)
  186167. {
  186168. flags ^= GENERIC_WRITE;
  186169. h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186170. }
  186171. return h;
  186172. }
  186173. static DWORD performScsiPassThroughCommand (const LPSRB_ExecSCSICmd srb,
  186174. const char driveLetter,
  186175. HANDLE& deviceHandle,
  186176. const bool retryOnFailure = true)
  186177. {
  186178. SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER s;
  186179. zerostruct (s);
  186180. s.spt.Length = sizeof (SCSI_PASS_THROUGH);
  186181. s.spt.CdbLength = srb->SRB_CDBLen;
  186182. s.spt.DataIn = (BYTE) ((srb->SRB_Flags & SRB_DIR_IN)
  186183. ? SCSI_IOCTL_DATA_IN
  186184. : ((srb->SRB_Flags & SRB_DIR_OUT)
  186185. ? SCSI_IOCTL_DATA_OUT
  186186. : SCSI_IOCTL_DATA_UNSPECIFIED));
  186187. s.spt.DataTransferLength = srb->SRB_BufLen;
  186188. s.spt.TimeOutValue = 5;
  186189. s.spt.DataBuffer = srb->SRB_BufPointer;
  186190. s.spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  186191. memcpy (s.spt.Cdb, srb->CDBByte, srb->SRB_CDBLen);
  186192. srb->SRB_Status = SS_ERR;
  186193. srb->SRB_TargStat = 0x0004;
  186194. DWORD bytesReturned = 0;
  186195. if (DeviceIoControl (deviceHandle, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  186196. &s, sizeof (s),
  186197. &s, sizeof (s),
  186198. &bytesReturned, 0) != 0)
  186199. {
  186200. srb->SRB_Status = SS_COMP;
  186201. }
  186202. else if (retryOnFailure)
  186203. {
  186204. const DWORD error = GetLastError();
  186205. if ((error == ERROR_MEDIA_CHANGED) || (error == ERROR_INVALID_HANDLE))
  186206. {
  186207. if (error != ERROR_INVALID_HANDLE)
  186208. CloseHandle (deviceHandle);
  186209. deviceHandle = CreateSCSIDeviceHandle (driveLetter);
  186210. return performScsiPassThroughCommand (srb, driveLetter, deviceHandle, false);
  186211. }
  186212. }
  186213. return srb->SRB_Status;
  186214. }
  186215. // Controller types..
  186216. class ControllerType1 : public CDController
  186217. {
  186218. public:
  186219. ControllerType1() {}
  186220. ~ControllerType1() {}
  186221. bool read (CDReadBuffer* rb)
  186222. {
  186223. if (rb->numFrames * 2352 > rb->bufferSize)
  186224. return false;
  186225. SRB_ExecSCSICmd s;
  186226. prepare (s);
  186227. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186228. s.SRB_BufLen = rb->bufferSize;
  186229. s.SRB_BufPointer = rb->buffer;
  186230. s.SRB_CDBLen = 12;
  186231. s.CDBByte[0] = 0xBE;
  186232. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186233. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186234. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186235. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186236. s.CDBByte[9] = (BYTE)((deviceInfo->readType == READTYPE_ATAPI1) ? 0x10 : 0xF0);
  186237. perform (s);
  186238. if (s.SRB_Status != SS_COMP)
  186239. return false;
  186240. rb->dataLength = rb->numFrames * 2352;
  186241. rb->dataStartOffset = 0;
  186242. return true;
  186243. }
  186244. };
  186245. class ControllerType2 : public CDController
  186246. {
  186247. public:
  186248. ControllerType2() {}
  186249. ~ControllerType2() {}
  186250. void shutDown()
  186251. {
  186252. if (initialised)
  186253. {
  186254. BYTE bufPointer[] = { 0, 0, 0, 8, 83, 0, 0, 0, 0, 0, 8, 0 };
  186255. SRB_ExecSCSICmd s;
  186256. prepare (s);
  186257. s.SRB_Flags = SRB_EVENT_NOTIFY | SRB_ENABLE_RESIDUAL_COUNT;
  186258. s.SRB_BufLen = 0x0C;
  186259. s.SRB_BufPointer = bufPointer;
  186260. s.SRB_CDBLen = 6;
  186261. s.CDBByte[0] = 0x15;
  186262. s.CDBByte[4] = 0x0C;
  186263. perform (s);
  186264. }
  186265. }
  186266. bool init()
  186267. {
  186268. SRB_ExecSCSICmd s;
  186269. s.SRB_Status = SS_ERR;
  186270. if (deviceInfo->readType == READTYPE_READ10_2)
  186271. {
  186272. BYTE bufPointer1[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 35, 6, 0, 0, 0, 0, 0, 128 };
  186273. BYTE bufPointer2[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 1, 6, 32, 7, 0, 0, 0, 0 };
  186274. for (int i = 0; i < 2; ++i)
  186275. {
  186276. prepare (s);
  186277. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186278. s.SRB_BufLen = 0x14;
  186279. s.SRB_BufPointer = (i == 0) ? bufPointer1 : bufPointer2;
  186280. s.SRB_CDBLen = 6;
  186281. s.CDBByte[0] = 0x15;
  186282. s.CDBByte[1] = 0x10;
  186283. s.CDBByte[4] = 0x14;
  186284. perform (s);
  186285. if (s.SRB_Status != SS_COMP)
  186286. return false;
  186287. }
  186288. }
  186289. else
  186290. {
  186291. BYTE bufPointer[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48 };
  186292. prepare (s);
  186293. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186294. s.SRB_BufLen = 0x0C;
  186295. s.SRB_BufPointer = bufPointer;
  186296. s.SRB_CDBLen = 6;
  186297. s.CDBByte[0] = 0x15;
  186298. s.CDBByte[4] = 0x0C;
  186299. perform (s);
  186300. }
  186301. return s.SRB_Status == SS_COMP;
  186302. }
  186303. bool read (CDReadBuffer* rb)
  186304. {
  186305. if (rb->numFrames * 2352 > rb->bufferSize)
  186306. return false;
  186307. if (!initialised)
  186308. {
  186309. initialised = init();
  186310. if (!initialised)
  186311. return false;
  186312. }
  186313. SRB_ExecSCSICmd s;
  186314. prepare (s);
  186315. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186316. s.SRB_BufLen = rb->bufferSize;
  186317. s.SRB_BufPointer = rb->buffer;
  186318. s.SRB_CDBLen = 10;
  186319. s.CDBByte[0] = 0x28;
  186320. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  186321. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186322. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186323. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186324. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186325. perform (s);
  186326. if (s.SRB_Status != SS_COMP)
  186327. return false;
  186328. rb->dataLength = rb->numFrames * 2352;
  186329. rb->dataStartOffset = 0;
  186330. return true;
  186331. }
  186332. };
  186333. class ControllerType3 : public CDController
  186334. {
  186335. public:
  186336. ControllerType3() {}
  186337. ~ControllerType3() {}
  186338. bool read (CDReadBuffer* rb)
  186339. {
  186340. if (rb->numFrames * 2352 > rb->bufferSize)
  186341. return false;
  186342. if (!initialised)
  186343. {
  186344. setPaused (false);
  186345. initialised = true;
  186346. }
  186347. SRB_ExecSCSICmd s;
  186348. prepare (s);
  186349. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186350. s.SRB_BufLen = rb->numFrames * 2352;
  186351. s.SRB_BufPointer = rb->buffer;
  186352. s.SRB_CDBLen = 12;
  186353. s.CDBByte[0] = 0xD8;
  186354. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186355. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186356. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186357. s.CDBByte[9] = (BYTE)(rb->numFrames & 0xFF);
  186358. perform (s);
  186359. if (s.SRB_Status != SS_COMP)
  186360. return false;
  186361. rb->dataLength = rb->numFrames * 2352;
  186362. rb->dataStartOffset = 0;
  186363. return true;
  186364. }
  186365. };
  186366. class ControllerType4 : public CDController
  186367. {
  186368. public:
  186369. ControllerType4() {}
  186370. ~ControllerType4() {}
  186371. bool selectD4Mode()
  186372. {
  186373. BYTE bufPointer[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 48 };
  186374. SRB_ExecSCSICmd s;
  186375. prepare (s);
  186376. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186377. s.SRB_CDBLen = 6;
  186378. s.SRB_BufLen = 12;
  186379. s.SRB_BufPointer = bufPointer;
  186380. s.CDBByte[0] = 0x15;
  186381. s.CDBByte[1] = 0x10;
  186382. s.CDBByte[4] = 0x08;
  186383. perform (s);
  186384. return s.SRB_Status == SS_COMP;
  186385. }
  186386. bool read (CDReadBuffer* rb)
  186387. {
  186388. if (rb->numFrames * 2352 > rb->bufferSize)
  186389. return false;
  186390. if (!initialised)
  186391. {
  186392. setPaused (true);
  186393. if (deviceInfo->readType == READTYPE_READ_D4_1)
  186394. selectD4Mode();
  186395. initialised = true;
  186396. }
  186397. SRB_ExecSCSICmd s;
  186398. prepare (s);
  186399. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186400. s.SRB_BufLen = rb->bufferSize;
  186401. s.SRB_BufPointer = rb->buffer;
  186402. s.SRB_CDBLen = 10;
  186403. s.CDBByte[0] = 0xD4;
  186404. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186405. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186406. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186407. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186408. perform (s);
  186409. if (s.SRB_Status != SS_COMP)
  186410. return false;
  186411. rb->dataLength = rb->numFrames * 2352;
  186412. rb->dataStartOffset = 0;
  186413. return true;
  186414. }
  186415. };
  186416. CDController::CDController() : initialised (false)
  186417. {
  186418. }
  186419. CDController::~CDController()
  186420. {
  186421. }
  186422. void CDController::prepare (SRB_ExecSCSICmd& s)
  186423. {
  186424. zerostruct (s);
  186425. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186426. s.SRB_HaID = deviceInfo->info.ha;
  186427. s.SRB_Target = deviceInfo->info.tgt;
  186428. s.SRB_Lun = deviceInfo->info.lun;
  186429. s.SRB_SenseLen = SENSE_LEN;
  186430. }
  186431. void CDController::perform (SRB_ExecSCSICmd& s)
  186432. {
  186433. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186434. s.SRB_PostProc = (void*)event;
  186435. ResetEvent (event);
  186436. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s,
  186437. deviceInfo->info.scsiDriveLetter,
  186438. deviceInfo->scsiHandle)
  186439. : fSendASPI32Command ((LPSRB)&s);
  186440. if (status == SS_PENDING)
  186441. WaitForSingleObject (event, 4000);
  186442. CloseHandle (event);
  186443. }
  186444. void CDController::setPaused (bool paused)
  186445. {
  186446. SRB_ExecSCSICmd s;
  186447. prepare (s);
  186448. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186449. s.SRB_CDBLen = 10;
  186450. s.CDBByte[0] = 0x4B;
  186451. s.CDBByte[8] = (BYTE) (paused ? 0 : 1);
  186452. perform (s);
  186453. }
  186454. void CDController::shutDown()
  186455. {
  186456. }
  186457. bool CDController::readAudio (CDReadBuffer* rb, CDReadBuffer* overlapBuffer)
  186458. {
  186459. if (overlapBuffer != 0)
  186460. {
  186461. const bool canDoJitter = (overlapBuffer->bufferSize >= 2352 * framesToCheck);
  186462. const bool doJitter = canDoJitter && ! overlapBuffer->isZero();
  186463. if (doJitter
  186464. && overlapBuffer->startFrame > 0
  186465. && overlapBuffer->numFrames > 0
  186466. && overlapBuffer->dataLength > 0)
  186467. {
  186468. const int numFrames = rb->numFrames;
  186469. if (overlapBuffer->startFrame == (rb->startFrame - framesToCheck))
  186470. {
  186471. rb->startFrame -= framesOverlap;
  186472. if (framesToCheck < framesOverlap
  186473. && numFrames + framesOverlap <= rb->bufferSize / 2352)
  186474. rb->numFrames += framesOverlap;
  186475. }
  186476. else
  186477. {
  186478. overlapBuffer->dataLength = 0;
  186479. overlapBuffer->startFrame = 0;
  186480. overlapBuffer->numFrames = 0;
  186481. }
  186482. }
  186483. if (! read (rb))
  186484. return false;
  186485. if (doJitter)
  186486. {
  186487. const int checkLen = framesToCheck * 2352;
  186488. const int maxToCheck = rb->dataLength - checkLen;
  186489. if (overlapBuffer->dataLength == 0 || overlapBuffer->isZero())
  186490. return true;
  186491. BYTE* const p = overlapBuffer->buffer + overlapBuffer->dataStartOffset;
  186492. bool found = false;
  186493. for (int i = 0; i < maxToCheck; ++i)
  186494. {
  186495. if (!memcmp (p, rb->buffer + i, checkLen))
  186496. {
  186497. i += checkLen;
  186498. rb->dataStartOffset = i;
  186499. rb->dataLength -= i;
  186500. rb->startFrame = overlapBuffer->startFrame + framesToCheck;
  186501. found = true;
  186502. break;
  186503. }
  186504. }
  186505. rb->numFrames = rb->dataLength / 2352;
  186506. rb->dataLength = 2352 * rb->numFrames;
  186507. if (!found)
  186508. return false;
  186509. }
  186510. if (canDoJitter)
  186511. {
  186512. memcpy (overlapBuffer->buffer,
  186513. rb->buffer + rb->dataStartOffset + 2352 * (rb->numFrames - framesToCheck),
  186514. 2352 * framesToCheck);
  186515. overlapBuffer->startFrame = rb->startFrame + rb->numFrames - framesToCheck;
  186516. overlapBuffer->numFrames = framesToCheck;
  186517. overlapBuffer->dataLength = 2352 * framesToCheck;
  186518. overlapBuffer->dataStartOffset = 0;
  186519. }
  186520. else
  186521. {
  186522. overlapBuffer->startFrame = 0;
  186523. overlapBuffer->numFrames = 0;
  186524. overlapBuffer->dataLength = 0;
  186525. }
  186526. return true;
  186527. }
  186528. else
  186529. {
  186530. return read (rb);
  186531. }
  186532. }
  186533. int CDController::getLastIndex()
  186534. {
  186535. char qdata[100];
  186536. SRB_ExecSCSICmd s;
  186537. prepare (s);
  186538. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186539. s.SRB_BufLen = sizeof (qdata);
  186540. s.SRB_BufPointer = (BYTE*)qdata;
  186541. s.SRB_CDBLen = 12;
  186542. s.CDBByte[0] = 0x42;
  186543. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  186544. s.CDBByte[2] = 64;
  186545. s.CDBByte[3] = 1; // get current position
  186546. s.CDBByte[7] = 0;
  186547. s.CDBByte[8] = (BYTE)sizeof (qdata);
  186548. perform (s);
  186549. if (s.SRB_Status == SS_COMP)
  186550. return qdata[7];
  186551. return 0;
  186552. }
  186553. bool CDDeviceHandle::readTOC (TOC* lpToc, bool useMSF)
  186554. {
  186555. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186556. SRB_ExecSCSICmd s;
  186557. zerostruct (s);
  186558. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186559. s.SRB_HaID = info.ha;
  186560. s.SRB_Target = info.tgt;
  186561. s.SRB_Lun = info.lun;
  186562. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186563. s.SRB_BufLen = 0x324;
  186564. s.SRB_BufPointer = (BYTE*)lpToc;
  186565. s.SRB_SenseLen = 0x0E;
  186566. s.SRB_CDBLen = 0x0A;
  186567. s.SRB_PostProc = (void*)event;
  186568. s.CDBByte[0] = 0x43;
  186569. s.CDBByte[1] = (BYTE)(useMSF ? 0x02 : 0x00);
  186570. s.CDBByte[7] = 0x03;
  186571. s.CDBByte[8] = 0x24;
  186572. ResetEvent (event);
  186573. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  186574. : fSendASPI32Command ((LPSRB)&s);
  186575. if (status == SS_PENDING)
  186576. WaitForSingleObject (event, 4000);
  186577. CloseHandle (event);
  186578. return (s.SRB_Status == SS_COMP);
  186579. }
  186580. bool CDDeviceHandle::readAudio (CDReadBuffer* const buffer,
  186581. CDReadBuffer* const overlapBuffer)
  186582. {
  186583. if (controller == 0)
  186584. {
  186585. testController (READTYPE_ATAPI2, new ControllerType1(), buffer)
  186586. || testController (READTYPE_ATAPI1, new ControllerType1(), buffer)
  186587. || testController (READTYPE_READ10_2, new ControllerType2(), buffer)
  186588. || testController (READTYPE_READ10, new ControllerType2(), buffer)
  186589. || testController (READTYPE_READ_D8, new ControllerType3(), buffer)
  186590. || testController (READTYPE_READ_D4, new ControllerType4(), buffer)
  186591. || testController (READTYPE_READ_D4_1, new ControllerType4(), buffer);
  186592. }
  186593. buffer->index = 0;
  186594. if ((controller != 0)
  186595. && controller->readAudio (buffer, overlapBuffer))
  186596. {
  186597. if (buffer->wantsIndex)
  186598. buffer->index = controller->getLastIndex();
  186599. return true;
  186600. }
  186601. return false;
  186602. }
  186603. void CDDeviceHandle::openDrawer (bool shouldBeOpen)
  186604. {
  186605. if (shouldBeOpen)
  186606. {
  186607. if (controller != 0)
  186608. {
  186609. controller->shutDown();
  186610. controller = 0;
  186611. }
  186612. if (scsiHandle != 0)
  186613. {
  186614. CloseHandle (scsiHandle);
  186615. scsiHandle = 0;
  186616. }
  186617. }
  186618. SRB_ExecSCSICmd s;
  186619. zerostruct (s);
  186620. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186621. s.SRB_HaID = info.ha;
  186622. s.SRB_Target = info.tgt;
  186623. s.SRB_Lun = info.lun;
  186624. s.SRB_SenseLen = SENSE_LEN;
  186625. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186626. s.SRB_BufLen = 0;
  186627. s.SRB_BufPointer = 0;
  186628. s.SRB_CDBLen = 12;
  186629. s.CDBByte[0] = 0x1b;
  186630. s.CDBByte[1] = (BYTE)(info.lun << 5);
  186631. s.CDBByte[4] = (BYTE)((shouldBeOpen) ? 2 : 3);
  186632. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186633. s.SRB_PostProc = (void*)event;
  186634. ResetEvent (event);
  186635. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  186636. : fSendASPI32Command ((LPSRB)&s);
  186637. if (status == SS_PENDING)
  186638. WaitForSingleObject (event, 4000);
  186639. CloseHandle (event);
  186640. }
  186641. bool CDDeviceHandle::testController (const int type,
  186642. CDController* const newController,
  186643. CDReadBuffer* const rb)
  186644. {
  186645. controller = newController;
  186646. readType = (BYTE)type;
  186647. controller->deviceInfo = this;
  186648. controller->framesToCheck = 1;
  186649. controller->framesOverlap = 3;
  186650. bool passed = false;
  186651. memset (rb->buffer, 0xcd, rb->bufferSize);
  186652. if (controller->read (rb))
  186653. {
  186654. passed = true;
  186655. int* p = (int*) (rb->buffer + rb->dataStartOffset);
  186656. int wrong = 0;
  186657. for (int i = rb->dataLength / 4; --i >= 0;)
  186658. {
  186659. if (*p++ == (int) 0xcdcdcdcd)
  186660. {
  186661. if (++wrong == 4)
  186662. {
  186663. passed = false;
  186664. break;
  186665. }
  186666. }
  186667. else
  186668. {
  186669. wrong = 0;
  186670. }
  186671. }
  186672. }
  186673. if (! passed)
  186674. {
  186675. controller->shutDown();
  186676. controller = 0;
  186677. }
  186678. return passed;
  186679. }
  186680. static void GetAspiDeviceInfo (CDDeviceInfo* dev, BYTE ha, BYTE tgt, BYTE lun)
  186681. {
  186682. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186683. const int bufSize = 128;
  186684. BYTE buffer[bufSize];
  186685. zeromem (buffer, bufSize);
  186686. SRB_ExecSCSICmd s;
  186687. zerostruct (s);
  186688. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186689. s.SRB_HaID = ha;
  186690. s.SRB_Target = tgt;
  186691. s.SRB_Lun = lun;
  186692. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186693. s.SRB_BufLen = bufSize;
  186694. s.SRB_BufPointer = buffer;
  186695. s.SRB_SenseLen = SENSE_LEN;
  186696. s.SRB_CDBLen = 6;
  186697. s.SRB_PostProc = (void*)event;
  186698. s.CDBByte[0] = SCSI_INQUIRY;
  186699. s.CDBByte[4] = 100;
  186700. ResetEvent (event);
  186701. if (fSendASPI32Command ((LPSRB)&s) == SS_PENDING)
  186702. WaitForSingleObject (event, 4000);
  186703. CloseHandle (event);
  186704. if (s.SRB_Status == SS_COMP)
  186705. {
  186706. memcpy (dev->vendor, &buffer[8], 8);
  186707. memcpy (dev->productId, &buffer[16], 16);
  186708. memcpy (dev->rev, &buffer[32], 4);
  186709. memcpy (dev->vendorSpec, &buffer[36], 20);
  186710. }
  186711. }
  186712. static int FindCDDevices (CDDeviceInfo* const list,
  186713. int maxItems)
  186714. {
  186715. int count = 0;
  186716. if (usingScsi)
  186717. {
  186718. for (char driveLetter = 'b'; driveLetter <= 'z'; ++driveLetter)
  186719. {
  186720. TCHAR drivePath[8];
  186721. drivePath[0] = driveLetter;
  186722. drivePath[1] = ':';
  186723. drivePath[2] = '\\';
  186724. drivePath[3] = 0;
  186725. if (GetDriveType (drivePath) == DRIVE_CDROM)
  186726. {
  186727. HANDLE h = CreateSCSIDeviceHandle (driveLetter);
  186728. if (h != INVALID_HANDLE_VALUE)
  186729. {
  186730. BYTE buffer[100], passThroughStruct[1024];
  186731. zeromem (buffer, sizeof (buffer));
  186732. zeromem (passThroughStruct, sizeof (passThroughStruct));
  186733. PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER p = (PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER)passThroughStruct;
  186734. p->spt.Length = sizeof (SCSI_PASS_THROUGH);
  186735. p->spt.CdbLength = 6;
  186736. p->spt.SenseInfoLength = 24;
  186737. p->spt.DataIn = SCSI_IOCTL_DATA_IN;
  186738. p->spt.DataTransferLength = 100;
  186739. p->spt.TimeOutValue = 2;
  186740. p->spt.DataBuffer = buffer;
  186741. p->spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  186742. p->spt.Cdb[0] = 0x12;
  186743. p->spt.Cdb[4] = 100;
  186744. DWORD bytesReturned = 0;
  186745. if (DeviceIoControl (h, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  186746. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  186747. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  186748. &bytesReturned, 0) != 0)
  186749. {
  186750. zeromem (&list[count], sizeof (CDDeviceInfo));
  186751. list[count].scsiDriveLetter = driveLetter;
  186752. memcpy (list[count].vendor, &buffer[8], 8);
  186753. memcpy (list[count].productId, &buffer[16], 16);
  186754. memcpy (list[count].rev, &buffer[32], 4);
  186755. memcpy (list[count].vendorSpec, &buffer[36], 20);
  186756. zeromem (passThroughStruct, sizeof (passThroughStruct));
  186757. PSCSI_ADDRESS scsiAddr = (PSCSI_ADDRESS)passThroughStruct;
  186758. scsiAddr->Length = sizeof (SCSI_ADDRESS);
  186759. if (DeviceIoControl (h, IOCTL_SCSI_GET_ADDRESS,
  186760. 0, 0, scsiAddr, sizeof (SCSI_ADDRESS),
  186761. &bytesReturned, 0) != 0)
  186762. {
  186763. list[count].ha = scsiAddr->PortNumber;
  186764. list[count].tgt = scsiAddr->TargetId;
  186765. list[count].lun = scsiAddr->Lun;
  186766. ++count;
  186767. }
  186768. }
  186769. CloseHandle (h);
  186770. }
  186771. }
  186772. }
  186773. }
  186774. else
  186775. {
  186776. const DWORD d = fGetASPI32SupportInfo();
  186777. BYTE status = HIBYTE (LOWORD (d));
  186778. if (status != SS_COMP || status == SS_NO_ADAPTERS)
  186779. return 0;
  186780. const int numAdapters = LOBYTE (LOWORD (d));
  186781. for (BYTE ha = 0; ha < numAdapters; ++ha)
  186782. {
  186783. SRB_HAInquiry s;
  186784. zerostruct (s);
  186785. s.SRB_Cmd = SC_HA_INQUIRY;
  186786. s.SRB_HaID = ha;
  186787. fSendASPI32Command ((LPSRB)&s);
  186788. if (s.SRB_Status == SS_COMP)
  186789. {
  186790. maxItems = (int)s.HA_Unique[3];
  186791. if (maxItems == 0)
  186792. maxItems = 8;
  186793. for (BYTE tgt = 0; tgt < maxItems; ++tgt)
  186794. {
  186795. for (BYTE lun = 0; lun < 8; ++lun)
  186796. {
  186797. SRB_GDEVBlock sb;
  186798. zerostruct (sb);
  186799. sb.SRB_Cmd = SC_GET_DEV_TYPE;
  186800. sb.SRB_HaID = ha;
  186801. sb.SRB_Target = tgt;
  186802. sb.SRB_Lun = lun;
  186803. fSendASPI32Command ((LPSRB) &sb);
  186804. if (sb.SRB_Status == SS_COMP
  186805. && sb.SRB_DeviceType == DTYPE_CROM)
  186806. {
  186807. zeromem (&list[count], sizeof (CDDeviceInfo));
  186808. list[count].ha = ha;
  186809. list[count].tgt = tgt;
  186810. list[count].lun = lun;
  186811. GetAspiDeviceInfo (&(list[count]), ha, tgt, lun);
  186812. ++count;
  186813. }
  186814. }
  186815. }
  186816. }
  186817. }
  186818. }
  186819. return count;
  186820. }
  186821. static int ripperUsers = 0;
  186822. static bool initialisedOk = false;
  186823. class DeinitialiseTimer : private Timer,
  186824. private DeletedAtShutdown
  186825. {
  186826. DeinitialiseTimer (const DeinitialiseTimer&);
  186827. DeinitialiseTimer& operator= (const DeinitialiseTimer&);
  186828. public:
  186829. DeinitialiseTimer()
  186830. {
  186831. startTimer (4000);
  186832. }
  186833. ~DeinitialiseTimer()
  186834. {
  186835. if (--ripperUsers == 0)
  186836. DeinitialiseCDRipper();
  186837. }
  186838. void timerCallback()
  186839. {
  186840. delete this;
  186841. }
  186842. juce_UseDebuggingNewOperator
  186843. };
  186844. static void incUserCount()
  186845. {
  186846. if (ripperUsers++ == 0)
  186847. initialisedOk = InitialiseCDRipper();
  186848. }
  186849. static void decUserCount()
  186850. {
  186851. new DeinitialiseTimer();
  186852. }
  186853. struct CDDeviceWrapper
  186854. {
  186855. ScopedPointer<CDDeviceHandle> cdH;
  186856. ScopedPointer<CDReadBuffer> overlapBuffer;
  186857. bool jitter;
  186858. };
  186859. static int getAddressOf (const TOCTRACK* const t)
  186860. {
  186861. return (((DWORD)t->addr[0]) << 24) + (((DWORD)t->addr[1]) << 16) +
  186862. (((DWORD)t->addr[2]) << 8) + ((DWORD)t->addr[3]);
  186863. }
  186864. static int getMSFAddressOf (const TOCTRACK* const t)
  186865. {
  186866. return 60 * t->addr[1] + t->addr[2];
  186867. }
  186868. static const int samplesPerFrame = 44100 / 75;
  186869. static const int bytesPerFrame = samplesPerFrame * 4;
  186870. static CDDeviceHandle* openHandle (const CDDeviceInfo* const device)
  186871. {
  186872. SRB_GDEVBlock s;
  186873. zerostruct (s);
  186874. s.SRB_Cmd = SC_GET_DEV_TYPE;
  186875. s.SRB_HaID = device->ha;
  186876. s.SRB_Target = device->tgt;
  186877. s.SRB_Lun = device->lun;
  186878. if (usingScsi)
  186879. {
  186880. HANDLE h = CreateSCSIDeviceHandle (device->scsiDriveLetter);
  186881. if (h != INVALID_HANDLE_VALUE)
  186882. {
  186883. CDDeviceHandle* cdh = new CDDeviceHandle (device);
  186884. cdh->scsiHandle = h;
  186885. return cdh;
  186886. }
  186887. }
  186888. else
  186889. {
  186890. if (fSendASPI32Command ((LPSRB)&s) == SS_COMP
  186891. && s.SRB_DeviceType == DTYPE_CROM)
  186892. {
  186893. return new CDDeviceHandle (device);
  186894. }
  186895. }
  186896. return 0;
  186897. }
  186898. }
  186899. const StringArray AudioCDReader::getAvailableCDNames()
  186900. {
  186901. using namespace CDReaderHelpers;
  186902. StringArray results;
  186903. incUserCount();
  186904. if (initialisedOk)
  186905. {
  186906. CDDeviceInfo list[8];
  186907. const int num = FindCDDevices (list, 8);
  186908. decUserCount();
  186909. for (int i = 0; i < num; ++i)
  186910. {
  186911. String s;
  186912. if (list[i].scsiDriveLetter > 0)
  186913. s << String::charToString (list[i].scsiDriveLetter).toUpperCase() << ": ";
  186914. s << String (list[i].vendor).trim()
  186915. << ' ' << String (list[i].productId).trim()
  186916. << ' ' << String (list[i].rev).trim();
  186917. results.add (s);
  186918. }
  186919. }
  186920. return results;
  186921. }
  186922. AudioCDReader* AudioCDReader::createReaderForCD (const int deviceIndex)
  186923. {
  186924. using namespace CDReaderHelpers;
  186925. incUserCount();
  186926. if (initialisedOk)
  186927. {
  186928. CDDeviceInfo list[8];
  186929. const int num = FindCDDevices (list, 8);
  186930. if (((unsigned int) deviceIndex) < (unsigned int) num)
  186931. {
  186932. CDDeviceHandle* const handle = openHandle (&(list[deviceIndex]));
  186933. if (handle != 0)
  186934. {
  186935. CDDeviceWrapper* const d = new CDDeviceWrapper();
  186936. d->cdH = handle;
  186937. d->overlapBuffer = new CDReadBuffer(3);
  186938. return new AudioCDReader (d);
  186939. }
  186940. }
  186941. }
  186942. decUserCount();
  186943. return 0;
  186944. }
  186945. AudioCDReader::AudioCDReader (void* handle_)
  186946. : AudioFormatReader (0, "CD Audio"),
  186947. handle (handle_),
  186948. indexingEnabled (false),
  186949. lastIndex (0),
  186950. firstFrameInBuffer (0),
  186951. samplesInBuffer (0)
  186952. {
  186953. using namespace CDReaderHelpers;
  186954. jassert (handle_ != 0);
  186955. refreshTrackLengths();
  186956. sampleRate = 44100.0;
  186957. bitsPerSample = 16;
  186958. lengthInSamples = getPositionOfTrackStart (numTracks);
  186959. numChannels = 2;
  186960. usesFloatingPointData = false;
  186961. buffer.setSize (4 * bytesPerFrame, true);
  186962. }
  186963. AudioCDReader::~AudioCDReader()
  186964. {
  186965. using namespace CDReaderHelpers;
  186966. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  186967. delete device;
  186968. decUserCount();
  186969. }
  186970. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  186971. int64 startSampleInFile, int numSamples)
  186972. {
  186973. using namespace CDReaderHelpers;
  186974. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  186975. bool ok = true;
  186976. while (numSamples > 0)
  186977. {
  186978. const int bufferStartSample = firstFrameInBuffer * samplesPerFrame;
  186979. const int bufferEndSample = bufferStartSample + samplesInBuffer;
  186980. if (startSampleInFile >= bufferStartSample
  186981. && startSampleInFile < bufferEndSample)
  186982. {
  186983. const int toDo = (int) jmin ((int64) numSamples, bufferEndSample - startSampleInFile);
  186984. int* const l = destSamples[0] + startOffsetInDestBuffer;
  186985. int* const r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  186986. const short* src = (const short*) buffer.getData();
  186987. src += 2 * (startSampleInFile - bufferStartSample);
  186988. for (int i = 0; i < toDo; ++i)
  186989. {
  186990. l[i] = src [i << 1] << 16;
  186991. if (r != 0)
  186992. r[i] = src [(i << 1) + 1] << 16;
  186993. }
  186994. startOffsetInDestBuffer += toDo;
  186995. startSampleInFile += toDo;
  186996. numSamples -= toDo;
  186997. }
  186998. else
  186999. {
  187000. const int framesInBuffer = buffer.getSize() / bytesPerFrame;
  187001. const int frameNeeded = (int) (startSampleInFile / samplesPerFrame);
  187002. if (firstFrameInBuffer + framesInBuffer != frameNeeded)
  187003. {
  187004. device->overlapBuffer->dataLength = 0;
  187005. device->overlapBuffer->startFrame = 0;
  187006. device->overlapBuffer->numFrames = 0;
  187007. device->jitter = false;
  187008. }
  187009. firstFrameInBuffer = frameNeeded;
  187010. lastIndex = 0;
  187011. CDReadBuffer readBuffer (framesInBuffer + 4);
  187012. readBuffer.wantsIndex = indexingEnabled;
  187013. int i;
  187014. for (i = 5; --i >= 0;)
  187015. {
  187016. readBuffer.startFrame = frameNeeded;
  187017. readBuffer.numFrames = framesInBuffer;
  187018. if (device->cdH->readAudio (&readBuffer, (device->jitter) ? device->overlapBuffer : 0))
  187019. break;
  187020. else
  187021. device->overlapBuffer->dataLength = 0;
  187022. }
  187023. if (i >= 0)
  187024. {
  187025. memcpy ((char*) buffer.getData(),
  187026. readBuffer.buffer + readBuffer.dataStartOffset,
  187027. readBuffer.dataLength);
  187028. samplesInBuffer = readBuffer.dataLength >> 2;
  187029. lastIndex = readBuffer.index;
  187030. }
  187031. else
  187032. {
  187033. int* l = destSamples[0] + startOffsetInDestBuffer;
  187034. int* r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  187035. while (--numSamples >= 0)
  187036. {
  187037. *l++ = 0;
  187038. if (r != 0)
  187039. *r++ = 0;
  187040. }
  187041. // sometimes the read fails for just the very last couple of blocks, so
  187042. // we'll ignore and errors in the last half-second of the disk..
  187043. ok = startSampleInFile > (trackStarts [numTracks] - 20000);
  187044. break;
  187045. }
  187046. }
  187047. }
  187048. return ok;
  187049. }
  187050. bool AudioCDReader::isCDStillPresent() const
  187051. {
  187052. using namespace CDReaderHelpers;
  187053. TOC toc;
  187054. zerostruct (toc);
  187055. return ((CDDeviceWrapper*) handle)->cdH->readTOC (&toc, false);
  187056. }
  187057. int AudioCDReader::getNumTracks() const
  187058. {
  187059. return numTracks;
  187060. }
  187061. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  187062. {
  187063. using namespace CDReaderHelpers;
  187064. return (trackNum >= 0 && trackNum <= numTracks) ? trackStarts [trackNum] * samplesPerFrame
  187065. : 0;
  187066. }
  187067. void AudioCDReader::refreshTrackLengths()
  187068. {
  187069. using namespace CDReaderHelpers;
  187070. zeromem (trackStarts, sizeof (trackStarts));
  187071. zeromem (audioTracks, sizeof (audioTracks));
  187072. TOC toc;
  187073. zerostruct (toc);
  187074. if (((CDDeviceWrapper*)handle)->cdH->readTOC (&toc, false))
  187075. {
  187076. numTracks = 1 + toc.lastTrack - toc.firstTrack;
  187077. for (int i = 0; i <= numTracks; ++i)
  187078. {
  187079. trackStarts[i] = getAddressOf (&toc.tracks[i]);
  187080. audioTracks[i] = ((toc.tracks[i].ADR & 4) == 0);
  187081. }
  187082. }
  187083. else
  187084. {
  187085. numTracks = 0;
  187086. }
  187087. }
  187088. bool AudioCDReader::isTrackAudio (int trackNum) const
  187089. {
  187090. return (trackNum >= 0 && trackNum <= numTracks) ? audioTracks [trackNum]
  187091. : false;
  187092. }
  187093. void AudioCDReader::enableIndexScanning (bool b)
  187094. {
  187095. indexingEnabled = b;
  187096. }
  187097. int AudioCDReader::getLastIndex() const
  187098. {
  187099. return lastIndex;
  187100. }
  187101. const int framesPerIndexRead = 4;
  187102. int AudioCDReader::getIndexAt (int samplePos)
  187103. {
  187104. using namespace CDReaderHelpers;
  187105. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187106. const int frameNeeded = samplePos / samplesPerFrame;
  187107. device->overlapBuffer->dataLength = 0;
  187108. device->overlapBuffer->startFrame = 0;
  187109. device->overlapBuffer->numFrames = 0;
  187110. device->jitter = false;
  187111. firstFrameInBuffer = 0;
  187112. lastIndex = 0;
  187113. CDReadBuffer readBuffer (4 + framesPerIndexRead);
  187114. readBuffer.wantsIndex = true;
  187115. int i;
  187116. for (i = 5; --i >= 0;)
  187117. {
  187118. readBuffer.startFrame = frameNeeded;
  187119. readBuffer.numFrames = framesPerIndexRead;
  187120. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187121. break;
  187122. }
  187123. if (i >= 0)
  187124. return readBuffer.index;
  187125. return -1;
  187126. }
  187127. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  187128. {
  187129. using namespace CDReaderHelpers;
  187130. Array <int> indexes;
  187131. const int trackStart = getPositionOfTrackStart (trackNumber);
  187132. const int trackEnd = getPositionOfTrackStart (trackNumber + 1);
  187133. bool needToScan = true;
  187134. if (trackEnd - trackStart > 20 * 44100)
  187135. {
  187136. // check the end of the track for indexes before scanning the whole thing
  187137. needToScan = false;
  187138. int pos = jmax (trackStart, trackEnd - 44100 * 5);
  187139. bool seenAnIndex = false;
  187140. while (pos <= trackEnd - samplesPerFrame)
  187141. {
  187142. const int index = getIndexAt (pos);
  187143. if (index == 0)
  187144. {
  187145. // lead-out, so skip back a bit if we've not found any indexes yet..
  187146. if (seenAnIndex)
  187147. break;
  187148. pos -= 44100 * 5;
  187149. if (pos < trackStart)
  187150. break;
  187151. }
  187152. else
  187153. {
  187154. if (index > 0)
  187155. seenAnIndex = true;
  187156. if (index > 1)
  187157. {
  187158. needToScan = true;
  187159. break;
  187160. }
  187161. pos += samplesPerFrame * framesPerIndexRead;
  187162. }
  187163. }
  187164. }
  187165. if (needToScan)
  187166. {
  187167. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187168. int pos = trackStart;
  187169. int last = -1;
  187170. while (pos < trackEnd - samplesPerFrame * 10)
  187171. {
  187172. const int frameNeeded = pos / samplesPerFrame;
  187173. device->overlapBuffer->dataLength = 0;
  187174. device->overlapBuffer->startFrame = 0;
  187175. device->overlapBuffer->numFrames = 0;
  187176. device->jitter = false;
  187177. firstFrameInBuffer = 0;
  187178. CDReadBuffer readBuffer (4);
  187179. readBuffer.wantsIndex = true;
  187180. int i;
  187181. for (i = 5; --i >= 0;)
  187182. {
  187183. readBuffer.startFrame = frameNeeded;
  187184. readBuffer.numFrames = framesPerIndexRead;
  187185. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187186. break;
  187187. }
  187188. if (i < 0)
  187189. break;
  187190. if (readBuffer.index > last && readBuffer.index > 1)
  187191. {
  187192. last = readBuffer.index;
  187193. indexes.add (pos);
  187194. }
  187195. pos += samplesPerFrame * framesPerIndexRead;
  187196. }
  187197. indexes.removeValue (trackStart);
  187198. }
  187199. return indexes;
  187200. }
  187201. int AudioCDReader::getCDDBId()
  187202. {
  187203. using namespace CDReaderHelpers;
  187204. refreshTrackLengths();
  187205. if (numTracks > 0)
  187206. {
  187207. TOC toc;
  187208. zerostruct (toc);
  187209. if (((CDDeviceWrapper*) handle)->cdH->readTOC (&toc, true))
  187210. {
  187211. int n = 0;
  187212. for (int i = numTracks; --i >= 0;)
  187213. {
  187214. int j = getMSFAddressOf (&toc.tracks[i]);
  187215. while (j > 0)
  187216. {
  187217. n += (j % 10);
  187218. j /= 10;
  187219. }
  187220. }
  187221. if (n != 0)
  187222. {
  187223. const int t = getMSFAddressOf (&toc.tracks[numTracks])
  187224. - getMSFAddressOf (&toc.tracks[0]);
  187225. return ((n % 0xff) << 24) | (t << 8) | numTracks;
  187226. }
  187227. }
  187228. }
  187229. return 0;
  187230. }
  187231. void AudioCDReader::ejectDisk()
  187232. {
  187233. using namespace CDReaderHelpers;
  187234. ((CDDeviceWrapper*) handle)->cdH->openDrawer (true);
  187235. }
  187236. #endif
  187237. #if JUCE_USE_CDBURNER
  187238. static IDiscRecorder* enumCDBurners (StringArray* list, int indexToOpen, IDiscMaster** master)
  187239. {
  187240. CoInitialize (0);
  187241. IDiscMaster* dm;
  187242. IDiscRecorder* result = 0;
  187243. if (SUCCEEDED (CoCreateInstance (CLSID_MSDiscMasterObj, 0,
  187244. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
  187245. IID_IDiscMaster,
  187246. (void**) &dm)))
  187247. {
  187248. if (SUCCEEDED (dm->Open()))
  187249. {
  187250. IEnumDiscRecorders* drEnum = 0;
  187251. if (SUCCEEDED (dm->EnumDiscRecorders (&drEnum)))
  187252. {
  187253. IDiscRecorder* dr = 0;
  187254. DWORD dummy;
  187255. int index = 0;
  187256. while (drEnum->Next (1, &dr, &dummy) == S_OK)
  187257. {
  187258. if (indexToOpen == index)
  187259. {
  187260. result = dr;
  187261. break;
  187262. }
  187263. else if (list != 0)
  187264. {
  187265. BSTR path;
  187266. if (SUCCEEDED (dr->GetPath (&path)))
  187267. list->add ((const WCHAR*) path);
  187268. }
  187269. ++index;
  187270. dr->Release();
  187271. }
  187272. drEnum->Release();
  187273. }
  187274. if (master == 0)
  187275. dm->Close();
  187276. }
  187277. if (master != 0)
  187278. *master = dm;
  187279. else
  187280. dm->Release();
  187281. }
  187282. return result;
  187283. }
  187284. class AudioCDBurner::Pimpl : public IDiscMasterProgressEvents,
  187285. public Timer
  187286. {
  187287. public:
  187288. Pimpl (AudioCDBurner& owner_, IDiscMaster* discMaster_, IDiscRecorder* discRecorder_)
  187289. : owner (owner_), discMaster (discMaster_), discRecorder (discRecorder_), redbook (0),
  187290. listener (0), progress (0), shouldCancel (false), refCount (1)
  187291. {
  187292. HRESULT hr = discMaster->SetActiveDiscMasterFormat (IID_IRedbookDiscMaster, (void**) &redbook);
  187293. jassert (SUCCEEDED (hr));
  187294. hr = discMaster->SetActiveDiscRecorder (discRecorder);
  187295. //jassert (SUCCEEDED (hr));
  187296. lastState = getDiskState();
  187297. startTimer (2000);
  187298. }
  187299. ~Pimpl() {}
  187300. void releaseObjects()
  187301. {
  187302. discRecorder->Close();
  187303. if (redbook != 0)
  187304. redbook->Release();
  187305. discRecorder->Release();
  187306. discMaster->Release();
  187307. Release();
  187308. }
  187309. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  187310. {
  187311. if (result == 0)
  187312. return E_POINTER;
  187313. if (id == IID_IUnknown || id == IID_IDiscMasterProgressEvents)
  187314. {
  187315. AddRef();
  187316. *result = this;
  187317. return S_OK;
  187318. }
  187319. *result = 0;
  187320. return E_NOINTERFACE;
  187321. }
  187322. ULONG __stdcall AddRef() { return ++refCount; }
  187323. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  187324. HRESULT __stdcall QueryCancel (boolean* pbCancel)
  187325. {
  187326. if (listener != 0 && ! shouldCancel)
  187327. shouldCancel = listener->audioCDBurnProgress (progress);
  187328. *pbCancel = shouldCancel;
  187329. return S_OK;
  187330. }
  187331. HRESULT __stdcall NotifyBlockProgress (long nCompleted, long nTotal)
  187332. {
  187333. progress = nCompleted / (float) nTotal;
  187334. shouldCancel = listener != 0 && listener->audioCDBurnProgress (progress);
  187335. return E_NOTIMPL;
  187336. }
  187337. HRESULT __stdcall NotifyPnPActivity (void) { return E_NOTIMPL; }
  187338. HRESULT __stdcall NotifyAddProgress (long /*nCompletedSteps*/, long /*nTotalSteps*/) { return E_NOTIMPL; }
  187339. HRESULT __stdcall NotifyTrackProgress (long /*nCurrentTrack*/, long /*nTotalTracks*/) { return E_NOTIMPL; }
  187340. HRESULT __stdcall NotifyPreparingBurn (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187341. HRESULT __stdcall NotifyClosingDisc (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187342. HRESULT __stdcall NotifyBurnComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187343. HRESULT __stdcall NotifyEraseComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187344. class ScopedDiscOpener
  187345. {
  187346. public:
  187347. ScopedDiscOpener (Pimpl& p) : pimpl (p) { pimpl.discRecorder->OpenExclusive(); }
  187348. ~ScopedDiscOpener() { pimpl.discRecorder->Close(); }
  187349. private:
  187350. Pimpl& pimpl;
  187351. ScopedDiscOpener (const ScopedDiscOpener&);
  187352. ScopedDiscOpener& operator= (const ScopedDiscOpener&);
  187353. };
  187354. DiskState getDiskState()
  187355. {
  187356. const ScopedDiscOpener opener (*this);
  187357. long type, flags;
  187358. HRESULT hr = discRecorder->QueryMediaType (&type, &flags);
  187359. if (FAILED (hr))
  187360. return unknown;
  187361. if (type != 0 && (flags & MEDIA_WRITABLE) != 0)
  187362. return writableDiskPresent;
  187363. if (type == 0)
  187364. return noDisc;
  187365. else
  187366. return readOnlyDiskPresent;
  187367. }
  187368. int getIntProperty (const LPOLESTR name, const int defaultReturn) const
  187369. {
  187370. ComSmartPtr<IPropertyStorage> prop;
  187371. if (FAILED (discRecorder->GetRecorderProperties (&prop)))
  187372. return defaultReturn;
  187373. PROPSPEC iPropSpec;
  187374. iPropSpec.ulKind = PRSPEC_LPWSTR;
  187375. iPropSpec.lpwstr = name;
  187376. PROPVARIANT iPropVariant;
  187377. return FAILED (prop->ReadMultiple (1, &iPropSpec, &iPropVariant))
  187378. ? defaultReturn : (int) iPropVariant.lVal;
  187379. }
  187380. bool setIntProperty (const LPOLESTR name, const int value) const
  187381. {
  187382. ComSmartPtr<IPropertyStorage> prop;
  187383. if (FAILED (discRecorder->GetRecorderProperties (&prop)))
  187384. return false;
  187385. PROPSPEC iPropSpec;
  187386. iPropSpec.ulKind = PRSPEC_LPWSTR;
  187387. iPropSpec.lpwstr = name;
  187388. PROPVARIANT iPropVariant;
  187389. if (FAILED (prop->ReadMultiple (1, &iPropSpec, &iPropVariant)))
  187390. return false;
  187391. iPropVariant.lVal = (long) value;
  187392. return SUCCEEDED (prop->WriteMultiple (1, &iPropSpec, &iPropVariant, iPropVariant.vt))
  187393. && SUCCEEDED (discRecorder->SetRecorderProperties (prop));
  187394. }
  187395. void timerCallback()
  187396. {
  187397. const DiskState state = getDiskState();
  187398. if (state != lastState)
  187399. {
  187400. lastState = state;
  187401. owner.sendChangeMessage (&owner);
  187402. }
  187403. }
  187404. AudioCDBurner& owner;
  187405. DiskState lastState;
  187406. IDiscMaster* discMaster;
  187407. IDiscRecorder* discRecorder;
  187408. IRedbookDiscMaster* redbook;
  187409. AudioCDBurner::BurnProgressListener* listener;
  187410. float progress;
  187411. bool shouldCancel;
  187412. private:
  187413. int refCount;
  187414. };
  187415. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  187416. {
  187417. IDiscMaster* discMaster = 0;
  187418. IDiscRecorder* discRecorder = enumCDBurners (0, deviceIndex, &discMaster);
  187419. if (discRecorder != 0)
  187420. pimpl = new Pimpl (*this, discMaster, discRecorder);
  187421. }
  187422. AudioCDBurner::~AudioCDBurner()
  187423. {
  187424. if (pimpl != 0)
  187425. pimpl.release()->releaseObjects();
  187426. }
  187427. const StringArray AudioCDBurner::findAvailableDevices()
  187428. {
  187429. StringArray devs;
  187430. enumCDBurners (&devs, -1, 0);
  187431. return devs;
  187432. }
  187433. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  187434. {
  187435. ScopedPointer<AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  187436. if (b->pimpl == 0)
  187437. b = 0;
  187438. return b.release();
  187439. }
  187440. AudioCDBurner::DiskState AudioCDBurner::getDiskState() const
  187441. {
  187442. return pimpl->getDiskState();
  187443. }
  187444. bool AudioCDBurner::isDiskPresent() const
  187445. {
  187446. return getDiskState() == writableDiskPresent;
  187447. }
  187448. bool AudioCDBurner::openTray()
  187449. {
  187450. const Pimpl::ScopedDiscOpener opener (*pimpl);
  187451. return SUCCEEDED (pimpl->discRecorder->Eject());
  187452. }
  187453. AudioCDBurner::DiskState AudioCDBurner::waitUntilStateChange (int timeOutMilliseconds)
  187454. {
  187455. const int64 timeout = Time::currentTimeMillis() + timeOutMilliseconds;
  187456. DiskState oldState = getDiskState();
  187457. DiskState newState = oldState;
  187458. while (newState == oldState && Time::currentTimeMillis() < timeout)
  187459. {
  187460. newState = getDiskState();
  187461. Thread::sleep (jmin (250, (int) (timeout - Time::currentTimeMillis())));
  187462. }
  187463. return newState;
  187464. }
  187465. const Array<int> AudioCDBurner::getAvailableWriteSpeeds() const
  187466. {
  187467. Array<int> results;
  187468. const int maxSpeed = pimpl->getIntProperty (L"MaxWriteSpeed", 1);
  187469. const int speeds[] = { 1, 2, 4, 8, 12, 16, 20, 24, 32, 40, 64, 80 };
  187470. for (int i = 0; i < numElementsInArray (speeds); ++i)
  187471. if (speeds[i] <= maxSpeed)
  187472. results.add (speeds[i]);
  187473. results.addIfNotAlreadyThere (maxSpeed);
  187474. return results;
  187475. }
  187476. bool AudioCDBurner::setBufferUnderrunProtection (const bool shouldBeEnabled)
  187477. {
  187478. if (pimpl->getIntProperty (L"BufferUnderrunFreeCapable", 0) == 0)
  187479. return false;
  187480. pimpl->setIntProperty (L"EnableBufferUnderrunFree", shouldBeEnabled ? -1 : 0);
  187481. return pimpl->getIntProperty (L"EnableBufferUnderrunFree", 0) != 0;
  187482. }
  187483. int AudioCDBurner::getNumAvailableAudioBlocks() const
  187484. {
  187485. long blocksFree = 0;
  187486. pimpl->redbook->GetAvailableAudioTrackBlocks (&blocksFree);
  187487. return blocksFree;
  187488. }
  187489. const String AudioCDBurner::burn (AudioCDBurner::BurnProgressListener* listener, bool ejectDiscAfterwards,
  187490. bool performFakeBurnForTesting, int writeSpeed)
  187491. {
  187492. pimpl->setIntProperty (L"WriteSpeed", writeSpeed > 0 ? writeSpeed : -1);
  187493. pimpl->listener = listener;
  187494. pimpl->progress = 0;
  187495. pimpl->shouldCancel = false;
  187496. UINT_PTR cookie;
  187497. HRESULT hr = pimpl->discMaster->ProgressAdvise ((AudioCDBurner::Pimpl*) pimpl, &cookie);
  187498. hr = pimpl->discMaster->RecordDisc (performFakeBurnForTesting,
  187499. ejectDiscAfterwards);
  187500. String error;
  187501. if (hr != S_OK)
  187502. {
  187503. const char* e = "Couldn't open or write to the CD device";
  187504. if (hr == IMAPI_E_USERABORT)
  187505. e = "User cancelled the write operation";
  187506. else if (hr == IMAPI_E_MEDIUM_NOTPRESENT || hr == IMAPI_E_TRACKOPEN)
  187507. e = "No Disk present";
  187508. error = e;
  187509. }
  187510. pimpl->discMaster->ProgressUnadvise (cookie);
  187511. pimpl->listener = 0;
  187512. return error;
  187513. }
  187514. bool AudioCDBurner::addAudioTrack (AudioSource* audioSource, int numSamples)
  187515. {
  187516. if (audioSource == 0)
  187517. return false;
  187518. ScopedPointer<AudioSource> source (audioSource);
  187519. long bytesPerBlock;
  187520. HRESULT hr = pimpl->redbook->GetAudioBlockSize (&bytesPerBlock);
  187521. const int samplesPerBlock = bytesPerBlock / 4;
  187522. bool ok = true;
  187523. hr = pimpl->redbook->CreateAudioTrack ((long) numSamples / (bytesPerBlock * 4));
  187524. HeapBlock <byte> buffer (bytesPerBlock);
  187525. AudioSampleBuffer sourceBuffer (2, samplesPerBlock);
  187526. int samplesDone = 0;
  187527. source->prepareToPlay (samplesPerBlock, 44100.0);
  187528. while (ok)
  187529. {
  187530. {
  187531. AudioSourceChannelInfo info;
  187532. info.buffer = &sourceBuffer;
  187533. info.numSamples = samplesPerBlock;
  187534. info.startSample = 0;
  187535. sourceBuffer.clear();
  187536. source->getNextAudioBlock (info);
  187537. }
  187538. zeromem (buffer, bytesPerBlock);
  187539. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (0, 0),
  187540. buffer, samplesPerBlock, 4);
  187541. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (1, 0),
  187542. buffer + 2, samplesPerBlock, 4);
  187543. hr = pimpl->redbook->AddAudioTrackBlocks (buffer, bytesPerBlock);
  187544. if (FAILED (hr))
  187545. ok = false;
  187546. samplesDone += samplesPerBlock;
  187547. if (samplesDone >= numSamples)
  187548. break;
  187549. }
  187550. hr = pimpl->redbook->CloseAudioTrack();
  187551. return ok && hr == S_OK;
  187552. }
  187553. #endif
  187554. #endif
  187555. /*** End of inlined file: juce_win32_AudioCDReader.cpp ***/
  187556. /*** Start of inlined file: juce_win32_Midi.cpp ***/
  187557. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  187558. // compiled on its own).
  187559. #if JUCE_INCLUDED_FILE
  187560. using ::free;
  187561. namespace MidiConstants
  187562. {
  187563. static const int midiBufferSize = 1024 * 10;
  187564. static const int numInHeaders = 32;
  187565. static const int inBufferSize = 256;
  187566. }
  187567. class MidiInThread : public Thread
  187568. {
  187569. public:
  187570. MidiInThread (MidiInput* const input_,
  187571. MidiInputCallback* const callback_)
  187572. : Thread ("Juce Midi"),
  187573. hIn (0),
  187574. input (input_),
  187575. callback (callback_),
  187576. isStarted (false),
  187577. startTime (0),
  187578. pendingLength(0)
  187579. {
  187580. for (int i = MidiConstants::numInHeaders; --i >= 0;)
  187581. {
  187582. zeromem (&hdr[i], sizeof (MIDIHDR));
  187583. hdr[i].lpData = inData[i];
  187584. hdr[i].dwBufferLength = MidiConstants::inBufferSize;
  187585. }
  187586. };
  187587. ~MidiInThread()
  187588. {
  187589. stop();
  187590. if (hIn != 0)
  187591. {
  187592. int count = 5;
  187593. while (--count >= 0)
  187594. {
  187595. if (midiInClose (hIn) == MMSYSERR_NOERROR)
  187596. break;
  187597. Sleep (20);
  187598. }
  187599. }
  187600. }
  187601. void handle (const uint32 message, const uint32 timeStamp) throw()
  187602. {
  187603. const int byte = message & 0xff;
  187604. if (byte < 0x80)
  187605. return;
  187606. const int numBytes = MidiMessage::getMessageLengthFromFirstByte ((uint8) byte);
  187607. const double time = timeStampToTime (timeStamp);
  187608. {
  187609. const ScopedLock sl (lock);
  187610. if (pendingLength < MidiConstants::midiBufferSize - 12)
  187611. {
  187612. char* const p = pending + pendingLength;
  187613. *(double*) p = time;
  187614. *(uint32*) (p + 8) = numBytes;
  187615. *(uint32*) (p + 12) = message;
  187616. pendingLength += 12 + numBytes;
  187617. }
  187618. else
  187619. {
  187620. jassertfalse // midi buffer overflow! You might need to increase the size..
  187621. }
  187622. }
  187623. notify();
  187624. }
  187625. void handleSysEx (MIDIHDR* const hdr, const uint32 timeStamp) throw()
  187626. {
  187627. const int num = hdr->dwBytesRecorded;
  187628. if (num > 0)
  187629. {
  187630. const double time = timeStampToTime (timeStamp);
  187631. {
  187632. const ScopedLock sl (lock);
  187633. if (pendingLength < MidiConstants::midiBufferSize - (8 + num))
  187634. {
  187635. char* const p = pending + pendingLength;
  187636. *(double*) p = time;
  187637. *(uint32*) (p + 8) = num;
  187638. memcpy (p + 12, hdr->lpData, num);
  187639. pendingLength += 12 + num;
  187640. }
  187641. else
  187642. {
  187643. jassertfalse // midi buffer overflow! You might need to increase the size..
  187644. }
  187645. }
  187646. notify();
  187647. }
  187648. }
  187649. void writeBlock (const int i) throw()
  187650. {
  187651. hdr[i].dwBytesRecorded = 0;
  187652. MMRESULT res = midiInPrepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  187653. jassert (res == MMSYSERR_NOERROR);
  187654. res = midiInAddBuffer (hIn, &hdr[i], sizeof (MIDIHDR));
  187655. jassert (res == MMSYSERR_NOERROR);
  187656. }
  187657. void run()
  187658. {
  187659. MemoryBlock pendingCopy (64);
  187660. while (! threadShouldExit())
  187661. {
  187662. for (int i = 0; i < MidiConstants::numInHeaders; ++i)
  187663. {
  187664. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  187665. {
  187666. MMRESULT res = midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  187667. (void) res;
  187668. jassert (res == MMSYSERR_NOERROR);
  187669. writeBlock (i);
  187670. }
  187671. }
  187672. int len;
  187673. {
  187674. const ScopedLock sl (lock);
  187675. len = pendingLength;
  187676. if (len > 0)
  187677. {
  187678. pendingCopy.ensureSize (len);
  187679. pendingCopy.copyFrom (pending, 0, len);
  187680. pendingLength = 0;
  187681. }
  187682. }
  187683. //xxx needs to figure out if blocks are broken up or not
  187684. if (len == 0)
  187685. {
  187686. wait (500);
  187687. }
  187688. else
  187689. {
  187690. const char* p = (const char*) pendingCopy.getData();
  187691. while (len > 0)
  187692. {
  187693. const double time = *(const double*) p;
  187694. const int messageLen = *(const int*) (p + 8);
  187695. const MidiMessage message ((const uint8*) (p + 12), messageLen, time);
  187696. callback->handleIncomingMidiMessage (input, message);
  187697. p += 12 + messageLen;
  187698. len -= 12 + messageLen;
  187699. }
  187700. }
  187701. }
  187702. }
  187703. void start() throw()
  187704. {
  187705. jassert (hIn != 0);
  187706. if (hIn != 0 && ! isStarted)
  187707. {
  187708. stop();
  187709. activeMidiThreads.addIfNotAlreadyThere (this);
  187710. int i;
  187711. for (i = 0; i < MidiConstants::numInHeaders; ++i)
  187712. writeBlock (i);
  187713. startTime = Time::getMillisecondCounter();
  187714. MMRESULT res = midiInStart (hIn);
  187715. jassert (res == MMSYSERR_NOERROR);
  187716. if (res == MMSYSERR_NOERROR)
  187717. {
  187718. isStarted = true;
  187719. pendingLength = 0;
  187720. startThread (6);
  187721. }
  187722. }
  187723. }
  187724. void stop() throw()
  187725. {
  187726. if (isStarted)
  187727. {
  187728. stopThread (5000);
  187729. midiInReset (hIn);
  187730. midiInStop (hIn);
  187731. activeMidiThreads.removeValue (this);
  187732. { const ScopedLock sl (lock); }
  187733. for (int i = MidiConstants::numInHeaders; --i >= 0;)
  187734. {
  187735. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  187736. {
  187737. int c = 10;
  187738. while (--c >= 0 && midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR)) == MIDIERR_STILLPLAYING)
  187739. Sleep (20);
  187740. jassert (c >= 0);
  187741. }
  187742. }
  187743. isStarted = false;
  187744. pendingLength = 0;
  187745. }
  187746. }
  187747. static void CALLBACK midiInCallback (HMIDIIN, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR midiMessage, DWORD_PTR timeStamp)
  187748. {
  187749. MidiInThread* const thread = reinterpret_cast <MidiInThread*> (dwInstance);
  187750. if (thread != 0 && activeMidiThreads.contains (thread))
  187751. {
  187752. if (uMsg == MIM_DATA)
  187753. thread->handle ((uint32) midiMessage, (uint32) timeStamp);
  187754. else if (uMsg == MIM_LONGDATA)
  187755. thread->handleSysEx ((MIDIHDR*) midiMessage, (uint32) timeStamp);
  187756. }
  187757. }
  187758. juce_UseDebuggingNewOperator
  187759. HMIDIIN hIn;
  187760. private:
  187761. static Array <void*, CriticalSection> activeMidiThreads;
  187762. MidiInput* input;
  187763. MidiInputCallback* callback;
  187764. bool isStarted;
  187765. uint32 startTime;
  187766. CriticalSection lock;
  187767. MIDIHDR hdr [MidiConstants::numInHeaders];
  187768. char inData [MidiConstants::numInHeaders] [MidiConstants::inBufferSize];
  187769. int pendingLength;
  187770. char pending [MidiConstants::midiBufferSize];
  187771. double timeStampToTime (uint32 timeStamp) throw()
  187772. {
  187773. timeStamp += startTime;
  187774. const uint32 now = Time::getMillisecondCounter();
  187775. if (timeStamp > now)
  187776. {
  187777. if (timeStamp > now + 2)
  187778. --startTime;
  187779. timeStamp = now;
  187780. }
  187781. return 0.001 * timeStamp;
  187782. }
  187783. MidiInThread (const MidiInThread&);
  187784. MidiInThread& operator= (const MidiInThread&);
  187785. };
  187786. Array <void*, CriticalSection> MidiInThread::activeMidiThreads;
  187787. const StringArray MidiInput::getDevices()
  187788. {
  187789. StringArray s;
  187790. const int num = midiInGetNumDevs();
  187791. for (int i = 0; i < num; ++i)
  187792. {
  187793. MIDIINCAPS mc;
  187794. zerostruct (mc);
  187795. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187796. s.add (String (mc.szPname, sizeof (mc.szPname)));
  187797. }
  187798. return s;
  187799. }
  187800. int MidiInput::getDefaultDeviceIndex()
  187801. {
  187802. return 0;
  187803. }
  187804. MidiInput* MidiInput::openDevice (const int index, MidiInputCallback* const callback)
  187805. {
  187806. if (callback == 0)
  187807. return 0;
  187808. UINT deviceId = MIDI_MAPPER;
  187809. int n = 0;
  187810. String name;
  187811. const int num = midiInGetNumDevs();
  187812. for (int i = 0; i < num; ++i)
  187813. {
  187814. MIDIINCAPS mc;
  187815. zerostruct (mc);
  187816. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187817. {
  187818. if (index == n)
  187819. {
  187820. deviceId = i;
  187821. name = String (mc.szPname, sizeof (mc.szPname));
  187822. break;
  187823. }
  187824. ++n;
  187825. }
  187826. }
  187827. ScopedPointer <MidiInput> in (new MidiInput (name));
  187828. ScopedPointer <MidiInThread> thread (new MidiInThread (in, callback));
  187829. HMIDIIN h;
  187830. HRESULT err = midiInOpen (&h, deviceId,
  187831. (DWORD_PTR) &MidiInThread::midiInCallback,
  187832. (DWORD_PTR) (MidiInThread*) thread,
  187833. CALLBACK_FUNCTION);
  187834. if (err == MMSYSERR_NOERROR)
  187835. {
  187836. thread->hIn = h;
  187837. in->internal = (void*) thread.release();
  187838. return in.release();
  187839. }
  187840. return 0;
  187841. }
  187842. MidiInput::MidiInput (const String& name_)
  187843. : name (name_),
  187844. internal (0)
  187845. {
  187846. }
  187847. MidiInput::~MidiInput()
  187848. {
  187849. delete static_cast <MidiInThread*> (internal);
  187850. }
  187851. void MidiInput::start()
  187852. {
  187853. static_cast <MidiInThread*> (internal)->start();
  187854. }
  187855. void MidiInput::stop()
  187856. {
  187857. static_cast <MidiInThread*> (internal)->stop();
  187858. }
  187859. struct MidiOutHandle
  187860. {
  187861. int refCount;
  187862. UINT deviceId;
  187863. HMIDIOUT handle;
  187864. static Array<MidiOutHandle*> activeHandles;
  187865. juce_UseDebuggingNewOperator
  187866. };
  187867. Array<MidiOutHandle*> MidiOutHandle::activeHandles;
  187868. const StringArray MidiOutput::getDevices()
  187869. {
  187870. StringArray s;
  187871. const int num = midiOutGetNumDevs();
  187872. for (int i = 0; i < num; ++i)
  187873. {
  187874. MIDIOUTCAPS mc;
  187875. zerostruct (mc);
  187876. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187877. s.add (String (mc.szPname, sizeof (mc.szPname)));
  187878. }
  187879. return s;
  187880. }
  187881. int MidiOutput::getDefaultDeviceIndex()
  187882. {
  187883. const int num = midiOutGetNumDevs();
  187884. int n = 0;
  187885. for (int i = 0; i < num; ++i)
  187886. {
  187887. MIDIOUTCAPS mc;
  187888. zerostruct (mc);
  187889. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187890. {
  187891. if ((mc.wTechnology & MOD_MAPPER) != 0)
  187892. return n;
  187893. ++n;
  187894. }
  187895. }
  187896. return 0;
  187897. }
  187898. MidiOutput* MidiOutput::openDevice (int index)
  187899. {
  187900. UINT deviceId = MIDI_MAPPER;
  187901. const int num = midiOutGetNumDevs();
  187902. int i, n = 0;
  187903. for (i = 0; i < num; ++i)
  187904. {
  187905. MIDIOUTCAPS mc;
  187906. zerostruct (mc);
  187907. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187908. {
  187909. // use the microsoft sw synth as a default - best not to allow deviceId
  187910. // to be MIDI_MAPPER, or else device sharing breaks
  187911. if (String (mc.szPname, sizeof (mc.szPname)).containsIgnoreCase (T("microsoft")))
  187912. deviceId = i;
  187913. if (index == n)
  187914. {
  187915. deviceId = i;
  187916. break;
  187917. }
  187918. ++n;
  187919. }
  187920. }
  187921. for (i = MidiOutHandle::activeHandles.size(); --i >= 0;)
  187922. {
  187923. MidiOutHandle* const han = MidiOutHandle::activeHandles.getUnchecked(i);
  187924. if (han != 0 && han->deviceId == deviceId)
  187925. {
  187926. han->refCount++;
  187927. MidiOutput* const out = new MidiOutput();
  187928. out->internal = (void*) han;
  187929. return out;
  187930. }
  187931. }
  187932. for (i = 4; --i >= 0;)
  187933. {
  187934. HMIDIOUT h = 0;
  187935. MMRESULT res = midiOutOpen (&h, deviceId, 0, 0, CALLBACK_NULL);
  187936. if (res == MMSYSERR_NOERROR)
  187937. {
  187938. MidiOutHandle* const han = new MidiOutHandle();
  187939. han->deviceId = deviceId;
  187940. han->refCount = 1;
  187941. han->handle = h;
  187942. MidiOutHandle::activeHandles.add (han);
  187943. MidiOutput* const out = new MidiOutput();
  187944. out->internal = (void*) han;
  187945. return out;
  187946. }
  187947. else if (res == MMSYSERR_ALLOCATED)
  187948. {
  187949. Sleep (100);
  187950. }
  187951. else
  187952. {
  187953. break;
  187954. }
  187955. }
  187956. return 0;
  187957. }
  187958. MidiOutput::~MidiOutput()
  187959. {
  187960. MidiOutHandle* const h = static_cast <MidiOutHandle*> (internal);
  187961. if (MidiOutHandle::activeHandles.contains (h) && --(h->refCount) == 0)
  187962. {
  187963. midiOutClose (h->handle);
  187964. MidiOutHandle::activeHandles.removeValue (h);
  187965. delete h;
  187966. }
  187967. }
  187968. void MidiOutput::reset()
  187969. {
  187970. const MidiOutHandle* const h = static_cast <const MidiOutHandle*> (internal);
  187971. midiOutReset (h->handle);
  187972. }
  187973. bool MidiOutput::getVolume (float& leftVol,
  187974. float& rightVol)
  187975. {
  187976. const MidiOutHandle* const handle = static_cast <const MidiOutHandle*> (internal);
  187977. DWORD n;
  187978. if (midiOutGetVolume (handle->handle, &n) == MMSYSERR_NOERROR)
  187979. {
  187980. const unsigned short* const nn = (const unsigned short*) &n;
  187981. rightVol = nn[0] / (float) 0xffff;
  187982. leftVol = nn[1] / (float) 0xffff;
  187983. return true;
  187984. }
  187985. else
  187986. {
  187987. rightVol = leftVol = 1.0f;
  187988. return false;
  187989. }
  187990. }
  187991. void MidiOutput::setVolume (float leftVol,
  187992. float rightVol)
  187993. {
  187994. const MidiOutHandle* const handle = static_cast <MidiOutHandle*> (internal);
  187995. DWORD n;
  187996. unsigned short* const nn = (unsigned short*) &n;
  187997. nn[0] = (unsigned short) jlimit (0, 0xffff, (int) (rightVol * 0xffff));
  187998. nn[1] = (unsigned short) jlimit (0, 0xffff, (int) (leftVol * 0xffff));
  187999. midiOutSetVolume (handle->handle, n);
  188000. }
  188001. void MidiOutput::sendMessageNow (const MidiMessage& message)
  188002. {
  188003. const MidiOutHandle* const handle = static_cast <const MidiOutHandle*> (internal);
  188004. if (message.getRawDataSize() > 3
  188005. || message.isSysEx())
  188006. {
  188007. MIDIHDR h;
  188008. zerostruct (h);
  188009. h.lpData = (char*) message.getRawData();
  188010. h.dwBufferLength = message.getRawDataSize();
  188011. h.dwBytesRecorded = message.getRawDataSize();
  188012. if (midiOutPrepareHeader (handle->handle, &h, sizeof (MIDIHDR)) == MMSYSERR_NOERROR)
  188013. {
  188014. MMRESULT res = midiOutLongMsg (handle->handle, &h, sizeof (MIDIHDR));
  188015. if (res == MMSYSERR_NOERROR)
  188016. {
  188017. while ((h.dwFlags & MHDR_DONE) == 0)
  188018. Sleep (1);
  188019. int count = 500; // 1 sec timeout
  188020. while (--count >= 0)
  188021. {
  188022. res = midiOutUnprepareHeader (handle->handle, &h, sizeof (MIDIHDR));
  188023. if (res == MIDIERR_STILLPLAYING)
  188024. Sleep (2);
  188025. else
  188026. break;
  188027. }
  188028. }
  188029. }
  188030. }
  188031. else
  188032. {
  188033. midiOutShortMsg (handle->handle,
  188034. *(unsigned int*) message.getRawData());
  188035. }
  188036. }
  188037. #endif
  188038. /*** End of inlined file: juce_win32_Midi.cpp ***/
  188039. /*** Start of inlined file: juce_win32_ASIO.cpp ***/
  188040. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  188041. // compiled on its own).
  188042. #if JUCE_INCLUDED_FILE && JUCE_ASIO
  188043. #undef WINDOWS
  188044. // #define ASIO_DEBUGGING
  188045. #ifdef ASIO_DEBUGGING
  188046. #define log(a) { Logger::writeToLog (a); DBG (a) }
  188047. #else
  188048. #define log(a) {}
  188049. #endif
  188050. #ifdef ASIO_DEBUGGING
  188051. static void logError (const String& context, long error)
  188052. {
  188053. String err ("unknown error");
  188054. if (error == ASE_NotPresent)
  188055. err = "Not Present";
  188056. else if (error == ASE_HWMalfunction)
  188057. err = "Hardware Malfunction";
  188058. else if (error == ASE_InvalidParameter)
  188059. err = "Invalid Parameter";
  188060. else if (error == ASE_InvalidMode)
  188061. err = "Invalid Mode";
  188062. else if (error == ASE_SPNotAdvancing)
  188063. err = "Sample position not advancing";
  188064. else if (error == ASE_NoClock)
  188065. err = "No Clock";
  188066. else if (error == ASE_NoMemory)
  188067. err = "Out of memory";
  188068. log ("!!error: " + context + " - " + err);
  188069. }
  188070. #else
  188071. #define logError(a, b) {}
  188072. #endif
  188073. class ASIOAudioIODevice;
  188074. static ASIOAudioIODevice* volatile currentASIODev[3] = { 0, 0, 0 };
  188075. static const int maxASIOChannels = 160;
  188076. class JUCE_API ASIOAudioIODevice : public AudioIODevice,
  188077. private Timer
  188078. {
  188079. public:
  188080. Component ourWindow;
  188081. ASIOAudioIODevice (const String& name_, const CLSID classId_, const int slotNumber,
  188082. const String& optionalDllForDirectLoading_)
  188083. : AudioIODevice (name_, "ASIO"),
  188084. asioObject (0),
  188085. classId (classId_),
  188086. optionalDllForDirectLoading (optionalDllForDirectLoading_),
  188087. currentBitDepth (16),
  188088. currentSampleRate (0),
  188089. isOpen_ (false),
  188090. isStarted (false),
  188091. postOutput (true),
  188092. insideControlPanelModalLoop (false),
  188093. shouldUsePreferredSize (false)
  188094. {
  188095. name = name_;
  188096. ourWindow.addToDesktop (0);
  188097. windowHandle = ourWindow.getWindowHandle();
  188098. jassert (currentASIODev [slotNumber] == 0);
  188099. currentASIODev [slotNumber] = this;
  188100. openDevice();
  188101. }
  188102. ~ASIOAudioIODevice()
  188103. {
  188104. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  188105. if (currentASIODev[i] == this)
  188106. currentASIODev[i] = 0;
  188107. close();
  188108. log ("ASIO - exiting");
  188109. removeCurrentDriver();
  188110. }
  188111. void updateSampleRates()
  188112. {
  188113. // find a list of sample rates..
  188114. const double possibleSampleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  188115. sampleRates.clear();
  188116. if (asioObject != 0)
  188117. {
  188118. for (int index = 0; index < numElementsInArray (possibleSampleRates); ++index)
  188119. {
  188120. const long err = asioObject->canSampleRate (possibleSampleRates[index]);
  188121. if (err == 0)
  188122. {
  188123. sampleRates.add ((int) possibleSampleRates[index]);
  188124. log ("rate: " + String ((int) possibleSampleRates[index]));
  188125. }
  188126. else if (err != ASE_NoClock)
  188127. {
  188128. logError ("CanSampleRate", err);
  188129. }
  188130. }
  188131. if (sampleRates.size() == 0)
  188132. {
  188133. double cr = 0;
  188134. const long err = asioObject->getSampleRate (&cr);
  188135. log ("No sample rates supported - current rate: " + String ((int) cr));
  188136. if (err == 0)
  188137. sampleRates.add ((int) cr);
  188138. }
  188139. }
  188140. }
  188141. const StringArray getOutputChannelNames()
  188142. {
  188143. return outputChannelNames;
  188144. }
  188145. const StringArray getInputChannelNames()
  188146. {
  188147. return inputChannelNames;
  188148. }
  188149. int getNumSampleRates()
  188150. {
  188151. return sampleRates.size();
  188152. }
  188153. double getSampleRate (int index)
  188154. {
  188155. return sampleRates [index];
  188156. }
  188157. int getNumBufferSizesAvailable()
  188158. {
  188159. return bufferSizes.size();
  188160. }
  188161. int getBufferSizeSamples (int index)
  188162. {
  188163. return bufferSizes [index];
  188164. }
  188165. int getDefaultBufferSize()
  188166. {
  188167. return preferredSize;
  188168. }
  188169. const String open (const BigInteger& inputChannels,
  188170. const BigInteger& outputChannels,
  188171. double sr,
  188172. int bufferSizeSamples)
  188173. {
  188174. close();
  188175. currentCallback = 0;
  188176. if (bufferSizeSamples <= 0)
  188177. shouldUsePreferredSize = true;
  188178. if (asioObject == 0 || ! isASIOOpen)
  188179. {
  188180. log ("Warning: device not open");
  188181. const String err (openDevice());
  188182. if (asioObject == 0 || ! isASIOOpen)
  188183. return err;
  188184. }
  188185. isStarted = false;
  188186. bufferIndex = -1;
  188187. long err = 0;
  188188. long newPreferredSize = 0;
  188189. // if the preferred size has just changed, assume it's a control panel thing and use it as the new value.
  188190. minSize = 0;
  188191. maxSize = 0;
  188192. newPreferredSize = 0;
  188193. granularity = 0;
  188194. if (asioObject->getBufferSize (&minSize, &maxSize, &newPreferredSize, &granularity) == 0)
  188195. {
  188196. if (preferredSize != 0 && newPreferredSize != 0 && newPreferredSize != preferredSize)
  188197. shouldUsePreferredSize = true;
  188198. preferredSize = newPreferredSize;
  188199. }
  188200. // unfortunate workaround for certain manufacturers whose drivers crash horribly if you make
  188201. // dynamic changes to the buffer size...
  188202. shouldUsePreferredSize = shouldUsePreferredSize
  188203. || getName().containsIgnoreCase (T("Digidesign"));
  188204. if (shouldUsePreferredSize)
  188205. {
  188206. log ("Using preferred size for buffer..");
  188207. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  188208. {
  188209. bufferSizeSamples = preferredSize;
  188210. }
  188211. else
  188212. {
  188213. bufferSizeSamples = 1024;
  188214. logError ("GetBufferSize1", err);
  188215. }
  188216. shouldUsePreferredSize = false;
  188217. }
  188218. int sampleRate = roundDoubleToInt (sr);
  188219. currentSampleRate = sampleRate;
  188220. currentBlockSizeSamples = bufferSizeSamples;
  188221. currentChansOut.clear();
  188222. currentChansIn.clear();
  188223. zeromem (inBuffers, sizeof (inBuffers));
  188224. zeromem (outBuffers, sizeof (outBuffers));
  188225. updateSampleRates();
  188226. if (sampleRate == 0 || (sampleRates.size() > 0 && ! sampleRates.contains (sampleRate)))
  188227. sampleRate = sampleRates[0];
  188228. jassert (sampleRate != 0);
  188229. if (sampleRate == 0)
  188230. sampleRate = 44100;
  188231. long numSources = 32;
  188232. ASIOClockSource clocks[32];
  188233. zeromem (clocks, sizeof (clocks));
  188234. asioObject->getClockSources (clocks, &numSources);
  188235. bool isSourceSet = false;
  188236. // careful not to remove this loop because it does more than just logging!
  188237. int i;
  188238. for (i = 0; i < numSources; ++i)
  188239. {
  188240. String s ("clock: ");
  188241. s += clocks[i].name;
  188242. if (clocks[i].isCurrentSource)
  188243. {
  188244. isSourceSet = true;
  188245. s << " (cur)";
  188246. }
  188247. log (s);
  188248. }
  188249. if (numSources > 1 && ! isSourceSet)
  188250. {
  188251. log ("setting clock source");
  188252. asioObject->setClockSource (clocks[0].index);
  188253. Thread::sleep (20);
  188254. }
  188255. else
  188256. {
  188257. if (numSources == 0)
  188258. {
  188259. log ("ASIO - no clock sources!");
  188260. }
  188261. }
  188262. double cr = 0;
  188263. err = asioObject->getSampleRate (&cr);
  188264. if (err == 0)
  188265. {
  188266. currentSampleRate = cr;
  188267. }
  188268. else
  188269. {
  188270. logError ("GetSampleRate", err);
  188271. currentSampleRate = 0;
  188272. }
  188273. error = String::empty;
  188274. needToReset = false;
  188275. isReSync = false;
  188276. err = 0;
  188277. bool buffersCreated = false;
  188278. if (currentSampleRate != sampleRate)
  188279. {
  188280. log ("ASIO samplerate: " + String (currentSampleRate) + " to " + String (sampleRate));
  188281. err = asioObject->setSampleRate (sampleRate);
  188282. if (err == ASE_NoClock && numSources > 0)
  188283. {
  188284. log ("trying to set a clock source..");
  188285. Thread::sleep (10);
  188286. err = asioObject->setClockSource (clocks[0].index);
  188287. if (err != 0)
  188288. {
  188289. logError ("SetClock", err);
  188290. }
  188291. Thread::sleep (10);
  188292. err = asioObject->setSampleRate (sampleRate);
  188293. }
  188294. }
  188295. if (err == 0)
  188296. {
  188297. currentSampleRate = sampleRate;
  188298. if (needToReset)
  188299. {
  188300. if (isReSync)
  188301. {
  188302. log ("Resync request");
  188303. }
  188304. log ("! Resetting ASIO after sample rate change");
  188305. removeCurrentDriver();
  188306. loadDriver();
  188307. const String error (initDriver());
  188308. if (error.isNotEmpty())
  188309. {
  188310. log ("ASIOInit: " + error);
  188311. }
  188312. needToReset = false;
  188313. isReSync = false;
  188314. }
  188315. numActiveInputChans = 0;
  188316. numActiveOutputChans = 0;
  188317. ASIOBufferInfo* info = bufferInfos;
  188318. int i;
  188319. for (i = 0; i < totalNumInputChans; ++i)
  188320. {
  188321. if (inputChannels[i])
  188322. {
  188323. currentChansIn.setBit (i);
  188324. info->isInput = 1;
  188325. info->channelNum = i;
  188326. info->buffers[0] = info->buffers[1] = 0;
  188327. ++info;
  188328. ++numActiveInputChans;
  188329. }
  188330. }
  188331. for (i = 0; i < totalNumOutputChans; ++i)
  188332. {
  188333. if (outputChannels[i])
  188334. {
  188335. currentChansOut.setBit (i);
  188336. info->isInput = 0;
  188337. info->channelNum = i;
  188338. info->buffers[0] = info->buffers[1] = 0;
  188339. ++info;
  188340. ++numActiveOutputChans;
  188341. }
  188342. }
  188343. const int totalBuffers = numActiveInputChans + numActiveOutputChans;
  188344. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  188345. if (currentASIODev[0] == this)
  188346. {
  188347. callbacks.bufferSwitch = &bufferSwitchCallback0;
  188348. callbacks.asioMessage = &asioMessagesCallback0;
  188349. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  188350. }
  188351. else if (currentASIODev[1] == this)
  188352. {
  188353. callbacks.bufferSwitch = &bufferSwitchCallback1;
  188354. callbacks.asioMessage = &asioMessagesCallback1;
  188355. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  188356. }
  188357. else if (currentASIODev[2] == this)
  188358. {
  188359. callbacks.bufferSwitch = &bufferSwitchCallback2;
  188360. callbacks.asioMessage = &asioMessagesCallback2;
  188361. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  188362. }
  188363. else
  188364. {
  188365. jassertfalse
  188366. }
  188367. log ("disposing buffers");
  188368. err = asioObject->disposeBuffers();
  188369. log ("creating buffers: " + String (totalBuffers) + ", " + String (currentBlockSizeSamples));
  188370. err = asioObject->createBuffers (bufferInfos,
  188371. totalBuffers,
  188372. currentBlockSizeSamples,
  188373. &callbacks);
  188374. if (err != 0)
  188375. {
  188376. currentBlockSizeSamples = preferredSize;
  188377. logError ("create buffers 2", err);
  188378. asioObject->disposeBuffers();
  188379. err = asioObject->createBuffers (bufferInfos,
  188380. totalBuffers,
  188381. currentBlockSizeSamples,
  188382. &callbacks);
  188383. }
  188384. if (err == 0)
  188385. {
  188386. buffersCreated = true;
  188387. tempBuffer.calloc (totalBuffers * currentBlockSizeSamples + 32);
  188388. int n = 0;
  188389. Array <int> types;
  188390. currentBitDepth = 16;
  188391. for (i = 0; i < jmin ((int) totalNumInputChans, maxASIOChannels); ++i)
  188392. {
  188393. if (inputChannels[i])
  188394. {
  188395. inBuffers[n] = tempBuffer + (currentBlockSizeSamples * n);
  188396. ASIOChannelInfo channelInfo;
  188397. zerostruct (channelInfo);
  188398. channelInfo.channel = i;
  188399. channelInfo.isInput = 1;
  188400. asioObject->getChannelInfo (&channelInfo);
  188401. types.addIfNotAlreadyThere (channelInfo.type);
  188402. typeToFormatParameters (channelInfo.type,
  188403. inputChannelBitDepths[n],
  188404. inputChannelBytesPerSample[n],
  188405. inputChannelIsFloat[n],
  188406. inputChannelLittleEndian[n]);
  188407. currentBitDepth = jmax (currentBitDepth, inputChannelBitDepths[n]);
  188408. ++n;
  188409. }
  188410. }
  188411. jassert (numActiveInputChans == n);
  188412. n = 0;
  188413. for (i = 0; i < jmin ((int) totalNumOutputChans, maxASIOChannels); ++i)
  188414. {
  188415. if (outputChannels[i])
  188416. {
  188417. outBuffers[n] = tempBuffer + (currentBlockSizeSamples * (numActiveInputChans + n));
  188418. ASIOChannelInfo channelInfo;
  188419. zerostruct (channelInfo);
  188420. channelInfo.channel = i;
  188421. channelInfo.isInput = 0;
  188422. asioObject->getChannelInfo (&channelInfo);
  188423. types.addIfNotAlreadyThere (channelInfo.type);
  188424. typeToFormatParameters (channelInfo.type,
  188425. outputChannelBitDepths[n],
  188426. outputChannelBytesPerSample[n],
  188427. outputChannelIsFloat[n],
  188428. outputChannelLittleEndian[n]);
  188429. currentBitDepth = jmax (currentBitDepth, outputChannelBitDepths[n]);
  188430. ++n;
  188431. }
  188432. }
  188433. jassert (numActiveOutputChans == n);
  188434. for (i = types.size(); --i >= 0;)
  188435. {
  188436. log ("channel format: " + String (types[i]));
  188437. }
  188438. jassert (n <= totalBuffers);
  188439. for (i = 0; i < numActiveOutputChans; ++i)
  188440. {
  188441. const int size = currentBlockSizeSamples * (outputChannelBitDepths[i] >> 3);
  188442. if (bufferInfos [numActiveInputChans + i].buffers[0] == 0
  188443. || bufferInfos [numActiveInputChans + i].buffers[1] == 0)
  188444. {
  188445. log ("!! Null buffers");
  188446. }
  188447. else
  188448. {
  188449. zeromem (bufferInfos[numActiveInputChans + i].buffers[0], size);
  188450. zeromem (bufferInfos[numActiveInputChans + i].buffers[1], size);
  188451. }
  188452. }
  188453. inputLatency = outputLatency = 0;
  188454. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  188455. {
  188456. log ("ASIO - no latencies");
  188457. }
  188458. else
  188459. {
  188460. log ("ASIO latencies: " + String ((int) outputLatency) + ", " + String ((int) inputLatency));
  188461. }
  188462. isOpen_ = true;
  188463. log ("starting ASIO");
  188464. calledback = false;
  188465. err = asioObject->start();
  188466. if (err != 0)
  188467. {
  188468. isOpen_ = false;
  188469. log ("ASIO - stop on failure");
  188470. Thread::sleep (10);
  188471. asioObject->stop();
  188472. error = "Can't start device";
  188473. Thread::sleep (10);
  188474. }
  188475. else
  188476. {
  188477. int count = 300;
  188478. while (--count > 0 && ! calledback)
  188479. Thread::sleep (10);
  188480. isStarted = true;
  188481. if (! calledback)
  188482. {
  188483. error = "Device didn't start correctly";
  188484. log ("ASIO didn't callback - stopping..");
  188485. asioObject->stop();
  188486. }
  188487. }
  188488. }
  188489. else
  188490. {
  188491. error = "Can't create i/o buffers";
  188492. }
  188493. }
  188494. else
  188495. {
  188496. error = "Can't set sample rate: ";
  188497. error << sampleRate;
  188498. }
  188499. if (error.isNotEmpty())
  188500. {
  188501. logError (error, err);
  188502. if (asioObject != 0 && buffersCreated)
  188503. asioObject->disposeBuffers();
  188504. Thread::sleep (20);
  188505. isStarted = false;
  188506. isOpen_ = false;
  188507. close();
  188508. }
  188509. needToReset = false;
  188510. isReSync = false;
  188511. return error;
  188512. }
  188513. void close()
  188514. {
  188515. error = String::empty;
  188516. stopTimer();
  188517. stop();
  188518. if (isASIOOpen && isOpen_)
  188519. {
  188520. const ScopedLock sl (callbackLock);
  188521. isOpen_ = false;
  188522. isStarted = false;
  188523. needToReset = false;
  188524. isReSync = false;
  188525. log ("ASIO - stopping");
  188526. if (asioObject != 0)
  188527. {
  188528. Thread::sleep (20);
  188529. asioObject->stop();
  188530. Thread::sleep (10);
  188531. asioObject->disposeBuffers();
  188532. }
  188533. Thread::sleep (10);
  188534. }
  188535. }
  188536. bool isOpen()
  188537. {
  188538. return isOpen_ || insideControlPanelModalLoop;
  188539. }
  188540. int getCurrentBufferSizeSamples()
  188541. {
  188542. return currentBlockSizeSamples;
  188543. }
  188544. double getCurrentSampleRate()
  188545. {
  188546. return currentSampleRate;
  188547. }
  188548. const BigInteger getActiveOutputChannels() const
  188549. {
  188550. return currentChansOut;
  188551. }
  188552. const BigInteger getActiveInputChannels() const
  188553. {
  188554. return currentChansIn;
  188555. }
  188556. int getCurrentBitDepth()
  188557. {
  188558. return currentBitDepth;
  188559. }
  188560. int getOutputLatencyInSamples()
  188561. {
  188562. return outputLatency + currentBlockSizeSamples / 4;
  188563. }
  188564. int getInputLatencyInSamples()
  188565. {
  188566. return inputLatency + currentBlockSizeSamples / 4;
  188567. }
  188568. void start (AudioIODeviceCallback* callback)
  188569. {
  188570. if (callback != 0)
  188571. {
  188572. callback->audioDeviceAboutToStart (this);
  188573. const ScopedLock sl (callbackLock);
  188574. currentCallback = callback;
  188575. }
  188576. }
  188577. void stop()
  188578. {
  188579. AudioIODeviceCallback* const lastCallback = currentCallback;
  188580. {
  188581. const ScopedLock sl (callbackLock);
  188582. currentCallback = 0;
  188583. }
  188584. if (lastCallback != 0)
  188585. lastCallback->audioDeviceStopped();
  188586. }
  188587. bool isPlaying()
  188588. {
  188589. return isASIOOpen && (currentCallback != 0);
  188590. }
  188591. const String getLastError()
  188592. {
  188593. return error;
  188594. }
  188595. bool hasControlPanel() const
  188596. {
  188597. return true;
  188598. }
  188599. bool showControlPanel()
  188600. {
  188601. log ("ASIO - showing control panel");
  188602. Component modalWindow (String::empty);
  188603. modalWindow.setOpaque (true);
  188604. modalWindow.addToDesktop (0);
  188605. modalWindow.enterModalState();
  188606. bool done = false;
  188607. JUCE_TRY
  188608. {
  188609. // are there are devices that need to be closed before showing their control panel?
  188610. // close();
  188611. insideControlPanelModalLoop = true;
  188612. const uint32 started = Time::getMillisecondCounter();
  188613. if (asioObject != 0)
  188614. {
  188615. asioObject->controlPanel();
  188616. const int spent = (int) Time::getMillisecondCounter() - (int) started;
  188617. log ("spent: " + String (spent));
  188618. if (spent > 300)
  188619. {
  188620. shouldUsePreferredSize = true;
  188621. done = true;
  188622. }
  188623. }
  188624. }
  188625. JUCE_CATCH_ALL
  188626. insideControlPanelModalLoop = false;
  188627. return done;
  188628. }
  188629. void resetRequest() throw()
  188630. {
  188631. needToReset = true;
  188632. }
  188633. void resyncRequest() throw()
  188634. {
  188635. needToReset = true;
  188636. isReSync = true;
  188637. }
  188638. void timerCallback()
  188639. {
  188640. if (! insideControlPanelModalLoop)
  188641. {
  188642. stopTimer();
  188643. // used to cause a reset
  188644. log ("! ASIO restart request!");
  188645. if (isOpen_)
  188646. {
  188647. AudioIODeviceCallback* const oldCallback = currentCallback;
  188648. close();
  188649. open (BigInteger (currentChansIn), BigInteger (currentChansOut),
  188650. currentSampleRate, currentBlockSizeSamples);
  188651. if (oldCallback != 0)
  188652. start (oldCallback);
  188653. }
  188654. }
  188655. else
  188656. {
  188657. startTimer (100);
  188658. }
  188659. }
  188660. juce_UseDebuggingNewOperator
  188661. private:
  188662. IASIO* volatile asioObject;
  188663. ASIOCallbacks callbacks;
  188664. void* windowHandle;
  188665. CLSID classId;
  188666. const String optionalDllForDirectLoading;
  188667. String error;
  188668. long totalNumInputChans, totalNumOutputChans;
  188669. StringArray inputChannelNames, outputChannelNames;
  188670. Array<int> sampleRates, bufferSizes;
  188671. long inputLatency, outputLatency;
  188672. long minSize, maxSize, preferredSize, granularity;
  188673. int volatile currentBlockSizeSamples;
  188674. int volatile currentBitDepth;
  188675. double volatile currentSampleRate;
  188676. BigInteger currentChansOut, currentChansIn;
  188677. AudioIODeviceCallback* volatile currentCallback;
  188678. CriticalSection callbackLock;
  188679. ASIOBufferInfo bufferInfos [maxASIOChannels];
  188680. float* inBuffers [maxASIOChannels];
  188681. float* outBuffers [maxASIOChannels];
  188682. int inputChannelBitDepths [maxASIOChannels];
  188683. int outputChannelBitDepths [maxASIOChannels];
  188684. int inputChannelBytesPerSample [maxASIOChannels];
  188685. int outputChannelBytesPerSample [maxASIOChannels];
  188686. bool inputChannelIsFloat [maxASIOChannels];
  188687. bool outputChannelIsFloat [maxASIOChannels];
  188688. bool inputChannelLittleEndian [maxASIOChannels];
  188689. bool outputChannelLittleEndian [maxASIOChannels];
  188690. WaitableEvent event1;
  188691. HeapBlock <float> tempBuffer;
  188692. int volatile bufferIndex, numActiveInputChans, numActiveOutputChans;
  188693. bool isOpen_, isStarted;
  188694. bool volatile isASIOOpen;
  188695. bool volatile calledback;
  188696. bool volatile littleEndian, postOutput, needToReset, isReSync;
  188697. bool volatile insideControlPanelModalLoop;
  188698. bool volatile shouldUsePreferredSize;
  188699. void removeCurrentDriver()
  188700. {
  188701. if (asioObject != 0)
  188702. {
  188703. asioObject->Release();
  188704. asioObject = 0;
  188705. }
  188706. }
  188707. bool loadDriver()
  188708. {
  188709. removeCurrentDriver();
  188710. JUCE_TRY
  188711. {
  188712. if (CoCreateInstance (classId, 0, CLSCTX_INPROC_SERVER,
  188713. classId, (void**) &asioObject) == S_OK)
  188714. {
  188715. return true;
  188716. }
  188717. // If a class isn't registered but we have a path for it, we can fallback to
  188718. // doing a direct load of the COM object (only available via the juce_createASIOAudioIODeviceForGUID function).
  188719. if (optionalDllForDirectLoading.isNotEmpty())
  188720. {
  188721. HMODULE h = LoadLibrary (optionalDllForDirectLoading);
  188722. if (h != 0)
  188723. {
  188724. typedef HRESULT (CALLBACK* DllGetClassObjectFunc) (REFCLSID clsid, REFIID iid, LPVOID* ppv);
  188725. DllGetClassObjectFunc dllGetClassObject = (DllGetClassObjectFunc) GetProcAddress (h, "DllGetClassObject");
  188726. if (dllGetClassObject != 0)
  188727. {
  188728. IClassFactory* classFactory = 0;
  188729. HRESULT hr = dllGetClassObject (classId, IID_IClassFactory, (void**) &classFactory);
  188730. if (classFactory != 0)
  188731. {
  188732. hr = classFactory->CreateInstance (0, classId, (void**) &asioObject);
  188733. classFactory->Release();
  188734. }
  188735. return asioObject != 0;
  188736. }
  188737. }
  188738. }
  188739. }
  188740. JUCE_CATCH_ALL
  188741. asioObject = 0;
  188742. return false;
  188743. }
  188744. const String initDriver()
  188745. {
  188746. if (asioObject != 0)
  188747. {
  188748. char buffer [256];
  188749. zeromem (buffer, sizeof (buffer));
  188750. if (! asioObject->init (windowHandle))
  188751. {
  188752. asioObject->getErrorMessage (buffer);
  188753. return String (buffer, sizeof (buffer) - 1);
  188754. }
  188755. // just in case any daft drivers expect this to be called..
  188756. asioObject->getDriverName (buffer);
  188757. return String::empty;
  188758. }
  188759. return "No Driver";
  188760. }
  188761. const String openDevice()
  188762. {
  188763. // use this in case the driver starts opening dialog boxes..
  188764. Component modalWindow (String::empty);
  188765. modalWindow.setOpaque (true);
  188766. modalWindow.addToDesktop (0);
  188767. modalWindow.enterModalState();
  188768. // open the device and get its info..
  188769. log ("opening ASIO device: " + getName());
  188770. needToReset = false;
  188771. isReSync = false;
  188772. outputChannelNames.clear();
  188773. inputChannelNames.clear();
  188774. bufferSizes.clear();
  188775. sampleRates.clear();
  188776. isASIOOpen = false;
  188777. isOpen_ = false;
  188778. totalNumInputChans = 0;
  188779. totalNumOutputChans = 0;
  188780. numActiveInputChans = 0;
  188781. numActiveOutputChans = 0;
  188782. currentCallback = 0;
  188783. error = String::empty;
  188784. if (getName().isEmpty())
  188785. return error;
  188786. long err = 0;
  188787. if (loadDriver())
  188788. {
  188789. if ((error = initDriver()).isEmpty())
  188790. {
  188791. numActiveInputChans = 0;
  188792. numActiveOutputChans = 0;
  188793. totalNumInputChans = 0;
  188794. totalNumOutputChans = 0;
  188795. if (asioObject != 0
  188796. && (err = asioObject->getChannels (&totalNumInputChans, &totalNumOutputChans)) == 0)
  188797. {
  188798. log (String ((int) totalNumInputChans) + " in, " + String ((int) totalNumOutputChans) + " out");
  188799. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  188800. {
  188801. // find a list of buffer sizes..
  188802. log (String ((int) minSize) + " " + String ((int) maxSize) + " " + String ((int) preferredSize) + " " + String ((int) granularity));
  188803. if (granularity >= 0)
  188804. {
  188805. granularity = jmax (1, (int) granularity);
  188806. for (int i = jmax ((int) minSize, (int) granularity); i < jmin (6400, (int) maxSize); i += granularity)
  188807. bufferSizes.addIfNotAlreadyThere (granularity * (i / granularity));
  188808. }
  188809. else if (granularity < 0)
  188810. {
  188811. for (int i = 0; i < 18; ++i)
  188812. {
  188813. const int s = (1 << i);
  188814. if (s >= minSize && s <= maxSize)
  188815. bufferSizes.add (s);
  188816. }
  188817. }
  188818. if (! bufferSizes.contains (preferredSize))
  188819. bufferSizes.insert (0, preferredSize);
  188820. double currentRate = 0;
  188821. asioObject->getSampleRate (&currentRate);
  188822. if (currentRate <= 0.0 || currentRate > 192001.0)
  188823. {
  188824. log ("setting sample rate");
  188825. err = asioObject->setSampleRate (44100.0);
  188826. if (err != 0)
  188827. {
  188828. logError ("setting sample rate", err);
  188829. }
  188830. asioObject->getSampleRate (&currentRate);
  188831. }
  188832. currentSampleRate = currentRate;
  188833. postOutput = (asioObject->outputReady() == 0);
  188834. if (postOutput)
  188835. {
  188836. log ("ASIO outputReady = ok");
  188837. }
  188838. updateSampleRates();
  188839. // ..because cubase does it at this point
  188840. inputLatency = outputLatency = 0;
  188841. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  188842. {
  188843. log ("ASIO - no latencies");
  188844. }
  188845. log ("latencies: " + String ((int) inputLatency) + ", " + String ((int) outputLatency));
  188846. // create some dummy buffers now.. because cubase does..
  188847. numActiveInputChans = 0;
  188848. numActiveOutputChans = 0;
  188849. ASIOBufferInfo* info = bufferInfos;
  188850. int i, numChans = 0;
  188851. for (i = 0; i < jmin (2, (int) totalNumInputChans); ++i)
  188852. {
  188853. info->isInput = 1;
  188854. info->channelNum = i;
  188855. info->buffers[0] = info->buffers[1] = 0;
  188856. ++info;
  188857. ++numChans;
  188858. }
  188859. const int outputBufferIndex = numChans;
  188860. for (i = 0; i < jmin (2, (int) totalNumOutputChans); ++i)
  188861. {
  188862. info->isInput = 0;
  188863. info->channelNum = i;
  188864. info->buffers[0] = info->buffers[1] = 0;
  188865. ++info;
  188866. ++numChans;
  188867. }
  188868. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  188869. if (currentASIODev[0] == this)
  188870. {
  188871. callbacks.bufferSwitch = &bufferSwitchCallback0;
  188872. callbacks.asioMessage = &asioMessagesCallback0;
  188873. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  188874. }
  188875. else if (currentASIODev[1] == this)
  188876. {
  188877. callbacks.bufferSwitch = &bufferSwitchCallback1;
  188878. callbacks.asioMessage = &asioMessagesCallback1;
  188879. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  188880. }
  188881. else if (currentASIODev[2] == this)
  188882. {
  188883. callbacks.bufferSwitch = &bufferSwitchCallback2;
  188884. callbacks.asioMessage = &asioMessagesCallback2;
  188885. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  188886. }
  188887. else
  188888. {
  188889. jassertfalse
  188890. }
  188891. log ("creating buffers (dummy): " + String (numChans) + ", " + String ((int) preferredSize));
  188892. if (preferredSize > 0)
  188893. {
  188894. err = asioObject->createBuffers (bufferInfos, numChans, preferredSize, &callbacks);
  188895. if (err != 0)
  188896. {
  188897. logError ("dummy buffers", err);
  188898. }
  188899. }
  188900. long newInps = 0, newOuts = 0;
  188901. asioObject->getChannels (&newInps, &newOuts);
  188902. if (totalNumInputChans != newInps || totalNumOutputChans != newOuts)
  188903. {
  188904. totalNumInputChans = newInps;
  188905. totalNumOutputChans = newOuts;
  188906. log (String ((int) totalNumInputChans) + " in; " + String ((int) totalNumOutputChans) + " out");
  188907. }
  188908. updateSampleRates();
  188909. ASIOChannelInfo channelInfo;
  188910. channelInfo.type = 0;
  188911. for (i = 0; i < totalNumInputChans; ++i)
  188912. {
  188913. zerostruct (channelInfo);
  188914. channelInfo.channel = i;
  188915. channelInfo.isInput = 1;
  188916. asioObject->getChannelInfo (&channelInfo);
  188917. inputChannelNames.add (String (channelInfo.name));
  188918. }
  188919. for (i = 0; i < totalNumOutputChans; ++i)
  188920. {
  188921. zerostruct (channelInfo);
  188922. channelInfo.channel = i;
  188923. channelInfo.isInput = 0;
  188924. asioObject->getChannelInfo (&channelInfo);
  188925. outputChannelNames.add (String (channelInfo.name));
  188926. typeToFormatParameters (channelInfo.type,
  188927. outputChannelBitDepths[i],
  188928. outputChannelBytesPerSample[i],
  188929. outputChannelIsFloat[i],
  188930. outputChannelLittleEndian[i]);
  188931. if (i < 2)
  188932. {
  188933. // clear the channels that are used with the dummy stuff
  188934. const int bytesPerBuffer = preferredSize * (outputChannelBitDepths[i] >> 3);
  188935. zeromem (bufferInfos [outputBufferIndex + i].buffers[0], bytesPerBuffer);
  188936. zeromem (bufferInfos [outputBufferIndex + i].buffers[1], bytesPerBuffer);
  188937. }
  188938. }
  188939. outputChannelNames.trim();
  188940. inputChannelNames.trim();
  188941. outputChannelNames.appendNumbersToDuplicates (false, true);
  188942. inputChannelNames.appendNumbersToDuplicates (false, true);
  188943. // start and stop because cubase does it..
  188944. asioObject->getLatencies (&inputLatency, &outputLatency);
  188945. if ((err = asioObject->start()) != 0)
  188946. {
  188947. // ignore an error here, as it might start later after setting other stuff up
  188948. logError ("ASIO start", err);
  188949. }
  188950. Thread::sleep (100);
  188951. asioObject->stop();
  188952. }
  188953. else
  188954. {
  188955. error = "Can't detect buffer sizes";
  188956. }
  188957. }
  188958. else
  188959. {
  188960. error = "Can't detect asio channels";
  188961. }
  188962. }
  188963. }
  188964. else
  188965. {
  188966. error = "No such device";
  188967. }
  188968. if (error.isNotEmpty())
  188969. {
  188970. logError (error, err);
  188971. if (asioObject != 0)
  188972. asioObject->disposeBuffers();
  188973. removeCurrentDriver();
  188974. isASIOOpen = false;
  188975. }
  188976. else
  188977. {
  188978. isASIOOpen = true;
  188979. log ("ASIO device open");
  188980. }
  188981. isOpen_ = false;
  188982. needToReset = false;
  188983. isReSync = false;
  188984. return error;
  188985. }
  188986. void callback (const long index) throw()
  188987. {
  188988. if (isStarted)
  188989. {
  188990. bufferIndex = index;
  188991. processBuffer();
  188992. }
  188993. else
  188994. {
  188995. if (postOutput && (asioObject != 0))
  188996. asioObject->outputReady();
  188997. }
  188998. calledback = true;
  188999. }
  189000. void processBuffer() throw()
  189001. {
  189002. const ASIOBufferInfo* const infos = bufferInfos;
  189003. const int bi = bufferIndex;
  189004. const ScopedLock sl (callbackLock);
  189005. if (needToReset)
  189006. {
  189007. needToReset = false;
  189008. if (isReSync)
  189009. {
  189010. log ("! ASIO resync");
  189011. isReSync = false;
  189012. }
  189013. else
  189014. {
  189015. startTimer (20);
  189016. }
  189017. }
  189018. if (bi >= 0)
  189019. {
  189020. const int samps = currentBlockSizeSamples;
  189021. if (currentCallback != 0)
  189022. {
  189023. int i;
  189024. for (i = 0; i < numActiveInputChans; ++i)
  189025. {
  189026. float* const dst = inBuffers[i];
  189027. jassert (dst != 0);
  189028. const char* const src = (const char*) (infos[i].buffers[bi]);
  189029. if (inputChannelIsFloat[i])
  189030. {
  189031. memcpy (dst, src, samps * sizeof (float));
  189032. }
  189033. else
  189034. {
  189035. jassert (dst == tempBuffer + (samps * i));
  189036. switch (inputChannelBitDepths[i])
  189037. {
  189038. case 16:
  189039. convertInt16ToFloat (src, dst, inputChannelBytesPerSample[i],
  189040. samps, inputChannelLittleEndian[i]);
  189041. break;
  189042. case 24:
  189043. convertInt24ToFloat (src, dst, inputChannelBytesPerSample[i],
  189044. samps, inputChannelLittleEndian[i]);
  189045. break;
  189046. case 32:
  189047. convertInt32ToFloat (src, dst, inputChannelBytesPerSample[i],
  189048. samps, inputChannelLittleEndian[i]);
  189049. break;
  189050. case 64:
  189051. jassertfalse
  189052. break;
  189053. }
  189054. }
  189055. }
  189056. currentCallback->audioDeviceIOCallback ((const float**) inBuffers,
  189057. numActiveInputChans,
  189058. outBuffers,
  189059. numActiveOutputChans,
  189060. samps);
  189061. for (i = 0; i < numActiveOutputChans; ++i)
  189062. {
  189063. float* const src = outBuffers[i];
  189064. jassert (src != 0);
  189065. char* const dst = (char*) (infos [numActiveInputChans + i].buffers[bi]);
  189066. if (outputChannelIsFloat[i])
  189067. {
  189068. memcpy (dst, src, samps * sizeof (float));
  189069. }
  189070. else
  189071. {
  189072. jassert (src == tempBuffer + (samps * (numActiveInputChans + i)));
  189073. switch (outputChannelBitDepths[i])
  189074. {
  189075. case 16:
  189076. convertFloatToInt16 (src, dst, outputChannelBytesPerSample[i],
  189077. samps, outputChannelLittleEndian[i]);
  189078. break;
  189079. case 24:
  189080. convertFloatToInt24 (src, dst, outputChannelBytesPerSample[i],
  189081. samps, outputChannelLittleEndian[i]);
  189082. break;
  189083. case 32:
  189084. convertFloatToInt32 (src, dst, outputChannelBytesPerSample[i],
  189085. samps, outputChannelLittleEndian[i]);
  189086. break;
  189087. case 64:
  189088. jassertfalse
  189089. break;
  189090. }
  189091. }
  189092. }
  189093. }
  189094. else
  189095. {
  189096. for (int i = 0; i < numActiveOutputChans; ++i)
  189097. {
  189098. const int bytesPerBuffer = samps * (outputChannelBitDepths[i] >> 3);
  189099. zeromem (infos[numActiveInputChans + i].buffers[bi], bytesPerBuffer);
  189100. }
  189101. }
  189102. }
  189103. if (postOutput)
  189104. asioObject->outputReady();
  189105. }
  189106. static ASIOTime* bufferSwitchTimeInfoCallback0 (ASIOTime*, long index, long) throw()
  189107. {
  189108. if (currentASIODev[0] != 0)
  189109. currentASIODev[0]->callback (index);
  189110. return 0;
  189111. }
  189112. static ASIOTime* bufferSwitchTimeInfoCallback1 (ASIOTime*, long index, long) throw()
  189113. {
  189114. if (currentASIODev[1] != 0)
  189115. currentASIODev[1]->callback (index);
  189116. return 0;
  189117. }
  189118. static ASIOTime* bufferSwitchTimeInfoCallback2 (ASIOTime*, long index, long) throw()
  189119. {
  189120. if (currentASIODev[2] != 0)
  189121. currentASIODev[2]->callback (index);
  189122. return 0;
  189123. }
  189124. static void bufferSwitchCallback0 (long index, long) throw()
  189125. {
  189126. if (currentASIODev[0] != 0)
  189127. currentASIODev[0]->callback (index);
  189128. }
  189129. static void bufferSwitchCallback1 (long index, long) throw()
  189130. {
  189131. if (currentASIODev[1] != 0)
  189132. currentASIODev[1]->callback (index);
  189133. }
  189134. static void bufferSwitchCallback2 (long index, long) throw()
  189135. {
  189136. if (currentASIODev[2] != 0)
  189137. currentASIODev[2]->callback (index);
  189138. }
  189139. static long asioMessagesCallback0 (long selector, long value, void*, double*) throw()
  189140. {
  189141. return asioMessagesCallback (selector, value, 0);
  189142. }
  189143. static long asioMessagesCallback1 (long selector, long value, void*, double*) throw()
  189144. {
  189145. return asioMessagesCallback (selector, value, 1);
  189146. }
  189147. static long asioMessagesCallback2 (long selector, long value, void*, double*) throw()
  189148. {
  189149. return asioMessagesCallback (selector, value, 2);
  189150. }
  189151. static long asioMessagesCallback (long selector, long value, const int deviceIndex) throw()
  189152. {
  189153. switch (selector)
  189154. {
  189155. case kAsioSelectorSupported:
  189156. if (value == kAsioResetRequest
  189157. || value == kAsioEngineVersion
  189158. || value == kAsioResyncRequest
  189159. || value == kAsioLatenciesChanged
  189160. || value == kAsioSupportsInputMonitor)
  189161. return 1;
  189162. break;
  189163. case kAsioBufferSizeChange:
  189164. break;
  189165. case kAsioResetRequest:
  189166. if (currentASIODev[deviceIndex] != 0)
  189167. currentASIODev[deviceIndex]->resetRequest();
  189168. return 1;
  189169. case kAsioResyncRequest:
  189170. if (currentASIODev[deviceIndex] != 0)
  189171. currentASIODev[deviceIndex]->resyncRequest();
  189172. return 1;
  189173. case kAsioLatenciesChanged:
  189174. return 1;
  189175. case kAsioEngineVersion:
  189176. return 2;
  189177. case kAsioSupportsTimeInfo:
  189178. case kAsioSupportsTimeCode:
  189179. return 0;
  189180. }
  189181. return 0;
  189182. }
  189183. static void sampleRateChangedCallback (ASIOSampleRate) throw()
  189184. {
  189185. }
  189186. static void convertInt16ToFloat (const char* src,
  189187. float* dest,
  189188. const int srcStrideBytes,
  189189. int numSamples,
  189190. const bool littleEndian) throw()
  189191. {
  189192. const double g = 1.0 / 32768.0;
  189193. if (littleEndian)
  189194. {
  189195. while (--numSamples >= 0)
  189196. {
  189197. *dest++ = (float) (g * (short) ByteOrder::littleEndianShort (src));
  189198. src += srcStrideBytes;
  189199. }
  189200. }
  189201. else
  189202. {
  189203. while (--numSamples >= 0)
  189204. {
  189205. *dest++ = (float) (g * (short) ByteOrder::bigEndianShort (src));
  189206. src += srcStrideBytes;
  189207. }
  189208. }
  189209. }
  189210. static void convertFloatToInt16 (const float* src,
  189211. char* dest,
  189212. const int dstStrideBytes,
  189213. int numSamples,
  189214. const bool littleEndian) throw()
  189215. {
  189216. const double maxVal = (double) 0x7fff;
  189217. if (littleEndian)
  189218. {
  189219. while (--numSamples >= 0)
  189220. {
  189221. *(uint16*) dest = ByteOrder::swapIfBigEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189222. dest += dstStrideBytes;
  189223. }
  189224. }
  189225. else
  189226. {
  189227. while (--numSamples >= 0)
  189228. {
  189229. *(uint16*) dest = ByteOrder::swapIfLittleEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189230. dest += dstStrideBytes;
  189231. }
  189232. }
  189233. }
  189234. static void convertInt24ToFloat (const char* src,
  189235. float* dest,
  189236. const int srcStrideBytes,
  189237. int numSamples,
  189238. const bool littleEndian) throw()
  189239. {
  189240. const double g = 1.0 / 0x7fffff;
  189241. if (littleEndian)
  189242. {
  189243. while (--numSamples >= 0)
  189244. {
  189245. *dest++ = (float) (g * ByteOrder::littleEndian24Bit (src));
  189246. src += srcStrideBytes;
  189247. }
  189248. }
  189249. else
  189250. {
  189251. while (--numSamples >= 0)
  189252. {
  189253. *dest++ = (float) (g * ByteOrder::bigEndian24Bit (src));
  189254. src += srcStrideBytes;
  189255. }
  189256. }
  189257. }
  189258. static void convertFloatToInt24 (const float* src,
  189259. char* dest,
  189260. const int dstStrideBytes,
  189261. int numSamples,
  189262. const bool littleEndian) throw()
  189263. {
  189264. const double maxVal = (double) 0x7fffff;
  189265. if (littleEndian)
  189266. {
  189267. while (--numSamples >= 0)
  189268. {
  189269. ByteOrder::littleEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189270. dest += dstStrideBytes;
  189271. }
  189272. }
  189273. else
  189274. {
  189275. while (--numSamples >= 0)
  189276. {
  189277. ByteOrder::bigEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189278. dest += dstStrideBytes;
  189279. }
  189280. }
  189281. }
  189282. static void convertInt32ToFloat (const char* src,
  189283. float* dest,
  189284. const int srcStrideBytes,
  189285. int numSamples,
  189286. const bool littleEndian) throw()
  189287. {
  189288. const double g = 1.0 / 0x7fffffff;
  189289. if (littleEndian)
  189290. {
  189291. while (--numSamples >= 0)
  189292. {
  189293. *dest++ = (float) (g * (int) ByteOrder::littleEndianInt (src));
  189294. src += srcStrideBytes;
  189295. }
  189296. }
  189297. else
  189298. {
  189299. while (--numSamples >= 0)
  189300. {
  189301. *dest++ = (float) (g * (int) ByteOrder::bigEndianInt (src));
  189302. src += srcStrideBytes;
  189303. }
  189304. }
  189305. }
  189306. static void convertFloatToInt32 (const float* src,
  189307. char* dest,
  189308. const int dstStrideBytes,
  189309. int numSamples,
  189310. const bool littleEndian) throw()
  189311. {
  189312. const double maxVal = (double) 0x7fffffff;
  189313. if (littleEndian)
  189314. {
  189315. while (--numSamples >= 0)
  189316. {
  189317. *(uint32*) dest = ByteOrder::swapIfBigEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189318. dest += dstStrideBytes;
  189319. }
  189320. }
  189321. else
  189322. {
  189323. while (--numSamples >= 0)
  189324. {
  189325. *(uint32*) dest = ByteOrder::swapIfLittleEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189326. dest += dstStrideBytes;
  189327. }
  189328. }
  189329. }
  189330. static void typeToFormatParameters (const long type,
  189331. int& bitDepth,
  189332. int& byteStride,
  189333. bool& formatIsFloat,
  189334. bool& littleEndian) throw()
  189335. {
  189336. bitDepth = 0;
  189337. littleEndian = false;
  189338. formatIsFloat = false;
  189339. switch (type)
  189340. {
  189341. case ASIOSTInt16MSB:
  189342. case ASIOSTInt16LSB:
  189343. case ASIOSTInt32MSB16:
  189344. case ASIOSTInt32LSB16:
  189345. bitDepth = 16; break;
  189346. case ASIOSTFloat32MSB:
  189347. case ASIOSTFloat32LSB:
  189348. formatIsFloat = true;
  189349. bitDepth = 32; break;
  189350. case ASIOSTInt32MSB:
  189351. case ASIOSTInt32LSB:
  189352. bitDepth = 32; break;
  189353. case ASIOSTInt24MSB:
  189354. case ASIOSTInt24LSB:
  189355. case ASIOSTInt32MSB24:
  189356. case ASIOSTInt32LSB24:
  189357. case ASIOSTInt32MSB18:
  189358. case ASIOSTInt32MSB20:
  189359. case ASIOSTInt32LSB18:
  189360. case ASIOSTInt32LSB20:
  189361. bitDepth = 24; break;
  189362. case ASIOSTFloat64MSB:
  189363. case ASIOSTFloat64LSB:
  189364. default:
  189365. bitDepth = 64;
  189366. break;
  189367. }
  189368. switch (type)
  189369. {
  189370. case ASIOSTInt16MSB:
  189371. case ASIOSTInt32MSB16:
  189372. case ASIOSTFloat32MSB:
  189373. case ASIOSTFloat64MSB:
  189374. case ASIOSTInt32MSB:
  189375. case ASIOSTInt32MSB18:
  189376. case ASIOSTInt32MSB20:
  189377. case ASIOSTInt32MSB24:
  189378. case ASIOSTInt24MSB:
  189379. littleEndian = false; break;
  189380. case ASIOSTInt16LSB:
  189381. case ASIOSTInt32LSB16:
  189382. case ASIOSTFloat32LSB:
  189383. case ASIOSTFloat64LSB:
  189384. case ASIOSTInt32LSB:
  189385. case ASIOSTInt32LSB18:
  189386. case ASIOSTInt32LSB20:
  189387. case ASIOSTInt32LSB24:
  189388. case ASIOSTInt24LSB:
  189389. littleEndian = true; break;
  189390. default:
  189391. break;
  189392. }
  189393. switch (type)
  189394. {
  189395. case ASIOSTInt16LSB:
  189396. case ASIOSTInt16MSB:
  189397. byteStride = 2; break;
  189398. case ASIOSTInt24LSB:
  189399. case ASIOSTInt24MSB:
  189400. byteStride = 3; break;
  189401. case ASIOSTInt32MSB16:
  189402. case ASIOSTInt32LSB16:
  189403. case ASIOSTInt32MSB:
  189404. case ASIOSTInt32MSB18:
  189405. case ASIOSTInt32MSB20:
  189406. case ASIOSTInt32MSB24:
  189407. case ASIOSTInt32LSB:
  189408. case ASIOSTInt32LSB18:
  189409. case ASIOSTInt32LSB20:
  189410. case ASIOSTInt32LSB24:
  189411. case ASIOSTFloat32LSB:
  189412. case ASIOSTFloat32MSB:
  189413. byteStride = 4; break;
  189414. case ASIOSTFloat64MSB:
  189415. case ASIOSTFloat64LSB:
  189416. byteStride = 8; break;
  189417. default:
  189418. break;
  189419. }
  189420. }
  189421. };
  189422. class ASIOAudioIODeviceType : public AudioIODeviceType
  189423. {
  189424. public:
  189425. ASIOAudioIODeviceType()
  189426. : AudioIODeviceType ("ASIO"),
  189427. hasScanned (false)
  189428. {
  189429. CoInitialize (0);
  189430. }
  189431. ~ASIOAudioIODeviceType()
  189432. {
  189433. }
  189434. void scanForDevices()
  189435. {
  189436. hasScanned = true;
  189437. deviceNames.clear();
  189438. classIds.clear();
  189439. HKEY hk = 0;
  189440. int index = 0;
  189441. if (RegOpenKeyA (HKEY_LOCAL_MACHINE, "software\\asio", &hk) == ERROR_SUCCESS)
  189442. {
  189443. for (;;)
  189444. {
  189445. char name [256];
  189446. if (RegEnumKeyA (hk, index++, name, 256) == ERROR_SUCCESS)
  189447. {
  189448. addDriverInfo (name, hk);
  189449. }
  189450. else
  189451. {
  189452. break;
  189453. }
  189454. }
  189455. RegCloseKey (hk);
  189456. }
  189457. }
  189458. const StringArray getDeviceNames (const bool /*wantInputNames*/) const
  189459. {
  189460. jassert (hasScanned); // need to call scanForDevices() before doing this
  189461. return deviceNames;
  189462. }
  189463. int getDefaultDeviceIndex (const bool) const
  189464. {
  189465. jassert (hasScanned); // need to call scanForDevices() before doing this
  189466. for (int i = deviceNames.size(); --i >= 0;)
  189467. if (deviceNames[i].containsIgnoreCase (T("asio4all")))
  189468. return i; // asio4all is a safe choice for a default..
  189469. #if JUCE_DEBUG
  189470. if (deviceNames.size() > 1 && deviceNames[0].containsIgnoreCase (T("digidesign")))
  189471. return 1; // (the digi m-box driver crashes the app when you run
  189472. // it in the debugger, which can be a bit annoying)
  189473. #endif
  189474. return 0;
  189475. }
  189476. static int findFreeSlot()
  189477. {
  189478. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  189479. if (currentASIODev[i] == 0)
  189480. return i;
  189481. jassertfalse; // unfortunately you can only have a finite number
  189482. // of ASIO devices open at the same time..
  189483. return -1;
  189484. }
  189485. int getIndexOfDevice (AudioIODevice* d, const bool /*asInput*/) const
  189486. {
  189487. jassert (hasScanned); // need to call scanForDevices() before doing this
  189488. return d == 0 ? -1 : deviceNames.indexOf (d->getName());
  189489. }
  189490. bool hasSeparateInputsAndOutputs() const { return false; }
  189491. AudioIODevice* createDevice (const String& outputDeviceName,
  189492. const String& inputDeviceName)
  189493. {
  189494. // ASIO can't open two different devices for input and output - they must be the same one.
  189495. jassert (inputDeviceName == outputDeviceName || outputDeviceName.isEmpty() || inputDeviceName.isEmpty());
  189496. jassert (hasScanned); // need to call scanForDevices() before doing this
  189497. const int index = deviceNames.indexOf (outputDeviceName.isNotEmpty() ? outputDeviceName
  189498. : inputDeviceName);
  189499. if (index >= 0)
  189500. {
  189501. const int freeSlot = findFreeSlot();
  189502. if (freeSlot >= 0)
  189503. return new ASIOAudioIODevice (outputDeviceName, *(classIds [index]), freeSlot, String::empty);
  189504. }
  189505. return 0;
  189506. }
  189507. juce_UseDebuggingNewOperator
  189508. private:
  189509. StringArray deviceNames;
  189510. OwnedArray <CLSID> classIds;
  189511. bool hasScanned;
  189512. static bool checkClassIsOk (const String& classId)
  189513. {
  189514. HKEY hk = 0;
  189515. bool ok = false;
  189516. if (RegOpenKey (HKEY_CLASSES_ROOT, _T("clsid"), &hk) == ERROR_SUCCESS)
  189517. {
  189518. int index = 0;
  189519. for (;;)
  189520. {
  189521. WCHAR buf [512];
  189522. if (RegEnumKey (hk, index++, buf, 512) == ERROR_SUCCESS)
  189523. {
  189524. if (classId.equalsIgnoreCase (buf))
  189525. {
  189526. HKEY subKey, pathKey;
  189527. if (RegOpenKeyEx (hk, buf, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  189528. {
  189529. if (RegOpenKeyEx (subKey, _T("InprocServer32"), 0, KEY_READ, &pathKey) == ERROR_SUCCESS)
  189530. {
  189531. WCHAR pathName [1024];
  189532. DWORD dtype = REG_SZ;
  189533. DWORD dsize = sizeof (pathName);
  189534. if (RegQueryValueEx (pathKey, 0, 0, &dtype, (LPBYTE) pathName, &dsize) == ERROR_SUCCESS)
  189535. ok = File (pathName).exists();
  189536. RegCloseKey (pathKey);
  189537. }
  189538. RegCloseKey (subKey);
  189539. }
  189540. break;
  189541. }
  189542. }
  189543. else
  189544. {
  189545. break;
  189546. }
  189547. }
  189548. RegCloseKey (hk);
  189549. }
  189550. return ok;
  189551. }
  189552. void addDriverInfo (const String& keyName, HKEY hk)
  189553. {
  189554. HKEY subKey;
  189555. if (RegOpenKeyEx (hk, keyName, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  189556. {
  189557. WCHAR buf [256];
  189558. zerostruct (buf);
  189559. DWORD dtype = REG_SZ;
  189560. DWORD dsize = sizeof (buf);
  189561. if (RegQueryValueEx (subKey, _T("clsid"), 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  189562. {
  189563. if (dsize > 0 && checkClassIsOk (buf))
  189564. {
  189565. CLSID classId;
  189566. if (CLSIDFromString ((LPOLESTR) buf, &classId) == S_OK)
  189567. {
  189568. dtype = REG_SZ;
  189569. dsize = sizeof (buf);
  189570. String deviceName;
  189571. if (RegQueryValueEx (subKey, _T("description"), 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  189572. deviceName = buf;
  189573. else
  189574. deviceName = keyName;
  189575. log ("found " + deviceName);
  189576. deviceNames.add (deviceName);
  189577. classIds.add (new CLSID (classId));
  189578. }
  189579. }
  189580. RegCloseKey (subKey);
  189581. }
  189582. }
  189583. }
  189584. ASIOAudioIODeviceType (const ASIOAudioIODeviceType&);
  189585. ASIOAudioIODeviceType& operator= (const ASIOAudioIODeviceType&);
  189586. };
  189587. AudioIODeviceType* juce_createAudioIODeviceType_ASIO()
  189588. {
  189589. return new ASIOAudioIODeviceType();
  189590. }
  189591. AudioIODevice* juce_createASIOAudioIODeviceForGUID (const String& name,
  189592. void* guid,
  189593. const String& optionalDllForDirectLoading)
  189594. {
  189595. const int freeSlot = ASIOAudioIODeviceType::findFreeSlot();
  189596. if (freeSlot < 0)
  189597. return 0;
  189598. return new ASIOAudioIODevice (name, *(CLSID*) guid, freeSlot, optionalDllForDirectLoading);
  189599. }
  189600. #undef log
  189601. #endif
  189602. /*** End of inlined file: juce_win32_ASIO.cpp ***/
  189603. /*** Start of inlined file: juce_win32_DirectSound.cpp ***/
  189604. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  189605. // compiled on its own).
  189606. #if JUCE_INCLUDED_FILE && JUCE_DIRECTSOUND
  189607. END_JUCE_NAMESPACE
  189608. extern "C"
  189609. {
  189610. // Declare just the minimum number of interfaces for the DSound objects that we need..
  189611. typedef struct typeDSBUFFERDESC
  189612. {
  189613. DWORD dwSize;
  189614. DWORD dwFlags;
  189615. DWORD dwBufferBytes;
  189616. DWORD dwReserved;
  189617. LPWAVEFORMATEX lpwfxFormat;
  189618. GUID guid3DAlgorithm;
  189619. } DSBUFFERDESC;
  189620. struct IDirectSoundBuffer;
  189621. #undef INTERFACE
  189622. #define INTERFACE IDirectSound
  189623. DECLARE_INTERFACE_(IDirectSound, IUnknown)
  189624. {
  189625. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189626. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189627. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189628. STDMETHOD(CreateSoundBuffer) (THIS_ DSBUFFERDESC*, IDirectSoundBuffer**, LPUNKNOWN) PURE;
  189629. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189630. STDMETHOD(DuplicateSoundBuffer) (THIS_ IDirectSoundBuffer*, IDirectSoundBuffer**) PURE;
  189631. STDMETHOD(SetCooperativeLevel) (THIS_ HWND, DWORD) PURE;
  189632. STDMETHOD(Compact) (THIS) PURE;
  189633. STDMETHOD(GetSpeakerConfig) (THIS_ LPDWORD) PURE;
  189634. STDMETHOD(SetSpeakerConfig) (THIS_ DWORD) PURE;
  189635. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  189636. };
  189637. #undef INTERFACE
  189638. #define INTERFACE IDirectSoundBuffer
  189639. DECLARE_INTERFACE_(IDirectSoundBuffer, IUnknown)
  189640. {
  189641. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189642. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189643. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189644. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189645. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  189646. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  189647. STDMETHOD(GetVolume) (THIS_ LPLONG) PURE;
  189648. STDMETHOD(GetPan) (THIS_ LPLONG) PURE;
  189649. STDMETHOD(GetFrequency) (THIS_ LPDWORD) PURE;
  189650. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  189651. STDMETHOD(Initialize) (THIS_ IDirectSound*, DSBUFFERDESC*) PURE;
  189652. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  189653. STDMETHOD(Play) (THIS_ DWORD, DWORD, DWORD) PURE;
  189654. STDMETHOD(SetCurrentPosition) (THIS_ DWORD) PURE;
  189655. STDMETHOD(SetFormat) (THIS_ const WAVEFORMATEX*) PURE;
  189656. STDMETHOD(SetVolume) (THIS_ LONG) PURE;
  189657. STDMETHOD(SetPan) (THIS_ LONG) PURE;
  189658. STDMETHOD(SetFrequency) (THIS_ DWORD) PURE;
  189659. STDMETHOD(Stop) (THIS) PURE;
  189660. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  189661. STDMETHOD(Restore) (THIS) PURE;
  189662. };
  189663. typedef struct typeDSCBUFFERDESC
  189664. {
  189665. DWORD dwSize;
  189666. DWORD dwFlags;
  189667. DWORD dwBufferBytes;
  189668. DWORD dwReserved;
  189669. LPWAVEFORMATEX lpwfxFormat;
  189670. } DSCBUFFERDESC;
  189671. struct IDirectSoundCaptureBuffer;
  189672. #undef INTERFACE
  189673. #define INTERFACE IDirectSoundCapture
  189674. DECLARE_INTERFACE_(IDirectSoundCapture, IUnknown)
  189675. {
  189676. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189677. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189678. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189679. STDMETHOD(CreateCaptureBuffer) (THIS_ DSCBUFFERDESC*, IDirectSoundCaptureBuffer**, LPUNKNOWN) PURE;
  189680. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189681. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  189682. };
  189683. #undef INTERFACE
  189684. #define INTERFACE IDirectSoundCaptureBuffer
  189685. DECLARE_INTERFACE_(IDirectSoundCaptureBuffer, IUnknown)
  189686. {
  189687. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189688. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189689. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189690. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189691. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  189692. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  189693. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  189694. STDMETHOD(Initialize) (THIS_ IDirectSoundCapture*, DSCBUFFERDESC*) PURE;
  189695. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  189696. STDMETHOD(Start) (THIS_ DWORD) PURE;
  189697. STDMETHOD(Stop) (THIS) PURE;
  189698. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  189699. };
  189700. };
  189701. BEGIN_JUCE_NAMESPACE
  189702. static const String getDSErrorMessage (HRESULT hr)
  189703. {
  189704. const char* result = 0;
  189705. switch (hr)
  189706. {
  189707. case MAKE_HRESULT(1, 0x878, 10):
  189708. result = "Device already allocated";
  189709. break;
  189710. case MAKE_HRESULT(1, 0x878, 30):
  189711. result = "Control unavailable";
  189712. break;
  189713. case E_INVALIDARG:
  189714. result = "Invalid parameter";
  189715. break;
  189716. case MAKE_HRESULT(1, 0x878, 50):
  189717. result = "Invalid call";
  189718. break;
  189719. case E_FAIL:
  189720. result = "Generic error";
  189721. break;
  189722. case MAKE_HRESULT(1, 0x878, 70):
  189723. result = "Priority level error";
  189724. break;
  189725. case E_OUTOFMEMORY:
  189726. result = "Out of memory";
  189727. break;
  189728. case MAKE_HRESULT(1, 0x878, 100):
  189729. result = "Bad format";
  189730. break;
  189731. case E_NOTIMPL:
  189732. result = "Unsupported function";
  189733. break;
  189734. case MAKE_HRESULT(1, 0x878, 120):
  189735. result = "No driver";
  189736. break;
  189737. case MAKE_HRESULT(1, 0x878, 130):
  189738. result = "Already initialised";
  189739. break;
  189740. case CLASS_E_NOAGGREGATION:
  189741. result = "No aggregation";
  189742. break;
  189743. case MAKE_HRESULT(1, 0x878, 150):
  189744. result = "Buffer lost";
  189745. break;
  189746. case MAKE_HRESULT(1, 0x878, 160):
  189747. result = "Another app has priority";
  189748. break;
  189749. case MAKE_HRESULT(1, 0x878, 170):
  189750. result = "Uninitialised";
  189751. break;
  189752. case E_NOINTERFACE:
  189753. result = "No interface";
  189754. break;
  189755. case S_OK:
  189756. result = "No error";
  189757. break;
  189758. default:
  189759. return "Unknown error: " + String ((int) hr);
  189760. }
  189761. return result;
  189762. }
  189763. #define DS_DEBUGGING 1
  189764. #ifdef DS_DEBUGGING
  189765. #define CATCH JUCE_CATCH_EXCEPTION
  189766. #undef log
  189767. #define log(a) Logger::writeToLog(a);
  189768. #undef logError
  189769. #define logError(a) logDSError(a, __LINE__);
  189770. static void logDSError (HRESULT hr, int lineNum)
  189771. {
  189772. if (hr != S_OK)
  189773. {
  189774. String error ("DS error at line ");
  189775. error << lineNum << " - " << getDSErrorMessage (hr);
  189776. log (error);
  189777. }
  189778. }
  189779. #else
  189780. #define CATCH JUCE_CATCH_ALL
  189781. #define log(a)
  189782. #define logError(a)
  189783. #endif
  189784. #define DSOUND_FUNCTION(functionName, params) \
  189785. typedef HRESULT (WINAPI *type##functionName) params; \
  189786. static type##functionName ds##functionName = 0;
  189787. #define DSOUND_FUNCTION_LOAD(functionName) \
  189788. ds##functionName = (type##functionName) GetProcAddress (h, #functionName); \
  189789. jassert (ds##functionName != 0);
  189790. typedef BOOL (CALLBACK *LPDSENUMCALLBACKW) (LPGUID, LPCWSTR, LPCWSTR, LPVOID);
  189791. typedef BOOL (CALLBACK *LPDSENUMCALLBACKA) (LPGUID, LPCSTR, LPCSTR, LPVOID);
  189792. DSOUND_FUNCTION (DirectSoundCreate, (const GUID*, IDirectSound**, LPUNKNOWN))
  189793. DSOUND_FUNCTION (DirectSoundCaptureCreate, (const GUID*, IDirectSoundCapture**, LPUNKNOWN))
  189794. DSOUND_FUNCTION (DirectSoundEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  189795. DSOUND_FUNCTION (DirectSoundCaptureEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  189796. static void initialiseDSoundFunctions()
  189797. {
  189798. if (dsDirectSoundCreate == 0)
  189799. {
  189800. HMODULE h = LoadLibraryA ("dsound.dll");
  189801. DSOUND_FUNCTION_LOAD (DirectSoundCreate)
  189802. DSOUND_FUNCTION_LOAD (DirectSoundCaptureCreate)
  189803. DSOUND_FUNCTION_LOAD (DirectSoundEnumerateW)
  189804. DSOUND_FUNCTION_LOAD (DirectSoundCaptureEnumerateW)
  189805. }
  189806. }
  189807. class DSoundInternalOutChannel
  189808. {
  189809. String name;
  189810. LPGUID guid;
  189811. int sampleRate, bufferSizeSamples;
  189812. float* leftBuffer;
  189813. float* rightBuffer;
  189814. IDirectSound* pDirectSound;
  189815. IDirectSoundBuffer* pOutputBuffer;
  189816. DWORD writeOffset;
  189817. int totalBytesPerBuffer;
  189818. int bytesPerBuffer;
  189819. unsigned int lastPlayCursor;
  189820. public:
  189821. int bitDepth;
  189822. bool doneFlag;
  189823. DSoundInternalOutChannel (const String& name_,
  189824. LPGUID guid_,
  189825. int rate,
  189826. int bufferSize,
  189827. float* left,
  189828. float* right)
  189829. : name (name_),
  189830. guid (guid_),
  189831. sampleRate (rate),
  189832. bufferSizeSamples (bufferSize),
  189833. leftBuffer (left),
  189834. rightBuffer (right),
  189835. pDirectSound (0),
  189836. pOutputBuffer (0),
  189837. bitDepth (16)
  189838. {
  189839. }
  189840. ~DSoundInternalOutChannel()
  189841. {
  189842. close();
  189843. }
  189844. void close()
  189845. {
  189846. HRESULT hr;
  189847. if (pOutputBuffer != 0)
  189848. {
  189849. JUCE_TRY
  189850. {
  189851. log ("closing dsound out: " + name);
  189852. hr = pOutputBuffer->Stop();
  189853. logError (hr);
  189854. }
  189855. CATCH
  189856. JUCE_TRY
  189857. {
  189858. hr = pOutputBuffer->Release();
  189859. logError (hr);
  189860. }
  189861. CATCH
  189862. pOutputBuffer = 0;
  189863. }
  189864. if (pDirectSound != 0)
  189865. {
  189866. JUCE_TRY
  189867. {
  189868. hr = pDirectSound->Release();
  189869. logError (hr);
  189870. }
  189871. CATCH
  189872. pDirectSound = 0;
  189873. }
  189874. }
  189875. const String open()
  189876. {
  189877. log ("opening dsound out device: " + name + " rate=" + String (sampleRate)
  189878. + " bits=" + String (bitDepth) + " buf=" + String (bufferSizeSamples));
  189879. pDirectSound = 0;
  189880. pOutputBuffer = 0;
  189881. writeOffset = 0;
  189882. String error;
  189883. HRESULT hr = E_NOINTERFACE;
  189884. if (dsDirectSoundCreate != 0)
  189885. hr = dsDirectSoundCreate (guid, &pDirectSound, 0);
  189886. if (hr == S_OK)
  189887. {
  189888. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  189889. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  189890. const int numChannels = 2;
  189891. hr = pDirectSound->SetCooperativeLevel (GetDesktopWindow(), 2 /* DSSCL_PRIORITY */);
  189892. logError (hr);
  189893. if (hr == S_OK)
  189894. {
  189895. IDirectSoundBuffer* pPrimaryBuffer;
  189896. DSBUFFERDESC primaryDesc;
  189897. zerostruct (primaryDesc);
  189898. primaryDesc.dwSize = sizeof (DSBUFFERDESC);
  189899. primaryDesc.dwFlags = 1 /* DSBCAPS_PRIMARYBUFFER */;
  189900. primaryDesc.dwBufferBytes = 0;
  189901. primaryDesc.lpwfxFormat = 0;
  189902. log ("opening dsound out step 2");
  189903. hr = pDirectSound->CreateSoundBuffer (&primaryDesc, &pPrimaryBuffer, 0);
  189904. logError (hr);
  189905. if (hr == S_OK)
  189906. {
  189907. WAVEFORMATEX wfFormat;
  189908. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  189909. wfFormat.nChannels = (unsigned short) numChannels;
  189910. wfFormat.nSamplesPerSec = sampleRate;
  189911. wfFormat.wBitsPerSample = (unsigned short) bitDepth;
  189912. wfFormat.nBlockAlign = (unsigned short) (wfFormat.nChannels * wfFormat.wBitsPerSample / 8);
  189913. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  189914. wfFormat.cbSize = 0;
  189915. hr = pPrimaryBuffer->SetFormat (&wfFormat);
  189916. logError (hr);
  189917. if (hr == S_OK)
  189918. {
  189919. DSBUFFERDESC secondaryDesc;
  189920. zerostruct (secondaryDesc);
  189921. secondaryDesc.dwSize = sizeof (DSBUFFERDESC);
  189922. secondaryDesc.dwFlags = 0x8000 /* DSBCAPS_GLOBALFOCUS */
  189923. | 0x10000 /* DSBCAPS_GETCURRENTPOSITION2 */;
  189924. secondaryDesc.dwBufferBytes = totalBytesPerBuffer;
  189925. secondaryDesc.lpwfxFormat = &wfFormat;
  189926. hr = pDirectSound->CreateSoundBuffer (&secondaryDesc, &pOutputBuffer, 0);
  189927. logError (hr);
  189928. if (hr == S_OK)
  189929. {
  189930. log ("opening dsound out step 3");
  189931. DWORD dwDataLen;
  189932. unsigned char* pDSBuffData;
  189933. hr = pOutputBuffer->Lock (0, totalBytesPerBuffer,
  189934. (LPVOID*) &pDSBuffData, &dwDataLen, 0, 0, 0);
  189935. logError (hr);
  189936. if (hr == S_OK)
  189937. {
  189938. zeromem (pDSBuffData, dwDataLen);
  189939. hr = pOutputBuffer->Unlock (pDSBuffData, dwDataLen, 0, 0);
  189940. if (hr == S_OK)
  189941. {
  189942. hr = pOutputBuffer->SetCurrentPosition (0);
  189943. if (hr == S_OK)
  189944. {
  189945. hr = pOutputBuffer->Play (0, 0, 1 /* DSBPLAY_LOOPING */);
  189946. if (hr == S_OK)
  189947. return String::empty;
  189948. }
  189949. }
  189950. }
  189951. }
  189952. }
  189953. }
  189954. }
  189955. }
  189956. error = getDSErrorMessage (hr);
  189957. close();
  189958. return error;
  189959. }
  189960. void synchronisePosition()
  189961. {
  189962. if (pOutputBuffer != 0)
  189963. {
  189964. DWORD playCursor;
  189965. pOutputBuffer->GetCurrentPosition (&playCursor, &writeOffset);
  189966. }
  189967. }
  189968. bool service()
  189969. {
  189970. if (pOutputBuffer == 0)
  189971. return true;
  189972. DWORD playCursor, writeCursor;
  189973. for (;;)
  189974. {
  189975. HRESULT hr = pOutputBuffer->GetCurrentPosition (&playCursor, &writeCursor);
  189976. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  189977. {
  189978. pOutputBuffer->Restore();
  189979. continue;
  189980. }
  189981. if (hr == S_OK)
  189982. break;
  189983. logError (hr);
  189984. jassertfalse
  189985. return true;
  189986. }
  189987. int playWriteGap = writeCursor - playCursor;
  189988. if (playWriteGap < 0)
  189989. playWriteGap += totalBytesPerBuffer;
  189990. int bytesEmpty = playCursor - writeOffset;
  189991. if (bytesEmpty < 0)
  189992. bytesEmpty += totalBytesPerBuffer;
  189993. if (bytesEmpty > (totalBytesPerBuffer - playWriteGap))
  189994. {
  189995. writeOffset = writeCursor;
  189996. bytesEmpty = totalBytesPerBuffer - playWriteGap;
  189997. }
  189998. if (bytesEmpty >= bytesPerBuffer)
  189999. {
  190000. LPBYTE lpbuf1 = 0;
  190001. LPBYTE lpbuf2 = 0;
  190002. DWORD dwSize1 = 0;
  190003. DWORD dwSize2 = 0;
  190004. HRESULT hr = pOutputBuffer->Lock (writeOffset,
  190005. bytesPerBuffer,
  190006. (void**) &lpbuf1, &dwSize1,
  190007. (void**) &lpbuf2, &dwSize2, 0);
  190008. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  190009. {
  190010. pOutputBuffer->Restore();
  190011. hr = pOutputBuffer->Lock (writeOffset,
  190012. bytesPerBuffer,
  190013. (void**) &lpbuf1, &dwSize1,
  190014. (void**) &lpbuf2, &dwSize2, 0);
  190015. }
  190016. if (hr == S_OK)
  190017. {
  190018. if (bitDepth == 16)
  190019. {
  190020. const float gainL = 32767.0f;
  190021. const float gainR = 32767.0f;
  190022. int* dest = (int*)lpbuf1;
  190023. const float* left = leftBuffer;
  190024. const float* right = rightBuffer;
  190025. int samples1 = dwSize1 >> 2;
  190026. int samples2 = dwSize2 >> 2;
  190027. if (left == 0)
  190028. {
  190029. while (--samples1 >= 0)
  190030. {
  190031. int r = roundToInt (gainR * *right++);
  190032. if (r < -32768)
  190033. r = -32768;
  190034. else if (r > 32767)
  190035. r = 32767;
  190036. *dest++ = (r << 16);
  190037. }
  190038. dest = (int*)lpbuf2;
  190039. while (--samples2 >= 0)
  190040. {
  190041. int r = roundToInt (gainR * *right++);
  190042. if (r < -32768)
  190043. r = -32768;
  190044. else if (r > 32767)
  190045. r = 32767;
  190046. *dest++ = (r << 16);
  190047. }
  190048. }
  190049. else if (right == 0)
  190050. {
  190051. while (--samples1 >= 0)
  190052. {
  190053. int l = roundToInt (gainL * *left++);
  190054. if (l < -32768)
  190055. l = -32768;
  190056. else if (l > 32767)
  190057. l = 32767;
  190058. l &= 0xffff;
  190059. *dest++ = l;
  190060. }
  190061. dest = (int*)lpbuf2;
  190062. while (--samples2 >= 0)
  190063. {
  190064. int l = roundToInt (gainL * *left++);
  190065. if (l < -32768)
  190066. l = -32768;
  190067. else if (l > 32767)
  190068. l = 32767;
  190069. l &= 0xffff;
  190070. *dest++ = l;
  190071. }
  190072. }
  190073. else
  190074. {
  190075. while (--samples1 >= 0)
  190076. {
  190077. int l = roundToInt (gainL * *left++);
  190078. if (l < -32768)
  190079. l = -32768;
  190080. else if (l > 32767)
  190081. l = 32767;
  190082. l &= 0xffff;
  190083. int r = roundToInt (gainR * *right++);
  190084. if (r < -32768)
  190085. r = -32768;
  190086. else if (r > 32767)
  190087. r = 32767;
  190088. *dest++ = (r << 16) | l;
  190089. }
  190090. dest = (int*)lpbuf2;
  190091. while (--samples2 >= 0)
  190092. {
  190093. int l = roundToInt (gainL * *left++);
  190094. if (l < -32768)
  190095. l = -32768;
  190096. else if (l > 32767)
  190097. l = 32767;
  190098. l &= 0xffff;
  190099. int r = roundToInt (gainR * *right++);
  190100. if (r < -32768)
  190101. r = -32768;
  190102. else if (r > 32767)
  190103. r = 32767;
  190104. *dest++ = (r << 16) | l;
  190105. }
  190106. }
  190107. }
  190108. else
  190109. {
  190110. jassertfalse
  190111. }
  190112. writeOffset = (writeOffset + dwSize1 + dwSize2) % totalBytesPerBuffer;
  190113. pOutputBuffer->Unlock (lpbuf1, dwSize1, lpbuf2, dwSize2);
  190114. }
  190115. else
  190116. {
  190117. jassertfalse
  190118. logError (hr);
  190119. }
  190120. bytesEmpty -= bytesPerBuffer;
  190121. return true;
  190122. }
  190123. else
  190124. {
  190125. return false;
  190126. }
  190127. }
  190128. };
  190129. struct DSoundInternalInChannel
  190130. {
  190131. String name;
  190132. LPGUID guid;
  190133. int sampleRate, bufferSizeSamples;
  190134. float* leftBuffer;
  190135. float* rightBuffer;
  190136. IDirectSound* pDirectSound;
  190137. IDirectSoundCapture* pDirectSoundCapture;
  190138. IDirectSoundCaptureBuffer* pInputBuffer;
  190139. public:
  190140. unsigned int readOffset;
  190141. int bytesPerBuffer, totalBytesPerBuffer;
  190142. int bitDepth;
  190143. bool doneFlag;
  190144. DSoundInternalInChannel (const String& name_,
  190145. LPGUID guid_,
  190146. int rate,
  190147. int bufferSize,
  190148. float* left,
  190149. float* right)
  190150. : name (name_),
  190151. guid (guid_),
  190152. sampleRate (rate),
  190153. bufferSizeSamples (bufferSize),
  190154. leftBuffer (left),
  190155. rightBuffer (right),
  190156. pDirectSound (0),
  190157. pDirectSoundCapture (0),
  190158. pInputBuffer (0),
  190159. bitDepth (16)
  190160. {
  190161. }
  190162. ~DSoundInternalInChannel()
  190163. {
  190164. close();
  190165. }
  190166. void close()
  190167. {
  190168. HRESULT hr;
  190169. if (pInputBuffer != 0)
  190170. {
  190171. JUCE_TRY
  190172. {
  190173. log ("closing dsound in: " + name);
  190174. hr = pInputBuffer->Stop();
  190175. logError (hr);
  190176. }
  190177. CATCH
  190178. JUCE_TRY
  190179. {
  190180. hr = pInputBuffer->Release();
  190181. logError (hr);
  190182. }
  190183. CATCH
  190184. pInputBuffer = 0;
  190185. }
  190186. if (pDirectSoundCapture != 0)
  190187. {
  190188. JUCE_TRY
  190189. {
  190190. hr = pDirectSoundCapture->Release();
  190191. logError (hr);
  190192. }
  190193. CATCH
  190194. pDirectSoundCapture = 0;
  190195. }
  190196. if (pDirectSound != 0)
  190197. {
  190198. JUCE_TRY
  190199. {
  190200. hr = pDirectSound->Release();
  190201. logError (hr);
  190202. }
  190203. CATCH
  190204. pDirectSound = 0;
  190205. }
  190206. }
  190207. const String open()
  190208. {
  190209. log ("opening dsound in device: " + name
  190210. + " rate=" + String (sampleRate) + " bits=" + String (bitDepth) + " buf=" + String (bufferSizeSamples));
  190211. pDirectSound = 0;
  190212. pDirectSoundCapture = 0;
  190213. pInputBuffer = 0;
  190214. readOffset = 0;
  190215. totalBytesPerBuffer = 0;
  190216. String error;
  190217. HRESULT hr = E_NOINTERFACE;
  190218. if (dsDirectSoundCaptureCreate != 0)
  190219. hr = dsDirectSoundCaptureCreate (guid, &pDirectSoundCapture, 0);
  190220. logError (hr);
  190221. if (hr == S_OK)
  190222. {
  190223. const int numChannels = 2;
  190224. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  190225. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  190226. WAVEFORMATEX wfFormat;
  190227. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  190228. wfFormat.nChannels = (unsigned short)numChannels;
  190229. wfFormat.nSamplesPerSec = sampleRate;
  190230. wfFormat.wBitsPerSample = (unsigned short)bitDepth;
  190231. wfFormat.nBlockAlign = (unsigned short)(wfFormat.nChannels * (wfFormat.wBitsPerSample / 8));
  190232. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  190233. wfFormat.cbSize = 0;
  190234. DSCBUFFERDESC captureDesc;
  190235. zerostruct (captureDesc);
  190236. captureDesc.dwSize = sizeof (DSCBUFFERDESC);
  190237. captureDesc.dwFlags = 0;
  190238. captureDesc.dwBufferBytes = totalBytesPerBuffer;
  190239. captureDesc.lpwfxFormat = &wfFormat;
  190240. log ("opening dsound in step 2");
  190241. hr = pDirectSoundCapture->CreateCaptureBuffer (&captureDesc, &pInputBuffer, 0);
  190242. logError (hr);
  190243. if (hr == S_OK)
  190244. {
  190245. hr = pInputBuffer->Start (1 /* DSCBSTART_LOOPING */);
  190246. logError (hr);
  190247. if (hr == S_OK)
  190248. return String::empty;
  190249. }
  190250. }
  190251. error = getDSErrorMessage (hr);
  190252. close();
  190253. return error;
  190254. }
  190255. void synchronisePosition()
  190256. {
  190257. if (pInputBuffer != 0)
  190258. {
  190259. DWORD capturePos;
  190260. pInputBuffer->GetCurrentPosition (&capturePos, (DWORD*)&readOffset);
  190261. }
  190262. }
  190263. bool service()
  190264. {
  190265. if (pInputBuffer == 0)
  190266. return true;
  190267. DWORD capturePos, readPos;
  190268. HRESULT hr = pInputBuffer->GetCurrentPosition (&capturePos, &readPos);
  190269. logError (hr);
  190270. if (hr != S_OK)
  190271. return true;
  190272. int bytesFilled = readPos - readOffset;
  190273. if (bytesFilled < 0)
  190274. bytesFilled += totalBytesPerBuffer;
  190275. if (bytesFilled >= bytesPerBuffer)
  190276. {
  190277. LPBYTE lpbuf1 = 0;
  190278. LPBYTE lpbuf2 = 0;
  190279. DWORD dwsize1 = 0;
  190280. DWORD dwsize2 = 0;
  190281. HRESULT hr = pInputBuffer->Lock (readOffset,
  190282. bytesPerBuffer,
  190283. (void**) &lpbuf1, &dwsize1,
  190284. (void**) &lpbuf2, &dwsize2, 0);
  190285. if (hr == S_OK)
  190286. {
  190287. if (bitDepth == 16)
  190288. {
  190289. const float g = 1.0f / 32768.0f;
  190290. float* destL = leftBuffer;
  190291. float* destR = rightBuffer;
  190292. int samples1 = dwsize1 >> 2;
  190293. int samples2 = dwsize2 >> 2;
  190294. const short* src = (const short*)lpbuf1;
  190295. if (destL == 0)
  190296. {
  190297. while (--samples1 >= 0)
  190298. {
  190299. ++src;
  190300. *destR++ = *src++ * g;
  190301. }
  190302. src = (const short*)lpbuf2;
  190303. while (--samples2 >= 0)
  190304. {
  190305. ++src;
  190306. *destR++ = *src++ * g;
  190307. }
  190308. }
  190309. else if (destR == 0)
  190310. {
  190311. while (--samples1 >= 0)
  190312. {
  190313. *destL++ = *src++ * g;
  190314. ++src;
  190315. }
  190316. src = (const short*)lpbuf2;
  190317. while (--samples2 >= 0)
  190318. {
  190319. *destL++ = *src++ * g;
  190320. ++src;
  190321. }
  190322. }
  190323. else
  190324. {
  190325. while (--samples1 >= 0)
  190326. {
  190327. *destL++ = *src++ * g;
  190328. *destR++ = *src++ * g;
  190329. }
  190330. src = (const short*)lpbuf2;
  190331. while (--samples2 >= 0)
  190332. {
  190333. *destL++ = *src++ * g;
  190334. *destR++ = *src++ * g;
  190335. }
  190336. }
  190337. }
  190338. else
  190339. {
  190340. jassertfalse
  190341. }
  190342. readOffset = (readOffset + dwsize1 + dwsize2) % totalBytesPerBuffer;
  190343. pInputBuffer->Unlock (lpbuf1, dwsize1, lpbuf2, dwsize2);
  190344. }
  190345. else
  190346. {
  190347. logError (hr);
  190348. jassertfalse
  190349. }
  190350. bytesFilled -= bytesPerBuffer;
  190351. return true;
  190352. }
  190353. else
  190354. {
  190355. return false;
  190356. }
  190357. }
  190358. };
  190359. class DSoundAudioIODevice : public AudioIODevice,
  190360. public Thread
  190361. {
  190362. public:
  190363. DSoundAudioIODevice (const String& deviceName,
  190364. const int outputDeviceIndex_,
  190365. const int inputDeviceIndex_)
  190366. : AudioIODevice (deviceName, "DirectSound"),
  190367. Thread ("Juce DSound"),
  190368. isOpen_ (false),
  190369. isStarted (false),
  190370. outputDeviceIndex (outputDeviceIndex_),
  190371. inputDeviceIndex (inputDeviceIndex_),
  190372. numInputBuffers (0),
  190373. numOutputBuffers (0),
  190374. totalSamplesOut (0),
  190375. sampleRate (0.0),
  190376. inputBuffers (0),
  190377. outputBuffers (0),
  190378. callback (0),
  190379. bufferSizeSamples (0)
  190380. {
  190381. if (outputDeviceIndex_ >= 0)
  190382. {
  190383. outChannels.add (TRANS("Left"));
  190384. outChannels.add (TRANS("Right"));
  190385. }
  190386. if (inputDeviceIndex_ >= 0)
  190387. {
  190388. inChannels.add (TRANS("Left"));
  190389. inChannels.add (TRANS("Right"));
  190390. }
  190391. }
  190392. ~DSoundAudioIODevice()
  190393. {
  190394. close();
  190395. }
  190396. const StringArray getOutputChannelNames()
  190397. {
  190398. return outChannels;
  190399. }
  190400. const StringArray getInputChannelNames()
  190401. {
  190402. return inChannels;
  190403. }
  190404. int getNumSampleRates()
  190405. {
  190406. return 4;
  190407. }
  190408. double getSampleRate (int index)
  190409. {
  190410. const double samps[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  190411. return samps [jlimit (0, 3, index)];
  190412. }
  190413. int getNumBufferSizesAvailable()
  190414. {
  190415. return 50;
  190416. }
  190417. int getBufferSizeSamples (int index)
  190418. {
  190419. int n = 64;
  190420. for (int i = 0; i < index; ++i)
  190421. n += (n < 512) ? 32
  190422. : ((n < 1024) ? 64
  190423. : ((n < 2048) ? 128 : 256));
  190424. return n;
  190425. }
  190426. int getDefaultBufferSize()
  190427. {
  190428. return 2560;
  190429. }
  190430. const String open (const BigInteger& inputChannels,
  190431. const BigInteger& outputChannels,
  190432. double sampleRate,
  190433. int bufferSizeSamples)
  190434. {
  190435. lastError = openDevice (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  190436. isOpen_ = lastError.isEmpty();
  190437. return lastError;
  190438. }
  190439. void close()
  190440. {
  190441. stop();
  190442. if (isOpen_)
  190443. {
  190444. closeDevice();
  190445. isOpen_ = false;
  190446. }
  190447. }
  190448. bool isOpen()
  190449. {
  190450. return isOpen_ && isThreadRunning();
  190451. }
  190452. int getCurrentBufferSizeSamples()
  190453. {
  190454. return bufferSizeSamples;
  190455. }
  190456. double getCurrentSampleRate()
  190457. {
  190458. return sampleRate;
  190459. }
  190460. int getCurrentBitDepth()
  190461. {
  190462. int i, bits = 256;
  190463. for (i = inChans.size(); --i >= 0;)
  190464. bits = jmin (bits, inChans[i]->bitDepth);
  190465. for (i = outChans.size(); --i >= 0;)
  190466. bits = jmin (bits, outChans[i]->bitDepth);
  190467. if (bits > 32)
  190468. bits = 16;
  190469. return bits;
  190470. }
  190471. const BigInteger getActiveOutputChannels() const
  190472. {
  190473. return enabledOutputs;
  190474. }
  190475. const BigInteger getActiveInputChannels() const
  190476. {
  190477. return enabledInputs;
  190478. }
  190479. int getOutputLatencyInSamples()
  190480. {
  190481. return (int) (getCurrentBufferSizeSamples() * 1.5);
  190482. }
  190483. int getInputLatencyInSamples()
  190484. {
  190485. return getOutputLatencyInSamples();
  190486. }
  190487. void start (AudioIODeviceCallback* call)
  190488. {
  190489. if (isOpen_ && call != 0 && ! isStarted)
  190490. {
  190491. if (! isThreadRunning())
  190492. {
  190493. // something gone wrong and the thread's stopped..
  190494. isOpen_ = false;
  190495. return;
  190496. }
  190497. call->audioDeviceAboutToStart (this);
  190498. const ScopedLock sl (startStopLock);
  190499. callback = call;
  190500. isStarted = true;
  190501. }
  190502. }
  190503. void stop()
  190504. {
  190505. if (isStarted)
  190506. {
  190507. AudioIODeviceCallback* const callbackLocal = callback;
  190508. {
  190509. const ScopedLock sl (startStopLock);
  190510. isStarted = false;
  190511. }
  190512. if (callbackLocal != 0)
  190513. callbackLocal->audioDeviceStopped();
  190514. }
  190515. }
  190516. bool isPlaying()
  190517. {
  190518. return isStarted && isOpen_ && isThreadRunning();
  190519. }
  190520. const String getLastError()
  190521. {
  190522. return lastError;
  190523. }
  190524. juce_UseDebuggingNewOperator
  190525. StringArray inChannels, outChannels;
  190526. int outputDeviceIndex, inputDeviceIndex;
  190527. private:
  190528. bool isOpen_;
  190529. bool isStarted;
  190530. String lastError;
  190531. OwnedArray <DSoundInternalInChannel> inChans;
  190532. OwnedArray <DSoundInternalOutChannel> outChans;
  190533. WaitableEvent startEvent;
  190534. int numInputBuffers, numOutputBuffers, bufferSizeSamples;
  190535. int volatile totalSamplesOut;
  190536. int64 volatile lastBlockTime;
  190537. double sampleRate;
  190538. BigInteger enabledInputs, enabledOutputs;
  190539. HeapBlock <float*> inputBuffers, outputBuffers;
  190540. AudioIODeviceCallback* callback;
  190541. CriticalSection startStopLock;
  190542. DSoundAudioIODevice (const DSoundAudioIODevice&);
  190543. DSoundAudioIODevice& operator= (const DSoundAudioIODevice&);
  190544. const String openDevice (const BigInteger& inputChannels,
  190545. const BigInteger& outputChannels,
  190546. double sampleRate_,
  190547. int bufferSizeSamples_);
  190548. void closeDevice()
  190549. {
  190550. isStarted = false;
  190551. stopThread (5000);
  190552. inChans.clear();
  190553. outChans.clear();
  190554. int i;
  190555. for (i = 0; i < numInputBuffers; ++i)
  190556. juce_free (inputBuffers[i]);
  190557. inputBuffers.free();
  190558. numInputBuffers = 0;
  190559. for (i = 0; i < numOutputBuffers; ++i)
  190560. juce_free (outputBuffers[i]);
  190561. outputBuffers.free();
  190562. numOutputBuffers = 0;
  190563. }
  190564. void resync()
  190565. {
  190566. if (! threadShouldExit())
  190567. {
  190568. sleep (5);
  190569. int i;
  190570. for (i = 0; i < outChans.size(); ++i)
  190571. outChans.getUnchecked(i)->synchronisePosition();
  190572. for (i = 0; i < inChans.size(); ++i)
  190573. inChans.getUnchecked(i)->synchronisePosition();
  190574. }
  190575. }
  190576. public:
  190577. void run()
  190578. {
  190579. while (! threadShouldExit())
  190580. {
  190581. if (wait (100))
  190582. break;
  190583. }
  190584. const int latencyMs = (int) (bufferSizeSamples * 1000.0 / sampleRate);
  190585. const int maxTimeMS = jmax (5, 3 * latencyMs);
  190586. while (! threadShouldExit())
  190587. {
  190588. int numToDo = 0;
  190589. uint32 startTime = Time::getMillisecondCounter();
  190590. int i;
  190591. for (i = inChans.size(); --i >= 0;)
  190592. {
  190593. inChans.getUnchecked(i)->doneFlag = false;
  190594. ++numToDo;
  190595. }
  190596. for (i = outChans.size(); --i >= 0;)
  190597. {
  190598. outChans.getUnchecked(i)->doneFlag = false;
  190599. ++numToDo;
  190600. }
  190601. if (numToDo > 0)
  190602. {
  190603. const int maxCount = 3;
  190604. int count = maxCount;
  190605. for (;;)
  190606. {
  190607. for (i = inChans.size(); --i >= 0;)
  190608. {
  190609. DSoundInternalInChannel* const in = inChans.getUnchecked(i);
  190610. if ((! in->doneFlag) && in->service())
  190611. {
  190612. in->doneFlag = true;
  190613. --numToDo;
  190614. }
  190615. }
  190616. for (i = outChans.size(); --i >= 0;)
  190617. {
  190618. DSoundInternalOutChannel* const out = outChans.getUnchecked(i);
  190619. if ((! out->doneFlag) && out->service())
  190620. {
  190621. out->doneFlag = true;
  190622. --numToDo;
  190623. }
  190624. }
  190625. if (numToDo <= 0)
  190626. break;
  190627. if (Time::getMillisecondCounter() > startTime + maxTimeMS)
  190628. {
  190629. resync();
  190630. break;
  190631. }
  190632. if (--count <= 0)
  190633. {
  190634. Sleep (1);
  190635. count = maxCount;
  190636. }
  190637. if (threadShouldExit())
  190638. return;
  190639. }
  190640. }
  190641. else
  190642. {
  190643. sleep (1);
  190644. }
  190645. const ScopedLock sl (startStopLock);
  190646. if (isStarted)
  190647. {
  190648. JUCE_TRY
  190649. {
  190650. callback->audioDeviceIOCallback (const_cast <const float**> (inputBuffers.getData()),
  190651. numInputBuffers,
  190652. outputBuffers,
  190653. numOutputBuffers,
  190654. bufferSizeSamples);
  190655. }
  190656. JUCE_CATCH_EXCEPTION
  190657. totalSamplesOut += bufferSizeSamples;
  190658. }
  190659. else
  190660. {
  190661. for (i = 0; i < numOutputBuffers; ++i)
  190662. if (outputBuffers[i] != 0)
  190663. zeromem (outputBuffers[i], bufferSizeSamples * sizeof (float));
  190664. totalSamplesOut = 0;
  190665. sleep (1);
  190666. }
  190667. }
  190668. }
  190669. };
  190670. class DSoundAudioIODeviceType : public AudioIODeviceType
  190671. {
  190672. public:
  190673. DSoundAudioIODeviceType()
  190674. : AudioIODeviceType ("DirectSound"),
  190675. hasScanned (false)
  190676. {
  190677. initialiseDSoundFunctions();
  190678. }
  190679. ~DSoundAudioIODeviceType()
  190680. {
  190681. }
  190682. void scanForDevices()
  190683. {
  190684. hasScanned = true;
  190685. outputDeviceNames.clear();
  190686. outputGuids.clear();
  190687. inputDeviceNames.clear();
  190688. inputGuids.clear();
  190689. if (dsDirectSoundEnumerateW != 0)
  190690. {
  190691. dsDirectSoundEnumerateW (outputEnumProcW, this);
  190692. dsDirectSoundCaptureEnumerateW (inputEnumProcW, this);
  190693. }
  190694. }
  190695. const StringArray getDeviceNames (const bool wantInputNames) const
  190696. {
  190697. jassert (hasScanned); // need to call scanForDevices() before doing this
  190698. return wantInputNames ? inputDeviceNames
  190699. : outputDeviceNames;
  190700. }
  190701. int getDefaultDeviceIndex (const bool /*forInput*/) const
  190702. {
  190703. jassert (hasScanned); // need to call scanForDevices() before doing this
  190704. return 0;
  190705. }
  190706. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  190707. {
  190708. jassert (hasScanned); // need to call scanForDevices() before doing this
  190709. DSoundAudioIODevice* const d = dynamic_cast <DSoundAudioIODevice*> (device);
  190710. if (d == 0)
  190711. return -1;
  190712. return asInput ? d->inputDeviceIndex
  190713. : d->outputDeviceIndex;
  190714. }
  190715. bool hasSeparateInputsAndOutputs() const { return true; }
  190716. AudioIODevice* createDevice (const String& outputDeviceName,
  190717. const String& inputDeviceName)
  190718. {
  190719. jassert (hasScanned); // need to call scanForDevices() before doing this
  190720. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  190721. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  190722. if (outputIndex >= 0 || inputIndex >= 0)
  190723. return new DSoundAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  190724. : inputDeviceName,
  190725. outputIndex, inputIndex);
  190726. return 0;
  190727. }
  190728. juce_UseDebuggingNewOperator
  190729. StringArray outputDeviceNames;
  190730. OwnedArray <GUID> outputGuids;
  190731. StringArray inputDeviceNames;
  190732. OwnedArray <GUID> inputGuids;
  190733. private:
  190734. bool hasScanned;
  190735. BOOL outputEnumProc (LPGUID lpGUID, String desc)
  190736. {
  190737. desc = desc.trim();
  190738. if (desc.isNotEmpty())
  190739. {
  190740. const String origDesc (desc);
  190741. int n = 2;
  190742. while (outputDeviceNames.contains (desc))
  190743. desc = origDesc + " (" + String (n++) + ")";
  190744. outputDeviceNames.add (desc);
  190745. if (lpGUID != 0)
  190746. outputGuids.add (new GUID (*lpGUID));
  190747. else
  190748. outputGuids.add (0);
  190749. }
  190750. return TRUE;
  190751. }
  190752. static BOOL CALLBACK outputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  190753. {
  190754. return ((DSoundAudioIODeviceType*) object)
  190755. ->outputEnumProc (lpGUID, String (description));
  190756. }
  190757. static BOOL CALLBACK outputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  190758. {
  190759. return ((DSoundAudioIODeviceType*) object)
  190760. ->outputEnumProc (lpGUID, String (description));
  190761. }
  190762. BOOL CALLBACK inputEnumProc (LPGUID lpGUID, String desc)
  190763. {
  190764. desc = desc.trim();
  190765. if (desc.isNotEmpty())
  190766. {
  190767. const String origDesc (desc);
  190768. int n = 2;
  190769. while (inputDeviceNames.contains (desc))
  190770. desc = origDesc + " (" + String (n++) + ")";
  190771. inputDeviceNames.add (desc);
  190772. if (lpGUID != 0)
  190773. inputGuids.add (new GUID (*lpGUID));
  190774. else
  190775. inputGuids.add (0);
  190776. }
  190777. return TRUE;
  190778. }
  190779. static BOOL CALLBACK inputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  190780. {
  190781. return ((DSoundAudioIODeviceType*) object)
  190782. ->inputEnumProc (lpGUID, String (description));
  190783. }
  190784. static BOOL CALLBACK inputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  190785. {
  190786. return ((DSoundAudioIODeviceType*) object)
  190787. ->inputEnumProc (lpGUID, String (description));
  190788. }
  190789. DSoundAudioIODeviceType (const DSoundAudioIODeviceType&);
  190790. DSoundAudioIODeviceType& operator= (const DSoundAudioIODeviceType&);
  190791. };
  190792. const String DSoundAudioIODevice::openDevice (const BigInteger& inputChannels,
  190793. const BigInteger& outputChannels,
  190794. double sampleRate_,
  190795. int bufferSizeSamples_)
  190796. {
  190797. closeDevice();
  190798. totalSamplesOut = 0;
  190799. sampleRate = sampleRate_;
  190800. if (bufferSizeSamples_ <= 0)
  190801. bufferSizeSamples_ = 960; // use as a default size if none is set.
  190802. bufferSizeSamples = bufferSizeSamples_ & ~7;
  190803. DSoundAudioIODeviceType dlh;
  190804. dlh.scanForDevices();
  190805. enabledInputs = inputChannels;
  190806. enabledInputs.setRange (inChannels.size(),
  190807. enabledInputs.getHighestBit() + 1 - inChannels.size(),
  190808. false);
  190809. numInputBuffers = enabledInputs.countNumberOfSetBits();
  190810. inputBuffers.calloc (numInputBuffers + 2);
  190811. int i, numIns = 0;
  190812. for (i = 0; i <= enabledInputs.getHighestBit(); i += 2)
  190813. {
  190814. float* left = 0;
  190815. float* right = 0;
  190816. if (enabledInputs[i])
  190817. left = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190818. if (enabledInputs[i + 1])
  190819. right = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190820. if (left != 0 || right != 0)
  190821. inChans.add (new DSoundInternalInChannel (dlh.inputDeviceNames [inputDeviceIndex],
  190822. dlh.inputGuids [inputDeviceIndex],
  190823. (int) sampleRate, bufferSizeSamples,
  190824. left, right));
  190825. }
  190826. enabledOutputs = outputChannels;
  190827. enabledOutputs.setRange (outChannels.size(),
  190828. enabledOutputs.getHighestBit() + 1 - outChannels.size(),
  190829. false);
  190830. numOutputBuffers = enabledOutputs.countNumberOfSetBits();
  190831. outputBuffers.calloc (numOutputBuffers + 2);
  190832. int numOuts = 0;
  190833. for (i = 0; i <= enabledOutputs.getHighestBit(); i += 2)
  190834. {
  190835. float* left = 0;
  190836. float* right = 0;
  190837. if (enabledOutputs[i])
  190838. left = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190839. if (enabledOutputs[i + 1])
  190840. right = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190841. if (left != 0 || right != 0)
  190842. outChans.add (new DSoundInternalOutChannel (dlh.outputDeviceNames[outputDeviceIndex],
  190843. dlh.outputGuids [outputDeviceIndex],
  190844. (int) sampleRate, bufferSizeSamples,
  190845. left, right));
  190846. }
  190847. String error;
  190848. // boost our priority while opening the devices to try to get better sync between them
  190849. const int oldThreadPri = GetThreadPriority (GetCurrentThread());
  190850. const int oldProcPri = GetPriorityClass (GetCurrentProcess());
  190851. SetThreadPriority (GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
  190852. SetPriorityClass (GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
  190853. for (i = 0; i < outChans.size(); ++i)
  190854. {
  190855. error = outChans[i]->open();
  190856. if (error.isNotEmpty())
  190857. {
  190858. error = "Error opening " + dlh.outputDeviceNames[i] + ": \"" + error + "\"";
  190859. break;
  190860. }
  190861. }
  190862. if (error.isEmpty())
  190863. {
  190864. for (i = 0; i < inChans.size(); ++i)
  190865. {
  190866. error = inChans[i]->open();
  190867. if (error.isNotEmpty())
  190868. {
  190869. error = "Error opening " + dlh.inputDeviceNames[i] + ": \"" + error + "\"";
  190870. break;
  190871. }
  190872. }
  190873. }
  190874. if (error.isEmpty())
  190875. {
  190876. totalSamplesOut = 0;
  190877. for (i = 0; i < outChans.size(); ++i)
  190878. outChans.getUnchecked(i)->synchronisePosition();
  190879. for (i = 0; i < inChans.size(); ++i)
  190880. inChans.getUnchecked(i)->synchronisePosition();
  190881. startThread (9);
  190882. sleep (10);
  190883. notify();
  190884. }
  190885. else
  190886. {
  190887. log (error);
  190888. }
  190889. SetThreadPriority (GetCurrentThread(), oldThreadPri);
  190890. SetPriorityClass (GetCurrentProcess(), oldProcPri);
  190891. return error;
  190892. }
  190893. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound()
  190894. {
  190895. return new DSoundAudioIODeviceType();
  190896. }
  190897. #undef log
  190898. #endif
  190899. /*** End of inlined file: juce_win32_DirectSound.cpp ***/
  190900. /*** Start of inlined file: juce_win32_WASAPI.cpp ***/
  190901. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  190902. // compiled on its own).
  190903. #if JUCE_INCLUDED_FILE && JUCE_WASAPI
  190904. #if 1
  190905. const String getAudioErrorDesc (HRESULT hr)
  190906. {
  190907. const char* e = 0;
  190908. switch (hr)
  190909. {
  190910. case E_POINTER: e = "E_POINTER"; break;
  190911. case E_INVALIDARG: e = "E_INVALIDARG"; break;
  190912. case AUDCLNT_E_NOT_INITIALIZED: e = "AUDCLNT_E_NOT_INITIALIZED"; break;
  190913. case AUDCLNT_E_ALREADY_INITIALIZED: e = "AUDCLNT_E_ALREADY_INITIALIZED"; break;
  190914. case AUDCLNT_E_WRONG_ENDPOINT_TYPE: e = "AUDCLNT_E_WRONG_ENDPOINT_TYPE"; break;
  190915. case AUDCLNT_E_DEVICE_INVALIDATED: e = "AUDCLNT_E_DEVICE_INVALIDATED"; break;
  190916. case AUDCLNT_E_NOT_STOPPED: e = "AUDCLNT_E_NOT_STOPPED"; break;
  190917. case AUDCLNT_E_BUFFER_TOO_LARGE: e = "AUDCLNT_E_BUFFER_TOO_LARGE"; break;
  190918. case AUDCLNT_E_OUT_OF_ORDER: e = "AUDCLNT_E_OUT_OF_ORDER"; break;
  190919. case AUDCLNT_E_UNSUPPORTED_FORMAT: e = "AUDCLNT_E_UNSUPPORTED_FORMAT"; break;
  190920. case AUDCLNT_E_INVALID_SIZE: e = "AUDCLNT_E_INVALID_SIZE"; break;
  190921. case AUDCLNT_E_DEVICE_IN_USE: e = "AUDCLNT_E_DEVICE_IN_USE"; break;
  190922. case AUDCLNT_E_BUFFER_OPERATION_PENDING: e = "AUDCLNT_E_BUFFER_OPERATION_PENDING"; break;
  190923. case AUDCLNT_E_THREAD_NOT_REGISTERED: e = "AUDCLNT_E_THREAD_NOT_REGISTERED"; break;
  190924. case AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED: e = "AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED"; break;
  190925. case AUDCLNT_E_ENDPOINT_CREATE_FAILED: e = "AUDCLNT_E_ENDPOINT_CREATE_FAILED"; break;
  190926. case AUDCLNT_E_SERVICE_NOT_RUNNING: e = "AUDCLNT_E_SERVICE_NOT_RUNNING"; break;
  190927. case AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED: e = "AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED"; break;
  190928. case AUDCLNT_E_EXCLUSIVE_MODE_ONLY: e = "AUDCLNT_E_EXCLUSIVE_MODE_ONLY"; break;
  190929. case AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL: e = "AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL"; break;
  190930. case AUDCLNT_E_EVENTHANDLE_NOT_SET: e = "AUDCLNT_E_EVENTHANDLE_NOT_SET"; break;
  190931. case AUDCLNT_E_INCORRECT_BUFFER_SIZE: e = "AUDCLNT_E_INCORRECT_BUFFER_SIZE"; break;
  190932. case AUDCLNT_E_BUFFER_SIZE_ERROR: e = "AUDCLNT_E_BUFFER_SIZE_ERROR"; break;
  190933. case AUDCLNT_S_BUFFER_EMPTY: e = "AUDCLNT_S_BUFFER_EMPTY"; break;
  190934. case AUDCLNT_S_THREAD_ALREADY_REGISTERED: e = "AUDCLNT_S_THREAD_ALREADY_REGISTERED"; break;
  190935. default: return String::toHexString ((int) hr);
  190936. }
  190937. return e;
  190938. }
  190939. #define logFailure(hr) { if (FAILED (hr)) { DBG ("WASAPI FAIL! " + getAudioErrorDesc (hr)); jassertfalse } }
  190940. #define OK(a) wasapi_checkResult(a)
  190941. static bool wasapi_checkResult (HRESULT hr)
  190942. {
  190943. logFailure (hr);
  190944. return SUCCEEDED (hr);
  190945. }
  190946. #else
  190947. #define logFailure(hr) {}
  190948. #define OK(a) SUCCEEDED(a)
  190949. #endif
  190950. static const String wasapi_getDeviceID (IMMDevice* const device)
  190951. {
  190952. String s;
  190953. WCHAR* deviceId = 0;
  190954. if (OK (device->GetId (&deviceId)))
  190955. {
  190956. s = String (deviceId);
  190957. CoTaskMemFree (deviceId);
  190958. }
  190959. return s;
  190960. }
  190961. static EDataFlow wasapi_getDataFlow (IMMDevice* const device)
  190962. {
  190963. EDataFlow flow = eRender;
  190964. ComSmartPtr <IMMEndpoint> endPoint;
  190965. if (OK (device->QueryInterface (__uuidof (IMMEndpoint), (void**) &endPoint)))
  190966. (void) OK (endPoint->GetDataFlow (&flow));
  190967. return flow;
  190968. }
  190969. static int wasapi_refTimeToSamples (const REFERENCE_TIME& t, const double sampleRate) throw()
  190970. {
  190971. return roundDoubleToInt (sampleRate * ((double) t) * 0.0000001);
  190972. }
  190973. static void wasapi_copyWavFormat (WAVEFORMATEXTENSIBLE& dest, const WAVEFORMATEX* const src) throw()
  190974. {
  190975. memcpy (&dest, src, src->wFormatTag == WAVE_FORMAT_EXTENSIBLE ? sizeof (WAVEFORMATEXTENSIBLE)
  190976. : sizeof (WAVEFORMATEX));
  190977. }
  190978. class WASAPIDeviceBase
  190979. {
  190980. public:
  190981. WASAPIDeviceBase (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  190982. : device (device_),
  190983. sampleRate (0),
  190984. numChannels (0),
  190985. actualNumChannels (0),
  190986. defaultSampleRate (0),
  190987. minBufferSize (0),
  190988. defaultBufferSize (0),
  190989. latencySamples (0),
  190990. useExclusiveMode (useExclusiveMode_)
  190991. {
  190992. clientEvent = CreateEvent (0, false, false, _T("JuceWASAPI"));
  190993. ComSmartPtr <IAudioClient> tempClient (createClient());
  190994. if (tempClient == 0)
  190995. return;
  190996. REFERENCE_TIME defaultPeriod, minPeriod;
  190997. if (! OK (tempClient->GetDevicePeriod (&defaultPeriod, &minPeriod)))
  190998. return;
  190999. WAVEFORMATEX* mixFormat = 0;
  191000. if (! OK (tempClient->GetMixFormat (&mixFormat)))
  191001. return;
  191002. WAVEFORMATEXTENSIBLE format;
  191003. wasapi_copyWavFormat (format, mixFormat);
  191004. CoTaskMemFree (mixFormat);
  191005. actualNumChannels = numChannels = format.Format.nChannels;
  191006. defaultSampleRate = format.Format.nSamplesPerSec;
  191007. minBufferSize = wasapi_refTimeToSamples (minPeriod, defaultSampleRate);
  191008. defaultBufferSize = wasapi_refTimeToSamples (defaultPeriod, defaultSampleRate);
  191009. FloatElementComparator<double> comparator;
  191010. rates.addSorted (comparator, defaultSampleRate);
  191011. static const double ratesToTest[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  191012. for (int i = 0; i < numElementsInArray (ratesToTest); ++i)
  191013. {
  191014. if (ratesToTest[i] == defaultSampleRate)
  191015. continue;
  191016. format.Format.nSamplesPerSec = roundDoubleToInt (ratesToTest[i]);
  191017. if (SUCCEEDED (tempClient->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191018. (WAVEFORMATEX*) &format, 0)))
  191019. if (! rates.contains (ratesToTest[i]))
  191020. rates.addSorted (comparator, ratesToTest[i]);
  191021. }
  191022. }
  191023. ~WASAPIDeviceBase()
  191024. {
  191025. device = 0;
  191026. CloseHandle (clientEvent);
  191027. }
  191028. bool isOk() const throw() { return defaultBufferSize > 0 && defaultSampleRate > 0; }
  191029. bool openClient (const double newSampleRate, const BigInteger& newChannels)
  191030. {
  191031. sampleRate = newSampleRate;
  191032. channels = newChannels;
  191033. channels.setRange (actualNumChannels, channels.getHighestBit() + 1 - actualNumChannels, false);
  191034. numChannels = channels.getHighestBit() + 1;
  191035. if (numChannels == 0)
  191036. return true;
  191037. client = createClient();
  191038. if (client != 0
  191039. && (tryInitialisingWithFormat (true, 4) || tryInitialisingWithFormat (false, 4)
  191040. || tryInitialisingWithFormat (false, 3) || tryInitialisingWithFormat (false, 2)))
  191041. {
  191042. channelMaps.clear();
  191043. for (int i = 0; i <= channels.getHighestBit(); ++i)
  191044. if (channels[i])
  191045. channelMaps.add (i);
  191046. REFERENCE_TIME latency;
  191047. if (OK (client->GetStreamLatency (&latency)))
  191048. latencySamples = wasapi_refTimeToSamples (latency, sampleRate);
  191049. (void) OK (client->GetBufferSize (&actualBufferSize));
  191050. return OK (client->SetEventHandle (clientEvent));
  191051. }
  191052. return false;
  191053. }
  191054. void closeClient()
  191055. {
  191056. if (client != 0)
  191057. client->Stop();
  191058. client = 0;
  191059. ResetEvent (clientEvent);
  191060. }
  191061. ComSmartPtr <IMMDevice> device;
  191062. ComSmartPtr <IAudioClient> client;
  191063. double sampleRate, defaultSampleRate;
  191064. int numChannels, actualNumChannels;
  191065. int minBufferSize, defaultBufferSize, latencySamples;
  191066. const bool useExclusiveMode;
  191067. Array <double> rates;
  191068. HANDLE clientEvent;
  191069. BigInteger channels;
  191070. AudioDataConverters::DataFormat dataFormat;
  191071. Array <int> channelMaps;
  191072. UINT32 actualBufferSize;
  191073. int bytesPerSample;
  191074. private:
  191075. const ComSmartPtr <IAudioClient> createClient()
  191076. {
  191077. ComSmartPtr <IAudioClient> client;
  191078. if (device != 0)
  191079. {
  191080. HRESULT hr = device->Activate (__uuidof (IAudioClient), CLSCTX_INPROC_SERVER, 0, (void**) &client);
  191081. logFailure (hr);
  191082. }
  191083. return client;
  191084. }
  191085. bool tryInitialisingWithFormat (const bool useFloat, const int bytesPerSampleToTry)
  191086. {
  191087. WAVEFORMATEXTENSIBLE format;
  191088. zerostruct (format);
  191089. if (numChannels <= 2 && bytesPerSampleToTry <= 2)
  191090. {
  191091. format.Format.wFormatTag = WAVE_FORMAT_PCM;
  191092. }
  191093. else
  191094. {
  191095. format.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
  191096. format.Format.cbSize = sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX);
  191097. }
  191098. format.Format.nSamplesPerSec = roundDoubleToInt (sampleRate);
  191099. format.Format.nChannels = (WORD) numChannels;
  191100. format.Format.wBitsPerSample = (WORD) (8 * bytesPerSampleToTry);
  191101. format.Format.nAvgBytesPerSec = (DWORD) (format.Format.nSamplesPerSec * numChannels * bytesPerSampleToTry);
  191102. format.Format.nBlockAlign = (WORD) (numChannels * bytesPerSampleToTry);
  191103. format.SubFormat = useFloat ? KSDATAFORMAT_SUBTYPE_IEEE_FLOAT : KSDATAFORMAT_SUBTYPE_PCM;
  191104. format.Samples.wValidBitsPerSample = format.Format.wBitsPerSample;
  191105. switch (numChannels)
  191106. {
  191107. case 1: format.dwChannelMask = SPEAKER_FRONT_CENTER; break;
  191108. case 2: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; break;
  191109. case 4: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191110. case 6: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191111. 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;
  191112. default: break;
  191113. }
  191114. WAVEFORMATEXTENSIBLE* nearestFormat = 0;
  191115. HRESULT hr = client->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191116. (WAVEFORMATEX*) &format, useExclusiveMode ? 0 : (WAVEFORMATEX**) &nearestFormat);
  191117. logFailure (hr);
  191118. if (hr == S_FALSE && format.Format.nSamplesPerSec == nearestFormat->Format.nSamplesPerSec)
  191119. {
  191120. wasapi_copyWavFormat (format, (WAVEFORMATEX*) nearestFormat);
  191121. hr = S_OK;
  191122. }
  191123. CoTaskMemFree (nearestFormat);
  191124. REFERENCE_TIME defaultPeriod = 0, minPeriod = 0;
  191125. if (useExclusiveMode)
  191126. OK (client->GetDevicePeriod (&defaultPeriod, &minPeriod));
  191127. GUID session;
  191128. if (hr == S_OK
  191129. && OK (client->Initialize (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191130. AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
  191131. defaultPeriod, defaultPeriod, (WAVEFORMATEX*) &format, &session)))
  191132. {
  191133. actualNumChannels = format.Format.nChannels;
  191134. const bool isFloat = format.Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE && format.SubFormat == KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
  191135. bytesPerSample = format.Format.wBitsPerSample / 8;
  191136. dataFormat = isFloat ? AudioDataConverters::float32LE
  191137. : (bytesPerSample == 4 ? AudioDataConverters::int32LE
  191138. : ((bytesPerSample == 3 ? AudioDataConverters::int24LE
  191139. : AudioDataConverters::int16LE)));
  191140. return true;
  191141. }
  191142. return false;
  191143. }
  191144. };
  191145. class WASAPIInputDevice : public WASAPIDeviceBase
  191146. {
  191147. public:
  191148. WASAPIInputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191149. : WASAPIDeviceBase (device_, useExclusiveMode_),
  191150. reservoir (1, 1)
  191151. {
  191152. }
  191153. ~WASAPIInputDevice()
  191154. {
  191155. close();
  191156. }
  191157. bool open (const double newSampleRate, const BigInteger& newChannels)
  191158. {
  191159. reservoirSize = 0;
  191160. reservoirCapacity = 16384;
  191161. reservoir.setSize (actualNumChannels * reservoirCapacity * sizeof (float));
  191162. return openClient (newSampleRate, newChannels)
  191163. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioCaptureClient), (void**) &captureClient)));
  191164. }
  191165. void close()
  191166. {
  191167. closeClient();
  191168. captureClient = 0;
  191169. reservoir.setSize (0);
  191170. }
  191171. void copyBuffers (float** destBuffers, int numDestBuffers, int bufferSize, Thread& thread)
  191172. {
  191173. if (numChannels <= 0)
  191174. return;
  191175. int offset = 0;
  191176. while (bufferSize > 0)
  191177. {
  191178. if (reservoirSize > 0) // There's stuff in the reservoir, so use that...
  191179. {
  191180. const int samplesToDo = jmin (bufferSize, (int) reservoirSize);
  191181. for (int i = 0; i < numDestBuffers; ++i)
  191182. {
  191183. float* const dest = destBuffers[i] + offset;
  191184. const int srcChan = channelMaps.getUnchecked(i);
  191185. switch (dataFormat)
  191186. {
  191187. case AudioDataConverters::float32LE:
  191188. AudioDataConverters::convertFloat32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191189. break;
  191190. case AudioDataConverters::int32LE:
  191191. AudioDataConverters::convertInt32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191192. break;
  191193. case AudioDataConverters::int24LE:
  191194. AudioDataConverters::convertInt24LEToFloat (((uint8*) reservoir.getData()) + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191195. break;
  191196. case AudioDataConverters::int16LE:
  191197. AudioDataConverters::convertInt16LEToFloat (((uint8*) reservoir.getData()) + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191198. break;
  191199. default: jassertfalse; break;
  191200. }
  191201. }
  191202. bufferSize -= samplesToDo;
  191203. offset += samplesToDo;
  191204. reservoirSize -= samplesToDo;
  191205. }
  191206. else
  191207. {
  191208. UINT32 packetLength = 0;
  191209. if (! OK (captureClient->GetNextPacketSize (&packetLength)))
  191210. break;
  191211. if (packetLength == 0)
  191212. {
  191213. if (thread.threadShouldExit())
  191214. break;
  191215. Thread::sleep (1);
  191216. continue;
  191217. }
  191218. uint8* inputData = 0;
  191219. UINT32 numSamplesAvailable;
  191220. DWORD flags;
  191221. if (OK (captureClient->GetBuffer (&inputData, &numSamplesAvailable, &flags, 0, 0)))
  191222. {
  191223. const int samplesToDo = jmin (bufferSize, (int) numSamplesAvailable);
  191224. for (int i = 0; i < numDestBuffers; ++i)
  191225. {
  191226. float* const dest = destBuffers[i] + offset;
  191227. const int srcChan = channelMaps.getUnchecked(i);
  191228. switch (dataFormat)
  191229. {
  191230. case AudioDataConverters::float32LE:
  191231. AudioDataConverters::convertFloat32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191232. break;
  191233. case AudioDataConverters::int32LE:
  191234. AudioDataConverters::convertInt32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191235. break;
  191236. case AudioDataConverters::int24LE:
  191237. AudioDataConverters::convertInt24LEToFloat (inputData + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191238. break;
  191239. case AudioDataConverters::int16LE:
  191240. AudioDataConverters::convertInt16LEToFloat (inputData + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191241. break;
  191242. default: jassertfalse; break;
  191243. }
  191244. }
  191245. bufferSize -= samplesToDo;
  191246. offset += samplesToDo;
  191247. if (samplesToDo < (int) numSamplesAvailable)
  191248. {
  191249. reservoirSize = jmin ((int) (numSamplesAvailable - samplesToDo), reservoirCapacity);
  191250. memcpy ((uint8*) reservoir.getData(), inputData + bytesPerSample * actualNumChannels * samplesToDo,
  191251. bytesPerSample * actualNumChannels * reservoirSize);
  191252. }
  191253. captureClient->ReleaseBuffer (numSamplesAvailable);
  191254. }
  191255. }
  191256. }
  191257. }
  191258. ComSmartPtr <IAudioCaptureClient> captureClient;
  191259. MemoryBlock reservoir;
  191260. int reservoirSize, reservoirCapacity;
  191261. };
  191262. class WASAPIOutputDevice : public WASAPIDeviceBase
  191263. {
  191264. public:
  191265. WASAPIOutputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191266. : WASAPIDeviceBase (device_, useExclusiveMode_)
  191267. {
  191268. }
  191269. ~WASAPIOutputDevice()
  191270. {
  191271. close();
  191272. }
  191273. bool open (const double newSampleRate, const BigInteger& newChannels)
  191274. {
  191275. return openClient (newSampleRate, newChannels)
  191276. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioRenderClient), (void**) &renderClient)));
  191277. }
  191278. void close()
  191279. {
  191280. closeClient();
  191281. renderClient = 0;
  191282. }
  191283. void copyBuffers (const float** const srcBuffers, const int numSrcBuffers, int bufferSize, Thread& thread)
  191284. {
  191285. if (numChannels <= 0)
  191286. return;
  191287. int offset = 0;
  191288. while (bufferSize > 0)
  191289. {
  191290. UINT32 padding = 0;
  191291. if (! OK (client->GetCurrentPadding (&padding)))
  191292. return;
  191293. int samplesToDo = useExclusiveMode ? bufferSize
  191294. : jmin ((int) (actualBufferSize - padding), bufferSize);
  191295. if (samplesToDo <= 0)
  191296. {
  191297. if (thread.threadShouldExit())
  191298. break;
  191299. Thread::sleep (0);
  191300. continue;
  191301. }
  191302. uint8* outputData = 0;
  191303. if (OK (renderClient->GetBuffer (samplesToDo, &outputData)))
  191304. {
  191305. for (int i = 0; i < numSrcBuffers; ++i)
  191306. {
  191307. const float* const source = srcBuffers[i] + offset;
  191308. const int destChan = channelMaps.getUnchecked(i);
  191309. switch (dataFormat)
  191310. {
  191311. case AudioDataConverters::float32LE:
  191312. AudioDataConverters::convertFloatToFloat32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191313. break;
  191314. case AudioDataConverters::int32LE:
  191315. AudioDataConverters::convertFloatToInt32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191316. break;
  191317. case AudioDataConverters::int24LE:
  191318. AudioDataConverters::convertFloatToInt24LE (source, outputData + 3 * destChan, samplesToDo, 3 * actualNumChannels);
  191319. break;
  191320. case AudioDataConverters::int16LE:
  191321. AudioDataConverters::convertFloatToInt16LE (source, outputData + 2 * destChan, samplesToDo, 2 * actualNumChannels);
  191322. break;
  191323. default: jassertfalse; break;
  191324. }
  191325. }
  191326. renderClient->ReleaseBuffer (samplesToDo, 0);
  191327. offset += samplesToDo;
  191328. bufferSize -= samplesToDo;
  191329. }
  191330. }
  191331. }
  191332. ComSmartPtr <IAudioRenderClient> renderClient;
  191333. };
  191334. class WASAPIAudioIODevice : public AudioIODevice,
  191335. public Thread
  191336. {
  191337. public:
  191338. WASAPIAudioIODevice (const String& deviceName,
  191339. const String& outputDeviceId_,
  191340. const String& inputDeviceId_,
  191341. const bool useExclusiveMode_)
  191342. : AudioIODevice (deviceName, "Windows Audio"),
  191343. Thread ("Juce WASAPI"),
  191344. isOpen_ (false),
  191345. isStarted (false),
  191346. outputDevice (0),
  191347. outputDeviceId (outputDeviceId_),
  191348. inputDevice (0),
  191349. inputDeviceId (inputDeviceId_),
  191350. useExclusiveMode (useExclusiveMode_),
  191351. currentBufferSizeSamples (0),
  191352. currentSampleRate (0),
  191353. callback (0)
  191354. {
  191355. }
  191356. ~WASAPIAudioIODevice()
  191357. {
  191358. close();
  191359. deleteAndZero (inputDevice);
  191360. deleteAndZero (outputDevice);
  191361. }
  191362. bool initialise()
  191363. {
  191364. double defaultSampleRateIn = 0, defaultSampleRateOut = 0;
  191365. int minBufferSizeIn = 0, defaultBufferSizeIn = 0, minBufferSizeOut = 0, defaultBufferSizeOut = 0;
  191366. latencyIn = latencyOut = 0;
  191367. Array <double> ratesIn, ratesOut;
  191368. if (createDevices())
  191369. {
  191370. jassert (inputDevice != 0 || outputDevice != 0);
  191371. if (inputDevice != 0 && outputDevice != 0)
  191372. {
  191373. defaultSampleRate = jmin (inputDevice->defaultSampleRate, outputDevice->defaultSampleRate);
  191374. minBufferSize = jmin (inputDevice->minBufferSize, outputDevice->minBufferSize);
  191375. defaultBufferSize = jmax (inputDevice->defaultBufferSize, outputDevice->defaultBufferSize);
  191376. sampleRates = inputDevice->rates;
  191377. sampleRates.removeValuesNotIn (outputDevice->rates);
  191378. }
  191379. else
  191380. {
  191381. WASAPIDeviceBase* const d = inputDevice != 0 ? (WASAPIDeviceBase*) inputDevice : (WASAPIDeviceBase*) outputDevice;
  191382. defaultSampleRate = d->defaultSampleRate;
  191383. minBufferSize = d->minBufferSize;
  191384. defaultBufferSize = d->defaultBufferSize;
  191385. sampleRates = d->rates;
  191386. }
  191387. IntegerElementComparator<int> comparator;
  191388. bufferSizes.addSorted (comparator, defaultBufferSize);
  191389. if (minBufferSize != defaultBufferSize)
  191390. bufferSizes.addSorted (comparator, minBufferSize);
  191391. int n = 64;
  191392. for (int i = 0; i < 40; ++i)
  191393. {
  191394. if (n >= minBufferSize && n <= 2048 && ! bufferSizes.contains (n))
  191395. bufferSizes.addSorted (comparator, n);
  191396. n += (n < 512) ? 32 : (n < 1024 ? 64 : 128);
  191397. }
  191398. return true;
  191399. }
  191400. return false;
  191401. }
  191402. const StringArray getOutputChannelNames()
  191403. {
  191404. StringArray outChannels;
  191405. if (outputDevice != 0)
  191406. for (int i = 1; i <= outputDevice->actualNumChannels; ++i)
  191407. outChannels.add ("Output channel " + String (i));
  191408. return outChannels;
  191409. }
  191410. const StringArray getInputChannelNames()
  191411. {
  191412. StringArray inChannels;
  191413. if (inputDevice != 0)
  191414. for (int i = 1; i <= inputDevice->actualNumChannels; ++i)
  191415. inChannels.add ("Input channel " + String (i));
  191416. return inChannels;
  191417. }
  191418. int getNumSampleRates() { return sampleRates.size(); }
  191419. double getSampleRate (int index) { return sampleRates [index]; }
  191420. int getNumBufferSizesAvailable() { return bufferSizes.size(); }
  191421. int getBufferSizeSamples (int index) { return bufferSizes [index]; }
  191422. int getDefaultBufferSize() { return defaultBufferSize; }
  191423. int getCurrentBufferSizeSamples() { return currentBufferSizeSamples; }
  191424. double getCurrentSampleRate() { return currentSampleRate; }
  191425. int getCurrentBitDepth() { return 32; }
  191426. int getOutputLatencyInSamples() { return latencyOut; }
  191427. int getInputLatencyInSamples() { return latencyIn; }
  191428. const BigInteger getActiveOutputChannels() const { return outputDevice != 0 ? outputDevice->channels : BigInteger(); }
  191429. const BigInteger getActiveInputChannels() const { return inputDevice != 0 ? inputDevice->channels : BigInteger(); }
  191430. const String getLastError() { return lastError; }
  191431. const String open (const BigInteger& inputChannels, const BigInteger& outputChannels,
  191432. double sampleRate, int bufferSizeSamples)
  191433. {
  191434. close();
  191435. lastError = String::empty;
  191436. if (sampleRates.size() == 0 && inputDevice != 0 && outputDevice != 0)
  191437. {
  191438. lastError = "The input and output devices don't share a common sample rate!";
  191439. return lastError;
  191440. }
  191441. currentBufferSizeSamples = bufferSizeSamples <= 0 ? defaultBufferSize : jmax (bufferSizeSamples, minBufferSize);
  191442. currentSampleRate = sampleRate > 0 ? sampleRate : defaultSampleRate;
  191443. if (inputDevice != 0 && ! inputDevice->open (currentSampleRate, inputChannels))
  191444. {
  191445. lastError = "Couldn't open the input device!";
  191446. return lastError;
  191447. }
  191448. if (outputDevice != 0 && ! outputDevice->open (currentSampleRate, outputChannels))
  191449. {
  191450. close();
  191451. lastError = "Couldn't open the output device!";
  191452. return lastError;
  191453. }
  191454. if (inputDevice != 0)
  191455. ResetEvent (inputDevice->clientEvent);
  191456. if (outputDevice != 0)
  191457. ResetEvent (outputDevice->clientEvent);
  191458. startThread (8);
  191459. Thread::sleep (5);
  191460. if (inputDevice != 0 && inputDevice->client != 0)
  191461. {
  191462. latencyIn = inputDevice->latencySamples + inputDevice->actualBufferSize + inputDevice->minBufferSize;
  191463. HRESULT hr = inputDevice->client->Start();
  191464. logFailure (hr); //xxx handle this
  191465. }
  191466. if (outputDevice != 0 && outputDevice->client != 0)
  191467. {
  191468. latencyOut = outputDevice->latencySamples + outputDevice->actualBufferSize + outputDevice->minBufferSize;
  191469. HRESULT hr = outputDevice->client->Start();
  191470. logFailure (hr); //xxx handle this
  191471. }
  191472. isOpen_ = true;
  191473. return lastError;
  191474. }
  191475. void close()
  191476. {
  191477. stop();
  191478. if (inputDevice != 0)
  191479. SetEvent (inputDevice->clientEvent);
  191480. if (outputDevice != 0)
  191481. SetEvent (outputDevice->clientEvent);
  191482. stopThread (5000);
  191483. if (inputDevice != 0)
  191484. inputDevice->close();
  191485. if (outputDevice != 0)
  191486. outputDevice->close();
  191487. isOpen_ = false;
  191488. }
  191489. bool isOpen() { return isOpen_ && isThreadRunning(); }
  191490. bool isPlaying() { return isStarted && isOpen_ && isThreadRunning(); }
  191491. void start (AudioIODeviceCallback* call)
  191492. {
  191493. if (isOpen_ && call != 0 && ! isStarted)
  191494. {
  191495. if (! isThreadRunning())
  191496. {
  191497. // something's gone wrong and the thread's stopped..
  191498. isOpen_ = false;
  191499. return;
  191500. }
  191501. call->audioDeviceAboutToStart (this);
  191502. const ScopedLock sl (startStopLock);
  191503. callback = call;
  191504. isStarted = true;
  191505. }
  191506. }
  191507. void stop()
  191508. {
  191509. if (isStarted)
  191510. {
  191511. AudioIODeviceCallback* const callbackLocal = callback;
  191512. {
  191513. const ScopedLock sl (startStopLock);
  191514. isStarted = false;
  191515. }
  191516. if (callbackLocal != 0)
  191517. callbackLocal->audioDeviceStopped();
  191518. }
  191519. }
  191520. void setMMThreadPriority()
  191521. {
  191522. DynamicLibraryLoader dll ("avrt.dll");
  191523. DynamicLibraryImport (AvSetMmThreadCharacteristics, avSetMmThreadCharacteristics, HANDLE, dll, (LPCTSTR, LPDWORD))
  191524. DynamicLibraryImport (AvSetMmThreadPriority, avSetMmThreadPriority, HANDLE, dll, (HANDLE, AVRT_PRIORITY))
  191525. if (avSetMmThreadCharacteristics != 0 && avSetMmThreadPriority != 0)
  191526. {
  191527. DWORD dummy = 0;
  191528. HANDLE h = avSetMmThreadCharacteristics (_T("Pro Audio"), &dummy);
  191529. if (h != 0)
  191530. avSetMmThreadPriority (h, AVRT_PRIORITY_NORMAL);
  191531. }
  191532. }
  191533. void run()
  191534. {
  191535. setMMThreadPriority();
  191536. const int bufferSize = currentBufferSizeSamples;
  191537. HANDLE events[2];
  191538. int numEvents = 0;
  191539. if (inputDevice != 0)
  191540. events [numEvents++] = inputDevice->clientEvent;
  191541. if (outputDevice != 0)
  191542. events [numEvents++] = outputDevice->clientEvent;
  191543. const int numInputBuffers = getActiveInputChannels().countNumberOfSetBits();
  191544. const int numOutputBuffers = getActiveOutputChannels().countNumberOfSetBits();
  191545. AudioSampleBuffer ins (jmax (1, numInputBuffers), bufferSize + 32);
  191546. AudioSampleBuffer outs (jmax (1, numOutputBuffers), bufferSize + 32);
  191547. float** const inputBuffers = ins.getArrayOfChannels();
  191548. float** const outputBuffers = outs.getArrayOfChannels();
  191549. ins.clear();
  191550. while (! threadShouldExit())
  191551. {
  191552. const DWORD result = useExclusiveMode ? WaitForSingleObject (inputDevice->clientEvent, 1000)
  191553. : WaitForMultipleObjects (numEvents, events, true, 1000);
  191554. if (result == WAIT_TIMEOUT)
  191555. continue;
  191556. if (threadShouldExit())
  191557. break;
  191558. if (inputDevice != 0)
  191559. inputDevice->copyBuffers (inputBuffers, numInputBuffers, bufferSize, *this);
  191560. // Make the callback..
  191561. {
  191562. const ScopedLock sl (startStopLock);
  191563. if (isStarted)
  191564. {
  191565. JUCE_TRY
  191566. {
  191567. callback->audioDeviceIOCallback ((const float**) inputBuffers,
  191568. numInputBuffers,
  191569. outputBuffers,
  191570. numOutputBuffers,
  191571. bufferSize);
  191572. }
  191573. JUCE_CATCH_EXCEPTION
  191574. }
  191575. else
  191576. {
  191577. outs.clear();
  191578. }
  191579. }
  191580. if (useExclusiveMode && WaitForSingleObject (outputDevice->clientEvent, 1000) == WAIT_TIMEOUT)
  191581. continue;
  191582. if (outputDevice != 0)
  191583. outputDevice->copyBuffers ((const float**) outputBuffers, numOutputBuffers, bufferSize, *this);
  191584. }
  191585. }
  191586. juce_UseDebuggingNewOperator
  191587. String outputDeviceId, inputDeviceId;
  191588. String lastError;
  191589. private:
  191590. // Device stats...
  191591. WASAPIInputDevice* inputDevice;
  191592. WASAPIOutputDevice* outputDevice;
  191593. const bool useExclusiveMode;
  191594. double defaultSampleRate;
  191595. int minBufferSize, defaultBufferSize;
  191596. int latencyIn, latencyOut;
  191597. Array <double> sampleRates;
  191598. Array <int> bufferSizes;
  191599. // Active state...
  191600. bool isOpen_, isStarted;
  191601. int currentBufferSizeSamples;
  191602. double currentSampleRate;
  191603. AudioIODeviceCallback* callback;
  191604. CriticalSection startStopLock;
  191605. bool createDevices()
  191606. {
  191607. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  191608. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  191609. return false;
  191610. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  191611. if (! OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection)))
  191612. return false;
  191613. UINT32 numDevices = 0;
  191614. if (! OK (deviceCollection->GetCount (&numDevices)))
  191615. return false;
  191616. for (UINT32 i = 0; i < numDevices; ++i)
  191617. {
  191618. ComSmartPtr <IMMDevice> device;
  191619. if (! OK (deviceCollection->Item (i, &device)))
  191620. continue;
  191621. const String deviceId (wasapi_getDeviceID (device));
  191622. if (deviceId.isEmpty())
  191623. continue;
  191624. const EDataFlow flow = wasapi_getDataFlow (device);
  191625. if (deviceId == inputDeviceId && flow == eCapture)
  191626. inputDevice = new WASAPIInputDevice (device, useExclusiveMode);
  191627. else if (deviceId == outputDeviceId && flow == eRender)
  191628. outputDevice = new WASAPIOutputDevice (device, useExclusiveMode);
  191629. }
  191630. return (outputDeviceId.isEmpty() || (outputDevice != 0 && outputDevice->isOk()))
  191631. && (inputDeviceId.isEmpty() || (inputDevice != 0 && inputDevice->isOk()));
  191632. }
  191633. WASAPIAudioIODevice (const WASAPIAudioIODevice&);
  191634. WASAPIAudioIODevice& operator= (const WASAPIAudioIODevice&);
  191635. };
  191636. class WASAPIAudioIODeviceType : public AudioIODeviceType
  191637. {
  191638. public:
  191639. WASAPIAudioIODeviceType()
  191640. : AudioIODeviceType ("Windows Audio"),
  191641. hasScanned (false)
  191642. {
  191643. }
  191644. ~WASAPIAudioIODeviceType()
  191645. {
  191646. }
  191647. void scanForDevices()
  191648. {
  191649. hasScanned = true;
  191650. outputDeviceNames.clear();
  191651. inputDeviceNames.clear();
  191652. outputDeviceIds.clear();
  191653. inputDeviceIds.clear();
  191654. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  191655. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  191656. return;
  191657. const String defaultRenderer = getDefaultEndpoint (enumerator, false);
  191658. const String defaultCapture = getDefaultEndpoint (enumerator, true);
  191659. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  191660. UINT32 numDevices = 0;
  191661. if (! (OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection))
  191662. && OK (deviceCollection->GetCount (&numDevices))))
  191663. return;
  191664. for (UINT32 i = 0; i < numDevices; ++i)
  191665. {
  191666. ComSmartPtr <IMMDevice> device;
  191667. if (! OK (deviceCollection->Item (i, &device)))
  191668. continue;
  191669. const String deviceId (wasapi_getDeviceID (device));
  191670. DWORD state = 0;
  191671. if (! OK (device->GetState (&state)))
  191672. continue;
  191673. if (state != DEVICE_STATE_ACTIVE)
  191674. continue;
  191675. String name;
  191676. {
  191677. ComSmartPtr <IPropertyStore> properties;
  191678. if (! OK (device->OpenPropertyStore (STGM_READ, &properties)))
  191679. continue;
  191680. PROPVARIANT value;
  191681. PropVariantInit (&value);
  191682. if (OK (properties->GetValue (PKEY_Device_FriendlyName, &value)))
  191683. name = value.pwszVal;
  191684. PropVariantClear (&value);
  191685. }
  191686. const EDataFlow flow = wasapi_getDataFlow (device);
  191687. if (flow == eRender)
  191688. {
  191689. const int index = (deviceId == defaultRenderer) ? 0 : -1;
  191690. outputDeviceIds.insert (index, deviceId);
  191691. outputDeviceNames.insert (index, name);
  191692. }
  191693. else if (flow == eCapture)
  191694. {
  191695. const int index = (deviceId == defaultCapture) ? 0 : -1;
  191696. inputDeviceIds.insert (index, deviceId);
  191697. inputDeviceNames.insert (index, name);
  191698. }
  191699. }
  191700. inputDeviceNames.appendNumbersToDuplicates (false, false);
  191701. outputDeviceNames.appendNumbersToDuplicates (false, false);
  191702. }
  191703. const StringArray getDeviceNames (const bool wantInputNames) const
  191704. {
  191705. jassert (hasScanned); // need to call scanForDevices() before doing this
  191706. return wantInputNames ? inputDeviceNames
  191707. : outputDeviceNames;
  191708. }
  191709. int getDefaultDeviceIndex (const bool /*forInput*/) const
  191710. {
  191711. jassert (hasScanned); // need to call scanForDevices() before doing this
  191712. return 0;
  191713. }
  191714. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  191715. {
  191716. jassert (hasScanned); // need to call scanForDevices() before doing this
  191717. WASAPIAudioIODevice* const d = dynamic_cast <WASAPIAudioIODevice*> (device);
  191718. return d == 0 ? -1 : (asInput ? inputDeviceIds.indexOf (d->inputDeviceId)
  191719. : outputDeviceIds.indexOf (d->outputDeviceId));
  191720. }
  191721. bool hasSeparateInputsAndOutputs() const { return true; }
  191722. AudioIODevice* createDevice (const String& outputDeviceName,
  191723. const String& inputDeviceName)
  191724. {
  191725. jassert (hasScanned); // need to call scanForDevices() before doing this
  191726. const bool useExclusiveMode = false;
  191727. ScopedPointer<WASAPIAudioIODevice> device;
  191728. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  191729. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  191730. if (outputIndex >= 0 || inputIndex >= 0)
  191731. {
  191732. device = new WASAPIAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  191733. : inputDeviceName,
  191734. outputDeviceIds [outputIndex],
  191735. inputDeviceIds [inputIndex],
  191736. useExclusiveMode);
  191737. if (! device->initialise())
  191738. device = 0;
  191739. }
  191740. return device.release();
  191741. }
  191742. juce_UseDebuggingNewOperator
  191743. StringArray outputDeviceNames, outputDeviceIds;
  191744. StringArray inputDeviceNames, inputDeviceIds;
  191745. private:
  191746. bool hasScanned;
  191747. static const String getDefaultEndpoint (IMMDeviceEnumerator* const enumerator, const bool forCapture)
  191748. {
  191749. String s;
  191750. IMMDevice* dev = 0;
  191751. if (OK (enumerator->GetDefaultAudioEndpoint (forCapture ? eCapture : eRender,
  191752. eMultimedia, &dev)))
  191753. {
  191754. WCHAR* deviceId = 0;
  191755. if (OK (dev->GetId (&deviceId)))
  191756. {
  191757. s = String (deviceId);
  191758. CoTaskMemFree (deviceId);
  191759. }
  191760. dev->Release();
  191761. }
  191762. return s;
  191763. }
  191764. WASAPIAudioIODeviceType (const WASAPIAudioIODeviceType&);
  191765. WASAPIAudioIODeviceType& operator= (const WASAPIAudioIODeviceType&);
  191766. };
  191767. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI()
  191768. {
  191769. return new WASAPIAudioIODeviceType();
  191770. }
  191771. #undef logFailure
  191772. #undef OK
  191773. #endif
  191774. /*** End of inlined file: juce_win32_WASAPI.cpp ***/
  191775. /*** Start of inlined file: juce_win32_CameraDevice.cpp ***/
  191776. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  191777. // compiled on its own).
  191778. #if JUCE_INCLUDED_FILE && JUCE_USE_CAMERA
  191779. class DShowCameraDeviceInteral : public ChangeBroadcaster
  191780. {
  191781. public:
  191782. DShowCameraDeviceInteral (CameraDevice* const owner_,
  191783. const ComSmartPtr <ICaptureGraphBuilder2>& captureGraphBuilder_,
  191784. const ComSmartPtr <IBaseFilter>& filter_,
  191785. int minWidth, int minHeight,
  191786. int maxWidth, int maxHeight)
  191787. : owner (owner_),
  191788. captureGraphBuilder (captureGraphBuilder_),
  191789. filter (filter_),
  191790. ok (false),
  191791. imageNeedsFlipping (false),
  191792. width (0),
  191793. height (0),
  191794. activeUsers (0),
  191795. recordNextFrameTime (false),
  191796. activeImage (0),
  191797. loadingImage (0)
  191798. {
  191799. HRESULT hr = graphBuilder.CoCreateInstance (CLSID_FilterGraph, CLSCTX_INPROC);
  191800. if (FAILED (hr))
  191801. return;
  191802. hr = captureGraphBuilder->SetFiltergraph (graphBuilder);
  191803. if (FAILED (hr))
  191804. return;
  191805. hr = graphBuilder->QueryInterface (IID_IMediaControl, (void**) &mediaControl);
  191806. if (FAILED (hr))
  191807. return;
  191808. {
  191809. ComSmartPtr <IAMStreamConfig> streamConfig;
  191810. hr = captureGraphBuilder->FindInterface (&PIN_CATEGORY_CAPTURE, 0, filter,
  191811. IID_IAMStreamConfig, (void**) &streamConfig);
  191812. if (streamConfig != 0)
  191813. {
  191814. getVideoSizes (streamConfig);
  191815. if (! selectVideoSize (streamConfig, minWidth, minHeight, maxWidth, maxHeight))
  191816. return;
  191817. }
  191818. }
  191819. hr = graphBuilder->AddFilter (filter, _T("Video Capture"));
  191820. if (FAILED (hr))
  191821. return;
  191822. hr = smartTee.CoCreateInstance (CLSID_SmartTee, CLSCTX_INPROC_SERVER);
  191823. if (FAILED (hr))
  191824. return;
  191825. hr = graphBuilder->AddFilter (smartTee, _T("Smart Tee"));
  191826. if (FAILED (hr))
  191827. return;
  191828. if (! connectFilters (filter, smartTee))
  191829. return;
  191830. ComSmartPtr <IBaseFilter> sampleGrabberBase;
  191831. hr = sampleGrabberBase.CoCreateInstance (CLSID_SampleGrabber, CLSCTX_INPROC_SERVER);
  191832. if (FAILED (hr))
  191833. return;
  191834. hr = sampleGrabberBase->QueryInterface (IID_ISampleGrabber, (void**) &sampleGrabber);
  191835. if (FAILED (hr))
  191836. return;
  191837. AM_MEDIA_TYPE mt;
  191838. zerostruct (mt);
  191839. mt.majortype = MEDIATYPE_Video;
  191840. mt.subtype = MEDIASUBTYPE_RGB24;
  191841. mt.formattype = FORMAT_VideoInfo;
  191842. sampleGrabber->SetMediaType (&mt);
  191843. callback = new GrabberCallback (*this);
  191844. sampleGrabber->SetCallback (callback, 1);
  191845. hr = graphBuilder->AddFilter (sampleGrabberBase, _T("Sample Grabber"));
  191846. if (FAILED (hr))
  191847. return;
  191848. ComSmartPtr <IPin> grabberInputPin;
  191849. if (! (getPin (smartTee, PINDIR_OUTPUT, &smartTeeCaptureOutputPin, "capture")
  191850. && getPin (smartTee, PINDIR_OUTPUT, &smartTeePreviewOutputPin, "preview")
  191851. && getPin (sampleGrabberBase, PINDIR_INPUT, &grabberInputPin)))
  191852. return;
  191853. hr = graphBuilder->Connect (smartTeePreviewOutputPin, grabberInputPin);
  191854. if (FAILED (hr))
  191855. return;
  191856. zerostruct (mt);
  191857. hr = sampleGrabber->GetConnectedMediaType (&mt);
  191858. VIDEOINFOHEADER* pVih = (VIDEOINFOHEADER*) (mt.pbFormat);
  191859. width = pVih->bmiHeader.biWidth;
  191860. height = pVih->bmiHeader.biHeight;
  191861. ComSmartPtr <IBaseFilter> nullFilter;
  191862. hr = nullFilter.CoCreateInstance (CLSID_NullRenderer, CLSCTX_INPROC_SERVER);
  191863. hr = graphBuilder->AddFilter (nullFilter, _T("Null Renderer"));
  191864. if (connectFilters (sampleGrabberBase, nullFilter)
  191865. && addGraphToRot())
  191866. {
  191867. activeImage = new Image (Image::RGB, width, height, true);
  191868. loadingImage = new Image (Image::RGB, width, height, true);
  191869. ok = true;
  191870. }
  191871. }
  191872. ~DShowCameraDeviceInteral()
  191873. {
  191874. if (mediaControl != 0)
  191875. mediaControl->Stop();
  191876. removeGraphFromRot();
  191877. for (int i = viewerComps.size(); --i >= 0;)
  191878. ((DShowCaptureViewerComp*) viewerComps.getUnchecked(i))->ownerDeleted();
  191879. callback = 0;
  191880. graphBuilder = 0;
  191881. sampleGrabber = 0;
  191882. mediaControl = 0;
  191883. filter = 0;
  191884. captureGraphBuilder = 0;
  191885. smartTee = 0;
  191886. smartTeePreviewOutputPin = 0;
  191887. smartTeeCaptureOutputPin = 0;
  191888. asfWriter = 0;
  191889. delete activeImage;
  191890. delete loadingImage;
  191891. }
  191892. void addUser()
  191893. {
  191894. if (ok && activeUsers++ == 0)
  191895. mediaControl->Run();
  191896. }
  191897. void removeUser()
  191898. {
  191899. if (ok && --activeUsers == 0)
  191900. mediaControl->Stop();
  191901. }
  191902. void handleFrame (double /*time*/, BYTE* buffer, long /*bufferSize*/)
  191903. {
  191904. if (recordNextFrameTime)
  191905. {
  191906. const double defaultCameraLatency = 0.1;
  191907. firstRecordedTime = Time::getCurrentTime() - RelativeTime (defaultCameraLatency);
  191908. recordNextFrameTime = false;
  191909. ComSmartPtr <IPin> pin;
  191910. if (getPin (filter, PINDIR_OUTPUT, &pin))
  191911. {
  191912. ComSmartPtr <IAMPushSource> pushSource;
  191913. HRESULT hr = pin->QueryInterface (IID_IAMPushSource, (void**) &pushSource);
  191914. if (pushSource != 0)
  191915. {
  191916. REFERENCE_TIME latency = 0;
  191917. hr = pushSource->GetLatency (&latency);
  191918. firstRecordedTime = firstRecordedTime - RelativeTime ((double) latency);
  191919. }
  191920. }
  191921. }
  191922. {
  191923. const int lineStride = width * 3;
  191924. const ScopedLock sl (imageSwapLock);
  191925. {
  191926. const Image::BitmapData destData (*loadingImage, 0, 0, width, height, true);
  191927. for (int i = 0; i < height; ++i)
  191928. memcpy (destData.getLinePointer ((height - 1) - i),
  191929. buffer + lineStride * i,
  191930. lineStride);
  191931. }
  191932. imageNeedsFlipping = true;
  191933. }
  191934. if (listeners.size() > 0)
  191935. callListeners (*loadingImage);
  191936. sendChangeMessage (this);
  191937. }
  191938. void drawCurrentImage (Graphics& g, int x, int y, int w, int h)
  191939. {
  191940. if (imageNeedsFlipping)
  191941. {
  191942. const ScopedLock sl (imageSwapLock);
  191943. swapVariables (loadingImage, activeImage);
  191944. imageNeedsFlipping = false;
  191945. }
  191946. RectanglePlacement rp (RectanglePlacement::centred);
  191947. double dx = 0, dy = 0, dw = width, dh = height;
  191948. rp.applyTo (dx, dy, dw, dh, x, y, w, h);
  191949. const int rx = roundToInt (dx), ry = roundToInt (dy);
  191950. const int rw = roundToInt (dw), rh = roundToInt (dh);
  191951. g.saveState();
  191952. g.excludeClipRegion (Rectangle<int> (rx, ry, rw, rh));
  191953. g.fillAll (Colours::black);
  191954. g.restoreState();
  191955. g.drawImage (activeImage, rx, ry, rw, rh, 0, 0, width, height);
  191956. }
  191957. bool createFileCaptureFilter (const File& file)
  191958. {
  191959. removeFileCaptureFilter();
  191960. file.deleteFile();
  191961. mediaControl->Stop();
  191962. firstRecordedTime = Time();
  191963. recordNextFrameTime = true;
  191964. HRESULT hr = asfWriter.CoCreateInstance (CLSID_WMAsfWriter, CLSCTX_INPROC_SERVER);
  191965. if (SUCCEEDED (hr))
  191966. {
  191967. ComSmartPtr <IFileSinkFilter> fileSink;
  191968. hr = asfWriter->QueryInterface (IID_IFileSinkFilter, (void**) &fileSink);
  191969. if (SUCCEEDED (hr))
  191970. {
  191971. hr = fileSink->SetFileName (file.getFullPathName(), 0);
  191972. if (SUCCEEDED (hr))
  191973. {
  191974. hr = graphBuilder->AddFilter (asfWriter, _T("AsfWriter"));
  191975. if (SUCCEEDED (hr))
  191976. {
  191977. ComSmartPtr <IConfigAsfWriter> asfConfig;
  191978. hr = asfWriter->QueryInterface (IID_IConfigAsfWriter, (void**) &asfConfig);
  191979. asfConfig->SetIndexMode (true);
  191980. ComSmartPtr <IWMProfileManager> profileManager;
  191981. hr = WMCreateProfileManager (&profileManager);
  191982. // This gibberish is the DirectShow profile for a video-only wmv file.
  191983. String prof ("<profile version=\"589824\" storageformat=\"1\" name=\"Quality\" description=\"Quality type for output.\"><streamconfig "
  191984. "majortype=\"{73646976-0000-0010-8000-00AA00389B71}\" streamnumber=\"1\" streamname=\"Video Stream\" inputname=\"Video409\" bitrate=\"894960\" "
  191985. "bufferwindow=\"0\" reliabletransport=\"1\" decodercomplexity=\"AU\" rfc1766langid=\"en-us\"><videomediaprops maxkeyframespacing=\"50000000\" quality=\"90\"/>"
  191986. "<wmmediatype subtype=\"{33564D57-0000-0010-8000-00AA00389B71}\" bfixedsizesamples=\"0\" btemporalcompression=\"1\" lsamplesize=\"0\"> <videoinfoheader "
  191987. "dwbitrate=\"894960\" dwbiterrorrate=\"0\" avgtimeperframe=\"100000\"><rcsource left=\"0\" top=\"0\" right=\"$WIDTH\" bottom=\"$HEIGHT\"/> <rctarget "
  191988. "left=\"0\" top=\"0\" right=\"$WIDTH\" bottom=\"$HEIGHT\"/> <bitmapinfoheader biwidth=\"$WIDTH\" biheight=\"$HEIGHT\" biplanes=\"1\" bibitcount=\"24\" "
  191989. "bicompression=\"WMV3\" bisizeimage=\"0\" bixpelspermeter=\"0\" biypelspermeter=\"0\" biclrused=\"0\" biclrimportant=\"0\"/> "
  191990. "</videoinfoheader></wmmediatype></streamconfig></profile>");
  191991. prof = prof.replace (T("$WIDTH"), String (width))
  191992. .replace (T("$HEIGHT"), String (height));
  191993. ComSmartPtr <IWMProfile> currentProfile;
  191994. hr = profileManager->LoadProfileByData ((const WCHAR*) prof, &currentProfile);
  191995. hr = asfConfig->ConfigureFilterUsingProfile (currentProfile);
  191996. if (SUCCEEDED (hr))
  191997. {
  191998. ComSmartPtr <IPin> asfWriterInputPin;
  191999. if (getPin (asfWriter, PINDIR_INPUT, &asfWriterInputPin, "Video Input 01"))
  192000. {
  192001. hr = graphBuilder->Connect (smartTeeCaptureOutputPin, asfWriterInputPin);
  192002. if (SUCCEEDED (hr)
  192003. && ok && activeUsers > 0
  192004. && SUCCEEDED (mediaControl->Run()))
  192005. {
  192006. return true;
  192007. }
  192008. }
  192009. }
  192010. }
  192011. }
  192012. }
  192013. }
  192014. removeFileCaptureFilter();
  192015. if (ok && activeUsers > 0)
  192016. mediaControl->Run();
  192017. return false;
  192018. }
  192019. void removeFileCaptureFilter()
  192020. {
  192021. mediaControl->Stop();
  192022. if (asfWriter != 0)
  192023. {
  192024. graphBuilder->RemoveFilter (asfWriter);
  192025. asfWriter = 0;
  192026. }
  192027. if (ok && activeUsers > 0)
  192028. mediaControl->Run();
  192029. }
  192030. void addListener (CameraImageListener* listenerToAdd)
  192031. {
  192032. const ScopedLock sl (listenerLock);
  192033. if (listeners.size() == 0)
  192034. addUser();
  192035. listeners.addIfNotAlreadyThere (listenerToAdd);
  192036. }
  192037. void removeListener (CameraImageListener* listenerToRemove)
  192038. {
  192039. const ScopedLock sl (listenerLock);
  192040. listeners.removeValue (listenerToRemove);
  192041. if (listeners.size() == 0)
  192042. removeUser();
  192043. }
  192044. void callListeners (Image& image)
  192045. {
  192046. const ScopedLock sl (listenerLock);
  192047. for (int i = listeners.size(); --i >= 0;)
  192048. {
  192049. CameraImageListener* l = (CameraImageListener*) listeners[i];
  192050. if (l != 0)
  192051. l->imageReceived (image);
  192052. }
  192053. }
  192054. class DShowCaptureViewerComp : public Component,
  192055. public ChangeListener
  192056. {
  192057. public:
  192058. DShowCaptureViewerComp (DShowCameraDeviceInteral* const owner_)
  192059. : owner (owner_)
  192060. {
  192061. setOpaque (true);
  192062. owner->addChangeListener (this);
  192063. owner->addUser();
  192064. owner->viewerComps.add (this);
  192065. setSize (owner_->width, owner_->height);
  192066. }
  192067. ~DShowCaptureViewerComp()
  192068. {
  192069. if (owner != 0)
  192070. {
  192071. owner->viewerComps.removeValue (this);
  192072. owner->removeUser();
  192073. owner->removeChangeListener (this);
  192074. }
  192075. }
  192076. void ownerDeleted()
  192077. {
  192078. owner = 0;
  192079. }
  192080. void paint (Graphics& g)
  192081. {
  192082. g.setColour (Colours::black);
  192083. g.setImageResamplingQuality (Graphics::lowResamplingQuality);
  192084. if (owner != 0)
  192085. owner->drawCurrentImage (g, 0, 0, getWidth(), getHeight());
  192086. else
  192087. g.fillAll (Colours::black);
  192088. }
  192089. void changeListenerCallback (void*)
  192090. {
  192091. repaint();
  192092. }
  192093. private:
  192094. DShowCameraDeviceInteral* owner;
  192095. };
  192096. bool ok;
  192097. int width, height;
  192098. Time firstRecordedTime;
  192099. VoidArray viewerComps;
  192100. private:
  192101. CameraDevice* const owner;
  192102. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192103. ComSmartPtr <IBaseFilter> filter;
  192104. ComSmartPtr <IBaseFilter> smartTee;
  192105. ComSmartPtr <IGraphBuilder> graphBuilder;
  192106. ComSmartPtr <ISampleGrabber> sampleGrabber;
  192107. ComSmartPtr <IMediaControl> mediaControl;
  192108. ComSmartPtr <IPin> smartTeePreviewOutputPin;
  192109. ComSmartPtr <IPin> smartTeeCaptureOutputPin;
  192110. ComSmartPtr <IBaseFilter> asfWriter;
  192111. int activeUsers;
  192112. Array <int> widths, heights;
  192113. DWORD graphRegistrationID;
  192114. CriticalSection imageSwapLock;
  192115. bool imageNeedsFlipping;
  192116. Image* loadingImage;
  192117. Image* activeImage;
  192118. bool recordNextFrameTime;
  192119. void getVideoSizes (IAMStreamConfig* const streamConfig)
  192120. {
  192121. widths.clear();
  192122. heights.clear();
  192123. int count = 0, size = 0;
  192124. streamConfig->GetNumberOfCapabilities (&count, &size);
  192125. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192126. {
  192127. for (int i = 0; i < count; ++i)
  192128. {
  192129. VIDEO_STREAM_CONFIG_CAPS scc;
  192130. AM_MEDIA_TYPE* config;
  192131. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192132. if (SUCCEEDED (hr))
  192133. {
  192134. const int w = scc.InputSize.cx;
  192135. const int h = scc.InputSize.cy;
  192136. bool duplicate = false;
  192137. for (int j = widths.size(); --j >= 0;)
  192138. {
  192139. if (w == widths.getUnchecked (j) && h == heights.getUnchecked (j))
  192140. {
  192141. duplicate = true;
  192142. break;
  192143. }
  192144. }
  192145. if (! duplicate)
  192146. {
  192147. DBG ("Camera capture size: " + String (w) + ", " + String (h));
  192148. widths.add (w);
  192149. heights.add (h);
  192150. }
  192151. deleteMediaType (config);
  192152. }
  192153. }
  192154. }
  192155. }
  192156. bool selectVideoSize (IAMStreamConfig* const streamConfig,
  192157. const int minWidth, const int minHeight,
  192158. const int maxWidth, const int maxHeight)
  192159. {
  192160. int count = 0, size = 0, bestArea = 0, bestIndex = -1;
  192161. streamConfig->GetNumberOfCapabilities (&count, &size);
  192162. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192163. {
  192164. AM_MEDIA_TYPE* config;
  192165. VIDEO_STREAM_CONFIG_CAPS scc;
  192166. for (int i = 0; i < count; ++i)
  192167. {
  192168. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192169. if (SUCCEEDED (hr))
  192170. {
  192171. if (scc.InputSize.cx >= minWidth
  192172. && scc.InputSize.cy >= minHeight
  192173. && scc.InputSize.cx <= maxWidth
  192174. && scc.InputSize.cy <= maxHeight)
  192175. {
  192176. int area = scc.InputSize.cx * scc.InputSize.cy;
  192177. if (area > bestArea)
  192178. {
  192179. bestIndex = i;
  192180. bestArea = area;
  192181. }
  192182. }
  192183. deleteMediaType (config);
  192184. }
  192185. }
  192186. if (bestIndex >= 0)
  192187. {
  192188. HRESULT hr = streamConfig->GetStreamCaps (bestIndex, &config, (BYTE*) &scc);
  192189. hr = streamConfig->SetFormat (config);
  192190. deleteMediaType (config);
  192191. return SUCCEEDED (hr);
  192192. }
  192193. }
  192194. return false;
  192195. }
  192196. static bool getPin (IBaseFilter* filter, const PIN_DIRECTION wantedDirection, IPin** result, const char* pinName = 0)
  192197. {
  192198. ComSmartPtr <IEnumPins> enumerator;
  192199. ComSmartPtr <IPin> pin;
  192200. filter->EnumPins (&enumerator);
  192201. while (enumerator->Next (1, &pin, 0) == S_OK)
  192202. {
  192203. PIN_DIRECTION dir;
  192204. pin->QueryDirection (&dir);
  192205. if (wantedDirection == dir)
  192206. {
  192207. PIN_INFO info;
  192208. zerostruct (info);
  192209. pin->QueryPinInfo (&info);
  192210. if (pinName == 0 || String (pinName).equalsIgnoreCase (String (info.achName)))
  192211. {
  192212. pin.p->AddRef();
  192213. *result = pin;
  192214. return true;
  192215. }
  192216. }
  192217. }
  192218. return false;
  192219. }
  192220. bool connectFilters (IBaseFilter* const first, IBaseFilter* const second) const
  192221. {
  192222. ComSmartPtr <IPin> in, out;
  192223. return getPin (first, PINDIR_OUTPUT, &out)
  192224. && getPin (second, PINDIR_INPUT, &in)
  192225. && SUCCEEDED (graphBuilder->Connect (out, in));
  192226. }
  192227. bool addGraphToRot()
  192228. {
  192229. ComSmartPtr <IRunningObjectTable> rot;
  192230. if (FAILED (GetRunningObjectTable (0, &rot)))
  192231. return false;
  192232. ComSmartPtr <IMoniker> moniker;
  192233. WCHAR buffer[128];
  192234. HRESULT hr = CreateItemMoniker (_T("!"), buffer, &moniker);
  192235. if (FAILED (hr))
  192236. return false;
  192237. graphRegistrationID = 0;
  192238. return SUCCEEDED (rot->Register (0, graphBuilder, moniker, &graphRegistrationID));
  192239. }
  192240. void removeGraphFromRot()
  192241. {
  192242. ComSmartPtr <IRunningObjectTable> rot;
  192243. if (SUCCEEDED (GetRunningObjectTable (0, &rot)))
  192244. rot->Revoke (graphRegistrationID);
  192245. }
  192246. static void deleteMediaType (AM_MEDIA_TYPE* const pmt)
  192247. {
  192248. if (pmt->cbFormat != 0)
  192249. CoTaskMemFree ((PVOID) pmt->pbFormat);
  192250. if (pmt->pUnk != 0)
  192251. pmt->pUnk->Release();
  192252. CoTaskMemFree (pmt);
  192253. }
  192254. class GrabberCallback : public ISampleGrabberCB
  192255. {
  192256. public:
  192257. GrabberCallback (DShowCameraDeviceInteral& owner_)
  192258. : owner (owner_)
  192259. {
  192260. }
  192261. HRESULT __stdcall QueryInterface (REFIID id, void** result)
  192262. {
  192263. if (id == IID_IUnknown)
  192264. *result = dynamic_cast <IUnknown*> (this);
  192265. else if (id == IID_ISampleGrabberCB)
  192266. *result = dynamic_cast <ISampleGrabberCB*> (this);
  192267. else
  192268. {
  192269. *result = 0;
  192270. return E_NOINTERFACE;
  192271. }
  192272. AddRef();
  192273. return S_OK;
  192274. }
  192275. ULONG __stdcall AddRef() { return ++refCount; }
  192276. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  192277. STDMETHODIMP SampleCB (double /*SampleTime*/, IMediaSample* /*pSample*/)
  192278. {
  192279. return E_FAIL;
  192280. }
  192281. STDMETHODIMP BufferCB (double time, BYTE* buffer, long bufferSize)
  192282. {
  192283. owner.handleFrame (time, buffer, bufferSize);
  192284. return S_OK;
  192285. }
  192286. private:
  192287. int refCount;
  192288. DShowCameraDeviceInteral& owner;
  192289. GrabberCallback (const GrabberCallback&);
  192290. GrabberCallback& operator= (const GrabberCallback&);
  192291. };
  192292. ComSmartPtr <GrabberCallback> callback;
  192293. VoidArray listeners;
  192294. CriticalSection listenerLock;
  192295. DShowCameraDeviceInteral (const DShowCameraDeviceInteral&);
  192296. DShowCameraDeviceInteral& operator= (const DShowCameraDeviceInteral&);
  192297. };
  192298. CameraDevice::CameraDevice (const String& name_, int /*index*/)
  192299. : name (name_)
  192300. {
  192301. isRecording = false;
  192302. }
  192303. CameraDevice::~CameraDevice()
  192304. {
  192305. stopRecording();
  192306. delete (DShowCameraDeviceInteral*) internal;
  192307. internal = 0;
  192308. }
  192309. Component* CameraDevice::createViewerComponent()
  192310. {
  192311. return new DShowCameraDeviceInteral::DShowCaptureViewerComp ((DShowCameraDeviceInteral*) internal);
  192312. }
  192313. const String CameraDevice::getFileExtension()
  192314. {
  192315. return ".wmv";
  192316. }
  192317. void CameraDevice::startRecordingToFile (const File& file, int quality)
  192318. {
  192319. stopRecording();
  192320. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192321. d->addUser();
  192322. isRecording = d->createFileCaptureFilter (file);
  192323. }
  192324. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  192325. {
  192326. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192327. return d->firstRecordedTime;
  192328. }
  192329. void CameraDevice::stopRecording()
  192330. {
  192331. if (isRecording)
  192332. {
  192333. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192334. d->removeFileCaptureFilter();
  192335. d->removeUser();
  192336. isRecording = false;
  192337. }
  192338. }
  192339. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  192340. {
  192341. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192342. if (listenerToAdd != 0)
  192343. d->addListener (listenerToAdd);
  192344. }
  192345. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  192346. {
  192347. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192348. if (listenerToRemove != 0)
  192349. d->removeListener (listenerToRemove);
  192350. }
  192351. static ComSmartPtr <IBaseFilter> enumerateCameras (StringArray* const names,
  192352. const int deviceIndexToOpen,
  192353. String& name)
  192354. {
  192355. int index = 0;
  192356. ComSmartPtr <IBaseFilter> result;
  192357. ComSmartPtr <ICreateDevEnum> pDevEnum;
  192358. HRESULT hr = pDevEnum.CoCreateInstance (CLSID_SystemDeviceEnum, CLSCTX_INPROC);
  192359. if (SUCCEEDED (hr))
  192360. {
  192361. ComSmartPtr <IEnumMoniker> enumerator;
  192362. hr = pDevEnum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &enumerator, 0);
  192363. if (SUCCEEDED (hr) && enumerator != 0)
  192364. {
  192365. ComSmartPtr <IBaseFilter> captureFilter;
  192366. ComSmartPtr <IMoniker> moniker;
  192367. ULONG fetched;
  192368. while (enumerator->Next (1, &moniker, &fetched) == S_OK)
  192369. {
  192370. hr = moniker->BindToObject (0, 0, IID_IBaseFilter, (void**) &captureFilter);
  192371. if (SUCCEEDED (hr))
  192372. {
  192373. ComSmartPtr <IPropertyBag> propertyBag;
  192374. hr = moniker->BindToStorage (0, 0, IID_IPropertyBag, (void**) &propertyBag);
  192375. if (SUCCEEDED (hr))
  192376. {
  192377. VARIANT var;
  192378. var.vt = VT_BSTR;
  192379. hr = propertyBag->Read (_T("FriendlyName"), &var, 0);
  192380. propertyBag = 0;
  192381. if (SUCCEEDED (hr))
  192382. {
  192383. if (names != 0)
  192384. names->add (var.bstrVal);
  192385. if (index == deviceIndexToOpen)
  192386. {
  192387. name = var.bstrVal;
  192388. result = captureFilter;
  192389. captureFilter = 0;
  192390. break;
  192391. }
  192392. ++index;
  192393. }
  192394. moniker = 0;
  192395. }
  192396. captureFilter = 0;
  192397. }
  192398. }
  192399. }
  192400. }
  192401. return result;
  192402. }
  192403. const StringArray CameraDevice::getAvailableDevices()
  192404. {
  192405. StringArray devs;
  192406. String dummy;
  192407. enumerateCameras (&devs, -1, dummy);
  192408. return devs;
  192409. }
  192410. CameraDevice* CameraDevice::openDevice (int index,
  192411. int minWidth, int minHeight,
  192412. int maxWidth, int maxHeight)
  192413. {
  192414. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192415. HRESULT hr = captureGraphBuilder.CoCreateInstance (CLSID_CaptureGraphBuilder2, CLSCTX_INPROC);
  192416. if (SUCCEEDED (hr))
  192417. {
  192418. String name;
  192419. const ComSmartPtr <IBaseFilter> filter (enumerateCameras (0, index, name));
  192420. if (filter != 0)
  192421. {
  192422. CameraDevice* const cam = new CameraDevice (name, index);
  192423. DShowCameraDeviceInteral* const intern
  192424. = new DShowCameraDeviceInteral (cam, captureGraphBuilder, filter,
  192425. minWidth, minHeight, maxWidth, maxHeight);
  192426. cam->internal = intern;
  192427. if (intern->ok)
  192428. return cam;
  192429. else
  192430. delete cam;
  192431. }
  192432. }
  192433. return 0;
  192434. }
  192435. #endif
  192436. /*** End of inlined file: juce_win32_CameraDevice.cpp ***/
  192437. #endif
  192438. // Auto-link the other win32 libs that are needed by library calls..
  192439. #if (JUCE_AMALGAMATED_TEMPLATE || defined (JUCE_DLL_BUILD)) && JUCE_MSVC && ! DONT_AUTOLINK_TO_WIN32_LIBRARIES
  192440. /*** Start of inlined file: juce_win32_AutoLinkLibraries.h ***/
  192441. // Auto-links to various win32 libs that are needed by library calls..
  192442. #pragma comment(lib, "kernel32.lib")
  192443. #pragma comment(lib, "user32.lib")
  192444. #pragma comment(lib, "shell32.lib")
  192445. #pragma comment(lib, "gdi32.lib")
  192446. #pragma comment(lib, "vfw32.lib")
  192447. #pragma comment(lib, "comdlg32.lib")
  192448. #pragma comment(lib, "winmm.lib")
  192449. #pragma comment(lib, "wininet.lib")
  192450. #pragma comment(lib, "ole32.lib")
  192451. #pragma comment(lib, "oleaut32.lib")
  192452. #pragma comment(lib, "advapi32.lib")
  192453. #pragma comment(lib, "ws2_32.lib")
  192454. #pragma comment(lib, "comsupp.lib")
  192455. #pragma comment(lib, "version.lib")
  192456. #if JUCE_OPENGL
  192457. #pragma comment(lib, "OpenGL32.Lib")
  192458. #pragma comment(lib, "GlU32.Lib")
  192459. #endif
  192460. #if JUCE_QUICKTIME
  192461. #pragma comment (lib, "QTMLClient.lib")
  192462. #endif
  192463. #if JUCE_USE_CAMERA
  192464. #pragma comment (lib, "Strmiids.lib")
  192465. #pragma comment (lib, "wmvcore.lib")
  192466. #endif
  192467. /*** End of inlined file: juce_win32_AutoLinkLibraries.h ***/
  192468. #endif
  192469. END_JUCE_NAMESPACE
  192470. #endif
  192471. /*** End of inlined file: juce_win32_NativeCode.cpp ***/
  192472. #endif
  192473. #if JUCE_LINUX
  192474. /*** Start of inlined file: juce_linux_NativeCode.cpp ***/
  192475. #if JUCE_LINUX
  192476. BEGIN_JUCE_NAMESPACE
  192477. #if defined (CPU_ISSET) && ! defined (SUPPORT_AFFINITIES)
  192478. #define SUPPORT_AFFINITIES 1
  192479. #endif
  192480. #define JUCE_INCLUDED_FILE 1
  192481. // Now include the actual code files..
  192482. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  192483. CriticalSection::CriticalSection() throw()
  192484. {
  192485. pthread_mutexattr_t atts;
  192486. pthread_mutexattr_init (&atts);
  192487. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  192488. pthread_mutex_init (&internal, &atts);
  192489. }
  192490. CriticalSection::~CriticalSection() throw()
  192491. {
  192492. pthread_mutex_destroy (&internal);
  192493. }
  192494. void CriticalSection::enter() const throw()
  192495. {
  192496. pthread_mutex_lock (&internal);
  192497. }
  192498. bool CriticalSection::tryEnter() const throw()
  192499. {
  192500. return pthread_mutex_trylock (&internal) == 0;
  192501. }
  192502. void CriticalSection::exit() const throw()
  192503. {
  192504. pthread_mutex_unlock (&internal);
  192505. }
  192506. class WaitableEventImpl
  192507. {
  192508. public:
  192509. WaitableEventImpl()
  192510. : triggered (false)
  192511. {
  192512. pthread_cond_init (&condition, 0);
  192513. pthread_mutex_init (&mutex, 0);
  192514. }
  192515. ~WaitableEventImpl()
  192516. {
  192517. pthread_cond_destroy (&condition);
  192518. pthread_mutex_destroy (&mutex);
  192519. }
  192520. bool wait (const int timeOutMillisecs) throw()
  192521. {
  192522. pthread_mutex_lock (&mutex);
  192523. if (! triggered)
  192524. {
  192525. if (timeOutMillisecs < 0)
  192526. {
  192527. do
  192528. {
  192529. pthread_cond_wait (&condition, &mutex);
  192530. }
  192531. while (! triggered);
  192532. }
  192533. else
  192534. {
  192535. struct timeval now;
  192536. gettimeofday (&now, 0);
  192537. struct timespec time;
  192538. time.tv_sec = now.tv_sec + (timeOutMillisecs / 1000);
  192539. time.tv_nsec = (now.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  192540. if (time.tv_nsec >= 1000000000)
  192541. {
  192542. time.tv_nsec -= 1000000000;
  192543. time.tv_sec++;
  192544. }
  192545. do
  192546. {
  192547. if (pthread_cond_timedwait (&condition, &mutex, &time) == ETIMEDOUT)
  192548. {
  192549. pthread_mutex_unlock (&mutex);
  192550. return false;
  192551. }
  192552. }
  192553. while (! triggered);
  192554. }
  192555. }
  192556. triggered = false;
  192557. pthread_mutex_unlock (&mutex);
  192558. return true;
  192559. }
  192560. void signal() throw()
  192561. {
  192562. pthread_mutex_lock (&mutex);
  192563. triggered = true;
  192564. pthread_cond_broadcast (&condition);
  192565. pthread_mutex_unlock (&mutex);
  192566. }
  192567. void reset() throw()
  192568. {
  192569. pthread_mutex_lock (&mutex);
  192570. triggered = false;
  192571. pthread_mutex_unlock (&mutex);
  192572. }
  192573. private:
  192574. pthread_cond_t condition;
  192575. pthread_mutex_t mutex;
  192576. bool triggered;
  192577. WaitableEventImpl (const WaitableEventImpl&);
  192578. WaitableEventImpl& operator= (const WaitableEventImpl&);
  192579. };
  192580. WaitableEvent::WaitableEvent() throw()
  192581. : internal (new WaitableEventImpl())
  192582. {
  192583. }
  192584. WaitableEvent::~WaitableEvent() throw()
  192585. {
  192586. delete static_cast <WaitableEventImpl*> (internal);
  192587. }
  192588. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  192589. {
  192590. return static_cast <WaitableEventImpl*> (internal)->wait (timeOutMillisecs);
  192591. }
  192592. void WaitableEvent::signal() const throw()
  192593. {
  192594. static_cast <WaitableEventImpl*> (internal)->signal();
  192595. }
  192596. void WaitableEvent::reset() const throw()
  192597. {
  192598. static_cast <WaitableEventImpl*> (internal)->reset();
  192599. }
  192600. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  192601. {
  192602. struct timespec time;
  192603. time.tv_sec = millisecs / 1000;
  192604. time.tv_nsec = (millisecs % 1000) * 1000000;
  192605. nanosleep (&time, 0);
  192606. }
  192607. const juce_wchar File::separator = '/';
  192608. const juce_wchar* File::separatorString = T("/");
  192609. const File File::getCurrentWorkingDirectory()
  192610. {
  192611. HeapBlock<char> heapBuffer;
  192612. char localBuffer [1024];
  192613. char* cwd = getcwd (localBuffer, sizeof (localBuffer) - 1);
  192614. int bufferSize = 4096;
  192615. while (cwd == 0 && errno == ERANGE)
  192616. {
  192617. heapBuffer.malloc (bufferSize);
  192618. cwd = getcwd (heapBuffer, bufferSize - 1);
  192619. bufferSize += 1024;
  192620. }
  192621. return File (String::fromUTF8 (cwd));
  192622. }
  192623. bool File::setAsCurrentWorkingDirectory() const
  192624. {
  192625. return chdir (getFullPathName().toUTF8()) == 0;
  192626. }
  192627. bool juce_copyFile (const String& s, const String& d);
  192628. static bool juce_stat (const String& fileName, struct stat& info)
  192629. {
  192630. return fileName.isNotEmpty()
  192631. && (stat (fileName.toUTF8(), &info) == 0);
  192632. }
  192633. bool juce_isDirectory (const String& fileName)
  192634. {
  192635. struct stat info;
  192636. return fileName.isEmpty()
  192637. || (juce_stat (fileName, info)
  192638. && ((info.st_mode & S_IFDIR) != 0));
  192639. }
  192640. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  192641. {
  192642. if (fileName.isEmpty())
  192643. return false;
  192644. const char* const fileNameUTF8 = fileName.toUTF8();
  192645. bool exists = access (fileNameUTF8, F_OK) == 0;
  192646. if (exists && dontCountDirectories)
  192647. {
  192648. struct stat info;
  192649. const int res = stat (fileNameUTF8, &info);
  192650. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  192651. exists = false;
  192652. }
  192653. return exists;
  192654. }
  192655. int64 juce_getFileSize (const String& fileName)
  192656. {
  192657. struct stat info;
  192658. return juce_stat (fileName, info) ? info.st_size : 0;
  192659. }
  192660. bool juce_canWriteToFile (const String& fileName)
  192661. {
  192662. return access (fileName.toUTF8(), W_OK) == 0;
  192663. }
  192664. bool juce_deleteFile (const String& fileName)
  192665. {
  192666. if (juce_isDirectory (fileName))
  192667. return rmdir (fileName.toUTF8()) == 0;
  192668. else
  192669. return remove (fileName.toUTF8()) == 0;
  192670. }
  192671. bool juce_moveFile (const String& source, const String& dest)
  192672. {
  192673. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  192674. return true;
  192675. if (juce_canWriteToFile (source)
  192676. && juce_copyFile (source, dest))
  192677. {
  192678. if (juce_deleteFile (source))
  192679. return true;
  192680. juce_deleteFile (dest);
  192681. }
  192682. return false;
  192683. }
  192684. void juce_createDirectory (const String& fileName)
  192685. {
  192686. mkdir (fileName.toUTF8(), 0777);
  192687. }
  192688. void* juce_fileOpen (const String& fileName, bool forWriting)
  192689. {
  192690. int flags = O_RDONLY;
  192691. if (forWriting)
  192692. {
  192693. if (juce_fileExists (fileName, false))
  192694. {
  192695. const int f = open (fileName.toUTF8(), O_RDWR, 00644);
  192696. if (f != -1)
  192697. lseek (f, 0, SEEK_END);
  192698. return (void*) f;
  192699. }
  192700. else
  192701. {
  192702. flags = O_RDWR + O_CREAT;
  192703. }
  192704. }
  192705. return (void*) open (fileName.toUTF8(), flags, 00644);
  192706. }
  192707. void juce_fileClose (void* handle)
  192708. {
  192709. if (handle != 0)
  192710. close ((int) (pointer_sized_int) handle);
  192711. }
  192712. int juce_fileRead (void* handle, void* buffer, int size)
  192713. {
  192714. if (handle != 0)
  192715. return jmax (0, (int) read ((int) (pointer_sized_int) handle, buffer, size));
  192716. return 0;
  192717. }
  192718. int juce_fileWrite (void* handle, const void* buffer, int size)
  192719. {
  192720. if (handle != 0)
  192721. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  192722. return 0;
  192723. }
  192724. int64 juce_fileSetPosition (void* handle, int64 pos)
  192725. {
  192726. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  192727. return pos;
  192728. return -1;
  192729. }
  192730. int64 juce_fileGetPosition (void* handle)
  192731. {
  192732. if (handle != 0)
  192733. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  192734. return -1;
  192735. }
  192736. void juce_fileFlush (void* handle)
  192737. {
  192738. if (handle != 0)
  192739. fsync ((int) (pointer_sized_int) handle);
  192740. }
  192741. const File juce_getExecutableFile()
  192742. {
  192743. Dl_info exeInfo;
  192744. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  192745. return File (String::fromUTF8 (exeInfo.dli_fname));
  192746. }
  192747. // if this file doesn't exist, find a parent of it that does..
  192748. static bool doStatFS (const File* file, struct statfs& result)
  192749. {
  192750. File f (*file);
  192751. for (int i = 5; --i >= 0;)
  192752. {
  192753. if (f.exists())
  192754. break;
  192755. f = f.getParentDirectory();
  192756. }
  192757. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  192758. }
  192759. int64 File::getBytesFreeOnVolume() const
  192760. {
  192761. struct statfs buf;
  192762. if (doStatFS (this, buf))
  192763. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  192764. return 0;
  192765. }
  192766. int64 File::getVolumeTotalSize() const
  192767. {
  192768. struct statfs buf;
  192769. if (doStatFS (this, buf))
  192770. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  192771. return 0;
  192772. }
  192773. const String juce_getVolumeLabel (const String& filenameOnVolume,
  192774. int& volumeSerialNumber)
  192775. {
  192776. volumeSerialNumber = 0;
  192777. #if JUCE_MAC
  192778. struct VolAttrBuf
  192779. {
  192780. u_int32_t length;
  192781. attrreference_t mountPointRef;
  192782. char mountPointSpace [MAXPATHLEN];
  192783. } attrBuf;
  192784. struct attrlist attrList;
  192785. zerostruct (attrList);
  192786. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  192787. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  192788. File f (filenameOnVolume);
  192789. for (;;)
  192790. {
  192791. if (getattrlist (f.getFullPathName().toUTF8(),
  192792. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  192793. {
  192794. return String::fromUTF8 (((const char*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  192795. (int) attrBuf.mountPointRef.attr_length);
  192796. }
  192797. const File parent (f.getParentDirectory());
  192798. if (f == parent)
  192799. break;
  192800. f = parent;
  192801. }
  192802. #endif
  192803. return String::empty;
  192804. }
  192805. void juce_runSystemCommand (const String& command)
  192806. {
  192807. int result = system (command.toUTF8());
  192808. (void) result;
  192809. }
  192810. const String juce_getOutputFromCommand (const String& command)
  192811. {
  192812. // slight bodge here, as we just pipe the output into a temp file and read it...
  192813. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  192814. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  192815. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  192816. String result (tempFile.loadFileAsString());
  192817. tempFile.deleteFile();
  192818. return result;
  192819. }
  192820. InterProcessLock::InterProcessLock (const String& name_)
  192821. : internal (0),
  192822. name (name_),
  192823. reentrancyLevel (0)
  192824. {
  192825. #if JUCE_MAC
  192826. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  192827. const File temp (File ("~/Library/Caches/Juce").getChildFile (name));
  192828. #else
  192829. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  192830. #endif
  192831. temp.create();
  192832. internal = open (temp.getFullPathName().toUTF8(), O_RDWR);
  192833. }
  192834. InterProcessLock::~InterProcessLock()
  192835. {
  192836. while (reentrancyLevel > 0)
  192837. this->exit();
  192838. close (internal);
  192839. }
  192840. bool InterProcessLock::enter (const int timeOutMillisecs)
  192841. {
  192842. if (internal == 0)
  192843. return false;
  192844. if (reentrancyLevel != 0)
  192845. return true;
  192846. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  192847. struct flock fl;
  192848. zerostruct (fl);
  192849. fl.l_whence = SEEK_SET;
  192850. fl.l_type = F_WRLCK;
  192851. for (;;)
  192852. {
  192853. const int result = fcntl (internal, F_SETLK, &fl);
  192854. if (result >= 0)
  192855. {
  192856. ++reentrancyLevel;
  192857. return true;
  192858. }
  192859. if (errno != EINTR)
  192860. {
  192861. if (timeOutMillisecs == 0
  192862. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  192863. break;
  192864. Thread::sleep (10);
  192865. }
  192866. }
  192867. return false;
  192868. }
  192869. void InterProcessLock::exit()
  192870. {
  192871. if (reentrancyLevel > 0 && internal != 0)
  192872. {
  192873. --reentrancyLevel;
  192874. struct flock fl;
  192875. zerostruct (fl);
  192876. fl.l_whence = SEEK_SET;
  192877. fl.l_type = F_UNLCK;
  192878. for (;;)
  192879. {
  192880. const int result = fcntl (internal, F_SETLKW, &fl);
  192881. if (result >= 0 || errno != EINTR)
  192882. break;
  192883. }
  192884. }
  192885. }
  192886. /*** End of inlined file: juce_posix_SharedCode.h ***/
  192887. /*** Start of inlined file: juce_linux_Files.cpp ***/
  192888. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  192889. // compiled on its own).
  192890. #if JUCE_INCLUDED_FILE
  192891. static const short U_ISOFS_SUPER_MAGIC = 0x9660; // linux/iso_fs.h
  192892. static const short U_MSDOS_SUPER_MAGIC = 0x4d44; // linux/msdos_fs.h
  192893. static const short U_NFS_SUPER_MAGIC = 0x6969; // linux/nfs_fs.h
  192894. static const short U_SMB_SUPER_MAGIC = 0x517B; // linux/smb_fs.h
  192895. void juce_getFileTimes (const String& fileName,
  192896. int64& modificationTime,
  192897. int64& accessTime,
  192898. int64& creationTime)
  192899. {
  192900. modificationTime = 0;
  192901. accessTime = 0;
  192902. creationTime = 0;
  192903. struct stat info;
  192904. const int res = stat (fileName.toUTF8(), &info);
  192905. if (res == 0)
  192906. {
  192907. modificationTime = (int64) info.st_mtime * 1000;
  192908. accessTime = (int64) info.st_atime * 1000;
  192909. creationTime = (int64) info.st_ctime * 1000;
  192910. }
  192911. }
  192912. bool juce_setFileTimes (const String& fileName,
  192913. int64 modificationTime,
  192914. int64 accessTime,
  192915. int64 creationTime)
  192916. {
  192917. struct utimbuf times;
  192918. times.actime = (time_t) (accessTime / 1000);
  192919. times.modtime = (time_t) (modificationTime / 1000);
  192920. return utime (fileName.toUTF8(), &times) == 0;
  192921. }
  192922. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  192923. {
  192924. struct stat info;
  192925. const int res = stat (fileName.toUTF8(), &info);
  192926. if (res != 0)
  192927. return false;
  192928. info.st_mode &= 0777; // Just permissions
  192929. if( isReadOnly )
  192930. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  192931. else
  192932. // Give everybody write permission?
  192933. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  192934. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  192935. }
  192936. bool juce_copyFile (const String& s, const String& d)
  192937. {
  192938. const File source (s), dest (d);
  192939. FileInputStream* in = source.createInputStream();
  192940. bool ok = false;
  192941. if (in != 0)
  192942. {
  192943. if (dest.deleteFile())
  192944. {
  192945. FileOutputStream* const out = dest.createOutputStream();
  192946. if (out != 0)
  192947. {
  192948. const int bytesCopied = out->writeFromInputStream (*in, -1);
  192949. delete out;
  192950. ok = (bytesCopied == source.getSize());
  192951. if (! ok)
  192952. dest.deleteFile();
  192953. }
  192954. }
  192955. delete in;
  192956. }
  192957. return ok;
  192958. }
  192959. const StringArray juce_getFileSystemRoots()
  192960. {
  192961. StringArray s;
  192962. s.add ("/");
  192963. return s;
  192964. }
  192965. bool File::isOnCDRomDrive() const
  192966. {
  192967. struct statfs buf;
  192968. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  192969. return (buf.f_type == U_ISOFS_SUPER_MAGIC);
  192970. // Assume not if this fails for some reason
  192971. return false;
  192972. }
  192973. bool File::isOnHardDisk() const
  192974. {
  192975. struct statfs buf;
  192976. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  192977. {
  192978. switch (buf.f_type)
  192979. {
  192980. case U_ISOFS_SUPER_MAGIC: // CD-ROM
  192981. case U_MSDOS_SUPER_MAGIC: // Probably floppy (but could be mounted FAT filesystem)
  192982. case U_NFS_SUPER_MAGIC: // Network NFS
  192983. case U_SMB_SUPER_MAGIC: // Network Samba
  192984. return false;
  192985. default:
  192986. // Assume anything else is a hard-disk (but note it could
  192987. // be a RAM disk. There isn't a good way of determining
  192988. // this for sure)
  192989. return true;
  192990. }
  192991. }
  192992. // Assume so if this fails for some reason
  192993. return true;
  192994. }
  192995. bool File::isOnRemovableDrive() const
  192996. {
  192997. jassertfalse // xxx not implemented for linux!
  192998. return false;
  192999. }
  193000. bool File::isHidden() const
  193001. {
  193002. return getFileName().startsWithChar ('.');
  193003. }
  193004. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  193005. const File File::getSpecialLocation (const SpecialLocationType type)
  193006. {
  193007. switch (type)
  193008. {
  193009. case userHomeDirectory:
  193010. {
  193011. const char* homeDir = getenv ("HOME");
  193012. if (homeDir == 0)
  193013. {
  193014. struct passwd* const pw = getpwuid (getuid());
  193015. if (pw != 0)
  193016. homeDir = pw->pw_dir;
  193017. }
  193018. return File (String::fromUTF8 (homeDir));
  193019. }
  193020. case userDocumentsDirectory:
  193021. case userMusicDirectory:
  193022. case userMoviesDirectory:
  193023. case userApplicationDataDirectory:
  193024. return File ("~");
  193025. case userDesktopDirectory:
  193026. return File ("~/Desktop");
  193027. case commonApplicationDataDirectory:
  193028. return File ("/var");
  193029. case globalApplicationsDirectory:
  193030. return File ("/usr");
  193031. case tempDirectory:
  193032. {
  193033. File tmp ("/var/tmp");
  193034. if (! tmp.isDirectory())
  193035. {
  193036. tmp = "/tmp";
  193037. if (! tmp.isDirectory())
  193038. tmp = File::getCurrentWorkingDirectory();
  193039. }
  193040. return tmp;
  193041. }
  193042. case invokedExecutableFile:
  193043. if (juce_Argv0 != 0)
  193044. return File (String::fromUTF8 (juce_Argv0));
  193045. // deliberate fall-through...
  193046. case currentExecutableFile:
  193047. case currentApplicationFile:
  193048. return juce_getExecutableFile();
  193049. default:
  193050. jassertfalse // unknown type?
  193051. break;
  193052. }
  193053. return File::nonexistent;
  193054. }
  193055. const String File::getVersion() const
  193056. {
  193057. return String::empty; // xxx not yet implemented
  193058. }
  193059. const File File::getLinkedTarget() const
  193060. {
  193061. char buffer [4096];
  193062. size_t numChars = readlink (getFullPathName().toUTF8(),
  193063. buffer, sizeof (buffer));
  193064. if (numChars > 0 && numChars <= sizeof (buffer))
  193065. return File (String::fromUTF8 (buffer, (int) numChars));
  193066. return *this;
  193067. }
  193068. bool File::moveToTrash() const
  193069. {
  193070. if (! exists())
  193071. return true;
  193072. File trashCan ("~/.Trash");
  193073. if (! trashCan.isDirectory())
  193074. trashCan = "~/.local/share/Trash/files";
  193075. if (! trashCan.isDirectory())
  193076. return false;
  193077. return moveFileTo (trashCan.getNonexistentChildFile (getFileNameWithoutExtension(),
  193078. getFileExtension()));
  193079. }
  193080. struct FindFileStruct
  193081. {
  193082. String parentDir, wildCard;
  193083. DIR* dir;
  193084. bool getNextMatch (String& result, bool* const isDir, bool* const isHidden, int64* const fileSize,
  193085. Time* const modTime, Time* const creationTime, bool* const isReadOnly)
  193086. {
  193087. const char* const wildcardUTF8 = wildCard.toUTF8();
  193088. for (;;)
  193089. {
  193090. struct dirent* const de = readdir (dir);
  193091. if (de == 0)
  193092. break;
  193093. if (fnmatch (wildcardUTF8, de->d_name, FNM_CASEFOLD) == 0)
  193094. {
  193095. result = String::fromUTF8 (de->d_name);
  193096. const String path (parentDir + result);
  193097. if (isDir != 0 || fileSize != 0)
  193098. {
  193099. struct stat info;
  193100. const bool statOk = (stat (path.toUTF8(), &info) == 0);
  193101. if (isDir != 0)
  193102. *isDir = path.isEmpty() || (statOk && ((info.st_mode & S_IFDIR) != 0));
  193103. if (isHidden != 0)
  193104. *isHidden = (de->d_name[0] == '.');
  193105. if (fileSize != 0)
  193106. *fileSize = statOk ? info.st_size : 0;
  193107. }
  193108. if (modTime != 0 || creationTime != 0)
  193109. {
  193110. int64 m, a, c;
  193111. juce_getFileTimes (path, m, a, c);
  193112. if (modTime != 0)
  193113. *modTime = m;
  193114. if (creationTime != 0)
  193115. *creationTime = c;
  193116. }
  193117. if (isReadOnly != 0)
  193118. *isReadOnly = ! juce_canWriteToFile (path);
  193119. return true;
  193120. }
  193121. }
  193122. return false;
  193123. }
  193124. };
  193125. // returns 0 on failure
  193126. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  193127. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  193128. Time* creationTime, bool* isReadOnly)
  193129. {
  193130. DIR* d = opendir (directory.toUTF8());
  193131. if (d != 0)
  193132. {
  193133. FindFileStruct* ff = new FindFileStruct();
  193134. ff->parentDir = directory;
  193135. if (!ff->parentDir.endsWithChar (File::separator))
  193136. ff->parentDir += File::separator;
  193137. ff->wildCard = wildCard;
  193138. if (wildCard == "*.*")
  193139. ff->wildCard = "*";
  193140. ff->dir = d;
  193141. if (ff->getNextMatch (firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  193142. {
  193143. return ff;
  193144. }
  193145. else
  193146. {
  193147. firstResultFile = String::empty;
  193148. isDir = false;
  193149. isHidden = false;
  193150. closedir (d);
  193151. delete ff;
  193152. }
  193153. }
  193154. return 0;
  193155. }
  193156. bool juce_findFileNext (void* handle, String& resultFile,
  193157. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  193158. {
  193159. FindFileStruct* const ff = (FindFileStruct*) handle;
  193160. if (ff != 0)
  193161. return ff->getNextMatch (resultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly);
  193162. return false;
  193163. }
  193164. void juce_findFileClose (void* handle)
  193165. {
  193166. FindFileStruct* const ff = (FindFileStruct*) handle;
  193167. if (ff != 0)
  193168. {
  193169. closedir (ff->dir);
  193170. delete ff;
  193171. }
  193172. }
  193173. bool juce_launchFile (const String& fileName,
  193174. const String& parameters)
  193175. {
  193176. String cmdString (fileName.replace (T(" "), T("\\ "),false));
  193177. cmdString << " " << parameters;
  193178. if (URL::isProbablyAWebsiteURL (fileName)
  193179. || cmdString.startsWithIgnoreCase (T("file:"))
  193180. || URL::isProbablyAnEmailAddress (fileName))
  193181. {
  193182. // create a command that tries to launch a bunch of likely browsers
  193183. const char* const browserNames[] = { "xdg-open", "/etc/alternatives/x-www-browser", "firefox", "mozilla", "konqueror", "opera" };
  193184. StringArray cmdLines;
  193185. for (int i = 0; i < numElementsInArray (browserNames); ++i)
  193186. cmdLines.add (String (browserNames[i]) + " " + cmdString.trim().quoted());
  193187. cmdString = cmdLines.joinIntoString (" || ");
  193188. }
  193189. const char* const argv[4] = { "/bin/sh", "-c", cmdString.toUTF8(), 0 };
  193190. const int cpid = fork();
  193191. if (cpid == 0)
  193192. {
  193193. setsid();
  193194. // Child process
  193195. execve (argv[0], (char**) argv, environ);
  193196. exit (0);
  193197. }
  193198. return cpid >= 0;
  193199. }
  193200. void File::revealToUser() const
  193201. {
  193202. if (isDirectory())
  193203. startAsProcess();
  193204. else if (getParentDirectory().exists())
  193205. getParentDirectory().startAsProcess();
  193206. }
  193207. #endif
  193208. /*** End of inlined file: juce_linux_Files.cpp ***/
  193209. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  193210. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  193211. // compiled on its own).
  193212. #if JUCE_INCLUDED_FILE
  193213. struct NamedPipeInternal
  193214. {
  193215. String pipeInName, pipeOutName;
  193216. int pipeIn, pipeOut;
  193217. bool volatile createdPipe, blocked, stopReadOperation;
  193218. static void signalHandler (int) {}
  193219. };
  193220. void NamedPipe::cancelPendingReads()
  193221. {
  193222. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  193223. {
  193224. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193225. intern->stopReadOperation = true;
  193226. char buffer [1] = { 0 };
  193227. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  193228. (void) bytesWritten;
  193229. int timeout = 2000;
  193230. while (intern->blocked && --timeout >= 0)
  193231. Thread::sleep (2);
  193232. intern->stopReadOperation = false;
  193233. }
  193234. }
  193235. void NamedPipe::close()
  193236. {
  193237. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193238. if (intern != 0)
  193239. {
  193240. internal = 0;
  193241. if (intern->pipeIn != -1)
  193242. ::close (intern->pipeIn);
  193243. if (intern->pipeOut != -1)
  193244. ::close (intern->pipeOut);
  193245. if (intern->createdPipe)
  193246. {
  193247. unlink (intern->pipeInName.toUTF8());
  193248. unlink (intern->pipeOutName.toUTF8());
  193249. }
  193250. delete intern;
  193251. }
  193252. }
  193253. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  193254. {
  193255. close();
  193256. NamedPipeInternal* const intern = new NamedPipeInternal();
  193257. internal = intern;
  193258. intern->createdPipe = createPipe;
  193259. intern->blocked = false;
  193260. intern->stopReadOperation = false;
  193261. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  193262. siginterrupt (SIGPIPE, 1);
  193263. const String pipePath ("/tmp/" + File::createLegalFileName (pipeName));
  193264. intern->pipeInName = pipePath + "_in";
  193265. intern->pipeOutName = pipePath + "_out";
  193266. intern->pipeIn = -1;
  193267. intern->pipeOut = -1;
  193268. if (createPipe)
  193269. {
  193270. if ((mkfifo (intern->pipeInName.toUTF8(), 0666) && errno != EEXIST)
  193271. || (mkfifo (intern->pipeOutName.toUTF8(), 0666) && errno != EEXIST))
  193272. {
  193273. delete intern;
  193274. internal = 0;
  193275. return false;
  193276. }
  193277. }
  193278. return true;
  193279. }
  193280. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  193281. {
  193282. int bytesRead = -1;
  193283. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193284. if (intern != 0)
  193285. {
  193286. intern->blocked = true;
  193287. if (intern->pipeIn == -1)
  193288. {
  193289. if (intern->createdPipe)
  193290. intern->pipeIn = ::open (intern->pipeInName.toUTF8(), O_RDWR);
  193291. else
  193292. intern->pipeIn = ::open (intern->pipeOutName.toUTF8(), O_RDWR);
  193293. if (intern->pipeIn == -1)
  193294. {
  193295. intern->blocked = false;
  193296. return -1;
  193297. }
  193298. }
  193299. bytesRead = 0;
  193300. char* p = (char*) destBuffer;
  193301. while (bytesRead < maxBytesToRead)
  193302. {
  193303. const int bytesThisTime = maxBytesToRead - bytesRead;
  193304. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  193305. if (numRead <= 0 || intern->stopReadOperation)
  193306. {
  193307. bytesRead = -1;
  193308. break;
  193309. }
  193310. bytesRead += numRead;
  193311. p += bytesRead;
  193312. }
  193313. intern->blocked = false;
  193314. }
  193315. return bytesRead;
  193316. }
  193317. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  193318. {
  193319. int bytesWritten = -1;
  193320. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193321. if (intern != 0)
  193322. {
  193323. if (intern->pipeOut == -1)
  193324. {
  193325. if (intern->createdPipe)
  193326. intern->pipeOut = ::open (intern->pipeOutName.toUTF8(), O_WRONLY);
  193327. else
  193328. intern->pipeOut = ::open (intern->pipeInName.toUTF8(), O_WRONLY);
  193329. if (intern->pipeOut == -1)
  193330. {
  193331. return -1;
  193332. }
  193333. }
  193334. const char* p = (const char*) sourceBuffer;
  193335. bytesWritten = 0;
  193336. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  193337. while (bytesWritten < numBytesToWrite
  193338. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  193339. {
  193340. const int bytesThisTime = numBytesToWrite - bytesWritten;
  193341. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  193342. if (numWritten <= 0)
  193343. {
  193344. bytesWritten = -1;
  193345. break;
  193346. }
  193347. bytesWritten += numWritten;
  193348. p += bytesWritten;
  193349. }
  193350. }
  193351. return bytesWritten;
  193352. }
  193353. #endif
  193354. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  193355. /*** Start of inlined file: juce_linux_Network.cpp ***/
  193356. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193357. // compiled on its own).
  193358. #if JUCE_INCLUDED_FILE
  193359. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
  193360. {
  193361. int numResults = 0;
  193362. const int s = socket (AF_INET, SOCK_DGRAM, 0);
  193363. if (s != -1)
  193364. {
  193365. char buf [1024];
  193366. struct ifconf ifc;
  193367. ifc.ifc_len = sizeof (buf);
  193368. ifc.ifc_buf = buf;
  193369. ioctl (s, SIOCGIFCONF, &ifc);
  193370. for (unsigned int i = 0; i < ifc.ifc_len / sizeof (struct ifreq); ++i)
  193371. {
  193372. struct ifreq ifr;
  193373. strcpy (ifr.ifr_name, ifc.ifc_req[i].ifr_name);
  193374. if (ioctl (s, SIOCGIFFLAGS, &ifr) == 0
  193375. && (ifr.ifr_flags & IFF_LOOPBACK) == 0
  193376. && ioctl (s, SIOCGIFHWADDR, &ifr) == 0
  193377. && numResults < maxNum)
  193378. {
  193379. int64 a = 0;
  193380. for (int j = 6; --j >= 0;)
  193381. a = (a << 8) | (uint8) ifr.ifr_hwaddr.sa_data [littleEndian ? j : (5 - j)];
  193382. *addresses++ = a;
  193383. ++numResults;
  193384. }
  193385. }
  193386. close (s);
  193387. }
  193388. return numResults;
  193389. }
  193390. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  193391. const String& emailSubject,
  193392. const String& bodyText,
  193393. const StringArray& filesToAttach)
  193394. {
  193395. jassertfalse // xxx todo
  193396. return false;
  193397. }
  193398. class JUCE_HTTPSocketStream
  193399. {
  193400. public:
  193401. JUCE_HTTPSocketStream()
  193402. : readPosition (0),
  193403. socketHandle (-1),
  193404. levelsOfRedirection (0),
  193405. timeoutSeconds (15)
  193406. {
  193407. }
  193408. ~JUCE_HTTPSocketStream()
  193409. {
  193410. closeSocket();
  193411. }
  193412. bool open (const String& url,
  193413. const String& headers,
  193414. const MemoryBlock& postData,
  193415. const bool isPost,
  193416. URL::OpenStreamProgressCallback* callback,
  193417. void* callbackContext,
  193418. int timeOutMs)
  193419. {
  193420. closeSocket();
  193421. uint32 timeOutTime = Time::getMillisecondCounter();
  193422. if (timeOutMs == 0)
  193423. timeOutTime += 60000;
  193424. else if (timeOutMs < 0)
  193425. timeOutTime = 0xffffffff;
  193426. else
  193427. timeOutTime += timeOutMs;
  193428. String hostName, hostPath;
  193429. int hostPort;
  193430. if (! decomposeURL (url, hostName, hostPath, hostPort))
  193431. return false;
  193432. const struct hostent* host = 0;
  193433. int port = 0;
  193434. String proxyName, proxyPath;
  193435. int proxyPort = 0;
  193436. String proxyURL (getenv ("http_proxy"));
  193437. if (proxyURL.startsWithIgnoreCase (T("http://")))
  193438. {
  193439. if (! decomposeURL (proxyURL, proxyName, proxyPath, proxyPort))
  193440. return false;
  193441. host = gethostbyname (proxyName.toUTF8());
  193442. port = proxyPort;
  193443. }
  193444. else
  193445. {
  193446. host = gethostbyname (hostName.toUTF8());
  193447. port = hostPort;
  193448. }
  193449. if (host == 0)
  193450. return false;
  193451. struct sockaddr_in address;
  193452. zerostruct (address);
  193453. memcpy ((void*) &address.sin_addr, (const void*) host->h_addr, host->h_length);
  193454. address.sin_family = host->h_addrtype;
  193455. address.sin_port = htons (port);
  193456. socketHandle = socket (host->h_addrtype, SOCK_STREAM, 0);
  193457. if (socketHandle == -1)
  193458. return false;
  193459. int receiveBufferSize = 16384;
  193460. setsockopt (socketHandle, SOL_SOCKET, SO_RCVBUF, (char*) &receiveBufferSize, sizeof (receiveBufferSize));
  193461. setsockopt (socketHandle, SOL_SOCKET, SO_KEEPALIVE, 0, 0);
  193462. #if JUCE_MAC
  193463. setsockopt (socketHandle, SOL_SOCKET, SO_NOSIGPIPE, 0, 0);
  193464. #endif
  193465. if (connect (socketHandle, (struct sockaddr*) &address, sizeof (address)) == -1)
  193466. {
  193467. closeSocket();
  193468. return false;
  193469. }
  193470. const MemoryBlock requestHeader (createRequestHeader (hostName, hostPort,
  193471. proxyName, proxyPort,
  193472. hostPath, url,
  193473. headers, postData,
  193474. isPost));
  193475. size_t totalHeaderSent = 0;
  193476. while (totalHeaderSent < requestHeader.getSize())
  193477. {
  193478. if (Time::getMillisecondCounter() > timeOutTime)
  193479. {
  193480. closeSocket();
  193481. return false;
  193482. }
  193483. const int numToSend = jmin (1024, (int) (requestHeader.getSize() - totalHeaderSent));
  193484. if (send (socketHandle,
  193485. ((const char*) requestHeader.getData()) + totalHeaderSent,
  193486. numToSend, 0)
  193487. != numToSend)
  193488. {
  193489. closeSocket();
  193490. return false;
  193491. }
  193492. totalHeaderSent += numToSend;
  193493. if (callback != 0 && ! callback (callbackContext, totalHeaderSent, requestHeader.getSize()))
  193494. {
  193495. closeSocket();
  193496. return false;
  193497. }
  193498. }
  193499. const String responseHeader (readResponse (timeOutTime));
  193500. if (responseHeader.isNotEmpty())
  193501. {
  193502. //DBG (responseHeader);
  193503. StringArray lines;
  193504. lines.addLines (responseHeader);
  193505. // NB - using charToString() here instead of just T(" "), because that was
  193506. // causing a mysterious gcc internal compiler error...
  193507. const int statusCode = responseHeader.fromFirstOccurrenceOf (String::charToString (' '), false, false)
  193508. .substring (0, 3).getIntValue();
  193509. //int contentLength = findHeaderItem (lines, T("Content-Length:")).getIntValue();
  193510. //bool isChunked = findHeaderItem (lines, T("Transfer-Encoding:")).equalsIgnoreCase ("chunked");
  193511. String location (findHeaderItem (lines, "Location:"));
  193512. if (statusCode >= 300 && statusCode < 400
  193513. && location.isNotEmpty())
  193514. {
  193515. if (! location.startsWithIgnoreCase (T("http://")))
  193516. location = "http://" + location;
  193517. if (levelsOfRedirection++ < 3)
  193518. return open (location, headers, postData, isPost, callback, callbackContext, timeOutMs);
  193519. }
  193520. else
  193521. {
  193522. levelsOfRedirection = 0;
  193523. return true;
  193524. }
  193525. }
  193526. closeSocket();
  193527. return false;
  193528. }
  193529. int read (void* buffer, int bytesToRead)
  193530. {
  193531. fd_set readbits;
  193532. FD_ZERO (&readbits);
  193533. FD_SET (socketHandle, &readbits);
  193534. struct timeval tv;
  193535. tv.tv_sec = timeoutSeconds;
  193536. tv.tv_usec = 0;
  193537. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  193538. return 0; // (timeout)
  193539. const int bytesRead = jmax (0, (int) recv (socketHandle, buffer, bytesToRead, MSG_WAITALL));
  193540. readPosition += bytesRead;
  193541. return bytesRead;
  193542. }
  193543. int readPosition;
  193544. juce_UseDebuggingNewOperator
  193545. private:
  193546. int socketHandle, levelsOfRedirection;
  193547. const int timeoutSeconds;
  193548. void closeSocket()
  193549. {
  193550. if (socketHandle >= 0)
  193551. close (socketHandle);
  193552. socketHandle = -1;
  193553. }
  193554. const MemoryBlock createRequestHeader (const String& hostName,
  193555. const int hostPort,
  193556. const String& proxyName,
  193557. const int proxyPort,
  193558. const String& hostPath,
  193559. const String& originalURL,
  193560. const String& headers,
  193561. const MemoryBlock& postData,
  193562. const bool isPost)
  193563. {
  193564. String header (isPost ? "POST " : "GET ");
  193565. if (proxyName.isEmpty())
  193566. {
  193567. header << hostPath << " HTTP/1.0\r\nHost: "
  193568. << hostName << ':' << hostPort;
  193569. }
  193570. else
  193571. {
  193572. header << originalURL << " HTTP/1.0\r\nHost: "
  193573. << proxyName << ':' << proxyPort;
  193574. }
  193575. header << "\r\nUser-Agent: JUCE/"
  193576. << JUCE_MAJOR_VERSION << '.' << JUCE_MINOR_VERSION
  193577. << "\r\nConnection: Close\r\nContent-Length: "
  193578. << postData.getSize() << "\r\n"
  193579. << headers << "\r\n";
  193580. MemoryBlock mb;
  193581. mb.append (header.toUTF8(), (int) strlen (header.toUTF8()));
  193582. mb.append (postData.getData(), postData.getSize());
  193583. return mb;
  193584. }
  193585. const String readResponse (const uint32 timeOutTime)
  193586. {
  193587. int bytesRead = 0, numConsecutiveLFs = 0;
  193588. MemoryBlock buffer (1024, true);
  193589. while (numConsecutiveLFs < 2 && bytesRead < 32768
  193590. && Time::getMillisecondCounter() <= timeOutTime)
  193591. {
  193592. fd_set readbits;
  193593. FD_ZERO (&readbits);
  193594. FD_SET (socketHandle, &readbits);
  193595. struct timeval tv;
  193596. tv.tv_sec = timeoutSeconds;
  193597. tv.tv_usec = 0;
  193598. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  193599. return String::empty; // (timeout)
  193600. buffer.ensureSize (bytesRead + 8, true);
  193601. char* const dest = (char*) buffer.getData() + bytesRead;
  193602. if (recv (socketHandle, dest, 1, 0) == -1)
  193603. return String::empty;
  193604. const char lastByte = *dest;
  193605. ++bytesRead;
  193606. if (lastByte == '\n')
  193607. ++numConsecutiveLFs;
  193608. else if (lastByte != '\r')
  193609. numConsecutiveLFs = 0;
  193610. }
  193611. const String header (String::fromUTF8 ((const char*) buffer.getData()));
  193612. if (header.startsWithIgnoreCase (T("HTTP/")))
  193613. return header.trimEnd();
  193614. return String::empty;
  193615. }
  193616. static bool decomposeURL (const String& url,
  193617. String& host, String& path, int& port)
  193618. {
  193619. if (! url.startsWithIgnoreCase (T("http://")))
  193620. return false;
  193621. const int nextSlash = url.indexOfChar (7, '/');
  193622. int nextColon = url.indexOfChar (7, ':');
  193623. if (nextColon > nextSlash && nextSlash > 0)
  193624. nextColon = -1;
  193625. if (nextColon >= 0)
  193626. {
  193627. host = url.substring (7, nextColon);
  193628. if (nextSlash >= 0)
  193629. port = url.substring (nextColon + 1, nextSlash).getIntValue();
  193630. else
  193631. port = url.substring (nextColon + 1).getIntValue();
  193632. }
  193633. else
  193634. {
  193635. port = 80;
  193636. if (nextSlash >= 0)
  193637. host = url.substring (7, nextSlash);
  193638. else
  193639. host = url.substring (7);
  193640. }
  193641. if (nextSlash >= 0)
  193642. path = url.substring (nextSlash);
  193643. else
  193644. path = "/";
  193645. return true;
  193646. }
  193647. static const String findHeaderItem (const StringArray& lines, const String& itemName)
  193648. {
  193649. for (int i = 0; i < lines.size(); ++i)
  193650. if (lines[i].startsWithIgnoreCase (itemName))
  193651. return lines[i].substring (itemName.length()).trim();
  193652. return String::empty;
  193653. }
  193654. };
  193655. bool juce_isOnLine()
  193656. {
  193657. return true;
  193658. }
  193659. void* juce_openInternetFile (const String& url,
  193660. const String& headers,
  193661. const MemoryBlock& postData,
  193662. const bool isPost,
  193663. URL::OpenStreamProgressCallback* callback,
  193664. void* callbackContext,
  193665. int timeOutMs)
  193666. {
  193667. JUCE_HTTPSocketStream* const s = new JUCE_HTTPSocketStream();
  193668. if (s->open (url, headers, postData, isPost,
  193669. callback, callbackContext, timeOutMs))
  193670. return s;
  193671. delete s;
  193672. return 0;
  193673. }
  193674. void juce_closeInternetFile (void* handle)
  193675. {
  193676. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193677. if (s != 0)
  193678. delete s;
  193679. }
  193680. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  193681. {
  193682. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193683. if (s != 0)
  193684. return s->read (buffer, bytesToRead);
  193685. return 0;
  193686. }
  193687. int64 juce_getInternetFileContentLength (void* handle)
  193688. {
  193689. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193690. if (s != 0)
  193691. {
  193692. //xxx todo
  193693. jassertfalse
  193694. }
  193695. return -1;
  193696. }
  193697. int juce_seekInInternetFile (void* handle, int newPosition)
  193698. {
  193699. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193700. if (s != 0)
  193701. return s->readPosition;
  193702. return 0;
  193703. }
  193704. #endif
  193705. /*** End of inlined file: juce_linux_Network.cpp ***/
  193706. /*** Start of inlined file: juce_linux_SystemStats.cpp ***/
  193707. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193708. // compiled on its own).
  193709. #if JUCE_INCLUDED_FILE
  193710. void Logger::outputDebugString (const String& text) throw()
  193711. {
  193712. std::cerr << text << std::endl;
  193713. }
  193714. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  193715. {
  193716. return Linux;
  193717. }
  193718. const String SystemStats::getOperatingSystemName() throw()
  193719. {
  193720. return "Linux";
  193721. }
  193722. bool SystemStats::isOperatingSystem64Bit() throw()
  193723. {
  193724. #if JUCE_64BIT
  193725. return true;
  193726. #else
  193727. //xxx not sure how to find this out?..
  193728. return false;
  193729. #endif
  193730. }
  193731. static const String getCpuInfo (const char* key, bool lastOne = false) throw()
  193732. {
  193733. String info;
  193734. char buf [256];
  193735. FILE* f = fopen ("/proc/cpuinfo", "r");
  193736. while (f != 0 && fgets (buf, sizeof(buf), f))
  193737. {
  193738. if (strncmp (buf, key, strlen (key)) == 0)
  193739. {
  193740. char* p = buf;
  193741. while (*p && *p != '\n')
  193742. ++p;
  193743. if (*p != 0)
  193744. *p = 0;
  193745. p = buf;
  193746. while (*p != 0 && *p != ':')
  193747. ++p;
  193748. if (*p != 0 && *(p + 1) != 0)
  193749. info = p + 2;
  193750. if (! lastOne)
  193751. break;
  193752. }
  193753. }
  193754. fclose (f);
  193755. return info;
  193756. }
  193757. bool SystemStats::hasMMX() throw()
  193758. {
  193759. return getCpuInfo ("flags").contains (T("mmx"));
  193760. }
  193761. bool SystemStats::hasSSE() throw()
  193762. {
  193763. return getCpuInfo ("flags").contains (T("sse"));
  193764. }
  193765. bool SystemStats::hasSSE2() throw()
  193766. {
  193767. return getCpuInfo ("flags").contains (T("sse2"));
  193768. }
  193769. bool SystemStats::has3DNow() throw()
  193770. {
  193771. return getCpuInfo ("flags").contains (T("3dnow"));
  193772. }
  193773. const String SystemStats::getCpuVendor() throw()
  193774. {
  193775. return getCpuInfo ("vendor_id");
  193776. }
  193777. int SystemStats::getCpuSpeedInMegaherz() throw()
  193778. {
  193779. const String speed (getCpuInfo ("cpu MHz"));
  193780. return (int) (speed.getFloatValue() + 0.5f);
  193781. }
  193782. int SystemStats::getMemorySizeInMegabytes() throw()
  193783. {
  193784. struct sysinfo sysi;
  193785. if (sysinfo (&sysi) == 0)
  193786. return (sysi.totalram * sysi.mem_unit / (1024 * 1024));
  193787. return 0;
  193788. }
  193789. uint32 juce_millisecondsSinceStartup() throw()
  193790. {
  193791. static unsigned int calibrate = 0;
  193792. static bool calibrated = false;
  193793. timeval t;
  193794. unsigned int ret = 0;
  193795. if (! gettimeofday (&t, 0))
  193796. {
  193797. if (! calibrated)
  193798. {
  193799. struct sysinfo sysi;
  193800. if (sysinfo (&sysi) == 0)
  193801. // Safe to assume system was not brought up earlier than 1970!
  193802. calibrate = t.tv_sec - sysi.uptime;
  193803. calibrated = true;
  193804. }
  193805. ret = 1000 * (t.tv_sec - calibrate) + (t.tv_usec / 1000);
  193806. }
  193807. return ret;
  193808. }
  193809. double Time::getMillisecondCounterHiRes() throw()
  193810. {
  193811. return getHighResolutionTicks() * 0.001;
  193812. }
  193813. int64 Time::getHighResolutionTicks() throw()
  193814. {
  193815. timeval t;
  193816. if (gettimeofday (&t, 0))
  193817. return 0;
  193818. return ((int64) t.tv_sec * (int64) 1000000) + (int64) t.tv_usec;
  193819. }
  193820. int64 Time::getHighResolutionTicksPerSecond() throw()
  193821. {
  193822. // Microseconds
  193823. return 1000000;
  193824. }
  193825. bool Time::setSystemTimeToThisTime() const throw()
  193826. {
  193827. timeval t;
  193828. t.tv_sec = millisSinceEpoch % 1000000;
  193829. t.tv_usec = millisSinceEpoch - t.tv_sec;
  193830. return settimeofday (&t, NULL) ? false : true;
  193831. }
  193832. int SystemStats::getPageSize() throw()
  193833. {
  193834. static int systemPageSize = 0;
  193835. if (systemPageSize == 0)
  193836. systemPageSize = sysconf (_SC_PAGESIZE);
  193837. return systemPageSize;
  193838. }
  193839. int SystemStats::getNumCpus() throw()
  193840. {
  193841. const int lastCpu = getCpuInfo ("processor", true).getIntValue();
  193842. return lastCpu + 1;
  193843. }
  193844. const String SystemStats::getLogonName()
  193845. {
  193846. const char* user = getenv ("USER");
  193847. if (user == 0)
  193848. {
  193849. struct passwd* const pw = getpwuid (getuid());
  193850. if (pw != 0)
  193851. user = pw->pw_name;
  193852. }
  193853. return String::fromUTF8 (user);
  193854. }
  193855. const String SystemStats::getFullUserName()
  193856. {
  193857. return getLogonName();
  193858. }
  193859. void SystemStats::initialiseStats() throw()
  193860. {
  193861. // Process starts off as root when running suid
  193862. Process::lowerPrivilege();
  193863. String s (SystemStats::getJUCEVersion());
  193864. }
  193865. void PlatformUtilities::fpuReset()
  193866. {
  193867. }
  193868. #endif
  193869. /*** End of inlined file: juce_linux_SystemStats.cpp ***/
  193870. /*** Start of inlined file: juce_linux_Threads.cpp ***/
  193871. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193872. // compiled on its own).
  193873. #if JUCE_INCLUDED_FILE
  193874. void JUCE_API juce_threadEntryPoint (void*);
  193875. void* threadEntryProc (void* value)
  193876. {
  193877. // New threads start off as root when running suid
  193878. Process::lowerPrivilege();
  193879. juce_threadEntryPoint (value);
  193880. return 0;
  193881. }
  193882. void* juce_createThread (void* userData)
  193883. {
  193884. pthread_t handle = 0;
  193885. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  193886. {
  193887. pthread_detach (handle);
  193888. return (void*)handle;
  193889. }
  193890. return 0;
  193891. }
  193892. void juce_killThread (void* handle)
  193893. {
  193894. if (handle != 0)
  193895. pthread_cancel ((pthread_t)handle);
  193896. }
  193897. void juce_setCurrentThreadName (const String& /*name*/)
  193898. {
  193899. }
  193900. Thread::ThreadID Thread::getCurrentThreadId()
  193901. {
  193902. return (ThreadID) pthread_self();
  193903. }
  193904. // priority 1 to 10 where 5=normal, 1=low. If the handle is 0, sets the
  193905. // priority of the current thread
  193906. bool juce_setThreadPriority (void* handle, int priority)
  193907. {
  193908. struct sched_param param;
  193909. int policy, maxp, minp, pri;
  193910. if (handle == 0)
  193911. handle = (void*) pthread_self();
  193912. if (pthread_getschedparam ((pthread_t) handle, &policy, &param) == 0
  193913. && policy != SCHED_OTHER)
  193914. {
  193915. minp = sched_get_priority_min(policy);
  193916. maxp = sched_get_priority_max(policy);
  193917. pri = ((maxp - minp) / 2) * (priority - 1) / 9;
  193918. if (param.__sched_priority >= (minp + (maxp - minp) / 2))
  193919. // Realtime process priority
  193920. param.__sched_priority = minp + ((maxp - minp) / 2) + pri;
  193921. else
  193922. // High process priority
  193923. param.__sched_priority = minp + pri;
  193924. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  193925. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  193926. }
  193927. return false;
  193928. }
  193929. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  193930. {
  193931. #if SUPPORT_AFFINITIES
  193932. cpu_set_t affinity;
  193933. CPU_ZERO (&affinity);
  193934. for (int i = 0; i < 32; ++i)
  193935. if ((affinityMask & (1 << i)) != 0)
  193936. CPU_SET (i, &affinity);
  193937. sched_setaffinity (getpid(), sizeof (cpu_set_t), &affinity);
  193938. sched_yield();
  193939. #else
  193940. /* affinities aren't supported because either the appropriate header files weren't found,
  193941. or the SUPPORT_AFFINITIES macro was turned off in linuxheaders.h
  193942. */
  193943. jassertfalse
  193944. #endif
  193945. }
  193946. void Thread::yield()
  193947. {
  193948. sched_yield();
  193949. }
  193950. // sets the process to 0=low priority, 1=normal, 2=high, 3=realtime
  193951. void Process::setPriority (ProcessPriority prior)
  193952. {
  193953. struct sched_param param;
  193954. int policy, maxp, minp;
  193955. const int p = (int) prior;
  193956. if (p <= 1)
  193957. policy = SCHED_OTHER;
  193958. else
  193959. policy = SCHED_RR;
  193960. minp = sched_get_priority_min (policy);
  193961. maxp = sched_get_priority_max (policy);
  193962. if (p < 2)
  193963. param.__sched_priority = 0;
  193964. else if (p == 2 )
  193965. // Set to middle of lower realtime priority range
  193966. param.__sched_priority = minp + (maxp - minp) / 4;
  193967. else
  193968. // Set to middle of higher realtime priority range
  193969. param.__sched_priority = minp + (3 * (maxp - minp) / 4);
  193970. pthread_setschedparam (pthread_self(), policy, &param);
  193971. }
  193972. void Process::terminate()
  193973. {
  193974. exit (0);
  193975. }
  193976. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  193977. {
  193978. static char testResult = 0;
  193979. if (testResult == 0)
  193980. {
  193981. testResult = (char) ptrace (PT_TRACE_ME, 0, 0, 0);
  193982. if (testResult >= 0)
  193983. {
  193984. ptrace (PT_DETACH, 0, (caddr_t) 1, 0);
  193985. testResult = 1;
  193986. }
  193987. }
  193988. return testResult < 0;
  193989. }
  193990. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  193991. {
  193992. return juce_isRunningUnderDebugger();
  193993. }
  193994. void Process::raisePrivilege()
  193995. {
  193996. // If running suid root, change effective user
  193997. // to root
  193998. if (geteuid() != 0 && getuid() == 0)
  193999. {
  194000. setreuid (geteuid(), getuid());
  194001. setregid (getegid(), getgid());
  194002. }
  194003. }
  194004. void Process::lowerPrivilege()
  194005. {
  194006. // If runing suid root, change effective user
  194007. // back to real user
  194008. if (geteuid() == 0 && getuid() != 0)
  194009. {
  194010. setreuid (geteuid(), getuid());
  194011. setregid (getegid(), getgid());
  194012. }
  194013. }
  194014. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  194015. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  194016. {
  194017. return dlopen (name.toUTF8(), RTLD_LOCAL | RTLD_NOW);
  194018. }
  194019. void PlatformUtilities::freeDynamicLibrary (void* handle)
  194020. {
  194021. dlclose(handle);
  194022. }
  194023. void* PlatformUtilities::getProcedureEntryPoint (void* libraryHandle, const String& procedureName)
  194024. {
  194025. return dlsym (libraryHandle, procedureName.toCString());
  194026. }
  194027. #endif
  194028. #endif
  194029. /*** End of inlined file: juce_linux_Threads.cpp ***/
  194030. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  194031. /*** Start of inlined file: juce_linux_Clipboard.cpp ***/
  194032. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194033. // compiled on its own).
  194034. #if JUCE_INCLUDED_FILE
  194035. #ifdef JUCE_DEBUG
  194036. #define JUCE_DEBUG_XERRORS 1
  194037. #endif
  194038. extern Display* display;
  194039. extern Window juce_messageWindowHandle;
  194040. static String localClipboardContent;
  194041. static Atom atom_UTF8_STRING;
  194042. static Atom atom_CLIPBOARD;
  194043. static Atom atom_TARGETS;
  194044. static void initSelectionAtoms()
  194045. {
  194046. static bool isInitialised = false;
  194047. if (! isInitialised)
  194048. {
  194049. atom_UTF8_STRING = XInternAtom (display, "UTF8_STRING", False);
  194050. atom_CLIPBOARD = XInternAtom (display, "CLIPBOARD", False);
  194051. atom_TARGETS = XInternAtom (display, "TARGETS", False);
  194052. }
  194053. }
  194054. // Read the content of a window property as either a locale-dependent string or an utf8 string
  194055. // works only for strings shorter than 1000000 bytes
  194056. static String juce_readWindowProperty (Window window, Atom prop,
  194057. Atom fmt, // XA_STRING or UTF8_STRING
  194058. bool deleteAfterReading)
  194059. {
  194060. String returnData;
  194061. char* clipData;
  194062. Atom actualType;
  194063. int actualFormat;
  194064. unsigned long numItems, bytesLeft;
  194065. if (XGetWindowProperty (display, window, prop,
  194066. 0L /* offset */, 1000000 /* length (max) */, False,
  194067. AnyPropertyType /* format */,
  194068. &actualType, &actualFormat, &numItems, &bytesLeft,
  194069. (unsigned char**) &clipData) == Success)
  194070. {
  194071. if (actualType == atom_UTF8_STRING && actualFormat == 8)
  194072. {
  194073. returnData = String::fromUTF8 (clipData, numItems);
  194074. }
  194075. else if (actualType == XA_STRING && actualFormat == 8)
  194076. {
  194077. returnData = String (clipData, numItems);
  194078. }
  194079. if (clipData != 0)
  194080. XFree (clipData);
  194081. jassert (bytesLeft == 0 || numItems == 1000000);
  194082. }
  194083. if (deleteAfterReading)
  194084. XDeleteProperty (display, window, prop);
  194085. return returnData;
  194086. }
  194087. // Send a SelectionRequest to the window owning the selection and waits for its answer (with a timeout) */
  194088. static bool juce_requestSelectionContent (String &selection_content, Atom selection, Atom requested_format)
  194089. {
  194090. Atom property_name = XInternAtom (display, "JUCE_SEL", false);
  194091. // The selection owner will be asked to set the JUCE_SEL property on the
  194092. // juce_messageWindowHandle with the selection content
  194093. XConvertSelection (display, selection, requested_format, property_name,
  194094. juce_messageWindowHandle, CurrentTime);
  194095. int timeoutMs = 200; // will wait at most for 200 ms
  194096. do
  194097. {
  194098. XEvent event;
  194099. if (XCheckTypedWindowEvent (display, juce_messageWindowHandle, SelectionNotify, &event))
  194100. {
  194101. if (event.xselection.property == property_name)
  194102. {
  194103. jassert (event.xselection.requestor == juce_messageWindowHandle);
  194104. selection_content = juce_readWindowProperty (event.xselection.requestor,
  194105. event.xselection.property,
  194106. requested_format, true);
  194107. return true;
  194108. }
  194109. else
  194110. {
  194111. return false; // the format we asked for was denied.. (event.xselection.property == None)
  194112. }
  194113. }
  194114. // not very elegant.. we could do a select() or something like that...
  194115. // however clipboard content requesting is inherently slow on x11, it
  194116. // often takes 50ms or more so...
  194117. Thread::sleep (4);
  194118. timeoutMs -= 4;
  194119. }
  194120. while (timeoutMs > 0);
  194121. DBG("timeout for juce_requestSelectionContent");
  194122. return false;
  194123. }
  194124. // Called from the event loop in juce_linux_Messaging in response to SelectionRequest events
  194125. void juce_handleSelectionRequest (XSelectionRequestEvent &evt)
  194126. {
  194127. initSelectionAtoms();
  194128. // the selection content is sent to the target window as a window property
  194129. XSelectionEvent reply;
  194130. reply.type = SelectionNotify;
  194131. reply.display = evt.display;
  194132. reply.requestor = evt.requestor;
  194133. reply.selection = evt.selection;
  194134. reply.target = evt.target;
  194135. reply.property = None; // == "fail"
  194136. reply.time = evt.time;
  194137. HeapBlock <char> data;
  194138. int propertyFormat = 0, numDataItems = 0;
  194139. if (evt.selection == XA_PRIMARY || evt.selection == atom_CLIPBOARD)
  194140. {
  194141. if (evt.target == XA_STRING)
  194142. {
  194143. // format data according to system locale
  194144. numDataItems = localClipboardContent.getNumBytesAsCString() + 1;
  194145. data.calloc (numDataItems + 1);
  194146. localClipboardContent.copyToCString (data, numDataItems);
  194147. propertyFormat = 8; // bits/item
  194148. }
  194149. else if (evt.target == atom_UTF8_STRING)
  194150. {
  194151. // translate to utf8
  194152. numDataItems = localClipboardContent.getNumBytesAsUTF8() + 1;
  194153. data.calloc (numDataItems + 1);
  194154. localClipboardContent.copyToUTF8 (data, numDataItems);
  194155. propertyFormat = 8; // bits/item
  194156. }
  194157. else if (evt.target == atom_TARGETS)
  194158. {
  194159. // another application wants to know what we are able to send
  194160. numDataItems = 2;
  194161. propertyFormat = 32; // atoms are 32-bit
  194162. data.calloc (numDataItems * 4);
  194163. Atom* atoms = reinterpret_cast<Atom*> (data.getData());
  194164. atoms[0] = atom_UTF8_STRING;
  194165. atoms[1] = XA_STRING;
  194166. }
  194167. }
  194168. else
  194169. {
  194170. DBG ("requested unsupported clipboard");
  194171. }
  194172. if (data != 0)
  194173. {
  194174. const int maxReasonableSelectionSize = 1000000;
  194175. // for very big chunks of data, we should use the "INCR" protocol , which is a pain in the *ss
  194176. if (evt.property != None && numDataItems < maxReasonableSelectionSize)
  194177. {
  194178. XChangeProperty (evt.display, evt.requestor,
  194179. evt.property, evt.target,
  194180. propertyFormat /* 8 or 32 */, PropModeReplace,
  194181. reinterpret_cast<const unsigned char*> (data.getData()), numDataItems);
  194182. reply.property = evt.property; // " == success"
  194183. }
  194184. }
  194185. XSendEvent (evt.display, evt.requestor, 0, NoEventMask, (XEvent*) &reply);
  194186. }
  194187. void SystemClipboard::copyTextToClipboard (const String& clipText)
  194188. {
  194189. initSelectionAtoms();
  194190. localClipboardContent = clipText;
  194191. XSetSelectionOwner (display, XA_PRIMARY, juce_messageWindowHandle, CurrentTime);
  194192. XSetSelectionOwner (display, atom_CLIPBOARD, juce_messageWindowHandle, CurrentTime);
  194193. }
  194194. const String SystemClipboard::getTextFromClipboard()
  194195. {
  194196. initSelectionAtoms();
  194197. String content;
  194198. Atom selection = XA_PRIMARY;
  194199. Window selectionOwner = None;
  194200. if ((selectionOwner = XGetSelectionOwner (display, selection)) == None)
  194201. {
  194202. selection = atom_CLIPBOARD;
  194203. selectionOwner = XGetSelectionOwner (display, selection);
  194204. }
  194205. if (selectionOwner != None)
  194206. {
  194207. if (selectionOwner == juce_messageWindowHandle)
  194208. {
  194209. content = localClipboardContent;
  194210. }
  194211. else
  194212. {
  194213. // first try: we want an utf8 string
  194214. bool ok = juce_requestSelectionContent (content, selection, atom_UTF8_STRING);
  194215. if (! ok)
  194216. {
  194217. // second chance, ask for a good old locale-dependent string ..
  194218. ok = juce_requestSelectionContent (content, selection, XA_STRING);
  194219. }
  194220. }
  194221. }
  194222. return content;
  194223. }
  194224. #endif
  194225. /*** End of inlined file: juce_linux_Clipboard.cpp ***/
  194226. /*** Start of inlined file: juce_linux_Messaging.cpp ***/
  194227. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194228. // compiled on its own).
  194229. #if JUCE_INCLUDED_FILE
  194230. #ifdef JUCE_DEBUG
  194231. #define JUCE_DEBUG_XERRORS 1
  194232. #endif
  194233. Display* display = 0; // This is also referenced from WindowDriver.cpp
  194234. Window juce_messageWindowHandle = None;
  194235. XContext improbableNumber; // This is referenced from Windowing.cpp
  194236. extern void juce_windowMessageReceive (XEvent* event); // Defined in Windowing.cpp
  194237. extern void juce_handleSelectionRequest (XSelectionRequestEvent &evt); // Defined in Clipboard.cpp
  194238. ScopedXLock::ScopedXLock() { XLockDisplay (display); }
  194239. ScopedXLock::~ScopedXLock() { XUnlockDisplay (display); }
  194240. class InternalMessageQueue
  194241. {
  194242. public:
  194243. InternalMessageQueue()
  194244. : bytesInSocket (0)
  194245. {
  194246. int ret = ::socketpair (AF_LOCAL, SOCK_STREAM, 0, fd);
  194247. (void) ret; jassert (ret == 0);
  194248. //setNonBlocking (fd[0]);
  194249. //setNonBlocking (fd[1]);
  194250. }
  194251. ~InternalMessageQueue()
  194252. {
  194253. close (fd[0]);
  194254. close (fd[1]);
  194255. }
  194256. void postMessage (Message* msg)
  194257. {
  194258. const int maxBytesInSocketQueue = 128;
  194259. ScopedLock sl (lock);
  194260. queue.add (msg);
  194261. if (bytesInSocket < maxBytesInSocketQueue)
  194262. {
  194263. ++bytesInSocket;
  194264. ScopedUnlock ul (lock);
  194265. const unsigned char x = 0xff;
  194266. size_t bytesWritten = write (fd[0], &x, 1);
  194267. (void) bytesWritten;
  194268. }
  194269. }
  194270. bool isEmpty() const
  194271. {
  194272. ScopedLock sl (lock);
  194273. return queue.size() == 0;
  194274. }
  194275. Message* popNextMessage()
  194276. {
  194277. ScopedLock sl (lock);
  194278. if (bytesInSocket > 0)
  194279. {
  194280. --bytesInSocket;
  194281. ScopedUnlock ul (lock);
  194282. unsigned char x;
  194283. size_t numBytes = read (fd[1], &x, 1);
  194284. (void) numBytes;
  194285. }
  194286. Message* m = queue[0];
  194287. queue.remove (0, false /* deleteObject */);
  194288. return m;
  194289. }
  194290. int getWaitHandle() const { return fd[1]; }
  194291. private:
  194292. CriticalSection lock;
  194293. OwnedArray <Message> queue;
  194294. int fd[2];
  194295. int bytesInSocket;
  194296. static bool setNonBlocking (int handle)
  194297. {
  194298. int socketFlags = fcntl (handle, F_GETFL, 0);
  194299. if (socketFlags == -1)
  194300. return false;
  194301. socketFlags |= O_NONBLOCK;
  194302. return fcntl (handle, F_SETFL, socketFlags) == 0;
  194303. }
  194304. };
  194305. struct MessageThreadFuncCall
  194306. {
  194307. enum { uniqueID = 0x73774623 };
  194308. MessageCallbackFunction* func;
  194309. void* parameter;
  194310. void* result;
  194311. CriticalSection lock;
  194312. WaitableEvent event;
  194313. };
  194314. static InternalMessageQueue* juce_internalMessageQueue = 0;
  194315. // error handling in X11
  194316. static bool errorOccurred = false;
  194317. static bool keyboardBreakOccurred = false;
  194318. static XErrorHandler oldErrorHandler = (XErrorHandler) 0;
  194319. static XIOErrorHandler oldIOErrorHandler = (XIOErrorHandler) 0;
  194320. // Usually happens when client-server connection is broken
  194321. static int ioErrorHandler (Display* display)
  194322. {
  194323. DBG ("ERROR: connection to X server broken.. terminating.");
  194324. errorOccurred = true;
  194325. if (JUCEApplication::getInstance() != 0)
  194326. Process::terminate();
  194327. return 0;
  194328. }
  194329. // A protocol error has occurred
  194330. static int errorHandler (Display* display, XErrorEvent* event)
  194331. {
  194332. #ifdef JUCE_DEBUG_XERRORS
  194333. char errorStr[64] = { 0 };
  194334. char requestStr[64] = { 0 };
  194335. XGetErrorText (display, event->error_code, errorStr, 64);
  194336. XGetErrorDatabaseText (display, "XRequest", String (event->request_code).toCString(),
  194337. "Unknown", requestStr, 64);
  194338. DBG ("ERROR: X returned " + String (errorStr) + " for operation " + String (requestStr));
  194339. #endif
  194340. return 0;
  194341. }
  194342. // Breakin from keyboard
  194343. static void signalHandler (int sig)
  194344. {
  194345. if (sig == SIGINT)
  194346. {
  194347. keyboardBreakOccurred = true;
  194348. return;
  194349. }
  194350. static bool reentrant = false;
  194351. if (! reentrant)
  194352. {
  194353. reentrant = true;
  194354. // Illegal instruction
  194355. fflush (stdout);
  194356. Logger::outputDebugString ("ERROR: Program executed illegal instruction.. terminating");
  194357. errorOccurred = true;
  194358. if (JUCEApplication::getInstance() != 0)
  194359. Process::terminate();
  194360. }
  194361. else
  194362. {
  194363. if (JUCEApplication::getInstance() != 0)
  194364. exit(0);
  194365. }
  194366. }
  194367. void MessageManager::doPlatformSpecificInitialisation()
  194368. {
  194369. // Initialise xlib for multiple thread support
  194370. static bool initThreadCalled = false;
  194371. if (! initThreadCalled)
  194372. {
  194373. if (! XInitThreads())
  194374. {
  194375. // This is fatal! Print error and closedown
  194376. Logger::outputDebugString ("Failed to initialise xlib thread support.");
  194377. if (JUCEApplication::getInstance() != 0)
  194378. Process::terminate();
  194379. return;
  194380. }
  194381. initThreadCalled = true;
  194382. }
  194383. // This is called if the client/server connection is broken
  194384. oldIOErrorHandler = XSetIOErrorHandler (ioErrorHandler);
  194385. // This is called if a protocol error occurs
  194386. oldErrorHandler = XSetErrorHandler (errorHandler);
  194387. // Install signal handler for break-in
  194388. struct sigaction saction;
  194389. sigset_t maskSet;
  194390. sigemptyset (&maskSet);
  194391. saction.sa_handler = signalHandler;
  194392. saction.sa_mask = maskSet;
  194393. saction.sa_flags = 0;
  194394. sigaction (SIGINT, &saction, NULL);
  194395. #ifndef _DEBUG
  194396. // Setup signal handlers for various fatal errors
  194397. sigaction (SIGILL, &saction, NULL);
  194398. sigaction (SIGBUS, &saction, NULL);
  194399. sigaction (SIGFPE, &saction, NULL);
  194400. sigaction (SIGSEGV, &saction, NULL);
  194401. sigaction (SIGSYS, &saction, NULL);
  194402. #endif
  194403. // Create the internal message queue
  194404. juce_internalMessageQueue = new InternalMessageQueue();
  194405. // Try to connect to a display
  194406. String displayName (getenv ("DISPLAY"));
  194407. if (displayName.isEmpty())
  194408. displayName = ":0.0";
  194409. display = XOpenDisplay (displayName.toCString());
  194410. if (display == 0)
  194411. {
  194412. // This is not fatal! we can run headless.
  194413. return;
  194414. }
  194415. // Get defaults for various properties
  194416. int screen = DefaultScreen (display);
  194417. Window root = RootWindow (display, screen);
  194418. Visual* visual = DefaultVisual (display, screen);
  194419. // Create a context to store user data associated with Windows we
  194420. // create in WindowDriver
  194421. improbableNumber = XUniqueContext();
  194422. // We're only interested in client messages for this window
  194423. // which are always sent
  194424. XSetWindowAttributes swa;
  194425. swa.event_mask = NoEventMask;
  194426. // Create our message window (this will never be mapped)
  194427. juce_messageWindowHandle = XCreateWindow (display, root,
  194428. 0, 0, 1, 1, 0, 0, InputOnly,
  194429. visual, CWEventMask, &swa);
  194430. }
  194431. void MessageManager::doPlatformSpecificShutdown()
  194432. {
  194433. deleteAndZero (juce_internalMessageQueue);
  194434. if (display != 0 && ! errorOccurred)
  194435. {
  194436. XDestroyWindow (display, juce_messageWindowHandle);
  194437. XCloseDisplay (display);
  194438. // reset pointers
  194439. juce_messageWindowHandle = 0;
  194440. display = 0;
  194441. // Restore original error handlers
  194442. XSetIOErrorHandler (oldIOErrorHandler);
  194443. oldIOErrorHandler = 0;
  194444. XSetErrorHandler (oldErrorHandler);
  194445. oldErrorHandler = 0;
  194446. }
  194447. }
  194448. bool juce_postMessageToSystemQueue (void* message)
  194449. {
  194450. if (errorOccurred)
  194451. return false;
  194452. juce_internalMessageQueue->postMessage ((Message*) message);
  194453. return true;
  194454. }
  194455. void MessageManager::broadcastMessage (const String& value) throw()
  194456. {
  194457. }
  194458. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* func,
  194459. void* parameter)
  194460. {
  194461. if (errorOccurred)
  194462. return 0;
  194463. if (! isThisTheMessageThread())
  194464. {
  194465. MessageThreadFuncCall messageCallContext;
  194466. messageCallContext.func = func;
  194467. messageCallContext.parameter = parameter;
  194468. juce_internalMessageQueue->postMessage (new Message (MessageThreadFuncCall::uniqueID,
  194469. 0, 0, &messageCallContext));
  194470. // Wait for it to complete before continuing
  194471. messageCallContext.event.wait();
  194472. return messageCallContext.result;
  194473. }
  194474. else
  194475. {
  194476. // Just call the function directly
  194477. return func (parameter);
  194478. }
  194479. }
  194480. // Wait for an event (either XEvent, or an internal Message)
  194481. static bool juce_sleepUntilEvent (const int timeoutMs)
  194482. {
  194483. if (! juce_internalMessageQueue->isEmpty())
  194484. return true;
  194485. if (display != 0)
  194486. {
  194487. ScopedXLock xlock;
  194488. if (XPending (display))
  194489. return true;
  194490. }
  194491. struct timeval tv;
  194492. tv.tv_sec = 0;
  194493. tv.tv_usec = timeoutMs * 1000;
  194494. int fd0 = juce_internalMessageQueue->getWaitHandle();
  194495. int fdmax = fd0;
  194496. fd_set readset;
  194497. FD_ZERO (&readset);
  194498. FD_SET (fd0, &readset);
  194499. if (display != 0)
  194500. {
  194501. ScopedXLock xlock;
  194502. int fd1 = XConnectionNumber (display);
  194503. FD_SET (fd1, &readset);
  194504. fdmax = jmax (fd0, fd1);
  194505. }
  194506. const int ret = select (fdmax + 1, &readset, 0, 0, &tv);
  194507. return (ret > 0); // ret <= 0 if error or timeout
  194508. }
  194509. // Handle next XEvent (if any)
  194510. static bool juce_dispatchNextXEvent()
  194511. {
  194512. if (display == 0)
  194513. return false;
  194514. XEvent evt;
  194515. {
  194516. ScopedXLock xlock;
  194517. if (! XPending (display))
  194518. return false;
  194519. XNextEvent (display, &evt);
  194520. }
  194521. if (evt.type == SelectionRequest && evt.xany.window == juce_messageWindowHandle)
  194522. {
  194523. juce_handleSelectionRequest (evt.xselectionrequest);
  194524. }
  194525. else if (evt.xany.window != juce_messageWindowHandle)
  194526. {
  194527. juce_windowMessageReceive (&evt);
  194528. }
  194529. return true;
  194530. }
  194531. // Handle next internal Message (if any)
  194532. static bool juce_dispatchNextInternalMessage()
  194533. {
  194534. ScopedPointer <Message> msg (juce_internalMessageQueue->popNextMessage());
  194535. if (msg == 0)
  194536. return false;
  194537. if (msg->intParameter1 == MessageThreadFuncCall::uniqueID)
  194538. {
  194539. // Handle callback message
  194540. MessageThreadFuncCall* const call = (MessageThreadFuncCall*) msg->pointerParameter;
  194541. call->result = (*(call->func)) (call->parameter);
  194542. call->event.signal();
  194543. }
  194544. else
  194545. {
  194546. // Handle "normal" messages
  194547. MessageManager::getInstance()->deliverMessage (msg.release());
  194548. }
  194549. return true;
  194550. }
  194551. // this function expects that it will NEVER be called simultaneously for two concurrent threads
  194552. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages)
  194553. {
  194554. for (;;)
  194555. {
  194556. if (errorOccurred)
  194557. break;
  194558. if (keyboardBreakOccurred)
  194559. {
  194560. errorOccurred = true;
  194561. if (JUCEApplication::getInstance() != 0)
  194562. Process::terminate();
  194563. break;
  194564. }
  194565. static int totalEventCount = 0;
  194566. ++totalEventCount;
  194567. // The purpose here is to give either priority to XEvents or
  194568. // to internal messages This is necessary to keep a "good"
  194569. // behaviour when the cpu is overloaded
  194570. if (totalEventCount & 1)
  194571. {
  194572. if (juce_dispatchNextXEvent() || juce_dispatchNextInternalMessage())
  194573. return true;
  194574. }
  194575. else
  194576. {
  194577. if (juce_dispatchNextInternalMessage() || juce_dispatchNextXEvent())
  194578. return true;
  194579. }
  194580. if (returnIfNoPendingMessages) // early exit
  194581. break;
  194582. // the timeout is to be on the safe side, but it does not seem to be useful
  194583. juce_sleepUntilEvent (2000);
  194584. }
  194585. return false;
  194586. }
  194587. #endif
  194588. /*** End of inlined file: juce_linux_Messaging.cpp ***/
  194589. /*** Start of inlined file: juce_linux_Fonts.cpp ***/
  194590. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194591. // compiled on its own).
  194592. #if JUCE_INCLUDED_FILE
  194593. class FreeTypeFontFace
  194594. {
  194595. public:
  194596. enum FontStyle
  194597. {
  194598. Plain = 0,
  194599. Bold = 1,
  194600. Italic = 2
  194601. };
  194602. struct FontNameIndex
  194603. {
  194604. String fileName;
  194605. int faceIndex;
  194606. };
  194607. FreeTypeFontFace (const String& familyName)
  194608. : hasSerif (false),
  194609. monospaced (false)
  194610. {
  194611. family = familyName;
  194612. }
  194613. void setFileName (const String& name, const int faceIndex, FontStyle style)
  194614. {
  194615. if (names [(int) style].fileName.isEmpty())
  194616. {
  194617. names [(int) style].fileName = name;
  194618. names [(int) style].faceIndex = faceIndex;
  194619. }
  194620. }
  194621. const String& getFamilyName() const throw() { return family; }
  194622. const String& getFileName (const int style, int& faceIndex) const throw()
  194623. {
  194624. faceIndex = names[style].faceIndex;
  194625. return names[style].fileName;
  194626. }
  194627. void setMonospaced (bool mono) throw() { monospaced = mono; }
  194628. bool getMonospaced() const throw() { return monospaced; }
  194629. void setSerif (const bool serif) throw() { hasSerif = serif; }
  194630. bool getSerif() const throw() { return hasSerif; }
  194631. private:
  194632. String family;
  194633. FontNameIndex names[4];
  194634. bool hasSerif, monospaced;
  194635. };
  194636. class FreeTypeInterface : public DeletedAtShutdown
  194637. {
  194638. public:
  194639. FreeTypeInterface()
  194640. : lastFace (0),
  194641. lastBold (false),
  194642. lastItalic (false)
  194643. {
  194644. if (FT_Init_FreeType (&ftLib) != 0)
  194645. {
  194646. ftLib = 0;
  194647. DBG ("Failed to initialize FreeType");
  194648. }
  194649. StringArray fontDirs;
  194650. fontDirs.addTokens (String::fromUTF8 (getenv ("JUCE_FONT_PATH")), ";,", String::empty);
  194651. fontDirs.removeEmptyStrings (true);
  194652. if (fontDirs.size() == 0)
  194653. {
  194654. XmlDocument fontsConfig (File ("/etc/fonts/fonts.conf"));
  194655. XmlElement* const fontsInfo = fontsConfig.getDocumentElement();
  194656. if (fontsInfo != 0)
  194657. {
  194658. forEachXmlChildElementWithTagName (*fontsInfo, e, "dir")
  194659. {
  194660. fontDirs.add (e->getAllSubText().trim());
  194661. }
  194662. delete fontsInfo;
  194663. }
  194664. }
  194665. if (fontDirs.size() == 0)
  194666. fontDirs.add ("/usr/X11R6/lib/X11/fonts");
  194667. for (int i = 0; i < fontDirs.size(); ++i)
  194668. enumerateFaces (fontDirs[i]);
  194669. }
  194670. ~FreeTypeInterface()
  194671. {
  194672. if (lastFace != 0)
  194673. FT_Done_Face (lastFace);
  194674. if (ftLib != 0)
  194675. FT_Done_FreeType (ftLib);
  194676. clearSingletonInstance();
  194677. }
  194678. FreeTypeFontFace* findOrCreate (const String& familyName, const bool create = false)
  194679. {
  194680. for (int i = 0; i < faces.size(); i++)
  194681. if (faces[i]->getFamilyName() == familyName)
  194682. return faces[i];
  194683. if (! create)
  194684. return NULL;
  194685. FreeTypeFontFace* newFace = new FreeTypeFontFace (familyName);
  194686. faces.add (newFace);
  194687. return newFace;
  194688. }
  194689. // Enumerate all font faces available in a given directory
  194690. void enumerateFaces (const String& path)
  194691. {
  194692. File dirPath (path);
  194693. if (path.isEmpty() || ! dirPath.isDirectory())
  194694. return;
  194695. DirectoryIterator di (dirPath, true);
  194696. while (di.next())
  194697. {
  194698. File possible (di.getFile());
  194699. if (possible.hasFileExtension ("ttf")
  194700. || possible.hasFileExtension ("pfb")
  194701. || possible.hasFileExtension ("pcf"))
  194702. {
  194703. FT_Face face;
  194704. int faceIndex = 0;
  194705. int numFaces = 0;
  194706. do
  194707. {
  194708. if (FT_New_Face (ftLib, possible.getFullPathName().toUTF8(),
  194709. faceIndex, &face) == 0)
  194710. {
  194711. if (faceIndex == 0)
  194712. numFaces = face->num_faces;
  194713. if ((face->face_flags & FT_FACE_FLAG_SCALABLE) != 0)
  194714. {
  194715. FreeTypeFontFace* const newFace = findOrCreate (face->family_name, true);
  194716. int style = (int) FreeTypeFontFace::Plain;
  194717. if ((face->style_flags & FT_STYLE_FLAG_BOLD) != 0)
  194718. style |= (int) FreeTypeFontFace::Bold;
  194719. if ((face->style_flags & FT_STYLE_FLAG_ITALIC) != 0)
  194720. style |= (int) FreeTypeFontFace::Italic;
  194721. newFace->setFileName (possible.getFullPathName(), faceIndex, (FreeTypeFontFace::FontStyle) style);
  194722. newFace->setMonospaced ((face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) != 0);
  194723. // Surely there must be a better way to do this?
  194724. const String name (face->family_name);
  194725. newFace->setSerif (! (name.containsIgnoreCase (T("Sans"))
  194726. || name.containsIgnoreCase (T("Verdana"))
  194727. || name.containsIgnoreCase (T("Arial"))));
  194728. }
  194729. FT_Done_Face (face);
  194730. }
  194731. ++faceIndex;
  194732. }
  194733. while (faceIndex < numFaces);
  194734. }
  194735. }
  194736. }
  194737. // Create a FreeType face object for a given font
  194738. FT_Face createFT_Face (const String& fontName, const bool bold, const bool italic)
  194739. {
  194740. FT_Face face = 0;
  194741. if (fontName == lastFontName && bold == lastBold && italic == lastItalic)
  194742. {
  194743. face = lastFace;
  194744. }
  194745. else
  194746. {
  194747. if (lastFace != 0)
  194748. {
  194749. FT_Done_Face (lastFace);
  194750. lastFace = 0;
  194751. }
  194752. lastFontName = fontName;
  194753. lastBold = bold;
  194754. lastItalic = italic;
  194755. FreeTypeFontFace* const ftFace = findOrCreate (fontName);
  194756. if (ftFace != 0)
  194757. {
  194758. int style = (int) FreeTypeFontFace::Plain;
  194759. if (bold)
  194760. style |= (int) FreeTypeFontFace::Bold;
  194761. if (italic)
  194762. style |= (int) FreeTypeFontFace::Italic;
  194763. int faceIndex;
  194764. String fileName (ftFace->getFileName (style, faceIndex));
  194765. if (fileName.isEmpty())
  194766. {
  194767. style ^= (int) FreeTypeFontFace::Bold;
  194768. fileName = ftFace->getFileName (style, faceIndex);
  194769. if (fileName.isEmpty())
  194770. {
  194771. style ^= (int) FreeTypeFontFace::Bold;
  194772. style ^= (int) FreeTypeFontFace::Italic;
  194773. fileName = ftFace->getFileName (style, faceIndex);
  194774. if (! fileName.length())
  194775. {
  194776. style ^= (int) FreeTypeFontFace::Bold;
  194777. fileName = ftFace->getFileName (style, faceIndex);
  194778. }
  194779. }
  194780. }
  194781. if (! FT_New_Face (ftLib, fileName.toUTF8(), faceIndex, &lastFace))
  194782. {
  194783. face = lastFace;
  194784. // If there isn't a unicode charmap then select the first one.
  194785. if (FT_Select_Charmap (face, ft_encoding_unicode))
  194786. FT_Set_Charmap (face, face->charmaps[0]);
  194787. }
  194788. }
  194789. }
  194790. return face;
  194791. }
  194792. bool addGlyph (FT_Face face, CustomTypeface& dest, uint32 character)
  194793. {
  194794. const unsigned int glyphIndex = FT_Get_Char_Index (face, character);
  194795. const float height = (float) (face->ascender - face->descender);
  194796. const float scaleX = 1.0f / height;
  194797. const float scaleY = -1.0f / height;
  194798. Path destShape;
  194799. if (FT_Load_Glyph (face, glyphIndex, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_TRANSFORM) != 0
  194800. || face->glyph->format != ft_glyph_format_outline)
  194801. {
  194802. return false;
  194803. }
  194804. const FT_Outline* const outline = &face->glyph->outline;
  194805. const short* const contours = outline->contours;
  194806. const char* const tags = outline->tags;
  194807. FT_Vector* const points = outline->points;
  194808. for (int c = 0; c < outline->n_contours; c++)
  194809. {
  194810. const int startPoint = (c == 0) ? 0 : contours [c - 1] + 1;
  194811. const int endPoint = contours[c];
  194812. for (int p = startPoint; p <= endPoint; p++)
  194813. {
  194814. const float x = scaleX * points[p].x;
  194815. const float y = scaleY * points[p].y;
  194816. if (p == startPoint)
  194817. {
  194818. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  194819. {
  194820. float x2 = scaleX * points [endPoint].x;
  194821. float y2 = scaleY * points [endPoint].y;
  194822. if (FT_CURVE_TAG (tags[endPoint]) != FT_Curve_Tag_On)
  194823. {
  194824. x2 = (x + x2) * 0.5f;
  194825. y2 = (y + y2) * 0.5f;
  194826. }
  194827. destShape.startNewSubPath (x2, y2);
  194828. }
  194829. else
  194830. {
  194831. destShape.startNewSubPath (x, y);
  194832. }
  194833. }
  194834. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_On)
  194835. {
  194836. if (p != startPoint)
  194837. destShape.lineTo (x, y);
  194838. }
  194839. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  194840. {
  194841. const int nextIndex = (p == endPoint) ? startPoint : p + 1;
  194842. float x2 = scaleX * points [nextIndex].x;
  194843. float y2 = scaleY * points [nextIndex].y;
  194844. if (FT_CURVE_TAG (tags [nextIndex]) == FT_Curve_Tag_Conic)
  194845. {
  194846. x2 = (x + x2) * 0.5f;
  194847. y2 = (y + y2) * 0.5f;
  194848. }
  194849. else
  194850. {
  194851. ++p;
  194852. }
  194853. destShape.quadraticTo (x, y, x2, y2);
  194854. }
  194855. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Cubic)
  194856. {
  194857. if (p >= endPoint)
  194858. return false;
  194859. const int next1 = p + 1;
  194860. const int next2 = (p == (endPoint - 1)) ? startPoint : p + 2;
  194861. const float x2 = scaleX * points [next1].x;
  194862. const float y2 = scaleY * points [next1].y;
  194863. const float x3 = scaleX * points [next2].x;
  194864. const float y3 = scaleY * points [next2].y;
  194865. if (FT_CURVE_TAG (tags[next1]) != FT_Curve_Tag_Cubic
  194866. || FT_CURVE_TAG (tags[next2]) != FT_Curve_Tag_On)
  194867. return false;
  194868. destShape.cubicTo (x, y, x2, y2, x3, y3);
  194869. p += 2;
  194870. }
  194871. }
  194872. destShape.closeSubPath();
  194873. }
  194874. dest.addGlyph (character, destShape, face->glyph->metrics.horiAdvance / height);
  194875. if ((face->face_flags & FT_FACE_FLAG_KERNING) != 0)
  194876. addKerning (face, dest, character, glyphIndex);
  194877. return true;
  194878. }
  194879. void addKerning (FT_Face face, CustomTypeface& dest, const uint32 character, const uint32 glyphIndex)
  194880. {
  194881. const float height = (float) (face->ascender - face->descender);
  194882. uint32 rightGlyphIndex;
  194883. uint32 rightCharCode = FT_Get_First_Char (face, &rightGlyphIndex);
  194884. while (rightGlyphIndex != 0)
  194885. {
  194886. FT_Vector kerning;
  194887. if (FT_Get_Kerning (face, glyphIndex, rightGlyphIndex, ft_kerning_unscaled, &kerning) == 0)
  194888. {
  194889. if (kerning.x != 0)
  194890. dest.addKerningPair (character, rightCharCode, kerning.x / height);
  194891. }
  194892. rightCharCode = FT_Get_Next_Char (face, rightCharCode, &rightGlyphIndex);
  194893. }
  194894. }
  194895. // Add a glyph to a font
  194896. bool addGlyphToFont (const uint32 character,
  194897. const tchar* fontName, bool bold, bool italic,
  194898. CustomTypeface& dest)
  194899. {
  194900. FT_Face face = createFT_Face (fontName, bold, italic);
  194901. if (face != 0)
  194902. return addGlyph (face, dest, character);
  194903. return false;
  194904. }
  194905. void getFamilyNames (StringArray& familyNames) const
  194906. {
  194907. for (int i = 0; i < faces.size(); i++)
  194908. familyNames.add (faces[i]->getFamilyName());
  194909. }
  194910. void getMonospacedNames (StringArray& monoSpaced) const
  194911. {
  194912. for (int i = 0; i < faces.size(); i++)
  194913. if (faces[i]->getMonospaced())
  194914. monoSpaced.add (faces[i]->getFamilyName());
  194915. }
  194916. void getSerifNames (StringArray& serif) const
  194917. {
  194918. for (int i = 0; i < faces.size(); i++)
  194919. if (faces[i]->getSerif())
  194920. serif.add (faces[i]->getFamilyName());
  194921. }
  194922. void getSansSerifNames (StringArray& sansSerif) const
  194923. {
  194924. for (int i = 0; i < faces.size(); i++)
  194925. if (! faces[i]->getSerif())
  194926. sansSerif.add (faces[i]->getFamilyName());
  194927. }
  194928. juce_DeclareSingleton_SingleThreaded_Minimal (FreeTypeInterface)
  194929. private:
  194930. FT_Library ftLib;
  194931. FT_Face lastFace;
  194932. String lastFontName;
  194933. bool lastBold, lastItalic;
  194934. OwnedArray<FreeTypeFontFace> faces;
  194935. };
  194936. juce_ImplementSingleton_SingleThreaded (FreeTypeInterface)
  194937. class FreetypeTypeface : public CustomTypeface
  194938. {
  194939. public:
  194940. FreetypeTypeface (const Font& font)
  194941. {
  194942. FT_Face face = FreeTypeInterface::getInstance()
  194943. ->createFT_Face (font.getTypefaceName(), font.isBold(), font.isItalic());
  194944. if (face == 0)
  194945. {
  194946. #ifdef JUCE_DEBUG
  194947. String msg ("Failed to create typeface: ");
  194948. msg << font.getTypefaceName() << " " << (font.isBold() ? 'B' : ' ') << (font.isItalic() ? 'I' : ' ');
  194949. DBG (msg);
  194950. #endif
  194951. }
  194952. else
  194953. {
  194954. setCharacteristics (font.getTypefaceName(),
  194955. face->ascender / (float) (face->ascender - face->descender),
  194956. font.isBold(), font.isItalic(),
  194957. L' ');
  194958. }
  194959. }
  194960. bool loadGlyphIfPossible (juce_wchar character)
  194961. {
  194962. return FreeTypeInterface::getInstance()
  194963. ->addGlyphToFont (character, name, isBold, isItalic, *this);
  194964. }
  194965. };
  194966. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  194967. {
  194968. return new FreetypeTypeface (font);
  194969. }
  194970. const StringArray Font::findAllTypefaceNames()
  194971. {
  194972. StringArray s;
  194973. FreeTypeInterface::getInstance()->getFamilyNames (s);
  194974. s.sort (true);
  194975. return s;
  194976. }
  194977. static const String pickBestFont (const StringArray& names,
  194978. const char* const choicesString)
  194979. {
  194980. StringArray choices;
  194981. choices.addTokens (String (choicesString), ",", String::empty);
  194982. choices.trim();
  194983. choices.removeEmptyStrings();
  194984. int i, j;
  194985. for (j = 0; j < choices.size(); ++j)
  194986. if (names.contains (choices[j], true))
  194987. return choices[j];
  194988. for (j = 0; j < choices.size(); ++j)
  194989. for (i = 0; i < names.size(); i++)
  194990. if (names[i].startsWithIgnoreCase (choices[j]))
  194991. return names[i];
  194992. for (j = 0; j < choices.size(); ++j)
  194993. for (i = 0; i < names.size(); i++)
  194994. if (names[i].containsIgnoreCase (choices[j]))
  194995. return names[i];
  194996. return names[0];
  194997. }
  194998. static const String linux_getDefaultSansSerifFontName()
  194999. {
  195000. StringArray allFonts;
  195001. FreeTypeInterface::getInstance()->getSansSerifNames (allFonts);
  195002. return pickBestFont (allFonts, "Verdana, Bitstream Vera Sans, Luxi Sans, Sans");
  195003. }
  195004. static const String linux_getDefaultSerifFontName()
  195005. {
  195006. StringArray allFonts;
  195007. FreeTypeInterface::getInstance()->getSerifNames (allFonts);
  195008. return pickBestFont (allFonts, "Bitstream Vera Serif, Times, Nimbus Roman, Serif");
  195009. }
  195010. static const String linux_getDefaultMonospacedFontName()
  195011. {
  195012. StringArray allFonts;
  195013. FreeTypeInterface::getInstance()->getMonospacedNames (allFonts);
  195014. return pickBestFont (allFonts, "Bitstream Vera Sans Mono, Courier, Sans Mono, Mono");
  195015. }
  195016. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed)
  195017. {
  195018. defaultSans = linux_getDefaultSansSerifFontName();
  195019. defaultSerif = linux_getDefaultSerifFontName();
  195020. defaultFixed = linux_getDefaultMonospacedFontName();
  195021. }
  195022. #endif
  195023. /*** End of inlined file: juce_linux_Fonts.cpp ***/
  195024. /*** Start of inlined file: juce_linux_Windowing.cpp ***/
  195025. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  195026. // compiled on its own).
  195027. #if JUCE_INCLUDED_FILE
  195028. namespace Atoms
  195029. {
  195030. enum ProtocolItems
  195031. {
  195032. TAKE_FOCUS = 0,
  195033. DELETE_WINDOW = 1
  195034. };
  195035. static Atom Protocols, ProtocolList[2], ChangeState, State,
  195036. ActiveWin, Pid, WindowType, WindowState,
  195037. XdndAware, XdndEnter, XdndLeave, XdndPosition, XdndStatus,
  195038. XdndDrop, XdndFinished, XdndSelection, XdndTypeList, XdndActionList,
  195039. XdndActionDescription, XdndActionCopy,
  195040. allowedActions[5],
  195041. allowedMimeTypes[2];
  195042. const unsigned long DndVersion = 3;
  195043. static void initialiseAtoms()
  195044. {
  195045. static bool atomsInitialised = false;
  195046. if (! atomsInitialised)
  195047. {
  195048. atomsInitialised = true;
  195049. Protocols = XInternAtom (display, "WM_PROTOCOLS", True);
  195050. ProtocolList [TAKE_FOCUS] = XInternAtom (display, "WM_TAKE_FOCUS", True);
  195051. ProtocolList [DELETE_WINDOW] = XInternAtom (display, "WM_DELETE_WINDOW", True);
  195052. ChangeState = XInternAtom (display, "WM_CHANGE_STATE", True);
  195053. State = XInternAtom (display, "WM_STATE", True);
  195054. ActiveWin = XInternAtom (display, "_NET_ACTIVE_WINDOW", False);
  195055. Pid = XInternAtom (display, "_NET_WM_PID", False);
  195056. WindowType = XInternAtom (display, "_NET_WM_WINDOW_TYPE", True);
  195057. WindowState = XInternAtom (display, "_NET_WM_WINDOW_STATE", True);
  195058. XdndAware = XInternAtom (display, "XdndAware", False);
  195059. XdndEnter = XInternAtom (display, "XdndEnter", False);
  195060. XdndLeave = XInternAtom (display, "XdndLeave", False);
  195061. XdndPosition = XInternAtom (display, "XdndPosition", False);
  195062. XdndStatus = XInternAtom (display, "XdndStatus", False);
  195063. XdndDrop = XInternAtom (display, "XdndDrop", False);
  195064. XdndFinished = XInternAtom (display, "XdndFinished", False);
  195065. XdndSelection = XInternAtom (display, "XdndSelection", False);
  195066. XdndTypeList = XInternAtom (display, "XdndTypeList", False);
  195067. XdndActionList = XInternAtom (display, "XdndActionList", False);
  195068. XdndActionCopy = XInternAtom (display, "XdndActionCopy", False);
  195069. XdndActionDescription = XInternAtom (display, "XdndActionDescription", False);
  195070. allowedMimeTypes [0] = XInternAtom (display, "text/plain", False);
  195071. allowedMimeTypes [1] = XInternAtom (display, "text/uri-list", False);
  195072. allowedActions [0] = XInternAtom (display, "XdndActionMove", False);
  195073. allowedActions [1] = XdndActionCopy;
  195074. allowedActions [2] = XInternAtom (display, "XdndActionLink", False);
  195075. allowedActions [3] = XInternAtom (display, "XdndActionAsk", False);
  195076. allowedActions [4] = XInternAtom (display, "XdndActionPrivate", False);
  195077. }
  195078. }
  195079. }
  195080. enum SystemTrayValues
  195081. {
  195082. SYSTEM_TRAY_REQUEST_DOCK = 0,
  195083. SYSTEM_TRAY_BEGIN_MESSAGE = 1,
  195084. SYSTEM_TRAY_CANCEL_MESSAGE = 2
  195085. };
  195086. static XErrorHandler oldHandler = 0;
  195087. static int trappedErrorCode = 0;
  195088. extern "C" int errorTrapHandler (Display* dpy, XErrorEvent* err)
  195089. {
  195090. trappedErrorCode = err->error_code;
  195091. return 0;
  195092. }
  195093. static void trapErrors()
  195094. {
  195095. trappedErrorCode = 0;
  195096. oldHandler = XSetErrorHandler (errorTrapHandler);
  195097. }
  195098. static bool untrapErrors()
  195099. {
  195100. XSetErrorHandler (oldHandler);
  195101. return (trappedErrorCode == 0);
  195102. }
  195103. static bool isActiveApplication = false;
  195104. bool Process::isForegroundProcess()
  195105. {
  195106. return isActiveApplication;
  195107. }
  195108. // These are defined in juce_linux_Messaging.cpp
  195109. extern Display* display;
  195110. extern XContext improbableNumber;
  195111. static const int eventMask = NoEventMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask
  195112. | EnterWindowMask | LeaveWindowMask | PointerMotionMask | KeymapStateMask
  195113. | ExposureMask | StructureNotifyMask | FocusChangeMask;
  195114. namespace Keys
  195115. {
  195116. enum MouseButtons
  195117. {
  195118. NoButton = 0,
  195119. LeftButton = 1,
  195120. MiddleButton = 2,
  195121. RightButton = 3,
  195122. WheelUp = 4,
  195123. WheelDown = 5
  195124. };
  195125. static int AltMask = 0;
  195126. static int NumLockMask = 0;
  195127. static bool numLock = false;
  195128. static bool capsLock = false;
  195129. static char keyStates [32];
  195130. static const int extendedKeyModifier = 0x10000000;
  195131. }
  195132. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  195133. {
  195134. int keysym;
  195135. if (keyCode & Keys::extendedKeyModifier)
  195136. {
  195137. keysym = 0xff00 | (keyCode & 0xff);
  195138. }
  195139. else
  195140. {
  195141. keysym = keyCode;
  195142. if (keysym == (XK_Tab & 0xff)
  195143. || keysym == (XK_Return & 0xff)
  195144. || keysym == (XK_Escape & 0xff)
  195145. || keysym == (XK_BackSpace & 0xff))
  195146. {
  195147. keysym |= 0xff00;
  195148. }
  195149. }
  195150. ScopedXLock xlock;
  195151. const int keycode = XKeysymToKeycode (display, keysym);
  195152. const int keybyte = keycode >> 3;
  195153. const int keybit = (1 << (keycode & 7));
  195154. return (Keys::keyStates [keybyte] & keybit) != 0;
  195155. }
  195156. #if JUCE_USE_XSHM
  195157. static bool isShmAvailable() throw()
  195158. {
  195159. static bool isChecked = false;
  195160. static bool isAvailable = false;
  195161. if (! isChecked)
  195162. {
  195163. isChecked = true;
  195164. int major, minor;
  195165. Bool pixmaps;
  195166. ScopedXLock xlock;
  195167. if (XShmQueryVersion (display, &major, &minor, &pixmaps))
  195168. {
  195169. trapErrors();
  195170. XShmSegmentInfo segmentInfo;
  195171. zerostruct (segmentInfo);
  195172. XImage* xImage = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  195173. 24, ZPixmap, 0, &segmentInfo, 50, 50);
  195174. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195175. xImage->bytes_per_line * xImage->height,
  195176. IPC_CREAT | 0777)) >= 0)
  195177. {
  195178. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195179. if (segmentInfo.shmaddr != (void*) -1)
  195180. {
  195181. segmentInfo.readOnly = False;
  195182. xImage->data = segmentInfo.shmaddr;
  195183. XSync (display, False);
  195184. if (XShmAttach (display, &segmentInfo) != 0)
  195185. {
  195186. XSync (display, False);
  195187. XShmDetach (display, &segmentInfo);
  195188. isAvailable = true;
  195189. }
  195190. }
  195191. XFlush (display);
  195192. XDestroyImage (xImage);
  195193. shmdt (segmentInfo.shmaddr);
  195194. }
  195195. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195196. isAvailable &= untrapErrors();
  195197. }
  195198. }
  195199. return isAvailable;
  195200. }
  195201. #endif
  195202. #if JUCE_USE_XRENDER
  195203. namespace XRender
  195204. {
  195205. typedef Status (*tXRenderQueryVersion) (Display*, int*, int*);
  195206. typedef XRenderPictFormat* (*tXrenderFindStandardFormat) (Display*, int);
  195207. typedef XRenderPictFormat* (*tXRenderFindFormat) (Display*, unsigned long, XRenderPictFormat*, int);
  195208. typedef XRenderPictFormat* (*tXRenderFindVisualFormat) (Display*, Visual*);
  195209. static tXRenderQueryVersion xRenderQueryVersion = 0;
  195210. static tXrenderFindStandardFormat xRenderFindStandardFormat = 0;
  195211. static tXRenderFindFormat xRenderFindFormat = 0;
  195212. static tXRenderFindVisualFormat xRenderFindVisualFormat = 0;
  195213. static bool isAvailable()
  195214. {
  195215. static bool isChecked = false;
  195216. static bool isAvailable = false;
  195217. if (! isChecked)
  195218. {
  195219. ScopedXLock xlock;
  195220. isChecked = true;
  195221. if (xRenderQueryVersion == 0)
  195222. {
  195223. void* h = dlopen ("libXrender.so", RTLD_GLOBAL | RTLD_NOW);
  195224. if (h != 0)
  195225. {
  195226. xRenderQueryVersion = (tXRenderQueryVersion) dlsym (h, "XRenderQueryVersion");
  195227. xRenderFindStandardFormat = (tXrenderFindStandardFormat) dlsym (h, "XrenderFindStandardFormat");
  195228. xRenderFindFormat = (tXRenderFindFormat) dlsym (h, "XRenderFindFormat");
  195229. xRenderFindVisualFormat = (tXRenderFindVisualFormat) dlsym (h, "XRenderFindVisualFormat");
  195230. }
  195231. }
  195232. if (xRenderQueryVersion != 0
  195233. && xRenderFindStandardFormat != 0
  195234. && xRenderFindFormat != 0
  195235. && xRenderFindVisualFormat != 0)
  195236. {
  195237. int major, minor;
  195238. if (xRenderQueryVersion (display, &major, &minor))
  195239. isAvailable = true;
  195240. }
  195241. }
  195242. return isAvailable;
  195243. }
  195244. static XRenderPictFormat* findPictureFormat()
  195245. {
  195246. ScopedXLock xlock;
  195247. XRenderPictFormat* pictFormat = 0;
  195248. if (isAvailable())
  195249. {
  195250. pictFormat = xRenderFindStandardFormat (display, PictStandardARGB32);
  195251. if (pictFormat == 0)
  195252. {
  195253. XRenderPictFormat desiredFormat;
  195254. desiredFormat.type = PictTypeDirect;
  195255. desiredFormat.depth = 32;
  195256. desiredFormat.direct.alphaMask = 0xff;
  195257. desiredFormat.direct.redMask = 0xff;
  195258. desiredFormat.direct.greenMask = 0xff;
  195259. desiredFormat.direct.blueMask = 0xff;
  195260. desiredFormat.direct.alpha = 24;
  195261. desiredFormat.direct.red = 16;
  195262. desiredFormat.direct.green = 8;
  195263. desiredFormat.direct.blue = 0;
  195264. pictFormat = xRenderFindFormat (display,
  195265. PictFormatType | PictFormatDepth
  195266. | PictFormatRedMask | PictFormatRed
  195267. | PictFormatGreenMask | PictFormatGreen
  195268. | PictFormatBlueMask | PictFormatBlue
  195269. | PictFormatAlphaMask | PictFormatAlpha,
  195270. &desiredFormat,
  195271. 0);
  195272. }
  195273. }
  195274. return pictFormat;
  195275. }
  195276. }
  195277. #endif
  195278. namespace Visuals
  195279. {
  195280. static Visual* findVisualWithDepth (const int desiredDepth) throw()
  195281. {
  195282. ScopedXLock xlock;
  195283. Visual* visual = 0;
  195284. int numVisuals = 0;
  195285. long desiredMask = VisualNoMask;
  195286. XVisualInfo desiredVisual;
  195287. desiredVisual.screen = DefaultScreen (display);
  195288. desiredVisual.depth = desiredDepth;
  195289. desiredMask = VisualScreenMask | VisualDepthMask;
  195290. if (desiredDepth == 32)
  195291. {
  195292. desiredVisual.c_class = TrueColor;
  195293. desiredVisual.red_mask = 0x00FF0000;
  195294. desiredVisual.green_mask = 0x0000FF00;
  195295. desiredVisual.blue_mask = 0x000000FF;
  195296. desiredVisual.bits_per_rgb = 8;
  195297. desiredMask |= VisualClassMask;
  195298. desiredMask |= VisualRedMaskMask;
  195299. desiredMask |= VisualGreenMaskMask;
  195300. desiredMask |= VisualBlueMaskMask;
  195301. desiredMask |= VisualBitsPerRGBMask;
  195302. }
  195303. XVisualInfo* xvinfos = XGetVisualInfo (display,
  195304. desiredMask,
  195305. &desiredVisual,
  195306. &numVisuals);
  195307. if (xvinfos != 0)
  195308. {
  195309. for (int i = 0; i < numVisuals; i++)
  195310. {
  195311. if (xvinfos[i].depth == desiredDepth)
  195312. {
  195313. visual = xvinfos[i].visual;
  195314. break;
  195315. }
  195316. }
  195317. XFree (xvinfos);
  195318. }
  195319. return visual;
  195320. }
  195321. static Visual* findVisualFormat (const int desiredDepth, int& matchedDepth) throw()
  195322. {
  195323. Visual* visual = 0;
  195324. if (desiredDepth == 32)
  195325. {
  195326. #if JUCE_USE_XSHM
  195327. if (isShmAvailable())
  195328. {
  195329. #if JUCE_USE_XRENDER
  195330. if (XRender::isAvailable())
  195331. {
  195332. XRenderPictFormat* pictFormat = XRender::findPictureFormat();
  195333. if (pictFormat != 0)
  195334. {
  195335. int numVisuals = 0;
  195336. XVisualInfo desiredVisual;
  195337. desiredVisual.screen = DefaultScreen (display);
  195338. desiredVisual.depth = 32;
  195339. desiredVisual.bits_per_rgb = 8;
  195340. XVisualInfo* xvinfos = XGetVisualInfo (display,
  195341. VisualScreenMask | VisualDepthMask | VisualBitsPerRGBMask,
  195342. &desiredVisual, &numVisuals);
  195343. if (xvinfos != 0)
  195344. {
  195345. for (int i = 0; i < numVisuals; ++i)
  195346. {
  195347. XRenderPictFormat* pictVisualFormat = XRender::xRenderFindVisualFormat (display, xvinfos[i].visual);
  195348. if (pictVisualFormat != 0
  195349. && pictVisualFormat->type == PictTypeDirect
  195350. && pictVisualFormat->direct.alphaMask)
  195351. {
  195352. visual = xvinfos[i].visual;
  195353. matchedDepth = 32;
  195354. break;
  195355. }
  195356. }
  195357. XFree (xvinfos);
  195358. }
  195359. }
  195360. }
  195361. #endif
  195362. if (visual == 0)
  195363. {
  195364. visual = findVisualWithDepth (32);
  195365. if (visual != 0)
  195366. matchedDepth = 32;
  195367. }
  195368. }
  195369. #endif
  195370. }
  195371. if (visual == 0 && desiredDepth >= 24)
  195372. {
  195373. visual = findVisualWithDepth (24);
  195374. if (visual != 0)
  195375. matchedDepth = 24;
  195376. }
  195377. if (visual == 0 && desiredDepth >= 16)
  195378. {
  195379. visual = findVisualWithDepth (16);
  195380. if (visual != 0)
  195381. matchedDepth = 16;
  195382. }
  195383. return visual;
  195384. }
  195385. }
  195386. class XBitmapImage : public Image
  195387. {
  195388. public:
  195389. XBitmapImage (const PixelFormat format_, const int w, const int h,
  195390. const bool clearImage, const int imageDepth_, Visual* visual)
  195391. : Image (format_, w, h),
  195392. imageDepth (imageDepth_),
  195393. gc (None)
  195394. {
  195395. jassert (format_ == RGB || format_ == ARGB);
  195396. pixelStride = (format_ == RGB) ? 3 : 4;
  195397. lineStride = ((w * pixelStride + 3) & ~3);
  195398. ScopedXLock xlock;
  195399. #if JUCE_USE_XSHM
  195400. usingXShm = false;
  195401. if ((imageDepth > 16) && isShmAvailable())
  195402. {
  195403. zerostruct (segmentInfo);
  195404. segmentInfo.shmid = -1;
  195405. segmentInfo.shmaddr = (char *) -1;
  195406. segmentInfo.readOnly = False;
  195407. xImage = XShmCreateImage (display, visual, imageDepth, ZPixmap, 0, &segmentInfo, w, h);
  195408. if (xImage != 0)
  195409. {
  195410. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195411. xImage->bytes_per_line * xImage->height,
  195412. IPC_CREAT | 0777)) >= 0)
  195413. {
  195414. if (segmentInfo.shmid != -1)
  195415. {
  195416. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195417. if (segmentInfo.shmaddr != (void*) -1)
  195418. {
  195419. segmentInfo.readOnly = False;
  195420. xImage->data = segmentInfo.shmaddr;
  195421. imageData = (uint8*) segmentInfo.shmaddr;
  195422. if (XShmAttach (display, &segmentInfo) != 0)
  195423. {
  195424. usingXShm = true;
  195425. }
  195426. else
  195427. {
  195428. jassertfalse
  195429. }
  195430. }
  195431. else
  195432. {
  195433. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195434. }
  195435. }
  195436. }
  195437. }
  195438. }
  195439. if (! usingXShm)
  195440. #endif
  195441. {
  195442. imageDataAllocated.malloc (lineStride * h);
  195443. imageData = imageDataAllocated;
  195444. if (format_ == ARGB && clearImage)
  195445. zeromem (imageData, h * lineStride);
  195446. xImage = (XImage*) juce_calloc (sizeof (XImage));
  195447. xImage->width = w;
  195448. xImage->height = h;
  195449. xImage->xoffset = 0;
  195450. xImage->format = ZPixmap;
  195451. xImage->data = (char*) imageData;
  195452. xImage->byte_order = ImageByteOrder (display);
  195453. xImage->bitmap_unit = BitmapUnit (display);
  195454. xImage->bitmap_bit_order = BitmapBitOrder (display);
  195455. xImage->bitmap_pad = 32;
  195456. xImage->depth = pixelStride * 8;
  195457. xImage->bytes_per_line = lineStride;
  195458. xImage->bits_per_pixel = pixelStride * 8;
  195459. xImage->red_mask = 0x00FF0000;
  195460. xImage->green_mask = 0x0000FF00;
  195461. xImage->blue_mask = 0x000000FF;
  195462. if (imageDepth == 16)
  195463. {
  195464. const int pixelStride = 2;
  195465. const int lineStride = ((w * pixelStride + 3) & ~3);
  195466. imageData16Bit.malloc (lineStride * h);
  195467. xImage->data = imageData16Bit;
  195468. xImage->bitmap_pad = 16;
  195469. xImage->depth = pixelStride * 8;
  195470. xImage->bytes_per_line = lineStride;
  195471. xImage->bits_per_pixel = pixelStride * 8;
  195472. xImage->red_mask = visual->red_mask;
  195473. xImage->green_mask = visual->green_mask;
  195474. xImage->blue_mask = visual->blue_mask;
  195475. }
  195476. if (! XInitImage (xImage))
  195477. {
  195478. jassertfalse
  195479. }
  195480. }
  195481. }
  195482. ~XBitmapImage()
  195483. {
  195484. ScopedXLock xlock;
  195485. #if JUCE_USE_XSHM
  195486. if (usingXShm)
  195487. {
  195488. XShmDetach (display, &segmentInfo);
  195489. XFlush (display);
  195490. XDestroyImage (xImage);
  195491. shmdt (segmentInfo.shmaddr);
  195492. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195493. }
  195494. else
  195495. #endif
  195496. {
  195497. xImage->data = 0;
  195498. XDestroyImage (xImage);
  195499. }
  195500. }
  195501. void blitToWindow (Window window, int dx, int dy, int dw, int dh, int sx, int sy)
  195502. {
  195503. ScopedXLock xlock;
  195504. if (gc == 0)
  195505. {
  195506. XGCValues gcvalues;
  195507. gcvalues.foreground = None;
  195508. gcvalues.background = None;
  195509. gcvalues.function = GXcopy;
  195510. gcvalues.plane_mask = AllPlanes;
  195511. gcvalues.clip_mask = None;
  195512. gcvalues.graphics_exposures = False;
  195513. gc = XCreateGC (display, window,
  195514. GCBackground | GCForeground | GCFunction | GCPlaneMask | GCClipMask | GCGraphicsExposures,
  195515. &gcvalues);
  195516. }
  195517. if (imageDepth == 16)
  195518. {
  195519. const uint32 rMask = xImage->red_mask;
  195520. const uint32 rShiftL = jmax (0, getShiftNeeded (rMask));
  195521. const uint32 rShiftR = jmax (0, -getShiftNeeded (rMask));
  195522. const uint32 gMask = xImage->green_mask;
  195523. const uint32 gShiftL = jmax (0, getShiftNeeded (gMask));
  195524. const uint32 gShiftR = jmax (0, -getShiftNeeded (gMask));
  195525. const uint32 bMask = xImage->blue_mask;
  195526. const uint32 bShiftL = jmax (0, getShiftNeeded (bMask));
  195527. const uint32 bShiftR = jmax (0, -getShiftNeeded (bMask));
  195528. const Image::BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  195529. for (int y = sy; y < sy + dh; ++y)
  195530. {
  195531. const uint8* p = srcData.getPixelPointer (sx, y);
  195532. for (int x = sx; x < sx + dw; ++x)
  195533. {
  195534. const PixelRGB* const pixel = (const PixelRGB*) p;
  195535. p += srcData.pixelStride;
  195536. XPutPixel (xImage, x, y,
  195537. (((((uint32) pixel->getRed()) << rShiftL) >> rShiftR) & rMask)
  195538. | (((((uint32) pixel->getGreen()) << gShiftL) >> gShiftR) & gMask)
  195539. | (((((uint32) pixel->getBlue()) << bShiftL) >> bShiftR) & bMask));
  195540. }
  195541. }
  195542. }
  195543. // blit results to screen.
  195544. #if JUCE_USE_XSHM
  195545. if (usingXShm)
  195546. XShmPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh, True);
  195547. else
  195548. #endif
  195549. XPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh);
  195550. }
  195551. juce_UseDebuggingNewOperator
  195552. private:
  195553. XImage* xImage;
  195554. const int imageDepth;
  195555. HeapBlock <char> imageData16Bit;
  195556. GC gc;
  195557. #if JUCE_USE_XSHM
  195558. XShmSegmentInfo segmentInfo;
  195559. bool usingXShm;
  195560. #endif
  195561. static int getShiftNeeded (const uint32 mask) throw()
  195562. {
  195563. for (int i = 32; --i >= 0;)
  195564. if (((mask >> i) & 1) != 0)
  195565. return i - 7;
  195566. jassertfalse
  195567. return 0;
  195568. }
  195569. };
  195570. class LinuxComponentPeer : public ComponentPeer
  195571. {
  195572. public:
  195573. LinuxComponentPeer (Component* const component, const int windowStyleFlags)
  195574. : ComponentPeer (component, windowStyleFlags),
  195575. windowH (0),
  195576. parentWindow (0),
  195577. wx (0),
  195578. wy (0),
  195579. ww (0),
  195580. wh (0),
  195581. fullScreen (false),
  195582. mapped (false),
  195583. visual (0),
  195584. depth (0)
  195585. {
  195586. // it's dangerous to create a window on a thread other than the message thread..
  195587. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  195588. repainter = new LinuxRepaintManager (this);
  195589. createWindow();
  195590. setTitle (component->getName());
  195591. }
  195592. ~LinuxComponentPeer()
  195593. {
  195594. // it's dangerous to delete a window on a thread other than the message thread..
  195595. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  195596. deleteIconPixmaps();
  195597. destroyWindow();
  195598. windowH = 0;
  195599. }
  195600. void* getNativeHandle() const
  195601. {
  195602. return (void*) windowH;
  195603. }
  195604. static LinuxComponentPeer* getPeerFor (Window windowHandle) throw()
  195605. {
  195606. XPointer peer = 0;
  195607. ScopedXLock xlock;
  195608. if (! XFindContext (display, (XID) windowHandle, improbableNumber, &peer))
  195609. {
  195610. if (peer != 0 && ! ComponentPeer::isValidPeer ((LinuxComponentPeer*) peer))
  195611. peer = 0;
  195612. }
  195613. return (LinuxComponentPeer*) peer;
  195614. }
  195615. void setVisible (bool shouldBeVisible)
  195616. {
  195617. ScopedXLock xlock;
  195618. if (shouldBeVisible)
  195619. XMapWindow (display, windowH);
  195620. else
  195621. XUnmapWindow (display, windowH);
  195622. }
  195623. void setTitle (const String& title)
  195624. {
  195625. setWindowTitle (windowH, title);
  195626. }
  195627. void setPosition (int x, int y)
  195628. {
  195629. setBounds (x, y, ww, wh, false);
  195630. }
  195631. void setSize (int w, int h)
  195632. {
  195633. setBounds (wx, wy, w, h, false);
  195634. }
  195635. void setBounds (int x, int y, int w, int h, bool isNowFullScreen)
  195636. {
  195637. fullScreen = isNowFullScreen;
  195638. if (windowH != 0)
  195639. {
  195640. Component::SafePointer<Component> deletionChecker (component);
  195641. wx = x;
  195642. wy = y;
  195643. ww = jmax (1, w);
  195644. wh = jmax (1, h);
  195645. ScopedXLock xlock;
  195646. // Make sure the Window manager does what we want
  195647. XSizeHints* hints = XAllocSizeHints();
  195648. hints->flags = USSize | USPosition;
  195649. hints->width = ww;
  195650. hints->height = wh;
  195651. hints->x = wx;
  195652. hints->y = wy;
  195653. if ((getStyleFlags() & (windowHasTitleBar | windowIsResizable)) == windowHasTitleBar)
  195654. {
  195655. hints->min_width = hints->max_width = hints->width;
  195656. hints->min_height = hints->max_height = hints->height;
  195657. hints->flags |= PMinSize | PMaxSize;
  195658. }
  195659. XSetWMNormalHints (display, windowH, hints);
  195660. XFree (hints);
  195661. XMoveResizeWindow (display, windowH,
  195662. wx - windowBorder.getLeft(),
  195663. wy - windowBorder.getTop(), ww, wh);
  195664. if (deletionChecker != 0)
  195665. {
  195666. updateBorderSize();
  195667. handleMovedOrResized();
  195668. }
  195669. }
  195670. }
  195671. const Rectangle<int> getBounds() const { return Rectangle<int> (wx, wy, ww, wh); }
  195672. const Point<int> getScreenPosition() const { return Point<int> (wx, wy); }
  195673. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  195674. {
  195675. return relativePosition + getScreenPosition();
  195676. }
  195677. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  195678. {
  195679. return screenPosition - getScreenPosition();
  195680. }
  195681. void setMinimised (bool shouldBeMinimised)
  195682. {
  195683. if (shouldBeMinimised)
  195684. {
  195685. Window root = RootWindow (display, DefaultScreen (display));
  195686. XClientMessageEvent clientMsg;
  195687. clientMsg.display = display;
  195688. clientMsg.window = windowH;
  195689. clientMsg.type = ClientMessage;
  195690. clientMsg.format = 32;
  195691. clientMsg.message_type = Atoms::ChangeState;
  195692. clientMsg.data.l[0] = IconicState;
  195693. ScopedXLock xlock;
  195694. XSendEvent (display, root, false,
  195695. SubstructureRedirectMask | SubstructureNotifyMask,
  195696. (XEvent*) &clientMsg);
  195697. }
  195698. else
  195699. {
  195700. setVisible (true);
  195701. }
  195702. }
  195703. bool isMinimised() const
  195704. {
  195705. bool minimised = false;
  195706. unsigned char* stateProp;
  195707. unsigned long nitems, bytesLeft;
  195708. Atom actualType;
  195709. int actualFormat;
  195710. ScopedXLock xlock;
  195711. if (XGetWindowProperty (display, windowH, Atoms::State, 0, 64, False,
  195712. Atoms::State, &actualType, &actualFormat, &nitems, &bytesLeft,
  195713. &stateProp) == Success
  195714. && actualType == Atoms::State
  195715. && actualFormat == 32
  195716. && nitems > 0)
  195717. {
  195718. if (((unsigned long*) stateProp)[0] == IconicState)
  195719. minimised = true;
  195720. XFree (stateProp);
  195721. }
  195722. return minimised;
  195723. }
  195724. void setFullScreen (const bool shouldBeFullScreen)
  195725. {
  195726. Rectangle<int> r (lastNonFullscreenBounds); // (get a copy of this before de-minimising)
  195727. setMinimised (false);
  195728. if (fullScreen != shouldBeFullScreen)
  195729. {
  195730. if (shouldBeFullScreen)
  195731. r = Desktop::getInstance().getMainMonitorArea();
  195732. if (! r.isEmpty())
  195733. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  195734. getComponent()->repaint();
  195735. }
  195736. }
  195737. bool isFullScreen() const
  195738. {
  195739. return fullScreen;
  195740. }
  195741. bool isChildWindowOf (Window possibleParent) const
  195742. {
  195743. Window* windowList = 0;
  195744. uint32 windowListSize = 0;
  195745. Window parent, root;
  195746. ScopedXLock xlock;
  195747. if (XQueryTree (display, windowH, &root, &parent, &windowList, &windowListSize) != 0)
  195748. {
  195749. if (windowList != 0)
  195750. XFree (windowList);
  195751. return parent == possibleParent;
  195752. }
  195753. return false;
  195754. }
  195755. bool isFrontWindow() const
  195756. {
  195757. Window* windowList = 0;
  195758. uint32 windowListSize = 0;
  195759. bool result = false;
  195760. ScopedXLock xlock;
  195761. Window parent, root = RootWindow (display, DefaultScreen (display));
  195762. if (XQueryTree (display, root, &root, &parent, &windowList, &windowListSize) != 0)
  195763. {
  195764. for (int i = windowListSize; --i >= 0;)
  195765. {
  195766. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (windowList[i]);
  195767. if (peer != 0)
  195768. {
  195769. result = (peer == this);
  195770. break;
  195771. }
  195772. }
  195773. }
  195774. if (windowList != 0)
  195775. XFree (windowList);
  195776. return result;
  195777. }
  195778. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const
  195779. {
  195780. int x = position.getX();
  195781. int y = position.getY();
  195782. if (((unsigned int) x) >= (unsigned int) ww
  195783. || ((unsigned int) y) >= (unsigned int) wh)
  195784. return false;
  195785. bool inFront = false;
  195786. for (int i = 0; i < Desktop::getInstance().getNumComponents(); ++i)
  195787. {
  195788. Component* const c = Desktop::getInstance().getComponent (i);
  195789. if (inFront)
  195790. {
  195791. if (c->contains (x + wx - c->getScreenX(),
  195792. y + wy - c->getScreenY()))
  195793. {
  195794. return false;
  195795. }
  195796. }
  195797. else if (c == getComponent())
  195798. {
  195799. inFront = true;
  195800. }
  195801. }
  195802. if (trueIfInAChildWindow)
  195803. return true;
  195804. ::Window root, child;
  195805. unsigned int bw, depth;
  195806. int wx, wy, w, h;
  195807. ScopedXLock xlock;
  195808. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  195809. &wx, &wy, (unsigned int*) &w, (unsigned int*) &h,
  195810. &bw, &depth))
  195811. {
  195812. return false;
  195813. }
  195814. if (! XTranslateCoordinates (display, windowH, windowH, x, y, &wx, &wy, &child))
  195815. return false;
  195816. return child == None;
  195817. }
  195818. const BorderSize getFrameSize() const
  195819. {
  195820. return BorderSize();
  195821. }
  195822. bool setAlwaysOnTop (bool alwaysOnTop)
  195823. {
  195824. if (windowH != 0)
  195825. {
  195826. const bool wasVisible = component->isVisible();
  195827. if (wasVisible)
  195828. setVisible (false); // doesn't always seem to work if the window is visible when this is done..
  195829. {
  195830. ScopedXLock xlock;
  195831. XSetWindowAttributes swa;
  195832. swa.override_redirect = alwaysOnTop ? True : False;
  195833. XChangeWindowAttributes (display, windowH, CWOverrideRedirect, &swa);
  195834. }
  195835. if (wasVisible)
  195836. setVisible (true);
  195837. }
  195838. return true;
  195839. }
  195840. void toFront (bool makeActive)
  195841. {
  195842. if (makeActive)
  195843. {
  195844. setVisible (true);
  195845. grabFocus();
  195846. }
  195847. XEvent ev;
  195848. ev.xclient.type = ClientMessage;
  195849. ev.xclient.serial = 0;
  195850. ev.xclient.send_event = True;
  195851. ev.xclient.message_type = Atoms::ActiveWin;
  195852. ev.xclient.window = windowH;
  195853. ev.xclient.format = 32;
  195854. ev.xclient.data.l[0] = 2;
  195855. ev.xclient.data.l[1] = CurrentTime;
  195856. ev.xclient.data.l[2] = 0;
  195857. ev.xclient.data.l[3] = 0;
  195858. ev.xclient.data.l[4] = 0;
  195859. {
  195860. ScopedXLock xlock;
  195861. XSendEvent (display, RootWindow (display, DefaultScreen (display)),
  195862. False,
  195863. SubstructureRedirectMask | SubstructureNotifyMask,
  195864. &ev);
  195865. XWindowAttributes attr;
  195866. XGetWindowAttributes (display, windowH, &attr);
  195867. if (attr.override_redirect)
  195868. XRaiseWindow (display, windowH);
  195869. XSync (display, False);
  195870. }
  195871. handleBroughtToFront();
  195872. }
  195873. void toBehind (ComponentPeer* other)
  195874. {
  195875. LinuxComponentPeer* const otherPeer = dynamic_cast <LinuxComponentPeer*> (other);
  195876. jassert (otherPeer != 0); // wrong type of window?
  195877. if (otherPeer != 0)
  195878. {
  195879. setMinimised (false);
  195880. Window newStack[] = { otherPeer->windowH, windowH };
  195881. ScopedXLock xlock;
  195882. XRestackWindows (display, newStack, 2);
  195883. }
  195884. }
  195885. bool isFocused() const
  195886. {
  195887. int revert;
  195888. Window focusedWindow = 0;
  195889. ScopedXLock xlock;
  195890. XGetInputFocus (display, &focusedWindow, &revert);
  195891. return focusedWindow == windowH;
  195892. }
  195893. void grabFocus()
  195894. {
  195895. XWindowAttributes atts;
  195896. ScopedXLock xlock;
  195897. if (windowH != 0
  195898. && XGetWindowAttributes (display, windowH, &atts)
  195899. && atts.map_state == IsViewable
  195900. && ! isFocused())
  195901. {
  195902. XSetInputFocus (display, windowH, RevertToParent, CurrentTime);
  195903. isActiveApplication = true;
  195904. }
  195905. }
  195906. void textInputRequired (const Point<int>&)
  195907. {
  195908. }
  195909. void repaint (int x, int y, int w, int h)
  195910. {
  195911. if (Rectangle<int>::intersectRectangles (x, y, w, h,
  195912. 0, 0,
  195913. getComponent()->getWidth(),
  195914. getComponent()->getHeight()))
  195915. {
  195916. repainter->repaint (x, y, w, h);
  195917. }
  195918. }
  195919. void performAnyPendingRepaintsNow()
  195920. {
  195921. repainter->performAnyPendingRepaintsNow();
  195922. }
  195923. static Pixmap juce_createColourPixmapFromImage (Display* display, const Image& image)
  195924. {
  195925. ScopedXLock xlock;
  195926. const int width = image.getWidth();
  195927. const int height = image.getHeight();
  195928. HeapBlock <uint32> colour (width * height);
  195929. int index = 0;
  195930. for (int y = 0; y < height; ++y)
  195931. for (int x = 0; x < width; ++x)
  195932. colour[index++] = image.getPixelAt (x, y).getARGB();
  195933. XImage* ximage = XCreateImage (display, CopyFromParent, 24, ZPixmap,
  195934. 0, reinterpret_cast<char*> (colour.getData()),
  195935. width, height, 32, 0);
  195936. Pixmap pixmap = XCreatePixmap (display, DefaultRootWindow (display),
  195937. width, height, 24);
  195938. GC gc = XCreateGC (display, pixmap, 0, 0);
  195939. XPutImage (display, pixmap, gc, ximage, 0, 0, 0, 0, width, height);
  195940. XFreeGC (display, gc);
  195941. return pixmap;
  195942. }
  195943. static Pixmap juce_createMaskPixmapFromImage (Display* display, const Image& image)
  195944. {
  195945. ScopedXLock xlock;
  195946. const int width = image.getWidth();
  195947. const int height = image.getHeight();
  195948. const int stride = (width + 7) >> 3;
  195949. HeapBlock <uint8> mask;
  195950. mask.calloc (stride * height);
  195951. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  195952. for (int y = 0; y < height; ++y)
  195953. {
  195954. for (int x = 0; x < width; ++x)
  195955. {
  195956. const uint8 bit = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  195957. const int offset = y * stride + (x >> 3);
  195958. if (image.getPixelAt (x, y).getAlpha() >= 128)
  195959. mask[offset] |= bit;
  195960. }
  195961. }
  195962. return XCreatePixmapFromBitmapData (display, DefaultRootWindow (display),
  195963. reinterpret_cast<char*> (mask.getData()), width, height, 1, 0, 1);
  195964. }
  195965. void setIcon (const Image& newIcon)
  195966. {
  195967. const int dataSize = newIcon.getWidth() * newIcon.getHeight() + 2;
  195968. HeapBlock <unsigned long> data (dataSize);
  195969. int index = 0;
  195970. data[index++] = newIcon.getWidth();
  195971. data[index++] = newIcon.getHeight();
  195972. for (int y = 0; y < newIcon.getHeight(); ++y)
  195973. for (int x = 0; x < newIcon.getWidth(); ++x)
  195974. data[index++] = newIcon.getPixelAt (x, y).getARGB();
  195975. ScopedXLock xlock;
  195976. XChangeProperty (display, windowH,
  195977. XInternAtom (display, "_NET_WM_ICON", False),
  195978. XA_CARDINAL, 32, PropModeReplace,
  195979. reinterpret_cast<unsigned char*> (data.getData()), dataSize);
  195980. deleteIconPixmaps();
  195981. XWMHints* wmHints = XGetWMHints (display, windowH);
  195982. if (wmHints == 0)
  195983. wmHints = XAllocWMHints();
  195984. wmHints->flags |= IconPixmapHint | IconMaskHint;
  195985. wmHints->icon_pixmap = juce_createColourPixmapFromImage (display, newIcon);
  195986. wmHints->icon_mask = juce_createMaskPixmapFromImage (display, newIcon);
  195987. XSetWMHints (display, windowH, wmHints);
  195988. XFree (wmHints);
  195989. XSync (display, False);
  195990. }
  195991. void deleteIconPixmaps()
  195992. {
  195993. ScopedXLock xlock;
  195994. XWMHints* wmHints = XGetWMHints (display, windowH);
  195995. if (wmHints != 0)
  195996. {
  195997. if ((wmHints->flags & IconPixmapHint) != 0)
  195998. {
  195999. wmHints->flags &= ~IconPixmapHint;
  196000. XFreePixmap (display, wmHints->icon_pixmap);
  196001. }
  196002. if ((wmHints->flags & IconMaskHint) != 0)
  196003. {
  196004. wmHints->flags &= ~IconMaskHint;
  196005. XFreePixmap (display, wmHints->icon_mask);
  196006. }
  196007. XSetWMHints (display, windowH, wmHints);
  196008. XFree (wmHints);
  196009. }
  196010. }
  196011. void handleWindowMessage (XEvent* event)
  196012. {
  196013. switch (event->xany.type)
  196014. {
  196015. case 2: // 'KeyPress'
  196016. {
  196017. ScopedXLock xlock;
  196018. XKeyEvent* const keyEvent = (XKeyEvent*) &event->xkey;
  196019. updateKeyStates (keyEvent->keycode, true);
  196020. char utf8 [64];
  196021. zeromem (utf8, sizeof (utf8));
  196022. KeySym sym;
  196023. {
  196024. const char* oldLocale = ::setlocale (LC_ALL, 0);
  196025. ::setlocale (LC_ALL, "");
  196026. XLookupString (keyEvent, utf8, sizeof (utf8), &sym, 0);
  196027. ::setlocale (LC_ALL, oldLocale);
  196028. }
  196029. const juce_wchar unicodeChar = *(const juce_wchar*) String::fromUTF8 (utf8, sizeof (utf8) - 1);
  196030. int keyCode = (int) unicodeChar;
  196031. if (keyCode < 0x20)
  196032. keyCode = XKeycodeToKeysym (display, keyEvent->keycode, currentModifiers.isShiftDown() ? 1 : 0);
  196033. const ModifierKeys oldMods (currentModifiers);
  196034. bool keyPressed = false;
  196035. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, true);
  196036. if ((sym & 0xff00) == 0xff00)
  196037. {
  196038. // Translate keypad
  196039. if (sym == XK_KP_Divide)
  196040. keyCode = XK_slash;
  196041. else if (sym == XK_KP_Multiply)
  196042. keyCode = XK_asterisk;
  196043. else if (sym == XK_KP_Subtract)
  196044. keyCode = XK_hyphen;
  196045. else if (sym == XK_KP_Add)
  196046. keyCode = XK_plus;
  196047. else if (sym == XK_KP_Enter)
  196048. keyCode = XK_Return;
  196049. else if (sym == XK_KP_Decimal)
  196050. keyCode = Keys::numLock ? XK_period : XK_Delete;
  196051. else if (sym == XK_KP_0)
  196052. keyCode = Keys::numLock ? XK_0 : XK_Insert;
  196053. else if (sym == XK_KP_1)
  196054. keyCode = Keys::numLock ? XK_1 : XK_End;
  196055. else if (sym == XK_KP_2)
  196056. keyCode = Keys::numLock ? XK_2 : XK_Down;
  196057. else if (sym == XK_KP_3)
  196058. keyCode = Keys::numLock ? XK_3 : XK_Page_Down;
  196059. else if (sym == XK_KP_4)
  196060. keyCode = Keys::numLock ? XK_4 : XK_Left;
  196061. else if (sym == XK_KP_5)
  196062. keyCode = XK_5;
  196063. else if (sym == XK_KP_6)
  196064. keyCode = Keys::numLock ? XK_6 : XK_Right;
  196065. else if (sym == XK_KP_7)
  196066. keyCode = Keys::numLock ? XK_7 : XK_Home;
  196067. else if (sym == XK_KP_8)
  196068. keyCode = Keys::numLock ? XK_8 : XK_Up;
  196069. else if (sym == XK_KP_9)
  196070. keyCode = Keys::numLock ? XK_9 : XK_Page_Up;
  196071. switch (sym)
  196072. {
  196073. case XK_Left:
  196074. case XK_Right:
  196075. case XK_Up:
  196076. case XK_Down:
  196077. case XK_Page_Up:
  196078. case XK_Page_Down:
  196079. case XK_End:
  196080. case XK_Home:
  196081. case XK_Delete:
  196082. case XK_Insert:
  196083. keyPressed = true;
  196084. keyCode = (sym & 0xff) | Keys::extendedKeyModifier;
  196085. break;
  196086. case XK_Tab:
  196087. case XK_Return:
  196088. case XK_Escape:
  196089. case XK_BackSpace:
  196090. keyPressed = true;
  196091. keyCode &= 0xff;
  196092. break;
  196093. default:
  196094. {
  196095. if (sym >= XK_F1 && sym <= XK_F16)
  196096. {
  196097. keyPressed = true;
  196098. keyCode = (sym & 0xff) | Keys::extendedKeyModifier;
  196099. }
  196100. break;
  196101. }
  196102. }
  196103. }
  196104. if (utf8[0] != 0 || ((sym & 0xff00) == 0 && sym >= 8))
  196105. keyPressed = true;
  196106. if (oldMods != currentModifiers)
  196107. handleModifierKeysChange();
  196108. if (keyDownChange)
  196109. handleKeyUpOrDown (true);
  196110. if (keyPressed)
  196111. handleKeyPress (keyCode, unicodeChar);
  196112. break;
  196113. }
  196114. case KeyRelease:
  196115. {
  196116. const XKeyEvent* const keyEvent = (const XKeyEvent*) &event->xkey;
  196117. updateKeyStates (keyEvent->keycode, false);
  196118. ScopedXLock xlock;
  196119. KeySym sym = XKeycodeToKeysym (display, keyEvent->keycode, 0);
  196120. const ModifierKeys oldMods (currentModifiers);
  196121. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, false);
  196122. if (oldMods != currentModifiers)
  196123. handleModifierKeysChange();
  196124. if (keyDownChange)
  196125. handleKeyUpOrDown (false);
  196126. break;
  196127. }
  196128. case ButtonPress:
  196129. {
  196130. const XButtonPressedEvent* const buttonPressEvent = (const XButtonPressedEvent*) &event->xbutton;
  196131. updateKeyModifiers (buttonPressEvent->state);
  196132. bool buttonMsg = false;
  196133. const int map = pointerMap [buttonPressEvent->button - Button1];
  196134. if (map == Keys::WheelUp || map == Keys::WheelDown)
  196135. {
  196136. handleMouseWheel (0, Point<int> (buttonPressEvent->x, buttonPressEvent->y),
  196137. getEventTime (buttonPressEvent->time), 0, map == Keys::WheelDown ? -84.0f : 84.0f);
  196138. }
  196139. if (map == Keys::LeftButton)
  196140. {
  196141. currentModifiers = currentModifiers.withFlags (ModifierKeys::leftButtonModifier);
  196142. buttonMsg = true;
  196143. }
  196144. else if (map == Keys::RightButton)
  196145. {
  196146. currentModifiers = currentModifiers.withFlags (ModifierKeys::rightButtonModifier);
  196147. buttonMsg = true;
  196148. }
  196149. else if (map == Keys::MiddleButton)
  196150. {
  196151. currentModifiers = currentModifiers.withFlags (ModifierKeys::middleButtonModifier);
  196152. buttonMsg = true;
  196153. }
  196154. if (buttonMsg)
  196155. {
  196156. toFront (true);
  196157. handleMouseEvent (0, Point<int> (buttonPressEvent->x, buttonPressEvent->y), currentModifiers,
  196158. getEventTime (buttonPressEvent->time));
  196159. }
  196160. clearLastMousePos();
  196161. break;
  196162. }
  196163. case ButtonRelease:
  196164. {
  196165. const XButtonReleasedEvent* const buttonRelEvent = (const XButtonReleasedEvent*) &event->xbutton;
  196166. updateKeyModifiers (buttonRelEvent->state);
  196167. const int map = pointerMap [buttonRelEvent->button - Button1];
  196168. if (map == Keys::LeftButton)
  196169. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::leftButtonModifier);
  196170. else if (map == Keys::RightButton)
  196171. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::rightButtonModifier);
  196172. else if (map == Keys::MiddleButton)
  196173. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::middleButtonModifier);
  196174. handleMouseEvent (0, Point<int> (buttonRelEvent->x, buttonRelEvent->y), currentModifiers,
  196175. getEventTime (buttonRelEvent->time));
  196176. clearLastMousePos();
  196177. break;
  196178. }
  196179. case MotionNotify:
  196180. {
  196181. const XPointerMovedEvent* const movedEvent = (const XPointerMovedEvent*) &event->xmotion;
  196182. updateKeyModifiers (movedEvent->state);
  196183. const Point<int> mousePos (Desktop::getMousePosition());
  196184. if (lastMousePos != mousePos)
  196185. {
  196186. lastMousePos = mousePos;
  196187. if (parentWindow != 0 && (styleFlags & windowHasTitleBar) == 0)
  196188. {
  196189. Window wRoot = 0, wParent = 0;
  196190. {
  196191. ScopedXLock xlock;
  196192. unsigned int numChildren;
  196193. Window* wChild = 0;
  196194. XQueryTree (display, windowH, &wRoot, &wParent, &wChild, &numChildren);
  196195. }
  196196. if (wParent != 0
  196197. && wParent != windowH
  196198. && wParent != wRoot)
  196199. {
  196200. parentWindow = wParent;
  196201. updateBounds();
  196202. }
  196203. else
  196204. {
  196205. parentWindow = 0;
  196206. }
  196207. }
  196208. handleMouseEvent (0, mousePos - getScreenPosition(), currentModifiers, getEventTime (movedEvent->time));
  196209. }
  196210. break;
  196211. }
  196212. case EnterNotify:
  196213. {
  196214. clearLastMousePos();
  196215. const XEnterWindowEvent* const enterEvent = (const XEnterWindowEvent*) &event->xcrossing;
  196216. if (! currentModifiers.isAnyMouseButtonDown())
  196217. {
  196218. updateKeyModifiers (enterEvent->state);
  196219. handleMouseEvent (0, Point<int> (enterEvent->x, enterEvent->y), currentModifiers, getEventTime (enterEvent->time));
  196220. }
  196221. break;
  196222. }
  196223. case LeaveNotify:
  196224. {
  196225. const XLeaveWindowEvent* const leaveEvent = (const XLeaveWindowEvent*) &event->xcrossing;
  196226. // Suppress the normal leave if we've got a pointer grab, or if
  196227. // it's a bogus one caused by clicking a mouse button when running
  196228. // in a Window manager
  196229. if (((! currentModifiers.isAnyMouseButtonDown()) && leaveEvent->mode == NotifyNormal)
  196230. || leaveEvent->mode == NotifyUngrab)
  196231. {
  196232. updateKeyModifiers (leaveEvent->state);
  196233. handleMouseEvent (0, Point<int> (leaveEvent->x, leaveEvent->y), currentModifiers, getEventTime (leaveEvent->time));
  196234. }
  196235. break;
  196236. }
  196237. case FocusIn:
  196238. {
  196239. isActiveApplication = true;
  196240. if (isFocused())
  196241. handleFocusGain();
  196242. break;
  196243. }
  196244. case FocusOut:
  196245. {
  196246. isActiveApplication = false;
  196247. if (! isFocused())
  196248. handleFocusLoss();
  196249. break;
  196250. }
  196251. case Expose:
  196252. {
  196253. // Batch together all pending expose events
  196254. XExposeEvent* exposeEvent = (XExposeEvent*) &event->xexpose;
  196255. XEvent nextEvent;
  196256. ScopedXLock xlock;
  196257. if (exposeEvent->window != windowH)
  196258. {
  196259. Window child;
  196260. XTranslateCoordinates (display, exposeEvent->window, windowH,
  196261. exposeEvent->x, exposeEvent->y, &exposeEvent->x, &exposeEvent->y,
  196262. &child);
  196263. }
  196264. repaint (exposeEvent->x, exposeEvent->y,
  196265. exposeEvent->width, exposeEvent->height);
  196266. while (XEventsQueued (display, QueuedAfterFlush) > 0)
  196267. {
  196268. XPeekEvent (display, (XEvent*) &nextEvent);
  196269. if (nextEvent.type != Expose || nextEvent.xany.window != event->xany.window)
  196270. break;
  196271. XNextEvent (display, (XEvent*) &nextEvent);
  196272. XExposeEvent* nextExposeEvent = (XExposeEvent*) &nextEvent.xexpose;
  196273. repaint (nextExposeEvent->x, nextExposeEvent->y,
  196274. nextExposeEvent->width, nextExposeEvent->height);
  196275. }
  196276. break;
  196277. }
  196278. case CirculateNotify:
  196279. case CreateNotify:
  196280. case DestroyNotify:
  196281. // Think we can ignore these
  196282. break;
  196283. case ConfigureNotify:
  196284. {
  196285. updateBounds();
  196286. updateBorderSize();
  196287. handleMovedOrResized();
  196288. // if the native title bar is dragged, need to tell any active menus, etc.
  196289. if ((styleFlags & windowHasTitleBar) != 0
  196290. && component->isCurrentlyBlockedByAnotherModalComponent())
  196291. {
  196292. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  196293. if (currentModalComp != 0)
  196294. currentModalComp->inputAttemptWhenModal();
  196295. }
  196296. XConfigureEvent* const confEvent = (XConfigureEvent*) &event->xconfigure;
  196297. if (confEvent->window == windowH
  196298. && confEvent->above != 0
  196299. && isFrontWindow())
  196300. {
  196301. handleBroughtToFront();
  196302. }
  196303. break;
  196304. }
  196305. case ReparentNotify:
  196306. case GravityNotify:
  196307. {
  196308. parentWindow = 0;
  196309. Window wRoot = 0;
  196310. Window* wChild = 0;
  196311. unsigned int numChildren;
  196312. {
  196313. ScopedXLock xlock;
  196314. XQueryTree (display, windowH, &wRoot, &parentWindow, &wChild, &numChildren);
  196315. }
  196316. if (parentWindow == windowH || parentWindow == wRoot)
  196317. parentWindow = 0;
  196318. updateBounds();
  196319. updateBorderSize();
  196320. handleMovedOrResized();
  196321. break;
  196322. }
  196323. case MapNotify:
  196324. mapped = true;
  196325. handleBroughtToFront();
  196326. break;
  196327. case UnmapNotify:
  196328. mapped = false;
  196329. break;
  196330. case MappingNotify:
  196331. {
  196332. XMappingEvent* mappingEvent = (XMappingEvent*) &event->xmapping;
  196333. if (mappingEvent->request != MappingPointer)
  196334. {
  196335. // Deal with modifier/keyboard mapping
  196336. ScopedXLock xlock;
  196337. XRefreshKeyboardMapping (mappingEvent);
  196338. updateModifierMappings();
  196339. }
  196340. break;
  196341. }
  196342. case ClientMessage:
  196343. {
  196344. const XClientMessageEvent* const clientMsg = (const XClientMessageEvent*) &event->xclient;
  196345. if (clientMsg->message_type == Atoms::Protocols && clientMsg->format == 32)
  196346. {
  196347. const Atom atom = (Atom) clientMsg->data.l[0];
  196348. if (atom == Atoms::ProtocolList [Atoms::TAKE_FOCUS])
  196349. {
  196350. XWindowAttributes atts;
  196351. ScopedXLock xlock;
  196352. if (clientMsg->window != 0
  196353. && XGetWindowAttributes (display, clientMsg->window, &atts))
  196354. {
  196355. if (atts.map_state == IsViewable)
  196356. XSetInputFocus (display, clientMsg->window, RevertToParent, clientMsg->data.l[1]);
  196357. }
  196358. }
  196359. else if (atom == Atoms::ProtocolList [Atoms::DELETE_WINDOW])
  196360. {
  196361. handleUserClosingWindow();
  196362. }
  196363. }
  196364. else if (clientMsg->message_type == Atoms::XdndEnter)
  196365. {
  196366. handleDragAndDropEnter (clientMsg);
  196367. }
  196368. else if (clientMsg->message_type == Atoms::XdndLeave)
  196369. {
  196370. resetDragAndDrop();
  196371. }
  196372. else if (clientMsg->message_type == Atoms::XdndPosition)
  196373. {
  196374. handleDragAndDropPosition (clientMsg);
  196375. }
  196376. else if (clientMsg->message_type == Atoms::XdndDrop)
  196377. {
  196378. handleDragAndDropDrop (clientMsg);
  196379. }
  196380. else if (clientMsg->message_type == Atoms::XdndStatus)
  196381. {
  196382. handleDragAndDropStatus (clientMsg);
  196383. }
  196384. else if (clientMsg->message_type == Atoms::XdndFinished)
  196385. {
  196386. resetDragAndDrop();
  196387. }
  196388. break;
  196389. }
  196390. case SelectionNotify:
  196391. handleDragAndDropSelection (event);
  196392. break;
  196393. case SelectionClear:
  196394. case SelectionRequest:
  196395. break;
  196396. default:
  196397. #if JUCE_USE_XSHM
  196398. {
  196399. ScopedXLock xlock;
  196400. if (event->xany.type == XShmGetEventBase (display))
  196401. repainter->notifyPaintCompleted();
  196402. }
  196403. #endif
  196404. break;
  196405. }
  196406. }
  196407. void showMouseCursor (Cursor cursor) throw()
  196408. {
  196409. ScopedXLock xlock;
  196410. XDefineCursor (display, windowH, cursor);
  196411. }
  196412. void setTaskBarIcon (const Image& image)
  196413. {
  196414. ScopedXLock xlock;
  196415. taskbarImage = image.createCopy();
  196416. Screen* const screen = XDefaultScreenOfDisplay (display);
  196417. const int screenNumber = XScreenNumberOfScreen (screen);
  196418. String screenAtom ("_NET_SYSTEM_TRAY_S");
  196419. screenAtom << screenNumber;
  196420. Atom selectionAtom = XInternAtom (display, screenAtom.toUTF8(), false);
  196421. XGrabServer (display);
  196422. Window managerWin = XGetSelectionOwner (display, selectionAtom);
  196423. if (managerWin != None)
  196424. XSelectInput (display, managerWin, StructureNotifyMask);
  196425. XUngrabServer (display);
  196426. XFlush (display);
  196427. if (managerWin != None)
  196428. {
  196429. XEvent ev;
  196430. zerostruct (ev);
  196431. ev.xclient.type = ClientMessage;
  196432. ev.xclient.window = managerWin;
  196433. ev.xclient.message_type = XInternAtom (display, "_NET_SYSTEM_TRAY_OPCODE", False);
  196434. ev.xclient.format = 32;
  196435. ev.xclient.data.l[0] = CurrentTime;
  196436. ev.xclient.data.l[1] = SYSTEM_TRAY_REQUEST_DOCK;
  196437. ev.xclient.data.l[2] = windowH;
  196438. ev.xclient.data.l[3] = 0;
  196439. ev.xclient.data.l[4] = 0;
  196440. XSendEvent (display, managerWin, False, NoEventMask, &ev);
  196441. XSync (display, False);
  196442. }
  196443. // For older KDE's ...
  196444. long atomData = 1;
  196445. Atom trayAtom = XInternAtom (display, "KWM_DOCKWINDOW", false);
  196446. XChangeProperty (display, windowH, trayAtom, trayAtom, 32, PropModeReplace, (unsigned char*) &atomData, 1);
  196447. // For more recent KDE's...
  196448. trayAtom = XInternAtom (display, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false);
  196449. XChangeProperty (display, windowH, trayAtom, XA_WINDOW, 32, PropModeReplace, (unsigned char*) &windowH, 1);
  196450. // a minimum size must be specified for GNOME and Xfce, otherwise the icon is displayed with a width of 1
  196451. XSizeHints* hints = XAllocSizeHints();
  196452. hints->flags = PMinSize;
  196453. hints->min_width = 22;
  196454. hints->min_height = 22;
  196455. XSetWMNormalHints (display, windowH, hints);
  196456. XFree (hints);
  196457. }
  196458. const Image* getTaskbarIcon() const throw() { return taskbarImage; }
  196459. juce_UseDebuggingNewOperator
  196460. bool dontRepaint;
  196461. static ModifierKeys currentModifiers;
  196462. private:
  196463. class LinuxRepaintManager : public Timer
  196464. {
  196465. public:
  196466. LinuxRepaintManager (LinuxComponentPeer* const peer_)
  196467. : peer (peer_),
  196468. lastTimeImageUsed (0)
  196469. {
  196470. #if JUCE_USE_XSHM
  196471. shmCompletedDrawing = true;
  196472. useARGBImagesForRendering = isShmAvailable();
  196473. if (useARGBImagesForRendering)
  196474. {
  196475. ScopedXLock xlock;
  196476. XShmSegmentInfo segmentinfo;
  196477. XImage* const testImage
  196478. = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  196479. 24, ZPixmap, 0, &segmentinfo, 64, 64);
  196480. useARGBImagesForRendering = (testImage->bits_per_pixel == 32);
  196481. XDestroyImage (testImage);
  196482. }
  196483. #endif
  196484. }
  196485. ~LinuxRepaintManager()
  196486. {
  196487. }
  196488. void timerCallback()
  196489. {
  196490. #if JUCE_USE_XSHM
  196491. if (! shmCompletedDrawing)
  196492. return;
  196493. #endif
  196494. if (! regionsNeedingRepaint.isEmpty())
  196495. {
  196496. stopTimer();
  196497. performAnyPendingRepaintsNow();
  196498. }
  196499. else if (Time::getApproximateMillisecondCounter() > lastTimeImageUsed + 3000)
  196500. {
  196501. stopTimer();
  196502. image = 0;
  196503. }
  196504. }
  196505. void repaint (int x, int y, int w, int h)
  196506. {
  196507. if (! isTimerRunning())
  196508. startTimer (repaintTimerPeriod);
  196509. regionsNeedingRepaint.add (x, y, w, h);
  196510. }
  196511. void performAnyPendingRepaintsNow()
  196512. {
  196513. #if JUCE_USE_XSHM
  196514. if (! shmCompletedDrawing)
  196515. {
  196516. startTimer (repaintTimerPeriod);
  196517. return;
  196518. }
  196519. #endif
  196520. peer->clearMaskedRegion();
  196521. RectangleList originalRepaintRegion (regionsNeedingRepaint);
  196522. regionsNeedingRepaint.clear();
  196523. const Rectangle<int> totalArea (originalRepaintRegion.getBounds());
  196524. if (! totalArea.isEmpty())
  196525. {
  196526. if (image == 0 || image->getWidth() < totalArea.getWidth()
  196527. || image->getHeight() < totalArea.getHeight())
  196528. {
  196529. #if JUCE_USE_XSHM
  196530. image = new XBitmapImage (useARGBImagesForRendering ? Image::ARGB
  196531. : Image::RGB,
  196532. #else
  196533. image = new XBitmapImage (Image::RGB,
  196534. #endif
  196535. (totalArea.getWidth() + 31) & ~31,
  196536. (totalArea.getHeight() + 31) & ~31,
  196537. false,
  196538. peer->depth,
  196539. peer->visual);
  196540. }
  196541. startTimer (repaintTimerPeriod);
  196542. LowLevelGraphicsSoftwareRenderer context (*image);
  196543. context.setOrigin (-totalArea.getX(), -totalArea.getY());
  196544. if (context.clipToRectangleList (originalRepaintRegion))
  196545. {
  196546. if (peer->depth == 32)
  196547. {
  196548. RectangleList::Iterator i (originalRepaintRegion);
  196549. while (i.next())
  196550. {
  196551. const Rectangle<int>& r = *i.getRectangle();
  196552. image->clear (r.getX() - totalArea.getX(), r.getY() - totalArea.getY(), r.getWidth(), r.getHeight());
  196553. }
  196554. }
  196555. peer->handlePaint (context);
  196556. }
  196557. if (! peer->maskedRegion.isEmpty())
  196558. originalRepaintRegion.subtract (peer->maskedRegion);
  196559. for (RectangleList::Iterator i (originalRepaintRegion); i.next();)
  196560. {
  196561. #if JUCE_USE_XSHM
  196562. shmCompletedDrawing = false;
  196563. #endif
  196564. const Rectangle<int>& r = *i.getRectangle();
  196565. image->blitToWindow (peer->windowH,
  196566. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  196567. r.getX() - totalArea.getX(), r.getY() - totalArea.getY());
  196568. }
  196569. }
  196570. lastTimeImageUsed = Time::getApproximateMillisecondCounter();
  196571. startTimer (repaintTimerPeriod);
  196572. }
  196573. #if JUCE_USE_XSHM
  196574. void notifyPaintCompleted() { shmCompletedDrawing = true; }
  196575. #endif
  196576. private:
  196577. enum { repaintTimerPeriod = 1000 / 100 };
  196578. LinuxComponentPeer* const peer;
  196579. ScopedPointer <XBitmapImage> image;
  196580. uint32 lastTimeImageUsed;
  196581. RectangleList regionsNeedingRepaint;
  196582. #if JUCE_USE_XSHM
  196583. bool useARGBImagesForRendering, shmCompletedDrawing;
  196584. #endif
  196585. LinuxRepaintManager (const LinuxRepaintManager&);
  196586. LinuxRepaintManager& operator= (const LinuxRepaintManager&);
  196587. };
  196588. ScopedPointer <LinuxRepaintManager> repainter;
  196589. friend class LinuxRepaintManager;
  196590. Window windowH, parentWindow;
  196591. int wx, wy, ww, wh;
  196592. ScopedPointer<Image> taskbarImage;
  196593. bool fullScreen, mapped;
  196594. Visual* visual;
  196595. int depth;
  196596. BorderSize windowBorder;
  196597. struct MotifWmHints
  196598. {
  196599. unsigned long flags;
  196600. unsigned long functions;
  196601. unsigned long decorations;
  196602. long input_mode;
  196603. unsigned long status;
  196604. };
  196605. static void updateKeyStates (const int keycode, const bool press) throw()
  196606. {
  196607. const int keybyte = keycode >> 3;
  196608. const int keybit = (1 << (keycode & 7));
  196609. if (press)
  196610. Keys::keyStates [keybyte] |= keybit;
  196611. else
  196612. Keys::keyStates [keybyte] &= ~keybit;
  196613. }
  196614. static void updateKeyModifiers (const int status) throw()
  196615. {
  196616. int keyMods = 0;
  196617. if (status & ShiftMask) keyMods |= ModifierKeys::shiftModifier;
  196618. if (status & ControlMask) keyMods |= ModifierKeys::ctrlModifier;
  196619. if (status & Keys::AltMask) keyMods |= ModifierKeys::altModifier;
  196620. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  196621. Keys::numLock = ((status & Keys::NumLockMask) != 0);
  196622. Keys::capsLock = ((status & LockMask) != 0);
  196623. }
  196624. static bool updateKeyModifiersFromSym (KeySym sym, const bool press) throw()
  196625. {
  196626. int modifier = 0;
  196627. bool isModifier = true;
  196628. switch (sym)
  196629. {
  196630. case XK_Shift_L:
  196631. case XK_Shift_R:
  196632. modifier = ModifierKeys::shiftModifier;
  196633. break;
  196634. case XK_Control_L:
  196635. case XK_Control_R:
  196636. modifier = ModifierKeys::ctrlModifier;
  196637. break;
  196638. case XK_Alt_L:
  196639. case XK_Alt_R:
  196640. modifier = ModifierKeys::altModifier;
  196641. break;
  196642. case XK_Num_Lock:
  196643. if (press)
  196644. Keys::numLock = ! Keys::numLock;
  196645. break;
  196646. case XK_Caps_Lock:
  196647. if (press)
  196648. Keys::capsLock = ! Keys::capsLock;
  196649. break;
  196650. case XK_Scroll_Lock:
  196651. break;
  196652. default:
  196653. isModifier = false;
  196654. break;
  196655. }
  196656. if (modifier != 0)
  196657. {
  196658. if (press)
  196659. currentModifiers = currentModifiers.withFlags (modifier);
  196660. else
  196661. currentModifiers = currentModifiers.withoutFlags (modifier);
  196662. }
  196663. return isModifier;
  196664. }
  196665. // Alt and Num lock are not defined by standard X
  196666. // modifier constants: check what they're mapped to
  196667. static void updateModifierMappings() throw()
  196668. {
  196669. ScopedXLock xlock;
  196670. const int altLeftCode = XKeysymToKeycode (display, XK_Alt_L);
  196671. const int numLockCode = XKeysymToKeycode (display, XK_Num_Lock);
  196672. Keys::AltMask = 0;
  196673. Keys::NumLockMask = 0;
  196674. XModifierKeymap* mapping = XGetModifierMapping (display);
  196675. if (mapping)
  196676. {
  196677. for (int i = 0; i < 8; i++)
  196678. {
  196679. if (mapping->modifiermap [i << 1] == altLeftCode)
  196680. Keys::AltMask = 1 << i;
  196681. else if (mapping->modifiermap [i << 1] == numLockCode)
  196682. Keys::NumLockMask = 1 << i;
  196683. }
  196684. XFreeModifiermap (mapping);
  196685. }
  196686. }
  196687. void removeWindowDecorations (Window wndH)
  196688. {
  196689. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  196690. if (hints != None)
  196691. {
  196692. MotifWmHints motifHints;
  196693. zerostruct (motifHints);
  196694. motifHints.flags = 2; /* MWM_HINTS_DECORATIONS */
  196695. motifHints.decorations = 0;
  196696. ScopedXLock xlock;
  196697. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196698. (unsigned char*) &motifHints, 4);
  196699. }
  196700. hints = XInternAtom (display, "_WIN_HINTS", True);
  196701. if (hints != None)
  196702. {
  196703. long gnomeHints = 0;
  196704. ScopedXLock xlock;
  196705. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196706. (unsigned char*) &gnomeHints, 1);
  196707. }
  196708. hints = XInternAtom (display, "KWM_WIN_DECORATION", True);
  196709. if (hints != None)
  196710. {
  196711. long kwmHints = 2; /*KDE_tinyDecoration*/
  196712. ScopedXLock xlock;
  196713. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196714. (unsigned char*) &kwmHints, 1);
  196715. }
  196716. }
  196717. void addWindowButtons (Window wndH)
  196718. {
  196719. ScopedXLock xlock;
  196720. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  196721. if (hints != None)
  196722. {
  196723. MotifWmHints motifHints;
  196724. zerostruct (motifHints);
  196725. motifHints.flags = 1 | 2; /* MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS */
  196726. motifHints.decorations = 2 /* MWM_DECOR_BORDER */ | 8 /* MWM_DECOR_TITLE */ | 16; /* MWM_DECOR_MENU */
  196727. motifHints.functions = 4 /* MWM_FUNC_MOVE */;
  196728. if ((styleFlags & windowHasCloseButton) != 0)
  196729. motifHints.functions |= 32; /* MWM_FUNC_CLOSE */
  196730. if ((styleFlags & windowHasMinimiseButton) != 0)
  196731. {
  196732. motifHints.functions |= 8; /* MWM_FUNC_MINIMIZE */
  196733. motifHints.decorations |= 0x20; /* MWM_DECOR_MINIMIZE */
  196734. }
  196735. if ((styleFlags & windowHasMaximiseButton) != 0)
  196736. {
  196737. motifHints.functions |= 0x10; /* MWM_FUNC_MAXIMIZE */
  196738. motifHints.decorations |= 0x40; /* MWM_DECOR_MAXIMIZE */
  196739. }
  196740. if ((styleFlags & windowIsResizable) != 0)
  196741. {
  196742. motifHints.functions |= 2; /* MWM_FUNC_RESIZE */
  196743. motifHints.decorations |= 0x4; /* MWM_DECOR_RESIZEH */
  196744. }
  196745. XChangeProperty (display, wndH, hints, hints, 32, 0, (unsigned char*) &motifHints, 5);
  196746. }
  196747. hints = XInternAtom (display, "_NET_WM_ALLOWED_ACTIONS", True);
  196748. if (hints != None)
  196749. {
  196750. int netHints [6];
  196751. int num = 0;
  196752. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_RESIZE", (styleFlags & windowIsResizable) ? True : False);
  196753. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_FULLSCREEN", (styleFlags & windowHasMaximiseButton) ? True : False);
  196754. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_MINIMIZE", (styleFlags & windowHasMinimiseButton) ? True : False);
  196755. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_CLOSE", (styleFlags & windowHasCloseButton) ? True : False);
  196756. XChangeProperty (display, wndH, hints, XA_ATOM, 32, PropModeReplace,
  196757. (unsigned char*) &netHints, num);
  196758. }
  196759. }
  196760. void setWindowType (Window wndH)
  196761. {
  196762. int netHints [2];
  196763. int numHints = 0;
  196764. if ((styleFlags & windowIsTemporary) != 0
  196765. || ((styleFlags & windowHasDropShadow) == 0 && Desktop::canUseSemiTransparentWindows()))
  196766. {
  196767. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_COMBO", True);
  196768. }
  196769. else
  196770. {
  196771. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_NORMAL", True);
  196772. }
  196773. if (netHints [numHints] != 0)
  196774. ++numHints;
  196775. netHints[numHints] = XInternAtom (display, "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE", True);
  196776. if (netHints [numHints] != 0)
  196777. ++numHints;
  196778. XChangeProperty (display, wndH, Atoms::WindowType, XA_ATOM, 32, PropModeReplace,
  196779. (unsigned char*) &netHints, numHints);
  196780. if ((styleFlags & windowAppearsOnTaskbar) == 0)
  196781. {
  196782. }
  196783. }
  196784. void createWindow()
  196785. {
  196786. ScopedXLock xlock;
  196787. Atoms::initialiseAtoms();
  196788. resetDragAndDrop();
  196789. // Get defaults for various properties
  196790. const int screen = DefaultScreen (display);
  196791. Window root = RootWindow (display, screen);
  196792. // Try to obtain a 32-bit visual or fallback to 24 or 16
  196793. visual = Visuals::findVisualFormat ((styleFlags & windowIsSemiTransparent) ? 32 : 24, depth);
  196794. if (visual == 0)
  196795. {
  196796. Logger::outputDebugString ("ERROR: System doesn't support 32, 24 or 16 bit RGB display.\n");
  196797. Process::terminate();
  196798. }
  196799. // Create and install a colormap suitable fr our visual
  196800. Colormap colormap = XCreateColormap (display, root, visual, AllocNone);
  196801. XInstallColormap (display, colormap);
  196802. // Set up the window attributes
  196803. XSetWindowAttributes swa;
  196804. swa.border_pixel = 0;
  196805. swa.background_pixmap = None;
  196806. swa.colormap = colormap;
  196807. swa.override_redirect = getComponent()->isAlwaysOnTop() ? True : False;
  196808. swa.event_mask = eventMask;
  196809. Window wndH = XCreateWindow (display, root,
  196810. 0, 0, 1, 1,
  196811. 0, depth, InputOutput, visual,
  196812. CWBorderPixel | CWColormap | CWBackPixmap | CWEventMask | CWOverrideRedirect,
  196813. &swa);
  196814. XGrabButton (display, AnyButton, AnyModifier, wndH, False,
  196815. ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
  196816. GrabModeAsync, GrabModeAsync, None, None);
  196817. // Set the window context to identify the window handle object
  196818. if (XSaveContext (display, (XID) wndH, improbableNumber, (XPointer) this))
  196819. {
  196820. // Failed
  196821. jassertfalse
  196822. Logger::outputDebugString ("Failed to create context information for window.\n");
  196823. XDestroyWindow (display, wndH);
  196824. wndH = 0;
  196825. }
  196826. // Set window manager hints
  196827. XWMHints* wmHints = XAllocWMHints();
  196828. wmHints->flags = InputHint | StateHint;
  196829. wmHints->input = True; // Locally active input model
  196830. wmHints->initial_state = NormalState;
  196831. XSetWMHints (display, wndH, wmHints);
  196832. XFree (wmHints);
  196833. // Set the window type
  196834. setWindowType (wndH);
  196835. // Define decoration
  196836. if ((styleFlags & windowHasTitleBar) == 0)
  196837. removeWindowDecorations (wndH);
  196838. else
  196839. addWindowButtons (wndH);
  196840. // Set window name
  196841. setWindowTitle (wndH, getComponent()->getName());
  196842. // Associate the PID, allowing to be shut down when something goes wrong
  196843. unsigned long pid = getpid();
  196844. XChangeProperty (display, wndH, Atoms::Pid, XA_CARDINAL, 32, PropModeReplace,
  196845. (unsigned char*) &pid, 1);
  196846. // Set window manager protocols
  196847. XChangeProperty (display, wndH, Atoms::Protocols, XA_ATOM, 32, PropModeReplace,
  196848. (unsigned char*) Atoms::ProtocolList, 2);
  196849. // Set drag and drop flags
  196850. XChangeProperty (display, wndH, Atoms::XdndTypeList, XA_ATOM, 32, PropModeReplace,
  196851. (const unsigned char*) Atoms::allowedMimeTypes, numElementsInArray (Atoms::allowedMimeTypes));
  196852. XChangeProperty (display, wndH, Atoms::XdndActionList, XA_ATOM, 32, PropModeReplace,
  196853. (const unsigned char*) Atoms::allowedActions, numElementsInArray (Atoms::allowedActions));
  196854. XChangeProperty (display, wndH, Atoms::XdndActionDescription, XA_STRING, 8, PropModeReplace,
  196855. (const unsigned char*) "", 0);
  196856. unsigned long dndVersion = Atoms::DndVersion;
  196857. XChangeProperty (display, wndH, Atoms::XdndAware, XA_ATOM, 32, PropModeReplace,
  196858. (const unsigned char*) &dndVersion, 1);
  196859. // Initialise the pointer and keyboard mapping
  196860. // This is not the same as the logical pointer mapping the X server uses:
  196861. // we don't mess with this.
  196862. static bool mappingInitialised = false;
  196863. if (! mappingInitialised)
  196864. {
  196865. mappingInitialised = true;
  196866. const int numButtons = XGetPointerMapping (display, 0, 0);
  196867. if (numButtons == 2)
  196868. {
  196869. pointerMap[0] = Keys::LeftButton;
  196870. pointerMap[1] = Keys::RightButton;
  196871. pointerMap[2] = pointerMap[3] = pointerMap[4] = Keys::NoButton;
  196872. }
  196873. else if (numButtons >= 3)
  196874. {
  196875. pointerMap[0] = Keys::LeftButton;
  196876. pointerMap[1] = Keys::MiddleButton;
  196877. pointerMap[2] = Keys::RightButton;
  196878. if (numButtons >= 5)
  196879. {
  196880. pointerMap[3] = Keys::WheelUp;
  196881. pointerMap[4] = Keys::WheelDown;
  196882. }
  196883. }
  196884. updateModifierMappings();
  196885. }
  196886. windowH = wndH;
  196887. }
  196888. void destroyWindow()
  196889. {
  196890. ScopedXLock xlock;
  196891. XPointer handlePointer;
  196892. if (! XFindContext (display, (XID) windowH, improbableNumber, &handlePointer))
  196893. XDeleteContext (display, (XID) windowH, improbableNumber);
  196894. XDestroyWindow (display, windowH);
  196895. // Wait for it to complete and then remove any events for this
  196896. // window from the event queue.
  196897. XSync (display, false);
  196898. XEvent event;
  196899. while (XCheckWindowEvent (display, windowH, eventMask, &event) == True)
  196900. {}
  196901. }
  196902. static int64 getEventTime (::Time t)
  196903. {
  196904. static int64 eventTimeOffset = 0x12345678;
  196905. const int64 thisMessageTime = t;
  196906. if (eventTimeOffset == 0x12345678)
  196907. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  196908. return eventTimeOffset + thisMessageTime;
  196909. }
  196910. static void setWindowTitle (Window xwin, const String& title)
  196911. {
  196912. XTextProperty nameProperty;
  196913. char* strings[] = { const_cast <char*> (title.toUTF8()) };
  196914. ScopedXLock xlock;
  196915. if (XStringListToTextProperty (strings, 1, &nameProperty))
  196916. {
  196917. XSetWMName (display, xwin, &nameProperty);
  196918. XSetWMIconName (display, xwin, &nameProperty);
  196919. XFree (nameProperty.value);
  196920. }
  196921. }
  196922. void updateBorderSize()
  196923. {
  196924. if ((styleFlags & windowHasTitleBar) == 0)
  196925. {
  196926. windowBorder = BorderSize (0);
  196927. }
  196928. else if (windowBorder.getTopAndBottom() == 0 && windowBorder.getLeftAndRight() == 0)
  196929. {
  196930. ScopedXLock xlock;
  196931. Atom hints = XInternAtom (display, "_NET_FRAME_EXTENTS", True);
  196932. if (hints != None)
  196933. {
  196934. unsigned char* data = 0;
  196935. unsigned long nitems, bytesLeft;
  196936. Atom actualType;
  196937. int actualFormat;
  196938. if (XGetWindowProperty (display, windowH, hints, 0, 4, False,
  196939. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  196940. &data) == Success)
  196941. {
  196942. const unsigned long* const sizes = (const unsigned long*) data;
  196943. if (actualFormat == 32)
  196944. windowBorder = BorderSize ((int) sizes[2], (int) sizes[0],
  196945. (int) sizes[3], (int) sizes[1]);
  196946. XFree (data);
  196947. }
  196948. }
  196949. }
  196950. }
  196951. void updateBounds()
  196952. {
  196953. jassert (windowH != 0);
  196954. if (windowH != 0)
  196955. {
  196956. Window root, child;
  196957. unsigned int bw, depth;
  196958. ScopedXLock xlock;
  196959. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  196960. &wx, &wy, (unsigned int*) &ww, (unsigned int*) &wh,
  196961. &bw, &depth))
  196962. {
  196963. wx = wy = ww = wh = 0;
  196964. }
  196965. else if (! XTranslateCoordinates (display, windowH, root, 0, 0, &wx, &wy, &child))
  196966. {
  196967. wx = wy = 0;
  196968. }
  196969. }
  196970. }
  196971. void resetDragAndDrop()
  196972. {
  196973. dragAndDropFiles.clear();
  196974. lastDropPos = Point<int> (-1, -1);
  196975. dragAndDropCurrentMimeType = 0;
  196976. dragAndDropSourceWindow = 0;
  196977. srcMimeTypeAtomList.clear();
  196978. }
  196979. void sendDragAndDropMessage (XClientMessageEvent& msg)
  196980. {
  196981. msg.type = ClientMessage;
  196982. msg.display = display;
  196983. msg.window = dragAndDropSourceWindow;
  196984. msg.format = 32;
  196985. msg.data.l[0] = windowH;
  196986. ScopedXLock xlock;
  196987. XSendEvent (display, dragAndDropSourceWindow, False, 0, (XEvent*) &msg);
  196988. }
  196989. void sendDragAndDropStatus (const bool acceptDrop, Atom dropAction)
  196990. {
  196991. XClientMessageEvent msg;
  196992. zerostruct (msg);
  196993. msg.message_type = Atoms::XdndStatus;
  196994. msg.data.l[1] = (acceptDrop ? 1 : 0) | 2; // 2 indicates that we want to receive position messages
  196995. msg.data.l[4] = dropAction;
  196996. sendDragAndDropMessage (msg);
  196997. }
  196998. void sendDragAndDropLeave()
  196999. {
  197000. XClientMessageEvent msg;
  197001. zerostruct (msg);
  197002. msg.message_type = Atoms::XdndLeave;
  197003. sendDragAndDropMessage (msg);
  197004. }
  197005. void sendDragAndDropFinish()
  197006. {
  197007. XClientMessageEvent msg;
  197008. zerostruct (msg);
  197009. msg.message_type = Atoms::XdndFinished;
  197010. sendDragAndDropMessage (msg);
  197011. }
  197012. void handleDragAndDropStatus (const XClientMessageEvent* const clientMsg)
  197013. {
  197014. if ((clientMsg->data.l[1] & 1) == 0)
  197015. {
  197016. sendDragAndDropLeave();
  197017. if (dragAndDropFiles.size() > 0)
  197018. handleFileDragExit (dragAndDropFiles);
  197019. dragAndDropFiles.clear();
  197020. }
  197021. }
  197022. void handleDragAndDropPosition (const XClientMessageEvent* const clientMsg)
  197023. {
  197024. if (dragAndDropSourceWindow == 0)
  197025. return;
  197026. dragAndDropSourceWindow = clientMsg->data.l[0];
  197027. Point<int> dropPos ((int) clientMsg->data.l[2] >> 16,
  197028. (int) clientMsg->data.l[2] & 0xffff);
  197029. dropPos -= getScreenPosition();
  197030. if (lastDropPos != dropPos)
  197031. {
  197032. lastDropPos = dropPos;
  197033. dragAndDropTimestamp = clientMsg->data.l[3];
  197034. Atom targetAction = Atoms::XdndActionCopy;
  197035. for (int i = numElementsInArray (Atoms::allowedActions); --i >= 0;)
  197036. {
  197037. if ((Atom) clientMsg->data.l[4] == Atoms::allowedActions[i])
  197038. {
  197039. targetAction = Atoms::allowedActions[i];
  197040. break;
  197041. }
  197042. }
  197043. sendDragAndDropStatus (true, targetAction);
  197044. if (dragAndDropFiles.size() == 0)
  197045. updateDraggedFileList (clientMsg);
  197046. if (dragAndDropFiles.size() > 0)
  197047. handleFileDragMove (dragAndDropFiles, dropPos);
  197048. }
  197049. }
  197050. void handleDragAndDropDrop (const XClientMessageEvent* const clientMsg)
  197051. {
  197052. if (dragAndDropFiles.size() == 0)
  197053. updateDraggedFileList (clientMsg);
  197054. const StringArray files (dragAndDropFiles);
  197055. const Point<int> lastPos (lastDropPos);
  197056. sendDragAndDropFinish();
  197057. resetDragAndDrop();
  197058. if (files.size() > 0)
  197059. handleFileDragDrop (files, lastPos);
  197060. }
  197061. void handleDragAndDropEnter (const XClientMessageEvent* const clientMsg)
  197062. {
  197063. dragAndDropFiles.clear();
  197064. srcMimeTypeAtomList.clear();
  197065. dragAndDropCurrentMimeType = 0;
  197066. const unsigned long dndCurrentVersion = static_cast <unsigned long> (clientMsg->data.l[1] & 0xff000000) >> 24;
  197067. if (dndCurrentVersion < 3 || dndCurrentVersion > Atoms::DndVersion)
  197068. {
  197069. dragAndDropSourceWindow = 0;
  197070. return;
  197071. }
  197072. dragAndDropSourceWindow = clientMsg->data.l[0];
  197073. if ((clientMsg->data.l[1] & 1) != 0)
  197074. {
  197075. Atom actual;
  197076. int format;
  197077. unsigned long count = 0, remaining = 0;
  197078. unsigned char* data = 0;
  197079. ScopedXLock xlock;
  197080. XGetWindowProperty (display, dragAndDropSourceWindow, Atoms::XdndTypeList,
  197081. 0, 0x8000000L, False, XA_ATOM, &actual, &format,
  197082. &count, &remaining, &data);
  197083. if (data != 0)
  197084. {
  197085. if (actual == XA_ATOM && format == 32 && count != 0)
  197086. {
  197087. const unsigned long* const types = (const unsigned long*) data;
  197088. for (unsigned int i = 0; i < count; ++i)
  197089. if (types[i] != None)
  197090. srcMimeTypeAtomList.add (types[i]);
  197091. }
  197092. XFree (data);
  197093. }
  197094. }
  197095. if (srcMimeTypeAtomList.size() == 0)
  197096. {
  197097. for (int i = 2; i < 5; ++i)
  197098. if (clientMsg->data.l[i] != None)
  197099. srcMimeTypeAtomList.add (clientMsg->data.l[i]);
  197100. if (srcMimeTypeAtomList.size() == 0)
  197101. {
  197102. dragAndDropSourceWindow = 0;
  197103. return;
  197104. }
  197105. }
  197106. for (int i = 0; i < srcMimeTypeAtomList.size() && dragAndDropCurrentMimeType == 0; ++i)
  197107. for (int j = 0; j < numElementsInArray (Atoms::allowedMimeTypes); ++j)
  197108. if (srcMimeTypeAtomList[i] == Atoms::allowedMimeTypes[j])
  197109. dragAndDropCurrentMimeType = Atoms::allowedMimeTypes[j];
  197110. handleDragAndDropPosition (clientMsg);
  197111. }
  197112. void handleDragAndDropSelection (const XEvent* const evt)
  197113. {
  197114. dragAndDropFiles.clear();
  197115. if (evt->xselection.property != 0)
  197116. {
  197117. StringArray lines;
  197118. {
  197119. MemoryBlock dropData;
  197120. for (;;)
  197121. {
  197122. Atom actual;
  197123. uint8* data = 0;
  197124. unsigned long count = 0, remaining = 0;
  197125. int format = 0;
  197126. ScopedXLock xlock;
  197127. if (XGetWindowProperty (display, evt->xany.window, evt->xselection.property,
  197128. dropData.getSize() / 4, 65536, 1, AnyPropertyType, &actual,
  197129. &format, &count, &remaining, &data) == Success)
  197130. {
  197131. dropData.append (data, count * format / 8);
  197132. XFree (data);
  197133. if (remaining == 0)
  197134. break;
  197135. }
  197136. else
  197137. {
  197138. XFree (data);
  197139. break;
  197140. }
  197141. }
  197142. lines.addLines (dropData.toString());
  197143. }
  197144. for (int i = 0; i < lines.size(); ++i)
  197145. dragAndDropFiles.add (URL::removeEscapeChars (lines[i].fromFirstOccurrenceOf (T("file://"), false, true)));
  197146. dragAndDropFiles.trim();
  197147. dragAndDropFiles.removeEmptyStrings();
  197148. }
  197149. }
  197150. void updateDraggedFileList (const XClientMessageEvent* const clientMsg)
  197151. {
  197152. dragAndDropFiles.clear();
  197153. if (dragAndDropSourceWindow != None
  197154. && dragAndDropCurrentMimeType != 0)
  197155. {
  197156. dragAndDropTimestamp = clientMsg->data.l[2];
  197157. ScopedXLock xlock;
  197158. XConvertSelection (display,
  197159. Atoms::XdndSelection,
  197160. dragAndDropCurrentMimeType,
  197161. XInternAtom (display, "JXSelectionWindowProperty", 0),
  197162. windowH,
  197163. dragAndDropTimestamp);
  197164. }
  197165. }
  197166. StringArray dragAndDropFiles;
  197167. int dragAndDropTimestamp;
  197168. Point<int> lastDropPos;
  197169. Atom dragAndDropCurrentMimeType;
  197170. Window dragAndDropSourceWindow;
  197171. Array <Atom> srcMimeTypeAtomList;
  197172. static int pointerMap[5];
  197173. static Point<int> lastMousePos;
  197174. static void clearLastMousePos() throw()
  197175. {
  197176. lastMousePos = Point<int> (0x100000, 0x100000);
  197177. }
  197178. };
  197179. ModifierKeys LinuxComponentPeer::currentModifiers;
  197180. int LinuxComponentPeer::pointerMap[5];
  197181. Point<int> LinuxComponentPeer::lastMousePos;
  197182. void ModifierKeys::updateCurrentModifiers() throw()
  197183. {
  197184. currentModifiers = LinuxComponentPeer::currentModifiers;
  197185. }
  197186. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  197187. {
  197188. Window root, child;
  197189. int x, y, winx, winy;
  197190. unsigned int mask;
  197191. int mouseMods = 0;
  197192. ScopedXLock xlock;
  197193. if (XQueryPointer (display, RootWindow (display, DefaultScreen (display)),
  197194. &root, &child, &x, &y, &winx, &winy, &mask) != False)
  197195. {
  197196. if ((mask & Button1Mask) != 0) mouseMods |= ModifierKeys::leftButtonModifier;
  197197. if ((mask & Button2Mask) != 0) mouseMods |= ModifierKeys::middleButtonModifier;
  197198. if ((mask & Button3Mask) != 0) mouseMods |= ModifierKeys::rightButtonModifier;
  197199. }
  197200. LinuxComponentPeer::currentModifiers = LinuxComponentPeer::currentModifiers.withoutMouseButtons().withFlags (mouseMods);
  197201. return LinuxComponentPeer::currentModifiers;
  197202. }
  197203. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  197204. {
  197205. if (enableOrDisable)
  197206. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  197207. }
  197208. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  197209. {
  197210. return new LinuxComponentPeer (this, styleFlags);
  197211. }
  197212. // (this callback is hooked up in the messaging code)
  197213. void juce_windowMessageReceive (XEvent* event)
  197214. {
  197215. if (event->xany.window != None)
  197216. {
  197217. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (event->xany.window);
  197218. if (ComponentPeer::isValidPeer (peer))
  197219. peer->handleWindowMessage (event);
  197220. }
  197221. else
  197222. {
  197223. switch (event->xany.type)
  197224. {
  197225. case KeymapNotify:
  197226. {
  197227. const XKeymapEvent* const keymapEvent = (const XKeymapEvent*) &event->xkeymap;
  197228. memcpy (Keys::keyStates, keymapEvent->key_vector, 32);
  197229. break;
  197230. }
  197231. default:
  197232. break;
  197233. }
  197234. }
  197235. }
  197236. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool /*clipToWorkArea*/)
  197237. {
  197238. if (display == 0)
  197239. return;
  197240. #if JUCE_USE_XINERAMA
  197241. int major_opcode, first_event, first_error;
  197242. ScopedXLock xlock;
  197243. if (XQueryExtension (display, "XINERAMA", &major_opcode, &first_event, &first_error))
  197244. {
  197245. typedef Bool (*tXineramaIsActive) (Display*);
  197246. typedef XineramaScreenInfo* (*tXineramaQueryScreens) (Display*, int*);
  197247. static tXineramaIsActive xXineramaIsActive = 0;
  197248. static tXineramaQueryScreens xXineramaQueryScreens = 0;
  197249. if (xXineramaIsActive == 0 || xXineramaQueryScreens == 0)
  197250. {
  197251. void* h = dlopen ("libXinerama.so", RTLD_GLOBAL | RTLD_NOW);
  197252. if (h != 0)
  197253. {
  197254. xXineramaIsActive = (tXineramaIsActive) dlsym (h, "XineramaIsActive");
  197255. xXineramaQueryScreens = (tXineramaQueryScreens) dlsym (h, "XineramaQueryScreens");
  197256. }
  197257. }
  197258. if (xXineramaIsActive != 0
  197259. && xXineramaQueryScreens != 0
  197260. && xXineramaIsActive (display))
  197261. {
  197262. int numMonitors = 0;
  197263. XineramaScreenInfo* const screens = xXineramaQueryScreens (display, &numMonitors);
  197264. if (screens != 0)
  197265. {
  197266. for (int i = numMonitors; --i >= 0;)
  197267. {
  197268. int index = screens[i].screen_number;
  197269. if (index >= 0)
  197270. {
  197271. while (monitorCoords.size() < index)
  197272. monitorCoords.add (Rectangle<int>());
  197273. monitorCoords.set (index, Rectangle<int> (screens[i].x_org,
  197274. screens[i].y_org,
  197275. screens[i].width,
  197276. screens[i].height));
  197277. }
  197278. }
  197279. XFree (screens);
  197280. }
  197281. }
  197282. }
  197283. if (monitorCoords.size() == 0)
  197284. #endif
  197285. {
  197286. Atom hints = XInternAtom (display, "_NET_WORKAREA", True);
  197287. if (hints != None)
  197288. {
  197289. const int numMonitors = ScreenCount (display);
  197290. for (int i = 0; i < numMonitors; ++i)
  197291. {
  197292. Window root = RootWindow (display, i);
  197293. unsigned long nitems, bytesLeft;
  197294. Atom actualType;
  197295. int actualFormat;
  197296. unsigned char* data = 0;
  197297. if (XGetWindowProperty (display, root, hints, 0, 4, False,
  197298. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197299. &data) == Success)
  197300. {
  197301. const long* const position = (const long*) data;
  197302. if (actualType == XA_CARDINAL && actualFormat == 32 && nitems == 4)
  197303. monitorCoords.add (Rectangle<int> (position[0], position[1],
  197304. position[2], position[3]));
  197305. XFree (data);
  197306. }
  197307. }
  197308. }
  197309. if (monitorCoords.size() == 0)
  197310. {
  197311. monitorCoords.add (Rectangle<int> (0, 0,
  197312. DisplayWidth (display, DefaultScreen (display)),
  197313. DisplayHeight (display, DefaultScreen (display))));
  197314. }
  197315. }
  197316. }
  197317. void Desktop::createMouseInputSources()
  197318. {
  197319. mouseSources.add (new MouseInputSource (0, true));
  197320. }
  197321. bool Desktop::canUseSemiTransparentWindows() throw()
  197322. {
  197323. int matchedDepth = 0;
  197324. const int desiredDepth = 32;
  197325. return Visuals::findVisualFormat (desiredDepth, matchedDepth) != 0
  197326. && (matchedDepth == desiredDepth);
  197327. }
  197328. const Point<int> Desktop::getMousePosition()
  197329. {
  197330. Window root, child;
  197331. int x, y, winx, winy;
  197332. unsigned int mask;
  197333. ScopedXLock xlock;
  197334. if (XQueryPointer (display,
  197335. RootWindow (display, DefaultScreen (display)),
  197336. &root, &child,
  197337. &x, &y, &winx, &winy, &mask) == False)
  197338. {
  197339. // Pointer not on the default screen
  197340. x = y = -1;
  197341. }
  197342. return Point<int> (x, y);
  197343. }
  197344. void Desktop::setMousePosition (const Point<int>& newPosition)
  197345. {
  197346. ScopedXLock xlock;
  197347. Window root = RootWindow (display, DefaultScreen (display));
  197348. XWarpPointer (display, None, root, 0, 0, 0, 0, newPosition.getX(), newPosition.getY());
  197349. }
  197350. static bool screenSaverAllowed = true;
  197351. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  197352. {
  197353. if (screenSaverAllowed != isEnabled)
  197354. {
  197355. screenSaverAllowed = isEnabled;
  197356. typedef void (*tXScreenSaverSuspend) (Display*, Bool);
  197357. static tXScreenSaverSuspend xScreenSaverSuspend = 0;
  197358. if (xScreenSaverSuspend == 0)
  197359. {
  197360. void* h = dlopen ("libXss.so", RTLD_GLOBAL | RTLD_NOW);
  197361. if (h != 0)
  197362. xScreenSaverSuspend = (tXScreenSaverSuspend) dlsym (h, "XScreenSaverSuspend");
  197363. }
  197364. ScopedXLock xlock;
  197365. if (xScreenSaverSuspend != 0)
  197366. xScreenSaverSuspend (display, ! isEnabled);
  197367. }
  197368. }
  197369. bool Desktop::isScreenSaverEnabled() throw()
  197370. {
  197371. return screenSaverAllowed;
  197372. }
  197373. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  197374. {
  197375. ScopedXLock xlock;
  197376. Window root = RootWindow (display, DefaultScreen (display));
  197377. const unsigned int imageW = image.getWidth();
  197378. const unsigned int imageH = image.getHeight();
  197379. unsigned int cursorW, cursorH;
  197380. if (! XQueryBestCursor (display, root, imageW, imageH, &cursorW, &cursorH))
  197381. return 0;
  197382. Image im (Image::ARGB, cursorW, cursorH, true);
  197383. Graphics g (im);
  197384. if (imageW > cursorW || imageH > cursorH)
  197385. {
  197386. hotspotX = (hotspotX * cursorW) / imageW;
  197387. hotspotY = (hotspotY * cursorH) / imageH;
  197388. g.drawImageWithin (&image, 0, 0, imageW, imageH,
  197389. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  197390. false);
  197391. }
  197392. else
  197393. {
  197394. g.drawImageAt (&image, 0, 0);
  197395. }
  197396. const int stride = (cursorW + 7) >> 3;
  197397. HeapBlock <uint8> maskPlane, sourcePlane;
  197398. maskPlane.calloc (stride * cursorH);
  197399. sourcePlane.calloc (stride * cursorH);
  197400. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  197401. for (int y = cursorH; --y >= 0;)
  197402. {
  197403. for (int x = cursorW; --x >= 0;)
  197404. {
  197405. const uint8 mask = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  197406. const int offset = y * stride + (x >> 3);
  197407. const Colour c (im.getPixelAt (x, y));
  197408. if (c.getAlpha() >= 128)
  197409. maskPlane[offset] |= mask;
  197410. if (c.getBrightness() >= 0.5f)
  197411. sourcePlane[offset] |= mask;
  197412. }
  197413. }
  197414. Pixmap sourcePixmap = XCreatePixmapFromBitmapData (display, root, reinterpret_cast <char*> (sourcePlane.getData()), cursorW, cursorH, 0xffff, 0, 1);
  197415. Pixmap maskPixmap = XCreatePixmapFromBitmapData (display, root, reinterpret_cast <char*> (maskPlane.getData()), cursorW, cursorH, 0xffff, 0, 1);
  197416. XColor white, black;
  197417. black.red = black.green = black.blue = 0;
  197418. white.red = white.green = white.blue = 0xffff;
  197419. void* result = (void*) XCreatePixmapCursor (display, sourcePixmap, maskPixmap, &white, &black, hotspotX, hotspotY);
  197420. XFreePixmap (display, sourcePixmap);
  197421. XFreePixmap (display, maskPixmap);
  197422. return result;
  197423. }
  197424. void juce_deleteMouseCursor (void* const cursorHandle, const bool) throw()
  197425. {
  197426. ScopedXLock xlock;
  197427. if (cursorHandle != None)
  197428. XFreeCursor (display, (Cursor) cursorHandle);
  197429. }
  197430. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  197431. {
  197432. unsigned int shape;
  197433. switch (type)
  197434. {
  197435. case MouseCursor::NoCursor:
  197436. {
  197437. const Image im (Image::ARGB, 16, 16, true);
  197438. return juce_createMouseCursorFromImage (im, 0, 0);
  197439. }
  197440. case MouseCursor::NormalCursor:
  197441. return (void*) None; // Use parent cursor
  197442. case MouseCursor::DraggingHandCursor:
  197443. {
  197444. static unsigned char dragHandData[] = {71,73,70,56,57,97,16,0,16,0,145,2,0,0,0,0,255,255,255,0,
  197445. 0,0,0,0,0,33,249,4,1,0,0,2,0,44,0,0,0,0,16,0,
  197446. 16,0,0,2,52,148,47,0,200,185,16,130,90,12,74,139,107,84,123,39,
  197447. 132,117,151,116,132,146,248,60,209,138,98,22,203,114,34,236,37,52,77,217,
  197448. 247,154,191,119,110,240,193,128,193,95,163,56,60,234,98,135,2,0,59 };
  197449. const int dragHandDataSize = 99;
  197450. const ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) dragHandData, dragHandDataSize));
  197451. return juce_createMouseCursorFromImage (*im, 8, 7);
  197452. }
  197453. case MouseCursor::CopyingCursor:
  197454. {
  197455. static unsigned char copyCursorData[] = {71,73,70,56,57,97,21,0,21,0,145,0,0,0,0,0,255,255,255,0,
  197456. 128,128,255,255,255,33,249,4,1,0,0,3,0,44,0,0,0,0,21,0,
  197457. 21,0,0,2,72,4,134,169,171,16,199,98,11,79,90,71,161,93,56,111,
  197458. 78,133,218,215,137,31,82,154,100,200,86,91,202,142,12,108,212,87,235,174,
  197459. 15,54,214,126,237,226,37,96,59,141,16,37,18,201,142,157,230,204,51,112,
  197460. 252,114,147,74,83,5,50,68,147,208,217,16,71,149,252,124,5,0,59,0,0 };
  197461. const int copyCursorSize = 119;
  197462. const ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) copyCursorData, copyCursorSize));
  197463. return juce_createMouseCursorFromImage (*im, 1, 3);
  197464. }
  197465. case MouseCursor::WaitCursor:
  197466. shape = XC_watch;
  197467. break;
  197468. case MouseCursor::IBeamCursor:
  197469. shape = XC_xterm;
  197470. break;
  197471. case MouseCursor::PointingHandCursor:
  197472. shape = XC_hand2;
  197473. break;
  197474. case MouseCursor::LeftRightResizeCursor:
  197475. shape = XC_sb_h_double_arrow;
  197476. break;
  197477. case MouseCursor::UpDownResizeCursor:
  197478. shape = XC_sb_v_double_arrow;
  197479. break;
  197480. case MouseCursor::UpDownLeftRightResizeCursor:
  197481. shape = XC_fleur;
  197482. break;
  197483. case MouseCursor::TopEdgeResizeCursor:
  197484. shape = XC_top_side;
  197485. break;
  197486. case MouseCursor::BottomEdgeResizeCursor:
  197487. shape = XC_bottom_side;
  197488. break;
  197489. case MouseCursor::LeftEdgeResizeCursor:
  197490. shape = XC_left_side;
  197491. break;
  197492. case MouseCursor::RightEdgeResizeCursor:
  197493. shape = XC_right_side;
  197494. break;
  197495. case MouseCursor::TopLeftCornerResizeCursor:
  197496. shape = XC_top_left_corner;
  197497. break;
  197498. case MouseCursor::TopRightCornerResizeCursor:
  197499. shape = XC_top_right_corner;
  197500. break;
  197501. case MouseCursor::BottomLeftCornerResizeCursor:
  197502. shape = XC_bottom_left_corner;
  197503. break;
  197504. case MouseCursor::BottomRightCornerResizeCursor:
  197505. shape = XC_bottom_right_corner;
  197506. break;
  197507. case MouseCursor::CrosshairCursor:
  197508. shape = XC_crosshair;
  197509. break;
  197510. default:
  197511. return (void*) None; // Use parent cursor
  197512. }
  197513. ScopedXLock xlock;
  197514. return (void*) XCreateFontCursor (display, shape);
  197515. }
  197516. void MouseCursor::showInWindow (ComponentPeer* peer) const throw()
  197517. {
  197518. LinuxComponentPeer* const lp = dynamic_cast <LinuxComponentPeer*> (peer);
  197519. if (lp != 0)
  197520. lp->showMouseCursor ((Cursor) getHandle());
  197521. }
  197522. void MouseCursor::showInAllWindows() const throw()
  197523. {
  197524. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  197525. showInWindow (ComponentPeer::getPeer (i));
  197526. }
  197527. Image* juce_createIconForFile (const File& file)
  197528. {
  197529. return 0;
  197530. }
  197531. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  197532. {
  197533. return new Image (format, imageWidth, imageHeight, clearImage);
  197534. }
  197535. #if JUCE_OPENGL
  197536. class WindowedGLContext : public OpenGLContext
  197537. {
  197538. public:
  197539. WindowedGLContext (Component* const component,
  197540. const OpenGLPixelFormat& pixelFormat_,
  197541. GLXContext sharedContext)
  197542. : renderContext (0),
  197543. embeddedWindow (0),
  197544. pixelFormat (pixelFormat_)
  197545. {
  197546. jassert (component != 0);
  197547. LinuxComponentPeer* const peer = dynamic_cast <LinuxComponentPeer*> (component->getTopLevelComponent()->getPeer());
  197548. if (peer == 0)
  197549. return;
  197550. ScopedXLock xlock;
  197551. XSync (display, False);
  197552. GLint attribs [64];
  197553. int n = 0;
  197554. attribs[n++] = GLX_RGBA;
  197555. attribs[n++] = GLX_DOUBLEBUFFER;
  197556. attribs[n++] = GLX_RED_SIZE;
  197557. attribs[n++] = pixelFormat.redBits;
  197558. attribs[n++] = GLX_GREEN_SIZE;
  197559. attribs[n++] = pixelFormat.greenBits;
  197560. attribs[n++] = GLX_BLUE_SIZE;
  197561. attribs[n++] = pixelFormat.blueBits;
  197562. attribs[n++] = GLX_ALPHA_SIZE;
  197563. attribs[n++] = pixelFormat.alphaBits;
  197564. attribs[n++] = GLX_DEPTH_SIZE;
  197565. attribs[n++] = pixelFormat.depthBufferBits;
  197566. attribs[n++] = GLX_STENCIL_SIZE;
  197567. attribs[n++] = pixelFormat.stencilBufferBits;
  197568. attribs[n++] = GLX_ACCUM_RED_SIZE;
  197569. attribs[n++] = pixelFormat.accumulationBufferRedBits;
  197570. attribs[n++] = GLX_ACCUM_GREEN_SIZE;
  197571. attribs[n++] = pixelFormat.accumulationBufferGreenBits;
  197572. attribs[n++] = GLX_ACCUM_BLUE_SIZE;
  197573. attribs[n++] = pixelFormat.accumulationBufferBlueBits;
  197574. attribs[n++] = GLX_ACCUM_ALPHA_SIZE;
  197575. attribs[n++] = pixelFormat.accumulationBufferAlphaBits;
  197576. // xxx not sure how to do fullSceneAntiAliasingNumSamples on linux..
  197577. attribs[n++] = None;
  197578. XVisualInfo* const bestVisual = glXChooseVisual (display, DefaultScreen (display), attribs);
  197579. if (bestVisual == 0)
  197580. return;
  197581. renderContext = glXCreateContext (display, bestVisual, sharedContext, GL_TRUE);
  197582. Window windowH = (Window) peer->getNativeHandle();
  197583. Colormap colourMap = XCreateColormap (display, windowH, bestVisual->visual, AllocNone);
  197584. XSetWindowAttributes swa;
  197585. swa.colormap = colourMap;
  197586. swa.border_pixel = 0;
  197587. swa.event_mask = ExposureMask | StructureNotifyMask;
  197588. embeddedWindow = XCreateWindow (display, windowH,
  197589. 0, 0, 1, 1, 0,
  197590. bestVisual->depth,
  197591. InputOutput,
  197592. bestVisual->visual,
  197593. CWBorderPixel | CWColormap | CWEventMask,
  197594. &swa);
  197595. XSaveContext (display, (XID) embeddedWindow, improbableNumber, (XPointer) peer);
  197596. XMapWindow (display, embeddedWindow);
  197597. XFreeColormap (display, colourMap);
  197598. XFree (bestVisual);
  197599. XSync (display, False);
  197600. }
  197601. ~WindowedGLContext()
  197602. {
  197603. makeInactive();
  197604. ScopedXLock xlock;
  197605. glXDestroyContext (display, renderContext);
  197606. XUnmapWindow (display, embeddedWindow);
  197607. XDestroyWindow (display, embeddedWindow);
  197608. }
  197609. bool makeActive() const throw()
  197610. {
  197611. jassert (renderContext != 0);
  197612. ScopedXLock xlock;
  197613. return glXMakeCurrent (display, embeddedWindow, renderContext)
  197614. && XSync (display, False);
  197615. }
  197616. bool makeInactive() const throw()
  197617. {
  197618. ScopedXLock xlock;
  197619. return (! isActive()) || glXMakeCurrent (display, None, 0);
  197620. }
  197621. bool isActive() const throw()
  197622. {
  197623. ScopedXLock xlock;
  197624. return glXGetCurrentContext() == renderContext;
  197625. }
  197626. const OpenGLPixelFormat getPixelFormat() const
  197627. {
  197628. return pixelFormat;
  197629. }
  197630. void* getRawContext() const throw()
  197631. {
  197632. return renderContext;
  197633. }
  197634. void updateWindowPosition (int x, int y, int w, int h, int)
  197635. {
  197636. ScopedXLock xlock;
  197637. XMoveResizeWindow (display, embeddedWindow,
  197638. x, y, jmax (1, w), jmax (1, h));
  197639. }
  197640. void swapBuffers()
  197641. {
  197642. ScopedXLock xlock;
  197643. glXSwapBuffers (display, embeddedWindow);
  197644. }
  197645. bool setSwapInterval (const int numFramesPerSwap)
  197646. {
  197647. // xxx needs doing..
  197648. return false;
  197649. }
  197650. int getSwapInterval() const
  197651. {
  197652. // xxx needs doing..
  197653. return 0;
  197654. }
  197655. void repaint()
  197656. {
  197657. }
  197658. juce_UseDebuggingNewOperator
  197659. GLXContext renderContext;
  197660. private:
  197661. Window embeddedWindow;
  197662. OpenGLPixelFormat pixelFormat;
  197663. WindowedGLContext (const WindowedGLContext&);
  197664. WindowedGLContext& operator= (const WindowedGLContext&);
  197665. };
  197666. OpenGLContext* OpenGLComponent::createContext()
  197667. {
  197668. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this, preferredPixelFormat,
  197669. contextToShareListsWith != 0 ? (GLXContext) contextToShareListsWith->getRawContext() : 0));
  197670. return (c->renderContext != 0) ? c.release() : 0;
  197671. }
  197672. void juce_glViewport (const int w, const int h)
  197673. {
  197674. glViewport (0, 0, w, h);
  197675. }
  197676. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  197677. OwnedArray <OpenGLPixelFormat>& results)
  197678. {
  197679. results.add (new OpenGLPixelFormat()); // xxx
  197680. }
  197681. #endif
  197682. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  197683. {
  197684. jassertfalse // not implemented!
  197685. return false;
  197686. }
  197687. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  197688. {
  197689. jassertfalse // not implemented!
  197690. return false;
  197691. }
  197692. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  197693. {
  197694. if (! isOnDesktop ())
  197695. addToDesktop (0);
  197696. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  197697. if (wp != 0)
  197698. {
  197699. wp->setTaskBarIcon (newImage);
  197700. setVisible (true);
  197701. toFront (false);
  197702. repaint();
  197703. }
  197704. }
  197705. void SystemTrayIconComponent::paint (Graphics& g)
  197706. {
  197707. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  197708. if (wp != 0)
  197709. {
  197710. const Image* const image = wp->getTaskbarIcon();
  197711. if (image != 0)
  197712. {
  197713. g.drawImageWithin (image, 0, 0, getWidth(), getHeight(),
  197714. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  197715. false);
  197716. }
  197717. }
  197718. }
  197719. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  197720. {
  197721. // xxx not yet implemented!
  197722. }
  197723. void PlatformUtilities::beep()
  197724. {
  197725. std::cout << "\a" << std::flush;
  197726. }
  197727. bool AlertWindow::showNativeDialogBox (const String& title,
  197728. const String& bodyText,
  197729. bool isOkCancel)
  197730. {
  197731. // use a non-native one for the time being..
  197732. if (isOkCancel)
  197733. return AlertWindow::showOkCancelBox (AlertWindow::NoIcon, title, bodyText);
  197734. else
  197735. AlertWindow::showMessageBox (AlertWindow::NoIcon, title, bodyText);
  197736. return true;
  197737. }
  197738. const int KeyPress::spaceKey = XK_space & 0xff;
  197739. const int KeyPress::returnKey = XK_Return & 0xff;
  197740. const int KeyPress::escapeKey = XK_Escape & 0xff;
  197741. const int KeyPress::backspaceKey = XK_BackSpace & 0xff;
  197742. const int KeyPress::leftKey = (XK_Left & 0xff) | Keys::extendedKeyModifier;
  197743. const int KeyPress::rightKey = (XK_Right & 0xff) | Keys::extendedKeyModifier;
  197744. const int KeyPress::upKey = (XK_Up & 0xff) | Keys::extendedKeyModifier;
  197745. const int KeyPress::downKey = (XK_Down & 0xff) | Keys::extendedKeyModifier;
  197746. const int KeyPress::pageUpKey = (XK_Page_Up & 0xff) | Keys::extendedKeyModifier;
  197747. const int KeyPress::pageDownKey = (XK_Page_Down & 0xff) | Keys::extendedKeyModifier;
  197748. const int KeyPress::endKey = (XK_End & 0xff) | Keys::extendedKeyModifier;
  197749. const int KeyPress::homeKey = (XK_Home & 0xff) | Keys::extendedKeyModifier;
  197750. const int KeyPress::insertKey = (XK_Insert & 0xff) | Keys::extendedKeyModifier;
  197751. const int KeyPress::deleteKey = (XK_Delete & 0xff) | Keys::extendedKeyModifier;
  197752. const int KeyPress::tabKey = XK_Tab & 0xff;
  197753. const int KeyPress::F1Key = (XK_F1 & 0xff) | Keys::extendedKeyModifier;
  197754. const int KeyPress::F2Key = (XK_F2 & 0xff) | Keys::extendedKeyModifier;
  197755. const int KeyPress::F3Key = (XK_F3 & 0xff) | Keys::extendedKeyModifier;
  197756. const int KeyPress::F4Key = (XK_F4 & 0xff) | Keys::extendedKeyModifier;
  197757. const int KeyPress::F5Key = (XK_F5 & 0xff) | Keys::extendedKeyModifier;
  197758. const int KeyPress::F6Key = (XK_F6 & 0xff) | Keys::extendedKeyModifier;
  197759. const int KeyPress::F7Key = (XK_F7 & 0xff) | Keys::extendedKeyModifier;
  197760. const int KeyPress::F8Key = (XK_F8 & 0xff) | Keys::extendedKeyModifier;
  197761. const int KeyPress::F9Key = (XK_F9 & 0xff) | Keys::extendedKeyModifier;
  197762. const int KeyPress::F10Key = (XK_F10 & 0xff) | Keys::extendedKeyModifier;
  197763. const int KeyPress::F11Key = (XK_F11 & 0xff) | Keys::extendedKeyModifier;
  197764. const int KeyPress::F12Key = (XK_F12 & 0xff) | Keys::extendedKeyModifier;
  197765. const int KeyPress::F13Key = (XK_F13 & 0xff) | Keys::extendedKeyModifier;
  197766. const int KeyPress::F14Key = (XK_F14 & 0xff) | Keys::extendedKeyModifier;
  197767. const int KeyPress::F15Key = (XK_F15 & 0xff) | Keys::extendedKeyModifier;
  197768. const int KeyPress::F16Key = (XK_F16 & 0xff) | Keys::extendedKeyModifier;
  197769. const int KeyPress::numberPad0 = (XK_KP_0 & 0xff) | Keys::extendedKeyModifier;
  197770. const int KeyPress::numberPad1 = (XK_KP_1 & 0xff) | Keys::extendedKeyModifier;
  197771. const int KeyPress::numberPad2 = (XK_KP_2 & 0xff) | Keys::extendedKeyModifier;
  197772. const int KeyPress::numberPad3 = (XK_KP_3 & 0xff) | Keys::extendedKeyModifier;
  197773. const int KeyPress::numberPad4 = (XK_KP_4 & 0xff) | Keys::extendedKeyModifier;
  197774. const int KeyPress::numberPad5 = (XK_KP_5 & 0xff) | Keys::extendedKeyModifier;
  197775. const int KeyPress::numberPad6 = (XK_KP_6 & 0xff) | Keys::extendedKeyModifier;
  197776. const int KeyPress::numberPad7 = (XK_KP_7 & 0xff)| Keys::extendedKeyModifier;
  197777. const int KeyPress::numberPad8 = (XK_KP_8 & 0xff)| Keys::extendedKeyModifier;
  197778. const int KeyPress::numberPad9 = (XK_KP_9 & 0xff)| Keys::extendedKeyModifier;
  197779. const int KeyPress::numberPadAdd = (XK_KP_Add & 0xff)| Keys::extendedKeyModifier;
  197780. const int KeyPress::numberPadSubtract = (XK_KP_Subtract & 0xff)| Keys::extendedKeyModifier;
  197781. const int KeyPress::numberPadMultiply = (XK_KP_Multiply & 0xff)| Keys::extendedKeyModifier;
  197782. const int KeyPress::numberPadDivide = (XK_KP_Divide & 0xff)| Keys::extendedKeyModifier;
  197783. const int KeyPress::numberPadSeparator = (XK_KP_Separator & 0xff)| Keys::extendedKeyModifier;
  197784. const int KeyPress::numberPadDecimalPoint = (XK_KP_Decimal & 0xff)| Keys::extendedKeyModifier;
  197785. const int KeyPress::numberPadEquals = (XK_KP_Equal & 0xff)| Keys::extendedKeyModifier;
  197786. const int KeyPress::numberPadDelete = (XK_KP_Delete & 0xff)| Keys::extendedKeyModifier;
  197787. const int KeyPress::playKey = (0xffeeff00) | Keys::extendedKeyModifier;
  197788. const int KeyPress::stopKey = (0xffeeff01) | Keys::extendedKeyModifier;
  197789. const int KeyPress::fastForwardKey = (0xffeeff02) | Keys::extendedKeyModifier;
  197790. const int KeyPress::rewindKey = (0xffeeff03) | Keys::extendedKeyModifier;
  197791. #endif
  197792. /*** End of inlined file: juce_linux_Windowing.cpp ***/
  197793. /*** Start of inlined file: juce_linux_Audio.cpp ***/
  197794. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  197795. // compiled on its own).
  197796. #if JUCE_INCLUDED_FILE && JUCE_ALSA
  197797. static const int maxNumChans = 64;
  197798. static void getDeviceSampleRates (snd_pcm_t* handle, Array <int>& rates)
  197799. {
  197800. const int ratesToTry[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  197801. snd_pcm_hw_params_t* hwParams;
  197802. snd_pcm_hw_params_alloca (&hwParams);
  197803. for (int i = 0; ratesToTry[i] != 0; ++i)
  197804. {
  197805. if (snd_pcm_hw_params_any (handle, hwParams) >= 0
  197806. && snd_pcm_hw_params_test_rate (handle, hwParams, ratesToTry[i], 0) == 0)
  197807. {
  197808. rates.addIfNotAlreadyThere (ratesToTry[i]);
  197809. }
  197810. }
  197811. }
  197812. static void getDeviceNumChannels (snd_pcm_t* handle, unsigned int* minChans, unsigned int* maxChans)
  197813. {
  197814. snd_pcm_hw_params_t *params;
  197815. snd_pcm_hw_params_alloca (&params);
  197816. if (snd_pcm_hw_params_any (handle, params) >= 0)
  197817. {
  197818. snd_pcm_hw_params_get_channels_min (params, minChans);
  197819. snd_pcm_hw_params_get_channels_max (params, maxChans);
  197820. }
  197821. }
  197822. static void getDeviceProperties (const String& deviceID,
  197823. unsigned int& minChansOut,
  197824. unsigned int& maxChansOut,
  197825. unsigned int& minChansIn,
  197826. unsigned int& maxChansIn,
  197827. Array <int>& rates)
  197828. {
  197829. if (deviceID.isEmpty())
  197830. return;
  197831. snd_ctl_t* handle;
  197832. if (snd_ctl_open (&handle, deviceID.upToLastOccurrenceOf (T(","), false, false).toUTF8(), SND_CTL_NONBLOCK) >= 0)
  197833. {
  197834. snd_pcm_info_t* info;
  197835. snd_pcm_info_alloca (&info);
  197836. snd_pcm_info_set_stream (info, SND_PCM_STREAM_PLAYBACK);
  197837. snd_pcm_info_set_device (info, deviceID.fromLastOccurrenceOf (T(","), false, false).getIntValue());
  197838. snd_pcm_info_set_subdevice (info, 0);
  197839. if (snd_ctl_pcm_info (handle, info) >= 0)
  197840. {
  197841. snd_pcm_t* pcmHandle;
  197842. if (snd_pcm_open (&pcmHandle, deviceID.toUTF8(), SND_PCM_STREAM_PLAYBACK, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  197843. {
  197844. getDeviceNumChannels (pcmHandle, &minChansOut, &maxChansOut);
  197845. getDeviceSampleRates (pcmHandle, rates);
  197846. snd_pcm_close (pcmHandle);
  197847. }
  197848. }
  197849. snd_pcm_info_set_stream (info, SND_PCM_STREAM_CAPTURE);
  197850. if (snd_ctl_pcm_info (handle, info) >= 0)
  197851. {
  197852. snd_pcm_t* pcmHandle;
  197853. if (snd_pcm_open (&pcmHandle, deviceID.toUTF8(), SND_PCM_STREAM_CAPTURE, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  197854. {
  197855. getDeviceNumChannels (pcmHandle, &minChansIn, &maxChansIn);
  197856. if (rates.size() == 0)
  197857. getDeviceSampleRates (pcmHandle, rates);
  197858. snd_pcm_close (pcmHandle);
  197859. }
  197860. }
  197861. snd_ctl_close (handle);
  197862. }
  197863. }
  197864. class ALSADevice
  197865. {
  197866. public:
  197867. ALSADevice (const String& deviceID,
  197868. const bool forInput)
  197869. : handle (0),
  197870. bitDepth (16),
  197871. numChannelsRunning (0),
  197872. isInput (forInput),
  197873. sampleFormat (AudioDataConverters::int16LE)
  197874. {
  197875. failed (snd_pcm_open (&handle, deviceID.toUTF8(),
  197876. forInput ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK,
  197877. SND_PCM_ASYNC));
  197878. }
  197879. ~ALSADevice()
  197880. {
  197881. if (handle != 0)
  197882. snd_pcm_close (handle);
  197883. }
  197884. bool setParameters (unsigned int sampleRate, int numChannels, int bufferSize)
  197885. {
  197886. if (handle == 0)
  197887. return false;
  197888. snd_pcm_hw_params_t* hwParams;
  197889. snd_pcm_hw_params_alloca (&hwParams);
  197890. if (failed (snd_pcm_hw_params_any (handle, hwParams)))
  197891. return false;
  197892. if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_NONINTERLEAVED) >= 0)
  197893. isInterleaved = false;
  197894. else if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_INTERLEAVED) >= 0)
  197895. isInterleaved = true;
  197896. else
  197897. {
  197898. jassertfalse
  197899. return false;
  197900. }
  197901. const int formatsToTry[] = { SND_PCM_FORMAT_FLOAT_LE, 32, AudioDataConverters::float32LE,
  197902. SND_PCM_FORMAT_FLOAT_BE, 32, AudioDataConverters::float32BE,
  197903. SND_PCM_FORMAT_S32_LE, 32, AudioDataConverters::int32LE,
  197904. SND_PCM_FORMAT_S32_BE, 32, AudioDataConverters::int32BE,
  197905. SND_PCM_FORMAT_S24_3LE, 24, AudioDataConverters::int24LE,
  197906. SND_PCM_FORMAT_S24_3BE, 24, AudioDataConverters::int24BE,
  197907. SND_PCM_FORMAT_S16_LE, 16, AudioDataConverters::int16LE,
  197908. SND_PCM_FORMAT_S16_BE, 16, AudioDataConverters::int16BE };
  197909. bitDepth = 0;
  197910. for (int i = 0; i < numElementsInArray (formatsToTry); i += 3)
  197911. {
  197912. if (snd_pcm_hw_params_set_format (handle, hwParams, (_snd_pcm_format) formatsToTry [i]) >= 0)
  197913. {
  197914. bitDepth = formatsToTry [i + 1];
  197915. sampleFormat = (AudioDataConverters::DataFormat) formatsToTry [i + 2];
  197916. break;
  197917. }
  197918. }
  197919. if (bitDepth == 0)
  197920. {
  197921. error = "device doesn't support a compatible PCM format";
  197922. DBG ("ALSA error: " + error + "\n");
  197923. return false;
  197924. }
  197925. int dir = 0;
  197926. unsigned int periods = 4;
  197927. snd_pcm_uframes_t samplesPerPeriod = bufferSize;
  197928. if (failed (snd_pcm_hw_params_set_rate_near (handle, hwParams, &sampleRate, 0))
  197929. || failed (snd_pcm_hw_params_set_channels (handle, hwParams, numChannels))
  197930. || failed (snd_pcm_hw_params_set_periods_near (handle, hwParams, &periods, &dir))
  197931. || failed (snd_pcm_hw_params_set_period_size_near (handle, hwParams, &samplesPerPeriod, &dir))
  197932. || failed (snd_pcm_hw_params (handle, hwParams)))
  197933. {
  197934. return false;
  197935. }
  197936. snd_pcm_sw_params_t* swParams;
  197937. snd_pcm_sw_params_alloca (&swParams);
  197938. snd_pcm_uframes_t boundary;
  197939. if (failed (snd_pcm_sw_params_current (handle, swParams))
  197940. || failed (snd_pcm_sw_params_get_boundary (swParams, &boundary))
  197941. || failed (snd_pcm_sw_params_set_silence_threshold (handle, swParams, 0))
  197942. || failed (snd_pcm_sw_params_set_silence_size (handle, swParams, boundary))
  197943. || failed (snd_pcm_sw_params_set_start_threshold (handle, swParams, samplesPerPeriod))
  197944. || failed (snd_pcm_sw_params_set_stop_threshold (handle, swParams, boundary))
  197945. || failed (snd_pcm_sw_params (handle, swParams)))
  197946. {
  197947. return false;
  197948. }
  197949. numChannelsRunning = numChannels;
  197950. return true;
  197951. }
  197952. bool write (float** const data, const int numSamples)
  197953. {
  197954. if (isInterleaved)
  197955. {
  197956. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  197957. float* interleaved = reinterpret_cast <float*> (scratch.getData());
  197958. AudioDataConverters::interleaveSamples ((const float**) data, interleaved, numSamples, numChannelsRunning);
  197959. AudioDataConverters::convertFloatToFormat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  197960. snd_pcm_sframes_t num = snd_pcm_writei (handle, (void*) interleaved, numSamples);
  197961. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  197962. return false;
  197963. }
  197964. else
  197965. {
  197966. for (int i = 0; i < numChannelsRunning; ++i)
  197967. if (data[i] != 0)
  197968. AudioDataConverters::convertFloatToFormat (sampleFormat, data[i], data[i], numSamples);
  197969. snd_pcm_sframes_t num = snd_pcm_writen (handle, (void**) data, numSamples);
  197970. if (failed (num))
  197971. {
  197972. if (num == -EPIPE)
  197973. {
  197974. if (failed (snd_pcm_prepare (handle)))
  197975. return false;
  197976. }
  197977. else if (num != -ESTRPIPE)
  197978. return false;
  197979. }
  197980. }
  197981. return true;
  197982. }
  197983. bool read (float** const data, const int numSamples)
  197984. {
  197985. if (isInterleaved)
  197986. {
  197987. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  197988. float* interleaved = reinterpret_cast <float*> (scratch.getData());
  197989. snd_pcm_sframes_t num = snd_pcm_readi (handle, (void*) interleaved, numSamples);
  197990. if (failed (num))
  197991. {
  197992. if (num == -EPIPE)
  197993. {
  197994. if (failed (snd_pcm_prepare (handle)))
  197995. return false;
  197996. }
  197997. else if (num != -ESTRPIPE)
  197998. return false;
  197999. }
  198000. AudioDataConverters::convertFormatToFloat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  198001. AudioDataConverters::deinterleaveSamples (interleaved, data, numSamples, numChannelsRunning);
  198002. }
  198003. else
  198004. {
  198005. snd_pcm_sframes_t num = snd_pcm_readn (handle, (void**) data, numSamples);
  198006. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  198007. return false;
  198008. for (int i = 0; i < numChannelsRunning; ++i)
  198009. if (data[i] != 0)
  198010. AudioDataConverters::convertFormatToFloat (sampleFormat, data[i], data[i], numSamples);
  198011. }
  198012. return true;
  198013. }
  198014. juce_UseDebuggingNewOperator
  198015. snd_pcm_t* handle;
  198016. String error;
  198017. int bitDepth, numChannelsRunning;
  198018. private:
  198019. const bool isInput;
  198020. bool isInterleaved;
  198021. MemoryBlock scratch;
  198022. AudioDataConverters::DataFormat sampleFormat;
  198023. bool failed (const int errorNum)
  198024. {
  198025. if (errorNum >= 0)
  198026. return false;
  198027. error = snd_strerror (errorNum);
  198028. DBG ("ALSA error: " + error + "\n");
  198029. return true;
  198030. }
  198031. };
  198032. class ALSAThread : public Thread
  198033. {
  198034. public:
  198035. ALSAThread (const String& inputId_,
  198036. const String& outputId_)
  198037. : Thread ("Juce ALSA"),
  198038. sampleRate (0),
  198039. bufferSize (0),
  198040. callback (0),
  198041. inputId (inputId_),
  198042. outputId (outputId_),
  198043. outputDevice (0),
  198044. inputDevice (0),
  198045. numCallbacks (0),
  198046. totalNumInputChannels (0),
  198047. totalNumOutputChannels (0)
  198048. {
  198049. zeromem (outputChannelData, sizeof (outputChannelData));
  198050. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198051. zeromem (inputChannelData, sizeof (inputChannelData));
  198052. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198053. initialiseRatesAndChannels();
  198054. }
  198055. ~ALSAThread()
  198056. {
  198057. close();
  198058. }
  198059. void open (BigInteger inputChannels,
  198060. BigInteger outputChannels,
  198061. const double sampleRate_,
  198062. const int bufferSize_)
  198063. {
  198064. close();
  198065. error = String::empty;
  198066. sampleRate = sampleRate_;
  198067. bufferSize = bufferSize_;
  198068. currentInputChans.clear();
  198069. currentOutputChans.clear();
  198070. if (inputChannels.getHighestBit() >= 0)
  198071. {
  198072. for (int i = 0; i <= jmax (inputChannels.getHighestBit(), (int) minChansIn); ++i)
  198073. {
  198074. inputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198075. if (inputChannels[i])
  198076. {
  198077. inputChannelDataForCallback [totalNumInputChannels++] = inputChannelData [i];
  198078. currentInputChans.setBit (i);
  198079. }
  198080. }
  198081. }
  198082. if (outputChannels.getHighestBit() >= 0)
  198083. {
  198084. for (int i = 0; i <= jmax (outputChannels.getHighestBit(), (int) minChansOut); ++i)
  198085. {
  198086. outputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198087. if (outputChannels[i])
  198088. {
  198089. outputChannelDataForCallback [totalNumOutputChannels++] = outputChannelData [i];
  198090. currentOutputChans.setBit (i);
  198091. }
  198092. }
  198093. }
  198094. if (totalNumOutputChannels > 0 && outputId.isNotEmpty())
  198095. {
  198096. outputDevice = new ALSADevice (outputId, false);
  198097. if (outputDevice->error.isNotEmpty())
  198098. {
  198099. error = outputDevice->error;
  198100. deleteAndZero (outputDevice);
  198101. return;
  198102. }
  198103. currentOutputChans.setRange (0, minChansOut, true);
  198104. if (! outputDevice->setParameters ((unsigned int) sampleRate,
  198105. jlimit ((int) minChansOut, (int) maxChansOut, currentOutputChans.getHighestBit() + 1),
  198106. bufferSize))
  198107. {
  198108. error = outputDevice->error;
  198109. deleteAndZero (outputDevice);
  198110. return;
  198111. }
  198112. }
  198113. if (totalNumInputChannels > 0 && inputId.isNotEmpty())
  198114. {
  198115. inputDevice = new ALSADevice (inputId, true);
  198116. if (inputDevice->error.isNotEmpty())
  198117. {
  198118. error = inputDevice->error;
  198119. deleteAndZero (inputDevice);
  198120. return;
  198121. }
  198122. currentInputChans.setRange (0, minChansIn, true);
  198123. if (! inputDevice->setParameters ((unsigned int) sampleRate,
  198124. jlimit ((int) minChansIn, (int) maxChansIn, currentInputChans.getHighestBit() + 1),
  198125. bufferSize))
  198126. {
  198127. error = inputDevice->error;
  198128. deleteAndZero (inputDevice);
  198129. return;
  198130. }
  198131. }
  198132. if (outputDevice == 0 && inputDevice == 0)
  198133. {
  198134. error = "no channels";
  198135. return;
  198136. }
  198137. if (outputDevice != 0 && inputDevice != 0)
  198138. {
  198139. snd_pcm_link (outputDevice->handle, inputDevice->handle);
  198140. }
  198141. if (inputDevice != 0 && failed (snd_pcm_prepare (inputDevice->handle)))
  198142. return;
  198143. if (outputDevice != 0 && failed (snd_pcm_prepare (outputDevice->handle)))
  198144. return;
  198145. startThread (9);
  198146. int count = 1000;
  198147. while (numCallbacks == 0)
  198148. {
  198149. sleep (5);
  198150. if (--count < 0 || ! isThreadRunning())
  198151. {
  198152. error = "device didn't start";
  198153. break;
  198154. }
  198155. }
  198156. }
  198157. void close()
  198158. {
  198159. stopThread (6000);
  198160. deleteAndZero (inputDevice);
  198161. deleteAndZero (outputDevice);
  198162. for (int i = 0; i < maxNumChans; ++i)
  198163. {
  198164. juce_free (inputChannelData [i]);
  198165. juce_free (outputChannelData [i]);
  198166. }
  198167. zeromem (outputChannelData, sizeof (outputChannelData));
  198168. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198169. zeromem (inputChannelData, sizeof (inputChannelData));
  198170. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198171. totalNumOutputChannels = 0;
  198172. totalNumInputChannels = 0;
  198173. numCallbacks = 0;
  198174. }
  198175. void setCallback (AudioIODeviceCallback* const newCallback) throw()
  198176. {
  198177. const ScopedLock sl (callbackLock);
  198178. callback = newCallback;
  198179. }
  198180. void run()
  198181. {
  198182. while (! threadShouldExit())
  198183. {
  198184. if (inputDevice != 0)
  198185. {
  198186. if (! inputDevice->read (inputChannelData, bufferSize))
  198187. {
  198188. DBG ("ALSA: read failure");
  198189. break;
  198190. }
  198191. }
  198192. if (threadShouldExit())
  198193. break;
  198194. {
  198195. const ScopedLock sl (callbackLock);
  198196. ++numCallbacks;
  198197. if (callback != 0)
  198198. {
  198199. callback->audioDeviceIOCallback ((const float**) inputChannelDataForCallback,
  198200. totalNumInputChannels,
  198201. outputChannelDataForCallback,
  198202. totalNumOutputChannels,
  198203. bufferSize);
  198204. }
  198205. else
  198206. {
  198207. for (int i = 0; i < totalNumOutputChannels; ++i)
  198208. zeromem (outputChannelDataForCallback[i], sizeof (float) * bufferSize);
  198209. }
  198210. }
  198211. if (outputDevice != 0)
  198212. {
  198213. failed (snd_pcm_wait (outputDevice->handle, 2000));
  198214. if (threadShouldExit())
  198215. break;
  198216. failed (snd_pcm_avail_update (outputDevice->handle));
  198217. if (! outputDevice->write (outputChannelData, bufferSize))
  198218. {
  198219. DBG ("ALSA: write failure");
  198220. break;
  198221. }
  198222. }
  198223. }
  198224. }
  198225. int getBitDepth() const throw()
  198226. {
  198227. if (outputDevice != 0)
  198228. return outputDevice->bitDepth;
  198229. if (inputDevice != 0)
  198230. return inputDevice->bitDepth;
  198231. return 16;
  198232. }
  198233. juce_UseDebuggingNewOperator
  198234. String error;
  198235. double sampleRate;
  198236. int bufferSize;
  198237. BigInteger currentInputChans, currentOutputChans;
  198238. Array <int> sampleRates;
  198239. StringArray channelNamesOut, channelNamesIn;
  198240. AudioIODeviceCallback* callback;
  198241. private:
  198242. const String inputId, outputId;
  198243. ALSADevice* outputDevice;
  198244. ALSADevice* inputDevice;
  198245. int numCallbacks;
  198246. CriticalSection callbackLock;
  198247. float* outputChannelData [maxNumChans];
  198248. float* outputChannelDataForCallback [maxNumChans];
  198249. int totalNumInputChannels;
  198250. float* inputChannelData [maxNumChans];
  198251. float* inputChannelDataForCallback [maxNumChans];
  198252. int totalNumOutputChannels;
  198253. unsigned int minChansOut, maxChansOut;
  198254. unsigned int minChansIn, maxChansIn;
  198255. bool failed (const int errorNum) throw()
  198256. {
  198257. if (errorNum >= 0)
  198258. return false;
  198259. error = snd_strerror (errorNum);
  198260. DBG ("ALSA error: " + error + "\n");
  198261. return true;
  198262. }
  198263. void initialiseRatesAndChannels() throw()
  198264. {
  198265. sampleRates.clear();
  198266. channelNamesOut.clear();
  198267. channelNamesIn.clear();
  198268. minChansOut = 0;
  198269. maxChansOut = 0;
  198270. minChansIn = 0;
  198271. maxChansIn = 0;
  198272. unsigned int dummy = 0;
  198273. getDeviceProperties (inputId, dummy, dummy, minChansIn, maxChansIn, sampleRates);
  198274. getDeviceProperties (outputId, minChansOut, maxChansOut, dummy, dummy, sampleRates);
  198275. unsigned int i;
  198276. for (i = 0; i < maxChansOut; ++i)
  198277. channelNamesOut.add ("channel " + String ((int) i + 1));
  198278. for (i = 0; i < maxChansIn; ++i)
  198279. channelNamesIn.add ("channel " + String ((int) i + 1));
  198280. }
  198281. };
  198282. class ALSAAudioIODevice : public AudioIODevice
  198283. {
  198284. public:
  198285. ALSAAudioIODevice (const String& deviceName,
  198286. const String& inputId_,
  198287. const String& outputId_)
  198288. : AudioIODevice (deviceName, "ALSA"),
  198289. inputId (inputId_),
  198290. outputId (outputId_),
  198291. isOpen_ (false),
  198292. isStarted (false),
  198293. internal (0)
  198294. {
  198295. internal = new ALSAThread (inputId, outputId);
  198296. }
  198297. ~ALSAAudioIODevice()
  198298. {
  198299. delete internal;
  198300. }
  198301. const StringArray getOutputChannelNames()
  198302. {
  198303. return internal->channelNamesOut;
  198304. }
  198305. const StringArray getInputChannelNames()
  198306. {
  198307. return internal->channelNamesIn;
  198308. }
  198309. int getNumSampleRates()
  198310. {
  198311. return internal->sampleRates.size();
  198312. }
  198313. double getSampleRate (int index)
  198314. {
  198315. return internal->sampleRates [index];
  198316. }
  198317. int getNumBufferSizesAvailable()
  198318. {
  198319. return 50;
  198320. }
  198321. int getBufferSizeSamples (int index)
  198322. {
  198323. int n = 16;
  198324. for (int i = 0; i < index; ++i)
  198325. n += n < 64 ? 16
  198326. : (n < 512 ? 32
  198327. : (n < 1024 ? 64
  198328. : (n < 2048 ? 128 : 256)));
  198329. return n;
  198330. }
  198331. int getDefaultBufferSize()
  198332. {
  198333. return 512;
  198334. }
  198335. const String open (const BigInteger& inputChannels,
  198336. const BigInteger& outputChannels,
  198337. double sampleRate,
  198338. int bufferSizeSamples)
  198339. {
  198340. close();
  198341. if (bufferSizeSamples <= 0)
  198342. bufferSizeSamples = getDefaultBufferSize();
  198343. if (sampleRate <= 0)
  198344. {
  198345. for (int i = 0; i < getNumSampleRates(); ++i)
  198346. {
  198347. if (getSampleRate (i) >= 44100)
  198348. {
  198349. sampleRate = getSampleRate (i);
  198350. break;
  198351. }
  198352. }
  198353. }
  198354. internal->open (inputChannels, outputChannels,
  198355. sampleRate, bufferSizeSamples);
  198356. isOpen_ = internal->error.isEmpty();
  198357. return internal->error;
  198358. }
  198359. void close()
  198360. {
  198361. stop();
  198362. internal->close();
  198363. isOpen_ = false;
  198364. }
  198365. bool isOpen()
  198366. {
  198367. return isOpen_;
  198368. }
  198369. int getCurrentBufferSizeSamples()
  198370. {
  198371. return internal->bufferSize;
  198372. }
  198373. double getCurrentSampleRate()
  198374. {
  198375. return internal->sampleRate;
  198376. }
  198377. int getCurrentBitDepth()
  198378. {
  198379. return internal->getBitDepth();
  198380. }
  198381. const BigInteger getActiveOutputChannels() const
  198382. {
  198383. return internal->currentOutputChans;
  198384. }
  198385. const BigInteger getActiveInputChannels() const
  198386. {
  198387. return internal->currentInputChans;
  198388. }
  198389. int getOutputLatencyInSamples()
  198390. {
  198391. return 0;
  198392. }
  198393. int getInputLatencyInSamples()
  198394. {
  198395. return 0;
  198396. }
  198397. void start (AudioIODeviceCallback* callback)
  198398. {
  198399. if (! isOpen_)
  198400. callback = 0;
  198401. internal->setCallback (callback);
  198402. if (callback != 0)
  198403. callback->audioDeviceAboutToStart (this);
  198404. isStarted = (callback != 0);
  198405. }
  198406. void stop()
  198407. {
  198408. AudioIODeviceCallback* const oldCallback = internal->callback;
  198409. start (0);
  198410. if (oldCallback != 0)
  198411. oldCallback->audioDeviceStopped();
  198412. }
  198413. bool isPlaying()
  198414. {
  198415. return isStarted && internal->error.isEmpty();
  198416. }
  198417. const String getLastError()
  198418. {
  198419. return internal->error;
  198420. }
  198421. String inputId, outputId;
  198422. private:
  198423. bool isOpen_, isStarted;
  198424. ALSAThread* internal;
  198425. };
  198426. class ALSAAudioIODeviceType : public AudioIODeviceType
  198427. {
  198428. public:
  198429. ALSAAudioIODeviceType()
  198430. : AudioIODeviceType ("ALSA"),
  198431. hasScanned (false)
  198432. {
  198433. }
  198434. ~ALSAAudioIODeviceType()
  198435. {
  198436. }
  198437. void scanForDevices()
  198438. {
  198439. if (hasScanned)
  198440. return;
  198441. hasScanned = true;
  198442. inputNames.clear();
  198443. inputIds.clear();
  198444. outputNames.clear();
  198445. outputIds.clear();
  198446. snd_ctl_t* handle;
  198447. snd_ctl_card_info_t* info;
  198448. snd_ctl_card_info_alloca (&info);
  198449. int cardNum = -1;
  198450. while (outputIds.size() + inputIds.size() <= 32)
  198451. {
  198452. snd_card_next (&cardNum);
  198453. if (cardNum < 0)
  198454. break;
  198455. if (snd_ctl_open (&handle, ("hw:" + String (cardNum)).toUTF8(), SND_CTL_NONBLOCK) >= 0)
  198456. {
  198457. if (snd_ctl_card_info (handle, info) >= 0)
  198458. {
  198459. String cardId (snd_ctl_card_info_get_id (info));
  198460. if (cardId.removeCharacters (T("0123456789")).isEmpty())
  198461. cardId = String (cardNum);
  198462. int device = -1;
  198463. for (;;)
  198464. {
  198465. if (snd_ctl_pcm_next_device (handle, &device) < 0 || device < 0)
  198466. break;
  198467. String id, name;
  198468. id << "hw:" << cardId << ',' << device;
  198469. bool isInput, isOutput;
  198470. if (testDevice (id, isInput, isOutput))
  198471. {
  198472. name << snd_ctl_card_info_get_name (info);
  198473. if (name.isEmpty())
  198474. name = id;
  198475. if (isInput)
  198476. {
  198477. inputNames.add (name);
  198478. inputIds.add (id);
  198479. }
  198480. if (isOutput)
  198481. {
  198482. outputNames.add (name);
  198483. outputIds.add (id);
  198484. }
  198485. }
  198486. }
  198487. }
  198488. snd_ctl_close (handle);
  198489. }
  198490. }
  198491. inputNames.appendNumbersToDuplicates (false, true);
  198492. outputNames.appendNumbersToDuplicates (false, true);
  198493. }
  198494. const StringArray getDeviceNames (const bool wantInputNames) const
  198495. {
  198496. jassert (hasScanned); // need to call scanForDevices() before doing this
  198497. return wantInputNames ? inputNames : outputNames;
  198498. }
  198499. int getDefaultDeviceIndex (const bool forInput) const
  198500. {
  198501. jassert (hasScanned); // need to call scanForDevices() before doing this
  198502. return 0;
  198503. }
  198504. bool hasSeparateInputsAndOutputs() const { return true; }
  198505. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  198506. {
  198507. jassert (hasScanned); // need to call scanForDevices() before doing this
  198508. ALSAAudioIODevice* const d = dynamic_cast <ALSAAudioIODevice*> (device);
  198509. if (d == 0)
  198510. return -1;
  198511. return asInput ? inputIds.indexOf (d->inputId)
  198512. : outputIds.indexOf (d->outputId);
  198513. }
  198514. AudioIODevice* createDevice (const String& outputDeviceName,
  198515. const String& inputDeviceName)
  198516. {
  198517. jassert (hasScanned); // need to call scanForDevices() before doing this
  198518. const int inputIndex = inputNames.indexOf (inputDeviceName);
  198519. const int outputIndex = outputNames.indexOf (outputDeviceName);
  198520. String deviceName (outputIndex >= 0 ? outputDeviceName
  198521. : inputDeviceName);
  198522. if (inputIndex >= 0 || outputIndex >= 0)
  198523. return new ALSAAudioIODevice (deviceName,
  198524. inputIds [inputIndex],
  198525. outputIds [outputIndex]);
  198526. return 0;
  198527. }
  198528. juce_UseDebuggingNewOperator
  198529. private:
  198530. StringArray inputNames, outputNames, inputIds, outputIds;
  198531. bool hasScanned;
  198532. static bool testDevice (const String& id, bool& isInput, bool& isOutput)
  198533. {
  198534. unsigned int minChansOut = 0, maxChansOut = 0;
  198535. unsigned int minChansIn = 0, maxChansIn = 0;
  198536. Array <int> rates;
  198537. getDeviceProperties (id, minChansOut, maxChansOut, minChansIn, maxChansIn, rates);
  198538. DBG ("ALSA device: " + id
  198539. + " outs=" + String ((int) minChansOut) + "-" + String ((int) maxChansOut)
  198540. + " ins=" + String ((int) minChansIn) + "-" + String ((int) maxChansIn)
  198541. + " rates=" + String (rates.size()));
  198542. isInput = maxChansIn > 0;
  198543. isOutput = maxChansOut > 0;
  198544. return (isInput || isOutput) && rates.size() > 0;
  198545. }
  198546. ALSAAudioIODeviceType (const ALSAAudioIODeviceType&);
  198547. ALSAAudioIODeviceType& operator= (const ALSAAudioIODeviceType&);
  198548. };
  198549. AudioIODeviceType* juce_createAudioIODeviceType_ALSA()
  198550. {
  198551. return new ALSAAudioIODeviceType();
  198552. }
  198553. #endif
  198554. /*** End of inlined file: juce_linux_Audio.cpp ***/
  198555. /*** Start of inlined file: juce_linux_JackAudio.cpp ***/
  198556. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  198557. // compiled on its own).
  198558. #ifdef JUCE_INCLUDED_FILE
  198559. #if JUCE_JACK
  198560. static void* juce_libjack_handle = 0;
  198561. void* juce_load_jack_function (const char* const name)
  198562. {
  198563. if (juce_libjack_handle == 0)
  198564. return 0;
  198565. return dlsym (juce_libjack_handle, name);
  198566. }
  198567. #define JUCE_DECL_JACK_FUNCTION(return_type, fn_name, argument_types, arguments) \
  198568. typedef return_type (*fn_name##_ptr_t)argument_types; \
  198569. return_type fn_name argument_types { \
  198570. static fn_name##_ptr_t fn = 0; \
  198571. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198572. if (fn) return (*fn)arguments; \
  198573. else return 0; \
  198574. }
  198575. #define JUCE_DECL_VOID_JACK_FUNCTION(fn_name, argument_types, arguments) \
  198576. typedef void (*fn_name##_ptr_t)argument_types; \
  198577. void fn_name argument_types { \
  198578. static fn_name##_ptr_t fn = 0; \
  198579. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198580. if (fn) (*fn)arguments; \
  198581. }
  198582. 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));
  198583. JUCE_DECL_JACK_FUNCTION (int, jack_client_close, (jack_client_t *client), (client));
  198584. JUCE_DECL_JACK_FUNCTION (int, jack_activate, (jack_client_t* client), (client));
  198585. JUCE_DECL_JACK_FUNCTION (int, jack_deactivate, (jack_client_t* client), (client));
  198586. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_buffer_size, (jack_client_t* client), (client));
  198587. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_sample_rate, (jack_client_t* client), (client));
  198588. JUCE_DECL_VOID_JACK_FUNCTION (jack_on_shutdown, (jack_client_t* client, void (*function)(void* arg), void* arg), (client, function, arg));
  198589. JUCE_DECL_JACK_FUNCTION (void* , jack_port_get_buffer, (jack_port_t* port, jack_nframes_t nframes), (port, nframes));
  198590. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_port_get_total_latency, (jack_client_t* client, jack_port_t* port), (client, port));
  198591. 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));
  198592. JUCE_DECL_VOID_JACK_FUNCTION (jack_set_error_function, (void (*func)(const char*)), (func));
  198593. JUCE_DECL_JACK_FUNCTION (int, jack_set_process_callback, (jack_client_t* client, JackProcessCallback process_callback, void* arg), (client, process_callback, arg));
  198594. 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));
  198595. JUCE_DECL_JACK_FUNCTION (int, jack_connect, (jack_client_t* client, const char* source_port, const char* destination_port), (client, source_port, destination_port));
  198596. JUCE_DECL_JACK_FUNCTION (const char*, jack_port_name, (const jack_port_t* port), (port));
  198597. JUCE_DECL_JACK_FUNCTION (int, jack_set_port_connect_callback, (jack_client_t* client, JackPortConnectCallback connect_callback, void* arg), (client, connect_callback, arg));
  198598. JUCE_DECL_JACK_FUNCTION (jack_port_t* , jack_port_by_id, (jack_client_t* client, jack_port_id_t port_id), (client, port_id));
  198599. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected, (const jack_port_t* port), (port));
  198600. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected_to, (const jack_port_t* port, const char* port_name), (port, port_name));
  198601. #if JUCE_DEBUG
  198602. #define JACK_LOGGING_ENABLED 1
  198603. #endif
  198604. #if JACK_LOGGING_ENABLED
  198605. static void jack_Log (const String& s)
  198606. {
  198607. std::cerr << s << std::endl;
  198608. }
  198609. static void dumpJackErrorMessage (const jack_status_t status) throw()
  198610. {
  198611. if (status & JackServerFailed || status & JackServerError)
  198612. jack_Log ("Unable to connect to JACK server");
  198613. if (status & JackVersionError)
  198614. jack_Log ("Client's protocol version does not match");
  198615. if (status & JackInvalidOption)
  198616. jack_Log ("The operation contained an invalid or unsupported option");
  198617. if (status & JackNameNotUnique)
  198618. jack_Log ("The desired client name was not unique");
  198619. if (status & JackNoSuchClient)
  198620. jack_Log ("Requested client does not exist");
  198621. if (status & JackInitFailure)
  198622. jack_Log ("Unable to initialize client");
  198623. }
  198624. #else
  198625. #define dumpJackErrorMessage(a) {}
  198626. #define jack_Log(...) {}
  198627. #endif
  198628. #ifndef JUCE_JACK_CLIENT_NAME
  198629. #define JUCE_JACK_CLIENT_NAME "JuceJack"
  198630. #endif
  198631. class JackAudioIODevice : public AudioIODevice
  198632. {
  198633. public:
  198634. JackAudioIODevice (const String& deviceName,
  198635. const String& inputId_,
  198636. const String& outputId_)
  198637. : AudioIODevice (deviceName, "JACK"),
  198638. inputId (inputId_),
  198639. outputId (outputId_),
  198640. isOpen_ (false),
  198641. callback (0),
  198642. totalNumberOfInputChannels (0),
  198643. totalNumberOfOutputChannels (0)
  198644. {
  198645. jassert (deviceName.isNotEmpty());
  198646. jack_status_t status;
  198647. client = JUCE_NAMESPACE::jack_client_open (JUCE_JACK_CLIENT_NAME, JackNoStartServer, &status);
  198648. if (client == 0)
  198649. {
  198650. dumpJackErrorMessage (status);
  198651. }
  198652. else
  198653. {
  198654. JUCE_NAMESPACE::jack_set_error_function (errorCallback);
  198655. // open input ports
  198656. const StringArray inputChannels (getInputChannelNames());
  198657. for (int i = 0; i < inputChannels.size(); i++)
  198658. {
  198659. String inputName;
  198660. inputName << "in_" << ++totalNumberOfInputChannels;
  198661. inputPorts.add (JUCE_NAMESPACE::jack_port_register (client, inputName.toUTF8(),
  198662. JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0));
  198663. }
  198664. // open output ports
  198665. const StringArray outputChannels (getOutputChannelNames());
  198666. for (int i = 0; i < outputChannels.size (); i++)
  198667. {
  198668. String outputName;
  198669. outputName << "out_" << ++totalNumberOfOutputChannels;
  198670. outputPorts.add (JUCE_NAMESPACE::jack_port_register (client, outputName.toUTF8(),
  198671. JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0));
  198672. }
  198673. inChans.calloc (totalNumberOfInputChannels + 2);
  198674. outChans.calloc (totalNumberOfOutputChannels + 2);
  198675. }
  198676. }
  198677. ~JackAudioIODevice()
  198678. {
  198679. close();
  198680. if (client != 0)
  198681. {
  198682. JUCE_NAMESPACE::jack_client_close (client);
  198683. client = 0;
  198684. }
  198685. }
  198686. const StringArray getChannelNames (bool forInput) const
  198687. {
  198688. StringArray names;
  198689. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */
  198690. forInput ? JackPortIsInput : JackPortIsOutput);
  198691. if (ports != 0)
  198692. {
  198693. int j = 0;
  198694. while (ports[j] != 0)
  198695. {
  198696. const String portName (ports [j++]);
  198697. if (portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  198698. names.add (portName.fromFirstOccurrenceOf (T(":"), false, false));
  198699. }
  198700. free (ports);
  198701. }
  198702. return names;
  198703. }
  198704. const StringArray getOutputChannelNames() { return getChannelNames (false); }
  198705. const StringArray getInputChannelNames() { return getChannelNames (true); }
  198706. int getNumSampleRates() { return client != 0 ? 1 : 0; }
  198707. double getSampleRate (int index) { return client != 0 ? JUCE_NAMESPACE::jack_get_sample_rate (client) : 0; }
  198708. int getNumBufferSizesAvailable() { return client != 0 ? 1 : 0; }
  198709. int getBufferSizeSamples (int index) { return getDefaultBufferSize(); }
  198710. int getDefaultBufferSize() { return client != 0 ? JUCE_NAMESPACE::jack_get_buffer_size (client) : 0; }
  198711. const String open (const BigInteger& inputChannels, const BigInteger& outputChannels,
  198712. double sampleRate, int bufferSizeSamples)
  198713. {
  198714. if (client == 0)
  198715. {
  198716. lastError = "No JACK client running";
  198717. return lastError;
  198718. }
  198719. lastError = String::empty;
  198720. close();
  198721. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, this);
  198722. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, this);
  198723. JUCE_NAMESPACE::jack_activate (client);
  198724. isOpen_ = true;
  198725. if (! inputChannels.isZero())
  198726. {
  198727. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  198728. if (ports != 0)
  198729. {
  198730. const int numInputChannels = inputChannels.getHighestBit() + 1;
  198731. for (int i = 0; i < numInputChannels; ++i)
  198732. {
  198733. const String portName (ports[i]);
  198734. if (inputChannels[i] && portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  198735. {
  198736. int error = JUCE_NAMESPACE::jack_connect (client, ports[i], JUCE_NAMESPACE::jack_port_name ((jack_port_t*) inputPorts[i]));
  198737. if (error != 0)
  198738. jack_Log ("Cannot connect input port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  198739. }
  198740. }
  198741. free (ports);
  198742. }
  198743. }
  198744. if (! outputChannels.isZero())
  198745. {
  198746. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  198747. if (ports != 0)
  198748. {
  198749. const int numOutputChannels = outputChannels.getHighestBit() + 1;
  198750. for (int i = 0; i < numOutputChannels; ++i)
  198751. {
  198752. const String portName (ports[i]);
  198753. if (outputChannels[i] && portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  198754. {
  198755. int error = JUCE_NAMESPACE::jack_connect (client, JUCE_NAMESPACE::jack_port_name ((jack_port_t*) outputPorts[i]), ports[i]);
  198756. if (error != 0)
  198757. jack_Log ("Cannot connect output port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  198758. }
  198759. }
  198760. free (ports);
  198761. }
  198762. }
  198763. return lastError;
  198764. }
  198765. void close()
  198766. {
  198767. stop();
  198768. if (client != 0)
  198769. {
  198770. JUCE_NAMESPACE::jack_deactivate (client);
  198771. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, 0);
  198772. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, 0);
  198773. }
  198774. isOpen_ = false;
  198775. }
  198776. void start (AudioIODeviceCallback* newCallback)
  198777. {
  198778. if (isOpen_ && newCallback != callback)
  198779. {
  198780. if (newCallback != 0)
  198781. newCallback->audioDeviceAboutToStart (this);
  198782. AudioIODeviceCallback* const oldCallback = callback;
  198783. {
  198784. const ScopedLock sl (callbackLock);
  198785. callback = newCallback;
  198786. }
  198787. if (oldCallback != 0)
  198788. oldCallback->audioDeviceStopped();
  198789. }
  198790. }
  198791. void stop()
  198792. {
  198793. start (0);
  198794. }
  198795. bool isOpen() { return isOpen_; }
  198796. bool isPlaying() { return callback != 0; }
  198797. int getCurrentBufferSizeSamples() { return getBufferSizeSamples (0); }
  198798. double getCurrentSampleRate() { return getSampleRate (0); }
  198799. int getCurrentBitDepth() { return 32; }
  198800. const String getLastError() { return lastError; }
  198801. const BigInteger getActiveOutputChannels() const
  198802. {
  198803. BigInteger outputBits;
  198804. for (int i = 0; i < outputPorts.size(); i++)
  198805. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) outputPorts [i]))
  198806. outputBits.setBit (i);
  198807. return outputBits;
  198808. }
  198809. const BigInteger getActiveInputChannels() const
  198810. {
  198811. BigInteger inputBits;
  198812. for (int i = 0; i < inputPorts.size(); i++)
  198813. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) inputPorts [i]))
  198814. inputBits.setBit (i);
  198815. return inputBits;
  198816. }
  198817. int getOutputLatencyInSamples()
  198818. {
  198819. int latency = 0;
  198820. for (int i = 0; i < outputPorts.size(); i++)
  198821. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) outputPorts [i]));
  198822. return latency;
  198823. }
  198824. int getInputLatencyInSamples()
  198825. {
  198826. int latency = 0;
  198827. for (int i = 0; i < inputPorts.size(); i++)
  198828. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) inputPorts [i]));
  198829. return latency;
  198830. }
  198831. String inputId, outputId;
  198832. private:
  198833. void process (const int numSamples)
  198834. {
  198835. int i, numActiveInChans = 0, numActiveOutChans = 0;
  198836. for (i = 0; i < totalNumberOfInputChannels; ++i)
  198837. {
  198838. jack_default_audio_sample_t* in
  198839. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) inputPorts.getUnchecked(i), numSamples);
  198840. if (in != 0)
  198841. inChans [numActiveInChans++] = (float*) in;
  198842. }
  198843. for (i = 0; i < totalNumberOfOutputChannels; ++i)
  198844. {
  198845. jack_default_audio_sample_t* out
  198846. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) outputPorts.getUnchecked(i), numSamples);
  198847. if (out != 0)
  198848. outChans [numActiveOutChans++] = (float*) out;
  198849. }
  198850. const ScopedLock sl (callbackLock);
  198851. if (callback != 0)
  198852. {
  198853. callback->audioDeviceIOCallback (const_cast<const float**> (inChans.getData()), numActiveInChans,
  198854. outChans, numActiveOutChans, numSamples);
  198855. }
  198856. else
  198857. {
  198858. for (i = 0; i < numActiveOutChans; ++i)
  198859. zeromem (outChans[i], sizeof (float) * numSamples);
  198860. }
  198861. }
  198862. static int processCallback (jack_nframes_t nframes, void* callbackArgument)
  198863. {
  198864. if (callbackArgument != 0)
  198865. ((JackAudioIODevice*) callbackArgument)->process (nframes);
  198866. return 0;
  198867. }
  198868. static void threadInitCallback (void* callbackArgument)
  198869. {
  198870. jack_Log ("JackAudioIODevice::initialise");
  198871. }
  198872. static void shutdownCallback (void* callbackArgument)
  198873. {
  198874. jack_Log ("JackAudioIODevice::shutdown");
  198875. JackAudioIODevice* device = (JackAudioIODevice*) callbackArgument;
  198876. if (device != 0)
  198877. {
  198878. device->client = 0;
  198879. device->close();
  198880. }
  198881. }
  198882. static void errorCallback (const char* msg)
  198883. {
  198884. jack_Log ("JackAudioIODevice::errorCallback " + String (msg));
  198885. }
  198886. bool isOpen_;
  198887. jack_client_t* client;
  198888. String lastError;
  198889. AudioIODeviceCallback* callback;
  198890. CriticalSection callbackLock;
  198891. HeapBlock <float*> inChans, outChans;
  198892. int totalNumberOfInputChannels;
  198893. int totalNumberOfOutputChannels;
  198894. VoidArray inputPorts, outputPorts;
  198895. };
  198896. class JackAudioIODeviceType : public AudioIODeviceType
  198897. {
  198898. public:
  198899. JackAudioIODeviceType()
  198900. : AudioIODeviceType ("JACK"),
  198901. hasScanned (false)
  198902. {
  198903. }
  198904. ~JackAudioIODeviceType()
  198905. {
  198906. }
  198907. void scanForDevices()
  198908. {
  198909. hasScanned = true;
  198910. inputNames.clear();
  198911. inputIds.clear();
  198912. outputNames.clear();
  198913. outputIds.clear();
  198914. if (juce_libjack_handle == 0)
  198915. {
  198916. juce_libjack_handle = dlopen ("libjack.so", RTLD_LAZY);
  198917. if (juce_libjack_handle == 0)
  198918. return;
  198919. }
  198920. // open a dummy client
  198921. jack_status_t status;
  198922. jack_client_t* client = JUCE_NAMESPACE::jack_client_open ("JuceJackDummy", JackNoStartServer, &status);
  198923. if (client == 0)
  198924. {
  198925. dumpJackErrorMessage (status);
  198926. }
  198927. else
  198928. {
  198929. // scan for output devices
  198930. const char** ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  198931. if (ports != 0)
  198932. {
  198933. int j = 0;
  198934. while (ports[j] != 0)
  198935. {
  198936. String clientName (ports[j]);
  198937. clientName = clientName.upToFirstOccurrenceOf (T(":"), false, false);
  198938. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  198939. && ! inputNames.contains (clientName))
  198940. {
  198941. inputNames.add (clientName);
  198942. inputIds.add (ports [j]);
  198943. }
  198944. ++j;
  198945. }
  198946. free (ports);
  198947. }
  198948. // scan for input devices
  198949. ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  198950. if (ports != 0)
  198951. {
  198952. int j = 0;
  198953. while (ports[j] != 0)
  198954. {
  198955. String clientName (ports[j]);
  198956. clientName = clientName.upToFirstOccurrenceOf (T(":"), false, false);
  198957. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  198958. && ! outputNames.contains (clientName))
  198959. {
  198960. outputNames.add (clientName);
  198961. outputIds.add (ports [j]);
  198962. }
  198963. ++j;
  198964. }
  198965. free (ports);
  198966. }
  198967. JUCE_NAMESPACE::jack_client_close (client);
  198968. }
  198969. }
  198970. const StringArray getDeviceNames (const bool wantInputNames) const
  198971. {
  198972. jassert (hasScanned); // need to call scanForDevices() before doing this
  198973. return wantInputNames ? inputNames : outputNames;
  198974. }
  198975. int getDefaultDeviceIndex (const bool forInput) const
  198976. {
  198977. jassert (hasScanned); // need to call scanForDevices() before doing this
  198978. return 0;
  198979. }
  198980. bool hasSeparateInputsAndOutputs() const { return true; }
  198981. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  198982. {
  198983. jassert (hasScanned); // need to call scanForDevices() before doing this
  198984. JackAudioIODevice* const d = dynamic_cast <JackAudioIODevice*> (device);
  198985. if (d == 0)
  198986. return -1;
  198987. return asInput ? inputIds.indexOf (d->inputId)
  198988. : outputIds.indexOf (d->outputId);
  198989. }
  198990. AudioIODevice* createDevice (const String& outputDeviceName,
  198991. const String& inputDeviceName)
  198992. {
  198993. jassert (hasScanned); // need to call scanForDevices() before doing this
  198994. const int inputIndex = inputNames.indexOf (inputDeviceName);
  198995. const int outputIndex = outputNames.indexOf (outputDeviceName);
  198996. if (inputIndex >= 0 || outputIndex >= 0)
  198997. return new JackAudioIODevice (outputIndex >= 0 ? outputDeviceName
  198998. : inputDeviceName,
  198999. inputIds [inputIndex],
  199000. outputIds [outputIndex]);
  199001. return 0;
  199002. }
  199003. juce_UseDebuggingNewOperator
  199004. private:
  199005. StringArray inputNames, outputNames, inputIds, outputIds;
  199006. bool hasScanned;
  199007. JackAudioIODeviceType (const JackAudioIODeviceType&);
  199008. JackAudioIODeviceType& operator= (const JackAudioIODeviceType&);
  199009. };
  199010. AudioIODeviceType* juce_createAudioIODeviceType_JACK()
  199011. {
  199012. return new JackAudioIODeviceType();
  199013. }
  199014. #else // if JACK is turned off..
  199015. AudioIODeviceType* juce_createAudioIODeviceType_JACK() { return 0; }
  199016. #endif
  199017. #endif
  199018. /*** End of inlined file: juce_linux_JackAudio.cpp ***/
  199019. /*** Start of inlined file: juce_linux_Midi.cpp ***/
  199020. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199021. // compiled on its own).
  199022. #if JUCE_INCLUDED_FILE
  199023. #if JUCE_ALSA
  199024. static snd_seq_t* iterateDevices (const bool forInput,
  199025. StringArray& deviceNamesFound,
  199026. const int deviceIndexToOpen)
  199027. {
  199028. snd_seq_t* returnedHandle = 0;
  199029. snd_seq_t* seqHandle;
  199030. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199031. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199032. {
  199033. snd_seq_system_info_t* systemInfo;
  199034. snd_seq_client_info_t* clientInfo;
  199035. if (snd_seq_system_info_malloc (&systemInfo) == 0)
  199036. {
  199037. if (snd_seq_system_info (seqHandle, systemInfo) == 0
  199038. && snd_seq_client_info_malloc (&clientInfo) == 0)
  199039. {
  199040. int numClients = snd_seq_system_info_get_cur_clients (systemInfo);
  199041. while (--numClients >= 0 && returnedHandle == 0)
  199042. {
  199043. if (snd_seq_query_next_client (seqHandle, clientInfo) == 0)
  199044. {
  199045. snd_seq_port_info_t* portInfo;
  199046. if (snd_seq_port_info_malloc (&portInfo) == 0)
  199047. {
  199048. int numPorts = snd_seq_client_info_get_num_ports (clientInfo);
  199049. const int client = snd_seq_client_info_get_client (clientInfo);
  199050. snd_seq_port_info_set_client (portInfo, client);
  199051. snd_seq_port_info_set_port (portInfo, -1);
  199052. while (--numPorts >= 0)
  199053. {
  199054. if (snd_seq_query_next_port (seqHandle, portInfo) == 0
  199055. && (snd_seq_port_info_get_capability (portInfo)
  199056. & (forInput ? SND_SEQ_PORT_CAP_READ
  199057. : SND_SEQ_PORT_CAP_WRITE)) != 0)
  199058. {
  199059. deviceNamesFound.add (snd_seq_client_info_get_name (clientInfo));
  199060. if (deviceNamesFound.size() == deviceIndexToOpen + 1)
  199061. {
  199062. const int sourcePort = snd_seq_port_info_get_port (portInfo);
  199063. const int sourceClient = snd_seq_client_info_get_client (clientInfo);
  199064. if (sourcePort != -1)
  199065. {
  199066. snd_seq_set_client_name (seqHandle,
  199067. forInput ? "Juce Midi Input"
  199068. : "Juce Midi Output");
  199069. const int portId
  199070. = snd_seq_create_simple_port (seqHandle,
  199071. forInput ? "Juce Midi In Port"
  199072. : "Juce Midi Out Port",
  199073. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199074. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199075. SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199076. snd_seq_connect_from (seqHandle, portId, sourceClient, sourcePort);
  199077. returnedHandle = seqHandle;
  199078. }
  199079. }
  199080. }
  199081. }
  199082. snd_seq_port_info_free (portInfo);
  199083. }
  199084. }
  199085. }
  199086. snd_seq_client_info_free (clientInfo);
  199087. }
  199088. snd_seq_system_info_free (systemInfo);
  199089. }
  199090. if (returnedHandle == 0)
  199091. snd_seq_close (seqHandle);
  199092. }
  199093. deviceNamesFound.appendNumbersToDuplicates (true, true);
  199094. return returnedHandle;
  199095. }
  199096. static snd_seq_t* createDevice (const bool forInput,
  199097. const String& deviceNameToOpen)
  199098. {
  199099. snd_seq_t* seqHandle = 0;
  199100. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199101. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199102. {
  199103. snd_seq_set_client_name (seqHandle,
  199104. (deviceNameToOpen + (forInput ? " Input" : " Output")).toCString());
  199105. const int portId
  199106. = snd_seq_create_simple_port (seqHandle,
  199107. forInput ? "in"
  199108. : "out",
  199109. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199110. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199111. forInput ? SND_SEQ_PORT_TYPE_APPLICATION
  199112. : SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199113. if (portId < 0)
  199114. {
  199115. snd_seq_close (seqHandle);
  199116. seqHandle = 0;
  199117. }
  199118. }
  199119. return seqHandle;
  199120. }
  199121. class MidiOutputDevice
  199122. {
  199123. public:
  199124. MidiOutputDevice (MidiOutput* const midiOutput_,
  199125. snd_seq_t* const seqHandle_)
  199126. :
  199127. midiOutput (midiOutput_),
  199128. seqHandle (seqHandle_),
  199129. maxEventSize (16 * 1024)
  199130. {
  199131. jassert (seqHandle != 0 && midiOutput != 0);
  199132. snd_midi_event_new (maxEventSize, &midiParser);
  199133. }
  199134. ~MidiOutputDevice()
  199135. {
  199136. snd_midi_event_free (midiParser);
  199137. snd_seq_close (seqHandle);
  199138. }
  199139. void sendMessageNow (const MidiMessage& message)
  199140. {
  199141. if (message.getRawDataSize() > maxEventSize)
  199142. {
  199143. maxEventSize = message.getRawDataSize();
  199144. snd_midi_event_free (midiParser);
  199145. snd_midi_event_new (maxEventSize, &midiParser);
  199146. }
  199147. snd_seq_event_t event;
  199148. snd_seq_ev_clear (&event);
  199149. snd_midi_event_encode (midiParser,
  199150. message.getRawData(),
  199151. message.getRawDataSize(),
  199152. &event);
  199153. snd_midi_event_reset_encode (midiParser);
  199154. snd_seq_ev_set_source (&event, 0);
  199155. snd_seq_ev_set_subs (&event);
  199156. snd_seq_ev_set_direct (&event);
  199157. snd_seq_event_output (seqHandle, &event);
  199158. snd_seq_drain_output (seqHandle);
  199159. }
  199160. juce_UseDebuggingNewOperator
  199161. private:
  199162. MidiOutput* const midiOutput;
  199163. snd_seq_t* const seqHandle;
  199164. snd_midi_event_t* midiParser;
  199165. int maxEventSize;
  199166. };
  199167. const StringArray MidiOutput::getDevices()
  199168. {
  199169. StringArray devices;
  199170. iterateDevices (false, devices, -1);
  199171. return devices;
  199172. }
  199173. int MidiOutput::getDefaultDeviceIndex()
  199174. {
  199175. return 0;
  199176. }
  199177. MidiOutput* MidiOutput::openDevice (int deviceIndex)
  199178. {
  199179. MidiOutput* newDevice = 0;
  199180. StringArray devices;
  199181. snd_seq_t* const handle = iterateDevices (false, devices, deviceIndex);
  199182. if (handle != 0)
  199183. {
  199184. newDevice = new MidiOutput();
  199185. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199186. }
  199187. return newDevice;
  199188. }
  199189. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  199190. {
  199191. MidiOutput* newDevice = 0;
  199192. snd_seq_t* const handle = createDevice (false, deviceName);
  199193. if (handle != 0)
  199194. {
  199195. newDevice = new MidiOutput();
  199196. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199197. }
  199198. return newDevice;
  199199. }
  199200. MidiOutput::~MidiOutput()
  199201. {
  199202. MidiOutputDevice* const device = (MidiOutputDevice*) internal;
  199203. delete device;
  199204. }
  199205. void MidiOutput::reset()
  199206. {
  199207. }
  199208. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  199209. {
  199210. return false;
  199211. }
  199212. void MidiOutput::setVolume (float leftVol, float rightVol)
  199213. {
  199214. }
  199215. void MidiOutput::sendMessageNow (const MidiMessage& message)
  199216. {
  199217. ((MidiOutputDevice*) internal)->sendMessageNow (message);
  199218. }
  199219. class MidiInputThread : public Thread
  199220. {
  199221. public:
  199222. MidiInputThread (MidiInput* const midiInput_,
  199223. snd_seq_t* const seqHandle_,
  199224. MidiInputCallback* const callback_)
  199225. : Thread ("Juce MIDI Input"),
  199226. midiInput (midiInput_),
  199227. seqHandle (seqHandle_),
  199228. callback (callback_)
  199229. {
  199230. jassert (seqHandle != 0 && callback != 0 && midiInput != 0);
  199231. }
  199232. ~MidiInputThread()
  199233. {
  199234. snd_seq_close (seqHandle);
  199235. }
  199236. void run()
  199237. {
  199238. const int maxEventSize = 16 * 1024;
  199239. snd_midi_event_t* midiParser;
  199240. if (snd_midi_event_new (maxEventSize, &midiParser) >= 0)
  199241. {
  199242. HeapBlock <uint8> buffer (maxEventSize);
  199243. const int numPfds = snd_seq_poll_descriptors_count (seqHandle, POLLIN);
  199244. struct pollfd* const pfd = (struct pollfd*) alloca (numPfds * sizeof (struct pollfd));
  199245. snd_seq_poll_descriptors (seqHandle, pfd, numPfds, POLLIN);
  199246. while (! threadShouldExit())
  199247. {
  199248. if (poll (pfd, numPfds, 500) > 0)
  199249. {
  199250. snd_seq_event_t* inputEvent = 0;
  199251. snd_seq_nonblock (seqHandle, 1);
  199252. do
  199253. {
  199254. if (snd_seq_event_input (seqHandle, &inputEvent) >= 0)
  199255. {
  199256. // xxx what about SYSEXes that are too big for the buffer?
  199257. const int numBytes = snd_midi_event_decode (midiParser, buffer, maxEventSize, inputEvent);
  199258. snd_midi_event_reset_decode (midiParser);
  199259. if (numBytes > 0)
  199260. {
  199261. const MidiMessage message ((const uint8*) buffer,
  199262. numBytes,
  199263. Time::getMillisecondCounter() * 0.001);
  199264. callback->handleIncomingMidiMessage (midiInput, message);
  199265. }
  199266. snd_seq_free_event (inputEvent);
  199267. }
  199268. }
  199269. while (snd_seq_event_input_pending (seqHandle, 0) > 0);
  199270. snd_seq_free_event (inputEvent);
  199271. }
  199272. }
  199273. snd_midi_event_free (midiParser);
  199274. }
  199275. };
  199276. juce_UseDebuggingNewOperator
  199277. private:
  199278. MidiInput* const midiInput;
  199279. snd_seq_t* const seqHandle;
  199280. MidiInputCallback* const callback;
  199281. };
  199282. MidiInput::MidiInput (const String& name_)
  199283. : name (name_),
  199284. internal (0)
  199285. {
  199286. }
  199287. MidiInput::~MidiInput()
  199288. {
  199289. stop();
  199290. MidiInputThread* const thread = (MidiInputThread*) internal;
  199291. delete thread;
  199292. }
  199293. void MidiInput::start()
  199294. {
  199295. ((MidiInputThread*) internal)->startThread();
  199296. }
  199297. void MidiInput::stop()
  199298. {
  199299. ((MidiInputThread*) internal)->stopThread (3000);
  199300. }
  199301. int MidiInput::getDefaultDeviceIndex()
  199302. {
  199303. return 0;
  199304. }
  199305. const StringArray MidiInput::getDevices()
  199306. {
  199307. StringArray devices;
  199308. iterateDevices (true, devices, -1);
  199309. return devices;
  199310. }
  199311. MidiInput* MidiInput::openDevice (int deviceIndex, MidiInputCallback* callback)
  199312. {
  199313. MidiInput* newDevice = 0;
  199314. StringArray devices;
  199315. snd_seq_t* const handle = iterateDevices (true, devices, deviceIndex);
  199316. if (handle != 0)
  199317. {
  199318. newDevice = new MidiInput (devices [deviceIndex]);
  199319. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199320. }
  199321. return newDevice;
  199322. }
  199323. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  199324. {
  199325. MidiInput* newDevice = 0;
  199326. snd_seq_t* const handle = createDevice (true, deviceName);
  199327. if (handle != 0)
  199328. {
  199329. newDevice = new MidiInput (deviceName);
  199330. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199331. }
  199332. return newDevice;
  199333. }
  199334. #else
  199335. // (These are just stub functions if ALSA is unavailable...)
  199336. const StringArray MidiOutput::getDevices() { return StringArray(); }
  199337. int MidiOutput::getDefaultDeviceIndex() { return 0; }
  199338. MidiOutput* MidiOutput::openDevice (int) { return 0; }
  199339. MidiOutput* MidiOutput::createNewDevice (const String&) { return 0; }
  199340. MidiOutput::~MidiOutput() {}
  199341. void MidiOutput::reset() {}
  199342. bool MidiOutput::getVolume (float&, float&) { return false; }
  199343. void MidiOutput::setVolume (float, float) {}
  199344. void MidiOutput::sendMessageNow (const MidiMessage&) {}
  199345. MidiInput::MidiInput (const String& name_) : name (name_), internal (0) {}
  199346. MidiInput::~MidiInput() {}
  199347. void MidiInput::start() {}
  199348. void MidiInput::stop() {}
  199349. int MidiInput::getDefaultDeviceIndex() { return 0; }
  199350. const StringArray MidiInput::getDevices() { return StringArray(); }
  199351. MidiInput* MidiInput::openDevice (int, MidiInputCallback*) { return 0; }
  199352. MidiInput* MidiInput::createNewDevice (const String&, MidiInputCallback*) { return 0; }
  199353. #endif
  199354. #endif
  199355. /*** End of inlined file: juce_linux_Midi.cpp ***/
  199356. /*** Start of inlined file: juce_linux_AudioCDReader.cpp ***/
  199357. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199358. // compiled on its own).
  199359. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  199360. AudioCDReader::AudioCDReader()
  199361. : AudioFormatReader (0, "CD Audio")
  199362. {
  199363. }
  199364. const StringArray AudioCDReader::getAvailableCDNames()
  199365. {
  199366. StringArray names;
  199367. return names;
  199368. }
  199369. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  199370. {
  199371. return 0;
  199372. }
  199373. AudioCDReader::~AudioCDReader()
  199374. {
  199375. }
  199376. void AudioCDReader::refreshTrackLengths()
  199377. {
  199378. }
  199379. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  199380. int64 startSampleInFile, int numSamples)
  199381. {
  199382. return false;
  199383. }
  199384. bool AudioCDReader::isCDStillPresent() const
  199385. {
  199386. return false;
  199387. }
  199388. int AudioCDReader::getNumTracks() const
  199389. {
  199390. return 0;
  199391. }
  199392. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  199393. {
  199394. return 0;
  199395. }
  199396. bool AudioCDReader::isTrackAudio (int trackNum) const
  199397. {
  199398. return false;
  199399. }
  199400. void AudioCDReader::enableIndexScanning (bool b)
  199401. {
  199402. }
  199403. int AudioCDReader::getLastIndex() const
  199404. {
  199405. return 0;
  199406. }
  199407. const Array<int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  199408. {
  199409. return Array<int>();
  199410. }
  199411. int AudioCDReader::getCDDBId()
  199412. {
  199413. return 0;
  199414. }
  199415. #endif
  199416. /*** End of inlined file: juce_linux_AudioCDReader.cpp ***/
  199417. /*** Start of inlined file: juce_linux_FileChooser.cpp ***/
  199418. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199419. // compiled on its own).
  199420. #if JUCE_INCLUDED_FILE
  199421. void FileChooser::showPlatformDialog (Array<File>& results,
  199422. const String& title,
  199423. const File& file,
  199424. const String& filters,
  199425. bool isDirectory,
  199426. bool selectsFiles,
  199427. bool isSave,
  199428. bool warnAboutOverwritingExistingFiles,
  199429. bool selectMultipleFiles,
  199430. FilePreviewComponent* previewComponent)
  199431. {
  199432. const String separator (":");
  199433. String command ("zenity --file-selection");
  199434. if (title.isNotEmpty())
  199435. command << " --title=\"" << title << "\"";
  199436. if (file != File::nonexistent)
  199437. command << " --filename=\"" << file.getFullPathName () << "\"";
  199438. if (isDirectory)
  199439. command << " --directory";
  199440. if (isSave)
  199441. command << " --save";
  199442. if (selectMultipleFiles)
  199443. command << " --multiple --separator=\"" << separator << "\"";
  199444. command << " 2>&1";
  199445. MemoryOutputStream result;
  199446. int status = -1;
  199447. FILE* stream = popen (command.toUTF8(), "r");
  199448. if (stream != 0)
  199449. {
  199450. for (;;)
  199451. {
  199452. char buffer [1024];
  199453. const int bytesRead = fread (buffer, 1, sizeof (buffer), stream);
  199454. if (bytesRead <= 0)
  199455. break;
  199456. result.write (buffer, bytesRead);
  199457. }
  199458. status = pclose (stream);
  199459. }
  199460. if (status == 0)
  199461. {
  199462. String resultString (String::fromUTF8 (result.getData(), result.getDataSize()));
  199463. StringArray tokens;
  199464. if (selectMultipleFiles)
  199465. tokens.addTokens (resultString, separator, String::empty);
  199466. else
  199467. tokens.add (resultString);
  199468. for (int i = 0; i < tokens.size(); i++)
  199469. results.add (File (tokens[i]));
  199470. return;
  199471. }
  199472. //xxx ain't got one!
  199473. jassertfalse
  199474. }
  199475. #endif
  199476. /*** End of inlined file: juce_linux_FileChooser.cpp ***/
  199477. /*** Start of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199478. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199479. // compiled on its own).
  199480. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  199481. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  199482. : browser (0),
  199483. blankPageShown (false),
  199484. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  199485. {
  199486. setOpaque (true);
  199487. }
  199488. WebBrowserComponent::~WebBrowserComponent()
  199489. {
  199490. }
  199491. void WebBrowserComponent::goToURL (const String& url,
  199492. const StringArray* headers,
  199493. const MemoryBlock* postData)
  199494. {
  199495. lastURL = url;
  199496. lastHeaders.clear();
  199497. if (headers != 0)
  199498. lastHeaders = *headers;
  199499. lastPostData.setSize (0);
  199500. if (postData != 0)
  199501. lastPostData = *postData;
  199502. blankPageShown = false;
  199503. }
  199504. void WebBrowserComponent::stop()
  199505. {
  199506. }
  199507. void WebBrowserComponent::goBack()
  199508. {
  199509. lastURL = String::empty;
  199510. blankPageShown = false;
  199511. }
  199512. void WebBrowserComponent::goForward()
  199513. {
  199514. lastURL = String::empty;
  199515. }
  199516. void WebBrowserComponent::refresh()
  199517. {
  199518. }
  199519. void WebBrowserComponent::paint (Graphics& g)
  199520. {
  199521. g.fillAll (Colours::white);
  199522. }
  199523. void WebBrowserComponent::checkWindowAssociation()
  199524. {
  199525. }
  199526. void WebBrowserComponent::reloadLastURL()
  199527. {
  199528. if (lastURL.isNotEmpty())
  199529. {
  199530. goToURL (lastURL, &lastHeaders, &lastPostData);
  199531. lastURL = String::empty;
  199532. }
  199533. }
  199534. void WebBrowserComponent::parentHierarchyChanged()
  199535. {
  199536. checkWindowAssociation();
  199537. }
  199538. void WebBrowserComponent::resized()
  199539. {
  199540. }
  199541. void WebBrowserComponent::visibilityChanged()
  199542. {
  199543. checkWindowAssociation();
  199544. }
  199545. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  199546. {
  199547. return true;
  199548. }
  199549. #endif
  199550. /*** End of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199551. #endif
  199552. END_JUCE_NAMESPACE
  199553. #endif
  199554. /*** End of inlined file: juce_linux_NativeCode.cpp ***/
  199555. #endif
  199556. #if JUCE_MAC || JUCE_IPHONE
  199557. /*** Start of inlined file: juce_mac_NativeCode.mm ***/
  199558. #if JUCE_MAC || JUCE_IPHONE
  199559. BEGIN_JUCE_NAMESPACE
  199560. #undef Point
  199561. #define JUCE_INCLUDED_FILE 1
  199562. // Now include the actual code files..
  199563. /*** Start of inlined file: juce_mac_ObjCSuffix.h ***/
  199564. #ifndef JUCE_ObjCExtraSuffix
  199565. #define JUCE_ObjCExtraSuffix 3
  199566. #endif
  199567. #define appendMacro1(a, b, c, d, e) a ## _ ## b ## _ ## c ## _ ## d ## _ ## e
  199568. #define appendMacro2(a, b, c, d, e) appendMacro1(a, b, c, d, e)
  199569. #define MakeObjCClassName(rootName) appendMacro2 (rootName, JUCE_MAJOR_VERSION, JUCE_MINOR_VERSION, JUCE_BUILDNUMBER, JUCE_ObjCExtraSuffix)
  199570. /*** End of inlined file: juce_mac_ObjCSuffix.h ***/
  199571. /*** Start of inlined file: juce_mac_Strings.mm ***/
  199572. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199573. // compiled on its own).
  199574. #if JUCE_INCLUDED_FILE
  199575. static const String nsStringToJuce (NSString* s)
  199576. {
  199577. return String::fromUTF8 ([s UTF8String]);
  199578. }
  199579. static NSString* juceStringToNS (const String& s)
  199580. {
  199581. return [NSString stringWithUTF8String: s.toUTF8()];
  199582. }
  199583. static const String convertUTF16ToString (const UniChar* utf16)
  199584. {
  199585. String s;
  199586. while (*utf16 != 0)
  199587. s += (juce_wchar) *utf16++;
  199588. return s;
  199589. }
  199590. const String PlatformUtilities::cfStringToJuceString (CFStringRef cfString)
  199591. {
  199592. String result;
  199593. if (cfString != 0)
  199594. {
  199595. CFRange range = { 0, CFStringGetLength (cfString) };
  199596. HeapBlock <UniChar> u (range.length + 1);
  199597. CFStringGetCharacters (cfString, range, u);
  199598. u[range.length] = 0;
  199599. result = convertUTF16ToString (u);
  199600. }
  199601. return result;
  199602. }
  199603. CFStringRef PlatformUtilities::juceStringToCFString (const String& s)
  199604. {
  199605. const int len = s.length();
  199606. const juce_wchar* t = (const juce_wchar*) s;
  199607. HeapBlock <UniChar> temp (len + 2);
  199608. for (int i = 0; i <= len; ++i)
  199609. temp[i] = t[i];
  199610. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  199611. }
  199612. const String PlatformUtilities::convertToPrecomposedUnicode (const String& s)
  199613. {
  199614. #if JUCE_IPHONE
  199615. const ScopedAutoReleasePool pool;
  199616. return nsStringToJuce ([juceStringToNS (s) precomposedStringWithCanonicalMapping]);
  199617. #else
  199618. UnicodeMapping map;
  199619. map.unicodeEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  199620. kUnicodeNoSubset,
  199621. kTextEncodingDefaultFormat);
  199622. map.otherEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  199623. kUnicodeCanonicalCompVariant,
  199624. kTextEncodingDefaultFormat);
  199625. map.mappingVersion = kUnicodeUseLatestMapping;
  199626. UnicodeToTextInfo conversionInfo = 0;
  199627. String result;
  199628. if (CreateUnicodeToTextInfo (&map, &conversionInfo) == noErr)
  199629. {
  199630. const int len = s.length();
  199631. HeapBlock <UniChar> tempIn, tempOut;
  199632. tempIn.calloc (len + 2);
  199633. tempOut.calloc (len + 2);
  199634. for (int i = 0; i <= len; ++i)
  199635. tempIn[i] = s[i];
  199636. ByteCount bytesRead = 0;
  199637. ByteCount outputBufferSize = 0;
  199638. if (ConvertFromUnicodeToText (conversionInfo,
  199639. len * sizeof (UniChar), tempIn,
  199640. kUnicodeDefaultDirectionMask,
  199641. 0, 0, 0, 0,
  199642. len * sizeof (UniChar), &bytesRead,
  199643. &outputBufferSize, tempOut) == noErr)
  199644. {
  199645. result.preallocateStorage (bytesRead / sizeof (UniChar) + 2);
  199646. tchar* t = const_cast <tchar*> ((const tchar*) result);
  199647. unsigned int i;
  199648. for (i = 0; i < bytesRead / sizeof (UniChar); ++i)
  199649. t[i] = (tchar) tempOut[i];
  199650. t[i] = 0;
  199651. }
  199652. DisposeUnicodeToTextInfo (&conversionInfo);
  199653. }
  199654. return result;
  199655. #endif
  199656. }
  199657. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  199658. void SystemClipboard::copyTextToClipboard (const String& text)
  199659. {
  199660. #if JUCE_IPHONE
  199661. [[UIPasteboard generalPasteboard] setValue: juceStringToNS (text)
  199662. forPasteboardType: @"public.text"];
  199663. #else
  199664. [[NSPasteboard generalPasteboard] declareTypes: [NSArray arrayWithObject: NSStringPboardType]
  199665. owner: nil];
  199666. [[NSPasteboard generalPasteboard] setString: juceStringToNS (text)
  199667. forType: NSStringPboardType];
  199668. #endif
  199669. }
  199670. const String SystemClipboard::getTextFromClipboard()
  199671. {
  199672. #if JUCE_IPHONE
  199673. NSString* text = [[UIPasteboard generalPasteboard] valueForPasteboardType: @"public.text"];
  199674. #else
  199675. NSString* text = [[NSPasteboard generalPasteboard] stringForType: NSStringPboardType];
  199676. #endif
  199677. return text == 0 ? String::empty
  199678. : nsStringToJuce (text);
  199679. }
  199680. #endif
  199681. #endif
  199682. /*** End of inlined file: juce_mac_Strings.mm ***/
  199683. /*** Start of inlined file: juce_mac_SystemStats.mm ***/
  199684. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199685. // compiled on its own).
  199686. #if JUCE_INCLUDED_FILE
  199687. namespace SystemStatsHelpers
  199688. {
  199689. static int64 highResTimerFrequency = 0;
  199690. static double highResTimerToMillisecRatio = 0;
  199691. #if JUCE_INTEL
  199692. static void juce_getCpuVendor (char* const v) throw()
  199693. {
  199694. int vendor[4];
  199695. zerostruct (vendor);
  199696. int dummy = 0;
  199697. asm ("mov %%ebx, %%esi \n\t"
  199698. "cpuid \n\t"
  199699. "xchg %%esi, %%ebx"
  199700. : "=a" (dummy), "=S" (vendor[0]), "=c" (vendor[2]), "=d" (vendor[1]) : "a" (0));
  199701. memcpy (v, vendor, 16);
  199702. }
  199703. static unsigned int getCPUIDWord (unsigned int& familyModel, unsigned int& extFeatures)
  199704. {
  199705. unsigned int cpu = 0;
  199706. unsigned int ext = 0;
  199707. unsigned int family = 0;
  199708. unsigned int dummy = 0;
  199709. asm ("mov %%ebx, %%esi \n\t"
  199710. "cpuid \n\t"
  199711. "xchg %%esi, %%ebx"
  199712. : "=a" (family), "=S" (ext), "=c" (dummy), "=d" (cpu) : "a" (1));
  199713. familyModel = family;
  199714. extFeatures = ext;
  199715. return cpu;
  199716. }
  199717. struct CPUFlags
  199718. {
  199719. bool hasMMX : 1;
  199720. bool hasSSE : 1;
  199721. bool hasSSE2 : 1;
  199722. bool has3DNow : 1;
  199723. };
  199724. static CPUFlags cpuFlags;
  199725. #endif
  199726. }
  199727. void SystemStats::initialiseStats() throw()
  199728. {
  199729. using namespace SystemStatsHelpers;
  199730. static bool initialised = false;
  199731. if (! initialised)
  199732. {
  199733. initialised = true;
  199734. #if JUCE_MAC
  199735. // extremely annoying: adding this line stops the apple menu items from working. Of
  199736. // course, not adding it means that carbon windows (e.g. in plugins) won't get
  199737. // any events.
  199738. //NSApplicationLoad();
  199739. [NSApplication sharedApplication];
  199740. #endif
  199741. #if JUCE_INTEL
  199742. {
  199743. unsigned int familyModel, extFeatures;
  199744. const unsigned int features = getCPUIDWord (familyModel, extFeatures);
  199745. cpuFlags.hasMMX = ((features & (1 << 23)) != 0);
  199746. cpuFlags.hasSSE = ((features & (1 << 25)) != 0);
  199747. cpuFlags.hasSSE2 = ((features & (1 << 26)) != 0);
  199748. cpuFlags.has3DNow = ((extFeatures & (1 << 31)) != 0);
  199749. }
  199750. #endif
  199751. mach_timebase_info_data_t timebase;
  199752. (void) mach_timebase_info (&timebase);
  199753. highResTimerFrequency = (int64) (1.0e9 * timebase.denom / timebase.numer);
  199754. highResTimerToMillisecRatio = timebase.numer / (1.0e6 * timebase.denom);
  199755. String s (SystemStats::getJUCEVersion());
  199756. rlimit lim;
  199757. getrlimit (RLIMIT_NOFILE, &lim);
  199758. lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
  199759. setrlimit (RLIMIT_NOFILE, &lim);
  199760. }
  199761. }
  199762. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  199763. {
  199764. return MacOSX;
  199765. }
  199766. const String SystemStats::getOperatingSystemName() throw()
  199767. {
  199768. return "Mac OS X";
  199769. }
  199770. bool SystemStats::isOperatingSystem64Bit() throw()
  199771. {
  199772. #if JUCE_64BIT
  199773. return true;
  199774. #else
  199775. //xxx not sure how to find this out?..
  199776. return false;
  199777. #endif
  199778. }
  199779. int SystemStats::getMemorySizeInMegabytes() throw()
  199780. {
  199781. uint64 mem = 0;
  199782. size_t memSize = sizeof (mem);
  199783. int mib[] = { CTL_HW, HW_MEMSIZE };
  199784. sysctl (mib, 2, &mem, &memSize, 0, 0);
  199785. return (int) (mem / (1024 * 1024));
  199786. }
  199787. bool SystemStats::hasMMX() throw()
  199788. {
  199789. #if JUCE_INTEL
  199790. return SystemStatsHelpers::cpuFlags.hasMMX;
  199791. #else
  199792. return false;
  199793. #endif
  199794. }
  199795. bool SystemStats::hasSSE() throw()
  199796. {
  199797. #if JUCE_INTEL
  199798. return SystemStatsHelpers::cpuFlags.hasSSE;
  199799. #else
  199800. return false;
  199801. #endif
  199802. }
  199803. bool SystemStats::hasSSE2() throw()
  199804. {
  199805. #if JUCE_INTEL
  199806. return SystemStatsHelpers::cpuFlags.hasSSE2;
  199807. #else
  199808. return false;
  199809. #endif
  199810. }
  199811. bool SystemStats::has3DNow() throw()
  199812. {
  199813. #if JUCE_INTEL
  199814. return SystemStatsHelpers::cpuFlags.has3DNow;
  199815. #else
  199816. return false;
  199817. #endif
  199818. }
  199819. const String SystemStats::getCpuVendor() throw()
  199820. {
  199821. #if JUCE_INTEL
  199822. char v [16];
  199823. SystemStatsHelpers::juce_getCpuVendor (v);
  199824. return String (v, 16);
  199825. #else
  199826. return String::empty;
  199827. #endif
  199828. }
  199829. int SystemStats::getCpuSpeedInMegaherz() throw()
  199830. {
  199831. uint64 speedHz = 0;
  199832. size_t speedSize = sizeof (speedHz);
  199833. int mib[] = { CTL_HW, HW_CPU_FREQ };
  199834. sysctl (mib, 2, &speedHz, &speedSize, 0, 0);
  199835. #if JUCE_BIG_ENDIAN
  199836. if (speedSize == 4)
  199837. speedHz >>= 32;
  199838. #endif
  199839. return (int) (speedHz / 1000000);
  199840. }
  199841. int SystemStats::getNumCpus() throw()
  199842. {
  199843. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  199844. return (int) [[NSProcessInfo processInfo] activeProcessorCount];
  199845. #else
  199846. return MPProcessors();
  199847. #endif
  199848. }
  199849. const String SystemStats::getLogonName()
  199850. {
  199851. return nsStringToJuce (NSUserName());
  199852. }
  199853. const String SystemStats::getFullUserName()
  199854. {
  199855. return nsStringToJuce (NSFullUserName());
  199856. }
  199857. uint32 juce_millisecondsSinceStartup() throw()
  199858. {
  199859. return (uint32) (mach_absolute_time() * SystemStatsHelpers::highResTimerToMillisecRatio);
  199860. }
  199861. double Time::getMillisecondCounterHiRes() throw()
  199862. {
  199863. return mach_absolute_time() * SystemStatsHelpers::highResTimerToMillisecRatio;
  199864. }
  199865. int64 Time::getHighResolutionTicks() throw()
  199866. {
  199867. return (int64) mach_absolute_time();
  199868. }
  199869. int64 Time::getHighResolutionTicksPerSecond() throw()
  199870. {
  199871. return SystemStatsHelpers::highResTimerFrequency;
  199872. }
  199873. int64 SystemStats::getClockCycleCounter() throw()
  199874. {
  199875. return (int64) mach_absolute_time();
  199876. }
  199877. bool Time::setSystemTimeToThisTime() const throw()
  199878. {
  199879. jassertfalse
  199880. return false;
  199881. }
  199882. int SystemStats::getPageSize() throw()
  199883. {
  199884. return (int) NSPageSize();
  199885. }
  199886. void PlatformUtilities::fpuReset()
  199887. {
  199888. }
  199889. #endif
  199890. /*** End of inlined file: juce_mac_SystemStats.mm ***/
  199891. /*** Start of inlined file: juce_mac_Network.mm ***/
  199892. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199893. // compiled on its own).
  199894. #if JUCE_INCLUDED_FILE
  199895. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
  199896. {
  199897. #ifndef IFT_ETHER
  199898. #define IFT_ETHER 6
  199899. #endif
  199900. ifaddrs* addrs = 0;
  199901. int numResults = 0;
  199902. if (getifaddrs (&addrs) == 0)
  199903. {
  199904. const ifaddrs* cursor = addrs;
  199905. while (cursor != 0 && numResults < maxNum)
  199906. {
  199907. sockaddr_storage* sto = (sockaddr_storage*) cursor->ifa_addr;
  199908. if (sto->ss_family == AF_LINK)
  199909. {
  199910. const sockaddr_dl* const sadd = (const sockaddr_dl*) cursor->ifa_addr;
  199911. if (sadd->sdl_type == IFT_ETHER)
  199912. {
  199913. const uint8* const addr = ((const uint8*) sadd->sdl_data) + sadd->sdl_nlen;
  199914. uint64 a = 0;
  199915. for (int i = 6; --i >= 0;)
  199916. a = (a << 8) | addr [littleEndian ? i : (5 - i)];
  199917. *addresses++ = (int64) a;
  199918. ++numResults;
  199919. }
  199920. }
  199921. cursor = cursor->ifa_next;
  199922. }
  199923. freeifaddrs (addrs);
  199924. }
  199925. return numResults;
  199926. }
  199927. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  199928. const String& emailSubject,
  199929. const String& bodyText,
  199930. const StringArray& filesToAttach)
  199931. {
  199932. #if JUCE_IPHONE
  199933. //xxx probably need to use MFMailComposeViewController
  199934. jassertfalse
  199935. return false;
  199936. #else
  199937. const ScopedAutoReleasePool pool;
  199938. String script;
  199939. script << "tell application \"Mail\"\r\n"
  199940. "set newMessage to make new outgoing message with properties {subject:\""
  199941. << emailSubject.replace (T("\""), T("\\\""))
  199942. << "\", content:\""
  199943. << bodyText.replace (T("\""), T("\\\""))
  199944. << "\" & return & return}\r\n"
  199945. "tell newMessage\r\n"
  199946. "set visible to true\r\n"
  199947. "set sender to \"sdfsdfsdfewf\"\r\n"
  199948. "make new to recipient at end of to recipients with properties {address:\""
  199949. << targetEmailAddress
  199950. << "\"}\r\n";
  199951. for (int i = 0; i < filesToAttach.size(); ++i)
  199952. {
  199953. script << "tell content\r\n"
  199954. "make new attachment with properties {file name:\""
  199955. << filesToAttach[i].replace (T("\""), T("\\\""))
  199956. << "\"} at after the last paragraph\r\n"
  199957. "end tell\r\n";
  199958. }
  199959. script << "end tell\r\n"
  199960. "end tell\r\n";
  199961. NSAppleScript* s = [[NSAppleScript alloc]
  199962. initWithSource: juceStringToNS (script)];
  199963. NSDictionary* error = 0;
  199964. const bool ok = [s executeAndReturnError: &error] != nil;
  199965. [s release];
  199966. return ok;
  199967. #endif
  199968. }
  199969. END_JUCE_NAMESPACE
  199970. using namespace JUCE_NAMESPACE;
  199971. #define JuceURLConnection MakeObjCClassName(JuceURLConnection)
  199972. @interface JuceURLConnection : NSObject
  199973. {
  199974. @public
  199975. NSURLRequest* request;
  199976. NSURLConnection* connection;
  199977. NSMutableData* data;
  199978. Thread* runLoopThread;
  199979. bool initialised, hasFailed, hasFinished;
  199980. int position;
  199981. int64 contentLength;
  199982. NSLock* dataLock;
  199983. }
  199984. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req withCallback: (URL::OpenStreamProgressCallback*) callback withContext: (void*) context;
  199985. - (void) dealloc;
  199986. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response;
  199987. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error;
  199988. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) data;
  199989. - (void) connectionDidFinishLoading: (NSURLConnection*) connection;
  199990. - (BOOL) isOpen;
  199991. - (int) read: (char*) dest numBytes: (int) num;
  199992. - (int) readPosition;
  199993. - (void) stop;
  199994. - (void) createConnection;
  199995. @end
  199996. class JuceURLConnectionMessageThread : public Thread
  199997. {
  199998. JuceURLConnection* owner;
  199999. public:
  200000. JuceURLConnectionMessageThread (JuceURLConnection* owner_)
  200001. : Thread ("http connection"),
  200002. owner (owner_)
  200003. {
  200004. }
  200005. ~JuceURLConnectionMessageThread()
  200006. {
  200007. stopThread (10000);
  200008. }
  200009. void run()
  200010. {
  200011. [owner createConnection];
  200012. while (! threadShouldExit())
  200013. {
  200014. const ScopedAutoReleasePool pool;
  200015. [[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  200016. }
  200017. }
  200018. };
  200019. @implementation JuceURLConnection
  200020. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req
  200021. withCallback: (URL::OpenStreamProgressCallback*) callback
  200022. withContext: (void*) context;
  200023. {
  200024. [super init];
  200025. request = req;
  200026. [request retain];
  200027. data = [[NSMutableData data] retain];
  200028. dataLock = [[NSLock alloc] init];
  200029. connection = 0;
  200030. initialised = false;
  200031. hasFailed = false;
  200032. hasFinished = false;
  200033. contentLength = -1;
  200034. runLoopThread = new JuceURLConnectionMessageThread (self);
  200035. runLoopThread->startThread();
  200036. while (runLoopThread->isThreadRunning() && ! initialised)
  200037. {
  200038. if (callback != 0)
  200039. callback (context, -1, (int) [[request HTTPBody] length]);
  200040. Thread::sleep (1);
  200041. }
  200042. return self;
  200043. }
  200044. - (void) dealloc
  200045. {
  200046. [self stop];
  200047. delete runLoopThread;
  200048. [connection release];
  200049. [data release];
  200050. [dataLock release];
  200051. [request release];
  200052. [super dealloc];
  200053. }
  200054. - (void) createConnection
  200055. {
  200056. connection = [[NSURLConnection alloc] initWithRequest: request
  200057. delegate: [self retain]];
  200058. if (connection == nil)
  200059. runLoopThread->signalThreadShouldExit();
  200060. }
  200061. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response
  200062. {
  200063. [dataLock lock];
  200064. [data setLength: 0];
  200065. [dataLock unlock];
  200066. initialised = true;
  200067. contentLength = [response expectedContentLength];
  200068. }
  200069. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error
  200070. {
  200071. DBG (nsStringToJuce ([error description]));
  200072. hasFailed = true;
  200073. initialised = true;
  200074. runLoopThread->signalThreadShouldExit();
  200075. }
  200076. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) newData
  200077. {
  200078. [dataLock lock];
  200079. [data appendData: newData];
  200080. [dataLock unlock];
  200081. initialised = true;
  200082. }
  200083. - (void) connectionDidFinishLoading: (NSURLConnection*) connection
  200084. {
  200085. hasFinished = true;
  200086. initialised = true;
  200087. runLoopThread->signalThreadShouldExit();
  200088. }
  200089. - (BOOL) isOpen
  200090. {
  200091. return connection != 0 && ! hasFailed;
  200092. }
  200093. - (int) readPosition
  200094. {
  200095. return position;
  200096. }
  200097. - (int) read: (char*) dest numBytes: (int) numNeeded
  200098. {
  200099. int numDone = 0;
  200100. while (numNeeded > 0)
  200101. {
  200102. int available = jmin (numNeeded, (int) [data length]);
  200103. if (available > 0)
  200104. {
  200105. [dataLock lock];
  200106. [data getBytes: dest length: available];
  200107. [data replaceBytesInRange: NSMakeRange (0, available) withBytes: nil length: 0];
  200108. [dataLock unlock];
  200109. numDone += available;
  200110. numNeeded -= available;
  200111. dest += available;
  200112. }
  200113. else
  200114. {
  200115. if (hasFailed || hasFinished)
  200116. break;
  200117. Thread::sleep (1);
  200118. }
  200119. }
  200120. position += numDone;
  200121. return numDone;
  200122. }
  200123. - (void) stop
  200124. {
  200125. [connection cancel];
  200126. runLoopThread->stopThread (10000);
  200127. }
  200128. @end
  200129. BEGIN_JUCE_NAMESPACE
  200130. bool juce_isOnLine()
  200131. {
  200132. return true;
  200133. }
  200134. void* juce_openInternetFile (const String& url,
  200135. const String& headers,
  200136. const MemoryBlock& postData,
  200137. const bool isPost,
  200138. URL::OpenStreamProgressCallback* callback,
  200139. void* callbackContext,
  200140. int timeOutMs)
  200141. {
  200142. const ScopedAutoReleasePool pool;
  200143. NSMutableURLRequest* req = [NSMutableURLRequest
  200144. requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  200145. cachePolicy: NSURLRequestUseProtocolCachePolicy
  200146. timeoutInterval: timeOutMs <= 0 ? 60.0 : (timeOutMs / 1000.0)];
  200147. if (req == nil)
  200148. return 0;
  200149. [req setHTTPMethod: isPost ? @"POST" : @"GET"];
  200150. //[req setCachePolicy: NSURLRequestReloadIgnoringLocalAndRemoteCacheData];
  200151. StringArray headerLines;
  200152. headerLines.addLines (headers);
  200153. headerLines.removeEmptyStrings (true);
  200154. for (int i = 0; i < headerLines.size(); ++i)
  200155. {
  200156. const String key (headerLines[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  200157. const String value (headerLines[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  200158. if (key.isNotEmpty() && value.isNotEmpty())
  200159. [req addValue: juceStringToNS (value) forHTTPHeaderField: juceStringToNS (key)];
  200160. }
  200161. if (isPost && postData.getSize() > 0)
  200162. {
  200163. [req setHTTPBody: [NSData dataWithBytes: postData.getData()
  200164. length: postData.getSize()]];
  200165. }
  200166. JuceURLConnection* const s = [[JuceURLConnection alloc] initWithRequest: req
  200167. withCallback: callback
  200168. withContext: callbackContext];
  200169. if ([s isOpen])
  200170. return s;
  200171. [s release];
  200172. return 0;
  200173. }
  200174. void juce_closeInternetFile (void* handle)
  200175. {
  200176. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200177. if (s != 0)
  200178. {
  200179. const ScopedAutoReleasePool pool;
  200180. [s stop];
  200181. [s release];
  200182. }
  200183. }
  200184. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  200185. {
  200186. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200187. if (s != 0)
  200188. {
  200189. const ScopedAutoReleasePool pool;
  200190. return [s read: (char*) buffer numBytes: bytesToRead];
  200191. }
  200192. return 0;
  200193. }
  200194. int64 juce_getInternetFileContentLength (void* handle)
  200195. {
  200196. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200197. if (s != 0)
  200198. return s->contentLength;
  200199. return -1;
  200200. }
  200201. int juce_seekInInternetFile (void* handle, int newPosition)
  200202. {
  200203. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200204. if (s != 0)
  200205. return [s readPosition];
  200206. return 0;
  200207. }
  200208. #endif
  200209. /*** End of inlined file: juce_mac_Network.mm ***/
  200210. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  200211. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200212. // compiled on its own).
  200213. #if JUCE_INCLUDED_FILE
  200214. struct NamedPipeInternal
  200215. {
  200216. String pipeInName, pipeOutName;
  200217. int pipeIn, pipeOut;
  200218. bool volatile createdPipe, blocked, stopReadOperation;
  200219. static void signalHandler (int) {}
  200220. };
  200221. void NamedPipe::cancelPendingReads()
  200222. {
  200223. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  200224. {
  200225. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200226. intern->stopReadOperation = true;
  200227. char buffer [1] = { 0 };
  200228. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  200229. (void) bytesWritten;
  200230. int timeout = 2000;
  200231. while (intern->blocked && --timeout >= 0)
  200232. Thread::sleep (2);
  200233. intern->stopReadOperation = false;
  200234. }
  200235. }
  200236. void NamedPipe::close()
  200237. {
  200238. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200239. if (intern != 0)
  200240. {
  200241. internal = 0;
  200242. if (intern->pipeIn != -1)
  200243. ::close (intern->pipeIn);
  200244. if (intern->pipeOut != -1)
  200245. ::close (intern->pipeOut);
  200246. if (intern->createdPipe)
  200247. {
  200248. unlink (intern->pipeInName.toUTF8());
  200249. unlink (intern->pipeOutName.toUTF8());
  200250. }
  200251. delete intern;
  200252. }
  200253. }
  200254. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  200255. {
  200256. close();
  200257. NamedPipeInternal* const intern = new NamedPipeInternal();
  200258. internal = intern;
  200259. intern->createdPipe = createPipe;
  200260. intern->blocked = false;
  200261. intern->stopReadOperation = false;
  200262. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  200263. siginterrupt (SIGPIPE, 1);
  200264. const String pipePath ("/tmp/" + File::createLegalFileName (pipeName));
  200265. intern->pipeInName = pipePath + "_in";
  200266. intern->pipeOutName = pipePath + "_out";
  200267. intern->pipeIn = -1;
  200268. intern->pipeOut = -1;
  200269. if (createPipe)
  200270. {
  200271. if ((mkfifo (intern->pipeInName.toUTF8(), 0666) && errno != EEXIST)
  200272. || (mkfifo (intern->pipeOutName.toUTF8(), 0666) && errno != EEXIST))
  200273. {
  200274. delete intern;
  200275. internal = 0;
  200276. return false;
  200277. }
  200278. }
  200279. return true;
  200280. }
  200281. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  200282. {
  200283. int bytesRead = -1;
  200284. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200285. if (intern != 0)
  200286. {
  200287. intern->blocked = true;
  200288. if (intern->pipeIn == -1)
  200289. {
  200290. if (intern->createdPipe)
  200291. intern->pipeIn = ::open (intern->pipeInName.toUTF8(), O_RDWR);
  200292. else
  200293. intern->pipeIn = ::open (intern->pipeOutName.toUTF8(), O_RDWR);
  200294. if (intern->pipeIn == -1)
  200295. {
  200296. intern->blocked = false;
  200297. return -1;
  200298. }
  200299. }
  200300. bytesRead = 0;
  200301. char* p = (char*) destBuffer;
  200302. while (bytesRead < maxBytesToRead)
  200303. {
  200304. const int bytesThisTime = maxBytesToRead - bytesRead;
  200305. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  200306. if (numRead <= 0 || intern->stopReadOperation)
  200307. {
  200308. bytesRead = -1;
  200309. break;
  200310. }
  200311. bytesRead += numRead;
  200312. p += bytesRead;
  200313. }
  200314. intern->blocked = false;
  200315. }
  200316. return bytesRead;
  200317. }
  200318. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  200319. {
  200320. int bytesWritten = -1;
  200321. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200322. if (intern != 0)
  200323. {
  200324. if (intern->pipeOut == -1)
  200325. {
  200326. if (intern->createdPipe)
  200327. intern->pipeOut = ::open (intern->pipeOutName.toUTF8(), O_WRONLY);
  200328. else
  200329. intern->pipeOut = ::open (intern->pipeInName.toUTF8(), O_WRONLY);
  200330. if (intern->pipeOut == -1)
  200331. {
  200332. return -1;
  200333. }
  200334. }
  200335. const char* p = (const char*) sourceBuffer;
  200336. bytesWritten = 0;
  200337. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  200338. while (bytesWritten < numBytesToWrite
  200339. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  200340. {
  200341. const int bytesThisTime = numBytesToWrite - bytesWritten;
  200342. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  200343. if (numWritten <= 0)
  200344. {
  200345. bytesWritten = -1;
  200346. break;
  200347. }
  200348. bytesWritten += numWritten;
  200349. p += bytesWritten;
  200350. }
  200351. }
  200352. return bytesWritten;
  200353. }
  200354. #endif
  200355. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  200356. /*** Start of inlined file: juce_mac_Threads.mm ***/
  200357. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200358. // compiled on its own).
  200359. #if JUCE_INCLUDED_FILE
  200360. void JUCE_API juce_threadEntryPoint (void*);
  200361. void* threadEntryProc (void* userData)
  200362. {
  200363. const ScopedAutoReleasePool pool;
  200364. juce_threadEntryPoint (userData);
  200365. return 0;
  200366. }
  200367. void* juce_createThread (void* userData)
  200368. {
  200369. pthread_t handle = 0;
  200370. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  200371. {
  200372. pthread_detach (handle);
  200373. return (void*) handle;
  200374. }
  200375. return 0;
  200376. }
  200377. void juce_killThread (void* handle)
  200378. {
  200379. if (handle != 0)
  200380. pthread_cancel ((pthread_t) handle);
  200381. }
  200382. void juce_setCurrentThreadName (const String& /*name*/)
  200383. {
  200384. }
  200385. bool juce_setThreadPriority (void* handle, int priority)
  200386. {
  200387. if (handle == 0)
  200388. handle = (void*) pthread_self();
  200389. struct sched_param param;
  200390. int policy;
  200391. pthread_getschedparam ((pthread_t) handle, &policy, &param);
  200392. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  200393. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  200394. }
  200395. Thread::ThreadID Thread::getCurrentThreadId()
  200396. {
  200397. return static_cast <ThreadID> (pthread_self());
  200398. }
  200399. void Thread::yield()
  200400. {
  200401. sched_yield();
  200402. }
  200403. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  200404. {
  200405. // xxx
  200406. jassertfalse
  200407. }
  200408. bool Process::isForegroundProcess()
  200409. {
  200410. #if JUCE_MAC
  200411. return [NSApp isActive];
  200412. #else
  200413. return true; // xxx change this if more than one app is ever possible on the iPhone!
  200414. #endif
  200415. }
  200416. void Process::raisePrivilege()
  200417. {
  200418. jassertfalse
  200419. }
  200420. void Process::lowerPrivilege()
  200421. {
  200422. jassertfalse
  200423. }
  200424. void Process::terminate()
  200425. {
  200426. exit (0);
  200427. }
  200428. void Process::setPriority (ProcessPriority p)
  200429. {
  200430. // xxx
  200431. }
  200432. #endif
  200433. /*** End of inlined file: juce_mac_Threads.mm ***/
  200434. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  200435. CriticalSection::CriticalSection() throw()
  200436. {
  200437. pthread_mutexattr_t atts;
  200438. pthread_mutexattr_init (&atts);
  200439. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  200440. pthread_mutex_init (&internal, &atts);
  200441. }
  200442. CriticalSection::~CriticalSection() throw()
  200443. {
  200444. pthread_mutex_destroy (&internal);
  200445. }
  200446. void CriticalSection::enter() const throw()
  200447. {
  200448. pthread_mutex_lock (&internal);
  200449. }
  200450. bool CriticalSection::tryEnter() const throw()
  200451. {
  200452. return pthread_mutex_trylock (&internal) == 0;
  200453. }
  200454. void CriticalSection::exit() const throw()
  200455. {
  200456. pthread_mutex_unlock (&internal);
  200457. }
  200458. class WaitableEventImpl
  200459. {
  200460. public:
  200461. WaitableEventImpl()
  200462. : triggered (false)
  200463. {
  200464. pthread_cond_init (&condition, 0);
  200465. pthread_mutex_init (&mutex, 0);
  200466. }
  200467. ~WaitableEventImpl()
  200468. {
  200469. pthread_cond_destroy (&condition);
  200470. pthread_mutex_destroy (&mutex);
  200471. }
  200472. bool wait (const int timeOutMillisecs) throw()
  200473. {
  200474. pthread_mutex_lock (&mutex);
  200475. if (! triggered)
  200476. {
  200477. if (timeOutMillisecs < 0)
  200478. {
  200479. do
  200480. {
  200481. pthread_cond_wait (&condition, &mutex);
  200482. }
  200483. while (! triggered);
  200484. }
  200485. else
  200486. {
  200487. struct timeval now;
  200488. gettimeofday (&now, 0);
  200489. struct timespec time;
  200490. time.tv_sec = now.tv_sec + (timeOutMillisecs / 1000);
  200491. time.tv_nsec = (now.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  200492. if (time.tv_nsec >= 1000000000)
  200493. {
  200494. time.tv_nsec -= 1000000000;
  200495. time.tv_sec++;
  200496. }
  200497. do
  200498. {
  200499. if (pthread_cond_timedwait (&condition, &mutex, &time) == ETIMEDOUT)
  200500. {
  200501. pthread_mutex_unlock (&mutex);
  200502. return false;
  200503. }
  200504. }
  200505. while (! triggered);
  200506. }
  200507. }
  200508. triggered = false;
  200509. pthread_mutex_unlock (&mutex);
  200510. return true;
  200511. }
  200512. void signal() throw()
  200513. {
  200514. pthread_mutex_lock (&mutex);
  200515. triggered = true;
  200516. pthread_cond_broadcast (&condition);
  200517. pthread_mutex_unlock (&mutex);
  200518. }
  200519. void reset() throw()
  200520. {
  200521. pthread_mutex_lock (&mutex);
  200522. triggered = false;
  200523. pthread_mutex_unlock (&mutex);
  200524. }
  200525. private:
  200526. pthread_cond_t condition;
  200527. pthread_mutex_t mutex;
  200528. bool triggered;
  200529. WaitableEventImpl (const WaitableEventImpl&);
  200530. WaitableEventImpl& operator= (const WaitableEventImpl&);
  200531. };
  200532. WaitableEvent::WaitableEvent() throw()
  200533. : internal (new WaitableEventImpl())
  200534. {
  200535. }
  200536. WaitableEvent::~WaitableEvent() throw()
  200537. {
  200538. delete static_cast <WaitableEventImpl*> (internal);
  200539. }
  200540. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  200541. {
  200542. return static_cast <WaitableEventImpl*> (internal)->wait (timeOutMillisecs);
  200543. }
  200544. void WaitableEvent::signal() const throw()
  200545. {
  200546. static_cast <WaitableEventImpl*> (internal)->signal();
  200547. }
  200548. void WaitableEvent::reset() const throw()
  200549. {
  200550. static_cast <WaitableEventImpl*> (internal)->reset();
  200551. }
  200552. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  200553. {
  200554. struct timespec time;
  200555. time.tv_sec = millisecs / 1000;
  200556. time.tv_nsec = (millisecs % 1000) * 1000000;
  200557. nanosleep (&time, 0);
  200558. }
  200559. const juce_wchar File::separator = '/';
  200560. const juce_wchar* File::separatorString = T("/");
  200561. const File File::getCurrentWorkingDirectory()
  200562. {
  200563. HeapBlock<char> heapBuffer;
  200564. char localBuffer [1024];
  200565. char* cwd = getcwd (localBuffer, sizeof (localBuffer) - 1);
  200566. int bufferSize = 4096;
  200567. while (cwd == 0 && errno == ERANGE)
  200568. {
  200569. heapBuffer.malloc (bufferSize);
  200570. cwd = getcwd (heapBuffer, bufferSize - 1);
  200571. bufferSize += 1024;
  200572. }
  200573. return File (String::fromUTF8 (cwd));
  200574. }
  200575. bool File::setAsCurrentWorkingDirectory() const
  200576. {
  200577. return chdir (getFullPathName().toUTF8()) == 0;
  200578. }
  200579. bool juce_copyFile (const String& s, const String& d);
  200580. static bool juce_stat (const String& fileName, struct stat& info)
  200581. {
  200582. return fileName.isNotEmpty()
  200583. && (stat (fileName.toUTF8(), &info) == 0);
  200584. }
  200585. bool juce_isDirectory (const String& fileName)
  200586. {
  200587. struct stat info;
  200588. return fileName.isEmpty()
  200589. || (juce_stat (fileName, info)
  200590. && ((info.st_mode & S_IFDIR) != 0));
  200591. }
  200592. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  200593. {
  200594. if (fileName.isEmpty())
  200595. return false;
  200596. const char* const fileNameUTF8 = fileName.toUTF8();
  200597. bool exists = access (fileNameUTF8, F_OK) == 0;
  200598. if (exists && dontCountDirectories)
  200599. {
  200600. struct stat info;
  200601. const int res = stat (fileNameUTF8, &info);
  200602. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  200603. exists = false;
  200604. }
  200605. return exists;
  200606. }
  200607. int64 juce_getFileSize (const String& fileName)
  200608. {
  200609. struct stat info;
  200610. return juce_stat (fileName, info) ? info.st_size : 0;
  200611. }
  200612. bool juce_canWriteToFile (const String& fileName)
  200613. {
  200614. return access (fileName.toUTF8(), W_OK) == 0;
  200615. }
  200616. bool juce_deleteFile (const String& fileName)
  200617. {
  200618. if (juce_isDirectory (fileName))
  200619. return rmdir (fileName.toUTF8()) == 0;
  200620. else
  200621. return remove (fileName.toUTF8()) == 0;
  200622. }
  200623. bool juce_moveFile (const String& source, const String& dest)
  200624. {
  200625. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  200626. return true;
  200627. if (juce_canWriteToFile (source)
  200628. && juce_copyFile (source, dest))
  200629. {
  200630. if (juce_deleteFile (source))
  200631. return true;
  200632. juce_deleteFile (dest);
  200633. }
  200634. return false;
  200635. }
  200636. void juce_createDirectory (const String& fileName)
  200637. {
  200638. mkdir (fileName.toUTF8(), 0777);
  200639. }
  200640. void* juce_fileOpen (const String& fileName, bool forWriting)
  200641. {
  200642. int flags = O_RDONLY;
  200643. if (forWriting)
  200644. {
  200645. if (juce_fileExists (fileName, false))
  200646. {
  200647. const int f = open (fileName.toUTF8(), O_RDWR, 00644);
  200648. if (f != -1)
  200649. lseek (f, 0, SEEK_END);
  200650. return (void*) f;
  200651. }
  200652. else
  200653. {
  200654. flags = O_RDWR + O_CREAT;
  200655. }
  200656. }
  200657. return (void*) open (fileName.toUTF8(), flags, 00644);
  200658. }
  200659. void juce_fileClose (void* handle)
  200660. {
  200661. if (handle != 0)
  200662. close ((int) (pointer_sized_int) handle);
  200663. }
  200664. int juce_fileRead (void* handle, void* buffer, int size)
  200665. {
  200666. if (handle != 0)
  200667. return jmax (0, (int) read ((int) (pointer_sized_int) handle, buffer, size));
  200668. return 0;
  200669. }
  200670. int juce_fileWrite (void* handle, const void* buffer, int size)
  200671. {
  200672. if (handle != 0)
  200673. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  200674. return 0;
  200675. }
  200676. int64 juce_fileSetPosition (void* handle, int64 pos)
  200677. {
  200678. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  200679. return pos;
  200680. return -1;
  200681. }
  200682. int64 juce_fileGetPosition (void* handle)
  200683. {
  200684. if (handle != 0)
  200685. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  200686. return -1;
  200687. }
  200688. void juce_fileFlush (void* handle)
  200689. {
  200690. if (handle != 0)
  200691. fsync ((int) (pointer_sized_int) handle);
  200692. }
  200693. const File juce_getExecutableFile()
  200694. {
  200695. Dl_info exeInfo;
  200696. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  200697. return File (String::fromUTF8 (exeInfo.dli_fname));
  200698. }
  200699. // if this file doesn't exist, find a parent of it that does..
  200700. static bool doStatFS (const File* file, struct statfs& result)
  200701. {
  200702. File f (*file);
  200703. for (int i = 5; --i >= 0;)
  200704. {
  200705. if (f.exists())
  200706. break;
  200707. f = f.getParentDirectory();
  200708. }
  200709. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  200710. }
  200711. int64 File::getBytesFreeOnVolume() const
  200712. {
  200713. struct statfs buf;
  200714. if (doStatFS (this, buf))
  200715. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  200716. return 0;
  200717. }
  200718. int64 File::getVolumeTotalSize() const
  200719. {
  200720. struct statfs buf;
  200721. if (doStatFS (this, buf))
  200722. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  200723. return 0;
  200724. }
  200725. const String juce_getVolumeLabel (const String& filenameOnVolume,
  200726. int& volumeSerialNumber)
  200727. {
  200728. volumeSerialNumber = 0;
  200729. #if JUCE_MAC
  200730. struct VolAttrBuf
  200731. {
  200732. u_int32_t length;
  200733. attrreference_t mountPointRef;
  200734. char mountPointSpace [MAXPATHLEN];
  200735. } attrBuf;
  200736. struct attrlist attrList;
  200737. zerostruct (attrList);
  200738. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  200739. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  200740. File f (filenameOnVolume);
  200741. for (;;)
  200742. {
  200743. if (getattrlist (f.getFullPathName().toUTF8(),
  200744. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  200745. {
  200746. return String::fromUTF8 (((const char*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  200747. (int) attrBuf.mountPointRef.attr_length);
  200748. }
  200749. const File parent (f.getParentDirectory());
  200750. if (f == parent)
  200751. break;
  200752. f = parent;
  200753. }
  200754. #endif
  200755. return String::empty;
  200756. }
  200757. void juce_runSystemCommand (const String& command)
  200758. {
  200759. int result = system (command.toUTF8());
  200760. (void) result;
  200761. }
  200762. const String juce_getOutputFromCommand (const String& command)
  200763. {
  200764. // slight bodge here, as we just pipe the output into a temp file and read it...
  200765. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  200766. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  200767. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  200768. String result (tempFile.loadFileAsString());
  200769. tempFile.deleteFile();
  200770. return result;
  200771. }
  200772. InterProcessLock::InterProcessLock (const String& name_)
  200773. : internal (0),
  200774. name (name_),
  200775. reentrancyLevel (0)
  200776. {
  200777. #if JUCE_MAC
  200778. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  200779. const File temp (File ("~/Library/Caches/Juce").getChildFile (name));
  200780. #else
  200781. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  200782. #endif
  200783. temp.create();
  200784. internal = open (temp.getFullPathName().toUTF8(), O_RDWR);
  200785. }
  200786. InterProcessLock::~InterProcessLock()
  200787. {
  200788. while (reentrancyLevel > 0)
  200789. this->exit();
  200790. close (internal);
  200791. }
  200792. bool InterProcessLock::enter (const int timeOutMillisecs)
  200793. {
  200794. if (internal == 0)
  200795. return false;
  200796. if (reentrancyLevel != 0)
  200797. return true;
  200798. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  200799. struct flock fl;
  200800. zerostruct (fl);
  200801. fl.l_whence = SEEK_SET;
  200802. fl.l_type = F_WRLCK;
  200803. for (;;)
  200804. {
  200805. const int result = fcntl (internal, F_SETLK, &fl);
  200806. if (result >= 0)
  200807. {
  200808. ++reentrancyLevel;
  200809. return true;
  200810. }
  200811. if (errno != EINTR)
  200812. {
  200813. if (timeOutMillisecs == 0
  200814. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  200815. break;
  200816. Thread::sleep (10);
  200817. }
  200818. }
  200819. return false;
  200820. }
  200821. void InterProcessLock::exit()
  200822. {
  200823. if (reentrancyLevel > 0 && internal != 0)
  200824. {
  200825. --reentrancyLevel;
  200826. struct flock fl;
  200827. zerostruct (fl);
  200828. fl.l_whence = SEEK_SET;
  200829. fl.l_type = F_UNLCK;
  200830. for (;;)
  200831. {
  200832. const int result = fcntl (internal, F_SETLKW, &fl);
  200833. if (result >= 0 || errno != EINTR)
  200834. break;
  200835. }
  200836. }
  200837. }
  200838. /*** End of inlined file: juce_posix_SharedCode.h ***/
  200839. /*** Start of inlined file: juce_mac_Files.mm ***/
  200840. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200841. // compiled on its own).
  200842. #if JUCE_INCLUDED_FILE
  200843. void juce_getFileTimes (const String& fileName,
  200844. int64& modificationTime,
  200845. int64& accessTime,
  200846. int64& creationTime)
  200847. {
  200848. modificationTime = 0;
  200849. accessTime = 0;
  200850. creationTime = 0;
  200851. struct stat info;
  200852. const int res = stat (fileName.toUTF8(), &info);
  200853. if (res == 0)
  200854. {
  200855. modificationTime = (int64) info.st_mtime * 1000;
  200856. accessTime = (int64) info.st_atime * 1000;
  200857. creationTime = (int64) info.st_ctime * 1000;
  200858. }
  200859. }
  200860. bool juce_setFileTimes (const String& fileName,
  200861. int64 modificationTime,
  200862. int64 accessTime,
  200863. int64 creationTime)
  200864. {
  200865. struct utimbuf times;
  200866. times.actime = (time_t) (accessTime / 1000);
  200867. times.modtime = (time_t) (modificationTime / 1000);
  200868. return utime (fileName.toUTF8(), &times) == 0;
  200869. }
  200870. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  200871. {
  200872. struct stat info;
  200873. const int res = stat (fileName.toUTF8(), &info);
  200874. if (res != 0)
  200875. return false;
  200876. info.st_mode &= 0777; // Just permissions
  200877. if (isReadOnly)
  200878. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  200879. else
  200880. // Give everybody write permission?
  200881. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  200882. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  200883. }
  200884. bool juce_copyFile (const String& src, const String& dst)
  200885. {
  200886. const ScopedAutoReleasePool pool;
  200887. NSFileManager* fm = [NSFileManager defaultManager];
  200888. return [fm fileExistsAtPath: juceStringToNS (src)]
  200889. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  200890. && [fm copyItemAtPath: juceStringToNS (src)
  200891. toPath: juceStringToNS (dst)
  200892. error: nil];
  200893. #else
  200894. && [fm copyPath: juceStringToNS (src)
  200895. toPath: juceStringToNS (dst)
  200896. handler: nil];
  200897. #endif
  200898. }
  200899. const StringArray juce_getFileSystemRoots()
  200900. {
  200901. StringArray s;
  200902. s.add ("/");
  200903. return s;
  200904. }
  200905. static bool isFileOnDriveType (const File* const f, const char** types)
  200906. {
  200907. struct statfs buf;
  200908. if (doStatFS (f, buf))
  200909. {
  200910. const String type (buf.f_fstypename);
  200911. while (*types != 0)
  200912. if (type.equalsIgnoreCase (*types++))
  200913. return true;
  200914. }
  200915. return false;
  200916. }
  200917. bool File::isOnCDRomDrive() const
  200918. {
  200919. static const char* const cdTypes[] = { "cd9660", "cdfs", "cddafs", "udf", 0 };
  200920. return isFileOnDriveType (this, (const char**) cdTypes);
  200921. }
  200922. bool File::isOnHardDisk() const
  200923. {
  200924. static const char* const nonHDTypes[] = { "nfs", "smbfs", "ramfs", 0 };
  200925. return ! (isOnCDRomDrive() || isFileOnDriveType (this, (const char**) nonHDTypes));
  200926. }
  200927. bool File::isOnRemovableDrive() const
  200928. {
  200929. #if JUCE_IPHONE
  200930. return false; // xxx is this possible?
  200931. #else
  200932. const ScopedAutoReleasePool pool;
  200933. BOOL removable = false;
  200934. [[NSWorkspace sharedWorkspace]
  200935. getFileSystemInfoForPath: juceStringToNS (getFullPathName())
  200936. isRemovable: &removable
  200937. isWritable: nil
  200938. isUnmountable: nil
  200939. description: nil
  200940. type: nil];
  200941. return removable;
  200942. #endif
  200943. }
  200944. static bool juce_isHiddenFile (const String& path)
  200945. {
  200946. #if JUCE_IPHONE
  200947. return File (path).getFileName().startsWithChar ('.');
  200948. #else
  200949. FSRef ref;
  200950. if (! PlatformUtilities::makeFSRefFromPath (&ref, path))
  200951. return false;
  200952. FSCatalogInfo info;
  200953. FSGetCatalogInfo (&ref, kFSCatInfoNodeFlags | kFSCatInfoFinderInfo, &info, 0, 0, 0);
  200954. if ((info.nodeFlags & kFSNodeIsDirectoryBit) != 0)
  200955. return (((FolderInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  200956. return (((FileInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  200957. #endif
  200958. }
  200959. bool File::isHidden() const
  200960. {
  200961. return juce_isHiddenFile (getFullPathName());
  200962. }
  200963. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  200964. const File File::getSpecialLocation (const SpecialLocationType type)
  200965. {
  200966. const ScopedAutoReleasePool pool;
  200967. String resultPath;
  200968. switch (type)
  200969. {
  200970. case userHomeDirectory:
  200971. resultPath = nsStringToJuce (NSHomeDirectory());
  200972. break;
  200973. case userDocumentsDirectory:
  200974. resultPath = "~/Documents";
  200975. break;
  200976. case userDesktopDirectory:
  200977. resultPath = "~/Desktop";
  200978. break;
  200979. case userApplicationDataDirectory:
  200980. resultPath = "~/Library";
  200981. break;
  200982. case commonApplicationDataDirectory:
  200983. resultPath = "/Library";
  200984. break;
  200985. case globalApplicationsDirectory:
  200986. resultPath = "/Applications";
  200987. break;
  200988. case userMusicDirectory:
  200989. resultPath = "~/Music";
  200990. break;
  200991. case userMoviesDirectory:
  200992. resultPath = "~/Movies";
  200993. break;
  200994. case tempDirectory:
  200995. {
  200996. File tmp ("~/Library/Caches/" + juce_getExecutableFile().getFileNameWithoutExtension());
  200997. tmp.createDirectory();
  200998. return tmp.getFullPathName();
  200999. }
  201000. case invokedExecutableFile:
  201001. if (juce_Argv0 != 0)
  201002. return File (String::fromUTF8 (juce_Argv0));
  201003. // deliberate fall-through...
  201004. case currentExecutableFile:
  201005. return juce_getExecutableFile();
  201006. case currentApplicationFile:
  201007. {
  201008. const File exe (juce_getExecutableFile());
  201009. const File parent (exe.getParentDirectory());
  201010. return parent.getFullPathName().endsWithIgnoreCase (T("Contents/MacOS"))
  201011. ? parent.getParentDirectory().getParentDirectory()
  201012. : exe;
  201013. }
  201014. default:
  201015. jassertfalse // unknown type?
  201016. break;
  201017. }
  201018. if (resultPath.isNotEmpty())
  201019. return File (PlatformUtilities::convertToPrecomposedUnicode (resultPath));
  201020. return File::nonexistent;
  201021. }
  201022. const String File::getVersion() const
  201023. {
  201024. const ScopedAutoReleasePool pool;
  201025. String result;
  201026. NSBundle* bundle = [NSBundle bundleWithPath: juceStringToNS (getFullPathName())];
  201027. if (bundle != 0)
  201028. {
  201029. NSDictionary* info = [bundle infoDictionary];
  201030. if (info != 0)
  201031. {
  201032. NSString* name = [info valueForKey: @"CFBundleShortVersionString"];
  201033. if (name != nil)
  201034. result = nsStringToJuce (name);
  201035. }
  201036. }
  201037. return result;
  201038. }
  201039. const File File::getLinkedTarget() const
  201040. {
  201041. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201042. NSString* dest = [[NSFileManager defaultManager] destinationOfSymbolicLinkAtPath: juceStringToNS (getFullPathName()) error: nil];
  201043. #else
  201044. NSString* dest = [[NSFileManager defaultManager] pathContentOfSymbolicLinkAtPath: juceStringToNS (getFullPathName())];
  201045. #endif
  201046. if (dest != nil)
  201047. return File (nsStringToJuce (dest));
  201048. return *this;
  201049. }
  201050. bool File::moveToTrash() const
  201051. {
  201052. if (! exists())
  201053. return true;
  201054. #if JUCE_IPHONE
  201055. return deleteFile(); //xxx is there a trashcan on the iPhone?
  201056. #else
  201057. const ScopedAutoReleasePool pool;
  201058. NSString* p = juceStringToNS (getFullPathName());
  201059. return [[NSWorkspace sharedWorkspace]
  201060. performFileOperation: NSWorkspaceRecycleOperation
  201061. source: [p stringByDeletingLastPathComponent]
  201062. destination: @""
  201063. files: [NSArray arrayWithObject: [p lastPathComponent]]
  201064. tag: nil ];
  201065. #endif
  201066. }
  201067. struct FindFileStruct
  201068. {
  201069. NSDirectoryEnumerator* enumerator;
  201070. String parentDir, wildCard;
  201071. };
  201072. bool juce_findFileNext (void* handle, String& resultFile,
  201073. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  201074. {
  201075. ScopedAutoReleasePool pool;
  201076. FindFileStruct* ff = (FindFileStruct*) handle;
  201077. NSString* file;
  201078. const char* const wildcardUTF8 = ff->wildCard.toUTF8();
  201079. for (;;)
  201080. {
  201081. if (ff == 0 || (file = [ff->enumerator nextObject]) == 0)
  201082. return false;
  201083. [ff->enumerator skipDescendents];
  201084. resultFile = nsStringToJuce (file);
  201085. if (fnmatch (wildcardUTF8, resultFile.toUTF8(), FNM_CASEFOLD) != 0)
  201086. continue;
  201087. const String path (ff->parentDir + resultFile);
  201088. if (isDir != 0 || fileSize != 0)
  201089. {
  201090. struct stat info;
  201091. const bool statOk = juce_stat (path, info);
  201092. if (isDir != 0)
  201093. *isDir = statOk && ((info.st_mode & S_IFDIR) != 0);
  201094. if (isHidden != 0)
  201095. *isHidden = juce_isHiddenFile (path);
  201096. if (fileSize != 0)
  201097. *fileSize = statOk ? info.st_size : 0;
  201098. }
  201099. if (modTime != 0 || creationTime != 0)
  201100. {
  201101. int64 m, a, c;
  201102. juce_getFileTimes (path, m, a, c);
  201103. if (modTime != 0)
  201104. *modTime = m;
  201105. if (creationTime != 0)
  201106. *creationTime = c;
  201107. }
  201108. if (isReadOnly != 0)
  201109. *isReadOnly = ! juce_canWriteToFile (path);
  201110. return true;
  201111. }
  201112. }
  201113. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  201114. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  201115. Time* creationTime, bool* isReadOnly)
  201116. {
  201117. ScopedAutoReleasePool pool;
  201118. NSDirectoryEnumerator* e = [[NSFileManager defaultManager] enumeratorAtPath: juceStringToNS (directory)];
  201119. if (e != 0)
  201120. {
  201121. ScopedPointer <FindFileStruct> ff (new FindFileStruct());
  201122. ff->enumerator = [e retain];
  201123. ff->parentDir = directory;
  201124. ff->wildCard = wildCard;
  201125. if (! ff->parentDir.endsWithChar (File::separator))
  201126. ff->parentDir += File::separator;
  201127. if (juce_findFileNext (ff, firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  201128. return ff.release();
  201129. [e release];
  201130. }
  201131. return 0;
  201132. }
  201133. void juce_findFileClose (void* handle)
  201134. {
  201135. ScopedAutoReleasePool pool;
  201136. ScopedPointer <FindFileStruct> ff ((FindFileStruct*) handle);
  201137. [ff->enumerator release];
  201138. }
  201139. bool juce_launchExecutable (const String& pathAndArguments)
  201140. {
  201141. const char* const argv[4] = { "/bin/sh", "-c", pathAndArguments.toUTF8(), 0 };
  201142. const int cpid = fork();
  201143. if (cpid == 0)
  201144. {
  201145. // Child process
  201146. if (execve (argv[0], (char**) argv, 0) < 0)
  201147. exit (0);
  201148. }
  201149. else
  201150. {
  201151. if (cpid < 0)
  201152. return false;
  201153. }
  201154. return true;
  201155. }
  201156. bool juce_launchFile (const String& fileName, const String& parameters)
  201157. {
  201158. #if JUCE_IPHONE
  201159. return [[UIApplication sharedApplication] openURL: [NSURL fileURLWithPath: juceStringToNS (fileName)]];
  201160. #else
  201161. const ScopedAutoReleasePool pool;
  201162. if (parameters.isEmpty())
  201163. {
  201164. return [[NSWorkspace sharedWorkspace] openFile: juceStringToNS (fileName)]
  201165. || [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: juceStringToNS (fileName)]];
  201166. }
  201167. bool ok = false;
  201168. FSRef ref;
  201169. if (PlatformUtilities::makeFSRefFromPath (&ref, fileName))
  201170. {
  201171. if (PlatformUtilities::isBundle (fileName))
  201172. {
  201173. NSMutableArray* urls = [NSMutableArray array];
  201174. StringArray docs;
  201175. docs.addTokens (parameters, true);
  201176. for (int i = 0; i < docs.size(); ++i)
  201177. [urls addObject: juceStringToNS (docs[i])];
  201178. ok = [[NSWorkspace sharedWorkspace] openURLs: urls
  201179. withAppBundleIdentifier: [[NSBundle bundleWithPath: juceStringToNS (fileName)] bundleIdentifier]
  201180. options: 0
  201181. additionalEventParamDescriptor: nil
  201182. launchIdentifiers: nil];
  201183. }
  201184. else
  201185. {
  201186. ok = juce_launchExecutable ("\"" + fileName + "\" " + parameters);
  201187. }
  201188. }
  201189. return ok;
  201190. #endif
  201191. }
  201192. void File::revealToUser() const
  201193. {
  201194. #if ! JUCE_IPHONE
  201195. if (exists())
  201196. [[NSWorkspace sharedWorkspace] selectFile: juceStringToNS (getFullPathName()) inFileViewerRootedAtPath: @""];
  201197. else if (getParentDirectory().exists())
  201198. getParentDirectory().revealToUser();
  201199. #endif
  201200. }
  201201. #if ! JUCE_IPHONE
  201202. bool PlatformUtilities::makeFSRefFromPath (FSRef* destFSRef, const String& path)
  201203. {
  201204. return FSPathMakeRef ((const UInt8*) path.toUTF8(), destFSRef, 0) == noErr;
  201205. }
  201206. const String PlatformUtilities::makePathFromFSRef (FSRef* file)
  201207. {
  201208. char path [2048];
  201209. zerostruct (path);
  201210. if (FSRefMakePath (file, (UInt8*) path, sizeof (path) - 1) == noErr)
  201211. return PlatformUtilities::convertToPrecomposedUnicode (String::fromUTF8 (path));
  201212. return String::empty;
  201213. }
  201214. #endif
  201215. OSType PlatformUtilities::getTypeOfFile (const String& filename)
  201216. {
  201217. const ScopedAutoReleasePool pool;
  201218. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201219. NSDictionary* fileDict = [[NSFileManager defaultManager] attributesOfItemAtPath: juceStringToNS (filename) error: nil];
  201220. #else
  201221. NSDictionary* fileDict = [[NSFileManager defaultManager] fileAttributesAtPath: juceStringToNS (filename) traverseLink: NO];
  201222. #endif
  201223. //return (OSType) [fileDict objectForKey: NSFileHFSTypeCode];
  201224. return [fileDict fileHFSTypeCode];
  201225. }
  201226. bool PlatformUtilities::isBundle (const String& filename)
  201227. {
  201228. #if JUCE_IPHONE
  201229. return false; // xxx can't find a sensible way to do this without trying to open the bundle..
  201230. #else
  201231. const ScopedAutoReleasePool pool;
  201232. return [[NSWorkspace sharedWorkspace] isFilePackageAtPath: juceStringToNS (filename)];
  201233. #endif
  201234. }
  201235. #endif
  201236. /*** End of inlined file: juce_mac_Files.mm ***/
  201237. #if JUCE_IPHONE
  201238. /*** Start of inlined file: juce_iphone_MiscUtilities.mm ***/
  201239. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201240. // compiled on its own).
  201241. #if JUCE_INCLUDED_FILE
  201242. static JUCEApplication* juce_intialisingApp;
  201243. END_JUCE_NAMESPACE
  201244. @interface JuceAppStartupDelegate : NSObject <UIApplicationDelegate>
  201245. {
  201246. }
  201247. - (void) applicationDidFinishLaunching: (UIApplication*) application;
  201248. - (void) applicationWillResignActive: (UIApplication*) application;
  201249. @end
  201250. @implementation JuceAppStartupDelegate
  201251. - (void) applicationDidFinishLaunching: (UIApplication*) application
  201252. {
  201253. String dummy;
  201254. if (! juce_intialisingApp->initialiseApp (dummy))
  201255. exit (0);
  201256. }
  201257. - (void) applicationWillResignActive: (UIApplication*) application
  201258. {
  201259. JUCEApplication::shutdownAppAndClearUp();
  201260. }
  201261. @end
  201262. BEGIN_JUCE_NAMESPACE
  201263. int juce_IPhoneMain (int argc, const char* argv[], JUCEApplication* app)
  201264. {
  201265. juce_intialisingApp = app;
  201266. return UIApplicationMain (argc, const_cast<char**> (argv), nil, @"JuceAppStartupDelegate");
  201267. }
  201268. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201269. {
  201270. pool = [[NSAutoreleasePool alloc] init];
  201271. }
  201272. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201273. {
  201274. [((NSAutoreleasePool*) pool) release];
  201275. }
  201276. void PlatformUtilities::beep()
  201277. {
  201278. //xxx
  201279. //AudioServicesPlaySystemSound ();
  201280. }
  201281. void PlatformUtilities::addItemToDock (const File& file)
  201282. {
  201283. }
  201284. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201285. END_JUCE_NAMESPACE
  201286. @interface JuceAlertBoxDelegate : NSObject
  201287. {
  201288. @public
  201289. bool clickedOk;
  201290. }
  201291. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex;
  201292. @end
  201293. @implementation JuceAlertBoxDelegate
  201294. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex
  201295. {
  201296. clickedOk = (buttonIndex == 0);
  201297. alertView.hidden = true;
  201298. }
  201299. @end
  201300. BEGIN_JUCE_NAMESPACE
  201301. // (This function is used directly by other bits of code)
  201302. bool juce_iPhoneShowModalAlert (const String& title,
  201303. const String& bodyText,
  201304. NSString* okButtonText,
  201305. NSString* cancelButtonText)
  201306. {
  201307. const ScopedAutoReleasePool pool;
  201308. JuceAlertBoxDelegate* callback = [[JuceAlertBoxDelegate alloc] init];
  201309. UIAlertView* alert = [[UIAlertView alloc] initWithTitle: juceStringToNS (title)
  201310. message: juceStringToNS (bodyText)
  201311. delegate: callback
  201312. cancelButtonTitle: okButtonText
  201313. otherButtonTitles: cancelButtonText, nil];
  201314. [alert retain];
  201315. [alert show];
  201316. while (! alert.hidden && alert.superview != nil)
  201317. [[NSRunLoop mainRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  201318. const bool result = callback->clickedOk;
  201319. [alert release];
  201320. [callback release];
  201321. return result;
  201322. }
  201323. bool AlertWindow::showNativeDialogBox (const String& title,
  201324. const String& bodyText,
  201325. bool isOkCancel)
  201326. {
  201327. return juce_iPhoneShowModalAlert (title, bodyText,
  201328. @"OK",
  201329. isOkCancel ? @"Cancel" : nil);
  201330. }
  201331. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201332. {
  201333. jassertfalse // no such thing on the iphone!
  201334. return false;
  201335. }
  201336. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201337. {
  201338. jassertfalse // no such thing on the iphone!
  201339. return false;
  201340. }
  201341. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201342. {
  201343. [[UIApplication sharedApplication] setIdleTimerDisabled: ! isEnabled];
  201344. }
  201345. bool Desktop::isScreenSaverEnabled() throw()
  201346. {
  201347. return ! [[UIApplication sharedApplication] isIdleTimerDisabled];
  201348. }
  201349. void juce_updateMultiMonitorInfo (Array <Rectangle <int> >& monitorCoords, const bool clipToWorkArea)
  201350. {
  201351. const ScopedAutoReleasePool pool;
  201352. monitorCoords.clear();
  201353. CGRect r = clipToWorkArea ? [[UIScreen mainScreen] applicationFrame]
  201354. : [[UIScreen mainScreen] bounds];
  201355. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201356. (int) r.origin.y,
  201357. (int) r.size.width,
  201358. (int) r.size.height));
  201359. }
  201360. #endif
  201361. #endif
  201362. /*** End of inlined file: juce_iphone_MiscUtilities.mm ***/
  201363. #else
  201364. /*** Start of inlined file: juce_mac_MiscUtilities.mm ***/
  201365. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201366. // compiled on its own).
  201367. #if JUCE_INCLUDED_FILE
  201368. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201369. {
  201370. pool = [[NSAutoreleasePool alloc] init];
  201371. }
  201372. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201373. {
  201374. [((NSAutoreleasePool*) pool) release];
  201375. }
  201376. void PlatformUtilities::beep()
  201377. {
  201378. NSBeep();
  201379. }
  201380. void PlatformUtilities::addItemToDock (const File& file)
  201381. {
  201382. // check that it's not already there...
  201383. if (! juce_getOutputFromCommand ("defaults read com.apple.dock persistent-apps")
  201384. .containsIgnoreCase (file.getFullPathName()))
  201385. {
  201386. 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>"
  201387. + file.getFullPathName() + "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>\"");
  201388. juce_runSystemCommand ("osascript -e \"tell application \\\"Dock\\\" to quit\"");
  201389. }
  201390. }
  201391. int PlatformUtilities::getOSXMinorVersionNumber()
  201392. {
  201393. SInt32 versionMinor = 0;
  201394. OSErr err = Gestalt (gestaltSystemVersionMinor, &versionMinor);
  201395. (void) err;
  201396. jassert (err == noErr);
  201397. return (int) versionMinor;
  201398. }
  201399. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201400. bool AlertWindow::showNativeDialogBox (const String& title,
  201401. const String& bodyText,
  201402. bool isOkCancel)
  201403. {
  201404. const ScopedAutoReleasePool pool;
  201405. return NSRunAlertPanel (juceStringToNS (title),
  201406. juceStringToNS (bodyText),
  201407. @"Ok",
  201408. isOkCancel ? @"Cancel" : nil,
  201409. nil) == NSAlertDefaultReturn;
  201410. }
  201411. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201412. {
  201413. if (files.size() == 0)
  201414. return false;
  201415. MouseInputSource* draggingSource = Desktop::getInstance().getDraggingMouseSource(0);
  201416. if (draggingSource == 0)
  201417. {
  201418. jassertfalse // This method must be called in response to a component's mouseDown or mouseDrag event!
  201419. return false;
  201420. }
  201421. Component* sourceComp = draggingSource->getComponentUnderMouse();
  201422. if (sourceComp == 0)
  201423. {
  201424. jassertfalse // This method must be called in response to a component's mouseDown or mouseDrag event!
  201425. return false;
  201426. }
  201427. const ScopedAutoReleasePool pool;
  201428. NSView* view = (NSView*) sourceComp->getWindowHandle();
  201429. if (view == 0)
  201430. return false;
  201431. NSPasteboard* pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
  201432. [pboard declareTypes: [NSArray arrayWithObject: NSFilenamesPboardType]
  201433. owner: nil];
  201434. NSMutableArray* filesArray = [NSMutableArray arrayWithCapacity: 4];
  201435. for (int i = 0; i < files.size(); ++i)
  201436. [filesArray addObject: juceStringToNS (files[i])];
  201437. [pboard setPropertyList: filesArray
  201438. forType: NSFilenamesPboardType];
  201439. NSPoint dragPosition = [view convertPoint: [[[view window] currentEvent] locationInWindow]
  201440. fromView: nil];
  201441. dragPosition.x -= 16;
  201442. dragPosition.y -= 16;
  201443. [view dragImage: [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (files[0])]
  201444. at: dragPosition
  201445. offset: NSMakeSize (0, 0)
  201446. event: [[view window] currentEvent]
  201447. pasteboard: pboard
  201448. source: view
  201449. slideBack: YES];
  201450. return true;
  201451. }
  201452. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201453. {
  201454. jassertfalse // not implemented!
  201455. return false;
  201456. }
  201457. bool Desktop::canUseSemiTransparentWindows() throw()
  201458. {
  201459. return true;
  201460. }
  201461. const Point<int> Desktop::getMousePosition()
  201462. {
  201463. const ScopedAutoReleasePool pool;
  201464. const NSPoint p ([NSEvent mouseLocation]);
  201465. return Point<int> (roundToInt (p.x), roundToInt ([[[NSScreen screens] objectAtIndex: 0] frame].size.height - p.y));
  201466. }
  201467. void Desktop::setMousePosition (const Point<int>& newPosition)
  201468. {
  201469. // this rubbish needs to be done around the warp call, to avoid causing a
  201470. // bizarre glitch..
  201471. CGAssociateMouseAndMouseCursorPosition (false);
  201472. CGWarpMouseCursorPosition (CGPointMake (newPosition.getX(), newPosition.getY()));
  201473. CGAssociateMouseAndMouseCursorPosition (true);
  201474. }
  201475. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201476. class ScreenSaverDefeater : public Timer,
  201477. public DeletedAtShutdown
  201478. {
  201479. public:
  201480. ScreenSaverDefeater() throw()
  201481. {
  201482. startTimer (10000);
  201483. timerCallback();
  201484. }
  201485. ~ScreenSaverDefeater() {}
  201486. void timerCallback()
  201487. {
  201488. if (Process::isForegroundProcess())
  201489. UpdateSystemActivity (UsrActivity);
  201490. }
  201491. };
  201492. static ScreenSaverDefeater* screenSaverDefeater = 0;
  201493. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201494. {
  201495. if (isEnabled)
  201496. {
  201497. deleteAndZero (screenSaverDefeater);
  201498. }
  201499. else if (screenSaverDefeater == 0)
  201500. {
  201501. screenSaverDefeater = new ScreenSaverDefeater();
  201502. }
  201503. }
  201504. bool Desktop::isScreenSaverEnabled() throw()
  201505. {
  201506. return screenSaverDefeater == 0;
  201507. }
  201508. #else
  201509. static IOPMAssertionID screenSaverDisablerID = 0;
  201510. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201511. {
  201512. if (isEnabled)
  201513. {
  201514. if (screenSaverDisablerID != 0)
  201515. {
  201516. IOPMAssertionRelease (screenSaverDisablerID);
  201517. screenSaverDisablerID = 0;
  201518. }
  201519. }
  201520. else
  201521. {
  201522. if (screenSaverDisablerID == 0)
  201523. {
  201524. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  201525. IOPMAssertionCreateWithName (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201526. CFSTR ("Juce"), &screenSaverDisablerID);
  201527. #else
  201528. IOPMAssertionCreate (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201529. &screenSaverDisablerID);
  201530. #endif
  201531. }
  201532. }
  201533. }
  201534. bool Desktop::isScreenSaverEnabled() throw()
  201535. {
  201536. return screenSaverDisablerID == 0;
  201537. }
  201538. #endif
  201539. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  201540. {
  201541. const ScopedAutoReleasePool pool;
  201542. monitorCoords.clear();
  201543. NSArray* screens = [NSScreen screens];
  201544. const CGFloat mainScreenBottom = [[[NSScreen screens] objectAtIndex: 0] frame].size.height;
  201545. for (unsigned int i = 0; i < [screens count]; ++i)
  201546. {
  201547. NSScreen* s = (NSScreen*) [screens objectAtIndex: i];
  201548. NSRect r = clipToWorkArea ? [s visibleFrame]
  201549. : [s frame];
  201550. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201551. (int) (mainScreenBottom - (r.origin.y + r.size.height)),
  201552. (int) r.size.width,
  201553. (int) r.size.height));
  201554. }
  201555. jassert (monitorCoords.size() > 0);
  201556. }
  201557. #endif
  201558. #endif
  201559. /*** End of inlined file: juce_mac_MiscUtilities.mm ***/
  201560. #endif
  201561. /*** Start of inlined file: juce_mac_Debugging.mm ***/
  201562. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201563. // compiled on its own).
  201564. #if JUCE_INCLUDED_FILE
  201565. void Logger::outputDebugString (const String& text) throw()
  201566. {
  201567. std::cerr << text << std::endl;
  201568. }
  201569. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  201570. {
  201571. static char testResult = 0;
  201572. if (testResult == 0)
  201573. {
  201574. struct kinfo_proc info;
  201575. int m[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };
  201576. size_t sz = sizeof (info);
  201577. sysctl (m, 4, &info, &sz, 0, 0);
  201578. testResult = ((info.kp_proc.p_flag & P_TRACED) != 0) ? 1 : -1;
  201579. }
  201580. return testResult > 0;
  201581. }
  201582. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  201583. {
  201584. return juce_isRunningUnderDebugger();
  201585. }
  201586. #endif
  201587. /*** End of inlined file: juce_mac_Debugging.mm ***/
  201588. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201589. #if JUCE_IPHONE
  201590. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  201591. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201592. // compiled on its own).
  201593. #if JUCE_INCLUDED_FILE
  201594. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201595. #define SUPPORT_10_4_FONTS 1
  201596. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  201597. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  201598. #define SUPPORT_ONLY_10_4_FONTS 1
  201599. #endif
  201600. END_JUCE_NAMESPACE
  201601. @interface NSFont (PrivateHack)
  201602. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  201603. @end
  201604. BEGIN_JUCE_NAMESPACE
  201605. #endif
  201606. class MacTypeface : public Typeface
  201607. {
  201608. public:
  201609. MacTypeface (const Font& font)
  201610. : Typeface (font.getTypefaceName())
  201611. {
  201612. const ScopedAutoReleasePool pool;
  201613. renderingTransform = CGAffineTransformIdentity;
  201614. bool needsItalicTransform = false;
  201615. #if JUCE_IPHONE
  201616. NSString* fontName = juceStringToNS (font.getTypefaceName());
  201617. if (font.isItalic() || font.isBold())
  201618. {
  201619. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  201620. for (NSString* i in familyFonts)
  201621. {
  201622. const String fn (nsStringToJuce (i));
  201623. const String afterDash (fn.fromFirstOccurrenceOf (T("-"), false, false));
  201624. const bool probablyBold = afterDash.containsIgnoreCase (T("bold")) || fn.endsWithIgnoreCase (T("bold"));
  201625. const bool probablyItalic = afterDash.containsIgnoreCase (T("oblique"))
  201626. || afterDash.containsIgnoreCase (T("italic"))
  201627. || fn.endsWithIgnoreCase (T("oblique"))
  201628. || fn.endsWithIgnoreCase (T("italic"));
  201629. if (probablyBold == font.isBold()
  201630. && probablyItalic == font.isItalic())
  201631. {
  201632. fontName = i;
  201633. needsItalicTransform = false;
  201634. break;
  201635. }
  201636. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  201637. {
  201638. fontName = i;
  201639. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  201640. }
  201641. }
  201642. if (needsItalicTransform)
  201643. renderingTransform.c = 0.15f;
  201644. }
  201645. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  201646. const int ascender = abs (CGFontGetAscent (fontRef));
  201647. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  201648. ascent = ascender / totalHeight;
  201649. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201650. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  201651. #else
  201652. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  201653. if (font.isItalic())
  201654. {
  201655. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  201656. toHaveTrait: NSItalicFontMask];
  201657. if (newFont == nsFont)
  201658. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  201659. nsFont = newFont;
  201660. }
  201661. if (font.isBold())
  201662. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  201663. [nsFont retain];
  201664. ascent = fabsf ((float) [nsFont ascender]);
  201665. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  201666. ascent /= totalSize;
  201667. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  201668. if (needsItalicTransform)
  201669. {
  201670. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  201671. renderingTransform.c = 0.15f;
  201672. }
  201673. #if SUPPORT_ONLY_10_4_FONTS
  201674. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201675. if (atsFont == 0)
  201676. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201677. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  201678. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  201679. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201680. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  201681. #else
  201682. #if SUPPORT_10_4_FONTS
  201683. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201684. {
  201685. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201686. if (atsFont == 0)
  201687. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201688. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  201689. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  201690. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201691. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  201692. }
  201693. else
  201694. #endif
  201695. {
  201696. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  201697. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  201698. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201699. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  201700. }
  201701. #endif
  201702. #endif
  201703. }
  201704. ~MacTypeface()
  201705. {
  201706. #if ! JUCE_IPHONE
  201707. [nsFont release];
  201708. #endif
  201709. if (fontRef != 0)
  201710. CGFontRelease (fontRef);
  201711. }
  201712. float getAscent() const
  201713. {
  201714. return ascent;
  201715. }
  201716. float getDescent() const
  201717. {
  201718. return 1.0f - ascent;
  201719. }
  201720. float getStringWidth (const String& text)
  201721. {
  201722. if (fontRef == 0 || text.isEmpty())
  201723. return 0;
  201724. const int length = text.length();
  201725. HeapBlock <CGGlyph> glyphs;
  201726. createGlyphsForString (text, length, glyphs);
  201727. float x = 0;
  201728. #if SUPPORT_ONLY_10_4_FONTS
  201729. HeapBlock <NSSize> advances (length);
  201730. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  201731. for (int i = 0; i < length; ++i)
  201732. x += advances[i].width;
  201733. #else
  201734. #if SUPPORT_10_4_FONTS
  201735. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201736. {
  201737. HeapBlock <NSSize> advances (length);
  201738. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast<NSGlyph*> (glyphs.getData()) count: length];
  201739. for (int i = 0; i < length; ++i)
  201740. x += advances[i].width;
  201741. }
  201742. else
  201743. #endif
  201744. {
  201745. HeapBlock <int> advances (length);
  201746. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  201747. for (int i = 0; i < length; ++i)
  201748. x += advances[i];
  201749. }
  201750. #endif
  201751. return x * unitsToHeightScaleFactor;
  201752. }
  201753. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  201754. {
  201755. xOffsets.add (0);
  201756. if (fontRef == 0 || text.isEmpty())
  201757. return;
  201758. const int length = text.length();
  201759. HeapBlock <CGGlyph> glyphs;
  201760. createGlyphsForString (text, length, glyphs);
  201761. #if SUPPORT_ONLY_10_4_FONTS
  201762. HeapBlock <NSSize> advances (length);
  201763. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  201764. int x = 0;
  201765. for (int i = 0; i < length; ++i)
  201766. {
  201767. x += advances[i].width;
  201768. xOffsets.add (x * unitsToHeightScaleFactor);
  201769. resultGlyphs.add (reinterpret_cast <NSGlyph*> (glyphs.getData())[i]);
  201770. }
  201771. #else
  201772. #if SUPPORT_10_4_FONTS
  201773. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201774. {
  201775. HeapBlock <NSSize> advances (length);
  201776. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  201777. [nsFont getAdvancements: advances forGlyphs: nsGlyphs count: length];
  201778. float x = 0;
  201779. for (int i = 0; i < length; ++i)
  201780. {
  201781. x += advances[i].width;
  201782. xOffsets.add (x * unitsToHeightScaleFactor);
  201783. resultGlyphs.add (nsGlyphs[i]);
  201784. }
  201785. }
  201786. else
  201787. #endif
  201788. {
  201789. HeapBlock <int> advances (length);
  201790. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  201791. {
  201792. int x = 0;
  201793. for (int i = 0; i < length; ++i)
  201794. {
  201795. x += advances [i];
  201796. xOffsets.add (x * unitsToHeightScaleFactor);
  201797. resultGlyphs.add (glyphs[i]);
  201798. }
  201799. }
  201800. }
  201801. #endif
  201802. }
  201803. bool getOutlineForGlyph (int glyphNumber, Path& path)
  201804. {
  201805. #if JUCE_IPHONE
  201806. return false;
  201807. #else
  201808. if (nsFont == 0)
  201809. return false;
  201810. // we might need to apply a transform to the path, so it mustn't have anything else in it
  201811. jassert (path.isEmpty());
  201812. const ScopedAutoReleasePool pool;
  201813. NSBezierPath* bez = [NSBezierPath bezierPath];
  201814. [bez moveToPoint: NSMakePoint (0, 0)];
  201815. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  201816. inFont: nsFont];
  201817. for (int i = 0; i < [bez elementCount]; ++i)
  201818. {
  201819. NSPoint p[3];
  201820. switch ([bez elementAtIndex: i associatedPoints: p])
  201821. {
  201822. case NSMoveToBezierPathElement:
  201823. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  201824. break;
  201825. case NSLineToBezierPathElement:
  201826. path.lineTo ((float) p[0].x, (float) -p[0].y);
  201827. break;
  201828. case NSCurveToBezierPathElement:
  201829. 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);
  201830. break;
  201831. case NSClosePathBezierPathElement:
  201832. path.closeSubPath();
  201833. break;
  201834. default:
  201835. jassertfalse
  201836. break;
  201837. }
  201838. }
  201839. path.applyTransform (pathTransform);
  201840. return true;
  201841. #endif
  201842. }
  201843. juce_UseDebuggingNewOperator
  201844. CGFontRef fontRef;
  201845. float fontHeightToCGSizeFactor;
  201846. CGAffineTransform renderingTransform;
  201847. private:
  201848. float ascent, unitsToHeightScaleFactor;
  201849. #if JUCE_IPHONE
  201850. #else
  201851. NSFont* nsFont;
  201852. AffineTransform pathTransform;
  201853. #endif
  201854. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  201855. {
  201856. #if SUPPORT_10_4_FONTS
  201857. #if ! SUPPORT_ONLY_10_4_FONTS
  201858. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201859. #endif
  201860. {
  201861. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  201862. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  201863. for (int i = 0; i < length; ++i)
  201864. nsGlyphs[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  201865. return;
  201866. }
  201867. #endif
  201868. #if ! SUPPORT_ONLY_10_4_FONTS
  201869. if (charToGlyphMapper == 0)
  201870. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  201871. glyphs.malloc (length);
  201872. for (int i = 0; i < length; ++i)
  201873. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  201874. #endif
  201875. }
  201876. #if ! SUPPORT_ONLY_10_4_FONTS
  201877. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  201878. class CharToGlyphMapper
  201879. {
  201880. public:
  201881. CharToGlyphMapper (CGFontRef fontRef)
  201882. : segCount (0), endCode (0), startCode (0), idDelta (0),
  201883. idRangeOffset (0), glyphIndexes (0)
  201884. {
  201885. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  201886. if (cmapTable != 0)
  201887. {
  201888. const int numSubtables = getValue16 (cmapTable, 2);
  201889. for (int i = 0; i < numSubtables; ++i)
  201890. {
  201891. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  201892. {
  201893. const int offset = getValue32 (cmapTable, i * 8 + 8);
  201894. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  201895. {
  201896. const int length = getValue16 (cmapTable, offset + 2);
  201897. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  201898. segCount = segCountX2 / 2;
  201899. const int endCodeOffset = offset + 14;
  201900. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  201901. const int idDeltaOffset = startCodeOffset + segCountX2;
  201902. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  201903. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  201904. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  201905. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  201906. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  201907. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  201908. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  201909. }
  201910. break;
  201911. }
  201912. }
  201913. CFRelease (cmapTable);
  201914. }
  201915. }
  201916. ~CharToGlyphMapper()
  201917. {
  201918. if (endCode != 0)
  201919. {
  201920. CFRelease (endCode);
  201921. CFRelease (startCode);
  201922. CFRelease (idDelta);
  201923. CFRelease (idRangeOffset);
  201924. CFRelease (glyphIndexes);
  201925. }
  201926. }
  201927. int getGlyphForCharacter (const juce_wchar c) const
  201928. {
  201929. for (int i = 0; i < segCount; ++i)
  201930. {
  201931. if (getValue16 (endCode, i * 2) >= c)
  201932. {
  201933. const int start = getValue16 (startCode, i * 2);
  201934. if (start > c)
  201935. break;
  201936. const int delta = getValue16 (idDelta, i * 2);
  201937. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  201938. if (rangeOffset == 0)
  201939. return delta + c;
  201940. else
  201941. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  201942. }
  201943. }
  201944. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  201945. return jmax (-1, c - 29);
  201946. }
  201947. private:
  201948. int segCount;
  201949. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  201950. static uint16 getValue16 (CFDataRef data, const int index)
  201951. {
  201952. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  201953. }
  201954. static uint32 getValue32 (CFDataRef data, const int index)
  201955. {
  201956. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  201957. }
  201958. };
  201959. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  201960. #endif
  201961. MacTypeface (const MacTypeface&);
  201962. MacTypeface& operator= (const MacTypeface&);
  201963. };
  201964. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  201965. {
  201966. return new MacTypeface (font);
  201967. }
  201968. const StringArray Font::findAllTypefaceNames()
  201969. {
  201970. StringArray names;
  201971. const ScopedAutoReleasePool pool;
  201972. #if JUCE_IPHONE
  201973. NSArray* fonts = [UIFont familyNames];
  201974. #else
  201975. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  201976. #endif
  201977. for (unsigned int i = 0; i < [fonts count]; ++i)
  201978. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  201979. names.sort (true);
  201980. return names;
  201981. }
  201982. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed)
  201983. {
  201984. #if JUCE_IPHONE
  201985. defaultSans = "Helvetica";
  201986. defaultSerif = "Times New Roman";
  201987. defaultFixed = "Courier New";
  201988. #else
  201989. defaultSans = "Lucida Grande";
  201990. defaultSerif = "Times New Roman";
  201991. defaultFixed = "Monaco";
  201992. #endif
  201993. }
  201994. #endif
  201995. /*** End of inlined file: juce_mac_Fonts.mm ***/
  201996. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  201997. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201998. // compiled on its own).
  201999. #if JUCE_INCLUDED_FILE
  202000. class CoreGraphicsImage : public Image
  202001. {
  202002. public:
  202003. CoreGraphicsImage (const PixelFormat format_,
  202004. const int imageWidth_,
  202005. const int imageHeight_,
  202006. const bool clearImage)
  202007. : Image (format_, imageWidth_, imageHeight_, clearImage)
  202008. {
  202009. CGColorSpaceRef colourSpace = (format == Image::SingleChannel) ? CGColorSpaceCreateDeviceGray()
  202010. : CGColorSpaceCreateDeviceRGB();
  202011. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  202012. colourSpace, getCGImageFlags (*this));
  202013. CGColorSpaceRelease (colourSpace);
  202014. }
  202015. ~CoreGraphicsImage()
  202016. {
  202017. CGContextRelease (context);
  202018. }
  202019. LowLevelGraphicsContext* createLowLevelContext();
  202020. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  202021. {
  202022. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  202023. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  202024. {
  202025. return CGBitmapContextCreateImage (nativeImage->context);
  202026. }
  202027. else
  202028. {
  202029. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  202030. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  202031. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  202032. 8, srcData.pixelStride * 8, srcData.lineStride,
  202033. colourSpace, getCGImageFlags (juceImage), provider,
  202034. 0, true, kCGRenderingIntentDefault);
  202035. CGDataProviderRelease (provider);
  202036. return imageRef;
  202037. }
  202038. }
  202039. #if JUCE_MAC
  202040. static NSImage* createNSImage (const Image& image)
  202041. {
  202042. const ScopedAutoReleasePool pool;
  202043. NSImage* im = [[NSImage alloc] init];
  202044. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  202045. [im lockFocus];
  202046. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  202047. CGImageRef imageRef = createImage (image, false, colourSpace);
  202048. CGColorSpaceRelease (colourSpace);
  202049. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  202050. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  202051. CGImageRelease (imageRef);
  202052. [im unlockFocus];
  202053. return im;
  202054. }
  202055. #endif
  202056. CGContextRef context;
  202057. private:
  202058. static CGBitmapInfo getCGImageFlags (const Image& image)
  202059. {
  202060. #if JUCE_BIG_ENDIAN
  202061. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  202062. #else
  202063. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  202064. #endif
  202065. }
  202066. };
  202067. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  202068. {
  202069. #if USE_COREGRAPHICS_RENDERING
  202070. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  202071. #else
  202072. return new Image (format, imageWidth, imageHeight, clearImage);
  202073. #endif
  202074. }
  202075. class CoreGraphicsContext : public LowLevelGraphicsContext
  202076. {
  202077. public:
  202078. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  202079. : context (context_),
  202080. flipHeight (flipHeight_),
  202081. state (new SavedState()),
  202082. numGradientLookupEntries (0)
  202083. {
  202084. CGContextRetain (context);
  202085. CGContextSaveGState(context);
  202086. CGContextSetShouldSmoothFonts (context, true);
  202087. CGContextSetShouldAntialias (context, true);
  202088. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202089. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  202090. greyColourSpace = CGColorSpaceCreateDeviceGray();
  202091. gradientCallbacks.version = 0;
  202092. gradientCallbacks.evaluate = gradientCallback;
  202093. gradientCallbacks.releaseInfo = 0;
  202094. setFont (Font());
  202095. }
  202096. ~CoreGraphicsContext()
  202097. {
  202098. CGContextRestoreGState (context);
  202099. CGContextRelease (context);
  202100. CGColorSpaceRelease (rgbColourSpace);
  202101. CGColorSpaceRelease (greyColourSpace);
  202102. }
  202103. bool isVectorDevice() const { return false; }
  202104. void setOrigin (int x, int y)
  202105. {
  202106. CGContextTranslateCTM (context, x, -y);
  202107. }
  202108. bool clipToRectangle (const Rectangle<int>& r)
  202109. {
  202110. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  202111. return ! isClipEmpty();
  202112. }
  202113. bool clipToRectangleList (const RectangleList& clipRegion)
  202114. {
  202115. if (clipRegion.isEmpty())
  202116. {
  202117. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  202118. return false;
  202119. }
  202120. else
  202121. {
  202122. const int numRects = clipRegion.getNumRectangles();
  202123. HeapBlock <CGRect> rects (numRects);
  202124. for (int i = 0; i < numRects; ++i)
  202125. {
  202126. const Rectangle<int>& r = clipRegion.getRectangle(i);
  202127. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202128. }
  202129. CGContextClipToRects (context, rects, numRects);
  202130. return ! isClipEmpty();
  202131. }
  202132. }
  202133. void excludeClipRectangle (const Rectangle<int>& r)
  202134. {
  202135. RectangleList remaining (getClipBounds());
  202136. remaining.subtract (r);
  202137. clipToRectangleList (remaining);
  202138. }
  202139. void clipToPath (const Path& path, const AffineTransform& transform)
  202140. {
  202141. createPath (path, transform);
  202142. CGContextClip (context);
  202143. }
  202144. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  202145. {
  202146. if (! transform.isSingularity())
  202147. {
  202148. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  202149. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  202150. flip();
  202151. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  202152. applyTransform (t);
  202153. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  202154. CGContextClipToMask (context, r, image);
  202155. applyTransform (t.inverted());
  202156. flip();
  202157. CGImageRelease (image);
  202158. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  202159. }
  202160. }
  202161. bool clipRegionIntersects (const Rectangle<int>& r)
  202162. {
  202163. return getClipBounds().intersects (r);
  202164. }
  202165. const Rectangle<int> getClipBounds() const
  202166. {
  202167. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202168. return Rectangle<int> (roundToInt (bounds.origin.x),
  202169. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  202170. roundToInt (bounds.size.width),
  202171. roundToInt (bounds.size.height));
  202172. }
  202173. bool isClipEmpty() const
  202174. {
  202175. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  202176. }
  202177. void saveState()
  202178. {
  202179. CGContextSaveGState (context);
  202180. stateStack.add (new SavedState (*state));
  202181. }
  202182. void restoreState()
  202183. {
  202184. CGContextRestoreGState (context);
  202185. SavedState* const top = stateStack.getLast();
  202186. if (top != 0)
  202187. {
  202188. state = top;
  202189. stateStack.removeLast (1, false);
  202190. }
  202191. else
  202192. {
  202193. jassertfalse // trying to pop with an empty stack!
  202194. }
  202195. }
  202196. void setFill (const FillType& fillType)
  202197. {
  202198. state->fillType = fillType;
  202199. if (fillType.isColour())
  202200. {
  202201. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  202202. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  202203. CGContextSetAlpha (context, 1.0f);
  202204. }
  202205. }
  202206. void setOpacity (float newOpacity)
  202207. {
  202208. state->fillType.setOpacity (newOpacity);
  202209. setFill (state->fillType);
  202210. }
  202211. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  202212. {
  202213. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  202214. ? kCGInterpolationLow
  202215. : kCGInterpolationHigh);
  202216. }
  202217. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  202218. {
  202219. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202220. if (replaceExistingContents)
  202221. {
  202222. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  202223. CGContextClearRect (context, cgRect);
  202224. #else
  202225. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  202226. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  202227. CGContextClearRect (context, cgRect);
  202228. else
  202229. #endif
  202230. CGContextSetBlendMode (context, kCGBlendModeCopy);
  202231. #endif
  202232. fillRect (r, false);
  202233. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202234. }
  202235. else
  202236. {
  202237. if (state->fillType.isColour())
  202238. {
  202239. CGContextFillRect (context, cgRect);
  202240. }
  202241. else if (state->fillType.isGradient())
  202242. {
  202243. CGContextSaveGState (context);
  202244. CGContextClipToRect (context, cgRect);
  202245. drawGradient();
  202246. CGContextRestoreGState (context);
  202247. }
  202248. else
  202249. {
  202250. CGContextSaveGState (context);
  202251. CGContextClipToRect (context, cgRect);
  202252. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202253. CGContextRestoreGState (context);
  202254. }
  202255. }
  202256. }
  202257. void fillPath (const Path& path, const AffineTransform& transform)
  202258. {
  202259. CGContextSaveGState (context);
  202260. if (state->fillType.isColour())
  202261. {
  202262. flip();
  202263. applyTransform (transform);
  202264. createPath (path);
  202265. if (path.isUsingNonZeroWinding())
  202266. CGContextFillPath (context);
  202267. else
  202268. CGContextEOFillPath (context);
  202269. }
  202270. else
  202271. {
  202272. createPath (path, transform);
  202273. if (path.isUsingNonZeroWinding())
  202274. CGContextClip (context);
  202275. else
  202276. CGContextEOClip (context);
  202277. if (state->fillType.isGradient())
  202278. drawGradient();
  202279. else
  202280. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202281. }
  202282. CGContextRestoreGState (context);
  202283. }
  202284. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  202285. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  202286. {
  202287. jassert (sourceImage.getBounds().contains (srcClip));
  202288. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  202289. CGImageRef image = fullImage;
  202290. if (srcClip != sourceImage.getBounds())
  202291. {
  202292. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  202293. srcClip.getWidth(), srcClip.getHeight()));
  202294. CGImageRelease (fullImage);
  202295. }
  202296. CGContextSaveGState (context);
  202297. CGContextSetAlpha (context, state->fillType.getOpacity());
  202298. flip();
  202299. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  202300. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  202301. if (fillEntireClipAsTiles)
  202302. {
  202303. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  202304. CGContextDrawTiledImage (context, imageRect, image);
  202305. #else
  202306. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  202307. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  202308. // if it's doing a transformation - it's quicker to just draw lots of images manually
  202309. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  202310. CGContextDrawTiledImage (context, imageRect, image);
  202311. else
  202312. #endif
  202313. {
  202314. // Fallback to manually doing a tiled fill on 10.4
  202315. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202316. const int iw = srcClip.getWidth();
  202317. const int ih = srcClip.getHeight();
  202318. int x = 0, y = 0;
  202319. while (x > clip.origin.x) x -= iw;
  202320. while (y > clip.origin.y) y -= ih;
  202321. const int right = (int) (clip.origin.x + clip.size.width);
  202322. const int bottom = (int) (clip.origin.y + clip.size.height);
  202323. while (y < bottom)
  202324. {
  202325. for (int x2 = x; x2 < right; x2 += iw)
  202326. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  202327. y += ih;
  202328. }
  202329. }
  202330. #endif
  202331. }
  202332. else
  202333. {
  202334. CGContextDrawImage (context, imageRect, image);
  202335. }
  202336. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  202337. CGContextRestoreGState (context);
  202338. }
  202339. void drawLine (double x1, double y1, double x2, double y2)
  202340. {
  202341. CGContextSetLineCap (context, kCGLineCapSquare);
  202342. CGContextSetLineWidth (context, 1.0f);
  202343. CGContextSetRGBStrokeColor (context,
  202344. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  202345. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  202346. CGPoint line[] = { { (CGFloat) x1, flipHeight - (CGFloat) y1 },
  202347. { (CGFloat) x2, flipHeight - (CGFloat) y2 } };
  202348. CGContextStrokeLineSegments (context, line, 1);
  202349. }
  202350. void drawVerticalLine (const int x, double top, double bottom)
  202351. {
  202352. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202353. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  202354. #else
  202355. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202356. // the x co-ord slightly to trick it..
  202357. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  202358. #endif
  202359. }
  202360. void drawHorizontalLine (const int y, double left, double right)
  202361. {
  202362. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202363. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  202364. #else
  202365. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202366. // the x co-ord slightly to trick it..
  202367. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  202368. #endif
  202369. }
  202370. void setFont (const Font& newFont)
  202371. {
  202372. if (state->font != newFont)
  202373. {
  202374. state->fontRef = 0;
  202375. state->font = newFont;
  202376. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  202377. if (mf != 0)
  202378. {
  202379. state->fontRef = mf->fontRef;
  202380. CGContextSetFont (context, state->fontRef);
  202381. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  202382. state->fontTransform = mf->renderingTransform;
  202383. state->fontTransform.a *= state->font.getHorizontalScale();
  202384. CGContextSetTextMatrix (context, state->fontTransform);
  202385. }
  202386. }
  202387. }
  202388. const Font getFont()
  202389. {
  202390. return state->font;
  202391. }
  202392. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  202393. {
  202394. if (state->fontRef != 0 && state->fillType.isColour())
  202395. {
  202396. if (transform.isOnlyTranslation())
  202397. {
  202398. CGGlyph g = glyphNumber;
  202399. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  202400. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  202401. }
  202402. else
  202403. {
  202404. CGContextSaveGState (context);
  202405. flip();
  202406. applyTransform (transform);
  202407. CGAffineTransform t = state->fontTransform;
  202408. t.d = -t.d;
  202409. CGContextSetTextMatrix (context, t);
  202410. CGGlyph g = glyphNumber;
  202411. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  202412. CGContextSetTextMatrix (context, state->fontTransform);
  202413. CGContextRestoreGState (context);
  202414. }
  202415. }
  202416. else
  202417. {
  202418. Path p;
  202419. Font& f = state->font;
  202420. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  202421. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  202422. .followedBy (transform));
  202423. }
  202424. }
  202425. private:
  202426. CGContextRef context;
  202427. const CGFloat flipHeight;
  202428. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  202429. CGFunctionCallbacks gradientCallbacks;
  202430. struct SavedState
  202431. {
  202432. SavedState()
  202433. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  202434. {
  202435. }
  202436. SavedState (const SavedState& other)
  202437. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  202438. fontTransform (other.fontTransform)
  202439. {
  202440. }
  202441. ~SavedState()
  202442. {
  202443. }
  202444. FillType fillType;
  202445. Font font;
  202446. CGFontRef fontRef;
  202447. CGAffineTransform fontTransform;
  202448. };
  202449. ScopedPointer <SavedState> state;
  202450. OwnedArray <SavedState> stateStack;
  202451. HeapBlock <PixelARGB> gradientLookupTable;
  202452. int numGradientLookupEntries;
  202453. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  202454. {
  202455. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  202456. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  202457. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  202458. colour.unpremultiply();
  202459. outData[0] = colour.getRed() / 255.0f;
  202460. outData[1] = colour.getGreen() / 255.0f;
  202461. outData[2] = colour.getBlue() / 255.0f;
  202462. outData[3] = colour.getAlpha() / 255.0f;
  202463. }
  202464. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  202465. {
  202466. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  202467. --numGradientLookupEntries;
  202468. CGShadingRef result = 0;
  202469. CGFunctionRef function = CGFunctionCreate ((void*) this, 1, 0, 4, 0, &gradientCallbacks);
  202470. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  202471. if (gradient.isRadial)
  202472. {
  202473. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  202474. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  202475. function, true, true);
  202476. }
  202477. else
  202478. {
  202479. result = CGShadingCreateAxial (rgbColourSpace, p1,
  202480. CGPointMake (gradient.x2, gradient.y2),
  202481. function, true, true);
  202482. }
  202483. CGFunctionRelease (function);
  202484. return result;
  202485. }
  202486. void drawGradient()
  202487. {
  202488. flip();
  202489. applyTransform (state->fillType.transform);
  202490. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  202491. // you draw a gradient with high quality interp enabled).
  202492. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  202493. CGContextSetAlpha (context, state->fillType.getOpacity());
  202494. CGContextDrawShading (context, shading);
  202495. CGShadingRelease (shading);
  202496. }
  202497. void createPath (const Path& path) const
  202498. {
  202499. CGContextBeginPath (context);
  202500. Path::Iterator i (path);
  202501. while (i.next())
  202502. {
  202503. switch (i.elementType)
  202504. {
  202505. case Path::Iterator::startNewSubPath:
  202506. CGContextMoveToPoint (context, i.x1, i.y1);
  202507. break;
  202508. case Path::Iterator::lineTo:
  202509. CGContextAddLineToPoint (context, i.x1, i.y1);
  202510. break;
  202511. case Path::Iterator::quadraticTo:
  202512. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  202513. break;
  202514. case Path::Iterator::cubicTo:
  202515. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  202516. break;
  202517. case Path::Iterator::closePath:
  202518. CGContextClosePath (context); break;
  202519. default:
  202520. jassertfalse
  202521. break;
  202522. }
  202523. }
  202524. }
  202525. void createPath (const Path& path, const AffineTransform& transform) const
  202526. {
  202527. CGContextBeginPath (context);
  202528. Path::Iterator i (path);
  202529. while (i.next())
  202530. {
  202531. switch (i.elementType)
  202532. {
  202533. case Path::Iterator::startNewSubPath:
  202534. transform.transformPoint (i.x1, i.y1);
  202535. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  202536. break;
  202537. case Path::Iterator::lineTo:
  202538. transform.transformPoint (i.x1, i.y1);
  202539. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  202540. break;
  202541. case Path::Iterator::quadraticTo:
  202542. transform.transformPoint (i.x1, i.y1);
  202543. transform.transformPoint (i.x2, i.y2);
  202544. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  202545. break;
  202546. case Path::Iterator::cubicTo:
  202547. transform.transformPoint (i.x1, i.y1);
  202548. transform.transformPoint (i.x2, i.y2);
  202549. transform.transformPoint (i.x3, i.y3);
  202550. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  202551. break;
  202552. case Path::Iterator::closePath:
  202553. CGContextClosePath (context); break;
  202554. default:
  202555. jassertfalse
  202556. break;
  202557. }
  202558. }
  202559. }
  202560. static Image* createAlphaChannelImage (const Image& im)
  202561. {
  202562. if (im.getFormat() == Image::SingleChannel)
  202563. return const_cast <Image*> (&im);
  202564. return im.createCopyOfAlphaChannel();
  202565. }
  202566. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  202567. {
  202568. if (im.getFormat() != Image::SingleChannel)
  202569. delete alphaIm;
  202570. }
  202571. void flip() const
  202572. {
  202573. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  202574. }
  202575. void applyTransform (const AffineTransform& transform) const
  202576. {
  202577. CGAffineTransform t;
  202578. t.a = transform.mat00;
  202579. t.b = transform.mat10;
  202580. t.c = transform.mat01;
  202581. t.d = transform.mat11;
  202582. t.tx = transform.mat02;
  202583. t.ty = transform.mat12;
  202584. CGContextConcatCTM (context, t);
  202585. }
  202586. CoreGraphicsContext (const CoreGraphicsContext&);
  202587. CoreGraphicsContext& operator= (const CoreGraphicsContext&);
  202588. };
  202589. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  202590. {
  202591. return new CoreGraphicsContext (context, imageHeight);
  202592. }
  202593. #endif
  202594. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  202595. /*** Start of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  202596. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202597. // compiled on its own).
  202598. #if JUCE_INCLUDED_FILE
  202599. class UIViewComponentPeer;
  202600. END_JUCE_NAMESPACE
  202601. #define JuceUIView MakeObjCClassName(JuceUIView)
  202602. @interface JuceUIView : UIView <UITextFieldDelegate>
  202603. {
  202604. @public
  202605. UIViewComponentPeer* owner;
  202606. UITextField *hiddenTextField;
  202607. }
  202608. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner withFrame: (CGRect) frame;
  202609. - (void) dealloc;
  202610. - (void) drawRect: (CGRect) r;
  202611. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event;
  202612. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event;
  202613. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event;
  202614. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event;
  202615. - (BOOL) becomeFirstResponder;
  202616. - (BOOL) resignFirstResponder;
  202617. - (BOOL) canBecomeFirstResponder;
  202618. - (void) asyncRepaint: (id) rect;
  202619. - (BOOL) textField: (UITextField*) textField shouldChangeCharactersInRange: (NSRange) range replacementString: (NSString*) string;
  202620. - (BOOL) textFieldShouldClear: (UITextField*) textField;
  202621. - (BOOL) textFieldShouldReturn: (UITextField*) textField;
  202622. @end
  202623. #define JuceUIWindow MakeObjCClassName(JuceUIWindow)
  202624. @interface JuceUIWindow : UIWindow
  202625. {
  202626. @private
  202627. UIViewComponentPeer* owner;
  202628. bool isZooming;
  202629. }
  202630. - (void) setOwner: (UIViewComponentPeer*) owner;
  202631. - (void) becomeKeyWindow;
  202632. @end
  202633. BEGIN_JUCE_NAMESPACE
  202634. class UIViewComponentPeer : public ComponentPeer,
  202635. public FocusChangeListener
  202636. {
  202637. public:
  202638. UIViewComponentPeer (Component* const component,
  202639. const int windowStyleFlags,
  202640. UIView* viewToAttachTo);
  202641. ~UIViewComponentPeer();
  202642. void* getNativeHandle() const;
  202643. void setVisible (bool shouldBeVisible);
  202644. void setTitle (const String& title);
  202645. void setPosition (int x, int y);
  202646. void setSize (int w, int h);
  202647. void setBounds (int x, int y, int w, int h, bool isNowFullScreen);
  202648. const Rectangle<int> getBounds() const;
  202649. const Rectangle<int> getBounds (const bool global) const;
  202650. const Point<int> getScreenPosition() const;
  202651. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition);
  202652. const Point<int> globalPositionToRelative (const Point<int>& screenPosition);
  202653. void setMinimised (bool shouldBeMinimised);
  202654. bool isMinimised() const;
  202655. void setFullScreen (bool shouldBeFullScreen);
  202656. bool isFullScreen() const;
  202657. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const;
  202658. const BorderSize getFrameSize() const;
  202659. bool setAlwaysOnTop (bool alwaysOnTop);
  202660. void toFront (bool makeActiveWindow);
  202661. void toBehind (ComponentPeer* other);
  202662. void setIcon (const Image& newIcon);
  202663. virtual void drawRect (CGRect r);
  202664. virtual bool canBecomeKeyWindow();
  202665. virtual bool windowShouldClose();
  202666. virtual void redirectMovedOrResized();
  202667. virtual CGRect constrainRect (CGRect r);
  202668. virtual void viewFocusGain();
  202669. virtual void viewFocusLoss();
  202670. bool isFocused() const;
  202671. void grabFocus();
  202672. void textInputRequired (const Point<int>& position);
  202673. virtual BOOL textFieldReplaceCharacters (const Range<int>& range, const String& text);
  202674. virtual BOOL textFieldShouldClear();
  202675. virtual BOOL textFieldShouldReturn();
  202676. void updateHiddenTextContent (TextInputTarget* target);
  202677. void globalFocusChanged (Component*);
  202678. void handleTouches (UIEvent* e, bool isDown, bool isUp, bool isCancel);
  202679. void repaint (int x, int y, int w, int h);
  202680. void performAnyPendingRepaintsNow();
  202681. juce_UseDebuggingNewOperator
  202682. UIWindow* window;
  202683. JuceUIView* view;
  202684. bool isSharedWindow, fullScreen, insideDrawRect;
  202685. static ModifierKeys currentModifiers;
  202686. static int64 getMouseTime (UIEvent* e)
  202687. {
  202688. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  202689. + (int64) ([e timestamp] * 1000.0);
  202690. }
  202691. Array <UITouch*> currentTouches;
  202692. };
  202693. END_JUCE_NAMESPACE
  202694. @implementation JuceUIView
  202695. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner_
  202696. withFrame: (CGRect) frame
  202697. {
  202698. [super initWithFrame: frame];
  202699. owner = owner_;
  202700. hiddenTextField = [[UITextField alloc] initWithFrame: CGRectMake (0, 0, 0, 0)];
  202701. [self addSubview: hiddenTextField];
  202702. hiddenTextField.delegate = self;
  202703. return self;
  202704. }
  202705. - (void) dealloc
  202706. {
  202707. [hiddenTextField removeFromSuperview];
  202708. [hiddenTextField release];
  202709. [super dealloc];
  202710. }
  202711. - (void) drawRect: (CGRect) r
  202712. {
  202713. if (owner != 0)
  202714. owner->drawRect (r);
  202715. }
  202716. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  202717. {
  202718. return false;
  202719. }
  202720. ModifierKeys UIViewComponentPeer::currentModifiers;
  202721. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  202722. {
  202723. return UIViewComponentPeer::currentModifiers;
  202724. }
  202725. void ModifierKeys::updateCurrentModifiers() throw()
  202726. {
  202727. currentModifiers = UIViewComponentPeer::currentModifiers;
  202728. }
  202729. JUCE_NAMESPACE::Point<int> juce_lastMousePos;
  202730. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event
  202731. {
  202732. if (owner != 0)
  202733. owner->handleTouches (event, true, false, false);
  202734. }
  202735. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event
  202736. {
  202737. if (owner != 0)
  202738. owner->handleTouches (event, false, false, false);
  202739. }
  202740. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event
  202741. {
  202742. if (owner != 0)
  202743. owner->handleTouches (event, false, true, false);
  202744. }
  202745. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event
  202746. {
  202747. if (owner != 0)
  202748. owner->handleTouches (event, false, true, true);
  202749. [self touchesEnded: touches withEvent: event];
  202750. }
  202751. - (BOOL) becomeFirstResponder
  202752. {
  202753. if (owner != 0)
  202754. owner->viewFocusGain();
  202755. return true;
  202756. }
  202757. - (BOOL) resignFirstResponder
  202758. {
  202759. if (owner != 0)
  202760. owner->viewFocusLoss();
  202761. return true;
  202762. }
  202763. - (BOOL) canBecomeFirstResponder
  202764. {
  202765. return owner != 0 && owner->canBecomeKeyWindow();
  202766. }
  202767. - (void) asyncRepaint: (id) rect
  202768. {
  202769. CGRect* r = (CGRect*) [((NSData*) rect) bytes];
  202770. [self setNeedsDisplayInRect: *r];
  202771. }
  202772. - (BOOL) textField: (UITextField*) textField shouldChangeCharactersInRange: (NSRange) range replacementString: (NSString*) text
  202773. {
  202774. return owner->textFieldReplaceCharacters (Range<int> (range.location, range.location + range.length),
  202775. nsStringToJuce (text));
  202776. }
  202777. - (BOOL) textFieldShouldClear: (UITextField*) textField
  202778. {
  202779. return owner->textFieldShouldClear();
  202780. }
  202781. - (BOOL) textFieldShouldReturn: (UITextField*) textField
  202782. {
  202783. return owner->textFieldShouldReturn();
  202784. }
  202785. @end
  202786. @implementation JuceUIWindow
  202787. - (void) setOwner: (UIViewComponentPeer*) owner_
  202788. {
  202789. owner = owner_;
  202790. isZooming = false;
  202791. }
  202792. - (void) becomeKeyWindow
  202793. {
  202794. [super becomeKeyWindow];
  202795. if (owner != 0)
  202796. owner->grabFocus();
  202797. }
  202798. @end
  202799. BEGIN_JUCE_NAMESPACE
  202800. UIViewComponentPeer::UIViewComponentPeer (Component* const component,
  202801. const int windowStyleFlags,
  202802. UIView* viewToAttachTo)
  202803. : ComponentPeer (component, windowStyleFlags),
  202804. window (0),
  202805. view (0),
  202806. isSharedWindow (viewToAttachTo != 0),
  202807. fullScreen (false),
  202808. insideDrawRect (false)
  202809. {
  202810. CGRect r = CGRectMake (0, 0, (float) component->getWidth(), (float) component->getHeight());
  202811. view = [[JuceUIView alloc] initWithOwner: this withFrame: r];
  202812. if (isSharedWindow)
  202813. {
  202814. window = [viewToAttachTo window];
  202815. [viewToAttachTo addSubview: view];
  202816. setVisible (component->isVisible());
  202817. }
  202818. else
  202819. {
  202820. r.origin.x = (float) component->getX();
  202821. r.origin.y = (float) component->getY();
  202822. r.origin.y = [[UIScreen mainScreen] bounds].size.height - (r.origin.y + r.size.height);
  202823. window = [[JuceUIWindow alloc] init];
  202824. window.frame = r;
  202825. window.opaque = component->isOpaque();
  202826. view.opaque = component->isOpaque();
  202827. window.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  202828. view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  202829. [((JuceUIWindow*) window) setOwner: this];
  202830. if (component->isAlwaysOnTop())
  202831. window.windowLevel = UIWindowLevelAlert;
  202832. [window addSubview: view];
  202833. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  202834. view.hidden = ! component->isVisible();
  202835. window.hidden = ! component->isVisible();
  202836. view.multipleTouchEnabled = YES;
  202837. }
  202838. setTitle (component->getName());
  202839. Desktop::getInstance().addFocusChangeListener (this);
  202840. }
  202841. UIViewComponentPeer::~UIViewComponentPeer()
  202842. {
  202843. Desktop::getInstance().removeFocusChangeListener (this);
  202844. view->owner = 0;
  202845. [view removeFromSuperview];
  202846. [view release];
  202847. if (! isSharedWindow)
  202848. {
  202849. [((JuceUIWindow*) window) setOwner: 0];
  202850. [window release];
  202851. }
  202852. }
  202853. void* UIViewComponentPeer::getNativeHandle() const
  202854. {
  202855. return view;
  202856. }
  202857. void UIViewComponentPeer::setVisible (bool shouldBeVisible)
  202858. {
  202859. view.hidden = ! shouldBeVisible;
  202860. if (! isSharedWindow)
  202861. window.hidden = ! shouldBeVisible;
  202862. }
  202863. void UIViewComponentPeer::setTitle (const String& title)
  202864. {
  202865. // xxx is this possible?
  202866. }
  202867. void UIViewComponentPeer::setPosition (int x, int y)
  202868. {
  202869. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  202870. }
  202871. void UIViewComponentPeer::setSize (int w, int h)
  202872. {
  202873. setBounds (component->getX(), component->getY(), w, h, false);
  202874. }
  202875. void UIViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  202876. {
  202877. fullScreen = isNowFullScreen;
  202878. w = jmax (0, w);
  202879. h = jmax (0, h);
  202880. CGRect r;
  202881. r.origin.x = (float) x;
  202882. r.origin.y = (float) y;
  202883. r.size.width = (float) w;
  202884. r.size.height = (float) h;
  202885. if (isSharedWindow)
  202886. {
  202887. //r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  202888. if ([view frame].size.width != r.size.width
  202889. || [view frame].size.height != r.size.height)
  202890. [view setNeedsDisplay];
  202891. view.frame = r;
  202892. }
  202893. else
  202894. {
  202895. window.frame = r;
  202896. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  202897. }
  202898. }
  202899. const Rectangle<int> UIViewComponentPeer::getBounds (const bool global) const
  202900. {
  202901. CGRect r = [view frame];
  202902. if (global && [view window] != 0)
  202903. {
  202904. r = [view convertRect: r toView: nil];
  202905. CGRect wr = [[view window] frame];
  202906. r.origin.x += wr.origin.x;
  202907. r.origin.y += wr.origin.y;
  202908. }
  202909. return Rectangle<int> ((int) r.origin.x, (int) r.origin.y,
  202910. (int) r.size.width, (int) r.size.height);
  202911. }
  202912. const Rectangle<int> UIViewComponentPeer::getBounds() const
  202913. {
  202914. return getBounds (! isSharedWindow);
  202915. }
  202916. const Point<int> UIViewComponentPeer::getScreenPosition() const
  202917. {
  202918. return getBounds (true).getPosition();
  202919. }
  202920. const Point<int> UIViewComponentPeer::relativePositionToGlobal (const Point<int>& relativePosition)
  202921. {
  202922. return relativePosition + getScreenPosition();
  202923. }
  202924. const Point<int> UIViewComponentPeer::globalPositionToRelative (const Point<int>& screenPosition)
  202925. {
  202926. return screenPosition - getScreenPosition();
  202927. }
  202928. CGRect UIViewComponentPeer::constrainRect (CGRect r)
  202929. {
  202930. if (constrainer != 0)
  202931. {
  202932. CGRect current = [window frame];
  202933. current.origin.y = [[UIScreen mainScreen] bounds].size.height - current.origin.y - current.size.height;
  202934. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.origin.y - r.size.height;
  202935. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  202936. (int) r.size.width, (int) r.size.height);
  202937. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  202938. (int) current.size.width, (int) current.size.height);
  202939. constrainer->checkBounds (pos, original,
  202940. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  202941. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  202942. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  202943. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  202944. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  202945. r.origin.x = pos.getX();
  202946. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.size.height - pos.getY();
  202947. r.size.width = pos.getWidth();
  202948. r.size.height = pos.getHeight();
  202949. }
  202950. return r;
  202951. }
  202952. void UIViewComponentPeer::setMinimised (bool shouldBeMinimised)
  202953. {
  202954. // xxx
  202955. }
  202956. bool UIViewComponentPeer::isMinimised() const
  202957. {
  202958. return false;
  202959. }
  202960. void UIViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  202961. {
  202962. if (! isSharedWindow)
  202963. {
  202964. Rectangle<int> r (lastNonFullscreenBounds);
  202965. setMinimised (false);
  202966. if (fullScreen != shouldBeFullScreen)
  202967. {
  202968. if (shouldBeFullScreen)
  202969. r = Desktop::getInstance().getMainMonitorArea();
  202970. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  202971. if (r != getComponent()->getBounds() && ! r.isEmpty())
  202972. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  202973. }
  202974. }
  202975. }
  202976. bool UIViewComponentPeer::isFullScreen() const
  202977. {
  202978. return fullScreen;
  202979. }
  202980. bool UIViewComponentPeer::contains (const Point<int>& position, bool trueIfInAChildWindow) const
  202981. {
  202982. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  202983. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  202984. return false;
  202985. CGPoint p;
  202986. p.x = (float) position.getX();
  202987. p.y = (float) position.getY();
  202988. UIView* v = [view hitTest: p withEvent: nil];
  202989. if (trueIfInAChildWindow)
  202990. return v != nil;
  202991. return v == view;
  202992. }
  202993. const BorderSize UIViewComponentPeer::getFrameSize() const
  202994. {
  202995. BorderSize b;
  202996. if (! isSharedWindow)
  202997. {
  202998. CGRect v = [view convertRect: [view frame] toView: nil];
  202999. CGRect w = [window frame];
  203000. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  203001. b.setBottom ((int) v.origin.y);
  203002. b.setLeft ((int) v.origin.x);
  203003. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  203004. }
  203005. return b;
  203006. }
  203007. bool UIViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  203008. {
  203009. if (! isSharedWindow)
  203010. window.windowLevel = alwaysOnTop ? UIWindowLevelAlert : UIWindowLevelNormal;
  203011. return true;
  203012. }
  203013. void UIViewComponentPeer::toFront (bool makeActiveWindow)
  203014. {
  203015. if (isSharedWindow)
  203016. [[view superview] bringSubviewToFront: view];
  203017. if (window != 0 && component->isVisible())
  203018. [window makeKeyAndVisible];
  203019. }
  203020. void UIViewComponentPeer::toBehind (ComponentPeer* other)
  203021. {
  203022. UIViewComponentPeer* o = (UIViewComponentPeer*) other;
  203023. if (isSharedWindow)
  203024. {
  203025. [[view superview] insertSubview: view belowSubview: o->view];
  203026. }
  203027. else
  203028. {
  203029. jassertfalse // don't know how to do this
  203030. }
  203031. }
  203032. void UIViewComponentPeer::setIcon (const Image& /*newIcon*/)
  203033. {
  203034. // to do..
  203035. }
  203036. void UIViewComponentPeer::handleTouches (UIEvent* event, const bool isDown, const bool isUp, bool isCancel)
  203037. {
  203038. NSArray* touches = [[event touchesForView: view] allObjects];
  203039. for (unsigned int i = 0; i < [touches count]; ++i)
  203040. {
  203041. UITouch* touch = [touches objectAtIndex: i];
  203042. CGPoint p = [touch locationInView: view];
  203043. const Point<int> pos ((int) p.x, (int) p.y);
  203044. juce_lastMousePos = pos + getScreenPosition();
  203045. const int64 time = getMouseTime (event);
  203046. int touchIndex = currentTouches.indexOf (touch);
  203047. if (touchIndex < 0)
  203048. {
  203049. touchIndex = currentTouches.size();
  203050. currentTouches.add (touch);
  203051. }
  203052. if (isDown)
  203053. {
  203054. currentModifiers = currentModifiers.withoutMouseButtons();
  203055. handleMouseEvent (touchIndex, pos, currentModifiers, time);
  203056. currentModifiers = currentModifiers.withoutMouseButtons().withFlags (ModifierKeys::leftButtonModifier);
  203057. }
  203058. else if (isUp)
  203059. {
  203060. currentModifiers = currentModifiers.withoutMouseButtons();
  203061. currentTouches.remove (touchIndex);
  203062. }
  203063. if (isCancel)
  203064. currentTouches.clear();
  203065. handleMouseEvent (touchIndex, pos, currentModifiers, time);
  203066. }
  203067. }
  203068. static UIViewComponentPeer* currentlyFocusedPeer = 0;
  203069. void UIViewComponentPeer::viewFocusGain()
  203070. {
  203071. if (currentlyFocusedPeer != this)
  203072. {
  203073. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  203074. currentlyFocusedPeer->handleFocusLoss();
  203075. currentlyFocusedPeer = this;
  203076. handleFocusGain();
  203077. }
  203078. }
  203079. void UIViewComponentPeer::viewFocusLoss()
  203080. {
  203081. if (currentlyFocusedPeer == this)
  203082. {
  203083. currentlyFocusedPeer = 0;
  203084. handleFocusLoss();
  203085. }
  203086. }
  203087. void juce_HandleProcessFocusChange()
  203088. {
  203089. if (UIViewComponentPeer::isValidPeer (currentlyFocusedPeer))
  203090. {
  203091. if (Process::isForegroundProcess())
  203092. {
  203093. currentlyFocusedPeer->handleFocusGain();
  203094. ComponentPeer::bringModalComponentToFront();
  203095. }
  203096. else
  203097. {
  203098. currentlyFocusedPeer->handleFocusLoss();
  203099. // turn kiosk mode off if we lose focus..
  203100. Desktop::getInstance().setKioskModeComponent (0);
  203101. }
  203102. }
  203103. }
  203104. bool UIViewComponentPeer::isFocused() const
  203105. {
  203106. return isSharedWindow ? this == currentlyFocusedPeer
  203107. : (window != 0 && [window isKeyWindow]);
  203108. }
  203109. void UIViewComponentPeer::grabFocus()
  203110. {
  203111. if (window != 0)
  203112. {
  203113. [window makeKeyWindow];
  203114. viewFocusGain();
  203115. }
  203116. }
  203117. void UIViewComponentPeer::textInputRequired (const Point<int>&)
  203118. {
  203119. }
  203120. void UIViewComponentPeer::updateHiddenTextContent (TextInputTarget* target)
  203121. {
  203122. view->hiddenTextField.text = juceStringToNS (target->getTextInRange (Range<int> (0, target->getHighlightedRegion().getStart())));
  203123. }
  203124. BOOL UIViewComponentPeer::textFieldReplaceCharacters (const Range<int>& range, const String& text)
  203125. {
  203126. TextInputTarget* const target = findCurrentTextInputTarget();
  203127. if (target != 0)
  203128. {
  203129. const Range<int> currentSelection (target->getHighlightedRegion());
  203130. if (range.getLength() == 1 && text.isEmpty()) // (detect backspace)
  203131. if (currentSelection.isEmpty())
  203132. target->setHighlightedRegion (currentSelection.withStart (currentSelection.getStart() - 1));
  203133. target->insertTextAtCaret (text);
  203134. updateHiddenTextContent (target);
  203135. }
  203136. return NO;
  203137. }
  203138. BOOL UIViewComponentPeer::textFieldShouldClear()
  203139. {
  203140. TextInputTarget* const target = findCurrentTextInputTarget();
  203141. if (target != 0)
  203142. {
  203143. target->setHighlightedRegion (Range<int> (0, std::numeric_limits<int>::max()));
  203144. target->insertTextAtCaret (String::empty);
  203145. updateHiddenTextContent (target);
  203146. }
  203147. return YES;
  203148. }
  203149. BOOL UIViewComponentPeer::textFieldShouldReturn()
  203150. {
  203151. TextInputTarget* const target = findCurrentTextInputTarget();
  203152. if (target != 0)
  203153. {
  203154. target->insertTextAtCaret ("\n");
  203155. updateHiddenTextContent (target);
  203156. }
  203157. return YES;
  203158. }
  203159. void UIViewComponentPeer::globalFocusChanged (Component*)
  203160. {
  203161. TextInputTarget* const target = findCurrentTextInputTarget();
  203162. if (target != 0)
  203163. {
  203164. Component* comp = dynamic_cast<Component*> (target);
  203165. Point<int> pos (comp->relativePositionToOtherComponent (component, Point<int>()));
  203166. view->hiddenTextField.frame = CGRectMake (pos.getX(), pos.getY(), 0, 0);
  203167. updateHiddenTextContent (target);
  203168. [view->hiddenTextField becomeFirstResponder];
  203169. }
  203170. else
  203171. {
  203172. [view->hiddenTextField resignFirstResponder];
  203173. }
  203174. }
  203175. void UIViewComponentPeer::drawRect (CGRect r)
  203176. {
  203177. if (r.size.width < 1.0f || r.size.height < 1.0f)
  203178. return;
  203179. CGContextRef cg = UIGraphicsGetCurrentContext();
  203180. if (! component->isOpaque())
  203181. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  203182. CGContextConcatCTM (cg, CGAffineTransformMake (1, 0, 0, -1, 0, view.bounds.size.height));
  203183. CoreGraphicsContext g (cg, view.bounds.size.height);
  203184. insideDrawRect = true;
  203185. handlePaint (g);
  203186. insideDrawRect = false;
  203187. }
  203188. bool UIViewComponentPeer::canBecomeKeyWindow()
  203189. {
  203190. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  203191. }
  203192. bool UIViewComponentPeer::windowShouldClose()
  203193. {
  203194. if (! isValidPeer (this))
  203195. return YES;
  203196. handleUserClosingWindow();
  203197. return NO;
  203198. }
  203199. void UIViewComponentPeer::redirectMovedOrResized()
  203200. {
  203201. handleMovedOrResized();
  203202. }
  203203. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  203204. {
  203205. }
  203206. class AsyncRepaintMessage : public CallbackMessage
  203207. {
  203208. public:
  203209. UIViewComponentPeer* const peer;
  203210. const Rectangle<int> rect;
  203211. AsyncRepaintMessage (UIViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  203212. : peer (peer_), rect (rect_)
  203213. {
  203214. }
  203215. void messageCallback()
  203216. {
  203217. if (ComponentPeer::isValidPeer (peer))
  203218. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  203219. }
  203220. };
  203221. void UIViewComponentPeer::repaint (int x, int y, int w, int h)
  203222. {
  203223. if (insideDrawRect || ! MessageManager::getInstance()->isThisTheMessageThread())
  203224. {
  203225. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  203226. }
  203227. else
  203228. {
  203229. [view setNeedsDisplayInRect: CGRectMake ((float) x, (float) y, (float) w, (float) h)];
  203230. }
  203231. }
  203232. void UIViewComponentPeer::performAnyPendingRepaintsNow()
  203233. {
  203234. }
  203235. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  203236. {
  203237. return new UIViewComponentPeer (this, styleFlags, (UIView*) windowToAttachTo);
  203238. }
  203239. Image* juce_createIconForFile (const File& file)
  203240. {
  203241. return 0;
  203242. }
  203243. void Desktop::createMouseInputSources()
  203244. {
  203245. for (int i = 0; i < 10; ++i)
  203246. mouseSources.add (new MouseInputSource (i, false));
  203247. }
  203248. bool Desktop::canUseSemiTransparentWindows() throw()
  203249. {
  203250. return true;
  203251. }
  203252. const Point<int> Desktop::getMousePosition()
  203253. {
  203254. return juce_lastMousePos;
  203255. }
  203256. void Desktop::setMousePosition (const Point<int>&)
  203257. {
  203258. }
  203259. const int KeyPress::spaceKey = ' ';
  203260. const int KeyPress::returnKey = 0x0d;
  203261. const int KeyPress::escapeKey = 0x1b;
  203262. const int KeyPress::backspaceKey = 0x7f;
  203263. const int KeyPress::leftKey = 0x1000;
  203264. const int KeyPress::rightKey = 0x1001;
  203265. const int KeyPress::upKey = 0x1002;
  203266. const int KeyPress::downKey = 0x1003;
  203267. const int KeyPress::pageUpKey = 0x1004;
  203268. const int KeyPress::pageDownKey = 0x1005;
  203269. const int KeyPress::endKey = 0x1006;
  203270. const int KeyPress::homeKey = 0x1007;
  203271. const int KeyPress::deleteKey = 0x1008;
  203272. const int KeyPress::insertKey = -1;
  203273. const int KeyPress::tabKey = 9;
  203274. const int KeyPress::F1Key = 0x2001;
  203275. const int KeyPress::F2Key = 0x2002;
  203276. const int KeyPress::F3Key = 0x2003;
  203277. const int KeyPress::F4Key = 0x2004;
  203278. const int KeyPress::F5Key = 0x2005;
  203279. const int KeyPress::F6Key = 0x2006;
  203280. const int KeyPress::F7Key = 0x2007;
  203281. const int KeyPress::F8Key = 0x2008;
  203282. const int KeyPress::F9Key = 0x2009;
  203283. const int KeyPress::F10Key = 0x200a;
  203284. const int KeyPress::F11Key = 0x200b;
  203285. const int KeyPress::F12Key = 0x200c;
  203286. const int KeyPress::F13Key = 0x200d;
  203287. const int KeyPress::F14Key = 0x200e;
  203288. const int KeyPress::F15Key = 0x200f;
  203289. const int KeyPress::F16Key = 0x2010;
  203290. const int KeyPress::numberPad0 = 0x30020;
  203291. const int KeyPress::numberPad1 = 0x30021;
  203292. const int KeyPress::numberPad2 = 0x30022;
  203293. const int KeyPress::numberPad3 = 0x30023;
  203294. const int KeyPress::numberPad4 = 0x30024;
  203295. const int KeyPress::numberPad5 = 0x30025;
  203296. const int KeyPress::numberPad6 = 0x30026;
  203297. const int KeyPress::numberPad7 = 0x30027;
  203298. const int KeyPress::numberPad8 = 0x30028;
  203299. const int KeyPress::numberPad9 = 0x30029;
  203300. const int KeyPress::numberPadAdd = 0x3002a;
  203301. const int KeyPress::numberPadSubtract = 0x3002b;
  203302. const int KeyPress::numberPadMultiply = 0x3002c;
  203303. const int KeyPress::numberPadDivide = 0x3002d;
  203304. const int KeyPress::numberPadSeparator = 0x3002e;
  203305. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  203306. const int KeyPress::numberPadEquals = 0x30030;
  203307. const int KeyPress::numberPadDelete = 0x30031;
  203308. const int KeyPress::playKey = 0x30000;
  203309. const int KeyPress::stopKey = 0x30001;
  203310. const int KeyPress::fastForwardKey = 0x30002;
  203311. const int KeyPress::rewindKey = 0x30003;
  203312. #endif
  203313. /*** End of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  203314. /*** Start of inlined file: juce_iphone_MessageManager.mm ***/
  203315. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203316. // compiled on its own).
  203317. #if JUCE_INCLUDED_FILE
  203318. struct CallbackMessagePayload
  203319. {
  203320. MessageCallbackFunction* function;
  203321. void* parameter;
  203322. void* volatile result;
  203323. bool volatile hasBeenExecuted;
  203324. };
  203325. END_JUCE_NAMESPACE
  203326. using namespace JUCE_NAMESPACE;
  203327. @interface JuceAppDelegate : NSObject <UIApplicationDelegate>
  203328. {
  203329. }
  203330. - (JuceAppDelegate*) init;
  203331. - (void) dealloc;
  203332. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url;
  203333. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  203334. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  203335. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  203336. - (void) customEvent: (id) data;
  203337. - (void) performCallback: (id) info;
  203338. @end
  203339. @implementation JuceAppDelegate
  203340. - (JuceAppDelegate*) init
  203341. {
  203342. [super init];
  203343. [[UIApplication sharedApplication] setDelegate: self];
  203344. return self;
  203345. }
  203346. - (void) dealloc
  203347. {
  203348. [[UIApplication sharedApplication] setDelegate: nil];
  203349. [super dealloc];
  203350. }
  203351. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url
  203352. {
  203353. if (JUCEApplication::getInstance() != 0)
  203354. {
  203355. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce ([url absoluteString]));
  203356. return YES;
  203357. }
  203358. return NO;
  203359. }
  203360. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  203361. {
  203362. juce_HandleProcessFocusChange();
  203363. }
  203364. - (void) applicationDidResignActive: (NSNotification*) aNotification
  203365. {
  203366. juce_HandleProcessFocusChange();
  203367. }
  203368. - (void) applicationWillUnhide: (NSNotification*) aNotification
  203369. {
  203370. juce_HandleProcessFocusChange();
  203371. }
  203372. - (void) customEvent: (id) n
  203373. {
  203374. NSData* data = (NSData*) n;
  203375. void* message = 0;
  203376. [data getBytes: &message length: sizeof (message)];
  203377. [data release];
  203378. if (message != 0)
  203379. MessageManager::getInstance()->deliverMessage (message);
  203380. }
  203381. - (void) performCallback: (id) info
  203382. {
  203383. if ([info isKindOfClass: [NSData class]])
  203384. {
  203385. CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
  203386. if (pl != 0)
  203387. {
  203388. pl->result = (*pl->function) (pl->parameter);
  203389. pl->hasBeenExecuted = true;
  203390. }
  203391. }
  203392. else
  203393. {
  203394. jassertfalse // should never get here!
  203395. }
  203396. }
  203397. @end
  203398. BEGIN_JUCE_NAMESPACE
  203399. static JuceAppDelegate* juceAppDelegate = 0;
  203400. void MessageManager::runDispatchLoop()
  203401. {
  203402. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203403. runDispatchLoopUntil (-1);
  203404. }
  203405. void MessageManager::stopDispatchLoop()
  203406. {
  203407. exit (0); // iPhone apps get no mercy..
  203408. }
  203409. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  203410. {
  203411. const ScopedAutoReleasePool pool;
  203412. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203413. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  203414. NSDate* endDate = [NSDate dateWithTimeIntervalSinceNow: millisecondsToRunFor * 0.001];
  203415. while (! quitMessagePosted)
  203416. {
  203417. const ScopedAutoReleasePool pool;
  203418. [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
  203419. beforeDate: endDate];
  203420. if (millisecondsToRunFor >= 0 && Time::getMillisecondCounter() >= endTime)
  203421. break;
  203422. }
  203423. return ! quitMessagePosted;
  203424. }
  203425. static CFRunLoopRef runLoop = 0;
  203426. static CFRunLoopSourceRef runLoopSource = 0;
  203427. static Array <void*, CriticalSection>* pendingMessages = 0;
  203428. static void runLoopSourceCallback (void*)
  203429. {
  203430. if (pendingMessages != 0)
  203431. {
  203432. int numDispatched = 0;
  203433. do
  203434. {
  203435. void* const nextMessage = pendingMessages->remove (0);
  203436. if (nextMessage == 0)
  203437. return;
  203438. const ScopedAutoReleasePool pool;
  203439. MessageManager::getInstance()->deliverMessage (nextMessage);
  203440. } while (++numDispatched <= 4);
  203441. CFRunLoopSourceSignal (runLoopSource);
  203442. CFRunLoopWakeUp (runLoop);
  203443. }
  203444. }
  203445. void MessageManager::doPlatformSpecificInitialisation()
  203446. {
  203447. pendingMessages = new Array <void*, CriticalSection>();
  203448. runLoop = CFRunLoopGetCurrent();
  203449. CFRunLoopSourceContext sourceContext;
  203450. zerostruct (sourceContext);
  203451. sourceContext.perform = runLoopSourceCallback;
  203452. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  203453. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  203454. if (juceAppDelegate == 0)
  203455. juceAppDelegate = [[JuceAppDelegate alloc] init];
  203456. }
  203457. void MessageManager::doPlatformSpecificShutdown()
  203458. {
  203459. CFRunLoopSourceInvalidate (runLoopSource);
  203460. CFRelease (runLoopSource);
  203461. runLoopSource = 0;
  203462. if (pendingMessages != 0)
  203463. {
  203464. while (pendingMessages->size() > 0)
  203465. delete ((Message*) pendingMessages->remove(0));
  203466. deleteAndZero (pendingMessages);
  203467. }
  203468. if (juceAppDelegate != 0)
  203469. {
  203470. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  203471. [juceAppDelegate release];
  203472. juceAppDelegate = 0;
  203473. }
  203474. }
  203475. bool juce_postMessageToSystemQueue (void* message)
  203476. {
  203477. if (pendingMessages != 0)
  203478. {
  203479. pendingMessages->add (message);
  203480. CFRunLoopSourceSignal (runLoopSource);
  203481. CFRunLoopWakeUp (runLoop);
  203482. }
  203483. return true;
  203484. }
  203485. void MessageManager::broadcastMessage (const String& value) throw()
  203486. {
  203487. }
  203488. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  203489. void* data)
  203490. {
  203491. if (isThisTheMessageThread())
  203492. {
  203493. return (*callback) (data);
  203494. }
  203495. else
  203496. {
  203497. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  203498. // deadlock because the message manager is blocked from running, so can never
  203499. // call your function..
  203500. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  203501. const ScopedAutoReleasePool pool;
  203502. CallbackMessagePayload cmp;
  203503. cmp.function = callback;
  203504. cmp.parameter = data;
  203505. cmp.result = 0;
  203506. cmp.hasBeenExecuted = false;
  203507. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  203508. withObject: [NSData dataWithBytesNoCopy: &cmp
  203509. length: sizeof (cmp)
  203510. freeWhenDone: NO]
  203511. waitUntilDone: YES];
  203512. return cmp.result;
  203513. }
  203514. }
  203515. #endif
  203516. /*** End of inlined file: juce_iphone_MessageManager.mm ***/
  203517. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  203518. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203519. // compiled on its own).
  203520. #if JUCE_INCLUDED_FILE
  203521. #if JUCE_MAC
  203522. END_JUCE_NAMESPACE
  203523. using namespace JUCE_NAMESPACE;
  203524. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  203525. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  203526. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  203527. #else
  203528. @interface JuceFileChooserDelegate : NSObject
  203529. #endif
  203530. {
  203531. StringArray* filters;
  203532. }
  203533. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  203534. - (void) dealloc;
  203535. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  203536. @end
  203537. @implementation JuceFileChooserDelegate
  203538. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  203539. {
  203540. [super init];
  203541. filters = filters_;
  203542. return self;
  203543. }
  203544. - (void) dealloc
  203545. {
  203546. delete filters;
  203547. [super dealloc];
  203548. }
  203549. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  203550. {
  203551. const File f (nsStringToJuce (filename));
  203552. for (int i = filters->size(); --i >= 0;)
  203553. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  203554. return true;
  203555. return f.isDirectory();
  203556. }
  203557. @end
  203558. BEGIN_JUCE_NAMESPACE
  203559. void FileChooser::showPlatformDialog (Array<File>& results,
  203560. const String& title,
  203561. const File& currentFileOrDirectory,
  203562. const String& filter,
  203563. bool selectsDirectory,
  203564. bool selectsFiles,
  203565. bool isSaveDialogue,
  203566. bool warnAboutOverwritingExistingFiles,
  203567. bool selectMultipleFiles,
  203568. FilePreviewComponent* extraInfoComponent)
  203569. {
  203570. const ScopedAutoReleasePool pool;
  203571. StringArray* filters = new StringArray();
  203572. filters->addTokens (filter.replaceCharacters (T(",:"), T(";;")), T(";"), String::empty);
  203573. filters->trim();
  203574. filters->removeEmptyStrings();
  203575. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  203576. [delegate autorelease];
  203577. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  203578. : [NSOpenPanel openPanel];
  203579. [panel setTitle: juceStringToNS (title)];
  203580. if (! isSaveDialogue)
  203581. {
  203582. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203583. [openPanel setCanChooseDirectories: selectsDirectory];
  203584. [openPanel setCanChooseFiles: selectsFiles];
  203585. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  203586. }
  203587. [panel setDelegate: delegate];
  203588. if (isSaveDialogue || selectsDirectory)
  203589. [panel setCanCreateDirectories: YES];
  203590. String directory, filename;
  203591. if (currentFileOrDirectory.isDirectory())
  203592. {
  203593. directory = currentFileOrDirectory.getFullPathName();
  203594. }
  203595. else
  203596. {
  203597. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  203598. filename = currentFileOrDirectory.getFileName();
  203599. }
  203600. if ([panel runModalForDirectory: juceStringToNS (directory)
  203601. file: juceStringToNS (filename)]
  203602. == NSOKButton)
  203603. {
  203604. if (isSaveDialogue)
  203605. {
  203606. results.add (File (nsStringToJuce ([panel filename])));
  203607. }
  203608. else
  203609. {
  203610. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203611. NSArray* urls = [openPanel filenames];
  203612. for (unsigned int i = 0; i < [urls count]; ++i)
  203613. {
  203614. NSString* f = [urls objectAtIndex: i];
  203615. results.add (File (nsStringToJuce (f)));
  203616. }
  203617. }
  203618. }
  203619. [panel setDelegate: nil];
  203620. }
  203621. #else
  203622. void FileChooser::showPlatformDialog (Array<File>& results,
  203623. const String& title,
  203624. const File& currentFileOrDirectory,
  203625. const String& filter,
  203626. bool selectsDirectory,
  203627. bool selectsFiles,
  203628. bool isSaveDialogue,
  203629. bool warnAboutOverwritingExistingFiles,
  203630. bool selectMultipleFiles,
  203631. FilePreviewComponent* extraInfoComponent)
  203632. {
  203633. const ScopedAutoReleasePool pool;
  203634. jassertfalse //xxx to do
  203635. }
  203636. #endif
  203637. #endif
  203638. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  203639. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  203640. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203641. // compiled on its own).
  203642. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  203643. #if JUCE_MAC
  203644. END_JUCE_NAMESPACE
  203645. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  203646. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  203647. {
  203648. CriticalSection* contextLock;
  203649. bool needsUpdate;
  203650. }
  203651. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  203652. - (bool) makeActive;
  203653. - (void) makeInactive;
  203654. - (void) reshape;
  203655. @end
  203656. @implementation ThreadSafeNSOpenGLView
  203657. - (id) initWithFrame: (NSRect) frameRect
  203658. pixelFormat: (NSOpenGLPixelFormat*) format
  203659. {
  203660. contextLock = new CriticalSection();
  203661. self = [super initWithFrame: frameRect pixelFormat: format];
  203662. if (self != nil)
  203663. [[NSNotificationCenter defaultCenter] addObserver: self
  203664. selector: @selector (_surfaceNeedsUpdate:)
  203665. name: NSViewGlobalFrameDidChangeNotification
  203666. object: self];
  203667. return self;
  203668. }
  203669. - (void) dealloc
  203670. {
  203671. [[NSNotificationCenter defaultCenter] removeObserver: self];
  203672. delete contextLock;
  203673. [super dealloc];
  203674. }
  203675. - (bool) makeActive
  203676. {
  203677. const ScopedLock sl (*contextLock);
  203678. if ([self openGLContext] == 0)
  203679. return false;
  203680. [[self openGLContext] makeCurrentContext];
  203681. if (needsUpdate)
  203682. {
  203683. [super update];
  203684. needsUpdate = false;
  203685. }
  203686. return true;
  203687. }
  203688. - (void) makeInactive
  203689. {
  203690. const ScopedLock sl (*contextLock);
  203691. [NSOpenGLContext clearCurrentContext];
  203692. }
  203693. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  203694. {
  203695. const ScopedLock sl (*contextLock);
  203696. needsUpdate = true;
  203697. }
  203698. - (void) update
  203699. {
  203700. const ScopedLock sl (*contextLock);
  203701. needsUpdate = true;
  203702. }
  203703. - (void) reshape
  203704. {
  203705. const ScopedLock sl (*contextLock);
  203706. needsUpdate = true;
  203707. }
  203708. @end
  203709. BEGIN_JUCE_NAMESPACE
  203710. class WindowedGLContext : public OpenGLContext
  203711. {
  203712. public:
  203713. WindowedGLContext (Component* const component,
  203714. const OpenGLPixelFormat& pixelFormat_,
  203715. NSOpenGLContext* sharedContext)
  203716. : renderContext (0),
  203717. pixelFormat (pixelFormat_)
  203718. {
  203719. jassert (component != 0);
  203720. NSOpenGLPixelFormatAttribute attribs [64];
  203721. int n = 0;
  203722. attribs[n++] = NSOpenGLPFADoubleBuffer;
  203723. attribs[n++] = NSOpenGLPFAAccelerated;
  203724. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  203725. attribs[n++] = NSOpenGLPFAColorSize;
  203726. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  203727. pixelFormat.greenBits,
  203728. pixelFormat.blueBits);
  203729. attribs[n++] = NSOpenGLPFAAlphaSize;
  203730. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  203731. attribs[n++] = NSOpenGLPFADepthSize;
  203732. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  203733. attribs[n++] = NSOpenGLPFAStencilSize;
  203734. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  203735. attribs[n++] = NSOpenGLPFAAccumSize;
  203736. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  203737. pixelFormat.accumulationBufferGreenBits,
  203738. pixelFormat.accumulationBufferBlueBits,
  203739. pixelFormat.accumulationBufferAlphaBits);
  203740. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  203741. attribs[n++] = NSOpenGLPFASampleBuffers;
  203742. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  203743. attribs[n++] = NSOpenGLPFAClosestPolicy;
  203744. attribs[n++] = NSOpenGLPFANoRecovery;
  203745. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  203746. NSOpenGLPixelFormat* format
  203747. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  203748. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  203749. pixelFormat: format];
  203750. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  203751. shareContext: sharedContext] autorelease];
  203752. const GLint swapInterval = 1;
  203753. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  203754. [view setOpenGLContext: renderContext];
  203755. [renderContext setView: view];
  203756. [format release];
  203757. viewHolder = new NSViewComponentInternal (view, component);
  203758. }
  203759. ~WindowedGLContext()
  203760. {
  203761. makeInactive();
  203762. [renderContext clearDrawable];
  203763. viewHolder = 0;
  203764. }
  203765. bool makeActive() const throw()
  203766. {
  203767. jassert (renderContext != 0);
  203768. [view makeActive];
  203769. return isActive();
  203770. }
  203771. bool makeInactive() const throw()
  203772. {
  203773. [view makeInactive];
  203774. return true;
  203775. }
  203776. bool isActive() const throw()
  203777. {
  203778. return [NSOpenGLContext currentContext] == renderContext;
  203779. }
  203780. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  203781. void* getRawContext() const throw() { return renderContext; }
  203782. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  203783. {
  203784. }
  203785. void swapBuffers()
  203786. {
  203787. [renderContext flushBuffer];
  203788. }
  203789. bool setSwapInterval (const int numFramesPerSwap)
  203790. {
  203791. [renderContext setValues: (const GLint*) &numFramesPerSwap
  203792. forParameter: NSOpenGLCPSwapInterval];
  203793. return true;
  203794. }
  203795. int getSwapInterval() const
  203796. {
  203797. GLint numFrames = 0;
  203798. [renderContext getValues: &numFrames
  203799. forParameter: NSOpenGLCPSwapInterval];
  203800. return numFrames;
  203801. }
  203802. void repaint()
  203803. {
  203804. // we need to invalidate the juce view that holds this gl view, to make it
  203805. // cause a repaint callback
  203806. NSView* v = (NSView*) viewHolder->view;
  203807. NSRect r = [v frame];
  203808. // bit of a bodge here.. if we only invalidate the area of the gl component,
  203809. // it's completely covered by the NSOpenGLView, so the OS throws away the
  203810. // repaint message, thus never causing our paint() callback, and never repainting
  203811. // the comp. So invalidating just a little bit around the edge helps..
  203812. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  203813. }
  203814. void* getNativeWindowHandle() const { return viewHolder->view; }
  203815. juce_UseDebuggingNewOperator
  203816. NSOpenGLContext* renderContext;
  203817. ThreadSafeNSOpenGLView* view;
  203818. private:
  203819. OpenGLPixelFormat pixelFormat;
  203820. ScopedPointer <NSViewComponentInternal> viewHolder;
  203821. WindowedGLContext (const WindowedGLContext&);
  203822. WindowedGLContext& operator= (const WindowedGLContext&);
  203823. };
  203824. OpenGLContext* OpenGLComponent::createContext()
  203825. {
  203826. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this, preferredPixelFormat,
  203827. contextToShareListsWith != 0 ? (NSOpenGLContext*) contextToShareListsWith->getRawContext() : 0));
  203828. return (c->renderContext != 0) ? c.release() : 0;
  203829. }
  203830. void* OpenGLComponent::getNativeWindowHandle() const
  203831. {
  203832. return context != 0 ? static_cast<WindowedGLContext*> (static_cast<OpenGLContext*> (context))->getNativeWindowHandle()
  203833. : 0;
  203834. }
  203835. void juce_glViewport (const int w, const int h)
  203836. {
  203837. glViewport (0, 0, w, h);
  203838. }
  203839. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  203840. OwnedArray <OpenGLPixelFormat>& results)
  203841. {
  203842. /* GLint attribs [64];
  203843. int n = 0;
  203844. attribs[n++] = AGL_RGBA;
  203845. attribs[n++] = AGL_DOUBLEBUFFER;
  203846. attribs[n++] = AGL_ACCELERATED;
  203847. attribs[n++] = AGL_NO_RECOVERY;
  203848. attribs[n++] = AGL_NONE;
  203849. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  203850. while (p != 0)
  203851. {
  203852. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  203853. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  203854. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  203855. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  203856. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  203857. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  203858. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  203859. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  203860. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  203861. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  203862. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  203863. results.add (pf);
  203864. p = aglNextPixelFormat (p);
  203865. }*/
  203866. //jassertfalse //xxx can't see how you do this in cocoa!
  203867. }
  203868. #else
  203869. END_JUCE_NAMESPACE
  203870. @interface JuceGLView : UIView
  203871. {
  203872. }
  203873. + (Class) layerClass;
  203874. @end
  203875. @implementation JuceGLView
  203876. + (Class) layerClass
  203877. {
  203878. return [CAEAGLLayer class];
  203879. }
  203880. @end
  203881. BEGIN_JUCE_NAMESPACE
  203882. class GLESContext : public OpenGLContext
  203883. {
  203884. public:
  203885. GLESContext (UIViewComponentPeer* peer,
  203886. Component* const component_,
  203887. const OpenGLPixelFormat& pixelFormat_,
  203888. const GLESContext* const sharedContext,
  203889. NSUInteger apiType)
  203890. : component (component_), pixelFormat (pixelFormat_), glLayer (0), context (0),
  203891. useDepthBuffer (pixelFormat_.depthBufferBits > 0), frameBufferHandle (0), colorBufferHandle (0),
  203892. depthBufferHandle (0), lastWidth (0), lastHeight (0)
  203893. {
  203894. view = [[JuceGLView alloc] initWithFrame: CGRectMake (0, 0, 64, 64)];
  203895. view.opaque = YES;
  203896. view.hidden = NO;
  203897. view.backgroundColor = [UIColor blackColor];
  203898. view.userInteractionEnabled = NO;
  203899. glLayer = (CAEAGLLayer*) [view layer];
  203900. [peer->view addSubview: view];
  203901. if (sharedContext != 0)
  203902. context = [[EAGLContext alloc] initWithAPI: apiType
  203903. sharegroup: [sharedContext->context sharegroup]];
  203904. else
  203905. context = [[EAGLContext alloc] initWithAPI: apiType];
  203906. createGLBuffers();
  203907. }
  203908. ~GLESContext()
  203909. {
  203910. makeInactive();
  203911. [context release];
  203912. [view removeFromSuperview];
  203913. [view release];
  203914. freeGLBuffers();
  203915. }
  203916. bool makeActive() const throw()
  203917. {
  203918. jassert (context != 0);
  203919. [EAGLContext setCurrentContext: context];
  203920. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  203921. return true;
  203922. }
  203923. void swapBuffers()
  203924. {
  203925. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  203926. [context presentRenderbuffer: GL_RENDERBUFFER_OES];
  203927. }
  203928. bool makeInactive() const throw()
  203929. {
  203930. return [EAGLContext setCurrentContext: nil];
  203931. }
  203932. bool isActive() const throw()
  203933. {
  203934. return [EAGLContext currentContext] == context;
  203935. }
  203936. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  203937. void* getRawContext() const throw() { return (void*) glLayer; }
  203938. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  203939. {
  203940. view.frame = CGRectMake ((CGFloat) x, (CGFloat) y, (CGFloat) w, (CGFloat) h);
  203941. if (lastWidth != w || lastHeight != h)
  203942. {
  203943. lastWidth = w;
  203944. lastHeight = h;
  203945. freeGLBuffers();
  203946. createGLBuffers();
  203947. }
  203948. }
  203949. bool setSwapInterval (const int numFramesPerSwap)
  203950. {
  203951. numFrames = numFramesPerSwap;
  203952. return true;
  203953. }
  203954. int getSwapInterval() const
  203955. {
  203956. return numFrames;
  203957. }
  203958. void repaint()
  203959. {
  203960. }
  203961. void createGLBuffers()
  203962. {
  203963. makeActive();
  203964. glGenFramebuffersOES (1, &frameBufferHandle);
  203965. glGenRenderbuffersOES (1, &colorBufferHandle);
  203966. glGenRenderbuffersOES (1, &depthBufferHandle);
  203967. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  203968. [context renderbufferStorage: GL_RENDERBUFFER_OES fromDrawable: glLayer];
  203969. GLint width, height;
  203970. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &width);
  203971. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &height);
  203972. if (useDepthBuffer)
  203973. {
  203974. glBindRenderbufferOES (GL_RENDERBUFFER_OES, depthBufferHandle);
  203975. glRenderbufferStorageOES (GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, width, height);
  203976. }
  203977. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  203978. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  203979. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorBufferHandle);
  203980. if (useDepthBuffer)
  203981. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthBufferHandle);
  203982. jassert (glCheckFramebufferStatusOES (GL_FRAMEBUFFER_OES) == GL_FRAMEBUFFER_COMPLETE_OES);
  203983. }
  203984. void freeGLBuffers()
  203985. {
  203986. if (frameBufferHandle != 0)
  203987. {
  203988. glDeleteFramebuffersOES (1, &frameBufferHandle);
  203989. frameBufferHandle = 0;
  203990. }
  203991. if (colorBufferHandle != 0)
  203992. {
  203993. glDeleteRenderbuffersOES (1, &colorBufferHandle);
  203994. colorBufferHandle = 0;
  203995. }
  203996. if (depthBufferHandle != 0)
  203997. {
  203998. glDeleteRenderbuffersOES (1, &depthBufferHandle);
  203999. depthBufferHandle = 0;
  204000. }
  204001. }
  204002. juce_UseDebuggingNewOperator
  204003. private:
  204004. Component::SafePointer<Component> component;
  204005. OpenGLPixelFormat pixelFormat;
  204006. JuceGLView* view;
  204007. CAEAGLLayer* glLayer;
  204008. EAGLContext* context;
  204009. bool useDepthBuffer;
  204010. GLuint frameBufferHandle, colorBufferHandle, depthBufferHandle;
  204011. int numFrames;
  204012. int lastWidth, lastHeight;
  204013. GLESContext (const GLESContext&);
  204014. GLESContext& operator= (const GLESContext&);
  204015. };
  204016. OpenGLContext* OpenGLComponent::createContext()
  204017. {
  204018. ScopedAutoReleasePool pool;
  204019. UIViewComponentPeer* peer = dynamic_cast <UIViewComponentPeer*> (getPeer());
  204020. if (peer != 0)
  204021. return new GLESContext (peer, this, preferredPixelFormat,
  204022. dynamic_cast <const GLESContext*> (contextToShareListsWith),
  204023. type == openGLES2 ? kEAGLRenderingAPIOpenGLES2 : kEAGLRenderingAPIOpenGLES1);
  204024. return 0;
  204025. }
  204026. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  204027. OwnedArray <OpenGLPixelFormat>& /*results*/)
  204028. {
  204029. }
  204030. void juce_glViewport (const int w, const int h)
  204031. {
  204032. glViewport (0, 0, w, h);
  204033. }
  204034. #endif
  204035. #endif
  204036. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  204037. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  204038. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204039. // compiled on its own).
  204040. #if JUCE_INCLUDED_FILE
  204041. #if JUCE_MAC
  204042. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  204043. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  204044. {
  204045. NSImage* im = CoreGraphicsImage::createNSImage (image);
  204046. NSCursor* c = [[NSCursor alloc] initWithImage: im
  204047. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  204048. [im release];
  204049. return (void*) c;
  204050. }
  204051. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  204052. {
  204053. MemoryInputStream stream (data, size, false);
  204054. ScopedPointer <Image> im (juce_loadPNGImageFromStream (stream));
  204055. jassert (im != 0);
  204056. if (im == 0)
  204057. return 0;
  204058. return juce_createMouseCursorFromImage (*im,
  204059. (int) (hx * im->getWidth()),
  204060. (int) (hy * im->getHeight()));
  204061. }
  204062. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  204063. {
  204064. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  204065. MemoryBlock mb;
  204066. if (f.getChildFile (filename).loadFileAsData (mb))
  204067. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  204068. return 0;
  204069. }
  204070. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  204071. {
  204072. const ScopedAutoReleasePool pool;
  204073. NSCursor* c = 0;
  204074. switch (type)
  204075. {
  204076. case MouseCursor::NormalCursor:
  204077. c = [NSCursor arrowCursor];
  204078. break;
  204079. case MouseCursor::NoCursor:
  204080. return juce_createMouseCursorFromImage (Image (Image::ARGB, 8, 8, true), 0, 0);
  204081. case MouseCursor::DraggingHandCursor:
  204082. c = [NSCursor openHandCursor];
  204083. break;
  204084. case MouseCursor::CopyingCursor:
  204085. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  204086. case MouseCursor::WaitCursor:
  204087. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  204088. break;
  204089. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  204090. case MouseCursor::IBeamCursor:
  204091. c = [NSCursor IBeamCursor];
  204092. break;
  204093. case MouseCursor::PointingHandCursor:
  204094. c = [NSCursor pointingHandCursor];
  204095. break;
  204096. case MouseCursor::LeftRightResizeCursor:
  204097. c = [NSCursor resizeLeftRightCursor];
  204098. break;
  204099. case MouseCursor::LeftEdgeResizeCursor:
  204100. c = [NSCursor resizeLeftCursor];
  204101. break;
  204102. case MouseCursor::RightEdgeResizeCursor:
  204103. c = [NSCursor resizeRightCursor];
  204104. break;
  204105. case MouseCursor::UpDownResizeCursor:
  204106. case MouseCursor::TopEdgeResizeCursor:
  204107. case MouseCursor::BottomEdgeResizeCursor:
  204108. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  204109. case MouseCursor::TopLeftCornerResizeCursor:
  204110. case MouseCursor::BottomRightCornerResizeCursor:
  204111. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  204112. case MouseCursor::TopRightCornerResizeCursor:
  204113. case MouseCursor::BottomLeftCornerResizeCursor:
  204114. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  204115. case MouseCursor::UpDownLeftRightResizeCursor:
  204116. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  204117. case MouseCursor::CrosshairCursor:
  204118. c = [NSCursor crosshairCursor];
  204119. break;
  204120. }
  204121. [c retain];
  204122. return (void*) c;
  204123. }
  204124. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  204125. {
  204126. NSCursor* c = (NSCursor*) cursorHandle;
  204127. [c release];
  204128. }
  204129. void MouseCursor::showInAllWindows() const throw()
  204130. {
  204131. showInWindow (0);
  204132. }
  204133. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  204134. {
  204135. NSCursor* const c = (NSCursor*) getHandle();
  204136. [c set];
  204137. }
  204138. #else
  204139. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  204140. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  204141. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  204142. void MouseCursor::showInAllWindows() const throw() {}
  204143. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  204144. #endif
  204145. #endif
  204146. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  204147. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204148. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204149. // compiled on its own).
  204150. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  204151. #if JUCE_MAC
  204152. END_JUCE_NAMESPACE
  204153. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  204154. @interface DownloadClickDetector : NSObject
  204155. {
  204156. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  204157. }
  204158. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  204159. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204160. request: (NSURLRequest*) request
  204161. frame: (WebFrame*) frame
  204162. decisionListener: (id<WebPolicyDecisionListener>) listener;
  204163. @end
  204164. @implementation DownloadClickDetector
  204165. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  204166. {
  204167. [super init];
  204168. ownerComponent = ownerComponent_;
  204169. return self;
  204170. }
  204171. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204172. request: (NSURLRequest*) request
  204173. frame: (WebFrame*) frame
  204174. decisionListener: (id <WebPolicyDecisionListener>) listener
  204175. {
  204176. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  204177. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  204178. [listener use];
  204179. else
  204180. [listener ignore];
  204181. }
  204182. @end
  204183. BEGIN_JUCE_NAMESPACE
  204184. class WebBrowserComponentInternal : public NSViewComponent
  204185. {
  204186. public:
  204187. WebBrowserComponentInternal (WebBrowserComponent* owner)
  204188. {
  204189. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  204190. frameName: @""
  204191. groupName: @""];
  204192. setView (webView);
  204193. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  204194. [webView setPolicyDelegate: clickListener];
  204195. }
  204196. ~WebBrowserComponentInternal()
  204197. {
  204198. [webView setPolicyDelegate: nil];
  204199. [clickListener release];
  204200. setView (0);
  204201. }
  204202. void goToURL (const String& url,
  204203. const StringArray* headers,
  204204. const MemoryBlock* postData)
  204205. {
  204206. NSMutableURLRequest* r
  204207. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  204208. cachePolicy: NSURLRequestUseProtocolCachePolicy
  204209. timeoutInterval: 30.0];
  204210. if (postData != 0 && postData->getSize() > 0)
  204211. {
  204212. [r setHTTPMethod: @"POST"];
  204213. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  204214. length: postData->getSize()]];
  204215. }
  204216. if (headers != 0)
  204217. {
  204218. for (int i = 0; i < headers->size(); ++i)
  204219. {
  204220. const String headerName ((*headers)[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  204221. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  204222. [r setValue: juceStringToNS (headerValue)
  204223. forHTTPHeaderField: juceStringToNS (headerName)];
  204224. }
  204225. }
  204226. stop();
  204227. [[webView mainFrame] loadRequest: r];
  204228. }
  204229. void goBack()
  204230. {
  204231. [webView goBack];
  204232. }
  204233. void goForward()
  204234. {
  204235. [webView goForward];
  204236. }
  204237. void stop()
  204238. {
  204239. [webView stopLoading: nil];
  204240. }
  204241. void refresh()
  204242. {
  204243. [webView reload: nil];
  204244. }
  204245. private:
  204246. WebView* webView;
  204247. DownloadClickDetector* clickListener;
  204248. };
  204249. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204250. : browser (0),
  204251. blankPageShown (false),
  204252. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  204253. {
  204254. setOpaque (true);
  204255. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  204256. }
  204257. WebBrowserComponent::~WebBrowserComponent()
  204258. {
  204259. deleteAndZero (browser);
  204260. }
  204261. void WebBrowserComponent::goToURL (const String& url,
  204262. const StringArray* headers,
  204263. const MemoryBlock* postData)
  204264. {
  204265. lastURL = url;
  204266. lastHeaders.clear();
  204267. if (headers != 0)
  204268. lastHeaders = *headers;
  204269. lastPostData.setSize (0);
  204270. if (postData != 0)
  204271. lastPostData = *postData;
  204272. blankPageShown = false;
  204273. browser->goToURL (url, headers, postData);
  204274. }
  204275. void WebBrowserComponent::stop()
  204276. {
  204277. browser->stop();
  204278. }
  204279. void WebBrowserComponent::goBack()
  204280. {
  204281. lastURL = String::empty;
  204282. blankPageShown = false;
  204283. browser->goBack();
  204284. }
  204285. void WebBrowserComponent::goForward()
  204286. {
  204287. lastURL = String::empty;
  204288. browser->goForward();
  204289. }
  204290. void WebBrowserComponent::refresh()
  204291. {
  204292. browser->refresh();
  204293. }
  204294. void WebBrowserComponent::paint (Graphics& g)
  204295. {
  204296. }
  204297. void WebBrowserComponent::checkWindowAssociation()
  204298. {
  204299. if (isShowing())
  204300. {
  204301. if (blankPageShown)
  204302. goBack();
  204303. }
  204304. else
  204305. {
  204306. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  204307. {
  204308. // when the component becomes invisible, some stuff like flash
  204309. // carries on playing audio, so we need to force it onto a blank
  204310. // page to avoid this, (and send it back when it's made visible again).
  204311. blankPageShown = true;
  204312. browser->goToURL ("about:blank", 0, 0);
  204313. }
  204314. }
  204315. }
  204316. void WebBrowserComponent::reloadLastURL()
  204317. {
  204318. if (lastURL.isNotEmpty())
  204319. {
  204320. goToURL (lastURL, &lastHeaders, &lastPostData);
  204321. lastURL = String::empty;
  204322. }
  204323. }
  204324. void WebBrowserComponent::parentHierarchyChanged()
  204325. {
  204326. checkWindowAssociation();
  204327. }
  204328. void WebBrowserComponent::resized()
  204329. {
  204330. browser->setSize (getWidth(), getHeight());
  204331. }
  204332. void WebBrowserComponent::visibilityChanged()
  204333. {
  204334. checkWindowAssociation();
  204335. }
  204336. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204337. {
  204338. return true;
  204339. }
  204340. #else
  204341. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204342. {
  204343. }
  204344. WebBrowserComponent::~WebBrowserComponent()
  204345. {
  204346. }
  204347. void WebBrowserComponent::goToURL (const String& url,
  204348. const StringArray* headers,
  204349. const MemoryBlock* postData)
  204350. {
  204351. }
  204352. void WebBrowserComponent::stop()
  204353. {
  204354. }
  204355. void WebBrowserComponent::goBack()
  204356. {
  204357. }
  204358. void WebBrowserComponent::goForward()
  204359. {
  204360. }
  204361. void WebBrowserComponent::refresh()
  204362. {
  204363. }
  204364. void WebBrowserComponent::paint (Graphics& g)
  204365. {
  204366. }
  204367. void WebBrowserComponent::checkWindowAssociation()
  204368. {
  204369. }
  204370. void WebBrowserComponent::reloadLastURL()
  204371. {
  204372. }
  204373. void WebBrowserComponent::parentHierarchyChanged()
  204374. {
  204375. }
  204376. void WebBrowserComponent::resized()
  204377. {
  204378. }
  204379. void WebBrowserComponent::visibilityChanged()
  204380. {
  204381. }
  204382. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204383. {
  204384. return true;
  204385. }
  204386. #endif
  204387. #endif
  204388. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204389. /*** Start of inlined file: juce_iphone_Audio.cpp ***/
  204390. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204391. // compiled on its own).
  204392. #if JUCE_INCLUDED_FILE
  204393. class IPhoneAudioIODevice : public AudioIODevice
  204394. {
  204395. public:
  204396. IPhoneAudioIODevice (const String& deviceName)
  204397. : AudioIODevice (deviceName, "Audio"),
  204398. audioUnit (0),
  204399. isRunning (false),
  204400. callback (0),
  204401. actualBufferSize (0),
  204402. floatData (1, 2)
  204403. {
  204404. numInputChannels = 2;
  204405. numOutputChannels = 2;
  204406. preferredBufferSize = 0;
  204407. AudioSessionInitialize (0, 0, interruptionListenerStatic, this);
  204408. updateDeviceInfo();
  204409. }
  204410. ~IPhoneAudioIODevice()
  204411. {
  204412. close();
  204413. }
  204414. const StringArray getOutputChannelNames()
  204415. {
  204416. StringArray s;
  204417. s.add ("Left");
  204418. s.add ("Right");
  204419. return s;
  204420. }
  204421. const StringArray getInputChannelNames()
  204422. {
  204423. StringArray s;
  204424. if (audioInputIsAvailable)
  204425. {
  204426. s.add ("Left");
  204427. s.add ("Right");
  204428. }
  204429. return s;
  204430. }
  204431. int getNumSampleRates()
  204432. {
  204433. return 1;
  204434. }
  204435. double getSampleRate (int index)
  204436. {
  204437. return sampleRate;
  204438. }
  204439. int getNumBufferSizesAvailable()
  204440. {
  204441. return 1;
  204442. }
  204443. int getBufferSizeSamples (int index)
  204444. {
  204445. return getDefaultBufferSize();
  204446. }
  204447. int getDefaultBufferSize()
  204448. {
  204449. return 1024;
  204450. }
  204451. const String open (const BigInteger& inputChannels,
  204452. const BigInteger& outputChannels,
  204453. double sampleRate,
  204454. int bufferSize)
  204455. {
  204456. close();
  204457. lastError = String::empty;
  204458. preferredBufferSize = (bufferSize <= 0) ? getDefaultBufferSize() : bufferSize;
  204459. // xxx set up channel mapping
  204460. activeOutputChans = outputChannels;
  204461. activeOutputChans.setRange (2, activeOutputChans.getHighestBit(), false);
  204462. numOutputChannels = activeOutputChans.countNumberOfSetBits();
  204463. monoOutputChannelNumber = activeOutputChans.findNextSetBit (0);
  204464. activeInputChans = inputChannels;
  204465. activeInputChans.setRange (2, activeInputChans.getHighestBit(), false);
  204466. numInputChannels = activeInputChans.countNumberOfSetBits();
  204467. monoInputChannelNumber = activeInputChans.findNextSetBit (0);
  204468. AudioSessionSetActive (true);
  204469. UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord;
  204470. AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (audioCategory), &audioCategory);
  204471. AudioSessionAddPropertyListener (kAudioSessionProperty_AudioRouteChange, propertyChangedStatic, this);
  204472. fixAudioRouteIfSetToReceiver();
  204473. updateDeviceInfo();
  204474. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204475. AudioSessionSetProperty (kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof (bufferDuration), &bufferDuration);
  204476. actualBufferSize = preferredBufferSize;
  204477. prepareFloatBuffers();
  204478. isRunning = true;
  204479. propertyChanged (0, 0, 0); // creates and starts the AU
  204480. lastError = audioUnit != 0 ? "" : "Couldn't open the device";
  204481. return lastError;
  204482. }
  204483. void close()
  204484. {
  204485. if (isRunning)
  204486. {
  204487. isRunning = false;
  204488. AudioSessionSetActive (false);
  204489. if (audioUnit != 0)
  204490. {
  204491. AudioComponentInstanceDispose (audioUnit);
  204492. audioUnit = 0;
  204493. }
  204494. }
  204495. }
  204496. bool isOpen()
  204497. {
  204498. return isRunning;
  204499. }
  204500. int getCurrentBufferSizeSamples()
  204501. {
  204502. return actualBufferSize;
  204503. }
  204504. double getCurrentSampleRate()
  204505. {
  204506. return sampleRate;
  204507. }
  204508. int getCurrentBitDepth()
  204509. {
  204510. return 16;
  204511. }
  204512. const BigInteger getActiveOutputChannels() const
  204513. {
  204514. return activeOutputChans;
  204515. }
  204516. const BigInteger getActiveInputChannels() const
  204517. {
  204518. return activeInputChans;
  204519. }
  204520. int getOutputLatencyInSamples()
  204521. {
  204522. return 0; //xxx
  204523. }
  204524. int getInputLatencyInSamples()
  204525. {
  204526. return 0; //xxx
  204527. }
  204528. void start (AudioIODeviceCallback* callback_)
  204529. {
  204530. if (isRunning && callback != callback_)
  204531. {
  204532. if (callback_ != 0)
  204533. callback_->audioDeviceAboutToStart (this);
  204534. const ScopedLock sl (callbackLock);
  204535. callback = callback_;
  204536. }
  204537. }
  204538. void stop()
  204539. {
  204540. if (isRunning)
  204541. {
  204542. AudioIODeviceCallback* lastCallback;
  204543. {
  204544. const ScopedLock sl (callbackLock);
  204545. lastCallback = callback;
  204546. callback = 0;
  204547. }
  204548. if (lastCallback != 0)
  204549. lastCallback->audioDeviceStopped();
  204550. }
  204551. }
  204552. bool isPlaying()
  204553. {
  204554. return isRunning && callback != 0;
  204555. }
  204556. const String getLastError()
  204557. {
  204558. return lastError;
  204559. }
  204560. private:
  204561. CriticalSection callbackLock;
  204562. Float64 sampleRate;
  204563. int numInputChannels, numOutputChannels;
  204564. int preferredBufferSize;
  204565. int actualBufferSize;
  204566. bool isRunning;
  204567. String lastError;
  204568. AudioStreamBasicDescription format;
  204569. AudioUnit audioUnit;
  204570. UInt32 audioInputIsAvailable;
  204571. AudioIODeviceCallback* callback;
  204572. BigInteger activeOutputChans, activeInputChans;
  204573. AudioSampleBuffer floatData;
  204574. float* inputChannels[3];
  204575. float* outputChannels[3];
  204576. bool monoInputChannelNumber, monoOutputChannelNumber;
  204577. void prepareFloatBuffers()
  204578. {
  204579. floatData.setSize (numInputChannels + numOutputChannels, actualBufferSize);
  204580. zerostruct (inputChannels);
  204581. zerostruct (outputChannels);
  204582. for (int i = 0; i < numInputChannels; ++i)
  204583. inputChannels[i] = floatData.getSampleData (i);
  204584. for (int i = 0; i < numOutputChannels; ++i)
  204585. outputChannels[i] = floatData.getSampleData (i + numInputChannels);
  204586. }
  204587. OSStatus process (AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204588. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204589. {
  204590. OSStatus err = noErr;
  204591. if (audioInputIsAvailable)
  204592. err = AudioUnitRender (audioUnit, ioActionFlags, inTimeStamp, 1, inNumberFrames, ioData);
  204593. const ScopedLock sl (callbackLock);
  204594. if (callback != 0)
  204595. {
  204596. if (audioInputIsAvailable && numInputChannels > 0)
  204597. {
  204598. short* shortData = (short*) ioData->mBuffers[0].mData;
  204599. if (numInputChannels >= 2)
  204600. {
  204601. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204602. {
  204603. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204604. inputChannels[1][i] = *shortData++ * (1.0f / 32768.0f);
  204605. }
  204606. }
  204607. else
  204608. {
  204609. if (monoInputChannelNumber > 0)
  204610. ++shortData;
  204611. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204612. {
  204613. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204614. ++shortData;
  204615. }
  204616. }
  204617. }
  204618. else
  204619. {
  204620. for (int i = numInputChannels; --i >= 0;)
  204621. zeromem (inputChannels[i], sizeof (float) * inNumberFrames);
  204622. }
  204623. callback->audioDeviceIOCallback ((const float**) inputChannels, numInputChannels,
  204624. outputChannels, numOutputChannels,
  204625. (int) inNumberFrames);
  204626. short* shortData = (short*) ioData->mBuffers[0].mData;
  204627. int n = 0;
  204628. if (numOutputChannels >= 2)
  204629. {
  204630. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204631. {
  204632. shortData [n++] = (short) (outputChannels[0][i] * 32767.0f);
  204633. shortData [n++] = (short) (outputChannels[1][i] * 32767.0f);
  204634. }
  204635. }
  204636. else if (numOutputChannels == 1)
  204637. {
  204638. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204639. {
  204640. const short s = (short) (outputChannels[monoOutputChannelNumber][i] * 32767.0f);
  204641. shortData [n++] = s;
  204642. shortData [n++] = s;
  204643. }
  204644. }
  204645. else
  204646. {
  204647. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204648. }
  204649. }
  204650. else
  204651. {
  204652. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204653. }
  204654. return err;
  204655. }
  204656. void updateDeviceInfo()
  204657. {
  204658. UInt32 size = sizeof (sampleRate);
  204659. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareSampleRate, &size, &sampleRate);
  204660. size = sizeof (audioInputIsAvailable);
  204661. AudioSessionGetProperty (kAudioSessionProperty_AudioInputAvailable, &size, &audioInputIsAvailable);
  204662. }
  204663. void propertyChanged (AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204664. {
  204665. if (! isRunning)
  204666. return;
  204667. if (inPropertyValue != 0)
  204668. {
  204669. CFDictionaryRef routeChangeDictionary = (CFDictionaryRef) inPropertyValue;
  204670. CFNumberRef routeChangeReasonRef = (CFNumberRef) CFDictionaryGetValue (routeChangeDictionary,
  204671. CFSTR (kAudioSession_AudioRouteChangeKey_Reason));
  204672. SInt32 routeChangeReason;
  204673. CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);
  204674. if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable)
  204675. fixAudioRouteIfSetToReceiver();
  204676. }
  204677. updateDeviceInfo();
  204678. createAudioUnit();
  204679. AudioSessionSetActive (true);
  204680. if (audioUnit != 0)
  204681. {
  204682. UInt32 formatSize = sizeof (format);
  204683. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, &formatSize);
  204684. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204685. UInt32 bufferDurationSize = sizeof (bufferDuration);
  204686. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareIOBufferDuration, &bufferDurationSize, &bufferDurationSize);
  204687. actualBufferSize = (int) (sampleRate * bufferDuration + 0.5);
  204688. AudioOutputUnitStart (audioUnit);
  204689. }
  204690. }
  204691. void interruptionListener (UInt32 inInterruption)
  204692. {
  204693. if (inInterruption == kAudioSessionEndInterruption)
  204694. {
  204695. isRunning = true;
  204696. AudioSessionSetActive (true);
  204697. AudioOutputUnitStart (audioUnit);
  204698. }
  204699. }
  204700. static OSStatus processStatic (void* inRefCon, AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204701. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204702. {
  204703. return ((IPhoneAudioIODevice*) inRefCon)->process (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  204704. }
  204705. static void propertyChangedStatic (void* inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204706. {
  204707. ((IPhoneAudioIODevice*) inClientData)->propertyChanged (inID, inDataSize, inPropertyValue);
  204708. }
  204709. static void interruptionListenerStatic (void* inClientData, UInt32 inInterruption)
  204710. {
  204711. ((IPhoneAudioIODevice*) inClientData)->interruptionListener (inInterruption);
  204712. }
  204713. void resetFormat (const int numChannels)
  204714. {
  204715. memset (&format, 0, sizeof (format));
  204716. format.mFormatID = kAudioFormatLinearPCM;
  204717. format.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
  204718. format.mBitsPerChannel = 8 * sizeof (short);
  204719. format.mChannelsPerFrame = 2;
  204720. format.mFramesPerPacket = 1;
  204721. format.mBytesPerFrame = format.mBytesPerPacket = 2 * sizeof (short);
  204722. }
  204723. bool createAudioUnit()
  204724. {
  204725. if (audioUnit != 0)
  204726. {
  204727. AudioComponentInstanceDispose (audioUnit);
  204728. audioUnit = 0;
  204729. }
  204730. resetFormat (2);
  204731. AudioComponentDescription desc;
  204732. desc.componentType = kAudioUnitType_Output;
  204733. desc.componentSubType = kAudioUnitSubType_RemoteIO;
  204734. desc.componentManufacturer = kAudioUnitManufacturer_Apple;
  204735. desc.componentFlags = 0;
  204736. desc.componentFlagsMask = 0;
  204737. AudioComponent comp = AudioComponentFindNext (0, &desc);
  204738. AudioComponentInstanceNew (comp, &audioUnit);
  204739. if (audioUnit == 0)
  204740. return false;
  204741. const UInt32 one = 1;
  204742. AudioUnitSetProperty (audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &one, sizeof (one));
  204743. AudioChannelLayout layout;
  204744. layout.mChannelBitmap = 0;
  204745. layout.mNumberChannelDescriptions = 0;
  204746. layout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  204747. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Input, 0, &layout, sizeof (layout));
  204748. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Output, 0, &layout, sizeof (layout));
  204749. AURenderCallbackStruct inputProc;
  204750. inputProc.inputProc = processStatic;
  204751. inputProc.inputProcRefCon = this;
  204752. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &inputProc, sizeof (inputProc));
  204753. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &format, sizeof (format));
  204754. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, sizeof (format));
  204755. AudioUnitInitialize (audioUnit);
  204756. return true;
  204757. }
  204758. // If the routing is set to go through the receiver (i.e. the speaker, but quiet), this re-routes it
  204759. // to make it loud. Needed because by default when using an input + output, the output is kept quiet.
  204760. static void fixAudioRouteIfSetToReceiver()
  204761. {
  204762. CFStringRef audioRoute = 0;
  204763. UInt32 propertySize = sizeof (audioRoute);
  204764. if (AudioSessionGetProperty (kAudioSessionProperty_AudioRoute, &propertySize, &audioRoute) == noErr)
  204765. {
  204766. NSString* route = (NSString*) audioRoute;
  204767. //DBG ("audio route: " + nsStringToJuce (route));
  204768. if ([route hasPrefix: @"Receiver"])
  204769. {
  204770. UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
  204771. AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof (audioRouteOverride), &audioRouteOverride);
  204772. }
  204773. CFRelease (audioRoute);
  204774. }
  204775. }
  204776. IPhoneAudioIODevice (const IPhoneAudioIODevice&);
  204777. IPhoneAudioIODevice& operator= (const IPhoneAudioIODevice&);
  204778. };
  204779. class IPhoneAudioIODeviceType : public AudioIODeviceType
  204780. {
  204781. public:
  204782. IPhoneAudioIODeviceType()
  204783. : AudioIODeviceType ("iPhone Audio")
  204784. {
  204785. }
  204786. ~IPhoneAudioIODeviceType()
  204787. {
  204788. }
  204789. void scanForDevices()
  204790. {
  204791. }
  204792. const StringArray getDeviceNames (const bool wantInputNames) const
  204793. {
  204794. StringArray s;
  204795. s.add ("iPhone Audio");
  204796. return s;
  204797. }
  204798. int getDefaultDeviceIndex (const bool forInput) const
  204799. {
  204800. return 0;
  204801. }
  204802. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  204803. {
  204804. return device != 0 ? 0 : -1;
  204805. }
  204806. bool hasSeparateInputsAndOutputs() const { return false; }
  204807. AudioIODevice* createDevice (const String& outputDeviceName,
  204808. const String& inputDeviceName)
  204809. {
  204810. if (outputDeviceName.isNotEmpty() || inputDeviceName.isNotEmpty())
  204811. {
  204812. return new IPhoneAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  204813. : inputDeviceName);
  204814. }
  204815. return 0;
  204816. }
  204817. juce_UseDebuggingNewOperator
  204818. private:
  204819. IPhoneAudioIODeviceType (const IPhoneAudioIODeviceType&);
  204820. IPhoneAudioIODeviceType& operator= (const IPhoneAudioIODeviceType&);
  204821. };
  204822. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio()
  204823. {
  204824. return new IPhoneAudioIODeviceType();
  204825. }
  204826. #endif
  204827. /*** End of inlined file: juce_iphone_Audio.cpp ***/
  204828. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  204829. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204830. // compiled on its own).
  204831. #if JUCE_INCLUDED_FILE
  204832. #if JUCE_MAC
  204833. #undef log
  204834. #define log(a) Logger::writeToLog(a)
  204835. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  204836. {
  204837. if (err == noErr)
  204838. return true;
  204839. log ("CoreMidi error: " + String (lineNum) + " - " + String::toHexString ((int) err));
  204840. jassertfalse
  204841. return false;
  204842. }
  204843. #undef OK
  204844. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  204845. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  204846. {
  204847. String result;
  204848. CFStringRef str = 0;
  204849. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  204850. if (str != 0)
  204851. {
  204852. result = PlatformUtilities::cfStringToJuceString (str);
  204853. CFRelease (str);
  204854. str = 0;
  204855. }
  204856. MIDIEntityRef entity = 0;
  204857. MIDIEndpointGetEntity (endpoint, &entity);
  204858. if (entity == 0)
  204859. return result; // probably virtual
  204860. if (result.isEmpty())
  204861. {
  204862. // endpoint name has zero length - try the entity
  204863. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  204864. if (str != 0)
  204865. {
  204866. result += PlatformUtilities::cfStringToJuceString (str);
  204867. CFRelease (str);
  204868. str = 0;
  204869. }
  204870. }
  204871. // now consider the device's name
  204872. MIDIDeviceRef device = 0;
  204873. MIDIEntityGetDevice (entity, &device);
  204874. if (device == 0)
  204875. return result;
  204876. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  204877. if (str != 0)
  204878. {
  204879. const String s (PlatformUtilities::cfStringToJuceString (str));
  204880. CFRelease (str);
  204881. // if an external device has only one entity, throw away
  204882. // the endpoint name and just use the device name
  204883. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  204884. {
  204885. result = s;
  204886. }
  204887. else if (! result.startsWithIgnoreCase (s))
  204888. {
  204889. // prepend the device name to the entity name
  204890. result = (s + " " + result).trimEnd();
  204891. }
  204892. }
  204893. return result;
  204894. }
  204895. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  204896. {
  204897. String result;
  204898. // Does the endpoint have connections?
  204899. CFDataRef connections = 0;
  204900. int numConnections = 0;
  204901. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  204902. if (connections != 0)
  204903. {
  204904. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  204905. if (numConnections > 0)
  204906. {
  204907. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  204908. for (int i = 0; i < numConnections; ++i, ++pid)
  204909. {
  204910. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  204911. MIDIObjectRef connObject;
  204912. MIDIObjectType connObjectType;
  204913. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  204914. if (err == noErr)
  204915. {
  204916. String s;
  204917. if (connObjectType == kMIDIObjectType_ExternalSource
  204918. || connObjectType == kMIDIObjectType_ExternalDestination)
  204919. {
  204920. // Connected to an external device's endpoint (10.3 and later).
  204921. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  204922. }
  204923. else
  204924. {
  204925. // Connected to an external device (10.2) (or something else, catch-all)
  204926. CFStringRef str = 0;
  204927. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  204928. if (str != 0)
  204929. {
  204930. s = PlatformUtilities::cfStringToJuceString (str);
  204931. CFRelease (str);
  204932. }
  204933. }
  204934. if (s.isNotEmpty())
  204935. {
  204936. if (result.isNotEmpty())
  204937. result += (", ");
  204938. result += s;
  204939. }
  204940. }
  204941. }
  204942. }
  204943. CFRelease (connections);
  204944. }
  204945. if (result.isNotEmpty())
  204946. return result;
  204947. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  204948. return getEndpointName (endpoint, false);
  204949. }
  204950. const StringArray MidiOutput::getDevices()
  204951. {
  204952. StringArray s;
  204953. const ItemCount num = MIDIGetNumberOfDestinations();
  204954. for (ItemCount i = 0; i < num; ++i)
  204955. {
  204956. MIDIEndpointRef dest = MIDIGetDestination (i);
  204957. if (dest != 0)
  204958. {
  204959. String name (getConnectedEndpointName (dest));
  204960. if (name.isEmpty())
  204961. name = "<error>";
  204962. s.add (name);
  204963. }
  204964. else
  204965. {
  204966. s.add ("<error>");
  204967. }
  204968. }
  204969. return s;
  204970. }
  204971. int MidiOutput::getDefaultDeviceIndex()
  204972. {
  204973. return 0;
  204974. }
  204975. static MIDIClientRef globalMidiClient;
  204976. static bool hasGlobalClientBeenCreated = false;
  204977. static bool makeSureClientExists()
  204978. {
  204979. if (! hasGlobalClientBeenCreated)
  204980. {
  204981. String name ("JUCE");
  204982. if (JUCEApplication::getInstance() != 0)
  204983. name = JUCEApplication::getInstance()->getApplicationName();
  204984. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  204985. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  204986. CFRelease (appName);
  204987. }
  204988. return hasGlobalClientBeenCreated;
  204989. }
  204990. class MidiPortAndEndpoint
  204991. {
  204992. public:
  204993. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  204994. : port (port_), endPoint (endPoint_)
  204995. {
  204996. }
  204997. ~MidiPortAndEndpoint()
  204998. {
  204999. if (port != 0)
  205000. MIDIPortDispose (port);
  205001. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  205002. MIDIEndpointDispose (endPoint);
  205003. }
  205004. MIDIPortRef port;
  205005. MIDIEndpointRef endPoint;
  205006. };
  205007. MidiOutput* MidiOutput::openDevice (int index)
  205008. {
  205009. MidiOutput* mo = 0;
  205010. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  205011. {
  205012. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  205013. CFStringRef pname;
  205014. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205015. {
  205016. log ("CoreMidi - opening out: " + PlatformUtilities::cfStringToJuceString (pname));
  205017. if (makeSureClientExists())
  205018. {
  205019. MIDIPortRef port;
  205020. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  205021. {
  205022. mo = new MidiOutput();
  205023. mo->internal = (void*) new MidiPortAndEndpoint (port, endPoint);
  205024. }
  205025. }
  205026. CFRelease (pname);
  205027. }
  205028. }
  205029. return mo;
  205030. }
  205031. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  205032. {
  205033. MidiOutput* mo = 0;
  205034. if (makeSureClientExists())
  205035. {
  205036. MIDIEndpointRef endPoint;
  205037. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  205038. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  205039. {
  205040. mo = new MidiOutput();
  205041. mo->internal = (void*) new MidiPortAndEndpoint (0, endPoint);
  205042. }
  205043. CFRelease (name);
  205044. }
  205045. return mo;
  205046. }
  205047. MidiOutput::~MidiOutput()
  205048. {
  205049. delete (MidiPortAndEndpoint*) internal;
  205050. }
  205051. void MidiOutput::reset()
  205052. {
  205053. }
  205054. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205055. {
  205056. return false;
  205057. }
  205058. void MidiOutput::setVolume (float leftVol, float rightVol)
  205059. {
  205060. }
  205061. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205062. {
  205063. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  205064. if (message.isSysEx())
  205065. {
  205066. const int maxPacketSize = 256;
  205067. int pos = 0, bytesLeft = message.getRawDataSize();
  205068. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  205069. HeapBlock <MIDIPacketList> packets;
  205070. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  205071. packets->numPackets = numPackets;
  205072. MIDIPacket* p = packets->packet;
  205073. for (int i = 0; i < numPackets; ++i)
  205074. {
  205075. p->timeStamp = 0;
  205076. p->length = jmin (maxPacketSize, bytesLeft);
  205077. memcpy (p->data, message.getRawData() + pos, p->length);
  205078. pos += p->length;
  205079. bytesLeft -= p->length;
  205080. p = MIDIPacketNext (p);
  205081. }
  205082. if (mpe->port != 0)
  205083. MIDISend (mpe->port, mpe->endPoint, packets);
  205084. else
  205085. MIDIReceived (mpe->endPoint, packets);
  205086. }
  205087. else
  205088. {
  205089. MIDIPacketList packets;
  205090. packets.numPackets = 1;
  205091. packets.packet[0].timeStamp = 0;
  205092. packets.packet[0].length = message.getRawDataSize();
  205093. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  205094. if (mpe->port != 0)
  205095. MIDISend (mpe->port, mpe->endPoint, &packets);
  205096. else
  205097. MIDIReceived (mpe->endPoint, &packets);
  205098. }
  205099. }
  205100. const StringArray MidiInput::getDevices()
  205101. {
  205102. StringArray s;
  205103. const ItemCount num = MIDIGetNumberOfSources();
  205104. for (ItemCount i = 0; i < num; ++i)
  205105. {
  205106. MIDIEndpointRef source = MIDIGetSource (i);
  205107. if (source != 0)
  205108. {
  205109. String name (getConnectedEndpointName (source));
  205110. if (name.isEmpty())
  205111. name = "<error>";
  205112. s.add (name);
  205113. }
  205114. else
  205115. {
  205116. s.add ("<error>");
  205117. }
  205118. }
  205119. return s;
  205120. }
  205121. int MidiInput::getDefaultDeviceIndex()
  205122. {
  205123. return 0;
  205124. }
  205125. struct MidiPortAndCallback
  205126. {
  205127. MidiInput* input;
  205128. MidiPortAndEndpoint* portAndEndpoint;
  205129. MidiInputCallback* callback;
  205130. MemoryBlock pendingData;
  205131. int pendingBytes;
  205132. double pendingDataTime;
  205133. bool active;
  205134. void processSysex (const uint8*& d, int& size, const double time)
  205135. {
  205136. if (*d == 0xf0)
  205137. {
  205138. pendingBytes = 0;
  205139. pendingDataTime = time;
  205140. }
  205141. pendingData.ensureSize (pendingBytes + size, false);
  205142. uint8* totalMessage = (uint8*) pendingData.getData();
  205143. uint8* dest = totalMessage + pendingBytes;
  205144. while (size > 0)
  205145. {
  205146. if (pendingBytes > 0 && *d >= 0x80)
  205147. {
  205148. if (*d >= 0xfa || *d == 0xf8)
  205149. {
  205150. callback->handleIncomingMidiMessage (input, MidiMessage (*d, time));
  205151. ++d;
  205152. --size;
  205153. }
  205154. else
  205155. {
  205156. if (*d == 0xf7)
  205157. {
  205158. *dest++ = *d++;
  205159. pendingBytes++;
  205160. --size;
  205161. }
  205162. break;
  205163. }
  205164. }
  205165. else
  205166. {
  205167. *dest++ = *d++;
  205168. pendingBytes++;
  205169. --size;
  205170. }
  205171. }
  205172. if (totalMessage [pendingBytes - 1] == 0xf7)
  205173. {
  205174. callback->handleIncomingMidiMessage (input, MidiMessage (totalMessage, pendingBytes, pendingDataTime));
  205175. pendingBytes = 0;
  205176. }
  205177. else
  205178. {
  205179. callback->handlePartialSysexMessage (input, totalMessage, pendingBytes, pendingDataTime);
  205180. }
  205181. }
  205182. };
  205183. namespace CoreMidiCallbacks
  205184. {
  205185. static CriticalSection callbackLock;
  205186. static VoidArray activeCallbacks;
  205187. }
  205188. static void midiInputProc (const MIDIPacketList* pktlist,
  205189. void* readProcRefCon,
  205190. void* srcConnRefCon)
  205191. {
  205192. double time = Time::getMillisecondCounterHiRes() * 0.001;
  205193. const double originalTime = time;
  205194. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  205195. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205196. if (CoreMidiCallbacks::activeCallbacks.contains (mpc) && mpc->active)
  205197. {
  205198. const MIDIPacket* packet = &pktlist->packet[0];
  205199. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  205200. {
  205201. const uint8* d = (const uint8*) (packet->data);
  205202. int size = packet->length;
  205203. while (size > 0)
  205204. {
  205205. time = originalTime;
  205206. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  205207. {
  205208. mpc->processSysex (d, size, time);
  205209. }
  205210. else
  205211. {
  205212. int used = 0;
  205213. const MidiMessage m (d, size, used, 0, time);
  205214. if (used <= 0)
  205215. {
  205216. jassertfalse // malformed midi message
  205217. break;
  205218. }
  205219. else
  205220. {
  205221. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  205222. }
  205223. size -= used;
  205224. d += used;
  205225. }
  205226. }
  205227. packet = MIDIPacketNext (packet);
  205228. }
  205229. }
  205230. }
  205231. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205232. {
  205233. MidiInput* mi = 0;
  205234. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  205235. {
  205236. MIDIEndpointRef endPoint = MIDIGetSource (index);
  205237. if (endPoint != 0)
  205238. {
  205239. CFStringRef pname;
  205240. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205241. {
  205242. log ("CoreMidi - opening inp: " + PlatformUtilities::cfStringToJuceString (pname));
  205243. if (makeSureClientExists())
  205244. {
  205245. MIDIPortRef port;
  205246. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205247. mpc->active = false;
  205248. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  205249. {
  205250. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  205251. {
  205252. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  205253. mpc->callback = callback;
  205254. mpc->pendingBytes = 0;
  205255. mpc->pendingData.ensureSize (128);
  205256. mi = new MidiInput (getDevices() [index]);
  205257. mpc->input = mi;
  205258. mi->internal = (void*) mpc;
  205259. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205260. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  205261. }
  205262. else
  205263. {
  205264. OK (MIDIPortDispose (port));
  205265. }
  205266. }
  205267. }
  205268. }
  205269. CFRelease (pname);
  205270. }
  205271. }
  205272. return mi;
  205273. }
  205274. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  205275. {
  205276. MidiInput* mi = 0;
  205277. if (makeSureClientExists())
  205278. {
  205279. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205280. mpc->active = false;
  205281. MIDIEndpointRef endPoint;
  205282. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  205283. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  205284. {
  205285. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  205286. mpc->callback = callback;
  205287. mpc->pendingBytes = 0;
  205288. mpc->pendingData.ensureSize (128);
  205289. mi = new MidiInput (deviceName);
  205290. mpc->input = mi;
  205291. mi->internal = (void*) mpc;
  205292. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205293. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  205294. }
  205295. CFRelease (name);
  205296. }
  205297. return mi;
  205298. }
  205299. MidiInput::MidiInput (const String& name_)
  205300. : name (name_)
  205301. {
  205302. }
  205303. MidiInput::~MidiInput()
  205304. {
  205305. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205306. mpc->active = false;
  205307. {
  205308. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205309. CoreMidiCallbacks::activeCallbacks.removeValue (mpc);
  205310. }
  205311. if (mpc->portAndEndpoint->port != 0)
  205312. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  205313. delete mpc->portAndEndpoint;
  205314. delete mpc;
  205315. }
  205316. void MidiInput::start()
  205317. {
  205318. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205319. ((MidiPortAndCallback*) internal)->active = true;
  205320. }
  205321. void MidiInput::stop()
  205322. {
  205323. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205324. ((MidiPortAndCallback*) internal)->active = false;
  205325. }
  205326. #undef log
  205327. #else
  205328. MidiOutput::~MidiOutput()
  205329. {
  205330. }
  205331. void MidiOutput::reset()
  205332. {
  205333. }
  205334. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205335. {
  205336. return false;
  205337. }
  205338. void MidiOutput::setVolume (float leftVol, float rightVol)
  205339. {
  205340. }
  205341. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205342. {
  205343. }
  205344. const StringArray MidiOutput::getDevices()
  205345. {
  205346. return StringArray();
  205347. }
  205348. MidiOutput* MidiOutput::openDevice (int index)
  205349. {
  205350. return 0;
  205351. }
  205352. const StringArray MidiInput::getDevices()
  205353. {
  205354. return StringArray();
  205355. }
  205356. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205357. {
  205358. return 0;
  205359. }
  205360. #endif
  205361. #endif
  205362. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  205363. #else
  205364. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  205365. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205366. // compiled on its own).
  205367. #if JUCE_INCLUDED_FILE
  205368. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  205369. #define SUPPORT_10_4_FONTS 1
  205370. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  205371. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  205372. #define SUPPORT_ONLY_10_4_FONTS 1
  205373. #endif
  205374. END_JUCE_NAMESPACE
  205375. @interface NSFont (PrivateHack)
  205376. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  205377. @end
  205378. BEGIN_JUCE_NAMESPACE
  205379. #endif
  205380. class MacTypeface : public Typeface
  205381. {
  205382. public:
  205383. MacTypeface (const Font& font)
  205384. : Typeface (font.getTypefaceName())
  205385. {
  205386. const ScopedAutoReleasePool pool;
  205387. renderingTransform = CGAffineTransformIdentity;
  205388. bool needsItalicTransform = false;
  205389. #if JUCE_IPHONE
  205390. NSString* fontName = juceStringToNS (font.getTypefaceName());
  205391. if (font.isItalic() || font.isBold())
  205392. {
  205393. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  205394. for (NSString* i in familyFonts)
  205395. {
  205396. const String fn (nsStringToJuce (i));
  205397. const String afterDash (fn.fromFirstOccurrenceOf (T("-"), false, false));
  205398. const bool probablyBold = afterDash.containsIgnoreCase (T("bold")) || fn.endsWithIgnoreCase (T("bold"));
  205399. const bool probablyItalic = afterDash.containsIgnoreCase (T("oblique"))
  205400. || afterDash.containsIgnoreCase (T("italic"))
  205401. || fn.endsWithIgnoreCase (T("oblique"))
  205402. || fn.endsWithIgnoreCase (T("italic"));
  205403. if (probablyBold == font.isBold()
  205404. && probablyItalic == font.isItalic())
  205405. {
  205406. fontName = i;
  205407. needsItalicTransform = false;
  205408. break;
  205409. }
  205410. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  205411. {
  205412. fontName = i;
  205413. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  205414. }
  205415. }
  205416. if (needsItalicTransform)
  205417. renderingTransform.c = 0.15f;
  205418. }
  205419. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  205420. const int ascender = abs (CGFontGetAscent (fontRef));
  205421. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  205422. ascent = ascender / totalHeight;
  205423. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205424. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  205425. #else
  205426. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  205427. if (font.isItalic())
  205428. {
  205429. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  205430. toHaveTrait: NSItalicFontMask];
  205431. if (newFont == nsFont)
  205432. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  205433. nsFont = newFont;
  205434. }
  205435. if (font.isBold())
  205436. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  205437. [nsFont retain];
  205438. ascent = fabsf ((float) [nsFont ascender]);
  205439. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  205440. ascent /= totalSize;
  205441. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  205442. if (needsItalicTransform)
  205443. {
  205444. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  205445. renderingTransform.c = 0.15f;
  205446. }
  205447. #if SUPPORT_ONLY_10_4_FONTS
  205448. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205449. if (atsFont == 0)
  205450. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205451. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205452. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205453. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205454. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205455. #else
  205456. #if SUPPORT_10_4_FONTS
  205457. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205458. {
  205459. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205460. if (atsFont == 0)
  205461. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205462. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205463. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205464. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205465. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205466. }
  205467. else
  205468. #endif
  205469. {
  205470. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  205471. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  205472. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205473. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  205474. }
  205475. #endif
  205476. #endif
  205477. }
  205478. ~MacTypeface()
  205479. {
  205480. #if ! JUCE_IPHONE
  205481. [nsFont release];
  205482. #endif
  205483. if (fontRef != 0)
  205484. CGFontRelease (fontRef);
  205485. }
  205486. float getAscent() const
  205487. {
  205488. return ascent;
  205489. }
  205490. float getDescent() const
  205491. {
  205492. return 1.0f - ascent;
  205493. }
  205494. float getStringWidth (const String& text)
  205495. {
  205496. if (fontRef == 0 || text.isEmpty())
  205497. return 0;
  205498. const int length = text.length();
  205499. HeapBlock <CGGlyph> glyphs;
  205500. createGlyphsForString (text, length, glyphs);
  205501. float x = 0;
  205502. #if SUPPORT_ONLY_10_4_FONTS
  205503. HeapBlock <NSSize> advances (length);
  205504. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  205505. for (int i = 0; i < length; ++i)
  205506. x += advances[i].width;
  205507. #else
  205508. #if SUPPORT_10_4_FONTS
  205509. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205510. {
  205511. HeapBlock <NSSize> advances (length);
  205512. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast<NSGlyph*> (glyphs.getData()) count: length];
  205513. for (int i = 0; i < length; ++i)
  205514. x += advances[i].width;
  205515. }
  205516. else
  205517. #endif
  205518. {
  205519. HeapBlock <int> advances (length);
  205520. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205521. for (int i = 0; i < length; ++i)
  205522. x += advances[i];
  205523. }
  205524. #endif
  205525. return x * unitsToHeightScaleFactor;
  205526. }
  205527. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  205528. {
  205529. xOffsets.add (0);
  205530. if (fontRef == 0 || text.isEmpty())
  205531. return;
  205532. const int length = text.length();
  205533. HeapBlock <CGGlyph> glyphs;
  205534. createGlyphsForString (text, length, glyphs);
  205535. #if SUPPORT_ONLY_10_4_FONTS
  205536. HeapBlock <NSSize> advances (length);
  205537. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  205538. int x = 0;
  205539. for (int i = 0; i < length; ++i)
  205540. {
  205541. x += advances[i].width;
  205542. xOffsets.add (x * unitsToHeightScaleFactor);
  205543. resultGlyphs.add (reinterpret_cast <NSGlyph*> (glyphs.getData())[i]);
  205544. }
  205545. #else
  205546. #if SUPPORT_10_4_FONTS
  205547. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205548. {
  205549. HeapBlock <NSSize> advances (length);
  205550. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  205551. [nsFont getAdvancements: advances forGlyphs: nsGlyphs count: length];
  205552. float x = 0;
  205553. for (int i = 0; i < length; ++i)
  205554. {
  205555. x += advances[i].width;
  205556. xOffsets.add (x * unitsToHeightScaleFactor);
  205557. resultGlyphs.add (nsGlyphs[i]);
  205558. }
  205559. }
  205560. else
  205561. #endif
  205562. {
  205563. HeapBlock <int> advances (length);
  205564. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205565. {
  205566. int x = 0;
  205567. for (int i = 0; i < length; ++i)
  205568. {
  205569. x += advances [i];
  205570. xOffsets.add (x * unitsToHeightScaleFactor);
  205571. resultGlyphs.add (glyphs[i]);
  205572. }
  205573. }
  205574. }
  205575. #endif
  205576. }
  205577. bool getOutlineForGlyph (int glyphNumber, Path& path)
  205578. {
  205579. #if JUCE_IPHONE
  205580. return false;
  205581. #else
  205582. if (nsFont == 0)
  205583. return false;
  205584. // we might need to apply a transform to the path, so it mustn't have anything else in it
  205585. jassert (path.isEmpty());
  205586. const ScopedAutoReleasePool pool;
  205587. NSBezierPath* bez = [NSBezierPath bezierPath];
  205588. [bez moveToPoint: NSMakePoint (0, 0)];
  205589. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  205590. inFont: nsFont];
  205591. for (int i = 0; i < [bez elementCount]; ++i)
  205592. {
  205593. NSPoint p[3];
  205594. switch ([bez elementAtIndex: i associatedPoints: p])
  205595. {
  205596. case NSMoveToBezierPathElement:
  205597. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  205598. break;
  205599. case NSLineToBezierPathElement:
  205600. path.lineTo ((float) p[0].x, (float) -p[0].y);
  205601. break;
  205602. case NSCurveToBezierPathElement:
  205603. 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);
  205604. break;
  205605. case NSClosePathBezierPathElement:
  205606. path.closeSubPath();
  205607. break;
  205608. default:
  205609. jassertfalse
  205610. break;
  205611. }
  205612. }
  205613. path.applyTransform (pathTransform);
  205614. return true;
  205615. #endif
  205616. }
  205617. juce_UseDebuggingNewOperator
  205618. CGFontRef fontRef;
  205619. float fontHeightToCGSizeFactor;
  205620. CGAffineTransform renderingTransform;
  205621. private:
  205622. float ascent, unitsToHeightScaleFactor;
  205623. #if JUCE_IPHONE
  205624. #else
  205625. NSFont* nsFont;
  205626. AffineTransform pathTransform;
  205627. #endif
  205628. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  205629. {
  205630. #if SUPPORT_10_4_FONTS
  205631. #if ! SUPPORT_ONLY_10_4_FONTS
  205632. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205633. #endif
  205634. {
  205635. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  205636. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  205637. for (int i = 0; i < length; ++i)
  205638. nsGlyphs[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  205639. return;
  205640. }
  205641. #endif
  205642. #if ! SUPPORT_ONLY_10_4_FONTS
  205643. if (charToGlyphMapper == 0)
  205644. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  205645. glyphs.malloc (length);
  205646. for (int i = 0; i < length; ++i)
  205647. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  205648. #endif
  205649. }
  205650. #if ! SUPPORT_ONLY_10_4_FONTS
  205651. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  205652. class CharToGlyphMapper
  205653. {
  205654. public:
  205655. CharToGlyphMapper (CGFontRef fontRef)
  205656. : segCount (0), endCode (0), startCode (0), idDelta (0),
  205657. idRangeOffset (0), glyphIndexes (0)
  205658. {
  205659. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  205660. if (cmapTable != 0)
  205661. {
  205662. const int numSubtables = getValue16 (cmapTable, 2);
  205663. for (int i = 0; i < numSubtables; ++i)
  205664. {
  205665. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  205666. {
  205667. const int offset = getValue32 (cmapTable, i * 8 + 8);
  205668. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  205669. {
  205670. const int length = getValue16 (cmapTable, offset + 2);
  205671. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  205672. segCount = segCountX2 / 2;
  205673. const int endCodeOffset = offset + 14;
  205674. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  205675. const int idDeltaOffset = startCodeOffset + segCountX2;
  205676. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  205677. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  205678. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  205679. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  205680. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  205681. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  205682. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  205683. }
  205684. break;
  205685. }
  205686. }
  205687. CFRelease (cmapTable);
  205688. }
  205689. }
  205690. ~CharToGlyphMapper()
  205691. {
  205692. if (endCode != 0)
  205693. {
  205694. CFRelease (endCode);
  205695. CFRelease (startCode);
  205696. CFRelease (idDelta);
  205697. CFRelease (idRangeOffset);
  205698. CFRelease (glyphIndexes);
  205699. }
  205700. }
  205701. int getGlyphForCharacter (const juce_wchar c) const
  205702. {
  205703. for (int i = 0; i < segCount; ++i)
  205704. {
  205705. if (getValue16 (endCode, i * 2) >= c)
  205706. {
  205707. const int start = getValue16 (startCode, i * 2);
  205708. if (start > c)
  205709. break;
  205710. const int delta = getValue16 (idDelta, i * 2);
  205711. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  205712. if (rangeOffset == 0)
  205713. return delta + c;
  205714. else
  205715. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  205716. }
  205717. }
  205718. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  205719. return jmax (-1, c - 29);
  205720. }
  205721. private:
  205722. int segCount;
  205723. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  205724. static uint16 getValue16 (CFDataRef data, const int index)
  205725. {
  205726. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  205727. }
  205728. static uint32 getValue32 (CFDataRef data, const int index)
  205729. {
  205730. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  205731. }
  205732. };
  205733. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  205734. #endif
  205735. MacTypeface (const MacTypeface&);
  205736. MacTypeface& operator= (const MacTypeface&);
  205737. };
  205738. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  205739. {
  205740. return new MacTypeface (font);
  205741. }
  205742. const StringArray Font::findAllTypefaceNames()
  205743. {
  205744. StringArray names;
  205745. const ScopedAutoReleasePool pool;
  205746. #if JUCE_IPHONE
  205747. NSArray* fonts = [UIFont familyNames];
  205748. #else
  205749. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  205750. #endif
  205751. for (unsigned int i = 0; i < [fonts count]; ++i)
  205752. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  205753. names.sort (true);
  205754. return names;
  205755. }
  205756. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed)
  205757. {
  205758. #if JUCE_IPHONE
  205759. defaultSans = "Helvetica";
  205760. defaultSerif = "Times New Roman";
  205761. defaultFixed = "Courier New";
  205762. #else
  205763. defaultSans = "Lucida Grande";
  205764. defaultSerif = "Times New Roman";
  205765. defaultFixed = "Monaco";
  205766. #endif
  205767. }
  205768. #endif
  205769. /*** End of inlined file: juce_mac_Fonts.mm ***/
  205770. // (must go before juce_mac_CoreGraphicsContext.mm)
  205771. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  205772. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205773. // compiled on its own).
  205774. #if JUCE_INCLUDED_FILE
  205775. class CoreGraphicsImage : public Image
  205776. {
  205777. public:
  205778. CoreGraphicsImage (const PixelFormat format_,
  205779. const int imageWidth_,
  205780. const int imageHeight_,
  205781. const bool clearImage)
  205782. : Image (format_, imageWidth_, imageHeight_, clearImage)
  205783. {
  205784. CGColorSpaceRef colourSpace = (format == Image::SingleChannel) ? CGColorSpaceCreateDeviceGray()
  205785. : CGColorSpaceCreateDeviceRGB();
  205786. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  205787. colourSpace, getCGImageFlags (*this));
  205788. CGColorSpaceRelease (colourSpace);
  205789. }
  205790. ~CoreGraphicsImage()
  205791. {
  205792. CGContextRelease (context);
  205793. }
  205794. LowLevelGraphicsContext* createLowLevelContext();
  205795. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  205796. {
  205797. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  205798. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  205799. {
  205800. return CGBitmapContextCreateImage (nativeImage->context);
  205801. }
  205802. else
  205803. {
  205804. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  205805. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  205806. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  205807. 8, srcData.pixelStride * 8, srcData.lineStride,
  205808. colourSpace, getCGImageFlags (juceImage), provider,
  205809. 0, true, kCGRenderingIntentDefault);
  205810. CGDataProviderRelease (provider);
  205811. return imageRef;
  205812. }
  205813. }
  205814. #if JUCE_MAC
  205815. static NSImage* createNSImage (const Image& image)
  205816. {
  205817. const ScopedAutoReleasePool pool;
  205818. NSImage* im = [[NSImage alloc] init];
  205819. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  205820. [im lockFocus];
  205821. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  205822. CGImageRef imageRef = createImage (image, false, colourSpace);
  205823. CGColorSpaceRelease (colourSpace);
  205824. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  205825. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  205826. CGImageRelease (imageRef);
  205827. [im unlockFocus];
  205828. return im;
  205829. }
  205830. #endif
  205831. CGContextRef context;
  205832. private:
  205833. static CGBitmapInfo getCGImageFlags (const Image& image)
  205834. {
  205835. #if JUCE_BIG_ENDIAN
  205836. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  205837. #else
  205838. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  205839. #endif
  205840. }
  205841. };
  205842. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  205843. {
  205844. #if USE_COREGRAPHICS_RENDERING
  205845. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  205846. #else
  205847. return new Image (format, imageWidth, imageHeight, clearImage);
  205848. #endif
  205849. }
  205850. class CoreGraphicsContext : public LowLevelGraphicsContext
  205851. {
  205852. public:
  205853. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  205854. : context (context_),
  205855. flipHeight (flipHeight_),
  205856. state (new SavedState()),
  205857. numGradientLookupEntries (0)
  205858. {
  205859. CGContextRetain (context);
  205860. CGContextSaveGState(context);
  205861. CGContextSetShouldSmoothFonts (context, true);
  205862. CGContextSetShouldAntialias (context, true);
  205863. CGContextSetBlendMode (context, kCGBlendModeNormal);
  205864. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  205865. greyColourSpace = CGColorSpaceCreateDeviceGray();
  205866. gradientCallbacks.version = 0;
  205867. gradientCallbacks.evaluate = gradientCallback;
  205868. gradientCallbacks.releaseInfo = 0;
  205869. setFont (Font());
  205870. }
  205871. ~CoreGraphicsContext()
  205872. {
  205873. CGContextRestoreGState (context);
  205874. CGContextRelease (context);
  205875. CGColorSpaceRelease (rgbColourSpace);
  205876. CGColorSpaceRelease (greyColourSpace);
  205877. }
  205878. bool isVectorDevice() const { return false; }
  205879. void setOrigin (int x, int y)
  205880. {
  205881. CGContextTranslateCTM (context, x, -y);
  205882. }
  205883. bool clipToRectangle (const Rectangle<int>& r)
  205884. {
  205885. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  205886. return ! isClipEmpty();
  205887. }
  205888. bool clipToRectangleList (const RectangleList& clipRegion)
  205889. {
  205890. if (clipRegion.isEmpty())
  205891. {
  205892. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  205893. return false;
  205894. }
  205895. else
  205896. {
  205897. const int numRects = clipRegion.getNumRectangles();
  205898. HeapBlock <CGRect> rects (numRects);
  205899. for (int i = 0; i < numRects; ++i)
  205900. {
  205901. const Rectangle<int>& r = clipRegion.getRectangle(i);
  205902. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  205903. }
  205904. CGContextClipToRects (context, rects, numRects);
  205905. return ! isClipEmpty();
  205906. }
  205907. }
  205908. void excludeClipRectangle (const Rectangle<int>& r)
  205909. {
  205910. RectangleList remaining (getClipBounds());
  205911. remaining.subtract (r);
  205912. clipToRectangleList (remaining);
  205913. }
  205914. void clipToPath (const Path& path, const AffineTransform& transform)
  205915. {
  205916. createPath (path, transform);
  205917. CGContextClip (context);
  205918. }
  205919. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  205920. {
  205921. if (! transform.isSingularity())
  205922. {
  205923. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  205924. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  205925. flip();
  205926. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  205927. applyTransform (t);
  205928. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  205929. CGContextClipToMask (context, r, image);
  205930. applyTransform (t.inverted());
  205931. flip();
  205932. CGImageRelease (image);
  205933. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  205934. }
  205935. }
  205936. bool clipRegionIntersects (const Rectangle<int>& r)
  205937. {
  205938. return getClipBounds().intersects (r);
  205939. }
  205940. const Rectangle<int> getClipBounds() const
  205941. {
  205942. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  205943. return Rectangle<int> (roundToInt (bounds.origin.x),
  205944. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  205945. roundToInt (bounds.size.width),
  205946. roundToInt (bounds.size.height));
  205947. }
  205948. bool isClipEmpty() const
  205949. {
  205950. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  205951. }
  205952. void saveState()
  205953. {
  205954. CGContextSaveGState (context);
  205955. stateStack.add (new SavedState (*state));
  205956. }
  205957. void restoreState()
  205958. {
  205959. CGContextRestoreGState (context);
  205960. SavedState* const top = stateStack.getLast();
  205961. if (top != 0)
  205962. {
  205963. state = top;
  205964. stateStack.removeLast (1, false);
  205965. }
  205966. else
  205967. {
  205968. jassertfalse // trying to pop with an empty stack!
  205969. }
  205970. }
  205971. void setFill (const FillType& fillType)
  205972. {
  205973. state->fillType = fillType;
  205974. if (fillType.isColour())
  205975. {
  205976. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  205977. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  205978. CGContextSetAlpha (context, 1.0f);
  205979. }
  205980. }
  205981. void setOpacity (float newOpacity)
  205982. {
  205983. state->fillType.setOpacity (newOpacity);
  205984. setFill (state->fillType);
  205985. }
  205986. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  205987. {
  205988. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  205989. ? kCGInterpolationLow
  205990. : kCGInterpolationHigh);
  205991. }
  205992. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  205993. {
  205994. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  205995. if (replaceExistingContents)
  205996. {
  205997. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  205998. CGContextClearRect (context, cgRect);
  205999. #else
  206000. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206001. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  206002. CGContextClearRect (context, cgRect);
  206003. else
  206004. #endif
  206005. CGContextSetBlendMode (context, kCGBlendModeCopy);
  206006. #endif
  206007. fillRect (r, false);
  206008. CGContextSetBlendMode (context, kCGBlendModeNormal);
  206009. }
  206010. else
  206011. {
  206012. if (state->fillType.isColour())
  206013. {
  206014. CGContextFillRect (context, cgRect);
  206015. }
  206016. else if (state->fillType.isGradient())
  206017. {
  206018. CGContextSaveGState (context);
  206019. CGContextClipToRect (context, cgRect);
  206020. drawGradient();
  206021. CGContextRestoreGState (context);
  206022. }
  206023. else
  206024. {
  206025. CGContextSaveGState (context);
  206026. CGContextClipToRect (context, cgRect);
  206027. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206028. CGContextRestoreGState (context);
  206029. }
  206030. }
  206031. }
  206032. void fillPath (const Path& path, const AffineTransform& transform)
  206033. {
  206034. CGContextSaveGState (context);
  206035. if (state->fillType.isColour())
  206036. {
  206037. flip();
  206038. applyTransform (transform);
  206039. createPath (path);
  206040. if (path.isUsingNonZeroWinding())
  206041. CGContextFillPath (context);
  206042. else
  206043. CGContextEOFillPath (context);
  206044. }
  206045. else
  206046. {
  206047. createPath (path, transform);
  206048. if (path.isUsingNonZeroWinding())
  206049. CGContextClip (context);
  206050. else
  206051. CGContextEOClip (context);
  206052. if (state->fillType.isGradient())
  206053. drawGradient();
  206054. else
  206055. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206056. }
  206057. CGContextRestoreGState (context);
  206058. }
  206059. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  206060. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  206061. {
  206062. jassert (sourceImage.getBounds().contains (srcClip));
  206063. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  206064. CGImageRef image = fullImage;
  206065. if (srcClip != sourceImage.getBounds())
  206066. {
  206067. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  206068. srcClip.getWidth(), srcClip.getHeight()));
  206069. CGImageRelease (fullImage);
  206070. }
  206071. CGContextSaveGState (context);
  206072. CGContextSetAlpha (context, state->fillType.getOpacity());
  206073. flip();
  206074. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  206075. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  206076. if (fillEntireClipAsTiles)
  206077. {
  206078. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  206079. CGContextDrawTiledImage (context, imageRect, image);
  206080. #else
  206081. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  206082. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  206083. // if it's doing a transformation - it's quicker to just draw lots of images manually
  206084. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  206085. CGContextDrawTiledImage (context, imageRect, image);
  206086. else
  206087. #endif
  206088. {
  206089. // Fallback to manually doing a tiled fill on 10.4
  206090. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  206091. const int iw = srcClip.getWidth();
  206092. const int ih = srcClip.getHeight();
  206093. int x = 0, y = 0;
  206094. while (x > clip.origin.x) x -= iw;
  206095. while (y > clip.origin.y) y -= ih;
  206096. const int right = (int) (clip.origin.x + clip.size.width);
  206097. const int bottom = (int) (clip.origin.y + clip.size.height);
  206098. while (y < bottom)
  206099. {
  206100. for (int x2 = x; x2 < right; x2 += iw)
  206101. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  206102. y += ih;
  206103. }
  206104. }
  206105. #endif
  206106. }
  206107. else
  206108. {
  206109. CGContextDrawImage (context, imageRect, image);
  206110. }
  206111. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  206112. CGContextRestoreGState (context);
  206113. }
  206114. void drawLine (double x1, double y1, double x2, double y2)
  206115. {
  206116. CGContextSetLineCap (context, kCGLineCapSquare);
  206117. CGContextSetLineWidth (context, 1.0f);
  206118. CGContextSetRGBStrokeColor (context,
  206119. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  206120. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  206121. CGPoint line[] = { { (CGFloat) x1, flipHeight - (CGFloat) y1 },
  206122. { (CGFloat) x2, flipHeight - (CGFloat) y2 } };
  206123. CGContextStrokeLineSegments (context, line, 1);
  206124. }
  206125. void drawVerticalLine (const int x, double top, double bottom)
  206126. {
  206127. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206128. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  206129. #else
  206130. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206131. // the x co-ord slightly to trick it..
  206132. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  206133. #endif
  206134. }
  206135. void drawHorizontalLine (const int y, double left, double right)
  206136. {
  206137. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206138. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  206139. #else
  206140. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206141. // the x co-ord slightly to trick it..
  206142. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  206143. #endif
  206144. }
  206145. void setFont (const Font& newFont)
  206146. {
  206147. if (state->font != newFont)
  206148. {
  206149. state->fontRef = 0;
  206150. state->font = newFont;
  206151. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  206152. if (mf != 0)
  206153. {
  206154. state->fontRef = mf->fontRef;
  206155. CGContextSetFont (context, state->fontRef);
  206156. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  206157. state->fontTransform = mf->renderingTransform;
  206158. state->fontTransform.a *= state->font.getHorizontalScale();
  206159. CGContextSetTextMatrix (context, state->fontTransform);
  206160. }
  206161. }
  206162. }
  206163. const Font getFont()
  206164. {
  206165. return state->font;
  206166. }
  206167. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  206168. {
  206169. if (state->fontRef != 0 && state->fillType.isColour())
  206170. {
  206171. if (transform.isOnlyTranslation())
  206172. {
  206173. CGGlyph g = glyphNumber;
  206174. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  206175. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  206176. }
  206177. else
  206178. {
  206179. CGContextSaveGState (context);
  206180. flip();
  206181. applyTransform (transform);
  206182. CGAffineTransform t = state->fontTransform;
  206183. t.d = -t.d;
  206184. CGContextSetTextMatrix (context, t);
  206185. CGGlyph g = glyphNumber;
  206186. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  206187. CGContextSetTextMatrix (context, state->fontTransform);
  206188. CGContextRestoreGState (context);
  206189. }
  206190. }
  206191. else
  206192. {
  206193. Path p;
  206194. Font& f = state->font;
  206195. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  206196. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  206197. .followedBy (transform));
  206198. }
  206199. }
  206200. private:
  206201. CGContextRef context;
  206202. const CGFloat flipHeight;
  206203. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  206204. CGFunctionCallbacks gradientCallbacks;
  206205. struct SavedState
  206206. {
  206207. SavedState()
  206208. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  206209. {
  206210. }
  206211. SavedState (const SavedState& other)
  206212. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  206213. fontTransform (other.fontTransform)
  206214. {
  206215. }
  206216. ~SavedState()
  206217. {
  206218. }
  206219. FillType fillType;
  206220. Font font;
  206221. CGFontRef fontRef;
  206222. CGAffineTransform fontTransform;
  206223. };
  206224. ScopedPointer <SavedState> state;
  206225. OwnedArray <SavedState> stateStack;
  206226. HeapBlock <PixelARGB> gradientLookupTable;
  206227. int numGradientLookupEntries;
  206228. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  206229. {
  206230. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  206231. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  206232. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  206233. colour.unpremultiply();
  206234. outData[0] = colour.getRed() / 255.0f;
  206235. outData[1] = colour.getGreen() / 255.0f;
  206236. outData[2] = colour.getBlue() / 255.0f;
  206237. outData[3] = colour.getAlpha() / 255.0f;
  206238. }
  206239. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  206240. {
  206241. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  206242. --numGradientLookupEntries;
  206243. CGShadingRef result = 0;
  206244. CGFunctionRef function = CGFunctionCreate ((void*) this, 1, 0, 4, 0, &gradientCallbacks);
  206245. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  206246. if (gradient.isRadial)
  206247. {
  206248. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  206249. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  206250. function, true, true);
  206251. }
  206252. else
  206253. {
  206254. result = CGShadingCreateAxial (rgbColourSpace, p1,
  206255. CGPointMake (gradient.x2, gradient.y2),
  206256. function, true, true);
  206257. }
  206258. CGFunctionRelease (function);
  206259. return result;
  206260. }
  206261. void drawGradient()
  206262. {
  206263. flip();
  206264. applyTransform (state->fillType.transform);
  206265. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  206266. // you draw a gradient with high quality interp enabled).
  206267. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  206268. CGContextSetAlpha (context, state->fillType.getOpacity());
  206269. CGContextDrawShading (context, shading);
  206270. CGShadingRelease (shading);
  206271. }
  206272. void createPath (const Path& path) const
  206273. {
  206274. CGContextBeginPath (context);
  206275. Path::Iterator i (path);
  206276. while (i.next())
  206277. {
  206278. switch (i.elementType)
  206279. {
  206280. case Path::Iterator::startNewSubPath:
  206281. CGContextMoveToPoint (context, i.x1, i.y1);
  206282. break;
  206283. case Path::Iterator::lineTo:
  206284. CGContextAddLineToPoint (context, i.x1, i.y1);
  206285. break;
  206286. case Path::Iterator::quadraticTo:
  206287. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  206288. break;
  206289. case Path::Iterator::cubicTo:
  206290. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  206291. break;
  206292. case Path::Iterator::closePath:
  206293. CGContextClosePath (context); break;
  206294. default:
  206295. jassertfalse
  206296. break;
  206297. }
  206298. }
  206299. }
  206300. void createPath (const Path& path, const AffineTransform& transform) const
  206301. {
  206302. CGContextBeginPath (context);
  206303. Path::Iterator i (path);
  206304. while (i.next())
  206305. {
  206306. switch (i.elementType)
  206307. {
  206308. case Path::Iterator::startNewSubPath:
  206309. transform.transformPoint (i.x1, i.y1);
  206310. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  206311. break;
  206312. case Path::Iterator::lineTo:
  206313. transform.transformPoint (i.x1, i.y1);
  206314. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  206315. break;
  206316. case Path::Iterator::quadraticTo:
  206317. transform.transformPoint (i.x1, i.y1);
  206318. transform.transformPoint (i.x2, i.y2);
  206319. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  206320. break;
  206321. case Path::Iterator::cubicTo:
  206322. transform.transformPoint (i.x1, i.y1);
  206323. transform.transformPoint (i.x2, i.y2);
  206324. transform.transformPoint (i.x3, i.y3);
  206325. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  206326. break;
  206327. case Path::Iterator::closePath:
  206328. CGContextClosePath (context); break;
  206329. default:
  206330. jassertfalse
  206331. break;
  206332. }
  206333. }
  206334. }
  206335. static Image* createAlphaChannelImage (const Image& im)
  206336. {
  206337. if (im.getFormat() == Image::SingleChannel)
  206338. return const_cast <Image*> (&im);
  206339. return im.createCopyOfAlphaChannel();
  206340. }
  206341. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  206342. {
  206343. if (im.getFormat() != Image::SingleChannel)
  206344. delete alphaIm;
  206345. }
  206346. void flip() const
  206347. {
  206348. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  206349. }
  206350. void applyTransform (const AffineTransform& transform) const
  206351. {
  206352. CGAffineTransform t;
  206353. t.a = transform.mat00;
  206354. t.b = transform.mat10;
  206355. t.c = transform.mat01;
  206356. t.d = transform.mat11;
  206357. t.tx = transform.mat02;
  206358. t.ty = transform.mat12;
  206359. CGContextConcatCTM (context, t);
  206360. }
  206361. CoreGraphicsContext (const CoreGraphicsContext&);
  206362. CoreGraphicsContext& operator= (const CoreGraphicsContext&);
  206363. };
  206364. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  206365. {
  206366. return new CoreGraphicsContext (context, imageHeight);
  206367. }
  206368. #endif
  206369. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  206370. /*** Start of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  206371. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  206372. // compiled on its own).
  206373. #if JUCE_INCLUDED_FILE
  206374. class NSViewComponentPeer;
  206375. END_JUCE_NAMESPACE
  206376. #define JuceNSView MakeObjCClassName(JuceNSView)
  206377. @interface JuceNSView : NSView<NSTextInput>
  206378. {
  206379. @public
  206380. NSViewComponentPeer* owner;
  206381. NSNotificationCenter* notificationCenter;
  206382. String* stringBeingComposed;
  206383. bool textWasInserted;
  206384. }
  206385. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner withFrame: (NSRect) frame;
  206386. - (void) dealloc;
  206387. - (BOOL) isOpaque;
  206388. - (void) drawRect: (NSRect) r;
  206389. - (void) mouseDown: (NSEvent*) ev;
  206390. - (void) asyncMouseDown: (NSEvent*) ev;
  206391. - (void) mouseUp: (NSEvent*) ev;
  206392. - (void) asyncMouseUp: (NSEvent*) ev;
  206393. - (void) mouseDragged: (NSEvent*) ev;
  206394. - (void) mouseMoved: (NSEvent*) ev;
  206395. - (void) mouseEntered: (NSEvent*) ev;
  206396. - (void) mouseExited: (NSEvent*) ev;
  206397. - (void) rightMouseDown: (NSEvent*) ev;
  206398. - (void) rightMouseDragged: (NSEvent*) ev;
  206399. - (void) rightMouseUp: (NSEvent*) ev;
  206400. - (void) otherMouseDown: (NSEvent*) ev;
  206401. - (void) otherMouseDragged: (NSEvent*) ev;
  206402. - (void) otherMouseUp: (NSEvent*) ev;
  206403. - (void) scrollWheel: (NSEvent*) ev;
  206404. - (BOOL) acceptsFirstMouse: (NSEvent*) ev;
  206405. - (void) frameChanged: (NSNotification*) n;
  206406. - (void) viewDidMoveToWindow;
  206407. - (void) keyDown: (NSEvent*) ev;
  206408. - (void) keyUp: (NSEvent*) ev;
  206409. // NSTextInput Methods
  206410. - (void) insertText: (id) aString;
  206411. - (void) doCommandBySelector: (SEL) aSelector;
  206412. - (void) setMarkedText: (id) aString selectedRange: (NSRange) selRange;
  206413. - (void) unmarkText;
  206414. - (BOOL) hasMarkedText;
  206415. - (long) conversationIdentifier;
  206416. - (NSAttributedString*) attributedSubstringFromRange: (NSRange) theRange;
  206417. - (NSRange) markedRange;
  206418. - (NSRange) selectedRange;
  206419. - (NSRect) firstRectForCharacterRange: (NSRange) theRange;
  206420. - (unsigned int) characterIndexForPoint: (NSPoint) thePoint;
  206421. - (NSArray*) validAttributesForMarkedText;
  206422. - (void) flagsChanged: (NSEvent*) ev;
  206423. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206424. - (BOOL) performKeyEquivalent: (NSEvent*) ev;
  206425. #endif
  206426. - (BOOL) becomeFirstResponder;
  206427. - (BOOL) resignFirstResponder;
  206428. - (BOOL) acceptsFirstResponder;
  206429. - (void) asyncRepaint: (id) rect;
  206430. - (NSArray*) getSupportedDragTypes;
  206431. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender;
  206432. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender;
  206433. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender;
  206434. - (void) draggingEnded: (id <NSDraggingInfo>) sender;
  206435. - (void) draggingExited: (id <NSDraggingInfo>) sender;
  206436. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender;
  206437. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender;
  206438. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender;
  206439. @end
  206440. #define JuceNSWindow MakeObjCClassName(JuceNSWindow)
  206441. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  206442. @interface JuceNSWindow : NSWindow <NSWindowDelegate>
  206443. #else
  206444. @interface JuceNSWindow : NSWindow
  206445. #endif
  206446. {
  206447. @private
  206448. NSViewComponentPeer* owner;
  206449. bool isZooming;
  206450. }
  206451. - (void) setOwner: (NSViewComponentPeer*) owner;
  206452. - (BOOL) canBecomeKeyWindow;
  206453. - (void) becomeKeyWindow;
  206454. - (BOOL) windowShouldClose: (id) window;
  206455. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen;
  206456. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize;
  206457. - (void) zoom: (id) sender;
  206458. @end
  206459. BEGIN_JUCE_NAMESPACE
  206460. class NSViewComponentPeer : public ComponentPeer
  206461. {
  206462. public:
  206463. NSViewComponentPeer (Component* const component,
  206464. const int windowStyleFlags,
  206465. NSView* viewToAttachTo);
  206466. ~NSViewComponentPeer();
  206467. void* getNativeHandle() const;
  206468. void setVisible (bool shouldBeVisible);
  206469. void setTitle (const String& title);
  206470. void setPosition (int x, int y);
  206471. void setSize (int w, int h);
  206472. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  206473. const Rectangle<int> getBounds (const bool global) const;
  206474. const Rectangle<int> getBounds() const;
  206475. const Point<int> getScreenPosition() const;
  206476. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition);
  206477. const Point<int> globalPositionToRelative (const Point<int>& screenPosition);
  206478. void setMinimised (bool shouldBeMinimised);
  206479. bool isMinimised() const;
  206480. void setFullScreen (bool shouldBeFullScreen);
  206481. bool isFullScreen() const;
  206482. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const;
  206483. const BorderSize getFrameSize() const;
  206484. bool setAlwaysOnTop (bool alwaysOnTop);
  206485. void toFront (bool makeActiveWindow);
  206486. void toBehind (ComponentPeer* other);
  206487. void setIcon (const Image& newIcon);
  206488. const StringArray getAvailableRenderingEngines() throw();
  206489. int getCurrentRenderingEngine() throw();
  206490. void setCurrentRenderingEngine (int index) throw();
  206491. virtual void redirectMouseDown (NSEvent* ev);
  206492. virtual void redirectMouseUp (NSEvent* ev);
  206493. virtual void redirectMouseDrag (NSEvent* ev);
  206494. virtual void redirectMouseMove (NSEvent* ev);
  206495. virtual void redirectMouseEnter (NSEvent* ev);
  206496. virtual void redirectMouseExit (NSEvent* ev);
  206497. virtual void redirectMouseWheel (NSEvent* ev);
  206498. void sendMouseEvent (NSEvent* ev);
  206499. bool handleKeyEvent (NSEvent* ev, bool isKeyDown);
  206500. virtual bool redirectKeyDown (NSEvent* ev);
  206501. virtual bool redirectKeyUp (NSEvent* ev);
  206502. virtual void redirectModKeyChange (NSEvent* ev);
  206503. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206504. virtual bool redirectPerformKeyEquivalent (NSEvent* ev);
  206505. #endif
  206506. virtual BOOL sendDragCallback (int type, id <NSDraggingInfo> sender);
  206507. virtual bool isOpaque();
  206508. virtual void drawRect (NSRect r);
  206509. virtual bool canBecomeKeyWindow();
  206510. virtual bool windowShouldClose();
  206511. virtual void redirectMovedOrResized();
  206512. virtual void viewMovedToWindow();
  206513. virtual NSRect constrainRect (NSRect r);
  206514. static void showArrowCursorIfNeeded();
  206515. static void updateModifiers (NSEvent* e);
  206516. static void updateKeysDown (NSEvent* ev, bool isKeyDown);
  206517. static int getKeyCodeFromEvent (NSEvent* ev)
  206518. {
  206519. const String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  206520. int keyCode = unmodified[0];
  206521. if (keyCode == 0x19) // (backwards-tab)
  206522. keyCode = '\t';
  206523. else if (keyCode == 0x03) // (enter)
  206524. keyCode = '\r';
  206525. return keyCode;
  206526. }
  206527. static int64 getMouseTime (NSEvent* e)
  206528. {
  206529. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  206530. + (int64) ([e timestamp] * 1000.0);
  206531. }
  206532. static const Point<int> getMousePos (NSEvent* e, NSView* view)
  206533. {
  206534. NSPoint p = [view convertPoint: [e locationInWindow] fromView: nil];
  206535. return Point<int> (roundToInt (p.x), roundToInt ([view frame].size.height - p.y));
  206536. }
  206537. static int getModifierForButtonNumber (const NSInteger num)
  206538. {
  206539. return num == 0 ? ModifierKeys::leftButtonModifier
  206540. : (num == 1 ? ModifierKeys::rightButtonModifier
  206541. : (num == 2 ? ModifierKeys::middleButtonModifier : 0));
  206542. }
  206543. virtual void viewFocusGain();
  206544. virtual void viewFocusLoss();
  206545. bool isFocused() const;
  206546. void grabFocus();
  206547. void textInputRequired (const Point<int>& position);
  206548. void repaint (int x, int y, int w, int h);
  206549. void performAnyPendingRepaintsNow();
  206550. juce_UseDebuggingNewOperator
  206551. NSWindow* window;
  206552. JuceNSView* view;
  206553. bool isSharedWindow, fullScreen, insideDrawRect, usingCoreGraphics, recursiveToFrontCall;
  206554. static ModifierKeys currentModifiers;
  206555. static ComponentPeer* currentlyFocusedPeer;
  206556. static VoidArray keysCurrentlyDown;
  206557. };
  206558. END_JUCE_NAMESPACE
  206559. @implementation JuceNSView
  206560. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner_
  206561. withFrame: (NSRect) frame
  206562. {
  206563. [super initWithFrame: frame];
  206564. owner = owner_;
  206565. stringBeingComposed = 0;
  206566. textWasInserted = false;
  206567. notificationCenter = [NSNotificationCenter defaultCenter];
  206568. [notificationCenter addObserver: self
  206569. selector: @selector (frameChanged:)
  206570. name: NSViewFrameDidChangeNotification
  206571. object: self];
  206572. if (! owner_->isSharedWindow)
  206573. {
  206574. [notificationCenter addObserver: self
  206575. selector: @selector (frameChanged:)
  206576. name: NSWindowDidMoveNotification
  206577. object: owner_->window];
  206578. }
  206579. [self registerForDraggedTypes: [self getSupportedDragTypes]];
  206580. return self;
  206581. }
  206582. - (void) dealloc
  206583. {
  206584. [notificationCenter removeObserver: self];
  206585. delete stringBeingComposed;
  206586. [super dealloc];
  206587. }
  206588. - (void) drawRect: (NSRect) r
  206589. {
  206590. if (owner != 0)
  206591. owner->drawRect (r);
  206592. }
  206593. - (BOOL) isOpaque
  206594. {
  206595. return owner == 0 || owner->isOpaque();
  206596. }
  206597. - (void) mouseDown: (NSEvent*) ev
  206598. {
  206599. // In some host situations, the host will stop modal loops from working
  206600. // correctly if they're called from a mouse event, so we'll trigger
  206601. // the event asynchronously..
  206602. if (JUCEApplication::getInstance() == 0)
  206603. [self performSelectorOnMainThread: @selector (asyncMouseDown:)
  206604. withObject: ev
  206605. waitUntilDone: NO];
  206606. else
  206607. [self asyncMouseDown: ev];
  206608. }
  206609. - (void) asyncMouseDown: (NSEvent*) ev
  206610. {
  206611. if (owner != 0)
  206612. owner->redirectMouseDown (ev);
  206613. }
  206614. - (void) mouseUp: (NSEvent*) ev
  206615. {
  206616. // In some host situations, the host will stop modal loops from working
  206617. // correctly if they're called from a mouse event, so we'll trigger
  206618. // the event asynchronously..
  206619. if (JUCEApplication::getInstance() == 0)
  206620. [self performSelectorOnMainThread: @selector (asyncMouseUp:)
  206621. withObject: ev
  206622. waitUntilDone: NO];
  206623. else
  206624. [self asyncMouseUp: ev];
  206625. }
  206626. - (void) asyncMouseUp: (NSEvent*) ev
  206627. {
  206628. if (owner != 0)
  206629. owner->redirectMouseUp (ev);
  206630. }
  206631. - (void) mouseDragged: (NSEvent*) ev
  206632. {
  206633. if (owner != 0)
  206634. owner->redirectMouseDrag (ev);
  206635. }
  206636. - (void) mouseMoved: (NSEvent*) ev
  206637. {
  206638. if (owner != 0)
  206639. owner->redirectMouseMove (ev);
  206640. }
  206641. - (void) mouseEntered: (NSEvent*) ev
  206642. {
  206643. if (owner != 0)
  206644. owner->redirectMouseEnter (ev);
  206645. }
  206646. - (void) mouseExited: (NSEvent*) ev
  206647. {
  206648. if (owner != 0)
  206649. owner->redirectMouseExit (ev);
  206650. }
  206651. - (void) rightMouseDown: (NSEvent*) ev
  206652. {
  206653. [self mouseDown: ev];
  206654. }
  206655. - (void) rightMouseDragged: (NSEvent*) ev
  206656. {
  206657. [self mouseDragged: ev];
  206658. }
  206659. - (void) rightMouseUp: (NSEvent*) ev
  206660. {
  206661. [self mouseUp: ev];
  206662. }
  206663. - (void) otherMouseDown: (NSEvent*) ev
  206664. {
  206665. [self mouseDown: ev];
  206666. }
  206667. - (void) otherMouseDragged: (NSEvent*) ev
  206668. {
  206669. [self mouseDragged: ev];
  206670. }
  206671. - (void) otherMouseUp: (NSEvent*) ev
  206672. {
  206673. [self mouseUp: ev];
  206674. }
  206675. - (void) scrollWheel: (NSEvent*) ev
  206676. {
  206677. if (owner != 0)
  206678. owner->redirectMouseWheel (ev);
  206679. }
  206680. - (BOOL) acceptsFirstMouse: (NSEvent*) ev
  206681. {
  206682. return YES;
  206683. }
  206684. - (void) frameChanged: (NSNotification*) n
  206685. {
  206686. if (owner != 0)
  206687. owner->redirectMovedOrResized();
  206688. }
  206689. - (void) viewDidMoveToWindow
  206690. {
  206691. if (owner != 0)
  206692. owner->viewMovedToWindow();
  206693. }
  206694. - (void) asyncRepaint: (id) rect
  206695. {
  206696. NSRect* r = (NSRect*) [((NSData*) rect) bytes];
  206697. [self setNeedsDisplayInRect: *r];
  206698. }
  206699. - (void) keyDown: (NSEvent*) ev
  206700. {
  206701. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206702. textWasInserted = false;
  206703. if (target != 0)
  206704. [self interpretKeyEvents: [NSArray arrayWithObject: ev]];
  206705. else
  206706. deleteAndZero (stringBeingComposed);
  206707. if ((! textWasInserted) && (owner == 0 || ! owner->redirectKeyDown (ev)))
  206708. [super keyDown: ev];
  206709. }
  206710. - (void) keyUp: (NSEvent*) ev
  206711. {
  206712. if (owner == 0 || ! owner->redirectKeyUp (ev))
  206713. [super keyUp: ev];
  206714. }
  206715. - (void) insertText: (id) aString
  206716. {
  206717. // This commits multi-byte text when return is pressed, or after every keypress for western keyboards
  206718. if ([aString length] > 0)
  206719. {
  206720. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206721. if (target != 0)
  206722. {
  206723. target->insertTextAtCaret (nsStringToJuce ([aString isKindOfClass: [NSAttributedString class]] ? [aString string] : aString));
  206724. textWasInserted = true;
  206725. }
  206726. }
  206727. deleteAndZero (stringBeingComposed);
  206728. }
  206729. - (void) doCommandBySelector: (SEL) aSelector
  206730. {
  206731. }
  206732. - (void) setMarkedText: (id) aString selectedRange: (NSRange) selectionRange
  206733. {
  206734. if (stringBeingComposed == 0)
  206735. stringBeingComposed = new String();
  206736. *stringBeingComposed = nsStringToJuce ([aString isKindOfClass:[NSAttributedString class]] ? [aString string] : aString);
  206737. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206738. if (target != 0)
  206739. {
  206740. const Range<int> currentHighlight (target->getHighlightedRegion());
  206741. target->insertTextAtCaret (*stringBeingComposed);
  206742. target->setHighlightedRegion (currentHighlight.withLength (stringBeingComposed->length()));
  206743. textWasInserted = true;
  206744. }
  206745. }
  206746. - (void) unmarkText
  206747. {
  206748. if (stringBeingComposed != 0)
  206749. {
  206750. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206751. if (target != 0)
  206752. {
  206753. target->insertTextAtCaret (*stringBeingComposed);
  206754. textWasInserted = true;
  206755. }
  206756. }
  206757. deleteAndZero (stringBeingComposed);
  206758. }
  206759. - (BOOL) hasMarkedText
  206760. {
  206761. return stringBeingComposed != 0;
  206762. }
  206763. - (long) conversationIdentifier
  206764. {
  206765. return (long) (pointer_sized_int) self;
  206766. }
  206767. - (NSAttributedString*) attributedSubstringFromRange: (NSRange) theRange
  206768. {
  206769. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206770. if (target != 0)
  206771. {
  206772. const Range<int> r ((int) theRange.location,
  206773. (int) (theRange.location + theRange.length));
  206774. return [[[NSAttributedString alloc] initWithString: juceStringToNS (target->getTextInRange (r))] autorelease];
  206775. }
  206776. return nil;
  206777. }
  206778. - (NSRange) markedRange
  206779. {
  206780. return stringBeingComposed != 0 ? NSMakeRange (0, stringBeingComposed->length())
  206781. : NSMakeRange (NSNotFound, 0);
  206782. }
  206783. - (NSRange) selectedRange
  206784. {
  206785. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206786. if (target != 0)
  206787. {
  206788. const Range<int> highlight (target->getHighlightedRegion());
  206789. if (! highlight.isEmpty())
  206790. return NSMakeRange (highlight.getStart(), highlight.getLength());
  206791. }
  206792. return NSMakeRange (NSNotFound, 0);
  206793. }
  206794. - (NSRect) firstRectForCharacterRange: (NSRange) theRange
  206795. {
  206796. JUCE_NAMESPACE::Component* const comp = dynamic_cast <JUCE_NAMESPACE::Component*> (owner->findCurrentTextInputTarget());
  206797. if (comp == 0)
  206798. return NSMakeRect (0, 0, 0, 0);
  206799. const Rectangle<int> bounds (comp->getScreenBounds());
  206800. return NSMakeRect (bounds.getX(),
  206801. [[[NSScreen screens] objectAtIndex: 0] frame].size.height - bounds.getY(),
  206802. bounds.getWidth(),
  206803. bounds.getHeight());
  206804. }
  206805. - (unsigned int) characterIndexForPoint: (NSPoint) thePoint
  206806. {
  206807. return NSNotFound;
  206808. }
  206809. - (NSArray*) validAttributesForMarkedText
  206810. {
  206811. return [NSArray array];
  206812. }
  206813. - (void) flagsChanged: (NSEvent*) ev
  206814. {
  206815. if (owner != 0)
  206816. owner->redirectModKeyChange (ev);
  206817. }
  206818. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206819. - (BOOL) performKeyEquivalent: (NSEvent*) ev
  206820. {
  206821. if (owner != 0 && owner->redirectPerformKeyEquivalent (ev))
  206822. return true;
  206823. return [super performKeyEquivalent: ev];
  206824. }
  206825. #endif
  206826. - (BOOL) becomeFirstResponder
  206827. {
  206828. if (owner != 0)
  206829. owner->viewFocusGain();
  206830. return true;
  206831. }
  206832. - (BOOL) resignFirstResponder
  206833. {
  206834. if (owner != 0)
  206835. owner->viewFocusLoss();
  206836. return true;
  206837. }
  206838. - (BOOL) acceptsFirstResponder
  206839. {
  206840. return owner != 0 && owner->canBecomeKeyWindow();
  206841. }
  206842. - (NSArray*) getSupportedDragTypes
  206843. {
  206844. return [NSArray arrayWithObjects: NSFilenamesPboardType, /*NSFilesPromisePboardType, NSStringPboardType,*/ nil];
  206845. }
  206846. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender
  206847. {
  206848. return owner != 0 && owner->sendDragCallback (type, sender);
  206849. }
  206850. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender
  206851. {
  206852. if ([self sendDragCallback: 0 sender: sender])
  206853. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206854. else
  206855. return NSDragOperationNone;
  206856. }
  206857. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender
  206858. {
  206859. if ([self sendDragCallback: 0 sender: sender])
  206860. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206861. else
  206862. return NSDragOperationNone;
  206863. }
  206864. - (void) draggingEnded: (id <NSDraggingInfo>) sender
  206865. {
  206866. [self sendDragCallback: 1 sender: sender];
  206867. }
  206868. - (void) draggingExited: (id <NSDraggingInfo>) sender
  206869. {
  206870. [self sendDragCallback: 1 sender: sender];
  206871. }
  206872. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender
  206873. {
  206874. return YES;
  206875. }
  206876. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender
  206877. {
  206878. return [self sendDragCallback: 2 sender: sender];
  206879. }
  206880. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender
  206881. {
  206882. }
  206883. @end
  206884. @implementation JuceNSWindow
  206885. - (void) setOwner: (NSViewComponentPeer*) owner_
  206886. {
  206887. owner = owner_;
  206888. isZooming = false;
  206889. }
  206890. - (BOOL) canBecomeKeyWindow
  206891. {
  206892. return owner != 0 && owner->canBecomeKeyWindow();
  206893. }
  206894. - (void) becomeKeyWindow
  206895. {
  206896. [super becomeKeyWindow];
  206897. if (owner != 0)
  206898. owner->grabFocus();
  206899. }
  206900. - (BOOL) windowShouldClose: (id) window
  206901. {
  206902. return owner == 0 || owner->windowShouldClose();
  206903. }
  206904. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen
  206905. {
  206906. if (owner != 0)
  206907. frameRect = owner->constrainRect (frameRect);
  206908. return frameRect;
  206909. }
  206910. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize
  206911. {
  206912. if (isZooming)
  206913. return proposedFrameSize;
  206914. NSRect frameRect = [self frame];
  206915. frameRect.origin.y -= proposedFrameSize.height - frameRect.size.height;
  206916. frameRect.size = proposedFrameSize;
  206917. if (owner != 0)
  206918. frameRect = owner->constrainRect (frameRect);
  206919. return frameRect.size;
  206920. }
  206921. - (void) zoom: (id) sender
  206922. {
  206923. isZooming = true;
  206924. [super zoom: sender];
  206925. isZooming = false;
  206926. }
  206927. - (void) windowWillMove: (NSNotification*) notification
  206928. {
  206929. if (JUCE_NAMESPACE::Component::getCurrentlyModalComponent() != 0
  206930. && owner->getComponent()->isCurrentlyBlockedByAnotherModalComponent()
  206931. && (owner->getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowHasTitleBar) != 0)
  206932. JUCE_NAMESPACE::Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  206933. }
  206934. @end
  206935. BEGIN_JUCE_NAMESPACE
  206936. ModifierKeys NSViewComponentPeer::currentModifiers;
  206937. ComponentPeer* NSViewComponentPeer::currentlyFocusedPeer = 0;
  206938. VoidArray NSViewComponentPeer::keysCurrentlyDown;
  206939. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  206940. {
  206941. if (NSViewComponentPeer::keysCurrentlyDown.contains ((void*) keyCode))
  206942. return true;
  206943. if (keyCode >= 'A' && keyCode <= 'Z'
  206944. && NSViewComponentPeer::keysCurrentlyDown.contains ((void*) (int) CharacterFunctions::toLowerCase ((tchar) keyCode)))
  206945. return true;
  206946. if (keyCode >= 'a' && keyCode <= 'z'
  206947. && NSViewComponentPeer::keysCurrentlyDown.contains ((void*) (int) CharacterFunctions::toUpperCase ((tchar) keyCode)))
  206948. return true;
  206949. return false;
  206950. }
  206951. void NSViewComponentPeer::updateModifiers (NSEvent* e)
  206952. {
  206953. int m = 0;
  206954. if (([e modifierFlags] & NSShiftKeyMask) != 0) m |= ModifierKeys::shiftModifier;
  206955. if (([e modifierFlags] & NSControlKeyMask) != 0) m |= ModifierKeys::ctrlModifier;
  206956. if (([e modifierFlags] & NSAlternateKeyMask) != 0) m |= ModifierKeys::altModifier;
  206957. if (([e modifierFlags] & NSCommandKeyMask) != 0) m |= ModifierKeys::commandModifier;
  206958. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (m);
  206959. }
  206960. void NSViewComponentPeer::updateKeysDown (NSEvent* ev, bool isKeyDown)
  206961. {
  206962. updateModifiers (ev);
  206963. int keyCode = getKeyCodeFromEvent (ev);
  206964. if (keyCode != 0)
  206965. {
  206966. if (isKeyDown)
  206967. keysCurrentlyDown.addIfNotAlreadyThere ((void*) keyCode);
  206968. else
  206969. keysCurrentlyDown.removeValue ((void*) keyCode);
  206970. }
  206971. }
  206972. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  206973. {
  206974. return NSViewComponentPeer::currentModifiers;
  206975. }
  206976. void ModifierKeys::updateCurrentModifiers() throw()
  206977. {
  206978. currentModifiers = NSViewComponentPeer::currentModifiers;
  206979. }
  206980. NSViewComponentPeer::NSViewComponentPeer (Component* const component_,
  206981. const int windowStyleFlags,
  206982. NSView* viewToAttachTo)
  206983. : ComponentPeer (component_, windowStyleFlags),
  206984. window (0),
  206985. view (0),
  206986. isSharedWindow (viewToAttachTo != 0),
  206987. fullScreen (false),
  206988. insideDrawRect (false),
  206989. #if USE_COREGRAPHICS_RENDERING
  206990. usingCoreGraphics (true),
  206991. #else
  206992. usingCoreGraphics (false),
  206993. #endif
  206994. recursiveToFrontCall (false)
  206995. {
  206996. NSRect r;
  206997. r.origin.x = 0;
  206998. r.origin.y = 0;
  206999. r.size.width = (float) component->getWidth();
  207000. r.size.height = (float) component->getHeight();
  207001. view = [[JuceNSView alloc] initWithOwner: this withFrame: r];
  207002. [view setPostsFrameChangedNotifications: YES];
  207003. if (isSharedWindow)
  207004. {
  207005. window = [viewToAttachTo window];
  207006. [viewToAttachTo addSubview: view];
  207007. setVisible (component->isVisible());
  207008. }
  207009. else
  207010. {
  207011. r.origin.x = (float) component->getX();
  207012. r.origin.y = (float) component->getY();
  207013. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207014. unsigned int style = 0;
  207015. if ((windowStyleFlags & windowHasTitleBar) == 0)
  207016. style = NSBorderlessWindowMask;
  207017. else
  207018. style = NSTitledWindowMask;
  207019. if ((windowStyleFlags & windowHasMinimiseButton) != 0)
  207020. style |= NSMiniaturizableWindowMask;
  207021. if ((windowStyleFlags & windowHasCloseButton) != 0)
  207022. style |= NSClosableWindowMask;
  207023. if ((windowStyleFlags & windowIsResizable) != 0)
  207024. style |= NSResizableWindowMask;
  207025. window = [[JuceNSWindow alloc] initWithContentRect: r
  207026. styleMask: style
  207027. backing: NSBackingStoreBuffered
  207028. defer: YES];
  207029. [((JuceNSWindow*) window) setOwner: this];
  207030. [window orderOut: nil];
  207031. [window setDelegate: (JuceNSWindow*) window];
  207032. [window setOpaque: component->isOpaque()];
  207033. [window setHasShadow: ((windowStyleFlags & windowHasDropShadow) != 0)];
  207034. if (component->isAlwaysOnTop())
  207035. [window setLevel: NSFloatingWindowLevel];
  207036. [window setContentView: view];
  207037. [window setAutodisplay: YES];
  207038. [window setAcceptsMouseMovedEvents: YES];
  207039. // We'll both retain and also release this on closing because plugin hosts can unexpectedly
  207040. // close the window for us, and also tend to get cause trouble if setReleasedWhenClosed is NO.
  207041. [window setReleasedWhenClosed: YES];
  207042. [window retain];
  207043. [window setExcludedFromWindowsMenu: (windowStyleFlags & windowIsTemporary) != 0];
  207044. [window setIgnoresMouseEvents: (windowStyleFlags & windowIgnoresMouseClicks) != 0];
  207045. }
  207046. setTitle (component->getName());
  207047. }
  207048. NSViewComponentPeer::~NSViewComponentPeer()
  207049. {
  207050. view->owner = 0;
  207051. [view removeFromSuperview];
  207052. [view release];
  207053. if (! isSharedWindow)
  207054. {
  207055. [((JuceNSWindow*) window) setOwner: 0];
  207056. [window close];
  207057. [window release];
  207058. }
  207059. }
  207060. void* NSViewComponentPeer::getNativeHandle() const
  207061. {
  207062. return view;
  207063. }
  207064. void NSViewComponentPeer::setVisible (bool shouldBeVisible)
  207065. {
  207066. if (isSharedWindow)
  207067. {
  207068. [view setHidden: ! shouldBeVisible];
  207069. }
  207070. else
  207071. {
  207072. if (shouldBeVisible)
  207073. {
  207074. [window orderFront: nil];
  207075. handleBroughtToFront();
  207076. }
  207077. else
  207078. {
  207079. [window orderOut: nil];
  207080. }
  207081. }
  207082. }
  207083. void NSViewComponentPeer::setTitle (const String& title)
  207084. {
  207085. const ScopedAutoReleasePool pool;
  207086. if (! isSharedWindow)
  207087. [window setTitle: juceStringToNS (title)];
  207088. }
  207089. void NSViewComponentPeer::setPosition (int x, int y)
  207090. {
  207091. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  207092. }
  207093. void NSViewComponentPeer::setSize (int w, int h)
  207094. {
  207095. setBounds (component->getX(), component->getY(), w, h, false);
  207096. }
  207097. void NSViewComponentPeer::setBounds (int x, int y, int w, int h, bool isNowFullScreen)
  207098. {
  207099. fullScreen = isNowFullScreen;
  207100. w = jmax (0, w);
  207101. h = jmax (0, h);
  207102. NSRect r;
  207103. r.origin.x = (float) x;
  207104. r.origin.y = (float) y;
  207105. r.size.width = (float) w;
  207106. r.size.height = (float) h;
  207107. if (isSharedWindow)
  207108. {
  207109. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207110. if ([view frame].size.width != r.size.width
  207111. || [view frame].size.height != r.size.height)
  207112. [view setNeedsDisplay: true];
  207113. [view setFrame: r];
  207114. }
  207115. else
  207116. {
  207117. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207118. [window setFrame: [window frameRectForContentRect: r]
  207119. display: true];
  207120. }
  207121. }
  207122. const Rectangle<int> NSViewComponentPeer::getBounds (const bool global) const
  207123. {
  207124. NSRect r = [view frame];
  207125. if (global && [view window] != 0)
  207126. {
  207127. r = [view convertRect: r toView: nil];
  207128. NSRect wr = [[view window] frame];
  207129. r.origin.x += wr.origin.x;
  207130. r.origin.y += wr.origin.y;
  207131. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  207132. }
  207133. else
  207134. {
  207135. r.origin.y = [[view superview] frame].size.height - r.origin.y - r.size.height;
  207136. }
  207137. return Rectangle<int> ((int) r.origin.x, (int) r.origin.y, (int) r.size.width, (int) r.size.height);
  207138. }
  207139. const Rectangle<int> NSViewComponentPeer::getBounds() const
  207140. {
  207141. return getBounds (! isSharedWindow);
  207142. }
  207143. const Point<int> NSViewComponentPeer::getScreenPosition() const
  207144. {
  207145. return getBounds (true).getPosition();
  207146. }
  207147. const Point<int> NSViewComponentPeer::relativePositionToGlobal (const Point<int>& relativePosition)
  207148. {
  207149. return relativePosition + getScreenPosition();
  207150. }
  207151. const Point<int> NSViewComponentPeer::globalPositionToRelative (const Point<int>& screenPosition)
  207152. {
  207153. return screenPosition - getScreenPosition();
  207154. }
  207155. NSRect NSViewComponentPeer::constrainRect (NSRect r)
  207156. {
  207157. if (constrainer != 0)
  207158. {
  207159. NSRect current = [window frame];
  207160. current.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - current.origin.y - current.size.height;
  207161. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  207162. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  207163. (int) r.size.width, (int) r.size.height);
  207164. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  207165. (int) current.size.width, (int) current.size.height);
  207166. constrainer->checkBounds (pos, original,
  207167. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  207168. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  207169. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  207170. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  207171. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  207172. r.origin.x = pos.getX();
  207173. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.size.height - pos.getY();
  207174. r.size.width = pos.getWidth();
  207175. r.size.height = pos.getHeight();
  207176. }
  207177. return r;
  207178. }
  207179. void NSViewComponentPeer::setMinimised (bool shouldBeMinimised)
  207180. {
  207181. if (! isSharedWindow)
  207182. {
  207183. if (shouldBeMinimised)
  207184. [window miniaturize: nil];
  207185. else
  207186. [window deminiaturize: nil];
  207187. }
  207188. }
  207189. bool NSViewComponentPeer::isMinimised() const
  207190. {
  207191. return window != 0 && [window isMiniaturized];
  207192. }
  207193. void NSViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  207194. {
  207195. if (! isSharedWindow)
  207196. {
  207197. Rectangle<int> r (lastNonFullscreenBounds);
  207198. setMinimised (false);
  207199. if (fullScreen != shouldBeFullScreen)
  207200. {
  207201. if (shouldBeFullScreen && (getStyleFlags() & windowHasTitleBar) != 0)
  207202. {
  207203. fullScreen = true;
  207204. [window performZoom: nil];
  207205. }
  207206. else
  207207. {
  207208. if (shouldBeFullScreen)
  207209. r = Desktop::getInstance().getMainMonitorArea();
  207210. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  207211. if (r != getComponent()->getBounds() && ! r.isEmpty())
  207212. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  207213. }
  207214. }
  207215. }
  207216. }
  207217. bool NSViewComponentPeer::isFullScreen() const
  207218. {
  207219. return fullScreen;
  207220. }
  207221. bool NSViewComponentPeer::contains (const Point<int>& position, bool trueIfInAChildWindow) const
  207222. {
  207223. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  207224. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  207225. return false;
  207226. NSPoint p;
  207227. p.x = (float) position.getX();
  207228. p.y = (float) position.getY();
  207229. NSView* v = [view hitTest: p];
  207230. if (trueIfInAChildWindow)
  207231. return v != nil;
  207232. return v == view;
  207233. }
  207234. const BorderSize NSViewComponentPeer::getFrameSize() const
  207235. {
  207236. BorderSize b;
  207237. if (! isSharedWindow)
  207238. {
  207239. NSRect v = [view convertRect: [view frame] toView: nil];
  207240. NSRect w = [window frame];
  207241. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  207242. b.setBottom ((int) v.origin.y);
  207243. b.setLeft ((int) v.origin.x);
  207244. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  207245. }
  207246. return b;
  207247. }
  207248. bool NSViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  207249. {
  207250. if (! isSharedWindow)
  207251. {
  207252. [window setLevel: alwaysOnTop ? NSFloatingWindowLevel
  207253. : NSNormalWindowLevel];
  207254. }
  207255. return true;
  207256. }
  207257. void NSViewComponentPeer::toFront (bool makeActiveWindow)
  207258. {
  207259. if (isSharedWindow)
  207260. {
  207261. [[view superview] addSubview: view
  207262. positioned: NSWindowAbove
  207263. relativeTo: nil];
  207264. }
  207265. if (window != 0 && component->isVisible())
  207266. {
  207267. if (makeActiveWindow)
  207268. [window makeKeyAndOrderFront: nil];
  207269. else
  207270. [window orderFront: nil];
  207271. if (! recursiveToFrontCall)
  207272. {
  207273. recursiveToFrontCall = true;
  207274. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  207275. handleBroughtToFront();
  207276. recursiveToFrontCall = false;
  207277. }
  207278. }
  207279. }
  207280. void NSViewComponentPeer::toBehind (ComponentPeer* other)
  207281. {
  207282. NSViewComponentPeer* o = (NSViewComponentPeer*) other;
  207283. if (isSharedWindow)
  207284. {
  207285. [[view superview] addSubview: view
  207286. positioned: NSWindowBelow
  207287. relativeTo: o->view];
  207288. }
  207289. else
  207290. {
  207291. [window orderWindow: NSWindowBelow
  207292. relativeTo: o->window != 0 ? [o->window windowNumber]
  207293. : nil ];
  207294. }
  207295. }
  207296. void NSViewComponentPeer::setIcon (const Image& /*newIcon*/)
  207297. {
  207298. // to do..
  207299. }
  207300. void NSViewComponentPeer::viewFocusGain()
  207301. {
  207302. if (currentlyFocusedPeer != this)
  207303. {
  207304. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  207305. currentlyFocusedPeer->handleFocusLoss();
  207306. currentlyFocusedPeer = this;
  207307. handleFocusGain();
  207308. }
  207309. }
  207310. void NSViewComponentPeer::viewFocusLoss()
  207311. {
  207312. if (currentlyFocusedPeer == this)
  207313. {
  207314. currentlyFocusedPeer = 0;
  207315. handleFocusLoss();
  207316. }
  207317. }
  207318. void juce_HandleProcessFocusChange()
  207319. {
  207320. NSViewComponentPeer::keysCurrentlyDown.clear();
  207321. if (NSViewComponentPeer::isValidPeer (NSViewComponentPeer::currentlyFocusedPeer))
  207322. {
  207323. if (Process::isForegroundProcess())
  207324. {
  207325. NSViewComponentPeer::currentlyFocusedPeer->handleFocusGain();
  207326. ComponentPeer::bringModalComponentToFront();
  207327. }
  207328. else
  207329. {
  207330. NSViewComponentPeer::currentlyFocusedPeer->handleFocusLoss();
  207331. // turn kiosk mode off if we lose focus..
  207332. Desktop::getInstance().setKioskModeComponent (0);
  207333. }
  207334. }
  207335. }
  207336. bool NSViewComponentPeer::isFocused() const
  207337. {
  207338. return isSharedWindow ? this == currentlyFocusedPeer
  207339. : (window != 0 && [window isKeyWindow]);
  207340. }
  207341. void NSViewComponentPeer::grabFocus()
  207342. {
  207343. if (window != 0)
  207344. {
  207345. [window makeKeyWindow];
  207346. [window makeFirstResponder: view];
  207347. viewFocusGain();
  207348. }
  207349. }
  207350. void NSViewComponentPeer::textInputRequired (const Point<int>&)
  207351. {
  207352. }
  207353. bool NSViewComponentPeer::handleKeyEvent (NSEvent* ev, bool isKeyDown)
  207354. {
  207355. String unicode (nsStringToJuce ([ev characters]));
  207356. String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  207357. int keyCode = getKeyCodeFromEvent (ev);
  207358. //DBG ("unicode: " + unicode + " " + String::toHexString ((int) unicode[0]));
  207359. //DBG ("unmodified: " + unmodified + " " + String::toHexString ((int) unmodified[0]));
  207360. if (unicode.isNotEmpty() || keyCode != 0)
  207361. {
  207362. if (isKeyDown)
  207363. {
  207364. bool used = false;
  207365. while (unicode.length() > 0)
  207366. {
  207367. juce_wchar textCharacter = unicode[0];
  207368. unicode = unicode.substring (1);
  207369. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207370. textCharacter = 0;
  207371. used = handleKeyUpOrDown (true) || used;
  207372. used = handleKeyPress (keyCode, textCharacter) || used;
  207373. }
  207374. return used;
  207375. }
  207376. else
  207377. {
  207378. if (handleKeyUpOrDown (false))
  207379. return true;
  207380. }
  207381. }
  207382. return false;
  207383. }
  207384. bool NSViewComponentPeer::redirectKeyDown (NSEvent* ev)
  207385. {
  207386. updateKeysDown (ev, true);
  207387. bool used = handleKeyEvent (ev, true);
  207388. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207389. {
  207390. // for command keys, the key-up event is thrown away, so simulate one..
  207391. updateKeysDown (ev, false);
  207392. used = (isValidPeer (this) && handleKeyEvent (ev, false)) || used;
  207393. }
  207394. // (If we're running modally, don't allow unused keystrokes to be passed
  207395. // along to other blocked views..)
  207396. if (Component::getCurrentlyModalComponent() != 0)
  207397. used = true;
  207398. return used;
  207399. }
  207400. bool NSViewComponentPeer::redirectKeyUp (NSEvent* ev)
  207401. {
  207402. updateKeysDown (ev, false);
  207403. return handleKeyEvent (ev, false)
  207404. || Component::getCurrentlyModalComponent() != 0;
  207405. }
  207406. void NSViewComponentPeer::redirectModKeyChange (NSEvent* ev)
  207407. {
  207408. keysCurrentlyDown.clear();
  207409. handleKeyUpOrDown (true);
  207410. updateModifiers (ev);
  207411. handleModifierKeysChange();
  207412. }
  207413. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  207414. bool NSViewComponentPeer::redirectPerformKeyEquivalent (NSEvent* ev)
  207415. {
  207416. if ([ev type] == NSKeyDown)
  207417. return redirectKeyDown (ev);
  207418. else if ([ev type] == NSKeyUp)
  207419. return redirectKeyUp (ev);
  207420. return false;
  207421. }
  207422. #endif
  207423. void NSViewComponentPeer::sendMouseEvent (NSEvent* ev)
  207424. {
  207425. updateModifiers (ev);
  207426. handleMouseEvent (0, getMousePos (ev, view), currentModifiers, getMouseTime (ev));
  207427. }
  207428. void NSViewComponentPeer::redirectMouseDown (NSEvent* ev)
  207429. {
  207430. currentModifiers = currentModifiers.withFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207431. sendMouseEvent (ev);
  207432. }
  207433. void NSViewComponentPeer::redirectMouseUp (NSEvent* ev)
  207434. {
  207435. currentModifiers = currentModifiers.withoutFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207436. sendMouseEvent (ev);
  207437. showArrowCursorIfNeeded();
  207438. }
  207439. void NSViewComponentPeer::redirectMouseDrag (NSEvent* ev)
  207440. {
  207441. currentModifiers = currentModifiers.withFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207442. sendMouseEvent (ev);
  207443. }
  207444. void NSViewComponentPeer::redirectMouseMove (NSEvent* ev)
  207445. {
  207446. currentModifiers = currentModifiers.withoutMouseButtons();
  207447. sendMouseEvent (ev);
  207448. showArrowCursorIfNeeded();
  207449. }
  207450. void NSViewComponentPeer::redirectMouseEnter (NSEvent* ev)
  207451. {
  207452. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  207453. currentModifiers = currentModifiers.withoutMouseButtons();
  207454. sendMouseEvent (ev);
  207455. }
  207456. void NSViewComponentPeer::redirectMouseExit (NSEvent* ev)
  207457. {
  207458. currentModifiers = currentModifiers.withoutMouseButtons();
  207459. sendMouseEvent (ev);
  207460. }
  207461. void NSViewComponentPeer::redirectMouseWheel (NSEvent* ev)
  207462. {
  207463. updateModifiers (ev);
  207464. handleMouseWheel (0, getMousePos (ev, view), getMouseTime (ev),
  207465. [ev deltaX] * 10.0f, [ev deltaY] * 10.0f);
  207466. }
  207467. void NSViewComponentPeer::showArrowCursorIfNeeded()
  207468. {
  207469. MouseInputSource& mouse = Desktop::getInstance().getMainMouseSource();
  207470. if (mouse.getComponentUnderMouse() == 0
  207471. && Desktop::getInstance().findComponentAt (mouse.getScreenPosition()) == 0)
  207472. {
  207473. [[NSCursor arrowCursor] set];
  207474. }
  207475. }
  207476. BOOL NSViewComponentPeer::sendDragCallback (int type, id <NSDraggingInfo> sender)
  207477. {
  207478. NSString* bestType
  207479. = [[sender draggingPasteboard] availableTypeFromArray: [view getSupportedDragTypes]];
  207480. if (bestType == nil)
  207481. return false;
  207482. NSPoint p = [view convertPoint: [sender draggingLocation] fromView: nil];
  207483. const Point<int> pos ((int) p.x, (int) ([view frame].size.height - p.y));
  207484. StringArray files;
  207485. id list = [[sender draggingPasteboard] propertyListForType: bestType];
  207486. if (list == nil)
  207487. return false;
  207488. if ([list isKindOfClass: [NSArray class]])
  207489. {
  207490. NSArray* items = (NSArray*) list;
  207491. for (unsigned int i = 0; i < [items count]; ++i)
  207492. files.add (nsStringToJuce ((NSString*) [items objectAtIndex: i]));
  207493. }
  207494. if (files.size() == 0)
  207495. return false;
  207496. if (type == 0)
  207497. handleFileDragMove (files, pos);
  207498. else if (type == 1)
  207499. handleFileDragExit (files);
  207500. else if (type == 2)
  207501. handleFileDragDrop (files, pos);
  207502. return true;
  207503. }
  207504. bool NSViewComponentPeer::isOpaque()
  207505. {
  207506. return component == 0 || component->isOpaque();
  207507. }
  207508. void NSViewComponentPeer::drawRect (NSRect r)
  207509. {
  207510. if (r.size.width < 1.0f || r.size.height < 1.0f)
  207511. return;
  207512. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  207513. if (! component->isOpaque())
  207514. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  207515. #if USE_COREGRAPHICS_RENDERING
  207516. if (usingCoreGraphics)
  207517. {
  207518. CoreGraphicsContext context (cg, (float) [view frame].size.height);
  207519. insideDrawRect = true;
  207520. handlePaint (context);
  207521. insideDrawRect = false;
  207522. }
  207523. else
  207524. #endif
  207525. {
  207526. Image temp (getComponent()->isOpaque() ? Image::RGB : Image::ARGB,
  207527. (int) (r.size.width + 0.5f),
  207528. (int) (r.size.height + 0.5f),
  207529. ! getComponent()->isOpaque());
  207530. LowLevelGraphicsSoftwareRenderer context (temp);
  207531. context.setOrigin (-roundToInt (r.origin.x),
  207532. -roundToInt ([view frame].size.height - (r.origin.y + r.size.height)));
  207533. const NSRect* rects = 0;
  207534. NSInteger numRects = 0;
  207535. [view getRectsBeingDrawn: &rects count: &numRects];
  207536. RectangleList clip;
  207537. for (int i = 0; i < numRects; ++i)
  207538. {
  207539. clip.addWithoutMerging (Rectangle<int> (roundToInt (rects[i].origin.x),
  207540. roundToInt ([view frame].size.height - (rects[i].origin.y + rects[i].size.height)),
  207541. roundToInt (rects[i].size.width),
  207542. roundToInt (rects[i].size.height)));
  207543. }
  207544. if (context.clipToRectangleList (clip))
  207545. {
  207546. insideDrawRect = true;
  207547. handlePaint (context);
  207548. insideDrawRect = false;
  207549. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  207550. CGImageRef image = CoreGraphicsImage::createImage (temp, false, colourSpace);
  207551. CGColorSpaceRelease (colourSpace);
  207552. CGContextDrawImage (cg, CGRectMake (r.origin.x, r.origin.y, temp.getWidth(), temp.getHeight()), image);
  207553. CGImageRelease (image);
  207554. }
  207555. }
  207556. }
  207557. const StringArray NSViewComponentPeer::getAvailableRenderingEngines() throw()
  207558. {
  207559. StringArray s;
  207560. s.add ("Software Renderer");
  207561. #if USE_COREGRAPHICS_RENDERING
  207562. s.add ("CoreGraphics Renderer");
  207563. #endif
  207564. return s;
  207565. }
  207566. int NSViewComponentPeer::getCurrentRenderingEngine() throw()
  207567. {
  207568. return usingCoreGraphics ? 1 : 0;
  207569. }
  207570. void NSViewComponentPeer::setCurrentRenderingEngine (int index) throw()
  207571. {
  207572. #if USE_COREGRAPHICS_RENDERING
  207573. if (usingCoreGraphics != (index > 0))
  207574. {
  207575. usingCoreGraphics = index > 0;
  207576. [view setNeedsDisplay: true];
  207577. }
  207578. #endif
  207579. }
  207580. bool NSViewComponentPeer::canBecomeKeyWindow()
  207581. {
  207582. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  207583. }
  207584. bool NSViewComponentPeer::windowShouldClose()
  207585. {
  207586. if (! isValidPeer (this))
  207587. return YES;
  207588. handleUserClosingWindow();
  207589. return NO;
  207590. }
  207591. void NSViewComponentPeer::redirectMovedOrResized()
  207592. {
  207593. handleMovedOrResized();
  207594. }
  207595. void NSViewComponentPeer::viewMovedToWindow()
  207596. {
  207597. if (isSharedWindow)
  207598. window = [view window];
  207599. }
  207600. void Desktop::createMouseInputSources()
  207601. {
  207602. mouseSources.add (new MouseInputSource (0, true));
  207603. }
  207604. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  207605. {
  207606. // Very annoyingly, this function has to use the old SetSystemUIMode function,
  207607. // which is in Carbon.framework. But, because there's no Cocoa equivalent, it
  207608. // is apparently still available in 64-bit apps..
  207609. if (enableOrDisable)
  207610. {
  207611. SetSystemUIMode (kUIModeAllSuppressed, allowMenusAndBars ? kUIOptionAutoShowMenuBar : 0);
  207612. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  207613. }
  207614. else
  207615. {
  207616. SetSystemUIMode (kUIModeNormal, 0);
  207617. }
  207618. }
  207619. class AsyncRepaintMessage : public CallbackMessage
  207620. {
  207621. public:
  207622. NSViewComponentPeer* const peer;
  207623. const Rectangle<int> rect;
  207624. AsyncRepaintMessage (NSViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  207625. : peer (peer_), rect (rect_)
  207626. {
  207627. }
  207628. void messageCallback()
  207629. {
  207630. if (ComponentPeer::isValidPeer (peer))
  207631. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  207632. }
  207633. };
  207634. void NSViewComponentPeer::repaint (int x, int y, int w, int h)
  207635. {
  207636. if (insideDrawRect)
  207637. {
  207638. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  207639. }
  207640. else
  207641. {
  207642. [view setNeedsDisplayInRect: NSMakeRect ((float) x, (float) ([view frame].size.height - (y + h)),
  207643. (float) w, (float) h)];
  207644. }
  207645. }
  207646. void NSViewComponentPeer::performAnyPendingRepaintsNow()
  207647. {
  207648. [view displayIfNeeded];
  207649. }
  207650. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  207651. {
  207652. return new NSViewComponentPeer (this, styleFlags, (NSView*) windowToAttachTo);
  207653. }
  207654. Image* juce_createIconForFile (const File& file)
  207655. {
  207656. const ScopedAutoReleasePool pool;
  207657. NSImage* image = [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (file.getFullPathName())];
  207658. CoreGraphicsImage* result = new CoreGraphicsImage (Image::ARGB, (int) [image size].width, (int) [image size].height, true);
  207659. [NSGraphicsContext saveGraphicsState];
  207660. [NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithGraphicsPort: result->context flipped: false]];
  207661. [image drawAtPoint: NSMakePoint (0, 0)
  207662. fromRect: NSMakeRect (0, 0, [image size].width, [image size].height)
  207663. operation: NSCompositeSourceOver fraction: 1.0f];
  207664. [[NSGraphicsContext currentContext] flushGraphics];
  207665. [NSGraphicsContext restoreGraphicsState];
  207666. return result;
  207667. }
  207668. const int KeyPress::spaceKey = ' ';
  207669. const int KeyPress::returnKey = 0x0d;
  207670. const int KeyPress::escapeKey = 0x1b;
  207671. const int KeyPress::backspaceKey = 0x7f;
  207672. const int KeyPress::leftKey = NSLeftArrowFunctionKey;
  207673. const int KeyPress::rightKey = NSRightArrowFunctionKey;
  207674. const int KeyPress::upKey = NSUpArrowFunctionKey;
  207675. const int KeyPress::downKey = NSDownArrowFunctionKey;
  207676. const int KeyPress::pageUpKey = NSPageUpFunctionKey;
  207677. const int KeyPress::pageDownKey = NSPageDownFunctionKey;
  207678. const int KeyPress::endKey = NSEndFunctionKey;
  207679. const int KeyPress::homeKey = NSHomeFunctionKey;
  207680. const int KeyPress::deleteKey = NSDeleteFunctionKey;
  207681. const int KeyPress::insertKey = -1;
  207682. const int KeyPress::tabKey = 9;
  207683. const int KeyPress::F1Key = NSF1FunctionKey;
  207684. const int KeyPress::F2Key = NSF2FunctionKey;
  207685. const int KeyPress::F3Key = NSF3FunctionKey;
  207686. const int KeyPress::F4Key = NSF4FunctionKey;
  207687. const int KeyPress::F5Key = NSF5FunctionKey;
  207688. const int KeyPress::F6Key = NSF6FunctionKey;
  207689. const int KeyPress::F7Key = NSF7FunctionKey;
  207690. const int KeyPress::F8Key = NSF8FunctionKey;
  207691. const int KeyPress::F9Key = NSF9FunctionKey;
  207692. const int KeyPress::F10Key = NSF10FunctionKey;
  207693. const int KeyPress::F11Key = NSF1FunctionKey;
  207694. const int KeyPress::F12Key = NSF12FunctionKey;
  207695. const int KeyPress::F13Key = NSF13FunctionKey;
  207696. const int KeyPress::F14Key = NSF14FunctionKey;
  207697. const int KeyPress::F15Key = NSF15FunctionKey;
  207698. const int KeyPress::F16Key = NSF16FunctionKey;
  207699. const int KeyPress::numberPad0 = 0x30020;
  207700. const int KeyPress::numberPad1 = 0x30021;
  207701. const int KeyPress::numberPad2 = 0x30022;
  207702. const int KeyPress::numberPad3 = 0x30023;
  207703. const int KeyPress::numberPad4 = 0x30024;
  207704. const int KeyPress::numberPad5 = 0x30025;
  207705. const int KeyPress::numberPad6 = 0x30026;
  207706. const int KeyPress::numberPad7 = 0x30027;
  207707. const int KeyPress::numberPad8 = 0x30028;
  207708. const int KeyPress::numberPad9 = 0x30029;
  207709. const int KeyPress::numberPadAdd = 0x3002a;
  207710. const int KeyPress::numberPadSubtract = 0x3002b;
  207711. const int KeyPress::numberPadMultiply = 0x3002c;
  207712. const int KeyPress::numberPadDivide = 0x3002d;
  207713. const int KeyPress::numberPadSeparator = 0x3002e;
  207714. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  207715. const int KeyPress::numberPadEquals = 0x30030;
  207716. const int KeyPress::numberPadDelete = 0x30031;
  207717. const int KeyPress::playKey = 0x30000;
  207718. const int KeyPress::stopKey = 0x30001;
  207719. const int KeyPress::fastForwardKey = 0x30002;
  207720. const int KeyPress::rewindKey = 0x30003;
  207721. #endif
  207722. /*** End of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  207723. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  207724. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207725. // compiled on its own).
  207726. #if JUCE_INCLUDED_FILE
  207727. #if JUCE_MAC
  207728. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  207729. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  207730. {
  207731. NSImage* im = CoreGraphicsImage::createNSImage (image);
  207732. NSCursor* c = [[NSCursor alloc] initWithImage: im
  207733. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  207734. [im release];
  207735. return (void*) c;
  207736. }
  207737. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  207738. {
  207739. MemoryInputStream stream (data, size, false);
  207740. ScopedPointer <Image> im (juce_loadPNGImageFromStream (stream));
  207741. jassert (im != 0);
  207742. if (im == 0)
  207743. return 0;
  207744. return juce_createMouseCursorFromImage (*im,
  207745. (int) (hx * im->getWidth()),
  207746. (int) (hy * im->getHeight()));
  207747. }
  207748. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  207749. {
  207750. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  207751. MemoryBlock mb;
  207752. if (f.getChildFile (filename).loadFileAsData (mb))
  207753. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  207754. return 0;
  207755. }
  207756. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  207757. {
  207758. const ScopedAutoReleasePool pool;
  207759. NSCursor* c = 0;
  207760. switch (type)
  207761. {
  207762. case MouseCursor::NormalCursor:
  207763. c = [NSCursor arrowCursor];
  207764. break;
  207765. case MouseCursor::NoCursor:
  207766. return juce_createMouseCursorFromImage (Image (Image::ARGB, 8, 8, true), 0, 0);
  207767. case MouseCursor::DraggingHandCursor:
  207768. c = [NSCursor openHandCursor];
  207769. break;
  207770. case MouseCursor::CopyingCursor:
  207771. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  207772. case MouseCursor::WaitCursor:
  207773. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  207774. break;
  207775. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  207776. case MouseCursor::IBeamCursor:
  207777. c = [NSCursor IBeamCursor];
  207778. break;
  207779. case MouseCursor::PointingHandCursor:
  207780. c = [NSCursor pointingHandCursor];
  207781. break;
  207782. case MouseCursor::LeftRightResizeCursor:
  207783. c = [NSCursor resizeLeftRightCursor];
  207784. break;
  207785. case MouseCursor::LeftEdgeResizeCursor:
  207786. c = [NSCursor resizeLeftCursor];
  207787. break;
  207788. case MouseCursor::RightEdgeResizeCursor:
  207789. c = [NSCursor resizeRightCursor];
  207790. break;
  207791. case MouseCursor::UpDownResizeCursor:
  207792. case MouseCursor::TopEdgeResizeCursor:
  207793. case MouseCursor::BottomEdgeResizeCursor:
  207794. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  207795. case MouseCursor::TopLeftCornerResizeCursor:
  207796. case MouseCursor::BottomRightCornerResizeCursor:
  207797. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  207798. case MouseCursor::TopRightCornerResizeCursor:
  207799. case MouseCursor::BottomLeftCornerResizeCursor:
  207800. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  207801. case MouseCursor::UpDownLeftRightResizeCursor:
  207802. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  207803. case MouseCursor::CrosshairCursor:
  207804. c = [NSCursor crosshairCursor];
  207805. break;
  207806. }
  207807. [c retain];
  207808. return (void*) c;
  207809. }
  207810. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  207811. {
  207812. NSCursor* c = (NSCursor*) cursorHandle;
  207813. [c release];
  207814. }
  207815. void MouseCursor::showInAllWindows() const throw()
  207816. {
  207817. showInWindow (0);
  207818. }
  207819. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  207820. {
  207821. NSCursor* const c = (NSCursor*) getHandle();
  207822. [c set];
  207823. }
  207824. #else
  207825. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  207826. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  207827. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  207828. void MouseCursor::showInAllWindows() const throw() {}
  207829. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  207830. #endif
  207831. #endif
  207832. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  207833. /*** Start of inlined file: juce_mac_NSViewComponent.mm ***/
  207834. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207835. // compiled on its own).
  207836. #if JUCE_INCLUDED_FILE
  207837. class NSViewComponentInternal : public ComponentMovementWatcher
  207838. {
  207839. Component* const owner;
  207840. NSViewComponentPeer* currentPeer;
  207841. bool wasShowing;
  207842. public:
  207843. NSView* const view;
  207844. NSViewComponentInternal (NSView* const view_, Component* const owner_)
  207845. : ComponentMovementWatcher (owner_),
  207846. owner (owner_),
  207847. currentPeer (0),
  207848. wasShowing (false),
  207849. view (view_)
  207850. {
  207851. [view_ retain];
  207852. if (owner_->isShowing())
  207853. componentPeerChanged();
  207854. }
  207855. ~NSViewComponentInternal()
  207856. {
  207857. [view removeFromSuperview];
  207858. [view release];
  207859. }
  207860. void componentMovedOrResized (Component& comp, bool wasMoved, bool wasResized)
  207861. {
  207862. ComponentMovementWatcher::componentMovedOrResized (comp, wasMoved, wasResized);
  207863. // The ComponentMovementWatcher version of this method avoids calling
  207864. // us when the top-level comp is resized, but for an NSView we need to know this
  207865. // because with inverted co-ords, we need to update the position even if the
  207866. // top-left pos hasn't changed
  207867. if (comp.isOnDesktop() && wasResized)
  207868. componentMovedOrResized (wasMoved, wasResized);
  207869. }
  207870. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  207871. {
  207872. Component* const topComp = owner->getTopLevelComponent();
  207873. if (topComp->getPeer() != 0)
  207874. {
  207875. const Point<int> pos (owner->relativePositionToOtherComponent (topComp, Point<int>()));
  207876. NSRect r;
  207877. r.origin.x = (float) pos.getX();
  207878. r.origin.y = (float) pos.getY();
  207879. r.size.width = (float) owner->getWidth();
  207880. r.size.height = (float) owner->getHeight();
  207881. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207882. [view setFrame: r];
  207883. }
  207884. }
  207885. void componentPeerChanged()
  207886. {
  207887. NSViewComponentPeer* const peer = dynamic_cast <NSViewComponentPeer*> (owner->getPeer());
  207888. if (currentPeer != peer)
  207889. {
  207890. [view removeFromSuperview];
  207891. currentPeer = peer;
  207892. if (peer != 0)
  207893. {
  207894. [peer->view addSubview: view];
  207895. componentMovedOrResized (false, false);
  207896. }
  207897. }
  207898. [view setHidden: ! owner->isShowing()];
  207899. }
  207900. void componentVisibilityChanged (Component&)
  207901. {
  207902. componentPeerChanged();
  207903. }
  207904. juce_UseDebuggingNewOperator
  207905. private:
  207906. NSViewComponentInternal (const NSViewComponentInternal&);
  207907. NSViewComponentInternal& operator= (const NSViewComponentInternal&);
  207908. };
  207909. NSViewComponent::NSViewComponent()
  207910. {
  207911. }
  207912. NSViewComponent::~NSViewComponent()
  207913. {
  207914. }
  207915. void NSViewComponent::setView (void* view)
  207916. {
  207917. if (view != getView())
  207918. {
  207919. if (view != 0)
  207920. info = new NSViewComponentInternal ((NSView*) view, this);
  207921. else
  207922. info = 0;
  207923. }
  207924. }
  207925. void* NSViewComponent::getView() const
  207926. {
  207927. return info == 0 ? 0 : info->view;
  207928. }
  207929. void NSViewComponent::paint (Graphics& g)
  207930. {
  207931. }
  207932. #endif
  207933. /*** End of inlined file: juce_mac_NSViewComponent.mm ***/
  207934. /*** Start of inlined file: juce_mac_AppleRemote.mm ***/
  207935. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207936. // compiled on its own).
  207937. #if JUCE_INCLUDED_FILE
  207938. AppleRemoteDevice::AppleRemoteDevice()
  207939. : device (0),
  207940. queue (0),
  207941. remoteId (0)
  207942. {
  207943. }
  207944. AppleRemoteDevice::~AppleRemoteDevice()
  207945. {
  207946. stop();
  207947. }
  207948. static io_object_t getAppleRemoteDevice()
  207949. {
  207950. CFMutableDictionaryRef dict = IOServiceMatching ("AppleIRController");
  207951. io_iterator_t iter = 0;
  207952. io_object_t iod = 0;
  207953. if (IOServiceGetMatchingServices (kIOMasterPortDefault, dict, &iter) == kIOReturnSuccess
  207954. && iter != 0)
  207955. {
  207956. iod = IOIteratorNext (iter);
  207957. }
  207958. IOObjectRelease (iter);
  207959. return iod;
  207960. }
  207961. static bool createAppleRemoteInterface (io_object_t iod, void** device)
  207962. {
  207963. jassert (*device == 0);
  207964. io_name_t classname;
  207965. if (IOObjectGetClass (iod, classname) == kIOReturnSuccess)
  207966. {
  207967. IOCFPlugInInterface** cfPlugInInterface = 0;
  207968. SInt32 score = 0;
  207969. if (IOCreatePlugInInterfaceForService (iod,
  207970. kIOHIDDeviceUserClientTypeID,
  207971. kIOCFPlugInInterfaceID,
  207972. &cfPlugInInterface,
  207973. &score) == kIOReturnSuccess)
  207974. {
  207975. HRESULT hr = (*cfPlugInInterface)->QueryInterface (cfPlugInInterface,
  207976. CFUUIDGetUUIDBytes (kIOHIDDeviceInterfaceID),
  207977. device);
  207978. (void) hr;
  207979. (*cfPlugInInterface)->Release (cfPlugInInterface);
  207980. }
  207981. }
  207982. return *device != 0;
  207983. }
  207984. bool AppleRemoteDevice::start (const bool inExclusiveMode)
  207985. {
  207986. if (queue != 0)
  207987. return true;
  207988. stop();
  207989. bool result = false;
  207990. io_object_t iod = getAppleRemoteDevice();
  207991. if (iod != 0)
  207992. {
  207993. if (createAppleRemoteInterface (iod, &device) && open (inExclusiveMode))
  207994. result = true;
  207995. else
  207996. stop();
  207997. IOObjectRelease (iod);
  207998. }
  207999. return result;
  208000. }
  208001. void AppleRemoteDevice::stop()
  208002. {
  208003. if (queue != 0)
  208004. {
  208005. (*(IOHIDQueueInterface**) queue)->stop ((IOHIDQueueInterface**) queue);
  208006. (*(IOHIDQueueInterface**) queue)->dispose ((IOHIDQueueInterface**) queue);
  208007. (*(IOHIDQueueInterface**) queue)->Release ((IOHIDQueueInterface**) queue);
  208008. queue = 0;
  208009. }
  208010. if (device != 0)
  208011. {
  208012. (*(IOHIDDeviceInterface**) device)->close ((IOHIDDeviceInterface**) device);
  208013. (*(IOHIDDeviceInterface**) device)->Release ((IOHIDDeviceInterface**) device);
  208014. device = 0;
  208015. }
  208016. }
  208017. bool AppleRemoteDevice::isActive() const
  208018. {
  208019. return queue != 0;
  208020. }
  208021. static void appleRemoteQueueCallback (void* const target, const IOReturn result, void*, void*)
  208022. {
  208023. if (result == kIOReturnSuccess)
  208024. ((AppleRemoteDevice*) target)->handleCallbackInternal();
  208025. }
  208026. bool AppleRemoteDevice::open (const bool openInExclusiveMode)
  208027. {
  208028. Array <int> cookies;
  208029. CFArrayRef elements;
  208030. IOHIDDeviceInterface122** const device122 = (IOHIDDeviceInterface122**) device;
  208031. if ((*device122)->copyMatchingElements (device122, 0, &elements) != kIOReturnSuccess)
  208032. return false;
  208033. for (int i = 0; i < CFArrayGetCount (elements); ++i)
  208034. {
  208035. CFDictionaryRef element = (CFDictionaryRef) CFArrayGetValueAtIndex (elements, i);
  208036. // get the cookie
  208037. CFTypeRef object = CFDictionaryGetValue (element, CFSTR (kIOHIDElementCookieKey));
  208038. if (object == 0 || CFGetTypeID (object) != CFNumberGetTypeID())
  208039. continue;
  208040. long number;
  208041. if (! CFNumberGetValue ((CFNumberRef) object, kCFNumberLongType, &number))
  208042. continue;
  208043. cookies.add ((int) number);
  208044. }
  208045. CFRelease (elements);
  208046. if ((*(IOHIDDeviceInterface**) device)
  208047. ->open ((IOHIDDeviceInterface**) device,
  208048. openInExclusiveMode ? kIOHIDOptionsTypeSeizeDevice
  208049. : kIOHIDOptionsTypeNone) == KERN_SUCCESS)
  208050. {
  208051. queue = (*(IOHIDDeviceInterface**) device)->allocQueue ((IOHIDDeviceInterface**) device);
  208052. if (queue != 0)
  208053. {
  208054. (*(IOHIDQueueInterface**) queue)->create ((IOHIDQueueInterface**) queue, 0, 12);
  208055. for (int i = 0; i < cookies.size(); ++i)
  208056. {
  208057. IOHIDElementCookie cookie = (IOHIDElementCookie) cookies.getUnchecked(i);
  208058. (*(IOHIDQueueInterface**) queue)->addElement ((IOHIDQueueInterface**) queue, cookie, 0);
  208059. }
  208060. CFRunLoopSourceRef eventSource;
  208061. if ((*(IOHIDQueueInterface**) queue)
  208062. ->createAsyncEventSource ((IOHIDQueueInterface**) queue, &eventSource) == KERN_SUCCESS)
  208063. {
  208064. if ((*(IOHIDQueueInterface**) queue)->setEventCallout ((IOHIDQueueInterface**) queue,
  208065. appleRemoteQueueCallback, this, 0) == KERN_SUCCESS)
  208066. {
  208067. CFRunLoopAddSource (CFRunLoopGetCurrent(), eventSource, kCFRunLoopDefaultMode);
  208068. (*(IOHIDQueueInterface**) queue)->start ((IOHIDQueueInterface**) queue);
  208069. return true;
  208070. }
  208071. }
  208072. }
  208073. }
  208074. return false;
  208075. }
  208076. void AppleRemoteDevice::handleCallbackInternal()
  208077. {
  208078. int totalValues = 0;
  208079. AbsoluteTime nullTime = { 0, 0 };
  208080. char cookies [12];
  208081. int numCookies = 0;
  208082. while (numCookies < numElementsInArray (cookies))
  208083. {
  208084. IOHIDEventStruct e;
  208085. if ((*(IOHIDQueueInterface**) queue)->getNextEvent ((IOHIDQueueInterface**) queue, &e, nullTime, 0) != kIOReturnSuccess)
  208086. break;
  208087. if ((int) e.elementCookie == 19)
  208088. {
  208089. remoteId = e.value;
  208090. buttonPressed (switched, false);
  208091. }
  208092. else
  208093. {
  208094. totalValues += e.value;
  208095. cookies [numCookies++] = (char) (pointer_sized_int) e.elementCookie;
  208096. }
  208097. }
  208098. cookies [numCookies++] = 0;
  208099. //DBG (String::toHexString ((uint8*) cookies, numCookies, 1) + " " + String (totalValues));
  208100. static const char buttonPatterns[] =
  208101. {
  208102. 0x1f, 0x14, 0x12, 0x1f, 0x14, 0x12, 0,
  208103. 0x1f, 0x15, 0x12, 0x1f, 0x15, 0x12, 0,
  208104. 0x1f, 0x1d, 0x1c, 0x12, 0,
  208105. 0x1f, 0x1e, 0x1c, 0x12, 0,
  208106. 0x1f, 0x16, 0x12, 0x1f, 0x16, 0x12, 0,
  208107. 0x1f, 0x17, 0x12, 0x1f, 0x17, 0x12, 0,
  208108. 0x1f, 0x12, 0x04, 0x02, 0,
  208109. 0x1f, 0x12, 0x03, 0x02, 0,
  208110. 0x1f, 0x12, 0x1f, 0x12, 0,
  208111. 0x23, 0x1f, 0x12, 0x23, 0x1f, 0x12, 0,
  208112. 19, 0
  208113. };
  208114. int buttonNum = (int) menuButton;
  208115. int i = 0;
  208116. while (i < numElementsInArray (buttonPatterns))
  208117. {
  208118. if (strcmp (cookies, buttonPatterns + i) == 0)
  208119. {
  208120. buttonPressed ((ButtonType) buttonNum, totalValues > 0);
  208121. break;
  208122. }
  208123. i += (int) strlen (buttonPatterns + i) + 1;
  208124. ++buttonNum;
  208125. }
  208126. }
  208127. #endif
  208128. /*** End of inlined file: juce_mac_AppleRemote.mm ***/
  208129. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  208130. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208131. // compiled on its own).
  208132. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  208133. #if JUCE_MAC
  208134. END_JUCE_NAMESPACE
  208135. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  208136. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  208137. {
  208138. CriticalSection* contextLock;
  208139. bool needsUpdate;
  208140. }
  208141. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  208142. - (bool) makeActive;
  208143. - (void) makeInactive;
  208144. - (void) reshape;
  208145. @end
  208146. @implementation ThreadSafeNSOpenGLView
  208147. - (id) initWithFrame: (NSRect) frameRect
  208148. pixelFormat: (NSOpenGLPixelFormat*) format
  208149. {
  208150. contextLock = new CriticalSection();
  208151. self = [super initWithFrame: frameRect pixelFormat: format];
  208152. if (self != nil)
  208153. [[NSNotificationCenter defaultCenter] addObserver: self
  208154. selector: @selector (_surfaceNeedsUpdate:)
  208155. name: NSViewGlobalFrameDidChangeNotification
  208156. object: self];
  208157. return self;
  208158. }
  208159. - (void) dealloc
  208160. {
  208161. [[NSNotificationCenter defaultCenter] removeObserver: self];
  208162. delete contextLock;
  208163. [super dealloc];
  208164. }
  208165. - (bool) makeActive
  208166. {
  208167. const ScopedLock sl (*contextLock);
  208168. if ([self openGLContext] == 0)
  208169. return false;
  208170. [[self openGLContext] makeCurrentContext];
  208171. if (needsUpdate)
  208172. {
  208173. [super update];
  208174. needsUpdate = false;
  208175. }
  208176. return true;
  208177. }
  208178. - (void) makeInactive
  208179. {
  208180. const ScopedLock sl (*contextLock);
  208181. [NSOpenGLContext clearCurrentContext];
  208182. }
  208183. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  208184. {
  208185. const ScopedLock sl (*contextLock);
  208186. needsUpdate = true;
  208187. }
  208188. - (void) update
  208189. {
  208190. const ScopedLock sl (*contextLock);
  208191. needsUpdate = true;
  208192. }
  208193. - (void) reshape
  208194. {
  208195. const ScopedLock sl (*contextLock);
  208196. needsUpdate = true;
  208197. }
  208198. @end
  208199. BEGIN_JUCE_NAMESPACE
  208200. class WindowedGLContext : public OpenGLContext
  208201. {
  208202. public:
  208203. WindowedGLContext (Component* const component,
  208204. const OpenGLPixelFormat& pixelFormat_,
  208205. NSOpenGLContext* sharedContext)
  208206. : renderContext (0),
  208207. pixelFormat (pixelFormat_)
  208208. {
  208209. jassert (component != 0);
  208210. NSOpenGLPixelFormatAttribute attribs [64];
  208211. int n = 0;
  208212. attribs[n++] = NSOpenGLPFADoubleBuffer;
  208213. attribs[n++] = NSOpenGLPFAAccelerated;
  208214. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  208215. attribs[n++] = NSOpenGLPFAColorSize;
  208216. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  208217. pixelFormat.greenBits,
  208218. pixelFormat.blueBits);
  208219. attribs[n++] = NSOpenGLPFAAlphaSize;
  208220. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  208221. attribs[n++] = NSOpenGLPFADepthSize;
  208222. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  208223. attribs[n++] = NSOpenGLPFAStencilSize;
  208224. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  208225. attribs[n++] = NSOpenGLPFAAccumSize;
  208226. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  208227. pixelFormat.accumulationBufferGreenBits,
  208228. pixelFormat.accumulationBufferBlueBits,
  208229. pixelFormat.accumulationBufferAlphaBits);
  208230. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  208231. attribs[n++] = NSOpenGLPFASampleBuffers;
  208232. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  208233. attribs[n++] = NSOpenGLPFAClosestPolicy;
  208234. attribs[n++] = NSOpenGLPFANoRecovery;
  208235. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  208236. NSOpenGLPixelFormat* format
  208237. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  208238. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  208239. pixelFormat: format];
  208240. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  208241. shareContext: sharedContext] autorelease];
  208242. const GLint swapInterval = 1;
  208243. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  208244. [view setOpenGLContext: renderContext];
  208245. [renderContext setView: view];
  208246. [format release];
  208247. viewHolder = new NSViewComponentInternal (view, component);
  208248. }
  208249. ~WindowedGLContext()
  208250. {
  208251. makeInactive();
  208252. [renderContext clearDrawable];
  208253. viewHolder = 0;
  208254. }
  208255. bool makeActive() const throw()
  208256. {
  208257. jassert (renderContext != 0);
  208258. [view makeActive];
  208259. return isActive();
  208260. }
  208261. bool makeInactive() const throw()
  208262. {
  208263. [view makeInactive];
  208264. return true;
  208265. }
  208266. bool isActive() const throw()
  208267. {
  208268. return [NSOpenGLContext currentContext] == renderContext;
  208269. }
  208270. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  208271. void* getRawContext() const throw() { return renderContext; }
  208272. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  208273. {
  208274. }
  208275. void swapBuffers()
  208276. {
  208277. [renderContext flushBuffer];
  208278. }
  208279. bool setSwapInterval (const int numFramesPerSwap)
  208280. {
  208281. [renderContext setValues: (const GLint*) &numFramesPerSwap
  208282. forParameter: NSOpenGLCPSwapInterval];
  208283. return true;
  208284. }
  208285. int getSwapInterval() const
  208286. {
  208287. GLint numFrames = 0;
  208288. [renderContext getValues: &numFrames
  208289. forParameter: NSOpenGLCPSwapInterval];
  208290. return numFrames;
  208291. }
  208292. void repaint()
  208293. {
  208294. // we need to invalidate the juce view that holds this gl view, to make it
  208295. // cause a repaint callback
  208296. NSView* v = (NSView*) viewHolder->view;
  208297. NSRect r = [v frame];
  208298. // bit of a bodge here.. if we only invalidate the area of the gl component,
  208299. // it's completely covered by the NSOpenGLView, so the OS throws away the
  208300. // repaint message, thus never causing our paint() callback, and never repainting
  208301. // the comp. So invalidating just a little bit around the edge helps..
  208302. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  208303. }
  208304. void* getNativeWindowHandle() const { return viewHolder->view; }
  208305. juce_UseDebuggingNewOperator
  208306. NSOpenGLContext* renderContext;
  208307. ThreadSafeNSOpenGLView* view;
  208308. private:
  208309. OpenGLPixelFormat pixelFormat;
  208310. ScopedPointer <NSViewComponentInternal> viewHolder;
  208311. WindowedGLContext (const WindowedGLContext&);
  208312. WindowedGLContext& operator= (const WindowedGLContext&);
  208313. };
  208314. OpenGLContext* OpenGLComponent::createContext()
  208315. {
  208316. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this, preferredPixelFormat,
  208317. contextToShareListsWith != 0 ? (NSOpenGLContext*) contextToShareListsWith->getRawContext() : 0));
  208318. return (c->renderContext != 0) ? c.release() : 0;
  208319. }
  208320. void* OpenGLComponent::getNativeWindowHandle() const
  208321. {
  208322. return context != 0 ? static_cast<WindowedGLContext*> (static_cast<OpenGLContext*> (context))->getNativeWindowHandle()
  208323. : 0;
  208324. }
  208325. void juce_glViewport (const int w, const int h)
  208326. {
  208327. glViewport (0, 0, w, h);
  208328. }
  208329. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  208330. OwnedArray <OpenGLPixelFormat>& results)
  208331. {
  208332. /* GLint attribs [64];
  208333. int n = 0;
  208334. attribs[n++] = AGL_RGBA;
  208335. attribs[n++] = AGL_DOUBLEBUFFER;
  208336. attribs[n++] = AGL_ACCELERATED;
  208337. attribs[n++] = AGL_NO_RECOVERY;
  208338. attribs[n++] = AGL_NONE;
  208339. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  208340. while (p != 0)
  208341. {
  208342. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  208343. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  208344. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  208345. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  208346. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  208347. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  208348. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  208349. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  208350. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  208351. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  208352. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  208353. results.add (pf);
  208354. p = aglNextPixelFormat (p);
  208355. }*/
  208356. //jassertfalse //xxx can't see how you do this in cocoa!
  208357. }
  208358. #else
  208359. END_JUCE_NAMESPACE
  208360. @interface JuceGLView : UIView
  208361. {
  208362. }
  208363. + (Class) layerClass;
  208364. @end
  208365. @implementation JuceGLView
  208366. + (Class) layerClass
  208367. {
  208368. return [CAEAGLLayer class];
  208369. }
  208370. @end
  208371. BEGIN_JUCE_NAMESPACE
  208372. class GLESContext : public OpenGLContext
  208373. {
  208374. public:
  208375. GLESContext (UIViewComponentPeer* peer,
  208376. Component* const component_,
  208377. const OpenGLPixelFormat& pixelFormat_,
  208378. const GLESContext* const sharedContext,
  208379. NSUInteger apiType)
  208380. : component (component_), pixelFormat (pixelFormat_), glLayer (0), context (0),
  208381. useDepthBuffer (pixelFormat_.depthBufferBits > 0), frameBufferHandle (0), colorBufferHandle (0),
  208382. depthBufferHandle (0), lastWidth (0), lastHeight (0)
  208383. {
  208384. view = [[JuceGLView alloc] initWithFrame: CGRectMake (0, 0, 64, 64)];
  208385. view.opaque = YES;
  208386. view.hidden = NO;
  208387. view.backgroundColor = [UIColor blackColor];
  208388. view.userInteractionEnabled = NO;
  208389. glLayer = (CAEAGLLayer*) [view layer];
  208390. [peer->view addSubview: view];
  208391. if (sharedContext != 0)
  208392. context = [[EAGLContext alloc] initWithAPI: apiType
  208393. sharegroup: [sharedContext->context sharegroup]];
  208394. else
  208395. context = [[EAGLContext alloc] initWithAPI: apiType];
  208396. createGLBuffers();
  208397. }
  208398. ~GLESContext()
  208399. {
  208400. makeInactive();
  208401. [context release];
  208402. [view removeFromSuperview];
  208403. [view release];
  208404. freeGLBuffers();
  208405. }
  208406. bool makeActive() const throw()
  208407. {
  208408. jassert (context != 0);
  208409. [EAGLContext setCurrentContext: context];
  208410. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  208411. return true;
  208412. }
  208413. void swapBuffers()
  208414. {
  208415. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  208416. [context presentRenderbuffer: GL_RENDERBUFFER_OES];
  208417. }
  208418. bool makeInactive() const throw()
  208419. {
  208420. return [EAGLContext setCurrentContext: nil];
  208421. }
  208422. bool isActive() const throw()
  208423. {
  208424. return [EAGLContext currentContext] == context;
  208425. }
  208426. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  208427. void* getRawContext() const throw() { return (void*) glLayer; }
  208428. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  208429. {
  208430. view.frame = CGRectMake ((CGFloat) x, (CGFloat) y, (CGFloat) w, (CGFloat) h);
  208431. if (lastWidth != w || lastHeight != h)
  208432. {
  208433. lastWidth = w;
  208434. lastHeight = h;
  208435. freeGLBuffers();
  208436. createGLBuffers();
  208437. }
  208438. }
  208439. bool setSwapInterval (const int numFramesPerSwap)
  208440. {
  208441. numFrames = numFramesPerSwap;
  208442. return true;
  208443. }
  208444. int getSwapInterval() const
  208445. {
  208446. return numFrames;
  208447. }
  208448. void repaint()
  208449. {
  208450. }
  208451. void createGLBuffers()
  208452. {
  208453. makeActive();
  208454. glGenFramebuffersOES (1, &frameBufferHandle);
  208455. glGenRenderbuffersOES (1, &colorBufferHandle);
  208456. glGenRenderbuffersOES (1, &depthBufferHandle);
  208457. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  208458. [context renderbufferStorage: GL_RENDERBUFFER_OES fromDrawable: glLayer];
  208459. GLint width, height;
  208460. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &width);
  208461. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &height);
  208462. if (useDepthBuffer)
  208463. {
  208464. glBindRenderbufferOES (GL_RENDERBUFFER_OES, depthBufferHandle);
  208465. glRenderbufferStorageOES (GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, width, height);
  208466. }
  208467. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  208468. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  208469. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorBufferHandle);
  208470. if (useDepthBuffer)
  208471. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthBufferHandle);
  208472. jassert (glCheckFramebufferStatusOES (GL_FRAMEBUFFER_OES) == GL_FRAMEBUFFER_COMPLETE_OES);
  208473. }
  208474. void freeGLBuffers()
  208475. {
  208476. if (frameBufferHandle != 0)
  208477. {
  208478. glDeleteFramebuffersOES (1, &frameBufferHandle);
  208479. frameBufferHandle = 0;
  208480. }
  208481. if (colorBufferHandle != 0)
  208482. {
  208483. glDeleteRenderbuffersOES (1, &colorBufferHandle);
  208484. colorBufferHandle = 0;
  208485. }
  208486. if (depthBufferHandle != 0)
  208487. {
  208488. glDeleteRenderbuffersOES (1, &depthBufferHandle);
  208489. depthBufferHandle = 0;
  208490. }
  208491. }
  208492. juce_UseDebuggingNewOperator
  208493. private:
  208494. Component::SafePointer<Component> component;
  208495. OpenGLPixelFormat pixelFormat;
  208496. JuceGLView* view;
  208497. CAEAGLLayer* glLayer;
  208498. EAGLContext* context;
  208499. bool useDepthBuffer;
  208500. GLuint frameBufferHandle, colorBufferHandle, depthBufferHandle;
  208501. int numFrames;
  208502. int lastWidth, lastHeight;
  208503. GLESContext (const GLESContext&);
  208504. GLESContext& operator= (const GLESContext&);
  208505. };
  208506. OpenGLContext* OpenGLComponent::createContext()
  208507. {
  208508. ScopedAutoReleasePool pool;
  208509. UIViewComponentPeer* peer = dynamic_cast <UIViewComponentPeer*> (getPeer());
  208510. if (peer != 0)
  208511. return new GLESContext (peer, this, preferredPixelFormat,
  208512. dynamic_cast <const GLESContext*> (contextToShareListsWith),
  208513. type == openGLES2 ? kEAGLRenderingAPIOpenGLES2 : kEAGLRenderingAPIOpenGLES1);
  208514. return 0;
  208515. }
  208516. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  208517. OwnedArray <OpenGLPixelFormat>& /*results*/)
  208518. {
  208519. }
  208520. void juce_glViewport (const int w, const int h)
  208521. {
  208522. glViewport (0, 0, w, h);
  208523. }
  208524. #endif
  208525. #endif
  208526. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  208527. /*** Start of inlined file: juce_mac_MainMenu.mm ***/
  208528. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208529. // compiled on its own).
  208530. #if JUCE_INCLUDED_FILE
  208531. class JuceMainMenuHandler;
  208532. END_JUCE_NAMESPACE
  208533. using namespace JUCE_NAMESPACE;
  208534. #define JuceMenuCallback MakeObjCClassName(JuceMenuCallback)
  208535. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208536. @interface JuceMenuCallback : NSObject <NSMenuDelegate>
  208537. #else
  208538. @interface JuceMenuCallback : NSObject
  208539. #endif
  208540. {
  208541. JuceMainMenuHandler* owner;
  208542. }
  208543. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_;
  208544. - (void) dealloc;
  208545. - (void) menuItemInvoked: (id) menu;
  208546. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208547. @end
  208548. BEGIN_JUCE_NAMESPACE
  208549. class JuceMainMenuHandler : private MenuBarModelListener,
  208550. private DeletedAtShutdown
  208551. {
  208552. public:
  208553. static JuceMainMenuHandler* instance;
  208554. JuceMainMenuHandler()
  208555. : currentModel (0),
  208556. lastUpdateTime (0)
  208557. {
  208558. callback = [[JuceMenuCallback alloc] initWithOwner: this];
  208559. }
  208560. ~JuceMainMenuHandler()
  208561. {
  208562. setMenu (0);
  208563. jassert (instance == this);
  208564. instance = 0;
  208565. [callback release];
  208566. }
  208567. void setMenu (MenuBarModel* const newMenuBarModel)
  208568. {
  208569. if (currentModel != newMenuBarModel)
  208570. {
  208571. if (currentModel != 0)
  208572. currentModel->removeListener (this);
  208573. currentModel = newMenuBarModel;
  208574. if (currentModel != 0)
  208575. currentModel->addListener (this);
  208576. menuBarItemsChanged (0);
  208577. }
  208578. }
  208579. void addSubMenu (NSMenu* parent, const PopupMenu& child,
  208580. const String& name, const int menuId, const int tag)
  208581. {
  208582. NSMenuItem* item = [parent addItemWithTitle: juceStringToNS (name)
  208583. action: nil
  208584. keyEquivalent: @""];
  208585. [item setTag: tag];
  208586. NSMenu* sub = createMenu (child, name, menuId, tag);
  208587. [parent setSubmenu: sub forItem: item];
  208588. [sub setAutoenablesItems: false];
  208589. [sub release];
  208590. }
  208591. void updateSubMenu (NSMenuItem* parentItem, const PopupMenu& menuToCopy,
  208592. const String& name, const int menuId, const int tag)
  208593. {
  208594. [parentItem setTag: tag];
  208595. NSMenu* menu = [parentItem submenu];
  208596. [menu setTitle: juceStringToNS (name)];
  208597. while ([menu numberOfItems] > 0)
  208598. [menu removeItemAtIndex: 0];
  208599. PopupMenu::MenuItemIterator iter (menuToCopy);
  208600. while (iter.next())
  208601. addMenuItem (iter, menu, menuId, tag);
  208602. [menu setAutoenablesItems: false];
  208603. [menu update];
  208604. }
  208605. void menuBarItemsChanged (MenuBarModel*)
  208606. {
  208607. lastUpdateTime = Time::getMillisecondCounter();
  208608. StringArray menuNames;
  208609. if (currentModel != 0)
  208610. menuNames = currentModel->getMenuBarNames();
  208611. NSMenu* menuBar = [NSApp mainMenu];
  208612. while ([menuBar numberOfItems] > 1 + menuNames.size())
  208613. [menuBar removeItemAtIndex: [menuBar numberOfItems] - 1];
  208614. int menuId = 1;
  208615. for (int i = 0; i < menuNames.size(); ++i)
  208616. {
  208617. const PopupMenu menu (currentModel->getMenuForIndex (i, menuNames [i]));
  208618. if (i >= [menuBar numberOfItems] - 1)
  208619. addSubMenu (menuBar, menu, menuNames[i], menuId, i);
  208620. else
  208621. updateSubMenu ([menuBar itemAtIndex: 1 + i], menu, menuNames[i], menuId, i);
  208622. }
  208623. }
  208624. static void flashMenuBar (NSMenu* menu)
  208625. {
  208626. if ([[menu title] isEqualToString: @"Apple"])
  208627. return;
  208628. [menu retain];
  208629. const unichar f35Key = NSF35FunctionKey;
  208630. NSString* f35String = [NSString stringWithCharacters: &f35Key length: 1];
  208631. NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"x"
  208632. action: nil
  208633. keyEquivalent: f35String];
  208634. [item setTarget: nil];
  208635. [menu insertItem: item atIndex: [menu numberOfItems]];
  208636. [item release];
  208637. if ([menu indexOfItem: item] >= 0)
  208638. {
  208639. NSEvent* f35Event = [NSEvent keyEventWithType: NSKeyDown
  208640. location: NSZeroPoint
  208641. modifierFlags: NSCommandKeyMask
  208642. timestamp: 0
  208643. windowNumber: 0
  208644. context: [NSGraphicsContext currentContext]
  208645. characters: f35String
  208646. charactersIgnoringModifiers: f35String
  208647. isARepeat: NO
  208648. keyCode: 0];
  208649. [menu performKeyEquivalent: f35Event];
  208650. [menu removeItem: item]; // (this throws if the item isn't actually in the menu)
  208651. }
  208652. [menu release];
  208653. }
  208654. static NSMenuItem* findMenuItem (NSMenu* const menu, const ApplicationCommandTarget::InvocationInfo& info)
  208655. {
  208656. for (NSInteger i = [menu numberOfItems]; --i >= 0;)
  208657. {
  208658. NSMenuItem* m = [menu itemAtIndex: i];
  208659. if ([m tag] == info.commandID)
  208660. return m;
  208661. if ([m submenu] != 0)
  208662. {
  208663. NSMenuItem* found = findMenuItem ([m submenu], info);
  208664. if (found != 0)
  208665. return found;
  208666. }
  208667. }
  208668. return 0;
  208669. }
  208670. void menuCommandInvoked (MenuBarModel*, const ApplicationCommandTarget::InvocationInfo& info)
  208671. {
  208672. NSMenuItem* item = findMenuItem ([NSApp mainMenu], info);
  208673. if (item != 0)
  208674. flashMenuBar ([item menu]);
  208675. }
  208676. void updateMenus()
  208677. {
  208678. if (Time::getMillisecondCounter() > lastUpdateTime + 500)
  208679. menuBarItemsChanged (0);
  208680. }
  208681. void invoke (const int commandId, ApplicationCommandManager* const commandManager, const int topLevelIndex) const
  208682. {
  208683. if (currentModel != 0)
  208684. {
  208685. if (commandManager != 0)
  208686. {
  208687. ApplicationCommandTarget::InvocationInfo info (commandId);
  208688. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  208689. commandManager->invoke (info, true);
  208690. }
  208691. currentModel->menuItemSelected (commandId, topLevelIndex);
  208692. }
  208693. }
  208694. MenuBarModel* currentModel;
  208695. uint32 lastUpdateTime;
  208696. void addMenuItem (PopupMenu::MenuItemIterator& iter, NSMenu* menuToAddTo,
  208697. const int topLevelMenuId, const int topLevelIndex)
  208698. {
  208699. NSString* text = juceStringToNS (iter.itemName.upToFirstOccurrenceOf (T("<end>"), false, true));
  208700. if (text == 0)
  208701. text = @"";
  208702. if (iter.isSeparator)
  208703. {
  208704. [menuToAddTo addItem: [NSMenuItem separatorItem]];
  208705. }
  208706. else if (iter.isSectionHeader)
  208707. {
  208708. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208709. action: nil
  208710. keyEquivalent: @""];
  208711. [item setEnabled: false];
  208712. }
  208713. else if (iter.subMenu != 0)
  208714. {
  208715. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208716. action: nil
  208717. keyEquivalent: @""];
  208718. [item setTag: iter.itemId];
  208719. [item setEnabled: iter.isEnabled];
  208720. NSMenu* sub = createMenu (*iter.subMenu, iter.itemName, topLevelMenuId, topLevelIndex);
  208721. [sub setDelegate: nil];
  208722. [menuToAddTo setSubmenu: sub forItem: item];
  208723. [sub release];
  208724. }
  208725. else
  208726. {
  208727. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208728. action: @selector (menuItemInvoked:)
  208729. keyEquivalent: @""];
  208730. [item setTag: iter.itemId];
  208731. [item setEnabled: iter.isEnabled];
  208732. [item setState: iter.isTicked ? NSOnState : NSOffState];
  208733. [item setTarget: (id) callback];
  208734. NSMutableArray* info = [NSMutableArray arrayWithObject: [NSNumber numberWithUnsignedLongLong: (pointer_sized_int) (void*) iter.commandManager]];
  208735. [info addObject: [NSNumber numberWithInt: topLevelIndex]];
  208736. [item setRepresentedObject: info];
  208737. if (iter.commandManager != 0)
  208738. {
  208739. const Array <KeyPress> keyPresses (iter.commandManager->getKeyMappings()
  208740. ->getKeyPressesAssignedToCommand (iter.itemId));
  208741. if (keyPresses.size() > 0)
  208742. {
  208743. const KeyPress& kp = keyPresses.getReference(0);
  208744. juce_wchar key = kp.getTextCharacter();
  208745. if (kp.getKeyCode() == KeyPress::backspaceKey)
  208746. key = NSBackspaceCharacter;
  208747. else if (kp.getKeyCode() == KeyPress::deleteKey)
  208748. key = NSDeleteCharacter;
  208749. else if (key == 0)
  208750. key = (juce_wchar) kp.getKeyCode();
  208751. unsigned int mods = 0;
  208752. if (kp.getModifiers().isShiftDown())
  208753. mods |= NSShiftKeyMask;
  208754. if (kp.getModifiers().isCtrlDown())
  208755. mods |= NSControlKeyMask;
  208756. if (kp.getModifiers().isAltDown())
  208757. mods |= NSAlternateKeyMask;
  208758. if (kp.getModifiers().isCommandDown())
  208759. mods |= NSCommandKeyMask;
  208760. [item setKeyEquivalent: juceStringToNS (String::charToString (key))];
  208761. [item setKeyEquivalentModifierMask: mods];
  208762. }
  208763. }
  208764. }
  208765. }
  208766. JuceMenuCallback* callback;
  208767. private:
  208768. NSMenu* createMenu (const PopupMenu menu,
  208769. const String& menuName,
  208770. const int topLevelMenuId,
  208771. const int topLevelIndex)
  208772. {
  208773. NSMenu* m = [[NSMenu alloc] initWithTitle: juceStringToNS (menuName)];
  208774. [m setAutoenablesItems: false];
  208775. [m setDelegate: callback];
  208776. PopupMenu::MenuItemIterator iter (menu);
  208777. while (iter.next())
  208778. addMenuItem (iter, m, topLevelMenuId, topLevelIndex);
  208779. [m update];
  208780. return m;
  208781. }
  208782. };
  208783. JuceMainMenuHandler* JuceMainMenuHandler::instance = 0;
  208784. END_JUCE_NAMESPACE
  208785. @implementation JuceMenuCallback
  208786. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_
  208787. {
  208788. [super init];
  208789. owner = owner_;
  208790. return self;
  208791. }
  208792. - (void) dealloc
  208793. {
  208794. [super dealloc];
  208795. }
  208796. - (void) menuItemInvoked: (id) menu
  208797. {
  208798. NSMenuItem* item = (NSMenuItem*) menu;
  208799. if ([[item representedObject] isKindOfClass: [NSArray class]])
  208800. {
  208801. // 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
  208802. // our own components, which may have wanted to intercept it. So, rather than dispatching directly, we'll feed it back
  208803. // into the focused component and let it trigger the menu item indirectly.
  208804. NSEvent* e = [NSApp currentEvent];
  208805. if ([e type] == NSKeyDown || [e type] == NSKeyUp)
  208806. {
  208807. if (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent() != 0)
  208808. {
  208809. JUCE_NAMESPACE::NSViewComponentPeer* peer = dynamic_cast <JUCE_NAMESPACE::NSViewComponentPeer*> (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->getPeer());
  208810. if (peer != 0)
  208811. {
  208812. if ([e type] == NSKeyDown)
  208813. peer->redirectKeyDown (e);
  208814. else
  208815. peer->redirectKeyUp (e);
  208816. return;
  208817. }
  208818. }
  208819. }
  208820. NSArray* info = (NSArray*) [item representedObject];
  208821. owner->invoke ((int) [item tag],
  208822. (ApplicationCommandManager*) (pointer_sized_int)
  208823. [((NSNumber*) [info objectAtIndex: 0]) unsignedLongLongValue],
  208824. (int) [((NSNumber*) [info objectAtIndex: 1]) intValue]);
  208825. }
  208826. }
  208827. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208828. {
  208829. if (JuceMainMenuHandler::instance != 0)
  208830. JuceMainMenuHandler::instance->updateMenus();
  208831. }
  208832. @end
  208833. BEGIN_JUCE_NAMESPACE
  208834. static NSMenu* createStandardAppMenu (NSMenu* menu, const String& appName,
  208835. const PopupMenu* extraItems)
  208836. {
  208837. if (extraItems != 0 && JuceMainMenuHandler::instance != 0 && extraItems->getNumItems() > 0)
  208838. {
  208839. PopupMenu::MenuItemIterator iter (*extraItems);
  208840. while (iter.next())
  208841. JuceMainMenuHandler::instance->addMenuItem (iter, menu, 0, -1);
  208842. [menu addItem: [NSMenuItem separatorItem]];
  208843. }
  208844. NSMenuItem* item;
  208845. // Services...
  208846. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Services", nil)
  208847. action: nil keyEquivalent: @""];
  208848. [menu addItem: item];
  208849. [item release];
  208850. NSMenu* servicesMenu = [[NSMenu alloc] initWithTitle: @"Services"];
  208851. [menu setSubmenu: servicesMenu forItem: item];
  208852. [NSApp setServicesMenu: servicesMenu];
  208853. [servicesMenu release];
  208854. [menu addItem: [NSMenuItem separatorItem]];
  208855. // Hide + Show stuff...
  208856. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Hide " + appName)
  208857. action: @selector (hide:) keyEquivalent: @"h"];
  208858. [item setTarget: NSApp];
  208859. [menu addItem: item];
  208860. [item release];
  208861. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Hide Others", nil)
  208862. action: @selector (hideOtherApplications:) keyEquivalent: @"h"];
  208863. [item setKeyEquivalentModifierMask: NSCommandKeyMask | NSAlternateKeyMask];
  208864. [item setTarget: NSApp];
  208865. [menu addItem: item];
  208866. [item release];
  208867. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Show All", nil)
  208868. action: @selector (unhideAllApplications:) keyEquivalent: @""];
  208869. [item setTarget: NSApp];
  208870. [menu addItem: item];
  208871. [item release];
  208872. [menu addItem: [NSMenuItem separatorItem]];
  208873. // Quit item....
  208874. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Quit " + appName)
  208875. action: @selector (terminate:) keyEquivalent: @"q"];
  208876. [item setTarget: NSApp];
  208877. [menu addItem: item];
  208878. [item release];
  208879. return menu;
  208880. }
  208881. // Since our app has no NIB, this initialises a standard app menu...
  208882. static void rebuildMainMenu (const PopupMenu* extraItems)
  208883. {
  208884. // this can't be used in a plugin!
  208885. jassert (JUCEApplication::getInstance() != 0);
  208886. if (JUCEApplication::getInstance() != 0)
  208887. {
  208888. const ScopedAutoReleasePool pool;
  208889. NSMenu* mainMenu = [[NSMenu alloc] initWithTitle: @"MainMenu"];
  208890. NSMenuItem* item = [mainMenu addItemWithTitle: @"Apple" action: nil keyEquivalent: @""];
  208891. NSMenu* appMenu = [[NSMenu alloc] initWithTitle: @"Apple"];
  208892. [NSApp performSelector: @selector (setAppleMenu:) withObject: appMenu];
  208893. [mainMenu setSubmenu: appMenu forItem: item];
  208894. [NSApp setMainMenu: mainMenu];
  208895. createStandardAppMenu (appMenu, JUCEApplication::getInstance()->getApplicationName(), extraItems);
  208896. [appMenu release];
  208897. [mainMenu release];
  208898. }
  208899. }
  208900. void MenuBarModel::setMacMainMenu (MenuBarModel* newMenuBarModel,
  208901. const PopupMenu* extraAppleMenuItems)
  208902. {
  208903. if (getMacMainMenu() != newMenuBarModel)
  208904. {
  208905. const ScopedAutoReleasePool pool;
  208906. if (newMenuBarModel == 0)
  208907. {
  208908. delete JuceMainMenuHandler::instance;
  208909. jassert (JuceMainMenuHandler::instance == 0); // should be zeroed in the destructor
  208910. jassert (extraAppleMenuItems == 0); // you can't specify some extra items without also supplying a model
  208911. extraAppleMenuItems = 0;
  208912. }
  208913. else
  208914. {
  208915. if (JuceMainMenuHandler::instance == 0)
  208916. JuceMainMenuHandler::instance = new JuceMainMenuHandler();
  208917. JuceMainMenuHandler::instance->setMenu (newMenuBarModel);
  208918. }
  208919. }
  208920. rebuildMainMenu (extraAppleMenuItems);
  208921. if (newMenuBarModel != 0)
  208922. newMenuBarModel->menuItemsChanged();
  208923. }
  208924. MenuBarModel* MenuBarModel::getMacMainMenu()
  208925. {
  208926. return JuceMainMenuHandler::instance != 0
  208927. ? JuceMainMenuHandler::instance->currentModel : 0;
  208928. }
  208929. void initialiseMainMenu()
  208930. {
  208931. if (JUCEApplication::getInstance() != 0) // only needed in an app
  208932. rebuildMainMenu (0);
  208933. }
  208934. #endif
  208935. /*** End of inlined file: juce_mac_MainMenu.mm ***/
  208936. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  208937. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208938. // compiled on its own).
  208939. #if JUCE_INCLUDED_FILE
  208940. #if JUCE_MAC
  208941. END_JUCE_NAMESPACE
  208942. using namespace JUCE_NAMESPACE;
  208943. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  208944. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208945. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  208946. #else
  208947. @interface JuceFileChooserDelegate : NSObject
  208948. #endif
  208949. {
  208950. StringArray* filters;
  208951. }
  208952. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  208953. - (void) dealloc;
  208954. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  208955. @end
  208956. @implementation JuceFileChooserDelegate
  208957. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  208958. {
  208959. [super init];
  208960. filters = filters_;
  208961. return self;
  208962. }
  208963. - (void) dealloc
  208964. {
  208965. delete filters;
  208966. [super dealloc];
  208967. }
  208968. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  208969. {
  208970. const File f (nsStringToJuce (filename));
  208971. for (int i = filters->size(); --i >= 0;)
  208972. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  208973. return true;
  208974. return f.isDirectory();
  208975. }
  208976. @end
  208977. BEGIN_JUCE_NAMESPACE
  208978. void FileChooser::showPlatformDialog (Array<File>& results,
  208979. const String& title,
  208980. const File& currentFileOrDirectory,
  208981. const String& filter,
  208982. bool selectsDirectory,
  208983. bool selectsFiles,
  208984. bool isSaveDialogue,
  208985. bool warnAboutOverwritingExistingFiles,
  208986. bool selectMultipleFiles,
  208987. FilePreviewComponent* extraInfoComponent)
  208988. {
  208989. const ScopedAutoReleasePool pool;
  208990. StringArray* filters = new StringArray();
  208991. filters->addTokens (filter.replaceCharacters (T(",:"), T(";;")), T(";"), String::empty);
  208992. filters->trim();
  208993. filters->removeEmptyStrings();
  208994. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  208995. [delegate autorelease];
  208996. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  208997. : [NSOpenPanel openPanel];
  208998. [panel setTitle: juceStringToNS (title)];
  208999. if (! isSaveDialogue)
  209000. {
  209001. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  209002. [openPanel setCanChooseDirectories: selectsDirectory];
  209003. [openPanel setCanChooseFiles: selectsFiles];
  209004. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  209005. }
  209006. [panel setDelegate: delegate];
  209007. if (isSaveDialogue || selectsDirectory)
  209008. [panel setCanCreateDirectories: YES];
  209009. String directory, filename;
  209010. if (currentFileOrDirectory.isDirectory())
  209011. {
  209012. directory = currentFileOrDirectory.getFullPathName();
  209013. }
  209014. else
  209015. {
  209016. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  209017. filename = currentFileOrDirectory.getFileName();
  209018. }
  209019. if ([panel runModalForDirectory: juceStringToNS (directory)
  209020. file: juceStringToNS (filename)]
  209021. == NSOKButton)
  209022. {
  209023. if (isSaveDialogue)
  209024. {
  209025. results.add (File (nsStringToJuce ([panel filename])));
  209026. }
  209027. else
  209028. {
  209029. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  209030. NSArray* urls = [openPanel filenames];
  209031. for (unsigned int i = 0; i < [urls count]; ++i)
  209032. {
  209033. NSString* f = [urls objectAtIndex: i];
  209034. results.add (File (nsStringToJuce (f)));
  209035. }
  209036. }
  209037. }
  209038. [panel setDelegate: nil];
  209039. }
  209040. #else
  209041. void FileChooser::showPlatformDialog (Array<File>& results,
  209042. const String& title,
  209043. const File& currentFileOrDirectory,
  209044. const String& filter,
  209045. bool selectsDirectory,
  209046. bool selectsFiles,
  209047. bool isSaveDialogue,
  209048. bool warnAboutOverwritingExistingFiles,
  209049. bool selectMultipleFiles,
  209050. FilePreviewComponent* extraInfoComponent)
  209051. {
  209052. const ScopedAutoReleasePool pool;
  209053. jassertfalse //xxx to do
  209054. }
  209055. #endif
  209056. #endif
  209057. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  209058. /*** Start of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  209059. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209060. // compiled on its own).
  209061. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  209062. END_JUCE_NAMESPACE
  209063. #define NonInterceptingQTMovieView MakeObjCClassName(NonInterceptingQTMovieView)
  209064. @interface NonInterceptingQTMovieView : QTMovieView
  209065. {
  209066. }
  209067. - (id) initWithFrame: (NSRect) frame;
  209068. - (BOOL) acceptsFirstMouse: (NSEvent*) theEvent;
  209069. - (NSView*) hitTest: (NSPoint) p;
  209070. @end
  209071. @implementation NonInterceptingQTMovieView
  209072. - (id) initWithFrame: (NSRect) frame
  209073. {
  209074. self = [super initWithFrame: frame];
  209075. [self setNextResponder: [self superview]];
  209076. return self;
  209077. }
  209078. - (void) dealloc
  209079. {
  209080. [super dealloc];
  209081. }
  209082. - (NSView*) hitTest: (NSPoint) point
  209083. {
  209084. return [self isControllerVisible] ? [super hitTest: point] : nil;
  209085. }
  209086. - (BOOL) acceptsFirstMouse: (NSEvent*) theEvent
  209087. {
  209088. return YES;
  209089. }
  209090. @end
  209091. BEGIN_JUCE_NAMESPACE
  209092. #define theMovie (static_cast <QTMovie*> (movie))
  209093. QuickTimeMovieComponent::QuickTimeMovieComponent()
  209094. : movie (0)
  209095. {
  209096. setOpaque (true);
  209097. setVisible (true);
  209098. QTMovieView* view = [[NonInterceptingQTMovieView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)];
  209099. setView (view);
  209100. [view release];
  209101. }
  209102. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  209103. {
  209104. closeMovie();
  209105. setView (0);
  209106. }
  209107. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  209108. {
  209109. return true;
  209110. }
  209111. static QTMovie* openMovieFromStream (InputStream* movieStream, File& movieFile)
  209112. {
  209113. // unfortunately, QTMovie objects can only be created on the main thread..
  209114. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  209115. QTMovie* movie = 0;
  209116. FileInputStream* const fin = dynamic_cast <FileInputStream*> (movieStream);
  209117. if (fin != 0)
  209118. {
  209119. movieFile = fin->getFile();
  209120. movie = [QTMovie movieWithFile: juceStringToNS (movieFile.getFullPathName())
  209121. error: nil];
  209122. }
  209123. else
  209124. {
  209125. MemoryBlock temp;
  209126. movieStream->readIntoMemoryBlock (temp);
  209127. const char* const suffixesToTry[] = { ".mov", ".mp3", ".avi", ".m4a" };
  209128. for (int i = 0; i < numElementsInArray (suffixesToTry); ++i)
  209129. {
  209130. movie = [QTMovie movieWithDataReference: [QTDataReference dataReferenceWithReferenceToData: [NSData dataWithBytes: temp.getData()
  209131. length: temp.getSize()]
  209132. name: [NSString stringWithUTF8String: suffixesToTry[i]]
  209133. MIMEType: @""]
  209134. error: nil];
  209135. if (movie != 0)
  209136. break;
  209137. }
  209138. }
  209139. return movie;
  209140. }
  209141. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  209142. const bool isControllerVisible_)
  209143. {
  209144. return loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible_);
  209145. }
  209146. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  209147. const bool controllerVisible_)
  209148. {
  209149. closeMovie();
  209150. if (getPeer() == 0)
  209151. {
  209152. // To open a movie, this component must be visible inside a functioning window, so that
  209153. // the QT control can be assigned to the window.
  209154. jassertfalse
  209155. return false;
  209156. }
  209157. movie = openMovieFromStream (movieStream, movieFile);
  209158. [theMovie retain];
  209159. QTMovieView* view = (QTMovieView*) getView();
  209160. [view setMovie: theMovie];
  209161. [view setControllerVisible: controllerVisible_];
  209162. setLooping (looping);
  209163. return movie != nil;
  209164. }
  209165. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  209166. const bool isControllerVisible_)
  209167. {
  209168. // unfortunately, QTMovie objects can only be created on the main thread..
  209169. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  209170. closeMovie();
  209171. if (getPeer() == 0)
  209172. {
  209173. // To open a movie, this component must be visible inside a functioning window, so that
  209174. // the QT control can be assigned to the window.
  209175. jassertfalse
  209176. return false;
  209177. }
  209178. NSURL* url = [NSURL URLWithString: juceStringToNS (movieURL.toString (true))];
  209179. NSError* err;
  209180. if ([QTMovie canInitWithURL: url])
  209181. movie = [QTMovie movieWithURL: url error: &err];
  209182. [theMovie retain];
  209183. QTMovieView* view = (QTMovieView*) getView();
  209184. [view setMovie: theMovie];
  209185. [view setControllerVisible: controllerVisible];
  209186. setLooping (looping);
  209187. return movie != nil;
  209188. }
  209189. void QuickTimeMovieComponent::closeMovie()
  209190. {
  209191. stop();
  209192. QTMovieView* view = (QTMovieView*) getView();
  209193. [view setMovie: nil];
  209194. [theMovie release];
  209195. movie = 0;
  209196. movieFile = File::nonexistent;
  209197. }
  209198. bool QuickTimeMovieComponent::isMovieOpen() const
  209199. {
  209200. return movie != nil;
  209201. }
  209202. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  209203. {
  209204. return movieFile;
  209205. }
  209206. void QuickTimeMovieComponent::play()
  209207. {
  209208. [theMovie play];
  209209. }
  209210. void QuickTimeMovieComponent::stop()
  209211. {
  209212. [theMovie stop];
  209213. }
  209214. bool QuickTimeMovieComponent::isPlaying() const
  209215. {
  209216. return movie != 0 && [theMovie rate] != 0;
  209217. }
  209218. void QuickTimeMovieComponent::setPosition (const double seconds)
  209219. {
  209220. if (movie != 0)
  209221. {
  209222. QTTime t;
  209223. t.timeValue = (uint64) (100000.0 * seconds);
  209224. t.timeScale = 100000;
  209225. t.flags = 0;
  209226. [theMovie setCurrentTime: t];
  209227. }
  209228. }
  209229. double QuickTimeMovieComponent::getPosition() const
  209230. {
  209231. if (movie == 0)
  209232. return 0.0;
  209233. QTTime t = [theMovie currentTime];
  209234. return t.timeValue / (double) t.timeScale;
  209235. }
  209236. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  209237. {
  209238. [theMovie setRate: newSpeed];
  209239. }
  209240. double QuickTimeMovieComponent::getMovieDuration() const
  209241. {
  209242. if (movie == 0)
  209243. return 0.0;
  209244. QTTime t = [theMovie duration];
  209245. return t.timeValue / (double) t.timeScale;
  209246. }
  209247. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  209248. {
  209249. looping = shouldLoop;
  209250. [theMovie setAttribute: [NSNumber numberWithBool: shouldLoop]
  209251. forKey: QTMovieLoopsAttribute];
  209252. }
  209253. bool QuickTimeMovieComponent::isLooping() const
  209254. {
  209255. return looping;
  209256. }
  209257. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  209258. {
  209259. [theMovie setVolume: newVolume];
  209260. }
  209261. float QuickTimeMovieComponent::getMovieVolume() const
  209262. {
  209263. return movie != 0 ? [theMovie volume] : 0.0f;
  209264. }
  209265. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  209266. {
  209267. width = 0;
  209268. height = 0;
  209269. if (movie != 0)
  209270. {
  209271. NSSize s = [[theMovie attributeForKey: QTMovieNaturalSizeAttribute] sizeValue];
  209272. width = (int) s.width;
  209273. height = (int) s.height;
  209274. }
  209275. }
  209276. void QuickTimeMovieComponent::paint (Graphics& g)
  209277. {
  209278. if (movie == 0)
  209279. g.fillAll (Colours::black);
  209280. }
  209281. bool QuickTimeMovieComponent::isControllerVisible() const
  209282. {
  209283. return controllerVisible;
  209284. }
  209285. void QuickTimeMovieComponent::goToStart()
  209286. {
  209287. setPosition (0.0);
  209288. }
  209289. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  209290. const RectanglePlacement& placement)
  209291. {
  209292. int normalWidth, normalHeight;
  209293. getMovieNormalSize (normalWidth, normalHeight);
  209294. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  209295. {
  209296. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  209297. placement.applyTo (x, y, w, h,
  209298. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  209299. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  209300. if (w > 0 && h > 0)
  209301. {
  209302. setBounds (roundToInt (x), roundToInt (y),
  209303. roundToInt (w), roundToInt (h));
  209304. }
  209305. }
  209306. else
  209307. {
  209308. setBounds (spaceToFitWithin);
  209309. }
  209310. }
  209311. #if ! (JUCE_MAC && JUCE_64BIT)
  209312. bool juce_OpenQuickTimeMovieFromStream (InputStream* movieStream, Movie& result, Handle& dataHandle)
  209313. {
  209314. if (movieStream == 0)
  209315. return false;
  209316. File file;
  209317. QTMovie* movie = openMovieFromStream (movieStream, file);
  209318. if (movie != nil)
  209319. result = [movie quickTimeMovie];
  209320. return movie != nil;
  209321. }
  209322. #endif
  209323. #endif
  209324. /*** End of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  209325. /*** Start of inlined file: juce_mac_AudioCDBurner.mm ***/
  209326. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209327. // compiled on its own).
  209328. #if JUCE_INCLUDED_FILE && JUCE_USE_CDBURNER
  209329. const int kilobytesPerSecond1x = 176;
  209330. END_JUCE_NAMESPACE
  209331. #define OpenDiskDevice MakeObjCClassName(OpenDiskDevice)
  209332. @interface OpenDiskDevice : NSObject
  209333. {
  209334. @public
  209335. DRDevice* device;
  209336. NSMutableArray* tracks;
  209337. bool underrunProtection;
  209338. }
  209339. - (OpenDiskDevice*) initWithDRDevice: (DRDevice*) device;
  209340. - (void) dealloc;
  209341. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) numSamples_;
  209342. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209343. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting speed: (int) burnSpeed;
  209344. @end
  209345. #define AudioTrackProducer MakeObjCClassName(AudioTrackProducer)
  209346. @interface AudioTrackProducer : NSObject
  209347. {
  209348. JUCE_NAMESPACE::AudioSource* source;
  209349. int readPosition, lengthInFrames;
  209350. }
  209351. - (AudioTrackProducer*) init: (int) lengthInFrames;
  209352. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) lengthInSamples;
  209353. - (void) dealloc;
  209354. - (void) setupTrackProperties: (DRTrack*) track;
  209355. - (void) cleanupTrackAfterBurn: (DRTrack*) track;
  209356. - (BOOL) cleanupTrackAfterVerification:(DRTrack*)track;
  209357. - (uint64_t) estimateLengthOfTrack:(DRTrack*)track;
  209358. - (BOOL) prepareTrack:(DRTrack*)track forBurn:(DRBurn*)burn
  209359. toMedia:(NSDictionary*)mediaInfo;
  209360. - (BOOL) prepareTrackForVerification:(DRTrack*)track;
  209361. - (uint32_t) produceDataForTrack:(DRTrack*)track intoBuffer:(char*)buffer
  209362. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209363. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209364. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209365. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209366. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209367. ioFlags:(uint32_t*)flags;
  209368. - (BOOL) verifyDataForTrack:(DRTrack*)track inBuffer:(const char*)buffer
  209369. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209370. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209371. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209372. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209373. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209374. ioFlags:(uint32_t*)flags;
  209375. @end
  209376. @implementation OpenDiskDevice
  209377. - (OpenDiskDevice*) initWithDRDevice: (DRDevice*) device_
  209378. {
  209379. [super init];
  209380. device = device_;
  209381. tracks = [[NSMutableArray alloc] init];
  209382. underrunProtection = true;
  209383. return self;
  209384. }
  209385. - (void) dealloc
  209386. {
  209387. [tracks release];
  209388. [super dealloc];
  209389. }
  209390. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) numSamples_
  209391. {
  209392. AudioTrackProducer* p = [[AudioTrackProducer alloc] initWithAudioSource: source_ numSamples: numSamples_];
  209393. DRTrack* t = [[DRTrack alloc] initWithProducer: p];
  209394. [p setupTrackProperties: t];
  209395. [tracks addObject: t];
  209396. [t release];
  209397. [p release];
  209398. }
  209399. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209400. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting speed: (int) burnSpeed
  209401. {
  209402. DRBurn* burn = [DRBurn burnForDevice: device];
  209403. if (! [device acquireExclusiveAccess])
  209404. {
  209405. *error = "Couldn't open or write to the CD device";
  209406. return;
  209407. }
  209408. [device acquireMediaReservation];
  209409. NSMutableDictionary* d = [[burn properties] mutableCopy];
  209410. [d autorelease];
  209411. [d setObject: [NSNumber numberWithBool: peformFakeBurnForTesting] forKey: DRBurnTestingKey];
  209412. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnVerifyDiscKey];
  209413. [d setObject: (shouldEject ? DRBurnCompletionActionEject : DRBurnCompletionActionMount) forKey: DRBurnCompletionActionKey];
  209414. if (burnSpeed > 0)
  209415. [d setObject: [NSNumber numberWithFloat: burnSpeed * JUCE_NAMESPACE::kilobytesPerSecond1x] forKey: DRBurnRequestedSpeedKey];
  209416. if (! underrunProtection)
  209417. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnUnderrunProtectionKey];
  209418. [burn setProperties: d];
  209419. [burn writeLayout: tracks];
  209420. for (;;)
  209421. {
  209422. JUCE_NAMESPACE::Thread::sleep (300);
  209423. float progress = [[[burn status] objectForKey: DRStatusPercentCompleteKey] floatValue];
  209424. if (listener != 0 && listener->audioCDBurnProgress (progress))
  209425. {
  209426. [burn abort];
  209427. *error = "User cancelled the write operation";
  209428. break;
  209429. }
  209430. if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateFailed])
  209431. {
  209432. *error = "Write operation failed";
  209433. break;
  209434. }
  209435. else if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateDone])
  209436. {
  209437. break;
  209438. }
  209439. NSString* err = (NSString*) [[[burn status] objectForKey: DRErrorStatusKey]
  209440. objectForKey: DRErrorStatusErrorStringKey];
  209441. if ([err length] > 0)
  209442. {
  209443. *error = JUCE_NAMESPACE::String::fromUTF8 ([err UTF8String]);
  209444. break;
  209445. }
  209446. }
  209447. [device releaseMediaReservation];
  209448. [device releaseExclusiveAccess];
  209449. }
  209450. @end
  209451. @implementation AudioTrackProducer
  209452. - (AudioTrackProducer*) init: (int) lengthInFrames_
  209453. {
  209454. lengthInFrames = lengthInFrames_;
  209455. readPosition = 0;
  209456. return self;
  209457. }
  209458. - (void) setupTrackProperties: (DRTrack*) track
  209459. {
  209460. NSMutableDictionary* p = [[track properties] mutableCopy];
  209461. [p setObject:[DRMSF msfWithFrames: lengthInFrames] forKey: DRTrackLengthKey];
  209462. [p setObject:[NSNumber numberWithUnsignedShort:2352] forKey: DRBlockSizeKey];
  209463. [p setObject:[NSNumber numberWithInt:0] forKey: DRDataFormKey];
  209464. [p setObject:[NSNumber numberWithInt:0] forKey: DRBlockTypeKey];
  209465. [p setObject:[NSNumber numberWithInt:0] forKey: DRTrackModeKey];
  209466. [p setObject:[NSNumber numberWithInt:0] forKey: DRSessionFormatKey];
  209467. [track setProperties: p];
  209468. [p release];
  209469. }
  209470. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) lengthInSamples
  209471. {
  209472. AudioTrackProducer* s = [self init: (lengthInSamples + 587) / 588];
  209473. if (s != nil)
  209474. s->source = source_;
  209475. return s;
  209476. }
  209477. - (void) dealloc
  209478. {
  209479. if (source != 0)
  209480. {
  209481. source->releaseResources();
  209482. delete source;
  209483. }
  209484. [super dealloc];
  209485. }
  209486. - (void) cleanupTrackAfterBurn: (DRTrack*) track
  209487. {
  209488. }
  209489. - (BOOL) cleanupTrackAfterVerification: (DRTrack*) track
  209490. {
  209491. return true;
  209492. }
  209493. - (uint64_t) estimateLengthOfTrack: (DRTrack*) track
  209494. {
  209495. return lengthInFrames;
  209496. }
  209497. - (BOOL) prepareTrack: (DRTrack*) track forBurn: (DRBurn*) burn
  209498. toMedia: (NSDictionary*) mediaInfo
  209499. {
  209500. if (source != 0)
  209501. source->prepareToPlay (44100 / 75, 44100);
  209502. readPosition = 0;
  209503. return true;
  209504. }
  209505. - (BOOL) prepareTrackForVerification: (DRTrack*) track
  209506. {
  209507. if (source != 0)
  209508. source->prepareToPlay (44100 / 75, 44100);
  209509. return true;
  209510. }
  209511. - (uint32_t) produceDataForTrack: (DRTrack*) track intoBuffer: (char*) buffer
  209512. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209513. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209514. {
  209515. if (source != 0)
  209516. {
  209517. const int numSamples = JUCE_NAMESPACE::jmin ((int) bufferLength / 4, (lengthInFrames * (44100 / 75)) - readPosition);
  209518. if (numSamples > 0)
  209519. {
  209520. JUCE_NAMESPACE::AudioSampleBuffer tempBuffer (2, numSamples);
  209521. JUCE_NAMESPACE::AudioSourceChannelInfo info;
  209522. info.buffer = &tempBuffer;
  209523. info.startSample = 0;
  209524. info.numSamples = numSamples;
  209525. source->getNextAudioBlock (info);
  209526. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (0),
  209527. buffer, numSamples, 4);
  209528. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (1),
  209529. buffer + 2, numSamples, 4);
  209530. readPosition += numSamples;
  209531. }
  209532. return numSamples * 4;
  209533. }
  209534. return 0;
  209535. }
  209536. - (uint32_t) producePreGapForTrack: (DRTrack*) track
  209537. intoBuffer: (char*) buffer length: (uint32_t) bufferLength
  209538. atAddress: (uint64_t) address blockSize: (uint32_t) blockSize
  209539. ioFlags: (uint32_t*) flags
  209540. {
  209541. zeromem (buffer, bufferLength);
  209542. return bufferLength;
  209543. }
  209544. - (BOOL) verifyDataForTrack: (DRTrack*) track inBuffer: (const char*) buffer
  209545. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209546. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209547. {
  209548. return true;
  209549. }
  209550. @end
  209551. BEGIN_JUCE_NAMESPACE
  209552. class AudioCDBurner::Pimpl : public Timer
  209553. {
  209554. public:
  209555. Pimpl (AudioCDBurner& owner_, const int deviceIndex)
  209556. : device (0), owner (owner_)
  209557. {
  209558. DRDevice* dev = [[DRDevice devices] objectAtIndex: deviceIndex];
  209559. if (dev != 0)
  209560. {
  209561. device = [[OpenDiskDevice alloc] initWithDRDevice: dev];
  209562. lastState = getDiskState();
  209563. startTimer (1000);
  209564. }
  209565. }
  209566. ~Pimpl()
  209567. {
  209568. stopTimer();
  209569. [device release];
  209570. }
  209571. void timerCallback()
  209572. {
  209573. const DiskState state = getDiskState();
  209574. if (state != lastState)
  209575. {
  209576. lastState = state;
  209577. owner.sendChangeMessage (&owner);
  209578. }
  209579. }
  209580. DiskState getDiskState() const
  209581. {
  209582. if ([device->device isValid])
  209583. {
  209584. NSDictionary* status = [device->device status];
  209585. NSString* state = [status objectForKey: DRDeviceMediaStateKey];
  209586. if ([state isEqualTo: DRDeviceMediaStateNone])
  209587. {
  209588. if ([[status objectForKey: DRDeviceIsTrayOpenKey] boolValue])
  209589. return trayOpen;
  209590. return noDisc;
  209591. }
  209592. if ([state isEqualTo: DRDeviceMediaStateMediaPresent])
  209593. {
  209594. if ([[[status objectForKey: DRDeviceMediaInfoKey] objectForKey: DRDeviceMediaBlocksFreeKey] intValue] > 0)
  209595. return writableDiskPresent;
  209596. else
  209597. return readOnlyDiskPresent;
  209598. }
  209599. }
  209600. return unknown;
  209601. }
  209602. bool openTray() { return [device->device isValid] && [device->device ejectMedia]; }
  209603. const Array<int> getAvailableWriteSpeeds() const
  209604. {
  209605. Array<int> results;
  209606. if ([device->device isValid])
  209607. {
  209608. NSArray* speeds = [[[device->device status] objectForKey: DRDeviceMediaInfoKey] objectForKey: DRDeviceBurnSpeedsKey];
  209609. for (unsigned int i = 0; i < [speeds count]; ++i)
  209610. {
  209611. const int kbPerSec = [[speeds objectAtIndex: i] intValue];
  209612. results.add (kbPerSec / kilobytesPerSecond1x);
  209613. }
  209614. }
  209615. return results;
  209616. }
  209617. bool setBufferUnderrunProtection (const bool shouldBeEnabled)
  209618. {
  209619. if ([device->device isValid])
  209620. {
  209621. device->underrunProtection = shouldBeEnabled;
  209622. return shouldBeEnabled && [[[device->device status] objectForKey: DRDeviceCanUnderrunProtectCDKey] boolValue];
  209623. }
  209624. return false;
  209625. }
  209626. int getNumAvailableAudioBlocks() const
  209627. {
  209628. return [[[[device->device status] objectForKey: DRDeviceMediaInfoKey]
  209629. objectForKey: DRDeviceMediaBlocksFreeKey] intValue];
  209630. }
  209631. OpenDiskDevice* device;
  209632. private:
  209633. DiskState lastState;
  209634. AudioCDBurner& owner;
  209635. };
  209636. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  209637. {
  209638. pimpl = new Pimpl (*this, deviceIndex);
  209639. }
  209640. AudioCDBurner::~AudioCDBurner()
  209641. {
  209642. }
  209643. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  209644. {
  209645. ScopedPointer <AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  209646. if (b->pimpl->device == 0)
  209647. b = 0;
  209648. return b.release();
  209649. }
  209650. static NSArray* findDiskBurnerDevices()
  209651. {
  209652. NSMutableArray* results = [NSMutableArray array];
  209653. NSArray* devs = [DRDevice devices];
  209654. if (devs != 0)
  209655. {
  209656. int num = [devs count];
  209657. int i;
  209658. for (i = 0; i < num; ++i)
  209659. {
  209660. NSDictionary* dic = [[devs objectAtIndex: i] info];
  209661. NSString* name = [dic valueForKey: DRDeviceProductNameKey];
  209662. if (name != nil)
  209663. [results addObject: name];
  209664. }
  209665. }
  209666. return results;
  209667. }
  209668. const StringArray AudioCDBurner::findAvailableDevices()
  209669. {
  209670. NSArray* names = findDiskBurnerDevices();
  209671. StringArray s;
  209672. for (unsigned int i = 0; i < [names count]; ++i)
  209673. s.add (String::fromUTF8 ([[names objectAtIndex: i] UTF8String]));
  209674. return s;
  209675. }
  209676. AudioCDBurner::DiskState AudioCDBurner::getDiskState() const
  209677. {
  209678. return pimpl->getDiskState();
  209679. }
  209680. bool AudioCDBurner::isDiskPresent() const
  209681. {
  209682. return getDiskState() == writableDiskPresent;
  209683. }
  209684. bool AudioCDBurner::openTray()
  209685. {
  209686. return pimpl->openTray();
  209687. }
  209688. AudioCDBurner::DiskState AudioCDBurner::waitUntilStateChange (int timeOutMilliseconds)
  209689. {
  209690. const int64 timeout = Time::currentTimeMillis() + timeOutMilliseconds;
  209691. DiskState oldState = getDiskState();
  209692. DiskState newState = oldState;
  209693. while (newState == oldState && Time::currentTimeMillis() < timeout)
  209694. {
  209695. newState = getDiskState();
  209696. Thread::sleep (100);
  209697. }
  209698. return newState;
  209699. }
  209700. const Array<int> AudioCDBurner::getAvailableWriteSpeeds() const
  209701. {
  209702. return pimpl->getAvailableWriteSpeeds();
  209703. }
  209704. bool AudioCDBurner::setBufferUnderrunProtection (const bool shouldBeEnabled)
  209705. {
  209706. return pimpl->setBufferUnderrunProtection (shouldBeEnabled);
  209707. }
  209708. int AudioCDBurner::getNumAvailableAudioBlocks() const
  209709. {
  209710. return pimpl->getNumAvailableAudioBlocks();
  209711. }
  209712. bool AudioCDBurner::addAudioTrack (AudioSource* source, int numSamps)
  209713. {
  209714. if ([pimpl->device->device isValid])
  209715. {
  209716. [pimpl->device addSourceTrack: source numSamples: numSamps];
  209717. return true;
  209718. }
  209719. return false;
  209720. }
  209721. const String AudioCDBurner::burn (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener* listener,
  209722. bool ejectDiscAfterwards,
  209723. bool performFakeBurnForTesting,
  209724. int writeSpeed)
  209725. {
  209726. String error ("Couldn't open or write to the CD device");
  209727. if ([pimpl->device->device isValid])
  209728. {
  209729. error = String::empty;
  209730. [pimpl->device burn: listener
  209731. errorString: &error
  209732. ejectAfterwards: ejectDiscAfterwards
  209733. isFake: performFakeBurnForTesting
  209734. speed: writeSpeed];
  209735. }
  209736. return error;
  209737. }
  209738. #endif
  209739. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  209740. void AudioCDReader::ejectDisk()
  209741. {
  209742. const ScopedAutoReleasePool p;
  209743. [[NSWorkspace sharedWorkspace] unmountAndEjectDeviceAtPath: juceStringToNS (volumeDir.getFullPathName())];
  209744. }
  209745. #endif
  209746. /*** End of inlined file: juce_mac_AudioCDBurner.mm ***/
  209747. /*** Start of inlined file: juce_mac_MessageManager.mm ***/
  209748. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209749. // compiled on its own).
  209750. #if JUCE_INCLUDED_FILE
  209751. class AppDelegateRedirector
  209752. {
  209753. public:
  209754. AppDelegateRedirector()
  209755. {
  209756. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4
  209757. runLoop = CFRunLoopGetMain();
  209758. #else
  209759. runLoop = CFRunLoopGetCurrent();
  209760. #endif
  209761. CFRunLoopSourceContext sourceContext;
  209762. zerostruct (sourceContext);
  209763. sourceContext.info = this;
  209764. sourceContext.perform = runLoopSourceCallback;
  209765. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  209766. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209767. }
  209768. virtual ~AppDelegateRedirector()
  209769. {
  209770. CFRunLoopRemoveSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209771. CFRunLoopSourceInvalidate (runLoopSource);
  209772. CFRelease (runLoopSource);
  209773. while (messages.size() > 0)
  209774. delete ((Message*) messages.remove(0));
  209775. }
  209776. virtual NSApplicationTerminateReply shouldTerminate()
  209777. {
  209778. if (JUCEApplication::getInstance() != 0)
  209779. {
  209780. JUCEApplication::getInstance()->systemRequestedQuit();
  209781. return NSTerminateCancel;
  209782. }
  209783. return NSTerminateNow;
  209784. }
  209785. virtual BOOL openFile (const NSString* filename)
  209786. {
  209787. if (JUCEApplication::getInstance() != 0)
  209788. {
  209789. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce (filename));
  209790. return YES;
  209791. }
  209792. return NO;
  209793. }
  209794. virtual void openFiles (NSArray* filenames)
  209795. {
  209796. StringArray files;
  209797. for (unsigned int i = 0; i < [filenames count]; ++i)
  209798. {
  209799. String filename (nsStringToJuce ((NSString*) [filenames objectAtIndex: i]));
  209800. if (filename.containsChar (' '))
  209801. filename = filename.quoted('"');
  209802. files.add (filename);
  209803. }
  209804. if (files.size() > 0 && JUCEApplication::getInstance() != 0)
  209805. {
  209806. JUCEApplication::getInstance()->anotherInstanceStarted (files.joinIntoString (" "));
  209807. }
  209808. }
  209809. virtual void focusChanged()
  209810. {
  209811. juce_HandleProcessFocusChange();
  209812. }
  209813. struct CallbackMessagePayload
  209814. {
  209815. MessageCallbackFunction* function;
  209816. void* parameter;
  209817. void* volatile result;
  209818. bool volatile hasBeenExecuted;
  209819. };
  209820. virtual void performCallback (CallbackMessagePayload* pl)
  209821. {
  209822. pl->result = (*pl->function) (pl->parameter);
  209823. pl->hasBeenExecuted = true;
  209824. }
  209825. virtual void deleteSelf()
  209826. {
  209827. delete this;
  209828. }
  209829. void postMessage (void* m)
  209830. {
  209831. messages.add (m);
  209832. CFRunLoopSourceSignal (runLoopSource);
  209833. CFRunLoopWakeUp (runLoop);
  209834. }
  209835. private:
  209836. CFRunLoopRef runLoop;
  209837. CFRunLoopSourceRef runLoopSource;
  209838. Array <void*, CriticalSection> messages;
  209839. void runLoopCallback()
  209840. {
  209841. int numDispatched = 0;
  209842. do
  209843. {
  209844. void* const nextMessage = messages.remove (0);
  209845. if (nextMessage == 0)
  209846. return;
  209847. const ScopedAutoReleasePool pool;
  209848. MessageManager::getInstance()->deliverMessage (nextMessage);
  209849. } while (++numDispatched <= 4);
  209850. CFRunLoopSourceSignal (runLoopSource);
  209851. CFRunLoopWakeUp (runLoop);
  209852. }
  209853. static void runLoopSourceCallback (void* info)
  209854. {
  209855. ((AppDelegateRedirector*) info)->runLoopCallback();
  209856. }
  209857. };
  209858. END_JUCE_NAMESPACE
  209859. using namespace JUCE_NAMESPACE;
  209860. #define JuceAppDelegate MakeObjCClassName(JuceAppDelegate)
  209861. @interface JuceAppDelegate : NSObject
  209862. {
  209863. @private
  209864. id oldDelegate;
  209865. @public
  209866. AppDelegateRedirector* redirector;
  209867. }
  209868. - (JuceAppDelegate*) init;
  209869. - (void) dealloc;
  209870. - (BOOL) application: (NSApplication*) theApplication openFile: (NSString*) filename;
  209871. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames;
  209872. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app;
  209873. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  209874. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  209875. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  209876. - (void) performCallback: (id) info;
  209877. - (void) dummyMethod;
  209878. @end
  209879. @implementation JuceAppDelegate
  209880. - (JuceAppDelegate*) init
  209881. {
  209882. [super init];
  209883. redirector = new AppDelegateRedirector();
  209884. NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
  209885. if (JUCEApplication::getInstance() != 0)
  209886. {
  209887. oldDelegate = [NSApp delegate];
  209888. [NSApp setDelegate: self];
  209889. }
  209890. else
  209891. {
  209892. oldDelegate = 0;
  209893. [center addObserver: self selector: @selector (applicationDidResignActive:)
  209894. name: NSApplicationDidResignActiveNotification object: NSApp];
  209895. [center addObserver: self selector: @selector (applicationDidBecomeActive:)
  209896. name: NSApplicationDidBecomeActiveNotification object: NSApp];
  209897. [center addObserver: self selector: @selector (applicationWillUnhide:)
  209898. name: NSApplicationWillUnhideNotification object: NSApp];
  209899. }
  209900. return self;
  209901. }
  209902. - (void) dealloc
  209903. {
  209904. if (oldDelegate != 0)
  209905. [NSApp setDelegate: oldDelegate];
  209906. redirector->deleteSelf();
  209907. [super dealloc];
  209908. }
  209909. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app
  209910. {
  209911. return redirector->shouldTerminate();
  209912. }
  209913. - (BOOL) application: (NSApplication*) app openFile: (NSString*) filename
  209914. {
  209915. return redirector->openFile (filename);
  209916. }
  209917. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames
  209918. {
  209919. return redirector->openFiles (filenames);
  209920. }
  209921. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  209922. {
  209923. redirector->focusChanged();
  209924. }
  209925. - (void) applicationDidResignActive: (NSNotification*) aNotification
  209926. {
  209927. redirector->focusChanged();
  209928. }
  209929. - (void) applicationWillUnhide: (NSNotification*) aNotification
  209930. {
  209931. redirector->focusChanged();
  209932. }
  209933. - (void) performCallback: (id) info
  209934. {
  209935. if ([info isKindOfClass: [NSData class]])
  209936. {
  209937. AppDelegateRedirector::CallbackMessagePayload* pl
  209938. = (AppDelegateRedirector::CallbackMessagePayload*) [((NSData*) info) bytes];
  209939. if (pl != 0)
  209940. redirector->performCallback (pl);
  209941. }
  209942. else
  209943. {
  209944. jassertfalse // should never get here!
  209945. }
  209946. }
  209947. - (void) dummyMethod {} // (used as a way of running a dummy thread)
  209948. @end
  209949. BEGIN_JUCE_NAMESPACE
  209950. static JuceAppDelegate* juceAppDelegate = 0;
  209951. void MessageManager::runDispatchLoop()
  209952. {
  209953. if (! quitMessagePosted) // check that the quit message wasn't already posted..
  209954. {
  209955. const ScopedAutoReleasePool pool;
  209956. // must only be called by the message thread!
  209957. jassert (isThisTheMessageThread());
  209958. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  209959. @try
  209960. {
  209961. [NSApp run];
  209962. }
  209963. @catch (NSException* e)
  209964. {
  209965. // An AppKit exception will kill the app, but at least this provides a chance to log it.,
  209966. std::runtime_error ex (std::string ("NSException: ") + [[e name] UTF8String] + ", Reason:" + [[e reason] UTF8String]);
  209967. JUCEApplication::sendUnhandledException (&ex, __FILE__, __LINE__);
  209968. }
  209969. @finally
  209970. {
  209971. }
  209972. #else
  209973. [NSApp run];
  209974. #endif
  209975. }
  209976. }
  209977. void MessageManager::stopDispatchLoop()
  209978. {
  209979. quitMessagePosted = true;
  209980. [NSApp stop: nil];
  209981. [NSApp activateIgnoringOtherApps: YES]; // (if the app is inactive, it sits there and ignores the quit request until the next time it gets activated)
  209982. [NSEvent startPeriodicEventsAfterDelay: 0 withPeriod: 0.1];
  209983. }
  209984. static bool isEventBlockedByModalComps (NSEvent* e)
  209985. {
  209986. if (Component::getNumCurrentlyModalComponents() == 0)
  209987. return false;
  209988. NSWindow* const w = [e window];
  209989. if (w == 0 || [w worksWhenModal])
  209990. return false;
  209991. bool isKey = false, isInputAttempt = false;
  209992. switch ([e type])
  209993. {
  209994. case NSKeyDown:
  209995. case NSKeyUp:
  209996. isKey = isInputAttempt = true;
  209997. break;
  209998. case NSLeftMouseDown:
  209999. case NSRightMouseDown:
  210000. case NSOtherMouseDown:
  210001. isInputAttempt = true;
  210002. break;
  210003. case NSLeftMouseDragged:
  210004. case NSRightMouseDragged:
  210005. case NSLeftMouseUp:
  210006. case NSRightMouseUp:
  210007. case NSOtherMouseUp:
  210008. case NSOtherMouseDragged:
  210009. if (Desktop::getInstance().getDraggingMouseSource(0) != 0)
  210010. return false;
  210011. break;
  210012. case NSMouseMoved:
  210013. case NSMouseEntered:
  210014. case NSMouseExited:
  210015. case NSCursorUpdate:
  210016. case NSScrollWheel:
  210017. case NSTabletPoint:
  210018. case NSTabletProximity:
  210019. break;
  210020. default:
  210021. return false;
  210022. }
  210023. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  210024. {
  210025. ComponentPeer* const peer = ComponentPeer::getPeer (i);
  210026. NSView* const compView = (NSView*) peer->getNativeHandle();
  210027. if ([compView window] == w)
  210028. {
  210029. if (isKey)
  210030. {
  210031. if (compView == [w firstResponder])
  210032. return false;
  210033. }
  210034. else
  210035. {
  210036. if (NSPointInRect ([compView convertPoint: [e locationInWindow] fromView: nil],
  210037. [compView bounds]))
  210038. return false;
  210039. }
  210040. }
  210041. }
  210042. if (isInputAttempt)
  210043. {
  210044. if (! [NSApp isActive])
  210045. [NSApp activateIgnoringOtherApps: YES];
  210046. Component* const modal = Component::getCurrentlyModalComponent (0);
  210047. if (modal != 0)
  210048. modal->inputAttemptWhenModal();
  210049. }
  210050. return true;
  210051. }
  210052. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  210053. {
  210054. const ScopedAutoReleasePool pool;
  210055. jassert (isThisTheMessageThread()); // must only be called by the message thread
  210056. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  210057. while (! quitMessagePosted)
  210058. {
  210059. const ScopedAutoReleasePool pool2;
  210060. CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0.001, true);
  210061. NSEvent* e = [NSApp nextEventMatchingMask: NSAnyEventMask
  210062. untilDate: [NSDate dateWithTimeIntervalSinceNow: 0.001]
  210063. inMode: NSDefaultRunLoopMode
  210064. dequeue: YES];
  210065. if (e != 0 && ! isEventBlockedByModalComps (e))
  210066. [NSApp sendEvent: e];
  210067. if (Time::getMillisecondCounter() >= endTime)
  210068. break;
  210069. }
  210070. return ! quitMessagePosted;
  210071. }
  210072. void MessageManager::doPlatformSpecificInitialisation()
  210073. {
  210074. if (juceAppDelegate == 0)
  210075. juceAppDelegate = [[JuceAppDelegate alloc] init];
  210076. // This launches a dummy thread, which forces Cocoa to initialise NSThreads
  210077. // correctly (needed prior to 10.5)
  210078. if (! [NSThread isMultiThreaded])
  210079. [NSThread detachNewThreadSelector: @selector (dummyMethod)
  210080. toTarget: juceAppDelegate
  210081. withObject: nil];
  210082. initialiseMainMenu();
  210083. }
  210084. void MessageManager::doPlatformSpecificShutdown()
  210085. {
  210086. if (juceAppDelegate != 0)
  210087. {
  210088. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  210089. [[NSNotificationCenter defaultCenter] removeObserver: juceAppDelegate];
  210090. [juceAppDelegate release];
  210091. juceAppDelegate = 0;
  210092. }
  210093. }
  210094. bool juce_postMessageToSystemQueue (void* message)
  210095. {
  210096. juceAppDelegate->redirector->postMessage (message);
  210097. return true;
  210098. }
  210099. void MessageManager::broadcastMessage (const String& value) throw()
  210100. {
  210101. }
  210102. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  210103. void* data)
  210104. {
  210105. if (isThisTheMessageThread())
  210106. {
  210107. return (*callback) (data);
  210108. }
  210109. else
  210110. {
  210111. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  210112. // deadlock because the message manager is blocked from running, so can never
  210113. // call your function..
  210114. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  210115. const ScopedAutoReleasePool pool;
  210116. AppDelegateRedirector::CallbackMessagePayload cmp;
  210117. cmp.function = callback;
  210118. cmp.parameter = data;
  210119. cmp.result = 0;
  210120. cmp.hasBeenExecuted = false;
  210121. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  210122. withObject: [NSData dataWithBytesNoCopy: &cmp
  210123. length: sizeof (cmp)
  210124. freeWhenDone: NO]
  210125. waitUntilDone: YES];
  210126. return cmp.result;
  210127. }
  210128. }
  210129. #endif
  210130. /*** End of inlined file: juce_mac_MessageManager.mm ***/
  210131. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  210132. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  210133. // compiled on its own).
  210134. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  210135. #if JUCE_MAC
  210136. END_JUCE_NAMESPACE
  210137. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  210138. @interface DownloadClickDetector : NSObject
  210139. {
  210140. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  210141. }
  210142. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  210143. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  210144. request: (NSURLRequest*) request
  210145. frame: (WebFrame*) frame
  210146. decisionListener: (id<WebPolicyDecisionListener>) listener;
  210147. @end
  210148. @implementation DownloadClickDetector
  210149. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  210150. {
  210151. [super init];
  210152. ownerComponent = ownerComponent_;
  210153. return self;
  210154. }
  210155. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  210156. request: (NSURLRequest*) request
  210157. frame: (WebFrame*) frame
  210158. decisionListener: (id <WebPolicyDecisionListener>) listener
  210159. {
  210160. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  210161. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  210162. [listener use];
  210163. else
  210164. [listener ignore];
  210165. }
  210166. @end
  210167. BEGIN_JUCE_NAMESPACE
  210168. class WebBrowserComponentInternal : public NSViewComponent
  210169. {
  210170. public:
  210171. WebBrowserComponentInternal (WebBrowserComponent* owner)
  210172. {
  210173. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  210174. frameName: @""
  210175. groupName: @""];
  210176. setView (webView);
  210177. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  210178. [webView setPolicyDelegate: clickListener];
  210179. }
  210180. ~WebBrowserComponentInternal()
  210181. {
  210182. [webView setPolicyDelegate: nil];
  210183. [clickListener release];
  210184. setView (0);
  210185. }
  210186. void goToURL (const String& url,
  210187. const StringArray* headers,
  210188. const MemoryBlock* postData)
  210189. {
  210190. NSMutableURLRequest* r
  210191. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  210192. cachePolicy: NSURLRequestUseProtocolCachePolicy
  210193. timeoutInterval: 30.0];
  210194. if (postData != 0 && postData->getSize() > 0)
  210195. {
  210196. [r setHTTPMethod: @"POST"];
  210197. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  210198. length: postData->getSize()]];
  210199. }
  210200. if (headers != 0)
  210201. {
  210202. for (int i = 0; i < headers->size(); ++i)
  210203. {
  210204. const String headerName ((*headers)[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  210205. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  210206. [r setValue: juceStringToNS (headerValue)
  210207. forHTTPHeaderField: juceStringToNS (headerName)];
  210208. }
  210209. }
  210210. stop();
  210211. [[webView mainFrame] loadRequest: r];
  210212. }
  210213. void goBack()
  210214. {
  210215. [webView goBack];
  210216. }
  210217. void goForward()
  210218. {
  210219. [webView goForward];
  210220. }
  210221. void stop()
  210222. {
  210223. [webView stopLoading: nil];
  210224. }
  210225. void refresh()
  210226. {
  210227. [webView reload: nil];
  210228. }
  210229. private:
  210230. WebView* webView;
  210231. DownloadClickDetector* clickListener;
  210232. };
  210233. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210234. : browser (0),
  210235. blankPageShown (false),
  210236. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  210237. {
  210238. setOpaque (true);
  210239. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  210240. }
  210241. WebBrowserComponent::~WebBrowserComponent()
  210242. {
  210243. deleteAndZero (browser);
  210244. }
  210245. void WebBrowserComponent::goToURL (const String& url,
  210246. const StringArray* headers,
  210247. const MemoryBlock* postData)
  210248. {
  210249. lastURL = url;
  210250. lastHeaders.clear();
  210251. if (headers != 0)
  210252. lastHeaders = *headers;
  210253. lastPostData.setSize (0);
  210254. if (postData != 0)
  210255. lastPostData = *postData;
  210256. blankPageShown = false;
  210257. browser->goToURL (url, headers, postData);
  210258. }
  210259. void WebBrowserComponent::stop()
  210260. {
  210261. browser->stop();
  210262. }
  210263. void WebBrowserComponent::goBack()
  210264. {
  210265. lastURL = String::empty;
  210266. blankPageShown = false;
  210267. browser->goBack();
  210268. }
  210269. void WebBrowserComponent::goForward()
  210270. {
  210271. lastURL = String::empty;
  210272. browser->goForward();
  210273. }
  210274. void WebBrowserComponent::refresh()
  210275. {
  210276. browser->refresh();
  210277. }
  210278. void WebBrowserComponent::paint (Graphics& g)
  210279. {
  210280. }
  210281. void WebBrowserComponent::checkWindowAssociation()
  210282. {
  210283. if (isShowing())
  210284. {
  210285. if (blankPageShown)
  210286. goBack();
  210287. }
  210288. else
  210289. {
  210290. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  210291. {
  210292. // when the component becomes invisible, some stuff like flash
  210293. // carries on playing audio, so we need to force it onto a blank
  210294. // page to avoid this, (and send it back when it's made visible again).
  210295. blankPageShown = true;
  210296. browser->goToURL ("about:blank", 0, 0);
  210297. }
  210298. }
  210299. }
  210300. void WebBrowserComponent::reloadLastURL()
  210301. {
  210302. if (lastURL.isNotEmpty())
  210303. {
  210304. goToURL (lastURL, &lastHeaders, &lastPostData);
  210305. lastURL = String::empty;
  210306. }
  210307. }
  210308. void WebBrowserComponent::parentHierarchyChanged()
  210309. {
  210310. checkWindowAssociation();
  210311. }
  210312. void WebBrowserComponent::resized()
  210313. {
  210314. browser->setSize (getWidth(), getHeight());
  210315. }
  210316. void WebBrowserComponent::visibilityChanged()
  210317. {
  210318. checkWindowAssociation();
  210319. }
  210320. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210321. {
  210322. return true;
  210323. }
  210324. #else
  210325. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210326. {
  210327. }
  210328. WebBrowserComponent::~WebBrowserComponent()
  210329. {
  210330. }
  210331. void WebBrowserComponent::goToURL (const String& url,
  210332. const StringArray* headers,
  210333. const MemoryBlock* postData)
  210334. {
  210335. }
  210336. void WebBrowserComponent::stop()
  210337. {
  210338. }
  210339. void WebBrowserComponent::goBack()
  210340. {
  210341. }
  210342. void WebBrowserComponent::goForward()
  210343. {
  210344. }
  210345. void WebBrowserComponent::refresh()
  210346. {
  210347. }
  210348. void WebBrowserComponent::paint (Graphics& g)
  210349. {
  210350. }
  210351. void WebBrowserComponent::checkWindowAssociation()
  210352. {
  210353. }
  210354. void WebBrowserComponent::reloadLastURL()
  210355. {
  210356. }
  210357. void WebBrowserComponent::parentHierarchyChanged()
  210358. {
  210359. }
  210360. void WebBrowserComponent::resized()
  210361. {
  210362. }
  210363. void WebBrowserComponent::visibilityChanged()
  210364. {
  210365. }
  210366. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210367. {
  210368. return true;
  210369. }
  210370. #endif
  210371. #endif
  210372. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  210373. /*** Start of inlined file: juce_mac_CoreAudio.cpp ***/
  210374. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  210375. // compiled on its own).
  210376. #if JUCE_INCLUDED_FILE
  210377. #ifndef JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210378. #define JUCE_COREAUDIO_ERROR_LOGGING_ENABLED 1
  210379. #endif
  210380. #undef log
  210381. #if JUCE_COREAUDIO_LOGGING_ENABLED
  210382. #define log(a) Logger::writeToLog (a)
  210383. #else
  210384. #define log(a)
  210385. #endif
  210386. #undef OK
  210387. #if JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210388. static bool logAnyErrors_CoreAudio (const OSStatus err, const int lineNum)
  210389. {
  210390. if (err == noErr)
  210391. return true;
  210392. Logger::writeToLog ("CoreAudio error: " + String (lineNum) + " - " + String::toHexString ((int) err));
  210393. jassertfalse
  210394. return false;
  210395. }
  210396. #define OK(a) logAnyErrors_CoreAudio (a, __LINE__)
  210397. #else
  210398. #define OK(a) (a == noErr)
  210399. #endif
  210400. class CoreAudioInternal : public Timer
  210401. {
  210402. public:
  210403. CoreAudioInternal (AudioDeviceID id)
  210404. : inputLatency (0),
  210405. outputLatency (0),
  210406. callback (0),
  210407. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210408. audioProcID (0),
  210409. #endif
  210410. inputDevice (0),
  210411. isSlaveDevice (false),
  210412. deviceID (id),
  210413. started (false),
  210414. sampleRate (0),
  210415. bufferSize (512),
  210416. numInputChans (0),
  210417. numOutputChans (0),
  210418. callbacksAllowed (true),
  210419. numInputChannelInfos (0),
  210420. numOutputChannelInfos (0)
  210421. {
  210422. jassert (deviceID != 0);
  210423. updateDetailsFromDevice();
  210424. AudioObjectPropertyAddress pa;
  210425. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210426. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210427. pa.mElement = kAudioObjectPropertyElementWildcard;
  210428. AudioObjectAddPropertyListener (deviceID, &pa, deviceListenerProc, this);
  210429. }
  210430. ~CoreAudioInternal()
  210431. {
  210432. AudioObjectPropertyAddress pa;
  210433. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210434. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210435. pa.mElement = kAudioObjectPropertyElementWildcard;
  210436. AudioObjectRemovePropertyListener (deviceID, &pa, deviceListenerProc, this);
  210437. stop (false);
  210438. delete inputDevice;
  210439. }
  210440. void allocateTempBuffers()
  210441. {
  210442. const int tempBufSize = bufferSize + 4;
  210443. audioBuffer.calloc ((numInputChans + numOutputChans) * tempBufSize);
  210444. tempInputBuffers.calloc (numInputChans + 2);
  210445. tempOutputBuffers.calloc (numOutputChans + 2);
  210446. int i, count = 0;
  210447. for (i = 0; i < numInputChans; ++i)
  210448. tempInputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210449. for (i = 0; i < numOutputChans; ++i)
  210450. tempOutputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210451. }
  210452. // returns the number of actual available channels
  210453. void fillInChannelInfo (const bool input)
  210454. {
  210455. int chanNum = 0;
  210456. UInt32 size;
  210457. AudioObjectPropertyAddress pa;
  210458. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  210459. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210460. pa.mElement = kAudioObjectPropertyElementMaster;
  210461. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210462. {
  210463. HeapBlock <AudioBufferList> bufList;
  210464. bufList.calloc (size, 1);
  210465. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  210466. {
  210467. const int numStreams = bufList->mNumberBuffers;
  210468. for (int i = 0; i < numStreams; ++i)
  210469. {
  210470. const AudioBuffer& b = bufList->mBuffers[i];
  210471. for (unsigned int j = 0; j < b.mNumberChannels; ++j)
  210472. {
  210473. String name;
  210474. {
  210475. char channelName [256];
  210476. zerostruct (channelName);
  210477. UInt32 nameSize = sizeof (channelName);
  210478. UInt32 channelNum = chanNum + 1;
  210479. pa.mSelector = kAudioDevicePropertyChannelName;
  210480. if (AudioObjectGetPropertyData (deviceID, &pa, sizeof (channelNum), &channelNum, &nameSize, channelName) == noErr)
  210481. name = String::fromUTF8 (channelName, nameSize);
  210482. }
  210483. if (input)
  210484. {
  210485. if (activeInputChans[chanNum])
  210486. {
  210487. inputChannelInfo [numInputChannelInfos].streamNum = i;
  210488. inputChannelInfo [numInputChannelInfos].dataOffsetSamples = j;
  210489. inputChannelInfo [numInputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210490. ++numInputChannelInfos;
  210491. }
  210492. if (name.isEmpty())
  210493. name << "Input " << (chanNum + 1);
  210494. inChanNames.add (name);
  210495. }
  210496. else
  210497. {
  210498. if (activeOutputChans[chanNum])
  210499. {
  210500. outputChannelInfo [numOutputChannelInfos].streamNum = i;
  210501. outputChannelInfo [numOutputChannelInfos].dataOffsetSamples = j;
  210502. outputChannelInfo [numOutputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210503. ++numOutputChannelInfos;
  210504. }
  210505. if (name.isEmpty())
  210506. name << "Output " << (chanNum + 1);
  210507. outChanNames.add (name);
  210508. }
  210509. ++chanNum;
  210510. }
  210511. }
  210512. }
  210513. }
  210514. }
  210515. void updateDetailsFromDevice()
  210516. {
  210517. stopTimer();
  210518. if (deviceID == 0)
  210519. return;
  210520. const ScopedLock sl (callbackLock);
  210521. Float64 sr;
  210522. UInt32 size = sizeof (Float64);
  210523. AudioObjectPropertyAddress pa;
  210524. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210525. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210526. pa.mElement = kAudioObjectPropertyElementMaster;
  210527. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &sr)))
  210528. sampleRate = sr;
  210529. UInt32 framesPerBuf;
  210530. size = sizeof (framesPerBuf);
  210531. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210532. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &framesPerBuf)))
  210533. {
  210534. bufferSize = framesPerBuf;
  210535. allocateTempBuffers();
  210536. }
  210537. bufferSizes.clear();
  210538. pa.mSelector = kAudioDevicePropertyBufferFrameSizeRange;
  210539. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210540. {
  210541. HeapBlock <AudioValueRange> ranges;
  210542. ranges.calloc (size, 1);
  210543. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210544. {
  210545. bufferSizes.add ((int) ranges[0].mMinimum);
  210546. for (int i = 32; i < 2048; i += 32)
  210547. {
  210548. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210549. {
  210550. if (i >= ranges[j].mMinimum && i <= ranges[j].mMaximum)
  210551. {
  210552. bufferSizes.addIfNotAlreadyThere (i);
  210553. break;
  210554. }
  210555. }
  210556. }
  210557. if (bufferSize > 0)
  210558. bufferSizes.addIfNotAlreadyThere (bufferSize);
  210559. }
  210560. }
  210561. if (bufferSizes.size() == 0 && bufferSize > 0)
  210562. bufferSizes.add (bufferSize);
  210563. sampleRates.clear();
  210564. const double possibleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  210565. String rates;
  210566. pa.mSelector = kAudioDevicePropertyAvailableNominalSampleRates;
  210567. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210568. {
  210569. HeapBlock <AudioValueRange> ranges;
  210570. ranges.calloc (size, 1);
  210571. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210572. {
  210573. for (int i = 0; i < numElementsInArray (possibleRates); ++i)
  210574. {
  210575. bool ok = false;
  210576. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210577. if (possibleRates[i] >= ranges[j].mMinimum - 2 && possibleRates[i] <= ranges[j].mMaximum + 2)
  210578. ok = true;
  210579. if (ok)
  210580. {
  210581. sampleRates.add (possibleRates[i]);
  210582. rates << possibleRates[i] << ' ';
  210583. }
  210584. }
  210585. }
  210586. }
  210587. if (sampleRates.size() == 0 && sampleRate > 0)
  210588. {
  210589. sampleRates.add (sampleRate);
  210590. rates << sampleRate;
  210591. }
  210592. log ("sr: " + rates);
  210593. inputLatency = 0;
  210594. outputLatency = 0;
  210595. UInt32 lat;
  210596. size = sizeof (lat);
  210597. pa.mSelector = kAudioDevicePropertyLatency;
  210598. pa.mScope = kAudioDevicePropertyScopeInput;
  210599. //if (AudioDeviceGetProperty (deviceID, 0, true, kAudioDevicePropertyLatency, &size, &lat) == noErr)
  210600. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210601. inputLatency = (int) lat;
  210602. pa.mScope = kAudioDevicePropertyScopeOutput;
  210603. size = sizeof (lat);
  210604. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210605. outputLatency = (int) lat;
  210606. log ("lat: " + String (inputLatency) + " " + String (outputLatency));
  210607. inChanNames.clear();
  210608. outChanNames.clear();
  210609. inputChannelInfo.calloc (numInputChans + 2);
  210610. numInputChannelInfos = 0;
  210611. outputChannelInfo.calloc (numOutputChans + 2);
  210612. numOutputChannelInfos = 0;
  210613. fillInChannelInfo (true);
  210614. fillInChannelInfo (false);
  210615. }
  210616. const StringArray getSources (bool input)
  210617. {
  210618. StringArray s;
  210619. HeapBlock <OSType> types;
  210620. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210621. for (int i = 0; i < num; ++i)
  210622. {
  210623. AudioValueTranslation avt;
  210624. char buffer[256];
  210625. avt.mInputData = (void*) &(types[i]);
  210626. avt.mInputDataSize = sizeof (UInt32);
  210627. avt.mOutputData = buffer;
  210628. avt.mOutputDataSize = 256;
  210629. UInt32 transSize = sizeof (avt);
  210630. AudioObjectPropertyAddress pa;
  210631. pa.mSelector = kAudioDevicePropertyDataSourceNameForID;
  210632. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210633. pa.mElement = kAudioObjectPropertyElementMaster;
  210634. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &transSize, &avt)))
  210635. {
  210636. DBG (buffer);
  210637. s.add (buffer);
  210638. }
  210639. }
  210640. return s;
  210641. }
  210642. int getCurrentSourceIndex (bool input) const
  210643. {
  210644. OSType currentSourceID = 0;
  210645. UInt32 size = sizeof (currentSourceID);
  210646. int result = -1;
  210647. AudioObjectPropertyAddress pa;
  210648. pa.mSelector = kAudioDevicePropertyDataSource;
  210649. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210650. pa.mElement = kAudioObjectPropertyElementMaster;
  210651. if (deviceID != 0)
  210652. {
  210653. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &currentSourceID)))
  210654. {
  210655. HeapBlock <OSType> types;
  210656. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210657. for (int i = 0; i < num; ++i)
  210658. {
  210659. if (types[num] == currentSourceID)
  210660. {
  210661. result = i;
  210662. break;
  210663. }
  210664. }
  210665. }
  210666. }
  210667. return result;
  210668. }
  210669. void setCurrentSourceIndex (int index, bool input)
  210670. {
  210671. if (deviceID != 0)
  210672. {
  210673. HeapBlock <OSType> types;
  210674. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210675. if (((unsigned int) index) < (unsigned int) num)
  210676. {
  210677. AudioObjectPropertyAddress pa;
  210678. pa.mSelector = kAudioDevicePropertyDataSource;
  210679. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210680. pa.mElement = kAudioObjectPropertyElementMaster;
  210681. OSType typeId = types[index];
  210682. OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (typeId), &typeId));
  210683. }
  210684. }
  210685. }
  210686. const String reopen (const BigInteger& inputChannels,
  210687. const BigInteger& outputChannels,
  210688. double newSampleRate,
  210689. int bufferSizeSamples)
  210690. {
  210691. String error;
  210692. log ("CoreAudio reopen");
  210693. callbacksAllowed = false;
  210694. stopTimer();
  210695. stop (false);
  210696. activeInputChans = inputChannels;
  210697. activeInputChans.setRange (inChanNames.size(),
  210698. activeInputChans.getHighestBit() + 1 - inChanNames.size(),
  210699. false);
  210700. activeOutputChans = outputChannels;
  210701. activeOutputChans.setRange (outChanNames.size(),
  210702. activeOutputChans.getHighestBit() + 1 - outChanNames.size(),
  210703. false);
  210704. numInputChans = activeInputChans.countNumberOfSetBits();
  210705. numOutputChans = activeOutputChans.countNumberOfSetBits();
  210706. // set sample rate
  210707. AudioObjectPropertyAddress pa;
  210708. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210709. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210710. pa.mElement = kAudioObjectPropertyElementMaster;
  210711. Float64 sr = newSampleRate;
  210712. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (sr), &sr)))
  210713. {
  210714. error = "Couldn't change sample rate";
  210715. }
  210716. else
  210717. {
  210718. // change buffer size
  210719. UInt32 framesPerBuf = bufferSizeSamples;
  210720. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210721. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (framesPerBuf), &framesPerBuf)))
  210722. {
  210723. error = "Couldn't change buffer size";
  210724. }
  210725. else
  210726. {
  210727. // Annoyingly, after changing the rate and buffer size, some devices fail to
  210728. // correctly report their new settings until some random time in the future, so
  210729. // after calling updateDetailsFromDevice, we need to manually bodge these values
  210730. // to make sure we're using the correct numbers..
  210731. updateDetailsFromDevice();
  210732. sampleRate = newSampleRate;
  210733. bufferSize = bufferSizeSamples;
  210734. if (sampleRates.size() == 0)
  210735. error = "Device has no available sample-rates";
  210736. else if (bufferSizes.size() == 0)
  210737. error = "Device has no available buffer-sizes";
  210738. else if (inputDevice != 0)
  210739. error = inputDevice->reopen (inputChannels,
  210740. outputChannels,
  210741. newSampleRate,
  210742. bufferSizeSamples);
  210743. }
  210744. }
  210745. callbacksAllowed = true;
  210746. return error;
  210747. }
  210748. bool start (AudioIODeviceCallback* cb)
  210749. {
  210750. if (! started)
  210751. {
  210752. callback = 0;
  210753. if (deviceID != 0)
  210754. {
  210755. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210756. if (OK (AudioDeviceAddIOProc (deviceID, audioIOProc, (void*) this)))
  210757. #else
  210758. if (OK (AudioDeviceCreateIOProcID (deviceID, audioIOProc, (void*) this, &audioProcID)))
  210759. #endif
  210760. {
  210761. if (OK (AudioDeviceStart (deviceID, audioIOProc)))
  210762. {
  210763. started = true;
  210764. }
  210765. else
  210766. {
  210767. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210768. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210769. #else
  210770. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210771. audioProcID = 0;
  210772. #endif
  210773. }
  210774. }
  210775. }
  210776. }
  210777. if (started)
  210778. {
  210779. const ScopedLock sl (callbackLock);
  210780. callback = cb;
  210781. }
  210782. if (inputDevice != 0)
  210783. return started && inputDevice->start (cb);
  210784. else
  210785. return started;
  210786. }
  210787. void stop (bool leaveInterruptRunning)
  210788. {
  210789. {
  210790. const ScopedLock sl (callbackLock);
  210791. callback = 0;
  210792. }
  210793. if (started
  210794. && (deviceID != 0)
  210795. && ! leaveInterruptRunning)
  210796. {
  210797. OK (AudioDeviceStop (deviceID, audioIOProc));
  210798. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210799. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210800. #else
  210801. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210802. audioProcID = 0;
  210803. #endif
  210804. started = false;
  210805. { const ScopedLock sl (callbackLock); }
  210806. // wait until it's definately stopped calling back..
  210807. for (int i = 40; --i >= 0;)
  210808. {
  210809. Thread::sleep (50);
  210810. UInt32 running = 0;
  210811. UInt32 size = sizeof (running);
  210812. AudioObjectPropertyAddress pa;
  210813. pa.mSelector = kAudioDevicePropertyDeviceIsRunning;
  210814. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210815. pa.mElement = kAudioObjectPropertyElementMaster;
  210816. OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &running));
  210817. if (running == 0)
  210818. break;
  210819. }
  210820. const ScopedLock sl (callbackLock);
  210821. }
  210822. if (inputDevice != 0)
  210823. inputDevice->stop (leaveInterruptRunning);
  210824. }
  210825. double getSampleRate() const
  210826. {
  210827. return sampleRate;
  210828. }
  210829. int getBufferSize() const
  210830. {
  210831. return bufferSize;
  210832. }
  210833. void audioCallback (const AudioBufferList* inInputData,
  210834. AudioBufferList* outOutputData)
  210835. {
  210836. int i;
  210837. const ScopedLock sl (callbackLock);
  210838. if (callback != 0)
  210839. {
  210840. if (inputDevice == 0)
  210841. {
  210842. for (i = numInputChans; --i >= 0;)
  210843. {
  210844. const CallbackDetailsForChannel& info = inputChannelInfo[i];
  210845. float* dest = tempInputBuffers [i];
  210846. const float* src = ((const float*) inInputData->mBuffers[info.streamNum].mData)
  210847. + info.dataOffsetSamples;
  210848. const int stride = info.dataStrideSamples;
  210849. if (stride != 0) // if this is zero, info is invalid
  210850. {
  210851. for (int j = bufferSize; --j >= 0;)
  210852. {
  210853. *dest++ = *src;
  210854. src += stride;
  210855. }
  210856. }
  210857. }
  210858. }
  210859. if (! isSlaveDevice)
  210860. {
  210861. if (inputDevice == 0)
  210862. {
  210863. callback->audioDeviceIOCallback (const_cast<const float**> (tempInputBuffers.getData()),
  210864. numInputChans,
  210865. tempOutputBuffers,
  210866. numOutputChans,
  210867. bufferSize);
  210868. }
  210869. else
  210870. {
  210871. jassert (inputDevice->bufferSize == bufferSize);
  210872. // Sometimes the two linked devices seem to get their callbacks in
  210873. // parallel, so we need to lock both devices to stop the input data being
  210874. // changed while inside our callback..
  210875. const ScopedLock sl2 (inputDevice->callbackLock);
  210876. callback->audioDeviceIOCallback (const_cast<const float**> (inputDevice->tempInputBuffers.getData()),
  210877. inputDevice->numInputChans,
  210878. tempOutputBuffers,
  210879. numOutputChans,
  210880. bufferSize);
  210881. }
  210882. for (i = numOutputChans; --i >= 0;)
  210883. {
  210884. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210885. const float* src = tempOutputBuffers [i];
  210886. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210887. + info.dataOffsetSamples;
  210888. const int stride = info.dataStrideSamples;
  210889. if (stride != 0) // if this is zero, info is invalid
  210890. {
  210891. for (int j = bufferSize; --j >= 0;)
  210892. {
  210893. *dest = *src++;
  210894. dest += stride;
  210895. }
  210896. }
  210897. }
  210898. }
  210899. }
  210900. else
  210901. {
  210902. for (i = jmin (numOutputChans, numOutputChannelInfos); --i >= 0;)
  210903. {
  210904. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210905. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210906. + info.dataOffsetSamples;
  210907. const int stride = info.dataStrideSamples;
  210908. if (stride != 0) // if this is zero, info is invalid
  210909. {
  210910. for (int j = bufferSize; --j >= 0;)
  210911. {
  210912. *dest = 0.0f;
  210913. dest += stride;
  210914. }
  210915. }
  210916. }
  210917. }
  210918. }
  210919. // called by callbacks
  210920. void deviceDetailsChanged()
  210921. {
  210922. if (callbacksAllowed)
  210923. startTimer (100);
  210924. }
  210925. void timerCallback()
  210926. {
  210927. stopTimer();
  210928. log ("CoreAudio device changed callback");
  210929. const double oldSampleRate = sampleRate;
  210930. const int oldBufferSize = bufferSize;
  210931. updateDetailsFromDevice();
  210932. if (oldBufferSize != bufferSize || oldSampleRate != sampleRate)
  210933. {
  210934. callbacksAllowed = false;
  210935. stop (false);
  210936. updateDetailsFromDevice();
  210937. callbacksAllowed = true;
  210938. }
  210939. }
  210940. CoreAudioInternal* getRelatedDevice() const
  210941. {
  210942. UInt32 size = 0;
  210943. ScopedPointer <CoreAudioInternal> result;
  210944. AudioObjectPropertyAddress pa;
  210945. pa.mSelector = kAudioDevicePropertyRelatedDevices;
  210946. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210947. pa.mElement = kAudioObjectPropertyElementMaster;
  210948. if (deviceID != 0
  210949. && AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size) == noErr
  210950. && size > 0)
  210951. {
  210952. HeapBlock <AudioDeviceID> devs;
  210953. devs.calloc (size, 1);
  210954. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, devs)))
  210955. {
  210956. for (unsigned int i = 0; i < size / sizeof (AudioDeviceID); ++i)
  210957. {
  210958. if (devs[i] != deviceID && devs[i] != 0)
  210959. {
  210960. result = new CoreAudioInternal (devs[i]);
  210961. const bool thisIsInput = inChanNames.size() > 0 && outChanNames.size() == 0;
  210962. const bool otherIsInput = result->inChanNames.size() > 0 && result->outChanNames.size() == 0;
  210963. if (thisIsInput != otherIsInput
  210964. || (inChanNames.size() + outChanNames.size() == 0)
  210965. || (result->inChanNames.size() + result->outChanNames.size()) == 0)
  210966. break;
  210967. result = 0;
  210968. }
  210969. }
  210970. }
  210971. }
  210972. return result.release();
  210973. }
  210974. juce_UseDebuggingNewOperator
  210975. int inputLatency, outputLatency;
  210976. BigInteger activeInputChans, activeOutputChans;
  210977. StringArray inChanNames, outChanNames;
  210978. Array <double> sampleRates;
  210979. Array <int> bufferSizes;
  210980. AudioIODeviceCallback* callback;
  210981. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210982. AudioDeviceIOProcID audioProcID;
  210983. #endif
  210984. CoreAudioInternal* inputDevice;
  210985. bool isSlaveDevice;
  210986. private:
  210987. CriticalSection callbackLock;
  210988. AudioDeviceID deviceID;
  210989. bool started;
  210990. double sampleRate;
  210991. int bufferSize;
  210992. HeapBlock <float> audioBuffer;
  210993. int numInputChans, numOutputChans;
  210994. bool callbacksAllowed;
  210995. struct CallbackDetailsForChannel
  210996. {
  210997. int streamNum;
  210998. int dataOffsetSamples;
  210999. int dataStrideSamples;
  211000. };
  211001. int numInputChannelInfos, numOutputChannelInfos;
  211002. HeapBlock <CallbackDetailsForChannel> inputChannelInfo, outputChannelInfo;
  211003. HeapBlock <float*> tempInputBuffers, tempOutputBuffers;
  211004. CoreAudioInternal (const CoreAudioInternal&);
  211005. CoreAudioInternal& operator= (const CoreAudioInternal&);
  211006. static OSStatus audioIOProc (AudioDeviceID inDevice,
  211007. const AudioTimeStamp* inNow,
  211008. const AudioBufferList* inInputData,
  211009. const AudioTimeStamp* inInputTime,
  211010. AudioBufferList* outOutputData,
  211011. const AudioTimeStamp* inOutputTime,
  211012. void* device)
  211013. {
  211014. ((CoreAudioInternal*) device)->audioCallback (inInputData, outOutputData);
  211015. return noErr;
  211016. }
  211017. static OSStatus deviceListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  211018. {
  211019. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  211020. switch (pa->mSelector)
  211021. {
  211022. case kAudioDevicePropertyBufferSize:
  211023. case kAudioDevicePropertyBufferFrameSize:
  211024. case kAudioDevicePropertyNominalSampleRate:
  211025. case kAudioDevicePropertyStreamFormat:
  211026. case kAudioDevicePropertyDeviceIsAlive:
  211027. intern->deviceDetailsChanged();
  211028. break;
  211029. case kAudioDevicePropertyBufferSizeRange:
  211030. case kAudioDevicePropertyVolumeScalar:
  211031. case kAudioDevicePropertyMute:
  211032. case kAudioDevicePropertyPlayThru:
  211033. case kAudioDevicePropertyDataSource:
  211034. case kAudioDevicePropertyDeviceIsRunning:
  211035. break;
  211036. }
  211037. return noErr;
  211038. }
  211039. static int getAllDataSourcesForDevice (AudioDeviceID deviceID, const bool input, HeapBlock <OSType>& types)
  211040. {
  211041. AudioObjectPropertyAddress pa;
  211042. pa.mSelector = kAudioDevicePropertyDataSources;
  211043. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211044. pa.mElement = kAudioObjectPropertyElementMaster;
  211045. UInt32 size = 0;
  211046. if (deviceID != 0
  211047. && OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  211048. {
  211049. types.calloc (size, 1);
  211050. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, types)))
  211051. return size / (int) sizeof (OSType);
  211052. }
  211053. return 0;
  211054. }
  211055. };
  211056. class CoreAudioIODevice : public AudioIODevice
  211057. {
  211058. public:
  211059. CoreAudioIODevice (const String& deviceName,
  211060. AudioDeviceID inputDeviceId,
  211061. const int inputIndex_,
  211062. AudioDeviceID outputDeviceId,
  211063. const int outputIndex_)
  211064. : AudioIODevice (deviceName, "CoreAudio"),
  211065. inputIndex (inputIndex_),
  211066. outputIndex (outputIndex_),
  211067. isOpen_ (false),
  211068. isStarted (false)
  211069. {
  211070. internal = 0;
  211071. CoreAudioInternal* device = 0;
  211072. if (outputDeviceId == 0 || outputDeviceId == inputDeviceId)
  211073. {
  211074. jassert (inputDeviceId != 0);
  211075. device = new CoreAudioInternal (inputDeviceId);
  211076. }
  211077. else
  211078. {
  211079. device = new CoreAudioInternal (outputDeviceId);
  211080. if (inputDeviceId != 0)
  211081. {
  211082. CoreAudioInternal* secondDevice = new CoreAudioInternal (inputDeviceId);
  211083. device->inputDevice = secondDevice;
  211084. secondDevice->isSlaveDevice = true;
  211085. }
  211086. }
  211087. internal = device;
  211088. AudioObjectPropertyAddress pa;
  211089. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  211090. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211091. pa.mElement = kAudioObjectPropertyElementWildcard;
  211092. AudioObjectAddPropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  211093. }
  211094. ~CoreAudioIODevice()
  211095. {
  211096. AudioObjectPropertyAddress pa;
  211097. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  211098. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211099. pa.mElement = kAudioObjectPropertyElementWildcard;
  211100. AudioObjectRemovePropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  211101. delete internal;
  211102. }
  211103. const StringArray getOutputChannelNames()
  211104. {
  211105. return internal->outChanNames;
  211106. }
  211107. const StringArray getInputChannelNames()
  211108. {
  211109. if (internal->inputDevice != 0)
  211110. return internal->inputDevice->inChanNames;
  211111. else
  211112. return internal->inChanNames;
  211113. }
  211114. int getNumSampleRates()
  211115. {
  211116. return internal->sampleRates.size();
  211117. }
  211118. double getSampleRate (int index)
  211119. {
  211120. return internal->sampleRates [index];
  211121. }
  211122. int getNumBufferSizesAvailable()
  211123. {
  211124. return internal->bufferSizes.size();
  211125. }
  211126. int getBufferSizeSamples (int index)
  211127. {
  211128. return internal->bufferSizes [index];
  211129. }
  211130. int getDefaultBufferSize()
  211131. {
  211132. for (int i = 0; i < getNumBufferSizesAvailable(); ++i)
  211133. if (getBufferSizeSamples(i) >= 512)
  211134. return getBufferSizeSamples(i);
  211135. return 512;
  211136. }
  211137. const String open (const BigInteger& inputChannels,
  211138. const BigInteger& outputChannels,
  211139. double sampleRate,
  211140. int bufferSizeSamples)
  211141. {
  211142. isOpen_ = true;
  211143. if (bufferSizeSamples <= 0)
  211144. bufferSizeSamples = getDefaultBufferSize();
  211145. lastError = internal->reopen (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  211146. isOpen_ = lastError.isEmpty();
  211147. return lastError;
  211148. }
  211149. void close()
  211150. {
  211151. isOpen_ = false;
  211152. internal->stop (false);
  211153. }
  211154. bool isOpen()
  211155. {
  211156. return isOpen_;
  211157. }
  211158. int getCurrentBufferSizeSamples()
  211159. {
  211160. return internal != 0 ? internal->getBufferSize() : 512;
  211161. }
  211162. double getCurrentSampleRate()
  211163. {
  211164. return internal != 0 ? internal->getSampleRate() : 0;
  211165. }
  211166. int getCurrentBitDepth()
  211167. {
  211168. return 32; // no way to find out, so just assume it's high..
  211169. }
  211170. const BigInteger getActiveOutputChannels() const
  211171. {
  211172. return internal != 0 ? internal->activeOutputChans : BigInteger();
  211173. }
  211174. const BigInteger getActiveInputChannels() const
  211175. {
  211176. BigInteger chans;
  211177. if (internal != 0)
  211178. {
  211179. chans = internal->activeInputChans;
  211180. if (internal->inputDevice != 0)
  211181. chans |= internal->inputDevice->activeInputChans;
  211182. }
  211183. return chans;
  211184. }
  211185. int getOutputLatencyInSamples()
  211186. {
  211187. if (internal == 0)
  211188. return 0;
  211189. // this seems like a good guess at getting the latency right - comparing
  211190. // this with a round-trip measurement, it gets it to within a few millisecs
  211191. // for the built-in mac soundcard
  211192. return internal->outputLatency + internal->getBufferSize() * 2;
  211193. }
  211194. int getInputLatencyInSamples()
  211195. {
  211196. if (internal == 0)
  211197. return 0;
  211198. return internal->inputLatency + internal->getBufferSize() * 2;
  211199. }
  211200. void start (AudioIODeviceCallback* callback)
  211201. {
  211202. if (internal != 0 && ! isStarted)
  211203. {
  211204. if (callback != 0)
  211205. callback->audioDeviceAboutToStart (this);
  211206. isStarted = true;
  211207. internal->start (callback);
  211208. }
  211209. }
  211210. void stop()
  211211. {
  211212. if (isStarted && internal != 0)
  211213. {
  211214. AudioIODeviceCallback* const lastCallback = internal->callback;
  211215. isStarted = false;
  211216. internal->stop (true);
  211217. if (lastCallback != 0)
  211218. lastCallback->audioDeviceStopped();
  211219. }
  211220. }
  211221. bool isPlaying()
  211222. {
  211223. if (internal->callback == 0)
  211224. isStarted = false;
  211225. return isStarted;
  211226. }
  211227. const String getLastError()
  211228. {
  211229. return lastError;
  211230. }
  211231. int inputIndex, outputIndex;
  211232. juce_UseDebuggingNewOperator
  211233. private:
  211234. CoreAudioInternal* internal;
  211235. bool isOpen_, isStarted;
  211236. String lastError;
  211237. static OSStatus hardwareListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  211238. {
  211239. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  211240. switch (pa->mSelector)
  211241. {
  211242. case kAudioHardwarePropertyDevices:
  211243. intern->deviceDetailsChanged();
  211244. break;
  211245. case kAudioHardwarePropertyDefaultOutputDevice:
  211246. case kAudioHardwarePropertyDefaultInputDevice:
  211247. case kAudioHardwarePropertyDefaultSystemOutputDevice:
  211248. break;
  211249. }
  211250. return noErr;
  211251. }
  211252. CoreAudioIODevice (const CoreAudioIODevice&);
  211253. CoreAudioIODevice& operator= (const CoreAudioIODevice&);
  211254. };
  211255. class CoreAudioIODeviceType : public AudioIODeviceType
  211256. {
  211257. public:
  211258. CoreAudioIODeviceType()
  211259. : AudioIODeviceType ("CoreAudio"),
  211260. hasScanned (false)
  211261. {
  211262. }
  211263. ~CoreAudioIODeviceType()
  211264. {
  211265. }
  211266. void scanForDevices()
  211267. {
  211268. hasScanned = true;
  211269. inputDeviceNames.clear();
  211270. outputDeviceNames.clear();
  211271. inputIds.clear();
  211272. outputIds.clear();
  211273. UInt32 size;
  211274. AudioObjectPropertyAddress pa;
  211275. pa.mSelector = kAudioHardwarePropertyDevices;
  211276. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211277. pa.mElement = kAudioObjectPropertyElementMaster;
  211278. if (OK (AudioObjectGetPropertyDataSize (kAudioObjectSystemObject, &pa, 0, 0, &size)))
  211279. {
  211280. HeapBlock <AudioDeviceID> devs;
  211281. devs.calloc (size, 1);
  211282. if (OK (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, devs)))
  211283. {
  211284. static bool alreadyLogged = false;
  211285. const int num = size / (int) sizeof (AudioDeviceID);
  211286. for (int i = 0; i < num; ++i)
  211287. {
  211288. char name [1024];
  211289. size = sizeof (name);
  211290. pa.mSelector = kAudioDevicePropertyDeviceName;
  211291. if (OK (AudioObjectGetPropertyData (devs[i], &pa, 0, 0, &size, name)))
  211292. {
  211293. const String nameString (String::fromUTF8 (name, (int) strlen (name)));
  211294. if (! alreadyLogged)
  211295. log ("CoreAudio device: " + nameString);
  211296. const int numIns = getNumChannels (devs[i], true);
  211297. const int numOuts = getNumChannels (devs[i], false);
  211298. if (numIns > 0)
  211299. {
  211300. inputDeviceNames.add (nameString);
  211301. inputIds.add (devs[i]);
  211302. }
  211303. if (numOuts > 0)
  211304. {
  211305. outputDeviceNames.add (nameString);
  211306. outputIds.add (devs[i]);
  211307. }
  211308. }
  211309. }
  211310. alreadyLogged = true;
  211311. }
  211312. }
  211313. inputDeviceNames.appendNumbersToDuplicates (false, true);
  211314. outputDeviceNames.appendNumbersToDuplicates (false, true);
  211315. }
  211316. const StringArray getDeviceNames (const bool wantInputNames) const
  211317. {
  211318. jassert (hasScanned); // need to call scanForDevices() before doing this
  211319. if (wantInputNames)
  211320. return inputDeviceNames;
  211321. else
  211322. return outputDeviceNames;
  211323. }
  211324. int getDefaultDeviceIndex (const bool forInput) const
  211325. {
  211326. jassert (hasScanned); // need to call scanForDevices() before doing this
  211327. AudioDeviceID deviceID;
  211328. UInt32 size = sizeof (deviceID);
  211329. // if they're asking for any input channels at all, use the default input, so we
  211330. // get the built-in mic rather than the built-in output with no inputs..
  211331. AudioObjectPropertyAddress pa;
  211332. pa.mSelector = forInput ? kAudioHardwarePropertyDefaultInputDevice : kAudioHardwarePropertyDefaultOutputDevice;
  211333. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211334. pa.mElement = kAudioObjectPropertyElementMaster;
  211335. if (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, &deviceID) == noErr)
  211336. {
  211337. if (forInput)
  211338. {
  211339. for (int i = inputIds.size(); --i >= 0;)
  211340. if (inputIds[i] == deviceID)
  211341. return i;
  211342. }
  211343. else
  211344. {
  211345. for (int i = outputIds.size(); --i >= 0;)
  211346. if (outputIds[i] == deviceID)
  211347. return i;
  211348. }
  211349. }
  211350. return 0;
  211351. }
  211352. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  211353. {
  211354. jassert (hasScanned); // need to call scanForDevices() before doing this
  211355. CoreAudioIODevice* const d = dynamic_cast <CoreAudioIODevice*> (device);
  211356. if (d == 0)
  211357. return -1;
  211358. return asInput ? d->inputIndex
  211359. : d->outputIndex;
  211360. }
  211361. bool hasSeparateInputsAndOutputs() const { return true; }
  211362. AudioIODevice* createDevice (const String& outputDeviceName,
  211363. const String& inputDeviceName)
  211364. {
  211365. jassert (hasScanned); // need to call scanForDevices() before doing this
  211366. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  211367. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  211368. String deviceName (outputDeviceName);
  211369. if (deviceName.isEmpty())
  211370. deviceName = inputDeviceName;
  211371. if (index >= 0)
  211372. return new CoreAudioIODevice (deviceName,
  211373. inputIds [inputIndex],
  211374. inputIndex,
  211375. outputIds [outputIndex],
  211376. outputIndex);
  211377. return 0;
  211378. }
  211379. juce_UseDebuggingNewOperator
  211380. private:
  211381. StringArray inputDeviceNames, outputDeviceNames;
  211382. Array <AudioDeviceID> inputIds, outputIds;
  211383. bool hasScanned;
  211384. static int getNumChannels (AudioDeviceID deviceID, bool input)
  211385. {
  211386. int total = 0;
  211387. UInt32 size;
  211388. AudioObjectPropertyAddress pa;
  211389. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  211390. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  211391. pa.mElement = kAudioObjectPropertyElementMaster;
  211392. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  211393. {
  211394. HeapBlock <AudioBufferList> bufList;
  211395. bufList.calloc (size, 1);
  211396. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  211397. {
  211398. const int numStreams = bufList->mNumberBuffers;
  211399. for (int i = 0; i < numStreams; ++i)
  211400. {
  211401. const AudioBuffer& b = bufList->mBuffers[i];
  211402. total += b.mNumberChannels;
  211403. }
  211404. }
  211405. }
  211406. return total;
  211407. }
  211408. CoreAudioIODeviceType (const CoreAudioIODeviceType&);
  211409. CoreAudioIODeviceType& operator= (const CoreAudioIODeviceType&);
  211410. };
  211411. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio()
  211412. {
  211413. return new CoreAudioIODeviceType();
  211414. }
  211415. #undef log
  211416. #endif
  211417. /*** End of inlined file: juce_mac_CoreAudio.cpp ***/
  211418. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  211419. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211420. // compiled on its own).
  211421. #if JUCE_INCLUDED_FILE
  211422. #if JUCE_MAC
  211423. #undef log
  211424. #define log(a) Logger::writeToLog(a)
  211425. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  211426. {
  211427. if (err == noErr)
  211428. return true;
  211429. log ("CoreMidi error: " + String (lineNum) + " - " + String::toHexString ((int) err));
  211430. jassertfalse
  211431. return false;
  211432. }
  211433. #undef OK
  211434. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  211435. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  211436. {
  211437. String result;
  211438. CFStringRef str = 0;
  211439. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  211440. if (str != 0)
  211441. {
  211442. result = PlatformUtilities::cfStringToJuceString (str);
  211443. CFRelease (str);
  211444. str = 0;
  211445. }
  211446. MIDIEntityRef entity = 0;
  211447. MIDIEndpointGetEntity (endpoint, &entity);
  211448. if (entity == 0)
  211449. return result; // probably virtual
  211450. if (result.isEmpty())
  211451. {
  211452. // endpoint name has zero length - try the entity
  211453. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  211454. if (str != 0)
  211455. {
  211456. result += PlatformUtilities::cfStringToJuceString (str);
  211457. CFRelease (str);
  211458. str = 0;
  211459. }
  211460. }
  211461. // now consider the device's name
  211462. MIDIDeviceRef device = 0;
  211463. MIDIEntityGetDevice (entity, &device);
  211464. if (device == 0)
  211465. return result;
  211466. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  211467. if (str != 0)
  211468. {
  211469. const String s (PlatformUtilities::cfStringToJuceString (str));
  211470. CFRelease (str);
  211471. // if an external device has only one entity, throw away
  211472. // the endpoint name and just use the device name
  211473. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  211474. {
  211475. result = s;
  211476. }
  211477. else if (! result.startsWithIgnoreCase (s))
  211478. {
  211479. // prepend the device name to the entity name
  211480. result = (s + " " + result).trimEnd();
  211481. }
  211482. }
  211483. return result;
  211484. }
  211485. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  211486. {
  211487. String result;
  211488. // Does the endpoint have connections?
  211489. CFDataRef connections = 0;
  211490. int numConnections = 0;
  211491. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  211492. if (connections != 0)
  211493. {
  211494. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  211495. if (numConnections > 0)
  211496. {
  211497. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  211498. for (int i = 0; i < numConnections; ++i, ++pid)
  211499. {
  211500. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  211501. MIDIObjectRef connObject;
  211502. MIDIObjectType connObjectType;
  211503. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  211504. if (err == noErr)
  211505. {
  211506. String s;
  211507. if (connObjectType == kMIDIObjectType_ExternalSource
  211508. || connObjectType == kMIDIObjectType_ExternalDestination)
  211509. {
  211510. // Connected to an external device's endpoint (10.3 and later).
  211511. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  211512. }
  211513. else
  211514. {
  211515. // Connected to an external device (10.2) (or something else, catch-all)
  211516. CFStringRef str = 0;
  211517. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  211518. if (str != 0)
  211519. {
  211520. s = PlatformUtilities::cfStringToJuceString (str);
  211521. CFRelease (str);
  211522. }
  211523. }
  211524. if (s.isNotEmpty())
  211525. {
  211526. if (result.isNotEmpty())
  211527. result += (", ");
  211528. result += s;
  211529. }
  211530. }
  211531. }
  211532. }
  211533. CFRelease (connections);
  211534. }
  211535. if (result.isNotEmpty())
  211536. return result;
  211537. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  211538. return getEndpointName (endpoint, false);
  211539. }
  211540. const StringArray MidiOutput::getDevices()
  211541. {
  211542. StringArray s;
  211543. const ItemCount num = MIDIGetNumberOfDestinations();
  211544. for (ItemCount i = 0; i < num; ++i)
  211545. {
  211546. MIDIEndpointRef dest = MIDIGetDestination (i);
  211547. if (dest != 0)
  211548. {
  211549. String name (getConnectedEndpointName (dest));
  211550. if (name.isEmpty())
  211551. name = "<error>";
  211552. s.add (name);
  211553. }
  211554. else
  211555. {
  211556. s.add ("<error>");
  211557. }
  211558. }
  211559. return s;
  211560. }
  211561. int MidiOutput::getDefaultDeviceIndex()
  211562. {
  211563. return 0;
  211564. }
  211565. static MIDIClientRef globalMidiClient;
  211566. static bool hasGlobalClientBeenCreated = false;
  211567. static bool makeSureClientExists()
  211568. {
  211569. if (! hasGlobalClientBeenCreated)
  211570. {
  211571. String name ("JUCE");
  211572. if (JUCEApplication::getInstance() != 0)
  211573. name = JUCEApplication::getInstance()->getApplicationName();
  211574. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  211575. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  211576. CFRelease (appName);
  211577. }
  211578. return hasGlobalClientBeenCreated;
  211579. }
  211580. class MidiPortAndEndpoint
  211581. {
  211582. public:
  211583. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  211584. : port (port_), endPoint (endPoint_)
  211585. {
  211586. }
  211587. ~MidiPortAndEndpoint()
  211588. {
  211589. if (port != 0)
  211590. MIDIPortDispose (port);
  211591. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  211592. MIDIEndpointDispose (endPoint);
  211593. }
  211594. MIDIPortRef port;
  211595. MIDIEndpointRef endPoint;
  211596. };
  211597. MidiOutput* MidiOutput::openDevice (int index)
  211598. {
  211599. MidiOutput* mo = 0;
  211600. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  211601. {
  211602. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  211603. CFStringRef pname;
  211604. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211605. {
  211606. log ("CoreMidi - opening out: " + PlatformUtilities::cfStringToJuceString (pname));
  211607. if (makeSureClientExists())
  211608. {
  211609. MIDIPortRef port;
  211610. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  211611. {
  211612. mo = new MidiOutput();
  211613. mo->internal = (void*) new MidiPortAndEndpoint (port, endPoint);
  211614. }
  211615. }
  211616. CFRelease (pname);
  211617. }
  211618. }
  211619. return mo;
  211620. }
  211621. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  211622. {
  211623. MidiOutput* mo = 0;
  211624. if (makeSureClientExists())
  211625. {
  211626. MIDIEndpointRef endPoint;
  211627. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  211628. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  211629. {
  211630. mo = new MidiOutput();
  211631. mo->internal = (void*) new MidiPortAndEndpoint (0, endPoint);
  211632. }
  211633. CFRelease (name);
  211634. }
  211635. return mo;
  211636. }
  211637. MidiOutput::~MidiOutput()
  211638. {
  211639. delete (MidiPortAndEndpoint*) internal;
  211640. }
  211641. void MidiOutput::reset()
  211642. {
  211643. }
  211644. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211645. {
  211646. return false;
  211647. }
  211648. void MidiOutput::setVolume (float leftVol, float rightVol)
  211649. {
  211650. }
  211651. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211652. {
  211653. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  211654. if (message.isSysEx())
  211655. {
  211656. const int maxPacketSize = 256;
  211657. int pos = 0, bytesLeft = message.getRawDataSize();
  211658. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  211659. HeapBlock <MIDIPacketList> packets;
  211660. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  211661. packets->numPackets = numPackets;
  211662. MIDIPacket* p = packets->packet;
  211663. for (int i = 0; i < numPackets; ++i)
  211664. {
  211665. p->timeStamp = 0;
  211666. p->length = jmin (maxPacketSize, bytesLeft);
  211667. memcpy (p->data, message.getRawData() + pos, p->length);
  211668. pos += p->length;
  211669. bytesLeft -= p->length;
  211670. p = MIDIPacketNext (p);
  211671. }
  211672. if (mpe->port != 0)
  211673. MIDISend (mpe->port, mpe->endPoint, packets);
  211674. else
  211675. MIDIReceived (mpe->endPoint, packets);
  211676. }
  211677. else
  211678. {
  211679. MIDIPacketList packets;
  211680. packets.numPackets = 1;
  211681. packets.packet[0].timeStamp = 0;
  211682. packets.packet[0].length = message.getRawDataSize();
  211683. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  211684. if (mpe->port != 0)
  211685. MIDISend (mpe->port, mpe->endPoint, &packets);
  211686. else
  211687. MIDIReceived (mpe->endPoint, &packets);
  211688. }
  211689. }
  211690. const StringArray MidiInput::getDevices()
  211691. {
  211692. StringArray s;
  211693. const ItemCount num = MIDIGetNumberOfSources();
  211694. for (ItemCount i = 0; i < num; ++i)
  211695. {
  211696. MIDIEndpointRef source = MIDIGetSource (i);
  211697. if (source != 0)
  211698. {
  211699. String name (getConnectedEndpointName (source));
  211700. if (name.isEmpty())
  211701. name = "<error>";
  211702. s.add (name);
  211703. }
  211704. else
  211705. {
  211706. s.add ("<error>");
  211707. }
  211708. }
  211709. return s;
  211710. }
  211711. int MidiInput::getDefaultDeviceIndex()
  211712. {
  211713. return 0;
  211714. }
  211715. struct MidiPortAndCallback
  211716. {
  211717. MidiInput* input;
  211718. MidiPortAndEndpoint* portAndEndpoint;
  211719. MidiInputCallback* callback;
  211720. MemoryBlock pendingData;
  211721. int pendingBytes;
  211722. double pendingDataTime;
  211723. bool active;
  211724. void processSysex (const uint8*& d, int& size, const double time)
  211725. {
  211726. if (*d == 0xf0)
  211727. {
  211728. pendingBytes = 0;
  211729. pendingDataTime = time;
  211730. }
  211731. pendingData.ensureSize (pendingBytes + size, false);
  211732. uint8* totalMessage = (uint8*) pendingData.getData();
  211733. uint8* dest = totalMessage + pendingBytes;
  211734. while (size > 0)
  211735. {
  211736. if (pendingBytes > 0 && *d >= 0x80)
  211737. {
  211738. if (*d >= 0xfa || *d == 0xf8)
  211739. {
  211740. callback->handleIncomingMidiMessage (input, MidiMessage (*d, time));
  211741. ++d;
  211742. --size;
  211743. }
  211744. else
  211745. {
  211746. if (*d == 0xf7)
  211747. {
  211748. *dest++ = *d++;
  211749. pendingBytes++;
  211750. --size;
  211751. }
  211752. break;
  211753. }
  211754. }
  211755. else
  211756. {
  211757. *dest++ = *d++;
  211758. pendingBytes++;
  211759. --size;
  211760. }
  211761. }
  211762. if (totalMessage [pendingBytes - 1] == 0xf7)
  211763. {
  211764. callback->handleIncomingMidiMessage (input, MidiMessage (totalMessage, pendingBytes, pendingDataTime));
  211765. pendingBytes = 0;
  211766. }
  211767. else
  211768. {
  211769. callback->handlePartialSysexMessage (input, totalMessage, pendingBytes, pendingDataTime);
  211770. }
  211771. }
  211772. };
  211773. namespace CoreMidiCallbacks
  211774. {
  211775. static CriticalSection callbackLock;
  211776. static VoidArray activeCallbacks;
  211777. }
  211778. static void midiInputProc (const MIDIPacketList* pktlist,
  211779. void* readProcRefCon,
  211780. void* srcConnRefCon)
  211781. {
  211782. double time = Time::getMillisecondCounterHiRes() * 0.001;
  211783. const double originalTime = time;
  211784. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  211785. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211786. if (CoreMidiCallbacks::activeCallbacks.contains (mpc) && mpc->active)
  211787. {
  211788. const MIDIPacket* packet = &pktlist->packet[0];
  211789. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  211790. {
  211791. const uint8* d = (const uint8*) (packet->data);
  211792. int size = packet->length;
  211793. while (size > 0)
  211794. {
  211795. time = originalTime;
  211796. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  211797. {
  211798. mpc->processSysex (d, size, time);
  211799. }
  211800. else
  211801. {
  211802. int used = 0;
  211803. const MidiMessage m (d, size, used, 0, time);
  211804. if (used <= 0)
  211805. {
  211806. jassertfalse // malformed midi message
  211807. break;
  211808. }
  211809. else
  211810. {
  211811. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  211812. }
  211813. size -= used;
  211814. d += used;
  211815. }
  211816. }
  211817. packet = MIDIPacketNext (packet);
  211818. }
  211819. }
  211820. }
  211821. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211822. {
  211823. MidiInput* mi = 0;
  211824. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  211825. {
  211826. MIDIEndpointRef endPoint = MIDIGetSource (index);
  211827. if (endPoint != 0)
  211828. {
  211829. CFStringRef pname;
  211830. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211831. {
  211832. log ("CoreMidi - opening inp: " + PlatformUtilities::cfStringToJuceString (pname));
  211833. if (makeSureClientExists())
  211834. {
  211835. MIDIPortRef port;
  211836. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211837. mpc->active = false;
  211838. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  211839. {
  211840. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  211841. {
  211842. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  211843. mpc->callback = callback;
  211844. mpc->pendingBytes = 0;
  211845. mpc->pendingData.ensureSize (128);
  211846. mi = new MidiInput (getDevices() [index]);
  211847. mpc->input = mi;
  211848. mi->internal = (void*) mpc;
  211849. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211850. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  211851. }
  211852. else
  211853. {
  211854. OK (MIDIPortDispose (port));
  211855. }
  211856. }
  211857. }
  211858. }
  211859. CFRelease (pname);
  211860. }
  211861. }
  211862. return mi;
  211863. }
  211864. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  211865. {
  211866. MidiInput* mi = 0;
  211867. if (makeSureClientExists())
  211868. {
  211869. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211870. mpc->active = false;
  211871. MIDIEndpointRef endPoint;
  211872. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  211873. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  211874. {
  211875. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  211876. mpc->callback = callback;
  211877. mpc->pendingBytes = 0;
  211878. mpc->pendingData.ensureSize (128);
  211879. mi = new MidiInput (deviceName);
  211880. mpc->input = mi;
  211881. mi->internal = (void*) mpc;
  211882. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211883. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  211884. }
  211885. CFRelease (name);
  211886. }
  211887. return mi;
  211888. }
  211889. MidiInput::MidiInput (const String& name_)
  211890. : name (name_)
  211891. {
  211892. }
  211893. MidiInput::~MidiInput()
  211894. {
  211895. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211896. mpc->active = false;
  211897. {
  211898. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211899. CoreMidiCallbacks::activeCallbacks.removeValue (mpc);
  211900. }
  211901. if (mpc->portAndEndpoint->port != 0)
  211902. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  211903. delete mpc->portAndEndpoint;
  211904. delete mpc;
  211905. }
  211906. void MidiInput::start()
  211907. {
  211908. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211909. ((MidiPortAndCallback*) internal)->active = true;
  211910. }
  211911. void MidiInput::stop()
  211912. {
  211913. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211914. ((MidiPortAndCallback*) internal)->active = false;
  211915. }
  211916. #undef log
  211917. #else
  211918. MidiOutput::~MidiOutput()
  211919. {
  211920. }
  211921. void MidiOutput::reset()
  211922. {
  211923. }
  211924. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211925. {
  211926. return false;
  211927. }
  211928. void MidiOutput::setVolume (float leftVol, float rightVol)
  211929. {
  211930. }
  211931. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211932. {
  211933. }
  211934. const StringArray MidiOutput::getDevices()
  211935. {
  211936. return StringArray();
  211937. }
  211938. MidiOutput* MidiOutput::openDevice (int index)
  211939. {
  211940. return 0;
  211941. }
  211942. const StringArray MidiInput::getDevices()
  211943. {
  211944. return StringArray();
  211945. }
  211946. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211947. {
  211948. return 0;
  211949. }
  211950. #endif
  211951. #endif
  211952. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  211953. /*** Start of inlined file: juce_mac_CameraDevice.mm ***/
  211954. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211955. // compiled on its own).
  211956. #if JUCE_INCLUDED_FILE && JUCE_USE_CAMERA
  211957. #if ! JUCE_QUICKTIME
  211958. #error "On the Mac, cameras use Quicktime, so if you turn on JUCE_USE_CAMERA, you also need to enable JUCE_QUICKTIME"
  211959. #endif
  211960. #define QTCaptureCallbackDelegate MakeObjCClassName(QTCaptureCallbackDelegate)
  211961. class QTCameraDeviceInteral;
  211962. END_JUCE_NAMESPACE
  211963. @interface QTCaptureCallbackDelegate : NSObject
  211964. {
  211965. @public
  211966. CameraDevice* owner;
  211967. QTCameraDeviceInteral* internal;
  211968. int64 firstPresentationTime;
  211969. int64 averageTimeOffset;
  211970. }
  211971. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner internalDev: (QTCameraDeviceInteral*) d;
  211972. - (void) dealloc;
  211973. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  211974. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  211975. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211976. fromConnection: (QTCaptureConnection*) connection;
  211977. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  211978. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211979. fromConnection: (QTCaptureConnection*) connection;
  211980. @end
  211981. BEGIN_JUCE_NAMESPACE
  211982. class QTCameraDeviceInteral
  211983. {
  211984. public:
  211985. QTCameraDeviceInteral (CameraDevice* owner, int index)
  211986. {
  211987. const ScopedAutoReleasePool pool;
  211988. session = [[QTCaptureSession alloc] init];
  211989. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  211990. device = (QTCaptureDevice*) [devs objectAtIndex: index];
  211991. input = 0;
  211992. audioInput = 0;
  211993. audioDevice = 0;
  211994. fileOutput = 0;
  211995. imageOutput = 0;
  211996. callbackDelegate = [[QTCaptureCallbackDelegate alloc] initWithOwner: owner
  211997. internalDev: this];
  211998. NSError* err = 0;
  211999. [device retain];
  212000. [device open: &err];
  212001. if (err == 0)
  212002. {
  212003. input = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  212004. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  212005. [session addInput: input error: &err];
  212006. if (err == 0)
  212007. {
  212008. resetFile();
  212009. imageOutput = [[QTCaptureDecompressedVideoOutput alloc] init];
  212010. [imageOutput setDelegate: callbackDelegate];
  212011. if (err == 0)
  212012. {
  212013. [session startRunning];
  212014. return;
  212015. }
  212016. }
  212017. }
  212018. openingError = nsStringToJuce ([err description]);
  212019. DBG (openingError);
  212020. }
  212021. ~QTCameraDeviceInteral()
  212022. {
  212023. [session stopRunning];
  212024. [session removeOutput: imageOutput];
  212025. [session release];
  212026. [input release];
  212027. [device release];
  212028. [audioDevice release];
  212029. [audioInput release];
  212030. [fileOutput release];
  212031. [imageOutput release];
  212032. [callbackDelegate release];
  212033. }
  212034. void resetFile()
  212035. {
  212036. [fileOutput recordToOutputFileURL: nil];
  212037. [session removeOutput: fileOutput];
  212038. [fileOutput release];
  212039. fileOutput = [[QTCaptureMovieFileOutput alloc] init];
  212040. [session removeInput: audioInput];
  212041. [audioInput release];
  212042. audioInput = 0;
  212043. [audioDevice release];
  212044. audioDevice = 0;
  212045. [fileOutput setDelegate: callbackDelegate];
  212046. }
  212047. void addDefaultAudioInput()
  212048. {
  212049. NSError* err = nil;
  212050. audioDevice = [QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeSound];
  212051. if ([audioDevice open: &err])
  212052. [audioDevice retain];
  212053. else
  212054. audioDevice = nil;
  212055. if (audioDevice != 0)
  212056. {
  212057. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: audioDevice];
  212058. [session addInput: audioInput error: &err];
  212059. }
  212060. }
  212061. void addListener (CameraImageListener* listenerToAdd)
  212062. {
  212063. const ScopedLock sl (listenerLock);
  212064. if (listeners.size() == 0)
  212065. [session addOutput: imageOutput error: nil];
  212066. listeners.addIfNotAlreadyThere (listenerToAdd);
  212067. }
  212068. void removeListener (CameraImageListener* listenerToRemove)
  212069. {
  212070. const ScopedLock sl (listenerLock);
  212071. listeners.removeValue (listenerToRemove);
  212072. if (listeners.size() == 0)
  212073. [session removeOutput: imageOutput];
  212074. }
  212075. void callListeners (CIImage* frame, int w, int h)
  212076. {
  212077. CoreGraphicsImage image (Image::ARGB, w, h, false);
  212078. CIContext* cic = [CIContext contextWithCGContext: image.context options: nil];
  212079. [cic drawImage: frame inRect: CGRectMake (0, 0, w, h) fromRect: CGRectMake (0, 0, w, h)];
  212080. CGContextFlush (image.context);
  212081. const ScopedLock sl (listenerLock);
  212082. for (int i = listeners.size(); --i >= 0;)
  212083. {
  212084. CameraImageListener* l = (CameraImageListener*) listeners[i];
  212085. if (l != 0)
  212086. l->imageReceived (image);
  212087. }
  212088. }
  212089. QTCaptureDevice* device;
  212090. QTCaptureDeviceInput* input;
  212091. QTCaptureDevice* audioDevice;
  212092. QTCaptureDeviceInput* audioInput;
  212093. QTCaptureSession* session;
  212094. QTCaptureMovieFileOutput* fileOutput;
  212095. QTCaptureDecompressedVideoOutput* imageOutput;
  212096. QTCaptureCallbackDelegate* callbackDelegate;
  212097. String openingError;
  212098. VoidArray listeners;
  212099. CriticalSection listenerLock;
  212100. };
  212101. END_JUCE_NAMESPACE
  212102. @implementation QTCaptureCallbackDelegate
  212103. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner_
  212104. internalDev: (QTCameraDeviceInteral*) d
  212105. {
  212106. [super init];
  212107. owner = owner_;
  212108. internal = d;
  212109. firstPresentationTime = 0;
  212110. averageTimeOffset = 0;
  212111. return self;
  212112. }
  212113. - (void) dealloc
  212114. {
  212115. [super dealloc];
  212116. }
  212117. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  212118. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  212119. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  212120. fromConnection: (QTCaptureConnection*) connection
  212121. {
  212122. if (internal->listeners.size() > 0)
  212123. {
  212124. const ScopedAutoReleasePool pool;
  212125. internal->callListeners ([CIImage imageWithCVImageBuffer: videoFrame],
  212126. CVPixelBufferGetWidth (videoFrame),
  212127. CVPixelBufferGetHeight (videoFrame));
  212128. }
  212129. }
  212130. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  212131. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  212132. fromConnection: (QTCaptureConnection*) connection
  212133. {
  212134. const Time now (Time::getCurrentTime());
  212135. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  212136. NSNumber* hosttime = (NSNumber*) [sampleBuffer attributeForKey: QTSampleBufferHostTimeAttribute];
  212137. #else
  212138. NSNumber* hosttime = (NSNumber*) [sampleBuffer attributeForKey: @"hostTime"];
  212139. #endif
  212140. int64 presentationTime = (hosttime != nil)
  212141. ? ((int64) AudioConvertHostTimeToNanos ([hosttime unsignedLongLongValue]) / 1000000 + 40)
  212142. : (([sampleBuffer presentationTime].timeValue * 1000) / [sampleBuffer presentationTime].timeScale + 50);
  212143. const int64 timeDiff = now.toMilliseconds() - presentationTime;
  212144. if (firstPresentationTime == 0)
  212145. {
  212146. firstPresentationTime = presentationTime;
  212147. averageTimeOffset = timeDiff;
  212148. }
  212149. else
  212150. {
  212151. averageTimeOffset = (averageTimeOffset * 120 + timeDiff * 8) / 128;
  212152. }
  212153. }
  212154. @end
  212155. BEGIN_JUCE_NAMESPACE
  212156. class QTCaptureViewerComp : public NSViewComponent
  212157. {
  212158. public:
  212159. QTCaptureViewerComp (CameraDevice* const cameraDevice, QTCameraDeviceInteral* const internal)
  212160. {
  212161. const ScopedAutoReleasePool pool;
  212162. captureView = [[QTCaptureView alloc] init];
  212163. [captureView setCaptureSession: internal->session];
  212164. setSize (640, 480); // xxx need to somehow get the movie size - how?
  212165. setView (captureView);
  212166. }
  212167. ~QTCaptureViewerComp()
  212168. {
  212169. setView (0);
  212170. [captureView setCaptureSession: nil];
  212171. [captureView release];
  212172. }
  212173. QTCaptureView* captureView;
  212174. };
  212175. CameraDevice::CameraDevice (const String& name_, int index)
  212176. : name (name_)
  212177. {
  212178. isRecording = false;
  212179. internal = new QTCameraDeviceInteral (this, index);
  212180. }
  212181. CameraDevice::~CameraDevice()
  212182. {
  212183. stopRecording();
  212184. delete static_cast <QTCameraDeviceInteral*> (internal);
  212185. internal = 0;
  212186. }
  212187. Component* CameraDevice::createViewerComponent()
  212188. {
  212189. return new QTCaptureViewerComp (this, static_cast <QTCameraDeviceInteral*> (internal));
  212190. }
  212191. const String CameraDevice::getFileExtension()
  212192. {
  212193. return ".mov";
  212194. }
  212195. void CameraDevice::startRecordingToFile (const File& file, int quality)
  212196. {
  212197. stopRecording();
  212198. QTCameraDeviceInteral* const d = static_cast <QTCameraDeviceInteral*> (internal);
  212199. d->callbackDelegate->firstPresentationTime = 0;
  212200. file.deleteFile();
  212201. // In some versions of QT (e.g. on 10.5), if you record video without audio, the speed comes
  212202. // out wrong, so we'll put some audio in there too..,
  212203. d->addDefaultAudioInput();
  212204. [d->session addOutput: d->fileOutput error: nil];
  212205. NSEnumerator* connectionEnumerator = [[d->fileOutput connections] objectEnumerator];
  212206. for (;;)
  212207. {
  212208. QTCaptureConnection* connection = [connectionEnumerator nextObject];
  212209. if (connection == 0)
  212210. break;
  212211. QTCompressionOptions* options = 0;
  212212. NSString* mediaType = [connection mediaType];
  212213. if ([mediaType isEqualToString: QTMediaTypeVideo])
  212214. options = [QTCompressionOptions compressionOptionsWithIdentifier:
  212215. quality >= 1 ? @"QTCompressionOptionsSD480SizeH264Video"
  212216. : @"QTCompressionOptions240SizeH264Video"];
  212217. else if ([mediaType isEqualToString: QTMediaTypeSound])
  212218. options = [QTCompressionOptions compressionOptionsWithIdentifier: @"QTCompressionOptionsHighQualityAACAudio"];
  212219. [d->fileOutput setCompressionOptions: options forConnection: connection];
  212220. }
  212221. [d->fileOutput recordToOutputFileURL: [NSURL fileURLWithPath: juceStringToNS (file.getFullPathName())]];
  212222. isRecording = true;
  212223. }
  212224. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  212225. {
  212226. QTCameraDeviceInteral* const d = static_cast <QTCameraDeviceInteral*> (internal);
  212227. if (d->callbackDelegate->firstPresentationTime != 0)
  212228. return Time (d->callbackDelegate->firstPresentationTime + d->callbackDelegate->averageTimeOffset);
  212229. return Time();
  212230. }
  212231. void CameraDevice::stopRecording()
  212232. {
  212233. if (isRecording)
  212234. {
  212235. static_cast <QTCameraDeviceInteral*> (internal)->resetFile();
  212236. isRecording = false;
  212237. }
  212238. }
  212239. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  212240. {
  212241. if (listenerToAdd != 0)
  212242. static_cast <QTCameraDeviceInteral*> (internal)->addListener (listenerToAdd);
  212243. }
  212244. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  212245. {
  212246. if (listenerToRemove != 0)
  212247. static_cast <QTCameraDeviceInteral*> (internal)->removeListener (listenerToRemove);
  212248. }
  212249. const StringArray CameraDevice::getAvailableDevices()
  212250. {
  212251. const ScopedAutoReleasePool pool;
  212252. StringArray results;
  212253. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  212254. for (int i = 0; i < (int) [devs count]; ++i)
  212255. {
  212256. QTCaptureDevice* dev = (QTCaptureDevice*) [devs objectAtIndex: i];
  212257. results.add (nsStringToJuce ([dev localizedDisplayName]));
  212258. }
  212259. return results;
  212260. }
  212261. CameraDevice* CameraDevice::openDevice (int index,
  212262. int minWidth, int minHeight,
  212263. int maxWidth, int maxHeight)
  212264. {
  212265. ScopedPointer <CameraDevice> d (new CameraDevice (getAvailableDevices() [index], index));
  212266. if (static_cast <QTCameraDeviceInteral*> (d->internal)->openingError.isEmpty())
  212267. return d.release();
  212268. return 0;
  212269. }
  212270. #endif
  212271. /*** End of inlined file: juce_mac_CameraDevice.mm ***/
  212272. #endif
  212273. #endif
  212274. END_JUCE_NAMESPACE
  212275. #endif
  212276. /*** End of inlined file: juce_mac_NativeCode.mm ***/
  212277. #endif
  212278. #endif